summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-11-14 21:01:46 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-11-14 21:01:46 -0500
commit4e4510fec4af08ead21f6934c1410af1f19a8cad (patch)
tree2bafab4f7cc2cdf2983186b24140f6303d4dfc8c
parent4008e6a9bcee2f3b61bb11951de0fb0ed764cb91 (diff)
parent7087cb8fad5e19113d82f47f351fc6b338948d5f (diff)
Merge tag 'sound-4.15-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/tiwai/sound
Pull sound updates from Takashi Iwai: "There are no big surprising changes in this cycle, yet not too boring, either. The biggest change from diffstat POV is the removal of the legacy OSS driver codes that have been already disabled for a long time. This will bring a few trivial merge conflicts. As new features in ASoC side, there are two things: a new AC97 bus implementation and AMD Stony platform support. Both include the relevant changes shared with other subsystems, e.g. AC97 MFD changes and DRM AMD changes. Some other highlighted topics are: - A bunch of USB-audio drivers got the hardening against the malicious device accesses with a new helper code for endpoint sanity check - Lots of cleanups for ASoC Intel platform code, including support for their open source audio firmware - Continued ASoC core componentization works - Support for scaling MCLK with sample rate in ASoC simple-card - Stabler PCM hot-unplug capability, especially for ASoC usages" * tag 'sound-4.15-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/tiwai/sound: (302 commits) Documentation: sound: hd-audio: notes.rst ASoC: bcm2835: Support left/right justified and DSP modes ASoC: bcm2835: Enforce full symmetry ASoC: bcm2835: Support additional samplerates up to 384kHz ASoC: bcm2835: Add support for TDM modes ASoC: add mclk-fs support to audio graph card ASoC: add mclk-fs to audio graph card binding ASoC: rt5514: work around link error ASoC: rt5514: mark PM functions as __maybe_unused ASoC: rt5663: Check the JD status in the button pushing ASoC: amd: Modified DMA transfer Mechanism for Playback ASoC: rt5645: Wait for 400msec before concluding on value of RT5645_VENDOR_ID2 ASoC: sun4i-codec: fixed 32bit audio capture support for H3/H2+ ASoC: da7213: add support for DSP modes ASoC: sun8i-codec: Add a comment on the LRCK inversion ASoC: sun8i-codec: Set the BCLK divider ASoC: rt5663: Delay and retry reading rt5663 ID register ASoC: amd: use do_div rather than 64 bit division to fix 32 bit builds ASoC: cs42l56: Fix reset GPIO name in example DT binding ASoC: rt5514-spi: check irq status to schedule data copy in resume function ...
-rw-r--r--Documentation/devicetree/bindings/mfd/arizona.txt40
-rw-r--r--Documentation/devicetree/bindings/sound/audio-graph-card.txt1
-rw-r--r--Documentation/devicetree/bindings/sound/audio-graph-scu-card.txt5
-rw-r--r--Documentation/devicetree/bindings/sound/cs42l56.txt2
-rw-r--r--Documentation/devicetree/bindings/sound/rt5514.txt13
-rw-r--r--Documentation/devicetree/bindings/sound/rt5663.txt16
-rw-r--r--Documentation/devicetree/bindings/sound/sgtl5000.txt2
-rw-r--r--Documentation/devicetree/bindings/sound/st,stm32-sai.txt14
-rw-r--r--Documentation/devicetree/bindings/sound/tfa9879.txt23
-rw-r--r--Documentation/devicetree/bindings/sound/wlf,arizona.txt53
-rw-r--r--Documentation/sound/hd-audio/models.rst2
-rw-r--r--Documentation/sound/oss/ALS66
-rw-r--r--Documentation/sound/oss/AudioExcelDSP16101
-rw-r--r--Documentation/sound/oss/CMI8330152
-rw-r--r--Documentation/sound/oss/ESS34
-rw-r--r--Documentation/sound/oss/ESS186855
-rw-r--r--Documentation/sound/oss/Introduction459
-rw-r--r--Documentation/sound/oss/MultiSound1137
-rw-r--r--Documentation/sound/oss/OPL36
-rw-r--r--Documentation/sound/oss/Opti218
-rw-r--r--Documentation/sound/oss/PAS16162
-rw-r--r--Documentation/sound/oss/PSS41
-rw-r--r--Documentation/sound/oss/PSS-updates88
-rw-r--r--Documentation/sound/oss/README.OSS1455
-rw-r--r--Documentation/sound/oss/README.modules106
-rw-r--r--Documentation/sound/oss/README.ymfsb107
-rw-r--r--Documentation/sound/oss/SoundPro105
-rw-r--r--Documentation/sound/oss/Soundblaster53
-rw-r--r--Documentation/sound/oss/Tropez+26
-rw-r--r--Documentation/sound/oss/VIBRA1680
-rw-r--r--Documentation/sound/oss/WaveArtist170
-rw-r--r--Documentation/sound/oss/btaudio92
-rw-r--r--Documentation/sound/oss/mwave185
-rw-r--r--Documentation/sound/oss/oss-parameters.txt51
-rw-r--r--Documentation/sound/oss/ultrasound30
-rw-r--r--MAINTAINERS12
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c2
-rw-r--r--drivers/gpu/drm/amd/include/amd_shared.h29
-rw-r--r--drivers/input/touchscreen/Kconfig2
-rw-r--r--drivers/input/touchscreen/wm97xx-core.c252
-rw-r--r--drivers/mfd/Kconfig14
-rw-r--r--drivers/mfd/Makefile1
-rw-r--r--drivers/mfd/arizona-core.c132
-rw-r--r--drivers/mfd/wm97xx-core.c366
-rw-r--r--drivers/usb/core/urb.c30
-rw-r--r--include/drm/amd_asic_type.h52
-rw-r--r--include/linux/mfd/arizona/pdata.h3
-rw-r--r--include/linux/mfd/wm97xx.h25
-rw-r--r--include/linux/usb.h2
-rw-r--r--include/sound/ac97/codec.h118
-rw-r--r--include/sound/ac97/compat.h20
-rw-r--r--include/sound/ac97/controller.h85
-rw-r--r--include/sound/ac97/regs.h262
-rw-r--r--include/sound/ac97_codec.h239
-rw-r--r--include/sound/core.h2
-rw-r--r--include/sound/hdaudio.h3
-rw-r--r--include/sound/pxa2xx-lib.h15
-rw-r--r--include/sound/rt5651.h8
-rw-r--r--include/sound/rt5663.h3
-rw-r--r--include/sound/snd_wavefront.h1
-rw-r--r--include/sound/soc-acpi-intel-match.h32
-rw-r--r--include/sound/soc-acpi.h111
-rw-r--r--include/sound/soc.h115
-rw-r--r--sound/Kconfig35
-rw-r--r--sound/Makefile4
-rw-r--r--sound/ac97/Kconfig19
-rw-r--r--sound/ac97/Makefile8
-rw-r--r--sound/ac97/ac97_core.h16
-rw-r--r--sound/ac97/bus.c539
-rw-r--r--sound/ac97/codec.c15
-rw-r--r--sound/ac97/snd_ac97_compat.c108
-rw-r--r--sound/arm/pxa2xx-ac97-lib.c37
-rw-r--r--sound/arm/pxa2xx-ac97.c35
-rw-r--r--sound/core/hrtimer.c2
-rw-r--r--sound/core/hwdep.c2
-rw-r--r--sound/core/init.c32
-rw-r--r--sound/core/jack.c2
-rw-r--r--sound/core/pcm.c20
-rw-r--r--sound/core/pcm_native.c2
-rw-r--r--sound/core/seq/seq_clientmgr.c4
-rw-r--r--sound/core/timer.c11
-rw-r--r--sound/drivers/aloop.c7
-rw-r--r--sound/drivers/dummy.c7
-rw-r--r--sound/drivers/mpu401/mpu401_uart.c7
-rw-r--r--sound/drivers/mtpav.c7
-rw-r--r--sound/drivers/opl3/opl3_midi.c4
-rw-r--r--sound/drivers/opl3/opl3_seq.c2
-rw-r--r--sound/drivers/opl3/opl3_voice.h2
-rw-r--r--sound/drivers/serial-u16550.c7
-rw-r--r--sound/hda/hdac_controller.c3
-rw-r--r--sound/hda/hdac_device.c43
-rw-r--r--sound/hda/hdac_sysfs.c47
-rw-r--r--sound/hda/local.h2
-rw-r--r--sound/i2c/other/ak4117.c8
-rw-r--r--sound/isa/sb/emu8000_pcm.c6
-rw-r--r--sound/isa/sb/sb8_midi.c11
-rw-r--r--sound/isa/wavefront/wavefront_midi.c10
-rw-r--r--sound/oss/CHANGELOG369
-rw-r--r--sound/oss/Kconfig533
-rw-r--r--sound/oss/Makefile108
-rw-r--r--sound/oss/README.FIRST6
-rw-r--r--sound/oss/ad1848.c3062
-rw-r--r--sound/oss/ad1848.h25
-rw-r--r--sound/oss/ad1848_mixer.h253
-rw-r--r--sound/oss/aedsp16.c1373
-rw-r--r--sound/oss/audio.c985
-rw-r--r--sound/oss/bin2hex.c40
-rw-r--r--sound/oss/coproc.h12
-rw-r--r--sound/oss/dev_table.c256
-rw-r--r--sound/oss/dev_table.h390
-rw-r--r--sound/oss/dmabuf.c1268
-rw-r--r--sound/oss/hex2hex.c102
-rw-r--r--sound/oss/kahlua.c229
-rw-r--r--sound/oss/midi_ctrl.h23
-rw-r--r--sound/oss/midi_synth.c712
-rw-r--r--sound/oss/midi_synth.h48
-rw-r--r--sound/oss/midibuf.c427
-rw-r--r--sound/oss/mpu401.c1804
-rw-r--r--sound/oss/mpu401.h12
-rw-r--r--sound/oss/msnd.c413
-rw-r--r--sound/oss/msnd.h278
-rw-r--r--sound/oss/msnd_classic.c3
-rw-r--r--sound/oss/msnd_classic.h185
-rw-r--r--sound/oss/msnd_pinnacle.c1941
-rw-r--r--sound/oss/msnd_pinnacle.h246
-rw-r--r--sound/oss/opl3.c1255
-rw-r--r--sound/oss/opl3_hw.h246
-rw-r--r--sound/oss/os.h46
-rw-r--r--sound/oss/pas2.h21
-rw-r--r--sound/oss/pas2_card.c458
-rw-r--r--sound/oss/pas2_midi.c262
-rw-r--r--sound/oss/pas2_mixer.c327
-rw-r--r--sound/oss/pas2_pcm.c419
-rw-r--r--sound/oss/pss.c1270
-rw-r--r--sound/oss/sb.h186
-rw-r--r--sound/oss/sb_audio.c1097
-rw-r--r--sound/oss/sb_card.c354
-rw-r--r--sound/oss/sb_card.h149
-rw-r--r--sound/oss/sb_common.c1287
-rw-r--r--sound/oss/sb_ess.c1823
-rw-r--r--sound/oss/sb_ess.h35
-rw-r--r--sound/oss/sb_midi.c206
-rw-r--r--sound/oss/sb_mixer.c770
-rw-r--r--sound/oss/sb_mixer.h105
-rw-r--r--sound/oss/sequencer.c1661
-rw-r--r--sound/oss/sleep.h19
-rw-r--r--sound/oss/sound_calls.h88
-rw-r--r--sound/oss/sound_config.h144
-rw-r--r--sound/oss/sound_firmware.h30
-rw-r--r--sound/oss/sound_timer.c327
-rw-r--r--sound/oss/soundcard.c733
-rw-r--r--sound/oss/soundvers.h2
-rw-r--r--sound/oss/swarm_cs4297a.c2781
-rw-r--r--sound/oss/sys_timer.c280
-rw-r--r--sound/oss/trix.c525
-rw-r--r--sound/oss/tuning.h24
-rw-r--r--sound/oss/uart401.c477
-rw-r--r--sound/oss/uart6850.c361
-rw-r--r--sound/oss/ulaw.h70
-rw-r--r--sound/oss/v_midi.c290
-rw-r--r--sound/oss/v_midi.h15
-rw-r--r--sound/oss/vidc.c557
-rw-r--r--sound/oss/vidc.h63
-rw-r--r--sound/oss/vidc_fill.S218
-rw-r--r--sound/oss/waveartist.c2043
-rw-r--r--sound/oss/waveartist.h93
-rw-r--r--sound/pci/asihpi/asihpi.c15
-rw-r--r--sound/pci/au88x0/au88x0_core.c2
-rw-r--r--sound/pci/ctxfi/cttimer.c7
-rw-r--r--sound/pci/echoaudio/midi.c10
-rw-r--r--sound/pci/emu10k1/emuproc.c1
-rw-r--r--sound/pci/ens1370.c3
-rw-r--r--sound/pci/hda/hda_codec.c2
-rw-r--r--sound/pci/hda/hda_generic.c2
-rw-r--r--sound/pci/hda/patch_ca0132.c8
-rw-r--r--sound/pci/hda/patch_realtek.c24
-rw-r--r--sound/pci/ice1712/ice1712.c2
-rw-r--r--sound/pci/ice1712/ice1712.h3
-rw-r--r--sound/pci/korg1212/korg1212.c7
-rw-r--r--sound/pci/oxygen/xonar_dg.h2
-rw-r--r--sound/pci/oxygen/xonar_dg_mixer.c2
-rw-r--r--sound/pci/rme9652/hdsp.c8
-rw-r--r--sound/pci/rme9652/hdspm.c8
-rw-r--r--sound/sh/aica.c20
-rw-r--r--sound/soc/Kconfig3
-rw-r--r--sound/soc/Makefile6
-rw-r--r--sound/soc/amd/Kconfig7
-rw-r--r--sound/soc/amd/Makefile6
-rw-r--r--sound/soc/amd/acp-pcm-dma.c356
-rw-r--r--sound/soc/amd/acp-rt5645.c199
-rw-r--r--sound/soc/amd/acp.h19
-rw-r--r--sound/soc/bcm/bcm2835-i2s.c391
-rw-r--r--sound/soc/bcm/cygnus-ssp.c34
-rw-r--r--sound/soc/codecs/Kconfig13
-rw-r--r--sound/soc/codecs/Makefile1
-rw-r--r--sound/soc/codecs/arizona.c166
-rw-r--r--sound/soc/codecs/arizona.h6
-rw-r--r--sound/soc/codecs/cs43130.c16
-rw-r--r--sound/soc/codecs/cs47l24.c14
-rw-r--r--sound/soc/codecs/da7213.c58
-rw-r--r--sound/soc/codecs/da7213.h1
-rw-r--r--sound/soc/codecs/hdac_hdmi.c51
-rw-r--r--sound/soc/codecs/hdmi-codec.c5
-rw-r--r--sound/soc/codecs/max98090.c2
-rw-r--r--sound/soc/codecs/max98925.c23
-rw-r--r--sound/soc/codecs/max98927.c155
-rw-r--r--sound/soc/codecs/max98927.h7
-rw-r--r--sound/soc/codecs/msm8916-wcd-analog.c120
-rw-r--r--sound/soc/codecs/msm8916-wcd-digital.c4
-rw-r--r--sound/soc/codecs/pcm512x-i2c.c4
-rw-r--r--sound/soc/codecs/pcm512x-spi.c2
-rw-r--r--sound/soc/codecs/pcm512x.c4
-rw-r--r--sound/soc/codecs/pcm512x.h2
-rw-r--r--sound/soc/codecs/rl6231.c5
-rw-r--r--sound/soc/codecs/rt5514-spi.c46
-rw-r--r--sound/soc/codecs/rt5514.c6
-rw-r--r--sound/soc/codecs/rt5645.c39
-rw-r--r--sound/soc/codecs/rt5651.c219
-rw-r--r--sound/soc/codecs/rt5651.h4
-rw-r--r--sound/soc/codecs/rt5659.c26
-rw-r--r--sound/soc/codecs/rt5663.c272
-rw-r--r--sound/soc/codecs/rt5670.c143
-rw-r--r--sound/soc/codecs/rt5670.h4
-rw-r--r--sound/soc/codecs/tas571x.c3
-rw-r--r--sound/soc/codecs/tfa9879.c6
-rw-r--r--sound/soc/codecs/tlv320aic23.c1
-rw-r--r--sound/soc/codecs/tlv320aic31xx.c2
-rw-r--r--sound/soc/codecs/tpa6130a2.c1
-rw-r--r--sound/soc/codecs/ts3a227e.c10
-rw-r--r--sound/soc/codecs/wm5102.c14
-rw-r--r--sound/soc/codecs/wm5110.c14
-rw-r--r--sound/soc/codecs/wm8741.c39
-rw-r--r--sound/soc/codecs/wm8753.c4
-rw-r--r--sound/soc/codecs/wm8993.c2
-rw-r--r--sound/soc/codecs/wm8994.c2
-rw-r--r--sound/soc/codecs/wm8997.c15
-rw-r--r--sound/soc/codecs/wm8998.c95
-rw-r--r--sound/soc/codecs/wm9705.c68
-rw-r--r--sound/soc/codecs/wm9712.c48
-rw-r--r--sound/soc/codecs/wm9713.c39
-rw-r--r--sound/soc/davinci/davinci-mcasp.c21
-rw-r--r--sound/soc/dwc/Kconfig4
-rw-r--r--sound/soc/fsl/fsl-asoc-card.c14
-rw-r--r--sound/soc/fsl/fsl_spdif.c4
-rw-r--r--sound/soc/fsl/fsl_ssi.c46
-rw-r--r--sound/soc/generic/audio-graph-card.c47
-rw-r--r--sound/soc/img/img-i2s-in.c130
-rw-r--r--sound/soc/img/img-i2s-out.c120
-rw-r--r--sound/soc/img/img-parallel-out.c6
-rw-r--r--sound/soc/img/img-spdif-in.c110
-rw-r--r--sound/soc/img/img-spdif-out.c87
-rw-r--r--sound/soc/intel/Kconfig302
-rw-r--r--sound/soc/intel/Makefile2
-rw-r--r--sound/soc/intel/atom/sst-mfld-platform-compress.c2
-rw-r--r--sound/soc/intel/atom/sst-mfld-platform.h2
-rw-r--r--sound/soc/intel/atom/sst/sst_acpi.c312
-rw-r--r--sound/soc/intel/atom/sst/sst_loader.c1
-rw-r--r--sound/soc/intel/atom/sst/sst_stream.c1
-rw-r--r--sound/soc/intel/boards/Kconfig265
-rw-r--r--sound/soc/intel/boards/bxt_da7219_max98357a.c16
-rw-r--r--sound/soc/intel/boards/bytcht_da7213.c23
-rw-r--r--sound/soc/intel/boards/bytcht_es8316.c27
-rw-r--r--sound/soc/intel/boards/bytcht_nocodec.c10
-rw-r--r--sound/soc/intel/boards/bytcr_rt5640.c118
-rw-r--r--sound/soc/intel/boards/bytcr_rt5651.c297
-rw-r--r--sound/soc/intel/boards/cht_bsw_max98090_ti.c185
-rw-r--r--sound/soc/intel/boards/cht_bsw_rt5645.c128
-rw-r--r--sound/soc/intel/boards/cht_bsw_rt5672.c68
-rw-r--r--sound/soc/intel/boards/kbl_rt5663_max98927.c76
-rw-r--r--sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c3
-rw-r--r--sound/soc/intel/boards/skl_nau88l25_max98357a.c16
-rw-r--r--sound/soc/intel/boards/skl_nau88l25_ssm4567.c16
-rw-r--r--sound/soc/intel/common/Makefile4
-rw-r--r--sound/soc/intel/common/soc-acpi-intel-byt-match.c196
-rw-r--r--sound/soc/intel/common/soc-acpi-intel-cht-match.c194
-rw-r--r--sound/soc/intel/common/soc-acpi-intel-hsw-bdw-match.c64
-rw-r--r--sound/soc/intel/common/sst-acpi.c36
-rw-r--r--sound/soc/intel/common/sst-acpi.h82
-rw-r--r--sound/soc/intel/common/sst-firmware.c3
-rw-r--r--sound/soc/intel/skylake/skl-messages.c32
-rw-r--r--sound/soc/intel/skylake/skl-nhlt.c9
-rw-r--r--sound/soc/intel/skylake/skl-pcm.c49
-rw-r--r--sound/soc/intel/skylake/skl-sst-utils.c15
-rw-r--r--sound/soc/intel/skylake/skl-topology.c70
-rw-r--r--sound/soc/intel/skylake/skl-topology.h10
-rw-r--r--sound/soc/intel/skylake/skl.c50
-rw-r--r--sound/soc/intel/skylake/skl.h4
-rw-r--r--sound/soc/kirkwood/kirkwood-dma.c2
-rw-r--r--sound/soc/kirkwood/kirkwood.h2
-rw-r--r--sound/soc/omap/ams-delta.c4
-rw-r--r--sound/soc/omap/omap-hdmi-audio.c3
-rw-r--r--sound/soc/pxa/pxa2xx-ac97.c32
-rw-r--r--sound/soc/qcom/lpass-platform.c2
-rw-r--r--sound/soc/rockchip/rk3399_gru_sound.c159
-rw-r--r--sound/soc/rockchip/rockchip_i2s.c1
-rw-r--r--sound/soc/samsung/i2s.c10
-rw-r--r--sound/soc/samsung/i2s.h3
-rw-r--r--sound/soc/samsung/tm2_wm5110.c7
-rw-r--r--sound/soc/sh/fsi.c11
-rw-r--r--sound/soc/sh/rcar/adg.c72
-rw-r--r--sound/soc/sh/rcar/core.c51
-rw-r--r--sound/soc/sh/rcar/ctu.c88
-rw-r--r--sound/soc/sh/rcar/dma.c84
-rw-r--r--sound/soc/sh/rcar/dvc.c60
-rw-r--r--sound/soc/sh/rcar/mix.c158
-rw-r--r--sound/soc/sh/rcar/rsnd.h22
-rw-r--r--sound/soc/sh/rcar/ssi.c58
-rw-r--r--sound/soc/soc-acpi.c (renamed from sound/soc/intel/common/sst-match-acpi.c)56
-rw-r--r--sound/soc/soc-compress.c461
-rw-r--r--sound/soc/soc-core.c222
-rw-r--r--sound/soc/soc-dapm.c158
-rw-r--r--sound/soc/soc-io.c14
-rw-r--r--sound/soc/soc-pcm.c462
-rw-r--r--sound/soc/stm/stm32_sai.c162
-rw-r--r--sound/soc/stm/stm32_sai.h22
-rw-r--r--sound/soc/stm/stm32_sai_sub.c162
-rw-r--r--sound/soc/stm/stm32_spdifrx.c23
-rw-r--r--sound/soc/sunxi/sun4i-codec.c29
-rw-r--r--sound/soc/sunxi/sun8i-codec.c72
-rw-r--r--sound/soc/zte/zx-spdif.c4
-rw-r--r--sound/synth/emux/emux.c2
-rw-r--r--sound/synth/emux/emux_oss.c2
-rw-r--r--sound/synth/emux/emux_synth.c4
-rw-r--r--sound/synth/emux/emux_voice.h2
-rw-r--r--sound/usb/6fire/chip.c2
-rw-r--r--sound/usb/bcd2000/bcd2000.c7
-rw-r--r--sound/usb/caiaq/device.c7
-rw-r--r--sound/usb/caiaq/input.c9
-rw-r--r--sound/usb/hiface/pcm.c9
-rw-r--r--sound/usb/line6/capture.c2
-rw-r--r--sound/usb/line6/capture.h2
-rw-r--r--sound/usb/line6/driver.c34
-rw-r--r--sound/usb/line6/driver.h3
-rw-r--r--sound/usb/line6/midi.c17
-rw-r--r--sound/usb/line6/playback.c2
-rw-r--r--sound/usb/line6/playback.h2
-rw-r--r--sound/usb/line6/pod.c11
-rw-r--r--sound/usb/line6/podhd.c26
-rw-r--r--sound/usb/line6/toneport.c7
-rw-r--r--sound/usb/line6/variax.c32
-rw-r--r--sound/usb/midi.c45
-rw-r--r--sound/usb/quirks.c24
-rw-r--r--sound/usb/usx2y/usb_stream.c23
-rw-r--r--sound/usb/usx2y/usbusx2y.c5
-rw-r--r--sound/usb/usx2y/usbusx2yaudio.c3
345 files changed, 9146 insertions, 44387 deletions
diff --git a/Documentation/devicetree/bindings/mfd/arizona.txt b/Documentation/devicetree/bindings/mfd/arizona.txt
index b37bdde5cfda..bdd017686ea5 100644
--- a/Documentation/devicetree/bindings/mfd/arizona.txt
+++ b/Documentation/devicetree/bindings/mfd/arizona.txt
@@ -65,45 +65,6 @@ Optional properties:
65 a value that is out of range for a 16 bit register then the chip default 65 a value that is out of range for a 16 bit register then the chip default
66 will be used. If present exactly five values must be specified. 66 will be used. If present exactly five values must be specified.
67 67
68 - wlf,inmode : A list of INn_MODE register values, where n is the number
69 of input signals. Valid values are 0 (Differential), 1 (Single-ended) and
70 2 (Digital Microphone). If absent, INn_MODE registers set to 0 by default.
71 If present, values must be specified less than or equal to the number of
72 input signals. If values less than the number of input signals, elements
73 that have not been specified are set to 0 by default. Entries are:
74 <IN1, IN2, IN3, IN4> (wm5102, wm5110, wm8280, wm8997)
75 <IN1A, IN2A, IN1B, IN2B> (wm8998, wm1814)
76 - wlf,out-mono : A list of boolean values indicating whether each output is
77 mono or stereo. Position within the list indicates the output affected
78 (eg. First entry in the list corresponds to output 1). A non-zero value
79 indicates a mono output. If present, the number of values should be less
80 than or equal to the number of outputs, if less values are supplied the
81 additional outputs will be treated as stereo.
82
83 - wlf,dmic-ref : DMIC reference voltage source for each input, can be
84 selected from either MICVDD or one of the MICBIAS's, defines
85 (ARIZONA_DMIC_xxxx) are provided in <dt-bindings/mfd/arizona.txt>. If
86 present, the number of values should be less than or equal to the
87 number of inputs, unspecified inputs will use the chip default.
88
89 - wlf,max-channels-clocked : The maximum number of channels to be clocked on
90 each AIF, useful for I2S systems with multiple data lines being mastered.
91 Specify one cell for each AIF to be configured, specify zero for AIFs that
92 should be handled normally.
93 If present, number of cells must be less than or equal to the number of
94 AIFs. If less than the number of AIFs, for cells that have not been
95 specified the corresponding AIFs will be treated as default setting.
96
97 - wlf,spk-fmt : PDM speaker data format, must contain 2 cells (OUT5 and OUT6).
98 See the datasheet for values.
99 The second cell is ignored for codecs that do not have OUT6 (wm5102, wm8997,
100 wm8998, wm1814)
101
102 - wlf,spk-mute : PDM speaker mute setting, must contain 2 cells (OUT5 and OUT6).
103 See the datasheet for values.
104 The second cell is ignored for codecs that do not have OUT6 (wm5102, wm8997,
105 wm8998, wm1814)
106
107 - DCVDD-supply, MICVDD-supply : Power supplies, only need to be specified if 68 - DCVDD-supply, MICVDD-supply : Power supplies, only need to be specified if
108 they are being externally supplied. As covered in 69 they are being externally supplied. As covered in
109 Documentation/devicetree/bindings/regulator/regulator.txt 70 Documentation/devicetree/bindings/regulator/regulator.txt
@@ -112,6 +73,7 @@ Optional properties:
112Also see child specific device properties: 73Also see child specific device properties:
113 Regulator - ../regulator/arizona-regulator.txt 74 Regulator - ../regulator/arizona-regulator.txt
114 Extcon - ../extcon/extcon-arizona.txt 75 Extcon - ../extcon/extcon-arizona.txt
76 Sound - ../sound/arizona.txt
115 77
116Example: 78Example:
117 79
diff --git a/Documentation/devicetree/bindings/sound/audio-graph-card.txt b/Documentation/devicetree/bindings/sound/audio-graph-card.txt
index 6e6720aa33f1..d04ea3b1a1dd 100644
--- a/Documentation/devicetree/bindings/sound/audio-graph-card.txt
+++ b/Documentation/devicetree/bindings/sound/audio-graph-card.txt
@@ -17,6 +17,7 @@ Below are same as Simple-Card.
17- bitclock-master 17- bitclock-master
18- bitclock-inversion 18- bitclock-inversion
19- frame-inversion 19- frame-inversion
20- mclk-fs
20- dai-tdm-slot-num 21- dai-tdm-slot-num
21- dai-tdm-slot-width 22- dai-tdm-slot-width
22- clocks / system-clock-frequency 23- clocks / system-clock-frequency
diff --git a/Documentation/devicetree/bindings/sound/audio-graph-scu-card.txt b/Documentation/devicetree/bindings/sound/audio-graph-scu-card.txt
index 8b8afe9fcb31..441dd6f29df1 100644
--- a/Documentation/devicetree/bindings/sound/audio-graph-scu-card.txt
+++ b/Documentation/devicetree/bindings/sound/audio-graph-scu-card.txt
@@ -43,7 +43,7 @@ Example 1. Sampling Rate Conversion
43 label = "sound-card"; 43 label = "sound-card";
44 prefix = "codec"; 44 prefix = "codec";
45 routing = "codec Playback", "DAI0 Playback", 45 routing = "codec Playback", "DAI0 Playback",
46 "codec Playback", "DAI1 Playback"; 46 "DAI0 Capture", "codec Capture";
47 convert-rate = <48000>; 47 convert-rate = <48000>;
48 48
49 dais = <&cpu_port>; 49 dais = <&cpu_port>;
@@ -79,7 +79,8 @@ Example 2. 2 CPU 1 Codec (Mixing)
79 label = "sound-card"; 79 label = "sound-card";
80 prefix = "codec"; 80 prefix = "codec";
81 routing = "codec Playback", "DAI0 Playback", 81 routing = "codec Playback", "DAI0 Playback",
82 "codec Playback", "DAI1 Playback"; 82 "codec Playback", "DAI1 Playback",
83 "DAI0 Capture", "codec Capture";
83 convert-rate = <48000>; 84 convert-rate = <48000>;
84 85
85 dais = <&cpu_port0 86 dais = <&cpu_port0
diff --git a/Documentation/devicetree/bindings/sound/cs42l56.txt b/Documentation/devicetree/bindings/sound/cs42l56.txt
index 4feb0eb27ea4..4ba520a28ae8 100644
--- a/Documentation/devicetree/bindings/sound/cs42l56.txt
+++ b/Documentation/devicetree/bindings/sound/cs42l56.txt
@@ -55,7 +55,7 @@ Example:
55codec: codec@4b { 55codec: codec@4b {
56 compatible = "cirrus,cs42l56"; 56 compatible = "cirrus,cs42l56";
57 reg = <0x4b>; 57 reg = <0x4b>;
58 gpio-reset = <&gpio 10 0>; 58 cirrus,gpio-nreset = <&gpio 10 0>;
59 cirrus,chgfreq-divisor = <0x05>; 59 cirrus,chgfreq-divisor = <0x05>;
60 cirrus.ain1_ref_cfg; 60 cirrus.ain1_ref_cfg;
61 cirrus,micbias-lvl = <5>; 61 cirrus,micbias-lvl = <5>;
diff --git a/Documentation/devicetree/bindings/sound/rt5514.txt b/Documentation/devicetree/bindings/sound/rt5514.txt
index 929ca6756b02..4f33b0d96afe 100644
--- a/Documentation/devicetree/bindings/sound/rt5514.txt
+++ b/Documentation/devicetree/bindings/sound/rt5514.txt
@@ -1,22 +1,27 @@
1RT5514 audio CODEC 1RT5514 audio CODEC
2 2
3This device supports I2C only. 3This device supports both I2C and SPI.
4 4
5Required properties: 5Required properties:
6 6
7- compatible : "realtek,rt5514". 7- compatible : "realtek,rt5514".
8 8
9- reg : The I2C address of the device. 9- reg : the I2C address of the device for I2C, the chip select
10 number for SPI.
10 11
11Optional properties: 12Optional properties:
12 13
13- clocks: The phandle of the master clock to the CODEC 14- clocks: The phandle of the master clock to the CODEC
14- clock-names: Should be "mclk" 15- clock-names: Should be "mclk"
15 16
17- interrupt-parent: The phandle for the interrupt controller.
18- interrupts: The interrupt number to the cpu. The interrupt specifier format
19 depends on the interrupt controller.
20
16- realtek,dmic-init-delay-ms 21- realtek,dmic-init-delay-ms
17 Set the DMIC initial delay (ms) to wait it ready. 22 Set the DMIC initial delay (ms) to wait it ready for I2C.
18 23
19Pins on the device (for linking into audio routes) for RT5514: 24Pins on the device (for linking into audio routes) for I2C:
20 25
21 * DMIC1L 26 * DMIC1L
22 * DMIC1R 27 * DMIC1R
diff --git a/Documentation/devicetree/bindings/sound/rt5663.txt b/Documentation/devicetree/bindings/sound/rt5663.txt
index ff381718c517..497bcfc58b71 100644
--- a/Documentation/devicetree/bindings/sound/rt5663.txt
+++ b/Documentation/devicetree/bindings/sound/rt5663.txt
@@ -19,6 +19,22 @@ Optional properties:
19 Based on the different PCB layout, add the manual offset value to 19 Based on the different PCB layout, add the manual offset value to
20 compensate the DC offset for each L and R channel, and they are different 20 compensate the DC offset for each L and R channel, and they are different
21 between headphone and headset. 21 between headphone and headset.
22- "realtek,impedance_sensing_num"
23 The matrix row number of the impedance sensing table.
24 If the value is 0, it means the impedance sensing is not supported.
25- "realtek,impedance_sensing_table"
26 The matrix rows of the impedance sensing table are consisted by impedance
27 minimum, impedance maximun, volume, DC offset w/o and w/ mic of each L and
28 R channel accordingly. Example is shown as following.
29 < 0 300 7 0xffd160 0xffd1c0 0xff8a10 0xff8ab0
30 301 65535 4 0xffe470 0xffe470 0xffb8e0 0xffb8e0>
31 The first and second column are defined for the impedance range. If the
32 detected impedance value is in the range, then the volume value of the
33 third column will be set to codec. In our codec design, each volume value
34 should compensate different DC offset to avoid the pop sound, and it is
35 also different between headphone and headset. In the example, the
36 "realtek,impedance_sensing_num" is 2. It means that there are 2 ranges of
37 impedance in the impedance sensing function.
22 38
23Pins on the device (for linking into audio routes) for RT5663: 39Pins on the device (for linking into audio routes) for RT5663:
24 40
diff --git a/Documentation/devicetree/bindings/sound/sgtl5000.txt b/Documentation/devicetree/bindings/sound/sgtl5000.txt
index 7a73a9d62015..060cb4a3b47e 100644
--- a/Documentation/devicetree/bindings/sound/sgtl5000.txt
+++ b/Documentation/devicetree/bindings/sound/sgtl5000.txt
@@ -37,7 +37,7 @@ VDDIO 1.8V 2.5V 3.3V
37 37
38Example: 38Example:
39 39
40codec: sgtl5000@0a { 40codec: sgtl5000@a {
41 compatible = "fsl,sgtl5000"; 41 compatible = "fsl,sgtl5000";
42 reg = <0x0a>; 42 reg = <0x0a>;
43 clocks = <&clks 150>; 43 clocks = <&clks 150>;
diff --git a/Documentation/devicetree/bindings/sound/st,stm32-sai.txt b/Documentation/devicetree/bindings/sound/st,stm32-sai.txt
index f1c5ae59e7c9..1f9cd7095337 100644
--- a/Documentation/devicetree/bindings/sound/st,stm32-sai.txt
+++ b/Documentation/devicetree/bindings/sound/st,stm32-sai.txt
@@ -10,13 +10,21 @@ Required properties:
10 - reg: Base address and size of SAI common register set. 10 - reg: Base address and size of SAI common register set.
11 - clocks: Must contain phandle and clock specifier pairs for each entry 11 - clocks: Must contain phandle and clock specifier pairs for each entry
12 in clock-names. 12 in clock-names.
13 - clock-names: Must contain "x8k" and "x11k" 13 - clock-names: Must contain "pclk" "x8k" and "x11k"
14 "pclk": Clock which feeds the peripheral bus interface.
15 Mandatory for "st,stm32h7-sai" compatible.
16 Not used for "st,stm32f4-sai" compatible.
14 "x8k": SAI parent clock for sampling rates multiple of 8kHz. 17 "x8k": SAI parent clock for sampling rates multiple of 8kHz.
15 "x11k": SAI parent clock for sampling rates multiple of 11.025kHz. 18 "x11k": SAI parent clock for sampling rates multiple of 11.025kHz.
16 - interrupts: cpu DAI interrupt line shared by SAI sub-blocks 19 - interrupts: cpu DAI interrupt line shared by SAI sub-blocks
17 20
18Optional properties: 21Optional properties:
19 - resets: Reference to a reset controller asserting the SAI 22 - resets: Reference to a reset controller asserting the SAI
23 - st,sync: specify synchronization mode.
24 By default SAI sub-block is in asynchronous mode.
25 This property sets SAI sub-block as slave of another SAI sub-block.
26 Must contain the phandle and index of the sai sub-block providing
27 the synchronization.
20 28
21SAI subnodes: 29SAI subnodes:
22Two subnodes corresponding to SAI sub-block instances A et B can be defined. 30Two subnodes corresponding to SAI sub-block instances A et B can be defined.
@@ -52,8 +60,8 @@ sai1: sai1@40015800 {
52 #size-cells = <1>; 60 #size-cells = <1>;
53 ranges = <0 0x40015800 0x400>; 61 ranges = <0 0x40015800 0x400>;
54 reg = <0x40015800 0x4>; 62 reg = <0x40015800 0x4>;
55 clocks = <&rcc PLL1_Q>, <&rcc PLL2_P>; 63 clocks = <&rcc SAI1_CK>, <&rcc PLL1_Q>, <&rcc PLL2_P>;
56 clock-names = "x8k", "x11k"; 64 clock-names = "pclk", "x8k", "x11k";
57 interrupts = <87>; 65 interrupts = <87>;
58 66
59 sai1a: audio-controller@40015804 { 67 sai1a: audio-controller@40015804 {
diff --git a/Documentation/devicetree/bindings/sound/tfa9879.txt b/Documentation/devicetree/bindings/sound/tfa9879.txt
new file mode 100644
index 000000000000..23ba522d9e2b
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/tfa9879.txt
@@ -0,0 +1,23 @@
1NXP TFA9879 class-D audio amplifier
2
3Required properties:
4
5- compatible : "nxp,tfa9879"
6
7- reg : the I2C address of the device
8
9Example:
10
11&i2c1 {
12 clock-frequency = <100000>;
13 pinctrl-names = "default";
14 pinctrl-0 = <&pinctrl_i2c1>;
15 status = "okay";
16
17 codec: tfa9879@6c {
18 #sound-dai-cells = <0>;
19 compatible = "nxp,tfa9879";
20 reg = <0x6c>;
21 };
22};
23
diff --git a/Documentation/devicetree/bindings/sound/wlf,arizona.txt b/Documentation/devicetree/bindings/sound/wlf,arizona.txt
new file mode 100644
index 000000000000..e172c62dc2df
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/wlf,arizona.txt
@@ -0,0 +1,53 @@
1Cirrus Logic Arizona class audio SoCs
2
3These devices are audio SoCs with extensive digital capabilities and a range
4of analogue I/O.
5
6This document lists sound specific bindings, see the primary binding
7document:
8 ../mfd/arizona.txt
9
10Optional properties:
11
12 - wlf,inmode : A list of INn_MODE register values, where n is the number
13 of input signals. Valid values are 0 (Differential), 1 (Single-ended) and
14 2 (Digital Microphone). If absent, INn_MODE registers set to 0 by default.
15 If present, values must be specified less than or equal to the number of
16 input signals. If values less than the number of input signals, elements
17 that have not been specified are set to 0 by default. Entries are:
18 <IN1, IN2, IN3, IN4> (wm5102, wm5110, wm8280, wm8997)
19 <IN1A, IN2A, IN1B, IN2B> (wm8998, wm1814)
20 - wlf,out-mono : A list of boolean values indicating whether each output is
21 mono or stereo. Position within the list indicates the output affected
22 (eg. First entry in the list corresponds to output 1). A non-zero value
23 indicates a mono output. If present, the number of values should be less
24 than or equal to the number of outputs, if less values are supplied the
25 additional outputs will be treated as stereo.
26
27 - wlf,dmic-ref : DMIC reference voltage source for each input, can be
28 selected from either MICVDD or one of the MICBIAS's, defines
29 (ARIZONA_DMIC_xxxx) are provided in <dt-bindings/mfd/arizona.txt>. If
30 present, the number of values should be less than or equal to the
31 number of inputs, unspecified inputs will use the chip default.
32
33 - wlf,max-channels-clocked : The maximum number of channels to be clocked on
34 each AIF, useful for I2S systems with multiple data lines being mastered.
35 Specify one cell for each AIF to be configured, specify zero for AIFs that
36 should be handled normally.
37 If present, number of cells must be less than or equal to the number of
38 AIFs. If less than the number of AIFs, for cells that have not been
39 specified the corresponding AIFs will be treated as default setting.
40
41 - wlf,spk-fmt : PDM speaker data format, must contain 2 cells (OUT5 and OUT6).
42 See the datasheet for values.
43 The second cell is ignored for codecs that do not have OUT6 (wm5102, wm8997,
44 wm8998, wm1814)
45
46 - wlf,spk-mute : PDM speaker mute setting, must contain 2 cells (OUT5 and OUT6).
47 See the datasheet for values.
48 The second cell is ignored for codecs that do not have OUT6 (wm5102, wm8997,
49 wm8998, wm1814)
50
51 - wlf,out-volume-limit : The volume limit value that should be applied to each
52 output channel. See the datasheet for exact values. Channels are specified
53 in the order OUT1L, OUT1R, OUT2L, OUT2R, etc.
diff --git a/Documentation/sound/hd-audio/models.rst b/Documentation/sound/hd-audio/models.rst
index 773d2bfacc6c..1fee5a4f6660 100644
--- a/Documentation/sound/hd-audio/models.rst
+++ b/Documentation/sound/hd-audio/models.rst
@@ -82,6 +82,8 @@ tpt460
82 Lenovo Thinkpad T460/560 setup 82 Lenovo Thinkpad T460/560 setup
83dual-codecs 83dual-codecs
84 Lenovo laptops with dual codecs 84 Lenovo laptops with dual codecs
85alc700-ref
86 Intel reference board with ALC700 codec
85 87
86ALC66x/67x/892 88ALC66x/67x/892
87============== 89==============
diff --git a/Documentation/sound/oss/ALS b/Documentation/sound/oss/ALS
deleted file mode 100644
index bf10bed4574b..000000000000
--- a/Documentation/sound/oss/ALS
+++ /dev/null
@@ -1,66 +0,0 @@
1ALS-007/ALS-100/ALS-200 based sound cards
2=========================================
3
4Support for sound cards based around the Avance Logic
5ALS-007/ALS-100/ALS-200 chip is included. These chips are a single
6chip PnP sound solution which is mostly hardware compatible with the
7Sound Blaster 16 card, with most differences occurring in the use of
8the mixer registers. For this reason the ALS code is integrated
9as part of the Sound Blaster 16 driver (adding only 800 bytes to the
10SB16 driver).
11
12To use an ALS sound card under Linux, enable the following options as
13modules in the sound configuration section of the kernel config:
14 - 100% Sound Blaster compatibles (SB16/32/64, ESS, Jazz16) support
15 - FM synthesizer (YM3812/OPL-3) support
16 - standalone MPU401 support may be required for some cards; for the
17 ALS-007, when using isapnptools, it is required
18Since the ALS-007/100/200 are PnP cards, ISAPnP support should probably be
19compiled in. If kernel level PnP support is not included, isapnptools will
20be required to configure the card before the sound modules are loaded.
21
22When using kernel level ISAPnP, the kernel should correctly identify and
23configure all resources required by the card when the "sb" module is
24inserted. Note that the ALS-007 does not have a 16 bit DMA channel and that
25the MPU401 interface on this card uses a different interrupt to the audio
26section. This should all be correctly configured by the kernel; if problems
27with the MPU401 interface surface, try using the standalone MPU401 module,
28passing "0" as the "sb" module's "mpu_io" module parameter to prevent the
29soundblaster driver attempting to register the MPU401 itself. The onboard
30synth device can be accessed using the "opl3" module.
31
32If isapnptools is used to wake up the sound card (as in 2.2.x), the settings
33of the card's resources should be passed to the kernel modules ("sb", "opl3"
34and "mpu401") using the module parameters. When configuring an ALS-007, be
35sure to specify different IRQs for the audio and MPU401 sections - this card
36requires they be different. For "sb", "io", "irq" and "dma" should be set
37to the same values used to configure the audio section of the card with
38isapnp. "dma16" should be explicitly set to "-1" for an ALS-007 since this
39card does not have a 16 bit dma channel; if not specified the kernel will
40default to using channel 5 anyway which will cause audio not to work.
41"mpu_io" should be set to 0. The "io" parameter of the "opl3" module should
42also agree with the setting used by isapnp. To get the MPU401 interface
43working on an ALS-007 card, the "mpu401" module will be required since this
44card uses separate IRQs for the audio and MPU401 sections and there is no
45parameter available to pass a different IRQ to the "sb" driver (whose
46inbuilt MPU401 driver would otherwise be fine). Insert the mpu401 module
47passing appropriate values using the "io" and "irq" parameters.
48
49The resulting sound driver will provide the following capabilities:
50 - 8 and 16 bit audio playback
51 - 8 and 16 bit audio recording
52 - Software selection of record source (line in, CD, FM, mic, master)
53 - Record and playback of midi data via the external MPU-401
54 - Playback of midi data using inbuilt FM synthesizer
55 - Control of the ALS-007 mixer via any OSS-compatible mixer programs.
56 Controls available are Master (L&R), Line in (L&R), CD (L&R),
57 DSP/PCM/audio out (L&R), FM (L&R) and Mic in (mono).
58
59Jonathan Woithe
60jwoithe@just42.net
6130 March 1998
62
63Modified 2000-02-26 by Dave Forrest, drf5n@virginia.edu to add ALS100/ALS200
64Modified 2000-04-10 by Paul Laufer, pelaufer@csupomona.edu to add ISAPnP info.
65Modified 2000-11-19 by Jonathan Woithe, jwoithe@just42.net
66 - updated information for kernel 2.4.x.
diff --git a/Documentation/sound/oss/AudioExcelDSP16 b/Documentation/sound/oss/AudioExcelDSP16
deleted file mode 100644
index ea8549faede9..000000000000
--- a/Documentation/sound/oss/AudioExcelDSP16
+++ /dev/null
@@ -1,101 +0,0 @@
1Driver
2------
3
4Information about Audio Excel DSP 16 driver can be found in the source
5file aedsp16.c
6Please, read the head of the source before using it. It contain useful
7information.
8
9Configuration
10-------------
11
12The Audio Excel configuration, is now done with the standard Linux setup.
13You have to configure the sound card (Sound Blaster or Microsoft Sound System)
14and, if you want it, the Roland MPU-401 (do not use the Sound Blaster MPU-401,
15SB-MPU401) in the main driver menu. Activate the lowlevel drivers then select
16the Audio Excel hardware that you want to initialize. Check the IRQ/DMA/MIRQ
17of the Audio Excel initialization: it must be the same as the SBPRO (or MSS)
18setup. If the parameters are different, correct it.
19I you own a Gallant's audio card based on SC-6600, activate the SC-6600 support.
20If you want to change the configuration of the sound board, be sure to
21check off all the configuration items before re-configure it.
22
23Module parameters
24-----------------
25To use this driver as a module, you must configure some module parameters, to
26set up I/O addresses, IRQ lines and DMA channels. Some parameters are
27mandatory while some others are optional. Here a list of parameters you can
28use with this module:
29
30Name Description
31==== ===========
32MANDATORY
33io I/O base address (0x220 or 0x240)
34irq irq line (5, 7, 9, 10 or 11)
35dma dma channel (0, 1 or 3)
36
37OPTIONAL
38mss_base I/O base address for activate MSS mode (default SBPRO)
39 (0x530 or 0xE80)
40mpu_base I/O base address for activate MPU-401 mode
41 (0x300, 0x310, 0x320 or 0x330)
42mpu_irq MPU-401 irq line (5, 7, 9, 10 or 0)
43
44A configuration file in /etc/modprobe.d/ directory will have lines like this:
45
46options opl3 io=0x388
47options ad1848 io=0x530 irq=11 dma=3
48options aedsp16 io=0x220 irq=11 dma=3 mss_base=0x530
49
50Where the aedsp16 options are the options for this driver while opl3 and
51ad1848 are the corresponding options for the MSS and OPL3 modules.
52
53Loading MSS and OPL3 needs to pre load the aedsp16 module to set up correctly
54the sound card. Installation dependencies must be written in configuration
55files under /etc/modprobe.d/ directory:
56
57softdep ad1848 pre: aedsp16
58softdep opl3 pre: aedsp16
59
60Then you must load the sound modules stack in this order:
61sound -> aedsp16 -> [ ad1848, opl3 ]
62
63With the above configuration, loading ad1848 or opl3 modules, will
64automatically load all the sound stack.
65
66Sound cards supported
67---------------------
68This driver supports the SC-6000 and SC-6600 based Gallant's sound card.
69It don't support the Audio Excel DSP 16 III (try the SC-6600 code).
70I'm working on the III version of the card: if someone have useful
71information about it, please let me know.
72For all the non-supported audio cards, you have to boot MS-DOS (or WIN95)
73activating the audio card with the MS-DOS device driver, then you have to
74<ctrl>-<alt>-<del> and boot Linux.
75Follow these steps:
76
771) Compile Linux kernel with standard sound driver, using the emulation
78 you want, with the parameters of your audio card,
79 e.g. Microsoft Sound System irq10 dma3
802) Install your new kernel as the default boot kernel.
813) Boot MS-DOS and configure the audio card with the boot time device
82 driver, for MSS irq10 dma3 in our example.
834) <ctrl>-<alt>-<del> and boot Linux. This will maintain the DOS configuration
84 and will boot the new kernel with sound driver. The sound driver will find
85 the audio card and will recognize and attach it.
86
87Reports on User successes
88-------------------------
89
90> Date: Mon, 29 Jul 1996 08:35:40 +0100
91> From: Mr S J Greenaway <sjg95@unixfe.rl.ac.uk>
92> To: riccardo@cdc8g5.cdc.polimi.it (Riccardo Facchetti)
93> Subject: Re: Audio Excel DSP 16 initialization code
94>
95> Just to let you know got my Audio Excel (emulating a MSS) working
96> with my original SB16, thanks for the driver!
97
98
99Last revised: 20 August 1998
100Riccardo Facchetti
101fizban@tin.it
diff --git a/Documentation/sound/oss/CMI8330 b/Documentation/sound/oss/CMI8330
deleted file mode 100644
index 8a5fd1611c6f..000000000000
--- a/Documentation/sound/oss/CMI8330
+++ /dev/null
@@ -1,152 +0,0 @@
1Documentation for CMI 8330 (SoundPRO)
2-------------------------------------
3Alessandro Zummo <azummo@ita.flashnet.it>
4
5( Be sure to read Documentation/sound/oss/SoundPro too )
6
7
8This adapter is now directly supported by the sb driver.
9
10 The only thing you have to do is to compile the kernel sound
11support as a module and to enable kernel ISAPnP support,
12as shown below.
13
14
15CONFIG_SOUND=m
16CONFIG_SOUND_SB=m
17
18CONFIG_PNP=y
19CONFIG_ISAPNP=y
20
21
22and optionally:
23
24
25CONFIG_SOUND_MPU401=m
26
27 for MPU401 support.
28
29
30(I suggest you to use "make menuconfig" or "make xconfig"
31 for a more comfortable configuration editing)
32
33
34
35Then you can do
36
37 modprobe sb
38
39and everything will be (hopefully) configured.
40
41You should get something similar in syslog:
42
43sb: CMI8330 detected.
44sb: CMI8330 sb base located at 0x220
45sb: CMI8330 mpu base located at 0x330
46sb: CMI8330 mail reports to Alessandro Zummo <azummo@ita.flashnet.it>
47sb: ISAPnP reports CMI 8330 SoundPRO at i/o 0x220, irq 7, dma 1,5
48
49
50
51
52The old documentation file follows for reference
53purposes.
54
55
56How to enable CMI 8330 (SOUNDPRO) soundchip on Linux
57------------------------------------------
58Stefan Laudat <Stefan.Laudat@asit.ro>
59
60[Note: The CMI 8338 is unrelated and is supported by cmpci.o]
61
62
63 In order to use CMI8330 under Linux you just have to use a proper isapnp.conf, a good isapnp and a little bit of patience. I use isapnp 1.17, but
64you may get a better one I guess at http://www.roestock.demon.co.uk/isapnptools/.
65
66 Of course you will have to compile kernel sound support as module, as shown below:
67
68CONFIG_SOUND=m
69CONFIG_SOUND_OSS=m
70CONFIG_SOUND_SB=m
71CONFIG_SOUND_ADLIB=m
72CONFIG_SOUND_MPU401=m
73# Mikro$chaft sound system (kinda useful here ;))
74CONFIG_SOUND_MSS=m
75
76 The /etc/isapnp.conf file will be:
77
78<snip below>
79
80
81(READPORT 0x0203)
82(ISOLATE PRESERVE)
83(IDENTIFY *)
84(VERBOSITY 2)
85(CONFLICT (IO FATAL)(IRQ FATAL)(DMA FATAL)(MEM FATAL)) # or WARNING
86(VERIFYLD N)
87
88
89# WSS
90
91(CONFIGURE CMI0001/16777472 (LD 0
92(IO 0 (SIZE 8) (BASE 0x0530))
93(IO 1 (SIZE 8) (BASE 0x0388))
94(INT 0 (IRQ 7 (MODE +E)))
95(DMA 0 (CHANNEL 0))
96(NAME "CMI0001/16777472[0]{CMI8330/C3D Audio Adapter}")
97(ACT Y)
98))
99
100# MPU
101
102(CONFIGURE CMI0001/16777472 (LD 1
103(IO 0 (SIZE 2) (BASE 0x0330))
104(INT 0 (IRQ 11 (MODE +E)))
105(NAME "CMI0001/16777472[1]{CMI8330/C3D Audio Adapter}")
106(ACT Y)
107))
108
109# Joystick
110
111(CONFIGURE CMI0001/16777472 (LD 2
112(IO 0 (SIZE 8) (BASE 0x0200))
113(NAME "CMI0001/16777472[2]{CMI8330/C3D Audio Adapter}")
114(ACT Y)
115))
116
117# SoundBlaster
118
119(CONFIGURE CMI0001/16777472 (LD 3
120(IO 0 (SIZE 16) (BASE 0x0220))
121(INT 0 (IRQ 5 (MODE +E)))
122(DMA 0 (CHANNEL 1))
123(DMA 1 (CHANNEL 5))
124(NAME "CMI0001/16777472[3]{CMI8330/C3D Audio Adapter}")
125(ACT Y)
126))
127
128
129(WAITFORKEY)
130
131<end of snip>
132
133 The module sequence is trivial:
134
135/sbin/insmod soundcore
136/sbin/insmod sound
137/sbin/insmod uart401
138# insert this first
139/sbin/insmod ad1848 io=0x530 irq=7 dma=0 soundpro=1
140# The sb module is an alternative to the ad1848 (Microsoft Sound System)
141# Anyhow, this is full duplex and has MIDI
142/sbin/insmod sb io=0x220 dma=1 dma16=5 irq=5 mpu_io=0x330
143
144
145
146Alma Chao <elysian@ethereal.torsion.org> suggests the following in
147a /etc/modprobe.d/*conf file:
148
149alias sound ad1848
150alias synth0 opl3
151options ad1848 io=0x530 irq=7 dma=0 soundpro=1
152options opl3 io=0x388
diff --git a/Documentation/sound/oss/ESS b/Documentation/sound/oss/ESS
deleted file mode 100644
index bba93b4d2def..000000000000
--- a/Documentation/sound/oss/ESS
+++ /dev/null
@@ -1,34 +0,0 @@
1Documentation for the ESS AudioDrive chips
2
3In 2.4 kernels the SoundBlaster driver not only tries to detect an ESS chip, it
4tries to detect the type of ESS chip too. The correct detection of the chip
5doesn't always succeed however, so unless you use the kernel isapnp facilities
6(and you chip is pnp capable) the default behaviour is 2.0 behaviour which
7means: only detect ES688 and ES1688.
8
9All ESS chips now have a recording level setting. This is a need-to-have for
10people who want to use their ESS for recording sound.
11
12Every chip that's detected as a later-than-es1688 chip has a 6 bits logarithmic
13master volume control.
14
15Every chip that's detected as a ES1887 now has Full Duplex support. Made a
16little testprogram that shows that is works, haven't seen a real program that
17needs this however.
18
19For ESS chips an additional parameter "esstype" can be specified. This controls
20the (auto) detection of the ESS chips. It can have 3 kinds of values:
21
22-1 Act like 2.0 kernels: only detect ES688 or ES1688.
230 Try to auto-detect the chip (may fail for ES1688)
24688 The chip will be treated as ES688
251688 ,, ,, ,, ,, ,, ,, ES1688
261868 ,, ,, ,, ,, ,, ,, ES1868
271869 ,, ,, ,, ,, ,, ,, ES1869
281788 ,, ,, ,, ,, ,, ,, ES1788
291887 ,, ,, ,, ,, ,, ,, ES1887
301888 ,, ,, ,, ,, ,, ,, ES1888
31
32Because Full Duplex is supported for ES1887 you can specify a second DMA
33channel by specifying module parameter dma16. It can be one of: 0, 1, 3 or 5.
34
diff --git a/Documentation/sound/oss/ESS1868 b/Documentation/sound/oss/ESS1868
deleted file mode 100644
index 55e922f21bc0..000000000000
--- a/Documentation/sound/oss/ESS1868
+++ /dev/null
@@ -1,55 +0,0 @@
1Documentation for the ESS1868F AudioDrive PnP sound card
2
3The ESS1868 sound card is a PnP ESS1688-compatible 16-bit sound card.
4
5It should be automatically detected by the Linux Kernel isapnp support when you
6load the sb.o module. Otherwise you should take care of:
7
8 * The ESS1868 does not allow use of a 16-bit DMA, thus DMA 0, 1, 2, and 3
9 may only be used.
10
11 * isapnptools version 1.14 does work with ESS1868. Earlier versions might
12 not.
13
14 * Sound support MUST be compiled as MODULES, not statically linked
15 into the kernel.
16
17
18NOTE: this is only needed when not using the kernel isapnp support!
19
20For configuring the sound card's I/O addresses, IRQ and DMA, here is a
21sample copy of the isapnp.conf directives regarding the ESS1868:
22
23(CONFIGURE ESS1868/-1 (LD 1
24(IO 0 (BASE 0x0220))
25(IO 1 (BASE 0x0388))
26(IO 2 (BASE 0x0330))
27(DMA 0 (CHANNEL 1))
28(INT 0 (IRQ 5 (MODE +E)))
29(ACT Y)
30))
31
32(for a full working isapnp.conf file, remember the
33(ISOLATE)
34(IDENTIFY *)
35at the beginning and the
36(WAITFORKEY)
37at the end.)
38
39In this setup, the main card I/O is 0x0220, FM synthesizer is 0x0388, and
40the MPU-401 MIDI port is located at 0x0330. IRQ is IRQ 5, DMA is channel 1.
41
42After configuring the sound card via isapnp, to use the card you must load
43the sound modules with the proper I/O information. Here is my setup:
44
45# ESS1868F AudioDrive initialization
46
47/sbin/modprobe sound
48/sbin/insmod uart401
49/sbin/insmod sb io=0x220 irq=5 dma=1 dma16=-1
50/sbin/insmod mpu401 io=0x330
51/sbin/insmod opl3 io=0x388
52/sbin/insmod v_midi
53
54opl3 is the FM synthesizer
55/sbin/insmod opl3 io=0x388
diff --git a/Documentation/sound/oss/Introduction b/Documentation/sound/oss/Introduction
deleted file mode 100644
index 42da2d8fa372..000000000000
--- a/Documentation/sound/oss/Introduction
+++ /dev/null
@@ -1,459 +0,0 @@
1Introduction Notes on Modular Sound Drivers and Soundcore
2Wade Hampton
32/14/2001
4
5Purpose:
6========
7This document provides some general notes on the modular
8sound drivers and their configuration, along with the
9support modules sound.o and soundcore.o.
10
11Note, some of this probably should be added to the Sound-HOWTO!
12
13Note, soundlow.o was present with 2.2 kernels but is not
14required for 2.4.x kernels. References have been removed
15to this.
16
17
18Copying:
19========
20none
21
22
23History:
24========
250.1.0 11/20/1998 First version, draft
261.0.0 11/1998 Alan Cox changes, incorporation in 2.2.0
27 as Documentation/sound/oss/Introduction
281.1.0 6/30/1999 Second version, added notes on making the drivers,
29 added info on multiple sound cards of similar types,]
30 added more diagnostics info, added info about esd.
31 added info on OSS and ALSA.
321.1.1 19991031 Added notes on sound-slot- and sound-service.
33 (Alan Cox)
341.1.2 20000920 Modified for Kernel 2.4 (Christoph Hellwig)
351.1.3 20010214 Minor notes and corrections (Wade Hampton)
36 Added examples of sound-slot-0, etc.
37
38
39Modular Sound Drivers:
40======================
41
42Thanks to the GREAT work by Alan Cox (alan@lxorguk.ukuu.org.uk),
43
44[And Oleg Drokin, Thomas Sailer, Andrew Veliath and more than a few
45 others - not to mention Hannu's original code being designed well
46 enough to cope with that kind of chopping up](Alan)
47
48the standard Linux kernels support a modular sound driver. From
49Alan's comments in linux/drivers/sound/README.FIRST:
50
51 The modular sound driver patches were funded by Red Hat Software
52 (www.redhat.com). The sound driver here is thus a modified version of
53 Hannu's code. Please bear that in mind when considering the appropriate
54 forums for bug reporting.
55
56The modular sound drivers may be loaded via insmod or modprobe.
57To support all the various sound modules, there are two general
58support modules that must be loaded first:
59
60 soundcore.o: Top level handler for the sound system, provides
61 a set of functions for registration of devices
62 by type.
63
64 sound.o: Common sound functions required by all modules.
65
66For the specific sound modules (e.g., sb.o for the Soundblaster),
67read the documentation on that module to determine what options
68are available, for example IRQ, address, DMA.
69
70Warning, the options for different cards sometime use different names
71for the same or a similar feature (dma1= versus dma16=). As a last
72resort, inspect the code (search for module_param).
73
74Notes:
75
761. There is a new OpenSource sound driver called ALSA which is
77 currently under development: http://www.alsa-project.org/
78 The ALSA drivers support some newer hardware that may not
79 be supported by this sound driver and also provide some
80 additional features.
81
822. The commercial OSS driver may be obtained from the site:
83 http://www.opensound.com. This may be used for cards that
84 are unsupported by the kernel driver, or may be used
85 by other operating systems.
86
873. The enlightenment sound daemon may be used for playing
88 multiple sounds at the same time via a single card, eliminating
89 some of the requirements for multiple sound card systems. For
90 more information, see: http://www.tux.org/~ricdude/EsounD.html
91 The "esd" program may be used with the real-player and mpeg
92 players like mpg123 and x11amp. The newer real-player
93 and some games even include built-in support for ESD!
94
95
96Building the Modules:
97=====================
98
99This document does not provide full details on building the
100kernel, etc. The notes below apply only to making the kernel
101sound modules. If this conflicts with the kernel's README,
102the README takes precedence.
103
1041. To make the kernel sound modules, cd to your /usr/src/linux
105 directory (typically) and type make config, make menuconfig,
106 or make xconfig (to start the command line, dialog, or x-based
107 configuration tool).
108
1092. Select the Sound option and a dialog will be displayed.
110
1113. Select M (module) for "Sound card support".
112
1134. Select your sound driver(s) as a module. For ProAudio, Sound
114 Blaster, etc., select M (module) for OSS sound modules.
115 [thanks to Marvin Stodolsky <stodolsk@erols.com>]A
116
1175. Make the kernel (e.g., make bzImage), and install the kernel.
118
1196. Make the modules and install them (make modules; make modules_install).
120
121Note, for 2.5.x kernels, make sure you have the newer module-init-tools
122installed or modules will not be loaded properly. 2.5.x requires an
123updated module-init-tools.
124
125
126Plug and Play (PnP:
127===================
128
129If the sound card is an ISA PnP card, isapnp may be used
130to configure the card. See the file isapnp.txt in the
131directory one level up (e.g., /usr/src/linux/Documentation).
132
133Also the 2.4.x kernels provide PnP capabilities, see the
134file NEWS in this directory.
135
136PCI sound cards are highly recommended, as they are far
137easier to configure and from what I have read, they use
138less resources and are more CPU efficient.
139
140
141INSMOD:
142=======
143
144If loading via insmod, the common modules must be loaded in the
145order below BEFORE loading the other sound modules. The card-specific
146modules may then be loaded (most require parameters). For example,
147I use the following via a shell script to load my SoundBlaster:
148
149SB_BASE=0x240
150SB_IRQ=9
151SB_DMA=3
152SB_DMA2=5
153SB_MPU=0x300
154#
155echo Starting sound
156/sbin/insmod soundcore
157/sbin/insmod sound
158#
159echo Starting sound blaster....
160/sbin/insmod uart401
161/sbin/insmod sb io=$SB_BASE irq=$SB_IRQ dma=$SB_DMA dma16=$SB_DMA2 mpu_io=$SB_MP
162
163When using sound as a module, I typically put these commands
164in a file such as /root/soundon.sh.
165
166
167MODPROBE:
168=========
169
170If loading via modprobe, these common files are automatically loaded when
171requested by modprobe. For example, my /etc/modprobe.d/oss.conf contains:
172
173alias sound sb
174options sb io=0x240 irq=9 dma=3 dma16=5 mpu_io=0x300
175
176All you need to do to load the module is:
177
178 /sbin/modprobe sb
179
180
181Sound Status:
182=============
183
184The status of sound may be read/checked by:
185 cat (anyfile).au >/dev/audio
186
187[WWH: This may not work properly for SoundBlaster PCI 128 cards
188such as the es1370/1 (see the es1370/1 files in this directory)
189as they do not automatically support uLaw on /dev/audio.]
190
191The status of the modules and which modules depend on
192which other modules may be checked by:
193 /sbin/lsmod
194
195/sbin/lsmod should show something like the following:
196 sb 26280 0
197 uart401 5640 0 [sb]
198 sound 57112 0 [sb uart401]
199 soundcore 1968 8 [sb sound]
200
201
202Removing Sound:
203===============
204
205Sound may be removed by using /sbin/rmmod in the reverse order
206in which you load the modules. Note, if a program has a sound device
207open (e.g., xmixer), that module (and the modules on which it
208depends) may not be unloaded.
209
210For example, I use the following to remove my Soundblaster (rmmod
211in the reverse order in which I loaded the modules):
212
213/sbin/rmmod sb
214/sbin/rmmod uart401
215/sbin/rmmod sound
216/sbin/rmmod soundcore
217
218When using sound as a module, I typically put these commands
219in a script such as /root/soundoff.sh.
220
221
222Removing Sound for use with OSS:
223================================
224
225If you get really stuck or have a card that the kernel modules
226will not support, you can get a commercial sound driver from
227http://www.opensound.com. Before loading the commercial sound
228driver, you should do the following:
229
2301. remove sound modules (detailed above)
2312. remove the sound modules from /etc/modprobe.d/*.conf
2323. move the sound modules from /lib/modules/<kernel>/misc
233 (for example, I make a /lib/modules/<kernel>/misc/tmp
234 directory and copy the sound module files to that
235 directory).
236
237
238Multiple Sound Cards:
239=====================
240
241The sound drivers will support multiple sound cards and there
242are some great applications like multitrack that support them.
243Typically, you need two sound cards of different types. Note, this
244uses more precious interrupts and DMA channels and sometimes
245can be a configuration nightmare. I have heard reports of 3-4
246sound cards (typically I only use 2). You can sometimes use
247multiple PCI sound cards of the same type.
248
249On my machine I have two sound cards (cs4232 and Soundblaster Vibra
25016). By loading sound as modules, I can control which is the first
251sound device (/dev/dsp, /dev/audio, /dev/mixer) and which is
252the second. Normally, the cs4232 (Dell sound on the motherboard)
253would be the first sound device, but I prefer the Soundblaster.
254All you have to do is to load the one you want as /dev/dsp
255first (in my case "sb") and then load the other one
256(in my case "cs4232").
257
258If you have two cards of the same type that are jumpered
259cards or different PnP revisions, you may load the same
260module twice. For example, I have a SoundBlaster vibra 16
261and an older SoundBlaster 16 (jumpers). To load the module
262twice, you need to do the following:
263
2641. Copy the sound modules to a new name. For example
265 sb.o could be copied (or symlinked) to sb1.o for the
266 second SoundBlaster.
267
2682. Make a second entry in /etc/modprobe.d/*conf, for example,
269 sound1 or sb1. This second entry should refer to the
270 new module names for example sb1, and should include
271 the I/O, etc. for the second sound card.
272
2733. Update your soundon.sh script, etc.
274
275Warning: I have never been able to get two PnP sound cards of the
276same type to load at the same time. I have tried this several times
277with the Soundblaster Vibra 16 cards. OSS has indicated that this
278is a PnP problem.... If anyone has any luck doing this, please
279send me an E-MAIL. PCI sound cards should not have this problem.a
280Since this was originally release, I have received a couple of
281mails from people who have accomplished this!
282
283NOTE: In Linux 2.4 the Sound Blaster driver (and only this one yet)
284supports multiple cards with one module by default.
285Read the file 'Soundblaster' in this directory for details.
286
287
288Sound Problems:
289===============
290
291First RTFM (including the troubleshooting section
292in the Sound-HOWTO).
293
2941) If you are having problems loading the modules (for
295 example, if you get device conflict errors) try the
296 following:
297
298 A) If you have Win95 or NT on the same computer,
299 write down what addresses, IRQ, and DMA channels
300 those were using for the same hardware. You probably
301 can use these addresses, IRQs, and DMA channels.
302 You should really do this BEFORE attempting to get
303 sound working!
304
305 B) Check (cat) /proc/interrupts, /proc/ioports,
306 and /proc/dma. Are you trying to use an address,
307 IRQ or DMA port that another device is using?
308
309 C) Check (cat) /proc/isapnp
310
311 D) Inspect your /var/log/messages file. Often that will
312 indicate what IRQ or IO port could not be obtained.
313
314 E) Try another port or IRQ. Note this may involve
315 using the PnP tools to move the sound card to
316 another location. Sometimes this is the only way
317 and it is more or less trial and error.
318
3192) If you get motor-boating (the same sound or part of a
320 sound clip repeated), you probably have either an IRQ
321 or DMA conflict. Move the card to another IRQ or DMA
322 port. This has happened to me when playing long files
323 when I had an IRQ conflict.
324
3253. If you get dropouts or pauses when playing high sample
326 rate files such as using mpg123 or x11amp/xmms, you may
327 have too slow of a CPU and may have to use the options to
328 play the files at 1/2 speed. For example, you may use
329 the -2 or -4 option on mpg123. You may also get this
330 when trying to play mpeg files stored on a CD-ROM
331 (my Toshiba T8000 PII/366 sometimes has this problem).
332
3334. If you get "cannot access device" errors, your /dev/dsp
334 files, etc. may be set to owner root, mode 600. You
335 may have to use the command:
336 chmod 666 /dev/dsp /dev/mixer /dev/audio
337
3385. If you get "device busy" errors, another program has the
339 sound device open. For example, if using the Enlightenment
340 sound daemon "esd", the "esd" program has the sound device.
341 If using "esd", please RTFM the docs on ESD. For example,
342 esddsp <program> may be used to play files via a non-esd
343 aware program.
344
3456) Ask for help on the sound list or send E-MAIL to the
346 sound driver author/maintainer.
347
3487) Turn on debug in drivers/sound/sound_config.h (DEB, DDB, MDB).
349
3508) If the system reports insufficient DMA memory then you may want to
351 load sound with the "dmabufs=1" option. Or in /etc/conf.modules add
352
353 preinstall sound dmabufs=1
354
355 This makes the sound system allocate its buffers and hang onto them.
356
357 You may also set persistent DMA when building a 2.4.x kernel.
358
359
360Configuring Sound:
361==================
362
363There are several ways of configuring your sound:
364
3651) On the kernel command line (when using the sound driver(s)
366 compiled in the kernel). Check the driver source and
367 documentation for details.
368
3692) On the command line when using insmod or in a bash script
370 using command line calls to load sound.
371
3723) In /etc/modprobe.d/*conf when using modprobe.
373
3744) Via Red Hat's GPL'd /usr/sbin/sndconfig program (text based).
375
3765) Via the OSS soundconf program (with the commercial version
377 of the OSS driver.
378
3796) By just loading the module and let isapnp do everything relevant
380 for you. This works only with a few drivers yet and - of course -
381 only with isapnp hardware.
382
383And I am sure, several other ways.
384
385Anyone want to write a linuxconf module for configuring sound?
386
387
388Module Loading:
389===============
390
391When a sound card is first referenced and sound is modular, the sound system
392will ask for the sound devices to be loaded. Initially it requests that
393the driver for the sound system is loaded. It then will ask for
394sound-slot-0, where 0 is the first sound card. (sound-slot-1 the second and
395so on). Thus you can do
396
397alias sound-slot-0 sb
398
399To load a soundblaster at this point. If the slot loading does not provide
400the desired device - for example a soundblaster does not directly provide
401a midi synth in all cases then it will request "sound-service-0-n" where n
402is
403
404 0 Mixer
405
406 2 MIDI
407
408 3, 4 DSP audio
409
410
411For example, I use the following to load my Soundblaster PCI 128
412(ES 1371) card first, followed by my SoundBlaster Vibra 16 card,
413then by my TV card:
414
415# Load the Soundblaster PCI 128 as /dev/dsp, /dev/dsp1, /dev/mixer
416alias sound-slot-0 es1371
417
418# Load the Soundblaster Vibra 16 as /dev/dsp2, /dev/mixer1
419alias sound-slot-1 sb
420options sb io=0x240 irq=5 dma=1 dma16=5 mpu_io=0x330
421
422# Load the BTTV (TV card) as /dev/mixer2
423alias sound-slot-2 bttv
424alias sound-service-2-0 tvmixer
425
426pre-install bttv modprobe tuner ; modprobe tvmixer
427pre-install tvmixer modprobe msp3400; modprobe tvaudio
428options tuner debug=0 type=8
429options bttv card=0 radio=0 pll=0
430
431
432For More Information (RTFM):
433============================
4341) Information on kernel modules: manual pages for insmod and modprobe.
435
4362) Information on PnP, RTFM manual pages for isapnp.
437
4383) Sound-HOWTO and Sound-Playing-HOWTO.
439
4404) OSS's WWW site at http://www.opensound.com.
441
4425) All the files in Documentation/sound.
443
4446) The comments and code in linux/drivers/sound.
445
4467) The sndconfig and rhsound documentation from Red Hat.
447
4488) The Linux-sound mailing list: sound-list@redhat.com.
449
4509) Enlightenment documentation (for info on esd)
451 http://www.tux.org/~ricdude/EsounD.html.
452
45310) ALSA home page: http://www.alsa-project.org/
454
455
456Contact Information:
457====================
458Wade Hampton: (whampton@staffnet.com)
459
diff --git a/Documentation/sound/oss/MultiSound b/Documentation/sound/oss/MultiSound
deleted file mode 100644
index e4a18bb7f73a..000000000000
--- a/Documentation/sound/oss/MultiSound
+++ /dev/null
@@ -1,1137 +0,0 @@
1#! /bin/sh
2#
3# Turtle Beach MultiSound Driver Notes
4# -- Andrew Veliath <andrewtv@usa.net>
5#
6# Last update: September 10, 1998
7# Corresponding msnd driver: 0.8.3
8#
9# ** This file is a README (top part) and shell archive (bottom part).
10# The corresponding archived utility sources can be unpacked by
11# running `sh MultiSound' (the utilities are only needed for the
12# Pinnacle and Fiji cards). **
13#
14#
15# -=-=- Getting Firmware -=-=-
16# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17#
18# See the section `Obtaining and Creating Firmware Files' in this
19# document for instructions on obtaining the necessary firmware
20# files.
21#
22#
23# Supported Features
24# ~~~~~~~~~~~~~~~~~~
25#
26# Currently, full-duplex digital audio (/dev/dsp only, /dev/audio is
27# not currently available) and mixer functionality (/dev/mixer) are
28# supported (memory mapped digital audio is not yet supported).
29# Digital transfers and monitoring can be done as well if you have
30# the digital daughterboard (see the section on using the S/PDIF port
31# for more information).
32#
33# Support for the Turtle Beach MultiSound Hurricane architecture is
34# composed of the following modules (these can also operate compiled
35# into the kernel):
36#
37# msnd - MultiSound base (requires soundcore)
38#
39# msnd_classic - Base audio/mixer support for Classic, Monetery and
40# Tahiti cards
41#
42# msnd_pinnacle - Base audio/mixer support for Pinnacle and Fiji cards
43#
44#
45# Important Notes - Read Before Using
46# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47#
48# The firmware files are not included (may change in future). You
49# must obtain these images from Turtle Beach (they are included in
50# the MultiSound Development Kits), and place them in /etc/sound for
51# example, and give the full paths in the Linux configuration. If
52# you are compiling in support for the MultiSound driver rather than
53# using it as a module, these firmware files must be accessible
54# during kernel compilation.
55#
56# Please note these files must be binary files, not assembler. See
57# the section later in this document for instructions to obtain these
58# files.
59#
60#
61# Configuring Card Resources
62# ~~~~~~~~~~~~~~~~~~~~~~~~~~
63#
64# ** This section is very important, as your card may not work at all
65# or your machine may crash if you do not do this correctly. **
66#
67# * Classic/Monterey/Tahiti
68#
69# These cards are configured through the driver msnd_classic. You must
70# know the io port, then the driver will select the irq and memory resources
71# on the card. It is up to you to know if these are free locations or now,
72# a conflict can lock the machine up.
73#
74# * Pinnacle/Fiji
75#
76# The Pinnacle and Fiji cards have an extra config port, either
77# 0x250, 0x260 or 0x270. This port can be disabled to have the card
78# configured strictly through PnP, however you lose the ability to
79# access the IDE controller and joystick devices on this card when
80# using PnP. The included pinnaclecfg program in this shell archive
81# can be used to configure the card in non-PnP mode, and in PnP mode
82# you can use isapnptools. These are described briefly here.
83#
84# pinnaclecfg is not required; you can use the msnd_pinnacle module
85# to fully configure the card as well. However, pinnaclecfg can be
86# used to change the resource values of a particular device after the
87# msnd_pinnacle module has been loaded. If you are compiling the
88# driver into the kernel, you must set these values during compile
89# time, however other peripheral resource values can be changed with
90# the pinnaclecfg program after the kernel is loaded.
91#
92#
93# *** PnP mode
94#
95# Use pnpdump to obtain a sample configuration if you can; I was able
96# to obtain one with the command `pnpdump 1 0x203' -- this may vary
97# for you (running pnpdump by itself did not work for me). Then,
98# edit this file and use isapnp to uncomment and set the card values.
99# Use these values when inserting the msnd_pinnacle module. Using
100# this method, you can set the resources for the DSP and the Kurzweil
101# synth (Pinnacle). Since Linux does not directly support PnP
102# devices, you may have difficulty when using the card in PnP mode
103# when it the driver is compiled into the kernel. Using non-PnP mode
104# is preferable in this case.
105#
106# Here is an example mypinnacle.conf for isapnp that sets the card to
107# io base 0x210, irq 5 and mem 0xd8000, and also sets the Kurzweil
108# synth to 0x330 and irq 9 (may need editing for your system):
109#
110# (READPORT 0x0203)
111# (CSN 2)
112# (IDENTIFY *)
113#
114# # DSP
115# (CONFIGURE BVJ0440/-1 (LD 0
116# (INT 0 (IRQ 5 (MODE +E))) (IO 0 (BASE 0x0210)) (MEM 0 (BASE 0x0d8000))
117# (ACT Y)))
118#
119# # Kurzweil Synth (Pinnacle Only)
120# (CONFIGURE BVJ0440/-1 (LD 1
121# (IO 0 (BASE 0x0330)) (INT 0 (IRQ 9 (MODE +E)))
122# (ACT Y)))
123#
124# (WAITFORKEY)
125#
126#
127# *** Non-PnP mode
128#
129# The second way is by running the card in non-PnP mode. This
130# actually has some advantages in that you can access some other
131# devices on the card, such as the joystick and IDE controller. To
132# configure the card, unpack this shell archive and build the
133# pinnaclecfg program. Using this program, you can assign the
134# resource values to the card's devices, or disable the devices. As
135# an alternative to using pinnaclecfg, you can specify many of the
136# configuration values when loading the msnd_pinnacle module (or
137# during kernel configuration when compiling the driver into the
138# kernel).
139#
140# If you specify cfg=0x250 for the msnd_pinnacle module, it
141# automatically configure the card to the given io, irq and memory
142# values using that config port (the config port is jumper selectable
143# on the card to 0x250, 0x260 or 0x270).
144#
145# See the `msnd_pinnacle Additional Options' section below for more
146# information on these parameters (also, if you compile the driver
147# directly into the kernel, these extra parameters can be useful
148# here).
149#
150#
151# ** It is very easy to cause problems in your machine if you choose a
152# resource value which is incorrect. **
153#
154#
155# Examples
156# ~~~~~~~~
157#
158# * MultiSound Classic/Monterey/Tahiti:
159#
160# modprobe soundcore
161# insmod msnd
162# insmod msnd_classic io=0x290 irq=7 mem=0xd0000
163#
164# * MultiSound Pinnacle in PnP mode:
165#
166# modprobe soundcore
167# insmod msnd
168# isapnp mypinnacle.conf
169# insmod msnd_pinnacle io=0x210 irq=5 mem=0xd8000 <-- match mypinnacle.conf values
170#
171# * MultiSound Pinnacle in non-PnP mode (replace 0x250 with your configuration port,
172# one of 0x250, 0x260 or 0x270):
173#
174# insmod soundcore
175# insmod msnd
176# insmod msnd_pinnacle cfg=0x250 io=0x290 irq=5 mem=0xd0000
177#
178# * To use the MPU-compatible Kurzweil synth on the Pinnacle in PnP
179# mode, add the following (assumes you did `isapnp mypinnacle.conf'):
180#
181# insmod sound
182# insmod mpu401 io=0x330 irq=9 <-- match mypinnacle.conf values
183#
184# * To use the MPU-compatible Kurzweil synth on the Pinnacle in non-PnP
185# mode, add the following. Note how we first configure the peripheral's
186# resources, _then_ install a Linux driver for it:
187#
188# insmod sound
189# pinnaclecfg 0x250 mpu 0x330 9
190# insmod mpu401 io=0x330 irq=9
191#
192# -- OR you can use the following sequence without pinnaclecfg in non-PnP mode:
193#
194# insmod soundcore
195# insmod msnd
196# insmod msnd_pinnacle cfg=0x250 io=0x290 irq=5 mem=0xd0000 mpu_io=0x330 mpu_irq=9
197# insmod sound
198# insmod mpu401 io=0x330 irq=9
199#
200# * To setup the joystick port on the Pinnacle in non-PnP mode (though
201# you have to find the actual Linux joystick driver elsewhere), you
202# can use pinnaclecfg:
203#
204# pinnaclecfg 0x250 joystick 0x200
205#
206# -- OR you can configure this using msnd_pinnacle with the following:
207#
208# insmod soundcore
209# insmod msnd
210# insmod msnd_pinnacle cfg=0x250 io=0x290 irq=5 mem=0xd0000 joystick_io=0x200
211#
212#
213# msnd_classic, msnd_pinnacle Required Options
214# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
215#
216# If the following options are not given, the module will not load.
217# Examine the kernel message log for informative error messages.
218# WARNING--probing isn't supported so try to make sure you have the
219# correct shared memory area, otherwise you may experience problems.
220#
221# io I/O base of DSP, e.g. io=0x210
222# irq IRQ number, e.g. irq=5
223# mem Shared memory area, e.g. mem=0xd8000
224#
225#
226# msnd_classic, msnd_pinnacle Additional Options
227# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228#
229# fifosize The digital audio FIFOs, in kilobytes. If not
230# specified, the default will be used. Increasing
231# this value will reduce the chance of a FIFO
232# underflow at the expense of increasing overall
233# latency. For example, fifosize=512 will
234# allocate 512kB read and write FIFOs (1MB total).
235# While this may reduce dropouts, a heavy machine
236# load will undoubtedly starve the FIFO of data
237# and you will eventually get dropouts. One
238# option is to alter the scheduling priority of
239# the playback process, using `nice' or some form
240# of POSIX soft real-time scheduling.
241#
242# calibrate_signal Setting this to one calibrates the ADCs to the
243# signal, zero calibrates to the card (defaults
244# to zero).
245#
246#
247# msnd_pinnacle Additional Options
248# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
249#
250# digital Specify digital=1 to enable the S/PDIF input
251# if you have the digital daughterboard
252# adapter. This will enable access to the
253# DIGITAL1 input for the soundcard in the mixer.
254# Some mixer programs might have trouble setting
255# the DIGITAL1 source as an input. If you have
256# trouble, you can try the setdigital.c program
257# at the bottom of this document.
258#
259# cfg Non-PnP configuration port for the Pinnacle
260# and Fiji (typically 0x250, 0x260 or 0x270,
261# depending on the jumper configuration). If
262# this option is omitted, then it is assumed
263# that the card is in PnP mode, and that the
264# specified DSP resource values are already
265# configured with PnP (i.e. it won't attempt to
266# do any sort of configuration).
267#
268# When the Pinnacle is in non-PnP mode, you can use the following
269# options to configure particular devices. If a full specification
270# for a device is not given, then the device is not configured. Note
271# that you still must use a Linux driver for any of these devices
272# once their resources are setup (such as the Linux joystick driver,
273# or the MPU401 driver from OSS for the Kurzweil synth).
274#
275# mpu_io I/O port of MPU (on-board Kurzweil synth)
276# mpu_irq IRQ of MPU (on-board Kurzweil synth)
277# ide_io0 First I/O port of IDE controller
278# ide_io1 Second I/O port of IDE controller
279# ide_irq IRQ IDE controller
280# joystick_io I/O port of joystick
281#
282#
283# Obtaining and Creating Firmware Files
284# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285#
286# For the Classic/Tahiti/Monterey
287# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
288#
289# Download to /tmp and unzip the following file from Turtle Beach:
290#
291# ftp://ftp.voyetra.com/pub/tbs/msndcl/msndvkit.zip
292#
293# When unzipped, unzip the file named MsndFiles.zip. Then copy the
294# following firmware files to /etc/sound (note the file renaming):
295#
296# cp DSPCODE/MSNDINIT.BIN /etc/sound/msndinit.bin
297# cp DSPCODE/MSNDPERM.REB /etc/sound/msndperm.bin
298#
299# When configuring the Linux kernel, specify /etc/sound/msndinit.bin and
300# /etc/sound/msndperm.bin for the two firmware files (Linux kernel
301# versions older than 2.2 do not ask for firmware paths, and are
302# hardcoded to /etc/sound).
303#
304# If you are compiling the driver into the kernel, these files must
305# be accessible during compilation, but will not be needed later.
306# The files must remain, however, if the driver is used as a module.
307#
308#
309# For the Pinnacle/Fiji
310# ~~~~~~~~~~~~~~~~~~~~~
311#
312# Download to /tmp and unzip the following file from Turtle Beach (be
313# sure to use the entire URL; some have had trouble navigating to the
314# URL):
315#
316# ftp://ftp.voyetra.com/pub/tbs/pinn/pnddk100.zip
317#
318# Unpack this shell archive, and run make in the created directory
319# (you need a C compiler and flex to build the utilities). This
320# should give you the executables conv, pinnaclecfg and setdigital.
321# conv is only used temporarily here to create the firmware files,
322# while pinnaclecfg is used to configure the Pinnacle or Fiji card in
323# non-PnP mode, and setdigital can be used to set the S/PDIF input on
324# the mixer (pinnaclecfg and setdigital should be copied to a
325# convenient place, possibly run during system initialization).
326#
327# To generating the firmware files with the `conv' program, we create
328# the binary firmware files by doing the following conversion
329# (assuming the archive unpacked into a directory named PINNDDK):
330#
331# ./conv < PINNDDK/dspcode/pndspini.asm > /etc/sound/pndspini.bin
332# ./conv < PINNDDK/dspcode/pndsperm.asm > /etc/sound/pndsperm.bin
333#
334# The conv (and conv.l) program is not needed after conversion and can
335# be safely deleted. Then, when configuring the Linux kernel, specify
336# /etc/sound/pndspini.bin and /etc/sound/pndsperm.bin for the two
337# firmware files (Linux kernel versions older than 2.2 do not ask for
338# firmware paths, and are hardcoded to /etc/sound).
339#
340# If you are compiling the driver into the kernel, these files must
341# be accessible during compilation, but will not be needed later.
342# The files must remain, however, if the driver is used as a module.
343#
344#
345# Using Digital I/O with the S/PDIF Port
346# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
347#
348# If you have a Pinnacle or Fiji with the digital daughterboard and
349# want to set it as the input source, you can use this program if you
350# have trouble trying to do it with a mixer program (be sure to
351# insert the module with the digital=1 option, or say Y to the option
352# during compiled-in kernel operation). Upon selection of the S/PDIF
353# port, you should be able monitor and record from it.
354#
355# There is something to note about using the S/PDIF port. Digital
356# timing is taken from the digital signal, so if a signal is not
357# connected to the port and it is selected as recording input, you
358# will find PCM playback to be distorted in playback rate. Also,
359# attempting to record at a sampling rate other than the DAT rate may
360# be problematic (i.e. trying to record at 8000Hz when the DAT signal
361# is 44100Hz). If you have a problem with this, set the recording
362# input to analog if you need to record at a rate other than that of
363# the DAT rate.
364#
365#
366# -- Shell archive attached below, just run `sh MultiSound' to extract.
367# Contains Pinnacle/Fiji utilities to convert firmware, configure
368# in non-PnP mode, and select the DIGITAL1 input for the mixer.
369#
370#
371#!/bin/sh
372# This is a shell archive (produced by GNU sharutils 4.2).
373# To extract the files from this archive, save it to some FILE, remove
374# everything before the `!/bin/sh' line above, then type `sh FILE'.
375#
376# Made on 1998-12-04 10:07 EST by <andrewtv@ztransform.velsoft.com>.
377# Source directory was `/home/andrewtv/programming/pinnacle/pinnacle'.
378#
379# Existing files will *not* be overwritten unless `-c' is specified.
380#
381# This shar contains:
382# length mode name
383# ------ ---------- ------------------------------------------
384# 2046 -rw-rw-r-- MultiSound.d/setdigital.c
385# 10235 -rw-rw-r-- MultiSound.d/pinnaclecfg.c
386# 106 -rw-rw-r-- MultiSound.d/Makefile
387# 141 -rw-rw-r-- MultiSound.d/conv.l
388# 1472 -rw-rw-r-- MultiSound.d/msndreset.c
389#
390save_IFS="${IFS}"
391IFS="${IFS}:"
392gettext_dir=FAILED
393locale_dir=FAILED
394first_param="$1"
395for dir in $PATH
396do
397 if test "$gettext_dir" = FAILED && test -f $dir/gettext \
398 && ($dir/gettext --version >/dev/null 2>&1)
399 then
400 set `$dir/gettext --version 2>&1`
401 if test "$3" = GNU
402 then
403 gettext_dir=$dir
404 fi
405 fi
406 if test "$locale_dir" = FAILED && test -f $dir/shar \
407 && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
408 then
409 locale_dir=`$dir/shar --print-text-domain-dir`
410 fi
411done
412IFS="$save_IFS"
413if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
414then
415 echo=echo
416else
417 TEXTDOMAINDIR=$locale_dir
418 export TEXTDOMAINDIR
419 TEXTDOMAIN=sharutils
420 export TEXTDOMAIN
421 echo="$gettext_dir/gettext -s"
422fi
423touch -am 1231235999 $$.touch >/dev/null 2>&1
424if test ! -f 1231235999 && test -f $$.touch; then
425 shar_touch=touch
426else
427 shar_touch=:
428 echo
429 $echo 'WARNING: not restoring timestamps. Consider getting and'
430 $echo "installing GNU \`touch', distributed in GNU File Utilities..."
431 echo
432fi
433rm -f 1231235999 $$.touch
434#
435if mkdir _sh01426; then
436 $echo 'x -' 'creating lock directory'
437else
438 $echo 'failed to create lock directory'
439 exit 1
440fi
441# ============= MultiSound.d/setdigital.c ==============
442if test ! -d 'MultiSound.d'; then
443 $echo 'x -' 'creating directory' 'MultiSound.d'
444 mkdir 'MultiSound.d'
445fi
446if test -f 'MultiSound.d/setdigital.c' && test "$first_param" != -c; then
447 $echo 'x -' SKIPPING 'MultiSound.d/setdigital.c' '(file already exists)'
448else
449 $echo 'x -' extracting 'MultiSound.d/setdigital.c' '(text)'
450 sed 's/^X//' << 'SHAR_EOF' > 'MultiSound.d/setdigital.c' &&
451/*********************************************************************
452X *
453X * setdigital.c - sets the DIGITAL1 input for a mixer
454X *
455X * Copyright (C) 1998 Andrew Veliath
456X *
457X * This program is free software; you can redistribute it and/or modify
458X * it under the terms of the GNU General Public License as published by
459X * the Free Software Foundation; either version 2 of the License, or
460X * (at your option) any later version.
461X *
462X * This program is distributed in the hope that it will be useful,
463X * but WITHOUT ANY WARRANTY; without even the implied warranty of
464X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
465X * GNU General Public License for more details.
466X *
467X * You should have received a copy of the GNU General Public License
468X * along with this program; if not, write to the Free Software
469X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
470X *
471X ********************************************************************/
472X
473#include <stdio.h>
474#include <unistd.h>
475#include <fcntl.h>
476#include <sys/types.h>
477#include <sys/stat.h>
478#include <sys/ioctl.h>
479#include <sys/soundcard.h>
480X
481int main(int argc, char *argv[])
482{
483X int fd;
484X unsigned long recmask, recsrc;
485X
486X if (argc != 2) {
487X fprintf(stderr, "usage: setdigital <mixer device>\n");
488X exit(1);
489X }
490X
491X if ((fd = open(argv[1], O_RDWR)) < 0) {
492X perror(argv[1]);
493X exit(1);
494X }
495X
496X if (ioctl(fd, SOUND_MIXER_READ_RECMASK, &recmask) < 0) {
497X fprintf(stderr, "error: ioctl read recording mask failed\n");
498X perror("ioctl");
499X close(fd);
500X exit(1);
501X }
502X
503X if (!(recmask & SOUND_MASK_DIGITAL1)) {
504X fprintf(stderr, "error: cannot find DIGITAL1 device in mixer\n");
505X close(fd);
506X exit(1);
507X }
508X
509X if (ioctl(fd, SOUND_MIXER_READ_RECSRC, &recsrc) < 0) {
510X fprintf(stderr, "error: ioctl read recording source failed\n");
511X perror("ioctl");
512X close(fd);
513X exit(1);
514X }
515X
516X recsrc |= SOUND_MASK_DIGITAL1;
517X
518X if (ioctl(fd, SOUND_MIXER_WRITE_RECSRC, &recsrc) < 0) {
519X fprintf(stderr, "error: ioctl write recording source failed\n");
520X perror("ioctl");
521X close(fd);
522X exit(1);
523X }
524X
525X close(fd);
526X
527X return 0;
528}
529SHAR_EOF
530 $shar_touch -am 1204092598 'MultiSound.d/setdigital.c' &&
531 chmod 0664 'MultiSound.d/setdigital.c' ||
532 $echo 'restore of' 'MultiSound.d/setdigital.c' 'failed'
533 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
534 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
535 md5sum -c << SHAR_EOF >/dev/null 2>&1 \
536 || $echo 'MultiSound.d/setdigital.c:' 'MD5 check failed'
537e87217fc3e71288102ba41fd81f71ec4 MultiSound.d/setdigital.c
538SHAR_EOF
539 else
540 shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'MultiSound.d/setdigital.c'`"
541 test 2046 -eq "$shar_count" ||
542 $echo 'MultiSound.d/setdigital.c:' 'original size' '2046,' 'current size' "$shar_count!"
543 fi
544fi
545# ============= MultiSound.d/pinnaclecfg.c ==============
546if test -f 'MultiSound.d/pinnaclecfg.c' && test "$first_param" != -c; then
547 $echo 'x -' SKIPPING 'MultiSound.d/pinnaclecfg.c' '(file already exists)'
548else
549 $echo 'x -' extracting 'MultiSound.d/pinnaclecfg.c' '(text)'
550 sed 's/^X//' << 'SHAR_EOF' > 'MultiSound.d/pinnaclecfg.c' &&
551/*********************************************************************
552X *
553X * pinnaclecfg.c - Pinnacle/Fiji Device Configuration Program
554X *
555X * This is for NON-PnP mode only. For PnP mode, use isapnptools.
556X *
557X * This is Linux-specific, and must be run with root permissions.
558X *
559X * Part of the Turtle Beach MultiSound Sound Card Driver for Linux
560X *
561X * Copyright (C) 1998 Andrew Veliath
562X *
563X * This program is free software; you can redistribute it and/or modify
564X * it under the terms of the GNU General Public License as published by
565X * the Free Software Foundation; either version 2 of the License, or
566X * (at your option) any later version.
567X *
568X * This program is distributed in the hope that it will be useful,
569X * but WITHOUT ANY WARRANTY; without even the implied warranty of
570X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
571X * GNU General Public License for more details.
572X *
573X * You should have received a copy of the GNU General Public License
574X * along with this program; if not, write to the Free Software
575X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
576X *
577X ********************************************************************/
578X
579#include <stdio.h>
580#include <stdlib.h>
581#include <string.h>
582#include <errno.h>
583#include <unistd.h>
584#include <asm/io.h>
585#include <asm/types.h>
586X
587#define IREG_LOGDEVICE 0x07
588#define IREG_ACTIVATE 0x30
589#define LD_ACTIVATE 0x01
590#define LD_DISACTIVATE 0x00
591#define IREG_EECONTROL 0x3F
592#define IREG_MEMBASEHI 0x40
593#define IREG_MEMBASELO 0x41
594#define IREG_MEMCONTROL 0x42
595#define IREG_MEMRANGEHI 0x43
596#define IREG_MEMRANGELO 0x44
597#define MEMTYPE_8BIT 0x00
598#define MEMTYPE_16BIT 0x02
599#define MEMTYPE_RANGE 0x00
600#define MEMTYPE_HIADDR 0x01
601#define IREG_IO0_BASEHI 0x60
602#define IREG_IO0_BASELO 0x61
603#define IREG_IO1_BASEHI 0x62
604#define IREG_IO1_BASELO 0x63
605#define IREG_IRQ_NUMBER 0x70
606#define IREG_IRQ_TYPE 0x71
607#define IRQTYPE_HIGH 0x02
608#define IRQTYPE_LOW 0x00
609#define IRQTYPE_LEVEL 0x01
610#define IRQTYPE_EDGE 0x00
611X
612#define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
613#define LOBYTE(w) ((BYTE)(w))
614#define MAKEWORD(low,hi) ((WORD)(((BYTE)(low))|(((WORD)((BYTE)(hi)))<<8)))
615X
616typedef __u8 BYTE;
617typedef __u16 USHORT;
618typedef __u16 WORD;
619X
620static int config_port = -1;
621X
622static int msnd_write_cfg(int cfg, int reg, int value)
623{
624X outb(reg, cfg);
625X outb(value, cfg + 1);
626X if (value != inb(cfg + 1)) {
627X fprintf(stderr, "error: msnd_write_cfg: I/O error\n");
628X return -EIO;
629X }
630X return 0;
631}
632X
633static int msnd_read_cfg(int cfg, int reg)
634{
635X outb(reg, cfg);
636X return inb(cfg + 1);
637}
638X
639static int msnd_write_cfg_io0(int cfg, int num, WORD io)
640{
641X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
642X return -EIO;
643X if (msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
644X return -EIO;
645X if (msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
646X return -EIO;
647X return 0;
648}
649X
650static int msnd_read_cfg_io0(int cfg, int num, WORD *io)
651{
652X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
653X return -EIO;
654X
655X *io = MAKEWORD(msnd_read_cfg(cfg, IREG_IO0_BASELO),
656X msnd_read_cfg(cfg, IREG_IO0_BASEHI));
657X
658X return 0;
659}
660X
661static int msnd_write_cfg_io1(int cfg, int num, WORD io)
662{
663X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
664X return -EIO;
665X if (msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
666X return -EIO;
667X if (msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
668X return -EIO;
669X return 0;
670}
671X
672static int msnd_read_cfg_io1(int cfg, int num, WORD *io)
673{
674X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
675X return -EIO;
676X
677X *io = MAKEWORD(msnd_read_cfg(cfg, IREG_IO1_BASELO),
678X msnd_read_cfg(cfg, IREG_IO1_BASEHI));
679X
680X return 0;
681}
682X
683static int msnd_write_cfg_irq(int cfg, int num, WORD irq)
684{
685X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
686X return -EIO;
687X if (msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
688X return -EIO;
689X if (msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
690X return -EIO;
691X return 0;
692}
693X
694static int msnd_read_cfg_irq(int cfg, int num, WORD *irq)
695{
696X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
697X return -EIO;
698X
699X *irq = msnd_read_cfg(cfg, IREG_IRQ_NUMBER);
700X
701X return 0;
702}
703X
704static int msnd_write_cfg_mem(int cfg, int num, int mem)
705{
706X WORD wmem;
707X
708X mem >>= 8;
709X mem &= 0xfff;
710X wmem = (WORD)mem;
711X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
712X return -EIO;
713X if (msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
714X return -EIO;
715X if (msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
716X return -EIO;
717X if (wmem && msnd_write_cfg(cfg, IREG_MEMCONTROL, (MEMTYPE_HIADDR | MEMTYPE_16BIT)))
718X return -EIO;
719X return 0;
720}
721X
722static int msnd_read_cfg_mem(int cfg, int num, int *mem)
723{
724X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
725X return -EIO;
726X
727X *mem = MAKEWORD(msnd_read_cfg(cfg, IREG_MEMBASELO),
728X msnd_read_cfg(cfg, IREG_MEMBASEHI));
729X *mem <<= 8;
730X
731X return 0;
732}
733X
734static int msnd_activate_logical(int cfg, int num)
735{
736X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
737X return -EIO;
738X if (msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
739X return -EIO;
740X return 0;
741}
742X
743static int msnd_write_cfg_logical(int cfg, int num, WORD io0, WORD io1, WORD irq, int mem)
744{
745X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
746X return -EIO;
747X if (msnd_write_cfg_io0(cfg, num, io0))
748X return -EIO;
749X if (msnd_write_cfg_io1(cfg, num, io1))
750X return -EIO;
751X if (msnd_write_cfg_irq(cfg, num, irq))
752X return -EIO;
753X if (msnd_write_cfg_mem(cfg, num, mem))
754X return -EIO;
755X if (msnd_activate_logical(cfg, num))
756X return -EIO;
757X return 0;
758}
759X
760static int msnd_read_cfg_logical(int cfg, int num, WORD *io0, WORD *io1, WORD *irq, int *mem)
761{
762X if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
763X return -EIO;
764X if (msnd_read_cfg_io0(cfg, num, io0))
765X return -EIO;
766X if (msnd_read_cfg_io1(cfg, num, io1))
767X return -EIO;
768X if (msnd_read_cfg_irq(cfg, num, irq))
769X return -EIO;
770X if (msnd_read_cfg_mem(cfg, num, mem))
771X return -EIO;
772X return 0;
773}
774X
775static void usage(void)
776{
777X fprintf(stderr,
778X "\n"
779X "pinnaclecfg 1.0\n"
780X "\n"
781X "usage: pinnaclecfg <config port> [device config]\n"
782X "\n"
783X "This is for use with the card in NON-PnP mode only.\n"
784X "\n"
785X "Available devices (not all available for Fiji):\n"
786X "\n"
787X " Device Description\n"
788X " -------------------------------------------------------------------\n"
789X " reset Reset all devices (i.e. disable)\n"
790X " show Display current device configurations\n"
791X "\n"
792X " dsp <io> <irq> <mem> Audio device\n"
793X " mpu <io> <irq> Internal Kurzweil synth\n"
794X " ide <io0> <io1> <irq> On-board IDE controller\n"
795X " joystick <io> Joystick port\n"
796X "\n");
797X exit(1);
798}
799X
800static int cfg_reset(void)
801{
802X int i;
803X
804X for (i = 0; i < 4; ++i)
805X msnd_write_cfg_logical(config_port, i, 0, 0, 0, 0);
806X
807X return 0;
808}
809X
810static int cfg_show(void)
811{
812X int i;
813X int count = 0;
814X
815X for (i = 0; i < 4; ++i) {
816X WORD io0, io1, irq;
817X int mem;
818X msnd_read_cfg_logical(config_port, i, &io0, &io1, &irq, &mem);
819X switch (i) {
820X case 0:
821X if (io0 || irq || mem) {
822X printf("dsp 0x%x %d 0x%x\n", io0, irq, mem);
823X ++count;
824X }
825X break;
826X case 1:
827X if (io0 || irq) {
828X printf("mpu 0x%x %d\n", io0, irq);
829X ++count;
830X }
831X break;
832X case 2:
833X if (io0 || io1 || irq) {
834X printf("ide 0x%x 0x%x %d\n", io0, io1, irq);
835X ++count;
836X }
837X break;
838X case 3:
839X if (io0) {
840X printf("joystick 0x%x\n", io0);
841X ++count;
842X }
843X break;
844X }
845X }
846X
847X if (count == 0)
848X fprintf(stderr, "no devices configured\n");
849X
850X return 0;
851}
852X
853static int cfg_dsp(int argc, char *argv[])
854{
855X int io, irq, mem;
856X
857X if (argc < 3 ||
858X sscanf(argv[0], "0x%x", &io) != 1 ||
859X sscanf(argv[1], "%d", &irq) != 1 ||
860X sscanf(argv[2], "0x%x", &mem) != 1)
861X usage();
862X
863X if (!(io == 0x290 ||
864X io == 0x260 ||
865X io == 0x250 ||
866X io == 0x240 ||
867X io == 0x230 ||
868X io == 0x220 ||
869X io == 0x210 ||
870X io == 0x3e0)) {
871X fprintf(stderr, "error: io must be one of "
872X "210, 220, 230, 240, 250, 260, 290, or 3E0\n");
873X usage();
874X }
875X
876X if (!(irq == 5 ||
877X irq == 7 ||
878X irq == 9 ||
879X irq == 10 ||
880X irq == 11 ||
881X irq == 12)) {
882X fprintf(stderr, "error: irq must be one of "
883X "5, 7, 9, 10, 11 or 12\n");
884X usage();
885X }
886X
887X if (!(mem == 0xb0000 ||
888X mem == 0xc8000 ||
889X mem == 0xd0000 ||
890X mem == 0xd8000 ||
891X mem == 0xe0000 ||
892X mem == 0xe8000)) {
893X fprintf(stderr, "error: mem must be one of "
894X "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or 0xe8000\n");
895X usage();
896X }
897X
898X return msnd_write_cfg_logical(config_port, 0, io, 0, irq, mem);
899}
900X
901static int cfg_mpu(int argc, char *argv[])
902{
903X int io, irq;
904X
905X if (argc < 2 ||
906X sscanf(argv[0], "0x%x", &io) != 1 ||
907X sscanf(argv[1], "%d", &irq) != 1)
908X usage();
909X
910X return msnd_write_cfg_logical(config_port, 1, io, 0, irq, 0);
911}
912X
913static int cfg_ide(int argc, char *argv[])
914{
915X int io0, io1, irq;
916X
917X if (argc < 3 ||
918X sscanf(argv[0], "0x%x", &io0) != 1 ||
919X sscanf(argv[0], "0x%x", &io1) != 1 ||
920X sscanf(argv[1], "%d", &irq) != 1)
921X usage();
922X
923X return msnd_write_cfg_logical(config_port, 2, io0, io1, irq, 0);
924}
925X
926static int cfg_joystick(int argc, char *argv[])
927{
928X int io;
929X
930X if (argc < 1 ||
931X sscanf(argv[0], "0x%x", &io) != 1)
932X usage();
933X
934X return msnd_write_cfg_logical(config_port, 3, io, 0, 0, 0);
935}
936X
937int main(int argc, char *argv[])
938{
939X char *device;
940X int rv = 0;
941X
942X --argc; ++argv;
943X
944X if (argc < 2)
945X usage();
946X
947X sscanf(argv[0], "0x%x", &config_port);
948X if (config_port != 0x250 && config_port != 0x260 && config_port != 0x270) {
949X fprintf(stderr, "error: <config port> must be 0x250, 0x260 or 0x270\n");
950X exit(1);
951X }
952X if (ioperm(config_port, 2, 1)) {
953X perror("ioperm");
954X fprintf(stderr, "note: pinnaclecfg must be run as root\n");
955X exit(1);
956X }
957X device = argv[1];
958X
959X argc -= 2; argv += 2;
960X
961X if (strcmp(device, "reset") == 0)
962X rv = cfg_reset();
963X else if (strcmp(device, "show") == 0)
964X rv = cfg_show();
965X else if (strcmp(device, "dsp") == 0)
966X rv = cfg_dsp(argc, argv);
967X else if (strcmp(device, "mpu") == 0)
968X rv = cfg_mpu(argc, argv);
969X else if (strcmp(device, "ide") == 0)
970X rv = cfg_ide(argc, argv);
971X else if (strcmp(device, "joystick") == 0)
972X rv = cfg_joystick(argc, argv);
973X else {
974X fprintf(stderr, "error: unknown device %s\n", device);
975X usage();
976X }
977X
978X if (rv)
979X fprintf(stderr, "error: device configuration failed\n");
980X
981X return 0;
982}
983SHAR_EOF
984 $shar_touch -am 1204092598 'MultiSound.d/pinnaclecfg.c' &&
985 chmod 0664 'MultiSound.d/pinnaclecfg.c' ||
986 $echo 'restore of' 'MultiSound.d/pinnaclecfg.c' 'failed'
987 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
988 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
989 md5sum -c << SHAR_EOF >/dev/null 2>&1 \
990 || $echo 'MultiSound.d/pinnaclecfg.c:' 'MD5 check failed'
991366bdf27f0db767a3c7921d0a6db20fe MultiSound.d/pinnaclecfg.c
992SHAR_EOF
993 else
994 shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'MultiSound.d/pinnaclecfg.c'`"
995 test 10235 -eq "$shar_count" ||
996 $echo 'MultiSound.d/pinnaclecfg.c:' 'original size' '10235,' 'current size' "$shar_count!"
997 fi
998fi
999# ============= MultiSound.d/Makefile ==============
1000if test -f 'MultiSound.d/Makefile' && test "$first_param" != -c; then
1001 $echo 'x -' SKIPPING 'MultiSound.d/Makefile' '(file already exists)'
1002else
1003 $echo 'x -' extracting 'MultiSound.d/Makefile' '(text)'
1004 sed 's/^X//' << 'SHAR_EOF' > 'MultiSound.d/Makefile' &&
1005CC = gcc
1006CFLAGS = -O
1007PROGS = setdigital msndreset pinnaclecfg conv
1008X
1009all: $(PROGS)
1010X
1011clean:
1012X rm -f $(PROGS)
1013SHAR_EOF
1014 $shar_touch -am 1204092398 'MultiSound.d/Makefile' &&
1015 chmod 0664 'MultiSound.d/Makefile' ||
1016 $echo 'restore of' 'MultiSound.d/Makefile' 'failed'
1017 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
1018 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
1019 md5sum -c << SHAR_EOF >/dev/null 2>&1 \
1020 || $echo 'MultiSound.d/Makefile:' 'MD5 check failed'
102176ca8bb44e3882edcf79c97df6c81845 MultiSound.d/Makefile
1022SHAR_EOF
1023 else
1024 shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'MultiSound.d/Makefile'`"
1025 test 106 -eq "$shar_count" ||
1026 $echo 'MultiSound.d/Makefile:' 'original size' '106,' 'current size' "$shar_count!"
1027 fi
1028fi
1029# ============= MultiSound.d/conv.l ==============
1030if test -f 'MultiSound.d/conv.l' && test "$first_param" != -c; then
1031 $echo 'x -' SKIPPING 'MultiSound.d/conv.l' '(file already exists)'
1032else
1033 $echo 'x -' extracting 'MultiSound.d/conv.l' '(text)'
1034 sed 's/^X//' << 'SHAR_EOF' > 'MultiSound.d/conv.l' &&
1035%%
1036[ \n\t,\r]
1037\;.*
1038DB
1039[0-9A-Fa-f]+H { int n; sscanf(yytext, "%xH", &n); printf("%c", n); }
1040%%
1041int yywrap() { return 1; }
1042main() { yylex(); }
1043SHAR_EOF
1044 $shar_touch -am 0828231798 'MultiSound.d/conv.l' &&
1045 chmod 0664 'MultiSound.d/conv.l' ||
1046 $echo 'restore of' 'MultiSound.d/conv.l' 'failed'
1047 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
1048 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
1049 md5sum -c << SHAR_EOF >/dev/null 2>&1 \
1050 || $echo 'MultiSound.d/conv.l:' 'MD5 check failed'
1051d2411fc32cd71a00dcdc1f009e858dd2 MultiSound.d/conv.l
1052SHAR_EOF
1053 else
1054 shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'MultiSound.d/conv.l'`"
1055 test 141 -eq "$shar_count" ||
1056 $echo 'MultiSound.d/conv.l:' 'original size' '141,' 'current size' "$shar_count!"
1057 fi
1058fi
1059# ============= MultiSound.d/msndreset.c ==============
1060if test -f 'MultiSound.d/msndreset.c' && test "$first_param" != -c; then
1061 $echo 'x -' SKIPPING 'MultiSound.d/msndreset.c' '(file already exists)'
1062else
1063 $echo 'x -' extracting 'MultiSound.d/msndreset.c' '(text)'
1064 sed 's/^X//' << 'SHAR_EOF' > 'MultiSound.d/msndreset.c' &&
1065/*********************************************************************
1066X *
1067X * msndreset.c - resets the MultiSound card
1068X *
1069X * Copyright (C) 1998 Andrew Veliath
1070X *
1071X * This program is free software; you can redistribute it and/or modify
1072X * it under the terms of the GNU General Public License as published by
1073X * the Free Software Foundation; either version 2 of the License, or
1074X * (at your option) any later version.
1075X *
1076X * This program is distributed in the hope that it will be useful,
1077X * but WITHOUT ANY WARRANTY; without even the implied warranty of
1078X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1079X * GNU General Public License for more details.
1080X *
1081X * You should have received a copy of the GNU General Public License
1082X * along with this program; if not, write to the Free Software
1083X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1084X *
1085X ********************************************************************/
1086X
1087#include <stdio.h>
1088#include <unistd.h>
1089#include <fcntl.h>
1090#include <sys/types.h>
1091#include <sys/stat.h>
1092#include <sys/ioctl.h>
1093#include <sys/soundcard.h>
1094X
1095int main(int argc, char *argv[])
1096{
1097X int fd;
1098X
1099X if (argc != 2) {
1100X fprintf(stderr, "usage: msndreset <mixer device>\n");
1101X exit(1);
1102X }
1103X
1104X if ((fd = open(argv[1], O_RDWR)) < 0) {
1105X perror(argv[1]);
1106X exit(1);
1107X }
1108X
1109X if (ioctl(fd, SOUND_MIXER_PRIVATE1, 0) < 0) {
1110X fprintf(stderr, "error: msnd ioctl reset failed\n");
1111X perror("ioctl");
1112X close(fd);
1113X exit(1);
1114X }
1115X
1116X close(fd);
1117X
1118X return 0;
1119}
1120SHAR_EOF
1121 $shar_touch -am 1204100698 'MultiSound.d/msndreset.c' &&
1122 chmod 0664 'MultiSound.d/msndreset.c' ||
1123 $echo 'restore of' 'MultiSound.d/msndreset.c' 'failed'
1124 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
1125 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
1126 md5sum -c << SHAR_EOF >/dev/null 2>&1 \
1127 || $echo 'MultiSound.d/msndreset.c:' 'MD5 check failed'
1128c52f876521084e8eb25e12e01dcccb8a MultiSound.d/msndreset.c
1129SHAR_EOF
1130 else
1131 shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'MultiSound.d/msndreset.c'`"
1132 test 1472 -eq "$shar_count" ||
1133 $echo 'MultiSound.d/msndreset.c:' 'original size' '1472,' 'current size' "$shar_count!"
1134 fi
1135fi
1136rm -fr _sh01426
1137exit 0
diff --git a/Documentation/sound/oss/OPL3 b/Documentation/sound/oss/OPL3
deleted file mode 100644
index 2468ff827688..000000000000
--- a/Documentation/sound/oss/OPL3
+++ /dev/null
@@ -1,6 +0,0 @@
1A pure OPL3 card is nice and easy to configure. Simply do
2
3insmod opl3 io=0x388
4
5Change the I/O address in the very unlikely case this card is differently
6configured
diff --git a/Documentation/sound/oss/Opti b/Documentation/sound/oss/Opti
deleted file mode 100644
index 4cd5d9ab3580..000000000000
--- a/Documentation/sound/oss/Opti
+++ /dev/null
@@ -1,218 +0,0 @@
1Support for the OPTi 82C931 chip
2--------------------------------
3Note: parts of this README file apply also to other
4cards that use the mad16 driver.
5
6Some items in this README file are based on features
7added to the sound driver after Linux-2.1.91 was out.
8By the time of writing this I do not know which official
9kernel release will include these features.
10Please do not report inconsistencies on older Linux
11kernels.
12
13The OPTi 82C931 is supported in its non-PnP mode.
14Usually you do not need to set jumpers, etc. The sound driver
15will check the card status and if it is required it will
16force the card into a mode in which it can be programmed.
17
18If you have another OS installed on your computer it is recommended
19that Linux and the other OS use the same resources.
20
21Also, it is recommended that resources specified in /etc/modprobe.d/*.conf
22and resources specified in /etc/isapnp.conf agree.
23
24Compiling the sound driver
25--------------------------
26I highly recommend that you build a modularized sound driver.
27This document does not cover a sound-driver which is built in
28the kernel.
29
30Sound card support should be enabled as a module (chose m).
31Answer 'm' for these items:
32 Generic OPL2/OPL3 FM synthesizer support (CONFIG_SOUND_ADLIB)
33 Microsoft Sound System support (CONFIG_SOUND_MSS)
34 Support for OPTi MAD16 and/or Mozart based cards (CONFIG_SOUND_MAD16)
35 FM synthesizer (YM3812/OPL-3) support (CONFIG_SOUND_YM3812)
36
37The configuration menu may ask for addresses, IRQ lines or DMA
38channels. If the card is used as a module the module loading
39options will override these values.
40
41For the OPTi 931 you can answer 'n' to:
42 Support MIDI in older MAD16 based cards (requires SB) (CONFIG_SOUND_MAD16_OLDCARD)
43If you do need MIDI support in a Mozart or C928 based card you
44need to answer 'm' to the above question. In that case you will
45also need to answer 'm' to:
46 '100% Sound Blaster compatibles (SB16/32/64, ESS, Jazz16) support' (CONFIG_SOUND_SB)
47
48Go on and compile your kernel and modules. Install the modules. Run depmod -a.
49
50Using isapnptools
51-----------------
52In most systems with a PnP BIOS you do not need to use isapnp. The
53initialization provided by the BIOS is sufficient for the driver
54to pick up the card and continue initialization.
55
56If that fails, or if you have other PnP cards, you need to use isapnp
57to initialize the card.
58This was tested with isapnptools-1.11 but I recommend that you use
59isapnptools-1.13 (or newer). Run pnpdump to dump the information
60about your PnP cards. Then edit the resulting file and select
61the options of your choice. This file is normally installed as
62/etc/isapnp.conf.
63
64The driver has one limitation with respect to I/O port resources:
65IO3 base must be 0x0E0C. Although isapnp allows other ports, this
66address is hard-coded into the driver.
67
68Using kmod and autoloading the sound driver
69-------------------------------------------
70Config files in '/etc/modprobe.d/' are used as below:
71
72alias mixer0 mad16
73alias audio0 mad16
74alias midi0 mad16
75alias synth0 opl3
76options sb mad16=1
77options mad16 irq=10 dma=0 dma16=1 io=0x530 joystick=1 cdtype=0
78options opl3 io=0x388
79install mad16 /sbin/modprobe -i mad16 && /sbin/ad1848_mixer_reroute 14 8 15 3 16 6
80
81If you have an MPU daughtercard or onboard MPU you will want to add to the
82"options mad16" line - eg
83
84options mad16 irq=5 dma=0 dma16=3 io=0x530 mpu_io=0x330 mpu_irq=9
85
86To set the I/O and IRQ of the MPU.
87
88
89Explain:
90
91alias mixer0 mad16
92alias audio0 mad16
93alias midi0 mad16
94alias synth0 opl3
95
96When any sound device is opened the kernel requests auto-loading
97of char-major-14. There is a built-in alias that translates this
98request to loading the main sound module.
99
100The sound module in its turn will request loading of a sub-driver
101for mixer, audio, midi or synthesizer device. The first 3 are
102supported by the mad16 driver. The synth device is supported
103by the opl3 driver.
104
105There is currently no way to autoload the sound device driver
106if more than one card is installed.
107
108options sb mad16=1
109
110This is left for historical reasons. If you enable the
111config option 'Support MIDI in older MAD16 based cards (requires SB)'
112or if you use an older mad16 driver it will force loading of the
113SoundBlaster driver. This option tells the SB driver not to look
114for a SB card but to wait for the mad16 driver.
115
116options mad16 irq=10 dma=0 dma16=1 io=0x530 joystick=1 cdtype=0
117options opl3 io=0x388
118
119post-install mad16 /sbin/ad1848_mixer_reroute 14 8 15 3 16 6
120
121This sets resources and options for the mad16 and opl3 drivers.
122I use two DMA channels (only one is required) to enable full duplex.
123joystick=1 enables the joystick port. cdtype=0 disables the cd port.
124You can also set mpu_io and mpu_irq in the mad16 options for the
125uart401 driver.
126
127This tells modprobe to run /sbin/ad1848_mixer_reroute after
128mad16 is successfully loaded and initialized. The source
129for ad1848_mixer_reroute is appended to the end of this readme
130file. It is impossible for the sound driver to know the actual
131connections to the mixer. The 3 inputs intended for cd, synth
132and line-in are mapped to the generic inputs line1, line2 and
133line3. This program reroutes these mixer channels to their
134right names (note the right mapping depends on the actual sound
135card that you use).
136The numeric parameters mean:
137 14=line1 8=cd - reroute line1 to the CD input.
138 15=line2 3=synth - reroute line2 to the synthesizer input.
139 16=line3 6=line - reroute line3 to the line input.
140For reference on other input names look at the file
141/usr/include/linux/soundcard.h.
142
143Using a joystick
144-----------------
145You must enable a joystick in the mad16 options. (also
146in /etc/isapnp.conf if you use it).
147Tested with regular analog joysticks.
148
149A CDROM drive connected to the sound card
150-----------------------------------------
151The 82C931 chip has support only for secondary ATAPI cdrom.
152(cdtype=8). Loading the mad16 driver resets the C931 chip
153and if a cdrom was already mounted it may cause a complete
154system hang. Do not use the sound card if you have an alternative.
155If you do use the sound card it is important that you load
156the mad16 driver (use "modprobe mad16" to prevent auto-unloading)
157before the cdrom is accessed the first time.
158
159Using the sound driver built-in to the kernel may help here, but...
160Most new systems have a PnP BIOS and also two IDE controllers.
161The IDE controller on the sound card may be needed only on older
162systems (which have only one IDE controller) but these systems
163also do not have a PnP BIOS - requiring isapnptools and a modularized
164driver.
165
166Known problems
167--------------
1681. See the section on "A CDROM drive connected to the sound card".
169
1702. On my system the codec cannot capture companded sound samples.
171 (eg., recording from /dev/audio). When any companded capture is
172 requested I get stereo-16 bit samples instead. Playback of
173 companded samples works well. Apparently this problem is not common
174 to all C931 based cards. I do not know how to identify cards that
175 have this problem.
176
177Source for ad1848_mixer_reroute.c
178---------------------------------
179#include <stdio.h>
180#include <fcntl.h>
181#include <linux/soundcard.h>
182
183static char *mixer_names[SOUND_MIXER_NRDEVICES] =
184 SOUND_DEVICE_LABELS;
185
186int
187main(int argc, char **argv) {
188 int val, from, to;
189 int i, fd;
190
191 fd = open("/dev/mixer", O_RDWR);
192 if(fd < 0) {
193 perror("/dev/mixer");
194 return 1;
195 }
196
197 for(i = 2; i < argc; i += 2) {
198 from = atoi(argv[i-1]);
199 to = atoi(argv[i]);
200
201 if(to == SOUND_MIXER_NONE)
202 fprintf(stderr, "%s: turning off mixer %s\n",
203 argv[0], mixer_names[to]);
204 else
205 fprintf(stderr, "%s: rerouting mixer %s to %s\n",
206 argv[0], mixer_names[from], mixer_names[to]);
207
208 val = from << 8 | to;
209
210 if(ioctl(fd, SOUND_MIXER_PRIVATE2, &val)) {
211 perror("AD1848 mixer reroute");
212 return 1;
213 }
214 }
215
216 return 0;
217}
218
diff --git a/Documentation/sound/oss/PAS16 b/Documentation/sound/oss/PAS16
deleted file mode 100644
index 5c27229eec8c..000000000000
--- a/Documentation/sound/oss/PAS16
+++ /dev/null
@@ -1,162 +0,0 @@
1Pro Audio Spectrum 16 for 2.3.99 and later
2=========================================
3by Thomas Molina (tmolina@home.com)
4last modified 3 Mar 2001
5Acknowledgement to Axel Boldt (boldt@math.ucsb.edu) for stuff taken
6from Configure.help, Riccardo Facchetti for stuff from README.OSS,
7and others whose names I could not find.
8
9This documentation is relevant for the PAS16 driver (pas2_card.c and
10friends) under kernel version 2.3.99 and later. If you are
11unfamiliar with configuring sound under Linux, please read the
12Sound-HOWTO, Documentation/sound/oss/Introduction and other
13relevant docs first.
14
15The following information is relevant information from README.OSS
16and legacy docs for the Pro Audio Spectrum 16 (PAS16):
17==================================================================
18
19The pas2_card.c driver supports the following cards --
20Pro Audio Spectrum 16 (PAS16) and compatibles:
21 Pro Audio Spectrum 16
22 Pro Audio Studio 16
23 Logitech Sound Man 16
24 NOTE! The original Pro Audio Spectrum as well as the PAS+ are not
25 and will not be supported by the driver.
26
27The sound driver configuration dialog
28-------------------------------------
29
30Sound configuration starts by making some yes/no questions. Be careful
31when answering to these questions since answering y to a question may
32prevent some later ones from being asked. For example don't answer y to
33the question about (PAS16) if you don't really have a PAS16. Sound
34configuration may also be made modular by answering m to configuration
35options presented.
36
37Note also that all questions may not be asked. The configuration program
38may disable some questions depending on the earlier choices. It may also
39select some options automatically as well.
40
41 "ProAudioSpectrum 16 support",
42 - Answer 'y'_ONLY_ if you have a Pro Audio Spectrum _16_,
43 Pro Audio Studio 16 or Logitech SoundMan 16 (be sure that
44 you read the above list correctly). Don't answer 'y' if you
45 have some other card made by Media Vision or Logitech since they
46 are not PAS16 compatible.
47 NOTE! Since 3.5-beta10 you need to enable SB support (next question)
48 if you want to use the SB emulation of PAS16. It's also possible to
49 the emulation if you want to use a true SB card together with PAS16
50 (there is another question about this that is asked later).
51
52 "Generic OPL2/OPL3 FM synthesizer support",
53 - Answer 'y' if your card has a FM chip made by Yamaha (OPL2/OPL3/OPL4).
54 The PAS16 has an OPL3-compatible FM chip.
55
56With PAS16 you can use two audio device files at the same time. /dev/dsp (and
57/dev/audio) is connected to the 8/16 bit native codec and the /dev/dsp1 (and
58/dev/audio1) is connected to the SB emulation (8 bit mono only).
59
60
61The new stuff for 2.3.99 and later
62============================================================================
63The following configuration options are relevant to configuring the PAS16:
64
65Sound card support
66CONFIG_SOUND
67 If you have a sound card in your computer, i.e. if it can say more
68 than an occasional beep, say Y. Be sure to have all the information
69 about your sound card and its configuration down (I/O port,
70 interrupt and DMA channel), because you will be asked for it.
71
72 You want to read the Sound-HOWTO, available from
73 http://www.tldp.org/docs.html#howto . General information
74 about the modular sound system is contained in the files
75 Documentation/sound/oss/Introduction. The file
76 Documentation/sound/oss/README.OSS contains some slightly outdated but
77 still useful information as well.
78
79OSS sound modules
80CONFIG_SOUND_OSS
81 OSS is the Open Sound System suite of sound card drivers. They make
82 sound programming easier since they provide a common API. Say Y or M
83 here (the module will be called sound.o) if you haven't found a
84 driver for your sound card above, then pick your driver from the
85 list below.
86
87Persistent DMA buffers
88CONFIG_SOUND_DMAP
89 Linux can often have problems allocating DMA buffers for ISA sound
90 cards on machines with more than 16MB of RAM. This is because ISA
91 DMA buffers must exist below the 16MB boundary and it is quite
92 possible that a large enough free block in this region cannot be
93 found after the machine has been running for a while. If you say Y
94 here the DMA buffers (64Kb) will be allocated at boot time and kept
95 until the shutdown. This option is only useful if you said Y to
96 "OSS sound modules", above. If you said M to "OSS sound modules"
97 then you can get the persistent DMA buffer functionality by passing
98 the command-line argument "dmabuf=1" to the sound.o module.
99
100 Say y here for PAS16.
101
102ProAudioSpectrum 16 support
103CONFIG_SOUND_PAS
104 Answer Y only if you have a Pro Audio Spectrum 16, ProAudio Studio
105 16 or Logitech SoundMan 16 sound card. Don't answer Y if you have
106 some other card made by Media Vision or Logitech since they are not
107 PAS16 compatible. It is not necessary to enable the separate
108 Sound Blaster support; it is included in the PAS driver.
109
110 If you compile the driver into the kernel, you have to add
111 "pas2=<io>,<irq>,<dma>,<dma2>,<sbio>,<sbirq>,<sbdma>,<sbdma2>
112 to the kernel command line.
113
114FM Synthesizer (YM3812/OPL-3) support
115CONFIG_SOUND_YM3812
116 Answer Y if your card has a FM chip made by Yamaha (OPL2/OPL3/OPL4).
117 Answering Y is usually a safe and recommended choice, however some
118 cards may have software (TSR) FM emulation. Enabling FM support with
119 these cards may cause trouble (I don't currently know of any such
120 cards, however).
121 Please read the file Documentation/sound/oss/OPL3 if your card has an
122 OPL3 chip.
123 If you compile the driver into the kernel, you have to add
124 "opl3=<io>" to the kernel command line.
125
126 If you compile your drivers into the kernel, you MUST configure
127 OPL3 support as a module for PAS16 support to work properly.
128 You can then get OPL3 functionality by issuing the command:
129 insmod opl3
130 In addition, you must either add the following line to
131 /etc/modprobe.d/*.conf:
132 options opl3 io=0x388
133 or else add the following line to /etc/lilo.conf:
134 opl3=0x388
135
136
137EXAMPLES
138===================================================================
139To use the PAS16 in my computer I have enabled the following sound
140configuration options:
141
142CONFIG_SOUND=y
143CONFIG_SOUND_OSS=y
144CONFIG_SOUND_TRACEINIT=y
145CONFIG_SOUND_DMAP=y
146CONFIG_SOUND_PAS=y
147CONFIG_SOUND_SB=n
148CONFIG_SOUND_YM3812=m
149
150I have also included the following append line in /etc/lilo.conf:
151append="pas2=0x388,10,3,-1,0x220,5,1,-1 sb=0x220,5,1,-1 opl3=0x388"
152
153The io address of 0x388 is default configuration on the PAS16. The
154irq of 10 and dma of 3 may not match your installation. The above
155configuration enables PAS16, 8-bit Soundblaster and OPL3
156functionality. If Soundblaster functionality is not desired, the
157following line would be appropriate:
158append="pas2=0x388,10,3,-1,0,-1,-1,-1 opl3=0x388"
159
160If sound is built totally modular, the above options may be
161specified in /etc/modprobe.d/*.conf for pas2, sb and opl3
162respectively.
diff --git a/Documentation/sound/oss/PSS b/Documentation/sound/oss/PSS
deleted file mode 100644
index 187b9525e1f6..000000000000
--- a/Documentation/sound/oss/PSS
+++ /dev/null
@@ -1,41 +0,0 @@
1The PSS cards and other ECHO based cards provide an onboard DSP with
2downloadable programs and also has an AD1848 "Microsoft Sound System"
3device. The PSS driver enables MSS and MPU401 modes of the card. SB
4is not enabled since it doesn't work concurrently with MSS.
5
6If you build this driver as a module then the driver takes the following
7parameters
8
9pss_io. The I/O base the PSS card is configured at (normally 0x220
10 or 0x240)
11
12mss_io The base address of the Microsoft Sound System interface.
13 This is normally 0x530, but may be 0x604 or other addresses.
14
15mss_irq The interrupt assigned to the Microsoft Sound System
16 emulation. IRQ's 3,5,7,9,10,11 and 12 are available. If you
17 get IRQ errors be sure to check the interrupt is set to
18 "ISA/Legacy" in the BIOS on modern machines.
19
20mss_dma The DMA channel used by the Microsoft Sound System.
21 This can be 0, 1, or 3. DMA 0 is not available on older
22 machines and will cause a crash on them.
23
24mpu_io The MPU emulation base address. This sets the base of the
25 synthesizer. It is typically 0x330 but can be altered.
26
27mpu_irq The interrupt to use for the synthesizer. It must differ
28 from the IRQ used by the Microsoft Sound System port.
29
30
31The mpu_io/mpu_irq fields are optional. If they are not specified the
32synthesizer parts are not configured.
33
34When the module is loaded it looks for a file called
35/etc/sound/pss_synth. This is the firmware file from the DOS install disks.
36This fil holds a general MIDI emulation. The file expected is called
37genmidi.ld on newer DOS driver install disks and synth.ld on older ones.
38
39You can also load alternative DSP algorithms into the card if you wish. One
40alternative driver can be found at http://www.mpg123.de/
41
diff --git a/Documentation/sound/oss/PSS-updates b/Documentation/sound/oss/PSS-updates
deleted file mode 100644
index 11914a1dc7e7..000000000000
--- a/Documentation/sound/oss/PSS-updates
+++ /dev/null
@@ -1,88 +0,0 @@
1 This file contains notes for users of PSS sound cards who wish to use the
2newly added features of the newest version of this driver.
3
4 The major enhancements present in this new revision of this driver is the
5addition of two new module parameters that allow you to take full advantage of
6all the features present on your PSS sound card. These features include the
7ability to enable both the builtin CDROM and joystick ports.
8
9pss_enable_joystick
10
11 This parameter is basically a flag. A 0 will leave the joystick port
12disabled, while a non-zero value would enable the joystick port. The default
13setting is pss_enable_joystick=0 as this keeps this driver fully compatible
14with systems that were using previous versions of this driver. If you wish to
15enable the joystick port you will have to add pss_enable_joystick=1 as an
16argument to the driver. To actually use the joystick port you will then have
17to load the joystick driver itself. Just remember to load the joystick driver
18AFTER the pss sound driver.
19
20pss_cdrom_port
21
22 This parameter takes a port address as its parameter. Any available port
23address can be specified to enable the CDROM port, except for 0x0 and -1 as
24these values would leave the port disabled. Like the joystick port, the cdrom
25port will require that an appropriate CDROM driver be loaded before you can make
26use of the newly enabled CDROM port. Like the joystick port option above,
27remember to load the CDROM driver AFTER the pss sound driver. While it may
28differ on some PSS sound cards, all the PSS sound cards that I have seen have a
29builtin Wearnes CDROM port. If this is the case with your PSS sound card you
30should load aztcd with the appropriate port option that matches the port you
31assigned to the CDROM port when you loaded your pss sound driver. (ex.
32modprobe pss pss_cdrom_port=0x340 && modprobe aztcd aztcd=0x340) The default
33setting of this parameter leaves the CDROM port disabled to maintain full
34compatibility with systems using previous versions of this driver.
35
36 Other options have also been added for the added convenience and utility
37of the user. These options are only available if this driver is loaded as a
38module.
39
40pss_no_sound
41
42 This module parameter is a flag that can be used to tell the driver to
43just configure non-sound components. 0 configures all components, a non-0
44value will only attempt to configure the CDROM and joystick ports. This
45parameter can be used by a user who only wished to use the builtin joystick
46and/or CDROM port(s) of his PSS sound card. If this driver is loaded with this
47parameter and with the parameter below set to true then a user can safely unload
48this driver with the following command "rmmod pss && rmmod ad1848 && rmmod
49mpu401 && rmmod sound && rmmod soundcore" and retain the full functionality of
50his CDROM and/or joystick port(s) while gaining back the memory previously used
51by the sound drivers. This default setting of this parameter is 0 to retain
52full behavioral compatibility with previous versions of this driver.
53
54pss_keep_settings
55
56 This parameter can be used to specify whether you want the driver to reset
57all emulations whenever its unloaded. This can be useful for those who are
58sharing resources (io ports, IRQ's, DMA's) between different ISA cards. This
59flag can also be useful in that future versions of this driver may reset all
60emulations by default on the driver's unloading (as it probably should), so
61specifying it now will ensure that all future versions of this driver will
62continue to work as expected. The default value of this parameter is 1 to
63retain full behavioral compatibility with previous versions of this driver.
64
65pss_firmware
66
67 This parameter can be used to specify the file containing the firmware
68code so that a user could tell the driver where that file is located instead
69of having to put it in a predefined location with a predefined name. The
70default setting of this parameter is "/etc/sound/pss_synth" as this was the
71path and filename the hardcoded value in the previous versions of this driver.
72
73Examples:
74
75# Normal PSS sound card system, loading of drivers.
76# Should be specified in an rc file (ex. Slackware uses /etc/rc.d/rc.modules).
77
78/sbin/modprobe pss pss_io=0x220 mpu_io=0x338 mpu_irq=9 mss_io=0x530 mss_irq=10 mss_dma=1 pss_cdrom_port=0x340 pss_enable_joystick=1
79/sbin/modprobe aztcd aztcd=0x340
80/sbin/modprobe joystick
81
82# System using the PSS sound card just for its CDROM and joystick ports.
83# Should be specified in an rc file (ex. Slackware uses /etc/rc.d/rc.modules).
84
85/sbin/modprobe pss pss_io=0x220 pss_cdrom_port=0x340 pss_enable_joystick=1 pss_no_sound=1
86/sbin/rmmod pss && /sbin/rmmod ad1848 && /sbin/rmmod mpu401 && /sbin/rmmod sound && /sbin/rmmod soundcore # This line not needed, but saves memory.
87/sbin/modprobe aztcd aztcd=0x340
88/sbin/modprobe joystick
diff --git a/Documentation/sound/oss/README.OSS b/Documentation/sound/oss/README.OSS
deleted file mode 100644
index a085ea3611a1..000000000000
--- a/Documentation/sound/oss/README.OSS
+++ /dev/null
@@ -1,1455 +0,0 @@
1Introduction
2------------
3
4This file is a collection of all the old Readme files distributed with
5OSS/Lite by Hannu Savolainen. Since the new Linux sound driver is founded
6on it I think these information may still be interesting for users that
7have to configure their sound system.
8
9Be warned: Alan Cox is the current maintainer of the Linux sound driver so if
10you have problems with it, please contact him or the current device-specific
11driver maintainer (e.g. for aedsp16 specific problems contact me). If you have
12patches, contributions or suggestions send them to Alan: I'm sure they are
13welcome.
14
15In this document you will find a lot of references about OSS/Lite or ossfree:
16they are gone forever. Keeping this in mind and with a grain of salt this
17document can be still interesting and very helpful.
18
19[ File edited 17.01.1999 - Riccardo Facchetti ]
20[ Edited miroSOUND section 19.04.2001 - Robert Siemer ]
21
22OSS/Free version 3.8 release notes
23----------------------------------
24
25Please read the SOUND-HOWTO (available from sunsite.unc.edu and other Linux FTP
26sites). It gives instructions about using sound with Linux. It's bit out of
27date but still very useful. Information about bug fixes and such things
28is available from the web page (see above).
29
30Please check http://www.opensound.com/pguide for more info about programming
31with OSS API.
32
33 ====================================================
34- THIS VERSION ____REQUIRES____ Linux 2.1.57 OR LATER.
35 ====================================================
36
37Packages "snd-util-3.8.tar.gz" and "snd-data-0.1.tar.Z"
38contain useful utilities to be used with this driver.
39See http://www.opensound.com/ossfree/ for
40download instructions.
41
42If you are looking for the installation instructions, please
43look forward into this document.
44
45Supported sound cards
46---------------------
47
48See below.
49
50Contributors
51------------
52
53This driver contains code by several contributors. In addition several other
54persons have given useful suggestions. The following is a list of major
55contributors. (I could have forgotten some names.)
56
57 Craig Metz 1/2 of the PAS16 Mixer and PCM support
58 Rob Hooft Volume computation algorithm for the FM synth.
59 Mika Liljeberg uLaw encoding and decoding routines
60 Jeff Tranter Linux SOUND HOWTO document
61 Greg Lee Volume computation algorithm for the GUS and
62 lots of valuable suggestions.
63 Andy Warner ISC port
64 Jim Lowe,
65 Amancio Hasty Jr FreeBSD/NetBSD port
66 Anders Baekgaard Bug hunting and valuable suggestions.
67 Joerg Schubert SB16 DSP support (initial version).
68 Andrew Robinson Improvements to the GUS driver
69 Megens SA MIDI recording for SB and SB Pro (initial version).
70 Mikael Nordqvist Linear volume support for GUS and
71 nonblocking /dev/sequencer.
72 Ian Hartas SVR4.2 port
73 Markus Aroharju and
74 Risto Kankkunen Major contributions to the mixer support
75 of GUS v3.7.
76 Hunyue Yau Mixer support for SG NX Pro.
77 Marc Hoffman PSS support (initial version).
78 Rainer Vranken Initialization for Jazz16 (initial version).
79 Peter Trattler Initial version of loadable module support for Linux.
80 JRA Gibson 16 bit mode for Jazz16 (initial version)
81 Davor Jadrijevic MAD16 support (initial version)
82 Gregor Hoffleit Mozart support (initial version)
83 Riccardo Facchetti Audio Excel DSP 16 (aedsp16) support
84 James Hightower Spotting a tiny but important bug in CS423x support.
85 Denis Sablic OPTi 82C924 specific enhancements (non PnP mode)
86 Tim MacKenzie Full duplex support for OPTi 82C930.
87
88 Please look at lowlevel/README for more contributors.
89
90There are probably many other names missing. If you have sent me some
91patches and your name is not in the above list, please inform me.
92
93Sending your contributions or patches
94-------------------------------------
95
96First of all it's highly recommended to contact me before sending anything
97or before even starting to do any work. Tell me what you suggest to be
98changed or what you have planned to do. Also ensure you are using the
99very latest (development) version of OSS/Free since the change may already be
100implemented there. In general it's a major waste of time to try to improve a
101several months old version. Information about the latest version can be found
102from http://www.opensound.com/ossfree. In general there is no point in
103sending me patches relative to production kernels.
104
105Sponsors etc.
106-------------
107
108The following companies have greatly helped development of this driver
109in form of a free copy of their product:
110
111Novell, Inc. UnixWare personal edition + SDK
112The Santa Cruz Operation, Inc. A SCO OpenServer + SDK
113Ensoniq Corp, a SoundScape card and extensive amount of assistance
114MediaTrix Peripherals Inc, a AudioTrix Pro card + SDK
115Acer, Inc. a pair of AcerMagic S23 cards.
116
117In addition the following companies have provided me sufficient amount
118of technical information at least some of their products (free or $$$):
119
120Advanced Gravis Computer Technology Ltd.
121Media Vision Inc.
122Analog Devices Inc.
123Logitech Inc.
124Aztech Labs Inc.
125Crystal Semiconductor Corporation,
126Integrated Circuit Systems Inc.
127OAK Technology
128OPTi
129Turtle Beach
130miro
131Ad Lib Inc. ($$)
132Music Quest Inc. ($$)
133Creative Labs ($$$)
134
135If you have some problems
136=========================
137
138Read the sound HOWTO (sunsite.unc.edu:/pub/Linux/docs/...?).
139Also look at the home page (http://www.opensound.com/ossfree). It may
140contain info about some recent bug fixes.
141
142It's likely that you have some problems when trying to use the sound driver
143first time. Sound cards don't have standard configuration so there are no
144good default configuration to use. Please try to use same I/O, DMA and IRQ
145values for the sound card than with DOS.
146
147If you get an error message when trying to use the driver, please look
148at /var/adm/messages for more verbose error message.
149
150
151The following errors are likely with /dev/dsp and /dev/audio.
152
153 - "No such device or address".
154 This error indicates that there are no suitable hardware for the
155 device file or the sound driver has been compiled without support for
156 this particular device. For example /dev/audio and /dev/dsp will not
157 work if "digitized voice support" was not enabled during "make config".
158
159 - "Device or resource busy". Probably the IRQ (or DMA) channel
160 required by the sound card is in use by some other device/driver.
161
162 - "I/O error". Almost certainly (99%) it's an IRQ or DMA conflict.
163 Look at the kernel messages in /var/adm/notice for more info.
164
165 - "Invalid argument". The application is calling ioctl()
166 with impossible parameters. Check that the application is
167 for sound driver version 2.X or later.
168
169Linux installation
170==================
171
172IMPORTANT! Read this if you are installing a separately
173 distributed version of this driver.
174
175 Check that your kernel version works with this
176 release of the driver (see Readme). Also verify
177 that your current kernel version doesn't have more
178 recent sound driver version than this one. IT'S HIGHLY
179 RECOMMENDED THAT YOU USE THE SOUND DRIVER VERSION THAT
180 IS DISTRIBUTED WITH KERNEL SOURCES.
181
182- When installing separately distributed sound driver you should first
183 read the above notice. Then try to find proper directory where and how
184 to install the driver sources. You should not try to install a separately
185 distributed driver version if you are not able to find the proper way
186 yourself (in this case use the version that is distributed with kernel
187 sources). Remove old version of linux/drivers/sound directory before
188 installing new files.
189
190- To build the device files you need to run the enclosed shell script
191 (see below). You need to do this only when installing sound driver
192 first time or when upgrading to much recent version than the earlier
193 one.
194
195- Configure and compile Linux as normally (remember to include the
196 sound support during "make config"). Please refer to kernel documentation
197 for instructions about configuring and compiling kernel. File Readme.cards
198 contains card specific instructions for configuring this driver for
199 use with various sound cards.
200
201Boot time configuration (using lilo and insmod)
202-----------------------------------------------
203
204This information has been removed. Too many users didn't believe
205that it's really not necessary to use this method. Please look at
206Readme of sound driver version 3.0.1 if you still want to use this method.
207
208Problems
209--------
210
211Common error messages:
212
213- /dev/???????: No such file or directory.
214Run the script at the end of this file.
215
216- /dev/???????: No such device.
217You are not running kernel which contains the sound driver. When using
218modularized sound driver this error means that the sound driver is not
219loaded.
220
221- /dev/????: No such device or address.
222Sound driver didn't detect suitable card when initializing. Please look at
223Readme.cards for info about configuring the driver with your card. Also
224check for possible boot (insmod) time error messages in /var/adm/messages.
225
226- Other messages or problems
227Please check http://www.opensound.com/ossfree for more info.
228
229Configuring version 3.8 (for Linux) with some common sound cards
230================================================================
231
232This document describes configuring sound cards with the freeware version of
233Open Sound Systems (OSS/Free). Information about the commercial version
234(OSS/Linux) and its configuration is available from
235http://www.opensound.com/linux.html. Information presented here is
236not valid for OSS/Linux.
237
238If you are unsure about how to configure OSS/Free
239you can download the free evaluation version of OSS/Linux from the above
240address. There is a chance that it can autodetect your sound card. In this case
241you can use the information included in soundon.log when configuring OSS/Free.
242
243
244IMPORTANT! This document covers only cards that were "known" when
245 this driver version was released. Please look at
246 http://www.opensound.com/ossfree for info about
247 cards introduced recently.
248
249 When configuring the sound driver, you should carefully
250 check each sound configuration option (particularly
251 "Support for /dev/dsp and /dev/audio"). The default values
252 offered by these programs are not necessarily valid.
253
254
255THE BIGGEST MISTAKES YOU CAN MAKE
256=================================
257
2581. Assuming that the card is Sound Blaster compatible when it's not.
259--------------------------------------------------------------------
260
261The number one mistake is to assume that your card is compatible with
262Sound Blaster. Only the cards made by Creative Technology or which have
263one or more chips labeled by Creative are SB compatible. In addition there
264are few sound chipsets which are SB compatible in Linux such as ESS1688 or
265Jazz16. Note that SB compatibility in DOS/Windows does _NOT_ mean anything
266in Linux.
267
268IF YOU REALLY ARE 150% SURE YOU HAVE A SOUND BLASTER YOU CAN SKIP THE REST OF
269THIS CHAPTER.
270
271For most other "supposed to be SB compatible" cards you have to use other
272than SB drivers (see below). It is possible to get most sound cards to work
273in SB mode but in general it's a complete waste of time. There are several
274problems which you will encounter by using SB mode with cards that are not
275truly SB compatible:
276
277- The SB emulation is at most SB Pro (DSP version 3.x) which means that
278you get only 8 bit audio (there is always an another ("native") mode which
279gives the 16 bit capability). The 8 bit only operation is the reason why
280many users claim that sound quality in Linux is much worse than in DOS.
281In addition some applications require 16 bit mode and they produce just
282noise with a 8 bit only device.
283- The card may work only in some cases but refuse to work most of the
284time. The SB compatible mode always requires special initialization which is
285done by the DOS/Windows drivers. This kind of cards work in Linux after
286you have warm booted it after DOS but they don't work after cold boot
287(power on or reset).
288- You get the famous "DMA timed out" messages. Usually all SB clones have
289software selectable IRQ and DMA settings. If the (power on default) values
290currently used by the card don't match configuration of the driver you will
291get the above error message whenever you try to record or play. There are
292few other reasons to the DMA timeout message but using the SB mode seems
293to be the most common cause.
294
2952. Trying to use a PnP (Plug & Play) card just like an ordinary sound card
296--------------------------------------------------------------------------
297
298Plug & Play is a protocol defined by Intel and Microsoft. It lets operating
299systems to easily identify and reconfigure I/O ports, IRQs and DMAs of ISA
300cards. The problem with PnP cards is that the standard Linux doesn't currently
301(versions 2.1.x and earlier) don't support PnP. This means that you will have
302to use some special tricks (see later) to get a PnP card alive. Many PnP cards
303work after they have been initialized but this is not always the case.
304
305There are sometimes both PnP and non-PnP versions of the same sound card.
306The non-PnP version is the original model which usually has been discontinued
307more than an year ago. The PnP version has the same name but with "PnP"
308appended to it (sometimes not). This causes major confusion since the non-PnP
309model works with Linux but the PnP one doesn't.
310
311You should carefully check if "Plug & Play" or "PnP" is mentioned in the name
312of the card or in the documentation or package that came with the card.
313Everything described in the rest of this document is not necessarily valid for
314PnP models of sound cards even you have managed to wake up the card properly.
315Many PnP cards are simply too different from their non-PnP ancestors which are
316covered by this document.
317
318
319Cards that are not (fully) supported by this driver
320===================================================
321
322See http://www.opensound.com/ossfree for information about sound cards
323to be supported in future.
324
325
326How to use sound without recompiling kernel and/or sound driver
327===============================================================
328
329There is a commercial sound driver which comes in precompiled form and doesn't
330require recompiling of the kernel. See http://www.4Front-tech.com/oss.html for
331more info.
332
333
334Configuring PnP cards
335=====================
336
337New versions of most sound cards use the so-called ISA PnP protocol for
338soft configuring their I/O, IRQ, DMA and shared memory resources.
339Currently at least cards made by Creative Technology (SB32 and SB32AWE
340PnP), Gravis (GUS PnP and GUS PnP Pro), Ensoniq (Soundscape PnP) and
341Aztech (some Sound Galaxy models) use PnP technology. The CS4232/4236 audio
342chip by Crystal Semiconductor (Intel Atlantis, HP Pavilion and many other
343motherboards) is also based on PnP technology but there is a "native" driver
344available for it (see information about CS4232 later in this document).
345
346PnP sound cards (as well as most other PnP ISA cards) are not supported
347by this version of the driver . Proper
348support for them should be released during 97 once the kernel level
349PnP support is available.
350
351There is a method to get most of the PnP cards to work. The basic method
352is the following:
353
3541) Boot DOS so the card's DOS drivers have a chance to initialize it.
3552) _Cold_ boot to Linux by using "loadlin.exe". Hitting ctrl-alt-del
356works with older machines but causes a hard reset of all cards on recent
357(Pentium) machines.
3583) If you have the sound driver in Linux configured properly, the card should
359work now. "Proper" means that I/O, IRQ and DMA settings are the same as in
360DOS. The hard part is to find which settings were used. See the documentation of
361your card for more info.
362
363Windows 95 could work as well as DOS but running loadlin may be difficult.
364Probably you should "shut down" your machine to MS-DOS mode before running it.
365
366Some machines have a BIOS utility for setting PnP resources. This is a good
367way to configure some cards. In this case you don't need to boot DOS/Win95
368before starting Linux.
369
370Another way to initialize PnP cards without DOS/Win95 is a Linux based
371PnP isolation tool. When writing this there is a pre alpha test version
372of such a tool available from ftp://ftp.demon.co.uk/pub/unix/linux/utils. The
373file is called isapnptools-*. Please note that this tool is just a temporary
374solution which may be incompatible with future kernel versions having proper
375support for PnP cards. There are bugs in setting DMA channels in earlier
376versions of isapnptools so at least version 1.6 is required with sound cards.
377
378Yet another way to use PnP cards is to use (commercial) OSS/Linux drivers. See
379http://www.opensound.com/linux.html for more info. This is probably the way you
380should do it if you don't want to spend time recompiling the kernel and
381required tools.
382
383
384Read this before trying to configure the driver
385===============================================
386
387There are currently many cards that work with this driver. Some of the cards
388have native support while others work since they emulate some other
389card (usually SB, MSS/WSS and/or MPU401). The following cards have native
390support in the driver. Detailed instructions for configuring these cards
391will be given later in this document.
392
393Pro Audio Spectrum 16 (PAS16) and compatibles:
394 Pro Audio Spectrum 16
395 Pro Audio Studio 16
396 Logitech Sound Man 16
397 NOTE! The original Pro Audio Spectrum as well as the PAS+ are not
398 and will not be supported by the driver.
399
400Media Vision Jazz16 based cards
401 Pro Sonic 16
402 Logitech SoundMan Wave
403 (Other Jazz based cards should work but I don't have any reports
404 about them).
405
406Sound Blasters
407 SB 1.0 to 2.0
408 SB Pro
409 SB 16
410 SB32/64/AWE
411 Configure SB32/64/AWE just like SB16. See lowlevel/README.awe
412 for information about using the wave table synth.
413 NOTE! AWE63/Gold and 16/32/AWE "PnP" cards need to be activated
414 using isapnptools before they work with OSS/Free.
415 SB16 compatible cards by other manufacturers than Creative.
416 You have been fooled since there are _no_ SB16 compatible
417 cards on the market (as of May 1997). It's likely that your card
418 is compatible just with SB Pro but there is also a non-SB-
419 compatible 16 bit mode. Usually it's MSS/WSS but it could also
420 be a proprietary one like MV Jazz16 or ESS ES688. OPTi
421 MAD16 chips are very common in so called "SB 16 bit cards"
422 (try with the MAD16 driver).
423
424 ======================================================================
425 "Supposed to be SB compatible" cards.
426 Forget the SB compatibility and check for other alternatives
427 first. The only cards that work with the SB driver in
428 Linux have been made by Creative Technology (there is at least
429 one chip on the card with "CREATIVE" printed on it). The
430 only other SB compatible chips are ESS and Jazz16 chips
431 (maybe ALSxxx chips too but they probably don't work).
432 Most other "16 bit SB compatible" cards such as "OPTi/MAD16" or
433 "Crystal" are _NOT_ SB compatible in Linux.
434
435 Practically all sound cards have some kind of SB emulation mode
436 in addition to their native (16 bit) mode. In most cases this
437 (8 bit only) SB compatible mode doesn't work with Linux. If
438 you get it working it may cause problems with games and
439 applications which require 16 bit audio. Some 16 bit only
440 applications don't check if the card actually supports 16 bits.
441 They just dump 16 bit data to a 8 bit card which produces just
442 noise.
443
444 In most cases the 16 bit native mode is supported by Linux.
445 Use the SB mode with "clones" only if you don't find anything
446 better from the rest of this doc.
447 ======================================================================
448
449Gravis Ultrasound (GUS)
450 GUS
451 GUS + the 16 bit option
452 GUS MAX
453 GUS ACE (No MIDI port and audio recording)
454 GUS PnP (with RAM)
455
456MPU-401 and compatibles
457 The driver works both with the full (intelligent mode) MPU-401
458 cards (such as MPU IPC-T and MQX-32M) and with the UART only
459 dumb MIDI ports. MPU-401 is currently the most common MIDI
460 interface. Most sound cards are compatible with it. However,
461 don't enable MPU401 mode blindly. Many cards with native support
462 in the driver have their own MPU401 driver. Enabling the standard one
463 will cause a conflict with these cards. So check if your card is
464 in the list of supported cards before enabling MPU401.
465
466Windows Sound System (MSS/WSS)
467 Even when Microsoft has discontinued their own Sound System card
468 they managed to make it a standard. MSS compatible cards are based on
469 a codec chip which is easily available from at least two manufacturers
470 (AD1848 by Analog Devices and CS4231/CS4248 by Crystal Semiconductor).
471 Currently most sound cards are based on one of the MSS compatible codec
472 chips. The CS4231 is used in the high quality cards such as GUS MAX,
473 MediaTrix AudioTrix Pro and TB Tropez (GUS MAX is not MSS compatible).
474
475 Having a AD1848, CS4248 or CS4231 codec chip on the card is a good
476 sign. Even if the card is not MSS compatible, it could be easy to write
477 support for it. Note also that most MSS compatible cards
478 require special boot time initialization which may not be present
479 in the driver. Also, some MSS compatible cards have native support.
480 Enabling the MSS support with these cards is likely to
481 cause a conflict. So check if your card is listed in this file before
482 enabling the MSS support.
483
484Yamaha FM synthesizers (OPL2, OPL3 (not OPL3-SA) and OPL4)
485 Most sound cards have a FM synthesizer chip. The OPL2 is a 2
486 operator chip used in the original AdLib card. Currently it's used
487 only in the cheapest (8 bit mono) cards. The OPL3 is a 4 operator
488 FM chip which provides better sound quality and/or more available
489 voices than the OPL2. The OPL4 is a new chip that has an OPL3 and
490 a wave table synthesizer packed onto the same chip. The driver supports
491 just the OPL3 mode directly. Most cards with an OPL4 (like
492 SM Wave and AudioTrix Pro) support the OPL4 mode using MPU401
493 emulation. Writing a native OPL4 support is difficult
494 since Yamaha doesn't give information about their sample ROM chip.
495
496 Enable the generic OPL2/OPL3 FM synthesizer support if your
497 card has a FM chip made by Yamaha. Don't enable it if your card
498 has a software (TRS) based FM emulator.
499
500 ----------------------------------------------------------------
501 NOTE! OPL3-SA is different chip than the ordinary OPL3. In addition
502 to the FM synth this chip has also digital audio (WSS) and
503 MIDI (MPU401) capabilities. Support for OPL3-SA is described below.
504 ----------------------------------------------------------------
505
506Yamaha OPL3-SA1
507
508 Yamaha OPL3-SA1 (YMF701) is an audio controller chip used on some
509 (Intel) motherboards and on cheap sound cards. It should not be
510 confused with the original OPL3 chip (YMF278) which is entirely
511 different chip. OPL3-SA1 has support for MSS, MPU401 and SB Pro
512 (not used in OSS/Free) in addition to the OPL3 FM synth.
513
514 There are also chips called OPL3-SA2, OPL3-SA3, ..., OPL3SA-N. They
515 are PnP chips and will not work with the OPL3-SA1 driver. You should
516 use the standard MSS, MPU401 and OPL3 options with these chips and to
517 activate the card using isapnptools.
518
5194Front Technologies SoftOSS
520
521 SoftOSS is a software based wave table emulation which works with
522 any 16 bit stereo sound card. Due to its nature a fast CPU is
523 required (P133 is minimum). Although SoftOSS does _not_ use MMX
524 instructions it has proven out that recent processors (which appear
525 to have MMX) perform significantly better with SoftOSS than earlier
526 ones. For example a P166MMX beats a PPro200. SoftOSS should not be used
527 on 486 or 386 machines.
528
529 The amount of CPU load caused by SoftOSS can be controlled by
530 selecting the CONFIG_SOFTOSS_RATE and CONFIG_SOFTOSS_VOICES
531 parameters properly (they will be prompted by make config). It's
532 recommended to set CONFIG_SOFTOSS_VOICES to 32. If you have a
533 P166MMX or faster (PPro200 is not faster) you can set
534 CONFIG_SOFTOSS_RATE to 44100 (kHz). However with slower systems it
535 recommended to use sampling rates around 22050 or even 16000 kHz.
536 Selecting too high values for these parameters may hang your
537 system when playing MIDI files with hight degree of polyphony
538 (number of concurrently playing notes). It's also possible to
539 decrease CONFIG_SOFTOSS_VOICES. This makes it possible to use
540 higher sampling rates. However using fewer voices decreases
541 playback quality more than decreasing the sampling rate.
542
543 SoftOSS keeps the samples loaded on the system's RAM so much RAM is
544 required. SoftOSS should never be used on machines with less than 16 MB
545 of RAM since this is potentially dangerous (you may accidentally run out
546 of memory which probably crashes the machine).
547
548 SoftOSS implements the wave table API originally designed for GUS. For
549 this reason all applications designed for GUS should work (at least
550 after minor modifications). For example gmod/xgmod and playmidi -g are
551 known to work.
552
553 To work SoftOSS will require GUS compatible
554 patch files to be installed on the system (in /dos/ultrasnd/midi). You
555 can use the public domain MIDIA patchset available from several ftp
556 sites.
557
558 *********************************************************************
559 IMPORTANT NOTICE! The original patch set distributed with the Gravis
560 Ultrasound card is not in public domain (even though it's available from
561 some FTP sites). You should contact Voice Crystal (www.voicecrystal.com)
562 if you like to use these patches with SoftOSS included in OSS/Free.
563 *********************************************************************
564
565PSS based cards (AD1848 + ADSP-2115 + Echo ESC614 ASIC)
566 Analog Devices and Echo Speech have together defined a sound card
567 architecture based on the above chips. The DSP chip is used
568 for emulation of SB Pro, FM and General MIDI/MT32.
569
570 There are several cards based on this architecture. The most known
571 ones are Orchid SW32 and Cardinal DSP16.
572
573 The driver supports downloading DSP algorithms to these cards.
574
575 NOTE! You will have to use the "old" config script when configuring
576 PSS cards.
577
578MediaTrix AudioTrix Pro
579 The ATP card is built around a CS4231 codec and an OPL4 synthesizer
580 chips. The OPL4 mode is supported by a microcontroller running a
581 General MIDI emulator. There is also a SB 1.5 compatible playback mode.
582
583Ensoniq SoundScape and compatibles
584 Ensoniq has designed a sound card architecture based on the
585 OTTO synthesizer chip used in their professional MIDI synthesizers.
586 Several companies (including Ensoniq, Reveal and Spea) are selling
587 cards based on this architecture.
588
589 NOTE! The SoundScape PnP is not supported by OSS/Free. Ensoniq VIVO and
590 VIVO90 cards are not compatible with Soundscapes so the Soundscape
591 driver will not work with them. You may want to use OSS/Linux with these
592 cards.
593
594OPTi MAD16 and Mozart based cards
595 The Mozart (OAK OTI-601), MAD16 (OPTi 82C928), MAD16 Pro (OPTi 82C929),
596 OPTi 82C924/82C925 (in _non_ PnP mode) and OPTi 82C930 interface
597 chips are used in many different sound cards, including some
598 cards by Reveal miro and Turtle Beach (Tropez). The purpose of these
599 chips is to connect other audio components to the PC bus. The
600 interface chip performs address decoding for the other chips.
601 NOTE! Tropez Plus is not MAD16 but CS4232 based.
602 NOTE! MAD16 PnP cards (82C924, 82C925, 82C931) are not MAD16 compatible
603 in the PnP mode. You will have to use them in MSS mode after having
604 initialized them using isapnptools or DOS. 82C931 probably requires
605 initialization using DOS/Windows (running isapnptools is not enough).
606 It's possible to use 82C931 with OSS/Free by jumpering it to non-PnP
607 mode (provided that the card has a jumper for this). In non-PnP mode
608 82C931 is compatible with 82C930 and should work with the MAD16 driver
609 (without need to use isapnptools or DOS to initialize it). All OPTi
610 chips are supported by OSS/Linux (both in PnP and non-PnP modes).
611
612Audio Excel DSP16
613 Support for this card was written by Riccardo Faccetti
614 (riccardo@cdc8g5.cdc.polimi.it). The AEDSP16 driver included in
615 the lowlevel/ directory. To use it you should enable the
616 "Additional low level drivers" option.
617
618Crystal CS4232 and CS4236 based cards such as AcerMagic S23, TB Tropez _Plus_ and
619 many PC motherboards (Compaq, HP, Intel, ...)
620 CS4232 is a PnP multimedia chip which contains a CS3231A codec,
621 SB and MPU401 emulations. There is support for OPL3 too.
622 Unfortunately the MPU401 mode doesn't work (I don't know how to
623 initialize it). CS4236 is an enhanced (compatible) version of CS4232.
624 NOTE! Don't ever try to use isapnptools with CS4232 since this will just
625 freeze your machine (due to chip bugs). If you have problems in getting
626 CS4232 working you could try initializing it with DOS (CS4232C.EXE) and
627 then booting Linux using loadlin. CS4232C.EXE loads a secret firmware
628 patch which is not documented by Crystal.
629
630Turtle Beach Maui and Tropez "classic"
631 This driver version supports sample, patch and program loading commands
632 described in the Maui/Tropez User's manual.
633 There is now full initialization support too. The audio side of
634 the Tropez is based on the MAD16 chip (see above).
635 NOTE! Tropez Plus is different card than Tropez "classic" and will not
636 work fully in Linux. You can get audio features working by configuring
637 the card as a CS4232 based card (above).
638
639
640Jumpers and software configuration
641==================================
642
643Some of the earliest sound cards were jumper configurable. You have to
644configure the driver use I/O, IRQ and DMA settings
645that match the jumpers. Just few 8 bit cards are fully jumper
646configurable (SB 1.x/2.x, SB Pro and clones).
647Some cards made by Aztech have an EEPROM which contains the
648config info. These cards behave much like hardware jumpered cards.
649
650Most cards have jumper for the base I/O address but other parameters
651are software configurable. Sometimes there are few other jumpers too.
652
653Latest cards are fully software configurable or they are PnP ISA
654compatible. There are no jumpers on the board.
655
656The driver handles software configurable cards automatically. Just configure
657the driver to use I/O, IRQ and DMA settings which are known to work.
658You could usually use the same values than with DOS and/or Windows.
659Using different settings is possible but not recommended since it may cause
660some trouble (for example when warm booting from an OS to another or
661when installing new hardware to the machine).
662
663Sound driver sets the soft configurable parameters of the card automatically
664during boot. Usually you don't need to run any extra initialization
665programs when booting Linux but there are some exceptions. See the
666card-specific instructions below for more info.
667
668The drawback of software configuration is that the driver needs to know
669how the card must be initialized. It cannot initialize unknown cards
670even if they are otherwise compatible with some other cards (like SB,
671MPU401 or Windows Sound System).
672
673
674What if your card was not listed above?
675=======================================
676
677The first thing to do is to look at the major IC chips on the card.
678Many of the latest sound cards are based on some standard chips. If you
679are lucky, all of them could be supported by the driver. The most common ones
680are the OPTi MAD16, Mozart, SoundScape (Ensoniq) and the PSS architectures
681listed above. Also look at the end of this file for list of unsupported
682cards and the ones which could be supported later.
683
684The last resort is to send _exact_ name and model information of the card
685to me together with a list of the major IC chips (manufactured, model) to
686me. I could then try to check if your card looks like something familiar.
687
688There are many more cards in the world than listed above. The first thing to
689do with these cards is to check if they emulate some other card or interface
690such as SB, MSS and/or MPU401. In this case there is a chance to get the
691card to work by booting DOS before starting Linux (boot DOS, hit ctrl-alt-del
692and boot Linux without hard resetting the machine). In this method the
693DOS based driver initializes the hardware to use known I/O, IRQ and DMA
694settings. If sound driver is configured to use the same settings, everything
695should work OK.
696
697
698Configuring sound driver (with Linux)
699=====================================
700
701The sound driver is currently distributed as part of the Linux kernel. The
702files are in /usr/src/linux/drivers/sound/.
703
704****************************************************************************
705* ALWAYS USE THE SOUND DRIVER VERSION WHICH IS DISTRIBUTED WITH *
706* THE KERNEL SOURCE PACKAGE YOU ARE USING. SOME ALPHA AND BETA TEST *
707* VERSIONS CAN BE INSTALLED FROM A SEPARATELY DISTRIBUTED PACKAGE *
708* BUT CHECK THAT THE PACKAGE IS NOT MUCH OLDER (OR NEWER) THAN THE *
709* KERNEL YOU ARE USING. IT'S POSSIBLE THAT THE KERNEL/DRIVER *
710* INTERFACE CHANGES BETWEEN KERNEL RELEASES WHICH MAY CAUSE SOME *
711* INCOMPATIBILITY PROBLEMS. *
712* *
713* IN CASE YOU INSTALL A SEPARATELY DISTRIBUTED SOUND DRIVER VERSION, *
714* BE SURE TO REMOVE OR RENAME THE OLD SOUND DRIVER DIRECTORY BEFORE *
715* INSTALLING THE NEW ONE. LEAVING OLD FILES TO THE SOUND DRIVER *
716* DIRECTORY _WILL_ CAUSE PROBLEMS WHEN THE DRIVER IS USED OR *
717* COMPILED. *
718****************************************************************************
719
720To configure the driver, run "make config" in the kernel source directory
721(/usr/src/linux). Answer "y" or "m" to the question about Sound card support
722(after the questions about mouse, CD-ROM, ftape, etc. support). Questions
723about options for sound will then be asked.
724
725After configuring the kernel and sound driver and compile the kernel
726following instructions in the kernel README.
727
728The sound driver configuration dialog
729-------------------------------------
730
731Sound configuration starts by making some yes/no questions. Be careful
732when answering to these questions since answering y to a question may
733prevent some later ones from being asked. For example don't answer y to
734the first question (PAS16) if you don't really have a PAS16. Don't enable
735more cards than you really need since they just consume memory. Also
736some drivers (like MPU401) may conflict with your SCSI controller and
737prevent kernel from booting. If you card was in the list of supported
738cards (above), please look at the card specific config instructions
739(later in this file) before starting to configure. Some cards must be
740configured in way which is not obvious.
741
742So here is the beginning of the config dialog. Answer 'y' or 'n' to these
743questions. The default answer is shown so that (y/n) means 'y' by default and
744(n/y) means 'n'. To use the default value, just hit ENTER. But be careful
745since using the default _doesn't_ guarantee anything.
746
747Note also that all questions may not be asked. The configuration program
748may disable some questions depending on the earlier choices. It may also
749select some options automatically as well.
750
751 "ProAudioSpectrum 16 support",
752 - Answer 'y'_ONLY_ if you have a Pro Audio Spectrum _16_,
753 Pro Audio Studio 16 or Logitech SoundMan 16 (be sure that
754 you read the above list correctly). Don't answer 'y' if you
755 have some other card made by Media Vision or Logitech since they
756 are not PAS16 compatible.
757 NOTE! Since 3.5-beta10 you need to enable SB support (next question)
758 if you want to use the SB emulation of PAS16. It's also possible to
759 the emulation if you want to use a true SB card together with PAS16
760 (there is another question about this that is asked later).
761 "Sound Blaster support",
762 - Answer 'y' if you have an original SB card made by Creative Labs
763 or a full 100% hardware compatible clone (like Thunderboard or
764 SM Games). If your card was in the list of supported cards (above),
765 please look at the card specific instructions later in this file
766 before answering this question. For an unknown card you may answer
767 'y' if the card claims to be SB compatible.
768 Enable this option also with PAS16 (changed since v3.5-beta9).
769
770 Don't enable SB if you have a MAD16 or Mozart compatible card.
771
772 "Generic OPL2/OPL3 FM synthesizer support",
773 - Answer 'y' if your card has a FM chip made by Yamaha (OPL2/OPL3/OPL4).
774 Answering 'y' is usually a safe and recommended choice. However some
775 cards may have software (TSR) FM emulation. Enabling FM support
776 with these cards may cause trouble. However I don't currently know
777 such cards.
778 "Gravis Ultrasound support",
779 - Answer 'y' if you have GUS or GUS MAX. Answer 'n' if you don't
780 have GUS since the GUS driver consumes much memory.
781 Currently I don't have experiences with the GUS ACE so I don't
782 know what to answer with it.
783 "MPU-401 support (NOT for SB16)",
784 - Be careful with this question. The MPU401 interface is supported
785 by almost any sound card today. However some natively supported cards
786 have their own driver for MPU401. Enabling the MPU401 option with
787 these cards will cause a conflict. Also enabling MPU401 on a system
788 that doesn't really have a MPU401 could cause some trouble. If your
789 card was in the list of supported cards (above), please look at
790 the card specific instructions later in this file.
791
792 In MOST cases this MPU401 driver should only be used with "true"
793 MIDI-only MPU401 professional cards. In most other cases there
794 is another way to get the MPU401 compatible interface of a
795 sound card to work.
796 Support for the MPU401 compatible MIDI port of SB16, ESS1688
797 and MV Jazz16 cards is included in the SB driver. Use it instead
798 of this separate MPU401 driver with these cards. As well
799 Soundscape, PSS and Maui drivers include their own MPU401
800 options.
801
802 It's safe to answer 'y' if you have a true MPU401 MIDI interface
803 card.
804 "6850 UART Midi support",
805 - It's safe to answer 'n' to this question in all cases. The 6850
806 UART interface is so rarely used.
807 "PSS (ECHO-ADI2111) support",
808 - Answer 'y' only if you have Orchid SW32, Cardinal DSP16 or some
809 other card based on the PSS chipset (AD1848 codec + ADSP-2115
810 DSP chip + Echo ESC614 ASIC CHIP).
811 "16 bit sampling option of GUS (_NOT_ GUS MAX)",
812 - Answer 'y' if you have installed the 16 bit sampling daughtercard
813 to your GUS. Answer 'n' if you have GUS MAX. Enabling this option
814 disables GUS MAX support.
815 "GUS MAX support",
816 - Answer 'y' only if you have a GUS MAX.
817 "Microsoft Sound System support",
818 - Again think carefully before answering 'y' to this question. It's
819 safe to answer 'y' in case you have the original Windows Sound
820 System card made by Microsoft or Aztech SG 16 Pro (or NX16 Pro).
821 Also you may answer 'y' in case your card was not listed earlier
822 in this file. For cards having native support in the driver, consult
823 the card specific instructions later in this file. Some drivers
824 have their own MSS support and enabling this option will cause a
825 conflict.
826 Note! The MSS driver permits configuring two DMA channels. This is a
827 "nonstandard" feature and works only with very few cards (if any).
828 In most cases the second DMA channel should be disabled or set to
829 the same channel than the first one. Trying to configure two separate
830 channels with cards that don't support this feature will prevent
831 audio (at least recording) from working.
832 "Ensoniq Soundscape support",
833 - Answer 'y' if you have a sound card based on the Ensoniq SoundScape
834 chipset. Such cards are being manufactured at least by Ensoniq,
835 Spea and Reveal (note that Reveal makes other cards also). The oldest
836 cards made by Spea don't work properly with Linux.
837 Soundscape PnP as well as Ensoniq VIVO work only with the commercial
838 OSS/Linux version.
839 "MediaTrix AudioTrix Pro support",
840 - Answer 'y' if you have the AudioTrix Pro.
841 "Support for MAD16 and/or Mozart based cards",
842 - Answer y if your card has a Mozart (OAK OTI-601) or MAD16
843 (OPTi 82C928, 82C929, 82C924/82C925 or 82C930) audio interface chip.
844 These chips are
845 currently quite common so it's possible that many no-name cards
846 have one of them. In addition the MAD16 chip is used in some
847 cards made by known manufacturers such as Turtle Beach (Tropez),
848 Reveal (some models) and Diamond (some recent models).
849 Note OPTi 82C924 and 82C925 are MAD16 compatible only in non PnP
850 mode (jumper selectable on many cards).
851 "Support for TB Maui"
852 - This enables TB Maui specific initialization. Works with TB Maui
853 and TB Tropez (may not work with Tropez Plus).
854
855
856Then the configuration program asks some y/n questions about the higher
857level services. It's recommended to answer 'y' to each of these questions.
858Answer 'n' only if you know you will not need the option.
859
860 "MIDI interface support",
861 - Answering 'n' disables /dev/midi## devices and access to any
862 MIDI ports using /dev/sequencer and /dev/music. This option
863 also affects any MPU401 and/or General MIDI compatible devices.
864 "FM synthesizer (YM3812/OPL-3) support",
865 - Answer 'y' here.
866 "/dev/sequencer support",
867 - Answering 'n' disables /dev/sequencer and /dev/music.
868
869Entering the I/O, IRQ and DMA config parameters
870-----------------------------------------------
871
872After the above questions the configuration program prompts for the
873card specific configuration information. Usually just a set of
874I/O address, IRQ and DMA numbers are asked. With some cards the program
875asks for some files to be used during initialization of the card. For example
876many cards have a DSP chip or microprocessor which must be initialized by
877downloading a program (microcode) file to the card.
878
879Instructions for answering these questions are given in the next section.
880
881
882Card specific information
883=========================
884
885This section gives additional instructions about configuring some cards.
886Please refer manual of your card for valid I/O, IRQ and DMA numbers. Using
887the same settings with DOS/Windows and Linux is recommended. Using
888different values could cause some problems when switching between
889different operating systems.
890
891Sound Blasters (the original ones by Creative)
892---------------------------------------------
893
894NOTE! Check if you have a PnP Sound Blaster (cards sold after summer 1995
895 are almost certainly PnP ones). With PnP cards you should use isapnptools
896 to activate them (see above).
897
898It's possible to configure these cards to use different I/O, IRQ and
899DMA settings. Since the possible/default settings have changed between various
900models, you have to consult manual of your card for the proper ones. It's
901a good idea to use the same values than with DOS/Windows. With SB and SB Pro
902it's the only choice. SB16 has software selectable IRQ and DMA channels but
903using different values with DOS and Linux is likely to cause troubles. The
904DOS driver is not able to reset the card properly after warm boot from Linux
905if Linux has used different IRQ or DMA values.
906
907The original (steam) Sound Blaster (versions 1.x and 2.x) use always
908DMA1. There is no way to change it.
909
910The SB16 needs two DMA channels. A 8 bit one (1 or 3) is required for
9118 bit operation and a 16 bit one (5, 6 or 7) for the 16 bit mode. In theory
912it's possible to use just one (8 bit) DMA channel by answering the 8 bit
913one when the configuration program asks for the 16 bit one. This may work
914in some systems but is likely to cause terrible noise on some other systems.
915
916It's possible to use two SB16/32/64 at the same time. To do this you should
917first configure OSS/Free for one card. Then edit local.h manually and define
918SB2_BASE, SB2_IRQ, SB2_DMA and SB2_DMA2 for the second one. You can't get
919the OPL3, MIDI and EMU8000 devices of the second card to work. If you are
920going to use two PnP Sound Blasters, ensure that they are of different model
921and have different PnP IDs. There is no way to get two cards with the same
922card ID and serial number to work. The easiest way to check this is trying
923if isapnptools can see both cards or just one.
924
925NOTE! Don't enable the SM Games option (asked by the configuration program)
926 if you are not 101% sure that your card is a Logitech Soundman Games
927 (not a SM Wave or SM16).
928
929SB Clones
930---------
931
932First of all: There are no SB16 clones. There are SB Pro clones with a
93316 bit mode which is not SB16 compatible. The most likely alternative is that
934the 16 bit mode means MSS/WSS.
935
936There are just a few fully 100% hardware SB or SB Pro compatible cards.
937I know just Thunderboard and SM Games. Other cards require some kind of
938hardware initialization before they become SB compatible. Check if your card
939was listed in the beginning of this file. In this case you should follow
940instructions for your card later in this file.
941
942For other not fully SB clones you may try initialization using DOS in
943the following way:
944
945 - Boot DOS so that the card specific driver gets run.
946 - Hit ctrl-alt-del (or use loadlin) to boot Linux. Don't
947 switch off power or press the reset button.
948 - If you use the same I/O, IRQ and DMA settings in Linux, the
949 card should work.
950
951If your card is both SB and MSS compatible, I recommend using the MSS mode.
952Most cards of this kind are not able to work in the SB and the MSS mode
953simultaneously. Using the MSS mode provides 16 bit recording and playback.
954
955ProAudioSpectrum 16 and compatibles
956-----------------------------------
957
958PAS16 has a SB emulation chip which can be used together with the native
959(16 bit) mode of the card. To enable this emulation you should configure
960the driver to have SB support too (this has been changed since version
9613.5-beta9 of this driver).
962
963With current driver versions it's also possible to use PAS16 together with
964another SB compatible card. In this case you should configure SB support
965for the other card and to disable the SB emulation of PAS16 (there is a
966separate questions about this).
967
968With PAS16 you can use two audio device files at the same time. /dev/dsp (and
969/dev/audio) is connected to the 8/16 bit native codec and the /dev/dsp1 (and
970/dev/audio1) is connected to the SB emulation (8 bit mono only).
971
972Gravis Ultrasound
973-----------------
974
975There are many different revisions of the Ultrasound card (GUS). The
976earliest ones (pre 3.7) don't have a hardware mixer. With these cards
977the driver uses a software emulation for synth and pcm playbacks. It's
978also possible to switch some of the inputs (line in, mic) off by setting
979mixer volume of the channel level below 10%. For recording you have
980to select the channel as a recording source and to use volume above 10%.
981
982GUS 3.7 has a hardware mixer.
983
984GUS MAX and the 16 bit sampling daughtercard have a CS4231 codec chip which
985also contains a mixer.
986
987Configuring GUS is simple. Just enable the GUS support and GUS MAX or
988the 16 bit daughtercard if you have them. Note that enabling the daughter
989card disables GUS MAX driver.
990
991NOTE for owners of the 16 bit daughtercard: By default the daughtercard
992uses /dev/dsp (and /dev/audio). Command "ln -sf /dev/dsp1 /dev/dsp"
993selects the daughter card as the default device.
994
995With just the standard GUS enabled the configuration program prompts
996for the I/O, IRQ and DMA numbers for the card. Use the same values than
997with DOS.
998
999With the daughter card option enabled you will be prompted for the I/O,
1000IRQ and DMA numbers for the daughter card. You have to use different I/O
1001and DMA values than for the standard GUS. The daughter card permits
1002simultaneous recording and playback. Use /dev/dsp (the daughtercard) for
1003recording and /dev/dsp1 (GUS GF1) for playback.
1004
1005GUS MAX uses the same I/O address and IRQ settings than the original GUS
1006(GUS MAX = GUS + a CS4231 codec). In addition an extra DMA channel may be used.
1007Using two DMA channels permits simultaneous playback using two devices
1008(dev/dsp0 and /dev/dsp1). The second DMA channel is required for
1009full duplex audio.
1010To enable the second DMA channels, give a valid DMA channel when the config
1011program asks for the GUS MAX DMA (entering -1 disables the second DMA).
1012Using 16 bit DMA channels (5,6 or 7) is recommended.
1013
1014If you have problems in recording with GUS MAX, you could try to use
1015just one 8 bit DMA channel. Recording will not work with one DMA
1016channel if it's a 16 bit one.
1017
1018Microphone input of GUS MAX is connected to mixer in little bit nonstandard
1019way. There is actually two microphone volume controls. Normal "mic" controls
1020only recording level. Mixer control "speaker" is used to control volume of
1021microphone signal connected directly to line/speaker out. So just decrease
1022volume of "speaker" if you have problems with microphone feedback.
1023
1024GUS ACE works too but any attempt to record or to use the MIDI port
1025will fail.
1026
1027GUS PnP (with RAM) is partially supported but it needs to be initialized using
1028DOS or isapnptools before starting the driver.
1029
1030MPU401 and Windows Sound System
1031-------------------------------
1032
1033Again. Don't enable these options in case your card is listed
1034somewhere else in this file.
1035
1036Configuring these cards is obvious (or it should be). With MSS
1037you should probably enable the OPL3 synth also since
1038most MSS compatible cards have it. However check that this is true
1039before enabling OPL3.
1040
1041Sound driver supports more than one MPU401 compatible cards at the same time
1042but the config program asks config info for just the first of them.
1043Adding the second or third MPU interfaces must be done manually by
1044editing sound/local.h (after running the config program). Add defines for
1045MPU2_BASE & MPU2_IRQ (and MPU3_BASE & MPU3_IRQ) to the file.
1046
1047CAUTION!
1048
1049The default I/O base of Adaptec AHA-1542 SCSI controller is 0x330 which
1050is also the default of the MPU401 driver. Don't configure the sound driver to
1051use 0x330 as the MPU401 base if you have a AHA1542. The kernel will not boot
1052if you make this mistake.
1053
1054PSS
1055---
1056
1057Even the PSS cards are compatible with SB, MSS and MPU401, you must not
1058enable these options when configuring the driver. The configuration
1059program handles these options itself. (You may use the SB, MPU and MSS options
1060together with PSS if you have another card on the system).
1061
1062The PSS driver enables MSS and MPU401 modes of the card. SB is not enabled
1063since it doesn't work concurrently with MSS. The driver loads also a
1064DSP algorithm which is used to for the general MIDI emulation. The
1065algorithm file (.ld) is read by the config program and written to a
1066file included when the pss.c is compiled. For this reason the config
1067program asks if you want to download the file. Use the genmidi.ld file
1068distributed with the DOS/Windows drivers of the card (don't use the mt32.ld).
1069With some cards the file is called 'synth.ld'. You must have access to
1070the file when configuring the driver. The easiest way is to mount the DOS
1071partition containing the file with Linux.
1072
1073It's possible to load your own DSP algorithms and run them with the card.
1074Look at the directory pss_test of snd-util-3.0.tar.gz for more info.
1075
1076AudioTrix Pro
1077-------------
1078
1079You have to enable the OPL3 and SB (not SB Pro or SB16) drivers in addition
1080to the native AudioTrix driver. Don't enable MSS or MPU drivers.
1081
1082Configuring ATP is little bit tricky since it uses so many I/O, IRQ and
1083DMA numbers. Using the same values than with DOS/Win is a good idea. Don't
1084attempt to use the same IRQ or DMA channels twice.
1085
1086The SB mode of ATP is implemented so the ATP driver just enables SB
1087in the proper address. The SB driver handles the rest. You have to configure
1088both the SB driver and the SB mode of ATP to use the same IRQ, DMA and I/O
1089settings.
1090
1091Also the ATP has a microcontroller for the General MIDI emulation (OPL4).
1092For this reason the driver asks for the name of a file containing the
1093microcode (TRXPRO.HEX). This file is usually located in the directory
1094where the DOS drivers were installed. You must have access to this file
1095when configuring the driver.
1096
1097If you have the effects daughtercard, it must be initialized by running
1098the setfx program of snd-util-3.0.tar.gz package. This step is not required
1099when using the (future) binary distribution version of the driver.
1100
1101Ensoniq SoundScape
1102------------------
1103
1104NOTE! The new PnP SoundScape is not supported yet. Soundscape compatible
1105 cards made by Reveal don't work with Linux. They use older revision
1106 of the Soundscape chipset which is not fully compatible with
1107 newer cards made by Ensoniq.
1108
1109The SoundScape driver handles initialization of MSS and MPU supports
1110itself so you don't need to enable other drivers than SoundScape
1111(enable also the /dev/dsp, /dev/sequencer and MIDI supports).
1112
1113!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1114!!!!! !!!!
1115!!!!! NOTE! Before version 3.5-beta6 there WERE two sets of audio !!!!
1116!!!!! device files (/dev/dsp0 and /dev/dsp1). The first one WAS !!!!
1117!!!!! used only for card initialization and the second for audio !!!!
1118!!!!! purposes. It WAS required to change /dev/dsp (a symlink) to !!!!
1119!!!!! point to /dev/dsp1. !!!!
1120!!!!! !!!!
1121!!!!! This is not required with OSS versions 3.5-beta6 and later !!!!
1122!!!!! since there is now just one audio device file. Please !!!!
1123!!!!! change /dev/dsp to point back to /dev/dsp0 if you are !!!!
1124!!!!! upgrading from an earlier driver version using !!!!
1125!!!!! (cd /dev;rm dsp;ln -s dsp0 dsp). !!!!
1126!!!!! !!!!
1127!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1128
1129The configuration program asks one DMA channel and two interrupts. One IRQ
1130and one DMA is used by the MSS codec. The second IRQ is required for the
1131MPU401 mode (you have to use different IRQs for both purposes).
1132There were earlier two DMA channels for SoundScape but the current driver
1133version requires just one.
1134
1135The SoundScape card has a Motorola microcontroller which must initialized
1136_after_ boot (the driver doesn't initialize it during boot).
1137The initialization is done by running the 'ssinit' program which is
1138distributed in the snd-util-3.0.tar.gz package. You have to edit two
1139defines in the ssinit.c and then compile the program. You may run ssinit
1140manually (after each boot) or add it to /etc/rc.d/rc.local.
1141
1142The ssinit program needs the microcode file that comes with the DOS/Windows
1143driver of the card. You will need to use version 1.30.00 or later
1144of the microcode file (sndscape.co0 or sndscape.co1 depending on
1145your card model). THE OLD sndscape.cod WILL NOT WORK. IT WILL HANG YOUR
1146MACHINE. The only way to get the new microcode file is to download
1147and install the DOS/Windows driver from ftp://ftp.ensoniq.com/pub.
1148
1149Then you have to select the proper microcode file to use: soundscape.co0
1150is the right one for most cards and sndscape.co1 is for few (older) cards
1151made by Reveal and/or Spea. The driver has capability to detect the card
1152version during boot. Look at the boot log messages in /var/adm/messages
1153and locate the sound driver initialization message for the SoundScape
1154card. If the driver displays string <Ensoniq Soundscape (old)>, you have
1155an old card and you will need to use sndscape.co1. For other cards use
1156soundscape.co0. New Soundscape revisions such as Elite and PnP use
1157code files with higher numbers (.co2, .co3, etc.).
1158
1159NOTE! Ensoniq Soundscape VIVO is not compatible with other Soundscape cards.
1160 Currently it's possible to use it in Linux only with OSS/Linux
1161 drivers.
1162
1163Check /var/adm/messages after running ssinit. The driver prints
1164the board version after downloading the microcode file. That version
1165number must match the number in the name of the microcode file (extension).
1166
1167Running ssinit with a wrong version of the sndscape.co? file is not
1168dangerous as long as you don't try to use a file called sndscape.cod.
1169If you have initialized the card using a wrong microcode file (sounds
1170are terrible), just modify ssinit.c to use another microcode file and try
1171again. It's possible to use an earlier version of sndscape.co[01] but it
1172may sound weird.
1173
1174MAD16 (Pro) and Mozart
1175----------------------
1176
1177You need to enable just the MAD16 /Mozart support when configuring
1178the driver. _Don't_ enable SB, MPU401 or MSS. However you will need the
1179/dev/audio, /dev/sequencer and MIDI supports.
1180
1181Mozart and OPTi 82C928 (the original MAD16) chips don't support
1182MPU401 mode so enter just 0 when the configuration program asks the
1183MPU/MIDI I/O base. The MAD16 Pro (OPTi 82C929) and 82C930 chips have MPU401
1184mode.
1185
1186TB Tropez is based on the 82C929 chip. It has two MIDI ports.
1187The one connected to the MAD16 chip is the second one (there is a second
1188MIDI connector/pins somewhere??). If you have not connected the second MIDI
1189port, just disable the MIDI port of MAD16. The 'Maui' compatible synth of
1190Tropez is jumper configurable and not connected to the MAD16 chip (the
1191Maui driver can be used with it).
1192
1193Some MAD16 based cards may cause feedback, whistle or terrible noise if the
1194line3 mixer channel is turned too high. This happens at least with Shuttle
1195Sound System. Current driver versions set volume of line3 low enough so
1196this should not be a problem.
1197
1198If you have a MAD16 card which have an OPL4 (FM + Wave table) synthesizer
1199chip (_not_ an OPL3), you have to append a line containing #define MAD16_OPL4
1200to the file linux/drivers/sound/local.h (after running make config).
1201
1202MAD16 cards having a CS4231 codec support full duplex mode. This mode
1203can be enabled by configuring the card to use two DMA channels. Possible
1204DMA channel pairs are: 0&1, 1&0 and 3&0.
1205
1206NOTE! Cards having an OPTi 82C924/82C925 chip work with OSS/Free only in
1207non-PnP mode (usually jumper selectable). The PnP mode is supported only
1208by OSS/Linux.
1209
1210MV Jazz (ProSonic)
1211------------------
1212
1213The Jazz16 driver is just a hack made to the SB Pro driver. However it works
1214fairly well. You have to enable SB, SB Pro (_not_ SB16) and MPU401 supports
1215when configuring the driver. The configuration program asks later if you
1216want support for MV Jazz16 based cards (after asking SB base address). Answer
1217'y' here and the driver asks the second (16 bit) DMA channel.
1218
1219The Jazz16 driver uses the MPU401 driver in a way which will cause
1220problems if you have another MPU401 compatible card. In this case you must
1221give address of the Jazz16 based MPU401 interface when the config
1222program prompts for the MPU401 information. Then look at the MPU401
1223specific section for instructions about configuring more than one MPU401 cards.
1224
1225Logitech Soundman Wave
1226----------------------
1227
1228Read the above MV Jazz specific instructions first.
1229
1230The Logitech SoundMan Wave (don't confuse this with the SM16 or SM Games) is
1231a MV Jazz based card which has an additional OPL4 based wave table
1232synthesizer. The OPL4 chip is handled by an on board microcontroller
1233which must be initialized during boot. The config program asks if
1234you have a SM Wave immediately after asking the second DMA channel of jazz16.
1235If you answer 'y', the config program will ask name of the file containing
1236code to be loaded to the microcontroller. The file is usually called
1237MIDI0001.BIN and it's located in the DOS/Windows driver directory. The file
1238may also be called as TSUNAMI.BIN or something else (older cards?).
1239
1240The OPL4 synth will be inaccessible without loading the microcontroller code.
1241
1242Also remember to enable SB MPU401 support if you want to use the OPL4 mode.
1243(Don't enable the 'normal' MPU401 device as with some earlier driver
1244versions (pre 3.5-alpha8)).
1245
1246NOTE! Don't answer 'y' when the driver asks about SM Games support
1247 (the next question after the MIDI0001.BIN name). However
1248 answering 'y' doesn't cause damage your computer so don't panic.
1249
1250Sound Galaxies
1251--------------
1252
1253There are many different Sound Galaxy cards made by Aztech. The 8 bit
1254ones are fully SB or SB Pro compatible and there should be no problems
1255with them.
1256
1257The older 16 bit cards (SG Pro16, SG NX Pro16, Nova and Lyra) have
1258an EEPROM chip for storing the configuration data. There is a microcontroller
1259which initializes the card to match the EEPROM settings when the machine
1260is powered on. These cards actually behave just like they have jumpers
1261for all of the settings. Configure driver for MSS, MPU, SB/SB Pro and OPL3
1262supports with these cards.
1263
1264There are some new Sound Galaxies in the market. I have no experience with
1265them so read the card's manual carefully.
1266
1267ESS ES1688 and ES688 'AudioDrive' based cards
1268---------------------------------------------
1269
1270Support for these two ESS chips is embedded in the SB driver.
1271Configure these cards just like SB. Enable the 'SB MPU401 MIDI port'
1272if you want to use MIDI features of ES1688. ES688 doesn't have MPU mode
1273so you don't need to enable it (the driver uses normal SB MIDI automatically
1274with ES688).
1275
1276NOTE! ESS cards are not compatible with MSS/WSS so don't worry if MSS support
1277of OSS doesn't work with it.
1278
1279There are some ES1688/688 based sound cards and (particularly) motherboards
1280which use software configurable I/O port relocation feature of the chip.
1281This ESS proprietary feature is supported only by OSS/Linux.
1282
1283There are ES1688 based cards which use different interrupt pin assignment than
1284recommended by ESS (5, 7, 9/2 and 10). In this case all IRQs don't work.
1285At least a card called (Pearl?) Hypersound 16 supports IRQ 15 but it doesn't
1286work.
1287
1288ES1868 is a PnP chip which is (supposed to be) compatible with ESS1688
1289probably works with OSS/Free after initialization using isapnptools.
1290
1291Reveal cards
1292------------
1293
1294There are several different cards made/marketed by Reveal. Some of them
1295are compatible with SoundScape and some use the MAD16 chip. You may have
1296to look at the card and try to identify its origin.
1297
1298Diamond
1299-------
1300
1301The oldest (Sierra Aria based) sound cards made by Diamond are not supported
1302(they may work if the card is initialized using DOS). The recent (LX?)
1303models are based on the MAD16 chip which is supported by the driver.
1304
1305Audio Excel DSP16
1306-----------------
1307
1308Support for this card is currently not functional. A new driver for it
1309should be available later this year.
1310
1311PCMCIA cards
1312------------
1313
1314Sorry, can't help. Some cards may work and some don't.
1315
1316TI TM4000M notebooks
1317--------------------
1318
1319These computers have a built in sound support based on the Jazz chipset.
1320Look at the instructions for MV Jazz (above). It's also important to note
1321that there is something wrong with the mouse port and sound at least on
1322some TM models. Don't enable the "C&T 82C710 mouse port support" when
1323configuring Linux. Having it enabled is likely to cause mysterious problems
1324and kernel failures when sound is used.
1325
1326miroSOUND
1327---------
1328
1329The miroSOUND PCM1-pro, PCM12 and PCM20 radio has been used
1330successfully. These cards are based on the MAD16, OPL4, and CS4231A chips
1331and everything said in the section about MAD16 cards applies here,
1332too. The only major difference between the PCMxx and other MAD16 cards
1333is that instead of the mixer in the CS4231 codec a separate mixer
1334controlled by an on-board 80C32 microcontroller is used. Control of
1335the mixer takes place via the ACI (miro's audio control interface)
1336protocol that is implemented in a separate lowlevel driver. Make sure
1337you compile this ACI driver together with the normal MAD16 support
1338when you use a miroSOUND PCMxx card. The ACI mixer is controlled by
1339/dev/mixer and the CS4231 mixer by /dev/mixer1 (depends on load
1340time). Only in special cases you want to change something regularly on
1341the CS4231 mixer.
1342
1343The miroSOUND PCM12 and PCM20 radio is capable of full duplex
1344operation (simultaneous PCM replay and recording), which allows you to
1345implement nice real-time signal processing audio effect software and
1346network telephones. The ACI mixer has to be switched into the "solo"
1347mode for duplex operation in order to avoid feedback caused by the
1348mixer (input hears output signal). You can de-/activate this mode
1349through toggling the record button for the wave controller with an
1350OSS-mixer.
1351
1352The PCM20 contains a radio tuner, which is also controlled by
1353ACI. This radio tuner is supported by the ACI driver together with the
1354miropcm20.o module. Also the 7-band equalizer is integrated
1355(limited by the OSS-design). Development has started and maybe
1356finished for the RDS decoder on this card, too. You will be able to
1357read RadioText, the Programme Service name, Programme TYpe and
1358others. Even the v4l radio module benefits from it with a refined
1359strength value. See aci.[ch] and miropcm20*.[ch] for more details.
1360
1361The following configuration parameters have worked fine for the PCM12
1362in Markus Kuhn's system, many other configurations might work, too:
1363CONFIG_MAD16_BASE=0x530, CONFIG_MAD16_IRQ=11, CONFIG_MAD16_DMA=3,
1364CONFIG_MAD16_DMA2=0, CONFIG_MAD16_MPU_BASE=0x330, CONFIG_MAD16_MPU_IRQ=10,
1365DSP_BUFFSIZE=65536, SELECTED_SOUND_OPTIONS=0x00281000.
1366
1367Bas van der Linden is using his PCM1-pro with a configuration that
1368differs in: CONFIG_MAD16_IRQ=7, CONFIG_MAD16_DMA=1, CONFIG_MAD16_MPU_IRQ=9
1369
1370Compaq Deskpro XL
1371-----------------
1372
1373The builtin sound hardware of Compaq Deskpro XL is now supported.
1374You need to configure the driver with MSS and OPL3 supports enabled.
1375In addition you need to manually edit linux/drivers/sound/local.h and
1376to add a line containing "#define DESKPROXL" if you used
1377make menuconfig/xconfig.
1378
1379Others?
1380-------
1381
1382Since there are so many different sound cards, it's likely that I have
1383forgotten to mention many of them. Please inform me if you know yet another
1384card which works with Linux, please inform me (or is anybody else
1385willing to maintain a database of supported cards (just like in XF86)?).
1386
1387Cards not supported yet
1388=======================
1389
1390Please check the version of sound driver you are using before
1391complaining that your card is not supported. It's possible you are
1392using a driver version which was released months before your card was
1393introduced.
1394
1395First of all, there is an easy way to make most sound cards work with Linux.
1396Just use the DOS based driver to initialize the card to a known state, then use
1397loadlin.exe to boot Linux. If Linux is configured to use the same I/O, IRQ and
1398DMA numbers as DOS, the card could work.
1399(ctrl-alt-del can be used in place of loadlin.exe but it doesn't work with
1400new motherboards). This method works also with all/most PnP sound cards.
1401
1402Don't get fooled with SB compatibility. Most cards are compatible with
1403SB but that may require a TSR which is not possible with Linux. If
1404the card is compatible with MSS, it's a better choice. Some cards
1405don't work in the SB and MSS modes at the same time.
1406
1407Then there are cards which are no longer manufactured and/or which
1408are relatively rarely used (such as the 8 bit ProAudioSpectrum
1409models). It's extremely unlikely that such cards ever get supported.
1410Adding support for a new card requires much work and increases time
1411required in maintaining the driver (some changes need to be done
1412to all low level drivers and be tested too, maybe with multiple
1413operating systems). For this reason I have made a decision to not support
1414obsolete cards. It's possible that someone else makes a separately
1415distributed driver (diffs) for the card.
1416
1417Writing a driver for a new card is not possible if there are no
1418programming information available about the card. If you don't
1419find your new card from this file, look from the home page
1420(http://www.opensound.com/ossfree). Then please contact
1421manufacturer of the card and ask if they have (or are willing to)
1422released technical details of the card. Do this before contacting me. I
1423can only answer 'no' if there are no programming information available.
1424
1425I have made decision to not accept code based on reverse engineering
1426to the driver. There are three main reasons: First I don't want to break
1427relationships to sound card manufacturers. The second reason is that
1428maintaining and supporting a driver without any specs will be a pain.
1429The third reason is that companies have freedom to refuse selling their
1430products to other than Windows users.
1431
1432Some companies don't give low level technical information about their
1433products to public or at least their require signing a NDA. It's not
1434possible to implement a freeware driver for them. However it's possible
1435that support for such cards become available in the commercial version
1436of this driver (see http://www.4Front-tech.com/oss.html for more info).
1437
1438There are some common audio chipsets that are not supported yet. For example
1439Sierra Aria and IBM Mwave. It's possible that these architectures
1440get some support in future but I can't make any promises. Just look
1441at the home page (http://www.opensound.com/ossfree/)
1442for latest info.
1443
1444Information about unsupported sound cards and chipsets is welcome as well
1445as free copies of sound cards, SDKs and operating systems.
1446
1447If you have any corrections and/or comments, please contact me.
1448
1449Hannu Savolainen
1450hannu@opensound.com
1451
1452home page of OSS/Free: http://www.opensound.com/ossfree
1453
1454home page of commercial OSS
1455(Open Sound System) drivers: http://www.opensound.com/oss.html
diff --git a/Documentation/sound/oss/README.modules b/Documentation/sound/oss/README.modules
deleted file mode 100644
index cdc039421a46..000000000000
--- a/Documentation/sound/oss/README.modules
+++ /dev/null
@@ -1,106 +0,0 @@
1Building a modular sound driver
2================================
3
4 The following information is current as of linux-2.1.85. Check the other
5readme files, especially README.OSS, for information not specific to
6making sound modular.
7
8 First, configure your kernel. This is an idea of what you should be
9setting in the sound section:
10
11<M> Sound card support
12
13<M> 100% Sound Blaster compatibles (SB16/32/64, ESS, Jazz16) support
14
15 I have SoundBlaster. Select your card from the list.
16
17<M> Generic OPL2/OPL3 FM synthesizer support
18<M> FM synthesizer (YM3812/OPL-3) support
19
20 If you don't set these, you will probably find you can play .wav files
21but not .midi. As the help for them says, set them unless you know your
22card does not use one of these chips for FM support.
23
24 Once you are configured, make zlilo, modules, modules_install; reboot.
25Note that it is no longer necessary or possible to configure sound in the
26drivers/sound dir. Now one simply configures and makes one's kernel and
27modules in the usual way.
28
29 Then, add to your /etc/modprobe.d/oss.conf something like:
30
31alias char-major-14-* sb
32install sb /sbin/modprobe -i sb && /sbin/modprobe adlib_card
33options sb io=0x220 irq=7 dma=1 dma16=5 mpu_io=0x330
34options adlib_card io=0x388 # FM synthesizer
35
36 Alternatively, if you have compiled in kernel level ISAPnP support:
37
38alias char-major-14 sb
39softdep sb post: adlib_card
40options adlib_card io=0x388
41
42 The effect of this is that the sound driver and all necessary bits and
43pieces autoload on demand, assuming you use kerneld (a sound choice) and
44autoclean when not in use. Also, options for the device drivers are
45set. They will not work without them. Change as appropriate for your card.
46If you are not yet using the very cool kerneld, you will have to "modprobe
47-k sb" yourself to get things going. Eventually things may be fixed so
48that this kludgery is not necessary; for the time being, it seems to work
49well.
50
51 Replace 'sb' with the driver for your card, and give it the right
52options. To find the filename of the driver, look in
53/lib/modules/<kernel-version>/misc. Mine looks like:
54
55adlib_card.o # This is the generic OPLx driver
56opl3.o # The OPL3 driver
57sb.o # <<The SoundBlaster driver. Yours may differ.>>
58sound.o # The sound driver
59uart401.o # Used by sb, maybe other cards
60
61 Whichever card you have, try feeding it the options that would be the
62default if you were making the driver wired, not as modules. You can
63look at function referred to by module_init() for the card to see what
64args are expected.
65
66 Note that at present there is no way to configure the io, irq and other
67parameters for the modular drivers as one does for the wired drivers.. One
68needs to pass the modules the necessary parameters as arguments, either
69with /etc/modprobe.d/*.conf or with command-line args to modprobe, e.g.
70
71modprobe sb io=0x220 irq=7 dma=1 dma16=5 mpu_io=0x330
72modprobe adlib_card io=0x388
73
74 recommend using /etc/modprobe.d/*.conf.
75
76Persistent DMA Buffers:
77
78The sound modules normally allocate DMA buffers during open() and
79deallocate them during close(). Linux can often have problems allocating
80DMA buffers for ISA cards on machines with more than 16MB RAM. This is
81because ISA DMA buffers must exist below the 16MB boundary and it is quite
82possible that we can't find a large enough free block in this region after
83the machine has been running for any amount of time. The way to avoid this
84problem is to allocate the DMA buffers during module load and deallocate
85them when the module is unloaded. For this to be effective we need to load
86the sound modules right after the kernel boots, either manually or by an
87init script, and keep them around until we shut down. This is a little
88wasteful of RAM, but it guarantees that sound always works.
89
90To make the sound driver use persistent DMA buffers we need to pass the
91sound.o module a "dmabuf=1" command-line argument. This is normally done
92in /etc/modprobe.d/*.conf files like so:
93
94options sound dmabuf=1
95
96If you have 16MB or less RAM or a PCI sound card, this is wasteful and
97unnecessary. It is possible that machine with 16MB or less RAM will find
98this option useful, but if your machine is so memory-starved that it
99cannot find a 64K block free, you will be wasting even more RAM by keeping
100the sound modules loaded and the DMA buffers allocated when they are not
101needed. The proper solution is to upgrade your RAM. But you do also have
102this improper solution as well. Use it wisely.
103
104 I'm afraid I know nothing about anything but my setup, being more of a
105text-mode guy anyway. If you have options for other cards or other helpful
106hints, send them to me, Jim Bray, jb@as220.org, http://as220.org/jb.
diff --git a/Documentation/sound/oss/README.ymfsb b/Documentation/sound/oss/README.ymfsb
deleted file mode 100644
index b6b77906b58d..000000000000
--- a/Documentation/sound/oss/README.ymfsb
+++ /dev/null
@@ -1,107 +0,0 @@
1Legacy audio driver for YMF7xx PCI cards.
2
3
4FIRST OF ALL
5============
6
7 This code references YAMAHA's sample codes and data sheets.
8 I respect and thank for all people they made open the information
9 about YMF7xx cards.
10
11 And this codes heavily based on Jeff Garzik <jgarzik@pobox.com>'s
12 old VIA 82Cxxx driver (via82cxxx.c). I also respect him.
13
14
15DISCLIMER
16=========
17
18 This driver is currently at early ALPHA stage. It may cause serious
19 damage to your computer when used.
20 PLEASE USE IT AT YOUR OWN RISK.
21
22
23ABOUT THIS DRIVER
24=================
25
26 This code enables you to use your YMF724[A-F], YMF740[A-C], YMF744, YMF754
27 cards. When enabled, your card acts as "SoundBlaster Pro" compatible card.
28 It can only play 22.05kHz / 8bit / Stereo samples, control external MIDI
29 port.
30 If you want to use your card as recent "16-bit" card, you should use
31 Alsa or OSS/Linux driver. Of course you can write native PCI driver for
32 your cards :)
33
34
35USAGE
36=====
37
38 # modprobe ymfsb (options)
39
40
41OPTIONS FOR MODULE
42==================
43
44 io : SB base address (0x220, 0x240, 0x260, 0x280)
45 synth_io : OPL3 base address (0x388, 0x398, 0x3a0, 0x3a8)
46 dma : DMA number (0,1,3)
47 master_volume: AC'97 PCM out Vol (0-100)
48 spdif_out : SPDIF-out flag (0:disable 1:enable)
49
50 These options will change in future...
51
52
53FREQUENCY
54=========
55
56 When playing sounds via this driver, you will hear its pitch is slightly
57 lower than original sounds. Since this driver recognizes your card acts
58 with 21.739kHz sample rates rather than 22.050kHz (I think it must be
59 hardware restriction). So many players become tone deafness.
60 To prevent this, you should express some options to your sound player
61 that specify correct sample frequency. For example, to play your MP3 file
62 correctly with mpg123, specify the frequency like following:
63
64 % mpg123 -r 21739 foo.mp3
65
66
67SPDIF OUT
68=========
69
70 With installing modules with option 'spdif_out=1', you can enjoy your
71 sounds from SPDIF-out of your card (if it had).
72 Its Fs is fixed to 48kHz (It never means the sample frequency become
73 up to 48kHz. All sounds via SPDIF-out also 22kHz samples). So your
74 digital-in capable components has to be able to handle 48kHz Fs.
75
76
77COPYING
78=======
79
80 This program is free software; you can redistribute it and/or modify
81 it under the terms of the GNU General Public License as published by
82 the Free Software Foundation; either version 2, or (at your option)
83 any later version.
84
85 This program is distributed in the hope that it will be useful, but
86 WITHOUT ANY WARRANTY; without even the implied warranty of
87 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
88 General Public License for more details.
89
90 You should have received a copy of the GNU General Public License
91 along with this program; if not, write to the Free Software
92 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
93
94
95TODO
96====
97 * support for multiple cards
98 (set the different SB_IO,MPU_IO,OPL_IO for each cards)
99
100 * support for OPL (dmfm) : There will be no requirements... :-<
101
102
103AUTHOR
104======
105
106 Daisuke Nagano <breeze.nagano@nifty.ne.jp>
107
diff --git a/Documentation/sound/oss/SoundPro b/Documentation/sound/oss/SoundPro
deleted file mode 100644
index 9d4db1f29d3c..000000000000
--- a/Documentation/sound/oss/SoundPro
+++ /dev/null
@@ -1,105 +0,0 @@
1Documentation for the SoundPro CMI8330 extensions in the WSS driver (ad1848.o)
2------------------------------------------------------------------------------
3
4( Be sure to read Documentation/sound/oss/CMI8330 too )
5
6Ion Badulescu, ionut@cs.columbia.edu
7February 24, 1999
8
9(derived from the OPL3-SA2 documentation by Scott Murray)
10
11The SoundPro CMI8330 (ISA) is a chip usually found on some Taiwanese
12motherboards. The official name in the documentation is CMI8330, SoundPro
13is the nickname and the big inscription on the chip itself.
14
15The chip emulates a WSS as well as a SB16, but it has certain differences
16in the mixer section which require separate support. It also emulates an
17MPU401 and an OPL3 synthesizer, so you probably want to enable support
18for these, too.
19
20The chip identifies itself as an AD1848, but its mixer is significantly
21more advanced than the original AD1848 one. If your system works with
22either WSS or SB16 and you are having problems with some mixer controls
23(no CD audio, no line-in, etc), you might want to give this driver a try.
24Detection should work, but it hasn't been widely tested, so it might still
25mis-identify the chip. You can still force soundpro=1 in the modprobe
26parameters for ad1848. Please let me know if it happens to you, so I can
27adjust the detection routine.
28
29The chip is capable of doing full-duplex, but since the driver sees it as an
30AD1848, it cannot take advantage of this. Moreover, the full-duplex mode is
31not achievable through the WSS interface, b/c it needs a dma16 line which is
32assigned only to the SB16 subdevice (with isapnp). Windows documentation
33says the user must use WSS Playback and SB16 Recording for full-duplex, so
34it might be possible to do the same thing under Linux. You can try loading
35up both ad1848 and sb then use one for playback and the other for
36recording. I don't know if this works, b/c I haven't tested it. Anyway, if
37you try it, be very careful: the SB16 mixer *mostly* works, but certain
38settings can have unexpected effects. Use the WSS mixer for best results.
39
40There is also a PCI SoundPro chip. I have not seen this chip, so I have
41no idea if the driver will work with it. I suspect it won't.
42
43As with PnP cards, some configuration is required. There are two ways
44of doing this. The most common is to use the isapnptools package to
45initialize the card, and use the kernel module form of the sound
46subsystem and sound drivers. Alternatively, some BIOS's allow manual
47configuration of installed PnP devices in a BIOS menu, which should
48allow using the non-modular sound drivers, i.e. built into the kernel.
49Since in this latter case you cannot use module parameters, you will
50have to enable support for the SoundPro at compile time.
51
52The IRQ and DMA values can be any that are considered acceptable for a
53WSS. Assuming you've got isapnp all happy, then you should be able to
54do something like the following (which *must* match the isapnp/BIOS
55configuration):
56
57modprobe ad1848 io=0x530 irq=11 dma=0 soundpro=1
58-and maybe-
59modprobe sb io=0x220 irq=5 dma=1 dma16=5
60
61-then-
62modprobe mpu401 io=0x330 irq=9
63modprobe opl3 io=0x388
64
65If all goes well and you see no error messages, you should be able to
66start using the sound capabilities of your system. If you get an
67error message while trying to insert the module(s), then make
68sure that the values of the various arguments match what you specified
69in your isapnp configuration file, and that there is no conflict with
70another device for an I/O port or interrupt. Checking the contents of
71/proc/ioports and /proc/interrupts can be useful to see if you're
72butting heads with another device.
73
74If you do not see the chipset version message, and none of the other
75messages present in the system log are helpful, try adding 'debug=1'
76to the ad1848 parameters, email me the syslog results and I'll do
77my best to help.
78
79Lastly, if you're using modules and want to set up automatic module
80loading with kmod, the kernel module loader, here is the section I
81currently use in my conf.modules file:
82
83# Sound
84post-install sound modprobe -k ad1848; modprobe -k mpu401; modprobe -k opl3
85options ad1848 io=0x530 irq=11 dma=0
86options sb io=0x220 irq=5 dma=1 dma16=5
87options mpu401 io=0x330 irq=9
88options opl3 io=0x388
89
90The above ensures that ad1848 will be loaded whenever the sound system
91is being used.
92
93Good luck.
94
95Ion
96
97NOT REALLY TESTED:
98- recording
99- recording device selection
100- full-duplex
101
102TODO:
103- implement mixer support for surround, loud, digital CD switches.
104- come up with a scheme which allows recording volumes for each subdevice.
105This is a major OSS API change.
diff --git a/Documentation/sound/oss/Soundblaster b/Documentation/sound/oss/Soundblaster
deleted file mode 100644
index b288d464ba8b..000000000000
--- a/Documentation/sound/oss/Soundblaster
+++ /dev/null
@@ -1,53 +0,0 @@
1modprobe sound
2insmod uart401
3insmod sb ...
4
5This loads the driver for the Sound Blaster and assorted clones. Cards that
6are covered by other drivers should not be using this driver.
7
8The Sound Blaster module takes the following arguments
9
10io I/O address of the Sound Blaster chip (0x220,0x240,0x260,0x280)
11irq IRQ of the Sound Blaster chip (5,7,9,10)
12dma 8-bit DMA channel for the Sound Blaster (0,1,3)
13dma16 16-bit DMA channel for SB16 and equivalent cards (5,6,7)
14mpu_io I/O for MPU chip if present (0x300,0x330)
15
16sm_games=1 Set if you have a Logitech soundman games
17acer=1 Set this to detect cards in some ACER notebooks
18mwave_bug=1 Set if you are trying to use this driver with mwave (see on)
19type Use this to specify a specific card type
20
21The following arguments are taken if ISAPnP support is compiled in
22
23isapnp=0 Set this to disable ISAPnP detection (use io=0xXXX etc. above)
24multiple=0 Set to disable detection of multiple Soundblaster cards.
25 Consider it a bug if this option is needed, and send in a
26 report.
27pnplegacy=1 Set this to be able to use a PnP card(s) along with a single
28 non-PnP (legacy) card. Above options for io, irq, etc. are
29 needed, and will apply only to the legacy card.
30reverse=1 Reverses the order of the search in the PnP table.
31uart401=1 Set to enable detection of mpu devices on some clones.
32isapnpjump=n Jumps to slot n in the driver's PnP table. Use the source,
33 Luke.
34
35You may well want to load the opl3 driver for synth music on most SB and
36clone SB devices
37
38insmod opl3 io=0x388
39
40Using Mwave
41
42To make this driver work with Mwave you must set mwave_bug. You also need
43to warm boot from DOS/Windows with the required firmware loaded under this
44OS. IBM are being difficult about documenting how to load this firmware.
45
46Avance Logic ALS007
47
48This card is supported; see the separate file ALS007 for full details.
49
50Avance Logic ALS100
51
52This card is supported; setup should be as for a standard Sound Blaster 16.
53The driver will identify the audio device as a "Sound Blaster 16 (ALS-100)".
diff --git a/Documentation/sound/oss/Tropez+ b/Documentation/sound/oss/Tropez+
deleted file mode 100644
index b93a6b734fc0..000000000000
--- a/Documentation/sound/oss/Tropez+
+++ /dev/null
@@ -1,26 +0,0 @@
1From: Paul Barton-Davis <pbd@op.net>
2
3Here is the configuration I use with a Tropez+ and my modular
4driver:
5
6 alias char-major-14 wavefront
7 alias synth0 wavefront
8 alias mixer0 cs4232
9 alias audio0 cs4232
10 pre-install wavefront modprobe "-k" "cs4232"
11 post-install wavefront modprobe "-k" "opl3"
12 options wavefront io=0x200 irq=9
13 options cs4232 synthirq=9 synthio=0x200 io=0x530 irq=5 dma=1 dma2=0
14 options opl3 io=0x388
15
16Things to note:
17
18 the wavefront options "io" and "irq" ***MUST*** match the "synthio"
19 and "synthirq" cs4232 options.
20
21 you can do without the opl3 module if you don't
22 want to use the OPL/[34] synth on the soundcard
23
24 the opl3 io parameter is conventionally not adjustable.
25
26Please see drivers/sound/README.wavefront for more details.
diff --git a/Documentation/sound/oss/VIBRA16 b/Documentation/sound/oss/VIBRA16
deleted file mode 100644
index 68a5a46beb88..000000000000
--- a/Documentation/sound/oss/VIBRA16
+++ /dev/null
@@ -1,80 +0,0 @@
1Sound Blaster 16X Vibra addendum
2--------------------------------
3by Marius Ilioaea <mariusi@protv.ro>
4 Stefan Laudat <stefan@asit.ro>
5
6Sat Mar 6 23:55:27 EET 1999
7
8 Hello again,
9
10 Playing with a SB Vibra 16x soundcard we found it very difficult
11to setup because the kernel reported a lot of DMA errors and wouldn't
12simply play any sound.
13 A good starting point is that the vibra16x chip full-duplex facility
14is neither still exploited by the sb driver found in the linux kernel
15(tried it with a 2.2.2-ac7), nor in the commercial OSS package (it reports
16it as half-duplex soundcard). Oh, I almost forgot, the RedHat sndconfig
17failed detecting it ;)
18 So, the big problem still remains, because the sb module wants a
198-bit and a 16-bit dma, which we could not allocate for vibra... it supports
20only two 8-bit dma channels, the second one will be passed to the module
21as a 16 bit channel, the kernel will yield about that but everything will
22be okay, trust us.
23 The only inconvenient you may find is that you will have
24some sound playing jitters if you have HDD dma support enabled - but this
25will happen with almost all soundcards...
26
27 A fully working isapnp.conf is just here:
28
29<snip here>
30
31(READPORT 0x0203)
32(ISOLATE PRESERVE)
33(IDENTIFY *)
34(VERBOSITY 2)
35(CONFLICT (IO FATAL)(IRQ FATAL)(DMA FATAL)(MEM FATAL)) # or WARNING
36# SB 16 and OPL3 devices
37(CONFIGURE CTL00f0/-1 (LD 0
38(INT 0 (IRQ 5 (MODE +E)))
39(DMA 0 (CHANNEL 1))
40(DMA 1 (CHANNEL 3))
41(IO 0 (SIZE 16) (BASE 0x0220))
42(IO 2 (SIZE 4) (BASE 0x0388))
43(NAME "CTL00f0/-1[0]{Audio }")
44(ACT Y)
45))
46
47# Joystick device - only if you need it :-/
48
49(CONFIGURE CTL00f0/-1 (LD 1
50(IO 0 (SIZE 1) (BASE 0x0200))
51(NAME "CTL00f0/-1[1]{Game }")
52(ACT Y)
53))
54(WAITFORKEY)
55
56<end of snipping>
57
58 So, after a good kernel modules compilation and a 'depmod -a kernel_ver'
59you may want to:
60
61modprobe sb io=0x220 irq=5 dma=1 dma16=3
62
63 Or, take the hard way:
64
65modprobe soundcore
66modprobe sound
67modprobe uart401
68modprobe sb io=0x220 irq=5 dma=1 dma16=3
69# do you need MIDI?
70modprobe opl3=0x388
71
72 Just in case, the kernel sound support should be:
73
74CONFIG_SOUND=m
75CONFIG_SOUND_OSS=m
76CONFIG_SOUND_SB=m
77
78 Enjoy your new noisy Linux box! ;)
79
80
diff --git a/Documentation/sound/oss/WaveArtist b/Documentation/sound/oss/WaveArtist
deleted file mode 100644
index f4f3407cd818..000000000000
--- a/Documentation/sound/oss/WaveArtist
+++ /dev/null
@@ -1,170 +0,0 @@
1
2 (the following is from the armlinux CVS)
3
4 WaveArtist mixer and volume levels can be accessed via these commands:
5
6 nn30 read registers nn, where nn = 00 - 09 for mixer settings
7 0a - 13 for channel volumes
8 mm31 write the volume setting in pairs, where mm = (nn - 10) / 2
9 rr32 write the mixer settings in pairs, where rr = nn/2
10 xx33 reset all settings to default
11 0y34 select mono source, y=0 = left, y=1 = right
12
13 bits
14 nn 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
15----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
16 00 | 0 | 0 0 1 1 | left line mixer gain | left aux1 mixer gain |lmute|
17----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
18 01 | 0 | 0 1 0 1 | left aux2 mixer gain | right 2 left mic gain |mmute|
19----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
20 02 | 0 | 0 1 1 1 | left mic mixer gain | left mic | left mixer gain |dith |
21----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
22 03 | 0 | 1 0 0 1 | left mixer input select |lrfg | left ADC gain |
23----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
24 04 | 0 | 1 0 1 1 | right line mixer gain | right aux1 mixer gain |rmute|
25----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
26 05 | 0 | 1 1 0 1 | right aux2 mixer gain | left 2 right mic gain |test |
27----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
28 06 | 0 | 1 1 1 1 | right mic mixer gain | right mic |right mixer gain |rbyps|
29----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
30 07 | 1 | 0 0 0 1 | right mixer select |rrfg | right ADC gain |
31----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
32 08 | 1 | 0 0 1 1 | mono mixer gain |right ADC mux sel|left ADC mux sel |
33----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
34 09 | 1 | 0 1 0 1 |loopb|left linout|loop|ADCch|TxFch|OffCD|test |loopb|loopb|osamp|
35----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
36 0a | 0 | left PCM channel volume |
37----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
38 0b | 0 | right PCM channel volume |
39----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
40 0c | 0 | left FM channel volume |
41----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
42 0d | 0 | right FM channel volume |
43----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
44 0e | 0 | left wavetable channel volume |
45----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
46 0f | 0 | right wavetable channel volume |
47----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
48 10 | 0 | left PCM expansion channel volume |
49----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
50 11 | 0 | right PCM expansion channel volume |
51----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
52 12 | 0 | left FM expansion channel volume |
53----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
54 13 | 0 | right FM expansion channel volume |
55----+---+------------+-----+-----+-----+----+-----+-----+-----+-----+-----+-----+-----+
56
57 lmute: left mute
58 mmute: mono mute
59 dith: dithds
60 lrfg:
61 rmute: right mute
62 rbyps: right bypass
63 rrfg:
64 ADCch:
65 TxFch:
66 OffCD:
67 osamp:
68
69 And the following diagram is derived from the description in the CVS archive:
70
71 MIC L (mouthpiece)
72 +------+
73 -->PreAmp>-\
74 +--^---+ |
75 | |
76 r2b4-5 | +--------+
77 /----*-------------------------------->5 |
78 | | |
79 | /----------------------------------->4 |
80 | | | |
81 | | /--------------------------------->3 1of5 | +---+
82 | | | | mux >-->AMP>--> ADC L
83 | | | /------------------------------->2 | +-^-+
84 | | | | | | |
85 Line | | | | +----+ +------+ +---+ /---->1 | r3b3-0
86 ------------*->mute>--> Gain >--> | | | |
87 L | | | +----+ +------+ | | | *->0 |
88 | | | | | | +---^----+
89 Aux2 | | | +----+ +------+ | | | |
90 ----------*--->mute>--> Gain >--> M | | r8b0-2
91 L | | +----+ +------+ | | |
92 | | | | \------\
93 Aux1 | | +----+ +------+ | | |
94 --------*----->mute>--> Gain >--> I | |
95 L | +----+ +------+ | | |
96 | | | |
97 | +----+ +------+ | | +---+ |
98 *------->mute>--> Gain >--> X >-->AMP>--*
99 | +----+ +------+ | | +-^-+ |
100 | | | | |
101 | +----+ +------+ | | r2b1-3 |
102 | /----->mute>--> Gain >--> E | |
103 | | +----+ +------+ | | |
104 | | | | |
105 | | +----+ +------+ | | |
106 | | /--->mute>--> Gain >--> R | |
107 | | | +----+ +------+ | | |
108 | | | | | | r9b8-9
109 | | | +----+ +------+ | | | |
110 | | | /->mute>--> Gain >--> | | +---v---+
111 | | | | +----+ +------+ +---+ /-*->0 |
112 DAC | | | | | | |
113 ------------*----------------------------------->? | +----+
114 L | | | | | Mux >-->mute>--> L output
115 | | | | /->? | +--^-+
116 | | | | | | | |
117 | | | /--------->? | r0b0
118 | | | | | | +-------+
119 | | | | | |
120 Mono | | | | | | +-------+
121 ----------* | \---> | +----+
122 | | | | | | Mix >-->mute>--> Mono output
123 | | | | *-> | +--^-+
124 | | | | | +-------+ |
125 | | | | | r1b0
126 DAC | | | | | +-------+
127 ------------*-------------------------*--------->1 | +----+
128 R | | | | | | Mux >-->mute>--> R output
129 | | | | +----+ +------+ +---+ *->0 | +--^-+
130 | | | \->mute>--> Gain >--> | | +---^---+ |
131 | | | +----+ +------+ | | | | r5b0
132 | | | | | | r6b0
133 | | | +----+ +------+ | | |
134 | | \--->mute>--> Gain >--> M | |
135 | | +----+ +------+ | | |
136 | | | | |
137 | | +----+ +------+ | | |
138 | *----->mute>--> Gain >--> I | |
139 | | +----+ +------+ | | |
140 | | | | |
141 | | +----+ +------+ | | +---+ |
142 \------->mute>--> Gain >--> X >-->AMP>--*
143 | +----+ +------+ | | +-^-+ |
144 /--/ | | | |
145 Aux1 | +----+ +------+ | | r6b1-3 |
146 -------*------>mute>--> Gain >--> E | |
147 R | | +----+ +------+ | | |
148 | | | | |
149 Aux2 | | +----+ +------+ | | /------/
150 ---------*---->mute>--> Gain >--> R | |
151 R | | | +----+ +------+ | | |
152 | | | | | | +--------+
153 Line | | | +----+ +------+ | | | *->0 |
154 -----------*-->mute>--> Gain >--> | | | |
155 R | | | | +----+ +------+ +---+ \---->1 |
156 | | | | | |
157 | | | \-------------------------------->2 | +---+
158 | | | | Mux >-->AMP>--> ADC R
159 | | \---------------------------------->3 | +-^-+
160 | | | | |
161 | \------------------------------------>4 | r7b3-0
162 | | |
163 \-----*-------------------------------->5 |
164 | +---^----+
165 r6b4-5 | |
166 | | r8b3-5
167 +--v---+ |
168 -->PreAmp>-/
169 +------+
170 MIC R (electret mic)
diff --git a/Documentation/sound/oss/btaudio b/Documentation/sound/oss/btaudio
deleted file mode 100644
index effdb9a3f898..000000000000
--- a/Documentation/sound/oss/btaudio
+++ /dev/null
@@ -1,92 +0,0 @@
1
2Intro
3=====
4
5people start bugging me about this with questions, looks like I
6should write up some documentation for this beast. That way I
7don't have to answer that much mails I hope. Yes, I'm lazy...
8
9
10You might have noticed that the bt878 grabber cards have actually
11_two_ PCI functions:
12
13$ lspci
14[ ... ]
1500:0a.0 Multimedia video controller: Brooktree Corporation Bt878 (rev 02)
1600:0a.1 Multimedia controller: Brooktree Corporation Bt878 (rev 02)
17[ ... ]
18
19The first does video, it is backward compatible to the bt848. The second
20does audio. btaudio is a driver for the second function. It's a sound
21driver which can be used for recording sound (and _only_ recording, no
22playback). As most TV cards come with a short cable which can be plugged
23into your sound card's line-in you probably don't need this driver if all
24you want to do is just watching TV...
25
26
27Driver Status
28=============
29
30Still somewhat experimental. The driver should work stable, i.e. it
31should'nt crash your box. It might not work as expected, have bugs,
32not being fully OSS API compliant, ...
33
34Latest versions are available from http://bytesex.org/bttv/, the
35driver is in the bttv tarball. Kernel patches might be available too,
36have a look at http://bytesex.org/bttv/listing.html.
37
38The chip knows two different modes. btaudio registers two dsp
39devices, one for each mode. They can not be used at the same time.
40
41
42Digital audio mode
43==================
44
45The chip gives you 16 bit stereo sound. The sample rate depends on
46the external source which feeds the bt878 with digital sound via I2S
47interface. There is a insmod option (rate) to tell the driver which
48sample rate the hardware uses (32000 is the default).
49
50One possible source for digital sound is the msp34xx audio processor
51chip which provides digital sound via I2S with 32 kHz sample rate. My
52Hauppauge board works this way.
53
54The Osprey-200 reportly gives you digital sound with 44100 Hz sample
55rate. It is also possible that you get no sound at all.
56
57
58analog mode (A/D)
59=================
60
61You can tell the driver to use this mode with the insmod option "analog=1".
62The chip has three analog inputs. Consequently you'll get a mixer device
63to control these.
64
65The analog mode supports mono only. Both 8 + 16 bit. Both are _signed_
66int, which is uncommon for the 8 bit case. Sample rate range is 119 kHz
67to 448 kHz. Yes, the number of digits is correct. The driver supports
68downsampling by powers of two, so you can ask for more usual sample rates
69like 44 kHz too.
70
71With my Hauppauge I get noisy sound on the second input (mapped to line2
72by the mixer device). Others get a useable signal on line1.
73
74
75some examples
76=============
77
78* read audio data from btaudio (dsp2), send to es1730 (dsp,dsp1):
79 $ sox -w -r 32000 -t ossdsp /dev/dsp2 -t ossdsp /dev/dsp
80
81* read audio data from btaudio, send to esound daemon (which might be
82 running on another host):
83 $ sox -c 2 -w -r 32000 -t ossdsp /dev/dsp2 -t sw - | esdcat -r 32000
84 $ sox -c 1 -w -r 32000 -t ossdsp /dev/dsp2 -t sw - | esdcat -m -r 32000
85
86
87Have fun,
88
89 Gerd
90
91--
92Gerd Knorr <kraxel@bytesex.org>
diff --git a/Documentation/sound/oss/mwave b/Documentation/sound/oss/mwave
deleted file mode 100644
index 5fbcb1609275..000000000000
--- a/Documentation/sound/oss/mwave
+++ /dev/null
@@ -1,185 +0,0 @@
1 How to try to survive an IBM Mwave under Linux SB drivers
2
3
4+ IBM have now released documentation of sorts and Torsten is busy
5 trying to make the Mwave work. This is not however a trivial task.
6
7----------------------------------------------------------------------------
8
9OK, first thing - the IRQ problem IS a problem, whether the test is bypassed or
10not. It is NOT a Linux problem, but an MWAVE problem that is fixed with the
11latest MWAVE patches. So, in other words, don't bypass the test for MWAVES!
12
13I have Windows 95 on /dev/hda1, swap on /dev/hda2, and Red Hat 5 on /dev/hda3.
14
15The steps, then:
16
17 Boot to Linux.
18 Mount Windows 95 file system (assume mount point = /dos95).
19 mkdir /dos95/linux
20 mkdir /dos95/linux/boot
21 mkdir /dos95/linux/boot/parms
22
23 Copy the kernel, any initrd image, and loadlin to /dos95/linux/boot/.
24
25 Reboot to Windows 95.
26
27 Edit C:/msdos.sys and add or change the following:
28
29 Logo=0
30 BootGUI=0
31
32 Note that msdos.sys is a text file but it needs to be made 'unhidden',
33 readable and writable before it can be edited. This can be done with
34 DOS' "attrib" command.
35
36 Edit config.sys to have multiple config menus. I have one for windows 95 and
37 five for Linux, like this:
38------------
39[menu]
40menuitem=W95, Windows 95
41menuitem=LINTP, Linux - ThinkPad
42menuitem=LINTP3, Linux - ThinkPad Console
43menuitem=LINDOC, Linux - Docked
44menuitem=LINDOC3, Linux - Docked Console
45menuitem=LIN1, Linux - Single User Mode
46REM menudefault=W95,10
47
48[W95]
49
50[LINTP]
51
52[LINDOC]
53
54[LINTP3]
55
56[LINDOC3]
57
58[LIN1]
59
60[COMMON]
61FILES=30
62REM Please read README.TXT in C:\MWW subdirectory before changing the DOS= statement.
63DOS=HIGH,UMB
64DEVICE=C:\MWW\MANAGER\MWD50430.EXE
65SHELL=c:\command.com /e:2048
66-------------------
67
68The important things are the SHELL and DEVICE statements.
69
70 Then change autoexec.bat. Basically everything in there originally should be
71 done ONLY when Windows 95 is booted. Then you add new things specifically
72 for Linux. Mine is as follows
73
74---------------
75@ECHO OFF
76if "%CONFIG%" == "W95" goto W95
77
78REM
79REM Linux stuff
80REM
81SET MWPATH=C:\MWW\DLL;C:\MWW\MWGAMES;C:\MWW\DSP
82SET BLASTER=A220 I5 D1
83SET MWROOT=C:\MWW
84SET LIBPATH=C:\MWW\DLL
85SET PATH=C:\WINDOWS;C:\MWW\DLL;
86CALL MWAVE START NOSHOW
87c:\linux\boot\loadlin.exe @c:\linux\boot\parms\%CONFIG%.par
88
89:W95
90REM
91REM Windows 95 stuff
92REM
93c:\toolkit\guard
94SET MSINPUT=C:\MSINPUT
95SET MWPATH=C:\MWW\DLL;C:\MWW\MWGAMES;C:\MWW\DSP
96REM The following is used by DOS games to recognize Sound Blaster hardware.
97REM If hardware settings are changed, please change this line as well.
98REM See the Mwave README file for instructions.
99SET BLASTER=A220 I5 D1
100SET MWROOT=C:\MWW
101SET LIBPATH=C:\MWW\DLL
102SET PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;E:\ORAWIN95\BIN;f:\msdev\bin;e:\v30\bin.dbg;v:\devt\v30\bin;c:\JavaSDK\Bin;C:\MWW\DLL;
103SET INCLUDE=f:\MSDEV\INCLUDE;F:\MSDEV\MFC\INCLUDE
104SET LIB=F:\MSDEV\LIB;F:\MSDEV\MFC\LIB
105win
106
107------------------------
108
109Now build a file in c:\linux\boot\parms for each Linux config that you have.
110
111For example, my LINDOC3 config is for a docked Thinkpad at runlevel 3 with no
112initrd image, and has a parameter file named LINDOC3.PAR in c:\linux\boot\parms:
113
114-----------------------
115# LOADLIN @param_file image=other_image root=/dev/other
116#
117# Linux Console in docking station
118#
119c:\linux\boot\zImage.krn # First value must be filename of Linux kernel.
120root=/dev/hda3 # device which gets mounted as root FS
121ro # Other kernel arguments go here.
122apm=off
123doc=yes
1243
125-----------------------
126
127The doc=yes parameter is an environment variable used by my init scripts, not
128a kernel argument.
129
130However, the apm=off parameter IS a kernel argument! APM, at least in my setup,
131causes the kernel to crash when loaded via loadlin (but NOT when loaded via
132LILO). The APM stuff COULD be forced out of the kernel via the kernel compile
133options. Instead, I got an unofficial patch to the APM drivers that allows them
134to be dynamically deactivated via kernel arguments. Whatever you chose to
135document, APM, it seems, MUST be off for setups like mine.
136
137Now make sure C:\MWW\MWCONFIG.REF looks like this:
138
139----------------------
140[NativeDOS]
141Default=SB1.5
142SBInputSource=CD
143SYNTH=FM
144QSound=OFF
145Reverb=OFF
146Chorus=OFF
147ReverbDepth=5
148ChorusDepth=5
149SBInputVolume=5
150SBMainVolume=10
151SBWaveVolume=10
152SBSynthVolume=10
153WaveTableVolume=10
154AudioPowerDriver=ON
155
156[FastCFG]
157Show=No
158HideOption=Off
159-----------------------------
160
161OR the Default= line COULD be
162
163Default=SBPRO
164
165Reboot to Windows 95 and choose Linux. When booted, use sndconfig to configure
166the sound modules and voilà - ThinkPad sound with Linux.
167
168Now the gotchas - you can either have CD sound OR Mixers but not both. That's a
169problem with the SB1.5 (CD sound) or SBPRO (Mixers) settings. No one knows why
170this is!
171
172For some reason MPEG3 files, when played through mpg123, sound like they
173are playing at 1/8th speed - not very useful! If you have ANY insight
174on why this second thing might be happening, I would be grateful.
175
176===========================================================
177 _/ _/_/_/_/
178 _/_/ _/_/ _/
179 _/ _/_/ _/_/_/_/ Martin John Bartlett
180 _/ _/ _/ _/ (martin@nitram.demon.co.uk)
181_/ _/_/_/_/
182 _/
183_/ _/
184 _/_/
185===========================================================
diff --git a/Documentation/sound/oss/oss-parameters.txt b/Documentation/sound/oss/oss-parameters.txt
deleted file mode 100644
index cc675f25eee4..000000000000
--- a/Documentation/sound/oss/oss-parameters.txt
+++ /dev/null
@@ -1,51 +0,0 @@
1 OSS Kernel Parameters
2 ~~~~~~~~~~~~~~~~~~~~~
3
4See Documentation/admin-guide/kernel-parameters.rst for general information on
5specifying module parameters.
6
7This document may not be entirely up to date and comprehensive. The command
8"modinfo -p ${modulename}" shows a current list of all parameters of a loadable
9module. Loadable modules, after being loaded into the running kernel, also
10reveal their parameters in /sys/module/${modulename}/parameters/. Some of these
11parameters may be changed at runtime by the command
12"echo -n ${value} > /sys/module/${modulename}/parameters/${parm}".
13
14
15 ad1848= [HW,OSS]
16 Format: <io>,<irq>,<dma>,<dma2>,<type>
17
18 aedsp16= [HW,OSS] Audio Excel DSP 16
19 Format: <io>,<irq>,<dma>,<mss_io>,<mpu_io>,<mpu_irq>
20 See also header of sound/oss/aedsp16.c.
21
22 dmasound= [HW,OSS] Sound subsystem buffers
23
24 mpu401= [HW,OSS]
25 Format: <io>,<irq>
26
27 opl3= [HW,OSS]
28 Format: <io>
29
30 pas2= [HW,OSS] Format:
31 <io>,<irq>,<dma>,<dma16>,<sb_io>,<sb_irq>,<sb_dma>,<sb_dma16>
32
33 pss= [HW,OSS] Personal Sound System (ECHO ESC614)
34 Format:
35 <io>,<mss_io>,<mss_irq>,<mss_dma>,<mpu_io>,<mpu_irq>
36
37 sscape= [HW,OSS]
38 Format: <io>,<irq>,<dma>,<mpu_io>,<mpu_irq>
39
40 trix= [HW,OSS] MediaTrix AudioTrix Pro
41 Format:
42 <io>,<irq>,<dma>,<dma2>,<sb_io>,<sb_irq>,<sb_dma>,<mpu_io>,<mpu_irq>
43
44 uart401= [HW,OSS]
45 Format: <io>,<irq>
46
47 uart6850= [HW,OSS]
48 Format: <io>,<irq>
49
50 waveartist= [HW,OSS]
51 Format: <io>,<irq>,<dma>,<dma2>
diff --git a/Documentation/sound/oss/ultrasound b/Documentation/sound/oss/ultrasound
deleted file mode 100644
index eed331c738a3..000000000000
--- a/Documentation/sound/oss/ultrasound
+++ /dev/null
@@ -1,30 +0,0 @@
1modprobe sound
2insmod ad1848
3insmod gus io=* irq=* dma=* ...
4
5This loads the driver for the Gravis Ultrasound family of sound cards.
6
7The gus module takes the following arguments
8
9io I/O address of the Ultrasound card (eg. io=0x220)
10irq IRQ of the Sound Blaster card
11dma DMA channel for the Sound Blaster
12dma16 2nd DMA channel, only needed for full duplex operation
13type 1 for PnP card
14gus16 1 for using 16 bit sampling daughter board
15no_wave_dma Set to disable DMA usage for wavetable (see note)
16db16 ???
17
18
19no_wave_dma option
20
21This option defaults to a value of 0, which allows the Ultrasound wavetable
22DSP to use DMA for playback and downloading samples. This is the same
23as the old behaviour. If set to 1, no DMA is needed for downloading samples,
24and allows owners of a GUS MAX to make use of simultaneous digital audio
25(/dev/dsp), MIDI, and wavetable playback.
26
27
28If you have problems in recording with GUS MAX, you could try to use
29just one 8 bit DMA channel. Recording will not work with one DMA
30channel if it's a 16 bit one.
diff --git a/MAINTAINERS b/MAINTAINERS
index a76f02f64469..fbebd08ae42e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -527,11 +527,6 @@ W: http://ez.analog.com/community/linux-device-drivers
527S: Supported 527S: Supported
528F: drivers/input/misc/adxl34x.c 528F: drivers/input/misc/adxl34x.c
529 529
530AEDSP16 DRIVER
531M: Riccardo Facchetti <fizban@tin.it>
532S: Maintained
533F: sound/oss/aedsp16.c
534
535AF9013 MEDIA DRIVER 530AF9013 MEDIA DRIVER
536M: Antti Palosaari <crope@iki.fi> 531M: Antti Palosaari <crope@iki.fi>
537L: linux-media@vger.kernel.org 532L: linux-media@vger.kernel.org
@@ -9222,12 +9217,6 @@ F: include/linux/dt-bindings/mux/
9222F: include/linux/mux/ 9217F: include/linux/mux/
9223F: drivers/mux/ 9218F: drivers/mux/
9224 9219
9225MULTISOUND SOUND DRIVER
9226M: Andrew Veliath <andrewtv@usa.net>
9227S: Maintained
9228F: Documentation/sound/oss/MultiSound
9229F: sound/oss/msnd*
9230
9231MULTITECH MULTIPORT CARD (ISICOM) 9220MULTITECH MULTIPORT CARD (ISICOM)
9232S: Orphan 9221S: Orphan
9233F: drivers/tty/isicom.c 9222F: drivers/tty/isicom.c
@@ -14638,6 +14627,7 @@ F: Documentation/devicetree/bindings/extcon/extcon-arizona.txt
14638F: Documentation/devicetree/bindings/regulator/arizona-regulator.txt 14627F: Documentation/devicetree/bindings/regulator/arizona-regulator.txt
14639F: Documentation/devicetree/bindings/mfd/arizona.txt 14628F: Documentation/devicetree/bindings/mfd/arizona.txt
14640F: Documentation/devicetree/bindings/mfd/wm831x.txt 14629F: Documentation/devicetree/bindings/mfd/wm831x.txt
14630F: Documentation/devicetree/bindings/sound/wlf,arizona.txt
14641F: arch/arm/mach-s3c64xx/mach-crag6410* 14631F: arch/arm/mach-s3c64xx/mach-crag6410*
14642F: drivers/clk/clk-wm83*.c 14632F: drivers/clk/clk-wm83*.c
14643F: drivers/extcon/extcon-arizona.c 14633F: drivers/extcon/extcon-arizona.c
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
index a52795d9b458..ebca22302ebb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
@@ -371,6 +371,8 @@ static int acp_hw_init(void *handle)
371 adev->acp.acp_cell[0].name = "acp_audio_dma"; 371 adev->acp.acp_cell[0].name = "acp_audio_dma";
372 adev->acp.acp_cell[0].num_resources = 4; 372 adev->acp.acp_cell[0].num_resources = 4;
373 adev->acp.acp_cell[0].resources = &adev->acp.acp_res[0]; 373 adev->acp.acp_cell[0].resources = &adev->acp.acp_res[0];
374 adev->acp.acp_cell[0].platform_data = &adev->asic_type;
375 adev->acp.acp_cell[0].pdata_size = sizeof(adev->asic_type);
374 376
375 adev->acp.acp_cell[1].name = "designware-i2s"; 377 adev->acp.acp_cell[1].name = "designware-i2s";
376 adev->acp.acp_cell[1].num_resources = 1; 378 adev->acp.acp_cell[1].num_resources = 1;
diff --git a/drivers/gpu/drm/amd/include/amd_shared.h b/drivers/gpu/drm/amd/include/amd_shared.h
index 70e8c20acb2f..3a49fbd8baf8 100644
--- a/drivers/gpu/drm/amd/include/amd_shared.h
+++ b/drivers/gpu/drm/amd/include/amd_shared.h
@@ -23,34 +23,9 @@
23#ifndef __AMD_SHARED_H__ 23#ifndef __AMD_SHARED_H__
24#define __AMD_SHARED_H__ 24#define __AMD_SHARED_H__
25 25
26#define AMD_MAX_USEC_TIMEOUT 200000 /* 200 ms */ 26#include <drm/amd_asic_type.h>
27 27
28/* 28#define AMD_MAX_USEC_TIMEOUT 200000 /* 200 ms */
29 * Supported ASIC types
30 */
31enum amd_asic_type {
32 CHIP_TAHITI = 0,
33 CHIP_PITCAIRN,
34 CHIP_VERDE,
35 CHIP_OLAND,
36 CHIP_HAINAN,
37 CHIP_BONAIRE,
38 CHIP_KAVERI,
39 CHIP_KABINI,
40 CHIP_HAWAII,
41 CHIP_MULLINS,
42 CHIP_TOPAZ,
43 CHIP_TONGA,
44 CHIP_FIJI,
45 CHIP_CARRIZO,
46 CHIP_STONEY,
47 CHIP_POLARIS10,
48 CHIP_POLARIS11,
49 CHIP_POLARIS12,
50 CHIP_VEGA10,
51 CHIP_RAVEN,
52 CHIP_LAST,
53};
54 29
55/* 30/*
56 * Chip flags 31 * Chip flags
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 64b30fe273fd..176b1a74b2b7 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -727,7 +727,7 @@ config TOUCHSCREEN_WM831X
727 727
728config TOUCHSCREEN_WM97XX 728config TOUCHSCREEN_WM97XX
729 tristate "Support for WM97xx AC97 touchscreen controllers" 729 tristate "Support for WM97xx AC97 touchscreen controllers"
730 depends on AC97_BUS 730 depends on AC97_BUS || AC97_BUS_NEW
731 help 731 help
732 Say Y here if you have a Wolfson Microelectronics WM97xx 732 Say Y here if you have a Wolfson Microelectronics WM97xx
733 touchscreen connected to your system. Note that this option 733 touchscreen connected to your system. Note that this option
diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c
index c9d1c91e1887..fd714ee881f7 100644
--- a/drivers/input/touchscreen/wm97xx-core.c
+++ b/drivers/input/touchscreen/wm97xx-core.c
@@ -44,6 +44,7 @@
44#include <linux/pm.h> 44#include <linux/pm.h>
45#include <linux/interrupt.h> 45#include <linux/interrupt.h>
46#include <linux/bitops.h> 46#include <linux/bitops.h>
47#include <linux/mfd/wm97xx.h>
47#include <linux/workqueue.h> 48#include <linux/workqueue.h>
48#include <linux/wm97xx.h> 49#include <linux/wm97xx.h>
49#include <linux/uaccess.h> 50#include <linux/uaccess.h>
@@ -581,27 +582,85 @@ static void wm97xx_ts_input_close(struct input_dev *idev)
581 wm->codec->acc_enable(wm, 0); 582 wm->codec->acc_enable(wm, 0);
582} 583}
583 584
584static int wm97xx_probe(struct device *dev) 585static int wm97xx_register_touch(struct wm97xx *wm)
585{ 586{
586 struct wm97xx *wm; 587 struct wm97xx_pdata *pdata = dev_get_platdata(wm->dev);
587 struct wm97xx_pdata *pdata = dev_get_platdata(dev); 588 int ret;
588 int ret = 0, id = 0;
589 589
590 wm = kzalloc(sizeof(struct wm97xx), GFP_KERNEL); 590 wm->input_dev = devm_input_allocate_device(wm->dev);
591 if (!wm) 591 if (wm->input_dev == NULL)
592 return -ENOMEM; 592 return -ENOMEM;
593 mutex_init(&wm->codec_mutex);
594 593
595 wm->dev = dev; 594 /* set up touch configuration */
596 dev_set_drvdata(dev, wm); 595 wm->input_dev->name = "wm97xx touchscreen";
597 wm->ac97 = to_ac97_t(dev); 596 wm->input_dev->phys = "wm97xx";
597 wm->input_dev->open = wm97xx_ts_input_open;
598 wm->input_dev->close = wm97xx_ts_input_close;
599
600 __set_bit(EV_ABS, wm->input_dev->evbit);
601 __set_bit(EV_KEY, wm->input_dev->evbit);
602 __set_bit(BTN_TOUCH, wm->input_dev->keybit);
603
604 input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1],
605 abs_x[2], 0);
606 input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1],
607 abs_y[2], 0);
608 input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1],
609 abs_p[2], 0);
610
611 input_set_drvdata(wm->input_dev, wm);
612 wm->input_dev->dev.parent = wm->dev;
613
614 ret = input_register_device(wm->input_dev);
615 if (ret)
616 return ret;
617
618 /*
619 * register our extended touch device (for machine specific
620 * extensions)
621 */
622 wm->touch_dev = platform_device_alloc("wm97xx-touch", -1);
623 if (!wm->touch_dev) {
624 ret = -ENOMEM;
625 goto touch_err;
626 }
627 platform_set_drvdata(wm->touch_dev, wm);
628 wm->touch_dev->dev.parent = wm->dev;
629 wm->touch_dev->dev.platform_data = pdata;
630 ret = platform_device_add(wm->touch_dev);
631 if (ret < 0)
632 goto touch_reg_err;
633
634 return 0;
635touch_reg_err:
636 platform_device_put(wm->touch_dev);
637touch_err:
638 input_unregister_device(wm->input_dev);
639 wm->input_dev = NULL;
640
641 return ret;
642}
643
644static void wm97xx_unregister_touch(struct wm97xx *wm)
645{
646 platform_device_unregister(wm->touch_dev);
647 input_unregister_device(wm->input_dev);
648 wm->input_dev = NULL;
649}
650
651static int _wm97xx_probe(struct wm97xx *wm)
652{
653 int id = 0;
654
655 mutex_init(&wm->codec_mutex);
656 dev_set_drvdata(wm->dev, wm);
598 657
599 /* check that we have a supported codec */ 658 /* check that we have a supported codec */
600 id = wm97xx_reg_read(wm, AC97_VENDOR_ID1); 659 id = wm97xx_reg_read(wm, AC97_VENDOR_ID1);
601 if (id != WM97XX_ID1) { 660 if (id != WM97XX_ID1) {
602 dev_err(dev, "Device with vendor %04x is not a wm97xx\n", id); 661 dev_err(wm->dev,
603 ret = -ENODEV; 662 "Device with vendor %04x is not a wm97xx\n", id);
604 goto alloc_err; 663 return -ENODEV;
605 } 664 }
606 665
607 wm->id = wm97xx_reg_read(wm, AC97_VENDOR_ID2); 666 wm->id = wm97xx_reg_read(wm, AC97_VENDOR_ID2);
@@ -629,8 +688,7 @@ static int wm97xx_probe(struct device *dev)
629 default: 688 default:
630 dev_err(wm->dev, "Support for wm97%02x not compiled in.\n", 689 dev_err(wm->dev, "Support for wm97%02x not compiled in.\n",
631 wm->id & 0xff); 690 wm->id & 0xff);
632 ret = -ENODEV; 691 return -ENODEV;
633 goto alloc_err;
634 } 692 }
635 693
636 /* set up physical characteristics */ 694 /* set up physical characteristics */
@@ -644,79 +702,58 @@ static int wm97xx_probe(struct device *dev)
644 wm->gpio[4] = wm97xx_reg_read(wm, AC97_GPIO_STATUS); 702 wm->gpio[4] = wm97xx_reg_read(wm, AC97_GPIO_STATUS);
645 wm->gpio[5] = wm97xx_reg_read(wm, AC97_MISC_AFE); 703 wm->gpio[5] = wm97xx_reg_read(wm, AC97_MISC_AFE);
646 704
647 wm->input_dev = input_allocate_device(); 705 return wm97xx_register_touch(wm);
648 if (wm->input_dev == NULL) { 706}
649 ret = -ENOMEM;
650 goto alloc_err;
651 }
652
653 /* set up touch configuration */
654 wm->input_dev->name = "wm97xx touchscreen";
655 wm->input_dev->phys = "wm97xx";
656 wm->input_dev->open = wm97xx_ts_input_open;
657 wm->input_dev->close = wm97xx_ts_input_close;
658
659 __set_bit(EV_ABS, wm->input_dev->evbit);
660 __set_bit(EV_KEY, wm->input_dev->evbit);
661 __set_bit(BTN_TOUCH, wm->input_dev->keybit);
662
663 input_set_abs_params(wm->input_dev, ABS_X, abs_x[0], abs_x[1],
664 abs_x[2], 0);
665 input_set_abs_params(wm->input_dev, ABS_Y, abs_y[0], abs_y[1],
666 abs_y[2], 0);
667 input_set_abs_params(wm->input_dev, ABS_PRESSURE, abs_p[0], abs_p[1],
668 abs_p[2], 0);
669 707
670 input_set_drvdata(wm->input_dev, wm); 708static void wm97xx_remove_battery(struct wm97xx *wm)
671 wm->input_dev->dev.parent = dev; 709{
710 platform_device_unregister(wm->battery_dev);
711}
672 712
673 ret = input_register_device(wm->input_dev); 713static int wm97xx_add_battery(struct wm97xx *wm,
674 if (ret < 0) 714 struct wm97xx_batt_pdata *pdata)
675 goto dev_alloc_err; 715{
716 int ret;
676 717
677 /* register our battery device */
678 wm->battery_dev = platform_device_alloc("wm97xx-battery", -1); 718 wm->battery_dev = platform_device_alloc("wm97xx-battery", -1);
679 if (!wm->battery_dev) { 719 if (!wm->battery_dev)
680 ret = -ENOMEM; 720 return -ENOMEM;
681 goto batt_err; 721
682 }
683 platform_set_drvdata(wm->battery_dev, wm); 722 platform_set_drvdata(wm->battery_dev, wm);
684 wm->battery_dev->dev.parent = dev; 723 wm->battery_dev->dev.parent = wm->dev;
685 wm->battery_dev->dev.platform_data = pdata ? pdata->batt_pdata : NULL; 724 wm->battery_dev->dev.platform_data = pdata;
686 ret = platform_device_add(wm->battery_dev); 725 ret = platform_device_add(wm->battery_dev);
687 if (ret < 0) 726 if (ret)
688 goto batt_reg_err; 727 platform_device_put(wm->battery_dev);
689 728
690 /* register our extended touch device (for machine specific 729 return ret;
691 * extensions) */ 730}
692 wm->touch_dev = platform_device_alloc("wm97xx-touch", -1); 731
693 if (!wm->touch_dev) { 732static int wm97xx_probe(struct device *dev)
694 ret = -ENOMEM; 733{
695 goto touch_err; 734 struct wm97xx *wm;
696 } 735 int ret;
697 platform_set_drvdata(wm->touch_dev, wm); 736 struct wm97xx_pdata *pdata = dev_get_platdata(dev);
698 wm->touch_dev->dev.parent = dev; 737
699 wm->touch_dev->dev.platform_data = pdata; 738 wm = devm_kzalloc(dev, sizeof(struct wm97xx), GFP_KERNEL);
700 ret = platform_device_add(wm->touch_dev); 739 if (!wm)
740 return -ENOMEM;
741
742 wm->dev = dev;
743 wm->ac97 = to_ac97_t(dev);
744
745 ret = _wm97xx_probe(wm);
746 if (ret)
747 return ret;
748
749 ret = wm97xx_add_battery(wm, pdata ? pdata->batt_pdata : NULL);
701 if (ret < 0) 750 if (ret < 0)
702 goto touch_reg_err; 751 goto batt_err;
703 752
704 return ret; 753 return ret;
705 754
706 touch_reg_err: 755batt_err:
707 platform_device_put(wm->touch_dev); 756 wm97xx_unregister_touch(wm);
708 touch_err:
709 platform_device_del(wm->battery_dev);
710 batt_reg_err:
711 platform_device_put(wm->battery_dev);
712 batt_err:
713 input_unregister_device(wm->input_dev);
714 wm->input_dev = NULL;
715 dev_alloc_err:
716 input_free_device(wm->input_dev);
717 alloc_err:
718 kfree(wm);
719
720 return ret; 757 return ret;
721} 758}
722 759
@@ -724,14 +761,45 @@ static int wm97xx_remove(struct device *dev)
724{ 761{
725 struct wm97xx *wm = dev_get_drvdata(dev); 762 struct wm97xx *wm = dev_get_drvdata(dev);
726 763
727 platform_device_unregister(wm->battery_dev); 764 wm97xx_remove_battery(wm);
728 platform_device_unregister(wm->touch_dev); 765 wm97xx_unregister_touch(wm);
729 input_unregister_device(wm->input_dev);
730 kfree(wm);
731 766
732 return 0; 767 return 0;
733} 768}
734 769
770static int wm97xx_mfd_probe(struct platform_device *pdev)
771{
772 struct wm97xx *wm;
773 struct wm97xx_platform_data *mfd_pdata = dev_get_platdata(&pdev->dev);
774 int ret;
775
776 wm = devm_kzalloc(&pdev->dev, sizeof(struct wm97xx), GFP_KERNEL);
777 if (!wm)
778 return -ENOMEM;
779
780 wm->dev = &pdev->dev;
781 wm->ac97 = mfd_pdata->ac97;
782
783 ret = _wm97xx_probe(wm);
784 if (ret)
785 return ret;
786
787 ret = wm97xx_add_battery(wm, mfd_pdata->batt_pdata);
788 if (ret < 0)
789 goto batt_err;
790
791 return ret;
792
793batt_err:
794 wm97xx_unregister_touch(wm);
795 return ret;
796}
797
798static int wm97xx_mfd_remove(struct platform_device *pdev)
799{
800 return wm97xx_remove(&pdev->dev);
801}
802
735static int __maybe_unused wm97xx_suspend(struct device *dev) 803static int __maybe_unused wm97xx_suspend(struct device *dev)
736{ 804{
737 struct wm97xx *wm = dev_get_drvdata(dev); 805 struct wm97xx *wm = dev_get_drvdata(dev);
@@ -828,21 +896,41 @@ EXPORT_SYMBOL_GPL(wm97xx_unregister_mach_ops);
828 896
829static struct device_driver wm97xx_driver = { 897static struct device_driver wm97xx_driver = {
830 .name = "wm97xx-ts", 898 .name = "wm97xx-ts",
899#ifdef CONFIG_AC97_BUS
831 .bus = &ac97_bus_type, 900 .bus = &ac97_bus_type,
901#endif
832 .owner = THIS_MODULE, 902 .owner = THIS_MODULE,
833 .probe = wm97xx_probe, 903 .probe = wm97xx_probe,
834 .remove = wm97xx_remove, 904 .remove = wm97xx_remove,
835 .pm = &wm97xx_pm_ops, 905 .pm = &wm97xx_pm_ops,
836}; 906};
837 907
908static struct platform_driver wm97xx_mfd_driver = {
909 .driver = {
910 .name = "wm97xx-ts",
911 .pm = &wm97xx_pm_ops,
912 },
913 .probe = wm97xx_mfd_probe,
914 .remove = wm97xx_mfd_remove,
915};
916
838static int __init wm97xx_init(void) 917static int __init wm97xx_init(void)
839{ 918{
840 return driver_register(&wm97xx_driver); 919 int ret;
920
921 ret = platform_driver_register(&wm97xx_mfd_driver);
922 if (ret)
923 return ret;
924
925 if (IS_BUILTIN(CONFIG_AC97_BUS))
926 ret = driver_register(&wm97xx_driver);
927 return ret;
841} 928}
842 929
843static void __exit wm97xx_exit(void) 930static void __exit wm97xx_exit(void)
844{ 931{
845 driver_unregister(&wm97xx_driver); 932 driver_unregister(&wm97xx_driver);
933 platform_driver_unregister(&wm97xx_mfd_driver);
846} 934}
847 935
848module_init(wm97xx_init); 936module_init(wm97xx_init);
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index fc5e4fef89d2..ac5ad6d0837c 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1746,6 +1746,20 @@ config MFD_WM8994
1746 core support for the WM8994, in order to use the actual 1746 core support for the WM8994, in order to use the actual
1747 functionaltiy of the device other drivers must be enabled. 1747 functionaltiy of the device other drivers must be enabled.
1748 1748
1749config MFD_WM97xx
1750 tristate "Wolfson Microelectronics WM97xx"
1751 select MFD_CORE
1752 select REGMAP_AC97
1753 select AC97_BUS_COMPAT
1754 depends on AC97_BUS_NEW
1755 help
1756 The WM9705, WM9712 and WM9713 is a highly integrated hi-fi CODEC
1757 designed for smartphone applications. As well as audio functionality
1758 it has on board GPIO and a touchscreen functionality which is
1759 supported via the relevant subsystems. This driver provides core
1760 support for the WM97xx, in order to use the actual functionaltiy of
1761 the device other drivers must be enabled.
1762
1749config MFD_STW481X 1763config MFD_STW481X
1750 tristate "Support for ST Microelectronics STw481x" 1764 tristate "Support for ST Microelectronics STw481x"
1751 depends on I2C && (ARCH_NOMADIK || COMPILE_TEST) 1765 depends on I2C && (ARCH_NOMADIK || COMPILE_TEST)
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 8703ff17998e..0235e6766bc1 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -74,6 +74,7 @@ obj-$(CONFIG_MFD_WM8350) += wm8350.o
74obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o 74obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o
75wm8994-objs := wm8994-core.o wm8994-irq.o wm8994-regmap.o 75wm8994-objs := wm8994-core.o wm8994-irq.o wm8994-regmap.o
76obj-$(CONFIG_MFD_WM8994) += wm8994.o 76obj-$(CONFIG_MFD_WM8994) += wm8994.o
77obj-$(CONFIG_MFD_WM97xx) += wm97xx-core.o
77 78
78obj-$(CONFIG_TPS6105X) += tps6105x.o 79obj-$(CONFIG_TPS6105X) += tps6105x.o
79obj-$(CONFIG_TPS65010) += tps65010.o 80obj-$(CONFIG_TPS65010) += tps65010.o
diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c
index 8d46e3ad9529..77875250abe5 100644
--- a/drivers/mfd/arizona-core.c
+++ b/drivers/mfd/arizona-core.c
@@ -797,12 +797,7 @@ EXPORT_SYMBOL_GPL(arizona_of_get_type);
797static int arizona_of_get_core_pdata(struct arizona *arizona) 797static int arizona_of_get_core_pdata(struct arizona *arizona)
798{ 798{
799 struct arizona_pdata *pdata = &arizona->pdata; 799 struct arizona_pdata *pdata = &arizona->pdata;
800 struct property *prop;
801 const __be32 *cur;
802 u32 val;
803 u32 pdm_val[ARIZONA_MAX_PDM_SPK];
804 int ret, i; 800 int ret, i;
805 int count = 0;
806 801
807 pdata->reset = of_get_named_gpio(arizona->dev->of_node, "wlf,reset", 0); 802 pdata->reset = of_get_named_gpio(arizona->dev->of_node, "wlf,reset", 0);
808 if (pdata->reset == -EPROBE_DEFER) { 803 if (pdata->reset == -EPROBE_DEFER) {
@@ -836,64 +831,6 @@ static int arizona_of_get_core_pdata(struct arizona *arizona)
836 ret); 831 ret);
837 } 832 }
838 833
839 of_property_for_each_u32(arizona->dev->of_node, "wlf,inmode", prop,
840 cur, val) {
841 if (count == ARRAY_SIZE(pdata->inmode))
842 break;
843
844 pdata->inmode[count] = val;
845 count++;
846 }
847
848 count = 0;
849 of_property_for_each_u32(arizona->dev->of_node, "wlf,dmic-ref", prop,
850 cur, val) {
851 if (count == ARRAY_SIZE(pdata->dmic_ref))
852 break;
853
854 pdata->dmic_ref[count] = val;
855 count++;
856 }
857
858 count = 0;
859 of_property_for_each_u32(arizona->dev->of_node, "wlf,out-mono", prop,
860 cur, val) {
861 if (count == ARRAY_SIZE(pdata->out_mono))
862 break;
863
864 pdata->out_mono[count] = !!val;
865 count++;
866 }
867
868 count = 0;
869 of_property_for_each_u32(arizona->dev->of_node,
870 "wlf,max-channels-clocked",
871 prop, cur, val) {
872 if (count == ARRAY_SIZE(pdata->max_channels_clocked))
873 break;
874
875 pdata->max_channels_clocked[count] = val;
876 count++;
877 }
878
879 ret = of_property_read_u32_array(arizona->dev->of_node,
880 "wlf,spk-fmt",
881 pdm_val,
882 ARRAY_SIZE(pdm_val));
883
884 if (ret >= 0)
885 for (count = 0; count < ARRAY_SIZE(pdata->spk_fmt); ++count)
886 pdata->spk_fmt[count] = pdm_val[count];
887
888 ret = of_property_read_u32_array(arizona->dev->of_node,
889 "wlf,spk-mute",
890 pdm_val,
891 ARRAY_SIZE(pdm_val));
892
893 if (ret >= 0)
894 for (count = 0; count < ARRAY_SIZE(pdata->spk_mute); ++count)
895 pdata->spk_mute[count] = pdm_val[count];
896
897 return 0; 834 return 0;
898} 835}
899 836
@@ -1026,7 +963,7 @@ int arizona_dev_init(struct arizona *arizona)
1026 const char * const mclk_name[] = { "mclk1", "mclk2" }; 963 const char * const mclk_name[] = { "mclk1", "mclk2" };
1027 struct device *dev = arizona->dev; 964 struct device *dev = arizona->dev;
1028 const char *type_name = NULL; 965 const char *type_name = NULL;
1029 unsigned int reg, val, mask; 966 unsigned int reg, val;
1030 int (*apply_patch)(struct arizona *) = NULL; 967 int (*apply_patch)(struct arizona *) = NULL;
1031 const struct mfd_cell *subdevs = NULL; 968 const struct mfd_cell *subdevs = NULL;
1032 int n_subdevs, ret, i; 969 int n_subdevs, ret, i;
@@ -1429,73 +1366,6 @@ int arizona_dev_init(struct arizona *arizona)
1429 ARIZONA_MICB1_RATE, val); 1366 ARIZONA_MICB1_RATE, val);
1430 } 1367 }
1431 1368
1432 for (i = 0; i < ARIZONA_MAX_INPUT; i++) {
1433 /* Default for both is 0 so noop with defaults */
1434 val = arizona->pdata.dmic_ref[i]
1435 << ARIZONA_IN1_DMIC_SUP_SHIFT;
1436 if (arizona->pdata.inmode[i] & ARIZONA_INMODE_DMIC)
1437 val |= 1 << ARIZONA_IN1_MODE_SHIFT;
1438
1439 switch (arizona->type) {
1440 case WM8998:
1441 case WM1814:
1442 regmap_update_bits(arizona->regmap,
1443 ARIZONA_ADC_DIGITAL_VOLUME_1L + (i * 8),
1444 ARIZONA_IN1L_SRC_SE_MASK,
1445 (arizona->pdata.inmode[i] & ARIZONA_INMODE_SE)
1446 << ARIZONA_IN1L_SRC_SE_SHIFT);
1447
1448 regmap_update_bits(arizona->regmap,
1449 ARIZONA_ADC_DIGITAL_VOLUME_1R + (i * 8),
1450 ARIZONA_IN1R_SRC_SE_MASK,
1451 (arizona->pdata.inmode[i] & ARIZONA_INMODE_SE)
1452 << ARIZONA_IN1R_SRC_SE_SHIFT);
1453
1454 mask = ARIZONA_IN1_DMIC_SUP_MASK |
1455 ARIZONA_IN1_MODE_MASK;
1456 break;
1457 default:
1458 if (arizona->pdata.inmode[i] & ARIZONA_INMODE_SE)
1459 val |= 1 << ARIZONA_IN1_SINGLE_ENDED_SHIFT;
1460
1461 mask = ARIZONA_IN1_DMIC_SUP_MASK |
1462 ARIZONA_IN1_MODE_MASK |
1463 ARIZONA_IN1_SINGLE_ENDED_MASK;
1464 break;
1465 }
1466
1467 regmap_update_bits(arizona->regmap,
1468 ARIZONA_IN1L_CONTROL + (i * 8),
1469 mask, val);
1470 }
1471
1472 for (i = 0; i < ARIZONA_MAX_OUTPUT; i++) {
1473 /* Default is 0 so noop with defaults */
1474 if (arizona->pdata.out_mono[i])
1475 val = ARIZONA_OUT1_MONO;
1476 else
1477 val = 0;
1478
1479 regmap_update_bits(arizona->regmap,
1480 ARIZONA_OUTPUT_PATH_CONFIG_1L + (i * 8),
1481 ARIZONA_OUT1_MONO, val);
1482 }
1483
1484 for (i = 0; i < ARIZONA_MAX_PDM_SPK; i++) {
1485 if (arizona->pdata.spk_mute[i])
1486 regmap_update_bits(arizona->regmap,
1487 ARIZONA_PDM_SPK1_CTRL_1 + (i * 2),
1488 ARIZONA_SPK1_MUTE_ENDIAN_MASK |
1489 ARIZONA_SPK1_MUTE_SEQ1_MASK,
1490 arizona->pdata.spk_mute[i]);
1491
1492 if (arizona->pdata.spk_fmt[i])
1493 regmap_update_bits(arizona->regmap,
1494 ARIZONA_PDM_SPK1_CTRL_2 + (i * 2),
1495 ARIZONA_SPK1_FMT_MASK,
1496 arizona->pdata.spk_fmt[i]);
1497 }
1498
1499 pm_runtime_set_active(arizona->dev); 1369 pm_runtime_set_active(arizona->dev);
1500 pm_runtime_enable(arizona->dev); 1370 pm_runtime_enable(arizona->dev);
1501 1371
diff --git a/drivers/mfd/wm97xx-core.c b/drivers/mfd/wm97xx-core.c
new file mode 100644
index 000000000000..4141ee52a70b
--- /dev/null
+++ b/drivers/mfd/wm97xx-core.c
@@ -0,0 +1,366 @@
1/*
2 * Wolfson WM97xx -- Core device
3 *
4 * Copyright (C) 2017 Robert Jarzmik
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 as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * Features:
12 * - an AC97 audio codec
13 * - a touchscreen driver
14 * - a GPIO block
15 */
16
17#include <linux/device.h>
18#include <linux/mfd/core.h>
19#include <linux/mfd/wm97xx.h>
20#include <linux/module.h>
21#include <linux/regmap.h>
22#include <linux/slab.h>
23#include <linux/wm97xx.h>
24#include <sound/ac97/codec.h>
25#include <sound/ac97/compat.h>
26
27#define WM9705_VENDOR_ID 0x574d4c05
28#define WM9712_VENDOR_ID 0x574d4c12
29#define WM9713_VENDOR_ID 0x574d4c13
30#define WM97xx_VENDOR_ID_MASK 0xffffffff
31
32struct wm97xx_priv {
33 struct regmap *regmap;
34 struct snd_ac97 *ac97;
35 struct device *dev;
36 struct wm97xx_platform_data codec_pdata;
37};
38
39static bool wm97xx_readable_reg(struct device *dev, unsigned int reg)
40{
41 switch (reg) {
42 case AC97_RESET ... AC97_PCM_SURR_DAC_RATE:
43 case AC97_PCM_LR_ADC_RATE:
44 case AC97_CENTER_LFE_MASTER:
45 case AC97_SPDIF ... AC97_LINE1_LEVEL:
46 case AC97_GPIO_CFG ... 0x5c:
47 case AC97_CODEC_CLASS_REV ... AC97_PCI_SID:
48 case 0x74 ... AC97_VENDOR_ID2:
49 return true;
50 default:
51 return false;
52 }
53}
54
55static bool wm97xx_writeable_reg(struct device *dev, unsigned int reg)
56{
57 switch (reg) {
58 case AC97_VENDOR_ID1:
59 case AC97_VENDOR_ID2:
60 return false;
61 default:
62 return wm97xx_readable_reg(dev, reg);
63 }
64}
65
66static const struct reg_default wm9705_reg_defaults[] = {
67 { 0x02, 0x8000 },
68 { 0x04, 0x8000 },
69 { 0x06, 0x8000 },
70 { 0x0a, 0x8000 },
71 { 0x0c, 0x8008 },
72 { 0x0e, 0x8008 },
73 { 0x10, 0x8808 },
74 { 0x12, 0x8808 },
75 { 0x14, 0x8808 },
76 { 0x16, 0x8808 },
77 { 0x18, 0x8808 },
78 { 0x1a, 0x0000 },
79 { 0x1c, 0x8000 },
80 { 0x20, 0x0000 },
81 { 0x22, 0x0000 },
82 { 0x26, 0x000f },
83 { 0x28, 0x0605 },
84 { 0x2a, 0x0000 },
85 { 0x2c, 0xbb80 },
86 { 0x32, 0xbb80 },
87 { 0x34, 0x2000 },
88 { 0x5a, 0x0000 },
89 { 0x5c, 0x0000 },
90 { 0x72, 0x0808 },
91 { 0x74, 0x0000 },
92 { 0x76, 0x0006 },
93 { 0x78, 0x0000 },
94 { 0x7a, 0x0000 },
95};
96
97static const struct regmap_config wm9705_regmap_config = {
98 .reg_bits = 16,
99 .reg_stride = 2,
100 .val_bits = 16,
101 .max_register = 0x7e,
102 .cache_type = REGCACHE_RBTREE,
103
104 .reg_defaults = wm9705_reg_defaults,
105 .num_reg_defaults = ARRAY_SIZE(wm9705_reg_defaults),
106 .volatile_reg = regmap_ac97_default_volatile,
107 .readable_reg = wm97xx_readable_reg,
108 .writeable_reg = wm97xx_writeable_reg,
109};
110
111static struct mfd_cell wm9705_cells[] = {
112 { .name = "wm9705-codec", },
113 { .name = "wm97xx-ts", },
114};
115
116static bool wm9712_volatile_reg(struct device *dev, unsigned int reg)
117{
118 switch (reg) {
119 case AC97_REC_GAIN:
120 return true;
121 default:
122 return regmap_ac97_default_volatile(dev, reg);
123 }
124}
125
126static const struct reg_default wm9712_reg_defaults[] = {
127 { 0x02, 0x8000 },
128 { 0x04, 0x8000 },
129 { 0x06, 0x8000 },
130 { 0x08, 0x0f0f },
131 { 0x0a, 0xaaa0 },
132 { 0x0c, 0xc008 },
133 { 0x0e, 0x6808 },
134 { 0x10, 0xe808 },
135 { 0x12, 0xaaa0 },
136 { 0x14, 0xad00 },
137 { 0x16, 0x8000 },
138 { 0x18, 0xe808 },
139 { 0x1a, 0x3000 },
140 { 0x1c, 0x8000 },
141 { 0x20, 0x0000 },
142 { 0x22, 0x0000 },
143 { 0x26, 0x000f },
144 { 0x28, 0x0605 },
145 { 0x2a, 0x0410 },
146 { 0x2c, 0xbb80 },
147 { 0x2e, 0xbb80 },
148 { 0x32, 0xbb80 },
149 { 0x34, 0x2000 },
150 { 0x4c, 0xf83e },
151 { 0x4e, 0xffff },
152 { 0x50, 0x0000 },
153 { 0x52, 0x0000 },
154 { 0x56, 0xf83e },
155 { 0x58, 0x0008 },
156 { 0x5c, 0x0000 },
157 { 0x60, 0xb032 },
158 { 0x62, 0x3e00 },
159 { 0x64, 0x0000 },
160 { 0x76, 0x0006 },
161 { 0x78, 0x0001 },
162 { 0x7a, 0x0000 },
163};
164
165static const struct regmap_config wm9712_regmap_config = {
166 .reg_bits = 16,
167 .reg_stride = 2,
168 .val_bits = 16,
169 .max_register = 0x7e,
170 .cache_type = REGCACHE_RBTREE,
171
172 .reg_defaults = wm9712_reg_defaults,
173 .num_reg_defaults = ARRAY_SIZE(wm9712_reg_defaults),
174 .volatile_reg = wm9712_volatile_reg,
175 .readable_reg = wm97xx_readable_reg,
176 .writeable_reg = wm97xx_writeable_reg,
177};
178
179static struct mfd_cell wm9712_cells[] = {
180 { .name = "wm9712-codec", },
181 { .name = "wm97xx-ts", },
182};
183
184static const struct reg_default wm9713_reg_defaults[] = {
185 { 0x02, 0x8080 }, /* Speaker Output Volume */
186 { 0x04, 0x8080 }, /* Headphone Output Volume */
187 { 0x06, 0x8080 }, /* Out3/OUT4 Volume */
188 { 0x08, 0xc880 }, /* Mono Volume */
189 { 0x0a, 0xe808 }, /* LINEIN Volume */
190 { 0x0c, 0xe808 }, /* DAC PGA Volume */
191 { 0x0e, 0x0808 }, /* MIC PGA Volume */
192 { 0x10, 0x00da }, /* MIC Routing Control */
193 { 0x12, 0x8000 }, /* Record PGA Volume */
194 { 0x14, 0xd600 }, /* Record Routing */
195 { 0x16, 0xaaa0 }, /* PCBEEP Volume */
196 { 0x18, 0xaaa0 }, /* VxDAC Volume */
197 { 0x1a, 0xaaa0 }, /* AUXDAC Volume */
198 { 0x1c, 0x0000 }, /* Output PGA Mux */
199 { 0x1e, 0x0000 }, /* DAC 3D control */
200 { 0x20, 0x0f0f }, /* DAC Tone Control*/
201 { 0x22, 0x0040 }, /* MIC Input Select & Bias */
202 { 0x24, 0x0000 }, /* Output Volume Mapping & Jack */
203 { 0x26, 0x7f00 }, /* Powerdown Ctrl/Stat*/
204 { 0x28, 0x0405 }, /* Extended Audio ID */
205 { 0x2a, 0x0410 }, /* Extended Audio Start/Ctrl */
206 { 0x2c, 0xbb80 }, /* Audio DACs Sample Rate */
207 { 0x2e, 0xbb80 }, /* AUXDAC Sample Rate */
208 { 0x32, 0xbb80 }, /* Audio ADCs Sample Rate */
209 { 0x36, 0x4523 }, /* PCM codec control */
210 { 0x3a, 0x2000 }, /* SPDIF control */
211 { 0x3c, 0xfdff }, /* Powerdown 1 */
212 { 0x3e, 0xffff }, /* Powerdown 2 */
213 { 0x40, 0x0000 }, /* General Purpose */
214 { 0x42, 0x0000 }, /* Fast Power-Up Control */
215 { 0x44, 0x0080 }, /* MCLK/PLL Control */
216 { 0x46, 0x0000 }, /* MCLK/PLL Control */
217
218 { 0x4c, 0xfffe }, /* GPIO Pin Configuration */
219 { 0x4e, 0xffff }, /* GPIO Pin Polarity / Type */
220 { 0x50, 0x0000 }, /* GPIO Pin Sticky */
221 { 0x52, 0x0000 }, /* GPIO Pin Wake-Up */
222 /* GPIO Pin Status */
223 { 0x56, 0xfffe }, /* GPIO Pin Sharing */
224 { 0x58, 0x4000 }, /* GPIO PullUp/PullDown */
225 { 0x5a, 0x0000 }, /* Additional Functions 1 */
226 { 0x5c, 0x0000 }, /* Additional Functions 2 */
227 { 0x60, 0xb032 }, /* ALC Control */
228 { 0x62, 0x3e00 }, /* ALC / Noise Gate Control */
229 { 0x64, 0x0000 }, /* AUXDAC input control */
230 { 0x74, 0x0000 }, /* Digitiser Reg 1 */
231 { 0x76, 0x0006 }, /* Digitiser Reg 2 */
232 { 0x78, 0x0001 }, /* Digitiser Reg 3 */
233 { 0x7a, 0x0000 }, /* Digitiser Read Back */
234};
235
236static const struct regmap_config wm9713_regmap_config = {
237 .reg_bits = 16,
238 .reg_stride = 2,
239 .val_bits = 16,
240 .max_register = 0x7e,
241 .cache_type = REGCACHE_RBTREE,
242
243 .reg_defaults = wm9713_reg_defaults,
244 .num_reg_defaults = ARRAY_SIZE(wm9713_reg_defaults),
245 .volatile_reg = regmap_ac97_default_volatile,
246 .readable_reg = wm97xx_readable_reg,
247 .writeable_reg = wm97xx_writeable_reg,
248};
249
250static struct mfd_cell wm9713_cells[] = {
251 { .name = "wm9713-codec", },
252 { .name = "wm97xx-ts", },
253};
254
255static int wm97xx_ac97_probe(struct ac97_codec_device *adev)
256{
257 struct wm97xx_priv *wm97xx;
258 const struct regmap_config *config;
259 struct wm97xx_platform_data *codec_pdata;
260 struct mfd_cell *cells;
261 int ret = -ENODEV, nb_cells, i;
262 struct wm97xx_pdata *pdata = snd_ac97_codec_get_platdata(adev);
263
264 wm97xx = devm_kzalloc(ac97_codec_dev2dev(adev),
265 sizeof(*wm97xx), GFP_KERNEL);
266 if (!wm97xx)
267 return -ENOMEM;
268
269 wm97xx->dev = ac97_codec_dev2dev(adev);
270 wm97xx->ac97 = snd_ac97_compat_alloc(adev);
271 if (IS_ERR(wm97xx->ac97))
272 return PTR_ERR(wm97xx->ac97);
273
274
275 ac97_set_drvdata(adev, wm97xx);
276 dev_info(wm97xx->dev, "wm97xx core found, id=0x%x\n",
277 adev->vendor_id);
278
279 codec_pdata = &wm97xx->codec_pdata;
280 codec_pdata->ac97 = wm97xx->ac97;
281 codec_pdata->batt_pdata = pdata->batt_pdata;
282
283 switch (adev->vendor_id) {
284 case WM9705_VENDOR_ID:
285 config = &wm9705_regmap_config;
286 cells = wm9705_cells;
287 nb_cells = ARRAY_SIZE(wm9705_cells);
288 break;
289 case WM9712_VENDOR_ID:
290 config = &wm9712_regmap_config;
291 cells = wm9712_cells;
292 nb_cells = ARRAY_SIZE(wm9712_cells);
293 break;
294 case WM9713_VENDOR_ID:
295 config = &wm9713_regmap_config;
296 cells = wm9713_cells;
297 nb_cells = ARRAY_SIZE(wm9713_cells);
298 break;
299 default:
300 goto err_free_compat;
301 }
302
303 for (i = 0; i < nb_cells; i++) {
304 cells[i].platform_data = codec_pdata;
305 cells[i].pdata_size = sizeof(*codec_pdata);
306 }
307
308 codec_pdata->regmap = devm_regmap_init_ac97(wm97xx->ac97, config);
309 if (IS_ERR(codec_pdata->regmap)) {
310 ret = PTR_ERR(codec_pdata->regmap);
311 goto err_free_compat;
312 }
313
314 ret = devm_mfd_add_devices(wm97xx->dev, PLATFORM_DEVID_NONE,
315 cells, nb_cells, NULL, 0, NULL);
316 if (ret)
317 goto err_free_compat;
318
319 return ret;
320
321err_free_compat:
322 snd_ac97_compat_release(wm97xx->ac97);
323 return ret;
324}
325
326static int wm97xx_ac97_remove(struct ac97_codec_device *adev)
327{
328 struct wm97xx_priv *wm97xx = ac97_get_drvdata(adev);
329
330 snd_ac97_compat_release(wm97xx->ac97);
331
332 return 0;
333}
334
335static const struct ac97_id wm97xx_ac97_ids[] = {
336 { .id = WM9705_VENDOR_ID, .mask = WM97xx_VENDOR_ID_MASK },
337 { .id = WM9712_VENDOR_ID, .mask = WM97xx_VENDOR_ID_MASK },
338 { .id = WM9713_VENDOR_ID, .mask = WM97xx_VENDOR_ID_MASK },
339 { }
340};
341
342static struct ac97_codec_driver wm97xx_ac97_driver = {
343 .driver = {
344 .name = "wm97xx-core",
345 },
346 .probe = wm97xx_ac97_probe,
347 .remove = wm97xx_ac97_remove,
348 .id_table = wm97xx_ac97_ids,
349};
350
351static int __init wm97xx_module_init(void)
352{
353 return snd_ac97_codec_driver_register(&wm97xx_ac97_driver);
354}
355module_init(wm97xx_module_init);
356
357static void __exit wm97xx_module_exit(void)
358{
359 snd_ac97_codec_driver_unregister(&wm97xx_ac97_driver);
360}
361module_exit(wm97xx_module_exit);
362
363MODULE_DESCRIPTION("WM9712, WM9713 core driver");
364MODULE_AUTHOR("Robert Jarzmik <robert.jarzmik@free.fr>");
365MODULE_LICENSE("GPL");
366
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index f501af0b3079..9fdf137c4865 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -187,6 +187,31 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb);
187 187
188/*-------------------------------------------------------------------*/ 188/*-------------------------------------------------------------------*/
189 189
190static const int pipetypes[4] = {
191 PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT
192};
193
194/**
195 * usb_urb_ep_type_check - sanity check of endpoint in the given urb
196 * @urb: urb to be checked
197 *
198 * This performs a light-weight sanity check for the endpoint in the
199 * given urb. It returns 0 if the urb contains a valid endpoint, otherwise
200 * a negative error code.
201 */
202int usb_urb_ep_type_check(const struct urb *urb)
203{
204 const struct usb_host_endpoint *ep;
205
206 ep = usb_pipe_endpoint(urb->dev, urb->pipe);
207 if (!ep)
208 return -EINVAL;
209 if (usb_pipetype(urb->pipe) != pipetypes[usb_endpoint_type(&ep->desc)])
210 return -EINVAL;
211 return 0;
212}
213EXPORT_SYMBOL_GPL(usb_urb_ep_type_check);
214
190/** 215/**
191 * usb_submit_urb - issue an asynchronous transfer request for an endpoint 216 * usb_submit_urb - issue an asynchronous transfer request for an endpoint
192 * @urb: pointer to the urb describing the request 217 * @urb: pointer to the urb describing the request
@@ -326,9 +351,6 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb);
326 */ 351 */
327int usb_submit_urb(struct urb *urb, gfp_t mem_flags) 352int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
328{ 353{
329 static int pipetypes[4] = {
330 PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT
331 };
332 int xfertype, max; 354 int xfertype, max;
333 struct usb_device *dev; 355 struct usb_device *dev;
334 struct usb_host_endpoint *ep; 356 struct usb_host_endpoint *ep;
@@ -444,7 +466,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
444 */ 466 */
445 467
446 /* Check that the pipe's type matches the endpoint's type */ 468 /* Check that the pipe's type matches the endpoint's type */
447 if (usb_pipetype(urb->pipe) != pipetypes[xfertype]) 469 if (usb_urb_ep_type_check(urb))
448 dev_WARN(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n", 470 dev_WARN(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n",
449 usb_pipetype(urb->pipe), pipetypes[xfertype]); 471 usb_pipetype(urb->pipe), pipetypes[xfertype]);
450 472
diff --git a/include/drm/amd_asic_type.h b/include/drm/amd_asic_type.h
new file mode 100644
index 000000000000..599028f66585
--- /dev/null
+++ b/include/drm/amd_asic_type.h
@@ -0,0 +1,52 @@
1/*
2 * Copyright 2017 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23#ifndef __AMD_ASIC_TYPE_H__
24#define __AMD_ASIC_TYPE_H__
25/*
26 * Supported ASIC types
27 */
28enum amd_asic_type {
29 CHIP_TAHITI = 0,
30 CHIP_PITCAIRN,
31 CHIP_VERDE,
32 CHIP_OLAND,
33 CHIP_HAINAN,
34 CHIP_BONAIRE,
35 CHIP_KAVERI,
36 CHIP_KABINI,
37 CHIP_HAWAII,
38 CHIP_MULLINS,
39 CHIP_TOPAZ,
40 CHIP_TONGA,
41 CHIP_FIJI,
42 CHIP_CARRIZO,
43 CHIP_STONEY,
44 CHIP_POLARIS10,
45 CHIP_POLARIS11,
46 CHIP_POLARIS12,
47 CHIP_VEGA10,
48 CHIP_RAVEN,
49 CHIP_LAST,
50};
51
52#endif /*__AMD_ASIC_TYPE_H__ */
diff --git a/include/linux/mfd/arizona/pdata.h b/include/linux/mfd/arizona/pdata.h
index bfeecf179895..f72dc53848d7 100644
--- a/include/linux/mfd/arizona/pdata.h
+++ b/include/linux/mfd/arizona/pdata.h
@@ -174,6 +174,9 @@ struct arizona_pdata {
174 /** Mode for outputs */ 174 /** Mode for outputs */
175 int out_mono[ARIZONA_MAX_OUTPUT]; 175 int out_mono[ARIZONA_MAX_OUTPUT];
176 176
177 /** Limit output volumes */
178 unsigned int out_vol_limit[2 * ARIZONA_MAX_OUTPUT];
179
177 /** PDM speaker mute setting */ 180 /** PDM speaker mute setting */
178 unsigned int spk_mute[ARIZONA_MAX_PDM_SPK]; 181 unsigned int spk_mute[ARIZONA_MAX_PDM_SPK];
179 182
diff --git a/include/linux/mfd/wm97xx.h b/include/linux/mfd/wm97xx.h
new file mode 100644
index 000000000000..45fb54f19d09
--- /dev/null
+++ b/include/linux/mfd/wm97xx.h
@@ -0,0 +1,25 @@
1/*
2 * wm97xx client interface
3 *
4 * Copyright (C) 2017 Robert Jarzmik
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 as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#ifndef __LINUX_MFD_WM97XX_H
13#define __LINUX_MFD_WM97XX_H
14
15struct regmap;
16struct wm97xx_batt_pdata;
17struct snd_ac97;
18
19struct wm97xx_platform_data {
20 struct snd_ac97 *ac97;
21 struct regmap *regmap;
22 struct wm97xx_batt_pdata *batt_pdata;
23};
24
25#endif
diff --git a/include/linux/usb.h b/include/linux/usb.h
index f019b0397599..fbbe974661f2 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -1729,6 +1729,8 @@ static inline int usb_urb_dir_out(struct urb *urb)
1729 return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_OUT; 1729 return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_OUT;
1730} 1730}
1731 1731
1732int usb_urb_ep_type_check(const struct urb *urb);
1733
1732void *usb_alloc_coherent(struct usb_device *dev, size_t size, 1734void *usb_alloc_coherent(struct usb_device *dev, size_t size,
1733 gfp_t mem_flags, dma_addr_t *dma); 1735 gfp_t mem_flags, dma_addr_t *dma);
1734void usb_free_coherent(struct usb_device *dev, size_t size, 1736void usb_free_coherent(struct usb_device *dev, size_t size,
diff --git a/include/sound/ac97/codec.h b/include/sound/ac97/codec.h
new file mode 100644
index 000000000000..ec04be9ab119
--- /dev/null
+++ b/include/sound/ac97/codec.h
@@ -0,0 +1,118 @@
1/*
2 * Copyright (C) 2016 Robert Jarzmik <robert.jarzmik@free.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8#ifndef __SOUND_AC97_CODEC2_H
9#define __SOUND_AC97_CODEC2_H
10
11#include <linux/device.h>
12
13#define AC97_ID(vendor_id1, vendor_id2) \
14 ((((vendor_id1) & 0xffff) << 16) | ((vendor_id2) & 0xffff))
15#define AC97_DRIVER_ID(vendor_id1, vendor_id2, mask_id1, mask_id2, _data) \
16 { .id = (((vendor_id1) & 0xffff) << 16) | ((vendor_id2) & 0xffff), \
17 .mask = (((mask_id1) & 0xffff) << 16) | ((mask_id2) & 0xffff), \
18 .data = (_data) }
19
20struct ac97_controller;
21struct clk;
22
23/**
24 * struct ac97_id - matches a codec device and driver on an ac97 bus
25 * @id: The significant bits if the codec vendor ID1 and ID2
26 * @mask: Bitmask specifying which bits of the id field are significant when
27 * matching. A driver binds to a device when :
28 * ((vendorID1 << 8 | vendorID2) & (mask_id1 << 8 | mask_id2)) == id.
29 * @data: Private data used by the driver.
30 */
31struct ac97_id {
32 unsigned int id;
33 unsigned int mask;
34 void *data;
35};
36
37/**
38 * ac97_codec_device - a ac97 codec
39 * @dev: the core device
40 * @vendor_id: the vendor_id of the codec, as sensed on the AC-link
41 * @num: the codec number, 0 is primary, 1 is first slave, etc ...
42 * @clk: the clock BIT_CLK provided by the codec
43 * @ac97_ctrl: ac97 digital controller on the same AC-link
44 *
45 * This is the device instantiated for each codec living on a AC-link. There are
46 * normally 0 to 4 codec devices per AC-link, and all of them are controlled by
47 * an AC97 digital controller.
48 */
49struct ac97_codec_device {
50 struct device dev;
51 unsigned int vendor_id;
52 unsigned int num;
53 struct clk *clk;
54 struct ac97_controller *ac97_ctrl;
55};
56
57/**
58 * ac97_codec_driver - a ac97 codec driver
59 * @driver: the device driver structure
60 * @probe: the function called when a ac97_codec_device is matched
61 * @remove: the function called when the device is unbound/removed
62 * @shutdown: shutdown function (might be NULL)
63 * @id_table: ac97 vendor_id match table, { } member terminated
64 */
65struct ac97_codec_driver {
66 struct device_driver driver;
67 int (*probe)(struct ac97_codec_device *);
68 int (*remove)(struct ac97_codec_device *);
69 void (*shutdown)(struct ac97_codec_device *);
70 const struct ac97_id *id_table;
71};
72
73static inline struct ac97_codec_device *to_ac97_device(struct device *d)
74{
75 return container_of(d, struct ac97_codec_device, dev);
76}
77
78static inline struct ac97_codec_driver *to_ac97_driver(struct device_driver *d)
79{
80 return container_of(d, struct ac97_codec_driver, driver);
81}
82
83#if IS_ENABLED(CONFIG_AC97_BUS_NEW)
84int snd_ac97_codec_driver_register(struct ac97_codec_driver *drv);
85void snd_ac97_codec_driver_unregister(struct ac97_codec_driver *drv);
86#else
87static inline int
88snd_ac97_codec_driver_register(struct ac97_codec_driver *drv)
89{
90 return 0;
91}
92static inline void
93snd_ac97_codec_driver_unregister(struct ac97_codec_driver *drv)
94{
95}
96#endif
97
98
99static inline struct device *
100ac97_codec_dev2dev(struct ac97_codec_device *adev)
101{
102 return &adev->dev;
103}
104
105static inline void *ac97_get_drvdata(struct ac97_codec_device *adev)
106{
107 return dev_get_drvdata(ac97_codec_dev2dev(adev));
108}
109
110static inline void ac97_set_drvdata(struct ac97_codec_device *adev,
111 void *data)
112{
113 dev_set_drvdata(ac97_codec_dev2dev(adev), data);
114}
115
116void *snd_ac97_codec_get_platdata(const struct ac97_codec_device *adev);
117
118#endif
diff --git a/include/sound/ac97/compat.h b/include/sound/ac97/compat.h
new file mode 100644
index 000000000000..1351cba40048
--- /dev/null
+++ b/include/sound/ac97/compat.h
@@ -0,0 +1,20 @@
1/*
2 * Copyright (C) 2016 Robert Jarzmik <robert.jarzmik@free.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This file is for backward compatibility with snd_ac97 structure and its
9 * multiple usages, such as the snd_ac97_bus and snd_ac97_build_ops.
10 *
11 */
12#ifndef AC97_COMPAT_H
13#define AC97_COMPAT_H
14
15#include <sound/ac97_codec.h>
16
17struct snd_ac97 *snd_ac97_compat_alloc(struct ac97_codec_device *adev);
18void snd_ac97_compat_release(struct snd_ac97 *ac97);
19
20#endif
diff --git a/include/sound/ac97/controller.h b/include/sound/ac97/controller.h
new file mode 100644
index 000000000000..b36ecdd64f14
--- /dev/null
+++ b/include/sound/ac97/controller.h
@@ -0,0 +1,85 @@
1/*
2 * Copyright (C) 2016 Robert Jarzmik <robert.jarzmik@free.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8#ifndef AC97_CONTROLLER_H
9#define AC97_CONTROLLER_H
10
11#include <linux/device.h>
12#include <linux/list.h>
13
14#define AC97_BUS_MAX_CODECS 4
15#define AC97_SLOTS_AVAILABLE_ALL 0xf
16
17struct ac97_controller_ops;
18
19/**
20 * struct ac97_controller - The AC97 controller of the AC-Link
21 * @ops: the AC97 operations.
22 * @controllers: linked list of all existing controllers.
23 * @adap: the shell device ac97-%d, ie. ac97 adapter
24 * @nr: the number of the shell device
25 * @slots_available: the mask of accessible/scanable codecs.
26 * @parent: the device providing the AC97 controller.
27 * @codecs: the 4 possible AC97 codecs (NULL if none found).
28 * @codecs_pdata: platform_data for each codec (NULL if no pdata).
29 *
30 * This structure is internal to AC97 bus, and should not be used by the
31 * controllers themselves, excepting for using @dev.
32 */
33struct ac97_controller {
34 const struct ac97_controller_ops *ops;
35 struct list_head controllers;
36 struct device adap;
37 int nr;
38 unsigned short slots_available;
39 struct device *parent;
40 struct ac97_codec_device *codecs[AC97_BUS_MAX_CODECS];
41 void *codecs_pdata[AC97_BUS_MAX_CODECS];
42};
43
44/**
45 * struct ac97_controller_ops - The AC97 operations
46 * @reset: Cold reset of the AC97 AC-Link.
47 * @warm_reset: Warm reset of the AC97 AC-Link.
48 * @read: Read of a single AC97 register.
49 * Returns the register value or a negative error code.
50 * @write: Write of a single AC97 register.
51 *
52 * These are the basic operation an AC97 controller must provide for an AC97
53 * access functions. Amongst these, all but the last 2 are mandatory.
54 * The slot number is also known as the AC97 codec number, between 0 and 3.
55 */
56struct ac97_controller_ops {
57 void (*reset)(struct ac97_controller *adrv);
58 void (*warm_reset)(struct ac97_controller *adrv);
59 int (*write)(struct ac97_controller *adrv, int slot,
60 unsigned short reg, unsigned short val);
61 int (*read)(struct ac97_controller *adrv, int slot, unsigned short reg);
62};
63
64#if IS_ENABLED(CONFIG_AC97_BUS_NEW)
65struct ac97_controller *snd_ac97_controller_register(
66 const struct ac97_controller_ops *ops, struct device *dev,
67 unsigned short slots_available, void **codecs_pdata);
68void snd_ac97_controller_unregister(struct ac97_controller *ac97_ctrl);
69#else
70static inline struct ac97_controller *
71snd_ac97_controller_register(const struct ac97_controller_ops *ops,
72 struct device *dev,
73 unsigned short slots_available,
74 void **codecs_pdata)
75{
76 return ERR_PTR(-ENODEV);
77}
78
79static inline void
80snd_ac97_controller_unregister(struct ac97_controller *ac97_ctrl)
81{
82}
83#endif
84
85#endif
diff --git a/include/sound/ac97/regs.h b/include/sound/ac97/regs.h
new file mode 100644
index 000000000000..4bb86d379bd5
--- /dev/null
+++ b/include/sound/ac97/regs.h
@@ -0,0 +1,262 @@
1/*
2 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
3 * Universal interface for Audio Codec '97
4 *
5 * For more details look to AC '97 component specification revision 2.1
6 * by Intel Corporation (http://developer.intel.com).
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25/*
26 * AC'97 codec registers
27 */
28
29#define AC97_RESET 0x00 /* Reset */
30#define AC97_MASTER 0x02 /* Master Volume */
31#define AC97_HEADPHONE 0x04 /* Headphone Volume (optional) */
32#define AC97_MASTER_MONO 0x06 /* Master Volume Mono (optional) */
33#define AC97_MASTER_TONE 0x08 /* Master Tone (Bass & Treble) (optional) */
34#define AC97_PC_BEEP 0x0a /* PC Beep Volume (optinal) */
35#define AC97_PHONE 0x0c /* Phone Volume (optional) */
36#define AC97_MIC 0x0e /* MIC Volume */
37#define AC97_LINE 0x10 /* Line In Volume */
38#define AC97_CD 0x12 /* CD Volume */
39#define AC97_VIDEO 0x14 /* Video Volume (optional) */
40#define AC97_AUX 0x16 /* AUX Volume (optional) */
41#define AC97_PCM 0x18 /* PCM Volume */
42#define AC97_REC_SEL 0x1a /* Record Select */
43#define AC97_REC_GAIN 0x1c /* Record Gain */
44#define AC97_REC_GAIN_MIC 0x1e /* Record Gain MIC (optional) */
45#define AC97_GENERAL_PURPOSE 0x20 /* General Purpose (optional) */
46#define AC97_3D_CONTROL 0x22 /* 3D Control (optional) */
47#define AC97_INT_PAGING 0x24 /* Audio Interrupt & Paging (AC'97 2.3) */
48#define AC97_POWERDOWN 0x26 /* Powerdown control / status */
49/* range 0x28-0x3a - AUDIO AC'97 2.0 extensions */
50#define AC97_EXTENDED_ID 0x28 /* Extended Audio ID */
51#define AC97_EXTENDED_STATUS 0x2a /* Extended Audio Status and Control */
52#define AC97_PCM_FRONT_DAC_RATE 0x2c /* PCM Front DAC Rate */
53#define AC97_PCM_SURR_DAC_RATE 0x2e /* PCM Surround DAC Rate */
54#define AC97_PCM_LFE_DAC_RATE 0x30 /* PCM LFE DAC Rate */
55#define AC97_PCM_LR_ADC_RATE 0x32 /* PCM LR ADC Rate */
56#define AC97_PCM_MIC_ADC_RATE 0x34 /* PCM MIC ADC Rate */
57#define AC97_CENTER_LFE_MASTER 0x36 /* Center + LFE Master Volume */
58#define AC97_SURROUND_MASTER 0x38 /* Surround (Rear) Master Volume */
59#define AC97_SPDIF 0x3a /* S/PDIF control */
60/* range 0x3c-0x58 - MODEM */
61#define AC97_EXTENDED_MID 0x3c /* Extended Modem ID */
62#define AC97_EXTENDED_MSTATUS 0x3e /* Extended Modem Status and Control */
63#define AC97_LINE1_RATE 0x40 /* Line1 DAC/ADC Rate */
64#define AC97_LINE2_RATE 0x42 /* Line2 DAC/ADC Rate */
65#define AC97_HANDSET_RATE 0x44 /* Handset DAC/ADC Rate */
66#define AC97_LINE1_LEVEL 0x46 /* Line1 DAC/ADC Level */
67#define AC97_LINE2_LEVEL 0x48 /* Line2 DAC/ADC Level */
68#define AC97_HANDSET_LEVEL 0x4a /* Handset DAC/ADC Level */
69#define AC97_GPIO_CFG 0x4c /* GPIO Configuration */
70#define AC97_GPIO_POLARITY 0x4e /* GPIO Pin Polarity/Type, 0=low, 1=high active */
71#define AC97_GPIO_STICKY 0x50 /* GPIO Pin Sticky, 0=not, 1=sticky */
72#define AC97_GPIO_WAKEUP 0x52 /* GPIO Pin Wakeup, 0=no int, 1=yes int */
73#define AC97_GPIO_STATUS 0x54 /* GPIO Pin Status, slot 12 */
74#define AC97_MISC_AFE 0x56 /* Miscellaneous Modem AFE Status and Control */
75/* range 0x5a-0x7b - Vendor Specific */
76#define AC97_VENDOR_ID1 0x7c /* Vendor ID1 */
77#define AC97_VENDOR_ID2 0x7e /* Vendor ID2 / revision */
78/* range 0x60-0x6f (page 1) - extended codec registers */
79#define AC97_CODEC_CLASS_REV 0x60 /* Codec Class/Revision */
80#define AC97_PCI_SVID 0x62 /* PCI Subsystem Vendor ID */
81#define AC97_PCI_SID 0x64 /* PCI Subsystem ID */
82#define AC97_FUNC_SELECT 0x66 /* Function Select */
83#define AC97_FUNC_INFO 0x68 /* Function Information */
84#define AC97_SENSE_INFO 0x6a /* Sense Details */
85
86/* volume controls */
87#define AC97_MUTE_MASK_MONO 0x8000
88#define AC97_MUTE_MASK_STEREO 0x8080
89
90/* slot allocation */
91#define AC97_SLOT_TAG 0
92#define AC97_SLOT_CMD_ADDR 1
93#define AC97_SLOT_CMD_DATA 2
94#define AC97_SLOT_PCM_LEFT 3
95#define AC97_SLOT_PCM_RIGHT 4
96#define AC97_SLOT_MODEM_LINE1 5
97#define AC97_SLOT_PCM_CENTER 6
98#define AC97_SLOT_MIC 6 /* input */
99#define AC97_SLOT_SPDIF_LEFT1 6
100#define AC97_SLOT_PCM_SLEFT 7 /* surround left */
101#define AC97_SLOT_PCM_LEFT_0 7 /* double rate operation */
102#define AC97_SLOT_SPDIF_LEFT 7
103#define AC97_SLOT_PCM_SRIGHT 8 /* surround right */
104#define AC97_SLOT_PCM_RIGHT_0 8 /* double rate operation */
105#define AC97_SLOT_SPDIF_RIGHT 8
106#define AC97_SLOT_LFE 9
107#define AC97_SLOT_SPDIF_RIGHT1 9
108#define AC97_SLOT_MODEM_LINE2 10
109#define AC97_SLOT_PCM_LEFT_1 10 /* double rate operation */
110#define AC97_SLOT_SPDIF_LEFT2 10
111#define AC97_SLOT_HANDSET 11 /* output */
112#define AC97_SLOT_PCM_RIGHT_1 11 /* double rate operation */
113#define AC97_SLOT_SPDIF_RIGHT2 11
114#define AC97_SLOT_MODEM_GPIO 12 /* modem GPIO */
115#define AC97_SLOT_PCM_CENTER_1 12 /* double rate operation */
116
117/* basic capabilities (reset register) */
118#define AC97_BC_DEDICATED_MIC 0x0001 /* Dedicated Mic PCM In Channel */
119#define AC97_BC_RESERVED1 0x0002 /* Reserved (was Modem Line Codec support) */
120#define AC97_BC_BASS_TREBLE 0x0004 /* Bass & Treble Control */
121#define AC97_BC_SIM_STEREO 0x0008 /* Simulated stereo */
122#define AC97_BC_HEADPHONE 0x0010 /* Headphone Out Support */
123#define AC97_BC_LOUDNESS 0x0020 /* Loudness (bass boost) Support */
124#define AC97_BC_16BIT_DAC 0x0000 /* 16-bit DAC resolution */
125#define AC97_BC_18BIT_DAC 0x0040 /* 18-bit DAC resolution */
126#define AC97_BC_20BIT_DAC 0x0080 /* 20-bit DAC resolution */
127#define AC97_BC_DAC_MASK 0x00c0
128#define AC97_BC_16BIT_ADC 0x0000 /* 16-bit ADC resolution */
129#define AC97_BC_18BIT_ADC 0x0100 /* 18-bit ADC resolution */
130#define AC97_BC_20BIT_ADC 0x0200 /* 20-bit ADC resolution */
131#define AC97_BC_ADC_MASK 0x0300
132#define AC97_BC_3D_TECH_ID_MASK 0x7c00 /* Per-vendor ID of 3D enhancement */
133
134/* general purpose */
135#define AC97_GP_DRSS_MASK 0x0c00 /* double rate slot select */
136#define AC97_GP_DRSS_1011 0x0000 /* LR(C) 10+11(+12) */
137#define AC97_GP_DRSS_78 0x0400 /* LR 7+8 */
138
139/* powerdown bits */
140#define AC97_PD_ADC_STATUS 0x0001 /* ADC status (RO) */
141#define AC97_PD_DAC_STATUS 0x0002 /* DAC status (RO) */
142#define AC97_PD_MIXER_STATUS 0x0004 /* Analog mixer status (RO) */
143#define AC97_PD_VREF_STATUS 0x0008 /* Vref status (RO) */
144#define AC97_PD_PR0 0x0100 /* Power down PCM ADCs and input MUX */
145#define AC97_PD_PR1 0x0200 /* Power down PCM front DAC */
146#define AC97_PD_PR2 0x0400 /* Power down Mixer (Vref still on) */
147#define AC97_PD_PR3 0x0800 /* Power down Mixer (Vref off) */
148#define AC97_PD_PR4 0x1000 /* Power down AC-Link */
149#define AC97_PD_PR5 0x2000 /* Disable internal clock usage */
150#define AC97_PD_PR6 0x4000 /* Headphone amplifier */
151#define AC97_PD_EAPD 0x8000 /* External Amplifer Power Down (EAPD) */
152
153/* extended audio ID bit defines */
154#define AC97_EI_VRA 0x0001 /* Variable bit rate supported */
155#define AC97_EI_DRA 0x0002 /* Double rate supported */
156#define AC97_EI_SPDIF 0x0004 /* S/PDIF out supported */
157#define AC97_EI_VRM 0x0008 /* Variable bit rate supported for MIC */
158#define AC97_EI_DACS_SLOT_MASK 0x0030 /* DACs slot assignment */
159#define AC97_EI_DACS_SLOT_SHIFT 4
160#define AC97_EI_CDAC 0x0040 /* PCM Center DAC available */
161#define AC97_EI_SDAC 0x0080 /* PCM Surround DACs available */
162#define AC97_EI_LDAC 0x0100 /* PCM LFE DAC available */
163#define AC97_EI_AMAP 0x0200 /* indicates optional slot/DAC mapping based on codec ID */
164#define AC97_EI_REV_MASK 0x0c00 /* AC'97 revision mask */
165#define AC97_EI_REV_22 0x0400 /* AC'97 revision 2.2 */
166#define AC97_EI_REV_23 0x0800 /* AC'97 revision 2.3 */
167#define AC97_EI_REV_SHIFT 10
168#define AC97_EI_ADDR_MASK 0xc000 /* physical codec ID (address) */
169#define AC97_EI_ADDR_SHIFT 14
170
171/* extended audio status and control bit defines */
172#define AC97_EA_VRA 0x0001 /* Variable bit rate enable bit */
173#define AC97_EA_DRA 0x0002 /* Double-rate audio enable bit */
174#define AC97_EA_SPDIF 0x0004 /* S/PDIF out enable bit */
175#define AC97_EA_VRM 0x0008 /* Variable bit rate for MIC enable bit */
176#define AC97_EA_SPSA_SLOT_MASK 0x0030 /* Mask for slot assignment bits */
177#define AC97_EA_SPSA_SLOT_SHIFT 4
178#define AC97_EA_SPSA_3_4 0x0000 /* Slot assigned to 3 & 4 */
179#define AC97_EA_SPSA_7_8 0x0010 /* Slot assigned to 7 & 8 */
180#define AC97_EA_SPSA_6_9 0x0020 /* Slot assigned to 6 & 9 */
181#define AC97_EA_SPSA_10_11 0x0030 /* Slot assigned to 10 & 11 */
182#define AC97_EA_CDAC 0x0040 /* PCM Center DAC is ready (Read only) */
183#define AC97_EA_SDAC 0x0080 /* PCM Surround DACs are ready (Read only) */
184#define AC97_EA_LDAC 0x0100 /* PCM LFE DAC is ready (Read only) */
185#define AC97_EA_MDAC 0x0200 /* MIC ADC is ready (Read only) */
186#define AC97_EA_SPCV 0x0400 /* S/PDIF configuration valid (Read only) */
187#define AC97_EA_PRI 0x0800 /* Turns the PCM Center DAC off */
188#define AC97_EA_PRJ 0x1000 /* Turns the PCM Surround DACs off */
189#define AC97_EA_PRK 0x2000 /* Turns the PCM LFE DAC off */
190#define AC97_EA_PRL 0x4000 /* Turns the MIC ADC off */
191
192/* S/PDIF control bit defines */
193#define AC97_SC_PRO 0x0001 /* Professional status */
194#define AC97_SC_NAUDIO 0x0002 /* Non audio stream */
195#define AC97_SC_COPY 0x0004 /* Copyright status */
196#define AC97_SC_PRE 0x0008 /* Preemphasis status */
197#define AC97_SC_CC_MASK 0x07f0 /* Category Code mask */
198#define AC97_SC_CC_SHIFT 4
199#define AC97_SC_L 0x0800 /* Generation Level status */
200#define AC97_SC_SPSR_MASK 0x3000 /* S/PDIF Sample Rate bits */
201#define AC97_SC_SPSR_SHIFT 12
202#define AC97_SC_SPSR_44K 0x0000 /* Use 44.1kHz Sample rate */
203#define AC97_SC_SPSR_48K 0x2000 /* Use 48kHz Sample rate */
204#define AC97_SC_SPSR_32K 0x3000 /* Use 32kHz Sample rate */
205#define AC97_SC_DRS 0x4000 /* Double Rate S/PDIF */
206#define AC97_SC_V 0x8000 /* Validity status */
207
208/* Interrupt and Paging bit defines (AC'97 2.3) */
209#define AC97_PAGE_MASK 0x000f /* Page Selector */
210#define AC97_PAGE_VENDOR 0 /* Vendor-specific registers */
211#define AC97_PAGE_1 1 /* Extended Codec Registers page 1 */
212#define AC97_INT_ENABLE 0x0800 /* Interrupt Enable */
213#define AC97_INT_SENSE 0x1000 /* Sense Cycle */
214#define AC97_INT_CAUSE_SENSE 0x2000 /* Sense Cycle Completed (RO) */
215#define AC97_INT_CAUSE_GPIO 0x4000 /* GPIO bits changed (RO) */
216#define AC97_INT_STATUS 0x8000 /* Interrupt Status */
217
218/* extended modem ID bit defines */
219#define AC97_MEI_LINE1 0x0001 /* Line1 present */
220#define AC97_MEI_LINE2 0x0002 /* Line2 present */
221#define AC97_MEI_HANDSET 0x0004 /* Handset present */
222#define AC97_MEI_CID1 0x0008 /* caller ID decode for Line1 is supported */
223#define AC97_MEI_CID2 0x0010 /* caller ID decode for Line2 is supported */
224#define AC97_MEI_ADDR_MASK 0xc000 /* physical codec ID (address) */
225#define AC97_MEI_ADDR_SHIFT 14
226
227/* extended modem status and control bit defines */
228#define AC97_MEA_GPIO 0x0001 /* GPIO is ready (ro) */
229#define AC97_MEA_MREF 0x0002 /* Vref is up to nominal level (ro) */
230#define AC97_MEA_ADC1 0x0004 /* ADC1 operational (ro) */
231#define AC97_MEA_DAC1 0x0008 /* DAC1 operational (ro) */
232#define AC97_MEA_ADC2 0x0010 /* ADC2 operational (ro) */
233#define AC97_MEA_DAC2 0x0020 /* DAC2 operational (ro) */
234#define AC97_MEA_HADC 0x0040 /* HADC operational (ro) */
235#define AC97_MEA_HDAC 0x0080 /* HDAC operational (ro) */
236#define AC97_MEA_PRA 0x0100 /* GPIO power down (high) */
237#define AC97_MEA_PRB 0x0200 /* reserved */
238#define AC97_MEA_PRC 0x0400 /* ADC1 power down (high) */
239#define AC97_MEA_PRD 0x0800 /* DAC1 power down (high) */
240#define AC97_MEA_PRE 0x1000 /* ADC2 power down (high) */
241#define AC97_MEA_PRF 0x2000 /* DAC2 power down (high) */
242#define AC97_MEA_PRG 0x4000 /* HADC power down (high) */
243#define AC97_MEA_PRH 0x8000 /* HDAC power down (high) */
244
245/* modem gpio status defines */
246#define AC97_GPIO_LINE1_OH 0x0001 /* Off Hook Line1 */
247#define AC97_GPIO_LINE1_RI 0x0002 /* Ring Detect Line1 */
248#define AC97_GPIO_LINE1_CID 0x0004 /* Caller ID path enable Line1 */
249#define AC97_GPIO_LINE1_LCS 0x0008 /* Loop Current Sense Line1 */
250#define AC97_GPIO_LINE1_PULSE 0x0010 /* Opt./ Pulse Dial Line1 (out) */
251#define AC97_GPIO_LINE1_HL1R 0x0020 /* Opt./ Handset to Line1 relay control (out) */
252#define AC97_GPIO_LINE1_HOHD 0x0040 /* Opt./ Handset off hook detect Line1 (in) */
253#define AC97_GPIO_LINE12_AC 0x0080 /* Opt./ Int.bit 1 / Line1/2 AC (out) */
254#define AC97_GPIO_LINE12_DC 0x0100 /* Opt./ Int.bit 2 / Line1/2 DC (out) */
255#define AC97_GPIO_LINE12_RS 0x0200 /* Opt./ Int.bit 3 / Line1/2 RS (out) */
256#define AC97_GPIO_LINE2_OH 0x0400 /* Off Hook Line2 */
257#define AC97_GPIO_LINE2_RI 0x0800 /* Ring Detect Line2 */
258#define AC97_GPIO_LINE2_CID 0x1000 /* Caller ID path enable Line2 */
259#define AC97_GPIO_LINE2_LCS 0x2000 /* Loop Current Sense Line2 */
260#define AC97_GPIO_LINE2_PULSE 0x4000 /* Opt./ Pulse Dial Line2 (out) */
261#define AC97_GPIO_LINE2_HL1R 0x8000 /* Opt./ Handset to Line2 relay control (out) */
262
diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h
index 15aa5f07c955..89d311a503d3 100644
--- a/include/sound/ac97_codec.h
+++ b/include/sound/ac97_codec.h
@@ -28,6 +28,7 @@
28#include <linux/bitops.h> 28#include <linux/bitops.h>
29#include <linux/device.h> 29#include <linux/device.h>
30#include <linux/workqueue.h> 30#include <linux/workqueue.h>
31#include <sound/ac97/regs.h>
31#include <sound/pcm.h> 32#include <sound/pcm.h>
32#include <sound/control.h> 33#include <sound/control.h>
33#include <sound/info.h> 34#include <sound/info.h>
@@ -35,244 +36,6 @@
35/* maximum number of devices on the AC97 bus */ 36/* maximum number of devices on the AC97 bus */
36#define AC97_BUS_MAX_DEVICES 4 37#define AC97_BUS_MAX_DEVICES 4
37 38
38/*
39 * AC'97 codec registers
40 */
41
42#define AC97_RESET 0x00 /* Reset */
43#define AC97_MASTER 0x02 /* Master Volume */
44#define AC97_HEADPHONE 0x04 /* Headphone Volume (optional) */
45#define AC97_MASTER_MONO 0x06 /* Master Volume Mono (optional) */
46#define AC97_MASTER_TONE 0x08 /* Master Tone (Bass & Treble) (optional) */
47#define AC97_PC_BEEP 0x0a /* PC Beep Volume (optinal) */
48#define AC97_PHONE 0x0c /* Phone Volume (optional) */
49#define AC97_MIC 0x0e /* MIC Volume */
50#define AC97_LINE 0x10 /* Line In Volume */
51#define AC97_CD 0x12 /* CD Volume */
52#define AC97_VIDEO 0x14 /* Video Volume (optional) */
53#define AC97_AUX 0x16 /* AUX Volume (optional) */
54#define AC97_PCM 0x18 /* PCM Volume */
55#define AC97_REC_SEL 0x1a /* Record Select */
56#define AC97_REC_GAIN 0x1c /* Record Gain */
57#define AC97_REC_GAIN_MIC 0x1e /* Record Gain MIC (optional) */
58#define AC97_GENERAL_PURPOSE 0x20 /* General Purpose (optional) */
59#define AC97_3D_CONTROL 0x22 /* 3D Control (optional) */
60#define AC97_INT_PAGING 0x24 /* Audio Interrupt & Paging (AC'97 2.3) */
61#define AC97_POWERDOWN 0x26 /* Powerdown control / status */
62/* range 0x28-0x3a - AUDIO AC'97 2.0 extensions */
63#define AC97_EXTENDED_ID 0x28 /* Extended Audio ID */
64#define AC97_EXTENDED_STATUS 0x2a /* Extended Audio Status and Control */
65#define AC97_PCM_FRONT_DAC_RATE 0x2c /* PCM Front DAC Rate */
66#define AC97_PCM_SURR_DAC_RATE 0x2e /* PCM Surround DAC Rate */
67#define AC97_PCM_LFE_DAC_RATE 0x30 /* PCM LFE DAC Rate */
68#define AC97_PCM_LR_ADC_RATE 0x32 /* PCM LR ADC Rate */
69#define AC97_PCM_MIC_ADC_RATE 0x34 /* PCM MIC ADC Rate */
70#define AC97_CENTER_LFE_MASTER 0x36 /* Center + LFE Master Volume */
71#define AC97_SURROUND_MASTER 0x38 /* Surround (Rear) Master Volume */
72#define AC97_SPDIF 0x3a /* S/PDIF control */
73/* range 0x3c-0x58 - MODEM */
74#define AC97_EXTENDED_MID 0x3c /* Extended Modem ID */
75#define AC97_EXTENDED_MSTATUS 0x3e /* Extended Modem Status and Control */
76#define AC97_LINE1_RATE 0x40 /* Line1 DAC/ADC Rate */
77#define AC97_LINE2_RATE 0x42 /* Line2 DAC/ADC Rate */
78#define AC97_HANDSET_RATE 0x44 /* Handset DAC/ADC Rate */
79#define AC97_LINE1_LEVEL 0x46 /* Line1 DAC/ADC Level */
80#define AC97_LINE2_LEVEL 0x48 /* Line2 DAC/ADC Level */
81#define AC97_HANDSET_LEVEL 0x4a /* Handset DAC/ADC Level */
82#define AC97_GPIO_CFG 0x4c /* GPIO Configuration */
83#define AC97_GPIO_POLARITY 0x4e /* GPIO Pin Polarity/Type, 0=low, 1=high active */
84#define AC97_GPIO_STICKY 0x50 /* GPIO Pin Sticky, 0=not, 1=sticky */
85#define AC97_GPIO_WAKEUP 0x52 /* GPIO Pin Wakeup, 0=no int, 1=yes int */
86#define AC97_GPIO_STATUS 0x54 /* GPIO Pin Status, slot 12 */
87#define AC97_MISC_AFE 0x56 /* Miscellaneous Modem AFE Status and Control */
88/* range 0x5a-0x7b - Vendor Specific */
89#define AC97_VENDOR_ID1 0x7c /* Vendor ID1 */
90#define AC97_VENDOR_ID2 0x7e /* Vendor ID2 / revision */
91/* range 0x60-0x6f (page 1) - extended codec registers */
92#define AC97_CODEC_CLASS_REV 0x60 /* Codec Class/Revision */
93#define AC97_PCI_SVID 0x62 /* PCI Subsystem Vendor ID */
94#define AC97_PCI_SID 0x64 /* PCI Subsystem ID */
95#define AC97_FUNC_SELECT 0x66 /* Function Select */
96#define AC97_FUNC_INFO 0x68 /* Function Information */
97#define AC97_SENSE_INFO 0x6a /* Sense Details */
98
99/* volume controls */
100#define AC97_MUTE_MASK_MONO 0x8000
101#define AC97_MUTE_MASK_STEREO 0x8080
102
103/* slot allocation */
104#define AC97_SLOT_TAG 0
105#define AC97_SLOT_CMD_ADDR 1
106#define AC97_SLOT_CMD_DATA 2
107#define AC97_SLOT_PCM_LEFT 3
108#define AC97_SLOT_PCM_RIGHT 4
109#define AC97_SLOT_MODEM_LINE1 5
110#define AC97_SLOT_PCM_CENTER 6
111#define AC97_SLOT_MIC 6 /* input */
112#define AC97_SLOT_SPDIF_LEFT1 6
113#define AC97_SLOT_PCM_SLEFT 7 /* surround left */
114#define AC97_SLOT_PCM_LEFT_0 7 /* double rate operation */
115#define AC97_SLOT_SPDIF_LEFT 7
116#define AC97_SLOT_PCM_SRIGHT 8 /* surround right */
117#define AC97_SLOT_PCM_RIGHT_0 8 /* double rate operation */
118#define AC97_SLOT_SPDIF_RIGHT 8
119#define AC97_SLOT_LFE 9
120#define AC97_SLOT_SPDIF_RIGHT1 9
121#define AC97_SLOT_MODEM_LINE2 10
122#define AC97_SLOT_PCM_LEFT_1 10 /* double rate operation */
123#define AC97_SLOT_SPDIF_LEFT2 10
124#define AC97_SLOT_HANDSET 11 /* output */
125#define AC97_SLOT_PCM_RIGHT_1 11 /* double rate operation */
126#define AC97_SLOT_SPDIF_RIGHT2 11
127#define AC97_SLOT_MODEM_GPIO 12 /* modem GPIO */
128#define AC97_SLOT_PCM_CENTER_1 12 /* double rate operation */
129
130/* basic capabilities (reset register) */
131#define AC97_BC_DEDICATED_MIC 0x0001 /* Dedicated Mic PCM In Channel */
132#define AC97_BC_RESERVED1 0x0002 /* Reserved (was Modem Line Codec support) */
133#define AC97_BC_BASS_TREBLE 0x0004 /* Bass & Treble Control */
134#define AC97_BC_SIM_STEREO 0x0008 /* Simulated stereo */
135#define AC97_BC_HEADPHONE 0x0010 /* Headphone Out Support */
136#define AC97_BC_LOUDNESS 0x0020 /* Loudness (bass boost) Support */
137#define AC97_BC_16BIT_DAC 0x0000 /* 16-bit DAC resolution */
138#define AC97_BC_18BIT_DAC 0x0040 /* 18-bit DAC resolution */
139#define AC97_BC_20BIT_DAC 0x0080 /* 20-bit DAC resolution */
140#define AC97_BC_DAC_MASK 0x00c0
141#define AC97_BC_16BIT_ADC 0x0000 /* 16-bit ADC resolution */
142#define AC97_BC_18BIT_ADC 0x0100 /* 18-bit ADC resolution */
143#define AC97_BC_20BIT_ADC 0x0200 /* 20-bit ADC resolution */
144#define AC97_BC_ADC_MASK 0x0300
145#define AC97_BC_3D_TECH_ID_MASK 0x7c00 /* Per-vendor ID of 3D enhancement */
146
147/* general purpose */
148#define AC97_GP_DRSS_MASK 0x0c00 /* double rate slot select */
149#define AC97_GP_DRSS_1011 0x0000 /* LR(C) 10+11(+12) */
150#define AC97_GP_DRSS_78 0x0400 /* LR 7+8 */
151
152/* powerdown bits */
153#define AC97_PD_ADC_STATUS 0x0001 /* ADC status (RO) */
154#define AC97_PD_DAC_STATUS 0x0002 /* DAC status (RO) */
155#define AC97_PD_MIXER_STATUS 0x0004 /* Analog mixer status (RO) */
156#define AC97_PD_VREF_STATUS 0x0008 /* Vref status (RO) */
157#define AC97_PD_PR0 0x0100 /* Power down PCM ADCs and input MUX */
158#define AC97_PD_PR1 0x0200 /* Power down PCM front DAC */
159#define AC97_PD_PR2 0x0400 /* Power down Mixer (Vref still on) */
160#define AC97_PD_PR3 0x0800 /* Power down Mixer (Vref off) */
161#define AC97_PD_PR4 0x1000 /* Power down AC-Link */
162#define AC97_PD_PR5 0x2000 /* Disable internal clock usage */
163#define AC97_PD_PR6 0x4000 /* Headphone amplifier */
164#define AC97_PD_EAPD 0x8000 /* External Amplifer Power Down (EAPD) */
165
166/* extended audio ID bit defines */
167#define AC97_EI_VRA 0x0001 /* Variable bit rate supported */
168#define AC97_EI_DRA 0x0002 /* Double rate supported */
169#define AC97_EI_SPDIF 0x0004 /* S/PDIF out supported */
170#define AC97_EI_VRM 0x0008 /* Variable bit rate supported for MIC */
171#define AC97_EI_DACS_SLOT_MASK 0x0030 /* DACs slot assignment */
172#define AC97_EI_DACS_SLOT_SHIFT 4
173#define AC97_EI_CDAC 0x0040 /* PCM Center DAC available */
174#define AC97_EI_SDAC 0x0080 /* PCM Surround DACs available */
175#define AC97_EI_LDAC 0x0100 /* PCM LFE DAC available */
176#define AC97_EI_AMAP 0x0200 /* indicates optional slot/DAC mapping based on codec ID */
177#define AC97_EI_REV_MASK 0x0c00 /* AC'97 revision mask */
178#define AC97_EI_REV_22 0x0400 /* AC'97 revision 2.2 */
179#define AC97_EI_REV_23 0x0800 /* AC'97 revision 2.3 */
180#define AC97_EI_REV_SHIFT 10
181#define AC97_EI_ADDR_MASK 0xc000 /* physical codec ID (address) */
182#define AC97_EI_ADDR_SHIFT 14
183
184/* extended audio status and control bit defines */
185#define AC97_EA_VRA 0x0001 /* Variable bit rate enable bit */
186#define AC97_EA_DRA 0x0002 /* Double-rate audio enable bit */
187#define AC97_EA_SPDIF 0x0004 /* S/PDIF out enable bit */
188#define AC97_EA_VRM 0x0008 /* Variable bit rate for MIC enable bit */
189#define AC97_EA_SPSA_SLOT_MASK 0x0030 /* Mask for slot assignment bits */
190#define AC97_EA_SPSA_SLOT_SHIFT 4
191#define AC97_EA_SPSA_3_4 0x0000 /* Slot assigned to 3 & 4 */
192#define AC97_EA_SPSA_7_8 0x0010 /* Slot assigned to 7 & 8 */
193#define AC97_EA_SPSA_6_9 0x0020 /* Slot assigned to 6 & 9 */
194#define AC97_EA_SPSA_10_11 0x0030 /* Slot assigned to 10 & 11 */
195#define AC97_EA_CDAC 0x0040 /* PCM Center DAC is ready (Read only) */
196#define AC97_EA_SDAC 0x0080 /* PCM Surround DACs are ready (Read only) */
197#define AC97_EA_LDAC 0x0100 /* PCM LFE DAC is ready (Read only) */
198#define AC97_EA_MDAC 0x0200 /* MIC ADC is ready (Read only) */
199#define AC97_EA_SPCV 0x0400 /* S/PDIF configuration valid (Read only) */
200#define AC97_EA_PRI 0x0800 /* Turns the PCM Center DAC off */
201#define AC97_EA_PRJ 0x1000 /* Turns the PCM Surround DACs off */
202#define AC97_EA_PRK 0x2000 /* Turns the PCM LFE DAC off */
203#define AC97_EA_PRL 0x4000 /* Turns the MIC ADC off */
204
205/* S/PDIF control bit defines */
206#define AC97_SC_PRO 0x0001 /* Professional status */
207#define AC97_SC_NAUDIO 0x0002 /* Non audio stream */
208#define AC97_SC_COPY 0x0004 /* Copyright status */
209#define AC97_SC_PRE 0x0008 /* Preemphasis status */
210#define AC97_SC_CC_MASK 0x07f0 /* Category Code mask */
211#define AC97_SC_CC_SHIFT 4
212#define AC97_SC_L 0x0800 /* Generation Level status */
213#define AC97_SC_SPSR_MASK 0x3000 /* S/PDIF Sample Rate bits */
214#define AC97_SC_SPSR_SHIFT 12
215#define AC97_SC_SPSR_44K 0x0000 /* Use 44.1kHz Sample rate */
216#define AC97_SC_SPSR_48K 0x2000 /* Use 48kHz Sample rate */
217#define AC97_SC_SPSR_32K 0x3000 /* Use 32kHz Sample rate */
218#define AC97_SC_DRS 0x4000 /* Double Rate S/PDIF */
219#define AC97_SC_V 0x8000 /* Validity status */
220
221/* Interrupt and Paging bit defines (AC'97 2.3) */
222#define AC97_PAGE_MASK 0x000f /* Page Selector */
223#define AC97_PAGE_VENDOR 0 /* Vendor-specific registers */
224#define AC97_PAGE_1 1 /* Extended Codec Registers page 1 */
225#define AC97_INT_ENABLE 0x0800 /* Interrupt Enable */
226#define AC97_INT_SENSE 0x1000 /* Sense Cycle */
227#define AC97_INT_CAUSE_SENSE 0x2000 /* Sense Cycle Completed (RO) */
228#define AC97_INT_CAUSE_GPIO 0x4000 /* GPIO bits changed (RO) */
229#define AC97_INT_STATUS 0x8000 /* Interrupt Status */
230
231/* extended modem ID bit defines */
232#define AC97_MEI_LINE1 0x0001 /* Line1 present */
233#define AC97_MEI_LINE2 0x0002 /* Line2 present */
234#define AC97_MEI_HANDSET 0x0004 /* Handset present */
235#define AC97_MEI_CID1 0x0008 /* caller ID decode for Line1 is supported */
236#define AC97_MEI_CID2 0x0010 /* caller ID decode for Line2 is supported */
237#define AC97_MEI_ADDR_MASK 0xc000 /* physical codec ID (address) */
238#define AC97_MEI_ADDR_SHIFT 14
239
240/* extended modem status and control bit defines */
241#define AC97_MEA_GPIO 0x0001 /* GPIO is ready (ro) */
242#define AC97_MEA_MREF 0x0002 /* Vref is up to nominal level (ro) */
243#define AC97_MEA_ADC1 0x0004 /* ADC1 operational (ro) */
244#define AC97_MEA_DAC1 0x0008 /* DAC1 operational (ro) */
245#define AC97_MEA_ADC2 0x0010 /* ADC2 operational (ro) */
246#define AC97_MEA_DAC2 0x0020 /* DAC2 operational (ro) */
247#define AC97_MEA_HADC 0x0040 /* HADC operational (ro) */
248#define AC97_MEA_HDAC 0x0080 /* HDAC operational (ro) */
249#define AC97_MEA_PRA 0x0100 /* GPIO power down (high) */
250#define AC97_MEA_PRB 0x0200 /* reserved */
251#define AC97_MEA_PRC 0x0400 /* ADC1 power down (high) */
252#define AC97_MEA_PRD 0x0800 /* DAC1 power down (high) */
253#define AC97_MEA_PRE 0x1000 /* ADC2 power down (high) */
254#define AC97_MEA_PRF 0x2000 /* DAC2 power down (high) */
255#define AC97_MEA_PRG 0x4000 /* HADC power down (high) */
256#define AC97_MEA_PRH 0x8000 /* HDAC power down (high) */
257
258/* modem gpio status defines */
259#define AC97_GPIO_LINE1_OH 0x0001 /* Off Hook Line1 */
260#define AC97_GPIO_LINE1_RI 0x0002 /* Ring Detect Line1 */
261#define AC97_GPIO_LINE1_CID 0x0004 /* Caller ID path enable Line1 */
262#define AC97_GPIO_LINE1_LCS 0x0008 /* Loop Current Sense Line1 */
263#define AC97_GPIO_LINE1_PULSE 0x0010 /* Opt./ Pulse Dial Line1 (out) */
264#define AC97_GPIO_LINE1_HL1R 0x0020 /* Opt./ Handset to Line1 relay control (out) */
265#define AC97_GPIO_LINE1_HOHD 0x0040 /* Opt./ Handset off hook detect Line1 (in) */
266#define AC97_GPIO_LINE12_AC 0x0080 /* Opt./ Int.bit 1 / Line1/2 AC (out) */
267#define AC97_GPIO_LINE12_DC 0x0100 /* Opt./ Int.bit 2 / Line1/2 DC (out) */
268#define AC97_GPIO_LINE12_RS 0x0200 /* Opt./ Int.bit 3 / Line1/2 RS (out) */
269#define AC97_GPIO_LINE2_OH 0x0400 /* Off Hook Line2 */
270#define AC97_GPIO_LINE2_RI 0x0800 /* Ring Detect Line2 */
271#define AC97_GPIO_LINE2_CID 0x1000 /* Caller ID path enable Line2 */
272#define AC97_GPIO_LINE2_LCS 0x2000 /* Loop Current Sense Line2 */
273#define AC97_GPIO_LINE2_PULSE 0x4000 /* Opt./ Pulse Dial Line2 (out) */
274#define AC97_GPIO_LINE2_HL1R 0x8000 /* Opt./ Handset to Line2 relay control (out) */
275
276/* specific - SigmaTel */ 39/* specific - SigmaTel */
277#define AC97_SIGMATEL_OUTSEL 0x64 /* Output Select, STAC9758 */ 40#define AC97_SIGMATEL_OUTSEL 0x64 /* Output Select, STAC9758 */
278#define AC97_SIGMATEL_INSEL 0x66 /* Input Select, STAC9758 */ 41#define AC97_SIGMATEL_INSEL 0x66 /* Input Select, STAC9758 */
diff --git a/include/sound/core.h b/include/sound/core.h
index 4104a9d1001f..5f181b875c2f 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -133,6 +133,7 @@ struct snd_card {
133 struct device card_dev; /* cardX object for sysfs */ 133 struct device card_dev; /* cardX object for sysfs */
134 const struct attribute_group *dev_groups[4]; /* assigned sysfs attr */ 134 const struct attribute_group *dev_groups[4]; /* assigned sysfs attr */
135 bool registered; /* card_dev is registered? */ 135 bool registered; /* card_dev is registered? */
136 wait_queue_head_t remove_sleep;
136 137
137#ifdef CONFIG_PM 138#ifdef CONFIG_PM
138 unsigned int power_state; /* power state */ 139 unsigned int power_state; /* power state */
@@ -240,6 +241,7 @@ int snd_card_new(struct device *parent, int idx, const char *xid,
240 struct snd_card **card_ret); 241 struct snd_card **card_ret);
241 242
242int snd_card_disconnect(struct snd_card *card); 243int snd_card_disconnect(struct snd_card *card);
244void snd_card_disconnect_sync(struct snd_card *card);
243int snd_card_free(struct snd_card *card); 245int snd_card_free(struct snd_card *card);
244int snd_card_free_when_closed(struct snd_card *card); 246int snd_card_free_when_closed(struct snd_card *card);
245void snd_card_set_id(struct snd_card *card, const char *id); 247void snd_card_set_id(struct snd_card *card, const char *id);
diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h
index d8afd8a5bd76..68169e3749de 100644
--- a/include/sound/hdaudio.h
+++ b/include/sound/hdaudio.h
@@ -112,8 +112,7 @@ void snd_hdac_device_unregister(struct hdac_device *codec);
112int snd_hdac_device_set_chip_name(struct hdac_device *codec, const char *name); 112int snd_hdac_device_set_chip_name(struct hdac_device *codec, const char *name);
113int snd_hdac_codec_modalias(struct hdac_device *hdac, char *buf, size_t size); 113int snd_hdac_codec_modalias(struct hdac_device *hdac, char *buf, size_t size);
114 114
115int snd_hdac_refresh_widgets(struct hdac_device *codec); 115int snd_hdac_refresh_widgets(struct hdac_device *codec, bool sysfs);
116int snd_hdac_refresh_widget_sysfs(struct hdac_device *codec);
117 116
118unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid, 117unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid,
119 unsigned int verb, unsigned int parm); 118 unsigned int verb, unsigned int parm);
diff --git a/include/sound/pxa2xx-lib.h b/include/sound/pxa2xx-lib.h
index 5e710d848bd3..63f75450d3db 100644
--- a/include/sound/pxa2xx-lib.h
+++ b/include/sound/pxa2xx-lib.h
@@ -2,10 +2,13 @@
2#ifndef PXA2XX_LIB_H 2#ifndef PXA2XX_LIB_H
3#define PXA2XX_LIB_H 3#define PXA2XX_LIB_H
4 4
5#include <uapi/sound/asound.h>
5#include <linux/platform_device.h> 6#include <linux/platform_device.h>
6#include <sound/ac97_codec.h>
7 7
8/* PCM */ 8/* PCM */
9struct snd_pcm_substream;
10struct snd_pcm_hw_params;
11struct snd_pcm;
9 12
10extern int __pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream, 13extern int __pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream,
11 struct snd_pcm_hw_params *params); 14 struct snd_pcm_hw_params *params);
@@ -22,12 +25,12 @@ extern void pxa2xx_pcm_free_dma_buffers(struct snd_pcm *pcm);
22 25
23/* AC97 */ 26/* AC97 */
24 27
25extern unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg); 28extern int pxa2xx_ac97_read(int slot, unsigned short reg);
26extern void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val); 29extern int pxa2xx_ac97_write(int slot, unsigned short reg, unsigned short val);
27 30
28extern bool pxa2xx_ac97_try_warm_reset(struct snd_ac97 *ac97); 31extern bool pxa2xx_ac97_try_warm_reset(void);
29extern bool pxa2xx_ac97_try_cold_reset(struct snd_ac97 *ac97); 32extern bool pxa2xx_ac97_try_cold_reset(void);
30extern void pxa2xx_ac97_finish_reset(struct snd_ac97 *ac97); 33extern void pxa2xx_ac97_finish_reset(void);
31 34
32extern int pxa2xx_ac97_hw_suspend(void); 35extern int pxa2xx_ac97_hw_suspend(void);
33extern int pxa2xx_ac97_hw_resume(void); 36extern int pxa2xx_ac97_hw_resume(void);
diff --git a/include/sound/rt5651.h b/include/sound/rt5651.h
index d35de758dfb5..18b79a761f10 100644
--- a/include/sound/rt5651.h
+++ b/include/sound/rt5651.h
@@ -11,11 +11,19 @@
11#ifndef __LINUX_SND_RT5651_H 11#ifndef __LINUX_SND_RT5651_H
12#define __LINUX_SND_RT5651_H 12#define __LINUX_SND_RT5651_H
13 13
14enum rt5651_jd_src {
15 RT5651_JD_NULL,
16 RT5651_JD1_1,
17 RT5651_JD1_2,
18 RT5651_JD2,
19};
20
14struct rt5651_platform_data { 21struct rt5651_platform_data {
15 /* IN2 can optionally be differential */ 22 /* IN2 can optionally be differential */
16 bool in2_diff; 23 bool in2_diff;
17 24
18 bool dmic_en; 25 bool dmic_en;
26 enum rt5651_jd_src jd_src;
19}; 27};
20 28
21#endif 29#endif
diff --git a/include/sound/rt5663.h b/include/sound/rt5663.h
index 7d00e5849706..7b90a8f1034c 100644
--- a/include/sound/rt5663.h
+++ b/include/sound/rt5663.h
@@ -16,6 +16,9 @@ struct rt5663_platform_data {
16 unsigned int dc_offset_r_manual; 16 unsigned int dc_offset_r_manual;
17 unsigned int dc_offset_l_manual_mic; 17 unsigned int dc_offset_l_manual_mic;
18 unsigned int dc_offset_r_manual_mic; 18 unsigned int dc_offset_r_manual_mic;
19
20 unsigned int impedance_sensing_num;
21 unsigned int *impedance_sensing_table;
19}; 22};
20 23
21#endif 24#endif
diff --git a/include/sound/snd_wavefront.h b/include/sound/snd_wavefront.h
index 6231eb57361f..55053557c898 100644
--- a/include/sound/snd_wavefront.h
+++ b/include/sound/snd_wavefront.h
@@ -29,6 +29,7 @@ struct _snd_wavefront_midi {
29 struct snd_rawmidi_substream *substream_output[2]; 29 struct snd_rawmidi_substream *substream_output[2];
30 struct snd_rawmidi_substream *substream_input[2]; 30 struct snd_rawmidi_substream *substream_input[2];
31 struct timer_list timer; 31 struct timer_list timer;
32 snd_wavefront_card_t *timer_card;
32 spinlock_t open; 33 spinlock_t open;
33 spinlock_t virtual; /* protects isvirtual */ 34 spinlock_t virtual; /* protects isvirtual */
34}; 35};
diff --git a/include/sound/soc-acpi-intel-match.h b/include/sound/soc-acpi-intel-match.h
new file mode 100644
index 000000000000..1a9191cd4bb3
--- /dev/null
+++ b/include/sound/soc-acpi-intel-match.h
@@ -0,0 +1,32 @@
1
2/*
3 * Copyright (C) 2017, Intel Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version
7 * 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15
16#ifndef __LINUX_SND_SOC_ACPI_INTEL_MATCH_H
17#define __LINUX_SND_SOC_ACPI_INTEL_MATCH_H
18
19#include <linux/stddef.h>
20#include <linux/acpi.h>
21
22/*
23 * these tables are not constants, some fields can be used for
24 * pdata or machine ops
25 */
26extern struct snd_soc_acpi_mach snd_soc_acpi_intel_haswell_machines[];
27extern struct snd_soc_acpi_mach snd_soc_acpi_intel_broadwell_machines[];
28extern struct snd_soc_acpi_mach snd_soc_acpi_intel_baytrail_legacy_machines[];
29extern struct snd_soc_acpi_mach snd_soc_acpi_intel_baytrail_machines[];
30extern struct snd_soc_acpi_mach snd_soc_acpi_intel_cherrytrail_machines[];
31
32#endif
diff --git a/include/sound/soc-acpi.h b/include/sound/soc-acpi.h
new file mode 100644
index 000000000000..a7d8d335b043
--- /dev/null
+++ b/include/sound/soc-acpi.h
@@ -0,0 +1,111 @@
1/*
2 * Copyright (C) 2013-15, Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License version
6 * 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
15#ifndef __LINUX_SND_SOC_ACPI_H
16#define __LINUX_SND_SOC_ACPI_H
17
18#include <linux/stddef.h>
19#include <linux/acpi.h>
20
21struct snd_soc_acpi_package_context {
22 char *name; /* package name */
23 int length; /* number of elements */
24 struct acpi_buffer *format;
25 struct acpi_buffer *state;
26 bool data_valid;
27};
28
29#if IS_ENABLED(CONFIG_ACPI)
30/* translation fron HID to I2C name, needed for DAI codec_name */
31const char *snd_soc_acpi_find_name_from_hid(const u8 hid[ACPI_ID_LEN]);
32bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
33 struct snd_soc_acpi_package_context *ctx);
34#else
35static inline const char *
36snd_soc_acpi_find_name_from_hid(const u8 hid[ACPI_ID_LEN])
37{
38 return NULL;
39}
40static inline bool
41snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
42 struct snd_soc_acpi_package_context *ctx)
43{
44 return false;
45}
46#endif
47
48/* acpi match */
49struct snd_soc_acpi_mach *
50snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines);
51
52/* acpi check hid */
53bool snd_soc_acpi_check_hid(const u8 hid[ACPI_ID_LEN]);
54
55/**
56 * snd_soc_acpi_mach: ACPI-based machine descriptor. Most of the fields are
57 * related to the hardware, except for the firmware and topology file names.
58 * A platform supported by legacy and Sound Open Firmware (SOF) would expose
59 * all firmware/topology related fields.
60 *
61 * @id: ACPI ID (usually the codec's) used to find a matching machine driver.
62 * @drv_name: machine driver name
63 * @fw_filename: firmware file name. Used when SOF is not enabled.
64 * @board: board name
65 * @machine_quirk: pointer to quirk, usually based on DMI information when
66 * ACPI ID alone is not sufficient, wrong or misleading
67 * @quirk_data: data used to uniquely identify a machine, usually a list of
68 * audio codecs whose presence if checked with ACPI
69 * @pdata: intended for platform data or machine specific-ops. This structure
70 * is not constant since this field may be updated at run-time
71 * @sof_fw_filename: Sound Open Firmware file name, if enabled
72 * @sof_tplg_filename: Sound Open Firmware topology file name, if enabled
73 * @asoc_plat_name: ASoC platform name, used for binding machine drivers
74 * if non NULL
75 * @new_mach_data: machine driver private data fixup
76 */
77/* Descriptor for SST ASoC machine driver */
78struct snd_soc_acpi_mach {
79 const u8 id[ACPI_ID_LEN];
80 const char *drv_name;
81 const char *fw_filename;
82 const char *board;
83 struct snd_soc_acpi_mach * (*machine_quirk)(void *arg);
84 const void *quirk_data;
85 void *pdata;
86 const char *sof_fw_filename;
87 const char *sof_tplg_filename;
88 const char *asoc_plat_name;
89 struct platform_device * (*new_mach_data)(void *pdata);
90};
91
92#define SND_SOC_ACPI_MAX_CODECS 3
93
94/**
95 * struct snd_soc_acpi_codecs: Structure to hold secondary codec information
96 * apart from the matched one, this data will be passed to the quirk function
97 * to match with the ACPI detected devices
98 *
99 * @num_codecs: number of secondary codecs used in the platform
100 * @codecs: holds the codec IDs
101 *
102 */
103struct snd_soc_acpi_codecs {
104 int num_codecs;
105 u8 codecs[SND_SOC_ACPI_MAX_CODECS][ACPI_ID_LEN];
106};
107
108/* check all codecs */
109struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg);
110
111#endif
diff --git a/include/sound/soc.h b/include/sound/soc.h
index d22de9712c45..1a7323238c49 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -468,6 +468,11 @@ int snd_soc_register_codec(struct device *dev,
468 const struct snd_soc_codec_driver *codec_drv, 468 const struct snd_soc_codec_driver *codec_drv,
469 struct snd_soc_dai_driver *dai_drv, int num_dai); 469 struct snd_soc_dai_driver *dai_drv, int num_dai);
470void snd_soc_unregister_codec(struct device *dev); 470void snd_soc_unregister_codec(struct device *dev);
471int snd_soc_add_component(struct device *dev,
472 struct snd_soc_component *component,
473 const struct snd_soc_component_driver *component_driver,
474 struct snd_soc_dai_driver *dai_drv,
475 int num_dai);
471int snd_soc_register_component(struct device *dev, 476int snd_soc_register_component(struct device *dev,
472 const struct snd_soc_component_driver *component_driver, 477 const struct snd_soc_component_driver *component_driver,
473 struct snd_soc_dai_driver *dai_drv, int num_dai); 478 struct snd_soc_dai_driver *dai_drv, int num_dai);
@@ -475,6 +480,8 @@ int devm_snd_soc_register_component(struct device *dev,
475 const struct snd_soc_component_driver *component_driver, 480 const struct snd_soc_component_driver *component_driver,
476 struct snd_soc_dai_driver *dai_drv, int num_dai); 481 struct snd_soc_dai_driver *dai_drv, int num_dai);
477void snd_soc_unregister_component(struct device *dev); 482void snd_soc_unregister_component(struct device *dev);
483struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
484 const char *driver_name);
478int snd_soc_cache_init(struct snd_soc_codec *codec); 485int snd_soc_cache_init(struct snd_soc_codec *codec);
479int snd_soc_cache_exit(struct snd_soc_codec *codec); 486int snd_soc_cache_exit(struct snd_soc_codec *codec);
480 487
@@ -795,6 +802,10 @@ struct snd_soc_component_driver {
795 int (*suspend)(struct snd_soc_component *); 802 int (*suspend)(struct snd_soc_component *);
796 int (*resume)(struct snd_soc_component *); 803 int (*resume)(struct snd_soc_component *);
797 804
805 /* pcm creation and destruction */
806 int (*pcm_new)(struct snd_soc_pcm_runtime *);
807 void (*pcm_free)(struct snd_pcm *);
808
798 /* component wide operations */ 809 /* component wide operations */
799 int (*set_sysclk)(struct snd_soc_component *component, 810 int (*set_sysclk)(struct snd_soc_component *component,
800 int clk_id, int source, unsigned int freq, int dir); 811 int clk_id, int source, unsigned int freq, int dir);
@@ -812,10 +823,22 @@ struct snd_soc_component_driver {
812 void (*seq_notifier)(struct snd_soc_component *, enum snd_soc_dapm_type, 823 void (*seq_notifier)(struct snd_soc_component *, enum snd_soc_dapm_type,
813 int subseq); 824 int subseq);
814 int (*stream_event)(struct snd_soc_component *, int event); 825 int (*stream_event)(struct snd_soc_component *, int event);
826 int (*set_bias_level)(struct snd_soc_component *component,
827 enum snd_soc_bias_level level);
828
829 const struct snd_pcm_ops *ops;
830 const struct snd_compr_ops *compr_ops;
815 831
816 /* probe ordering - for components with runtime dependencies */ 832 /* probe ordering - for components with runtime dependencies */
817 int probe_order; 833 int probe_order;
818 int remove_order; 834 int remove_order;
835
836 /* bits */
837 unsigned int idle_bias_on:1;
838 unsigned int suspend_bias_off:1;
839 unsigned int pmdown_time:1; /* care pmdown_time at stop */
840 unsigned int endianness:1;
841 unsigned int non_legacy_dai_naming:1;
819}; 842};
820 843
821struct snd_soc_component { 844struct snd_soc_component {
@@ -872,6 +895,8 @@ struct snd_soc_component {
872 void (*remove)(struct snd_soc_component *); 895 void (*remove)(struct snd_soc_component *);
873 int (*suspend)(struct snd_soc_component *); 896 int (*suspend)(struct snd_soc_component *);
874 int (*resume)(struct snd_soc_component *); 897 int (*resume)(struct snd_soc_component *);
898 int (*pcm_new)(struct snd_soc_component *, struct snd_soc_pcm_runtime *);
899 void (*pcm_free)(struct snd_soc_component *, struct snd_pcm *);
875 900
876 int (*set_sysclk)(struct snd_soc_component *component, 901 int (*set_sysclk)(struct snd_soc_component *component,
877 int clk_id, int source, unsigned int freq, int dir); 902 int clk_id, int source, unsigned int freq, int dir);
@@ -879,6 +904,8 @@ struct snd_soc_component {
879 int source, unsigned int freq_in, unsigned int freq_out); 904 int source, unsigned int freq_in, unsigned int freq_out);
880 int (*set_jack)(struct snd_soc_component *component, 905 int (*set_jack)(struct snd_soc_component *component,
881 struct snd_soc_jack *jack, void *data); 906 struct snd_soc_jack *jack, void *data);
907 int (*set_bias_level)(struct snd_soc_component *component,
908 enum snd_soc_bias_level level);
882 909
883 /* machine specific init */ 910 /* machine specific init */
884 int (*init)(struct snd_soc_component *component); 911 int (*init)(struct snd_soc_component *component);
@@ -1413,6 +1440,21 @@ static inline void snd_soc_codec_init_bias_level(struct snd_soc_codec *codec,
1413} 1440}
1414 1441
1415/** 1442/**
1443 * snd_soc_component_init_bias_level() - Initialize COMPONENT DAPM bias level
1444 * @component: The COMPONENT for which to initialize the DAPM bias level
1445 * @level: The DAPM level to initialize to
1446 *
1447 * Initializes the COMPONENT DAPM bias level. See snd_soc_dapm_init_bias_level().
1448 */
1449static inline void
1450snd_soc_component_init_bias_level(struct snd_soc_component *component,
1451 enum snd_soc_bias_level level)
1452{
1453 snd_soc_dapm_init_bias_level(
1454 snd_soc_component_get_dapm(component), level);
1455}
1456
1457/**
1416 * snd_soc_dapm_get_bias_level() - Get current CODEC DAPM bias level 1458 * snd_soc_dapm_get_bias_level() - Get current CODEC DAPM bias level
1417 * @codec: The CODEC for which to get the DAPM bias level 1459 * @codec: The CODEC for which to get the DAPM bias level
1418 * 1460 *
@@ -1425,6 +1467,19 @@ static inline enum snd_soc_bias_level snd_soc_codec_get_bias_level(
1425} 1467}
1426 1468
1427/** 1469/**
1470 * snd_soc_component_get_bias_level() - Get current COMPONENT DAPM bias level
1471 * @component: The COMPONENT for which to get the DAPM bias level
1472 *
1473 * Returns: The current DAPM bias level of the COMPONENT.
1474 */
1475static inline enum snd_soc_bias_level
1476snd_soc_component_get_bias_level(struct snd_soc_component *component)
1477{
1478 return snd_soc_dapm_get_bias_level(
1479 snd_soc_component_get_dapm(component));
1480}
1481
1482/**
1428 * snd_soc_codec_force_bias_level() - Set the CODEC DAPM bias level 1483 * snd_soc_codec_force_bias_level() - Set the CODEC DAPM bias level
1429 * @codec: The CODEC for which to set the level 1484 * @codec: The CODEC for which to set the level
1430 * @level: The level to set to 1485 * @level: The level to set to
@@ -1440,6 +1495,23 @@ static inline int snd_soc_codec_force_bias_level(struct snd_soc_codec *codec,
1440} 1495}
1441 1496
1442/** 1497/**
1498 * snd_soc_component_force_bias_level() - Set the COMPONENT DAPM bias level
1499 * @component: The COMPONENT for which to set the level
1500 * @level: The level to set to
1501 *
1502 * Forces the COMPONENT bias level to a specific state. See
1503 * snd_soc_dapm_force_bias_level().
1504 */
1505static inline int
1506snd_soc_component_force_bias_level(struct snd_soc_component *component,
1507 enum snd_soc_bias_level level)
1508{
1509 return snd_soc_dapm_force_bias_level(
1510 snd_soc_component_get_dapm(component),
1511 level);
1512}
1513
1514/**
1443 * snd_soc_dapm_kcontrol_codec() - Returns the codec associated to a kcontrol 1515 * snd_soc_dapm_kcontrol_codec() - Returns the codec associated to a kcontrol
1444 * @kcontrol: The kcontrol 1516 * @kcontrol: The kcontrol
1445 * 1517 *
@@ -1452,6 +1524,19 @@ static inline struct snd_soc_codec *snd_soc_dapm_kcontrol_codec(
1452 return snd_soc_dapm_to_codec(snd_soc_dapm_kcontrol_dapm(kcontrol)); 1524 return snd_soc_dapm_to_codec(snd_soc_dapm_kcontrol_dapm(kcontrol));
1453} 1525}
1454 1526
1527/**
1528 * snd_soc_dapm_kcontrol_component() - Returns the component associated to a kcontrol
1529 * @kcontrol: The kcontrol
1530 *
1531 * This function must only be used on DAPM contexts that are known to be part of
1532 * a COMPONENT (e.g. in a COMPONENT driver). Otherwise the behavior is undefined.
1533 */
1534static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
1535 struct snd_kcontrol *kcontrol)
1536{
1537 return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
1538}
1539
1455/* codec IO */ 1540/* codec IO */
1456unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg); 1541unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
1457int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg, 1542int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg,
@@ -1468,9 +1553,23 @@ static inline int snd_soc_cache_sync(struct snd_soc_codec *codec)
1468 return regcache_sync(codec->component.regmap); 1553 return regcache_sync(codec->component.regmap);
1469} 1554}
1470 1555
1556/**
1557 * snd_soc_component_cache_sync() - Sync the register cache with the hardware
1558 * @component: COMPONENT to sync
1559 *
1560 * Note: This function will call regcache_sync()
1561 */
1562static inline int snd_soc_component_cache_sync(
1563 struct snd_soc_component *component)
1564{
1565 return regcache_sync(component->regmap);
1566}
1567
1471/* component IO */ 1568/* component IO */
1472int snd_soc_component_read(struct snd_soc_component *component, 1569int snd_soc_component_read(struct snd_soc_component *component,
1473 unsigned int reg, unsigned int *val); 1570 unsigned int reg, unsigned int *val);
1571unsigned int snd_soc_component_read32(struct snd_soc_component *component,
1572 unsigned int reg);
1474int snd_soc_component_write(struct snd_soc_component *component, 1573int snd_soc_component_write(struct snd_soc_component *component,
1475 unsigned int reg, unsigned int val); 1574 unsigned int reg, unsigned int val);
1476int snd_soc_component_update_bits(struct snd_soc_component *component, 1575int snd_soc_component_update_bits(struct snd_soc_component *component,
@@ -1487,6 +1586,8 @@ int snd_soc_component_set_sysclk(struct snd_soc_component *component,
1487int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id, 1586int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
1488 int source, unsigned int freq_in, 1587 int source, unsigned int freq_in,
1489 unsigned int freq_out); 1588 unsigned int freq_out);
1589int snd_soc_component_set_jack(struct snd_soc_component *component,
1590 struct snd_soc_jack *jack, void *data);
1490 1591
1491#ifdef CONFIG_REGMAP 1592#ifdef CONFIG_REGMAP
1492 1593
@@ -1720,6 +1821,20 @@ struct snd_soc_dai *snd_soc_find_dai(
1720 1821
1721#include <sound/soc-dai.h> 1822#include <sound/soc-dai.h>
1722 1823
1824static inline
1825struct snd_soc_dai *snd_soc_card_get_codec_dai(struct snd_soc_card *card,
1826 const char *dai_name)
1827{
1828 struct snd_soc_pcm_runtime *rtd;
1829
1830 list_for_each_entry(rtd, &card->rtd_list, list) {
1831 if (!strcmp(rtd->codec_dai->name, dai_name))
1832 return rtd->codec_dai;
1833 }
1834
1835 return NULL;
1836}
1837
1723#ifdef CONFIG_DEBUG_FS 1838#ifdef CONFIG_DEBUG_FS
1724extern struct dentry *snd_soc_debugfs_root; 1839extern struct dentry *snd_soc_debugfs_root;
1725#endif 1840#endif
diff --git a/sound/Kconfig b/sound/Kconfig
index d7d2aac9542e..6833db9002ec 100644
--- a/sound/Kconfig
+++ b/sound/Kconfig
@@ -3,25 +3,7 @@ menuconfig SOUND
3 depends on HAS_IOMEM 3 depends on HAS_IOMEM
4 help 4 help
5 If you have a sound card in your computer, i.e. if it can say more 5 If you have a sound card in your computer, i.e. if it can say more
6 than an occasional beep, say Y. Be sure to have all the information 6 than an occasional beep, say Y.
7 about your sound card and its configuration down (I/O port,
8 interrupt and DMA channel), because you will be asked for it.
9
10 You want to read the Sound-HOWTO, available from
11 <http://www.tldp.org/docs.html#howto>. General information about
12 the modular sound system is contained in the files
13 <file:Documentation/sound/oss/Introduction>. The file
14 <file:Documentation/sound/oss/README.OSS> contains some slightly
15 outdated but still useful information as well. Newer sound
16 driver documentation is found in <file:Documentation/sound/alsa/*>.
17
18 If you have a PnP sound card and you want to configure it at boot
19 time using the ISA PnP tools (read
20 <http://www.roestock.demon.co.uk/isapnptools/>), then you need to
21 compile the sound card support as a module and load that module
22 after the PnP configuration is finished. To do this, choose M here
23 and read <file:Documentation/sound/oss/README.modules>; the module
24 will be called soundcore.
25 7
26if SOUND 8if SOUND
27 9
@@ -80,6 +62,8 @@ source "sound/hda/Kconfig"
80 62
81source "sound/ppc/Kconfig" 63source "sound/ppc/Kconfig"
82 64
65source "sound/ac97/Kconfig"
66
83source "sound/aoa/Kconfig" 67source "sound/aoa/Kconfig"
84 68
85source "sound/arm/Kconfig" 69source "sound/arm/Kconfig"
@@ -114,19 +98,6 @@ source "sound/synth/Kconfig"
114 98
115endif # SND 99endif # SND
116 100
117menuconfig SOUND_PRIME
118 tristate "Open Sound System (DEPRECATED)"
119 select SOUND_OSS_CORE
120 depends on BROKEN
121 help
122 Say 'Y' or 'M' to enable Open Sound System drivers.
123
124if SOUND_PRIME
125
126source "sound/oss/Kconfig"
127
128endif # SOUND_PRIME
129
130endif # !UML 101endif # !UML
131 102
132endif # SOUND 103endif # SOUND
diff --git a/sound/Makefile b/sound/Makefile
index f2d1d093bcdc..99d8c31262c8 100644
--- a/sound/Makefile
+++ b/sound/Makefile
@@ -3,14 +3,14 @@
3# 3#
4 4
5obj-$(CONFIG_SOUND) += soundcore.o 5obj-$(CONFIG_SOUND) += soundcore.o
6obj-$(CONFIG_SOUND_PRIME) += oss/ 6obj-$(CONFIG_DMASOUND) += oss/dmasound/
7obj-$(CONFIG_DMASOUND) += oss/
8obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \ 7obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \
9 firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ hda/ x86/ 8 firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ hda/ x86/
10obj-$(CONFIG_SND_AOA) += aoa/ 9obj-$(CONFIG_SND_AOA) += aoa/
11 10
12# This one must be compilable even if sound is configured out 11# This one must be compilable even if sound is configured out
13obj-$(CONFIG_AC97_BUS) += ac97_bus.o 12obj-$(CONFIG_AC97_BUS) += ac97_bus.o
13obj-$(CONFIG_AC97_BUS_NEW) += ac97/
14 14
15ifeq ($(CONFIG_SND),y) 15ifeq ($(CONFIG_SND),y)
16 obj-y += last.o 16 obj-y += last.o
diff --git a/sound/ac97/Kconfig b/sound/ac97/Kconfig
new file mode 100644
index 000000000000..f8a64e15e5bf
--- /dev/null
+++ b/sound/ac97/Kconfig
@@ -0,0 +1,19 @@
1#
2# AC97 configuration
3#
4
5
6config AC97_BUS_NEW
7 tristate
8 select AC97
9 help
10 This is the new AC97 bus type, successor of AC97_BUS. The ported
11 drivers which benefit from the AC97 automatic probing should "select"
12 this instead of the AC97_BUS.
13 Say Y here if you want to have AC97 devices, which are sound oriented
14 devices around an AC-Link.
15
16config AC97_BUS_COMPAT
17 bool
18 depends on AC97_BUS_NEW
19 depends on !AC97_BUS
diff --git a/sound/ac97/Makefile b/sound/ac97/Makefile
new file mode 100644
index 000000000000..f9c2640bfb59
--- /dev/null
+++ b/sound/ac97/Makefile
@@ -0,0 +1,8 @@
1#
2# make for AC97 bus drivers
3#
4
5obj-$(CONFIG_AC97_BUS_NEW) += ac97.o
6
7ac97-y += bus.o codec.o
8ac97-$(CONFIG_AC97_BUS_COMPAT) += snd_ac97_compat.o
diff --git a/sound/ac97/ac97_core.h b/sound/ac97/ac97_core.h
new file mode 100644
index 000000000000..08441a4fda7c
--- /dev/null
+++ b/sound/ac97/ac97_core.h
@@ -0,0 +1,16 @@
1/*
2 * Copyright (C) 2016 Robert Jarzmik <robert.jarzmik@free.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9unsigned int snd_ac97_bus_scan_one(struct ac97_controller *ac97,
10 unsigned int codec_num);
11
12static inline bool ac97_ids_match(unsigned int id1, unsigned int id2,
13 unsigned int mask)
14{
15 return (id1 & mask) == (id2 & mask);
16}
diff --git a/sound/ac97/bus.c b/sound/ac97/bus.c
new file mode 100644
index 000000000000..31f858eceffc
--- /dev/null
+++ b/sound/ac97/bus.c
@@ -0,0 +1,539 @@
1/*
2 * Copyright (C) 2016 Robert Jarzmik <robert.jarzmik@free.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/module.h>
10#include <linux/bitops.h>
11#include <linux/clk.h>
12#include <linux/device.h>
13#include <linux/idr.h>
14#include <linux/list.h>
15#include <linux/mutex.h>
16#include <linux/pm.h>
17#include <linux/pm_runtime.h>
18#include <linux/slab.h>
19#include <linux/sysfs.h>
20#include <sound/ac97/codec.h>
21#include <sound/ac97/controller.h>
22#include <sound/ac97/regs.h>
23
24#include "ac97_core.h"
25
26/*
27 * Protects ac97_controllers and each ac97_controller structure.
28 */
29static DEFINE_MUTEX(ac97_controllers_mutex);
30static DEFINE_IDR(ac97_adapter_idr);
31static LIST_HEAD(ac97_controllers);
32
33static struct bus_type ac97_bus_type;
34
35static inline struct ac97_controller*
36to_ac97_controller(struct device *ac97_adapter)
37{
38 return container_of(ac97_adapter, struct ac97_controller, adap);
39}
40
41static int ac97_unbound_ctrl_write(struct ac97_controller *adrv, int slot,
42 unsigned short reg, unsigned short val)
43{
44 return -ENODEV;
45}
46
47static int ac97_unbound_ctrl_read(struct ac97_controller *adrv, int slot,
48 unsigned short reg)
49{
50 return -ENODEV;
51}
52
53static const struct ac97_controller_ops ac97_unbound_ctrl_ops = {
54 .write = ac97_unbound_ctrl_write,
55 .read = ac97_unbound_ctrl_read,
56};
57
58static struct ac97_controller ac97_unbound_ctrl = {
59 .ops = &ac97_unbound_ctrl_ops,
60};
61
62static struct ac97_codec_device *
63ac97_codec_find(struct ac97_controller *ac97_ctrl, unsigned int codec_num)
64{
65 if (codec_num >= AC97_BUS_MAX_CODECS)
66 return ERR_PTR(-EINVAL);
67
68 return ac97_ctrl->codecs[codec_num];
69}
70
71static void ac97_codec_release(struct device *dev)
72{
73 struct ac97_codec_device *adev;
74 struct ac97_controller *ac97_ctrl;
75
76 adev = to_ac97_device(dev);
77 ac97_ctrl = adev->ac97_ctrl;
78 ac97_ctrl->codecs[adev->num] = NULL;
79 kfree(adev);
80}
81
82static int ac97_codec_add(struct ac97_controller *ac97_ctrl, int idx,
83 unsigned int vendor_id)
84{
85 struct ac97_codec_device *codec;
86 int ret;
87
88 codec = kzalloc(sizeof(*codec), GFP_KERNEL);
89 if (!codec)
90 return -ENOMEM;
91 ac97_ctrl->codecs[idx] = codec;
92 codec->vendor_id = vendor_id;
93 codec->dev.release = ac97_codec_release;
94 codec->dev.bus = &ac97_bus_type;
95 codec->dev.parent = &ac97_ctrl->adap;
96 codec->num = idx;
97 codec->ac97_ctrl = ac97_ctrl;
98
99 device_initialize(&codec->dev);
100 dev_set_name(&codec->dev, "%s:%u", dev_name(ac97_ctrl->parent), idx);
101
102 ret = device_add(&codec->dev);
103 if (ret)
104 goto err_free_codec;
105
106 return 0;
107err_free_codec:
108 put_device(&codec->dev);
109 kfree(codec);
110 ac97_ctrl->codecs[idx] = NULL;
111
112 return ret;
113}
114
115unsigned int snd_ac97_bus_scan_one(struct ac97_controller *adrv,
116 unsigned int codec_num)
117{
118 unsigned short vid1, vid2;
119 int ret;
120
121 ret = adrv->ops->read(adrv, codec_num, AC97_VENDOR_ID1);
122 vid1 = (ret & 0xffff);
123 if (ret < 0)
124 return 0;
125
126 ret = adrv->ops->read(adrv, codec_num, AC97_VENDOR_ID2);
127 vid2 = (ret & 0xffff);
128 if (ret < 0)
129 return 0;
130
131 dev_dbg(&adrv->adap, "%s(codec_num=%u): vendor_id=0x%08x\n",
132 __func__, codec_num, AC97_ID(vid1, vid2));
133 return AC97_ID(vid1, vid2);
134}
135
136static int ac97_bus_scan(struct ac97_controller *ac97_ctrl)
137{
138 int ret, i;
139 unsigned int vendor_id;
140
141 for (i = 0; i < AC97_BUS_MAX_CODECS; i++) {
142 if (ac97_codec_find(ac97_ctrl, i))
143 continue;
144 if (!(ac97_ctrl->slots_available & BIT(i)))
145 continue;
146 vendor_id = snd_ac97_bus_scan_one(ac97_ctrl, i);
147 if (!vendor_id)
148 continue;
149
150 ret = ac97_codec_add(ac97_ctrl, i, vendor_id);
151 if (ret < 0)
152 return ret;
153 }
154 return 0;
155}
156
157static int ac97_bus_reset(struct ac97_controller *ac97_ctrl)
158{
159 ac97_ctrl->ops->reset(ac97_ctrl);
160
161 return 0;
162}
163
164/**
165 * snd_ac97_codec_driver_register - register an AC97 codec driver
166 * @dev: AC97 driver codec to register
167 *
168 * Register an AC97 codec driver to the ac97 bus driver, aka. the AC97 digital
169 * controller.
170 *
171 * Returns 0 on success or error code
172 */
173int snd_ac97_codec_driver_register(struct ac97_codec_driver *drv)
174{
175 drv->driver.bus = &ac97_bus_type;
176 return driver_register(&drv->driver);
177}
178EXPORT_SYMBOL_GPL(snd_ac97_codec_driver_register);
179
180/**
181 * snd_ac97_codec_driver_unregister - unregister an AC97 codec driver
182 * @dev: AC97 codec driver to unregister
183 *
184 * Unregister a previously registered ac97 codec driver.
185 */
186void snd_ac97_codec_driver_unregister(struct ac97_codec_driver *drv)
187{
188 driver_unregister(&drv->driver);
189}
190EXPORT_SYMBOL_GPL(snd_ac97_codec_driver_unregister);
191
192/**
193 * snd_ac97_codec_get_platdata - get platform_data
194 * @adev: the ac97 codec device
195 *
196 * For legacy platforms, in order to have platform_data in codec drivers
197 * available, while ac97 device are auto-created upon probe, this retrieves the
198 * platdata which was setup on ac97 controller registration.
199 *
200 * Returns the platform data pointer
201 */
202void *snd_ac97_codec_get_platdata(const struct ac97_codec_device *adev)
203{
204 struct ac97_controller *ac97_ctrl = adev->ac97_ctrl;
205
206 return ac97_ctrl->codecs_pdata[adev->num];
207}
208EXPORT_SYMBOL_GPL(snd_ac97_codec_get_platdata);
209
210static void ac97_ctrl_codecs_unregister(struct ac97_controller *ac97_ctrl)
211{
212 int i;
213
214 for (i = 0; i < AC97_BUS_MAX_CODECS; i++)
215 if (ac97_ctrl->codecs[i]) {
216 ac97_ctrl->codecs[i]->ac97_ctrl = &ac97_unbound_ctrl;
217 device_unregister(&ac97_ctrl->codecs[i]->dev);
218 }
219}
220
221static ssize_t cold_reset_store(struct device *dev,
222 struct device_attribute *attr, const char *buf,
223 size_t len)
224{
225 struct ac97_controller *ac97_ctrl;
226
227 mutex_lock(&ac97_controllers_mutex);
228 ac97_ctrl = to_ac97_controller(dev);
229 ac97_ctrl->ops->reset(ac97_ctrl);
230 mutex_unlock(&ac97_controllers_mutex);
231 return len;
232}
233static DEVICE_ATTR_WO(cold_reset);
234
235static ssize_t warm_reset_store(struct device *dev,
236 struct device_attribute *attr, const char *buf,
237 size_t len)
238{
239 struct ac97_controller *ac97_ctrl;
240
241 if (!dev)
242 return -ENODEV;
243
244 mutex_lock(&ac97_controllers_mutex);
245 ac97_ctrl = to_ac97_controller(dev);
246 ac97_ctrl->ops->warm_reset(ac97_ctrl);
247 mutex_unlock(&ac97_controllers_mutex);
248 return len;
249}
250static DEVICE_ATTR_WO(warm_reset);
251
252static struct attribute *ac97_controller_device_attrs[] = {
253 &dev_attr_cold_reset.attr,
254 &dev_attr_warm_reset.attr,
255 NULL
256};
257
258static struct attribute_group ac97_adapter_attr_group = {
259 .name = "ac97_operations",
260 .attrs = ac97_controller_device_attrs,
261};
262
263static const struct attribute_group *ac97_adapter_groups[] = {
264 &ac97_adapter_attr_group,
265 NULL,
266};
267
268static void ac97_del_adapter(struct ac97_controller *ac97_ctrl)
269{
270 mutex_lock(&ac97_controllers_mutex);
271 ac97_ctrl_codecs_unregister(ac97_ctrl);
272 list_del(&ac97_ctrl->controllers);
273 mutex_unlock(&ac97_controllers_mutex);
274
275 device_unregister(&ac97_ctrl->adap);
276}
277
278static void ac97_adapter_release(struct device *dev)
279{
280 struct ac97_controller *ac97_ctrl;
281
282 ac97_ctrl = to_ac97_controller(dev);
283 idr_remove(&ac97_adapter_idr, ac97_ctrl->nr);
284 dev_dbg(&ac97_ctrl->adap, "adapter unregistered by %s\n",
285 dev_name(ac97_ctrl->parent));
286}
287
288static const struct device_type ac97_adapter_type = {
289 .groups = ac97_adapter_groups,
290 .release = ac97_adapter_release,
291};
292
293static int ac97_add_adapter(struct ac97_controller *ac97_ctrl)
294{
295 int ret;
296
297 mutex_lock(&ac97_controllers_mutex);
298 ret = idr_alloc(&ac97_adapter_idr, ac97_ctrl, 0, 0, GFP_KERNEL);
299 ac97_ctrl->nr = ret;
300 if (ret >= 0) {
301 dev_set_name(&ac97_ctrl->adap, "ac97-%d", ret);
302 ac97_ctrl->adap.type = &ac97_adapter_type;
303 ac97_ctrl->adap.parent = ac97_ctrl->parent;
304 ret = device_register(&ac97_ctrl->adap);
305 if (ret)
306 put_device(&ac97_ctrl->adap);
307 }
308 if (!ret)
309 list_add(&ac97_ctrl->controllers, &ac97_controllers);
310 mutex_unlock(&ac97_controllers_mutex);
311
312 if (!ret)
313 dev_dbg(&ac97_ctrl->adap, "adapter registered by %s\n",
314 dev_name(ac97_ctrl->parent));
315 return ret;
316}
317
318/**
319 * snd_ac97_controller_register - register an ac97 controller
320 * @ops: the ac97 bus operations
321 * @dev: the device providing the ac97 DC function
322 * @slots_available: mask of the ac97 codecs that can be scanned and probed
323 * bit0 => codec 0, bit1 => codec 1 ... bit 3 => codec 3
324 *
325 * Register a digital controller which can control up to 4 ac97 codecs. This is
326 * the controller side of the AC97 AC-link, while the slave side are the codecs.
327 *
328 * Returns a valid controller upon success, negative pointer value upon error
329 */
330struct ac97_controller *snd_ac97_controller_register(
331 const struct ac97_controller_ops *ops, struct device *dev,
332 unsigned short slots_available, void **codecs_pdata)
333{
334 struct ac97_controller *ac97_ctrl;
335 int ret, i;
336
337 ac97_ctrl = kzalloc(sizeof(*ac97_ctrl), GFP_KERNEL);
338 if (!ac97_ctrl)
339 return ERR_PTR(-ENOMEM);
340
341 for (i = 0; i < AC97_BUS_MAX_CODECS && codecs_pdata; i++)
342 ac97_ctrl->codecs_pdata[i] = codecs_pdata[i];
343
344 ac97_ctrl->ops = ops;
345 ac97_ctrl->slots_available = slots_available;
346 ac97_ctrl->parent = dev;
347 ret = ac97_add_adapter(ac97_ctrl);
348
349 if (ret)
350 goto err;
351 ac97_bus_reset(ac97_ctrl);
352 ac97_bus_scan(ac97_ctrl);
353
354 return ac97_ctrl;
355err:
356 kfree(ac97_ctrl);
357 return ERR_PTR(ret);
358}
359EXPORT_SYMBOL_GPL(snd_ac97_controller_register);
360
361/**
362 * snd_ac97_controller_unregister - unregister an ac97 controller
363 * @ac97_ctrl: the device previously provided to ac97_controller_register()
364 *
365 */
366void snd_ac97_controller_unregister(struct ac97_controller *ac97_ctrl)
367{
368 ac97_del_adapter(ac97_ctrl);
369}
370EXPORT_SYMBOL_GPL(snd_ac97_controller_unregister);
371
372#ifdef CONFIG_PM
373static int ac97_pm_runtime_suspend(struct device *dev)
374{
375 struct ac97_codec_device *codec = to_ac97_device(dev);
376 int ret = pm_generic_runtime_suspend(dev);
377
378 if (ret == 0 && dev->driver) {
379 if (pm_runtime_is_irq_safe(dev))
380 clk_disable(codec->clk);
381 else
382 clk_disable_unprepare(codec->clk);
383 }
384
385 return ret;
386}
387
388static int ac97_pm_runtime_resume(struct device *dev)
389{
390 struct ac97_codec_device *codec = to_ac97_device(dev);
391 int ret;
392
393 if (dev->driver) {
394 if (pm_runtime_is_irq_safe(dev))
395 ret = clk_enable(codec->clk);
396 else
397 ret = clk_prepare_enable(codec->clk);
398 if (ret)
399 return ret;
400 }
401
402 return pm_generic_runtime_resume(dev);
403}
404#endif /* CONFIG_PM */
405
406static const struct dev_pm_ops ac97_pm = {
407 .suspend = pm_generic_suspend,
408 .resume = pm_generic_resume,
409 .freeze = pm_generic_freeze,
410 .thaw = pm_generic_thaw,
411 .poweroff = pm_generic_poweroff,
412 .restore = pm_generic_restore,
413 SET_RUNTIME_PM_OPS(
414 ac97_pm_runtime_suspend,
415 ac97_pm_runtime_resume,
416 NULL)
417};
418
419static int ac97_get_enable_clk(struct ac97_codec_device *adev)
420{
421 int ret;
422
423 adev->clk = clk_get(&adev->dev, "ac97_clk");
424 if (IS_ERR(adev->clk))
425 return PTR_ERR(adev->clk);
426
427 ret = clk_prepare_enable(adev->clk);
428 if (ret)
429 clk_put(adev->clk);
430
431 return ret;
432}
433
434static void ac97_put_disable_clk(struct ac97_codec_device *adev)
435{
436 clk_disable_unprepare(adev->clk);
437 clk_put(adev->clk);
438}
439
440static ssize_t vendor_id_show(struct device *dev,
441 struct device_attribute *attr, char *buf)
442{
443 struct ac97_codec_device *codec = to_ac97_device(dev);
444
445 return sprintf(buf, "%08x", codec->vendor_id);
446}
447DEVICE_ATTR_RO(vendor_id);
448
449static struct attribute *ac97_dev_attrs[] = {
450 &dev_attr_vendor_id.attr,
451 NULL,
452};
453ATTRIBUTE_GROUPS(ac97_dev);
454
455static int ac97_bus_match(struct device *dev, struct device_driver *drv)
456{
457 struct ac97_codec_device *adev = to_ac97_device(dev);
458 struct ac97_codec_driver *adrv = to_ac97_driver(drv);
459 const struct ac97_id *id = adrv->id_table;
460 int i = 0;
461
462 if (adev->vendor_id == 0x0 || adev->vendor_id == 0xffffffff)
463 return false;
464
465 do {
466 if (ac97_ids_match(id[i].id, adev->vendor_id, id[i].mask))
467 return true;
468 } while (id[i++].id);
469
470 return false;
471}
472
473static int ac97_bus_probe(struct device *dev)
474{
475 struct ac97_codec_device *adev = to_ac97_device(dev);
476 struct ac97_codec_driver *adrv = to_ac97_driver(dev->driver);
477 int ret;
478
479 ret = ac97_get_enable_clk(adev);
480 if (ret)
481 return ret;
482
483 pm_runtime_get_noresume(dev);
484 pm_runtime_set_active(dev);
485 pm_runtime_enable(dev);
486
487 ret = adrv->probe(adev);
488 if (ret == 0)
489 return 0;
490
491 pm_runtime_disable(dev);
492 pm_runtime_set_suspended(dev);
493 pm_runtime_put_noidle(dev);
494 ac97_put_disable_clk(adev);
495
496 return ret;
497}
498
499static int ac97_bus_remove(struct device *dev)
500{
501 struct ac97_codec_device *adev = to_ac97_device(dev);
502 struct ac97_codec_driver *adrv = to_ac97_driver(dev->driver);
503 int ret;
504
505 ret = pm_runtime_get_sync(dev);
506 if (ret)
507 return ret;
508
509 ret = adrv->remove(adev);
510 pm_runtime_put_noidle(dev);
511 if (ret == 0)
512 ac97_put_disable_clk(adev);
513
514 return ret;
515}
516
517static struct bus_type ac97_bus_type = {
518 .name = "ac97bus",
519 .dev_groups = ac97_dev_groups,
520 .match = ac97_bus_match,
521 .pm = &ac97_pm,
522 .probe = ac97_bus_probe,
523 .remove = ac97_bus_remove,
524};
525
526static int __init ac97_bus_init(void)
527{
528 return bus_register(&ac97_bus_type);
529}
530subsys_initcall(ac97_bus_init);
531
532static void __exit ac97_bus_exit(void)
533{
534 bus_unregister(&ac97_bus_type);
535}
536module_exit(ac97_bus_exit);
537
538MODULE_LICENSE("GPL");
539MODULE_AUTHOR("Robert Jarzmik <robert.jarzmik@free.fr>");
diff --git a/sound/ac97/codec.c b/sound/ac97/codec.c
new file mode 100644
index 000000000000..a835f03744bf
--- /dev/null
+++ b/sound/ac97/codec.c
@@ -0,0 +1,15 @@
1/*
2 * Copyright (C) 2016 Robert Jarzmik <robert.jarzmik@free.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <sound/ac97_codec.h>
10#include <sound/ac97/codec.h>
11#include <sound/ac97/controller.h>
12#include <linux/device.h>
13#include <linux/slab.h>
14#include <sound/soc.h> /* For compat_ac97_* */
15
diff --git a/sound/ac97/snd_ac97_compat.c b/sound/ac97/snd_ac97_compat.c
new file mode 100644
index 000000000000..61544e0d8de4
--- /dev/null
+++ b/sound/ac97/snd_ac97_compat.c
@@ -0,0 +1,108 @@
1/*
2 * Copyright (C) 2016 Robert Jarzmik <robert.jarzmik@free.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/list.h>
10#include <linux/slab.h>
11#include <sound/ac97/codec.h>
12#include <sound/ac97/compat.h>
13#include <sound/ac97/controller.h>
14#include <sound/soc.h>
15
16#include "ac97_core.h"
17
18static void compat_ac97_reset(struct snd_ac97 *ac97)
19{
20 struct ac97_codec_device *adev = to_ac97_device(ac97->private_data);
21 struct ac97_controller *actrl = adev->ac97_ctrl;
22
23 if (actrl->ops->reset)
24 actrl->ops->reset(actrl);
25}
26
27static void compat_ac97_warm_reset(struct snd_ac97 *ac97)
28{
29 struct ac97_codec_device *adev = to_ac97_device(ac97->private_data);
30 struct ac97_controller *actrl = adev->ac97_ctrl;
31
32 if (actrl->ops->warm_reset)
33 actrl->ops->warm_reset(actrl);
34}
35
36static void compat_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
37 unsigned short val)
38{
39 struct ac97_codec_device *adev = to_ac97_device(ac97->private_data);
40 struct ac97_controller *actrl = adev->ac97_ctrl;
41
42 actrl->ops->write(actrl, ac97->num, reg, val);
43}
44
45static unsigned short compat_ac97_read(struct snd_ac97 *ac97,
46 unsigned short reg)
47{
48 struct ac97_codec_device *adev = to_ac97_device(ac97->private_data);
49 struct ac97_controller *actrl = adev->ac97_ctrl;
50
51 return actrl->ops->read(actrl, ac97->num, reg);
52}
53
54static struct snd_ac97_bus_ops compat_snd_ac97_bus_ops = {
55 .reset = compat_ac97_reset,
56 .warm_reset = compat_ac97_warm_reset,
57 .write = compat_ac97_write,
58 .read = compat_ac97_read,
59};
60
61static struct snd_ac97_bus compat_soc_ac97_bus = {
62 .ops = &compat_snd_ac97_bus_ops,
63};
64
65struct snd_ac97 *snd_ac97_compat_alloc(struct ac97_codec_device *adev)
66{
67 struct snd_ac97 *ac97;
68
69 ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
70 if (ac97 == NULL)
71 return ERR_PTR(-ENOMEM);
72
73 ac97->dev = adev->dev;
74 ac97->private_data = adev;
75 ac97->bus = &compat_soc_ac97_bus;
76 return ac97;
77}
78EXPORT_SYMBOL_GPL(snd_ac97_compat_alloc);
79
80void snd_ac97_compat_release(struct snd_ac97 *ac97)
81{
82 kfree(ac97);
83}
84EXPORT_SYMBOL_GPL(snd_ac97_compat_release);
85
86int snd_ac97_reset(struct snd_ac97 *ac97, bool try_warm, unsigned int id,
87 unsigned int id_mask)
88{
89 struct ac97_codec_device *adev = to_ac97_device(ac97->private_data);
90 struct ac97_controller *actrl = adev->ac97_ctrl;
91 unsigned int scanned;
92
93 if (try_warm) {
94 compat_ac97_warm_reset(ac97);
95 scanned = snd_ac97_bus_scan_one(actrl, adev->num);
96 if (ac97_ids_match(scanned, adev->vendor_id, id_mask))
97 return 1;
98 }
99
100 compat_ac97_reset(ac97);
101 compat_ac97_warm_reset(ac97);
102 scanned = snd_ac97_bus_scan_one(actrl, adev->num);
103 if (ac97_ids_match(scanned, adev->vendor_id, id_mask))
104 return 0;
105
106 return -ENODEV;
107}
108EXPORT_SYMBOL_GPL(snd_ac97_reset);
diff --git a/sound/arm/pxa2xx-ac97-lib.c b/sound/arm/pxa2xx-ac97-lib.c
index 39c3969ac1c7..5950a9e218d9 100644
--- a/sound/arm/pxa2xx-ac97-lib.c
+++ b/sound/arm/pxa2xx-ac97-lib.c
@@ -20,7 +20,6 @@
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/gpio.h> 21#include <linux/gpio.h>
22 22
23#include <sound/ac97_codec.h>
24#include <sound/pxa2xx-lib.h> 23#include <sound/pxa2xx-lib.h>
25 24
26#include <mach/irqs.h> 25#include <mach/irqs.h>
@@ -46,38 +45,41 @@ extern void pxa27x_configure_ac97reset(int reset_gpio, bool to_gpio);
46 * 1 jiffy timeout if interrupt never comes). 45 * 1 jiffy timeout if interrupt never comes).
47 */ 46 */
48 47
49unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg) 48int pxa2xx_ac97_read(int slot, unsigned short reg)
50{ 49{
51 unsigned short val = -1; 50 int val = -ENODEV;
52 volatile u32 *reg_addr; 51 volatile u32 *reg_addr;
53 52
53 if (slot > 0)
54 return -ENODEV;
55
54 mutex_lock(&car_mutex); 56 mutex_lock(&car_mutex);
55 57
56 /* set up primary or secondary codec space */ 58 /* set up primary or secondary codec space */
57 if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS) 59 if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS)
58 reg_addr = ac97->num ? &SMC_REG_BASE : &PMC_REG_BASE; 60 reg_addr = slot ? &SMC_REG_BASE : &PMC_REG_BASE;
59 else 61 else
60 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE; 62 reg_addr = slot ? &SAC_REG_BASE : &PAC_REG_BASE;
61 reg_addr += (reg >> 1); 63 reg_addr += (reg >> 1);
62 64
63 /* start read access across the ac97 link */ 65 /* start read access across the ac97 link */
64 GSR = GSR_CDONE | GSR_SDONE; 66 GSR = GSR_CDONE | GSR_SDONE;
65 gsr_bits = 0; 67 gsr_bits = 0;
66 val = *reg_addr; 68 val = (*reg_addr & 0xffff);
67 if (reg == AC97_GPIO_STATUS) 69 if (reg == AC97_GPIO_STATUS)
68 goto out; 70 goto out;
69 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 && 71 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 &&
70 !((GSR | gsr_bits) & GSR_SDONE)) { 72 !((GSR | gsr_bits) & GSR_SDONE)) {
71 printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n", 73 printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n",
72 __func__, reg, GSR | gsr_bits); 74 __func__, reg, GSR | gsr_bits);
73 val = -1; 75 val = -ETIMEDOUT;
74 goto out; 76 goto out;
75 } 77 }
76 78
77 /* valid data now */ 79 /* valid data now */
78 GSR = GSR_CDONE | GSR_SDONE; 80 GSR = GSR_CDONE | GSR_SDONE;
79 gsr_bits = 0; 81 gsr_bits = 0;
80 val = *reg_addr; 82 val = (*reg_addr & 0xffff);
81 /* but we've just started another cycle... */ 83 /* but we've just started another cycle... */
82 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1); 84 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1);
83 85
@@ -86,29 +88,32 @@ out: mutex_unlock(&car_mutex);
86} 88}
87EXPORT_SYMBOL_GPL(pxa2xx_ac97_read); 89EXPORT_SYMBOL_GPL(pxa2xx_ac97_read);
88 90
89void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, 91int pxa2xx_ac97_write(int slot, unsigned short reg, unsigned short val)
90 unsigned short val)
91{ 92{
92 volatile u32 *reg_addr; 93 volatile u32 *reg_addr;
94 int ret = 0;
93 95
94 mutex_lock(&car_mutex); 96 mutex_lock(&car_mutex);
95 97
96 /* set up primary or secondary codec space */ 98 /* set up primary or secondary codec space */
97 if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS) 99 if (cpu_is_pxa25x() && reg == AC97_GPIO_STATUS)
98 reg_addr = ac97->num ? &SMC_REG_BASE : &PMC_REG_BASE; 100 reg_addr = slot ? &SMC_REG_BASE : &PMC_REG_BASE;
99 else 101 else
100 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE; 102 reg_addr = slot ? &SAC_REG_BASE : &PAC_REG_BASE;
101 reg_addr += (reg >> 1); 103 reg_addr += (reg >> 1);
102 104
103 GSR = GSR_CDONE | GSR_SDONE; 105 GSR = GSR_CDONE | GSR_SDONE;
104 gsr_bits = 0; 106 gsr_bits = 0;
105 *reg_addr = val; 107 *reg_addr = val;
106 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 && 108 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 &&
107 !((GSR | gsr_bits) & GSR_CDONE)) 109 !((GSR | gsr_bits) & GSR_CDONE)) {
108 printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n", 110 printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n",
109 __func__, reg, GSR | gsr_bits); 111 __func__, reg, GSR | gsr_bits);
112 ret = -EIO;
113 }
110 114
111 mutex_unlock(&car_mutex); 115 mutex_unlock(&car_mutex);
116 return ret;
112} 117}
113EXPORT_SYMBOL_GPL(pxa2xx_ac97_write); 118EXPORT_SYMBOL_GPL(pxa2xx_ac97_write);
114 119
@@ -188,7 +193,7 @@ static inline void pxa_ac97_cold_pxa3xx(void)
188} 193}
189#endif 194#endif
190 195
191bool pxa2xx_ac97_try_warm_reset(struct snd_ac97 *ac97) 196bool pxa2xx_ac97_try_warm_reset(void)
192{ 197{
193 unsigned long gsr; 198 unsigned long gsr;
194 unsigned int timeout = 100; 199 unsigned int timeout = 100;
@@ -225,7 +230,7 @@ bool pxa2xx_ac97_try_warm_reset(struct snd_ac97 *ac97)
225} 230}
226EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_warm_reset); 231EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_warm_reset);
227 232
228bool pxa2xx_ac97_try_cold_reset(struct snd_ac97 *ac97) 233bool pxa2xx_ac97_try_cold_reset(void)
229{ 234{
230 unsigned long gsr; 235 unsigned long gsr;
231 unsigned int timeout = 1000; 236 unsigned int timeout = 1000;
@@ -263,7 +268,7 @@ bool pxa2xx_ac97_try_cold_reset(struct snd_ac97 *ac97)
263EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_cold_reset); 268EXPORT_SYMBOL_GPL(pxa2xx_ac97_try_cold_reset);
264 269
265 270
266void pxa2xx_ac97_finish_reset(struct snd_ac97 *ac97) 271void pxa2xx_ac97_finish_reset(void)
267{ 272{
268 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); 273 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
269 GCR |= GCR_SDONE_IE|GCR_CDONE_IE; 274 GCR |= GCR_SDONE_IE|GCR_CDONE_IE;
diff --git a/sound/arm/pxa2xx-ac97.c b/sound/arm/pxa2xx-ac97.c
index fbd5dad0c484..4bc244c40f80 100644
--- a/sound/arm/pxa2xx-ac97.c
+++ b/sound/arm/pxa2xx-ac97.c
@@ -29,19 +29,38 @@
29 29
30#include "pxa2xx-pcm.h" 30#include "pxa2xx-pcm.h"
31 31
32static void pxa2xx_ac97_reset(struct snd_ac97 *ac97) 32static void pxa2xx_ac97_legacy_reset(struct snd_ac97 *ac97)
33{ 33{
34 if (!pxa2xx_ac97_try_cold_reset(ac97)) { 34 if (!pxa2xx_ac97_try_cold_reset())
35 pxa2xx_ac97_try_warm_reset(ac97); 35 pxa2xx_ac97_try_warm_reset();
36 } 36
37 pxa2xx_ac97_finish_reset();
38}
39
40static unsigned short pxa2xx_ac97_legacy_read(struct snd_ac97 *ac97,
41 unsigned short reg)
42{
43 int ret;
44
45 ret = pxa2xx_ac97_read(ac97->num, reg);
46 if (ret < 0)
47 return 0;
48 else
49 return (unsigned short)(ret & 0xffff);
50}
51
52static void pxa2xx_ac97_legacy_write(struct snd_ac97 *ac97,
53 unsigned short reg, unsigned short val)
54{
55 int __always_unused ret;
37 56
38 pxa2xx_ac97_finish_reset(ac97); 57 ret = pxa2xx_ac97_write(ac97->num, reg, val);
39} 58}
40 59
41static struct snd_ac97_bus_ops pxa2xx_ac97_ops = { 60static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
42 .read = pxa2xx_ac97_read, 61 .read = pxa2xx_ac97_legacy_read,
43 .write = pxa2xx_ac97_write, 62 .write = pxa2xx_ac97_legacy_write,
44 .reset = pxa2xx_ac97_reset, 63 .reset = pxa2xx_ac97_legacy_reset,
45}; 64};
46 65
47static struct pxad_param pxa2xx_ac97_pcm_out_req = { 66static struct pxad_param pxa2xx_ac97_pcm_out_req = {
diff --git a/sound/core/hrtimer.c b/sound/core/hrtimer.c
index 6e47b823bcaa..18cb6f476bf4 100644
--- a/sound/core/hrtimer.c
+++ b/sound/core/hrtimer.c
@@ -127,7 +127,7 @@ static int snd_hrtimer_stop(struct snd_timer *t)
127 return 0; 127 return 0;
128} 128}
129 129
130static struct snd_timer_hardware hrtimer_hw = { 130static const struct snd_timer_hardware hrtimer_hw __initconst = {
131 .flags = SNDRV_TIMER_HW_AUTO | SNDRV_TIMER_HW_TASKLET, 131 .flags = SNDRV_TIMER_HW_AUTO | SNDRV_TIMER_HW_TASKLET,
132 .open = snd_hrtimer_open, 132 .open = snd_hrtimer_open,
133 .close = snd_hrtimer_close, 133 .close = snd_hrtimer_close,
diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c
index a73baa1242be..8faae3d1455d 100644
--- a/sound/core/hwdep.c
+++ b/sound/core/hwdep.c
@@ -228,6 +228,8 @@ static int snd_hwdep_dsp_load(struct snd_hwdep *hw,
228 memset(&info, 0, sizeof(info)); 228 memset(&info, 0, sizeof(info));
229 if (copy_from_user(&info, _info, sizeof(info))) 229 if (copy_from_user(&info, _info, sizeof(info)))
230 return -EFAULT; 230 return -EFAULT;
231 if (info.index >= 32)
232 return -EINVAL;
231 /* check whether the dsp was already loaded */ 233 /* check whether the dsp was already loaded */
232 if (hw->dsp_loaded & (1 << info.index)) 234 if (hw->dsp_loaded & (1 << info.index))
233 return -EBUSY; 235 return -EBUSY;
diff --git a/sound/core/init.c b/sound/core/init.c
index 32ebe2f6bc59..168ae03d3a1c 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -255,6 +255,7 @@ int snd_card_new(struct device *parent, int idx, const char *xid,
255#ifdef CONFIG_PM 255#ifdef CONFIG_PM
256 init_waitqueue_head(&card->power_sleep); 256 init_waitqueue_head(&card->power_sleep);
257#endif 257#endif
258 init_waitqueue_head(&card->remove_sleep);
258 259
259 device_initialize(&card->card_dev); 260 device_initialize(&card->card_dev);
260 card->card_dev.parent = parent; 261 card->card_dev.parent = parent;
@@ -452,6 +453,35 @@ int snd_card_disconnect(struct snd_card *card)
452} 453}
453EXPORT_SYMBOL(snd_card_disconnect); 454EXPORT_SYMBOL(snd_card_disconnect);
454 455
456/**
457 * snd_card_disconnect_sync - disconnect card and wait until files get closed
458 * @card: card object to disconnect
459 *
460 * This calls snd_card_disconnect() for disconnecting all belonging components
461 * and waits until all pending files get closed.
462 * It assures that all accesses from user-space finished so that the driver
463 * can release its resources gracefully.
464 */
465void snd_card_disconnect_sync(struct snd_card *card)
466{
467 int err;
468
469 err = snd_card_disconnect(card);
470 if (err < 0) {
471 dev_err(card->dev,
472 "snd_card_disconnect error (%d), skipping sync\n",
473 err);
474 return;
475 }
476
477 spin_lock_irq(&card->files_lock);
478 wait_event_lock_irq(card->remove_sleep,
479 list_empty(&card->files_list),
480 card->files_lock);
481 spin_unlock_irq(&card->files_lock);
482}
483EXPORT_SYMBOL_GPL(snd_card_disconnect_sync);
484
455static int snd_card_do_free(struct snd_card *card) 485static int snd_card_do_free(struct snd_card *card)
456{ 486{
457#if IS_ENABLED(CONFIG_SND_MIXER_OSS) 487#if IS_ENABLED(CONFIG_SND_MIXER_OSS)
@@ -957,6 +987,8 @@ int snd_card_file_remove(struct snd_card *card, struct file *file)
957 break; 987 break;
958 } 988 }
959 } 989 }
990 if (list_empty(&card->files_list))
991 wake_up_all(&card->remove_sleep);
960 spin_unlock(&card->files_lock); 992 spin_unlock(&card->files_lock);
961 if (!found) { 993 if (!found) {
962 dev_err(card->dev, "card file remove problem (%p)\n", file); 994 dev_err(card->dev, "card file remove problem (%p)\n", file);
diff --git a/sound/core/jack.c b/sound/core/jack.c
index f652e90efd7e..84c2a17c56ee 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -310,7 +310,7 @@ EXPORT_SYMBOL(snd_jack_set_parent);
310 * @type: Jack report type for this key 310 * @type: Jack report type for this key
311 * @keytype: Input layer key type to be reported 311 * @keytype: Input layer key type to be reported
312 * 312 *
313 * Map a SND_JACK_BTN_ button type to an input layer key, allowing 313 * Map a SND_JACK_BTN_* button type to an input layer key, allowing
314 * reporting of keys on accessories via the jack abstraction. If no 314 * reporting of keys on accessories via the jack abstraction. If no
315 * mapping is provided but keys are enabled in the jack type then 315 * mapping is provided but keys are enabled in the jack type then
316 * BTN_n numeric buttons will be reported. 316 * BTN_n numeric buttons will be reported.
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 7eadb7fd8074..9070f277f8db 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -775,6 +775,9 @@ static int _snd_pcm_new(struct snd_card *card, const char *id, int device,
775 .dev_register = snd_pcm_dev_register, 775 .dev_register = snd_pcm_dev_register,
776 .dev_disconnect = snd_pcm_dev_disconnect, 776 .dev_disconnect = snd_pcm_dev_disconnect,
777 }; 777 };
778 static struct snd_device_ops internal_ops = {
779 .dev_free = snd_pcm_dev_free,
780 };
778 781
779 if (snd_BUG_ON(!card)) 782 if (snd_BUG_ON(!card))
780 return -ENXIO; 783 return -ENXIO;
@@ -801,7 +804,8 @@ static int _snd_pcm_new(struct snd_card *card, const char *id, int device,
801 if (err < 0) 804 if (err < 0)
802 goto free_pcm; 805 goto free_pcm;
803 806
804 err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops); 807 err = snd_device_new(card, SNDRV_DEV_PCM, pcm,
808 internal ? &internal_ops : &ops);
805 if (err < 0) 809 if (err < 0)
806 goto free_pcm; 810 goto free_pcm;
807 811
@@ -1099,8 +1103,6 @@ static int snd_pcm_dev_register(struct snd_device *device)
1099 if (snd_BUG_ON(!device || !device->device_data)) 1103 if (snd_BUG_ON(!device || !device->device_data))
1100 return -ENXIO; 1104 return -ENXIO;
1101 pcm = device->device_data; 1105 pcm = device->device_data;
1102 if (pcm->internal)
1103 return 0;
1104 1106
1105 mutex_lock(&register_mutex); 1107 mutex_lock(&register_mutex);
1106 err = snd_pcm_add(pcm); 1108 err = snd_pcm_add(pcm);
@@ -1152,6 +1154,10 @@ static int snd_pcm_dev_disconnect(struct snd_device *device)
1152 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) { 1154 for (substream = pcm->streams[cidx].substream; substream; substream = substream->next) {
1153 snd_pcm_stream_lock_irq(substream); 1155 snd_pcm_stream_lock_irq(substream);
1154 if (substream->runtime) { 1156 if (substream->runtime) {
1157 if (snd_pcm_running(substream))
1158 snd_pcm_stop(substream,
1159 SNDRV_PCM_STATE_DISCONNECTED);
1160 /* to be sure, set the state unconditionally */
1155 substream->runtime->status->state = SNDRV_PCM_STATE_DISCONNECTED; 1161 substream->runtime->status->state = SNDRV_PCM_STATE_DISCONNECTED;
1156 wake_up(&substream->runtime->sleep); 1162 wake_up(&substream->runtime->sleep);
1157 wake_up(&substream->runtime->tsleep); 1163 wake_up(&substream->runtime->tsleep);
@@ -1159,12 +1165,10 @@ static int snd_pcm_dev_disconnect(struct snd_device *device)
1159 snd_pcm_stream_unlock_irq(substream); 1165 snd_pcm_stream_unlock_irq(substream);
1160 } 1166 }
1161 } 1167 }
1162 if (!pcm->internal) { 1168
1163 pcm_call_notify(pcm, n_disconnect); 1169 pcm_call_notify(pcm, n_disconnect);
1164 }
1165 for (cidx = 0; cidx < 2; cidx++) { 1170 for (cidx = 0; cidx < 2; cidx++) {
1166 if (!pcm->internal) 1171 snd_unregister_device(&pcm->streams[cidx].dev);
1167 snd_unregister_device(&pcm->streams[cidx].dev);
1168 free_chmap(&pcm->streams[cidx]); 1172 free_chmap(&pcm->streams[cidx]);
1169 } 1173 }
1170 mutex_unlock(&pcm->open_mutex); 1174 mutex_unlock(&pcm->open_mutex);
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 2fec2feac387..a4d92e46c459 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -195,7 +195,6 @@ EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock_irqrestore);
195 195
196int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info) 196int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info)
197{ 197{
198 struct snd_pcm_runtime *runtime;
199 struct snd_pcm *pcm = substream->pcm; 198 struct snd_pcm *pcm = substream->pcm;
200 struct snd_pcm_str *pstr = substream->pstr; 199 struct snd_pcm_str *pstr = substream->pstr;
201 200
@@ -211,7 +210,6 @@ int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info)
211 info->subdevices_count = pstr->substream_count; 210 info->subdevices_count = pstr->substream_count;
212 info->subdevices_avail = pstr->substream_count - pstr->substream_opened; 211 info->subdevices_avail = pstr->substream_count - pstr->substream_opened;
213 strlcpy(info->subname, substream->name, sizeof(info->subname)); 212 strlcpy(info->subname, substream->name, sizeof(info->subname));
214 runtime = substream->runtime;
215 213
216 return 0; 214 return 0;
217} 215}
diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c
index d10c780dfd54..6e22eea72654 100644
--- a/sound/core/seq/seq_clientmgr.c
+++ b/sound/core/seq/seq_clientmgr.c
@@ -802,6 +802,10 @@ static int snd_seq_deliver_event(struct snd_seq_client *client, struct snd_seq_e
802 return -EMLINK; 802 return -EMLINK;
803 } 803 }
804 804
805 if (snd_seq_ev_is_variable(event) &&
806 snd_BUG_ON(atomic && (event->data.ext.len & SNDRV_SEQ_EXT_USRPTR)))
807 return -EINVAL;
808
805 if (event->queue == SNDRV_SEQ_ADDRESS_SUBSCRIBERS || 809 if (event->queue == SNDRV_SEQ_ADDRESS_SUBSCRIBERS ||
806 event->dest.client == SNDRV_SEQ_ADDRESS_SUBSCRIBERS) 810 event->dest.client == SNDRV_SEQ_ADDRESS_SUBSCRIBERS)
807 result = deliver_to_subscribers(client, event, atomic, hop); 811 result = deliver_to_subscribers(client, event, atomic, hop);
diff --git a/sound/core/timer.c b/sound/core/timer.c
index 15e82a656d96..ee09dace8bb1 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -1069,15 +1069,17 @@ EXPORT_SYMBOL(snd_timer_global_register);
1069 1069
1070struct snd_timer_system_private { 1070struct snd_timer_system_private {
1071 struct timer_list tlist; 1071 struct timer_list tlist;
1072 struct snd_timer *snd_timer;
1072 unsigned long last_expires; 1073 unsigned long last_expires;
1073 unsigned long last_jiffies; 1074 unsigned long last_jiffies;
1074 unsigned long correction; 1075 unsigned long correction;
1075}; 1076};
1076 1077
1077static void snd_timer_s_function(unsigned long data) 1078static void snd_timer_s_function(struct timer_list *t)
1078{ 1079{
1079 struct snd_timer *timer = (struct snd_timer *)data; 1080 struct snd_timer_system_private *priv = from_timer(priv, t,
1080 struct snd_timer_system_private *priv = timer->private_data; 1081 tlist);
1082 struct snd_timer *timer = priv->snd_timer;
1081 unsigned long jiff = jiffies; 1083 unsigned long jiff = jiffies;
1082 if (time_after(jiff, priv->last_expires)) 1084 if (time_after(jiff, priv->last_expires))
1083 priv->correction += (long)jiff - (long)priv->last_expires; 1085 priv->correction += (long)jiff - (long)priv->last_expires;
@@ -1159,7 +1161,8 @@ static int snd_timer_register_system(void)
1159 snd_timer_free(timer); 1161 snd_timer_free(timer);
1160 return -ENOMEM; 1162 return -ENOMEM;
1161 } 1163 }
1162 setup_timer(&priv->tlist, snd_timer_s_function, (unsigned long) timer); 1164 priv->snd_timer = timer;
1165 timer_setup(&priv->tlist, snd_timer_s_function, 0);
1163 timer->private_data = priv; 1166 timer->private_data = priv;
1164 timer->private_free = snd_timer_free_system; 1167 timer->private_free = snd_timer_free_system;
1165 return snd_timer_global_register(timer); 1168 return snd_timer_global_register(timer);
diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c
index 135adb17703c..afac886ffa28 100644
--- a/sound/drivers/aloop.c
+++ b/sound/drivers/aloop.c
@@ -529,9 +529,9 @@ static unsigned int loopback_pos_update(struct loopback_cable *cable)
529 return running; 529 return running;
530} 530}
531 531
532static void loopback_timer_function(unsigned long data) 532static void loopback_timer_function(struct timer_list *t)
533{ 533{
534 struct loopback_pcm *dpcm = (struct loopback_pcm *)data; 534 struct loopback_pcm *dpcm = from_timer(dpcm, t, timer);
535 unsigned long flags; 535 unsigned long flags;
536 536
537 spin_lock_irqsave(&dpcm->cable->lock, flags); 537 spin_lock_irqsave(&dpcm->cable->lock, flags);
@@ -675,8 +675,7 @@ static int loopback_open(struct snd_pcm_substream *substream)
675 } 675 }
676 dpcm->loopback = loopback; 676 dpcm->loopback = loopback;
677 dpcm->substream = substream; 677 dpcm->substream = substream;
678 setup_timer(&dpcm->timer, loopback_timer_function, 678 timer_setup(&dpcm->timer, loopback_timer_function, 0);
679 (unsigned long)dpcm);
680 679
681 cable = loopback->cables[substream->number][dev]; 680 cable = loopback->cables[substream->number][dev];
682 if (!cable) { 681 if (!cable) {
diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index c0939a0164a6..7b2b1f766b00 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -306,9 +306,9 @@ static int dummy_systimer_prepare(struct snd_pcm_substream *substream)
306 return 0; 306 return 0;
307} 307}
308 308
309static void dummy_systimer_callback(unsigned long data) 309static void dummy_systimer_callback(struct timer_list *t)
310{ 310{
311 struct dummy_systimer_pcm *dpcm = (struct dummy_systimer_pcm *)data; 311 struct dummy_systimer_pcm *dpcm = from_timer(dpcm, t, timer);
312 unsigned long flags; 312 unsigned long flags;
313 int elapsed = 0; 313 int elapsed = 0;
314 314
@@ -343,8 +343,7 @@ static int dummy_systimer_create(struct snd_pcm_substream *substream)
343 if (!dpcm) 343 if (!dpcm)
344 return -ENOMEM; 344 return -ENOMEM;
345 substream->runtime->private_data = dpcm; 345 substream->runtime->private_data = dpcm;
346 setup_timer(&dpcm->timer, dummy_systimer_callback, 346 timer_setup(&dpcm->timer, dummy_systimer_callback, 0);
347 (unsigned long) dpcm);
348 spin_lock_init(&dpcm->lock); 347 spin_lock_init(&dpcm->lock);
349 dpcm->substream = substream; 348 dpcm->substream = substream;
350 return 0; 349 return 0;
diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c
index b997222274bd..3e745f47dd2f 100644
--- a/sound/drivers/mpu401/mpu401_uart.c
+++ b/sound/drivers/mpu401/mpu401_uart.c
@@ -169,9 +169,9 @@ EXPORT_SYMBOL(snd_mpu401_uart_interrupt_tx);
169 * timer callback 169 * timer callback
170 * reprogram the timer and call the interrupt job 170 * reprogram the timer and call the interrupt job
171 */ 171 */
172static void snd_mpu401_uart_timer(unsigned long data) 172static void snd_mpu401_uart_timer(struct timer_list *t)
173{ 173{
174 struct snd_mpu401 *mpu = (struct snd_mpu401 *)data; 174 struct snd_mpu401 *mpu = from_timer(mpu, t, timer);
175 unsigned long flags; 175 unsigned long flags;
176 176
177 spin_lock_irqsave(&mpu->timer_lock, flags); 177 spin_lock_irqsave(&mpu->timer_lock, flags);
@@ -191,8 +191,7 @@ static void snd_mpu401_uart_add_timer (struct snd_mpu401 *mpu, int input)
191 191
192 spin_lock_irqsave (&mpu->timer_lock, flags); 192 spin_lock_irqsave (&mpu->timer_lock, flags);
193 if (mpu->timer_invoked == 0) { 193 if (mpu->timer_invoked == 0) {
194 setup_timer(&mpu->timer, snd_mpu401_uart_timer, 194 timer_setup(&mpu->timer, snd_mpu401_uart_timer, 0);
195 (unsigned long)mpu);
196 mod_timer(&mpu->timer, 1 + jiffies); 195 mod_timer(&mpu->timer, 1 + jiffies);
197 } 196 }
198 mpu->timer_invoked |= input ? MPU401_MODE_INPUT_TIMER : 197 mpu->timer_invoked |= input ? MPU401_MODE_INPUT_TIMER :
diff --git a/sound/drivers/mtpav.c b/sound/drivers/mtpav.c
index 0f6392001e30..547662e02fcc 100644
--- a/sound/drivers/mtpav.c
+++ b/sound/drivers/mtpav.c
@@ -406,10 +406,10 @@ static void snd_mtpav_input_trigger(struct snd_rawmidi_substream *substream, int
406 * timer interrupt for outputs 406 * timer interrupt for outputs
407 */ 407 */
408 408
409static void snd_mtpav_output_timer(unsigned long data) 409static void snd_mtpav_output_timer(struct timer_list *t)
410{ 410{
411 unsigned long flags; 411 unsigned long flags;
412 struct mtpav *chip = (struct mtpav *)data; 412 struct mtpav *chip = from_timer(chip, t, timer);
413 int p; 413 int p;
414 414
415 spin_lock_irqsave(&chip->spinlock, flags); 415 spin_lock_irqsave(&chip->spinlock, flags);
@@ -707,8 +707,7 @@ static int snd_mtpav_probe(struct platform_device *dev)
707 mtp_card->share_irq = 0; 707 mtp_card->share_irq = 0;
708 mtp_card->inmidistate = 0; 708 mtp_card->inmidistate = 0;
709 mtp_card->outmidihwport = 0xffffffff; 709 mtp_card->outmidihwport = 0xffffffff;
710 setup_timer(&mtp_card->timer, snd_mtpav_output_timer, 710 timer_setup(&mtp_card->timer, snd_mtpav_output_timer, 0);
711 (unsigned long) mtp_card);
712 711
713 card->private_free = snd_mtpav_free; 712 card->private_free = snd_mtpav_free;
714 713
diff --git a/sound/drivers/opl3/opl3_midi.c b/sound/drivers/opl3/opl3_midi.c
index 13c0a7e1bc2b..bb3f3a5a6951 100644
--- a/sound/drivers/opl3/opl3_midi.c
+++ b/sound/drivers/opl3/opl3_midi.c
@@ -238,10 +238,10 @@ static int opl3_get_voice(struct snd_opl3 *opl3, int instr_4op,
238/* 238/*
239 * System timer interrupt function 239 * System timer interrupt function
240 */ 240 */
241void snd_opl3_timer_func(unsigned long data) 241void snd_opl3_timer_func(struct timer_list *t)
242{ 242{
243 243
244 struct snd_opl3 *opl3 = (struct snd_opl3 *)data; 244 struct snd_opl3 *opl3 = from_timer(opl3, t, tlist);
245 unsigned long flags; 245 unsigned long flags;
246 int again = 0; 246 int again = 0;
247 int i; 247 int i;
diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
index d3e91be8b23a..5f881c4cdf1f 100644
--- a/sound/drivers/opl3/opl3_seq.c
+++ b/sound/drivers/opl3/opl3_seq.c
@@ -248,7 +248,7 @@ static int snd_opl3_seq_probe(struct device *_dev)
248 } 248 }
249 249
250 /* setup system timer */ 250 /* setup system timer */
251 setup_timer(&opl3->tlist, snd_opl3_timer_func, (unsigned long) opl3); 251 timer_setup(&opl3->tlist, snd_opl3_timer_func, 0);
252 spin_lock_init(&opl3->sys_timer_lock); 252 spin_lock_init(&opl3->sys_timer_lock);
253 opl3->sys_timer_status = 0; 253 opl3->sys_timer_status = 0;
254 254
diff --git a/sound/drivers/opl3/opl3_voice.h b/sound/drivers/opl3/opl3_voice.h
index eaef435e0528..a2445163008e 100644
--- a/sound/drivers/opl3/opl3_voice.h
+++ b/sound/drivers/opl3/opl3_voice.h
@@ -37,7 +37,7 @@ void snd_opl3_nrpn(void *p, struct snd_midi_channel *chan, struct snd_midi_chann
37void snd_opl3_sysex(void *p, unsigned char *buf, int len, int parsed, struct snd_midi_channel_set *chset); 37void snd_opl3_sysex(void *p, unsigned char *buf, int len, int parsed, struct snd_midi_channel_set *chset);
38 38
39void snd_opl3_calc_volume(unsigned char *reg, int vel, struct snd_midi_channel *chan); 39void snd_opl3_calc_volume(unsigned char *reg, int vel, struct snd_midi_channel *chan);
40void snd_opl3_timer_func(unsigned long data); 40void snd_opl3_timer_func(struct timer_list *t);
41 41
42/* Prototypes for opl3_drums.c */ 42/* Prototypes for opl3_drums.c */
43void snd_opl3_load_drums(struct snd_opl3 *opl3); 43void snd_opl3_load_drums(struct snd_opl3 *opl3);
diff --git a/sound/drivers/serial-u16550.c b/sound/drivers/serial-u16550.c
index 88e66ea0306d..0a67b8b9f176 100644
--- a/sound/drivers/serial-u16550.c
+++ b/sound/drivers/serial-u16550.c
@@ -309,12 +309,12 @@ static irqreturn_t snd_uart16550_interrupt(int irq, void *dev_id)
309} 309}
310 310
311/* When the polling mode, this function calls snd_uart16550_io_loop. */ 311/* When the polling mode, this function calls snd_uart16550_io_loop. */
312static void snd_uart16550_buffer_timer(unsigned long data) 312static void snd_uart16550_buffer_timer(struct timer_list *t)
313{ 313{
314 unsigned long flags; 314 unsigned long flags;
315 struct snd_uart16550 *uart; 315 struct snd_uart16550 *uart;
316 316
317 uart = (struct snd_uart16550 *)data; 317 uart = from_timer(uart, t, buffer_timer);
318 spin_lock_irqsave(&uart->open_lock, flags); 318 spin_lock_irqsave(&uart->open_lock, flags);
319 snd_uart16550_del_timer(uart); 319 snd_uart16550_del_timer(uart);
320 snd_uart16550_io_loop(uart); 320 snd_uart16550_io_loop(uart);
@@ -828,8 +828,7 @@ static int snd_uart16550_create(struct snd_card *card,
828 uart->prev_in = 0; 828 uart->prev_in = 0;
829 uart->rstatus = 0; 829 uart->rstatus = 0;
830 memset(uart->prev_status, 0x80, sizeof(unsigned char) * SNDRV_SERIAL_MAX_OUTS); 830 memset(uart->prev_status, 0x80, sizeof(unsigned char) * SNDRV_SERIAL_MAX_OUTS);
831 setup_timer(&uart->buffer_timer, snd_uart16550_buffer_timer, 831 timer_setup(&uart->buffer_timer, snd_uart16550_buffer_timer, 0);
832 (unsigned long)uart);
833 uart->timer_running = 0; 832 uart->timer_running = 0;
834 833
835 /* Register device */ 834 /* Register device */
diff --git a/sound/hda/hdac_controller.c b/sound/hda/hdac_controller.c
index f6d2985b2520..560ec0986e1a 100644
--- a/sound/hda/hdac_controller.c
+++ b/sound/hda/hdac_controller.c
@@ -319,7 +319,8 @@ int snd_hdac_bus_parse_capabilities(struct hdac_bus *bus)
319 break; 319 break;
320 320
321 default: 321 default:
322 dev_dbg(bus->dev, "Unknown capability %d\n", cur_cap); 322 dev_err(bus->dev, "Unknown capability %d\n", cur_cap);
323 cur_cap = 0;
323 break; 324 break;
324 } 325 }
325 326
diff --git a/sound/hda/hdac_device.c b/sound/hda/hdac_device.c
index 19deb306facb..06f845e293cb 100644
--- a/sound/hda/hdac_device.c
+++ b/sound/hda/hdac_device.c
@@ -87,7 +87,7 @@ int snd_hdac_device_init(struct hdac_device *codec, struct hdac_bus *bus,
87 87
88 fg = codec->afg ? codec->afg : codec->mfg; 88 fg = codec->afg ? codec->afg : codec->mfg;
89 89
90 err = snd_hdac_refresh_widgets(codec); 90 err = snd_hdac_refresh_widgets(codec, false);
91 if (err < 0) 91 if (err < 0)
92 goto error; 92 goto error;
93 93
@@ -388,11 +388,12 @@ static void setup_fg_nodes(struct hdac_device *codec)
388/** 388/**
389 * snd_hdac_refresh_widgets - Reset the widget start/end nodes 389 * snd_hdac_refresh_widgets - Reset the widget start/end nodes
390 * @codec: the codec object 390 * @codec: the codec object
391 * @sysfs: re-initialize sysfs tree, too
391 */ 392 */
392int snd_hdac_refresh_widgets(struct hdac_device *codec) 393int snd_hdac_refresh_widgets(struct hdac_device *codec, bool sysfs)
393{ 394{
394 hda_nid_t start_nid; 395 hda_nid_t start_nid;
395 int nums; 396 int nums, err;
396 397
397 nums = snd_hdac_get_sub_nodes(codec, codec->afg, &start_nid); 398 nums = snd_hdac_get_sub_nodes(codec, codec->afg, &start_nid);
398 if (!start_nid || nums <= 0 || nums >= 0xff) { 399 if (!start_nid || nums <= 0 || nums >= 0xff) {
@@ -401,6 +402,12 @@ int snd_hdac_refresh_widgets(struct hdac_device *codec)
401 return -EINVAL; 402 return -EINVAL;
402 } 403 }
403 404
405 if (sysfs) {
406 err = hda_widget_sysfs_reinit(codec, start_nid, nums);
407 if (err < 0)
408 return err;
409 }
410
404 codec->num_nodes = nums; 411 codec->num_nodes = nums;
405 codec->start_nid = start_nid; 412 codec->start_nid = start_nid;
406 codec->end_nid = start_nid + nums; 413 codec->end_nid = start_nid + nums;
@@ -408,36 +415,6 @@ int snd_hdac_refresh_widgets(struct hdac_device *codec)
408} 415}
409EXPORT_SYMBOL_GPL(snd_hdac_refresh_widgets); 416EXPORT_SYMBOL_GPL(snd_hdac_refresh_widgets);
410 417
411/**
412 * snd_hdac_refresh_widget_sysfs - Reset the codec widgets and reinit the
413 * codec sysfs
414 * @codec: the codec object
415 *
416 * first we need to remove sysfs, then refresh widgets and lastly
417 * recreate it
418 */
419int snd_hdac_refresh_widget_sysfs(struct hdac_device *codec)
420{
421 int ret;
422
423 if (device_is_registered(&codec->dev))
424 hda_widget_sysfs_exit(codec);
425 ret = snd_hdac_refresh_widgets(codec);
426 if (ret) {
427 dev_err(&codec->dev, "failed to refresh widget: %d\n", ret);
428 return ret;
429 }
430 if (device_is_registered(&codec->dev)) {
431 ret = hda_widget_sysfs_init(codec);
432 if (ret) {
433 dev_err(&codec->dev, "failed to init sysfs: %d\n", ret);
434 return ret;
435 }
436 }
437 return ret;
438}
439EXPORT_SYMBOL_GPL(snd_hdac_refresh_widget_sysfs);
440
441/* return CONNLIST_LEN parameter of the given widget */ 418/* return CONNLIST_LEN parameter of the given widget */
442static unsigned int get_num_conns(struct hdac_device *codec, hda_nid_t nid) 419static unsigned int get_num_conns(struct hdac_device *codec, hda_nid_t nid)
443{ 420{
diff --git a/sound/hda/hdac_sysfs.c b/sound/hda/hdac_sysfs.c
index 3c2d45ee6ab8..fb2aa344981e 100644
--- a/sound/hda/hdac_sysfs.c
+++ b/sound/hda/hdac_sysfs.c
@@ -415,3 +415,50 @@ void hda_widget_sysfs_exit(struct hdac_device *codec)
415{ 415{
416 widget_tree_free(codec); 416 widget_tree_free(codec);
417} 417}
418
419int hda_widget_sysfs_reinit(struct hdac_device *codec,
420 hda_nid_t start_nid, int num_nodes)
421{
422 struct hdac_widget_tree *tree;
423 hda_nid_t end_nid = start_nid + num_nodes;
424 hda_nid_t nid;
425 int i;
426
427 if (!codec->widgets)
428 return hda_widget_sysfs_init(codec);
429
430 tree = kmemdup(codec->widgets, sizeof(*tree), GFP_KERNEL);
431 if (!tree)
432 return -ENOMEM;
433
434 tree->nodes = kcalloc(num_nodes + 1, sizeof(*tree->nodes), GFP_KERNEL);
435 if (!tree->nodes) {
436 kfree(tree);
437 return -ENOMEM;
438 }
439
440 /* prune non-existing nodes */
441 for (i = 0, nid = codec->start_nid; i < codec->num_nodes; i++, nid++) {
442 if (nid < start_nid || nid >= end_nid)
443 free_widget_node(codec->widgets->nodes[i],
444 &widget_node_group);
445 }
446
447 /* add new nodes */
448 for (i = 0, nid = start_nid; i < num_nodes; i++, nid++) {
449 if (nid < codec->start_nid || nid >= codec->end_nid)
450 add_widget_node(tree->root, nid, &widget_node_group,
451 &tree->nodes[i]);
452 else
453 tree->nodes[i] =
454 codec->widgets->nodes[nid - codec->start_nid];
455 }
456
457 /* replace with the new tree */
458 kfree(codec->widgets->nodes);
459 kfree(codec->widgets);
460 codec->widgets = tree;
461
462 kobject_uevent(tree->root, KOBJ_CHANGE);
463 return 0;
464}
diff --git a/sound/hda/local.h b/sound/hda/local.h
index 7258fa8ce268..877631e39373 100644
--- a/sound/hda/local.h
+++ b/sound/hda/local.h
@@ -29,6 +29,8 @@ static inline unsigned int get_wcaps_channels(u32 wcaps)
29 29
30extern const struct attribute_group *hdac_dev_attr_groups[]; 30extern const struct attribute_group *hdac_dev_attr_groups[];
31int hda_widget_sysfs_init(struct hdac_device *codec); 31int hda_widget_sysfs_init(struct hdac_device *codec);
32int hda_widget_sysfs_reinit(struct hdac_device *codec, hda_nid_t start_nid,
33 int num_nodes);
32void hda_widget_sysfs_exit(struct hdac_device *codec); 34void hda_widget_sysfs_exit(struct hdac_device *codec);
33 35
34#endif /* __HDAC_LOCAL_H */ 36#endif /* __HDAC_LOCAL_H */
diff --git a/sound/i2c/other/ak4117.c b/sound/i2c/other/ak4117.c
index 3ab099fb8c15..b923342cadf4 100644
--- a/sound/i2c/other/ak4117.c
+++ b/sound/i2c/other/ak4117.c
@@ -35,7 +35,7 @@ MODULE_LICENSE("GPL");
35 35
36#define AK4117_ADDR 0x00 /* fixed address */ 36#define AK4117_ADDR 0x00 /* fixed address */
37 37
38static void snd_ak4117_timer(unsigned long data); 38static void snd_ak4117_timer(struct timer_list *t);
39 39
40static void reg_write(struct ak4117 *ak4117, unsigned char reg, unsigned char val) 40static void reg_write(struct ak4117 *ak4117, unsigned char reg, unsigned char val)
41{ 41{
@@ -91,7 +91,7 @@ int snd_ak4117_create(struct snd_card *card, ak4117_read_t *read, ak4117_write_t
91 chip->read = read; 91 chip->read = read;
92 chip->write = write; 92 chip->write = write;
93 chip->private_data = private_data; 93 chip->private_data = private_data;
94 setup_timer(&chip->timer, snd_ak4117_timer, (unsigned long)chip); 94 timer_setup(&chip->timer, snd_ak4117_timer, 0);
95 95
96 for (reg = 0; reg < 5; reg++) 96 for (reg = 0; reg < 5; reg++)
97 chip->regmap[reg] = pgm[reg]; 97 chip->regmap[reg] = pgm[reg];
@@ -529,9 +529,9 @@ int snd_ak4117_check_rate_and_errors(struct ak4117 *ak4117, unsigned int flags)
529 return res; 529 return res;
530} 530}
531 531
532static void snd_ak4117_timer(unsigned long data) 532static void snd_ak4117_timer(struct timer_list *t)
533{ 533{
534 struct ak4117 *chip = (struct ak4117 *)data; 534 struct ak4117 *chip = from_timer(chip, t, timer);
535 535
536 if (chip->init) 536 if (chip->init)
537 return; 537 return;
diff --git a/sound/isa/sb/emu8000_pcm.c b/sound/isa/sb/emu8000_pcm.c
index 8f34551abd8d..bc5af71d3bdb 100644
--- a/sound/isa/sb/emu8000_pcm.c
+++ b/sound/isa/sb/emu8000_pcm.c
@@ -193,9 +193,9 @@ static inline int emu8k_get_curpos(struct snd_emu8k_pcm *rec, int ch)
193 * timer interrupt handler 193 * timer interrupt handler
194 * check the current position and update the period if necessary. 194 * check the current position and update the period if necessary.
195 */ 195 */
196static void emu8k_pcm_timer_func(unsigned long data) 196static void emu8k_pcm_timer_func(struct timer_list *t)
197{ 197{
198 struct snd_emu8k_pcm *rec = (struct snd_emu8k_pcm *)data; 198 struct snd_emu8k_pcm *rec = from_timer(rec, t, timer);
199 int ptr, delta; 199 int ptr, delta;
200 200
201 spin_lock(&rec->timer_lock); 201 spin_lock(&rec->timer_lock);
@@ -241,7 +241,7 @@ static int emu8k_pcm_open(struct snd_pcm_substream *subs)
241 runtime->private_data = rec; 241 runtime->private_data = rec;
242 242
243 spin_lock_init(&rec->timer_lock); 243 spin_lock_init(&rec->timer_lock);
244 setup_timer(&rec->timer, emu8k_pcm_timer_func, (unsigned long)rec); 244 timer_setup(&rec->timer, emu8k_pcm_timer_func, 0);
245 245
246 runtime->hw = emu8k_pcm_hw; 246 runtime->hw = emu8k_pcm_hw;
247 runtime->hw.buffer_bytes_max = emu->mem_size - LOOP_BLANK_SIZE * 3; 247 runtime->hw.buffer_bytes_max = emu->mem_size - LOOP_BLANK_SIZE * 3;
diff --git a/sound/isa/sb/sb8_midi.c b/sound/isa/sb/sb8_midi.c
index bd672abb4854..4affdcb78f72 100644
--- a/sound/isa/sb/sb8_midi.c
+++ b/sound/isa/sb/sb8_midi.c
@@ -138,6 +138,7 @@ static int snd_sb8dsp_midi_output_close(struct snd_rawmidi_substream *substream)
138 struct snd_sb *chip; 138 struct snd_sb *chip;
139 139
140 chip = substream->rmidi->private_data; 140 chip = substream->rmidi->private_data;
141 del_timer_sync(&chip->midi_timer);
141 spin_lock_irqsave(&chip->open_lock, flags); 142 spin_lock_irqsave(&chip->open_lock, flags);
142 chip->open &= ~(SB_OPEN_MIDI_OUTPUT | SB_OPEN_MIDI_OUTPUT_TRIGGER); 143 chip->open &= ~(SB_OPEN_MIDI_OUTPUT | SB_OPEN_MIDI_OUTPUT_TRIGGER);
143 chip->midi_substream_output = NULL; 144 chip->midi_substream_output = NULL;
@@ -209,10 +210,10 @@ static void snd_sb8dsp_midi_output_write(struct snd_rawmidi_substream *substream
209 } 210 }
210} 211}
211 212
212static void snd_sb8dsp_midi_output_timer(unsigned long data) 213static void snd_sb8dsp_midi_output_timer(struct timer_list *t)
213{ 214{
214 struct snd_rawmidi_substream *substream = (struct snd_rawmidi_substream *) data; 215 struct snd_sb *chip = from_timer(chip, t, midi_timer);
215 struct snd_sb * chip = substream->rmidi->private_data; 216 struct snd_rawmidi_substream *substream = chip->midi_substream_output;
216 unsigned long flags; 217 unsigned long flags;
217 218
218 spin_lock_irqsave(&chip->open_lock, flags); 219 spin_lock_irqsave(&chip->open_lock, flags);
@@ -230,9 +231,6 @@ static void snd_sb8dsp_midi_output_trigger(struct snd_rawmidi_substream *substre
230 spin_lock_irqsave(&chip->open_lock, flags); 231 spin_lock_irqsave(&chip->open_lock, flags);
231 if (up) { 232 if (up) {
232 if (!(chip->open & SB_OPEN_MIDI_OUTPUT_TRIGGER)) { 233 if (!(chip->open & SB_OPEN_MIDI_OUTPUT_TRIGGER)) {
233 setup_timer(&chip->midi_timer,
234 snd_sb8dsp_midi_output_timer,
235 (unsigned long) substream);
236 mod_timer(&chip->midi_timer, 1 + jiffies); 234 mod_timer(&chip->midi_timer, 1 + jiffies);
237 chip->open |= SB_OPEN_MIDI_OUTPUT_TRIGGER; 235 chip->open |= SB_OPEN_MIDI_OUTPUT_TRIGGER;
238 } 236 }
@@ -275,6 +273,7 @@ int snd_sb8dsp_midi(struct snd_sb *chip, int device)
275 if (chip->hardware >= SB_HW_20) 273 if (chip->hardware >= SB_HW_20)
276 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX; 274 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX;
277 rmidi->private_data = chip; 275 rmidi->private_data = chip;
276 timer_setup(&chip->midi_timer, snd_sb8dsp_midi_output_timer, 0);
278 chip->rmidi = rmidi; 277 chip->rmidi = rmidi;
279 return 0; 278 return 0;
280} 279}
diff --git a/sound/isa/wavefront/wavefront_midi.c b/sound/isa/wavefront/wavefront_midi.c
index 2aa05f3aaa38..556b14738970 100644
--- a/sound/isa/wavefront/wavefront_midi.c
+++ b/sound/isa/wavefront/wavefront_midi.c
@@ -349,10 +349,10 @@ static void snd_wavefront_midi_input_trigger(struct snd_rawmidi_substream *subst
349 spin_unlock_irqrestore (&midi->virtual, flags); 349 spin_unlock_irqrestore (&midi->virtual, flags);
350} 350}
351 351
352static void snd_wavefront_midi_output_timer(unsigned long data) 352static void snd_wavefront_midi_output_timer(struct timer_list *t)
353{ 353{
354 snd_wavefront_card_t *card = (snd_wavefront_card_t *)data; 354 snd_wavefront_midi_t *midi = from_timer(midi, t, timer);
355 snd_wavefront_midi_t *midi = &card->wavefront.midi; 355 snd_wavefront_card_t *card = midi->timer_card;
356 unsigned long flags; 356 unsigned long flags;
357 357
358 spin_lock_irqsave (&midi->virtual, flags); 358 spin_lock_irqsave (&midi->virtual, flags);
@@ -383,9 +383,9 @@ static void snd_wavefront_midi_output_trigger(struct snd_rawmidi_substream *subs
383 if (up) { 383 if (up) {
384 if ((midi->mode[mpu] & MPU401_MODE_OUTPUT_TRIGGER) == 0) { 384 if ((midi->mode[mpu] & MPU401_MODE_OUTPUT_TRIGGER) == 0) {
385 if (!midi->istimer) { 385 if (!midi->istimer) {
386 setup_timer(&midi->timer, 386 timer_setup(&midi->timer,
387 snd_wavefront_midi_output_timer, 387 snd_wavefront_midi_output_timer,
388 (unsigned long) substream->rmidi->card->private_data); 388 0);
389 mod_timer(&midi->timer, 1 + jiffies); 389 mod_timer(&midi->timer, 1 + jiffies);
390 } 390 }
391 midi->istimer++; 391 midi->istimer++;
diff --git a/sound/oss/CHANGELOG b/sound/oss/CHANGELOG
deleted file mode 100644
index 8706cd66ca1f..000000000000
--- a/sound/oss/CHANGELOG
+++ /dev/null
@@ -1,369 +0,0 @@
1Note these changes relate to Hannu's code and don't include the changes
2made outside of this for modularising the sound
3
4Changelog for version 3.8o
5--------------------------
6
7Since 3.8h
8- Included support for OPL3-SA1 and SoftOSS
9
10Since 3.8
11- Fixed SNDCTL_DSP_GETOSPACE
12- Compatibility fixes for Linux 2.1.47
13
14Since 3.8-beta21
15- Fixed all known bugs (I think).
16
17Since 3.8-beta8
18- Lot of fixes to audio playback code in dmabuf.c
19
20Since 3.8-beta6
21- Fixed the famous Quake delay bug.
22
23Since 3.8-beta5
24- Fixed many bugs in audio playback.
25
26Since 3.8-beta4
27- Just minor changes.
28
29Since 3.8-beta1
30- Major rewrite of audio playback handling.
31- Added AWE32 support by Takashi Iwai (in ./lowlevel/).
32
33Since 3.7-beta#
34- Passing of ioctl() parameters between soundcard.c and other modules has been
35changed so that arg always points to kernel space.
36- Some bugfixes.
37
38Since 3.7-beta5
39- Disabled MIDI input with GUS PnP (Interwave). There seems to be constant
40stream of received 0x00 bytes when the MIDI receiver is enabled.
41
42Since 3.5
43- Changes almost everywhere.
44- Support for OPTi 82C924-based sound cards.
45
46Since 3.5.4-beta8
47- Fixed a bug in handling of non-fragment sized writes in 16 bit/stereo mode
48 with GUS.
49- Limited minimum fragment size with some audio devices (GUS=512 and
50 SB=32). These devices require more time to "recover" from processing
51 of each fragment.
52
53Since 3.5.4-beta6/7
54- There seems to be problems in the OPTi 82C930 so cards based on this
55 chip don't necessarily work yet. There are problems in detecting the
56 MIDI interface. Also mixer volumes may be seriously wrong on some systems.
57 You can safely use this driver version with C930 if it looks to work.
58 However please don't complain if you have problems with it. C930 support
59 should be fixed in future releases.
60- Got initialization of GUS PnP to work. With this version GUS PnP should
61 work in GUS compatible mode after initialization using isapnptools.
62- Fixed a bug in handling of full duplex cards in write only mode. This has
63 been causing "audio device opening" errors with RealAudio player.
64
65Since 3.5.4.beta5
66- Changes to OPTi 82C930 driver.
67- Major changes to the Soundscape driver. The driver requires now just one
68 DMA channel. The extra audio/dsp device (the "Not functional" one) used
69 for code download in the earlier versions has been eliminated. There is now
70 just one /dev/dsp# device which is used both for code download and audio.
71
72Since 3.5.4.beta4
73- Minor changes.
74
75Since 3.5.4-beta2
76- Fixed silent playback with ESS 688/1688.
77- Got SB16 to work without the 16 bit DMA channel (only the 8 bit one
78 is required for 8 and 16 bit modes).
79- Added the "lowlevel" subdirectory for additional low level drivers that
80 are not part of USS core. See lowlevel/README for more info.
81- Included support for ACI mixer (by Markus Kuhn). ACI is a mixer used in
82 miroPCM sound cards. See lowlevel/aci.readme for more info.
83- Support for Aztech Washington chipset (AZT2316 ASIC).
84
85Since 3.5.4-beta1
86- Reduced clicking with AD1848.
87- Support for OPTi 82C930. Only half duplex at this time. 16 bit playback
88 is sometimes just white noise (occurs randomly).
89
90Since 3.5.2
91- Major changes to the SB/Jazz16/ESS driver (most parts rewritten).
92 The most noticeable new feature is support for multiple SB cards at the same
93 time.
94- Renamed sb16_midi.c to uart401.c. Also modified it to work also with
95 other MPU401 UART compatible cards than SB16/ESS/Jazz.
96- Some changes which reduce clicking in audio playback.
97- Copying policy is now GPL.
98
99Since 3.5.1
100- TB Maui initialization support
101Since 3.5
102- Improved handling of playback underrun situations.
103
104Since 3.5-beta10
105- Bug fixing
106
107Since 3.5-beta9
108- Fixed for compatibility with Linux 1.3.70 and later.
109- Changed boot time passing of 16 bit DMA channel number to SB driver.
110
111Since 3.5-beta8
112- Minor changes
113
114Since 3.5-beta7
115- enhancements to configure program (by Jeff Tranter):
116 - prompts are in same format as 1.3.x Linux kernel config program
117 - on-line help for each question
118 - fixed some compile warnings detected by gcc/g++ -Wall
119 - minor grammatical changes to prompts
120
121Since 3.5-beta6
122- Fixed bugs in mmap() support.
123- Minor changes to Maui driver.
124
125Since 3.5-beta5
126- Fixed crash after recording with ESS688. It's generally a good
127 idea to stop inbound DMA transfers before freeing the memory
128 buffer.
129- Fixed handling of AD1845 codec (for example Shuttle Sound System).
130- Few other fixes.
131
132Since 3.5-beta4
133- Fixed bug in handling of uninitialized instruments with GUS.
134
135Since 3.5-beta3
136- Few changes which decrease popping at end/beginning of audio playback.
137
138Since 3.5-beta2
139- Removed MAD16+CS4231 hack made in previous version since it didn't
140 help.
141- Fixed the above bug in proper way and in proper place. Many thanks
142 to James Hightower.
143
144Since 3.5-beta1
145- Bug fixes.
146- Full duplex audio with MAD16+CS4231 may work now. The driver configures
147 SB DMA of MAD16 so that it doesn't conflict with codec's DMA channels.
148 The side effect is that all 8 bit DMA channels (0,1,3) are populated in
149 duplex mode.
150
151Since 3.5-alpha9
152- Bug fixes (mostly in Jazz16 and ESS1688/688 supports).
153- Temporarily disabled recording with ESS1688/688 since it causes crash.
154- Changed audio buffer partitioning algorithm so that it selects
155 smaller fragment size than earlier. This improves real time capabilities
156 of the driver and makes recording to disk to work better. Unfortunately
157 this change breaks some programs which assume that fragments cannot be
158 shorter than 4096 bytes.
159
160Since 3.5-alpha8
161- Bug fixes
162
163Since 3.5-alpha7
164- Linux kernel compatible configuration (_EXPERIMENTAL_). Enable
165 using command "cd /linux/drivers/sound;make script" and then
166 just run kernel's make config normally.
167- Minor fixes to the SB support. Hopefully the driver works with
168 all SB models now.
169- Added support for ESS ES1688 "AudioDrive" based cards.
170
171Since 3.5-alpha6
172- SB Pro and SB16 supports are no longer separately selectable options.
173 Enabling SB enables them too.
174- Changed all #ifndef EXCLUDE_xx stuff to #ifdef CONFIG_xx. Modified
175configure to handle this.
176- Removed initialization messages from the
177modularized version. They can be enabled by using init_trace=1 in
178the insmod command line (insmod sound init_trace=1).
179- More AIX stuff.
180- Added support for synchronizing dsp/audio devices with /dev/sequencer.
181- mmap() support for dsp/audio devices.
182
183Since 3.5-alpha5
184- AIX port.
185- Changed some xxx_PATCH macros in soundcard.h to work with
186 big endian machines.
187
188Since 3.5-alpha4
189- Removed the 'setfx' stuff from the version distributed with kernel
190 sources. Running 'setfx' is required again.
191
192Since 3.5-alpha3
193- Moved stuff from the 'setfx' program to the AudioTrix Pro driver.
194
195Since 3.5-alpha2
196- Modifications to makefile and configure.c. Unnecessary sources
197 are no longer compiled. Newly created local.h is also copied to
198 /etc/soundconf. "make oldconfig" reads /etc/soundconf and produces
199 new local.h which is compatible with current version of the driver.
200- Some fixes to the SB16 support.
201- Fixed random protection fault in gus_wave.c
202
203Since 3.5-alpha1
204- Modified to work with Linux-1.3.33 and later
205- Some minor changes
206
207Since 3.0.2
208- Support for CS4232 based PnP cards (AcerMagic S23 etc).
209- Full duplex support for some CS4231, CS4232 and AD1845 based cards
210(GUS MAX, AudioTrix Pro, AcerMagic S23 and many MAD16/Mozart cards
211having a codec mentioned above).
212- Almost fully rewritten loadable modules support.
213- Fixed some bugs.
214- Huge amount of testing (more testing is still required).
215- mmap() support (works with some cards). Requires much more testing.
216- Sample/patch/program loading for TB Maui/Tropez. No initialization
217since TB doesn't allow me to release that code.
218- Using CS4231 compatible codecs as timer for /dev/music.
219
220Since 3.0.1
221- Added allocation of I/O ports, DMA channels and interrupts
222to the initialization code. This may break modules support since
223the driver may not free some resources on unload. Should be fixed soon.
224
225Since 3.0
226- Some important bug fixes.
227- select() for /dev/dsp and /dev/audio (Linux only).
228(To use select() with read, you have to call read() to start
229the recording. Calling write() kills recording immediately so
230use select() carefully when you are writing a half duplex app.
231Full duplex mode is not implemented yet.) Select works also with
232/dev/sequencer and /dev/music. Maybe with /dev/midi## too.
233
234Since 3.0-beta2
235- Minor fixes.
236- Added Readme.cards
237
238Since 3.0-beta1
239- Minor fixes to the modules support.
240- Eliminated call to sb_free_irq() in ad1848.c
241- Rewritten MAD16&Mozart support (not tested with MAD16 Pro).
242- Fix to DMA initialization of PSS cards.
243- Some fixes to ad1848/cs42xx mixer support (GUS MAX, MSS, etc.)
244- Fixed some bugs in the PSS driver which caused I/O errors with
245 the MSS mode (/dev/dsp).
246
247Since 3.0-950506
248- Recording with GUS MAX fixed. It works when the driver is configured
249 to use two DMA channels with GUS MAX (16 bit ones recommended).
250
251Since 3.0-94xxxx
252- Too many changes
253
254Since 3.0-940818
255- Fixes for Linux 1.1.4x.
256- Disables Disney Sound System with SG NX Pro 16 (less noise).
257
258Since 2.90-2
259- Fixes to soundcard.h
260- Non blocking mode to /dev/sequencer
261- Experimental detection code for Ensoniq Soundscape.
262
263Since 2.90
264- Minor and major bug fixes
265
266Since pre-3.0-940712
267- GUS MAX support
268- Partially working MSS/WSS support (could work with some cards).
269- Hardware u-Law and A-Law support with AD1848/CS4248 and CS4231 codecs
270 (GUS MAX, GUS16, WSS etc). Hardware ADPCM is possible with GUS16 and
271 GUS MAX, but it doesn't work yet.
272Since pre-3.0-940426
273- AD1848/CS4248/CS4231 codec support (MSS, GUS MAX, Aztec, Orchid etc).
274This codec chip is used in various sound cards. This version is developed
275for the 16 bit daughtercard of GUS. It should work with other cards also
276if the following requirements are met:
277 - The I/O, IRQ and DMA settings are jumper selectable or
278 the card is initialized by booting DOS before booting Linux (etc.).
279 - You add the IO, IRQ and DMA settings manually to the local.h.
280 (Just define GUS16_BASE, GUS16_IRQ and GUS16_DMA). Note that
281 the base address bust be the base address of the codec chip not the
282 card itself. For the GUS16 these are the same but most MSS compatible
283 cards have the codec located at card_base+4.
284- Some minor changes
285
286Since 2.5 (******* MAJOR REWRITE ***********)
287
288This version is based on v2.3. I have tried to maintain two versions
289together so that this one should have the same features than v2.5.
290Something may still be missing. If you notice such things, please let me
291know.
292
293The Readme.v30 contains more details.
294
295- /dev/midi## devices.
296- /dev/sequencer2
297
298Since 2.5-beta2
299- Some fine tuning to the GUS v3.7 mixer code.
300- Fixed speed limits for the plain SB (1.0 to 2.0).
301
302Since 2.5-beta
303- Fixed OPL-3 detection with SB. Caused problems with PAS16.
304- GUS v3.7 mixer support.
305
306Since 2.4
307- Mixer support for Sound Galaxy NX Pro (define __SGNXPRO__ on your local.h).
308- Fixed truncated sound on /dev/dsp when the device is closed.
309- Linear volume mode for GUS
310- Pitch bends larger than +/- 2 octaves.
311- MIDI recording for SB and SB Pro. (Untested).
312- Some other fixes.
313- SB16 MIDI and DSP drivers only initialized if SB16 actually installed.
314- Implemented better detection for OPL-3. This should be useful if you
315 have an old SB Pro (the non-OPL-3 one) or a SB 2.0 clone which has a OPL-3.
316- SVR4.2 support by Ian Hartas. Initial ALPHA TEST version (untested).
317
318Since 2.3b
319- Fixed bug which made it impossible to make long recordings to disk.
320 Recording was not restarted after a buffer overflow situation.
321- Limited mixer support for GUS.
322- Numerous improvements to the GUS driver by Andrew Robinson. Including
323 some click removal etc.
324
325Since 2.3
326- Fixed some minor bugs in the SB16 driver.
327
328Since 2.2b
329- Full SB16 DSP support. 8/16 bit, mono/stereo
330- The SCO and FreeBSD versions should be in sync now. There are some
331 problems with SB16 and GUS in the FreeBSD versions.
332 The DMA buffer allocation of the SCO version has been polished but
333 there could still be some problems. At least it hogs memory.
334 The DMA channel
335 configuration method used in the SCO/System is a hack.
336- Support for the MPU emulation of the SB16.
337- Some big arrays are now allocated boot time. This makes the BSS segment
338 smaller which makes it possible to use the full driver with
339 NetBSD. These arrays are not allocated if no suitable sound card is available.
340- Fixed a bug in the compute_and_set_volume in gus_wave.c
341- Fixed the too fast mono playback problem of SB Pro and PAS16.
342
343Since 2.2
344- Stereo recording for SB Pro. Somehow it was missing and nobody
345 had noticed it earlier.
346- Minor polishing.
347- Interpreting of boot time arguments (sound=) for Linux.
348- Breakup of sb_dsp.c. Parts of the code has been moved to
349 sb_mixer.c and sb_midi.c
350
351Since 2.1
352- Preliminary support for SB16.
353 - The SB16 mixer is supported in its native mode.
354 - Digitized voice capability up to 44.1 kHz/8 bit/mono
355 (16 bit and stereo support coming in the next release).
356- Fixed some bugs in the digitized voice driver for PAS16.
357- Proper initialization of the SB emulation of latest PAS16 models.
358
359- Significantly improved /dev/dsp and /dev/audio support.
360 - Now supports half duplex mode. It's now possible to record and
361 playback without closing and reopening the device.
362 - It's possible to use smaller buffers than earlier. There is a new
363 ioctl(fd, SNDCTL_DSP_SUBDIVIDE, &n) where n should be 1, 2 or 4.
364 This call instructs the driver to use smaller buffers. The default
365 buffer size (0.5 to 1.0 seconds) is divided by n. Should be called
366 immediately after opening the device.
367
368Since 2.0
369Just cosmetic changes.
diff --git a/sound/oss/Kconfig b/sound/oss/Kconfig
deleted file mode 100644
index 4033fe58f0cf..000000000000
--- a/sound/oss/Kconfig
+++ /dev/null
@@ -1,533 +0,0 @@
1# 18 Apr 1998, Michael Elizabeth Chastain, <mailto:mec@shout.net>
2# More hacking for modularisation.
3#
4# Prompt user for primary drivers.
5
6config SOUND_BCM_CS4297A
7 tristate "Crystal Sound CS4297a (for Swarm)"
8 depends on SIBYTE_SWARM
9 help
10 The BCM91250A has a Crystal CS4297a on synchronous serial
11 port B (in addition to the DB-9 serial port). Say Y or M
12 here to enable the sound chip instead of the UART. Also
13 note that CONFIG_KGDB should not be enabled at the same
14 time, since it also attempts to use this UART port.
15
16config SOUND_MSNDCLAS
17 tristate "Support for Turtle Beach MultiSound Classic, Tahiti, Monterey"
18 depends on (m || !STANDALONE) && ISA
19 help
20 Say M here if you have a Turtle Beach MultiSound Classic, Tahiti or
21 Monterey (not for the Pinnacle or Fiji).
22
23 See <file:Documentation/sound/oss/MultiSound> for important information
24 about this driver. Note that it has been discontinued, but the
25 Voyetra Turtle Beach knowledge base entry for it is still available
26 at <http://www.turtlebeach.com/site/kb_ftp/790.asp>.
27
28comment "Compiled-in MSND Classic support requires firmware during compilation."
29 depends on SOUND_PRIME && SOUND_MSNDCLAS=y
30
31config MSNDCLAS_HAVE_BOOT
32 bool
33 depends on SOUND_MSNDCLAS=y && !STANDALONE
34 default y
35
36config MSNDCLAS_INIT_FILE
37 string "Full pathname of MSNDINIT.BIN firmware file"
38 depends on SOUND_MSNDCLAS
39 default "/etc/sound/msndinit.bin"
40 help
41 The MultiSound cards have two firmware files which are required for
42 operation, and are not currently included. These files can be
43 obtained from Turtle Beach. See
44 <file:Documentation/sound/oss/MultiSound> for information on how to
45 obtain this.
46
47config MSNDCLAS_PERM_FILE
48 string "Full pathname of MSNDPERM.BIN firmware file"
49 depends on SOUND_MSNDCLAS
50 default "/etc/sound/msndperm.bin"
51 help
52 The MultiSound cards have two firmware files which are required for
53 operation, and are not currently included. These files can be
54 obtained from Turtle Beach. See
55 <file:Documentation/sound/oss/MultiSound> for information on how to
56 obtain this.
57
58config MSNDCLAS_IRQ
59 int "MSND Classic IRQ 5, 7, 9, 10, 11, 12"
60 depends on SOUND_MSNDCLAS=y
61 default "5"
62 help
63 Interrupt Request line for the MultiSound Classic and related cards.
64
65config MSNDCLAS_MEM
66 hex "MSND Classic memory B0000, C8000, D0000, D8000, E0000, E8000"
67 depends on SOUND_MSNDCLAS=y
68 default "D0000"
69 help
70 Memory-mapped I/O base address for the MultiSound Classic and
71 related cards.
72
73config MSNDCLAS_IO
74 hex "MSND Classic I/O 210, 220, 230, 240, 250, 260, 290, 3E0"
75 depends on SOUND_MSNDCLAS=y
76 default "290"
77 help
78 I/O port address for the MultiSound Classic and related cards.
79
80config SOUND_MSNDPIN
81 tristate "Support for Turtle Beach MultiSound Pinnacle, Fiji"
82 depends on (m || !STANDALONE) && ISA
83 help
84 Say M here if you have a Turtle Beach MultiSound Pinnacle or Fiji.
85 See <file:Documentation/sound/oss/MultiSound> for important information
86 about this driver. Note that it has been discontinued, but the
87 Voyetra Turtle Beach knowledge base entry for it is still available
88 at <http://www.turtlebeach.com/site/kb_ftp/600.asp>.
89
90comment "Compiled-in MSND Pinnacle support requires firmware during compilation."
91 depends on SOUND_PRIME && SOUND_MSNDPIN=y
92
93config MSNDPIN_HAVE_BOOT
94 bool
95 depends on SOUND_MSNDPIN=y
96 default y
97
98config MSNDPIN_INIT_FILE
99 string "Full pathname of PNDSPINI.BIN firmware file"
100 depends on SOUND_MSNDPIN
101 default "/etc/sound/pndspini.bin"
102 help
103 The MultiSound cards have two firmware files which are required
104 for operation, and are not currently included. These files can be
105 obtained from Turtle Beach. See
106 <file:Documentation/sound/oss/MultiSound> for information on how to
107 obtain this.
108
109config MSNDPIN_PERM_FILE
110 string "Full pathname of PNDSPERM.BIN firmware file"
111 depends on SOUND_MSNDPIN
112 default "/etc/sound/pndsperm.bin"
113 help
114 The MultiSound cards have two firmware files which are required for
115 operation, and are not currently included. These files can be
116 obtained from Turtle Beach. See
117 <file:Documentation/sound/oss/MultiSound> for information on how to
118 obtain this.
119
120config MSNDPIN_IRQ
121 int "MSND Pinnacle IRQ 5, 7, 9, 10, 11, 12"
122 depends on SOUND_MSNDPIN=y
123 default "5"
124 help
125 Interrupt request line for the primary synthesizer on MultiSound
126 Pinnacle and Fiji sound cards.
127
128config MSNDPIN_MEM
129 hex "MSND Pinnacle memory B0000, C8000, D0000, D8000, E0000, E8000"
130 depends on SOUND_MSNDPIN=y
131 default "D0000"
132 help
133 Memory-mapped I/O base address for the primary synthesizer on
134 MultiSound Pinnacle and Fiji sound cards.
135
136config MSNDPIN_IO
137 hex "MSND Pinnacle I/O 210, 220, 230, 240, 250, 260, 290, 3E0"
138 depends on SOUND_MSNDPIN=y
139 default "290"
140 help
141 Memory-mapped I/O base address for the primary synthesizer on
142 MultiSound Pinnacle and Fiji sound cards.
143
144config MSNDPIN_DIGITAL
145 bool "MSND Pinnacle has S/PDIF I/O"
146 depends on SOUND_MSNDPIN=y
147 help
148 If you have the S/PDIF daughter board for the Pinnacle or Fiji,
149 answer Y here; otherwise, say N. If you have this, you will be able
150 to play and record from the S/PDIF port (digital signal). See
151 <file:Documentation/sound/oss/MultiSound> for information on how to make
152 use of this capability.
153
154config MSNDPIN_NONPNP
155 bool "MSND Pinnacle non-PnP Mode"
156 depends on SOUND_MSNDPIN=y
157 help
158 The Pinnacle and Fiji card resources can be configured either with
159 PnP, or through a configuration port. Say Y here if your card is NOT
160 in PnP mode. For the Pinnacle, configuration in non-PnP mode allows
161 use of the IDE and joystick peripherals on the card as well; these
162 do not show up when the card is in PnP mode. Specifying zero for any
163 resource of a device will disable the device. If you are running the
164 card in PnP mode, you must say N here and use isapnptools to
165 configure the card's resources.
166
167comment "MSND Pinnacle DSP section will be configured to above parameters."
168 depends on SOUND_MSNDPIN=y && MSNDPIN_NONPNP
169
170config MSNDPIN_CFG
171 hex "MSND Pinnacle config port 250,260,270"
172 depends on MSNDPIN_NONPNP
173 default "250"
174 help
175 This is the port which the Pinnacle and Fiji uses to configure the
176 card's resources when not in PnP mode. If your card is in PnP mode,
177 then be sure to say N to the previous option, "MSND Pinnacle Non-PnP
178 Mode".
179
180comment "Pinnacle-specific Device Configuration (0 disables)"
181 depends on SOUND_MSNDPIN=y && MSNDPIN_NONPNP
182
183config MSNDPIN_MPU_IO
184 hex "MSND Pinnacle MPU I/O (e.g. 330)"
185 depends on MSNDPIN_NONPNP
186 default "0"
187 help
188 Memory-mapped I/O base address for the Kurzweil daughterboard
189 synthesizer on MultiSound Pinnacle and Fiji sound cards.
190
191config MSNDPIN_MPU_IRQ
192 int "MSND Pinnacle MPU IRQ (e.g. 9)"
193 depends on MSNDPIN_NONPNP
194 default "0"
195 help
196 Interrupt request number for the Kurzweil daughterboard
197 synthesizer on MultiSound Pinnacle and Fiji sound cards.
198
199config MSNDPIN_IDE_IO0
200 hex "MSND Pinnacle IDE I/O 0 (e.g. 170)"
201 depends on MSNDPIN_NONPNP
202 default "0"
203 help
204 CD-ROM drive 0 memory-mapped I/O base address for the MultiSound
205 Pinnacle and Fiji sound cards.
206
207config MSNDPIN_IDE_IO1
208 hex "MSND Pinnacle IDE I/O 1 (e.g. 376)"
209 depends on MSNDPIN_NONPNP
210 default "0"
211 help
212 CD-ROM drive 1 memory-mapped I/O base address for the MultiSound
213 Pinnacle and Fiji sound cards.
214
215config MSNDPIN_IDE_IRQ
216 int "MSND Pinnacle IDE IRQ (e.g. 15)"
217 depends on MSNDPIN_NONPNP
218 default "0"
219 help
220 Interrupt request number for the IDE CD-ROM interface on the
221 MultiSound Pinnacle and Fiji sound cards.
222
223config MSNDPIN_JOYSTICK_IO
224 hex "MSND Pinnacle joystick I/O (e.g. 200)"
225 depends on MSNDPIN_NONPNP
226 default "0"
227 help
228 Memory-mapped I/O base address for the joystick port on MultiSound
229 Pinnacle and Fiji sound cards.
230
231config MSND_FIFOSIZE
232 int "MSND buffer size (kB)"
233 depends on SOUND_MSNDPIN=y || SOUND_MSNDCLAS=y
234 default "128"
235 help
236 Configures the size of each audio buffer, in kilobytes, for
237 recording and playing in the MultiSound drivers (both the Classic
238 and Pinnacle). Larger values reduce the chance of data overruns at
239 the expense of overall latency. If unsure, use the default.
240
241menuconfig SOUND_OSS
242 tristate "OSS sound modules"
243 depends on ISA_DMA_API && (VIRT_TO_BUS || ARCH_RPC || ARCH_NETWINDER)
244 depends on !GENERIC_ISA_DMA_SUPPORT_BROKEN
245 help
246 OSS is the Open Sound System suite of sound card drivers. They make
247 sound programming easier since they provide a common API. Say Y or
248 M here (the module will be called sound) if you haven't found a
249 driver for your sound card above, then pick your driver from the
250 list below.
251
252if SOUND_OSS
253
254config SOUND_TRACEINIT
255 bool "Verbose initialisation"
256 help
257 Verbose soundcard initialization -- affects the format of autoprobe
258 and initialization messages at boot time.
259
260config SOUND_DMAP
261 bool "Persistent DMA buffers"
262 ---help---
263 Linux can often have problems allocating DMA buffers for ISA sound
264 cards on machines with more than 16MB of RAM. This is because ISA
265 DMA buffers must exist below the 16MB boundary and it is quite
266 possible that a large enough free block in this region cannot be
267 found after the machine has been running for a while. If you say Y
268 here the DMA buffers (64Kb) will be allocated at boot time and kept
269 until the shutdown. This option is only useful if you said Y to
270 "OSS sound modules", above. If you said M to "OSS sound modules"
271 then you can get the persistent DMA buffer functionality by passing
272 the command-line argument "dmabuf=1" to the sound module.
273
274 Say Y unless you have 16MB or more RAM or a PCI sound card.
275
276config SOUND_VMIDI
277 tristate "Loopback MIDI device support"
278 help
279 Support for MIDI loopback on port 1 or 2.
280
281config SOUND_TRIX
282 tristate "MediaTrix AudioTrix Pro support"
283 help
284 Answer Y if you have the AudioTriX Pro sound card manufactured
285 by MediaTrix.
286
287config TRIX_HAVE_BOOT
288 bool "Have TRXPRO.HEX firmware file"
289 depends on SOUND_TRIX=y && !STANDALONE
290 help
291 The MediaTrix AudioTrix Pro has an on-board microcontroller which
292 needs to be initialized by downloading the code from the file
293 TRXPRO.HEX in the DOS driver directory. If you don't have the
294 TRXPRO.HEX file handy you may skip this step. However, the SB and
295 MPU-401 modes of AudioTrix Pro will not work without this file!
296
297config TRIX_BOOT_FILE
298 string "Full pathname of TRXPRO.HEX firmware file"
299 depends on TRIX_HAVE_BOOT
300 default "/etc/sound/trxpro.hex"
301 help
302 Enter the full pathname of your TRXPRO.HEX file, starting from /.
303
304config SOUND_MSS
305 tristate "Microsoft Sound System support"
306 ---help---
307 Again think carefully before answering Y to this question. It's
308 safe to answer Y if you have the original Windows Sound System card
309 made by Microsoft or Aztech SG 16 Pro (or NX16 Pro). Also you may
310 say Y in case your card is NOT among these:
311
312 ATI Stereo F/X, AdLib, Audio Excell DSP16, Cardinal DSP16,
313 Ensoniq SoundScape (and compatibles made by Reveal and Spea),
314 Gravis Ultrasound, Gravis Ultrasound ACE, Gravis Ultrasound Max,
315 Gravis Ultrasound with 16 bit option, Logitech Sound Man 16,
316 Logitech SoundMan Games, Logitech SoundMan Wave, MAD16 Pro (OPTi
317 82C929), Media Vision Jazz16, MediaTriX AudioTriX Pro, Microsoft
318 Windows Sound System (MSS/WSS), Mozart (OAK OTI-601), Orchid
319 SW32, Personal Sound System (PSS), Pro Audio Spectrum 16, Pro
320 Audio Studio 16, Pro Sonic 16, Roland MPU-401 MIDI interface,
321 Sound Blaster 1.0, Sound Blaster 16, Sound Blaster 16ASP, Sound
322 Blaster 2.0, Sound Blaster AWE32, Sound Blaster Pro, TI TM4000M
323 notebook, ThunderBoard, Turtle Beach Tropez, Yamaha FM
324 synthesizers (OPL2, OPL3 and OPL4), 6850 UART MIDI Interface.
325
326 For cards having native support in VoxWare, consult the card
327 specific instructions in <file:Documentation/sound/oss/README.OSS>.
328 Some drivers have their own MSS support and saying Y to this option
329 will cause a conflict.
330
331 If you compile the driver into the kernel, you have to add
332 "ad1848=<io>,<irq>,<dma>,<dma2>[,<type>]" to the kernel command
333 line.
334
335config SOUND_MPU401
336 tristate "MPU-401 support (NOT for SB16)"
337 ---help---
338 Be careful with this question. The MPU401 interface is supported by
339 all sound cards. However, some natively supported cards have their
340 own driver for MPU401. Enabling this MPU401 option with these cards
341 will cause a conflict. Also, enabling MPU401 on a system that
342 doesn't really have a MPU401 could cause some trouble. If your card
343 was in the list of supported cards, look at the card specific
344 instructions in the <file:Documentation/sound/oss/README.OSS> file. It
345 is safe to answer Y if you have a true MPU401 MIDI interface card.
346
347 If you compile the driver into the kernel, you have to add
348 "mpu401=<io>,<irq>" to the kernel command line.
349
350config SOUND_PAS
351 tristate "ProAudioSpectrum 16 support"
352 ---help---
353 Answer Y only if you have a Pro Audio Spectrum 16, ProAudio Studio
354 16 or Logitech SoundMan 16 sound card. Answer N if you have some
355 other card made by Media Vision or Logitech since those are not
356 PAS16 compatible. Please read <file:Documentation/sound/oss/PAS16>.
357 It is not necessary to add Sound Blaster support separately; it
358 is included in PAS support.
359
360 If you compile the driver into the kernel, you have to add
361 "pas2=<io>,<irq>,<dma>,<dma2>,<sbio>,<sbirq>,<sbdma>,<sbdma2>
362 to the kernel command line.
363
364config PAS_JOYSTICK
365 bool "Enable PAS16 joystick port"
366 depends on SOUND_PAS=y
367 help
368 Say Y here to enable the Pro Audio Spectrum 16's auxiliary joystick
369 port.
370
371config SOUND_PSS
372 tristate "PSS (AD1848, ADSP-2115, ESC614) support"
373 help
374 Answer Y or M if you have an Orchid SW32, Cardinal DSP16, Beethoven
375 ADSP-16 or some other card based on the PSS chipset (AD1848 codec +
376 ADSP-2115 DSP chip + Echo ESC614 ASIC CHIP). For more information on
377 how to compile it into the kernel or as a module see the file
378 <file:Documentation/sound/oss/PSS>.
379
380 If you compile the driver into the kernel, you have to add
381 "pss=<io>,<mssio>,<mssirq>,<mssdma>,<mpuio>,<mpuirq>" to the kernel
382 command line.
383
384config PSS_MIXER
385 bool "Enable PSS mixer (Beethoven ADSP-16 and other compatible)"
386 depends on SOUND_PSS
387 help
388 Answer Y for Beethoven ADSP-16. You may try to say Y also for other
389 cards if they have master volume, bass, treble, and you can't
390 control it under Linux. If you answer N for Beethoven ADSP-16, you
391 can't control master volume, bass, treble and synth volume.
392
393 If you said M to "PSS support" above, you may enable or disable this
394 PSS mixer with the module parameter pss_mixer. For more information
395 see the file <file:Documentation/sound/oss/PSS>.
396
397config PSS_HAVE_BOOT
398 bool "Have DSPxxx.LD firmware file"
399 depends on SOUND_PSS && !STANDALONE
400 help
401 If you have the DSPxxx.LD file or SYNTH.LD file for you card, say Y
402 to include this file. Without this file the synth device (OPL) may
403 not work.
404
405config PSS_BOOT_FILE
406 string "Full pathname of DSPxxx.LD firmware file"
407 depends on PSS_HAVE_BOOT
408 default "/etc/sound/dsp001.ld"
409 help
410 Enter the full pathname of your DSPxxx.LD file or SYNTH.LD file,
411 starting from /.
412
413config SOUND_SB
414 tristate "100% Sound Blaster compatibles (SB16/32/64, ESS, Jazz16) support"
415 ---help---
416 Answer Y if you have an original Sound Blaster card made by Creative
417 Labs or a 100% hardware compatible clone (like the Thunderboard or
418 SM Games). For an unknown card you may answer Y if the card claims
419 to be Sound Blaster-compatible.
420
421 Please read the file <file:Documentation/sound/oss/Soundblaster>.
422
423 You should also say Y here for cards based on the Avance Logic
424 ALS-007 and ALS-1X0 chips (read <file:Documentation/sound/oss/ALS>) and
425 for cards based on ESS chips (read
426 <file:Documentation/sound/oss/ESS1868> and
427 <file:Documentation/sound/oss/ESS>). If you have an IBM Mwave
428 card, say Y here and read <file:Documentation/sound/oss/mwave>.
429
430 If you compile the driver into the kernel and don't want to use
431 isapnp, you have to add "sb=<io>,<irq>,<dma>,<dma2>" to the kernel
432 command line.
433
434 You can say M here to compile this driver as a module; the module is
435 called sb.
436
437config SOUND_YM3812
438 tristate "Yamaha FM synthesizer (YM3812/OPL-3) support"
439 ---help---
440 Answer Y if your card has a FM chip made by Yamaha (OPL2/OPL3/OPL4).
441 Answering Y is usually a safe and recommended choice, however some
442 cards may have software (TSR) FM emulation. Enabling FM support with
443 these cards may cause trouble (I don't currently know of any such
444 cards, however). Please read the file
445 <file:Documentation/sound/oss/OPL3> if your card has an OPL3 chip.
446
447 If you compile the driver into the kernel, you have to add
448 "opl3=<io>" to the kernel command line.
449
450 If unsure, say Y.
451
452config SOUND_UART6850
453 tristate "6850 UART support"
454 help
455 This option enables support for MIDI interfaces based on the 6850
456 UART chip. This interface is rarely found on sound cards. It's safe
457 to answer N to this question.
458
459 If you compile the driver into the kernel, you have to add
460 "uart6850=<io>,<irq>" to the kernel command line.
461
462config SOUND_AEDSP16
463 tristate "Gallant Audio Cards (SC-6000 and SC-6600 based)"
464 ---help---
465 Answer Y if you have a Gallant's Audio Excel DSP 16 card. This
466 driver supports Audio Excel DSP 16 but not the III nor PnP versions
467 of this card.
468
469 The Gallant's Audio Excel DSP 16 card can emulate either an SBPro or
470 a Microsoft Sound System card, so you should have said Y to either
471 "100% Sound Blaster compatibles (SB16/32/64, ESS, Jazz16) support"
472 or "Microsoft Sound System support", above, and you need to answer
473 the "MSS emulation" and "SBPro emulation" questions below
474 accordingly. You should say Y to one and only one of these two
475 questions.
476
477 Read the <file:Documentation/sound/oss/README.OSS> file and the head of
478 <file:sound/oss/aedsp16.c> as well as
479 <file:Documentation/sound/oss/AudioExcelDSP16> to get more information
480 about this driver and its configuration.
481
482config SC6600
483 bool "SC-6600 based audio cards (new Audio Excel DSP 16)"
484 depends on SOUND_AEDSP16
485 help
486 The SC6600 is the new version of DSP mounted on the Audio Excel DSP
487 16 cards. Find in the manual the FCC ID of your audio card and
488 answer Y if you have an SC6600 DSP.
489
490config SC6600_JOY
491 bool "Activate SC-6600 Joystick Interface"
492 depends on SC6600
493 help
494 Say Y here in order to use the joystick interface of the Audio Excel
495 DSP 16 card.
496
497config SC6600_CDROM
498 int "SC-6600 CDROM Interface (4=None, 3=IDE, 1=Panasonic, 0=?Sony?)"
499 depends on SC6600
500 default "4"
501 help
502 This is used to activate the CD-ROM interface of the Audio Excel
503 DSP 16 card. Enter: 0 for Sony, 1 for Panasonic, 2 for IDE, 4 for no
504 CD-ROM present.
505
506config SC6600_CDROMBASE
507 hex "SC-6600 CDROM Interface I/O Address"
508 depends on SC6600
509 default "0"
510 help
511 Base I/O port address for the CD-ROM interface of the Audio Excel
512 DSP 16 card.
513
514config SOUND_VIDC
515 tristate "VIDC 16-bit sound"
516 depends on ARM && ARCH_ACORN
517 help
518 16-bit support for the VIDC onboard sound hardware found on Acorn
519 machines.
520
521config SOUND_WAVEARTIST
522 tristate "Netwinder WaveArtist"
523 depends on ARM && ARCH_NETWINDER
524 help
525 Say Y here to include support for the Rockwell WaveArtist sound
526 system. This driver is mainly for the NetWinder.
527
528config SOUND_KAHLUA
529 tristate "XpressAudio Sound Blaster emulation"
530 depends on SOUND_SB
531
532endif # SOUND_OSS
533
diff --git a/sound/oss/Makefile b/sound/oss/Makefile
deleted file mode 100644
index 6564eace4749..000000000000
--- a/sound/oss/Makefile
+++ /dev/null
@@ -1,108 +0,0 @@
1# SPDX-License-Identifier: GPL-2.0
2# Makefile for the Linux sound card driver
3#
4# 18 Apr 1998, Michael Elizabeth Chastain, <mailto:mec@shout.net>
5# Rewritten to use lists instead of if-statements.
6
7# Each configuration option enables a list of files.
8
9obj-$(CONFIG_SOUND_OSS) += sound.o
10
11# Please leave it as is, cause the link order is significant !
12
13obj-$(CONFIG_SOUND_AEDSP16) += aedsp16.o
14obj-$(CONFIG_SOUND_PSS) += pss.o ad1848.o mpu401.o
15obj-$(CONFIG_SOUND_TRIX) += trix.o ad1848.o sb_lib.o uart401.o
16obj-$(CONFIG_SOUND_MSS) += ad1848.o
17obj-$(CONFIG_SOUND_PAS) += pas2.o sb.o sb_lib.o uart401.o
18obj-$(CONFIG_SOUND_SB) += sb.o sb_lib.o uart401.o
19obj-$(CONFIG_SOUND_KAHLUA) += kahlua.o
20obj-$(CONFIG_SOUND_MPU401) += mpu401.o
21obj-$(CONFIG_SOUND_UART6850) += uart6850.o
22obj-$(CONFIG_SOUND_YM3812) += opl3.o
23obj-$(CONFIG_SOUND_VMIDI) += v_midi.o
24obj-$(CONFIG_SOUND_VIDC) += vidc_mod.o
25obj-$(CONFIG_SOUND_WAVEARTIST) += waveartist.o
26obj-$(CONFIG_SOUND_MSNDCLAS) += msnd.o msnd_classic.o
27obj-$(CONFIG_SOUND_MSNDPIN) += msnd.o msnd_pinnacle.o
28obj-$(CONFIG_SOUND_BCM_CS4297A) += swarm_cs4297a.o
29
30obj-$(CONFIG_DMASOUND) += dmasound/
31
32# Declare multi-part drivers.
33
34sound-objs := \
35 dev_table.o soundcard.o \
36 audio.o dmabuf.o \
37 midi_synth.o midibuf.o \
38 sequencer.o sound_timer.o sys_timer.o
39
40pas2-objs := pas2_card.o pas2_midi.o pas2_mixer.o pas2_pcm.o
41sb-objs := sb_card.o
42sb_lib-objs := sb_common.o sb_audio.o sb_midi.o sb_mixer.o sb_ess.o
43vidc_mod-objs := vidc.o vidc_fill.o
44
45hostprogs-y := bin2hex hex2hex
46
47# Files generated that shall be removed upon make clean
48clean-files := msndperm.c msndinit.c pndsperm.c pndspini.c \
49 pss_boot.h trix_boot.h
50
51# Firmware files that need translation
52#
53# The translated files are protected by a file that keeps track
54# of what name was used to build them. If the name changes, they
55# will be forced to be remade.
56#
57
58# Turtle Beach MultiSound
59
60ifeq ($(CONFIG_MSNDCLAS_HAVE_BOOT),y)
61 $(obj)/msnd_classic.o: $(obj)/msndperm.c $(obj)/msndinit.c
62
63 $(obj)/msndperm.c: $(patsubst "%", %, $(CONFIG_MSNDCLAS_PERM_FILE)) $(obj)/bin2hex
64 $(obj)/bin2hex msndperm < $< > $@
65
66 $(obj)/msndinit.c: $(patsubst "%", %, $(CONFIG_MSNDCLAS_INIT_FILE)) $(obj)/bin2hex
67 $(obj)/bin2hex msndinit < $< > $@
68endif
69
70ifeq ($(CONFIG_MSNDPIN_HAVE_BOOT),y)
71 $(obj)/msnd_pinnacle.o: $(obj)/pndsperm.c $(obj)/pndspini.c
72
73 $(obj)/pndsperm.c: $(patsubst "%", %, $(CONFIG_MSNDPIN_PERM_FILE)) $(obj)/bin2hex
74 $(obj)/bin2hex pndsperm < $< > $@
75
76 $(obj)/pndspini.c: $(patsubst "%", %, $(CONFIG_MSNDPIN_INIT_FILE)) $(obj)/bin2hex
77 $(obj)/bin2hex pndspini < $< > $@
78endif
79
80# PSS (ECHO-ADI2111)
81
82$(obj)/pss.o: $(obj)/pss_boot.h
83
84ifeq ($(CONFIG_PSS_HAVE_BOOT),y)
85 $(obj)/pss_boot.h: $(patsubst "%", %, $(CONFIG_PSS_BOOT_FILE)) $(obj)/bin2hex
86 $(obj)/bin2hex pss_synth < $< > $@
87else
88 $(obj)/pss_boot.h:
89 $(Q)( \
90 echo 'static unsigned char * pss_synth = NULL;'; \
91 echo 'static int pss_synthLen = 0;'; \
92 ) > $@
93endif
94
95# MediaTrix AudioTrix Pro
96
97$(obj)/trix.o: $(obj)/trix_boot.h
98
99ifeq ($(CONFIG_TRIX_HAVE_BOOT),y)
100 $(obj)/trix_boot.h: $(patsubst "%", %, $(CONFIG_TRIX_BOOT_FILE)) $(obj)/hex2hex
101 $(obj)/hex2hex -i trix_boot < $< > $@
102else
103 $(obj)/trix_boot.h:
104 $(Q)( \
105 echo 'static unsigned char * trix_boot = NULL;'; \
106 echo 'static int trix_boot_len = 0;'; \
107 ) > $@
108endif
diff --git a/sound/oss/README.FIRST b/sound/oss/README.FIRST
deleted file mode 100644
index 90fdcf063d2d..000000000000
--- a/sound/oss/README.FIRST
+++ /dev/null
@@ -1,6 +0,0 @@
1The modular sound driver patches were funded by Red Hat Software
2(www.redhat.com). The sound driver here is thus a modified version of
3Hannu's code. Please bear that in mind when considering the appropriate
4forums for bug reporting.
5
6Alan Cox
diff --git a/sound/oss/ad1848.c b/sound/oss/ad1848.c
deleted file mode 100644
index 2421f59cf279..000000000000
--- a/sound/oss/ad1848.c
+++ /dev/null
@@ -1,3062 +0,0 @@
1/*
2 * sound/oss/ad1848.c
3 *
4 * The low level driver for the AD1848/CS4248 codec chip which
5 * is used for example in the MS Sound System.
6 *
7 * The CS4231 which is used in the GUS MAX and some other cards is
8 * upwards compatible with AD1848 and this driver is able to drive it.
9 *
10 * CS4231A and AD1845 are upward compatible with CS4231. However
11 * the new features of these chips are different.
12 *
13 * CS4232 is a PnP audio chip which contains a CS4231A (and SB, MPU).
14 * CS4232A is an improved version of CS4232.
15 *
16 *
17 *
18 * Copyright (C) by Hannu Savolainen 1993-1997
19 *
20 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
21 * Version 2 (June 1991). See the "COPYING" file distributed with this software
22 * for more info.
23 *
24 *
25 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
26 * general sleep/wakeup clean up.
27 * Alan Cox : reformatted. Fixed SMP bugs. Moved to kernel alloc/free
28 * of irqs. Use dev_id.
29 * Christoph Hellwig : adapted to module_init/module_exit
30 * Aki Laukkanen : added power management support
31 * Arnaldo C. de Melo : added missing restore_flags in ad1848_resume
32 * Miguel Freitas : added ISA PnP support
33 * Alan Cox : Added CS4236->4239 identification
34 * Daniel T. Cobra : Alernate config/mixer for later chips
35 * Alan Cox : Merged chip idents and config code
36 *
37 * TODO
38 * APM save restore assist code on IBM thinkpad
39 *
40 * Status:
41 * Tested. Believed fully functional.
42 */
43
44#include <linux/init.h>
45#include <linux/interrupt.h>
46#include <linux/module.h>
47#include <linux/stddef.h>
48#include <linux/slab.h>
49#include <linux/isapnp.h>
50#include <linux/pnp.h>
51#include <linux/spinlock.h>
52
53#include "sound_config.h"
54
55#include "ad1848.h"
56#include "ad1848_mixer.h"
57
58typedef struct
59{
60 spinlock_t lock;
61 int base;
62 int irq;
63 int dma1, dma2;
64 int dual_dma; /* 1, when two DMA channels allocated */
65 int subtype;
66 unsigned char MCE_bit;
67 unsigned char saved_regs[64]; /* Includes extended register space */
68 int debug_flag;
69
70 int audio_flags;
71 int record_dev, playback_dev;
72
73 int xfer_count;
74 int audio_mode;
75 int open_mode;
76 int intr_active;
77 char *chip_name, *name;
78 int model;
79#define MD_1848 1
80#define MD_4231 2
81#define MD_4231A 3
82#define MD_1845 4
83#define MD_4232 5
84#define MD_C930 6
85#define MD_IWAVE 7
86#define MD_4235 8 /* Crystal Audio CS4235 */
87#define MD_1845_SSCAPE 9 /* Ensoniq Soundscape PNP*/
88#define MD_4236 10 /* 4236 and higher */
89#define MD_42xB 11 /* CS 42xB */
90#define MD_4239 12 /* CS4239 */
91
92 /* Mixer parameters */
93 int recmask;
94 int supported_devices, orig_devices;
95 int supported_rec_devices, orig_rec_devices;
96 int *levels;
97 short mixer_reroute[32];
98 int dev_no;
99 volatile unsigned long timer_ticks;
100 int timer_running;
101 int irq_ok;
102 mixer_ents *mix_devices;
103 int mixer_output_port;
104} ad1848_info;
105
106typedef struct ad1848_port_info
107{
108 int open_mode;
109 int speed;
110 unsigned char speed_bits;
111 int channels;
112 int audio_format;
113 unsigned char format_bits;
114}
115ad1848_port_info;
116
117static struct address_info cfg;
118static int nr_ad1848_devs;
119
120static bool deskpro_xl;
121static bool deskpro_m;
122static bool soundpro;
123
124#ifndef EXCLUDE_TIMERS
125static int timer_installed = -1;
126#endif
127
128static int loaded;
129
130static int ad_format_mask[13 /*devc->model */ ] =
131{
132 0,
133 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW,
134 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
135 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
136 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW, /* AD1845 */
137 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
138 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
139 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
140 AFMT_U8 | AFMT_S16_LE /* CS4235 */,
141 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW /* Ensoniq Soundscape*/,
142 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
143 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
144 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM
145};
146
147static ad1848_info adev_info[MAX_AUDIO_DEV];
148
149#define io_Index_Addr(d) ((d)->base)
150#define io_Indexed_Data(d) ((d)->base+1)
151#define io_Status(d) ((d)->base+2)
152#define io_Polled_IO(d) ((d)->base+3)
153
154static struct {
155 unsigned char flags;
156#define CAP_F_TIMER 0x01
157} capabilities [10 /*devc->model */ ] = {
158 {0}
159 ,{0} /* MD_1848 */
160 ,{CAP_F_TIMER} /* MD_4231 */
161 ,{CAP_F_TIMER} /* MD_4231A */
162 ,{CAP_F_TIMER} /* MD_1845 */
163 ,{CAP_F_TIMER} /* MD_4232 */
164 ,{0} /* MD_C930 */
165 ,{CAP_F_TIMER} /* MD_IWAVE */
166 ,{0} /* MD_4235 */
167 ,{CAP_F_TIMER} /* MD_1845_SSCAPE */
168};
169
170#ifdef CONFIG_PNP
171static int isapnp = 1;
172static int isapnpjump;
173static bool reverse;
174
175static int audio_activated;
176#else
177static int isapnp;
178#endif
179
180
181
182static int ad1848_open(int dev, int mode);
183static void ad1848_close(int dev);
184static void ad1848_output_block(int dev, unsigned long buf, int count, int intrflag);
185static void ad1848_start_input(int dev, unsigned long buf, int count, int intrflag);
186static int ad1848_prepare_for_output(int dev, int bsize, int bcount);
187static int ad1848_prepare_for_input(int dev, int bsize, int bcount);
188static void ad1848_halt(int dev);
189static void ad1848_halt_input(int dev);
190static void ad1848_halt_output(int dev);
191static void ad1848_trigger(int dev, int bits);
192static irqreturn_t adintr(int irq, void *dev_id);
193
194#ifndef EXCLUDE_TIMERS
195static int ad1848_tmr_install(int dev);
196static void ad1848_tmr_reprogram(int dev);
197#endif
198
199static int ad_read(ad1848_info * devc, int reg)
200{
201 int x;
202 int timeout = 900000;
203
204 while (timeout > 0 && inb(devc->base) == 0x80) /*Are we initializing */
205 timeout--;
206
207 if(reg < 32)
208 {
209 outb(((unsigned char) (reg & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
210 x = inb(io_Indexed_Data(devc));
211 }
212 else
213 {
214 int xreg, xra;
215
216 xreg = (reg & 0xff) - 32;
217 xra = (((xreg & 0x0f) << 4) & 0xf0) | 0x08 | ((xreg & 0x10) >> 2);
218 outb(((unsigned char) (23 & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
219 outb(((unsigned char) (xra & 0xff)), io_Indexed_Data(devc));
220 x = inb(io_Indexed_Data(devc));
221 }
222
223 return x;
224}
225
226static void ad_write(ad1848_info * devc, int reg, int data)
227{
228 int timeout = 900000;
229
230 while (timeout > 0 && inb(devc->base) == 0x80) /* Are we initializing */
231 timeout--;
232
233 if(reg < 32)
234 {
235 outb(((unsigned char) (reg & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
236 outb(((unsigned char) (data & 0xff)), io_Indexed_Data(devc));
237 }
238 else
239 {
240 int xreg, xra;
241
242 xreg = (reg & 0xff) - 32;
243 xra = (((xreg & 0x0f) << 4) & 0xf0) | 0x08 | ((xreg & 0x10) >> 2);
244 outb(((unsigned char) (23 & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
245 outb(((unsigned char) (xra & 0xff)), io_Indexed_Data(devc));
246 outb((unsigned char) (data & 0xff), io_Indexed_Data(devc));
247 }
248}
249
250static void wait_for_calibration(ad1848_info * devc)
251{
252 int timeout;
253
254 /*
255 * Wait until the auto calibration process has finished.
256 *
257 * 1) Wait until the chip becomes ready (reads don't return 0x80).
258 * 2) Wait until the ACI bit of I11 gets on and then off.
259 */
260
261 timeout = 100000;
262 while (timeout > 0 && inb(devc->base) == 0x80)
263 timeout--;
264 if (inb(devc->base) & 0x80)
265 printk(KERN_WARNING "ad1848: Auto calibration timed out(1).\n");
266
267 timeout = 100;
268 while (timeout > 0 && !(ad_read(devc, 11) & 0x20))
269 timeout--;
270 if (!(ad_read(devc, 11) & 0x20))
271 return;
272
273 timeout = 80000;
274 while (timeout > 0 && (ad_read(devc, 11) & 0x20))
275 timeout--;
276 if (ad_read(devc, 11) & 0x20)
277 if ((devc->model != MD_1845) && (devc->model != MD_1845_SSCAPE))
278 printk(KERN_WARNING "ad1848: Auto calibration timed out(3).\n");
279}
280
281static void ad_mute(ad1848_info * devc)
282{
283 int i;
284 unsigned char prev;
285
286 /*
287 * Save old register settings and mute output channels
288 */
289
290 for (i = 6; i < 8; i++)
291 {
292 prev = devc->saved_regs[i] = ad_read(devc, i);
293 }
294
295}
296
297static void ad_unmute(ad1848_info * devc)
298{
299}
300
301static void ad_enter_MCE(ad1848_info * devc)
302{
303 int timeout = 1000;
304 unsigned short prev;
305
306 while (timeout > 0 && inb(devc->base) == 0x80) /*Are we initializing */
307 timeout--;
308
309 devc->MCE_bit = 0x40;
310 prev = inb(io_Index_Addr(devc));
311 if (prev & 0x40)
312 {
313 return;
314 }
315 outb((devc->MCE_bit), io_Index_Addr(devc));
316}
317
318static void ad_leave_MCE(ad1848_info * devc)
319{
320 unsigned char prev, acal;
321 int timeout = 1000;
322
323 while (timeout > 0 && inb(devc->base) == 0x80) /*Are we initializing */
324 timeout--;
325
326 acal = ad_read(devc, 9);
327
328 devc->MCE_bit = 0x00;
329 prev = inb(io_Index_Addr(devc));
330 outb((0x00), io_Index_Addr(devc)); /* Clear the MCE bit */
331
332 if ((prev & 0x40) == 0) /* Not in MCE mode */
333 {
334 return;
335 }
336 outb((0x00), io_Index_Addr(devc)); /* Clear the MCE bit */
337 if (acal & 0x08) /* Auto calibration is enabled */
338 wait_for_calibration(devc);
339}
340
341static int ad1848_set_recmask(ad1848_info * devc, int mask)
342{
343 unsigned char recdev;
344 int i, n;
345 unsigned long flags;
346
347 mask &= devc->supported_rec_devices;
348
349 /* Rename the mixer bits if necessary */
350 for (i = 0; i < 32; i++)
351 {
352 if (devc->mixer_reroute[i] != i)
353 {
354 if (mask & (1 << i))
355 {
356 mask &= ~(1 << i);
357 mask |= (1 << devc->mixer_reroute[i]);
358 }
359 }
360 }
361
362 n = 0;
363 for (i = 0; i < 32; i++) /* Count selected device bits */
364 if (mask & (1 << i))
365 n++;
366
367 spin_lock_irqsave(&devc->lock,flags);
368 if (!soundpro) {
369 if (n == 0)
370 mask = SOUND_MASK_MIC;
371 else if (n != 1) { /* Too many devices selected */
372 mask &= ~devc->recmask; /* Filter out active settings */
373
374 n = 0;
375 for (i = 0; i < 32; i++) /* Count selected device bits */
376 if (mask & (1 << i))
377 n++;
378
379 if (n != 1)
380 mask = SOUND_MASK_MIC;
381 }
382 switch (mask) {
383 case SOUND_MASK_MIC:
384 recdev = 2;
385 break;
386
387 case SOUND_MASK_LINE:
388 case SOUND_MASK_LINE3:
389 recdev = 0;
390 break;
391
392 case SOUND_MASK_CD:
393 case SOUND_MASK_LINE1:
394 recdev = 1;
395 break;
396
397 case SOUND_MASK_IMIX:
398 recdev = 3;
399 break;
400
401 default:
402 mask = SOUND_MASK_MIC;
403 recdev = 2;
404 }
405
406 recdev <<= 6;
407 ad_write(devc, 0, (ad_read(devc, 0) & 0x3f) | recdev);
408 ad_write(devc, 1, (ad_read(devc, 1) & 0x3f) | recdev);
409 } else { /* soundpro */
410 unsigned char val;
411 int set_rec_bit;
412 int j;
413
414 for (i = 0; i < 32; i++) { /* For each bit */
415 if ((devc->supported_rec_devices & (1 << i)) == 0)
416 continue; /* Device not supported */
417
418 for (j = LEFT_CHN; j <= RIGHT_CHN; j++) {
419 if (devc->mix_devices[i][j].nbits == 0) /* Inexistent channel */
420 continue;
421
422 /*
423 * This is tricky:
424 * set_rec_bit becomes 1 if the corresponding bit in mask is set
425 * then it gets flipped if the polarity is inverse
426 */
427 set_rec_bit = ((mask & (1 << i)) != 0) ^ devc->mix_devices[i][j].recpol;
428
429 val = ad_read(devc, devc->mix_devices[i][j].recreg);
430 val &= ~(1 << devc->mix_devices[i][j].recpos);
431 val |= (set_rec_bit << devc->mix_devices[i][j].recpos);
432 ad_write(devc, devc->mix_devices[i][j].recreg, val);
433 }
434 }
435 }
436 spin_unlock_irqrestore(&devc->lock,flags);
437
438 /* Rename the mixer bits back if necessary */
439 for (i = 0; i < 32; i++)
440 {
441 if (devc->mixer_reroute[i] != i)
442 {
443 if (mask & (1 << devc->mixer_reroute[i]))
444 {
445 mask &= ~(1 << devc->mixer_reroute[i]);
446 mask |= (1 << i);
447 }
448 }
449 }
450 devc->recmask = mask;
451 return mask;
452}
453
454static void oss_change_bits(ad1848_info *devc, unsigned char *regval,
455 unsigned char *muteval, int dev, int chn, int newval)
456{
457 unsigned char mask;
458 int shift;
459 int mute;
460 int mutemask;
461 int set_mute_bit;
462
463 set_mute_bit = (newval == 0) ^ devc->mix_devices[dev][chn].mutepol;
464
465 if (devc->mix_devices[dev][chn].polarity == 1) /* Reverse */
466 newval = 100 - newval;
467
468 mask = (1 << devc->mix_devices[dev][chn].nbits) - 1;
469 shift = devc->mix_devices[dev][chn].bitpos;
470
471 if (devc->mix_devices[dev][chn].mutepos == 8)
472 { /* if there is no mute bit */
473 mute = 0; /* No mute bit; do nothing special */
474 mutemask = ~0; /* No mute bit; do nothing special */
475 }
476 else
477 {
478 mute = (set_mute_bit << devc->mix_devices[dev][chn].mutepos);
479 mutemask = ~(1 << devc->mix_devices[dev][chn].mutepos);
480 }
481
482 newval = (int) ((newval * mask) + 50) / 100; /* Scale it */
483 *regval &= ~(mask << shift); /* Clear bits */
484 *regval |= (newval & mask) << shift; /* Set new value */
485
486 *muteval &= mutemask;
487 *muteval |= mute;
488}
489
490static int ad1848_mixer_get(ad1848_info * devc, int dev)
491{
492 if (!((1 << dev) & devc->supported_devices))
493 return -EINVAL;
494
495 dev = devc->mixer_reroute[dev];
496
497 return devc->levels[dev];
498}
499
500static void ad1848_mixer_set_channel(ad1848_info *devc, int dev, int value, int channel)
501{
502 int regoffs, muteregoffs;
503 unsigned char val, muteval;
504 unsigned long flags;
505
506 regoffs = devc->mix_devices[dev][channel].regno;
507 muteregoffs = devc->mix_devices[dev][channel].mutereg;
508 val = ad_read(devc, regoffs);
509
510 if (muteregoffs != regoffs) {
511 muteval = ad_read(devc, muteregoffs);
512 oss_change_bits(devc, &val, &muteval, dev, channel, value);
513 }
514 else
515 oss_change_bits(devc, &val, &val, dev, channel, value);
516
517 spin_lock_irqsave(&devc->lock,flags);
518 ad_write(devc, regoffs, val);
519 devc->saved_regs[regoffs] = val;
520 if (muteregoffs != regoffs) {
521 ad_write(devc, muteregoffs, muteval);
522 devc->saved_regs[muteregoffs] = muteval;
523 }
524 spin_unlock_irqrestore(&devc->lock,flags);
525}
526
527static int ad1848_mixer_set(ad1848_info * devc, int dev, int value)
528{
529 int left = value & 0x000000ff;
530 int right = (value & 0x0000ff00) >> 8;
531 int retvol;
532
533 if (dev > 31)
534 return -EINVAL;
535
536 if (!(devc->supported_devices & (1 << dev)))
537 return -EINVAL;
538
539 dev = devc->mixer_reroute[dev];
540
541 if (devc->mix_devices[dev][LEFT_CHN].nbits == 0)
542 return -EINVAL;
543
544 if (left > 100)
545 left = 100;
546 if (right > 100)
547 right = 100;
548
549 if (devc->mix_devices[dev][RIGHT_CHN].nbits == 0) /* Mono control */
550 right = left;
551
552 retvol = left | (right << 8);
553
554 /* Scale volumes */
555 left = mix_cvt[left];
556 right = mix_cvt[right];
557
558 devc->levels[dev] = retvol;
559
560 /*
561 * Set the left channel
562 */
563 ad1848_mixer_set_channel(devc, dev, left, LEFT_CHN);
564
565 /*
566 * Set the right channel
567 */
568 if (devc->mix_devices[dev][RIGHT_CHN].nbits == 0)
569 goto out;
570 ad1848_mixer_set_channel(devc, dev, right, RIGHT_CHN);
571
572 out:
573 return retvol;
574}
575
576static void ad1848_mixer_reset(ad1848_info * devc)
577{
578 int i;
579 char name[32];
580 unsigned long flags;
581
582 devc->mix_devices = &(ad1848_mix_devices[0]);
583
584 sprintf(name, "%s_%d", devc->chip_name, nr_ad1848_devs);
585
586 for (i = 0; i < 32; i++)
587 devc->mixer_reroute[i] = i;
588
589 devc->supported_rec_devices = MODE1_REC_DEVICES;
590
591 switch (devc->model)
592 {
593 case MD_4231:
594 case MD_4231A:
595 case MD_1845:
596 case MD_1845_SSCAPE:
597 devc->supported_devices = MODE2_MIXER_DEVICES;
598 break;
599
600 case MD_C930:
601 devc->supported_devices = C930_MIXER_DEVICES;
602 devc->mix_devices = &(c930_mix_devices[0]);
603 break;
604
605 case MD_IWAVE:
606 devc->supported_devices = MODE3_MIXER_DEVICES;
607 devc->mix_devices = &(iwave_mix_devices[0]);
608 break;
609
610 case MD_42xB:
611 case MD_4239:
612 devc->mix_devices = &(cs42xb_mix_devices[0]);
613 devc->supported_devices = MODE3_MIXER_DEVICES;
614 break;
615 case MD_4232:
616 case MD_4235:
617 case MD_4236:
618 devc->supported_devices = MODE3_MIXER_DEVICES;
619 break;
620
621 case MD_1848:
622 if (soundpro) {
623 devc->supported_devices = SPRO_MIXER_DEVICES;
624 devc->supported_rec_devices = SPRO_REC_DEVICES;
625 devc->mix_devices = &(spro_mix_devices[0]);
626 break;
627 }
628
629 default:
630 devc->supported_devices = MODE1_MIXER_DEVICES;
631 }
632
633 devc->orig_devices = devc->supported_devices;
634 devc->orig_rec_devices = devc->supported_rec_devices;
635
636 devc->levels = load_mixer_volumes(name, default_mixer_levels, 1);
637
638 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
639 {
640 if (devc->supported_devices & (1 << i))
641 ad1848_mixer_set(devc, i, devc->levels[i]);
642 }
643
644 ad1848_set_recmask(devc, SOUND_MASK_MIC);
645
646 devc->mixer_output_port = devc->levels[31] | AUDIO_HEADPHONE | AUDIO_LINE_OUT;
647
648 spin_lock_irqsave(&devc->lock,flags);
649 if (!soundpro) {
650 if (devc->mixer_output_port & AUDIO_SPEAKER)
651 ad_write(devc, 26, ad_read(devc, 26) & ~0x40); /* Unmute mono out */
652 else
653 ad_write(devc, 26, ad_read(devc, 26) | 0x40); /* Mute mono out */
654 } else {
655 /*
656 * From the "wouldn't it be nice if the mixer API had (better)
657 * support for custom stuff" category
658 */
659 /* Enable surround mode and SB16 mixer */
660 ad_write(devc, 16, 0x60);
661 }
662 spin_unlock_irqrestore(&devc->lock,flags);
663}
664
665static int ad1848_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
666{
667 ad1848_info *devc = mixer_devs[dev]->devc;
668 int val;
669
670 if (cmd == SOUND_MIXER_PRIVATE1)
671 {
672 if (get_user(val, (int __user *)arg))
673 return -EFAULT;
674
675 if (val != 0xffff)
676 {
677 unsigned long flags;
678 val &= (AUDIO_SPEAKER | AUDIO_HEADPHONE | AUDIO_LINE_OUT);
679 devc->mixer_output_port = val;
680 val |= AUDIO_HEADPHONE | AUDIO_LINE_OUT; /* Always on */
681 devc->mixer_output_port = val;
682 spin_lock_irqsave(&devc->lock,flags);
683 if (val & AUDIO_SPEAKER)
684 ad_write(devc, 26, ad_read(devc, 26) & ~0x40); /* Unmute mono out */
685 else
686 ad_write(devc, 26, ad_read(devc, 26) | 0x40); /* Mute mono out */
687 spin_unlock_irqrestore(&devc->lock,flags);
688 }
689 val = devc->mixer_output_port;
690 return put_user(val, (int __user *)arg);
691 }
692 if (cmd == SOUND_MIXER_PRIVATE2)
693 {
694 if (get_user(val, (int __user *)arg))
695 return -EFAULT;
696 return(ad1848_control(AD1848_MIXER_REROUTE, val));
697 }
698 if (((cmd >> 8) & 0xff) == 'M')
699 {
700 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
701 {
702 switch (cmd & 0xff)
703 {
704 case SOUND_MIXER_RECSRC:
705 if (get_user(val, (int __user *)arg))
706 return -EFAULT;
707 val = ad1848_set_recmask(devc, val);
708 break;
709
710 default:
711 if (get_user(val, (int __user *)arg))
712 return -EFAULT;
713 val = ad1848_mixer_set(devc, cmd & 0xff, val);
714 break;
715 }
716 return put_user(val, (int __user *)arg);
717 }
718 else
719 {
720 switch (cmd & 0xff)
721 {
722 /*
723 * Return parameters
724 */
725
726 case SOUND_MIXER_RECSRC:
727 val = devc->recmask;
728 break;
729
730 case SOUND_MIXER_DEVMASK:
731 val = devc->supported_devices;
732 break;
733
734 case SOUND_MIXER_STEREODEVS:
735 val = devc->supported_devices;
736 if (devc->model != MD_C930)
737 val &= ~(SOUND_MASK_SPEAKER | SOUND_MASK_IMIX);
738 break;
739
740 case SOUND_MIXER_RECMASK:
741 val = devc->supported_rec_devices;
742 break;
743
744 case SOUND_MIXER_CAPS:
745 val=SOUND_CAP_EXCL_INPUT;
746 break;
747
748 default:
749 val = ad1848_mixer_get(devc, cmd & 0xff);
750 break;
751 }
752 return put_user(val, (int __user *)arg);
753 }
754 }
755 else
756 return -EINVAL;
757}
758
759static int ad1848_set_speed(int dev, int arg)
760{
761 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
762 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
763
764 /*
765 * The sampling speed is encoded in the least significant nibble of I8. The
766 * LSB selects the clock source (0=24.576 MHz, 1=16.9344 MHz) and other
767 * three bits select the divisor (indirectly):
768 *
769 * The available speeds are in the following table. Keep the speeds in
770 * the increasing order.
771 */
772 typedef struct
773 {
774 int speed;
775 unsigned char bits;
776 }
777 speed_struct;
778
779 static speed_struct speed_table[] =
780 {
781 {5510, (0 << 1) | 1},
782 {5510, (0 << 1) | 1},
783 {6620, (7 << 1) | 1},
784 {8000, (0 << 1) | 0},
785 {9600, (7 << 1) | 0},
786 {11025, (1 << 1) | 1},
787 {16000, (1 << 1) | 0},
788 {18900, (2 << 1) | 1},
789 {22050, (3 << 1) | 1},
790 {27420, (2 << 1) | 0},
791 {32000, (3 << 1) | 0},
792 {33075, (6 << 1) | 1},
793 {37800, (4 << 1) | 1},
794 {44100, (5 << 1) | 1},
795 {48000, (6 << 1) | 0}
796 };
797
798 int i, n, selected = -1;
799
800 n = sizeof(speed_table) / sizeof(speed_struct);
801
802 if (arg <= 0)
803 return portc->speed;
804
805 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE) /* AD1845 has different timer than others */
806 {
807 if (arg < 4000)
808 arg = 4000;
809 if (arg > 50000)
810 arg = 50000;
811
812 portc->speed = arg;
813 portc->speed_bits = speed_table[3].bits;
814 return portc->speed;
815 }
816 if (arg < speed_table[0].speed)
817 selected = 0;
818 if (arg > speed_table[n - 1].speed)
819 selected = n - 1;
820
821 for (i = 1 /*really */ ; selected == -1 && i < n; i++)
822 {
823 if (speed_table[i].speed == arg)
824 selected = i;
825 else if (speed_table[i].speed > arg)
826 {
827 int diff1, diff2;
828
829 diff1 = arg - speed_table[i - 1].speed;
830 diff2 = speed_table[i].speed - arg;
831
832 if (diff1 < diff2)
833 selected = i - 1;
834 else
835 selected = i;
836 }
837 }
838 if (selected == -1)
839 {
840 printk(KERN_WARNING "ad1848: Can't find speed???\n");
841 selected = 3;
842 }
843 portc->speed = speed_table[selected].speed;
844 portc->speed_bits = speed_table[selected].bits;
845 return portc->speed;
846}
847
848static short ad1848_set_channels(int dev, short arg)
849{
850 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
851
852 if (arg != 1 && arg != 2)
853 return portc->channels;
854
855 portc->channels = arg;
856 return arg;
857}
858
859static unsigned int ad1848_set_bits(int dev, unsigned int arg)
860{
861 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
862 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
863
864 static struct format_tbl
865 {
866 int format;
867 unsigned char bits;
868 }
869 format2bits[] =
870 {
871 {
872 0, 0
873 }
874 ,
875 {
876 AFMT_MU_LAW, 1
877 }
878 ,
879 {
880 AFMT_A_LAW, 3
881 }
882 ,
883 {
884 AFMT_IMA_ADPCM, 5
885 }
886 ,
887 {
888 AFMT_U8, 0
889 }
890 ,
891 {
892 AFMT_S16_LE, 2
893 }
894 ,
895 {
896 AFMT_S16_BE, 6
897 }
898 ,
899 {
900 AFMT_S8, 0
901 }
902 ,
903 {
904 AFMT_U16_LE, 0
905 }
906 ,
907 {
908 AFMT_U16_BE, 0
909 }
910 };
911 int i, n = sizeof(format2bits) / sizeof(struct format_tbl);
912
913 if (arg == 0)
914 return portc->audio_format;
915
916 if (!(arg & ad_format_mask[devc->model]))
917 arg = AFMT_U8;
918
919 portc->audio_format = arg;
920
921 for (i = 0; i < n; i++)
922 if (format2bits[i].format == arg)
923 {
924 if ((portc->format_bits = format2bits[i].bits) == 0)
925 return portc->audio_format = AFMT_U8; /* Was not supported */
926
927 return arg;
928 }
929 /* Still hanging here. Something must be terribly wrong */
930 portc->format_bits = 0;
931 return portc->audio_format = AFMT_U8;
932}
933
934static struct audio_driver ad1848_audio_driver =
935{
936 .owner = THIS_MODULE,
937 .open = ad1848_open,
938 .close = ad1848_close,
939 .output_block = ad1848_output_block,
940 .start_input = ad1848_start_input,
941 .prepare_for_input = ad1848_prepare_for_input,
942 .prepare_for_output = ad1848_prepare_for_output,
943 .halt_io = ad1848_halt,
944 .halt_input = ad1848_halt_input,
945 .halt_output = ad1848_halt_output,
946 .trigger = ad1848_trigger,
947 .set_speed = ad1848_set_speed,
948 .set_bits = ad1848_set_bits,
949 .set_channels = ad1848_set_channels
950};
951
952static struct mixer_operations ad1848_mixer_operations =
953{
954 .owner = THIS_MODULE,
955 .id = "SOUNDPORT",
956 .name = "AD1848/CS4248/CS4231",
957 .ioctl = ad1848_mixer_ioctl
958};
959
960static int ad1848_open(int dev, int mode)
961{
962 ad1848_info *devc;
963 ad1848_port_info *portc;
964 unsigned long flags;
965
966 if (dev < 0 || dev >= num_audiodevs)
967 return -ENXIO;
968
969 devc = (ad1848_info *) audio_devs[dev]->devc;
970 portc = (ad1848_port_info *) audio_devs[dev]->portc;
971
972 /* here we don't have to protect against intr */
973 spin_lock(&devc->lock);
974 if (portc->open_mode || (devc->open_mode & mode))
975 {
976 spin_unlock(&devc->lock);
977 return -EBUSY;
978 }
979 devc->dual_dma = 0;
980
981 if (audio_devs[dev]->flags & DMA_DUPLEX)
982 {
983 devc->dual_dma = 1;
984 }
985 devc->intr_active = 0;
986 devc->audio_mode = 0;
987 devc->open_mode |= mode;
988 portc->open_mode = mode;
989 spin_unlock(&devc->lock);
990 ad1848_trigger(dev, 0);
991
992 if (mode & OPEN_READ)
993 devc->record_dev = dev;
994 if (mode & OPEN_WRITE)
995 devc->playback_dev = dev;
996/*
997 * Mute output until the playback really starts. This decreases clicking (hope so).
998 */
999 spin_lock_irqsave(&devc->lock,flags);
1000 ad_mute(devc);
1001 spin_unlock_irqrestore(&devc->lock,flags);
1002
1003 return 0;
1004}
1005
1006static void ad1848_close(int dev)
1007{
1008 unsigned long flags;
1009 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1010 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1011
1012 devc->intr_active = 0;
1013 ad1848_halt(dev);
1014
1015 spin_lock_irqsave(&devc->lock,flags);
1016
1017 devc->audio_mode = 0;
1018 devc->open_mode &= ~portc->open_mode;
1019 portc->open_mode = 0;
1020
1021 ad_unmute(devc);
1022 spin_unlock_irqrestore(&devc->lock,flags);
1023}
1024
1025static void ad1848_output_block(int dev, unsigned long buf, int count, int intrflag)
1026{
1027 unsigned long flags, cnt;
1028 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1029 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1030
1031 cnt = count;
1032
1033 if (portc->audio_format == AFMT_IMA_ADPCM)
1034 {
1035 cnt /= 4;
1036 }
1037 else
1038 {
1039 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE)) /* 16 bit data */
1040 cnt >>= 1;
1041 }
1042 if (portc->channels > 1)
1043 cnt >>= 1;
1044 cnt--;
1045
1046 if ((devc->audio_mode & PCM_ENABLE_OUTPUT) && (audio_devs[dev]->flags & DMA_AUTOMODE) &&
1047 intrflag &&
1048 cnt == devc->xfer_count)
1049 {
1050 devc->audio_mode |= PCM_ENABLE_OUTPUT;
1051 devc->intr_active = 1;
1052 return; /*
1053 * Auto DMA mode on. No need to react
1054 */
1055 }
1056 spin_lock_irqsave(&devc->lock,flags);
1057
1058 ad_write(devc, 15, (unsigned char) (cnt & 0xff));
1059 ad_write(devc, 14, (unsigned char) ((cnt >> 8) & 0xff));
1060
1061 devc->xfer_count = cnt;
1062 devc->audio_mode |= PCM_ENABLE_OUTPUT;
1063 devc->intr_active = 1;
1064 spin_unlock_irqrestore(&devc->lock,flags);
1065}
1066
1067static void ad1848_start_input(int dev, unsigned long buf, int count, int intrflag)
1068{
1069 unsigned long flags, cnt;
1070 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1071 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1072
1073 cnt = count;
1074 if (portc->audio_format == AFMT_IMA_ADPCM)
1075 {
1076 cnt /= 4;
1077 }
1078 else
1079 {
1080 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE)) /* 16 bit data */
1081 cnt >>= 1;
1082 }
1083 if (portc->channels > 1)
1084 cnt >>= 1;
1085 cnt--;
1086
1087 if ((devc->audio_mode & PCM_ENABLE_INPUT) && (audio_devs[dev]->flags & DMA_AUTOMODE) &&
1088 intrflag &&
1089 cnt == devc->xfer_count)
1090 {
1091 devc->audio_mode |= PCM_ENABLE_INPUT;
1092 devc->intr_active = 1;
1093 return; /*
1094 * Auto DMA mode on. No need to react
1095 */
1096 }
1097 spin_lock_irqsave(&devc->lock,flags);
1098
1099 if (devc->model == MD_1848)
1100 {
1101 ad_write(devc, 15, (unsigned char) (cnt & 0xff));
1102 ad_write(devc, 14, (unsigned char) ((cnt >> 8) & 0xff));
1103 }
1104 else
1105 {
1106 ad_write(devc, 31, (unsigned char) (cnt & 0xff));
1107 ad_write(devc, 30, (unsigned char) ((cnt >> 8) & 0xff));
1108 }
1109
1110 ad_unmute(devc);
1111
1112 devc->xfer_count = cnt;
1113 devc->audio_mode |= PCM_ENABLE_INPUT;
1114 devc->intr_active = 1;
1115 spin_unlock_irqrestore(&devc->lock,flags);
1116}
1117
1118static int ad1848_prepare_for_output(int dev, int bsize, int bcount)
1119{
1120 int timeout;
1121 unsigned char fs, old_fs, tmp = 0;
1122 unsigned long flags;
1123 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1124 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1125
1126 ad_mute(devc);
1127
1128 spin_lock_irqsave(&devc->lock,flags);
1129 fs = portc->speed_bits | (portc->format_bits << 5);
1130
1131 if (portc->channels > 1)
1132 fs |= 0x10;
1133
1134 ad_enter_MCE(devc); /* Enables changes to the format select reg */
1135
1136 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE) /* Use alternate speed select registers */
1137 {
1138 fs &= 0xf0; /* Mask off the rate select bits */
1139
1140 ad_write(devc, 22, (portc->speed >> 8) & 0xff); /* Speed MSB */
1141 ad_write(devc, 23, portc->speed & 0xff); /* Speed LSB */
1142 }
1143 old_fs = ad_read(devc, 8);
1144
1145 if (devc->model == MD_4232 || devc->model >= MD_4236)
1146 {
1147 tmp = ad_read(devc, 16);
1148 ad_write(devc, 16, tmp | 0x30);
1149 }
1150 if (devc->model == MD_IWAVE)
1151 ad_write(devc, 17, 0xc2); /* Disable variable frequency select */
1152
1153 ad_write(devc, 8, fs);
1154
1155 /*
1156 * Write to I8 starts resynchronization. Wait until it completes.
1157 */
1158
1159 timeout = 0;
1160 while (timeout < 100 && inb(devc->base) != 0x80)
1161 timeout++;
1162 timeout = 0;
1163 while (timeout < 10000 && inb(devc->base) == 0x80)
1164 timeout++;
1165
1166 if (devc->model >= MD_4232)
1167 ad_write(devc, 16, tmp & ~0x30);
1168
1169 ad_leave_MCE(devc); /*
1170 * Starts the calibration process.
1171 */
1172 spin_unlock_irqrestore(&devc->lock,flags);
1173 devc->xfer_count = 0;
1174
1175#ifndef EXCLUDE_TIMERS
1176 if (dev == timer_installed && devc->timer_running)
1177 if ((fs & 0x01) != (old_fs & 0x01))
1178 {
1179 ad1848_tmr_reprogram(dev);
1180 }
1181#endif
1182 ad1848_halt_output(dev);
1183 return 0;
1184}
1185
1186static int ad1848_prepare_for_input(int dev, int bsize, int bcount)
1187{
1188 int timeout;
1189 unsigned char fs, old_fs, tmp = 0;
1190 unsigned long flags;
1191 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1192 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1193
1194 if (devc->audio_mode)
1195 return 0;
1196
1197 spin_lock_irqsave(&devc->lock,flags);
1198 fs = portc->speed_bits | (portc->format_bits << 5);
1199
1200 if (portc->channels > 1)
1201 fs |= 0x10;
1202
1203 ad_enter_MCE(devc); /* Enables changes to the format select reg */
1204
1205 if ((devc->model == MD_1845) || (devc->model == MD_1845_SSCAPE)) /* Use alternate speed select registers */
1206 {
1207 fs &= 0xf0; /* Mask off the rate select bits */
1208
1209 ad_write(devc, 22, (portc->speed >> 8) & 0xff); /* Speed MSB */
1210 ad_write(devc, 23, portc->speed & 0xff); /* Speed LSB */
1211 }
1212 if (devc->model == MD_4232)
1213 {
1214 tmp = ad_read(devc, 16);
1215 ad_write(devc, 16, tmp | 0x30);
1216 }
1217 if (devc->model == MD_IWAVE)
1218 ad_write(devc, 17, 0xc2); /* Disable variable frequency select */
1219
1220 /*
1221 * If mode >= 2 (CS4231), set I28. It's the capture format register.
1222 */
1223
1224 if (devc->model != MD_1848)
1225 {
1226 old_fs = ad_read(devc, 28);
1227 ad_write(devc, 28, fs);
1228
1229 /*
1230 * Write to I28 starts resynchronization. Wait until it completes.
1231 */
1232
1233 timeout = 0;
1234 while (timeout < 100 && inb(devc->base) != 0x80)
1235 timeout++;
1236
1237 timeout = 0;
1238 while (timeout < 10000 && inb(devc->base) == 0x80)
1239 timeout++;
1240
1241 if (devc->model != MD_1848 && devc->model != MD_1845 && devc->model != MD_1845_SSCAPE)
1242 {
1243 /*
1244 * CS4231 compatible devices don't have separate sampling rate selection
1245 * register for recording an playback. The I8 register is shared so we have to
1246 * set the speed encoding bits of it too.
1247 */
1248 unsigned char tmp = portc->speed_bits | (ad_read(devc, 8) & 0xf0);
1249
1250 ad_write(devc, 8, tmp);
1251 /*
1252 * Write to I8 starts resynchronization. Wait until it completes.
1253 */
1254 timeout = 0;
1255 while (timeout < 100 && inb(devc->base) != 0x80)
1256 timeout++;
1257
1258 timeout = 0;
1259 while (timeout < 10000 && inb(devc->base) == 0x80)
1260 timeout++;
1261 }
1262 }
1263 else
1264 { /* For AD1848 set I8. */
1265
1266 old_fs = ad_read(devc, 8);
1267 ad_write(devc, 8, fs);
1268 /*
1269 * Write to I8 starts resynchronization. Wait until it completes.
1270 */
1271 timeout = 0;
1272 while (timeout < 100 && inb(devc->base) != 0x80)
1273 timeout++;
1274 timeout = 0;
1275 while (timeout < 10000 && inb(devc->base) == 0x80)
1276 timeout++;
1277 }
1278
1279 if (devc->model == MD_4232)
1280 ad_write(devc, 16, tmp & ~0x30);
1281
1282 ad_leave_MCE(devc); /*
1283 * Starts the calibration process.
1284 */
1285 spin_unlock_irqrestore(&devc->lock,flags);
1286 devc->xfer_count = 0;
1287
1288#ifndef EXCLUDE_TIMERS
1289 if (dev == timer_installed && devc->timer_running)
1290 {
1291 if ((fs & 0x01) != (old_fs & 0x01))
1292 {
1293 ad1848_tmr_reprogram(dev);
1294 }
1295 }
1296#endif
1297 ad1848_halt_input(dev);
1298 return 0;
1299}
1300
1301static void ad1848_halt(int dev)
1302{
1303 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1304 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1305
1306 unsigned char bits = ad_read(devc, 9);
1307
1308 if (bits & 0x01 && (portc->open_mode & OPEN_WRITE))
1309 ad1848_halt_output(dev);
1310
1311 if (bits & 0x02 && (portc->open_mode & OPEN_READ))
1312 ad1848_halt_input(dev);
1313 devc->audio_mode = 0;
1314}
1315
1316static void ad1848_halt_input(int dev)
1317{
1318 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1319 unsigned long flags;
1320
1321 if (!(ad_read(devc, 9) & 0x02))
1322 return; /* Capture not enabled */
1323
1324 spin_lock_irqsave(&devc->lock,flags);
1325
1326 ad_mute(devc);
1327
1328 {
1329 int tmout;
1330
1331 if(!isa_dma_bridge_buggy)
1332 disable_dma(audio_devs[dev]->dmap_in->dma);
1333
1334 for (tmout = 0; tmout < 100000; tmout++)
1335 if (ad_read(devc, 11) & 0x10)
1336 break;
1337 ad_write(devc, 9, ad_read(devc, 9) & ~0x02); /* Stop capture */
1338
1339 if(!isa_dma_bridge_buggy)
1340 enable_dma(audio_devs[dev]->dmap_in->dma);
1341 devc->audio_mode &= ~PCM_ENABLE_INPUT;
1342 }
1343
1344 outb(0, io_Status(devc)); /* Clear interrupt status */
1345 outb(0, io_Status(devc)); /* Clear interrupt status */
1346
1347 devc->audio_mode &= ~PCM_ENABLE_INPUT;
1348
1349 spin_unlock_irqrestore(&devc->lock,flags);
1350}
1351
1352static void ad1848_halt_output(int dev)
1353{
1354 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1355 unsigned long flags;
1356
1357 if (!(ad_read(devc, 9) & 0x01))
1358 return; /* Playback not enabled */
1359
1360 spin_lock_irqsave(&devc->lock,flags);
1361
1362 ad_mute(devc);
1363 {
1364 int tmout;
1365
1366 if(!isa_dma_bridge_buggy)
1367 disable_dma(audio_devs[dev]->dmap_out->dma);
1368
1369 for (tmout = 0; tmout < 100000; tmout++)
1370 if (ad_read(devc, 11) & 0x10)
1371 break;
1372 ad_write(devc, 9, ad_read(devc, 9) & ~0x01); /* Stop playback */
1373
1374 if(!isa_dma_bridge_buggy)
1375 enable_dma(audio_devs[dev]->dmap_out->dma);
1376
1377 devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
1378 }
1379
1380 outb((0), io_Status(devc)); /* Clear interrupt status */
1381 outb((0), io_Status(devc)); /* Clear interrupt status */
1382
1383 devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
1384
1385 spin_unlock_irqrestore(&devc->lock,flags);
1386}
1387
1388static void ad1848_trigger(int dev, int state)
1389{
1390 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1391 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1392 unsigned long flags;
1393 unsigned char tmp, old;
1394
1395 spin_lock_irqsave(&devc->lock,flags);
1396 state &= devc->audio_mode;
1397
1398 tmp = old = ad_read(devc, 9);
1399
1400 if (portc->open_mode & OPEN_READ)
1401 {
1402 if (state & PCM_ENABLE_INPUT)
1403 tmp |= 0x02;
1404 else
1405 tmp &= ~0x02;
1406 }
1407 if (portc->open_mode & OPEN_WRITE)
1408 {
1409 if (state & PCM_ENABLE_OUTPUT)
1410 tmp |= 0x01;
1411 else
1412 tmp &= ~0x01;
1413 }
1414 /* ad_mute(devc); */
1415 if (tmp != old)
1416 {
1417 ad_write(devc, 9, tmp);
1418 ad_unmute(devc);
1419 }
1420 spin_unlock_irqrestore(&devc->lock,flags);
1421}
1422
1423static void ad1848_init_hw(ad1848_info * devc)
1424{
1425 int i;
1426 int *init_values;
1427
1428 /*
1429 * Initial values for the indirect registers of CS4248/AD1848.
1430 */
1431 static int init_values_a[] =
1432 {
1433 0xa8, 0xa8, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1434 0x00, 0x0c, 0x02, 0x00, 0x8a, 0x01, 0x00, 0x00,
1435
1436 /* Positions 16 to 31 just for CS4231/2 and ad1845 */
1437 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x1f, 0x40,
1438 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1439 };
1440
1441 static int init_values_b[] =
1442 {
1443 /*
1444 Values for the newer chips
1445 Some of the register initialization values were changed. In
1446 order to get rid of the click that preceded PCM playback,
1447 calibration was disabled on the 10th byte. On that same byte,
1448 dual DMA was enabled; on the 11th byte, ADC dithering was
1449 enabled, since that is theoretically desirable; on the 13th
1450 byte, Mode 3 was selected, to enable access to extended
1451 registers.
1452 */
1453 0xa8, 0xa8, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1454 0x00, 0x00, 0x06, 0x00, 0xe0, 0x01, 0x00, 0x00,
1455 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x1f, 0x40,
1456 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1457 };
1458
1459 /*
1460 * Select initialisation data
1461 */
1462
1463 init_values = init_values_a;
1464 if(devc->model >= MD_4236)
1465 init_values = init_values_b;
1466
1467 for (i = 0; i < 16; i++)
1468 ad_write(devc, i, init_values[i]);
1469
1470
1471 ad_mute(devc); /* Initialize some variables */
1472 ad_unmute(devc); /* Leave it unmuted now */
1473
1474 if (devc->model > MD_1848)
1475 {
1476 if (devc->model == MD_1845_SSCAPE)
1477 ad_write(devc, 12, ad_read(devc, 12) | 0x50);
1478 else
1479 ad_write(devc, 12, ad_read(devc, 12) | 0x40); /* Mode2 = enabled */
1480
1481 if (devc->model == MD_IWAVE)
1482 ad_write(devc, 12, 0x6c); /* Select codec mode 3 */
1483
1484 if (devc->model != MD_1845_SSCAPE)
1485 for (i = 16; i < 32; i++)
1486 ad_write(devc, i, init_values[i]);
1487
1488 if (devc->model == MD_IWAVE)
1489 ad_write(devc, 16, 0x30); /* Playback and capture counters enabled */
1490 }
1491 if (devc->model > MD_1848)
1492 {
1493 if (devc->audio_flags & DMA_DUPLEX)
1494 ad_write(devc, 9, ad_read(devc, 9) & ~0x04); /* Dual DMA mode */
1495 else
1496 ad_write(devc, 9, ad_read(devc, 9) | 0x04); /* Single DMA mode */
1497
1498 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE)
1499 ad_write(devc, 27, ad_read(devc, 27) | 0x08); /* Alternate freq select enabled */
1500
1501 if (devc->model == MD_IWAVE)
1502 { /* Some magic Interwave specific initialization */
1503 ad_write(devc, 12, 0x6c); /* Select codec mode 3 */
1504 ad_write(devc, 16, 0x30); /* Playback and capture counters enabled */
1505 ad_write(devc, 17, 0xc2); /* Alternate feature enable */
1506 }
1507 }
1508 else
1509 {
1510 devc->audio_flags &= ~DMA_DUPLEX;
1511 ad_write(devc, 9, ad_read(devc, 9) | 0x04); /* Single DMA mode */
1512 if (soundpro)
1513 ad_write(devc, 12, ad_read(devc, 12) | 0x40); /* Mode2 = enabled */
1514 }
1515
1516 outb((0), io_Status(devc)); /* Clear pending interrupts */
1517
1518 /*
1519 * Toggle the MCE bit. It completes the initialization phase.
1520 */
1521
1522 ad_enter_MCE(devc); /* In case the bit was off */
1523 ad_leave_MCE(devc);
1524
1525 ad1848_mixer_reset(devc);
1526}
1527
1528int ad1848_detect(struct resource *ports, int *ad_flags, int *osp)
1529{
1530 unsigned char tmp;
1531 ad1848_info *devc = &adev_info[nr_ad1848_devs];
1532 unsigned char tmp1 = 0xff, tmp2 = 0xff;
1533 int optiC930 = 0; /* OPTi 82C930 flag */
1534 int interwave = 0;
1535 int ad1847_flag = 0;
1536 int cs4248_flag = 0;
1537 int sscape_flag = 0;
1538 int io_base = ports->start;
1539
1540 int i;
1541
1542 DDB(printk("ad1848_detect(%x)\n", io_base));
1543
1544 if (ad_flags)
1545 {
1546 if (*ad_flags == 0x12345678)
1547 {
1548 interwave = 1;
1549 *ad_flags = 0;
1550 }
1551
1552 if (*ad_flags == 0x87654321)
1553 {
1554 sscape_flag = 1;
1555 *ad_flags = 0;
1556 }
1557
1558 if (*ad_flags == 0x12345677)
1559 {
1560 cs4248_flag = 1;
1561 *ad_flags = 0;
1562 }
1563 }
1564 if (nr_ad1848_devs >= MAX_AUDIO_DEV)
1565 {
1566 printk(KERN_ERR "ad1848 - Too many audio devices\n");
1567 return 0;
1568 }
1569 spin_lock_init(&devc->lock);
1570 devc->base = io_base;
1571 devc->irq_ok = 0;
1572 devc->timer_running = 0;
1573 devc->MCE_bit = 0x40;
1574 devc->irq = 0;
1575 devc->open_mode = 0;
1576 devc->chip_name = devc->name = "AD1848";
1577 devc->model = MD_1848; /* AD1848 or CS4248 */
1578 devc->levels = NULL;
1579 devc->debug_flag = 0;
1580
1581 /*
1582 * Check that the I/O address is in use.
1583 *
1584 * The bit 0x80 of the base I/O port is known to be 0 after the
1585 * chip has performed its power on initialization. Just assume
1586 * this has happened before the OS is starting.
1587 *
1588 * If the I/O address is unused, it typically returns 0xff.
1589 */
1590
1591 if (inb(devc->base) == 0xff)
1592 {
1593 DDB(printk("ad1848_detect: The base I/O address appears to be dead\n"));
1594 }
1595
1596 /*
1597 * Wait for the device to stop initialization
1598 */
1599
1600 DDB(printk("ad1848_detect() - step 0\n"));
1601
1602 for (i = 0; i < 10000000; i++)
1603 {
1604 unsigned char x = inb(devc->base);
1605
1606 if (x == 0xff || !(x & 0x80))
1607 break;
1608 }
1609
1610 DDB(printk("ad1848_detect() - step A\n"));
1611
1612 if (inb(devc->base) == 0x80) /* Not ready. Let's wait */
1613 ad_leave_MCE(devc);
1614
1615 if ((inb(devc->base) & 0x80) != 0x00) /* Not a AD1848 */
1616 {
1617 DDB(printk("ad1848 detect error - step A (%02x)\n", (int) inb(devc->base)));
1618 return 0;
1619 }
1620
1621 /*
1622 * Test if it's possible to change contents of the indirect registers.
1623 * Registers 0 and 1 are ADC volume registers. The bit 0x10 is read only
1624 * so try to avoid using it.
1625 */
1626
1627 DDB(printk("ad1848_detect() - step B\n"));
1628 ad_write(devc, 0, 0xaa);
1629 ad_write(devc, 1, 0x45); /* 0x55 with bit 0x10 clear */
1630
1631 if ((tmp1 = ad_read(devc, 0)) != 0xaa || (tmp2 = ad_read(devc, 1)) != 0x45)
1632 {
1633 if (tmp2 == 0x65) /* AD1847 has couple of bits hardcoded to 1 */
1634 ad1847_flag = 1;
1635 else
1636 {
1637 DDB(printk("ad1848 detect error - step B (%x/%x)\n", tmp1, tmp2));
1638 return 0;
1639 }
1640 }
1641 DDB(printk("ad1848_detect() - step C\n"));
1642 ad_write(devc, 0, 0x45);
1643 ad_write(devc, 1, 0xaa);
1644
1645 if ((tmp1 = ad_read(devc, 0)) != 0x45 || (tmp2 = ad_read(devc, 1)) != 0xaa)
1646 {
1647 if (tmp2 == 0x8a) /* AD1847 has few bits hardcoded to 1 */
1648 ad1847_flag = 1;
1649 else
1650 {
1651 DDB(printk("ad1848 detect error - step C (%x/%x)\n", tmp1, tmp2));
1652 return 0;
1653 }
1654 }
1655
1656 /*
1657 * The indirect register I12 has some read only bits. Let's
1658 * try to change them.
1659 */
1660
1661 DDB(printk("ad1848_detect() - step D\n"));
1662 tmp = ad_read(devc, 12);
1663 ad_write(devc, 12, (~tmp) & 0x0f);
1664
1665 if ((tmp & 0x0f) != ((tmp1 = ad_read(devc, 12)) & 0x0f))
1666 {
1667 DDB(printk("ad1848 detect error - step D (%x)\n", tmp1));
1668 return 0;
1669 }
1670
1671 /*
1672 * NOTE! Last 4 bits of the reg I12 tell the chip revision.
1673 * 0x01=RevB and 0x0A=RevC.
1674 */
1675
1676 /*
1677 * The original AD1848/CS4248 has just 15 indirect registers. This means
1678 * that I0 and I16 should return the same value (etc.).
1679 * However this doesn't work with CS4248. Actually it seems to be impossible
1680 * to detect if the chip is a CS4231 or CS4248.
1681 * Ensure that the Mode2 enable bit of I12 is 0. Otherwise this test fails
1682 * with CS4231.
1683 */
1684
1685 /*
1686 * OPTi 82C930 has mode2 control bit in another place. This test will fail
1687 * with it. Accept this situation as a possible indication of this chip.
1688 */
1689
1690 DDB(printk("ad1848_detect() - step F\n"));
1691 ad_write(devc, 12, 0); /* Mode2=disabled */
1692
1693 for (i = 0; i < 16; i++)
1694 {
1695 if ((tmp1 = ad_read(devc, i)) != (tmp2 = ad_read(devc, i + 16)))
1696 {
1697 DDB(printk("ad1848 detect step F(%d/%x/%x) - OPTi chip???\n", i, tmp1, tmp2));
1698 if (!ad1847_flag)
1699 optiC930 = 1;
1700 break;
1701 }
1702 }
1703
1704 /*
1705 * Try to switch the chip to mode2 (CS4231) by setting the MODE2 bit (0x40).
1706 * The bit 0x80 is always 1 in CS4248 and CS4231.
1707 */
1708
1709 DDB(printk("ad1848_detect() - step G\n"));
1710
1711 if (ad_flags && *ad_flags == 400)
1712 *ad_flags = 0;
1713 else
1714 ad_write(devc, 12, 0x40); /* Set mode2, clear 0x80 */
1715
1716
1717 if (ad_flags)
1718 *ad_flags = 0;
1719
1720 tmp1 = ad_read(devc, 12);
1721 if (tmp1 & 0x80)
1722 {
1723 if (ad_flags)
1724 *ad_flags |= AD_F_CS4248;
1725
1726 devc->chip_name = "CS4248"; /* Our best knowledge just now */
1727 }
1728 if (optiC930 || (tmp1 & 0xc0) == (0x80 | 0x40))
1729 {
1730 /*
1731 * CS4231 detected - is it?
1732 *
1733 * Verify that setting I0 doesn't change I16.
1734 */
1735
1736 DDB(printk("ad1848_detect() - step H\n"));
1737 ad_write(devc, 16, 0); /* Set I16 to known value */
1738
1739 ad_write(devc, 0, 0x45);
1740 if ((tmp1 = ad_read(devc, 16)) != 0x45) /* No change -> CS4231? */
1741 {
1742 ad_write(devc, 0, 0xaa);
1743 if ((tmp1 = ad_read(devc, 16)) == 0xaa) /* Rotten bits? */
1744 {
1745 DDB(printk("ad1848 detect error - step H(%x)\n", tmp1));
1746 return 0;
1747 }
1748
1749 /*
1750 * Verify that some bits of I25 are read only.
1751 */
1752
1753 DDB(printk("ad1848_detect() - step I\n"));
1754 tmp1 = ad_read(devc, 25); /* Original bits */
1755 ad_write(devc, 25, ~tmp1); /* Invert all bits */
1756 if ((ad_read(devc, 25) & 0xe7) == (tmp1 & 0xe7))
1757 {
1758 int id;
1759
1760 /*
1761 * It's at least CS4231
1762 */
1763
1764 devc->chip_name = "CS4231";
1765 devc->model = MD_4231;
1766
1767 /*
1768 * It could be an AD1845 or CS4231A as well.
1769 * CS4231 and AD1845 report the same revision info in I25
1770 * while the CS4231A reports different.
1771 */
1772
1773 id = ad_read(devc, 25);
1774 if ((id & 0xe7) == 0x80) /* Device busy??? */
1775 id = ad_read(devc, 25);
1776 if ((id & 0xe7) == 0x80) /* Device still busy??? */
1777 id = ad_read(devc, 25);
1778 DDB(printk("ad1848_detect() - step J (%02x/%02x)\n", id, ad_read(devc, 25)));
1779
1780 if ((id & 0xe7) == 0x80) {
1781 /*
1782 * It must be a CS4231 or AD1845. The register I23 of
1783 * CS4231 is undefined and it appears to be read only.
1784 * AD1845 uses I23 for setting sample rate. Assume
1785 * the chip is AD1845 if I23 is changeable.
1786 */
1787
1788 unsigned char tmp = ad_read(devc, 23);
1789 ad_write(devc, 23, ~tmp);
1790
1791 if (interwave)
1792 {
1793 devc->model = MD_IWAVE;
1794 devc->chip_name = "IWave";
1795 }
1796 else if (ad_read(devc, 23) != tmp) /* AD1845 ? */
1797 {
1798 devc->chip_name = "AD1845";
1799 devc->model = MD_1845;
1800 }
1801 else if (cs4248_flag)
1802 {
1803 if (ad_flags)
1804 *ad_flags |= AD_F_CS4248;
1805 devc->chip_name = "CS4248";
1806 devc->model = MD_1848;
1807 ad_write(devc, 12, ad_read(devc, 12) & ~0x40); /* Mode2 off */
1808 }
1809 ad_write(devc, 23, tmp); /* Restore */
1810 }
1811 else
1812 {
1813 switch (id & 0x1f) {
1814 case 3: /* CS4236/CS4235/CS42xB/CS4239 */
1815 {
1816 int xid;
1817 ad_write(devc, 12, ad_read(devc, 12) | 0x60); /* switch to mode 3 */
1818 ad_write(devc, 23, 0x9c); /* select extended register 25 */
1819 xid = inb(io_Indexed_Data(devc));
1820 ad_write(devc, 12, ad_read(devc, 12) & ~0x60); /* back to mode 0 */
1821 switch (xid & 0x1f)
1822 {
1823 case 0x00:
1824 devc->chip_name = "CS4237B(B)";
1825 devc->model = MD_42xB;
1826 break;
1827 case 0x08:
1828 /* Seems to be a 4238 ?? */
1829 devc->chip_name = "CS4238";
1830 devc->model = MD_42xB;
1831 break;
1832 case 0x09:
1833 devc->chip_name = "CS4238B";
1834 devc->model = MD_42xB;
1835 break;
1836 case 0x0b:
1837 devc->chip_name = "CS4236B";
1838 devc->model = MD_4236;
1839 break;
1840 case 0x10:
1841 devc->chip_name = "CS4237B";
1842 devc->model = MD_42xB;
1843 break;
1844 case 0x1d:
1845 devc->chip_name = "CS4235";
1846 devc->model = MD_4235;
1847 break;
1848 case 0x1e:
1849 devc->chip_name = "CS4239";
1850 devc->model = MD_4239;
1851 break;
1852 default:
1853 printk("Chip ident is %X.\n", xid&0x1F);
1854 devc->chip_name = "CS42xx";
1855 devc->model = MD_4232;
1856 break;
1857 }
1858 }
1859 break;
1860
1861 case 2: /* CS4232/CS4232A */
1862 devc->chip_name = "CS4232";
1863 devc->model = MD_4232;
1864 break;
1865
1866 case 0:
1867 if ((id & 0xe0) == 0xa0)
1868 {
1869 devc->chip_name = "CS4231A";
1870 devc->model = MD_4231A;
1871 }
1872 else
1873 {
1874 devc->chip_name = "CS4321";
1875 devc->model = MD_4231;
1876 }
1877 break;
1878
1879 default: /* maybe */
1880 DDB(printk("ad1848: I25 = %02x/%02x\n", ad_read(devc, 25), ad_read(devc, 25) & 0xe7));
1881 if (optiC930)
1882 {
1883 devc->chip_name = "82C930";
1884 devc->model = MD_C930;
1885 }
1886 else
1887 {
1888 devc->chip_name = "CS4231";
1889 devc->model = MD_4231;
1890 }
1891 }
1892 }
1893 }
1894 ad_write(devc, 25, tmp1); /* Restore bits */
1895
1896 DDB(printk("ad1848_detect() - step K\n"));
1897 }
1898 } else if (tmp1 == 0x0a) {
1899 /*
1900 * Is it perhaps a SoundPro CMI8330?
1901 * If so, then we should be able to change indirect registers
1902 * greater than I15 after activating MODE2, even though reading
1903 * back I12 does not show it.
1904 */
1905
1906 /*
1907 * Let's try comparing register values
1908 */
1909 for (i = 0; i < 16; i++) {
1910 if ((tmp1 = ad_read(devc, i)) != (tmp2 = ad_read(devc, i + 16))) {
1911 DDB(printk("ad1848 detect step H(%d/%x/%x) - SoundPro chip?\n", i, tmp1, tmp2));
1912 soundpro = 1;
1913 devc->chip_name = "SoundPro CMI 8330";
1914 break;
1915 }
1916 }
1917 }
1918
1919 DDB(printk("ad1848_detect() - step L\n"));
1920 if (ad_flags)
1921 {
1922 if (devc->model != MD_1848)
1923 *ad_flags |= AD_F_CS4231;
1924 }
1925 DDB(printk("ad1848_detect() - Detected OK\n"));
1926
1927 if (devc->model == MD_1848 && ad1847_flag)
1928 devc->chip_name = "AD1847";
1929
1930
1931 if (sscape_flag == 1)
1932 devc->model = MD_1845_SSCAPE;
1933
1934 return 1;
1935}
1936
1937int ad1848_init (char *name, struct resource *ports, int irq, int dma_playback,
1938 int dma_capture, int share_dma, int *osp, struct module *owner)
1939{
1940 /*
1941 * NOTE! If irq < 0, there is another driver which has allocated the IRQ
1942 * so that this driver doesn't need to allocate/deallocate it.
1943 * The actually used IRQ is ABS(irq).
1944 */
1945
1946 int my_dev;
1947 char dev_name[100];
1948 int e;
1949
1950 ad1848_info *devc = &adev_info[nr_ad1848_devs];
1951
1952 ad1848_port_info *portc = NULL;
1953
1954 devc->irq = (irq > 0) ? irq : 0;
1955 devc->open_mode = 0;
1956 devc->timer_ticks = 0;
1957 devc->dma1 = dma_playback;
1958 devc->dma2 = dma_capture;
1959 devc->subtype = cfg.card_subtype;
1960 devc->audio_flags = DMA_AUTOMODE;
1961 devc->playback_dev = devc->record_dev = 0;
1962 if (name != NULL)
1963 devc->name = name;
1964
1965 if (name != NULL && name[0] != 0)
1966 sprintf(dev_name,
1967 "%s (%s)", name, devc->chip_name);
1968 else
1969 sprintf(dev_name,
1970 "Generic audio codec (%s)", devc->chip_name);
1971
1972 rename_region(ports, devc->name);
1973
1974 conf_printf2(dev_name, devc->base, devc->irq, dma_playback, dma_capture);
1975
1976 if (devc->model == MD_1848 || devc->model == MD_C930)
1977 devc->audio_flags |= DMA_HARDSTOP;
1978
1979 if (devc->model > MD_1848)
1980 {
1981 if (devc->dma1 == devc->dma2 || devc->dma2 == -1 || devc->dma1 == -1)
1982 devc->audio_flags &= ~DMA_DUPLEX;
1983 else
1984 devc->audio_flags |= DMA_DUPLEX;
1985 }
1986
1987 portc = kmalloc(sizeof(ad1848_port_info), GFP_KERNEL);
1988 if(portc==NULL) {
1989 release_region(devc->base, 4);
1990 return -1;
1991 }
1992
1993 if ((my_dev = sound_install_audiodrv(AUDIO_DRIVER_VERSION,
1994 dev_name,
1995 &ad1848_audio_driver,
1996 sizeof(struct audio_driver),
1997 devc->audio_flags,
1998 ad_format_mask[devc->model],
1999 devc,
2000 dma_playback,
2001 dma_capture)) < 0)
2002 {
2003 release_region(devc->base, 4);
2004 kfree(portc);
2005 return -1;
2006 }
2007
2008 audio_devs[my_dev]->portc = portc;
2009 audio_devs[my_dev]->mixer_dev = -1;
2010 if (owner)
2011 audio_devs[my_dev]->d->owner = owner;
2012 memset((char *) portc, 0, sizeof(*portc));
2013
2014 nr_ad1848_devs++;
2015
2016 ad1848_init_hw(devc);
2017
2018 if (irq > 0)
2019 {
2020 devc->dev_no = my_dev;
2021 if (request_irq(devc->irq, adintr, 0, devc->name,
2022 (void *)(long)my_dev) < 0)
2023 {
2024 printk(KERN_WARNING "ad1848: Unable to allocate IRQ\n");
2025 /* Don't free it either then.. */
2026 devc->irq = 0;
2027 }
2028 if (capabilities[devc->model].flags & CAP_F_TIMER)
2029 {
2030#ifndef CONFIG_SMP
2031 int x;
2032 unsigned char tmp = ad_read(devc, 16);
2033#endif
2034
2035 devc->timer_ticks = 0;
2036
2037 ad_write(devc, 21, 0x00); /* Timer MSB */
2038 ad_write(devc, 20, 0x10); /* Timer LSB */
2039#ifndef CONFIG_SMP
2040 ad_write(devc, 16, tmp | 0x40); /* Enable timer */
2041 for (x = 0; x < 100000 && devc->timer_ticks == 0; x++);
2042 ad_write(devc, 16, tmp & ~0x40); /* Disable timer */
2043
2044 if (devc->timer_ticks == 0)
2045 printk(KERN_WARNING "ad1848: Interrupt test failed (IRQ%d)\n", irq);
2046 else
2047 {
2048 DDB(printk("Interrupt test OK\n"));
2049 devc->irq_ok = 1;
2050 }
2051#else
2052 devc->irq_ok = 1;
2053#endif
2054 }
2055 else
2056 devc->irq_ok = 1; /* Couldn't test. assume it's OK */
2057 } else if (irq < 0)
2058 devc->dev_no = my_dev;
2059
2060#ifndef EXCLUDE_TIMERS
2061 if ((capabilities[devc->model].flags & CAP_F_TIMER) &&
2062 devc->irq_ok)
2063 ad1848_tmr_install(my_dev);
2064#endif
2065
2066 if (!share_dma)
2067 {
2068 if (sound_alloc_dma(dma_playback, devc->name))
2069 printk(KERN_WARNING "ad1848.c: Can't allocate DMA%d\n", dma_playback);
2070
2071 if (dma_capture != dma_playback)
2072 if (sound_alloc_dma(dma_capture, devc->name))
2073 printk(KERN_WARNING "ad1848.c: Can't allocate DMA%d\n", dma_capture);
2074 }
2075
2076 if ((e = sound_install_mixer(MIXER_DRIVER_VERSION,
2077 dev_name,
2078 &ad1848_mixer_operations,
2079 sizeof(struct mixer_operations),
2080 devc)) >= 0)
2081 {
2082 audio_devs[my_dev]->mixer_dev = e;
2083 if (owner)
2084 mixer_devs[e]->owner = owner;
2085 }
2086 return my_dev;
2087}
2088
2089int ad1848_control(int cmd, int arg)
2090{
2091 ad1848_info *devc;
2092 unsigned long flags;
2093
2094 if (nr_ad1848_devs < 1)
2095 return -ENODEV;
2096
2097 devc = &adev_info[nr_ad1848_devs - 1];
2098
2099 switch (cmd)
2100 {
2101 case AD1848_SET_XTAL: /* Change clock frequency of AD1845 (only ) */
2102 if (devc->model != MD_1845 && devc->model != MD_1845_SSCAPE)
2103 return -EINVAL;
2104 spin_lock_irqsave(&devc->lock,flags);
2105 ad_enter_MCE(devc);
2106 ad_write(devc, 29, (ad_read(devc, 29) & 0x1f) | (arg << 5));
2107 ad_leave_MCE(devc);
2108 spin_unlock_irqrestore(&devc->lock,flags);
2109 break;
2110
2111 case AD1848_MIXER_REROUTE:
2112 {
2113 int o = (arg >> 8) & 0xff;
2114 int n = arg & 0xff;
2115
2116 if (o < 0 || o >= SOUND_MIXER_NRDEVICES)
2117 return -EINVAL;
2118
2119 if (!(devc->supported_devices & (1 << o)) &&
2120 !(devc->supported_rec_devices & (1 << o)))
2121 return -EINVAL;
2122
2123 if (n == SOUND_MIXER_NONE)
2124 { /* Just hide this control */
2125 ad1848_mixer_set(devc, o, 0); /* Shut up it */
2126 devc->supported_devices &= ~(1 << o);
2127 devc->supported_rec_devices &= ~(1 << o);
2128 break;
2129 }
2130
2131 /* Make the mixer control identified by o to appear as n */
2132 if (n < 0 || n >= SOUND_MIXER_NRDEVICES)
2133 return -EINVAL;
2134
2135 devc->mixer_reroute[n] = o; /* Rename the control */
2136 if (devc->supported_devices & (1 << o))
2137 devc->supported_devices |= (1 << n);
2138 if (devc->supported_rec_devices & (1 << o))
2139 devc->supported_rec_devices |= (1 << n);
2140
2141 devc->supported_devices &= ~(1 << o);
2142 devc->supported_rec_devices &= ~(1 << o);
2143 }
2144 break;
2145 }
2146 return 0;
2147}
2148
2149void ad1848_unload(int io_base, int irq, int dma_playback, int dma_capture, int share_dma)
2150{
2151 int i, mixer, dev = 0;
2152 ad1848_info *devc = NULL;
2153
2154 for (i = 0; devc == NULL && i < nr_ad1848_devs; i++)
2155 {
2156 if (adev_info[i].base == io_base)
2157 {
2158 devc = &adev_info[i];
2159 dev = devc->dev_no;
2160 }
2161 }
2162
2163 if (devc != NULL)
2164 {
2165 kfree(audio_devs[dev]->portc);
2166 release_region(devc->base, 4);
2167
2168 if (!share_dma)
2169 {
2170 if (devc->irq > 0) /* There is no point in freeing irq, if it wasn't allocated */
2171 free_irq(devc->irq, (void *)(long)devc->dev_no);
2172
2173 sound_free_dma(dma_playback);
2174
2175 if (dma_playback != dma_capture)
2176 sound_free_dma(dma_capture);
2177
2178 }
2179 mixer = audio_devs[devc->dev_no]->mixer_dev;
2180 if(mixer>=0)
2181 sound_unload_mixerdev(mixer);
2182
2183 nr_ad1848_devs--;
2184 for ( ; i < nr_ad1848_devs ; i++)
2185 adev_info[i] = adev_info[i+1];
2186 }
2187 else
2188 printk(KERN_ERR "ad1848: Can't find device to be unloaded. Base=%x\n", io_base);
2189}
2190
2191static irqreturn_t adintr(int irq, void *dev_id)
2192{
2193 unsigned char status;
2194 ad1848_info *devc;
2195 int dev;
2196 int alt_stat = 0xff;
2197 unsigned char c930_stat = 0;
2198 int cnt = 0;
2199
2200 dev = (long)dev_id;
2201 devc = (ad1848_info *) audio_devs[dev]->devc;
2202
2203interrupt_again: /* Jump back here if int status doesn't reset */
2204
2205 status = inb(io_Status(devc));
2206
2207 if (status == 0x80)
2208 printk(KERN_DEBUG "adintr: Why?\n");
2209 if (devc->model == MD_1848)
2210 outb((0), io_Status(devc)); /* Clear interrupt status */
2211
2212 if (status & 0x01)
2213 {
2214 if (devc->model == MD_C930)
2215 { /* 82C930 has interrupt status register in MAD16 register MC11 */
2216
2217 spin_lock(&devc->lock);
2218
2219 /* 0xe0e is C930 address port
2220 * 0xe0f is C930 data port
2221 */
2222 outb(11, 0xe0e);
2223 c930_stat = inb(0xe0f);
2224 outb((~c930_stat), 0xe0f);
2225
2226 spin_unlock(&devc->lock);
2227
2228 alt_stat = (c930_stat << 2) & 0x30;
2229 }
2230 else if (devc->model != MD_1848)
2231 {
2232 spin_lock(&devc->lock);
2233 alt_stat = ad_read(devc, 24);
2234 ad_write(devc, 24, ad_read(devc, 24) & ~alt_stat); /* Selective ack */
2235 spin_unlock(&devc->lock);
2236 }
2237
2238 if ((devc->open_mode & OPEN_READ) && (devc->audio_mode & PCM_ENABLE_INPUT) && (alt_stat & 0x20))
2239 {
2240 DMAbuf_inputintr(devc->record_dev);
2241 }
2242 if ((devc->open_mode & OPEN_WRITE) && (devc->audio_mode & PCM_ENABLE_OUTPUT) &&
2243 (alt_stat & 0x10))
2244 {
2245 DMAbuf_outputintr(devc->playback_dev, 1);
2246 }
2247 if (devc->model != MD_1848 && (alt_stat & 0x40)) /* Timer interrupt */
2248 {
2249 devc->timer_ticks++;
2250#ifndef EXCLUDE_TIMERS
2251 if (timer_installed == dev && devc->timer_running)
2252 sound_timer_interrupt();
2253#endif
2254 }
2255 }
2256/*
2257 * Sometimes playback or capture interrupts occur while a timer interrupt
2258 * is being handled. The interrupt will not be retriggered if we don't
2259 * handle it now. Check if an interrupt is still pending and restart
2260 * the handler in this case.
2261 */
2262 if (inb(io_Status(devc)) & 0x01 && cnt++ < 4)
2263 {
2264 goto interrupt_again;
2265 }
2266 return IRQ_HANDLED;
2267}
2268
2269/*
2270 * Experimental initialization sequence for the integrated sound system
2271 * of the Compaq Deskpro M.
2272 */
2273
2274static int init_deskpro_m(struct address_info *hw_config)
2275{
2276 unsigned char tmp;
2277
2278 if ((tmp = inb(0xc44)) == 0xff)
2279 {
2280 DDB(printk("init_deskpro_m: Dead port 0xc44\n"));
2281 return 0;
2282 }
2283
2284 outb(0x10, 0xc44);
2285 outb(0x40, 0xc45);
2286 outb(0x00, 0xc46);
2287 outb(0xe8, 0xc47);
2288 outb(0x14, 0xc44);
2289 outb(0x40, 0xc45);
2290 outb(0x00, 0xc46);
2291 outb(0xe8, 0xc47);
2292 outb(0x10, 0xc44);
2293
2294 return 1;
2295}
2296
2297/*
2298 * Experimental initialization sequence for the integrated sound system
2299 * of Compaq Deskpro XL.
2300 */
2301
2302static int init_deskpro(struct address_info *hw_config)
2303{
2304 unsigned char tmp;
2305
2306 if ((tmp = inb(0xc44)) == 0xff)
2307 {
2308 DDB(printk("init_deskpro: Dead port 0xc44\n"));
2309 return 0;
2310 }
2311 outb((tmp | 0x04), 0xc44); /* Select bank 1 */
2312 if (inb(0xc44) != 0x04)
2313 {
2314 DDB(printk("init_deskpro: Invalid bank1 signature in port 0xc44\n"));
2315 return 0;
2316 }
2317 /*
2318 * OK. It looks like a Deskpro so let's proceed.
2319 */
2320
2321 /*
2322 * I/O port 0xc44 Audio configuration register.
2323 *
2324 * bits 0xc0: Audio revision bits
2325 * 0x00 = Compaq Business Audio
2326 * 0x40 = MS Sound System Compatible (reset default)
2327 * 0x80 = Reserved
2328 * 0xc0 = Reserved
2329 * bit 0x20: No Wait State Enable
2330 * 0x00 = Disabled (reset default, DMA mode)
2331 * 0x20 = Enabled (programmed I/O mode)
2332 * bit 0x10: MS Sound System Decode Enable
2333 * 0x00 = Decoding disabled (reset default)
2334 * 0x10 = Decoding enabled
2335 * bit 0x08: FM Synthesis Decode Enable
2336 * 0x00 = Decoding Disabled (reset default)
2337 * 0x08 = Decoding enabled
2338 * bit 0x04 Bank select
2339 * 0x00 = Bank 0
2340 * 0x04 = Bank 1
2341 * bits 0x03 MSS Base address
2342 * 0x00 = 0x530 (reset default)
2343 * 0x01 = 0x604
2344 * 0x02 = 0xf40
2345 * 0x03 = 0xe80
2346 */
2347
2348#ifdef DEBUGXL
2349 /* Debug printing */
2350 printk("Port 0xc44 (before): ");
2351 outb((tmp & ~0x04), 0xc44);
2352 printk("%02x ", inb(0xc44));
2353 outb((tmp | 0x04), 0xc44);
2354 printk("%02x\n", inb(0xc44));
2355#endif
2356
2357 /* Set bank 1 of the register */
2358 tmp = 0x58; /* MSS Mode, MSS&FM decode enabled */
2359
2360 switch (hw_config->io_base)
2361 {
2362 case 0x530:
2363 tmp |= 0x00;
2364 break;
2365 case 0x604:
2366 tmp |= 0x01;
2367 break;
2368 case 0xf40:
2369 tmp |= 0x02;
2370 break;
2371 case 0xe80:
2372 tmp |= 0x03;
2373 break;
2374 default:
2375 DDB(printk("init_deskpro: Invalid MSS port %x\n", hw_config->io_base));
2376 return 0;
2377 }
2378 outb((tmp & ~0x04), 0xc44); /* Write to bank=0 */
2379
2380#ifdef DEBUGXL
2381 /* Debug printing */
2382 printk("Port 0xc44 (after): ");
2383 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2384 printk("%02x ", inb(0xc44));
2385 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2386 printk("%02x\n", inb(0xc44));
2387#endif
2388
2389 /*
2390 * I/O port 0xc45 FM Address Decode/MSS ID Register.
2391 *
2392 * bank=0, bits 0xfe: FM synthesis Decode Compare bits 7:1 (default=0x88)
2393 * bank=0, bit 0x01: SBIC Power Control Bit
2394 * 0x00 = Powered up
2395 * 0x01 = Powered down
2396 * bank=1, bits 0xfc: MSS ID (default=0x40)
2397 */
2398
2399#ifdef DEBUGXL
2400 /* Debug printing */
2401 printk("Port 0xc45 (before): ");
2402 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2403 printk("%02x ", inb(0xc45));
2404 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2405 printk("%02x\n", inb(0xc45));
2406#endif
2407
2408 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2409 outb((0x88), 0xc45); /* FM base 7:0 = 0x88 */
2410 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2411 outb((0x10), 0xc45); /* MSS ID = 0x10 (MSS port returns 0x04) */
2412
2413#ifdef DEBUGXL
2414 /* Debug printing */
2415 printk("Port 0xc45 (after): ");
2416 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2417 printk("%02x ", inb(0xc45));
2418 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2419 printk("%02x\n", inb(0xc45));
2420#endif
2421
2422
2423 /*
2424 * I/O port 0xc46 FM Address Decode/Address ASIC Revision Register.
2425 *
2426 * bank=0, bits 0xff: FM synthesis Decode Compare bits 15:8 (default=0x03)
2427 * bank=1, bits 0xff: Audio addressing ASIC id
2428 */
2429
2430#ifdef DEBUGXL
2431 /* Debug printing */
2432 printk("Port 0xc46 (before): ");
2433 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2434 printk("%02x ", inb(0xc46));
2435 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2436 printk("%02x\n", inb(0xc46));
2437#endif
2438
2439 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2440 outb((0x03), 0xc46); /* FM base 15:8 = 0x03 */
2441 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2442 outb((0x11), 0xc46); /* ASIC ID = 0x11 */
2443
2444#ifdef DEBUGXL
2445 /* Debug printing */
2446 printk("Port 0xc46 (after): ");
2447 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2448 printk("%02x ", inb(0xc46));
2449 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2450 printk("%02x\n", inb(0xc46));
2451#endif
2452
2453 /*
2454 * I/O port 0xc47 FM Address Decode Register.
2455 *
2456 * bank=0, bits 0xff: Decode enable selection for various FM address bits
2457 * bank=1, bits 0xff: Reserved
2458 */
2459
2460#ifdef DEBUGXL
2461 /* Debug printing */
2462 printk("Port 0xc47 (before): ");
2463 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2464 printk("%02x ", inb(0xc47));
2465 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2466 printk("%02x\n", inb(0xc47));
2467#endif
2468
2469 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2470 outb((0x7c), 0xc47); /* FM decode enable bits = 0x7c */
2471 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2472 outb((0x00), 0xc47); /* Reserved bank1 = 0x00 */
2473
2474#ifdef DEBUGXL
2475 /* Debug printing */
2476 printk("Port 0xc47 (after): ");
2477 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2478 printk("%02x ", inb(0xc47));
2479 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2480 printk("%02x\n", inb(0xc47));
2481#endif
2482
2483 /*
2484 * I/O port 0xc6f = Audio Disable Function Register
2485 */
2486
2487#ifdef DEBUGXL
2488 printk("Port 0xc6f (before) = %02x\n", inb(0xc6f));
2489#endif
2490
2491 outb((0x80), 0xc6f);
2492
2493#ifdef DEBUGXL
2494 printk("Port 0xc6f (after) = %02x\n", inb(0xc6f));
2495#endif
2496
2497 return 1;
2498}
2499
2500int probe_ms_sound(struct address_info *hw_config, struct resource *ports)
2501{
2502 unsigned char tmp;
2503
2504 DDB(printk("Entered probe_ms_sound(%x, %d)\n", hw_config->io_base, hw_config->card_subtype));
2505
2506 if (hw_config->card_subtype == 1) /* Has no IRQ/DMA registers */
2507 {
2508 /* check_opl3(0x388, hw_config); */
2509 return ad1848_detect(ports, NULL, hw_config->osp);
2510 }
2511
2512 if (deskpro_xl && hw_config->card_subtype == 2) /* Compaq Deskpro XL */
2513 {
2514 if (!init_deskpro(hw_config))
2515 return 0;
2516 }
2517
2518 if (deskpro_m) /* Compaq Deskpro M */
2519 {
2520 if (!init_deskpro_m(hw_config))
2521 return 0;
2522 }
2523
2524 /*
2525 * Check if the IO port returns valid signature. The original MS Sound
2526 * system returns 0x04 while some cards (AudioTrix Pro for example)
2527 * return 0x00 or 0x0f.
2528 */
2529
2530 if ((tmp = inb(hw_config->io_base + 3)) == 0xff) /* Bus float */
2531 {
2532 int ret;
2533
2534 DDB(printk("I/O address is inactive (%x)\n", tmp));
2535 if (!(ret = ad1848_detect(ports, NULL, hw_config->osp)))
2536 return 0;
2537 return 1;
2538 }
2539 DDB(printk("MSS signature = %x\n", tmp & 0x3f));
2540 if ((tmp & 0x3f) != 0x04 &&
2541 (tmp & 0x3f) != 0x0f &&
2542 (tmp & 0x3f) != 0x00)
2543 {
2544 int ret;
2545
2546 MDB(printk(KERN_ERR "No MSS signature detected on port 0x%x (0x%x)\n", hw_config->io_base, (int) inb(hw_config->io_base + 3)));
2547 DDB(printk("Trying to detect codec anyway but IRQ/DMA may not work\n"));
2548 if (!(ret = ad1848_detect(ports, NULL, hw_config->osp)))
2549 return 0;
2550
2551 hw_config->card_subtype = 1;
2552 return 1;
2553 }
2554 if ((hw_config->irq != 5) &&
2555 (hw_config->irq != 7) &&
2556 (hw_config->irq != 9) &&
2557 (hw_config->irq != 10) &&
2558 (hw_config->irq != 11) &&
2559 (hw_config->irq != 12))
2560 {
2561 printk(KERN_ERR "MSS: Bad IRQ %d\n", hw_config->irq);
2562 return 0;
2563 }
2564 if (hw_config->dma != 0 && hw_config->dma != 1 && hw_config->dma != 3)
2565 {
2566 printk(KERN_ERR "MSS: Bad DMA %d\n", hw_config->dma);
2567 return 0;
2568 }
2569 /*
2570 * Check that DMA0 is not in use with a 8 bit board.
2571 */
2572
2573 if (hw_config->dma == 0 && inb(hw_config->io_base + 3) & 0x80)
2574 {
2575 printk(KERN_ERR "MSS: Can't use DMA0 with a 8 bit card/slot\n");
2576 return 0;
2577 }
2578 if (hw_config->irq > 7 && hw_config->irq != 9 && inb(hw_config->io_base + 3) & 0x80)
2579 {
2580 printk(KERN_ERR "MSS: Can't use IRQ%d with a 8 bit card/slot\n", hw_config->irq);
2581 return 0;
2582 }
2583 return ad1848_detect(ports, NULL, hw_config->osp);
2584}
2585
2586void attach_ms_sound(struct address_info *hw_config, struct resource *ports, struct module *owner)
2587{
2588 static signed char interrupt_bits[12] =
2589 {
2590 -1, -1, -1, -1, -1, 0x00, -1, 0x08, -1, 0x10, 0x18, 0x20
2591 };
2592 signed char bits;
2593 char dma2_bit = 0;
2594
2595 static char dma_bits[4] =
2596 {
2597 1, 2, 0, 3
2598 };
2599
2600 int config_port = hw_config->io_base + 0;
2601 int version_port = hw_config->io_base + 3;
2602 int dma = hw_config->dma;
2603 int dma2 = hw_config->dma2;
2604
2605 if (hw_config->card_subtype == 1) /* Has no IRQ/DMA registers */
2606 {
2607 hw_config->slots[0] = ad1848_init("MS Sound System", ports,
2608 hw_config->irq,
2609 hw_config->dma,
2610 hw_config->dma2, 0,
2611 hw_config->osp,
2612 owner);
2613 return;
2614 }
2615 /*
2616 * Set the IRQ and DMA addresses.
2617 */
2618
2619 bits = interrupt_bits[hw_config->irq];
2620 if (bits == -1)
2621 {
2622 printk(KERN_ERR "MSS: Bad IRQ %d\n", hw_config->irq);
2623 release_region(ports->start, 4);
2624 release_region(ports->start - 4, 4);
2625 return;
2626 }
2627 outb((bits | 0x40), config_port);
2628 if ((inb(version_port) & 0x40) == 0)
2629 printk(KERN_ERR "[MSS: IRQ Conflict?]\n");
2630
2631/*
2632 * Handle the capture DMA channel
2633 */
2634
2635 if (dma2 != -1 && dma2 != dma)
2636 {
2637 if (!((dma == 0 && dma2 == 1) ||
2638 (dma == 1 && dma2 == 0) ||
2639 (dma == 3 && dma2 == 0)))
2640 { /* Unsupported combination. Try to swap channels */
2641 int tmp = dma;
2642
2643 dma = dma2;
2644 dma2 = tmp;
2645 }
2646 if ((dma == 0 && dma2 == 1) ||
2647 (dma == 1 && dma2 == 0) ||
2648 (dma == 3 && dma2 == 0))
2649 {
2650 dma2_bit = 0x04; /* Enable capture DMA */
2651 }
2652 else
2653 {
2654 printk(KERN_WARNING "MSS: Invalid capture DMA\n");
2655 dma2 = dma;
2656 }
2657 }
2658 else
2659 {
2660 dma2 = dma;
2661 }
2662
2663 hw_config->dma = dma;
2664 hw_config->dma2 = dma2;
2665
2666 outb((bits | dma_bits[dma] | dma2_bit), config_port); /* Write IRQ+DMA setup */
2667
2668 hw_config->slots[0] = ad1848_init("MS Sound System", ports,
2669 hw_config->irq,
2670 dma, dma2, 0,
2671 hw_config->osp,
2672 THIS_MODULE);
2673}
2674
2675void unload_ms_sound(struct address_info *hw_config)
2676{
2677 ad1848_unload(hw_config->io_base + 4,
2678 hw_config->irq,
2679 hw_config->dma,
2680 hw_config->dma2, 0);
2681 sound_unload_audiodev(hw_config->slots[0]);
2682 release_region(hw_config->io_base, 4);
2683}
2684
2685#ifndef EXCLUDE_TIMERS
2686
2687/*
2688 * Timer stuff (for /dev/music).
2689 */
2690
2691static unsigned int current_interval;
2692
2693static unsigned int ad1848_tmr_start(int dev, unsigned int usecs)
2694{
2695 unsigned long flags;
2696 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
2697 unsigned long xtal_nsecs; /* nanoseconds per xtal oscillator tick */
2698 unsigned long divider;
2699
2700 spin_lock_irqsave(&devc->lock,flags);
2701
2702 /*
2703 * Length of the timer interval (in nanoseconds) depends on the
2704 * selected crystal oscillator. Check this from bit 0x01 of I8.
2705 *
2706 * AD1845 has just one oscillator which has cycle time of 10.050 us
2707 * (when a 24.576 MHz xtal oscillator is used).
2708 *
2709 * Convert requested interval to nanoseconds before computing
2710 * the timer divider.
2711 */
2712
2713 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE)
2714 xtal_nsecs = 10050;
2715 else if (ad_read(devc, 8) & 0x01)
2716 xtal_nsecs = 9920;
2717 else
2718 xtal_nsecs = 9969;
2719
2720 divider = (usecs * 1000 + xtal_nsecs / 2) / xtal_nsecs;
2721
2722 if (divider < 100) /* Don't allow shorter intervals than about 1ms */
2723 divider = 100;
2724
2725 if (divider > 65535) /* Overflow check */
2726 divider = 65535;
2727
2728 ad_write(devc, 21, (divider >> 8) & 0xff); /* Set upper bits */
2729 ad_write(devc, 20, divider & 0xff); /* Set lower bits */
2730 ad_write(devc, 16, ad_read(devc, 16) | 0x40); /* Start the timer */
2731 devc->timer_running = 1;
2732 spin_unlock_irqrestore(&devc->lock,flags);
2733
2734 return current_interval = (divider * xtal_nsecs + 500) / 1000;
2735}
2736
2737static void ad1848_tmr_reprogram(int dev)
2738{
2739 /*
2740 * Audio driver has changed sampling rate so that a different xtal
2741 * oscillator was selected. We have to reprogram the timer rate.
2742 */
2743
2744 ad1848_tmr_start(dev, current_interval);
2745 sound_timer_syncinterval(current_interval);
2746}
2747
2748static void ad1848_tmr_disable(int dev)
2749{
2750 unsigned long flags;
2751 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
2752
2753 spin_lock_irqsave(&devc->lock,flags);
2754 ad_write(devc, 16, ad_read(devc, 16) & ~0x40);
2755 devc->timer_running = 0;
2756 spin_unlock_irqrestore(&devc->lock,flags);
2757}
2758
2759static void ad1848_tmr_restart(int dev)
2760{
2761 unsigned long flags;
2762 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
2763
2764 if (current_interval == 0)
2765 return;
2766
2767 spin_lock_irqsave(&devc->lock,flags);
2768 ad_write(devc, 16, ad_read(devc, 16) | 0x40);
2769 devc->timer_running = 1;
2770 spin_unlock_irqrestore(&devc->lock,flags);
2771}
2772
2773static struct sound_lowlev_timer ad1848_tmr =
2774{
2775 0,
2776 2,
2777 ad1848_tmr_start,
2778 ad1848_tmr_disable,
2779 ad1848_tmr_restart
2780};
2781
2782static int ad1848_tmr_install(int dev)
2783{
2784 if (timer_installed != -1)
2785 return 0; /* Don't install another timer */
2786
2787 timer_installed = ad1848_tmr.dev = dev;
2788 sound_timer_init(&ad1848_tmr, audio_devs[dev]->name);
2789
2790 return 1;
2791}
2792#endif /* EXCLUDE_TIMERS */
2793
2794EXPORT_SYMBOL(ad1848_detect);
2795EXPORT_SYMBOL(ad1848_init);
2796EXPORT_SYMBOL(ad1848_unload);
2797EXPORT_SYMBOL(ad1848_control);
2798EXPORT_SYMBOL(probe_ms_sound);
2799EXPORT_SYMBOL(attach_ms_sound);
2800EXPORT_SYMBOL(unload_ms_sound);
2801
2802static int __initdata io = -1;
2803static int __initdata irq = -1;
2804static int __initdata dma = -1;
2805static int __initdata dma2 = -1;
2806static int __initdata type = 0;
2807
2808module_param_hw(io, int, ioport, 0); /* I/O for a raw AD1848 card */
2809module_param_hw(irq, int, irq, 0); /* IRQ to use */
2810module_param_hw(dma, int, dma, 0); /* First DMA channel */
2811module_param_hw(dma2, int, dma, 0); /* Second DMA channel */
2812module_param(type, int, 0); /* Card type */
2813module_param(deskpro_xl, bool, 0); /* Special magic for Deskpro XL boxen */
2814module_param(deskpro_m, bool, 0); /* Special magic for Deskpro M box */
2815module_param(soundpro, bool, 0); /* More special magic for SoundPro chips */
2816
2817#ifdef CONFIG_PNP
2818module_param(isapnp, int, 0);
2819module_param(isapnpjump, int, 0);
2820module_param(reverse, bool, 0);
2821MODULE_PARM_DESC(isapnp, "When set to 0, Plug & Play support will be disabled");
2822MODULE_PARM_DESC(isapnpjump, "Jumps to a specific slot in the driver's PnP table. Use the source, Luke.");
2823MODULE_PARM_DESC(reverse, "When set to 1, will reverse ISAPnP search order");
2824
2825static struct pnp_dev *ad1848_dev = NULL;
2826
2827/* Please add new entries at the end of the table */
2828static struct {
2829 char *name;
2830 unsigned short card_vendor, card_device,
2831 vendor, function;
2832 short mss_io, irq, dma, dma2; /* index into isapnp table */
2833 int type;
2834} ad1848_isapnp_list[] __initdata = {
2835 {"CMI 8330 SoundPRO",
2836 ISAPNP_VENDOR('C','M','I'), ISAPNP_DEVICE(0x0001),
2837 ISAPNP_VENDOR('@','@','@'), ISAPNP_FUNCTION(0x0001),
2838 0, 0, 0,-1, 0},
2839 {"CS4232 based card",
2840 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2841 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0000),
2842 0, 0, 0, 1, 0},
2843 {"CS4232 based card",
2844 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2845 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0100),
2846 0, 0, 0, 1, 0},
2847 {"OPL3-SA2 WSS mode",
2848 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2849 ISAPNP_VENDOR('Y','M','H'), ISAPNP_FUNCTION(0x0021),
2850 1, 0, 0, 1, 1},
2851 {"Advanced Gravis InterWave Audio",
2852 ISAPNP_VENDOR('G','R','V'), ISAPNP_DEVICE(0x0001),
2853 ISAPNP_VENDOR('G','R','V'), ISAPNP_FUNCTION(0x0000),
2854 0, 0, 0, 1, 0},
2855 {NULL}
2856};
2857
2858#ifdef MODULE
2859static struct isapnp_device_id id_table[] = {
2860 { ISAPNP_VENDOR('C','M','I'), ISAPNP_DEVICE(0x0001),
2861 ISAPNP_VENDOR('@','@','@'), ISAPNP_FUNCTION(0x0001), 0 },
2862 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2863 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0000), 0 },
2864 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2865 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0100), 0 },
2866 /* The main driver for this card is opl3sa2
2867 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2868 ISAPNP_VENDOR('Y','M','H'), ISAPNP_FUNCTION(0x0021), 0 },
2869 */
2870 { ISAPNP_VENDOR('G','R','V'), ISAPNP_DEVICE(0x0001),
2871 ISAPNP_VENDOR('G','R','V'), ISAPNP_FUNCTION(0x0000), 0 },
2872 {0}
2873};
2874
2875MODULE_DEVICE_TABLE(isapnp, id_table);
2876#endif
2877
2878static struct pnp_dev *activate_dev(char *devname, char *resname, struct pnp_dev *dev)
2879{
2880 int err;
2881
2882 err = pnp_device_attach(dev);
2883 if (err < 0)
2884 return(NULL);
2885
2886 if((err = pnp_activate_dev(dev)) < 0) {
2887 printk(KERN_ERR "ad1848: %s %s config failed (out of resources?)[%d]\n", devname, resname, err);
2888
2889 pnp_device_detach(dev);
2890
2891 return(NULL);
2892 }
2893 audio_activated = 1;
2894 return(dev);
2895}
2896
2897static struct pnp_dev __init *ad1848_init_generic(struct pnp_card *bus,
2898 struct address_info *hw_config, int slot)
2899{
2900
2901 /* Configure Audio device */
2902 if((ad1848_dev = pnp_find_dev(bus, ad1848_isapnp_list[slot].vendor, ad1848_isapnp_list[slot].function, NULL)))
2903 {
2904 if((ad1848_dev = activate_dev(ad1848_isapnp_list[slot].name, "ad1848", ad1848_dev)))
2905 {
2906 hw_config->io_base = pnp_port_start(ad1848_dev, ad1848_isapnp_list[slot].mss_io);
2907 hw_config->irq = pnp_irq(ad1848_dev, ad1848_isapnp_list[slot].irq);
2908 hw_config->dma = pnp_dma(ad1848_dev, ad1848_isapnp_list[slot].dma);
2909 if(ad1848_isapnp_list[slot].dma2 != -1)
2910 hw_config->dma2 = pnp_dma(ad1848_dev, ad1848_isapnp_list[slot].dma2);
2911 else
2912 hw_config->dma2 = -1;
2913 hw_config->card_subtype = ad1848_isapnp_list[slot].type;
2914 } else
2915 return(NULL);
2916 } else
2917 return(NULL);
2918
2919 return(ad1848_dev);
2920}
2921
2922static int __init ad1848_isapnp_init(struct address_info *hw_config, struct pnp_card *bus, int slot)
2923{
2924 char *busname = bus->name[0] ? bus->name : ad1848_isapnp_list[slot].name;
2925
2926 /* Initialize this baby. */
2927
2928 if(ad1848_init_generic(bus, hw_config, slot)) {
2929 /* We got it. */
2930
2931 printk(KERN_NOTICE "ad1848: PnP reports '%s' at i/o %#x, irq %d, dma %d, %d\n",
2932 busname,
2933 hw_config->io_base, hw_config->irq, hw_config->dma,
2934 hw_config->dma2);
2935 return 1;
2936 }
2937 return 0;
2938}
2939
2940static int __init ad1848_isapnp_probe(struct address_info *hw_config)
2941{
2942 static int first = 1;
2943 int i;
2944
2945 /* Count entries in sb_isapnp_list */
2946 for (i = 0; ad1848_isapnp_list[i].card_vendor != 0; i++);
2947 i--;
2948
2949 /* Check and adjust isapnpjump */
2950 if( isapnpjump < 0 || isapnpjump > i) {
2951 isapnpjump = reverse ? i : 0;
2952 printk(KERN_ERR "ad1848: Valid range for isapnpjump is 0-%d. Adjusted to %d.\n", i, isapnpjump);
2953 }
2954
2955 if(!first || !reverse)
2956 i = isapnpjump;
2957 first = 0;
2958 while(ad1848_isapnp_list[i].card_vendor != 0) {
2959 static struct pnp_card *bus = NULL;
2960
2961 while ((bus = pnp_find_card(
2962 ad1848_isapnp_list[i].card_vendor,
2963 ad1848_isapnp_list[i].card_device,
2964 bus))) {
2965
2966 if(ad1848_isapnp_init(hw_config, bus, i)) {
2967 isapnpjump = i; /* start next search from here */
2968 return 0;
2969 }
2970 }
2971 i += reverse ? -1 : 1;
2972 }
2973
2974 return -ENODEV;
2975}
2976#endif
2977
2978
2979static int __init init_ad1848(void)
2980{
2981 printk(KERN_INFO "ad1848/cs4248 codec driver Copyright (C) by Hannu Savolainen 1993-1996\n");
2982
2983#ifdef CONFIG_PNP
2984 if(isapnp && (ad1848_isapnp_probe(&cfg) < 0) ) {
2985 printk(KERN_NOTICE "ad1848: No ISAPnP cards found, trying standard ones...\n");
2986 isapnp = 0;
2987 }
2988#endif
2989
2990 if(io != -1) {
2991 struct resource *ports;
2992 if( isapnp == 0 )
2993 {
2994 if(irq == -1 || dma == -1) {
2995 printk(KERN_WARNING "ad1848: must give I/O , IRQ and DMA.\n");
2996 return -EINVAL;
2997 }
2998
2999 cfg.irq = irq;
3000 cfg.io_base = io;
3001 cfg.dma = dma;
3002 cfg.dma2 = dma2;
3003 cfg.card_subtype = type;
3004 }
3005
3006 ports = request_region(io + 4, 4, "ad1848");
3007
3008 if (!ports)
3009 return -EBUSY;
3010
3011 if (!request_region(io, 4, "WSS config")) {
3012 release_region(io + 4, 4);
3013 return -EBUSY;
3014 }
3015
3016 if (!probe_ms_sound(&cfg, ports)) {
3017 release_region(io + 4, 4);
3018 release_region(io, 4);
3019 return -ENODEV;
3020 }
3021 attach_ms_sound(&cfg, ports, THIS_MODULE);
3022 loaded = 1;
3023 }
3024 return 0;
3025}
3026
3027static void __exit cleanup_ad1848(void)
3028{
3029 if(loaded)
3030 unload_ms_sound(&cfg);
3031
3032#ifdef CONFIG_PNP
3033 if(ad1848_dev){
3034 if(audio_activated)
3035 pnp_device_detach(ad1848_dev);
3036 }
3037#endif
3038}
3039
3040module_init(init_ad1848);
3041module_exit(cleanup_ad1848);
3042
3043#ifndef MODULE
3044static int __init setup_ad1848(char *str)
3045{
3046 /* io, irq, dma, dma2, type */
3047 int ints[6];
3048
3049 str = get_options(str, ARRAY_SIZE(ints), ints);
3050
3051 io = ints[1];
3052 irq = ints[2];
3053 dma = ints[3];
3054 dma2 = ints[4];
3055 type = ints[5];
3056
3057 return 1;
3058}
3059
3060__setup("ad1848=", setup_ad1848);
3061#endif
3062MODULE_LICENSE("GPL");
diff --git a/sound/oss/ad1848.h b/sound/oss/ad1848.h
deleted file mode 100644
index 390f03e13d09..000000000000
--- a/sound/oss/ad1848.h
+++ /dev/null
@@ -1,25 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2
3#include <linux/interrupt.h>
4
5#define AD_F_CS4231 0x0001 /* Returned if a CS4232 (or compatible) detected */
6#define AD_F_CS4248 0x0001 /* Returned if a CS4248 (or compatible) detected */
7
8#define AD1848_SET_XTAL 1
9#define AD1848_MIXER_REROUTE 2
10
11#define AD1848_REROUTE(oldctl, newctl) \
12 ad1848_control(AD1848_MIXER_REROUTE, ((oldctl)<<8)|(newctl))
13
14
15int ad1848_init(char *name, struct resource *ports, int irq, int dma_playback,
16 int dma_capture, int share_dma, int *osp, struct module *owner);
17void ad1848_unload (int io_base, int irq, int dma_playback, int dma_capture, int share_dma);
18
19int ad1848_detect (struct resource *ports, int *flags, int *osp);
20int ad1848_control(int cmd, int arg);
21
22void attach_ms_sound(struct address_info * hw_config, struct resource *ports, struct module * owner);
23
24int probe_ms_sound(struct address_info *hw_config, struct resource *ports);
25void unload_ms_sound(struct address_info *hw_info);
diff --git a/sound/oss/ad1848_mixer.h b/sound/oss/ad1848_mixer.h
deleted file mode 100644
index 2cf719b5fbbc..000000000000
--- a/sound/oss/ad1848_mixer.h
+++ /dev/null
@@ -1,253 +0,0 @@
1/*
2 * sound/oss/ad1848_mixer.h
3 *
4 * Definitions for the mixer of AD1848 and compatible codecs.
5 */
6
7/*
8 * Copyright (C) by Hannu Savolainen 1993-1997
9 *
10 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
11 * Version 2 (June 1991). See the "COPYING" file distributed with this software
12 * for more info.
13 */
14
15
16/*
17 * The AD1848 codec has generic input lines called Line, Aux1 and Aux2.
18 * Sound card manufacturers have connected actual inputs (CD, synth, line,
19 * etc) to these inputs in different order. Therefore it's difficult
20 * to assign mixer channels to these inputs correctly. The following
21 * contains two alternative mappings. The first one is for GUS MAX and
22 * the second is just a generic one (line1, line2 and line3).
23 * (Actually this is not a mapping but rather some kind of interleaving
24 * solution).
25 */
26#define MODE1_REC_DEVICES (SOUND_MASK_LINE3 | SOUND_MASK_MIC | \
27 SOUND_MASK_LINE1 | SOUND_MASK_IMIX)
28
29#define SPRO_REC_DEVICES (SOUND_MASK_LINE | SOUND_MASK_MIC | \
30 SOUND_MASK_CD | SOUND_MASK_LINE1)
31
32#define MODE1_MIXER_DEVICES (SOUND_MASK_LINE1 | SOUND_MASK_MIC | \
33 SOUND_MASK_LINE2 | \
34 SOUND_MASK_IGAIN | \
35 SOUND_MASK_PCM | SOUND_MASK_IMIX)
36
37#define MODE2_MIXER_DEVICES (SOUND_MASK_LINE1 | SOUND_MASK_LINE2 | \
38 SOUND_MASK_MIC | \
39 SOUND_MASK_LINE3 | SOUND_MASK_SPEAKER | \
40 SOUND_MASK_IGAIN | \
41 SOUND_MASK_PCM | SOUND_MASK_IMIX)
42
43#define MODE3_MIXER_DEVICES (MODE2_MIXER_DEVICES | SOUND_MASK_VOLUME)
44
45/* OPTi 82C930 has no IMIX level control, but it can still be selected as an
46 * input
47 */
48#define C930_MIXER_DEVICES (SOUND_MASK_LINE1 | SOUND_MASK_LINE2 | \
49 SOUND_MASK_MIC | SOUND_MASK_VOLUME | \
50 SOUND_MASK_LINE3 | \
51 SOUND_MASK_IGAIN | SOUND_MASK_PCM)
52
53#define SPRO_MIXER_DEVICES (SOUND_MASK_VOLUME | SOUND_MASK_PCM | \
54 SOUND_MASK_LINE | SOUND_MASK_SYNTH | \
55 SOUND_MASK_CD | SOUND_MASK_MIC | \
56 SOUND_MASK_SPEAKER | SOUND_MASK_LINE1 | \
57 SOUND_MASK_OGAIN)
58
59struct mixer_def {
60 unsigned int regno:6; /* register number for volume */
61 unsigned int polarity:1; /* volume polarity: 0=normal, 1=reversed */
62 unsigned int bitpos:3; /* position of bits in register for volume */
63 unsigned int nbits:3; /* number of bits in register for volume */
64 unsigned int mutereg:6; /* register number for mute bit */
65 unsigned int mutepol:1; /* mute polarity: 0=normal, 1=reversed */
66 unsigned int mutepos:4; /* position of mute bit in register */
67 unsigned int recreg:6; /* register number for recording bit */
68 unsigned int recpol:1; /* recording polarity: 0=normal, 1=reversed */
69 unsigned int recpos:4; /* position of recording bit in register */
70};
71
72static char mix_cvt[101] = {
73 0, 0, 3, 7,10,13,16,19,21,23,26,28,30,32,34,35,37,39,40,42,
74 43,45,46,47,49,50,51,52,53,55,56,57,58,59,60,61,62,63,64,65,
75 65,66,67,68,69,70,70,71,72,73,73,74,75,75,76,77,77,78,79,79,
76 80,81,81,82,82,83,84,84,85,85,86,86,87,87,88,88,89,89,90,90,
77 91,91,92,92,93,93,94,94,95,95,96,96,96,97,97,98,98,98,99,99,
78 100
79};
80
81typedef struct mixer_def mixer_ent;
82typedef mixer_ent mixer_ents[2];
83
84/*
85 * Most of the mixer entries work in backwards. Setting the polarity field
86 * makes them to work correctly.
87 *
88 * The channel numbering used by individual sound cards is not fixed. Some
89 * cards have assigned different meanings for the AUX1, AUX2 and LINE inputs.
90 * The current version doesn't try to compensate this.
91 */
92
93#define MIX_ENT(name, reg_l, pola_l, pos_l, len_l, reg_r, pola_r, pos_r, len_r, mute_bit) \
94 [name] = {{reg_l, pola_l, pos_l, len_l, reg_l, 0, mute_bit, 0, 0, 8}, \
95 {reg_r, pola_r, pos_r, len_r, reg_r, 0, mute_bit, 0, 0, 8}}
96
97#define MIX_ENT2(name, reg_l, pola_l, pos_l, len_l, mute_reg_l, mute_pola_l, mute_pos_l, \
98 rec_reg_l, rec_pola_l, rec_pos_l, \
99 reg_r, pola_r, pos_r, len_r, mute_reg_r, mute_pola_r, mute_pos_r, \
100 rec_reg_r, rec_pola_r, rec_pos_r) \
101 [name] = {{reg_l, pola_l, pos_l, len_l, mute_reg_l, mute_pola_l, mute_pos_l, \
102 rec_reg_l, rec_pola_l, rec_pos_l}, \
103 {reg_r, pola_r, pos_r, len_r, mute_reg_r, mute_pola_r, mute_pos_r, \
104 rec_reg_r, rec_pola_r, rec_pos_r}}
105
106static mixer_ents ad1848_mix_devices[32] = {
107 MIX_ENT(SOUND_MIXER_VOLUME, 27, 1, 0, 4, 29, 1, 0, 4, 8),
108 MIX_ENT(SOUND_MIXER_BASS, 0, 0, 0, 0, 0, 0, 0, 0, 8),
109 MIX_ENT(SOUND_MIXER_TREBLE, 0, 0, 0, 0, 0, 0, 0, 0, 8),
110 MIX_ENT(SOUND_MIXER_SYNTH, 4, 1, 0, 5, 5, 1, 0, 5, 7),
111 MIX_ENT(SOUND_MIXER_PCM, 6, 1, 0, 6, 7, 1, 0, 6, 7),
112 MIX_ENT(SOUND_MIXER_SPEAKER, 26, 1, 0, 4, 0, 0, 0, 0, 8),
113 MIX_ENT(SOUND_MIXER_LINE, 18, 1, 0, 5, 19, 1, 0, 5, 7),
114 MIX_ENT(SOUND_MIXER_MIC, 0, 0, 5, 1, 1, 0, 5, 1, 8),
115 MIX_ENT(SOUND_MIXER_CD, 2, 1, 0, 5, 3, 1, 0, 5, 7),
116 MIX_ENT(SOUND_MIXER_IMIX, 13, 1, 2, 6, 0, 0, 0, 0, 8),
117 MIX_ENT(SOUND_MIXER_ALTPCM, 0, 0, 0, 0, 0, 0, 0, 0, 8),
118 MIX_ENT(SOUND_MIXER_RECLEV, 0, 0, 0, 0, 0, 0, 0, 0, 8),
119 MIX_ENT(SOUND_MIXER_IGAIN, 0, 0, 0, 4, 1, 0, 0, 4, 8),
120 MIX_ENT(SOUND_MIXER_OGAIN, 0, 0, 0, 0, 0, 0, 0, 0, 8),
121 MIX_ENT(SOUND_MIXER_LINE1, 2, 1, 0, 5, 3, 1, 0, 5, 7),
122 MIX_ENT(SOUND_MIXER_LINE2, 4, 1, 0, 5, 5, 1, 0, 5, 7),
123 MIX_ENT(SOUND_MIXER_LINE3, 18, 1, 0, 5, 19, 1, 0, 5, 7)
124};
125
126static mixer_ents iwave_mix_devices[32] = {
127 MIX_ENT(SOUND_MIXER_VOLUME, 25, 1, 0, 5, 27, 1, 0, 5, 8),
128 MIX_ENT(SOUND_MIXER_BASS, 0, 0, 0, 0, 0, 0, 0, 0, 8),
129 MIX_ENT(SOUND_MIXER_TREBLE, 0, 0, 0, 0, 0, 0, 0, 0, 8),
130 MIX_ENT(SOUND_MIXER_SYNTH, 4, 1, 0, 5, 5, 1, 0, 5, 7),
131 MIX_ENT(SOUND_MIXER_PCM, 6, 1, 0, 6, 7, 1, 0, 6, 7),
132 MIX_ENT(SOUND_MIXER_SPEAKER, 26, 1, 0, 4, 0, 0, 0, 0, 8),
133 MIX_ENT(SOUND_MIXER_LINE, 18, 1, 0, 5, 19, 1, 0, 5, 7),
134 MIX_ENT(SOUND_MIXER_MIC, 0, 0, 5, 1, 1, 0, 5, 1, 8),
135 MIX_ENT(SOUND_MIXER_CD, 2, 1, 0, 5, 3, 1, 0, 5, 7),
136 MIX_ENT(SOUND_MIXER_IMIX, 16, 1, 0, 5, 17, 1, 0, 5, 8),
137 MIX_ENT(SOUND_MIXER_ALTPCM, 0, 0, 0, 0, 0, 0, 0, 0, 8),
138 MIX_ENT(SOUND_MIXER_RECLEV, 0, 0, 0, 0, 0, 0, 0, 0, 8),
139 MIX_ENT(SOUND_MIXER_IGAIN, 0, 0, 0, 4, 1, 0, 0, 4, 8),
140 MIX_ENT(SOUND_MIXER_OGAIN, 0, 0, 0, 0, 0, 0, 0, 0, 8),
141 MIX_ENT(SOUND_MIXER_LINE1, 2, 1, 0, 5, 3, 1, 0, 5, 7),
142 MIX_ENT(SOUND_MIXER_LINE2, 4, 1, 0, 5, 5, 1, 0, 5, 7),
143 MIX_ENT(SOUND_MIXER_LINE3, 18, 1, 0, 5, 19, 1, 0, 5, 7)
144};
145
146static mixer_ents cs42xb_mix_devices[32] = {
147 /* Digital master volume actually has seven bits, but we only use
148 six to avoid the discontinuity when the analog gain kicks in. */
149 MIX_ENT(SOUND_MIXER_VOLUME, 46, 1, 0, 6, 47, 1, 0, 6, 7),
150 MIX_ENT(SOUND_MIXER_BASS, 0, 0, 0, 0, 0, 0, 0, 0, 8),
151 MIX_ENT(SOUND_MIXER_TREBLE, 0, 0, 0, 0, 0, 0, 0, 0, 8),
152 MIX_ENT(SOUND_MIXER_SYNTH, 4, 1, 0, 5, 5, 1, 0, 5, 7),
153 MIX_ENT(SOUND_MIXER_PCM, 6, 1, 0, 6, 7, 1, 0, 6, 7),
154 MIX_ENT(SOUND_MIXER_SPEAKER, 26, 1, 0, 4, 0, 0, 0, 0, 8),
155 MIX_ENT(SOUND_MIXER_LINE, 18, 1, 0, 5, 19, 1, 0, 5, 7),
156 MIX_ENT(SOUND_MIXER_MIC, 34, 1, 0, 5, 35, 1, 0, 5, 7),
157 MIX_ENT(SOUND_MIXER_CD, 2, 1, 0, 5, 3, 1, 0, 5, 7),
158 /* For the IMIX entry, it was not possible to use the MIX_ENT macro
159 because the mute bit is in different positions for the two
160 channels and requires reverse polarity. */
161 [SOUND_MIXER_IMIX] = {{13, 1, 2, 6, 13, 1, 0, 0, 0, 8},
162 {42, 1, 0, 6, 42, 1, 7, 0, 0, 8}},
163 MIX_ENT(SOUND_MIXER_ALTPCM, 0, 0, 0, 0, 0, 0, 0, 0, 8),
164 MIX_ENT(SOUND_MIXER_RECLEV, 0, 0, 0, 0, 0, 0, 0, 0, 8),
165 MIX_ENT(SOUND_MIXER_IGAIN, 0, 0, 0, 4, 1, 0, 0, 4, 8),
166 MIX_ENT(SOUND_MIXER_OGAIN, 0, 0, 0, 0, 0, 0, 0, 0, 8),
167 MIX_ENT(SOUND_MIXER_LINE1, 2, 1, 0, 5, 3, 1, 0, 5, 7),
168 MIX_ENT(SOUND_MIXER_LINE2, 4, 1, 0, 5, 5, 1, 0, 5, 7),
169 MIX_ENT(SOUND_MIXER_LINE3, 38, 1, 0, 6, 39, 1, 0, 6, 7)
170};
171
172/* OPTi 82C930 has somewhat different port addresses.
173 * Note: VOLUME == SPEAKER, SYNTH == LINE2, LINE == LINE3, CD == LINE1
174 * VOLUME, SYNTH, LINE, CD are not enabled above.
175 * MIC is level of mic monitoring direct to output. Same for CD, LINE, etc.
176 */
177static mixer_ents c930_mix_devices[32] = {
178 MIX_ENT(SOUND_MIXER_VOLUME, 22, 1, 1, 5, 23, 1, 1, 5, 7),
179 MIX_ENT(SOUND_MIXER_BASS, 0, 0, 0, 0, 0, 0, 0, 0, 8),
180 MIX_ENT(SOUND_MIXER_TREBLE, 0, 0, 0, 0, 0, 0, 0, 0, 8),
181 MIX_ENT(SOUND_MIXER_SYNTH, 4, 1, 1, 4, 5, 1, 1, 4, 7),
182 MIX_ENT(SOUND_MIXER_PCM, 6, 1, 0, 5, 7, 1, 0, 5, 7),
183 MIX_ENT(SOUND_MIXER_SPEAKER, 22, 1, 1, 5, 23, 1, 1, 5, 7),
184 MIX_ENT(SOUND_MIXER_LINE, 18, 1, 1, 4, 19, 1, 1, 4, 7),
185 MIX_ENT(SOUND_MIXER_MIC, 20, 1, 1, 4, 21, 1, 1, 4, 7),
186 MIX_ENT(SOUND_MIXER_CD, 2, 1, 1, 4, 3, 1, 1, 4, 7),
187 MIX_ENT(SOUND_MIXER_IMIX, 0, 0, 0, 0, 0, 0, 0, 0, 8),
188 MIX_ENT(SOUND_MIXER_ALTPCM, 0, 0, 0, 0, 0, 0, 0, 0, 8),
189 MIX_ENT(SOUND_MIXER_RECLEV, 0, 0, 0, 0, 0, 0, 0, 0, 8),
190 MIX_ENT(SOUND_MIXER_IGAIN, 0, 0, 0, 4, 1, 0, 0, 4, 8),
191 MIX_ENT(SOUND_MIXER_OGAIN, 0, 0, 0, 0, 0, 0, 0, 0, 8),
192 MIX_ENT(SOUND_MIXER_LINE1, 2, 1, 1, 4, 3, 1, 1, 4, 7),
193 MIX_ENT(SOUND_MIXER_LINE2, 4, 1, 1, 4, 5, 1, 1, 4, 7),
194 MIX_ENT(SOUND_MIXER_LINE3, 18, 1, 1, 4, 19, 1, 1, 4, 7)
195};
196
197static mixer_ents spro_mix_devices[32] = {
198 MIX_ENT (SOUND_MIXER_VOLUME, 19, 0, 4, 4, 19, 0, 0, 4, 8),
199 MIX_ENT (SOUND_MIXER_BASS, 0, 0, 0, 0, 0, 0, 0, 0, 8),
200 MIX_ENT (SOUND_MIXER_TREBLE, 0, 0, 0, 0, 0, 0, 0, 0, 8),
201 MIX_ENT2(SOUND_MIXER_SYNTH, 4, 1, 1, 4, 23, 0, 3, 0, 0, 8,
202 5, 1, 1, 4, 23, 0, 3, 0, 0, 8),
203 MIX_ENT (SOUND_MIXER_PCM, 6, 1, 1, 4, 7, 1, 1, 4, 8),
204 MIX_ENT (SOUND_MIXER_SPEAKER, 18, 0, 3, 2, 0, 0, 0, 0, 8),
205 MIX_ENT2(SOUND_MIXER_LINE, 20, 0, 4, 4, 17, 1, 4, 16, 0, 2,
206 20, 0, 0, 4, 17, 1, 3, 16, 0, 1),
207 MIX_ENT2(SOUND_MIXER_MIC, 18, 0, 0, 3, 17, 1, 0, 16, 0, 0,
208 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
209 MIX_ENT2(SOUND_MIXER_CD, 21, 0, 4, 4, 17, 1, 2, 16, 0, 4,
210 21, 0, 0, 4, 17, 1, 1, 16, 0, 3),
211 MIX_ENT (SOUND_MIXER_IMIX, 0, 0, 0, 0, 0, 0, 0, 0, 8),
212 MIX_ENT (SOUND_MIXER_ALTPCM, 0, 0, 0, 0, 0, 0, 0, 0, 8),
213 MIX_ENT (SOUND_MIXER_RECLEV, 0, 0, 0, 0, 0, 0, 0, 0, 8),
214 MIX_ENT (SOUND_MIXER_IGAIN, 0, 0, 0, 0, 0, 0, 0, 0, 8),
215 MIX_ENT (SOUND_MIXER_OGAIN, 17, 1, 6, 1, 0, 0, 0, 0, 8),
216 /* This is external wavetable */
217 MIX_ENT2(SOUND_MIXER_LINE1, 22, 0, 4, 4, 23, 1, 1, 23, 0, 4,
218 22, 0, 0, 4, 23, 1, 0, 23, 0, 5),
219};
220
221static int default_mixer_levels[32] =
222{
223 0x3232, /* Master Volume */
224 0x3232, /* Bass */
225 0x3232, /* Treble */
226 0x4b4b, /* FM */
227 0x3232, /* PCM */
228 0x1515, /* PC Speaker */
229 0x2020, /* Ext Line */
230 0x1010, /* Mic */
231 0x4b4b, /* CD */
232 0x0000, /* Recording monitor */
233 0x4b4b, /* Second PCM */
234 0x4b4b, /* Recording level */
235 0x4b4b, /* Input gain */
236 0x4b4b, /* Output gain */
237 0x2020, /* Line1 */
238 0x2020, /* Line2 */
239 0x1515 /* Line3 (usually line in)*/
240};
241
242#define LEFT_CHN 0
243#define RIGHT_CHN 1
244
245/*
246 * Channel enable bits for ioctl(SOUND_MIXER_PRIVATE1)
247 */
248
249#ifndef AUDIO_SPEAKER
250#define AUDIO_SPEAKER 0x01 /* Enable mono output */
251#define AUDIO_HEADPHONE 0x02 /* Sparc only */
252#define AUDIO_LINE_OUT 0x04 /* Sparc only */
253#endif
diff --git a/sound/oss/aedsp16.c b/sound/oss/aedsp16.c
deleted file mode 100644
index f058ed6bdb69..000000000000
--- a/sound/oss/aedsp16.c
+++ /dev/null
@@ -1,1373 +0,0 @@
1/*
2 sound/oss/aedsp16.c
3
4 Audio Excel DSP 16 software configuration routines
5 Copyright (C) 1995,1996,1997,1998 Riccardo Facchetti (fizban@tin.it)
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 as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 */
22/*
23 * Include the main OSS Lite header file. It include all the os, OSS Lite, etc
24 * headers needed by this source.
25 */
26#include <linux/delay.h>
27#include <linux/module.h>
28#include <linux/init.h>
29#include "sound_config.h"
30
31/*
32
33 READ THIS
34
35 This module started to configure the Audio Excel DSP 16 Sound Card.
36 Now works with the SC-6000 (old aedsp16) and new SC-6600 based cards.
37
38 NOTE: I have NO idea about Audio Excel DSP 16 III. If someone owns this
39 audio card and want to see the kernel support for it, please contact me.
40
41 Audio Excel DSP 16 is an SB pro II, Microsoft Sound System and MPU-401
42 compatible card.
43 It is software-only configurable (no jumpers to hard-set irq/dma/mpu-irq),
44 so before this module, the only way to configure the DSP under linux was
45 boot the MS-DOS loading the sound.sys device driver (this driver soft-
46 configure the sound board hardware by massaging someone of its registers),
47 and then ctrl-alt-del to boot linux with the DSP configured by the DOS
48 driver.
49
50 This module works configuring your Audio Excel DSP 16's irq, dma and
51 mpu-401-irq. The OSS Lite routines rely on the fact that if the
52 hardware is there, they can detect it. The problem with AEDSP16 is
53 that no hardware can be found by the probe routines if the sound card
54 is not configured properly. Sometimes the kernel probe routines can find
55 an SBPRO even when the card is not configured (this is the standard setup
56 of the card), but the SBPRO emulation don't work well if the card is not
57 properly initialized. For this reason
58
59 aedsp16_init_board()
60
61 routine is called before the OSS Lite probe routines try to detect the
62 hardware.
63
64 NOTE (READ THE NOTE TOO, IT CONTAIN USEFUL INFORMATIONS)
65
66 NOTE: Now it works with SC-6000 and SC-6600 based audio cards. The new cards
67 have no jumper switch at all. No more WSS or MPU-401 I/O port switches. They
68 have to be configured by software.
69
70 NOTE: The driver is merged with the new OSS Lite sound driver. It works
71 as a lowlevel driver.
72
73 The Audio Excel DSP 16 Sound Card emulates both SBPRO and MSS;
74 the OSS Lite sound driver can be configured for SBPRO and MSS cards
75 at the same time, but the aedsp16 can't be two cards!!
76 When we configure it, we have to choose the SBPRO or the MSS emulation
77 for AEDSP16. We also can install a *REAL* card of the other type (see [1]).
78
79 NOTE: If someone can test the combination AEDSP16+MSS or AEDSP16+SBPRO
80 please let me know if it works.
81
82 The MPU-401 support can be compiled in together with one of the other
83 two operating modes.
84
85 NOTE: This is something like plug-and-play: we have only to plug
86 the AEDSP16 board in the socket, and then configure and compile
87 a kernel that uses the AEDSP16 software configuration capability.
88 No jumper setting is needed!
89
90 For example, if you want AEDSP16 to be an SBPro, on irq 10, dma 3
91 you have just to make config the OSS Lite package, configuring
92 the AEDSP16 sound card, then activating the SBPro emulation mode
93 and at last configuring IRQ and DMA.
94 Compile the kernel and run it.
95
96 NOTE: This means for SC-6000 cards that you can choose irq and dma,
97 but not the I/O addresses. To change I/O addresses you have to set
98 them with jumpers. For SC-6600 cards you have no jumpers so you have
99 to set up your full card configuration in the make config.
100
101 You can change the irq/dma/mirq settings WITHOUT THE NEED to open
102 your computer and massage the jumpers (there are no irq/dma/mirq
103 jumpers to be configured anyway, only I/O BASE values have to be
104 configured with jumpers)
105
106 For some ununderstandable reason, the card default of irq 7, dma 1,
107 don't work for me. Seems to be an IRQ or DMA conflict. Under heavy
108 HDD work, the kernel start to erupt out a lot of messages like:
109
110 'Sound: DMA timed out - IRQ/DRQ config error?'
111
112 For what I can say, I have NOT any conflict at irq 7 (under linux I'm
113 using the lp polling driver), and dma line 1 is unused as stated by
114 /proc/dma. I can suppose this is a bug of AEDSP16. I know my hardware so
115 I'm pretty sure I have not any conflict, but may be I'm wrong. Who knows!
116 Anyway a setting of irq 10, dma 3 works really fine.
117
118 NOTE: if someone can use AEDSP16 with irq 7, dma 1, please let me know
119 the emulation mode, all the installed hardware and the hardware
120 configuration (irq and dma settings of all the hardware).
121
122 This init module should work with SBPRO+MSS, when one of the two is
123 the AEDSP16 emulation and the other the real card. (see [1])
124 For example:
125
126 AEDSP16 (0x220) in SBPRO emu (0x220) + real MSS + other
127 AEDSP16 (0x220) in MSS emu + real SBPRO (0x240) + other
128
129 MPU401 should work. (see [2])
130
131 [1]
132 ---
133 Date: Mon, 29 Jul 1997 08:35:40 +0100
134 From: Mr S J Greenaway <sjg95@unixfe.rl.ac.uk>
135
136 [...]
137 Just to let you know got my Audio Excel (emulating a MSS) working
138 with my original SB16, thanks for the driver!
139 [...]
140 ---
141
142 [2] Not tested by me for lack of hardware.
143
144 TODO, WISHES AND TECH
145
146 - About I/O ports allocation -
147
148 Request the 2x0h region (port base) in any case if we are using this card.
149
150 NOTE: the "aedsp16 (base)" string with which we are requesting the aedsp16
151 port base region (see code) does not mean necessarily that we are emulating
152 sbpro. Even if this region is the sbpro I/O ports region, we use this
153 region to access the control registers of the card, and if emulating
154 sbpro, I/O sbpro registers too. If we are emulating MSS, the sbpro
155 registers are not used, in no way, to emulate an sbpro: they are
156 used only for configuration purposes.
157
158 Started Fri Mar 17 16:13:18 MET 1995
159
160 v0.1 (ALPHA, was a user-level program called AudioExcelDSP16.c)
161 - Initial code.
162 v0.2 (ALPHA)
163 - Cleanups.
164 - Integrated with Linux voxware v 2.90-2 kernel sound driver.
165 - SoundBlaster Pro mode configuration.
166 - Microsoft Sound System mode configuration.
167 - MPU-401 mode configuration.
168 v0.3 (ALPHA)
169 - Cleanups.
170 - Rearranged the code to let aedsp16_init_board be more general.
171 - Erased the REALLY_SLOW_IO. We don't need it. Erased the linux/io.h
172 inclusion too. We rely on os.h
173 - Used the to get a variable
174 len string (we are not sure about the len of Copyright string).
175 This works with any SB and compatible.
176 - Added the code to request_region at device init (should go in
177 the main body of voxware).
178 v0.4 (BETA)
179 - Better configure.c patch for aedsp16 configuration (better
180 logic of inclusion of AEDSP16 support)
181 - Modified the conditional compilation to better support more than
182 one sound card of the emulated type (read the NOTES above)
183 - Moved the sb init routine from the attach to the very first
184 probe in sb_card.c
185 - Rearrangements and cleanups
186 - Wiped out some unnecessary code and variables: this is kernel
187 code so it is better save some TEXT and DATA
188 - Fixed the request_region code. We must allocate the aedsp16 (sbpro)
189 I/O ports in any case because they are used to access the DSP
190 configuration registers and we can not allow anyone to get them.
191 v0.5
192 - cleanups on comments
193 - prep for diffs against v3.0-proto-950402
194 v0.6
195 - removed the request_region()s when compiling the MODULE sound.o
196 because we are not allowed (by the actual voxware structure) to
197 release_region()
198 v0.7 (pre ALPHA, not distributed)
199 - started porting this module to kernel 1.3.84. Dummy probe/attach
200 routines.
201 v0.8 (ALPHA)
202 - attached all the init routines.
203 v0.9 (BETA)
204 - Integrated with linux-pre2.0.7
205 - Integrated with configuration scripts.
206 - Cleaned up and beautyfied the code.
207 v0.9.9 (BETA)
208 - Thanks to Piercarlo Grandi: corrected the conditonal compilation code.
209 Now only the code configured is compiled in, with some memory saving.
210 v0.9.10
211 - Integration into the sound/lowlevel/ section of the sound driver.
212 - Re-organized the code.
213 v0.9.11 (not distributed)
214 - Rewritten the init interface-routines to initialize the AEDSP16 in
215 one shot.
216 - More cosmetics.
217 - SC-6600 support.
218 - More soft/hard configuration.
219 v0.9.12
220 - Refined the v0.9.11 code with conditional compilation to distinguish
221 between SC-6000 and SC-6600 code.
222 v1.0.0
223 - Prep for merging with OSS Lite and Linux kernel 2.1.13
224 - Corrected a bug in request/check/release region calls (thanks to the
225 new kernel exception handling).
226 v1.1
227 - Revamped for integration with new modularized sound drivers: to enhance
228 the flexibility of modular version, I have removed all the conditional
229 compilation for SBPRO, MPU and MSS code. Now it is all managed with
230 the ae_config structure.
231 v1.2
232 - Module informations added.
233 - Removed aedsp16_delay_10msec(), now using mdelay(10)
234 - All data and funcs moved to .*.init section.
235 v1.3
236 Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 2000/09/27
237 - got rid of check_region
238
239 Known Problems:
240 - Audio Excel DSP 16 III don't work with this driver.
241
242 Credits:
243 Many thanks to Gerald Britton <gbritton@CapAccess.org>. He helped me a
244 lot in testing the 0.9.11 and 0.9.12 versions of this driver.
245
246 */
247
248
249#define VERSION "1.3" /* Version of Audio Excel DSP 16 driver */
250
251#undef AEDSP16_DEBUG /* Define this to 1 to enable debug code */
252#undef AEDSP16_DEBUG_MORE /* Define this to 1 to enable more debug */
253#undef AEDSP16_INFO /* Define this to 1 to enable info code */
254
255#if defined(AEDSP16_DEBUG)
256# define DBG(x) printk x
257# if defined(AEDSP16_DEBUG_MORE)
258# define DBG1(x) printk x
259# else
260# define DBG1(x)
261# endif
262#else
263# define DBG(x)
264# define DBG1(x)
265#endif
266
267/*
268 * Misc definitions
269 */
270#define TRUE 1
271#define FALSE 0
272
273/*
274 * Region Size for request/check/release region.
275 */
276#define IOBASE_REGION_SIZE 0x10
277
278/*
279 * Hardware related defaults
280 */
281#define DEF_AEDSP16_IOB 0x220 /* 0x220(default) 0x240 */
282#define DEF_AEDSP16_IRQ 7 /* 5 7(default) 9 10 11 */
283#define DEF_AEDSP16_MRQ 0 /* 5 7 9 10 0(default), 0 means disable */
284#define DEF_AEDSP16_DMA 1 /* 0 1(default) 3 */
285
286/*
287 * Commands of AEDSP16's DSP (SBPRO+special).
288 * Some of them are COMMAND_xx, in the future they may change.
289 */
290#define WRITE_MDIRQ_CFG 0x50 /* Set M&I&DRQ mask (the real config) */
291#define COMMAND_52 0x52 /* */
292#define READ_HARD_CFG 0x58 /* Read Hardware Config (I/O base etc) */
293#define COMMAND_5C 0x5c /* */
294#define COMMAND_60 0x60 /* */
295#define COMMAND_66 0x66 /* */
296#define COMMAND_6C 0x6c /* */
297#define COMMAND_6E 0x6e /* */
298#define COMMAND_88 0x88 /* */
299#define DSP_INIT_MSS 0x8c /* Enable Microsoft Sound System mode */
300#define COMMAND_C5 0xc5 /* */
301#define GET_DSP_VERSION 0xe1 /* Get DSP Version */
302#define GET_DSP_COPYRIGHT 0xe3 /* Get DSP Copyright */
303
304/*
305 * Offsets of AEDSP16 DSP I/O ports. The offset is added to base I/O port
306 * to have the actual I/O port.
307 * Register permissions are:
308 * (wo) == Write Only
309 * (ro) == Read Only
310 * (w-) == Write
311 * (r-) == Read
312 */
313#define DSP_RESET 0x06 /* offset of DSP RESET (wo) */
314#define DSP_READ 0x0a /* offset of DSP READ (ro) */
315#define DSP_WRITE 0x0c /* offset of DSP WRITE (w-) */
316#define DSP_COMMAND 0x0c /* offset of DSP COMMAND (w-) */
317#define DSP_STATUS 0x0c /* offset of DSP STATUS (r-) */
318#define DSP_DATAVAIL 0x0e /* offset of DSP DATA AVAILABLE (ro) */
319
320
321#define RETRY 10 /* Various retry values on I/O opera- */
322#define STATUSRETRY 1000 /* tions. Sometimes we have to */
323#define HARDRETRY 500000 /* wait for previous cmd to complete */
324
325/*
326 * Size of character arrays that store name and version of sound card
327 */
328#define CARDNAMELEN 15 /* Size of the card's name in chars */
329#define CARDVERLEN 10 /* Size of the card's version in chars */
330#define CARDVERDIGITS 2 /* Number of digits in the version */
331
332#if defined(CONFIG_SC6600)
333/*
334 * Bitmapped flags of hard configuration
335 */
336/*
337 * Decode macros (xl == low byte, xh = high byte)
338 */
339#define IOBASE(xl) ((xl & 0x01)?0x240:0x220)
340#define JOY(xl) (xl & 0x02)
341#define MPUADDR(xl) ( \
342 (xl & 0x0C)?0x330: \
343 (xl & 0x08)?0x320: \
344 (xl & 0x04)?0x310: \
345 0x300)
346#define WSSADDR(xl) ((xl & 0x10)?0xE80:0x530)
347#define CDROM(xh) (xh & 0x20)
348#define CDROMADDR(xh) (((xh & 0x1F) << 4) + 0x200)
349/*
350 * Encode macros
351 */
352#define BLDIOBASE(xl, val) { \
353 xl &= ~0x01; \
354 if (val == 0x240) \
355 xl |= 0x01; \
356 }
357#define BLDJOY(xl, val) { \
358 xl &= ~0x02; \
359 if (val == 1) \
360 xl |= 0x02; \
361 }
362#define BLDMPUADDR(xl, val) { \
363 xl &= ~0x0C; \
364 switch (val) { \
365 case 0x330: \
366 xl |= 0x0C; \
367 break; \
368 case 0x320: \
369 xl |= 0x08; \
370 break; \
371 case 0x310: \
372 xl |= 0x04; \
373 break; \
374 case 0x300: \
375 xl |= 0x00; \
376 break; \
377 default: \
378 xl |= 0x00; \
379 break; \
380 } \
381 }
382#define BLDWSSADDR(xl, val) { \
383 xl &= ~0x10; \
384 if (val == 0xE80) \
385 xl |= 0x10; \
386 }
387#define BLDCDROM(xh, val) { \
388 xh &= ~0x20; \
389 if (val == 1) \
390 xh |= 0x20; \
391 }
392#define BLDCDROMADDR(xh, val) { \
393 int tmp = val; \
394 tmp -= 0x200; \
395 tmp >>= 4; \
396 tmp &= 0x1F; \
397 xh |= tmp; \
398 xh &= 0x7F; \
399 xh |= 0x40; \
400 }
401#endif /* CONFIG_SC6600 */
402
403/*
404 * Bit mapped flags for calling aedsp16_init_board(), and saving the current
405 * emulation mode.
406 */
407#define INIT_NONE (0 )
408#define INIT_SBPRO (1<<0)
409#define INIT_MSS (1<<1)
410#define INIT_MPU401 (1<<2)
411
412static int soft_cfg __initdata = 0; /* bitmapped config */
413static int soft_cfg_mss __initdata = 0; /* bitmapped mss config */
414static int ver[CARDVERDIGITS] __initdata = {0, 0}; /* DSP Ver:
415 hi->ver[0] lo->ver[1] */
416
417#if defined(CONFIG_SC6600)
418static int hard_cfg[2] /* lo<-hard_cfg[0] hi<-hard_cfg[1] */
419 __initdata = { 0, 0};
420#endif /* CONFIG_SC6600 */
421
422#if defined(CONFIG_SC6600)
423/* Decoded hard configuration */
424struct d_hcfg {
425 int iobase;
426 int joystick;
427 int mpubase;
428 int wssbase;
429 int cdrom;
430 int cdrombase;
431};
432
433static struct d_hcfg decoded_hcfg __initdata = {0, };
434
435#endif /* CONFIG_SC6600 */
436
437/* orVals contain the values to be or'ed */
438struct orVals {
439 int val; /* irq|mirq|dma */
440 int or; /* soft_cfg |= TheStruct.or */
441};
442
443/* aedsp16_info contain the audio card configuration */
444struct aedsp16_info {
445 int base_io; /* base I/O address for accessing card */
446 int irq; /* irq value for DSP I/O */
447 int mpu_irq; /* irq for mpu401 interface I/O */
448 int dma; /* dma value for DSP I/O */
449 int mss_base; /* base I/O for Microsoft Sound System */
450 int mpu_base; /* base I/O for MPU-401 emulation */
451 int init; /* Initialization status of the card */
452};
453
454/*
455 * Magic values that the DSP will eat when configuring irq/mirq/dma
456 */
457/* DSP IRQ conversion array */
458static struct orVals orIRQ[] __initdata = {
459 {0x05, 0x28},
460 {0x07, 0x08},
461 {0x09, 0x10},
462 {0x0a, 0x18},
463 {0x0b, 0x20},
464 {0x00, 0x00}
465};
466
467/* MPU-401 IRQ conversion array */
468static struct orVals orMIRQ[] __initdata = {
469 {0x05, 0x04},
470 {0x07, 0x44},
471 {0x09, 0x84},
472 {0x0a, 0xc4},
473 {0x00, 0x00}
474};
475
476/* DMA Channels conversion array */
477static struct orVals orDMA[] __initdata = {
478 {0x00, 0x01},
479 {0x01, 0x02},
480 {0x03, 0x03},
481 {0x00, 0x00}
482};
483
484static struct aedsp16_info ae_config = {
485 .base_io = DEF_AEDSP16_IOB,
486 .irq = DEF_AEDSP16_IRQ,
487 .mpu_irq = DEF_AEDSP16_MRQ,
488 .dma = DEF_AEDSP16_DMA,
489 .mss_base = -1,
490 .mpu_base = -1,
491 .init = INIT_NONE
492};
493
494/*
495 * Buffers to store audio card informations
496 */
497static char DSPCopyright[CARDNAMELEN + 1] __initdata = {0, };
498static char DSPVersion[CARDVERLEN + 1] __initdata = {0, };
499
500static int __init aedsp16_wait_data(int port)
501{
502 int loop = STATUSRETRY;
503 unsigned char ret = 0;
504
505 DBG1(("aedsp16_wait_data (0x%x): ", port));
506
507 do {
508 ret = inb(port + DSP_DATAVAIL);
509 /*
510 * Wait for data available (bit 7 of ret == 1)
511 */
512 } while (!(ret & 0x80) && loop--);
513
514 if (ret & 0x80) {
515 DBG1(("success.\n"));
516 return TRUE;
517 }
518
519 DBG1(("failure.\n"));
520 return FALSE;
521}
522
523static int __init aedsp16_read(int port)
524{
525 int inbyte;
526
527 DBG((" Read DSP Byte (0x%x): ", port));
528
529 if (aedsp16_wait_data(port) == FALSE) {
530 DBG(("failure.\n"));
531 return -1;
532 }
533
534 inbyte = inb(port + DSP_READ);
535
536 DBG(("read [0x%x]/{%c}.\n", inbyte, inbyte));
537
538 return inbyte;
539}
540
541static int __init aedsp16_test_dsp(int port)
542{
543 return ((aedsp16_read(port) == 0xaa) ? TRUE : FALSE);
544}
545
546static int __init aedsp16_dsp_reset(int port)
547{
548 /*
549 * Reset DSP
550 */
551
552 DBG(("Reset DSP:\n"));
553
554 outb(1, (port + DSP_RESET));
555 udelay(10);
556 outb(0, (port + DSP_RESET));
557 udelay(10);
558 udelay(10);
559 if (aedsp16_test_dsp(port) == TRUE) {
560 DBG(("success.\n"));
561 return TRUE;
562 } else
563 DBG(("failure.\n"));
564 return FALSE;
565}
566
567static int __init aedsp16_write(int port, int cmd)
568{
569 unsigned char ret;
570 int loop = HARDRETRY;
571
572 DBG((" Write DSP Byte (0x%x) [0x%x]: ", port, cmd));
573
574 do {
575 ret = inb(port + DSP_STATUS);
576 /*
577 * DSP ready to receive data if bit 7 of ret == 0
578 */
579 if (!(ret & 0x80)) {
580 outb(cmd, port + DSP_COMMAND);
581 DBG(("success.\n"));
582 return 0;
583 }
584 } while (loop--);
585
586 DBG(("timeout.\n"));
587 printk("[AEDSP16] DSP Command (0x%x) timeout.\n", cmd);
588
589 return -1;
590}
591
592#if defined(CONFIG_SC6600)
593
594#if defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
595void __init aedsp16_pinfo(void) {
596 DBG(("\n Base address: %x\n", decoded_hcfg.iobase));
597 DBG((" Joystick : %s present\n", decoded_hcfg.joystick?"":" not"));
598 DBG((" WSS addr : %x\n", decoded_hcfg.wssbase));
599 DBG((" MPU-401 addr: %x\n", decoded_hcfg.mpubase));
600 DBG((" CDROM : %s present\n", (decoded_hcfg.cdrom!=4)?"":" not"));
601 DBG((" CDROMADDR : %x\n\n", decoded_hcfg.cdrombase));
602}
603#endif
604
605static void __init aedsp16_hard_decode(void) {
606
607 DBG((" aedsp16_hard_decode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
608
609/*
610 * Decode Cfg Bytes.
611 */
612 decoded_hcfg.iobase = IOBASE(hard_cfg[0]);
613 decoded_hcfg.joystick = JOY(hard_cfg[0]);
614 decoded_hcfg.wssbase = WSSADDR(hard_cfg[0]);
615 decoded_hcfg.mpubase = MPUADDR(hard_cfg[0]);
616 decoded_hcfg.cdrom = CDROM(hard_cfg[1]);
617 decoded_hcfg.cdrombase = CDROMADDR(hard_cfg[1]);
618
619#if defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
620 printk(" Original sound card configuration:\n");
621 aedsp16_pinfo();
622#endif
623
624/*
625 * Now set up the real kernel configuration.
626 */
627 decoded_hcfg.iobase = ae_config.base_io;
628 decoded_hcfg.wssbase = ae_config.mss_base;
629 decoded_hcfg.mpubase = ae_config.mpu_base;
630
631#if defined(CONFIG_SC6600_JOY)
632 decoded_hcfg.joystick = CONFIG_SC6600_JOY; /* Enable */
633#endif
634#if defined(CONFIG_SC6600_CDROM)
635 decoded_hcfg.cdrom = CONFIG_SC6600_CDROM; /* 4:N-3:I-2:G-1:P-0:S */
636#endif
637#if defined(CONFIG_SC6600_CDROMBASE)
638 decoded_hcfg.cdrombase = CONFIG_SC6600_CDROMBASE; /* 0 Disable */
639#endif
640
641#if defined(AEDSP16_DEBUG)
642 DBG((" New Values:\n"));
643 aedsp16_pinfo();
644#endif
645
646 DBG(("success.\n"));
647}
648
649static void __init aedsp16_hard_encode(void) {
650
651 DBG((" aedsp16_hard_encode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
652
653 hard_cfg[0] = 0;
654 hard_cfg[1] = 0;
655
656 hard_cfg[0] |= 0x20;
657
658 BLDIOBASE (hard_cfg[0], decoded_hcfg.iobase);
659 BLDWSSADDR(hard_cfg[0], decoded_hcfg.wssbase);
660 BLDMPUADDR(hard_cfg[0], decoded_hcfg.mpubase);
661 BLDJOY(hard_cfg[0], decoded_hcfg.joystick);
662 BLDCDROM(hard_cfg[1], decoded_hcfg.cdrom);
663 BLDCDROMADDR(hard_cfg[1], decoded_hcfg.cdrombase);
664
665#if defined(AEDSP16_DEBUG)
666 aedsp16_pinfo();
667#endif
668
669 DBG((" aedsp16_hard_encode: 0x%x, 0x%x\n", hard_cfg[0], hard_cfg[1]));
670 DBG(("success.\n"));
671
672}
673
674static int __init aedsp16_hard_write(int port) {
675
676 DBG(("aedsp16_hard_write:\n"));
677
678 if (aedsp16_write(port, COMMAND_6C)) {
679 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_6C);
680 DBG(("failure.\n"));
681 return FALSE;
682 }
683 if (aedsp16_write(port, COMMAND_5C)) {
684 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
685 DBG(("failure.\n"));
686 return FALSE;
687 }
688 if (aedsp16_write(port, hard_cfg[0])) {
689 printk("[AEDSP16] DATA 0x%x: failed!\n", hard_cfg[0]);
690 DBG(("failure.\n"));
691 return FALSE;
692 }
693 if (aedsp16_write(port, hard_cfg[1])) {
694 printk("[AEDSP16] DATA 0x%x: failed!\n", hard_cfg[1]);
695 DBG(("failure.\n"));
696 return FALSE;
697 }
698 if (aedsp16_write(port, COMMAND_C5)) {
699 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_C5);
700 DBG(("failure.\n"));
701 return FALSE;
702 }
703
704 DBG(("success.\n"));
705
706 return TRUE;
707}
708
709static int __init aedsp16_hard_read(int port) {
710
711 DBG(("aedsp16_hard_read:\n"));
712
713 if (aedsp16_write(port, READ_HARD_CFG)) {
714 printk("[AEDSP16] CMD 0x%x: failed!\n", READ_HARD_CFG);
715 DBG(("failure.\n"));
716 return FALSE;
717 }
718
719 if ((hard_cfg[0] = aedsp16_read(port)) == -1) {
720 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
721 READ_HARD_CFG);
722 DBG(("failure.\n"));
723 return FALSE;
724 }
725 if ((hard_cfg[1] = aedsp16_read(port)) == -1) {
726 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
727 READ_HARD_CFG);
728 DBG(("failure.\n"));
729 return FALSE;
730 }
731 if (aedsp16_read(port) == -1) {
732 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
733 READ_HARD_CFG);
734 DBG(("failure.\n"));
735 return FALSE;
736 }
737
738 DBG(("success.\n"));
739
740 return TRUE;
741}
742
743static int __init aedsp16_ext_cfg_write(int port) {
744
745 int extcfg, val;
746
747 if (aedsp16_write(port, COMMAND_66)) {
748 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_66);
749 return FALSE;
750 }
751
752 extcfg = 7;
753 if (decoded_hcfg.cdrom != 2)
754 extcfg = 0x0F;
755 if ((decoded_hcfg.cdrom == 4) ||
756 (decoded_hcfg.cdrom == 3))
757 extcfg &= ~2;
758 if (decoded_hcfg.cdrombase == 0)
759 extcfg &= ~2;
760 if (decoded_hcfg.mpubase == 0)
761 extcfg &= ~1;
762
763 if (aedsp16_write(port, extcfg)) {
764 printk("[AEDSP16] Write extcfg: failed!\n");
765 return FALSE;
766 }
767 if (aedsp16_write(port, 0)) {
768 printk("[AEDSP16] Write extcfg: failed!\n");
769 return FALSE;
770 }
771 if (decoded_hcfg.cdrom == 3) {
772 if (aedsp16_write(port, COMMAND_52)) {
773 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_52);
774 return FALSE;
775 }
776 if ((val = aedsp16_read(port)) == -1) {
777 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n"
778 , COMMAND_52);
779 return FALSE;
780 }
781 val &= 0x7F;
782 if (aedsp16_write(port, COMMAND_60)) {
783 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_60);
784 return FALSE;
785 }
786 if (aedsp16_write(port, val)) {
787 printk("[AEDSP16] Write val: failed!\n");
788 return FALSE;
789 }
790 }
791
792 return TRUE;
793}
794
795#endif /* CONFIG_SC6600 */
796
797static int __init aedsp16_cfg_write(int port) {
798 if (aedsp16_write(port, WRITE_MDIRQ_CFG)) {
799 printk("[AEDSP16] CMD 0x%x: failed!\n", WRITE_MDIRQ_CFG);
800 return FALSE;
801 }
802 if (aedsp16_write(port, soft_cfg)) {
803 printk("[AEDSP16] Initialization of (M)IRQ and DMA: failed!\n");
804 return FALSE;
805 }
806 return TRUE;
807}
808
809static int __init aedsp16_init_mss(int port)
810{
811 DBG(("aedsp16_init_mss:\n"));
812
813 mdelay(10);
814
815 if (aedsp16_write(port, DSP_INIT_MSS)) {
816 printk("[AEDSP16] aedsp16_init_mss [0x%x]: failed!\n",
817 DSP_INIT_MSS);
818 DBG(("failure.\n"));
819 return FALSE;
820 }
821
822 mdelay(10);
823
824 if (aedsp16_cfg_write(port) == FALSE)
825 return FALSE;
826
827 outb(soft_cfg_mss, ae_config.mss_base);
828
829 DBG(("success.\n"));
830
831 return TRUE;
832}
833
834static int __init aedsp16_setup_board(int port) {
835 int loop = RETRY;
836
837#if defined(CONFIG_SC6600)
838 int val = 0;
839
840 if (aedsp16_hard_read(port) == FALSE) {
841 printk("[AEDSP16] aedsp16_hard_read: failed!\n");
842 return FALSE;
843 }
844
845 if (aedsp16_write(port, COMMAND_52)) {
846 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_52);
847 return FALSE;
848 }
849
850 if ((val = aedsp16_read(port)) == -1) {
851 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
852 COMMAND_52);
853 return FALSE;
854 }
855#endif
856
857 do {
858 if (aedsp16_write(port, COMMAND_88)) {
859 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_88);
860 return FALSE;
861 }
862 mdelay(10);
863 } while ((aedsp16_wait_data(port) == FALSE) && loop--);
864
865 if (aedsp16_read(port) == -1) {
866 printk("[AEDSP16] aedsp16_read after CMD 0x%x: failed\n",
867 COMMAND_88);
868 return FALSE;
869 }
870
871#if !defined(CONFIG_SC6600)
872 if (aedsp16_write(port, COMMAND_5C)) {
873 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
874 return FALSE;
875 }
876#endif
877
878 if (aedsp16_cfg_write(port) == FALSE)
879 return FALSE;
880
881#if defined(CONFIG_SC6600)
882 if (aedsp16_write(port, COMMAND_60)) {
883 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_60);
884 return FALSE;
885 }
886 if (aedsp16_write(port, val)) {
887 printk("[AEDSP16] DATA 0x%x: failed!\n", val);
888 return FALSE;
889 }
890 if (aedsp16_write(port, COMMAND_6E)) {
891 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_6E);
892 return FALSE;
893 }
894 if (aedsp16_write(port, ver[0])) {
895 printk("[AEDSP16] DATA 0x%x: failed!\n", ver[0]);
896 return FALSE;
897 }
898 if (aedsp16_write(port, ver[1])) {
899 printk("[AEDSP16] DATA 0x%x: failed!\n", ver[1]);
900 return FALSE;
901 }
902
903 if (aedsp16_hard_write(port) == FALSE) {
904 printk("[AEDSP16] aedsp16_hard_write: failed!\n");
905 return FALSE;
906 }
907
908 if (aedsp16_write(port, COMMAND_5C)) {
909 printk("[AEDSP16] CMD 0x%x: failed!\n", COMMAND_5C);
910 return FALSE;
911 }
912
913#if defined(THIS_IS_A_THING_I_HAVE_NOT_TESTED_YET)
914 if (aedsp16_cfg_write(port) == FALSE)
915 return FALSE;
916#endif
917
918#endif
919
920 return TRUE;
921}
922
923static int __init aedsp16_stdcfg(int port) {
924 if (aedsp16_write(port, WRITE_MDIRQ_CFG)) {
925 printk("[AEDSP16] CMD 0x%x: failed!\n", WRITE_MDIRQ_CFG);
926 return FALSE;
927 }
928 /*
929 * 0x0A == (IRQ 7, DMA 1, MIRQ 0)
930 */
931 if (aedsp16_write(port, 0x0A)) {
932 printk("[AEDSP16] aedsp16_stdcfg: failed!\n");
933 return FALSE;
934 }
935 return TRUE;
936}
937
938static int __init aedsp16_dsp_version(int port)
939{
940 int len = 0;
941 int ret;
942
943 DBG(("Get DSP Version:\n"));
944
945 if (aedsp16_write(ae_config.base_io, GET_DSP_VERSION)) {
946 printk("[AEDSP16] CMD 0x%x: failed!\n", GET_DSP_VERSION);
947 DBG(("failed.\n"));
948 return FALSE;
949 }
950
951 do {
952 if ((ret = aedsp16_read(port)) == -1) {
953 DBG(("failed.\n"));
954 return FALSE;
955 }
956 /*
957 * We already know how many int are stored (2), so we know when the
958 * string is finished.
959 */
960 ver[len++] = ret;
961 } while (len < CARDVERDIGITS);
962 sprintf(DSPVersion, "%d.%d", ver[0], ver[1]);
963
964 DBG(("success.\n"));
965
966 return TRUE;
967}
968
969static int __init aedsp16_dsp_copyright(int port)
970{
971 int len = 0;
972 int ret;
973
974 DBG(("Get DSP Copyright:\n"));
975
976 if (aedsp16_write(ae_config.base_io, GET_DSP_COPYRIGHT)) {
977 printk("[AEDSP16] CMD 0x%x: failed!\n", GET_DSP_COPYRIGHT);
978 DBG(("failed.\n"));
979 return FALSE;
980 }
981
982 do {
983 if ((ret = aedsp16_read(port)) == -1) {
984 /*
985 * If no more data available, return to the caller, no error if len>0.
986 * We have no other way to know when the string is finished.
987 */
988 if (len)
989 break;
990 else {
991 DBG(("failed.\n"));
992 return FALSE;
993 }
994 }
995
996 DSPCopyright[len++] = ret;
997
998 } while (len < CARDNAMELEN);
999
1000 DBG(("success.\n"));
1001
1002 return TRUE;
1003}
1004
1005static void __init aedsp16_init_tables(void)
1006{
1007 int i = 0;
1008
1009 memset(DSPCopyright, 0, CARDNAMELEN + 1);
1010 memset(DSPVersion, 0, CARDVERLEN + 1);
1011
1012 for (i = 0; orIRQ[i].or; i++)
1013 if (orIRQ[i].val == ae_config.irq) {
1014 soft_cfg |= orIRQ[i].or;
1015 soft_cfg_mss |= orIRQ[i].or;
1016 }
1017
1018 for (i = 0; orMIRQ[i].or; i++)
1019 if (orMIRQ[i].or == ae_config.mpu_irq)
1020 soft_cfg |= orMIRQ[i].or;
1021
1022 for (i = 0; orDMA[i].or; i++)
1023 if (orDMA[i].val == ae_config.dma) {
1024 soft_cfg |= orDMA[i].or;
1025 soft_cfg_mss |= orDMA[i].or;
1026 }
1027}
1028
1029static int __init aedsp16_init_board(void)
1030{
1031 aedsp16_init_tables();
1032
1033 if (aedsp16_dsp_reset(ae_config.base_io) == FALSE) {
1034 printk("[AEDSP16] aedsp16_dsp_reset: failed!\n");
1035 return FALSE;
1036 }
1037 if (aedsp16_dsp_copyright(ae_config.base_io) == FALSE) {
1038 printk("[AEDSP16] aedsp16_dsp_copyright: failed!\n");
1039 return FALSE;
1040 }
1041
1042 /*
1043 * My AEDSP16 card return SC-6000 in DSPCopyright, so
1044 * if we have something different, we have to be warned.
1045 */
1046 if (strcmp("SC-6000", DSPCopyright))
1047 printk("[AEDSP16] Warning: non SC-6000 audio card!\n");
1048
1049 if (aedsp16_dsp_version(ae_config.base_io) == FALSE) {
1050 printk("[AEDSP16] aedsp16_dsp_version: failed!\n");
1051 return FALSE;
1052 }
1053
1054 if (aedsp16_stdcfg(ae_config.base_io) == FALSE) {
1055 printk("[AEDSP16] aedsp16_stdcfg: failed!\n");
1056 return FALSE;
1057 }
1058
1059#if defined(CONFIG_SC6600)
1060 if (aedsp16_hard_read(ae_config.base_io) == FALSE) {
1061 printk("[AEDSP16] aedsp16_hard_read: failed!\n");
1062 return FALSE;
1063 }
1064
1065 aedsp16_hard_decode();
1066
1067 aedsp16_hard_encode();
1068
1069 if (aedsp16_hard_write(ae_config.base_io) == FALSE) {
1070 printk("[AEDSP16] aedsp16_hard_write: failed!\n");
1071 return FALSE;
1072 }
1073
1074 if (aedsp16_ext_cfg_write(ae_config.base_io) == FALSE) {
1075 printk("[AEDSP16] aedsp16_ext_cfg_write: failed!\n");
1076 return FALSE;
1077 }
1078#endif /* CONFIG_SC6600 */
1079
1080 if (aedsp16_setup_board(ae_config.base_io) == FALSE) {
1081 printk("[AEDSP16] aedsp16_setup_board: failed!\n");
1082 return FALSE;
1083 }
1084
1085 if (ae_config.mss_base != -1) {
1086 if (ae_config.init & INIT_MSS) {
1087 if (aedsp16_init_mss(ae_config.base_io) == FALSE) {
1088 printk("[AEDSP16] Can not initialize"
1089 "Microsoft Sound System mode.\n");
1090 return FALSE;
1091 }
1092 }
1093 }
1094
1095#if !defined(MODULE) || defined(AEDSP16_INFO) || defined(AEDSP16_DEBUG)
1096
1097 printk("Audio Excel DSP 16 init v%s (%s %s) [",
1098 VERSION, DSPCopyright,
1099 DSPVersion);
1100
1101 if (ae_config.mpu_base != -1) {
1102 if (ae_config.init & INIT_MPU401) {
1103 printk("MPU401");
1104 if ((ae_config.init & INIT_MSS) ||
1105 (ae_config.init & INIT_SBPRO))
1106 printk(" ");
1107 }
1108 }
1109
1110 if (ae_config.mss_base == -1) {
1111 if (ae_config.init & INIT_SBPRO) {
1112 printk("SBPro");
1113 if (ae_config.init & INIT_MSS)
1114 printk(" ");
1115 }
1116 }
1117
1118 if (ae_config.mss_base != -1)
1119 if (ae_config.init & INIT_MSS)
1120 printk("MSS");
1121
1122 printk("]\n");
1123#endif /* MODULE || AEDSP16_INFO || AEDSP16_DEBUG */
1124
1125 mdelay(10);
1126
1127 return TRUE;
1128}
1129
1130static int __init init_aedsp16_sb(void)
1131{
1132 DBG(("init_aedsp16_sb: "));
1133
1134/*
1135 * If the card is already init'ed MSS, we can not init it to SBPRO too
1136 * because the board can not emulate simultaneously MSS and SBPRO.
1137 */
1138 if (ae_config.init & INIT_MSS)
1139 return FALSE;
1140 if (ae_config.init & INIT_SBPRO)
1141 return FALSE;
1142
1143 ae_config.init |= INIT_SBPRO;
1144
1145 DBG(("done.\n"));
1146
1147 return TRUE;
1148}
1149
1150static void uninit_aedsp16_sb(void)
1151{
1152 DBG(("uninit_aedsp16_sb: "));
1153
1154 ae_config.init &= ~INIT_SBPRO;
1155
1156 DBG(("done.\n"));
1157}
1158
1159static int __init init_aedsp16_mss(void)
1160{
1161 DBG(("init_aedsp16_mss: "));
1162
1163/*
1164 * If the card is already init'ed SBPRO, we can not init it to MSS too
1165 * because the board can not emulate simultaneously MSS and SBPRO.
1166 */
1167 if (ae_config.init & INIT_SBPRO)
1168 return FALSE;
1169 if (ae_config.init & INIT_MSS)
1170 return FALSE;
1171/*
1172 * We must allocate the CONFIG_AEDSP16_BASE region too because these are the
1173 * I/O ports to access card's control registers.
1174 */
1175 if (!(ae_config.init & INIT_MPU401)) {
1176 if (!request_region(ae_config.base_io, IOBASE_REGION_SIZE,
1177 "aedsp16 (base)")) {
1178 printk(
1179 "AEDSP16 BASE I/O port region is already in use.\n");
1180 return FALSE;
1181 }
1182 }
1183
1184 ae_config.init |= INIT_MSS;
1185
1186 DBG(("done.\n"));
1187
1188 return TRUE;
1189}
1190
1191static void uninit_aedsp16_mss(void)
1192{
1193 DBG(("uninit_aedsp16_mss: "));
1194
1195 if ((!(ae_config.init & INIT_MPU401)) &&
1196 (ae_config.init & INIT_MSS)) {
1197 release_region(ae_config.base_io, IOBASE_REGION_SIZE);
1198 DBG(("AEDSP16 base region released.\n"));
1199 }
1200
1201 ae_config.init &= ~INIT_MSS;
1202 DBG(("done.\n"));
1203}
1204
1205static int __init init_aedsp16_mpu(void)
1206{
1207 DBG(("init_aedsp16_mpu: "));
1208
1209 if (ae_config.init & INIT_MPU401)
1210 return FALSE;
1211
1212/*
1213 * We must request the CONFIG_AEDSP16_BASE region too because these are the I/O
1214 * ports to access card's control registers.
1215 */
1216 if (!(ae_config.init & (INIT_MSS | INIT_SBPRO))) {
1217 if (!request_region(ae_config.base_io, IOBASE_REGION_SIZE,
1218 "aedsp16 (base)")) {
1219 printk(
1220 "AEDSP16 BASE I/O port region is already in use.\n");
1221 return FALSE;
1222 }
1223 }
1224
1225 ae_config.init |= INIT_MPU401;
1226
1227 DBG(("done.\n"));
1228
1229 return TRUE;
1230}
1231
1232static void uninit_aedsp16_mpu(void)
1233{
1234 DBG(("uninit_aedsp16_mpu: "));
1235
1236 if ((!(ae_config.init & (INIT_MSS | INIT_SBPRO))) &&
1237 (ae_config.init & INIT_MPU401)) {
1238 release_region(ae_config.base_io, IOBASE_REGION_SIZE);
1239 DBG(("AEDSP16 base region released.\n"));
1240 }
1241
1242 ae_config.init &= ~INIT_MPU401;
1243
1244 DBG(("done.\n"));
1245}
1246
1247static int __init init_aedsp16(void)
1248{
1249 int initialized = FALSE;
1250
1251 DBG(("Initializing BASE[0x%x] IRQ[%d] DMA[%d] MIRQ[%d]\n",
1252 ae_config.base_io,ae_config.irq,ae_config.dma,ae_config.mpu_irq));
1253
1254 if (ae_config.mss_base == -1) {
1255 if (init_aedsp16_sb() == FALSE) {
1256 uninit_aedsp16_sb();
1257 } else {
1258 initialized = TRUE;
1259 }
1260 }
1261
1262 if (ae_config.mpu_base != -1) {
1263 if (init_aedsp16_mpu() == FALSE) {
1264 uninit_aedsp16_mpu();
1265 } else {
1266 initialized = TRUE;
1267 }
1268 }
1269
1270/*
1271 * In the sequence of init routines, the MSS init MUST be the last!
1272 * This because of the special register programming the MSS mode needs.
1273 * A board reset would disable the MSS mode restoring the default SBPRO
1274 * mode.
1275 */
1276 if (ae_config.mss_base != -1) {
1277 if (init_aedsp16_mss() == FALSE) {
1278 uninit_aedsp16_mss();
1279 } else {
1280 initialized = TRUE;
1281 }
1282 }
1283
1284 if (initialized)
1285 initialized = aedsp16_init_board();
1286 return initialized;
1287}
1288
1289static void __exit uninit_aedsp16(void)
1290{
1291 if (ae_config.mss_base != -1)
1292 uninit_aedsp16_mss();
1293 else
1294 uninit_aedsp16_sb();
1295 if (ae_config.mpu_base != -1)
1296 uninit_aedsp16_mpu();
1297}
1298
1299static int __initdata io = -1;
1300static int __initdata irq = -1;
1301static int __initdata dma = -1;
1302static int __initdata mpu_irq = -1;
1303static int __initdata mss_base = -1;
1304static int __initdata mpu_base = -1;
1305
1306module_param_hw(io, int, ioport, 0);
1307MODULE_PARM_DESC(io, "I/O base address (0x220 0x240)");
1308module_param_hw(irq, int, irq, 0);
1309MODULE_PARM_DESC(irq, "IRQ line (5 7 9 10 11)");
1310module_param_hw(dma, int, dma, 0);
1311MODULE_PARM_DESC(dma, "dma line (0 1 3)");
1312module_param_hw(mpu_irq, int, irq, 0);
1313MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ line (5 7 9 10 0)");
1314module_param_hw(mss_base, int, ioport, 0);
1315MODULE_PARM_DESC(mss_base, "MSS emulation I/O base address (0x530 0xE80)");
1316module_param_hw(mpu_base, int, ioport, 0);
1317MODULE_PARM_DESC(mpu_base,"MPU-401 I/O base address (0x300 0x310 0x320 0x330)");
1318MODULE_AUTHOR("Riccardo Facchetti <fizban@tin.it>");
1319MODULE_DESCRIPTION("Audio Excel DSP 16 Driver Version " VERSION);
1320MODULE_LICENSE("GPL");
1321
1322static int __init do_init_aedsp16(void) {
1323 printk("Audio Excel DSP 16 init driver Copyright (C) Riccardo Facchetti 1995-98\n");
1324 if (io == -1 || dma == -1 || irq == -1) {
1325 printk(KERN_INFO "aedsp16: I/O, IRQ and DMA are mandatory\n");
1326 return -EINVAL;
1327 }
1328
1329 ae_config.base_io = io;
1330 ae_config.irq = irq;
1331 ae_config.dma = dma;
1332
1333 ae_config.mss_base = mss_base;
1334 ae_config.mpu_base = mpu_base;
1335 ae_config.mpu_irq = mpu_irq;
1336
1337 if (init_aedsp16() == FALSE) {
1338 printk(KERN_ERR "aedsp16: initialization failed\n");
1339 /*
1340 * XXX
1341 * What error should we return here ?
1342 */
1343 return -EINVAL;
1344 }
1345 return 0;
1346}
1347
1348static void __exit cleanup_aedsp16(void) {
1349 uninit_aedsp16();
1350}
1351
1352module_init(do_init_aedsp16);
1353module_exit(cleanup_aedsp16);
1354
1355#ifndef MODULE
1356static int __init setup_aedsp16(char *str)
1357{
1358 /* io, irq, dma, mss_io, mpu_io, mpu_irq */
1359 int ints[7];
1360
1361 str = get_options(str, ARRAY_SIZE(ints), ints);
1362
1363 io = ints[1];
1364 irq = ints[2];
1365 dma = ints[3];
1366 mss_base = ints[4];
1367 mpu_base = ints[5];
1368 mpu_irq = ints[6];
1369 return 1;
1370}
1371
1372__setup("aedsp16=", setup_aedsp16);
1373#endif
diff --git a/sound/oss/audio.c b/sound/oss/audio.c
deleted file mode 100644
index 09c932f899b8..000000000000
--- a/sound/oss/audio.c
+++ /dev/null
@@ -1,985 +0,0 @@
1/*
2 * sound/oss/audio.c
3 *
4 * Device file manager for /dev/audio
5 */
6
7/*
8 * Copyright (C) by Hannu Savolainen 1993-1997
9 *
10 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
11 * Version 2 (June 1991). See the "COPYING" file distributed with this software
12 * for more info.
13 */
14/*
15 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
16 * Thomas Sailer : moved several static variables into struct audio_operations
17 * (which is grossly misnamed btw.) because they have the same
18 * lifetime as the rest in there and dynamic allocation saves
19 * 12k or so
20 * Thomas Sailer : use more logical O_NONBLOCK semantics
21 * Daniel Rodriksson: reworked the use of the device specific copy_user
22 * still generic
23 * Horst von Brand: Add missing #include <linux/string.h>
24 * Chris Rankin : Update the module-usage counter for the coprocessor,
25 * and decrement the counters again if we cannot open
26 * the audio device.
27 */
28
29#include <linux/stddef.h>
30#include <linux/string.h>
31#include <linux/kmod.h>
32
33#include "sound_config.h"
34#include "ulaw.h"
35#include "coproc.h"
36
37#define NEUTRAL8 0x80
38#define NEUTRAL16 0x00
39
40
41static int dma_ioctl(int dev, unsigned int cmd, void __user *arg);
42
43static int set_format(int dev, int fmt)
44{
45 if (fmt != AFMT_QUERY)
46 {
47 audio_devs[dev]->local_conversion = 0;
48
49 if (!(audio_devs[dev]->format_mask & fmt)) /* Not supported */
50 {
51 if (fmt == AFMT_MU_LAW)
52 {
53 fmt = AFMT_U8;
54 audio_devs[dev]->local_conversion = CNV_MU_LAW;
55 }
56 else
57 fmt = AFMT_U8; /* This is always supported */
58 }
59 audio_devs[dev]->audio_format = audio_devs[dev]->d->set_bits(dev, fmt);
60 audio_devs[dev]->local_format = fmt;
61 }
62 else
63 return audio_devs[dev]->local_format;
64
65 if (audio_devs[dev]->local_conversion)
66 return audio_devs[dev]->local_conversion;
67 else
68 return audio_devs[dev]->local_format;
69}
70
71int audio_open(int dev, struct file *file)
72{
73 int ret;
74 int bits;
75 int dev_type = dev & 0x0f;
76 int mode = translate_mode(file);
77 const struct audio_driver *driver;
78 const struct coproc_operations *coprocessor;
79
80 dev = dev >> 4;
81
82 if (dev_type == SND_DEV_DSP16)
83 bits = 16;
84 else
85 bits = 8;
86
87 if (dev < 0 || dev >= num_audiodevs)
88 return -ENXIO;
89
90 driver = audio_devs[dev]->d;
91
92 if (!try_module_get(driver->owner))
93 return -ENODEV;
94
95 if ((ret = DMAbuf_open(dev, mode)) < 0)
96 goto error_1;
97
98 if ( (coprocessor = audio_devs[dev]->coproc) != NULL ) {
99 if (!try_module_get(coprocessor->owner))
100 goto error_2;
101
102 if ((ret = coprocessor->open(coprocessor->devc, COPR_PCM)) < 0) {
103 printk(KERN_WARNING "Sound: Can't access coprocessor device\n");
104 goto error_3;
105 }
106 }
107
108 audio_devs[dev]->local_conversion = 0;
109
110 if (dev_type == SND_DEV_AUDIO)
111 set_format(dev, AFMT_MU_LAW);
112 else
113 set_format(dev, bits);
114
115 audio_devs[dev]->audio_mode = AM_NONE;
116
117 return 0;
118
119 /*
120 * Clean-up stack: this is what needs (un)doing if
121 * we can't open the audio device ...
122 */
123 error_3:
124 module_put(coprocessor->owner);
125
126 error_2:
127 DMAbuf_release(dev, mode);
128
129 error_1:
130 module_put(driver->owner);
131
132 return ret;
133}
134
135static void sync_output(int dev)
136{
137 int p, i;
138 int l;
139 struct dma_buffparms *dmap = audio_devs[dev]->dmap_out;
140
141 if (dmap->fragment_size <= 0)
142 return;
143 dmap->flags |= DMA_POST;
144
145 /* Align the write pointer with fragment boundaries */
146
147 if ((l = dmap->user_counter % dmap->fragment_size) > 0)
148 {
149 int len;
150 unsigned long offs = dmap->user_counter % dmap->bytes_in_use;
151
152 len = dmap->fragment_size - l;
153 memset(dmap->raw_buf + offs, dmap->neutral_byte, len);
154 DMAbuf_move_wrpointer(dev, len);
155 }
156
157 /*
158 * Clean all unused buffer fragments.
159 */
160
161 p = dmap->qtail;
162 dmap->flags |= DMA_POST;
163
164 for (i = dmap->qlen + 1; i < dmap->nbufs; i++)
165 {
166 p = (p + 1) % dmap->nbufs;
167 if (((dmap->raw_buf + p * dmap->fragment_size) + dmap->fragment_size) >
168 (dmap->raw_buf + dmap->buffsize))
169 printk(KERN_ERR "audio: Buffer error 2\n");
170
171 memset(dmap->raw_buf + p * dmap->fragment_size,
172 dmap->neutral_byte,
173 dmap->fragment_size);
174 }
175
176 dmap->flags |= DMA_DIRTY;
177}
178
179void audio_release(int dev, struct file *file)
180{
181 const struct coproc_operations *coprocessor;
182 int mode = translate_mode(file);
183
184 dev = dev >> 4;
185
186 /*
187 * We do this in DMAbuf_release(). Why are we doing it
188 * here? Why don't we test the file mode before setting
189 * both flags? DMAbuf_release() does.
190 * ...pester...pester...pester...
191 */
192 audio_devs[dev]->dmap_out->closing = 1;
193 audio_devs[dev]->dmap_in->closing = 1;
194
195 /*
196 * We need to make sure we allocated the dmap_out buffer
197 * before we go mucking around with it in sync_output().
198 */
199 if (mode & OPEN_WRITE)
200 sync_output(dev);
201
202 if ( (coprocessor = audio_devs[dev]->coproc) != NULL ) {
203 coprocessor->close(coprocessor->devc, COPR_PCM);
204 module_put(coprocessor->owner);
205 }
206 DMAbuf_release(dev, mode);
207
208 module_put(audio_devs[dev]->d->owner);
209}
210
211static void translate_bytes(const unsigned char *table, unsigned char *buff, int n)
212{
213 unsigned long i;
214
215 if (n <= 0)
216 return;
217
218 for (i = 0; i < n; ++i)
219 buff[i] = table[buff[i]];
220}
221
222int audio_write(int dev, struct file *file, const char __user *buf, int count)
223{
224 int c, p, l, buf_size, used, returned;
225 int err;
226 char *dma_buf;
227
228 dev = dev >> 4;
229
230 p = 0;
231 c = count;
232
233 if(count < 0)
234 return -EINVAL;
235
236 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
237 return -EPERM;
238
239 if (audio_devs[dev]->flags & DMA_DUPLEX)
240 audio_devs[dev]->audio_mode |= AM_WRITE;
241 else
242 audio_devs[dev]->audio_mode = AM_WRITE;
243
244 if (!count) /* Flush output */
245 {
246 sync_output(dev);
247 return 0;
248 }
249
250 while (c)
251 {
252 if ((err = DMAbuf_getwrbuffer(dev, &dma_buf, &buf_size, !!(file->f_flags & O_NONBLOCK))) < 0)
253 {
254 /* Handle nonblocking mode */
255 if ((file->f_flags & O_NONBLOCK) && err == -EAGAIN)
256 return p? p : -EAGAIN; /* No more space. Return # of accepted bytes */
257 return err;
258 }
259 l = c;
260
261 if (l > buf_size)
262 l = buf_size;
263
264 returned = l;
265 used = l;
266 if (!audio_devs[dev]->d->copy_user)
267 {
268 if ((dma_buf + l) >
269 (audio_devs[dev]->dmap_out->raw_buf + audio_devs[dev]->dmap_out->buffsize))
270 {
271 printk(KERN_ERR "audio: Buffer error 3 (%lx,%d), (%lx, %d)\n", (long) dma_buf, l, (long) audio_devs[dev]->dmap_out->raw_buf, (int) audio_devs[dev]->dmap_out->buffsize);
272 return -EDOM;
273 }
274 if (dma_buf < audio_devs[dev]->dmap_out->raw_buf)
275 {
276 printk(KERN_ERR "audio: Buffer error 13 (%lx<%lx)\n", (long) dma_buf, (long) audio_devs[dev]->dmap_out->raw_buf);
277 return -EDOM;
278 }
279 if(copy_from_user(dma_buf, &(buf)[p], l))
280 return -EFAULT;
281 }
282 else audio_devs[dev]->d->copy_user (dev,
283 dma_buf, 0,
284 buf, p,
285 c, buf_size,
286 &used, &returned,
287 l);
288 l = returned;
289
290 if (audio_devs[dev]->local_conversion & CNV_MU_LAW)
291 {
292 translate_bytes(ulaw_dsp, (unsigned char *) dma_buf, l);
293 }
294 c -= used;
295 p += used;
296 DMAbuf_move_wrpointer(dev, l);
297
298 }
299
300 return count;
301}
302
303int audio_read(int dev, struct file *file, char __user *buf, int count)
304{
305 int c, p, l;
306 char *dmabuf;
307 int buf_no;
308
309 dev = dev >> 4;
310 p = 0;
311 c = count;
312
313 if (!(audio_devs[dev]->open_mode & OPEN_READ))
314 return -EPERM;
315
316 if ((audio_devs[dev]->audio_mode & AM_WRITE) && !(audio_devs[dev]->flags & DMA_DUPLEX))
317 sync_output(dev);
318
319 if (audio_devs[dev]->flags & DMA_DUPLEX)
320 audio_devs[dev]->audio_mode |= AM_READ;
321 else
322 audio_devs[dev]->audio_mode = AM_READ;
323
324 while(c)
325 {
326 if ((buf_no = DMAbuf_getrdbuffer(dev, &dmabuf, &l, !!(file->f_flags & O_NONBLOCK))) < 0)
327 {
328 /*
329 * Nonblocking mode handling. Return current # of bytes
330 */
331
332 if (p > 0) /* Avoid throwing away data */
333 return p; /* Return it instead */
334
335 if ((file->f_flags & O_NONBLOCK) && buf_no == -EAGAIN)
336 return -EAGAIN;
337
338 return buf_no;
339 }
340 if (l > c)
341 l = c;
342
343 /*
344 * Insert any local processing here.
345 */
346
347 if (audio_devs[dev]->local_conversion & CNV_MU_LAW)
348 {
349 translate_bytes(dsp_ulaw, (unsigned char *) dmabuf, l);
350 }
351
352 {
353 char *fixit = dmabuf;
354
355 if(copy_to_user(&(buf)[p], fixit, l))
356 return -EFAULT;
357 }
358
359 DMAbuf_rmchars(dev, buf_no, l);
360
361 p += l;
362 c -= l;
363 }
364
365 return count - c;
366}
367
368int audio_ioctl(int dev, struct file *file, unsigned int cmd, void __user *arg)
369{
370 int val, count;
371 unsigned long flags;
372 struct dma_buffparms *dmap;
373 int __user *p = arg;
374
375 dev = dev >> 4;
376
377 if (_IOC_TYPE(cmd) == 'C') {
378 if (audio_devs[dev]->coproc) /* Coprocessor ioctl */
379 return audio_devs[dev]->coproc->ioctl(audio_devs[dev]->coproc->devc, cmd, arg, 0);
380 /* else
381 printk(KERN_DEBUG"/dev/dsp%d: No coprocessor for this device\n", dev); */
382 return -ENXIO;
383 }
384 else switch (cmd)
385 {
386 case SNDCTL_DSP_SYNC:
387 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
388 return 0;
389 if (audio_devs[dev]->dmap_out->fragment_size == 0)
390 return 0;
391 sync_output(dev);
392 DMAbuf_sync(dev);
393 DMAbuf_reset(dev);
394 return 0;
395
396 case SNDCTL_DSP_POST:
397 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
398 return 0;
399 if (audio_devs[dev]->dmap_out->fragment_size == 0)
400 return 0;
401 audio_devs[dev]->dmap_out->flags |= DMA_POST | DMA_DIRTY;
402 sync_output(dev);
403 dma_ioctl(dev, SNDCTL_DSP_POST, NULL);
404 return 0;
405
406 case SNDCTL_DSP_RESET:
407 audio_devs[dev]->audio_mode = AM_NONE;
408 DMAbuf_reset(dev);
409 return 0;
410
411 case SNDCTL_DSP_GETFMTS:
412 val = audio_devs[dev]->format_mask | AFMT_MU_LAW;
413 break;
414
415 case SNDCTL_DSP_SETFMT:
416 if (get_user(val, p))
417 return -EFAULT;
418 val = set_format(dev, val);
419 break;
420
421 case SNDCTL_DSP_GETISPACE:
422 if (!(audio_devs[dev]->open_mode & OPEN_READ))
423 return 0;
424 if ((audio_devs[dev]->audio_mode & AM_WRITE) && !(audio_devs[dev]->flags & DMA_DUPLEX))
425 return -EBUSY;
426 return dma_ioctl(dev, cmd, arg);
427
428 case SNDCTL_DSP_GETOSPACE:
429 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
430 return -EPERM;
431 if ((audio_devs[dev]->audio_mode & AM_READ) && !(audio_devs[dev]->flags & DMA_DUPLEX))
432 return -EBUSY;
433 return dma_ioctl(dev, cmd, arg);
434
435 case SNDCTL_DSP_NONBLOCK:
436 spin_lock(&file->f_lock);
437 file->f_flags |= O_NONBLOCK;
438 spin_unlock(&file->f_lock);
439 return 0;
440
441 case SNDCTL_DSP_GETCAPS:
442 val = 1 | DSP_CAP_MMAP; /* Revision level of this ioctl() */
443 if (audio_devs[dev]->flags & DMA_DUPLEX &&
444 audio_devs[dev]->open_mode == OPEN_READWRITE)
445 val |= DSP_CAP_DUPLEX;
446 if (audio_devs[dev]->coproc)
447 val |= DSP_CAP_COPROC;
448 if (audio_devs[dev]->d->local_qlen) /* Device has hidden buffers */
449 val |= DSP_CAP_BATCH;
450 if (audio_devs[dev]->d->trigger) /* Supports SETTRIGGER */
451 val |= DSP_CAP_TRIGGER;
452 break;
453
454 case SOUND_PCM_WRITE_RATE:
455 if (get_user(val, p))
456 return -EFAULT;
457 val = audio_devs[dev]->d->set_speed(dev, val);
458 break;
459
460 case SOUND_PCM_READ_RATE:
461 val = audio_devs[dev]->d->set_speed(dev, 0);
462 break;
463
464 case SNDCTL_DSP_STEREO:
465 if (get_user(val, p))
466 return -EFAULT;
467 if (val > 1 || val < 0)
468 return -EINVAL;
469 val = audio_devs[dev]->d->set_channels(dev, val + 1) - 1;
470 break;
471
472 case SOUND_PCM_WRITE_CHANNELS:
473 if (get_user(val, p))
474 return -EFAULT;
475 val = audio_devs[dev]->d->set_channels(dev, val);
476 break;
477
478 case SOUND_PCM_READ_CHANNELS:
479 val = audio_devs[dev]->d->set_channels(dev, 0);
480 break;
481
482 case SOUND_PCM_READ_BITS:
483 val = audio_devs[dev]->d->set_bits(dev, 0);
484 break;
485
486 case SNDCTL_DSP_SETDUPLEX:
487 if (audio_devs[dev]->open_mode != OPEN_READWRITE)
488 return -EPERM;
489 return (audio_devs[dev]->flags & DMA_DUPLEX) ? 0 : -EIO;
490
491 case SNDCTL_DSP_PROFILE:
492 if (get_user(val, p))
493 return -EFAULT;
494 if (audio_devs[dev]->open_mode & OPEN_WRITE)
495 audio_devs[dev]->dmap_out->applic_profile = val;
496 if (audio_devs[dev]->open_mode & OPEN_READ)
497 audio_devs[dev]->dmap_in->applic_profile = val;
498 return 0;
499
500 case SNDCTL_DSP_GETODELAY:
501 dmap = audio_devs[dev]->dmap_out;
502 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
503 return -EINVAL;
504 if (!(dmap->flags & DMA_ALLOC_DONE))
505 {
506 val=0;
507 break;
508 }
509
510 spin_lock_irqsave(&dmap->lock,flags);
511 /* Compute number of bytes that have been played */
512 count = DMAbuf_get_buffer_pointer (dev, dmap, DMODE_OUTPUT);
513 if (count < dmap->fragment_size && dmap->qhead != 0)
514 count += dmap->bytes_in_use; /* Pointer wrap not handled yet */
515 count += dmap->byte_counter;
516
517 /* Subtract current count from the number of bytes written by app */
518 count = dmap->user_counter - count;
519 if (count < 0)
520 count = 0;
521 spin_unlock_irqrestore(&dmap->lock,flags);
522 val = count;
523 break;
524
525 default:
526 return dma_ioctl(dev, cmd, arg);
527 }
528 return put_user(val, p);
529}
530
531void audio_init_devices(void)
532{
533 /*
534 * NOTE! This routine could be called several times during boot.
535 */
536}
537
538void reorganize_buffers(int dev, struct dma_buffparms *dmap, int recording)
539{
540 /*
541 * This routine breaks the physical device buffers to logical ones.
542 */
543
544 struct audio_operations *dsp_dev = audio_devs[dev];
545
546 unsigned i, n;
547 unsigned sr, nc, sz, bsz;
548
549 sr = dsp_dev->d->set_speed(dev, 0);
550 nc = dsp_dev->d->set_channels(dev, 0);
551 sz = dsp_dev->d->set_bits(dev, 0);
552
553 if (sz == 8)
554 dmap->neutral_byte = NEUTRAL8;
555 else
556 dmap->neutral_byte = NEUTRAL16;
557
558 if (sr < 1 || nc < 1 || sz < 1)
559 {
560/* printk(KERN_DEBUG "Warning: Invalid PCM parameters[%d] sr=%d, nc=%d, sz=%d\n", dev, sr, nc, sz);*/
561 sr = DSP_DEFAULT_SPEED;
562 nc = 1;
563 sz = 8;
564 }
565
566 sz = sr * nc * sz;
567
568 sz /= 8; /* #bits -> #bytes */
569 dmap->data_rate = sz;
570
571 if (!dmap->needs_reorg)
572 return;
573 dmap->needs_reorg = 0;
574
575 if (dmap->fragment_size == 0)
576 {
577 /* Compute the fragment size using the default algorithm */
578
579 /*
580 * Compute a buffer size for time not exceeding 1 second.
581 * Usually this algorithm gives a buffer size for 0.5 to 1.0 seconds
582 * of sound (using the current speed, sample size and #channels).
583 */
584
585 bsz = dmap->buffsize;
586 while (bsz > sz)
587 bsz /= 2;
588
589 if (bsz == dmap->buffsize)
590 bsz /= 2; /* Needs at least 2 buffers */
591
592 /*
593 * Split the computed fragment to smaller parts. After 3.5a9
594 * the default subdivision is 4 which should give better
595 * results when recording.
596 */
597
598 if (dmap->subdivision == 0) /* Not already set */
599 {
600 dmap->subdivision = 4; /* Init to the default value */
601
602 if ((bsz / dmap->subdivision) > 4096)
603 dmap->subdivision *= 2;
604 if ((bsz / dmap->subdivision) < 4096)
605 dmap->subdivision = 1;
606 }
607 bsz /= dmap->subdivision;
608
609 if (bsz < 16)
610 bsz = 16; /* Just a sanity check */
611
612 dmap->fragment_size = bsz;
613 }
614 else
615 {
616 /*
617 * The process has specified the buffer size with SNDCTL_DSP_SETFRAGMENT or
618 * the buffer size computation has already been done.
619 */
620 if (dmap->fragment_size > (dmap->buffsize / 2))
621 dmap->fragment_size = (dmap->buffsize / 2);
622 bsz = dmap->fragment_size;
623 }
624
625 if (audio_devs[dev]->min_fragment)
626 if (bsz < (1 << audio_devs[dev]->min_fragment))
627 bsz = 1 << audio_devs[dev]->min_fragment;
628 if (audio_devs[dev]->max_fragment)
629 if (bsz > (1 << audio_devs[dev]->max_fragment))
630 bsz = 1 << audio_devs[dev]->max_fragment;
631 bsz &= ~0x07; /* Force size which is multiple of 8 bytes */
632#ifdef OS_DMA_ALIGN_CHECK
633 OS_DMA_ALIGN_CHECK(bsz);
634#endif
635
636 n = dmap->buffsize / bsz;
637 if (n > MAX_SUB_BUFFERS)
638 n = MAX_SUB_BUFFERS;
639 if (n > dmap->max_fragments)
640 n = dmap->max_fragments;
641
642 if (n < 2)
643 {
644 n = 2;
645 bsz /= 2;
646 }
647 dmap->nbufs = n;
648 dmap->bytes_in_use = n * bsz;
649 dmap->fragment_size = bsz;
650 dmap->max_byte_counter = (dmap->data_rate * 60 * 60) +
651 dmap->bytes_in_use; /* Approximately one hour */
652
653 if (dmap->raw_buf)
654 {
655 memset(dmap->raw_buf, dmap->neutral_byte, dmap->bytes_in_use);
656 }
657
658 for (i = 0; i < dmap->nbufs; i++)
659 {
660 dmap->counts[i] = 0;
661 }
662
663 dmap->flags |= DMA_ALLOC_DONE | DMA_EMPTY;
664}
665
666static int dma_subdivide(int dev, struct dma_buffparms *dmap, int fact)
667{
668 if (fact == 0)
669 {
670 fact = dmap->subdivision;
671 if (fact == 0)
672 fact = 1;
673 return fact;
674 }
675 if (dmap->subdivision != 0 || dmap->fragment_size) /* Too late to change */
676 return -EINVAL;
677
678 if (fact > MAX_REALTIME_FACTOR)
679 return -EINVAL;
680
681 if (fact != 1 && fact != 2 && fact != 4 && fact != 8 && fact != 16)
682 return -EINVAL;
683
684 dmap->subdivision = fact;
685 return fact;
686}
687
688static int dma_set_fragment(int dev, struct dma_buffparms *dmap, int fact)
689{
690 int bytes, count;
691
692 if (fact == 0)
693 return -EIO;
694
695 if (dmap->subdivision != 0 ||
696 dmap->fragment_size) /* Too late to change */
697 return -EINVAL;
698
699 bytes = fact & 0xffff;
700 count = (fact >> 16) & 0x7fff;
701
702 if (count == 0)
703 count = MAX_SUB_BUFFERS;
704 else if (count < MAX_SUB_BUFFERS)
705 count++;
706
707 if (bytes < 4 || bytes > 17) /* <16 || > 512k */
708 return -EINVAL;
709
710 if (count < 2)
711 return -EINVAL;
712
713 if (audio_devs[dev]->min_fragment > 0)
714 if (bytes < audio_devs[dev]->min_fragment)
715 bytes = audio_devs[dev]->min_fragment;
716
717 if (audio_devs[dev]->max_fragment > 0)
718 if (bytes > audio_devs[dev]->max_fragment)
719 bytes = audio_devs[dev]->max_fragment;
720
721#ifdef OS_DMA_MINBITS
722 if (bytes < OS_DMA_MINBITS)
723 bytes = OS_DMA_MINBITS;
724#endif
725
726 dmap->fragment_size = (1 << bytes);
727 dmap->max_fragments = count;
728
729 if (dmap->fragment_size > dmap->buffsize)
730 dmap->fragment_size = dmap->buffsize;
731
732 if (dmap->fragment_size == dmap->buffsize &&
733 audio_devs[dev]->flags & DMA_AUTOMODE)
734 dmap->fragment_size /= 2; /* Needs at least 2 buffers */
735
736 dmap->subdivision = 1; /* Disable SNDCTL_DSP_SUBDIVIDE */
737 return bytes | ((count - 1) << 16);
738}
739
740static int dma_ioctl(int dev, unsigned int cmd, void __user *arg)
741{
742 struct dma_buffparms *dmap_out = audio_devs[dev]->dmap_out;
743 struct dma_buffparms *dmap_in = audio_devs[dev]->dmap_in;
744 struct dma_buffparms *dmap;
745 audio_buf_info info;
746 count_info cinfo;
747 int fact, ret, changed, bits, count, err;
748 unsigned long flags;
749
750 switch (cmd)
751 {
752 case SNDCTL_DSP_SUBDIVIDE:
753 ret = 0;
754 if (get_user(fact, (int __user *)arg))
755 return -EFAULT;
756 if (audio_devs[dev]->open_mode & OPEN_WRITE)
757 ret = dma_subdivide(dev, dmap_out, fact);
758 if (ret < 0)
759 return ret;
760 if (audio_devs[dev]->open_mode != OPEN_WRITE ||
761 (audio_devs[dev]->flags & DMA_DUPLEX &&
762 audio_devs[dev]->open_mode & OPEN_READ))
763 ret = dma_subdivide(dev, dmap_in, fact);
764 if (ret < 0)
765 return ret;
766 break;
767
768 case SNDCTL_DSP_GETISPACE:
769 case SNDCTL_DSP_GETOSPACE:
770 dmap = dmap_out;
771 if (cmd == SNDCTL_DSP_GETISPACE && !(audio_devs[dev]->open_mode & OPEN_READ))
772 return -EINVAL;
773 if (cmd == SNDCTL_DSP_GETOSPACE && !(audio_devs[dev]->open_mode & OPEN_WRITE))
774 return -EINVAL;
775 if (cmd == SNDCTL_DSP_GETISPACE && audio_devs[dev]->flags & DMA_DUPLEX)
776 dmap = dmap_in;
777 if (dmap->mapping_flags & DMA_MAP_MAPPED)
778 return -EINVAL;
779 if (!(dmap->flags & DMA_ALLOC_DONE))
780 reorganize_buffers(dev, dmap, (cmd == SNDCTL_DSP_GETISPACE));
781 info.fragstotal = dmap->nbufs;
782 if (cmd == SNDCTL_DSP_GETISPACE)
783 info.fragments = dmap->qlen;
784 else
785 {
786 if (!DMAbuf_space_in_queue(dev))
787 info.fragments = 0;
788 else
789 {
790 info.fragments = DMAbuf_space_in_queue(dev);
791 if (audio_devs[dev]->d->local_qlen)
792 {
793 int tmp = audio_devs[dev]->d->local_qlen(dev);
794 if (tmp && info.fragments)
795 tmp--; /*
796 * This buffer has been counted twice
797 */
798 info.fragments -= tmp;
799 }
800 }
801 }
802 if (info.fragments < 0)
803 info.fragments = 0;
804 else if (info.fragments > dmap->nbufs)
805 info.fragments = dmap->nbufs;
806
807 info.fragsize = dmap->fragment_size;
808 info.bytes = info.fragments * dmap->fragment_size;
809
810 if (cmd == SNDCTL_DSP_GETISPACE && dmap->qlen)
811 info.bytes -= dmap->counts[dmap->qhead];
812 else
813 {
814 info.fragments = info.bytes / dmap->fragment_size;
815 info.bytes -= dmap->user_counter % dmap->fragment_size;
816 }
817 if (copy_to_user(arg, &info, sizeof(info)))
818 return -EFAULT;
819 return 0;
820
821 case SNDCTL_DSP_SETTRIGGER:
822 if (get_user(bits, (int __user *)arg))
823 return -EFAULT;
824 bits &= audio_devs[dev]->open_mode;
825 if (audio_devs[dev]->d->trigger == NULL)
826 return -EINVAL;
827 if (!(audio_devs[dev]->flags & DMA_DUPLEX) && (bits & PCM_ENABLE_INPUT) &&
828 (bits & PCM_ENABLE_OUTPUT))
829 return -EINVAL;
830
831 if (bits & PCM_ENABLE_INPUT)
832 {
833 spin_lock_irqsave(&dmap_in->lock,flags);
834 changed = (audio_devs[dev]->enable_bits ^ bits) & PCM_ENABLE_INPUT;
835 if (changed && audio_devs[dev]->go)
836 {
837 reorganize_buffers(dev, dmap_in, 1);
838 if ((err = audio_devs[dev]->d->prepare_for_input(dev,
839 dmap_in->fragment_size, dmap_in->nbufs)) < 0) {
840 spin_unlock_irqrestore(&dmap_in->lock,flags);
841 return err;
842 }
843 dmap_in->dma_mode = DMODE_INPUT;
844 audio_devs[dev]->enable_bits |= PCM_ENABLE_INPUT;
845 DMAbuf_activate_recording(dev, dmap_in);
846 } else
847 audio_devs[dev]->enable_bits &= ~PCM_ENABLE_INPUT;
848 spin_unlock_irqrestore(&dmap_in->lock,flags);
849 }
850 if (bits & PCM_ENABLE_OUTPUT)
851 {
852 spin_lock_irqsave(&dmap_out->lock,flags);
853 changed = (audio_devs[dev]->enable_bits ^ bits) & PCM_ENABLE_OUTPUT;
854 if (changed &&
855 (dmap_out->mapping_flags & DMA_MAP_MAPPED || dmap_out->qlen > 0) &&
856 audio_devs[dev]->go)
857 {
858 if (!(dmap_out->flags & DMA_ALLOC_DONE))
859 reorganize_buffers(dev, dmap_out, 0);
860 dmap_out->dma_mode = DMODE_OUTPUT;
861 audio_devs[dev]->enable_bits |= PCM_ENABLE_OUTPUT;
862 dmap_out->counts[dmap_out->qhead] = dmap_out->fragment_size;
863 DMAbuf_launch_output(dev, dmap_out);
864 } else
865 audio_devs[dev]->enable_bits &= ~PCM_ENABLE_OUTPUT;
866 spin_unlock_irqrestore(&dmap_out->lock,flags);
867 }
868#if 0
869 if (changed && audio_devs[dev]->d->trigger)
870 audio_devs[dev]->d->trigger(dev, bits * audio_devs[dev]->go);
871#endif
872 /* Falls through... */
873
874 case SNDCTL_DSP_GETTRIGGER:
875 ret = audio_devs[dev]->enable_bits;
876 break;
877
878 case SNDCTL_DSP_SETSYNCRO:
879 if (!audio_devs[dev]->d->trigger)
880 return -EINVAL;
881 audio_devs[dev]->d->trigger(dev, 0);
882 audio_devs[dev]->go = 0;
883 return 0;
884
885 case SNDCTL_DSP_GETIPTR:
886 if (!(audio_devs[dev]->open_mode & OPEN_READ))
887 return -EINVAL;
888 spin_lock_irqsave(&dmap_in->lock,flags);
889 cinfo.bytes = dmap_in->byte_counter;
890 cinfo.ptr = DMAbuf_get_buffer_pointer(dev, dmap_in, DMODE_INPUT) & ~3;
891 if (cinfo.ptr < dmap_in->fragment_size && dmap_in->qtail != 0)
892 cinfo.bytes += dmap_in->bytes_in_use; /* Pointer wrap not handled yet */
893 cinfo.blocks = dmap_in->qlen;
894 cinfo.bytes += cinfo.ptr;
895 if (dmap_in->mapping_flags & DMA_MAP_MAPPED)
896 dmap_in->qlen = 0; /* Reset interrupt counter */
897 spin_unlock_irqrestore(&dmap_in->lock,flags);
898 if (copy_to_user(arg, &cinfo, sizeof(cinfo)))
899 return -EFAULT;
900 return 0;
901
902 case SNDCTL_DSP_GETOPTR:
903 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
904 return -EINVAL;
905
906 spin_lock_irqsave(&dmap_out->lock,flags);
907 cinfo.bytes = dmap_out->byte_counter;
908 cinfo.ptr = DMAbuf_get_buffer_pointer(dev, dmap_out, DMODE_OUTPUT) & ~3;
909 if (cinfo.ptr < dmap_out->fragment_size && dmap_out->qhead != 0)
910 cinfo.bytes += dmap_out->bytes_in_use; /* Pointer wrap not handled yet */
911 cinfo.blocks = dmap_out->qlen;
912 cinfo.bytes += cinfo.ptr;
913 if (dmap_out->mapping_flags & DMA_MAP_MAPPED)
914 dmap_out->qlen = 0; /* Reset interrupt counter */
915 spin_unlock_irqrestore(&dmap_out->lock,flags);
916 if (copy_to_user(arg, &cinfo, sizeof(cinfo)))
917 return -EFAULT;
918 return 0;
919
920 case SNDCTL_DSP_GETODELAY:
921 if (!(audio_devs[dev]->open_mode & OPEN_WRITE))
922 return -EINVAL;
923 if (!(dmap_out->flags & DMA_ALLOC_DONE))
924 {
925 ret=0;
926 break;
927 }
928 spin_lock_irqsave(&dmap_out->lock,flags);
929 /* Compute number of bytes that have been played */
930 count = DMAbuf_get_buffer_pointer (dev, dmap_out, DMODE_OUTPUT);
931 if (count < dmap_out->fragment_size && dmap_out->qhead != 0)
932 count += dmap_out->bytes_in_use; /* Pointer wrap not handled yet */
933 count += dmap_out->byte_counter;
934 /* Subtract current count from the number of bytes written by app */
935 count = dmap_out->user_counter - count;
936 if (count < 0)
937 count = 0;
938 spin_unlock_irqrestore(&dmap_out->lock,flags);
939 ret = count;
940 break;
941
942 case SNDCTL_DSP_POST:
943 if (audio_devs[dev]->dmap_out->qlen > 0)
944 if (!(audio_devs[dev]->dmap_out->flags & DMA_ACTIVE))
945 DMAbuf_launch_output(dev, audio_devs[dev]->dmap_out);
946 return 0;
947
948 case SNDCTL_DSP_GETBLKSIZE:
949 dmap = dmap_out;
950 if (audio_devs[dev]->open_mode & OPEN_WRITE)
951 reorganize_buffers(dev, dmap_out, (audio_devs[dev]->open_mode == OPEN_READ));
952 if (audio_devs[dev]->open_mode == OPEN_READ ||
953 (audio_devs[dev]->flags & DMA_DUPLEX &&
954 audio_devs[dev]->open_mode & OPEN_READ))
955 reorganize_buffers(dev, dmap_in, (audio_devs[dev]->open_mode == OPEN_READ));
956 if (audio_devs[dev]->open_mode == OPEN_READ)
957 dmap = dmap_in;
958 ret = dmap->fragment_size;
959 break;
960
961 case SNDCTL_DSP_SETFRAGMENT:
962 ret = 0;
963 if (get_user(fact, (int __user *)arg))
964 return -EFAULT;
965 if (audio_devs[dev]->open_mode & OPEN_WRITE)
966 ret = dma_set_fragment(dev, dmap_out, fact);
967 if (ret < 0)
968 return ret;
969 if (audio_devs[dev]->open_mode == OPEN_READ ||
970 (audio_devs[dev]->flags & DMA_DUPLEX &&
971 audio_devs[dev]->open_mode & OPEN_READ))
972 ret = dma_set_fragment(dev, dmap_in, fact);
973 if (ret < 0)
974 return ret;
975 if (!arg) /* don't know what this is good for, but preserve old semantics */
976 return 0;
977 break;
978
979 default:
980 if (!audio_devs[dev]->d->ioctl)
981 return -EINVAL;
982 return audio_devs[dev]->d->ioctl(dev, cmd, arg);
983 }
984 return put_user(ret, (int __user *)arg);
985}
diff --git a/sound/oss/bin2hex.c b/sound/oss/bin2hex.c
deleted file mode 100644
index 26c04ce04d71..000000000000
--- a/sound/oss/bin2hex.c
+++ /dev/null
@@ -1,40 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2#include <stdio.h>
3#include <string.h>
4#include <stdlib.h>
5
6int main( int argc, const char * argv [] )
7{
8 const char * varname;
9 int i = 0;
10 int c;
11 int id = 0;
12
13 if(argv[1] && strcmp(argv[1],"-i")==0)
14 {
15 argv++;
16 argc--;
17 id=1;
18 }
19
20 if(argc==1)
21 {
22 fprintf(stderr, "bin2hex: [-i] firmware\n");
23 exit(1);
24 }
25
26 varname = argv[1];
27 printf( "/* automatically generated by bin2hex */\n" );
28 printf( "static unsigned char %s [] %s =\n{\n", varname , id?"__initdata":"");
29
30 while ( ( c = getchar( ) ) != EOF )
31 {
32 if ( i != 0 && i % 10 == 0 )
33 printf( "\n" );
34 printf( "0x%02lx,", c & 0xFFl );
35 i++;
36 }
37
38 printf( "};\nstatic int %sLen = %d;\n", varname, i );
39 return 0;
40}
diff --git a/sound/oss/coproc.h b/sound/oss/coproc.h
deleted file mode 100644
index 7bec21bbdd88..000000000000
--- a/sound/oss/coproc.h
+++ /dev/null
@@ -1,12 +0,0 @@
1/*
2 * Definitions for various on board processors on the sound cards. For
3 * example DSP processors.
4 */
5
6/*
7 * Coprocessor access types
8 */
9#define COPR_CUSTOM 0x0001 /* Custom applications */
10#define COPR_MIDI 0x0002 /* MIDI (MPU-401) emulation */
11#define COPR_PCM 0x0004 /* Digitized voice applications */
12#define COPR_SYNTH 0x0008 /* Music synthesis */
diff --git a/sound/oss/dev_table.c b/sound/oss/dev_table.c
deleted file mode 100644
index 6dad51596b70..000000000000
--- a/sound/oss/dev_table.c
+++ /dev/null
@@ -1,256 +0,0 @@
1/*
2 * sound/oss/dev_table.c
3 *
4 * Device call tables.
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 */
13
14#include <linux/init.h>
15
16#include "sound_config.h"
17
18struct audio_operations *audio_devs[MAX_AUDIO_DEV];
19EXPORT_SYMBOL(audio_devs);
20
21int num_audiodevs;
22EXPORT_SYMBOL(num_audiodevs);
23
24struct mixer_operations *mixer_devs[MAX_MIXER_DEV];
25EXPORT_SYMBOL(mixer_devs);
26
27int num_mixers;
28EXPORT_SYMBOL(num_mixers);
29
30struct synth_operations *synth_devs[MAX_SYNTH_DEV+MAX_MIDI_DEV];
31EXPORT_SYMBOL(synth_devs);
32
33int num_synths;
34
35struct midi_operations *midi_devs[MAX_MIDI_DEV];
36EXPORT_SYMBOL(midi_devs);
37
38int num_midis;
39EXPORT_SYMBOL(num_midis);
40
41struct sound_timer_operations *sound_timer_devs[MAX_TIMER_DEV] = {
42 &default_sound_timer, NULL
43};
44EXPORT_SYMBOL(sound_timer_devs);
45
46int num_sound_timers = 1;
47
48
49static int sound_alloc_audiodev(void);
50
51int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
52 int driver_size, int flags, unsigned int format_mask,
53 void *devc, int dma1, int dma2)
54{
55 struct audio_driver *d;
56 struct audio_operations *op;
57 int num;
58
59 if (vers != AUDIO_DRIVER_VERSION || driver_size > sizeof(struct audio_driver)) {
60 printk(KERN_ERR "Sound: Incompatible audio driver for %s\n", name);
61 return -EINVAL;
62 }
63 num = sound_alloc_audiodev();
64
65 if (num == -1) {
66 printk(KERN_ERR "sound: Too many audio drivers\n");
67 return -EBUSY;
68 }
69 d = (struct audio_driver *) (sound_mem_blocks[sound_nblocks] = vmalloc(sizeof(struct audio_driver)));
70 sound_nblocks++;
71 if (sound_nblocks >= MAX_MEM_BLOCKS)
72 sound_nblocks = MAX_MEM_BLOCKS - 1;
73
74 op = (struct audio_operations *) (sound_mem_blocks[sound_nblocks] = vzalloc(sizeof(struct audio_operations)));
75 sound_nblocks++;
76 if (sound_nblocks >= MAX_MEM_BLOCKS)
77 sound_nblocks = MAX_MEM_BLOCKS - 1;
78
79 if (d == NULL || op == NULL) {
80 printk(KERN_ERR "Sound: Can't allocate driver for (%s)\n", name);
81 sound_unload_audiodev(num);
82 return -ENOMEM;
83 }
84 init_waitqueue_head(&op->in_sleeper);
85 init_waitqueue_head(&op->out_sleeper);
86 init_waitqueue_head(&op->poll_sleeper);
87 if (driver_size < sizeof(struct audio_driver))
88 memset((char *) d, 0, sizeof(struct audio_driver));
89
90 memcpy((char *) d, (char *) driver, driver_size);
91
92 op->d = d;
93 strlcpy(op->name, name, sizeof(op->name));
94 op->flags = flags;
95 op->format_mask = format_mask;
96 op->devc = devc;
97
98 /*
99 * Hardcoded defaults
100 */
101 audio_devs[num] = op;
102
103 DMAbuf_init(num, dma1, dma2);
104
105 audio_init_devices();
106 return num;
107}
108EXPORT_SYMBOL(sound_install_audiodrv);
109
110int sound_install_mixer(int vers, char *name, struct mixer_operations *driver,
111 int driver_size, void *devc)
112{
113 struct mixer_operations *op;
114
115 int n = sound_alloc_mixerdev();
116
117 if (n == -1) {
118 printk(KERN_ERR "Sound: Too many mixer drivers\n");
119 return -EBUSY;
120 }
121 if (vers != MIXER_DRIVER_VERSION ||
122 driver_size > sizeof(struct mixer_operations)) {
123 printk(KERN_ERR "Sound: Incompatible mixer driver for %s\n", name);
124 return -EINVAL;
125 }
126
127 /* FIXME: This leaks a mixer_operations struct every time its called
128 until you unload sound! */
129
130 op = (struct mixer_operations *) (sound_mem_blocks[sound_nblocks] = vzalloc(sizeof(struct mixer_operations)));
131 sound_nblocks++;
132 if (sound_nblocks >= MAX_MEM_BLOCKS)
133 sound_nblocks = MAX_MEM_BLOCKS - 1;
134
135 if (op == NULL) {
136 printk(KERN_ERR "Sound: Can't allocate mixer driver for (%s)\n", name);
137 return -ENOMEM;
138 }
139 memcpy((char *) op, (char *) driver, driver_size);
140
141 strlcpy(op->name, name, sizeof(op->name));
142 op->devc = devc;
143
144 mixer_devs[n] = op;
145 return n;
146}
147EXPORT_SYMBOL(sound_install_mixer);
148
149void sound_unload_audiodev(int dev)
150{
151 if (dev != -1) {
152 DMAbuf_deinit(dev);
153 audio_devs[dev] = NULL;
154 unregister_sound_dsp((dev<<4)+3);
155 }
156}
157EXPORT_SYMBOL(sound_unload_audiodev);
158
159static int sound_alloc_audiodev(void)
160{
161 int i = register_sound_dsp(&oss_sound_fops, -1);
162 if(i==-1)
163 return i;
164 i>>=4;
165 if(i>=num_audiodevs)
166 num_audiodevs = i + 1;
167 return i;
168}
169
170int sound_alloc_mididev(void)
171{
172 int i = register_sound_midi(&oss_sound_fops, -1);
173 if(i==-1)
174 return i;
175 i>>=4;
176 if(i>=num_midis)
177 num_midis = i + 1;
178 return i;
179}
180EXPORT_SYMBOL(sound_alloc_mididev);
181
182int sound_alloc_synthdev(void)
183{
184 int i;
185
186 for (i = 0; i < MAX_SYNTH_DEV; i++) {
187 if (synth_devs[i] == NULL) {
188 if (i >= num_synths)
189 num_synths++;
190 return i;
191 }
192 }
193 return -1;
194}
195EXPORT_SYMBOL(sound_alloc_synthdev);
196
197int sound_alloc_mixerdev(void)
198{
199 int i = register_sound_mixer(&oss_sound_fops, -1);
200 if(i==-1)
201 return -1;
202 i>>=4;
203 if(i>=num_mixers)
204 num_mixers = i + 1;
205 return i;
206}
207EXPORT_SYMBOL(sound_alloc_mixerdev);
208
209int sound_alloc_timerdev(void)
210{
211 int i;
212
213 for (i = 0; i < MAX_TIMER_DEV; i++) {
214 if (sound_timer_devs[i] == NULL) {
215 if (i >= num_sound_timers)
216 num_sound_timers++;
217 return i;
218 }
219 }
220 return -1;
221}
222EXPORT_SYMBOL(sound_alloc_timerdev);
223
224void sound_unload_mixerdev(int dev)
225{
226 if (dev != -1) {
227 mixer_devs[dev] = NULL;
228 unregister_sound_mixer(dev<<4);
229 num_mixers--;
230 }
231}
232EXPORT_SYMBOL(sound_unload_mixerdev);
233
234void sound_unload_mididev(int dev)
235{
236 if (dev != -1) {
237 midi_devs[dev] = NULL;
238 unregister_sound_midi((dev<<4)+2);
239 }
240}
241EXPORT_SYMBOL(sound_unload_mididev);
242
243void sound_unload_synthdev(int dev)
244{
245 if (dev != -1)
246 synth_devs[dev] = NULL;
247}
248EXPORT_SYMBOL(sound_unload_synthdev);
249
250void sound_unload_timerdev(int dev)
251{
252 if (dev != -1)
253 sound_timer_devs[dev] = NULL;
254}
255EXPORT_SYMBOL(sound_unload_timerdev);
256
diff --git a/sound/oss/dev_table.h b/sound/oss/dev_table.h
deleted file mode 100644
index 0199a317c5a9..000000000000
--- a/sound/oss/dev_table.h
+++ /dev/null
@@ -1,390 +0,0 @@
1/*
2 * dev_table.h
3 *
4 * Global definitions for device call tables
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 */
13
14
15#ifndef _DEV_TABLE_H_
16#define _DEV_TABLE_H_
17
18#include <linux/spinlock.h>
19/*
20 * Sound card numbers 27 to 999. (1 to 26 are defined in soundcard.h)
21 * Numbers 1000 to N are reserved for driver's internal use.
22 */
23
24#define SNDCARD_DESKPROXL 27 /* Compaq Deskpro XL */
25#define SNDCARD_VIDC 28 /* ARMs VIDC */
26#define SNDCARD_SBPNP 29
27#define SNDCARD_SOFTOSS 36
28#define SNDCARD_VMIDI 37
29#define SNDCARD_OPL3SA1 38 /* Note: clash in msnd.h */
30#define SNDCARD_OPL3SA1_SB 39
31#define SNDCARD_OPL3SA1_MPU 40
32#define SNDCARD_WAVEFRONT 41
33#define SNDCARD_OPL3SA2 42
34#define SNDCARD_OPL3SA2_MPU 43
35#define SNDCARD_WAVEARTIST 44 /* Waveartist */
36#define SNDCARD_OPL3SA2_MSS 45 /* Originally missed */
37#define SNDCARD_AD1816 88
38
39/*
40 * NOTE! NOTE! NOTE! NOTE!
41 *
42 * If you modify this file, please check the dev_table.c also.
43 *
44 * NOTE! NOTE! NOTE! NOTE!
45 */
46
47struct driver_info
48{
49 char *driver_id;
50 int card_subtype; /* Driver specific. Usually 0 */
51 int card_type; /* From soundcard.h */
52 char *name;
53 void (*attach) (struct address_info *hw_config);
54 int (*probe) (struct address_info *hw_config);
55 void (*unload) (struct address_info *hw_config);
56};
57
58struct card_info
59{
60 int card_type; /* Link (search key) to the driver list */
61 struct address_info config;
62 int enabled;
63 void *for_driver_use;
64};
65
66
67/*
68 * Device specific parameters (used only by dmabuf.c)
69 */
70#define MAX_SUB_BUFFERS (32*MAX_REALTIME_FACTOR)
71
72#define DMODE_NONE 0
73#define DMODE_OUTPUT PCM_ENABLE_OUTPUT
74#define DMODE_INPUT PCM_ENABLE_INPUT
75
76struct dma_buffparms
77{
78 int dma_mode; /* DMODE_INPUT, DMODE_OUTPUT or DMODE_NONE */
79 int closing;
80
81 /*
82 * Pointers to raw buffers
83 */
84
85 char *raw_buf;
86 unsigned long raw_buf_phys;
87 int buffsize;
88
89 /*
90 * Device state tables
91 */
92
93 unsigned long flags;
94#define DMA_BUSY 0x00000001
95#define DMA_RESTART 0x00000002
96#define DMA_ACTIVE 0x00000004
97#define DMA_STARTED 0x00000008
98#define DMA_EMPTY 0x00000010
99#define DMA_ALLOC_DONE 0x00000020
100#define DMA_SYNCING 0x00000040
101#define DMA_DIRTY 0x00000080
102#define DMA_POST 0x00000100
103#define DMA_NODMA 0x00000200
104#define DMA_NOTIMEOUT 0x00000400
105
106 int open_mode;
107
108 /*
109 * Queue parameters.
110 */
111 int qlen;
112 int qhead;
113 int qtail;
114 spinlock_t lock;
115
116 int cfrag; /* Current incomplete fragment (write) */
117
118 int nbufs;
119 int counts[MAX_SUB_BUFFERS];
120 int subdivision;
121
122 int fragment_size;
123 int needs_reorg;
124 int max_fragments;
125
126 int bytes_in_use;
127
128 int underrun_count;
129 unsigned long byte_counter;
130 unsigned long user_counter;
131 unsigned long max_byte_counter;
132 int data_rate; /* Bytes/second */
133
134 int mapping_flags;
135#define DMA_MAP_MAPPED 0x00000001
136 char neutral_byte;
137 int dma; /* DMA channel */
138
139 int applic_profile; /* Application profile (APF_*) */
140 /* Interrupt callback stuff */
141 void (*audio_callback) (int dev, int parm);
142 int callback_parm;
143
144 int buf_flags[MAX_SUB_BUFFERS];
145#define BUFF_EOF 0x00000001 /* Increment eof count */
146#define BUFF_DIRTY 0x00000002 /* Buffer written */
147};
148
149/*
150 * Structure for use with various microcontrollers and DSP processors
151 * in the recent sound cards.
152 */
153typedef struct coproc_operations
154{
155 char name[64];
156 struct module *owner;
157 int (*open) (void *devc, int sub_device);
158 void (*close) (void *devc, int sub_device);
159 int (*ioctl) (void *devc, unsigned int cmd, void __user * arg, int local);
160 void (*reset) (void *devc);
161
162 void *devc; /* Driver specific info */
163} coproc_operations;
164
165struct audio_driver
166{
167 struct module *owner;
168 int (*open) (int dev, int mode);
169 void (*close) (int dev);
170 void (*output_block) (int dev, unsigned long buf,
171 int count, int intrflag);
172 void (*start_input) (int dev, unsigned long buf,
173 int count, int intrflag);
174 int (*ioctl) (int dev, unsigned int cmd, void __user * arg);
175 int (*prepare_for_input) (int dev, int bufsize, int nbufs);
176 int (*prepare_for_output) (int dev, int bufsize, int nbufs);
177 void (*halt_io) (int dev);
178 int (*local_qlen)(int dev);
179 void (*copy_user) (int dev,
180 char *localbuf, int localoffs,
181 const char __user *userbuf, int useroffs,
182 int max_in, int max_out,
183 int *used, int *returned,
184 int len);
185 void (*halt_input) (int dev);
186 void (*halt_output) (int dev);
187 void (*trigger) (int dev, int bits);
188 int (*set_speed)(int dev, int speed);
189 unsigned int (*set_bits)(int dev, unsigned int bits);
190 short (*set_channels)(int dev, short channels);
191 void (*postprocess_write)(int dev); /* Device spesific postprocessing for written data */
192 void (*preprocess_read)(int dev); /* Device spesific preprocessing for read data */
193 void (*mmap)(int dev);
194};
195
196struct audio_operations
197{
198 char name[128];
199 int flags;
200#define NOTHING_SPECIAL 0x00
201#define NEEDS_RESTART 0x01
202#define DMA_AUTOMODE 0x02
203#define DMA_DUPLEX 0x04
204#define DMA_PSEUDO_AUTOMODE 0x08
205#define DMA_HARDSTOP 0x10
206#define DMA_EXACT 0x40
207#define DMA_NORESET 0x80
208 int format_mask; /* Bitmask for supported audio formats */
209 void *devc; /* Driver specific info */
210 struct audio_driver *d;
211 void *portc; /* Driver specific info */
212 struct dma_buffparms *dmap_in, *dmap_out;
213 struct coproc_operations *coproc;
214 int mixer_dev;
215 int enable_bits;
216 int open_mode;
217 int go;
218 int min_fragment; /* 0 == unlimited */
219 int max_fragment; /* 0 == unlimited */
220 int parent_dev; /* 0 -> no parent, 1 to n -> parent=parent_dev+1 */
221
222 /* fields formerly in dmabuf.c */
223 wait_queue_head_t in_sleeper;
224 wait_queue_head_t out_sleeper;
225 wait_queue_head_t poll_sleeper;
226
227 /* fields formerly in audio.c */
228 int audio_mode;
229
230#define AM_NONE 0
231#define AM_WRITE OPEN_WRITE
232#define AM_READ OPEN_READ
233
234 int local_format;
235 int audio_format;
236 int local_conversion;
237#define CNV_MU_LAW 0x00000001
238
239 /* large structures at the end to keep offsets small */
240 struct dma_buffparms dmaps[2];
241};
242
243int *load_mixer_volumes(char *name, int *levels, int present);
244
245struct mixer_operations
246{
247 struct module *owner;
248 char id[16];
249 char name[64];
250 int (*ioctl) (int dev, unsigned int cmd, void __user * arg);
251
252 void *devc;
253 int modify_counter;
254};
255
256struct synth_operations
257{
258 struct module *owner;
259 char *id; /* Unique identifier (ASCII) max 29 char */
260 struct synth_info *info;
261 int midi_dev;
262 int synth_type;
263 int synth_subtype;
264
265 int (*open) (int dev, int mode);
266 void (*close) (int dev);
267 int (*ioctl) (int dev, unsigned int cmd, void __user * arg);
268 int (*kill_note) (int dev, int voice, int note, int velocity);
269 int (*start_note) (int dev, int voice, int note, int velocity);
270 int (*set_instr) (int dev, int voice, int instr);
271 void (*reset) (int dev);
272 void (*hw_control) (int dev, unsigned char *event);
273 int (*load_patch) (int dev, int format, const char __user *addr,
274 int count, int pmgr_flag);
275 void (*aftertouch) (int dev, int voice, int pressure);
276 void (*controller) (int dev, int voice, int ctrl_num, int value);
277 void (*panning) (int dev, int voice, int value);
278 void (*volume_method) (int dev, int mode);
279 void (*bender) (int dev, int chn, int value);
280 int (*alloc_voice) (int dev, int chn, int note, struct voice_alloc_info *alloc);
281 void (*setup_voice) (int dev, int voice, int chn);
282 int (*send_sysex)(int dev, unsigned char *bytes, int len);
283
284 struct voice_alloc_info alloc;
285 struct channel_info chn_info[16];
286 int emulation;
287#define EMU_GM 1 /* General MIDI */
288#define EMU_XG 2 /* Yamaha XG */
289#define MAX_SYSEX_BUF 64
290 unsigned char sysex_buf[MAX_SYSEX_BUF];
291 int sysex_ptr;
292};
293
294struct midi_input_info
295{
296 /* MIDI input scanner variables */
297#define MI_MAX 10
298 volatile int m_busy;
299 unsigned char m_buf[MI_MAX];
300 unsigned char m_prev_status; /* For running status */
301 int m_ptr;
302#define MST_INIT 0
303#define MST_DATA 1
304#define MST_SYSEX 2
305 int m_state;
306 int m_left;
307};
308
309struct midi_operations
310{
311 struct module *owner;
312 struct midi_info info;
313 struct synth_operations *converter;
314 struct midi_input_info in_info;
315 int (*open) (int dev, int mode,
316 void (*inputintr)(int dev, unsigned char data),
317 void (*outputintr)(int dev)
318 );
319 void (*close) (int dev);
320 int (*ioctl) (int dev, unsigned int cmd, void __user * arg);
321 int (*outputc) (int dev, unsigned char data);
322 int (*start_read) (int dev);
323 int (*end_read) (int dev);
324 void (*kick)(int dev);
325 int (*command) (int dev, unsigned char *data);
326 int (*buffer_status) (int dev);
327 int (*prefix_cmd) (int dev, unsigned char status);
328 struct coproc_operations *coproc;
329 void *devc;
330};
331
332struct sound_lowlev_timer
333{
334 int dev;
335 int priority;
336 unsigned int (*tmr_start)(int dev, unsigned int usecs);
337 void (*tmr_disable)(int dev);
338 void (*tmr_restart)(int dev);
339};
340
341struct sound_timer_operations
342{
343 struct module *owner;
344 struct sound_timer_info info;
345 int priority;
346 int devlink;
347 int (*open)(int dev, int mode);
348 void (*close)(int dev);
349 int (*event)(int dev, unsigned char *ev);
350 unsigned long (*get_time)(int dev);
351 int (*ioctl) (int dev, unsigned int cmd, void __user * arg);
352 void (*arm_timer)(int dev, long time);
353};
354
355extern struct sound_timer_operations default_sound_timer;
356
357extern struct audio_operations *audio_devs[MAX_AUDIO_DEV];
358extern int num_audiodevs;
359extern struct mixer_operations *mixer_devs[MAX_MIXER_DEV];
360extern int num_mixers;
361extern struct synth_operations *synth_devs[MAX_SYNTH_DEV+MAX_MIDI_DEV];
362extern int num_synths;
363extern struct midi_operations *midi_devs[MAX_MIDI_DEV];
364extern int num_midis;
365extern struct sound_timer_operations * sound_timer_devs[MAX_TIMER_DEV];
366extern int num_sound_timers;
367
368extern int sound_map_buffer (int dev, struct dma_buffparms *dmap, buffmem_desc *info);
369void sound_timer_init (struct sound_lowlev_timer *t, char *name);
370void sound_dma_intr (int dev, struct dma_buffparms *dmap, int chan);
371
372#define AUDIO_DRIVER_VERSION 2
373#define MIXER_DRIVER_VERSION 2
374int sound_install_audiodrv(int vers, char *name, struct audio_driver *driver,
375 int driver_size, int flags, unsigned int format_mask,
376 void *devc, int dma1, int dma2);
377int sound_install_mixer(int vers, char *name, struct mixer_operations *driver,
378 int driver_size, void *devc);
379
380void sound_unload_audiodev(int dev);
381void sound_unload_mixerdev(int dev);
382void sound_unload_mididev(int dev);
383void sound_unload_synthdev(int dev);
384void sound_unload_timerdev(int dev);
385int sound_alloc_mixerdev(void);
386int sound_alloc_timerdev(void);
387int sound_alloc_synthdev(void);
388int sound_alloc_mididev(void);
389#endif /* _DEV_TABLE_H_ */
390
diff --git a/sound/oss/dmabuf.c b/sound/oss/dmabuf.c
deleted file mode 100644
index c5dd396c66a2..000000000000
--- a/sound/oss/dmabuf.c
+++ /dev/null
@@ -1,1268 +0,0 @@
1/*
2 * sound/oss/dmabuf.c
3 *
4 * The DMA buffer manager for digitized voice applications
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 * Thomas Sailer : moved several static variables into struct audio_operations
14 * (which is grossly misnamed btw.) because they have the same
15 * lifetime as the rest in there and dynamic allocation saves
16 * 12k or so
17 * Thomas Sailer : remove {in,out}_sleep_flag. It was used for the sleeper to
18 * determine if it was woken up by the expiring timeout or by
19 * an explicit wake_up. The return value from schedule_timeout
20 * can be used instead; if 0, the wakeup was due to the timeout.
21 *
22 * Rob Riggs Added persistent DMA buffers (1998/10/17)
23 */
24
25#define BE_CONSERVATIVE
26#define SAMPLE_ROUNDUP 0
27
28#include <linux/mm.h>
29#include <linux/gfp.h>
30#include <linux/sched/signal.h>
31
32#include "sound_config.h"
33#include "sleep.h"
34
35#define DMAP_FREE_ON_CLOSE 0
36#define DMAP_KEEP_ON_CLOSE 1
37extern int sound_dmap_flag;
38
39static void dma_reset_output(int dev);
40static void dma_reset_input(int dev);
41static int local_start_dma(struct audio_operations *adev, unsigned long physaddr, int count, int dma_mode);
42
43
44
45static int debugmem; /* switched off by default */
46static int dma_buffsize = DSP_BUFFSIZE;
47
48static long dmabuf_timeout(struct dma_buffparms *dmap)
49{
50 long tmout;
51
52 tmout = (dmap->fragment_size * HZ) / dmap->data_rate;
53 tmout += HZ / 5; /* Some safety distance */
54 if (tmout < (HZ / 2))
55 tmout = HZ / 2;
56 if (tmout > 20 * HZ)
57 tmout = 20 * HZ;
58 return tmout;
59}
60
61static int sound_alloc_dmap(struct dma_buffparms *dmap)
62{
63 char *start_addr, *end_addr;
64 int dma_pagesize;
65 int sz, size;
66 struct page *page;
67
68 dmap->mapping_flags &= ~DMA_MAP_MAPPED;
69
70 if (dmap->raw_buf != NULL)
71 return 0; /* Already done */
72 if (dma_buffsize < 4096)
73 dma_buffsize = 4096;
74 dma_pagesize = (dmap->dma < 4) ? (64 * 1024) : (128 * 1024);
75
76 /*
77 * Now check for the Cyrix problem.
78 */
79
80 if(isa_dma_bridge_buggy==2)
81 dma_pagesize=32768;
82
83 dmap->raw_buf = NULL;
84 dmap->buffsize = dma_buffsize;
85 if (dmap->buffsize > dma_pagesize)
86 dmap->buffsize = dma_pagesize;
87 start_addr = NULL;
88 /*
89 * Now loop until we get a free buffer. Try to get smaller buffer if
90 * it fails. Don't accept smaller than 8k buffer for performance
91 * reasons.
92 */
93 while (start_addr == NULL && dmap->buffsize > PAGE_SIZE) {
94 for (sz = 0, size = PAGE_SIZE; size < dmap->buffsize; sz++, size <<= 1);
95 dmap->buffsize = PAGE_SIZE * (1 << sz);
96 start_addr = (char *) __get_free_pages(GFP_ATOMIC|GFP_DMA|__GFP_NOWARN, sz);
97 if (start_addr == NULL)
98 dmap->buffsize /= 2;
99 }
100
101 if (start_addr == NULL) {
102 printk(KERN_WARNING "Sound error: Couldn't allocate DMA buffer\n");
103 return -ENOMEM;
104 } else {
105 /* make some checks */
106 end_addr = start_addr + dmap->buffsize - 1;
107
108 if (debugmem)
109 printk(KERN_DEBUG "sound: start 0x%lx, end 0x%lx\n", (long) start_addr, (long) end_addr);
110
111 /* now check if it fits into the same dma-pagesize */
112
113 if (((long) start_addr & ~(dma_pagesize - 1)) != ((long) end_addr & ~(dma_pagesize - 1))
114 || end_addr >= (char *) (MAX_DMA_ADDRESS)) {
115 printk(KERN_ERR "sound: Got invalid address 0x%lx for %db DMA-buffer\n", (long) start_addr, dmap->buffsize);
116 return -EFAULT;
117 }
118 }
119 dmap->raw_buf = start_addr;
120 dmap->raw_buf_phys = dma_map_single(NULL, start_addr, dmap->buffsize, DMA_BIDIRECTIONAL);
121
122 for (page = virt_to_page(start_addr); page <= virt_to_page(end_addr); page++)
123 SetPageReserved(page);
124 return 0;
125}
126
127static void sound_free_dmap(struct dma_buffparms *dmap)
128{
129 int sz, size;
130 struct page *page;
131 unsigned long start_addr, end_addr;
132
133 if (dmap->raw_buf == NULL)
134 return;
135 if (dmap->mapping_flags & DMA_MAP_MAPPED)
136 return; /* Don't free mmapped buffer. Will use it next time */
137 for (sz = 0, size = PAGE_SIZE; size < dmap->buffsize; sz++, size <<= 1);
138
139 start_addr = (unsigned long) dmap->raw_buf;
140 end_addr = start_addr + dmap->buffsize;
141
142 for (page = virt_to_page(start_addr); page <= virt_to_page(end_addr); page++)
143 ClearPageReserved(page);
144
145 dma_unmap_single(NULL, dmap->raw_buf_phys, dmap->buffsize, DMA_BIDIRECTIONAL);
146 free_pages((unsigned long) dmap->raw_buf, sz);
147 dmap->raw_buf = NULL;
148}
149
150
151/* Intel version !!!!!!!!! */
152
153static int sound_start_dma(struct dma_buffparms *dmap, unsigned long physaddr, int count, int dma_mode)
154{
155 unsigned long flags;
156 int chan = dmap->dma;
157
158 /* printk( "Start DMA%d %d, %d\n", chan, (int)(physaddr-dmap->raw_buf_phys), count); */
159
160 flags = claim_dma_lock();
161 disable_dma(chan);
162 clear_dma_ff(chan);
163 set_dma_mode(chan, dma_mode);
164 set_dma_addr(chan, physaddr);
165 set_dma_count(chan, count);
166 enable_dma(chan);
167 release_dma_lock(flags);
168
169 return 0;
170}
171
172static void dma_init_buffers(struct dma_buffparms *dmap)
173{
174 dmap->qlen = dmap->qhead = dmap->qtail = dmap->user_counter = 0;
175 dmap->byte_counter = 0;
176 dmap->max_byte_counter = 8000 * 60 * 60;
177 dmap->bytes_in_use = dmap->buffsize;
178
179 dmap->dma_mode = DMODE_NONE;
180 dmap->mapping_flags = 0;
181 dmap->neutral_byte = 0x80;
182 dmap->data_rate = 8000;
183 dmap->cfrag = -1;
184 dmap->closing = 0;
185 dmap->nbufs = 1;
186 dmap->flags = DMA_BUSY; /* Other flags off */
187}
188
189static int open_dmap(struct audio_operations *adev, int mode, struct dma_buffparms *dmap)
190{
191 int err;
192
193 if (dmap->flags & DMA_BUSY)
194 return -EBUSY;
195 if ((err = sound_alloc_dmap(dmap)) < 0)
196 return err;
197
198 if (dmap->raw_buf == NULL) {
199 printk(KERN_WARNING "Sound: DMA buffers not available\n");
200 return -ENOSPC; /* Memory allocation failed during boot */
201 }
202 if (dmap->dma >= 0 && sound_open_dma(dmap->dma, adev->name)) {
203 printk(KERN_WARNING "Unable to grab(2) DMA%d for the audio driver\n", dmap->dma);
204 return -EBUSY;
205 }
206 dma_init_buffers(dmap);
207 spin_lock_init(&dmap->lock);
208 dmap->open_mode = mode;
209 dmap->subdivision = dmap->underrun_count = 0;
210 dmap->fragment_size = 0;
211 dmap->max_fragments = 65536; /* Just a large value */
212 dmap->byte_counter = 0;
213 dmap->max_byte_counter = 8000 * 60 * 60;
214 dmap->applic_profile = APF_NORMAL;
215 dmap->needs_reorg = 1;
216 dmap->audio_callback = NULL;
217 dmap->callback_parm = 0;
218 return 0;
219}
220
221static void close_dmap(struct audio_operations *adev, struct dma_buffparms *dmap)
222{
223 unsigned long flags;
224
225 if (dmap->dma >= 0) {
226 sound_close_dma(dmap->dma);
227 flags=claim_dma_lock();
228 disable_dma(dmap->dma);
229 release_dma_lock(flags);
230 }
231 if (dmap->flags & DMA_BUSY)
232 dmap->dma_mode = DMODE_NONE;
233 dmap->flags &= ~DMA_BUSY;
234
235 if (sound_dmap_flag == DMAP_FREE_ON_CLOSE)
236 sound_free_dmap(dmap);
237}
238
239
240static unsigned int default_set_bits(int dev, unsigned int bits)
241{
242 mm_segment_t fs = get_fs();
243
244 set_fs(get_ds());
245 audio_devs[dev]->d->ioctl(dev, SNDCTL_DSP_SETFMT, (void __user *)&bits);
246 set_fs(fs);
247 return bits;
248}
249
250static int default_set_speed(int dev, int speed)
251{
252 mm_segment_t fs = get_fs();
253
254 set_fs(get_ds());
255 audio_devs[dev]->d->ioctl(dev, SNDCTL_DSP_SPEED, (void __user *)&speed);
256 set_fs(fs);
257 return speed;
258}
259
260static short default_set_channels(int dev, short channels)
261{
262 int c = channels;
263 mm_segment_t fs = get_fs();
264
265 set_fs(get_ds());
266 audio_devs[dev]->d->ioctl(dev, SNDCTL_DSP_CHANNELS, (void __user *)&c);
267 set_fs(fs);
268 return c;
269}
270
271static void check_driver(struct audio_driver *d)
272{
273 if (d->set_speed == NULL)
274 d->set_speed = default_set_speed;
275 if (d->set_bits == NULL)
276 d->set_bits = default_set_bits;
277 if (d->set_channels == NULL)
278 d->set_channels = default_set_channels;
279}
280
281int DMAbuf_open(int dev, int mode)
282{
283 struct audio_operations *adev = audio_devs[dev];
284 int retval;
285 struct dma_buffparms *dmap_in = NULL;
286 struct dma_buffparms *dmap_out = NULL;
287
288 if (!adev)
289 return -ENXIO;
290 if (!(adev->flags & DMA_DUPLEX))
291 adev->dmap_in = adev->dmap_out;
292 check_driver(adev->d);
293
294 if ((retval = adev->d->open(dev, mode)) < 0)
295 return retval;
296 dmap_out = adev->dmap_out;
297 dmap_in = adev->dmap_in;
298 if (dmap_in == dmap_out)
299 adev->flags &= ~DMA_DUPLEX;
300
301 if (mode & OPEN_WRITE) {
302 if ((retval = open_dmap(adev, mode, dmap_out)) < 0) {
303 adev->d->close(dev);
304 return retval;
305 }
306 }
307 adev->enable_bits = mode;
308
309 if (mode == OPEN_READ || (mode != OPEN_WRITE && (adev->flags & DMA_DUPLEX))) {
310 if ((retval = open_dmap(adev, mode, dmap_in)) < 0) {
311 adev->d->close(dev);
312 if (mode & OPEN_WRITE)
313 close_dmap(adev, dmap_out);
314 return retval;
315 }
316 }
317 adev->open_mode = mode;
318 adev->go = 1;
319
320 adev->d->set_bits(dev, 8);
321 adev->d->set_channels(dev, 1);
322 adev->d->set_speed(dev, DSP_DEFAULT_SPEED);
323 if (adev->dmap_out->dma_mode == DMODE_OUTPUT)
324 memset(adev->dmap_out->raw_buf, adev->dmap_out->neutral_byte,
325 adev->dmap_out->bytes_in_use);
326 return 0;
327}
328/* MUST not hold the spinlock */
329void DMAbuf_reset(int dev)
330{
331 if (audio_devs[dev]->open_mode & OPEN_WRITE)
332 dma_reset_output(dev);
333
334 if (audio_devs[dev]->open_mode & OPEN_READ)
335 dma_reset_input(dev);
336}
337
338static void dma_reset_output(int dev)
339{
340 struct audio_operations *adev = audio_devs[dev];
341 unsigned long flags,f ;
342 struct dma_buffparms *dmap = adev->dmap_out;
343
344 if (!(dmap->flags & DMA_STARTED)) /* DMA is not active */
345 return;
346
347 /*
348 * First wait until the current fragment has been played completely
349 */
350 spin_lock_irqsave(&dmap->lock,flags);
351 adev->dmap_out->flags |= DMA_SYNCING;
352
353 adev->dmap_out->underrun_count = 0;
354 if (!signal_pending(current) && adev->dmap_out->qlen &&
355 adev->dmap_out->underrun_count == 0){
356 spin_unlock_irqrestore(&dmap->lock,flags);
357 oss_broken_sleep_on(&adev->out_sleeper, dmabuf_timeout(dmap));
358 spin_lock_irqsave(&dmap->lock,flags);
359 }
360 adev->dmap_out->flags &= ~(DMA_SYNCING | DMA_ACTIVE);
361
362 /*
363 * Finally shut the device off
364 */
365 if (!(adev->flags & DMA_DUPLEX) || !adev->d->halt_output)
366 adev->d->halt_io(dev);
367 else
368 adev->d->halt_output(dev);
369 adev->dmap_out->flags &= ~DMA_STARTED;
370
371 f=claim_dma_lock();
372 clear_dma_ff(dmap->dma);
373 disable_dma(dmap->dma);
374 release_dma_lock(f);
375
376 dmap->byte_counter = 0;
377 reorganize_buffers(dev, adev->dmap_out, 0);
378 dmap->qlen = dmap->qhead = dmap->qtail = dmap->user_counter = 0;
379 spin_unlock_irqrestore(&dmap->lock,flags);
380}
381
382static void dma_reset_input(int dev)
383{
384 struct audio_operations *adev = audio_devs[dev];
385 unsigned long flags;
386 struct dma_buffparms *dmap = adev->dmap_in;
387
388 spin_lock_irqsave(&dmap->lock,flags);
389 if (!(adev->flags & DMA_DUPLEX) || !adev->d->halt_input)
390 adev->d->halt_io(dev);
391 else
392 adev->d->halt_input(dev);
393 adev->dmap_in->flags &= ~DMA_STARTED;
394
395 dmap->qlen = dmap->qhead = dmap->qtail = dmap->user_counter = 0;
396 dmap->byte_counter = 0;
397 reorganize_buffers(dev, adev->dmap_in, 1);
398 spin_unlock_irqrestore(&dmap->lock,flags);
399}
400/* MUST be called with holding the dmap->lock */
401void DMAbuf_launch_output(int dev, struct dma_buffparms *dmap)
402{
403 struct audio_operations *adev = audio_devs[dev];
404
405 if (!((adev->enable_bits * adev->go) & PCM_ENABLE_OUTPUT))
406 return; /* Don't start DMA yet */
407 dmap->dma_mode = DMODE_OUTPUT;
408
409 if (!(dmap->flags & DMA_ACTIVE) || !(adev->flags & DMA_AUTOMODE) || (dmap->flags & DMA_NODMA)) {
410 if (!(dmap->flags & DMA_STARTED)) {
411 reorganize_buffers(dev, dmap, 0);
412 if (adev->d->prepare_for_output(dev, dmap->fragment_size, dmap->nbufs))
413 return;
414 if (!(dmap->flags & DMA_NODMA))
415 local_start_dma(adev, dmap->raw_buf_phys, dmap->bytes_in_use,DMA_MODE_WRITE);
416 dmap->flags |= DMA_STARTED;
417 }
418 if (dmap->counts[dmap->qhead] == 0)
419 dmap->counts[dmap->qhead] = dmap->fragment_size;
420 dmap->dma_mode = DMODE_OUTPUT;
421 adev->d->output_block(dev, dmap->raw_buf_phys + dmap->qhead * dmap->fragment_size,
422 dmap->counts[dmap->qhead], 1);
423 if (adev->d->trigger)
424 adev->d->trigger(dev,adev->enable_bits * adev->go);
425 }
426 dmap->flags |= DMA_ACTIVE;
427}
428
429int DMAbuf_sync(int dev)
430{
431 struct audio_operations *adev = audio_devs[dev];
432 unsigned long flags;
433 int n = 0;
434 struct dma_buffparms *dmap;
435
436 if (!adev->go && !(adev->enable_bits & PCM_ENABLE_OUTPUT))
437 return 0;
438
439 if (adev->dmap_out->dma_mode == DMODE_OUTPUT) {
440 dmap = adev->dmap_out;
441 spin_lock_irqsave(&dmap->lock,flags);
442 if (dmap->qlen > 0 && !(dmap->flags & DMA_ACTIVE))
443 DMAbuf_launch_output(dev, dmap);
444 adev->dmap_out->flags |= DMA_SYNCING;
445 adev->dmap_out->underrun_count = 0;
446 while (!signal_pending(current) && n++ < adev->dmap_out->nbufs &&
447 adev->dmap_out->qlen && adev->dmap_out->underrun_count == 0) {
448 long t = dmabuf_timeout(dmap);
449 spin_unlock_irqrestore(&dmap->lock,flags);
450 /* FIXME: not safe may miss events */
451 t = oss_broken_sleep_on(&adev->out_sleeper, t);
452 spin_lock_irqsave(&dmap->lock,flags);
453 if (!t) {
454 adev->dmap_out->flags &= ~DMA_SYNCING;
455 spin_unlock_irqrestore(&dmap->lock,flags);
456 return adev->dmap_out->qlen;
457 }
458 }
459 adev->dmap_out->flags &= ~(DMA_SYNCING | DMA_ACTIVE);
460
461 /*
462 * Some devices such as GUS have huge amount of on board RAM for the
463 * audio data. We have to wait until the device has finished playing.
464 */
465
466 /* still holding the lock */
467 if (adev->d->local_qlen) { /* Device has hidden buffers */
468 while (!signal_pending(current) &&
469 adev->d->local_qlen(dev)){
470 spin_unlock_irqrestore(&dmap->lock,flags);
471 oss_broken_sleep_on(&adev->out_sleeper,
472 dmabuf_timeout(dmap));
473 spin_lock_irqsave(&dmap->lock,flags);
474 }
475 }
476 spin_unlock_irqrestore(&dmap->lock,flags);
477 }
478 adev->dmap_out->dma_mode = DMODE_NONE;
479 return adev->dmap_out->qlen;
480}
481
482int DMAbuf_release(int dev, int mode)
483{
484 struct audio_operations *adev = audio_devs[dev];
485 struct dma_buffparms *dmap;
486 unsigned long flags;
487
488 dmap = adev->dmap_out;
489 if (adev->open_mode & OPEN_WRITE)
490 adev->dmap_out->closing = 1;
491
492 if (adev->open_mode & OPEN_READ){
493 adev->dmap_in->closing = 1;
494 dmap = adev->dmap_in;
495 }
496 if (adev->open_mode & OPEN_WRITE)
497 if (!(adev->dmap_out->mapping_flags & DMA_MAP_MAPPED))
498 if (!signal_pending(current) && (adev->dmap_out->dma_mode == DMODE_OUTPUT))
499 DMAbuf_sync(dev);
500 if (adev->dmap_out->dma_mode == DMODE_OUTPUT)
501 memset(adev->dmap_out->raw_buf, adev->dmap_out->neutral_byte, adev->dmap_out->bytes_in_use);
502
503 DMAbuf_reset(dev);
504 spin_lock_irqsave(&dmap->lock,flags);
505 adev->d->close(dev);
506
507 if (adev->open_mode & OPEN_WRITE)
508 close_dmap(adev, adev->dmap_out);
509
510 if (adev->open_mode == OPEN_READ ||
511 (adev->open_mode != OPEN_WRITE &&
512 (adev->flags & DMA_DUPLEX)))
513 close_dmap(adev, adev->dmap_in);
514 adev->open_mode = 0;
515 spin_unlock_irqrestore(&dmap->lock,flags);
516 return 0;
517}
518/* called with dmap->lock dold */
519int DMAbuf_activate_recording(int dev, struct dma_buffparms *dmap)
520{
521 struct audio_operations *adev = audio_devs[dev];
522 int err;
523
524 if (!(adev->open_mode & OPEN_READ))
525 return 0;
526 if (!(adev->enable_bits & PCM_ENABLE_INPUT))
527 return 0;
528 if (dmap->dma_mode == DMODE_OUTPUT) { /* Direction change */
529 /* release lock - it's not recursive */
530 spin_unlock_irq(&dmap->lock);
531 DMAbuf_sync(dev);
532 DMAbuf_reset(dev);
533 spin_lock_irq(&dmap->lock);
534 dmap->dma_mode = DMODE_NONE;
535 }
536 if (!dmap->dma_mode) {
537 reorganize_buffers(dev, dmap, 1);
538 if ((err = adev->d->prepare_for_input(dev,
539 dmap->fragment_size, dmap->nbufs)) < 0)
540 return err;
541 dmap->dma_mode = DMODE_INPUT;
542 }
543 if (!(dmap->flags & DMA_ACTIVE)) {
544 if (dmap->needs_reorg)
545 reorganize_buffers(dev, dmap, 0);
546 local_start_dma(adev, dmap->raw_buf_phys, dmap->bytes_in_use, DMA_MODE_READ);
547 adev->d->start_input(dev, dmap->raw_buf_phys + dmap->qtail * dmap->fragment_size,
548 dmap->fragment_size, 0);
549 dmap->flags |= DMA_ACTIVE;
550 if (adev->d->trigger)
551 adev->d->trigger(dev, adev->enable_bits * adev->go);
552 }
553 return 0;
554}
555/* acquires lock */
556int DMAbuf_getrdbuffer(int dev, char **buf, int *len, int dontblock)
557{
558 struct audio_operations *adev = audio_devs[dev];
559 unsigned long flags;
560 int err = 0, n = 0;
561 struct dma_buffparms *dmap = adev->dmap_in;
562
563 if (!(adev->open_mode & OPEN_READ))
564 return -EIO;
565 spin_lock_irqsave(&dmap->lock,flags);
566 if (dmap->needs_reorg)
567 reorganize_buffers(dev, dmap, 0);
568 if (adev->dmap_in->mapping_flags & DMA_MAP_MAPPED) {
569/* printk(KERN_WARNING "Sound: Can't read from mmapped device (1)\n");*/
570 spin_unlock_irqrestore(&dmap->lock,flags);
571 return -EINVAL;
572 } else while (dmap->qlen <= 0 && n++ < 10) {
573 long timeout = MAX_SCHEDULE_TIMEOUT;
574 if (!(adev->enable_bits & PCM_ENABLE_INPUT) || !adev->go) {
575 spin_unlock_irqrestore(&dmap->lock,flags);
576 return -EAGAIN;
577 }
578 if ((err = DMAbuf_activate_recording(dev, dmap)) < 0) {
579 spin_unlock_irqrestore(&dmap->lock,flags);
580 return err;
581 }
582 /* Wait for the next block */
583
584 if (dontblock) {
585 spin_unlock_irqrestore(&dmap->lock,flags);
586 return -EAGAIN;
587 }
588 if (adev->go)
589 timeout = dmabuf_timeout(dmap);
590
591 spin_unlock_irqrestore(&dmap->lock,flags);
592 timeout = oss_broken_sleep_on(&adev->in_sleeper, timeout);
593 if (!timeout) {
594 /* FIXME: include device name */
595 err = -EIO;
596 printk(KERN_WARNING "Sound: DMA (input) timed out - IRQ/DRQ config error?\n");
597 dma_reset_input(dev);
598 } else
599 err = -EINTR;
600 spin_lock_irqsave(&dmap->lock,flags);
601 }
602 spin_unlock_irqrestore(&dmap->lock,flags);
603
604 if (dmap->qlen <= 0)
605 return err ? err : -EINTR;
606 *buf = &dmap->raw_buf[dmap->qhead * dmap->fragment_size + dmap->counts[dmap->qhead]];
607 *len = dmap->fragment_size - dmap->counts[dmap->qhead];
608
609 return dmap->qhead;
610}
611
612int DMAbuf_rmchars(int dev, int buff_no, int c)
613{
614 struct audio_operations *adev = audio_devs[dev];
615 struct dma_buffparms *dmap = adev->dmap_in;
616 int p = dmap->counts[dmap->qhead] + c;
617
618 if (dmap->mapping_flags & DMA_MAP_MAPPED)
619 {
620/* printk("Sound: Can't read from mmapped device (2)\n");*/
621 return -EINVAL;
622 }
623 else if (dmap->qlen <= 0)
624 return -EIO;
625 else if (p >= dmap->fragment_size) { /* This buffer is completely empty */
626 dmap->counts[dmap->qhead] = 0;
627 dmap->qlen--;
628 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
629 }
630 else dmap->counts[dmap->qhead] = p;
631
632 return 0;
633}
634/* MUST be called with dmap->lock hold */
635int DMAbuf_get_buffer_pointer(int dev, struct dma_buffparms *dmap, int direction)
636{
637 /*
638 * Try to approximate the active byte position of the DMA pointer within the
639 * buffer area as well as possible.
640 */
641
642 int pos;
643 unsigned long f;
644
645 if (!(dmap->flags & DMA_ACTIVE))
646 pos = 0;
647 else {
648 int chan = dmap->dma;
649
650 f=claim_dma_lock();
651 clear_dma_ff(chan);
652
653 if(!isa_dma_bridge_buggy)
654 disable_dma(dmap->dma);
655
656 pos = get_dma_residue(chan);
657
658 pos = dmap->bytes_in_use - pos;
659
660 if (!(dmap->mapping_flags & DMA_MAP_MAPPED)) {
661 if (direction == DMODE_OUTPUT) {
662 if (dmap->qhead == 0)
663 if (pos > dmap->fragment_size)
664 pos = 0;
665 } else {
666 if (dmap->qtail == 0)
667 if (pos > dmap->fragment_size)
668 pos = 0;
669 }
670 }
671 if (pos < 0)
672 pos = 0;
673 if (pos >= dmap->bytes_in_use)
674 pos = 0;
675
676 if(!isa_dma_bridge_buggy)
677 enable_dma(dmap->dma);
678
679 release_dma_lock(f);
680 }
681 /* printk( "%04x ", pos); */
682
683 return pos;
684}
685
686/*
687 * DMAbuf_start_devices() is called by the /dev/music driver to start
688 * one or more audio devices at desired moment.
689 */
690
691void DMAbuf_start_devices(unsigned int devmask)
692{
693 struct audio_operations *adev;
694 int dev;
695
696 for (dev = 0; dev < num_audiodevs; dev++) {
697 if (!(devmask & (1 << dev)))
698 continue;
699 if (!(adev = audio_devs[dev]))
700 continue;
701 if (adev->open_mode == 0)
702 continue;
703 if (adev->go)
704 continue;
705 /* OK to start the device */
706 adev->go = 1;
707 if (adev->d->trigger)
708 adev->d->trigger(dev,adev->enable_bits * adev->go);
709 }
710}
711/* via poll called without a lock ?*/
712int DMAbuf_space_in_queue(int dev)
713{
714 struct audio_operations *adev = audio_devs[dev];
715 int len, max, tmp;
716 struct dma_buffparms *dmap = adev->dmap_out;
717 int lim = dmap->nbufs;
718
719 if (lim < 2)
720 lim = 2;
721
722 if (dmap->qlen >= lim) /* No space at all */
723 return 0;
724
725 /*
726 * Verify that there are no more pending buffers than the limit
727 * defined by the process.
728 */
729
730 max = dmap->max_fragments;
731 if (max > lim)
732 max = lim;
733 len = dmap->qlen;
734
735 if (adev->d->local_qlen) {
736 tmp = adev->d->local_qlen(dev);
737 if (tmp && len)
738 tmp--; /* This buffer has been counted twice */
739 len += tmp;
740 }
741 if (dmap->byte_counter % dmap->fragment_size) /* There is a partial fragment */
742 len = len + 1;
743
744 if (len >= max)
745 return 0;
746 return max - len;
747}
748/* MUST not hold the spinlock - this function may sleep */
749static int output_sleep(int dev, int dontblock)
750{
751 struct audio_operations *adev = audio_devs[dev];
752 int err = 0;
753 struct dma_buffparms *dmap = adev->dmap_out;
754 long timeout;
755 long timeout_value;
756
757 if (dontblock)
758 return -EAGAIN;
759 if (!(adev->enable_bits & PCM_ENABLE_OUTPUT))
760 return -EAGAIN;
761
762 /*
763 * Wait for free space
764 */
765 if (signal_pending(current))
766 return -EINTR;
767 timeout = (adev->go && !(dmap->flags & DMA_NOTIMEOUT));
768 if (timeout)
769 timeout_value = dmabuf_timeout(dmap);
770 else
771 timeout_value = MAX_SCHEDULE_TIMEOUT;
772 timeout_value = oss_broken_sleep_on(&adev->out_sleeper, timeout_value);
773 if (timeout != MAX_SCHEDULE_TIMEOUT && !timeout_value) {
774 printk(KERN_WARNING "Sound: DMA (output) timed out - IRQ/DRQ config error?\n");
775 dma_reset_output(dev);
776 } else {
777 if (signal_pending(current))
778 err = -EINTR;
779 }
780 return err;
781}
782/* called with the lock held */
783static int find_output_space(int dev, char **buf, int *size)
784{
785 struct audio_operations *adev = audio_devs[dev];
786 struct dma_buffparms *dmap = adev->dmap_out;
787 unsigned long active_offs;
788 long len, offs;
789 int maxfrags;
790 int occupied_bytes = (dmap->user_counter % dmap->fragment_size);
791
792 *buf = dmap->raw_buf;
793 if (!(maxfrags = DMAbuf_space_in_queue(dev)) && !occupied_bytes)
794 return 0;
795
796#ifdef BE_CONSERVATIVE
797 active_offs = dmap->byte_counter + dmap->qhead * dmap->fragment_size;
798#else
799 active_offs = max(DMAbuf_get_buffer_pointer(dev, dmap, DMODE_OUTPUT), 0);
800 /* Check for pointer wrapping situation */
801 if (active_offs >= dmap->bytes_in_use)
802 active_offs = 0;
803 active_offs += dmap->byte_counter;
804#endif
805
806 offs = (dmap->user_counter % dmap->bytes_in_use) & ~SAMPLE_ROUNDUP;
807 if (offs < 0 || offs >= dmap->bytes_in_use) {
808 printk(KERN_ERR "Sound: Got unexpected offs %ld. Giving up.\n", offs);
809 printk("Counter = %ld, bytes=%d\n", dmap->user_counter, dmap->bytes_in_use);
810 return 0;
811 }
812 *buf = dmap->raw_buf + offs;
813
814 len = active_offs + dmap->bytes_in_use - dmap->user_counter; /* Number of unused bytes in buffer */
815
816 if ((offs + len) > dmap->bytes_in_use)
817 len = dmap->bytes_in_use - offs;
818 if (len < 0) {
819 return 0;
820 }
821 if (len > ((maxfrags * dmap->fragment_size) - occupied_bytes))
822 len = (maxfrags * dmap->fragment_size) - occupied_bytes;
823 *size = len & ~SAMPLE_ROUNDUP;
824 return (*size > 0);
825}
826/* acquires lock */
827int DMAbuf_getwrbuffer(int dev, char **buf, int *size, int dontblock)
828{
829 struct audio_operations *adev = audio_devs[dev];
830 unsigned long flags;
831 int err = -EIO;
832 struct dma_buffparms *dmap = adev->dmap_out;
833
834 if (dmap->mapping_flags & DMA_MAP_MAPPED) {
835/* printk(KERN_DEBUG "Sound: Can't write to mmapped device (3)\n");*/
836 return -EINVAL;
837 }
838 spin_lock_irqsave(&dmap->lock,flags);
839 if (dmap->needs_reorg)
840 reorganize_buffers(dev, dmap, 0);
841
842 if (dmap->dma_mode == DMODE_INPUT) { /* Direction change */
843 spin_unlock_irqrestore(&dmap->lock,flags);
844 DMAbuf_reset(dev);
845 spin_lock_irqsave(&dmap->lock,flags);
846 }
847 dmap->dma_mode = DMODE_OUTPUT;
848
849 while (find_output_space(dev, buf, size) <= 0) {
850 spin_unlock_irqrestore(&dmap->lock,flags);
851 if ((err = output_sleep(dev, dontblock)) < 0) {
852 return err;
853 }
854 spin_lock_irqsave(&dmap->lock,flags);
855 }
856
857 spin_unlock_irqrestore(&dmap->lock,flags);
858 return 0;
859}
860/* has to acquire dmap->lock */
861int DMAbuf_move_wrpointer(int dev, int l)
862{
863 struct audio_operations *adev = audio_devs[dev];
864 struct dma_buffparms *dmap = adev->dmap_out;
865 unsigned long ptr;
866 unsigned long end_ptr, p;
867 int post;
868 unsigned long flags;
869
870 spin_lock_irqsave(&dmap->lock,flags);
871 post= (dmap->flags & DMA_POST);
872 ptr = (dmap->user_counter / dmap->fragment_size) * dmap->fragment_size;
873
874 dmap->flags &= ~DMA_POST;
875 dmap->cfrag = -1;
876 dmap->user_counter += l;
877 dmap->flags |= DMA_DIRTY;
878
879 if (dmap->byte_counter >= dmap->max_byte_counter) {
880 /* Wrap the byte counters */
881 long decr = dmap->byte_counter;
882 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use);
883 decr -= dmap->byte_counter;
884 dmap->user_counter -= decr;
885 }
886 end_ptr = (dmap->user_counter / dmap->fragment_size) * dmap->fragment_size;
887
888 p = (dmap->user_counter - 1) % dmap->bytes_in_use;
889 dmap->neutral_byte = dmap->raw_buf[p];
890
891 /* Update the fragment based bookkeeping too */
892 while (ptr < end_ptr) {
893 dmap->counts[dmap->qtail] = dmap->fragment_size;
894 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
895 dmap->qlen++;
896 ptr += dmap->fragment_size;
897 }
898
899 dmap->counts[dmap->qtail] = dmap->user_counter - ptr;
900
901 /*
902 * Let the low level driver perform some postprocessing to
903 * the written data.
904 */
905 if (adev->d->postprocess_write)
906 adev->d->postprocess_write(dev);
907
908 if (!(dmap->flags & DMA_ACTIVE))
909 if (dmap->qlen > 1 || (dmap->qlen > 0 && (post || dmap->qlen >= dmap->nbufs - 1)))
910 DMAbuf_launch_output(dev, dmap);
911
912 spin_unlock_irqrestore(&dmap->lock,flags);
913 return 0;
914}
915
916int DMAbuf_start_dma(int dev, unsigned long physaddr, int count, int dma_mode)
917{
918 struct audio_operations *adev = audio_devs[dev];
919 struct dma_buffparms *dmap = (dma_mode == DMA_MODE_WRITE) ? adev->dmap_out : adev->dmap_in;
920
921 if (dmap->raw_buf == NULL) {
922 printk(KERN_ERR "sound: DMA buffer(1) == NULL\n");
923 printk("Device %d, chn=%s\n", dev, (dmap == adev->dmap_out) ? "out" : "in");
924 return 0;
925 }
926 if (dmap->dma < 0)
927 return 0;
928 sound_start_dma(dmap, physaddr, count, dma_mode);
929 return count;
930}
931EXPORT_SYMBOL(DMAbuf_start_dma);
932
933static int local_start_dma(struct audio_operations *adev, unsigned long physaddr, int count, int dma_mode)
934{
935 struct dma_buffparms *dmap = (dma_mode == DMA_MODE_WRITE) ? adev->dmap_out : adev->dmap_in;
936
937 if (dmap->raw_buf == NULL) {
938 printk(KERN_ERR "sound: DMA buffer(2) == NULL\n");
939 printk(KERN_ERR "Device %s, chn=%s\n", adev->name, (dmap == adev->dmap_out) ? "out" : "in");
940 return 0;
941 }
942 if (dmap->flags & DMA_NODMA)
943 return 1;
944 if (dmap->dma < 0)
945 return 0;
946 sound_start_dma(dmap, dmap->raw_buf_phys, dmap->bytes_in_use, dma_mode | DMA_AUTOINIT);
947 dmap->flags |= DMA_STARTED;
948 return count;
949}
950
951static void finish_output_interrupt(int dev, struct dma_buffparms *dmap)
952{
953 struct audio_operations *adev = audio_devs[dev];
954
955 if (dmap->audio_callback != NULL)
956 dmap->audio_callback(dev, dmap->callback_parm);
957 wake_up(&adev->out_sleeper);
958 wake_up(&adev->poll_sleeper);
959}
960/* called with dmap->lock held in irq context*/
961static void do_outputintr(int dev, int dummy)
962{
963 struct audio_operations *adev = audio_devs[dev];
964 struct dma_buffparms *dmap = adev->dmap_out;
965 int this_fragment;
966
967 if (dmap->raw_buf == NULL) {
968 printk(KERN_ERR "Sound: Error. Audio interrupt (%d) after freeing buffers.\n", dev);
969 return;
970 }
971 if (dmap->mapping_flags & DMA_MAP_MAPPED) { /* Virtual memory mapped access */
972 /* mmapped access */
973 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
974 if (dmap->qhead == 0) { /* Wrapped */
975 dmap->byte_counter += dmap->bytes_in_use;
976 if (dmap->byte_counter >= dmap->max_byte_counter) { /* Overflow */
977 long decr = dmap->byte_counter;
978 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use);
979 decr -= dmap->byte_counter;
980 dmap->user_counter -= decr;
981 }
982 }
983 dmap->qlen++; /* Yes increment it (don't decrement) */
984 if (!(adev->flags & DMA_AUTOMODE))
985 dmap->flags &= ~DMA_ACTIVE;
986 dmap->counts[dmap->qhead] = dmap->fragment_size;
987 DMAbuf_launch_output(dev, dmap);
988 finish_output_interrupt(dev, dmap);
989 return;
990 }
991
992 dmap->qlen--;
993 this_fragment = dmap->qhead;
994 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
995
996 if (dmap->qhead == 0) { /* Wrapped */
997 dmap->byte_counter += dmap->bytes_in_use;
998 if (dmap->byte_counter >= dmap->max_byte_counter) { /* Overflow */
999 long decr = dmap->byte_counter;
1000 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use);
1001 decr -= dmap->byte_counter;
1002 dmap->user_counter -= decr;
1003 }
1004 }
1005 if (!(adev->flags & DMA_AUTOMODE))
1006 dmap->flags &= ~DMA_ACTIVE;
1007
1008 /*
1009 * This is dmap->qlen <= 0 except when closing when
1010 * dmap->qlen < 0
1011 */
1012
1013 while (dmap->qlen <= -dmap->closing) {
1014 dmap->underrun_count++;
1015 dmap->qlen++;
1016 if ((dmap->flags & DMA_DIRTY) && dmap->applic_profile != APF_CPUINTENS) {
1017 dmap->flags &= ~DMA_DIRTY;
1018 memset(adev->dmap_out->raw_buf, adev->dmap_out->neutral_byte,
1019 adev->dmap_out->buffsize);
1020 }
1021 dmap->user_counter += dmap->fragment_size;
1022 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1023 }
1024 if (dmap->qlen > 0)
1025 DMAbuf_launch_output(dev, dmap);
1026 finish_output_interrupt(dev, dmap);
1027}
1028/* called in irq context */
1029void DMAbuf_outputintr(int dev, int notify_only)
1030{
1031 struct audio_operations *adev = audio_devs[dev];
1032 unsigned long flags;
1033 struct dma_buffparms *dmap = adev->dmap_out;
1034
1035 spin_lock_irqsave(&dmap->lock,flags);
1036 if (!(dmap->flags & DMA_NODMA)) {
1037 int chan = dmap->dma, pos, n;
1038 unsigned long f;
1039
1040 f=claim_dma_lock();
1041
1042 if(!isa_dma_bridge_buggy)
1043 disable_dma(dmap->dma);
1044 clear_dma_ff(chan);
1045 pos = dmap->bytes_in_use - get_dma_residue(chan);
1046 if(!isa_dma_bridge_buggy)
1047 enable_dma(dmap->dma);
1048 release_dma_lock(f);
1049
1050 pos = pos / dmap->fragment_size; /* Actual qhead */
1051 if (pos < 0 || pos >= dmap->nbufs)
1052 pos = 0;
1053 n = 0;
1054 while (dmap->qhead != pos && n++ < dmap->nbufs)
1055 do_outputintr(dev, notify_only);
1056 }
1057 else
1058 do_outputintr(dev, notify_only);
1059 spin_unlock_irqrestore(&dmap->lock,flags);
1060}
1061EXPORT_SYMBOL(DMAbuf_outputintr);
1062
1063/* called with dmap->lock held in irq context */
1064static void do_inputintr(int dev)
1065{
1066 struct audio_operations *adev = audio_devs[dev];
1067 struct dma_buffparms *dmap = adev->dmap_in;
1068
1069 if (dmap->raw_buf == NULL) {
1070 printk(KERN_ERR "Sound: Fatal error. Audio interrupt after freeing buffers.\n");
1071 return;
1072 }
1073 if (dmap->mapping_flags & DMA_MAP_MAPPED) {
1074 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1075 if (dmap->qtail == 0) { /* Wrapped */
1076 dmap->byte_counter += dmap->bytes_in_use;
1077 if (dmap->byte_counter >= dmap->max_byte_counter) { /* Overflow */
1078 long decr = dmap->byte_counter;
1079 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use) + dmap->bytes_in_use;
1080 decr -= dmap->byte_counter;
1081 dmap->user_counter -= decr;
1082 }
1083 }
1084 dmap->qlen++;
1085
1086 if (!(adev->flags & DMA_AUTOMODE)) {
1087 if (dmap->needs_reorg)
1088 reorganize_buffers(dev, dmap, 0);
1089 local_start_dma(adev, dmap->raw_buf_phys, dmap->bytes_in_use,DMA_MODE_READ);
1090 adev->d->start_input(dev, dmap->raw_buf_phys + dmap->qtail * dmap->fragment_size,
1091 dmap->fragment_size, 1);
1092 if (adev->d->trigger)
1093 adev->d->trigger(dev, adev->enable_bits * adev->go);
1094 }
1095 dmap->flags |= DMA_ACTIVE;
1096 } else if (dmap->qlen >= (dmap->nbufs - 1)) {
1097 printk(KERN_WARNING "Sound: Recording overrun\n");
1098 dmap->underrun_count++;
1099
1100 /* Just throw away the oldest fragment but keep the engine running */
1101 dmap->qhead = (dmap->qhead + 1) % dmap->nbufs;
1102 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1103 } else if (dmap->qlen >= 0 && dmap->qlen < dmap->nbufs) {
1104 dmap->qlen++;
1105 dmap->qtail = (dmap->qtail + 1) % dmap->nbufs;
1106 if (dmap->qtail == 0) { /* Wrapped */
1107 dmap->byte_counter += dmap->bytes_in_use;
1108 if (dmap->byte_counter >= dmap->max_byte_counter) { /* Overflow */
1109 long decr = dmap->byte_counter;
1110 dmap->byte_counter = (dmap->byte_counter % dmap->bytes_in_use) + dmap->bytes_in_use;
1111 decr -= dmap->byte_counter;
1112 dmap->user_counter -= decr;
1113 }
1114 }
1115 }
1116 if (!(adev->flags & DMA_AUTOMODE) || (dmap->flags & DMA_NODMA)) {
1117 local_start_dma(adev, dmap->raw_buf_phys, dmap->bytes_in_use, DMA_MODE_READ);
1118 adev->d->start_input(dev, dmap->raw_buf_phys + dmap->qtail * dmap->fragment_size, dmap->fragment_size, 1);
1119 if (adev->d->trigger)
1120 adev->d->trigger(dev,adev->enable_bits * adev->go);
1121 }
1122 dmap->flags |= DMA_ACTIVE;
1123 if (dmap->qlen > 0)
1124 {
1125 wake_up(&adev->in_sleeper);
1126 wake_up(&adev->poll_sleeper);
1127 }
1128}
1129/* called in irq context */
1130void DMAbuf_inputintr(int dev)
1131{
1132 struct audio_operations *adev = audio_devs[dev];
1133 struct dma_buffparms *dmap = adev->dmap_in;
1134 unsigned long flags;
1135
1136 spin_lock_irqsave(&dmap->lock,flags);
1137
1138 if (!(dmap->flags & DMA_NODMA)) {
1139 int chan = dmap->dma, pos, n;
1140 unsigned long f;
1141
1142 f=claim_dma_lock();
1143 if(!isa_dma_bridge_buggy)
1144 disable_dma(dmap->dma);
1145 clear_dma_ff(chan);
1146 pos = dmap->bytes_in_use - get_dma_residue(chan);
1147 if(!isa_dma_bridge_buggy)
1148 enable_dma(dmap->dma);
1149 release_dma_lock(f);
1150
1151 pos = pos / dmap->fragment_size; /* Actual qhead */
1152 if (pos < 0 || pos >= dmap->nbufs)
1153 pos = 0;
1154
1155 n = 0;
1156 while (dmap->qtail != pos && ++n < dmap->nbufs)
1157 do_inputintr(dev);
1158 } else
1159 do_inputintr(dev);
1160 spin_unlock_irqrestore(&dmap->lock,flags);
1161}
1162EXPORT_SYMBOL(DMAbuf_inputintr);
1163
1164void DMAbuf_init(int dev, int dma1, int dma2)
1165{
1166 struct audio_operations *adev = audio_devs[dev];
1167 /*
1168 * NOTE! This routine could be called several times.
1169 */
1170
1171 if (adev && adev->dmap_out == NULL) {
1172 if (adev->d == NULL)
1173 panic("OSS: audio_devs[%d]->d == NULL\n", dev);
1174
1175 if (adev->parent_dev) { /* Use DMA map of the parent dev */
1176 int parent = adev->parent_dev - 1;
1177 adev->dmap_out = audio_devs[parent]->dmap_out;
1178 adev->dmap_in = audio_devs[parent]->dmap_in;
1179 } else {
1180 adev->dmap_out = adev->dmap_in = &adev->dmaps[0];
1181 adev->dmap_out->dma = dma1;
1182 if (adev->flags & DMA_DUPLEX) {
1183 adev->dmap_in = &adev->dmaps[1];
1184 adev->dmap_in->dma = dma2;
1185 }
1186 }
1187 /* Persistent DMA buffers allocated here */
1188 if (sound_dmap_flag == DMAP_KEEP_ON_CLOSE) {
1189 if (adev->dmap_in->raw_buf == NULL)
1190 sound_alloc_dmap(adev->dmap_in);
1191 if (adev->dmap_out->raw_buf == NULL)
1192 sound_alloc_dmap(adev->dmap_out);
1193 }
1194 }
1195}
1196
1197/* No kernel lock - DMAbuf_activate_recording protected by global cli/sti */
1198static unsigned int poll_input(struct file * file, int dev, poll_table *wait)
1199{
1200 struct audio_operations *adev = audio_devs[dev];
1201 struct dma_buffparms *dmap = adev->dmap_in;
1202
1203 if (!(adev->open_mode & OPEN_READ))
1204 return 0;
1205 if (dmap->mapping_flags & DMA_MAP_MAPPED) {
1206 if (dmap->qlen)
1207 return POLLIN | POLLRDNORM;
1208 return 0;
1209 }
1210 if (dmap->dma_mode != DMODE_INPUT) {
1211 if (dmap->dma_mode == DMODE_NONE &&
1212 adev->enable_bits & PCM_ENABLE_INPUT &&
1213 !dmap->qlen && adev->go) {
1214 unsigned long flags;
1215
1216 spin_lock_irqsave(&dmap->lock,flags);
1217 DMAbuf_activate_recording(dev, dmap);
1218 spin_unlock_irqrestore(&dmap->lock,flags);
1219 }
1220 return 0;
1221 }
1222 if (!dmap->qlen)
1223 return 0;
1224 return POLLIN | POLLRDNORM;
1225}
1226
1227static unsigned int poll_output(struct file * file, int dev, poll_table *wait)
1228{
1229 struct audio_operations *adev = audio_devs[dev];
1230 struct dma_buffparms *dmap = adev->dmap_out;
1231
1232 if (!(adev->open_mode & OPEN_WRITE))
1233 return 0;
1234 if (dmap->mapping_flags & DMA_MAP_MAPPED) {
1235 if (dmap->qlen)
1236 return POLLOUT | POLLWRNORM;
1237 return 0;
1238 }
1239 if (dmap->dma_mode == DMODE_INPUT)
1240 return 0;
1241 if (dmap->dma_mode == DMODE_NONE)
1242 return POLLOUT | POLLWRNORM;
1243 if (!DMAbuf_space_in_queue(dev))
1244 return 0;
1245 return POLLOUT | POLLWRNORM;
1246}
1247
1248unsigned int DMAbuf_poll(struct file * file, int dev, poll_table *wait)
1249{
1250 struct audio_operations *adev = audio_devs[dev];
1251 poll_wait(file, &adev->poll_sleeper, wait);
1252 return poll_input(file, dev, wait) | poll_output(file, dev, wait);
1253}
1254
1255void DMAbuf_deinit(int dev)
1256{
1257 struct audio_operations *adev = audio_devs[dev];
1258 /* This routine is called when driver is being unloaded */
1259 if (!adev)
1260 return;
1261
1262 /* Persistent DMA buffers deallocated here */
1263 if (sound_dmap_flag == DMAP_KEEP_ON_CLOSE) {
1264 sound_free_dmap(adev->dmap_out);
1265 if (adev->flags & DMA_DUPLEX)
1266 sound_free_dmap(adev->dmap_in);
1267 }
1268}
diff --git a/sound/oss/hex2hex.c b/sound/oss/hex2hex.c
deleted file mode 100644
index f76d729b0196..000000000000
--- a/sound/oss/hex2hex.c
+++ /dev/null
@@ -1,102 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * hex2hex reads stdin in Intel HEX format and produces an
4 * (unsigned char) array which contains the bytes and writes it
5 * to stdout using C syntax
6 */
7
8#include <stdio.h>
9#include <string.h>
10#include <stdlib.h>
11
12#define ABANDON(why) { fprintf(stderr, "%s\n", why); exit(1); }
13#define MAX_SIZE (256*1024)
14unsigned char buf[MAX_SIZE];
15
16static int loadhex(FILE *inf, unsigned char *buf)
17{
18 int l=0, c, i;
19
20 while ((c=getc(inf))!=EOF)
21 {
22 if (c == ':') /* Sync with beginning of line */
23 {
24 int n, check;
25 unsigned char sum;
26 int addr;
27 int linetype;
28
29 if (fscanf(inf, "%02x", &n) != 1)
30 ABANDON("File format error");
31 sum = n;
32
33 if (fscanf(inf, "%04x", &addr) != 1)
34 ABANDON("File format error");
35 sum += addr/256;
36 sum += addr%256;
37
38 if (fscanf(inf, "%02x", &linetype) != 1)
39 ABANDON("File format error");
40 sum += linetype;
41
42 if (linetype != 0)
43 continue;
44
45 for (i=0;i<n;i++)
46 {
47 if (fscanf(inf, "%02x", &c) != 1)
48 ABANDON("File format error");
49 if (addr >= MAX_SIZE)
50 ABANDON("File too large");
51 buf[addr++] = c;
52 if (addr > l)
53 l = addr;
54 sum += c;
55 }
56
57 if (fscanf(inf, "%02x", &check) != 1)
58 ABANDON("File format error");
59
60 sum = ~sum + 1;
61 if (check != sum)
62 ABANDON("Line checksum error");
63 }
64 }
65
66 return l;
67}
68
69int main( int argc, const char * argv [] )
70{
71 const char * varline;
72 int i,l;
73 int id=0;
74
75 if(argv[1] && strcmp(argv[1], "-i")==0)
76 {
77 argv++;
78 argc--;
79 id=1;
80 }
81 if(argv[1]==NULL)
82 {
83 fprintf(stderr,"hex2hex: [-i] filename\n");
84 exit(1);
85 }
86 varline = argv[1];
87 l = loadhex(stdin, buf);
88
89 printf("/*\n *\t Computer generated file. Do not edit.\n */\n");
90 printf("static int %s_len = %d;\n", varline, l);
91 printf("static unsigned char %s[] %s = {\n", varline, id?"__initdata":"");
92
93 for (i=0;i<l;i++)
94 {
95 if (i) printf(",");
96 if (i && !(i % 16)) printf("\n");
97 printf("0x%02x", buf[i]);
98 }
99
100 printf("\n};\n\n");
101 return 0;
102}
diff --git a/sound/oss/kahlua.c b/sound/oss/kahlua.c
deleted file mode 100644
index c4b0434c7604..000000000000
--- a/sound/oss/kahlua.c
+++ /dev/null
@@ -1,229 +0,0 @@
1/*
2 * Initialisation code for Cyrix/NatSemi VSA1 softaudio
3 *
4 * (C) Copyright 2003 Red Hat Inc <alan@lxorguk.ukuu.org.uk>
5 *
6 * XpressAudio(tm) is used on the Cyrix MediaGX (now NatSemi Geode) systems.
7 * The older version (VSA1) provides fairly good soundblaster emulation
8 * although there are a couple of bugs: large DMA buffers break record,
9 * and the MPU event handling seems suspect. VSA2 allows the native driver
10 * to control the AC97 audio engine directly and requires a different driver.
11 *
12 * Thanks to National Semiconductor for providing the needed information
13 * on the XpressAudio(tm) internals.
14 *
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 2, or (at your option) any
18 * later version.
19 *
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * General Public License for more details.
24 *
25 * TO DO:
26 * Investigate whether we can portably support Cognac (5520) in the
27 * same manner.
28 */
29
30#include <linux/delay.h>
31#include <linux/init.h>
32#include <linux/module.h>
33#include <linux/pci.h>
34#include <linux/slab.h>
35
36#include "sound_config.h"
37
38#include "sb.h"
39
40/*
41 * Read a soundblaster compatible mixer register.
42 * In this case we are actually reading an SMI trap
43 * not real hardware.
44 */
45
46static u8 mixer_read(unsigned long io, u8 reg)
47{
48 outb(reg, io + 4);
49 udelay(20);
50 reg = inb(io + 5);
51 udelay(20);
52 return reg;
53}
54
55static int probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
56{
57 struct address_info *hw_config;
58 unsigned long base;
59 void __iomem *mem;
60 unsigned long io;
61 u16 map;
62 u8 irq, dma8, dma16;
63 int oldquiet;
64 extern int sb_be_quiet;
65
66 base = pci_resource_start(pdev, 0);
67 if(base == 0UL)
68 return 1;
69
70 mem = ioremap(base, 128);
71 if (!mem)
72 return 1;
73 map = readw(mem + 0x18); /* Read the SMI enables */
74 iounmap(mem);
75
76 /* Map bits
77 0:1 * 0x20 + 0x200 = sb base
78 2 sb enable
79 3 adlib enable
80 5 MPU enable 0x330
81 6 MPU enable 0x300
82
83 The other bits may be used internally so must be masked */
84
85 io = 0x220 + 0x20 * (map & 3);
86
87 if(map & (1<<2))
88 printk(KERN_INFO "kahlua: XpressAudio at 0x%lx\n", io);
89 else
90 return 1;
91
92 if(map & (1<<5))
93 printk(KERN_INFO "kahlua: MPU at 0x300\n");
94 else if(map & (1<<6))
95 printk(KERN_INFO "kahlua: MPU at 0x330\n");
96
97 irq = mixer_read(io, 0x80) & 0x0F;
98 dma8 = mixer_read(io, 0x81);
99
100 // printk("IRQ=%x MAP=%x DMA=%x\n", irq, map, dma8);
101
102 if(dma8 & 0x20)
103 dma16 = 5;
104 else if(dma8 & 0x40)
105 dma16 = 6;
106 else if(dma8 & 0x80)
107 dma16 = 7;
108 else
109 {
110 printk(KERN_ERR "kahlua: No 16bit DMA enabled.\n");
111 return 1;
112 }
113
114 if(dma8 & 0x01)
115 dma8 = 0;
116 else if(dma8 & 0x02)
117 dma8 = 1;
118 else if(dma8 & 0x08)
119 dma8 = 3;
120 else
121 {
122 printk(KERN_ERR "kahlua: No 8bit DMA enabled.\n");
123 return 1;
124 }
125
126 if(irq & 1)
127 irq = 9;
128 else if(irq & 2)
129 irq = 5;
130 else if(irq & 4)
131 irq = 7;
132 else if(irq & 8)
133 irq = 10;
134 else
135 {
136 printk(KERN_ERR "kahlua: SB IRQ not set.\n");
137 return 1;
138 }
139
140 printk(KERN_INFO "kahlua: XpressAudio on IRQ %d, DMA %d, %d\n",
141 irq, dma8, dma16);
142
143 hw_config = kzalloc(sizeof(struct address_info), GFP_KERNEL);
144 if(hw_config == NULL)
145 {
146 printk(KERN_ERR "kahlua: out of memory.\n");
147 return 1;
148 }
149
150 pci_set_drvdata(pdev, hw_config);
151
152 hw_config->io_base = io;
153 hw_config->irq = irq;
154 hw_config->dma = dma8;
155 hw_config->dma2 = dma16;
156 hw_config->name = "Cyrix XpressAudio";
157 hw_config->driver_use_1 = SB_NO_MIDI | SB_PCI_IRQ;
158
159 if (!request_region(io, 16, "soundblaster"))
160 goto err_out_free;
161
162 if(sb_dsp_detect(hw_config, 0, 0, NULL)==0)
163 {
164 printk(KERN_ERR "kahlua: audio not responding.\n");
165 release_region(io, 16);
166 goto err_out_free;
167 }
168
169 oldquiet = sb_be_quiet;
170 sb_be_quiet = 1;
171 if(sb_dsp_init(hw_config, THIS_MODULE))
172 {
173 sb_be_quiet = oldquiet;
174 goto err_out_free;
175 }
176 sb_be_quiet = oldquiet;
177
178 return 0;
179
180err_out_free:
181 kfree(hw_config);
182 return 1;
183}
184
185static void remove_one(struct pci_dev *pdev)
186{
187 struct address_info *hw_config = pci_get_drvdata(pdev);
188 sb_dsp_unload(hw_config, 0);
189 kfree(hw_config);
190}
191
192MODULE_AUTHOR("Alan Cox");
193MODULE_DESCRIPTION("Kahlua VSA1 PCI Audio");
194MODULE_LICENSE("GPL");
195
196/*
197 * 5530 only. The 5510/5520 decode is different.
198 */
199
200static const struct pci_device_id id_tbl[] = {
201 { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO), 0 },
202 { }
203};
204
205MODULE_DEVICE_TABLE(pci, id_tbl);
206
207static struct pci_driver kahlua_driver = {
208 .name = "kahlua",
209 .id_table = id_tbl,
210 .probe = probe_one,
211 .remove = remove_one,
212};
213
214
215static int __init kahlua_init_module(void)
216{
217 printk(KERN_INFO "Cyrix Kahlua VSA1 XpressAudio support (c) Copyright 2003 Red Hat Inc\n");
218 return pci_register_driver(&kahlua_driver);
219}
220
221static void kahlua_cleanup_module(void)
222{
223 pci_unregister_driver(&kahlua_driver);
224}
225
226
227module_init(kahlua_init_module);
228module_exit(kahlua_cleanup_module);
229
diff --git a/sound/oss/midi_ctrl.h b/sound/oss/midi_ctrl.h
deleted file mode 100644
index 240d0c719f1e..000000000000
--- a/sound/oss/midi_ctrl.h
+++ /dev/null
@@ -1,23 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2static unsigned char ctrl_def_values[128] =
3{
4 0x40,0x00,0x40,0x40, 0x40,0x40,0x40,0x7f, /* 0 to 7 */
5 0x40,0x40,0x40,0x7f, 0x40,0x40,0x40,0x40, /* 8 to 15 */
6 0x40,0x40,0x40,0x40, 0x40,0x40,0x40,0x40, /* 16 to 23 */
7 0x40,0x40,0x40,0x40, 0x40,0x40,0x40,0x40, /* 24 to 31 */
8
9 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 32 to 39 */
10 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 40 to 47 */
11 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 48 to 55 */
12 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 56 to 63 */
13
14 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 64 to 71 */
15 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 72 to 79 */
16 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 80 to 87 */
17 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 88 to 95 */
18
19 0x00,0x00,0x7f,0x7f, 0x7f,0x7f,0x00,0x00, /* 96 to 103 */
20 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 104 to 111 */
21 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 112 to 119 */
22 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, /* 120 to 127 */
23};
diff --git a/sound/oss/midi_synth.c b/sound/oss/midi_synth.c
deleted file mode 100644
index 2292c230d7e6..000000000000
--- a/sound/oss/midi_synth.c
+++ /dev/null
@@ -1,712 +0,0 @@
1/*
2 * sound/oss/midi_synth.c
3 *
4 * High level midi sequencer manager for dumb MIDI interfaces.
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 */
13/*
14 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
15 * Andrew Veliath : fixed running status in MIDI input state machine
16 */
17#define USE_SEQ_MACROS
18#define USE_SIMPLE_MACROS
19
20#include "sound_config.h"
21
22#define _MIDI_SYNTH_C_
23
24#include "midi_synth.h"
25
26static int midi2synth[MAX_MIDI_DEV];
27static int sysex_state[MAX_MIDI_DEV] =
28{0};
29static unsigned char prev_out_status[MAX_MIDI_DEV];
30
31#define STORE(cmd) \
32{ \
33 int len; \
34 unsigned char obuf[8]; \
35 cmd; \
36 seq_input_event(obuf, len); \
37}
38
39#define _seqbuf obuf
40#define _seqbufptr 0
41#define _SEQ_ADVBUF(x) len=x
42
43void
44do_midi_msg(int synthno, unsigned char *msg, int mlen)
45{
46 switch (msg[0] & 0xf0)
47 {
48 case 0x90:
49 if (msg[2] != 0)
50 {
51 STORE(SEQ_START_NOTE(synthno, msg[0] & 0x0f, msg[1], msg[2]));
52 break;
53 }
54 msg[2] = 64;
55
56 case 0x80:
57 STORE(SEQ_STOP_NOTE(synthno, msg[0] & 0x0f, msg[1], msg[2]));
58 break;
59
60 case 0xA0:
61 STORE(SEQ_KEY_PRESSURE(synthno, msg[0] & 0x0f, msg[1], msg[2]));
62 break;
63
64 case 0xB0:
65 STORE(SEQ_CONTROL(synthno, msg[0] & 0x0f,
66 msg[1], msg[2]));
67 break;
68
69 case 0xC0:
70 STORE(SEQ_SET_PATCH(synthno, msg[0] & 0x0f, msg[1]));
71 break;
72
73 case 0xD0:
74 STORE(SEQ_CHN_PRESSURE(synthno, msg[0] & 0x0f, msg[1]));
75 break;
76
77 case 0xE0:
78 STORE(SEQ_BENDER(synthno, msg[0] & 0x0f,
79 (msg[1] & 0x7f) | ((msg[2] & 0x7f) << 7)));
80 break;
81
82 default:
83 /* printk( "MPU: Unknown midi channel message %02x\n", msg[0]); */
84 ;
85 }
86}
87EXPORT_SYMBOL(do_midi_msg);
88
89static void
90midi_outc(int midi_dev, int data)
91{
92 int timeout;
93
94 for (timeout = 0; timeout < 3200; timeout++)
95 if (midi_devs[midi_dev]->outputc(midi_dev, (unsigned char) (data & 0xff)))
96 {
97 if (data & 0x80) /*
98 * Status byte
99 */
100 prev_out_status[midi_dev] =
101 (unsigned char) (data & 0xff); /*
102 * Store for running status
103 */
104 return; /*
105 * Mission complete
106 */
107 }
108 /*
109 * Sorry! No space on buffers.
110 */
111 printk("Midi send timed out\n");
112}
113
114static int
115prefix_cmd(int midi_dev, unsigned char status)
116{
117 if ((char *) midi_devs[midi_dev]->prefix_cmd == NULL)
118 return 1;
119
120 return midi_devs[midi_dev]->prefix_cmd(midi_dev, status);
121}
122
123static void
124midi_synth_input(int orig_dev, unsigned char data)
125{
126 int dev;
127 struct midi_input_info *inc;
128
129 static unsigned char len_tab[] = /* # of data bytes following a status
130 */
131 {
132 2, /* 8x */
133 2, /* 9x */
134 2, /* Ax */
135 2, /* Bx */
136 1, /* Cx */
137 1, /* Dx */
138 2, /* Ex */
139 0 /* Fx */
140 };
141
142 if (orig_dev < 0 || orig_dev > num_midis || midi_devs[orig_dev] == NULL)
143 return;
144
145 if (data == 0xfe) /* Ignore active sensing */
146 return;
147
148 dev = midi2synth[orig_dev];
149 inc = &midi_devs[orig_dev]->in_info;
150
151 switch (inc->m_state)
152 {
153 case MST_INIT:
154 if (data & 0x80) /* MIDI status byte */
155 {
156 if ((data & 0xf0) == 0xf0) /* Common message */
157 {
158 switch (data)
159 {
160 case 0xf0: /* Sysex */
161 inc->m_state = MST_SYSEX;
162 break; /* Sysex */
163
164 case 0xf1: /* MTC quarter frame */
165 case 0xf3: /* Song select */
166 inc->m_state = MST_DATA;
167 inc->m_ptr = 1;
168 inc->m_left = 1;
169 inc->m_buf[0] = data;
170 break;
171
172 case 0xf2: /* Song position pointer */
173 inc->m_state = MST_DATA;
174 inc->m_ptr = 1;
175 inc->m_left = 2;
176 inc->m_buf[0] = data;
177 break;
178
179 default:
180 inc->m_buf[0] = data;
181 inc->m_ptr = 1;
182 do_midi_msg(dev, inc->m_buf, inc->m_ptr);
183 inc->m_ptr = 0;
184 inc->m_left = 0;
185 }
186 } else
187 {
188 inc->m_state = MST_DATA;
189 inc->m_ptr = 1;
190 inc->m_left = len_tab[(data >> 4) - 8];
191 inc->m_buf[0] = inc->m_prev_status = data;
192 }
193 } else if (inc->m_prev_status & 0x80) {
194 /* Data byte (use running status) */
195 inc->m_ptr = 2;
196 inc->m_buf[1] = data;
197 inc->m_buf[0] = inc->m_prev_status;
198 inc->m_left = len_tab[(inc->m_buf[0] >> 4) - 8] - 1;
199 if (inc->m_left > 0)
200 inc->m_state = MST_DATA; /* Not done yet */
201 else {
202 inc->m_state = MST_INIT;
203 do_midi_msg(dev, inc->m_buf, inc->m_ptr);
204 inc->m_ptr = 0;
205 }
206 }
207 break; /* MST_INIT */
208
209 case MST_DATA:
210 inc->m_buf[inc->m_ptr++] = data;
211 if (--inc->m_left <= 0)
212 {
213 inc->m_state = MST_INIT;
214 do_midi_msg(dev, inc->m_buf, inc->m_ptr);
215 inc->m_ptr = 0;
216 }
217 break; /* MST_DATA */
218
219 case MST_SYSEX:
220 if (data == 0xf7) /* Sysex end */
221 {
222 inc->m_state = MST_INIT;
223 inc->m_left = 0;
224 inc->m_ptr = 0;
225 }
226 break; /* MST_SYSEX */
227
228 default:
229 printk("MIDI%d: Unexpected state %d (%02x)\n", orig_dev, inc->m_state, (int) data);
230 inc->m_state = MST_INIT;
231 }
232}
233
234static void
235leave_sysex(int dev)
236{
237 int orig_dev = synth_devs[dev]->midi_dev;
238 int timeout = 0;
239
240 if (!sysex_state[dev])
241 return;
242
243 sysex_state[dev] = 0;
244
245 while (!midi_devs[orig_dev]->outputc(orig_dev, 0xf7) &&
246 timeout < 1000)
247 timeout++;
248
249 sysex_state[dev] = 0;
250}
251
252static void
253midi_synth_output(int dev)
254{
255 /*
256 * Currently NOP
257 */
258}
259
260int midi_synth_ioctl(int dev, unsigned int cmd, void __user *arg)
261{
262 /*
263 * int orig_dev = synth_devs[dev]->midi_dev;
264 */
265
266 switch (cmd) {
267
268 case SNDCTL_SYNTH_INFO:
269 if (__copy_to_user(arg, synth_devs[dev]->info, sizeof(struct synth_info)))
270 return -EFAULT;
271 return 0;
272
273 case SNDCTL_SYNTH_MEMAVL:
274 return 0x7fffffff;
275
276 default:
277 return -EINVAL;
278 }
279}
280EXPORT_SYMBOL(midi_synth_ioctl);
281
282int
283midi_synth_kill_note(int dev, int channel, int note, int velocity)
284{
285 int orig_dev = synth_devs[dev]->midi_dev;
286 int msg, chn;
287
288 if (note < 0 || note > 127)
289 return 0;
290 if (channel < 0 || channel > 15)
291 return 0;
292 if (velocity < 0)
293 velocity = 0;
294 if (velocity > 127)
295 velocity = 127;
296
297 leave_sysex(dev);
298
299 msg = prev_out_status[orig_dev] & 0xf0;
300 chn = prev_out_status[orig_dev] & 0x0f;
301
302 if (chn == channel && ((msg == 0x90 && velocity == 64) || msg == 0x80))
303 { /*
304 * Use running status
305 */
306 if (!prefix_cmd(orig_dev, note))
307 return 0;
308
309 midi_outc(orig_dev, note);
310
311 if (msg == 0x90) /*
312 * Running status = Note on
313 */
314 midi_outc(orig_dev, 0); /*
315 * Note on with velocity 0 == note
316 * off
317 */
318 else
319 midi_outc(orig_dev, velocity);
320 } else
321 {
322 if (velocity == 64)
323 {
324 if (!prefix_cmd(orig_dev, 0x90 | (channel & 0x0f)))
325 return 0;
326 midi_outc(orig_dev, 0x90 | (channel & 0x0f)); /*
327 * Note on
328 */
329 midi_outc(orig_dev, note);
330 midi_outc(orig_dev, 0); /*
331 * Zero G
332 */
333 } else
334 {
335 if (!prefix_cmd(orig_dev, 0x80 | (channel & 0x0f)))
336 return 0;
337 midi_outc(orig_dev, 0x80 | (channel & 0x0f)); /*
338 * Note off
339 */
340 midi_outc(orig_dev, note);
341 midi_outc(orig_dev, velocity);
342 }
343 }
344
345 return 0;
346}
347EXPORT_SYMBOL(midi_synth_kill_note);
348
349int
350midi_synth_set_instr(int dev, int channel, int instr_no)
351{
352 int orig_dev = synth_devs[dev]->midi_dev;
353
354 if (instr_no < 0 || instr_no > 127)
355 instr_no = 0;
356 if (channel < 0 || channel > 15)
357 return 0;
358
359 leave_sysex(dev);
360
361 if (!prefix_cmd(orig_dev, 0xc0 | (channel & 0x0f)))
362 return 0;
363 midi_outc(orig_dev, 0xc0 | (channel & 0x0f)); /*
364 * Program change
365 */
366 midi_outc(orig_dev, instr_no);
367
368 return 0;
369}
370EXPORT_SYMBOL(midi_synth_set_instr);
371
372int
373midi_synth_start_note(int dev, int channel, int note, int velocity)
374{
375 int orig_dev = synth_devs[dev]->midi_dev;
376 int msg, chn;
377
378 if (note < 0 || note > 127)
379 return 0;
380 if (channel < 0 || channel > 15)
381 return 0;
382 if (velocity < 0)
383 velocity = 0;
384 if (velocity > 127)
385 velocity = 127;
386
387 leave_sysex(dev);
388
389 msg = prev_out_status[orig_dev] & 0xf0;
390 chn = prev_out_status[orig_dev] & 0x0f;
391
392 if (chn == channel && msg == 0x90)
393 { /*
394 * Use running status
395 */
396 if (!prefix_cmd(orig_dev, note))
397 return 0;
398 midi_outc(orig_dev, note);
399 midi_outc(orig_dev, velocity);
400 } else
401 {
402 if (!prefix_cmd(orig_dev, 0x90 | (channel & 0x0f)))
403 return 0;
404 midi_outc(orig_dev, 0x90 | (channel & 0x0f)); /*
405 * Note on
406 */
407 midi_outc(orig_dev, note);
408 midi_outc(orig_dev, velocity);
409 }
410 return 0;
411}
412EXPORT_SYMBOL(midi_synth_start_note);
413
414void
415midi_synth_reset(int dev)
416{
417
418 leave_sysex(dev);
419}
420EXPORT_SYMBOL(midi_synth_reset);
421
422int
423midi_synth_open(int dev, int mode)
424{
425 int orig_dev = synth_devs[dev]->midi_dev;
426 int err;
427 struct midi_input_info *inc;
428
429 if (orig_dev < 0 || orig_dev >= num_midis || midi_devs[orig_dev] == NULL)
430 return -ENXIO;
431
432 midi2synth[orig_dev] = dev;
433 sysex_state[dev] = 0;
434 prev_out_status[orig_dev] = 0;
435
436 if ((err = midi_devs[orig_dev]->open(orig_dev, mode,
437 midi_synth_input, midi_synth_output)) < 0)
438 return err;
439 inc = &midi_devs[orig_dev]->in_info;
440
441 /* save_flags(flags);
442 cli();
443 don't know against what irqhandler to protect*/
444 inc->m_busy = 0;
445 inc->m_state = MST_INIT;
446 inc->m_ptr = 0;
447 inc->m_left = 0;
448 inc->m_prev_status = 0x00;
449 /* restore_flags(flags); */
450
451 return 1;
452}
453EXPORT_SYMBOL(midi_synth_open);
454
455void
456midi_synth_close(int dev)
457{
458 int orig_dev = synth_devs[dev]->midi_dev;
459
460 leave_sysex(dev);
461
462 /*
463 * Shut up the synths by sending just single active sensing message.
464 */
465 midi_devs[orig_dev]->outputc(orig_dev, 0xfe);
466
467 midi_devs[orig_dev]->close(orig_dev);
468}
469EXPORT_SYMBOL(midi_synth_close);
470
471void
472midi_synth_hw_control(int dev, unsigned char *event)
473{
474}
475EXPORT_SYMBOL(midi_synth_hw_control);
476
477int
478midi_synth_load_patch(int dev, int format, const char __user *addr,
479 int count, int pmgr_flag)
480{
481 int orig_dev = synth_devs[dev]->midi_dev;
482
483 struct sysex_info sysex;
484 int i;
485 unsigned long left, src_offs, eox_seen = 0;
486 int first_byte = 1;
487 int hdr_size = (unsigned long) &sysex.data[0] - (unsigned long) &sysex;
488
489 leave_sysex(dev);
490
491 if (!prefix_cmd(orig_dev, 0xf0))
492 return 0;
493
494 /* Invalid patch format */
495 if (format != SYSEX_PATCH)
496 return -EINVAL;
497
498 /* Patch header too short */
499 if (count < hdr_size)
500 return -EINVAL;
501
502 count -= hdr_size;
503
504 /*
505 * Copy the header from user space
506 */
507
508 if (copy_from_user(&sysex, addr, hdr_size))
509 return -EFAULT;
510
511 /* Sysex record too short */
512 if ((unsigned)count < (unsigned)sysex.len)
513 sysex.len = count;
514
515 left = sysex.len;
516 src_offs = 0;
517
518 for (i = 0; i < left && !signal_pending(current); i++)
519 {
520 unsigned char data;
521
522 if (get_user(data,
523 (unsigned char __user *)(addr + hdr_size + i)))
524 return -EFAULT;
525
526 eox_seen = (i > 0 && data & 0x80); /* End of sysex */
527
528 if (eox_seen && data != 0xf7)
529 data = 0xf7;
530
531 if (i == 0)
532 {
533 if (data != 0xf0)
534 {
535 printk(KERN_WARNING "midi_synth: Sysex start missing\n");
536 return -EINVAL;
537 }
538 }
539 while (!midi_devs[orig_dev]->outputc(orig_dev, (unsigned char) (data & 0xff)) &&
540 !signal_pending(current))
541 schedule();
542
543 if (!first_byte && data & 0x80)
544 return 0;
545 first_byte = 0;
546 }
547
548 if (!eox_seen)
549 midi_outc(orig_dev, 0xf7);
550 return 0;
551}
552EXPORT_SYMBOL(midi_synth_load_patch);
553
554void midi_synth_panning(int dev, int channel, int pressure)
555{
556}
557EXPORT_SYMBOL(midi_synth_panning);
558
559void midi_synth_aftertouch(int dev, int channel, int pressure)
560{
561 int orig_dev = synth_devs[dev]->midi_dev;
562 int msg, chn;
563
564 if (pressure < 0 || pressure > 127)
565 return;
566 if (channel < 0 || channel > 15)
567 return;
568
569 leave_sysex(dev);
570
571 msg = prev_out_status[orig_dev] & 0xf0;
572 chn = prev_out_status[orig_dev] & 0x0f;
573
574 if (msg != 0xd0 || chn != channel) /*
575 * Test for running status
576 */
577 {
578 if (!prefix_cmd(orig_dev, 0xd0 | (channel & 0x0f)))
579 return;
580 midi_outc(orig_dev, 0xd0 | (channel & 0x0f)); /*
581 * Channel pressure
582 */
583 } else if (!prefix_cmd(orig_dev, pressure))
584 return;
585
586 midi_outc(orig_dev, pressure);
587}
588EXPORT_SYMBOL(midi_synth_aftertouch);
589
590void
591midi_synth_controller(int dev, int channel, int ctrl_num, int value)
592{
593 int orig_dev = synth_devs[dev]->midi_dev;
594 int chn, msg;
595
596 if (ctrl_num < 0 || ctrl_num > 127)
597 return;
598 if (channel < 0 || channel > 15)
599 return;
600
601 leave_sysex(dev);
602
603 msg = prev_out_status[orig_dev] & 0xf0;
604 chn = prev_out_status[orig_dev] & 0x0f;
605
606 if (msg != 0xb0 || chn != channel)
607 {
608 if (!prefix_cmd(orig_dev, 0xb0 | (channel & 0x0f)))
609 return;
610 midi_outc(orig_dev, 0xb0 | (channel & 0x0f));
611 } else if (!prefix_cmd(orig_dev, ctrl_num))
612 return;
613
614 midi_outc(orig_dev, ctrl_num);
615 midi_outc(orig_dev, value & 0x7f);
616}
617EXPORT_SYMBOL(midi_synth_controller);
618
619void
620midi_synth_bender(int dev, int channel, int value)
621{
622 int orig_dev = synth_devs[dev]->midi_dev;
623 int msg, prev_chn;
624
625 if (channel < 0 || channel > 15)
626 return;
627
628 if (value < 0 || value > 16383)
629 return;
630
631 leave_sysex(dev);
632
633 msg = prev_out_status[orig_dev] & 0xf0;
634 prev_chn = prev_out_status[orig_dev] & 0x0f;
635
636 if (msg != 0xd0 || prev_chn != channel) /*
637 * Test for running status
638 */
639 {
640 if (!prefix_cmd(orig_dev, 0xe0 | (channel & 0x0f)))
641 return;
642 midi_outc(orig_dev, 0xe0 | (channel & 0x0f));
643 } else if (!prefix_cmd(orig_dev, value & 0x7f))
644 return;
645
646 midi_outc(orig_dev, value & 0x7f);
647 midi_outc(orig_dev, (value >> 7) & 0x7f);
648}
649EXPORT_SYMBOL(midi_synth_bender);
650
651void
652midi_synth_setup_voice(int dev, int voice, int channel)
653{
654}
655EXPORT_SYMBOL(midi_synth_setup_voice);
656
657int
658midi_synth_send_sysex(int dev, unsigned char *bytes, int len)
659{
660 int orig_dev = synth_devs[dev]->midi_dev;
661 int i;
662
663 for (i = 0; i < len; i++)
664 {
665 switch (bytes[i])
666 {
667 case 0xf0: /* Start sysex */
668 if (!prefix_cmd(orig_dev, 0xf0))
669 return 0;
670 sysex_state[dev] = 1;
671 break;
672
673 case 0xf7: /* End sysex */
674 if (!sysex_state[dev]) /* Orphan sysex end */
675 return 0;
676 sysex_state[dev] = 0;
677 break;
678
679 default:
680 if (!sysex_state[dev])
681 return 0;
682
683 if (bytes[i] & 0x80) /* Error. Another message before sysex end */
684 {
685 bytes[i] = 0xf7; /* Sysex end */
686 sysex_state[dev] = 0;
687 }
688 }
689
690 if (!midi_devs[orig_dev]->outputc(orig_dev, bytes[i]))
691 {
692/*
693 * Hardware level buffer is full. Abort the sysex message.
694 */
695
696 int timeout = 0;
697
698 bytes[i] = 0xf7;
699 sysex_state[dev] = 0;
700
701 while (!midi_devs[orig_dev]->outputc(orig_dev, bytes[i]) &&
702 timeout < 1000)
703 timeout++;
704 }
705 if (!sysex_state[dev])
706 return 0;
707 }
708
709 return 0;
710}
711EXPORT_SYMBOL(midi_synth_send_sysex);
712
diff --git a/sound/oss/midi_synth.h b/sound/oss/midi_synth.h
deleted file mode 100644
index 1cf676c7510e..000000000000
--- a/sound/oss/midi_synth.h
+++ /dev/null
@@ -1,48 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2int midi_synth_ioctl (int dev,
3 unsigned int cmd, void __user * arg);
4int midi_synth_kill_note (int dev, int channel, int note, int velocity);
5int midi_synth_set_instr (int dev, int channel, int instr_no);
6int midi_synth_start_note (int dev, int channel, int note, int volume);
7void midi_synth_reset (int dev);
8int midi_synth_open (int dev, int mode);
9void midi_synth_close (int dev);
10void midi_synth_hw_control (int dev, unsigned char *event);
11int midi_synth_load_patch (int dev, int format, const char __user * addr,
12 int count, int pmgr_flag);
13void midi_synth_panning (int dev, int channel, int pressure);
14void midi_synth_aftertouch (int dev, int channel, int pressure);
15void midi_synth_controller (int dev, int channel, int ctrl_num, int value);
16void midi_synth_bender (int dev, int chn, int value);
17void midi_synth_setup_voice (int dev, int voice, int chn);
18int midi_synth_send_sysex(int dev, unsigned char *bytes,int len);
19
20#ifndef _MIDI_SYNTH_C_
21static struct synth_info std_synth_info =
22{MIDI_SYNTH_NAME, 0, SYNTH_TYPE_MIDI, 0, 0, 128, 0, 128, MIDI_SYNTH_CAPS};
23
24static struct synth_operations std_midi_synth =
25{
26 .owner = THIS_MODULE,
27 .id = "MIDI",
28 .info = &std_synth_info,
29 .midi_dev = 0,
30 .synth_type = SYNTH_TYPE_MIDI,
31 .synth_subtype = 0,
32 .open = midi_synth_open,
33 .close = midi_synth_close,
34 .ioctl = midi_synth_ioctl,
35 .kill_note = midi_synth_kill_note,
36 .start_note = midi_synth_start_note,
37 .set_instr = midi_synth_set_instr,
38 .reset = midi_synth_reset,
39 .hw_control = midi_synth_hw_control,
40 .load_patch = midi_synth_load_patch,
41 .aftertouch = midi_synth_aftertouch,
42 .controller = midi_synth_controller,
43 .panning = midi_synth_panning,
44 .bender = midi_synth_bender,
45 .setup_voice = midi_synth_setup_voice,
46 .send_sysex = midi_synth_send_sysex
47};
48#endif
diff --git a/sound/oss/midibuf.c b/sound/oss/midibuf.c
deleted file mode 100644
index 1277df815d5b..000000000000
--- a/sound/oss/midibuf.c
+++ /dev/null
@@ -1,427 +0,0 @@
1/*
2 * sound/oss/midibuf.c
3 *
4 * Device file manager for /dev/midi#
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 */
13/*
14 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
15 */
16#include <linux/stddef.h>
17#include <linux/kmod.h>
18#include <linux/spinlock.h>
19#include <linux/sched/signal.h>
20
21#define MIDIBUF_C
22
23#include "sound_config.h"
24
25
26/*
27 * Don't make MAX_QUEUE_SIZE larger than 4000
28 */
29
30#define MAX_QUEUE_SIZE 4000
31
32static wait_queue_head_t midi_sleeper[MAX_MIDI_DEV];
33static wait_queue_head_t input_sleeper[MAX_MIDI_DEV];
34
35struct midi_buf
36{
37 int len, head, tail;
38 unsigned char queue[MAX_QUEUE_SIZE];
39};
40
41struct midi_parms
42{
43 long prech_timeout; /*
44 * Timeout before the first ch
45 */
46};
47
48static struct midi_buf *midi_out_buf[MAX_MIDI_DEV] = {NULL};
49static struct midi_buf *midi_in_buf[MAX_MIDI_DEV] = {NULL};
50static struct midi_parms parms[MAX_MIDI_DEV];
51
52static void midi_poll(unsigned long dummy);
53
54
55static DEFINE_TIMER(poll_timer, midi_poll);
56
57static volatile int open_devs;
58static DEFINE_SPINLOCK(lock);
59
60#define DATA_AVAIL(q) (q->len)
61#define SPACE_AVAIL(q) (MAX_QUEUE_SIZE - q->len)
62
63#define QUEUE_BYTE(q, data) \
64 if (SPACE_AVAIL(q)) \
65 { \
66 unsigned long flags; \
67 spin_lock_irqsave(&lock, flags); \
68 q->queue[q->tail] = (data); \
69 q->len++; q->tail = (q->tail+1) % MAX_QUEUE_SIZE; \
70 spin_unlock_irqrestore(&lock, flags); \
71 }
72
73#define REMOVE_BYTE(q, data) \
74 if (DATA_AVAIL(q)) \
75 { \
76 unsigned long flags; \
77 spin_lock_irqsave(&lock, flags); \
78 data = q->queue[q->head]; \
79 q->len--; q->head = (q->head+1) % MAX_QUEUE_SIZE; \
80 spin_unlock_irqrestore(&lock, flags); \
81 }
82
83static void drain_midi_queue(int dev)
84{
85
86 /*
87 * Give the Midi driver time to drain its output queues
88 */
89
90 if (midi_devs[dev]->buffer_status != NULL)
91 wait_event_interruptible_timeout(midi_sleeper[dev],
92 !midi_devs[dev]->buffer_status(dev), HZ/10);
93}
94
95static void midi_input_intr(int dev, unsigned char data)
96{
97 if (midi_in_buf[dev] == NULL)
98 return;
99
100 if (data == 0xfe) /*
101 * Active sensing
102 */
103 return; /*
104 * Ignore
105 */
106
107 if (SPACE_AVAIL(midi_in_buf[dev])) {
108 QUEUE_BYTE(midi_in_buf[dev], data);
109 wake_up(&input_sleeper[dev]);
110 }
111}
112
113static void midi_output_intr(int dev)
114{
115 /*
116 * Currently NOP
117 */
118}
119
120static void midi_poll(unsigned long dummy)
121{
122 unsigned long flags;
123 int dev;
124
125 spin_lock_irqsave(&lock, flags);
126 if (open_devs)
127 {
128 for (dev = 0; dev < num_midis; dev++)
129 if (midi_devs[dev] != NULL && midi_out_buf[dev] != NULL)
130 {
131 while (DATA_AVAIL(midi_out_buf[dev]))
132 {
133 int ok;
134 int c = midi_out_buf[dev]->queue[midi_out_buf[dev]->head];
135
136 spin_unlock_irqrestore(&lock,flags);/* Give some time to others */
137 ok = midi_devs[dev]->outputc(dev, c);
138 spin_lock_irqsave(&lock, flags);
139 if (!ok)
140 break;
141 midi_out_buf[dev]->head = (midi_out_buf[dev]->head + 1) % MAX_QUEUE_SIZE;
142 midi_out_buf[dev]->len--;
143 }
144
145 if (DATA_AVAIL(midi_out_buf[dev]) < 100)
146 wake_up(&midi_sleeper[dev]);
147 }
148 poll_timer.expires = (1) + jiffies;
149 add_timer(&poll_timer);
150 /*
151 * Come back later
152 */
153 }
154 spin_unlock_irqrestore(&lock, flags);
155}
156
157int MIDIbuf_open(int dev, struct file *file)
158{
159 int mode, err;
160
161 dev = dev >> 4;
162 mode = translate_mode(file);
163
164 if (num_midis > MAX_MIDI_DEV)
165 {
166 printk(KERN_ERR "midi: Too many midi interfaces\n");
167 num_midis = MAX_MIDI_DEV;
168 }
169 if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL)
170 return -ENXIO;
171 /*
172 * Interrupts disabled. Be careful
173 */
174
175 module_put(midi_devs[dev]->owner);
176
177 if ((err = midi_devs[dev]->open(dev, mode,
178 midi_input_intr, midi_output_intr)) < 0)
179 return err;
180
181 parms[dev].prech_timeout = MAX_SCHEDULE_TIMEOUT;
182 midi_in_buf[dev] = vmalloc(sizeof(struct midi_buf));
183
184 if (midi_in_buf[dev] == NULL)
185 {
186 printk(KERN_WARNING "midi: Can't allocate buffer\n");
187 midi_devs[dev]->close(dev);
188 return -EIO;
189 }
190 midi_in_buf[dev]->len = midi_in_buf[dev]->head = midi_in_buf[dev]->tail = 0;
191
192 midi_out_buf[dev] = vmalloc(sizeof(struct midi_buf));
193
194 if (midi_out_buf[dev] == NULL)
195 {
196 printk(KERN_WARNING "midi: Can't allocate buffer\n");
197 midi_devs[dev]->close(dev);
198 vfree(midi_in_buf[dev]);
199 midi_in_buf[dev] = NULL;
200 return -EIO;
201 }
202 midi_out_buf[dev]->len = midi_out_buf[dev]->head = midi_out_buf[dev]->tail = 0;
203 open_devs++;
204
205 init_waitqueue_head(&midi_sleeper[dev]);
206 init_waitqueue_head(&input_sleeper[dev]);
207
208 if (open_devs < 2) /* This was first open */
209 {
210 poll_timer.expires = 1 + jiffies;
211 add_timer(&poll_timer); /* Start polling */
212 }
213 return err;
214}
215
216void MIDIbuf_release(int dev, struct file *file)
217{
218 int mode;
219
220 dev = dev >> 4;
221 mode = translate_mode(file);
222
223 if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL)
224 return;
225
226 /*
227 * Wait until the queue is empty
228 */
229
230 if (mode != OPEN_READ)
231 {
232 midi_devs[dev]->outputc(dev, 0xfe); /*
233 * Active sensing to shut the
234 * devices
235 */
236
237 wait_event_interruptible(midi_sleeper[dev],
238 !DATA_AVAIL(midi_out_buf[dev]));
239 /*
240 * Sync
241 */
242
243 drain_midi_queue(dev); /*
244 * Ensure the output queues are empty
245 */
246 }
247
248 midi_devs[dev]->close(dev);
249
250 open_devs--;
251 if (open_devs == 0)
252 del_timer_sync(&poll_timer);
253 vfree(midi_in_buf[dev]);
254 vfree(midi_out_buf[dev]);
255 midi_in_buf[dev] = NULL;
256 midi_out_buf[dev] = NULL;
257
258 module_put(midi_devs[dev]->owner);
259}
260
261int MIDIbuf_write(int dev, struct file *file, const char __user *buf, int count)
262{
263 int c, n, i;
264 unsigned char tmp_data;
265
266 dev = dev >> 4;
267
268 if (!count)
269 return 0;
270
271 c = 0;
272
273 while (c < count)
274 {
275 n = SPACE_AVAIL(midi_out_buf[dev]);
276
277 if (n == 0) { /*
278 * No space just now.
279 */
280
281 if (file->f_flags & O_NONBLOCK) {
282 c = -EAGAIN;
283 goto out;
284 }
285
286 if (wait_event_interruptible(midi_sleeper[dev],
287 SPACE_AVAIL(midi_out_buf[dev])))
288 {
289 c = -EINTR;
290 goto out;
291 }
292 n = SPACE_AVAIL(midi_out_buf[dev]);
293 }
294 if (n > (count - c))
295 n = count - c;
296
297 for (i = 0; i < n; i++)
298 {
299 /* BROKE BROKE BROKE - CAN'T DO THIS WITH CLI !! */
300 /* yes, think the same, so I removed the cli() brackets
301 QUEUE_BYTE is protected against interrupts */
302 if (copy_from_user((char *) &tmp_data, &(buf)[c], 1)) {
303 c = -EFAULT;
304 goto out;
305 }
306 QUEUE_BYTE(midi_out_buf[dev], tmp_data);
307 c++;
308 }
309 }
310out:
311 return c;
312}
313
314
315int MIDIbuf_read(int dev, struct file *file, char __user *buf, int count)
316{
317 int n, c = 0;
318 unsigned char tmp_data;
319
320 dev = dev >> 4;
321
322 if (!DATA_AVAIL(midi_in_buf[dev])) { /*
323 * No data yet, wait
324 */
325 if (file->f_flags & O_NONBLOCK) {
326 c = -EAGAIN;
327 goto out;
328 }
329 wait_event_interruptible_timeout(input_sleeper[dev],
330 DATA_AVAIL(midi_in_buf[dev]),
331 parms[dev].prech_timeout);
332
333 if (signal_pending(current))
334 c = -EINTR; /* The user is getting restless */
335 }
336 if (c == 0 && DATA_AVAIL(midi_in_buf[dev])) /*
337 * Got some bytes
338 */
339 {
340 n = DATA_AVAIL(midi_in_buf[dev]);
341 if (n > count)
342 n = count;
343 c = 0;
344
345 while (c < n)
346 {
347 char *fixit;
348 REMOVE_BYTE(midi_in_buf[dev], tmp_data);
349 fixit = (char *) &tmp_data;
350 /* BROKE BROKE BROKE */
351 /* yes removed the cli() brackets again
352 should q->len,tail&head be atomic_t? */
353 if (copy_to_user(&(buf)[c], fixit, 1)) {
354 c = -EFAULT;
355 goto out;
356 }
357 c++;
358 }
359 }
360out:
361 return c;
362}
363
364int MIDIbuf_ioctl(int dev, struct file *file,
365 unsigned int cmd, void __user *arg)
366{
367 int val;
368
369 dev = dev >> 4;
370
371 if (((cmd >> 8) & 0xff) == 'C')
372 {
373 if (midi_devs[dev]->coproc) /* Coprocessor ioctl */
374 return midi_devs[dev]->coproc->ioctl(midi_devs[dev]->coproc->devc, cmd, arg, 0);
375/* printk("/dev/midi%d: No coprocessor for this device\n", dev);*/
376 return -ENXIO;
377 }
378 else
379 {
380 switch (cmd)
381 {
382 case SNDCTL_MIDI_PRETIME:
383 if (get_user(val, (int __user *)arg))
384 return -EFAULT;
385 if (val < 0)
386 val = 0;
387 val = (HZ * val) / 10;
388 parms[dev].prech_timeout = val;
389 return put_user(val, (int __user *)arg);
390
391 default:
392 if (!midi_devs[dev]->ioctl)
393 return -EINVAL;
394 return midi_devs[dev]->ioctl(dev, cmd, arg);
395 }
396 }
397}
398
399/* No kernel lock - fine */
400unsigned int MIDIbuf_poll(int dev, struct file *file, poll_table * wait)
401{
402 unsigned int mask = 0;
403
404 dev = dev >> 4;
405
406 /* input */
407 poll_wait(file, &input_sleeper[dev], wait);
408 if (DATA_AVAIL(midi_in_buf[dev]))
409 mask |= POLLIN | POLLRDNORM;
410
411 /* output */
412 poll_wait(file, &midi_sleeper[dev], wait);
413 if (!SPACE_AVAIL(midi_out_buf[dev]))
414 mask |= POLLOUT | POLLWRNORM;
415
416 return mask;
417}
418
419
420int MIDIbuf_avail(int dev)
421{
422 if (midi_in_buf[dev])
423 return DATA_AVAIL (midi_in_buf[dev]);
424 return 0;
425}
426EXPORT_SYMBOL(MIDIbuf_avail);
427
diff --git a/sound/oss/mpu401.c b/sound/oss/mpu401.c
deleted file mode 100644
index 20e8fa46f647..000000000000
--- a/sound/oss/mpu401.c
+++ /dev/null
@@ -1,1804 +0,0 @@
1/*
2 * sound/oss/mpu401.c
3 *
4 * The low level driver for Roland MPU-401 compatible Midi cards.
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Thomas Sailer ioctl code reworked (vmalloc/vfree removed)
15 * Alan Cox modularisation, use normal request_irq, use dev_id
16 * Bartlomiej Zolnierkiewicz removed some __init to allow using many drivers
17 * Chris Rankin Update the module-usage counter for the coprocessor
18 * Zwane Mwaikambo Changed attach/unload resource freeing
19 */
20
21#include <linux/module.h>
22#include <linux/slab.h>
23#include <linux/init.h>
24#include <linux/interrupt.h>
25#include <linux/spinlock.h>
26#define USE_SEQ_MACROS
27#define USE_SIMPLE_MACROS
28
29#include "sound_config.h"
30
31#include "coproc.h"
32#include "mpu401.h"
33
34static int timer_mode = TMR_INTERNAL, timer_caps = TMR_INTERNAL;
35
36struct mpu_config
37{
38 int base; /*
39 * I/O base
40 */
41 int irq;
42 int opened; /*
43 * Open mode
44 */
45 int devno;
46 int synthno;
47 int uart_mode;
48 int initialized;
49 int mode;
50#define MODE_MIDI 1
51#define MODE_SYNTH 2
52 unsigned char version, revision;
53 unsigned int capabilities;
54#define MPU_CAP_INTLG 0x10000000
55#define MPU_CAP_SYNC 0x00000010
56#define MPU_CAP_FSK 0x00000020
57#define MPU_CAP_CLS 0x00000040
58#define MPU_CAP_SMPTE 0x00000080
59#define MPU_CAP_2PORT 0x00000001
60 int timer_flag;
61
62#define MBUF_MAX 10
63#define BUFTEST(dc) if (dc->m_ptr >= MBUF_MAX || dc->m_ptr < 0) \
64 {printk( "MPU: Invalid buffer pointer %d/%d, s=%d\n", dc->m_ptr, dc->m_left, dc->m_state);dc->m_ptr--;}
65 int m_busy;
66 unsigned char m_buf[MBUF_MAX];
67 int m_ptr;
68 int m_state;
69 int m_left;
70 unsigned char last_status;
71 void (*inputintr) (int dev, unsigned char data);
72 int shared_irq;
73 int *osp;
74 spinlock_t lock;
75 };
76
77#define DATAPORT(base) (base)
78#define COMDPORT(base) (base+1)
79#define STATPORT(base) (base+1)
80
81
82static void mpu401_close(int dev);
83
84static inline int mpu401_status(struct mpu_config *devc)
85{
86 return inb(STATPORT(devc->base));
87}
88
89#define input_avail(devc) (!(mpu401_status(devc)&INPUT_AVAIL))
90#define output_ready(devc) (!(mpu401_status(devc)&OUTPUT_READY))
91
92static inline void write_command(struct mpu_config *devc, unsigned char cmd)
93{
94 outb(cmd, COMDPORT(devc->base));
95}
96
97static inline int read_data(struct mpu_config *devc)
98{
99 return inb(DATAPORT(devc->base));
100}
101
102static inline void write_data(struct mpu_config *devc, unsigned char byte)
103{
104 outb(byte, DATAPORT(devc->base));
105}
106
107#define OUTPUT_READY 0x40
108#define INPUT_AVAIL 0x80
109#define MPU_ACK 0xFE
110#define MPU_RESET 0xFF
111#define UART_MODE_ON 0x3F
112
113static struct mpu_config dev_conf[MAX_MIDI_DEV];
114
115static int n_mpu_devs;
116
117static int reset_mpu401(struct mpu_config *devc);
118static void set_uart_mode(int dev, struct mpu_config *devc, int arg);
119
120static int mpu_timer_init(int midi_dev);
121static void mpu_timer_interrupt(void);
122static void timer_ext_event(struct mpu_config *devc, int event, int parm);
123
124static struct synth_info mpu_synth_info_proto = {
125 "MPU-401 MIDI interface",
126 0,
127 SYNTH_TYPE_MIDI,
128 MIDI_TYPE_MPU401,
129 0, 128,
130 0, 128,
131 SYNTH_CAP_INPUT
132};
133
134static struct synth_info mpu_synth_info[MAX_MIDI_DEV];
135
136/*
137 * States for the input scanner
138 */
139
140#define ST_INIT 0 /* Ready for timing byte or msg */
141#define ST_TIMED 1 /* Leading timing byte rcvd */
142#define ST_DATABYTE 2 /* Waiting for (nr_left) data bytes */
143
144#define ST_SYSMSG 100 /* System message (sysx etc). */
145#define ST_SYSEX 101 /* System exclusive msg */
146#define ST_MTC 102 /* Midi Time Code (MTC) qframe msg */
147#define ST_SONGSEL 103 /* Song select */
148#define ST_SONGPOS 104 /* Song position pointer */
149
150static unsigned char len_tab[] = /* # of data bytes following a status
151 */
152{
153 2, /* 8x */
154 2, /* 9x */
155 2, /* Ax */
156 2, /* Bx */
157 1, /* Cx */
158 1, /* Dx */
159 2, /* Ex */
160 0 /* Fx */
161};
162
163#define STORE(cmd) \
164{ \
165 int len; \
166 unsigned char obuf[8]; \
167 cmd; \
168 seq_input_event(obuf, len); \
169}
170
171#define _seqbuf obuf
172#define _seqbufptr 0
173#define _SEQ_ADVBUF(x) len=x
174
175static int mpu_input_scanner(struct mpu_config *devc, unsigned char midic)
176{
177
178 switch (devc->m_state)
179 {
180 case ST_INIT:
181 switch (midic)
182 {
183 case 0xf8:
184 /* Timer overflow */
185 break;
186
187 case 0xfc:
188 printk("<all end>");
189 break;
190
191 case 0xfd:
192 if (devc->timer_flag)
193 mpu_timer_interrupt();
194 break;
195
196 case 0xfe:
197 return MPU_ACK;
198
199 case 0xf0:
200 case 0xf1:
201 case 0xf2:
202 case 0xf3:
203 case 0xf4:
204 case 0xf5:
205 case 0xf6:
206 case 0xf7:
207 printk("<Trk data rq #%d>", midic & 0x0f);
208 break;
209
210 case 0xf9:
211 printk("<conductor rq>");
212 break;
213
214 case 0xff:
215 devc->m_state = ST_SYSMSG;
216 break;
217
218 default:
219 if (midic <= 0xef)
220 {
221 /* printk( "mpu time: %d ", midic); */
222 devc->m_state = ST_TIMED;
223 }
224 else
225 printk("<MPU: Unknown event %02x> ", midic);
226 }
227 break;
228
229 case ST_TIMED:
230 {
231 int msg = ((int) (midic & 0xf0) >> 4);
232
233 devc->m_state = ST_DATABYTE;
234
235 if (msg < 8) /* Data byte */
236 {
237 /* printk( "midi msg (running status) "); */
238 msg = ((int) (devc->last_status & 0xf0) >> 4);
239 msg -= 8;
240 devc->m_left = len_tab[msg] - 1;
241
242 devc->m_ptr = 2;
243 devc->m_buf[0] = devc->last_status;
244 devc->m_buf[1] = midic;
245
246 if (devc->m_left <= 0)
247 {
248 devc->m_state = ST_INIT;
249 do_midi_msg(devc->synthno, devc->m_buf, devc->m_ptr);
250 devc->m_ptr = 0;
251 }
252 }
253 else if (msg == 0xf) /* MPU MARK */
254 {
255 devc->m_state = ST_INIT;
256
257 switch (midic)
258 {
259 case 0xf8:
260 /* printk( "NOP "); */
261 break;
262
263 case 0xf9:
264 /* printk( "meas end "); */
265 break;
266
267 case 0xfc:
268 /* printk( "data end "); */
269 break;
270
271 default:
272 printk("Unknown MPU mark %02x\n", midic);
273 }
274 }
275 else
276 {
277 devc->last_status = midic;
278 /* printk( "midi msg "); */
279 msg -= 8;
280 devc->m_left = len_tab[msg];
281
282 devc->m_ptr = 1;
283 devc->m_buf[0] = midic;
284
285 if (devc->m_left <= 0)
286 {
287 devc->m_state = ST_INIT;
288 do_midi_msg(devc->synthno, devc->m_buf, devc->m_ptr);
289 devc->m_ptr = 0;
290 }
291 }
292 }
293 break;
294
295 case ST_SYSMSG:
296 switch (midic)
297 {
298 case 0xf0:
299 printk("<SYX>");
300 devc->m_state = ST_SYSEX;
301 break;
302
303 case 0xf1:
304 devc->m_state = ST_MTC;
305 break;
306
307 case 0xf2:
308 devc->m_state = ST_SONGPOS;
309 devc->m_ptr = 0;
310 break;
311
312 case 0xf3:
313 devc->m_state = ST_SONGSEL;
314 break;
315
316 case 0xf6:
317 /* printk( "tune_request\n"); */
318 devc->m_state = ST_INIT;
319 break;
320
321 /*
322 * Real time messages
323 */
324 case 0xf8:
325 /* midi clock */
326 devc->m_state = ST_INIT;
327 timer_ext_event(devc, TMR_CLOCK, 0);
328 break;
329
330 case 0xfA:
331 devc->m_state = ST_INIT;
332 timer_ext_event(devc, TMR_START, 0);
333 break;
334
335 case 0xFB:
336 devc->m_state = ST_INIT;
337 timer_ext_event(devc, TMR_CONTINUE, 0);
338 break;
339
340 case 0xFC:
341 devc->m_state = ST_INIT;
342 timer_ext_event(devc, TMR_STOP, 0);
343 break;
344
345 case 0xFE:
346 /* active sensing */
347 devc->m_state = ST_INIT;
348 break;
349
350 case 0xff:
351 /* printk( "midi hard reset"); */
352 devc->m_state = ST_INIT;
353 break;
354
355 default:
356 printk("unknown MIDI sysmsg %0x\n", midic);
357 devc->m_state = ST_INIT;
358 }
359 break;
360
361 case ST_MTC:
362 devc->m_state = ST_INIT;
363 printk("MTC frame %x02\n", midic);
364 break;
365
366 case ST_SYSEX:
367 if (midic == 0xf7)
368 {
369 printk("<EOX>");
370 devc->m_state = ST_INIT;
371 }
372 else
373 printk("%02x ", midic);
374 break;
375
376 case ST_SONGPOS:
377 BUFTEST(devc);
378 devc->m_buf[devc->m_ptr++] = midic;
379 if (devc->m_ptr == 2)
380 {
381 devc->m_state = ST_INIT;
382 devc->m_ptr = 0;
383 timer_ext_event(devc, TMR_SPP,
384 ((devc->m_buf[1] & 0x7f) << 7) |
385 (devc->m_buf[0] & 0x7f));
386 }
387 break;
388
389 case ST_DATABYTE:
390 BUFTEST(devc);
391 devc->m_buf[devc->m_ptr++] = midic;
392 if ((--devc->m_left) <= 0)
393 {
394 devc->m_state = ST_INIT;
395 do_midi_msg(devc->synthno, devc->m_buf, devc->m_ptr);
396 devc->m_ptr = 0;
397 }
398 break;
399
400 default:
401 printk("Bad state %d ", devc->m_state);
402 devc->m_state = ST_INIT;
403 }
404 return 1;
405}
406
407static void mpu401_input_loop(struct mpu_config *devc)
408{
409 unsigned long flags;
410 int busy;
411 int n;
412
413 spin_lock_irqsave(&devc->lock,flags);
414 busy = devc->m_busy;
415 devc->m_busy = 1;
416 spin_unlock_irqrestore(&devc->lock,flags);
417
418 if (busy) /* Already inside the scanner */
419 return;
420
421 n = 50;
422
423 while (input_avail(devc) && n-- > 0)
424 {
425 unsigned char c = read_data(devc);
426
427 if (devc->mode == MODE_SYNTH)
428 {
429 mpu_input_scanner(devc, c);
430 }
431 else if (devc->opened & OPEN_READ && devc->inputintr != NULL)
432 devc->inputintr(devc->devno, c);
433 }
434 devc->m_busy = 0;
435}
436
437static irqreturn_t mpuintr(int irq, void *dev_id)
438{
439 struct mpu_config *devc;
440 int dev = (int)(unsigned long) dev_id;
441 int handled = 0;
442
443 devc = &dev_conf[dev];
444
445 if (input_avail(devc))
446 {
447 handled = 1;
448 if (devc->base != 0 && (devc->opened & OPEN_READ || devc->mode == MODE_SYNTH))
449 mpu401_input_loop(devc);
450 else
451 {
452 /* Dummy read (just to acknowledge the interrupt) */
453 read_data(devc);
454 }
455 }
456 return IRQ_RETVAL(handled);
457}
458
459static int mpu401_open(int dev, int mode,
460 void (*input) (int dev, unsigned char data),
461 void (*output) (int dev)
462)
463{
464 int err;
465 struct mpu_config *devc;
466 struct coproc_operations *coprocessor;
467
468 if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL)
469 return -ENXIO;
470
471 devc = &dev_conf[dev];
472
473 if (devc->opened)
474 return -EBUSY;
475 /*
476 * Verify that the device is really running.
477 * Some devices (such as Ensoniq SoundScape don't
478 * work before the on board processor (OBP) is initialized
479 * by downloading its microcode.
480 */
481
482 if (!devc->initialized)
483 {
484 if (mpu401_status(devc) == 0xff) /* Bus float */
485 {
486 printk(KERN_ERR "mpu401: Device not initialized properly\n");
487 return -EIO;
488 }
489 reset_mpu401(devc);
490 }
491
492 if ( (coprocessor = midi_devs[dev]->coproc) != NULL )
493 {
494 if (!try_module_get(coprocessor->owner)) {
495 mpu401_close(dev);
496 return -ENODEV;
497 }
498
499 if ((err = coprocessor->open(coprocessor->devc, COPR_MIDI)) < 0)
500 {
501 printk(KERN_WARNING "MPU-401: Can't access coprocessor device\n");
502 mpu401_close(dev);
503 return err;
504 }
505 }
506
507 set_uart_mode(dev, devc, 1);
508 devc->mode = MODE_MIDI;
509 devc->synthno = 0;
510
511 mpu401_input_loop(devc);
512
513 devc->inputintr = input;
514 devc->opened = mode;
515
516 return 0;
517}
518
519static void mpu401_close(int dev)
520{
521 struct mpu_config *devc;
522 struct coproc_operations *coprocessor;
523
524 devc = &dev_conf[dev];
525 if (devc->uart_mode)
526 reset_mpu401(devc); /*
527 * This disables the UART mode
528 */
529 devc->mode = 0;
530 devc->inputintr = NULL;
531
532 coprocessor = midi_devs[dev]->coproc;
533 if (coprocessor) {
534 coprocessor->close(coprocessor->devc, COPR_MIDI);
535 module_put(coprocessor->owner);
536 }
537 devc->opened = 0;
538}
539
540static int mpu401_out(int dev, unsigned char midi_byte)
541{
542 int timeout;
543 unsigned long flags;
544
545 struct mpu_config *devc;
546
547 devc = &dev_conf[dev];
548
549 /*
550 * Sometimes it takes about 30000 loops before the output becomes ready
551 * (After reset). Normally it takes just about 10 loops.
552 */
553
554 for (timeout = 30000; timeout > 0 && !output_ready(devc); timeout--);
555
556 spin_lock_irqsave(&devc->lock,flags);
557 if (!output_ready(devc))
558 {
559 printk(KERN_WARNING "mpu401: Send data timeout\n");
560 spin_unlock_irqrestore(&devc->lock,flags);
561 return 0;
562 }
563 write_data(devc, midi_byte);
564 spin_unlock_irqrestore(&devc->lock,flags);
565 return 1;
566}
567
568static int mpu401_command(int dev, mpu_command_rec * cmd)
569{
570 int i, timeout, ok;
571 unsigned long flags;
572 struct mpu_config *devc;
573
574 devc = &dev_conf[dev];
575
576 if (devc->uart_mode) /*
577 * Not possible in UART mode
578 */
579 {
580 printk(KERN_WARNING "mpu401: commands not possible in the UART mode\n");
581 return -EINVAL;
582 }
583 /*
584 * Test for input since pending input seems to block the output.
585 */
586 if (input_avail(devc))
587 mpu401_input_loop(devc);
588
589 /*
590 * Sometimes it takes about 50000 loops before the output becomes ready
591 * (After reset). Normally it takes just about 10 loops.
592 */
593
594 timeout = 50000;
595retry:
596 if (timeout-- <= 0)
597 {
598 printk(KERN_WARNING "mpu401: Command (0x%x) timeout\n", (int) cmd->cmd);
599 return -EIO;
600 }
601 spin_lock_irqsave(&devc->lock,flags);
602
603 if (!output_ready(devc))
604 {
605 spin_unlock_irqrestore(&devc->lock,flags);
606 goto retry;
607 }
608 write_command(devc, cmd->cmd);
609
610 ok = 0;
611 for (timeout = 50000; timeout > 0 && !ok; timeout--)
612 {
613 if (input_avail(devc))
614 {
615 if (devc->opened && devc->mode == MODE_SYNTH)
616 {
617 if (mpu_input_scanner(devc, read_data(devc)) == MPU_ACK)
618 ok = 1;
619 }
620 else
621 {
622 /* Device is not currently open. Use simpler method */
623 if (read_data(devc) == MPU_ACK)
624 ok = 1;
625 }
626 }
627 }
628 if (!ok)
629 {
630 spin_unlock_irqrestore(&devc->lock,flags);
631 return -EIO;
632 }
633 if (cmd->nr_args)
634 {
635 for (i = 0; i < cmd->nr_args; i++)
636 {
637 for (timeout = 3000; timeout > 0 && !output_ready(devc); timeout--);
638
639 if (!mpu401_out(dev, cmd->data[i]))
640 {
641 spin_unlock_irqrestore(&devc->lock,flags);
642 printk(KERN_WARNING "mpu401: Command (0x%x), parm send failed.\n", (int) cmd->cmd);
643 return -EIO;
644 }
645 }
646 }
647 cmd->data[0] = 0;
648
649 if (cmd->nr_returns)
650 {
651 for (i = 0; i < cmd->nr_returns; i++)
652 {
653 ok = 0;
654 for (timeout = 5000; timeout > 0 && !ok; timeout--)
655 if (input_avail(devc))
656 {
657 cmd->data[i] = read_data(devc);
658 ok = 1;
659 }
660 if (!ok)
661 {
662 spin_unlock_irqrestore(&devc->lock,flags);
663 return -EIO;
664 }
665 }
666 }
667 spin_unlock_irqrestore(&devc->lock,flags);
668 return 0;
669}
670
671static int mpu_cmd(int dev, int cmd, int data)
672{
673 int ret;
674
675 static mpu_command_rec rec;
676
677 rec.cmd = cmd & 0xff;
678 rec.nr_args = ((cmd & 0xf0) == 0xE0);
679 rec.nr_returns = ((cmd & 0xf0) == 0xA0);
680 rec.data[0] = data & 0xff;
681
682 if ((ret = mpu401_command(dev, &rec)) < 0)
683 return ret;
684 return (unsigned char) rec.data[0];
685}
686
687static int mpu401_prefix_cmd(int dev, unsigned char status)
688{
689 struct mpu_config *devc = &dev_conf[dev];
690
691 if (devc->uart_mode)
692 return 1;
693
694 if (status < 0xf0)
695 {
696 if (mpu_cmd(dev, 0xD0, 0) < 0)
697 return 0;
698 return 1;
699 }
700 switch (status)
701 {
702 case 0xF0:
703 if (mpu_cmd(dev, 0xDF, 0) < 0)
704 return 0;
705 return 1;
706
707 default:
708 return 0;
709 }
710}
711
712static int mpu401_start_read(int dev)
713{
714 return 0;
715}
716
717static int mpu401_end_read(int dev)
718{
719 return 0;
720}
721
722static int mpu401_ioctl(int dev, unsigned cmd, void __user *arg)
723{
724 struct mpu_config *devc;
725 mpu_command_rec rec;
726 int val, ret;
727
728 devc = &dev_conf[dev];
729 switch (cmd)
730 {
731 case SNDCTL_MIDI_MPUMODE:
732 if (!(devc->capabilities & MPU_CAP_INTLG)) { /* No intelligent mode */
733 printk(KERN_WARNING "mpu401: Intelligent mode not supported by the HW\n");
734 return -EINVAL;
735 }
736 if (get_user(val, (int __user *)arg))
737 return -EFAULT;
738 set_uart_mode(dev, devc, !val);
739 return 0;
740
741 case SNDCTL_MIDI_MPUCMD:
742 if (copy_from_user(&rec, arg, sizeof(rec)))
743 return -EFAULT;
744 if ((ret = mpu401_command(dev, &rec)) < 0)
745 return ret;
746 if (copy_to_user(arg, &rec, sizeof(rec)))
747 return -EFAULT;
748 return 0;
749
750 default:
751 return -EINVAL;
752 }
753}
754
755static void mpu401_kick(int dev)
756{
757}
758
759static int mpu401_buffer_status(int dev)
760{
761 return 0; /*
762 * No data in buffers
763 */
764}
765
766static int mpu_synth_ioctl(int dev, unsigned int cmd, void __user *arg)
767{
768 int midi_dev;
769 struct mpu_config *devc;
770
771 midi_dev = synth_devs[dev]->midi_dev;
772
773 if (midi_dev < 0 || midi_dev >= num_midis || midi_devs[midi_dev] == NULL)
774 return -ENXIO;
775
776 devc = &dev_conf[midi_dev];
777
778 switch (cmd)
779 {
780
781 case SNDCTL_SYNTH_INFO:
782 if (copy_to_user(arg, &mpu_synth_info[midi_dev],
783 sizeof(struct synth_info)))
784 return -EFAULT;
785 return 0;
786
787 case SNDCTL_SYNTH_MEMAVL:
788 return 0x7fffffff;
789
790 default:
791 return -EINVAL;
792 }
793}
794
795static int mpu_synth_open(int dev, int mode)
796{
797 int midi_dev, err;
798 struct mpu_config *devc;
799 struct coproc_operations *coprocessor;
800
801 midi_dev = synth_devs[dev]->midi_dev;
802
803 if (midi_dev < 0 || midi_dev > num_midis || midi_devs[midi_dev] == NULL)
804 return -ENXIO;
805
806 devc = &dev_conf[midi_dev];
807
808 /*
809 * Verify that the device is really running.
810 * Some devices (such as Ensoniq SoundScape don't
811 * work before the on board processor (OBP) is initialized
812 * by downloading its microcode.
813 */
814
815 if (!devc->initialized)
816 {
817 if (mpu401_status(devc) == 0xff) /* Bus float */
818 {
819 printk(KERN_ERR "mpu401: Device not initialized properly\n");
820 return -EIO;
821 }
822 reset_mpu401(devc);
823 }
824 if (devc->opened)
825 return -EBUSY;
826 devc->mode = MODE_SYNTH;
827 devc->synthno = dev;
828
829 devc->inputintr = NULL;
830
831 coprocessor = midi_devs[midi_dev]->coproc;
832 if (coprocessor) {
833 if (!try_module_get(coprocessor->owner))
834 return -ENODEV;
835
836 if ((err = coprocessor->open(coprocessor->devc, COPR_MIDI)) < 0)
837 {
838 printk(KERN_WARNING "mpu401: Can't access coprocessor device\n");
839 return err;
840 }
841 }
842 devc->opened = mode;
843 reset_mpu401(devc);
844
845 if (mode & OPEN_READ)
846 {
847 mpu_cmd(midi_dev, 0x8B, 0); /* Enable data in stop mode */
848 mpu_cmd(midi_dev, 0x34, 0); /* Return timing bytes in stop mode */
849 mpu_cmd(midi_dev, 0x87, 0); /* Enable pitch & controller */
850 }
851 return 0;
852}
853
854static void mpu_synth_close(int dev)
855{
856 int midi_dev;
857 struct mpu_config *devc;
858 struct coproc_operations *coprocessor;
859
860 midi_dev = synth_devs[dev]->midi_dev;
861
862 devc = &dev_conf[midi_dev];
863 mpu_cmd(midi_dev, 0x15, 0); /* Stop recording, playback and MIDI */
864 mpu_cmd(midi_dev, 0x8a, 0); /* Disable data in stopped mode */
865
866 devc->inputintr = NULL;
867
868 coprocessor = midi_devs[midi_dev]->coproc;
869 if (coprocessor) {
870 coprocessor->close(coprocessor->devc, COPR_MIDI);
871 module_put(coprocessor->owner);
872 }
873 devc->opened = 0;
874 devc->mode = 0;
875}
876
877#define MIDI_SYNTH_NAME "MPU-401 UART Midi"
878#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
879#include "midi_synth.h"
880
881static struct synth_operations mpu401_synth_proto =
882{
883 .owner = THIS_MODULE,
884 .id = "MPU401",
885 .info = NULL,
886 .midi_dev = 0,
887 .synth_type = SYNTH_TYPE_MIDI,
888 .synth_subtype = 0,
889 .open = mpu_synth_open,
890 .close = mpu_synth_close,
891 .ioctl = mpu_synth_ioctl,
892 .kill_note = midi_synth_kill_note,
893 .start_note = midi_synth_start_note,
894 .set_instr = midi_synth_set_instr,
895 .reset = midi_synth_reset,
896 .hw_control = midi_synth_hw_control,
897 .load_patch = midi_synth_load_patch,
898 .aftertouch = midi_synth_aftertouch,
899 .controller = midi_synth_controller,
900 .panning = midi_synth_panning,
901 .bender = midi_synth_bender,
902 .setup_voice = midi_synth_setup_voice,
903 .send_sysex = midi_synth_send_sysex
904};
905
906static struct synth_operations *mpu401_synth_operations[MAX_MIDI_DEV];
907
908static struct midi_operations mpu401_midi_proto =
909{
910 .owner = THIS_MODULE,
911 .info = {"MPU-401 Midi", 0, MIDI_CAP_MPU401, SNDCARD_MPU401},
912 .in_info = {0},
913 .open = mpu401_open,
914 .close = mpu401_close,
915 .ioctl = mpu401_ioctl,
916 .outputc = mpu401_out,
917 .start_read = mpu401_start_read,
918 .end_read = mpu401_end_read,
919 .kick = mpu401_kick,
920 .buffer_status = mpu401_buffer_status,
921 .prefix_cmd = mpu401_prefix_cmd
922};
923
924static struct midi_operations mpu401_midi_operations[MAX_MIDI_DEV];
925
926static void mpu401_chk_version(int n, struct mpu_config *devc)
927{
928 int tmp;
929
930 devc->version = devc->revision = 0;
931
932 tmp = mpu_cmd(n, 0xAC, 0);
933 if (tmp < 0)
934 return;
935 if ((tmp & 0xf0) > 0x20) /* Why it's larger than 2.x ??? */
936 return;
937 devc->version = tmp;
938
939 if ((tmp = mpu_cmd(n, 0xAD, 0)) < 0) {
940 devc->version = 0;
941 return;
942 }
943 devc->revision = tmp;
944}
945
946int attach_mpu401(struct address_info *hw_config, struct module *owner)
947{
948 unsigned long flags;
949 char revision_char;
950
951 int m, ret;
952 struct mpu_config *devc;
953
954 hw_config->slots[1] = -1;
955 m = sound_alloc_mididev();
956 if (m == -1)
957 {
958 printk(KERN_WARNING "MPU-401: Too many midi devices detected\n");
959 ret = -ENOMEM;
960 goto out_err;
961 }
962 devc = &dev_conf[m];
963 devc->base = hw_config->io_base;
964 devc->osp = hw_config->osp;
965 devc->irq = hw_config->irq;
966 devc->opened = 0;
967 devc->uart_mode = 0;
968 devc->initialized = 0;
969 devc->version = 0;
970 devc->revision = 0;
971 devc->capabilities = 0;
972 devc->timer_flag = 0;
973 devc->m_busy = 0;
974 devc->m_state = ST_INIT;
975 devc->shared_irq = hw_config->always_detect;
976 spin_lock_init(&devc->lock);
977
978 if (devc->irq < 0)
979 {
980 devc->irq *= -1;
981 devc->shared_irq = 1;
982 }
983
984 if (!hw_config->always_detect)
985 {
986 /* Verify the hardware again */
987 if (!reset_mpu401(devc))
988 {
989 printk(KERN_WARNING "mpu401: Device didn't respond\n");
990 ret = -ENODEV;
991 goto out_mididev;
992 }
993 if (!devc->shared_irq)
994 {
995 if (request_irq(devc->irq, mpuintr, 0, "mpu401",
996 hw_config) < 0)
997 {
998 printk(KERN_WARNING "mpu401: Failed to allocate IRQ%d\n", devc->irq);
999 ret = -ENOMEM;
1000 goto out_mididev;
1001 }
1002 }
1003 spin_lock_irqsave(&devc->lock,flags);
1004 mpu401_chk_version(m, devc);
1005 if (devc->version == 0)
1006 mpu401_chk_version(m, devc);
1007 spin_unlock_irqrestore(&devc->lock, flags);
1008 }
1009
1010 if (devc->version != 0)
1011 if (mpu_cmd(m, 0xC5, 0) >= 0) /* Set timebase OK */
1012 if (mpu_cmd(m, 0xE0, 120) >= 0) /* Set tempo OK */
1013 devc->capabilities |= MPU_CAP_INTLG; /* Supports intelligent mode */
1014
1015
1016 mpu401_synth_operations[m] = kmalloc(sizeof(struct synth_operations), GFP_KERNEL);
1017
1018 if (mpu401_synth_operations[m] == NULL)
1019 {
1020 printk(KERN_ERR "mpu401: Can't allocate memory\n");
1021 ret = -ENOMEM;
1022 goto out_irq;
1023 }
1024 if (!(devc->capabilities & MPU_CAP_INTLG)) /* No intelligent mode */
1025 {
1026 memcpy((char *) mpu401_synth_operations[m],
1027 (char *) &std_midi_synth,
1028 sizeof(struct synth_operations));
1029 }
1030 else
1031 {
1032 memcpy((char *) mpu401_synth_operations[m],
1033 (char *) &mpu401_synth_proto,
1034 sizeof(struct synth_operations));
1035 }
1036 if (owner)
1037 mpu401_synth_operations[m]->owner = owner;
1038
1039 memcpy((char *) &mpu401_midi_operations[m],
1040 (char *) &mpu401_midi_proto,
1041 sizeof(struct midi_operations));
1042
1043 mpu401_midi_operations[m].converter = mpu401_synth_operations[m];
1044
1045 memcpy((char *) &mpu_synth_info[m],
1046 (char *) &mpu_synth_info_proto,
1047 sizeof(struct synth_info));
1048
1049 n_mpu_devs++;
1050
1051 if (devc->version == 0x20 && devc->revision >= 0x07) /* MusicQuest interface */
1052 {
1053 int ports = (devc->revision & 0x08) ? 32 : 16;
1054
1055 devc->capabilities |= MPU_CAP_SYNC | MPU_CAP_SMPTE |
1056 MPU_CAP_CLS | MPU_CAP_2PORT;
1057
1058 revision_char = (devc->revision == 0x7f) ? 'M' : ' ';
1059 sprintf(mpu_synth_info[m].name, "MQX-%d%c MIDI Interface #%d",
1060 ports,
1061 revision_char,
1062 n_mpu_devs);
1063 }
1064 else
1065 {
1066 revision_char = devc->revision ? devc->revision + '@' : ' ';
1067 if ((int) devc->revision > ('Z' - '@'))
1068 revision_char = '+';
1069
1070 devc->capabilities |= MPU_CAP_SYNC | MPU_CAP_FSK;
1071
1072 if (hw_config->name)
1073 sprintf(mpu_synth_info[m].name, "%s (MPU401)", hw_config->name);
1074 else
1075 sprintf(mpu_synth_info[m].name,
1076 "MPU-401 %d.%d%c MIDI #%d",
1077 (int) (devc->version & 0xf0) >> 4,
1078 devc->version & 0x0f,
1079 revision_char,
1080 n_mpu_devs);
1081 }
1082
1083 strcpy(mpu401_midi_operations[m].info.name,
1084 mpu_synth_info[m].name);
1085
1086 conf_printf(mpu_synth_info[m].name, hw_config);
1087
1088 mpu401_synth_operations[m]->midi_dev = devc->devno = m;
1089 mpu401_synth_operations[devc->devno]->info = &mpu_synth_info[devc->devno];
1090
1091 if (devc->capabilities & MPU_CAP_INTLG) /* Intelligent mode */
1092 hw_config->slots[2] = mpu_timer_init(m);
1093
1094 midi_devs[m] = &mpu401_midi_operations[devc->devno];
1095
1096 if (owner)
1097 midi_devs[m]->owner = owner;
1098
1099 hw_config->slots[1] = m;
1100 sequencer_init();
1101
1102 return 0;
1103
1104out_irq:
1105 free_irq(devc->irq, hw_config);
1106out_mididev:
1107 sound_unload_mididev(m);
1108out_err:
1109 release_region(hw_config->io_base, 2);
1110 return ret;
1111}
1112
1113static int reset_mpu401(struct mpu_config *devc)
1114{
1115 unsigned long flags;
1116 int ok, timeout, n;
1117 int timeout_limit;
1118
1119 /*
1120 * Send the RESET command. Try again if no success at the first time.
1121 * (If the device is in the UART mode, it will not ack the reset cmd).
1122 */
1123
1124 ok = 0;
1125
1126 timeout_limit = devc->initialized ? 30000 : 100000;
1127 devc->initialized = 1;
1128
1129 for (n = 0; n < 2 && !ok; n++)
1130 {
1131 for (timeout = timeout_limit; timeout > 0 && !ok; timeout--)
1132 ok = output_ready(devc);
1133
1134 write_command(devc, MPU_RESET); /*
1135 * Send MPU-401 RESET Command
1136 */
1137
1138 /*
1139 * Wait at least 25 msec. This method is not accurate so let's make the
1140 * loop bit longer. Cannot sleep since this is called during boot.
1141 */
1142
1143 for (timeout = timeout_limit * 2; timeout > 0 && !ok; timeout--)
1144 {
1145 spin_lock_irqsave(&devc->lock,flags);
1146 if (input_avail(devc))
1147 if (read_data(devc) == MPU_ACK)
1148 ok = 1;
1149 spin_unlock_irqrestore(&devc->lock,flags);
1150 }
1151
1152 }
1153
1154 devc->m_state = ST_INIT;
1155 devc->m_ptr = 0;
1156 devc->m_left = 0;
1157 devc->last_status = 0;
1158 devc->uart_mode = 0;
1159
1160 return ok;
1161}
1162
1163static void set_uart_mode(int dev, struct mpu_config *devc, int arg)
1164{
1165 if (!arg && (devc->capabilities & MPU_CAP_INTLG))
1166 return;
1167 if ((devc->uart_mode == 0) == (arg == 0))
1168 return; /* Already set */
1169 reset_mpu401(devc); /* This exits the uart mode */
1170
1171 if (arg)
1172 {
1173 if (mpu_cmd(dev, UART_MODE_ON, 0) < 0)
1174 {
1175 printk(KERN_ERR "mpu401: Can't enter UART mode\n");
1176 devc->uart_mode = 0;
1177 return;
1178 }
1179 }
1180 devc->uart_mode = arg;
1181
1182}
1183
1184int probe_mpu401(struct address_info *hw_config, struct resource *ports)
1185{
1186 int ok = 0;
1187 struct mpu_config tmp_devc;
1188
1189 tmp_devc.base = hw_config->io_base;
1190 tmp_devc.irq = hw_config->irq;
1191 tmp_devc.initialized = 0;
1192 tmp_devc.opened = 0;
1193 tmp_devc.osp = hw_config->osp;
1194
1195 if (hw_config->always_detect)
1196 return 1;
1197
1198 if (inb(hw_config->io_base + 1) == 0xff)
1199 {
1200 DDB(printk("MPU401: Port %x looks dead.\n", hw_config->io_base));
1201 return 0; /* Just bus float? */
1202 }
1203 ok = reset_mpu401(&tmp_devc);
1204
1205 if (!ok)
1206 {
1207 DDB(printk("MPU401: Reset failed on port %x\n", hw_config->io_base));
1208 }
1209 return ok;
1210}
1211
1212void unload_mpu401(struct address_info *hw_config)
1213{
1214 void *p;
1215 int n=hw_config->slots[1];
1216
1217 if (n != -1) {
1218 release_region(hw_config->io_base, 2);
1219 if (hw_config->always_detect == 0 && hw_config->irq > 0)
1220 free_irq(hw_config->irq, hw_config);
1221 p=mpu401_synth_operations[n];
1222 sound_unload_mididev(n);
1223 sound_unload_timerdev(hw_config->slots[2]);
1224 kfree(p);
1225 }
1226}
1227
1228/*****************************************************
1229 * Timer stuff
1230 ****************************************************/
1231
1232static volatile int timer_initialized = 0, timer_open = 0, tmr_running = 0;
1233static volatile int curr_tempo, curr_timebase, hw_timebase;
1234static int max_timebase = 8; /* 8*24=192 ppqn */
1235static volatile unsigned long next_event_time;
1236static volatile unsigned long curr_ticks, curr_clocks;
1237static unsigned long prev_event_time;
1238static int metronome_mode;
1239
1240static unsigned long clocks2ticks(unsigned long clocks)
1241{
1242 /*
1243 * The MPU-401 supports just a limited set of possible timebase values.
1244 * Since the applications require more choices, the driver has to
1245 * program the HW to do its best and to convert between the HW and
1246 * actual timebases.
1247 */
1248 return ((clocks * curr_timebase) + (hw_timebase / 2)) / hw_timebase;
1249}
1250
1251static void set_timebase(int midi_dev, int val)
1252{
1253 int hw_val;
1254
1255 if (val < 48)
1256 val = 48;
1257 if (val > 1000)
1258 val = 1000;
1259
1260 hw_val = val;
1261 hw_val = (hw_val + 12) / 24;
1262 if (hw_val > max_timebase)
1263 hw_val = max_timebase;
1264
1265 if (mpu_cmd(midi_dev, 0xC0 | (hw_val & 0x0f), 0) < 0)
1266 {
1267 printk(KERN_WARNING "mpu401: Can't set HW timebase to %d\n", hw_val * 24);
1268 return;
1269 }
1270 hw_timebase = hw_val * 24;
1271 curr_timebase = val;
1272
1273}
1274
1275static void tmr_reset(struct mpu_config *devc)
1276{
1277 unsigned long flags;
1278
1279 spin_lock_irqsave(&devc->lock,flags);
1280 next_event_time = (unsigned long) -1;
1281 prev_event_time = 0;
1282 curr_ticks = curr_clocks = 0;
1283 spin_unlock_irqrestore(&devc->lock,flags);
1284}
1285
1286static void set_timer_mode(int midi_dev)
1287{
1288 if (timer_mode & TMR_MODE_CLS)
1289 mpu_cmd(midi_dev, 0x3c, 0); /* Use CLS sync */
1290 else if (timer_mode & TMR_MODE_SMPTE)
1291 mpu_cmd(midi_dev, 0x3d, 0); /* Use SMPTE sync */
1292
1293 if (timer_mode & TMR_INTERNAL)
1294 {
1295 mpu_cmd(midi_dev, 0x80, 0); /* Use MIDI sync */
1296 }
1297 else
1298 {
1299 if (timer_mode & (TMR_MODE_MIDI | TMR_MODE_CLS))
1300 {
1301 mpu_cmd(midi_dev, 0x82, 0); /* Use MIDI sync */
1302 mpu_cmd(midi_dev, 0x91, 0); /* Enable ext MIDI ctrl */
1303 }
1304 else if (timer_mode & TMR_MODE_FSK)
1305 mpu_cmd(midi_dev, 0x81, 0); /* Use FSK sync */
1306 }
1307}
1308
1309static void stop_metronome(int midi_dev)
1310{
1311 mpu_cmd(midi_dev, 0x84, 0); /* Disable metronome */
1312}
1313
1314static void setup_metronome(int midi_dev)
1315{
1316 int numerator, denominator;
1317 int clks_per_click, num_32nds_per_beat;
1318 int beats_per_measure;
1319
1320 numerator = ((unsigned) metronome_mode >> 24) & 0xff;
1321 denominator = ((unsigned) metronome_mode >> 16) & 0xff;
1322 clks_per_click = ((unsigned) metronome_mode >> 8) & 0xff;
1323 num_32nds_per_beat = (unsigned) metronome_mode & 0xff;
1324 beats_per_measure = (numerator * 4) >> denominator;
1325
1326 if (!metronome_mode)
1327 mpu_cmd(midi_dev, 0x84, 0); /* Disable metronome */
1328 else
1329 {
1330 mpu_cmd(midi_dev, 0xE4, clks_per_click);
1331 mpu_cmd(midi_dev, 0xE6, beats_per_measure);
1332 mpu_cmd(midi_dev, 0x83, 0); /* Enable metronome without accents */
1333 }
1334}
1335
1336static int mpu_start_timer(int midi_dev)
1337{
1338 struct mpu_config *devc= &dev_conf[midi_dev];
1339
1340 tmr_reset(devc);
1341 set_timer_mode(midi_dev);
1342
1343 if (tmr_running)
1344 return TIMER_NOT_ARMED; /* Already running */
1345
1346 if (timer_mode & TMR_INTERNAL)
1347 {
1348 mpu_cmd(midi_dev, 0x02, 0); /* Send MIDI start */
1349 tmr_running = 1;
1350 return TIMER_NOT_ARMED;
1351 }
1352 else
1353 {
1354 mpu_cmd(midi_dev, 0x35, 0); /* Enable mode messages to PC */
1355 mpu_cmd(midi_dev, 0x38, 0); /* Enable sys common messages to PC */
1356 mpu_cmd(midi_dev, 0x39, 0); /* Enable real time messages to PC */
1357 mpu_cmd(midi_dev, 0x97, 0); /* Enable system exclusive messages to PC */
1358 }
1359 return TIMER_ARMED;
1360}
1361
1362static int mpu_timer_open(int dev, int mode)
1363{
1364 int midi_dev = sound_timer_devs[dev]->devlink;
1365 struct mpu_config *devc= &dev_conf[midi_dev];
1366
1367 if (timer_open)
1368 return -EBUSY;
1369
1370 tmr_reset(devc);
1371 curr_tempo = 50;
1372 mpu_cmd(midi_dev, 0xE0, 50);
1373 curr_timebase = hw_timebase = 120;
1374 set_timebase(midi_dev, 120);
1375 timer_open = 1;
1376 metronome_mode = 0;
1377 set_timer_mode(midi_dev);
1378
1379 mpu_cmd(midi_dev, 0xe7, 0x04); /* Send all clocks to host */
1380 mpu_cmd(midi_dev, 0x95, 0); /* Enable clock to host */
1381
1382 return 0;
1383}
1384
1385static void mpu_timer_close(int dev)
1386{
1387 int midi_dev = sound_timer_devs[dev]->devlink;
1388
1389 timer_open = tmr_running = 0;
1390 mpu_cmd(midi_dev, 0x15, 0); /* Stop all */
1391 mpu_cmd(midi_dev, 0x94, 0); /* Disable clock to host */
1392 mpu_cmd(midi_dev, 0x8c, 0); /* Disable measure end messages to host */
1393 stop_metronome(midi_dev);
1394}
1395
1396static int mpu_timer_event(int dev, unsigned char *event)
1397{
1398 unsigned char command = event[1];
1399 unsigned long parm = *(unsigned int *) &event[4];
1400 int midi_dev = sound_timer_devs[dev]->devlink;
1401
1402 switch (command)
1403 {
1404 case TMR_WAIT_REL:
1405 parm += prev_event_time;
1406 case TMR_WAIT_ABS:
1407 if (parm > 0)
1408 {
1409 long time;
1410
1411 if (parm <= curr_ticks) /* It's the time */
1412 return TIMER_NOT_ARMED;
1413 time = parm;
1414 next_event_time = prev_event_time = time;
1415
1416 return TIMER_ARMED;
1417 }
1418 break;
1419
1420 case TMR_START:
1421 if (tmr_running)
1422 break;
1423 return mpu_start_timer(midi_dev);
1424
1425 case TMR_STOP:
1426 mpu_cmd(midi_dev, 0x01, 0); /* Send MIDI stop */
1427 stop_metronome(midi_dev);
1428 tmr_running = 0;
1429 break;
1430
1431 case TMR_CONTINUE:
1432 if (tmr_running)
1433 break;
1434 mpu_cmd(midi_dev, 0x03, 0); /* Send MIDI continue */
1435 setup_metronome(midi_dev);
1436 tmr_running = 1;
1437 break;
1438
1439 case TMR_TEMPO:
1440 if (parm)
1441 {
1442 if (parm < 8)
1443 parm = 8;
1444 if (parm > 250)
1445 parm = 250;
1446 if (mpu_cmd(midi_dev, 0xE0, parm) < 0)
1447 printk(KERN_WARNING "mpu401: Can't set tempo to %d\n", (int) parm);
1448 curr_tempo = parm;
1449 }
1450 break;
1451
1452 case TMR_ECHO:
1453 seq_copy_to_input(event, 8);
1454 break;
1455
1456 case TMR_TIMESIG:
1457 if (metronome_mode) /* Metronome enabled */
1458 {
1459 metronome_mode = parm;
1460 setup_metronome(midi_dev);
1461 }
1462 break;
1463
1464 default:;
1465 }
1466 return TIMER_NOT_ARMED;
1467}
1468
1469static unsigned long mpu_timer_get_time(int dev)
1470{
1471 if (!timer_open)
1472 return 0;
1473
1474 return curr_ticks;
1475}
1476
1477static int mpu_timer_ioctl(int dev, unsigned int command, void __user *arg)
1478{
1479 int midi_dev = sound_timer_devs[dev]->devlink;
1480 int __user *p = (int __user *)arg;
1481
1482 switch (command)
1483 {
1484 case SNDCTL_TMR_SOURCE:
1485 {
1486 int parm;
1487
1488 if (get_user(parm, p))
1489 return -EFAULT;
1490 parm &= timer_caps;
1491
1492 if (parm != 0)
1493 {
1494 timer_mode = parm;
1495
1496 if (timer_mode & TMR_MODE_CLS)
1497 mpu_cmd(midi_dev, 0x3c, 0); /* Use CLS sync */
1498 else if (timer_mode & TMR_MODE_SMPTE)
1499 mpu_cmd(midi_dev, 0x3d, 0); /* Use SMPTE sync */
1500 }
1501 if (put_user(timer_mode, p))
1502 return -EFAULT;
1503 return timer_mode;
1504 }
1505 break;
1506
1507 case SNDCTL_TMR_START:
1508 mpu_start_timer(midi_dev);
1509 return 0;
1510
1511 case SNDCTL_TMR_STOP:
1512 tmr_running = 0;
1513 mpu_cmd(midi_dev, 0x01, 0); /* Send MIDI stop */
1514 stop_metronome(midi_dev);
1515 return 0;
1516
1517 case SNDCTL_TMR_CONTINUE:
1518 if (tmr_running)
1519 return 0;
1520 tmr_running = 1;
1521 mpu_cmd(midi_dev, 0x03, 0); /* Send MIDI continue */
1522 return 0;
1523
1524 case SNDCTL_TMR_TIMEBASE:
1525 {
1526 int val;
1527 if (get_user(val, p))
1528 return -EFAULT;
1529 if (val)
1530 set_timebase(midi_dev, val);
1531 if (put_user(curr_timebase, p))
1532 return -EFAULT;
1533 return curr_timebase;
1534 }
1535 break;
1536
1537 case SNDCTL_TMR_TEMPO:
1538 {
1539 int val;
1540 int ret;
1541
1542 if (get_user(val, p))
1543 return -EFAULT;
1544
1545 if (val)
1546 {
1547 if (val < 8)
1548 val = 8;
1549 if (val > 250)
1550 val = 250;
1551 if ((ret = mpu_cmd(midi_dev, 0xE0, val)) < 0)
1552 {
1553 printk(KERN_WARNING "mpu401: Can't set tempo to %d\n", (int) val);
1554 return ret;
1555 }
1556 curr_tempo = val;
1557 }
1558 if (put_user(curr_tempo, p))
1559 return -EFAULT;
1560 return curr_tempo;
1561 }
1562 break;
1563
1564 case SNDCTL_SEQ_CTRLRATE:
1565 {
1566 int val;
1567 if (get_user(val, p))
1568 return -EFAULT;
1569
1570 if (val != 0) /* Can't change */
1571 return -EINVAL;
1572 val = ((curr_tempo * curr_timebase) + 30)/60;
1573 if (put_user(val, p))
1574 return -EFAULT;
1575 return val;
1576 }
1577 break;
1578
1579 case SNDCTL_SEQ_GETTIME:
1580 if (put_user(curr_ticks, p))
1581 return -EFAULT;
1582 return curr_ticks;
1583
1584 case SNDCTL_TMR_METRONOME:
1585 if (get_user(metronome_mode, p))
1586 return -EFAULT;
1587 setup_metronome(midi_dev);
1588 return 0;
1589
1590 default:;
1591 }
1592 return -EINVAL;
1593}
1594
1595static void mpu_timer_arm(int dev, long time)
1596{
1597 if (time < 0)
1598 time = curr_ticks + 1;
1599 else if (time <= curr_ticks) /* It's the time */
1600 return;
1601 next_event_time = prev_event_time = time;
1602 return;
1603}
1604
1605static struct sound_timer_operations mpu_timer =
1606{
1607 .owner = THIS_MODULE,
1608 .info = {"MPU-401 Timer", 0},
1609 .priority = 10, /* Priority */
1610 .devlink = 0, /* Local device link */
1611 .open = mpu_timer_open,
1612 .close = mpu_timer_close,
1613 .event = mpu_timer_event,
1614 .get_time = mpu_timer_get_time,
1615 .ioctl = mpu_timer_ioctl,
1616 .arm_timer = mpu_timer_arm
1617};
1618
1619static void mpu_timer_interrupt(void)
1620{
1621 if (!timer_open)
1622 return;
1623
1624 if (!tmr_running)
1625 return;
1626
1627 curr_clocks++;
1628 curr_ticks = clocks2ticks(curr_clocks);
1629
1630 if (curr_ticks >= next_event_time)
1631 {
1632 next_event_time = (unsigned long) -1;
1633 sequencer_timer(0);
1634 }
1635}
1636
1637static void timer_ext_event(struct mpu_config *devc, int event, int parm)
1638{
1639 int midi_dev = devc->devno;
1640
1641 if (!devc->timer_flag)
1642 return;
1643
1644 switch (event)
1645 {
1646 case TMR_CLOCK:
1647 printk("<MIDI clk>");
1648 break;
1649
1650 case TMR_START:
1651 printk("Ext MIDI start\n");
1652 if (!tmr_running)
1653 {
1654 if (timer_mode & TMR_EXTERNAL)
1655 {
1656 tmr_running = 1;
1657 setup_metronome(midi_dev);
1658 next_event_time = 0;
1659 STORE(SEQ_START_TIMER());
1660 }
1661 }
1662 break;
1663
1664 case TMR_STOP:
1665 printk("Ext MIDI stop\n");
1666 if (timer_mode & TMR_EXTERNAL)
1667 {
1668 tmr_running = 0;
1669 stop_metronome(midi_dev);
1670 STORE(SEQ_STOP_TIMER());
1671 }
1672 break;
1673
1674 case TMR_CONTINUE:
1675 printk("Ext MIDI continue\n");
1676 if (timer_mode & TMR_EXTERNAL)
1677 {
1678 tmr_running = 1;
1679 setup_metronome(midi_dev);
1680 STORE(SEQ_CONTINUE_TIMER());
1681 }
1682 break;
1683
1684 case TMR_SPP:
1685 printk("Songpos: %d\n", parm);
1686 if (timer_mode & TMR_EXTERNAL)
1687 {
1688 STORE(SEQ_SONGPOS(parm));
1689 }
1690 break;
1691 }
1692}
1693
1694static int mpu_timer_init(int midi_dev)
1695{
1696 struct mpu_config *devc;
1697 int n;
1698
1699 devc = &dev_conf[midi_dev];
1700
1701 if (timer_initialized)
1702 return -1; /* There is already a similar timer */
1703
1704 timer_initialized = 1;
1705
1706 mpu_timer.devlink = midi_dev;
1707 dev_conf[midi_dev].timer_flag = 1;
1708
1709 n = sound_alloc_timerdev();
1710 if (n == -1)
1711 n = 0;
1712 sound_timer_devs[n] = &mpu_timer;
1713
1714 if (devc->version < 0x20) /* Original MPU-401 */
1715 timer_caps = TMR_INTERNAL | TMR_EXTERNAL | TMR_MODE_FSK | TMR_MODE_MIDI;
1716 else
1717 {
1718 /*
1719 * The version number 2.0 is used (at least) by the
1720 * MusicQuest cards and the Roland Super-MPU.
1721 *
1722 * MusicQuest has given a special meaning to the bits of the
1723 * revision number. The Super-MPU returns 0.
1724 */
1725
1726 if (devc->revision)
1727 timer_caps |= TMR_EXTERNAL | TMR_MODE_MIDI;
1728
1729 if (devc->revision & 0x02)
1730 timer_caps |= TMR_MODE_CLS;
1731
1732
1733 if (devc->revision & 0x40)
1734 max_timebase = 10; /* Has the 216 and 240 ppqn modes */
1735 }
1736
1737 timer_mode = (TMR_INTERNAL | TMR_MODE_MIDI) & timer_caps;
1738 return n;
1739
1740}
1741
1742EXPORT_SYMBOL(probe_mpu401);
1743EXPORT_SYMBOL(attach_mpu401);
1744EXPORT_SYMBOL(unload_mpu401);
1745
1746static struct address_info cfg;
1747
1748static int io = -1;
1749static int irq = -1;
1750
1751module_param_hw(irq, int, irq, 0);
1752module_param_hw(io, int, ioport, 0);
1753
1754static int __init init_mpu401(void)
1755{
1756 int ret;
1757 /* Can be loaded either for module use or to provide functions
1758 to others */
1759 if (io != -1 && irq != -1) {
1760 struct resource *ports;
1761 cfg.irq = irq;
1762 cfg.io_base = io;
1763 ports = request_region(io, 2, "mpu401");
1764 if (!ports)
1765 return -EBUSY;
1766 if (probe_mpu401(&cfg, ports) == 0) {
1767 release_region(io, 2);
1768 return -ENODEV;
1769 }
1770 if ((ret = attach_mpu401(&cfg, THIS_MODULE)))
1771 return ret;
1772 }
1773
1774 return 0;
1775}
1776
1777static void __exit cleanup_mpu401(void)
1778{
1779 if (io != -1 && irq != -1) {
1780 /* Check for use by, for example, sscape driver */
1781 unload_mpu401(&cfg);
1782 }
1783}
1784
1785module_init(init_mpu401);
1786module_exit(cleanup_mpu401);
1787
1788#ifndef MODULE
1789static int __init setup_mpu401(char *str)
1790{
1791 /* io, irq */
1792 int ints[3];
1793
1794 str = get_options(str, ARRAY_SIZE(ints), ints);
1795
1796 io = ints[1];
1797 irq = ints[2];
1798
1799 return 1;
1800}
1801
1802__setup("mpu401=", setup_mpu401);
1803#endif
1804MODULE_LICENSE("GPL");
diff --git a/sound/oss/mpu401.h b/sound/oss/mpu401.h
deleted file mode 100644
index 6beb8c2ae405..000000000000
--- a/sound/oss/mpu401.h
+++ /dev/null
@@ -1,12 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2
3/* From uart401.c */
4int probe_uart401 (struct address_info *hw_config, struct module *owner);
5void unload_uart401 (struct address_info *hw_config);
6
7irqreturn_t uart401intr (int irq, void *dev_id);
8
9/* From mpu401.c */
10int probe_mpu401(struct address_info *hw_config, struct resource *ports);
11int attach_mpu401(struct address_info * hw_config, struct module *owner);
12void unload_mpu401(struct address_info *hw_info);
diff --git a/sound/oss/msnd.c b/sound/oss/msnd.c
deleted file mode 100644
index b63010ad22f1..000000000000
--- a/sound/oss/msnd.c
+++ /dev/null
@@ -1,413 +0,0 @@
1/*********************************************************************
2 *
3 * msnd.c - Driver Base
4 *
5 * Turtle Beach MultiSound Sound Card Driver for Linux
6 *
7 * Copyright (C) 1998 Andrew Veliath
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 ********************************************************************/
24
25#include <linux/module.h>
26#include <linux/kernel.h>
27#include <linux/vmalloc.h>
28#include <linux/types.h>
29#include <linux/delay.h>
30#include <linux/mm.h>
31#include <linux/init.h>
32#include <linux/interrupt.h>
33
34#include <asm/io.h>
35#include <linux/uaccess.h>
36#include <linux/spinlock.h>
37#include <asm/irq.h>
38#include "msnd.h"
39
40#define LOGNAME "msnd"
41
42#define MSND_MAX_DEVS 4
43
44static multisound_dev_t *devs[MSND_MAX_DEVS];
45static int num_devs;
46
47int msnd_register(multisound_dev_t *dev)
48{
49 int i;
50
51 for (i = 0; i < MSND_MAX_DEVS; ++i)
52 if (devs[i] == NULL)
53 break;
54
55 if (i == MSND_MAX_DEVS)
56 return -ENOMEM;
57
58 devs[i] = dev;
59 ++num_devs;
60 return 0;
61}
62
63void msnd_unregister(multisound_dev_t *dev)
64{
65 int i;
66
67 for (i = 0; i < MSND_MAX_DEVS; ++i)
68 if (devs[i] == dev)
69 break;
70
71 if (i == MSND_MAX_DEVS) {
72 printk(KERN_WARNING LOGNAME ": Unregistering unknown device\n");
73 return;
74 }
75
76 devs[i] = NULL;
77 --num_devs;
78}
79
80void msnd_init_queue(void __iomem *base, int start, int size)
81{
82 writew(PCTODSP_BASED(start), base + JQS_wStart);
83 writew(PCTODSP_OFFSET(size) - 1, base + JQS_wSize);
84 writew(0, base + JQS_wHead);
85 writew(0, base + JQS_wTail);
86}
87
88void msnd_fifo_init(msnd_fifo *f)
89{
90 f->data = NULL;
91}
92
93void msnd_fifo_free(msnd_fifo *f)
94{
95 vfree(f->data);
96 f->data = NULL;
97}
98
99int msnd_fifo_alloc(msnd_fifo *f, size_t n)
100{
101 msnd_fifo_free(f);
102 f->data = vmalloc(n);
103 f->n = n;
104 f->tail = 0;
105 f->head = 0;
106 f->len = 0;
107
108 if (!f->data)
109 return -ENOMEM;
110
111 return 0;
112}
113
114void msnd_fifo_make_empty(msnd_fifo *f)
115{
116 f->len = f->tail = f->head = 0;
117}
118
119int msnd_fifo_write_io(msnd_fifo *f, char __iomem *buf, size_t len)
120{
121 int count = 0;
122
123 while ((count < len) && (f->len != f->n)) {
124
125 int nwritten;
126
127 if (f->head <= f->tail) {
128 nwritten = len - count;
129 if (nwritten > f->n - f->tail)
130 nwritten = f->n - f->tail;
131 }
132 else {
133 nwritten = f->head - f->tail;
134 if (nwritten > len - count)
135 nwritten = len - count;
136 }
137
138 memcpy_fromio(f->data + f->tail, buf, nwritten);
139
140 count += nwritten;
141 buf += nwritten;
142 f->len += nwritten;
143 f->tail += nwritten;
144 f->tail %= f->n;
145 }
146
147 return count;
148}
149
150int msnd_fifo_write(msnd_fifo *f, const char *buf, size_t len)
151{
152 int count = 0;
153
154 while ((count < len) && (f->len != f->n)) {
155
156 int nwritten;
157
158 if (f->head <= f->tail) {
159 nwritten = len - count;
160 if (nwritten > f->n - f->tail)
161 nwritten = f->n - f->tail;
162 }
163 else {
164 nwritten = f->head - f->tail;
165 if (nwritten > len - count)
166 nwritten = len - count;
167 }
168
169 memcpy(f->data + f->tail, buf, nwritten);
170
171 count += nwritten;
172 buf += nwritten;
173 f->len += nwritten;
174 f->tail += nwritten;
175 f->tail %= f->n;
176 }
177
178 return count;
179}
180
181int msnd_fifo_read_io(msnd_fifo *f, char __iomem *buf, size_t len)
182{
183 int count = 0;
184
185 while ((count < len) && (f->len > 0)) {
186
187 int nread;
188
189 if (f->tail <= f->head) {
190 nread = len - count;
191 if (nread > f->n - f->head)
192 nread = f->n - f->head;
193 }
194 else {
195 nread = f->tail - f->head;
196 if (nread > len - count)
197 nread = len - count;
198 }
199
200 memcpy_toio(buf, f->data + f->head, nread);
201
202 count += nread;
203 buf += nread;
204 f->len -= nread;
205 f->head += nread;
206 f->head %= f->n;
207 }
208
209 return count;
210}
211
212int msnd_fifo_read(msnd_fifo *f, char *buf, size_t len)
213{
214 int count = 0;
215
216 while ((count < len) && (f->len > 0)) {
217
218 int nread;
219
220 if (f->tail <= f->head) {
221 nread = len - count;
222 if (nread > f->n - f->head)
223 nread = f->n - f->head;
224 }
225 else {
226 nread = f->tail - f->head;
227 if (nread > len - count)
228 nread = len - count;
229 }
230
231 memcpy(buf, f->data + f->head, nread);
232
233 count += nread;
234 buf += nread;
235 f->len -= nread;
236 f->head += nread;
237 f->head %= f->n;
238 }
239
240 return count;
241}
242
243static int msnd_wait_TXDE(multisound_dev_t *dev)
244{
245 register unsigned int io = dev->io;
246 register int timeout = 1000;
247
248 while(timeout-- > 0)
249 if (msnd_inb(io + HP_ISR) & HPISR_TXDE)
250 return 0;
251
252 return -EIO;
253}
254
255static int msnd_wait_HC0(multisound_dev_t *dev)
256{
257 register unsigned int io = dev->io;
258 register int timeout = 1000;
259
260 while(timeout-- > 0)
261 if (!(msnd_inb(io + HP_CVR) & HPCVR_HC))
262 return 0;
263
264 return -EIO;
265}
266
267int msnd_send_dsp_cmd(multisound_dev_t *dev, BYTE cmd)
268{
269 unsigned long flags;
270
271 spin_lock_irqsave(&dev->lock, flags);
272 if (msnd_wait_HC0(dev) == 0) {
273 msnd_outb(cmd, dev->io + HP_CVR);
274 spin_unlock_irqrestore(&dev->lock, flags);
275 return 0;
276 }
277 spin_unlock_irqrestore(&dev->lock, flags);
278
279 printk(KERN_DEBUG LOGNAME ": Send DSP command timeout\n");
280
281 return -EIO;
282}
283
284int msnd_send_word(multisound_dev_t *dev, unsigned char high,
285 unsigned char mid, unsigned char low)
286{
287 register unsigned int io = dev->io;
288
289 if (msnd_wait_TXDE(dev) == 0) {
290 msnd_outb(high, io + HP_TXH);
291 msnd_outb(mid, io + HP_TXM);
292 msnd_outb(low, io + HP_TXL);
293 return 0;
294 }
295
296 printk(KERN_DEBUG LOGNAME ": Send host word timeout\n");
297
298 return -EIO;
299}
300
301int msnd_upload_host(multisound_dev_t *dev, char *bin, int len)
302{
303 int i;
304
305 if (len % 3 != 0) {
306 printk(KERN_WARNING LOGNAME ": Upload host data not multiple of 3!\n");
307 return -EINVAL;
308 }
309
310 for (i = 0; i < len; i += 3)
311 if (msnd_send_word(dev, bin[i], bin[i + 1], bin[i + 2]) != 0)
312 return -EIO;
313
314 msnd_inb(dev->io + HP_RXL);
315 msnd_inb(dev->io + HP_CVR);
316
317 return 0;
318}
319
320int msnd_enable_irq(multisound_dev_t *dev)
321{
322 unsigned long flags;
323
324 if (dev->irq_ref++)
325 return 0;
326
327 printk(KERN_DEBUG LOGNAME ": Enabling IRQ\n");
328
329 spin_lock_irqsave(&dev->lock, flags);
330 if (msnd_wait_TXDE(dev) == 0) {
331 msnd_outb(msnd_inb(dev->io + HP_ICR) | HPICR_TREQ, dev->io + HP_ICR);
332 if (dev->type == msndClassic)
333 msnd_outb(dev->irqid, dev->io + HP_IRQM);
334 msnd_outb(msnd_inb(dev->io + HP_ICR) & ~HPICR_TREQ, dev->io + HP_ICR);
335 msnd_outb(msnd_inb(dev->io + HP_ICR) | HPICR_RREQ, dev->io + HP_ICR);
336 enable_irq(dev->irq);
337 msnd_init_queue(dev->DSPQ, dev->dspq_data_buff, dev->dspq_buff_size);
338 spin_unlock_irqrestore(&dev->lock, flags);
339 return 0;
340 }
341 spin_unlock_irqrestore(&dev->lock, flags);
342
343 printk(KERN_DEBUG LOGNAME ": Enable IRQ failed\n");
344
345 return -EIO;
346}
347
348int msnd_disable_irq(multisound_dev_t *dev)
349{
350 unsigned long flags;
351
352 if (--dev->irq_ref > 0)
353 return 0;
354
355 if (dev->irq_ref < 0)
356 printk(KERN_DEBUG LOGNAME ": IRQ ref count is %d\n", dev->irq_ref);
357
358 printk(KERN_DEBUG LOGNAME ": Disabling IRQ\n");
359
360 spin_lock_irqsave(&dev->lock, flags);
361 if (msnd_wait_TXDE(dev) == 0) {
362 msnd_outb(msnd_inb(dev->io + HP_ICR) & ~HPICR_RREQ, dev->io + HP_ICR);
363 if (dev->type == msndClassic)
364 msnd_outb(HPIRQ_NONE, dev->io + HP_IRQM);
365 disable_irq(dev->irq);
366 spin_unlock_irqrestore(&dev->lock, flags);
367 return 0;
368 }
369 spin_unlock_irqrestore(&dev->lock, flags);
370
371 printk(KERN_DEBUG LOGNAME ": Disable IRQ failed\n");
372
373 return -EIO;
374}
375
376#ifndef LINUX20
377EXPORT_SYMBOL(msnd_register);
378EXPORT_SYMBOL(msnd_unregister);
379
380EXPORT_SYMBOL(msnd_init_queue);
381
382EXPORT_SYMBOL(msnd_fifo_init);
383EXPORT_SYMBOL(msnd_fifo_free);
384EXPORT_SYMBOL(msnd_fifo_alloc);
385EXPORT_SYMBOL(msnd_fifo_make_empty);
386EXPORT_SYMBOL(msnd_fifo_write_io);
387EXPORT_SYMBOL(msnd_fifo_read_io);
388EXPORT_SYMBOL(msnd_fifo_write);
389EXPORT_SYMBOL(msnd_fifo_read);
390
391EXPORT_SYMBOL(msnd_send_dsp_cmd);
392EXPORT_SYMBOL(msnd_send_word);
393EXPORT_SYMBOL(msnd_upload_host);
394
395EXPORT_SYMBOL(msnd_enable_irq);
396EXPORT_SYMBOL(msnd_disable_irq);
397#endif
398
399#ifdef MODULE
400MODULE_AUTHOR ("Andrew Veliath <andrewtv@usa.net>");
401MODULE_DESCRIPTION ("Turtle Beach MultiSound Driver Base");
402MODULE_LICENSE("GPL");
403
404
405int init_module(void)
406{
407 return 0;
408}
409
410void cleanup_module(void)
411{
412}
413#endif
diff --git a/sound/oss/msnd.h b/sound/oss/msnd.h
deleted file mode 100644
index c8be47ec2b7e..000000000000
--- a/sound/oss/msnd.h
+++ /dev/null
@@ -1,278 +0,0 @@
1/*********************************************************************
2 *
3 * msnd.h
4 *
5 * Turtle Beach MultiSound Sound Card Driver for Linux
6 *
7 * Some parts of this header file were derived from the Turtle Beach
8 * MultiSound Driver Development Kit.
9 *
10 * Copyright (C) 1998 Andrew Veliath
11 * Copyright (C) 1993 Turtle Beach Systems, Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 ********************************************************************/
28#ifndef __MSND_H
29#define __MSND_H
30
31#define VERSION "0.8.3.1"
32
33#define DEFSAMPLERATE DSP_DEFAULT_SPEED
34#define DEFSAMPLESIZE AFMT_U8
35#define DEFCHANNELS 1
36
37#define DEFFIFOSIZE 128
38
39#define SNDCARD_MSND 38
40
41#define SRAM_BANK_SIZE 0x8000
42#define SRAM_CNTL_START 0x7F00
43
44#define DSP_BASE_ADDR 0x4000
45#define DSP_BANK_BASE 0x4000
46
47#define HP_ICR 0x00
48#define HP_CVR 0x01
49#define HP_ISR 0x02
50#define HP_IVR 0x03
51#define HP_NU 0x04
52#define HP_INFO 0x04
53#define HP_TXH 0x05
54#define HP_RXH 0x05
55#define HP_TXM 0x06
56#define HP_RXM 0x06
57#define HP_TXL 0x07
58#define HP_RXL 0x07
59
60#define HP_ICR_DEF 0x00
61#define HP_CVR_DEF 0x12
62#define HP_ISR_DEF 0x06
63#define HP_IVR_DEF 0x0f
64#define HP_NU_DEF 0x00
65
66#define HP_IRQM 0x09
67
68#define HPR_BLRC 0x08
69#define HPR_SPR1 0x09
70#define HPR_SPR2 0x0A
71#define HPR_TCL0 0x0B
72#define HPR_TCL1 0x0C
73#define HPR_TCL2 0x0D
74#define HPR_TCL3 0x0E
75#define HPR_TCL4 0x0F
76
77#define HPICR_INIT 0x80
78#define HPICR_HM1 0x40
79#define HPICR_HM0 0x20
80#define HPICR_HF1 0x10
81#define HPICR_HF0 0x08
82#define HPICR_TREQ 0x02
83#define HPICR_RREQ 0x01
84
85#define HPCVR_HC 0x80
86
87#define HPISR_HREQ 0x80
88#define HPISR_DMA 0x40
89#define HPISR_HF3 0x10
90#define HPISR_HF2 0x08
91#define HPISR_TRDY 0x04
92#define HPISR_TXDE 0x02
93#define HPISR_RXDF 0x01
94
95#define HPIO_290 0
96#define HPIO_260 1
97#define HPIO_250 2
98#define HPIO_240 3
99#define HPIO_230 4
100#define HPIO_220 5
101#define HPIO_210 6
102#define HPIO_3E0 7
103
104#define HPMEM_NONE 0
105#define HPMEM_B000 1
106#define HPMEM_C800 2
107#define HPMEM_D000 3
108#define HPMEM_D400 4
109#define HPMEM_D800 5
110#define HPMEM_E000 6
111#define HPMEM_E800 7
112
113#define HPIRQ_NONE 0
114#define HPIRQ_5 1
115#define HPIRQ_7 2
116#define HPIRQ_9 3
117#define HPIRQ_10 4
118#define HPIRQ_11 5
119#define HPIRQ_12 6
120#define HPIRQ_15 7
121
122#define HIMT_PLAY_DONE 0x00
123#define HIMT_RECORD_DONE 0x01
124#define HIMT_MIDI_EOS 0x02
125#define HIMT_MIDI_OUT 0x03
126
127#define HIMT_MIDI_IN_UCHAR 0x0E
128#define HIMT_DSP 0x0F
129
130#define HDEX_BASE 0x92
131#define HDEX_PLAY_START (0 + HDEX_BASE)
132#define HDEX_PLAY_STOP (1 + HDEX_BASE)
133#define HDEX_PLAY_PAUSE (2 + HDEX_BASE)
134#define HDEX_PLAY_RESUME (3 + HDEX_BASE)
135#define HDEX_RECORD_START (4 + HDEX_BASE)
136#define HDEX_RECORD_STOP (5 + HDEX_BASE)
137#define HDEX_MIDI_IN_START (6 + HDEX_BASE)
138#define HDEX_MIDI_IN_STOP (7 + HDEX_BASE)
139#define HDEX_MIDI_OUT_START (8 + HDEX_BASE)
140#define HDEX_MIDI_OUT_STOP (9 + HDEX_BASE)
141#define HDEX_AUX_REQ (10 + HDEX_BASE)
142
143#define HIWORD(l) ((WORD)((((DWORD)(l)) >> 16) & 0xFFFF))
144#define LOWORD(l) ((WORD)(DWORD)(l))
145#define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
146#define LOBYTE(w) ((BYTE)(w))
147#define MAKELONG(low,hi) ((long)(((WORD)(low))|(((DWORD)((WORD)(hi)))<<16)))
148#define MAKEWORD(low,hi) ((WORD)(((BYTE)(low))|(((WORD)((BYTE)(hi)))<<8)))
149
150#define PCTODSP_OFFSET(w) (USHORT)((w)/2)
151#define PCTODSP_BASED(w) (USHORT)(((w)/2) + DSP_BASE_ADDR)
152#define DSPTOPC_BASED(w) (((w) - DSP_BASE_ADDR) * 2)
153
154#ifdef SLOWIO
155#define msnd_outb outb_p
156#define msnd_inb inb_p
157#else
158#define msnd_outb outb
159#define msnd_inb inb
160#endif
161
162/* JobQueueStruct */
163#define JQS_wStart 0x00
164#define JQS_wSize 0x02
165#define JQS_wHead 0x04
166#define JQS_wTail 0x06
167#define JQS__size 0x08
168
169/* DAQueueDataStruct */
170#define DAQDS_wStart 0x00
171#define DAQDS_wSize 0x02
172#define DAQDS_wFormat 0x04
173#define DAQDS_wSampleSize 0x06
174#define DAQDS_wChannels 0x08
175#define DAQDS_wSampleRate 0x0A
176#define DAQDS_wIntMsg 0x0C
177#define DAQDS_wFlags 0x0E
178#define DAQDS__size 0x10
179
180typedef u8 BYTE;
181typedef u16 USHORT;
182typedef u16 WORD;
183typedef u32 DWORD;
184typedef void __iomem * LPDAQD;
185
186/* Generic FIFO */
187typedef struct {
188 size_t n, len;
189 char *data;
190 int head, tail;
191} msnd_fifo;
192
193typedef struct multisound_dev {
194 /* Linux device info */
195 char *name;
196 int dsp_minor, mixer_minor;
197 int ext_midi_dev, hdr_midi_dev;
198
199 /* Hardware resources */
200 int io, numio;
201 int memid, irqid;
202 int irq, irq_ref;
203 unsigned char info;
204 void __iomem *base;
205
206 /* Motorola 56k DSP SMA */
207 void __iomem *SMA;
208 void __iomem *DAPQ, *DARQ, *MODQ, *MIDQ, *DSPQ;
209 void __iomem *pwDSPQData, *pwMIDQData, *pwMODQData;
210 int dspq_data_buff, dspq_buff_size;
211
212 /* State variables */
213 enum { msndClassic, msndPinnacle } type;
214 fmode_t mode;
215 unsigned long flags;
216#define F_RESETTING 0
217#define F_HAVEDIGITAL 1
218#define F_AUDIO_WRITE_INUSE 2
219#define F_WRITING 3
220#define F_WRITEBLOCK 4
221#define F_WRITEFLUSH 5
222#define F_AUDIO_READ_INUSE 6
223#define F_READING 7
224#define F_READBLOCK 8
225#define F_EXT_MIDI_INUSE 9
226#define F_HDR_MIDI_INUSE 10
227#define F_DISABLE_WRITE_NDELAY 11
228 wait_queue_head_t writeblock;
229 wait_queue_head_t readblock;
230 wait_queue_head_t writeflush;
231 spinlock_t lock;
232 int nresets;
233 unsigned long recsrc;
234 int left_levels[32];
235 int right_levels[32];
236 int mixer_mod_count;
237 int calibrate_signal;
238 int play_sample_size, play_sample_rate, play_channels;
239 int play_ndelay;
240 int rec_sample_size, rec_sample_rate, rec_channels;
241 int rec_ndelay;
242 BYTE bCurrentMidiPatch;
243
244 /* Digital audio FIFOs */
245 msnd_fifo DAPF, DARF;
246 int fifosize;
247 int last_playbank, last_recbank;
248
249 /* MIDI in callback */
250 void (*midi_in_interrupt)(struct multisound_dev *);
251} multisound_dev_t;
252
253#ifndef mdelay
254# define mdelay(a) udelay((a) * 1000)
255#endif
256
257int msnd_register(multisound_dev_t *dev);
258void msnd_unregister(multisound_dev_t *dev);
259
260void msnd_init_queue(void __iomem *, int start, int size);
261
262void msnd_fifo_init(msnd_fifo *f);
263void msnd_fifo_free(msnd_fifo *f);
264int msnd_fifo_alloc(msnd_fifo *f, size_t n);
265void msnd_fifo_make_empty(msnd_fifo *f);
266int msnd_fifo_write_io(msnd_fifo *f, char __iomem *buf, size_t len);
267int msnd_fifo_read_io(msnd_fifo *f, char __iomem *buf, size_t len);
268int msnd_fifo_write(msnd_fifo *f, const char *buf, size_t len);
269int msnd_fifo_read(msnd_fifo *f, char *buf, size_t len);
270
271int msnd_send_dsp_cmd(multisound_dev_t *dev, BYTE cmd);
272int msnd_send_word(multisound_dev_t *dev, unsigned char high,
273 unsigned char mid, unsigned char low);
274int msnd_upload_host(multisound_dev_t *dev, char *bin, int len);
275int msnd_enable_irq(multisound_dev_t *dev);
276int msnd_disable_irq(multisound_dev_t *dev);
277
278#endif /* __MSND_H */
diff --git a/sound/oss/msnd_classic.c b/sound/oss/msnd_classic.c
deleted file mode 100644
index 3b23a096fa4e..000000000000
--- a/sound/oss/msnd_classic.c
+++ /dev/null
@@ -1,3 +0,0 @@
1/* The work is in msnd_pinnacle.c, just define MSND_CLASSIC before it. */
2#define MSND_CLASSIC
3#include "msnd_pinnacle.c"
diff --git a/sound/oss/msnd_classic.h b/sound/oss/msnd_classic.h
deleted file mode 100644
index 1a17dde2f650..000000000000
--- a/sound/oss/msnd_classic.h
+++ /dev/null
@@ -1,185 +0,0 @@
1/*********************************************************************
2 *
3 * msnd_classic.h
4 *
5 * Turtle Beach MultiSound Sound Card Driver for Linux
6 *
7 * Some parts of this header file were derived from the Turtle Beach
8 * MultiSound Driver Development Kit.
9 *
10 * Copyright (C) 1998 Andrew Veliath
11 * Copyright (C) 1993 Turtle Beach Systems, Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 ********************************************************************/
28#ifndef __MSND_CLASSIC_H
29#define __MSND_CLASSIC_H
30
31
32#define DSP_NUMIO 0x10
33
34#define HP_MEMM 0x08
35
36#define HP_BITM 0x0E
37#define HP_WAIT 0x0D
38#define HP_DSPR 0x0A
39#define HP_PROR 0x0B
40#define HP_BLKS 0x0C
41
42#define HPPRORESET_OFF 0
43#define HPPRORESET_ON 1
44
45#define HPDSPRESET_OFF 0
46#define HPDSPRESET_ON 1
47
48#define HPBLKSEL_0 0
49#define HPBLKSEL_1 1
50
51#define HPWAITSTATE_0 0
52#define HPWAITSTATE_1 1
53
54#define HPBITMODE_16 0
55#define HPBITMODE_8 1
56
57#define HIDSP_INT_PLAY_UNDER 0x00
58#define HIDSP_INT_RECORD_OVER 0x01
59#define HIDSP_INPUT_CLIPPING 0x02
60#define HIDSP_MIDI_IN_OVER 0x10
61#define HIDSP_MIDI_OVERRUN_ERR 0x13
62
63#define HDEXAR_CLEAR_PEAKS 1
64#define HDEXAR_IN_SET_POTS 2
65#define HDEXAR_AUX_SET_POTS 3
66#define HDEXAR_CAL_A_TO_D 4
67#define HDEXAR_RD_EXT_DSP_BITS 5
68
69#define TIME_PRO_RESET_DONE 0x028A
70#define TIME_PRO_SYSEX 0x0040
71#define TIME_PRO_RESET 0x0032
72
73#define AGND 0x01
74#define SIGNAL 0x02
75
76#define EXT_DSP_BIT_DCAL 0x0001
77#define EXT_DSP_BIT_MIDI_CON 0x0002
78
79#define BUFFSIZE 0x8000
80#define HOSTQ_SIZE 0x40
81
82#define SRAM_CNTL_START 0x7F00
83#define SMA_STRUCT_START 0x7F40
84
85#define DAP_BUFF_SIZE 0x2400
86#define DAR_BUFF_SIZE 0x2000
87
88#define DAPQ_STRUCT_SIZE 0x10
89#define DARQ_STRUCT_SIZE 0x10
90#define DAPQ_BUFF_SIZE (3 * 0x10)
91#define DARQ_BUFF_SIZE (3 * 0x10)
92#define MODQ_BUFF_SIZE 0x400
93#define MIDQ_BUFF_SIZE 0x200
94#define DSPQ_BUFF_SIZE 0x40
95
96#define DAPQ_DATA_BUFF 0x6C00
97#define DARQ_DATA_BUFF 0x6C30
98#define MODQ_DATA_BUFF 0x6C60
99#define MIDQ_DATA_BUFF 0x7060
100#define DSPQ_DATA_BUFF 0x7260
101
102#define DAPQ_OFFSET SRAM_CNTL_START
103#define DARQ_OFFSET (SRAM_CNTL_START + 0x08)
104#define MODQ_OFFSET (SRAM_CNTL_START + 0x10)
105#define MIDQ_OFFSET (SRAM_CNTL_START + 0x18)
106#define DSPQ_OFFSET (SRAM_CNTL_START + 0x20)
107
108#define MOP_SYNTH 0x10
109#define MOP_EXTOUT 0x32
110#define MOP_EXTTHRU 0x02
111#define MOP_OUTMASK 0x01
112
113#define MIP_EXTIN 0x01
114#define MIP_SYNTH 0x00
115#define MIP_INMASK 0x32
116
117/* Classic SMA Common Data */
118#define SMA_wCurrPlayBytes 0x0000
119#define SMA_wCurrRecordBytes 0x0002
120#define SMA_wCurrPlayVolLeft 0x0004
121#define SMA_wCurrPlayVolRight 0x0006
122#define SMA_wCurrInVolLeft 0x0008
123#define SMA_wCurrInVolRight 0x000a
124#define SMA_wUser_3 0x000c
125#define SMA_wUser_4 0x000e
126#define SMA_dwUser_5 0x0010
127#define SMA_dwUser_6 0x0014
128#define SMA_wUser_7 0x0018
129#define SMA_wReserved_A 0x001a
130#define SMA_wReserved_B 0x001c
131#define SMA_wReserved_C 0x001e
132#define SMA_wReserved_D 0x0020
133#define SMA_wReserved_E 0x0022
134#define SMA_wReserved_F 0x0024
135#define SMA_wReserved_G 0x0026
136#define SMA_wReserved_H 0x0028
137#define SMA_wCurrDSPStatusFlags 0x002a
138#define SMA_wCurrHostStatusFlags 0x002c
139#define SMA_wCurrInputTagBits 0x002e
140#define SMA_wCurrLeftPeak 0x0030
141#define SMA_wCurrRightPeak 0x0032
142#define SMA_wExtDSPbits 0x0034
143#define SMA_bExtHostbits 0x0036
144#define SMA_bBoardLevel 0x0037
145#define SMA_bInPotPosRight 0x0038
146#define SMA_bInPotPosLeft 0x0039
147#define SMA_bAuxPotPosRight 0x003a
148#define SMA_bAuxPotPosLeft 0x003b
149#define SMA_wCurrMastVolLeft 0x003c
150#define SMA_wCurrMastVolRight 0x003e
151#define SMA_bUser_12 0x0040
152#define SMA_bUser_13 0x0041
153#define SMA_wUser_14 0x0042
154#define SMA_wUser_15 0x0044
155#define SMA_wCalFreqAtoD 0x0046
156#define SMA_wUser_16 0x0048
157#define SMA_wUser_17 0x004a
158#define SMA__size 0x004c
159
160#ifdef HAVE_DSPCODEH
161# include "msndperm.c"
162# include "msndinit.c"
163# define PERMCODE msndperm
164# define INITCODE msndinit
165# define PERMCODESIZE sizeof(msndperm)
166# define INITCODESIZE sizeof(msndinit)
167#else
168# ifndef CONFIG_MSNDCLAS_INIT_FILE
169# define CONFIG_MSNDCLAS_INIT_FILE \
170 "/etc/sound/msndinit.bin"
171# endif
172# ifndef CONFIG_MSNDCLAS_PERM_FILE
173# define CONFIG_MSNDCLAS_PERM_FILE \
174 "/etc/sound/msndperm.bin"
175# endif
176# define PERMCODEFILE CONFIG_MSNDCLAS_PERM_FILE
177# define INITCODEFILE CONFIG_MSNDCLAS_INIT_FILE
178# define PERMCODE dspini
179# define INITCODE permini
180# define PERMCODESIZE sizeof_dspini
181# define INITCODESIZE sizeof_permini
182#endif
183#define LONGNAME "MultiSound (Classic/Monterey/Tahiti)"
184
185#endif /* __MSND_CLASSIC_H */
diff --git a/sound/oss/msnd_pinnacle.c b/sound/oss/msnd_pinnacle.c
deleted file mode 100644
index d2abc2cf3213..000000000000
--- a/sound/oss/msnd_pinnacle.c
+++ /dev/null
@@ -1,1941 +0,0 @@
1/*********************************************************************
2 *
3 * Turtle Beach MultiSound Sound Card Driver for Linux
4 * Linux 2.0/2.2 Version
5 *
6 * msnd_pinnacle.c / msnd_classic.c
7 *
8 * -- If MSND_CLASSIC is defined:
9 *
10 * -> driver for Turtle Beach Classic/Monterey/Tahiti
11 *
12 * -- Else
13 *
14 * -> driver for Turtle Beach Pinnacle/Fiji
15 *
16 * Copyright (C) 1998 Andrew Veliath
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 *
32 * 12-3-2000 Modified IO port validation Steve Sycamore
33 *
34 ********************************************************************/
35
36#include <linux/kernel.h>
37#include <linux/module.h>
38#include <linux/types.h>
39#include <linux/delay.h>
40#include <linux/init.h>
41#include <linux/interrupt.h>
42#include <linux/mutex.h>
43#include <linux/gfp.h>
44#include <linux/sched/signal.h>
45
46#include <asm/irq.h>
47#include <asm/io.h>
48#include "sound_config.h"
49#include "sound_firmware.h"
50#ifdef MSND_CLASSIC
51# ifndef __alpha__
52# define SLOWIO
53# endif
54#endif
55#include "msnd.h"
56#ifdef MSND_CLASSIC
57# ifdef CONFIG_MSNDCLAS_HAVE_BOOT
58# define HAVE_DSPCODEH
59# endif
60# include "msnd_classic.h"
61# define LOGNAME "msnd_classic"
62#else
63# ifdef CONFIG_MSNDPIN_HAVE_BOOT
64# define HAVE_DSPCODEH
65# endif
66# include "msnd_pinnacle.h"
67# define LOGNAME "msnd_pinnacle"
68#endif
69
70#ifndef CONFIG_MSND_WRITE_NDELAY
71# define CONFIG_MSND_WRITE_NDELAY 1
72#endif
73
74#define get_play_delay_jiffies(size) ((size) * HZ * \
75 dev.play_sample_size / 8 / \
76 dev.play_sample_rate / \
77 dev.play_channels)
78
79#define get_rec_delay_jiffies(size) ((size) * HZ * \
80 dev.rec_sample_size / 8 / \
81 dev.rec_sample_rate / \
82 dev.rec_channels)
83
84static DEFINE_MUTEX(msnd_pinnacle_mutex);
85static multisound_dev_t dev;
86
87#ifndef HAVE_DSPCODEH
88static char *dspini, *permini;
89static int sizeof_dspini, sizeof_permini;
90#endif
91
92static int dsp_full_reset(void);
93static void dsp_write_flush(void);
94
95static __inline__ int chk_send_dsp_cmd(multisound_dev_t *dev, register BYTE cmd)
96{
97 if (msnd_send_dsp_cmd(dev, cmd) == 0)
98 return 0;
99 dsp_full_reset();
100 return msnd_send_dsp_cmd(dev, cmd);
101}
102
103static void reset_play_queue(void)
104{
105 int n;
106 LPDAQD lpDAQ;
107
108 dev.last_playbank = -1;
109 writew(PCTODSP_OFFSET(0 * DAQDS__size), dev.DAPQ + JQS_wHead);
110 writew(PCTODSP_OFFSET(0 * DAQDS__size), dev.DAPQ + JQS_wTail);
111
112 for (n = 0, lpDAQ = dev.base + DAPQ_DATA_BUFF; n < 3; ++n, lpDAQ += DAQDS__size) {
113 writew(PCTODSP_BASED((DWORD)(DAP_BUFF_SIZE * n)), lpDAQ + DAQDS_wStart);
114 writew(0, lpDAQ + DAQDS_wSize);
115 writew(1, lpDAQ + DAQDS_wFormat);
116 writew(dev.play_sample_size, lpDAQ + DAQDS_wSampleSize);
117 writew(dev.play_channels, lpDAQ + DAQDS_wChannels);
118 writew(dev.play_sample_rate, lpDAQ + DAQDS_wSampleRate);
119 writew(HIMT_PLAY_DONE * 0x100 + n, lpDAQ + DAQDS_wIntMsg);
120 writew(n, lpDAQ + DAQDS_wFlags);
121 }
122}
123
124static void reset_record_queue(void)
125{
126 int n;
127 LPDAQD lpDAQ;
128 unsigned long flags;
129
130 dev.last_recbank = 2;
131 writew(PCTODSP_OFFSET(0 * DAQDS__size), dev.DARQ + JQS_wHead);
132 writew(PCTODSP_OFFSET(dev.last_recbank * DAQDS__size), dev.DARQ + JQS_wTail);
133
134 /* Critical section: bank 1 access */
135 spin_lock_irqsave(&dev.lock, flags);
136 msnd_outb(HPBLKSEL_1, dev.io + HP_BLKS);
137 memset_io(dev.base, 0, DAR_BUFF_SIZE * 3);
138 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
139 spin_unlock_irqrestore(&dev.lock, flags);
140
141 for (n = 0, lpDAQ = dev.base + DARQ_DATA_BUFF; n < 3; ++n, lpDAQ += DAQDS__size) {
142 writew(PCTODSP_BASED((DWORD)(DAR_BUFF_SIZE * n)) + 0x4000, lpDAQ + DAQDS_wStart);
143 writew(DAR_BUFF_SIZE, lpDAQ + DAQDS_wSize);
144 writew(1, lpDAQ + DAQDS_wFormat);
145 writew(dev.rec_sample_size, lpDAQ + DAQDS_wSampleSize);
146 writew(dev.rec_channels, lpDAQ + DAQDS_wChannels);
147 writew(dev.rec_sample_rate, lpDAQ + DAQDS_wSampleRate);
148 writew(HIMT_RECORD_DONE * 0x100 + n, lpDAQ + DAQDS_wIntMsg);
149 writew(n, lpDAQ + DAQDS_wFlags);
150 }
151}
152
153static void reset_queues(void)
154{
155 if (dev.mode & FMODE_WRITE) {
156 msnd_fifo_make_empty(&dev.DAPF);
157 reset_play_queue();
158 }
159 if (dev.mode & FMODE_READ) {
160 msnd_fifo_make_empty(&dev.DARF);
161 reset_record_queue();
162 }
163}
164
165static int dsp_set_format(struct file *file, int val)
166{
167 int data, i;
168 LPDAQD lpDAQ, lpDARQ;
169
170 lpDAQ = dev.base + DAPQ_DATA_BUFF;
171 lpDARQ = dev.base + DARQ_DATA_BUFF;
172
173 switch (val) {
174 case AFMT_U8:
175 case AFMT_S16_LE:
176 data = val;
177 break;
178 default:
179 data = DEFSAMPLESIZE;
180 break;
181 }
182
183 for (i = 0; i < 3; ++i, lpDAQ += DAQDS__size, lpDARQ += DAQDS__size) {
184 if (file->f_mode & FMODE_WRITE)
185 writew(data, lpDAQ + DAQDS_wSampleSize);
186 if (file->f_mode & FMODE_READ)
187 writew(data, lpDARQ + DAQDS_wSampleSize);
188 }
189 if (file->f_mode & FMODE_WRITE)
190 dev.play_sample_size = data;
191 if (file->f_mode & FMODE_READ)
192 dev.rec_sample_size = data;
193
194 return data;
195}
196
197static int dsp_get_frag_size(void)
198{
199 int size;
200 size = dev.fifosize / 4;
201 if (size > 32 * 1024)
202 size = 32 * 1024;
203 return size;
204}
205
206static int dsp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
207{
208 int val, i, data, tmp;
209 LPDAQD lpDAQ, lpDARQ;
210 audio_buf_info abinfo;
211 unsigned long flags;
212 int __user *p = (int __user *)arg;
213
214 lpDAQ = dev.base + DAPQ_DATA_BUFF;
215 lpDARQ = dev.base + DARQ_DATA_BUFF;
216
217 switch (cmd) {
218 case SNDCTL_DSP_SUBDIVIDE:
219 case SNDCTL_DSP_SETFRAGMENT:
220 case SNDCTL_DSP_SETDUPLEX:
221 case SNDCTL_DSP_POST:
222 return 0;
223
224 case SNDCTL_DSP_GETIPTR:
225 case SNDCTL_DSP_GETOPTR:
226 case SNDCTL_DSP_MAPINBUF:
227 case SNDCTL_DSP_MAPOUTBUF:
228 return -EINVAL;
229
230 case SNDCTL_DSP_GETOSPACE:
231 if (!(file->f_mode & FMODE_WRITE))
232 return -EINVAL;
233 spin_lock_irqsave(&dev.lock, flags);
234 abinfo.fragsize = dsp_get_frag_size();
235 abinfo.bytes = dev.DAPF.n - dev.DAPF.len;
236 abinfo.fragstotal = dev.DAPF.n / abinfo.fragsize;
237 abinfo.fragments = abinfo.bytes / abinfo.fragsize;
238 spin_unlock_irqrestore(&dev.lock, flags);
239 return copy_to_user((void __user *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
240
241 case SNDCTL_DSP_GETISPACE:
242 if (!(file->f_mode & FMODE_READ))
243 return -EINVAL;
244 spin_lock_irqsave(&dev.lock, flags);
245 abinfo.fragsize = dsp_get_frag_size();
246 abinfo.bytes = dev.DARF.n - dev.DARF.len;
247 abinfo.fragstotal = dev.DARF.n / abinfo.fragsize;
248 abinfo.fragments = abinfo.bytes / abinfo.fragsize;
249 spin_unlock_irqrestore(&dev.lock, flags);
250 return copy_to_user((void __user *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
251
252 case SNDCTL_DSP_RESET:
253 dev.nresets = 0;
254 reset_queues();
255 return 0;
256
257 case SNDCTL_DSP_SYNC:
258 dsp_write_flush();
259 return 0;
260
261 case SNDCTL_DSP_GETBLKSIZE:
262 tmp = dsp_get_frag_size();
263 if (put_user(tmp, p))
264 return -EFAULT;
265 return 0;
266
267 case SNDCTL_DSP_GETFMTS:
268 val = AFMT_S16_LE | AFMT_U8;
269 if (put_user(val, p))
270 return -EFAULT;
271 return 0;
272
273 case SNDCTL_DSP_SETFMT:
274 if (get_user(val, p))
275 return -EFAULT;
276
277 if (file->f_mode & FMODE_WRITE)
278 data = val == AFMT_QUERY
279 ? dev.play_sample_size
280 : dsp_set_format(file, val);
281 else
282 data = val == AFMT_QUERY
283 ? dev.rec_sample_size
284 : dsp_set_format(file, val);
285
286 if (put_user(data, p))
287 return -EFAULT;
288 return 0;
289
290 case SNDCTL_DSP_NONBLOCK:
291 if (!test_bit(F_DISABLE_WRITE_NDELAY, &dev.flags) &&
292 file->f_mode & FMODE_WRITE)
293 dev.play_ndelay = 1;
294 if (file->f_mode & FMODE_READ)
295 dev.rec_ndelay = 1;
296 return 0;
297
298 case SNDCTL_DSP_GETCAPS:
299 val = DSP_CAP_DUPLEX | DSP_CAP_BATCH;
300 if (put_user(val, p))
301 return -EFAULT;
302 return 0;
303
304 case SNDCTL_DSP_SPEED:
305 if (get_user(val, p))
306 return -EFAULT;
307
308 if (val < 8000)
309 val = 8000;
310
311 if (val > 48000)
312 val = 48000;
313
314 data = val;
315
316 for (i = 0; i < 3; ++i, lpDAQ += DAQDS__size, lpDARQ += DAQDS__size) {
317 if (file->f_mode & FMODE_WRITE)
318 writew(data, lpDAQ + DAQDS_wSampleRate);
319 if (file->f_mode & FMODE_READ)
320 writew(data, lpDARQ + DAQDS_wSampleRate);
321 }
322 if (file->f_mode & FMODE_WRITE)
323 dev.play_sample_rate = data;
324 if (file->f_mode & FMODE_READ)
325 dev.rec_sample_rate = data;
326
327 if (put_user(data, p))
328 return -EFAULT;
329 return 0;
330
331 case SNDCTL_DSP_CHANNELS:
332 case SNDCTL_DSP_STEREO:
333 if (get_user(val, p))
334 return -EFAULT;
335
336 if (cmd == SNDCTL_DSP_CHANNELS) {
337 switch (val) {
338 case 1:
339 case 2:
340 data = val;
341 break;
342 default:
343 val = data = 2;
344 break;
345 }
346 } else {
347 switch (val) {
348 case 0:
349 data = 1;
350 break;
351 default:
352 val = 1;
353 case 1:
354 data = 2;
355 break;
356 }
357 }
358
359 for (i = 0; i < 3; ++i, lpDAQ += DAQDS__size, lpDARQ += DAQDS__size) {
360 if (file->f_mode & FMODE_WRITE)
361 writew(data, lpDAQ + DAQDS_wChannels);
362 if (file->f_mode & FMODE_READ)
363 writew(data, lpDARQ + DAQDS_wChannels);
364 }
365 if (file->f_mode & FMODE_WRITE)
366 dev.play_channels = data;
367 if (file->f_mode & FMODE_READ)
368 dev.rec_channels = data;
369
370 if (put_user(val, p))
371 return -EFAULT;
372 return 0;
373 }
374
375 return -EINVAL;
376}
377
378static int mixer_get(int d)
379{
380 if (d > 31)
381 return -EINVAL;
382
383 switch (d) {
384 case SOUND_MIXER_VOLUME:
385 case SOUND_MIXER_PCM:
386 case SOUND_MIXER_LINE:
387 case SOUND_MIXER_IMIX:
388 case SOUND_MIXER_LINE1:
389#ifndef MSND_CLASSIC
390 case SOUND_MIXER_MIC:
391 case SOUND_MIXER_SYNTH:
392#endif
393 return (dev.left_levels[d] >> 8) * 100 / 0xff |
394 (((dev.right_levels[d] >> 8) * 100 / 0xff) << 8);
395 default:
396 return 0;
397 }
398}
399
400#define update_volm(a,b) \
401 writew((dev.left_levels[a] >> 1) * \
402 readw(dev.SMA + SMA_wCurrMastVolLeft) / 0xffff, \
403 dev.SMA + SMA_##b##Left); \
404 writew((dev.right_levels[a] >> 1) * \
405 readw(dev.SMA + SMA_wCurrMastVolRight) / 0xffff, \
406 dev.SMA + SMA_##b##Right);
407
408#define update_potm(d,s,ar) \
409 writeb((dev.left_levels[d] >> 8) * \
410 readw(dev.SMA + SMA_wCurrMastVolLeft) / 0xffff, \
411 dev.SMA + SMA_##s##Left); \
412 writeb((dev.right_levels[d] >> 8) * \
413 readw(dev.SMA + SMA_wCurrMastVolRight) / 0xffff, \
414 dev.SMA + SMA_##s##Right); \
415 if (msnd_send_word(&dev, 0, 0, ar) == 0) \
416 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
417
418#define update_pot(d,s,ar) \
419 writeb(dev.left_levels[d] >> 8, \
420 dev.SMA + SMA_##s##Left); \
421 writeb(dev.right_levels[d] >> 8, \
422 dev.SMA + SMA_##s##Right); \
423 if (msnd_send_word(&dev, 0, 0, ar) == 0) \
424 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
425
426static int mixer_set(int d, int value)
427{
428 int left = value & 0x000000ff;
429 int right = (value & 0x0000ff00) >> 8;
430 int bLeft, bRight;
431 int wLeft, wRight;
432 int updatemaster = 0;
433
434 if (d > 31)
435 return -EINVAL;
436
437 bLeft = left * 0xff / 100;
438 wLeft = left * 0xffff / 100;
439
440 bRight = right * 0xff / 100;
441 wRight = right * 0xffff / 100;
442
443 dev.left_levels[d] = wLeft;
444 dev.right_levels[d] = wRight;
445
446 switch (d) {
447 /* master volume unscaled controls */
448 case SOUND_MIXER_LINE: /* line pot control */
449 /* scaled by IMIX in digital mix */
450 writeb(bLeft, dev.SMA + SMA_bInPotPosLeft);
451 writeb(bRight, dev.SMA + SMA_bInPotPosRight);
452 if (msnd_send_word(&dev, 0, 0, HDEXAR_IN_SET_POTS) == 0)
453 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
454 break;
455#ifndef MSND_CLASSIC
456 case SOUND_MIXER_MIC: /* mic pot control */
457 /* scaled by IMIX in digital mix */
458 writeb(bLeft, dev.SMA + SMA_bMicPotPosLeft);
459 writeb(bRight, dev.SMA + SMA_bMicPotPosRight);
460 if (msnd_send_word(&dev, 0, 0, HDEXAR_MIC_SET_POTS) == 0)
461 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
462 break;
463#endif
464 case SOUND_MIXER_VOLUME: /* master volume */
465 writew(wLeft, dev.SMA + SMA_wCurrMastVolLeft);
466 writew(wRight, dev.SMA + SMA_wCurrMastVolRight);
467 /* fall through */
468
469 case SOUND_MIXER_LINE1: /* aux pot control */
470 /* scaled by master volume */
471 /* fall through */
472
473 /* digital controls */
474 case SOUND_MIXER_SYNTH: /* synth vol (dsp mix) */
475 case SOUND_MIXER_PCM: /* pcm vol (dsp mix) */
476 case SOUND_MIXER_IMIX: /* input monitor (dsp mix) */
477 /* scaled by master volume */
478 updatemaster = 1;
479 break;
480
481 default:
482 return 0;
483 }
484
485 if (updatemaster) {
486 /* update master volume scaled controls */
487 update_volm(SOUND_MIXER_PCM, wCurrPlayVol);
488 update_volm(SOUND_MIXER_IMIX, wCurrInVol);
489#ifndef MSND_CLASSIC
490 update_volm(SOUND_MIXER_SYNTH, wCurrMHdrVol);
491#endif
492 update_potm(SOUND_MIXER_LINE1, bAuxPotPos, HDEXAR_AUX_SET_POTS);
493 }
494
495 return mixer_get(d);
496}
497
498static void mixer_setup(void)
499{
500 update_pot(SOUND_MIXER_LINE, bInPotPos, HDEXAR_IN_SET_POTS);
501 update_potm(SOUND_MIXER_LINE1, bAuxPotPos, HDEXAR_AUX_SET_POTS);
502 update_volm(SOUND_MIXER_PCM, wCurrPlayVol);
503 update_volm(SOUND_MIXER_IMIX, wCurrInVol);
504#ifndef MSND_CLASSIC
505 update_pot(SOUND_MIXER_MIC, bMicPotPos, HDEXAR_MIC_SET_POTS);
506 update_volm(SOUND_MIXER_SYNTH, wCurrMHdrVol);
507#endif
508}
509
510static unsigned long set_recsrc(unsigned long recsrc)
511{
512 if (dev.recsrc == recsrc)
513 return dev.recsrc;
514#ifdef HAVE_NORECSRC
515 else if (recsrc == 0)
516 dev.recsrc = 0;
517#endif
518 else
519 dev.recsrc ^= recsrc;
520
521#ifndef MSND_CLASSIC
522 if (dev.recsrc & SOUND_MASK_IMIX) {
523 if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_ANA_IN) == 0)
524 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
525 }
526 else if (dev.recsrc & SOUND_MASK_SYNTH) {
527 if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_SYNTH_IN) == 0)
528 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
529 }
530 else if ((dev.recsrc & SOUND_MASK_DIGITAL1) && test_bit(F_HAVEDIGITAL, &dev.flags)) {
531 if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_DAT_IN) == 0)
532 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
533 }
534 else {
535#ifdef HAVE_NORECSRC
536 /* Select no input (?) */
537 dev.recsrc = 0;
538#else
539 dev.recsrc = SOUND_MASK_IMIX;
540 if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_ANA_IN) == 0)
541 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
542#endif
543 }
544#endif /* MSND_CLASSIC */
545
546 return dev.recsrc;
547}
548
549static unsigned long force_recsrc(unsigned long recsrc)
550{
551 dev.recsrc = 0;
552 return set_recsrc(recsrc);
553}
554
555#define set_mixer_info() \
556 memset(&info, 0, sizeof(info)); \
557 strlcpy(info.id, "MSNDMIXER", sizeof(info.id)); \
558 strlcpy(info.name, "MultiSound Mixer", sizeof(info.name));
559
560static int mixer_ioctl(unsigned int cmd, unsigned long arg)
561{
562 if (cmd == SOUND_MIXER_INFO) {
563 mixer_info info;
564 set_mixer_info();
565 info.modify_counter = dev.mixer_mod_count;
566 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
567 return -EFAULT;
568 return 0;
569 } else if (cmd == SOUND_OLD_MIXER_INFO) {
570 _old_mixer_info info;
571 set_mixer_info();
572 if (copy_to_user((void __user *)arg, &info, sizeof(info)))
573 return -EFAULT;
574 return 0;
575 } else if (cmd == SOUND_MIXER_PRIVATE1) {
576 dev.nresets = 0;
577 dsp_full_reset();
578 return 0;
579 } else if (((cmd >> 8) & 0xff) == 'M') {
580 int val = 0;
581
582 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
583 switch (cmd & 0xff) {
584 case SOUND_MIXER_RECSRC:
585 if (get_user(val, (int __user *)arg))
586 return -EFAULT;
587 val = set_recsrc(val);
588 break;
589
590 default:
591 if (get_user(val, (int __user *)arg))
592 return -EFAULT;
593 val = mixer_set(cmd & 0xff, val);
594 break;
595 }
596 ++dev.mixer_mod_count;
597 return put_user(val, (int __user *)arg);
598 } else {
599 switch (cmd & 0xff) {
600 case SOUND_MIXER_RECSRC:
601 val = dev.recsrc;
602 break;
603
604 case SOUND_MIXER_DEVMASK:
605 case SOUND_MIXER_STEREODEVS:
606 val = SOUND_MASK_PCM |
607 SOUND_MASK_LINE |
608 SOUND_MASK_IMIX |
609 SOUND_MASK_LINE1 |
610#ifndef MSND_CLASSIC
611 SOUND_MASK_MIC |
612 SOUND_MASK_SYNTH |
613#endif
614 SOUND_MASK_VOLUME;
615 break;
616
617 case SOUND_MIXER_RECMASK:
618#ifdef MSND_CLASSIC
619 val = 0;
620#else
621 val = SOUND_MASK_IMIX |
622 SOUND_MASK_SYNTH;
623 if (test_bit(F_HAVEDIGITAL, &dev.flags))
624 val |= SOUND_MASK_DIGITAL1;
625#endif
626 break;
627
628 case SOUND_MIXER_CAPS:
629 val = SOUND_CAP_EXCL_INPUT;
630 break;
631
632 default:
633 if ((val = mixer_get(cmd & 0xff)) < 0)
634 return -EINVAL;
635 break;
636 }
637 }
638
639 return put_user(val, (int __user *)arg);
640 }
641
642 return -EINVAL;
643}
644
645static long dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
646{
647 int minor = iminor(file_inode(file));
648 int ret;
649
650 if (cmd == OSS_GETVERSION) {
651 int sound_version = SOUND_VERSION;
652 return put_user(sound_version, (int __user *)arg);
653 }
654
655 ret = -EINVAL;
656
657 mutex_lock(&msnd_pinnacle_mutex);
658 if (minor == dev.dsp_minor)
659 ret = dsp_ioctl(file, cmd, arg);
660 else if (minor == dev.mixer_minor)
661 ret = mixer_ioctl(cmd, arg);
662 mutex_unlock(&msnd_pinnacle_mutex);
663
664 return ret;
665}
666
667static void dsp_write_flush(void)
668{
669 int timeout = get_play_delay_jiffies(dev.DAPF.len);
670
671 if (!(dev.mode & FMODE_WRITE) || !test_bit(F_WRITING, &dev.flags))
672 return;
673 set_bit(F_WRITEFLUSH, &dev.flags);
674 wait_event_interruptible_timeout(
675 dev.writeflush,
676 !test_bit(F_WRITEFLUSH, &dev.flags),
677 timeout);
678 clear_bit(F_WRITEFLUSH, &dev.flags);
679 if (!signal_pending(current)) {
680 __set_current_state(TASK_INTERRUPTIBLE);
681 schedule_timeout(get_play_delay_jiffies(DAP_BUFF_SIZE));
682 }
683 clear_bit(F_WRITING, &dev.flags);
684}
685
686static void dsp_halt(struct file *file)
687{
688 if ((file ? file->f_mode : dev.mode) & FMODE_READ) {
689 clear_bit(F_READING, &dev.flags);
690 chk_send_dsp_cmd(&dev, HDEX_RECORD_STOP);
691 msnd_disable_irq(&dev);
692 if (file) {
693 printk(KERN_DEBUG LOGNAME ": Stopping read for %p\n", file);
694 dev.mode &= ~FMODE_READ;
695 }
696 clear_bit(F_AUDIO_READ_INUSE, &dev.flags);
697 }
698 if ((file ? file->f_mode : dev.mode) & FMODE_WRITE) {
699 if (test_bit(F_WRITING, &dev.flags)) {
700 dsp_write_flush();
701 chk_send_dsp_cmd(&dev, HDEX_PLAY_STOP);
702 }
703 msnd_disable_irq(&dev);
704 if (file) {
705 printk(KERN_DEBUG LOGNAME ": Stopping write for %p\n", file);
706 dev.mode &= ~FMODE_WRITE;
707 }
708 clear_bit(F_AUDIO_WRITE_INUSE, &dev.flags);
709 }
710}
711
712static int dsp_release(struct file *file)
713{
714 dsp_halt(file);
715 return 0;
716}
717
718static int dsp_open(struct file *file)
719{
720 if ((file ? file->f_mode : dev.mode) & FMODE_WRITE) {
721 set_bit(F_AUDIO_WRITE_INUSE, &dev.flags);
722 clear_bit(F_WRITING, &dev.flags);
723 msnd_fifo_make_empty(&dev.DAPF);
724 reset_play_queue();
725 if (file) {
726 printk(KERN_DEBUG LOGNAME ": Starting write for %p\n", file);
727 dev.mode |= FMODE_WRITE;
728 }
729 msnd_enable_irq(&dev);
730 }
731 if ((file ? file->f_mode : dev.mode) & FMODE_READ) {
732 set_bit(F_AUDIO_READ_INUSE, &dev.flags);
733 clear_bit(F_READING, &dev.flags);
734 msnd_fifo_make_empty(&dev.DARF);
735 reset_record_queue();
736 if (file) {
737 printk(KERN_DEBUG LOGNAME ": Starting read for %p\n", file);
738 dev.mode |= FMODE_READ;
739 }
740 msnd_enable_irq(&dev);
741 }
742 return 0;
743}
744
745static void set_default_play_audio_parameters(void)
746{
747 dev.play_sample_size = DEFSAMPLESIZE;
748 dev.play_sample_rate = DEFSAMPLERATE;
749 dev.play_channels = DEFCHANNELS;
750}
751
752static void set_default_rec_audio_parameters(void)
753{
754 dev.rec_sample_size = DEFSAMPLESIZE;
755 dev.rec_sample_rate = DEFSAMPLERATE;
756 dev.rec_channels = DEFCHANNELS;
757}
758
759static void set_default_audio_parameters(void)
760{
761 set_default_play_audio_parameters();
762 set_default_rec_audio_parameters();
763}
764
765static int dev_open(struct inode *inode, struct file *file)
766{
767 int minor = iminor(inode);
768 int err = 0;
769
770 mutex_lock(&msnd_pinnacle_mutex);
771 if (minor == dev.dsp_minor) {
772 if ((file->f_mode & FMODE_WRITE &&
773 test_bit(F_AUDIO_WRITE_INUSE, &dev.flags)) ||
774 (file->f_mode & FMODE_READ &&
775 test_bit(F_AUDIO_READ_INUSE, &dev.flags))) {
776 err = -EBUSY;
777 goto out;
778 }
779
780 if ((err = dsp_open(file)) >= 0) {
781 dev.nresets = 0;
782 if (file->f_mode & FMODE_WRITE) {
783 set_default_play_audio_parameters();
784 if (!test_bit(F_DISABLE_WRITE_NDELAY, &dev.flags))
785 dev.play_ndelay = (file->f_flags & O_NDELAY) ? 1 : 0;
786 else
787 dev.play_ndelay = 0;
788 }
789 if (file->f_mode & FMODE_READ) {
790 set_default_rec_audio_parameters();
791 dev.rec_ndelay = (file->f_flags & O_NDELAY) ? 1 : 0;
792 }
793 }
794 }
795 else if (minor == dev.mixer_minor) {
796 /* nothing */
797 } else
798 err = -EINVAL;
799out:
800 mutex_unlock(&msnd_pinnacle_mutex);
801 return err;
802}
803
804static int dev_release(struct inode *inode, struct file *file)
805{
806 int minor = iminor(inode);
807 int err = 0;
808
809 mutex_lock(&msnd_pinnacle_mutex);
810 if (minor == dev.dsp_minor)
811 err = dsp_release(file);
812 else if (minor == dev.mixer_minor) {
813 /* nothing */
814 } else
815 err = -EINVAL;
816 mutex_unlock(&msnd_pinnacle_mutex);
817 return err;
818}
819
820static __inline__ int pack_DARQ_to_DARF(register int bank)
821{
822 register int size, timeout = 3;
823 register WORD wTmp;
824 LPDAQD DAQD;
825
826 /* Increment the tail and check for queue wrap */
827 wTmp = readw(dev.DARQ + JQS_wTail) + PCTODSP_OFFSET(DAQDS__size);
828 if (wTmp > readw(dev.DARQ + JQS_wSize))
829 wTmp = 0;
830 while (wTmp == readw(dev.DARQ + JQS_wHead) && timeout--)
831 udelay(1);
832 writew(wTmp, dev.DARQ + JQS_wTail);
833
834 /* Get our digital audio queue struct */
835 DAQD = bank * DAQDS__size + dev.base + DARQ_DATA_BUFF;
836
837 /* Get length of data */
838 size = readw(DAQD + DAQDS_wSize);
839
840 /* Read data from the head (unprotected bank 1 access okay
841 since this is only called inside an interrupt) */
842 msnd_outb(HPBLKSEL_1, dev.io + HP_BLKS);
843 msnd_fifo_write_io(
844 &dev.DARF,
845 dev.base + bank * DAR_BUFF_SIZE,
846 size);
847 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
848
849 return 1;
850}
851
852static __inline__ int pack_DAPF_to_DAPQ(register int start)
853{
854 register WORD DAPQ_tail;
855 register int protect = start, nbanks = 0;
856 LPDAQD DAQD;
857
858 DAPQ_tail = readw(dev.DAPQ + JQS_wTail);
859 while (DAPQ_tail != readw(dev.DAPQ + JQS_wHead) || start) {
860 register int bank_num = DAPQ_tail / PCTODSP_OFFSET(DAQDS__size);
861 register int n;
862 unsigned long flags;
863
864 /* Write the data to the new tail */
865 if (protect) {
866 /* Critical section: protect fifo in non-interrupt */
867 spin_lock_irqsave(&dev.lock, flags);
868 n = msnd_fifo_read_io(
869 &dev.DAPF,
870 dev.base + bank_num * DAP_BUFF_SIZE,
871 DAP_BUFF_SIZE);
872 spin_unlock_irqrestore(&dev.lock, flags);
873 } else {
874 n = msnd_fifo_read_io(
875 &dev.DAPF,
876 dev.base + bank_num * DAP_BUFF_SIZE,
877 DAP_BUFF_SIZE);
878 }
879 if (!n)
880 break;
881
882 if (start)
883 start = 0;
884
885 /* Get our digital audio queue struct */
886 DAQD = bank_num * DAQDS__size + dev.base + DAPQ_DATA_BUFF;
887
888 /* Write size of this bank */
889 writew(n, DAQD + DAQDS_wSize);
890 ++nbanks;
891
892 /* Then advance the tail */
893 DAPQ_tail = (++bank_num % 3) * PCTODSP_OFFSET(DAQDS__size);
894 writew(DAPQ_tail, dev.DAPQ + JQS_wTail);
895 /* Tell the DSP to play the bank */
896 msnd_send_dsp_cmd(&dev, HDEX_PLAY_START);
897 }
898 return nbanks;
899}
900
901static int dsp_read(char __user *buf, size_t len)
902{
903 int count = len;
904 char *page = (char *)__get_free_page(GFP_KERNEL);
905 int timeout = get_rec_delay_jiffies(DAR_BUFF_SIZE);
906
907 if (!page)
908 return -ENOMEM;
909
910 while (count > 0) {
911 int n, k;
912 unsigned long flags;
913
914 k = PAGE_SIZE;
915 if (k > count)
916 k = count;
917
918 /* Critical section: protect fifo in non-interrupt */
919 spin_lock_irqsave(&dev.lock, flags);
920 n = msnd_fifo_read(&dev.DARF, page, k);
921 spin_unlock_irqrestore(&dev.lock, flags);
922 if (copy_to_user(buf, page, n)) {
923 free_page((unsigned long)page);
924 return -EFAULT;
925 }
926 buf += n;
927 count -= n;
928
929 if (n == k && count)
930 continue;
931
932 if (!test_bit(F_READING, &dev.flags) && dev.mode & FMODE_READ) {
933 dev.last_recbank = -1;
934 if (chk_send_dsp_cmd(&dev, HDEX_RECORD_START) == 0)
935 set_bit(F_READING, &dev.flags);
936 }
937
938 if (dev.rec_ndelay) {
939 free_page((unsigned long)page);
940 return count == len ? -EAGAIN : len - count;
941 }
942
943 if (count > 0) {
944 set_bit(F_READBLOCK, &dev.flags);
945 if (wait_event_interruptible_timeout(
946 dev.readblock,
947 test_bit(F_READBLOCK, &dev.flags),
948 timeout) <= 0)
949 clear_bit(F_READING, &dev.flags);
950 if (signal_pending(current)) {
951 free_page((unsigned long)page);
952 return -EINTR;
953 }
954 }
955 }
956 free_page((unsigned long)page);
957 return len - count;
958}
959
960static int dsp_write(const char __user *buf, size_t len)
961{
962 int count = len;
963 char *page = (char *)__get_free_page(GFP_KERNEL);
964 int timeout = get_play_delay_jiffies(DAP_BUFF_SIZE);
965
966 if (!page)
967 return -ENOMEM;
968
969 while (count > 0) {
970 int n, k;
971 unsigned long flags;
972
973 k = PAGE_SIZE;
974 if (k > count)
975 k = count;
976
977 if (copy_from_user(page, buf, k)) {
978 free_page((unsigned long)page);
979 return -EFAULT;
980 }
981
982 /* Critical section: protect fifo in non-interrupt */
983 spin_lock_irqsave(&dev.lock, flags);
984 n = msnd_fifo_write(&dev.DAPF, page, k);
985 spin_unlock_irqrestore(&dev.lock, flags);
986 buf += n;
987 count -= n;
988
989 if (count && n == k)
990 continue;
991
992 if (!test_bit(F_WRITING, &dev.flags) && (dev.mode & FMODE_WRITE)) {
993 dev.last_playbank = -1;
994 if (pack_DAPF_to_DAPQ(1) > 0)
995 set_bit(F_WRITING, &dev.flags);
996 }
997
998 if (dev.play_ndelay) {
999 free_page((unsigned long)page);
1000 return count == len ? -EAGAIN : len - count;
1001 }
1002
1003 if (count > 0) {
1004 set_bit(F_WRITEBLOCK, &dev.flags);
1005 wait_event_interruptible_timeout(
1006 dev.writeblock,
1007 test_bit(F_WRITEBLOCK, &dev.flags),
1008 timeout);
1009 if (signal_pending(current)) {
1010 free_page((unsigned long)page);
1011 return -EINTR;
1012 }
1013 }
1014 }
1015
1016 free_page((unsigned long)page);
1017 return len - count;
1018}
1019
1020static ssize_t dev_read(struct file *file, char __user *buf, size_t count, loff_t *off)
1021{
1022 int minor = iminor(file_inode(file));
1023 if (minor == dev.dsp_minor)
1024 return dsp_read(buf, count);
1025 else
1026 return -EINVAL;
1027}
1028
1029static ssize_t dev_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
1030{
1031 int minor = iminor(file_inode(file));
1032 if (minor == dev.dsp_minor)
1033 return dsp_write(buf, count);
1034 else
1035 return -EINVAL;
1036}
1037
1038static __inline__ void eval_dsp_msg(register WORD wMessage)
1039{
1040 switch (HIBYTE(wMessage)) {
1041 case HIMT_PLAY_DONE:
1042 if (dev.last_playbank == LOBYTE(wMessage) || !test_bit(F_WRITING, &dev.flags))
1043 break;
1044 dev.last_playbank = LOBYTE(wMessage);
1045
1046 if (pack_DAPF_to_DAPQ(0) <= 0) {
1047 if (!test_bit(F_WRITEBLOCK, &dev.flags)) {
1048 if (test_and_clear_bit(F_WRITEFLUSH, &dev.flags))
1049 wake_up_interruptible(&dev.writeflush);
1050 }
1051 clear_bit(F_WRITING, &dev.flags);
1052 }
1053
1054 if (test_and_clear_bit(F_WRITEBLOCK, &dev.flags))
1055 wake_up_interruptible(&dev.writeblock);
1056 break;
1057
1058 case HIMT_RECORD_DONE:
1059 if (dev.last_recbank == LOBYTE(wMessage))
1060 break;
1061 dev.last_recbank = LOBYTE(wMessage);
1062
1063 pack_DARQ_to_DARF(dev.last_recbank);
1064
1065 if (test_and_clear_bit(F_READBLOCK, &dev.flags))
1066 wake_up_interruptible(&dev.readblock);
1067 break;
1068
1069 case HIMT_DSP:
1070 switch (LOBYTE(wMessage)) {
1071#ifndef MSND_CLASSIC
1072 case HIDSP_PLAY_UNDER:
1073#endif
1074 case HIDSP_INT_PLAY_UNDER:
1075/* printk(KERN_DEBUG LOGNAME ": Play underflow\n"); */
1076 clear_bit(F_WRITING, &dev.flags);
1077 break;
1078
1079 case HIDSP_INT_RECORD_OVER:
1080/* printk(KERN_DEBUG LOGNAME ": Record overflow\n"); */
1081 clear_bit(F_READING, &dev.flags);
1082 break;
1083
1084 default:
1085/* printk(KERN_DEBUG LOGNAME ": DSP message %d 0x%02x\n",
1086 LOBYTE(wMessage), LOBYTE(wMessage)); */
1087 break;
1088 }
1089 break;
1090
1091 case HIMT_MIDI_IN_UCHAR:
1092 if (dev.midi_in_interrupt)
1093 (*dev.midi_in_interrupt)(&dev);
1094 break;
1095
1096 default:
1097/* printk(KERN_DEBUG LOGNAME ": HIMT message %d 0x%02x\n", HIBYTE(wMessage), HIBYTE(wMessage)); */
1098 break;
1099 }
1100}
1101
1102static irqreturn_t intr(int irq, void *dev_id)
1103{
1104 /* Send ack to DSP */
1105 msnd_inb(dev.io + HP_RXL);
1106
1107 /* Evaluate queued DSP messages */
1108 while (readw(dev.DSPQ + JQS_wTail) != readw(dev.DSPQ + JQS_wHead)) {
1109 register WORD wTmp;
1110
1111 eval_dsp_msg(readw(dev.pwDSPQData + 2*readw(dev.DSPQ + JQS_wHead)));
1112
1113 if ((wTmp = readw(dev.DSPQ + JQS_wHead) + 1) > readw(dev.DSPQ + JQS_wSize))
1114 writew(0, dev.DSPQ + JQS_wHead);
1115 else
1116 writew(wTmp, dev.DSPQ + JQS_wHead);
1117 }
1118 return IRQ_HANDLED;
1119}
1120
1121static const struct file_operations dev_fileops = {
1122 .owner = THIS_MODULE,
1123 .read = dev_read,
1124 .write = dev_write,
1125 .unlocked_ioctl = dev_ioctl,
1126 .open = dev_open,
1127 .release = dev_release,
1128 .llseek = noop_llseek,
1129};
1130
1131static int reset_dsp(void)
1132{
1133 int timeout = 100;
1134
1135 msnd_outb(HPDSPRESET_ON, dev.io + HP_DSPR);
1136 mdelay(1);
1137#ifndef MSND_CLASSIC
1138 dev.info = msnd_inb(dev.io + HP_INFO);
1139#endif
1140 msnd_outb(HPDSPRESET_OFF, dev.io + HP_DSPR);
1141 mdelay(1);
1142 while (timeout-- > 0) {
1143 if (msnd_inb(dev.io + HP_CVR) == HP_CVR_DEF)
1144 return 0;
1145 mdelay(1);
1146 }
1147 printk(KERN_ERR LOGNAME ": Cannot reset DSP\n");
1148
1149 return -EIO;
1150}
1151
1152static int __init probe_multisound(void)
1153{
1154#ifndef MSND_CLASSIC
1155 char *xv, *rev = NULL;
1156 char *pin = "Pinnacle", *fiji = "Fiji";
1157 char *pinfiji = "Pinnacle/Fiji";
1158#endif
1159
1160 if (!request_region(dev.io, dev.numio, "probing")) {
1161 printk(KERN_ERR LOGNAME ": I/O port conflict\n");
1162 return -ENODEV;
1163 }
1164
1165 if (reset_dsp() < 0) {
1166 release_region(dev.io, dev.numio);
1167 return -ENODEV;
1168 }
1169
1170#ifdef MSND_CLASSIC
1171 dev.name = "Classic/Tahiti/Monterey";
1172 printk(KERN_INFO LOGNAME ": %s, "
1173#else
1174 switch (dev.info >> 4) {
1175 case 0xf: xv = "<= 1.15"; break;
1176 case 0x1: xv = "1.18/1.2"; break;
1177 case 0x2: xv = "1.3"; break;
1178 case 0x3: xv = "1.4"; break;
1179 default: xv = "unknown"; break;
1180 }
1181
1182 switch (dev.info & 0x7) {
1183 case 0x0: rev = "I"; dev.name = pin; break;
1184 case 0x1: rev = "F"; dev.name = pin; break;
1185 case 0x2: rev = "G"; dev.name = pin; break;
1186 case 0x3: rev = "H"; dev.name = pin; break;
1187 case 0x4: rev = "E"; dev.name = fiji; break;
1188 case 0x5: rev = "C"; dev.name = fiji; break;
1189 case 0x6: rev = "D"; dev.name = fiji; break;
1190 case 0x7:
1191 rev = "A-B (Fiji) or A-E (Pinnacle)";
1192 dev.name = pinfiji;
1193 break;
1194 }
1195 printk(KERN_INFO LOGNAME ": %s revision %s, Xilinx version %s, "
1196#endif /* MSND_CLASSIC */
1197 "I/O 0x%x-0x%x, IRQ %d, memory mapped to %p-%p\n",
1198 dev.name,
1199#ifndef MSND_CLASSIC
1200 rev, xv,
1201#endif
1202 dev.io, dev.io + dev.numio - 1,
1203 dev.irq,
1204 dev.base, dev.base + 0x7fff);
1205
1206 release_region(dev.io, dev.numio);
1207 return 0;
1208}
1209
1210static int init_sma(void)
1211{
1212 static int initted;
1213 WORD mastVolLeft, mastVolRight;
1214 unsigned long flags;
1215
1216#ifdef MSND_CLASSIC
1217 msnd_outb(dev.memid, dev.io + HP_MEMM);
1218#endif
1219 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
1220 if (initted) {
1221 mastVolLeft = readw(dev.SMA + SMA_wCurrMastVolLeft);
1222 mastVolRight = readw(dev.SMA + SMA_wCurrMastVolRight);
1223 } else
1224 mastVolLeft = mastVolRight = 0;
1225 memset_io(dev.base, 0, 0x8000);
1226
1227 /* Critical section: bank 1 access */
1228 spin_lock_irqsave(&dev.lock, flags);
1229 msnd_outb(HPBLKSEL_1, dev.io + HP_BLKS);
1230 memset_io(dev.base, 0, 0x8000);
1231 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
1232 spin_unlock_irqrestore(&dev.lock, flags);
1233
1234 dev.pwDSPQData = (dev.base + DSPQ_DATA_BUFF);
1235 dev.pwMODQData = (dev.base + MODQ_DATA_BUFF);
1236 dev.pwMIDQData = (dev.base + MIDQ_DATA_BUFF);
1237
1238 /* Motorola 56k shared memory base */
1239 dev.SMA = dev.base + SMA_STRUCT_START;
1240
1241 /* Digital audio play queue */
1242 dev.DAPQ = dev.base + DAPQ_OFFSET;
1243 msnd_init_queue(dev.DAPQ, DAPQ_DATA_BUFF, DAPQ_BUFF_SIZE);
1244
1245 /* Digital audio record queue */
1246 dev.DARQ = dev.base + DARQ_OFFSET;
1247 msnd_init_queue(dev.DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE);
1248
1249 /* MIDI out queue */
1250 dev.MODQ = dev.base + MODQ_OFFSET;
1251 msnd_init_queue(dev.MODQ, MODQ_DATA_BUFF, MODQ_BUFF_SIZE);
1252
1253 /* MIDI in queue */
1254 dev.MIDQ = dev.base + MIDQ_OFFSET;
1255 msnd_init_queue(dev.MIDQ, MIDQ_DATA_BUFF, MIDQ_BUFF_SIZE);
1256
1257 /* DSP -> host message queue */
1258 dev.DSPQ = dev.base + DSPQ_OFFSET;
1259 msnd_init_queue(dev.DSPQ, DSPQ_DATA_BUFF, DSPQ_BUFF_SIZE);
1260
1261 /* Setup some DSP values */
1262#ifndef MSND_CLASSIC
1263 writew(1, dev.SMA + SMA_wCurrPlayFormat);
1264 writew(dev.play_sample_size, dev.SMA + SMA_wCurrPlaySampleSize);
1265 writew(dev.play_channels, dev.SMA + SMA_wCurrPlayChannels);
1266 writew(dev.play_sample_rate, dev.SMA + SMA_wCurrPlaySampleRate);
1267#endif
1268 writew(dev.play_sample_rate, dev.SMA + SMA_wCalFreqAtoD);
1269 writew(mastVolLeft, dev.SMA + SMA_wCurrMastVolLeft);
1270 writew(mastVolRight, dev.SMA + SMA_wCurrMastVolRight);
1271#ifndef MSND_CLASSIC
1272 writel(0x00010000, dev.SMA + SMA_dwCurrPlayPitch);
1273 writel(0x00000001, dev.SMA + SMA_dwCurrPlayRate);
1274#endif
1275 writew(0x303, dev.SMA + SMA_wCurrInputTagBits);
1276
1277 initted = 1;
1278
1279 return 0;
1280}
1281
1282static int __init calibrate_adc(WORD srate)
1283{
1284 writew(srate, dev.SMA + SMA_wCalFreqAtoD);
1285 if (dev.calibrate_signal == 0)
1286 writew(readw(dev.SMA + SMA_wCurrHostStatusFlags)
1287 | 0x0001, dev.SMA + SMA_wCurrHostStatusFlags);
1288 else
1289 writew(readw(dev.SMA + SMA_wCurrHostStatusFlags)
1290 & ~0x0001, dev.SMA + SMA_wCurrHostStatusFlags);
1291 if (msnd_send_word(&dev, 0, 0, HDEXAR_CAL_A_TO_D) == 0 &&
1292 chk_send_dsp_cmd(&dev, HDEX_AUX_REQ) == 0) {
1293 schedule_timeout_interruptible(HZ / 3);
1294 return 0;
1295 }
1296 printk(KERN_WARNING LOGNAME ": ADC calibration failed\n");
1297
1298 return -EIO;
1299}
1300
1301static int upload_dsp_code(void)
1302{
1303 int ret = 0;
1304
1305 msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
1306#ifndef HAVE_DSPCODEH
1307 INITCODESIZE = mod_firmware_load(INITCODEFILE, &INITCODE);
1308 if (!INITCODE) {
1309 printk(KERN_ERR LOGNAME ": Error loading " INITCODEFILE);
1310 return -EBUSY;
1311 }
1312
1313 PERMCODESIZE = mod_firmware_load(PERMCODEFILE, &PERMCODE);
1314 if (!PERMCODE) {
1315 printk(KERN_ERR LOGNAME ": Error loading " PERMCODEFILE);
1316 vfree(INITCODE);
1317 return -EBUSY;
1318 }
1319#endif
1320 memcpy_toio(dev.base, PERMCODE, PERMCODESIZE);
1321 if (msnd_upload_host(&dev, INITCODE, INITCODESIZE) < 0) {
1322 printk(KERN_WARNING LOGNAME ": Error uploading to DSP\n");
1323 ret = -ENODEV;
1324 goto out;
1325 }
1326#ifdef HAVE_DSPCODEH
1327 printk(KERN_INFO LOGNAME ": DSP firmware uploaded (resident)\n");
1328#else
1329 printk(KERN_INFO LOGNAME ": DSP firmware uploaded\n");
1330#endif
1331
1332out:
1333#ifndef HAVE_DSPCODEH
1334 vfree(INITCODE);
1335 vfree(PERMCODE);
1336#endif
1337
1338 return ret;
1339}
1340
1341#ifdef MSND_CLASSIC
1342static void reset_proteus(void)
1343{
1344 msnd_outb(HPPRORESET_ON, dev.io + HP_PROR);
1345 mdelay(TIME_PRO_RESET);
1346 msnd_outb(HPPRORESET_OFF, dev.io + HP_PROR);
1347 mdelay(TIME_PRO_RESET_DONE);
1348}
1349#endif
1350
1351static int initialize(void)
1352{
1353 int err, timeout;
1354
1355#ifdef MSND_CLASSIC
1356 msnd_outb(HPWAITSTATE_0, dev.io + HP_WAIT);
1357 msnd_outb(HPBITMODE_16, dev.io + HP_BITM);
1358
1359 reset_proteus();
1360#endif
1361 if ((err = init_sma()) < 0) {
1362 printk(KERN_WARNING LOGNAME ": Cannot initialize SMA\n");
1363 return err;
1364 }
1365
1366 if ((err = reset_dsp()) < 0)
1367 return err;
1368
1369 if ((err = upload_dsp_code()) < 0) {
1370 printk(KERN_WARNING LOGNAME ": Cannot upload DSP code\n");
1371 return err;
1372 }
1373
1374 timeout = 200;
1375 while (readw(dev.base)) {
1376 mdelay(1);
1377 if (!timeout--) {
1378 printk(KERN_DEBUG LOGNAME ": DSP reset timeout\n");
1379 return -EIO;
1380 }
1381 }
1382
1383 mixer_setup();
1384
1385 return 0;
1386}
1387
1388static int dsp_full_reset(void)
1389{
1390 int rv;
1391
1392 if (test_bit(F_RESETTING, &dev.flags) || ++dev.nresets > 10)
1393 return 0;
1394
1395 set_bit(F_RESETTING, &dev.flags);
1396 printk(KERN_INFO LOGNAME ": DSP reset\n");
1397 dsp_halt(NULL); /* Unconditionally halt */
1398 if ((rv = initialize()))
1399 printk(KERN_WARNING LOGNAME ": DSP reset failed\n");
1400 force_recsrc(dev.recsrc);
1401 dsp_open(NULL);
1402 clear_bit(F_RESETTING, &dev.flags);
1403
1404 return rv;
1405}
1406
1407static int __init attach_multisound(void)
1408{
1409 int err;
1410
1411 if ((err = request_irq(dev.irq, intr, 0, dev.name, &dev)) < 0) {
1412 printk(KERN_ERR LOGNAME ": Couldn't grab IRQ %d\n", dev.irq);
1413 return err;
1414 }
1415 if (request_region(dev.io, dev.numio, dev.name) == NULL) {
1416 free_irq(dev.irq, &dev);
1417 return -EBUSY;
1418 }
1419
1420 err = dsp_full_reset();
1421 if (err < 0) {
1422 release_region(dev.io, dev.numio);
1423 free_irq(dev.irq, &dev);
1424 return err;
1425 }
1426
1427 if ((err = msnd_register(&dev)) < 0) {
1428 printk(KERN_ERR LOGNAME ": Unable to register MultiSound\n");
1429 release_region(dev.io, dev.numio);
1430 free_irq(dev.irq, &dev);
1431 return err;
1432 }
1433
1434 if ((dev.dsp_minor = register_sound_dsp(&dev_fileops, -1)) < 0) {
1435 printk(KERN_ERR LOGNAME ": Unable to register DSP operations\n");
1436 msnd_unregister(&dev);
1437 release_region(dev.io, dev.numio);
1438 free_irq(dev.irq, &dev);
1439 return dev.dsp_minor;
1440 }
1441
1442 if ((dev.mixer_minor = register_sound_mixer(&dev_fileops, -1)) < 0) {
1443 printk(KERN_ERR LOGNAME ": Unable to register mixer operations\n");
1444 unregister_sound_mixer(dev.mixer_minor);
1445 msnd_unregister(&dev);
1446 release_region(dev.io, dev.numio);
1447 free_irq(dev.irq, &dev);
1448 return dev.mixer_minor;
1449 }
1450
1451 dev.ext_midi_dev = dev.hdr_midi_dev = -1;
1452
1453 disable_irq(dev.irq);
1454 calibrate_adc(dev.play_sample_rate);
1455#ifndef MSND_CLASSIC
1456 force_recsrc(SOUND_MASK_IMIX);
1457#endif
1458
1459 return 0;
1460}
1461
1462static void __exit unload_multisound(void)
1463{
1464 release_region(dev.io, dev.numio);
1465 free_irq(dev.irq, &dev);
1466 unregister_sound_mixer(dev.mixer_minor);
1467 unregister_sound_dsp(dev.dsp_minor);
1468 msnd_unregister(&dev);
1469}
1470
1471#ifndef MSND_CLASSIC
1472
1473/* Pinnacle/Fiji Logical Device Configuration */
1474
1475static int __init msnd_write_cfg(int cfg, int reg, int value)
1476{
1477 msnd_outb(reg, cfg);
1478 msnd_outb(value, cfg + 1);
1479 if (value != msnd_inb(cfg + 1)) {
1480 printk(KERN_ERR LOGNAME ": msnd_write_cfg: I/O error\n");
1481 return -EIO;
1482 }
1483 return 0;
1484}
1485
1486static int __init msnd_write_cfg_io0(int cfg, int num, WORD io)
1487{
1488 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1489 return -EIO;
1490 if (msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
1491 return -EIO;
1492 if (msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
1493 return -EIO;
1494 return 0;
1495}
1496
1497static int __init msnd_write_cfg_io1(int cfg, int num, WORD io)
1498{
1499 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1500 return -EIO;
1501 if (msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
1502 return -EIO;
1503 if (msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
1504 return -EIO;
1505 return 0;
1506}
1507
1508static int __init msnd_write_cfg_irq(int cfg, int num, WORD irq)
1509{
1510 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1511 return -EIO;
1512 if (msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
1513 return -EIO;
1514 if (msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
1515 return -EIO;
1516 return 0;
1517}
1518
1519static int __init msnd_write_cfg_mem(int cfg, int num, int mem)
1520{
1521 WORD wmem;
1522
1523 mem >>= 8;
1524 mem &= 0xfff;
1525 wmem = (WORD)mem;
1526 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1527 return -EIO;
1528 if (msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
1529 return -EIO;
1530 if (msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
1531 return -EIO;
1532 if (wmem && msnd_write_cfg(cfg, IREG_MEMCONTROL, (MEMTYPE_HIADDR | MEMTYPE_16BIT)))
1533 return -EIO;
1534 return 0;
1535}
1536
1537static int __init msnd_activate_logical(int cfg, int num)
1538{
1539 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1540 return -EIO;
1541 if (msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
1542 return -EIO;
1543 return 0;
1544}
1545
1546static int __init msnd_write_cfg_logical(int cfg, int num, WORD io0, WORD io1, WORD irq, int mem)
1547{
1548 if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
1549 return -EIO;
1550 if (msnd_write_cfg_io0(cfg, num, io0))
1551 return -EIO;
1552 if (msnd_write_cfg_io1(cfg, num, io1))
1553 return -EIO;
1554 if (msnd_write_cfg_irq(cfg, num, irq))
1555 return -EIO;
1556 if (msnd_write_cfg_mem(cfg, num, mem))
1557 return -EIO;
1558 if (msnd_activate_logical(cfg, num))
1559 return -EIO;
1560 return 0;
1561}
1562
1563typedef struct msnd_pinnacle_cfg_device {
1564 WORD io0, io1, irq;
1565 int mem;
1566} msnd_pinnacle_cfg_t[4];
1567
1568static int __init msnd_pinnacle_cfg_devices(int cfg, int reset, msnd_pinnacle_cfg_t device)
1569{
1570 int i;
1571
1572 /* Reset devices if told to */
1573 if (reset) {
1574 printk(KERN_INFO LOGNAME ": Resetting all devices\n");
1575 for (i = 0; i < 4; ++i)
1576 if (msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0))
1577 return -EIO;
1578 }
1579
1580 /* Configure specified devices */
1581 for (i = 0; i < 4; ++i) {
1582
1583 switch (i) {
1584 case 0: /* DSP */
1585 if (!(device[i].io0 && device[i].irq && device[i].mem))
1586 continue;
1587 break;
1588 case 1: /* MPU */
1589 if (!(device[i].io0 && device[i].irq))
1590 continue;
1591 printk(KERN_INFO LOGNAME
1592 ": Configuring MPU to I/O 0x%x IRQ %d\n",
1593 device[i].io0, device[i].irq);
1594 break;
1595 case 2: /* IDE */
1596 if (!(device[i].io0 && device[i].io1 && device[i].irq))
1597 continue;
1598 printk(KERN_INFO LOGNAME
1599 ": Configuring IDE to I/O 0x%x, 0x%x IRQ %d\n",
1600 device[i].io0, device[i].io1, device[i].irq);
1601 break;
1602 case 3: /* Joystick */
1603 if (!(device[i].io0))
1604 continue;
1605 printk(KERN_INFO LOGNAME
1606 ": Configuring joystick to I/O 0x%x\n",
1607 device[i].io0);
1608 break;
1609 }
1610
1611 /* Configure the device */
1612 if (msnd_write_cfg_logical(cfg, i, device[i].io0, device[i].io1, device[i].irq, device[i].mem))
1613 return -EIO;
1614 }
1615
1616 return 0;
1617}
1618#endif
1619
1620#ifdef MODULE
1621MODULE_AUTHOR ("Andrew Veliath <andrewtv@usa.net>");
1622MODULE_DESCRIPTION ("Turtle Beach " LONGNAME " Linux Driver");
1623MODULE_LICENSE("GPL");
1624
1625static int io __initdata = -1;
1626static int irq __initdata = -1;
1627static int mem __initdata = -1;
1628static int write_ndelay __initdata = -1;
1629
1630#ifndef MSND_CLASSIC
1631/* Pinnacle/Fiji non-PnP Config Port */
1632static int cfg __initdata = -1;
1633
1634/* Extra Peripheral Configuration */
1635static int reset __initdata = 0;
1636static int mpu_io __initdata = 0;
1637static int mpu_irq __initdata = 0;
1638static int ide_io0 __initdata = 0;
1639static int ide_io1 __initdata = 0;
1640static int ide_irq __initdata = 0;
1641static int joystick_io __initdata = 0;
1642
1643/* If we have the digital daugherboard... */
1644static bool digital __initdata = false;
1645#endif
1646
1647static int fifosize __initdata = DEFFIFOSIZE;
1648static int calibrate_signal __initdata = 0;
1649
1650#else /* not a module */
1651
1652static int write_ndelay __initdata = -1;
1653
1654#ifdef MSND_CLASSIC
1655static int io __initdata = CONFIG_MSNDCLAS_IO;
1656static int irq __initdata = CONFIG_MSNDCLAS_IRQ;
1657static int mem __initdata = CONFIG_MSNDCLAS_MEM;
1658#else /* Pinnacle/Fiji */
1659
1660static int io __initdata = CONFIG_MSNDPIN_IO;
1661static int irq __initdata = CONFIG_MSNDPIN_IRQ;
1662static int mem __initdata = CONFIG_MSNDPIN_MEM;
1663
1664/* Pinnacle/Fiji non-PnP Config Port */
1665#ifdef CONFIG_MSNDPIN_NONPNP
1666# ifndef CONFIG_MSNDPIN_CFG
1667# define CONFIG_MSNDPIN_CFG 0x250
1668# endif
1669#else
1670# ifdef CONFIG_MSNDPIN_CFG
1671# undef CONFIG_MSNDPIN_CFG
1672# endif
1673# define CONFIG_MSNDPIN_CFG -1
1674#endif
1675static int cfg __initdata = CONFIG_MSNDPIN_CFG;
1676/* If not a module, we don't need to bother with reset=1 */
1677static int reset;
1678
1679/* Extra Peripheral Configuration (Default: Disable) */
1680#ifndef CONFIG_MSNDPIN_MPU_IO
1681# define CONFIG_MSNDPIN_MPU_IO 0
1682#endif
1683static int mpu_io __initdata = CONFIG_MSNDPIN_MPU_IO;
1684
1685#ifndef CONFIG_MSNDPIN_MPU_IRQ
1686# define CONFIG_MSNDPIN_MPU_IRQ 0
1687#endif
1688static int mpu_irq __initdata = CONFIG_MSNDPIN_MPU_IRQ;
1689
1690#ifndef CONFIG_MSNDPIN_IDE_IO0
1691# define CONFIG_MSNDPIN_IDE_IO0 0
1692#endif
1693static int ide_io0 __initdata = CONFIG_MSNDPIN_IDE_IO0;
1694
1695#ifndef CONFIG_MSNDPIN_IDE_IO1
1696# define CONFIG_MSNDPIN_IDE_IO1 0
1697#endif
1698static int ide_io1 __initdata = CONFIG_MSNDPIN_IDE_IO1;
1699
1700#ifndef CONFIG_MSNDPIN_IDE_IRQ
1701# define CONFIG_MSNDPIN_IDE_IRQ 0
1702#endif
1703static int ide_irq __initdata = CONFIG_MSNDPIN_IDE_IRQ;
1704
1705#ifndef CONFIG_MSNDPIN_JOYSTICK_IO
1706# define CONFIG_MSNDPIN_JOYSTICK_IO 0
1707#endif
1708static int joystick_io __initdata = CONFIG_MSNDPIN_JOYSTICK_IO;
1709
1710/* Have SPDIF (Digital) Daughterboard */
1711#ifndef CONFIG_MSNDPIN_DIGITAL
1712# define CONFIG_MSNDPIN_DIGITAL 0
1713#endif
1714static bool digital __initdata = CONFIG_MSNDPIN_DIGITAL;
1715
1716#endif /* MSND_CLASSIC */
1717
1718#ifndef CONFIG_MSND_FIFOSIZE
1719# define CONFIG_MSND_FIFOSIZE DEFFIFOSIZE
1720#endif
1721static int fifosize __initdata = CONFIG_MSND_FIFOSIZE;
1722
1723#ifndef CONFIG_MSND_CALSIGNAL
1724# define CONFIG_MSND_CALSIGNAL 0
1725#endif
1726static int
1727calibrate_signal __initdata = CONFIG_MSND_CALSIGNAL;
1728#endif /* MODULE */
1729
1730module_param_hw (io, int, ioport, 0);
1731module_param_hw (irq, int, irq, 0);
1732module_param_hw (mem, int, iomem, 0);
1733module_param (write_ndelay, int, 0);
1734module_param (fifosize, int, 0);
1735module_param (calibrate_signal, int, 0);
1736#ifndef MSND_CLASSIC
1737module_param (digital, bool, 0);
1738module_param_hw (cfg, int, ioport, 0);
1739module_param (reset, int, 0);
1740module_param_hw (mpu_io, int, ioport, 0);
1741module_param_hw (mpu_irq, int, irq, 0);
1742module_param_hw (ide_io0, int, ioport, 0);
1743module_param_hw (ide_io1, int, ioport, 0);
1744module_param_hw (ide_irq, int, irq, 0);
1745module_param_hw (joystick_io, int, ioport, 0);
1746#endif
1747
1748static int __init msnd_init(void)
1749{
1750 int err;
1751#ifndef MSND_CLASSIC
1752 static msnd_pinnacle_cfg_t pinnacle_devs;
1753#endif /* MSND_CLASSIC */
1754
1755 printk(KERN_INFO LOGNAME ": Turtle Beach " LONGNAME " Linux Driver Version "
1756 VERSION ", Copyright (C) 1998 Andrew Veliath\n");
1757
1758 if (io == -1 || irq == -1 || mem == -1)
1759 printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n");
1760
1761#ifdef MSND_CLASSIC
1762 if (io == -1 ||
1763 !(io == 0x290 ||
1764 io == 0x260 ||
1765 io == 0x250 ||
1766 io == 0x240 ||
1767 io == 0x230 ||
1768 io == 0x220 ||
1769 io == 0x210 ||
1770 io == 0x3e0)) {
1771 printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, or 0x3E0\n");
1772 return -EINVAL;
1773 }
1774#else
1775 if (io == -1 ||
1776 io < 0x100 ||
1777 io > 0x3e0 ||
1778 (io % 0x10) != 0) {
1779 printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must within the range 0x100 to 0x3E0 and must be evenly divisible by 0x10\n");
1780 return -EINVAL;
1781 }
1782#endif /* MSND_CLASSIC */
1783
1784 if (irq == -1 ||
1785 !(irq == 5 ||
1786 irq == 7 ||
1787 irq == 9 ||
1788 irq == 10 ||
1789 irq == 11 ||
1790 irq == 12)) {
1791 printk(KERN_ERR LOGNAME ": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
1792 return -EINVAL;
1793 }
1794
1795 if (mem == -1 ||
1796 !(mem == 0xb0000 ||
1797 mem == 0xc8000 ||
1798 mem == 0xd0000 ||
1799 mem == 0xd8000 ||
1800 mem == 0xe0000 ||
1801 mem == 0xe8000)) {
1802 printk(KERN_ERR LOGNAME ": \"mem\" - must be set to "
1803 "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or 0xe8000\n");
1804 return -EINVAL;
1805 }
1806
1807#ifdef MSND_CLASSIC
1808 switch (irq) {
1809 case 5: dev.irqid = HPIRQ_5; break;
1810 case 7: dev.irqid = HPIRQ_7; break;
1811 case 9: dev.irqid = HPIRQ_9; break;
1812 case 10: dev.irqid = HPIRQ_10; break;
1813 case 11: dev.irqid = HPIRQ_11; break;
1814 case 12: dev.irqid = HPIRQ_12; break;
1815 }
1816
1817 switch (mem) {
1818 case 0xb0000: dev.memid = HPMEM_B000; break;
1819 case 0xc8000: dev.memid = HPMEM_C800; break;
1820 case 0xd0000: dev.memid = HPMEM_D000; break;
1821 case 0xd8000: dev.memid = HPMEM_D800; break;
1822 case 0xe0000: dev.memid = HPMEM_E000; break;
1823 case 0xe8000: dev.memid = HPMEM_E800; break;
1824 }
1825#else
1826 if (cfg == -1) {
1827 printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
1828 } else if (cfg != 0x250 && cfg != 0x260 && cfg != 0x270) {
1829 printk(KERN_INFO LOGNAME ": Config port must be 0x250, 0x260 or 0x270 (or unspecified for PnP mode)\n");
1830 return -EINVAL;
1831 } else {
1832 printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%x\n", cfg);
1833
1834 /* DSP */
1835 pinnacle_devs[0].io0 = io;
1836 pinnacle_devs[0].irq = irq;
1837 pinnacle_devs[0].mem = mem;
1838
1839 /* The following are Pinnacle specific */
1840
1841 /* MPU */
1842 pinnacle_devs[1].io0 = mpu_io;
1843 pinnacle_devs[1].irq = mpu_irq;
1844
1845 /* IDE */
1846 pinnacle_devs[2].io0 = ide_io0;
1847 pinnacle_devs[2].io1 = ide_io1;
1848 pinnacle_devs[2].irq = ide_irq;
1849
1850 /* Joystick */
1851 pinnacle_devs[3].io0 = joystick_io;
1852
1853 if (!request_region(cfg, 2, "Pinnacle/Fiji Config")) {
1854 printk(KERN_ERR LOGNAME ": Config port 0x%x conflict\n", cfg);
1855 return -EIO;
1856 }
1857
1858 if (msnd_pinnacle_cfg_devices(cfg, reset, pinnacle_devs)) {
1859 printk(KERN_ERR LOGNAME ": Device configuration error\n");
1860 release_region(cfg, 2);
1861 return -EIO;
1862 }
1863 release_region(cfg, 2);
1864 }
1865#endif /* MSND_CLASSIC */
1866
1867 if (fifosize < 16)
1868 fifosize = 16;
1869
1870 if (fifosize > 1024)
1871 fifosize = 1024;
1872
1873 set_default_audio_parameters();
1874#ifdef MSND_CLASSIC
1875 dev.type = msndClassic;
1876#else
1877 dev.type = msndPinnacle;
1878#endif
1879 dev.io = io;
1880 dev.numio = DSP_NUMIO;
1881 dev.irq = irq;
1882 dev.base = ioremap(mem, 0x8000);
1883 dev.fifosize = fifosize * 1024;
1884 dev.calibrate_signal = calibrate_signal ? 1 : 0;
1885 dev.recsrc = 0;
1886 dev.dspq_data_buff = DSPQ_DATA_BUFF;
1887 dev.dspq_buff_size = DSPQ_BUFF_SIZE;
1888 if (write_ndelay == -1)
1889 write_ndelay = CONFIG_MSND_WRITE_NDELAY;
1890 if (write_ndelay)
1891 clear_bit(F_DISABLE_WRITE_NDELAY, &dev.flags);
1892 else
1893 set_bit(F_DISABLE_WRITE_NDELAY, &dev.flags);
1894#ifndef MSND_CLASSIC
1895 if (digital)
1896 set_bit(F_HAVEDIGITAL, &dev.flags);
1897#endif
1898 init_waitqueue_head(&dev.writeblock);
1899 init_waitqueue_head(&dev.readblock);
1900 init_waitqueue_head(&dev.writeflush);
1901 msnd_fifo_init(&dev.DAPF);
1902 msnd_fifo_init(&dev.DARF);
1903 spin_lock_init(&dev.lock);
1904 printk(KERN_INFO LOGNAME ": %u byte audio FIFOs (x2)\n", dev.fifosize);
1905 if ((err = msnd_fifo_alloc(&dev.DAPF, dev.fifosize)) < 0) {
1906 printk(KERN_ERR LOGNAME ": Couldn't allocate write FIFO\n");
1907 return err;
1908 }
1909
1910 if ((err = msnd_fifo_alloc(&dev.DARF, dev.fifosize)) < 0) {
1911 printk(KERN_ERR LOGNAME ": Couldn't allocate read FIFO\n");
1912 msnd_fifo_free(&dev.DAPF);
1913 return err;
1914 }
1915
1916 if ((err = probe_multisound()) < 0) {
1917 printk(KERN_ERR LOGNAME ": Probe failed\n");
1918 msnd_fifo_free(&dev.DAPF);
1919 msnd_fifo_free(&dev.DARF);
1920 return err;
1921 }
1922
1923 if ((err = attach_multisound()) < 0) {
1924 printk(KERN_ERR LOGNAME ": Attach failed\n");
1925 msnd_fifo_free(&dev.DAPF);
1926 msnd_fifo_free(&dev.DARF);
1927 return err;
1928 }
1929
1930 return 0;
1931}
1932
1933static void __exit msdn_cleanup(void)
1934{
1935 unload_multisound();
1936 msnd_fifo_free(&dev.DAPF);
1937 msnd_fifo_free(&dev.DARF);
1938}
1939
1940module_init(msnd_init);
1941module_exit(msdn_cleanup);
diff --git a/sound/oss/msnd_pinnacle.h b/sound/oss/msnd_pinnacle.h
deleted file mode 100644
index c18d66cbbe3f..000000000000
--- a/sound/oss/msnd_pinnacle.h
+++ /dev/null
@@ -1,246 +0,0 @@
1/*********************************************************************
2 *
3 * msnd_pinnacle.h
4 *
5 * Turtle Beach MultiSound Sound Card Driver for Linux
6 *
7 * Some parts of this header file were derived from the Turtle Beach
8 * MultiSound Driver Development Kit.
9 *
10 * Copyright (C) 1998 Andrew Veliath
11 * Copyright (C) 1993 Turtle Beach Systems, Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 ********************************************************************/
28#ifndef __MSND_PINNACLE_H
29#define __MSND_PINNACLE_H
30
31
32#define DSP_NUMIO 0x08
33
34#define IREG_LOGDEVICE 0x07
35#define IREG_ACTIVATE 0x30
36#define LD_ACTIVATE 0x01
37#define LD_DISACTIVATE 0x00
38#define IREG_EECONTROL 0x3F
39#define IREG_MEMBASEHI 0x40
40#define IREG_MEMBASELO 0x41
41#define IREG_MEMCONTROL 0x42
42#define IREG_MEMRANGEHI 0x43
43#define IREG_MEMRANGELO 0x44
44#define MEMTYPE_8BIT 0x00
45#define MEMTYPE_16BIT 0x02
46#define MEMTYPE_RANGE 0x00
47#define MEMTYPE_HIADDR 0x01
48#define IREG_IO0_BASEHI 0x60
49#define IREG_IO0_BASELO 0x61
50#define IREG_IO1_BASEHI 0x62
51#define IREG_IO1_BASELO 0x63
52#define IREG_IRQ_NUMBER 0x70
53#define IREG_IRQ_TYPE 0x71
54#define IRQTYPE_HIGH 0x02
55#define IRQTYPE_LOW 0x00
56#define IRQTYPE_LEVEL 0x01
57#define IRQTYPE_EDGE 0x00
58
59#define HP_DSPR 0x04
60#define HP_BLKS 0x04
61
62#define HPDSPRESET_OFF 2
63#define HPDSPRESET_ON 0
64
65#define HPBLKSEL_0 2
66#define HPBLKSEL_1 3
67
68#define HIMT_DAT_OFF 0x03
69
70#define HIDSP_PLAY_UNDER 0x00
71#define HIDSP_INT_PLAY_UNDER 0x01
72#define HIDSP_SSI_TX_UNDER 0x02
73#define HIDSP_RECQ_OVERFLOW 0x08
74#define HIDSP_INT_RECORD_OVER 0x09
75#define HIDSP_SSI_RX_OVERFLOW 0x0a
76
77#define HIDSP_MIDI_IN_OVER 0x10
78
79#define HIDSP_MIDI_FRAME_ERR 0x11
80#define HIDSP_MIDI_PARITY_ERR 0x12
81#define HIDSP_MIDI_OVERRUN_ERR 0x13
82
83#define HIDSP_INPUT_CLIPPING 0x20
84#define HIDSP_MIX_CLIPPING 0x30
85#define HIDSP_DAT_IN_OFF 0x21
86
87#define HDEXAR_SET_ANA_IN 0
88#define HDEXAR_CLEAR_PEAKS 1
89#define HDEXAR_IN_SET_POTS 2
90#define HDEXAR_AUX_SET_POTS 3
91#define HDEXAR_CAL_A_TO_D 4
92#define HDEXAR_RD_EXT_DSP_BITS 5
93
94#define HDEXAR_SET_SYNTH_IN 4
95#define HDEXAR_READ_DAT_IN 5
96#define HDEXAR_MIC_SET_POTS 6
97#define HDEXAR_SET_DAT_IN 7
98
99#define HDEXAR_SET_SYNTH_48 8
100#define HDEXAR_SET_SYNTH_44 9
101
102#define TIME_PRO_RESET_DONE 0x028A
103#define TIME_PRO_SYSEX 0x001E
104#define TIME_PRO_RESET 0x0032
105
106#define AGND 0x01
107#define SIGNAL 0x02
108
109#define EXT_DSP_BIT_DCAL 0x0001
110#define EXT_DSP_BIT_MIDI_CON 0x0002
111
112#define BUFFSIZE 0x8000
113#define HOSTQ_SIZE 0x40
114
115#define SRAM_CNTL_START 0x7F00
116#define SMA_STRUCT_START 0x7F40
117
118#define DAP_BUFF_SIZE 0x2400
119#define DAR_BUFF_SIZE 0x2000
120
121#define DAPQ_STRUCT_SIZE 0x10
122#define DARQ_STRUCT_SIZE 0x10
123#define DAPQ_BUFF_SIZE (3 * 0x10)
124#define DARQ_BUFF_SIZE (3 * 0x10)
125#define MODQ_BUFF_SIZE 0x400
126#define MIDQ_BUFF_SIZE 0x800
127#define DSPQ_BUFF_SIZE 0x5A0
128
129#define DAPQ_DATA_BUFF 0x6C00
130#define DARQ_DATA_BUFF 0x6C30
131#define MODQ_DATA_BUFF 0x6C60
132#define MIDQ_DATA_BUFF 0x7060
133#define DSPQ_DATA_BUFF 0x7860
134
135#define DAPQ_OFFSET SRAM_CNTL_START
136#define DARQ_OFFSET (SRAM_CNTL_START + 0x08)
137#define MODQ_OFFSET (SRAM_CNTL_START + 0x10)
138#define MIDQ_OFFSET (SRAM_CNTL_START + 0x18)
139#define DSPQ_OFFSET (SRAM_CNTL_START + 0x20)
140
141#define MOP_WAVEHDR 0
142#define MOP_EXTOUT 1
143#define MOP_HWINIT 0xfe
144#define MOP_NONE 0xff
145#define MOP_MAX 1
146
147#define MIP_EXTIN 0
148#define MIP_WAVEHDR 1
149#define MIP_HWINIT 0xfe
150#define MIP_MAX 1
151
152/* Pinnacle/Fiji SMA Common Data */
153#define SMA_wCurrPlayBytes 0x0000
154#define SMA_wCurrRecordBytes 0x0002
155#define SMA_wCurrPlayVolLeft 0x0004
156#define SMA_wCurrPlayVolRight 0x0006
157#define SMA_wCurrInVolLeft 0x0008
158#define SMA_wCurrInVolRight 0x000a
159#define SMA_wCurrMHdrVolLeft 0x000c
160#define SMA_wCurrMHdrVolRight 0x000e
161#define SMA_dwCurrPlayPitch 0x0010
162#define SMA_dwCurrPlayRate 0x0014
163#define SMA_wCurrMIDIIOPatch 0x0018
164#define SMA_wCurrPlayFormat 0x001a
165#define SMA_wCurrPlaySampleSize 0x001c
166#define SMA_wCurrPlayChannels 0x001e
167#define SMA_wCurrPlaySampleRate 0x0020
168#define SMA_wCurrRecordFormat 0x0022
169#define SMA_wCurrRecordSampleSize 0x0024
170#define SMA_wCurrRecordChannels 0x0026
171#define SMA_wCurrRecordSampleRate 0x0028
172#define SMA_wCurrDSPStatusFlags 0x002a
173#define SMA_wCurrHostStatusFlags 0x002c
174#define SMA_wCurrInputTagBits 0x002e
175#define SMA_wCurrLeftPeak 0x0030
176#define SMA_wCurrRightPeak 0x0032
177#define SMA_bMicPotPosLeft 0x0034
178#define SMA_bMicPotPosRight 0x0035
179#define SMA_bMicPotMaxLeft 0x0036
180#define SMA_bMicPotMaxRight 0x0037
181#define SMA_bInPotPosLeft 0x0038
182#define SMA_bInPotPosRight 0x0039
183#define SMA_bAuxPotPosLeft 0x003a
184#define SMA_bAuxPotPosRight 0x003b
185#define SMA_bInPotMaxLeft 0x003c
186#define SMA_bInPotMaxRight 0x003d
187#define SMA_bAuxPotMaxLeft 0x003e
188#define SMA_bAuxPotMaxRight 0x003f
189#define SMA_bInPotMaxMethod 0x0040
190#define SMA_bAuxPotMaxMethod 0x0041
191#define SMA_wCurrMastVolLeft 0x0042
192#define SMA_wCurrMastVolRight 0x0044
193#define SMA_wCalFreqAtoD 0x0046
194#define SMA_wCurrAuxVolLeft 0x0048
195#define SMA_wCurrAuxVolRight 0x004a
196#define SMA_wCurrPlay1VolLeft 0x004c
197#define SMA_wCurrPlay1VolRight 0x004e
198#define SMA_wCurrPlay2VolLeft 0x0050
199#define SMA_wCurrPlay2VolRight 0x0052
200#define SMA_wCurrPlay3VolLeft 0x0054
201#define SMA_wCurrPlay3VolRight 0x0056
202#define SMA_wCurrPlay4VolLeft 0x0058
203#define SMA_wCurrPlay4VolRight 0x005a
204#define SMA_wCurrPlay1PeakLeft 0x005c
205#define SMA_wCurrPlay1PeakRight 0x005e
206#define SMA_wCurrPlay2PeakLeft 0x0060
207#define SMA_wCurrPlay2PeakRight 0x0062
208#define SMA_wCurrPlay3PeakLeft 0x0064
209#define SMA_wCurrPlay3PeakRight 0x0066
210#define SMA_wCurrPlay4PeakLeft 0x0068
211#define SMA_wCurrPlay4PeakRight 0x006a
212#define SMA_wCurrPlayPeakLeft 0x006c
213#define SMA_wCurrPlayPeakRight 0x006e
214#define SMA_wCurrDATSR 0x0070
215#define SMA_wCurrDATRXCHNL 0x0072
216#define SMA_wCurrDATTXCHNL 0x0074
217#define SMA_wCurrDATRXRate 0x0076
218#define SMA_dwDSPPlayCount 0x0078
219#define SMA__size 0x007c
220
221#ifdef HAVE_DSPCODEH
222# include "pndsperm.c"
223# include "pndspini.c"
224# define PERMCODE pndsperm
225# define INITCODE pndspini
226# define PERMCODESIZE sizeof(pndsperm)
227# define INITCODESIZE sizeof(pndspini)
228#else
229# ifndef CONFIG_MSNDPIN_INIT_FILE
230# define CONFIG_MSNDPIN_INIT_FILE \
231 "/etc/sound/pndspini.bin"
232# endif
233# ifndef CONFIG_MSNDPIN_PERM_FILE
234# define CONFIG_MSNDPIN_PERM_FILE \
235 "/etc/sound/pndsperm.bin"
236# endif
237# define PERMCODEFILE CONFIG_MSNDPIN_PERM_FILE
238# define INITCODEFILE CONFIG_MSNDPIN_INIT_FILE
239# define PERMCODE dspini
240# define INITCODE permini
241# define PERMCODESIZE sizeof_dspini
242# define INITCODESIZE sizeof_permini
243#endif
244#define LONGNAME "MultiSound (Pinnacle/Fiji)"
245
246#endif /* __MSND_PINNACLE_H */
diff --git a/sound/oss/opl3.c b/sound/oss/opl3.c
deleted file mode 100644
index f0f5b5be6314..000000000000
--- a/sound/oss/opl3.c
+++ /dev/null
@@ -1,1255 +0,0 @@
1/*
2 * sound/oss/opl3.c
3 *
4 * A low level driver for Yamaha YM3812 and OPL-3 -chips
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Changes
15 * Thomas Sailer ioctl code reworked (vmalloc/vfree removed)
16 * Alan Cox modularisation, fixed sound_mem allocs.
17 * Christoph Hellwig Adapted to module_init/module_exit
18 * Arnaldo C. de Melo get rid of check_region, use request_region for
19 * OPL4, release it on exit, some cleanups.
20 *
21 * Status
22 * Believed to work. Badly needs rewriting a bit to support multiple
23 * OPL3 devices.
24 */
25
26#include <linux/init.h>
27#include <linux/slab.h>
28#include <linux/module.h>
29#include <linux/delay.h>
30
31/*
32 * Major improvements to the FM handling 30AUG92 by Rob Hooft,
33 * hooft@chem.ruu.nl
34 */
35
36#include "sound_config.h"
37
38#include "opl3_hw.h"
39
40#define MAX_VOICE 18
41#define OFFS_4OP 11
42
43struct voice_info
44{
45 unsigned char keyon_byte;
46 long bender;
47 long bender_range;
48 unsigned long orig_freq;
49 unsigned long current_freq;
50 int volume;
51 int mode;
52 int panning; /* 0xffff means not set */
53};
54
55struct opl_devinfo
56{
57 int base;
58 int left_io, right_io;
59 int nr_voice;
60 int lv_map[MAX_VOICE];
61
62 struct voice_info voc[MAX_VOICE];
63 struct voice_alloc_info *v_alloc;
64 struct channel_info *chn_info;
65
66 struct sbi_instrument i_map[SBFM_MAXINSTR];
67 struct sbi_instrument *act_i[MAX_VOICE];
68
69 struct synth_info fm_info;
70
71 int busy;
72 int model;
73 unsigned char cmask;
74
75 int is_opl4;
76};
77
78static struct opl_devinfo *devc = NULL;
79
80static int detected_model;
81
82static int store_instr(int instr_no, struct sbi_instrument *instr);
83static void freq_to_fnum(int freq, int *block, int *fnum);
84static void opl3_command(int io_addr, unsigned int addr, unsigned int val);
85static int opl3_kill_note(int dev, int voice, int note, int velocity);
86
87static void enter_4op_mode(void)
88{
89 int i;
90 static int v4op[MAX_VOICE] = {
91 0, 1, 2, 9, 10, 11, 6, 7, 8, 15, 16, 17
92 };
93
94 devc->cmask = 0x3f; /* Connect all possible 4 OP voice operators */
95 opl3_command(devc->right_io, CONNECTION_SELECT_REGISTER, 0x3f);
96
97 for (i = 0; i < 3; i++)
98 pv_map[i].voice_mode = 4;
99 for (i = 3; i < 6; i++)
100 pv_map[i].voice_mode = 0;
101
102 for (i = 9; i < 12; i++)
103 pv_map[i].voice_mode = 4;
104 for (i = 12; i < 15; i++)
105 pv_map[i].voice_mode = 0;
106
107 for (i = 0; i < 12; i++)
108 devc->lv_map[i] = v4op[i];
109 devc->v_alloc->max_voice = devc->nr_voice = 12;
110}
111
112static int opl3_ioctl(int dev, unsigned int cmd, void __user * arg)
113{
114 struct sbi_instrument ins;
115
116 switch (cmd) {
117 case SNDCTL_FM_LOAD_INSTR:
118 printk(KERN_WARNING "Warning: Obsolete ioctl(SNDCTL_FM_LOAD_INSTR) used. Fix the program.\n");
119 if (copy_from_user(&ins, arg, sizeof(ins)))
120 return -EFAULT;
121 if (ins.channel < 0 || ins.channel >= SBFM_MAXINSTR) {
122 printk(KERN_WARNING "FM Error: Invalid instrument number %d\n", ins.channel);
123 return -EINVAL;
124 }
125 return store_instr(ins.channel, &ins);
126
127 case SNDCTL_SYNTH_INFO:
128 devc->fm_info.nr_voices = (devc->nr_voice == 12) ? 6 : devc->nr_voice;
129 if (copy_to_user(arg, &devc->fm_info, sizeof(devc->fm_info)))
130 return -EFAULT;
131 return 0;
132
133 case SNDCTL_SYNTH_MEMAVL:
134 return 0x7fffffff;
135
136 case SNDCTL_FM_4OP_ENABLE:
137 if (devc->model == 2)
138 enter_4op_mode();
139 return 0;
140
141 default:
142 return -EINVAL;
143 }
144}
145
146static int opl3_detect(int ioaddr)
147{
148 /*
149 * This function returns 1 if the FM chip is present at the given I/O port
150 * The detection algorithm plays with the timer built in the FM chip and
151 * looks for a change in the status register.
152 *
153 * Note! The timers of the FM chip are not connected to AdLib (and compatible)
154 * boards.
155 *
156 * Note2! The chip is initialized if detected.
157 */
158
159 unsigned char stat1, signature;
160 int i;
161
162 if (devc != NULL)
163 {
164 printk(KERN_ERR "opl3: Only one OPL3 supported.\n");
165 return 0;
166 }
167
168 devc = kzalloc(sizeof(*devc), GFP_KERNEL);
169
170 if (devc == NULL)
171 {
172 printk(KERN_ERR "opl3: Can't allocate memory for the device control "
173 "structure \n ");
174 return 0;
175 }
176
177 strcpy(devc->fm_info.name, "OPL2");
178
179 if (!request_region(ioaddr, 4, devc->fm_info.name)) {
180 printk(KERN_WARNING "opl3: I/O port 0x%x already in use\n", ioaddr);
181 goto cleanup_devc;
182 }
183
184 devc->base = ioaddr;
185
186 /* Reset timers 1 and 2 */
187 opl3_command(ioaddr, TIMER_CONTROL_REGISTER, TIMER1_MASK | TIMER2_MASK);
188
189 /* Reset the IRQ of the FM chip */
190 opl3_command(ioaddr, TIMER_CONTROL_REGISTER, IRQ_RESET);
191
192 signature = stat1 = inb(ioaddr); /* Status register */
193
194 if (signature != 0x00 && signature != 0x06 && signature != 0x02 &&
195 signature != 0x0f)
196 {
197 MDB(printk(KERN_INFO "OPL3 not detected %x\n", signature));
198 goto cleanup_region;
199 }
200
201 if (signature == 0x06) /* OPL2 */
202 {
203 detected_model = 2;
204 }
205 else if (signature == 0x00 || signature == 0x0f) /* OPL3 or OPL4 */
206 {
207 unsigned char tmp;
208
209 detected_model = 3;
210
211 /*
212 * Detect availability of OPL4 (_experimental_). Works probably
213 * only after a cold boot. In addition the OPL4 port
214 * of the chip may not be connected to the PC bus at all.
215 */
216
217 opl3_command(ioaddr + 2, OPL3_MODE_REGISTER, 0x00);
218 opl3_command(ioaddr + 2, OPL3_MODE_REGISTER, OPL3_ENABLE | OPL4_ENABLE);
219
220 if ((tmp = inb(ioaddr)) == 0x02) /* Have a OPL4 */
221 {
222 detected_model = 4;
223 }
224
225 if (request_region(ioaddr - 8, 2, "OPL4")) /* OPL4 port was free */
226 {
227 int tmp;
228
229 outb((0x02), ioaddr - 8); /* Select OPL4 ID register */
230 udelay(10);
231 tmp = inb(ioaddr - 7); /* Read it */
232 udelay(10);
233
234 if (tmp == 0x20) /* OPL4 should return 0x20 here */
235 {
236 detected_model = 4;
237 outb((0xF8), ioaddr - 8); /* Select OPL4 FM mixer control */
238 udelay(10);
239 outb((0x1B), ioaddr - 7); /* Write value */
240 udelay(10);
241 }
242 else
243 { /* release OPL4 port */
244 release_region(ioaddr - 8, 2);
245 detected_model = 3;
246 }
247 }
248 opl3_command(ioaddr + 2, OPL3_MODE_REGISTER, 0);
249 }
250 for (i = 0; i < 9; i++)
251 opl3_command(ioaddr, KEYON_BLOCK + i, 0); /*
252 * Note off
253 */
254
255 opl3_command(ioaddr, TEST_REGISTER, ENABLE_WAVE_SELECT);
256 opl3_command(ioaddr, PERCOSSION_REGISTER, 0x00); /*
257 * Melodic mode.
258 */
259 return 1;
260cleanup_region:
261 release_region(ioaddr, 4);
262cleanup_devc:
263 kfree(devc);
264 devc = NULL;
265 return 0;
266}
267
268static int opl3_kill_note (int devno, int voice, int note, int velocity)
269{
270 struct physical_voice_info *map;
271
272 if (voice < 0 || voice >= devc->nr_voice)
273 return 0;
274
275 devc->v_alloc->map[voice] = 0;
276
277 map = &pv_map[devc->lv_map[voice]];
278
279 if (map->voice_mode == 0)
280 return 0;
281
282 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, devc->voc[voice].keyon_byte & ~0x20);
283 devc->voc[voice].keyon_byte = 0;
284 devc->voc[voice].bender = 0;
285 devc->voc[voice].volume = 64;
286 devc->voc[voice].panning = 0xffff; /* Not set */
287 devc->voc[voice].bender_range = 200;
288 devc->voc[voice].orig_freq = 0;
289 devc->voc[voice].current_freq = 0;
290 devc->voc[voice].mode = 0;
291 return 0;
292}
293
294#define HIHAT 0
295#define CYMBAL 1
296#define TOMTOM 2
297#define SNARE 3
298#define BDRUM 4
299#define UNDEFINED TOMTOM
300#define DEFAULT TOMTOM
301
302static int store_instr(int instr_no, struct sbi_instrument *instr)
303{
304 if (instr->key != FM_PATCH && (instr->key != OPL3_PATCH || devc->model != 2))
305 printk(KERN_WARNING "FM warning: Invalid patch format field (key) 0x%x\n", instr->key);
306 memcpy((char *) &(devc->i_map[instr_no]), (char *) instr, sizeof(*instr));
307 return 0;
308}
309
310static int opl3_set_instr (int dev, int voice, int instr_no)
311{
312 if (voice < 0 || voice >= devc->nr_voice)
313 return 0;
314 if (instr_no < 0 || instr_no >= SBFM_MAXINSTR)
315 instr_no = 0; /* Acoustic piano (usually) */
316
317 devc->act_i[voice] = &devc->i_map[instr_no];
318 return 0;
319}
320
321/*
322 * The next table looks magical, but it certainly is not. Its values have
323 * been calculated as table[i]=8*log(i/64)/log(2) with an obvious exception
324 * for i=0. This log-table converts a linear volume-scaling (0..127) to a
325 * logarithmic scaling as present in the FM-synthesizer chips. so : Volume
326 * 64 = 0 db = relative volume 0 and: Volume 32 = -6 db = relative
327 * volume -8 it was implemented as a table because it is only 128 bytes and
328 * it saves a lot of log() calculations. (RH)
329 */
330
331static char fm_volume_table[128] =
332{
333 -64, -48, -40, -35, -32, -29, -27, -26,
334 -24, -23, -21, -20, -19, -18, -18, -17,
335 -16, -15, -15, -14, -13, -13, -12, -12,
336 -11, -11, -10, -10, -10, -9, -9, -8,
337 -8, -8, -7, -7, -7, -6, -6, -6,
338 -5, -5, -5, -5, -4, -4, -4, -4,
339 -3, -3, -3, -3, -2, -2, -2, -2,
340 -2, -1, -1, -1, -1, 0, 0, 0,
341 0, 0, 0, 1, 1, 1, 1, 1,
342 1, 2, 2, 2, 2, 2, 2, 2,
343 3, 3, 3, 3, 3, 3, 3, 4,
344 4, 4, 4, 4, 4, 4, 4, 5,
345 5, 5, 5, 5, 5, 5, 5, 5,
346 6, 6, 6, 6, 6, 6, 6, 6,
347 6, 7, 7, 7, 7, 7, 7, 7,
348 7, 7, 7, 8, 8, 8, 8, 8
349};
350
351static void calc_vol(unsigned char *regbyte, int volume, int main_vol)
352{
353 int level = (~*regbyte & 0x3f);
354
355 if (main_vol > 127)
356 main_vol = 127;
357 volume = (volume * main_vol) / 127;
358
359 if (level)
360 level += fm_volume_table[volume];
361
362 if (level > 0x3f)
363 level = 0x3f;
364 if (level < 0)
365 level = 0;
366
367 *regbyte = (*regbyte & 0xc0) | (~level & 0x3f);
368}
369
370static void set_voice_volume(int voice, int volume, int main_vol)
371{
372 unsigned char vol1, vol2, vol3, vol4;
373 struct sbi_instrument *instr;
374 struct physical_voice_info *map;
375
376 if (voice < 0 || voice >= devc->nr_voice)
377 return;
378
379 map = &pv_map[devc->lv_map[voice]];
380 instr = devc->act_i[voice];
381
382 if (!instr)
383 instr = &devc->i_map[0];
384
385 if (instr->channel < 0)
386 return;
387
388 if (devc->voc[voice].mode == 0)
389 return;
390
391 if (devc->voc[voice].mode == 2)
392 {
393 vol1 = instr->operators[2];
394 vol2 = instr->operators[3];
395 if ((instr->operators[10] & 0x01))
396 {
397 calc_vol(&vol1, volume, main_vol);
398 calc_vol(&vol2, volume, main_vol);
399 }
400 else
401 {
402 calc_vol(&vol2, volume, main_vol);
403 }
404 opl3_command(map->ioaddr, KSL_LEVEL + map->op[0], vol1);
405 opl3_command(map->ioaddr, KSL_LEVEL + map->op[1], vol2);
406 }
407 else
408 { /*
409 * 4 OP voice
410 */
411 int connection;
412
413 vol1 = instr->operators[2];
414 vol2 = instr->operators[3];
415 vol3 = instr->operators[OFFS_4OP + 2];
416 vol4 = instr->operators[OFFS_4OP + 3];
417
418 /*
419 * The connection method for 4 OP devc->voc is defined by the rightmost
420 * bits at the offsets 10 and 10+OFFS_4OP
421 */
422
423 connection = ((instr->operators[10] & 0x01) << 1) | (instr->operators[10 + OFFS_4OP] & 0x01);
424
425 switch (connection)
426 {
427 case 0:
428 calc_vol(&vol4, volume, main_vol);
429 break;
430
431 case 1:
432 calc_vol(&vol2, volume, main_vol);
433 calc_vol(&vol4, volume, main_vol);
434 break;
435
436 case 2:
437 calc_vol(&vol1, volume, main_vol);
438 calc_vol(&vol4, volume, main_vol);
439 break;
440
441 case 3:
442 calc_vol(&vol1, volume, main_vol);
443 calc_vol(&vol3, volume, main_vol);
444 calc_vol(&vol4, volume, main_vol);
445 break;
446
447 default:
448 ;
449 }
450 opl3_command(map->ioaddr, KSL_LEVEL + map->op[0], vol1);
451 opl3_command(map->ioaddr, KSL_LEVEL + map->op[1], vol2);
452 opl3_command(map->ioaddr, KSL_LEVEL + map->op[2], vol3);
453 opl3_command(map->ioaddr, KSL_LEVEL + map->op[3], vol4);
454 }
455}
456
457static int opl3_start_note (int dev, int voice, int note, int volume)
458{
459 unsigned char data, fpc;
460 int block, fnum, freq, voice_mode, pan;
461 struct sbi_instrument *instr;
462 struct physical_voice_info *map;
463
464 if (voice < 0 || voice >= devc->nr_voice)
465 return 0;
466
467 map = &pv_map[devc->lv_map[voice]];
468 pan = devc->voc[voice].panning;
469
470 if (map->voice_mode == 0)
471 return 0;
472
473 if (note == 255) /*
474 * Just change the volume
475 */
476 {
477 set_voice_volume(voice, volume, devc->voc[voice].volume);
478 return 0;
479 }
480
481 /*
482 * Kill previous note before playing
483 */
484
485 opl3_command(map->ioaddr, KSL_LEVEL + map->op[1], 0xff); /*
486 * Carrier
487 * volume to
488 * min
489 */
490 opl3_command(map->ioaddr, KSL_LEVEL + map->op[0], 0xff); /*
491 * Modulator
492 * volume to
493 */
494
495 if (map->voice_mode == 4)
496 {
497 opl3_command(map->ioaddr, KSL_LEVEL + map->op[2], 0xff);
498 opl3_command(map->ioaddr, KSL_LEVEL + map->op[3], 0xff);
499 }
500
501 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, 0x00); /*
502 * Note
503 * off
504 */
505
506 instr = devc->act_i[voice];
507
508 if (!instr)
509 instr = &devc->i_map[0];
510
511 if (instr->channel < 0)
512 {
513 printk(KERN_WARNING "opl3: Initializing voice %d with undefined instrument\n", voice);
514 return 0;
515 }
516
517 if (map->voice_mode == 2 && instr->key == OPL3_PATCH)
518 return 0; /*
519 * Cannot play
520 */
521
522 voice_mode = map->voice_mode;
523
524 if (voice_mode == 4)
525 {
526 int voice_shift;
527
528 voice_shift = (map->ioaddr == devc->left_io) ? 0 : 3;
529 voice_shift += map->voice_num;
530
531 if (instr->key != OPL3_PATCH) /*
532 * Just 2 OP patch
533 */
534 {
535 voice_mode = 2;
536 devc->cmask &= ~(1 << voice_shift);
537 }
538 else
539 {
540 devc->cmask |= (1 << voice_shift);
541 }
542
543 opl3_command(devc->right_io, CONNECTION_SELECT_REGISTER, devc->cmask);
544 }
545
546 /*
547 * Set Sound Characteristics
548 */
549
550 opl3_command(map->ioaddr, AM_VIB + map->op[0], instr->operators[0]);
551 opl3_command(map->ioaddr, AM_VIB + map->op[1], instr->operators[1]);
552
553 /*
554 * Set Attack/Decay
555 */
556
557 opl3_command(map->ioaddr, ATTACK_DECAY + map->op[0], instr->operators[4]);
558 opl3_command(map->ioaddr, ATTACK_DECAY + map->op[1], instr->operators[5]);
559
560 /*
561 * Set Sustain/Release
562 */
563
564 opl3_command(map->ioaddr, SUSTAIN_RELEASE + map->op[0], instr->operators[6]);
565 opl3_command(map->ioaddr, SUSTAIN_RELEASE + map->op[1], instr->operators[7]);
566
567 /*
568 * Set Wave Select
569 */
570
571 opl3_command(map->ioaddr, WAVE_SELECT + map->op[0], instr->operators[8]);
572 opl3_command(map->ioaddr, WAVE_SELECT + map->op[1], instr->operators[9]);
573
574 /*
575 * Set Feedback/Connection
576 */
577
578 fpc = instr->operators[10];
579
580 if (pan != 0xffff)
581 {
582 fpc &= ~STEREO_BITS;
583 if (pan < -64)
584 fpc |= VOICE_TO_LEFT;
585 else
586 if (pan > 64)
587 fpc |= VOICE_TO_RIGHT;
588 else
589 fpc |= (VOICE_TO_LEFT | VOICE_TO_RIGHT);
590 }
591
592 if (!(fpc & 0x30))
593 fpc |= 0x30; /*
594 * Ensure that at least one chn is enabled
595 */
596 opl3_command(map->ioaddr, FEEDBACK_CONNECTION + map->voice_num, fpc);
597
598 /*
599 * If the voice is a 4 OP one, initialize the operators 3 and 4 also
600 */
601
602 if (voice_mode == 4)
603 {
604 /*
605 * Set Sound Characteristics
606 */
607
608 opl3_command(map->ioaddr, AM_VIB + map->op[2], instr->operators[OFFS_4OP + 0]);
609 opl3_command(map->ioaddr, AM_VIB + map->op[3], instr->operators[OFFS_4OP + 1]);
610
611 /*
612 * Set Attack/Decay
613 */
614
615 opl3_command(map->ioaddr, ATTACK_DECAY + map->op[2], instr->operators[OFFS_4OP + 4]);
616 opl3_command(map->ioaddr, ATTACK_DECAY + map->op[3], instr->operators[OFFS_4OP + 5]);
617
618 /*
619 * Set Sustain/Release
620 */
621
622 opl3_command(map->ioaddr, SUSTAIN_RELEASE + map->op[2], instr->operators[OFFS_4OP + 6]);
623 opl3_command(map->ioaddr, SUSTAIN_RELEASE + map->op[3], instr->operators[OFFS_4OP + 7]);
624
625 /*
626 * Set Wave Select
627 */
628
629 opl3_command(map->ioaddr, WAVE_SELECT + map->op[2], instr->operators[OFFS_4OP + 8]);
630 opl3_command(map->ioaddr, WAVE_SELECT + map->op[3], instr->operators[OFFS_4OP + 9]);
631
632 /*
633 * Set Feedback/Connection
634 */
635
636 fpc = instr->operators[OFFS_4OP + 10];
637 if (!(fpc & 0x30))
638 fpc |= 0x30; /*
639 * Ensure that at least one chn is enabled
640 */
641 opl3_command(map->ioaddr, FEEDBACK_CONNECTION + map->voice_num + 3, fpc);
642 }
643
644 devc->voc[voice].mode = voice_mode;
645 set_voice_volume(voice, volume, devc->voc[voice].volume);
646
647 freq = devc->voc[voice].orig_freq = note_to_freq(note) / 1000;
648
649 /*
650 * Since the pitch bender may have been set before playing the note, we
651 * have to calculate the bending now.
652 */
653
654 freq = compute_finetune(devc->voc[voice].orig_freq, devc->voc[voice].bender, devc->voc[voice].bender_range, 0);
655 devc->voc[voice].current_freq = freq;
656
657 freq_to_fnum(freq, &block, &fnum);
658
659 /*
660 * Play note
661 */
662
663 data = fnum & 0xff; /*
664 * Least significant bits of fnumber
665 */
666 opl3_command(map->ioaddr, FNUM_LOW + map->voice_num, data);
667
668 data = 0x20 | ((block & 0x7) << 2) | ((fnum >> 8) & 0x3);
669 devc->voc[voice].keyon_byte = data;
670 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, data);
671 if (voice_mode == 4)
672 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num + 3, data);
673
674 return 0;
675}
676
677static void freq_to_fnum (int freq, int *block, int *fnum)
678{
679 int f, octave;
680
681 /*
682 * Converts the note frequency to block and fnum values for the FM chip
683 */
684 /*
685 * First try to compute the block -value (octave) where the note belongs
686 */
687
688 f = freq;
689
690 octave = 5;
691
692 if (f == 0)
693 octave = 0;
694 else if (f < 261)
695 {
696 while (f < 261)
697 {
698 octave--;
699 f <<= 1;
700 }
701 }
702 else if (f > 493)
703 {
704 while (f > 493)
705 {
706 octave++;
707 f >>= 1;
708 }
709 }
710
711 if (octave > 7)
712 octave = 7;
713
714 *fnum = freq * (1 << (20 - octave)) / 49716;
715 *block = octave;
716}
717
718static void opl3_command (int io_addr, unsigned int addr, unsigned int val)
719{
720 int i;
721
722 /*
723 * The original 2-OP synth requires a quite long delay after writing to a
724 * register. The OPL-3 survives with just two INBs
725 */
726
727 outb(((unsigned char) (addr & 0xff)), io_addr);
728
729 if (devc->model != 2)
730 udelay(10);
731 else
732 for (i = 0; i < 2; i++)
733 inb(io_addr);
734
735 outb(((unsigned char) (val & 0xff)), io_addr + 1);
736
737 if (devc->model != 2)
738 udelay(30);
739 else
740 for (i = 0; i < 2; i++)
741 inb(io_addr);
742}
743
744static void opl3_reset(int devno)
745{
746 int i;
747
748 for (i = 0; i < 18; i++)
749 devc->lv_map[i] = i;
750
751 for (i = 0; i < devc->nr_voice; i++)
752 {
753 opl3_command(pv_map[devc->lv_map[i]].ioaddr,
754 KSL_LEVEL + pv_map[devc->lv_map[i]].op[0], 0xff);
755
756 opl3_command(pv_map[devc->lv_map[i]].ioaddr,
757 KSL_LEVEL + pv_map[devc->lv_map[i]].op[1], 0xff);
758
759 if (pv_map[devc->lv_map[i]].voice_mode == 4)
760 {
761 opl3_command(pv_map[devc->lv_map[i]].ioaddr,
762 KSL_LEVEL + pv_map[devc->lv_map[i]].op[2], 0xff);
763
764 opl3_command(pv_map[devc->lv_map[i]].ioaddr,
765 KSL_LEVEL + pv_map[devc->lv_map[i]].op[3], 0xff);
766 }
767
768 opl3_kill_note(devno, i, 0, 64);
769 }
770
771 if (devc->model == 2)
772 {
773 devc->v_alloc->max_voice = devc->nr_voice = 18;
774
775 for (i = 0; i < 18; i++)
776 pv_map[i].voice_mode = 2;
777
778 }
779}
780
781static int opl3_open(int dev, int mode)
782{
783 int i;
784
785 if (devc->busy)
786 return -EBUSY;
787 devc->busy = 1;
788
789 devc->v_alloc->max_voice = devc->nr_voice = (devc->model == 2) ? 18 : 9;
790 devc->v_alloc->timestamp = 0;
791
792 for (i = 0; i < 18; i++)
793 {
794 devc->v_alloc->map[i] = 0;
795 devc->v_alloc->alloc_times[i] = 0;
796 }
797
798 devc->cmask = 0x00; /*
799 * Just 2 OP mode
800 */
801 if (devc->model == 2)
802 opl3_command(devc->right_io, CONNECTION_SELECT_REGISTER, devc->cmask);
803 return 0;
804}
805
806static void opl3_close(int dev)
807{
808 devc->busy = 0;
809 devc->v_alloc->max_voice = devc->nr_voice = (devc->model == 2) ? 18 : 9;
810
811 devc->fm_info.nr_drums = 0;
812 devc->fm_info.perc_mode = 0;
813
814 opl3_reset(dev);
815}
816
817static void opl3_hw_control(int dev, unsigned char *event)
818{
819}
820
821static int opl3_load_patch(int dev, int format, const char __user *addr,
822 int count, int pmgr_flag)
823{
824 struct sbi_instrument ins;
825
826 if (count <sizeof(ins))
827 {
828 printk(KERN_WARNING "FM Error: Patch record too short\n");
829 return -EINVAL;
830 }
831
832 if (copy_from_user(&ins, addr, sizeof(ins)))
833 return -EFAULT;
834
835 if (ins.channel < 0 || ins.channel >= SBFM_MAXINSTR)
836 {
837 printk(KERN_WARNING "FM Error: Invalid instrument number %d\n", ins.channel);
838 return -EINVAL;
839 }
840 ins.key = format;
841
842 return store_instr(ins.channel, &ins);
843}
844
845static void opl3_panning(int dev, int voice, int value)
846{
847
848 if (voice < 0 || voice >= devc->nr_voice)
849 return;
850
851 devc->voc[voice].panning = value;
852}
853
854static void opl3_volume_method(int dev, int mode)
855{
856}
857
858#define SET_VIBRATO(cell) { \
859 tmp = instr->operators[(cell-1)+(((cell-1)/2)*OFFS_4OP)]; \
860 if (pressure > 110) \
861 tmp |= 0x40; /* Vibrato on */ \
862 opl3_command (map->ioaddr, AM_VIB + map->op[cell-1], tmp);}
863
864static void opl3_aftertouch(int dev, int voice, int pressure)
865{
866 int tmp;
867 struct sbi_instrument *instr;
868 struct physical_voice_info *map;
869
870 if (voice < 0 || voice >= devc->nr_voice)
871 return;
872
873 map = &pv_map[devc->lv_map[voice]];
874
875 if (map->voice_mode == 0)
876 return;
877
878 /*
879 * Adjust the amount of vibrato depending the pressure
880 */
881
882 instr = devc->act_i[voice];
883
884 if (!instr)
885 instr = &devc->i_map[0];
886
887 if (devc->voc[voice].mode == 4)
888 {
889 int connection = ((instr->operators[10] & 0x01) << 1) | (instr->operators[10 + OFFS_4OP] & 0x01);
890
891 switch (connection)
892 {
893 case 0:
894 SET_VIBRATO(4);
895 break;
896
897 case 1:
898 SET_VIBRATO(2);
899 SET_VIBRATO(4);
900 break;
901
902 case 2:
903 SET_VIBRATO(1);
904 SET_VIBRATO(4);
905 break;
906
907 case 3:
908 SET_VIBRATO(1);
909 SET_VIBRATO(3);
910 SET_VIBRATO(4);
911 break;
912
913 }
914 /*
915 * Not implemented yet
916 */
917 }
918 else
919 {
920 SET_VIBRATO(1);
921
922 if ((instr->operators[10] & 0x01)) /*
923 * Additive synthesis
924 */
925 SET_VIBRATO(2);
926 }
927}
928
929#undef SET_VIBRATO
930
931static void bend_pitch(int dev, int voice, int value)
932{
933 unsigned char data;
934 int block, fnum, freq;
935 struct physical_voice_info *map;
936
937 map = &pv_map[devc->lv_map[voice]];
938
939 if (map->voice_mode == 0)
940 return;
941
942 devc->voc[voice].bender = value;
943 if (!value)
944 return;
945 if (!(devc->voc[voice].keyon_byte & 0x20))
946 return; /*
947 * Not keyed on
948 */
949
950 freq = compute_finetune(devc->voc[voice].orig_freq, devc->voc[voice].bender, devc->voc[voice].bender_range, 0);
951 devc->voc[voice].current_freq = freq;
952
953 freq_to_fnum(freq, &block, &fnum);
954
955 data = fnum & 0xff; /*
956 * Least significant bits of fnumber
957 */
958 opl3_command(map->ioaddr, FNUM_LOW + map->voice_num, data);
959
960 data = 0x20 | ((block & 0x7) << 2) | ((fnum >> 8) & 0x3);
961 devc->voc[voice].keyon_byte = data;
962 opl3_command(map->ioaddr, KEYON_BLOCK + map->voice_num, data);
963}
964
965static void opl3_controller (int dev, int voice, int ctrl_num, int value)
966{
967 if (voice < 0 || voice >= devc->nr_voice)
968 return;
969
970 switch (ctrl_num)
971 {
972 case CTRL_PITCH_BENDER:
973 bend_pitch(dev, voice, value);
974 break;
975
976 case CTRL_PITCH_BENDER_RANGE:
977 devc->voc[voice].bender_range = value;
978 break;
979
980 case CTL_MAIN_VOLUME:
981 devc->voc[voice].volume = value / 128;
982 break;
983
984 case CTL_PAN:
985 devc->voc[voice].panning = (value * 2) - 128;
986 break;
987 }
988}
989
990static void opl3_bender(int dev, int voice, int value)
991{
992 if (voice < 0 || voice >= devc->nr_voice)
993 return;
994
995 bend_pitch(dev, voice, value - 8192);
996}
997
998static int opl3_alloc_voice(int dev, int chn, int note, struct voice_alloc_info *alloc)
999{
1000 int i, p, best, first, avail, best_time = 0x7fffffff;
1001 struct sbi_instrument *instr;
1002 int is4op;
1003 int instr_no;
1004
1005 if (chn < 0 || chn > 15)
1006 instr_no = 0;
1007 else
1008 instr_no = devc->chn_info[chn].pgm_num;
1009
1010 instr = &devc->i_map[instr_no];
1011 if (instr->channel < 0 || /* Instrument not loaded */
1012 devc->nr_voice != 12) /* Not in 4 OP mode */
1013 is4op = 0;
1014 else if (devc->nr_voice == 12) /* 4 OP mode */
1015 is4op = (instr->key == OPL3_PATCH);
1016 else
1017 is4op = 0;
1018
1019 if (is4op)
1020 {
1021 first = p = 0;
1022 avail = 6;
1023 }
1024 else
1025 {
1026 if (devc->nr_voice == 12) /* 4 OP mode. Use the '2 OP only' operators first */
1027 first = p = 6;
1028 else
1029 first = p = 0;
1030 avail = devc->nr_voice;
1031 }
1032
1033 /*
1034 * Now try to find a free voice
1035 */
1036 best = first;
1037
1038 for (i = 0; i < avail; i++)
1039 {
1040 if (alloc->map[p] == 0)
1041 {
1042 return p;
1043 }
1044 if (alloc->alloc_times[p] < best_time) /* Find oldest playing note */
1045 {
1046 best_time = alloc->alloc_times[p];
1047 best = p;
1048 }
1049 p = (p + 1) % avail;
1050 }
1051
1052 /*
1053 * Insert some kind of priority mechanism here.
1054 */
1055
1056 if (best < 0)
1057 best = 0;
1058 if (best > devc->nr_voice)
1059 best -= devc->nr_voice;
1060
1061 return best; /* All devc->voc in use. Select the first one. */
1062}
1063
1064static void opl3_setup_voice(int dev, int voice, int chn)
1065{
1066 struct channel_info *info;
1067
1068 if (voice < 0 || voice >= devc->nr_voice)
1069 return;
1070
1071 if (chn < 0 || chn > 15)
1072 return;
1073
1074 info = &synth_devs[dev]->chn_info[chn];
1075
1076 opl3_set_instr(dev, voice, info->pgm_num);
1077
1078 devc->voc[voice].bender = 0;
1079 devc->voc[voice].bender_range = info->bender_range;
1080 devc->voc[voice].volume = info->controllers[CTL_MAIN_VOLUME];
1081 devc->voc[voice].panning = (info->controllers[CTL_PAN] * 2) - 128;
1082}
1083
1084static struct synth_operations opl3_operations =
1085{
1086 .owner = THIS_MODULE,
1087 .id = "OPL",
1088 .info = NULL,
1089 .midi_dev = 0,
1090 .synth_type = SYNTH_TYPE_FM,
1091 .synth_subtype = FM_TYPE_ADLIB,
1092 .open = opl3_open,
1093 .close = opl3_close,
1094 .ioctl = opl3_ioctl,
1095 .kill_note = opl3_kill_note,
1096 .start_note = opl3_start_note,
1097 .set_instr = opl3_set_instr,
1098 .reset = opl3_reset,
1099 .hw_control = opl3_hw_control,
1100 .load_patch = opl3_load_patch,
1101 .aftertouch = opl3_aftertouch,
1102 .controller = opl3_controller,
1103 .panning = opl3_panning,
1104 .volume_method = opl3_volume_method,
1105 .bender = opl3_bender,
1106 .alloc_voice = opl3_alloc_voice,
1107 .setup_voice = opl3_setup_voice
1108};
1109
1110static int opl3_init(int ioaddr, struct module *owner)
1111{
1112 int i;
1113 int me;
1114
1115 if (devc == NULL)
1116 {
1117 printk(KERN_ERR "opl3: Device control structure not initialized.\n");
1118 return -1;
1119 }
1120
1121 if ((me = sound_alloc_synthdev()) == -1)
1122 {
1123 printk(KERN_WARNING "opl3: Too many synthesizers\n");
1124 return -1;
1125 }
1126
1127 devc->nr_voice = 9;
1128
1129 devc->fm_info.device = 0;
1130 devc->fm_info.synth_type = SYNTH_TYPE_FM;
1131 devc->fm_info.synth_subtype = FM_TYPE_ADLIB;
1132 devc->fm_info.perc_mode = 0;
1133 devc->fm_info.nr_voices = 9;
1134 devc->fm_info.nr_drums = 0;
1135 devc->fm_info.instr_bank_size = SBFM_MAXINSTR;
1136 devc->fm_info.capabilities = 0;
1137 devc->left_io = ioaddr;
1138 devc->right_io = ioaddr + 2;
1139
1140 if (detected_model <= 2)
1141 devc->model = 1;
1142 else
1143 {
1144 devc->model = 2;
1145 if (detected_model == 4)
1146 devc->is_opl4 = 1;
1147 }
1148
1149 opl3_operations.info = &devc->fm_info;
1150
1151 synth_devs[me] = &opl3_operations;
1152
1153 if (owner)
1154 synth_devs[me]->owner = owner;
1155
1156 sequencer_init();
1157 devc->v_alloc = &opl3_operations.alloc;
1158 devc->chn_info = &opl3_operations.chn_info[0];
1159
1160 if (devc->model == 2)
1161 {
1162 if (devc->is_opl4)
1163 strcpy(devc->fm_info.name, "Yamaha OPL4/OPL3 FM");
1164 else
1165 strcpy(devc->fm_info.name, "Yamaha OPL3");
1166
1167 devc->v_alloc->max_voice = devc->nr_voice = 18;
1168 devc->fm_info.nr_drums = 0;
1169 devc->fm_info.synth_subtype = FM_TYPE_OPL3;
1170 devc->fm_info.capabilities |= SYNTH_CAP_OPL3;
1171
1172 for (i = 0; i < 18; i++)
1173 {
1174 if (pv_map[i].ioaddr == USE_LEFT)
1175 pv_map[i].ioaddr = devc->left_io;
1176 else
1177 pv_map[i].ioaddr = devc->right_io;
1178 }
1179 opl3_command(devc->right_io, OPL3_MODE_REGISTER, OPL3_ENABLE);
1180 opl3_command(devc->right_io, CONNECTION_SELECT_REGISTER, 0x00);
1181 }
1182 else
1183 {
1184 strcpy(devc->fm_info.name, "Yamaha OPL2");
1185 devc->v_alloc->max_voice = devc->nr_voice = 9;
1186 devc->fm_info.nr_drums = 0;
1187
1188 for (i = 0; i < 18; i++)
1189 pv_map[i].ioaddr = devc->left_io;
1190 }
1191 conf_printf2(devc->fm_info.name, ioaddr, 0, -1, -1);
1192
1193 for (i = 0; i < SBFM_MAXINSTR; i++)
1194 devc->i_map[i].channel = -1;
1195
1196 return me;
1197}
1198
1199static int me;
1200
1201static int io = -1;
1202
1203module_param_hw(io, int, ioport, 0);
1204
1205static int __init init_opl3 (void)
1206{
1207 printk(KERN_INFO "YM3812 and OPL-3 driver Copyright (C) by Hannu Savolainen, Rob Hooft 1993-1996\n");
1208
1209 if (io != -1) /* User loading pure OPL3 module */
1210 {
1211 if (!opl3_detect(io))
1212 {
1213 return -ENODEV;
1214 }
1215
1216 me = opl3_init(io, THIS_MODULE);
1217 }
1218
1219 return 0;
1220}
1221
1222static void __exit cleanup_opl3(void)
1223{
1224 if (devc && io != -1)
1225 {
1226 if (devc->base) {
1227 release_region(devc->base,4);
1228 if (devc->is_opl4)
1229 release_region(devc->base - 8, 2);
1230 }
1231 kfree(devc);
1232 devc = NULL;
1233 sound_unload_synthdev(me);
1234 }
1235}
1236
1237module_init(init_opl3);
1238module_exit(cleanup_opl3);
1239
1240#ifndef MODULE
1241static int __init setup_opl3(char *str)
1242{
1243 /* io */
1244 int ints[2];
1245
1246 str = get_options(str, ARRAY_SIZE(ints), ints);
1247
1248 io = ints[1];
1249
1250 return 1;
1251}
1252
1253__setup("opl3=", setup_opl3);
1254#endif
1255MODULE_LICENSE("GPL");
diff --git a/sound/oss/opl3_hw.h b/sound/oss/opl3_hw.h
deleted file mode 100644
index 8b11c893e869..000000000000
--- a/sound/oss/opl3_hw.h
+++ /dev/null
@@ -1,246 +0,0 @@
1/*
2 * opl3_hw.h - Definitions of the OPL-3 registers
3 *
4 *
5 * Copyright (C) by Hannu Savolainen 1993-1997
6 *
7 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
8 * Version 2 (June 1991). See the "COPYING" file distributed with this software
9 * for more info.
10 *
11 *
12 * The OPL-3 mode is switched on by writing 0x01, to the offset 5
13 * of the right side.
14 *
15 * Another special register at the right side is at offset 4. It contains
16 * a bit mask defining which voices are used as 4 OP voices.
17 *
18 * The percussive mode is implemented in the left side only.
19 *
20 * With the above exceptions the both sides can be operated independently.
21 *
22 * A 4 OP voice can be created by setting the corresponding
23 * bit at offset 4 of the right side.
24 *
25 * For example setting the rightmost bit (0x01) changes the
26 * first voice on the right side to the 4 OP mode. The fourth
27 * voice is made inaccessible.
28 *
29 * If a voice is set to the 2 OP mode, it works like 2 OP modes
30 * of the original YM3812 (AdLib). In addition the voice can
31 * be connected the left, right or both stereo channels. It can
32 * even be left unconnected. This works with 4 OP voices also.
33 *
34 * The stereo connection bits are located in the FEEDBACK_CONNECTION
35 * register of the voice (0xC0-0xC8). In 4 OP voices these bits are
36 * in the second half of the voice.
37 */
38
39/*
40 * Register numbers for the global registers
41 */
42
43#define TEST_REGISTER 0x01
44#define ENABLE_WAVE_SELECT 0x20
45
46#define TIMER1_REGISTER 0x02
47#define TIMER2_REGISTER 0x03
48#define TIMER_CONTROL_REGISTER 0x04 /* Left side */
49#define IRQ_RESET 0x80
50#define TIMER1_MASK 0x40
51#define TIMER2_MASK 0x20
52#define TIMER1_START 0x01
53#define TIMER2_START 0x02
54
55#define CONNECTION_SELECT_REGISTER 0x04 /* Right side */
56#define RIGHT_4OP_0 0x01
57#define RIGHT_4OP_1 0x02
58#define RIGHT_4OP_2 0x04
59#define LEFT_4OP_0 0x08
60#define LEFT_4OP_1 0x10
61#define LEFT_4OP_2 0x20
62
63#define OPL3_MODE_REGISTER 0x05 /* Right side */
64#define OPL3_ENABLE 0x01
65#define OPL4_ENABLE 0x02
66
67#define KBD_SPLIT_REGISTER 0x08 /* Left side */
68#define COMPOSITE_SINE_WAVE_MODE 0x80 /* Don't use with OPL-3? */
69#define KEYBOARD_SPLIT 0x40
70
71#define PERCOSSION_REGISTER 0xbd /* Left side only */
72#define TREMOLO_DEPTH 0x80
73#define VIBRATO_DEPTH 0x40
74#define PERCOSSION_ENABLE 0x20
75#define BASSDRUM_ON 0x10
76#define SNAREDRUM_ON 0x08
77#define TOMTOM_ON 0x04
78#define CYMBAL_ON 0x02
79#define HIHAT_ON 0x01
80
81/*
82 * Offsets to the register banks for operators. To get the
83 * register number just add the operator offset to the bank offset
84 *
85 * AM/VIB/EG/KSR/Multiple (0x20 to 0x35)
86 */
87#define AM_VIB 0x20
88#define TREMOLO_ON 0x80
89#define VIBRATO_ON 0x40
90#define SUSTAIN_ON 0x20
91#define KSR 0x10 /* Key scaling rate */
92#define MULTIPLE_MASK 0x0f /* Frequency multiplier */
93
94 /*
95 * KSL/Total level (0x40 to 0x55)
96 */
97#define KSL_LEVEL 0x40
98#define KSL_MASK 0xc0 /* Envelope scaling bits */
99#define TOTAL_LEVEL_MASK 0x3f /* Strength (volume) of OP */
100
101/*
102 * Attack / Decay rate (0x60 to 0x75)
103 */
104#define ATTACK_DECAY 0x60
105#define ATTACK_MASK 0xf0
106#define DECAY_MASK 0x0f
107
108/*
109 * Sustain level / Release rate (0x80 to 0x95)
110 */
111#define SUSTAIN_RELEASE 0x80
112#define SUSTAIN_MASK 0xf0
113#define RELEASE_MASK 0x0f
114
115/*
116 * Wave select (0xE0 to 0xF5)
117 */
118#define WAVE_SELECT 0xe0
119
120/*
121 * Offsets to the register banks for voices. Just add to the
122 * voice number to get the register number.
123 *
124 * F-Number low bits (0xA0 to 0xA8).
125 */
126#define FNUM_LOW 0xa0
127
128/*
129 * F-number high bits / Key on / Block (octave) (0xB0 to 0xB8)
130 */
131#define KEYON_BLOCK 0xb0
132#define KEYON_BIT 0x20
133#define BLOCKNUM_MASK 0x1c
134#define FNUM_HIGH_MASK 0x03
135
136/*
137 * Feedback / Connection (0xc0 to 0xc8)
138 *
139 * These registers have two new bits when the OPL-3 mode
140 * is selected. These bits controls connecting the voice
141 * to the stereo channels. For 4 OP voices this bit is
142 * defined in the second half of the voice (add 3 to the
143 * register offset).
144 *
145 * For 4 OP voices the connection bit is used in the
146 * both halves (gives 4 ways to connect the operators).
147 */
148#define FEEDBACK_CONNECTION 0xc0
149#define FEEDBACK_MASK 0x0e /* Valid just for 1st OP of a voice */
150#define CONNECTION_BIT 0x01
151/*
152 * In the 4 OP mode there is four possible configurations how the
153 * operators can be connected together (in 2 OP modes there is just
154 * AM or FM). The 4 OP connection mode is defined by the rightmost
155 * bit of the FEEDBACK_CONNECTION (0xC0-0xC8) on the both halves.
156 *
157 * First half Second half Mode
158 *
159 * +---+
160 * v |
161 * 0 0 >+-1-+--2--3--4-->
162 *
163 *
164 *
165 * +---+
166 * | |
167 * 0 1 >+-1-+--2-+
168 * |->
169 * >--3----4-+
170 *
171 * +---+
172 * | |
173 * 1 0 >+-1-+-----+
174 * |->
175 * >--2--3--4-+
176 *
177 * +---+
178 * | |
179 * 1 1 >+-1-+--+
180 * |
181 * >--2--3-+->
182 * |
183 * >--4----+
184 */
185#define STEREO_BITS 0x30 /* OPL-3 only */
186#define VOICE_TO_LEFT 0x10
187#define VOICE_TO_RIGHT 0x20
188
189/*
190 * Definition table for the physical voices
191 */
192
193struct physical_voice_info {
194 unsigned char voice_num;
195 unsigned char voice_mode; /* 0=unavailable, 2=2 OP, 4=4 OP */
196 unsigned short ioaddr; /* I/O port (left or right side) */
197 unsigned char op[4]; /* Operator offsets */
198 };
199
200/*
201 * There is 18 possible 2 OP voices
202 * (9 in the left and 9 in the right).
203 * The first OP is the modulator and 2nd is the carrier.
204 *
205 * The first three voices in the both sides may be connected
206 * with another voice to a 4 OP voice. For example voice 0
207 * can be connected with voice 3. The operators of voice 3 are
208 * used as operators 3 and 4 of the new 4 OP voice.
209 * In this case the 2 OP voice number 0 is the 'first half' and
210 * voice 3 is the second.
211 */
212
213#define USE_LEFT 0
214#define USE_RIGHT 1
215
216static struct physical_voice_info pv_map[18] =
217{
218/* No Mode Side OP1 OP2 OP3 OP4 */
219/* --------------------------------------------------- */
220 { 0, 2, USE_LEFT, {0x00, 0x03, 0x08, 0x0b}},
221 { 1, 2, USE_LEFT, {0x01, 0x04, 0x09, 0x0c}},
222 { 2, 2, USE_LEFT, {0x02, 0x05, 0x0a, 0x0d}},
223
224 { 3, 2, USE_LEFT, {0x08, 0x0b, 0x00, 0x00}},
225 { 4, 2, USE_LEFT, {0x09, 0x0c, 0x00, 0x00}},
226 { 5, 2, USE_LEFT, {0x0a, 0x0d, 0x00, 0x00}},
227
228 { 6, 2, USE_LEFT, {0x10, 0x13, 0x00, 0x00}}, /* Used by percussive voices */
229 { 7, 2, USE_LEFT, {0x11, 0x14, 0x00, 0x00}}, /* if the percussive mode */
230 { 8, 2, USE_LEFT, {0x12, 0x15, 0x00, 0x00}}, /* is selected */
231
232 { 0, 2, USE_RIGHT, {0x00, 0x03, 0x08, 0x0b}},
233 { 1, 2, USE_RIGHT, {0x01, 0x04, 0x09, 0x0c}},
234 { 2, 2, USE_RIGHT, {0x02, 0x05, 0x0a, 0x0d}},
235
236 { 3, 2, USE_RIGHT, {0x08, 0x0b, 0x00, 0x00}},
237 { 4, 2, USE_RIGHT, {0x09, 0x0c, 0x00, 0x00}},
238 { 5, 2, USE_RIGHT, {0x0a, 0x0d, 0x00, 0x00}},
239
240 { 6, 2, USE_RIGHT, {0x10, 0x13, 0x00, 0x00}},
241 { 7, 2, USE_RIGHT, {0x11, 0x14, 0x00, 0x00}},
242 { 8, 2, USE_RIGHT, {0x12, 0x15, 0x00, 0x00}}
243};
244/*
245 * DMA buffer calls
246 */
diff --git a/sound/oss/os.h b/sound/oss/os.h
deleted file mode 100644
index 16f3a069b85c..000000000000
--- a/sound/oss/os.h
+++ /dev/null
@@ -1,46 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#define ALLOW_SELECT
3#undef NO_INLINE_ASM
4#define SHORT_BANNERS
5#define MANUAL_PNP
6#undef DO_TIMINGS
7
8#include <linux/module.h>
9
10#ifdef __KERNEL__
11#include <linux/string.h>
12#include <linux/fs.h>
13#include <asm/dma.h>
14#include <asm/io.h>
15#include <asm/param.h>
16#include <linux/sched.h>
17#include <linux/slab.h>
18#include <linux/ioport.h>
19#include <asm/page.h>
20#include <linux/vmalloc.h>
21#include <linux/uaccess.h>
22#include <linux/poll.h>
23#include <linux/pci.h>
24#endif
25
26#include <linux/soundcard.h>
27
28#define FALSE 0
29#define TRUE 1
30
31extern int sound_alloc_dma(int chn, char *deviceID);
32extern int sound_open_dma(int chn, char *deviceID);
33extern void sound_free_dma(int chn);
34extern void sound_close_dma(int chn);
35
36extern void reprogram_timer(void);
37
38#define USE_AUTOINIT_DMA
39
40extern void *sound_mem_blocks[1024];
41extern int sound_nblocks;
42
43#undef PSEUDO_DMA_AUTOINIT
44#define ALLOW_BUFFER_MAPPING
45
46extern const struct file_operations oss_sound_fops;
diff --git a/sound/oss/pas2.h b/sound/oss/pas2.h
deleted file mode 100644
index 57f476238309..000000000000
--- a/sound/oss/pas2.h
+++ /dev/null
@@ -1,21 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2
3/* From pas_card.c */
4int pas_set_intr(int mask);
5int pas_remove_intr(int mask);
6unsigned char pas_read(int ioaddr);
7void pas_write(unsigned char data, int ioaddr);
8
9/* From pas_audio.c */
10void pas_pcm_interrupt(unsigned char status, int cause);
11void pas_pcm_init(struct address_info *hw_config);
12
13/* From pas_mixer.c */
14int pas_init_mixer(void);
15
16/* From pas_midi.c */
17void pas_midi_init(void);
18void pas_midi_interrupt(void);
19
20/* From pas2_mixer.c*/
21void mix_write(unsigned char data, int ioaddr);
diff --git a/sound/oss/pas2_card.c b/sound/oss/pas2_card.c
deleted file mode 100644
index 769fca692d2a..000000000000
--- a/sound/oss/pas2_card.c
+++ /dev/null
@@ -1,458 +0,0 @@
1/*
2 * sound/oss/pas2_card.c
3 *
4 * Detection routine for the Pro Audio Spectrum cards.
5 */
6
7#include <linux/init.h>
8#include <linux/interrupt.h>
9#include <linux/module.h>
10#include <linux/spinlock.h>
11#include "sound_config.h"
12
13#include "pas2.h"
14#include "sb.h"
15
16static unsigned char dma_bits[] = {
17 4, 1, 2, 3, 0, 5, 6, 7
18};
19
20static unsigned char irq_bits[] = {
21 0, 0, 1, 2, 3, 4, 5, 6, 0, 1, 7, 8, 9, 0, 10, 11
22};
23
24static unsigned char sb_irq_bits[] = {
25 0x00, 0x00, 0x08, 0x10, 0x00, 0x18, 0x00, 0x20,
26 0x00, 0x08, 0x28, 0x30, 0x38, 0, 0
27};
28
29static unsigned char sb_dma_bits[] = {
30 0x00, 0x40, 0x80, 0xC0, 0, 0, 0, 0
31};
32
33/*
34 * The Address Translation code is used to convert I/O register addresses to
35 * be relative to the given base -register
36 */
37
38int pas_translate_code = 0;
39static int pas_intr_mask;
40static int pas_irq;
41static int pas_sb_base;
42DEFINE_SPINLOCK(pas_lock);
43#ifndef CONFIG_PAS_JOYSTICK
44static bool joystick;
45#else
46static bool joystick = 1;
47#endif
48#ifdef SYMPHONY_PAS
49static bool symphony = 1;
50#else
51static bool symphony;
52#endif
53#ifdef BROKEN_BUS_CLOCK
54static bool broken_bus_clock = 1;
55#else
56static bool broken_bus_clock;
57#endif
58
59static struct address_info cfg;
60static struct address_info cfg2;
61
62char pas_model = 0;
63static char *pas_model_names[] = {
64 "",
65 "Pro AudioSpectrum+",
66 "CDPC",
67 "Pro AudioSpectrum 16",
68 "Pro AudioSpectrum 16D"
69};
70
71/*
72 * pas_read() and pas_write() are equivalents of inb and outb
73 * These routines perform the I/O address translation required
74 * to support other than the default base address
75 */
76
77unsigned char pas_read(int ioaddr)
78{
79 return inb(ioaddr + pas_translate_code);
80}
81
82void pas_write(unsigned char data, int ioaddr)
83{
84 outb((data), ioaddr + pas_translate_code);
85}
86
87/******************* Begin of the Interrupt Handler ********************/
88
89static irqreturn_t pasintr(int irq, void *dev_id)
90{
91 int status;
92
93 status = pas_read(0x0B89);
94 pas_write(status, 0x0B89); /* Clear interrupt */
95
96 if (status & 0x08)
97 {
98 pas_pcm_interrupt(status, 1);
99 status &= ~0x08;
100 }
101 if (status & 0x10)
102 {
103 pas_midi_interrupt();
104 status &= ~0x10;
105 }
106 return IRQ_HANDLED;
107}
108
109int pas_set_intr(int mask)
110{
111 if (!mask)
112 return 0;
113
114 pas_intr_mask |= mask;
115
116 pas_write(pas_intr_mask, 0x0B8B);
117 return 0;
118}
119
120int pas_remove_intr(int mask)
121{
122 if (!mask)
123 return 0;
124
125 pas_intr_mask &= ~mask;
126 pas_write(pas_intr_mask, 0x0B8B);
127
128 return 0;
129}
130
131/******************* End of the Interrupt handler **********************/
132
133/******************* Begin of the Initialization Code ******************/
134
135static int __init config_pas_hw(struct address_info *hw_config)
136{
137 char ok = 1;
138 unsigned int_ptrs; /* scsi/sound interrupt pointers */
139
140 pas_irq = hw_config->irq;
141
142 pas_write(0x00, 0x0B8B);
143 pas_write(0x36, 0x138B);
144 pas_write(0x36, 0x1388);
145 pas_write(0, 0x1388);
146 pas_write(0x74, 0x138B);
147 pas_write(0x74, 0x1389);
148 pas_write(0, 0x1389);
149
150 pas_write(0x80 | 0x40 | 0x20 | 1, 0x0B8A);
151 pas_write(0x80 | 0x20 | 0x10 | 0x08 | 0x01, 0xF8A);
152 pas_write(0x01 | 0x02 | 0x04 | 0x10 /*
153 * |
154 * 0x80
155 */ , 0xB88);
156
157 pas_write(0x80 | (joystick ? 0x40 : 0), 0xF388);
158
159 if (pas_irq < 0 || pas_irq > 15)
160 {
161 printk(KERN_ERR "PAS16: Invalid IRQ %d", pas_irq);
162 hw_config->irq=-1;
163 ok = 0;
164 }
165 else
166 {
167 int_ptrs = pas_read(0xF38A);
168 int_ptrs = (int_ptrs & 0xf0) | irq_bits[pas_irq];
169 pas_write(int_ptrs, 0xF38A);
170 if (!irq_bits[pas_irq])
171 {
172 printk(KERN_ERR "PAS16: Invalid IRQ %d", pas_irq);
173 hw_config->irq=-1;
174 ok = 0;
175 }
176 else
177 {
178 if (request_irq(pas_irq, pasintr, 0, "PAS16",hw_config) < 0) {
179 printk(KERN_ERR "PAS16: Cannot allocate IRQ %d\n",pas_irq);
180 hw_config->irq=-1;
181 ok = 0;
182 }
183 }
184 }
185
186 if (hw_config->dma < 0 || hw_config->dma > 7)
187 {
188 printk(KERN_ERR "PAS16: Invalid DMA selection %d", hw_config->dma);
189 hw_config->dma=-1;
190 ok = 0;
191 }
192 else
193 {
194 pas_write(dma_bits[hw_config->dma], 0xF389);
195 if (!dma_bits[hw_config->dma])
196 {
197 printk(KERN_ERR "PAS16: Invalid DMA selection %d", hw_config->dma);
198 hw_config->dma=-1;
199 ok = 0;
200 }
201 else
202 {
203 if (sound_alloc_dma(hw_config->dma, "PAS16"))
204 {
205 printk(KERN_ERR "pas2_card.c: Can't allocate DMA channel\n");
206 hw_config->dma=-1;
207 ok = 0;
208 }
209 }
210 }
211
212 /*
213 * This fixes the timing problems of the PAS due to the Symphony chipset
214 * as per Media Vision. Only define this if your PAS doesn't work correctly.
215 */
216
217 if(symphony)
218 {
219 outb((0x05), 0xa8);
220 outb((0x60), 0xa9);
221 }
222
223 if(broken_bus_clock)
224 pas_write(0x01 | 0x10 | 0x20 | 0x04, 0x8388);
225 else
226 /*
227 * pas_write(0x01, 0x8388);
228 */
229 pas_write(0x01 | 0x10 | 0x20, 0x8388);
230
231 pas_write(0x18, 0x838A); /* ??? */
232 pas_write(0x20 | 0x01, 0x0B8A); /* Mute off, filter = 17.897 kHz */
233 pas_write(8, 0xBF8A);
234
235 mix_write(0x80 | 5, 0x078B);
236 mix_write(5, 0x078B);
237
238 {
239 struct address_info *sb_config;
240
241 sb_config = &cfg2;
242 if (sb_config->io_base)
243 {
244 unsigned char irq_dma;
245
246 /*
247 * Turn on Sound Blaster compatibility
248 * bit 1 = SB emulation
249 * bit 0 = MPU401 emulation (CDPC only :-( )
250 */
251
252 pas_write(0x02, 0xF788);
253
254 /*
255 * "Emulation address"
256 */
257
258 pas_write((sb_config->io_base >> 4) & 0x0f, 0xF789);
259 pas_sb_base = sb_config->io_base;
260
261 if (!sb_dma_bits[sb_config->dma])
262 printk(KERN_ERR "PAS16 Warning: Invalid SB DMA %d\n\n", sb_config->dma);
263
264 if (!sb_irq_bits[sb_config->irq])
265 printk(KERN_ERR "PAS16 Warning: Invalid SB IRQ %d\n\n", sb_config->irq);
266
267 irq_dma = sb_dma_bits[sb_config->dma] |
268 sb_irq_bits[sb_config->irq];
269
270 pas_write(irq_dma, 0xFB8A);
271 }
272 else
273 pas_write(0x00, 0xF788);
274 }
275
276 if (!ok)
277 printk(KERN_WARNING "PAS16: Driver not enabled\n");
278
279 return ok;
280}
281
282static int __init detect_pas_hw(struct address_info *hw_config)
283{
284 unsigned char board_id, foo;
285
286 /*
287 * WARNING: Setting an option like W:1 or so that disables warm boot reset
288 * of the card will screw up this detect code something fierce. Adding code
289 * to handle this means possibly interfering with other cards on the bus if
290 * you have something on base port 0x388. SO be forewarned.
291 */
292
293 outb((0xBC), 0x9A01); /* Activate first board */
294 outb((hw_config->io_base >> 2), 0x9A01); /* Set base address */
295 pas_translate_code = hw_config->io_base - 0x388;
296 pas_write(1, 0xBF88); /* Select one wait states */
297
298 board_id = pas_read(0x0B8B);
299
300 if (board_id == 0xff)
301 return 0;
302
303 /*
304 * We probably have a PAS-series board, now check for a PAS16-series board
305 * by trying to change the board revision bits. PAS16-series hardware won't
306 * let you do this - the bits are read-only.
307 */
308
309 foo = board_id ^ 0xe0;
310
311 pas_write(foo, 0x0B8B);
312 foo = pas_read(0x0B8B);
313 pas_write(board_id, 0x0B8B);
314
315 if (board_id != foo)
316 return 0;
317
318 pas_model = pas_read(0xFF88);
319
320 return pas_model;
321}
322
323static void __init attach_pas_card(struct address_info *hw_config)
324{
325 pas_irq = hw_config->irq;
326
327 if (detect_pas_hw(hw_config))
328 {
329
330 if ((pas_model = pas_read(0xFF88)))
331 {
332 char temp[100];
333
334 if (pas_model < 0 ||
335 pas_model >= ARRAY_SIZE(pas_model_names)) {
336 printk(KERN_ERR "pas2 unrecognized model.\n");
337 return;
338 }
339 sprintf(temp,
340 "%s rev %d", pas_model_names[(int) pas_model],
341 pas_read(0x2789));
342 conf_printf(temp, hw_config);
343 }
344 if (config_pas_hw(hw_config))
345 {
346 pas_pcm_init(hw_config);
347 pas_midi_init();
348 pas_init_mixer();
349 }
350 }
351}
352
353static inline int __init probe_pas(struct address_info *hw_config)
354{
355 return detect_pas_hw(hw_config);
356}
357
358static void __exit unload_pas(struct address_info *hw_config)
359{
360 extern int pas_audiodev;
361 extern int pas2_mididev;
362
363 if (hw_config->dma>0)
364 sound_free_dma(hw_config->dma);
365 if (hw_config->irq>0)
366 free_irq(hw_config->irq, hw_config);
367
368 if(pas_audiodev!=-1)
369 sound_unload_mixerdev(audio_devs[pas_audiodev]->mixer_dev);
370 if(pas2_mididev!=-1)
371 sound_unload_mididev(pas2_mididev);
372 if(pas_audiodev!=-1)
373 sound_unload_audiodev(pas_audiodev);
374}
375
376static int __initdata io = -1;
377static int __initdata irq = -1;
378static int __initdata dma = -1;
379static int __initdata dma16 = -1; /* Set this for modules that need it */
380
381static int __initdata sb_io = 0;
382static int __initdata sb_irq = -1;
383static int __initdata sb_dma = -1;
384static int __initdata sb_dma16 = -1;
385
386module_param_hw(io, int, ioport, 0);
387module_param_hw(irq, int, irq, 0);
388module_param_hw(dma, int, dma, 0);
389module_param_hw(dma16, int, dma, 0);
390
391module_param_hw(sb_io, int, ioport, 0);
392module_param_hw(sb_irq, int, irq, 0);
393module_param_hw(sb_dma, int, dma, 0);
394module_param_hw(sb_dma16, int, dma, 0);
395
396module_param(joystick, bool, 0);
397module_param(symphony, bool, 0);
398module_param(broken_bus_clock, bool, 0);
399
400MODULE_LICENSE("GPL");
401
402static int __init init_pas2(void)
403{
404 printk(KERN_INFO "Pro Audio Spectrum driver Copyright (C) by Hannu Savolainen 1993-1996\n");
405
406 cfg.io_base = io;
407 cfg.irq = irq;
408 cfg.dma = dma;
409 cfg.dma2 = dma16;
410
411 cfg2.io_base = sb_io;
412 cfg2.irq = sb_irq;
413 cfg2.dma = sb_dma;
414 cfg2.dma2 = sb_dma16;
415
416 if (cfg.io_base == -1 || cfg.dma == -1 || cfg.irq == -1) {
417 printk(KERN_INFO "I/O, IRQ, DMA and type are mandatory\n");
418 return -EINVAL;
419 }
420
421 if (!probe_pas(&cfg))
422 return -ENODEV;
423 attach_pas_card(&cfg);
424
425 return 0;
426}
427
428static void __exit cleanup_pas2(void)
429{
430 unload_pas(&cfg);
431}
432
433module_init(init_pas2);
434module_exit(cleanup_pas2);
435
436#ifndef MODULE
437static int __init setup_pas2(char *str)
438{
439 /* io, irq, dma, dma2, sb_io, sb_irq, sb_dma, sb_dma2 */
440 int ints[9];
441
442 str = get_options(str, ARRAY_SIZE(ints), ints);
443
444 io = ints[1];
445 irq = ints[2];
446 dma = ints[3];
447 dma16 = ints[4];
448
449 sb_io = ints[5];
450 sb_irq = ints[6];
451 sb_dma = ints[7];
452 sb_dma16 = ints[8];
453
454 return 1;
455}
456
457__setup("pas2=", setup_pas2);
458#endif
diff --git a/sound/oss/pas2_midi.c b/sound/oss/pas2_midi.c
deleted file mode 100644
index 1122d10a20c3..000000000000
--- a/sound/oss/pas2_midi.c
+++ /dev/null
@@ -1,262 +0,0 @@
1/*
2 * sound/oss/pas2_midi.c
3 *
4 * The low level driver for the PAS Midi Interface.
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 * Bartlomiej Zolnierkiewicz : Added __init to pas_init_mixer()
14 */
15
16#include <linux/init.h>
17#include <linux/spinlock.h>
18#include "sound_config.h"
19
20#include "pas2.h"
21
22extern spinlock_t pas_lock;
23
24static int midi_busy, input_opened;
25static int my_dev;
26
27int pas2_mididev=-1;
28
29static unsigned char tmp_queue[256];
30static volatile int qlen;
31static volatile unsigned char qhead, qtail;
32
33static void (*midi_input_intr) (int dev, unsigned char data);
34
35static int pas_midi_open(int dev, int mode,
36 void (*input) (int dev, unsigned char data),
37 void (*output) (int dev)
38)
39{
40 int err;
41 unsigned long flags;
42 unsigned char ctrl;
43
44
45 if (midi_busy)
46 return -EBUSY;
47
48 /*
49 * Reset input and output FIFO pointers
50 */
51 pas_write(0x20 | 0x40,
52 0x178b);
53
54 spin_lock_irqsave(&pas_lock, flags);
55
56 if ((err = pas_set_intr(0x10)) < 0)
57 {
58 spin_unlock_irqrestore(&pas_lock, flags);
59 return err;
60 }
61 /*
62 * Enable input available and output FIFO empty interrupts
63 */
64
65 ctrl = 0;
66 input_opened = 0;
67 midi_input_intr = input;
68
69 if (mode == OPEN_READ || mode == OPEN_READWRITE)
70 {
71 ctrl |= 0x04; /* Enable input */
72 input_opened = 1;
73 }
74 if (mode == OPEN_WRITE || mode == OPEN_READWRITE)
75 {
76 ctrl |= 0x08 | 0x10; /* Enable output */
77 }
78 pas_write(ctrl, 0x178b);
79
80 /*
81 * Acknowledge any pending interrupts
82 */
83
84 pas_write(0xff, 0x1B88);
85
86 spin_unlock_irqrestore(&pas_lock, flags);
87
88 midi_busy = 1;
89 qlen = qhead = qtail = 0;
90 return 0;
91}
92
93static void pas_midi_close(int dev)
94{
95
96 /*
97 * Reset FIFO pointers, disable intrs
98 */
99 pas_write(0x20 | 0x40, 0x178b);
100
101 pas_remove_intr(0x10);
102 midi_busy = 0;
103}
104
105static int dump_to_midi(unsigned char midi_byte)
106{
107 int fifo_space, x;
108
109 fifo_space = ((x = pas_read(0x1B89)) >> 4) & 0x0f;
110
111 /*
112 * The MIDI FIFO space register and it's documentation is nonunderstandable.
113 * There seem to be no way to differentiate between buffer full and buffer
114 * empty situations. For this reason we don't never write the buffer
115 * completely full. In this way we can assume that 0 (or is it 15)
116 * means that the buffer is empty.
117 */
118
119 if (fifo_space < 2 && fifo_space != 0) /* Full (almost) */
120 return 0; /* Ask upper layers to retry after some time */
121
122 pas_write(midi_byte, 0x178A);
123
124 return 1;
125}
126
127static int pas_midi_out(int dev, unsigned char midi_byte)
128{
129
130 unsigned long flags;
131
132 /*
133 * Drain the local queue first
134 */
135
136 spin_lock_irqsave(&pas_lock, flags);
137
138 while (qlen && dump_to_midi(tmp_queue[qhead]))
139 {
140 qlen--;
141 qhead++;
142 }
143
144 spin_unlock_irqrestore(&pas_lock, flags);
145
146 /*
147 * Output the byte if the local queue is empty.
148 */
149
150 if (!qlen)
151 if (dump_to_midi(midi_byte))
152 return 1;
153
154 /*
155 * Put to the local queue
156 */
157
158 if (qlen >= 256)
159 return 0; /* Local queue full */
160
161 spin_lock_irqsave(&pas_lock, flags);
162
163 tmp_queue[qtail] = midi_byte;
164 qlen++;
165 qtail++;
166
167 spin_unlock_irqrestore(&pas_lock, flags);
168
169 return 1;
170}
171
172static int pas_midi_start_read(int dev)
173{
174 return 0;
175}
176
177static int pas_midi_end_read(int dev)
178{
179 return 0;
180}
181
182static void pas_midi_kick(int dev)
183{
184}
185
186static int pas_buffer_status(int dev)
187{
188 return qlen;
189}
190
191#define MIDI_SYNTH_NAME "Pro Audio Spectrum Midi"
192#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
193#include "midi_synth.h"
194
195static struct midi_operations pas_midi_operations =
196{
197 .owner = THIS_MODULE,
198 .info = {"Pro Audio Spectrum", 0, 0, SNDCARD_PAS},
199 .converter = &std_midi_synth,
200 .in_info = {0},
201 .open = pas_midi_open,
202 .close = pas_midi_close,
203 .outputc = pas_midi_out,
204 .start_read = pas_midi_start_read,
205 .end_read = pas_midi_end_read,
206 .kick = pas_midi_kick,
207 .buffer_status = pas_buffer_status,
208};
209
210void __init pas_midi_init(void)
211{
212 int dev = sound_alloc_mididev();
213
214 if (dev == -1)
215 {
216 printk(KERN_WARNING "pas_midi_init: Too many midi devices detected\n");
217 return;
218 }
219 std_midi_synth.midi_dev = my_dev = dev;
220 midi_devs[dev] = &pas_midi_operations;
221 pas2_mididev = dev;
222 sequencer_init();
223}
224
225void pas_midi_interrupt(void)
226{
227 unsigned char stat;
228 int i, incount;
229
230 stat = pas_read(0x1B88);
231
232 if (stat & 0x04) /* Input data available */
233 {
234 incount = pas_read(0x1B89) & 0x0f; /* Input FIFO size */
235 if (!incount)
236 incount = 16;
237
238 for (i = 0; i < incount; i++)
239 if (input_opened)
240 {
241 midi_input_intr(my_dev, pas_read(0x178A));
242 } else
243 pas_read(0x178A); /* Flush */
244 }
245 if (stat & (0x08 | 0x10))
246 {
247 spin_lock(&pas_lock);/* called in irq context */
248
249 while (qlen && dump_to_midi(tmp_queue[qhead]))
250 {
251 qlen--;
252 qhead++;
253 }
254
255 spin_unlock(&pas_lock);
256 }
257 if (stat & 0x40)
258 {
259 printk(KERN_WARNING "MIDI output overrun %x,%x\n", pas_read(0x1B89), stat);
260 }
261 pas_write(stat, 0x1B88); /* Acknowledge interrupts */
262}
diff --git a/sound/oss/pas2_mixer.c b/sound/oss/pas2_mixer.c
deleted file mode 100644
index 50b5bd501247..000000000000
--- a/sound/oss/pas2_mixer.c
+++ /dev/null
@@ -1,327 +0,0 @@
1
2/*
3 * sound/oss/pas2_mixer.c
4 *
5 * Mixer routines for the Pro Audio Spectrum cards.
6 */
7
8/*
9 * Copyright (C) by Hannu Savolainen 1993-1997
10 *
11 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
12 * Version 2 (June 1991). See the "COPYING" file distributed with this software
13 * for more info.
14 */
15/*
16 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
17 * Bartlomiej Zolnierkiewicz : added __init to pas_init_mixer()
18 */
19#include <linux/init.h>
20#include "sound_config.h"
21
22#include "pas2.h"
23
24extern int pas_translate_code;
25extern char pas_model;
26extern int *pas_osp;
27extern int pas_audiodev;
28
29static int rec_devices = (SOUND_MASK_MIC); /* Default recording source */
30static int mode_control;
31
32#define POSSIBLE_RECORDING_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
33 SOUND_MASK_CD | SOUND_MASK_ALTPCM)
34
35#define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
36 SOUND_MASK_CD | SOUND_MASK_ALTPCM | SOUND_MASK_IMIX | \
37 SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_RECLEV)
38
39static int *levels;
40
41static int default_levels[32] =
42{
43 0x3232, /* Master Volume */
44 0x3232, /* Bass */
45 0x3232, /* Treble */
46 0x5050, /* FM */
47 0x4b4b, /* PCM */
48 0x3232, /* PC Speaker */
49 0x4b4b, /* Ext Line */
50 0x4b4b, /* Mic */
51 0x4b4b, /* CD */
52 0x6464, /* Recording monitor */
53 0x4b4b, /* SB PCM */
54 0x6464 /* Recording level */
55};
56
57void
58mix_write(unsigned char data, int ioaddr)
59{
60 /*
61 * The Revision D cards have a problem with their MVA508 interface. The
62 * kludge-o-rama fix is to make a 16-bit quantity with identical LSB and
63 * MSBs out of the output byte and to do a 16-bit out to the mixer port -
64 * 1. We need to do this because it isn't timing problem but chip access
65 * sequence problem.
66 */
67
68 if (pas_model == 4)
69 {
70 outw(data | (data << 8), (ioaddr + pas_translate_code) - 1);
71 outb((0x80), 0);
72 } else
73 pas_write(data, ioaddr);
74}
75
76static int
77mixer_output(int right_vol, int left_vol, int div, int bits,
78 int mixer) /* Input or output mixer */
79{
80 int left = left_vol * div / 100;
81 int right = right_vol * div / 100;
82
83
84 if (bits & 0x10)
85 {
86 left |= mixer;
87 right |= mixer;
88 }
89 if (bits == 0x03 || bits == 0x04)
90 {
91 mix_write(0x80 | bits, 0x078B);
92 mix_write(left, 0x078B);
93 right_vol = left_vol;
94 } else
95 {
96 mix_write(0x80 | 0x20 | bits, 0x078B);
97 mix_write(left, 0x078B);
98 mix_write(0x80 | 0x40 | bits, 0x078B);
99 mix_write(right, 0x078B);
100 }
101
102 return (left_vol | (right_vol << 8));
103}
104
105static void
106set_mode(int new_mode)
107{
108 mix_write(0x80 | 0x05, 0x078B);
109 mix_write(new_mode, 0x078B);
110
111 mode_control = new_mode;
112}
113
114static int
115pas_mixer_set(int whichDev, unsigned int level)
116{
117 int left, right, devmask, changed, i, mixer = 0;
118
119 left = level & 0x7f;
120 right = (level & 0x7f00) >> 8;
121
122 if (whichDev < SOUND_MIXER_NRDEVICES) {
123 if ((1 << whichDev) & rec_devices)
124 mixer = 0x20;
125 else
126 mixer = 0x00;
127 }
128
129 switch (whichDev)
130 {
131 case SOUND_MIXER_VOLUME: /* Master volume (0-63) */
132 levels[whichDev] = mixer_output(right, left, 63, 0x01, 0);
133 break;
134
135 /*
136 * Note! Bass and Treble are mono devices. Will use just the left
137 * channel.
138 */
139 case SOUND_MIXER_BASS: /* Bass (0-12) */
140 levels[whichDev] = mixer_output(right, left, 12, 0x03, 0);
141 break;
142 case SOUND_MIXER_TREBLE: /* Treble (0-12) */
143 levels[whichDev] = mixer_output(right, left, 12, 0x04, 0);
144 break;
145
146 case SOUND_MIXER_SYNTH: /* Internal synthesizer (0-31) */
147 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x00, mixer);
148 break;
149 case SOUND_MIXER_PCM: /* PAS PCM (0-31) */
150 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x05, mixer);
151 break;
152 case SOUND_MIXER_ALTPCM: /* SB PCM (0-31) */
153 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x07, mixer);
154 break;
155 case SOUND_MIXER_SPEAKER: /* PC speaker (0-31) */
156 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x06, mixer);
157 break;
158 case SOUND_MIXER_LINE: /* External line (0-31) */
159 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x02, mixer);
160 break;
161 case SOUND_MIXER_CD: /* CD (0-31) */
162 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x03, mixer);
163 break;
164 case SOUND_MIXER_MIC: /* External microphone (0-31) */
165 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x04, mixer);
166 break;
167 case SOUND_MIXER_IMIX: /* Recording monitor (0-31) (Output mixer only) */
168 levels[whichDev] = mixer_output(right, left, 31, 0x10 | 0x01,
169 0x00);
170 break;
171 case SOUND_MIXER_RECLEV: /* Recording level (0-15) */
172 levels[whichDev] = mixer_output(right, left, 15, 0x02, 0);
173 break;
174
175
176 case SOUND_MIXER_RECSRC:
177 devmask = level & POSSIBLE_RECORDING_DEVICES;
178
179 changed = devmask ^ rec_devices;
180 rec_devices = devmask;
181
182 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
183 if (changed & (1 << i))
184 {
185 pas_mixer_set(i, levels[i]);
186 }
187 return rec_devices;
188 break;
189
190 default:
191 return -EINVAL;
192 }
193
194 return (levels[whichDev]);
195}
196
197/*****/
198
199static void
200pas_mixer_reset(void)
201{
202 int foo;
203
204 for (foo = 0; foo < SOUND_MIXER_NRDEVICES; foo++)
205 pas_mixer_set(foo, levels[foo]);
206
207 set_mode(0x04 | 0x01);
208}
209
210static int pas_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
211{
212 int level,v ;
213 int __user *p = (int __user *)arg;
214
215 if (cmd == SOUND_MIXER_PRIVATE1) { /* Set loudness bit */
216 if (get_user(level, p))
217 return -EFAULT;
218 if (level == -1) /* Return current settings */
219 level = (mode_control & 0x04);
220 else {
221 mode_control &= ~0x04;
222 if (level)
223 mode_control |= 0x04;
224 set_mode(mode_control);
225 }
226 level = !!level;
227 return put_user(level, p);
228 }
229 if (cmd == SOUND_MIXER_PRIVATE2) { /* Set enhance bit */
230 if (get_user(level, p))
231 return -EFAULT;
232 if (level == -1) { /* Return current settings */
233 if (!(mode_control & 0x03))
234 level = 0;
235 else
236 level = ((mode_control & 0x03) + 1) * 20;
237 } else {
238 int i = 0;
239
240 level &= 0x7f;
241 if (level)
242 i = (level / 20) - 1;
243 mode_control &= ~0x03;
244 mode_control |= i & 0x03;
245 set_mode(mode_control);
246 if (i)
247 i = (i + 1) * 20;
248 level = i;
249 }
250 return put_user(level, p);
251 }
252 if (cmd == SOUND_MIXER_PRIVATE3) { /* Set mute bit */
253 if (get_user(level, p))
254 return -EFAULT;
255 if (level == -1) /* Return current settings */
256 level = !(pas_read(0x0B8A) & 0x20);
257 else {
258 if (level)
259 pas_write(pas_read(0x0B8A) & (~0x20), 0x0B8A);
260 else
261 pas_write(pas_read(0x0B8A) | 0x20, 0x0B8A);
262
263 level = !(pas_read(0x0B8A) & 0x20);
264 }
265 return put_user(level, p);
266 }
267 if (((cmd >> 8) & 0xff) == 'M') {
268 if (get_user(v, p))
269 return -EFAULT;
270 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
271 v = pas_mixer_set(cmd & 0xff, v);
272 } else {
273 switch (cmd & 0xff) {
274 case SOUND_MIXER_RECSRC:
275 v = rec_devices;
276 break;
277
278 case SOUND_MIXER_STEREODEVS:
279 v = SUPPORTED_MIXER_DEVICES & ~(SOUND_MASK_BASS | SOUND_MASK_TREBLE);
280 break;
281
282 case SOUND_MIXER_DEVMASK:
283 v = SUPPORTED_MIXER_DEVICES;
284 break;
285
286 case SOUND_MIXER_RECMASK:
287 v = POSSIBLE_RECORDING_DEVICES & SUPPORTED_MIXER_DEVICES;
288 break;
289
290 case SOUND_MIXER_CAPS:
291 v = 0; /* No special capabilities */
292 break;
293
294 default:
295 v = levels[cmd & 0xff];
296 break;
297 }
298 }
299 return put_user(v, p);
300 }
301 return -EINVAL;
302}
303
304static struct mixer_operations pas_mixer_operations =
305{
306 .owner = THIS_MODULE,
307 .id = "PAS16",
308 .name = "Pro Audio Spectrum 16",
309 .ioctl = pas_mixer_ioctl
310};
311
312int __init
313pas_init_mixer(void)
314{
315 int d;
316
317 levels = load_mixer_volumes("PAS16_1", default_levels, 1);
318
319 pas_mixer_reset();
320
321 if ((d = sound_alloc_mixerdev()) != -1)
322 {
323 audio_devs[pas_audiodev]->mixer_dev = d;
324 mixer_devs[d] = &pas_mixer_operations;
325 }
326 return 1;
327}
diff --git a/sound/oss/pas2_pcm.c b/sound/oss/pas2_pcm.c
deleted file mode 100644
index 474803b52f7d..000000000000
--- a/sound/oss/pas2_pcm.c
+++ /dev/null
@@ -1,419 +0,0 @@
1/*
2 * pas2_pcm.c Audio routines for PAS16
3 *
4 *
5 * Copyright (C) by Hannu Savolainen 1993-1997
6 *
7 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
8 * Version 2 (June 1991). See the "COPYING" file distributed with this software
9 * for more info.
10 *
11 *
12 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
13 * Alan Cox : Swatted a double allocation of device bug. Made a few
14 * more things module options.
15 * Bartlomiej Zolnierkiewicz : Added __init to pas_pcm_init()
16 */
17
18#include <linux/init.h>
19#include <linux/spinlock.h>
20#include <linux/timex.h>
21#include "sound_config.h"
22
23#include "pas2.h"
24
25#define PAS_PCM_INTRBITS (0x08)
26/*
27 * Sample buffer timer interrupt enable
28 */
29
30#define PCM_NON 0
31#define PCM_DAC 1
32#define PCM_ADC 2
33
34static unsigned long pcm_speed; /* sampling rate */
35static unsigned char pcm_channels = 1; /* channels (1 or 2) */
36static unsigned char pcm_bits = 8; /* bits/sample (8 or 16) */
37static unsigned char pcm_filter; /* filter FLAG */
38static unsigned char pcm_mode = PCM_NON;
39static unsigned long pcm_count;
40static unsigned short pcm_bitsok = 8; /* mask of OK bits */
41static int pcm_busy;
42int pas_audiodev = -1;
43static int open_mode;
44
45extern spinlock_t pas_lock;
46
47static int pcm_set_speed(int arg)
48{
49 int foo, tmp;
50 unsigned long flags;
51
52 if (arg == 0)
53 return pcm_speed;
54
55 if (arg > 44100)
56 arg = 44100;
57 if (arg < 5000)
58 arg = 5000;
59
60 if (pcm_channels & 2)
61 {
62 foo = ((PIT_TICK_RATE / 2) + (arg / 2)) / arg;
63 arg = ((PIT_TICK_RATE / 2) + (foo / 2)) / foo;
64 }
65 else
66 {
67 foo = (PIT_TICK_RATE + (arg / 2)) / arg;
68 arg = (PIT_TICK_RATE + (foo / 2)) / foo;
69 }
70
71 pcm_speed = arg;
72
73 tmp = pas_read(0x0B8A);
74
75 /*
76 * Set anti-aliasing filters according to sample rate. You really *NEED*
77 * to enable this feature for all normal recording unless you want to
78 * experiment with aliasing effects.
79 * These filters apply to the selected "recording" source.
80 * I (pfw) don't know the encoding of these 5 bits. The values shown
81 * come from the SDK found on ftp.uwp.edu:/pub/msdos/proaudio/.
82 *
83 * I cleared bit 5 of these values, since that bit controls the master
84 * mute flag. (Olav Wölfelschneider)
85 *
86 */
87#if !defined NO_AUTO_FILTER_SET
88 tmp &= 0xe0;
89 if (pcm_speed >= 2 * 17897)
90 tmp |= 0x01;
91 else if (pcm_speed >= 2 * 15909)
92 tmp |= 0x02;
93 else if (pcm_speed >= 2 * 11931)
94 tmp |= 0x09;
95 else if (pcm_speed >= 2 * 8948)
96 tmp |= 0x11;
97 else if (pcm_speed >= 2 * 5965)
98 tmp |= 0x19;
99 else if (pcm_speed >= 2 * 2982)
100 tmp |= 0x04;
101 pcm_filter = tmp;
102#endif
103
104 spin_lock_irqsave(&pas_lock, flags);
105
106 pas_write(tmp & ~(0x40 | 0x80), 0x0B8A);
107 pas_write(0x00 | 0x30 | 0x04, 0x138B);
108 pas_write(foo & 0xff, 0x1388);
109 pas_write((foo >> 8) & 0xff, 0x1388);
110 pas_write(tmp, 0x0B8A);
111
112 spin_unlock_irqrestore(&pas_lock, flags);
113
114 return pcm_speed;
115}
116
117static int pcm_set_channels(int arg)
118{
119
120 if ((arg != 1) && (arg != 2))
121 return pcm_channels;
122
123 if (arg != pcm_channels)
124 {
125 pas_write(pas_read(0xF8A) ^ 0x20, 0xF8A);
126
127 pcm_channels = arg;
128 pcm_set_speed(pcm_speed); /* The speed must be reinitialized */
129 }
130 return pcm_channels;
131}
132
133static int pcm_set_bits(int arg)
134{
135 if (arg == 0)
136 return pcm_bits;
137
138 if ((arg & pcm_bitsok) != arg)
139 return pcm_bits;
140
141 if (arg != pcm_bits)
142 {
143 pas_write(pas_read(0x8389) ^ 0x04, 0x8389);
144
145 pcm_bits = arg;
146 }
147 return pcm_bits;
148}
149
150static int pas_audio_ioctl(int dev, unsigned int cmd, void __user *arg)
151{
152 int val, ret;
153 int __user *p = arg;
154
155 switch (cmd)
156 {
157 case SOUND_PCM_WRITE_RATE:
158 if (get_user(val, p))
159 return -EFAULT;
160 ret = pcm_set_speed(val);
161 break;
162
163 case SOUND_PCM_READ_RATE:
164 ret = pcm_speed;
165 break;
166
167 case SNDCTL_DSP_STEREO:
168 if (get_user(val, p))
169 return -EFAULT;
170 ret = pcm_set_channels(val + 1) - 1;
171 break;
172
173 case SOUND_PCM_WRITE_CHANNELS:
174 if (get_user(val, p))
175 return -EFAULT;
176 ret = pcm_set_channels(val);
177 break;
178
179 case SOUND_PCM_READ_CHANNELS:
180 ret = pcm_channels;
181 break;
182
183 case SNDCTL_DSP_SETFMT:
184 if (get_user(val, p))
185 return -EFAULT;
186 ret = pcm_set_bits(val);
187 break;
188
189 case SOUND_PCM_READ_BITS:
190 ret = pcm_bits;
191 break;
192
193 default:
194 return -EINVAL;
195 }
196 return put_user(ret, p);
197}
198
199static void pas_audio_reset(int dev)
200{
201 pas_write(pas_read(0xF8A) & ~0x40, 0xF8A); /* Disable PCM */
202}
203
204static int pas_audio_open(int dev, int mode)
205{
206 int err;
207 unsigned long flags;
208
209 spin_lock_irqsave(&pas_lock, flags);
210 if (pcm_busy)
211 {
212 spin_unlock_irqrestore(&pas_lock, flags);
213 return -EBUSY;
214 }
215 pcm_busy = 1;
216 spin_unlock_irqrestore(&pas_lock, flags);
217
218 if ((err = pas_set_intr(PAS_PCM_INTRBITS)) < 0)
219 return err;
220
221
222 pcm_count = 0;
223 open_mode = mode;
224
225 return 0;
226}
227
228static void pas_audio_close(int dev)
229{
230 unsigned long flags;
231
232 spin_lock_irqsave(&pas_lock, flags);
233
234 pas_audio_reset(dev);
235 pas_remove_intr(PAS_PCM_INTRBITS);
236 pcm_mode = PCM_NON;
237
238 pcm_busy = 0;
239 spin_unlock_irqrestore(&pas_lock, flags);
240}
241
242static void pas_audio_output_block(int dev, unsigned long buf, int count,
243 int intrflag)
244{
245 unsigned long flags, cnt;
246
247 cnt = count;
248 if (audio_devs[dev]->dmap_out->dma > 3)
249 cnt >>= 1;
250
251 if (audio_devs[dev]->flags & DMA_AUTOMODE &&
252 intrflag &&
253 cnt == pcm_count)
254 return;
255
256 spin_lock_irqsave(&pas_lock, flags);
257
258 pas_write(pas_read(0xF8A) & ~0x40,
259 0xF8A);
260
261 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
262
263 if (audio_devs[dev]->dmap_out->dma > 3)
264 count >>= 1;
265
266 if (count != pcm_count)
267 {
268 pas_write(pas_read(0x0B8A) & ~0x80, 0x0B8A);
269 pas_write(0x40 | 0x30 | 0x04, 0x138B);
270 pas_write(count & 0xff, 0x1389);
271 pas_write((count >> 8) & 0xff, 0x1389);
272 pas_write(pas_read(0x0B8A) | 0x80, 0x0B8A);
273
274 pcm_count = count;
275 }
276 pas_write(pas_read(0x0B8A) | 0x80 | 0x40, 0x0B8A);
277#ifdef NO_TRIGGER
278 pas_write(pas_read(0xF8A) | 0x40 | 0x10, 0xF8A);
279#endif
280
281 pcm_mode = PCM_DAC;
282
283 spin_unlock_irqrestore(&pas_lock, flags);
284}
285
286static void pas_audio_start_input(int dev, unsigned long buf, int count,
287 int intrflag)
288{
289 unsigned long flags;
290 int cnt;
291
292 cnt = count;
293 if (audio_devs[dev]->dmap_out->dma > 3)
294 cnt >>= 1;
295
296 if (audio_devs[pas_audiodev]->flags & DMA_AUTOMODE &&
297 intrflag &&
298 cnt == pcm_count)
299 return;
300
301 spin_lock_irqsave(&pas_lock, flags);
302
303 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
304
305 if (audio_devs[dev]->dmap_out->dma > 3)
306 count >>= 1;
307
308 if (count != pcm_count)
309 {
310 pas_write(pas_read(0x0B8A) & ~0x80, 0x0B8A);
311 pas_write(0x40 | 0x30 | 0x04, 0x138B);
312 pas_write(count & 0xff, 0x1389);
313 pas_write((count >> 8) & 0xff, 0x1389);
314 pas_write(pas_read(0x0B8A) | 0x80, 0x0B8A);
315
316 pcm_count = count;
317 }
318 pas_write(pas_read(0x0B8A) | 0x80 | 0x40, 0x0B8A);
319#ifdef NO_TRIGGER
320 pas_write((pas_read(0xF8A) | 0x40) & ~0x10, 0xF8A);
321#endif
322
323 pcm_mode = PCM_ADC;
324
325 spin_unlock_irqrestore(&pas_lock, flags);
326}
327
328#ifndef NO_TRIGGER
329static void pas_audio_trigger(int dev, int state)
330{
331 unsigned long flags;
332
333 spin_lock_irqsave(&pas_lock, flags);
334 state &= open_mode;
335
336 if (state & PCM_ENABLE_OUTPUT)
337 pas_write(pas_read(0xF8A) | 0x40 | 0x10, 0xF8A);
338 else if (state & PCM_ENABLE_INPUT)
339 pas_write((pas_read(0xF8A) | 0x40) & ~0x10, 0xF8A);
340 else
341 pas_write(pas_read(0xF8A) & ~0x40, 0xF8A);
342
343 spin_unlock_irqrestore(&pas_lock, flags);
344}
345#endif
346
347static int pas_audio_prepare_for_input(int dev, int bsize, int bcount)
348{
349 pas_audio_reset(dev);
350 return 0;
351}
352
353static int pas_audio_prepare_for_output(int dev, int bsize, int bcount)
354{
355 pas_audio_reset(dev);
356 return 0;
357}
358
359static struct audio_driver pas_audio_driver =
360{
361 .owner = THIS_MODULE,
362 .open = pas_audio_open,
363 .close = pas_audio_close,
364 .output_block = pas_audio_output_block,
365 .start_input = pas_audio_start_input,
366 .ioctl = pas_audio_ioctl,
367 .prepare_for_input = pas_audio_prepare_for_input,
368 .prepare_for_output = pas_audio_prepare_for_output,
369 .halt_io = pas_audio_reset,
370 .trigger = pas_audio_trigger
371};
372
373void __init pas_pcm_init(struct address_info *hw_config)
374{
375 pcm_bitsok = 8;
376 if (pas_read(0xEF8B) & 0x08)
377 pcm_bitsok |= 16;
378
379 pcm_set_speed(DSP_DEFAULT_SPEED);
380
381 if ((pas_audiodev = sound_install_audiodrv(AUDIO_DRIVER_VERSION,
382 "Pro Audio Spectrum",
383 &pas_audio_driver,
384 sizeof(struct audio_driver),
385 DMA_AUTOMODE,
386 AFMT_U8 | AFMT_S16_LE,
387 NULL,
388 hw_config->dma,
389 hw_config->dma)) < 0)
390 printk(KERN_WARNING "PAS16: Too many PCM devices available\n");
391}
392
393void pas_pcm_interrupt(unsigned char status, int cause)
394{
395 if (cause == 1)
396 {
397 /*
398 * Halt the PCM first. Otherwise we don't have time to start a new
399 * block before the PCM chip proceeds to the next sample
400 */
401
402 if (!(audio_devs[pas_audiodev]->flags & DMA_AUTOMODE))
403 pas_write(pas_read(0xF8A) & ~0x40, 0xF8A);
404
405 switch (pcm_mode)
406 {
407 case PCM_DAC:
408 DMAbuf_outputintr(pas_audiodev, 1);
409 break;
410
411 case PCM_ADC:
412 DMAbuf_inputintr(pas_audiodev);
413 break;
414
415 default:
416 printk(KERN_WARNING "PAS: Unexpected PCM interrupt\n");
417 }
418 }
419}
diff --git a/sound/oss/pss.c b/sound/oss/pss.c
deleted file mode 100644
index 33c3a442e162..000000000000
--- a/sound/oss/pss.c
+++ /dev/null
@@ -1,1270 +0,0 @@
1/*
2 * sound/oss/pss.c
3 *
4 * The low level driver for the Personal Sound System (ECHO ESC614).
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Thomas Sailer ioctl code reworked (vmalloc/vfree removed)
15 * Alan Cox modularisation, clean up.
16 *
17 * 98-02-21: Vladimir Michl <vladimir.michl@upol.cz>
18 * Added mixer device for Beethoven ADSP-16 (master volume,
19 * bass, treble, synth), only for speakers.
20 * Fixed bug in pss_write (exchange parameters)
21 * Fixed config port of SB
22 * Requested two regions for PSS (PSS mixer, PSS config)
23 * Modified pss_download_boot
24 * To probe_pss_mss added test for initialize AD1848
25 * 98-05-28: Vladimir Michl <vladimir.michl@upol.cz>
26 * Fixed computation of mixer volumes
27 * 04-05-1999: Anthony Barbachan <barbcode@xmen.cis.fordham.edu>
28 * Added code that allows the user to enable his cdrom and/or
29 * joystick through the module parameters pss_cdrom_port and
30 * pss_enable_joystick. pss_cdrom_port takes a port address as its
31 * argument. pss_enable_joystick takes either a 0 or a non-0 as its
32 * argument.
33 * 04-06-1999: Anthony Barbachan <barbcode@xmen.cis.fordham.edu>
34 * Separated some code into new functions for easier reuse.
35 * Cleaned up and streamlined new code. Added code to allow a user
36 * to only use this driver for enabling non-sound components
37 * through the new module parameter pss_no_sound (flag). Added
38 * code that would allow a user to decide whether the driver should
39 * reset the configured hardware settings for the PSS board through
40 * the module parameter pss_keep_settings (flag). This flag will
41 * allow a user to free up resources in use by this card if needbe,
42 * furthermore it allows him to use this driver to just enable the
43 * emulations and then be unloaded as it is no longer needed. Both
44 * new settings are only available to this driver if compiled as a
45 * module. The default settings of all new parameters are set to
46 * load the driver as it did in previous versions.
47 * 04-07-1999: Anthony Barbachan <barbcode@xmen.cis.fordham.edu>
48 * Added module parameter pss_firmware to allow the user to tell
49 * the driver where the firmware file is located. The default
50 * setting is the previous hardcoded setting "/etc/sound/pss_synth".
51 * 00-03-03: Christoph Hellwig <chhellwig@infradead.org>
52 * Adapted to module_init/module_exit
53 * 11-10-2000: Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
54 * Added __init to probe_pss(), attach_pss() and probe_pss_mpu()
55 * 02-Jan-2001: Chris Rankin
56 * Specify that this module owns the coprocessor
57 */
58
59
60#include <linux/init.h>
61#include <linux/module.h>
62#include <linux/spinlock.h>
63
64#include "sound_config.h"
65#include "sound_firmware.h"
66
67#include "ad1848.h"
68#include "mpu401.h"
69
70/*
71 * PSS registers.
72 */
73#define REG(x) (devc->base+x)
74#define PSS_DATA 0
75#define PSS_STATUS 2
76#define PSS_CONTROL 2
77#define PSS_ID 4
78#define PSS_IRQACK 4
79#define PSS_PIO 0x1a
80
81/*
82 * Config registers
83 */
84#define CONF_PSS 0x10
85#define CONF_WSS 0x12
86#define CONF_SB 0x14
87#define CONF_CDROM 0x16
88#define CONF_MIDI 0x18
89
90/*
91 * Status bits.
92 */
93#define PSS_FLAG3 0x0800
94#define PSS_FLAG2 0x0400
95#define PSS_FLAG1 0x1000
96#define PSS_FLAG0 0x0800
97#define PSS_WRITE_EMPTY 0x8000
98#define PSS_READ_FULL 0x4000
99
100/*
101 * WSS registers
102 */
103#define WSS_INDEX 4
104#define WSS_DATA 5
105
106/*
107 * WSS status bits
108 */
109#define WSS_INITIALIZING 0x80
110#define WSS_AUTOCALIBRATION 0x20
111
112#define NO_WSS_MIXER -1
113
114#include "coproc.h"
115
116#include "pss_boot.h"
117
118/* If compiled into kernel, it enable or disable pss mixer */
119#ifdef CONFIG_PSS_MIXER
120static bool pss_mixer = 1;
121#else
122static bool pss_mixer;
123#endif
124
125
126struct pss_mixerdata {
127 unsigned int volume_l;
128 unsigned int volume_r;
129 unsigned int bass;
130 unsigned int treble;
131 unsigned int synth;
132};
133
134struct pss_confdata {
135 int base;
136 int irq;
137 int dma;
138 int *osp;
139 struct pss_mixerdata mixer;
140 int ad_mixer_dev;
141};
142
143static struct pss_confdata pss_data;
144static struct pss_confdata *devc = &pss_data;
145static DEFINE_SPINLOCK(lock);
146
147static int pss_initialized;
148static int nonstandard_microcode;
149static int pss_cdrom_port = -1; /* Parameter for the PSS cdrom port */
150static bool pss_enable_joystick; /* Parameter for enabling the joystick */
151static coproc_operations pss_coproc_operations;
152
153static void pss_write(struct pss_confdata *devc, int data)
154{
155 unsigned long i, limit;
156
157 limit = jiffies + HZ/10; /* The timeout is 0.1 seconds */
158 /*
159 * Note! the i<5000000 is an emergency exit. The dsp_command() is sometimes
160 * called while interrupts are disabled. This means that the timer is
161 * disabled also. However the timeout situation is a abnormal condition.
162 * Normally the DSP should be ready to accept commands after just couple of
163 * loops.
164 */
165
166 for (i = 0; i < 5000000 && time_before(jiffies, limit); i++)
167 {
168 if (inw(REG(PSS_STATUS)) & PSS_WRITE_EMPTY)
169 {
170 outw(data, REG(PSS_DATA));
171 return;
172 }
173 }
174 printk(KERN_WARNING "PSS: DSP Command (%04x) Timeout.\n", data);
175}
176
177static int __init probe_pss(struct address_info *hw_config)
178{
179 unsigned short id;
180 int irq, dma;
181
182 devc->base = hw_config->io_base;
183 irq = devc->irq = hw_config->irq;
184 dma = devc->dma = hw_config->dma;
185 devc->osp = hw_config->osp;
186
187 if (devc->base != 0x220 && devc->base != 0x240)
188 if (devc->base != 0x230 && devc->base != 0x250) /* Some cards use these */
189 return 0;
190
191 if (!request_region(devc->base, 0x10, "PSS mixer, SB emulation")) {
192 printk(KERN_ERR "PSS: I/O port conflict\n");
193 return 0;
194 }
195 id = inw(REG(PSS_ID));
196 if ((id >> 8) != 'E') {
197 printk(KERN_ERR "No PSS signature detected at 0x%x (0x%x)\n", devc->base, id);
198 release_region(devc->base, 0x10);
199 return 0;
200 }
201 if (!request_region(devc->base + 0x10, 0x9, "PSS config")) {
202 printk(KERN_ERR "PSS: I/O port conflict\n");
203 release_region(devc->base, 0x10);
204 return 0;
205 }
206 return 1;
207}
208
209static int set_irq(struct pss_confdata *devc, int dev, int irq)
210{
211 static unsigned short irq_bits[16] =
212 {
213 0x0000, 0x0000, 0x0000, 0x0008,
214 0x0000, 0x0010, 0x0000, 0x0018,
215 0x0000, 0x0020, 0x0028, 0x0030,
216 0x0038, 0x0000, 0x0000, 0x0000
217 };
218
219 unsigned short tmp, bits;
220
221 if (irq < 0 || irq > 15)
222 return 0;
223
224 tmp = inw(REG(dev)) & ~0x38; /* Load confreg, mask IRQ bits out */
225
226 if ((bits = irq_bits[irq]) == 0 && irq != 0)
227 {
228 printk(KERN_ERR "PSS: Invalid IRQ %d\n", irq);
229 return 0;
230 }
231 outw(tmp | bits, REG(dev));
232 return 1;
233}
234
235static void set_io_base(struct pss_confdata *devc, int dev, int base)
236{
237 unsigned short tmp = inw(REG(dev)) & 0x003f;
238 unsigned short bits = (base & 0x0ffc) << 4;
239
240 outw(bits | tmp, REG(dev));
241}
242
243static int set_dma(struct pss_confdata *devc, int dev, int dma)
244{
245 static unsigned short dma_bits[8] =
246 {
247 0x0001, 0x0002, 0x0000, 0x0003,
248 0x0000, 0x0005, 0x0006, 0x0007
249 };
250
251 unsigned short tmp, bits;
252
253 if (dma < 0 || dma > 7)
254 return 0;
255
256 tmp = inw(REG(dev)) & ~0x07; /* Load confreg, mask DMA bits out */
257
258 if ((bits = dma_bits[dma]) == 0 && dma != 4)
259 {
260 printk(KERN_ERR "PSS: Invalid DMA %d\n", dma);
261 return 0;
262 }
263 outw(tmp | bits, REG(dev));
264 return 1;
265}
266
267static int pss_reset_dsp(struct pss_confdata *devc)
268{
269 unsigned long i, limit = jiffies + HZ/10;
270
271 outw(0x2000, REG(PSS_CONTROL));
272 for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
273 inw(REG(PSS_CONTROL));
274 outw(0x0000, REG(PSS_CONTROL));
275 return 1;
276}
277
278static int pss_put_dspword(struct pss_confdata *devc, unsigned short word)
279{
280 int i, val;
281
282 for (i = 0; i < 327680; i++)
283 {
284 val = inw(REG(PSS_STATUS));
285 if (val & PSS_WRITE_EMPTY)
286 {
287 outw(word, REG(PSS_DATA));
288 return 1;
289 }
290 }
291 return 0;
292}
293
294static int pss_get_dspword(struct pss_confdata *devc, unsigned short *word)
295{
296 int i, val;
297
298 for (i = 0; i < 327680; i++)
299 {
300 val = inw(REG(PSS_STATUS));
301 if (val & PSS_READ_FULL)
302 {
303 *word = inw(REG(PSS_DATA));
304 return 1;
305 }
306 }
307 return 0;
308}
309
310static int pss_download_boot(struct pss_confdata *devc, unsigned char *block,
311 int size, int flags)
312{
313 int i, val, count;
314 unsigned long limit;
315
316 if (flags & CPF_FIRST)
317 {
318/*_____ Warn DSP software that a boot is coming */
319 outw(0x00fe, REG(PSS_DATA));
320
321 limit = jiffies + HZ/10;
322 for (i = 0; i < 32768 && time_before(jiffies, limit); i++)
323 if (inw(REG(PSS_DATA)) == 0x5500)
324 break;
325
326 outw(*block++, REG(PSS_DATA));
327 pss_reset_dsp(devc);
328 }
329 count = 1;
330 while ((flags&CPF_LAST) || count<size )
331 {
332 int j;
333
334 for (j = 0; j < 327670; j++)
335 {
336/*_____ Wait for BG to appear */
337 if (inw(REG(PSS_STATUS)) & PSS_FLAG3)
338 break;
339 }
340
341 if (j == 327670)
342 {
343 /* It's ok we timed out when the file was empty */
344 if (count >= size && flags & CPF_LAST)
345 break;
346 else
347 {
348 printk("\n");
349 printk(KERN_ERR "PSS: Download timeout problems, byte %d=%d\n", count, size);
350 return 0;
351 }
352 }
353/*_____ Send the next byte */
354 if (count >= size)
355 {
356 /* If not data in block send 0xffff */
357 outw (0xffff, REG (PSS_DATA));
358 }
359 else
360 {
361 /*_____ Send the next byte */
362 outw (*block++, REG (PSS_DATA));
363 }
364 count++;
365 }
366
367 if (flags & CPF_LAST)
368 {
369/*_____ Why */
370 outw(0, REG(PSS_DATA));
371
372 limit = jiffies + HZ/10;
373 for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
374 val = inw(REG(PSS_STATUS));
375
376 limit = jiffies + HZ/10;
377 for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
378 {
379 val = inw(REG(PSS_STATUS));
380 if (val & 0x4000)
381 break;
382 }
383
384 /* now read the version */
385 for (i = 0; i < 32000; i++)
386 {
387 val = inw(REG(PSS_STATUS));
388 if (val & PSS_READ_FULL)
389 break;
390 }
391 if (i == 32000)
392 return 0;
393
394 val = inw(REG(PSS_DATA));
395 /* printk( "<PSS: microcode version %d.%d loaded>", val/16, val % 16); */
396 }
397 return 1;
398}
399
400/* Mixer */
401static void set_master_volume(struct pss_confdata *devc, int left, int right)
402{
403 static unsigned char log_scale[101] = {
404 0xdb, 0xe0, 0xe3, 0xe5, 0xe7, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xed, 0xee,
405 0xef, 0xef, 0xf0, 0xf0, 0xf1, 0xf1, 0xf2, 0xf2, 0xf2, 0xf3, 0xf3, 0xf3,
406 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7,
407 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9,
408 0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb,
409 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
410 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd,
411 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
412 0xfe, 0xfe, 0xff, 0xff, 0xff
413 };
414 pss_write(devc, 0x0010);
415 pss_write(devc, log_scale[left] | 0x0000);
416 pss_write(devc, 0x0010);
417 pss_write(devc, log_scale[right] | 0x0100);
418}
419
420static void set_synth_volume(struct pss_confdata *devc, int volume)
421{
422 int vol = ((0x8000*volume)/100L);
423 pss_write(devc, 0x0080);
424 pss_write(devc, vol);
425 pss_write(devc, 0x0081);
426 pss_write(devc, vol);
427}
428
429static void set_bass(struct pss_confdata *devc, int level)
430{
431 int vol = (int)(((0xfd - 0xf0) * level)/100L) + 0xf0;
432 pss_write(devc, 0x0010);
433 pss_write(devc, vol | 0x0200);
434};
435
436static void set_treble(struct pss_confdata *devc, int level)
437{
438 int vol = (((0xfd - 0xf0) * level)/100L) + 0xf0;
439 pss_write(devc, 0x0010);
440 pss_write(devc, vol | 0x0300);
441};
442
443static void pss_mixer_reset(struct pss_confdata *devc)
444{
445 set_master_volume(devc, 33, 33);
446 set_bass(devc, 50);
447 set_treble(devc, 50);
448 set_synth_volume(devc, 30);
449 pss_write (devc, 0x0010);
450 pss_write (devc, 0x0800 | 0xce); /* Stereo */
451
452 if(pss_mixer)
453 {
454 devc->mixer.volume_l = devc->mixer.volume_r = 33;
455 devc->mixer.bass = 50;
456 devc->mixer.treble = 50;
457 devc->mixer.synth = 30;
458 }
459}
460
461static int set_volume_mono(unsigned __user *p, unsigned int *aleft)
462{
463 unsigned int left, volume;
464 if (get_user(volume, p))
465 return -EFAULT;
466
467 left = volume & 0xff;
468 if (left > 100)
469 left = 100;
470 *aleft = left;
471 return 0;
472}
473
474static int set_volume_stereo(unsigned __user *p,
475 unsigned int *aleft,
476 unsigned int *aright)
477{
478 unsigned int left, right, volume;
479 if (get_user(volume, p))
480 return -EFAULT;
481
482 left = volume & 0xff;
483 if (left > 100)
484 left = 100;
485 right = (volume >> 8) & 0xff;
486 if (right > 100)
487 right = 100;
488 *aleft = left;
489 *aright = right;
490 return 0;
491}
492
493static int ret_vol_mono(int left)
494{
495 return ((left << 8) | left);
496}
497
498static int ret_vol_stereo(int left, int right)
499{
500 return ((right << 8) | left);
501}
502
503static int call_ad_mixer(struct pss_confdata *devc, unsigned int cmd,
504 void __user *arg)
505{
506 if (devc->ad_mixer_dev != NO_WSS_MIXER)
507 return mixer_devs[devc->ad_mixer_dev]->ioctl(devc->ad_mixer_dev, cmd, arg);
508 else
509 return -EINVAL;
510}
511
512static int pss_mixer_ioctl (int dev, unsigned int cmd, void __user *arg)
513{
514 struct pss_confdata *devc = mixer_devs[dev]->devc;
515 int cmdf = cmd & 0xff;
516
517 if ((cmdf != SOUND_MIXER_VOLUME) && (cmdf != SOUND_MIXER_BASS) &&
518 (cmdf != SOUND_MIXER_TREBLE) && (cmdf != SOUND_MIXER_SYNTH) &&
519 (cmdf != SOUND_MIXER_DEVMASK) && (cmdf != SOUND_MIXER_STEREODEVS) &&
520 (cmdf != SOUND_MIXER_RECMASK) && (cmdf != SOUND_MIXER_CAPS) &&
521 (cmdf != SOUND_MIXER_RECSRC))
522 {
523 return call_ad_mixer(devc, cmd, arg);
524 }
525
526 if (((cmd >> 8) & 0xff) != 'M')
527 return -EINVAL;
528
529 if (_SIOC_DIR (cmd) & _SIOC_WRITE)
530 {
531 switch (cmdf)
532 {
533 case SOUND_MIXER_RECSRC:
534 if (devc->ad_mixer_dev != NO_WSS_MIXER)
535 return call_ad_mixer(devc, cmd, arg);
536 else
537 {
538 int v;
539 if (get_user(v, (int __user *)arg))
540 return -EFAULT;
541 if (v != 0)
542 return -EINVAL;
543 return 0;
544 }
545 case SOUND_MIXER_VOLUME:
546 if (set_volume_stereo(arg,
547 &devc->mixer.volume_l,
548 &devc->mixer.volume_r))
549 return -EFAULT;
550 set_master_volume(devc, devc->mixer.volume_l,
551 devc->mixer.volume_r);
552 return ret_vol_stereo(devc->mixer.volume_l,
553 devc->mixer.volume_r);
554
555 case SOUND_MIXER_BASS:
556 if (set_volume_mono(arg, &devc->mixer.bass))
557 return -EFAULT;
558 set_bass(devc, devc->mixer.bass);
559 return ret_vol_mono(devc->mixer.bass);
560
561 case SOUND_MIXER_TREBLE:
562 if (set_volume_mono(arg, &devc->mixer.treble))
563 return -EFAULT;
564 set_treble(devc, devc->mixer.treble);
565 return ret_vol_mono(devc->mixer.treble);
566
567 case SOUND_MIXER_SYNTH:
568 if (set_volume_mono(arg, &devc->mixer.synth))
569 return -EFAULT;
570 set_synth_volume(devc, devc->mixer.synth);
571 return ret_vol_mono(devc->mixer.synth);
572
573 default:
574 return -EINVAL;
575 }
576 }
577 else
578 {
579 int val, and_mask = 0, or_mask = 0;
580 /*
581 * Return parameters
582 */
583 switch (cmdf)
584 {
585 case SOUND_MIXER_DEVMASK:
586 if (call_ad_mixer(devc, cmd, arg) == -EINVAL)
587 break;
588 and_mask = ~0;
589 or_mask = SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_SYNTH;
590 break;
591
592 case SOUND_MIXER_STEREODEVS:
593 if (call_ad_mixer(devc, cmd, arg) == -EINVAL)
594 break;
595 and_mask = ~0;
596 or_mask = SOUND_MASK_VOLUME;
597 break;
598
599 case SOUND_MIXER_RECMASK:
600 if (devc->ad_mixer_dev != NO_WSS_MIXER)
601 return call_ad_mixer(devc, cmd, arg);
602 break;
603
604 case SOUND_MIXER_CAPS:
605 if (devc->ad_mixer_dev != NO_WSS_MIXER)
606 return call_ad_mixer(devc, cmd, arg);
607 or_mask = SOUND_CAP_EXCL_INPUT;
608 break;
609
610 case SOUND_MIXER_RECSRC:
611 if (devc->ad_mixer_dev != NO_WSS_MIXER)
612 return call_ad_mixer(devc, cmd, arg);
613 break;
614
615 case SOUND_MIXER_VOLUME:
616 or_mask = ret_vol_stereo(devc->mixer.volume_l, devc->mixer.volume_r);
617 break;
618
619 case SOUND_MIXER_BASS:
620 or_mask = ret_vol_mono(devc->mixer.bass);
621 break;
622
623 case SOUND_MIXER_TREBLE:
624 or_mask = ret_vol_mono(devc->mixer.treble);
625 break;
626
627 case SOUND_MIXER_SYNTH:
628 or_mask = ret_vol_mono(devc->mixer.synth);
629 break;
630 default:
631 return -EINVAL;
632 }
633 if (get_user(val, (int __user *)arg))
634 return -EFAULT;
635 val &= and_mask;
636 val |= or_mask;
637 if (put_user(val, (int __user *)arg))
638 return -EFAULT;
639 return val;
640 }
641}
642
643static struct mixer_operations pss_mixer_operations =
644{
645 .owner = THIS_MODULE,
646 .id = "SOUNDPORT",
647 .name = "PSS-AD1848",
648 .ioctl = pss_mixer_ioctl
649};
650
651static void disable_all_emulations(void)
652{
653 outw(0x0000, REG(CONF_PSS)); /* 0x0400 enables joystick */
654 outw(0x0000, REG(CONF_WSS));
655 outw(0x0000, REG(CONF_SB));
656 outw(0x0000, REG(CONF_MIDI));
657 outw(0x0000, REG(CONF_CDROM));
658}
659
660static void configure_nonsound_components(void)
661{
662 /* Configure Joystick port */
663
664 if(pss_enable_joystick)
665 {
666 outw(0x0400, REG(CONF_PSS)); /* 0x0400 enables joystick */
667 printk(KERN_INFO "PSS: joystick enabled.\n");
668 }
669 else
670 {
671 printk(KERN_INFO "PSS: joystick port not enabled.\n");
672 }
673
674 /* Configure CDROM port */
675
676 if (pss_cdrom_port == -1) { /* If cdrom port enablation wasn't requested */
677 printk(KERN_INFO "PSS: CDROM port not enabled.\n");
678 } else if (!request_region(pss_cdrom_port, 2, "PSS CDROM")) {
679 pss_cdrom_port = -1;
680 printk(KERN_ERR "PSS: CDROM I/O port conflict.\n");
681 } else {
682 set_io_base(devc, CONF_CDROM, pss_cdrom_port);
683 printk(KERN_INFO "PSS: CDROM I/O port set to 0x%x.\n", pss_cdrom_port);
684 }
685}
686
687static int __init attach_pss(struct address_info *hw_config)
688{
689 unsigned short id;
690 char tmp[100];
691
692 devc->base = hw_config->io_base;
693 devc->irq = hw_config->irq;
694 devc->dma = hw_config->dma;
695 devc->osp = hw_config->osp;
696 devc->ad_mixer_dev = NO_WSS_MIXER;
697
698 if (!probe_pss(hw_config))
699 return 0;
700
701 id = inw(REG(PSS_ID)) & 0x00ff;
702
703 /*
704 * Disable all emulations. Will be enabled later (if required).
705 */
706
707 disable_all_emulations();
708
709#ifdef YOU_REALLY_WANT_TO_ALLOCATE_THESE_RESOURCES
710 if (sound_alloc_dma(hw_config->dma, "PSS"))
711 {
712 printk("pss.c: Can't allocate DMA channel.\n");
713 release_region(hw_config->io_base, 0x10);
714 release_region(hw_config->io_base+0x10, 0x9);
715 return 0;
716 }
717 if (!set_irq(devc, CONF_PSS, devc->irq))
718 {
719 printk("PSS: IRQ allocation error.\n");
720 release_region(hw_config->io_base, 0x10);
721 release_region(hw_config->io_base+0x10, 0x9);
722 return 0;
723 }
724 if (!set_dma(devc, CONF_PSS, devc->dma))
725 {
726 printk(KERN_ERR "PSS: DMA allocation error\n");
727 release_region(hw_config->io_base, 0x10);
728 release_region(hw_config->io_base+0x10, 0x9);
729 return 0;
730 }
731#endif
732
733 configure_nonsound_components();
734 pss_initialized = 1;
735 sprintf(tmp, "ECHO-PSS Rev. %d", id);
736 conf_printf(tmp, hw_config);
737 return 1;
738}
739
740static int __init probe_pss_mpu(struct address_info *hw_config)
741{
742 struct resource *ports;
743 int timeout;
744
745 if (!pss_initialized)
746 return 0;
747
748 ports = request_region(hw_config->io_base, 2, "mpu401");
749
750 if (!ports) {
751 printk(KERN_ERR "PSS: MPU I/O port conflict\n");
752 return 0;
753 }
754 set_io_base(devc, CONF_MIDI, hw_config->io_base);
755 if (!set_irq(devc, CONF_MIDI, hw_config->irq)) {
756 printk(KERN_ERR "PSS: MIDI IRQ allocation error.\n");
757 goto fail;
758 }
759 if (!pss_synthLen) {
760 printk(KERN_ERR "PSS: Can't enable MPU. MIDI synth microcode not available.\n");
761 goto fail;
762 }
763 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST)) {
764 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
765 goto fail;
766 }
767
768 /*
769 * Finally wait until the DSP algorithm has initialized itself and
770 * deactivates receive interrupt.
771 */
772
773 for (timeout = 900000; timeout > 0; timeout--)
774 {
775 if ((inb(hw_config->io_base + 1) & 0x80) == 0) /* Input data avail */
776 inb(hw_config->io_base); /* Discard it */
777 else
778 break; /* No more input */
779 }
780
781 if (!probe_mpu401(hw_config, ports))
782 goto fail;
783
784 attach_mpu401(hw_config, THIS_MODULE); /* Slot 1 */
785 if (hw_config->slots[1] != -1) /* The MPU driver installed itself */
786 midi_devs[hw_config->slots[1]]->coproc = &pss_coproc_operations;
787 return 1;
788fail:
789 release_region(hw_config->io_base, 2);
790 return 0;
791}
792
793static int pss_coproc_open(void *dev_info, int sub_device)
794{
795 switch (sub_device)
796 {
797 case COPR_MIDI:
798 if (pss_synthLen == 0)
799 {
800 printk(KERN_ERR "PSS: MIDI synth microcode not available.\n");
801 return -EIO;
802 }
803 if (nonstandard_microcode)
804 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
805 {
806 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
807 return -EIO;
808 }
809 nonstandard_microcode = 0;
810 break;
811
812 default:
813 break;
814 }
815 return 0;
816}
817
818static void pss_coproc_close(void *dev_info, int sub_device)
819{
820 return;
821}
822
823static void pss_coproc_reset(void *dev_info)
824{
825 if (pss_synthLen)
826 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
827 {
828 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
829 }
830 nonstandard_microcode = 0;
831}
832
833static int download_boot_block(void *dev_info, copr_buffer * buf)
834{
835 if (buf->len <= 0 || buf->len > sizeof(buf->data))
836 return -EINVAL;
837
838 if (!pss_download_boot(devc, buf->data, buf->len, buf->flags))
839 {
840 printk(KERN_ERR "PSS: Unable to load microcode block to DSP.\n");
841 return -EIO;
842 }
843 nonstandard_microcode = 1; /* The MIDI microcode has been overwritten */
844 return 0;
845}
846
847static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg, int local)
848{
849 copr_buffer *buf;
850 copr_msg *mbuf;
851 copr_debug_buf dbuf;
852 unsigned short tmp;
853 unsigned long flags;
854 unsigned short *data;
855 int i, err;
856 /* printk( "PSS coproc ioctl %x %x %d\n", cmd, arg, local); */
857
858 switch (cmd)
859 {
860 case SNDCTL_COPR_RESET:
861 pss_coproc_reset(dev_info);
862 return 0;
863
864 case SNDCTL_COPR_LOAD:
865 buf = vmalloc(sizeof(copr_buffer));
866 if (buf == NULL)
867 return -ENOSPC;
868 if (copy_from_user(buf, arg, sizeof(copr_buffer))) {
869 vfree(buf);
870 return -EFAULT;
871 }
872 err = download_boot_block(dev_info, buf);
873 vfree(buf);
874 return err;
875
876 case SNDCTL_COPR_SENDMSG:
877 mbuf = vmalloc(sizeof(copr_msg));
878 if (mbuf == NULL)
879 return -ENOSPC;
880 if (copy_from_user(mbuf, arg, sizeof(copr_msg))) {
881 vfree(mbuf);
882 return -EFAULT;
883 }
884 data = (unsigned short *)(mbuf->data);
885 spin_lock_irqsave(&lock, flags);
886 for (i = 0; i < mbuf->len; i++) {
887 if (!pss_put_dspword(devc, *data++)) {
888 spin_unlock_irqrestore(&lock,flags);
889 mbuf->len = i; /* feed back number of WORDs sent */
890 err = copy_to_user(arg, mbuf, sizeof(copr_msg));
891 vfree(mbuf);
892 return err ? -EFAULT : -EIO;
893 }
894 }
895 spin_unlock_irqrestore(&lock,flags);
896 vfree(mbuf);
897 return 0;
898
899 case SNDCTL_COPR_RCVMSG:
900 err = 0;
901 mbuf = vmalloc(sizeof(copr_msg));
902 if (mbuf == NULL)
903 return -ENOSPC;
904 data = (unsigned short *)mbuf->data;
905 spin_lock_irqsave(&lock, flags);
906 for (i = 0; i < sizeof(mbuf->data)/sizeof(unsigned short); i++) {
907 mbuf->len = i; /* feed back number of WORDs read */
908 if (!pss_get_dspword(devc, data++)) {
909 if (i == 0)
910 err = -EIO;
911 break;
912 }
913 }
914 spin_unlock_irqrestore(&lock,flags);
915 if (copy_to_user(arg, mbuf, sizeof(copr_msg)))
916 err = -EFAULT;
917 vfree(mbuf);
918 return err;
919
920 case SNDCTL_COPR_RDATA:
921 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
922 return -EFAULT;
923 spin_lock_irqsave(&lock, flags);
924 if (!pss_put_dspword(devc, 0x00d0)) {
925 spin_unlock_irqrestore(&lock,flags);
926 return -EIO;
927 }
928 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
929 spin_unlock_irqrestore(&lock,flags);
930 return -EIO;
931 }
932 if (!pss_get_dspword(devc, &tmp)) {
933 spin_unlock_irqrestore(&lock,flags);
934 return -EIO;
935 }
936 dbuf.parm1 = tmp;
937 spin_unlock_irqrestore(&lock,flags);
938 if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
939 return -EFAULT;
940 return 0;
941
942 case SNDCTL_COPR_WDATA:
943 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
944 return -EFAULT;
945 spin_lock_irqsave(&lock, flags);
946 if (!pss_put_dspword(devc, 0x00d1)) {
947 spin_unlock_irqrestore(&lock,flags);
948 return -EIO;
949 }
950 if (!pss_put_dspword(devc, (unsigned short) (dbuf.parm1 & 0xffff))) {
951 spin_unlock_irqrestore(&lock,flags);
952 return -EIO;
953 }
954 tmp = (unsigned int)dbuf.parm2 & 0xffff;
955 if (!pss_put_dspword(devc, tmp)) {
956 spin_unlock_irqrestore(&lock,flags);
957 return -EIO;
958 }
959 spin_unlock_irqrestore(&lock,flags);
960 return 0;
961
962 case SNDCTL_COPR_WCODE:
963 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
964 return -EFAULT;
965 spin_lock_irqsave(&lock, flags);
966 if (!pss_put_dspword(devc, 0x00d3)) {
967 spin_unlock_irqrestore(&lock,flags);
968 return -EIO;
969 }
970 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
971 spin_unlock_irqrestore(&lock,flags);
972 return -EIO;
973 }
974 tmp = (unsigned int)dbuf.parm2 & 0x00ff;
975 if (!pss_put_dspword(devc, tmp)) {
976 spin_unlock_irqrestore(&lock,flags);
977 return -EIO;
978 }
979 tmp = ((unsigned int)dbuf.parm2 >> 8) & 0xffff;
980 if (!pss_put_dspword(devc, tmp)) {
981 spin_unlock_irqrestore(&lock,flags);
982 return -EIO;
983 }
984 spin_unlock_irqrestore(&lock,flags);
985 return 0;
986
987 case SNDCTL_COPR_RCODE:
988 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
989 return -EFAULT;
990 spin_lock_irqsave(&lock, flags);
991 if (!pss_put_dspword(devc, 0x00d2)) {
992 spin_unlock_irqrestore(&lock,flags);
993 return -EIO;
994 }
995 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
996 spin_unlock_irqrestore(&lock,flags);
997 return -EIO;
998 }
999 if (!pss_get_dspword(devc, &tmp)) { /* Read MSB */
1000 spin_unlock_irqrestore(&lock,flags);
1001 return -EIO;
1002 }
1003 dbuf.parm1 = tmp << 8;
1004 if (!pss_get_dspword(devc, &tmp)) { /* Read LSB */
1005 spin_unlock_irqrestore(&lock,flags);
1006 return -EIO;
1007 }
1008 dbuf.parm1 |= tmp & 0x00ff;
1009 spin_unlock_irqrestore(&lock,flags);
1010 if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
1011 return -EFAULT;
1012 return 0;
1013
1014 default:
1015 return -EINVAL;
1016 }
1017 return -EINVAL;
1018}
1019
1020static coproc_operations pss_coproc_operations =
1021{
1022 "ADSP-2115",
1023 THIS_MODULE,
1024 pss_coproc_open,
1025 pss_coproc_close,
1026 pss_coproc_ioctl,
1027 pss_coproc_reset,
1028 &pss_data
1029};
1030
1031static int __init probe_pss_mss(struct address_info *hw_config)
1032{
1033 volatile int timeout;
1034 struct resource *ports;
1035 int my_mix = -999; /* gcc shut up */
1036
1037 if (!pss_initialized)
1038 return 0;
1039
1040 if (!request_region(hw_config->io_base, 4, "WSS config")) {
1041 printk(KERN_ERR "PSS: WSS I/O port conflicts.\n");
1042 return 0;
1043 }
1044 ports = request_region(hw_config->io_base + 4, 4, "ad1848");
1045 if (!ports) {
1046 printk(KERN_ERR "PSS: WSS I/O port conflicts.\n");
1047 release_region(hw_config->io_base, 4);
1048 return 0;
1049 }
1050 set_io_base(devc, CONF_WSS, hw_config->io_base);
1051 if (!set_irq(devc, CONF_WSS, hw_config->irq)) {
1052 printk("PSS: WSS IRQ allocation error.\n");
1053 goto fail;
1054 }
1055 if (!set_dma(devc, CONF_WSS, hw_config->dma)) {
1056 printk(KERN_ERR "PSS: WSS DMA allocation error\n");
1057 goto fail;
1058 }
1059 /*
1060 * For some reason the card returns 0xff in the WSS status register
1061 * immediately after boot. Probably MIDI+SB emulation algorithm
1062 * downloaded to the ADSP2115 spends some time initializing the card.
1063 * Let's try to wait until it finishes this task.
1064 */
1065 for (timeout = 0; timeout < 100000 && (inb(hw_config->io_base + WSS_INDEX) &
1066 WSS_INITIALIZING); timeout++)
1067 ;
1068
1069 outb((0x0b), hw_config->io_base + WSS_INDEX); /* Required by some cards */
1070
1071 for (timeout = 0; (inb(hw_config->io_base + WSS_DATA) & WSS_AUTOCALIBRATION) &&
1072 (timeout < 100000); timeout++)
1073 ;
1074
1075 if (!probe_ms_sound(hw_config, ports))
1076 goto fail;
1077
1078 devc->ad_mixer_dev = NO_WSS_MIXER;
1079 if (pss_mixer)
1080 {
1081 if ((my_mix = sound_install_mixer (MIXER_DRIVER_VERSION,
1082 "PSS-SPEAKERS and AD1848 (through MSS audio codec)",
1083 &pss_mixer_operations,
1084 sizeof (struct mixer_operations),
1085 devc)) < 0)
1086 {
1087 printk(KERN_ERR "Could not install PSS mixer\n");
1088 goto fail;
1089 }
1090 }
1091 pss_mixer_reset(devc);
1092 attach_ms_sound(hw_config, ports, THIS_MODULE); /* Slot 0 */
1093
1094 if (hw_config->slots[0] != -1)
1095 {
1096 /* The MSS driver installed itself */
1097 audio_devs[hw_config->slots[0]]->coproc = &pss_coproc_operations;
1098 if (pss_mixer && (num_mixers == (my_mix + 2)))
1099 {
1100 /* The MSS mixer installed */
1101 devc->ad_mixer_dev = audio_devs[hw_config->slots[0]]->mixer_dev;
1102 }
1103 }
1104 return 1;
1105fail:
1106 release_region(hw_config->io_base + 4, 4);
1107 release_region(hw_config->io_base, 4);
1108 return 0;
1109}
1110
1111static inline void __exit unload_pss(struct address_info *hw_config)
1112{
1113 release_region(hw_config->io_base, 0x10);
1114 release_region(hw_config->io_base+0x10, 0x9);
1115}
1116
1117static inline void __exit unload_pss_mpu(struct address_info *hw_config)
1118{
1119 unload_mpu401(hw_config);
1120}
1121
1122static inline void __exit unload_pss_mss(struct address_info *hw_config)
1123{
1124 unload_ms_sound(hw_config);
1125}
1126
1127
1128static struct address_info cfg;
1129static struct address_info cfg2;
1130static struct address_info cfg_mpu;
1131
1132static int pss_io __initdata = -1;
1133static int mss_io __initdata = -1;
1134static int mss_irq __initdata = -1;
1135static int mss_dma __initdata = -1;
1136static int mpu_io __initdata = -1;
1137static int mpu_irq __initdata = -1;
1138static bool pss_no_sound = 0; /* Just configure non-sound components */
1139static bool pss_keep_settings = 1; /* Keep hardware settings at module exit */
1140static char *pss_firmware = "/etc/sound/pss_synth";
1141
1142module_param_hw(pss_io, int, ioport, 0);
1143MODULE_PARM_DESC(pss_io, "Set i/o base of PSS card (probably 0x220 or 0x240)");
1144module_param_hw(mss_io, int, ioport, 0);
1145MODULE_PARM_DESC(mss_io, "Set WSS (audio) i/o base (0x530, 0x604, 0xE80, 0xF40, or other. Address must end in 0 or 4 and must be from 0x100 to 0xFF4)");
1146module_param_hw(mss_irq, int, irq, 0);
1147MODULE_PARM_DESC(mss_irq, "Set WSS (audio) IRQ (3, 5, 7, 9, 10, 11, 12)");
1148module_param_hw(mss_dma, int, dma, 0);
1149MODULE_PARM_DESC(mss_dma, "Set WSS (audio) DMA (0, 1, 3)");
1150module_param_hw(mpu_io, int, ioport, 0);
1151MODULE_PARM_DESC(mpu_io, "Set MIDI i/o base (0x330 or other. Address must be on 4 location boundaries and must be from 0x100 to 0xFFC)");
1152module_param_hw(mpu_irq, int, irq, 0);
1153MODULE_PARM_DESC(mpu_irq, "Set MIDI IRQ (3, 5, 7, 9, 10, 11, 12)");
1154module_param_hw(pss_cdrom_port, int, ioport, 0);
1155MODULE_PARM_DESC(pss_cdrom_port, "Set the PSS CDROM port i/o base (0x340 or other)");
1156module_param(pss_enable_joystick, bool, 0);
1157MODULE_PARM_DESC(pss_enable_joystick, "Enables the PSS joystick port (1 to enable, 0 to disable)");
1158module_param(pss_no_sound, bool, 0);
1159MODULE_PARM_DESC(pss_no_sound, "Configure sound compoents (0 - no, 1 - yes)");
1160module_param(pss_keep_settings, bool, 0);
1161MODULE_PARM_DESC(pss_keep_settings, "Keep hardware setting at driver unloading (0 - no, 1 - yes)");
1162module_param(pss_firmware, charp, 0);
1163MODULE_PARM_DESC(pss_firmware, "Location of the firmware file (default - /etc/sound/pss_synth)");
1164module_param(pss_mixer, bool, 0);
1165MODULE_PARM_DESC(pss_mixer, "Enable (1) or disable (0) PSS mixer (controlling of output volume, bass, treble, synth volume). The mixer is not available on all PSS cards.");
1166MODULE_AUTHOR("Hannu Savolainen, Vladimir Michl");
1167MODULE_DESCRIPTION("Module for PSS sound cards (based on AD1848, ADSP-2115 and ESC614). This module includes control of output amplifier and synth volume of the Beethoven ADSP-16 card (this may work with other PSS cards).");
1168MODULE_LICENSE("GPL");
1169
1170
1171static int fw_load = 0;
1172static int pssmpu = 0, pssmss = 0;
1173
1174/*
1175 * Load a PSS sound card module
1176 */
1177
1178static int __init init_pss(void)
1179{
1180
1181 if(pss_no_sound) /* If configuring only nonsound components */
1182 {
1183 cfg.io_base = pss_io;
1184 if(!probe_pss(&cfg))
1185 return -ENODEV;
1186 printk(KERN_INFO "ECHO-PSS Rev. %d\n", inw(REG(PSS_ID)) & 0x00ff);
1187 printk(KERN_INFO "PSS: loading in no sound mode.\n");
1188 disable_all_emulations();
1189 configure_nonsound_components();
1190 release_region(pss_io, 0x10);
1191 release_region(pss_io + 0x10, 0x9);
1192 return 0;
1193 }
1194
1195 cfg.io_base = pss_io;
1196
1197 cfg2.io_base = mss_io;
1198 cfg2.irq = mss_irq;
1199 cfg2.dma = mss_dma;
1200
1201 cfg_mpu.io_base = mpu_io;
1202 cfg_mpu.irq = mpu_irq;
1203
1204 if (cfg.io_base == -1 || cfg2.io_base == -1 || cfg2.irq == -1 || cfg.dma == -1) {
1205 printk(KERN_INFO "pss: mss_io, mss_dma, mss_irq and pss_io must be set.\n");
1206 return -EINVAL;
1207 }
1208
1209 if (!pss_synth) {
1210 fw_load = 1;
1211 pss_synthLen = mod_firmware_load(pss_firmware, (void *) &pss_synth);
1212 }
1213 if (!attach_pss(&cfg))
1214 return -ENODEV;
1215 /*
1216 * Attach stuff
1217 */
1218 if (probe_pss_mpu(&cfg_mpu))
1219 pssmpu = 1;
1220
1221 if (probe_pss_mss(&cfg2))
1222 pssmss = 1;
1223
1224 return 0;
1225}
1226
1227static void __exit cleanup_pss(void)
1228{
1229 if(!pss_no_sound)
1230 {
1231 if (fw_load)
1232 vfree(pss_synth);
1233 if(pssmss)
1234 unload_pss_mss(&cfg2);
1235 if(pssmpu)
1236 unload_pss_mpu(&cfg_mpu);
1237 unload_pss(&cfg);
1238 } else if (pss_cdrom_port != -1)
1239 release_region(pss_cdrom_port, 2);
1240
1241 if(!pss_keep_settings) /* Keep hardware settings if asked */
1242 {
1243 disable_all_emulations();
1244 printk(KERN_INFO "Resetting PSS sound card configurations.\n");
1245 }
1246}
1247
1248module_init(init_pss);
1249module_exit(cleanup_pss);
1250
1251#ifndef MODULE
1252static int __init setup_pss(char *str)
1253{
1254 /* io, mss_io, mss_irq, mss_dma, mpu_io, mpu_irq */
1255 int ints[7];
1256
1257 str = get_options(str, ARRAY_SIZE(ints), ints);
1258
1259 pss_io = ints[1];
1260 mss_io = ints[2];
1261 mss_irq = ints[3];
1262 mss_dma = ints[4];
1263 mpu_io = ints[5];
1264 mpu_irq = ints[6];
1265
1266 return 1;
1267}
1268
1269__setup("pss=", setup_pss);
1270#endif
diff --git a/sound/oss/sb.h b/sound/oss/sb.h
deleted file mode 100644
index bb1d18709b36..000000000000
--- a/sound/oss/sb.h
+++ /dev/null
@@ -1,186 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#define DSP_RESET (devc->base + 0x6)
3#define DSP_READ (devc->base + 0xA)
4#define DSP_WRITE (devc->base + 0xC)
5#define DSP_COMMAND (devc->base + 0xC)
6#define DSP_STATUS (devc->base + 0xC)
7#define DSP_DATA_AVAIL (devc->base + 0xE)
8#define DSP_DATA_AVL16 (devc->base + 0xF)
9#define MIXER_ADDR (devc->base + 0x4)
10#define MIXER_DATA (devc->base + 0x5)
11#define OPL3_LEFT (devc->base + 0x0)
12#define OPL3_RIGHT (devc->base + 0x2)
13#define OPL3_BOTH (devc->base + 0x8)
14/* DSP Commands */
15
16#define DSP_CMD_SPKON 0xD1
17#define DSP_CMD_SPKOFF 0xD3
18#define DSP_CMD_DMAON 0xD0
19#define DSP_CMD_DMAOFF 0xD4
20
21#define IMODE_NONE 0
22#define IMODE_OUTPUT PCM_ENABLE_OUTPUT
23#define IMODE_INPUT PCM_ENABLE_INPUT
24#define IMODE_INIT 3
25#define IMODE_MIDI 4
26
27#define NORMAL_MIDI 0
28#define UART_MIDI 1
29
30
31/*
32 * Device models
33 */
34#define MDL_NONE 0
35#define MDL_SB1 1 /* SB1.0 or 1.5 */
36#define MDL_SB2 2 /* SB2.0 */
37#define MDL_SB201 3 /* SB2.01 */
38#define MDL_SBPRO 4 /* SB Pro */
39#define MDL_SB16 5 /* SB16/32/AWE */
40#define MDL_SBPNP 6 /* SB16/32/AWE PnP */
41#define MDL_JAZZ 10 /* Media Vision Jazz16 */
42#define MDL_SMW 11 /* Logitech SoundMan Wave (Jazz16) */
43#define MDL_ESS 12 /* ESS ES688 and ES1688 */
44#define MDL_AZTECH 13 /* Aztech Sound Galaxy family */
45#define MDL_ES1868MIDI 14 /* MIDI port of ESS1868 */
46#define MDL_AEDSP 15 /* Audio Excel DSP 16 */
47#define MDL_ESSPCI 16 /* ESS PCI card */
48#define MDL_YMPCI 17 /* Yamaha PCI sb in emulation */
49
50#define SUBMDL_ALS007 42 /* ALS-007 differs from SB16 only in mixer */
51 /* register assignment */
52#define SUBMDL_ALS100 43 /* ALS-100 allows sampling rates of up */
53 /* to 48kHz */
54
55/*
56 * Config flags
57 */
58#define SB_NO_MIDI 0x00000001
59#define SB_NO_MIXER 0x00000002
60#define SB_NO_AUDIO 0x00000004
61#define SB_NO_RECORDING 0x00000008 /* No audio recording */
62#define SB_MIDI_ONLY (SB_NO_AUDIO|SB_NO_MIXER)
63#define SB_PCI_IRQ 0x00000010 /* PCI shared IRQ */
64
65struct mixer_def {
66 unsigned int regno: 8;
67 unsigned int bitoffs:4;
68 unsigned int nbits:4;
69};
70
71typedef struct mixer_def mixer_tab[32][2];
72typedef struct mixer_def mixer_ent;
73
74struct sb_module_options
75{
76 int esstype; /* ESS chip type */
77 int acer; /* Do acer notebook init? */
78 int sm_games; /* Logitech soundman games? */
79};
80
81typedef struct sb_devc {
82 int dev;
83
84 /* Hardware parameters */
85 int *osp;
86 int minor, major;
87 int type;
88 int model, submodel;
89 int caps;
90# define SBCAP_STEREO 0x00000001
91# define SBCAP_16BITS 0x00000002
92
93 /* Hardware resources */
94 int base;
95 int irq;
96 int dma8, dma16;
97
98 int pcibase; /* For ESS Maestro etc */
99
100 /* State variables */
101 int opened;
102 /* new audio fields for full duplex support */
103 int fullduplex;
104 int duplex;
105 int speed, bits, channels;
106 volatile int irq_ok;
107 volatile int intr_active, irq_mode;
108 /* duplicate audio fields for full duplex support */
109 volatile int intr_active_16, irq_mode_16;
110
111 /* Mixer fields */
112 int *levels;
113 mixer_tab *iomap;
114 size_t iomap_sz; /* number or records in the iomap table */
115 int mixer_caps, recmask, outmask, supported_devices;
116 int supported_rec_devices, supported_out_devices;
117 int my_mixerdev;
118 int sbmixnum;
119
120 /* Audio fields */
121 unsigned long trg_buf;
122 int trigger_bits;
123 int trg_bytes;
124 int trg_intrflag;
125 int trg_restart;
126 /* duplicate audio fields for full duplex support */
127 unsigned long trg_buf_16;
128 int trigger_bits_16;
129 int trg_bytes_16;
130 int trg_intrflag_16;
131 int trg_restart_16;
132
133 unsigned char tconst;
134
135 /* MIDI fields */
136 int my_mididev;
137 int input_opened;
138 int midi_broken;
139 void (*midi_input_intr) (int dev, unsigned char data);
140 void *midi_irq_cookie; /* IRQ cookie for the midi */
141
142 spinlock_t lock;
143
144 struct sb_module_options sbmo; /* Module options */
145
146 } sb_devc;
147
148/*
149 * PCI card types
150 */
151
152#define SB_PCI_ESSMAESTRO 1 /* ESS Maestro Legacy */
153#define SB_PCI_YAMAHA 2 /* Yamaha Legacy */
154
155/*
156 * Functions
157 */
158
159int sb_dsp_command (sb_devc *devc, unsigned char val);
160int sb_dsp_get_byte(sb_devc * devc);
161int sb_dsp_reset (sb_devc *devc);
162void sb_setmixer (sb_devc *devc, unsigned int port, unsigned int value);
163unsigned int sb_getmixer (sb_devc *devc, unsigned int port);
164int sb_dsp_detect (struct address_info *hw_config, int pci, int pciio, struct sb_module_options *sbmo);
165int sb_dsp_init (struct address_info *hw_config, struct module *owner);
166void sb_dsp_unload(struct address_info *hw_config, int sbmpu);
167int sb_mixer_init(sb_devc *devc, struct module *owner);
168void sb_mixer_unload(sb_devc *devc);
169void sb_mixer_set_stereo (sb_devc *devc, int mode);
170void smw_mixer_init(sb_devc *devc);
171void sb_dsp_midi_init (sb_devc *devc, struct module *owner);
172void sb_audio_init (sb_devc *devc, char *name, struct module *owner);
173void sb_midi_interrupt (sb_devc *devc);
174void sb_chgmixer (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val);
175int sb_common_mixer_set(sb_devc * devc, int dev, int left, int right);
176
177int sb_audio_open(int dev, int mode);
178void sb_audio_close(int dev);
179
180/* From sb_common.c */
181void sb_dsp_disable_midi(int port);
182int probe_sbmpu (struct address_info *hw_config, struct module *owner);
183void unload_sbmpu (struct address_info *hw_config);
184
185void unload_sb16(struct address_info *hw_info);
186void unload_sb16midi(struct address_info *hw_info);
diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
deleted file mode 100644
index dc91072f4d82..000000000000
--- a/sound/oss/sb_audio.c
+++ /dev/null
@@ -1,1097 +0,0 @@
1/*
2 * sound/oss/sb_audio.c
3 *
4 * Audio routines for Sound Blaster compatible cards.
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 * Changes
14 * Alan Cox : Formatting and clean ups
15 *
16 * Status
17 * Mostly working. Weird uart bug causing irq storms
18 *
19 * Daniel J. Rodriksson: Changes to make sb16 work full duplex.
20 * Maybe other 16 bit cards in this code could behave
21 * the same.
22 * Chris Rankin: Use spinlocks instead of CLI/STI
23 */
24
25#include <linux/spinlock.h>
26
27#include "sound_config.h"
28
29#include "sb_mixer.h"
30#include "sb.h"
31
32#include "sb_ess.h"
33
34int sb_audio_open(int dev, int mode)
35{
36 sb_devc *devc = audio_devs[dev]->devc;
37 unsigned long flags;
38
39 if (devc == NULL)
40 {
41 printk(KERN_ERR "Sound Blaster: incomplete initialization.\n");
42 return -ENXIO;
43 }
44 if (devc->caps & SB_NO_RECORDING && mode & OPEN_READ)
45 {
46 if (mode == OPEN_READ)
47 return -EPERM;
48 }
49 spin_lock_irqsave(&devc->lock, flags);
50 if (devc->opened)
51 {
52 spin_unlock_irqrestore(&devc->lock, flags);
53 return -EBUSY;
54 }
55 if (devc->dma16 != -1 && devc->dma16 != devc->dma8 && !devc->duplex)
56 {
57 if (sound_open_dma(devc->dma16, "Sound Blaster 16 bit"))
58 {
59 spin_unlock_irqrestore(&devc->lock, flags);
60 return -EBUSY;
61 }
62 }
63 devc->opened = mode;
64 spin_unlock_irqrestore(&devc->lock, flags);
65
66 devc->irq_mode = IMODE_NONE;
67 devc->irq_mode_16 = IMODE_NONE;
68 devc->fullduplex = devc->duplex &&
69 ((mode & OPEN_READ) && (mode & OPEN_WRITE));
70 sb_dsp_reset(devc);
71
72 /* At first glance this check isn't enough, some ESS chips might not
73 * have a RECLEV. However if they don't common_mixer_set will refuse
74 * cause devc->iomap has no register mapping for RECLEV
75 */
76 if (devc->model == MDL_ESS) ess_mixer_reload (devc, SOUND_MIXER_RECLEV);
77
78 /* The ALS007 seems to require that the DSP be removed from the output */
79 /* in order for recording to be activated properly. This is done by */
80 /* setting the appropriate bits of the output control register 4ch to */
81 /* zero. This code assumes that the output control registers are not */
82 /* used anywhere else and therefore the DSP bits are *always* ON for */
83 /* output and OFF for sampling. */
84
85 if (devc->submodel == SUBMDL_ALS007)
86 {
87 if (mode & OPEN_READ)
88 sb_setmixer(devc,ALS007_OUTPUT_CTRL2,
89 sb_getmixer(devc,ALS007_OUTPUT_CTRL2) & 0xf9);
90 else
91 sb_setmixer(devc,ALS007_OUTPUT_CTRL2,
92 sb_getmixer(devc,ALS007_OUTPUT_CTRL2) | 0x06);
93 }
94 return 0;
95}
96
97void sb_audio_close(int dev)
98{
99 sb_devc *devc = audio_devs[dev]->devc;
100
101 /* fix things if mmap turned off fullduplex */
102 if(devc->duplex
103 && !devc->fullduplex
104 && (devc->opened & OPEN_READ) && (devc->opened & OPEN_WRITE))
105 swap(audio_devs[dev]->dmap_out, audio_devs[dev]->dmap_in);
106
107 audio_devs[dev]->dmap_out->dma = devc->dma8;
108 audio_devs[dev]->dmap_in->dma = ( devc->duplex ) ?
109 devc->dma16 : devc->dma8;
110
111 if (devc->dma16 != -1 && devc->dma16 != devc->dma8 && !devc->duplex)
112 sound_close_dma(devc->dma16);
113
114 /* For ALS007, turn DSP output back on if closing the device for read */
115
116 if ((devc->submodel == SUBMDL_ALS007) && (devc->opened & OPEN_READ))
117 {
118 sb_setmixer(devc,ALS007_OUTPUT_CTRL2,
119 sb_getmixer(devc,ALS007_OUTPUT_CTRL2) | 0x06);
120 }
121 devc->opened = 0;
122}
123
124static void sb_set_output_parms(int dev, unsigned long buf, int nr_bytes,
125 int intrflag)
126{
127 sb_devc *devc = audio_devs[dev]->devc;
128
129 if (!devc->fullduplex || devc->bits == AFMT_S16_LE)
130 {
131 devc->trg_buf = buf;
132 devc->trg_bytes = nr_bytes;
133 devc->trg_intrflag = intrflag;
134 devc->irq_mode = IMODE_OUTPUT;
135 }
136 else
137 {
138 devc->trg_buf_16 = buf;
139 devc->trg_bytes_16 = nr_bytes;
140 devc->trg_intrflag_16 = intrflag;
141 devc->irq_mode_16 = IMODE_OUTPUT;
142 }
143}
144
145static void sb_set_input_parms(int dev, unsigned long buf, int count, int intrflag)
146{
147 sb_devc *devc = audio_devs[dev]->devc;
148
149 if (!devc->fullduplex || devc->bits != AFMT_S16_LE)
150 {
151 devc->trg_buf = buf;
152 devc->trg_bytes = count;
153 devc->trg_intrflag = intrflag;
154 devc->irq_mode = IMODE_INPUT;
155 }
156 else
157 {
158 devc->trg_buf_16 = buf;
159 devc->trg_bytes_16 = count;
160 devc->trg_intrflag_16 = intrflag;
161 devc->irq_mode_16 = IMODE_INPUT;
162 }
163}
164
165/*
166 * SB1.x compatible routines
167 */
168
169static void sb1_audio_output_block(int dev, unsigned long buf, int nr_bytes, int intrflag)
170{
171 unsigned long flags;
172 int count = nr_bytes;
173 sb_devc *devc = audio_devs[dev]->devc;
174
175 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
176
177 if (audio_devs[dev]->dmap_out->dma > 3)
178 count >>= 1;
179 count--;
180
181 devc->irq_mode = IMODE_OUTPUT;
182
183 spin_lock_irqsave(&devc->lock, flags);
184 if (sb_dsp_command(devc, 0x14)) /* 8 bit DAC using DMA */
185 {
186 sb_dsp_command(devc, (unsigned char) (count & 0xff));
187 sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));
188 }
189 else
190 printk(KERN_WARNING "Sound Blaster: unable to start DAC.\n");
191 spin_unlock_irqrestore(&devc->lock, flags);
192 devc->intr_active = 1;
193}
194
195static void sb1_audio_start_input(int dev, unsigned long buf, int nr_bytes, int intrflag)
196{
197 unsigned long flags;
198 int count = nr_bytes;
199 sb_devc *devc = audio_devs[dev]->devc;
200
201 /*
202 * Start a DMA input to the buffer pointed by dmaqtail
203 */
204
205 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
206
207 if (audio_devs[dev]->dmap_out->dma > 3)
208 count >>= 1;
209 count--;
210
211 devc->irq_mode = IMODE_INPUT;
212
213 spin_lock_irqsave(&devc->lock, flags);
214 if (sb_dsp_command(devc, 0x24)) /* 8 bit ADC using DMA */
215 {
216 sb_dsp_command(devc, (unsigned char) (count & 0xff));
217 sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));
218 }
219 else
220 printk(KERN_ERR "Sound Blaster: unable to start ADC.\n");
221 spin_unlock_irqrestore(&devc->lock, flags);
222
223 devc->intr_active = 1;
224}
225
226static void sb1_audio_trigger(int dev, int bits)
227{
228 sb_devc *devc = audio_devs[dev]->devc;
229
230 bits &= devc->irq_mode;
231
232 if (!bits)
233 sb_dsp_command(devc, 0xd0); /* Halt DMA */
234 else
235 {
236 switch (devc->irq_mode)
237 {
238 case IMODE_INPUT:
239 sb1_audio_start_input(dev, devc->trg_buf, devc->trg_bytes,
240 devc->trg_intrflag);
241 break;
242
243 case IMODE_OUTPUT:
244 sb1_audio_output_block(dev, devc->trg_buf, devc->trg_bytes,
245 devc->trg_intrflag);
246 break;
247 }
248 }
249 devc->trigger_bits = bits;
250}
251
252static int sb1_audio_prepare_for_input(int dev, int bsize, int bcount)
253{
254 sb_devc *devc = audio_devs[dev]->devc;
255 unsigned long flags;
256
257 spin_lock_irqsave(&devc->lock, flags);
258 if (sb_dsp_command(devc, 0x40))
259 sb_dsp_command(devc, devc->tconst);
260 sb_dsp_command(devc, DSP_CMD_SPKOFF);
261 spin_unlock_irqrestore(&devc->lock, flags);
262
263 devc->trigger_bits = 0;
264 return 0;
265}
266
267static int sb1_audio_prepare_for_output(int dev, int bsize, int bcount)
268{
269 sb_devc *devc = audio_devs[dev]->devc;
270 unsigned long flags;
271
272 spin_lock_irqsave(&devc->lock, flags);
273 if (sb_dsp_command(devc, 0x40))
274 sb_dsp_command(devc, devc->tconst);
275 sb_dsp_command(devc, DSP_CMD_SPKON);
276 spin_unlock_irqrestore(&devc->lock, flags);
277 devc->trigger_bits = 0;
278 return 0;
279}
280
281static int sb1_audio_set_speed(int dev, int speed)
282{
283 int max_speed = 23000;
284 sb_devc *devc = audio_devs[dev]->devc;
285 int tmp;
286
287 if (devc->opened & OPEN_READ)
288 max_speed = 13000;
289
290 if (speed > 0)
291 {
292 if (speed < 4000)
293 speed = 4000;
294
295 if (speed > max_speed)
296 speed = max_speed;
297
298 devc->tconst = (256 - ((1000000 + speed / 2) / speed)) & 0xff;
299 tmp = 256 - devc->tconst;
300 speed = (1000000 + tmp / 2) / tmp;
301
302 devc->speed = speed;
303 }
304 return devc->speed;
305}
306
307static short sb1_audio_set_channels(int dev, short channels)
308{
309 sb_devc *devc = audio_devs[dev]->devc;
310 return devc->channels = 1;
311}
312
313static unsigned int sb1_audio_set_bits(int dev, unsigned int bits)
314{
315 sb_devc *devc = audio_devs[dev]->devc;
316 return devc->bits = 8;
317}
318
319static void sb1_audio_halt_xfer(int dev)
320{
321 unsigned long flags;
322 sb_devc *devc = audio_devs[dev]->devc;
323
324 spin_lock_irqsave(&devc->lock, flags);
325 sb_dsp_reset(devc);
326 spin_unlock_irqrestore(&devc->lock, flags);
327}
328
329/*
330 * SB 2.0 and SB 2.01 compatible routines
331 */
332
333static void sb20_audio_output_block(int dev, unsigned long buf, int nr_bytes,
334 int intrflag)
335{
336 unsigned long flags;
337 int count = nr_bytes;
338 sb_devc *devc = audio_devs[dev]->devc;
339 unsigned char cmd;
340
341 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
342
343 if (audio_devs[dev]->dmap_out->dma > 3)
344 count >>= 1;
345 count--;
346
347 devc->irq_mode = IMODE_OUTPUT;
348
349 spin_lock_irqsave(&devc->lock, flags);
350 if (sb_dsp_command(devc, 0x48)) /* DSP Block size */
351 {
352 sb_dsp_command(devc, (unsigned char) (count & 0xff));
353 sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));
354
355 if (devc->speed * devc->channels <= 23000)
356 cmd = 0x1c; /* 8 bit PCM output */
357 else
358 cmd = 0x90; /* 8 bit high speed PCM output (SB2.01/Pro) */
359
360 if (!sb_dsp_command(devc, cmd))
361 printk(KERN_ERR "Sound Blaster: unable to start DAC.\n");
362 }
363 else
364 printk(KERN_ERR "Sound Blaster: unable to start DAC.\n");
365 spin_unlock_irqrestore(&devc->lock, flags);
366 devc->intr_active = 1;
367}
368
369static void sb20_audio_start_input(int dev, unsigned long buf, int nr_bytes, int intrflag)
370{
371 unsigned long flags;
372 int count = nr_bytes;
373 sb_devc *devc = audio_devs[dev]->devc;
374 unsigned char cmd;
375
376 /*
377 * Start a DMA input to the buffer pointed by dmaqtail
378 */
379
380 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
381
382 if (audio_devs[dev]->dmap_out->dma > 3)
383 count >>= 1;
384 count--;
385
386 devc->irq_mode = IMODE_INPUT;
387
388 spin_lock_irqsave(&devc->lock, flags);
389 if (sb_dsp_command(devc, 0x48)) /* DSP Block size */
390 {
391 sb_dsp_command(devc, (unsigned char) (count & 0xff));
392 sb_dsp_command(devc, (unsigned char) ((count >> 8) & 0xff));
393
394 if (devc->speed * devc->channels <= (devc->major == 3 ? 23000 : 13000))
395 cmd = 0x2c; /* 8 bit PCM input */
396 else
397 cmd = 0x98; /* 8 bit high speed PCM input (SB2.01/Pro) */
398
399 if (!sb_dsp_command(devc, cmd))
400 printk(KERN_ERR "Sound Blaster: unable to start ADC.\n");
401 }
402 else
403 printk(KERN_ERR "Sound Blaster: unable to start ADC.\n");
404 spin_unlock_irqrestore(&devc->lock, flags);
405 devc->intr_active = 1;
406}
407
408static void sb20_audio_trigger(int dev, int bits)
409{
410 sb_devc *devc = audio_devs[dev]->devc;
411 bits &= devc->irq_mode;
412
413 if (!bits)
414 sb_dsp_command(devc, 0xd0); /* Halt DMA */
415 else
416 {
417 switch (devc->irq_mode)
418 {
419 case IMODE_INPUT:
420 sb20_audio_start_input(dev, devc->trg_buf, devc->trg_bytes,
421 devc->trg_intrflag);
422 break;
423
424 case IMODE_OUTPUT:
425 sb20_audio_output_block(dev, devc->trg_buf, devc->trg_bytes,
426 devc->trg_intrflag);
427 break;
428 }
429 }
430 devc->trigger_bits = bits;
431}
432
433/*
434 * SB2.01 specific speed setup
435 */
436
437static int sb201_audio_set_speed(int dev, int speed)
438{
439 sb_devc *devc = audio_devs[dev]->devc;
440 int tmp;
441 int s;
442
443 if (speed > 0)
444 {
445 if (speed < 4000)
446 speed = 4000;
447 if (speed > 44100)
448 speed = 44100;
449 if (devc->opened & OPEN_READ && speed > 15000)
450 speed = 15000;
451 s = speed * devc->channels;
452 devc->tconst = (256 - ((1000000 + s / 2) / s)) & 0xff;
453 tmp = 256 - devc->tconst;
454 speed = ((1000000 + tmp / 2) / tmp) / devc->channels;
455
456 devc->speed = speed;
457 }
458 return devc->speed;
459}
460
461/*
462 * SB Pro specific routines
463 */
464
465static int sbpro_audio_prepare_for_input(int dev, int bsize, int bcount)
466{ /* For SB Pro and Jazz16 */
467 sb_devc *devc = audio_devs[dev]->devc;
468 unsigned long flags;
469 unsigned char bits = 0;
470
471 if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)
472 audio_devs[dev]->dmap_out->dma = audio_devs[dev]->dmap_in->dma =
473 devc->bits == 16 ? devc->dma16 : devc->dma8;
474
475 if (devc->model == MDL_JAZZ || devc->model == MDL_SMW)
476 if (devc->bits == AFMT_S16_LE)
477 bits = 0x04; /* 16 bit mode */
478
479 spin_lock_irqsave(&devc->lock, flags);
480 if (sb_dsp_command(devc, 0x40))
481 sb_dsp_command(devc, devc->tconst);
482 sb_dsp_command(devc, DSP_CMD_SPKOFF);
483 if (devc->channels == 1)
484 sb_dsp_command(devc, 0xa0 | bits); /* Mono input */
485 else
486 sb_dsp_command(devc, 0xa8 | bits); /* Stereo input */
487 spin_unlock_irqrestore(&devc->lock, flags);
488
489 devc->trigger_bits = 0;
490 return 0;
491}
492
493static int sbpro_audio_prepare_for_output(int dev, int bsize, int bcount)
494{ /* For SB Pro and Jazz16 */
495 sb_devc *devc = audio_devs[dev]->devc;
496 unsigned long flags;
497 unsigned char tmp;
498 unsigned char bits = 0;
499
500 if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)
501 audio_devs[dev]->dmap_out->dma = audio_devs[dev]->dmap_in->dma = devc->bits == 16 ? devc->dma16 : devc->dma8;
502 if (devc->model == MDL_SBPRO)
503 sb_mixer_set_stereo(devc, devc->channels == 2);
504
505 spin_lock_irqsave(&devc->lock, flags);
506 if (sb_dsp_command(devc, 0x40))
507 sb_dsp_command(devc, devc->tconst);
508 sb_dsp_command(devc, DSP_CMD_SPKON);
509
510 if (devc->model == MDL_JAZZ || devc->model == MDL_SMW)
511 {
512 if (devc->bits == AFMT_S16_LE)
513 bits = 0x04; /* 16 bit mode */
514
515 if (devc->channels == 1)
516 sb_dsp_command(devc, 0xa0 | bits); /* Mono output */
517 else
518 sb_dsp_command(devc, 0xa8 | bits); /* Stereo output */
519 spin_unlock_irqrestore(&devc->lock, flags);
520 }
521 else
522 {
523 spin_unlock_irqrestore(&devc->lock, flags);
524 tmp = sb_getmixer(devc, 0x0e);
525 if (devc->channels == 1)
526 tmp &= ~0x02;
527 else
528 tmp |= 0x02;
529 sb_setmixer(devc, 0x0e, tmp);
530 }
531 devc->trigger_bits = 0;
532 return 0;
533}
534
535static int sbpro_audio_set_speed(int dev, int speed)
536{
537 sb_devc *devc = audio_devs[dev]->devc;
538
539 if (speed > 0)
540 {
541 if (speed < 4000)
542 speed = 4000;
543 if (speed > 44100)
544 speed = 44100;
545 if (devc->channels > 1 && speed > 22050)
546 speed = 22050;
547 sb201_audio_set_speed(dev, speed);
548 }
549 return devc->speed;
550}
551
552static short sbpro_audio_set_channels(int dev, short channels)
553{
554 sb_devc *devc = audio_devs[dev]->devc;
555
556 if (channels == 1 || channels == 2)
557 {
558 if (channels != devc->channels)
559 {
560 devc->channels = channels;
561 if (devc->model == MDL_SBPRO && devc->channels == 2)
562 sbpro_audio_set_speed(dev, devc->speed);
563 }
564 }
565 return devc->channels;
566}
567
568static int jazz16_audio_set_speed(int dev, int speed)
569{
570 sb_devc *devc = audio_devs[dev]->devc;
571
572 if (speed > 0)
573 {
574 int tmp;
575 int s;
576
577 if (speed < 5000)
578 speed = 5000;
579 if (speed > 44100)
580 speed = 44100;
581
582 s = speed * devc->channels;
583
584 devc->tconst = (256 - ((1000000 + s / 2) / s)) & 0xff;
585
586 tmp = 256 - devc->tconst;
587 speed = ((1000000 + tmp / 2) / tmp) / devc->channels;
588
589 devc->speed = speed;
590 }
591 return devc->speed;
592}
593
594/*
595 * SB16 specific routines
596 */
597
598static int sb16_audio_set_speed(int dev, int speed)
599{
600 sb_devc *devc = audio_devs[dev]->devc;
601 int max_speed = devc->submodel == SUBMDL_ALS100 ? 48000 : 44100;
602
603 if (speed > 0)
604 {
605 if (speed < 5000)
606 speed = 5000;
607
608 if (speed > max_speed)
609 speed = max_speed;
610
611 devc->speed = speed;
612 }
613 return devc->speed;
614}
615
616static unsigned int sb16_audio_set_bits(int dev, unsigned int bits)
617{
618 sb_devc *devc = audio_devs[dev]->devc;
619
620 if (bits != 0)
621 {
622 if (bits == AFMT_U8 || bits == AFMT_S16_LE)
623 devc->bits = bits;
624 else
625 devc->bits = AFMT_U8;
626 }
627
628 return devc->bits;
629}
630
631static int sb16_audio_prepare_for_input(int dev, int bsize, int bcount)
632{
633 sb_devc *devc = audio_devs[dev]->devc;
634
635 if (!devc->fullduplex)
636 {
637 audio_devs[dev]->dmap_out->dma =
638 audio_devs[dev]->dmap_in->dma =
639 devc->bits == AFMT_S16_LE ?
640 devc->dma16 : devc->dma8;
641 }
642 else if (devc->bits == AFMT_S16_LE)
643 {
644 audio_devs[dev]->dmap_out->dma = devc->dma8;
645 audio_devs[dev]->dmap_in->dma = devc->dma16;
646 }
647 else
648 {
649 audio_devs[dev]->dmap_out->dma = devc->dma16;
650 audio_devs[dev]->dmap_in->dma = devc->dma8;
651 }
652
653 devc->trigger_bits = 0;
654 return 0;
655}
656
657static int sb16_audio_prepare_for_output(int dev, int bsize, int bcount)
658{
659 sb_devc *devc = audio_devs[dev]->devc;
660
661 if (!devc->fullduplex)
662 {
663 audio_devs[dev]->dmap_out->dma =
664 audio_devs[dev]->dmap_in->dma =
665 devc->bits == AFMT_S16_LE ?
666 devc->dma16 : devc->dma8;
667 }
668 else if (devc->bits == AFMT_S16_LE)
669 {
670 audio_devs[dev]->dmap_out->dma = devc->dma8;
671 audio_devs[dev]->dmap_in->dma = devc->dma16;
672 }
673 else
674 {
675 audio_devs[dev]->dmap_out->dma = devc->dma16;
676 audio_devs[dev]->dmap_in->dma = devc->dma8;
677 }
678
679 devc->trigger_bits = 0;
680 return 0;
681}
682
683static void sb16_audio_output_block(int dev, unsigned long buf, int count,
684 int intrflag)
685{
686 unsigned long flags, cnt;
687 sb_devc *devc = audio_devs[dev]->devc;
688 unsigned long bits;
689
690 if (!devc->fullduplex || devc->bits == AFMT_S16_LE)
691 {
692 devc->irq_mode = IMODE_OUTPUT;
693 devc->intr_active = 1;
694 }
695 else
696 {
697 devc->irq_mode_16 = IMODE_OUTPUT;
698 devc->intr_active_16 = 1;
699 }
700
701 /* save value */
702 spin_lock_irqsave(&devc->lock, flags);
703 bits = devc->bits;
704 if (devc->fullduplex)
705 devc->bits = (devc->bits == AFMT_S16_LE) ?
706 AFMT_U8 : AFMT_S16_LE;
707 spin_unlock_irqrestore(&devc->lock, flags);
708
709 cnt = count;
710 if (devc->bits == AFMT_S16_LE)
711 cnt >>= 1;
712 cnt--;
713
714 spin_lock_irqsave(&devc->lock, flags);
715
716 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE); */
717
718 sb_dsp_command(devc, 0x41);
719 sb_dsp_command(devc, (unsigned char) ((devc->speed >> 8) & 0xff));
720 sb_dsp_command(devc, (unsigned char) (devc->speed & 0xff));
721
722 sb_dsp_command(devc, (devc->bits == AFMT_S16_LE ? 0xb6 : 0xc6));
723 sb_dsp_command(devc, ((devc->channels == 2 ? 0x20 : 0) +
724 (devc->bits == AFMT_S16_LE ? 0x10 : 0)));
725 sb_dsp_command(devc, (unsigned char) (cnt & 0xff));
726 sb_dsp_command(devc, (unsigned char) (cnt >> 8));
727
728 /* restore real value after all programming */
729 devc->bits = bits;
730 spin_unlock_irqrestore(&devc->lock, flags);
731}
732
733
734/*
735 * This fails on the Cyrix MediaGX. If you don't have the DMA enabled
736 * before the first sample arrives it locks up. However even if you
737 * do enable the DMA in time you just get DMA timeouts and missing
738 * interrupts and stuff, so for now I've not bothered fixing this either.
739 */
740
741static void sb16_audio_start_input(int dev, unsigned long buf, int count, int intrflag)
742{
743 unsigned long flags, cnt;
744 sb_devc *devc = audio_devs[dev]->devc;
745
746 if (!devc->fullduplex || devc->bits != AFMT_S16_LE)
747 {
748 devc->irq_mode = IMODE_INPUT;
749 devc->intr_active = 1;
750 }
751 else
752 {
753 devc->irq_mode_16 = IMODE_INPUT;
754 devc->intr_active_16 = 1;
755 }
756
757 cnt = count;
758 if (devc->bits == AFMT_S16_LE)
759 cnt >>= 1;
760 cnt--;
761
762 spin_lock_irqsave(&devc->lock, flags);
763
764 /* DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ); */
765
766 sb_dsp_command(devc, 0x42);
767 sb_dsp_command(devc, (unsigned char) ((devc->speed >> 8) & 0xff));
768 sb_dsp_command(devc, (unsigned char) (devc->speed & 0xff));
769
770 sb_dsp_command(devc, (devc->bits == AFMT_S16_LE ? 0xbe : 0xce));
771 sb_dsp_command(devc, ((devc->channels == 2 ? 0x20 : 0) +
772 (devc->bits == AFMT_S16_LE ? 0x10 : 0)));
773 sb_dsp_command(devc, (unsigned char) (cnt & 0xff));
774 sb_dsp_command(devc, (unsigned char) (cnt >> 8));
775
776 spin_unlock_irqrestore(&devc->lock, flags);
777}
778
779static void sb16_audio_trigger(int dev, int bits)
780{
781 sb_devc *devc = audio_devs[dev]->devc;
782
783 int bits_16 = bits & devc->irq_mode_16;
784 bits &= devc->irq_mode;
785
786 if (!bits && !bits_16)
787 sb_dsp_command(devc, 0xd0); /* Halt DMA */
788 else
789 {
790 if (bits)
791 {
792 switch (devc->irq_mode)
793 {
794 case IMODE_INPUT:
795 sb16_audio_start_input(dev,
796 devc->trg_buf,
797 devc->trg_bytes,
798 devc->trg_intrflag);
799 break;
800
801 case IMODE_OUTPUT:
802 sb16_audio_output_block(dev,
803 devc->trg_buf,
804 devc->trg_bytes,
805 devc->trg_intrflag);
806 break;
807 }
808 }
809 if (bits_16)
810 {
811 switch (devc->irq_mode_16)
812 {
813 case IMODE_INPUT:
814 sb16_audio_start_input(dev,
815 devc->trg_buf_16,
816 devc->trg_bytes_16,
817 devc->trg_intrflag_16);
818 break;
819
820 case IMODE_OUTPUT:
821 sb16_audio_output_block(dev,
822 devc->trg_buf_16,
823 devc->trg_bytes_16,
824 devc->trg_intrflag_16);
825 break;
826 }
827 }
828 }
829
830 devc->trigger_bits = bits | bits_16;
831}
832
833static unsigned char lbuf8[2048];
834static signed short *lbuf16 = (signed short *)lbuf8;
835#define LBUFCOPYSIZE 1024
836static void
837sb16_copy_from_user(int dev,
838 char *localbuf, int localoffs,
839 const char __user *userbuf, int useroffs,
840 int max_in, int max_out,
841 int *used, int *returned,
842 int len)
843{
844 sb_devc *devc = audio_devs[dev]->devc;
845 int i, c, p, locallen;
846 unsigned char *buf8;
847 signed short *buf16;
848
849 /* if not duplex no conversion */
850 if (!devc->fullduplex)
851 {
852 if (copy_from_user(localbuf + localoffs,
853 userbuf + useroffs, len))
854 return;
855 *used = len;
856 *returned = len;
857 }
858 else if (devc->bits == AFMT_S16_LE)
859 {
860 /* 16 -> 8 */
861 /* max_in >> 1, max number of samples in ( 16 bits ) */
862 /* max_out, max number of samples out ( 8 bits ) */
863 /* len, number of samples that will be taken ( 16 bits )*/
864 /* c, count of samples remaining in buffer ( 16 bits )*/
865 /* p, count of samples already processed ( 16 bits )*/
866 len = ( (max_in >> 1) > max_out) ? max_out : (max_in >> 1);
867 c = len;
868 p = 0;
869 buf8 = (unsigned char *)(localbuf + localoffs);
870 while (c)
871 {
872 locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
873 /* << 1 in order to get 16 bit samples */
874 if (copy_from_user(lbuf16,
875 userbuf + useroffs + (p << 1),
876 locallen << 1))
877 return;
878 for (i = 0; i < locallen; i++)
879 {
880 buf8[p+i] = ~((lbuf16[i] >> 8) & 0xff) ^ 0x80;
881 }
882 c -= locallen; p += locallen;
883 }
884 /* used = ( samples * 16 bits size ) */
885 *used = max_in > ( max_out << 1) ? (max_out << 1) : max_in;
886 /* returned = ( samples * 8 bits size ) */
887 *returned = len;
888 }
889 else
890 {
891 /* 8 -> 16 */
892 /* max_in, max number of samples in ( 8 bits ) */
893 /* max_out >> 1, max number of samples out ( 16 bits ) */
894 /* len, number of samples that will be taken ( 8 bits )*/
895 /* c, count of samples remaining in buffer ( 8 bits )*/
896 /* p, count of samples already processed ( 8 bits )*/
897 len = max_in > (max_out >> 1) ? (max_out >> 1) : max_in;
898 c = len;
899 p = 0;
900 buf16 = (signed short *)(localbuf + localoffs);
901 while (c)
902 {
903 locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
904 if (copy_from_user(lbuf8,
905 userbuf+useroffs + p,
906 locallen))
907 return;
908 for (i = 0; i < locallen; i++)
909 {
910 buf16[p+i] = (~lbuf8[i] ^ 0x80) << 8;
911 }
912 c -= locallen; p += locallen;
913 }
914 /* used = ( samples * 8 bits size ) */
915 *used = len;
916 /* returned = ( samples * 16 bits size ) */
917 *returned = len << 1;
918 }
919}
920
921static void
922sb16_audio_mmap(int dev)
923{
924 sb_devc *devc = audio_devs[dev]->devc;
925 devc->fullduplex = 0;
926}
927
928static struct audio_driver sb1_audio_driver = /* SB1.x */
929{
930 .owner = THIS_MODULE,
931 .open = sb_audio_open,
932 .close = sb_audio_close,
933 .output_block = sb_set_output_parms,
934 .start_input = sb_set_input_parms,
935 .prepare_for_input = sb1_audio_prepare_for_input,
936 .prepare_for_output = sb1_audio_prepare_for_output,
937 .halt_io = sb1_audio_halt_xfer,
938 .trigger = sb1_audio_trigger,
939 .set_speed = sb1_audio_set_speed,
940 .set_bits = sb1_audio_set_bits,
941 .set_channels = sb1_audio_set_channels
942};
943
944static struct audio_driver sb20_audio_driver = /* SB2.0 */
945{
946 .owner = THIS_MODULE,
947 .open = sb_audio_open,
948 .close = sb_audio_close,
949 .output_block = sb_set_output_parms,
950 .start_input = sb_set_input_parms,
951 .prepare_for_input = sb1_audio_prepare_for_input,
952 .prepare_for_output = sb1_audio_prepare_for_output,
953 .halt_io = sb1_audio_halt_xfer,
954 .trigger = sb20_audio_trigger,
955 .set_speed = sb1_audio_set_speed,
956 .set_bits = sb1_audio_set_bits,
957 .set_channels = sb1_audio_set_channels
958};
959
960static struct audio_driver sb201_audio_driver = /* SB2.01 */
961{
962 .owner = THIS_MODULE,
963 .open = sb_audio_open,
964 .close = sb_audio_close,
965 .output_block = sb_set_output_parms,
966 .start_input = sb_set_input_parms,
967 .prepare_for_input = sb1_audio_prepare_for_input,
968 .prepare_for_output = sb1_audio_prepare_for_output,
969 .halt_io = sb1_audio_halt_xfer,
970 .trigger = sb20_audio_trigger,
971 .set_speed = sb201_audio_set_speed,
972 .set_bits = sb1_audio_set_bits,
973 .set_channels = sb1_audio_set_channels
974};
975
976static struct audio_driver sbpro_audio_driver = /* SB Pro */
977{
978 .owner = THIS_MODULE,
979 .open = sb_audio_open,
980 .close = sb_audio_close,
981 .output_block = sb_set_output_parms,
982 .start_input = sb_set_input_parms,
983 .prepare_for_input = sbpro_audio_prepare_for_input,
984 .prepare_for_output = sbpro_audio_prepare_for_output,
985 .halt_io = sb1_audio_halt_xfer,
986 .trigger = sb20_audio_trigger,
987 .set_speed = sbpro_audio_set_speed,
988 .set_bits = sb1_audio_set_bits,
989 .set_channels = sbpro_audio_set_channels
990};
991
992static struct audio_driver jazz16_audio_driver = /* Jazz16 and SM Wave */
993{
994 .owner = THIS_MODULE,
995 .open = sb_audio_open,
996 .close = sb_audio_close,
997 .output_block = sb_set_output_parms,
998 .start_input = sb_set_input_parms,
999 .prepare_for_input = sbpro_audio_prepare_for_input,
1000 .prepare_for_output = sbpro_audio_prepare_for_output,
1001 .halt_io = sb1_audio_halt_xfer,
1002 .trigger = sb20_audio_trigger,
1003 .set_speed = jazz16_audio_set_speed,
1004 .set_bits = sb16_audio_set_bits,
1005 .set_channels = sbpro_audio_set_channels
1006};
1007
1008static struct audio_driver sb16_audio_driver = /* SB16 */
1009{
1010 .owner = THIS_MODULE,
1011 .open = sb_audio_open,
1012 .close = sb_audio_close,
1013 .output_block = sb_set_output_parms,
1014 .start_input = sb_set_input_parms,
1015 .prepare_for_input = sb16_audio_prepare_for_input,
1016 .prepare_for_output = sb16_audio_prepare_for_output,
1017 .halt_io = sb1_audio_halt_xfer,
1018 .copy_user = sb16_copy_from_user,
1019 .trigger = sb16_audio_trigger,
1020 .set_speed = sb16_audio_set_speed,
1021 .set_bits = sb16_audio_set_bits,
1022 .set_channels = sbpro_audio_set_channels,
1023 .mmap = sb16_audio_mmap
1024};
1025
1026void sb_audio_init(sb_devc * devc, char *name, struct module *owner)
1027{
1028 int audio_flags = 0;
1029 int format_mask = AFMT_U8;
1030
1031 struct audio_driver *driver = &sb1_audio_driver;
1032
1033 switch (devc->model)
1034 {
1035 case MDL_SB1: /* SB1.0 or SB 1.5 */
1036 DDB(printk("Will use standard SB1.x driver\n"));
1037 audio_flags = DMA_HARDSTOP;
1038 break;
1039
1040 case MDL_SB2:
1041 DDB(printk("Will use SB2.0 driver\n"));
1042 audio_flags = DMA_AUTOMODE;
1043 driver = &sb20_audio_driver;
1044 break;
1045
1046 case MDL_SB201:
1047 DDB(printk("Will use SB2.01 (high speed) driver\n"));
1048 audio_flags = DMA_AUTOMODE;
1049 driver = &sb201_audio_driver;
1050 break;
1051
1052 case MDL_JAZZ:
1053 case MDL_SMW:
1054 DDB(printk("Will use Jazz16 driver\n"));
1055 audio_flags = DMA_AUTOMODE;
1056 format_mask |= AFMT_S16_LE;
1057 driver = &jazz16_audio_driver;
1058 break;
1059
1060 case MDL_ESS:
1061 DDB(printk("Will use ESS ES688/1688 driver\n"));
1062 driver = ess_audio_init (devc, &audio_flags, &format_mask);
1063 break;
1064
1065 case MDL_SB16:
1066 DDB(printk("Will use SB16 driver\n"));
1067 audio_flags = DMA_AUTOMODE;
1068 format_mask |= AFMT_S16_LE;
1069 if (devc->dma8 != devc->dma16 && devc->dma16 != -1)
1070 {
1071 audio_flags |= DMA_DUPLEX;
1072 devc->duplex = 1;
1073 }
1074 driver = &sb16_audio_driver;
1075 break;
1076
1077 default:
1078 DDB(printk("Will use SB Pro driver\n"));
1079 audio_flags = DMA_AUTOMODE;
1080 driver = &sbpro_audio_driver;
1081 }
1082
1083 if (owner)
1084 driver->owner = owner;
1085
1086 if ((devc->dev = sound_install_audiodrv(AUDIO_DRIVER_VERSION,
1087 name,driver, sizeof(struct audio_driver),
1088 audio_flags, format_mask, devc,
1089 devc->dma8,
1090 devc->duplex ? devc->dma16 : devc->dma8)) < 0)
1091 {
1092 printk(KERN_ERR "Sound Blaster: unable to install audio.\n");
1093 return;
1094 }
1095 audio_devs[devc->dev]->mixer_dev = devc->my_mixerdev;
1096 audio_devs[devc->dev]->min_fragment = 5;
1097}
diff --git a/sound/oss/sb_card.c b/sound/oss/sb_card.c
deleted file mode 100644
index 2a92cfe6cfe9..000000000000
--- a/sound/oss/sb_card.c
+++ /dev/null
@@ -1,354 +0,0 @@
1/*
2 * sound/oss/sb_card.c
3 *
4 * Detection routine for the ISA Sound Blaster and compatible sound
5 * cards.
6 *
7 * This file is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
8 * Version 2 (June 1991). See the "COPYING" file distributed with this
9 * software for more info.
10 *
11 * This is a complete rewrite of the detection routines. This was
12 * prompted by the PnP API change during v2.5 and the ugly state the
13 * code was in.
14 *
15 * Copyright (C) by Paul Laufer 2002. Based on code originally by
16 * Hannu Savolainen which was modified by many others over the
17 * years. Authors specifically mentioned in the previous version were:
18 * Daniel Stone, Alessandro Zummo, Jeff Garzik, Arnaldo Carvalho de
19 * Melo, Daniel Church, and myself.
20 *
21 * 02-05-2003 Original Release, Paul Laufer <paul@laufernet.com>
22 * 02-07-2003 Bug made it into first release. Take two.
23 */
24
25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/slab.h>
28#include <linux/init.h>
29#include "sound_config.h"
30#include "sb_mixer.h"
31#include "sb.h"
32#ifdef CONFIG_PNP
33#include <linux/pnp.h>
34#endif /* CONFIG_PNP */
35#include "sb_card.h"
36
37MODULE_DESCRIPTION("OSS Soundblaster ISA PnP and legacy sound driver");
38MODULE_LICENSE("GPL");
39
40extern void *smw_free;
41
42static int __initdata mpu_io = 0;
43static int __initdata io = -1;
44static int __initdata irq = -1;
45static int __initdata dma = -1;
46static int __initdata dma16 = -1;
47static int __initdata type = 0; /* Can set this to a specific card type */
48static int __initdata esstype = 0; /* ESS chip type */
49static int __initdata acer = 0; /* Do acer notebook init? */
50static int __initdata sm_games = 0; /* Logitech soundman games? */
51
52static struct sb_card_config *legacy = NULL;
53
54#ifdef CONFIG_PNP
55static int pnp_registered;
56static int __initdata pnp = 1;
57/*
58static int __initdata uart401 = 0;
59*/
60#else
61static int __initdata pnp = 0;
62#endif
63
64module_param_hw(io, int, ioport, 000);
65MODULE_PARM_DESC(io, "Soundblaster i/o base address (0x220,0x240,0x260,0x280)");
66module_param_hw(irq, int, irq, 000);
67MODULE_PARM_DESC(irq, "IRQ (5,7,9,10)");
68module_param_hw(dma, int, dma, 000);
69MODULE_PARM_DESC(dma, "8-bit DMA channel (0,1,3)");
70module_param_hw(dma16, int, dma, 000);
71MODULE_PARM_DESC(dma16, "16-bit DMA channel (5,6,7)");
72module_param_hw(mpu_io, int, ioport, 000);
73MODULE_PARM_DESC(mpu_io, "MPU base address");
74module_param(type, int, 000);
75MODULE_PARM_DESC(type, "You can set this to specific card type (doesn't " \
76 "work with pnp)");
77module_param(sm_games, int, 000);
78MODULE_PARM_DESC(sm_games, "Enable support for Logitech soundman games " \
79 "(doesn't work with pnp)");
80module_param(esstype, int, 000);
81MODULE_PARM_DESC(esstype, "ESS chip type (doesn't work with pnp)");
82module_param(acer, int, 000);
83MODULE_PARM_DESC(acer, "Set this to detect cards in some ACER notebooks "\
84 "(doesn't work with pnp)");
85
86#ifdef CONFIG_PNP
87module_param(pnp, int, 000);
88MODULE_PARM_DESC(pnp, "Went set to 0 will disable detection using PnP. "\
89 "Default is 1.\n");
90/* Not done yet.... */
91/*
92module_param(uart401, int, 000);
93MODULE_PARM_DESC(uart401, "When set to 1, will attempt to detect and enable"\
94 "the mpu on some clones");
95*/
96#endif /* CONFIG_PNP */
97
98/* OSS subsystem card registration shared by PnP and legacy routines */
99static int sb_register_oss(struct sb_card_config *scc, struct sb_module_options *sbmo)
100{
101 if (!request_region(scc->conf.io_base, 16, "soundblaster")) {
102 printk(KERN_ERR "sb: ports busy.\n");
103 kfree(scc);
104 return -EBUSY;
105 }
106
107 if (!sb_dsp_detect(&scc->conf, 0, 0, sbmo)) {
108 release_region(scc->conf.io_base, 16);
109 printk(KERN_ERR "sb: Failed DSP Detect.\n");
110 kfree(scc);
111 return -ENODEV;
112 }
113 if(!sb_dsp_init(&scc->conf, THIS_MODULE)) {
114 printk(KERN_ERR "sb: Failed DSP init.\n");
115 kfree(scc);
116 return -ENODEV;
117 }
118 if(scc->mpucnf.io_base > 0) {
119 scc->mpu = 1;
120 printk(KERN_INFO "sb: Turning on MPU\n");
121 if(!probe_sbmpu(&scc->mpucnf, THIS_MODULE))
122 scc->mpu = 0;
123 }
124
125 return 1;
126}
127
128static void sb_unload(struct sb_card_config *scc)
129{
130 sb_dsp_unload(&scc->conf, 0);
131 if(scc->mpu)
132 unload_sbmpu(&scc->mpucnf);
133 kfree(scc);
134}
135
136/* Register legacy card with OSS subsystem */
137static int __init sb_init_legacy(void)
138{
139 struct sb_module_options sbmo = {0};
140
141 if((legacy = kzalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
142 printk(KERN_ERR "sb: Error: Could not allocate memory\n");
143 return -ENOMEM;
144 }
145
146 legacy->conf.io_base = io;
147 legacy->conf.irq = irq;
148 legacy->conf.dma = dma;
149 legacy->conf.dma2 = dma16;
150 legacy->conf.card_subtype = type;
151
152 legacy->mpucnf.io_base = mpu_io;
153 legacy->mpucnf.irq = -1;
154 legacy->mpucnf.dma = -1;
155 legacy->mpucnf.dma2 = -1;
156
157 sbmo.esstype = esstype;
158 sbmo.sm_games = sm_games;
159 sbmo.acer = acer;
160
161 return sb_register_oss(legacy, &sbmo);
162}
163
164#ifdef CONFIG_PNP
165
166/* Populate the OSS subsystem structures with information from PnP */
167static void sb_dev2cfg(struct pnp_dev *dev, struct sb_card_config *scc)
168{
169 scc->conf.io_base = -1;
170 scc->conf.irq = -1;
171 scc->conf.dma = -1;
172 scc->conf.dma2 = -1;
173 scc->mpucnf.io_base = -1;
174 scc->mpucnf.irq = -1;
175 scc->mpucnf.dma = -1;
176 scc->mpucnf.dma2 = -1;
177
178 /* All clones layout their PnP tables differently and some use
179 different logical devices for the MPU */
180 if(!strncmp("CTL",scc->card_id,3)) {
181 scc->conf.io_base = pnp_port_start(dev,0);
182 scc->conf.irq = pnp_irq(dev,0);
183 scc->conf.dma = pnp_dma(dev,0);
184 scc->conf.dma2 = pnp_dma(dev,1);
185 scc->mpucnf.io_base = pnp_port_start(dev,1);
186 return;
187 }
188 if(!strncmp("tBA",scc->card_id,3)) {
189 scc->conf.io_base = pnp_port_start(dev,0);
190 scc->conf.irq = pnp_irq(dev,0);
191 scc->conf.dma = pnp_dma(dev,0);
192 scc->conf.dma2 = pnp_dma(dev,1);
193 return;
194 }
195 if(!strncmp("ESS",scc->card_id,3)) {
196 scc->conf.io_base = pnp_port_start(dev,0);
197 scc->conf.irq = pnp_irq(dev,0);
198 scc->conf.dma = pnp_dma(dev,0);
199 scc->conf.dma2 = pnp_dma(dev,1);
200 scc->mpucnf.io_base = pnp_port_start(dev,2);
201 return;
202 }
203 if(!strncmp("CMI",scc->card_id,3)) {
204 scc->conf.io_base = pnp_port_start(dev,0);
205 scc->conf.irq = pnp_irq(dev,0);
206 scc->conf.dma = pnp_dma(dev,0);
207 scc->conf.dma2 = pnp_dma(dev,1);
208 return;
209 }
210 if(!strncmp("RWB",scc->card_id,3)) {
211 scc->conf.io_base = pnp_port_start(dev,0);
212 scc->conf.irq = pnp_irq(dev,0);
213 scc->conf.dma = pnp_dma(dev,0);
214 return;
215 }
216 if(!strncmp("ALS",scc->card_id,3)) {
217 if(!strncmp("ALS0007",scc->card_id,7)) {
218 scc->conf.io_base = pnp_port_start(dev,0);
219 scc->conf.irq = pnp_irq(dev,0);
220 scc->conf.dma = pnp_dma(dev,0);
221 } else {
222 scc->conf.io_base = pnp_port_start(dev,0);
223 scc->conf.irq = pnp_irq(dev,0);
224 scc->conf.dma = pnp_dma(dev,1);
225 scc->conf.dma2 = pnp_dma(dev,0);
226 }
227 return;
228 }
229 if(!strncmp("RTL",scc->card_id,3)) {
230 scc->conf.io_base = pnp_port_start(dev,0);
231 scc->conf.irq = pnp_irq(dev,0);
232 scc->conf.dma = pnp_dma(dev,1);
233 scc->conf.dma2 = pnp_dma(dev,0);
234 }
235}
236
237static unsigned int sb_pnp_devices;
238
239/* Probe callback function for the PnP API */
240static int sb_pnp_probe(struct pnp_card_link *card, const struct pnp_card_device_id *card_id)
241{
242 struct sb_card_config *scc;
243 struct sb_module_options sbmo = {0}; /* Default to 0 for PnP */
244 struct pnp_dev *dev = pnp_request_card_device(card, card_id->devs[0].id, NULL);
245
246 if(!dev){
247 return -EBUSY;
248 }
249
250 if((scc = kzalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
251 printk(KERN_ERR "sb: Error: Could not allocate memory\n");
252 return -ENOMEM;
253 }
254
255 printk(KERN_INFO "sb: PnP: Found Card Named = \"%s\", Card PnP id = " \
256 "%s, Device PnP id = %s\n", card->card->name, card_id->id,
257 dev->id->id);
258
259 scc->card_id = card_id->id;
260 scc->dev_id = dev->id->id;
261 sb_dev2cfg(dev, scc);
262
263 printk(KERN_INFO "sb: PnP: Detected at: io=0x%x, irq=%d, " \
264 "dma=%d, dma16=%d\n", scc->conf.io_base, scc->conf.irq,
265 scc->conf.dma, scc->conf.dma2);
266
267 pnp_set_card_drvdata(card, scc);
268 sb_pnp_devices++;
269
270 return sb_register_oss(scc, &sbmo);
271}
272
273static void sb_pnp_remove(struct pnp_card_link *card)
274{
275 struct sb_card_config *scc = pnp_get_card_drvdata(card);
276
277 if(!scc)
278 return;
279
280 printk(KERN_INFO "sb: PnP: Removing %s\n", scc->card_id);
281
282 sb_unload(scc);
283}
284
285static struct pnp_card_driver sb_pnp_driver = {
286 .name = "OSS SndBlstr", /* 16 character limit */
287 .id_table = sb_pnp_card_table,
288 .probe = sb_pnp_probe,
289 .remove = sb_pnp_remove,
290};
291MODULE_DEVICE_TABLE(pnp_card, sb_pnp_card_table);
292#endif /* CONFIG_PNP */
293
294static void sb_unregister_all(void)
295{
296#ifdef CONFIG_PNP
297 if (pnp_registered)
298 pnp_unregister_card_driver(&sb_pnp_driver);
299#endif
300}
301
302static int __init sb_init(void)
303{
304 int lres = 0;
305 int pres = 0;
306
307 printk(KERN_INFO "sb: Init: Starting Probe...\n");
308
309 if(io != -1 && irq != -1 && dma != -1) {
310 printk(KERN_INFO "sb: Probing legacy card with io=%x, "\
311 "irq=%d, dma=%d, dma16=%d\n",io, irq, dma, dma16);
312 lres = sb_init_legacy();
313 } else if((io != -1 || irq != -1 || dma != -1) ||
314 (!pnp && (io == -1 && irq == -1 && dma == -1)))
315 printk(KERN_ERR "sb: Error: At least io, irq, and dma "\
316 "must be set for legacy cards.\n");
317
318#ifdef CONFIG_PNP
319 if(pnp) {
320 int err = pnp_register_card_driver(&sb_pnp_driver);
321 if (!err)
322 pnp_registered = 1;
323 pres = sb_pnp_devices;
324 }
325#endif
326 printk(KERN_INFO "sb: Init: Done\n");
327
328 /* If either PnP or Legacy registered a card then return
329 * success */
330 if (pres == 0 && lres <= 0) {
331 sb_unregister_all();
332 return -ENODEV;
333 }
334 return 0;
335}
336
337static void __exit sb_exit(void)
338{
339 printk(KERN_INFO "sb: Unloading...\n");
340
341 /* Unload legacy card */
342 if (legacy) {
343 printk (KERN_INFO "sb: Unloading legacy card\n");
344 sb_unload(legacy);
345 }
346
347 sb_unregister_all();
348
349 vfree(smw_free);
350 smw_free = NULL;
351}
352
353module_init(sb_init);
354module_exit(sb_exit);
diff --git a/sound/oss/sb_card.h b/sound/oss/sb_card.h
deleted file mode 100644
index 5535cff800df..000000000000
--- a/sound/oss/sb_card.h
+++ /dev/null
@@ -1,149 +0,0 @@
1/*
2 * sound/oss/sb_card.h
3 *
4 * This file is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
5 * Version 2 (June 1991). See the "COPYING" file distributed with this
6 * software for more info.
7 *
8 * 02-05-2002 Original Release, Paul Laufer <paul@laufernet.com>
9 */
10
11struct sb_card_config {
12 struct address_info conf;
13 struct address_info mpucnf;
14 const char *card_id;
15 const char *dev_id;
16 int mpu;
17};
18
19#ifdef CONFIG_PNP
20
21/*
22 * SoundBlaster PnP tables and structures.
23 */
24
25/* Card PnP ID Table */
26static struct pnp_card_device_id sb_pnp_card_table[] = {
27 /* Sound Blaster 16 */
28 {.id = "CTL0024", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
29 /* Sound Blaster 16 */
30 {.id = "CTL0025", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
31 /* Sound Blaster 16 */
32 {.id = "CTL0026", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
33 /* Sound Blaster 16 */
34 {.id = "CTL0027", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
35 /* Sound Blaster 16 */
36 {.id = "CTL0028", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
37 /* Sound Blaster 16 */
38 {.id = "CTL0029", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
39 /* Sound Blaster 16 */
40 {.id = "CTL002a", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
41 /* Sound Blaster 16 */
42 {.id = "CTL002b", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
43 /* Sound Blaster 16 */
44 {.id = "CTL002c", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
45 /* Sound Blaster 16 */
46 {.id = "CTL00ed", .driver_data = 0, .devs = { {.id="CTL0041"}, } },
47 /* Sound Blaster 16 */
48 {.id = "CTL0086", .driver_data = 0, .devs = { {.id="CTL0041"}, } },
49 /* Sound Blaster Vibra16S */
50 {.id = "CTL0051", .driver_data = 0, .devs = { {.id="CTL0001"}, } },
51 /* Sound Blaster Vibra16C */
52 {.id = "CTL0070", .driver_data = 0, .devs = { {.id="CTL0001"}, } },
53 /* Sound Blaster Vibra16CL */
54 {.id = "CTL0080", .driver_data = 0, .devs = { {.id="CTL0041"}, } },
55 /* Sound Blaster Vibra16CL */
56 {.id = "CTL00F0", .driver_data = 0, .devs = { {.id="CTL0043"}, } },
57 /* Sound Blaster AWE 32 */
58 {.id = "CTL0039", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
59 /* Sound Blaster AWE 32 */
60 {.id = "CTL0042", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
61 /* Sound Blaster AWE 32 */
62 {.id = "CTL0043", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
63 /* Sound Blaster AWE 32 */
64 {.id = "CTL0044", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
65 /* Sound Blaster AWE 32 */
66 {.id = "CTL0045", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
67 /* Sound Blaster AWE 32 */
68 {.id = "CTL0046", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
69 /* Sound Blaster AWE 32 */
70 {.id = "CTL0047", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
71 /* Sound Blaster AWE 32 */
72 {.id = "CTL0048", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
73 /* Sound Blaster AWE 32 */
74 {.id = "CTL0054", .driver_data = 0, .devs = { {.id="CTL0031"}, } },
75 /* Sound Blaster AWE 32 */
76 {.id = "CTL009C", .driver_data = 0, .devs = { {.id="CTL0041"}, } },
77 /* Createive SB32 PnP */
78 {.id = "CTL009F", .driver_data = 0, .devs = { {.id="CTL0041"}, } },
79 /* Sound Blaster AWE 64 */
80 {.id = "CTL009D", .driver_data = 0, .devs = { {.id="CTL0042"}, } },
81 /* Sound Blaster AWE 64 Gold */
82 {.id = "CTL009E", .driver_data = 0, .devs = { {.id="CTL0044"}, } },
83 /* Sound Blaster AWE 64 Gold */
84 {.id = "CTL00B2", .driver_data = 0, .devs = { {.id="CTL0044"}, } },
85 /* Sound Blaster AWE 64 */
86 {.id = "CTL00C1", .driver_data = 0, .devs = { {.id="CTL0042"}, } },
87 /* Sound Blaster AWE 64 */
88 {.id = "CTL00C3", .driver_data = 0, .devs = { {.id="CTL0045"}, } },
89 /* Sound Blaster AWE 64 */
90 {.id = "CTL00C5", .driver_data = 0, .devs = { {.id="CTL0045"}, } },
91 /* Sound Blaster AWE 64 */
92 {.id = "CTL00C7", .driver_data = 0, .devs = { {.id="CTL0045"}, } },
93 /* Sound Blaster AWE 64 */
94 {.id = "CTL00E4", .driver_data = 0, .devs = { {.id="CTL0045"}, } },
95 /* Sound Blaster AWE 64 */
96 {.id = "CTL00E9", .driver_data = 0, .devs = { {.id="CTL0045"}, } },
97 /* ESS 1868 */
98 {.id = "ESS0968", .driver_data = 0, .devs = { {.id="ESS0968"}, } },
99 /* ESS 1868 */
100 {.id = "ESS1868", .driver_data = 0, .devs = { {.id="ESS1868"}, } },
101 /* ESS 1868 */
102 {.id = "ESS1868", .driver_data = 0, .devs = { {.id="ESS8611"}, } },
103 /* ESS 1869 PnP AudioDrive */
104 {.id = "ESS0003", .driver_data = 0, .devs = { {.id="ESS1869"}, } },
105 /* ESS 1869 */
106 {.id = "ESS1869", .driver_data = 0, .devs = { {.id="ESS1869"}, } },
107 /* ESS 1878 */
108 {.id = "ESS1878", .driver_data = 0, .devs = { {.id="ESS1878"}, } },
109 /* ESS 1879 */
110 {.id = "ESS1879", .driver_data = 0, .devs = { {.id="ESS1879"}, } },
111 /* CMI 8330 SoundPRO */
112 {.id = "CMI0001", .driver_data = 0, .devs = { {.id="@X@0001"},
113 {.id="@H@0001"},
114 {.id="@@@0001"}, } },
115 /* Diamond DT0197H */
116 {.id = "RWR1688", .driver_data = 0, .devs = { {.id="@@@0001"},
117 {.id="@X@0001"},
118 {.id="@H@0001"}, } },
119 /* ALS007 */
120 {.id = "ALS0007", .driver_data = 0, .devs = { {.id="@@@0001"},
121 {.id="@X@0001"},
122 {.id="@H@0001"}, } },
123 /* ALS100 */
124 {.id = "ALS0001", .driver_data = 0, .devs = { {.id="@@@0001"},
125 {.id="@X@0001"},
126 {.id="@H@0001"}, } },
127 /* ALS110 */
128 {.id = "ALS0110", .driver_data = 0, .devs = { {.id="@@@1001"},
129 {.id="@X@1001"},
130 {.id="@H@0001"}, } },
131 /* ALS120 */
132 {.id = "ALS0120", .driver_data = 0, .devs = { {.id="@@@2001"},
133 {.id="@X@2001"},
134 {.id="@H@0001"}, } },
135 /* ALS200 */
136 {.id = "ALS0200", .driver_data = 0, .devs = { {.id="@@@0020"},
137 {.id="@X@0030"},
138 {.id="@H@0001"}, } },
139 /* ALS200 */
140 {.id = "RTL3000", .driver_data = 0, .devs = { {.id="@@@2001"},
141 {.id="@X@2001"},
142 {.id="@H@0001"}, } },
143 /* Sound Blaster 16 (Virtual PC 2004) */
144 {.id = "tBA03b0", .driver_data = 0, .devs = { {.id="PNPb003"}, } },
145 /* -end- */
146 {.id = "", }
147};
148
149#endif
diff --git a/sound/oss/sb_common.c b/sound/oss/sb_common.c
deleted file mode 100644
index 3d50fb4236ed..000000000000
--- a/sound/oss/sb_common.c
+++ /dev/null
@@ -1,1287 +0,0 @@
1/*
2 * sound/oss/sb_common.c
3 *
4 * Common routines for Sound Blaster compatible cards.
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Daniel J. Rodriksson: Modified sbintr to handle 8 and 16 bit interrupts
15 * for full duplex support ( only sb16 by now )
16 * Rolf Fokkens: Added (BETA?) support for ES1887 chips.
17 * (fokkensr@vertis.nl) Which means: You can adjust the recording levels.
18 *
19 * 2000/01/18 - separated sb_card and sb_common -
20 * Jeff Garzik <jgarzik@pobox.com>
21 *
22 * 2000/09/18 - got rid of attach_uart401
23 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
24 *
25 * 2001/01/26 - replaced CLI/STI with spinlocks
26 * Chris Rankin <rankinc@zipworld.com.au>
27 */
28
29#include <linux/init.h>
30#include <linux/interrupt.h>
31#include <linux/module.h>
32#include <linux/delay.h>
33#include <linux/spinlock.h>
34#include <linux/slab.h>
35
36#include "sound_config.h"
37#include "sound_firmware.h"
38
39#include "mpu401.h"
40
41#include "sb_mixer.h"
42#include "sb.h"
43#include "sb_ess.h"
44
45/*
46 * global module flag
47 */
48
49int sb_be_quiet;
50
51static sb_devc *detected_devc; /* For communication from probe to init */
52static sb_devc *last_devc; /* For MPU401 initialization */
53
54static unsigned char jazz_irq_bits[] = {
55 0, 0, 2, 3, 0, 1, 0, 4, 0, 2, 5, 0, 0, 0, 0, 6
56};
57
58static unsigned char jazz_dma_bits[] = {
59 0, 1, 0, 2, 0, 3, 0, 4
60};
61
62void *smw_free;
63
64/*
65 * Jazz16 chipset specific control variables
66 */
67
68static int jazz16_base; /* Not detected */
69static unsigned char jazz16_bits; /* I/O relocation bits */
70static DEFINE_SPINLOCK(jazz16_lock);
71
72/*
73 * Logitech Soundman Wave specific initialization code
74 */
75
76#ifdef SMW_MIDI0001_INCLUDED
77#include "smw-midi0001.h"
78#else
79static unsigned char *smw_ucode;
80static int smw_ucodeLen;
81
82#endif
83
84static sb_devc *last_sb; /* Last sb loaded */
85
86int sb_dsp_command(sb_devc * devc, unsigned char val)
87{
88 int i;
89 unsigned long limit;
90
91 limit = jiffies + HZ / 10; /* Timeout */
92
93 /*
94 * Note! the i<500000 is an emergency exit. The sb_dsp_command() is sometimes
95 * called while interrupts are disabled. This means that the timer is
96 * disabled also. However the timeout situation is a abnormal condition.
97 * Normally the DSP should be ready to accept commands after just couple of
98 * loops.
99 */
100
101 for (i = 0; i < 500000 && (limit-jiffies)>0; i++)
102 {
103 if ((inb(DSP_STATUS) & 0x80) == 0)
104 {
105 outb((val), DSP_COMMAND);
106 return 1;
107 }
108 }
109 printk(KERN_WARNING "Sound Blaster: DSP command(%x) timeout.\n", val);
110 return 0;
111}
112
113int sb_dsp_get_byte(sb_devc * devc)
114{
115 int i;
116
117 for (i = 1000; i; i--)
118 {
119 if (inb(DSP_DATA_AVAIL) & 0x80)
120 return inb(DSP_READ);
121 }
122 return 0xffff;
123}
124
125static void sb_intr (sb_devc *devc)
126{
127 int status;
128 unsigned char src = 0xff;
129
130 if (devc->model == MDL_SB16)
131 {
132 src = sb_getmixer(devc, IRQ_STAT); /* Interrupt source register */
133
134 if (src & 4) /* MPU401 interrupt */
135 if(devc->midi_irq_cookie)
136 uart401intr(devc->irq, devc->midi_irq_cookie);
137
138 if (!(src & 3))
139 return; /* Not a DSP interrupt */
140 }
141 if (devc->intr_active && (!devc->fullduplex || (src & 0x01)))
142 {
143 switch (devc->irq_mode)
144 {
145 case IMODE_OUTPUT:
146 DMAbuf_outputintr(devc->dev, 1);
147 break;
148
149 case IMODE_INPUT:
150 DMAbuf_inputintr(devc->dev);
151 break;
152
153 case IMODE_INIT:
154 break;
155
156 case IMODE_MIDI:
157 sb_midi_interrupt(devc);
158 break;
159
160 default:
161 /* printk(KERN_WARNING "Sound Blaster: Unexpected interrupt\n"); */
162 ;
163 }
164 }
165 else if (devc->intr_active_16 && (src & 0x02))
166 {
167 switch (devc->irq_mode_16)
168 {
169 case IMODE_OUTPUT:
170 DMAbuf_outputintr(devc->dev, 1);
171 break;
172
173 case IMODE_INPUT:
174 DMAbuf_inputintr(devc->dev);
175 break;
176
177 case IMODE_INIT:
178 break;
179
180 default:
181 /* printk(KERN_WARNING "Sound Blaster: Unexpected interrupt\n"); */
182 ;
183 }
184 }
185 /*
186 * Acknowledge interrupts
187 */
188
189 if (src & 0x01)
190 status = inb(DSP_DATA_AVAIL);
191
192 if (devc->model == MDL_SB16 && src & 0x02)
193 status = inb(DSP_DATA_AVL16);
194}
195
196static void pci_intr(sb_devc *devc)
197{
198 int src = inb(devc->pcibase+0x1A);
199 src&=3;
200 if(src)
201 sb_intr(devc);
202}
203
204static irqreturn_t sbintr(int irq, void *dev_id)
205{
206 sb_devc *devc = dev_id;
207
208 devc->irq_ok = 1;
209
210 switch (devc->model) {
211 case MDL_ESSPCI:
212 pci_intr (devc);
213 break;
214
215 case MDL_ESS:
216 ess_intr (devc);
217 break;
218 default:
219 sb_intr (devc);
220 break;
221 }
222 return IRQ_HANDLED;
223}
224
225int sb_dsp_reset(sb_devc * devc)
226{
227 int loopc;
228
229 if (devc->model == MDL_ESS) return ess_dsp_reset (devc);
230
231 /* This is only for non-ESS chips */
232
233 outb(1, DSP_RESET);
234
235 udelay(10);
236 outb(0, DSP_RESET);
237 udelay(30);
238
239 for (loopc = 0; loopc < 1000 && !(inb(DSP_DATA_AVAIL) & 0x80); loopc++);
240
241 if (inb(DSP_READ) != 0xAA)
242 {
243 DDB(printk("sb: No response to RESET\n"));
244 return 0; /* Sorry */
245 }
246
247 return 1;
248}
249
250static void dsp_get_vers(sb_devc * devc)
251{
252 int i;
253
254 unsigned long flags;
255
256 DDB(printk("Entered dsp_get_vers()\n"));
257 spin_lock_irqsave(&devc->lock, flags);
258 devc->major = devc->minor = 0;
259 sb_dsp_command(devc, 0xe1); /* Get version */
260
261 for (i = 100000; i; i--)
262 {
263 if (inb(DSP_DATA_AVAIL) & 0x80)
264 {
265 if (devc->major == 0)
266 devc->major = inb(DSP_READ);
267 else
268 {
269 devc->minor = inb(DSP_READ);
270 break;
271 }
272 }
273 }
274 spin_unlock_irqrestore(&devc->lock, flags);
275 DDB(printk("DSP version %d.%02d\n", devc->major, devc->minor));
276}
277
278static int sb16_set_dma_hw(sb_devc * devc)
279{
280 int bits;
281
282 if (devc->dma8 != 0 && devc->dma8 != 1 && devc->dma8 != 3)
283 {
284 printk(KERN_ERR "SB16: Invalid 8 bit DMA (%d)\n", devc->dma8);
285 return 0;
286 }
287 bits = (1 << devc->dma8);
288
289 if (devc->dma16 >= 5 && devc->dma16 <= 7)
290 bits |= (1 << devc->dma16);
291
292 sb_setmixer(devc, DMA_NR, bits);
293 return 1;
294}
295
296static void sb16_set_mpu_port(sb_devc * devc, struct address_info *hw_config)
297{
298 /*
299 * This routine initializes new MIDI port setup register of SB Vibra (CT2502).
300 */
301 unsigned char bits = sb_getmixer(devc, 0x84) & ~0x06;
302
303 switch (hw_config->io_base)
304 {
305 case 0x300:
306 sb_setmixer(devc, 0x84, bits | 0x04);
307 break;
308
309 case 0x330:
310 sb_setmixer(devc, 0x84, bits | 0x00);
311 break;
312
313 default:
314 sb_setmixer(devc, 0x84, bits | 0x02); /* Disable MPU */
315 printk(KERN_ERR "SB16: Invalid MIDI I/O port %x\n", hw_config->io_base);
316 }
317}
318
319static int sb16_set_irq_hw(sb_devc * devc, int level)
320{
321 int ival;
322
323 switch (level)
324 {
325 case 5:
326 ival = 2;
327 break;
328 case 7:
329 ival = 4;
330 break;
331 case 9:
332 ival = 1;
333 break;
334 case 10:
335 ival = 8;
336 break;
337 default:
338 printk(KERN_ERR "SB16: Invalid IRQ%d\n", level);
339 return 0;
340 }
341 sb_setmixer(devc, IRQ_NR, ival);
342 return 1;
343}
344
345static void relocate_Jazz16(sb_devc * devc, struct address_info *hw_config)
346{
347 unsigned char bits = 0;
348 unsigned long flags;
349
350 if (jazz16_base != 0 && jazz16_base != hw_config->io_base)
351 return;
352
353 switch (hw_config->io_base)
354 {
355 case 0x220:
356 bits = 1;
357 break;
358 case 0x240:
359 bits = 2;
360 break;
361 case 0x260:
362 bits = 3;
363 break;
364 default:
365 return;
366 }
367 bits = jazz16_bits = bits << 5;
368 jazz16_base = hw_config->io_base;
369
370 /*
371 * Magic wake up sequence by writing to 0x201 (aka Joystick port)
372 */
373 spin_lock_irqsave(&jazz16_lock, flags);
374 outb((0xAF), 0x201);
375 outb((0x50), 0x201);
376 outb((bits), 0x201);
377 spin_unlock_irqrestore(&jazz16_lock, flags);
378}
379
380static int init_Jazz16(sb_devc * devc, struct address_info *hw_config)
381{
382 char name[100];
383 /*
384 * First try to check that the card has Jazz16 chip. It identifies itself
385 * by returning 0x12 as response to DSP command 0xfa.
386 */
387
388 if (!sb_dsp_command(devc, 0xfa))
389 return 0;
390
391 if (sb_dsp_get_byte(devc) != 0x12)
392 return 0;
393
394 /*
395 * OK so far. Now configure the IRQ and DMA channel used by the card.
396 */
397 if (hw_config->irq < 1 || hw_config->irq > 15 || jazz_irq_bits[hw_config->irq] == 0)
398 {
399 printk(KERN_ERR "Jazz16: Invalid interrupt (IRQ%d)\n", hw_config->irq);
400 return 0;
401 }
402 if (hw_config->dma < 0 || hw_config->dma > 3 || jazz_dma_bits[hw_config->dma] == 0)
403 {
404 printk(KERN_ERR "Jazz16: Invalid 8 bit DMA (DMA%d)\n", hw_config->dma);
405 return 0;
406 }
407 if (hw_config->dma2 < 0)
408 {
409 printk(KERN_ERR "Jazz16: No 16 bit DMA channel defined\n");
410 return 0;
411 }
412 if (hw_config->dma2 < 5 || hw_config->dma2 > 7 || jazz_dma_bits[hw_config->dma2] == 0)
413 {
414 printk(KERN_ERR "Jazz16: Invalid 16 bit DMA (DMA%d)\n", hw_config->dma2);
415 return 0;
416 }
417 devc->dma16 = hw_config->dma2;
418
419 if (!sb_dsp_command(devc, 0xfb))
420 return 0;
421
422 if (!sb_dsp_command(devc, jazz_dma_bits[hw_config->dma] |
423 (jazz_dma_bits[hw_config->dma2] << 4)))
424 return 0;
425
426 if (!sb_dsp_command(devc, jazz_irq_bits[hw_config->irq]))
427 return 0;
428
429 /*
430 * Now we have configured a standard Jazz16 device.
431 */
432 devc->model = MDL_JAZZ;
433 strcpy(name, "Jazz16");
434
435 hw_config->name = "Jazz16";
436 devc->caps |= SB_NO_MIDI;
437 return 1;
438}
439
440static void relocate_ess1688(sb_devc * devc)
441{
442 unsigned char bits;
443
444 switch (devc->base)
445 {
446 case 0x220:
447 bits = 0x04;
448 break;
449 case 0x230:
450 bits = 0x05;
451 break;
452 case 0x240:
453 bits = 0x06;
454 break;
455 case 0x250:
456 bits = 0x07;
457 break;
458 default:
459 return; /* Wrong port */
460 }
461
462 DDB(printk("Doing ESS1688 address selection\n"));
463
464 /*
465 * ES1688 supports two alternative ways for software address config.
466 * First try the so called Read-Sequence-Key method.
467 */
468
469 /* Reset the sequence logic */
470 inb(0x229);
471 inb(0x229);
472 inb(0x229);
473
474 /* Perform the read sequence */
475 inb(0x22b);
476 inb(0x229);
477 inb(0x22b);
478 inb(0x229);
479 inb(0x229);
480 inb(0x22b);
481 inb(0x229);
482
483 /* Select the base address by reading from it. Then probe using the port. */
484 inb(devc->base);
485 if (sb_dsp_reset(devc)) /* Bingo */
486 return;
487
488#if 0 /* This causes system lockups (Nokia 386/25 at least) */
489 /*
490 * The last resort is the system control register method.
491 */
492
493 outb((0x00), 0xfb); /* 0xFB is the unlock register */
494 outb((0x00), 0xe0); /* Select index 0 */
495 outb((bits), 0xe1); /* Write the config bits */
496 outb((0x00), 0xf9); /* 0xFB is the lock register */
497#endif
498}
499
500int sb_dsp_detect(struct address_info *hw_config, int pci, int pciio, struct sb_module_options *sbmo)
501{
502 sb_devc sb_info;
503 sb_devc *devc = &sb_info;
504
505 memset((char *) &sb_info, 0, sizeof(sb_info)); /* Zero everything */
506
507 /* Copy module options in place */
508 if(sbmo) memcpy(&devc->sbmo, sbmo, sizeof(struct sb_module_options));
509
510 sb_info.my_mididev = -1;
511 sb_info.my_mixerdev = -1;
512 sb_info.dev = -1;
513
514 /*
515 * Initialize variables
516 */
517
518 DDB(printk("sb_dsp_detect(%x) entered\n", hw_config->io_base));
519
520 spin_lock_init(&devc->lock);
521 devc->type = hw_config->card_subtype;
522
523 devc->base = hw_config->io_base;
524 devc->irq = hw_config->irq;
525 devc->dma8 = hw_config->dma;
526
527 devc->dma16 = -1;
528 devc->pcibase = pciio;
529
530 if(pci == SB_PCI_ESSMAESTRO)
531 {
532 devc->model = MDL_ESSPCI;
533 devc->caps |= SB_PCI_IRQ;
534 hw_config->driver_use_1 |= SB_PCI_IRQ;
535 hw_config->card_subtype = MDL_ESSPCI;
536 }
537
538 if(pci == SB_PCI_YAMAHA)
539 {
540 devc->model = MDL_YMPCI;
541 devc->caps |= SB_PCI_IRQ;
542 hw_config->driver_use_1 |= SB_PCI_IRQ;
543 hw_config->card_subtype = MDL_YMPCI;
544
545 printk("Yamaha PCI mode.\n");
546 }
547
548 if (devc->sbmo.acer)
549 {
550 unsigned long flags;
551
552 spin_lock_irqsave(&devc->lock, flags);
553 inb(devc->base + 0x09);
554 inb(devc->base + 0x09);
555 inb(devc->base + 0x09);
556 inb(devc->base + 0x0b);
557 inb(devc->base + 0x09);
558 inb(devc->base + 0x0b);
559 inb(devc->base + 0x09);
560 inb(devc->base + 0x09);
561 inb(devc->base + 0x0b);
562 inb(devc->base + 0x09);
563 inb(devc->base + 0x00);
564 spin_unlock_irqrestore(&devc->lock, flags);
565 }
566 /*
567 * Detect the device
568 */
569
570 if (sb_dsp_reset(devc))
571 dsp_get_vers(devc);
572 else
573 devc->major = 0;
574
575 if (devc->type == 0 || devc->type == MDL_JAZZ || devc->type == MDL_SMW)
576 if (devc->major == 0 || (devc->major == 3 && devc->minor == 1))
577 relocate_Jazz16(devc, hw_config);
578
579 if (devc->major == 0 && (devc->type == MDL_ESS || devc->type == 0))
580 relocate_ess1688(devc);
581
582 if (!sb_dsp_reset(devc))
583 {
584 DDB(printk("SB reset failed\n"));
585#ifdef MODULE
586 printk(KERN_INFO "sb: dsp reset failed.\n");
587#endif
588 return 0;
589 }
590 if (devc->major == 0)
591 dsp_get_vers(devc);
592
593 if (devc->major == 3 && devc->minor == 1)
594 {
595 if (devc->type == MDL_AZTECH) /* SG Washington? */
596 {
597 if (sb_dsp_command(devc, 0x09))
598 if (sb_dsp_command(devc, 0x00)) /* Enter WSS mode */
599 {
600 int i;
601
602 /* Have some delay */
603 for (i = 0; i < 10000; i++)
604 inb(DSP_DATA_AVAIL);
605 devc->caps = SB_NO_AUDIO | SB_NO_MIDI; /* Mixer only */
606 devc->model = MDL_AZTECH;
607 }
608 }
609 }
610
611 if(devc->type == MDL_ESSPCI)
612 devc->model = MDL_ESSPCI;
613
614 if(devc->type == MDL_YMPCI)
615 {
616 printk("YMPCI selected\n");
617 devc->model = MDL_YMPCI;
618 }
619
620 /*
621 * Save device information for sb_dsp_init()
622 */
623
624
625 detected_devc = kmemdup(devc, sizeof(sb_devc), GFP_KERNEL);
626 if (detected_devc == NULL)
627 {
628 printk(KERN_ERR "sb: Can't allocate memory for device information\n");
629 return 0;
630 }
631 MDB(printk(KERN_INFO "SB %d.%02d detected OK (%x)\n", devc->major, devc->minor, hw_config->io_base));
632 return 1;
633}
634
635int sb_dsp_init(struct address_info *hw_config, struct module *owner)
636{
637 sb_devc *devc;
638 char name[100];
639 extern int sb_be_quiet;
640 int mixer22, mixer30;
641
642/*
643 * Check if we had detected a SB device earlier
644 */
645 DDB(printk("sb_dsp_init(%x) entered\n", hw_config->io_base));
646 name[0] = 0;
647
648 if (detected_devc == NULL)
649 {
650 MDB(printk("No detected device\n"));
651 return 0;
652 }
653 devc = detected_devc;
654 detected_devc = NULL;
655
656 if (devc->base != hw_config->io_base)
657 {
658 DDB(printk("I/O port mismatch\n"));
659 release_region(devc->base, 16);
660 return 0;
661 }
662 /*
663 * Now continue initialization of the device
664 */
665
666 devc->caps = hw_config->driver_use_1;
667
668 if (!((devc->caps & SB_NO_AUDIO) && (devc->caps & SB_NO_MIDI)) && hw_config->irq > 0)
669 { /* IRQ setup */
670
671 /*
672 * ESS PCI cards do shared PCI IRQ stuff. Since they
673 * will get shared PCI irq lines we must cope.
674 */
675
676 int i=(devc->caps&SB_PCI_IRQ)?IRQF_SHARED:0;
677
678 if (request_irq(hw_config->irq, sbintr, i, "soundblaster", devc) < 0)
679 {
680 printk(KERN_ERR "SB: Can't allocate IRQ%d\n", hw_config->irq);
681 release_region(devc->base, 16);
682 return 0;
683 }
684 devc->irq_ok = 0;
685
686 if (devc->major == 4)
687 if (!sb16_set_irq_hw(devc, devc->irq)) /* Unsupported IRQ */
688 {
689 free_irq(devc->irq, devc);
690 release_region(devc->base, 16);
691 return 0;
692 }
693 if ((devc->type == 0 || devc->type == MDL_ESS) &&
694 devc->major == 3 && devc->minor == 1)
695 { /* Handle various chipsets which claim they are SB Pro compatible */
696 if ((devc->type != 0 && devc->type != MDL_ESS) ||
697 !ess_init(devc, hw_config))
698 {
699 if ((devc->type != 0 && devc->type != MDL_JAZZ &&
700 devc->type != MDL_SMW) || !init_Jazz16(devc, hw_config))
701 {
702 DDB(printk("This is a genuine SB Pro\n"));
703 }
704 }
705 }
706 if (devc->major == 4 && devc->minor <= 11 ) /* Won't work */
707 devc->irq_ok = 1;
708 else
709 {
710 int n;
711
712 for (n = 0; n < 3 && devc->irq_ok == 0; n++)
713 {
714 if (sb_dsp_command(devc, 0xf2)) /* Cause interrupt immediately */
715 {
716 int i;
717
718 for (i = 0; !devc->irq_ok && i < 10000; i++);
719 }
720 }
721 if (!devc->irq_ok)
722 printk(KERN_WARNING "sb: Interrupt test on IRQ%d failed - Probable IRQ conflict\n", devc->irq);
723 else
724 {
725 DDB(printk("IRQ test OK (IRQ%d)\n", devc->irq));
726 }
727 }
728 } /* IRQ setup */
729
730 last_sb = devc;
731
732 switch (devc->major)
733 {
734 case 1: /* SB 1.0 or 1.5 */
735 devc->model = hw_config->card_subtype = MDL_SB1;
736 break;
737
738 case 2: /* SB 2.x */
739 if (devc->minor == 0)
740 devc->model = hw_config->card_subtype = MDL_SB2;
741 else
742 devc->model = hw_config->card_subtype = MDL_SB201;
743 break;
744
745 case 3: /* SB Pro and most clones */
746 switch (devc->model) {
747 case 0:
748 devc->model = hw_config->card_subtype = MDL_SBPRO;
749 if (hw_config->name == NULL)
750 hw_config->name = "Sound Blaster Pro (8 BIT ONLY)";
751 break;
752 case MDL_ESS:
753 ess_dsp_init(devc, hw_config);
754 break;
755 }
756 break;
757
758 case 4:
759 devc->model = hw_config->card_subtype = MDL_SB16;
760 /*
761 * ALS007 and ALS100 return DSP version 4.2 and have 2 post-reset !=0
762 * registers at 0x3c and 0x4c (output ctrl registers on ALS007) whereas
763 * a "standard" SB16 doesn't have a register at 0x4c. ALS100 actively
764 * updates register 0x22 whenever 0x30 changes, as per the SB16 spec.
765 * Since ALS007 doesn't, this can be used to differentiate the 2 cards.
766 */
767 if ((devc->minor == 2) && sb_getmixer(devc,0x3c) && sb_getmixer(devc,0x4c))
768 {
769 mixer30 = sb_getmixer(devc,0x30);
770 sb_setmixer(devc,0x22,(mixer22=sb_getmixer(devc,0x22)) & 0x0f);
771 sb_setmixer(devc,0x30,0xff);
772 /* ALS100 will force 0x30 to 0xf8 like SB16; ALS007 will allow 0xff. */
773 /* Register 0x22 & 0xf0 on ALS100 == 0xf0; on ALS007 it == 0x10. */
774 if ((sb_getmixer(devc,0x30) != 0xff) || ((sb_getmixer(devc,0x22) & 0xf0) != 0x10))
775 {
776 devc->submodel = SUBMDL_ALS100;
777 if (hw_config->name == NULL)
778 hw_config->name = "Sound Blaster 16 (ALS-100)";
779 }
780 else
781 {
782 sb_setmixer(devc,0x3c,0x1f); /* Enable all inputs */
783 sb_setmixer(devc,0x4c,0x1f);
784 sb_setmixer(devc,0x22,mixer22); /* Restore 0x22 to original value */
785 devc->submodel = SUBMDL_ALS007;
786 if (hw_config->name == NULL)
787 hw_config->name = "Sound Blaster 16 (ALS-007)";
788 }
789 sb_setmixer(devc,0x30,mixer30);
790 }
791 else if (hw_config->name == NULL)
792 hw_config->name = "Sound Blaster 16";
793
794 if (hw_config->dma2 == -1)
795 devc->dma16 = devc->dma8;
796 else if (hw_config->dma2 < 5 || hw_config->dma2 > 7)
797 {
798 printk(KERN_WARNING "SB16: Bad or missing 16 bit DMA channel\n");
799 devc->dma16 = devc->dma8;
800 }
801 else
802 devc->dma16 = hw_config->dma2;
803
804 if(!sb16_set_dma_hw(devc)) {
805 free_irq(devc->irq, devc);
806 release_region(hw_config->io_base, 16);
807 return 0;
808 }
809
810 devc->caps |= SB_NO_MIDI;
811 }
812
813 if (!(devc->caps & SB_NO_MIXER))
814 if (devc->major == 3 || devc->major == 4)
815 sb_mixer_init(devc, owner);
816
817 if (!(devc->caps & SB_NO_MIDI))
818 sb_dsp_midi_init(devc, owner);
819
820 if (hw_config->name == NULL)
821 hw_config->name = "Sound Blaster (8 BIT/MONO ONLY)";
822
823 sprintf(name, "%s (%d.%02d)", hw_config->name, devc->major, devc->minor);
824 conf_printf(name, hw_config);
825
826 /*
827 * Assuming that a sound card is Sound Blaster (compatible) is the most common
828 * configuration error and the mother of all problems. Usually sound cards
829 * emulate SB Pro but in addition they have a 16 bit native mode which should be
830 * used in Unix. See Readme.cards for more information about configuring OSS/Free
831 * properly.
832 */
833 if (devc->model <= MDL_SBPRO)
834 {
835 if (devc->major == 3 && devc->minor != 1) /* "True" SB Pro should have v3.1 (rare ones may have 3.2). */
836 {
837 printk(KERN_INFO "This sound card may not be fully Sound Blaster Pro compatible.\n");
838 printk(KERN_INFO "In many cases there is another way to configure OSS so that\n");
839 printk(KERN_INFO "it works properly with OSS (for example in 16 bit mode).\n");
840 printk(KERN_INFO "Please ignore this message if you _really_ have a SB Pro.\n");
841 }
842 else if (!sb_be_quiet && devc->model == MDL_SBPRO)
843 {
844 printk(KERN_INFO "SB DSP version is just %d.%02d which means that your card is\n", devc->major, devc->minor);
845 printk(KERN_INFO "several years old (8 bit only device) or alternatively the sound driver\n");
846 printk(KERN_INFO "is incorrectly configured.\n");
847 }
848 }
849 hw_config->card_subtype = devc->model;
850 hw_config->slots[0]=devc->dev;
851 last_devc = devc; /* For SB MPU detection */
852
853 if (!(devc->caps & SB_NO_AUDIO) && devc->dma8 >= 0)
854 {
855 if (sound_alloc_dma(devc->dma8, "SoundBlaster8"))
856 {
857 printk(KERN_WARNING "Sound Blaster: Can't allocate 8 bit DMA channel %d\n", devc->dma8);
858 }
859 if (devc->dma16 >= 0 && devc->dma16 != devc->dma8)
860 {
861 if (sound_alloc_dma(devc->dma16, "SoundBlaster16"))
862 printk(KERN_WARNING "Sound Blaster: can't allocate 16 bit DMA channel %d.\n", devc->dma16);
863 }
864 sb_audio_init(devc, name, owner);
865 hw_config->slots[0]=devc->dev;
866 }
867 else
868 {
869 MDB(printk("Sound Blaster: no audio devices found.\n"));
870 }
871 return 1;
872}
873
874/* if (sbmpu) below we allow mpu401 to manage the midi devs
875 otherwise we have to unload them. (Andrzej Krzysztofowicz) */
876
877void sb_dsp_unload(struct address_info *hw_config, int sbmpu)
878{
879 sb_devc *devc;
880
881 devc = audio_devs[hw_config->slots[0]]->devc;
882
883 if (devc && devc->base == hw_config->io_base)
884 {
885 if ((devc->model & MDL_ESS) && devc->pcibase)
886 release_region(devc->pcibase, 8);
887
888 release_region(devc->base, 16);
889
890 if (!(devc->caps & SB_NO_AUDIO))
891 {
892 sound_free_dma(devc->dma8);
893 if (devc->dma16 >= 0)
894 sound_free_dma(devc->dma16);
895 }
896 if (!(devc->caps & SB_NO_AUDIO && devc->caps & SB_NO_MIDI))
897 {
898 if (devc->irq > 0)
899 free_irq(devc->irq, devc);
900
901 sb_mixer_unload(devc);
902 /* We don't have to do this bit any more the UART401 is its own
903 master -- Krzysztof Halasa */
904 /* But we have to do it, if UART401 is not detected */
905 if (!sbmpu)
906 sound_unload_mididev(devc->my_mididev);
907 sound_unload_audiodev(devc->dev);
908 }
909 kfree(devc);
910 }
911 else
912 release_region(hw_config->io_base, 16);
913
914 kfree(detected_devc);
915}
916
917/*
918 * Mixer access routines
919 *
920 * ES1887 modifications: some mixer registers reside in the
921 * range above 0xa0. These must be accessed in another way.
922 */
923
924void sb_setmixer(sb_devc * devc, unsigned int port, unsigned int value)
925{
926 unsigned long flags;
927
928 if (devc->model == MDL_ESS) {
929 ess_setmixer (devc, port, value);
930 return;
931 }
932
933 spin_lock_irqsave(&devc->lock, flags);
934
935 outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
936 udelay(20);
937 outb(((unsigned char) (value & 0xff)), MIXER_DATA);
938 udelay(20);
939
940 spin_unlock_irqrestore(&devc->lock, flags);
941}
942
943unsigned int sb_getmixer(sb_devc * devc, unsigned int port)
944{
945 unsigned int val;
946 unsigned long flags;
947
948 if (devc->model == MDL_ESS) return ess_getmixer (devc, port);
949
950 spin_lock_irqsave(&devc->lock, flags);
951
952 outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
953 udelay(20);
954 val = inb(MIXER_DATA);
955 udelay(20);
956
957 spin_unlock_irqrestore(&devc->lock, flags);
958
959 return val;
960}
961
962void sb_chgmixer
963 (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val)
964{
965 int value;
966
967 value = sb_getmixer(devc, reg);
968 value = (value & ~mask) | (val & mask);
969 sb_setmixer(devc, reg, value);
970}
971
972/*
973 * MPU401 MIDI initialization.
974 */
975
976static void smw_putmem(sb_devc * devc, int base, int addr, unsigned char val)
977{
978 unsigned long flags;
979
980 spin_lock_irqsave(&jazz16_lock, flags); /* NOT the SB card? */
981
982 outb((addr & 0xff), base + 1); /* Low address bits */
983 outb((addr >> 8), base + 2); /* High address bits */
984 outb((val), base); /* Data */
985
986 spin_unlock_irqrestore(&jazz16_lock, flags);
987}
988
989static unsigned char smw_getmem(sb_devc * devc, int base, int addr)
990{
991 unsigned long flags;
992 unsigned char val;
993
994 spin_lock_irqsave(&jazz16_lock, flags); /* NOT the SB card? */
995
996 outb((addr & 0xff), base + 1); /* Low address bits */
997 outb((addr >> 8), base + 2); /* High address bits */
998 val = inb(base); /* Data */
999
1000 spin_unlock_irqrestore(&jazz16_lock, flags);
1001 return val;
1002}
1003
1004static int smw_midi_init(sb_devc * devc, struct address_info *hw_config)
1005{
1006 int mpu_base = hw_config->io_base;
1007 int mp_base = mpu_base + 4; /* Microcontroller base */
1008 int i;
1009 unsigned char control;
1010
1011
1012 /*
1013 * Reset the microcontroller so that the RAM can be accessed
1014 */
1015
1016 control = inb(mpu_base + 7);
1017 outb((control | 3), mpu_base + 7); /* Set last two bits to 1 (?) */
1018 outb(((control & 0xfe) | 2), mpu_base + 7); /* xxxxxxx0 resets the mc */
1019
1020 mdelay(3); /* Wait at least 1ms */
1021
1022 outb((control & 0xfc), mpu_base + 7); /* xxxxxx00 enables RAM */
1023
1024 /*
1025 * Detect microcontroller by probing the 8k RAM area
1026 */
1027 smw_putmem(devc, mp_base, 0, 0x00);
1028 smw_putmem(devc, mp_base, 1, 0xff);
1029 udelay(10);
1030
1031 if (smw_getmem(devc, mp_base, 0) != 0x00 || smw_getmem(devc, mp_base, 1) != 0xff)
1032 {
1033 DDB(printk("SM Wave: No microcontroller RAM detected (%02x, %02x)\n", smw_getmem(devc, mp_base, 0), smw_getmem(devc, mp_base, 1)));
1034 return 0; /* No RAM */
1035 }
1036 /*
1037 * There is RAM so assume it's really a SM Wave
1038 */
1039
1040 devc->model = MDL_SMW;
1041 smw_mixer_init(devc);
1042
1043#ifdef MODULE
1044 if (!smw_ucode)
1045 {
1046 smw_ucodeLen = mod_firmware_load("/etc/sound/midi0001.bin", (void *) &smw_ucode);
1047 smw_free = smw_ucode;
1048 }
1049#endif
1050 if (smw_ucodeLen > 0)
1051 {
1052 if (smw_ucodeLen != 8192)
1053 {
1054 printk(KERN_ERR "SM Wave: Invalid microcode (MIDI0001.BIN) length\n");
1055 return 1;
1056 }
1057 /*
1058 * Download microcode
1059 */
1060
1061 for (i = 0; i < 8192; i++)
1062 smw_putmem(devc, mp_base, i, smw_ucode[i]);
1063
1064 /*
1065 * Verify microcode
1066 */
1067
1068 for (i = 0; i < 8192; i++)
1069 if (smw_getmem(devc, mp_base, i) != smw_ucode[i])
1070 {
1071 printk(KERN_ERR "SM Wave: Microcode verification failed\n");
1072 return 0;
1073 }
1074 }
1075 control = 0;
1076#ifdef SMW_SCSI_IRQ
1077 /*
1078 * Set the SCSI interrupt (IRQ2/9, IRQ3 or IRQ10). The SCSI interrupt
1079 * is disabled by default.
1080 *
1081 * FIXME - make this a module option
1082 *
1083 * BTW the Zilog 5380 SCSI controller is located at MPU base + 0x10.
1084 */
1085 {
1086 static unsigned char scsi_irq_bits[] = {
1087 0, 0, 3, 1, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0
1088 };
1089 control |= scsi_irq_bits[SMW_SCSI_IRQ] << 6;
1090 }
1091#endif
1092
1093#ifdef SMW_OPL4_ENABLE
1094 /*
1095 * Make the OPL4 chip visible on the PC bus at 0x380.
1096 *
1097 * There is no need to enable this feature since this driver
1098 * doesn't support OPL4 yet. Also there is no RAM in SM Wave so
1099 * enabling OPL4 is pretty useless.
1100 */
1101 control |= 0x10; /* Uses IRQ12 if bit 0x20 == 0 */
1102 /* control |= 0x20; Uncomment this if you want to use IRQ7 */
1103#endif
1104 outb((control | 0x03), mpu_base + 7); /* xxxxxx11 restarts */
1105 hw_config->name = "SoundMan Wave";
1106 return 1;
1107}
1108
1109static int init_Jazz16_midi(sb_devc * devc, struct address_info *hw_config)
1110{
1111 int mpu_base = hw_config->io_base;
1112 int sb_base = devc->base;
1113 int irq = hw_config->irq;
1114
1115 unsigned char bits = 0;
1116 unsigned long flags;
1117
1118 if (irq < 0)
1119 irq *= -1;
1120
1121 if (irq < 1 || irq > 15 ||
1122 jazz_irq_bits[irq] == 0)
1123 {
1124 printk(KERN_ERR "Jazz16: Invalid MIDI interrupt (IRQ%d)\n", irq);
1125 return 0;
1126 }
1127 switch (sb_base)
1128 {
1129 case 0x220:
1130 bits = 1;
1131 break;
1132 case 0x240:
1133 bits = 2;
1134 break;
1135 case 0x260:
1136 bits = 3;
1137 break;
1138 default:
1139 return 0;
1140 }
1141 bits = jazz16_bits = bits << 5;
1142 switch (mpu_base)
1143 {
1144 case 0x310:
1145 bits |= 1;
1146 break;
1147 case 0x320:
1148 bits |= 2;
1149 break;
1150 case 0x330:
1151 bits |= 3;
1152 break;
1153 default:
1154 printk(KERN_ERR "Jazz16: Invalid MIDI I/O port %x\n", mpu_base);
1155 return 0;
1156 }
1157 /*
1158 * Magic wake up sequence by writing to 0x201 (aka Joystick port)
1159 */
1160 spin_lock_irqsave(&jazz16_lock, flags);
1161 outb(0xAF, 0x201);
1162 outb(0x50, 0x201);
1163 outb(bits, 0x201);
1164 spin_unlock_irqrestore(&jazz16_lock, flags);
1165
1166 hw_config->name = "Jazz16";
1167 smw_midi_init(devc, hw_config);
1168
1169 if (!sb_dsp_command(devc, 0xfb))
1170 return 0;
1171
1172 if (!sb_dsp_command(devc, jazz_dma_bits[devc->dma8] |
1173 (jazz_dma_bits[devc->dma16] << 4)))
1174 return 0;
1175
1176 if (!sb_dsp_command(devc, jazz_irq_bits[devc->irq] |
1177 (jazz_irq_bits[irq] << 4)))
1178 return 0;
1179
1180 return 1;
1181}
1182
1183int probe_sbmpu(struct address_info *hw_config, struct module *owner)
1184{
1185 sb_devc *devc = last_devc;
1186 int ret;
1187
1188 if (last_devc == NULL)
1189 return 0;
1190
1191 last_devc = NULL;
1192
1193 if (hw_config->io_base <= 0)
1194 {
1195 /* The real vibra16 is fine about this, but we have to go
1196 wipe up after Cyrix again */
1197
1198 if(devc->model == MDL_SB16 && devc->minor >= 12)
1199 {
1200 unsigned char bits = sb_getmixer(devc, 0x84) & ~0x06;
1201 sb_setmixer(devc, 0x84, bits | 0x02); /* Disable MPU */
1202 }
1203 return 0;
1204 }
1205
1206#if defined(CONFIG_SOUND_MPU401)
1207 if (devc->model == MDL_ESS)
1208 {
1209 struct resource *ports;
1210 ports = request_region(hw_config->io_base, 2, "mpu401");
1211 if (!ports) {
1212 printk(KERN_ERR "sbmpu: I/O port conflict (%x)\n", hw_config->io_base);
1213 return 0;
1214 }
1215 if (!ess_midi_init(devc, hw_config)) {
1216 release_region(hw_config->io_base, 2);
1217 return 0;
1218 }
1219 hw_config->name = "ESS1xxx MPU";
1220 devc->midi_irq_cookie = NULL;
1221 if (!probe_mpu401(hw_config, ports)) {
1222 release_region(hw_config->io_base, 2);
1223 return 0;
1224 }
1225 attach_mpu401(hw_config, owner);
1226 if (last_sb->irq == -hw_config->irq)
1227 last_sb->midi_irq_cookie =
1228 (void *)(long) hw_config->slots[1];
1229 return 1;
1230 }
1231#endif
1232
1233 switch (devc->model)
1234 {
1235 case MDL_SB16:
1236 if (hw_config->io_base != 0x300 && hw_config->io_base != 0x330)
1237 {
1238 printk(KERN_ERR "SB16: Invalid MIDI port %x\n", hw_config->io_base);
1239 return 0;
1240 }
1241 hw_config->name = "Sound Blaster 16";
1242 if (hw_config->irq < 3 || hw_config->irq == devc->irq)
1243 hw_config->irq = -devc->irq;
1244 if (devc->minor > 12) /* What is Vibra's version??? */
1245 sb16_set_mpu_port(devc, hw_config);
1246 break;
1247
1248 case MDL_JAZZ:
1249 if (hw_config->irq < 3 || hw_config->irq == devc->irq)
1250 hw_config->irq = -devc->irq;
1251 if (!init_Jazz16_midi(devc, hw_config))
1252 return 0;
1253 break;
1254
1255 case MDL_YMPCI:
1256 hw_config->name = "Yamaha PCI Legacy";
1257 printk("Yamaha PCI legacy UART401 check.\n");
1258 break;
1259 default:
1260 return 0;
1261 }
1262
1263 ret = probe_uart401(hw_config, owner);
1264 if (ret)
1265 last_sb->midi_irq_cookie=midi_devs[hw_config->slots[4]]->devc;
1266 return ret;
1267}
1268
1269void unload_sbmpu(struct address_info *hw_config)
1270{
1271#if defined(CONFIG_SOUND_MPU401)
1272 if (!strcmp (hw_config->name, "ESS1xxx MPU")) {
1273 unload_mpu401(hw_config);
1274 return;
1275 }
1276#endif
1277 unload_uart401(hw_config);
1278}
1279
1280EXPORT_SYMBOL(sb_dsp_init);
1281EXPORT_SYMBOL(sb_dsp_detect);
1282EXPORT_SYMBOL(sb_dsp_unload);
1283EXPORT_SYMBOL(sb_be_quiet);
1284EXPORT_SYMBOL(probe_sbmpu);
1285EXPORT_SYMBOL(unload_sbmpu);
1286EXPORT_SYMBOL(smw_free);
1287MODULE_LICENSE("GPL");
diff --git a/sound/oss/sb_ess.c b/sound/oss/sb_ess.c
deleted file mode 100644
index 17e3f14318cd..000000000000
--- a/sound/oss/sb_ess.c
+++ /dev/null
@@ -1,1823 +0,0 @@
1// SPDX-License-Identifier: GPL-2.0
2#undef FKS_LOGGING
3#undef FKS_TEST
4
5/*
6 * tabs should be 4 spaces, in vi(m): set tabstop=4
7 *
8 * TODO: consistency speed calculations!!
9 * cleanup!
10 * ????: Did I break MIDI support?
11 *
12 * History:
13 *
14 * Rolf Fokkens (Dec 20 1998): ES188x recording level support on a per
15 * fokkensr@vertis.nl input basis.
16 * (Dec 24 1998): Recognition of ES1788, ES1887, ES1888,
17 * ES1868, ES1869 and ES1878. Could be used for
18 * specific handling in the future. All except
19 * ES1887 and ES1888 and ES688 are handled like
20 * ES1688.
21 * (Dec 27 1998): RECLEV for all (?) ES1688+ chips. ES188x now
22 * have the "Dec 20" support + RECLEV
23 * (Jan 2 1999): Preparation for Full Duplex. This means
24 * Audio 2 is now used for playback when dma16
25 * is specified. The next step would be to use
26 * Audio 1 and Audio 2 at the same time.
27 * (Jan 9 1999): Put all ESS stuff into sb_ess.[ch], this
28 * includes both the ESS stuff that has been in
29 * sb_*[ch] before I touched it and the ESS support
30 * I added later
31 * (Jan 23 1999): Full Duplex seems to work. I wrote a small
32 * test proggy which works OK. Haven't found
33 * any applications to test it though. So why did
34 * I bother to create it anyway?? :) Just for
35 * fun.
36 * (May 2 1999): I tried to be too smart by "introducing"
37 * ess_calc_best_speed (). The idea was that two
38 * dividers could be used to setup a samplerate,
39 * ess_calc_best_speed () would choose the best.
40 * This works for playback, but results in
41 * recording problems for high samplerates. I
42 * fixed this by removing ess_calc_best_speed ()
43 * and just doing what the documentation says.
44 * Andy Sloane (Jun 4 1999): Stole some code from ALSA to fix the playback
45 * andy@guildsoftware.com speed on ES1869, ES1879, ES1887, and ES1888.
46 * 1879's were previously ignored by this driver;
47 * added (untested) support for those.
48 * Cvetan Ivanov (Oct 27 1999): Fixed ess_dsp_init to call ess_set_dma_hw for
49 * zezo@inet.bg _ALL_ ESS models, not only ES1887
50 *
51 * This files contains ESS chip specifics. It's based on the existing ESS
52 * handling as it resided in sb_common.c, sb_mixer.c and sb_audio.c. This
53 * file adds features like:
54 * - Chip Identification (as shown in /proc/sound)
55 * - RECLEV support for ES1688 and later
56 * - 6 bits playback level support chips later than ES1688
57 * - Recording level support on a per-device basis for ES1887
58 * - Full-Duplex for ES1887
59 *
60 * Full duplex is enabled by specifying dma16. While the normal dma must
61 * be one of 0, 1 or 3, dma16 can be one of 0, 1, 3 or 5. DMA 5 is a 16 bit
62 * DMA channel, while the others are 8 bit..
63 *
64 * ESS detection isn't full proof (yet). If it fails an additional module
65 * parameter esstype can be specified to be one of the following:
66 * -1, 0, 688, 1688, 1868, 1869, 1788, 1887, 1888
67 * -1 means: mimic 2.0 behaviour,
68 * 0 means: auto detect.
69 * others: explicitly specify chip
70 * -1 is default, cause auto detect still doesn't work.
71 */
72
73/*
74 * About the documentation
75 *
76 * I don't know if the chips all are OK, but the documentation is buggy. 'cause
77 * I don't have all the cips myself, there's a lot I cannot verify. I'll try to
78 * keep track of my latest insights about his here. If you have additional info,
79 * please enlighten me (fokkensr@vertis.nl)!
80 *
81 * I had the impression that ES1688 also has 6 bit master volume control. The
82 * documentation about ES1888 (rev C, october '95) claims that ES1888 has
83 * the following features ES1688 doesn't have:
84 * - 6 bit master volume
85 * - Full Duplex
86 * So ES1688 apparently doesn't have 6 bit master volume control, but the
87 * ES1688 does have RECLEV control. Makes me wonder: does ES688 have it too?
88 * Without RECLEV ES688 won't be much fun I guess.
89 *
90 * From the ES1888 (rev C, october '95) documentation I got the impression
91 * that registers 0x68 to 0x6e don't exist which means: no recording volume
92 * controls. To my surprise the ES888 documentation (1/14/96) claims that
93 * ES888 does have these record mixer registers, but that ES1888 doesn't have
94 * 0x69 and 0x6b. So the rest should be there.
95 *
96 * I'm trying to get ES1887 Full Duplex. Audio 2 is playback only, while Audio 2
97 * is both record and playback. I think I should use Audio 2 for all playback.
98 *
99 * The documentation is an adventure: it's close but not fully accurate. I
100 * found out that after a reset some registers are *NOT* reset, though the
101 * docs say the would be. Interesting ones are 0x7f, 0x7d and 0x7a. They are
102 * related to the Audio 2 channel. I also was surprised about the consequences
103 * of writing 0x00 to 0x7f (which should be done by reset): The ES1887 moves
104 * into ES1888 mode. This means that it claims IRQ 11, which happens to be my
105 * ISDN adapter. Needless to say it no longer worked. I now understand why
106 * after rebooting 0x7f already was 0x05, the value of my choice: the BIOS
107 * did it.
108 *
109 * Oh, and this is another trap: in ES1887 docs mixer register 0x70 is
110 * described as if it's exactly the same as register 0xa1. This is *NOT* true.
111 * The description of 0x70 in ES1869 docs is accurate however.
112 * Well, the assumption about ES1869 was wrong: register 0x70 is very much
113 * like register 0xa1, except that bit 7 is always 1, whatever you want
114 * it to be.
115 *
116 * When using audio 2 mixer register 0x72 seems te be meaningless. Only 0xa2
117 * has effect.
118 *
119 * Software reset not being able to reset all registers is great! Especially
120 * the fact that register 0x78 isn't reset is great when you wanna change back
121 * to single dma operation (simplex): audio 2 is still operational, and uses
122 * the same dma as audio 1: your ess changes into a funny echo machine.
123 *
124 * Received the news that ES1688 is detected as a ES1788. Did some thinking:
125 * the ES1887 detection scheme suggests in step 2 to try if bit 3 of register
126 * 0x64 can be changed. This is inaccurate, first I inverted the * check: "If
127 * can be modified, it's a 1688", which lead to a correct detection
128 * of my ES1887. It resulted however in bad detection of 1688 (reported by mail)
129 * and 1868 (if no PnP detection first): they result in a 1788 being detected.
130 * I don't have docs on 1688, but I do have docs on 1868: The documentation is
131 * probably inaccurate in the fact that I should check bit 2, not bit 3. This
132 * is what I do now.
133 */
134
135/*
136 * About recognition of ESS chips
137 *
138 * The distinction of ES688, ES1688, ES1788, ES1887 and ES1888 is described in
139 * a (preliminary ??) datasheet on ES1887. Its aim is to identify ES1887, but
140 * during detection the text claims that "this chip may be ..." when a step
141 * fails. This scheme is used to distinct between the above chips.
142 * It appears however that some PnP chips like ES1868 are recognized as ES1788
143 * by the ES1887 detection scheme. These PnP chips can be detected in another
144 * way however: ES1868, ES1869 and ES1878 can be recognized (full proof I think)
145 * by repeatedly reading mixer register 0x40. This is done by ess_identify in
146 * sb_common.c.
147 * This results in the following detection steps:
148 * - distinct between ES688 and ES1688+ (as always done in this driver)
149 * if ES688 we're ready
150 * - try to detect ES1868, ES1869 or ES1878
151 * if successful we're ready
152 * - try to detect ES1888, ES1887 or ES1788
153 * if successful we're ready
154 * - Dunno. Must be 1688. Will do in general
155 *
156 * About RECLEV support:
157 *
158 * The existing ES1688 support didn't take care of the ES1688+ recording
159 * levels very well. Whenever a device was selected (recmask) for recording
160 * its recording level was loud, and it couldn't be changed. The fact that
161 * internal register 0xb4 could take care of RECLEV, didn't work meaning until
162 * its value was restored every time the chip was reset; this reset the
163 * value of 0xb4 too. I guess that's what 4front also had (have?) trouble with.
164 *
165 * About ES1887 support:
166 *
167 * The ES1887 has separate registers to control the recording levels, for all
168 * inputs. The ES1887 specific software makes these levels the same as their
169 * corresponding playback levels, unless recmask says they aren't recorded. In
170 * the latter case the recording volumes are 0.
171 * Now recording levels of inputs can be controlled, by changing the playback
172 * levels. Furthermore several devices can be recorded together (which is not
173 * possible with the ES1688).
174 * Besides the separate recording level control for each input, the common
175 * recording level can also be controlled by RECLEV as described above.
176 *
177 * Not only ES1887 have this recording mixer. I know the following from the
178 * documentation:
179 * ES688 no
180 * ES1688 no
181 * ES1868 no
182 * ES1869 yes
183 * ES1878 no
184 * ES1879 yes
185 * ES1888 no/yes Contradicting documentation; most recent: yes
186 * ES1946 yes This is a PCI chip; not handled by this driver
187 */
188
189#include <linux/delay.h>
190#include <linux/interrupt.h>
191#include <linux/spinlock.h>
192
193#include "sound_config.h"
194#include "sb_mixer.h"
195#include "sb.h"
196
197#include "sb_ess.h"
198
199#define ESSTYPE_LIKE20 -1 /* Mimic 2.0 behaviour */
200#define ESSTYPE_DETECT 0 /* Mimic 2.0 behaviour */
201
202#define SUBMDL_ES1788 0x10 /* Subtype ES1788 for specific handling */
203#define SUBMDL_ES1868 0x11 /* Subtype ES1868 for specific handling */
204#define SUBMDL_ES1869 0x12 /* Subtype ES1869 for specific handling */
205#define SUBMDL_ES1878 0x13 /* Subtype ES1878 for specific handling */
206#define SUBMDL_ES1879 0x16 /* ES1879 was initially forgotten */
207#define SUBMDL_ES1887 0x14 /* Subtype ES1887 for specific handling */
208#define SUBMDL_ES1888 0x15 /* Subtype ES1888 for specific handling */
209
210#define SB_CAP_ES18XX_RATE 0x100
211
212#define ES1688_CLOCK1 795444 /* 128 - div */
213#define ES1688_CLOCK2 397722 /* 256 - div */
214#define ES18XX_CLOCK1 793800 /* 128 - div */
215#define ES18XX_CLOCK2 768000 /* 256 - div */
216
217#ifdef FKS_LOGGING
218static void ess_show_mixerregs (sb_devc *devc);
219#endif
220static int ess_read (sb_devc * devc, unsigned char reg);
221static int ess_write (sb_devc * devc, unsigned char reg, unsigned char data);
222static void ess_chgmixer
223 (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val);
224
225/****************************************************************************
226 * *
227 * ESS audio *
228 * *
229 ****************************************************************************/
230
231struct ess_command {short cmd; short data;};
232
233/*
234 * Commands for initializing Audio 1 for input (record)
235 */
236static struct ess_command ess_i08m[] = /* input 8 bit mono */
237 { {0xb7, 0x51}, {0xb7, 0xd0}, {-1, 0} };
238static struct ess_command ess_i16m[] = /* input 16 bit mono */
239 { {0xb7, 0x71}, {0xb7, 0xf4}, {-1, 0} };
240static struct ess_command ess_i08s[] = /* input 8 bit stereo */
241 { {0xb7, 0x51}, {0xb7, 0x98}, {-1, 0} };
242static struct ess_command ess_i16s[] = /* input 16 bit stereo */
243 { {0xb7, 0x71}, {0xb7, 0xbc}, {-1, 0} };
244
245static struct ess_command *ess_inp_cmds[] =
246 { ess_i08m, ess_i16m, ess_i08s, ess_i16s };
247
248
249/*
250 * Commands for initializing Audio 1 for output (playback)
251 */
252static struct ess_command ess_o08m[] = /* output 8 bit mono */
253 { {0xb6, 0x80}, {0xb7, 0x51}, {0xb7, 0xd0}, {-1, 0} };
254static struct ess_command ess_o16m[] = /* output 16 bit mono */
255 { {0xb6, 0x00}, {0xb7, 0x71}, {0xb7, 0xf4}, {-1, 0} };
256static struct ess_command ess_o08s[] = /* output 8 bit stereo */
257 { {0xb6, 0x80}, {0xb7, 0x51}, {0xb7, 0x98}, {-1, 0} };
258static struct ess_command ess_o16s[] = /* output 16 bit stereo */
259 { {0xb6, 0x00}, {0xb7, 0x71}, {0xb7, 0xbc}, {-1, 0} };
260
261static struct ess_command *ess_out_cmds[] =
262 { ess_o08m, ess_o16m, ess_o08s, ess_o16s };
263
264static void ess_exec_commands
265 (sb_devc *devc, struct ess_command *cmdtab[])
266{
267 struct ess_command *cmd;
268
269 cmd = cmdtab [ ((devc->channels != 1) << 1) + (devc->bits != AFMT_U8) ];
270
271 while (cmd->cmd != -1) {
272 ess_write (devc, cmd->cmd, cmd->data);
273 cmd++;
274 }
275}
276
277static void ess_change
278 (sb_devc *devc, unsigned int reg, unsigned int mask, unsigned int val)
279{
280 int value;
281
282 value = ess_read (devc, reg);
283 value = (value & ~mask) | (val & mask);
284 ess_write (devc, reg, value);
285}
286
287static void ess_set_output_parms
288 (int dev, unsigned long buf, int nr_bytes, int intrflag)
289{
290 sb_devc *devc = audio_devs[dev]->devc;
291
292 if (devc->duplex) {
293 devc->trg_buf_16 = buf;
294 devc->trg_bytes_16 = nr_bytes;
295 devc->trg_intrflag_16 = intrflag;
296 devc->irq_mode_16 = IMODE_OUTPUT;
297 } else {
298 devc->trg_buf = buf;
299 devc->trg_bytes = nr_bytes;
300 devc->trg_intrflag = intrflag;
301 devc->irq_mode = IMODE_OUTPUT;
302 }
303}
304
305static void ess_set_input_parms
306 (int dev, unsigned long buf, int count, int intrflag)
307{
308 sb_devc *devc = audio_devs[dev]->devc;
309
310 devc->trg_buf = buf;
311 devc->trg_bytes = count;
312 devc->trg_intrflag = intrflag;
313 devc->irq_mode = IMODE_INPUT;
314}
315
316static int ess_calc_div (int clock, int revert, int *speedp, int *diffp)
317{
318 int divider;
319 int speed, diff;
320 int retval;
321
322 speed = *speedp;
323 divider = (clock + speed / 2) / speed;
324 retval = revert - divider;
325 if (retval > revert - 1) {
326 retval = revert - 1;
327 divider = revert - retval;
328 }
329 /* This line is suggested. Must be wrong I think
330 *speedp = (clock + divider / 2) / divider;
331 So I chose the next one */
332
333 *speedp = clock / divider;
334 diff = speed - *speedp;
335 if (diff < 0) diff =-diff;
336 *diffp = diff;
337
338 return retval;
339}
340
341static int ess_calc_best_speed
342 (int clock1, int rev1, int clock2, int rev2, int *divp, int *speedp)
343{
344 int speed1 = *speedp, speed2 = *speedp;
345 int div1, div2;
346 int diff1, diff2;
347 int retval;
348
349 div1 = ess_calc_div (clock1, rev1, &speed1, &diff1);
350 div2 = ess_calc_div (clock2, rev2, &speed2, &diff2);
351
352 if (diff1 < diff2) {
353 *divp = div1;
354 *speedp = speed1;
355 retval = 1;
356 } else {
357 /* *divp = div2; */
358 *divp = 0x80 | div2;
359 *speedp = speed2;
360 retval = 2;
361 }
362
363 return retval;
364}
365
366/*
367 * Depending on the audiochannel ESS devices can
368 * have different clock settings. These are made consistent for duplex
369 * however.
370 * callers of ess_speed only do an audionum suggestion, which means
371 * input suggests 1, output suggests 2. This suggestion is only true
372 * however when doing duplex.
373 */
374static void ess_common_speed (sb_devc *devc, int *speedp, int *divp)
375{
376 int diff = 0, div;
377
378 if (devc->duplex) {
379 /*
380 * The 0x80 is important for the first audio channel
381 */
382 if (devc->submodel == SUBMDL_ES1888) {
383 div = 0x80 | ess_calc_div (795500, 256, speedp, &diff);
384 } else {
385 div = 0x80 | ess_calc_div (795500, 128, speedp, &diff);
386 }
387 } else if(devc->caps & SB_CAP_ES18XX_RATE) {
388 if (devc->submodel == SUBMDL_ES1888) {
389 ess_calc_best_speed(397700, 128, 795500, 256,
390 &div, speedp);
391 } else {
392 ess_calc_best_speed(ES18XX_CLOCK1, 128, ES18XX_CLOCK2, 256,
393 &div, speedp);
394 }
395 } else {
396 if (*speedp > 22000) {
397 div = 0x80 | ess_calc_div (ES1688_CLOCK1, 256, speedp, &diff);
398 } else {
399 div = 0x00 | ess_calc_div (ES1688_CLOCK2, 128, speedp, &diff);
400 }
401 }
402 *divp = div;
403}
404
405static void ess_speed (sb_devc *devc, int audionum)
406{
407 int speed;
408 int div, div2;
409
410 ess_common_speed (devc, &(devc->speed), &div);
411
412#ifdef FKS_REG_LOGGING
413printk (KERN_INFO "FKS: ess_speed (%d) b speed = %d, div=%x\n", audionum, devc->speed, div);
414#endif
415
416 /* Set filter roll-off to 90% of speed/2 */
417 speed = (devc->speed * 9) / 20;
418
419 div2 = 256 - 7160000 / (speed * 82);
420
421 if (!devc->duplex) audionum = 1;
422
423 if (audionum == 1) {
424 /* Change behaviour of register A1 *
425 sb_chg_mixer(devc, 0x71, 0x20, 0x20)
426 * For ES1869 only??? */
427 ess_write (devc, 0xa1, div);
428 ess_write (devc, 0xa2, div2);
429 } else {
430 ess_setmixer (devc, 0x70, div);
431 /*
432 * FKS: fascinating: 0x72 doesn't seem to work.
433 */
434 ess_write (devc, 0xa2, div2);
435 ess_setmixer (devc, 0x72, div2);
436 }
437}
438
439static int ess_audio_prepare_for_input(int dev, int bsize, int bcount)
440{
441 sb_devc *devc = audio_devs[dev]->devc;
442
443 ess_speed(devc, 1);
444
445 sb_dsp_command(devc, DSP_CMD_SPKOFF);
446
447 ess_write (devc, 0xb8, 0x0e); /* Auto init DMA mode */
448 ess_change (devc, 0xa8, 0x03, 3 - devc->channels); /* Mono/stereo */
449 ess_write (devc, 0xb9, 2); /* Demand mode (4 bytes/DMA request) */
450
451 ess_exec_commands (devc, ess_inp_cmds);
452
453 ess_change (devc, 0xb1, 0xf0, 0x50);
454 ess_change (devc, 0xb2, 0xf0, 0x50);
455
456 devc->trigger_bits = 0;
457 return 0;
458}
459
460static int ess_audio_prepare_for_output_audio1 (int dev, int bsize, int bcount)
461{
462 sb_devc *devc = audio_devs[dev]->devc;
463
464 sb_dsp_reset(devc);
465 ess_speed(devc, 1);
466 ess_write (devc, 0xb8, 4); /* Auto init DMA mode */
467 ess_change (devc, 0xa8, 0x03, 3 - devc->channels); /* Mono/stereo */
468 ess_write (devc, 0xb9, 2); /* Demand mode (4 bytes/request) */
469
470 ess_exec_commands (devc, ess_out_cmds);
471
472 ess_change (devc, 0xb1, 0xf0, 0x50); /* Enable DMA */
473 ess_change (devc, 0xb2, 0xf0, 0x50); /* Enable IRQ */
474
475 sb_dsp_command(devc, DSP_CMD_SPKON); /* There be sound! */
476
477 devc->trigger_bits = 0;
478 return 0;
479}
480
481static int ess_audio_prepare_for_output_audio2 (int dev, int bsize, int bcount)
482{
483 sb_devc *devc = audio_devs[dev]->devc;
484 unsigned char bits;
485
486/* FKS: qqq
487 sb_dsp_reset(devc);
488*/
489
490 /*
491 * Auto-Initialize:
492 * DMA mode + demand mode (8 bytes/request, yes I want it all!)
493 * But leave 16-bit DMA bit untouched!
494 */
495 ess_chgmixer (devc, 0x78, 0xd0, 0xd0);
496
497 ess_speed(devc, 2);
498
499 /* bits 4:3 on ES1887 represent recording source. Keep them! */
500 bits = ess_getmixer (devc, 0x7a) & 0x18;
501
502 /* Set stereo/mono */
503 if (devc->channels != 1) bits |= 0x02;
504
505 /* Init DACs; UNSIGNED mode for 8 bit; SIGNED mode for 16 bit */
506 if (devc->bits != AFMT_U8) bits |= 0x05; /* 16 bit */
507
508 /* Enable DMA, IRQ will be shared (hopefully)*/
509 bits |= 0x60;
510
511 ess_setmixer (devc, 0x7a, bits);
512
513 ess_mixer_reload (devc, SOUND_MIXER_PCM); /* There be sound! */
514
515 devc->trigger_bits = 0;
516 return 0;
517}
518
519static int ess_audio_prepare_for_output(int dev, int bsize, int bcount)
520{
521 sb_devc *devc = audio_devs[dev]->devc;
522
523#ifdef FKS_REG_LOGGING
524printk(KERN_INFO "ess_audio_prepare_for_output: dma_out=%d,dma_in=%d\n"
525, audio_devs[dev]->dmap_out->dma, audio_devs[dev]->dmap_in->dma);
526#endif
527
528 if (devc->duplex) {
529 return ess_audio_prepare_for_output_audio2 (dev, bsize, bcount);
530 } else {
531 return ess_audio_prepare_for_output_audio1 (dev, bsize, bcount);
532 }
533}
534
535static void ess_audio_halt_xfer(int dev)
536{
537 unsigned long flags;
538 sb_devc *devc = audio_devs[dev]->devc;
539
540 spin_lock_irqsave(&devc->lock, flags);
541 sb_dsp_reset(devc);
542 spin_unlock_irqrestore(&devc->lock, flags);
543
544 /*
545 * Audio 2 may still be operational! Creates awful sounds!
546 */
547 if (devc->duplex) ess_chgmixer(devc, 0x78, 0x03, 0x00);
548}
549
550static void ess_audio_start_input
551 (int dev, unsigned long buf, int nr_bytes, int intrflag)
552{
553 int count = nr_bytes;
554 sb_devc *devc = audio_devs[dev]->devc;
555 short c = -nr_bytes;
556
557 /*
558 * Start a DMA input to the buffer pointed by dmaqtail
559 */
560
561 if (audio_devs[dev]->dmap_in->dma > 3) count >>= 1;
562 count--;
563
564 devc->irq_mode = IMODE_INPUT;
565
566 ess_write (devc, 0xa4, (unsigned char) ((unsigned short) c & 0xff));
567 ess_write (devc, 0xa5, (unsigned char) (((unsigned short) c >> 8) & 0xff));
568
569 ess_change (devc, 0xb8, 0x0f, 0x0f); /* Go */
570 devc->intr_active = 1;
571}
572
573static void ess_audio_output_block_audio1
574 (int dev, unsigned long buf, int nr_bytes, int intrflag)
575{
576 int count = nr_bytes;
577 sb_devc *devc = audio_devs[dev]->devc;
578 short c = -nr_bytes;
579
580 if (audio_devs[dev]->dmap_out->dma > 3)
581 count >>= 1;
582 count--;
583
584 devc->irq_mode = IMODE_OUTPUT;
585
586 ess_write (devc, 0xa4, (unsigned char) ((unsigned short) c & 0xff));
587 ess_write (devc, 0xa5, (unsigned char) (((unsigned short) c >> 8) & 0xff));
588
589 ess_change (devc, 0xb8, 0x05, 0x05); /* Go */
590 devc->intr_active = 1;
591}
592
593static void ess_audio_output_block_audio2
594 (int dev, unsigned long buf, int nr_bytes, int intrflag)
595{
596 int count = nr_bytes;
597 sb_devc *devc = audio_devs[dev]->devc;
598 short c = -nr_bytes;
599
600 if (audio_devs[dev]->dmap_out->dma > 3) count >>= 1;
601 count--;
602
603 ess_setmixer (devc, 0x74, (unsigned char) ((unsigned short) c & 0xff));
604 ess_setmixer (devc, 0x76, (unsigned char) (((unsigned short) c >> 8) & 0xff));
605 ess_chgmixer (devc, 0x78, 0x03, 0x03); /* Go */
606
607 devc->irq_mode_16 = IMODE_OUTPUT;
608 devc->intr_active_16 = 1;
609}
610
611static void ess_audio_output_block
612 (int dev, unsigned long buf, int nr_bytes, int intrflag)
613{
614 sb_devc *devc = audio_devs[dev]->devc;
615
616 if (devc->duplex) {
617 ess_audio_output_block_audio2 (dev, buf, nr_bytes, intrflag);
618 } else {
619 ess_audio_output_block_audio1 (dev, buf, nr_bytes, intrflag);
620 }
621}
622
623/*
624 * FKS: the if-statements for both bits and bits_16 are quite alike.
625 * Combine this...
626 */
627static void ess_audio_trigger(int dev, int bits)
628{
629 sb_devc *devc = audio_devs[dev]->devc;
630
631 int bits_16 = bits & devc->irq_mode_16;
632 bits &= devc->irq_mode;
633
634 if (!bits && !bits_16) {
635 /* FKS oh oh.... wrong?? for dma 16? */
636 sb_dsp_command(devc, 0xd0); /* Halt DMA */
637 }
638
639 if (bits) {
640 switch (devc->irq_mode)
641 {
642 case IMODE_INPUT:
643 ess_audio_start_input(dev, devc->trg_buf, devc->trg_bytes,
644 devc->trg_intrflag);
645 break;
646
647 case IMODE_OUTPUT:
648 ess_audio_output_block(dev, devc->trg_buf, devc->trg_bytes,
649 devc->trg_intrflag);
650 break;
651 }
652 }
653
654 if (bits_16) {
655 switch (devc->irq_mode_16) {
656 case IMODE_INPUT:
657 ess_audio_start_input(dev, devc->trg_buf_16, devc->trg_bytes_16,
658 devc->trg_intrflag_16);
659 break;
660
661 case IMODE_OUTPUT:
662 ess_audio_output_block(dev, devc->trg_buf_16, devc->trg_bytes_16,
663 devc->trg_intrflag_16);
664 break;
665 }
666 }
667
668 devc->trigger_bits = bits | bits_16;
669}
670
671static int ess_audio_set_speed(int dev, int speed)
672{
673 sb_devc *devc = audio_devs[dev]->devc;
674 int minspeed, maxspeed, dummydiv;
675
676 if (speed > 0) {
677 minspeed = (devc->duplex ? 6215 : 5000 );
678 maxspeed = (devc->duplex ? 44100 : 48000);
679 if (speed < minspeed) speed = minspeed;
680 if (speed > maxspeed) speed = maxspeed;
681
682 ess_common_speed (devc, &speed, &dummydiv);
683
684 devc->speed = speed;
685 }
686 return devc->speed;
687}
688
689/*
690 * FKS: This is a one-on-one copy of sb1_audio_set_bits
691 */
692static unsigned int ess_audio_set_bits(int dev, unsigned int bits)
693{
694 sb_devc *devc = audio_devs[dev]->devc;
695
696 if (bits != 0) {
697 if (bits == AFMT_U8 || bits == AFMT_S16_LE) {
698 devc->bits = bits;
699 } else {
700 devc->bits = AFMT_U8;
701 }
702 }
703
704 return devc->bits;
705}
706
707/*
708 * FKS: This is a one-on-one copy of sbpro_audio_set_channels
709 * (*) Modified it!!
710 */
711static short ess_audio_set_channels(int dev, short channels)
712{
713 sb_devc *devc = audio_devs[dev]->devc;
714
715 if (channels == 1 || channels == 2) devc->channels = channels;
716
717 return devc->channels;
718}
719
720static struct audio_driver ess_audio_driver = /* ESS ES688/1688 */
721{
722 .owner = THIS_MODULE,
723 .open = sb_audio_open,
724 .close = sb_audio_close,
725 .output_block = ess_set_output_parms,
726 .start_input = ess_set_input_parms,
727 .prepare_for_input = ess_audio_prepare_for_input,
728 .prepare_for_output = ess_audio_prepare_for_output,
729 .halt_io = ess_audio_halt_xfer,
730 .trigger = ess_audio_trigger,
731 .set_speed = ess_audio_set_speed,
732 .set_bits = ess_audio_set_bits,
733 .set_channels = ess_audio_set_channels
734};
735
736/*
737 * ess_audio_init must be called from sb_audio_init
738 */
739struct audio_driver *ess_audio_init
740 (sb_devc *devc, int *audio_flags, int *format_mask)
741{
742 *audio_flags = DMA_AUTOMODE;
743 *format_mask |= AFMT_S16_LE;
744
745 if (devc->duplex) {
746 int tmp_dma;
747 /*
748 * sb_audio_init thinks dma8 is for playback and
749 * dma16 is for record. Not now! So swap them.
750 */
751 tmp_dma = devc->dma16;
752 devc->dma16 = devc->dma8;
753 devc->dma8 = tmp_dma;
754
755 *audio_flags |= DMA_DUPLEX;
756 }
757
758 return &ess_audio_driver;
759}
760
761/****************************************************************************
762 * *
763 * ESS common *
764 * *
765 ****************************************************************************/
766static void ess_handle_channel
767 (char *channel, int dev, int intr_active, unsigned char flag, int irq_mode)
768{
769 if (!intr_active || !flag) return;
770#ifdef FKS_REG_LOGGING
771printk(KERN_INFO "FKS: ess_handle_channel %s irq_mode=%d\n", channel, irq_mode);
772#endif
773 switch (irq_mode) {
774 case IMODE_OUTPUT:
775 DMAbuf_outputintr (dev, 1);
776 break;
777
778 case IMODE_INPUT:
779 DMAbuf_inputintr (dev);
780 break;
781
782 case IMODE_INIT:
783 break;
784
785 default:;
786 /* printk(KERN_WARNING "ESS: Unexpected interrupt\n"); */
787 }
788}
789
790/*
791 * FKS: TODO!!! Finish this!
792 *
793 * I think midi stuff uses uart401, without interrupts.
794 * So IMODE_MIDI isn't a value for devc->irq_mode.
795 */
796void ess_intr (sb_devc *devc)
797{
798 int status;
799 unsigned char src;
800
801 if (devc->submodel == SUBMDL_ES1887) {
802 src = ess_getmixer (devc, 0x7f) >> 4;
803 } else {
804 src = 0xff;
805 }
806
807#ifdef FKS_REG_LOGGING
808printk(KERN_INFO "FKS: sbintr src=%x\n",(int)src);
809#endif
810 ess_handle_channel
811 ( "Audio 1"
812 , devc->dev, devc->intr_active , src & 0x01, devc->irq_mode );
813 ess_handle_channel
814 ( "Audio 2"
815 , devc->dev, devc->intr_active_16, src & 0x02, devc->irq_mode_16);
816 /*
817 * Acknowledge interrupts
818 */
819 if (devc->submodel == SUBMDL_ES1887 && (src & 0x02)) {
820 ess_chgmixer (devc, 0x7a, 0x80, 0x00);
821 }
822
823 if (src & 0x01) {
824 status = inb(DSP_DATA_AVAIL);
825 }
826}
827
828static void ess_extended (sb_devc * devc)
829{
830 /* Enable extended mode */
831
832 sb_dsp_command(devc, 0xc6);
833}
834
835static int ess_write (sb_devc * devc, unsigned char reg, unsigned char data)
836{
837#ifdef FKS_REG_LOGGING
838printk(KERN_INFO "FKS: write reg %x: %x\n", reg, data);
839#endif
840 /* Write a byte to an extended mode register of ES1688 */
841
842 if (!sb_dsp_command(devc, reg))
843 return 0;
844
845 return sb_dsp_command(devc, data);
846}
847
848static int ess_read (sb_devc * devc, unsigned char reg)
849{
850 /* Read a byte from an extended mode register of ES1688 */
851
852 /* Read register command */
853 if (!sb_dsp_command(devc, 0xc0)) return -1;
854
855 if (!sb_dsp_command(devc, reg )) return -1;
856
857 return sb_dsp_get_byte(devc);
858}
859
860int ess_dsp_reset(sb_devc * devc)
861{
862 int loopc;
863
864#ifdef FKS_REG_LOGGING
865printk(KERN_INFO "FKS: ess_dsp_reset 1\n");
866ess_show_mixerregs (devc);
867#endif
868
869 outb(3, DSP_RESET); /* Reset FIFO too */
870
871 udelay(10);
872 outb(0, DSP_RESET);
873 udelay(30);
874
875 for (loopc = 0; loopc < 1000 && !(inb(DSP_DATA_AVAIL) & 0x80); loopc++);
876
877 if (inb(DSP_READ) != 0xAA) {
878 DDB(printk("sb: No response to RESET\n"));
879 return 0; /* Sorry */
880 }
881 ess_extended (devc);
882
883#ifdef FKS_LOGGING
884printk(KERN_INFO "FKS: dsp_reset 2\n");
885ess_show_mixerregs (devc);
886#endif
887
888 return 1;
889}
890
891static int ess_irq_bits (int irq)
892{
893 switch (irq) {
894 case 2:
895 case 9:
896 return 0;
897
898 case 5:
899 return 1;
900
901 case 7:
902 return 2;
903
904 case 10:
905 return 3;
906
907 default:
908 printk(KERN_ERR "ESS1688: Invalid IRQ %d\n", irq);
909 return -1;
910 }
911}
912
913/*
914 * Set IRQ configuration register for all ESS models
915 */
916static int ess_common_set_irq_hw (sb_devc * devc)
917{
918 int irq_bits;
919
920 if ((irq_bits = ess_irq_bits (devc->irq)) == -1) return 0;
921
922 if (!ess_write (devc, 0xb1, 0x50 | (irq_bits << 2))) {
923 printk(KERN_ERR "ES1688: Failed to write to IRQ config register\n");
924 return 0;
925 }
926 return 1;
927}
928
929/*
930 * I wanna use modern ES1887 mixer irq handling. Funny is the
931 * fact that my BIOS wants the same. But suppose someone's BIOS
932 * doesn't do this!
933 * This is independent of duplex. If there's a 1887 this will
934 * prevent it from going into 1888 mode.
935 */
936static void ess_es1887_set_irq_hw (sb_devc * devc)
937{
938 int irq_bits;
939
940 if ((irq_bits = ess_irq_bits (devc->irq)) == -1) return;
941
942 ess_chgmixer (devc, 0x7f, 0x0f, 0x01 | ((irq_bits + 1) << 1));
943}
944
945static int ess_set_irq_hw (sb_devc * devc)
946{
947 if (devc->submodel == SUBMDL_ES1887) ess_es1887_set_irq_hw (devc);
948
949 return ess_common_set_irq_hw (devc);
950}
951
952#ifdef FKS_TEST
953
954/*
955 * FKS_test:
956 * for ES1887: 00, 18, non wr bits: 0001 1000
957 * for ES1868: 00, b8, non wr bits: 1011 1000
958 * for ES1888: 00, f8, non wr bits: 1111 1000
959 * for ES1688: 00, f8, non wr bits: 1111 1000
960 * + ES968
961 */
962
963static void FKS_test (sb_devc * devc)
964{
965 int val1, val2;
966 val1 = ess_getmixer (devc, 0x64);
967 ess_setmixer (devc, 0x64, ~val1);
968 val2 = ess_getmixer (devc, 0x64) ^ ~val1;
969 ess_setmixer (devc, 0x64, val1);
970 val1 ^= ess_getmixer (devc, 0x64);
971printk (KERN_INFO "FKS: FKS_test %02x, %02x\n", (val1 & 0x0ff), (val2 & 0x0ff));
972};
973#endif
974
975static unsigned int ess_identify (sb_devc * devc)
976{
977 unsigned int val;
978 unsigned long flags;
979
980 spin_lock_irqsave(&devc->lock, flags);
981 outb(((unsigned char) (0x40 & 0xff)), MIXER_ADDR);
982
983 udelay(20);
984 val = inb(MIXER_DATA) << 8;
985 udelay(20);
986 val |= inb(MIXER_DATA);
987 udelay(20);
988 spin_unlock_irqrestore(&devc->lock, flags);
989
990 return val;
991}
992
993/*
994 * ESS technology describes a detection scheme in their docs. It involves
995 * fiddling with the bits in certain mixer registers. ess_probe is supposed
996 * to help.
997 *
998 * FKS: tracing shows ess_probe writes wrong value to 0x64. Bit 3 reads 1, but
999 * should be written 0 only. Check this.
1000 */
1001static int ess_probe (sb_devc * devc, int reg, int xorval)
1002{
1003 int val1, val2, val3;
1004
1005 val1 = ess_getmixer (devc, reg);
1006 val2 = val1 ^ xorval;
1007 ess_setmixer (devc, reg, val2);
1008 val3 = ess_getmixer (devc, reg);
1009 ess_setmixer (devc, reg, val1);
1010
1011 return (val2 == val3);
1012}
1013
1014int ess_init(sb_devc * devc, struct address_info *hw_config)
1015{
1016 unsigned char cfg;
1017 int ess_major = 0, ess_minor = 0;
1018 int i;
1019 static char name[100], modelname[10];
1020
1021 /*
1022 * Try to detect ESS chips.
1023 */
1024
1025 sb_dsp_command(devc, 0xe7); /* Return identification */
1026
1027 for (i = 1000; i; i--) {
1028 if (inb(DSP_DATA_AVAIL) & 0x80) {
1029 if (ess_major == 0) {
1030 ess_major = inb(DSP_READ);
1031 } else {
1032 ess_minor = inb(DSP_READ);
1033 break;
1034 }
1035 }
1036 }
1037
1038 if (ess_major == 0) return 0;
1039
1040 if (ess_major == 0x48 && (ess_minor & 0xf0) == 0x80) {
1041 sprintf(name, "ESS ES488 AudioDrive (rev %d)",
1042 ess_minor & 0x0f);
1043 hw_config->name = name;
1044 devc->model = MDL_SBPRO;
1045 return 1;
1046 }
1047
1048 /*
1049 * This the detection heuristic of ESS technology, though somewhat
1050 * changed to actually make it work.
1051 * This results in the following detection steps:
1052 * - distinct between ES688 and ES1688+ (as always done in this driver)
1053 * if ES688 we're ready
1054 * - try to detect ES1868, ES1869 or ES1878 (ess_identify)
1055 * if successful we're ready
1056 * - try to detect ES1888, ES1887 or ES1788 (aim: detect ES1887)
1057 * if successful we're ready
1058 * - Dunno. Must be 1688. Will do in general
1059 *
1060 * This is the most BETA part of the software: Will the detection
1061 * always work?
1062 */
1063 devc->model = MDL_ESS;
1064 devc->submodel = ess_minor & 0x0f;
1065
1066 if (ess_major == 0x68 && (ess_minor & 0xf0) == 0x80) {
1067 char *chip = NULL;
1068 int submodel = -1;
1069
1070 switch (devc->sbmo.esstype) {
1071 case ESSTYPE_DETECT:
1072 case ESSTYPE_LIKE20:
1073 break;
1074 case 688:
1075 submodel = 0x00;
1076 break;
1077 case 1688:
1078 submodel = 0x08;
1079 break;
1080 case 1868:
1081 submodel = SUBMDL_ES1868;
1082 break;
1083 case 1869:
1084 submodel = SUBMDL_ES1869;
1085 break;
1086 case 1788:
1087 submodel = SUBMDL_ES1788;
1088 break;
1089 case 1878:
1090 submodel = SUBMDL_ES1878;
1091 break;
1092 case 1879:
1093 submodel = SUBMDL_ES1879;
1094 break;
1095 case 1887:
1096 submodel = SUBMDL_ES1887;
1097 break;
1098 case 1888:
1099 submodel = SUBMDL_ES1888;
1100 break;
1101 default:
1102 printk (KERN_ERR "Invalid esstype=%d specified\n", devc->sbmo.esstype);
1103 return 0;
1104 }
1105 if (submodel != -1) {
1106 devc->submodel = submodel;
1107 sprintf (modelname, "ES%d", devc->sbmo.esstype);
1108 chip = modelname;
1109 }
1110 if (chip == NULL && (ess_minor & 0x0f) < 8) {
1111 chip = "ES688";
1112 }
1113#ifdef FKS_TEST
1114FKS_test (devc);
1115#endif
1116 /*
1117 * If Nothing detected yet, and we want 2.0 behaviour...
1118 * Then let's assume it's ES1688.
1119 */
1120 if (chip == NULL && devc->sbmo.esstype == ESSTYPE_LIKE20) {
1121 chip = "ES1688";
1122 }
1123
1124 if (chip == NULL) {
1125 int type;
1126
1127 type = ess_identify (devc);
1128
1129 switch (type) {
1130 case 0x1868:
1131 chip = "ES1868";
1132 devc->submodel = SUBMDL_ES1868;
1133 break;
1134 case 0x1869:
1135 chip = "ES1869";
1136 devc->submodel = SUBMDL_ES1869;
1137 break;
1138 case 0x1878:
1139 chip = "ES1878";
1140 devc->submodel = SUBMDL_ES1878;
1141 break;
1142 case 0x1879:
1143 chip = "ES1879";
1144 devc->submodel = SUBMDL_ES1879;
1145 break;
1146 default:
1147 if ((type & 0x00ff) != ((type >> 8) & 0x00ff)) {
1148 printk ("ess_init: Unrecognized %04x\n", type);
1149 }
1150 }
1151 }
1152#if 0
1153 /*
1154 * this one failed:
1155 * the probing of bit 4 is another thought: from ES1788 and up, all
1156 * chips seem to have hardware volume control. Bit 4 is readonly to
1157 * check if a hardware volume interrupt has fired.
1158 * Cause ES688/ES1688 don't have this feature, bit 4 might be writeable
1159 * for these chips.
1160 */
1161 if (chip == NULL && !ess_probe(devc, 0x64, (1 << 4))) {
1162#endif
1163 /*
1164 * the probing of bit 2 is my idea. The ES1887 docs want me to probe
1165 * bit 3. This results in ES1688 being detected as ES1788.
1166 * Bit 2 is for "Enable HWV IRQE", but as ES(1)688 chips don't have
1167 * HardWare Volume, I think they don't have this IRQE.
1168 */
1169 if (chip == NULL && ess_probe(devc, 0x64, (1 << 2))) {
1170 if (ess_probe (devc, 0x70, 0x7f)) {
1171 if (ess_probe (devc, 0x64, (1 << 5))) {
1172 chip = "ES1887";
1173 devc->submodel = SUBMDL_ES1887;
1174 } else {
1175 chip = "ES1888";
1176 devc->submodel = SUBMDL_ES1888;
1177 }
1178 } else {
1179 chip = "ES1788";
1180 devc->submodel = SUBMDL_ES1788;
1181 }
1182 }
1183 if (chip == NULL) {
1184 chip = "ES1688";
1185 }
1186
1187 printk(KERN_INFO "ESS chip %s %s%s\n", chip,
1188 (devc->sbmo.esstype == ESSTYPE_DETECT ||
1189 devc->sbmo.esstype == ESSTYPE_LIKE20) ?
1190 "detected" : "specified",
1191 devc->sbmo.esstype == ESSTYPE_LIKE20 ?
1192 " (kernel 2.0 compatible)" : "");
1193
1194 sprintf(name,"ESS %s AudioDrive (rev %d)", chip, ess_minor & 0x0f);
1195 } else {
1196 strcpy(name, "Jazz16");
1197 }
1198
1199 /* AAS: info stolen from ALSA: these boards have different clocks */
1200 switch(devc->submodel) {
1201/* APPARENTLY NOT 1869 AND 1887
1202 case SUBMDL_ES1869:
1203 case SUBMDL_ES1887:
1204*/
1205 case SUBMDL_ES1888:
1206 devc->caps |= SB_CAP_ES18XX_RATE;
1207 break;
1208 }
1209
1210 hw_config->name = name;
1211 /* FKS: sb_dsp_reset to enable extended mode???? */
1212 sb_dsp_reset(devc); /* Turn on extended mode */
1213
1214 /*
1215 * Enable joystick and OPL3
1216 */
1217 cfg = ess_getmixer (devc, 0x40);
1218 ess_setmixer (devc, 0x40, cfg | 0x03);
1219 if (devc->submodel >= 8) { /* ES1688 */
1220 devc->caps |= SB_NO_MIDI; /* ES1688 uses MPU401 MIDI mode */
1221 }
1222 sb_dsp_reset (devc);
1223
1224 /*
1225 * This is important! If it's not done, the IRQ probe in sb_dsp_init
1226 * may fail.
1227 */
1228 return ess_set_irq_hw (devc);
1229}
1230
1231static int ess_set_dma_hw(sb_devc * devc)
1232{
1233 unsigned char cfg, dma_bits = 0, dma16_bits;
1234 int dma;
1235
1236#ifdef FKS_LOGGING
1237printk(KERN_INFO "ess_set_dma_hw: dma8=%d,dma16=%d,dup=%d\n"
1238, devc->dma8, devc->dma16, devc->duplex);
1239#endif
1240
1241 /*
1242 * FKS: It seems as if this duplex flag isn't set yet. Check it.
1243 */
1244 dma = devc->dma8;
1245
1246 if (dma > 3 || dma < 0 || dma == 2) {
1247 dma_bits = 0;
1248 printk(KERN_ERR "ESS1688: Invalid DMA8 %d\n", dma);
1249 return 0;
1250 } else {
1251 /* Extended mode DMA enable */
1252 cfg = 0x50;
1253
1254 if (dma == 3) {
1255 dma_bits = 3;
1256 } else {
1257 dma_bits = dma + 1;
1258 }
1259 }
1260
1261 if (!ess_write (devc, 0xb2, cfg | (dma_bits << 2))) {
1262 printk(KERN_ERR "ESS1688: Failed to write to DMA config register\n");
1263 return 0;
1264 }
1265
1266 if (devc->duplex) {
1267 dma = devc->dma16;
1268 dma16_bits = 0;
1269
1270 if (dma >= 0) {
1271 switch (dma) {
1272 case 0:
1273 dma_bits = 0x04;
1274 break;
1275 case 1:
1276 dma_bits = 0x05;
1277 break;
1278 case 3:
1279 dma_bits = 0x06;
1280 break;
1281 case 5:
1282 dma_bits = 0x07;
1283 dma16_bits = 0x20;
1284 break;
1285 default:
1286 printk(KERN_ERR "ESS1887: Invalid DMA16 %d\n", dma);
1287 return 0;
1288 }
1289 ess_chgmixer (devc, 0x78, 0x20, dma16_bits);
1290 ess_chgmixer (devc, 0x7d, 0x07, dma_bits);
1291 }
1292 }
1293 return 1;
1294}
1295
1296/*
1297 * This one is called from sb_dsp_init.
1298 *
1299 * Return values:
1300 * 0: Failed
1301 * 1: Succeeded or doesn't apply (not SUBMDL_ES1887)
1302 */
1303int ess_dsp_init (sb_devc *devc, struct address_info *hw_config)
1304{
1305 /*
1306 * Caller also checks this, but anyway
1307 */
1308 if (devc->model != MDL_ESS) {
1309 printk (KERN_INFO "ess_dsp_init for non ESS chip\n");
1310 return 1;
1311 }
1312 /*
1313 * This for ES1887 to run Full Duplex. Actually ES1888
1314 * is allowed to do so too. I have no idea yet if this
1315 * will work for ES1888 however.
1316 *
1317 * For SB16 having both dma8 and dma16 means enable
1318 * Full Duplex. Let's try this for ES1887 too
1319 *
1320 */
1321 if (devc->submodel == SUBMDL_ES1887) {
1322 if (hw_config->dma2 != -1) {
1323 devc->dma16 = hw_config->dma2;
1324 }
1325 /*
1326 * devc->duplex initialization is put here, cause
1327 * ess_set_dma_hw needs it.
1328 */
1329 if (devc->dma8 != devc->dma16 && devc->dma16 != -1) {
1330 devc->duplex = 1;
1331 }
1332 }
1333 if (!ess_set_dma_hw (devc)) {
1334 free_irq(devc->irq, devc);
1335 return 0;
1336 }
1337 return 1;
1338}
1339
1340/****************************************************************************
1341 * *
1342 * ESS mixer *
1343 * *
1344 ****************************************************************************/
1345
1346#define ES688_RECORDING_DEVICES \
1347 ( SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD )
1348#define ES688_MIXER_DEVICES \
1349 ( SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_LINE \
1350 | SOUND_MASK_MIC | SOUND_MASK_CD | SOUND_MASK_VOLUME \
1351 | SOUND_MASK_LINE2 | SOUND_MASK_SPEAKER )
1352
1353#define ES1688_RECORDING_DEVICES \
1354 ( ES688_RECORDING_DEVICES )
1355#define ES1688_MIXER_DEVICES \
1356 ( ES688_MIXER_DEVICES | SOUND_MASK_RECLEV )
1357
1358#define ES1887_RECORDING_DEVICES \
1359 ( ES1688_RECORDING_DEVICES | SOUND_MASK_LINE2 | SOUND_MASK_SYNTH)
1360#define ES1887_MIXER_DEVICES \
1361 ( ES1688_MIXER_DEVICES )
1362
1363/*
1364 * Mixer registers of ES1887
1365 *
1366 * These registers specifically take care of recording levels. To make the
1367 * mapping from playback devices to recording devices every recording
1368 * devices = playback device + ES_REC_MIXER_RECDIFF
1369 */
1370#define ES_REC_MIXER_RECBASE (SOUND_MIXER_LINE3 + 1)
1371#define ES_REC_MIXER_RECDIFF (ES_REC_MIXER_RECBASE - SOUND_MIXER_SYNTH)
1372
1373#define ES_REC_MIXER_RECSYNTH (SOUND_MIXER_SYNTH + ES_REC_MIXER_RECDIFF)
1374#define ES_REC_MIXER_RECPCM (SOUND_MIXER_PCM + ES_REC_MIXER_RECDIFF)
1375#define ES_REC_MIXER_RECSPEAKER (SOUND_MIXER_SPEAKER + ES_REC_MIXER_RECDIFF)
1376#define ES_REC_MIXER_RECLINE (SOUND_MIXER_LINE + ES_REC_MIXER_RECDIFF)
1377#define ES_REC_MIXER_RECMIC (SOUND_MIXER_MIC + ES_REC_MIXER_RECDIFF)
1378#define ES_REC_MIXER_RECCD (SOUND_MIXER_CD + ES_REC_MIXER_RECDIFF)
1379#define ES_REC_MIXER_RECIMIX (SOUND_MIXER_IMIX + ES_REC_MIXER_RECDIFF)
1380#define ES_REC_MIXER_RECALTPCM (SOUND_MIXER_ALTPCM + ES_REC_MIXER_RECDIFF)
1381#define ES_REC_MIXER_RECRECLEV (SOUND_MIXER_RECLEV + ES_REC_MIXER_RECDIFF)
1382#define ES_REC_MIXER_RECIGAIN (SOUND_MIXER_IGAIN + ES_REC_MIXER_RECDIFF)
1383#define ES_REC_MIXER_RECOGAIN (SOUND_MIXER_OGAIN + ES_REC_MIXER_RECDIFF)
1384#define ES_REC_MIXER_RECLINE1 (SOUND_MIXER_LINE1 + ES_REC_MIXER_RECDIFF)
1385#define ES_REC_MIXER_RECLINE2 (SOUND_MIXER_LINE2 + ES_REC_MIXER_RECDIFF)
1386#define ES_REC_MIXER_RECLINE3 (SOUND_MIXER_LINE3 + ES_REC_MIXER_RECDIFF)
1387
1388static mixer_tab es688_mix = {
1389MIX_ENT(SOUND_MIXER_VOLUME, 0x32, 7, 4, 0x32, 3, 4),
1390MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1391MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1392MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1393MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
1394MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1395MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1396MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1397MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1398MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1399MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1400MIX_ENT(SOUND_MIXER_RECLEV, 0x00, 0, 0, 0x00, 0, 0),
1401MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1402MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1403MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1404MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1405MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
1406};
1407
1408/*
1409 * The ES1688 specifics... hopefully correct...
1410 * - 6 bit master volume
1411 * I was wrong, ES1888 docs say ES1688 didn't have it.
1412 * - RECLEV control
1413 * These may apply to ES688 too. I have no idea.
1414 */
1415static mixer_tab es1688_mix = {
1416MIX_ENT(SOUND_MIXER_VOLUME, 0x32, 7, 4, 0x32, 3, 4),
1417MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1418MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1419MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1420MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
1421MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1422MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1423MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1424MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1425MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1426MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1427MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
1428MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1429MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1430MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1431MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1432MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
1433};
1434
1435static mixer_tab es1688later_mix = {
1436MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
1437MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1438MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1439MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1440MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
1441MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1442MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1443MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1444MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1445MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1446MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1447MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
1448MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1449MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1450MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1451MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1452MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0)
1453};
1454
1455/*
1456 * This one is for all ESS chips with a record mixer.
1457 * It's not used (yet) however
1458 */
1459static mixer_tab es_rec_mix = {
1460MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
1461MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1462MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1463MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1464MIX_ENT(SOUND_MIXER_PCM, 0x14, 7, 4, 0x14, 3, 4),
1465MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1466MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1467MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1468MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1469MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1470MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1471MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
1472MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1473MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1474MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1475MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1476MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0),
1477MIX_ENT(ES_REC_MIXER_RECSYNTH, 0x6b, 7, 4, 0x6b, 3, 4),
1478MIX_ENT(ES_REC_MIXER_RECPCM, 0x00, 0, 0, 0x00, 0, 0),
1479MIX_ENT(ES_REC_MIXER_RECSPEAKER, 0x00, 0, 0, 0x00, 0, 0),
1480MIX_ENT(ES_REC_MIXER_RECLINE, 0x6e, 7, 4, 0x6e, 3, 4),
1481MIX_ENT(ES_REC_MIXER_RECMIC, 0x68, 7, 4, 0x68, 3, 4),
1482MIX_ENT(ES_REC_MIXER_RECCD, 0x6a, 7, 4, 0x6a, 3, 4),
1483MIX_ENT(ES_REC_MIXER_RECIMIX, 0x00, 0, 0, 0x00, 0, 0),
1484MIX_ENT(ES_REC_MIXER_RECALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1485MIX_ENT(ES_REC_MIXER_RECRECLEV, 0x00, 0, 0, 0x00, 0, 0),
1486MIX_ENT(ES_REC_MIXER_RECIGAIN, 0x00, 0, 0, 0x00, 0, 0),
1487MIX_ENT(ES_REC_MIXER_RECOGAIN, 0x00, 0, 0, 0x00, 0, 0),
1488MIX_ENT(ES_REC_MIXER_RECLINE1, 0x00, 0, 0, 0x00, 0, 0),
1489MIX_ENT(ES_REC_MIXER_RECLINE2, 0x6c, 7, 4, 0x6c, 3, 4),
1490MIX_ENT(ES_REC_MIXER_RECLINE3, 0x00, 0, 0, 0x00, 0, 0)
1491};
1492
1493/*
1494 * This one is for ES1887. It's little different from es_rec_mix: it
1495 * has 0x7c for PCM playback level. This is because ES1887 uses
1496 * Audio 2 for playback.
1497 */
1498static mixer_tab es1887_mix = {
1499MIX_ENT(SOUND_MIXER_VOLUME, 0x60, 5, 6, 0x62, 5, 6),
1500MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
1501MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
1502MIX_ENT(SOUND_MIXER_SYNTH, 0x36, 7, 4, 0x36, 3, 4),
1503MIX_ENT(SOUND_MIXER_PCM, 0x7c, 7, 4, 0x7c, 3, 4),
1504MIX_ENT(SOUND_MIXER_SPEAKER, 0x3c, 2, 3, 0x00, 0, 0),
1505MIX_ENT(SOUND_MIXER_LINE, 0x3e, 7, 4, 0x3e, 3, 4),
1506MIX_ENT(SOUND_MIXER_MIC, 0x1a, 7, 4, 0x1a, 3, 4),
1507MIX_ENT(SOUND_MIXER_CD, 0x38, 7, 4, 0x38, 3, 4),
1508MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
1509MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1510MIX_ENT(SOUND_MIXER_RECLEV, 0xb4, 7, 4, 0xb4, 3, 4),
1511MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
1512MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0),
1513MIX_ENT(SOUND_MIXER_LINE1, 0x00, 0, 0, 0x00, 0, 0),
1514MIX_ENT(SOUND_MIXER_LINE2, 0x3a, 7, 4, 0x3a, 3, 4),
1515MIX_ENT(SOUND_MIXER_LINE3, 0x00, 0, 0, 0x00, 0, 0),
1516MIX_ENT(ES_REC_MIXER_RECSYNTH, 0x6b, 7, 4, 0x6b, 3, 4),
1517MIX_ENT(ES_REC_MIXER_RECPCM, 0x00, 0, 0, 0x00, 0, 0),
1518MIX_ENT(ES_REC_MIXER_RECSPEAKER, 0x00, 0, 0, 0x00, 0, 0),
1519MIX_ENT(ES_REC_MIXER_RECLINE, 0x6e, 7, 4, 0x6e, 3, 4),
1520MIX_ENT(ES_REC_MIXER_RECMIC, 0x68, 7, 4, 0x68, 3, 4),
1521MIX_ENT(ES_REC_MIXER_RECCD, 0x6a, 7, 4, 0x6a, 3, 4),
1522MIX_ENT(ES_REC_MIXER_RECIMIX, 0x00, 0, 0, 0x00, 0, 0),
1523MIX_ENT(ES_REC_MIXER_RECALTPCM, 0x00, 0, 0, 0x00, 0, 0),
1524MIX_ENT(ES_REC_MIXER_RECRECLEV, 0x00, 0, 0, 0x00, 0, 0),
1525MIX_ENT(ES_REC_MIXER_RECIGAIN, 0x00, 0, 0, 0x00, 0, 0),
1526MIX_ENT(ES_REC_MIXER_RECOGAIN, 0x00, 0, 0, 0x00, 0, 0),
1527MIX_ENT(ES_REC_MIXER_RECLINE1, 0x00, 0, 0, 0x00, 0, 0),
1528MIX_ENT(ES_REC_MIXER_RECLINE2, 0x6c, 7, 4, 0x6c, 3, 4),
1529MIX_ENT(ES_REC_MIXER_RECLINE3, 0x00, 0, 0, 0x00, 0, 0)
1530};
1531
1532static int ess_has_rec_mixer (int submodel)
1533{
1534 switch (submodel) {
1535 case SUBMDL_ES1887:
1536 return 1;
1537 default:
1538 return 0;
1539 }
1540};
1541
1542#ifdef FKS_LOGGING
1543static int ess_mixer_mon_regs[]
1544 = { 0x70, 0x71, 0x72, 0x74, 0x76, 0x78, 0x7a, 0x7c, 0x7d, 0x7f
1545 , 0xa1, 0xa2, 0xa4, 0xa5, 0xa8, 0xa9
1546 , 0xb1, 0xb2, 0xb4, 0xb5, 0xb6, 0xb7, 0xb9
1547 , 0x00};
1548
1549static void ess_show_mixerregs (sb_devc *devc)
1550{
1551 int *mp = ess_mixer_mon_regs;
1552
1553return;
1554
1555 while (*mp != 0) {
1556 printk (KERN_INFO "res (%x)=%x\n", *mp, (int)(ess_getmixer (devc, *mp)));
1557 mp++;
1558 }
1559}
1560#endif
1561
1562void ess_setmixer (sb_devc * devc, unsigned int port, unsigned int value)
1563{
1564 unsigned long flags;
1565
1566#ifdef FKS_LOGGING
1567printk(KERN_INFO "FKS: write mixer %x: %x\n", port, value);
1568#endif
1569
1570 spin_lock_irqsave(&devc->lock, flags);
1571 if (port >= 0xa0) {
1572 ess_write (devc, port, value);
1573 } else {
1574 outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
1575
1576 udelay(20);
1577 outb(((unsigned char) (value & 0xff)), MIXER_DATA);
1578 udelay(20);
1579 }
1580 spin_unlock_irqrestore(&devc->lock, flags);
1581}
1582
1583unsigned int ess_getmixer (sb_devc * devc, unsigned int port)
1584{
1585 unsigned int val;
1586 unsigned long flags;
1587
1588 spin_lock_irqsave(&devc->lock, flags);
1589
1590 if (port >= 0xa0) {
1591 val = ess_read (devc, port);
1592 } else {
1593 outb(((unsigned char) (port & 0xff)), MIXER_ADDR);
1594
1595 udelay(20);
1596 val = inb(MIXER_DATA);
1597 udelay(20);
1598 }
1599 spin_unlock_irqrestore(&devc->lock, flags);
1600
1601 return val;
1602}
1603
1604static void ess_chgmixer
1605 (sb_devc * devc, unsigned int reg, unsigned int mask, unsigned int val)
1606{
1607 int value;
1608
1609 value = ess_getmixer (devc, reg);
1610 value = (value & ~mask) | (val & mask);
1611 ess_setmixer (devc, reg, value);
1612}
1613
1614/*
1615 * ess_mixer_init must be called from sb_mixer_init
1616 */
1617void ess_mixer_init (sb_devc * devc)
1618{
1619 devc->mixer_caps = SOUND_CAP_EXCL_INPUT;
1620
1621 /*
1622 * Take care of ES1887 specifics...
1623 */
1624 switch (devc->submodel) {
1625 case SUBMDL_ES1887:
1626 devc->supported_devices = ES1887_MIXER_DEVICES;
1627 devc->supported_rec_devices = ES1887_RECORDING_DEVICES;
1628#ifdef FKS_LOGGING
1629printk (KERN_INFO "FKS: ess_mixer_init dup = %d\n", devc->duplex);
1630#endif
1631 if (devc->duplex) {
1632 devc->iomap = &es1887_mix;
1633 devc->iomap_sz = ARRAY_SIZE(es1887_mix);
1634 } else {
1635 devc->iomap = &es_rec_mix;
1636 devc->iomap_sz = ARRAY_SIZE(es_rec_mix);
1637 }
1638 break;
1639 default:
1640 if (devc->submodel < 8) {
1641 devc->supported_devices = ES688_MIXER_DEVICES;
1642 devc->supported_rec_devices = ES688_RECORDING_DEVICES;
1643 devc->iomap = &es688_mix;
1644 devc->iomap_sz = ARRAY_SIZE(es688_mix);
1645 } else {
1646 /*
1647 * es1688 has 4 bits master vol.
1648 * later chips have 6 bits (?)
1649 */
1650 devc->supported_devices = ES1688_MIXER_DEVICES;
1651 devc->supported_rec_devices = ES1688_RECORDING_DEVICES;
1652 if (devc->submodel < 0x10) {
1653 devc->iomap = &es1688_mix;
1654 devc->iomap_sz = ARRAY_SIZE(es688_mix);
1655 } else {
1656 devc->iomap = &es1688later_mix;
1657 devc->iomap_sz = ARRAY_SIZE(es1688later_mix);
1658 }
1659 }
1660 }
1661}
1662
1663/*
1664 * Changing playback levels at an ESS chip with record mixer means having to
1665 * take care of recording levels of recorded inputs (devc->recmask) too!
1666 */
1667int ess_mixer_set(sb_devc *devc, int dev, int left, int right)
1668{
1669 if (ess_has_rec_mixer (devc->submodel) && (devc->recmask & (1 << dev))) {
1670 sb_common_mixer_set (devc, dev + ES_REC_MIXER_RECDIFF, left, right);
1671 }
1672 return sb_common_mixer_set (devc, dev, left, right);
1673}
1674
1675/*
1676 * After a sb_dsp_reset extended register 0xb4 (RECLEV) is reset too. After
1677 * sb_dsp_reset RECLEV has to be restored. This is where ess_mixer_reload
1678 * helps.
1679 */
1680void ess_mixer_reload (sb_devc *devc, int dev)
1681{
1682 int left, right, value;
1683
1684 value = devc->levels[dev];
1685 left = value & 0x000000ff;
1686 right = (value & 0x0000ff00) >> 8;
1687
1688 sb_common_mixer_set(devc, dev, left, right);
1689}
1690
1691static int es_rec_set_recmask(sb_devc * devc, int mask)
1692{
1693 int i, i_mask, cur_mask, diff_mask;
1694 int value, left, right;
1695
1696#ifdef FKS_LOGGING
1697printk (KERN_INFO "FKS: es_rec_set_recmask mask = %x\n", mask);
1698#endif
1699 /*
1700 * Changing the recmask on an ESS chip with recording mixer means:
1701 * (1) Find the differences
1702 * (2) For "turned-on" inputs: make the recording level the playback level
1703 * (3) For "turned-off" inputs: make the recording level zero
1704 */
1705 cur_mask = devc->recmask;
1706 diff_mask = (cur_mask ^ mask);
1707
1708 for (i = 0; i < 32; i++) {
1709 i_mask = (1 << i);
1710 if (diff_mask & i_mask) { /* Difference? (1) */
1711 if (mask & i_mask) { /* Turn it on (2) */
1712 value = devc->levels[i];
1713 left = value & 0x000000ff;
1714 right = (value & 0x0000ff00) >> 8;
1715 } else { /* Turn it off (3) */
1716 left = 0;
1717 right = 0;
1718 }
1719 sb_common_mixer_set(devc, i + ES_REC_MIXER_RECDIFF, left, right);
1720 }
1721 }
1722 return mask;
1723}
1724
1725int ess_set_recmask(sb_devc * devc, int *mask)
1726{
1727 /* This applies to ESS chips with record mixers only! */
1728
1729 if (ess_has_rec_mixer (devc->submodel)) {
1730 *mask = es_rec_set_recmask (devc, *mask);
1731 return 1; /* Applied */
1732 } else {
1733 return 0; /* Not applied */
1734 }
1735}
1736
1737/*
1738 * ess_mixer_reset must be called from sb_mixer_reset
1739 */
1740int ess_mixer_reset (sb_devc * devc)
1741{
1742 /*
1743 * Separate actions for ESS chips with a record mixer:
1744 */
1745 if (ess_has_rec_mixer (devc->submodel)) {
1746 switch (devc->submodel) {
1747 case SUBMDL_ES1887:
1748 /*
1749 * Separate actions for ES1887:
1750 * Change registers 7a and 1c to make the record mixer the
1751 * actual recording source.
1752 */
1753 ess_chgmixer(devc, 0x7a, 0x18, 0x08);
1754 ess_chgmixer(devc, 0x1c, 0x07, 0x07);
1755 break;
1756 }
1757 /*
1758 * Call set_recmask for proper initialization
1759 */
1760 devc->recmask = devc->supported_rec_devices;
1761 es_rec_set_recmask(devc, 0);
1762 devc->recmask = 0;
1763
1764 return 1; /* We took care of recmask. */
1765 } else {
1766 return 0; /* We didn't take care; caller do it */
1767 }
1768}
1769
1770/****************************************************************************
1771 * *
1772 * ESS midi *
1773 * *
1774 ****************************************************************************/
1775
1776/*
1777 * FKS: IRQ may be shared. Hm. And if so? Then What?
1778 */
1779int ess_midi_init(sb_devc * devc, struct address_info *hw_config)
1780{
1781 unsigned char cfg, tmp;
1782
1783 cfg = ess_getmixer (devc, 0x40) & 0x03;
1784
1785 if (devc->submodel < 8) {
1786 ess_setmixer (devc, 0x40, cfg | 0x03); /* Enable OPL3 & joystick */
1787 return 0; /* ES688 doesn't support MPU401 mode */
1788 }
1789 tmp = (hw_config->io_base & 0x0f0) >> 4;
1790
1791 if (tmp > 3) {
1792 ess_setmixer (devc, 0x40, cfg);
1793 return 0;
1794 }
1795 cfg |= tmp << 3;
1796
1797 tmp = 1; /* MPU enabled without interrupts */
1798
1799 /* May be shared: if so the value is -ve */
1800
1801 switch (abs(hw_config->irq)) {
1802 case 9:
1803 tmp = 0x4;
1804 break;
1805 case 5:
1806 tmp = 0x5;
1807 break;
1808 case 7:
1809 tmp = 0x6;
1810 break;
1811 case 10:
1812 tmp = 0x7;
1813 break;
1814 default:
1815 return 0;
1816 }
1817
1818 cfg |= tmp << 5;
1819 ess_setmixer (devc, 0x40, cfg | 0x03);
1820
1821 return 1;
1822}
1823
diff --git a/sound/oss/sb_ess.h b/sound/oss/sb_ess.h
deleted file mode 100644
index 1c741212bcfc..000000000000
--- a/sound/oss/sb_ess.h
+++ /dev/null
@@ -1,35 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Created: 9-Jan-1999 Rolf Fokkens
4 */
5
6extern void ess_intr
7 (sb_devc *devc);
8extern int ess_dsp_init
9 (sb_devc *devc, struct address_info *hw_config);
10
11extern struct audio_driver *ess_audio_init
12 (sb_devc *devc, int *audio_flags, int *format_mask);
13extern int ess_midi_init
14 (sb_devc *devc, struct address_info *hw_config);
15extern void ess_mixer_init
16 (sb_devc *devc);
17
18extern int ess_init
19 (sb_devc *devc, struct address_info *hw_config);
20extern int ess_dsp_reset
21 (sb_devc *devc);
22
23extern void ess_setmixer
24 (sb_devc *devc, unsigned int port, unsigned int value);
25extern unsigned int ess_getmixer
26 (sb_devc *devc, unsigned int port);
27extern int ess_mixer_set
28 (sb_devc *devc, int dev, int left, int right);
29extern int ess_mixer_reset
30 (sb_devc *devc);
31extern void ess_mixer_reload
32 (sb_devc * devc, int dev);
33extern int ess_set_recmask
34 (sb_devc *devc, int *mask);
35
diff --git a/sound/oss/sb_midi.c b/sound/oss/sb_midi.c
deleted file mode 100644
index 551ee7557b4e..000000000000
--- a/sound/oss/sb_midi.c
+++ /dev/null
@@ -1,206 +0,0 @@
1/*
2 * sound/oss/sb_midi.c
3 *
4 * The low level driver for the Sound Blaster DS chips.
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 */
13
14#include <linux/spinlock.h>
15#include <linux/slab.h>
16
17#include "sound_config.h"
18
19#include "sb.h"
20#undef SB_TEST_IRQ
21
22/*
23 * The DSP channel can be used either for input or output. Variable
24 * 'sb_irq_mode' will be set when the program calls read or write first time
25 * after open. Current version doesn't support mode changes without closing
26 * and reopening the device. Support for this feature may be implemented in a
27 * future version of this driver.
28 */
29
30
31static int sb_midi_open(int dev, int mode,
32 void (*input) (int dev, unsigned char data),
33 void (*output) (int dev)
34)
35{
36 sb_devc *devc = midi_devs[dev]->devc;
37 unsigned long flags;
38
39 if (devc == NULL)
40 return -ENXIO;
41
42 spin_lock_irqsave(&devc->lock, flags);
43 if (devc->opened)
44 {
45 spin_unlock_irqrestore(&devc->lock, flags);
46 return -EBUSY;
47 }
48 devc->opened = 1;
49 spin_unlock_irqrestore(&devc->lock, flags);
50
51 devc->irq_mode = IMODE_MIDI;
52 devc->midi_broken = 0;
53
54 sb_dsp_reset(devc);
55
56 if (!sb_dsp_command(devc, 0x35)) /* Start MIDI UART mode */
57 {
58 devc->opened = 0;
59 return -EIO;
60 }
61 devc->intr_active = 1;
62
63 if (mode & OPEN_READ)
64 {
65 devc->input_opened = 1;
66 devc->midi_input_intr = input;
67 }
68 return 0;
69}
70
71static void sb_midi_close(int dev)
72{
73 sb_devc *devc = midi_devs[dev]->devc;
74 unsigned long flags;
75
76 if (devc == NULL)
77 return;
78
79 spin_lock_irqsave(&devc->lock, flags);
80 sb_dsp_reset(devc);
81 devc->intr_active = 0;
82 devc->input_opened = 0;
83 devc->opened = 0;
84 spin_unlock_irqrestore(&devc->lock, flags);
85}
86
87static int sb_midi_out(int dev, unsigned char midi_byte)
88{
89 sb_devc *devc = midi_devs[dev]->devc;
90
91 if (devc == NULL)
92 return 1;
93
94 if (devc->midi_broken)
95 return 1;
96
97 if (!sb_dsp_command(devc, midi_byte))
98 {
99 devc->midi_broken = 1;
100 return 1;
101 }
102 return 1;
103}
104
105static int sb_midi_start_read(int dev)
106{
107 return 0;
108}
109
110static int sb_midi_end_read(int dev)
111{
112 sb_devc *devc = midi_devs[dev]->devc;
113
114 if (devc == NULL)
115 return -ENXIO;
116
117 sb_dsp_reset(devc);
118 devc->intr_active = 0;
119 return 0;
120}
121
122static int sb_midi_ioctl(int dev, unsigned cmd, void __user *arg)
123{
124 return -EINVAL;
125}
126
127void sb_midi_interrupt(sb_devc * devc)
128{
129 unsigned long flags;
130 unsigned char data;
131
132 if (devc == NULL)
133 return;
134
135 spin_lock_irqsave(&devc->lock, flags);
136
137 data = inb(DSP_READ);
138 if (devc->input_opened)
139 devc->midi_input_intr(devc->my_mididev, data);
140
141 spin_unlock_irqrestore(&devc->lock, flags);
142}
143
144#define MIDI_SYNTH_NAME "Sound Blaster Midi"
145#define MIDI_SYNTH_CAPS 0
146#include "midi_synth.h"
147
148static struct midi_operations sb_midi_operations =
149{
150 .owner = THIS_MODULE,
151 .info = {"Sound Blaster", 0, 0, SNDCARD_SB},
152 .converter = &std_midi_synth,
153 .in_info = {0},
154 .open = sb_midi_open,
155 .close = sb_midi_close,
156 .ioctl = sb_midi_ioctl,
157 .outputc = sb_midi_out,
158 .start_read = sb_midi_start_read,
159 .end_read = sb_midi_end_read,
160};
161
162void sb_dsp_midi_init(sb_devc * devc, struct module *owner)
163{
164 int dev;
165
166 if (devc->model < 2) /* No MIDI support for SB 1.x */
167 return;
168
169 dev = sound_alloc_mididev();
170
171 if (dev == -1)
172 {
173 printk(KERN_ERR "sb_midi: too many MIDI devices detected\n");
174 return;
175 }
176 std_midi_synth.midi_dev = devc->my_mididev = dev;
177 midi_devs[dev] = kmalloc(sizeof(struct midi_operations), GFP_KERNEL);
178 if (midi_devs[dev] == NULL)
179 {
180 printk(KERN_WARNING "Sound Blaster: failed to allocate MIDI memory.\n");
181 sound_unload_mididev(dev);
182 return;
183 }
184 memcpy((char *) midi_devs[dev], (char *) &sb_midi_operations,
185 sizeof(struct midi_operations));
186
187 if (owner)
188 midi_devs[dev]->owner = owner;
189
190 midi_devs[dev]->devc = devc;
191
192
193 midi_devs[dev]->converter = kmalloc(sizeof(struct synth_operations), GFP_KERNEL);
194 if (midi_devs[dev]->converter == NULL)
195 {
196 printk(KERN_WARNING "Sound Blaster: failed to allocate MIDI memory.\n");
197 kfree(midi_devs[dev]);
198 sound_unload_mididev(dev);
199 return;
200 }
201 memcpy((char *) midi_devs[dev]->converter, (char *) &std_midi_synth,
202 sizeof(struct synth_operations));
203
204 midi_devs[dev]->converter->id = "SBMIDI";
205 sequencer_init();
206}
diff --git a/sound/oss/sb_mixer.c b/sound/oss/sb_mixer.c
deleted file mode 100644
index acf7586aeb47..000000000000
--- a/sound/oss/sb_mixer.c
+++ /dev/null
@@ -1,770 +0,0 @@
1/*
2 * sound/oss/sb_mixer.c
3 *
4 * The low level mixer driver for the Sound Blaster compatible cards.
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
15 * Rolf Fokkens (Dec 20 1998) : Moved ESS stuff into sb_ess.[ch]
16 * Stanislav Voronyi <stas@esc.kharkov.com> : Support for AWE 3DSE device (Jun 7 1999)
17 */
18
19#include <linux/slab.h>
20
21#include "sound_config.h"
22
23#define __SB_MIXER_C__
24
25#include "sb.h"
26#include "sb_mixer.h"
27
28#include "sb_ess.h"
29
30#define SBPRO_RECORDING_DEVICES (SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD)
31
32/* Same as SB Pro, unless I find otherwise */
33#define SGNXPRO_RECORDING_DEVICES SBPRO_RECORDING_DEVICES
34
35#define SBPRO_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_LINE | SOUND_MASK_MIC | \
36 SOUND_MASK_CD | SOUND_MASK_VOLUME)
37
38/* SG NX Pro has treble and bass settings on the mixer. The 'speaker'
39 * channel is the COVOX/DisneySoundSource emulation volume control
40 * on the mixer. It does NOT control speaker volume. Should have own
41 * mask eventually?
42 */
43#define SGNXPRO_MIXER_DEVICES (SBPRO_MIXER_DEVICES|SOUND_MASK_BASS| \
44 SOUND_MASK_TREBLE|SOUND_MASK_SPEAKER )
45
46#define SB16_RECORDING_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_LINE | SOUND_MASK_MIC | \
47 SOUND_MASK_CD)
48
49#define SB16_OUTFILTER_DEVICES (SOUND_MASK_LINE | SOUND_MASK_MIC | \
50 SOUND_MASK_CD)
51
52#define SB16_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_SPEAKER | SOUND_MASK_LINE | SOUND_MASK_MIC | \
53 SOUND_MASK_CD | \
54 SOUND_MASK_IGAIN | SOUND_MASK_OGAIN | \
55 SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | \
56 SOUND_MASK_IMIX)
57
58/* These are the only devices that are working at the moment. Others could
59 * be added once they are identified and a method is found to control them.
60 */
61#define ALS007_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_LINE | \
62 SOUND_MASK_PCM | SOUND_MASK_MIC | \
63 SOUND_MASK_CD | \
64 SOUND_MASK_VOLUME)
65
66static mixer_tab sbpro_mix = {
67MIX_ENT(SOUND_MIXER_VOLUME, 0x22, 7, 4, 0x22, 3, 4),
68MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
69MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
70MIX_ENT(SOUND_MIXER_SYNTH, 0x26, 7, 4, 0x26, 3, 4),
71MIX_ENT(SOUND_MIXER_PCM, 0x04, 7, 4, 0x04, 3, 4),
72MIX_ENT(SOUND_MIXER_SPEAKER, 0x00, 0, 0, 0x00, 0, 0),
73MIX_ENT(SOUND_MIXER_LINE, 0x2e, 7, 4, 0x2e, 3, 4),
74MIX_ENT(SOUND_MIXER_MIC, 0x0a, 2, 3, 0x00, 0, 0),
75MIX_ENT(SOUND_MIXER_CD, 0x28, 7, 4, 0x28, 3, 4),
76MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
77MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
78MIX_ENT(SOUND_MIXER_RECLEV, 0x00, 0, 0, 0x00, 0, 0)
79};
80
81static mixer_tab sb16_mix = {
82MIX_ENT(SOUND_MIXER_VOLUME, 0x30, 7, 5, 0x31, 7, 5),
83MIX_ENT(SOUND_MIXER_BASS, 0x46, 7, 4, 0x47, 7, 4),
84MIX_ENT(SOUND_MIXER_TREBLE, 0x44, 7, 4, 0x45, 7, 4),
85MIX_ENT(SOUND_MIXER_SYNTH, 0x34, 7, 5, 0x35, 7, 5),
86MIX_ENT(SOUND_MIXER_PCM, 0x32, 7, 5, 0x33, 7, 5),
87MIX_ENT(SOUND_MIXER_SPEAKER, 0x3b, 7, 2, 0x00, 0, 0),
88MIX_ENT(SOUND_MIXER_LINE, 0x38, 7, 5, 0x39, 7, 5),
89MIX_ENT(SOUND_MIXER_MIC, 0x3a, 7, 5, 0x00, 0, 0),
90MIX_ENT(SOUND_MIXER_CD, 0x36, 7, 5, 0x37, 7, 5),
91MIX_ENT(SOUND_MIXER_IMIX, 0x3c, 0, 1, 0x00, 0, 0),
92MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
93MIX_ENT(SOUND_MIXER_RECLEV, 0x3f, 7, 2, 0x40, 7, 2), /* Obsolete. Use IGAIN */
94MIX_ENT(SOUND_MIXER_IGAIN, 0x3f, 7, 2, 0x40, 7, 2),
95MIX_ENT(SOUND_MIXER_OGAIN, 0x41, 7, 2, 0x42, 7, 2)
96};
97
98static mixer_tab als007_mix =
99{
100MIX_ENT(SOUND_MIXER_VOLUME, 0x62, 7, 4, 0x62, 3, 4),
101MIX_ENT(SOUND_MIXER_BASS, 0x00, 0, 0, 0x00, 0, 0),
102MIX_ENT(SOUND_MIXER_TREBLE, 0x00, 0, 0, 0x00, 0, 0),
103MIX_ENT(SOUND_MIXER_SYNTH, 0x66, 7, 4, 0x66, 3, 4),
104MIX_ENT(SOUND_MIXER_PCM, 0x64, 7, 4, 0x64, 3, 4),
105MIX_ENT(SOUND_MIXER_SPEAKER, 0x00, 0, 0, 0x00, 0, 0),
106MIX_ENT(SOUND_MIXER_LINE, 0x6e, 7, 4, 0x6e, 3, 4),
107MIX_ENT(SOUND_MIXER_MIC, 0x6a, 2, 3, 0x00, 0, 0),
108MIX_ENT(SOUND_MIXER_CD, 0x68, 7, 4, 0x68, 3, 4),
109MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
110MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
111MIX_ENT(SOUND_MIXER_RECLEV, 0x00, 0, 0, 0x00, 0, 0), /* Obsolete. Use IGAIN */
112MIX_ENT(SOUND_MIXER_IGAIN, 0x00, 0, 0, 0x00, 0, 0),
113MIX_ENT(SOUND_MIXER_OGAIN, 0x00, 0, 0, 0x00, 0, 0)
114};
115
116
117/* SM_GAMES Master volume is lower and PCM & FM volumes
118 higher than with SB Pro. This improves the
119 sound quality */
120
121static int smg_default_levels[32] =
122{
123 0x2020, /* Master Volume */
124 0x4b4b, /* Bass */
125 0x4b4b, /* Treble */
126 0x6464, /* FM */
127 0x6464, /* PCM */
128 0x4b4b, /* PC Speaker */
129 0x4b4b, /* Ext Line */
130 0x0000, /* Mic */
131 0x4b4b, /* CD */
132 0x4b4b, /* Recording monitor */
133 0x4b4b, /* SB PCM */
134 0x4b4b, /* Recording level */
135 0x4b4b, /* Input gain */
136 0x4b4b, /* Output gain */
137 0x4040, /* Line1 */
138 0x4040, /* Line2 */
139 0x1515 /* Line3 */
140};
141
142static int sb_default_levels[32] =
143{
144 0x5a5a, /* Master Volume */
145 0x4b4b, /* Bass */
146 0x4b4b, /* Treble */
147 0x4b4b, /* FM */
148 0x4b4b, /* PCM */
149 0x4b4b, /* PC Speaker */
150 0x4b4b, /* Ext Line */
151 0x1010, /* Mic */
152 0x4b4b, /* CD */
153 0x0000, /* Recording monitor */
154 0x4b4b, /* SB PCM */
155 0x4b4b, /* Recording level */
156 0x4b4b, /* Input gain */
157 0x4b4b, /* Output gain */
158 0x4040, /* Line1 */
159 0x4040, /* Line2 */
160 0x1515 /* Line3 */
161};
162
163static unsigned char sb16_recmasks_L[SOUND_MIXER_NRDEVICES] =
164{
165 0x00, /* SOUND_MIXER_VOLUME */
166 0x00, /* SOUND_MIXER_BASS */
167 0x00, /* SOUND_MIXER_TREBLE */
168 0x40, /* SOUND_MIXER_SYNTH */
169 0x00, /* SOUND_MIXER_PCM */
170 0x00, /* SOUND_MIXER_SPEAKER */
171 0x10, /* SOUND_MIXER_LINE */
172 0x01, /* SOUND_MIXER_MIC */
173 0x04, /* SOUND_MIXER_CD */
174 0x00, /* SOUND_MIXER_IMIX */
175 0x00, /* SOUND_MIXER_ALTPCM */
176 0x00, /* SOUND_MIXER_RECLEV */
177 0x00, /* SOUND_MIXER_IGAIN */
178 0x00 /* SOUND_MIXER_OGAIN */
179};
180
181static unsigned char sb16_recmasks_R[SOUND_MIXER_NRDEVICES] =
182{
183 0x00, /* SOUND_MIXER_VOLUME */
184 0x00, /* SOUND_MIXER_BASS */
185 0x00, /* SOUND_MIXER_TREBLE */
186 0x20, /* SOUND_MIXER_SYNTH */
187 0x00, /* SOUND_MIXER_PCM */
188 0x00, /* SOUND_MIXER_SPEAKER */
189 0x08, /* SOUND_MIXER_LINE */
190 0x01, /* SOUND_MIXER_MIC */
191 0x02, /* SOUND_MIXER_CD */
192 0x00, /* SOUND_MIXER_IMIX */
193 0x00, /* SOUND_MIXER_ALTPCM */
194 0x00, /* SOUND_MIXER_RECLEV */
195 0x00, /* SOUND_MIXER_IGAIN */
196 0x00 /* SOUND_MIXER_OGAIN */
197};
198
199static char smw_mix_regs[] = /* Left mixer registers */
200{
201 0x0b, /* SOUND_MIXER_VOLUME */
202 0x0d, /* SOUND_MIXER_BASS */
203 0x0d, /* SOUND_MIXER_TREBLE */
204 0x05, /* SOUND_MIXER_SYNTH */
205 0x09, /* SOUND_MIXER_PCM */
206 0x00, /* SOUND_MIXER_SPEAKER */
207 0x03, /* SOUND_MIXER_LINE */
208 0x01, /* SOUND_MIXER_MIC */
209 0x07, /* SOUND_MIXER_CD */
210 0x00, /* SOUND_MIXER_IMIX */
211 0x00, /* SOUND_MIXER_ALTPCM */
212 0x00, /* SOUND_MIXER_RECLEV */
213 0x00, /* SOUND_MIXER_IGAIN */
214 0x00, /* SOUND_MIXER_OGAIN */
215 0x00, /* SOUND_MIXER_LINE1 */
216 0x00, /* SOUND_MIXER_LINE2 */
217 0x00 /* SOUND_MIXER_LINE3 */
218};
219
220static int sbmixnum = 1;
221
222static void sb_mixer_reset(sb_devc * devc);
223
224void sb_mixer_set_stereo(sb_devc * devc, int mode)
225{
226 sb_chgmixer(devc, OUT_FILTER, STEREO_DAC, (mode ? STEREO_DAC : MONO_DAC));
227}
228
229static int detect_mixer(sb_devc * devc)
230{
231 /* Just trust the mixer is there */
232 return 1;
233}
234
235static void oss_change_bits(sb_devc *devc, unsigned char *regval, int dev, int chn, int newval)
236{
237 unsigned char mask;
238 int shift;
239
240 mask = (1 << (*devc->iomap)[dev][chn].nbits) - 1;
241 newval = (int) ((newval * mask) + 50) / 100; /* Scale */
242
243 shift = (*devc->iomap)[dev][chn].bitoffs - (*devc->iomap)[dev][LEFT_CHN].nbits + 1;
244
245 *regval &= ~(mask << shift); /* Mask out previous value */
246 *regval |= (newval & mask) << shift; /* Set the new value */
247}
248
249static int sb_mixer_get(sb_devc * devc, int dev)
250{
251 if (!((1 << dev) & devc->supported_devices))
252 return -EINVAL;
253 return devc->levels[dev];
254}
255
256void smw_mixer_init(sb_devc * devc)
257{
258 int i;
259
260 sb_setmixer(devc, 0x00, 0x18); /* Mute unused (Telephone) line */
261 sb_setmixer(devc, 0x10, 0x38); /* Config register 2 */
262
263 devc->supported_devices = 0;
264 for (i = 0; i < sizeof(smw_mix_regs); i++)
265 if (smw_mix_regs[i] != 0)
266 devc->supported_devices |= (1 << i);
267
268 devc->supported_rec_devices = devc->supported_devices &
269 ~(SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_PCM | SOUND_MASK_VOLUME);
270 sb_mixer_reset(devc);
271}
272
273int sb_common_mixer_set(sb_devc * devc, int dev, int left, int right)
274{
275 int regoffs;
276 unsigned char val;
277
278 if ((dev < 0) || (dev >= devc->iomap_sz))
279 return -EINVAL;
280
281 regoffs = (*devc->iomap)[dev][LEFT_CHN].regno;
282
283 if (regoffs == 0)
284 return -EINVAL;
285
286 val = sb_getmixer(devc, regoffs);
287 oss_change_bits(devc, &val, dev, LEFT_CHN, left);
288
289 if ((*devc->iomap)[dev][RIGHT_CHN].regno != regoffs) /*
290 * Change register
291 */
292 {
293 sb_setmixer(devc, regoffs, val); /*
294 * Save the old one
295 */
296 regoffs = (*devc->iomap)[dev][RIGHT_CHN].regno;
297
298 if (regoffs == 0)
299 return left | (left << 8); /*
300 * Just left channel present
301 */
302
303 val = sb_getmixer(devc, regoffs); /*
304 * Read the new one
305 */
306 }
307 oss_change_bits(devc, &val, dev, RIGHT_CHN, right);
308
309 sb_setmixer(devc, regoffs, val);
310
311 return left | (right << 8);
312}
313
314static int smw_mixer_set(sb_devc * devc, int dev, int left, int right)
315{
316 int reg, val;
317
318 switch (dev)
319 {
320 case SOUND_MIXER_VOLUME:
321 sb_setmixer(devc, 0x0b, 96 - (96 * left / 100)); /* 96=mute, 0=max */
322 sb_setmixer(devc, 0x0c, 96 - (96 * right / 100));
323 break;
324
325 case SOUND_MIXER_BASS:
326 case SOUND_MIXER_TREBLE:
327 devc->levels[dev] = left | (right << 8);
328 /* Set left bass and treble values */
329 val = ((devc->levels[SOUND_MIXER_TREBLE] & 0xff) * 16 / (unsigned) 100) << 4;
330 val |= ((devc->levels[SOUND_MIXER_BASS] & 0xff) * 16 / (unsigned) 100) & 0x0f;
331 sb_setmixer(devc, 0x0d, val);
332
333 /* Set right bass and treble values */
334 val = (((devc->levels[SOUND_MIXER_TREBLE] >> 8) & 0xff) * 16 / (unsigned) 100) << 4;
335 val |= (((devc->levels[SOUND_MIXER_BASS] >> 8) & 0xff) * 16 / (unsigned) 100) & 0x0f;
336 sb_setmixer(devc, 0x0e, val);
337
338 break;
339
340 default:
341 /* bounds check */
342 if (dev < 0 || dev >= ARRAY_SIZE(smw_mix_regs))
343 return -EINVAL;
344 reg = smw_mix_regs[dev];
345 if (reg == 0)
346 return -EINVAL;
347 sb_setmixer(devc, reg, (24 - (24 * left / 100)) | 0x20); /* 24=mute, 0=max */
348 sb_setmixer(devc, reg + 1, (24 - (24 * right / 100)) | 0x40);
349 }
350
351 devc->levels[dev] = left | (right << 8);
352 return left | (right << 8);
353}
354
355static int sb_mixer_set(sb_devc * devc, int dev, int value)
356{
357 int left = value & 0x000000ff;
358 int right = (value & 0x0000ff00) >> 8;
359 int retval;
360
361 if (left > 100)
362 left = 100;
363 if (right > 100)
364 right = 100;
365
366 if ((dev < 0) || (dev > 31))
367 return -EINVAL;
368
369 if (!(devc->supported_devices & (1 << dev))) /*
370 * Not supported
371 */
372 return -EINVAL;
373
374 /* Differentiate depending on the chipsets */
375 switch (devc->model) {
376 case MDL_SMW:
377 retval = smw_mixer_set(devc, dev, left, right);
378 break;
379 case MDL_ESS:
380 retval = ess_mixer_set(devc, dev, left, right);
381 break;
382 default:
383 retval = sb_common_mixer_set(devc, dev, left, right);
384 }
385 if (retval >= 0) devc->levels[dev] = retval;
386
387 return retval;
388}
389
390/*
391 * set_recsrc doesn't apply to ES188x
392 */
393static void set_recsrc(sb_devc * devc, int src)
394{
395 sb_setmixer(devc, RECORD_SRC, (sb_getmixer(devc, RECORD_SRC) & ~7) | (src & 0x7));
396}
397
398static int set_recmask(sb_devc * devc, int mask)
399{
400 int devmask, i;
401 unsigned char regimageL, regimageR;
402
403 devmask = mask & devc->supported_rec_devices;
404
405 switch (devc->model)
406 {
407 case MDL_SBPRO:
408 case MDL_ESS:
409 case MDL_JAZZ:
410 case MDL_SMW:
411 if (devc->model == MDL_ESS && ess_set_recmask (devc, &devmask)) {
412 break;
413 }
414 if (devmask != SOUND_MASK_MIC &&
415 devmask != SOUND_MASK_LINE &&
416 devmask != SOUND_MASK_CD)
417 {
418 /*
419 * More than one device selected. Drop the
420 * previous selection
421 */
422 devmask &= ~devc->recmask;
423 }
424 if (devmask != SOUND_MASK_MIC &&
425 devmask != SOUND_MASK_LINE &&
426 devmask != SOUND_MASK_CD)
427 {
428 /*
429 * More than one device selected. Default to
430 * mic
431 */
432 devmask = SOUND_MASK_MIC;
433 }
434 if (devmask ^ devc->recmask) /*
435 * Input source changed
436 */
437 {
438 switch (devmask)
439 {
440 case SOUND_MASK_MIC:
441 set_recsrc(devc, SRC__MIC);
442 break;
443
444 case SOUND_MASK_LINE:
445 set_recsrc(devc, SRC__LINE);
446 break;
447
448 case SOUND_MASK_CD:
449 set_recsrc(devc, SRC__CD);
450 break;
451
452 default:
453 set_recsrc(devc, SRC__MIC);
454 }
455 }
456 break;
457
458 case MDL_SB16:
459 if (!devmask)
460 devmask = SOUND_MASK_MIC;
461
462 if (devc->submodel == SUBMDL_ALS007)
463 {
464 switch (devmask)
465 {
466 case SOUND_MASK_LINE:
467 sb_setmixer(devc, ALS007_RECORD_SRC, ALS007_LINE);
468 break;
469 case SOUND_MASK_CD:
470 sb_setmixer(devc, ALS007_RECORD_SRC, ALS007_CD);
471 break;
472 case SOUND_MASK_SYNTH:
473 sb_setmixer(devc, ALS007_RECORD_SRC, ALS007_SYNTH);
474 break;
475 default: /* Also takes care of SOUND_MASK_MIC case */
476 sb_setmixer(devc, ALS007_RECORD_SRC, ALS007_MIC);
477 break;
478 }
479 }
480 else
481 {
482 regimageL = regimageR = 0;
483 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
484 {
485 if ((1 << i) & devmask)
486 {
487 regimageL |= sb16_recmasks_L[i];
488 regimageR |= sb16_recmasks_R[i];
489 }
490 sb_setmixer (devc, SB16_IMASK_L, regimageL);
491 sb_setmixer (devc, SB16_IMASK_R, regimageR);
492 }
493 }
494 break;
495 }
496 devc->recmask = devmask;
497 return devc->recmask;
498}
499
500static int set_outmask(sb_devc * devc, int mask)
501{
502 int devmask, i;
503 unsigned char regimage;
504
505 devmask = mask & devc->supported_out_devices;
506
507 switch (devc->model)
508 {
509 case MDL_SB16:
510 if (devc->submodel == SUBMDL_ALS007)
511 break;
512 else
513 {
514 regimage = 0;
515 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
516 {
517 if ((1 << i) & devmask)
518 {
519 regimage |= (sb16_recmasks_L[i] | sb16_recmasks_R[i]);
520 }
521 sb_setmixer (devc, SB16_OMASK, regimage);
522 }
523 }
524 break;
525 default:
526 break;
527 }
528
529 devc->outmask = devmask;
530 return devc->outmask;
531}
532
533static int sb_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
534{
535 sb_devc *devc = mixer_devs[dev]->devc;
536 int val, ret;
537 int __user *p = arg;
538
539 /*
540 * Use ioctl(fd, SOUND_MIXER_AGC, &mode) to turn AGC off (0) or on (1).
541 * Use ioctl(fd, SOUND_MIXER_3DSE, &mode) to turn 3DSE off (0) or on (1)
542 * or mode==2 put 3DSE state to mode.
543 */
544 if (devc->model == MDL_SB16) {
545 if (cmd == SOUND_MIXER_AGC)
546 {
547 if (get_user(val, p))
548 return -EFAULT;
549 sb_setmixer(devc, 0x43, (~val) & 0x01);
550 return 0;
551 }
552 if (cmd == SOUND_MIXER_3DSE)
553 {
554 /* I put here 15, but I don't know the exact version.
555 At least my 4.13 havn't 3DSE, 4.16 has it. */
556 if (devc->minor < 15)
557 return -EINVAL;
558 if (get_user(val, p))
559 return -EFAULT;
560 if (val == 0 || val == 1)
561 sb_chgmixer(devc, AWE_3DSE, 0x01, val);
562 else if (val == 2)
563 {
564 ret = sb_getmixer(devc, AWE_3DSE)&0x01;
565 return put_user(ret, p);
566 }
567 else
568 return -EINVAL;
569 return 0;
570 }
571 }
572 if (((cmd >> 8) & 0xff) == 'M')
573 {
574 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
575 {
576 if (get_user(val, p))
577 return -EFAULT;
578 switch (cmd & 0xff)
579 {
580 case SOUND_MIXER_RECSRC:
581 ret = set_recmask(devc, val);
582 break;
583
584 case SOUND_MIXER_OUTSRC:
585 ret = set_outmask(devc, val);
586 break;
587
588 default:
589 ret = sb_mixer_set(devc, cmd & 0xff, val);
590 }
591 }
592 else switch (cmd & 0xff)
593 {
594 case SOUND_MIXER_RECSRC:
595 ret = devc->recmask;
596 break;
597
598 case SOUND_MIXER_OUTSRC:
599 ret = devc->outmask;
600 break;
601
602 case SOUND_MIXER_DEVMASK:
603 ret = devc->supported_devices;
604 break;
605
606 case SOUND_MIXER_STEREODEVS:
607 ret = devc->supported_devices;
608 /* The ESS seems to have stereo mic controls */
609 if (devc->model == MDL_ESS)
610 ret &= ~(SOUND_MASK_SPEAKER|SOUND_MASK_IMIX);
611 else if (devc->model != MDL_JAZZ && devc->model != MDL_SMW)
612 ret &= ~(SOUND_MASK_MIC | SOUND_MASK_SPEAKER | SOUND_MASK_IMIX);
613 break;
614
615 case SOUND_MIXER_RECMASK:
616 ret = devc->supported_rec_devices;
617 break;
618
619 case SOUND_MIXER_OUTMASK:
620 ret = devc->supported_out_devices;
621 break;
622
623 case SOUND_MIXER_CAPS:
624 ret = devc->mixer_caps;
625 break;
626
627 default:
628 ret = sb_mixer_get(devc, cmd & 0xff);
629 break;
630 }
631 return put_user(ret, p);
632 } else
633 return -EINVAL;
634}
635
636static struct mixer_operations sb_mixer_operations =
637{
638 .owner = THIS_MODULE,
639 .id = "SB",
640 .name = "Sound Blaster",
641 .ioctl = sb_mixer_ioctl
642};
643
644static struct mixer_operations als007_mixer_operations =
645{
646 .owner = THIS_MODULE,
647 .id = "ALS007",
648 .name = "Avance ALS-007",
649 .ioctl = sb_mixer_ioctl
650};
651
652static void sb_mixer_reset(sb_devc * devc)
653{
654 char name[32];
655 int i;
656
657 sprintf(name, "SB_%d", devc->sbmixnum);
658
659 if (devc->sbmo.sm_games)
660 devc->levels = load_mixer_volumes(name, smg_default_levels, 1);
661 else
662 devc->levels = load_mixer_volumes(name, sb_default_levels, 1);
663
664 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
665 sb_mixer_set(devc, i, devc->levels[i]);
666
667 if (devc->model != MDL_ESS || !ess_mixer_reset (devc)) {
668 set_recmask(devc, SOUND_MASK_MIC);
669 }
670}
671
672int sb_mixer_init(sb_devc * devc, struct module *owner)
673{
674 int mixer_type = 0;
675 int m;
676
677 devc->sbmixnum = sbmixnum++;
678 devc->levels = NULL;
679
680 sb_setmixer(devc, 0x00, 0); /* Reset mixer */
681
682 if (!(mixer_type = detect_mixer(devc)))
683 return 0; /* No mixer. Why? */
684
685 switch (devc->model)
686 {
687 case MDL_ESSPCI:
688 case MDL_YMPCI:
689 case MDL_SBPRO:
690 case MDL_AZTECH:
691 case MDL_JAZZ:
692 devc->mixer_caps = SOUND_CAP_EXCL_INPUT;
693 devc->supported_devices = SBPRO_MIXER_DEVICES;
694 devc->supported_rec_devices = SBPRO_RECORDING_DEVICES;
695 devc->iomap = &sbpro_mix;
696 devc->iomap_sz = ARRAY_SIZE(sbpro_mix);
697 break;
698
699 case MDL_ESS:
700 ess_mixer_init (devc);
701 break;
702
703 case MDL_SMW:
704 devc->mixer_caps = SOUND_CAP_EXCL_INPUT;
705 devc->supported_devices = 0;
706 devc->supported_rec_devices = 0;
707 devc->iomap = &sbpro_mix;
708 devc->iomap_sz = ARRAY_SIZE(sbpro_mix);
709 smw_mixer_init(devc);
710 break;
711
712 case MDL_SB16:
713 devc->mixer_caps = 0;
714 devc->supported_rec_devices = SB16_RECORDING_DEVICES;
715 devc->supported_out_devices = SB16_OUTFILTER_DEVICES;
716 if (devc->submodel != SUBMDL_ALS007)
717 {
718 devc->supported_devices = SB16_MIXER_DEVICES;
719 devc->iomap = &sb16_mix;
720 devc->iomap_sz = ARRAY_SIZE(sb16_mix);
721 }
722 else
723 {
724 devc->supported_devices = ALS007_MIXER_DEVICES;
725 devc->iomap = &als007_mix;
726 devc->iomap_sz = ARRAY_SIZE(als007_mix);
727 }
728 break;
729
730 default:
731 printk(KERN_WARNING "sb_mixer: Unsupported mixer type %d\n", devc->model);
732 return 0;
733 }
734
735 m = sound_alloc_mixerdev();
736 if (m == -1)
737 return 0;
738
739 mixer_devs[m] = kmalloc(sizeof(struct mixer_operations), GFP_KERNEL);
740 if (mixer_devs[m] == NULL)
741 {
742 printk(KERN_ERR "sb_mixer: Can't allocate memory\n");
743 sound_unload_mixerdev(m);
744 return 0;
745 }
746
747 if (devc->submodel != SUBMDL_ALS007)
748 memcpy ((char *) mixer_devs[m], (char *) &sb_mixer_operations, sizeof (struct mixer_operations));
749 else
750 memcpy ((char *) mixer_devs[m], (char *) &als007_mixer_operations, sizeof (struct mixer_operations));
751
752 mixer_devs[m]->devc = devc;
753
754 if (owner)
755 mixer_devs[m]->owner = owner;
756
757 devc->my_mixerdev = m;
758 sb_mixer_reset(devc);
759 return 1;
760}
761
762void sb_mixer_unload(sb_devc *devc)
763{
764 if (devc->my_mixerdev == -1)
765 return;
766
767 kfree(mixer_devs[devc->my_mixerdev]);
768 sound_unload_mixerdev(devc->my_mixerdev);
769 sbmixnum--;
770}
diff --git a/sound/oss/sb_mixer.h b/sound/oss/sb_mixer.h
deleted file mode 100644
index 4b9425f085e3..000000000000
--- a/sound/oss/sb_mixer.h
+++ /dev/null
@@ -1,105 +0,0 @@
1/*
2 * sound/oss/sb_mixer.h
3 *
4 * Definitions for the SB Pro and SB16 mixers
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 */
13
14/*
15 * Modified:
16 * Hunyue Yau Jan 6 1994
17 * Added defines for the Sound Galaxy NX Pro mixer.
18 *
19 * Rolf Fokkens Dec 20 1998
20 * Added defines for some ES188x chips.
21 *
22 * Rolf Fokkens Dec 27 1998
23 * Moved static stuff to sb_mixer.c
24 *
25 */
26/*
27 * Mixer registers
28 *
29 * NOTE! RECORD_SRC == IN_FILTER
30 */
31
32/*
33 * Mixer registers of SB Pro
34 */
35#define VOC_VOL 0x04
36#define MIC_VOL 0x0A
37#define MIC_MIX 0x0A
38#define RECORD_SRC 0x0C
39#define IN_FILTER 0x0C
40#define OUT_FILTER 0x0E
41#define MASTER_VOL 0x22
42#define FM_VOL 0x26
43#define CD_VOL 0x28
44#define LINE_VOL 0x2E
45#define IRQ_NR 0x80
46#define DMA_NR 0x81
47#define IRQ_STAT 0x82
48#define OPSW 0x3c
49
50/*
51 * Additional registers on the SG NX Pro
52 */
53#define COVOX_VOL 0x42
54#define TREBLE_LVL 0x44
55#define BASS_LVL 0x46
56
57#define FREQ_HI (1 << 3)/* Use High-frequency ANFI filters */
58#define FREQ_LOW 0 /* Use Low-frequency ANFI filters */
59#define FILT_ON 0 /* Yes, 0 to turn it on, 1 for off */
60#define FILT_OFF (1 << 5)
61
62#define MONO_DAC 0x00
63#define STEREO_DAC 0x02
64
65/*
66 * Mixer registers of SB16
67 */
68#define SB16_OMASK 0x3c
69#define SB16_IMASK_L 0x3d
70#define SB16_IMASK_R 0x3e
71
72#define LEFT_CHN 0
73#define RIGHT_CHN 1
74
75/*
76 * 3DSE register of AWE32/64
77 */
78#define AWE_3DSE 0x90
79
80/*
81 * Mixer registers of ALS007
82 */
83#define ALS007_RECORD_SRC 0x6c
84#define ALS007_OUTPUT_CTRL1 0x3c
85#define ALS007_OUTPUT_CTRL2 0x4c
86
87#define MIX_ENT(name, reg_l, bit_l, len_l, reg_r, bit_r, len_r) \
88 {{reg_l, bit_l, len_l}, {reg_r, bit_r, len_r}}
89
90/*
91 * Recording sources (SB Pro)
92 */
93
94#define SRC__MIC 1 /* Select Microphone recording source */
95#define SRC__CD 3 /* Select CD recording source */
96#define SRC__LINE 7 /* Use Line-in for recording source */
97
98/*
99 * Recording sources for ALS-007
100 */
101
102#define ALS007_MIC 4
103#define ALS007_LINE 6
104#define ALS007_CD 2
105#define ALS007_SYNTH 7
diff --git a/sound/oss/sequencer.c b/sound/oss/sequencer.c
deleted file mode 100644
index f19da4b47c1d..000000000000
--- a/sound/oss/sequencer.c
+++ /dev/null
@@ -1,1661 +0,0 @@
1/*
2 * sound/oss/sequencer.c
3 *
4 * The sequencer personality manager.
5 */
6/*
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 */
13/*
14 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
15 * Alan Cox : reformatted and fixed a pair of null pointer bugs
16 */
17#include <linux/kmod.h>
18#include <linux/spinlock.h>
19#include "sound_config.h"
20
21#include "midi_ctrl.h"
22#include "sleep.h"
23
24static int sequencer_ok;
25static struct sound_timer_operations *tmr;
26static int tmr_no = -1; /* Currently selected timer */
27static int pending_timer = -1; /* For timer change operation */
28extern unsigned long seq_time;
29
30static int obsolete_api_used;
31static DEFINE_SPINLOCK(lock);
32
33/*
34 * Local counts for number of synth and MIDI devices. These are initialized
35 * by the sequencer_open.
36 */
37static int max_mididev;
38static int max_synthdev;
39
40/*
41 * The seq_mode gives the operating mode of the sequencer:
42 * 1 = level1 (the default)
43 * 2 = level2 (extended capabilities)
44 */
45
46#define SEQ_1 1
47#define SEQ_2 2
48static int seq_mode = SEQ_1;
49
50static DECLARE_WAIT_QUEUE_HEAD(seq_sleeper);
51static DECLARE_WAIT_QUEUE_HEAD(midi_sleeper);
52
53static int midi_opened[MAX_MIDI_DEV];
54
55static int midi_written[MAX_MIDI_DEV];
56
57static unsigned long prev_input_time;
58static int prev_event_time;
59
60#include "tuning.h"
61
62#define EV_SZ 8
63#define IEV_SZ 8
64
65static unsigned char *queue;
66static unsigned char *iqueue;
67
68static volatile int qhead, qtail, qlen;
69static volatile int iqhead, iqtail, iqlen;
70static volatile int seq_playing;
71static volatile int sequencer_busy;
72static int output_threshold;
73static long pre_event_timeout;
74static unsigned synth_open_mask;
75
76static int seq_queue(unsigned char *note, char nonblock);
77static void seq_startplay(void);
78static int seq_sync(void);
79static void seq_reset(void);
80
81#if MAX_SYNTH_DEV > 15
82#error Too many synthesizer devices enabled.
83#endif
84
85int sequencer_read(int dev, struct file *file, char __user *buf, int count)
86{
87 int c = count, p = 0;
88 int ev_len;
89 unsigned long flags;
90
91 dev = dev >> 4;
92
93 ev_len = seq_mode == SEQ_1 ? 4 : 8;
94
95 spin_lock_irqsave(&lock,flags);
96
97 if (!iqlen)
98 {
99 spin_unlock_irqrestore(&lock,flags);
100 if (file->f_flags & O_NONBLOCK) {
101 return -EAGAIN;
102 }
103
104 oss_broken_sleep_on(&midi_sleeper, pre_event_timeout);
105 spin_lock_irqsave(&lock,flags);
106 if (!iqlen)
107 {
108 spin_unlock_irqrestore(&lock,flags);
109 return 0;
110 }
111 }
112 while (iqlen && c >= ev_len)
113 {
114 char *fixit = (char *) &iqueue[iqhead * IEV_SZ];
115 spin_unlock_irqrestore(&lock,flags);
116 if (copy_to_user(&(buf)[p], fixit, ev_len))
117 return count - c;
118 p += ev_len;
119 c -= ev_len;
120
121 spin_lock_irqsave(&lock,flags);
122 iqhead = (iqhead + 1) % SEQ_MAX_QUEUE;
123 iqlen--;
124 }
125 spin_unlock_irqrestore(&lock,flags);
126 return count - c;
127}
128
129static void sequencer_midi_output(int dev)
130{
131 /*
132 * Currently NOP
133 */
134}
135
136void seq_copy_to_input(unsigned char *event_rec, int len)
137{
138 unsigned long flags;
139
140 /*
141 * Verify that the len is valid for the current mode.
142 */
143
144 if (len != 4 && len != 8)
145 return;
146 if ((seq_mode == SEQ_1) != (len == 4))
147 return;
148
149 if (iqlen >= (SEQ_MAX_QUEUE - 1))
150 return; /* Overflow */
151
152 spin_lock_irqsave(&lock,flags);
153 memcpy(&iqueue[iqtail * IEV_SZ], event_rec, len);
154 iqlen++;
155 iqtail = (iqtail + 1) % SEQ_MAX_QUEUE;
156 wake_up(&midi_sleeper);
157 spin_unlock_irqrestore(&lock,flags);
158}
159EXPORT_SYMBOL(seq_copy_to_input);
160
161static void sequencer_midi_input(int dev, unsigned char data)
162{
163 unsigned int tstamp;
164 unsigned char event_rec[4];
165
166 if (data == 0xfe) /* Ignore active sensing */
167 return;
168
169 tstamp = jiffies - seq_time;
170
171 if (tstamp != prev_input_time)
172 {
173 tstamp = (tstamp << 8) | SEQ_WAIT;
174 seq_copy_to_input((unsigned char *) &tstamp, 4);
175 prev_input_time = tstamp;
176 }
177 event_rec[0] = SEQ_MIDIPUTC;
178 event_rec[1] = data;
179 event_rec[2] = dev;
180 event_rec[3] = 0;
181
182 seq_copy_to_input(event_rec, 4);
183}
184
185void seq_input_event(unsigned char *event_rec, int len)
186{
187 unsigned long this_time;
188
189 if (seq_mode == SEQ_2)
190 this_time = tmr->get_time(tmr_no);
191 else
192 this_time = jiffies - seq_time;
193
194 if (this_time != prev_input_time)
195 {
196 unsigned char tmp_event[8];
197
198 tmp_event[0] = EV_TIMING;
199 tmp_event[1] = TMR_WAIT_ABS;
200 tmp_event[2] = 0;
201 tmp_event[3] = 0;
202 *(unsigned int *) &tmp_event[4] = this_time;
203
204 seq_copy_to_input(tmp_event, 8);
205 prev_input_time = this_time;
206 }
207 seq_copy_to_input(event_rec, len);
208}
209EXPORT_SYMBOL(seq_input_event);
210
211int sequencer_write(int dev, struct file *file, const char __user *buf, int count)
212{
213 unsigned char event_rec[EV_SZ], ev_code;
214 int p = 0, c, ev_size;
215 int mode = translate_mode(file);
216
217 dev = dev >> 4;
218
219 if (mode == OPEN_READ)
220 return -EIO;
221
222 c = count;
223
224 while (c >= 4)
225 {
226 if (copy_from_user((char *) event_rec, &(buf)[p], 4))
227 goto out;
228 ev_code = event_rec[0];
229
230 if (ev_code == SEQ_FULLSIZE)
231 {
232 int err, fmt;
233
234 dev = *(unsigned short *) &event_rec[2];
235 if (dev < 0 || dev >= max_synthdev || synth_devs[dev] == NULL)
236 return -ENXIO;
237
238 if (!(synth_open_mask & (1 << dev)))
239 return -ENXIO;
240
241 fmt = (*(short *) &event_rec[0]) & 0xffff;
242 err = synth_devs[dev]->load_patch(dev, fmt, buf + p, c, 0);
243 if (err < 0)
244 return err;
245
246 return err;
247 }
248 if (ev_code >= 128)
249 {
250 if (seq_mode == SEQ_2 && ev_code == SEQ_EXTENDED)
251 {
252 printk(KERN_WARNING "Sequencer: Invalid level 2 event %x\n", ev_code);
253 return -EINVAL;
254 }
255 ev_size = 8;
256
257 if (c < ev_size)
258 {
259 if (!seq_playing)
260 seq_startplay();
261 return count - c;
262 }
263 if (copy_from_user((char *)&event_rec[4],
264 &(buf)[p + 4], 4))
265 goto out;
266
267 }
268 else
269 {
270 if (seq_mode == SEQ_2)
271 {
272 printk(KERN_WARNING "Sequencer: 4 byte event in level 2 mode\n");
273 return -EINVAL;
274 }
275 ev_size = 4;
276
277 if (event_rec[0] != SEQ_MIDIPUTC)
278 obsolete_api_used = 1;
279 }
280
281 if (event_rec[0] == SEQ_MIDIPUTC)
282 {
283 if (!midi_opened[event_rec[2]])
284 {
285 int err, mode;
286 int dev = event_rec[2];
287
288 if (dev >= max_mididev || midi_devs[dev]==NULL)
289 {
290 /*printk("Sequencer Error: Nonexistent MIDI device %d\n", dev);*/
291 return -ENXIO;
292 }
293 mode = translate_mode(file);
294
295 if ((err = midi_devs[dev]->open(dev, mode,
296 sequencer_midi_input, sequencer_midi_output)) < 0)
297 {
298 seq_reset();
299 printk(KERN_WARNING "Sequencer Error: Unable to open Midi #%d\n", dev);
300 return err;
301 }
302 midi_opened[dev] = 1;
303 }
304 }
305 if (!seq_queue(event_rec, (file->f_flags & (O_NONBLOCK) ? 1 : 0)))
306 {
307 int processed = count - c;
308
309 if (!seq_playing)
310 seq_startplay();
311
312 if (!processed && (file->f_flags & O_NONBLOCK))
313 return -EAGAIN;
314 else
315 return processed;
316 }
317 p += ev_size;
318 c -= ev_size;
319 }
320
321 if (!seq_playing)
322 seq_startplay();
323out:
324 return count;
325}
326
327static int seq_queue(unsigned char *note, char nonblock)
328{
329
330 /*
331 * Test if there is space in the queue
332 */
333
334 if (qlen >= SEQ_MAX_QUEUE)
335 if (!seq_playing)
336 seq_startplay(); /*
337 * Give chance to drain the queue
338 */
339
340 if (!nonblock && qlen >= SEQ_MAX_QUEUE && !waitqueue_active(&seq_sleeper)) {
341 /*
342 * Sleep until there is enough space on the queue
343 */
344 oss_broken_sleep_on(&seq_sleeper, MAX_SCHEDULE_TIMEOUT);
345 }
346 if (qlen >= SEQ_MAX_QUEUE)
347 {
348 return 0; /*
349 * To be sure
350 */
351 }
352 memcpy(&queue[qtail * EV_SZ], note, EV_SZ);
353
354 qtail = (qtail + 1) % SEQ_MAX_QUEUE;
355 qlen++;
356
357 return 1;
358}
359
360static int extended_event(unsigned char *q)
361{
362 int dev = q[2];
363
364 if (dev < 0 || dev >= max_synthdev)
365 return -ENXIO;
366
367 if (!(synth_open_mask & (1 << dev)))
368 return -ENXIO;
369
370 switch (q[1])
371 {
372 case SEQ_NOTEOFF:
373 synth_devs[dev]->kill_note(dev, q[3], q[4], q[5]);
374 break;
375
376 case SEQ_NOTEON:
377 if (q[4] > 127 && q[4] != 255)
378 return 0;
379
380 if (q[5] == 0)
381 {
382 synth_devs[dev]->kill_note(dev, q[3], q[4], q[5]);
383 break;
384 }
385 synth_devs[dev]->start_note(dev, q[3], q[4], q[5]);
386 break;
387
388 case SEQ_PGMCHANGE:
389 synth_devs[dev]->set_instr(dev, q[3], q[4]);
390 break;
391
392 case SEQ_AFTERTOUCH:
393 synth_devs[dev]->aftertouch(dev, q[3], q[4]);
394 break;
395
396 case SEQ_BALANCE:
397 synth_devs[dev]->panning(dev, q[3], (char) q[4]);
398 break;
399
400 case SEQ_CONTROLLER:
401 synth_devs[dev]->controller(dev, q[3], q[4], (short) (q[5] | (q[6] << 8)));
402 break;
403
404 case SEQ_VOLMODE:
405 if (synth_devs[dev]->volume_method != NULL)
406 synth_devs[dev]->volume_method(dev, q[3]);
407 break;
408
409 default:
410 return -EINVAL;
411 }
412 return 0;
413}
414
415static int find_voice(int dev, int chn, int note)
416{
417 unsigned short key;
418 int i;
419
420 key = (chn << 8) | (note + 1);
421 for (i = 0; i < synth_devs[dev]->alloc.max_voice; i++)
422 if (synth_devs[dev]->alloc.map[i] == key)
423 return i;
424 return -1;
425}
426
427static int alloc_voice(int dev, int chn, int note)
428{
429 unsigned short key;
430 int voice;
431
432 key = (chn << 8) | (note + 1);
433
434 voice = synth_devs[dev]->alloc_voice(dev, chn, note,
435 &synth_devs[dev]->alloc);
436 synth_devs[dev]->alloc.map[voice] = key;
437 synth_devs[dev]->alloc.alloc_times[voice] =
438 synth_devs[dev]->alloc.timestamp++;
439 return voice;
440}
441
442static void seq_chn_voice_event(unsigned char *event_rec)
443{
444#define dev event_rec[1]
445#define cmd event_rec[2]
446#define chn event_rec[3]
447#define note event_rec[4]
448#define parm event_rec[5]
449
450 int voice = -1;
451
452 if ((int) dev > max_synthdev || synth_devs[dev] == NULL)
453 return;
454 if (!(synth_open_mask & (1 << dev)))
455 return;
456 if (!synth_devs[dev])
457 return;
458
459 if (seq_mode == SEQ_2)
460 {
461 if (synth_devs[dev]->alloc_voice)
462 voice = find_voice(dev, chn, note);
463
464 if (cmd == MIDI_NOTEON && parm == 0)
465 {
466 cmd = MIDI_NOTEOFF;
467 parm = 64;
468 }
469 }
470
471 switch (cmd)
472 {
473 case MIDI_NOTEON:
474 if (note > 127 && note != 255) /* Not a seq2 feature */
475 return;
476
477 if (voice == -1 && seq_mode == SEQ_2 && synth_devs[dev]->alloc_voice)
478 {
479 /* Internal synthesizer (FM, GUS, etc) */
480 voice = alloc_voice(dev, chn, note);
481 }
482 if (voice == -1)
483 voice = chn;
484
485 if (seq_mode == SEQ_2 && (int) dev < num_synths)
486 {
487 /*
488 * The MIDI channel 10 is a percussive channel. Use the note
489 * number to select the proper patch (128 to 255) to play.
490 */
491
492 if (chn == 9)
493 {
494 synth_devs[dev]->set_instr(dev, voice, 128 + note);
495 synth_devs[dev]->chn_info[chn].pgm_num = 128 + note;
496 }
497 synth_devs[dev]->setup_voice(dev, voice, chn);
498 }
499 synth_devs[dev]->start_note(dev, voice, note, parm);
500 break;
501
502 case MIDI_NOTEOFF:
503 if (voice == -1)
504 voice = chn;
505 synth_devs[dev]->kill_note(dev, voice, note, parm);
506 break;
507
508 case MIDI_KEY_PRESSURE:
509 if (voice == -1)
510 voice = chn;
511 synth_devs[dev]->aftertouch(dev, voice, parm);
512 break;
513
514 default:;
515 }
516#undef dev
517#undef cmd
518#undef chn
519#undef note
520#undef parm
521}
522
523
524static void seq_chn_common_event(unsigned char *event_rec)
525{
526 unsigned char dev = event_rec[1];
527 unsigned char cmd = event_rec[2];
528 unsigned char chn = event_rec[3];
529 unsigned char p1 = event_rec[4];
530
531 /* unsigned char p2 = event_rec[5]; */
532 unsigned short w14 = *(short *) &event_rec[6];
533
534 if ((int) dev > max_synthdev || synth_devs[dev] == NULL)
535 return;
536 if (!(synth_open_mask & (1 << dev)))
537 return;
538 if (!synth_devs[dev])
539 return;
540
541 switch (cmd)
542 {
543 case MIDI_PGM_CHANGE:
544 if (seq_mode == SEQ_2)
545 {
546 if (chn > 15)
547 break;
548
549 synth_devs[dev]->chn_info[chn].pgm_num = p1;
550 if ((int) dev >= num_synths)
551 synth_devs[dev]->set_instr(dev, chn, p1);
552 }
553 else
554 synth_devs[dev]->set_instr(dev, chn, p1);
555
556 break;
557
558 case MIDI_CTL_CHANGE:
559 if (seq_mode == SEQ_2)
560 {
561 if (chn > 15 || p1 > 127)
562 break;
563
564 synth_devs[dev]->chn_info[chn].controllers[p1] = w14 & 0x7f;
565
566 if (p1 < 32) /* Setting MSB should clear LSB to 0 */
567 synth_devs[dev]->chn_info[chn].controllers[p1 + 32] = 0;
568
569 if ((int) dev < num_synths)
570 {
571 int val = w14 & 0x7f;
572 int i, key;
573
574 if (p1 < 64) /* Combine MSB and LSB */
575 {
576 val = ((synth_devs[dev]->
577 chn_info[chn].controllers[p1 & ~32] & 0x7f) << 7)
578 | (synth_devs[dev]->
579 chn_info[chn].controllers[p1 | 32] & 0x7f);
580 p1 &= ~32;
581 }
582 /* Handle all playing notes on this channel */
583
584 key = ((int) chn << 8);
585
586 for (i = 0; i < synth_devs[dev]->alloc.max_voice; i++)
587 if ((synth_devs[dev]->alloc.map[i] & 0xff00) == key)
588 synth_devs[dev]->controller(dev, i, p1, val);
589 }
590 else
591 synth_devs[dev]->controller(dev, chn, p1, w14);
592 }
593 else /* Mode 1 */
594 synth_devs[dev]->controller(dev, chn, p1, w14);
595 break;
596
597 case MIDI_PITCH_BEND:
598 if (seq_mode == SEQ_2)
599 {
600 if (chn > 15)
601 break;
602
603 synth_devs[dev]->chn_info[chn].bender_value = w14;
604
605 if ((int) dev < num_synths)
606 {
607 /* Handle all playing notes on this channel */
608 int i, key;
609
610 key = (chn << 8);
611
612 for (i = 0; i < synth_devs[dev]->alloc.max_voice; i++)
613 if ((synth_devs[dev]->alloc.map[i] & 0xff00) == key)
614 synth_devs[dev]->bender(dev, i, w14);
615 }
616 else
617 synth_devs[dev]->bender(dev, chn, w14);
618 }
619 else /* MODE 1 */
620 synth_devs[dev]->bender(dev, chn, w14);
621 break;
622
623 default:;
624 }
625}
626
627static int seq_timing_event(unsigned char *event_rec)
628{
629 unsigned char cmd = event_rec[1];
630 unsigned int parm = *(int *) &event_rec[4];
631
632 if (seq_mode == SEQ_2)
633 {
634 int ret;
635
636 if ((ret = tmr->event(tmr_no, event_rec)) == TIMER_ARMED)
637 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
638 wake_up(&seq_sleeper);
639 return ret;
640 }
641 switch (cmd)
642 {
643 case TMR_WAIT_REL:
644 parm += prev_event_time;
645
646 /*
647 * NOTE! No break here. Execution of TMR_WAIT_REL continues in the
648 * next case (TMR_WAIT_ABS)
649 */
650
651 case TMR_WAIT_ABS:
652 if (parm > 0)
653 {
654 long time;
655
656 time = parm;
657 prev_event_time = time;
658
659 seq_playing = 1;
660 request_sound_timer(time);
661
662 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
663 wake_up(&seq_sleeper);
664 return TIMER_ARMED;
665 }
666 break;
667
668 case TMR_START:
669 seq_time = jiffies;
670 prev_input_time = 0;
671 prev_event_time = 0;
672 break;
673
674 case TMR_STOP:
675 break;
676
677 case TMR_CONTINUE:
678 break;
679
680 case TMR_TEMPO:
681 break;
682
683 case TMR_ECHO:
684 parm = (parm << 8 | SEQ_ECHO);
685 seq_copy_to_input((unsigned char *) &parm, 4);
686 break;
687
688 default:;
689 }
690
691 return TIMER_NOT_ARMED;
692}
693
694static void seq_local_event(unsigned char *event_rec)
695{
696 unsigned char cmd = event_rec[1];
697 unsigned int parm = *((unsigned int *) &event_rec[4]);
698
699 switch (cmd)
700 {
701 case LOCL_STARTAUDIO:
702 DMAbuf_start_devices(parm);
703 break;
704
705 default:;
706 }
707}
708
709static void seq_sysex_message(unsigned char *event_rec)
710{
711 unsigned int dev = event_rec[1];
712 int i, l = 0;
713 unsigned char *buf = &event_rec[2];
714
715 if (dev > max_synthdev)
716 return;
717 if (!(synth_open_mask & (1 << dev)))
718 return;
719 if (!synth_devs[dev])
720 return;
721
722 l = 0;
723 for (i = 0; i < 6 && buf[i] != 0xff; i++)
724 l = i + 1;
725
726 if (!synth_devs[dev]->send_sysex)
727 return;
728 if (l > 0)
729 synth_devs[dev]->send_sysex(dev, buf, l);
730}
731
732static int play_event(unsigned char *q)
733{
734 /*
735 * NOTE! This routine returns
736 * 0 = normal event played.
737 * 1 = Timer armed. Suspend playback until timer callback.
738 * 2 = MIDI output buffer full. Restore queue and suspend until timer
739 */
740 unsigned int *delay;
741
742 switch (q[0])
743 {
744 case SEQ_NOTEOFF:
745 if (synth_open_mask & (1 << 0))
746 if (synth_devs[0])
747 synth_devs[0]->kill_note(0, q[1], 255, q[3]);
748 break;
749
750 case SEQ_NOTEON:
751 if (q[4] < 128 || q[4] == 255)
752 if (synth_open_mask & (1 << 0))
753 if (synth_devs[0])
754 synth_devs[0]->start_note(0, q[1], q[2], q[3]);
755 break;
756
757 case SEQ_WAIT:
758 delay = (unsigned int *) q; /*
759 * Bytes 1 to 3 are containing the *
760 * delay in 'ticks'
761 */
762 *delay = (*delay >> 8) & 0xffffff;
763
764 if (*delay > 0)
765 {
766 long time;
767
768 seq_playing = 1;
769 time = *delay;
770 prev_event_time = time;
771
772 request_sound_timer(time);
773
774 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
775 wake_up(&seq_sleeper);
776 /*
777 * The timer is now active and will reinvoke this function
778 * after the timer expires. Return to the caller now.
779 */
780 return 1;
781 }
782 break;
783
784 case SEQ_PGMCHANGE:
785 if (synth_open_mask & (1 << 0))
786 if (synth_devs[0])
787 synth_devs[0]->set_instr(0, q[1], q[2]);
788 break;
789
790 case SEQ_SYNCTIMER: /*
791 * Reset timer
792 */
793 seq_time = jiffies;
794 prev_input_time = 0;
795 prev_event_time = 0;
796 break;
797
798 case SEQ_MIDIPUTC: /*
799 * Put a midi character
800 */
801 if (midi_opened[q[2]])
802 {
803 int dev;
804
805 dev = q[2];
806
807 if (dev < 0 || dev >= num_midis || midi_devs[dev] == NULL)
808 break;
809
810 if (!midi_devs[dev]->outputc(dev, q[1]))
811 {
812 /*
813 * Output FIFO is full. Wait one timer cycle and try again.
814 */
815
816 seq_playing = 1;
817 request_sound_timer(-1);
818 return 2;
819 }
820 else
821 midi_written[dev] = 1;
822 }
823 break;
824
825 case SEQ_ECHO:
826 seq_copy_to_input(q, 4); /*
827 * Echo back to the process
828 */
829 break;
830
831 case SEQ_PRIVATE:
832 if ((int) q[1] < max_synthdev)
833 synth_devs[q[1]]->hw_control(q[1], q);
834 break;
835
836 case SEQ_EXTENDED:
837 extended_event(q);
838 break;
839
840 case EV_CHN_VOICE:
841 seq_chn_voice_event(q);
842 break;
843
844 case EV_CHN_COMMON:
845 seq_chn_common_event(q);
846 break;
847
848 case EV_TIMING:
849 if (seq_timing_event(q) == TIMER_ARMED)
850 {
851 return 1;
852 }
853 break;
854
855 case EV_SEQ_LOCAL:
856 seq_local_event(q);
857 break;
858
859 case EV_SYSEX:
860 seq_sysex_message(q);
861 break;
862
863 default:;
864 }
865 return 0;
866}
867
868/* called also as timer in irq context */
869static void seq_startplay(void)
870{
871 int this_one, action;
872 unsigned long flags;
873
874 while (qlen > 0)
875 {
876
877 spin_lock_irqsave(&lock,flags);
878 qhead = ((this_one = qhead) + 1) % SEQ_MAX_QUEUE;
879 qlen--;
880 spin_unlock_irqrestore(&lock,flags);
881
882 seq_playing = 1;
883
884 if ((action = play_event(&queue[this_one * EV_SZ])))
885 { /* Suspend playback. Next timer routine invokes this routine again */
886 if (action == 2)
887 {
888 qlen++;
889 qhead = this_one;
890 }
891 return;
892 }
893 }
894
895 seq_playing = 0;
896
897 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
898 wake_up(&seq_sleeper);
899}
900
901static void reset_controllers(int dev, unsigned char *controller, int update_dev)
902{
903 int i;
904 for (i = 0; i < 128; i++)
905 controller[i] = ctrl_def_values[i];
906}
907
908static void setup_mode2(void)
909{
910 int dev;
911
912 max_synthdev = num_synths;
913
914 for (dev = 0; dev < num_midis; dev++)
915 {
916 if (midi_devs[dev] && midi_devs[dev]->converter != NULL)
917 {
918 synth_devs[max_synthdev++] = midi_devs[dev]->converter;
919 }
920 }
921
922 for (dev = 0; dev < max_synthdev; dev++)
923 {
924 int chn;
925
926 synth_devs[dev]->sysex_ptr = 0;
927 synth_devs[dev]->emulation = 0;
928
929 for (chn = 0; chn < 16; chn++)
930 {
931 synth_devs[dev]->chn_info[chn].pgm_num = 0;
932 reset_controllers(dev,
933 synth_devs[dev]->chn_info[chn].controllers,0);
934 synth_devs[dev]->chn_info[chn].bender_value = (1 << 7); /* Neutral */
935 synth_devs[dev]->chn_info[chn].bender_range = 200;
936 }
937 }
938 max_mididev = 0;
939 seq_mode = SEQ_2;
940}
941
942int sequencer_open(int dev, struct file *file)
943{
944 int retval, mode, i;
945 int level, tmp;
946
947 if (!sequencer_ok)
948 sequencer_init();
949
950 level = ((dev & 0x0f) == SND_DEV_SEQ2) ? 2 : 1;
951
952 dev = dev >> 4;
953 mode = translate_mode(file);
954
955 if (!sequencer_ok)
956 {
957/* printk("Sound card: sequencer not initialized\n");*/
958 return -ENXIO;
959 }
960 if (dev) /* Patch manager device (obsolete) */
961 return -ENXIO;
962
963 if(synth_devs[dev] == NULL)
964 request_module("synth0");
965
966 if (mode == OPEN_READ)
967 {
968 if (!num_midis)
969 {
970 /*printk("Sequencer: No MIDI devices. Input not possible\n");*/
971 sequencer_busy = 0;
972 return -ENXIO;
973 }
974 }
975 if (sequencer_busy)
976 {
977 return -EBUSY;
978 }
979 sequencer_busy = 1;
980 obsolete_api_used = 0;
981
982 max_mididev = num_midis;
983 max_synthdev = num_synths;
984 pre_event_timeout = MAX_SCHEDULE_TIMEOUT;
985 seq_mode = SEQ_1;
986
987 if (pending_timer != -1)
988 {
989 tmr_no = pending_timer;
990 pending_timer = -1;
991 }
992 if (tmr_no == -1) /* Not selected yet */
993 {
994 int i, best;
995
996 best = -1;
997 for (i = 0; i < num_sound_timers; i++)
998 if (sound_timer_devs[i] && sound_timer_devs[i]->priority > best)
999 {
1000 tmr_no = i;
1001 best = sound_timer_devs[i]->priority;
1002 }
1003 if (tmr_no == -1) /* Should not be */
1004 tmr_no = 0;
1005 }
1006 tmr = sound_timer_devs[tmr_no];
1007
1008 if (level == 2)
1009 {
1010 if (tmr == NULL)
1011 {
1012 /*printk("sequencer: No timer for level 2\n");*/
1013 sequencer_busy = 0;
1014 return -ENXIO;
1015 }
1016 setup_mode2();
1017 }
1018 if (!max_synthdev && !max_mididev)
1019 {
1020 sequencer_busy=0;
1021 return -ENXIO;
1022 }
1023
1024 synth_open_mask = 0;
1025
1026 for (i = 0; i < max_mididev; i++)
1027 {
1028 midi_opened[i] = 0;
1029 midi_written[i] = 0;
1030 }
1031
1032 for (i = 0; i < max_synthdev; i++)
1033 {
1034 if (synth_devs[i]==NULL)
1035 continue;
1036
1037 if (!try_module_get(synth_devs[i]->owner))
1038 continue;
1039
1040 if ((tmp = synth_devs[i]->open(i, mode)) < 0)
1041 {
1042 printk(KERN_WARNING "Sequencer: Warning! Cannot open synth device #%d (%d)\n", i, tmp);
1043 if (synth_devs[i]->midi_dev)
1044 printk(KERN_WARNING "(Maps to MIDI dev #%d)\n", synth_devs[i]->midi_dev);
1045 }
1046 else
1047 {
1048 synth_open_mask |= (1 << i);
1049 if (synth_devs[i]->midi_dev)
1050 midi_opened[synth_devs[i]->midi_dev] = 1;
1051 }
1052 }
1053
1054 seq_time = jiffies;
1055
1056 prev_input_time = 0;
1057 prev_event_time = 0;
1058
1059 if (seq_mode == SEQ_1 && (mode == OPEN_READ || mode == OPEN_READWRITE))
1060 {
1061 /*
1062 * Initialize midi input devices
1063 */
1064
1065 for (i = 0; i < max_mididev; i++)
1066 if (!midi_opened[i] && midi_devs[i])
1067 {
1068 if (!try_module_get(midi_devs[i]->owner))
1069 continue;
1070
1071 if ((retval = midi_devs[i]->open(i, mode,
1072 sequencer_midi_input, sequencer_midi_output)) >= 0)
1073 {
1074 midi_opened[i] = 1;
1075 }
1076 }
1077 }
1078
1079 if (seq_mode == SEQ_2) {
1080 if (try_module_get(tmr->owner))
1081 tmr->open(tmr_no, seq_mode);
1082 }
1083
1084 init_waitqueue_head(&seq_sleeper);
1085 init_waitqueue_head(&midi_sleeper);
1086 output_threshold = SEQ_MAX_QUEUE / 2;
1087
1088 return 0;
1089}
1090
1091static void seq_drain_midi_queues(void)
1092{
1093 int i, n;
1094
1095 /*
1096 * Give the Midi drivers time to drain their output queues
1097 */
1098
1099 n = 1;
1100
1101 while (!signal_pending(current) && n)
1102 {
1103 n = 0;
1104
1105 for (i = 0; i < max_mididev; i++)
1106 if (midi_opened[i] && midi_written[i])
1107 if (midi_devs[i]->buffer_status != NULL)
1108 if (midi_devs[i]->buffer_status(i))
1109 n++;
1110
1111 /*
1112 * Let's have a delay
1113 */
1114
1115 if (n)
1116 oss_broken_sleep_on(&seq_sleeper, HZ/10);
1117 }
1118}
1119
1120void sequencer_release(int dev, struct file *file)
1121{
1122 int i;
1123 int mode = translate_mode(file);
1124
1125 dev = dev >> 4;
1126
1127 /*
1128 * Wait until the queue is empty (if we don't have nonblock)
1129 */
1130
1131 if (mode != OPEN_READ && !(file->f_flags & O_NONBLOCK))
1132 {
1133 while (!signal_pending(current) && qlen > 0)
1134 {
1135 seq_sync();
1136 oss_broken_sleep_on(&seq_sleeper, 3*HZ);
1137 /* Extra delay */
1138 }
1139 }
1140
1141 if (mode != OPEN_READ)
1142 seq_drain_midi_queues(); /*
1143 * Ensure the output queues are empty
1144 */
1145 seq_reset();
1146 if (mode != OPEN_READ)
1147 seq_drain_midi_queues(); /*
1148 * Flush the all notes off messages
1149 */
1150
1151 for (i = 0; i < max_synthdev; i++)
1152 {
1153 if (synth_open_mask & (1 << i)) /*
1154 * Actually opened
1155 */
1156 if (synth_devs[i])
1157 {
1158 synth_devs[i]->close(i);
1159
1160 module_put(synth_devs[i]->owner);
1161
1162 if (synth_devs[i]->midi_dev)
1163 midi_opened[synth_devs[i]->midi_dev] = 0;
1164 }
1165 }
1166
1167 for (i = 0; i < max_mididev; i++)
1168 {
1169 if (midi_opened[i]) {
1170 midi_devs[i]->close(i);
1171 module_put(midi_devs[i]->owner);
1172 }
1173 }
1174
1175 if (seq_mode == SEQ_2) {
1176 tmr->close(tmr_no);
1177 module_put(tmr->owner);
1178 }
1179
1180 if (obsolete_api_used)
1181 printk(KERN_WARNING "/dev/music: Obsolete (4 byte) API was used by %s\n", current->comm);
1182 sequencer_busy = 0;
1183}
1184
1185static int seq_sync(void)
1186{
1187 if (qlen && !seq_playing && !signal_pending(current))
1188 seq_startplay();
1189
1190 if (qlen > 0)
1191 oss_broken_sleep_on(&seq_sleeper, HZ);
1192 return qlen;
1193}
1194
1195static void midi_outc(int dev, unsigned char data)
1196{
1197 /*
1198 * NOTE! Calls sleep(). Don't call this from interrupt.
1199 */
1200
1201 int n;
1202 unsigned long flags;
1203
1204 /*
1205 * This routine sends one byte to the Midi channel.
1206 * If the output FIFO is full, it waits until there
1207 * is space in the queue
1208 */
1209
1210 n = 3 * HZ; /* Timeout */
1211
1212 spin_lock_irqsave(&lock,flags);
1213 while (n && !midi_devs[dev]->outputc(dev, data)) {
1214 oss_broken_sleep_on(&seq_sleeper, HZ/25);
1215 n--;
1216 }
1217 spin_unlock_irqrestore(&lock,flags);
1218}
1219
1220static void seq_reset(void)
1221{
1222 /*
1223 * NOTE! Calls sleep(). Don't call this from interrupt.
1224 */
1225
1226 int i;
1227 int chn;
1228 unsigned long flags;
1229
1230 sound_stop_timer();
1231
1232 seq_time = jiffies;
1233 prev_input_time = 0;
1234 prev_event_time = 0;
1235
1236 qlen = qhead = qtail = 0;
1237 iqlen = iqhead = iqtail = 0;
1238
1239 for (i = 0; i < max_synthdev; i++)
1240 if (synth_open_mask & (1 << i))
1241 if (synth_devs[i])
1242 synth_devs[i]->reset(i);
1243
1244 if (seq_mode == SEQ_2)
1245 {
1246 for (chn = 0; chn < 16; chn++)
1247 for (i = 0; i < max_synthdev; i++)
1248 if (synth_open_mask & (1 << i))
1249 if (synth_devs[i])
1250 {
1251 synth_devs[i]->controller(i, chn, 123, 0); /* All notes off */
1252 synth_devs[i]->controller(i, chn, 121, 0); /* Reset all ctl */
1253 synth_devs[i]->bender(i, chn, 1 << 13); /* Bender off */
1254 }
1255 }
1256 else /* seq_mode == SEQ_1 */
1257 {
1258 for (i = 0; i < max_mididev; i++)
1259 if (midi_written[i]) /*
1260 * Midi used. Some notes may still be playing
1261 */
1262 {
1263 /*
1264 * Sending just a ACTIVE SENSING message should be enough to stop all
1265 * playing notes. Since there are devices not recognizing the
1266 * active sensing, we have to send some all notes off messages also.
1267 */
1268 midi_outc(i, 0xfe);
1269
1270 for (chn = 0; chn < 16; chn++)
1271 {
1272 midi_outc(i, (unsigned char) (0xb0 + (chn & 0x0f))); /* control change */
1273 midi_outc(i, 0x7b); /* All notes off */
1274 midi_outc(i, 0); /* Dummy parameter */
1275 }
1276
1277 midi_devs[i]->close(i);
1278
1279 midi_written[i] = 0;
1280 midi_opened[i] = 0;
1281 }
1282 }
1283
1284 seq_playing = 0;
1285
1286 spin_lock_irqsave(&lock,flags);
1287
1288 if (waitqueue_active(&seq_sleeper)) {
1289 /* printk( "Sequencer Warning: Unexpected sleeping process - Waking up\n"); */
1290 wake_up(&seq_sleeper);
1291 }
1292 spin_unlock_irqrestore(&lock,flags);
1293}
1294
1295static void seq_panic(void)
1296{
1297 /*
1298 * This routine is called by the application in case the user
1299 * wants to reset the system to the default state.
1300 */
1301
1302 seq_reset();
1303
1304 /*
1305 * Since some of the devices don't recognize the active sensing and
1306 * all notes off messages, we have to shut all notes manually.
1307 *
1308 * TO BE IMPLEMENTED LATER
1309 */
1310
1311 /*
1312 * Also return the controllers to their default states
1313 */
1314}
1315
1316int sequencer_ioctl(int dev, struct file *file, unsigned int cmd, void __user *arg)
1317{
1318 int midi_dev, orig_dev, val, err;
1319 int mode = translate_mode(file);
1320 struct synth_info inf;
1321 struct seq_event_rec event_rec;
1322 int __user *p = arg;
1323
1324 orig_dev = dev = dev >> 4;
1325
1326 switch (cmd)
1327 {
1328 case SNDCTL_TMR_TIMEBASE:
1329 case SNDCTL_TMR_TEMPO:
1330 case SNDCTL_TMR_START:
1331 case SNDCTL_TMR_STOP:
1332 case SNDCTL_TMR_CONTINUE:
1333 case SNDCTL_TMR_METRONOME:
1334 case SNDCTL_TMR_SOURCE:
1335 if (seq_mode != SEQ_2)
1336 return -EINVAL;
1337 return tmr->ioctl(tmr_no, cmd, arg);
1338
1339 case SNDCTL_TMR_SELECT:
1340 if (seq_mode != SEQ_2)
1341 return -EINVAL;
1342 if (get_user(pending_timer, p))
1343 return -EFAULT;
1344 if (pending_timer < 0 || pending_timer >= num_sound_timers || sound_timer_devs[pending_timer] == NULL)
1345 {
1346 pending_timer = -1;
1347 return -EINVAL;
1348 }
1349 val = pending_timer;
1350 break;
1351
1352 case SNDCTL_SEQ_PANIC:
1353 seq_panic();
1354 return -EINVAL;
1355
1356 case SNDCTL_SEQ_SYNC:
1357 if (mode == OPEN_READ)
1358 return 0;
1359 while (qlen > 0 && !signal_pending(current))
1360 seq_sync();
1361 return qlen ? -EINTR : 0;
1362
1363 case SNDCTL_SEQ_RESET:
1364 seq_reset();
1365 return 0;
1366
1367 case SNDCTL_SEQ_TESTMIDI:
1368 if (__get_user(midi_dev, p))
1369 return -EFAULT;
1370 if (midi_dev < 0 || midi_dev >= max_mididev || !midi_devs[midi_dev])
1371 return -ENXIO;
1372
1373 if (!midi_opened[midi_dev] &&
1374 (err = midi_devs[midi_dev]->open(midi_dev, mode, sequencer_midi_input,
1375 sequencer_midi_output)) < 0)
1376 return err;
1377 midi_opened[midi_dev] = 1;
1378 return 0;
1379
1380 case SNDCTL_SEQ_GETINCOUNT:
1381 if (mode == OPEN_WRITE)
1382 return 0;
1383 val = iqlen;
1384 break;
1385
1386 case SNDCTL_SEQ_GETOUTCOUNT:
1387 if (mode == OPEN_READ)
1388 return 0;
1389 val = SEQ_MAX_QUEUE - qlen;
1390 break;
1391
1392 case SNDCTL_SEQ_GETTIME:
1393 if (seq_mode == SEQ_2)
1394 return tmr->ioctl(tmr_no, cmd, arg);
1395 val = jiffies - seq_time;
1396 break;
1397
1398 case SNDCTL_SEQ_CTRLRATE:
1399 /*
1400 * If *arg == 0, just return the current rate
1401 */
1402 if (seq_mode == SEQ_2)
1403 return tmr->ioctl(tmr_no, cmd, arg);
1404
1405 if (get_user(val, p))
1406 return -EFAULT;
1407 if (val != 0)
1408 return -EINVAL;
1409 val = HZ;
1410 break;
1411
1412 case SNDCTL_SEQ_RESETSAMPLES:
1413 case SNDCTL_SYNTH_REMOVESAMPLE:
1414 case SNDCTL_SYNTH_CONTROL:
1415 if (get_user(dev, p))
1416 return -EFAULT;
1417 if (dev < 0 || dev >= num_synths || synth_devs[dev] == NULL)
1418 return -ENXIO;
1419 if (!(synth_open_mask & (1 << dev)) && !orig_dev)
1420 return -EBUSY;
1421 return synth_devs[dev]->ioctl(dev, cmd, arg);
1422
1423 case SNDCTL_SEQ_NRSYNTHS:
1424 val = max_synthdev;
1425 break;
1426
1427 case SNDCTL_SEQ_NRMIDIS:
1428 val = max_mididev;
1429 break;
1430
1431 case SNDCTL_SYNTH_MEMAVL:
1432 if (get_user(dev, p))
1433 return -EFAULT;
1434 if (dev < 0 || dev >= num_synths || synth_devs[dev] == NULL)
1435 return -ENXIO;
1436 if (!(synth_open_mask & (1 << dev)) && !orig_dev)
1437 return -EBUSY;
1438 val = synth_devs[dev]->ioctl(dev, cmd, arg);
1439 break;
1440
1441 case SNDCTL_FM_4OP_ENABLE:
1442 if (get_user(dev, p))
1443 return -EFAULT;
1444 if (dev < 0 || dev >= num_synths || synth_devs[dev] == NULL)
1445 return -ENXIO;
1446 if (!(synth_open_mask & (1 << dev)))
1447 return -ENXIO;
1448 synth_devs[dev]->ioctl(dev, cmd, arg);
1449 return 0;
1450
1451 case SNDCTL_SYNTH_INFO:
1452 if (get_user(dev, &((struct synth_info __user *)arg)->device))
1453 return -EFAULT;
1454 if (dev < 0 || dev >= max_synthdev)
1455 return -ENXIO;
1456 if (!(synth_open_mask & (1 << dev)) && !orig_dev)
1457 return -EBUSY;
1458 return synth_devs[dev]->ioctl(dev, cmd, arg);
1459
1460 /* Like SYNTH_INFO but returns ID in the name field */
1461 case SNDCTL_SYNTH_ID:
1462 if (get_user(dev, &((struct synth_info __user *)arg)->device))
1463 return -EFAULT;
1464 if (dev < 0 || dev >= max_synthdev)
1465 return -ENXIO;
1466 if (!(synth_open_mask & (1 << dev)) && !orig_dev)
1467 return -EBUSY;
1468 memcpy(&inf, synth_devs[dev]->info, sizeof(inf));
1469 strlcpy(inf.name, synth_devs[dev]->id, sizeof(inf.name));
1470 inf.device = dev;
1471 return copy_to_user(arg, &inf, sizeof(inf))?-EFAULT:0;
1472
1473 case SNDCTL_SEQ_OUTOFBAND:
1474 if (copy_from_user(&event_rec, arg, sizeof(event_rec)))
1475 return -EFAULT;
1476 play_event(event_rec.arr);
1477 return 0;
1478
1479 case SNDCTL_MIDI_INFO:
1480 if (get_user(dev, &((struct midi_info __user *)arg)->device))
1481 return -EFAULT;
1482 if (dev < 0 || dev >= max_mididev || !midi_devs[dev])
1483 return -ENXIO;
1484 midi_devs[dev]->info.device = dev;
1485 return copy_to_user(arg, &midi_devs[dev]->info, sizeof(struct midi_info))?-EFAULT:0;
1486
1487 case SNDCTL_SEQ_THRESHOLD:
1488 if (get_user(val, p))
1489 return -EFAULT;
1490 if (val < 1)
1491 val = 1;
1492 if (val >= SEQ_MAX_QUEUE)
1493 val = SEQ_MAX_QUEUE - 1;
1494 output_threshold = val;
1495 return 0;
1496
1497 case SNDCTL_MIDI_PRETIME:
1498 if (get_user(val, p))
1499 return -EFAULT;
1500 if (val < 0)
1501 val = 0;
1502 val = (HZ * val) / 10;
1503 pre_event_timeout = val;
1504 break;
1505
1506 default:
1507 if (mode == OPEN_READ)
1508 return -EIO;
1509 if (!synth_devs[0])
1510 return -ENXIO;
1511 if (!(synth_open_mask & (1 << 0)))
1512 return -ENXIO;
1513 if (!synth_devs[0]->ioctl)
1514 return -EINVAL;
1515 return synth_devs[0]->ioctl(0, cmd, arg);
1516 }
1517 return put_user(val, p);
1518}
1519
1520/* No kernel lock - we're using the global irq lock here */
1521unsigned int sequencer_poll(int dev, struct file *file, poll_table * wait)
1522{
1523 unsigned long flags;
1524 unsigned int mask = 0;
1525
1526 dev = dev >> 4;
1527
1528 spin_lock_irqsave(&lock,flags);
1529 /* input */
1530 poll_wait(file, &midi_sleeper, wait);
1531 if (iqlen)
1532 mask |= POLLIN | POLLRDNORM;
1533
1534 /* output */
1535 poll_wait(file, &seq_sleeper, wait);
1536 if ((SEQ_MAX_QUEUE - qlen) >= output_threshold)
1537 mask |= POLLOUT | POLLWRNORM;
1538 spin_unlock_irqrestore(&lock,flags);
1539 return mask;
1540}
1541
1542
1543void sequencer_timer(unsigned long dummy)
1544{
1545 seq_startplay();
1546}
1547EXPORT_SYMBOL(sequencer_timer);
1548
1549int note_to_freq(int note_num)
1550{
1551
1552 /*
1553 * This routine converts a midi note to a frequency (multiplied by 1000)
1554 */
1555
1556 int note, octave, note_freq;
1557 static int notes[] =
1558 {
1559 261632, 277189, 293671, 311132, 329632, 349232,
1560 369998, 391998, 415306, 440000, 466162, 493880
1561 };
1562
1563#define BASE_OCTAVE 5
1564
1565 octave = note_num / 12;
1566 note = note_num % 12;
1567
1568 note_freq = notes[note];
1569
1570 if (octave < BASE_OCTAVE)
1571 note_freq >>= (BASE_OCTAVE - octave);
1572 else if (octave > BASE_OCTAVE)
1573 note_freq <<= (octave - BASE_OCTAVE);
1574
1575 /*
1576 * note_freq >>= 1;
1577 */
1578
1579 return note_freq;
1580}
1581EXPORT_SYMBOL(note_to_freq);
1582
1583unsigned long compute_finetune(unsigned long base_freq, int bend, int range,
1584 int vibrato_cents)
1585{
1586 unsigned long amount;
1587 int negative, semitones, cents, multiplier = 1;
1588
1589 if (!bend)
1590 return base_freq;
1591 if (!range)
1592 return base_freq;
1593
1594 if (!base_freq)
1595 return base_freq;
1596
1597 if (range >= 8192)
1598 range = 8192;
1599
1600 bend = bend * range / 8192; /* Convert to cents */
1601 bend += vibrato_cents;
1602
1603 if (!bend)
1604 return base_freq;
1605
1606 negative = bend < 0 ? 1 : 0;
1607
1608 if (bend < 0)
1609 bend *= -1;
1610 if (bend > range)
1611 bend = range;
1612
1613 /*
1614 if (bend > 2399)
1615 bend = 2399;
1616 */
1617 while (bend > 2399)
1618 {
1619 multiplier *= 4;
1620 bend -= 2400;
1621 }
1622
1623 semitones = bend / 100;
1624 cents = bend % 100;
1625
1626 amount = (int) (semitone_tuning[semitones] * multiplier * cent_tuning[cents]) / 10000;
1627
1628 if (negative)
1629 return (base_freq * 10000) / amount; /* Bend down */
1630 else
1631 return (base_freq * amount) / 10000; /* Bend up */
1632}
1633EXPORT_SYMBOL(compute_finetune);
1634
1635void sequencer_init(void)
1636{
1637 if (sequencer_ok)
1638 return;
1639 queue = vmalloc(SEQ_MAX_QUEUE * EV_SZ);
1640 if (queue == NULL)
1641 {
1642 printk(KERN_ERR "sequencer: Can't allocate memory for sequencer output queue\n");
1643 return;
1644 }
1645 iqueue = vmalloc(SEQ_MAX_QUEUE * IEV_SZ);
1646 if (iqueue == NULL)
1647 {
1648 printk(KERN_ERR "sequencer: Can't allocate memory for sequencer input queue\n");
1649 vfree(queue);
1650 return;
1651 }
1652 sequencer_ok = 1;
1653}
1654EXPORT_SYMBOL(sequencer_init);
1655
1656void sequencer_unload(void)
1657{
1658 vfree(queue);
1659 vfree(iqueue);
1660 queue = iqueue = NULL;
1661}
diff --git a/sound/oss/sleep.h b/sound/oss/sleep.h
deleted file mode 100644
index fd17d44d13dd..000000000000
--- a/sound/oss/sleep.h
+++ /dev/null
@@ -1,19 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#include <linux/wait.h>
3
4/*
5 * Do not use. This is a replacement for the old
6 * "interruptible_sleep_on_timeout" function that has been
7 * deprecated for ages. All users should instead try to use
8 * wait_event_interruptible_timeout.
9 */
10
11static inline long
12oss_broken_sleep_on(wait_queue_head_t *q, long timeout)
13{
14 DEFINE_WAIT(wait);
15 prepare_to_wait(q, &wait, TASK_INTERRUPTIBLE);
16 timeout = schedule_timeout(timeout);
17 finish_wait(q, &wait);
18 return timeout;
19}
diff --git a/sound/oss/sound_calls.h b/sound/oss/sound_calls.h
deleted file mode 100644
index bcd3f7340ef7..000000000000
--- a/sound/oss/sound_calls.h
+++ /dev/null
@@ -1,88 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * DMA buffer calls
4 */
5
6int DMAbuf_open(int dev, int mode);
7int DMAbuf_release(int dev, int mode);
8int DMAbuf_getwrbuffer(int dev, char **buf, int *size, int dontblock);
9int DMAbuf_getrdbuffer(int dev, char **buf, int *len, int dontblock);
10int DMAbuf_rmchars(int dev, int buff_no, int c);
11int DMAbuf_start_output(int dev, int buff_no, int l);
12int DMAbuf_move_wrpointer(int dev, int l);
13/* int DMAbuf_ioctl(int dev, unsigned int cmd, void __user *arg, int local); */
14void DMAbuf_init(int dev, int dma1, int dma2);
15void DMAbuf_deinit(int dev);
16int DMAbuf_start_dma (int dev, unsigned long physaddr, int count, int dma_mode);
17void DMAbuf_inputintr(int dev);
18void DMAbuf_outputintr(int dev, int underflow_flag);
19struct dma_buffparms;
20int DMAbuf_space_in_queue (int dev);
21int DMAbuf_activate_recording (int dev, struct dma_buffparms *dmap);
22int DMAbuf_get_buffer_pointer (int dev, struct dma_buffparms *dmap, int direction);
23void DMAbuf_launch_output(int dev, struct dma_buffparms *dmap);
24unsigned int DMAbuf_poll(struct file *file, int dev, poll_table *wait);
25void DMAbuf_start_devices(unsigned int devmask);
26void DMAbuf_reset (int dev);
27int DMAbuf_sync (int dev);
28
29/*
30 * System calls for /dev/dsp and /dev/audio (audio.c)
31 */
32
33int audio_read (int dev, struct file *file, char __user *buf, int count);
34int audio_write (int dev, struct file *file, const char __user *buf, int count);
35int audio_open (int dev, struct file *file);
36void audio_release (int dev, struct file *file);
37int audio_ioctl (int dev, struct file *file,
38 unsigned int cmd, void __user *arg);
39void audio_init_devices (void);
40void reorganize_buffers (int dev, struct dma_buffparms *dmap, int recording);
41
42/*
43 * System calls for the /dev/sequencer
44 */
45
46int sequencer_read (int dev, struct file *file, char __user *buf, int count);
47int sequencer_write (int dev, struct file *file, const char __user *buf, int count);
48int sequencer_open (int dev, struct file *file);
49void sequencer_release (int dev, struct file *file);
50int sequencer_ioctl (int dev, struct file *file, unsigned int cmd, void __user *arg);
51unsigned int sequencer_poll(int dev, struct file *file, poll_table * wait);
52
53void sequencer_init (void);
54void sequencer_unload (void);
55void sequencer_timer(unsigned long dummy);
56int note_to_freq(int note_num);
57unsigned long compute_finetune(unsigned long base_freq, int bend, int range,
58 int vibrato_bend);
59void seq_input_event(unsigned char *event, int len);
60void seq_copy_to_input (unsigned char *event, int len);
61
62/*
63 * System calls for the /dev/midi
64 */
65
66int MIDIbuf_read (int dev, struct file *file, char __user *buf, int count);
67int MIDIbuf_write (int dev, struct file *file, const char __user *buf, int count);
68int MIDIbuf_open (int dev, struct file *file);
69void MIDIbuf_release (int dev, struct file *file);
70int MIDIbuf_ioctl (int dev, struct file *file, unsigned int cmd, void __user *arg);
71unsigned int MIDIbuf_poll(int dev, struct file *file, poll_table * wait);
72int MIDIbuf_avail(int dev);
73
74void MIDIbuf_bytes_received(int dev, unsigned char *buf, int count);
75
76
77/* From soundcard.c */
78void request_sound_timer (int count);
79void sound_stop_timer(void);
80void conf_printf(char *name, struct address_info *hw_config);
81void conf_printf2(char *name, int base, int irq, int dma, int dma2);
82
83/* From sound_timer.c */
84void sound_timer_interrupt(void);
85void sound_timer_syncinterval(unsigned int new_usecs);
86
87/* From midi_synth.c */
88void do_midi_msg (int synthno, unsigned char *msg, int mlen);
diff --git a/sound/oss/sound_config.h b/sound/oss/sound_config.h
deleted file mode 100644
index 5253b0a70437..000000000000
--- a/sound/oss/sound_config.h
+++ /dev/null
@@ -1,144 +0,0 @@
1/* sound_config.h
2 *
3 * A driver for sound cards, misc. configuration parameters.
4 */
5/*
6 * Copyright (C) by Hannu Savolainen 1993-1997
7 *
8 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
9 * Version 2 (June 1991). See the "COPYING" file distributed with this software
10 * for more info.
11 */
12
13
14#ifndef _SOUND_CONFIG_H_
15#define _SOUND_CONFIG_H_
16
17#include <linux/fs.h>
18#include <linux/sound.h>
19#include <linux/sched/signal.h>
20
21#include "os.h"
22#include "soundvers.h"
23
24
25#ifndef SND_DEFAULT_ENABLE
26#define SND_DEFAULT_ENABLE 1
27#endif
28
29#ifndef MAX_REALTIME_FACTOR
30#define MAX_REALTIME_FACTOR 4
31#endif
32
33/*
34 * Use always 64k buffer size. There is no reason to use shorter.
35 */
36#undef DSP_BUFFSIZE
37#define DSP_BUFFSIZE (64*1024)
38
39#ifndef DSP_BUFFCOUNT
40#define DSP_BUFFCOUNT 1 /* 1 is recommended. */
41#endif
42
43#define FM_MONO 0x388 /* This is the I/O address used by AdLib */
44
45#ifndef CONFIG_PAS_BASE
46#define CONFIG_PAS_BASE 0x388
47#endif
48
49/* SEQ_MAX_QUEUE is the maximum number of sequencer events buffered by the
50 driver. (There is no need to alter this) */
51#define SEQ_MAX_QUEUE 1024
52
53#define SBFM_MAXINSTR (256) /* Size of the FM Instrument bank */
54/* 128 instruments for general MIDI setup and 16 unassigned */
55
56#define SND_NDEVS 256 /* Number of supported devices */
57
58#define DSP_DEFAULT_SPEED 8000
59
60#define MAX_AUDIO_DEV 5
61#define MAX_MIXER_DEV 5
62#define MAX_SYNTH_DEV 5
63#define MAX_MIDI_DEV 6
64#define MAX_TIMER_DEV 4
65
66struct address_info {
67 int io_base;
68 int irq;
69 int dma;
70 int dma2;
71 int always_detect; /* 1=Trust me, it's there */
72 char *name;
73 int driver_use_1; /* Driver defined field 1 */
74 int driver_use_2; /* Driver defined field 2 */
75 int *osp; /* OS specific info */
76 int card_subtype; /* Driver specific. Usually 0 */
77 void *memptr; /* Module memory chainer */
78 int slots[6]; /* To remember driver slot ids */
79};
80
81#define SYNTH_MAX_VOICES 32
82
83struct voice_alloc_info {
84 int max_voice;
85 int used_voices;
86 int ptr; /* For device specific use */
87 unsigned short map[SYNTH_MAX_VOICES]; /* (ch << 8) | (note+1) */
88 int timestamp;
89 int alloc_times[SYNTH_MAX_VOICES];
90 };
91
92struct channel_info {
93 int pgm_num;
94 int bender_value;
95 int bender_range;
96 unsigned char controllers[128];
97 };
98
99/*
100 * Process wakeup reasons
101 */
102#define WK_NONE 0x00
103#define WK_WAKEUP 0x01
104#define WK_TIMEOUT 0x02
105#define WK_SIGNAL 0x04
106#define WK_SLEEP 0x08
107#define WK_SELECT 0x10
108#define WK_ABORT 0x20
109
110#define OPEN_READ PCM_ENABLE_INPUT
111#define OPEN_WRITE PCM_ENABLE_OUTPUT
112#define OPEN_READWRITE (OPEN_READ|OPEN_WRITE)
113
114static inline int translate_mode(struct file *file)
115{
116 if (OPEN_READ == (__force int)FMODE_READ &&
117 OPEN_WRITE == (__force int)FMODE_WRITE)
118 return (__force int)(file->f_mode & (FMODE_READ | FMODE_WRITE));
119 else
120 return ((file->f_mode & FMODE_READ) ? OPEN_READ : 0) |
121 ((file->f_mode & FMODE_WRITE) ? OPEN_WRITE : 0);
122}
123
124#include "sound_calls.h"
125#include "dev_table.h"
126
127#ifndef DDB
128#define DDB(x) do {} while (0)
129#endif
130
131#ifndef MDB
132#ifdef MODULE
133#define MDB(x) x
134#else
135#define MDB(x)
136#endif
137#endif
138
139#define TIMER_ARMED 121234
140#define TIMER_NOT_ARMED 1
141
142#define MAX_MEM_BLOCKS 1024
143
144#endif
diff --git a/sound/oss/sound_firmware.h b/sound/oss/sound_firmware.h
deleted file mode 100644
index ebcbded0e8c2..000000000000
--- a/sound/oss/sound_firmware.h
+++ /dev/null
@@ -1,30 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#include <linux/fs.h>
3
4/**
5 * mod_firmware_load - load sound driver firmware
6 * @fn: filename
7 * @fp: return for the buffer.
8 *
9 * Load the firmware for a sound module (up to 128K) into a buffer.
10 * The buffer is returned in *fp. It is allocated with vmalloc so is
11 * virtually linear and not DMAable. The caller should free it with
12 * vfree when finished.
13 *
14 * The length of the buffer is returned on a successful load, the
15 * value zero on a failure.
16 *
17 * Caution: This API is not recommended. Firmware should be loaded via
18 * request_firmware.
19 */
20static inline int mod_firmware_load(const char *fn, char **fp)
21{
22 loff_t size;
23 int err;
24
25 err = kernel_read_file_from_path(fn, (void **)fp, &size,
26 131072, READING_FIRMWARE);
27 if (err < 0)
28 return 0;
29 return size;
30}
diff --git a/sound/oss/sound_timer.c b/sound/oss/sound_timer.c
deleted file mode 100644
index 3a444a6f10eb..000000000000
--- a/sound/oss/sound_timer.c
+++ /dev/null
@@ -1,327 +0,0 @@
1/*
2 * sound/oss/sound_timer.c
3 */
4/*
5 * Copyright (C) by Hannu Savolainen 1993-1997
6 *
7 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
8 * Version 2 (June 1991). See the "COPYING" file distributed with this software
9 * for more info.
10 */
11/*
12 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
13 */
14#include <linux/string.h>
15#include <linux/spinlock.h>
16
17#include "sound_config.h"
18
19static volatile int initialized, opened, tmr_running;
20static volatile unsigned int tmr_offs, tmr_ctr;
21static volatile unsigned long ticks_offs;
22static volatile int curr_tempo, curr_timebase;
23static volatile unsigned long curr_ticks;
24static volatile unsigned long next_event_time;
25static unsigned long prev_event_time;
26static volatile unsigned long usecs_per_tmr; /* Length of the current interval */
27
28static struct sound_lowlev_timer *tmr;
29static DEFINE_SPINLOCK(lock);
30
31static unsigned long tmr2ticks(int tmr_value)
32{
33 /*
34 * Convert timer ticks to MIDI ticks
35 */
36
37 unsigned long tmp;
38 unsigned long scale;
39
40 tmp = tmr_value * usecs_per_tmr; /* Convert to usecs */
41 scale = (60 * 1000000) / (curr_tempo * curr_timebase); /* usecs per MIDI tick */
42 return (tmp + (scale / 2)) / scale;
43}
44
45void reprogram_timer(void)
46{
47 unsigned long usecs_per_tick;
48
49 /*
50 * The user is changing the timer rate before setting a timer
51 * slap, bad bad not allowed.
52 */
53
54 if(!tmr)
55 return;
56
57 usecs_per_tick = (60 * 1000000) / (curr_tempo * curr_timebase);
58
59 /*
60 * Don't kill the system by setting too high timer rate
61 */
62 if (usecs_per_tick < 2000)
63 usecs_per_tick = 2000;
64
65 usecs_per_tmr = tmr->tmr_start(tmr->dev, usecs_per_tick);
66}
67
68void sound_timer_syncinterval(unsigned int new_usecs)
69{
70 /*
71 * This routine is called by the hardware level if
72 * the clock frequency has changed for some reason.
73 */
74 tmr_offs = tmr_ctr;
75 ticks_offs += tmr2ticks(tmr_ctr);
76 tmr_ctr = 0;
77 usecs_per_tmr = new_usecs;
78}
79EXPORT_SYMBOL(sound_timer_syncinterval);
80
81static void tmr_reset(void)
82{
83 unsigned long flags;
84
85 spin_lock_irqsave(&lock,flags);
86 tmr_offs = 0;
87 ticks_offs = 0;
88 tmr_ctr = 0;
89 next_event_time = (unsigned long) -1;
90 prev_event_time = 0;
91 curr_ticks = 0;
92 spin_unlock_irqrestore(&lock,flags);
93}
94
95static int timer_open(int dev, int mode)
96{
97 if (opened)
98 return -EBUSY;
99 tmr_reset();
100 curr_tempo = 60;
101 curr_timebase = 100;
102 opened = 1;
103 reprogram_timer();
104 return 0;
105}
106
107static void timer_close(int dev)
108{
109 opened = tmr_running = 0;
110 tmr->tmr_disable(tmr->dev);
111}
112
113static int timer_event(int dev, unsigned char *event)
114{
115 unsigned char cmd = event[1];
116 unsigned long parm = *(int *) &event[4];
117
118 switch (cmd)
119 {
120 case TMR_WAIT_REL:
121 parm += prev_event_time;
122 case TMR_WAIT_ABS:
123 if (parm > 0)
124 {
125 long time;
126
127 if (parm <= curr_ticks) /* It's the time */
128 return TIMER_NOT_ARMED;
129 time = parm;
130 next_event_time = prev_event_time = time;
131 return TIMER_ARMED;
132 }
133 break;
134
135 case TMR_START:
136 tmr_reset();
137 tmr_running = 1;
138 reprogram_timer();
139 break;
140
141 case TMR_STOP:
142 tmr_running = 0;
143 break;
144
145 case TMR_CONTINUE:
146 tmr_running = 1;
147 reprogram_timer();
148 break;
149
150 case TMR_TEMPO:
151 if (parm)
152 {
153 if (parm < 8)
154 parm = 8;
155 if (parm > 250)
156 parm = 250;
157 tmr_offs = tmr_ctr;
158 ticks_offs += tmr2ticks(tmr_ctr);
159 tmr_ctr = 0;
160 curr_tempo = parm;
161 reprogram_timer();
162 }
163 break;
164
165 case TMR_ECHO:
166 seq_copy_to_input(event, 8);
167 break;
168
169 default:;
170 }
171 return TIMER_NOT_ARMED;
172}
173
174static unsigned long timer_get_time(int dev)
175{
176 if (!opened)
177 return 0;
178 return curr_ticks;
179}
180
181static int timer_ioctl(int dev, unsigned int cmd, void __user *arg)
182{
183 int __user *p = arg;
184 int val;
185
186 switch (cmd)
187 {
188 case SNDCTL_TMR_SOURCE:
189 val = TMR_INTERNAL;
190 break;
191
192 case SNDCTL_TMR_START:
193 tmr_reset();
194 tmr_running = 1;
195 return 0;
196
197 case SNDCTL_TMR_STOP:
198 tmr_running = 0;
199 return 0;
200
201 case SNDCTL_TMR_CONTINUE:
202 tmr_running = 1;
203 return 0;
204
205 case SNDCTL_TMR_TIMEBASE:
206 if (get_user(val, p))
207 return -EFAULT;
208 if (val)
209 {
210 if (val < 1)
211 val = 1;
212 if (val > 1000)
213 val = 1000;
214 curr_timebase = val;
215 }
216 val = curr_timebase;
217 break;
218
219 case SNDCTL_TMR_TEMPO:
220 if (get_user(val, p))
221 return -EFAULT;
222 if (val)
223 {
224 if (val < 8)
225 val = 8;
226 if (val > 250)
227 val = 250;
228 tmr_offs = tmr_ctr;
229 ticks_offs += tmr2ticks(tmr_ctr);
230 tmr_ctr = 0;
231 curr_tempo = val;
232 reprogram_timer();
233 }
234 val = curr_tempo;
235 break;
236
237 case SNDCTL_SEQ_CTRLRATE:
238 if (get_user(val, p))
239 return -EFAULT;
240 if (val != 0) /* Can't change */
241 return -EINVAL;
242 val = ((curr_tempo * curr_timebase) + 30) / 60;
243 break;
244
245 case SNDCTL_SEQ_GETTIME:
246 val = curr_ticks;
247 break;
248
249 case SNDCTL_TMR_METRONOME:
250 default:
251 return -EINVAL;
252 }
253 return put_user(val, p);
254}
255
256static void timer_arm(int dev, long time)
257{
258 if (time < 0)
259 time = curr_ticks + 1;
260 else if (time <= curr_ticks) /* It's the time */
261 return;
262
263 next_event_time = prev_event_time = time;
264 return;
265}
266
267static struct sound_timer_operations sound_timer =
268{
269 .owner = THIS_MODULE,
270 .info = {"Sound Timer", 0},
271 .priority = 1, /* Priority */
272 .devlink = 0, /* Local device link */
273 .open = timer_open,
274 .close = timer_close,
275 .event = timer_event,
276 .get_time = timer_get_time,
277 .ioctl = timer_ioctl,
278 .arm_timer = timer_arm
279};
280
281void sound_timer_interrupt(void)
282{
283 unsigned long flags;
284
285 if (!opened)
286 return;
287
288 tmr->tmr_restart(tmr->dev);
289
290 if (!tmr_running)
291 return;
292
293 spin_lock_irqsave(&lock,flags);
294 tmr_ctr++;
295 curr_ticks = ticks_offs + tmr2ticks(tmr_ctr);
296
297 if (curr_ticks >= next_event_time)
298 {
299 next_event_time = (unsigned long) -1;
300 sequencer_timer(0);
301 }
302 spin_unlock_irqrestore(&lock,flags);
303}
304EXPORT_SYMBOL(sound_timer_interrupt);
305
306void sound_timer_init(struct sound_lowlev_timer *t, char *name)
307{
308 int n;
309
310 if (initialized)
311 {
312 if (t->priority <= tmr->priority)
313 return; /* There is already a similar or better timer */
314 tmr = t;
315 return;
316 }
317 initialized = 1;
318 tmr = t;
319
320 n = sound_alloc_timerdev();
321 if (n == -1)
322 n = 0; /* Overwrite the system timer */
323 strlcpy(sound_timer.info.name, name, sizeof(sound_timer.info.name));
324 sound_timer_devs[n] = &sound_timer;
325}
326EXPORT_SYMBOL(sound_timer_init);
327
diff --git a/sound/oss/soundcard.c b/sound/oss/soundcard.c
deleted file mode 100644
index 4391062e5cfd..000000000000
--- a/sound/oss/soundcard.c
+++ /dev/null
@@ -1,733 +0,0 @@
1/*
2 * linux/sound/oss/soundcard.c
3 *
4 * Sound card driver for Linux
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
15 * integrated sound_switch.c
16 * Stefan Reinauer : integrated /proc/sound (equals to /dev/sndstat,
17 * which should disappear in the near future)
18 * Eric Dumas : devfs support (22-Jan-98) <dumas@linux.eu.org> with
19 * fixups by C. Scott Ananian <cananian@alumni.princeton.edu>
20 * Richard Gooch : moved common (non OSS-specific) devices to sound_core.c
21 * Rob Riggs : Added persistent DMA buffers support (1998/10/17)
22 * Christoph Hellwig : Some cleanup work (2000/03/01)
23 */
24
25
26#include "sound_config.h"
27#include <linux/init.h>
28#include <linux/types.h>
29#include <linux/errno.h>
30#include <linux/signal.h>
31#include <linux/fcntl.h>
32#include <linux/ctype.h>
33#include <linux/stddef.h>
34#include <linux/kmod.h>
35#include <linux/kernel.h>
36#include <asm/dma.h>
37#include <asm/io.h>
38#include <linux/wait.h>
39#include <linux/ioport.h>
40#include <linux/major.h>
41#include <linux/delay.h>
42#include <linux/proc_fs.h>
43#include <linux/mutex.h>
44#include <linux/module.h>
45#include <linux/mm.h>
46#include <linux/device.h>
47
48/*
49 * This ought to be moved into include/asm/dma.h
50 */
51#ifndef valid_dma
52#define valid_dma(n) ((n) >= 0 && (n) < MAX_DMA_CHANNELS && (n) != 4)
53#endif
54
55/*
56 * Table for permanently allocated memory (used when unloading the module)
57 */
58void * sound_mem_blocks[MAX_MEM_BLOCKS];
59static DEFINE_MUTEX(soundcard_mutex);
60int sound_nblocks = 0;
61
62/* Persistent DMA buffers */
63#ifdef CONFIG_SOUND_DMAP
64int sound_dmap_flag = 1;
65#else
66int sound_dmap_flag = 0;
67#endif
68
69static char dma_alloc_map[MAX_DMA_CHANNELS];
70
71#define DMA_MAP_UNAVAIL 0
72#define DMA_MAP_FREE 1
73#define DMA_MAP_BUSY 2
74
75
76unsigned long seq_time = 0; /* Time for /dev/sequencer */
77extern struct class *sound_class;
78
79/*
80 * Table for configurable mixer volume handling
81 */
82static mixer_vol_table mixer_vols[MAX_MIXER_DEV];
83static int num_mixer_volumes;
84
85int *load_mixer_volumes(char *name, int *levels, int present)
86{
87 int i, n;
88
89 for (i = 0; i < num_mixer_volumes; i++) {
90 if (strncmp(name, mixer_vols[i].name, 32) == 0) {
91 if (present)
92 mixer_vols[i].num = i;
93 return mixer_vols[i].levels;
94 }
95 }
96 if (num_mixer_volumes >= MAX_MIXER_DEV) {
97 printk(KERN_ERR "Sound: Too many mixers (%s)\n", name);
98 return levels;
99 }
100 n = num_mixer_volumes++;
101
102 strncpy(mixer_vols[n].name, name, 32);
103
104 if (present)
105 mixer_vols[n].num = n;
106 else
107 mixer_vols[n].num = -1;
108
109 for (i = 0; i < 32; i++)
110 mixer_vols[n].levels[i] = levels[i];
111 return mixer_vols[n].levels;
112}
113EXPORT_SYMBOL(load_mixer_volumes);
114
115static int set_mixer_levels(void __user * arg)
116{
117 /* mixer_vol_table is 174 bytes, so IMHO no reason to not allocate it on the stack */
118 mixer_vol_table buf;
119
120 if (__copy_from_user(&buf, arg, sizeof(buf)))
121 return -EFAULT;
122 load_mixer_volumes(buf.name, buf.levels, 0);
123 if (__copy_to_user(arg, &buf, sizeof(buf)))
124 return -EFAULT;
125 return 0;
126}
127
128static int get_mixer_levels(void __user * arg)
129{
130 int n;
131
132 if (__get_user(n, (int __user *)(&(((mixer_vol_table __user *)arg)->num))))
133 return -EFAULT;
134 if (n < 0 || n >= num_mixer_volumes)
135 return -EINVAL;
136 if (__copy_to_user(arg, &mixer_vols[n], sizeof(mixer_vol_table)))
137 return -EFAULT;
138 return 0;
139}
140
141/* 4K page size but our output routines use some slack for overruns */
142#define PROC_BLOCK_SIZE (3*1024)
143
144static ssize_t sound_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
145{
146 int dev = iminor(file_inode(file));
147 int ret = -EINVAL;
148
149 /*
150 * The OSS drivers aren't remotely happy without this locking,
151 * and unless someone fixes them when they are about to bite the
152 * big one anyway, we might as well bandage here..
153 */
154
155 mutex_lock(&soundcard_mutex);
156
157 switch (dev & 0x0f) {
158 case SND_DEV_DSP:
159 case SND_DEV_DSP16:
160 case SND_DEV_AUDIO:
161 ret = audio_read(dev, file, buf, count);
162 break;
163
164 case SND_DEV_SEQ:
165 case SND_DEV_SEQ2:
166 ret = sequencer_read(dev, file, buf, count);
167 break;
168
169 case SND_DEV_MIDIN:
170 ret = MIDIbuf_read(dev, file, buf, count);
171 }
172 mutex_unlock(&soundcard_mutex);
173 return ret;
174}
175
176static ssize_t sound_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
177{
178 int dev = iminor(file_inode(file));
179 int ret = -EINVAL;
180
181 mutex_lock(&soundcard_mutex);
182 switch (dev & 0x0f) {
183 case SND_DEV_SEQ:
184 case SND_DEV_SEQ2:
185 ret = sequencer_write(dev, file, buf, count);
186 break;
187
188 case SND_DEV_DSP:
189 case SND_DEV_DSP16:
190 case SND_DEV_AUDIO:
191 ret = audio_write(dev, file, buf, count);
192 break;
193
194 case SND_DEV_MIDIN:
195 ret = MIDIbuf_write(dev, file, buf, count);
196 break;
197 }
198 mutex_unlock(&soundcard_mutex);
199 return ret;
200}
201
202static int sound_open(struct inode *inode, struct file *file)
203{
204 int dev = iminor(inode);
205 int retval;
206
207 if ((dev >= SND_NDEVS) || (dev < 0)) {
208 printk(KERN_ERR "Invalid minor device %d\n", dev);
209 return -ENXIO;
210 }
211 mutex_lock(&soundcard_mutex);
212 switch (dev & 0x0f) {
213 case SND_DEV_CTL:
214 dev >>= 4;
215 if (dev >= 0 && dev < MAX_MIXER_DEV && mixer_devs[dev] == NULL) {
216 request_module("mixer%d", dev);
217 }
218 retval = -ENXIO;
219 if (dev && (dev >= num_mixers || mixer_devs[dev] == NULL))
220 break;
221
222 if (!try_module_get(mixer_devs[dev]->owner))
223 break;
224
225 retval = 0;
226 break;
227
228 case SND_DEV_SEQ:
229 case SND_DEV_SEQ2:
230 retval = sequencer_open(dev, file);
231 break;
232
233 case SND_DEV_MIDIN:
234 retval = MIDIbuf_open(dev, file);
235 break;
236
237 case SND_DEV_DSP:
238 case SND_DEV_DSP16:
239 case SND_DEV_AUDIO:
240 retval = audio_open(dev, file);
241 break;
242
243 default:
244 printk(KERN_ERR "Invalid minor device %d\n", dev);
245 retval = -ENXIO;
246 }
247
248 mutex_unlock(&soundcard_mutex);
249 return retval;
250}
251
252static int sound_release(struct inode *inode, struct file *file)
253{
254 int dev = iminor(inode);
255
256 mutex_lock(&soundcard_mutex);
257 switch (dev & 0x0f) {
258 case SND_DEV_CTL:
259 module_put(mixer_devs[dev >> 4]->owner);
260 break;
261
262 case SND_DEV_SEQ:
263 case SND_DEV_SEQ2:
264 sequencer_release(dev, file);
265 break;
266
267 case SND_DEV_MIDIN:
268 MIDIbuf_release(dev, file);
269 break;
270
271 case SND_DEV_DSP:
272 case SND_DEV_DSP16:
273 case SND_DEV_AUDIO:
274 audio_release(dev, file);
275 break;
276
277 default:
278 printk(KERN_ERR "Sound error: Releasing unknown device 0x%02x\n", dev);
279 }
280 mutex_unlock(&soundcard_mutex);
281
282 return 0;
283}
284
285static int get_mixer_info(int dev, void __user *arg)
286{
287 mixer_info info;
288 memset(&info, 0, sizeof(info));
289 strlcpy(info.id, mixer_devs[dev]->id, sizeof(info.id));
290 strlcpy(info.name, mixer_devs[dev]->name, sizeof(info.name));
291 info.modify_counter = mixer_devs[dev]->modify_counter;
292 if (__copy_to_user(arg, &info, sizeof(info)))
293 return -EFAULT;
294 return 0;
295}
296
297static int get_old_mixer_info(int dev, void __user *arg)
298{
299 _old_mixer_info info;
300 memset(&info, 0, sizeof(info));
301 strlcpy(info.id, mixer_devs[dev]->id, sizeof(info.id));
302 strlcpy(info.name, mixer_devs[dev]->name, sizeof(info.name));
303 if (copy_to_user(arg, &info, sizeof(info)))
304 return -EFAULT;
305 return 0;
306}
307
308static int sound_mixer_ioctl(int mixdev, unsigned int cmd, void __user *arg)
309{
310 if (mixdev < 0 || mixdev >= MAX_MIXER_DEV)
311 return -ENXIO;
312 /* Try to load the mixer... */
313 if (mixer_devs[mixdev] == NULL) {
314 request_module("mixer%d", mixdev);
315 }
316 if (mixdev >= num_mixers || !mixer_devs[mixdev])
317 return -ENXIO;
318 if (cmd == SOUND_MIXER_INFO)
319 return get_mixer_info(mixdev, arg);
320 if (cmd == SOUND_OLD_MIXER_INFO)
321 return get_old_mixer_info(mixdev, arg);
322 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
323 mixer_devs[mixdev]->modify_counter++;
324 if (!mixer_devs[mixdev]->ioctl)
325 return -EINVAL;
326 return mixer_devs[mixdev]->ioctl(mixdev, cmd, arg);
327}
328
329static long sound_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
330{
331 int len = 0, dtype;
332 int dev = iminor(file_inode(file));
333 long ret = -EINVAL;
334 void __user *p = (void __user *)arg;
335
336 if (_SIOC_DIR(cmd) != _SIOC_NONE && _SIOC_DIR(cmd) != 0) {
337 /*
338 * Have to validate the address given by the process.
339 */
340 len = _SIOC_SIZE(cmd);
341 if (len < 1 || len > 65536 || !p)
342 return -EFAULT;
343 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
344 if (!access_ok(VERIFY_READ, p, len))
345 return -EFAULT;
346 if (_SIOC_DIR(cmd) & _SIOC_READ)
347 if (!access_ok(VERIFY_WRITE, p, len))
348 return -EFAULT;
349 }
350 if (cmd == OSS_GETVERSION)
351 return __put_user(SOUND_VERSION, (int __user *)p);
352
353 mutex_lock(&soundcard_mutex);
354 if (_IOC_TYPE(cmd) == 'M' && num_mixers > 0 && /* Mixer ioctl */
355 (dev & 0x0f) != SND_DEV_CTL) {
356 dtype = dev & 0x0f;
357 switch (dtype) {
358 case SND_DEV_DSP:
359 case SND_DEV_DSP16:
360 case SND_DEV_AUDIO:
361 ret = sound_mixer_ioctl(audio_devs[dev >> 4]->mixer_dev,
362 cmd, p);
363 break;
364 default:
365 ret = sound_mixer_ioctl(dev >> 4, cmd, p);
366 break;
367 }
368 mutex_unlock(&soundcard_mutex);
369 return ret;
370 }
371
372 switch (dev & 0x0f) {
373 case SND_DEV_CTL:
374 if (cmd == SOUND_MIXER_GETLEVELS)
375 ret = get_mixer_levels(p);
376 else if (cmd == SOUND_MIXER_SETLEVELS)
377 ret = set_mixer_levels(p);
378 else
379 ret = sound_mixer_ioctl(dev >> 4, cmd, p);
380 break;
381
382 case SND_DEV_SEQ:
383 case SND_DEV_SEQ2:
384 ret = sequencer_ioctl(dev, file, cmd, p);
385 break;
386
387 case SND_DEV_DSP:
388 case SND_DEV_DSP16:
389 case SND_DEV_AUDIO:
390 ret = audio_ioctl(dev, file, cmd, p);
391 break;
392
393 case SND_DEV_MIDIN:
394 ret = MIDIbuf_ioctl(dev, file, cmd, p);
395 break;
396
397 }
398 mutex_unlock(&soundcard_mutex);
399 return ret;
400}
401
402static unsigned int sound_poll(struct file *file, poll_table * wait)
403{
404 struct inode *inode = file_inode(file);
405 int dev = iminor(inode);
406
407 switch (dev & 0x0f) {
408 case SND_DEV_SEQ:
409 case SND_DEV_SEQ2:
410 return sequencer_poll(dev, file, wait);
411
412 case SND_DEV_MIDIN:
413 return MIDIbuf_poll(dev, file, wait);
414
415 case SND_DEV_DSP:
416 case SND_DEV_DSP16:
417 case SND_DEV_AUDIO:
418 return DMAbuf_poll(file, dev >> 4, wait);
419 }
420 return 0;
421}
422
423static int sound_mmap(struct file *file, struct vm_area_struct *vma)
424{
425 int dev_class;
426 unsigned long size;
427 struct dma_buffparms *dmap = NULL;
428 int dev = iminor(file_inode(file));
429
430 dev_class = dev & 0x0f;
431 dev >>= 4;
432
433 if (dev_class != SND_DEV_DSP && dev_class != SND_DEV_DSP16 && dev_class != SND_DEV_AUDIO) {
434 printk(KERN_ERR "Sound: mmap() not supported for other than audio devices\n");
435 return -EINVAL;
436 }
437 mutex_lock(&soundcard_mutex);
438 if (vma->vm_flags & VM_WRITE) /* Map write and read/write to the output buf */
439 dmap = audio_devs[dev]->dmap_out;
440 else if (vma->vm_flags & VM_READ)
441 dmap = audio_devs[dev]->dmap_in;
442 else {
443 printk(KERN_ERR "Sound: Undefined mmap() access\n");
444 mutex_unlock(&soundcard_mutex);
445 return -EINVAL;
446 }
447
448 if (dmap == NULL) {
449 printk(KERN_ERR "Sound: mmap() error. dmap == NULL\n");
450 mutex_unlock(&soundcard_mutex);
451 return -EIO;
452 }
453 if (dmap->raw_buf == NULL) {
454 printk(KERN_ERR "Sound: mmap() called when raw_buf == NULL\n");
455 mutex_unlock(&soundcard_mutex);
456 return -EIO;
457 }
458 if (dmap->mapping_flags) {
459 printk(KERN_ERR "Sound: mmap() called twice for the same DMA buffer\n");
460 mutex_unlock(&soundcard_mutex);
461 return -EIO;
462 }
463 if (vma->vm_pgoff != 0) {
464 printk(KERN_ERR "Sound: mmap() offset must be 0.\n");
465 mutex_unlock(&soundcard_mutex);
466 return -EINVAL;
467 }
468 size = vma->vm_end - vma->vm_start;
469
470 if (size != dmap->bytes_in_use) {
471 printk(KERN_WARNING "Sound: mmap() size = %ld. Should be %d\n", size, dmap->bytes_in_use);
472 }
473 if (remap_pfn_range(vma, vma->vm_start,
474 virt_to_phys(dmap->raw_buf) >> PAGE_SHIFT,
475 vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
476 mutex_unlock(&soundcard_mutex);
477 return -EAGAIN;
478 }
479
480 dmap->mapping_flags |= DMA_MAP_MAPPED;
481
482 if( audio_devs[dev]->d->mmap)
483 audio_devs[dev]->d->mmap(dev);
484
485 memset(dmap->raw_buf,
486 dmap->neutral_byte,
487 dmap->bytes_in_use);
488 mutex_unlock(&soundcard_mutex);
489 return 0;
490}
491
492const struct file_operations oss_sound_fops = {
493 .owner = THIS_MODULE,
494 .llseek = no_llseek,
495 .read = sound_read,
496 .write = sound_write,
497 .poll = sound_poll,
498 .unlocked_ioctl = sound_ioctl,
499 .mmap = sound_mmap,
500 .open = sound_open,
501 .release = sound_release,
502};
503
504/*
505 * Create the required special subdevices
506 */
507
508static int create_special_devices(void)
509{
510 int seq1,seq2;
511 seq1=register_sound_special(&oss_sound_fops, 1);
512 if(seq1==-1)
513 goto bad;
514 seq2=register_sound_special(&oss_sound_fops, 8);
515 if(seq2!=-1)
516 return 0;
517 unregister_sound_special(1);
518bad:
519 return -1;
520}
521
522
523static int dmabuf;
524static int dmabug;
525
526module_param(dmabuf, int, 0444);
527module_param(dmabug, int, 0444);
528
529/* additional minors for compatibility */
530struct oss_minor_dev {
531 unsigned short minor;
532 unsigned int enabled;
533} dev_list[] = {
534 { SND_DEV_DSP16 },
535 { SND_DEV_AUDIO },
536};
537
538static int __init oss_init(void)
539{
540 int err;
541 int i, j;
542
543#ifdef CONFIG_PCI
544 if(dmabug)
545 isa_dma_bridge_buggy = dmabug;
546#endif
547
548 err = create_special_devices();
549 if (err) {
550 printk(KERN_ERR "sound: driver already loaded/included in kernel\n");
551 return err;
552 }
553
554 /* Protecting the innocent */
555 sound_dmap_flag = (dmabuf > 0 ? 1 : 0);
556
557 for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
558 j = 0;
559 do {
560 unsigned short minor = dev_list[i].minor + j * 0x10;
561 if (!register_sound_special(&oss_sound_fops, minor))
562 dev_list[i].enabled = (1 << j);
563 } while (++j < num_audiodevs);
564 }
565
566 if (sound_nblocks >= MAX_MEM_BLOCKS - 1)
567 printk(KERN_ERR "Sound warning: Deallocation table was too small.\n");
568
569 return 0;
570}
571
572static void __exit oss_cleanup(void)
573{
574 int i, j;
575
576 for (i = 0; i < ARRAY_SIZE(dev_list); i++) {
577 j = 0;
578 do {
579 if (dev_list[i].enabled & (1 << j))
580 unregister_sound_special(dev_list[i].minor);
581 } while (++j < num_audiodevs);
582 }
583
584 unregister_sound_special(1);
585 unregister_sound_special(8);
586
587 sound_stop_timer();
588
589 sequencer_unload();
590
591 for (i = 0; i < MAX_DMA_CHANNELS; i++)
592 if (dma_alloc_map[i] != DMA_MAP_UNAVAIL) {
593 printk(KERN_ERR "Sound: Hmm, DMA%d was left allocated - fixed\n", i);
594 sound_free_dma(i);
595 }
596
597 for (i = 0; i < sound_nblocks; i++)
598 vfree(sound_mem_blocks[i]);
599
600}
601
602module_init(oss_init);
603module_exit(oss_cleanup);
604MODULE_LICENSE("GPL");
605MODULE_DESCRIPTION("OSS Sound subsystem");
606MODULE_AUTHOR("Hannu Savolainen, et al.");
607
608
609int sound_alloc_dma(int chn, char *deviceID)
610{
611 int err;
612
613 if ((err = request_dma(chn, deviceID)) != 0)
614 return err;
615
616 dma_alloc_map[chn] = DMA_MAP_FREE;
617
618 return 0;
619}
620EXPORT_SYMBOL(sound_alloc_dma);
621
622int sound_open_dma(int chn, char *deviceID)
623{
624 if (!valid_dma(chn)) {
625 printk(KERN_ERR "sound_open_dma: Invalid DMA channel %d\n", chn);
626 return 1;
627 }
628
629 if (dma_alloc_map[chn] != DMA_MAP_FREE) {
630 printk("sound_open_dma: DMA channel %d busy or not allocated (%d)\n", chn, dma_alloc_map[chn]);
631 return 1;
632 }
633 dma_alloc_map[chn] = DMA_MAP_BUSY;
634 return 0;
635}
636EXPORT_SYMBOL(sound_open_dma);
637
638void sound_free_dma(int chn)
639{
640 if (dma_alloc_map[chn] == DMA_MAP_UNAVAIL) {
641 /* printk( "sound_free_dma: Bad access to DMA channel %d\n", chn); */
642 return;
643 }
644 free_dma(chn);
645 dma_alloc_map[chn] = DMA_MAP_UNAVAIL;
646}
647EXPORT_SYMBOL(sound_free_dma);
648
649void sound_close_dma(int chn)
650{
651 if (dma_alloc_map[chn] != DMA_MAP_BUSY) {
652 printk(KERN_ERR "sound_close_dma: Bad access to DMA channel %d\n", chn);
653 return;
654 }
655 dma_alloc_map[chn] = DMA_MAP_FREE;
656}
657EXPORT_SYMBOL(sound_close_dma);
658
659static void do_sequencer_timer(unsigned long dummy)
660{
661 sequencer_timer(0);
662}
663
664
665static DEFINE_TIMER(seq_timer, do_sequencer_timer);
666
667void request_sound_timer(int count)
668{
669 extern unsigned long seq_time;
670
671 if (count < 0) {
672 seq_timer.expires = (-count) + jiffies;
673 add_timer(&seq_timer);
674 return;
675 }
676 count += seq_time;
677
678 count -= jiffies;
679
680 if (count < 1)
681 count = 1;
682
683 seq_timer.expires = (count) + jiffies;
684 add_timer(&seq_timer);
685}
686
687void sound_stop_timer(void)
688{
689 del_timer(&seq_timer);
690}
691
692void conf_printf(char *name, struct address_info *hw_config)
693{
694#ifndef CONFIG_SOUND_TRACEINIT
695 return;
696#else
697 printk("<%s> at 0x%03x", name, hw_config->io_base);
698
699 if (hw_config->irq)
700 printk(" irq %d", (hw_config->irq > 0) ? hw_config->irq : -hw_config->irq);
701
702 if (hw_config->dma != -1 || hw_config->dma2 != -1)
703 {
704 printk(" dma %d", hw_config->dma);
705 if (hw_config->dma2 != -1)
706 printk(",%d", hw_config->dma2);
707 }
708 printk("\n");
709#endif
710}
711EXPORT_SYMBOL(conf_printf);
712
713void conf_printf2(char *name, int base, int irq, int dma, int dma2)
714{
715#ifndef CONFIG_SOUND_TRACEINIT
716 return;
717#else
718 printk("<%s> at 0x%03x", name, base);
719
720 if (irq)
721 printk(" irq %d", (irq > 0) ? irq : -irq);
722
723 if (dma != -1 || dma2 != -1)
724 {
725 printk(" dma %d", dma);
726 if (dma2 != -1)
727 printk(",%d", dma2);
728 }
729 printk("\n");
730#endif
731}
732EXPORT_SYMBOL(conf_printf2);
733
diff --git a/sound/oss/soundvers.h b/sound/oss/soundvers.h
deleted file mode 100644
index e9084d2f46a9..000000000000
--- a/sound/oss/soundvers.h
+++ /dev/null
@@ -1,2 +0,0 @@
1#define SOUND_VERSION_STRING "3.8s2++-971130"
2#define SOUND_INTERNAL_VERSION 0x030804
diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
deleted file mode 100644
index 97899352b15f..000000000000
--- a/sound/oss/swarm_cs4297a.c
+++ /dev/null
@@ -1,2781 +0,0 @@
1/*******************************************************************************
2*
3* "swarm_cs4297a.c" -- Cirrus Logic-Crystal CS4297a linux audio driver.
4*
5* Copyright (C) 2001 Broadcom Corporation.
6* Copyright (C) 2000,2001 Cirrus Logic Corp.
7* -- adapted from drivers by Thomas Sailer,
8* -- but don't bug him; Problems should go to:
9* -- tom woller (twoller@crystal.cirrus.com) or
10* (audio@crystal.cirrus.com).
11* -- adapted from cs4281 PCI driver for cs4297a on
12* BCM1250 Synchronous Serial interface
13* (Kip Walker, Broadcom Corp.)
14* Copyright (C) 2004 Maciej W. Rozycki
15* Copyright (C) 2005 Ralf Baechle (ralf@linux-mips.org)
16*
17* This program is free software; you can redistribute it and/or modify
18* it under the terms of the GNU General Public License as published by
19* the Free Software Foundation; either version 2 of the License, or
20* (at your option) any later version.
21*
22* This program is distributed in the hope that it will be useful,
23* but WITHOUT ANY WARRANTY; without even the implied warranty of
24* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25* GNU General Public License for more details.
26*
27* You should have received a copy of the GNU General Public License
28* along with this program; if not, write to the Free Software
29* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30*
31* Module command line parameters:
32* none
33*
34* Supported devices:
35* /dev/dsp standard /dev/dsp device, (mostly) OSS compatible
36* /dev/mixer standard /dev/mixer device, (mostly) OSS compatible
37* /dev/midi simple MIDI UART interface, no ioctl
38*
39* Modification History
40* 08/20/00 trw - silence and no stopping DAC until release
41* 08/23/00 trw - added CS_DBG statements, fix interrupt hang issue on DAC stop.
42* 09/18/00 trw - added 16bit only record with conversion
43* 09/24/00 trw - added Enhanced Full duplex (separate simultaneous
44* capture/playback rates)
45* 10/03/00 trw - fixed mmap (fixed GRECORD and the XMMS mmap test plugin
46* libOSSm.so)
47* 10/11/00 trw - modified for 2.4.0-test9 kernel enhancements (NR_MAP removal)
48* 11/03/00 trw - fixed interrupt loss/stutter, added debug.
49* 11/10/00 bkz - added __devinit to cs4297a_hw_init()
50* 11/10/00 trw - fixed SMP and capture spinlock hang.
51* 12/04/00 trw - cleaned up CSDEBUG flags and added "defaultorder" moduleparm.
52* 12/05/00 trw - fixed polling (myth2), and added underrun swptr fix.
53* 12/08/00 trw - added PM support.
54* 12/14/00 trw - added wrapper code, builds under 2.4.0, 2.2.17-20, 2.2.17-8
55* (RH/Dell base), 2.2.18, 2.2.12. cleaned up code mods by ident.
56* 12/19/00 trw - added PM support for 2.2 base (apm_callback). other PM cleanup.
57* 12/21/00 trw - added fractional "defaultorder" inputs. if >100 then use
58* defaultorder-100 as power of 2 for the buffer size. example:
59* 106 = 2^(106-100) = 2^6 = 64 bytes for the buffer size.
60*
61*******************************************************************************/
62
63#include <linux/list.h>
64#include <linux/module.h>
65#include <linux/string.h>
66#include <linux/ioport.h>
67#include <linux/sched/signal.h>
68#include <linux/delay.h>
69#include <linux/sound.h>
70#include <linux/slab.h>
71#include <linux/soundcard.h>
72#include <linux/pci.h>
73#include <linux/bitops.h>
74#include <linux/interrupt.h>
75#include <linux/init.h>
76#include <linux/poll.h>
77#include <linux/mutex.h>
78#include <linux/kernel.h>
79
80#include <asm/byteorder.h>
81#include <asm/dma.h>
82#include <asm/io.h>
83#include <linux/uaccess.h>
84
85#include <asm/sibyte/sb1250_regs.h>
86#include <asm/sibyte/sb1250_int.h>
87#include <asm/sibyte/sb1250_dma.h>
88#include <asm/sibyte/sb1250_scd.h>
89#include <asm/sibyte/sb1250_syncser.h>
90#include <asm/sibyte/sb1250_mac.h>
91#include <asm/sibyte/sb1250.h>
92
93#include "sleep.h"
94
95struct cs4297a_state;
96
97static DEFINE_MUTEX(swarm_cs4297a_mutex);
98static void stop_dac(struct cs4297a_state *s);
99static void stop_adc(struct cs4297a_state *s);
100static void start_dac(struct cs4297a_state *s);
101static void start_adc(struct cs4297a_state *s);
102#undef OSS_DOCUMENTED_MIXER_SEMANTICS
103
104// ---------------------------------------------------------------------
105
106#define CS4297a_MAGIC 0xf00beef1
107
108// buffer order determines the size of the dma buffer for the driver.
109// under Linux, a smaller buffer allows more responsiveness from many of the
110// applications (e.g. games). A larger buffer allows some of the apps (esound)
111// to not underrun the dma buffer as easily. As default, use 32k (order=3)
112// rather than 64k as some of the games work more responsively.
113// log base 2( buff sz = 32k).
114
115//
116// Turn on/off debugging compilation by commenting out "#define CSDEBUG"
117//
118#define CSDEBUG 0
119#if CSDEBUG
120#define CSDEBUG_INTERFACE 1
121#else
122#undef CSDEBUG_INTERFACE
123#endif
124//
125// cs_debugmask areas
126//
127#define CS_INIT 0x00000001 // initialization and probe functions
128#define CS_ERROR 0x00000002 // tmp debugging bit placeholder
129#define CS_INTERRUPT 0x00000004 // interrupt handler (separate from all other)
130#define CS_FUNCTION 0x00000008 // enter/leave functions
131#define CS_WAVE_WRITE 0x00000010 // write information for wave
132#define CS_WAVE_READ 0x00000020 // read information for wave
133#define CS_AC97 0x00000040 // AC97 register access
134#define CS_DESCR 0x00000080 // descriptor management
135#define CS_OPEN 0x00000400 // all open functions in the driver
136#define CS_RELEASE 0x00000800 // all release functions in the driver
137#define CS_PARMS 0x00001000 // functional and operational parameters
138#define CS_IOCTL 0x00002000 // ioctl (non-mixer)
139#define CS_TMP 0x10000000 // tmp debug mask bit
140
141//
142// CSDEBUG is usual mode is set to 1, then use the
143// cs_debuglevel and cs_debugmask to turn on or off debugging.
144// Debug level of 1 has been defined to be kernel errors and info
145// that should be printed on any released driver.
146//
147#if CSDEBUG
148#define CS_DBGOUT(mask,level,x) if((cs_debuglevel >= (level)) && ((mask) & cs_debugmask) ) {x;}
149#else
150#define CS_DBGOUT(mask,level,x)
151#endif
152
153#if CSDEBUG
154static unsigned long cs_debuglevel = 4; // levels range from 1-9
155static unsigned long cs_debugmask = CS_INIT /*| CS_IOCTL*/;
156module_param(cs_debuglevel, int, 0);
157module_param(cs_debugmask, int, 0);
158#endif
159#define CS_TRUE 1
160#define CS_FALSE 0
161
162#define CS_TYPE_ADC 0
163#define CS_TYPE_DAC 1
164
165#define SER_BASE (A_SER_BASE_1 + KSEG1)
166#define SS_CSR(t) (SER_BASE+t)
167#define SS_TXTBL(t) (SER_BASE+R_SER_TX_TABLE_BASE+(t*8))
168#define SS_RXTBL(t) (SER_BASE+R_SER_RX_TABLE_BASE+(t*8))
169
170#define FRAME_BYTES 32
171#define FRAME_SAMPLE_BYTES 4
172
173/* Should this be variable? */
174#define SAMPLE_BUF_SIZE (16*1024)
175#define SAMPLE_FRAME_COUNT (SAMPLE_BUF_SIZE / FRAME_SAMPLE_BYTES)
176/* The driver can explode/shrink the frames to/from a smaller sample
177 buffer */
178#define DMA_BLOAT_FACTOR 1
179#define DMA_DESCR (SAMPLE_FRAME_COUNT / DMA_BLOAT_FACTOR)
180#define DMA_BUF_SIZE (DMA_DESCR * FRAME_BYTES)
181
182/* Use the maxmium count (255 == 5.1 ms between interrupts) */
183#define DMA_INT_CNT ((1 << S_DMA_INT_PKTCNT) - 1)
184
185/* Figure this out: how many TX DMAs ahead to schedule a reg access */
186#define REG_LATENCY 150
187
188#define FRAME_TX_US 20
189
190#define SERDMA_NEXTBUF(d,f) (((d)->f+1) % (d)->ringsz)
191
192static const char invalid_magic[] =
193 KERN_CRIT "cs4297a: invalid magic value\n";
194
195#define VALIDATE_STATE(s) \
196({ \
197 if (!(s) || (s)->magic != CS4297a_MAGIC) { \
198 printk(invalid_magic); \
199 return -ENXIO; \
200 } \
201})
202
203/* AC97 registers */
204#define AC97_MASTER_VOL_STEREO 0x0002 /* Line Out */
205#define AC97_PCBEEP_VOL 0x000a /* none */
206#define AC97_PHONE_VOL 0x000c /* TAD Input (mono) */
207#define AC97_MIC_VOL 0x000e /* MIC Input (mono) */
208#define AC97_LINEIN_VOL 0x0010 /* Line Input (stereo) */
209#define AC97_CD_VOL 0x0012 /* CD Input (stereo) */
210#define AC97_AUX_VOL 0x0016 /* Aux Input (stereo) */
211#define AC97_PCMOUT_VOL 0x0018 /* Wave Output (stereo) */
212#define AC97_RECORD_SELECT 0x001a /* */
213#define AC97_RECORD_GAIN 0x001c
214#define AC97_GENERAL_PURPOSE 0x0020
215#define AC97_3D_CONTROL 0x0022
216#define AC97_POWER_CONTROL 0x0026
217#define AC97_VENDOR_ID1 0x007c
218
219struct list_head cs4297a_devs = { &cs4297a_devs, &cs4297a_devs };
220
221typedef struct serdma_descr_s {
222 u64 descr_a;
223 u64 descr_b;
224} serdma_descr_t;
225
226typedef unsigned long paddr_t;
227
228typedef struct serdma_s {
229 unsigned ringsz;
230 serdma_descr_t *descrtab;
231 serdma_descr_t *descrtab_end;
232 paddr_t descrtab_phys;
233
234 serdma_descr_t *descr_add;
235 serdma_descr_t *descr_rem;
236
237 u64 *dma_buf; // buffer for DMA contents (frames)
238 paddr_t dma_buf_phys;
239 u16 *sample_buf; // tmp buffer for sample conversions
240 u16 *sb_swptr;
241 u16 *sb_hwptr;
242 u16 *sb_end;
243
244 dma_addr_t dmaaddr;
245// unsigned buforder; // Log base 2 of 'dma_buf' size in bytes..
246 unsigned numfrag; // # of 'fragments' in the buffer.
247 unsigned fragshift; // Log base 2 of fragment size.
248 unsigned hwptr, swptr;
249 unsigned total_bytes; // # bytes process since open.
250 unsigned blocks; // last returned blocks value GETOPTR
251 unsigned wakeup; // interrupt occurred on block
252 int count;
253 unsigned underrun; // underrun flag
254 unsigned error; // over/underrun
255 wait_queue_head_t wait;
256 wait_queue_head_t reg_wait;
257 // redundant, but makes calculations easier
258 unsigned fragsize; // 2**fragshift..
259 unsigned sbufsz; // 2**buforder.
260 unsigned fragsamples;
261 // OSS stuff
262 unsigned mapped:1; // Buffer mapped in cs4297a_mmap()?
263 unsigned ready:1; // prog_dmabuf_dac()/adc() successful?
264 unsigned endcleared:1;
265 unsigned type:1; // adc or dac buffer (CS_TYPE_XXX)
266 unsigned ossfragshift;
267 int ossmaxfrags;
268 unsigned subdivision;
269} serdma_t;
270
271struct cs4297a_state {
272 // magic
273 unsigned int magic;
274
275 struct list_head list;
276
277 // soundcore stuff
278 int dev_audio;
279 int dev_mixer;
280
281 // hardware resources
282 unsigned int irq;
283
284 struct {
285 unsigned int rx_ovrrn; /* FIFO */
286 unsigned int rx_overflow; /* staging buffer */
287 unsigned int tx_underrun;
288 unsigned int rx_bad;
289 unsigned int rx_good;
290 } stats;
291
292 // mixer registers
293 struct {
294 unsigned short vol[10];
295 unsigned int recsrc;
296 unsigned int modcnt;
297 unsigned short micpreamp;
298 } mix;
299
300 // wave stuff
301 struct properties {
302 unsigned fmt;
303 unsigned fmt_original; // original requested format
304 unsigned channels;
305 unsigned rate;
306 } prop_dac, prop_adc;
307 unsigned conversion:1; // conversion from 16 to 8 bit in progress
308 unsigned ena;
309 spinlock_t lock;
310 struct mutex open_mutex;
311 struct mutex open_sem_adc;
312 struct mutex open_sem_dac;
313 fmode_t open_mode;
314 wait_queue_head_t open_wait;
315 wait_queue_head_t open_wait_adc;
316 wait_queue_head_t open_wait_dac;
317
318 dma_addr_t dmaaddr_sample_buf;
319 unsigned buforder_sample_buf; // Log base 2 of 'dma_buf' size in bytes..
320
321 serdma_t dma_dac, dma_adc;
322
323 volatile u16 read_value;
324 volatile u16 read_reg;
325 volatile u64 reg_request;
326};
327
328#if 1
329#define prog_codec(a,b)
330#define dealloc_dmabuf(a,b);
331#endif
332
333static int prog_dmabuf_adc(struct cs4297a_state *s)
334{
335 s->dma_adc.ready = 1;
336 return 0;
337}
338
339
340static int prog_dmabuf_dac(struct cs4297a_state *s)
341{
342 s->dma_dac.ready = 1;
343 return 0;
344}
345
346static void clear_advance(void *buf, unsigned bsize, unsigned bptr,
347 unsigned len, unsigned char c)
348{
349 if (bptr + len > bsize) {
350 unsigned x = bsize - bptr;
351 memset(((char *) buf) + bptr, c, x);
352 bptr = 0;
353 len -= x;
354 }
355 CS_DBGOUT(CS_WAVE_WRITE, 4, printk(KERN_INFO
356 "cs4297a: clear_advance(): memset %d at 0x%.8x for %d size \n",
357 (unsigned)c, (unsigned)((char *) buf) + bptr, len));
358 memset(((char *) buf) + bptr, c, len);
359}
360
361#if CSDEBUG
362
363// DEBUG ROUTINES
364
365#define SOUND_MIXER_CS_GETDBGLEVEL _SIOWR('M',120, int)
366#define SOUND_MIXER_CS_SETDBGLEVEL _SIOWR('M',121, int)
367#define SOUND_MIXER_CS_GETDBGMASK _SIOWR('M',122, int)
368#define SOUND_MIXER_CS_SETDBGMASK _SIOWR('M',123, int)
369
370static void cs_printioctl(unsigned int x)
371{
372 unsigned int i;
373 unsigned char vidx;
374 // Index of mixtable1[] member is Device ID
375 // and must be <= SOUND_MIXER_NRDEVICES.
376 // Value of array member is index into s->mix.vol[]
377 static const unsigned char mixtable1[SOUND_MIXER_NRDEVICES] = {
378 [SOUND_MIXER_PCM] = 1, // voice
379 [SOUND_MIXER_LINE1] = 2, // AUX
380 [SOUND_MIXER_CD] = 3, // CD
381 [SOUND_MIXER_LINE] = 4, // Line
382 [SOUND_MIXER_SYNTH] = 5, // FM
383 [SOUND_MIXER_MIC] = 6, // Mic
384 [SOUND_MIXER_SPEAKER] = 7, // Speaker
385 [SOUND_MIXER_RECLEV] = 8, // Recording level
386 [SOUND_MIXER_VOLUME] = 9 // Master Volume
387 };
388
389 switch (x) {
390 case SOUND_MIXER_CS_GETDBGMASK:
391 CS_DBGOUT(CS_IOCTL, 4,
392 printk("SOUND_MIXER_CS_GETDBGMASK:\n"));
393 break;
394 case SOUND_MIXER_CS_GETDBGLEVEL:
395 CS_DBGOUT(CS_IOCTL, 4,
396 printk("SOUND_MIXER_CS_GETDBGLEVEL:\n"));
397 break;
398 case SOUND_MIXER_CS_SETDBGMASK:
399 CS_DBGOUT(CS_IOCTL, 4,
400 printk("SOUND_MIXER_CS_SETDBGMASK:\n"));
401 break;
402 case SOUND_MIXER_CS_SETDBGLEVEL:
403 CS_DBGOUT(CS_IOCTL, 4,
404 printk("SOUND_MIXER_CS_SETDBGLEVEL:\n"));
405 break;
406 case OSS_GETVERSION:
407 CS_DBGOUT(CS_IOCTL, 4, printk("OSS_GETVERSION:\n"));
408 break;
409 case SNDCTL_DSP_SYNC:
410 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SYNC:\n"));
411 break;
412 case SNDCTL_DSP_SETDUPLEX:
413 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETDUPLEX:\n"));
414 break;
415 case SNDCTL_DSP_GETCAPS:
416 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETCAPS:\n"));
417 break;
418 case SNDCTL_DSP_RESET:
419 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_RESET:\n"));
420 break;
421 case SNDCTL_DSP_SPEED:
422 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SPEED:\n"));
423 break;
424 case SNDCTL_DSP_STEREO:
425 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_STEREO:\n"));
426 break;
427 case SNDCTL_DSP_CHANNELS:
428 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_CHANNELS:\n"));
429 break;
430 case SNDCTL_DSP_GETFMTS:
431 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETFMTS:\n"));
432 break;
433 case SNDCTL_DSP_SETFMT:
434 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETFMT:\n"));
435 break;
436 case SNDCTL_DSP_POST:
437 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_POST:\n"));
438 break;
439 case SNDCTL_DSP_GETTRIGGER:
440 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETTRIGGER:\n"));
441 break;
442 case SNDCTL_DSP_SETTRIGGER:
443 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETTRIGGER:\n"));
444 break;
445 case SNDCTL_DSP_GETOSPACE:
446 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETOSPACE:\n"));
447 break;
448 case SNDCTL_DSP_GETISPACE:
449 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETISPACE:\n"));
450 break;
451 case SNDCTL_DSP_NONBLOCK:
452 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_NONBLOCK:\n"));
453 break;
454 case SNDCTL_DSP_GETODELAY:
455 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETODELAY:\n"));
456 break;
457 case SNDCTL_DSP_GETIPTR:
458 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETIPTR:\n"));
459 break;
460 case SNDCTL_DSP_GETOPTR:
461 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETOPTR:\n"));
462 break;
463 case SNDCTL_DSP_GETBLKSIZE:
464 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_GETBLKSIZE:\n"));
465 break;
466 case SNDCTL_DSP_SETFRAGMENT:
467 CS_DBGOUT(CS_IOCTL, 4,
468 printk("SNDCTL_DSP_SETFRAGMENT:\n"));
469 break;
470 case SNDCTL_DSP_SUBDIVIDE:
471 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SUBDIVIDE:\n"));
472 break;
473 case SOUND_PCM_READ_RATE:
474 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_RATE:\n"));
475 break;
476 case SOUND_PCM_READ_CHANNELS:
477 CS_DBGOUT(CS_IOCTL, 4,
478 printk("SOUND_PCM_READ_CHANNELS:\n"));
479 break;
480 case SOUND_PCM_READ_BITS:
481 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_BITS:\n"));
482 break;
483 case SOUND_PCM_WRITE_FILTER:
484 CS_DBGOUT(CS_IOCTL, 4,
485 printk("SOUND_PCM_WRITE_FILTER:\n"));
486 break;
487 case SNDCTL_DSP_SETSYNCRO:
488 CS_DBGOUT(CS_IOCTL, 4, printk("SNDCTL_DSP_SETSYNCRO:\n"));
489 break;
490 case SOUND_PCM_READ_FILTER:
491 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_PCM_READ_FILTER:\n"));
492 break;
493 case SOUND_MIXER_PRIVATE1:
494 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE1:\n"));
495 break;
496 case SOUND_MIXER_PRIVATE2:
497 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE2:\n"));
498 break;
499 case SOUND_MIXER_PRIVATE3:
500 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE3:\n"));
501 break;
502 case SOUND_MIXER_PRIVATE4:
503 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE4:\n"));
504 break;
505 case SOUND_MIXER_PRIVATE5:
506 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_PRIVATE5:\n"));
507 break;
508 case SOUND_MIXER_INFO:
509 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_INFO:\n"));
510 break;
511 case SOUND_OLD_MIXER_INFO:
512 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_OLD_MIXER_INFO:\n"));
513 break;
514
515 default:
516 switch (_IOC_NR(x)) {
517 case SOUND_MIXER_VOLUME:
518 CS_DBGOUT(CS_IOCTL, 4,
519 printk("SOUND_MIXER_VOLUME:\n"));
520 break;
521 case SOUND_MIXER_SPEAKER:
522 CS_DBGOUT(CS_IOCTL, 4,
523 printk("SOUND_MIXER_SPEAKER:\n"));
524 break;
525 case SOUND_MIXER_RECLEV:
526 CS_DBGOUT(CS_IOCTL, 4,
527 printk("SOUND_MIXER_RECLEV:\n"));
528 break;
529 case SOUND_MIXER_MIC:
530 CS_DBGOUT(CS_IOCTL, 4,
531 printk("SOUND_MIXER_MIC:\n"));
532 break;
533 case SOUND_MIXER_SYNTH:
534 CS_DBGOUT(CS_IOCTL, 4,
535 printk("SOUND_MIXER_SYNTH:\n"));
536 break;
537 case SOUND_MIXER_RECSRC:
538 CS_DBGOUT(CS_IOCTL, 4,
539 printk("SOUND_MIXER_RECSRC:\n"));
540 break;
541 case SOUND_MIXER_DEVMASK:
542 CS_DBGOUT(CS_IOCTL, 4,
543 printk("SOUND_MIXER_DEVMASK:\n"));
544 break;
545 case SOUND_MIXER_RECMASK:
546 CS_DBGOUT(CS_IOCTL, 4,
547 printk("SOUND_MIXER_RECMASK:\n"));
548 break;
549 case SOUND_MIXER_STEREODEVS:
550 CS_DBGOUT(CS_IOCTL, 4,
551 printk("SOUND_MIXER_STEREODEVS:\n"));
552 break;
553 case SOUND_MIXER_CAPS:
554 CS_DBGOUT(CS_IOCTL, 4, printk("SOUND_MIXER_CAPS:\n"));
555 break;
556 default:
557 i = _IOC_NR(x);
558 if (i >= SOUND_MIXER_NRDEVICES
559 || !(vidx = mixtable1[i])) {
560 CS_DBGOUT(CS_IOCTL, 4, printk
561 ("UNKNOWN IOCTL: 0x%.8x NR=%d\n",
562 x, i));
563 } else {
564 CS_DBGOUT(CS_IOCTL, 4, printk
565 ("SOUND_MIXER_IOCTL AC9x: 0x%.8x NR=%d\n",
566 x, i));
567 }
568 break;
569 }
570 }
571}
572#endif
573
574
575static int ser_init(struct cs4297a_state *s)
576{
577 int i;
578
579 CS_DBGOUT(CS_INIT, 2,
580 printk(KERN_INFO "cs4297a: Setting up serial parameters\n"));
581
582 __raw_writeq(M_SYNCSER_CMD_RX_RESET | M_SYNCSER_CMD_TX_RESET, SS_CSR(R_SER_CMD));
583
584 __raw_writeq(M_SYNCSER_MSB_FIRST, SS_CSR(R_SER_MODE));
585 __raw_writeq(32, SS_CSR(R_SER_MINFRM_SZ));
586 __raw_writeq(32, SS_CSR(R_SER_MAXFRM_SZ));
587
588 __raw_writeq(1, SS_CSR(R_SER_TX_RD_THRSH));
589 __raw_writeq(4, SS_CSR(R_SER_TX_WR_THRSH));
590 __raw_writeq(8, SS_CSR(R_SER_RX_RD_THRSH));
591
592 /* This looks good from experimentation */
593 __raw_writeq((M_SYNCSER_TXSYNC_INT | V_SYNCSER_TXSYNC_DLY(0) | M_SYNCSER_TXCLK_EXT |
594 M_SYNCSER_RXSYNC_INT | V_SYNCSER_RXSYNC_DLY(1) | M_SYNCSER_RXCLK_EXT | M_SYNCSER_RXSYNC_EDGE),
595 SS_CSR(R_SER_LINE_MODE));
596
597 /* This looks good from experimentation */
598 __raw_writeq(V_SYNCSER_SEQ_COUNT(14) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_STROBE,
599 SS_TXTBL(0));
600 __raw_writeq(V_SYNCSER_SEQ_COUNT(15) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_BYTE,
601 SS_TXTBL(1));
602 __raw_writeq(V_SYNCSER_SEQ_COUNT(13) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_BYTE,
603 SS_TXTBL(2));
604 __raw_writeq(V_SYNCSER_SEQ_COUNT( 0) | M_SYNCSER_SEQ_ENABLE |
605 M_SYNCSER_SEQ_STROBE | M_SYNCSER_SEQ_LAST, SS_TXTBL(3));
606
607 __raw_writeq(V_SYNCSER_SEQ_COUNT(14) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_STROBE,
608 SS_RXTBL(0));
609 __raw_writeq(V_SYNCSER_SEQ_COUNT(15) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_BYTE,
610 SS_RXTBL(1));
611 __raw_writeq(V_SYNCSER_SEQ_COUNT(13) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_BYTE,
612 SS_RXTBL(2));
613 __raw_writeq(V_SYNCSER_SEQ_COUNT( 0) | M_SYNCSER_SEQ_ENABLE | M_SYNCSER_SEQ_STROBE |
614 M_SYNCSER_SEQ_LAST, SS_RXTBL(3));
615
616 for (i=4; i<16; i++) {
617 /* Just in case... */
618 __raw_writeq(M_SYNCSER_SEQ_LAST, SS_TXTBL(i));
619 __raw_writeq(M_SYNCSER_SEQ_LAST, SS_RXTBL(i));
620 }
621
622 return 0;
623}
624
625static int init_serdma(serdma_t *dma)
626{
627 CS_DBGOUT(CS_INIT, 2,
628 printk(KERN_ERR "cs4297a: desc - %d sbufsize - %d dbufsize - %d\n",
629 DMA_DESCR, SAMPLE_BUF_SIZE, DMA_BUF_SIZE));
630
631 /* Descriptors */
632 dma->ringsz = DMA_DESCR;
633 dma->descrtab = kzalloc(dma->ringsz * sizeof(serdma_descr_t), GFP_KERNEL);
634 if (!dma->descrtab) {
635 printk(KERN_ERR "cs4297a: kzalloc descrtab failed\n");
636 return -1;
637 }
638 dma->descrtab_end = dma->descrtab + dma->ringsz;
639 /* XXX bloddy mess, use proper DMA API here ... */
640 dma->descrtab_phys = CPHYSADDR((long)dma->descrtab);
641 dma->descr_add = dma->descr_rem = dma->descrtab;
642
643 /* Frame buffer area */
644 dma->dma_buf = kzalloc(DMA_BUF_SIZE, GFP_KERNEL);
645 if (!dma->dma_buf) {
646 printk(KERN_ERR "cs4297a: kzalloc dma_buf failed\n");
647 kfree(dma->descrtab);
648 return -1;
649 }
650 dma->dma_buf_phys = CPHYSADDR((long)dma->dma_buf);
651
652 /* Samples buffer area */
653 dma->sbufsz = SAMPLE_BUF_SIZE;
654 dma->sample_buf = kmalloc(dma->sbufsz, GFP_KERNEL);
655 if (!dma->sample_buf) {
656 printk(KERN_ERR "cs4297a: kmalloc sample_buf failed\n");
657 kfree(dma->descrtab);
658 kfree(dma->dma_buf);
659 return -1;
660 }
661 dma->sb_swptr = dma->sb_hwptr = dma->sample_buf;
662 dma->sb_end = (u16 *)((void *)dma->sample_buf + dma->sbufsz);
663 dma->fragsize = dma->sbufsz >> 1;
664
665 CS_DBGOUT(CS_INIT, 4,
666 printk(KERN_ERR "cs4297a: descrtab - %08x dma_buf - %x sample_buf - %x\n",
667 (int)dma->descrtab, (int)dma->dma_buf,
668 (int)dma->sample_buf));
669
670 return 0;
671}
672
673static int dma_init(struct cs4297a_state *s)
674{
675 int i;
676
677 CS_DBGOUT(CS_INIT, 2,
678 printk(KERN_INFO "cs4297a: Setting up DMA\n"));
679
680 if (init_serdma(&s->dma_adc) ||
681 init_serdma(&s->dma_dac))
682 return -1;
683
684 if (__raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_RX))||
685 __raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_TX))) {
686 panic("DMA state corrupted?!");
687 }
688
689 /* Initialize now - the descr/buffer pairings will never
690 change... */
691 for (i=0; i<DMA_DESCR; i++) {
692 s->dma_dac.descrtab[i].descr_a = M_DMA_SERRX_SOP | V_DMA_DSCRA_A_SIZE(1) |
693 (s->dma_dac.dma_buf_phys + i*FRAME_BYTES);
694 s->dma_dac.descrtab[i].descr_b = V_DMA_DSCRB_PKT_SIZE(FRAME_BYTES);
695 s->dma_adc.descrtab[i].descr_a = V_DMA_DSCRA_A_SIZE(1) |
696 (s->dma_adc.dma_buf_phys + i*FRAME_BYTES);
697 s->dma_adc.descrtab[i].descr_b = 0;
698 }
699
700 __raw_writeq((M_DMA_EOP_INT_EN | V_DMA_INT_PKTCNT(DMA_INT_CNT) |
701 V_DMA_RINGSZ(DMA_DESCR) | M_DMA_TDX_EN),
702 SS_CSR(R_SER_DMA_CONFIG0_RX));
703 __raw_writeq(M_DMA_L2CA, SS_CSR(R_SER_DMA_CONFIG1_RX));
704 __raw_writeq(s->dma_adc.descrtab_phys, SS_CSR(R_SER_DMA_DSCR_BASE_RX));
705
706 __raw_writeq(V_DMA_RINGSZ(DMA_DESCR), SS_CSR(R_SER_DMA_CONFIG0_TX));
707 __raw_writeq(M_DMA_L2CA | M_DMA_NO_DSCR_UPDT, SS_CSR(R_SER_DMA_CONFIG1_TX));
708 __raw_writeq(s->dma_dac.descrtab_phys, SS_CSR(R_SER_DMA_DSCR_BASE_TX));
709
710 /* Prep the receive DMA descriptor ring */
711 __raw_writeq(DMA_DESCR, SS_CSR(R_SER_DMA_DSCR_COUNT_RX));
712
713 __raw_writeq(M_SYNCSER_DMA_RX_EN | M_SYNCSER_DMA_TX_EN, SS_CSR(R_SER_DMA_ENABLE));
714
715 __raw_writeq((M_SYNCSER_RX_SYNC_ERR | M_SYNCSER_RX_OVERRUN | M_SYNCSER_RX_EOP_COUNT),
716 SS_CSR(R_SER_INT_MASK));
717
718 /* Enable the rx/tx; let the codec warm up to the sync and
719 start sending good frames before the receive FIFO is
720 enabled */
721 __raw_writeq(M_SYNCSER_CMD_TX_EN, SS_CSR(R_SER_CMD));
722 udelay(1000);
723 __raw_writeq(M_SYNCSER_CMD_RX_EN | M_SYNCSER_CMD_TX_EN, SS_CSR(R_SER_CMD));
724
725 /* XXXKW is this magic? (the "1" part) */
726 while ((__raw_readq(SS_CSR(R_SER_STATUS)) & 0xf1) != 1)
727 ;
728
729 CS_DBGOUT(CS_INIT, 4,
730 printk(KERN_INFO "cs4297a: status: %08x\n",
731 (unsigned int)(__raw_readq(SS_CSR(R_SER_STATUS)) & 0xffffffff)));
732
733 return 0;
734}
735
736static int serdma_reg_access(struct cs4297a_state *s, u64 data)
737{
738 serdma_t *d = &s->dma_dac;
739 u64 *data_p;
740 unsigned swptr;
741 unsigned long flags;
742 serdma_descr_t *descr;
743
744 if (s->reg_request) {
745 printk(KERN_ERR "cs4297a: attempt to issue multiple reg_access\n");
746 return -1;
747 }
748
749 if (s->ena & FMODE_WRITE) {
750 /* Since a writer has the DSP open, we have to mux the
751 request in */
752 s->reg_request = data;
753 oss_broken_sleep_on(&s->dma_dac.reg_wait, MAX_SCHEDULE_TIMEOUT);
754 /* XXXKW how can I deal with the starvation case where
755 the opener isn't writing? */
756 } else {
757 /* Be safe when changing ring pointers */
758 spin_lock_irqsave(&s->lock, flags);
759 if (d->hwptr != d->swptr) {
760 printk(KERN_ERR "cs4297a: reg access found bookkeeping error (hw/sw = %d/%d\n",
761 d->hwptr, d->swptr);
762 spin_unlock_irqrestore(&s->lock, flags);
763 return -1;
764 }
765 swptr = d->swptr;
766 d->hwptr = d->swptr = (d->swptr + 1) % d->ringsz;
767 spin_unlock_irqrestore(&s->lock, flags);
768
769 descr = &d->descrtab[swptr];
770 data_p = &d->dma_buf[swptr * 4];
771 *data_p = cpu_to_be64(data);
772 __raw_writeq(1, SS_CSR(R_SER_DMA_DSCR_COUNT_TX));
773 CS_DBGOUT(CS_DESCR, 4,
774 printk(KERN_INFO "cs4297a: add_tx %p (%x -> %x)\n",
775 data_p, swptr, d->hwptr));
776 }
777
778 CS_DBGOUT(CS_FUNCTION, 6,
779 printk(KERN_INFO "cs4297a: serdma_reg_access()-\n"));
780
781 return 0;
782}
783
784//****************************************************************************
785// "cs4297a_read_ac97" -- Reads an AC97 register
786//****************************************************************************
787static int cs4297a_read_ac97(struct cs4297a_state *s, u32 offset,
788 u32 * value)
789{
790 CS_DBGOUT(CS_AC97, 1,
791 printk(KERN_INFO "cs4297a: read reg %2x\n", offset));
792 if (serdma_reg_access(s, (0xCLL << 60) | (1LL << 47) | ((u64)(offset & 0x7F) << 40)))
793 return -1;
794
795 oss_broken_sleep_on(&s->dma_adc.reg_wait, MAX_SCHEDULE_TIMEOUT);
796 *value = s->read_value;
797 CS_DBGOUT(CS_AC97, 2,
798 printk(KERN_INFO "cs4297a: rdr reg %x -> %x\n", s->read_reg, s->read_value));
799
800 return 0;
801}
802
803
804//****************************************************************************
805// "cs4297a_write_ac97()"-- writes an AC97 register
806//****************************************************************************
807static int cs4297a_write_ac97(struct cs4297a_state *s, u32 offset,
808 u32 value)
809{
810 CS_DBGOUT(CS_AC97, 1,
811 printk(KERN_INFO "cs4297a: write reg %2x -> %04x\n", offset, value));
812 return (serdma_reg_access(s, (0xELL << 60) | ((u64)(offset & 0x7F) << 40) | ((value & 0xffff) << 12)));
813}
814
815static void stop_dac(struct cs4297a_state *s)
816{
817 unsigned long flags;
818
819 CS_DBGOUT(CS_WAVE_WRITE, 3, printk(KERN_INFO "cs4297a: stop_dac():\n"));
820 spin_lock_irqsave(&s->lock, flags);
821 s->ena &= ~FMODE_WRITE;
822#if 0
823 /* XXXKW what do I really want here? My theory for now is
824 that I just flip the "ena" bit, and the interrupt handler
825 will stop processing the xmit channel */
826 __raw_writeq((s->ena & FMODE_READ) ? M_SYNCSER_DMA_RX_EN : 0,
827 SS_CSR(R_SER_DMA_ENABLE));
828#endif
829
830 spin_unlock_irqrestore(&s->lock, flags);
831}
832
833
834static void start_dac(struct cs4297a_state *s)
835{
836 unsigned long flags;
837
838 CS_DBGOUT(CS_FUNCTION, 3, printk(KERN_INFO "cs4297a: start_dac()+\n"));
839 spin_lock_irqsave(&s->lock, flags);
840 if (!(s->ena & FMODE_WRITE) && (s->dma_dac.mapped ||
841 (s->dma_dac.count > 0
842 && s->dma_dac.ready))) {
843 s->ena |= FMODE_WRITE;
844 /* XXXKW what do I really want here? My theory for
845 now is that I just flip the "ena" bit, and the
846 interrupt handler will start processing the xmit
847 channel */
848
849 CS_DBGOUT(CS_WAVE_WRITE | CS_PARMS, 8, printk(KERN_INFO
850 "cs4297a: start_dac(): start dma\n"));
851
852 }
853 spin_unlock_irqrestore(&s->lock, flags);
854 CS_DBGOUT(CS_FUNCTION, 3,
855 printk(KERN_INFO "cs4297a: start_dac()-\n"));
856}
857
858
859static void stop_adc(struct cs4297a_state *s)
860{
861 unsigned long flags;
862
863 CS_DBGOUT(CS_FUNCTION, 3,
864 printk(KERN_INFO "cs4297a: stop_adc()+\n"));
865
866 spin_lock_irqsave(&s->lock, flags);
867 s->ena &= ~FMODE_READ;
868
869 if (s->conversion == 1) {
870 s->conversion = 0;
871 s->prop_adc.fmt = s->prop_adc.fmt_original;
872 }
873 /* Nothing to do really, I need to keep the DMA going
874 XXXKW when do I get here, and is there more I should do? */
875 spin_unlock_irqrestore(&s->lock, flags);
876 CS_DBGOUT(CS_FUNCTION, 3,
877 printk(KERN_INFO "cs4297a: stop_adc()-\n"));
878}
879
880
881static void start_adc(struct cs4297a_state *s)
882{
883 unsigned long flags;
884
885 CS_DBGOUT(CS_FUNCTION, 2,
886 printk(KERN_INFO "cs4297a: start_adc()+\n"));
887
888 if (!(s->ena & FMODE_READ) &&
889 (s->dma_adc.mapped || s->dma_adc.count <=
890 (signed) (s->dma_adc.sbufsz - 2 * s->dma_adc.fragsize))
891 && s->dma_adc.ready) {
892 if (s->prop_adc.fmt & AFMT_S8 || s->prop_adc.fmt & AFMT_U8) {
893 //
894 // now only use 16 bit capture, due to truncation issue
895 // in the chip, noticeable distortion occurs.
896 // allocate buffer and then convert from 16 bit to
897 // 8 bit for the user buffer.
898 //
899 s->prop_adc.fmt_original = s->prop_adc.fmt;
900 if (s->prop_adc.fmt & AFMT_S8) {
901 s->prop_adc.fmt &= ~AFMT_S8;
902 s->prop_adc.fmt |= AFMT_S16_LE;
903 }
904 if (s->prop_adc.fmt & AFMT_U8) {
905 s->prop_adc.fmt &= ~AFMT_U8;
906 s->prop_adc.fmt |= AFMT_U16_LE;
907 }
908 //
909 // prog_dmabuf_adc performs a stop_adc() but that is
910 // ok since we really haven't started the DMA yet.
911 //
912 prog_codec(s, CS_TYPE_ADC);
913
914 prog_dmabuf_adc(s);
915 s->conversion = 1;
916 }
917 spin_lock_irqsave(&s->lock, flags);
918 s->ena |= FMODE_READ;
919 /* Nothing to do really, I am probably already
920 DMAing... XXXKW when do I get here, and is there
921 more I should do? */
922 spin_unlock_irqrestore(&s->lock, flags);
923
924 CS_DBGOUT(CS_PARMS, 6, printk(KERN_INFO
925 "cs4297a: start_adc(): start adc\n"));
926 }
927 CS_DBGOUT(CS_FUNCTION, 2,
928 printk(KERN_INFO "cs4297a: start_adc()-\n"));
929
930}
931
932
933// call with spinlock held!
934static void cs4297a_update_ptr(struct cs4297a_state *s, int intflag)
935{
936 int good_diff, diff, diff2;
937 u64 *data_p, data;
938 u32 *s_ptr;
939 unsigned hwptr;
940 u32 status;
941 serdma_t *d;
942 serdma_descr_t *descr;
943
944 // update ADC pointer
945 status = intflag ? __raw_readq(SS_CSR(R_SER_STATUS)) : 0;
946
947 if ((s->ena & FMODE_READ) || (status & (M_SYNCSER_RX_EOP_COUNT))) {
948 d = &s->dma_adc;
949 hwptr = (unsigned) (((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_RX)) & M_DMA_CURDSCR_ADDR) -
950 d->descrtab_phys) / sizeof(serdma_descr_t));
951
952 if (s->ena & FMODE_READ) {
953 CS_DBGOUT(CS_FUNCTION, 2,
954 printk(KERN_INFO "cs4297a: upd_rcv sw->hw->hw %x/%x/%x (int-%d)n",
955 d->swptr, d->hwptr, hwptr, intflag));
956 /* Number of DMA buffers available for software: */
957 diff2 = diff = (d->ringsz + hwptr - d->hwptr) % d->ringsz;
958 d->hwptr = hwptr;
959 good_diff = 0;
960 s_ptr = (u32 *)&(d->dma_buf[d->swptr*4]);
961 descr = &d->descrtab[d->swptr];
962 while (diff2--) {
963 u64 data = be64_to_cpu(*(u64 *)s_ptr);
964 u64 descr_a;
965 u16 left, right;
966 descr_a = descr->descr_a;
967 descr->descr_a &= ~M_DMA_SERRX_SOP;
968 if ((descr_a & M_DMA_DSCRA_A_ADDR) != CPHYSADDR((long)s_ptr)) {
969 printk(KERN_ERR "cs4297a: RX Bad address (read)\n");
970 }
971 if (((data & 0x9800000000000000) != 0x9800000000000000) ||
972 (!(descr_a & M_DMA_SERRX_SOP)) ||
973 (G_DMA_DSCRB_PKT_SIZE(descr->descr_b) != FRAME_BYTES)) {
974 s->stats.rx_bad++;
975 printk(KERN_DEBUG "cs4297a: RX Bad attributes (read)\n");
976 continue;
977 }
978 s->stats.rx_good++;
979 if ((data >> 61) == 7) {
980 s->read_value = (data >> 12) & 0xffff;
981 s->read_reg = (data >> 40) & 0x7f;
982 wake_up(&d->reg_wait);
983 }
984 if (d->count && (d->sb_hwptr == d->sb_swptr)) {
985 s->stats.rx_overflow++;
986 printk(KERN_DEBUG "cs4297a: RX overflow\n");
987 continue;
988 }
989 good_diff++;
990 left = ((be32_to_cpu(s_ptr[1]) & 0xff) << 8) |
991 ((be32_to_cpu(s_ptr[2]) >> 24) & 0xff);
992 right = (be32_to_cpu(s_ptr[2]) >> 4) & 0xffff;
993 *d->sb_hwptr++ = cpu_to_be16(left);
994 *d->sb_hwptr++ = cpu_to_be16(right);
995 if (d->sb_hwptr == d->sb_end)
996 d->sb_hwptr = d->sample_buf;
997 descr++;
998 if (descr == d->descrtab_end) {
999 descr = d->descrtab;
1000 s_ptr = (u32 *)s->dma_adc.dma_buf;
1001 } else {
1002 s_ptr += 8;
1003 }
1004 }
1005 d->total_bytes += good_diff * FRAME_SAMPLE_BYTES;
1006 d->count += good_diff * FRAME_SAMPLE_BYTES;
1007 if (d->count > d->sbufsz) {
1008 printk(KERN_ERR "cs4297a: bogus receive overflow!!\n");
1009 }
1010 d->swptr = (d->swptr + diff) % d->ringsz;
1011 __raw_writeq(diff, SS_CSR(R_SER_DMA_DSCR_COUNT_RX));
1012 if (d->mapped) {
1013 if (d->count >= (signed) d->fragsize)
1014 wake_up(&d->wait);
1015 } else {
1016 if (d->count > 0) {
1017 CS_DBGOUT(CS_WAVE_READ, 4,
1018 printk(KERN_INFO
1019 "cs4297a: update count -> %d\n", d->count));
1020 wake_up(&d->wait);
1021 }
1022 }
1023 } else {
1024 /* Receive is going even if no one is
1025 listening (for register accesses and to
1026 avoid FIFO overrun) */
1027 diff2 = diff = (hwptr + d->ringsz - d->hwptr) % d->ringsz;
1028 if (!diff) {
1029 printk(KERN_ERR "cs4297a: RX full or empty?\n");
1030 }
1031
1032 descr = &d->descrtab[d->swptr];
1033 data_p = &d->dma_buf[d->swptr*4];
1034
1035 /* Force this to happen at least once; I got
1036 here because of an interrupt, so there must
1037 be a buffer to process. */
1038 do {
1039 data = be64_to_cpu(*data_p);
1040 if ((descr->descr_a & M_DMA_DSCRA_A_ADDR) != CPHYSADDR((long)data_p)) {
1041 printk(KERN_ERR "cs4297a: RX Bad address %d (%llx %lx)\n", d->swptr,
1042 (long long)(descr->descr_a & M_DMA_DSCRA_A_ADDR),
1043 (long)CPHYSADDR((long)data_p));
1044 }
1045 if (!(data & (1LL << 63)) ||
1046 !(descr->descr_a & M_DMA_SERRX_SOP) ||
1047 (G_DMA_DSCRB_PKT_SIZE(descr->descr_b) != FRAME_BYTES)) {
1048 s->stats.rx_bad++;
1049 printk(KERN_DEBUG "cs4297a: RX Bad attributes\n");
1050 } else {
1051 s->stats.rx_good++;
1052 if ((data >> 61) == 7) {
1053 s->read_value = (data >> 12) & 0xffff;
1054 s->read_reg = (data >> 40) & 0x7f;
1055 wake_up(&d->reg_wait);
1056 }
1057 }
1058 descr->descr_a &= ~M_DMA_SERRX_SOP;
1059 descr++;
1060 d->swptr++;
1061 data_p += 4;
1062 if (descr == d->descrtab_end) {
1063 descr = d->descrtab;
1064 d->swptr = 0;
1065 data_p = d->dma_buf;
1066 }
1067 __raw_writeq(1, SS_CSR(R_SER_DMA_DSCR_COUNT_RX));
1068 } while (--diff);
1069 d->hwptr = hwptr;
1070
1071 CS_DBGOUT(CS_DESCR, 6,
1072 printk(KERN_INFO "cs4297a: hw/sw %x/%x\n", d->hwptr, d->swptr));
1073 }
1074
1075 CS_DBGOUT(CS_PARMS, 8, printk(KERN_INFO
1076 "cs4297a: cs4297a_update_ptr(): s=0x%.8x hwptr=%d total_bytes=%d count=%d \n",
1077 (unsigned)s, d->hwptr,
1078 d->total_bytes, d->count));
1079 }
1080
1081 /* XXXKW worry about s->reg_request -- there is a starvation
1082 case if s->ena has FMODE_WRITE on, but the client isn't
1083 doing writes */
1084
1085 // update DAC pointer
1086 //
1087 // check for end of buffer, means that we are going to wait for another interrupt
1088 // to allow silence to fill the fifos on the part, to keep pops down to a minimum.
1089 //
1090 if (s->ena & FMODE_WRITE) {
1091 serdma_t *d = &s->dma_dac;
1092 hwptr = (unsigned) (((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_TX)) & M_DMA_CURDSCR_ADDR) -
1093 d->descrtab_phys) / sizeof(serdma_descr_t));
1094 diff = (d->ringsz + hwptr - d->hwptr) % d->ringsz;
1095 CS_DBGOUT(CS_WAVE_WRITE, 4, printk(KERN_INFO
1096 "cs4297a: cs4297a_update_ptr(): hw/hw/sw %x/%x/%x diff %d count %d\n",
1097 d->hwptr, hwptr, d->swptr, diff, d->count));
1098 d->hwptr = hwptr;
1099 /* XXXKW stereo? conversion? Just assume 2 16-bit samples for now */
1100 d->total_bytes += diff * FRAME_SAMPLE_BYTES;
1101 if (d->mapped) {
1102 d->count += diff * FRAME_SAMPLE_BYTES;
1103 if (d->count >= d->fragsize) {
1104 d->wakeup = 1;
1105 wake_up(&d->wait);
1106 if (d->count > d->sbufsz)
1107 d->count &= d->sbufsz - 1;
1108 }
1109 } else {
1110 d->count -= diff * FRAME_SAMPLE_BYTES;
1111 if (d->count <= 0) {
1112 //
1113 // fill with silence, and do not shut down the DAC.
1114 // Continue to play silence until the _release.
1115 //
1116 CS_DBGOUT(CS_WAVE_WRITE, 6, printk(KERN_INFO
1117 "cs4297a: cs4297a_update_ptr(): memset %d at 0x%.8x for %d size \n",
1118 (unsigned)(s->prop_dac.fmt &
1119 (AFMT_U8 | AFMT_U16_LE)) ? 0x80 : 0,
1120 (unsigned)d->dma_buf,
1121 d->ringsz));
1122 memset(d->dma_buf, 0, d->ringsz * FRAME_BYTES);
1123 if (d->count < 0) {
1124 d->underrun = 1;
1125 s->stats.tx_underrun++;
1126 d->count = 0;
1127 CS_DBGOUT(CS_ERROR, 9, printk(KERN_INFO
1128 "cs4297a: cs4297a_update_ptr(): underrun\n"));
1129 }
1130 } else if (d->count <=
1131 (signed) d->fragsize
1132 && !d->endcleared) {
1133 /* XXXKW what is this for? */
1134 clear_advance(d->dma_buf,
1135 d->sbufsz,
1136 d->swptr,
1137 d->fragsize,
1138 0);
1139 d->endcleared = 1;
1140 }
1141 if ( (d->count <= (signed) d->sbufsz/2) || intflag)
1142 {
1143 CS_DBGOUT(CS_WAVE_WRITE, 4,
1144 printk(KERN_INFO
1145 "cs4297a: update count -> %d\n", d->count));
1146 wake_up(&d->wait);
1147 }
1148 }
1149 CS_DBGOUT(CS_PARMS, 8, printk(KERN_INFO
1150 "cs4297a: cs4297a_update_ptr(): s=0x%.8x hwptr=%d total_bytes=%d count=%d \n",
1151 (unsigned) s, d->hwptr,
1152 d->total_bytes, d->count));
1153 }
1154}
1155
1156static int mixer_ioctl(struct cs4297a_state *s, unsigned int cmd,
1157 unsigned long arg)
1158{
1159 // Index to mixer_src[] is value of AC97 Input Mux Select Reg.
1160 // Value of array member is recording source Device ID Mask.
1161 static const unsigned int mixer_src[8] = {
1162 SOUND_MASK_MIC, SOUND_MASK_CD, 0, SOUND_MASK_LINE1,
1163 SOUND_MASK_LINE, SOUND_MASK_VOLUME, 0, 0
1164 };
1165
1166 // Index of mixtable1[] member is Device ID
1167 // and must be <= SOUND_MIXER_NRDEVICES.
1168 // Value of array member is index into s->mix.vol[]
1169 static const unsigned char mixtable1[SOUND_MIXER_NRDEVICES] = {
1170 [SOUND_MIXER_PCM] = 1, // voice
1171 [SOUND_MIXER_LINE1] = 2, // AUX
1172 [SOUND_MIXER_CD] = 3, // CD
1173 [SOUND_MIXER_LINE] = 4, // Line
1174 [SOUND_MIXER_SYNTH] = 5, // FM
1175 [SOUND_MIXER_MIC] = 6, // Mic
1176 [SOUND_MIXER_SPEAKER] = 7, // Speaker
1177 [SOUND_MIXER_RECLEV] = 8, // Recording level
1178 [SOUND_MIXER_VOLUME] = 9 // Master Volume
1179 };
1180
1181 static const unsigned mixreg[] = {
1182 AC97_PCMOUT_VOL,
1183 AC97_AUX_VOL,
1184 AC97_CD_VOL,
1185 AC97_LINEIN_VOL
1186 };
1187 unsigned char l, r, rl, rr, vidx;
1188 unsigned char attentbl[11] =
1189 { 63, 42, 26, 17, 14, 11, 8, 6, 4, 2, 0 };
1190 unsigned temp1;
1191 int i, val;
1192
1193 VALIDATE_STATE(s);
1194 CS_DBGOUT(CS_FUNCTION, 4, printk(KERN_INFO
1195 "cs4297a: mixer_ioctl(): s=0x%.8x cmd=0x%.8x\n",
1196 (unsigned) s, cmd));
1197#if CSDEBUG
1198 cs_printioctl(cmd);
1199#endif
1200#if CSDEBUG_INTERFACE
1201
1202 if ((cmd == SOUND_MIXER_CS_GETDBGMASK) ||
1203 (cmd == SOUND_MIXER_CS_SETDBGMASK) ||
1204 (cmd == SOUND_MIXER_CS_GETDBGLEVEL) ||
1205 (cmd == SOUND_MIXER_CS_SETDBGLEVEL))
1206 {
1207 switch (cmd) {
1208
1209 case SOUND_MIXER_CS_GETDBGMASK:
1210 return put_user(cs_debugmask,
1211 (unsigned long *) arg);
1212
1213 case SOUND_MIXER_CS_GETDBGLEVEL:
1214 return put_user(cs_debuglevel,
1215 (unsigned long *) arg);
1216
1217 case SOUND_MIXER_CS_SETDBGMASK:
1218 if (get_user(val, (unsigned long *) arg))
1219 return -EFAULT;
1220 cs_debugmask = val;
1221 return 0;
1222
1223 case SOUND_MIXER_CS_SETDBGLEVEL:
1224 if (get_user(val, (unsigned long *) arg))
1225 return -EFAULT;
1226 cs_debuglevel = val;
1227 return 0;
1228 default:
1229 CS_DBGOUT(CS_ERROR, 1, printk(KERN_INFO
1230 "cs4297a: mixer_ioctl(): ERROR unknown debug cmd\n"));
1231 return 0;
1232 }
1233 }
1234#endif
1235
1236 if (cmd == SOUND_MIXER_PRIVATE1) {
1237 return -EINVAL;
1238 }
1239 if (cmd == SOUND_MIXER_PRIVATE2) {
1240 // enable/disable/query spatializer
1241 if (get_user(val, (int *) arg))
1242 return -EFAULT;
1243 if (val != -1) {
1244 temp1 = (val & 0x3f) >> 2;
1245 cs4297a_write_ac97(s, AC97_3D_CONTROL, temp1);
1246 cs4297a_read_ac97(s, AC97_GENERAL_PURPOSE,
1247 &temp1);
1248 cs4297a_write_ac97(s, AC97_GENERAL_PURPOSE,
1249 temp1 | 0x2000);
1250 }
1251 cs4297a_read_ac97(s, AC97_3D_CONTROL, &temp1);
1252 return put_user((temp1 << 2) | 3, (int *) arg);
1253 }
1254 if (cmd == SOUND_MIXER_INFO) {
1255 mixer_info info;
1256 memset(&info, 0, sizeof(info));
1257 strlcpy(info.id, "CS4297a", sizeof(info.id));
1258 strlcpy(info.name, "Crystal CS4297a", sizeof(info.name));
1259 info.modify_counter = s->mix.modcnt;
1260 if (copy_to_user((void *) arg, &info, sizeof(info)))
1261 return -EFAULT;
1262 return 0;
1263 }
1264 if (cmd == SOUND_OLD_MIXER_INFO) {
1265 _old_mixer_info info;
1266 memset(&info, 0, sizeof(info));
1267 strlcpy(info.id, "CS4297a", sizeof(info.id));
1268 strlcpy(info.name, "Crystal CS4297a", sizeof(info.name));
1269 if (copy_to_user((void *) arg, &info, sizeof(info)))
1270 return -EFAULT;
1271 return 0;
1272 }
1273 if (cmd == OSS_GETVERSION)
1274 return put_user(SOUND_VERSION, (int *) arg);
1275
1276 if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int))
1277 return -EINVAL;
1278
1279 // If ioctl has only the SIOC_READ bit(bit 31)
1280 // on, process the only-read commands.
1281 if (_SIOC_DIR(cmd) == _SIOC_READ) {
1282 switch (_IOC_NR(cmd)) {
1283 case SOUND_MIXER_RECSRC: // Arg contains a bit for each recording source
1284 cs4297a_read_ac97(s, AC97_RECORD_SELECT,
1285 &temp1);
1286 return put_user(mixer_src[temp1 & 7], (int *) arg);
1287
1288 case SOUND_MIXER_DEVMASK: // Arg contains a bit for each supported device
1289 return put_user(SOUND_MASK_PCM | SOUND_MASK_LINE |
1290 SOUND_MASK_VOLUME | SOUND_MASK_RECLEV,
1291 (int *) arg);
1292
1293 case SOUND_MIXER_RECMASK: // Arg contains a bit for each supported recording source
1294 return put_user(SOUND_MASK_LINE | SOUND_MASK_VOLUME,
1295 (int *) arg);
1296
1297 case SOUND_MIXER_STEREODEVS: // Mixer channels supporting stereo
1298 return put_user(SOUND_MASK_PCM | SOUND_MASK_LINE |
1299 SOUND_MASK_VOLUME | SOUND_MASK_RECLEV,
1300 (int *) arg);
1301
1302 case SOUND_MIXER_CAPS:
1303 return put_user(SOUND_CAP_EXCL_INPUT, (int *) arg);
1304
1305 default:
1306 i = _IOC_NR(cmd);
1307 if (i >= SOUND_MIXER_NRDEVICES
1308 || !(vidx = mixtable1[i]))
1309 return -EINVAL;
1310 return put_user(s->mix.vol[vidx - 1], (int *) arg);
1311 }
1312 }
1313 // If ioctl doesn't have both the SIOC_READ and
1314 // the SIOC_WRITE bit set, return invalid.
1315 if (_SIOC_DIR(cmd) != (_SIOC_READ | _SIOC_WRITE))
1316 return -EINVAL;
1317
1318 // Increment the count of volume writes.
1319 s->mix.modcnt++;
1320
1321 // Isolate the command; it must be a write.
1322 switch (_IOC_NR(cmd)) {
1323
1324 case SOUND_MIXER_RECSRC: // Arg contains a bit for each recording source
1325 if (get_user(val, (int *) arg))
1326 return -EFAULT;
1327 i = hweight32(val); // i = # bits on in val.
1328 if (i != 1) // One & only 1 bit must be on.
1329 return 0;
1330 for (i = 0; i < sizeof(mixer_src) / sizeof(int); i++) {
1331 if (val == mixer_src[i]) {
1332 temp1 = (i << 8) | i;
1333 cs4297a_write_ac97(s,
1334 AC97_RECORD_SELECT,
1335 temp1);
1336 return 0;
1337 }
1338 }
1339 return 0;
1340
1341 case SOUND_MIXER_VOLUME:
1342 if (get_user(val, (int *) arg))
1343 return -EFAULT;
1344 l = val & 0xff;
1345 if (l > 100)
1346 l = 100; // Max soundcard.h vol is 100.
1347 if (l < 6) {
1348 rl = 63;
1349 l = 0;
1350 } else
1351 rl = attentbl[(10 * l) / 100]; // Convert 0-100 vol to 63-0 atten.
1352
1353 r = (val >> 8) & 0xff;
1354 if (r > 100)
1355 r = 100; // Max right volume is 100, too
1356 if (r < 6) {
1357 rr = 63;
1358 r = 0;
1359 } else
1360 rr = attentbl[(10 * r) / 100]; // Convert volume to attenuation.
1361
1362 if ((rl > 60) && (rr > 60)) // If both l & r are 'low',
1363 temp1 = 0x8000; // turn on the mute bit.
1364 else
1365 temp1 = 0;
1366
1367 temp1 |= (rl << 8) | rr;
1368
1369 cs4297a_write_ac97(s, AC97_MASTER_VOL_STEREO, temp1);
1370 cs4297a_write_ac97(s, AC97_PHONE_VOL, temp1);
1371
1372#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1373 s->mix.vol[8] = ((unsigned int) r << 8) | l;
1374#else
1375 s->mix.vol[8] = val;
1376#endif
1377 return put_user(s->mix.vol[8], (int *) arg);
1378
1379 case SOUND_MIXER_SPEAKER:
1380 if (get_user(val, (int *) arg))
1381 return -EFAULT;
1382 l = val & 0xff;
1383 if (l > 100)
1384 l = 100;
1385 if (l < 3) {
1386 rl = 0;
1387 l = 0;
1388 } else {
1389 rl = (l * 2 - 5) / 13; // Convert 0-100 range to 0-15.
1390 l = (rl * 13 + 5) / 2;
1391 }
1392
1393 if (rl < 3) {
1394 temp1 = 0x8000;
1395 rl = 0;
1396 } else
1397 temp1 = 0;
1398 rl = 15 - rl; // Convert volume to attenuation.
1399 temp1 |= rl << 1;
1400 cs4297a_write_ac97(s, AC97_PCBEEP_VOL, temp1);
1401
1402#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1403 s->mix.vol[6] = l << 8;
1404#else
1405 s->mix.vol[6] = val;
1406#endif
1407 return put_user(s->mix.vol[6], (int *) arg);
1408
1409 case SOUND_MIXER_RECLEV:
1410 if (get_user(val, (int *) arg))
1411 return -EFAULT;
1412 l = val & 0xff;
1413 if (l > 100)
1414 l = 100;
1415 r = (val >> 8) & 0xff;
1416 if (r > 100)
1417 r = 100;
1418 rl = (l * 2 - 5) / 13; // Convert 0-100 scale to 0-15.
1419 rr = (r * 2 - 5) / 13;
1420 if (rl < 3 && rr < 3)
1421 temp1 = 0x8000;
1422 else
1423 temp1 = 0;
1424
1425 temp1 = temp1 | (rl << 8) | rr;
1426 cs4297a_write_ac97(s, AC97_RECORD_GAIN, temp1);
1427
1428#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1429 s->mix.vol[7] = ((unsigned int) r << 8) | l;
1430#else
1431 s->mix.vol[7] = val;
1432#endif
1433 return put_user(s->mix.vol[7], (int *) arg);
1434
1435 case SOUND_MIXER_MIC:
1436 if (get_user(val, (int *) arg))
1437 return -EFAULT;
1438 l = val & 0xff;
1439 if (l > 100)
1440 l = 100;
1441 if (l < 1) {
1442 l = 0;
1443 rl = 0;
1444 } else {
1445 rl = ((unsigned) l * 5 - 4) / 16; // Convert 0-100 range to 0-31.
1446 l = (rl * 16 + 4) / 5;
1447 }
1448 cs4297a_read_ac97(s, AC97_MIC_VOL, &temp1);
1449 temp1 &= 0x40; // Isolate 20db gain bit.
1450 if (rl < 3) {
1451 temp1 |= 0x8000;
1452 rl = 0;
1453 }
1454 rl = 31 - rl; // Convert volume to attenuation.
1455 temp1 |= rl;
1456 cs4297a_write_ac97(s, AC97_MIC_VOL, temp1);
1457
1458#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1459 s->mix.vol[5] = val << 8;
1460#else
1461 s->mix.vol[5] = val;
1462#endif
1463 return put_user(s->mix.vol[5], (int *) arg);
1464
1465
1466 case SOUND_MIXER_SYNTH:
1467 if (get_user(val, (int *) arg))
1468 return -EFAULT;
1469 l = val & 0xff;
1470 if (l > 100)
1471 l = 100;
1472 if (get_user(val, (int *) arg))
1473 return -EFAULT;
1474 r = (val >> 8) & 0xff;
1475 if (r > 100)
1476 r = 100;
1477 rl = (l * 2 - 11) / 3; // Convert 0-100 range to 0-63.
1478 rr = (r * 2 - 11) / 3;
1479 if (rl < 3) // If l is low, turn on
1480 temp1 = 0x0080; // the mute bit.
1481 else
1482 temp1 = 0;
1483
1484 rl = 63 - rl; // Convert vol to attenuation.
1485// writel(temp1 | rl, s->pBA0 + FMLVC);
1486 if (rr < 3) // If rr is low, turn on
1487 temp1 = 0x0080; // the mute bit.
1488 else
1489 temp1 = 0;
1490 rr = 63 - rr; // Convert vol to attenuation.
1491// writel(temp1 | rr, s->pBA0 + FMRVC);
1492
1493#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1494 s->mix.vol[4] = (r << 8) | l;
1495#else
1496 s->mix.vol[4] = val;
1497#endif
1498 return put_user(s->mix.vol[4], (int *) arg);
1499
1500
1501 default:
1502 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
1503 "cs4297a: mixer_ioctl(): default\n"));
1504
1505 i = _IOC_NR(cmd);
1506 if (i >= SOUND_MIXER_NRDEVICES || !(vidx = mixtable1[i]))
1507 return -EINVAL;
1508 if (get_user(val, (int *) arg))
1509 return -EFAULT;
1510 l = val & 0xff;
1511 if (l > 100)
1512 l = 100;
1513 if (l < 1) {
1514 l = 0;
1515 rl = 31;
1516 } else
1517 rl = (attentbl[(l * 10) / 100]) >> 1;
1518
1519 r = (val >> 8) & 0xff;
1520 if (r > 100)
1521 r = 100;
1522 if (r < 1) {
1523 r = 0;
1524 rr = 31;
1525 } else
1526 rr = (attentbl[(r * 10) / 100]) >> 1;
1527 if ((rl > 30) && (rr > 30))
1528 temp1 = 0x8000;
1529 else
1530 temp1 = 0;
1531 temp1 = temp1 | (rl << 8) | rr;
1532 cs4297a_write_ac97(s, mixreg[vidx - 1], temp1);
1533
1534#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
1535 s->mix.vol[vidx - 1] = ((unsigned int) r << 8) | l;
1536#else
1537 s->mix.vol[vidx - 1] = val;
1538#endif
1539 return put_user(s->mix.vol[vidx - 1], (int *) arg);
1540 }
1541}
1542
1543
1544// ---------------------------------------------------------------------
1545
1546static int cs4297a_open_mixdev(struct inode *inode, struct file *file)
1547{
1548 int minor = iminor(inode);
1549 struct cs4297a_state *s=NULL;
1550 struct list_head *entry;
1551
1552 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4,
1553 printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()+\n"));
1554
1555 mutex_lock(&swarm_cs4297a_mutex);
1556 list_for_each(entry, &cs4297a_devs)
1557 {
1558 s = list_entry(entry, struct cs4297a_state, list);
1559 if(s->dev_mixer == minor)
1560 break;
1561 }
1562 if (!s)
1563 {
1564 CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2,
1565 printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()- -ENODEV\n"));
1566
1567 mutex_unlock(&swarm_cs4297a_mutex);
1568 return -ENODEV;
1569 }
1570 VALIDATE_STATE(s);
1571 file->private_data = s;
1572
1573 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 4,
1574 printk(KERN_INFO "cs4297a: cs4297a_open_mixdev()- 0\n"));
1575 mutex_unlock(&swarm_cs4297a_mutex);
1576
1577 return nonseekable_open(inode, file);
1578}
1579
1580
1581static int cs4297a_release_mixdev(struct inode *inode, struct file *file)
1582{
1583 struct cs4297a_state *s =
1584 (struct cs4297a_state *) file->private_data;
1585
1586 VALIDATE_STATE(s);
1587 return 0;
1588}
1589
1590
1591static int cs4297a_ioctl_mixdev(struct file *file,
1592 unsigned int cmd, unsigned long arg)
1593{
1594 int ret;
1595 mutex_lock(&swarm_cs4297a_mutex);
1596 ret = mixer_ioctl((struct cs4297a_state *) file->private_data, cmd,
1597 arg);
1598 mutex_unlock(&swarm_cs4297a_mutex);
1599 return ret;
1600}
1601
1602
1603// ******************************************************************************************
1604// Mixer file operations struct.
1605// ******************************************************************************************
1606static const struct file_operations cs4297a_mixer_fops = {
1607 .owner = THIS_MODULE,
1608 .llseek = no_llseek,
1609 .unlocked_ioctl = cs4297a_ioctl_mixdev,
1610 .open = cs4297a_open_mixdev,
1611 .release = cs4297a_release_mixdev,
1612};
1613
1614// ---------------------------------------------------------------------
1615
1616
1617static int drain_adc(struct cs4297a_state *s, int nonblock)
1618{
1619 /* This routine serves no purpose currently - any samples
1620 sitting in the receive queue will just be processed by the
1621 background consumer. This would be different if DMA
1622 actually stopped when there were no clients. */
1623 return 0;
1624}
1625
1626static int drain_dac(struct cs4297a_state *s, int nonblock)
1627{
1628 DECLARE_WAITQUEUE(wait, current);
1629 unsigned long flags;
1630 unsigned hwptr;
1631 unsigned tmo;
1632 int count;
1633
1634 if (s->dma_dac.mapped)
1635 return 0;
1636 if (nonblock)
1637 return -EBUSY;
1638 add_wait_queue(&s->dma_dac.wait, &wait);
1639 while ((count = __raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_TX))) ||
1640 (s->dma_dac.count > 0)) {
1641 if (!signal_pending(current)) {
1642 set_current_state(TASK_INTERRUPTIBLE);
1643 /* XXXKW is this calculation working? */
1644 tmo = ((count * FRAME_TX_US) * HZ) / 1000000;
1645 schedule_timeout(tmo + 1);
1646 } else {
1647 /* XXXKW do I care if there is a signal pending? */
1648 }
1649 }
1650 spin_lock_irqsave(&s->lock, flags);
1651 /* Reset the bookkeeping */
1652 hwptr = (int)(((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_TX)) & M_DMA_CURDSCR_ADDR) -
1653 s->dma_dac.descrtab_phys) / sizeof(serdma_descr_t));
1654 s->dma_dac.hwptr = s->dma_dac.swptr = hwptr;
1655 spin_unlock_irqrestore(&s->lock, flags);
1656 remove_wait_queue(&s->dma_dac.wait, &wait);
1657 __set_current_state(TASK_RUNNING);
1658 return 0;
1659}
1660
1661
1662// ---------------------------------------------------------------------
1663
1664static ssize_t cs4297a_read(struct file *file, char *buffer, size_t count,
1665 loff_t * ppos)
1666{
1667 struct cs4297a_state *s =
1668 (struct cs4297a_state *) file->private_data;
1669 ssize_t ret;
1670 unsigned long flags;
1671 int cnt, count_fr, cnt_by;
1672 unsigned copied = 0;
1673
1674 CS_DBGOUT(CS_FUNCTION | CS_WAVE_READ, 2,
1675 printk(KERN_INFO "cs4297a: cs4297a_read()+ %d \n", count));
1676
1677 VALIDATE_STATE(s);
1678 if (s->dma_adc.mapped)
1679 return -ENXIO;
1680 if (!s->dma_adc.ready && (ret = prog_dmabuf_adc(s)))
1681 return ret;
1682 if (!access_ok(VERIFY_WRITE, buffer, count))
1683 return -EFAULT;
1684 ret = 0;
1685//
1686// "count" is the amount of bytes to read (from app), is decremented each loop
1687// by the amount of bytes that have been returned to the user buffer.
1688// "cnt" is the running total of each read from the buffer (changes each loop)
1689// "buffer" points to the app's buffer
1690// "ret" keeps a running total of the amount of bytes that have been copied
1691// to the user buffer.
1692// "copied" is the total bytes copied into the user buffer for each loop.
1693//
1694 while (count > 0) {
1695 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO
1696 "_read() count>0 count=%d .count=%d .swptr=%d .hwptr=%d \n",
1697 count, s->dma_adc.count,
1698 s->dma_adc.swptr, s->dma_adc.hwptr));
1699 spin_lock_irqsave(&s->lock, flags);
1700
1701 /* cnt will be the number of available samples (16-bit
1702 stereo); it starts out as the maxmimum consequetive
1703 samples */
1704 cnt = (s->dma_adc.sb_end - s->dma_adc.sb_swptr) / 2;
1705 count_fr = s->dma_adc.count / FRAME_SAMPLE_BYTES;
1706
1707 // dma_adc.count is the current total bytes that have not been read.
1708 // if the amount of unread bytes from the current sw pointer to the
1709 // end of the buffer is greater than the current total bytes that
1710 // have not been read, then set the "cnt" (unread bytes) to the
1711 // amount of unread bytes.
1712
1713 if (count_fr < cnt)
1714 cnt = count_fr;
1715 cnt_by = cnt * FRAME_SAMPLE_BYTES;
1716 spin_unlock_irqrestore(&s->lock, flags);
1717 //
1718 // if we are converting from 8/16 then we need to copy
1719 // twice the number of 16 bit bytes then 8 bit bytes.
1720 //
1721 if (s->conversion) {
1722 if (cnt_by > (count * 2)) {
1723 cnt = (count * 2) / FRAME_SAMPLE_BYTES;
1724 cnt_by = count * 2;
1725 }
1726 } else {
1727 if (cnt_by > count) {
1728 cnt = count / FRAME_SAMPLE_BYTES;
1729 cnt_by = count;
1730 }
1731 }
1732 //
1733 // "cnt" NOW is the smaller of the amount that will be read,
1734 // and the amount that is requested in this read (or partial).
1735 // if there are no bytes in the buffer to read, then start the
1736 // ADC and wait for the interrupt handler to wake us up.
1737 //
1738 if (cnt <= 0) {
1739
1740 // start up the dma engine and then continue back to the top of
1741 // the loop when wake up occurs.
1742 start_adc(s);
1743 if (file->f_flags & O_NONBLOCK)
1744 return ret ? ret : -EAGAIN;
1745 oss_broken_sleep_on(&s->dma_adc.wait, MAX_SCHEDULE_TIMEOUT);
1746 if (signal_pending(current))
1747 return ret ? ret : -ERESTARTSYS;
1748 continue;
1749 }
1750 // there are bytes in the buffer to read.
1751 // copy from the hw buffer over to the user buffer.
1752 // user buffer is designated by "buffer"
1753 // virtual address to copy from is dma_buf+swptr
1754 // the "cnt" is the number of bytes to read.
1755
1756 CS_DBGOUT(CS_WAVE_READ, 2, printk(KERN_INFO
1757 "_read() copy_to cnt=%d count=%d ", cnt_by, count));
1758 CS_DBGOUT(CS_WAVE_READ, 8, printk(KERN_INFO
1759 " .sbufsz=%d .count=%d buffer=0x%.8x ret=%d\n",
1760 s->dma_adc.sbufsz, s->dma_adc.count,
1761 (unsigned) buffer, ret));
1762
1763 if (copy_to_user (buffer, ((void *)s->dma_adc.sb_swptr), cnt_by))
1764 return ret ? ret : -EFAULT;
1765 copied = cnt_by;
1766
1767 /* Return the descriptors */
1768 spin_lock_irqsave(&s->lock, flags);
1769 CS_DBGOUT(CS_FUNCTION, 2,
1770 printk(KERN_INFO "cs4297a: upd_rcv sw->hw %x/%x\n", s->dma_adc.swptr, s->dma_adc.hwptr));
1771 s->dma_adc.count -= cnt_by;
1772 s->dma_adc.sb_swptr += cnt * 2;
1773 if (s->dma_adc.sb_swptr == s->dma_adc.sb_end)
1774 s->dma_adc.sb_swptr = s->dma_adc.sample_buf;
1775 spin_unlock_irqrestore(&s->lock, flags);
1776 count -= copied;
1777 buffer += copied;
1778 ret += copied;
1779 start_adc(s);
1780 }
1781 CS_DBGOUT(CS_FUNCTION | CS_WAVE_READ, 2,
1782 printk(KERN_INFO "cs4297a: cs4297a_read()- %d\n", ret));
1783 return ret;
1784}
1785
1786
1787static ssize_t cs4297a_write(struct file *file, const char *buffer,
1788 size_t count, loff_t * ppos)
1789{
1790 struct cs4297a_state *s =
1791 (struct cs4297a_state *) file->private_data;
1792 ssize_t ret;
1793 unsigned long flags;
1794 unsigned swptr, hwptr;
1795 int cnt;
1796
1797 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE, 2,
1798 printk(KERN_INFO "cs4297a: cs4297a_write()+ count=%d\n",
1799 count));
1800 VALIDATE_STATE(s);
1801
1802 if (s->dma_dac.mapped)
1803 return -ENXIO;
1804 if (!s->dma_dac.ready && (ret = prog_dmabuf_dac(s)))
1805 return ret;
1806 if (!access_ok(VERIFY_READ, buffer, count))
1807 return -EFAULT;
1808 ret = 0;
1809 while (count > 0) {
1810 serdma_t *d = &s->dma_dac;
1811 int copy_cnt;
1812 u32 *s_tmpl;
1813 u32 *t_tmpl;
1814 u32 left, right;
1815 int swap = (s->prop_dac.fmt == AFMT_S16_LE) || (s->prop_dac.fmt == AFMT_U16_LE);
1816
1817 /* XXXXXX this is broken for BLOAT_FACTOR */
1818 spin_lock_irqsave(&s->lock, flags);
1819 if (d->count < 0) {
1820 d->count = 0;
1821 d->swptr = d->hwptr;
1822 }
1823 if (d->underrun) {
1824 d->underrun = 0;
1825 hwptr = (unsigned) (((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_TX)) & M_DMA_CURDSCR_ADDR) -
1826 d->descrtab_phys) / sizeof(serdma_descr_t));
1827 d->swptr = d->hwptr = hwptr;
1828 }
1829 swptr = d->swptr;
1830 cnt = d->sbufsz - (swptr * FRAME_SAMPLE_BYTES);
1831 /* Will this write fill up the buffer? */
1832 if (d->count + cnt > d->sbufsz)
1833 cnt = d->sbufsz - d->count;
1834 spin_unlock_irqrestore(&s->lock, flags);
1835 if (cnt > count)
1836 cnt = count;
1837 if (cnt <= 0) {
1838 start_dac(s);
1839 if (file->f_flags & O_NONBLOCK)
1840 return ret ? ret : -EAGAIN;
1841 oss_broken_sleep_on(&d->wait, MAX_SCHEDULE_TIMEOUT);
1842 if (signal_pending(current))
1843 return ret ? ret : -ERESTARTSYS;
1844 continue;
1845 }
1846 if (copy_from_user(d->sample_buf, buffer, cnt))
1847 return ret ? ret : -EFAULT;
1848
1849 copy_cnt = cnt;
1850 s_tmpl = (u32 *)d->sample_buf;
1851 t_tmpl = (u32 *)(d->dma_buf + (swptr * 4));
1852
1853 /* XXXKW assuming 16-bit stereo! */
1854 do {
1855 u32 tmp;
1856
1857 t_tmpl[0] = cpu_to_be32(0x98000000);
1858
1859 tmp = be32_to_cpu(s_tmpl[0]);
1860 left = tmp & 0xffff;
1861 right = tmp >> 16;
1862 if (swap) {
1863 left = swab16(left);
1864 right = swab16(right);
1865 }
1866 t_tmpl[1] = cpu_to_be32(left >> 8);
1867 t_tmpl[2] = cpu_to_be32(((left & 0xff) << 24) |
1868 (right << 4));
1869
1870 s_tmpl++;
1871 t_tmpl += 8;
1872 copy_cnt -= 4;
1873 } while (copy_cnt);
1874
1875 /* Mux in any pending read/write accesses */
1876 if (s->reg_request) {
1877 *(u64 *)(d->dma_buf + (swptr * 4)) |=
1878 cpu_to_be64(s->reg_request);
1879 s->reg_request = 0;
1880 wake_up(&s->dma_dac.reg_wait);
1881 }
1882
1883 CS_DBGOUT(CS_WAVE_WRITE, 4,
1884 printk(KERN_INFO
1885 "cs4297a: copy in %d to swptr %x\n", cnt, swptr));
1886
1887 swptr = (swptr + (cnt/FRAME_SAMPLE_BYTES)) % d->ringsz;
1888 __raw_writeq(cnt/FRAME_SAMPLE_BYTES, SS_CSR(R_SER_DMA_DSCR_COUNT_TX));
1889 spin_lock_irqsave(&s->lock, flags);
1890 d->swptr = swptr;
1891 d->count += cnt;
1892 d->endcleared = 0;
1893 spin_unlock_irqrestore(&s->lock, flags);
1894 count -= cnt;
1895 buffer += cnt;
1896 ret += cnt;
1897 start_dac(s);
1898 }
1899 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE, 2,
1900 printk(KERN_INFO "cs4297a: cs4297a_write()- %d\n", ret));
1901 return ret;
1902}
1903
1904
1905static unsigned int cs4297a_poll(struct file *file,
1906 struct poll_table_struct *wait)
1907{
1908 struct cs4297a_state *s =
1909 (struct cs4297a_state *) file->private_data;
1910 unsigned long flags;
1911 unsigned int mask = 0;
1912
1913 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
1914 printk(KERN_INFO "cs4297a: cs4297a_poll()+\n"));
1915 VALIDATE_STATE(s);
1916 if (file->f_mode & FMODE_WRITE) {
1917 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
1918 printk(KERN_INFO
1919 "cs4297a: cs4297a_poll() wait on FMODE_WRITE\n"));
1920 if(!s->dma_dac.ready && prog_dmabuf_dac(s))
1921 return 0;
1922 poll_wait(file, &s->dma_dac.wait, wait);
1923 }
1924 if (file->f_mode & FMODE_READ) {
1925 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
1926 printk(KERN_INFO
1927 "cs4297a: cs4297a_poll() wait on FMODE_READ\n"));
1928 if(!s->dma_dac.ready && prog_dmabuf_adc(s))
1929 return 0;
1930 poll_wait(file, &s->dma_adc.wait, wait);
1931 }
1932 spin_lock_irqsave(&s->lock, flags);
1933 cs4297a_update_ptr(s,CS_FALSE);
1934 if (file->f_mode & FMODE_WRITE) {
1935 if (s->dma_dac.mapped) {
1936 if (s->dma_dac.count >=
1937 (signed) s->dma_dac.fragsize) {
1938 if (s->dma_dac.wakeup)
1939 mask |= POLLOUT | POLLWRNORM;
1940 else
1941 mask = 0;
1942 s->dma_dac.wakeup = 0;
1943 }
1944 } else {
1945 if ((signed) (s->dma_dac.sbufsz/2) >= s->dma_dac.count)
1946 mask |= POLLOUT | POLLWRNORM;
1947 }
1948 } else if (file->f_mode & FMODE_READ) {
1949 if (s->dma_adc.mapped) {
1950 if (s->dma_adc.count >= (signed) s->dma_adc.fragsize)
1951 mask |= POLLIN | POLLRDNORM;
1952 } else {
1953 if (s->dma_adc.count > 0)
1954 mask |= POLLIN | POLLRDNORM;
1955 }
1956 }
1957 spin_unlock_irqrestore(&s->lock, flags);
1958 CS_DBGOUT(CS_FUNCTION | CS_WAVE_WRITE | CS_WAVE_READ, 4,
1959 printk(KERN_INFO "cs4297a: cs4297a_poll()- 0x%.8x\n",
1960 mask));
1961 return mask;
1962}
1963
1964
1965static int cs4297a_mmap(struct file *file, struct vm_area_struct *vma)
1966{
1967 /* XXXKW currently no mmap support */
1968 return -EINVAL;
1969 return 0;
1970}
1971
1972
1973static int cs4297a_ioctl(struct file *file,
1974 unsigned int cmd, unsigned long arg)
1975{
1976 struct cs4297a_state *s =
1977 (struct cs4297a_state *) file->private_data;
1978 unsigned long flags;
1979 audio_buf_info abinfo;
1980 count_info cinfo;
1981 int val, mapped, ret;
1982
1983 CS_DBGOUT(CS_FUNCTION|CS_IOCTL, 4, printk(KERN_INFO
1984 "cs4297a: cs4297a_ioctl(): file=0x%.8x cmd=0x%.8x\n",
1985 (unsigned) file, cmd));
1986#if CSDEBUG
1987 cs_printioctl(cmd);
1988#endif
1989 VALIDATE_STATE(s);
1990 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
1991 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
1992 switch (cmd) {
1993 case OSS_GETVERSION:
1994 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
1995 "cs4297a: cs4297a_ioctl(): SOUND_VERSION=0x%.8x\n",
1996 SOUND_VERSION));
1997 return put_user(SOUND_VERSION, (int *) arg);
1998
1999 case SNDCTL_DSP_SYNC:
2000 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
2001 "cs4297a: cs4297a_ioctl(): DSP_SYNC\n"));
2002 if (file->f_mode & FMODE_WRITE)
2003 return drain_dac(s,
2004 0 /*file->f_flags & O_NONBLOCK */
2005 );
2006 return 0;
2007
2008 case SNDCTL_DSP_SETDUPLEX:
2009 return 0;
2010
2011 case SNDCTL_DSP_GETCAPS:
2012 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME |
2013 DSP_CAP_TRIGGER | DSP_CAP_MMAP,
2014 (int *) arg);
2015
2016 case SNDCTL_DSP_RESET:
2017 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
2018 "cs4297a: cs4297a_ioctl(): DSP_RESET\n"));
2019 if (file->f_mode & FMODE_WRITE) {
2020 stop_dac(s);
2021 synchronize_irq(s->irq);
2022 s->dma_dac.count = s->dma_dac.total_bytes =
2023 s->dma_dac.blocks = s->dma_dac.wakeup = 0;
2024 s->dma_dac.swptr = s->dma_dac.hwptr =
2025 (int)(((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_TX)) & M_DMA_CURDSCR_ADDR) -
2026 s->dma_dac.descrtab_phys) / sizeof(serdma_descr_t));
2027 }
2028 if (file->f_mode & FMODE_READ) {
2029 stop_adc(s);
2030 synchronize_irq(s->irq);
2031 s->dma_adc.count = s->dma_adc.total_bytes =
2032 s->dma_adc.blocks = s->dma_dac.wakeup = 0;
2033 s->dma_adc.swptr = s->dma_adc.hwptr =
2034 (int)(((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_RX)) & M_DMA_CURDSCR_ADDR) -
2035 s->dma_adc.descrtab_phys) / sizeof(serdma_descr_t));
2036 }
2037 return 0;
2038
2039 case SNDCTL_DSP_SPEED:
2040 if (get_user(val, (int *) arg))
2041 return -EFAULT;
2042 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2043 "cs4297a: cs4297a_ioctl(): DSP_SPEED val=%d -> 48000\n", val));
2044 val = 48000;
2045 return put_user(val, (int *) arg);
2046
2047 case SNDCTL_DSP_STEREO:
2048 if (get_user(val, (int *) arg))
2049 return -EFAULT;
2050 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2051 "cs4297a: cs4297a_ioctl(): DSP_STEREO val=%d\n", val));
2052 if (file->f_mode & FMODE_READ) {
2053 stop_adc(s);
2054 s->dma_adc.ready = 0;
2055 s->prop_adc.channels = val ? 2 : 1;
2056 }
2057 if (file->f_mode & FMODE_WRITE) {
2058 stop_dac(s);
2059 s->dma_dac.ready = 0;
2060 s->prop_dac.channels = val ? 2 : 1;
2061 }
2062 return 0;
2063
2064 case SNDCTL_DSP_CHANNELS:
2065 if (get_user(val, (int *) arg))
2066 return -EFAULT;
2067 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2068 "cs4297a: cs4297a_ioctl(): DSP_CHANNELS val=%d\n",
2069 val));
2070 if (val != 0) {
2071 if (file->f_mode & FMODE_READ) {
2072 stop_adc(s);
2073 s->dma_adc.ready = 0;
2074 if (val >= 2)
2075 s->prop_adc.channels = 2;
2076 else
2077 s->prop_adc.channels = 1;
2078 }
2079 if (file->f_mode & FMODE_WRITE) {
2080 stop_dac(s);
2081 s->dma_dac.ready = 0;
2082 if (val >= 2)
2083 s->prop_dac.channels = 2;
2084 else
2085 s->prop_dac.channels = 1;
2086 }
2087 }
2088
2089 if (file->f_mode & FMODE_WRITE)
2090 val = s->prop_dac.channels;
2091 else if (file->f_mode & FMODE_READ)
2092 val = s->prop_adc.channels;
2093
2094 return put_user(val, (int *) arg);
2095
2096 case SNDCTL_DSP_GETFMTS: // Returns a mask
2097 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2098 "cs4297a: cs4297a_ioctl(): DSP_GETFMT val=0x%.8x\n",
2099 AFMT_S16_LE | AFMT_U16_LE | AFMT_S8 |
2100 AFMT_U8));
2101 return put_user(AFMT_S16_LE | AFMT_U16_LE | AFMT_S8 |
2102 AFMT_U8, (int *) arg);
2103
2104 case SNDCTL_DSP_SETFMT:
2105 if (get_user(val, (int *) arg))
2106 return -EFAULT;
2107 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2108 "cs4297a: cs4297a_ioctl(): DSP_SETFMT val=0x%.8x\n",
2109 val));
2110 if (val != AFMT_QUERY) {
2111 if (file->f_mode & FMODE_READ) {
2112 stop_adc(s);
2113 s->dma_adc.ready = 0;
2114 if (val != AFMT_S16_LE
2115 && val != AFMT_U16_LE && val != AFMT_S8
2116 && val != AFMT_U8)
2117 val = AFMT_U8;
2118 s->prop_adc.fmt = val;
2119 s->prop_adc.fmt_original = s->prop_adc.fmt;
2120 }
2121 if (file->f_mode & FMODE_WRITE) {
2122 stop_dac(s);
2123 s->dma_dac.ready = 0;
2124 if (val != AFMT_S16_LE
2125 && val != AFMT_U16_LE && val != AFMT_S8
2126 && val != AFMT_U8)
2127 val = AFMT_U8;
2128 s->prop_dac.fmt = val;
2129 s->prop_dac.fmt_original = s->prop_dac.fmt;
2130 }
2131 } else {
2132 if (file->f_mode & FMODE_WRITE)
2133 val = s->prop_dac.fmt_original;
2134 else if (file->f_mode & FMODE_READ)
2135 val = s->prop_adc.fmt_original;
2136 }
2137 CS_DBGOUT(CS_IOCTL | CS_PARMS, 4, printk(KERN_INFO
2138 "cs4297a: cs4297a_ioctl(): DSP_SETFMT return val=0x%.8x\n",
2139 val));
2140 return put_user(val, (int *) arg);
2141
2142 case SNDCTL_DSP_POST:
2143 CS_DBGOUT(CS_IOCTL, 4, printk(KERN_INFO
2144 "cs4297a: cs4297a_ioctl(): DSP_POST\n"));
2145 return 0;
2146
2147 case SNDCTL_DSP_GETTRIGGER:
2148 val = 0;
2149 if (file->f_mode & s->ena & FMODE_READ)
2150 val |= PCM_ENABLE_INPUT;
2151 if (file->f_mode & s->ena & FMODE_WRITE)
2152 val |= PCM_ENABLE_OUTPUT;
2153 return put_user(val, (int *) arg);
2154
2155 case SNDCTL_DSP_SETTRIGGER:
2156 if (get_user(val, (int *) arg))
2157 return -EFAULT;
2158 if (file->f_mode & FMODE_READ) {
2159 if (val & PCM_ENABLE_INPUT) {
2160 if (!s->dma_adc.ready
2161 && (ret = prog_dmabuf_adc(s)))
2162 return ret;
2163 start_adc(s);
2164 } else
2165 stop_adc(s);
2166 }
2167 if (file->f_mode & FMODE_WRITE) {
2168 if (val & PCM_ENABLE_OUTPUT) {
2169 if (!s->dma_dac.ready
2170 && (ret = prog_dmabuf_dac(s)))
2171 return ret;
2172 start_dac(s);
2173 } else
2174 stop_dac(s);
2175 }
2176 return 0;
2177
2178 case SNDCTL_DSP_GETOSPACE:
2179 if (!(file->f_mode & FMODE_WRITE))
2180 return -EINVAL;
2181 if (!s->dma_dac.ready && (val = prog_dmabuf_dac(s)))
2182 return val;
2183 spin_lock_irqsave(&s->lock, flags);
2184 cs4297a_update_ptr(s,CS_FALSE);
2185 abinfo.fragsize = s->dma_dac.fragsize;
2186 if (s->dma_dac.mapped)
2187 abinfo.bytes = s->dma_dac.sbufsz;
2188 else
2189 abinfo.bytes =
2190 s->dma_dac.sbufsz - s->dma_dac.count;
2191 abinfo.fragstotal = s->dma_dac.numfrag;
2192 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
2193 CS_DBGOUT(CS_FUNCTION | CS_PARMS, 4, printk(KERN_INFO
2194 "cs4297a: cs4297a_ioctl(): GETOSPACE .fragsize=%d .bytes=%d .fragstotal=%d .fragments=%d\n",
2195 abinfo.fragsize,abinfo.bytes,abinfo.fragstotal,
2196 abinfo.fragments));
2197 spin_unlock_irqrestore(&s->lock, flags);
2198 return copy_to_user((void *) arg, &abinfo,
2199 sizeof(abinfo)) ? -EFAULT : 0;
2200
2201 case SNDCTL_DSP_GETISPACE:
2202 if (!(file->f_mode & FMODE_READ))
2203 return -EINVAL;
2204 if (!s->dma_adc.ready && (val = prog_dmabuf_adc(s)))
2205 return val;
2206 spin_lock_irqsave(&s->lock, flags);
2207 cs4297a_update_ptr(s,CS_FALSE);
2208 if (s->conversion) {
2209 abinfo.fragsize = s->dma_adc.fragsize / 2;
2210 abinfo.bytes = s->dma_adc.count / 2;
2211 abinfo.fragstotal = s->dma_adc.numfrag;
2212 abinfo.fragments =
2213 abinfo.bytes >> (s->dma_adc.fragshift - 1);
2214 } else {
2215 abinfo.fragsize = s->dma_adc.fragsize;
2216 abinfo.bytes = s->dma_adc.count;
2217 abinfo.fragstotal = s->dma_adc.numfrag;
2218 abinfo.fragments =
2219 abinfo.bytes >> s->dma_adc.fragshift;
2220 }
2221 spin_unlock_irqrestore(&s->lock, flags);
2222 return copy_to_user((void *) arg, &abinfo,
2223 sizeof(abinfo)) ? -EFAULT : 0;
2224
2225 case SNDCTL_DSP_NONBLOCK:
2226 spin_lock(&file->f_lock);
2227 file->f_flags |= O_NONBLOCK;
2228 spin_unlock(&file->f_lock);
2229 return 0;
2230
2231 case SNDCTL_DSP_GETODELAY:
2232 if (!(file->f_mode & FMODE_WRITE))
2233 return -EINVAL;
2234 if(!s->dma_dac.ready && prog_dmabuf_dac(s))
2235 return 0;
2236 spin_lock_irqsave(&s->lock, flags);
2237 cs4297a_update_ptr(s,CS_FALSE);
2238 val = s->dma_dac.count;
2239 spin_unlock_irqrestore(&s->lock, flags);
2240 return put_user(val, (int *) arg);
2241
2242 case SNDCTL_DSP_GETIPTR:
2243 if (!(file->f_mode & FMODE_READ))
2244 return -EINVAL;
2245 if(!s->dma_adc.ready && prog_dmabuf_adc(s))
2246 return 0;
2247 spin_lock_irqsave(&s->lock, flags);
2248 cs4297a_update_ptr(s,CS_FALSE);
2249 cinfo.bytes = s->dma_adc.total_bytes;
2250 if (s->dma_adc.mapped) {
2251 cinfo.blocks =
2252 (cinfo.bytes >> s->dma_adc.fragshift) -
2253 s->dma_adc.blocks;
2254 s->dma_adc.blocks =
2255 cinfo.bytes >> s->dma_adc.fragshift;
2256 } else {
2257 if (s->conversion) {
2258 cinfo.blocks =
2259 s->dma_adc.count /
2260 2 >> (s->dma_adc.fragshift - 1);
2261 } else
2262 cinfo.blocks =
2263 s->dma_adc.count >> s->dma_adc.
2264 fragshift;
2265 }
2266 if (s->conversion)
2267 cinfo.ptr = s->dma_adc.hwptr / 2;
2268 else
2269 cinfo.ptr = s->dma_adc.hwptr;
2270 if (s->dma_adc.mapped)
2271 s->dma_adc.count &= s->dma_adc.fragsize - 1;
2272 spin_unlock_irqrestore(&s->lock, flags);
2273 return copy_to_user((void *) arg, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
2274
2275 case SNDCTL_DSP_GETOPTR:
2276 if (!(file->f_mode & FMODE_WRITE))
2277 return -EINVAL;
2278 if(!s->dma_dac.ready && prog_dmabuf_dac(s))
2279 return 0;
2280 spin_lock_irqsave(&s->lock, flags);
2281 cs4297a_update_ptr(s,CS_FALSE);
2282 cinfo.bytes = s->dma_dac.total_bytes;
2283 if (s->dma_dac.mapped) {
2284 cinfo.blocks =
2285 (cinfo.bytes >> s->dma_dac.fragshift) -
2286 s->dma_dac.blocks;
2287 s->dma_dac.blocks =
2288 cinfo.bytes >> s->dma_dac.fragshift;
2289 } else {
2290 cinfo.blocks =
2291 s->dma_dac.count >> s->dma_dac.fragshift;
2292 }
2293 cinfo.ptr = s->dma_dac.hwptr;
2294 if (s->dma_dac.mapped)
2295 s->dma_dac.count &= s->dma_dac.fragsize - 1;
2296 spin_unlock_irqrestore(&s->lock, flags);
2297 return copy_to_user((void *) arg, &cinfo, sizeof(cinfo)) ? -EFAULT : 0;
2298
2299 case SNDCTL_DSP_GETBLKSIZE:
2300 if (file->f_mode & FMODE_WRITE) {
2301 if ((val = prog_dmabuf_dac(s)))
2302 return val;
2303 return put_user(s->dma_dac.fragsize, (int *) arg);
2304 }
2305 if ((val = prog_dmabuf_adc(s)))
2306 return val;
2307 if (s->conversion)
2308 return put_user(s->dma_adc.fragsize / 2,
2309 (int *) arg);
2310 else
2311 return put_user(s->dma_adc.fragsize, (int *) arg);
2312
2313 case SNDCTL_DSP_SETFRAGMENT:
2314 if (get_user(val, (int *) arg))
2315 return -EFAULT;
2316 return 0; // Say OK, but do nothing.
2317
2318 case SNDCTL_DSP_SUBDIVIDE:
2319 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision)
2320 || (file->f_mode & FMODE_WRITE
2321 && s->dma_dac.subdivision)) return -EINVAL;
2322 if (get_user(val, (int *) arg))
2323 return -EFAULT;
2324 if (val != 1 && val != 2 && val != 4)
2325 return -EINVAL;
2326 if (file->f_mode & FMODE_READ)
2327 s->dma_adc.subdivision = val;
2328 else if (file->f_mode & FMODE_WRITE)
2329 s->dma_dac.subdivision = val;
2330 return 0;
2331
2332 case SOUND_PCM_READ_RATE:
2333 if (file->f_mode & FMODE_READ)
2334 return put_user(s->prop_adc.rate, (int *) arg);
2335 else if (file->f_mode & FMODE_WRITE)
2336 return put_user(s->prop_dac.rate, (int *) arg);
2337
2338 case SOUND_PCM_READ_CHANNELS:
2339 if (file->f_mode & FMODE_READ)
2340 return put_user(s->prop_adc.channels, (int *) arg);
2341 else if (file->f_mode & FMODE_WRITE)
2342 return put_user(s->prop_dac.channels, (int *) arg);
2343
2344 case SOUND_PCM_READ_BITS:
2345 if (file->f_mode & FMODE_READ)
2346 return
2347 put_user(
2348 (s->prop_adc.
2349 fmt & (AFMT_S8 | AFMT_U8)) ? 8 : 16,
2350 (int *) arg);
2351 else if (file->f_mode & FMODE_WRITE)
2352 return
2353 put_user(
2354 (s->prop_dac.
2355 fmt & (AFMT_S8 | AFMT_U8)) ? 8 : 16,
2356 (int *) arg);
2357
2358 case SOUND_PCM_WRITE_FILTER:
2359 case SNDCTL_DSP_SETSYNCRO:
2360 case SOUND_PCM_READ_FILTER:
2361 return -EINVAL;
2362 }
2363 return mixer_ioctl(s, cmd, arg);
2364}
2365
2366static long cs4297a_unlocked_ioctl(struct file *file, u_int cmd, u_long arg)
2367{
2368 int ret;
2369
2370 mutex_lock(&swarm_cs4297a_mutex);
2371 ret = cs4297a_ioctl(file, cmd, arg);
2372 mutex_unlock(&swarm_cs4297a_mutex);
2373
2374 return ret;
2375}
2376
2377static int cs4297a_release(struct inode *inode, struct file *file)
2378{
2379 struct cs4297a_state *s =
2380 (struct cs4297a_state *) file->private_data;
2381
2382 CS_DBGOUT(CS_FUNCTION | CS_RELEASE, 2, printk(KERN_INFO
2383 "cs4297a: cs4297a_release(): inode=0x%.8x file=0x%.8x f_mode=0x%x\n",
2384 (unsigned) inode, (unsigned) file, file->f_mode));
2385 VALIDATE_STATE(s);
2386
2387 if (file->f_mode & FMODE_WRITE) {
2388 drain_dac(s, file->f_flags & O_NONBLOCK);
2389 mutex_lock(&s->open_sem_dac);
2390 stop_dac(s);
2391 dealloc_dmabuf(s, &s->dma_dac);
2392 s->open_mode &= ~FMODE_WRITE;
2393 mutex_unlock(&s->open_sem_dac);
2394 wake_up(&s->open_wait_dac);
2395 }
2396 if (file->f_mode & FMODE_READ) {
2397 drain_adc(s, file->f_flags & O_NONBLOCK);
2398 mutex_lock(&s->open_sem_adc);
2399 stop_adc(s);
2400 dealloc_dmabuf(s, &s->dma_adc);
2401 s->open_mode &= ~FMODE_READ;
2402 mutex_unlock(&s->open_sem_adc);
2403 wake_up(&s->open_wait_adc);
2404 }
2405 return 0;
2406}
2407
2408static int cs4297a_locked_open(struct inode *inode, struct file *file)
2409{
2410 int minor = iminor(inode);
2411 struct cs4297a_state *s=NULL;
2412 struct list_head *entry;
2413
2414 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
2415 "cs4297a: cs4297a_open(): inode=0x%.8x file=0x%.8x f_mode=0x%x\n",
2416 (unsigned) inode, (unsigned) file, file->f_mode));
2417 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
2418 "cs4297a: status = %08x\n", (int)__raw_readq(SS_CSR(R_SER_STATUS_DEBUG))));
2419
2420 list_for_each(entry, &cs4297a_devs)
2421 {
2422 s = list_entry(entry, struct cs4297a_state, list);
2423
2424 if (!((s->dev_audio ^ minor) & ~0xf))
2425 break;
2426 }
2427 if (entry == &cs4297a_devs)
2428 return -ENODEV;
2429 if (!s) {
2430 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2, printk(KERN_INFO
2431 "cs4297a: cs4297a_open(): Error - unable to find audio state struct\n"));
2432 return -ENODEV;
2433 }
2434 VALIDATE_STATE(s);
2435 file->private_data = s;
2436
2437 // wait for device to become free
2438 if (!(file->f_mode & (FMODE_WRITE | FMODE_READ))) {
2439 CS_DBGOUT(CS_FUNCTION | CS_OPEN | CS_ERROR, 2, printk(KERN_INFO
2440 "cs4297a: cs4297a_open(): Error - must open READ and/or WRITE\n"));
2441 return -ENODEV;
2442 }
2443 if (file->f_mode & FMODE_WRITE) {
2444 if (__raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_TX)) != 0) {
2445 printk(KERN_ERR "cs4297a: TX pipe needs to drain\n");
2446 while (__raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_TX)))
2447 ;
2448 }
2449
2450 mutex_lock(&s->open_sem_dac);
2451 while (s->open_mode & FMODE_WRITE) {
2452 if (file->f_flags & O_NONBLOCK) {
2453 mutex_unlock(&s->open_sem_dac);
2454 return -EBUSY;
2455 }
2456 mutex_unlock(&s->open_sem_dac);
2457 oss_broken_sleep_on(&s->open_wait_dac, MAX_SCHEDULE_TIMEOUT);
2458
2459 if (signal_pending(current)) {
2460 printk("open - sig pending\n");
2461 return -ERESTARTSYS;
2462 }
2463 mutex_lock(&s->open_sem_dac);
2464 }
2465 }
2466 if (file->f_mode & FMODE_READ) {
2467 mutex_lock(&s->open_sem_adc);
2468 while (s->open_mode & FMODE_READ) {
2469 if (file->f_flags & O_NONBLOCK) {
2470 mutex_unlock(&s->open_sem_adc);
2471 return -EBUSY;
2472 }
2473 mutex_unlock(&s->open_sem_adc);
2474 oss_broken_sleep_on(&s->open_wait_adc, MAX_SCHEDULE_TIMEOUT);
2475
2476 if (signal_pending(current)) {
2477 printk("open - sig pending\n");
2478 return -ERESTARTSYS;
2479 }
2480 mutex_lock(&s->open_sem_adc);
2481 }
2482 }
2483 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
2484 if (file->f_mode & FMODE_READ) {
2485 s->prop_adc.fmt = AFMT_S16_BE;
2486 s->prop_adc.fmt_original = s->prop_adc.fmt;
2487 s->prop_adc.channels = 2;
2488 s->prop_adc.rate = 48000;
2489 s->conversion = 0;
2490 s->ena &= ~FMODE_READ;
2491 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags =
2492 s->dma_adc.subdivision = 0;
2493 mutex_unlock(&s->open_sem_adc);
2494
2495 if (prog_dmabuf_adc(s)) {
2496 CS_DBGOUT(CS_OPEN | CS_ERROR, 2, printk(KERN_ERR
2497 "cs4297a: adc Program dmabufs failed.\n"));
2498 cs4297a_release(inode, file);
2499 return -ENOMEM;
2500 }
2501 }
2502 if (file->f_mode & FMODE_WRITE) {
2503 s->prop_dac.fmt = AFMT_S16_BE;
2504 s->prop_dac.fmt_original = s->prop_dac.fmt;
2505 s->prop_dac.channels = 2;
2506 s->prop_dac.rate = 48000;
2507 s->conversion = 0;
2508 s->ena &= ~FMODE_WRITE;
2509 s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags =
2510 s->dma_dac.subdivision = 0;
2511 mutex_unlock(&s->open_sem_dac);
2512
2513 if (prog_dmabuf_dac(s)) {
2514 CS_DBGOUT(CS_OPEN | CS_ERROR, 2, printk(KERN_ERR
2515 "cs4297a: dac Program dmabufs failed.\n"));
2516 cs4297a_release(inode, file);
2517 return -ENOMEM;
2518 }
2519 }
2520 CS_DBGOUT(CS_FUNCTION | CS_OPEN, 2,
2521 printk(KERN_INFO "cs4297a: cs4297a_open()- 0\n"));
2522 return nonseekable_open(inode, file);
2523}
2524
2525static int cs4297a_open(struct inode *inode, struct file *file)
2526{
2527 int ret;
2528
2529 mutex_lock(&swarm_cs4297a_mutex);
2530 ret = cs4297a_open(inode, file);
2531 mutex_unlock(&swarm_cs4297a_mutex);
2532
2533 return ret;
2534}
2535
2536// ******************************************************************************************
2537// Wave (audio) file operations struct.
2538// ******************************************************************************************
2539static const struct file_operations cs4297a_audio_fops = {
2540 .owner = THIS_MODULE,
2541 .llseek = no_llseek,
2542 .read = cs4297a_read,
2543 .write = cs4297a_write,
2544 .poll = cs4297a_poll,
2545 .unlocked_ioctl = cs4297a_unlocked_ioctl,
2546 .mmap = cs4297a_mmap,
2547 .open = cs4297a_open,
2548 .release = cs4297a_release,
2549};
2550
2551static void cs4297a_interrupt(int irq, void *dev_id)
2552{
2553 struct cs4297a_state *s = (struct cs4297a_state *) dev_id;
2554 u32 status;
2555
2556 status = __raw_readq(SS_CSR(R_SER_STATUS_DEBUG));
2557
2558 CS_DBGOUT(CS_INTERRUPT, 6, printk(KERN_INFO
2559 "cs4297a: cs4297a_interrupt() HISR=0x%.8x\n", status));
2560
2561#if 0
2562 /* XXXKW what check *should* be done here? */
2563 if (!(status & (M_SYNCSER_RX_EOP_COUNT | M_SYNCSER_RX_OVERRUN | M_SYNCSER_RX_SYNC_ERR))) {
2564 status = __raw_readq(SS_CSR(R_SER_STATUS));
2565 printk(KERN_ERR "cs4297a: unexpected interrupt (status %08x)\n", status);
2566 return;
2567 }
2568#endif
2569
2570 if (status & M_SYNCSER_RX_SYNC_ERR) {
2571 status = __raw_readq(SS_CSR(R_SER_STATUS));
2572 printk(KERN_ERR "cs4297a: rx sync error (status %08x)\n", status);
2573 return;
2574 }
2575
2576 if (status & M_SYNCSER_RX_OVERRUN) {
2577 int newptr, i;
2578 s->stats.rx_ovrrn++;
2579 printk(KERN_ERR "cs4297a: receive FIFO overrun\n");
2580
2581 /* Fix things up: get the receive descriptor pool
2582 clean and give them back to the hardware */
2583 while (__raw_readq(SS_CSR(R_SER_DMA_DSCR_COUNT_RX)))
2584 ;
2585 newptr = (unsigned) (((__raw_readq(SS_CSR(R_SER_DMA_CUR_DSCR_ADDR_RX)) & M_DMA_CURDSCR_ADDR) -
2586 s->dma_adc.descrtab_phys) / sizeof(serdma_descr_t));
2587 for (i=0; i<DMA_DESCR; i++) {
2588 s->dma_adc.descrtab[i].descr_a &= ~M_DMA_SERRX_SOP;
2589 }
2590 s->dma_adc.swptr = s->dma_adc.hwptr = newptr;
2591 s->dma_adc.count = 0;
2592 s->dma_adc.sb_swptr = s->dma_adc.sb_hwptr = s->dma_adc.sample_buf;
2593 __raw_writeq(DMA_DESCR, SS_CSR(R_SER_DMA_DSCR_COUNT_RX));
2594 }
2595
2596 spin_lock(&s->lock);
2597 cs4297a_update_ptr(s,CS_TRUE);
2598 spin_unlock(&s->lock);
2599
2600 CS_DBGOUT(CS_INTERRUPT, 6, printk(KERN_INFO
2601 "cs4297a: cs4297a_interrupt()-\n"));
2602}
2603
2604#if 0
2605static struct initvol {
2606 int mixch;
2607 int vol;
2608} initvol[] __initdata = {
2609
2610 {SOUND_MIXER_WRITE_VOLUME, 0x4040},
2611 {SOUND_MIXER_WRITE_PCM, 0x4040},
2612 {SOUND_MIXER_WRITE_SYNTH, 0x4040},
2613 {SOUND_MIXER_WRITE_CD, 0x4040},
2614 {SOUND_MIXER_WRITE_LINE, 0x4040},
2615 {SOUND_MIXER_WRITE_LINE1, 0x4040},
2616 {SOUND_MIXER_WRITE_RECLEV, 0x0000},
2617 {SOUND_MIXER_WRITE_SPEAKER, 0x4040},
2618 {SOUND_MIXER_WRITE_MIC, 0x0000}
2619};
2620#endif
2621
2622static int __init cs4297a_init(void)
2623{
2624 struct cs4297a_state *s;
2625 u32 pwr, id;
2626 mm_segment_t fs;
2627 int rval;
2628 u64 cfg;
2629 int mdio_val;
2630
2631 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2, printk(KERN_INFO
2632 "cs4297a: cs4297a_init_module()+ \n"));
2633
2634 mdio_val = __raw_readq(KSEG1 + A_MAC_REGISTER(2, R_MAC_MDIO)) &
2635 (M_MAC_MDIO_DIR|M_MAC_MDIO_OUT);
2636
2637 /* Check syscfg for synchronous serial on port 1 */
2638 cfg = __raw_readq(KSEG1 + A_SCD_SYSTEM_CFG);
2639 if (!(cfg & M_SYS_SER1_ENABLE)) {
2640 __raw_writeq(cfg | M_SYS_SER1_ENABLE, KSEG1+A_SCD_SYSTEM_CFG);
2641 cfg = __raw_readq(KSEG1 + A_SCD_SYSTEM_CFG);
2642 if (!(cfg & M_SYS_SER1_ENABLE)) {
2643 printk(KERN_INFO "cs4297a: serial port 1 not configured for synchronous operation\n");
2644 return -1;
2645 }
2646
2647 printk(KERN_INFO "cs4297a: serial port 1 switching to synchronous operation\n");
2648
2649 /* Force the codec (on SWARM) to reset by clearing
2650 GENO, preserving MDIO (no effect on CSWARM) */
2651 __raw_writeq(mdio_val, KSEG1+A_MAC_REGISTER(2, R_MAC_MDIO));
2652 udelay(10);
2653 }
2654
2655 /* Now set GENO */
2656 __raw_writeq(mdio_val | M_MAC_GENC, KSEG1+A_MAC_REGISTER(2, R_MAC_MDIO));
2657 /* Give the codec some time to finish resetting (start the bit clock) */
2658 udelay(100);
2659
2660 if (!(s = kzalloc(sizeof(struct cs4297a_state), GFP_KERNEL))) {
2661 CS_DBGOUT(CS_ERROR, 1, printk(KERN_ERR
2662 "cs4297a: probe() no memory for state struct.\n"));
2663 return -1;
2664 }
2665 s->magic = CS4297a_MAGIC;
2666 init_waitqueue_head(&s->dma_adc.wait);
2667 init_waitqueue_head(&s->dma_dac.wait);
2668 init_waitqueue_head(&s->dma_adc.reg_wait);
2669 init_waitqueue_head(&s->dma_dac.reg_wait);
2670 init_waitqueue_head(&s->open_wait);
2671 init_waitqueue_head(&s->open_wait_adc);
2672 init_waitqueue_head(&s->open_wait_dac);
2673 mutex_init(&s->open_sem_adc);
2674 mutex_init(&s->open_sem_dac);
2675 spin_lock_init(&s->lock);
2676
2677 s->irq = K_INT_SER_1;
2678
2679 if (request_irq
2680 (s->irq, cs4297a_interrupt, 0, "Crystal CS4297a", s)) {
2681 CS_DBGOUT(CS_INIT | CS_ERROR, 1,
2682 printk(KERN_ERR "cs4297a: irq %u in use\n", s->irq));
2683 goto err_irq;
2684 }
2685 if ((s->dev_audio = register_sound_dsp(&cs4297a_audio_fops, -1)) <
2686 0) {
2687 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
2688 "cs4297a: probe() register_sound_dsp() failed.\n"));
2689 goto err_dev1;
2690 }
2691 if ((s->dev_mixer = register_sound_mixer(&cs4297a_mixer_fops, -1)) <
2692 0) {
2693 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
2694 "cs4297a: probe() register_sound_mixer() failed.\n"));
2695 goto err_dev2;
2696 }
2697
2698 if (ser_init(s) || dma_init(s)) {
2699 CS_DBGOUT(CS_INIT | CS_ERROR, 1, printk(KERN_ERR
2700 "cs4297a: ser_init failed.\n"));
2701 goto err_dev3;
2702 }
2703
2704 do {
2705 udelay(4000);
2706 rval = cs4297a_read_ac97(s, AC97_POWER_CONTROL, &pwr);
2707 } while (!rval && (pwr != 0xf));
2708
2709 if (!rval) {
2710 char *sb1250_duart_present;
2711
2712 fs = get_fs();
2713 set_fs(KERNEL_DS);
2714#if 0
2715 val = SOUND_MASK_LINE;
2716 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
2717 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
2718 val = initvol[i].vol;
2719 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
2720 }
2721// cs4297a_write_ac97(s, 0x18, 0x0808);
2722#else
2723 // cs4297a_write_ac97(s, 0x5e, 0x180);
2724 cs4297a_write_ac97(s, 0x02, 0x0808);
2725 cs4297a_write_ac97(s, 0x18, 0x0808);
2726#endif
2727 set_fs(fs);
2728
2729 list_add(&s->list, &cs4297a_devs);
2730
2731 cs4297a_read_ac97(s, AC97_VENDOR_ID1, &id);
2732
2733 sb1250_duart_present = symbol_get(sb1250_duart_present);
2734 if (sb1250_duart_present)
2735 sb1250_duart_present[1] = 0;
2736
2737 printk(KERN_INFO "cs4297a: initialized (vendor id = %x)\n", id);
2738
2739 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2,
2740 printk(KERN_INFO "cs4297a: cs4297a_init_module()-\n"));
2741
2742 return 0;
2743 }
2744
2745 err_dev3:
2746 unregister_sound_mixer(s->dev_mixer);
2747 err_dev2:
2748 unregister_sound_dsp(s->dev_audio);
2749 err_dev1:
2750 free_irq(s->irq, s);
2751 err_irq:
2752 kfree(s);
2753
2754 printk(KERN_INFO "cs4297a: initialization failed\n");
2755
2756 return -1;
2757}
2758
2759static void __exit cs4297a_cleanup(void)
2760{
2761 /*
2762 XXXKW
2763 disable_irq, free_irq
2764 drain DMA queue
2765 disable DMA
2766 disable TX/RX
2767 free memory
2768 */
2769 CS_DBGOUT(CS_INIT | CS_FUNCTION, 2,
2770 printk(KERN_INFO "cs4297a: cleanup_cs4297a() finished\n"));
2771}
2772
2773// ---------------------------------------------------------------------
2774
2775MODULE_AUTHOR("Kip Walker, Broadcom Corp.");
2776MODULE_DESCRIPTION("Cirrus Logic CS4297a Driver for Broadcom SWARM board");
2777
2778// ---------------------------------------------------------------------
2779
2780module_init(cs4297a_init);
2781module_exit(cs4297a_cleanup);
diff --git a/sound/oss/sys_timer.c b/sound/oss/sys_timer.c
deleted file mode 100644
index 8a4b5625dba6..000000000000
--- a/sound/oss/sys_timer.c
+++ /dev/null
@@ -1,280 +0,0 @@
1/*
2 * sound/oss/sys_timer.c
3 *
4 * The default timer for the Level 2 sequencer interface
5 * Uses the (1/HZ sec) timer of kernel.
6 */
7/*
8 * Copyright (C) by Hannu Savolainen 1993-1997
9 *
10 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
11 * Version 2 (June 1991). See the "COPYING" file distributed with this software
12 * for more info.
13 */
14/*
15 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
16 * Andrew Veliath : adapted tmr2ticks from level 1 sequencer (avoid overflow)
17 */
18#include <linux/spinlock.h>
19#include "sound_config.h"
20
21static volatile int opened, tmr_running;
22static volatile unsigned int tmr_offs, tmr_ctr;
23static volatile unsigned long ticks_offs;
24static volatile int curr_tempo, curr_timebase;
25static volatile unsigned long curr_ticks;
26static volatile unsigned long next_event_time;
27static unsigned long prev_event_time;
28
29static void poll_def_tmr(unsigned long dummy);
30static DEFINE_SPINLOCK(lock);
31static DEFINE_TIMER(def_tmr, poll_def_tmr);
32
33static unsigned long
34tmr2ticks(int tmr_value)
35{
36 /*
37 * Convert timer ticks to MIDI ticks
38 */
39
40 unsigned long tmp;
41 unsigned long scale;
42
43 /* tmr_value (ticks per sec) *
44 1000000 (usecs per sec) / HZ (ticks per sec) -=> usecs */
45 tmp = tmr_value * (1000000 / HZ);
46 scale = (60 * 1000000) / (curr_tempo * curr_timebase); /* usecs per MIDI tick */
47 return (tmp + scale / 2) / scale;
48}
49
50static void
51poll_def_tmr(unsigned long dummy)
52{
53 if (!opened)
54 return;
55 def_tmr.expires = (1) + jiffies;
56 add_timer(&def_tmr);
57
58 if (!tmr_running)
59 return;
60
61 spin_lock(&lock);
62 tmr_ctr++;
63 curr_ticks = ticks_offs + tmr2ticks(tmr_ctr);
64
65 if (curr_ticks >= next_event_time) {
66 next_event_time = (unsigned long) -1;
67 sequencer_timer(0);
68 }
69
70 spin_unlock(&lock);
71}
72
73static void
74tmr_reset(void)
75{
76 unsigned long flags;
77
78 spin_lock_irqsave(&lock,flags);
79 tmr_offs = 0;
80 ticks_offs = 0;
81 tmr_ctr = 0;
82 next_event_time = (unsigned long) -1;
83 prev_event_time = 0;
84 curr_ticks = 0;
85 spin_unlock_irqrestore(&lock,flags);
86}
87
88static int
89def_tmr_open(int dev, int mode)
90{
91 if (opened)
92 return -EBUSY;
93
94 tmr_reset();
95 curr_tempo = 60;
96 curr_timebase = 100;
97 opened = 1;
98 {
99 def_tmr.expires = (1) + jiffies;
100 add_timer(&def_tmr);
101 }
102
103 return 0;
104}
105
106static void
107def_tmr_close(int dev)
108{
109 opened = tmr_running = 0;
110 del_timer(&def_tmr);
111}
112
113static int
114def_tmr_event(int dev, unsigned char *event)
115{
116 unsigned char cmd = event[1];
117 unsigned long parm = *(int *) &event[4];
118
119 switch (cmd)
120 {
121 case TMR_WAIT_REL:
122 parm += prev_event_time;
123 case TMR_WAIT_ABS:
124 if (parm > 0)
125 {
126 long time;
127
128 if (parm <= curr_ticks) /* It's the time */
129 return TIMER_NOT_ARMED;
130
131 time = parm;
132 next_event_time = prev_event_time = time;
133
134 return TIMER_ARMED;
135 }
136 break;
137
138 case TMR_START:
139 tmr_reset();
140 tmr_running = 1;
141 break;
142
143 case TMR_STOP:
144 tmr_running = 0;
145 break;
146
147 case TMR_CONTINUE:
148 tmr_running = 1;
149 break;
150
151 case TMR_TEMPO:
152 if (parm)
153 {
154 if (parm < 8)
155 parm = 8;
156 if (parm > 360)
157 parm = 360;
158 tmr_offs = tmr_ctr;
159 ticks_offs += tmr2ticks(tmr_ctr);
160 tmr_ctr = 0;
161 curr_tempo = parm;
162 }
163 break;
164
165 case TMR_ECHO:
166 seq_copy_to_input(event, 8);
167 break;
168
169 default:;
170 }
171
172 return TIMER_NOT_ARMED;
173}
174
175static unsigned long
176def_tmr_get_time(int dev)
177{
178 if (!opened)
179 return 0;
180
181 return curr_ticks;
182}
183
184/* same as sound_timer.c:timer_ioctl!? */
185static int def_tmr_ioctl(int dev, unsigned int cmd, void __user *arg)
186{
187 int __user *p = arg;
188 int val;
189
190 switch (cmd) {
191 case SNDCTL_TMR_SOURCE:
192 return __put_user(TMR_INTERNAL, p);
193
194 case SNDCTL_TMR_START:
195 tmr_reset();
196 tmr_running = 1;
197 return 0;
198
199 case SNDCTL_TMR_STOP:
200 tmr_running = 0;
201 return 0;
202
203 case SNDCTL_TMR_CONTINUE:
204 tmr_running = 1;
205 return 0;
206
207 case SNDCTL_TMR_TIMEBASE:
208 if (__get_user(val, p))
209 return -EFAULT;
210 if (val) {
211 if (val < 1)
212 val = 1;
213 if (val > 1000)
214 val = 1000;
215 curr_timebase = val;
216 }
217 return __put_user(curr_timebase, p);
218
219 case SNDCTL_TMR_TEMPO:
220 if (__get_user(val, p))
221 return -EFAULT;
222 if (val) {
223 if (val < 8)
224 val = 8;
225 if (val > 250)
226 val = 250;
227 tmr_offs = tmr_ctr;
228 ticks_offs += tmr2ticks(tmr_ctr);
229 tmr_ctr = 0;
230 curr_tempo = val;
231 reprogram_timer();
232 }
233 return __put_user(curr_tempo, p);
234
235 case SNDCTL_SEQ_CTRLRATE:
236 if (__get_user(val, p))
237 return -EFAULT;
238 if (val != 0) /* Can't change */
239 return -EINVAL;
240 val = ((curr_tempo * curr_timebase) + 30) / 60;
241 return __put_user(val, p);
242
243 case SNDCTL_SEQ_GETTIME:
244 return __put_user(curr_ticks, p);
245
246 case SNDCTL_TMR_METRONOME:
247 /* NOP */
248 break;
249
250 default:;
251 }
252 return -EINVAL;
253}
254
255static void
256def_tmr_arm(int dev, long time)
257{
258 if (time < 0)
259 time = curr_ticks + 1;
260 else if (time <= curr_ticks) /* It's the time */
261 return;
262
263 next_event_time = prev_event_time = time;
264
265 return;
266}
267
268struct sound_timer_operations default_sound_timer =
269{
270 .owner = THIS_MODULE,
271 .info = {"System clock", 0},
272 .priority = 0, /* Priority */
273 .devlink = 0, /* Local device link */
274 .open = def_tmr_open,
275 .close = def_tmr_close,
276 .event = def_tmr_event,
277 .get_time = def_tmr_get_time,
278 .ioctl = def_tmr_ioctl,
279 .arm_timer = def_tmr_arm
280};
diff --git a/sound/oss/trix.c b/sound/oss/trix.c
deleted file mode 100644
index a57bc635d758..000000000000
--- a/sound/oss/trix.c
+++ /dev/null
@@ -1,525 +0,0 @@
1/*
2 * sound/oss/trix.c
3 *
4 * Low level driver for the MediaTrix AudioTrix Pro
5 * (MT-0002-PC Control Chip)
6 *
7 *
8 * Copyright (C) by Hannu Savolainen 1993-1997
9 *
10 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
11 * Version 2 (June 1991). See the "COPYING" file distributed with this software
12 * for more info.
13 *
14 * Changes
15 * Alan Cox Modularisation, cleanup.
16 * Christoph Hellwig Adapted to module_init/module_exit
17 * Arnaldo C. de Melo Got rid of attach_uart401
18 */
19
20#include <linux/init.h>
21#include <linux/module.h>
22
23#include "sound_config.h"
24#include "sb.h"
25#include "sound_firmware.h"
26
27#include "ad1848.h"
28#include "mpu401.h"
29
30#include "trix_boot.h"
31
32static int mpu;
33
34static bool joystick;
35
36static unsigned char trix_read(int addr)
37{
38 outb(((unsigned char) addr), 0x390); /* MT-0002-PC ASIC address */
39 return inb(0x391); /* MT-0002-PC ASIC data */
40}
41
42static void trix_write(int addr, int data)
43{
44 outb(((unsigned char) addr), 0x390); /* MT-0002-PC ASIC address */
45 outb(((unsigned char) data), 0x391); /* MT-0002-PC ASIC data */
46}
47
48static void download_boot(int base)
49{
50 int i = 0, n = trix_boot_len;
51
52 if (trix_boot_len == 0)
53 return;
54
55 trix_write(0xf8, 0x00); /* ??????? */
56 outb((0x01), base + 6); /* Clear the internal data pointer */
57 outb((0x00), base + 6); /* Restart */
58
59 /*
60 * Write the boot code to the RAM upload/download register.
61 * Each write increments the internal data pointer.
62 */
63 outb((0x01), base + 6); /* Clear the internal data pointer */
64 outb((0x1A), 0x390); /* Select RAM download/upload port */
65
66 for (i = 0; i < n; i++)
67 outb((trix_boot[i]), 0x391);
68 for (i = n; i < 10016; i++) /* Clear up to first 16 bytes of data RAM */
69 outb((0x00), 0x391);
70 outb((0x00), base + 6); /* Reset */
71 outb((0x50), 0x390); /* ?????? */
72
73}
74
75static int trix_set_wss_port(struct address_info *hw_config)
76{
77 unsigned char addr_bits;
78
79 if (trix_read(0x15) != 0x71) /* No ASIC signature */
80 {
81 MDB(printk(KERN_ERR "No AudioTrix ASIC signature found\n"));
82 return 0;
83 }
84
85 /*
86 * Reset some registers.
87 */
88
89 trix_write(0x13, 0);
90 trix_write(0x14, 0);
91
92 /*
93 * Configure the ASIC to place the codec to the proper I/O location
94 */
95
96 switch (hw_config->io_base)
97 {
98 case 0x530:
99 addr_bits = 0;
100 break;
101 case 0x604:
102 addr_bits = 1;
103 break;
104 case 0xE80:
105 addr_bits = 2;
106 break;
107 case 0xF40:
108 addr_bits = 3;
109 break;
110 default:
111 return 0;
112 }
113
114 trix_write(0x19, (trix_read(0x19) & 0x03) | addr_bits);
115 return 1;
116}
117
118/*
119 * Probe and attach routines for the Windows Sound System mode of
120 * AudioTrix Pro
121 */
122
123static int __init init_trix_wss(struct address_info *hw_config)
124{
125 static unsigned char dma_bits[4] = {
126 1, 2, 0, 3
127 };
128 struct resource *ports;
129 int config_port = hw_config->io_base + 0;
130 int dma1 = hw_config->dma, dma2 = hw_config->dma2;
131 int old_num_mixers = num_mixers;
132 u8 config, bits;
133 int ret;
134
135 switch(hw_config->irq) {
136 case 7:
137 bits = 8;
138 break;
139 case 9:
140 bits = 0x10;
141 break;
142 case 10:
143 bits = 0x18;
144 break;
145 case 11:
146 bits = 0x20;
147 break;
148 default:
149 printk(KERN_ERR "AudioTrix: Bad WSS IRQ %d\n", hw_config->irq);
150 return 0;
151 }
152
153 switch (dma1) {
154 case 0:
155 case 1:
156 case 3:
157 break;
158 default:
159 printk(KERN_ERR "AudioTrix: Bad WSS DMA %d\n", dma1);
160 return 0;
161 }
162
163 switch (dma2) {
164 case -1:
165 case 0:
166 case 1:
167 case 3:
168 break;
169 default:
170 printk(KERN_ERR "AudioTrix: Bad capture DMA %d\n", dma2);
171 return 0;
172 }
173
174 /*
175 * Check if the IO port returns valid signature. The original MS Sound
176 * system returns 0x04 while some cards (AudioTrix Pro for example)
177 * return 0x00.
178 */
179 ports = request_region(hw_config->io_base + 4, 4, "ad1848");
180 if (!ports) {
181 printk(KERN_ERR "AudioTrix: MSS I/O port conflict (%x)\n", hw_config->io_base);
182 return 0;
183 }
184
185 if (!request_region(hw_config->io_base, 4, "MSS config")) {
186 printk(KERN_ERR "AudioTrix: MSS I/O port conflict (%x)\n", hw_config->io_base);
187 release_region(hw_config->io_base + 4, 4);
188 return 0;
189 }
190
191 if (!trix_set_wss_port(hw_config))
192 goto fail;
193
194 config = inb(hw_config->io_base + 3);
195
196 if ((config & 0x3f) != 0x00)
197 {
198 MDB(printk(KERN_ERR "No MSS signature detected on port 0x%x\n", hw_config->io_base));
199 goto fail;
200 }
201
202 /*
203 * Check that DMA0 is not in use with a 8 bit board.
204 */
205
206 if (dma1 == 0 && config & 0x80)
207 {
208 printk(KERN_ERR "AudioTrix: Can't use DMA0 with a 8 bit card slot\n");
209 goto fail;
210 }
211 if (hw_config->irq > 9 && config & 0x80)
212 {
213 printk(KERN_ERR "AudioTrix: Can't use IRQ%d with a 8 bit card slot\n", hw_config->irq);
214 goto fail;
215 }
216
217 ret = ad1848_detect(ports, NULL, hw_config->osp);
218 if (!ret)
219 goto fail;
220
221 if (joystick==1)
222 trix_write(0x15, 0x80);
223
224 /*
225 * Set the IRQ and DMA addresses.
226 */
227
228 outb((bits | 0x40), config_port);
229
230 if (dma2 == -1 || dma2 == dma1)
231 {
232 bits |= dma_bits[dma1];
233 dma2 = dma1;
234 }
235 else
236 {
237 unsigned char tmp;
238
239 tmp = trix_read(0x13) & ~30;
240 trix_write(0x13, tmp | 0x80 | (dma1 << 4));
241
242 tmp = trix_read(0x14) & ~30;
243 trix_write(0x14, tmp | 0x80 | (dma2 << 4));
244 }
245
246 outb((bits), config_port); /* Write IRQ+DMA setup */
247
248 hw_config->slots[0] = ad1848_init("AudioTrix Pro", ports,
249 hw_config->irq,
250 dma1,
251 dma2,
252 0,
253 hw_config->osp,
254 THIS_MODULE);
255
256 if (num_mixers > old_num_mixers) /* Mixer got installed */
257 {
258 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_LINE); /* Line in */
259 AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_CD);
260 AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_SYNTH); /* OPL4 */
261 AD1848_REROUTE(SOUND_MIXER_SPEAKER, SOUND_MIXER_ALTPCM); /* SB */
262 }
263 return 1;
264
265fail:
266 release_region(hw_config->io_base, 4);
267 release_region(hw_config->io_base + 4, 4);
268 return 0;
269}
270
271static int __init probe_trix_sb(struct address_info *hw_config)
272{
273
274 int tmp;
275 unsigned char conf;
276 extern int sb_be_quiet;
277 int old_quiet;
278 static signed char irq_translate[] = {
279 -1, -1, -1, 0, 1, 2, -1, 3
280 };
281
282 if (trix_boot_len == 0)
283 return 0; /* No boot code -> no fun */
284
285 if ((hw_config->io_base & 0xffffff8f) != 0x200)
286 return 0;
287
288 tmp = hw_config->irq;
289 if (tmp > 7)
290 return 0;
291 if (irq_translate[tmp] == -1)
292 return 0;
293
294 tmp = hw_config->dma;
295 if (tmp != 1 && tmp != 3)
296 return 0;
297
298 if (!request_region(hw_config->io_base, 16, "soundblaster")) {
299 printk(KERN_ERR "AudioTrix: SB I/O port conflict (%x)\n", hw_config->io_base);
300 return 0;
301 }
302
303 conf = 0x84; /* DMA and IRQ enable */
304 conf |= hw_config->io_base & 0x70; /* I/O address bits */
305 conf |= irq_translate[hw_config->irq];
306 if (hw_config->dma == 3)
307 conf |= 0x08;
308 trix_write(0x1b, conf);
309
310 download_boot(hw_config->io_base);
311
312 hw_config->name = "AudioTrix SB";
313 if (!sb_dsp_detect(hw_config, 0, 0, NULL)) {
314 release_region(hw_config->io_base, 16);
315 return 0;
316 }
317
318 hw_config->driver_use_1 = SB_NO_MIDI | SB_NO_MIXER | SB_NO_RECORDING;
319
320 /* Prevent false alarms */
321 old_quiet = sb_be_quiet;
322 sb_be_quiet = 1;
323
324 sb_dsp_init(hw_config, THIS_MODULE);
325
326 sb_be_quiet = old_quiet;
327 return 1;
328}
329
330static int __init probe_trix_mpu(struct address_info *hw_config)
331{
332 unsigned char conf;
333 static int irq_bits[] = {
334 -1, -1, -1, 1, 2, 3, -1, 4, -1, 5
335 };
336
337 if (hw_config->irq > 9)
338 {
339 printk(KERN_ERR "AudioTrix: Bad MPU IRQ %d\n", hw_config->irq);
340 return 0;
341 }
342 if (irq_bits[hw_config->irq] == -1)
343 {
344 printk(KERN_ERR "AudioTrix: Bad MPU IRQ %d\n", hw_config->irq);
345 return 0;
346 }
347 switch (hw_config->io_base)
348 {
349 case 0x330:
350 conf = 0x00;
351 break;
352 case 0x370:
353 conf = 0x04;
354 break;
355 case 0x3b0:
356 conf = 0x08;
357 break;
358 case 0x3f0:
359 conf = 0x0c;
360 break;
361 default:
362 return 0; /* Invalid port */
363 }
364
365 conf |= irq_bits[hw_config->irq] << 4;
366 trix_write(0x19, (trix_read(0x19) & 0x83) | conf);
367 hw_config->name = "AudioTrix Pro";
368 return probe_uart401(hw_config, THIS_MODULE);
369}
370
371static void __exit unload_trix_wss(struct address_info *hw_config)
372{
373 int dma2 = hw_config->dma2;
374
375 if (dma2 == -1)
376 dma2 = hw_config->dma;
377
378 release_region(0x390, 2);
379 release_region(hw_config->io_base, 4);
380
381 ad1848_unload(hw_config->io_base + 4,
382 hw_config->irq,
383 hw_config->dma,
384 dma2,
385 0);
386 sound_unload_audiodev(hw_config->slots[0]);
387}
388
389static inline void __exit unload_trix_mpu(struct address_info *hw_config)
390{
391 unload_uart401(hw_config);
392}
393
394static inline void __exit unload_trix_sb(struct address_info *hw_config)
395{
396 sb_dsp_unload(hw_config, mpu);
397}
398
399static struct address_info cfg;
400static struct address_info cfg2;
401static struct address_info cfg_mpu;
402
403static int sb;
404static int fw_load;
405
406static int __initdata io = -1;
407static int __initdata irq = -1;
408static int __initdata dma = -1;
409static int __initdata dma2 = -1; /* Set this for modules that need it */
410static int __initdata sb_io = -1;
411static int __initdata sb_dma = -1;
412static int __initdata sb_irq = -1;
413static int __initdata mpu_io = -1;
414static int __initdata mpu_irq = -1;
415
416module_param_hw(io, int, ioport, 0);
417module_param_hw(irq, int, irq, 0);
418module_param_hw(dma, int, dma, 0);
419module_param_hw(dma2, int, dma, 0);
420module_param_hw(sb_io, int, ioport, 0);
421module_param_hw(sb_dma, int, dma, 0);
422module_param_hw(sb_irq, int, irq, 0);
423module_param_hw(mpu_io, int, ioport, 0);
424module_param_hw(mpu_irq, int, irq, 0);
425module_param(joystick, bool, 0);
426
427static int __init init_trix(void)
428{
429 printk(KERN_INFO "MediaTrix audio driver Copyright (C) by Hannu Savolainen 1993-1996\n");
430
431 cfg.io_base = io;
432 cfg.irq = irq;
433 cfg.dma = dma;
434 cfg.dma2 = dma2;
435
436 cfg2.io_base = sb_io;
437 cfg2.irq = sb_irq;
438 cfg2.dma = sb_dma;
439
440 cfg_mpu.io_base = mpu_io;
441 cfg_mpu.irq = mpu_irq;
442
443 if (cfg.io_base == -1 || cfg.dma == -1 || cfg.irq == -1) {
444 printk(KERN_INFO "I/O, IRQ, DMA and type are mandatory\n");
445 return -EINVAL;
446 }
447
448 if (cfg2.io_base != -1 && (cfg2.irq == -1 || cfg2.dma == -1)) {
449 printk(KERN_INFO "CONFIG_SB_IRQ and CONFIG_SB_DMA must be specified if SB_IO is set.\n");
450 return -EINVAL;
451 }
452 if (cfg_mpu.io_base != -1 && cfg_mpu.irq == -1) {
453 printk(KERN_INFO "CONFIG_MPU_IRQ must be specified if MPU_IO is set.\n");
454 return -EINVAL;
455 }
456 if (!trix_boot)
457 {
458 fw_load = 1;
459 trix_boot_len = mod_firmware_load("/etc/sound/trxpro.bin",
460 (char **) &trix_boot);
461 }
462
463 if (!request_region(0x390, 2, "AudioTrix")) {
464 printk(KERN_ERR "AudioTrix: Config port I/O conflict\n");
465 return -ENODEV;
466 }
467
468 if (!init_trix_wss(&cfg)) {
469 release_region(0x390, 2);
470 return -ENODEV;
471 }
472
473 /*
474 * We must attach in the right order to get the firmware
475 * loaded up in time.
476 */
477
478 if (cfg2.io_base != -1) {
479 sb = probe_trix_sb(&cfg2);
480 }
481
482 if (cfg_mpu.io_base != -1)
483 mpu = probe_trix_mpu(&cfg_mpu);
484
485 return 0;
486}
487
488static void __exit cleanup_trix(void)
489{
490 if (fw_load)
491 vfree(trix_boot);
492 if (sb)
493 unload_trix_sb(&cfg2);
494 if (mpu)
495 unload_trix_mpu(&cfg_mpu);
496 unload_trix_wss(&cfg);
497}
498
499module_init(init_trix);
500module_exit(cleanup_trix);
501
502#ifndef MODULE
503static int __init setup_trix (char *str)
504{
505 /* io, irq, dma, dma2, sb_io, sb_irq, sb_dma, mpu_io, mpu_irq */
506 int ints[9];
507
508 str = get_options(str, ARRAY_SIZE(ints), ints);
509
510 io = ints[1];
511 irq = ints[2];
512 dma = ints[3];
513 dma2 = ints[4];
514 sb_io = ints[5];
515 sb_irq = ints[6];
516 sb_dma = ints[6];
517 mpu_io = ints[7];
518 mpu_irq = ints[8];
519
520 return 1;
521}
522
523__setup("trix=", setup_trix);
524#endif
525MODULE_LICENSE("GPL");
diff --git a/sound/oss/tuning.h b/sound/oss/tuning.h
deleted file mode 100644
index 953539931237..000000000000
--- a/sound/oss/tuning.h
+++ /dev/null
@@ -1,24 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2static unsigned short semitone_tuning[24] =
3{
4/* 0 */ 10000, 10595, 11225, 11892, 12599, 13348, 14142, 14983,
5/* 8 */ 15874, 16818, 17818, 18877, 20000, 21189, 22449, 23784,
6/* 16 */ 25198, 26697, 28284, 29966, 31748, 33636, 35636, 37755
7};
8
9static unsigned short cent_tuning[100] =
10{
11/* 0 */ 10000, 10006, 10012, 10017, 10023, 10029, 10035, 10041,
12/* 8 */ 10046, 10052, 10058, 10064, 10070, 10075, 10081, 10087,
13/* 16 */ 10093, 10099, 10105, 10110, 10116, 10122, 10128, 10134,
14/* 24 */ 10140, 10145, 10151, 10157, 10163, 10169, 10175, 10181,
15/* 32 */ 10187, 10192, 10198, 10204, 10210, 10216, 10222, 10228,
16/* 40 */ 10234, 10240, 10246, 10251, 10257, 10263, 10269, 10275,
17/* 48 */ 10281, 10287, 10293, 10299, 10305, 10311, 10317, 10323,
18/* 56 */ 10329, 10335, 10341, 10347, 10353, 10359, 10365, 10371,
19/* 64 */ 10377, 10383, 10389, 10395, 10401, 10407, 10413, 10419,
20/* 72 */ 10425, 10431, 10437, 10443, 10449, 10455, 10461, 10467,
21/* 80 */ 10473, 10479, 10485, 10491, 10497, 10503, 10509, 10515,
22/* 88 */ 10521, 10528, 10534, 10540, 10546, 10552, 10558, 10564,
23/* 96 */ 10570, 10576, 10582, 10589
24};
diff --git a/sound/oss/uart401.c b/sound/oss/uart401.c
deleted file mode 100644
index 83dcc85b8688..000000000000
--- a/sound/oss/uart401.c
+++ /dev/null
@@ -1,477 +0,0 @@
1/*
2 * sound/oss/uart401.c
3 *
4 * MPU-401 UART driver (formerly uart401_midi.c)
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 * Changes:
14 * Alan Cox Reformatted, removed sound_mem usage, use normal Linux
15 * interrupt allocation. Protect against bogus unload
16 * Fixed to allow IRQ > 15
17 * Christoph Hellwig Adapted to module_init/module_exit
18 * Arnaldo C. de Melo got rid of check_region
19 *
20 * Status:
21 * Untested
22 */
23
24#include <linux/init.h>
25#include <linux/interrupt.h>
26#include <linux/module.h>
27#include <linux/slab.h>
28#include <linux/spinlock.h>
29#include "sound_config.h"
30
31#include "mpu401.h"
32
33struct uart401_devc
34{
35 int base;
36 int irq;
37 int *osp;
38 void (*midi_input_intr) (int dev, unsigned char data);
39 int opened, disabled;
40 volatile unsigned char input_byte;
41 int my_dev;
42 int share_irq;
43 spinlock_t lock;
44};
45
46#define DATAPORT (devc->base)
47#define COMDPORT (devc->base+1)
48#define STATPORT (devc->base+1)
49
50static int uart401_status(struct uart401_devc *devc)
51{
52 return inb(STATPORT);
53}
54
55#define input_avail(devc) (!(uart401_status(devc)&INPUT_AVAIL))
56#define output_ready(devc) (!(uart401_status(devc)&OUTPUT_READY))
57
58static void uart401_cmd(struct uart401_devc *devc, unsigned char cmd)
59{
60 outb((cmd), COMDPORT);
61}
62
63static int uart401_read(struct uart401_devc *devc)
64{
65 return inb(DATAPORT);
66}
67
68static void uart401_write(struct uart401_devc *devc, unsigned char byte)
69{
70 outb((byte), DATAPORT);
71}
72
73#define OUTPUT_READY 0x40
74#define INPUT_AVAIL 0x80
75#define MPU_ACK 0xFE
76#define MPU_RESET 0xFF
77#define UART_MODE_ON 0x3F
78
79static int reset_uart401(struct uart401_devc *devc);
80static void enter_uart_mode(struct uart401_devc *devc);
81
82static void uart401_input_loop(struct uart401_devc *devc)
83{
84 int work_limit=30000;
85
86 while (input_avail(devc) && --work_limit)
87 {
88 unsigned char c = uart401_read(devc);
89
90 if (c == MPU_ACK)
91 devc->input_byte = c;
92 else if (devc->opened & OPEN_READ && devc->midi_input_intr)
93 devc->midi_input_intr(devc->my_dev, c);
94 }
95 if(work_limit==0)
96 printk(KERN_WARNING "Too much work in interrupt on uart401 (0x%X). UART jabbering ??\n", devc->base);
97}
98
99irqreturn_t uart401intr(int irq, void *dev_id)
100{
101 struct uart401_devc *devc = dev_id;
102
103 if (devc == NULL)
104 {
105 printk(KERN_ERR "uart401: bad devc\n");
106 return IRQ_NONE;
107 }
108
109 if (input_avail(devc))
110 uart401_input_loop(devc);
111 return IRQ_HANDLED;
112}
113
114static int
115uart401_open(int dev, int mode,
116 void (*input) (int dev, unsigned char data),
117 void (*output) (int dev)
118)
119{
120 struct uart401_devc *devc = (struct uart401_devc *)
121 midi_devs[dev]->devc;
122
123 if (devc->opened)
124 return -EBUSY;
125
126 /* Flush the UART */
127
128 while (input_avail(devc))
129 uart401_read(devc);
130
131 devc->midi_input_intr = input;
132 devc->opened = mode;
133 enter_uart_mode(devc);
134 devc->disabled = 0;
135
136 return 0;
137}
138
139static void uart401_close(int dev)
140{
141 struct uart401_devc *devc = (struct uart401_devc *)
142 midi_devs[dev]->devc;
143
144 reset_uart401(devc);
145 devc->opened = 0;
146}
147
148static int uart401_out(int dev, unsigned char midi_byte)
149{
150 int timeout;
151 unsigned long flags;
152 struct uart401_devc *devc = (struct uart401_devc *)
153 midi_devs[dev]->devc;
154
155 if (devc->disabled)
156 return 1;
157 /*
158 * Test for input since pending input seems to block the output.
159 */
160
161 spin_lock_irqsave(&devc->lock,flags);
162 if (input_avail(devc))
163 uart401_input_loop(devc);
164
165 spin_unlock_irqrestore(&devc->lock,flags);
166
167 /*
168 * Sometimes it takes about 13000 loops before the output becomes ready
169 * (After reset). Normally it takes just about 10 loops.
170 */
171
172 for (timeout = 30000; timeout > 0 && !output_ready(devc); timeout--);
173
174 if (!output_ready(devc))
175 {
176 printk(KERN_WARNING "uart401: Timeout - Device not responding\n");
177 devc->disabled = 1;
178 reset_uart401(devc);
179 enter_uart_mode(devc);
180 return 1;
181 }
182 uart401_write(devc, midi_byte);
183 return 1;
184}
185
186static inline int uart401_start_read(int dev)
187{
188 return 0;
189}
190
191static inline int uart401_end_read(int dev)
192{
193 return 0;
194}
195
196static inline void uart401_kick(int dev)
197{
198}
199
200static inline int uart401_buffer_status(int dev)
201{
202 return 0;
203}
204
205#define MIDI_SYNTH_NAME "MPU-401 UART"
206#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
207#include "midi_synth.h"
208
209static const struct midi_operations uart401_operations =
210{
211 .owner = THIS_MODULE,
212 .info = {"MPU-401 (UART) MIDI", 0, 0, SNDCARD_MPU401},
213 .converter = &std_midi_synth,
214 .in_info = {0},
215 .open = uart401_open,
216 .close = uart401_close,
217 .outputc = uart401_out,
218 .start_read = uart401_start_read,
219 .end_read = uart401_end_read,
220 .kick = uart401_kick,
221 .buffer_status = uart401_buffer_status,
222};
223
224static void enter_uart_mode(struct uart401_devc *devc)
225{
226 int ok, timeout;
227 unsigned long flags;
228
229 spin_lock_irqsave(&devc->lock,flags);
230 for (timeout = 30000; timeout > 0 && !output_ready(devc); timeout--);
231
232 devc->input_byte = 0;
233 uart401_cmd(devc, UART_MODE_ON);
234
235 ok = 0;
236 for (timeout = 50000; timeout > 0 && !ok; timeout--)
237 if (devc->input_byte == MPU_ACK)
238 ok = 1;
239 else if (input_avail(devc))
240 if (uart401_read(devc) == MPU_ACK)
241 ok = 1;
242
243 spin_unlock_irqrestore(&devc->lock,flags);
244}
245
246static int reset_uart401(struct uart401_devc *devc)
247{
248 int ok, timeout, n;
249
250 /*
251 * Send the RESET command. Try again if no success at the first time.
252 */
253
254 ok = 0;
255
256 for (n = 0; n < 2 && !ok; n++)
257 {
258 for (timeout = 30000; timeout > 0 && !output_ready(devc); timeout--);
259 devc->input_byte = 0;
260 uart401_cmd(devc, MPU_RESET);
261
262 /*
263 * Wait at least 25 msec. This method is not accurate so let's make the
264 * loop bit longer. Cannot sleep since this is called during boot.
265 */
266
267 for (timeout = 50000; timeout > 0 && !ok; timeout--)
268 {
269 if (devc->input_byte == MPU_ACK) /* Interrupt */
270 ok = 1;
271 else if (input_avail(devc))
272 {
273 if (uart401_read(devc) == MPU_ACK)
274 ok = 1;
275 }
276 }
277 }
278
279 /* Flush input before enabling interrupts */
280 if (ok)
281 uart401_input_loop(devc);
282 else
283 DDB(printk("Reset UART401 failed - No hardware detected.\n"));
284
285 return ok;
286}
287
288int probe_uart401(struct address_info *hw_config, struct module *owner)
289{
290 struct uart401_devc *devc;
291 char *name = "MPU-401 (UART) MIDI";
292 int ok = 0;
293 unsigned long flags;
294
295 DDB(printk("Entered probe_uart401()\n"));
296
297 /* Default to "not found" */
298 hw_config->slots[4] = -1;
299
300 if (!request_region(hw_config->io_base, 4, "MPU-401 UART")) {
301 printk(KERN_INFO "uart401: could not request_region(%d, 4)\n", hw_config->io_base);
302 return 0;
303 }
304
305 devc = kmalloc(sizeof(struct uart401_devc), GFP_KERNEL);
306 if (!devc) {
307 printk(KERN_WARNING "uart401: Can't allocate memory\n");
308 goto cleanup_region;
309 }
310
311 devc->base = hw_config->io_base;
312 devc->irq = hw_config->irq;
313 devc->osp = hw_config->osp;
314 devc->midi_input_intr = NULL;
315 devc->opened = 0;
316 devc->input_byte = 0;
317 devc->my_dev = 0;
318 devc->share_irq = 0;
319 spin_lock_init(&devc->lock);
320
321 spin_lock_irqsave(&devc->lock,flags);
322 ok = reset_uart401(devc);
323 spin_unlock_irqrestore(&devc->lock,flags);
324
325 if (!ok)
326 goto cleanup_devc;
327
328 if (hw_config->name)
329 name = hw_config->name;
330
331 if (devc->irq < 0) {
332 devc->share_irq = 1;
333 devc->irq *= -1;
334 } else
335 devc->share_irq = 0;
336
337 if (!devc->share_irq)
338 if (request_irq(devc->irq, uart401intr, 0, "MPU-401 UART", devc) < 0) {
339 printk(KERN_WARNING "uart401: Failed to allocate IRQ%d\n", devc->irq);
340 devc->share_irq = 1;
341 }
342 devc->my_dev = sound_alloc_mididev();
343 enter_uart_mode(devc);
344
345 if (devc->my_dev == -1) {
346 printk(KERN_INFO "uart401: Too many midi devices detected\n");
347 goto cleanup_irq;
348 }
349 conf_printf(name, hw_config);
350 midi_devs[devc->my_dev] = kmemdup(&uart401_operations,
351 sizeof(struct midi_operations),
352 GFP_KERNEL);
353 if (!midi_devs[devc->my_dev]) {
354 printk(KERN_ERR "uart401: Failed to allocate memory\n");
355 goto cleanup_unload_mididev;
356 }
357
358 if (owner)
359 midi_devs[devc->my_dev]->owner = owner;
360
361 midi_devs[devc->my_dev]->devc = devc;
362 midi_devs[devc->my_dev]->converter = kmemdup(&std_midi_synth,
363 sizeof(struct synth_operations),
364 GFP_KERNEL);
365
366 if (!midi_devs[devc->my_dev]->converter) {
367 printk(KERN_WARNING "uart401: Failed to allocate memory\n");
368 goto cleanup_midi_devs;
369 }
370 strcpy(midi_devs[devc->my_dev]->info.name, name);
371 midi_devs[devc->my_dev]->converter->id = "UART401";
372 midi_devs[devc->my_dev]->converter->midi_dev = devc->my_dev;
373
374 if (owner)
375 midi_devs[devc->my_dev]->converter->owner = owner;
376
377 hw_config->slots[4] = devc->my_dev;
378 sequencer_init();
379 devc->opened = 0;
380 return 1;
381cleanup_midi_devs:
382 kfree(midi_devs[devc->my_dev]);
383cleanup_unload_mididev:
384 sound_unload_mididev(devc->my_dev);
385cleanup_irq:
386 if (!devc->share_irq)
387 free_irq(devc->irq, devc);
388cleanup_devc:
389 kfree(devc);
390cleanup_region:
391 release_region(hw_config->io_base, 4);
392 return 0;
393}
394
395void unload_uart401(struct address_info *hw_config)
396{
397 struct uart401_devc *devc;
398 int n=hw_config->slots[4];
399
400 /* Not set up */
401 if(n==-1 || midi_devs[n]==NULL)
402 return;
403
404 /* Not allocated (erm ??) */
405
406 devc = midi_devs[hw_config->slots[4]]->devc;
407 if (devc == NULL)
408 return;
409
410 reset_uart401(devc);
411 release_region(hw_config->io_base, 4);
412
413 if (!devc->share_irq)
414 free_irq(devc->irq, devc);
415 kfree(midi_devs[devc->my_dev]->converter);
416 kfree(midi_devs[devc->my_dev]);
417 kfree(devc);
418
419 /* This kills midi_devs[x] */
420 sound_unload_mididev(hw_config->slots[4]);
421}
422
423EXPORT_SYMBOL(probe_uart401);
424EXPORT_SYMBOL(unload_uart401);
425EXPORT_SYMBOL(uart401intr);
426
427static struct address_info cfg_mpu;
428
429static int io = -1;
430static int irq = -1;
431
432module_param_hw(io, int, ioport, 0444);
433module_param_hw(irq, int, irq, 0444);
434
435
436static int __init init_uart401(void)
437{
438 cfg_mpu.irq = irq;
439 cfg_mpu.io_base = io;
440
441 /* Can be loaded either for module use or to provide functions
442 to others */
443 if (cfg_mpu.io_base != -1 && cfg_mpu.irq != -1) {
444 printk(KERN_INFO "MPU-401 UART driver Copyright (C) Hannu Savolainen 1993-1997");
445 if (!probe_uart401(&cfg_mpu, THIS_MODULE))
446 return -ENODEV;
447 }
448
449 return 0;
450}
451
452static void __exit cleanup_uart401(void)
453{
454 if (cfg_mpu.io_base != -1 && cfg_mpu.irq != -1)
455 unload_uart401(&cfg_mpu);
456}
457
458module_init(init_uart401);
459module_exit(cleanup_uart401);
460
461#ifndef MODULE
462static int __init setup_uart401(char *str)
463{
464 /* io, irq */
465 int ints[3];
466
467 str = get_options(str, ARRAY_SIZE(ints), ints);
468
469 io = ints[1];
470 irq = ints[2];
471
472 return 1;
473}
474
475__setup("uart401=", setup_uart401);
476#endif
477MODULE_LICENSE("GPL");
diff --git a/sound/oss/uart6850.c b/sound/oss/uart6850.c
deleted file mode 100644
index a9d3f7568525..000000000000
--- a/sound/oss/uart6850.c
+++ /dev/null
@@ -1,361 +0,0 @@
1/*
2 * sound/oss/uart6850.c
3 *
4 *
5 * Copyright (C) by Hannu Savolainen 1993-1997
6 *
7 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
8 * Version 2 (June 1991). See the "COPYING" file distributed with this software
9 * for more info.
10 * Extended by Alan Cox for Red Hat Software. Now a loadable MIDI driver.
11 * 28/4/97 - (C) Copyright Alan Cox. Released under the GPL version 2.
12 *
13 * Alan Cox: Updated for new modular code. Removed snd_* irq handling. Now
14 * uses native linux resources
15 * Christoph Hellwig: Adapted to module_init/module_exit
16 * Jeff Garzik: Made it work again, in theory
17 * FIXME: If the request_irq() succeeds, the probe succeeds. Ug.
18 *
19 * Status: Testing required (no shit -jgarzik)
20 *
21 *
22 */
23
24#include <linux/init.h>
25#include <linux/interrupt.h>
26#include <linux/module.h>
27#include <linux/spinlock.h>
28/* Mon Nov 22 22:38:35 MET 1993 marco@driq.home.usn.nl:
29 * added 6850 support, used with COVOX SoundMaster II and custom cards.
30 */
31
32#include "sound_config.h"
33
34static int uart6850_base = 0x330;
35
36static int *uart6850_osp;
37
38#define DATAPORT (uart6850_base)
39#define COMDPORT (uart6850_base+1)
40#define STATPORT (uart6850_base+1)
41
42static int uart6850_status(void)
43{
44 return inb(STATPORT);
45}
46
47#define input_avail() (uart6850_status()&INPUT_AVAIL)
48#define output_ready() (uart6850_status()&OUTPUT_READY)
49
50static void uart6850_cmd(unsigned char cmd)
51{
52 outb(cmd, COMDPORT);
53}
54
55static int uart6850_read(void)
56{
57 return inb(DATAPORT);
58}
59
60static void uart6850_write(unsigned char byte)
61{
62 outb(byte, DATAPORT);
63}
64
65#define OUTPUT_READY 0x02 /* Mask for data ready Bit */
66#define INPUT_AVAIL 0x01 /* Mask for Data Send Ready Bit */
67
68#define UART_RESET 0x95
69#define UART_MODE_ON 0x03
70
71static int uart6850_opened;
72static int uart6850_irq;
73static int uart6850_detected;
74static int my_dev;
75static DEFINE_SPINLOCK(lock);
76
77static void (*midi_input_intr) (int dev, unsigned char data);
78static void poll_uart6850(unsigned long dummy);
79
80
81static DEFINE_TIMER(uart6850_timer, poll_uart6850);
82
83static void uart6850_input_loop(void)
84{
85 int count = 10;
86
87 while (count)
88 {
89 /*
90 * Not timed out
91 */
92 if (input_avail())
93 {
94 unsigned char c = uart6850_read();
95 count = 100;
96 if (uart6850_opened & OPEN_READ)
97 midi_input_intr(my_dev, c);
98 }
99 else
100 {
101 while (!input_avail() && count)
102 count--;
103 }
104 }
105}
106
107static irqreturn_t m6850intr(int irq, void *dev_id)
108{
109 if (input_avail())
110 uart6850_input_loop();
111 return IRQ_HANDLED;
112}
113
114/*
115 * It looks like there is no input interrupts in the UART mode. Let's try
116 * polling.
117 */
118
119static void poll_uart6850(unsigned long dummy)
120{
121 unsigned long flags;
122
123 if (!(uart6850_opened & OPEN_READ))
124 return; /* Device has been closed */
125
126 spin_lock_irqsave(&lock,flags);
127 if (input_avail())
128 uart6850_input_loop();
129
130 uart6850_timer.expires = 1 + jiffies;
131 add_timer(&uart6850_timer);
132
133 /*
134 * Come back later
135 */
136
137 spin_unlock_irqrestore(&lock,flags);
138}
139
140static int uart6850_open(int dev, int mode,
141 void (*input) (int dev, unsigned char data),
142 void (*output) (int dev)
143)
144{
145 if (uart6850_opened)
146 {
147/* printk("Midi6850: Midi busy\n");*/
148 return -EBUSY;
149 }
150
151 uart6850_cmd(UART_RESET);
152 uart6850_input_loop();
153 midi_input_intr = input;
154 uart6850_opened = mode;
155 poll_uart6850(0); /*
156 * Enable input polling
157 */
158
159 return 0;
160}
161
162static void uart6850_close(int dev)
163{
164 uart6850_cmd(UART_MODE_ON);
165 del_timer(&uart6850_timer);
166 uart6850_opened = 0;
167}
168
169static int uart6850_out(int dev, unsigned char midi_byte)
170{
171 int timeout;
172 unsigned long flags;
173
174 /*
175 * Test for input since pending input seems to block the output.
176 */
177
178 spin_lock_irqsave(&lock,flags);
179
180 if (input_avail())
181 uart6850_input_loop();
182
183 spin_unlock_irqrestore(&lock,flags);
184
185 /*
186 * Sometimes it takes about 13000 loops before the output becomes ready
187 * (After reset). Normally it takes just about 10 loops.
188 */
189
190 for (timeout = 30000; timeout > 0 && !output_ready(); timeout--); /*
191 * Wait
192 */
193 if (!output_ready())
194 {
195 printk(KERN_WARNING "Midi6850: Timeout\n");
196 return 0;
197 }
198 uart6850_write(midi_byte);
199 return 1;
200}
201
202static inline int uart6850_command(int dev, unsigned char *midi_byte)
203{
204 return 1;
205}
206
207static inline int uart6850_start_read(int dev)
208{
209 return 0;
210}
211
212static inline int uart6850_end_read(int dev)
213{
214 return 0;
215}
216
217static inline void uart6850_kick(int dev)
218{
219}
220
221static inline int uart6850_buffer_status(int dev)
222{
223 return 0; /*
224 * No data in buffers
225 */
226}
227
228#define MIDI_SYNTH_NAME "6850 UART Midi"
229#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
230#include "midi_synth.h"
231
232static struct midi_operations uart6850_operations =
233{
234 .owner = THIS_MODULE,
235 .info = {"6850 UART", 0, 0, SNDCARD_UART6850},
236 .converter = &std_midi_synth,
237 .in_info = {0},
238 .open = uart6850_open,
239 .close = uart6850_close,
240 .outputc = uart6850_out,
241 .start_read = uart6850_start_read,
242 .end_read = uart6850_end_read,
243 .kick = uart6850_kick,
244 .command = uart6850_command,
245 .buffer_status = uart6850_buffer_status
246};
247
248
249static void __init attach_uart6850(struct address_info *hw_config)
250{
251 int ok, timeout;
252 unsigned long flags;
253
254 if (!uart6850_detected)
255 return;
256
257 if ((my_dev = sound_alloc_mididev()) == -1)
258 {
259 printk(KERN_INFO "uart6850: Too many midi devices detected\n");
260 return;
261 }
262 uart6850_base = hw_config->io_base;
263 uart6850_osp = hw_config->osp;
264 uart6850_irq = hw_config->irq;
265
266 spin_lock_irqsave(&lock,flags);
267
268 for (timeout = 30000; timeout > 0 && !output_ready(); timeout--); /*
269 * Wait
270 */
271 uart6850_cmd(UART_MODE_ON);
272 ok = 1;
273 spin_unlock_irqrestore(&lock,flags);
274
275 conf_printf("6850 Midi Interface", hw_config);
276
277 std_midi_synth.midi_dev = my_dev;
278 hw_config->slots[4] = my_dev;
279 midi_devs[my_dev] = &uart6850_operations;
280 sequencer_init();
281}
282
283static inline int reset_uart6850(void)
284{
285 uart6850_read();
286 return 1; /*
287 * OK
288 */
289}
290
291static int __init probe_uart6850(struct address_info *hw_config)
292{
293 int ok;
294
295 uart6850_osp = hw_config->osp;
296 uart6850_base = hw_config->io_base;
297 uart6850_irq = hw_config->irq;
298
299 if (request_irq(uart6850_irq, m6850intr, 0, "MIDI6850", NULL) < 0)
300 return 0;
301
302 ok = reset_uart6850();
303 uart6850_detected = ok;
304 return ok;
305}
306
307static void __exit unload_uart6850(struct address_info *hw_config)
308{
309 free_irq(hw_config->irq, NULL);
310 sound_unload_mididev(hw_config->slots[4]);
311}
312
313static struct address_info cfg_mpu;
314
315static int __initdata io = -1;
316static int __initdata irq = -1;
317
318module_param_hw(io, int, ioport, 0);
319module_param_hw(irq, int, irq, 0);
320
321static int __init init_uart6850(void)
322{
323 cfg_mpu.io_base = io;
324 cfg_mpu.irq = irq;
325
326 if (cfg_mpu.io_base == -1 || cfg_mpu.irq == -1) {
327 printk(KERN_INFO "uart6850: irq and io must be set.\n");
328 return -EINVAL;
329 }
330
331 if (probe_uart6850(&cfg_mpu))
332 return -ENODEV;
333 attach_uart6850(&cfg_mpu);
334
335 return 0;
336}
337
338static void __exit cleanup_uart6850(void)
339{
340 unload_uart6850(&cfg_mpu);
341}
342
343module_init(init_uart6850);
344module_exit(cleanup_uart6850);
345
346#ifndef MODULE
347static int __init setup_uart6850(char *str)
348{
349 /* io, irq */
350 int ints[3];
351
352 str = get_options(str, ARRAY_SIZE(ints), ints);
353
354 io = ints[1];
355 irq = ints[2];
356
357 return 1;
358}
359__setup("uart6850=", setup_uart6850);
360#endif
361MODULE_LICENSE("GPL");
diff --git a/sound/oss/ulaw.h b/sound/oss/ulaw.h
deleted file mode 100644
index ee898a0f78ce..000000000000
--- a/sound/oss/ulaw.h
+++ /dev/null
@@ -1,70 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2static unsigned char ulaw_dsp[] = {
3 3, 7, 11, 15, 19, 23, 27, 31,
4 35, 39, 43, 47, 51, 55, 59, 63,
5 66, 68, 70, 72, 74, 76, 78, 80,
6 82, 84, 86, 88, 90, 92, 94, 96,
7 98, 99, 100, 101, 102, 103, 104, 105,
8 106, 107, 108, 109, 110, 111, 112, 113,
9 113, 114, 114, 115, 115, 116, 116, 117,
10 117, 118, 118, 119, 119, 120, 120, 121,
11 121, 121, 122, 122, 122, 122, 123, 123,
12 123, 123, 124, 124, 124, 124, 125, 125,
13 125, 125, 125, 125, 126, 126, 126, 126,
14 126, 126, 126, 126, 127, 127, 127, 127,
15 127, 127, 127, 127, 127, 127, 127, 127,
16 128, 128, 128, 128, 128, 128, 128, 128,
17 128, 128, 128, 128, 128, 128, 128, 128,
18 128, 128, 128, 128, 128, 128, 128, 128,
19 253, 249, 245, 241, 237, 233, 229, 225,
20 221, 217, 213, 209, 205, 201, 197, 193,
21 190, 188, 186, 184, 182, 180, 178, 176,
22 174, 172, 170, 168, 166, 164, 162, 160,
23 158, 157, 156, 155, 154, 153, 152, 151,
24 150, 149, 148, 147, 146, 145, 144, 143,
25 143, 142, 142, 141, 141, 140, 140, 139,
26 139, 138, 138, 137, 137, 136, 136, 135,
27 135, 135, 134, 134, 134, 134, 133, 133,
28 133, 133, 132, 132, 132, 132, 131, 131,
29 131, 131, 131, 131, 130, 130, 130, 130,
30 130, 130, 130, 130, 129, 129, 129, 129,
31 129, 129, 129, 129, 129, 129, 129, 129,
32 128, 128, 128, 128, 128, 128, 128, 128,
33 128, 128, 128, 128, 128, 128, 128, 128,
34 128, 128, 128, 128, 128, 128, 128, 128,
35};
36
37static unsigned char dsp_ulaw[] = {
38 0, 0, 0, 0, 0, 1, 1, 1,
39 1, 2, 2, 2, 2, 3, 3, 3,
40 3, 4, 4, 4, 4, 5, 5, 5,
41 5, 6, 6, 6, 6, 7, 7, 7,
42 7, 8, 8, 8, 8, 9, 9, 9,
43 9, 10, 10, 10, 10, 11, 11, 11,
44 11, 12, 12, 12, 12, 13, 13, 13,
45 13, 14, 14, 14, 14, 15, 15, 15,
46 15, 16, 16, 17, 17, 18, 18, 19,
47 19, 20, 20, 21, 21, 22, 22, 23,
48 23, 24, 24, 25, 25, 26, 26, 27,
49 27, 28, 28, 29, 29, 30, 30, 31,
50 31, 32, 33, 34, 35, 36, 37, 38,
51 39, 40, 41, 42, 43, 44, 45, 46,
52 47, 49, 51, 53, 55, 57, 59, 61,
53 63, 66, 70, 74, 78, 84, 92, 104,
54 254, 231, 219, 211, 205, 201, 197, 193,
55 190, 188, 186, 184, 182, 180, 178, 176,
56 175, 174, 173, 172, 171, 170, 169, 168,
57 167, 166, 165, 164, 163, 162, 161, 160,
58 159, 159, 158, 158, 157, 157, 156, 156,
59 155, 155, 154, 154, 153, 153, 152, 152,
60 151, 151, 150, 150, 149, 149, 148, 148,
61 147, 147, 146, 146, 145, 145, 144, 144,
62 143, 143, 143, 143, 142, 142, 142, 142,
63 141, 141, 141, 141, 140, 140, 140, 140,
64 139, 139, 139, 139, 138, 138, 138, 138,
65 137, 137, 137, 137, 136, 136, 136, 136,
66 135, 135, 135, 135, 134, 134, 134, 134,
67 133, 133, 133, 133, 132, 132, 132, 132,
68 131, 131, 131, 131, 130, 130, 130, 130,
69 129, 129, 129, 129, 128, 128, 128, 128,
70};
diff --git a/sound/oss/v_midi.c b/sound/oss/v_midi.c
deleted file mode 100644
index fc0ba276cc8f..000000000000
--- a/sound/oss/v_midi.c
+++ /dev/null
@@ -1,290 +0,0 @@
1/*
2 * sound/oss/v_midi.c
3 *
4 * The low level driver for the Sound Blaster DS chips.
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1996
8 *
9 * USS/Lite for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 * ??
13 *
14 * Changes
15 * Alan Cox Modularisation, changed memory allocations
16 * Christoph Hellwig Adapted to module_init/module_exit
17 *
18 * Status
19 * Untested
20 */
21
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/slab.h>
25#include <linux/spinlock.h>
26#include "sound_config.h"
27
28#include "v_midi.h"
29
30static vmidi_devc *v_devc[2] = { NULL, NULL};
31static int midi1,midi2;
32static void *midi_mem = NULL;
33
34/*
35 * The DSP channel can be used either for input or output. Variable
36 * 'sb_irq_mode' will be set when the program calls read or write first time
37 * after open. Current version doesn't support mode changes without closing
38 * and reopening the device. Support for this feature may be implemented in a
39 * future version of this driver.
40 */
41
42
43static int v_midi_open (int dev, int mode,
44 void (*input) (int dev, unsigned char data),
45 void (*output) (int dev)
46)
47{
48 vmidi_devc *devc = midi_devs[dev]->devc;
49 unsigned long flags;
50
51 if (devc == NULL)
52 return -ENXIO;
53
54 spin_lock_irqsave(&devc->lock,flags);
55 if (devc->opened)
56 {
57 spin_unlock_irqrestore(&devc->lock,flags);
58 return -EBUSY;
59 }
60 devc->opened = 1;
61 spin_unlock_irqrestore(&devc->lock,flags);
62
63 devc->intr_active = 1;
64
65 if (mode & OPEN_READ)
66 {
67 devc->input_opened = 1;
68 devc->midi_input_intr = input;
69 }
70
71 return 0;
72}
73
74static void v_midi_close (int dev)
75{
76 vmidi_devc *devc = midi_devs[dev]->devc;
77 unsigned long flags;
78
79 if (devc == NULL)
80 return;
81
82 spin_lock_irqsave(&devc->lock,flags);
83 devc->intr_active = 0;
84 devc->input_opened = 0;
85 devc->opened = 0;
86 spin_unlock_irqrestore(&devc->lock,flags);
87}
88
89static int v_midi_out (int dev, unsigned char midi_byte)
90{
91 vmidi_devc *devc = midi_devs[dev]->devc;
92 vmidi_devc *pdevc;
93
94 if (devc == NULL)
95 return -ENXIO;
96
97 pdevc = midi_devs[devc->pair_mididev]->devc;
98 if (pdevc->input_opened > 0){
99 if (MIDIbuf_avail(pdevc->my_mididev) > 500)
100 return 0;
101 pdevc->midi_input_intr (pdevc->my_mididev, midi_byte);
102 }
103 return 1;
104}
105
106static inline int v_midi_start_read (int dev)
107{
108 return 0;
109}
110
111static int v_midi_end_read (int dev)
112{
113 vmidi_devc *devc = midi_devs[dev]->devc;
114 if (devc == NULL)
115 return -ENXIO;
116
117 devc->intr_active = 0;
118 return 0;
119}
120
121/* why -EPERM and not -EINVAL?? */
122
123static inline int v_midi_ioctl (int dev, unsigned cmd, void __user *arg)
124{
125 return -EPERM;
126}
127
128
129#define MIDI_SYNTH_NAME "Loopback MIDI"
130#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
131
132#include "midi_synth.h"
133
134static struct midi_operations v_midi_operations =
135{
136 .owner = THIS_MODULE,
137 .info = {"Loopback MIDI Port 1", 0, 0, SNDCARD_VMIDI},
138 .converter = &std_midi_synth,
139 .in_info = {0},
140 .open = v_midi_open,
141 .close = v_midi_close,
142 .ioctl = v_midi_ioctl,
143 .outputc = v_midi_out,
144 .start_read = v_midi_start_read,
145 .end_read = v_midi_end_read,
146};
147
148static struct midi_operations v_midi_operations2 =
149{
150 .owner = THIS_MODULE,
151 .info = {"Loopback MIDI Port 2", 0, 0, SNDCARD_VMIDI},
152 .converter = &std_midi_synth,
153 .in_info = {0},
154 .open = v_midi_open,
155 .close = v_midi_close,
156 .ioctl = v_midi_ioctl,
157 .outputc = v_midi_out,
158 .start_read = v_midi_start_read,
159 .end_read = v_midi_end_read,
160};
161
162/*
163 * We kmalloc just one of these - it makes life simpler and the code
164 * cleaner and the memory handling far more efficient
165 */
166
167struct vmidi_memory
168{
169 /* Must be first */
170 struct midi_operations m_ops[2];
171 struct synth_operations s_ops[2];
172 struct vmidi_devc v_ops[2];
173};
174
175static void __init attach_v_midi (struct address_info *hw_config)
176{
177 struct vmidi_memory *m;
178 /* printk("Attaching v_midi device.....\n"); */
179
180 midi1 = sound_alloc_mididev();
181 if (midi1 == -1)
182 {
183 printk(KERN_ERR "v_midi: Too many midi devices detected\n");
184 return;
185 }
186
187 m = kmalloc(sizeof(struct vmidi_memory), GFP_KERNEL);
188 if (m == NULL)
189 {
190 printk(KERN_WARNING "Loopback MIDI: Failed to allocate memory\n");
191 sound_unload_mididev(midi1);
192 return;
193 }
194
195 midi_mem = m;
196
197 midi_devs[midi1] = &m->m_ops[0];
198
199
200 midi2 = sound_alloc_mididev();
201 if (midi2 == -1)
202 {
203 printk (KERN_ERR "v_midi: Too many midi devices detected\n");
204 kfree(m);
205 sound_unload_mididev(midi1);
206 return;
207 }
208
209 midi_devs[midi2] = &m->m_ops[1];
210
211 /* printk("VMIDI1: %d VMIDI2: %d\n",midi1,midi2); */
212
213 /* for MIDI-1 */
214 v_devc[0] = &m->v_ops[0];
215 memcpy ((char *) midi_devs[midi1], (char *) &v_midi_operations,
216 sizeof (struct midi_operations));
217
218 v_devc[0]->my_mididev = midi1;
219 v_devc[0]->pair_mididev = midi2;
220 v_devc[0]->opened = v_devc[0]->input_opened = 0;
221 v_devc[0]->intr_active = 0;
222 v_devc[0]->midi_input_intr = NULL;
223 spin_lock_init(&v_devc[0]->lock);
224
225 midi_devs[midi1]->devc = v_devc[0];
226
227 midi_devs[midi1]->converter = &m->s_ops[0];
228 std_midi_synth.midi_dev = midi1;
229 memcpy ((char *) midi_devs[midi1]->converter, (char *) &std_midi_synth,
230 sizeof (struct synth_operations));
231 midi_devs[midi1]->converter->id = "V_MIDI 1";
232
233 /* for MIDI-2 */
234 v_devc[1] = &m->v_ops[1];
235
236 memcpy ((char *) midi_devs[midi2], (char *) &v_midi_operations2,
237 sizeof (struct midi_operations));
238
239 v_devc[1]->my_mididev = midi2;
240 v_devc[1]->pair_mididev = midi1;
241 v_devc[1]->opened = v_devc[1]->input_opened = 0;
242 v_devc[1]->intr_active = 0;
243 v_devc[1]->midi_input_intr = NULL;
244 spin_lock_init(&v_devc[1]->lock);
245
246 midi_devs[midi2]->devc = v_devc[1];
247 midi_devs[midi2]->converter = &m->s_ops[1];
248
249 std_midi_synth.midi_dev = midi2;
250 memcpy ((char *) midi_devs[midi2]->converter, (char *) &std_midi_synth,
251 sizeof (struct synth_operations));
252 midi_devs[midi2]->converter->id = "V_MIDI 2";
253
254 sequencer_init();
255 /* printk("Attached v_midi device\n"); */
256}
257
258static inline int __init probe_v_midi(struct address_info *hw_config)
259{
260 return(1); /* always OK */
261}
262
263
264static void __exit unload_v_midi(struct address_info *hw_config)
265{
266 sound_unload_mididev(midi1);
267 sound_unload_mididev(midi2);
268 kfree(midi_mem);
269}
270
271static struct address_info cfg; /* dummy */
272
273static int __init init_vmidi(void)
274{
275 printk("MIDI Loopback device driver\n");
276 if (!probe_v_midi(&cfg))
277 return -ENODEV;
278 attach_v_midi(&cfg);
279
280 return 0;
281}
282
283static void __exit cleanup_vmidi(void)
284{
285 unload_v_midi(&cfg);
286}
287
288module_init(init_vmidi);
289module_exit(cleanup_vmidi);
290MODULE_LICENSE("GPL");
diff --git a/sound/oss/v_midi.h b/sound/oss/v_midi.h
deleted file mode 100644
index f4fc2bed07f8..000000000000
--- a/sound/oss/v_midi.h
+++ /dev/null
@@ -1,15 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2typedef struct vmidi_devc {
3 int dev;
4
5 /* State variables */
6 int opened;
7 spinlock_t lock;
8
9 /* MIDI fields */
10 int my_mididev;
11 int pair_mididev;
12 int input_opened;
13 int intr_active;
14 void (*midi_input_intr) (int dev, unsigned char data);
15 } vmidi_devc;
diff --git a/sound/oss/vidc.c b/sound/oss/vidc.c
deleted file mode 100644
index 92ca5bee1860..000000000000
--- a/sound/oss/vidc.c
+++ /dev/null
@@ -1,557 +0,0 @@
1/*
2 * linux/drivers/sound/vidc.c
3 *
4 * Copyright (C) 1997-2000 by Russell King <rmk@arm.linux.org.uk>
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 * VIDC20 audio driver.
11 *
12 * The VIDC20 sound hardware consists of the VIDC20 itself, a DAC and a DMA
13 * engine. The DMA transfers fixed-format (16-bit little-endian linear)
14 * samples to the VIDC20, which then transfers this data serially to the
15 * DACs. The samplerate is controlled by the VIDC.
16 *
17 * We currently support a mixer device, but it is currently non-functional.
18 */
19
20#include <linux/gfp.h>
21#include <linux/init.h>
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/interrupt.h>
25
26#include <mach/hardware.h>
27#include <asm/dma.h>
28#include <asm/io.h>
29#include <asm/hardware/iomd.h>
30#include <asm/irq.h>
31
32#include "sound_config.h"
33#include "vidc.h"
34
35#ifndef _SIOC_TYPE
36#define _SIOC_TYPE(x) _IOC_TYPE(x)
37#endif
38#ifndef _SIOC_NR
39#define _SIOC_NR(x) _IOC_NR(x)
40#endif
41
42#define VIDC_SOUND_CLOCK (250000)
43#define VIDC_SOUND_CLOCK_EXT (176400)
44
45/*
46 * When using SERIAL SOUND mode (external DAC), the number of physical
47 * channels is fixed at 2.
48 */
49static int vidc_busy;
50static int vidc_adev;
51static int vidc_audio_rate;
52static char vidc_audio_format;
53static char vidc_audio_channels;
54
55static unsigned char vidc_level_l[SOUND_MIXER_NRDEVICES] = {
56 85, /* master */
57 50, /* bass */
58 50, /* treble */
59 0, /* synth */
60 75, /* pcm */
61 0, /* speaker */
62 100, /* ext line */
63 0, /* mic */
64 100, /* CD */
65 0,
66};
67
68static unsigned char vidc_level_r[SOUND_MIXER_NRDEVICES] = {
69 85, /* master */
70 50, /* bass */
71 50, /* treble */
72 0, /* synth */
73 75, /* pcm */
74 0, /* speaker */
75 100, /* ext line */
76 0, /* mic */
77 100, /* CD */
78 0,
79};
80
81static unsigned int vidc_audio_volume_l; /* left PCM vol, 0 - 65536 */
82static unsigned int vidc_audio_volume_r; /* right PCM vol, 0 - 65536 */
83
84extern void vidc_update_filler(int bits, int channels);
85extern int softoss_dev;
86
87static void
88vidc_mixer_set(int mdev, unsigned int level)
89{
90 unsigned int lev_l = level & 0x007f;
91 unsigned int lev_r = (level & 0x7f00) >> 8;
92 unsigned int mlev_l, mlev_r;
93
94 if (lev_l > 100)
95 lev_l = 100;
96 if (lev_r > 100)
97 lev_r = 100;
98
99#define SCALE(lev,master) ((lev) * (master) * 65536 / 10000)
100
101 mlev_l = vidc_level_l[SOUND_MIXER_VOLUME];
102 mlev_r = vidc_level_r[SOUND_MIXER_VOLUME];
103
104 switch (mdev) {
105 case SOUND_MIXER_VOLUME:
106 case SOUND_MIXER_PCM:
107 vidc_level_l[mdev] = lev_l;
108 vidc_level_r[mdev] = lev_r;
109
110 vidc_audio_volume_l = SCALE(lev_l, mlev_l);
111 vidc_audio_volume_r = SCALE(lev_r, mlev_r);
112/*printk("VIDC: PCM vol %05X %05X\n", vidc_audio_volume_l, vidc_audio_volume_r);*/
113 break;
114 }
115#undef SCALE
116}
117
118static int vidc_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
119{
120 unsigned int val;
121 unsigned int mdev;
122
123 if (_SIOC_TYPE(cmd) != 'M')
124 return -EINVAL;
125
126 mdev = _SIOC_NR(cmd);
127
128 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
129 if (get_user(val, (unsigned int __user *)arg))
130 return -EFAULT;
131
132 if (mdev < SOUND_MIXER_NRDEVICES)
133 vidc_mixer_set(mdev, val);
134 else
135 return -EINVAL;
136 }
137
138 /*
139 * Return parameters
140 */
141 switch (mdev) {
142 case SOUND_MIXER_RECSRC:
143 val = 0;
144 break;
145
146 case SOUND_MIXER_DEVMASK:
147 val = SOUND_MASK_VOLUME | SOUND_MASK_PCM | SOUND_MASK_SYNTH;
148 break;
149
150 case SOUND_MIXER_STEREODEVS:
151 val = SOUND_MASK_VOLUME | SOUND_MASK_PCM | SOUND_MASK_SYNTH;
152 break;
153
154 case SOUND_MIXER_RECMASK:
155 val = 0;
156 break;
157
158 case SOUND_MIXER_CAPS:
159 val = 0;
160 break;
161
162 default:
163 if (mdev < SOUND_MIXER_NRDEVICES)
164 val = vidc_level_l[mdev] | vidc_level_r[mdev] << 8;
165 else
166 return -EINVAL;
167 }
168
169 return put_user(val, (unsigned int __user *)arg) ? -EFAULT : 0;
170}
171
172static unsigned int vidc_audio_set_format(int dev, unsigned int fmt)
173{
174 switch (fmt) {
175 default:
176 fmt = AFMT_S16_LE;
177 case AFMT_U8:
178 case AFMT_S8:
179 case AFMT_S16_LE:
180 vidc_audio_format = fmt;
181 vidc_update_filler(vidc_audio_format, vidc_audio_channels);
182 case AFMT_QUERY:
183 break;
184 }
185 return vidc_audio_format;
186}
187
188#define my_abs(i) ((i)<0 ? -(i) : (i))
189
190static int vidc_audio_set_speed(int dev, int rate)
191{
192 if (rate) {
193 unsigned int hwctrl, hwrate, hwrate_ext, rate_int, rate_ext;
194 unsigned int diff_int, diff_ext;
195 unsigned int newsize, new2size;
196
197 hwctrl = 0x00000003;
198
199 /* Using internal clock */
200 hwrate = (((VIDC_SOUND_CLOCK * 2) / rate) + 1) >> 1;
201 if (hwrate < 3)
202 hwrate = 3;
203 if (hwrate > 255)
204 hwrate = 255;
205
206 /* Using exernal clock */
207 hwrate_ext = (((VIDC_SOUND_CLOCK_EXT * 2) / rate) + 1) >> 1;
208 if (hwrate_ext < 3)
209 hwrate_ext = 3;
210 if (hwrate_ext > 255)
211 hwrate_ext = 255;
212
213 rate_int = VIDC_SOUND_CLOCK / hwrate;
214 rate_ext = VIDC_SOUND_CLOCK_EXT / hwrate_ext;
215
216 /* Chose between external and internal clock */
217 diff_int = my_abs(rate_ext-rate);
218 diff_ext = my_abs(rate_int-rate);
219 if (diff_ext < diff_int) {
220 /*printk("VIDC: external %d %d %d\n", rate, rate_ext, hwrate_ext);*/
221 hwrate=hwrate_ext;
222 hwctrl=0x00000002;
223 /* Allow roughly 0.4% tolerance */
224 if (diff_ext > (rate/256))
225 rate=rate_ext;
226 } else {
227 /*printk("VIDC: internal %d %d %d\n", rate, rate_int, hwrate);*/
228 hwctrl=0x00000003;
229 /* Allow roughly 0.4% tolerance */
230 if (diff_int > (rate/256))
231 rate=rate_int;
232 }
233
234 vidc_writel(0xb0000000 | (hwrate - 2));
235 vidc_writel(0xb1000000 | hwctrl);
236
237 newsize = (10000 / hwrate) & ~3;
238 if (newsize < 208)
239 newsize = 208;
240 if (newsize > 4096)
241 newsize = 4096;
242 for (new2size = 128; new2size < newsize; new2size <<= 1);
243 if (new2size - newsize > newsize - (new2size >> 1))
244 new2size >>= 1;
245 if (new2size > 4096) {
246 printk(KERN_ERR "VIDC: error: dma buffer (%d) %d > 4K\n",
247 newsize, new2size);
248 new2size = 4096;
249 }
250 /*printk("VIDC: dma size %d\n", new2size);*/
251 dma_bufsize = new2size;
252 vidc_audio_rate = rate;
253 }
254 return vidc_audio_rate;
255}
256
257static short vidc_audio_set_channels(int dev, short channels)
258{
259 switch (channels) {
260 default:
261 channels = 2;
262 case 1:
263 case 2:
264 vidc_audio_channels = channels;
265 vidc_update_filler(vidc_audio_format, vidc_audio_channels);
266 case 0:
267 break;
268 }
269 return vidc_audio_channels;
270}
271
272/*
273 * Open the device
274 */
275static int vidc_audio_open(int dev, int mode)
276{
277 /* This audio device does not have recording capability */
278 if (mode == OPEN_READ)
279 return -EPERM;
280
281 if (vidc_busy)
282 return -EBUSY;
283
284 vidc_busy = 1;
285 return 0;
286}
287
288/*
289 * Close the device
290 */
291static void vidc_audio_close(int dev)
292{
293 vidc_busy = 0;
294}
295
296/*
297 * Output a block via DMA to sound device.
298 *
299 * We just set the DMA start and count; the DMA interrupt routine
300 * will take care of formatting the samples (via the appropriate
301 * vidc_filler routine), and flag via vidc_audio_dma_interrupt when
302 * more data is required.
303 */
304static void
305vidc_audio_output_block(int dev, unsigned long buf, int total_count, int one)
306{
307 struct dma_buffparms *dmap = audio_devs[dev]->dmap_out;
308 unsigned long flags;
309
310 local_irq_save(flags);
311 dma_start = buf - (unsigned long)dmap->raw_buf_phys + (unsigned long)dmap->raw_buf;
312 dma_count = total_count;
313 local_irq_restore(flags);
314}
315
316static void
317vidc_audio_start_input(int dev, unsigned long buf, int count, int intrflag)
318{
319}
320
321static int vidc_audio_prepare_for_input(int dev, int bsize, int bcount)
322{
323 return -EINVAL;
324}
325
326static irqreturn_t vidc_audio_dma_interrupt(void)
327{
328 DMAbuf_outputintr(vidc_adev, 1);
329 return IRQ_HANDLED;
330}
331
332/*
333 * Prepare for outputting samples.
334 *
335 * Each buffer that will be passed will be `bsize' bytes long,
336 * with a total of `bcount' buffers.
337 */
338static int vidc_audio_prepare_for_output(int dev, int bsize, int bcount)
339{
340 struct audio_operations *adev = audio_devs[dev];
341
342 dma_interrupt = NULL;
343 adev->dmap_out->flags |= DMA_NODMA;
344
345 return 0;
346}
347
348/*
349 * Stop our current operation.
350 */
351static void vidc_audio_reset(int dev)
352{
353 dma_interrupt = NULL;
354}
355
356static int vidc_audio_local_qlen(int dev)
357{
358 return /*dma_count !=*/ 0;
359}
360
361static void vidc_audio_trigger(int dev, int enable_bits)
362{
363 struct audio_operations *adev = audio_devs[dev];
364
365 if (enable_bits & PCM_ENABLE_OUTPUT) {
366 if (!(adev->dmap_out->flags & DMA_ACTIVE)) {
367 unsigned long flags;
368
369 local_irq_save(flags);
370
371 /* prevent recusion */
372 adev->dmap_out->flags |= DMA_ACTIVE;
373
374 dma_interrupt = vidc_audio_dma_interrupt;
375 vidc_sound_dma_irq(0, NULL);
376 iomd_writeb(DMA_CR_E | 0x10, IOMD_SD0CR);
377
378 local_irq_restore(flags);
379 }
380 }
381}
382
383static struct audio_driver vidc_audio_driver =
384{
385 .owner = THIS_MODULE,
386 .open = vidc_audio_open,
387 .close = vidc_audio_close,
388 .output_block = vidc_audio_output_block,
389 .start_input = vidc_audio_start_input,
390 .prepare_for_input = vidc_audio_prepare_for_input,
391 .prepare_for_output = vidc_audio_prepare_for_output,
392 .halt_io = vidc_audio_reset,
393 .local_qlen = vidc_audio_local_qlen,
394 .trigger = vidc_audio_trigger,
395 .set_speed = vidc_audio_set_speed,
396 .set_bits = vidc_audio_set_format,
397 .set_channels = vidc_audio_set_channels
398};
399
400static struct mixer_operations vidc_mixer_operations = {
401 .owner = THIS_MODULE,
402 .id = "VIDC",
403 .name = "VIDCsound",
404 .ioctl = vidc_mixer_ioctl
405};
406
407void vidc_update_filler(int format, int channels)
408{
409#define TYPE(fmt,ch) (((fmt)<<2) | ((ch)&3))
410
411 switch (TYPE(format, channels)) {
412 default:
413 case TYPE(AFMT_U8, 1):
414 vidc_filler = vidc_fill_1x8_u;
415 break;
416
417 case TYPE(AFMT_U8, 2):
418 vidc_filler = vidc_fill_2x8_u;
419 break;
420
421 case TYPE(AFMT_S8, 1):
422 vidc_filler = vidc_fill_1x8_s;
423 break;
424
425 case TYPE(AFMT_S8, 2):
426 vidc_filler = vidc_fill_2x8_s;
427 break;
428
429 case TYPE(AFMT_S16_LE, 1):
430 vidc_filler = vidc_fill_1x16_s;
431 break;
432
433 case TYPE(AFMT_S16_LE, 2):
434 vidc_filler = vidc_fill_2x16_s;
435 break;
436 }
437}
438
439static void __init attach_vidc(struct address_info *hw_config)
440{
441 char name[32];
442 int i, adev;
443
444 sprintf(name, "VIDC %d-bit sound", hw_config->card_subtype);
445 conf_printf(name, hw_config);
446 memset(dma_buf, 0, sizeof(dma_buf));
447
448 adev = sound_install_audiodrv(AUDIO_DRIVER_VERSION, name,
449 &vidc_audio_driver, sizeof(vidc_audio_driver),
450 DMA_AUTOMODE, AFMT_U8 | AFMT_S8 | AFMT_S16_LE,
451 NULL, hw_config->dma, hw_config->dma2);
452
453 if (adev < 0)
454 goto audio_failed;
455
456 /*
457 * 1024 bytes => 64 buffers
458 */
459 audio_devs[adev]->min_fragment = 10;
460 audio_devs[adev]->mixer_dev = num_mixers;
461
462 audio_devs[adev]->mixer_dev =
463 sound_install_mixer(MIXER_DRIVER_VERSION,
464 name, &vidc_mixer_operations,
465 sizeof(vidc_mixer_operations), NULL);
466
467 if (audio_devs[adev]->mixer_dev < 0)
468 goto mixer_failed;
469
470 for (i = 0; i < 2; i++) {
471 dma_buf[i] = get_zeroed_page(GFP_KERNEL);
472 if (!dma_buf[i]) {
473 printk(KERN_ERR "%s: can't allocate required buffers\n",
474 name);
475 goto mem_failed;
476 }
477 dma_pbuf[i] = virt_to_phys((void *)dma_buf[i]);
478 }
479
480 if (sound_alloc_dma(hw_config->dma, hw_config->name)) {
481 printk(KERN_ERR "%s: DMA %d is in use\n", name, hw_config->dma);
482 goto dma_failed;
483 }
484
485 if (request_irq(hw_config->irq, vidc_sound_dma_irq, 0,
486 hw_config->name, &dma_start)) {
487 printk(KERN_ERR "%s: IRQ %d is in use\n", name, hw_config->irq);
488 goto irq_failed;
489 }
490 vidc_adev = adev;
491 vidc_mixer_set(SOUND_MIXER_VOLUME, (85 | 85 << 8));
492
493 return;
494
495irq_failed:
496 sound_free_dma(hw_config->dma);
497dma_failed:
498mem_failed:
499 for (i = 0; i < 2; i++)
500 free_page(dma_buf[i]);
501 sound_unload_mixerdev(audio_devs[adev]->mixer_dev);
502mixer_failed:
503 sound_unload_audiodev(adev);
504audio_failed:
505 return;
506}
507
508static int __init probe_vidc(struct address_info *hw_config)
509{
510 hw_config->irq = IRQ_DMAS0;
511 hw_config->dma = DMA_VIRTUAL_SOUND;
512 hw_config->dma2 = -1;
513 hw_config->card_subtype = 16;
514 hw_config->name = "VIDC20";
515 return 1;
516}
517
518static void __exit unload_vidc(struct address_info *hw_config)
519{
520 int i, adev = vidc_adev;
521
522 vidc_adev = -1;
523
524 free_irq(hw_config->irq, &dma_start);
525 sound_free_dma(hw_config->dma);
526
527 if (adev >= 0) {
528 sound_unload_mixerdev(audio_devs[adev]->mixer_dev);
529 sound_unload_audiodev(adev);
530 for (i = 0; i < 2; i++)
531 free_page(dma_buf[i]);
532 }
533}
534
535static struct address_info cfg;
536
537static int __init init_vidc(void)
538{
539 if (probe_vidc(&cfg) == 0)
540 return -ENODEV;
541
542 attach_vidc(&cfg);
543
544 return 0;
545}
546
547static void __exit cleanup_vidc(void)
548{
549 unload_vidc(&cfg);
550}
551
552module_init(init_vidc);
553module_exit(cleanup_vidc);
554
555MODULE_AUTHOR("Russell King");
556MODULE_DESCRIPTION("VIDC20 audio driver");
557MODULE_LICENSE("GPL");
diff --git a/sound/oss/vidc.h b/sound/oss/vidc.h
deleted file mode 100644
index 0d1424751ecd..000000000000
--- a/sound/oss/vidc.h
+++ /dev/null
@@ -1,63 +0,0 @@
1/*
2 * linux/drivers/sound/vidc.h
3 *
4 * Copyright (C) 1997 Russell King <rmk@arm.linux.org.uk>
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 * VIDC sound function prototypes
11 */
12
13/* vidc_fill.S */
14
15/*
16 * Filler routines for different channels and sample sizes
17 */
18
19extern unsigned long vidc_fill_1x8_u(unsigned long ibuf, unsigned long iend,
20 unsigned long obuf, int mask);
21extern unsigned long vidc_fill_2x8_u(unsigned long ibuf, unsigned long iend,
22 unsigned long obuf, int mask);
23extern unsigned long vidc_fill_1x8_s(unsigned long ibuf, unsigned long iend,
24 unsigned long obuf, int mask);
25extern unsigned long vidc_fill_2x8_s(unsigned long ibuf, unsigned long iend,
26 unsigned long obuf, int mask);
27extern unsigned long vidc_fill_1x16_s(unsigned long ibuf, unsigned long iend,
28 unsigned long obuf, int mask);
29extern unsigned long vidc_fill_2x16_s(unsigned long ibuf, unsigned long iend,
30 unsigned long obuf, int mask);
31
32/*
33 * DMA Interrupt handler
34 */
35
36extern irqreturn_t vidc_sound_dma_irq(int irqnr, void *ref);
37
38/*
39 * Filler routine pointer
40 */
41
42extern unsigned long (*vidc_filler) (unsigned long ibuf, unsigned long iend,
43 unsigned long obuf, int mask);
44
45/*
46 * Virtual DMA buffer exhausted
47 */
48
49extern irqreturn_t (*dma_interrupt) (void);
50
51/*
52 * Virtual DMA buffer addresses
53 */
54
55extern unsigned long dma_start, dma_count, dma_bufsize;
56extern unsigned long dma_buf[2], dma_pbuf[2];
57
58/* vidc_synth.c */
59
60extern void vidc_synth_init(struct address_info *hw_config);
61extern void vidc_synth_exit(struct address_info *hw_config);
62extern int vidc_synth_get_volume(void);
63extern int vidc_synth_set_volume(int vol);
diff --git a/sound/oss/vidc_fill.S b/sound/oss/vidc_fill.S
deleted file mode 100644
index bed34921d176..000000000000
--- a/sound/oss/vidc_fill.S
+++ /dev/null
@@ -1,218 +0,0 @@
1/*
2 * linux/drivers/sound/vidc_fill.S
3 *
4 * Copyright (C) 1997 Russell King
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 * Filler routines for DMA buffers
11 */
12#include <linux/linkage.h>
13#include <asm/assembler.h>
14#include <mach/hardware.h>
15#include <asm/hardware/iomd.h>
16
17 .text
18
19ENTRY(vidc_fill_1x8_u)
20 mov ip, #0xff00
211: cmp r0, r1
22 bge vidc_clear
23 ldrb r4, [r0], #1
24 eor r4, r4, #0x80
25 and r4, ip, r4, lsl #8
26 orr r4, r4, r4, lsl #16
27 str r4, [r2], #4
28 cmp r2, r3
29 blt 1b
30 mov pc, lr
31
32ENTRY(vidc_fill_2x8_u)
33 mov ip, #0xff00
341: cmp r0, r1
35 bge vidc_clear
36 ldr r4, [r0], #2
37 and r5, r4, ip
38 and r4, ip, r4, lsl #8
39 orr r4, r4, r5, lsl #16
40 orr r4, r4, r4, lsr #8
41 str r4, [r2], #4
42 cmp r2, r3
43 blt 1b
44 mov pc, lr
45
46ENTRY(vidc_fill_1x8_s)
47 mov ip, #0xff00
481: cmp r0, r1
49 bge vidc_clear
50 ldrb r4, [r0], #1
51 and r4, ip, r4, lsl #8
52 orr r4, r4, r4, lsl #16
53 str r4, [r2], #4
54 cmp r2, r3
55 blt 1b
56 mov pc, lr
57
58ENTRY(vidc_fill_2x8_s)
59 mov ip, #0xff00
601: cmp r0, r1
61 bge vidc_clear
62 ldr r4, [r0], #2
63 and r5, r4, ip
64 and r4, ip, r4, lsl #8
65 orr r4, r4, r5, lsl #16
66 orr r4, r4, r4, lsr #8
67 str r4, [r2], #4
68 cmp r2, r3
69 blt 1b
70 mov pc, lr
71
72ENTRY(vidc_fill_1x16_s)
73 mov ip, #0xff00
74 orr ip, ip, ip, lsr #8
751: cmp r0, r1
76 bge vidc_clear
77 ldr r5, [r0], #2
78 and r4, r5, ip
79 orr r4, r4, r4, lsl #16
80 str r4, [r2], #4
81 cmp r0, r1
82 addlt r0, r0, #2
83 andlt r4, r5, ip, lsl #16
84 orrlt r4, r4, r4, lsr #16
85 strlt r4, [r2], #4
86 cmp r2, r3
87 blt 1b
88 mov pc, lr
89
90ENTRY(vidc_fill_2x16_s)
91 mov ip, #0xff00
92 orr ip, ip, ip, lsr #8
931: cmp r0, r1
94 bge vidc_clear
95 ldr r4, [r0], #4
96 str r4, [r2], #4
97 cmp r0, r1
98 ldrlt r4, [r0], #4
99 strlt r4, [r2], #4
100 cmp r2, r3
101 blt 1b
102 mov pc, lr
103
104ENTRY(vidc_fill_noaudio)
105 mov r0, #0
106 mov r1, #0
1072: mov r4, #0
108 mov r5, #0
1091: cmp r2, r3
110 stmltia r2!, {r0, r1, r4, r5}
111 blt 1b
112 mov pc, lr
113
114ENTRY(vidc_clear)
115 mov r0, #0
116 mov r1, #0
117 tst r2, #4
118 str r0, [r2], #4
119 tst r2, #8
120 stmia r2!, {r0, r1}
121 b 2b
122
123/*
124 * Call filler routines with:
125 * r0 = phys address
126 * r1 = phys end
127 * r2 = buffer
128 * Returns:
129 * r0 = new buffer address
130 * r2 = new buffer finish
131 * r4 = corrupted
132 * r5 = corrupted
133 * ip = corrupted
134 */
135
136ENTRY(vidc_sound_dma_irq)
137 stmfd sp!, {r4 - r8, lr}
138 ldr r8, =dma_start
139 ldmia r8, {r0, r1, r2, r3, r4, r5}
140 teq r1, #0
141 adreq r4, vidc_fill_noaudio
142 moveq r7, #1 << 31
143 movne r7, #0
144 mov ip, #IOMD_BASE & 0xff000000
145 orr ip, ip, #IOMD_BASE & 0x00ff0000
146 ldrb r6, [ip, #IOMD_SD0ST]
147 tst r6, #DMA_ST_OFL @ Check for overrun
148 eorne r6, r6, #DMA_ST_AB
149 tst r6, #DMA_ST_AB
150 moveq r2, r3 @ DMAing A, update B
151 add r3, r2, r5 @ End of DMA buffer
152 add r1, r1, r0 @ End of virtual DMA buffer
153 mov lr, pc
154 mov pc, r4 @ Call fill routine (uses r4, ip)
155 sub r1, r1, r0 @ Remaining length
156 stmia r8, {r0, r1}
157 mov r0, #0
158 tst r2, #4 @ Round buffer up to 4 words
159 strne r0, [r2], #4
160 tst r2, #8
161 strne r0, [r2], #4
162 strne r0, [r2], #4
163 sub r2, r2, #16
164 mov r2, r2, lsl #20
165 movs r2, r2, lsr #20
166 orreq r2, r2, #1 << 30 @ Set L bit
167 orr r2, r2, r7
168 ldmdb r8, {r3, r4, r5}
169 tst r6, #DMA_ST_AB
170 mov ip, #IOMD_BASE & 0xff000000
171 orr ip, ip, #IOMD_BASE & 0x00ff0000
172 streq r4, [ip, #IOMD_SD0CURB]
173 strne r5, [ip, #IOMD_SD0CURA]
174 streq r2, [ip, #IOMD_SD0ENDB]
175 strne r2, [ip, #IOMD_SD0ENDA]
176 ldr lr, [ip, #IOMD_SD0ST]
177 tst lr, #DMA_ST_OFL
178 bne 1f
179 tst r6, #DMA_ST_AB
180 strne r4, [ip, #IOMD_SD0CURB]
181 streq r5, [ip, #IOMD_SD0CURA]
182 strne r2, [ip, #IOMD_SD0ENDB]
183 streq r2, [ip, #IOMD_SD0ENDA]
1841: teq r7, #0
185 mov r0, #0x10
186 strneb r0, [ip, #IOMD_SD0CR]
187 ldmfd sp!, {r4 - r8, lr}
188 mov r0, #1 @ IRQ_HANDLED
189 teq r1, #0 @ If we have no more
190 movne pc, lr
191 teq r3, #0
192 movne pc, r3 @ Call interrupt routine
193 mov pc, lr
194
195 .data
196 .globl dma_interrupt
197dma_interrupt:
198 .long 0 @ r3
199 .globl dma_pbuf
200dma_pbuf:
201 .long 0 @ r4
202 .long 0 @ r5
203 .globl dma_start
204dma_start:
205 .long 0 @ r0
206 .globl dma_count
207dma_count:
208 .long 0 @ r1
209 .globl dma_buf
210dma_buf:
211 .long 0 @ r2
212 .long 0 @ r3
213 .globl vidc_filler
214vidc_filler:
215 .long vidc_fill_noaudio @ r4
216 .globl dma_bufsize
217dma_bufsize:
218 .long 0x1000 @ r5
diff --git a/sound/oss/waveartist.c b/sound/oss/waveartist.c
deleted file mode 100644
index 4f0c3a232e41..000000000000
--- a/sound/oss/waveartist.c
+++ /dev/null
@@ -1,2043 +0,0 @@
1/*
2 * linux/sound/oss/waveartist.c
3 *
4 * The low level driver for the RWA010 Rockwell Wave Artist
5 * codec chip used in the Rebel.com NetWinder.
6 *
7 * Cleaned up and integrated into 2.1 by Russell King (rmk@arm.linux.org.uk)
8 * and Pat Beirne (patb@corel.ca)
9 *
10 *
11 * Copyright (C) by Rebel.com 1998-1999
12 *
13 * RWA010 specs received under NDA from Rockwell
14 *
15 * Copyright (C) by Hannu Savolainen 1993-1997
16 *
17 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
18 * Version 2 (June 1991). See the "COPYING" file distributed with this software
19 * for more info.
20 *
21 * Changes:
22 * 11-10-2000 Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
23 * Added __init to waveartist_init()
24 */
25
26/* Debugging */
27#define DEBUG_CMD 1
28#define DEBUG_OUT 2
29#define DEBUG_IN 4
30#define DEBUG_INTR 8
31#define DEBUG_MIXER 16
32#define DEBUG_TRIGGER 32
33
34#define debug_flg (0)
35
36#include <linux/module.h>
37#include <linux/init.h>
38#include <linux/slab.h>
39#include <linux/sched.h>
40#include <linux/interrupt.h>
41#include <linux/delay.h>
42#include <linux/spinlock.h>
43#include <linux/bitops.h>
44
45
46#include "sound_config.h"
47#include "waveartist.h"
48
49#ifdef CONFIG_ARM
50#include <mach/hardware.h>
51#include <asm/mach-types.h>
52#endif
53
54#ifndef NO_DMA
55#define NO_DMA 255
56#endif
57
58#define SUPPORTED_MIXER_DEVICES (SOUND_MASK_SYNTH |\
59 SOUND_MASK_PCM |\
60 SOUND_MASK_LINE |\
61 SOUND_MASK_MIC |\
62 SOUND_MASK_LINE1 |\
63 SOUND_MASK_RECLEV |\
64 SOUND_MASK_VOLUME |\
65 SOUND_MASK_IMIX)
66
67static unsigned short levels[SOUND_MIXER_NRDEVICES] = {
68 0x5555, /* Master Volume */
69 0x0000, /* Bass */
70 0x0000, /* Treble */
71 0x2323, /* Synth (FM) */
72 0x4b4b, /* PCM */
73 0x6464, /* PC Speaker */
74 0x0000, /* Ext Line */
75 0x0000, /* Mic */
76 0x0000, /* CD */
77 0x6464, /* Recording monitor */
78 0x0000, /* SB PCM (ALT PCM) */
79 0x0000, /* Recording level */
80 0x6464, /* Input gain */
81 0x6464, /* Output gain */
82 0x0000, /* Line1 (Aux1) */
83 0x0000, /* Line2 (Aux2) */
84 0x0000, /* Line3 (Aux3) */
85 0x0000, /* Digital1 */
86 0x0000, /* Digital2 */
87 0x0000, /* Digital3 */
88 0x0000, /* Phone In */
89 0x6464, /* Phone Out */
90 0x0000, /* Video */
91 0x0000, /* Radio */
92 0x0000 /* Monitor */
93};
94
95struct wavnc_info {
96 struct address_info hw; /* hardware */
97 char *chip_name;
98
99 int xfer_count;
100 int audio_mode;
101 int open_mode;
102 int audio_flags;
103 int record_dev;
104 int playback_dev;
105 int dev_no;
106
107 /* Mixer parameters */
108 const struct waveartist_mixer_info *mix;
109
110 unsigned short *levels; /* cache of volume settings */
111 int recmask; /* currently enabled recording device! */
112
113#ifdef CONFIG_ARCH_NETWINDER
114 signed int slider_vol; /* hardware slider volume */
115 unsigned int handset_detect :1;
116 unsigned int telephone_detect:1;
117 unsigned int no_autoselect :1;/* handset/telephone autoselects a path */
118 unsigned int spkr_mute_state :1;/* set by ioctl or autoselect */
119 unsigned int line_mute_state :1;/* set by ioctl or autoselect */
120 unsigned int use_slider :1;/* use slider setting for o/p vol */
121#endif
122};
123
124/*
125 * This is the implementation specific mixer information.
126 */
127struct waveartist_mixer_info {
128 unsigned int supported_devs; /* Supported devices */
129 unsigned int recording_devs; /* Recordable devies */
130 unsigned int stereo_devs; /* Stereo devices */
131
132 unsigned int (*select_input)(struct wavnc_info *, unsigned int,
133 unsigned char *, unsigned char *);
134 int (*decode_mixer)(struct wavnc_info *, int,
135 unsigned char, unsigned char);
136 int (*get_mixer)(struct wavnc_info *, int);
137};
138
139struct wavnc_port_info {
140 int open_mode;
141 int speed;
142 int channels;
143 int audio_format;
144};
145
146static int nr_waveartist_devs;
147static struct wavnc_info adev_info[MAX_AUDIO_DEV];
148static DEFINE_SPINLOCK(waveartist_lock);
149
150#ifndef CONFIG_ARCH_NETWINDER
151#define machine_is_netwinder() 0
152#else
153static struct timer_list vnc_timer;
154static void vnc_configure_mixer(struct wavnc_info *devc,
155 unsigned int input_mask);
156static int vnc_private_ioctl(int dev, unsigned int cmd, int __user *arg);
157static void vnc_slider_tick(unsigned long data);
158#endif
159
160static inline void
161waveartist_set_ctlr(struct address_info *hw, unsigned char clear, unsigned char set)
162{
163 unsigned int ctlr_port = hw->io_base + CTLR;
164
165 clear = ~clear & inb(ctlr_port);
166
167 outb(clear | set, ctlr_port);
168}
169
170/* Toggle IRQ acknowledge line
171 */
172static inline void
173waveartist_iack(struct wavnc_info *devc)
174{
175 unsigned int ctlr_port = devc->hw.io_base + CTLR;
176 int old_ctlr;
177
178 old_ctlr = inb(ctlr_port) & ~IRQ_ACK;
179
180 outb(old_ctlr | IRQ_ACK, ctlr_port);
181 outb(old_ctlr, ctlr_port);
182}
183
184static inline int
185waveartist_sleep(int timeout_ms)
186{
187 unsigned int timeout = msecs_to_jiffies(timeout_ms*100);
188 return schedule_timeout_interruptible(timeout);
189}
190
191static int
192waveartist_reset(struct wavnc_info *devc)
193{
194 struct address_info *hw = &devc->hw;
195 unsigned int timeout, res = -1;
196
197 waveartist_set_ctlr(hw, -1, RESET);
198 waveartist_sleep(2);
199 waveartist_set_ctlr(hw, RESET, 0);
200
201 timeout = 500;
202 do {
203 mdelay(2);
204
205 if (inb(hw->io_base + STATR) & CMD_RF) {
206 res = inw(hw->io_base + CMDR);
207 if (res == 0x55aa)
208 break;
209 }
210 } while (--timeout);
211
212 if (timeout == 0) {
213 printk(KERN_WARNING "WaveArtist: reset timeout ");
214 if (res != (unsigned int)-1)
215 printk("(res=%04X)", res);
216 printk("\n");
217 return 1;
218 }
219 return 0;
220}
221
222/* Helper function to send and receive words
223 * from WaveArtist. It handles all the handshaking
224 * and can send or receive multiple words.
225 */
226static int
227waveartist_cmd(struct wavnc_info *devc,
228 int nr_cmd, unsigned int *cmd,
229 int nr_resp, unsigned int *resp)
230{
231 unsigned int io_base = devc->hw.io_base;
232 unsigned int timed_out = 0;
233 unsigned int i;
234
235 if (debug_flg & DEBUG_CMD) {
236 printk("waveartist_cmd: cmd=");
237
238 for (i = 0; i < nr_cmd; i++)
239 printk("%04X ", cmd[i]);
240
241 printk("\n");
242 }
243
244 if (inb(io_base + STATR) & CMD_RF) {
245 int old_data;
246
247 /* flush the port
248 */
249
250 old_data = inw(io_base + CMDR);
251
252 if (debug_flg & DEBUG_CMD)
253 printk("flushed %04X...", old_data);
254
255 udelay(10);
256 }
257
258 for (i = 0; !timed_out && i < nr_cmd; i++) {
259 int count;
260
261 for (count = 5000; count; count--)
262 if (inb(io_base + STATR) & CMD_WE)
263 break;
264
265 if (!count)
266 timed_out = 1;
267 else
268 outw(cmd[i], io_base + CMDR);
269 }
270
271 for (i = 0; !timed_out && i < nr_resp; i++) {
272 int count;
273
274 for (count = 5000; count; count--)
275 if (inb(io_base + STATR) & CMD_RF)
276 break;
277
278 if (!count)
279 timed_out = 1;
280 else
281 resp[i] = inw(io_base + CMDR);
282 }
283
284 if (debug_flg & DEBUG_CMD) {
285 if (!timed_out) {
286 printk("waveartist_cmd: resp=");
287
288 for (i = 0; i < nr_resp; i++)
289 printk("%04X ", resp[i]);
290
291 printk("\n");
292 } else
293 printk("waveartist_cmd: timed out\n");
294 }
295
296 return timed_out ? 1 : 0;
297}
298
299/*
300 * Send one command word
301 */
302static inline int
303waveartist_cmd1(struct wavnc_info *devc, unsigned int cmd)
304{
305 return waveartist_cmd(devc, 1, &cmd, 0, NULL);
306}
307
308/*
309 * Send one command, receive one word
310 */
311static inline unsigned int
312waveartist_cmd1_r(struct wavnc_info *devc, unsigned int cmd)
313{
314 unsigned int ret;
315
316 waveartist_cmd(devc, 1, &cmd, 1, &ret);
317
318 return ret;
319}
320
321/*
322 * Send a double command, receive one
323 * word (and throw it away)
324 */
325static inline int
326waveartist_cmd2(struct wavnc_info *devc, unsigned int cmd, unsigned int arg)
327{
328 unsigned int vals[2];
329
330 vals[0] = cmd;
331 vals[1] = arg;
332
333 return waveartist_cmd(devc, 2, vals, 1, vals);
334}
335
336/*
337 * Send a triple command
338 */
339static inline int
340waveartist_cmd3(struct wavnc_info *devc, unsigned int cmd,
341 unsigned int arg1, unsigned int arg2)
342{
343 unsigned int vals[3];
344
345 vals[0] = cmd;
346 vals[1] = arg1;
347 vals[2] = arg2;
348
349 return waveartist_cmd(devc, 3, vals, 0, NULL);
350}
351
352static int
353waveartist_getrev(struct wavnc_info *devc, char *rev)
354{
355 unsigned int temp[2];
356 unsigned int cmd = WACMD_GETREV;
357
358 waveartist_cmd(devc, 1, &cmd, 2, temp);
359
360 rev[0] = temp[0] >> 8;
361 rev[1] = temp[0] & 255;
362 rev[2] = '\0';
363
364 return temp[0];
365}
366
367static void waveartist_halt_output(int dev);
368static void waveartist_halt_input(int dev);
369static void waveartist_halt(int dev);
370static void waveartist_trigger(int dev, int state);
371
372static int
373waveartist_open(int dev, int mode)
374{
375 struct wavnc_info *devc;
376 struct wavnc_port_info *portc;
377 unsigned long flags;
378
379 if (dev < 0 || dev >= num_audiodevs)
380 return -ENXIO;
381
382 devc = (struct wavnc_info *) audio_devs[dev]->devc;
383 portc = (struct wavnc_port_info *) audio_devs[dev]->portc;
384
385 spin_lock_irqsave(&waveartist_lock, flags);
386 if (portc->open_mode || (devc->open_mode & mode)) {
387 spin_unlock_irqrestore(&waveartist_lock, flags);
388 return -EBUSY;
389 }
390
391 devc->audio_mode = 0;
392 devc->open_mode |= mode;
393 portc->open_mode = mode;
394 waveartist_trigger(dev, 0);
395
396 if (mode & OPEN_READ)
397 devc->record_dev = dev;
398 if (mode & OPEN_WRITE)
399 devc->playback_dev = dev;
400 spin_unlock_irqrestore(&waveartist_lock, flags);
401
402 return 0;
403}
404
405static void
406waveartist_close(int dev)
407{
408 struct wavnc_info *devc = (struct wavnc_info *)
409 audio_devs[dev]->devc;
410 struct wavnc_port_info *portc = (struct wavnc_port_info *)
411 audio_devs[dev]->portc;
412 unsigned long flags;
413
414 spin_lock_irqsave(&waveartist_lock, flags);
415
416 waveartist_halt(dev);
417
418 devc->audio_mode = 0;
419 devc->open_mode &= ~portc->open_mode;
420 portc->open_mode = 0;
421
422 spin_unlock_irqrestore(&waveartist_lock, flags);
423}
424
425static void
426waveartist_output_block(int dev, unsigned long buf, int __count, int intrflag)
427{
428 struct wavnc_port_info *portc = (struct wavnc_port_info *)
429 audio_devs[dev]->portc;
430 struct wavnc_info *devc = (struct wavnc_info *)
431 audio_devs[dev]->devc;
432 unsigned long flags;
433 unsigned int count = __count;
434
435 if (debug_flg & DEBUG_OUT)
436 printk("waveartist: output block, buf=0x%lx, count=0x%x...\n",
437 buf, count);
438 /*
439 * 16 bit data
440 */
441 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE))
442 count >>= 1;
443
444 if (portc->channels > 1)
445 count >>= 1;
446
447 count -= 1;
448
449 if (devc->audio_mode & PCM_ENABLE_OUTPUT &&
450 audio_devs[dev]->flags & DMA_AUTOMODE &&
451 intrflag &&
452 count == devc->xfer_count) {
453 devc->audio_mode |= PCM_ENABLE_OUTPUT;
454 return; /*
455 * Auto DMA mode on. No need to react
456 */
457 }
458
459 spin_lock_irqsave(&waveartist_lock, flags);
460
461 /*
462 * set sample count
463 */
464 waveartist_cmd2(devc, WACMD_OUTPUTSIZE, count);
465
466 devc->xfer_count = count;
467 devc->audio_mode |= PCM_ENABLE_OUTPUT;
468
469 spin_unlock_irqrestore(&waveartist_lock, flags);
470}
471
472static void
473waveartist_start_input(int dev, unsigned long buf, int __count, int intrflag)
474{
475 struct wavnc_port_info *portc = (struct wavnc_port_info *)
476 audio_devs[dev]->portc;
477 struct wavnc_info *devc = (struct wavnc_info *)
478 audio_devs[dev]->devc;
479 unsigned long flags;
480 unsigned int count = __count;
481
482 if (debug_flg & DEBUG_IN)
483 printk("waveartist: start input, buf=0x%lx, count=0x%x...\n",
484 buf, count);
485
486 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE)) /* 16 bit data */
487 count >>= 1;
488
489 if (portc->channels > 1)
490 count >>= 1;
491
492 count -= 1;
493
494 if (devc->audio_mode & PCM_ENABLE_INPUT &&
495 audio_devs[dev]->flags & DMA_AUTOMODE &&
496 intrflag &&
497 count == devc->xfer_count) {
498 devc->audio_mode |= PCM_ENABLE_INPUT;
499 return; /*
500 * Auto DMA mode on. No need to react
501 */
502 }
503
504 spin_lock_irqsave(&waveartist_lock, flags);
505
506 /*
507 * set sample count
508 */
509 waveartist_cmd2(devc, WACMD_INPUTSIZE, count);
510
511 devc->xfer_count = count;
512 devc->audio_mode |= PCM_ENABLE_INPUT;
513
514 spin_unlock_irqrestore(&waveartist_lock, flags);
515}
516
517static int
518waveartist_ioctl(int dev, unsigned int cmd, void __user * arg)
519{
520 return -EINVAL;
521}
522
523static unsigned int
524waveartist_get_speed(struct wavnc_port_info *portc)
525{
526 unsigned int speed;
527
528 /*
529 * program the speed, channels, bits
530 */
531 if (portc->speed == 8000)
532 speed = 0x2E71;
533 else if (portc->speed == 11025)
534 speed = 0x4000;
535 else if (portc->speed == 22050)
536 speed = 0x8000;
537 else if (portc->speed == 44100)
538 speed = 0x0;
539 else {
540 /*
541 * non-standard - just calculate
542 */
543 speed = portc->speed << 16;
544
545 speed = (speed / 44100) & 65535;
546 }
547
548 return speed;
549}
550
551static unsigned int
552waveartist_get_bits(struct wavnc_port_info *portc)
553{
554 unsigned int bits;
555
556 if (portc->audio_format == AFMT_S16_LE)
557 bits = 1;
558 else if (portc->audio_format == AFMT_S8)
559 bits = 0;
560 else
561 bits = 2; //default AFMT_U8
562
563 return bits;
564}
565
566static int
567waveartist_prepare_for_input(int dev, int bsize, int bcount)
568{
569 unsigned long flags;
570 struct wavnc_info *devc = (struct wavnc_info *)
571 audio_devs[dev]->devc;
572 struct wavnc_port_info *portc = (struct wavnc_port_info *)
573 audio_devs[dev]->portc;
574 unsigned int speed, bits;
575
576 if (devc->audio_mode)
577 return 0;
578
579 speed = waveartist_get_speed(portc);
580 bits = waveartist_get_bits(portc);
581
582 spin_lock_irqsave(&waveartist_lock, flags);
583
584 if (waveartist_cmd2(devc, WACMD_INPUTFORMAT, bits))
585 printk(KERN_WARNING "waveartist: error setting the "
586 "record format to %d\n", portc->audio_format);
587
588 if (waveartist_cmd2(devc, WACMD_INPUTCHANNELS, portc->channels))
589 printk(KERN_WARNING "waveartist: error setting record "
590 "to %d channels\n", portc->channels);
591
592 /*
593 * write cmd SetSampleSpeedTimeConstant
594 */
595 if (waveartist_cmd2(devc, WACMD_INPUTSPEED, speed))
596 printk(KERN_WARNING "waveartist: error setting the record "
597 "speed to %dHz.\n", portc->speed);
598
599 if (waveartist_cmd2(devc, WACMD_INPUTDMA, 1))
600 printk(KERN_WARNING "waveartist: error setting the record "
601 "data path to 0x%X\n", 1);
602
603 if (waveartist_cmd2(devc, WACMD_INPUTFORMAT, bits))
604 printk(KERN_WARNING "waveartist: error setting the record "
605 "format to %d\n", portc->audio_format);
606
607 devc->xfer_count = 0;
608 spin_unlock_irqrestore(&waveartist_lock, flags);
609 waveartist_halt_input(dev);
610
611 if (debug_flg & DEBUG_INTR) {
612 printk("WA CTLR reg: 0x%02X.\n",
613 inb(devc->hw.io_base + CTLR));
614 printk("WA STAT reg: 0x%02X.\n",
615 inb(devc->hw.io_base + STATR));
616 printk("WA IRQS reg: 0x%02X.\n",
617 inb(devc->hw.io_base + IRQSTAT));
618 }
619
620 return 0;
621}
622
623static int
624waveartist_prepare_for_output(int dev, int bsize, int bcount)
625{
626 unsigned long flags;
627 struct wavnc_info *devc = (struct wavnc_info *)
628 audio_devs[dev]->devc;
629 struct wavnc_port_info *portc = (struct wavnc_port_info *)
630 audio_devs[dev]->portc;
631 unsigned int speed, bits;
632
633 /*
634 * program the speed, channels, bits
635 */
636 speed = waveartist_get_speed(portc);
637 bits = waveartist_get_bits(portc);
638
639 spin_lock_irqsave(&waveartist_lock, flags);
640
641 if (waveartist_cmd2(devc, WACMD_OUTPUTSPEED, speed) &&
642 waveartist_cmd2(devc, WACMD_OUTPUTSPEED, speed))
643 printk(KERN_WARNING "waveartist: error setting the playback "
644 "speed to %dHz.\n", portc->speed);
645
646 if (waveartist_cmd2(devc, WACMD_OUTPUTCHANNELS, portc->channels))
647 printk(KERN_WARNING "waveartist: error setting the playback "
648 "to %d channels\n", portc->channels);
649
650 if (waveartist_cmd2(devc, WACMD_OUTPUTDMA, 0))
651 printk(KERN_WARNING "waveartist: error setting the playback "
652 "data path to 0x%X\n", 0);
653
654 if (waveartist_cmd2(devc, WACMD_OUTPUTFORMAT, bits))
655 printk(KERN_WARNING "waveartist: error setting the playback "
656 "format to %d\n", portc->audio_format);
657
658 devc->xfer_count = 0;
659 spin_unlock_irqrestore(&waveartist_lock, flags);
660 waveartist_halt_output(dev);
661
662 if (debug_flg & DEBUG_INTR) {
663 printk("WA CTLR reg: 0x%02X.\n",inb(devc->hw.io_base + CTLR));
664 printk("WA STAT reg: 0x%02X.\n",inb(devc->hw.io_base + STATR));
665 printk("WA IRQS reg: 0x%02X.\n",inb(devc->hw.io_base + IRQSTAT));
666 }
667
668 return 0;
669}
670
671static void
672waveartist_halt(int dev)
673{
674 struct wavnc_port_info *portc = (struct wavnc_port_info *)
675 audio_devs[dev]->portc;
676 struct wavnc_info *devc;
677
678 if (portc->open_mode & OPEN_WRITE)
679 waveartist_halt_output(dev);
680
681 if (portc->open_mode & OPEN_READ)
682 waveartist_halt_input(dev);
683
684 devc = (struct wavnc_info *) audio_devs[dev]->devc;
685 devc->audio_mode = 0;
686}
687
688static void
689waveartist_halt_input(int dev)
690{
691 struct wavnc_info *devc = (struct wavnc_info *)
692 audio_devs[dev]->devc;
693 unsigned long flags;
694
695 spin_lock_irqsave(&waveartist_lock, flags);
696
697 /*
698 * Stop capture
699 */
700 waveartist_cmd1(devc, WACMD_INPUTSTOP);
701
702 devc->audio_mode &= ~PCM_ENABLE_INPUT;
703
704 /*
705 * Clear interrupt by toggling
706 * the IRQ_ACK bit in CTRL
707 */
708 if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
709 waveartist_iack(devc);
710
711// devc->audio_mode &= ~PCM_ENABLE_INPUT;
712
713 spin_unlock_irqrestore(&waveartist_lock, flags);
714}
715
716static void
717waveartist_halt_output(int dev)
718{
719 struct wavnc_info *devc = (struct wavnc_info *)
720 audio_devs[dev]->devc;
721 unsigned long flags;
722
723 spin_lock_irqsave(&waveartist_lock, flags);
724
725 waveartist_cmd1(devc, WACMD_OUTPUTSTOP);
726
727 devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
728
729 /*
730 * Clear interrupt by toggling
731 * the IRQ_ACK bit in CTRL
732 */
733 if (inb(devc->hw.io_base + STATR) & IRQ_REQ)
734 waveartist_iack(devc);
735
736// devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
737
738 spin_unlock_irqrestore(&waveartist_lock, flags);
739}
740
741static void
742waveartist_trigger(int dev, int state)
743{
744 struct wavnc_info *devc = (struct wavnc_info *)
745 audio_devs[dev]->devc;
746 struct wavnc_port_info *portc = (struct wavnc_port_info *)
747 audio_devs[dev]->portc;
748 unsigned long flags;
749
750 if (debug_flg & DEBUG_TRIGGER) {
751 printk("wavnc: audio trigger ");
752 if (state & PCM_ENABLE_INPUT)
753 printk("in ");
754 if (state & PCM_ENABLE_OUTPUT)
755 printk("out");
756 printk("\n");
757 }
758
759 spin_lock_irqsave(&waveartist_lock, flags);
760
761 state &= devc->audio_mode;
762
763 if (portc->open_mode & OPEN_READ &&
764 state & PCM_ENABLE_INPUT)
765 /*
766 * enable ADC Data Transfer to PC
767 */
768 waveartist_cmd1(devc, WACMD_INPUTSTART);
769
770 if (portc->open_mode & OPEN_WRITE &&
771 state & PCM_ENABLE_OUTPUT)
772 /*
773 * enable DAC data transfer from PC
774 */
775 waveartist_cmd1(devc, WACMD_OUTPUTSTART);
776
777 spin_unlock_irqrestore(&waveartist_lock, flags);
778}
779
780static int
781waveartist_set_speed(int dev, int arg)
782{
783 struct wavnc_port_info *portc = (struct wavnc_port_info *)
784 audio_devs[dev]->portc;
785
786 if (arg <= 0)
787 return portc->speed;
788
789 if (arg < 5000)
790 arg = 5000;
791 if (arg > 44100)
792 arg = 44100;
793
794 portc->speed = arg;
795 return portc->speed;
796
797}
798
799static short
800waveartist_set_channels(int dev, short arg)
801{
802 struct wavnc_port_info *portc = (struct wavnc_port_info *)
803 audio_devs[dev]->portc;
804
805 if (arg != 1 && arg != 2)
806 return portc->channels;
807
808 portc->channels = arg;
809 return arg;
810}
811
812static unsigned int
813waveartist_set_bits(int dev, unsigned int arg)
814{
815 struct wavnc_port_info *portc = (struct wavnc_port_info *)
816 audio_devs[dev]->portc;
817
818 if (arg == 0)
819 return portc->audio_format;
820
821 if ((arg != AFMT_U8) && (arg != AFMT_S16_LE) && (arg != AFMT_S8))
822 arg = AFMT_U8;
823
824 portc->audio_format = arg;
825
826 return arg;
827}
828
829static struct audio_driver waveartist_audio_driver = {
830 .owner = THIS_MODULE,
831 .open = waveartist_open,
832 .close = waveartist_close,
833 .output_block = waveartist_output_block,
834 .start_input = waveartist_start_input,
835 .ioctl = waveartist_ioctl,
836 .prepare_for_input = waveartist_prepare_for_input,
837 .prepare_for_output = waveartist_prepare_for_output,
838 .halt_io = waveartist_halt,
839 .halt_input = waveartist_halt_input,
840 .halt_output = waveartist_halt_output,
841 .trigger = waveartist_trigger,
842 .set_speed = waveartist_set_speed,
843 .set_bits = waveartist_set_bits,
844 .set_channels = waveartist_set_channels
845};
846
847
848static irqreturn_t
849waveartist_intr(int irq, void *dev_id)
850{
851 struct wavnc_info *devc = dev_id;
852 int irqstatus, status;
853
854 spin_lock(&waveartist_lock);
855 irqstatus = inb(devc->hw.io_base + IRQSTAT);
856 status = inb(devc->hw.io_base + STATR);
857
858 if (debug_flg & DEBUG_INTR)
859 printk("waveartist_intr: stat=%02x, irqstat=%02x\n",
860 status, irqstatus);
861
862 if (status & IRQ_REQ) /* Clear interrupt */
863 waveartist_iack(devc);
864 else
865 printk(KERN_WARNING "waveartist: unexpected interrupt\n");
866
867 if (irqstatus & 0x01) {
868 int temp = 1;
869
870 /* PCM buffer done
871 */
872 if ((status & DMA0) && (devc->audio_mode & PCM_ENABLE_OUTPUT)) {
873 DMAbuf_outputintr(devc->playback_dev, 1);
874 temp = 0;
875 }
876 if ((status & DMA1) && (devc->audio_mode & PCM_ENABLE_INPUT)) {
877 DMAbuf_inputintr(devc->record_dev);
878 temp = 0;
879 }
880 if (temp) //default:
881 printk(KERN_WARNING "waveartist: Unknown interrupt\n");
882 }
883 if (irqstatus & 0x2)
884 // We do not use SB mode natively...
885 printk(KERN_WARNING "waveartist: Unexpected SB interrupt...\n");
886 spin_unlock(&waveartist_lock);
887 return IRQ_HANDLED;
888}
889
890/* -------------------------------------------------------------------------
891 * Mixer stuff
892 */
893struct mix_ent {
894 unsigned char reg_l;
895 unsigned char reg_r;
896 unsigned char shift;
897 unsigned char max;
898};
899
900static const struct mix_ent mix_devs[SOUND_MIXER_NRDEVICES] = {
901 { 2, 6, 1, 7 }, /* SOUND_MIXER_VOLUME */
902 { 0, 0, 0, 0 }, /* SOUND_MIXER_BASS */
903 { 0, 0, 0, 0 }, /* SOUND_MIXER_TREBLE */
904 { 0, 0, 0, 0 }, /* SOUND_MIXER_SYNTH */
905 { 0, 0, 0, 0 }, /* SOUND_MIXER_PCM */
906 { 0, 0, 0, 0 }, /* SOUND_MIXER_SPEAKER */
907 { 0, 4, 6, 31 }, /* SOUND_MIXER_LINE */
908 { 2, 6, 4, 3 }, /* SOUND_MIXER_MIC */
909 { 0, 0, 0, 0 }, /* SOUND_MIXER_CD */
910 { 0, 0, 0, 0 }, /* SOUND_MIXER_IMIX */
911 { 0, 0, 0, 0 }, /* SOUND_MIXER_ALTPCM */
912#if 0
913 { 3, 7, 0, 10 }, /* SOUND_MIXER_RECLEV */
914 { 0, 0, 0, 0 }, /* SOUND_MIXER_IGAIN */
915#else
916 { 0, 0, 0, 0 }, /* SOUND_MIXER_RECLEV */
917 { 3, 7, 0, 7 }, /* SOUND_MIXER_IGAIN */
918#endif
919 { 0, 0, 0, 0 }, /* SOUND_MIXER_OGAIN */
920 { 0, 4, 1, 31 }, /* SOUND_MIXER_LINE1 */
921 { 1, 5, 6, 31 }, /* SOUND_MIXER_LINE2 */
922 { 0, 0, 0, 0 }, /* SOUND_MIXER_LINE3 */
923 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL1 */
924 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL2 */
925 { 0, 0, 0, 0 }, /* SOUND_MIXER_DIGITAL3 */
926 { 0, 0, 0, 0 }, /* SOUND_MIXER_PHONEIN */
927 { 0, 0, 0, 0 }, /* SOUND_MIXER_PHONEOUT */
928 { 0, 0, 0, 0 }, /* SOUND_MIXER_VIDEO */
929 { 0, 0, 0, 0 }, /* SOUND_MIXER_RADIO */
930 { 0, 0, 0, 0 } /* SOUND_MIXER_MONITOR */
931};
932
933static void
934waveartist_mixer_update(struct wavnc_info *devc, int whichDev)
935{
936 unsigned int lev_left, lev_right;
937
938 lev_left = devc->levels[whichDev] & 0xff;
939 lev_right = devc->levels[whichDev] >> 8;
940
941 if (lev_left > 100)
942 lev_left = 100;
943 if (lev_right > 100)
944 lev_right = 100;
945
946#define SCALE(lev,max) ((lev) * (max) / 100)
947
948 if (machine_is_netwinder() && whichDev == SOUND_MIXER_PHONEOUT)
949 whichDev = SOUND_MIXER_VOLUME;
950
951 if (mix_devs[whichDev].reg_l || mix_devs[whichDev].reg_r) {
952 const struct mix_ent *mix = mix_devs + whichDev;
953 unsigned int mask, left, right;
954
955 mask = mix->max << mix->shift;
956 lev_left = SCALE(lev_left, mix->max) << mix->shift;
957 lev_right = SCALE(lev_right, mix->max) << mix->shift;
958
959 /* read left setting */
960 left = waveartist_cmd1_r(devc, WACMD_GET_LEVEL |
961 mix->reg_l << 8);
962
963 /* read right setting */
964 right = waveartist_cmd1_r(devc, WACMD_GET_LEVEL |
965 mix->reg_r << 8);
966
967 left = (left & ~mask) | (lev_left & mask);
968 right = (right & ~mask) | (lev_right & mask);
969
970 /* write left,right back */
971 waveartist_cmd3(devc, WACMD_SET_MIXER, left, right);
972 } else {
973 switch(whichDev) {
974 case SOUND_MIXER_PCM:
975 waveartist_cmd3(devc, WACMD_SET_LEVEL,
976 SCALE(lev_left, 32767),
977 SCALE(lev_right, 32767));
978 break;
979
980 case SOUND_MIXER_SYNTH:
981 waveartist_cmd3(devc, 0x0100 | WACMD_SET_LEVEL,
982 SCALE(lev_left, 32767),
983 SCALE(lev_right, 32767));
984 break;
985 }
986 }
987}
988
989/*
990 * Set the ADC MUX to the specified values. We do NOT do any
991 * checking of the values passed, since we assume that the
992 * relevant *_select_input function has done that for us.
993 */
994static void
995waveartist_set_adc_mux(struct wavnc_info *devc, char left_dev,
996 char right_dev)
997{
998 unsigned int reg_08, reg_09;
999
1000 reg_08 = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x0800);
1001 reg_09 = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x0900);
1002
1003 reg_08 = (reg_08 & ~0x3f) | right_dev << 3 | left_dev;
1004
1005 waveartist_cmd3(devc, WACMD_SET_MIXER, reg_08, reg_09);
1006}
1007
1008/*
1009 * Decode a recording mask into a mixer selection as follows:
1010 *
1011 * OSS Source WA Source Actual source
1012 * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
1013 * SOUND_MASK_LINE Line Line in
1014 * SOUND_MASK_LINE1 Aux 1 Aux 1 in
1015 * SOUND_MASK_LINE2 Aux 2 Aux 2 in
1016 * SOUND_MASK_MIC Mic Microphone
1017 */
1018static unsigned int
1019waveartist_select_input(struct wavnc_info *devc, unsigned int recmask,
1020 unsigned char *dev_l, unsigned char *dev_r)
1021{
1022 unsigned int recdev = ADC_MUX_NONE;
1023
1024 if (recmask & SOUND_MASK_IMIX) {
1025 recmask = SOUND_MASK_IMIX;
1026 recdev = ADC_MUX_MIXER;
1027 } else if (recmask & SOUND_MASK_LINE2) {
1028 recmask = SOUND_MASK_LINE2;
1029 recdev = ADC_MUX_AUX2;
1030 } else if (recmask & SOUND_MASK_LINE1) {
1031 recmask = SOUND_MASK_LINE1;
1032 recdev = ADC_MUX_AUX1;
1033 } else if (recmask & SOUND_MASK_LINE) {
1034 recmask = SOUND_MASK_LINE;
1035 recdev = ADC_MUX_LINE;
1036 } else if (recmask & SOUND_MASK_MIC) {
1037 recmask = SOUND_MASK_MIC;
1038 recdev = ADC_MUX_MIC;
1039 }
1040
1041 *dev_l = *dev_r = recdev;
1042
1043 return recmask;
1044}
1045
1046static int
1047waveartist_decode_mixer(struct wavnc_info *devc, int dev,
1048 unsigned char lev_l,
1049 unsigned char lev_r)
1050{
1051 switch (dev) {
1052 case SOUND_MIXER_VOLUME:
1053 case SOUND_MIXER_SYNTH:
1054 case SOUND_MIXER_PCM:
1055 case SOUND_MIXER_LINE:
1056 case SOUND_MIXER_MIC:
1057 case SOUND_MIXER_IGAIN:
1058 case SOUND_MIXER_LINE1:
1059 case SOUND_MIXER_LINE2:
1060 devc->levels[dev] = lev_l | lev_r << 8;
1061 break;
1062
1063 case SOUND_MIXER_IMIX:
1064 break;
1065
1066 default:
1067 dev = -EINVAL;
1068 break;
1069 }
1070
1071 return dev;
1072}
1073
1074static int waveartist_get_mixer(struct wavnc_info *devc, int dev)
1075{
1076 return devc->levels[dev];
1077}
1078
1079static const struct waveartist_mixer_info waveartist_mixer = {
1080 .supported_devs = SUPPORTED_MIXER_DEVICES | SOUND_MASK_IGAIN,
1081 .recording_devs = SOUND_MASK_LINE | SOUND_MASK_MIC |
1082 SOUND_MASK_LINE1 | SOUND_MASK_LINE2 |
1083 SOUND_MASK_IMIX,
1084 .stereo_devs = (SUPPORTED_MIXER_DEVICES | SOUND_MASK_IGAIN) & ~
1085 (SOUND_MASK_SPEAKER | SOUND_MASK_IMIX),
1086 .select_input = waveartist_select_input,
1087 .decode_mixer = waveartist_decode_mixer,
1088 .get_mixer = waveartist_get_mixer,
1089};
1090
1091static void
1092waveartist_set_recmask(struct wavnc_info *devc, unsigned int recmask)
1093{
1094 unsigned char dev_l, dev_r;
1095
1096 recmask &= devc->mix->recording_devs;
1097
1098 /*
1099 * If more than one recording device selected,
1100 * disable the device that is currently in use.
1101 */
1102 if (hweight32(recmask) > 1)
1103 recmask &= ~devc->recmask;
1104
1105 /*
1106 * Translate the recording device mask into
1107 * the ADC multiplexer settings.
1108 */
1109 devc->recmask = devc->mix->select_input(devc, recmask,
1110 &dev_l, &dev_r);
1111
1112 waveartist_set_adc_mux(devc, dev_l, dev_r);
1113}
1114
1115static int
1116waveartist_set_mixer(struct wavnc_info *devc, int dev, unsigned int level)
1117{
1118 unsigned int lev_left = level & 0x00ff;
1119 unsigned int lev_right = (level & 0xff00) >> 8;
1120
1121 if (lev_left > 100)
1122 lev_left = 100;
1123 if (lev_right > 100)
1124 lev_right = 100;
1125
1126 /*
1127 * Mono devices have their right volume forced to their
1128 * left volume. (from ALSA driver OSS emulation).
1129 */
1130 if (!(devc->mix->stereo_devs & (1 << dev)))
1131 lev_right = lev_left;
1132
1133 dev = devc->mix->decode_mixer(devc, dev, lev_left, lev_right);
1134
1135 if (dev >= 0)
1136 waveartist_mixer_update(devc, dev);
1137
1138 return dev < 0 ? dev : 0;
1139}
1140
1141static int
1142waveartist_mixer_ioctl(int dev, unsigned int cmd, void __user * arg)
1143{
1144 struct wavnc_info *devc = (struct wavnc_info *)audio_devs[dev]->devc;
1145 int ret = 0, val, nr;
1146
1147 /*
1148 * All SOUND_MIXER_* ioctls use type 'M'
1149 */
1150 if (((cmd >> 8) & 255) != 'M')
1151 return -ENOIOCTLCMD;
1152
1153#ifdef CONFIG_ARCH_NETWINDER
1154 if (machine_is_netwinder()) {
1155 ret = vnc_private_ioctl(dev, cmd, arg);
1156 if (ret != -ENOIOCTLCMD)
1157 return ret;
1158 else
1159 ret = 0;
1160 }
1161#endif
1162
1163 nr = cmd & 0xff;
1164
1165 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
1166 if (get_user(val, (int __user *)arg))
1167 return -EFAULT;
1168
1169 switch (nr) {
1170 case SOUND_MIXER_RECSRC:
1171 waveartist_set_recmask(devc, val);
1172 break;
1173
1174 default:
1175 ret = -EINVAL;
1176 if (nr < SOUND_MIXER_NRDEVICES &&
1177 devc->mix->supported_devs & (1 << nr))
1178 ret = waveartist_set_mixer(devc, nr, val);
1179 }
1180 }
1181
1182 if (ret == 0 && _SIOC_DIR(cmd) & _SIOC_READ) {
1183 ret = -EINVAL;
1184
1185 switch (nr) {
1186 case SOUND_MIXER_RECSRC:
1187 ret = devc->recmask;
1188 break;
1189
1190 case SOUND_MIXER_DEVMASK:
1191 ret = devc->mix->supported_devs;
1192 break;
1193
1194 case SOUND_MIXER_STEREODEVS:
1195 ret = devc->mix->stereo_devs;
1196 break;
1197
1198 case SOUND_MIXER_RECMASK:
1199 ret = devc->mix->recording_devs;
1200 break;
1201
1202 case SOUND_MIXER_CAPS:
1203 ret = SOUND_CAP_EXCL_INPUT;
1204 break;
1205
1206 default:
1207 if (nr < SOUND_MIXER_NRDEVICES)
1208 ret = devc->mix->get_mixer(devc, nr);
1209 break;
1210 }
1211
1212 if (ret >= 0)
1213 ret = put_user(ret, (int __user *)arg) ? -EFAULT : 0;
1214 }
1215
1216 return ret;
1217}
1218
1219static struct mixer_operations waveartist_mixer_operations =
1220{
1221 .owner = THIS_MODULE,
1222 .id = "WaveArtist",
1223 .name = "WaveArtist",
1224 .ioctl = waveartist_mixer_ioctl
1225};
1226
1227static void
1228waveartist_mixer_reset(struct wavnc_info *devc)
1229{
1230 int i;
1231
1232 if (debug_flg & DEBUG_MIXER)
1233 printk("%s: mixer_reset\n", devc->hw.name);
1234
1235 /*
1236 * reset mixer cmd
1237 */
1238 waveartist_cmd1(devc, WACMD_RST_MIXER);
1239
1240 /*
1241 * set input for ADC to come from 'quiet'
1242 * turn on default modes
1243 */
1244 waveartist_cmd3(devc, WACMD_SET_MIXER, 0x9800, 0xa836);
1245
1246 /*
1247 * set mixer input select to none, RX filter gains 0 dB
1248 */
1249 waveartist_cmd3(devc, WACMD_SET_MIXER, 0x4c00, 0x8c00);
1250
1251 /*
1252 * set bit 0 reg 2 to 1 - unmute MonoOut
1253 */
1254 waveartist_cmd3(devc, WACMD_SET_MIXER, 0x2801, 0x6800);
1255
1256 /* set default input device = internal mic
1257 * current recording device = none
1258 */
1259 waveartist_set_recmask(devc, 0);
1260
1261 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
1262 waveartist_mixer_update(devc, i);
1263}
1264
1265static int __init waveartist_init(struct wavnc_info *devc)
1266{
1267 struct wavnc_port_info *portc;
1268 char rev[3], dev_name[64];
1269 int my_dev;
1270
1271 if (waveartist_reset(devc))
1272 return -ENODEV;
1273
1274 sprintf(dev_name, "%s (%s", devc->hw.name, devc->chip_name);
1275
1276 if (waveartist_getrev(devc, rev)) {
1277 strcat(dev_name, " rev. ");
1278 strcat(dev_name, rev);
1279 }
1280 strcat(dev_name, ")");
1281
1282 conf_printf2(dev_name, devc->hw.io_base, devc->hw.irq,
1283 devc->hw.dma, devc->hw.dma2);
1284
1285 portc = kzalloc(sizeof(struct wavnc_port_info), GFP_KERNEL);
1286 if (portc == NULL)
1287 goto nomem;
1288
1289 my_dev = sound_install_audiodrv(AUDIO_DRIVER_VERSION, dev_name,
1290 &waveartist_audio_driver, sizeof(struct audio_driver),
1291 devc->audio_flags, AFMT_U8 | AFMT_S16_LE | AFMT_S8,
1292 devc, devc->hw.dma, devc->hw.dma2);
1293
1294 if (my_dev < 0)
1295 goto free;
1296
1297 audio_devs[my_dev]->portc = portc;
1298
1299 waveartist_mixer_reset(devc);
1300
1301 /*
1302 * clear any pending interrupt
1303 */
1304 waveartist_iack(devc);
1305
1306 if (request_irq(devc->hw.irq, waveartist_intr, 0, devc->hw.name, devc) < 0) {
1307 printk(KERN_ERR "%s: IRQ %d in use\n",
1308 devc->hw.name, devc->hw.irq);
1309 goto uninstall;
1310 }
1311
1312 if (sound_alloc_dma(devc->hw.dma, devc->hw.name)) {
1313 printk(KERN_ERR "%s: Can't allocate DMA%d\n",
1314 devc->hw.name, devc->hw.dma);
1315 goto uninstall_irq;
1316 }
1317
1318 if (devc->hw.dma != devc->hw.dma2 && devc->hw.dma2 != NO_DMA)
1319 if (sound_alloc_dma(devc->hw.dma2, devc->hw.name)) {
1320 printk(KERN_ERR "%s: can't allocate DMA%d\n",
1321 devc->hw.name, devc->hw.dma2);
1322 goto uninstall_dma;
1323 }
1324
1325 waveartist_set_ctlr(&devc->hw, 0, DMA1_IE | DMA0_IE);
1326
1327 audio_devs[my_dev]->mixer_dev =
1328 sound_install_mixer(MIXER_DRIVER_VERSION,
1329 dev_name,
1330 &waveartist_mixer_operations,
1331 sizeof(struct mixer_operations),
1332 devc);
1333
1334 return my_dev;
1335
1336uninstall_dma:
1337 sound_free_dma(devc->hw.dma);
1338
1339uninstall_irq:
1340 free_irq(devc->hw.irq, devc);
1341
1342uninstall:
1343 sound_unload_audiodev(my_dev);
1344
1345free:
1346 kfree(portc);
1347
1348nomem:
1349 return -1;
1350}
1351
1352static int __init probe_waveartist(struct address_info *hw_config)
1353{
1354 struct wavnc_info *devc = &adev_info[nr_waveartist_devs];
1355
1356 if (nr_waveartist_devs >= MAX_AUDIO_DEV) {
1357 printk(KERN_WARNING "waveartist: too many audio devices\n");
1358 return 0;
1359 }
1360
1361 if (!request_region(hw_config->io_base, 15, hw_config->name)) {
1362 printk(KERN_WARNING "WaveArtist: I/O port conflict\n");
1363 return 0;
1364 }
1365
1366 if (hw_config->irq > 15 || hw_config->irq < 0) {
1367 release_region(hw_config->io_base, 15);
1368 printk(KERN_WARNING "WaveArtist: Bad IRQ %d\n",
1369 hw_config->irq);
1370 return 0;
1371 }
1372
1373 if (hw_config->dma != 3) {
1374 release_region(hw_config->io_base, 15);
1375 printk(KERN_WARNING "WaveArtist: Bad DMA %d\n",
1376 hw_config->dma);
1377 return 0;
1378 }
1379
1380 hw_config->name = "WaveArtist";
1381 devc->hw = *hw_config;
1382 devc->open_mode = 0;
1383 devc->chip_name = "RWA-010";
1384
1385 return 1;
1386}
1387
1388static void __init
1389attach_waveartist(struct address_info *hw, const struct waveartist_mixer_info *mix)
1390{
1391 struct wavnc_info *devc = &adev_info[nr_waveartist_devs];
1392
1393 /*
1394 * NOTE! If irq < 0, there is another driver which has allocated the
1395 * IRQ so that this driver doesn't need to allocate/deallocate it.
1396 * The actually used IRQ is ABS(irq).
1397 */
1398 devc->hw = *hw;
1399 devc->hw.irq = (hw->irq > 0) ? hw->irq : 0;
1400 devc->open_mode = 0;
1401 devc->playback_dev = 0;
1402 devc->record_dev = 0;
1403 devc->audio_flags = DMA_AUTOMODE;
1404 devc->levels = levels;
1405
1406 if (hw->dma != hw->dma2 && hw->dma2 != NO_DMA)
1407 devc->audio_flags |= DMA_DUPLEX;
1408
1409 devc->mix = mix;
1410 devc->dev_no = waveartist_init(devc);
1411
1412 if (devc->dev_no < 0)
1413 release_region(hw->io_base, 15);
1414 else {
1415#ifdef CONFIG_ARCH_NETWINDER
1416 if (machine_is_netwinder()) {
1417 setup_timer(&vnc_timer, vnc_slider_tick,
1418 nr_waveartist_devs);
1419 mod_timer(&vnc_timer, jiffies);
1420
1421 vnc_configure_mixer(devc, 0);
1422
1423 devc->no_autoselect = 1;
1424 }
1425#endif
1426 nr_waveartist_devs += 1;
1427 }
1428}
1429
1430static void __exit unload_waveartist(struct address_info *hw)
1431{
1432 struct wavnc_info *devc = NULL;
1433 int i;
1434
1435 for (i = 0; i < nr_waveartist_devs; i++)
1436 if (hw->io_base == adev_info[i].hw.io_base) {
1437 devc = adev_info + i;
1438 break;
1439 }
1440
1441 if (devc != NULL) {
1442 int mixer;
1443
1444#ifdef CONFIG_ARCH_NETWINDER
1445 if (machine_is_netwinder())
1446 del_timer(&vnc_timer);
1447#endif
1448
1449 release_region(devc->hw.io_base, 15);
1450
1451 waveartist_set_ctlr(&devc->hw, DMA1_IE|DMA0_IE, 0);
1452
1453 if (devc->hw.irq >= 0)
1454 free_irq(devc->hw.irq, devc);
1455
1456 sound_free_dma(devc->hw.dma);
1457
1458 if (devc->hw.dma != devc->hw.dma2 &&
1459 devc->hw.dma2 != NO_DMA)
1460 sound_free_dma(devc->hw.dma2);
1461
1462 mixer = audio_devs[devc->dev_no]->mixer_dev;
1463
1464 if (mixer >= 0)
1465 sound_unload_mixerdev(mixer);
1466
1467 if (devc->dev_no >= 0)
1468 sound_unload_audiodev(devc->dev_no);
1469
1470 nr_waveartist_devs -= 1;
1471
1472 for (; i < nr_waveartist_devs; i++)
1473 adev_info[i] = adev_info[i + 1];
1474 } else
1475 printk(KERN_WARNING "waveartist: can't find device "
1476 "to unload\n");
1477}
1478
1479#ifdef CONFIG_ARCH_NETWINDER
1480
1481/*
1482 * Rebel.com Netwinder specifics...
1483 */
1484
1485#include <asm/hardware/dec21285.h>
1486
1487#define VNC_TIMER_PERIOD (HZ/4) //check slider 4 times/sec
1488
1489#define MIXER_PRIVATE3_RESET 0x53570000
1490#define MIXER_PRIVATE3_READ 0x53570001
1491#define MIXER_PRIVATE3_WRITE 0x53570002
1492
1493#define VNC_MUTE_INTERNAL_SPKR 0x01 //the sw mute on/off control bit
1494#define VNC_MUTE_LINE_OUT 0x10
1495#define VNC_PHONE_DETECT 0x20
1496#define VNC_HANDSET_DETECT 0x40
1497#define VNC_DISABLE_AUTOSWITCH 0x80
1498
1499static inline void
1500vnc_mute_spkr(struct wavnc_info *devc)
1501{
1502 unsigned long flags;
1503
1504 raw_spin_lock_irqsave(&nw_gpio_lock, flags);
1505 nw_cpld_modify(CPLD_UNMUTE, devc->spkr_mute_state ? 0 : CPLD_UNMUTE);
1506 raw_spin_unlock_irqrestore(&nw_gpio_lock, flags);
1507}
1508
1509static void
1510vnc_mute_lout(struct wavnc_info *devc)
1511{
1512 unsigned int left, right;
1513
1514 left = waveartist_cmd1_r(devc, WACMD_GET_LEVEL);
1515 right = waveartist_cmd1_r(devc, WACMD_GET_LEVEL | 0x400);
1516
1517 if (devc->line_mute_state) {
1518 left &= ~1;
1519 right &= ~1;
1520 } else {
1521 left |= 1;
1522 right |= 1;
1523 }
1524 waveartist_cmd3(devc, WACMD_SET_MIXER, left, right);
1525
1526}
1527
1528static int
1529vnc_volume_slider(struct wavnc_info *devc)
1530{
1531 static signed int old_slider_volume;
1532 unsigned long flags;
1533 signed int volume = 255;
1534
1535 *CSR_TIMER1_LOAD = 0x00ffffff;
1536
1537 spin_lock_irqsave(&waveartist_lock, flags);
1538
1539 outb(0xFF, 0x201);
1540 *CSR_TIMER1_CNTL = TIMER_CNTL_ENABLE | TIMER_CNTL_DIV1;
1541
1542 while (volume && (inb(0x201) & 0x01))
1543 volume--;
1544
1545 *CSR_TIMER1_CNTL = 0;
1546
1547 spin_unlock_irqrestore(&waveartist_lock,flags);
1548
1549 volume = 0x00ffffff - *CSR_TIMER1_VALUE;
1550
1551
1552#ifndef REVERSE
1553 volume = 150 - (volume >> 5);
1554#else
1555 volume = (volume >> 6) - 25;
1556#endif
1557
1558 if (volume < 0)
1559 volume = 0;
1560
1561 if (volume > 100)
1562 volume = 100;
1563
1564 /*
1565 * slider quite often reads +-8, so debounce this random noise
1566 */
1567 if (abs(volume - old_slider_volume) > 7) {
1568 old_slider_volume = volume;
1569
1570 if (debug_flg & DEBUG_MIXER)
1571 printk(KERN_DEBUG "Slider volume: %d.\n", volume);
1572 }
1573
1574 return old_slider_volume;
1575}
1576
1577/*
1578 * Decode a recording mask into a mixer selection on the NetWinder
1579 * as follows:
1580 *
1581 * OSS Source WA Source Actual source
1582 * SOUND_MASK_IMIX Mixer Mixer output (same as AD1848)
1583 * SOUND_MASK_LINE Line Line in
1584 * SOUND_MASK_LINE1 Left Mic Handset
1585 * SOUND_MASK_PHONEIN Left Aux Telephone microphone
1586 * SOUND_MASK_MIC Right Mic Builtin microphone
1587 */
1588static unsigned int
1589netwinder_select_input(struct wavnc_info *devc, unsigned int recmask,
1590 unsigned char *dev_l, unsigned char *dev_r)
1591{
1592 unsigned int recdev_l = ADC_MUX_NONE, recdev_r = ADC_MUX_NONE;
1593
1594 if (recmask & SOUND_MASK_IMIX) {
1595 recmask = SOUND_MASK_IMIX;
1596 recdev_l = ADC_MUX_MIXER;
1597 recdev_r = ADC_MUX_MIXER;
1598 } else if (recmask & SOUND_MASK_LINE) {
1599 recmask = SOUND_MASK_LINE;
1600 recdev_l = ADC_MUX_LINE;
1601 recdev_r = ADC_MUX_LINE;
1602 } else if (recmask & SOUND_MASK_LINE1) {
1603 recmask = SOUND_MASK_LINE1;
1604 waveartist_cmd1(devc, WACMD_SET_MONO); /* left */
1605 recdev_l = ADC_MUX_MIC;
1606 recdev_r = ADC_MUX_NONE;
1607 } else if (recmask & SOUND_MASK_PHONEIN) {
1608 recmask = SOUND_MASK_PHONEIN;
1609 waveartist_cmd1(devc, WACMD_SET_MONO); /* left */
1610 recdev_l = ADC_MUX_AUX1;
1611 recdev_r = ADC_MUX_NONE;
1612 } else if (recmask & SOUND_MASK_MIC) {
1613 recmask = SOUND_MASK_MIC;
1614 waveartist_cmd1(devc, WACMD_SET_MONO | 0x100); /* right */
1615 recdev_l = ADC_MUX_NONE;
1616 recdev_r = ADC_MUX_MIC;
1617 }
1618
1619 *dev_l = recdev_l;
1620 *dev_r = recdev_r;
1621
1622 return recmask;
1623}
1624
1625static int
1626netwinder_decode_mixer(struct wavnc_info *devc, int dev, unsigned char lev_l,
1627 unsigned char lev_r)
1628{
1629 switch (dev) {
1630 case SOUND_MIXER_VOLUME:
1631 case SOUND_MIXER_SYNTH:
1632 case SOUND_MIXER_PCM:
1633 case SOUND_MIXER_LINE:
1634 case SOUND_MIXER_IGAIN:
1635 devc->levels[dev] = lev_l | lev_r << 8;
1636 break;
1637
1638 case SOUND_MIXER_MIC: /* right mic only */
1639 devc->levels[SOUND_MIXER_MIC] &= 0xff;
1640 devc->levels[SOUND_MIXER_MIC] |= lev_l << 8;
1641 break;
1642
1643 case SOUND_MIXER_LINE1: /* left mic only */
1644 devc->levels[SOUND_MIXER_MIC] &= 0xff00;
1645 devc->levels[SOUND_MIXER_MIC] |= lev_l;
1646 dev = SOUND_MIXER_MIC;
1647 break;
1648
1649 case SOUND_MIXER_PHONEIN: /* left aux only */
1650 devc->levels[SOUND_MIXER_LINE1] = lev_l;
1651 dev = SOUND_MIXER_LINE1;
1652 break;
1653
1654 case SOUND_MIXER_IMIX:
1655 case SOUND_MIXER_PHONEOUT:
1656 break;
1657
1658 default:
1659 dev = -EINVAL;
1660 break;
1661 }
1662 return dev;
1663}
1664
1665static int netwinder_get_mixer(struct wavnc_info *devc, int dev)
1666{
1667 int levels;
1668
1669 switch (dev) {
1670 case SOUND_MIXER_VOLUME:
1671 case SOUND_MIXER_SYNTH:
1672 case SOUND_MIXER_PCM:
1673 case SOUND_MIXER_LINE:
1674 case SOUND_MIXER_IGAIN:
1675 levels = devc->levels[dev];
1676 break;
1677
1678 case SOUND_MIXER_MIC: /* builtin mic: right mic only */
1679 levels = devc->levels[SOUND_MIXER_MIC] >> 8;
1680 levels |= levels << 8;
1681 break;
1682
1683 case SOUND_MIXER_LINE1: /* handset mic: left mic only */
1684 levels = devc->levels[SOUND_MIXER_MIC] & 0xff;
1685 levels |= levels << 8;
1686 break;
1687
1688 case SOUND_MIXER_PHONEIN: /* phone mic: left aux1 only */
1689 levels = devc->levels[SOUND_MIXER_LINE1] & 0xff;
1690 levels |= levels << 8;
1691 break;
1692
1693 default:
1694 levels = 0;
1695 }
1696
1697 return levels;
1698}
1699
1700/*
1701 * Waveartist specific mixer information.
1702 */
1703static const struct waveartist_mixer_info netwinder_mixer = {
1704 .supported_devs = SOUND_MASK_VOLUME | SOUND_MASK_SYNTH |
1705 SOUND_MASK_PCM | SOUND_MASK_SPEAKER |
1706 SOUND_MASK_LINE | SOUND_MASK_MIC |
1707 SOUND_MASK_IMIX | SOUND_MASK_LINE1 |
1708 SOUND_MASK_PHONEIN | SOUND_MASK_PHONEOUT|
1709 SOUND_MASK_IGAIN,
1710
1711 .recording_devs = SOUND_MASK_LINE | SOUND_MASK_MIC |
1712 SOUND_MASK_IMIX | SOUND_MASK_LINE1 |
1713 SOUND_MASK_PHONEIN,
1714
1715 .stereo_devs = SOUND_MASK_VOLUME | SOUND_MASK_SYNTH |
1716 SOUND_MASK_PCM | SOUND_MASK_LINE |
1717 SOUND_MASK_IMIX | SOUND_MASK_IGAIN,
1718
1719 .select_input = netwinder_select_input,
1720 .decode_mixer = netwinder_decode_mixer,
1721 .get_mixer = netwinder_get_mixer,
1722};
1723
1724static void
1725vnc_configure_mixer(struct wavnc_info *devc, unsigned int recmask)
1726{
1727 if (!devc->no_autoselect) {
1728 if (devc->handset_detect) {
1729 recmask = SOUND_MASK_LINE1;
1730 devc->spkr_mute_state = devc->line_mute_state = 1;
1731 } else if (devc->telephone_detect) {
1732 recmask = SOUND_MASK_PHONEIN;
1733 devc->spkr_mute_state = devc->line_mute_state = 1;
1734 } else {
1735 /* unless someone has asked for LINE-IN,
1736 * we default to MIC
1737 */
1738 if ((devc->recmask & SOUND_MASK_LINE) == 0)
1739 devc->recmask = SOUND_MASK_MIC;
1740 devc->spkr_mute_state = devc->line_mute_state = 0;
1741 }
1742 vnc_mute_spkr(devc);
1743 vnc_mute_lout(devc);
1744
1745 if (recmask != devc->recmask)
1746 waveartist_set_recmask(devc, recmask);
1747 }
1748}
1749
1750static int
1751vnc_slider(struct wavnc_info *devc)
1752{
1753 signed int slider_volume;
1754 unsigned int temp, old_hs, old_td;
1755
1756 /*
1757 * read the "buttons" state.
1758 * Bit 4 = 0 means handset present
1759 * Bit 5 = 1 means phone offhook
1760 */
1761 temp = inb(0x201);
1762
1763 old_hs = devc->handset_detect;
1764 old_td = devc->telephone_detect;
1765
1766 devc->handset_detect = !(temp & 0x10);
1767 devc->telephone_detect = !!(temp & 0x20);
1768
1769 if (!devc->no_autoselect &&
1770 (old_hs != devc->handset_detect ||
1771 old_td != devc->telephone_detect))
1772 vnc_configure_mixer(devc, devc->recmask);
1773
1774 slider_volume = vnc_volume_slider(devc);
1775
1776 /*
1777 * If we're using software controlled volume, and
1778 * the slider moves by more than 20%, then we
1779 * switch back to slider controlled volume.
1780 */
1781 if (abs(devc->slider_vol - slider_volume) > 20)
1782 devc->use_slider = 1;
1783
1784 /*
1785 * use only left channel
1786 */
1787 temp = levels[SOUND_MIXER_VOLUME] & 0xFF;
1788
1789 if (slider_volume != temp && devc->use_slider) {
1790 devc->slider_vol = slider_volume;
1791
1792 waveartist_set_mixer(devc, SOUND_MIXER_VOLUME,
1793 slider_volume | slider_volume << 8);
1794
1795 return 1;
1796 }
1797
1798 return 0;
1799}
1800
1801static void
1802vnc_slider_tick(unsigned long data)
1803{
1804 int next_timeout;
1805
1806 if (vnc_slider(adev_info + data))
1807 next_timeout = 5; // mixer reported change
1808 else
1809 next_timeout = VNC_TIMER_PERIOD;
1810
1811 mod_timer(&vnc_timer, jiffies + next_timeout);
1812}
1813
1814static int
1815vnc_private_ioctl(int dev, unsigned int cmd, int __user * arg)
1816{
1817 struct wavnc_info *devc = (struct wavnc_info *)audio_devs[dev]->devc;
1818 int val;
1819
1820 switch (cmd) {
1821 case SOUND_MIXER_PRIVATE1:
1822 {
1823 u_int prev_spkr_mute, prev_line_mute, prev_auto_state;
1824 int val;
1825
1826 if (get_user(val, arg))
1827 return -EFAULT;
1828
1829 /* check if parameter is logical */
1830 if (val & ~(VNC_MUTE_INTERNAL_SPKR |
1831 VNC_MUTE_LINE_OUT |
1832 VNC_DISABLE_AUTOSWITCH))
1833 return -EINVAL;
1834
1835 prev_auto_state = devc->no_autoselect;
1836 prev_spkr_mute = devc->spkr_mute_state;
1837 prev_line_mute = devc->line_mute_state;
1838
1839 devc->no_autoselect = (val & VNC_DISABLE_AUTOSWITCH) ? 1 : 0;
1840 devc->spkr_mute_state = (val & VNC_MUTE_INTERNAL_SPKR) ? 1 : 0;
1841 devc->line_mute_state = (val & VNC_MUTE_LINE_OUT) ? 1 : 0;
1842
1843 if (prev_spkr_mute != devc->spkr_mute_state)
1844 vnc_mute_spkr(devc);
1845
1846 if (prev_line_mute != devc->line_mute_state)
1847 vnc_mute_lout(devc);
1848
1849 if (prev_auto_state != devc->no_autoselect)
1850 vnc_configure_mixer(devc, devc->recmask);
1851
1852 return 0;
1853 }
1854
1855 case SOUND_MIXER_PRIVATE2:
1856 if (get_user(val, arg))
1857 return -EFAULT;
1858
1859 switch (val) {
1860#define VNC_SOUND_PAUSE 0x53 //to pause the DSP
1861#define VNC_SOUND_RESUME 0x57 //to unpause the DSP
1862 case VNC_SOUND_PAUSE:
1863 waveartist_cmd1(devc, 0x16);
1864 break;
1865
1866 case VNC_SOUND_RESUME:
1867 waveartist_cmd1(devc, 0x18);
1868 break;
1869
1870 default:
1871 return -EINVAL;
1872 }
1873 return 0;
1874
1875 /* private ioctl to allow bulk access to waveartist */
1876 case SOUND_MIXER_PRIVATE3:
1877 {
1878 unsigned long flags;
1879 int mixer_reg[15], i, val;
1880
1881 if (get_user(val, arg))
1882 return -EFAULT;
1883 if (copy_from_user(mixer_reg, (void *)val, sizeof(mixer_reg)))
1884 return -EFAULT;
1885
1886 switch (mixer_reg[14]) {
1887 case MIXER_PRIVATE3_RESET:
1888 waveartist_mixer_reset(devc);
1889 break;
1890
1891 case MIXER_PRIVATE3_WRITE:
1892 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[0], mixer_reg[4]);
1893 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[1], mixer_reg[5]);
1894 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[2], mixer_reg[6]);
1895 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[3], mixer_reg[7]);
1896 waveartist_cmd3(devc, WACMD_SET_MIXER, mixer_reg[8], mixer_reg[9]);
1897
1898 waveartist_cmd3(devc, WACMD_SET_LEVEL, mixer_reg[10], mixer_reg[11]);
1899 waveartist_cmd3(devc, WACMD_SET_LEVEL, mixer_reg[12], mixer_reg[13]);
1900 break;
1901
1902 case MIXER_PRIVATE3_READ:
1903 spin_lock_irqsave(&waveartist_lock, flags);
1904
1905 for (i = 0x30; i < 14 << 8; i += 1 << 8)
1906 waveartist_cmd(devc, 1, &i, 1, mixer_reg + (i >> 8));
1907
1908 spin_unlock_irqrestore(&waveartist_lock, flags);
1909
1910 if (copy_to_user((void *)val, mixer_reg, sizeof(mixer_reg)))
1911 return -EFAULT;
1912 break;
1913
1914 default:
1915 return -EINVAL;
1916 }
1917 return 0;
1918 }
1919
1920 /* read back the state from PRIVATE1 */
1921 case SOUND_MIXER_PRIVATE4:
1922 val = (devc->spkr_mute_state ? VNC_MUTE_INTERNAL_SPKR : 0) |
1923 (devc->line_mute_state ? VNC_MUTE_LINE_OUT : 0) |
1924 (devc->handset_detect ? VNC_HANDSET_DETECT : 0) |
1925 (devc->telephone_detect ? VNC_PHONE_DETECT : 0) |
1926 (devc->no_autoselect ? VNC_DISABLE_AUTOSWITCH : 0);
1927
1928 return put_user(val, arg) ? -EFAULT : 0;
1929 }
1930
1931 if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
1932 /*
1933 * special case for master volume: if we
1934 * received this call - switch from hw
1935 * volume control to a software volume
1936 * control, till the hw volume is modified
1937 * to signal that user wants to be back in
1938 * hardware...
1939 */
1940 if ((cmd & 0xff) == SOUND_MIXER_VOLUME)
1941 devc->use_slider = 0;
1942
1943 /* speaker output */
1944 if ((cmd & 0xff) == SOUND_MIXER_SPEAKER) {
1945 unsigned int val, l, r;
1946
1947 if (get_user(val, arg))
1948 return -EFAULT;
1949
1950 l = val & 0x7f;
1951 r = (val & 0x7f00) >> 8;
1952 val = (l + r) / 2;
1953 devc->levels[SOUND_MIXER_SPEAKER] = val | (val << 8);
1954 devc->spkr_mute_state = (val <= 50);
1955 vnc_mute_spkr(devc);
1956 return 0;
1957 }
1958 }
1959
1960 return -ENOIOCTLCMD;
1961}
1962
1963#endif
1964
1965static struct address_info cfg;
1966
1967static int attached;
1968
1969static int __initdata io = 0;
1970static int __initdata irq = 0;
1971static int __initdata dma = 0;
1972static int __initdata dma2 = 0;
1973
1974
1975static int __init init_waveartist(void)
1976{
1977 const struct waveartist_mixer_info *mix;
1978
1979 if (!io && machine_is_netwinder()) {
1980 /*
1981 * The NetWinder WaveArtist is at a fixed address.
1982 * If the user does not supply an address, use the
1983 * well-known parameters.
1984 */
1985 io = 0x250;
1986 irq = 12;
1987 dma = 3;
1988 dma2 = 7;
1989 }
1990
1991 mix = &waveartist_mixer;
1992#ifdef CONFIG_ARCH_NETWINDER
1993 if (machine_is_netwinder())
1994 mix = &netwinder_mixer;
1995#endif
1996
1997 cfg.io_base = io;
1998 cfg.irq = irq;
1999 cfg.dma = dma;
2000 cfg.dma2 = dma2;
2001
2002 if (!probe_waveartist(&cfg))
2003 return -ENODEV;
2004
2005 attach_waveartist(&cfg, mix);
2006 attached = 1;
2007
2008 return 0;
2009}
2010
2011static void __exit cleanup_waveartist(void)
2012{
2013 if (attached)
2014 unload_waveartist(&cfg);
2015}
2016
2017module_init(init_waveartist);
2018module_exit(cleanup_waveartist);
2019
2020#ifndef MODULE
2021static int __init setup_waveartist(char *str)
2022{
2023 /* io, irq, dma, dma2 */
2024 int ints[5];
2025
2026 str = get_options(str, ARRAY_SIZE(ints), ints);
2027
2028 io = ints[1];
2029 irq = ints[2];
2030 dma = ints[3];
2031 dma2 = ints[4];
2032
2033 return 1;
2034}
2035__setup("waveartist=", setup_waveartist);
2036#endif
2037
2038MODULE_DESCRIPTION("Rockwell WaveArtist RWA-010 sound driver");
2039module_param_hw(io, int, ioport, 0); /* IO base */
2040module_param_hw(irq, int, irq, 0); /* IRQ */
2041module_param_hw(dma, int, dma, 0); /* DMA */
2042module_param_hw(dma2, int, dma, 0); /* DMA2 */
2043MODULE_LICENSE("GPL");
diff --git a/sound/oss/waveartist.h b/sound/oss/waveartist.h
deleted file mode 100644
index f18d74b26483..000000000000
--- a/sound/oss/waveartist.h
+++ /dev/null
@@ -1,93 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * linux/sound/oss/waveartist.h
4 *
5 * def file for Rockwell RWA010 chip set, as installed in Rebel.com NetWinder
6 */
7
8//registers
9#define CMDR 0
10#define DATR 2
11#define CTLR 4
12#define STATR 5
13#define IRQSTAT 12
14
15//bit defs
16//reg STATR
17#define CMD_WE 0x80
18#define CMD_RF 0x40
19#define DAT_WE 0x20
20#define DAT_RF 0x10
21
22#define IRQ_REQ 0x08
23#define DMA1 0x04
24#define DMA0 0x02
25
26//bit defs
27//reg CTLR
28#define CMD_WEIE 0x80
29#define CMD_RFIE 0x40
30#define DAT_WEIE 0x20
31#define DAT_RFIE 0x10
32
33#define RESET 0x08
34#define DMA1_IE 0x04
35#define DMA0_IE 0x02
36#define IRQ_ACK 0x01
37
38//commands
39
40#define WACMD_SYSTEMID 0x00
41#define WACMD_GETREV 0x00
42#define WACMD_INPUTFORMAT 0x10 //0-8S, 1-16S, 2-8U
43#define WACMD_INPUTCHANNELS 0x11 //1-Mono, 2-Stereo
44#define WACMD_INPUTSPEED 0x12 //sampling rate
45#define WACMD_INPUTDMA 0x13 //0-8bit, 1-16bit, 2-PIO
46#define WACMD_INPUTSIZE 0x14 //samples to interrupt
47#define WACMD_INPUTSTART 0x15 //start ADC
48#define WACMD_INPUTPAUSE 0x16 //pause ADC
49#define WACMD_INPUTSTOP 0x17 //stop ADC
50#define WACMD_INPUTRESUME 0x18 //resume ADC
51#define WACMD_INPUTPIO 0x19 //PIO ADC
52
53#define WACMD_OUTPUTFORMAT 0x20 //0-8S, 1-16S, 2-8U
54#define WACMD_OUTPUTCHANNELS 0x21 //1-Mono, 2-Stereo
55#define WACMD_OUTPUTSPEED 0x22 //sampling rate
56#define WACMD_OUTPUTDMA 0x23 //0-8bit, 1-16bit, 2-PIO
57#define WACMD_OUTPUTSIZE 0x24 //samples to interrupt
58#define WACMD_OUTPUTSTART 0x25 //start ADC
59#define WACMD_OUTPUTPAUSE 0x26 //pause ADC
60#define WACMD_OUTPUTSTOP 0x27 //stop ADC
61#define WACMD_OUTPUTRESUME 0x28 //resume ADC
62#define WACMD_OUTPUTPIO 0x29 //PIO ADC
63
64#define WACMD_GET_LEVEL 0x30
65#define WACMD_SET_LEVEL 0x31
66#define WACMD_SET_MIXER 0x32
67#define WACMD_RST_MIXER 0x33
68#define WACMD_SET_MONO 0x34
69
70/*
71 * Definitions for left/right recording input mux
72 */
73#define ADC_MUX_NONE 0
74#define ADC_MUX_MIXER 1
75#define ADC_MUX_LINE 2
76#define ADC_MUX_AUX2 3
77#define ADC_MUX_AUX1 4
78#define ADC_MUX_MIC 5
79
80/*
81 * Definitions for mixer gain settings
82 */
83#define MIX_GAIN_LINE 0 /* line in */
84#define MIX_GAIN_AUX1 1 /* aux1 */
85#define MIX_GAIN_AUX2 2 /* aux2 */
86#define MIX_GAIN_XMIC 3 /* crossover mic */
87#define MIX_GAIN_MIC 4 /* normal mic */
88#define MIX_GAIN_PREMIC 5 /* preamp mic */
89#define MIX_GAIN_OUT 6 /* output */
90#define MIX_GAIN_MONO 7 /* mono in */
91
92int wa_sendcmd(unsigned int cmd);
93int wa_writecmd(unsigned int cmd, unsigned int arg);
diff --git a/sound/pci/asihpi/asihpi.c b/sound/pci/asihpi/asihpi.c
index 70d023a85bf5..720361455c60 100644
--- a/sound/pci/asihpi/asihpi.c
+++ b/sound/pci/asihpi/asihpi.c
@@ -573,10 +573,8 @@ static void snd_card_asihpi_pcm_int_start(struct snd_pcm_substream *substream)
573 573
574static void snd_card_asihpi_pcm_int_stop(struct snd_pcm_substream *substream) 574static void snd_card_asihpi_pcm_int_stop(struct snd_pcm_substream *substream)
575{ 575{
576 struct snd_card_asihpi_pcm *dpcm;
577 struct snd_card_asihpi *card; 576 struct snd_card_asihpi *card;
578 577
579 dpcm = (struct snd_card_asihpi_pcm *)substream->runtime->private_data;
580 card = snd_pcm_substream_chip(substream); 578 card = snd_pcm_substream_chip(substream);
581 579
582 hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index, 580 hpi_handle_error(hpi_adapter_set_property(card->hpi->adapter->index,
@@ -749,9 +747,9 @@ static inline unsigned int modulo_min(unsigned int a, unsigned int b,
749 747
750/** Timer function, equivalent to interrupt service routine for cards 748/** Timer function, equivalent to interrupt service routine for cards
751*/ 749*/
752static void snd_card_asihpi_timer_function(unsigned long data) 750static void snd_card_asihpi_timer_function(struct timer_list *t)
753{ 751{
754 struct snd_card_asihpi_pcm *dpcm = (struct snd_card_asihpi_pcm *)data; 752 struct snd_card_asihpi_pcm *dpcm = from_timer(dpcm, t, timer);
755 struct snd_pcm_substream *substream = dpcm->substream; 753 struct snd_pcm_substream *substream = dpcm->substream;
756 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream); 754 struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
757 struct snd_pcm_runtime *runtime; 755 struct snd_pcm_runtime *runtime;
@@ -863,7 +861,6 @@ static void snd_card_asihpi_timer_function(unsigned long data)
863 861
864 snd_pcm_group_for_each_entry(s, substream) { 862 snd_pcm_group_for_each_entry(s, substream) {
865 struct snd_card_asihpi_pcm *ds = s->runtime->private_data; 863 struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
866 runtime = s->runtime;
867 864
868 /* don't link Cap and Play */ 865 /* don't link Cap and Play */
869 if (substream->stream != s->stream) 866 if (substream->stream != s->stream)
@@ -948,7 +945,7 @@ static void snd_card_asihpi_int_task(unsigned long data)
948 asihpi = (struct snd_card_asihpi *)a->snd_card->private_data; 945 asihpi = (struct snd_card_asihpi *)a->snd_card->private_data;
949 if (asihpi->llmode_streampriv) 946 if (asihpi->llmode_streampriv)
950 snd_card_asihpi_timer_function( 947 snd_card_asihpi_timer_function(
951 (unsigned long)asihpi->llmode_streampriv); 948 &asihpi->llmode_streampriv->timer);
952} 949}
953 950
954static void snd_card_asihpi_isr(struct hpi_adapter *a) 951static void snd_card_asihpi_isr(struct hpi_adapter *a)
@@ -1059,8 +1056,7 @@ static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)
1059 If internal and other stream playing, can't switch 1056 If internal and other stream playing, can't switch
1060 */ 1057 */
1061 1058
1062 setup_timer(&dpcm->timer, snd_card_asihpi_timer_function, 1059 timer_setup(&dpcm->timer, snd_card_asihpi_timer_function, 0);
1063 (unsigned long) dpcm);
1064 dpcm->substream = substream; 1060 dpcm->substream = substream;
1065 runtime->private_data = dpcm; 1061 runtime->private_data = dpcm;
1066 runtime->private_free = snd_card_asihpi_runtime_free; 1062 runtime->private_free = snd_card_asihpi_runtime_free;
@@ -1240,8 +1236,7 @@ static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)
1240 if (err) 1236 if (err)
1241 return -EIO; 1237 return -EIO;
1242 1238
1243 setup_timer(&dpcm->timer, snd_card_asihpi_timer_function, 1239 timer_setup(&dpcm->timer, snd_card_asihpi_timer_function, 0);
1244 (unsigned long) dpcm);
1245 dpcm->substream = substream; 1240 dpcm->substream = substream;
1246 runtime->private_data = dpcm; 1241 runtime->private_data = dpcm;
1247 runtime->private_free = snd_card_asihpi_runtime_free; 1242 runtime->private_free = snd_card_asihpi_runtime_free;
diff --git a/sound/pci/au88x0/au88x0_core.c b/sound/pci/au88x0/au88x0_core.c
index c308a4f70550..4083c8b01619 100644
--- a/sound/pci/au88x0/au88x0_core.c
+++ b/sound/pci/au88x0/au88x0_core.c
@@ -2628,7 +2628,7 @@ static void vortex_spdif_init(vortex_t * vortex, int spdif_sr, int spdif_mode)
2628 else 2628 else
2629 edi = 0x1ffff; 2629 edi = 0x1ffff;
2630 } else { 2630 } else {
2631 i = edi = 0x800; 2631 edi = 0x800;
2632 } 2632 }
2633 /* this_04 and this_08 are the CASp4Src's (samplerate converters) */ 2633 /* this_04 and this_08 are the CASp4Src's (samplerate converters) */
2634 vortex_src_setupchannel(vortex, this_04, edi, 0, 1, 2634 vortex_src_setupchannel(vortex, this_04, edi, 0, 1,
diff --git a/sound/pci/ctxfi/cttimer.c b/sound/pci/ctxfi/cttimer.c
index 8f945341720b..08e874e9a7f6 100644
--- a/sound/pci/ctxfi/cttimer.c
+++ b/sound/pci/ctxfi/cttimer.c
@@ -63,9 +63,9 @@ struct ct_timer {
63 * system-timer-based updates 63 * system-timer-based updates
64 */ 64 */
65 65
66static void ct_systimer_callback(unsigned long data) 66static void ct_systimer_callback(struct timer_list *t)
67{ 67{
68 struct ct_timer_instance *ti = (struct ct_timer_instance *)data; 68 struct ct_timer_instance *ti = from_timer(ti, t, timer);
69 struct snd_pcm_substream *substream = ti->substream; 69 struct snd_pcm_substream *substream = ti->substream;
70 struct snd_pcm_runtime *runtime = substream->runtime; 70 struct snd_pcm_runtime *runtime = substream->runtime;
71 struct ct_atc_pcm *apcm = ti->apcm; 71 struct ct_atc_pcm *apcm = ti->apcm;
@@ -93,8 +93,7 @@ static void ct_systimer_callback(unsigned long data)
93 93
94static void ct_systimer_init(struct ct_timer_instance *ti) 94static void ct_systimer_init(struct ct_timer_instance *ti)
95{ 95{
96 setup_timer(&ti->timer, ct_systimer_callback, 96 timer_setup(&ti->timer, ct_systimer_callback, 0);
97 (unsigned long)ti);
98} 97}
99 98
100static void ct_systimer_start(struct ct_timer_instance *ti) 99static void ct_systimer_start(struct ct_timer_instance *ti)
diff --git a/sound/pci/echoaudio/midi.c b/sound/pci/echoaudio/midi.c
index 8c685ddb1a41..6045a115cffe 100644
--- a/sound/pci/echoaudio/midi.c
+++ b/sound/pci/echoaudio/midi.c
@@ -199,9 +199,9 @@ static int snd_echo_midi_output_open(struct snd_rawmidi_substream *substream)
199 199
200 200
201 201
202static void snd_echo_midi_output_write(unsigned long data) 202static void snd_echo_midi_output_write(struct timer_list *t)
203{ 203{
204 struct echoaudio *chip = (struct echoaudio *)data; 204 struct echoaudio *chip = from_timer(chip, t, timer);
205 unsigned long flags; 205 unsigned long flags;
206 int bytes, sent, time; 206 int bytes, sent, time;
207 unsigned char buf[MIDI_OUT_BUFFER_SIZE - 1]; 207 unsigned char buf[MIDI_OUT_BUFFER_SIZE - 1];
@@ -257,8 +257,8 @@ static void snd_echo_midi_output_trigger(struct snd_rawmidi_substream *substream
257 spin_lock_irq(&chip->lock); 257 spin_lock_irq(&chip->lock);
258 if (up) { 258 if (up) {
259 if (!chip->tinuse) { 259 if (!chip->tinuse) {
260 setup_timer(&chip->timer, snd_echo_midi_output_write, 260 timer_setup(&chip->timer, snd_echo_midi_output_write,
261 (unsigned long)chip); 261 0);
262 chip->tinuse = 1; 262 chip->tinuse = 1;
263 } 263 }
264 } else { 264 } else {
@@ -273,7 +273,7 @@ static void snd_echo_midi_output_trigger(struct snd_rawmidi_substream *substream
273 spin_unlock_irq(&chip->lock); 273 spin_unlock_irq(&chip->lock);
274 274
275 if (up && !chip->midi_full) 275 if (up && !chip->midi_full)
276 snd_echo_midi_output_write((unsigned long)chip); 276 snd_echo_midi_output_write(&chip->timer);
277} 277}
278 278
279 279
diff --git a/sound/pci/emu10k1/emuproc.c b/sound/pci/emu10k1/emuproc.c
index cf05229b569b..bde0d1954f56 100644
--- a/sound/pci/emu10k1/emuproc.c
+++ b/sound/pci/emu10k1/emuproc.c
@@ -280,7 +280,6 @@ static void snd_emu10k1_proc_rates_read(struct snd_info_entry *entry,
280 struct snd_emu10k1 *emu = entry->private_data; 280 struct snd_emu10k1 *emu = entry->private_data;
281 unsigned int val, tmp, n; 281 unsigned int val, tmp, n;
282 val = snd_emu10k1_ptr20_read(emu, CAPTURE_RATE_STATUS, 0); 282 val = snd_emu10k1_ptr20_read(emu, CAPTURE_RATE_STATUS, 0);
283 tmp = (val >> 16) & 0x8;
284 for (n = 0; n < 4; n++) { 283 for (n = 0; n < 4; n++) {
285 tmp = val >> (16 + (n*4)); 284 tmp = val >> (16 + (n*4));
286 if (tmp & 0x8) snd_iprintf(buffer, "Channel %d: Rate=%d\n", n, samplerate[tmp & 0x7]); 285 if (tmp & 0x8) snd_iprintf(buffer, "Channel %d: Rate=%d\n", n, samplerate[tmp & 0x7]);
diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c
index d4cd6451fdca..39f79a6b5283 100644
--- a/sound/pci/ens1370.c
+++ b/sound/pci/ens1370.c
@@ -732,7 +732,7 @@ static void snd_es1371_codec_wait(struct snd_ac97 *ac97)
732 732
733static void snd_es1371_adc_rate(struct ensoniq * ensoniq, unsigned int rate) 733static void snd_es1371_adc_rate(struct ensoniq * ensoniq, unsigned int rate)
734{ 734{
735 unsigned int n, truncm, freq, result; 735 unsigned int n, truncm, freq;
736 736
737 mutex_lock(&ensoniq->src_mutex); 737 mutex_lock(&ensoniq->src_mutex);
738 n = rate / 3000; 738 n = rate / 3000;
@@ -740,7 +740,6 @@ static void snd_es1371_adc_rate(struct ensoniq * ensoniq, unsigned int rate)
740 n--; 740 n--;
741 truncm = (21 * n - 1) | 1; 741 truncm = (21 * n - 1) | 1;
742 freq = ((48000UL << 15) / rate) * n; 742 freq = ((48000UL << 15) / rate) * n;
743 result = (48000UL << 15) / (freq / n);
744 if (rate >= 24000) { 743 if (rate >= 24000) {
745 if (truncm > 239) 744 if (truncm > 239)
746 truncm = 239; 745 truncm = 239;
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index a0989d231fd0..c1f8e5479bf3 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -977,7 +977,7 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec)
977 hda_nid_t fg; 977 hda_nid_t fg;
978 int err; 978 int err;
979 979
980 err = snd_hdac_refresh_widget_sysfs(&codec->core); 980 err = snd_hdac_refresh_widgets(&codec->core, true);
981 if (err < 0) 981 if (err < 0)
982 return err; 982 return err;
983 983
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index 28e265a88383..5cc65093d941 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -795,6 +795,8 @@ static void activate_amp_in(struct hda_codec *codec, struct nid_path *path,
795 hda_nid_t nid = path->path[i]; 795 hda_nid_t nid = path->path[i];
796 796
797 nums = snd_hda_get_conn_list(codec, nid, &conn); 797 nums = snd_hda_get_conn_list(codec, nid, &conn);
798 if (nums < 0)
799 return;
798 type = get_wcaps_type(get_wcaps(codec, nid)); 800 type = get_wcaps_type(get_wcaps(codec, nid));
799 if (type == AC_WID_PIN || 801 if (type == AC_WID_PIN ||
800 (type == AC_WID_AUD_IN && codec->single_adc_amp)) { 802 (type == AC_WID_AUD_IN && codec->single_adc_amp)) {
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 3e73d5c6ccfc..768ea8651993 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -27,6 +27,7 @@
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/firmware.h> 29#include <linux/firmware.h>
30#include <linux/kernel.h>
30#include <sound/core.h> 31#include <sound/core.h>
31#include "hda_codec.h" 32#include "hda_codec.h"
32#include "hda_local.h" 33#include "hda_local.h"
@@ -3605,8 +3606,7 @@ static int ca0132_vnode_switch_set(struct snd_kcontrol *kcontrol,
3605static int ca0132_voicefx_info(struct snd_kcontrol *kcontrol, 3606static int ca0132_voicefx_info(struct snd_kcontrol *kcontrol,
3606 struct snd_ctl_elem_info *uinfo) 3607 struct snd_ctl_elem_info *uinfo)
3607{ 3608{
3608 unsigned int items = sizeof(ca0132_voicefx_presets) 3609 unsigned int items = ARRAY_SIZE(ca0132_voicefx_presets);
3609 / sizeof(struct ct_voicefx_preset);
3610 3610
3611 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 3611 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3612 uinfo->count = 1; 3612 uinfo->count = 1;
@@ -3635,10 +3635,8 @@ static int ca0132_voicefx_put(struct snd_kcontrol *kcontrol,
3635 struct ca0132_spec *spec = codec->spec; 3635 struct ca0132_spec *spec = codec->spec;
3636 int i, err = 0; 3636 int i, err = 0;
3637 int sel = ucontrol->value.enumerated.item[0]; 3637 int sel = ucontrol->value.enumerated.item[0];
3638 unsigned int items = sizeof(ca0132_voicefx_presets)
3639 / sizeof(struct ct_voicefx_preset);
3640 3638
3641 if (sel >= items) 3639 if (sel >= ARRAY_SIZE(ca0132_voicefx_presets))
3642 return 0; 3640 return 0;
3643 3641
3644 codec_dbg(codec, "ca0132_voicefx_put: sel=%d, preset=%s\n", 3642 codec_dbg(codec, "ca0132_voicefx_put: sel=%d, preset=%s\n",
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index dce0682c5001..db1a376e27c0 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -1803,6 +1803,7 @@ enum {
1803 ALC887_FIXUP_ASUS_BASS, 1803 ALC887_FIXUP_ASUS_BASS,
1804 ALC887_FIXUP_BASS_CHMAP, 1804 ALC887_FIXUP_BASS_CHMAP,
1805 ALC1220_FIXUP_GB_DUAL_CODECS, 1805 ALC1220_FIXUP_GB_DUAL_CODECS,
1806 ALC1220_FIXUP_CLEVO_P950,
1806}; 1807};
1807 1808
1808static void alc889_fixup_coef(struct hda_codec *codec, 1809static void alc889_fixup_coef(struct hda_codec *codec,
@@ -2020,6 +2021,23 @@ static void alc1220_fixup_gb_dual_codecs(struct hda_codec *codec,
2020 } 2021 }
2021} 2022}
2022 2023
2024static void alc1220_fixup_clevo_p950(struct hda_codec *codec,
2025 const struct hda_fixup *fix,
2026 int action)
2027{
2028 hda_nid_t conn1[1] = { 0x0c };
2029
2030 if (action != HDA_FIXUP_ACT_PRE_PROBE)
2031 return;
2032
2033 alc_update_coef_idx(codec, 0x7, 0, 0x3c3);
2034 /* We therefore want to make sure 0x14 (front headphone) and
2035 * 0x1b (speakers) use the stereo DAC 0x02
2036 */
2037 snd_hda_override_conn_list(codec, 0x14, 1, conn1);
2038 snd_hda_override_conn_list(codec, 0x1b, 1, conn1);
2039}
2040
2023static const struct hda_fixup alc882_fixups[] = { 2041static const struct hda_fixup alc882_fixups[] = {
2024 [ALC882_FIXUP_ABIT_AW9D_MAX] = { 2042 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
2025 .type = HDA_FIXUP_PINS, 2043 .type = HDA_FIXUP_PINS,
@@ -2260,6 +2278,10 @@ static const struct hda_fixup alc882_fixups[] = {
2260 .type = HDA_FIXUP_FUNC, 2278 .type = HDA_FIXUP_FUNC,
2261 .v.func = alc1220_fixup_gb_dual_codecs, 2279 .v.func = alc1220_fixup_gb_dual_codecs,
2262 }, 2280 },
2281 [ALC1220_FIXUP_CLEVO_P950] = {
2282 .type = HDA_FIXUP_FUNC,
2283 .v.func = alc1220_fixup_clevo_p950,
2284 },
2263}; 2285};
2264 2286
2265static const struct snd_pci_quirk alc882_fixup_tbl[] = { 2287static const struct snd_pci_quirk alc882_fixup_tbl[] = {
@@ -2333,6 +2355,7 @@ static const struct snd_pci_quirk alc882_fixup_tbl[] = {
2333 SND_PCI_QUIRK(0x1462, 0xda57, "MSI Z270-Gaming", ALC1220_FIXUP_GB_DUAL_CODECS), 2355 SND_PCI_QUIRK(0x1462, 0xda57, "MSI Z270-Gaming", ALC1220_FIXUP_GB_DUAL_CODECS),
2334 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3), 2356 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
2335 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX), 2357 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
2358 SND_PCI_QUIRK(0x1558, 0x9501, "Clevo P950HR", ALC1220_FIXUP_CLEVO_P950),
2336 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD), 2359 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
2337 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD), 2360 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
2338 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530), 2361 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
@@ -6366,6 +6389,7 @@ static const struct hda_model_fixup alc269_fixup_models[] = {
6366 {.id = ALC292_FIXUP_TPT440, .name = "tpt440"}, 6389 {.id = ALC292_FIXUP_TPT440, .name = "tpt440"},
6367 {.id = ALC292_FIXUP_TPT460, .name = "tpt460"}, 6390 {.id = ALC292_FIXUP_TPT460, .name = "tpt460"},
6368 {.id = ALC233_FIXUP_LENOVO_MULTI_CODECS, .name = "dual-codecs"}, 6391 {.id = ALC233_FIXUP_LENOVO_MULTI_CODECS, .name = "dual-codecs"},
6392 {.id = ALC700_FIXUP_INTEL_REFERENCE, .name = "alc700-ref"},
6369 {} 6393 {}
6370}; 6394};
6371#define ALC225_STANDARD_PINS \ 6395#define ALC225_STANDARD_PINS \
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index 0e66afa403a3..f1fe497c2f9d 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -2285,7 +2285,7 @@ static unsigned char snd_ice1712_read_i2c(struct snd_ice1712 *ice,
2285static int snd_ice1712_read_eeprom(struct snd_ice1712 *ice, 2285static int snd_ice1712_read_eeprom(struct snd_ice1712 *ice,
2286 const char *modelname) 2286 const char *modelname)
2287{ 2287{
2288 int dev = 0xa0; /* EEPROM device address */ 2288 int dev = ICE_I2C_EEPROM_ADDR; /* I2C EEPROM device address */
2289 unsigned int i, size; 2289 unsigned int i, size;
2290 struct snd_ice1712_card_info * const *tbl, *c; 2290 struct snd_ice1712_card_info * const *tbl, *c;
2291 2291
diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
index 5cfba09c9761..8ae8742662a5 100644
--- a/sound/pci/ice1712/ice1712.h
+++ b/sound/pci/ice1712/ice1712.h
@@ -218,8 +218,9 @@
218 218
219 219
220/* 220/*
221 * 221 * I2C EEPROM Address
222 */ 222 */
223#define ICE_I2C_EEPROM_ADDR 0xA0
223 224
224struct snd_ice1712; 225struct snd_ice1712;
225 226
diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c
index 04cd71c74e5c..c7b007164c99 100644
--- a/sound/pci/korg1212/korg1212.c
+++ b/sound/pci/korg1212/korg1212.c
@@ -599,9 +599,9 @@ static void snd_korg1212_SendStopAndWait(struct snd_korg1212 *korg1212)
599} 599}
600 600
601/* timer callback for checking the ack of stop request */ 601/* timer callback for checking the ack of stop request */
602static void snd_korg1212_timer_func(unsigned long data) 602static void snd_korg1212_timer_func(struct timer_list *t)
603{ 603{
604 struct snd_korg1212 *korg1212 = (struct snd_korg1212 *) data; 604 struct snd_korg1212 *korg1212 = from_timer(korg1212, t, timer);
605 unsigned long flags; 605 unsigned long flags;
606 606
607 spin_lock_irqsave(&korg1212->lock, flags); 607 spin_lock_irqsave(&korg1212->lock, flags);
@@ -2189,8 +2189,7 @@ static int snd_korg1212_create(struct snd_card *card, struct pci_dev *pci,
2189 init_waitqueue_head(&korg1212->wait); 2189 init_waitqueue_head(&korg1212->wait);
2190 spin_lock_init(&korg1212->lock); 2190 spin_lock_init(&korg1212->lock);
2191 mutex_init(&korg1212->open_mutex); 2191 mutex_init(&korg1212->open_mutex);
2192 setup_timer(&korg1212->timer, snd_korg1212_timer_func, 2192 timer_setup(&korg1212->timer, snd_korg1212_timer_func, 0);
2193 (unsigned long)korg1212);
2194 2193
2195 korg1212->irq = -1; 2194 korg1212->irq = -1;
2196 korg1212->clkSource = K1212_CLKIDX_Local; 2195 korg1212->clkSource = K1212_CLKIDX_Local;
diff --git a/sound/pci/oxygen/xonar_dg.h b/sound/pci/oxygen/xonar_dg.h
index 7a1e8f9c48e7..24d97721c247 100644
--- a/sound/pci/oxygen/xonar_dg.h
+++ b/sound/pci/oxygen/xonar_dg.h
@@ -52,6 +52,6 @@ void dg_suspend(struct oxygen *chip);
52void dg_resume(struct oxygen *chip); 52void dg_resume(struct oxygen *chip);
53void dg_cleanup(struct oxygen *chip); 53void dg_cleanup(struct oxygen *chip);
54 54
55extern struct oxygen_model model_xonar_dg; 55extern const struct oxygen_model model_xonar_dg;
56 56
57#endif 57#endif
diff --git a/sound/pci/oxygen/xonar_dg_mixer.c b/sound/pci/oxygen/xonar_dg_mixer.c
index b885dac28a09..d22fbe8aebd0 100644
--- a/sound/pci/oxygen/xonar_dg_mixer.c
+++ b/sound/pci/oxygen/xonar_dg_mixer.c
@@ -449,7 +449,7 @@ static int dg_mixer_init(struct oxygen *chip)
449 return 0; 449 return 0;
450} 450}
451 451
452struct oxygen_model model_xonar_dg = { 452const struct oxygen_model model_xonar_dg = {
453 .longname = "C-Media Oxygen HD Audio", 453 .longname = "C-Media Oxygen HD Audio",
454 .chip = "CMI8786", 454 .chip = "CMI8786",
455 .init = dg_init, 455 .init = dg_init,
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 9f0f73875f01..1bff4b1b39cd 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -1410,9 +1410,9 @@ static void snd_hdsp_midi_input_trigger(struct snd_rawmidi_substream *substream,
1410 spin_unlock_irqrestore (&hdsp->lock, flags); 1410 spin_unlock_irqrestore (&hdsp->lock, flags);
1411} 1411}
1412 1412
1413static void snd_hdsp_midi_output_timer(unsigned long data) 1413static void snd_hdsp_midi_output_timer(struct timer_list *t)
1414{ 1414{
1415 struct hdsp_midi *hmidi = (struct hdsp_midi *) data; 1415 struct hdsp_midi *hmidi = from_timer(hmidi, t, timer);
1416 unsigned long flags; 1416 unsigned long flags;
1417 1417
1418 snd_hdsp_midi_output_write(hmidi); 1418 snd_hdsp_midi_output_write(hmidi);
@@ -1439,8 +1439,8 @@ static void snd_hdsp_midi_output_trigger(struct snd_rawmidi_substream *substream
1439 spin_lock_irqsave (&hmidi->lock, flags); 1439 spin_lock_irqsave (&hmidi->lock, flags);
1440 if (up) { 1440 if (up) {
1441 if (!hmidi->istimer) { 1441 if (!hmidi->istimer) {
1442 setup_timer(&hmidi->timer, snd_hdsp_midi_output_timer, 1442 timer_setup(&hmidi->timer, snd_hdsp_midi_output_timer,
1443 (unsigned long) hmidi); 1443 0);
1444 mod_timer(&hmidi->timer, 1 + jiffies); 1444 mod_timer(&hmidi->timer, 1 + jiffies);
1445 hmidi->istimer++; 1445 hmidi->istimer++;
1446 } 1446 }
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index f20d42714e4d..4c59983158e0 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -1946,9 +1946,9 @@ snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
1946 spin_unlock_irqrestore (&hdspm->lock, flags); 1946 spin_unlock_irqrestore (&hdspm->lock, flags);
1947} 1947}
1948 1948
1949static void snd_hdspm_midi_output_timer(unsigned long data) 1949static void snd_hdspm_midi_output_timer(struct timer_list *t)
1950{ 1950{
1951 struct hdspm_midi *hmidi = (struct hdspm_midi *) data; 1951 struct hdspm_midi *hmidi = from_timer(hmidi, t, timer);
1952 unsigned long flags; 1952 unsigned long flags;
1953 1953
1954 snd_hdspm_midi_output_write(hmidi); 1954 snd_hdspm_midi_output_write(hmidi);
@@ -1976,8 +1976,8 @@ snd_hdspm_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
1976 spin_lock_irqsave (&hmidi->lock, flags); 1976 spin_lock_irqsave (&hmidi->lock, flags);
1977 if (up) { 1977 if (up) {
1978 if (!hmidi->istimer) { 1978 if (!hmidi->istimer) {
1979 setup_timer(&hmidi->timer, snd_hdspm_midi_output_timer, 1979 timer_setup(&hmidi->timer,
1980 (unsigned long) hmidi); 1980 snd_hdspm_midi_output_timer, 0);
1981 mod_timer(&hmidi->timer, 1 + jiffies); 1981 mod_timer(&hmidi->timer, 1 + jiffies);
1982 hmidi->istimer++; 1982 hmidi->istimer++;
1983 } 1983 }
diff --git a/sound/sh/aica.c b/sound/sh/aica.c
index fdc680ae8aa0..2b26311405a4 100644
--- a/sound/sh/aica.c
+++ b/sound/sh/aica.c
@@ -299,14 +299,14 @@ static void run_spu_dma(struct work_struct *work)
299 } 299 }
300} 300}
301 301
302static void aica_period_elapsed(unsigned long timer_var) 302static void aica_period_elapsed(struct timer_list *t)
303{ 303{
304 struct snd_card_aica *dreamcastcard = from_timer(dreamcastcard,
305 t, timer);
306 struct snd_pcm_substream *substream = dreamcastcard->timer_substream;
304 /*timer function - so cannot sleep */ 307 /*timer function - so cannot sleep */
305 int play_period; 308 int play_period;
306 struct snd_pcm_runtime *runtime; 309 struct snd_pcm_runtime *runtime;
307 struct snd_pcm_substream *substream;
308 struct snd_card_aica *dreamcastcard;
309 substream = (struct snd_pcm_substream *) timer_var;
310 runtime = substream->runtime; 310 runtime = substream->runtime;
311 dreamcastcard = substream->pcm->private_data; 311 dreamcastcard = substream->pcm->private_data;
312 /* Have we played out an additional period? */ 312 /* Have we played out an additional period? */
@@ -336,12 +336,12 @@ static void spu_begin_dma(struct snd_pcm_substream *substream)
336 /*get the queue to do the work */ 336 /*get the queue to do the work */
337 schedule_work(&(dreamcastcard->spu_dma_work)); 337 schedule_work(&(dreamcastcard->spu_dma_work));
338 /* Timer may already be running */ 338 /* Timer may already be running */
339 if (unlikely(dreamcastcard->timer.data)) { 339 if (unlikely(dreamcastcard->timer_substream)) {
340 mod_timer(&dreamcastcard->timer, jiffies + 4); 340 mod_timer(&dreamcastcard->timer, jiffies + 4);
341 return; 341 return;
342 } 342 }
343 setup_timer(&dreamcastcard->timer, aica_period_elapsed, 343 timer_setup(&dreamcastcard->timer, aica_period_elapsed, 0);
344 (unsigned long) substream); 344 dreamcastcard->timer_substream = substream;
345 mod_timer(&dreamcastcard->timer, jiffies + 4); 345 mod_timer(&dreamcastcard->timer, jiffies + 4);
346} 346}
347 347
@@ -379,7 +379,7 @@ static int snd_aicapcm_pcm_close(struct snd_pcm_substream
379{ 379{
380 struct snd_card_aica *dreamcastcard = substream->pcm->private_data; 380 struct snd_card_aica *dreamcastcard = substream->pcm->private_data;
381 flush_work(&(dreamcastcard->spu_dma_work)); 381 flush_work(&(dreamcastcard->spu_dma_work));
382 if (dreamcastcard->timer.data) 382 if (dreamcastcard->timer_substream)
383 del_timer(&dreamcastcard->timer); 383 del_timer(&dreamcastcard->timer);
384 kfree(dreamcastcard->channel); 384 kfree(dreamcastcard->channel);
385 spu_disable(); 385 spu_disable();
@@ -600,7 +600,7 @@ static int snd_aica_probe(struct platform_device *devptr)
600{ 600{
601 int err; 601 int err;
602 struct snd_card_aica *dreamcastcard; 602 struct snd_card_aica *dreamcastcard;
603 dreamcastcard = kmalloc(sizeof(struct snd_card_aica), GFP_KERNEL); 603 dreamcastcard = kzalloc(sizeof(struct snd_card_aica), GFP_KERNEL);
604 if (unlikely(!dreamcastcard)) 604 if (unlikely(!dreamcastcard))
605 return -ENOMEM; 605 return -ENOMEM;
606 err = snd_card_new(&devptr->dev, index, SND_AICA_DRIVER, 606 err = snd_card_new(&devptr->dev, index, SND_AICA_DRIVER,
@@ -619,8 +619,6 @@ static int snd_aica_probe(struct platform_device *devptr)
619 err = snd_aicapcmchip(dreamcastcard, 0); 619 err = snd_aicapcmchip(dreamcastcard, 0);
620 if (unlikely(err < 0)) 620 if (unlikely(err < 0))
621 goto freedreamcast; 621 goto freedreamcast;
622 dreamcastcard->timer.data = 0;
623 dreamcastcard->channel = NULL;
624 /* Add basic controls */ 622 /* Add basic controls */
625 err = add_aicamixer_controls(dreamcastcard); 623 err = add_aicamixer_controls(dreamcastcard);
626 if (unlikely(err < 0)) 624 if (unlikely(err < 0))
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig
index c0abad2067e1..d22758165496 100644
--- a/sound/soc/Kconfig
+++ b/sound/soc/Kconfig
@@ -36,6 +36,9 @@ config SND_SOC_COMPRESS
36config SND_SOC_TOPOLOGY 36config SND_SOC_TOPOLOGY
37 bool 37 bool
38 38
39config SND_SOC_ACPI
40 tristate
41
39# All the supported SoCs 42# All the supported SoCs
40source "sound/soc/adi/Kconfig" 43source "sound/soc/adi/Kconfig"
41source "sound/soc/amd/Kconfig" 44source "sound/soc/amd/Kconfig"
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index bf8c1e2ce0bf..5327f4d6c668 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -15,6 +15,12 @@ ifneq ($(CONFIG_SND_SOC_AC97_BUS),)
15snd-soc-core-objs += soc-ac97.o 15snd-soc-core-objs += soc-ac97.o
16endif 16endif
17 17
18ifneq ($(CONFIG_SND_SOC_ACPI),)
19snd-soc-acpi-objs := soc-acpi.o
20endif
21
22obj-$(CONFIG_SND_SOC_ACPI) += snd-soc-acpi.o
23
18obj-$(CONFIG_SND_SOC) += snd-soc-core.o 24obj-$(CONFIG_SND_SOC) += snd-soc-core.o
19obj-$(CONFIG_SND_SOC) += codecs/ 25obj-$(CONFIG_SND_SOC) += codecs/
20obj-$(CONFIG_SND_SOC) += generic/ 26obj-$(CONFIG_SND_SOC) += generic/
diff --git a/sound/soc/amd/Kconfig b/sound/soc/amd/Kconfig
index 78187eb24f56..d5838402f667 100644
--- a/sound/soc/amd/Kconfig
+++ b/sound/soc/amd/Kconfig
@@ -2,3 +2,10 @@ config SND_SOC_AMD_ACP
2 tristate "AMD Audio Coprocessor support" 2 tristate "AMD Audio Coprocessor support"
3 help 3 help
4 This option enables ACP DMA support on AMD platform. 4 This option enables ACP DMA support on AMD platform.
5
6config SND_SOC_AMD_CZ_RT5645_MACH
7 tristate "AMD CZ support for RT5645"
8 select SND_SOC_RT5645
9 depends on SND_SOC_AMD_ACP && I2C
10 help
11 This option enables machine driver for rt5645.
diff --git a/sound/soc/amd/Makefile b/sound/soc/amd/Makefile
index 1a66ec0366b2..f07fd2e2870a 100644
--- a/sound/soc/amd/Makefile
+++ b/sound/soc/amd/Makefile
@@ -1,3 +1,5 @@
1snd-soc-acp-pcm-objs := acp-pcm-dma.o 1acp_audio_dma-objs := acp-pcm-dma.o
2snd-soc-acp-rt5645-mach-objs := acp-rt5645.o
2 3
3obj-$(CONFIG_SND_SOC_AMD_ACP) += snd-soc-acp-pcm.o 4obj-$(CONFIG_SND_SOC_AMD_ACP) += acp_audio_dma.o
5obj-$(CONFIG_SND_SOC_AMD_CZ_RT5645_MACH) += snd-soc-acp-rt5645-mach.o
diff --git a/sound/soc/amd/acp-pcm-dma.c b/sound/soc/amd/acp-pcm-dma.c
index 08b1399d1da2..9f521a55d610 100644
--- a/sound/soc/amd/acp-pcm-dma.c
+++ b/sound/soc/amd/acp-pcm-dma.c
@@ -20,7 +20,7 @@
20#include <linux/pm_runtime.h> 20#include <linux/pm_runtime.h>
21 21
22#include <sound/soc.h> 22#include <sound/soc.h>
23 23#include <drm/amd_asic_type.h>
24#include "acp.h" 24#include "acp.h"
25 25
26#define PLAYBACK_MIN_NUM_PERIODS 2 26#define PLAYBACK_MIN_NUM_PERIODS 2
@@ -35,6 +35,13 @@
35#define MAX_BUFFER (PLAYBACK_MAX_PERIOD_SIZE * PLAYBACK_MAX_NUM_PERIODS) 35#define MAX_BUFFER (PLAYBACK_MAX_PERIOD_SIZE * PLAYBACK_MAX_NUM_PERIODS)
36#define MIN_BUFFER MAX_BUFFER 36#define MIN_BUFFER MAX_BUFFER
37 37
38#define ST_PLAYBACK_MAX_PERIOD_SIZE 8192
39#define ST_CAPTURE_MAX_PERIOD_SIZE ST_PLAYBACK_MAX_PERIOD_SIZE
40#define ST_MAX_BUFFER (ST_PLAYBACK_MAX_PERIOD_SIZE * PLAYBACK_MAX_NUM_PERIODS)
41#define ST_MIN_BUFFER ST_MAX_BUFFER
42
43#define DRV_NAME "acp_audio_dma"
44
38static const struct snd_pcm_hardware acp_pcm_hardware_playback = { 45static const struct snd_pcm_hardware acp_pcm_hardware_playback = {
39 .info = SNDRV_PCM_INFO_INTERLEAVED | 46 .info = SNDRV_PCM_INFO_INTERLEAVED |
40 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP | 47 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP |
@@ -73,10 +80,42 @@ static const struct snd_pcm_hardware acp_pcm_hardware_capture = {
73 .periods_max = CAPTURE_MAX_NUM_PERIODS, 80 .periods_max = CAPTURE_MAX_NUM_PERIODS,
74}; 81};
75 82
76struct audio_drv_data { 83static const struct snd_pcm_hardware acp_st_pcm_hardware_playback = {
77 struct snd_pcm_substream *play_stream; 84 .info = SNDRV_PCM_INFO_INTERLEAVED |
78 struct snd_pcm_substream *capture_stream; 85 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP |
79 void __iomem *acp_mmio; 86 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BATCH |
87 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME,
88 .formats = SNDRV_PCM_FMTBIT_S16_LE |
89 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE,
90 .channels_min = 1,
91 .channels_max = 8,
92 .rates = SNDRV_PCM_RATE_8000_96000,
93 .rate_min = 8000,
94 .rate_max = 96000,
95 .buffer_bytes_max = ST_MAX_BUFFER,
96 .period_bytes_min = PLAYBACK_MIN_PERIOD_SIZE,
97 .period_bytes_max = ST_PLAYBACK_MAX_PERIOD_SIZE,
98 .periods_min = PLAYBACK_MIN_NUM_PERIODS,
99 .periods_max = PLAYBACK_MAX_NUM_PERIODS,
100};
101
102static const struct snd_pcm_hardware acp_st_pcm_hardware_capture = {
103 .info = SNDRV_PCM_INFO_INTERLEAVED |
104 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP |
105 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BATCH |
106 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME,
107 .formats = SNDRV_PCM_FMTBIT_S16_LE |
108 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE,
109 .channels_min = 1,
110 .channels_max = 2,
111 .rates = SNDRV_PCM_RATE_8000_48000,
112 .rate_min = 8000,
113 .rate_max = 48000,
114 .buffer_bytes_max = ST_MAX_BUFFER,
115 .period_bytes_min = CAPTURE_MIN_PERIOD_SIZE,
116 .period_bytes_max = ST_CAPTURE_MAX_PERIOD_SIZE,
117 .periods_min = CAPTURE_MIN_NUM_PERIODS,
118 .periods_max = CAPTURE_MAX_NUM_PERIODS,
80}; 119};
81 120
82static u32 acp_reg_read(void __iomem *acp_mmio, u32 reg) 121static u32 acp_reg_read(void __iomem *acp_mmio, u32 reg)
@@ -143,8 +182,8 @@ static void config_dma_descriptor_in_sram(void __iomem *acp_mmio,
143 * system memory <-> ACP SRAM 182 * system memory <-> ACP SRAM
144 */ 183 */
145static void set_acp_sysmem_dma_descriptors(void __iomem *acp_mmio, 184static void set_acp_sysmem_dma_descriptors(void __iomem *acp_mmio,
146 u32 size, int direction, 185 u32 size, int direction,
147 u32 pte_offset) 186 u32 pte_offset, u32 asic_type)
148{ 187{
149 u16 i; 188 u16 i;
150 u16 dma_dscr_idx = PLAYBACK_START_DMA_DESCR_CH12; 189 u16 dma_dscr_idx = PLAYBACK_START_DMA_DESCR_CH12;
@@ -154,24 +193,46 @@ static void set_acp_sysmem_dma_descriptors(void __iomem *acp_mmio,
154 dmadscr[i].xfer_val = 0; 193 dmadscr[i].xfer_val = 0;
155 if (direction == SNDRV_PCM_STREAM_PLAYBACK) { 194 if (direction == SNDRV_PCM_STREAM_PLAYBACK) {
156 dma_dscr_idx = PLAYBACK_START_DMA_DESCR_CH12 + i; 195 dma_dscr_idx = PLAYBACK_START_DMA_DESCR_CH12 + i;
157 dmadscr[i].dest = ACP_SHARED_RAM_BANK_1_ADDRESS + 196 dmadscr[i].dest = ACP_SHARED_RAM_BANK_1_ADDRESS
158 (size / 2) - (i * (size/2)); 197 + (i * (size/2));
159 dmadscr[i].src = ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS 198 dmadscr[i].src = ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS
160 + (pte_offset * SZ_4K) + (i * (size/2)); 199 + (pte_offset * SZ_4K) + (i * (size/2));
161 dmadscr[i].xfer_val |= 200 switch (asic_type) {
162 (ACP_DMA_ATTRIBUTES_DAGB_ONION_TO_SHAREDMEM << 16) | 201 case CHIP_STONEY:
163 (size / 2); 202 dmadscr[i].xfer_val |=
203 (ACP_DMA_ATTRIBUTES_DAGB_GARLIC_TO_SHAREDMEM << 16) |
204 (size / 2);
205 break;
206 default:
207 dmadscr[i].xfer_val |=
208 (ACP_DMA_ATTRIBUTES_DAGB_ONION_TO_SHAREDMEM << 16) |
209 (size / 2);
210 }
164 } else { 211 } else {
165 dma_dscr_idx = CAPTURE_START_DMA_DESCR_CH14 + i; 212 dma_dscr_idx = CAPTURE_START_DMA_DESCR_CH14 + i;
166 dmadscr[i].src = ACP_SHARED_RAM_BANK_5_ADDRESS + 213 switch (asic_type) {
167 (i * (size/2)); 214 case CHIP_STONEY:
168 dmadscr[i].dest = ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS 215 dmadscr[i].src = ACP_SHARED_RAM_BANK_3_ADDRESS +
169 + (pte_offset * SZ_4K) + 216 (i * (size/2));
170 (i * (size/2)); 217 dmadscr[i].dest =
171 dmadscr[i].xfer_val |= 218 ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS +
172 BIT(22) | 219 (pte_offset * SZ_4K) + (i * (size/2));
173 (ACP_DMA_ATTRIBUTES_SHAREDMEM_TO_DAGB_ONION << 16) | 220 dmadscr[i].xfer_val |=
174 (size / 2); 221 BIT(22) |
222 (ACP_DMA_ATTRIBUTES_SHARED_MEM_TO_DAGB_GARLIC << 16) |
223 (size / 2);
224 break;
225 default:
226 dmadscr[i].src = ACP_SHARED_RAM_BANK_5_ADDRESS +
227 (i * (size/2));
228 dmadscr[i].dest =
229 ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS +
230 (pte_offset * SZ_4K) + (i * (size/2));
231 dmadscr[i].xfer_val |=
232 BIT(22) |
233 (ACP_DMA_ATTRIBUTES_SHAREDMEM_TO_DAGB_ONION << 16) |
234 (size / 2);
235 }
175 } 236 }
176 config_dma_descriptor_in_sram(acp_mmio, dma_dscr_idx, 237 config_dma_descriptor_in_sram(acp_mmio, dma_dscr_idx,
177 &dmadscr[i]); 238 &dmadscr[i]);
@@ -192,7 +253,8 @@ static void set_acp_sysmem_dma_descriptors(void __iomem *acp_mmio,
192 * ACP SRAM <-> I2S 253 * ACP SRAM <-> I2S
193 */ 254 */
194static void set_acp_to_i2s_dma_descriptors(void __iomem *acp_mmio, 255static void set_acp_to_i2s_dma_descriptors(void __iomem *acp_mmio,
195 u32 size, int direction) 256 u32 size, int direction,
257 u32 asic_type)
196{ 258{
197 259
198 u16 i; 260 u16 i;
@@ -213,8 +275,17 @@ static void set_acp_to_i2s_dma_descriptors(void __iomem *acp_mmio,
213 dma_dscr_idx = CAPTURE_START_DMA_DESCR_CH15 + i; 275 dma_dscr_idx = CAPTURE_START_DMA_DESCR_CH15 + i;
214 /* dmadscr[i].src is unused by hardware. */ 276 /* dmadscr[i].src is unused by hardware. */
215 dmadscr[i].src = 0; 277 dmadscr[i].src = 0;
216 dmadscr[i].dest = ACP_SHARED_RAM_BANK_5_ADDRESS + 278 switch (asic_type) {
279 case CHIP_STONEY:
280 dmadscr[i].dest =
281 ACP_SHARED_RAM_BANK_3_ADDRESS +
217 (i * (size / 2)); 282 (i * (size / 2));
283 break;
284 default:
285 dmadscr[i].dest =
286 ACP_SHARED_RAM_BANK_5_ADDRESS +
287 (i * (size / 2));
288 }
218 dmadscr[i].xfer_val |= BIT(22) | 289 dmadscr[i].xfer_val |= BIT(22) |
219 (FROM_ACP_I2S_1 << 16) | (size / 2); 290 (FROM_ACP_I2S_1 << 16) | (size / 2);
220 } 291 }
@@ -270,7 +341,8 @@ static void acp_pte_config(void __iomem *acp_mmio, struct page *pg,
270} 341}
271 342
272static void config_acp_dma(void __iomem *acp_mmio, 343static void config_acp_dma(void __iomem *acp_mmio,
273 struct audio_substream_data *audio_config) 344 struct audio_substream_data *audio_config,
345 u32 asic_type)
274{ 346{
275 u32 pte_offset; 347 u32 pte_offset;
276 348
@@ -284,11 +356,11 @@ static void config_acp_dma(void __iomem *acp_mmio,
284 356
285 /* Configure System memory <-> ACP SRAM DMA descriptors */ 357 /* Configure System memory <-> ACP SRAM DMA descriptors */
286 set_acp_sysmem_dma_descriptors(acp_mmio, audio_config->size, 358 set_acp_sysmem_dma_descriptors(acp_mmio, audio_config->size,
287 audio_config->direction, pte_offset); 359 audio_config->direction, pte_offset, asic_type);
288 360
289 /* Configure ACP SRAM <-> I2S DMA descriptors */ 361 /* Configure ACP SRAM <-> I2S DMA descriptors */
290 set_acp_to_i2s_dma_descriptors(acp_mmio, audio_config->size, 362 set_acp_to_i2s_dma_descriptors(acp_mmio, audio_config->size,
291 audio_config->direction); 363 audio_config->direction, asic_type);
292} 364}
293 365
294/* Start a given DMA channel transfer */ 366/* Start a given DMA channel transfer */
@@ -425,7 +497,7 @@ static void acp_set_sram_bank_state(void __iomem *acp_mmio, u16 bank,
425} 497}
426 498
427/* Initialize and bring ACP hardware to default state. */ 499/* Initialize and bring ACP hardware to default state. */
428static int acp_init(void __iomem *acp_mmio) 500static int acp_init(void __iomem *acp_mmio, u32 asic_type)
429{ 501{
430 u16 bank; 502 u16 bank;
431 u32 val, count, sram_pte_offset; 503 u32 val, count, sram_pte_offset;
@@ -499,10 +571,21 @@ static int acp_init(void __iomem *acp_mmio)
499 /* When ACP_TILE_P1 is turned on, all SRAM banks get turned on. 571 /* When ACP_TILE_P1 is turned on, all SRAM banks get turned on.
500 * Now, turn off all of them. This can't be done in 'poweron' of 572 * Now, turn off all of them. This can't be done in 'poweron' of
501 * ACP pm domain, as this requires ACP to be initialized. 573 * ACP pm domain, as this requires ACP to be initialized.
574 * For Stoney, Memory gating is disabled,i.e SRAM Banks
575 * won't be turned off. The default state for SRAM banks is ON.
576 * Setting SRAM bank state code skipped for STONEY platform.
502 */ 577 */
503 for (bank = 1; bank < 48; bank++) 578 if (asic_type != CHIP_STONEY) {
504 acp_set_sram_bank_state(acp_mmio, bank, false); 579 for (bank = 1; bank < 48; bank++)
580 acp_set_sram_bank_state(acp_mmio, bank, false);
581 }
505 582
583 /* Stoney supports 16bit resolution */
584 if (asic_type == CHIP_STONEY) {
585 val = acp_reg_read(acp_mmio, mmACP_I2S_16BIT_RESOLUTION_EN);
586 val |= 0x03;
587 acp_reg_write(val, acp_mmio, mmACP_I2S_16BIT_RESOLUTION_EN);
588 }
506 return 0; 589 return 0;
507} 590}
508 591
@@ -572,9 +655,9 @@ static irqreturn_t dma_irq_handler(int irq, void *arg)
572 valid_irq = true; 655 valid_irq = true;
573 if (acp_reg_read(acp_mmio, mmACP_DMA_CUR_DSCR_13) == 656 if (acp_reg_read(acp_mmio, mmACP_DMA_CUR_DSCR_13) ==
574 PLAYBACK_START_DMA_DESCR_CH13) 657 PLAYBACK_START_DMA_DESCR_CH13)
575 dscr_idx = PLAYBACK_START_DMA_DESCR_CH12;
576 else
577 dscr_idx = PLAYBACK_END_DMA_DESCR_CH12; 658 dscr_idx = PLAYBACK_END_DMA_DESCR_CH12;
659 else
660 dscr_idx = PLAYBACK_START_DMA_DESCR_CH12;
578 config_acp_dma_channel(acp_mmio, SYSRAM_TO_ACP_CH_NUM, dscr_idx, 661 config_acp_dma_channel(acp_mmio, SYSRAM_TO_ACP_CH_NUM, dscr_idx,
579 1, 0); 662 1, 0);
580 acp_dma_start(acp_mmio, SYSRAM_TO_ACP_CH_NUM, false); 663 acp_dma_start(acp_mmio, SYSRAM_TO_ACP_CH_NUM, false);
@@ -626,10 +709,23 @@ static int acp_dma_open(struct snd_pcm_substream *substream)
626 if (adata == NULL) 709 if (adata == NULL)
627 return -ENOMEM; 710 return -ENOMEM;
628 711
629 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 712 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
630 runtime->hw = acp_pcm_hardware_playback; 713 switch (intr_data->asic_type) {
631 else 714 case CHIP_STONEY:
632 runtime->hw = acp_pcm_hardware_capture; 715 runtime->hw = acp_st_pcm_hardware_playback;
716 break;
717 default:
718 runtime->hw = acp_pcm_hardware_playback;
719 }
720 } else {
721 switch (intr_data->asic_type) {
722 case CHIP_STONEY:
723 runtime->hw = acp_st_pcm_hardware_capture;
724 break;
725 default:
726 runtime->hw = acp_pcm_hardware_capture;
727 }
728 }
633 729
634 ret = snd_pcm_hw_constraint_integer(runtime, 730 ret = snd_pcm_hw_constraint_integer(runtime,
635 SNDRV_PCM_HW_PARAM_PERIODS); 731 SNDRV_PCM_HW_PARAM_PERIODS);
@@ -652,14 +748,22 @@ static int acp_dma_open(struct snd_pcm_substream *substream)
652 748
653 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 749 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
654 intr_data->play_stream = substream; 750 intr_data->play_stream = substream;
655 for (bank = 1; bank <= 4; bank++) 751 /* For Stoney, Memory gating is disabled,i.e SRAM Banks
656 acp_set_sram_bank_state(intr_data->acp_mmio, bank, 752 * won't be turned off. The default state for SRAM banks is ON.
657 true); 753 * Setting SRAM bank state code skipped for STONEY platform.
754 */
755 if (intr_data->asic_type != CHIP_STONEY) {
756 for (bank = 1; bank <= 4; bank++)
757 acp_set_sram_bank_state(intr_data->acp_mmio,
758 bank, true);
759 }
658 } else { 760 } else {
659 intr_data->capture_stream = substream; 761 intr_data->capture_stream = substream;
660 for (bank = 5; bank <= 8; bank++) 762 if (intr_data->asic_type != CHIP_STONEY) {
661 acp_set_sram_bank_state(intr_data->acp_mmio, bank, 763 for (bank = 5; bank <= 8; bank++)
662 true); 764 acp_set_sram_bank_state(intr_data->acp_mmio,
765 bank, true);
766 }
663 } 767 }
664 768
665 return 0; 769 return 0;
@@ -673,6 +777,8 @@ static int acp_dma_hw_params(struct snd_pcm_substream *substream,
673 struct page *pg; 777 struct page *pg;
674 struct snd_pcm_runtime *runtime; 778 struct snd_pcm_runtime *runtime;
675 struct audio_substream_data *rtd; 779 struct audio_substream_data *rtd;
780 struct snd_soc_pcm_runtime *prtd = substream->private_data;
781 struct audio_drv_data *adata = dev_get_drvdata(prtd->platform->dev);
676 782
677 runtime = substream->runtime; 783 runtime = substream->runtime;
678 rtd = runtime->private_data; 784 rtd = runtime->private_data;
@@ -700,7 +806,7 @@ static int acp_dma_hw_params(struct snd_pcm_substream *substream,
700 rtd->num_of_pages = PAGE_ALIGN(size) >> PAGE_SHIFT; 806 rtd->num_of_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
701 rtd->direction = substream->stream; 807 rtd->direction = substream->stream;
702 808
703 config_acp_dma(rtd->acp_mmio, rtd); 809 config_acp_dma(rtd->acp_mmio, rtd, adata->asic_type);
704 status = 0; 810 status = 0;
705 } else { 811 } else {
706 status = -ENOMEM; 812 status = -ENOMEM;
@@ -713,40 +819,48 @@ static int acp_dma_hw_free(struct snd_pcm_substream *substream)
713 return snd_pcm_lib_free_pages(substream); 819 return snd_pcm_lib_free_pages(substream);
714} 820}
715 821
822static u64 acp_get_byte_count(void __iomem *acp_mmio, int stream)
823{
824 union acp_dma_count playback_dma_count;
825 union acp_dma_count capture_dma_count;
826 u64 bytescount = 0;
827
828 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
829 playback_dma_count.bcount.high = acp_reg_read(acp_mmio,
830 mmACP_I2S_TRANSMIT_BYTE_CNT_HIGH);
831 playback_dma_count.bcount.low = acp_reg_read(acp_mmio,
832 mmACP_I2S_TRANSMIT_BYTE_CNT_LOW);
833 bytescount = playback_dma_count.bytescount;
834 } else {
835 capture_dma_count.bcount.high = acp_reg_read(acp_mmio,
836 mmACP_I2S_RECEIVED_BYTE_CNT_HIGH);
837 capture_dma_count.bcount.low = acp_reg_read(acp_mmio,
838 mmACP_I2S_RECEIVED_BYTE_CNT_LOW);
839 bytescount = capture_dma_count.bytescount;
840 }
841 return bytescount;
842}
843
716static snd_pcm_uframes_t acp_dma_pointer(struct snd_pcm_substream *substream) 844static snd_pcm_uframes_t acp_dma_pointer(struct snd_pcm_substream *substream)
717{ 845{
718 u16 dscr; 846 u32 buffersize;
719 u32 mul, dma_config, period_bytes;
720 u32 pos = 0; 847 u32 pos = 0;
848 u64 bytescount = 0;
721 849
722 struct snd_pcm_runtime *runtime = substream->runtime; 850 struct snd_pcm_runtime *runtime = substream->runtime;
723 struct audio_substream_data *rtd = runtime->private_data; 851 struct audio_substream_data *rtd = runtime->private_data;
724 852
725 period_bytes = frames_to_bytes(runtime, runtime->period_size); 853 buffersize = frames_to_bytes(runtime, runtime->buffer_size);
726 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 854 bytescount = acp_get_byte_count(rtd->acp_mmio, substream->stream);
727 dscr = acp_reg_read(rtd->acp_mmio, mmACP_DMA_CUR_DSCR_13);
728 855
729 if (dscr == PLAYBACK_START_DMA_DESCR_CH13) 856 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
730 mul = 0; 857 if (bytescount > rtd->renderbytescount)
731 else 858 bytescount = bytescount - rtd->renderbytescount;
732 mul = 1;
733 pos = (mul * period_bytes);
734 } else { 859 } else {
735 dma_config = acp_reg_read(rtd->acp_mmio, mmACP_DMA_CNTL_14); 860 if (bytescount > rtd->capturebytescount)
736 if (dma_config != 0) { 861 bytescount = bytescount - rtd->capturebytescount;
737 dscr = acp_reg_read(rtd->acp_mmio,
738 mmACP_DMA_CUR_DSCR_14);
739 if (dscr == CAPTURE_START_DMA_DESCR_CH14)
740 mul = 1;
741 else
742 mul = 2;
743 pos = (mul * period_bytes);
744 }
745
746 if (pos >= (2 * period_bytes))
747 pos = 0;
748
749 } 862 }
863 pos = do_div(bytescount, buffersize);
750 return bytes_to_frames(runtime, pos); 864 return bytes_to_frames(runtime, pos);
751} 865}
752 866
@@ -768,23 +882,6 @@ static int acp_dma_prepare(struct snd_pcm_substream *substream)
768 config_acp_dma_channel(rtd->acp_mmio, ACP_TO_I2S_DMA_CH_NUM, 882 config_acp_dma_channel(rtd->acp_mmio, ACP_TO_I2S_DMA_CH_NUM,
769 PLAYBACK_START_DMA_DESCR_CH13, 883 PLAYBACK_START_DMA_DESCR_CH13,
770 NUM_DSCRS_PER_CHANNEL, 0); 884 NUM_DSCRS_PER_CHANNEL, 0);
771 /* Fill ACP SRAM (2 periods) with zeros from System RAM
772 * which is zero-ed in hw_params
773 */
774 acp_dma_start(rtd->acp_mmio, SYSRAM_TO_ACP_CH_NUM, false);
775
776 /* ACP SRAM (2 periods of buffer size) is intially filled with
777 * zeros. Before rendering starts, 2nd half of SRAM will be
778 * filled with valid audio data DMA'ed from first half of system
779 * RAM and 1st half of SRAM will be filled with Zeros. This is
780 * the initial scenario when redering starts from SRAM. Later
781 * on, 2nd half of system memory will be DMA'ed to 1st half of
782 * SRAM, 1st half of system memory will be DMA'ed to 2nd half of
783 * SRAM in ping-pong way till rendering stops.
784 */
785 config_acp_dma_channel(rtd->acp_mmio, SYSRAM_TO_ACP_CH_NUM,
786 PLAYBACK_START_DMA_DESCR_CH12,
787 1, 0);
788 } else { 885 } else {
789 config_acp_dma_channel(rtd->acp_mmio, ACP_TO_SYSRAM_CH_NUM, 886 config_acp_dma_channel(rtd->acp_mmio, ACP_TO_SYSRAM_CH_NUM,
790 CAPTURE_START_DMA_DESCR_CH14, 887 CAPTURE_START_DMA_DESCR_CH14,
@@ -799,7 +896,8 @@ static int acp_dma_prepare(struct snd_pcm_substream *substream)
799static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd) 896static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd)
800{ 897{
801 int ret; 898 int ret;
802 u32 loops = 1000; 899 u32 loops = 4000;
900 u64 bytescount = 0;
803 901
804 struct snd_pcm_runtime *runtime = substream->runtime; 902 struct snd_pcm_runtime *runtime = substream->runtime;
805 struct snd_soc_pcm_runtime *prtd = substream->private_data; 903 struct snd_soc_pcm_runtime *prtd = substream->private_data;
@@ -811,7 +909,11 @@ static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd)
811 case SNDRV_PCM_TRIGGER_START: 909 case SNDRV_PCM_TRIGGER_START:
812 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 910 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
813 case SNDRV_PCM_TRIGGER_RESUME: 911 case SNDRV_PCM_TRIGGER_RESUME:
912 bytescount = acp_get_byte_count(rtd->acp_mmio,
913 substream->stream);
814 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 914 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
915 if (rtd->renderbytescount == 0)
916 rtd->renderbytescount = bytescount;
815 acp_dma_start(rtd->acp_mmio, 917 acp_dma_start(rtd->acp_mmio,
816 SYSRAM_TO_ACP_CH_NUM, false); 918 SYSRAM_TO_ACP_CH_NUM, false);
817 while (acp_reg_read(rtd->acp_mmio, mmACP_DMA_CH_STS) & 919 while (acp_reg_read(rtd->acp_mmio, mmACP_DMA_CH_STS) &
@@ -828,6 +930,8 @@ static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd)
828 ACP_TO_I2S_DMA_CH_NUM, true); 930 ACP_TO_I2S_DMA_CH_NUM, true);
829 931
830 } else { 932 } else {
933 if (rtd->capturebytescount == 0)
934 rtd->capturebytescount = bytescount;
831 acp_dma_start(rtd->acp_mmio, 935 acp_dma_start(rtd->acp_mmio,
832 I2S_TO_ACP_DMA_CH_NUM, true); 936 I2S_TO_ACP_DMA_CH_NUM, true);
833 } 937 }
@@ -841,12 +945,15 @@ static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd)
841 * channels will stopped automatically after its transfer 945 * channels will stopped automatically after its transfer
842 * completes : SYSRAM_TO_ACP_CH_NUM / ACP_TO_SYSRAM_CH_NUM 946 * completes : SYSRAM_TO_ACP_CH_NUM / ACP_TO_SYSRAM_CH_NUM
843 */ 947 */
844 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 948 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
845 ret = acp_dma_stop(rtd->acp_mmio, 949 ret = acp_dma_stop(rtd->acp_mmio,
846 ACP_TO_I2S_DMA_CH_NUM); 950 ACP_TO_I2S_DMA_CH_NUM);
847 else 951 rtd->renderbytescount = 0;
952 } else {
848 ret = acp_dma_stop(rtd->acp_mmio, 953 ret = acp_dma_stop(rtd->acp_mmio,
849 I2S_TO_ACP_DMA_CH_NUM); 954 I2S_TO_ACP_DMA_CH_NUM);
955 rtd->capturebytescount = 0;
956 }
850 break; 957 break;
851 default: 958 default:
852 ret = -EINVAL; 959 ret = -EINVAL;
@@ -857,10 +964,27 @@ static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd)
857 964
858static int acp_dma_new(struct snd_soc_pcm_runtime *rtd) 965static int acp_dma_new(struct snd_soc_pcm_runtime *rtd)
859{ 966{
860 return snd_pcm_lib_preallocate_pages_for_all(rtd->pcm, 967 int ret;
968 struct audio_drv_data *adata = dev_get_drvdata(rtd->platform->dev);
969
970 switch (adata->asic_type) {
971 case CHIP_STONEY:
972 ret = snd_pcm_lib_preallocate_pages_for_all(rtd->pcm,
973 SNDRV_DMA_TYPE_DEV,
974 NULL, ST_MIN_BUFFER,
975 ST_MAX_BUFFER);
976 break;
977 default:
978 ret = snd_pcm_lib_preallocate_pages_for_all(rtd->pcm,
861 SNDRV_DMA_TYPE_DEV, 979 SNDRV_DMA_TYPE_DEV,
862 NULL, MIN_BUFFER, 980 NULL, MIN_BUFFER,
863 MAX_BUFFER); 981 MAX_BUFFER);
982 break;
983 }
984 if (ret < 0)
985 dev_err(rtd->platform->dev,
986 "buffer preallocation failer error:%d\n", ret);
987 return ret;
864} 988}
865 989
866static int acp_dma_close(struct snd_pcm_substream *substream) 990static int acp_dma_close(struct snd_pcm_substream *substream)
@@ -875,14 +999,23 @@ static int acp_dma_close(struct snd_pcm_substream *substream)
875 999
876 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 1000 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
877 adata->play_stream = NULL; 1001 adata->play_stream = NULL;
878 for (bank = 1; bank <= 4; bank++) 1002 /* For Stoney, Memory gating is disabled,i.e SRAM Banks
879 acp_set_sram_bank_state(adata->acp_mmio, bank, 1003 * won't be turned off. The default state for SRAM banks is ON.
880 false); 1004 * Setting SRAM bank state code skipped for STONEY platform.
881 } else { 1005 * added condition checks for Carrizo platform only
1006 */
1007 if (adata->asic_type != CHIP_STONEY) {
1008 for (bank = 1; bank <= 4; bank++)
1009 acp_set_sram_bank_state(adata->acp_mmio, bank,
1010 false);
1011 }
1012 } else {
882 adata->capture_stream = NULL; 1013 adata->capture_stream = NULL;
883 for (bank = 5; bank <= 8; bank++) 1014 if (adata->asic_type != CHIP_STONEY) {
884 acp_set_sram_bank_state(adata->acp_mmio, bank, 1015 for (bank = 5; bank <= 8; bank++)
885 false); 1016 acp_set_sram_bank_state(adata->acp_mmio, bank,
1017 false);
1018 }
886 } 1019 }
887 1020
888 /* Disable ACP irq, when the current stream is being closed and 1021 /* Disable ACP irq, when the current stream is being closed and
@@ -916,6 +1049,7 @@ static int acp_audio_probe(struct platform_device *pdev)
916 int status; 1049 int status;
917 struct audio_drv_data *audio_drv_data; 1050 struct audio_drv_data *audio_drv_data;
918 struct resource *res; 1051 struct resource *res;
1052 const u32 *pdata = pdev->dev.platform_data;
919 1053
920 audio_drv_data = devm_kzalloc(&pdev->dev, sizeof(struct audio_drv_data), 1054 audio_drv_data = devm_kzalloc(&pdev->dev, sizeof(struct audio_drv_data),
921 GFP_KERNEL); 1055 GFP_KERNEL);
@@ -932,6 +1066,7 @@ static int acp_audio_probe(struct platform_device *pdev)
932 1066
933 audio_drv_data->play_stream = NULL; 1067 audio_drv_data->play_stream = NULL;
934 audio_drv_data->capture_stream = NULL; 1068 audio_drv_data->capture_stream = NULL;
1069 audio_drv_data->asic_type = *pdata;
935 1070
936 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 1071 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
937 if (!res) { 1072 if (!res) {
@@ -949,7 +1084,7 @@ static int acp_audio_probe(struct platform_device *pdev)
949 dev_set_drvdata(&pdev->dev, audio_drv_data); 1084 dev_set_drvdata(&pdev->dev, audio_drv_data);
950 1085
951 /* Initialize the ACP */ 1086 /* Initialize the ACP */
952 acp_init(audio_drv_data->acp_mmio); 1087 acp_init(audio_drv_data->acp_mmio, audio_drv_data->asic_type);
953 1088
954 status = snd_soc_register_platform(&pdev->dev, &acp_asoc_platform); 1089 status = snd_soc_register_platform(&pdev->dev, &acp_asoc_platform);
955 if (status != 0) { 1090 if (status != 0) {
@@ -980,21 +1115,31 @@ static int acp_pcm_resume(struct device *dev)
980 u16 bank; 1115 u16 bank;
981 struct audio_drv_data *adata = dev_get_drvdata(dev); 1116 struct audio_drv_data *adata = dev_get_drvdata(dev);
982 1117
983 acp_init(adata->acp_mmio); 1118 acp_init(adata->acp_mmio, adata->asic_type);
984 1119
985 if (adata->play_stream && adata->play_stream->runtime) { 1120 if (adata->play_stream && adata->play_stream->runtime) {
986 for (bank = 1; bank <= 4; bank++) 1121 /* For Stoney, Memory gating is disabled,i.e SRAM Banks
987 acp_set_sram_bank_state(adata->acp_mmio, bank, 1122 * won't be turned off. The default state for SRAM banks is ON.
1123 * Setting SRAM bank state code skipped for STONEY platform.
1124 */
1125 if (adata->asic_type != CHIP_STONEY) {
1126 for (bank = 1; bank <= 4; bank++)
1127 acp_set_sram_bank_state(adata->acp_mmio, bank,
988 true); 1128 true);
1129 }
989 config_acp_dma(adata->acp_mmio, 1130 config_acp_dma(adata->acp_mmio,
990 adata->play_stream->runtime->private_data); 1131 adata->play_stream->runtime->private_data,
1132 adata->asic_type);
991 } 1133 }
992 if (adata->capture_stream && adata->capture_stream->runtime) { 1134 if (adata->capture_stream && adata->capture_stream->runtime) {
993 for (bank = 5; bank <= 8; bank++) 1135 if (adata->asic_type != CHIP_STONEY) {
994 acp_set_sram_bank_state(adata->acp_mmio, bank, 1136 for (bank = 5; bank <= 8; bank++)
1137 acp_set_sram_bank_state(adata->acp_mmio, bank,
995 true); 1138 true);
1139 }
996 config_acp_dma(adata->acp_mmio, 1140 config_acp_dma(adata->acp_mmio,
997 adata->capture_stream->runtime->private_data); 1141 adata->capture_stream->runtime->private_data,
1142 adata->asic_type);
998 } 1143 }
999 acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); 1144 acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB);
1000 return 0; 1145 return 0;
@@ -1013,7 +1158,7 @@ static int acp_pcm_runtime_resume(struct device *dev)
1013{ 1158{
1014 struct audio_drv_data *adata = dev_get_drvdata(dev); 1159 struct audio_drv_data *adata = dev_get_drvdata(dev);
1015 1160
1016 acp_init(adata->acp_mmio); 1161 acp_init(adata->acp_mmio, adata->asic_type);
1017 acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB); 1162 acp_reg_write(1, adata->acp_mmio, mmACP_EXTERNAL_INTR_ENB);
1018 return 0; 1163 return 0;
1019} 1164}
@@ -1028,14 +1173,15 @@ static struct platform_driver acp_dma_driver = {
1028 .probe = acp_audio_probe, 1173 .probe = acp_audio_probe,
1029 .remove = acp_audio_remove, 1174 .remove = acp_audio_remove,
1030 .driver = { 1175 .driver = {
1031 .name = "acp_audio_dma", 1176 .name = DRV_NAME,
1032 .pm = &acp_pm_ops, 1177 .pm = &acp_pm_ops,
1033 }, 1178 },
1034}; 1179};
1035 1180
1036module_platform_driver(acp_dma_driver); 1181module_platform_driver(acp_dma_driver);
1037 1182
1183MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
1038MODULE_AUTHOR("Maruthi.Bayyavarapu@amd.com"); 1184MODULE_AUTHOR("Maruthi.Bayyavarapu@amd.com");
1039MODULE_DESCRIPTION("AMD ACP PCM Driver"); 1185MODULE_DESCRIPTION("AMD ACP PCM Driver");
1040MODULE_LICENSE("GPL v2"); 1186MODULE_LICENSE("GPL v2");
1041MODULE_ALIAS("platform:acp-dma-audio"); 1187MODULE_ALIAS("platform:"DRV_NAME);
diff --git a/sound/soc/amd/acp-rt5645.c b/sound/soc/amd/acp-rt5645.c
new file mode 100644
index 000000000000..941aed6bb364
--- /dev/null
+++ b/sound/soc/amd/acp-rt5645.c
@@ -0,0 +1,199 @@
1/*
2 * Machine driver for AMD ACP Audio engine using Realtek RT5645 codec
3 *
4 * Copyright 2017 Advanced Micro Devices, Inc.
5 *
6 * This file is modified from rt288 machine driver
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25 *
26 *
27 */
28
29#include <sound/core.h>
30#include <sound/soc.h>
31#include <sound/pcm.h>
32#include <sound/pcm_params.h>
33#include <sound/soc-dapm.h>
34#include <sound/jack.h>
35#include <linux/gpio.h>
36#include <linux/module.h>
37#include <linux/i2c.h>
38#include <linux/acpi.h>
39
40#include "../codecs/rt5645.h"
41
42#define CZ_PLAT_CLK 24000000
43
44static struct snd_soc_jack cz_jack;
45
46static int cz_aif1_hw_params(struct snd_pcm_substream *substream,
47 struct snd_pcm_hw_params *params)
48{
49 int ret = 0;
50 struct snd_soc_pcm_runtime *rtd = substream->private_data;
51 struct snd_soc_dai *codec_dai = rtd->codec_dai;
52
53 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5645_PLL1_S_MCLK,
54 CZ_PLAT_CLK, params_rate(params) * 512);
55 if (ret < 0) {
56 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
57 return ret;
58 }
59
60 ret = snd_soc_dai_set_sysclk(codec_dai, RT5645_SCLK_S_PLL1,
61 params_rate(params) * 512, SND_SOC_CLOCK_OUT);
62 if (ret < 0) {
63 dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret);
64 return ret;
65 }
66
67 return ret;
68}
69
70static int cz_init(struct snd_soc_pcm_runtime *rtd)
71{
72 int ret;
73 struct snd_soc_card *card;
74 struct snd_soc_codec *codec;
75
76 codec = rtd->codec;
77 card = rtd->card;
78
79 ret = snd_soc_card_jack_new(card, "Headset Jack",
80 SND_JACK_HEADPHONE | SND_JACK_MICROPHONE |
81 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
82 SND_JACK_BTN_2 | SND_JACK_BTN_3,
83 &cz_jack, NULL, 0);
84 if (ret) {
85 dev_err(card->dev, "HP jack creation failed %d\n", ret);
86 return ret;
87 }
88
89 rt5645_set_jack_detect(codec, &cz_jack, &cz_jack, &cz_jack);
90
91 return 0;
92}
93
94static struct snd_soc_ops cz_aif1_ops = {
95 .hw_params = cz_aif1_hw_params,
96};
97
98static struct snd_soc_dai_link cz_dai_rt5650[] = {
99 {
100 .name = "amd-rt5645-play",
101 .stream_name = "RT5645_AIF1",
102 .platform_name = "acp_audio_dma.0.auto",
103 .cpu_dai_name = "designware-i2s.1.auto",
104 .codec_dai_name = "rt5645-aif1",
105 .codec_name = "i2c-10EC5650:00",
106 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
107 | SND_SOC_DAIFMT_CBM_CFM,
108 .init = cz_init,
109 .ops = &cz_aif1_ops,
110 },
111 {
112 .name = "amd-rt5645-cap",
113 .stream_name = "RT5645_AIF1",
114 .platform_name = "acp_audio_dma.0.auto",
115 .cpu_dai_name = "designware-i2s.2.auto",
116 .codec_dai_name = "rt5645-aif1",
117 .codec_name = "i2c-10EC5650:00",
118 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
119 | SND_SOC_DAIFMT_CBM_CFM,
120 .ops = &cz_aif1_ops,
121 },
122};
123
124static const struct snd_soc_dapm_widget cz_widgets[] = {
125 SND_SOC_DAPM_HP("Headphones", NULL),
126 SND_SOC_DAPM_SPK("Speakers", NULL),
127 SND_SOC_DAPM_MIC("Headset Mic", NULL),
128 SND_SOC_DAPM_MIC("Int Mic", NULL),
129};
130
131static const struct snd_soc_dapm_route cz_audio_route[] = {
132 {"Headphones", NULL, "HPOL"},
133 {"Headphones", NULL, "HPOR"},
134 {"RECMIXL", NULL, "Headset Mic"},
135 {"RECMIXR", NULL, "Headset Mic"},
136 {"Speakers", NULL, "SPOL"},
137 {"Speakers", NULL, "SPOR"},
138 {"DMIC L2", NULL, "Int Mic"},
139 {"DMIC R2", NULL, "Int Mic"},
140};
141
142static const struct snd_kcontrol_new cz_mc_controls[] = {
143 SOC_DAPM_PIN_SWITCH("Headphones"),
144 SOC_DAPM_PIN_SWITCH("Speakers"),
145 SOC_DAPM_PIN_SWITCH("Headset Mic"),
146 SOC_DAPM_PIN_SWITCH("Int Mic"),
147};
148
149static struct snd_soc_card cz_card = {
150 .name = "acprt5650",
151 .owner = THIS_MODULE,
152 .dai_link = cz_dai_rt5650,
153 .num_links = ARRAY_SIZE(cz_dai_rt5650),
154 .dapm_widgets = cz_widgets,
155 .num_dapm_widgets = ARRAY_SIZE(cz_widgets),
156 .dapm_routes = cz_audio_route,
157 .num_dapm_routes = ARRAY_SIZE(cz_audio_route),
158 .controls = cz_mc_controls,
159 .num_controls = ARRAY_SIZE(cz_mc_controls),
160};
161
162static int cz_probe(struct platform_device *pdev)
163{
164 int ret;
165 struct snd_soc_card *card;
166
167 card = &cz_card;
168 cz_card.dev = &pdev->dev;
169 platform_set_drvdata(pdev, card);
170 ret = devm_snd_soc_register_card(&pdev->dev, &cz_card);
171 if (ret) {
172 dev_err(&pdev->dev,
173 "devm_snd_soc_register_card(%s) failed: %d\n",
174 cz_card.name, ret);
175 return ret;
176 }
177 return 0;
178}
179
180static const struct acpi_device_id cz_audio_acpi_match[] = {
181 { "AMDI1002", 0 },
182 {},
183};
184MODULE_DEVICE_TABLE(acpi, cz_audio_acpi_match);
185
186static struct platform_driver cz_pcm_driver = {
187 .driver = {
188 .name = "cz-rt5645",
189 .acpi_match_table = ACPI_PTR(cz_audio_acpi_match),
190 .pm = &snd_soc_pm_ops,
191 },
192 .probe = cz_probe,
193};
194
195module_platform_driver(cz_pcm_driver);
196
197MODULE_AUTHOR("akshu.agrawal@amd.com");
198MODULE_DESCRIPTION("cz-rt5645 audio support");
199MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/amd/acp.h b/sound/soc/amd/acp.h
index 9d338216c5ae..ecb458935d1e 100644
--- a/sound/soc/amd/acp.h
+++ b/sound/soc/amd/acp.h
@@ -20,6 +20,7 @@
20 20
21/* Capture SRAM address (as a source in dma descriptor) */ 21/* Capture SRAM address (as a source in dma descriptor) */
22#define ACP_SHARED_RAM_BANK_5_ADDRESS 0x400A000 22#define ACP_SHARED_RAM_BANK_5_ADDRESS 0x400A000
23#define ACP_SHARED_RAM_BANK_3_ADDRESS 0x4006000
23 24
24#define ACP_DMA_RESET_TIME 10000 25#define ACP_DMA_RESET_TIME 10000
25#define ACP_CLOCK_EN_TIME_OUT_VALUE 0x000000FF 26#define ACP_CLOCK_EN_TIME_OUT_VALUE 0x000000FF
@@ -68,6 +69,7 @@
68#define CAPTURE_START_DMA_DESCR_CH15 6 69#define CAPTURE_START_DMA_DESCR_CH15 6
69#define CAPTURE_END_DMA_DESCR_CH15 7 70#define CAPTURE_END_DMA_DESCR_CH15 7
70 71
72#define mmACP_I2S_16BIT_RESOLUTION_EN 0x5209
71enum acp_dma_priority_level { 73enum acp_dma_priority_level {
72 /* 0x0 Specifies the DMA channel is given normal priority */ 74 /* 0x0 Specifies the DMA channel is given normal priority */
73 ACP_DMA_PRIORITY_LEVEL_NORMAL = 0x0, 75 ACP_DMA_PRIORITY_LEVEL_NORMAL = 0x0,
@@ -82,9 +84,26 @@ struct audio_substream_data {
82 u16 num_of_pages; 84 u16 num_of_pages;
83 u16 direction; 85 u16 direction;
84 uint64_t size; 86 uint64_t size;
87 u64 renderbytescount;
88 u64 capturebytescount;
85 void __iomem *acp_mmio; 89 void __iomem *acp_mmio;
86}; 90};
87 91
92struct audio_drv_data {
93 struct snd_pcm_substream *play_stream;
94 struct snd_pcm_substream *capture_stream;
95 void __iomem *acp_mmio;
96 u32 asic_type;
97};
98
99union acp_dma_count {
100 struct {
101 u32 low;
102 u32 high;
103 } bcount;
104 u64 bytescount;
105};
106
88enum { 107enum {
89 ACP_TILE_P1 = 0, 108 ACP_TILE_P1 = 0,
90 ACP_TILE_P2, 109 ACP_TILE_P2,
diff --git a/sound/soc/bcm/bcm2835-i2s.c b/sound/soc/bcm/bcm2835-i2s.c
index 6ba20498202e..2e449d7173fc 100644
--- a/sound/soc/bcm/bcm2835-i2s.c
+++ b/sound/soc/bcm/bcm2835-i2s.c
@@ -31,6 +31,7 @@
31 * General Public License for more details. 31 * General Public License for more details.
32 */ 32 */
33 33
34#include <linux/bitops.h>
34#include <linux/clk.h> 35#include <linux/clk.h>
35#include <linux/delay.h> 36#include <linux/delay.h>
36#include <linux/device.h> 37#include <linux/device.h>
@@ -99,6 +100,8 @@
99#define BCM2835_I2S_CHWID(v) (v) 100#define BCM2835_I2S_CHWID(v) (v)
100#define BCM2835_I2S_CH1(v) ((v) << 16) 101#define BCM2835_I2S_CH1(v) ((v) << 16)
101#define BCM2835_I2S_CH2(v) (v) 102#define BCM2835_I2S_CH2(v) (v)
103#define BCM2835_I2S_CH1_POS(v) BCM2835_I2S_CH1(BCM2835_I2S_CHPOS(v))
104#define BCM2835_I2S_CH2_POS(v) BCM2835_I2S_CH2(BCM2835_I2S_CHPOS(v))
102 105
103#define BCM2835_I2S_TX_PANIC(v) ((v) << 24) 106#define BCM2835_I2S_TX_PANIC(v) ((v) << 24)
104#define BCM2835_I2S_RX_PANIC(v) ((v) << 16) 107#define BCM2835_I2S_RX_PANIC(v) ((v) << 16)
@@ -110,12 +113,19 @@
110#define BCM2835_I2S_INT_RXR BIT(1) 113#define BCM2835_I2S_INT_RXR BIT(1)
111#define BCM2835_I2S_INT_TXW BIT(0) 114#define BCM2835_I2S_INT_TXW BIT(0)
112 115
116/* Frame length register is 10 bit, maximum length 1024 */
117#define BCM2835_I2S_MAX_FRAME_LENGTH 1024
118
113/* General device struct */ 119/* General device struct */
114struct bcm2835_i2s_dev { 120struct bcm2835_i2s_dev {
115 struct device *dev; 121 struct device *dev;
116 struct snd_dmaengine_dai_dma_data dma_data[2]; 122 struct snd_dmaengine_dai_dma_data dma_data[2];
117 unsigned int fmt; 123 unsigned int fmt;
118 unsigned int bclk_ratio; 124 unsigned int tdm_slots;
125 unsigned int rx_mask;
126 unsigned int tx_mask;
127 unsigned int slot_width;
128 unsigned int frame_length;
119 129
120 struct regmap *i2s_regmap; 130 struct regmap *i2s_regmap;
121 struct clk *clk; 131 struct clk *clk;
@@ -225,19 +235,120 @@ static int bcm2835_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
225 unsigned int ratio) 235 unsigned int ratio)
226{ 236{
227 struct bcm2835_i2s_dev *dev = snd_soc_dai_get_drvdata(dai); 237 struct bcm2835_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
228 dev->bclk_ratio = ratio; 238
239 if (!ratio) {
240 dev->tdm_slots = 0;
241 return 0;
242 }
243
244 if (ratio > BCM2835_I2S_MAX_FRAME_LENGTH)
245 return -EINVAL;
246
247 dev->tdm_slots = 2;
248 dev->rx_mask = 0x03;
249 dev->tx_mask = 0x03;
250 dev->slot_width = ratio / 2;
251 dev->frame_length = ratio;
252
229 return 0; 253 return 0;
230} 254}
231 255
256static int bcm2835_i2s_set_dai_tdm_slot(struct snd_soc_dai *dai,
257 unsigned int tx_mask, unsigned int rx_mask,
258 int slots, int width)
259{
260 struct bcm2835_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
261
262 if (slots) {
263 if (slots < 0 || width < 0)
264 return -EINVAL;
265
266 /* Limit masks to available slots */
267 rx_mask &= GENMASK(slots - 1, 0);
268 tx_mask &= GENMASK(slots - 1, 0);
269
270 /*
271 * The driver is limited to 2-channel setups.
272 * Check that exactly 2 bits are set in the masks.
273 */
274 if (hweight_long((unsigned long) rx_mask) != 2
275 || hweight_long((unsigned long) tx_mask) != 2)
276 return -EINVAL;
277
278 if (slots * width > BCM2835_I2S_MAX_FRAME_LENGTH)
279 return -EINVAL;
280 }
281
282 dev->tdm_slots = slots;
283
284 dev->rx_mask = rx_mask;
285 dev->tx_mask = tx_mask;
286 dev->slot_width = width;
287 dev->frame_length = slots * width;
288
289 return 0;
290}
291
292/*
293 * Convert logical slot number into physical slot number.
294 *
295 * If odd_offset is 0 sequential number is identical to logical number.
296 * This is used for DSP modes with slot numbering 0 1 2 3 ...
297 *
298 * Otherwise odd_offset defines the physical offset for odd numbered
299 * slots. This is used for I2S and left/right justified modes to
300 * translate from logical slot numbers 0 1 2 3 ... into physical slot
301 * numbers 0 2 ... 3 4 ...
302 */
303static int bcm2835_i2s_convert_slot(unsigned int slot, unsigned int odd_offset)
304{
305 if (!odd_offset)
306 return slot;
307
308 if (slot & 1)
309 return (slot >> 1) + odd_offset;
310
311 return slot >> 1;
312}
313
314/*
315 * Calculate channel position from mask and slot width.
316 *
317 * Mask must contain exactly 2 set bits.
318 * Lowest set bit is channel 1 position, highest set bit channel 2.
319 * The constant offset is added to both channel positions.
320 *
321 * If odd_offset is > 0 slot positions are translated to
322 * I2S-style TDM slot numbering ( 0 2 ... 3 4 ...) with odd
323 * logical slot numbers starting at physical slot odd_offset.
324 */
325static void bcm2835_i2s_calc_channel_pos(
326 unsigned int *ch1_pos, unsigned int *ch2_pos,
327 unsigned int mask, unsigned int width,
328 unsigned int bit_offset, unsigned int odd_offset)
329{
330 *ch1_pos = bcm2835_i2s_convert_slot((ffs(mask) - 1), odd_offset)
331 * width + bit_offset;
332 *ch2_pos = bcm2835_i2s_convert_slot((fls(mask) - 1), odd_offset)
333 * width + bit_offset;
334}
335
232static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream, 336static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
233 struct snd_pcm_hw_params *params, 337 struct snd_pcm_hw_params *params,
234 struct snd_soc_dai *dai) 338 struct snd_soc_dai *dai)
235{ 339{
236 struct bcm2835_i2s_dev *dev = snd_soc_dai_get_drvdata(dai); 340 struct bcm2835_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
237 unsigned int sampling_rate = params_rate(params); 341 unsigned int data_length, data_delay, framesync_length;
238 unsigned int data_length, data_delay, bclk_ratio; 342 unsigned int slots, slot_width, odd_slot_offset;
239 unsigned int ch1pos, ch2pos, mode, format; 343 int frame_length, bclk_rate;
344 unsigned int rx_mask, tx_mask;
345 unsigned int rx_ch1_pos, rx_ch2_pos, tx_ch1_pos, tx_ch2_pos;
346 unsigned int mode, format;
347 bool bit_clock_master = false;
348 bool frame_sync_master = false;
349 bool frame_start_falling_edge = false;
240 uint32_t csreg; 350 uint32_t csreg;
351 int ret = 0;
241 352
242 /* 353 /*
243 * If a stream is already enabled, 354 * If a stream is already enabled,
@@ -248,42 +359,70 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
248 if (csreg & (BCM2835_I2S_TXON | BCM2835_I2S_RXON)) 359 if (csreg & (BCM2835_I2S_TXON | BCM2835_I2S_RXON))
249 return 0; 360 return 0;
250 361
251 /* 362 data_length = params_width(params);
252 * Adjust the data length according to the format. 363 data_delay = 0;
253 * We prefill the half frame length with an integer 364 odd_slot_offset = 0;
254 * divider of 2400 as explained at the clock settings. 365 mode = 0;
255 * Maybe it is overwritten there, if the Integer mode 366
256 * does not apply. 367 if (dev->tdm_slots) {
257 */ 368 slots = dev->tdm_slots;
258 switch (params_format(params)) { 369 slot_width = dev->slot_width;
259 case SNDRV_PCM_FORMAT_S16_LE: 370 frame_length = dev->frame_length;
260 data_length = 16; 371 rx_mask = dev->rx_mask;
261 break; 372 tx_mask = dev->tx_mask;
262 case SNDRV_PCM_FORMAT_S24_LE: 373 bclk_rate = dev->frame_length * params_rate(params);
263 data_length = 24; 374 } else {
375 slots = 2;
376 slot_width = params_width(params);
377 rx_mask = 0x03;
378 tx_mask = 0x03;
379
380 frame_length = snd_soc_params_to_frame_size(params);
381 if (frame_length < 0)
382 return frame_length;
383
384 bclk_rate = snd_soc_params_to_bclk(params);
385 if (bclk_rate < 0)
386 return bclk_rate;
387 }
388
389 /* Check if data fits into slots */
390 if (data_length > slot_width)
391 return -EINVAL;
392
393 /* Check if CPU is bit clock master */
394 switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
395 case SND_SOC_DAIFMT_CBS_CFS:
396 case SND_SOC_DAIFMT_CBS_CFM:
397 bit_clock_master = true;
264 break; 398 break;
265 case SNDRV_PCM_FORMAT_S32_LE: 399 case SND_SOC_DAIFMT_CBM_CFS:
266 data_length = 32; 400 case SND_SOC_DAIFMT_CBM_CFM:
401 bit_clock_master = false;
267 break; 402 break;
268 default: 403 default:
269 return -EINVAL; 404 return -EINVAL;
270 } 405 }
271 406
272 /* If bclk_ratio already set, use that one. */ 407 /* Check if CPU is frame sync master */
273 if (dev->bclk_ratio)
274 bclk_ratio = dev->bclk_ratio;
275 else
276 /* otherwise calculate a fitting block ratio */
277 bclk_ratio = 2 * data_length;
278
279 /* Clock should only be set up here if CPU is clock master */
280 switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) { 408 switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
281 case SND_SOC_DAIFMT_CBS_CFS: 409 case SND_SOC_DAIFMT_CBS_CFS:
410 case SND_SOC_DAIFMT_CBM_CFS:
411 frame_sync_master = true;
412 break;
282 case SND_SOC_DAIFMT_CBS_CFM: 413 case SND_SOC_DAIFMT_CBS_CFM:
283 clk_set_rate(dev->clk, sampling_rate * bclk_ratio); 414 case SND_SOC_DAIFMT_CBM_CFM:
415 frame_sync_master = false;
284 break; 416 break;
285 default: 417 default:
286 break; 418 return -EINVAL;
419 }
420
421 /* Clock should only be set up here if CPU is clock master */
422 if (bit_clock_master) {
423 ret = clk_set_rate(dev->clk, bclk_rate);
424 if (ret)
425 return ret;
287 } 426 }
288 427
289 /* Setup the frame format */ 428 /* Setup the frame format */
@@ -294,43 +433,94 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
294 433
295 format |= BCM2835_I2S_CHWID((data_length-8)&0xf); 434 format |= BCM2835_I2S_CHWID((data_length-8)&0xf);
296 435
436 /* CH2 format is the same as for CH1 */
437 format = BCM2835_I2S_CH1(format) | BCM2835_I2S_CH2(format);
438
297 switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 439 switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
298 case SND_SOC_DAIFMT_I2S: 440 case SND_SOC_DAIFMT_I2S:
299 data_delay = 1; 441 /* I2S mode needs an even number of slots */
300 break; 442 if (slots & 1)
301 default: 443 return -EINVAL;
444
302 /* 445 /*
303 * TODO 446 * Use I2S-style logical slot numbering: even slots
304 * Others are possible but are not implemented at the moment. 447 * are in first half of frame, odd slots in second half.
305 */ 448 */
306 dev_err(dev->dev, "%s:bad format\n", __func__); 449 odd_slot_offset = slots >> 1;
307 return -EINVAL;
308 }
309 450
310 ch1pos = data_delay; 451 /* MSB starts one cycle after frame start */
311 ch2pos = bclk_ratio / 2 + data_delay; 452 data_delay = 1;
312 453
313 switch (params_channels(params)) { 454 /* Setup frame sync signal for 50% duty cycle */
314 case 2: 455 framesync_length = frame_length / 2;
315 format = BCM2835_I2S_CH1(format) | BCM2835_I2S_CH2(format); 456 frame_start_falling_edge = true;
316 format |= BCM2835_I2S_CH1(BCM2835_I2S_CHPOS(ch1pos)); 457 break;
317 format |= BCM2835_I2S_CH2(BCM2835_I2S_CHPOS(ch2pos)); 458 case SND_SOC_DAIFMT_LEFT_J:
459 if (slots & 1)
460 return -EINVAL;
461
462 odd_slot_offset = slots >> 1;
463 data_delay = 0;
464 framesync_length = frame_length / 2;
465 frame_start_falling_edge = false;
466 break;
467 case SND_SOC_DAIFMT_RIGHT_J:
468 if (slots & 1)
469 return -EINVAL;
470
471 /* Odd frame lengths aren't supported */
472 if (frame_length & 1)
473 return -EINVAL;
474
475 odd_slot_offset = slots >> 1;
476 data_delay = slot_width - data_length;
477 framesync_length = frame_length / 2;
478 frame_start_falling_edge = false;
479 break;
480 case SND_SOC_DAIFMT_DSP_A:
481 data_delay = 1;
482 framesync_length = 1;
483 frame_start_falling_edge = false;
484 break;
485 case SND_SOC_DAIFMT_DSP_B:
486 data_delay = 0;
487 framesync_length = 1;
488 frame_start_falling_edge = false;
318 break; 489 break;
319 default: 490 default:
320 return -EINVAL; 491 return -EINVAL;
321 } 492 }
322 493
494 bcm2835_i2s_calc_channel_pos(&rx_ch1_pos, &rx_ch2_pos,
495 rx_mask, slot_width, data_delay, odd_slot_offset);
496 bcm2835_i2s_calc_channel_pos(&tx_ch1_pos, &tx_ch2_pos,
497 tx_mask, slot_width, data_delay, odd_slot_offset);
498
499 /*
500 * Transmitting data immediately after frame start, eg
501 * in left-justified or DSP mode A, only works stable
502 * if bcm2835 is the frame clock master.
503 */
504 if ((!rx_ch1_pos || !tx_ch1_pos) && !frame_sync_master)
505 dev_warn(dev->dev,
506 "Unstable slave config detected, L/R may be swapped");
507
323 /* 508 /*
324 * Set format for both streams. 509 * Set format for both streams.
325 * We cannot set another frame length 510 * We cannot set another frame length
326 * (and therefore word length) anyway, 511 * (and therefore word length) anyway,
327 * so the format will be the same. 512 * so the format will be the same.
328 */ 513 */
329 regmap_write(dev->i2s_regmap, BCM2835_I2S_RXC_A_REG, format); 514 regmap_write(dev->i2s_regmap, BCM2835_I2S_RXC_A_REG,
330 regmap_write(dev->i2s_regmap, BCM2835_I2S_TXC_A_REG, format); 515 format
516 | BCM2835_I2S_CH1_POS(rx_ch1_pos)
517 | BCM2835_I2S_CH2_POS(rx_ch2_pos));
518 regmap_write(dev->i2s_regmap, BCM2835_I2S_TXC_A_REG,
519 format
520 | BCM2835_I2S_CH1_POS(tx_ch1_pos)
521 | BCM2835_I2S_CH2_POS(tx_ch2_pos));
331 522
332 /* Setup the I2S mode */ 523 /* Setup the I2S mode */
333 mode = 0;
334 524
335 if (data_length <= 16) { 525 if (data_length <= 16) {
336 /* 526 /*
@@ -342,65 +532,41 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
342 mode |= BCM2835_I2S_FTXP | BCM2835_I2S_FRXP; 532 mode |= BCM2835_I2S_FTXP | BCM2835_I2S_FRXP;
343 } 533 }
344 534
345 mode |= BCM2835_I2S_FLEN(bclk_ratio - 1); 535 mode |= BCM2835_I2S_FLEN(frame_length - 1);
346 mode |= BCM2835_I2S_FSLEN(bclk_ratio / 2); 536 mode |= BCM2835_I2S_FSLEN(framesync_length);
347 537
348 /* Master or slave? */ 538 /* CLKM selects bcm2835 clock slave mode */
349 switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) { 539 if (!bit_clock_master)
350 case SND_SOC_DAIFMT_CBS_CFS:
351 /* CPU is master */
352 break;
353 case SND_SOC_DAIFMT_CBM_CFS:
354 /*
355 * CODEC is bit clock master
356 * CPU is frame master
357 */
358 mode |= BCM2835_I2S_CLKM; 540 mode |= BCM2835_I2S_CLKM;
359 break; 541
360 case SND_SOC_DAIFMT_CBS_CFM: 542 /* FSM selects bcm2835 frame sync slave mode */
361 /* 543 if (!frame_sync_master)
362 * CODEC is frame master
363 * CPU is bit clock master
364 */
365 mode |= BCM2835_I2S_FSM; 544 mode |= BCM2835_I2S_FSM;
545
546 /* CLKI selects normal clocking mode, sampling on rising edge */
547 switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) {
548 case SND_SOC_DAIFMT_NB_NF:
549 case SND_SOC_DAIFMT_NB_IF:
550 mode |= BCM2835_I2S_CLKI;
366 break; 551 break;
367 case SND_SOC_DAIFMT_CBM_CFM: 552 case SND_SOC_DAIFMT_IB_NF:
368 /* CODEC is master */ 553 case SND_SOC_DAIFMT_IB_IF:
369 mode |= BCM2835_I2S_CLKM;
370 mode |= BCM2835_I2S_FSM;
371 break; 554 break;
372 default: 555 default:
373 dev_err(dev->dev, "%s:bad master\n", __func__);
374 return -EINVAL; 556 return -EINVAL;
375 } 557 }
376 558
377 /* 559 /* FSI selects frame start on falling edge */
378 * Invert clocks?
379 *
380 * The BCM approach seems to be inverted to the classical I2S approach.
381 */
382 switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) { 560 switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) {
383 case SND_SOC_DAIFMT_NB_NF: 561 case SND_SOC_DAIFMT_NB_NF:
384 /* None. Therefore, both for BCM */ 562 case SND_SOC_DAIFMT_IB_NF:
385 mode |= BCM2835_I2S_CLKI; 563 if (frame_start_falling_edge)
386 mode |= BCM2835_I2S_FSI; 564 mode |= BCM2835_I2S_FSI;
387 break;
388 case SND_SOC_DAIFMT_IB_IF:
389 /* Both. Therefore, none for BCM */
390 break; 565 break;
391 case SND_SOC_DAIFMT_NB_IF: 566 case SND_SOC_DAIFMT_NB_IF:
392 /* 567 case SND_SOC_DAIFMT_IB_IF:
393 * Invert only frame sync. Therefore, 568 if (!frame_start_falling_edge)
394 * invert only bit clock for BCM 569 mode |= BCM2835_I2S_FSI;
395 */
396 mode |= BCM2835_I2S_CLKI;
397 break;
398 case SND_SOC_DAIFMT_IB_NF:
399 /*
400 * Invert only bit clock. Therefore,
401 * invert only frame sync for BCM
402 */
403 mode |= BCM2835_I2S_FSI;
404 break; 570 break;
405 default: 571 default:
406 return -EINVAL; 572 return -EINVAL;
@@ -423,7 +589,27 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
423 /* Clear FIFOs */ 589 /* Clear FIFOs */
424 bcm2835_i2s_clear_fifos(dev, true, true); 590 bcm2835_i2s_clear_fifos(dev, true, true);
425 591
426 return 0; 592 dev_dbg(dev->dev,
593 "slots: %d width: %d rx mask: 0x%02x tx_mask: 0x%02x\n",
594 slots, slot_width, rx_mask, tx_mask);
595
596 dev_dbg(dev->dev, "frame len: %d sync len: %d data len: %d\n",
597 frame_length, framesync_length, data_length);
598
599 dev_dbg(dev->dev, "rx pos: %d,%d tx pos: %d,%d\n",
600 rx_ch1_pos, rx_ch2_pos, tx_ch1_pos, tx_ch2_pos);
601
602 dev_dbg(dev->dev, "sampling rate: %d bclk rate: %d\n",
603 params_rate(params), bclk_rate);
604
605 dev_dbg(dev->dev, "CLKM: %d CLKI: %d FSM: %d FSI: %d frame start: %s edge\n",
606 !!(mode & BCM2835_I2S_CLKM),
607 !!(mode & BCM2835_I2S_CLKI),
608 !!(mode & BCM2835_I2S_FSM),
609 !!(mode & BCM2835_I2S_FSI),
610 (mode & BCM2835_I2S_FSI) ? "falling" : "rising");
611
612 return ret;
427} 613}
428 614
429static int bcm2835_i2s_prepare(struct snd_pcm_substream *substream, 615static int bcm2835_i2s_prepare(struct snd_pcm_substream *substream,
@@ -559,6 +745,7 @@ static const struct snd_soc_dai_ops bcm2835_i2s_dai_ops = {
559 .hw_params = bcm2835_i2s_hw_params, 745 .hw_params = bcm2835_i2s_hw_params,
560 .set_fmt = bcm2835_i2s_set_dai_fmt, 746 .set_fmt = bcm2835_i2s_set_dai_fmt,
561 .set_bclk_ratio = bcm2835_i2s_set_dai_bclk_ratio, 747 .set_bclk_ratio = bcm2835_i2s_set_dai_bclk_ratio,
748 .set_tdm_slot = bcm2835_i2s_set_dai_tdm_slot,
562}; 749};
563 750
564static int bcm2835_i2s_dai_probe(struct snd_soc_dai *dai) 751static int bcm2835_i2s_dai_probe(struct snd_soc_dai *dai)
@@ -578,7 +765,9 @@ static struct snd_soc_dai_driver bcm2835_i2s_dai = {
578 .playback = { 765 .playback = {
579 .channels_min = 2, 766 .channels_min = 2,
580 .channels_max = 2, 767 .channels_max = 2,
581 .rates = SNDRV_PCM_RATE_8000_192000, 768 .rates = SNDRV_PCM_RATE_CONTINUOUS,
769 .rate_min = 8000,
770 .rate_max = 384000,
582 .formats = SNDRV_PCM_FMTBIT_S16_LE 771 .formats = SNDRV_PCM_FMTBIT_S16_LE
583 | SNDRV_PCM_FMTBIT_S24_LE 772 | SNDRV_PCM_FMTBIT_S24_LE
584 | SNDRV_PCM_FMTBIT_S32_LE 773 | SNDRV_PCM_FMTBIT_S32_LE
@@ -586,13 +775,16 @@ static struct snd_soc_dai_driver bcm2835_i2s_dai = {
586 .capture = { 775 .capture = {
587 .channels_min = 2, 776 .channels_min = 2,
588 .channels_max = 2, 777 .channels_max = 2,
589 .rates = SNDRV_PCM_RATE_8000_192000, 778 .rates = SNDRV_PCM_RATE_CONTINUOUS,
779 .rate_min = 8000,
780 .rate_max = 384000,
590 .formats = SNDRV_PCM_FMTBIT_S16_LE 781 .formats = SNDRV_PCM_FMTBIT_S16_LE
591 | SNDRV_PCM_FMTBIT_S24_LE 782 | SNDRV_PCM_FMTBIT_S24_LE
592 | SNDRV_PCM_FMTBIT_S32_LE 783 | SNDRV_PCM_FMTBIT_S32_LE
593 }, 784 },
594 .ops = &bcm2835_i2s_dai_ops, 785 .ops = &bcm2835_i2s_dai_ops,
595 .symmetric_rates = 1 786 .symmetric_rates = 1,
787 .symmetric_samplebits = 1,
596}; 788};
597 789
598static bool bcm2835_i2s_volatile_reg(struct device *dev, unsigned int reg) 790static bool bcm2835_i2s_volatile_reg(struct device *dev, unsigned int reg)
@@ -699,9 +891,6 @@ static int bcm2835_i2s_probe(struct platform_device *pdev)
699 dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].flags = 891 dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].flags =
700 SND_DMAENGINE_PCM_DAI_FLAG_PACK; 892 SND_DMAENGINE_PCM_DAI_FLAG_PACK;
701 893
702 /* BCLK ratio - use default */
703 dev->bclk_ratio = 0;
704
705 /* Store the pdev */ 894 /* Store the pdev */
706 dev->dev = &pdev->dev; 895 dev->dev = &pdev->dev;
707 dev_set_drvdata(&pdev->dev, dev); 896 dev_set_drvdata(&pdev->dev, dev);
diff --git a/sound/soc/bcm/cygnus-ssp.c b/sound/soc/bcm/cygnus-ssp.c
index 15c438f0f22d..abafadc0b534 100644
--- a/sound/soc/bcm/cygnus-ssp.c
+++ b/sound/soc/bcm/cygnus-ssp.c
@@ -655,23 +655,10 @@ static int cygnus_ssp_hw_params(struct snd_pcm_substream *substream,
655 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 655 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
656 value = readl(aio->cygaud->audio + aio->regs.bf_sourcech_cfg); 656 value = readl(aio->cygaud->audio + aio->regs.bf_sourcech_cfg);
657 value &= ~BIT(BF_SRC_CFGX_BUFFER_PAIR_ENABLE); 657 value &= ~BIT(BF_SRC_CFGX_BUFFER_PAIR_ENABLE);
658 /* Configure channels as mono or stereo/TDM */ 658 value &= ~BIT(BF_SRC_CFGX_SAMPLE_CH_MODE);
659 if (params_channels(params) == 1)
660 value |= BIT(BF_SRC_CFGX_SAMPLE_CH_MODE);
661 else
662 value &= ~BIT(BF_SRC_CFGX_SAMPLE_CH_MODE);
663 writel(value, aio->cygaud->audio + aio->regs.bf_sourcech_cfg); 659 writel(value, aio->cygaud->audio + aio->regs.bf_sourcech_cfg);
664 660
665 switch (params_format(params)) { 661 switch (params_format(params)) {
666 case SNDRV_PCM_FORMAT_S8:
667 if (aio->port_type == PORT_SPDIF) {
668 dev_err(aio->cygaud->dev,
669 "SPDIF does not support 8bit format\n");
670 return -EINVAL;
671 }
672 bitres = 8;
673 break;
674
675 case SNDRV_PCM_FORMAT_S16_LE: 662 case SNDRV_PCM_FORMAT_S16_LE:
676 bitres = 16; 663 bitres = 16;
677 break; 664 break;
@@ -842,6 +829,7 @@ int cygnus_ssp_set_custom_fsync_width(struct snd_soc_dai *cpu_dai, int len)
842 return -EINVAL; 829 return -EINVAL;
843 } 830 }
844} 831}
832EXPORT_SYMBOL_GPL(cygnus_ssp_set_custom_fsync_width);
845 833
846static int cygnus_ssp_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) 834static int cygnus_ssp_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
847{ 835{
@@ -998,7 +986,7 @@ static int cygnus_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai,
998 986
999 active_slots = hweight32(tx_mask); 987 active_slots = hweight32(tx_mask);
1000 988
1001 if ((active_slots < 0) || (active_slots > 16)) 989 if (active_slots > 16)
1002 return -EINVAL; 990 return -EINVAL;
1003 991
1004 /* Slot value must be even */ 992 /* Slot value must be even */
@@ -1136,15 +1124,21 @@ static const struct snd_soc_dai_ops cygnus_ssp_dai_ops = {
1136 .set_tdm_slot = cygnus_set_dai_tdm_slot, 1124 .set_tdm_slot = cygnus_set_dai_tdm_slot,
1137}; 1125};
1138 1126
1127static const struct snd_soc_dai_ops cygnus_spdif_dai_ops = {
1128 .startup = cygnus_ssp_startup,
1129 .shutdown = cygnus_ssp_shutdown,
1130 .trigger = cygnus_ssp_trigger,
1131 .hw_params = cygnus_ssp_hw_params,
1132 .set_sysclk = cygnus_ssp_set_sysclk,
1133};
1139 1134
1140#define INIT_CPU_DAI(num) { \ 1135#define INIT_CPU_DAI(num) { \
1141 .name = "cygnus-ssp" #num, \ 1136 .name = "cygnus-ssp" #num, \
1142 .playback = { \ 1137 .playback = { \
1143 .channels_min = 1, \ 1138 .channels_min = 2, \
1144 .channels_max = 16, \ 1139 .channels_max = 16, \
1145 .rates = SNDRV_PCM_RATE_KNOT, \ 1140 .rates = SNDRV_PCM_RATE_KNOT, \
1146 .formats = SNDRV_PCM_FMTBIT_S8 | \ 1141 .formats = SNDRV_PCM_FMTBIT_S16_LE | \
1147 SNDRV_PCM_FMTBIT_S16_LE | \
1148 SNDRV_PCM_FMTBIT_S32_LE, \ 1142 SNDRV_PCM_FMTBIT_S32_LE, \
1149 }, \ 1143 }, \
1150 .capture = { \ 1144 .capture = { \
@@ -1152,7 +1146,7 @@ static const struct snd_soc_dai_ops cygnus_ssp_dai_ops = {
1152 .channels_max = 16, \ 1146 .channels_max = 16, \
1153 .rates = SNDRV_PCM_RATE_KNOT, \ 1147 .rates = SNDRV_PCM_RATE_KNOT, \
1154 .formats = SNDRV_PCM_FMTBIT_S16_LE | \ 1148 .formats = SNDRV_PCM_FMTBIT_S16_LE | \
1155 SNDRV_PCM_FMTBIT_S32_LE, \ 1149 SNDRV_PCM_FMTBIT_S32_LE, \
1156 }, \ 1150 }, \
1157 .ops = &cygnus_ssp_dai_ops, \ 1151 .ops = &cygnus_ssp_dai_ops, \
1158 .suspend = cygnus_ssp_suspend, \ 1152 .suspend = cygnus_ssp_suspend, \
@@ -1174,7 +1168,7 @@ static const struct snd_soc_dai_driver cygnus_spdif_dai_info = {
1174 .formats = SNDRV_PCM_FMTBIT_S16_LE | 1168 .formats = SNDRV_PCM_FMTBIT_S16_LE |
1175 SNDRV_PCM_FMTBIT_S32_LE, 1169 SNDRV_PCM_FMTBIT_S32_LE,
1176 }, 1170 },
1177 .ops = &cygnus_ssp_dai_ops, 1171 .ops = &cygnus_spdif_dai_ops,
1178 .suspend = cygnus_ssp_suspend, 1172 .suspend = cygnus_ssp_suspend,
1179 .resume = cygnus_ssp_resume, 1173 .resume = cygnus_ssp_resume,
1180}; 1174};
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index c367d11079bc..a42ddbc93f3d 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -214,9 +214,9 @@ config SND_SOC_ALL_CODECS
214 select SND_SOC_WM8998 if MFD_WM8998 214 select SND_SOC_WM8998 if MFD_WM8998
215 select SND_SOC_WM9081 if I2C 215 select SND_SOC_WM9081 if I2C
216 select SND_SOC_WM9090 if I2C 216 select SND_SOC_WM9090 if I2C
217 select SND_SOC_WM9705 if SND_SOC_AC97_BUS 217 select SND_SOC_WM9705 if (SND_SOC_AC97_BUS || SND_SOC_AC97_BUS_NEW)
218 select SND_SOC_WM9712 if SND_SOC_AC97_BUS 218 select SND_SOC_WM9712 if (SND_SOC_AC97_BUS || SND_SOC_AC97_BUS_NEW)
219 select SND_SOC_WM9713 if SND_SOC_AC97_BUS 219 select SND_SOC_WM9713 if (SND_SOC_AC97_BUS || SND_SOC_AC97_BUS_NEW)
220 help 220 help
221 Normally ASoC codec drivers are only built if a machine driver which 221 Normally ASoC codec drivers are only built if a machine driver which
222 uses them is also built since they are only usable with a machine 222 uses them is also built since they are only usable with a machine
@@ -749,6 +749,10 @@ config SND_SOC_RT5514
749config SND_SOC_RT5514_SPI 749config SND_SOC_RT5514_SPI
750 tristate 750 tristate
751 751
752config SND_SOC_RT5514_SPI_BUILTIN
753 bool # force RT5514_SPI to be built-in to avoid link errors
754 default SND_SOC_RT5514=y && SND_SOC_RT5514_SPI=m
755
752config SND_SOC_RT5616 756config SND_SOC_RT5616
753 tristate "Realtek RT5616 CODEC" 757 tristate "Realtek RT5616 CODEC"
754 depends on I2C 758 depends on I2C
@@ -1128,14 +1132,17 @@ config SND_SOC_WM9090
1128config SND_SOC_WM9705 1132config SND_SOC_WM9705
1129 tristate 1133 tristate
1130 select REGMAP_AC97 1134 select REGMAP_AC97
1135 select AC97_BUS_COMPAT if AC97_BUS_NEW
1131 1136
1132config SND_SOC_WM9712 1137config SND_SOC_WM9712
1133 tristate 1138 tristate
1134 select REGMAP_AC97 1139 select REGMAP_AC97
1140 select AC97_BUS_COMPAT if AC97_BUS_NEW
1135 1141
1136config SND_SOC_WM9713 1142config SND_SOC_WM9713
1137 tristate 1143 tristate
1138 select REGMAP_AC97 1144 select REGMAP_AC97
1145 select AC97_BUS_COMPAT if AC97_BUS_NEW
1139 1146
1140config SND_SOC_ZX_AUD96P22 1147config SND_SOC_ZX_AUD96P22
1141 tristate "ZTE ZX AUD96P22 CODEC" 1148 tristate "ZTE ZX AUD96P22 CODEC"
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 05018b7ca72b..0001069ce2a7 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -360,6 +360,7 @@ obj-$(CONFIG_SND_SOC_RT286) += snd-soc-rt286.o
360obj-$(CONFIG_SND_SOC_RT298) += snd-soc-rt298.o 360obj-$(CONFIG_SND_SOC_RT298) += snd-soc-rt298.o
361obj-$(CONFIG_SND_SOC_RT5514) += snd-soc-rt5514.o 361obj-$(CONFIG_SND_SOC_RT5514) += snd-soc-rt5514.o
362obj-$(CONFIG_SND_SOC_RT5514_SPI) += snd-soc-rt5514-spi.o 362obj-$(CONFIG_SND_SOC_RT5514_SPI) += snd-soc-rt5514-spi.o
363obj-$(CONFIG_SND_SOC_RT5514_SPI_BUILTIN) += snd-soc-rt5514-spi.o
363obj-$(CONFIG_SND_SOC_RT5616) += snd-soc-rt5616.o 364obj-$(CONFIG_SND_SOC_RT5616) += snd-soc-rt5616.o
364obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o 365obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
365obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o 366obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
index a1149f6a8450..b3375e19598a 100644
--- a/sound/soc/codecs/arizona.c
+++ b/sound/soc/codecs/arizona.c
@@ -13,6 +13,7 @@
13#include <linux/delay.h> 13#include <linux/delay.h>
14#include <linux/gcd.h> 14#include <linux/gcd.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/of.h>
16#include <linux/pm_runtime.h> 17#include <linux/pm_runtime.h>
17#include <sound/pcm.h> 18#include <sound/pcm.h>
18#include <sound/pcm_params.h> 19#include <sound/pcm_params.h>
@@ -293,16 +294,99 @@ int arizona_init_gpio(struct snd_soc_codec *codec)
293} 294}
294EXPORT_SYMBOL_GPL(arizona_init_gpio); 295EXPORT_SYMBOL_GPL(arizona_init_gpio);
295 296
296int arizona_init_notifiers(struct snd_soc_codec *codec) 297int arizona_init_common(struct arizona *arizona)
297{ 298{
298 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec); 299 struct arizona_pdata *pdata = &arizona->pdata;
299 struct arizona *arizona = priv->arizona; 300 unsigned int val, mask;
301 int i;
300 302
301 BLOCKING_INIT_NOTIFIER_HEAD(&arizona->notifier); 303 BLOCKING_INIT_NOTIFIER_HEAD(&arizona->notifier);
302 304
305 for (i = 0; i < ARIZONA_MAX_OUTPUT; ++i) {
306 /* Default is 0 so noop with defaults */
307 if (pdata->out_mono[i])
308 val = ARIZONA_OUT1_MONO;
309 else
310 val = 0;
311
312 regmap_update_bits(arizona->regmap,
313 ARIZONA_OUTPUT_PATH_CONFIG_1L + (i * 8),
314 ARIZONA_OUT1_MONO, val);
315 }
316
317 for (i = 0; i < ARIZONA_MAX_PDM_SPK; i++) {
318 if (pdata->spk_mute[i])
319 regmap_update_bits(arizona->regmap,
320 ARIZONA_PDM_SPK1_CTRL_1 + (i * 2),
321 ARIZONA_SPK1_MUTE_ENDIAN_MASK |
322 ARIZONA_SPK1_MUTE_SEQ1_MASK,
323 pdata->spk_mute[i]);
324
325 if (pdata->spk_fmt[i])
326 regmap_update_bits(arizona->regmap,
327 ARIZONA_PDM_SPK1_CTRL_2 + (i * 2),
328 ARIZONA_SPK1_FMT_MASK,
329 pdata->spk_fmt[i]);
330 }
331
332 for (i = 0; i < ARIZONA_MAX_INPUT; i++) {
333 /* Default for both is 0 so noop with defaults */
334 val = pdata->dmic_ref[i] << ARIZONA_IN1_DMIC_SUP_SHIFT;
335 if (pdata->inmode[i] & ARIZONA_INMODE_DMIC)
336 val |= 1 << ARIZONA_IN1_MODE_SHIFT;
337
338 switch (arizona->type) {
339 case WM8998:
340 case WM1814:
341 regmap_update_bits(arizona->regmap,
342 ARIZONA_ADC_DIGITAL_VOLUME_1L + (i * 8),
343 ARIZONA_IN1L_SRC_SE_MASK,
344 (pdata->inmode[i] & ARIZONA_INMODE_SE)
345 << ARIZONA_IN1L_SRC_SE_SHIFT);
346
347 regmap_update_bits(arizona->regmap,
348 ARIZONA_ADC_DIGITAL_VOLUME_1R + (i * 8),
349 ARIZONA_IN1R_SRC_SE_MASK,
350 (pdata->inmode[i] & ARIZONA_INMODE_SE)
351 << ARIZONA_IN1R_SRC_SE_SHIFT);
352
353 mask = ARIZONA_IN1_DMIC_SUP_MASK |
354 ARIZONA_IN1_MODE_MASK;
355 break;
356 default:
357 if (pdata->inmode[i] & ARIZONA_INMODE_SE)
358 val |= 1 << ARIZONA_IN1_SINGLE_ENDED_SHIFT;
359
360 mask = ARIZONA_IN1_DMIC_SUP_MASK |
361 ARIZONA_IN1_MODE_MASK |
362 ARIZONA_IN1_SINGLE_ENDED_MASK;
363 break;
364 }
365
366 regmap_update_bits(arizona->regmap,
367 ARIZONA_IN1L_CONTROL + (i * 8),
368 mask, val);
369 }
370
303 return 0; 371 return 0;
304} 372}
305EXPORT_SYMBOL_GPL(arizona_init_notifiers); 373EXPORT_SYMBOL_GPL(arizona_init_common);
374
375int arizona_init_vol_limit(struct arizona *arizona)
376{
377 int i;
378
379 for (i = 0; i < ARRAY_SIZE(arizona->pdata.out_vol_limit); ++i) {
380 if (arizona->pdata.out_vol_limit[i])
381 regmap_update_bits(arizona->regmap,
382 ARIZONA_DAC_VOLUME_LIMIT_1L + i * 4,
383 ARIZONA_OUT1L_VOL_LIM_MASK,
384 arizona->pdata.out_vol_limit[i]);
385 }
386
387 return 0;
388}
389EXPORT_SYMBOL_GPL(arizona_init_vol_limit);
306 390
307const char * const arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS] = { 391const char * const arizona_mixer_texts[ARIZONA_NUM_MIXER_INPUTS] = {
308 "None", 392 "None",
@@ -2695,6 +2779,80 @@ int arizona_lhpf_coeff_put(struct snd_kcontrol *kcontrol,
2695} 2779}
2696EXPORT_SYMBOL_GPL(arizona_lhpf_coeff_put); 2780EXPORT_SYMBOL_GPL(arizona_lhpf_coeff_put);
2697 2781
2782int arizona_of_get_audio_pdata(struct arizona *arizona)
2783{
2784 struct arizona_pdata *pdata = &arizona->pdata;
2785 struct device_node *np = arizona->dev->of_node;
2786 struct property *prop;
2787 const __be32 *cur;
2788 u32 val;
2789 u32 pdm_val[ARIZONA_MAX_PDM_SPK];
2790 int ret;
2791 int count = 0;
2792
2793 count = 0;
2794 of_property_for_each_u32(np, "wlf,inmode", prop, cur, val) {
2795 if (count == ARRAY_SIZE(pdata->inmode))
2796 break;
2797
2798 pdata->inmode[count] = val;
2799 count++;
2800 }
2801
2802 count = 0;
2803 of_property_for_each_u32(np, "wlf,dmic-ref", prop, cur, val) {
2804 if (count == ARRAY_SIZE(pdata->dmic_ref))
2805 break;
2806
2807 pdata->dmic_ref[count] = val;
2808 count++;
2809 }
2810
2811 count = 0;
2812 of_property_for_each_u32(np, "wlf,out-mono", prop, cur, val) {
2813 if (count == ARRAY_SIZE(pdata->out_mono))
2814 break;
2815
2816 pdata->out_mono[count] = !!val;
2817 count++;
2818 }
2819
2820 count = 0;
2821 of_property_for_each_u32(np, "wlf,max-channels-clocked", prop, cur, val) {
2822 if (count == ARRAY_SIZE(pdata->max_channels_clocked))
2823 break;
2824
2825 pdata->max_channels_clocked[count] = val;
2826 count++;
2827 }
2828
2829 count = 0;
2830 of_property_for_each_u32(np, "wlf,out-volume-limit", prop, cur, val) {
2831 if (count == ARRAY_SIZE(pdata->out_vol_limit))
2832 break;
2833
2834 pdata->out_vol_limit[count] = val;
2835 count++;
2836 }
2837
2838 ret = of_property_read_u32_array(np, "wlf,spk-fmt",
2839 pdm_val, ARRAY_SIZE(pdm_val));
2840
2841 if (ret >= 0)
2842 for (count = 0; count < ARRAY_SIZE(pdata->spk_fmt); ++count)
2843 pdata->spk_fmt[count] = pdm_val[count];
2844
2845 ret = of_property_read_u32_array(np, "wlf,spk-mute",
2846 pdm_val, ARRAY_SIZE(pdm_val));
2847
2848 if (ret >= 0)
2849 for (count = 0; count < ARRAY_SIZE(pdata->spk_mute); ++count)
2850 pdata->spk_mute[count] = pdm_val[count];
2851
2852 return 0;
2853}
2854EXPORT_SYMBOL_GPL(arizona_of_get_audio_pdata);
2855
2698MODULE_DESCRIPTION("ASoC Wolfson Arizona class device support"); 2856MODULE_DESCRIPTION("ASoC Wolfson Arizona class device support");
2699MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 2857MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
2700MODULE_LICENSE("GPL"); 2858MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/arizona.h b/sound/soc/codecs/arizona.h
index 1822e3b3de80..dfdf6d8c9687 100644
--- a/sound/soc/codecs/arizona.h
+++ b/sound/soc/codecs/arizona.h
@@ -313,7 +313,9 @@ int arizona_set_fll(struct arizona_fll *fll, int source,
313int arizona_init_spk(struct snd_soc_codec *codec); 313int arizona_init_spk(struct snd_soc_codec *codec);
314int arizona_init_gpio(struct snd_soc_codec *codec); 314int arizona_init_gpio(struct snd_soc_codec *codec);
315int arizona_init_mono(struct snd_soc_codec *codec); 315int arizona_init_mono(struct snd_soc_codec *codec);
316int arizona_init_notifiers(struct snd_soc_codec *codec); 316
317int arizona_init_common(struct arizona *arizona);
318int arizona_init_vol_limit(struct arizona *arizona);
317 319
318int arizona_init_spk_irqs(struct arizona *arizona); 320int arizona_init_spk_irqs(struct arizona *arizona);
319int arizona_free_spk_irqs(struct arizona *arizona); 321int arizona_free_spk_irqs(struct arizona *arizona);
@@ -350,4 +352,6 @@ static inline int arizona_unregister_notifier(struct snd_soc_codec *codec,
350 return blocking_notifier_chain_unregister(&arizona->notifier, nb); 352 return blocking_notifier_chain_unregister(&arizona->notifier, nb);
351} 353}
352 354
355int arizona_of_get_audio_pdata(struct arizona *arizona);
356
353#endif 357#endif
diff --git a/sound/soc/codecs/cs43130.c b/sound/soc/codecs/cs43130.c
index 643e37fc218e..5ba0edc19df4 100644
--- a/sound/soc/codecs/cs43130.c
+++ b/sound/soc/codecs/cs43130.c
@@ -909,6 +909,7 @@ static int cs43130_hw_params(struct snd_pcm_substream *substream,
909 regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2, 909 regmap_update_bits(cs43130->regmap, CS43130_DSD_PATH_CTL_2,
910 CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_XSP << 910 CS43130_DSD_SRC_MASK, CS43130_DSD_SRC_XSP <<
911 CS43130_DSD_SRC_SHIFT); 911 CS43130_DSD_SRC_SHIFT);
912 break;
912 } 913 }
913 914
914 if (!sclk && cs43130->dais[dai->id].dai_mode == SND_SOC_DAIFMT_CBM_CFM) 915 if (!sclk && cs43130->dais[dai->id].dai_mode == SND_SOC_DAIFMT_CBM_CFM)
@@ -1039,6 +1040,7 @@ static int cs43130_pcm_ch_put(struct snd_kcontrol *kcontrol,
1039 else 1040 else
1040 regmap_multi_reg_write(cs43130->regmap, pcm_ch_dis_seq, 1041 regmap_multi_reg_write(cs43130->regmap, pcm_ch_dis_seq,
1041 ARRAY_SIZE(pcm_ch_dis_seq)); 1042 ARRAY_SIZE(pcm_ch_dis_seq));
1043 break;
1042 } 1044 }
1043 1045
1044 return snd_soc_put_enum_double(kcontrol, ucontrol); 1046 return snd_soc_put_enum_double(kcontrol, ucontrol);
@@ -1152,6 +1154,7 @@ static int cs43130_dsd_event(struct snd_soc_dapm_widget *w,
1152 case CS4399_CHIP_ID: 1154 case CS4399_CHIP_ID:
1153 regmap_multi_reg_write(cs43130->regmap, dsd_seq, 1155 regmap_multi_reg_write(cs43130->regmap, dsd_seq,
1154 ARRAY_SIZE(dsd_seq)); 1156 ARRAY_SIZE(dsd_seq));
1157 break;
1155 } 1158 }
1156 break; 1159 break;
1157 case SND_SOC_DAPM_POST_PMU: 1160 case SND_SOC_DAPM_POST_PMU:
@@ -1162,6 +1165,7 @@ static int cs43130_dsd_event(struct snd_soc_dapm_widget *w,
1162 case CS4399_CHIP_ID: 1165 case CS4399_CHIP_ID:
1163 regmap_multi_reg_write(cs43130->regmap, unmute_seq, 1166 regmap_multi_reg_write(cs43130->regmap, unmute_seq,
1164 ARRAY_SIZE(unmute_seq)); 1167 ARRAY_SIZE(unmute_seq));
1168 break;
1165 } 1169 }
1166 break; 1170 break;
1167 case SND_SOC_DAPM_PRE_PMD: 1171 case SND_SOC_DAPM_PRE_PMD:
@@ -1184,6 +1188,7 @@ static int cs43130_dsd_event(struct snd_soc_dapm_widget *w,
1184 regmap_update_bits(cs43130->regmap, 1188 regmap_update_bits(cs43130->regmap,
1185 CS43130_DSD_PATH_CTL_1, 1189 CS43130_DSD_PATH_CTL_1,
1186 CS43130_MUTE_MASK, CS43130_MUTE_EN); 1190 CS43130_MUTE_MASK, CS43130_MUTE_EN);
1191 break;
1187 } 1192 }
1188 break; 1193 break;
1189 default: 1194 default:
@@ -1206,6 +1211,7 @@ static int cs43130_pcm_event(struct snd_soc_dapm_widget *w,
1206 case CS4399_CHIP_ID: 1211 case CS4399_CHIP_ID:
1207 regmap_multi_reg_write(cs43130->regmap, pcm_seq, 1212 regmap_multi_reg_write(cs43130->regmap, pcm_seq,
1208 ARRAY_SIZE(pcm_seq)); 1213 ARRAY_SIZE(pcm_seq));
1214 break;
1209 } 1215 }
1210 break; 1216 break;
1211 case SND_SOC_DAPM_POST_PMU: 1217 case SND_SOC_DAPM_POST_PMU:
@@ -1216,6 +1222,7 @@ static int cs43130_pcm_event(struct snd_soc_dapm_widget *w,
1216 case CS4399_CHIP_ID: 1222 case CS4399_CHIP_ID:
1217 regmap_multi_reg_write(cs43130->regmap, unmute_seq, 1223 regmap_multi_reg_write(cs43130->regmap, unmute_seq,
1218 ARRAY_SIZE(unmute_seq)); 1224 ARRAY_SIZE(unmute_seq));
1225 break;
1219 } 1226 }
1220 break; 1227 break;
1221 case SND_SOC_DAPM_PRE_PMD: 1228 case SND_SOC_DAPM_PRE_PMD:
@@ -1238,6 +1245,7 @@ static int cs43130_pcm_event(struct snd_soc_dapm_widget *w,
1238 regmap_update_bits(cs43130->regmap, 1245 regmap_update_bits(cs43130->regmap,
1239 CS43130_PCM_PATH_CTL_1, 1246 CS43130_PCM_PATH_CTL_1,
1240 CS43130_MUTE_MASK, CS43130_MUTE_EN); 1247 CS43130_MUTE_MASK, CS43130_MUTE_EN);
1248 break;
1241 } 1249 }
1242 break; 1250 break;
1243 default: 1251 default:
@@ -1277,6 +1285,7 @@ static int cs43130_dac_event(struct snd_soc_dapm_widget *w,
1277 case CS43198_CHIP_ID: 1285 case CS43198_CHIP_ID:
1278 regmap_multi_reg_write(cs43130->regmap, pop_free_seq2, 1286 regmap_multi_reg_write(cs43130->regmap, pop_free_seq2,
1279 ARRAY_SIZE(pop_free_seq2)); 1287 ARRAY_SIZE(pop_free_seq2));
1288 break;
1280 } 1289 }
1281 break; 1290 break;
1282 case SND_SOC_DAPM_POST_PMU: 1291 case SND_SOC_DAPM_POST_PMU:
@@ -1301,6 +1310,7 @@ static int cs43130_dac_event(struct snd_soc_dapm_widget *w,
1301 case CS43198_CHIP_ID: 1310 case CS43198_CHIP_ID:
1302 usleep_range(12000, 12010); 1311 usleep_range(12000, 12010);
1303 regmap_write(cs43130->regmap, CS43130_DXD13, 0); 1312 regmap_write(cs43130->regmap, CS43130_DXD13, 0);
1313 break;
1304 } 1314 }
1305 1315
1306 regmap_write(cs43130->regmap, CS43130_DXD1, 0); 1316 regmap_write(cs43130->regmap, CS43130_DXD1, 0);
@@ -1311,6 +1321,7 @@ static int cs43130_dac_event(struct snd_soc_dapm_widget *w,
1311 case CS4399_CHIP_ID: 1321 case CS4399_CHIP_ID:
1312 regmap_multi_reg_write(cs43130->regmap, dac_postpmd_seq, 1322 regmap_multi_reg_write(cs43130->regmap, dac_postpmd_seq,
1313 ARRAY_SIZE(dac_postpmd_seq)); 1323 ARRAY_SIZE(dac_postpmd_seq));
1324 break;
1314 } 1325 }
1315 break; 1326 break;
1316 default: 1327 default:
@@ -2133,6 +2144,7 @@ exit:
2133 cs43130_hpload_proc(cs43130, hp_dis_cal_seq2, 2144 cs43130_hpload_proc(cs43130, hp_dis_cal_seq2,
2134 ARRAY_SIZE(hp_dis_cal_seq2), 2145 ARRAY_SIZE(hp_dis_cal_seq2),
2135 CS43130_HPLOAD_OFF_INT, ac_idx); 2146 CS43130_HPLOAD_OFF_INT, ac_idx);
2147 break;
2136 } 2148 }
2137 2149
2138 regmap_multi_reg_write(cs43130->regmap, hp_cln_seq, 2150 regmap_multi_reg_write(cs43130->regmap, hp_cln_seq,
@@ -2543,6 +2555,7 @@ static int cs43130_i2c_probe(struct i2c_client *client,
2543 digital_hp_routes; 2555 digital_hp_routes;
2544 soc_codec_dev_cs43130.component_driver.num_dapm_routes = 2556 soc_codec_dev_cs43130.component_driver.num_dapm_routes =
2545 ARRAY_SIZE(digital_hp_routes); 2557 ARRAY_SIZE(digital_hp_routes);
2558 break;
2546 } 2559 }
2547 2560
2548 ret = snd_soc_register_codec(&client->dev, &soc_codec_dev_cs43130, 2561 ret = snd_soc_register_codec(&client->dev, &soc_codec_dev_cs43130,
@@ -2586,8 +2599,7 @@ static int cs43130_i2c_remove(struct i2c_client *client)
2586 device_remove_file(&client->dev, &dev_attr_hpload_ac_r); 2599 device_remove_file(&client->dev, &dev_attr_hpload_ac_r);
2587 } 2600 }
2588 2601
2589 if (cs43130->reset_gpio) 2602 gpiod_set_value_cansleep(cs43130->reset_gpio, 0);
2590 gpiod_set_value_cansleep(cs43130->reset_gpio, 0);
2591 2603
2592 pm_runtime_disable(&client->dev); 2604 pm_runtime_disable(&client->dev);
2593 regulator_bulk_disable(CS43130_NUM_SUPPLIES, cs43130->supplies); 2605 regulator_bulk_disable(CS43130_NUM_SUPPLIES, cs43130->supplies);
diff --git a/sound/soc/codecs/cs47l24.c b/sound/soc/codecs/cs47l24.c
index e09fc8f037f1..94c0209977d0 100644
--- a/sound/soc/codecs/cs47l24.c
+++ b/sound/soc/codecs/cs47l24.c
@@ -1130,7 +1130,6 @@ static int cs47l24_codec_probe(struct snd_soc_codec *codec)
1130 1130
1131 arizona_init_gpio(codec); 1131 arizona_init_gpio(codec);
1132 arizona_init_mono(codec); 1132 arizona_init_mono(codec);
1133 arizona_init_notifiers(codec);
1134 1133
1135 ret = wm_adsp2_codec_probe(&priv->core.adsp[1], codec); 1134 ret = wm_adsp2_codec_probe(&priv->core.adsp[1], codec);
1136 if (ret) 1135 if (ret)
@@ -1230,6 +1229,14 @@ static int cs47l24_probe(struct platform_device *pdev)
1230 if (!cs47l24) 1229 if (!cs47l24)
1231 return -ENOMEM; 1230 return -ENOMEM;
1232 1231
1232 if (IS_ENABLED(CONFIG_OF)) {
1233 if (!dev_get_platdata(arizona->dev)) {
1234 ret = arizona_of_get_audio_pdata(arizona);
1235 if (ret < 0)
1236 return ret;
1237 }
1238 }
1239
1233 platform_set_drvdata(pdev, cs47l24); 1240 platform_set_drvdata(pdev, cs47l24);
1234 1241
1235 cs47l24->core.arizona = arizona; 1242 cs47l24->core.arizona = arizona;
@@ -1288,6 +1295,11 @@ static int cs47l24_probe(struct platform_device *pdev)
1288 return ret; 1295 return ret;
1289 } 1296 }
1290 1297
1298 arizona_init_common(arizona);
1299
1300 ret = arizona_init_vol_limit(arizona);
1301 if (ret < 0)
1302 goto err_dsp_irq;
1291 ret = arizona_init_spk_irqs(arizona); 1303 ret = arizona_init_spk_irqs(arizona);
1292 if (ret < 0) 1304 if (ret < 0)
1293 goto err_dsp_irq; 1305 goto err_dsp_irq;
diff --git a/sound/soc/codecs/da7213.c b/sound/soc/codecs/da7213.c
index cc0b2d2eaf15..41d9b1da27c2 100644
--- a/sound/soc/codecs/da7213.c
+++ b/sound/soc/codecs/da7213.c
@@ -1220,6 +1220,7 @@ static int da7213_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1220 struct snd_soc_codec *codec = codec_dai->codec; 1220 struct snd_soc_codec *codec = codec_dai->codec;
1221 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec); 1221 struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
1222 u8 dai_clk_mode = 0, dai_ctrl = 0; 1222 u8 dai_clk_mode = 0, dai_ctrl = 0;
1223 u8 dai_offset = 0;
1223 1224
1224 /* Set master/slave mode */ 1225 /* Set master/slave mode */
1225 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 1226 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
@@ -1234,17 +1235,46 @@ static int da7213_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1234 } 1235 }
1235 1236
1236 /* Set clock normal/inverted */ 1237 /* Set clock normal/inverted */
1237 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 1238 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1238 case SND_SOC_DAIFMT_NB_NF: 1239 case SND_SOC_DAIFMT_I2S:
1239 break; 1240 case SND_SOC_DAIFMT_LEFT_J:
1240 case SND_SOC_DAIFMT_NB_IF: 1241 case SND_SOC_DAIFMT_RIGHT_J:
1241 dai_clk_mode |= DA7213_DAI_WCLK_POL_INV; 1242 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1242 break; 1243 case SND_SOC_DAIFMT_NB_NF:
1243 case SND_SOC_DAIFMT_IB_NF: 1244 break;
1244 dai_clk_mode |= DA7213_DAI_CLK_POL_INV; 1245 case SND_SOC_DAIFMT_NB_IF:
1246 dai_clk_mode |= DA7213_DAI_WCLK_POL_INV;
1247 break;
1248 case SND_SOC_DAIFMT_IB_NF:
1249 dai_clk_mode |= DA7213_DAI_CLK_POL_INV;
1250 break;
1251 case SND_SOC_DAIFMT_IB_IF:
1252 dai_clk_mode |= DA7213_DAI_WCLK_POL_INV |
1253 DA7213_DAI_CLK_POL_INV;
1254 break;
1255 default:
1256 return -EINVAL;
1257 }
1245 break; 1258 break;
1246 case SND_SOC_DAIFMT_IB_IF: 1259 case SND_SOC_DAI_FORMAT_DSP_A:
1247 dai_clk_mode |= DA7213_DAI_WCLK_POL_INV | DA7213_DAI_CLK_POL_INV; 1260 case SND_SOC_DAI_FORMAT_DSP_B:
1261 /* The bclk is inverted wrt ASoC conventions */
1262 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
1263 case SND_SOC_DAIFMT_NB_NF:
1264 dai_clk_mode |= DA7213_DAI_CLK_POL_INV;
1265 break;
1266 case SND_SOC_DAIFMT_NB_IF:
1267 dai_clk_mode |= DA7213_DAI_WCLK_POL_INV |
1268 DA7213_DAI_CLK_POL_INV;
1269 break;
1270 case SND_SOC_DAIFMT_IB_NF:
1271 break;
1272 case SND_SOC_DAIFMT_IB_IF:
1273 dai_clk_mode |= DA7213_DAI_WCLK_POL_INV;
1274 break;
1275 default:
1276 return -EINVAL;
1277 }
1248 break; 1278 break;
1249 default: 1279 default:
1250 return -EINVAL; 1280 return -EINVAL;
@@ -1261,6 +1291,13 @@ static int da7213_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1261 case SND_SOC_DAIFMT_RIGHT_J: 1291 case SND_SOC_DAIFMT_RIGHT_J:
1262 dai_ctrl |= DA7213_DAI_FORMAT_RIGHT_J; 1292 dai_ctrl |= DA7213_DAI_FORMAT_RIGHT_J;
1263 break; 1293 break;
1294 case SND_SOC_DAI_FORMAT_DSP_A: /* L data MSB after FRM LRC */
1295 dai_ctrl |= DA7213_DAI_FORMAT_DSP;
1296 dai_offset = 1;
1297 break;
1298 case SND_SOC_DAI_FORMAT_DSP_B: /* L data MSB during FRM LRC */
1299 dai_ctrl |= DA7213_DAI_FORMAT_DSP;
1300 break;
1264 default: 1301 default:
1265 return -EINVAL; 1302 return -EINVAL;
1266 } 1303 }
@@ -1271,6 +1308,7 @@ static int da7213_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1271 snd_soc_write(codec, DA7213_DAI_CLK_MODE, dai_clk_mode); 1308 snd_soc_write(codec, DA7213_DAI_CLK_MODE, dai_clk_mode);
1272 snd_soc_update_bits(codec, DA7213_DAI_CTRL, DA7213_DAI_FORMAT_MASK, 1309 snd_soc_update_bits(codec, DA7213_DAI_CTRL, DA7213_DAI_FORMAT_MASK,
1273 dai_ctrl); 1310 dai_ctrl);
1311 snd_soc_write(codec, DA7213_DAI_OFFSET, dai_offset);
1274 1312
1275 return 0; 1313 return 0;
1276} 1314}
diff --git a/sound/soc/codecs/da7213.h b/sound/soc/codecs/da7213.h
index 16ef56f77cd4..5a78dba1dcb5 100644
--- a/sound/soc/codecs/da7213.h
+++ b/sound/soc/codecs/da7213.h
@@ -188,6 +188,7 @@
188#define DA7213_DAI_FORMAT_I2S_MODE (0x0 << 0) 188#define DA7213_DAI_FORMAT_I2S_MODE (0x0 << 0)
189#define DA7213_DAI_FORMAT_LEFT_J (0x1 << 0) 189#define DA7213_DAI_FORMAT_LEFT_J (0x1 << 0)
190#define DA7213_DAI_FORMAT_RIGHT_J (0x2 << 0) 190#define DA7213_DAI_FORMAT_RIGHT_J (0x2 << 0)
191#define DA7213_DAI_FORMAT_DSP (0x3 << 0)
191#define DA7213_DAI_FORMAT_MASK (0x3 << 0) 192#define DA7213_DAI_FORMAT_MASK (0x3 << 0)
192#define DA7213_DAI_WORD_LENGTH_S16_LE (0x0 << 2) 193#define DA7213_DAI_WORD_LENGTH_S16_LE (0x0 << 2)
193#define DA7213_DAI_WORD_LENGTH_S20_LE (0x1 << 2) 194#define DA7213_DAI_WORD_LENGTH_S20_LE (0x1 << 2)
diff --git a/sound/soc/codecs/hdac_hdmi.c b/sound/soc/codecs/hdac_hdmi.c
index e824d47cc22b..f3b4f4dfae6a 100644
--- a/sound/soc/codecs/hdac_hdmi.c
+++ b/sound/soc/codecs/hdac_hdmi.c
@@ -942,7 +942,8 @@ static int hdac_hdmi_create_pin_port_muxs(struct hdac_ext_device *edev,
942 if (!se) 942 if (!se)
943 return -ENOMEM; 943 return -ENOMEM;
944 944
945 sprintf(kc_name, "Pin %d port %d Input", pin->nid, port->id); 945 snprintf(kc_name, NAME_SIZE, "Pin %d port %d Input",
946 pin->nid, port->id);
946 kc->name = devm_kstrdup(&edev->hdac.dev, kc_name, GFP_KERNEL); 947 kc->name = devm_kstrdup(&edev->hdac.dev, kc_name, GFP_KERNEL);
947 if (!kc->name) 948 if (!kc->name)
948 return -ENOMEM; 949 return -ENOMEM;
@@ -1452,6 +1453,8 @@ static int hdac_hdmi_parse_and_map_nid(struct hdac_ext_device *edev,
1452 int i, num_nodes; 1453 int i, num_nodes;
1453 struct hdac_device *hdac = &edev->hdac; 1454 struct hdac_device *hdac = &edev->hdac;
1454 struct hdac_hdmi_priv *hdmi = edev->private_data; 1455 struct hdac_hdmi_priv *hdmi = edev->private_data;
1456 struct hdac_hdmi_cvt *temp_cvt, *cvt_next;
1457 struct hdac_hdmi_pin *temp_pin, *pin_next;
1455 int ret; 1458 int ret;
1456 1459
1457 hdac_hdmi_skl_enable_all_pins(hdac); 1460 hdac_hdmi_skl_enable_all_pins(hdac);
@@ -1481,32 +1484,54 @@ static int hdac_hdmi_parse_and_map_nid(struct hdac_ext_device *edev,
1481 case AC_WID_AUD_OUT: 1484 case AC_WID_AUD_OUT:
1482 ret = hdac_hdmi_add_cvt(edev, nid); 1485 ret = hdac_hdmi_add_cvt(edev, nid);
1483 if (ret < 0) 1486 if (ret < 0)
1484 return ret; 1487 goto free_widgets;
1485 break; 1488 break;
1486 1489
1487 case AC_WID_PIN: 1490 case AC_WID_PIN:
1488 ret = hdac_hdmi_add_pin(edev, nid); 1491 ret = hdac_hdmi_add_pin(edev, nid);
1489 if (ret < 0) 1492 if (ret < 0)
1490 return ret; 1493 goto free_widgets;
1491 break; 1494 break;
1492 } 1495 }
1493 } 1496 }
1494 1497
1495 hdac->end_nid = nid; 1498 hdac->end_nid = nid;
1496 1499
1497 if (!hdmi->num_pin || !hdmi->num_cvt) 1500 if (!hdmi->num_pin || !hdmi->num_cvt) {
1498 return -EIO; 1501 ret = -EIO;
1502 goto free_widgets;
1503 }
1499 1504
1500 ret = hdac_hdmi_create_dais(hdac, dais, hdmi, hdmi->num_cvt); 1505 ret = hdac_hdmi_create_dais(hdac, dais, hdmi, hdmi->num_cvt);
1501 if (ret) { 1506 if (ret) {
1502 dev_err(&hdac->dev, "Failed to create dais with err: %d\n", 1507 dev_err(&hdac->dev, "Failed to create dais with err: %d\n",
1503 ret); 1508 ret);
1504 return ret; 1509 goto free_widgets;
1505 } 1510 }
1506 1511
1507 *num_dais = hdmi->num_cvt; 1512 *num_dais = hdmi->num_cvt;
1513 ret = hdac_hdmi_init_dai_map(edev);
1514 if (ret < 0)
1515 goto free_widgets;
1516
1517 return ret;
1518
1519free_widgets:
1520 list_for_each_entry_safe(temp_cvt, cvt_next, &hdmi->cvt_list, head) {
1521 list_del(&temp_cvt->head);
1522 kfree(temp_cvt->name);
1523 kfree(temp_cvt);
1524 }
1525
1526 list_for_each_entry_safe(temp_pin, pin_next, &hdmi->pin_list, head) {
1527 for (i = 0; i < temp_pin->num_ports; i++)
1528 temp_pin->ports[i].pin = NULL;
1529 kfree(temp_pin->ports);
1530 list_del(&temp_pin->head);
1531 kfree(temp_pin);
1532 }
1508 1533
1509 return hdac_hdmi_init_dai_map(edev); 1534 return ret;
1510} 1535}
1511 1536
1512static void hdac_hdmi_eld_notify_cb(void *aptr, int port, int pipe) 1537static void hdac_hdmi_eld_notify_cb(void *aptr, int port, int pipe)
@@ -1894,6 +1919,9 @@ static void hdac_hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx,
1894 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx); 1919 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
1895 struct hdac_hdmi_port *port; 1920 struct hdac_hdmi_port *port;
1896 1921
1922 if (!pcm)
1923 return;
1924
1897 if (list_empty(&pcm->port_list)) 1925 if (list_empty(&pcm->port_list))
1898 return; 1926 return;
1899 1927
@@ -1912,6 +1940,9 @@ static bool is_hdac_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx)
1912 struct hdac_hdmi_priv *hdmi = edev->private_data; 1940 struct hdac_hdmi_priv *hdmi = edev->private_data;
1913 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx); 1941 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
1914 1942
1943 if (!pcm)
1944 return false;
1945
1915 if (list_empty(&pcm->port_list)) 1946 if (list_empty(&pcm->port_list))
1916 return false; 1947 return false;
1917 1948
@@ -1925,6 +1956,9 @@ static int hdac_hdmi_get_spk_alloc(struct hdac_device *hdac, int pcm_idx)
1925 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx); 1956 struct hdac_hdmi_pcm *pcm = get_hdmi_pcm_from_id(hdmi, pcm_idx);
1926 struct hdac_hdmi_port *port; 1957 struct hdac_hdmi_port *port;
1927 1958
1959 if (!pcm)
1960 return 0;
1961
1928 if (list_empty(&pcm->port_list)) 1962 if (list_empty(&pcm->port_list))
1929 return 0; 1963 return 0;
1930 1964
@@ -1978,6 +2012,9 @@ static int hdac_hdmi_dev_probe(struct hdac_ext_device *edev)
1978 hdmi_priv->chmap.ops.is_pcm_attached = is_hdac_hdmi_pcm_attached; 2012 hdmi_priv->chmap.ops.is_pcm_attached = is_hdac_hdmi_pcm_attached;
1979 hdmi_priv->chmap.ops.get_spk_alloc = hdac_hdmi_get_spk_alloc; 2013 hdmi_priv->chmap.ops.get_spk_alloc = hdac_hdmi_get_spk_alloc;
1980 2014
2015 if (!hdac_id)
2016 return -ENODEV;
2017
1981 if (hdac_id->driver_data) 2018 if (hdac_id->driver_data)
1982 hdmi_priv->drv_data = 2019 hdmi_priv->drv_data =
1983 (struct hdac_hdmi_drv_data *)hdac_id->driver_data; 2020 (struct hdac_hdmi_drv_data *)hdac_id->driver_data;
diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
index 3abf82563408..5672e516bec3 100644
--- a/sound/soc/codecs/hdmi-codec.c
+++ b/sound/soc/codecs/hdmi-codec.c
@@ -303,11 +303,8 @@ enum {
303static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol, 303static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
304 struct snd_ctl_elem_info *uinfo) 304 struct snd_ctl_elem_info *uinfo)
305{ 305{
306 struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
307 struct hdmi_codec_priv *hcp = snd_soc_component_get_drvdata(component);
308
309 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; 306 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
310 uinfo->count = sizeof(hcp->eld); 307 uinfo->count = FIELD_SIZEOF(struct hdmi_codec_priv, eld);
311 308
312 return 0; 309 return 0;
313} 310}
diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c
index 13bcfb1ef9b4..f5075d1f79e6 100644
--- a/sound/soc/codecs/max98090.c
+++ b/sound/soc/codecs/max98090.c
@@ -2115,7 +2115,7 @@ static void max98090_pll_work(struct work_struct *work)
2115 if (!snd_soc_codec_is_active(codec)) 2115 if (!snd_soc_codec_is_active(codec))
2116 return; 2116 return;
2117 2117
2118 dev_info(codec->dev, "PLL unlocked\n"); 2118 dev_info_ratelimited(codec->dev, "PLL unlocked\n");
2119 2119
2120 /* Toggle shutdown OFF then ON */ 2120 /* Toggle shutdown OFF then ON */
2121 snd_soc_update_bits(codec, M98090_REG_DEVICE_SHUTDOWN, 2121 snd_soc_update_bits(codec, M98090_REG_DEVICE_SHUTDOWN,
diff --git a/sound/soc/codecs/max98925.c b/sound/soc/codecs/max98925.c
index 327eaa25c9bd..921f95fc396d 100644
--- a/sound/soc/codecs/max98925.c
+++ b/sound/soc/codecs/max98925.c
@@ -579,7 +579,7 @@ static int max98925_i2c_probe(struct i2c_client *i2c,
579 ret = PTR_ERR(max98925->regmap); 579 ret = PTR_ERR(max98925->regmap);
580 dev_err(&i2c->dev, 580 dev_err(&i2c->dev,
581 "Failed to allocate regmap: %d\n", ret); 581 "Failed to allocate regmap: %d\n", ret);
582 goto err_out; 582 return ret;
583 } 583 }
584 584
585 if (!of_property_read_u32(i2c->dev.of_node, "vmon-slot-no", &value)) { 585 if (!of_property_read_u32(i2c->dev.of_node, "vmon-slot-no", &value)) {
@@ -596,16 +596,20 @@ static int max98925_i2c_probe(struct i2c_client *i2c,
596 } 596 }
597 max98925->i_slot = value; 597 max98925->i_slot = value;
598 } 598 }
599 ret = regmap_read(max98925->regmap, 599
600 MAX98925_REV_VERSION, &reg); 600 ret = regmap_read(max98925->regmap, MAX98925_REV_VERSION, &reg);
601 if ((ret < 0) || 601 if (ret < 0) {
602 ((reg != MAX98925_VERSION) && 602 dev_err(&i2c->dev, "Read revision failed\n");
603 (reg != MAX98925_VERSION1))) { 603 return ret;
604 dev_err(&i2c->dev, 604 }
605 "device initialization error (%d 0x%02X)\n", 605
606 if ((reg != MAX98925_VERSION) && (reg != MAX98925_VERSION1)) {
607 ret = -ENODEV;
608 dev_err(&i2c->dev, "Invalid revision (%d 0x%02X)\n",
606 ret, reg); 609 ret, reg);
607 goto err_out; 610 return ret;
608 } 611 }
612
609 dev_info(&i2c->dev, "device version 0x%02X\n", reg); 613 dev_info(&i2c->dev, "device version 0x%02X\n", reg);
610 614
611 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_max98925, 615 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_max98925,
@@ -613,7 +617,6 @@ static int max98925_i2c_probe(struct i2c_client *i2c,
613 if (ret < 0) 617 if (ret < 0)
614 dev_err(&i2c->dev, 618 dev_err(&i2c->dev,
615 "Failed to register codec: %d\n", ret); 619 "Failed to register codec: %d\n", ret);
616err_out:
617 return ret; 620 return ret;
618} 621}
619 622
diff --git a/sound/soc/codecs/max98927.c b/sound/soc/codecs/max98927.c
index d9dbbe72f8ad..a1d39353719d 100644
--- a/sound/soc/codecs/max98927.c
+++ b/sound/soc/codecs/max98927.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * max98927.c -- MAX98927 ALSA Soc Audio driver 2 * max98927.c -- MAX98927 ALSA Soc Audio driver
3 * 3 *
4 * Copyright (C) 2016 Maxim Integrated Products 4 * Copyright (C) 2016-2017 Maxim Integrated Products
5 * Author: Ryan Lee <ryans.lee@maximintegrated.com> 5 * Author: Ryan Lee <ryans.lee@maximintegrated.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
@@ -146,6 +146,7 @@ static int max98927_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
146 struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec); 146 struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
147 unsigned int mode = 0; 147 unsigned int mode = 0;
148 unsigned int format = 0; 148 unsigned int format = 0;
149 bool use_pdm = false;
149 unsigned int invert = 0; 150 unsigned int invert = 0;
150 151
151 dev_dbg(codec->dev, "%s: fmt 0x%08X\n", __func__, fmt); 152 dev_dbg(codec->dev, "%s: fmt 0x%08X\n", __func__, fmt);
@@ -187,22 +188,27 @@ static int max98927_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
187 /* interface format */ 188 /* interface format */
188 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 189 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
189 case SND_SOC_DAIFMT_I2S: 190 case SND_SOC_DAIFMT_I2S:
190 max98927->iface |= SND_SOC_DAIFMT_I2S;
191 format = MAX98927_PCM_FORMAT_I2S; 191 format = MAX98927_PCM_FORMAT_I2S;
192 break; 192 break;
193 case SND_SOC_DAIFMT_LEFT_J: 193 case SND_SOC_DAIFMT_LEFT_J:
194 max98927->iface |= SND_SOC_DAIFMT_LEFT_J;
195 format = MAX98927_PCM_FORMAT_LJ; 194 format = MAX98927_PCM_FORMAT_LJ;
196 break; 195 break;
196 case SND_SOC_DAIFMT_DSP_A:
197 format = MAX98927_PCM_FORMAT_TDM_MODE1;
198 break;
199 case SND_SOC_DAIFMT_DSP_B:
200 format = MAX98927_PCM_FORMAT_TDM_MODE0;
201 break;
197 case SND_SOC_DAIFMT_PDM: 202 case SND_SOC_DAIFMT_PDM:
198 max98927->iface |= SND_SOC_DAIFMT_PDM; 203 use_pdm = true;
199 break; 204 break;
200 default: 205 default:
201 return -EINVAL; 206 return -EINVAL;
202 } 207 }
208 max98927->iface = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
203 209
204 /* pcm channel configuration */ 210 if (!use_pdm) {
205 if (max98927->iface & (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J)) { 211 /* pcm channel configuration */
206 regmap_update_bits(max98927->regmap, 212 regmap_update_bits(max98927->regmap,
207 MAX98927_R0018_PCM_RX_EN_A, 213 MAX98927_R0018_PCM_RX_EN_A,
208 MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 214 MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN,
@@ -217,13 +223,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
217 MAX98927_R003B_SPK_SRC_SEL, 223 MAX98927_R003B_SPK_SRC_SEL,
218 MAX98927_SPK_SRC_MASK, 0); 224 MAX98927_SPK_SRC_MASK, 0);
219 225
220 } else
221 regmap_update_bits(max98927->regmap, 226 regmap_update_bits(max98927->regmap,
222 MAX98927_R0018_PCM_RX_EN_A, 227 MAX98927_R0035_PDM_RX_CTRL,
223 MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0); 228 MAX98927_PDM_RX_EN_MASK, 0);
224 229 } else {
225 /* pdm channel configuration */ 230 /* pdm channel configuration */
226 if (max98927->iface & SND_SOC_DAIFMT_PDM) {
227 regmap_update_bits(max98927->regmap, 231 regmap_update_bits(max98927->regmap,
228 MAX98927_R0035_PDM_RX_CTRL, 232 MAX98927_R0035_PDM_RX_CTRL,
229 MAX98927_PDM_RX_EN_MASK, 1); 233 MAX98927_PDM_RX_EN_MASK, 1);
@@ -231,10 +235,11 @@ static int max98927_dai_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
231 regmap_update_bits(max98927->regmap, 235 regmap_update_bits(max98927->regmap,
232 MAX98927_R003B_SPK_SRC_SEL, 236 MAX98927_R003B_SPK_SRC_SEL,
233 MAX98927_SPK_SRC_MASK, 3); 237 MAX98927_SPK_SRC_MASK, 3);
234 } else 238
235 regmap_update_bits(max98927->regmap, 239 regmap_update_bits(max98927->regmap,
236 MAX98927_R0035_PDM_RX_CTRL, 240 MAX98927_R0018_PCM_RX_EN_A,
237 MAX98927_PDM_RX_EN_MASK, 0); 241 MAX98927_PCM_RX_CH0_EN | MAX98927_PCM_RX_CH1_EN, 0);
242 }
238 return 0; 243 return 0;
239} 244}
240 245
@@ -245,6 +250,21 @@ static const int rate_table[] = {
245 13000000, 19200000, 250 13000000, 19200000,
246}; 251};
247 252
253/* BCLKs per LRCLK */
254static const int bclk_sel_table[] = {
255 32, 48, 64, 96, 128, 192, 256, 384, 512,
256};
257
258static int max98927_get_bclk_sel(int bclk)
259{
260 int i;
261 /* match BCLKs per LRCLK */
262 for (i = 0; i < ARRAY_SIZE(bclk_sel_table); i++) {
263 if (bclk_sel_table[i] == bclk)
264 return i + 2;
265 }
266 return 0;
267}
248static int max98927_set_clock(struct max98927_priv *max98927, 268static int max98927_set_clock(struct max98927_priv *max98927,
249 struct snd_pcm_hw_params *params) 269 struct snd_pcm_hw_params *params)
250{ 270{
@@ -270,23 +290,20 @@ static int max98927_set_clock(struct max98927_priv *max98927,
270 i << MAX98927_PCM_MASTER_MODE_MCLK_RATE_SHIFT); 290 i << MAX98927_PCM_MASTER_MODE_MCLK_RATE_SHIFT);
271 } 291 }
272 292
273 switch (blr_clk_ratio) { 293 if (!max98927->tdm_mode) {
274 case 32: 294 /* BCLK configuration */
275 value = 2; 295 value = max98927_get_bclk_sel(blr_clk_ratio);
276 break; 296 if (!value) {
277 case 48: 297 dev_err(codec->dev, "format unsupported %d\n",
278 value = 3; 298 params_format(params));
279 break; 299 return -EINVAL;
280 case 64: 300 }
281 value = 4; 301
282 break; 302 regmap_update_bits(max98927->regmap,
283 default: 303 MAX98927_R0022_PCM_CLK_SETUP,
284 return -EINVAL; 304 MAX98927_PCM_CLK_SETUP_BSEL_MASK,
305 value);
285 } 306 }
286 regmap_update_bits(max98927->regmap,
287 MAX98927_R0022_PCM_CLK_SETUP,
288 MAX98927_PCM_CLK_SETUP_BSEL_MASK,
289 value);
290 return 0; 307 return 0;
291} 308}
292 309
@@ -386,6 +403,78 @@ err:
386 return -EINVAL; 403 return -EINVAL;
387} 404}
388 405
406static int max98927_dai_tdm_slot(struct snd_soc_dai *dai,
407 unsigned int tx_mask, unsigned int rx_mask,
408 int slots, int slot_width)
409{
410 struct snd_soc_codec *codec = dai->codec;
411 struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
412 int bsel = 0;
413 unsigned int chan_sz = 0;
414
415 max98927->tdm_mode = true;
416
417 /* BCLK configuration */
418 bsel = max98927_get_bclk_sel(slots * slot_width);
419 if (bsel == 0) {
420 dev_err(codec->dev, "BCLK %d not supported\n",
421 slots * slot_width);
422 return -EINVAL;
423 }
424
425 regmap_update_bits(max98927->regmap,
426 MAX98927_R0022_PCM_CLK_SETUP,
427 MAX98927_PCM_CLK_SETUP_BSEL_MASK,
428 bsel);
429
430 /* Channel size configuration */
431 switch (slot_width) {
432 case 16:
433 chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_16;
434 break;
435 case 24:
436 chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_24;
437 break;
438 case 32:
439 chan_sz = MAX98927_PCM_MODE_CFG_CHANSZ_32;
440 break;
441 default:
442 dev_err(codec->dev, "format unsupported %d\n",
443 slot_width);
444 return -EINVAL;
445 }
446
447 regmap_update_bits(max98927->regmap,
448 MAX98927_R0020_PCM_MODE_CFG,
449 MAX98927_PCM_MODE_CFG_CHANSZ_MASK, chan_sz);
450
451 /* Rx slot configuration */
452 regmap_write(max98927->regmap,
453 MAX98927_R0018_PCM_RX_EN_A,
454 rx_mask & 0xFF);
455 regmap_write(max98927->regmap,
456 MAX98927_R0019_PCM_RX_EN_B,
457 (rx_mask & 0xFF00) >> 8);
458
459 /* Tx slot configuration */
460 regmap_write(max98927->regmap,
461 MAX98927_R001A_PCM_TX_EN_A,
462 tx_mask & 0xFF);
463 regmap_write(max98927->regmap,
464 MAX98927_R001B_PCM_TX_EN_B,
465 (tx_mask & 0xFF00) >> 8);
466
467 /* Tx slot Hi-Z configuration */
468 regmap_write(max98927->regmap,
469 MAX98927_R001C_PCM_TX_HIZ_CTRL_A,
470 ~tx_mask & 0xFF);
471 regmap_write(max98927->regmap,
472 MAX98927_R001D_PCM_TX_HIZ_CTRL_B,
473 (~tx_mask & 0xFF00) >> 8);
474
475 return 0;
476}
477
389#define MAX98927_RATES SNDRV_PCM_RATE_8000_48000 478#define MAX98927_RATES SNDRV_PCM_RATE_8000_48000
390 479
391#define MAX98927_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \ 480#define MAX98927_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | \
@@ -405,6 +494,7 @@ static const struct snd_soc_dai_ops max98927_dai_ops = {
405 .set_sysclk = max98927_dai_set_sysclk, 494 .set_sysclk = max98927_dai_set_sysclk,
406 .set_fmt = max98927_dai_set_fmt, 495 .set_fmt = max98927_dai_set_fmt,
407 .hw_params = max98927_dai_hw_params, 496 .hw_params = max98927_dai_hw_params,
497 .set_tdm_slot = max98927_dai_tdm_slot,
408}; 498};
409 499
410static int max98927_dac_event(struct snd_soc_dapm_widget *w, 500static int max98927_dac_event(struct snd_soc_dapm_widget *w,
@@ -414,6 +504,9 @@ static int max98927_dac_event(struct snd_soc_dapm_widget *w,
414 struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec); 504 struct max98927_priv *max98927 = snd_soc_codec_get_drvdata(codec);
415 505
416 switch (event) { 506 switch (event) {
507 case SND_SOC_DAPM_PRE_PMU:
508 max98927->tdm_mode = 0;
509 break;
417 case SND_SOC_DAPM_POST_PMU: 510 case SND_SOC_DAPM_POST_PMU:
418 regmap_update_bits(max98927->regmap, 511 regmap_update_bits(max98927->regmap,
419 MAX98927_R003A_AMP_EN, 512 MAX98927_R003A_AMP_EN,
diff --git a/sound/soc/codecs/max98927.h b/sound/soc/codecs/max98927.h
index ece6a608cbe1..9ea839735433 100644
--- a/sound/soc/codecs/max98927.h
+++ b/sound/soc/codecs/max98927.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * max98927.h -- MAX98927 ALSA Soc Audio driver 2 * max98927.h -- MAX98927 ALSA Soc Audio driver
3 * 3 *
4 * Copyright 2013-15 Maxim Integrated Products 4 * Copyright (C) 2016-2017 Maxim Integrated Products
5 * Author: Ryan Lee <ryans.lee@maximintegrated.com> 5 * Author: Ryan Lee <ryans.lee@maximintegrated.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
@@ -161,7 +161,9 @@
161#define MAX98927_PCM_MODE_CFG_FORMAT_SHIFT (3) 161#define MAX98927_PCM_MODE_CFG_FORMAT_SHIFT (3)
162#define MAX98927_PCM_FORMAT_I2S (0x0 << 0) 162#define MAX98927_PCM_FORMAT_I2S (0x0 << 0)
163#define MAX98927_PCM_FORMAT_LJ (0x1 << 0) 163#define MAX98927_PCM_FORMAT_LJ (0x1 << 0)
164 164#define MAX98927_PCM_FORMAT_TDM_MODE0 (0x3 << 0)
165#define MAX98927_PCM_FORMAT_TDM_MODE1 (0x4 << 0)
166#define MAX98927_PCM_FORMAT_TDM_MODE2 (0x5 << 0)
165#define MAX98927_PCM_MODE_CFG_CHANSZ_MASK (0x3 << 6) 167#define MAX98927_PCM_MODE_CFG_CHANSZ_MASK (0x3 << 6)
166#define MAX98927_PCM_MODE_CFG_CHANSZ_16 (0x1 << 6) 168#define MAX98927_PCM_MODE_CFG_CHANSZ_16 (0x1 << 6)
167#define MAX98927_PCM_MODE_CFG_CHANSZ_24 (0x2 << 6) 169#define MAX98927_PCM_MODE_CFG_CHANSZ_24 (0x2 << 6)
@@ -268,5 +270,6 @@ struct max98927_priv {
268 unsigned int iface; 270 unsigned int iface;
269 unsigned int master; 271 unsigned int master;
270 unsigned int digital_gain; 272 unsigned int digital_gain;
273 bool tdm_mode;
271}; 274};
272#endif 275#endif
diff --git a/sound/soc/codecs/msm8916-wcd-analog.c b/sound/soc/codecs/msm8916-wcd-analog.c
index 549c269acc7d..5f3c42c4f74a 100644
--- a/sound/soc/codecs/msm8916-wcd-analog.c
+++ b/sound/soc/codecs/msm8916-wcd-analog.c
@@ -104,7 +104,7 @@
104#define CDC_A_MICB_1_VAL (0xf141) 104#define CDC_A_MICB_1_VAL (0xf141)
105#define MICB_MIN_VAL 1600 105#define MICB_MIN_VAL 1600
106#define MICB_STEP_SIZE 50 106#define MICB_STEP_SIZE 50
107#define MICB_VOLTAGE_REGVAL(v) ((v - MICB_MIN_VAL)/MICB_STEP_SIZE) 107#define MICB_VOLTAGE_REGVAL(v) (((v - MICB_MIN_VAL)/MICB_STEP_SIZE) << 3)
108#define MICB_1_VAL_MICB_OUT_VAL_MASK GENMASK(7, 3) 108#define MICB_1_VAL_MICB_OUT_VAL_MASK GENMASK(7, 3)
109#define MICB_1_VAL_MICB_OUT_VAL_V2P70V ((0x16) << 3) 109#define MICB_1_VAL_MICB_OUT_VAL_V2P70V ((0x16) << 3)
110#define MICB_1_VAL_MICB_OUT_VAL_V1P80V ((0x4) << 3) 110#define MICB_1_VAL_MICB_OUT_VAL_V1P80V ((0x4) << 3)
@@ -285,7 +285,7 @@ struct pm8916_wcd_analog_priv {
285 u16 codec_version; 285 u16 codec_version;
286 bool mbhc_btn_enabled; 286 bool mbhc_btn_enabled;
287 /* special event to detect accessory type */ 287 /* special event to detect accessory type */
288 bool mbhc_btn0_pressed; 288 int mbhc_btn0_released;
289 bool detect_accessory_type; 289 bool detect_accessory_type;
290 struct clk *mclk; 290 struct clk *mclk;
291 struct snd_soc_codec *codec; 291 struct snd_soc_codec *codec;
@@ -349,8 +349,9 @@ static void pm8916_wcd_analog_micbias_enable(struct snd_soc_codec *codec)
349 | MICB_1_CTL_EXT_PRECHARG_EN_ENABLE); 349 | MICB_1_CTL_EXT_PRECHARG_EN_ENABLE);
350 350
351 if (wcd->micbias_mv) { 351 if (wcd->micbias_mv) {
352 snd_soc_write(codec, CDC_A_MICB_1_VAL, 352 snd_soc_update_bits(codec, CDC_A_MICB_1_VAL,
353 MICB_VOLTAGE_REGVAL(wcd->micbias_mv)); 353 MICB_1_VAL_MICB_OUT_VAL_MASK,
354 MICB_VOLTAGE_REGVAL(wcd->micbias_mv));
354 /* 355 /*
355 * Special headset needs MICBIAS as 2.7V so wait for 356 * Special headset needs MICBIAS as 2.7V so wait for
356 * 50 msec for the MICBIAS to reach 2.7 volts. 357 * 50 msec for the MICBIAS to reach 2.7 volts.
@@ -443,50 +444,6 @@ static int pm8916_wcd_analog_enable_micbias_int1(struct
443 wcd->micbias1_cap_mode); 444 wcd->micbias1_cap_mode);
444} 445}
445 446
446static void pm8916_wcd_setup_mbhc(struct pm8916_wcd_analog_priv *wcd)
447{
448 struct snd_soc_codec *codec = wcd->codec;
449 u32 plug_type = 0;
450 u32 int_en_mask;
451
452 snd_soc_write(codec, CDC_A_MBHC_DET_CTL_1,
453 CDC_A_MBHC_DET_CTL_L_DET_EN |
454 CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_INSERTION |
455 CDC_A_MBHC_DET_CTL_MIC_CLAMP_CTL_AUTO |
456 CDC_A_MBHC_DET_CTL_MBHC_BIAS_EN);
457
458 if (wcd->hphl_jack_type_normally_open)
459 plug_type |= CDC_A_HPHL_PLUG_TYPE_NO;
460
461 if (wcd->gnd_jack_type_normally_open)
462 plug_type |= CDC_A_GND_PLUG_TYPE_NO;
463
464 snd_soc_write(codec, CDC_A_MBHC_DET_CTL_2,
465 CDC_A_MBHC_DET_CTL_HS_L_DET_PULL_UP_CTRL_I_3P0 |
466 CDC_A_MBHC_DET_CTL_HS_L_DET_COMPA_CTRL_V0P9_VDD |
467 plug_type |
468 CDC_A_MBHC_DET_CTL_HPHL_100K_TO_GND_EN);
469
470
471 snd_soc_write(codec, CDC_A_MBHC_DBNC_TIMER,
472 CDC_A_MBHC_DBNC_TIMER_INSREM_DBNC_T_256_MS |
473 CDC_A_MBHC_DBNC_TIMER_BTN_DBNC_T_16MS);
474
475 /* enable MBHC clock */
476 snd_soc_update_bits(codec, CDC_D_CDC_DIG_CLK_CTL,
477 DIG_CLK_CTL_D_MBHC_CLK_EN_MASK,
478 DIG_CLK_CTL_D_MBHC_CLK_EN);
479
480 int_en_mask = MBHC_SWITCH_INT;
481 if (wcd->mbhc_btn_enabled)
482 int_en_mask |= MBHC_BUTTON_PRESS_DET | MBHC_BUTTON_RELEASE_DET;
483
484 snd_soc_update_bits(codec, CDC_D_INT_EN_CLR, int_en_mask, 0);
485 snd_soc_update_bits(codec, CDC_D_INT_EN_SET, int_en_mask, int_en_mask);
486 wcd->mbhc_btn0_pressed = false;
487 wcd->detect_accessory_type = true;
488}
489
490static int pm8916_mbhc_configure_bias(struct pm8916_wcd_analog_priv *priv, 447static int pm8916_mbhc_configure_bias(struct pm8916_wcd_analog_priv *priv,
491 bool micbias2_enabled) 448 bool micbias2_enabled)
492{ 449{
@@ -534,6 +491,56 @@ static int pm8916_mbhc_configure_bias(struct pm8916_wcd_analog_priv *priv,
534 return 0; 491 return 0;
535} 492}
536 493
494static void pm8916_wcd_setup_mbhc(struct pm8916_wcd_analog_priv *wcd)
495{
496 struct snd_soc_codec *codec = wcd->codec;
497 bool micbias_enabled = false;
498 u32 plug_type = 0;
499 u32 int_en_mask;
500
501 snd_soc_write(codec, CDC_A_MBHC_DET_CTL_1,
502 CDC_A_MBHC_DET_CTL_L_DET_EN |
503 CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_INSERTION |
504 CDC_A_MBHC_DET_CTL_MIC_CLAMP_CTL_AUTO |
505 CDC_A_MBHC_DET_CTL_MBHC_BIAS_EN);
506
507 if (wcd->hphl_jack_type_normally_open)
508 plug_type |= CDC_A_HPHL_PLUG_TYPE_NO;
509
510 if (wcd->gnd_jack_type_normally_open)
511 plug_type |= CDC_A_GND_PLUG_TYPE_NO;
512
513 snd_soc_write(codec, CDC_A_MBHC_DET_CTL_2,
514 CDC_A_MBHC_DET_CTL_HS_L_DET_PULL_UP_CTRL_I_3P0 |
515 CDC_A_MBHC_DET_CTL_HS_L_DET_COMPA_CTRL_V0P9_VDD |
516 plug_type |
517 CDC_A_MBHC_DET_CTL_HPHL_100K_TO_GND_EN);
518
519
520 snd_soc_write(codec, CDC_A_MBHC_DBNC_TIMER,
521 CDC_A_MBHC_DBNC_TIMER_INSREM_DBNC_T_256_MS |
522 CDC_A_MBHC_DBNC_TIMER_BTN_DBNC_T_16MS);
523
524 /* enable MBHC clock */
525 snd_soc_update_bits(codec, CDC_D_CDC_DIG_CLK_CTL,
526 DIG_CLK_CTL_D_MBHC_CLK_EN_MASK,
527 DIG_CLK_CTL_D_MBHC_CLK_EN);
528
529 if (snd_soc_read(codec, CDC_A_MICB_2_EN) & CDC_A_MICB_2_EN_ENABLE)
530 micbias_enabled = true;
531
532 pm8916_mbhc_configure_bias(wcd, micbias_enabled);
533
534 int_en_mask = MBHC_SWITCH_INT;
535 if (wcd->mbhc_btn_enabled)
536 int_en_mask |= MBHC_BUTTON_PRESS_DET | MBHC_BUTTON_RELEASE_DET;
537
538 snd_soc_update_bits(codec, CDC_D_INT_EN_CLR, int_en_mask, 0);
539 snd_soc_update_bits(codec, CDC_D_INT_EN_SET, int_en_mask, int_en_mask);
540 wcd->mbhc_btn0_released = false;
541 wcd->detect_accessory_type = true;
542}
543
537static int pm8916_wcd_analog_enable_micbias_int2(struct 544static int pm8916_wcd_analog_enable_micbias_int2(struct
538 snd_soc_dapm_widget 545 snd_soc_dapm_widget
539 *w, struct snd_kcontrol 546 *w, struct snd_kcontrol
@@ -614,6 +621,7 @@ static int pm8916_wcd_analog_enable_adc(struct snd_soc_dapm_widget *w,
614 case CDC_A_TX_2_EN: 621 case CDC_A_TX_2_EN:
615 snd_soc_update_bits(codec, CDC_A_MICB_1_CTL, 622 snd_soc_update_bits(codec, CDC_A_MICB_1_CTL,
616 MICB_1_CTL_CFILT_REF_SEL_MASK, 0); 623 MICB_1_CTL_CFILT_REF_SEL_MASK, 0);
624 /* fall through */
617 case CDC_A_TX_3_EN: 625 case CDC_A_TX_3_EN:
618 snd_soc_update_bits(codec, CDC_D_CDC_CONN_TX2_CTL, 626 snd_soc_update_bits(codec, CDC_D_CDC_CONN_TX2_CTL,
619 CONN_TX2_SERIAL_TX2_MUX, 627 CONN_TX2_SERIAL_TX2_MUX,
@@ -950,7 +958,7 @@ static irqreturn_t mbhc_btn_release_irq_handler(int irq, void *arg)
950 958
951 /* check if its BTN0 thats released */ 959 /* check if its BTN0 thats released */
952 if ((val != -1) && !(val & CDC_A_MBHC_RESULT_1_BTN_RESULT_MASK)) 960 if ((val != -1) && !(val & CDC_A_MBHC_RESULT_1_BTN_RESULT_MASK))
953 priv->mbhc_btn0_pressed = false; 961 priv->mbhc_btn0_released = true;
954 962
955 } else { 963 } else {
956 snd_soc_jack_report(priv->jack, 0, btn_mask); 964 snd_soc_jack_report(priv->jack, 0, btn_mask);
@@ -983,9 +991,7 @@ static irqreturn_t mbhc_btn_press_irq_handler(int irq, void *arg)
983 break; 991 break;
984 case 0x0: 992 case 0x0:
985 /* handle BTN_0 specially for type detection */ 993 /* handle BTN_0 specially for type detection */
986 if (priv->detect_accessory_type) 994 if (!priv->detect_accessory_type)
987 priv->mbhc_btn0_pressed = true;
988 else
989 snd_soc_jack_report(priv->jack, 995 snd_soc_jack_report(priv->jack,
990 SND_JACK_BTN_0, btn_mask); 996 SND_JACK_BTN_0, btn_mask);
991 break; 997 break;
@@ -1029,19 +1035,19 @@ static irqreturn_t pm8916_mbhc_switch_irq_handler(int irq, void *arg)
1029 * both press and release event received then its 1035 * both press and release event received then its
1030 * a headset. 1036 * a headset.
1031 */ 1037 */
1032 if (priv->mbhc_btn0_pressed) 1038 if (priv->mbhc_btn0_released)
1033 snd_soc_jack_report(priv->jack, 1039 snd_soc_jack_report(priv->jack,
1034 SND_JACK_HEADPHONE, hs_jack_mask); 1040 SND_JACK_HEADSET, hs_jack_mask);
1035 else 1041 else
1036 snd_soc_jack_report(priv->jack, 1042 snd_soc_jack_report(priv->jack,
1037 SND_JACK_HEADSET, hs_jack_mask); 1043 SND_JACK_HEADPHONE, hs_jack_mask);
1038 1044
1039 priv->detect_accessory_type = false; 1045 priv->detect_accessory_type = false;
1040 1046
1041 } else { /* removal */ 1047 } else { /* removal */
1042 snd_soc_jack_report(priv->jack, 0, hs_jack_mask); 1048 snd_soc_jack_report(priv->jack, 0, hs_jack_mask);
1043 priv->detect_accessory_type = true; 1049 priv->detect_accessory_type = true;
1044 priv->mbhc_btn0_pressed = false; 1050 priv->mbhc_btn0_released = false;
1045 } 1051 }
1046 1052
1047 return IRQ_HANDLED; 1053 return IRQ_HANDLED;
@@ -1241,6 +1247,8 @@ static const struct of_device_id pm8916_wcd_analog_spmi_match_table[] = {
1241 { } 1247 { }
1242}; 1248};
1243 1249
1250MODULE_DEVICE_TABLE(of, pm8916_wcd_analog_spmi_match_table);
1251
1244static struct platform_driver pm8916_wcd_analog_spmi_driver = { 1252static struct platform_driver pm8916_wcd_analog_spmi_driver = {
1245 .driver = { 1253 .driver = {
1246 .name = "qcom,pm8916-wcd-spmi-codec", 1254 .name = "qcom,pm8916-wcd-spmi-codec",
diff --git a/sound/soc/codecs/msm8916-wcd-digital.c b/sound/soc/codecs/msm8916-wcd-digital.c
index 66df8f810f0d..a10a724eb448 100644
--- a/sound/soc/codecs/msm8916-wcd-digital.c
+++ b/sound/soc/codecs/msm8916-wcd-digital.c
@@ -238,7 +238,7 @@ static const struct soc_enum rx_mix2_inp1_chain_enum = SOC_ENUM_SINGLE(
238static const struct soc_enum rx2_mix1_inp_enum[] = { 238static const struct soc_enum rx2_mix1_inp_enum[] = {
239 SOC_ENUM_SINGLE(LPASS_CDC_CONN_RX2_B1_CTL, 0, 6, rx_mix1_text), 239 SOC_ENUM_SINGLE(LPASS_CDC_CONN_RX2_B1_CTL, 0, 6, rx_mix1_text),
240 SOC_ENUM_SINGLE(LPASS_CDC_CONN_RX2_B1_CTL, 3, 6, rx_mix1_text), 240 SOC_ENUM_SINGLE(LPASS_CDC_CONN_RX2_B1_CTL, 3, 6, rx_mix1_text),
241 SOC_ENUM_SINGLE(LPASS_CDC_CONN_RX2_B1_CTL, 0, 6, rx_mix1_text), 241 SOC_ENUM_SINGLE(LPASS_CDC_CONN_RX2_B2_CTL, 0, 6, rx_mix1_text),
242}; 242};
243 243
244/* RX2 MIX2 */ 244/* RX2 MIX2 */
@@ -249,7 +249,7 @@ static const struct soc_enum rx2_mix2_inp1_chain_enum = SOC_ENUM_SINGLE(
249static const struct soc_enum rx3_mix1_inp_enum[] = { 249static const struct soc_enum rx3_mix1_inp_enum[] = {
250 SOC_ENUM_SINGLE(LPASS_CDC_CONN_RX3_B1_CTL, 0, 6, rx_mix1_text), 250 SOC_ENUM_SINGLE(LPASS_CDC_CONN_RX3_B1_CTL, 0, 6, rx_mix1_text),
251 SOC_ENUM_SINGLE(LPASS_CDC_CONN_RX3_B1_CTL, 3, 6, rx_mix1_text), 251 SOC_ENUM_SINGLE(LPASS_CDC_CONN_RX3_B1_CTL, 3, 6, rx_mix1_text),
252 SOC_ENUM_SINGLE(LPASS_CDC_CONN_RX3_B1_CTL, 0, 6, rx_mix1_text), 252 SOC_ENUM_SINGLE(LPASS_CDC_CONN_RX3_B2_CTL, 0, 6, rx_mix1_text),
253}; 253};
254 254
255/* DEC */ 255/* DEC */
diff --git a/sound/soc/codecs/pcm512x-i2c.c b/sound/soc/codecs/pcm512x-i2c.c
index dbff416e38be..5f9c069569d5 100644
--- a/sound/soc/codecs/pcm512x-i2c.c
+++ b/sound/soc/codecs/pcm512x-i2c.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the PCM512x CODECs 2 * Driver for the PCM512x CODECs
3 * 3 *
4 * Author: Mark Brown <broonie@linaro.org> 4 * Author: Mark Brown <broonie@kernel.org>
5 * Copyright 2014 Linaro Ltd 5 * Copyright 2014 Linaro Ltd
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
@@ -75,5 +75,5 @@ static struct i2c_driver pcm512x_i2c_driver = {
75module_i2c_driver(pcm512x_i2c_driver); 75module_i2c_driver(pcm512x_i2c_driver);
76 76
77MODULE_DESCRIPTION("ASoC PCM512x codec driver - I2C"); 77MODULE_DESCRIPTION("ASoC PCM512x codec driver - I2C");
78MODULE_AUTHOR("Mark Brown <broonie@linaro.org>"); 78MODULE_AUTHOR("Mark Brown <broonie@kernel.org>");
79MODULE_LICENSE("GPL v2"); 79MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/codecs/pcm512x-spi.c b/sound/soc/codecs/pcm512x-spi.c
index 712ed6598c48..25c63510ae15 100644
--- a/sound/soc/codecs/pcm512x-spi.c
+++ b/sound/soc/codecs/pcm512x-spi.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the PCM512x CODECs 2 * Driver for the PCM512x CODECs
3 * 3 *
4 * Author: Mark Brown <broonie@linaro.org> 4 * Author: Mark Brown <broonie@kernel.org>
5 * Copyright 2014 Linaro Ltd 5 * Copyright 2014 Linaro Ltd
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c
index 68feae262476..e0f3556d3872 100644
--- a/sound/soc/codecs/pcm512x.c
+++ b/sound/soc/codecs/pcm512x.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the PCM512x CODECs 2 * Driver for the PCM512x CODECs
3 * 3 *
4 * Author: Mark Brown <broonie@linaro.org> 4 * Author: Mark Brown <broonie@kernel.org>
5 * Copyright 2014 Linaro Ltd 5 * Copyright 2014 Linaro Ltd
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
@@ -1602,5 +1602,5 @@ const struct dev_pm_ops pcm512x_pm_ops = {
1602EXPORT_SYMBOL_GPL(pcm512x_pm_ops); 1602EXPORT_SYMBOL_GPL(pcm512x_pm_ops);
1603 1603
1604MODULE_DESCRIPTION("ASoC PCM512x codec driver"); 1604MODULE_DESCRIPTION("ASoC PCM512x codec driver");
1605MODULE_AUTHOR("Mark Brown <broonie@linaro.org>"); 1605MODULE_AUTHOR("Mark Brown <broonie@kernel.org>");
1606MODULE_LICENSE("GPL v2"); 1606MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/codecs/pcm512x.h b/sound/soc/codecs/pcm512x.h
index b7c310207223..d70d9c0c2088 100644
--- a/sound/soc/codecs/pcm512x.h
+++ b/sound/soc/codecs/pcm512x.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for the PCM512x CODECs 2 * Driver for the PCM512x CODECs
3 * 3 *
4 * Author: Mark Brown <broonie@linaro.org> 4 * Author: Mark Brown <broonie@kernel.org>
5 * Copyright 2014 Linaro Ltd 5 * Copyright 2014 Linaro Ltd
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
diff --git a/sound/soc/codecs/rl6231.c b/sound/soc/codecs/rl6231.c
index 7b447d0b173a..974a9040651d 100644
--- a/sound/soc/codecs/rl6231.c
+++ b/sound/soc/codecs/rl6231.c
@@ -71,7 +71,7 @@ EXPORT_SYMBOL_GPL(rl6231_get_pre_div);
71 */ 71 */
72int rl6231_calc_dmic_clk(int rate) 72int rl6231_calc_dmic_clk(int rate)
73{ 73{
74 int div[] = {2, 3, 4, 6, 8, 12}; 74 static const int div[] = {2, 3, 4, 6, 8, 12};
75 int i; 75 int i;
76 76
77 if (rate < 1000000 * div[0]) { 77 if (rate < 1000000 * div[0]) {
@@ -189,7 +189,8 @@ EXPORT_SYMBOL_GPL(rl6231_pll_calc);
189 189
190int rl6231_get_clk_info(int sclk, int rate) 190int rl6231_get_clk_info(int sclk, int rate)
191{ 191{
192 int i, pd[] = {1, 2, 3, 4, 6, 8, 12, 16}; 192 int i;
193 static const int pd[] = {1, 2, 3, 4, 6, 8, 12, 16};
193 194
194 if (sclk <= 0 || rate <= 0) 195 if (sclk <= 0 || rate <= 0)
195 return -EINVAL; 196 return -EINVAL;
diff --git a/sound/soc/codecs/rt5514-spi.c b/sound/soc/codecs/rt5514-spi.c
index 12f2ecf3a4fe..2df91db765ac 100644
--- a/sound/soc/codecs/rt5514-spi.c
+++ b/sound/soc/codecs/rt5514-spi.c
@@ -147,8 +147,13 @@ done:
147 147
148static void rt5514_schedule_copy(struct rt5514_dsp *rt5514_dsp) 148static void rt5514_schedule_copy(struct rt5514_dsp *rt5514_dsp)
149{ 149{
150 size_t period_bytes;
150 u8 buf[8]; 151 u8 buf[8];
151 152
153 if (!rt5514_dsp->substream)
154 return;
155
156 period_bytes = snd_pcm_lib_period_bytes(rt5514_dsp->substream);
152 rt5514_dsp->get_size = 0; 157 rt5514_dsp->get_size = 0;
153 158
154 /** 159 /**
@@ -176,6 +181,10 @@ static void rt5514_schedule_copy(struct rt5514_dsp *rt5514_dsp)
176 181
177 rt5514_dsp->buf_size = rt5514_dsp->buf_limit - rt5514_dsp->buf_base; 182 rt5514_dsp->buf_size = rt5514_dsp->buf_limit - rt5514_dsp->buf_base;
178 183
184 if (rt5514_dsp->buf_size % period_bytes)
185 rt5514_dsp->buf_size = (rt5514_dsp->buf_size / period_bytes) *
186 period_bytes;
187
179 if (rt5514_dsp->buf_base && rt5514_dsp->buf_limit && 188 if (rt5514_dsp->buf_base && rt5514_dsp->buf_limit &&
180 rt5514_dsp->buf_rp && rt5514_dsp->buf_size) 189 rt5514_dsp->buf_rp && rt5514_dsp->buf_size)
181 schedule_delayed_work(&rt5514_dsp->copy_work, 0); 190 schedule_delayed_work(&rt5514_dsp->copy_work, 0);
@@ -447,9 +456,45 @@ static int rt5514_spi_probe(struct spi_device *spi)
447 return ret; 456 return ret;
448 } 457 }
449 458
459 device_init_wakeup(&spi->dev, true);
460
461 return 0;
462}
463
464static int __maybe_unused rt5514_suspend(struct device *dev)
465{
466 int irq = to_spi_device(dev)->irq;
467
468 if (device_may_wakeup(dev))
469 enable_irq_wake(irq);
470
471 return 0;
472}
473
474static int __maybe_unused rt5514_resume(struct device *dev)
475{
476 struct snd_soc_platform *platform = snd_soc_lookup_platform(dev);
477 struct rt5514_dsp *rt5514_dsp =
478 snd_soc_platform_get_drvdata(platform);
479 int irq = to_spi_device(dev)->irq;
480 u8 buf[8];
481
482 if (device_may_wakeup(dev))
483 disable_irq_wake(irq);
484
485 if (rt5514_dsp->substream) {
486 rt5514_spi_burst_read(RT5514_IRQ_CTRL, (u8 *)&buf, sizeof(buf));
487 if (buf[0] & RT5514_IRQ_STATUS_BIT)
488 rt5514_schedule_copy(rt5514_dsp);
489 }
490
450 return 0; 491 return 0;
451} 492}
452 493
494static const struct dev_pm_ops rt5514_pm_ops = {
495 SET_SYSTEM_SLEEP_PM_OPS(rt5514_suspend, rt5514_resume)
496};
497
453static const struct of_device_id rt5514_of_match[] = { 498static const struct of_device_id rt5514_of_match[] = {
454 { .compatible = "realtek,rt5514", }, 499 { .compatible = "realtek,rt5514", },
455 {}, 500 {},
@@ -459,6 +504,7 @@ MODULE_DEVICE_TABLE(of, rt5514_of_match);
459static struct spi_driver rt5514_spi_driver = { 504static struct spi_driver rt5514_spi_driver = {
460 .driver = { 505 .driver = {
461 .name = "rt5514", 506 .name = "rt5514",
507 .pm = &rt5514_pm_ops,
462 .of_match_table = of_match_ptr(rt5514_of_match), 508 .of_match_table = of_match_ptr(rt5514_of_match),
463 }, 509 },
464 .probe = rt5514_spi_probe, 510 .probe = rt5514_spi_probe,
diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c
index d7956ababd11..2a5b5d74e697 100644
--- a/sound/soc/codecs/rt5514.c
+++ b/sound/soc/codecs/rt5514.c
@@ -1143,7 +1143,7 @@ static const struct acpi_device_id rt5514_acpi_match[] = {
1143MODULE_DEVICE_TABLE(acpi, rt5514_acpi_match); 1143MODULE_DEVICE_TABLE(acpi, rt5514_acpi_match);
1144#endif 1144#endif
1145 1145
1146static int rt5514_parse_dt(struct rt5514_priv *rt5514, struct device *dev) 1146static int rt5514_parse_dp(struct rt5514_priv *rt5514, struct device *dev)
1147{ 1147{
1148 device_property_read_u32(dev, "realtek,dmic-init-delay-ms", 1148 device_property_read_u32(dev, "realtek,dmic-init-delay-ms",
1149 &rt5514->pdata.dmic_init_delay); 1149 &rt5514->pdata.dmic_init_delay);
@@ -1183,8 +1183,8 @@ static int rt5514_i2c_probe(struct i2c_client *i2c,
1183 1183
1184 if (pdata) 1184 if (pdata)
1185 rt5514->pdata = *pdata; 1185 rt5514->pdata = *pdata;
1186 else if (i2c->dev.of_node) 1186 else
1187 rt5514_parse_dt(rt5514, &i2c->dev); 1187 rt5514_parse_dp(rt5514, &i2c->dev);
1188 1188
1189 rt5514->i2c_regmap = devm_regmap_init_i2c(i2c, &rt5514_i2c_regmap); 1189 rt5514->i2c_regmap = devm_regmap_init_i2c(i2c, &rt5514_i2c_regmap);
1190 if (IS_ERR(rt5514->i2c_regmap)) { 1190 if (IS_ERR(rt5514->i2c_regmap)) {
diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index a98647ac497c..f020d2d1eef4 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -55,6 +55,8 @@ MODULE_PARM_DESC(quirk, "RT5645 pdata quirk override");
55 55
56#define RT5645_HWEQ_NUM 57 56#define RT5645_HWEQ_NUM 57
57 57
58#define TIME_TO_POWER_MS 400
59
58static const struct regmap_range_cfg rt5645_ranges[] = { 60static const struct regmap_range_cfg rt5645_ranges[] = {
59 { 61 {
60 .name = "PR", 62 .name = "PR",
@@ -432,6 +434,7 @@ struct rt5645_priv {
432 int jack_type; 434 int jack_type;
433 bool en_button_func; 435 bool en_button_func;
434 bool hp_on; 436 bool hp_on;
437 int v_id;
435}; 438};
436 439
437static int rt5645_reset(struct snd_soc_codec *codec) 440static int rt5645_reset(struct snd_soc_codec *codec)
@@ -2516,9 +2519,7 @@ static const struct snd_soc_dapm_route rt5645_dapm_routes[] = {
2516 { "SPKVOL L", "Switch", "SPK MIXL" }, 2519 { "SPKVOL L", "Switch", "SPK MIXL" },
2517 { "SPKVOL R", "Switch", "SPK MIXR" }, 2520 { "SPKVOL R", "Switch", "SPK MIXR" },
2518 2521
2519 { "SPOL MIX", "DAC R1 Switch", "DAC R1" },
2520 { "SPOL MIX", "DAC L1 Switch", "DAC L1" }, 2522 { "SPOL MIX", "DAC L1 Switch", "DAC L1" },
2521 { "SPOL MIX", "SPKVOL R Switch", "SPKVOL R" },
2522 { "SPOL MIX", "SPKVOL L Switch", "SPKVOL L" }, 2523 { "SPOL MIX", "SPKVOL L Switch", "SPKVOL L" },
2523 { "SPOR MIX", "DAC R1 Switch", "DAC R1" }, 2524 { "SPOR MIX", "DAC R1 Switch", "DAC R1" },
2524 { "SPOR MIX", "SPKVOL R Switch", "SPKVOL R" }, 2525 { "SPOR MIX", "SPKVOL R Switch", "SPKVOL R" },
@@ -2707,6 +2708,11 @@ static const struct snd_soc_dapm_route rt5645_specific_dapm_routes[] = {
2707 { "DAC R2 Mux", "IF1 DAC", "RT5645 IF1 DAC2 R Mux" }, 2708 { "DAC R2 Mux", "IF1 DAC", "RT5645 IF1 DAC2 R Mux" },
2708}; 2709};
2709 2710
2711static const struct snd_soc_dapm_route rt5645_old_dapm_routes[] = {
2712 { "SPOL MIX", "DAC R1 Switch", "DAC R1" },
2713 { "SPOL MIX", "SPKVOL R Switch", "SPKVOL R" },
2714};
2715
2710static int rt5645_hw_params(struct snd_pcm_substream *substream, 2716static int rt5645_hw_params(struct snd_pcm_substream *substream,
2711 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 2717 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
2712{ 2718{
@@ -3340,9 +3346,9 @@ static irqreturn_t rt5645_irq(int irq, void *data)
3340 return IRQ_HANDLED; 3346 return IRQ_HANDLED;
3341} 3347}
3342 3348
3343static void rt5645_btn_check_callback(unsigned long data) 3349static void rt5645_btn_check_callback(struct timer_list *t)
3344{ 3350{
3345 struct rt5645_priv *rt5645 = (struct rt5645_priv *)data; 3351 struct rt5645_priv *rt5645 = from_timer(rt5645, t, btn_check_timer);
3346 3352
3347 queue_delayed_work(system_power_efficient_wq, 3353 queue_delayed_work(system_power_efficient_wq,
3348 &rt5645->jack_detect_work, msecs_to_jiffies(5)); 3354 &rt5645->jack_detect_work, msecs_to_jiffies(5));
@@ -3363,6 +3369,11 @@ static int rt5645_probe(struct snd_soc_codec *codec)
3363 snd_soc_dapm_add_routes(dapm, 3369 snd_soc_dapm_add_routes(dapm,
3364 rt5645_specific_dapm_routes, 3370 rt5645_specific_dapm_routes,
3365 ARRAY_SIZE(rt5645_specific_dapm_routes)); 3371 ARRAY_SIZE(rt5645_specific_dapm_routes));
3372 if (rt5645->v_id < 3) {
3373 snd_soc_dapm_add_routes(dapm,
3374 rt5645_old_dapm_routes,
3375 ARRAY_SIZE(rt5645_old_dapm_routes));
3376 }
3366 break; 3377 break;
3367 case CODEC_TYPE_RT5650: 3378 case CODEC_TYPE_RT5650:
3368 snd_soc_dapm_new_controls(dapm, 3379 snd_soc_dapm_new_controls(dapm,
@@ -3637,14 +3648,14 @@ static const struct dmi_system_id dmi_platform_gpd_win[] = {
3637 {} 3648 {}
3638}; 3649};
3639 3650
3640static struct rt5645_platform_data general_platform_data2 = { 3651static const struct rt5645_platform_data general_platform_data2 = {
3641 .dmic1_data_pin = RT5645_DMIC_DATA_IN2N, 3652 .dmic1_data_pin = RT5645_DMIC_DATA_IN2N,
3642 .dmic2_data_pin = RT5645_DMIC2_DISABLE, 3653 .dmic2_data_pin = RT5645_DMIC2_DISABLE,
3643 .jd_mode = 3, 3654 .jd_mode = 3,
3644 .inv_jd1_1 = true, 3655 .inv_jd1_1 = true,
3645}; 3656};
3646 3657
3647static struct dmi_system_id dmi_platform_asus_t100ha[] = { 3658static const struct dmi_system_id dmi_platform_asus_t100ha[] = {
3648 { 3659 {
3649 .ident = "ASUS T100HAN", 3660 .ident = "ASUS T100HAN",
3650 .matches = { 3661 .matches = {
@@ -3655,11 +3666,11 @@ static struct dmi_system_id dmi_platform_asus_t100ha[] = {
3655 { } 3666 { }
3656}; 3667};
3657 3668
3658static struct rt5645_platform_data minix_z83_4_platform_data = { 3669static const struct rt5645_platform_data minix_z83_4_platform_data = {
3659 .jd_mode = 3, 3670 .jd_mode = 3,
3660}; 3671};
3661 3672
3662static struct dmi_system_id dmi_platform_minix_z83_4[] = { 3673static const struct dmi_system_id dmi_platform_minix_z83_4[] = {
3663 { 3674 {
3664 .ident = "MINIX Z83-4", 3675 .ident = "MINIX Z83-4",
3665 .matches = { 3676 .matches = {
@@ -3775,6 +3786,12 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
3775 ret); 3786 ret);
3776 return ret; 3787 return ret;
3777 } 3788 }
3789
3790 /*
3791 * Read after 400msec, as it is the interval required between
3792 * read and power On.
3793 */
3794 msleep(TIME_TO_POWER_MS);
3778 regmap_read(regmap, RT5645_VENDOR_ID2, &val); 3795 regmap_read(regmap, RT5645_VENDOR_ID2, &val);
3779 3796
3780 switch (val) { 3797 switch (val) {
@@ -3803,6 +3820,9 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
3803 3820
3804 regmap_write(rt5645->regmap, RT5645_RESET, 0); 3821 regmap_write(rt5645->regmap, RT5645_RESET, 0);
3805 3822
3823 regmap_read(regmap, RT5645_VENDOR_ID, &val);
3824 rt5645->v_id = val & 0xff;
3825
3806 ret = regmap_register_patch(rt5645->regmap, init_list, 3826 ret = regmap_register_patch(rt5645->regmap, init_list,
3807 ARRAY_SIZE(init_list)); 3827 ARRAY_SIZE(init_list));
3808 if (ret != 0) 3828 if (ret != 0)
@@ -3934,8 +3954,7 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
3934 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, 3954 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2,
3935 RT5645_JD_1_1_MASK, RT5645_JD_1_1_INV); 3955 RT5645_JD_1_1_MASK, RT5645_JD_1_1_INV);
3936 } 3956 }
3937 setup_timer(&rt5645->btn_check_timer, 3957 timer_setup(&rt5645->btn_check_timer, rt5645_btn_check_callback, 0);
3938 rt5645_btn_check_callback, (unsigned long)rt5645);
3939 3958
3940 INIT_DELAYED_WORK(&rt5645->jack_detect_work, rt5645_jack_detect_work); 3959 INIT_DELAYED_WORK(&rt5645->jack_detect_work, rt5645_jack_detect_work);
3941 INIT_DELAYED_WORK(&rt5645->rcclock_work, rt5645_rcclock_work); 3960 INIT_DELAYED_WORK(&rt5645->rcclock_work, rt5645_rcclock_work);
diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c
index da60b28ba3df..831b297978a4 100644
--- a/sound/soc/codecs/rt5651.c
+++ b/sound/soc/codecs/rt5651.c
@@ -19,6 +19,7 @@
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/spi/spi.h> 20#include <linux/spi/spi.h>
21#include <linux/acpi.h> 21#include <linux/acpi.h>
22#include <linux/dmi.h>
22#include <sound/core.h> 23#include <sound/core.h>
23#include <sound/pcm.h> 24#include <sound/pcm.h>
24#include <sound/pcm_params.h> 25#include <sound/pcm_params.h>
@@ -26,10 +27,15 @@
26#include <sound/soc-dapm.h> 27#include <sound/soc-dapm.h>
27#include <sound/initval.h> 28#include <sound/initval.h>
28#include <sound/tlv.h> 29#include <sound/tlv.h>
30#include <sound/jack.h>
29 31
30#include "rl6231.h" 32#include "rl6231.h"
31#include "rt5651.h" 33#include "rt5651.h"
32 34
35#define RT5651_JD_MAP(quirk) ((quirk) & GENMASK(7, 0))
36#define RT5651_IN2_DIFF BIT(16)
37#define RT5651_DMIC_EN BIT(17)
38
33#define RT5651_DEVICE_ID_VALUE 0x6281 39#define RT5651_DEVICE_ID_VALUE 0x6281
34 40
35#define RT5651_PR_RANGE_BASE (0xff + 1) 41#define RT5651_PR_RANGE_BASE (0xff + 1)
@@ -37,6 +43,8 @@
37 43
38#define RT5651_PR_BASE (RT5651_PR_RANGE_BASE + (0 * RT5651_PR_SPACING)) 44#define RT5651_PR_BASE (RT5651_PR_RANGE_BASE + (0 * RT5651_PR_SPACING))
39 45
46static unsigned long rt5651_quirk;
47
40static const struct regmap_range_cfg rt5651_ranges[] = { 48static const struct regmap_range_cfg rt5651_ranges[] = {
41 { .name = "PR", .range_min = RT5651_PR_BASE, 49 { .name = "PR", .range_min = RT5651_PR_BASE,
42 .range_max = RT5651_PR_BASE + 0xb4, 50 .range_max = RT5651_PR_BASE + 0xb4,
@@ -880,11 +888,14 @@ static const struct snd_soc_dapm_widget rt5651_dapm_widgets[] = {
880 SND_SOC_DAPM_SUPPLY("PLL1", RT5651_PWR_ANLG2, 888 SND_SOC_DAPM_SUPPLY("PLL1", RT5651_PWR_ANLG2,
881 RT5651_PWR_PLL_BIT, 0, NULL, 0), 889 RT5651_PWR_PLL_BIT, 0, NULL, 0),
882 /* Input Side */ 890 /* Input Side */
891 SND_SOC_DAPM_SUPPLY("JD Power", RT5651_PWR_ANLG2,
892 RT5651_PWM_JD_M_BIT, 0, NULL, 0),
893
883 /* micbias */ 894 /* micbias */
884 SND_SOC_DAPM_SUPPLY("LDO", RT5651_PWR_ANLG1, 895 SND_SOC_DAPM_SUPPLY("LDO", RT5651_PWR_ANLG1,
885 RT5651_PWR_LDO_BIT, 0, NULL, 0), 896 RT5651_PWR_LDO_BIT, 0, NULL, 0),
886 SND_SOC_DAPM_MICBIAS("micbias1", RT5651_PWR_ANLG2, 897 SND_SOC_DAPM_SUPPLY("micbias1", RT5651_PWR_ANLG2,
887 RT5651_PWR_MB1_BIT, 0), 898 RT5651_PWR_MB1_BIT, 0, NULL, 0),
888 /* Input Lines */ 899 /* Input Lines */
889 SND_SOC_DAPM_INPUT("MIC1"), 900 SND_SOC_DAPM_INPUT("MIC1"),
890 SND_SOC_DAPM_INPUT("MIC2"), 901 SND_SOC_DAPM_INPUT("MIC2"),
@@ -1528,6 +1539,8 @@ static int rt5651_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source,
1528static int rt5651_set_bias_level(struct snd_soc_codec *codec, 1539static int rt5651_set_bias_level(struct snd_soc_codec *codec,
1529 enum snd_soc_bias_level level) 1540 enum snd_soc_bias_level level)
1530{ 1541{
1542 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec);
1543
1531 switch (level) { 1544 switch (level) {
1532 case SND_SOC_BIAS_PREPARE: 1545 case SND_SOC_BIAS_PREPARE:
1533 if (SND_SOC_BIAS_STANDBY == snd_soc_codec_get_bias_level(codec)) { 1546 if (SND_SOC_BIAS_STANDBY == snd_soc_codec_get_bias_level(codec)) {
@@ -1556,8 +1569,13 @@ static int rt5651_set_bias_level(struct snd_soc_codec *codec,
1556 snd_soc_write(codec, RT5651_PWR_DIG2, 0x0000); 1569 snd_soc_write(codec, RT5651_PWR_DIG2, 0x0000);
1557 snd_soc_write(codec, RT5651_PWR_VOL, 0x0000); 1570 snd_soc_write(codec, RT5651_PWR_VOL, 0x0000);
1558 snd_soc_write(codec, RT5651_PWR_MIXER, 0x0000); 1571 snd_soc_write(codec, RT5651_PWR_MIXER, 0x0000);
1559 snd_soc_write(codec, RT5651_PWR_ANLG1, 0x0000); 1572 if (rt5651->pdata.jd_src) {
1560 snd_soc_write(codec, RT5651_PWR_ANLG2, 0x0000); 1573 snd_soc_write(codec, RT5651_PWR_ANLG2, 0x0204);
1574 snd_soc_write(codec, RT5651_PWR_ANLG1, 0x0002);
1575 } else {
1576 snd_soc_write(codec, RT5651_PWR_ANLG1, 0x0000);
1577 snd_soc_write(codec, RT5651_PWR_ANLG2, 0x0000);
1578 }
1561 break; 1579 break;
1562 1580
1563 default: 1581 default:
@@ -1570,6 +1588,7 @@ static int rt5651_set_bias_level(struct snd_soc_codec *codec,
1570static int rt5651_probe(struct snd_soc_codec *codec) 1588static int rt5651_probe(struct snd_soc_codec *codec)
1571{ 1589{
1572 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); 1590 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec);
1591 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1573 1592
1574 rt5651->codec = codec; 1593 rt5651->codec = codec;
1575 1594
@@ -1585,6 +1604,15 @@ static int rt5651_probe(struct snd_soc_codec *codec)
1585 1604
1586 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF); 1605 snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_OFF);
1587 1606
1607 if (rt5651->pdata.jd_src) {
1608 snd_soc_dapm_force_enable_pin(dapm, "JD Power");
1609 snd_soc_dapm_force_enable_pin(dapm, "LDO");
1610 snd_soc_dapm_sync(dapm);
1611
1612 regmap_update_bits(rt5651->regmap, RT5651_MICBIAS,
1613 0x38, 0x38);
1614 }
1615
1588 return 0; 1616 return 0;
1589} 1617}
1590 1618
@@ -1718,15 +1746,130 @@ static const struct i2c_device_id rt5651_i2c_id[] = {
1718}; 1746};
1719MODULE_DEVICE_TABLE(i2c, rt5651_i2c_id); 1747MODULE_DEVICE_TABLE(i2c, rt5651_i2c_id);
1720 1748
1749static int rt5651_quirk_cb(const struct dmi_system_id *id)
1750{
1751 rt5651_quirk = (unsigned long) id->driver_data;
1752 return 1;
1753}
1754
1755static const struct dmi_system_id rt5651_quirk_table[] = {
1756 {
1757 .callback = rt5651_quirk_cb,
1758 .matches = {
1759 DMI_MATCH(DMI_SYS_VENDOR, "KIANO"),
1760 DMI_MATCH(DMI_PRODUCT_NAME, "KIANO SlimNote 14.2"),
1761 },
1762 .driver_data = (unsigned long *) RT5651_JD1_1,
1763 },
1764 {}
1765};
1766
1721static int rt5651_parse_dt(struct rt5651_priv *rt5651, struct device_node *np) 1767static int rt5651_parse_dt(struct rt5651_priv *rt5651, struct device_node *np)
1722{ 1768{
1723 rt5651->pdata.in2_diff = of_property_read_bool(np, 1769 if (of_property_read_bool(np, "realtek,in2-differential"))
1724 "realtek,in2-differential"); 1770 rt5651_quirk |= RT5651_IN2_DIFF;
1725 rt5651->pdata.dmic_en = of_property_read_bool(np, 1771 if (of_property_read_bool(np, "realtek,dmic-en"))
1726 "realtek,dmic-en"); 1772 rt5651_quirk |= RT5651_DMIC_EN;
1773
1774 return 0;
1775}
1776
1777static void rt5651_set_pdata(struct rt5651_priv *rt5651)
1778{
1779 if (rt5651_quirk & RT5651_IN2_DIFF)
1780 rt5651->pdata.in2_diff = true;
1781 if (rt5651_quirk & RT5651_DMIC_EN)
1782 rt5651->pdata.dmic_en = true;
1783 if (RT5651_JD_MAP(rt5651_quirk))
1784 rt5651->pdata.jd_src = RT5651_JD_MAP(rt5651_quirk);
1785}
1786
1787static irqreturn_t rt5651_irq(int irq, void *data)
1788{
1789 struct rt5651_priv *rt5651 = data;
1790
1791 queue_delayed_work(system_power_efficient_wq,
1792 &rt5651->jack_detect_work, msecs_to_jiffies(250));
1793
1794 return IRQ_HANDLED;
1795}
1796
1797static int rt5651_jack_detect(struct snd_soc_codec *codec, int jack_insert)
1798{
1799 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
1800 int jack_type;
1801
1802 if (jack_insert) {
1803 snd_soc_dapm_force_enable_pin(dapm, "LDO");
1804 snd_soc_dapm_sync(dapm);
1805
1806 snd_soc_update_bits(codec, RT5651_MICBIAS,
1807 RT5651_MIC1_OVCD_MASK |
1808 RT5651_MIC1_OVTH_MASK |
1809 RT5651_PWR_CLK12M_MASK |
1810 RT5651_PWR_MB_MASK,
1811 RT5651_MIC1_OVCD_EN |
1812 RT5651_MIC1_OVTH_600UA |
1813 RT5651_PWR_MB_PU |
1814 RT5651_PWR_CLK12M_PU);
1815 msleep(100);
1816 if (snd_soc_read(codec, RT5651_IRQ_CTRL2) & RT5651_MB1_OC_CLR)
1817 jack_type = SND_JACK_HEADPHONE;
1818 else
1819 jack_type = SND_JACK_HEADSET;
1820 snd_soc_update_bits(codec, RT5651_IRQ_CTRL2,
1821 RT5651_MB1_OC_CLR, 0);
1822 } else { /* jack out */
1823 jack_type = 0;
1824
1825 snd_soc_update_bits(codec, RT5651_MICBIAS,
1826 RT5651_MIC1_OVCD_MASK,
1827 RT5651_MIC1_OVCD_DIS);
1828 }
1829
1830 return jack_type;
1831}
1832
1833static void rt5651_jack_detect_work(struct work_struct *work)
1834{
1835 struct rt5651_priv *rt5651 =
1836 container_of(work, struct rt5651_priv, jack_detect_work.work);
1837
1838 int report, val = 0;
1839
1840 if (!rt5651->codec)
1841 return;
1842
1843 switch (rt5651->pdata.jd_src) {
1844 case RT5651_JD1_1:
1845 val = snd_soc_read(rt5651->codec, RT5651_INT_IRQ_ST) & 0x1000;
1846 break;
1847 case RT5651_JD1_2:
1848 val = snd_soc_read(rt5651->codec, RT5651_INT_IRQ_ST) & 0x2000;
1849 break;
1850 case RT5651_JD2:
1851 val = snd_soc_read(rt5651->codec, RT5651_INT_IRQ_ST) & 0x4000;
1852 break;
1853 default:
1854 break;
1855 }
1856
1857 report = rt5651_jack_detect(rt5651->codec, !val);
1858
1859 snd_soc_jack_report(rt5651->hp_jack, report, SND_JACK_HEADSET);
1860}
1861
1862int rt5651_set_jack_detect(struct snd_soc_codec *codec,
1863 struct snd_soc_jack *hp_jack)
1864{
1865 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec);
1866
1867 rt5651->hp_jack = hp_jack;
1868 rt5651_irq(0, rt5651);
1727 1869
1728 return 0; 1870 return 0;
1729} 1871}
1872EXPORT_SYMBOL_GPL(rt5651_set_jack_detect);
1730 1873
1731static int rt5651_i2c_probe(struct i2c_client *i2c, 1874static int rt5651_i2c_probe(struct i2c_client *i2c,
1732 const struct i2c_device_id *id) 1875 const struct i2c_device_id *id)
@@ -1746,6 +1889,10 @@ static int rt5651_i2c_probe(struct i2c_client *i2c,
1746 rt5651->pdata = *pdata; 1889 rt5651->pdata = *pdata;
1747 else if (i2c->dev.of_node) 1890 else if (i2c->dev.of_node)
1748 rt5651_parse_dt(rt5651, i2c->dev.of_node); 1891 rt5651_parse_dt(rt5651, i2c->dev.of_node);
1892 else
1893 dmi_check_system(rt5651_quirk_table);
1894
1895 rt5651_set_pdata(rt5651);
1749 1896
1750 rt5651->regmap = devm_regmap_init_i2c(i2c, &rt5651_regmap); 1897 rt5651->regmap = devm_regmap_init_i2c(i2c, &rt5651_regmap);
1751 if (IS_ERR(rt5651->regmap)) { 1898 if (IS_ERR(rt5651->regmap)) {
@@ -1779,6 +1926,59 @@ static int rt5651_i2c_probe(struct i2c_client *i2c,
1779 1926
1780 rt5651->hp_mute = 1; 1927 rt5651->hp_mute = 1;
1781 1928
1929 if (rt5651->pdata.jd_src) {
1930
1931 /* IRQ output on GPIO1 */
1932 regmap_update_bits(rt5651->regmap, RT5651_GPIO_CTRL1,
1933 RT5651_GP1_PIN_MASK, RT5651_GP1_PIN_IRQ);
1934
1935 switch (rt5651->pdata.jd_src) {
1936 case RT5651_JD1_1:
1937 regmap_update_bits(rt5651->regmap, RT5651_JD_CTRL2,
1938 RT5651_JD_TRG_SEL_MASK,
1939 RT5651_JD_TRG_SEL_JD1_1);
1940 regmap_update_bits(rt5651->regmap, RT5651_IRQ_CTRL1,
1941 RT5651_JD1_1_IRQ_EN,
1942 RT5651_JD1_1_IRQ_EN);
1943 break;
1944 case RT5651_JD1_2:
1945 regmap_update_bits(rt5651->regmap, RT5651_JD_CTRL2,
1946 RT5651_JD_TRG_SEL_MASK,
1947 RT5651_JD_TRG_SEL_JD1_2);
1948 regmap_update_bits(rt5651->regmap, RT5651_IRQ_CTRL1,
1949 RT5651_JD1_2_IRQ_EN,
1950 RT5651_JD1_2_IRQ_EN);
1951 break;
1952 case RT5651_JD2:
1953 regmap_update_bits(rt5651->regmap, RT5651_JD_CTRL2,
1954 RT5651_JD_TRG_SEL_MASK,
1955 RT5651_JD_TRG_SEL_JD2);
1956 regmap_update_bits(rt5651->regmap, RT5651_IRQ_CTRL1,
1957 RT5651_JD2_IRQ_EN,
1958 RT5651_JD2_IRQ_EN);
1959 break;
1960 case RT5651_JD_NULL:
1961 break;
1962 default:
1963 dev_warn(&i2c->dev, "Currently only JD1_1 / JD1_2 / JD2 are supported\n");
1964 break;
1965 }
1966 }
1967
1968 INIT_DELAYED_WORK(&rt5651->jack_detect_work, rt5651_jack_detect_work);
1969
1970 if (i2c->irq) {
1971 ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL,
1972 rt5651_irq,
1973 IRQF_TRIGGER_RISING |
1974 IRQF_TRIGGER_FALLING |
1975 IRQF_ONESHOT, "rt5651", rt5651);
1976 if (ret) {
1977 dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret);
1978 return ret;
1979 }
1980 }
1981
1782 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5651, 1982 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5651,
1783 rt5651_dai, ARRAY_SIZE(rt5651_dai)); 1983 rt5651_dai, ARRAY_SIZE(rt5651_dai));
1784 1984
@@ -1787,6 +1987,9 @@ static int rt5651_i2c_probe(struct i2c_client *i2c,
1787 1987
1788static int rt5651_i2c_remove(struct i2c_client *i2c) 1988static int rt5651_i2c_remove(struct i2c_client *i2c)
1789{ 1989{
1990 struct rt5651_priv *rt5651 = i2c_get_clientdata(i2c);
1991
1992 cancel_delayed_work_sync(&rt5651->jack_detect_work);
1790 snd_soc_unregister_codec(&i2c->dev); 1993 snd_soc_unregister_codec(&i2c->dev);
1791 1994
1792 return 0; 1995 return 0;
diff --git a/sound/soc/codecs/rt5651.h b/sound/soc/codecs/rt5651.h
index 1bd33cfa6411..4f8b202121d7 100644
--- a/sound/soc/codecs/rt5651.h
+++ b/sound/soc/codecs/rt5651.h
@@ -2062,6 +2062,8 @@ struct rt5651_priv {
2062 struct snd_soc_codec *codec; 2062 struct snd_soc_codec *codec;
2063 struct rt5651_platform_data pdata; 2063 struct rt5651_platform_data pdata;
2064 struct regmap *regmap; 2064 struct regmap *regmap;
2065 struct snd_soc_jack *hp_jack;
2066 struct delayed_work jack_detect_work;
2065 2067
2066 int sysclk; 2068 int sysclk;
2067 int sysclk_src; 2069 int sysclk_src;
@@ -2077,4 +2079,6 @@ struct rt5651_priv {
2077 bool hp_mute; 2079 bool hp_mute;
2078}; 2080};
2079 2081
2082int rt5651_set_jack_detect(struct snd_soc_codec *codec,
2083 struct snd_soc_jack *hp_jack);
2080#endif /* __RT5651_H__ */ 2084#endif /* __RT5651_H__ */
diff --git a/sound/soc/codecs/rt5659.c b/sound/soc/codecs/rt5659.c
index fa66b11df8d4..07e7757417bc 100644
--- a/sound/soc/codecs/rt5659.c
+++ b/sound/soc/codecs/rt5659.c
@@ -3385,10 +3385,9 @@ static int rt5659_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3385 return 0; 3385 return 0;
3386} 3386}
3387 3387
3388static int rt5659_set_dai_sysclk(struct snd_soc_dai *dai, 3388static int rt5659_set_codec_sysclk(struct snd_soc_codec *codec, int clk_id,
3389 int clk_id, unsigned int freq, int dir) 3389 int source, unsigned int freq, int dir)
3390{ 3390{
3391 struct snd_soc_codec *codec = dai->codec;
3392 struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); 3391 struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
3393 unsigned int reg_val = 0; 3392 unsigned int reg_val = 0;
3394 3393
@@ -3414,20 +3413,21 @@ static int rt5659_set_dai_sysclk(struct snd_soc_dai *dai,
3414 rt5659->sysclk = freq; 3413 rt5659->sysclk = freq;
3415 rt5659->sysclk_src = clk_id; 3414 rt5659->sysclk_src = clk_id;
3416 3415
3417 dev_dbg(dai->dev, "Sysclk is %dHz and clock id is %d\n", freq, clk_id); 3416 dev_dbg(codec->dev, "Sysclk is %dHz and clock id is %d\n",
3417 freq, clk_id);
3418 3418
3419 return 0; 3419 return 0;
3420} 3420}
3421 3421
3422static int rt5659_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int Source, 3422static int rt5659_set_codec_pll(struct snd_soc_codec *codec, int pll_id,
3423 unsigned int freq_in, unsigned int freq_out) 3423 int source, unsigned int freq_in,
3424 unsigned int freq_out)
3424{ 3425{
3425 struct snd_soc_codec *codec = dai->codec;
3426 struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec); 3426 struct rt5659_priv *rt5659 = snd_soc_codec_get_drvdata(codec);
3427 struct rl6231_pll_code pll_code; 3427 struct rl6231_pll_code pll_code;
3428 int ret; 3428 int ret;
3429 3429
3430 if (Source == rt5659->pll_src && freq_in == rt5659->pll_in && 3430 if (source == rt5659->pll_src && freq_in == rt5659->pll_in &&
3431 freq_out == rt5659->pll_out) 3431 freq_out == rt5659->pll_out)
3432 return 0; 3432 return 0;
3433 3433
@@ -3441,7 +3441,7 @@ static int rt5659_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int Source,
3441 return 0; 3441 return 0;
3442 } 3442 }
3443 3443
3444 switch (Source) { 3444 switch (source) {
3445 case RT5659_PLL1_S_MCLK: 3445 case RT5659_PLL1_S_MCLK:
3446 snd_soc_update_bits(codec, RT5659_GLB_CLK, 3446 snd_soc_update_bits(codec, RT5659_GLB_CLK,
3447 RT5659_PLL1_SRC_MASK, RT5659_PLL1_SRC_MCLK); 3447 RT5659_PLL1_SRC_MASK, RT5659_PLL1_SRC_MCLK);
@@ -3459,7 +3459,7 @@ static int rt5659_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int Source,
3459 RT5659_PLL1_SRC_MASK, RT5659_PLL1_SRC_BCLK3); 3459 RT5659_PLL1_SRC_MASK, RT5659_PLL1_SRC_BCLK3);
3460 break; 3460 break;
3461 default: 3461 default:
3462 dev_err(codec->dev, "Unknown PLL Source %d\n", Source); 3462 dev_err(codec->dev, "Unknown PLL source %d\n", source);
3463 return -EINVAL; 3463 return -EINVAL;
3464 } 3464 }
3465 3465
@@ -3481,7 +3481,7 @@ static int rt5659_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int Source,
3481 3481
3482 rt5659->pll_in = freq_in; 3482 rt5659->pll_in = freq_in;
3483 rt5659->pll_out = freq_out; 3483 rt5659->pll_out = freq_out;
3484 rt5659->pll_src = Source; 3484 rt5659->pll_src = source;
3485 3485
3486 return 0; 3486 return 0;
3487} 3487}
@@ -3666,9 +3666,7 @@ static int rt5659_resume(struct snd_soc_codec *codec)
3666static const struct snd_soc_dai_ops rt5659_aif_dai_ops = { 3666static const struct snd_soc_dai_ops rt5659_aif_dai_ops = {
3667 .hw_params = rt5659_hw_params, 3667 .hw_params = rt5659_hw_params,
3668 .set_fmt = rt5659_set_dai_fmt, 3668 .set_fmt = rt5659_set_dai_fmt,
3669 .set_sysclk = rt5659_set_dai_sysclk,
3670 .set_tdm_slot = rt5659_set_tdm_slot, 3669 .set_tdm_slot = rt5659_set_tdm_slot,
3671 .set_pll = rt5659_set_dai_pll,
3672 .set_bclk_ratio = rt5659_set_bclk_ratio, 3670 .set_bclk_ratio = rt5659_set_bclk_ratio,
3673}; 3671};
3674 3672
@@ -3747,6 +3745,8 @@ static const struct snd_soc_codec_driver soc_codec_dev_rt5659 = {
3747 .dapm_routes = rt5659_dapm_routes, 3745 .dapm_routes = rt5659_dapm_routes,
3748 .num_dapm_routes = ARRAY_SIZE(rt5659_dapm_routes), 3746 .num_dapm_routes = ARRAY_SIZE(rt5659_dapm_routes),
3749 }, 3747 },
3748 .set_sysclk = rt5659_set_codec_sysclk,
3749 .set_pll = rt5659_set_codec_pll,
3750}; 3750};
3751 3751
3752 3752
diff --git a/sound/soc/codecs/rt5663.c b/sound/soc/codecs/rt5663.c
index e45b895d8279..b036c9dc0c8c 100644
--- a/sound/soc/codecs/rt5663.c
+++ b/sound/soc/codecs/rt5663.c
@@ -38,13 +38,24 @@ enum {
38 CODEC_VER_0, 38 CODEC_VER_0,
39}; 39};
40 40
41struct impedance_mapping_table {
42 unsigned int imp_min;
43 unsigned int imp_max;
44 unsigned int vol;
45 unsigned int dc_offset_l_manual;
46 unsigned int dc_offset_r_manual;
47 unsigned int dc_offset_l_manual_mic;
48 unsigned int dc_offset_r_manual_mic;
49};
50
41struct rt5663_priv { 51struct rt5663_priv {
42 struct snd_soc_codec *codec; 52 struct snd_soc_codec *codec;
43 struct rt5663_platform_data pdata; 53 struct rt5663_platform_data pdata;
44 struct regmap *regmap; 54 struct regmap *regmap;
45 struct delayed_work jack_detect_work; 55 struct delayed_work jack_detect_work, jd_unplug_work;
46 struct snd_soc_jack *hs_jack; 56 struct snd_soc_jack *hs_jack;
47 struct timer_list btn_check_timer; 57 struct timer_list btn_check_timer;
58 struct impedance_mapping_table *imp_table;
48 59
49 int codec_ver; 60 int codec_ver;
50 int sysclk; 61 int sysclk;
@@ -1575,6 +1586,9 @@ static int rt5663_jack_detect(struct snd_soc_codec *codec, int jack_insert)
1575 rt5663->jack_type = SND_JACK_HEADSET; 1586 rt5663->jack_type = SND_JACK_HEADSET;
1576 rt5663_enable_push_button_irq(codec, true); 1587 rt5663_enable_push_button_irq(codec, true);
1577 1588
1589 if (rt5663->pdata.impedance_sensing_num)
1590 break;
1591
1578 if (rt5663->pdata.dc_offset_l_manual_mic) { 1592 if (rt5663->pdata.dc_offset_l_manual_mic) {
1579 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_2, 1593 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_2,
1580 rt5663->pdata.dc_offset_l_manual_mic >> 1594 rt5663->pdata.dc_offset_l_manual_mic >>
@@ -1596,6 +1610,9 @@ static int rt5663_jack_detect(struct snd_soc_codec *codec, int jack_insert)
1596 default: 1610 default:
1597 rt5663->jack_type = SND_JACK_HEADPHONE; 1611 rt5663->jack_type = SND_JACK_HEADPHONE;
1598 1612
1613 if (rt5663->pdata.impedance_sensing_num)
1614 break;
1615
1599 if (rt5663->pdata.dc_offset_l_manual) { 1616 if (rt5663->pdata.dc_offset_l_manual) {
1600 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_2, 1617 regmap_write(rt5663->regmap, RT5663_MIC_DECRO_2,
1601 rt5663->pdata.dc_offset_l_manual >> 16); 1618 rt5663->pdata.dc_offset_l_manual >> 16);
@@ -1623,6 +1640,177 @@ static int rt5663_jack_detect(struct snd_soc_codec *codec, int jack_insert)
1623 return rt5663->jack_type; 1640 return rt5663->jack_type;
1624} 1641}
1625 1642
1643static int rt5663_impedance_sensing(struct snd_soc_codec *codec)
1644{
1645 struct rt5663_priv *rt5663 = snd_soc_codec_get_drvdata(codec);
1646 unsigned int value, i, reg84, reg26, reg2fa, reg91, reg10, reg80;
1647
1648 for (i = 0; i < rt5663->pdata.impedance_sensing_num; i++) {
1649 if (rt5663->imp_table[i].vol == 7)
1650 break;
1651 }
1652
1653 if (rt5663->jack_type == SND_JACK_HEADSET) {
1654 snd_soc_write(codec, RT5663_MIC_DECRO_2,
1655 rt5663->imp_table[i].dc_offset_l_manual_mic >> 16);
1656 snd_soc_write(codec, RT5663_MIC_DECRO_3,
1657 rt5663->imp_table[i].dc_offset_l_manual_mic & 0xffff);
1658 snd_soc_write(codec, RT5663_MIC_DECRO_5,
1659 rt5663->imp_table[i].dc_offset_r_manual_mic >> 16);
1660 snd_soc_write(codec, RT5663_MIC_DECRO_6,
1661 rt5663->imp_table[i].dc_offset_r_manual_mic & 0xffff);
1662 } else {
1663 snd_soc_write(codec, RT5663_MIC_DECRO_2,
1664 rt5663->imp_table[i].dc_offset_l_manual >> 16);
1665 snd_soc_write(codec, RT5663_MIC_DECRO_3,
1666 rt5663->imp_table[i].dc_offset_l_manual & 0xffff);
1667 snd_soc_write(codec, RT5663_MIC_DECRO_5,
1668 rt5663->imp_table[i].dc_offset_r_manual >> 16);
1669 snd_soc_write(codec, RT5663_MIC_DECRO_6,
1670 rt5663->imp_table[i].dc_offset_r_manual & 0xffff);
1671 }
1672
1673 reg84 = snd_soc_read(codec, RT5663_ASRC_2);
1674 reg26 = snd_soc_read(codec, RT5663_STO1_ADC_MIXER);
1675 reg2fa = snd_soc_read(codec, RT5663_DUMMY_1);
1676 reg91 = snd_soc_read(codec, RT5663_HP_CHARGE_PUMP_1);
1677 reg10 = snd_soc_read(codec, RT5663_RECMIX);
1678 reg80 = snd_soc_read(codec, RT5663_GLB_CLK);
1679
1680 snd_soc_update_bits(codec, RT5663_STO_DRE_1, 0x8000, 0);
1681 snd_soc_write(codec, RT5663_ASRC_2, 0);
1682 snd_soc_write(codec, RT5663_STO1_ADC_MIXER, 0x4040);
1683 snd_soc_update_bits(codec, RT5663_PWR_ANLG_1,
1684 RT5663_PWR_VREF1_MASK | RT5663_PWR_VREF2_MASK |
1685 RT5663_PWR_FV1_MASK | RT5663_PWR_FV2_MASK,
1686 RT5663_PWR_VREF1 | RT5663_PWR_VREF2);
1687 usleep_range(10000, 10005);
1688 snd_soc_update_bits(codec, RT5663_PWR_ANLG_1,
1689 RT5663_PWR_FV1_MASK | RT5663_PWR_FV2_MASK,
1690 RT5663_PWR_FV1 | RT5663_PWR_FV2);
1691 snd_soc_update_bits(codec, RT5663_GLB_CLK, RT5663_SCLK_SRC_MASK,
1692 RT5663_SCLK_SRC_RCCLK);
1693 snd_soc_update_bits(codec, RT5663_RC_CLK, RT5663_DIG_25M_CLK_MASK,
1694 RT5663_DIG_25M_CLK_EN);
1695 snd_soc_update_bits(codec, RT5663_ADDA_CLK_1, RT5663_I2S_PD1_MASK, 0);
1696 snd_soc_write(codec, RT5663_PRE_DIV_GATING_1, 0xff00);
1697 snd_soc_write(codec, RT5663_PRE_DIV_GATING_2, 0xfffc);
1698 snd_soc_write(codec, RT5663_HP_CHARGE_PUMP_1, 0x1232);
1699 snd_soc_write(codec, RT5663_HP_LOGIC_2, 0x0005);
1700 snd_soc_write(codec, RT5663_DEPOP_2, 0x3003);
1701 snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x0030, 0x0030);
1702 snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x0003, 0x0003);
1703 snd_soc_update_bits(codec, RT5663_PWR_DIG_2,
1704 RT5663_PWR_ADC_S1F | RT5663_PWR_DAC_S1F,
1705 RT5663_PWR_ADC_S1F | RT5663_PWR_DAC_S1F);
1706 snd_soc_update_bits(codec, RT5663_PWR_DIG_1,
1707 RT5663_PWR_DAC_L1 | RT5663_PWR_DAC_R1 |
1708 RT5663_PWR_LDO_DACREF_MASK | RT5663_PWR_ADC_L1 |
1709 RT5663_PWR_ADC_R1,
1710 RT5663_PWR_DAC_L1 | RT5663_PWR_DAC_R1 |
1711 RT5663_PWR_LDO_DACREF_ON | RT5663_PWR_ADC_L1 |
1712 RT5663_PWR_ADC_R1);
1713 msleep(40);
1714 snd_soc_update_bits(codec, RT5663_PWR_ANLG_2,
1715 RT5663_PWR_RECMIX1 | RT5663_PWR_RECMIX2,
1716 RT5663_PWR_RECMIX1 | RT5663_PWR_RECMIX2);
1717 msleep(30);
1718 snd_soc_write(codec, RT5663_HP_CHARGE_PUMP_2, 0x1371);
1719 snd_soc_write(codec, RT5663_STO_DAC_MIXER, 0);
1720 snd_soc_write(codec, RT5663_BYPASS_STO_DAC, 0x000c);
1721 snd_soc_write(codec, RT5663_HP_BIAS, 0xafaa);
1722 snd_soc_write(codec, RT5663_CHARGE_PUMP_1, 0x2224);
1723 snd_soc_write(codec, RT5663_HP_OUT_EN, 0x8088);
1724 snd_soc_write(codec, RT5663_CHOP_ADC, 0x3000);
1725 snd_soc_write(codec, RT5663_ADDA_RST, 0xc000);
1726 snd_soc_write(codec, RT5663_STO1_HPF_ADJ1, 0x3320);
1727 snd_soc_write(codec, RT5663_HP_CALIB_2, 0x00c9);
1728 snd_soc_write(codec, RT5663_DUMMY_1, 0x004c);
1729 snd_soc_write(codec, RT5663_ANA_BIAS_CUR_1, 0x7733);
1730 snd_soc_write(codec, RT5663_CHARGE_PUMP_2, 0x7777);
1731 snd_soc_write(codec, RT5663_STO_DRE_9, 0x0007);
1732 snd_soc_write(codec, RT5663_STO_DRE_10, 0x0007);
1733 snd_soc_write(codec, RT5663_DUMMY_2, 0x02a4);
1734 snd_soc_write(codec, RT5663_RECMIX, 0x0005);
1735 snd_soc_write(codec, RT5663_HP_IMP_SEN_1, 0x4334);
1736 snd_soc_update_bits(codec, RT5663_IRQ_3, 0x0004, 0x0004);
1737 snd_soc_write(codec, RT5663_HP_LOGIC_1, 0x2200);
1738 snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x3000, 0x3000);
1739 snd_soc_write(codec, RT5663_HP_LOGIC_1, 0x6200);
1740
1741 for (i = 0; i < 100; i++) {
1742 msleep(20);
1743 if (snd_soc_read(codec, RT5663_INT_ST_1) & 0x2)
1744 break;
1745 }
1746
1747 value = snd_soc_read(codec, RT5663_HP_IMP_SEN_4);
1748
1749 snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x3000, 0);
1750 snd_soc_write(codec, RT5663_INT_ST_1, 0);
1751 snd_soc_write(codec, RT5663_HP_LOGIC_1, 0);
1752 snd_soc_update_bits(codec, RT5663_RC_CLK, RT5663_DIG_25M_CLK_MASK,
1753 RT5663_DIG_25M_CLK_DIS);
1754 snd_soc_write(codec, RT5663_GLB_CLK, reg80);
1755 snd_soc_write(codec, RT5663_RECMIX, reg10);
1756 snd_soc_write(codec, RT5663_DUMMY_2, 0x00a4);
1757 snd_soc_write(codec, RT5663_DUMMY_1, reg2fa);
1758 snd_soc_write(codec, RT5663_HP_CALIB_2, 0x00c8);
1759 snd_soc_write(codec, RT5663_STO1_HPF_ADJ1, 0xb320);
1760 snd_soc_write(codec, RT5663_ADDA_RST, 0xe400);
1761 snd_soc_write(codec, RT5663_CHOP_ADC, 0x2000);
1762 snd_soc_write(codec, RT5663_HP_OUT_EN, 0x0008);
1763 snd_soc_update_bits(codec, RT5663_PWR_ANLG_2,
1764 RT5663_PWR_RECMIX1 | RT5663_PWR_RECMIX2, 0);
1765 snd_soc_update_bits(codec, RT5663_PWR_DIG_1,
1766 RT5663_PWR_DAC_L1 | RT5663_PWR_DAC_R1 |
1767 RT5663_PWR_LDO_DACREF_MASK | RT5663_PWR_ADC_L1 |
1768 RT5663_PWR_ADC_R1, 0);
1769 snd_soc_update_bits(codec, RT5663_PWR_DIG_2,
1770 RT5663_PWR_ADC_S1F | RT5663_PWR_DAC_S1F, 0);
1771 snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x0003, 0);
1772 snd_soc_update_bits(codec, RT5663_DEPOP_1, 0x0030, 0);
1773 snd_soc_write(codec, RT5663_HP_LOGIC_2, 0);
1774 snd_soc_write(codec, RT5663_HP_CHARGE_PUMP_1, reg91);
1775 snd_soc_update_bits(codec, RT5663_PWR_ANLG_1,
1776 RT5663_PWR_VREF1_MASK | RT5663_PWR_VREF2_MASK, 0);
1777 snd_soc_write(codec, RT5663_STO1_ADC_MIXER, reg26);
1778 snd_soc_write(codec, RT5663_ASRC_2, reg84);
1779
1780 for (i = 0; i < rt5663->pdata.impedance_sensing_num; i++) {
1781 if (value >= rt5663->imp_table[i].imp_min &&
1782 value <= rt5663->imp_table[i].imp_max)
1783 break;
1784 }
1785
1786 snd_soc_update_bits(codec, RT5663_STO_DRE_9, RT5663_DRE_GAIN_HP_MASK,
1787 rt5663->imp_table[i].vol);
1788 snd_soc_update_bits(codec, RT5663_STO_DRE_10, RT5663_DRE_GAIN_HP_MASK,
1789 rt5663->imp_table[i].vol);
1790
1791 if (rt5663->jack_type == SND_JACK_HEADSET) {
1792 snd_soc_write(codec, RT5663_MIC_DECRO_2,
1793 rt5663->imp_table[i].dc_offset_l_manual_mic >> 16);
1794 snd_soc_write(codec, RT5663_MIC_DECRO_3,
1795 rt5663->imp_table[i].dc_offset_l_manual_mic & 0xffff);
1796 snd_soc_write(codec, RT5663_MIC_DECRO_5,
1797 rt5663->imp_table[i].dc_offset_r_manual_mic >> 16);
1798 snd_soc_write(codec, RT5663_MIC_DECRO_6,
1799 rt5663->imp_table[i].dc_offset_r_manual_mic & 0xffff);
1800 } else {
1801 snd_soc_write(codec, RT5663_MIC_DECRO_2,
1802 rt5663->imp_table[i].dc_offset_l_manual >> 16);
1803 snd_soc_write(codec, RT5663_MIC_DECRO_3,
1804 rt5663->imp_table[i].dc_offset_l_manual & 0xffff);
1805 snd_soc_write(codec, RT5663_MIC_DECRO_5,
1806 rt5663->imp_table[i].dc_offset_r_manual >> 16);
1807 snd_soc_write(codec, RT5663_MIC_DECRO_6,
1808 rt5663->imp_table[i].dc_offset_r_manual & 0xffff);
1809 }
1810
1811 return 0;
1812}
1813
1626static int rt5663_button_detect(struct snd_soc_codec *codec) 1814static int rt5663_button_detect(struct snd_soc_codec *codec)
1627{ 1815{
1628 int btn_type, val; 1816 int btn_type, val;
@@ -1702,6 +1890,8 @@ static void rt5663_jack_detect_work(struct work_struct *work)
1702 break; 1890 break;
1703 case CODEC_VER_0: 1891 case CODEC_VER_0:
1704 report = rt5663_jack_detect(rt5663->codec, 1); 1892 report = rt5663_jack_detect(rt5663->codec, 1);
1893 if (rt5663->pdata.impedance_sensing_num)
1894 rt5663_impedance_sensing(rt5663->codec);
1705 break; 1895 break;
1706 default: 1896 default:
1707 dev_err(codec->dev, "Unknown CODEC Version\n"); 1897 dev_err(codec->dev, "Unknown CODEC Version\n");
@@ -1751,8 +1941,15 @@ static void rt5663_jack_detect_work(struct work_struct *work)
1751 break; 1941 break;
1752 } 1942 }
1753 /* button release or spurious interrput*/ 1943 /* button release or spurious interrput*/
1754 if (btn_type == 0) 1944 if (btn_type == 0) {
1755 report = rt5663->jack_type; 1945 report = rt5663->jack_type;
1946 cancel_delayed_work_sync(
1947 &rt5663->jd_unplug_work);
1948 } else {
1949 queue_delayed_work(system_wq,
1950 &rt5663->jd_unplug_work,
1951 msecs_to_jiffies(500));
1952 }
1756 } 1953 }
1757 } else { 1954 } else {
1758 /* jack out */ 1955 /* jack out */
@@ -1773,6 +1970,37 @@ static void rt5663_jack_detect_work(struct work_struct *work)
1773 SND_JACK_BTN_2 | SND_JACK_BTN_3); 1970 SND_JACK_BTN_2 | SND_JACK_BTN_3);
1774} 1971}
1775 1972
1973static void rt5663_jd_unplug_work(struct work_struct *work)
1974{
1975 struct rt5663_priv *rt5663 =
1976 container_of(work, struct rt5663_priv, jd_unplug_work.work);
1977 struct snd_soc_codec *codec = rt5663->codec;
1978
1979 if (!codec)
1980 return;
1981
1982 if (!rt5663_check_jd_status(codec)) {
1983 /* jack out */
1984 switch (rt5663->codec_ver) {
1985 case CODEC_VER_1:
1986 rt5663_v2_jack_detect(rt5663->codec, 0);
1987 break;
1988 case CODEC_VER_0:
1989 rt5663_jack_detect(rt5663->codec, 0);
1990 break;
1991 default:
1992 dev_err(codec->dev, "Unknown CODEC Version\n");
1993 }
1994
1995 snd_soc_jack_report(rt5663->hs_jack, 0, SND_JACK_HEADSET |
1996 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
1997 SND_JACK_BTN_2 | SND_JACK_BTN_3);
1998 } else {
1999 queue_delayed_work(system_wq, &rt5663->jd_unplug_work,
2000 msecs_to_jiffies(500));
2001 }
2002}
2003
1776static const struct snd_kcontrol_new rt5663_snd_controls[] = { 2004static const struct snd_kcontrol_new rt5663_snd_controls[] = {
1777 /* DAC Digital Volume */ 2005 /* DAC Digital Volume */
1778 SOC_DOUBLE_TLV("DAC Playback Volume", RT5663_STO1_DAC_DIG_VOL, 2006 SOC_DOUBLE_TLV("DAC Playback Volume", RT5663_STO1_DAC_DIG_VOL,
@@ -1797,10 +2025,6 @@ static const struct snd_kcontrol_new rt5663_v2_specific_controls[] = {
1797}; 2025};
1798 2026
1799static const struct snd_kcontrol_new rt5663_specific_controls[] = { 2027static const struct snd_kcontrol_new rt5663_specific_controls[] = {
1800 /* Headphone Output Volume */
1801 SOC_DOUBLE_R_TLV("Headphone Playback Volume", RT5663_STO_DRE_9,
1802 RT5663_STO_DRE_10, RT5663_DRE_GAIN_HP_SHIFT, 23, 1,
1803 rt5663_hp_vol_tlv),
1804 /* Mic Boost Volume*/ 2028 /* Mic Boost Volume*/
1805 SOC_SINGLE_TLV("IN1 Capture Volume", RT5663_CBJ_2, 2029 SOC_SINGLE_TLV("IN1 Capture Volume", RT5663_CBJ_2,
1806 RT5663_GAIN_BST1_SHIFT, 8, 0, in_bst_tlv), 2030 RT5663_GAIN_BST1_SHIFT, 8, 0, in_bst_tlv),
@@ -1808,6 +2032,13 @@ static const struct snd_kcontrol_new rt5663_specific_controls[] = {
1808 SOC_ENUM("IF1 ADC Data Swap", rt5663_if1_adc_enum), 2032 SOC_ENUM("IF1 ADC Data Swap", rt5663_if1_adc_enum),
1809}; 2033};
1810 2034
2035static const struct snd_kcontrol_new rt5663_hpvol_controls[] = {
2036 /* Headphone Output Volume */
2037 SOC_DOUBLE_R_TLV("Headphone Playback Volume", RT5663_STO_DRE_9,
2038 RT5663_STO_DRE_10, RT5663_DRE_GAIN_HP_SHIFT, 23, 1,
2039 rt5663_hp_vol_tlv),
2040};
2041
1811static int rt5663_is_sys_clk_from_pll(struct snd_soc_dapm_widget *w, 2042static int rt5663_is_sys_clk_from_pll(struct snd_soc_dapm_widget *w,
1812 struct snd_soc_dapm_widget *sink) 2043 struct snd_soc_dapm_widget *sink)
1813{ 2044{
@@ -2890,6 +3121,10 @@ static int rt5663_probe(struct snd_soc_codec *codec)
2890 ARRAY_SIZE(rt5663_specific_dapm_routes)); 3121 ARRAY_SIZE(rt5663_specific_dapm_routes));
2891 snd_soc_add_codec_controls(codec, rt5663_specific_controls, 3122 snd_soc_add_codec_controls(codec, rt5663_specific_controls,
2892 ARRAY_SIZE(rt5663_specific_controls)); 3123 ARRAY_SIZE(rt5663_specific_controls));
3124
3125 if (!rt5663->imp_table)
3126 snd_soc_add_codec_controls(codec, rt5663_hpvol_controls,
3127 ARRAY_SIZE(rt5663_hpvol_controls));
2893 break; 3128 break;
2894 } 3129 }
2895 3130
@@ -3178,6 +3413,8 @@ static void rt5663_calibrate(struct rt5663_priv *rt5663)
3178 3413
3179static int rt5663_parse_dp(struct rt5663_priv *rt5663, struct device *dev) 3414static int rt5663_parse_dp(struct rt5663_priv *rt5663, struct device *dev)
3180{ 3415{
3416 int table_size;
3417
3181 device_property_read_u32(dev, "realtek,dc_offset_l_manual", 3418 device_property_read_u32(dev, "realtek,dc_offset_l_manual",
3182 &rt5663->pdata.dc_offset_l_manual); 3419 &rt5663->pdata.dc_offset_l_manual);
3183 device_property_read_u32(dev, "realtek,dc_offset_r_manual", 3420 device_property_read_u32(dev, "realtek,dc_offset_r_manual",
@@ -3186,6 +3423,17 @@ static int rt5663_parse_dp(struct rt5663_priv *rt5663, struct device *dev)
3186 &rt5663->pdata.dc_offset_l_manual_mic); 3423 &rt5663->pdata.dc_offset_l_manual_mic);
3187 device_property_read_u32(dev, "realtek,dc_offset_r_manual_mic", 3424 device_property_read_u32(dev, "realtek,dc_offset_r_manual_mic",
3188 &rt5663->pdata.dc_offset_r_manual_mic); 3425 &rt5663->pdata.dc_offset_r_manual_mic);
3426 device_property_read_u32(dev, "realtek,impedance_sensing_num",
3427 &rt5663->pdata.impedance_sensing_num);
3428
3429 if (rt5663->pdata.impedance_sensing_num) {
3430 table_size = sizeof(struct impedance_mapping_table) *
3431 rt5663->pdata.impedance_sensing_num;
3432 rt5663->imp_table = devm_kzalloc(dev, table_size, GFP_KERNEL);
3433 device_property_read_u32_array(dev,
3434 "realtek,impedance_sensing_table",
3435 (u32 *)rt5663->imp_table, table_size);
3436 }
3189 3437
3190 return 0; 3438 return 0;
3191} 3439}
@@ -3219,7 +3467,16 @@ static int rt5663_i2c_probe(struct i2c_client *i2c,
3219 ret); 3467 ret);
3220 return ret; 3468 return ret;
3221 } 3469 }
3222 regmap_read(regmap, RT5663_VENDOR_ID_2, &val); 3470
3471 ret = regmap_read(regmap, RT5663_VENDOR_ID_2, &val);
3472 if (ret || (val != RT5663_DEVICE_ID_2 && val != RT5663_DEVICE_ID_1)) {
3473 dev_err(&i2c->dev,
3474 "Device with ID register %#x is not rt5663, retry one time.\n",
3475 val);
3476 msleep(100);
3477 regmap_read(regmap, RT5663_VENDOR_ID_2, &val);
3478 }
3479
3223 switch (val) { 3480 switch (val) {
3224 case RT5663_DEVICE_ID_2: 3481 case RT5663_DEVICE_ID_2:
3225 rt5663->regmap = devm_regmap_init_i2c(i2c, &rt5663_v2_regmap); 3482 rt5663->regmap = devm_regmap_init_i2c(i2c, &rt5663_v2_regmap);
@@ -3338,6 +3595,7 @@ static int rt5663_i2c_probe(struct i2c_client *i2c,
3338 } 3595 }
3339 3596
3340 INIT_DELAYED_WORK(&rt5663->jack_detect_work, rt5663_jack_detect_work); 3597 INIT_DELAYED_WORK(&rt5663->jack_detect_work, rt5663_jack_detect_work);
3598 INIT_DELAYED_WORK(&rt5663->jd_unplug_work, rt5663_jd_unplug_work);
3341 3599
3342 if (i2c->irq) { 3600 if (i2c->irq) {
3343 ret = request_irq(i2c->irq, rt5663_irq, 3601 ret = request_irq(i2c->irq, rt5663_irq,
diff --git a/sound/soc/codecs/rt5670.c b/sound/soc/codecs/rt5670.c
index 9545764ef3eb..c5094b4399e2 100644
--- a/sound/soc/codecs/rt5670.c
+++ b/sound/soc/codecs/rt5670.c
@@ -34,6 +34,24 @@
34#include "rt5670.h" 34#include "rt5670.h"
35#include "rt5670-dsp.h" 35#include "rt5670-dsp.h"
36 36
37#define RT5670_DEV_GPIO BIT(0)
38#define RT5670_IN2_DIFF BIT(1)
39#define RT5670_DMIC_EN BIT(2)
40#define RT5670_DMIC1_IN2P BIT(3)
41#define RT5670_DMIC1_GPIO6 BIT(4)
42#define RT5670_DMIC1_GPIO7 BIT(5)
43#define RT5670_DMIC2_INR BIT(6)
44#define RT5670_DMIC2_GPIO8 BIT(7)
45#define RT5670_DMIC3_GPIO5 BIT(8)
46#define RT5670_JD_MODE1 BIT(9)
47#define RT5670_JD_MODE2 BIT(10)
48#define RT5670_JD_MODE3 BIT(11)
49
50static unsigned long rt5670_quirk;
51static unsigned int quirk_override;
52module_param_named(quirk, quirk_override, uint, 0444);
53MODULE_PARM_DESC(quirk, "Board-specific quirk override");
54
37#define RT5670_DEVICE_ID 0x6271 55#define RT5670_DEVICE_ID 0x6271
38 56
39#define RT5670_PR_RANGE_BASE (0xff + 1) 57#define RT5670_PR_RANGE_BASE (0xff + 1)
@@ -2582,6 +2600,24 @@ static int rt5670_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
2582 return 0; 2600 return 0;
2583} 2601}
2584 2602
2603static int rt5670_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
2604{
2605 struct snd_soc_codec *codec = dai->codec;
2606
2607 dev_dbg(codec->dev, "%s ratio=%d\n", __func__, ratio);
2608 if (dai->id != RT5670_AIF1)
2609 return 0;
2610
2611 if ((ratio % 50) == 0)
2612 snd_soc_update_bits(codec, RT5670_GEN_CTRL3,
2613 RT5670_TDM_DATA_MODE_SEL, RT5670_TDM_DATA_MODE_50FS);
2614 else
2615 snd_soc_update_bits(codec, RT5670_GEN_CTRL3,
2616 RT5670_TDM_DATA_MODE_SEL, RT5670_TDM_DATA_MODE_NOR);
2617
2618 return 0;
2619}
2620
2585static int rt5670_set_bias_level(struct snd_soc_codec *codec, 2621static int rt5670_set_bias_level(struct snd_soc_codec *codec,
2586 enum snd_soc_bias_level level) 2622 enum snd_soc_bias_level level)
2587{ 2623{
@@ -2712,6 +2748,7 @@ static const struct snd_soc_dai_ops rt5670_aif_dai_ops = {
2712 .set_fmt = rt5670_set_dai_fmt, 2748 .set_fmt = rt5670_set_dai_fmt,
2713 .set_tdm_slot = rt5670_set_tdm_slot, 2749 .set_tdm_slot = rt5670_set_tdm_slot,
2714 .set_pll = rt5670_set_dai_pll, 2750 .set_pll = rt5670_set_dai_pll,
2751 .set_bclk_ratio = rt5670_set_bclk_ratio,
2715}; 2752};
2716 2753
2717static struct snd_soc_dai_driver rt5670_dai[] = { 2754static struct snd_soc_dai_driver rt5670_dai[] = {
@@ -2808,56 +2845,84 @@ static const struct acpi_device_id rt5670_acpi_match[] = {
2808MODULE_DEVICE_TABLE(acpi, rt5670_acpi_match); 2845MODULE_DEVICE_TABLE(acpi, rt5670_acpi_match);
2809#endif 2846#endif
2810 2847
2811static const struct dmi_system_id dmi_platform_intel_braswell[] = { 2848static int rt5670_quirk_cb(const struct dmi_system_id *id)
2849{
2850 rt5670_quirk = (unsigned long)id->driver_data;
2851 return 1;
2852}
2853
2854static const struct dmi_system_id dmi_platform_intel_quirks[] = {
2812 { 2855 {
2856 .callback = rt5670_quirk_cb,
2813 .ident = "Intel Braswell", 2857 .ident = "Intel Braswell",
2814 .matches = { 2858 .matches = {
2815 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"), 2859 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
2816 DMI_MATCH(DMI_BOARD_NAME, "Braswell CRB"), 2860 DMI_MATCH(DMI_BOARD_NAME, "Braswell CRB"),
2817 }, 2861 },
2862 .driver_data = (unsigned long *)(RT5670_DMIC_EN |
2863 RT5670_DMIC1_IN2P |
2864 RT5670_DEV_GPIO |
2865 RT5670_JD_MODE1),
2818 }, 2866 },
2819 { 2867 {
2868 .callback = rt5670_quirk_cb,
2820 .ident = "Dell Wyse 3040", 2869 .ident = "Dell Wyse 3040",
2821 .matches = { 2870 .matches = {
2822 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 2871 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
2823 DMI_MATCH(DMI_PRODUCT_NAME, "Wyse 3040"), 2872 DMI_MATCH(DMI_PRODUCT_NAME, "Wyse 3040"),
2824 }, 2873 },
2874 .driver_data = (unsigned long *)(RT5670_DMIC_EN |
2875 RT5670_DMIC1_IN2P |
2876 RT5670_DEV_GPIO |
2877 RT5670_JD_MODE1),
2825 }, 2878 },
2826 { 2879 {
2880 .callback = rt5670_quirk_cb,
2827 .ident = "Lenovo Thinkpad Tablet 10", 2881 .ident = "Lenovo Thinkpad Tablet 10",
2828 .matches = { 2882 .matches = {
2829 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 2883 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
2830 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad 10"), 2884 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad 10"),
2831 }, 2885 },
2886 .driver_data = (unsigned long *)(RT5670_DMIC_EN |
2887 RT5670_DMIC1_IN2P |
2888 RT5670_DEV_GPIO |
2889 RT5670_JD_MODE1),
2832 }, 2890 },
2833 { 2891 {
2892 .callback = rt5670_quirk_cb,
2834 .ident = "Lenovo Thinkpad Tablet 10", 2893 .ident = "Lenovo Thinkpad Tablet 10",
2835 .matches = { 2894 .matches = {
2836 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 2895 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
2837 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad Tablet B"), 2896 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad Tablet B"),
2838 }, 2897 },
2898 .driver_data = (unsigned long *)(RT5670_DMIC_EN |
2899 RT5670_DMIC1_IN2P |
2900 RT5670_DEV_GPIO |
2901 RT5670_JD_MODE1),
2839 }, 2902 },
2840 {}
2841};
2842
2843static const struct dmi_system_id dmi_platform_intel_bytcht_jdmode2[] = {
2844 { 2903 {
2904 .callback = rt5670_quirk_cb,
2845 .ident = "Lenovo Thinkpad Tablet 10", 2905 .ident = "Lenovo Thinkpad Tablet 10",
2846 .matches = { 2906 .matches = {
2847 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"), 2907 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
2848 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Miix 2 10"), 2908 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Miix 2 10"),
2849 }, 2909 },
2910 .driver_data = (unsigned long *)(RT5670_DMIC_EN |
2911 RT5670_DMIC1_IN2P |
2912 RT5670_DEV_GPIO |
2913 RT5670_JD_MODE2),
2850 }, 2914 },
2851 {}
2852};
2853
2854static const struct dmi_system_id dmi_platform_intel_bytcht_jdmode3[] = {
2855 { 2915 {
2916 .callback = rt5670_quirk_cb,
2856 .ident = "Dell Venue 8 Pro 5855", 2917 .ident = "Dell Venue 8 Pro 5855",
2857 .matches = { 2918 .matches = {
2858 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 2919 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
2859 DMI_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5855"), 2920 DMI_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5855"),
2860 }, 2921 },
2922 .driver_data = (unsigned long *)(RT5670_DMIC_EN |
2923 RT5670_DMIC2_INR |
2924 RT5670_DEV_GPIO |
2925 RT5670_JD_MODE3),
2861 }, 2926 },
2862 {} 2927 {}
2863}; 2928};
@@ -2881,21 +2946,61 @@ static int rt5670_i2c_probe(struct i2c_client *i2c,
2881 if (pdata) 2946 if (pdata)
2882 rt5670->pdata = *pdata; 2947 rt5670->pdata = *pdata;
2883 2948
2884 if (dmi_check_system(dmi_platform_intel_braswell)) { 2949 dmi_check_system(dmi_platform_intel_quirks);
2885 rt5670->pdata.dmic_en = true; 2950 if (quirk_override) {
2886 rt5670->pdata.dmic1_data_pin = RT5670_DMIC_DATA_IN2P; 2951 dev_info(&i2c->dev, "Overriding quirk 0x%x => 0x%x\n",
2952 (unsigned int)rt5670_quirk, quirk_override);
2953 rt5670_quirk = quirk_override;
2954 }
2955
2956 if (rt5670_quirk & RT5670_DEV_GPIO) {
2887 rt5670->pdata.dev_gpio = true; 2957 rt5670->pdata.dev_gpio = true;
2888 rt5670->pdata.jd_mode = 1; 2958 dev_info(&i2c->dev, "quirk dev_gpio\n");
2889 } else if (dmi_check_system(dmi_platform_intel_bytcht_jdmode2)) { 2959 }
2960 if (rt5670_quirk & RT5670_IN2_DIFF) {
2961 rt5670->pdata.in2_diff = true;
2962 dev_info(&i2c->dev, "quirk IN2_DIFF\n");
2963 }
2964 if (rt5670_quirk & RT5670_DMIC_EN) {
2890 rt5670->pdata.dmic_en = true; 2965 rt5670->pdata.dmic_en = true;
2966 dev_info(&i2c->dev, "quirk DMIC enabled\n");
2967 }
2968 if (rt5670_quirk & RT5670_DMIC1_IN2P) {
2891 rt5670->pdata.dmic1_data_pin = RT5670_DMIC_DATA_IN2P; 2969 rt5670->pdata.dmic1_data_pin = RT5670_DMIC_DATA_IN2P;
2892 rt5670->pdata.dev_gpio = true; 2970 dev_info(&i2c->dev, "quirk DMIC1 on IN2P pin\n");
2971 }
2972 if (rt5670_quirk & RT5670_DMIC1_GPIO6) {
2973 rt5670->pdata.dmic1_data_pin = RT5670_DMIC_DATA_GPIO6;
2974 dev_info(&i2c->dev, "quirk DMIC1 on GPIO6 pin\n");
2975 }
2976 if (rt5670_quirk & RT5670_DMIC1_GPIO7) {
2977 rt5670->pdata.dmic1_data_pin = RT5670_DMIC_DATA_GPIO7;
2978 dev_info(&i2c->dev, "quirk DMIC1 on GPIO7 pin\n");
2979 }
2980 if (rt5670_quirk & RT5670_DMIC2_INR) {
2981 rt5670->pdata.dmic2_data_pin = RT5670_DMIC_DATA_IN3N;
2982 dev_info(&i2c->dev, "quirk DMIC2 on INR pin\n");
2983 }
2984 if (rt5670_quirk & RT5670_DMIC2_GPIO8) {
2985 rt5670->pdata.dmic2_data_pin = RT5670_DMIC_DATA_GPIO8;
2986 dev_info(&i2c->dev, "quirk DMIC2 on GPIO8 pin\n");
2987 }
2988 if (rt5670_quirk & RT5670_DMIC3_GPIO5) {
2989 rt5670->pdata.dmic3_data_pin = RT5670_DMIC_DATA_GPIO5;
2990 dev_info(&i2c->dev, "quirk DMIC3 on GPIO5 pin\n");
2991 }
2992
2993 if (rt5670_quirk & RT5670_JD_MODE1) {
2994 rt5670->pdata.jd_mode = 1;
2995 dev_info(&i2c->dev, "quirk JD mode 1\n");
2996 }
2997 if (rt5670_quirk & RT5670_JD_MODE2) {
2893 rt5670->pdata.jd_mode = 2; 2998 rt5670->pdata.jd_mode = 2;
2894 } else if (dmi_check_system(dmi_platform_intel_bytcht_jdmode3)) { 2999 dev_info(&i2c->dev, "quirk JD mode 2\n");
2895 rt5670->pdata.dmic_en = true; 3000 }
2896 rt5670->pdata.dmic1_data_pin = RT5670_DMIC_DATA_IN2P; 3001 if (rt5670_quirk & RT5670_JD_MODE3) {
2897 rt5670->pdata.dev_gpio = true;
2898 rt5670->pdata.jd_mode = 3; 3002 rt5670->pdata.jd_mode = 3;
3003 dev_info(&i2c->dev, "quirk JD mode 3\n");
2899 } 3004 }
2900 3005
2901 rt5670->regmap = devm_regmap_init_i2c(i2c, &rt5670_regmap); 3006 rt5670->regmap = devm_regmap_init_i2c(i2c, &rt5670_regmap);
diff --git a/sound/soc/codecs/rt5670.h b/sound/soc/codecs/rt5670.h
index 5ba485cae4e6..265df80d504e 100644
--- a/sound/soc/codecs/rt5670.h
+++ b/sound/soc/codecs/rt5670.h
@@ -1816,6 +1816,10 @@
1816#define RT5670_ZCD_HP_DIS (0x0 << 15) 1816#define RT5670_ZCD_HP_DIS (0x0 << 15)
1817#define RT5670_ZCD_HP_EN (0x1 << 15) 1817#define RT5670_ZCD_HP_EN (0x1 << 15)
1818 1818
1819/* General Control 3 (0xfc) */
1820#define RT5670_TDM_DATA_MODE_SEL (0x1 << 11)
1821#define RT5670_TDM_DATA_MODE_NOR (0x0 << 11)
1822#define RT5670_TDM_DATA_MODE_50FS (0x1 << 11)
1819 1823
1820/* Codec Private Register definition */ 1824/* Codec Private Register definition */
1821/* 3D Speaker Control (0x63) */ 1825/* 3D Speaker Control (0x63) */
diff --git a/sound/soc/codecs/tas571x.c b/sound/soc/codecs/tas571x.c
index 810369f687d7..a09499977be4 100644
--- a/sound/soc/codecs/tas571x.c
+++ b/sound/soc/codecs/tas571x.c
@@ -697,7 +697,8 @@ static int tas571x_i2c_probe(struct i2c_client *client,
697 return PTR_ERR(priv->mclk); 697 return PTR_ERR(priv->mclk);
698 } 698 }
699 699
700 BUG_ON(priv->chip->num_supply_names > TAS571X_MAX_SUPPLIES); 700 if (WARN_ON(priv->chip->num_supply_names > TAS571X_MAX_SUPPLIES))
701 return -EINVAL;
701 for (i = 0; i < priv->chip->num_supply_names; i++) 702 for (i = 0; i < priv->chip->num_supply_names; i++)
702 priv->supplies[i].supply = priv->chip->supply_names[i]; 703 priv->supplies[i].supply = priv->chip->supply_names[i];
703 704
diff --git a/sound/soc/codecs/tfa9879.c b/sound/soc/codecs/tfa9879.c
index 95e0a7abeb7a..f8dd67ca0744 100644
--- a/sound/soc/codecs/tfa9879.c
+++ b/sound/soc/codecs/tfa9879.c
@@ -312,9 +312,15 @@ static const struct i2c_device_id tfa9879_i2c_id[] = {
312}; 312};
313MODULE_DEVICE_TABLE(i2c, tfa9879_i2c_id); 313MODULE_DEVICE_TABLE(i2c, tfa9879_i2c_id);
314 314
315static const struct of_device_id tfa9879_of_match[] = {
316 { .compatible = "nxp,tfa9879", },
317 { }
318};
319
315static struct i2c_driver tfa9879_i2c_driver = { 320static struct i2c_driver tfa9879_i2c_driver = {
316 .driver = { 321 .driver = {
317 .name = "tfa9879", 322 .name = "tfa9879",
323 .of_match_table = tfa9879_of_match,
318 }, 324 },
319 .probe = tfa9879_i2c_probe, 325 .probe = tfa9879_i2c_probe,
320 .remove = tfa9879_i2c_remove, 326 .remove = tfa9879_i2c_remove,
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c
index 3d42138a7974..74909211c608 100644
--- a/sound/soc/codecs/tlv320aic23.c
+++ b/sound/soc/codecs/tlv320aic23.c
@@ -454,6 +454,7 @@ static int tlv320aic23_set_dai_fmt(struct snd_soc_dai *codec_dai,
454 break; 454 break;
455 case SND_SOC_DAIFMT_DSP_A: 455 case SND_SOC_DAIFMT_DSP_A:
456 iface_reg |= TLV320AIC23_LRP_ON; 456 iface_reg |= TLV320AIC23_LRP_ON;
457 /* fall through */
457 case SND_SOC_DAIFMT_DSP_B: 458 case SND_SOC_DAIFMT_DSP_B:
458 iface_reg |= TLV320AIC23_FOR_DSP; 459 iface_reg |= TLV320AIC23_FOR_DSP;
459 break; 460 break;
diff --git a/sound/soc/codecs/tlv320aic31xx.c b/sound/soc/codecs/tlv320aic31xx.c
index 54a87a905eb6..e2862372c26e 100644
--- a/sound/soc/codecs/tlv320aic31xx.c
+++ b/sound/soc/codecs/tlv320aic31xx.c
@@ -929,7 +929,7 @@ static int aic31xx_set_dai_fmt(struct snd_soc_dai *codec_dai,
929 case SND_SOC_DAIFMT_I2S: 929 case SND_SOC_DAIFMT_I2S:
930 break; 930 break;
931 case SND_SOC_DAIFMT_DSP_A: 931 case SND_SOC_DAIFMT_DSP_A:
932 dsp_a_val = 0x1; 932 dsp_a_val = 0x1; /* fall through */
933 case SND_SOC_DAIFMT_DSP_B: 933 case SND_SOC_DAIFMT_DSP_B:
934 /* NOTE: BCLKINV bit value 1 equas NB and 0 equals IB */ 934 /* NOTE: BCLKINV bit value 1 equas NB and 0 equals IB */
935 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 935 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c
index 2e014c80d113..616cd4bebd01 100644
--- a/sound/soc/codecs/tpa6130a2.c
+++ b/sound/soc/codecs/tpa6130a2.c
@@ -274,6 +274,7 @@ static int tpa6130a2_probe(struct i2c_client *client,
274 default: 274 default:
275 dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n", 275 dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n",
276 data->id); 276 data->id);
277 /* fall through */
277 case TPA6130A2: 278 case TPA6130A2:
278 regulator = "Vdd"; 279 regulator = "Vdd";
279 break; 280 break;
diff --git a/sound/soc/codecs/ts3a227e.c b/sound/soc/codecs/ts3a227e.c
index 43568435c208..738e04b09116 100644
--- a/sound/soc/codecs/ts3a227e.c
+++ b/sound/soc/codecs/ts3a227e.c
@@ -15,6 +15,7 @@
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/of_gpio.h> 16#include <linux/of_gpio.h>
17#include <linux/regmap.h> 17#include <linux/regmap.h>
18#include <linux/acpi.h>
18 19
19#include <sound/core.h> 20#include <sound/core.h>
20#include <sound/jack.h> 21#include <sound/jack.h>
@@ -374,11 +375,20 @@ static const struct of_device_id ts3a227e_of_match[] = {
374}; 375};
375MODULE_DEVICE_TABLE(of, ts3a227e_of_match); 376MODULE_DEVICE_TABLE(of, ts3a227e_of_match);
376 377
378#ifdef CONFIG_ACPI
379static struct acpi_device_id ts3a227e_acpi_match[] = {
380 { "104C227E", 0 },
381 {},
382};
383MODULE_DEVICE_TABLE(acpi, ts3a227e_acpi_match);
384#endif
385
377static struct i2c_driver ts3a227e_driver = { 386static struct i2c_driver ts3a227e_driver = {
378 .driver = { 387 .driver = {
379 .name = "ts3a227e", 388 .name = "ts3a227e",
380 .pm = &ts3a227e_pm, 389 .pm = &ts3a227e_pm,
381 .of_match_table = of_match_ptr(ts3a227e_of_match), 390 .of_match_table = of_match_ptr(ts3a227e_of_match),
391 .acpi_match_table = ACPI_PTR(ts3a227e_acpi_match),
382 }, 392 },
383 .probe = ts3a227e_i2c_probe, 393 .probe = ts3a227e_i2c_probe,
384 .id_table = ts3a227e_i2c_ids, 394 .id_table = ts3a227e_i2c_ids,
diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
index 72486bf072f2..4f0481d3c7a7 100644
--- a/sound/soc/codecs/wm5102.c
+++ b/sound/soc/codecs/wm5102.c
@@ -1951,7 +1951,6 @@ static int wm5102_codec_probe(struct snd_soc_codec *codec)
1951 return ret; 1951 return ret;
1952 1952
1953 arizona_init_gpio(codec); 1953 arizona_init_gpio(codec);
1954 arizona_init_notifiers(codec);
1955 1954
1956 snd_soc_component_disable_pin(component, "HAPTICS"); 1955 snd_soc_component_disable_pin(component, "HAPTICS");
1957 1956
@@ -2043,6 +2042,14 @@ static int wm5102_probe(struct platform_device *pdev)
2043 return -ENOMEM; 2042 return -ENOMEM;
2044 platform_set_drvdata(pdev, wm5102); 2043 platform_set_drvdata(pdev, wm5102);
2045 2044
2045 if (IS_ENABLED(CONFIG_OF)) {
2046 if (!dev_get_platdata(arizona->dev)) {
2047 ret = arizona_of_get_audio_pdata(arizona);
2048 if (ret < 0)
2049 return ret;
2050 }
2051 }
2052
2046 mutex_init(&arizona->dac_comp_lock); 2053 mutex_init(&arizona->dac_comp_lock);
2047 2054
2048 wm5102->core.arizona = arizona; 2055 wm5102->core.arizona = arizona;
@@ -2098,6 +2105,11 @@ static int wm5102_probe(struct platform_device *pdev)
2098 return ret; 2105 return ret;
2099 } 2106 }
2100 2107
2108 arizona_init_common(arizona);
2109
2110 ret = arizona_init_vol_limit(arizona);
2111 if (ret < 0)
2112 goto err_dsp_irq;
2101 ret = arizona_init_spk_irqs(arizona); 2113 ret = arizona_init_spk_irqs(arizona);
2102 if (ret < 0) 2114 if (ret < 0)
2103 goto err_dsp_irq; 2115 goto err_dsp_irq;
diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c
index 858a24fc28e8..6ed1e1f9ce51 100644
--- a/sound/soc/codecs/wm5110.c
+++ b/sound/soc/codecs/wm5110.c
@@ -2290,7 +2290,6 @@ static int wm5110_codec_probe(struct snd_soc_codec *codec)
2290 2290
2291 arizona_init_gpio(codec); 2291 arizona_init_gpio(codec);
2292 arizona_init_mono(codec); 2292 arizona_init_mono(codec);
2293 arizona_init_notifiers(codec);
2294 2293
2295 for (i = 0; i < WM5110_NUM_ADSP; ++i) { 2294 for (i = 0; i < WM5110_NUM_ADSP; ++i) {
2296 ret = wm_adsp2_codec_probe(&priv->core.adsp[i], codec); 2295 ret = wm_adsp2_codec_probe(&priv->core.adsp[i], codec);
@@ -2398,6 +2397,14 @@ static int wm5110_probe(struct platform_device *pdev)
2398 return -ENOMEM; 2397 return -ENOMEM;
2399 platform_set_drvdata(pdev, wm5110); 2398 platform_set_drvdata(pdev, wm5110);
2400 2399
2400 if (IS_ENABLED(CONFIG_OF)) {
2401 if (!dev_get_platdata(arizona->dev)) {
2402 ret = arizona_of_get_audio_pdata(arizona);
2403 if (ret < 0)
2404 return ret;
2405 }
2406 }
2407
2401 wm5110->core.arizona = arizona; 2408 wm5110->core.arizona = arizona;
2402 wm5110->core.num_inputs = 8; 2409 wm5110->core.num_inputs = 8;
2403 2410
@@ -2454,6 +2461,11 @@ static int wm5110_probe(struct platform_device *pdev)
2454 return ret; 2461 return ret;
2455 } 2462 }
2456 2463
2464 arizona_init_common(arizona);
2465
2466 ret = arizona_init_vol_limit(arizona);
2467 if (ret < 0)
2468 goto err_dsp_irq;
2457 ret = arizona_init_spk_irqs(arizona); 2469 ret = arizona_init_spk_irqs(arizona);
2458 if (ret < 0) 2470 if (ret < 0)
2459 goto err_dsp_irq; 2471 goto err_dsp_irq;
diff --git a/sound/soc/codecs/wm8741.c b/sound/soc/codecs/wm8741.c
index b8c1940f2243..a394dbee77aa 100644
--- a/sound/soc/codecs/wm8741.c
+++ b/sound/soc/codecs/wm8741.c
@@ -196,7 +196,7 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream,
196{ 196{
197 struct snd_soc_codec *codec = dai->codec; 197 struct snd_soc_codec *codec = dai->codec;
198 struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec); 198 struct wm8741_priv *wm8741 = snd_soc_codec_get_drvdata(codec);
199 u16 iface = snd_soc_read(codec, WM8741_FORMAT_CONTROL) & 0x1FC; 199 unsigned int iface;
200 int i; 200 int i;
201 201
202 /* The set of sample rates that can be supported depends on the 202 /* The set of sample rates that can be supported depends on the
@@ -223,15 +223,16 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream,
223 /* bit size */ 223 /* bit size */
224 switch (params_width(params)) { 224 switch (params_width(params)) {
225 case 16: 225 case 16:
226 iface = 0x0;
226 break; 227 break;
227 case 20: 228 case 20:
228 iface |= 0x0001; 229 iface = 0x1;
229 break; 230 break;
230 case 24: 231 case 24:
231 iface |= 0x0002; 232 iface = 0x2;
232 break; 233 break;
233 case 32: 234 case 32:
234 iface |= 0x0003; 235 iface = 0x3;
235 break; 236 break;
236 default: 237 default:
237 dev_dbg(codec->dev, "wm8741_hw_params: Unsupported bit size param = %d", 238 dev_dbg(codec->dev, "wm8741_hw_params: Unsupported bit size param = %d",
@@ -242,7 +243,9 @@ static int wm8741_hw_params(struct snd_pcm_substream *substream,
242 dev_dbg(codec->dev, "wm8741_hw_params: bit size param = %d, rate param = %d", 243 dev_dbg(codec->dev, "wm8741_hw_params: bit size param = %d, rate param = %d",
243 params_width(params), params_rate(params)); 244 params_width(params), params_rate(params));
244 245
245 snd_soc_write(codec, WM8741_FORMAT_CONTROL, iface); 246 snd_soc_update_bits(codec, WM8741_FORMAT_CONTROL, WM8741_IWL_MASK,
247 iface);
248
246 return 0; 249 return 0;
247} 250}
248 251
@@ -295,7 +298,7 @@ static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai,
295 unsigned int fmt) 298 unsigned int fmt)
296{ 299{
297 struct snd_soc_codec *codec = codec_dai->codec; 300 struct snd_soc_codec *codec = codec_dai->codec;
298 u16 iface = snd_soc_read(codec, WM8741_FORMAT_CONTROL) & 0x1C3; 301 unsigned int iface;
299 302
300 /* check master/slave audio interface */ 303 /* check master/slave audio interface */
301 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 304 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
@@ -308,18 +311,19 @@ static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai,
308 /* interface format */ 311 /* interface format */
309 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 312 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
310 case SND_SOC_DAIFMT_I2S: 313 case SND_SOC_DAIFMT_I2S:
311 iface |= 0x0008; 314 iface = 0x08;
312 break; 315 break;
313 case SND_SOC_DAIFMT_RIGHT_J: 316 case SND_SOC_DAIFMT_RIGHT_J:
317 iface = 0x00;
314 break; 318 break;
315 case SND_SOC_DAIFMT_LEFT_J: 319 case SND_SOC_DAIFMT_LEFT_J:
316 iface |= 0x0004; 320 iface = 0x04;
317 break; 321 break;
318 case SND_SOC_DAIFMT_DSP_A: 322 case SND_SOC_DAIFMT_DSP_A:
319 iface |= 0x000C; 323 iface = 0x0C;
320 break; 324 break;
321 case SND_SOC_DAIFMT_DSP_B: 325 case SND_SOC_DAIFMT_DSP_B:
322 iface |= 0x001C; 326 iface = 0x1C;
323 break; 327 break;
324 default: 328 default:
325 return -EINVAL; 329 return -EINVAL;
@@ -329,14 +333,14 @@ static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai,
329 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 333 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
330 case SND_SOC_DAIFMT_NB_NF: 334 case SND_SOC_DAIFMT_NB_NF:
331 break; 335 break;
332 case SND_SOC_DAIFMT_IB_IF: 336 case SND_SOC_DAIFMT_NB_IF:
333 iface |= 0x0010; 337 iface |= 0x10;
334 break; 338 break;
335 case SND_SOC_DAIFMT_IB_NF: 339 case SND_SOC_DAIFMT_IB_NF:
336 iface |= 0x0020; 340 iface |= 0x20;
337 break; 341 break;
338 case SND_SOC_DAIFMT_NB_IF: 342 case SND_SOC_DAIFMT_IB_IF:
339 iface |= 0x0030; 343 iface |= 0x30;
340 break; 344 break;
341 default: 345 default:
342 return -EINVAL; 346 return -EINVAL;
@@ -347,7 +351,10 @@ static int wm8741_set_dai_fmt(struct snd_soc_dai *codec_dai,
347 fmt & SND_SOC_DAIFMT_FORMAT_MASK, 351 fmt & SND_SOC_DAIFMT_FORMAT_MASK,
348 ((fmt & SND_SOC_DAIFMT_INV_MASK))); 352 ((fmt & SND_SOC_DAIFMT_INV_MASK)));
349 353
350 snd_soc_write(codec, WM8741_FORMAT_CONTROL, iface); 354 snd_soc_update_bits(codec, WM8741_FORMAT_CONTROL,
355 WM8741_BCP_MASK | WM8741_LRP_MASK | WM8741_FMT_MASK,
356 iface);
357
351 return 0; 358 return 0;
352} 359}
353 360
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index d05d76e79c70..0271a5253bd3 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -971,7 +971,7 @@ static int wm8753_pcm_set_dai_fmt(struct snd_soc_codec *codec,
971 case SND_SOC_DAIFMT_CBS_CFS: 971 case SND_SOC_DAIFMT_CBS_CFS:
972 break; 972 break;
973 case SND_SOC_DAIFMT_CBM_CFM: 973 case SND_SOC_DAIFMT_CBM_CFM:
974 ioctl |= 0x2; 974 ioctl |= 0x2; /* fall through */
975 case SND_SOC_DAIFMT_CBM_CFS: 975 case SND_SOC_DAIFMT_CBM_CFS:
976 voice |= 0x0040; 976 voice |= 0x0040;
977 break; 977 break;
@@ -1096,7 +1096,7 @@ static int wm8753_i2s_set_dai_fmt(struct snd_soc_codec *codec,
1096 case SND_SOC_DAIFMT_CBS_CFS: 1096 case SND_SOC_DAIFMT_CBS_CFS:
1097 break; 1097 break;
1098 case SND_SOC_DAIFMT_CBM_CFM: 1098 case SND_SOC_DAIFMT_CBM_CFM:
1099 ioctl |= 0x1; 1099 ioctl |= 0x1; /* fall through */
1100 case SND_SOC_DAIFMT_CBM_CFS: 1100 case SND_SOC_DAIFMT_CBM_CFS:
1101 hifi |= 0x0040; 1101 hifi |= 0x0040;
1102 break; 1102 break;
diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c
index 195f7bf6eb22..830ffd80de4a 100644
--- a/sound/soc/codecs/wm8993.c
+++ b/sound/soc/codecs/wm8993.c
@@ -1076,6 +1076,7 @@ static int wm8993_set_sysclk(struct snd_soc_dai *codec_dai,
1076 switch (clk_id) { 1076 switch (clk_id) {
1077 case WM8993_SYSCLK_MCLK: 1077 case WM8993_SYSCLK_MCLK:
1078 wm8993->mclk_rate = freq; 1078 wm8993->mclk_rate = freq;
1079 /* fall through */
1079 case WM8993_SYSCLK_FLL: 1080 case WM8993_SYSCLK_FLL:
1080 wm8993->sysclk_source = clk_id; 1081 wm8993->sysclk_source = clk_id;
1081 break; 1082 break;
@@ -1123,6 +1124,7 @@ static int wm8993_set_dai_fmt(struct snd_soc_dai *dai,
1123 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 1124 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1124 case SND_SOC_DAIFMT_DSP_B: 1125 case SND_SOC_DAIFMT_DSP_B:
1125 aif1 |= WM8993_AIF_LRCLK_INV; 1126 aif1 |= WM8993_AIF_LRCLK_INV;
1127 /* fall through */
1126 case SND_SOC_DAIFMT_DSP_A: 1128 case SND_SOC_DAIFMT_DSP_A:
1127 aif1 |= 0x18; 1129 aif1 |= 0x18;
1128 break; 1130 break;
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index 3896523b71e9..f91b49e1ece3 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -860,6 +860,7 @@ static void vmid_reference(struct snd_soc_codec *codec)
860 switch (wm8994->vmid_mode) { 860 switch (wm8994->vmid_mode) {
861 default: 861 default:
862 WARN_ON(NULL == "Invalid VMID mode"); 862 WARN_ON(NULL == "Invalid VMID mode");
863 /* fall through */
863 case WM8994_VMID_NORMAL: 864 case WM8994_VMID_NORMAL:
864 /* Startup bias, VMID ramp & buffer */ 865 /* Startup bias, VMID ramp & buffer */
865 snd_soc_update_bits(codec, WM8994_ANTIPOP_2, 866 snd_soc_update_bits(codec, WM8994_ANTIPOP_2,
@@ -2654,6 +2655,7 @@ static int wm8994_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2654 case SND_SOC_DAIFMT_DSP_B: 2655 case SND_SOC_DAIFMT_DSP_B:
2655 aif1 |= WM8994_AIF1_LRCLK_INV; 2656 aif1 |= WM8994_AIF1_LRCLK_INV;
2656 lrclk |= WM8958_AIF1_LRCLK_INV; 2657 lrclk |= WM8958_AIF1_LRCLK_INV;
2658 /* fall through */
2657 case SND_SOC_DAIFMT_DSP_A: 2659 case SND_SOC_DAIFMT_DSP_A:
2658 aif1 |= 0x18; 2660 aif1 |= 0x18;
2659 break; 2661 break;
diff --git a/sound/soc/codecs/wm8997.c b/sound/soc/codecs/wm8997.c
index 49401a8aae64..77f512767273 100644
--- a/sound/soc/codecs/wm8997.c
+++ b/sound/soc/codecs/wm8997.c
@@ -1068,8 +1068,6 @@ static int wm8997_codec_probe(struct snd_soc_codec *codec)
1068 if (ret < 0) 1068 if (ret < 0)
1069 return ret; 1069 return ret;
1070 1070
1071 arizona_init_notifiers(codec);
1072
1073 snd_soc_component_disable_pin(component, "HAPTICS"); 1071 snd_soc_component_disable_pin(component, "HAPTICS");
1074 1072
1075 priv->core.arizona->dapm = dapm; 1073 priv->core.arizona->dapm = dapm;
@@ -1136,6 +1134,14 @@ static int wm8997_probe(struct platform_device *pdev)
1136 return -ENOMEM; 1134 return -ENOMEM;
1137 platform_set_drvdata(pdev, wm8997); 1135 platform_set_drvdata(pdev, wm8997);
1138 1136
1137 if (IS_ENABLED(CONFIG_OF)) {
1138 if (!dev_get_platdata(arizona->dev)) {
1139 ret = arizona_of_get_audio_pdata(arizona);
1140 if (ret < 0)
1141 return ret;
1142 }
1143 }
1144
1139 wm8997->core.arizona = arizona; 1145 wm8997->core.arizona = arizona;
1140 wm8997->core.num_inputs = 4; 1146 wm8997->core.num_inputs = 4;
1141 1147
@@ -1168,6 +1174,11 @@ static int wm8997_probe(struct platform_device *pdev)
1168 pm_runtime_enable(&pdev->dev); 1174 pm_runtime_enable(&pdev->dev);
1169 pm_runtime_idle(&pdev->dev); 1175 pm_runtime_idle(&pdev->dev);
1170 1176
1177 arizona_init_common(arizona);
1178
1179 ret = arizona_init_vol_limit(arizona);
1180 if (ret < 0)
1181 return ret;
1171 ret = arizona_init_spk_irqs(arizona); 1182 ret = arizona_init_spk_irqs(arizona);
1172 if (ret < 0) 1183 if (ret < 0)
1173 return ret; 1184 return ret;
diff --git a/sound/soc/codecs/wm8998.c b/sound/soc/codecs/wm8998.c
index 44f447136e22..2d211dbe7422 100644
--- a/sound/soc/codecs/wm8998.c
+++ b/sound/soc/codecs/wm8998.c
@@ -101,7 +101,7 @@ static int wm8998_asrc_ev(struct snd_soc_dapm_widget *w,
101 return 0; 101 return 0;
102} 102}
103 103
104static int wm8998_in1mux_put(struct snd_kcontrol *kcontrol, 104static int wm8998_inmux_put(struct snd_kcontrol *kcontrol,
105 struct snd_ctl_elem_value *ucontrol) 105 struct snd_ctl_elem_value *ucontrol)
106{ 106{
107 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); 107 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol);
@@ -109,84 +109,38 @@ static int wm8998_in1mux_put(struct snd_kcontrol *kcontrol,
109 struct wm8998_priv *wm8998 = snd_soc_codec_get_drvdata(codec); 109 struct wm8998_priv *wm8998 = snd_soc_codec_get_drvdata(codec);
110 struct arizona *arizona = wm8998->core.arizona; 110 struct arizona *arizona = wm8998->core.arizona;
111 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; 111 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
112 unsigned int mux, inmode; 112 unsigned int mode_reg, mode_index;
113 unsigned int mode_val, src_val; 113 unsigned int mux, inmode, src_val, mode_val;
114 114
115 mux = ucontrol->value.enumerated.item[0]; 115 mux = ucontrol->value.enumerated.item[0];
116 if (mux > 1) 116 if (mux > 1)
117 return -EINVAL; 117 return -EINVAL;
118 118
119 /* L and R registers have same shift and mask */ 119 switch (e->reg) {
120 inmode = arizona->pdata.inmode[2 * mux]; 120 case ARIZONA_ADC_DIGITAL_VOLUME_2L:
121 src_val = mux << ARIZONA_IN1L_SRC_SHIFT; 121 mode_reg = ARIZONA_IN2L_CONTROL;
122 if (inmode & ARIZONA_INMODE_SE) 122 mode_index = 1 + (2 * mux);
123 src_val |= 1 << ARIZONA_IN1L_SRC_SE_SHIFT;
124
125 switch (arizona->pdata.inmode[0]) {
126 case ARIZONA_INMODE_DMIC:
127 if (mux)
128 mode_val = 0; /* B always analogue */
129 else
130 mode_val = 1 << ARIZONA_IN1_MODE_SHIFT;
131
132 snd_soc_update_bits(codec, ARIZONA_IN1L_CONTROL,
133 ARIZONA_IN1_MODE_MASK, mode_val);
134
135 /* IN1A is digital so L and R must change together */
136 /* src_val setting same for both registers */
137 snd_soc_update_bits(codec,
138 ARIZONA_ADC_DIGITAL_VOLUME_1L,
139 ARIZONA_IN1L_SRC_MASK |
140 ARIZONA_IN1L_SRC_SE_MASK, src_val);
141 snd_soc_update_bits(codec,
142 ARIZONA_ADC_DIGITAL_VOLUME_1R,
143 ARIZONA_IN1R_SRC_MASK |
144 ARIZONA_IN1R_SRC_SE_MASK, src_val);
145 break; 123 break;
146 default: 124 default:
147 /* both analogue */ 125 mode_reg = ARIZONA_IN1L_CONTROL;
148 snd_soc_update_bits(codec, 126 mode_index = (2 * mux);
149 e->reg,
150 ARIZONA_IN1L_SRC_MASK |
151 ARIZONA_IN1L_SRC_SE_MASK,
152 src_val);
153 break; 127 break;
154 } 128 }
155 129
156 return snd_soc_dapm_mux_update_power(dapm, kcontrol, 130 inmode = arizona->pdata.inmode[mode_index];
157 ucontrol->value.enumerated.item[0],
158 e, NULL);
159}
160
161static int wm8998_in2mux_put(struct snd_kcontrol *kcontrol,
162 struct snd_ctl_elem_value *ucontrol)
163{
164 struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol);
165 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
166 struct wm8998_priv *wm8998 = snd_soc_codec_get_drvdata(codec);
167 struct arizona *arizona = wm8998->core.arizona;
168 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
169 unsigned int mux, inmode, src_val, mode_val;
170
171 mux = ucontrol->value.enumerated.item[0];
172 if (mux > 1)
173 return -EINVAL;
174
175 inmode = arizona->pdata.inmode[1 + (2 * mux)];
176 if (inmode & ARIZONA_INMODE_DMIC) 131 if (inmode & ARIZONA_INMODE_DMIC)
177 mode_val = 1 << ARIZONA_IN2_MODE_SHIFT; 132 mode_val = 1 << ARIZONA_IN1_MODE_SHIFT;
178 else 133 else
179 mode_val = 0; 134 mode_val = 0;
180 135
181 src_val = mux << ARIZONA_IN2L_SRC_SHIFT; 136 src_val = mux << ARIZONA_IN1L_SRC_SHIFT;
182 if (inmode & ARIZONA_INMODE_SE) 137 if (inmode & ARIZONA_INMODE_SE)
183 src_val |= 1 << ARIZONA_IN2L_SRC_SE_SHIFT; 138 src_val |= 1 << ARIZONA_IN1L_SRC_SE_SHIFT;
184 139
185 snd_soc_update_bits(codec, ARIZONA_IN2L_CONTROL, 140 snd_soc_update_bits(codec, mode_reg, ARIZONA_IN1_MODE_MASK, mode_val);
186 ARIZONA_IN2_MODE_MASK, mode_val);
187 141
188 snd_soc_update_bits(codec, ARIZONA_ADC_DIGITAL_VOLUME_2L, 142 snd_soc_update_bits(codec, e->reg,
189 ARIZONA_IN2L_SRC_MASK | ARIZONA_IN2L_SRC_SE_MASK, 143 ARIZONA_IN1L_SRC_MASK | ARIZONA_IN1L_SRC_SE_MASK,
190 src_val); 144 src_val);
191 145
192 return snd_soc_dapm_mux_update_power(dapm, kcontrol, 146 return snd_soc_dapm_mux_update_power(dapm, kcontrol,
@@ -216,14 +170,14 @@ static SOC_ENUM_SINGLE_DECL(wm8998_in2mux_enum,
216 170
217static const struct snd_kcontrol_new wm8998_in1mux[2] = { 171static const struct snd_kcontrol_new wm8998_in1mux[2] = {
218 SOC_DAPM_ENUM_EXT("IN1L Mux", wm8998_in1muxl_enum, 172 SOC_DAPM_ENUM_EXT("IN1L Mux", wm8998_in1muxl_enum,
219 snd_soc_dapm_get_enum_double, wm8998_in1mux_put), 173 snd_soc_dapm_get_enum_double, wm8998_inmux_put),
220 SOC_DAPM_ENUM_EXT("IN1R Mux", wm8998_in1muxr_enum, 174 SOC_DAPM_ENUM_EXT("IN1R Mux", wm8998_in1muxr_enum,
221 snd_soc_dapm_get_enum_double, wm8998_in1mux_put), 175 snd_soc_dapm_get_enum_double, wm8998_inmux_put),
222}; 176};
223 177
224static const struct snd_kcontrol_new wm8998_in2mux = 178static const struct snd_kcontrol_new wm8998_in2mux =
225 SOC_DAPM_ENUM_EXT("IN2 Mux", wm8998_in2mux_enum, 179 SOC_DAPM_ENUM_EXT("IN2 Mux", wm8998_in2mux_enum,
226 snd_soc_dapm_get_enum_double, wm8998_in2mux_put); 180 snd_soc_dapm_get_enum_double, wm8998_inmux_put);
227 181
228static DECLARE_TLV_DB_SCALE(ana_tlv, 0, 100, 0); 182static DECLARE_TLV_DB_SCALE(ana_tlv, 0, 100, 0);
229static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0); 183static DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
@@ -1330,7 +1284,6 @@ static int wm8998_codec_probe(struct snd_soc_codec *codec)
1330 return ret; 1284 return ret;
1331 1285
1332 arizona_init_gpio(codec); 1286 arizona_init_gpio(codec);
1333 arizona_init_notifiers(codec);
1334 1287
1335 snd_soc_component_disable_pin(component, "HAPTICS"); 1288 snd_soc_component_disable_pin(component, "HAPTICS");
1336 1289
@@ -1399,6 +1352,14 @@ static int wm8998_probe(struct platform_device *pdev)
1399 return -ENOMEM; 1352 return -ENOMEM;
1400 platform_set_drvdata(pdev, wm8998); 1353 platform_set_drvdata(pdev, wm8998);
1401 1354
1355 if (IS_ENABLED(CONFIG_OF)) {
1356 if (!dev_get_platdata(arizona->dev)) {
1357 ret = arizona_of_get_audio_pdata(arizona);
1358 if (ret < 0)
1359 return ret;
1360 }
1361 }
1362
1402 wm8998->core.arizona = arizona; 1363 wm8998->core.arizona = arizona;
1403 wm8998->core.num_inputs = 3; /* IN1L, IN1R, IN2 */ 1364 wm8998->core.num_inputs = 3; /* IN1L, IN1R, IN2 */
1404 1365
@@ -1423,6 +1384,8 @@ static int wm8998_probe(struct platform_device *pdev)
1423 pm_runtime_enable(&pdev->dev); 1384 pm_runtime_enable(&pdev->dev);
1424 pm_runtime_idle(&pdev->dev); 1385 pm_runtime_idle(&pdev->dev);
1425 1386
1387 arizona_init_common(arizona);
1388
1426 ret = arizona_init_spk_irqs(arizona); 1389 ret = arizona_init_spk_irqs(arizona);
1427 if (ret < 0) 1390 if (ret < 0)
1428 return ret; 1391 return ret;
diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c
index f6d5c0f2aea5..2c09f71fe433 100644
--- a/sound/soc/codecs/wm9705.c
+++ b/sound/soc/codecs/wm9705.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/mfd/wm97xx.h>
14#include <linux/module.h> 15#include <linux/module.h>
15#include <linux/kernel.h> 16#include <linux/kernel.h>
16#include <linux/device.h> 17#include <linux/device.h>
@@ -18,12 +19,19 @@
18#include <sound/core.h> 19#include <sound/core.h>
19#include <sound/pcm.h> 20#include <sound/pcm.h>
20#include <sound/ac97_codec.h> 21#include <sound/ac97_codec.h>
22#include <sound/ac97/codec.h>
23#include <sound/ac97/compat.h>
21#include <sound/initval.h> 24#include <sound/initval.h>
22#include <sound/soc.h> 25#include <sound/soc.h>
23 26
24#define WM9705_VENDOR_ID 0x574d4c05 27#define WM9705_VENDOR_ID 0x574d4c05
25#define WM9705_VENDOR_ID_MASK 0xffffffff 28#define WM9705_VENDOR_ID_MASK 0xffffffff
26 29
30struct wm9705_priv {
31 struct snd_ac97 *ac97;
32 struct wm97xx_platform_data *mfd_pdata;
33};
34
27static const struct reg_default wm9705_reg_defaults[] = { 35static const struct reg_default wm9705_reg_defaults[] = {
28 { 0x02, 0x8000 }, 36 { 0x02, 0x8000 },
29 { 0x04, 0x8000 }, 37 { 0x04, 0x8000 },
@@ -292,10 +300,10 @@ static int wm9705_soc_suspend(struct snd_soc_codec *codec)
292 300
293static int wm9705_soc_resume(struct snd_soc_codec *codec) 301static int wm9705_soc_resume(struct snd_soc_codec *codec)
294{ 302{
295 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec); 303 struct wm9705_priv *wm9705 = snd_soc_codec_get_drvdata(codec);
296 int ret; 304 int ret;
297 305
298 ret = snd_ac97_reset(ac97, true, WM9705_VENDOR_ID, 306 ret = snd_ac97_reset(wm9705->ac97, true, WM9705_VENDOR_ID,
299 WM9705_VENDOR_ID_MASK); 307 WM9705_VENDOR_ID_MASK);
300 if (ret < 0) 308 if (ret < 0)
301 return ret; 309 return ret;
@@ -311,38 +319,45 @@ static int wm9705_soc_resume(struct snd_soc_codec *codec)
311 319
312static int wm9705_soc_probe(struct snd_soc_codec *codec) 320static int wm9705_soc_probe(struct snd_soc_codec *codec)
313{ 321{
314 struct snd_ac97 *ac97; 322 struct wm9705_priv *wm9705 = snd_soc_codec_get_drvdata(codec);
315 struct regmap *regmap; 323 struct regmap *regmap;
316 int ret;
317
318 ac97 = snd_soc_new_ac97_codec(codec, WM9705_VENDOR_ID,
319 WM9705_VENDOR_ID_MASK);
320 if (IS_ERR(ac97)) {
321 dev_err(codec->dev, "Failed to register AC97 codec\n");
322 return PTR_ERR(ac97);
323 }
324 324
325 regmap = regmap_init_ac97(ac97, &wm9705_regmap_config); 325 if (wm9705->mfd_pdata) {
326 if (IS_ERR(regmap)) { 326 wm9705->ac97 = wm9705->mfd_pdata->ac97;
327 ret = PTR_ERR(regmap); 327 regmap = wm9705->mfd_pdata->regmap;
328 goto err_free_ac97_codec; 328 } else {
329#ifdef CONFIG_SND_SOC_AC97_BUS
330 wm9705->ac97 = snd_soc_new_ac97_codec(codec, WM9705_VENDOR_ID,
331 WM9705_VENDOR_ID_MASK);
332 if (IS_ERR(wm9705->ac97)) {
333 dev_err(codec->dev, "Failed to register AC97 codec\n");
334 return PTR_ERR(wm9705->ac97);
335 }
336
337 regmap = regmap_init_ac97(wm9705->ac97, &wm9705_regmap_config);
338 if (IS_ERR(regmap)) {
339 snd_soc_free_ac97_codec(wm9705->ac97);
340 return PTR_ERR(regmap);
341 }
342#endif
329 } 343 }
330 344
331 snd_soc_codec_set_drvdata(codec, ac97); 345 snd_soc_codec_set_drvdata(codec, wm9705->ac97);
332 snd_soc_codec_init_regmap(codec, regmap); 346 snd_soc_codec_init_regmap(codec, regmap);
333 347
334 return 0; 348 return 0;
335err_free_ac97_codec:
336 snd_soc_free_ac97_codec(ac97);
337 return ret;
338} 349}
339 350
340static int wm9705_soc_remove(struct snd_soc_codec *codec) 351static int wm9705_soc_remove(struct snd_soc_codec *codec)
341{ 352{
342 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec); 353#ifdef CONFIG_SND_SOC_AC97_BUS
354 struct wm9705_priv *wm9705 = snd_soc_codec_get_drvdata(codec);
343 355
344 snd_soc_codec_exit_regmap(codec); 356 if (!wm9705->mfd_pdata) {
345 snd_soc_free_ac97_codec(ac97); 357 snd_soc_codec_exit_regmap(codec);
358 snd_soc_free_ac97_codec(wm9705->ac97);
359 }
360#endif
346 return 0; 361 return 0;
347} 362}
348 363
@@ -364,6 +379,15 @@ static const struct snd_soc_codec_driver soc_codec_dev_wm9705 = {
364 379
365static int wm9705_probe(struct platform_device *pdev) 380static int wm9705_probe(struct platform_device *pdev)
366{ 381{
382 struct wm9705_priv *wm9705;
383
384 wm9705 = devm_kzalloc(&pdev->dev, sizeof(*wm9705), GFP_KERNEL);
385 if (wm9705 == NULL)
386 return -ENOMEM;
387
388 wm9705->mfd_pdata = dev_get_platdata(&pdev->dev);
389 platform_set_drvdata(pdev, wm9705);
390
367 return snd_soc_register_codec(&pdev->dev, 391 return snd_soc_register_codec(&pdev->dev,
368 &soc_codec_dev_wm9705, wm9705_dai, ARRAY_SIZE(wm9705_dai)); 392 &soc_codec_dev_wm9705, wm9705_dai, ARRAY_SIZE(wm9705_dai));
369} 393}
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
index 1a3e1797994a..4f6d1a442bc4 100644
--- a/sound/soc/codecs/wm9712.c
+++ b/sound/soc/codecs/wm9712.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/mfd/wm97xx.h>
15#include <linux/module.h> 16#include <linux/module.h>
16#include <linux/kernel.h> 17#include <linux/kernel.h>
17#include <linux/device.h> 18#include <linux/device.h>
@@ -19,6 +20,8 @@
19#include <sound/core.h> 20#include <sound/core.h>
20#include <sound/pcm.h> 21#include <sound/pcm.h>
21#include <sound/ac97_codec.h> 22#include <sound/ac97_codec.h>
23#include <sound/ac97/codec.h>
24#include <sound/ac97/compat.h>
22#include <sound/initval.h> 25#include <sound/initval.h>
23#include <sound/soc.h> 26#include <sound/soc.h>
24#include <sound/tlv.h> 27#include <sound/tlv.h>
@@ -30,6 +33,7 @@ struct wm9712_priv {
30 struct snd_ac97 *ac97; 33 struct snd_ac97 *ac97;
31 unsigned int hp_mixer[2]; 34 unsigned int hp_mixer[2];
32 struct mutex lock; 35 struct mutex lock;
36 struct wm97xx_platform_data *mfd_pdata;
33}; 37};
34 38
35static const struct reg_default wm9712_reg_defaults[] = { 39static const struct reg_default wm9712_reg_defaults[] = {
@@ -636,18 +640,26 @@ static int wm9712_soc_probe(struct snd_soc_codec *codec)
636 struct regmap *regmap; 640 struct regmap *regmap;
637 int ret; 641 int ret;
638 642
639 wm9712->ac97 = snd_soc_new_ac97_codec(codec, WM9712_VENDOR_ID, 643 if (wm9712->mfd_pdata) {
640 WM9712_VENDOR_ID_MASK); 644 wm9712->ac97 = wm9712->mfd_pdata->ac97;
641 if (IS_ERR(wm9712->ac97)) { 645 regmap = wm9712->mfd_pdata->regmap;
642 ret = PTR_ERR(wm9712->ac97); 646 } else {
643 dev_err(codec->dev, "Failed to register AC97 codec: %d\n", ret); 647#ifdef CONFIG_SND_SOC_AC97_BUS
644 return ret; 648 wm9712->ac97 = snd_soc_new_ac97_codec(codec, WM9712_VENDOR_ID,
645 } 649 WM9712_VENDOR_ID_MASK);
646 650 if (IS_ERR(wm9712->ac97)) {
647 regmap = regmap_init_ac97(wm9712->ac97, &wm9712_regmap_config); 651 ret = PTR_ERR(wm9712->ac97);
648 if (IS_ERR(regmap)) { 652 dev_err(codec->dev,
649 ret = PTR_ERR(regmap); 653 "Failed to register AC97 codec: %d\n", ret);
650 goto err_free_ac97_codec; 654 return ret;
655 }
656
657 regmap = regmap_init_ac97(wm9712->ac97, &wm9712_regmap_config);
658 if (IS_ERR(regmap)) {
659 snd_soc_free_ac97_codec(wm9712->ac97);
660 return PTR_ERR(regmap);
661 }
662#endif
651 } 663 }
652 664
653 snd_soc_codec_init_regmap(codec, regmap); 665 snd_soc_codec_init_regmap(codec, regmap);
@@ -656,17 +668,18 @@ static int wm9712_soc_probe(struct snd_soc_codec *codec)
656 snd_soc_update_bits(codec, AC97_VIDEO, 0x3000, 0x3000); 668 snd_soc_update_bits(codec, AC97_VIDEO, 0x3000, 0x3000);
657 669
658 return 0; 670 return 0;
659err_free_ac97_codec:
660 snd_soc_free_ac97_codec(wm9712->ac97);
661 return ret;
662} 671}
663 672
664static int wm9712_soc_remove(struct snd_soc_codec *codec) 673static int wm9712_soc_remove(struct snd_soc_codec *codec)
665{ 674{
675#ifdef CONFIG_SND_SOC_AC97_BUS
666 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); 676 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec);
667 677
668 snd_soc_codec_exit_regmap(codec); 678 if (!wm9712->mfd_pdata) {
669 snd_soc_free_ac97_codec(wm9712->ac97); 679 snd_soc_codec_exit_regmap(codec);
680 snd_soc_free_ac97_codec(wm9712->ac97);
681 }
682#endif
670 return 0; 683 return 0;
671} 684}
672 685
@@ -697,6 +710,7 @@ static int wm9712_probe(struct platform_device *pdev)
697 710
698 mutex_init(&wm9712->lock); 711 mutex_init(&wm9712->lock);
699 712
713 wm9712->mfd_pdata = dev_get_platdata(&pdev->dev);
700 platform_set_drvdata(pdev, wm9712); 714 platform_set_drvdata(pdev, wm9712);
701 715
702 return snd_soc_register_codec(&pdev->dev, 716 return snd_soc_register_codec(&pdev->dev,
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
index 7e4822185feb..df7220656d98 100644
--- a/sound/soc/codecs/wm9713.c
+++ b/sound/soc/codecs/wm9713.c
@@ -17,12 +17,15 @@
17 17
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/mfd/wm97xx.h>
20#include <linux/module.h> 21#include <linux/module.h>
21#include <linux/device.h> 22#include <linux/device.h>
22#include <linux/regmap.h> 23#include <linux/regmap.h>
23#include <sound/core.h> 24#include <sound/core.h>
24#include <sound/pcm.h> 25#include <sound/pcm.h>
25#include <sound/ac97_codec.h> 26#include <sound/ac97_codec.h>
27#include <sound/ac97/codec.h>
28#include <sound/ac97/compat.h>
26#include <sound/initval.h> 29#include <sound/initval.h>
27#include <sound/pcm_params.h> 30#include <sound/pcm_params.h>
28#include <sound/tlv.h> 31#include <sound/tlv.h>
@@ -38,6 +41,7 @@ struct wm9713_priv {
38 u32 pll_in; /* PLL input frequency */ 41 u32 pll_in; /* PLL input frequency */
39 unsigned int hp_mixer[2]; 42 unsigned int hp_mixer[2];
40 struct mutex lock; 43 struct mutex lock;
44 struct wm97xx_platform_data *mfd_pdata;
41}; 45};
42 46
43#define HPL_MIXER 0 47#define HPL_MIXER 0
@@ -1205,17 +1209,23 @@ static int wm9713_soc_resume(struct snd_soc_codec *codec)
1205static int wm9713_soc_probe(struct snd_soc_codec *codec) 1209static int wm9713_soc_probe(struct snd_soc_codec *codec)
1206{ 1210{
1207 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); 1211 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
1208 struct regmap *regmap; 1212 struct regmap *regmap = NULL;
1209 1213
1210 wm9713->ac97 = snd_soc_new_ac97_codec(codec, WM9713_VENDOR_ID, 1214 if (wm9713->mfd_pdata) {
1211 WM9713_VENDOR_ID_MASK); 1215 wm9713->ac97 = wm9713->mfd_pdata->ac97;
1212 if (IS_ERR(wm9713->ac97)) 1216 regmap = wm9713->mfd_pdata->regmap;
1213 return PTR_ERR(wm9713->ac97); 1217 } else {
1214 1218#ifdef CONFIG_SND_SOC_AC97_BUS
1215 regmap = regmap_init_ac97(wm9713->ac97, &wm9713_regmap_config); 1219 wm9713->ac97 = snd_soc_new_ac97_codec(codec, WM9713_VENDOR_ID,
1216 if (IS_ERR(regmap)) { 1220 WM9713_VENDOR_ID_MASK);
1217 snd_soc_free_ac97_codec(wm9713->ac97); 1221 if (IS_ERR(wm9713->ac97))
1218 return PTR_ERR(regmap); 1222 return PTR_ERR(wm9713->ac97);
1223 regmap = regmap_init_ac97(wm9713->ac97, &wm9713_regmap_config);
1224 if (IS_ERR(regmap)) {
1225 snd_soc_free_ac97_codec(wm9713->ac97);
1226 return PTR_ERR(regmap);
1227 }
1228#endif
1219 } 1229 }
1220 1230
1221 snd_soc_codec_init_regmap(codec, regmap); 1231 snd_soc_codec_init_regmap(codec, regmap);
@@ -1228,10 +1238,14 @@ static int wm9713_soc_probe(struct snd_soc_codec *codec)
1228 1238
1229static int wm9713_soc_remove(struct snd_soc_codec *codec) 1239static int wm9713_soc_remove(struct snd_soc_codec *codec)
1230{ 1240{
1241#ifdef CONFIG_SND_SOC_AC97_BUS
1231 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); 1242 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
1232 1243
1233 snd_soc_codec_exit_regmap(codec); 1244 if (!wm9713->mfd_pdata) {
1234 snd_soc_free_ac97_codec(wm9713->ac97); 1245 snd_soc_codec_exit_regmap(codec);
1246 snd_soc_free_ac97_codec(wm9713->ac97);
1247 }
1248#endif
1235 return 0; 1249 return 0;
1236} 1250}
1237 1251
@@ -1262,6 +1276,7 @@ static int wm9713_probe(struct platform_device *pdev)
1262 1276
1263 mutex_init(&wm9713->lock); 1277 mutex_init(&wm9713->lock);
1264 1278
1279 wm9713->mfd_pdata = dev_get_platdata(&pdev->dev);
1265 platform_set_drvdata(pdev, wm9713); 1280 platform_set_drvdata(pdev, wm9713);
1266 1281
1267 return snd_soc_register_codec(&pdev->dev, 1282 return snd_soc_register_codec(&pdev->dev,
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index f395bbc7c354..804c6f2bcf21 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -1721,7 +1721,8 @@ static int davinci_mcasp_get_dma_type(struct davinci_mcasp *mcasp)
1721 PTR_ERR(chan)); 1721 PTR_ERR(chan));
1722 return PTR_ERR(chan); 1722 return PTR_ERR(chan);
1723 } 1723 }
1724 BUG_ON(!chan->device || !chan->device->dev); 1724 if (WARN_ON(!chan->device || !chan->device->dev))
1725 return -EINVAL;
1725 1726
1726 if (chan->device->dev->of_node) 1727 if (chan->device->dev->of_node)
1727 ret = of_property_read_string(chan->device->dev->of_node, 1728 ret = of_property_read_string(chan->device->dev->of_node,
@@ -1867,6 +1868,10 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1867 if (irq >= 0) { 1868 if (irq >= 0) {
1868 irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_common", 1869 irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_common",
1869 dev_name(&pdev->dev)); 1870 dev_name(&pdev->dev));
1871 if (!irq_name) {
1872 ret = -ENOMEM;
1873 goto err;
1874 }
1870 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 1875 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
1871 davinci_mcasp_common_irq_handler, 1876 davinci_mcasp_common_irq_handler,
1872 IRQF_ONESHOT | IRQF_SHARED, 1877 IRQF_ONESHOT | IRQF_SHARED,
@@ -1884,6 +1889,10 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1884 if (irq >= 0) { 1889 if (irq >= 0) {
1885 irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_rx", 1890 irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_rx",
1886 dev_name(&pdev->dev)); 1891 dev_name(&pdev->dev));
1892 if (!irq_name) {
1893 ret = -ENOMEM;
1894 goto err;
1895 }
1887 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 1896 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
1888 davinci_mcasp_rx_irq_handler, 1897 davinci_mcasp_rx_irq_handler,
1889 IRQF_ONESHOT, irq_name, mcasp); 1898 IRQF_ONESHOT, irq_name, mcasp);
@@ -1899,6 +1908,10 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1899 if (irq >= 0) { 1908 if (irq >= 0) {
1900 irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_tx", 1909 irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_tx",
1901 dev_name(&pdev->dev)); 1910 dev_name(&pdev->dev));
1911 if (!irq_name) {
1912 ret = -ENOMEM;
1913 goto err;
1914 }
1902 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 1915 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
1903 davinci_mcasp_tx_irq_handler, 1916 davinci_mcasp_tx_irq_handler,
1904 IRQF_ONESHOT, irq_name, mcasp); 1917 IRQF_ONESHOT, irq_name, mcasp);
@@ -1982,8 +1995,10 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1982 GFP_KERNEL); 1995 GFP_KERNEL);
1983 1996
1984 if (!mcasp->chconstr[SNDRV_PCM_STREAM_PLAYBACK].list || 1997 if (!mcasp->chconstr[SNDRV_PCM_STREAM_PLAYBACK].list ||
1985 !mcasp->chconstr[SNDRV_PCM_STREAM_CAPTURE].list) 1998 !mcasp->chconstr[SNDRV_PCM_STREAM_CAPTURE].list) {
1986 return -ENOMEM; 1999 ret = -ENOMEM;
2000 goto err;
2001 }
1987 2002
1988 ret = davinci_mcasp_set_ch_constraints(mcasp); 2003 ret = davinci_mcasp_set_ch_constraints(mcasp);
1989 if (ret) 2004 if (ret)
diff --git a/sound/soc/dwc/Kconfig b/sound/soc/dwc/Kconfig
index c6fd95fa5ca6..aa0c6ec4d93c 100644
--- a/sound/soc/dwc/Kconfig
+++ b/sound/soc/dwc/Kconfig
@@ -4,8 +4,8 @@ config SND_DESIGNWARE_I2S
4 select SND_SOC_GENERIC_DMAENGINE_PCM 4 select SND_SOC_GENERIC_DMAENGINE_PCM
5 help 5 help
6 Say Y or M if you want to add support for I2S driver for 6 Say Y or M if you want to add support for I2S driver for
7 Synopsys desigwnware I2S device. The device supports upto 7 Synopsys designware I2S device. The device supports up to
8 maximum of 8 channels each for play and record. 8 a maximum of 8 channels each for play and record.
9 9
10config SND_DESIGNWARE_PCM 10config SND_DESIGNWARE_PCM
11 bool "PCM PIO extension for I2S driver" 11 bool "PCM PIO extension for I2S driver"
diff --git a/sound/soc/fsl/fsl-asoc-card.c b/sound/soc/fsl/fsl-asoc-card.c
index 2db4d0c80d33..1225e0399de8 100644
--- a/sound/soc/fsl/fsl-asoc-card.c
+++ b/sound/soc/fsl/fsl-asoc-card.c
@@ -166,7 +166,7 @@ static int fsl_asoc_card_hw_params(struct snd_pcm_substream *substream,
166 ret = snd_soc_dai_set_sysclk(rtd->cpu_dai, cpu_priv->sysclk_id[tx], 166 ret = snd_soc_dai_set_sysclk(rtd->cpu_dai, cpu_priv->sysclk_id[tx],
167 cpu_priv->sysclk_freq[tx], 167 cpu_priv->sysclk_freq[tx],
168 cpu_priv->sysclk_dir[tx]); 168 cpu_priv->sysclk_dir[tx]);
169 if (ret) { 169 if (ret && ret != -ENOTSUPP) {
170 dev_err(dev, "failed to set sysclk for cpu dai\n"); 170 dev_err(dev, "failed to set sysclk for cpu dai\n");
171 return ret; 171 return ret;
172 } 172 }
@@ -174,7 +174,7 @@ static int fsl_asoc_card_hw_params(struct snd_pcm_substream *substream,
174 if (cpu_priv->slot_width) { 174 if (cpu_priv->slot_width) {
175 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 175 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2,
176 cpu_priv->slot_width); 176 cpu_priv->slot_width);
177 if (ret) { 177 if (ret && ret != -ENOTSUPP) {
178 dev_err(dev, "failed to set TDM slot for cpu dai\n"); 178 dev_err(dev, "failed to set TDM slot for cpu dai\n");
179 return ret; 179 return ret;
180 } 180 }
@@ -270,7 +270,7 @@ static int fsl_asoc_card_set_bias_level(struct snd_soc_card *card,
270 270
271 ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->fll_id, 271 ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->fll_id,
272 pll_out, SND_SOC_CLOCK_IN); 272 pll_out, SND_SOC_CLOCK_IN);
273 if (ret) { 273 if (ret && ret != -ENOTSUPP) {
274 dev_err(dev, "failed to set SYSCLK: %d\n", ret); 274 dev_err(dev, "failed to set SYSCLK: %d\n", ret);
275 return ret; 275 return ret;
276 } 276 }
@@ -283,7 +283,7 @@ static int fsl_asoc_card_set_bias_level(struct snd_soc_card *card,
283 ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id, 283 ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id,
284 codec_priv->mclk_freq, 284 codec_priv->mclk_freq,
285 SND_SOC_CLOCK_IN); 285 SND_SOC_CLOCK_IN);
286 if (ret) { 286 if (ret && ret != -ENOTSUPP) {
287 dev_err(dev, "failed to switch away from FLL: %d\n", ret); 287 dev_err(dev, "failed to switch away from FLL: %d\n", ret);
288 return ret; 288 return ret;
289 } 289 }
@@ -459,7 +459,7 @@ static int fsl_asoc_card_late_probe(struct snd_soc_card *card)
459 459
460 ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id, 460 ret = snd_soc_dai_set_sysclk(codec_dai, codec_priv->mclk_id,
461 codec_priv->mclk_freq, SND_SOC_CLOCK_IN); 461 codec_priv->mclk_freq, SND_SOC_CLOCK_IN);
462 if (ret) { 462 if (ret && ret != -ENOTSUPP) {
463 dev_err(dev, "failed to set sysclk in %s\n", __func__); 463 dev_err(dev, "failed to set sysclk in %s\n", __func__);
464 return ret; 464 return ret;
465 } 465 }
@@ -639,6 +639,10 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
639 devm_kasprintf(&pdev->dev, GFP_KERNEL, 639 devm_kasprintf(&pdev->dev, GFP_KERNEL,
640 "ac97-codec.%u", 640 "ac97-codec.%u",
641 (unsigned int)idx); 641 (unsigned int)idx);
642 if (!priv->dai_link[0].codec_name) {
643 ret = -ENOMEM;
644 goto asrc_fail;
645 }
642 } 646 }
643 647
644 priv->dai_link[0].platform_of_node = cpu_np; 648 priv->dai_link[0].platform_of_node = cpu_np;
diff --git a/sound/soc/fsl/fsl_spdif.c b/sound/soc/fsl/fsl_spdif.c
index 7e6cc4da0088..4f7469c1864c 100644
--- a/sound/soc/fsl/fsl_spdif.c
+++ b/sound/soc/fsl/fsl_spdif.c
@@ -1110,7 +1110,7 @@ static u32 fsl_spdif_txclk_caldiv(struct fsl_spdif_priv *spdif_priv,
1110 struct clk *clk, u64 savesub, 1110 struct clk *clk, u64 savesub,
1111 enum spdif_txrate index, bool round) 1111 enum spdif_txrate index, bool round)
1112{ 1112{
1113 const u32 rate[] = { 32000, 44100, 48000, 96000, 192000 }; 1113 static const u32 rate[] = { 32000, 44100, 48000, 96000, 192000 };
1114 bool is_sysclk = clk_is_match(clk, spdif_priv->sysclk); 1114 bool is_sysclk = clk_is_match(clk, spdif_priv->sysclk);
1115 u64 rate_ideal, rate_actual, sub; 1115 u64 rate_ideal, rate_actual, sub;
1116 u32 sysclk_dfmin, sysclk_dfmax; 1116 u32 sysclk_dfmin, sysclk_dfmax;
@@ -1169,7 +1169,7 @@ out:
1169static int fsl_spdif_probe_txclk(struct fsl_spdif_priv *spdif_priv, 1169static int fsl_spdif_probe_txclk(struct fsl_spdif_priv *spdif_priv,
1170 enum spdif_txrate index) 1170 enum spdif_txrate index)
1171{ 1171{
1172 const u32 rate[] = { 32000, 44100, 48000, 96000, 192000 }; 1172 static const u32 rate[] = { 32000, 44100, 48000, 96000, 192000 };
1173 struct platform_device *pdev = spdif_priv->pdev; 1173 struct platform_device *pdev = spdif_priv->pdev;
1174 struct device *dev = &pdev->dev; 1174 struct device *dev = &pdev->dev;
1175 u64 savesub = 100000, ret; 1175 u64 savesub = 100000, ret;
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index 64598d1183f8..f2f51e06e22c 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -197,12 +197,13 @@ struct fsl_ssi_soc_data {
197 * @use_dma: DMA is used or FIQ with stream filter 197 * @use_dma: DMA is used or FIQ with stream filter
198 * @use_dual_fifo: DMA with support for both FIFOs used 198 * @use_dual_fifo: DMA with support for both FIFOs used
199 * @fifo_deph: Depth of the SSI FIFOs 199 * @fifo_deph: Depth of the SSI FIFOs
200 * @slot_width: width of each DAI slot
201 * @slots: number of slots
200 * @rxtx_reg_val: Specific register settings for receive/transmit configuration 202 * @rxtx_reg_val: Specific register settings for receive/transmit configuration
201 * 203 *
202 * @clk: SSI clock 204 * @clk: SSI clock
203 * @baudclk: SSI baud clock for master mode 205 * @baudclk: SSI baud clock for master mode
204 * @baudclk_streams: Active streams that are using baudclk 206 * @baudclk_streams: Active streams that are using baudclk
205 * @bitclk_freq: bitclock frequency set by .set_dai_sysclk
206 * 207 *
207 * @dma_params_tx: DMA transmit parameters 208 * @dma_params_tx: DMA transmit parameters
208 * @dma_params_rx: DMA receive parameters 209 * @dma_params_rx: DMA receive parameters
@@ -233,12 +234,13 @@ struct fsl_ssi_private {
233 bool use_dual_fifo; 234 bool use_dual_fifo;
234 bool has_ipg_clk_name; 235 bool has_ipg_clk_name;
235 unsigned int fifo_depth; 236 unsigned int fifo_depth;
237 unsigned int slot_width;
238 unsigned int slots;
236 struct fsl_ssi_rxtx_reg_val rxtx_reg_val; 239 struct fsl_ssi_rxtx_reg_val rxtx_reg_val;
237 240
238 struct clk *clk; 241 struct clk *clk;
239 struct clk *baudclk; 242 struct clk *baudclk;
240 unsigned int baudclk_streams; 243 unsigned int baudclk_streams;
241 unsigned int bitclk_freq;
242 244
243 /* regcache for volatile regs */ 245 /* regcache for volatile regs */
244 u32 regcache_sfcsr; 246 u32 regcache_sfcsr;
@@ -700,8 +702,8 @@ static void fsl_ssi_shutdown(struct snd_pcm_substream *substream,
700 * Note: This function can be only called when using SSI as DAI master 702 * Note: This function can be only called when using SSI as DAI master
701 * 703 *
702 * Quick instruction for parameters: 704 * Quick instruction for parameters:
703 * freq: Output BCLK frequency = samplerate * 32 (fixed) * channels 705 * freq: Output BCLK frequency = samplerate * slots * slot_width
704 * dir: SND_SOC_CLOCK_OUT -> TxBCLK, SND_SOC_CLOCK_IN -> RxBCLK. 706 * (In 2-channel I2S Master mode, slot_width is fixed 32)
705 */ 707 */
706static int fsl_ssi_set_bclk(struct snd_pcm_substream *substream, 708static int fsl_ssi_set_bclk(struct snd_pcm_substream *substream,
707 struct snd_soc_dai *cpu_dai, 709 struct snd_soc_dai *cpu_dai,
@@ -712,15 +714,21 @@ static int fsl_ssi_set_bclk(struct snd_pcm_substream *substream,
712 int synchronous = ssi_private->cpu_dai_drv.symmetric_rates, ret; 714 int synchronous = ssi_private->cpu_dai_drv.symmetric_rates, ret;
713 u32 pm = 999, div2, psr, stccr, mask, afreq, factor, i; 715 u32 pm = 999, div2, psr, stccr, mask, afreq, factor, i;
714 unsigned long clkrate, baudrate, tmprate; 716 unsigned long clkrate, baudrate, tmprate;
717 unsigned int slots = params_channels(hw_params);
718 unsigned int slot_width = 32;
715 u64 sub, savesub = 100000; 719 u64 sub, savesub = 100000;
716 unsigned int freq; 720 unsigned int freq;
717 bool baudclk_is_used; 721 bool baudclk_is_used;
718 722
719 /* Prefer the explicitly set bitclock frequency */ 723 /* Override slots and slot_width if being specifically set... */
720 if (ssi_private->bitclk_freq) 724 if (ssi_private->slots)
721 freq = ssi_private->bitclk_freq; 725 slots = ssi_private->slots;
722 else 726 /* ...but keep 32 bits if slots is 2 -- I2S Master mode */
723 freq = params_channels(hw_params) * 32 * params_rate(hw_params); 727 if (ssi_private->slot_width && slots != 2)
728 slot_width = ssi_private->slot_width;
729
730 /* Generate bit clock based on the slot number and slot width */
731 freq = slots * slot_width * params_rate(hw_params);
724 732
725 /* Don't apply it to any non-baudclk circumstance */ 733 /* Don't apply it to any non-baudclk circumstance */
726 if (IS_ERR(ssi_private->baudclk)) 734 if (IS_ERR(ssi_private->baudclk))
@@ -805,16 +813,6 @@ static int fsl_ssi_set_bclk(struct snd_pcm_substream *substream,
805 return 0; 813 return 0;
806} 814}
807 815
808static int fsl_ssi_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
809 int clk_id, unsigned int freq, int dir)
810{
811 struct fsl_ssi_private *ssi_private = snd_soc_dai_get_drvdata(cpu_dai);
812
813 ssi_private->bitclk_freq = freq;
814
815 return 0;
816}
817
818/** 816/**
819 * fsl_ssi_hw_params - program the sample size 817 * fsl_ssi_hw_params - program the sample size
820 * 818 *
@@ -1095,6 +1093,12 @@ static int fsl_ssi_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai, u32 tx_mask,
1095 struct regmap *regs = ssi_private->regs; 1093 struct regmap *regs = ssi_private->regs;
1096 u32 val; 1094 u32 val;
1097 1095
1096 /* The word length should be 8, 10, 12, 16, 18, 20, 22 or 24 */
1097 if (slot_width & 1 || slot_width < 8 || slot_width > 24) {
1098 dev_err(cpu_dai->dev, "invalid slot width: %d\n", slot_width);
1099 return -EINVAL;
1100 }
1101
1098 /* The slot number should be >= 2 if using Network mode or I2S mode */ 1102 /* The slot number should be >= 2 if using Network mode or I2S mode */
1099 regmap_read(regs, CCSR_SSI_SCR, &val); 1103 regmap_read(regs, CCSR_SSI_SCR, &val);
1100 val &= CCSR_SSI_SCR_I2S_MODE_MASK | CCSR_SSI_SCR_NET; 1104 val &= CCSR_SSI_SCR_I2S_MODE_MASK | CCSR_SSI_SCR_NET;
@@ -1121,6 +1125,9 @@ static int fsl_ssi_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai, u32 tx_mask,
1121 1125
1122 regmap_update_bits(regs, CCSR_SSI_SCR, CCSR_SSI_SCR_SSIEN, val); 1126 regmap_update_bits(regs, CCSR_SSI_SCR, CCSR_SSI_SCR_SSIEN, val);
1123 1127
1128 ssi_private->slot_width = slot_width;
1129 ssi_private->slots = slots;
1130
1124 return 0; 1131 return 0;
1125} 1132}
1126 1133
@@ -1191,7 +1198,6 @@ static const struct snd_soc_dai_ops fsl_ssi_dai_ops = {
1191 .hw_params = fsl_ssi_hw_params, 1198 .hw_params = fsl_ssi_hw_params,
1192 .hw_free = fsl_ssi_hw_free, 1199 .hw_free = fsl_ssi_hw_free,
1193 .set_fmt = fsl_ssi_set_dai_fmt, 1200 .set_fmt = fsl_ssi_set_dai_fmt,
1194 .set_sysclk = fsl_ssi_set_dai_sysclk,
1195 .set_tdm_slot = fsl_ssi_set_dai_tdm_slot, 1201 .set_tdm_slot = fsl_ssi_set_dai_tdm_slot,
1196 .trigger = fsl_ssi_trigger, 1202 .trigger = fsl_ssi_trigger,
1197}; 1203};
diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c
index 488c52f9405f..1b6164249341 100644
--- a/sound/soc/generic/audio-graph-card.c
+++ b/sound/soc/generic/audio-graph-card.c
@@ -29,7 +29,9 @@ struct graph_card_data {
29 struct graph_dai_props { 29 struct graph_dai_props {
30 struct asoc_simple_dai cpu_dai; 30 struct asoc_simple_dai cpu_dai;
31 struct asoc_simple_dai codec_dai; 31 struct asoc_simple_dai codec_dai;
32 unsigned int mclk_fs;
32 } *dai_props; 33 } *dai_props;
34 unsigned int mclk_fs;
33 struct snd_soc_dai_link *dai_link; 35 struct snd_soc_dai_link *dai_link;
34 struct gpio_desc *pa_gpio; 36 struct gpio_desc *pa_gpio;
35}; 37};
@@ -95,9 +97,43 @@ static void asoc_graph_card_shutdown(struct snd_pcm_substream *substream)
95 asoc_simple_card_clk_disable(&dai_props->codec_dai); 97 asoc_simple_card_clk_disable(&dai_props->codec_dai);
96} 98}
97 99
100static int asoc_graph_card_hw_params(struct snd_pcm_substream *substream,
101 struct snd_pcm_hw_params *params)
102{
103 struct snd_soc_pcm_runtime *rtd = substream->private_data;
104 struct snd_soc_dai *codec_dai = rtd->codec_dai;
105 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
106 struct graph_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
107 struct graph_dai_props *dai_props = graph_priv_to_props(priv, rtd->num);
108 unsigned int mclk, mclk_fs = 0;
109 int ret = 0;
110
111 if (priv->mclk_fs)
112 mclk_fs = priv->mclk_fs;
113 else if (dai_props->mclk_fs)
114 mclk_fs = dai_props->mclk_fs;
115
116 if (mclk_fs) {
117 mclk = params_rate(params) * mclk_fs;
118 ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
119 SND_SOC_CLOCK_IN);
120 if (ret && ret != -ENOTSUPP)
121 goto err;
122
123 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
124 SND_SOC_CLOCK_OUT);
125 if (ret && ret != -ENOTSUPP)
126 goto err;
127 }
128 return 0;
129err:
130 return ret;
131}
132
98static const struct snd_soc_ops asoc_graph_card_ops = { 133static const struct snd_soc_ops asoc_graph_card_ops = {
99 .startup = asoc_graph_card_startup, 134 .startup = asoc_graph_card_startup,
100 .shutdown = asoc_graph_card_shutdown, 135 .shutdown = asoc_graph_card_shutdown,
136 .hw_params = asoc_graph_card_hw_params,
101}; 137};
102 138
103static int asoc_graph_card_dai_init(struct snd_soc_pcm_runtime *rtd) 139static int asoc_graph_card_dai_init(struct snd_soc_pcm_runtime *rtd)
@@ -146,10 +182,7 @@ static int asoc_graph_card_dai_link_of(struct device_node *cpu_port,
146 if (ret < 0) 182 if (ret < 0)
147 goto dai_link_of_err; 183 goto dai_link_of_err;
148 184
149 /* 185 of_property_read_u32(rcpu_ep, "mclk-fs", &dai_props->mclk_fs);
150 * we need to consider "mclk-fs" around here
151 * see simple-card
152 */
153 186
154 ret = asoc_simple_card_parse_graph_cpu(cpu_ep, dai_link); 187 ret = asoc_simple_card_parse_graph_cpu(cpu_ep, dai_link);
155 if (ret < 0) 188 if (ret < 0)
@@ -217,10 +250,8 @@ static int asoc_graph_card_parse_of(struct graph_card_data *priv)
217 if (ret < 0) 250 if (ret < 0)
218 return ret; 251 return ret;
219 252
220 /* 253 /* Factor to mclk, used in hw_params() */
221 * we need to consider "mclk-fs" around here 254 of_property_read_u32(node, "mclk-fs", &priv->mclk_fs);
222 * see simple-card
223 */
224 255
225 of_for_each_phandle(&it, rc, node, "dais", NULL, 0) { 256 of_for_each_phandle(&it, rc, node, "dais", NULL, 0) {
226 ret = asoc_graph_card_dai_link_of(it.node, priv, idx++); 257 ret = asoc_graph_card_dai_link_of(it.node, priv, idx++);
diff --git a/sound/soc/img/img-i2s-in.c b/sound/soc/img/img-i2s-in.c
index 567f9767fb73..d7fbb0a0a28b 100644
--- a/sound/soc/img/img-i2s-in.c
+++ b/sound/soc/img/img-i2s-in.c
@@ -16,6 +16,7 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/of.h> 17#include <linux/of.h>
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/pm_runtime.h>
19#include <linux/reset.h> 20#include <linux/reset.h>
20 21
21#include <sound/core.h> 22#include <sound/core.h>
@@ -60,8 +61,33 @@ struct img_i2s_in {
60 void __iomem *channel_base; 61 void __iomem *channel_base;
61 unsigned int active_channels; 62 unsigned int active_channels;
62 struct snd_soc_dai_driver dai_driver; 63 struct snd_soc_dai_driver dai_driver;
64 u32 suspend_ctl;
65 u32 *suspend_ch_ctl;
63}; 66};
64 67
68static int img_i2s_in_runtime_suspend(struct device *dev)
69{
70 struct img_i2s_in *i2s = dev_get_drvdata(dev);
71
72 clk_disable_unprepare(i2s->clk_sys);
73
74 return 0;
75}
76
77static int img_i2s_in_runtime_resume(struct device *dev)
78{
79 struct img_i2s_in *i2s = dev_get_drvdata(dev);
80 int ret;
81
82 ret = clk_prepare_enable(i2s->clk_sys);
83 if (ret) {
84 dev_err(dev, "Unable to enable sys clock\n");
85 return ret;
86 }
87
88 return 0;
89}
90
65static inline void img_i2s_in_writel(struct img_i2s_in *i2s, u32 val, u32 reg) 91static inline void img_i2s_in_writel(struct img_i2s_in *i2s, u32 val, u32 reg)
66{ 92{
67 writel(val, i2s->base + reg); 93 writel(val, i2s->base + reg);
@@ -279,7 +305,7 @@ static int img_i2s_in_hw_params(struct snd_pcm_substream *substream,
279static int img_i2s_in_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 305static int img_i2s_in_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
280{ 306{
281 struct img_i2s_in *i2s = snd_soc_dai_get_drvdata(dai); 307 struct img_i2s_in *i2s = snd_soc_dai_get_drvdata(dai);
282 int i; 308 int i, ret;
283 u32 chan_control_mask, lrd_set = 0, blkp_set = 0, chan_control_set = 0; 309 u32 chan_control_mask, lrd_set = 0, blkp_set = 0, chan_control_set = 0;
284 u32 reg; 310 u32 reg;
285 311
@@ -319,6 +345,10 @@ static int img_i2s_in_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
319 345
320 chan_control_mask = IMG_I2S_IN_CH_CTL_CLK_TRANS_MASK; 346 chan_control_mask = IMG_I2S_IN_CH_CTL_CLK_TRANS_MASK;
321 347
348 ret = pm_runtime_get_sync(i2s->dev);
349 if (ret < 0)
350 return ret;
351
322 for (i = 0; i < i2s->active_channels; i++) 352 for (i = 0; i < i2s->active_channels; i++)
323 img_i2s_in_ch_disable(i2s, i); 353 img_i2s_in_ch_disable(i2s, i);
324 354
@@ -338,6 +368,8 @@ static int img_i2s_in_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
338 for (i = 0; i < i2s->active_channels; i++) 368 for (i = 0; i < i2s->active_channels; i++)
339 img_i2s_in_ch_enable(i2s, i); 369 img_i2s_in_ch_enable(i2s, i);
340 370
371 pm_runtime_put(i2s->dev);
372
341 return 0; 373 return 0;
342} 374}
343 375
@@ -427,9 +459,15 @@ static int img_i2s_in_probe(struct platform_device *pdev)
427 return PTR_ERR(i2s->clk_sys); 459 return PTR_ERR(i2s->clk_sys);
428 } 460 }
429 461
430 ret = clk_prepare_enable(i2s->clk_sys); 462 pm_runtime_enable(&pdev->dev);
431 if (ret) 463 if (!pm_runtime_enabled(&pdev->dev)) {
432 return ret; 464 ret = img_i2s_in_runtime_resume(&pdev->dev);
465 if (ret)
466 goto err_pm_disable;
467 }
468 ret = pm_runtime_get_sync(&pdev->dev);
469 if (ret < 0)
470 goto err_suspend;
433 471
434 i2s->active_channels = 1; 472 i2s->active_channels = 1;
435 i2s->dma_data.addr = res->start + IMG_I2S_IN_RX_FIFO; 473 i2s->dma_data.addr = res->start + IMG_I2S_IN_RX_FIFO;
@@ -447,7 +485,7 @@ static int img_i2s_in_probe(struct platform_device *pdev)
447 if (IS_ERR(rst)) { 485 if (IS_ERR(rst)) {
448 if (PTR_ERR(rst) == -EPROBE_DEFER) { 486 if (PTR_ERR(rst) == -EPROBE_DEFER) {
449 ret = -EPROBE_DEFER; 487 ret = -EPROBE_DEFER;
450 goto err_clk_disable; 488 goto err_suspend;
451 } 489 }
452 490
453 dev_dbg(dev, "No top level reset found\n"); 491 dev_dbg(dev, "No top level reset found\n");
@@ -469,42 +507,110 @@ static int img_i2s_in_probe(struct platform_device *pdev)
469 IMG_I2S_IN_CH_CTL_JUST_MASK | 507 IMG_I2S_IN_CH_CTL_JUST_MASK |
470 IMG_I2S_IN_CH_CTL_FW_MASK, IMG_I2S_IN_CH_CTL); 508 IMG_I2S_IN_CH_CTL_FW_MASK, IMG_I2S_IN_CH_CTL);
471 509
510 pm_runtime_put(&pdev->dev);
511
512 i2s->suspend_ch_ctl = devm_kzalloc(dev,
513 sizeof(*i2s->suspend_ch_ctl) * i2s->max_i2s_chan, GFP_KERNEL);
514 if (!i2s->suspend_ch_ctl) {
515 ret = -ENOMEM;
516 goto err_suspend;
517 }
518
472 ret = devm_snd_soc_register_component(dev, &img_i2s_in_component, 519 ret = devm_snd_soc_register_component(dev, &img_i2s_in_component,
473 &i2s->dai_driver, 1); 520 &i2s->dai_driver, 1);
474 if (ret) 521 if (ret)
475 goto err_clk_disable; 522 goto err_suspend;
476 523
477 ret = devm_snd_dmaengine_pcm_register(dev, &img_i2s_in_dma_config, 0); 524 ret = devm_snd_dmaengine_pcm_register(dev, &img_i2s_in_dma_config, 0);
478 if (ret) 525 if (ret)
479 goto err_clk_disable; 526 goto err_suspend;
480 527
481 return 0; 528 return 0;
482 529
483err_clk_disable: 530err_suspend:
484 clk_disable_unprepare(i2s->clk_sys); 531 if (!pm_runtime_enabled(&pdev->dev))
532 img_i2s_in_runtime_suspend(&pdev->dev);
533err_pm_disable:
534 pm_runtime_disable(&pdev->dev);
485 535
486 return ret; 536 return ret;
487} 537}
488 538
489static int img_i2s_in_dev_remove(struct platform_device *pdev) 539static int img_i2s_in_dev_remove(struct platform_device *pdev)
490{ 540{
491 struct img_i2s_in *i2s = platform_get_drvdata(pdev); 541 pm_runtime_disable(&pdev->dev);
542 if (!pm_runtime_status_suspended(&pdev->dev))
543 img_i2s_in_runtime_suspend(&pdev->dev);
492 544
493 clk_disable_unprepare(i2s->clk_sys); 545 return 0;
546}
547
548#ifdef CONFIG_PM_SLEEP
549static int img_i2s_in_suspend(struct device *dev)
550{
551 struct img_i2s_in *i2s = dev_get_drvdata(dev);
552 int i, ret;
553 u32 reg;
554
555 if (pm_runtime_status_suspended(dev)) {
556 ret = img_i2s_in_runtime_resume(dev);
557 if (ret)
558 return ret;
559 }
560
561 for (i = 0; i < i2s->max_i2s_chan; i++) {
562 reg = img_i2s_in_ch_readl(i2s, i, IMG_I2S_IN_CH_CTL);
563 i2s->suspend_ch_ctl[i] = reg;
564 }
565
566 i2s->suspend_ctl = img_i2s_in_readl(i2s, IMG_I2S_IN_CTL);
567
568 img_i2s_in_runtime_suspend(dev);
494 569
495 return 0; 570 return 0;
496} 571}
497 572
573static int img_i2s_in_resume(struct device *dev)
574{
575 struct img_i2s_in *i2s = dev_get_drvdata(dev);
576 int i, ret;
577 u32 reg;
578
579 ret = img_i2s_in_runtime_resume(dev);
580 if (ret)
581 return ret;
582
583 for (i = 0; i < i2s->max_i2s_chan; i++) {
584 reg = i2s->suspend_ch_ctl[i];
585 img_i2s_in_ch_writel(i2s, i, reg, IMG_I2S_IN_CH_CTL);
586 }
587
588 img_i2s_in_writel(i2s, i2s->suspend_ctl, IMG_I2S_IN_CTL);
589
590 if (pm_runtime_status_suspended(dev))
591 img_i2s_in_runtime_suspend(dev);
592
593 return 0;
594}
595#endif
596
498static const struct of_device_id img_i2s_in_of_match[] = { 597static const struct of_device_id img_i2s_in_of_match[] = {
499 { .compatible = "img,i2s-in" }, 598 { .compatible = "img,i2s-in" },
500 {} 599 {}
501}; 600};
502MODULE_DEVICE_TABLE(of, img_i2s_in_of_match); 601MODULE_DEVICE_TABLE(of, img_i2s_in_of_match);
503 602
603static const struct dev_pm_ops img_i2s_in_pm_ops = {
604 SET_RUNTIME_PM_OPS(img_i2s_in_runtime_suspend,
605 img_i2s_in_runtime_resume, NULL)
606 SET_SYSTEM_SLEEP_PM_OPS(img_i2s_in_suspend, img_i2s_in_resume)
607};
608
504static struct platform_driver img_i2s_in_driver = { 609static struct platform_driver img_i2s_in_driver = {
505 .driver = { 610 .driver = {
506 .name = "img-i2s-in", 611 .name = "img-i2s-in",
507 .of_match_table = img_i2s_in_of_match 612 .of_match_table = img_i2s_in_of_match,
613 .pm = &img_i2s_in_pm_ops
508 }, 614 },
509 .probe = img_i2s_in_probe, 615 .probe = img_i2s_in_probe,
510 .remove = img_i2s_in_dev_remove 616 .remove = img_i2s_in_dev_remove
diff --git a/sound/soc/img/img-i2s-out.c b/sound/soc/img/img-i2s-out.c
index 78b7f6cd675b..30a95bcef2db 100644
--- a/sound/soc/img/img-i2s-out.c
+++ b/sound/soc/img/img-i2s-out.c
@@ -63,29 +63,36 @@ struct img_i2s_out {
63 unsigned int active_channels; 63 unsigned int active_channels;
64 struct reset_control *rst; 64 struct reset_control *rst;
65 struct snd_soc_dai_driver dai_driver; 65 struct snd_soc_dai_driver dai_driver;
66 u32 suspend_ctl;
67 u32 *suspend_ch_ctl;
66}; 68};
67 69
68static int img_i2s_out_suspend(struct device *dev) 70static int img_i2s_out_runtime_suspend(struct device *dev)
69{ 71{
70 struct img_i2s_out *i2s = dev_get_drvdata(dev); 72 struct img_i2s_out *i2s = dev_get_drvdata(dev);
71 73
72 if (!i2s->force_clk_active) 74 clk_disable_unprepare(i2s->clk_ref);
73 clk_disable_unprepare(i2s->clk_ref); 75 clk_disable_unprepare(i2s->clk_sys);
74 76
75 return 0; 77 return 0;
76} 78}
77 79
78static int img_i2s_out_resume(struct device *dev) 80static int img_i2s_out_runtime_resume(struct device *dev)
79{ 81{
80 struct img_i2s_out *i2s = dev_get_drvdata(dev); 82 struct img_i2s_out *i2s = dev_get_drvdata(dev);
81 int ret; 83 int ret;
82 84
83 if (!i2s->force_clk_active) { 85 ret = clk_prepare_enable(i2s->clk_sys);
84 ret = clk_prepare_enable(i2s->clk_ref); 86 if (ret) {
85 if (ret) { 87 dev_err(dev, "clk_enable failed: %d\n", ret);
86 dev_err(dev, "clk_enable failed: %d\n", ret); 88 return ret;
87 return ret; 89 }
88 } 90
91 ret = clk_prepare_enable(i2s->clk_ref);
92 if (ret) {
93 dev_err(dev, "clk_enable failed: %d\n", ret);
94 clk_disable_unprepare(i2s->clk_sys);
95 return ret;
89 } 96 }
90 97
91 return 0; 98 return 0;
@@ -287,7 +294,7 @@ static int img_i2s_out_hw_params(struct snd_pcm_substream *substream,
287static int img_i2s_out_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 294static int img_i2s_out_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
288{ 295{
289 struct img_i2s_out *i2s = snd_soc_dai_get_drvdata(dai); 296 struct img_i2s_out *i2s = snd_soc_dai_get_drvdata(dai);
290 int i; 297 int i, ret;
291 bool force_clk_active; 298 bool force_clk_active;
292 u32 chan_control_mask, control_mask, chan_control_set = 0; 299 u32 chan_control_mask, control_mask, chan_control_set = 0;
293 u32 reg, control_set = 0; 300 u32 reg, control_set = 0;
@@ -342,6 +349,10 @@ static int img_i2s_out_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
342 349
343 chan_control_mask = IMG_I2S_OUT_CHAN_CTL_CLKT_MASK; 350 chan_control_mask = IMG_I2S_OUT_CHAN_CTL_CLKT_MASK;
344 351
352 ret = pm_runtime_get_sync(i2s->dev);
353 if (ret < 0)
354 return ret;
355
345 img_i2s_out_disable(i2s); 356 img_i2s_out_disable(i2s);
346 357
347 reg = img_i2s_out_readl(i2s, IMG_I2S_OUT_CTL); 358 reg = img_i2s_out_readl(i2s, IMG_I2S_OUT_CTL);
@@ -361,6 +372,7 @@ static int img_i2s_out_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
361 img_i2s_out_ch_enable(i2s, i); 372 img_i2s_out_ch_enable(i2s, i);
362 373
363 img_i2s_out_enable(i2s); 374 img_i2s_out_enable(i2s);
375 pm_runtime_put(i2s->dev);
364 376
365 i2s->force_clk_active = force_clk_active; 377 i2s->force_clk_active = force_clk_active;
366 378
@@ -467,9 +479,20 @@ static int img_i2s_out_probe(struct platform_device *pdev)
467 return PTR_ERR(i2s->clk_ref); 479 return PTR_ERR(i2s->clk_ref);
468 } 480 }
469 481
470 ret = clk_prepare_enable(i2s->clk_sys); 482 i2s->suspend_ch_ctl = devm_kzalloc(dev,
471 if (ret) 483 sizeof(*i2s->suspend_ch_ctl) * i2s->max_i2s_chan, GFP_KERNEL);
472 return ret; 484 if (!i2s->suspend_ch_ctl)
485 return -ENOMEM;
486
487 pm_runtime_enable(&pdev->dev);
488 if (!pm_runtime_enabled(&pdev->dev)) {
489 ret = img_i2s_out_runtime_resume(&pdev->dev);
490 if (ret)
491 goto err_pm_disable;
492 }
493 ret = pm_runtime_get_sync(&pdev->dev);
494 if (ret < 0)
495 goto err_suspend;
473 496
474 reg = IMG_I2S_OUT_CTL_FRM_SIZE_MASK; 497 reg = IMG_I2S_OUT_CTL_FRM_SIZE_MASK;
475 img_i2s_out_writel(i2s, reg, IMG_I2S_OUT_CTL); 498 img_i2s_out_writel(i2s, reg, IMG_I2S_OUT_CTL);
@@ -483,13 +506,7 @@ static int img_i2s_out_probe(struct platform_device *pdev)
483 img_i2s_out_ch_writel(i2s, i, reg, IMG_I2S_OUT_CH_CTL); 506 img_i2s_out_ch_writel(i2s, i, reg, IMG_I2S_OUT_CH_CTL);
484 507
485 img_i2s_out_reset(i2s); 508 img_i2s_out_reset(i2s);
486 509 pm_runtime_put(&pdev->dev);
487 pm_runtime_enable(&pdev->dev);
488 if (!pm_runtime_enabled(&pdev->dev)) {
489 ret = img_i2s_out_resume(&pdev->dev);
490 if (ret)
491 goto err_pm_disable;
492 }
493 510
494 i2s->active_channels = 1; 511 i2s->active_channels = 1;
495 i2s->dma_data.addr = res->start + IMG_I2S_OUT_TX_FIFO; 512 i2s->dma_data.addr = res->start + IMG_I2S_OUT_TX_FIFO;
@@ -517,26 +534,70 @@ static int img_i2s_out_probe(struct platform_device *pdev)
517 534
518err_suspend: 535err_suspend:
519 if (!pm_runtime_status_suspended(&pdev->dev)) 536 if (!pm_runtime_status_suspended(&pdev->dev))
520 img_i2s_out_suspend(&pdev->dev); 537 img_i2s_out_runtime_suspend(&pdev->dev);
521err_pm_disable: 538err_pm_disable:
522 pm_runtime_disable(&pdev->dev); 539 pm_runtime_disable(&pdev->dev);
523 clk_disable_unprepare(i2s->clk_sys);
524 540
525 return ret; 541 return ret;
526} 542}
527 543
528static int img_i2s_out_dev_remove(struct platform_device *pdev) 544static int img_i2s_out_dev_remove(struct platform_device *pdev)
529{ 545{
530 struct img_i2s_out *i2s = platform_get_drvdata(pdev);
531
532 pm_runtime_disable(&pdev->dev); 546 pm_runtime_disable(&pdev->dev);
533 if (!pm_runtime_status_suspended(&pdev->dev)) 547 if (!pm_runtime_status_suspended(&pdev->dev))
534 img_i2s_out_suspend(&pdev->dev); 548 img_i2s_out_runtime_suspend(&pdev->dev);
535 549
536 clk_disable_unprepare(i2s->clk_sys); 550 return 0;
551}
552
553#ifdef CONFIG_PM_SLEEP
554static int img_i2s_out_suspend(struct device *dev)
555{
556 struct img_i2s_out *i2s = dev_get_drvdata(dev);
557 int i, ret;
558 u32 reg;
559
560 if (pm_runtime_status_suspended(dev)) {
561 ret = img_i2s_out_runtime_resume(dev);
562 if (ret)
563 return ret;
564 }
565
566 for (i = 0; i < i2s->max_i2s_chan; i++) {
567 reg = img_i2s_out_ch_readl(i2s, i, IMG_I2S_OUT_CH_CTL);
568 i2s->suspend_ch_ctl[i] = reg;
569 }
570
571 i2s->suspend_ctl = img_i2s_out_readl(i2s, IMG_I2S_OUT_CTL);
572
573 img_i2s_out_runtime_suspend(dev);
574
575 return 0;
576}
577
578static int img_i2s_out_resume(struct device *dev)
579{
580 struct img_i2s_out *i2s = dev_get_drvdata(dev);
581 int i, ret;
582 u32 reg;
583
584 ret = img_i2s_out_runtime_resume(dev);
585 if (ret)
586 return ret;
587
588 for (i = 0; i < i2s->max_i2s_chan; i++) {
589 reg = i2s->suspend_ch_ctl[i];
590 img_i2s_out_ch_writel(i2s, i, reg, IMG_I2S_OUT_CH_CTL);
591 }
592
593 img_i2s_out_writel(i2s, i2s->suspend_ctl, IMG_I2S_OUT_CTL);
594
595 if (pm_runtime_status_suspended(dev))
596 img_i2s_out_runtime_suspend(dev);
537 597
538 return 0; 598 return 0;
539} 599}
600#endif
540 601
541static const struct of_device_id img_i2s_out_of_match[] = { 602static const struct of_device_id img_i2s_out_of_match[] = {
542 { .compatible = "img,i2s-out" }, 603 { .compatible = "img,i2s-out" },
@@ -545,8 +606,9 @@ static const struct of_device_id img_i2s_out_of_match[] = {
545MODULE_DEVICE_TABLE(of, img_i2s_out_of_match); 606MODULE_DEVICE_TABLE(of, img_i2s_out_of_match);
546 607
547static const struct dev_pm_ops img_i2s_out_pm_ops = { 608static const struct dev_pm_ops img_i2s_out_pm_ops = {
548 SET_RUNTIME_PM_OPS(img_i2s_out_suspend, 609 SET_RUNTIME_PM_OPS(img_i2s_out_runtime_suspend,
549 img_i2s_out_resume, NULL) 610 img_i2s_out_runtime_resume, NULL)
611 SET_SYSTEM_SLEEP_PM_OPS(img_i2s_out_suspend, img_i2s_out_resume)
550}; 612};
551 613
552static struct platform_driver img_i2s_out_driver = { 614static struct platform_driver img_i2s_out_driver = {
diff --git a/sound/soc/img/img-parallel-out.c b/sound/soc/img/img-parallel-out.c
index 23b0f0f6ec9c..acc005217be0 100644
--- a/sound/soc/img/img-parallel-out.c
+++ b/sound/soc/img/img-parallel-out.c
@@ -153,6 +153,7 @@ static int img_prl_out_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
153{ 153{
154 struct img_prl_out *prl = snd_soc_dai_get_drvdata(dai); 154 struct img_prl_out *prl = snd_soc_dai_get_drvdata(dai);
155 u32 reg, control_set = 0; 155 u32 reg, control_set = 0;
156 int ret;
156 157
157 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 158 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
158 case SND_SOC_DAIFMT_NB_NF: 159 case SND_SOC_DAIFMT_NB_NF:
@@ -164,9 +165,14 @@ static int img_prl_out_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
164 return -EINVAL; 165 return -EINVAL;
165 } 166 }
166 167
168 ret = pm_runtime_get_sync(prl->dev);
169 if (ret < 0)
170 return ret;
171
167 reg = img_prl_out_readl(prl, IMG_PRL_OUT_CTL); 172 reg = img_prl_out_readl(prl, IMG_PRL_OUT_CTL);
168 reg = (reg & ~IMG_PRL_OUT_CTL_EDGE_MASK) | control_set; 173 reg = (reg & ~IMG_PRL_OUT_CTL_EDGE_MASK) | control_set;
169 img_prl_out_writel(prl, reg, IMG_PRL_OUT_CTL); 174 img_prl_out_writel(prl, reg, IMG_PRL_OUT_CTL);
175 pm_runtime_put(prl->dev);
170 176
171 return 0; 177 return 0;
172} 178}
diff --git a/sound/soc/img/img-spdif-in.c b/sound/soc/img/img-spdif-in.c
index 8adfd65d4390..cedd40c8d1f3 100644
--- a/sound/soc/img/img-spdif-in.c
+++ b/sound/soc/img/img-spdif-in.c
@@ -16,6 +16,7 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/of.h> 17#include <linux/of.h>
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/pm_runtime.h>
19#include <linux/reset.h> 20#include <linux/reset.h>
20 21
21#include <sound/core.h> 22#include <sound/core.h>
@@ -82,11 +83,36 @@ struct img_spdif_in {
82 unsigned int single_freq; 83 unsigned int single_freq;
83 unsigned int multi_freqs[IMG_SPDIF_IN_NUM_ACLKGEN]; 84 unsigned int multi_freqs[IMG_SPDIF_IN_NUM_ACLKGEN];
84 bool active; 85 bool active;
86 u32 suspend_clkgen;
87 u32 suspend_ctl;
85 88
86 /* Write-only registers */ 89 /* Write-only registers */
87 unsigned int aclkgen_regs[IMG_SPDIF_IN_NUM_ACLKGEN]; 90 unsigned int aclkgen_regs[IMG_SPDIF_IN_NUM_ACLKGEN];
88}; 91};
89 92
93static int img_spdif_in_runtime_suspend(struct device *dev)
94{
95 struct img_spdif_in *spdif = dev_get_drvdata(dev);
96
97 clk_disable_unprepare(spdif->clk_sys);
98
99 return 0;
100}
101
102static int img_spdif_in_runtime_resume(struct device *dev)
103{
104 struct img_spdif_in *spdif = dev_get_drvdata(dev);
105 int ret;
106
107 ret = clk_prepare_enable(spdif->clk_sys);
108 if (ret) {
109 dev_err(dev, "Unable to enable sys clock\n");
110 return ret;
111 }
112
113 return 0;
114}
115
90static inline void img_spdif_in_writel(struct img_spdif_in *spdif, 116static inline void img_spdif_in_writel(struct img_spdif_in *spdif,
91 u32 val, u32 reg) 117 u32 val, u32 reg)
92{ 118{
@@ -723,15 +749,21 @@ static int img_spdif_in_probe(struct platform_device *pdev)
723 return PTR_ERR(spdif->clk_sys); 749 return PTR_ERR(spdif->clk_sys);
724 } 750 }
725 751
726 ret = clk_prepare_enable(spdif->clk_sys); 752 pm_runtime_enable(&pdev->dev);
727 if (ret) 753 if (!pm_runtime_enabled(&pdev->dev)) {
728 return ret; 754 ret = img_spdif_in_runtime_resume(&pdev->dev);
755 if (ret)
756 goto err_pm_disable;
757 }
758 ret = pm_runtime_get_sync(&pdev->dev);
759 if (ret < 0)
760 goto err_suspend;
729 761
730 rst = devm_reset_control_get_exclusive(&pdev->dev, "rst"); 762 rst = devm_reset_control_get_exclusive(&pdev->dev, "rst");
731 if (IS_ERR(rst)) { 763 if (IS_ERR(rst)) {
732 if (PTR_ERR(rst) == -EPROBE_DEFER) { 764 if (PTR_ERR(rst) == -EPROBE_DEFER) {
733 ret = -EPROBE_DEFER; 765 ret = -EPROBE_DEFER;
734 goto err_clk_disable; 766 goto err_pm_put;
735 } 767 }
736 dev_dbg(dev, "No top level reset found\n"); 768 dev_dbg(dev, "No top level reset found\n");
737 img_spdif_in_writel(spdif, IMG_SPDIF_IN_SOFT_RESET_MASK, 769 img_spdif_in_writel(spdif, IMG_SPDIF_IN_SOFT_RESET_MASK,
@@ -759,42 +791,98 @@ static int img_spdif_in_probe(struct platform_device *pdev)
759 IMG_SPDIF_IN_CTL_TRK_MASK; 791 IMG_SPDIF_IN_CTL_TRK_MASK;
760 img_spdif_in_writel(spdif, reg, IMG_SPDIF_IN_CTL); 792 img_spdif_in_writel(spdif, reg, IMG_SPDIF_IN_CTL);
761 793
794 pm_runtime_put(&pdev->dev);
795
762 ret = devm_snd_soc_register_component(&pdev->dev, 796 ret = devm_snd_soc_register_component(&pdev->dev,
763 &img_spdif_in_component, &img_spdif_in_dai, 1); 797 &img_spdif_in_component, &img_spdif_in_dai, 1);
764 if (ret) 798 if (ret)
765 goto err_clk_disable; 799 goto err_suspend;
766 800
767 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); 801 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
768 if (ret) 802 if (ret)
769 goto err_clk_disable; 803 goto err_suspend;
770 804
771 return 0; 805 return 0;
772 806
773err_clk_disable: 807err_pm_put:
774 clk_disable_unprepare(spdif->clk_sys); 808 pm_runtime_put(&pdev->dev);
809err_suspend:
810 if (!pm_runtime_enabled(&pdev->dev))
811 img_spdif_in_runtime_suspend(&pdev->dev);
812err_pm_disable:
813 pm_runtime_disable(&pdev->dev);
775 814
776 return ret; 815 return ret;
777} 816}
778 817
779static int img_spdif_in_dev_remove(struct platform_device *pdev) 818static int img_spdif_in_dev_remove(struct platform_device *pdev)
780{ 819{
781 struct img_spdif_in *spdif = platform_get_drvdata(pdev); 820 pm_runtime_disable(&pdev->dev);
821 if (!pm_runtime_status_suspended(&pdev->dev))
822 img_spdif_in_runtime_suspend(&pdev->dev);
782 823
783 clk_disable_unprepare(spdif->clk_sys); 824 return 0;
825}
826
827#ifdef CONFIG_PM_SLEEP
828static int img_spdif_in_suspend(struct device *dev)
829{
830 struct img_spdif_in *spdif = dev_get_drvdata(dev);
831 int ret;
832
833 if (pm_runtime_status_suspended(dev)) {
834 ret = img_spdif_in_runtime_resume(dev);
835 if (ret)
836 return ret;
837 }
838
839 spdif->suspend_clkgen = img_spdif_in_readl(spdif, IMG_SPDIF_IN_CLKGEN);
840 spdif->suspend_ctl = img_spdif_in_readl(spdif, IMG_SPDIF_IN_CTL);
841
842 img_spdif_in_runtime_suspend(dev);
784 843
785 return 0; 844 return 0;
786} 845}
787 846
847static int img_spdif_in_resume(struct device *dev)
848{
849 struct img_spdif_in *spdif = dev_get_drvdata(dev);
850 int i, ret;
851
852 ret = img_spdif_in_runtime_resume(dev);
853 if (ret)
854 return ret;
855
856 for (i = 0; i < IMG_SPDIF_IN_NUM_ACLKGEN; i++)
857 img_spdif_in_aclkgen_writel(spdif, i);
858
859 img_spdif_in_writel(spdif, spdif->suspend_clkgen, IMG_SPDIF_IN_CLKGEN);
860 img_spdif_in_writel(spdif, spdif->suspend_ctl, IMG_SPDIF_IN_CTL);
861
862 if (pm_runtime_status_suspended(dev))
863 img_spdif_in_runtime_suspend(dev);
864
865 return 0;
866}
867#endif
868
788static const struct of_device_id img_spdif_in_of_match[] = { 869static const struct of_device_id img_spdif_in_of_match[] = {
789 { .compatible = "img,spdif-in" }, 870 { .compatible = "img,spdif-in" },
790 {} 871 {}
791}; 872};
792MODULE_DEVICE_TABLE(of, img_spdif_in_of_match); 873MODULE_DEVICE_TABLE(of, img_spdif_in_of_match);
793 874
875static const struct dev_pm_ops img_spdif_in_pm_ops = {
876 SET_RUNTIME_PM_OPS(img_spdif_in_runtime_suspend,
877 img_spdif_in_runtime_resume, NULL)
878 SET_SYSTEM_SLEEP_PM_OPS(img_spdif_in_suspend, img_spdif_in_resume)
879};
880
794static struct platform_driver img_spdif_in_driver = { 881static struct platform_driver img_spdif_in_driver = {
795 .driver = { 882 .driver = {
796 .name = "img-spdif-in", 883 .name = "img-spdif-in",
797 .of_match_table = img_spdif_in_of_match 884 .of_match_table = img_spdif_in_of_match,
885 .pm = &img_spdif_in_pm_ops
798 }, 886 },
799 .probe = img_spdif_in_probe, 887 .probe = img_spdif_in_probe,
800 .remove = img_spdif_in_dev_remove 888 .remove = img_spdif_in_dev_remove
diff --git a/sound/soc/img/img-spdif-out.c b/sound/soc/img/img-spdif-out.c
index 383655da2e60..934ed3df2ebf 100644
--- a/sound/soc/img/img-spdif-out.c
+++ b/sound/soc/img/img-spdif-out.c
@@ -47,25 +47,36 @@ struct img_spdif_out {
47 struct snd_dmaengine_dai_dma_data dma_data; 47 struct snd_dmaengine_dai_dma_data dma_data;
48 struct device *dev; 48 struct device *dev;
49 struct reset_control *rst; 49 struct reset_control *rst;
50 u32 suspend_ctl;
51 u32 suspend_csl;
52 u32 suspend_csh;
50}; 53};
51 54
52static int img_spdif_out_suspend(struct device *dev) 55static int img_spdif_out_runtime_suspend(struct device *dev)
53{ 56{
54 struct img_spdif_out *spdif = dev_get_drvdata(dev); 57 struct img_spdif_out *spdif = dev_get_drvdata(dev);
55 58
56 clk_disable_unprepare(spdif->clk_ref); 59 clk_disable_unprepare(spdif->clk_ref);
60 clk_disable_unprepare(spdif->clk_sys);
57 61
58 return 0; 62 return 0;
59} 63}
60 64
61static int img_spdif_out_resume(struct device *dev) 65static int img_spdif_out_runtime_resume(struct device *dev)
62{ 66{
63 struct img_spdif_out *spdif = dev_get_drvdata(dev); 67 struct img_spdif_out *spdif = dev_get_drvdata(dev);
64 int ret; 68 int ret;
65 69
70 ret = clk_prepare_enable(spdif->clk_sys);
71 if (ret) {
72 dev_err(dev, "clk_enable failed: %d\n", ret);
73 return ret;
74 }
75
66 ret = clk_prepare_enable(spdif->clk_ref); 76 ret = clk_prepare_enable(spdif->clk_ref);
67 if (ret) { 77 if (ret) {
68 dev_err(dev, "clk_enable failed: %d\n", ret); 78 dev_err(dev, "clk_enable failed: %d\n", ret);
79 clk_disable_unprepare(spdif->clk_sys);
69 return ret; 80 return ret;
70 } 81 }
71 82
@@ -355,21 +366,21 @@ static int img_spdif_out_probe(struct platform_device *pdev)
355 return PTR_ERR(spdif->clk_ref); 366 return PTR_ERR(spdif->clk_ref);
356 } 367 }
357 368
358 ret = clk_prepare_enable(spdif->clk_sys);
359 if (ret)
360 return ret;
361
362 img_spdif_out_writel(spdif, IMG_SPDIF_OUT_CTL_FS_MASK,
363 IMG_SPDIF_OUT_CTL);
364
365 img_spdif_out_reset(spdif);
366
367 pm_runtime_enable(&pdev->dev); 369 pm_runtime_enable(&pdev->dev);
368 if (!pm_runtime_enabled(&pdev->dev)) { 370 if (!pm_runtime_enabled(&pdev->dev)) {
369 ret = img_spdif_out_resume(&pdev->dev); 371 ret = img_spdif_out_runtime_resume(&pdev->dev);
370 if (ret) 372 if (ret)
371 goto err_pm_disable; 373 goto err_pm_disable;
372 } 374 }
375 ret = pm_runtime_get_sync(&pdev->dev);
376 if (ret < 0)
377 goto err_suspend;
378
379 img_spdif_out_writel(spdif, IMG_SPDIF_OUT_CTL_FS_MASK,
380 IMG_SPDIF_OUT_CTL);
381
382 img_spdif_out_reset(spdif);
383 pm_runtime_put(&pdev->dev);
373 384
374 spin_lock_init(&spdif->lock); 385 spin_lock_init(&spdif->lock);
375 386
@@ -393,27 +404,62 @@ static int img_spdif_out_probe(struct platform_device *pdev)
393 404
394err_suspend: 405err_suspend:
395 if (!pm_runtime_status_suspended(&pdev->dev)) 406 if (!pm_runtime_status_suspended(&pdev->dev))
396 img_spdif_out_suspend(&pdev->dev); 407 img_spdif_out_runtime_suspend(&pdev->dev);
397err_pm_disable: 408err_pm_disable:
398 pm_runtime_disable(&pdev->dev); 409 pm_runtime_disable(&pdev->dev);
399 clk_disable_unprepare(spdif->clk_sys);
400 410
401 return ret; 411 return ret;
402} 412}
403 413
404static int img_spdif_out_dev_remove(struct platform_device *pdev) 414static int img_spdif_out_dev_remove(struct platform_device *pdev)
405{ 415{
406 struct img_spdif_out *spdif = platform_get_drvdata(pdev);
407
408 pm_runtime_disable(&pdev->dev); 416 pm_runtime_disable(&pdev->dev);
409 if (!pm_runtime_status_suspended(&pdev->dev)) 417 if (!pm_runtime_status_suspended(&pdev->dev))
410 img_spdif_out_suspend(&pdev->dev); 418 img_spdif_out_runtime_suspend(&pdev->dev);
411 419
412 clk_disable_unprepare(spdif->clk_sys); 420 return 0;
421}
422
423#ifdef CONFIG_PM_SLEEP
424static int img_spdif_out_suspend(struct device *dev)
425{
426 struct img_spdif_out *spdif = dev_get_drvdata(dev);
427 int ret;
428
429 if (pm_runtime_status_suspended(dev)) {
430 ret = img_spdif_out_runtime_resume(dev);
431 if (ret)
432 return ret;
433 }
434
435 spdif->suspend_ctl = img_spdif_out_readl(spdif, IMG_SPDIF_OUT_CTL);
436 spdif->suspend_csl = img_spdif_out_readl(spdif, IMG_SPDIF_OUT_CSL);
437 spdif->suspend_csh = img_spdif_out_readl(spdif, IMG_SPDIF_OUT_CSH_UV);
438
439 img_spdif_out_runtime_suspend(dev);
413 440
414 return 0; 441 return 0;
415} 442}
416 443
444static int img_spdif_out_resume(struct device *dev)
445{
446 struct img_spdif_out *spdif = dev_get_drvdata(dev);
447 int ret;
448
449 ret = img_spdif_out_runtime_resume(dev);
450 if (ret)
451 return ret;
452
453 img_spdif_out_writel(spdif, spdif->suspend_ctl, IMG_SPDIF_OUT_CTL);
454 img_spdif_out_writel(spdif, spdif->suspend_csl, IMG_SPDIF_OUT_CSL);
455 img_spdif_out_writel(spdif, spdif->suspend_csh, IMG_SPDIF_OUT_CSH_UV);
456
457 if (pm_runtime_status_suspended(dev))
458 img_spdif_out_runtime_suspend(dev);
459
460 return 0;
461}
462#endif
417static const struct of_device_id img_spdif_out_of_match[] = { 463static const struct of_device_id img_spdif_out_of_match[] = {
418 { .compatible = "img,spdif-out" }, 464 { .compatible = "img,spdif-out" },
419 {} 465 {}
@@ -421,8 +467,9 @@ static const struct of_device_id img_spdif_out_of_match[] = {
421MODULE_DEVICE_TABLE(of, img_spdif_out_of_match); 467MODULE_DEVICE_TABLE(of, img_spdif_out_of_match);
422 468
423static const struct dev_pm_ops img_spdif_out_pm_ops = { 469static const struct dev_pm_ops img_spdif_out_pm_ops = {
424 SET_RUNTIME_PM_OPS(img_spdif_out_suspend, 470 SET_RUNTIME_PM_OPS(img_spdif_out_runtime_suspend,
425 img_spdif_out_resume, NULL) 471 img_spdif_out_runtime_resume, NULL)
472 SET_SYSTEM_SLEEP_PM_OPS(img_spdif_out_suspend, img_spdif_out_resume)
426}; 473};
427 474
428static struct platform_driver img_spdif_out_driver = { 475static struct platform_driver img_spdif_out_driver = {
diff --git a/sound/soc/intel/Kconfig b/sound/soc/intel/Kconfig
index b3c7f554ec30..bb8be10b8437 100644
--- a/sound/soc/intel/Kconfig
+++ b/sound/soc/intel/Kconfig
@@ -1,19 +1,3 @@
1config SND_MFLD_MACHINE
2 tristate "SOC Machine Audio driver for Intel Medfield MID platform"
3 depends on INTEL_SCU_IPC
4 select SND_SOC_SN95031
5 select SND_SST_ATOM_HIFI2_PLATFORM
6 select SND_SST_IPC_PCI
7 help
8 This adds support for ASoC machine driver for Intel(R) MID Medfield platform
9 used as alsa device in audio substem in Intel(R) MID devices
10 Say Y if you have such a device.
11 If unsure select "N".
12
13config SND_SST_ATOM_HIFI2_PLATFORM
14 tristate
15 select SND_SOC_COMPRESS
16
17config SND_SST_IPC 1config SND_SST_IPC
18 tristate 2 tristate
19 3
@@ -27,10 +11,12 @@ config SND_SST_IPC_ACPI
27 select SND_SOC_INTEL_SST 11 select SND_SOC_INTEL_SST
28 select IOSF_MBI 12 select IOSF_MBI
29 13
14config SND_SOC_INTEL_COMMON
15 tristate
16
30config SND_SOC_INTEL_SST 17config SND_SOC_INTEL_SST
31 tristate 18 tristate
32 select SND_SOC_INTEL_SST_ACPI if ACPI 19 select SND_SOC_INTEL_SST_ACPI if ACPI
33 select SND_SOC_INTEL_SST_MATCH if ACPI
34 20
35config SND_SOC_INTEL_SST_FIRMWARE 21config SND_SOC_INTEL_SST_FIRMWARE
36 tristate 22 tristate
@@ -39,280 +25,42 @@ config SND_SOC_INTEL_SST_FIRMWARE
39config SND_SOC_INTEL_SST_ACPI 25config SND_SOC_INTEL_SST_ACPI
40 tristate 26 tristate
41 27
42config SND_SOC_INTEL_SST_MATCH 28config SND_SOC_ACPI_INTEL_MATCH
43 tristate 29 tristate
30 select SND_SOC_ACPI if ACPI
31
32config SND_SOC_INTEL_SST_TOPLEVEL
33 tristate "Intel ASoC SST drivers"
34 depends on X86 || COMPILE_TEST
35 select SND_SOC_INTEL_MACH
36 select SND_SOC_INTEL_COMMON
44 37
45config SND_SOC_INTEL_HASWELL 38config SND_SOC_INTEL_HASWELL
46 tristate 39 tristate "Intel ASoC SST driver for Haswell/Broadwell"
40 depends on SND_SOC_INTEL_SST_TOPLEVEL && SND_DMA_SGBUF
41 depends on DMADEVICES
47 select SND_SOC_INTEL_SST 42 select SND_SOC_INTEL_SST
48 select SND_SOC_INTEL_SST_FIRMWARE 43 select SND_SOC_INTEL_SST_FIRMWARE
49 44
50config SND_SOC_INTEL_BAYTRAIL 45config SND_SOC_INTEL_BAYTRAIL
51 tristate 46 tristate "Intel ASoC SST driver for Baytrail (legacy)"
52 select SND_SOC_INTEL_SST 47 depends on SND_SOC_INTEL_SST_TOPLEVEL
53 select SND_SOC_INTEL_SST_FIRMWARE
54
55config SND_SOC_INTEL_HASWELL_MACH
56 tristate "ASoC Audio DSP support for Intel Haswell Lynxpoint"
57 depends on X86_INTEL_LPSS && I2C && I2C_DESIGNWARE_PLATFORM
58 depends on DMADEVICES
59 select SND_SOC_INTEL_HASWELL
60 select SND_SOC_RT5640
61 help
62 This adds support for the Lynxpoint Audio DSP on Intel(R) Haswell
63 Ultrabook platforms.
64 Say Y if you have such a device.
65 If unsure select "N".
66
67config SND_SOC_INTEL_BXT_DA7219_MAX98357A_MACH
68 tristate "ASoC Audio driver for Broxton with DA7219 and MAX98357A in I2S Mode"
69 depends on X86 && ACPI && I2C
70 select SND_SOC_INTEL_SKYLAKE
71 select SND_SOC_DA7219
72 select SND_SOC_MAX98357A
73 select SND_SOC_DMIC
74 select SND_SOC_HDAC_HDMI
75 select SND_HDA_DSP_LOADER
76 help
77 This adds support for ASoC machine driver for Broxton-P platforms
78 with DA7219 + MAX98357A I2S audio codec.
79 Say Y if you have such a device.
80 If unsure select "N".
81
82config SND_SOC_INTEL_BXT_RT298_MACH
83 tristate "ASoC Audio driver for Broxton with RT298 I2S mode"
84 depends on X86 && ACPI && I2C
85 select SND_SOC_INTEL_SKYLAKE
86 select SND_SOC_RT298
87 select SND_SOC_DMIC
88 select SND_SOC_HDAC_HDMI
89 select SND_HDA_DSP_LOADER
90 help
91 This adds support for ASoC machine driver for Broxton platforms
92 with RT286 I2S audio codec.
93 Say Y if you have such a device.
94 If unsure select "N".
95
96config SND_SOC_INTEL_BYT_RT5640_MACH
97 tristate "ASoC Audio driver for Intel Baytrail with RT5640 codec"
98 depends on X86_INTEL_LPSS && I2C
99 depends on DMADEVICES 48 depends on DMADEVICES
100 depends on SND_SST_IPC_ACPI = n
101 select SND_SOC_INTEL_BAYTRAIL
102 select SND_SOC_RT5640
103 help
104 This adds audio driver for Intel Baytrail platform based boards
105 with the RT5640 audio codec. This driver is deprecated, use
106 SND_SOC_INTEL_BYTCR_RT5640_MACH instead for better functionality.
107
108config SND_SOC_INTEL_BYT_MAX98090_MACH
109 tristate "ASoC Audio driver for Intel Baytrail with MAX98090 codec"
110 depends on X86_INTEL_LPSS && I2C
111 depends on DMADEVICES
112 depends on SND_SST_IPC_ACPI = n
113 select SND_SOC_INTEL_BAYTRAIL
114 select SND_SOC_MAX98090
115 help
116 This adds audio driver for Intel Baytrail platform based boards
117 with the MAX98090 audio codec.
118
119config SND_SOC_INTEL_BDW_RT5677_MACH
120 tristate "ASoC Audio driver for Intel Broadwell with RT5677 codec"
121 depends on X86_INTEL_LPSS && GPIOLIB && I2C
122 depends on DMADEVICES
123 select SND_SOC_INTEL_HASWELL
124 select SND_SOC_RT5677
125 help
126 This adds support for Intel Broadwell platform based boards with
127 the RT5677 audio codec.
128
129config SND_SOC_INTEL_BROADWELL_MACH
130 tristate "ASoC Audio DSP support for Intel Broadwell Wildcatpoint"
131 depends on X86_INTEL_LPSS && I2C && I2C_DESIGNWARE_PLATFORM
132 depends on DMADEVICES
133 select SND_SOC_INTEL_HASWELL
134 select SND_SOC_RT286
135 help
136 This adds support for the Wilcatpoint Audio DSP on Intel(R) Broadwell
137 Ultrabook platforms.
138 Say Y if you have such a device.
139 If unsure select "N".
140
141config SND_SOC_INTEL_BYTCR_RT5640_MACH
142 tristate "ASoC Audio driver for Intel Baytrail and Baytrail-CR with RT5640 codec"
143 depends on X86 && I2C && ACPI
144 select SND_SOC_RT5640
145 select SND_SST_ATOM_HIFI2_PLATFORM
146 select SND_SST_IPC_ACPI
147 select SND_SOC_INTEL_SST_MATCH if ACPI
148 help
149 This adds support for ASoC machine driver for Intel(R) Baytrail and Baytrail-CR
150 platforms with RT5640 audio codec.
151 Say Y if you have such a device.
152 If unsure select "N".
153
154config SND_SOC_INTEL_BYTCR_RT5651_MACH
155 tristate "ASoC Audio driver for Intel Baytrail and Baytrail-CR with RT5651 codec"
156 depends on X86 && I2C && ACPI
157 select SND_SOC_RT5651
158 select SND_SST_ATOM_HIFI2_PLATFORM
159 select SND_SST_IPC_ACPI
160 select SND_SOC_INTEL_SST_MATCH if ACPI
161 help
162 This adds support for ASoC machine driver for Intel(R) Baytrail and Baytrail-CR
163 platforms with RT5651 audio codec.
164 Say Y if you have such a device.
165 If unsure select "N".
166
167config SND_SOC_INTEL_CHT_BSW_RT5672_MACH
168 tristate "ASoC Audio driver for Intel Cherrytrail & Braswell with RT5672 codec"
169 depends on X86_INTEL_LPSS && I2C && ACPI
170 select SND_SOC_RT5670
171 select SND_SST_ATOM_HIFI2_PLATFORM
172 select SND_SST_IPC_ACPI
173 select SND_SOC_INTEL_SST_MATCH if ACPI
174 help
175 This adds support for ASoC machine driver for Intel(R) Cherrytrail & Braswell
176 platforms with RT5672 audio codec.
177 Say Y if you have such a device.
178 If unsure select "N".
179
180config SND_SOC_INTEL_CHT_BSW_RT5645_MACH
181 tristate "ASoC Audio driver for Intel Cherrytrail & Braswell with RT5645/5650 codec"
182 depends on X86_INTEL_LPSS && I2C && ACPI
183 select SND_SOC_RT5645
184 select SND_SST_ATOM_HIFI2_PLATFORM
185 select SND_SST_IPC_ACPI
186 select SND_SOC_INTEL_SST_MATCH if ACPI
187 help
188 This adds support for ASoC machine driver for Intel(R) Cherrytrail & Braswell
189 platforms with RT5645/5650 audio codec.
190 If unsure select "N".
191
192config SND_SOC_INTEL_CHT_BSW_MAX98090_TI_MACH
193 tristate "ASoC Audio driver for Intel Cherrytrail & Braswell with MAX98090 & TI codec"
194 depends on X86_INTEL_LPSS && I2C && ACPI
195 select SND_SOC_MAX98090
196 select SND_SOC_TS3A227E
197 select SND_SST_ATOM_HIFI2_PLATFORM
198 select SND_SST_IPC_ACPI
199 select SND_SOC_INTEL_SST_MATCH if ACPI
200 help
201 This adds support for ASoC machine driver for Intel(R) Cherrytrail & Braswell
202 platforms with MAX98090 audio codec it also can support TI jack chip as aux device.
203 If unsure select "N".
204
205config SND_SOC_INTEL_BYT_CHT_DA7213_MACH
206 tristate "ASoC Audio driver for Intel Baytrail & Cherrytrail with DA7212/7213 codec"
207 depends on X86_INTEL_LPSS && I2C && ACPI
208 select SND_SOC_DA7213
209 select SND_SST_ATOM_HIFI2_PLATFORM
210 select SND_SST_IPC_ACPI
211 select SND_SOC_INTEL_SST_MATCH if ACPI
212 help
213 This adds support for ASoC machine driver for Intel(R) Baytrail & CherryTrail
214 platforms with DA7212/7213 audio codec.
215 If unsure select "N".
216
217config SND_SOC_INTEL_BYT_CHT_ES8316_MACH
218 tristate "ASoC Audio driver for Intel Baytrail & Cherrytrail with ES8316 codec"
219 depends on X86_INTEL_LPSS && I2C && ACPI
220 select SND_SOC_ES8316
221 select SND_SST_ATOM_HIFI2_PLATFORM
222 select SND_SST_IPC_ACPI
223 select SND_SOC_INTEL_SST_MATCH if ACPI
224 help
225 This adds support for ASoC machine driver for Intel(R) Baytrail &
226 Cherrytrail platforms with ES8316 audio codec.
227 If unsure select "N".
228
229config SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH
230 tristate "ASoC Audio driver for Intel Baytrail & Cherrytrail platform with no codec (MinnowBoard MAX, Up)"
231 depends on X86_INTEL_LPSS && I2C && ACPI
232 select SND_SST_ATOM_HIFI2_PLATFORM
233 select SND_SST_IPC_ACPI
234 select SND_SOC_INTEL_SST_MATCH if ACPI
235 help
236 This adds support for ASoC machine driver for the MinnowBoard Max or
237 Up boards and provides access to I2S signals on the Low-Speed
238 connector
239 If unsure select "N".
240
241config SND_SOC_INTEL_KBL_RT5663_MAX98927_MACH
242 tristate "ASoC Audio driver for KBL with RT5663 and MAX98927 in I2S Mode"
243 depends on X86_INTEL_LPSS && I2C
244 select SND_SOC_INTEL_SST 49 select SND_SOC_INTEL_SST
245 select SND_SOC_INTEL_SKYLAKE 50 select SND_SOC_INTEL_SST_FIRMWARE
246 select SND_SOC_RT5663
247 select SND_SOC_MAX98927
248 select SND_SOC_DMIC
249 select SND_SOC_HDAC_HDMI
250 help
251 This adds support for ASoC Onboard Codec I2S machine driver. This will
252 create an alsa sound card for RT5663 + MAX98927.
253 Say Y if you have such a device.
254 If unsure select "N".
255 51
256config SND_SOC_INTEL_KBL_RT5663_RT5514_MAX98927_MACH 52config SND_SST_ATOM_HIFI2_PLATFORM
257 tristate "ASoC Audio driver for KBL with RT5663, RT5514 and MAX98927 in I2S Mode" 53 tristate "Intel ASoC SST driver for HiFi2 platforms (*field, *trail)"
258 depends on X86_INTEL_LPSS && I2C && SPI 54 depends on SND_SOC_INTEL_SST_TOPLEVEL && X86
259 select SND_SOC_INTEL_SST 55 select SND_SOC_COMPRESS
260 select SND_SOC_INTEL_SKYLAKE
261 select SND_SOC_RT5663
262 select SND_SOC_RT5514
263 select SND_SOC_RT5514_SPI
264 select SND_SOC_MAX98927
265 select SND_SOC_HDAC_HDMI
266 help
267 This adds support for ASoC Onboard Codec I2S machine driver. This will
268 create an alsa sound card for RT5663 + RT5514 + MAX98927.
269 Say Y if you have such a device.
270 If unsure select "N".
271 56
272config SND_SOC_INTEL_SKYLAKE 57config SND_SOC_INTEL_SKYLAKE
273 tristate 58 tristate "Intel ASoC SST driver for SKL/BXT/KBL/GLK/CNL"
59 depends on SND_SOC_INTEL_SST_TOPLEVEL && PCI && ACPI
274 select SND_HDA_EXT_CORE 60 select SND_HDA_EXT_CORE
275 select SND_HDA_DSP_LOADER 61 select SND_HDA_DSP_LOADER
276 select SND_SOC_TOPOLOGY 62 select SND_SOC_TOPOLOGY
277 select SND_SOC_INTEL_SST 63 select SND_SOC_INTEL_SST
278 64
279config SND_SOC_INTEL_SKL_RT286_MACH 65# ASoC codec drivers
280 tristate "ASoC Audio driver for SKL with RT286 I2S mode" 66source "sound/soc/intel/boards/Kconfig"
281 depends on X86 && ACPI && I2C
282 select SND_SOC_INTEL_SKYLAKE
283 select SND_SOC_RT286
284 select SND_SOC_DMIC
285 select SND_SOC_HDAC_HDMI
286 help
287 This adds support for ASoC machine driver for Skylake platforms
288 with RT286 I2S audio codec.
289 Say Y if you have such a device.
290 If unsure select "N".
291
292config SND_SOC_INTEL_SKL_NAU88L25_SSM4567_MACH
293 tristate "ASoC Audio driver for SKL with NAU88L25 and SSM4567 in I2S Mode"
294 depends on X86_INTEL_LPSS && I2C
295 select SND_SOC_INTEL_SKYLAKE
296 select SND_SOC_NAU8825
297 select SND_SOC_SSM4567
298 select SND_SOC_DMIC
299 select SND_SOC_HDAC_HDMI
300 help
301 This adds support for ASoC Onboard Codec I2S machine driver. This will
302 create an alsa sound card for NAU88L25 + SSM4567.
303 Say Y if you have such a device.
304 If unsure select "N".
305
306config SND_SOC_INTEL_SKL_NAU88L25_MAX98357A_MACH
307 tristate "ASoC Audio driver for SKL with NAU88L25 and MAX98357A in I2S Mode"
308 depends on X86_INTEL_LPSS && I2C
309 select SND_SOC_INTEL_SKYLAKE
310 select SND_SOC_NAU8825
311 select SND_SOC_MAX98357A
312 select SND_SOC_DMIC
313 select SND_SOC_HDAC_HDMI
314 help
315 This adds support for ASoC Onboard Codec I2S machine driver. This will
316 create an alsa sound card for NAU88L25 + MAX98357A.
317 Say Y if you have such a device.
318 If unsure select "N".
diff --git a/sound/soc/intel/Makefile b/sound/soc/intel/Makefile
index 62f37ffffdf0..b973d457e834 100644
--- a/sound/soc/intel/Makefile
+++ b/sound/soc/intel/Makefile
@@ -1,6 +1,6 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2# Core support 2# Core support
3obj-$(CONFIG_SND_SOC_INTEL_SST) += common/ 3obj-$(CONFIG_SND_SOC_INTEL_COMMON) += common/
4 4
5# Platform Support 5# Platform Support
6obj-$(CONFIG_SND_SOC_INTEL_HASWELL) += haswell/ 6obj-$(CONFIG_SND_SOC_INTEL_HASWELL) += haswell/
diff --git a/sound/soc/intel/atom/sst-mfld-platform-compress.c b/sound/soc/intel/atom/sst-mfld-platform-compress.c
index 1bead81bb510..1dbcab5a6ff0 100644
--- a/sound/soc/intel/atom/sst-mfld-platform-compress.c
+++ b/sound/soc/intel/atom/sst-mfld-platform-compress.c
@@ -259,7 +259,7 @@ static int sst_platform_compr_set_metadata(struct snd_compr_stream *cstream,
259 return stream->compr_ops->set_metadata(sst->dev, stream->id, metadata); 259 return stream->compr_ops->set_metadata(sst->dev, stream->id, metadata);
260} 260}
261 261
262struct snd_compr_ops sst_platform_compr_ops = { 262const struct snd_compr_ops sst_platform_compr_ops = {
263 263
264 .open = sst_platform_compr_open, 264 .open = sst_platform_compr_open,
265 .free = sst_platform_compr_free, 265 .free = sst_platform_compr_free,
diff --git a/sound/soc/intel/atom/sst-mfld-platform.h b/sound/soc/intel/atom/sst-mfld-platform.h
index cb32cc7e5ec1..31a58c25472c 100644
--- a/sound/soc/intel/atom/sst-mfld-platform.h
+++ b/sound/soc/intel/atom/sst-mfld-platform.h
@@ -25,7 +25,7 @@
25#include "sst-atom-controls.h" 25#include "sst-atom-controls.h"
26 26
27extern struct sst_device *sst; 27extern struct sst_device *sst;
28extern struct snd_compr_ops sst_platform_compr_ops; 28extern const struct snd_compr_ops sst_platform_compr_ops;
29 29
30#define SST_MONO 1 30#define SST_MONO 1
31#define SST_STEREO 2 31#define SST_STEREO 2
diff --git a/sound/soc/intel/atom/sst/sst_acpi.c b/sound/soc/intel/atom/sst/sst_acpi.c
index 0e928d54305d..32d6e02e2104 100644
--- a/sound/soc/intel/atom/sst/sst_acpi.c
+++ b/sound/soc/intel/atom/sst/sst_acpi.c
@@ -23,7 +23,6 @@
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/io.h> 25#include <linux/io.h>
26#include <linux/miscdevice.h>
27#include <linux/platform_device.h> 26#include <linux/platform_device.h>
28#include <linux/firmware.h> 27#include <linux/firmware.h>
29#include <linux/pm_runtime.h> 28#include <linux/pm_runtime.h>
@@ -41,9 +40,10 @@
41#include <acpi/acpi_bus.h> 40#include <acpi/acpi_bus.h>
42#include <asm/cpu_device_id.h> 41#include <asm/cpu_device_id.h>
43#include <asm/iosf_mbi.h> 42#include <asm/iosf_mbi.h>
43#include <sound/soc-acpi.h>
44#include <sound/soc-acpi-intel-match.h>
44#include "../sst-mfld-platform.h" 45#include "../sst-mfld-platform.h"
45#include "../../common/sst-dsp.h" 46#include "../../common/sst-dsp.h"
46#include "../../common/sst-acpi.h"
47#include "sst.h" 47#include "sst.h"
48 48
49/* LPE viewpoint addresses */ 49/* LPE viewpoint addresses */
@@ -239,19 +239,26 @@ static int sst_platform_get_resources(struct intel_sst_drv *ctx)
239 return 0; 239 return 0;
240} 240}
241 241
242static int is_byt(void)
243{
244 bool status = false;
245 static const struct x86_cpu_id cpu_ids[] = {
246 { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
247 {}
248 };
249 if (x86_match_cpu(cpu_ids))
250 status = true;
251 return status;
252}
242 253
243static int is_byt_cr(struct device *dev, bool *bytcr) 254static int is_byt_cr(struct device *dev, bool *bytcr)
244{ 255{
245 int status = 0; 256 int status = 0;
246 257
247 if (IS_ENABLED(CONFIG_IOSF_MBI)) { 258 if (IS_ENABLED(CONFIG_IOSF_MBI)) {
248 static const struct x86_cpu_id cpu_ids[] = {
249 { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
250 {}
251 };
252 u32 bios_status; 259 u32 bios_status;
253 260
254 if (!x86_match_cpu(cpu_ids) || !iosf_mbi_available()) { 261 if (!is_byt() || !iosf_mbi_available()) {
255 /* bail silently */ 262 /* bail silently */
256 return status; 263 return status;
257 } 264 }
@@ -285,7 +292,7 @@ static int sst_acpi_probe(struct platform_device *pdev)
285 int ret = 0; 292 int ret = 0;
286 struct intel_sst_drv *ctx; 293 struct intel_sst_drv *ctx;
287 const struct acpi_device_id *id; 294 const struct acpi_device_id *id;
288 struct sst_acpi_mach *mach; 295 struct snd_soc_acpi_mach *mach;
289 struct platform_device *mdev; 296 struct platform_device *mdev;
290 struct platform_device *plat_dev; 297 struct platform_device *plat_dev;
291 struct sst_platform_info *pdata; 298 struct sst_platform_info *pdata;
@@ -297,13 +304,17 @@ static int sst_acpi_probe(struct platform_device *pdev)
297 return -ENODEV; 304 return -ENODEV;
298 dev_dbg(dev, "for %s\n", id->id); 305 dev_dbg(dev, "for %s\n", id->id);
299 306
300 mach = (struct sst_acpi_mach *)id->driver_data; 307 mach = (struct snd_soc_acpi_mach *)id->driver_data;
301 mach = sst_acpi_find_machine(mach); 308 mach = snd_soc_acpi_find_machine(mach);
302 if (mach == NULL) { 309 if (mach == NULL) {
303 dev_err(dev, "No matching machine driver found\n"); 310 dev_err(dev, "No matching machine driver found\n");
304 return -ENODEV; 311 return -ENODEV;
305 } 312 }
306 313
314 if (is_byt())
315 mach->pdata = &byt_rvp_platform_data;
316 else
317 mach->pdata = &chv_platform_data;
307 pdata = mach->pdata; 318 pdata = mach->pdata;
308 319
309 ret = kstrtouint(id->id, 16, &dev_id); 320 ret = kstrtouint(id->id, 16, &dev_id);
@@ -381,286 +392,9 @@ static int sst_acpi_remove(struct platform_device *pdev)
381 return 0; 392 return 0;
382} 393}
383 394
384static unsigned long cht_machine_id;
385
386#define CHT_SURFACE_MACH 1
387#define BYT_THINKPAD_10 2
388
389static int cht_surface_quirk_cb(const struct dmi_system_id *id)
390{
391 cht_machine_id = CHT_SURFACE_MACH;
392 return 1;
393}
394
395static int byt_thinkpad10_quirk_cb(const struct dmi_system_id *id)
396{
397 cht_machine_id = BYT_THINKPAD_10;
398 return 1;
399}
400
401
402static const struct dmi_system_id byt_table[] = {
403 {
404 .callback = byt_thinkpad10_quirk_cb,
405 .matches = {
406 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
407 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad 10"),
408 },
409 },
410 {
411 .callback = byt_thinkpad10_quirk_cb,
412 .matches = {
413 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
414 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad Tablet B"),
415 },
416 },
417 {
418 .callback = byt_thinkpad10_quirk_cb,
419 .matches = {
420 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
421 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Miix 2 10"),
422 },
423 },
424 { }
425};
426
427static const struct dmi_system_id cht_table[] = {
428 {
429 .callback = cht_surface_quirk_cb,
430 .matches = {
431 DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
432 DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"),
433 },
434 },
435 { }
436};
437
438
439static struct sst_acpi_mach cht_surface_mach = {
440 .id = "10EC5640",
441 .drv_name = "cht-bsw-rt5645",
442 .fw_filename = "intel/fw_sst_22a8.bin",
443 .board = "cht-bsw",
444 .pdata = &chv_platform_data,
445};
446
447static struct sst_acpi_mach byt_thinkpad_10 = {
448 .id = "10EC5640",
449 .drv_name = "cht-bsw-rt5672",
450 .fw_filename = "intel/fw_sst_0f28.bin",
451 .board = "cht-bsw",
452 .pdata = &byt_rvp_platform_data,
453};
454
455static struct sst_acpi_mach *cht_quirk(void *arg)
456{
457 struct sst_acpi_mach *mach = arg;
458
459 dmi_check_system(cht_table);
460
461 if (cht_machine_id == CHT_SURFACE_MACH)
462 return &cht_surface_mach;
463 else
464 return mach;
465}
466
467static struct sst_acpi_mach *byt_quirk(void *arg)
468{
469 struct sst_acpi_mach *mach = arg;
470
471 dmi_check_system(byt_table);
472
473 if (cht_machine_id == BYT_THINKPAD_10)
474 return &byt_thinkpad_10;
475 else
476 return mach;
477}
478
479
480static struct sst_acpi_mach sst_acpi_bytcr[] = {
481 {
482 .id = "10EC5640",
483 .drv_name = "bytcr_rt5640",
484 .fw_filename = "intel/fw_sst_0f28.bin",
485 .board = "bytcr_rt5640",
486 .machine_quirk = byt_quirk,
487 .pdata = &byt_rvp_platform_data,
488 },
489 {
490 .id = "10EC5642",
491 .drv_name = "bytcr_rt5640",
492 .fw_filename = "intel/fw_sst_0f28.bin",
493 .board = "bytcr_rt5640",
494 .pdata = &byt_rvp_platform_data
495 },
496 {
497 .id = "INTCCFFD",
498 .drv_name = "bytcr_rt5640",
499 .fw_filename = "intel/fw_sst_0f28.bin",
500 .board = "bytcr_rt5640",
501 .pdata = &byt_rvp_platform_data
502 },
503 {
504 .id = "10EC5651",
505 .drv_name = "bytcr_rt5651",
506 .fw_filename = "intel/fw_sst_0f28.bin",
507 .board = "bytcr_rt5651",
508 .pdata = &byt_rvp_platform_data
509 },
510 {
511 .id = "DLGS7212",
512 .drv_name = "bytcht_da7213",
513 .fw_filename = "intel/fw_sst_0f28.bin",
514 .board = "bytcht_da7213",
515 .pdata = &byt_rvp_platform_data
516 },
517 {
518 .id = "DLGS7213",
519 .drv_name = "bytcht_da7213",
520 .fw_filename = "intel/fw_sst_0f28.bin",
521 .board = "bytcht_da7213",
522 .pdata = &byt_rvp_platform_data
523 },
524 /* some Baytrail platforms rely on RT5645, use CHT machine driver */
525 {
526 .id = "10EC5645",
527 .drv_name = "cht-bsw-rt5645",
528 .fw_filename = "intel/fw_sst_0f28.bin",
529 .board = "cht-bsw",
530 .pdata = &byt_rvp_platform_data
531 },
532 {
533 .id = "10EC5648",
534 .drv_name = "cht-bsw-rt5645",
535 .fw_filename = "intel/fw_sst_0f28.bin",
536 .board = "cht-bsw",
537 .pdata = &byt_rvp_platform_data
538 },
539#if IS_ENABLED(CONFIG_SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH)
540 /*
541 * This is always last in the table so that it is selected only when
542 * enabled explicitly and there is no codec-related information in SSDT
543 */
544 {
545 .id = "80860F28",
546 .drv_name = "bytcht_nocodec",
547 .fw_filename = "intel/fw_sst_0f28.bin",
548 .board = "bytcht_nocodec",
549 .pdata = &byt_rvp_platform_data
550 },
551#endif
552 {},
553};
554
555/* Cherryview-based platforms: CherryTrail and Braswell */
556static struct sst_acpi_mach sst_acpi_chv[] = {
557 {
558 .id = "10EC5670",
559 .drv_name = "cht-bsw-rt5672",
560 .fw_filename = "intel/fw_sst_22a8.bin",
561 .board = "cht-bsw",
562 .pdata = &chv_platform_data
563 },
564 {
565 .id = "10EC5672",
566 .drv_name = "cht-bsw-rt5672",
567 .fw_filename = "intel/fw_sst_22a8.bin",
568 .board = "cht-bsw",
569 .pdata = &chv_platform_data
570 },
571 {
572 .id = "10EC5645",
573 .drv_name = "cht-bsw-rt5645",
574 .fw_filename = "intel/fw_sst_22a8.bin",
575 .board = "cht-bsw",
576 .pdata = &chv_platform_data
577 },
578 {
579 .id = "10EC5650",
580 .drv_name = "cht-bsw-rt5645",
581 .fw_filename = "intel/fw_sst_22a8.bin",
582 .board = "cht-bsw",
583 .pdata = &chv_platform_data
584 },
585 {
586 .id = "10EC3270",
587 .drv_name = "cht-bsw-rt5645",
588 .fw_filename = "intel/fw_sst_22a8.bin",
589 .board = "cht-bsw",
590 .pdata = &chv_platform_data
591 },
592
593 {
594 .id = "193C9890",
595 .drv_name = "cht-bsw-max98090",
596 .fw_filename = "intel/fw_sst_22a8.bin",
597 .board = "cht-bsw",
598 .pdata = &chv_platform_data
599 },
600 {
601 .id = "DLGS7212",
602 .drv_name = "bytcht_da7213",
603 .fw_filename = "intel/fw_sst_22a8.bin",
604 .board = "bytcht_da7213",
605 .pdata = &chv_platform_data
606 },
607 {
608 .id = "DLGS7213",
609 .drv_name = "bytcht_da7213",
610 .fw_filename = "intel/fw_sst_22a8.bin",
611 .board = "bytcht_da7213",
612 .pdata = &chv_platform_data
613 },
614 {
615 .id = "ESSX8316",
616 .drv_name = "bytcht_es8316",
617 .fw_filename = "intel/fw_sst_22a8.bin",
618 .board = "bytcht_es8316",
619 .pdata = &chv_platform_data
620 },
621 /* some CHT-T platforms rely on RT5640, use Baytrail machine driver */
622 {
623 .id = "10EC5640",
624 .drv_name = "bytcr_rt5640",
625 .fw_filename = "intel/fw_sst_22a8.bin",
626 .board = "bytcr_rt5640",
627 .machine_quirk = cht_quirk,
628 .pdata = &chv_platform_data
629 },
630 {
631 .id = "10EC3276",
632 .drv_name = "bytcr_rt5640",
633 .fw_filename = "intel/fw_sst_22a8.bin",
634 .board = "bytcr_rt5640",
635 .pdata = &chv_platform_data
636 },
637 /* some CHT-T platforms rely on RT5651, use Baytrail machine driver */
638 {
639 .id = "10EC5651",
640 .drv_name = "bytcr_rt5651",
641 .fw_filename = "intel/fw_sst_22a8.bin",
642 .board = "bytcr_rt5651",
643 .pdata = &chv_platform_data
644 },
645#if IS_ENABLED(CONFIG_SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH)
646 /*
647 * This is always last in the table so that it is selected only when
648 * enabled explicitly and there is no codec-related information in SSDT
649 */
650 {
651 .id = "808622A8",
652 .drv_name = "bytcht_nocodec",
653 .fw_filename = "intel/fw_sst_22a8.bin",
654 .board = "bytcht_nocodec",
655 .pdata = &chv_platform_data
656 },
657#endif
658 {},
659};
660
661static const struct acpi_device_id sst_acpi_ids[] = { 395static const struct acpi_device_id sst_acpi_ids[] = {
662 { "80860F28", (unsigned long)&sst_acpi_bytcr}, 396 { "80860F28", (unsigned long)&snd_soc_acpi_intel_baytrail_machines},
663 { "808622A8", (unsigned long) &sst_acpi_chv}, 397 { "808622A8", (unsigned long)&snd_soc_acpi_intel_cherrytrail_machines},
664 { }, 398 { },
665}; 399};
666 400
diff --git a/sound/soc/intel/atom/sst/sst_loader.c b/sound/soc/intel/atom/sst/sst_loader.c
index 33917146d9c4..a686eef2cf7f 100644
--- a/sound/soc/intel/atom/sst/sst_loader.c
+++ b/sound/soc/intel/atom/sst/sst_loader.c
@@ -415,7 +415,6 @@ int sst_load_fw(struct intel_sst_drv *sst_drv_ctx)
415 return ret_val; 415 return ret_val;
416 } 416 }
417 417
418 BUG_ON(!sst_drv_ctx->fw_in_mem);
419 block = sst_create_block(sst_drv_ctx, 0, FW_DWNL_ID); 418 block = sst_create_block(sst_drv_ctx, 0, FW_DWNL_ID);
420 if (block == NULL) 419 if (block == NULL)
421 return -ENOMEM; 420 return -ENOMEM;
diff --git a/sound/soc/intel/atom/sst/sst_stream.c b/sound/soc/intel/atom/sst/sst_stream.c
index 83d8dda15233..65e257b17a7e 100644
--- a/sound/soc/intel/atom/sst/sst_stream.c
+++ b/sound/soc/intel/atom/sst/sst_stream.c
@@ -45,7 +45,6 @@ int sst_alloc_stream_mrfld(struct intel_sst_drv *sst_drv_ctx, void *params)
45 void *data = NULL; 45 void *data = NULL;
46 46
47 dev_dbg(sst_drv_ctx->dev, "Enter\n"); 47 dev_dbg(sst_drv_ctx->dev, "Enter\n");
48 BUG_ON(!params);
49 48
50 str_params = (struct snd_sst_params *)params; 49 str_params = (struct snd_sst_params *)params;
51 memset(&alloc_param, 0, sizeof(alloc_param)); 50 memset(&alloc_param, 0, sizeof(alloc_param));
diff --git a/sound/soc/intel/boards/Kconfig b/sound/soc/intel/boards/Kconfig
new file mode 100644
index 000000000000..6f754708a48c
--- /dev/null
+++ b/sound/soc/intel/boards/Kconfig
@@ -0,0 +1,265 @@
1config SND_SOC_INTEL_MACH
2 tristate "Intel Audio machine drivers"
3 depends on SND_SOC_INTEL_SST_TOPLEVEL
4 select SND_SOC_ACPI_INTEL_MATCH if ACPI
5
6if SND_SOC_INTEL_MACH
7
8config SND_MFLD_MACHINE
9 tristate "SOC Machine Audio driver for Intel Medfield MID platform"
10 depends on INTEL_SCU_IPC
11 select SND_SOC_SN95031
12 depends on SND_SST_ATOM_HIFI2_PLATFORM
13 select SND_SST_IPC_PCI
14 help
15 This adds support for ASoC machine driver for Intel(R) MID Medfield platform
16 used as alsa device in audio substem in Intel(R) MID devices
17 Say Y if you have such a device.
18 If unsure select "N".
19
20config SND_SOC_INTEL_HASWELL_MACH
21 tristate "ASoC Audio DSP support for Intel Haswell Lynxpoint"
22 depends on X86_INTEL_LPSS && I2C && I2C_DESIGNWARE_PLATFORM
23 depends on SND_SOC_INTEL_HASWELL
24 select SND_SOC_RT5640
25 help
26 This adds support for the Lynxpoint Audio DSP on Intel(R) Haswell
27 Ultrabook platforms.
28 Say Y if you have such a device.
29 If unsure select "N".
30
31config SND_SOC_INTEL_BDW_RT5677_MACH
32 tristate "ASoC Audio driver for Intel Broadwell with RT5677 codec"
33 depends on X86_INTEL_LPSS && GPIOLIB && I2C
34 depends on SND_SOC_INTEL_HASWELL
35 select SND_SOC_RT5677
36 help
37 This adds support for Intel Broadwell platform based boards with
38 the RT5677 audio codec.
39
40config SND_SOC_INTEL_BROADWELL_MACH
41 tristate "ASoC Audio DSP support for Intel Broadwell Wildcatpoint"
42 depends on X86_INTEL_LPSS && I2C && I2C_DESIGNWARE_PLATFORM
43 depends on SND_SOC_INTEL_HASWELL
44 select SND_SOC_RT286
45 help
46 This adds support for the Wilcatpoint Audio DSP on Intel(R) Broadwell
47 Ultrabook platforms.
48 Say Y if you have such a device.
49 If unsure select "N".
50
51config SND_SOC_INTEL_BYT_MAX98090_MACH
52 tristate "ASoC Audio driver for Intel Baytrail with MAX98090 codec"
53 depends on X86_INTEL_LPSS && I2C
54 depends on SND_SST_IPC_ACPI = n
55 depends on SND_SOC_INTEL_BAYTRAIL
56 select SND_SOC_MAX98090
57 help
58 This adds audio driver for Intel Baytrail platform based boards
59 with the MAX98090 audio codec.
60
61config SND_SOC_INTEL_BYT_RT5640_MACH
62 tristate "ASoC Audio driver for Intel Baytrail with RT5640 codec"
63 depends on X86_INTEL_LPSS && I2C
64 depends on SND_SST_IPC_ACPI = n
65 depends on SND_SOC_INTEL_BAYTRAIL
66 select SND_SOC_RT5640
67 help
68 This adds audio driver for Intel Baytrail platform based boards
69 with the RT5640 audio codec. This driver is deprecated, use
70 SND_SOC_INTEL_BYTCR_RT5640_MACH instead for better functionality.
71
72config SND_SOC_INTEL_BYTCR_RT5640_MACH
73 tristate "ASoC Audio driver for Intel Baytrail and Baytrail-CR with RT5640 codec"
74 depends on X86 && I2C && ACPI
75 select SND_SOC_RT5640
76 depends on SND_SST_ATOM_HIFI2_PLATFORM
77 select SND_SST_IPC_ACPI
78 help
79 This adds support for ASoC machine driver for Intel(R) Baytrail and Baytrail-CR
80 platforms with RT5640 audio codec.
81 Say Y if you have such a device.
82 If unsure select "N".
83
84config SND_SOC_INTEL_BYTCR_RT5651_MACH
85 tristate "ASoC Audio driver for Intel Baytrail and Baytrail-CR with RT5651 codec"
86 depends on X86 && I2C && ACPI
87 select SND_SOC_RT5651
88 depends on SND_SST_ATOM_HIFI2_PLATFORM
89 select SND_SST_IPC_ACPI
90 help
91 This adds support for ASoC machine driver for Intel(R) Baytrail and Baytrail-CR
92 platforms with RT5651 audio codec.
93 Say Y if you have such a device.
94 If unsure select "N".
95
96config SND_SOC_INTEL_CHT_BSW_RT5672_MACH
97 tristate "ASoC Audio driver for Intel Cherrytrail & Braswell with RT5672 codec"
98 depends on X86_INTEL_LPSS && I2C && ACPI
99 select SND_SOC_RT5670
100 depends on SND_SST_ATOM_HIFI2_PLATFORM
101 select SND_SST_IPC_ACPI
102 help
103 This adds support for ASoC machine driver for Intel(R) Cherrytrail & Braswell
104 platforms with RT5672 audio codec.
105 Say Y if you have such a device.
106 If unsure select "N".
107
108config SND_SOC_INTEL_CHT_BSW_RT5645_MACH
109 tristate "ASoC Audio driver for Intel Cherrytrail & Braswell with RT5645/5650 codec"
110 depends on X86_INTEL_LPSS && I2C && ACPI
111 select SND_SOC_RT5645
112 depends on SND_SST_ATOM_HIFI2_PLATFORM
113 select SND_SST_IPC_ACPI
114 help
115 This adds support for ASoC machine driver for Intel(R) Cherrytrail & Braswell
116 platforms with RT5645/5650 audio codec.
117 If unsure select "N".
118
119config SND_SOC_INTEL_CHT_BSW_MAX98090_TI_MACH
120 tristate "ASoC Audio driver for Intel Cherrytrail & Braswell with MAX98090 & TI codec"
121 depends on X86_INTEL_LPSS && I2C && ACPI
122 select SND_SOC_MAX98090
123 select SND_SOC_TS3A227E
124 depends on SND_SST_ATOM_HIFI2_PLATFORM
125 select SND_SST_IPC_ACPI
126 help
127 This adds support for ASoC machine driver for Intel(R) Cherrytrail & Braswell
128 platforms with MAX98090 audio codec it also can support TI jack chip as aux device.
129 If unsure select "N".
130
131config SND_SOC_INTEL_BYT_CHT_DA7213_MACH
132 tristate "ASoC Audio driver for Intel Baytrail & Cherrytrail with DA7212/7213 codec"
133 depends on X86_INTEL_LPSS && I2C && ACPI
134 select SND_SOC_DA7213
135 depends on SND_SST_ATOM_HIFI2_PLATFORM
136 select SND_SST_IPC_ACPI
137 help
138 This adds support for ASoC machine driver for Intel(R) Baytrail & CherryTrail
139 platforms with DA7212/7213 audio codec.
140 If unsure select "N".
141
142config SND_SOC_INTEL_BYT_CHT_ES8316_MACH
143 tristate "ASoC Audio driver for Intel Baytrail & Cherrytrail with ES8316 codec"
144 depends on X86_INTEL_LPSS && I2C && ACPI
145 select SND_SOC_ES8316
146 depends on SND_SST_ATOM_HIFI2_PLATFORM
147 select SND_SST_IPC_ACPI
148 help
149 This adds support for ASoC machine driver for Intel(R) Baytrail &
150 Cherrytrail platforms with ES8316 audio codec.
151 If unsure select "N".
152
153config SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH
154 tristate "ASoC Audio driver for Intel Baytrail & Cherrytrail platform with no codec (MinnowBoard MAX, Up)"
155 depends on X86_INTEL_LPSS && I2C && ACPI
156 depends on SND_SST_ATOM_HIFI2_PLATFORM
157 select SND_SST_IPC_ACPI
158 help
159 This adds support for ASoC machine driver for the MinnowBoard Max or
160 Up boards and provides access to I2S signals on the Low-Speed
161 connector
162 If unsure select "N".
163
164config SND_SOC_INTEL_SKL_RT286_MACH
165 tristate "ASoC Audio driver for SKL with RT286 I2S mode"
166 depends on X86 && ACPI && I2C
167 depends on SND_SOC_INTEL_SKYLAKE
168 select SND_SOC_RT286
169 select SND_SOC_DMIC
170 select SND_SOC_HDAC_HDMI
171 help
172 This adds support for ASoC machine driver for Skylake platforms
173 with RT286 I2S audio codec.
174 Say Y if you have such a device.
175 If unsure select "N".
176
177config SND_SOC_INTEL_SKL_NAU88L25_SSM4567_MACH
178 tristate "ASoC Audio driver for SKL with NAU88L25 and SSM4567 in I2S Mode"
179 depends on X86_INTEL_LPSS && I2C
180 depends on SND_SOC_INTEL_SKYLAKE
181 select SND_SOC_NAU8825
182 select SND_SOC_SSM4567
183 select SND_SOC_DMIC
184 select SND_SOC_HDAC_HDMI
185 help
186 This adds support for ASoC Onboard Codec I2S machine driver. This will
187 create an alsa sound card for NAU88L25 + SSM4567.
188 Say Y if you have such a device.
189 If unsure select "N".
190
191config SND_SOC_INTEL_SKL_NAU88L25_MAX98357A_MACH
192 tristate "ASoC Audio driver for SKL with NAU88L25 and MAX98357A in I2S Mode"
193 depends on X86_INTEL_LPSS && I2C
194 depends on SND_SOC_INTEL_SKYLAKE
195 select SND_SOC_NAU8825
196 select SND_SOC_MAX98357A
197 select SND_SOC_DMIC
198 select SND_SOC_HDAC_HDMI
199 help
200 This adds support for ASoC Onboard Codec I2S machine driver. This will
201 create an alsa sound card for NAU88L25 + MAX98357A.
202 Say Y if you have such a device.
203 If unsure select "N".
204
205config SND_SOC_INTEL_BXT_DA7219_MAX98357A_MACH
206 tristate "ASoC Audio driver for Broxton with DA7219 and MAX98357A in I2S Mode"
207 depends on X86 && ACPI && I2C
208 depends on SND_SOC_INTEL_SKYLAKE
209 select SND_SOC_DA7219
210 select SND_SOC_MAX98357A
211 select SND_SOC_DMIC
212 select SND_SOC_HDAC_HDMI
213 select SND_HDA_DSP_LOADER
214 help
215 This adds support for ASoC machine driver for Broxton-P platforms
216 with DA7219 + MAX98357A I2S audio codec.
217 Say Y if you have such a device.
218 If unsure select "N".
219
220config SND_SOC_INTEL_BXT_RT298_MACH
221 tristate "ASoC Audio driver for Broxton with RT298 I2S mode"
222 depends on X86 && ACPI && I2C
223 depends on SND_SOC_INTEL_SKYLAKE
224 select SND_SOC_RT298
225 select SND_SOC_DMIC
226 select SND_SOC_HDAC_HDMI
227 select SND_HDA_DSP_LOADER
228 help
229 This adds support for ASoC machine driver for Broxton platforms
230 with RT286 I2S audio codec.
231 Say Y if you have such a device.
232 If unsure select "N".
233
234config SND_SOC_INTEL_KBL_RT5663_MAX98927_MACH
235 tristate "ASoC Audio driver for KBL with RT5663 and MAX98927 in I2S Mode"
236 depends on X86_INTEL_LPSS && I2C
237 select SND_SOC_INTEL_SST
238 depends on SND_SOC_INTEL_SKYLAKE
239 select SND_SOC_RT5663
240 select SND_SOC_MAX98927
241 select SND_SOC_DMIC
242 select SND_SOC_HDAC_HDMI
243 help
244 This adds support for ASoC Onboard Codec I2S machine driver. This will
245 create an alsa sound card for RT5663 + MAX98927.
246 Say Y if you have such a device.
247 If unsure select "N".
248
249config SND_SOC_INTEL_KBL_RT5663_RT5514_MAX98927_MACH
250 tristate "ASoC Audio driver for KBL with RT5663, RT5514 and MAX98927 in I2S Mode"
251 depends on X86_INTEL_LPSS && I2C && SPI
252 select SND_SOC_INTEL_SST
253 depends on SND_SOC_INTEL_SKYLAKE
254 select SND_SOC_RT5663
255 select SND_SOC_RT5514
256 select SND_SOC_RT5514_SPI
257 select SND_SOC_MAX98927
258 select SND_SOC_HDAC_HDMI
259 help
260 This adds support for ASoC Onboard Codec I2S machine driver. This will
261 create an alsa sound card for RT5663 + RT5514 + MAX98927.
262 Say Y if you have such a device.
263 If unsure select "N".
264
265endif
diff --git a/sound/soc/intel/boards/bxt_da7219_max98357a.c b/sound/soc/intel/boards/bxt_da7219_max98357a.c
index ce35ec7884d1..f8a91a6f2a17 100644
--- a/sound/soc/intel/boards/bxt_da7219_max98357a.c
+++ b/sound/soc/intel/boards/bxt_da7219_max98357a.c
@@ -55,20 +55,6 @@ enum {
55 BXT_DPCM_AUDIO_HDMI3_PB, 55 BXT_DPCM_AUDIO_HDMI3_PB,
56}; 56};
57 57
58static inline struct snd_soc_dai *bxt_get_codec_dai(struct snd_soc_card *card)
59{
60 struct snd_soc_pcm_runtime *rtd;
61
62 list_for_each_entry(rtd, &card->rtd_list, list) {
63
64 if (!strncmp(rtd->codec_dai->name, BXT_DIALOG_CODEC_DAI,
65 strlen(BXT_DIALOG_CODEC_DAI)))
66 return rtd->codec_dai;
67 }
68
69 return NULL;
70}
71
72static int platform_clock_control(struct snd_soc_dapm_widget *w, 58static int platform_clock_control(struct snd_soc_dapm_widget *w,
73 struct snd_kcontrol *k, int event) 59 struct snd_kcontrol *k, int event)
74{ 60{
@@ -77,7 +63,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
77 struct snd_soc_card *card = dapm->card; 63 struct snd_soc_card *card = dapm->card;
78 struct snd_soc_dai *codec_dai; 64 struct snd_soc_dai *codec_dai;
79 65
80 codec_dai = bxt_get_codec_dai(card); 66 codec_dai = snd_soc_card_get_codec_dai(card, BXT_DIALOG_CODEC_DAI);
81 if (!codec_dai) { 67 if (!codec_dai) {
82 dev_err(card->dev, "Codec dai not found; Unable to set/unset codec pll\n"); 68 dev_err(card->dev, "Codec dai not found; Unable to set/unset codec pll\n");
83 return -EIO; 69 return -EIO;
diff --git a/sound/soc/intel/boards/bytcht_da7213.c b/sound/soc/intel/boards/bytcht_da7213.c
index 18873e23f404..c4d82ad41bd7 100644
--- a/sound/soc/intel/boards/bytcht_da7213.c
+++ b/sound/soc/intel/boards/bytcht_da7213.c
@@ -27,9 +27,9 @@
27#include <sound/pcm.h> 27#include <sound/pcm.h>
28#include <sound/pcm_params.h> 28#include <sound/pcm_params.h>
29#include <sound/soc.h> 29#include <sound/soc.h>
30#include <sound/soc-acpi.h>
30#include "../../codecs/da7213.h" 31#include "../../codecs/da7213.h"
31#include "../atom/sst-atom-controls.h" 32#include "../atom/sst-atom-controls.h"
32#include "../common/sst-acpi.h"
33 33
34static const struct snd_kcontrol_new controls[] = { 34static const struct snd_kcontrol_new controls[] = {
35 SOC_DAPM_PIN_SWITCH("Headphone Jack"), 35 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
@@ -185,19 +185,11 @@ static struct snd_soc_dai_link dailink[] = {
185 .dpcm_playback = 1, 185 .dpcm_playback = 1,
186 .ops = &aif1_ops, 186 .ops = &aif1_ops,
187 }, 187 },
188 [MERR_DPCM_COMPR] = {
189 .name = "Compressed Port",
190 .stream_name = "Compress",
191 .cpu_dai_name = "compress-cpu-dai",
192 .codec_dai_name = "snd-soc-dummy-dai",
193 .codec_name = "snd-soc-dummy",
194 .platform_name = "sst-mfld-platform",
195 },
196 /* CODEC<->CODEC link */ 188 /* CODEC<->CODEC link */
197 /* back ends */ 189 /* back ends */
198 { 190 {
199 .name = "SSP2-Codec", 191 .name = "SSP2-Codec",
200 .id = 1, 192 .id = 0,
201 .cpu_dai_name = "ssp2-port", 193 .cpu_dai_name = "ssp2-port",
202 .platform_name = "sst-mfld-platform", 194 .platform_name = "sst-mfld-platform",
203 .no_pcm = 1, 195 .no_pcm = 1,
@@ -231,19 +223,18 @@ static char codec_name[16]; /* i2c-<HID>:00 with HID being 8 chars */
231 223
232static int bytcht_da7213_probe(struct platform_device *pdev) 224static int bytcht_da7213_probe(struct platform_device *pdev)
233{ 225{
234 int ret_val = 0;
235 int i;
236 struct snd_soc_card *card; 226 struct snd_soc_card *card;
237 struct sst_acpi_mach *mach; 227 struct snd_soc_acpi_mach *mach;
238 const char *i2c_name = NULL; 228 const char *i2c_name = NULL;
239 int dai_index = 0; 229 int dai_index = 0;
230 int ret_val = 0;
231 int i;
240 232
241 mach = (&pdev->dev)->platform_data; 233 mach = (&pdev->dev)->platform_data;
242 card = &bytcht_da7213_card; 234 card = &bytcht_da7213_card;
243 card->dev = &pdev->dev; 235 card->dev = &pdev->dev;
244 236
245 /* fix index of codec dai */ 237 /* fix index of codec dai */
246 dai_index = MERR_DPCM_COMPR + 1;
247 for (i = 0; i < ARRAY_SIZE(dailink); i++) { 238 for (i = 0; i < ARRAY_SIZE(dailink); i++) {
248 if (!strcmp(dailink[i].codec_name, "i2c-DLGS7213:00")) { 239 if (!strcmp(dailink[i].codec_name, "i2c-DLGS7213:00")) {
249 dai_index = i; 240 dai_index = i;
@@ -252,8 +243,8 @@ static int bytcht_da7213_probe(struct platform_device *pdev)
252 } 243 }
253 244
254 /* fixup codec name based on HID */ 245 /* fixup codec name based on HID */
255 i2c_name = sst_acpi_find_name_from_hid(mach->id); 246 i2c_name = snd_soc_acpi_find_name_from_hid(mach->id);
256 if (i2c_name != NULL) { 247 if (i2c_name) {
257 snprintf(codec_name, sizeof(codec_name), 248 snprintf(codec_name, sizeof(codec_name),
258 "%s%s", "i2c-", i2c_name); 249 "%s%s", "i2c-", i2c_name);
259 dailink[dai_index].codec_name = codec_name; 250 dailink[dai_index].codec_name = codec_name;
diff --git a/sound/soc/intel/boards/bytcht_es8316.c b/sound/soc/intel/boards/bytcht_es8316.c
index 52635462dac6..8088396717e3 100644
--- a/sound/soc/intel/boards/bytcht_es8316.c
+++ b/sound/soc/intel/boards/bytcht_es8316.c
@@ -29,28 +29,14 @@
29#include <sound/pcm.h> 29#include <sound/pcm.h>
30#include <sound/pcm_params.h> 30#include <sound/pcm_params.h>
31#include <sound/soc.h> 31#include <sound/soc.h>
32#include <sound/soc-acpi.h>
32#include "../atom/sst-atom-controls.h" 33#include "../atom/sst-atom-controls.h"
33#include "../common/sst-acpi.h"
34#include "../common/sst-dsp.h" 34#include "../common/sst-dsp.h"
35 35
36struct byt_cht_es8316_private { 36struct byt_cht_es8316_private {
37 struct clk *mclk; 37 struct clk *mclk;
38}; 38};
39 39
40#define CODEC_DAI1 "ES8316 HiFi"
41
42static inline struct snd_soc_dai *get_codec_dai(struct snd_soc_card *card)
43{
44 struct snd_soc_pcm_runtime *rtd;
45
46 list_for_each_entry(rtd, &card->rtd_list, list) {
47 if (!strncmp(rtd->codec_dai->name, CODEC_DAI1,
48 strlen(CODEC_DAI1)))
49 return rtd->codec_dai;
50 }
51 return NULL;
52}
53
54static const struct snd_soc_dapm_widget byt_cht_es8316_widgets[] = { 40static const struct snd_soc_dapm_widget byt_cht_es8316_widgets[] = {
55 SND_SOC_DAPM_HP("Headphone", NULL), 41 SND_SOC_DAPM_HP("Headphone", NULL),
56 42
@@ -208,22 +194,13 @@ static struct snd_soc_dai_link byt_cht_es8316_dais[] = {
208 .ops = &byt_cht_es8316_aif1_ops, 194 .ops = &byt_cht_es8316_aif1_ops,
209 }, 195 },
210 196
211 [MERR_DPCM_COMPR] = {
212 .name = "Compressed Port",
213 .stream_name = "Compress",
214 .cpu_dai_name = "compress-cpu-dai",
215 .codec_dai_name = "snd-soc-dummy-dai",
216 .codec_name = "snd-soc-dummy",
217 .platform_name = "sst-mfld-platform",
218 },
219
220 /* back ends */ 197 /* back ends */
221 { 198 {
222 /* Only SSP2 has been tested here, so BYT-CR platforms that 199 /* Only SSP2 has been tested here, so BYT-CR platforms that
223 * require SSP0 will not work. 200 * require SSP0 will not work.
224 */ 201 */
225 .name = "SSP2-Codec", 202 .name = "SSP2-Codec",
226 .id = 1, 203 .id = 0,
227 .cpu_dai_name = "ssp2-port", 204 .cpu_dai_name = "ssp2-port",
228 .platform_name = "sst-mfld-platform", 205 .platform_name = "sst-mfld-platform",
229 .no_pcm = 1, 206 .no_pcm = 1,
diff --git a/sound/soc/intel/boards/bytcht_nocodec.c b/sound/soc/intel/boards/bytcht_nocodec.c
index 1dd9441806fa..b80ec027a0e8 100644
--- a/sound/soc/intel/boards/bytcht_nocodec.c
+++ b/sound/soc/intel/boards/bytcht_nocodec.c
@@ -133,19 +133,11 @@ static struct snd_soc_dai_link dais[] = {
133 .dpcm_playback = 1, 133 .dpcm_playback = 1,
134 .ops = &aif1_ops, 134 .ops = &aif1_ops,
135 }, 135 },
136 [MERR_DPCM_COMPR] = {
137 .name = "Compressed Port",
138 .stream_name = "Compress",
139 .cpu_dai_name = "compress-cpu-dai",
140 .codec_dai_name = "snd-soc-dummy-dai",
141 .codec_name = "snd-soc-dummy",
142 .platform_name = "sst-mfld-platform",
143 },
144 /* CODEC<->CODEC link */ 136 /* CODEC<->CODEC link */
145 /* back ends */ 137 /* back ends */
146 { 138 {
147 .name = "SSP2-LowSpeed Connector", 139 .name = "SSP2-LowSpeed Connector",
148 .id = 1, 140 .id = 0,
149 .cpu_dai_name = "ssp2-port", 141 .cpu_dai_name = "ssp2-port",
150 .platform_name = "sst-mfld-platform", 142 .platform_name = "sst-mfld-platform",
151 .no_pcm = 1, 143 .no_pcm = 1,
diff --git a/sound/soc/intel/boards/bytcr_rt5640.c b/sound/soc/intel/boards/bytcr_rt5640.c
index 4a76b099a508..f2c0fc415e52 100644
--- a/sound/soc/intel/boards/bytcr_rt5640.c
+++ b/sound/soc/intel/boards/bytcr_rt5640.c
@@ -22,19 +22,19 @@
22#include <linux/moduleparam.h> 22#include <linux/moduleparam.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/acpi.h> 24#include <linux/acpi.h>
25#include <linux/clk.h>
25#include <linux/device.h> 26#include <linux/device.h>
26#include <linux/dmi.h> 27#include <linux/dmi.h>
27#include <linux/slab.h> 28#include <linux/slab.h>
28#include <asm/cpu_device_id.h> 29#include <asm/cpu_device_id.h>
29#include <asm/platform_sst_audio.h> 30#include <asm/platform_sst_audio.h>
30#include <linux/clk.h>
31#include <sound/pcm.h> 31#include <sound/pcm.h>
32#include <sound/pcm_params.h> 32#include <sound/pcm_params.h>
33#include <sound/soc.h> 33#include <sound/soc.h>
34#include <sound/jack.h> 34#include <sound/jack.h>
35#include <sound/soc-acpi.h>
35#include "../../codecs/rt5640.h" 36#include "../../codecs/rt5640.h"
36#include "../atom/sst-atom-controls.h" 37#include "../atom/sst-atom-controls.h"
37#include "../common/sst-acpi.h"
38#include "../common/sst-dsp.h" 38#include "../common/sst-dsp.h"
39 39
40enum { 40enum {
@@ -44,13 +44,13 @@ enum {
44 BYT_RT5640_IN3_MAP, 44 BYT_RT5640_IN3_MAP,
45}; 45};
46 46
47#define BYT_RT5640_MAP(quirk) ((quirk) & 0xff) 47#define BYT_RT5640_MAP(quirk) ((quirk) & GENMASK(7, 0))
48#define BYT_RT5640_DMIC_EN BIT(16) 48#define BYT_RT5640_DMIC_EN BIT(16)
49#define BYT_RT5640_MONO_SPEAKER BIT(17) 49#define BYT_RT5640_MONO_SPEAKER BIT(17)
50#define BYT_RT5640_DIFF_MIC BIT(18) /* defaut is single-ended */ 50#define BYT_RT5640_DIFF_MIC BIT(18) /* defaut is single-ended */
51#define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */ 51#define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */
52#define BYT_RT5640_SSP0_AIF1 BIT(20) 52#define BYT_RT5640_SSP0_AIF1 BIT(20)
53#define BYT_RT5640_SSP0_AIF2 BIT(21) 53#define BYT_RT5640_SSP0_AIF2 BIT(21)
54#define BYT_RT5640_MCLK_EN BIT(22) 54#define BYT_RT5640_MCLK_EN BIT(22)
55#define BYT_RT5640_MCLK_25MHZ BIT(23) 55#define BYT_RT5640_MCLK_25MHZ BIT(23)
56 56
@@ -145,22 +145,6 @@ static void log_quirks(struct device *dev)
145#define BYT_CODEC_DAI1 "rt5640-aif1" 145#define BYT_CODEC_DAI1 "rt5640-aif1"
146#define BYT_CODEC_DAI2 "rt5640-aif2" 146#define BYT_CODEC_DAI2 "rt5640-aif2"
147 147
148static inline struct snd_soc_dai *byt_get_codec_dai(struct snd_soc_card *card)
149{
150 struct snd_soc_pcm_runtime *rtd;
151
152 list_for_each_entry(rtd, &card->rtd_list, list) {
153 if (!strncmp(rtd->codec_dai->name, BYT_CODEC_DAI1,
154 strlen(BYT_CODEC_DAI1)))
155 return rtd->codec_dai;
156 if (!strncmp(rtd->codec_dai->name, BYT_CODEC_DAI2,
157 strlen(BYT_CODEC_DAI2)))
158 return rtd->codec_dai;
159
160 }
161 return NULL;
162}
163
164static int platform_clock_control(struct snd_soc_dapm_widget *w, 148static int platform_clock_control(struct snd_soc_dapm_widget *w,
165 struct snd_kcontrol *k, int event) 149 struct snd_kcontrol *k, int event)
166{ 150{
@@ -170,7 +154,10 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
170 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card); 154 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
171 int ret; 155 int ret;
172 156
173 codec_dai = byt_get_codec_dai(card); 157 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1);
158 if (!codec_dai)
159 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI2);
160
174 if (!codec_dai) { 161 if (!codec_dai) {
175 dev_err(card->dev, 162 dev_err(card->dev,
176 "Codec dai not found; Unable to set platform clock\n"); 163 "Codec dai not found; Unable to set platform clock\n");
@@ -178,7 +165,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
178 } 165 }
179 166
180 if (SND_SOC_DAPM_EVENT_ON(event)) { 167 if (SND_SOC_DAPM_EVENT_ON(event)) {
181 if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && priv->mclk) { 168 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
182 ret = clk_prepare_enable(priv->mclk); 169 ret = clk_prepare_enable(priv->mclk);
183 if (ret < 0) { 170 if (ret < 0) {
184 dev_err(card->dev, 171 dev_err(card->dev,
@@ -199,7 +186,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
199 48000 * 512, 186 48000 * 512,
200 SND_SOC_CLOCK_IN); 187 SND_SOC_CLOCK_IN);
201 if (!ret) { 188 if (!ret) {
202 if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && priv->mclk) 189 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
203 clk_disable_unprepare(priv->mclk); 190 clk_disable_unprepare(priv->mclk);
204 } 191 }
205 } 192 }
@@ -376,8 +363,8 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = {
376 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), 363 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
377 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"), 364 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
378 }, 365 },
379 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP | 366 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
380 BYT_RT5640_MCLK_EN), 367 BYT_RT5640_MCLK_EN),
381 }, 368 },
382 { 369 {
383 .callback = byt_rt5640_quirk_cb, 370 .callback = byt_rt5640_quirk_cb,
@@ -385,12 +372,11 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = {
385 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), 372 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
386 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"), 373 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
387 }, 374 },
388 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP | 375 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
389 BYT_RT5640_MONO_SPEAKER | 376 BYT_RT5640_MONO_SPEAKER |
390 BYT_RT5640_DIFF_MIC | 377 BYT_RT5640_DIFF_MIC |
391 BYT_RT5640_SSP0_AIF2 | 378 BYT_RT5640_SSP0_AIF2 |
392 BYT_RT5640_MCLK_EN 379 BYT_RT5640_MCLK_EN),
393 ),
394 }, 380 },
395 { 381 {
396 .callback = byt_rt5640_quirk_cb, 382 .callback = byt_rt5640_quirk_cb,
@@ -398,9 +384,9 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = {
398 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "DellInc."), 384 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "DellInc."),
399 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"), 385 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
400 }, 386 },
401 .driver_data = (unsigned long *)(BYT_RT5640_DMIC2_MAP | 387 .driver_data = (void *)(BYT_RT5640_DMIC2_MAP |
402 BYT_RT5640_DMIC_EN | 388 BYT_RT5640_DMIC_EN |
403 BYT_RT5640_MCLK_EN), 389 BYT_RT5640_MCLK_EN),
404 }, 390 },
405 { 391 {
406 .callback = byt_rt5640_quirk_cb, 392 .callback = byt_rt5640_quirk_cb,
@@ -408,8 +394,8 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = {
408 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), 394 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
409 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"), 395 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
410 }, 396 },
411 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP | 397 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
412 BYT_RT5640_MCLK_EN), 398 BYT_RT5640_MCLK_EN),
413 }, 399 },
414 { 400 {
415 .callback = byt_rt5640_quirk_cb, 401 .callback = byt_rt5640_quirk_cb,
@@ -417,8 +403,8 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = {
417 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"), 403 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
418 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"), 404 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
419 }, 405 },
420 .driver_data = (unsigned long *)(BYT_RT5640_DMIC1_MAP | 406 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
421 BYT_RT5640_DMIC_EN), 407 BYT_RT5640_DMIC_EN),
422 }, 408 },
423 { 409 {
424 .callback = byt_rt5640_quirk_cb, 410 .callback = byt_rt5640_quirk_cb,
@@ -426,9 +412,9 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = {
426 DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"), 412 DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
427 DMI_MATCH(DMI_BOARD_NAME, "tPAD"), 413 DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
428 }, 414 },
429 .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | 415 .driver_data = (void *)(BYT_RT5640_IN3_MAP |
430 BYT_RT5640_MCLK_EN | 416 BYT_RT5640_MCLK_EN |
431 BYT_RT5640_SSP0_AIF1), 417 BYT_RT5640_SSP0_AIF1),
432 }, 418 },
433 { 419 {
434 .callback = byt_rt5640_quirk_cb, 420 .callback = byt_rt5640_quirk_cb,
@@ -436,7 +422,7 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = {
436 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 422 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
437 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"), 423 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
438 }, 424 },
439 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP | 425 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
440 BYT_RT5640_MCLK_EN | 426 BYT_RT5640_MCLK_EN |
441 BYT_RT5640_SSP0_AIF1), 427 BYT_RT5640_SSP0_AIF1),
442 428
@@ -446,9 +432,9 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = {
446 .matches = { 432 .matches = {
447 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"), 433 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
448 }, 434 },
449 .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP | 435 .driver_data = (void *)(BYT_RT5640_IN3_MAP |
450 BYT_RT5640_MCLK_EN | 436 BYT_RT5640_MCLK_EN |
451 BYT_RT5640_SSP0_AIF1), 437 BYT_RT5640_SSP0_AIF1),
452 438
453 }, 439 },
454 {} 440 {}
@@ -456,12 +442,12 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = {
456 442
457static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime) 443static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
458{ 444{
459 int ret;
460 struct snd_soc_codec *codec = runtime->codec;
461 struct snd_soc_card *card = runtime->card; 445 struct snd_soc_card *card = runtime->card;
462 const struct snd_soc_dapm_route *custom_map;
463 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card); 446 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
447 struct snd_soc_codec *codec = runtime->codec;
448 const struct snd_soc_dapm_route *custom_map;
464 int num_routes; 449 int num_routes;
450 int ret;
465 451
466 card->dapm.idle_bias_off = true; 452 card->dapm.idle_bias_off = true;
467 453
@@ -549,7 +535,7 @@ static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
549 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone"); 535 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
550 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker"); 536 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
551 537
552 if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && priv->mclk) { 538 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
553 /* 539 /*
554 * The firmware might enable the clock at 540 * The firmware might enable the clock at
555 * boot (this information may or may not 541 * boot (this information may or may not
@@ -693,18 +679,10 @@ static struct snd_soc_dai_link byt_rt5640_dais[] = {
693 .dpcm_playback = 1, 679 .dpcm_playback = 1,
694 .ops = &byt_rt5640_aif1_ops, 680 .ops = &byt_rt5640_aif1_ops,
695 }, 681 },
696 [MERR_DPCM_COMPR] = {
697 .name = "Baytrail Compressed Port",
698 .stream_name = "Baytrail Compress",
699 .cpu_dai_name = "compress-cpu-dai",
700 .codec_dai_name = "snd-soc-dummy-dai",
701 .codec_name = "snd-soc-dummy",
702 .platform_name = "sst-mfld-platform",
703 },
704 /* back ends */ 682 /* back ends */
705 { 683 {
706 .name = "SSP2-Codec", 684 .name = "SSP2-Codec",
707 .id = 1, 685 .id = 0,
708 .cpu_dai_name = "ssp2-port", /* overwritten for ssp0 routing */ 686 .cpu_dai_name = "ssp2-port", /* overwritten for ssp0 routing */
709 .platform_name = "sst-mfld-platform", 687 .platform_name = "sst-mfld-platform",
710 .no_pcm = 1, 688 .no_pcm = 1,
@@ -758,12 +736,12 @@ struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
758 736
759static int snd_byt_rt5640_mc_probe(struct platform_device *pdev) 737static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
760{ 738{
761 int ret_val = 0; 739 struct byt_rt5640_private *priv;
762 struct sst_acpi_mach *mach; 740 struct snd_soc_acpi_mach *mach;
763 const char *i2c_name = NULL; 741 const char *i2c_name = NULL;
742 int ret_val = 0;
743 int dai_index = 0;
764 int i; 744 int i;
765 int dai_index;
766 struct byt_rt5640_private *priv;
767 745
768 is_bytcr = false; 746 is_bytcr = false;
769 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_ATOMIC); 747 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_ATOMIC);
@@ -776,7 +754,6 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
776 snd_soc_card_set_drvdata(&byt_rt5640_card, priv); 754 snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
777 755
778 /* fix index of codec dai */ 756 /* fix index of codec dai */
779 dai_index = MERR_DPCM_COMPR + 1;
780 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) { 757 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
781 if (!strcmp(byt_rt5640_dais[i].codec_name, "i2c-10EC5640:00")) { 758 if (!strcmp(byt_rt5640_dais[i].codec_name, "i2c-10EC5640:00")) {
782 dai_index = i; 759 dai_index = i;
@@ -785,8 +762,8 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
785 } 762 }
786 763
787 /* fixup codec name based on HID */ 764 /* fixup codec name based on HID */
788 i2c_name = sst_acpi_find_name_from_hid(mach->id); 765 i2c_name = snd_soc_acpi_find_name_from_hid(mach->id);
789 if (i2c_name != NULL) { 766 if (i2c_name) {
790 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name), 767 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
791 "%s%s", "i2c-", i2c_name); 768 "%s%s", "i2c-", i2c_name);
792 769
@@ -819,7 +796,7 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
819 /* format specified: 2 64-bit integers */ 796 /* format specified: 2 64-bit integers */
820 struct acpi_buffer format = {sizeof("NN"), "NN"}; 797 struct acpi_buffer format = {sizeof("NN"), "NN"};
821 struct acpi_buffer state = {0, NULL}; 798 struct acpi_buffer state = {0, NULL};
822 struct sst_acpi_package_context pkg_ctx; 799 struct snd_soc_acpi_package_context pkg_ctx;
823 bool pkg_found = false; 800 bool pkg_found = false;
824 801
825 state.length = sizeof(chan_package); 802 state.length = sizeof(chan_package);
@@ -831,7 +808,8 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
831 pkg_ctx.state = &state; 808 pkg_ctx.state = &state;
832 pkg_ctx.data_valid = false; 809 pkg_ctx.data_valid = false;
833 810
834 pkg_found = sst_acpi_find_package_from_hid(mach->id, &pkg_ctx); 811 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id,
812 &pkg_ctx);
835 if (pkg_found) { 813 if (pkg_found) {
836 if (chan_package.aif_value == 1) { 814 if (chan_package.aif_value == 1) {
837 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n"); 815 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
@@ -891,7 +869,7 @@ static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
891 byt_rt5640_cpu_dai_name; 869 byt_rt5640_cpu_dai_name;
892 } 870 }
893 871
894 if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && (is_valleyview())) { 872 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
895 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3"); 873 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
896 if (IS_ERR(priv->mclk)) { 874 if (IS_ERR(priv->mclk)) {
897 ret_val = PTR_ERR(priv->mclk); 875 ret_val = PTR_ERR(priv->mclk);
diff --git a/sound/soc/intel/boards/bytcr_rt5651.c b/sound/soc/intel/boards/bytcr_rt5651.c
index 4a3516b38c2c..d955836c6870 100644
--- a/sound/soc/intel/boards/bytcr_rt5651.c
+++ b/sound/soc/intel/boards/bytcr_rt5651.c
@@ -21,24 +21,124 @@
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/acpi.h> 23#include <linux/acpi.h>
24#include <linux/clk.h>
24#include <linux/device.h> 25#include <linux/device.h>
25#include <linux/dmi.h> 26#include <linux/dmi.h>
26#include <linux/slab.h> 27#include <linux/slab.h>
28#include <asm/platform_sst_audio.h>
27#include <sound/pcm.h> 29#include <sound/pcm.h>
28#include <sound/pcm_params.h> 30#include <sound/pcm_params.h>
29#include <sound/soc.h> 31#include <sound/soc.h>
30#include <sound/jack.h> 32#include <sound/jack.h>
33#include <sound/soc-acpi.h>
31#include "../../codecs/rt5651.h" 34#include "../../codecs/rt5651.h"
32#include "../atom/sst-atom-controls.h" 35#include "../atom/sst-atom-controls.h"
33 36
37enum {
38 BYT_RT5651_DMIC_MAP,
39 BYT_RT5651_IN1_MAP,
40 BYT_RT5651_IN2_MAP,
41};
42
43#define BYT_RT5651_MAP(quirk) ((quirk) & GENMASK(7, 0))
44#define BYT_RT5651_DMIC_EN BIT(16)
45#define BYT_RT5651_MCLK_EN BIT(17)
46#define BYT_RT5651_MCLK_25MHZ BIT(18)
47
48struct byt_rt5651_private {
49 struct clk *mclk;
50 struct snd_soc_jack jack;
51};
52
53static unsigned long byt_rt5651_quirk = BYT_RT5651_DMIC_MAP |
54 BYT_RT5651_DMIC_EN |
55 BYT_RT5651_MCLK_EN;
56
57static void log_quirks(struct device *dev)
58{
59 if (BYT_RT5651_MAP(byt_rt5651_quirk) == BYT_RT5651_DMIC_MAP)
60 dev_info(dev, "quirk DMIC_MAP enabled");
61 if (BYT_RT5651_MAP(byt_rt5651_quirk) == BYT_RT5651_IN1_MAP)
62 dev_info(dev, "quirk IN1_MAP enabled");
63 if (BYT_RT5651_MAP(byt_rt5651_quirk) == BYT_RT5651_IN2_MAP)
64 dev_info(dev, "quirk IN2_MAP enabled");
65 if (byt_rt5651_quirk & BYT_RT5651_DMIC_EN)
66 dev_info(dev, "quirk DMIC enabled");
67 if (byt_rt5651_quirk & BYT_RT5651_MCLK_EN)
68 dev_info(dev, "quirk MCLK_EN enabled");
69 if (byt_rt5651_quirk & BYT_RT5651_MCLK_25MHZ)
70 dev_info(dev, "quirk MCLK_25MHZ enabled");
71}
72
73#define BYT_CODEC_DAI1 "rt5651-aif1"
74
75static int platform_clock_control(struct snd_soc_dapm_widget *w,
76 struct snd_kcontrol *k, int event)
77{
78 struct snd_soc_dapm_context *dapm = w->dapm;
79 struct snd_soc_card *card = dapm->card;
80 struct snd_soc_dai *codec_dai;
81 struct byt_rt5651_private *priv = snd_soc_card_get_drvdata(card);
82 int ret;
83
84 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1);
85 if (!codec_dai) {
86 dev_err(card->dev,
87 "Codec dai not found; Unable to set platform clock\n");
88 return -EIO;
89 }
90
91 if (SND_SOC_DAPM_EVENT_ON(event)) {
92 if (byt_rt5651_quirk & BYT_RT5651_MCLK_EN) {
93 ret = clk_prepare_enable(priv->mclk);
94 if (ret < 0) {
95 dev_err(card->dev,
96 "could not configure MCLK state");
97 return ret;
98 }
99 }
100 ret = snd_soc_dai_set_sysclk(codec_dai, RT5651_SCLK_S_PLL1,
101 48000 * 512,
102 SND_SOC_CLOCK_IN);
103 } else {
104 /*
105 * Set codec clock source to internal clock before
106 * turning off the platform clock. Codec needs clock
107 * for Jack detection and button press
108 */
109 ret = snd_soc_dai_set_sysclk(codec_dai, RT5651_SCLK_S_RCCLK,
110 48000 * 512,
111 SND_SOC_CLOCK_IN);
112 if (!ret)
113 if (byt_rt5651_quirk & BYT_RT5651_MCLK_EN)
114 clk_disable_unprepare(priv->mclk);
115 }
116
117 if (ret < 0) {
118 dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
119 return ret;
120 }
121
122 return 0;
123}
124
34static const struct snd_soc_dapm_widget byt_rt5651_widgets[] = { 125static const struct snd_soc_dapm_widget byt_rt5651_widgets[] = {
35 SND_SOC_DAPM_HP("Headphone", NULL), 126 SND_SOC_DAPM_HP("Headphone", NULL),
36 SND_SOC_DAPM_MIC("Headset Mic", NULL), 127 SND_SOC_DAPM_MIC("Headset Mic", NULL),
37 SND_SOC_DAPM_MIC("Internal Mic", NULL), 128 SND_SOC_DAPM_MIC("Internal Mic", NULL),
38 SND_SOC_DAPM_SPK("Speaker", NULL), 129 SND_SOC_DAPM_SPK("Speaker", NULL),
130 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
131 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
132 SND_SOC_DAPM_POST_PMD),
133
39}; 134};
40 135
41static const struct snd_soc_dapm_route byt_rt5651_audio_map[] = { 136static const struct snd_soc_dapm_route byt_rt5651_audio_map[] = {
137 {"Headphone", NULL, "Platform Clock"},
138 {"Headset Mic", NULL, "Platform Clock"},
139 {"Internal Mic", NULL, "Platform Clock"},
140 {"Speaker", NULL, "Platform Clock"},
141
42 {"AIF1 Playback", NULL, "ssp2 Tx"}, 142 {"AIF1 Playback", NULL, "ssp2 Tx"},
43 {"ssp2 Tx", NULL, "codec_out0"}, 143 {"ssp2 Tx", NULL, "codec_out0"},
44 {"ssp2 Tx", NULL, "codec_out1"}, 144 {"ssp2 Tx", NULL, "codec_out1"},
@@ -47,38 +147,30 @@ static const struct snd_soc_dapm_route byt_rt5651_audio_map[] = {
47 {"ssp2 Rx", NULL, "AIF1 Capture"}, 147 {"ssp2 Rx", NULL, "AIF1 Capture"},
48 148
49 {"Headset Mic", NULL, "micbias1"}, /* lowercase for rt5651 */ 149 {"Headset Mic", NULL, "micbias1"}, /* lowercase for rt5651 */
50 {"IN2P", NULL, "Headset Mic"},
51 {"Headphone", NULL, "HPOL"}, 150 {"Headphone", NULL, "HPOL"},
52 {"Headphone", NULL, "HPOR"}, 151 {"Headphone", NULL, "HPOR"},
53 {"Speaker", NULL, "LOUTL"}, 152 {"Speaker", NULL, "LOUTL"},
54 {"Speaker", NULL, "LOUTR"}, 153 {"Speaker", NULL, "LOUTR"},
55}; 154};
56 155
57static const struct snd_soc_dapm_route byt_rt5651_intmic_dmic1_map[] = { 156static const struct snd_soc_dapm_route byt_rt5651_intmic_dmic_map[] = {
58 {"DMIC1", NULL, "Internal Mic"}, 157 {"IN2P", NULL, "Headset Mic"},
59}; 158 {"DMIC L1", NULL, "Internal Mic"},
60 159 {"DMIC R1", NULL, "Internal Mic"},
61static const struct snd_soc_dapm_route byt_rt5651_intmic_dmic2_map[] = {
62 {"DMIC2", NULL, "Internal Mic"},
63}; 160};
64 161
65static const struct snd_soc_dapm_route byt_rt5651_intmic_in1_map[] = { 162static const struct snd_soc_dapm_route byt_rt5651_intmic_in1_map[] = {
66 {"Internal Mic", NULL, "micbias1"}, 163 {"Internal Mic", NULL, "micbias1"},
164 {"IN2P", NULL, "Headset Mic"},
67 {"IN1P", NULL, "Internal Mic"}, 165 {"IN1P", NULL, "Internal Mic"},
68}; 166};
69 167
70enum { 168static const struct snd_soc_dapm_route byt_rt5651_intmic_in2_map[] = {
71 BYT_RT5651_DMIC1_MAP, 169 {"Internal Mic", NULL, "micbias1"},
72 BYT_RT5651_DMIC2_MAP, 170 {"IN1P", NULL, "Headset Mic"},
73 BYT_RT5651_IN1_MAP, 171 {"IN2P", NULL, "Internal Mic"},
74}; 172};
75 173
76#define BYT_RT5651_MAP(quirk) ((quirk) & 0xff)
77#define BYT_RT5651_DMIC_EN BIT(16)
78
79static unsigned long byt_rt5651_quirk = BYT_RT5651_DMIC1_MAP |
80 BYT_RT5651_DMIC_EN;
81
82static const struct snd_kcontrol_new byt_rt5651_controls[] = { 174static const struct snd_kcontrol_new byt_rt5651_controls[] = {
83 SOC_DAPM_PIN_SWITCH("Headphone"), 175 SOC_DAPM_PIN_SWITCH("Headphone"),
84 SOC_DAPM_PIN_SWITCH("Headset Mic"), 176 SOC_DAPM_PIN_SWITCH("Headset Mic"),
@@ -86,6 +178,17 @@ static const struct snd_kcontrol_new byt_rt5651_controls[] = {
86 SOC_DAPM_PIN_SWITCH("Speaker"), 178 SOC_DAPM_PIN_SWITCH("Speaker"),
87}; 179};
88 180
181static struct snd_soc_jack_pin bytcr_jack_pins[] = {
182 {
183 .pin = "Headphone",
184 .mask = SND_JACK_HEADPHONE,
185 },
186 {
187 .pin = "Headset Mic",
188 .mask = SND_JACK_MICROPHONE,
189 },
190};
191
89static int byt_rt5651_aif1_hw_params(struct snd_pcm_substream *substream, 192static int byt_rt5651_aif1_hw_params(struct snd_pcm_substream *substream,
90 struct snd_pcm_hw_params *params) 193 struct snd_pcm_hw_params *params)
91{ 194{
@@ -103,9 +206,26 @@ static int byt_rt5651_aif1_hw_params(struct snd_pcm_substream *substream,
103 return ret; 206 return ret;
104 } 207 }
105 208
106 ret = snd_soc_dai_set_pll(codec_dai, 0, RT5651_PLL1_S_BCLK1, 209 if (!(byt_rt5651_quirk & BYT_RT5651_MCLK_EN)) {
107 params_rate(params) * 50, 210 /* 2x25 bit slots on SSP2 */
108 params_rate(params) * 512); 211 ret = snd_soc_dai_set_pll(codec_dai, 0,
212 RT5651_PLL1_S_BCLK1,
213 params_rate(params) * 50,
214 params_rate(params) * 512);
215 } else {
216 if (byt_rt5651_quirk & BYT_RT5651_MCLK_25MHZ) {
217 ret = snd_soc_dai_set_pll(codec_dai, 0,
218 RT5651_PLL1_S_MCLK,
219 25000000,
220 params_rate(params) * 512);
221 } else {
222 ret = snd_soc_dai_set_pll(codec_dai, 0,
223 RT5651_PLL1_S_MCLK,
224 19200000,
225 params_rate(params) * 512);
226 }
227 }
228
109 if (ret < 0) { 229 if (ret < 0) {
110 dev_err(rtd->dev, "can't set codec pll: %d\n", ret); 230 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
111 return ret; 231 return ret;
@@ -114,33 +234,60 @@ static int byt_rt5651_aif1_hw_params(struct snd_pcm_substream *substream,
114 return 0; 234 return 0;
115} 235}
116 236
237static int byt_rt5651_quirk_cb(const struct dmi_system_id *id)
238{
239 byt_rt5651_quirk = (unsigned long)id->driver_data;
240 return 1;
241}
242
117static const struct dmi_system_id byt_rt5651_quirk_table[] = { 243static const struct dmi_system_id byt_rt5651_quirk_table[] = {
244 {
245 .callback = byt_rt5651_quirk_cb,
246 .matches = {
247 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
248 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
249 },
250 .driver_data = (void *)(BYT_RT5651_DMIC_MAP |
251 BYT_RT5651_DMIC_EN),
252 },
253 {
254 .callback = byt_rt5651_quirk_cb,
255 .matches = {
256 DMI_MATCH(DMI_SYS_VENDOR, "KIANO"),
257 DMI_MATCH(DMI_PRODUCT_NAME, "KIANO SlimNote 14.2"),
258 },
259 .driver_data = (void *)(BYT_RT5651_IN2_MAP),
260 },
118 {} 261 {}
119}; 262};
120 263
121static int byt_rt5651_init(struct snd_soc_pcm_runtime *runtime) 264static int byt_rt5651_init(struct snd_soc_pcm_runtime *runtime)
122{ 265{
123 int ret;
124 struct snd_soc_card *card = runtime->card; 266 struct snd_soc_card *card = runtime->card;
267 struct snd_soc_codec *codec = runtime->codec;
268 struct byt_rt5651_private *priv = snd_soc_card_get_drvdata(card);
125 const struct snd_soc_dapm_route *custom_map; 269 const struct snd_soc_dapm_route *custom_map;
126 int num_routes; 270 int num_routes;
271 int ret;
127 272
128 card->dapm.idle_bias_off = true; 273 card->dapm.idle_bias_off = true;
129 274
130 dmi_check_system(byt_rt5651_quirk_table);
131 switch (BYT_RT5651_MAP(byt_rt5651_quirk)) { 275 switch (BYT_RT5651_MAP(byt_rt5651_quirk)) {
132 case BYT_RT5651_IN1_MAP: 276 case BYT_RT5651_IN1_MAP:
133 custom_map = byt_rt5651_intmic_in1_map; 277 custom_map = byt_rt5651_intmic_in1_map;
134 num_routes = ARRAY_SIZE(byt_rt5651_intmic_in1_map); 278 num_routes = ARRAY_SIZE(byt_rt5651_intmic_in1_map);
135 break; 279 break;
136 case BYT_RT5651_DMIC2_MAP: 280 case BYT_RT5651_IN2_MAP:
137 custom_map = byt_rt5651_intmic_dmic2_map; 281 custom_map = byt_rt5651_intmic_in2_map;
138 num_routes = ARRAY_SIZE(byt_rt5651_intmic_dmic2_map); 282 num_routes = ARRAY_SIZE(byt_rt5651_intmic_in2_map);
139 break; 283 break;
140 default: 284 default:
141 custom_map = byt_rt5651_intmic_dmic1_map; 285 custom_map = byt_rt5651_intmic_dmic_map;
142 num_routes = ARRAY_SIZE(byt_rt5651_intmic_dmic1_map); 286 num_routes = ARRAY_SIZE(byt_rt5651_intmic_dmic_map);
143 } 287 }
288 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
289 if (ret)
290 return ret;
144 291
145 ret = snd_soc_add_card_controls(card, byt_rt5651_controls, 292 ret = snd_soc_add_card_controls(card, byt_rt5651_controls,
146 ARRAY_SIZE(byt_rt5651_controls)); 293 ARRAY_SIZE(byt_rt5651_controls));
@@ -151,6 +298,40 @@ static int byt_rt5651_init(struct snd_soc_pcm_runtime *runtime)
151 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone"); 298 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
152 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker"); 299 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
153 300
301 if (byt_rt5651_quirk & BYT_RT5651_MCLK_EN) {
302 /*
303 * The firmware might enable the clock at
304 * boot (this information may or may not
305 * be reflected in the enable clock register).
306 * To change the rate we must disable the clock
307 * first to cover these cases. Due to common
308 * clock framework restrictions that do not allow
309 * to disable a clock that has not been enabled,
310 * we need to enable the clock first.
311 */
312 ret = clk_prepare_enable(priv->mclk);
313 if (!ret)
314 clk_disable_unprepare(priv->mclk);
315
316 if (byt_rt5651_quirk & BYT_RT5651_MCLK_25MHZ)
317 ret = clk_set_rate(priv->mclk, 25000000);
318 else
319 ret = clk_set_rate(priv->mclk, 19200000);
320
321 if (ret)
322 dev_err(card->dev, "unable to set MCLK rate\n");
323 }
324
325 ret = snd_soc_card_jack_new(runtime->card, "Headset",
326 SND_JACK_HEADSET, &priv->jack,
327 bytcr_jack_pins, ARRAY_SIZE(bytcr_jack_pins));
328 if (ret) {
329 dev_err(runtime->dev, "Headset jack creation failed %d\n", ret);
330 return ret;
331 }
332
333 rt5651_set_jack_detect(codec, &priv->jack);
334
154 return ret; 335 return ret;
155} 336}
156 337
@@ -253,19 +434,11 @@ static struct snd_soc_dai_link byt_rt5651_dais[] = {
253 .dpcm_playback = 1, 434 .dpcm_playback = 1,
254 .ops = &byt_rt5651_aif1_ops, 435 .ops = &byt_rt5651_aif1_ops,
255 }, 436 },
256 [MERR_DPCM_COMPR] = {
257 .name = "Compressed Port",
258 .stream_name = "Compress",
259 .cpu_dai_name = "compress-cpu-dai",
260 .codec_dai_name = "snd-soc-dummy-dai",
261 .codec_name = "snd-soc-dummy",
262 .platform_name = "sst-mfld-platform",
263 },
264 /* CODEC<->CODEC link */ 437 /* CODEC<->CODEC link */
265 /* back ends */ 438 /* back ends */
266 { 439 {
267 .name = "SSP2-Codec", 440 .name = "SSP2-Codec",
268 .id = 1, 441 .id = 0,
269 .cpu_dai_name = "ssp2-port", 442 .cpu_dai_name = "ssp2-port",
270 .platform_name = "sst-mfld-platform", 443 .platform_name = "sst-mfld-platform",
271 .no_pcm = 1, 444 .no_pcm = 1,
@@ -296,13 +469,65 @@ static struct snd_soc_card byt_rt5651_card = {
296 .fully_routed = true, 469 .fully_routed = true,
297}; 470};
298 471
472static char byt_rt5651_codec_name[16]; /* i2c-<HID>:00 with HID being 8 chars */
473
299static int snd_byt_rt5651_mc_probe(struct platform_device *pdev) 474static int snd_byt_rt5651_mc_probe(struct platform_device *pdev)
300{ 475{
476 struct byt_rt5651_private *priv;
477 struct snd_soc_acpi_mach *mach;
478 const char *i2c_name = NULL;
301 int ret_val = 0; 479 int ret_val = 0;
480 int dai_index = 0;
481 int i;
482
483 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_ATOMIC);
484 if (!priv)
485 return -ENOMEM;
302 486
303 /* register the soc card */ 487 /* register the soc card */
304 byt_rt5651_card.dev = &pdev->dev; 488 byt_rt5651_card.dev = &pdev->dev;
305 489
490 mach = byt_rt5651_card.dev->platform_data;
491 snd_soc_card_set_drvdata(&byt_rt5651_card, priv);
492
493 /* fix index of codec dai */
494 for (i = 0; i < ARRAY_SIZE(byt_rt5651_dais); i++) {
495 if (!strcmp(byt_rt5651_dais[i].codec_name, "i2c-10EC5651:00")) {
496 dai_index = i;
497 break;
498 }
499 }
500
501 /* fixup codec name based on HID */
502 i2c_name = snd_soc_acpi_find_name_from_hid(mach->id);
503 if (i2c_name) {
504 snprintf(byt_rt5651_codec_name, sizeof(byt_rt5651_codec_name),
505 "%s%s", "i2c-", i2c_name);
506
507 byt_rt5651_dais[dai_index].codec_name = byt_rt5651_codec_name;
508 }
509
510 /* check quirks before creating card */
511 dmi_check_system(byt_rt5651_quirk_table);
512 log_quirks(&pdev->dev);
513
514 if (byt_rt5651_quirk & BYT_RT5651_MCLK_EN) {
515 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
516 if (IS_ERR(priv->mclk)) {
517 dev_err(&pdev->dev,
518 "Failed to get MCLK from pmc_plt_clk_3: %ld\n",
519 PTR_ERR(priv->mclk));
520 /*
521 * Fall back to bit clock usage for -ENOENT (clock not
522 * available likely due to missing dependencies), bail
523 * for all other errors, including -EPROBE_DEFER
524 */
525 if (ret_val != -ENOENT)
526 return ret_val;
527 byt_rt5651_quirk &= ~BYT_RT5651_MCLK_EN;
528 }
529 }
530
306 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5651_card); 531 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5651_card);
307 532
308 if (ret_val) { 533 if (ret_val) {
diff --git a/sound/soc/intel/boards/cht_bsw_max98090_ti.c b/sound/soc/intel/boards/cht_bsw_max98090_ti.c
index 20755ecc7f9e..d3e1c7e12004 100644
--- a/sound/soc/intel/boards/cht_bsw_max98090_ti.c
+++ b/sound/soc/intel/boards/cht_bsw_max98090_ti.c
@@ -23,6 +23,7 @@
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/acpi.h> 25#include <linux/acpi.h>
26#include <linux/clk.h>
26#include <sound/pcm.h> 27#include <sound/pcm.h>
27#include <sound/pcm_params.h> 28#include <sound/pcm_params.h>
28#include <sound/soc.h> 29#include <sound/soc.h>
@@ -35,15 +36,48 @@
35#define CHT_CODEC_DAI "HiFi" 36#define CHT_CODEC_DAI "HiFi"
36 37
37struct cht_mc_private { 38struct cht_mc_private {
39 struct clk *mclk;
38 struct snd_soc_jack jack; 40 struct snd_soc_jack jack;
39 bool ts3a227e_present; 41 bool ts3a227e_present;
40}; 42};
41 43
44static int platform_clock_control(struct snd_soc_dapm_widget *w,
45 struct snd_kcontrol *k, int event)
46{
47 struct snd_soc_dapm_context *dapm = w->dapm;
48 struct snd_soc_card *card = dapm->card;
49 struct snd_soc_dai *codec_dai;
50 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card);
51 int ret;
52
53 codec_dai = snd_soc_card_get_codec_dai(card, CHT_CODEC_DAI);
54 if (!codec_dai) {
55 dev_err(card->dev, "Codec dai not found; Unable to set platform clock\n");
56 return -EIO;
57 }
58
59 if (SND_SOC_DAPM_EVENT_ON(event)) {
60 ret = clk_prepare_enable(ctx->mclk);
61 if (ret < 0) {
62 dev_err(card->dev,
63 "could not configure MCLK state");
64 return ret;
65 }
66 } else {
67 clk_disable_unprepare(ctx->mclk);
68 }
69
70 return 0;
71}
72
42static const struct snd_soc_dapm_widget cht_dapm_widgets[] = { 73static const struct snd_soc_dapm_widget cht_dapm_widgets[] = {
43 SND_SOC_DAPM_HP("Headphone", NULL), 74 SND_SOC_DAPM_HP("Headphone", NULL),
44 SND_SOC_DAPM_MIC("Headset Mic", NULL), 75 SND_SOC_DAPM_MIC("Headset Mic", NULL),
45 SND_SOC_DAPM_MIC("Int Mic", NULL), 76 SND_SOC_DAPM_MIC("Int Mic", NULL),
46 SND_SOC_DAPM_SPK("Ext Spk", NULL), 77 SND_SOC_DAPM_SPK("Ext Spk", NULL),
78 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
79 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
80 SND_SOC_DAPM_POST_PMD),
47}; 81};
48 82
49static const struct snd_soc_dapm_route cht_audio_map[] = { 83static const struct snd_soc_dapm_route cht_audio_map[] = {
@@ -60,6 +94,10 @@ static const struct snd_soc_dapm_route cht_audio_map[] = {
60 {"codec_in0", NULL, "ssp2 Rx" }, 94 {"codec_in0", NULL, "ssp2 Rx" },
61 {"codec_in1", NULL, "ssp2 Rx" }, 95 {"codec_in1", NULL, "ssp2 Rx" },
62 {"ssp2 Rx", NULL, "HiFi Capture"}, 96 {"ssp2 Rx", NULL, "HiFi Capture"},
97 {"Headphone", NULL, "Platform Clock"},
98 {"Headset Mic", NULL, "Platform Clock"},
99 {"Int Mic", NULL, "Platform Clock"},
100 {"Ext Spk", NULL, "Platform Clock"},
63}; 101};
64 102
65static const struct snd_kcontrol_new cht_mc_controls[] = { 103static const struct snd_kcontrol_new cht_mc_controls[] = {
@@ -109,6 +147,40 @@ static struct notifier_block cht_jack_nb = {
109 .notifier_call = cht_ti_jack_event, 147 .notifier_call = cht_ti_jack_event,
110}; 148};
111 149
150static struct snd_soc_jack_pin hs_jack_pins[] = {
151 {
152 .pin = "Headphone",
153 .mask = SND_JACK_HEADPHONE,
154 },
155 {
156 .pin = "Headset Mic",
157 .mask = SND_JACK_MICROPHONE,
158 },
159};
160
161static struct snd_soc_jack_gpio hs_jack_gpios[] = {
162 {
163 .name = "hp",
164 .report = SND_JACK_HEADPHONE | SND_JACK_LINEOUT,
165 .debounce_time = 200,
166 },
167 {
168 .name = "mic",
169 .invert = 1,
170 .report = SND_JACK_MICROPHONE,
171 .debounce_time = 200,
172 },
173};
174
175static const struct acpi_gpio_params hp_gpios = { 0, 0, false };
176static const struct acpi_gpio_params mic_gpios = { 1, 0, false };
177
178static const struct acpi_gpio_mapping acpi_max98090_gpios[] = {
179 { "hp-gpios", &hp_gpios, 1 },
180 { "mic-gpios", &mic_gpios, 1 },
181 {},
182};
183
112static int cht_codec_init(struct snd_soc_pcm_runtime *runtime) 184static int cht_codec_init(struct snd_soc_pcm_runtime *runtime)
113{ 185{
114 int ret; 186 int ret;
@@ -116,30 +188,55 @@ static int cht_codec_init(struct snd_soc_pcm_runtime *runtime)
116 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(runtime->card); 188 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(runtime->card);
117 struct snd_soc_jack *jack = &ctx->jack; 189 struct snd_soc_jack *jack = &ctx->jack;
118 190
119 /** 191 if (ctx->ts3a227e_present) {
120 * TI supports 4 butons headset detection 192 /*
121 * KEY_MEDIA 193 * The jack has already been created in the
122 * KEY_VOICECOMMAND 194 * cht_max98090_headset_init() function.
123 * KEY_VOLUMEUP 195 */
124 * KEY_VOLUMEDOWN 196 snd_soc_jack_notifier_register(jack, &cht_jack_nb);
125 */ 197 return 0;
126 if (ctx->ts3a227e_present) 198 }
127 jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE |
128 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
129 SND_JACK_BTN_2 | SND_JACK_BTN_3;
130 else
131 jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE;
132 199
133 ret = snd_soc_card_jack_new(runtime->card, "Headset Jack", 200 jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE;
134 jack_type, jack, NULL, 0);
135 201
202 ret = snd_soc_card_jack_new(runtime->card, "Headset Jack",
203 jack_type, jack,
204 hs_jack_pins, ARRAY_SIZE(hs_jack_pins));
136 if (ret) { 205 if (ret) {
137 dev_err(runtime->dev, "Headset Jack creation failed %d\n", ret); 206 dev_err(runtime->dev, "Headset Jack creation failed %d\n", ret);
138 return ret; 207 return ret;
139 } 208 }
140 209
141 if (ctx->ts3a227e_present) 210 ret = snd_soc_jack_add_gpiods(runtime->card->dev->parent, jack,
142 snd_soc_jack_notifier_register(jack, &cht_jack_nb); 211 ARRAY_SIZE(hs_jack_gpios),
212 hs_jack_gpios);
213 if (ret) {
214 /*
215 * flag error but don't bail if jack detect is broken
216 * due to platform issues or bad BIOS/configuration
217 */
218 dev_err(runtime->dev,
219 "jack detection gpios not added, error %d\n", ret);
220 }
221
222 /*
223 * The firmware might enable the clock at
224 * boot (this information may or may not
225 * be reflected in the enable clock register).
226 * To change the rate we must disable the clock
227 * first to cover these cases. Due to common
228 * clock framework restrictions that do not allow
229 * to disable a clock that has not been enabled,
230 * we need to enable the clock first.
231 */
232 ret = clk_prepare_enable(ctx->mclk);
233 if (!ret)
234 clk_disable_unprepare(ctx->mclk);
235
236 ret = clk_set_rate(ctx->mclk, CHT_PLAT_CLK_3_HZ);
237
238 if (ret)
239 dev_err(runtime->dev, "unable to set MCLK rate\n");
143 240
144 return ret; 241 return ret;
145} 242}
@@ -160,7 +257,7 @@ static int cht_codec_fixup(struct snd_soc_pcm_runtime *rtd,
160 return ret; 257 return ret;
161 } 258 }
162 259
163 fmt = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF 260 fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
164 | SND_SOC_DAIFMT_CBS_CFS; 261 | SND_SOC_DAIFMT_CBS_CFS;
165 262
166 ret = snd_soc_dai_set_fmt(rtd->cpu_dai, fmt); 263 ret = snd_soc_dai_set_fmt(rtd->cpu_dai, fmt);
@@ -173,8 +270,8 @@ static int cht_codec_fixup(struct snd_soc_pcm_runtime *rtd,
173 rate->min = rate->max = 48000; 270 rate->min = rate->max = 48000;
174 channels->min = channels->max = 2; 271 channels->min = channels->max = 2;
175 272
176 /* set SSP2 to 24-bit */ 273 /* set SSP2 to 16-bit */
177 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE); 274 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
178 return 0; 275 return 0;
179} 276}
180 277
@@ -188,8 +285,29 @@ static int cht_max98090_headset_init(struct snd_soc_component *component)
188{ 285{
189 struct snd_soc_card *card = component->card; 286 struct snd_soc_card *card = component->card;
190 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card); 287 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card);
288 struct snd_soc_jack *jack = &ctx->jack;
289 int jack_type;
290 int ret;
191 291
192 return ts3a227e_enable_jack_detect(component, &ctx->jack); 292 /*
293 * TI supports 4 butons headset detection
294 * KEY_MEDIA
295 * KEY_VOICECOMMAND
296 * KEY_VOLUMEUP
297 * KEY_VOLUMEDOWN
298 */
299 jack_type = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE |
300 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
301 SND_JACK_BTN_2 | SND_JACK_BTN_3;
302
303 ret = snd_soc_card_jack_new(card, "Headset Jack", jack_type,
304 jack, NULL, 0);
305 if (ret) {
306 dev_err(card->dev, "Headset Jack creation failed %d\n", ret);
307 return ret;
308 }
309
310 return ts3a227e_enable_jack_detect(component, jack);
193} 311}
194 312
195static const struct snd_soc_ops cht_aif1_ops = { 313static const struct snd_soc_ops cht_aif1_ops = {
@@ -232,18 +350,10 @@ static struct snd_soc_dai_link cht_dailink[] = {
232 .dpcm_playback = 1, 350 .dpcm_playback = 1,
233 .ops = &cht_aif1_ops, 351 .ops = &cht_aif1_ops,
234 }, 352 },
235 [MERR_DPCM_COMPR] = {
236 .name = "Compressed Port",
237 .stream_name = "Compress",
238 .cpu_dai_name = "compress-cpu-dai",
239 .codec_dai_name = "snd-soc-dummy-dai",
240 .codec_name = "snd-soc-dummy",
241 .platform_name = "sst-mfld-platform",
242 },
243 /* back ends */ 353 /* back ends */
244 { 354 {
245 .name = "SSP2-Codec", 355 .name = "SSP2-Codec",
246 .id = 1, 356 .id = 0,
247 .cpu_dai_name = "ssp2-port", 357 .cpu_dai_name = "ssp2-port",
248 .platform_name = "sst-mfld-platform", 358 .platform_name = "sst-mfld-platform",
249 .no_pcm = 1, 359 .no_pcm = 1,
@@ -277,6 +387,7 @@ static struct snd_soc_card snd_soc_card_cht = {
277 387
278static int snd_cht_mc_probe(struct platform_device *pdev) 388static int snd_cht_mc_probe(struct platform_device *pdev)
279{ 389{
390 struct device *dev = &pdev->dev;
280 int ret_val = 0; 391 int ret_val = 0;
281 struct cht_mc_private *drv; 392 struct cht_mc_private *drv;
282 393
@@ -289,11 +400,25 @@ static int snd_cht_mc_probe(struct platform_device *pdev)
289 /* no need probe TI jack detection chip */ 400 /* no need probe TI jack detection chip */
290 snd_soc_card_cht.aux_dev = NULL; 401 snd_soc_card_cht.aux_dev = NULL;
291 snd_soc_card_cht.num_aux_devs = 0; 402 snd_soc_card_cht.num_aux_devs = 0;
403
404 ret_val = devm_acpi_dev_add_driver_gpios(dev->parent,
405 acpi_max98090_gpios);
406 if (ret_val)
407 dev_dbg(dev, "Unable to add GPIO mapping table\n");
292 } 408 }
293 409
294 /* register the soc card */ 410 /* register the soc card */
295 snd_soc_card_cht.dev = &pdev->dev; 411 snd_soc_card_cht.dev = &pdev->dev;
296 snd_soc_card_set_drvdata(&snd_soc_card_cht, drv); 412 snd_soc_card_set_drvdata(&snd_soc_card_cht, drv);
413
414 drv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
415 if (IS_ERR(drv->mclk)) {
416 dev_err(&pdev->dev,
417 "Failed to get MCLK from pmc_plt_clk_3: %ld\n",
418 PTR_ERR(drv->mclk));
419 return PTR_ERR(drv->mclk);
420 }
421
297 ret_val = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_cht); 422 ret_val = devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_cht);
298 if (ret_val) { 423 if (ret_val) {
299 dev_err(&pdev->dev, 424 dev_err(&pdev->dev,
diff --git a/sound/soc/intel/boards/cht_bsw_rt5645.c b/sound/soc/intel/boards/cht_bsw_rt5645.c
index 5bcde01d15e6..18d129caa974 100644
--- a/sound/soc/intel/boards/cht_bsw_rt5645.c
+++ b/sound/soc/intel/boards/cht_bsw_rt5645.c
@@ -21,20 +21,20 @@
21 */ 21 */
22 22
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/acpi.h>
25#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/acpi.h>
26#include <linux/clk.h>
26#include <linux/dmi.h> 27#include <linux/dmi.h>
27#include <linux/slab.h> 28#include <linux/slab.h>
28#include <asm/cpu_device_id.h> 29#include <asm/cpu_device_id.h>
29#include <asm/platform_sst_audio.h> 30#include <asm/platform_sst_audio.h>
30#include <linux/clk.h>
31#include <sound/pcm.h> 31#include <sound/pcm.h>
32#include <sound/pcm_params.h> 32#include <sound/pcm_params.h>
33#include <sound/soc.h> 33#include <sound/soc.h>
34#include <sound/jack.h> 34#include <sound/jack.h>
35#include <sound/soc-acpi.h>
35#include "../../codecs/rt5645.h" 36#include "../../codecs/rt5645.h"
36#include "../atom/sst-atom-controls.h" 37#include "../atom/sst-atom-controls.h"
37#include "../common/sst-acpi.h"
38 38
39#define CHT_PLAT_CLK_3_HZ 19200000 39#define CHT_PLAT_CLK_3_HZ 19200000
40#define CHT_CODEC_DAI1 "rt5645-aif1" 40#define CHT_CODEC_DAI1 "rt5645-aif1"
@@ -53,7 +53,7 @@ struct cht_mc_private {
53 struct clk *mclk; 53 struct clk *mclk;
54}; 54};
55 55
56#define CHT_RT5645_MAP(quirk) ((quirk) & 0xff) 56#define CHT_RT5645_MAP(quirk) ((quirk) & GENMASK(7, 0))
57#define CHT_RT5645_SSP2_AIF2 BIT(16) /* default is using AIF1 */ 57#define CHT_RT5645_SSP2_AIF2 BIT(16) /* default is using AIF1 */
58#define CHT_RT5645_SSP0_AIF1 BIT(17) 58#define CHT_RT5645_SSP0_AIF1 BIT(17)
59#define CHT_RT5645_SSP0_AIF2 BIT(18) 59#define CHT_RT5645_SSP0_AIF2 BIT(18)
@@ -70,21 +70,6 @@ static void log_quirks(struct device *dev)
70 dev_info(dev, "quirk SSP0_AIF2 enabled"); 70 dev_info(dev, "quirk SSP0_AIF2 enabled");
71} 71}
72 72
73static inline struct snd_soc_dai *cht_get_codec_dai(struct snd_soc_card *card)
74{
75 struct snd_soc_pcm_runtime *rtd;
76
77 list_for_each_entry(rtd, &card->rtd_list, list) {
78 if (!strncmp(rtd->codec_dai->name, CHT_CODEC_DAI1,
79 strlen(CHT_CODEC_DAI1)))
80 return rtd->codec_dai;
81 if (!strncmp(rtd->codec_dai->name, CHT_CODEC_DAI2,
82 strlen(CHT_CODEC_DAI2)))
83 return rtd->codec_dai;
84 }
85 return NULL;
86}
87
88static int platform_clock_control(struct snd_soc_dapm_widget *w, 73static int platform_clock_control(struct snd_soc_dapm_widget *w,
89 struct snd_kcontrol *k, int event) 74 struct snd_kcontrol *k, int event)
90{ 75{
@@ -94,20 +79,21 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
94 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card); 79 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card);
95 int ret; 80 int ret;
96 81
97 codec_dai = cht_get_codec_dai(card); 82 codec_dai = snd_soc_card_get_codec_dai(card, CHT_CODEC_DAI1);
83 if (!codec_dai)
84 codec_dai = snd_soc_card_get_codec_dai(card, CHT_CODEC_DAI2);
85
98 if (!codec_dai) { 86 if (!codec_dai) {
99 dev_err(card->dev, "Codec dai not found; Unable to set platform clock\n"); 87 dev_err(card->dev, "Codec dai not found; Unable to set platform clock\n");
100 return -EIO; 88 return -EIO;
101 } 89 }
102 90
103 if (SND_SOC_DAPM_EVENT_ON(event)) { 91 if (SND_SOC_DAPM_EVENT_ON(event)) {
104 if (ctx->mclk) { 92 ret = clk_prepare_enable(ctx->mclk);
105 ret = clk_prepare_enable(ctx->mclk); 93 if (ret < 0) {
106 if (ret < 0) { 94 dev_err(card->dev,
107 dev_err(card->dev, 95 "could not configure MCLK state");
108 "could not configure MCLK state"); 96 return ret;
109 return ret;
110 }
111 } 97 }
112 } else { 98 } else {
113 /* Set codec sysclk source to its internal clock because codec PLL will 99 /* Set codec sysclk source to its internal clock because codec PLL will
@@ -122,8 +108,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
122 return ret; 108 return ret;
123 } 109 }
124 110
125 if (ctx->mclk) 111 clk_disable_unprepare(ctx->mclk);
126 clk_disable_unprepare(ctx->mclk);
127 } 112 }
128 113
129 return 0; 114 return 0;
@@ -258,11 +243,11 @@ static const struct dmi_system_id cht_rt5645_quirk_table[] = {
258 243
259static int cht_codec_init(struct snd_soc_pcm_runtime *runtime) 244static int cht_codec_init(struct snd_soc_pcm_runtime *runtime)
260{ 245{
261 int ret;
262 int jack_type;
263 struct snd_soc_codec *codec = runtime->codec;
264 struct snd_soc_card *card = runtime->card; 246 struct snd_soc_card *card = runtime->card;
265 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(runtime->card); 247 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(runtime->card);
248 struct snd_soc_codec *codec = runtime->codec;
249 int jack_type;
250 int ret;
266 251
267 if ((cht_rt5645_quirk & CHT_RT5645_SSP2_AIF2) || 252 if ((cht_rt5645_quirk & CHT_RT5645_SSP2_AIF2) ||
268 (cht_rt5645_quirk & CHT_RT5645_SSP0_AIF2)) { 253 (cht_rt5645_quirk & CHT_RT5645_SSP0_AIF2)) {
@@ -320,26 +305,26 @@ static int cht_codec_init(struct snd_soc_pcm_runtime *runtime)
320 305
321 rt5645_set_jack_detect(codec, &ctx->jack, &ctx->jack, &ctx->jack); 306 rt5645_set_jack_detect(codec, &ctx->jack, &ctx->jack, &ctx->jack);
322 307
323 if (ctx->mclk) {
324 /*
325 * The firmware might enable the clock at
326 * boot (this information may or may not
327 * be reflected in the enable clock register).
328 * To change the rate we must disable the clock
329 * first to cover these cases. Due to common
330 * clock framework restrictions that do not allow
331 * to disable a clock that has not been enabled,
332 * we need to enable the clock first.
333 */
334 ret = clk_prepare_enable(ctx->mclk);
335 if (!ret)
336 clk_disable_unprepare(ctx->mclk);
337 308
338 ret = clk_set_rate(ctx->mclk, CHT_PLAT_CLK_3_HZ); 309 /*
310 * The firmware might enable the clock at
311 * boot (this information may or may not
312 * be reflected in the enable clock register).
313 * To change the rate we must disable the clock
314 * first to cover these cases. Due to common
315 * clock framework restrictions that do not allow
316 * to disable a clock that has not been enabled,
317 * we need to enable the clock first.
318 */
319 ret = clk_prepare_enable(ctx->mclk);
320 if (!ret)
321 clk_disable_unprepare(ctx->mclk);
322
323 ret = clk_set_rate(ctx->mclk, CHT_PLAT_CLK_3_HZ);
324
325 if (ret)
326 dev_err(runtime->dev, "unable to set MCLK rate\n");
339 327
340 if (ret)
341 dev_err(runtime->dev, "unable to set MCLK rate\n");
342 }
343 return ret; 328 return ret;
344} 329}
345 330
@@ -460,19 +445,11 @@ static struct snd_soc_dai_link cht_dailink[] = {
460 .dpcm_playback = 1, 445 .dpcm_playback = 1,
461 .ops = &cht_aif1_ops, 446 .ops = &cht_aif1_ops,
462 }, 447 },
463 [MERR_DPCM_COMPR] = {
464 .name = "Compressed Port",
465 .stream_name = "Compress",
466 .cpu_dai_name = "compress-cpu-dai",
467 .codec_dai_name = "snd-soc-dummy-dai",
468 .codec_name = "snd-soc-dummy",
469 .platform_name = "sst-mfld-platform",
470 },
471 /* CODEC<->CODEC link */ 448 /* CODEC<->CODEC link */
472 /* back ends */ 449 /* back ends */
473 { 450 {
474 .name = "SSP2-Codec", 451 .name = "SSP2-Codec",
475 .id = 1, 452 .id = 0,
476 .cpu_dai_name = "ssp2-port", 453 .cpu_dai_name = "ssp2-port",
477 .platform_name = "sst-mfld-platform", 454 .platform_name = "sst-mfld-platform",
478 .no_pcm = 1, 455 .no_pcm = 1,
@@ -545,15 +522,15 @@ struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
545 522
546static int snd_cht_mc_probe(struct platform_device *pdev) 523static int snd_cht_mc_probe(struct platform_device *pdev)
547{ 524{
548 int ret_val = 0;
549 int i;
550 struct cht_mc_private *drv;
551 struct snd_soc_card *card = snd_soc_cards[0].soc_card; 525 struct snd_soc_card *card = snd_soc_cards[0].soc_card;
552 struct sst_acpi_mach *mach; 526 struct snd_soc_acpi_mach *mach;
527 struct cht_mc_private *drv;
553 const char *i2c_name = NULL; 528 const char *i2c_name = NULL;
554 int dai_index = 0;
555 bool found = false; 529 bool found = false;
556 bool is_bytcr = false; 530 bool is_bytcr = false;
531 int dai_index = 0;
532 int ret_val = 0;
533 int i;
557 534
558 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_ATOMIC); 535 drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_ATOMIC);
559 if (!drv) 536 if (!drv)
@@ -589,8 +566,8 @@ static int snd_cht_mc_probe(struct platform_device *pdev)
589 } 566 }
590 567
591 /* fixup codec name based on HID */ 568 /* fixup codec name based on HID */
592 i2c_name = sst_acpi_find_name_from_hid(mach->id); 569 i2c_name = snd_soc_acpi_find_name_from_hid(mach->id);
593 if (i2c_name != NULL) { 570 if (i2c_name) {
594 snprintf(cht_rt5645_codec_name, sizeof(cht_rt5645_codec_name), 571 snprintf(cht_rt5645_codec_name, sizeof(cht_rt5645_codec_name),
595 "%s%s", "i2c-", i2c_name); 572 "%s%s", "i2c-", i2c_name);
596 cht_dailink[dai_index].codec_name = cht_rt5645_codec_name; 573 cht_dailink[dai_index].codec_name = cht_rt5645_codec_name;
@@ -622,7 +599,7 @@ static int snd_cht_mc_probe(struct platform_device *pdev)
622 /* format specified: 2 64-bit integers */ 599 /* format specified: 2 64-bit integers */
623 struct acpi_buffer format = {sizeof("NN"), "NN"}; 600 struct acpi_buffer format = {sizeof("NN"), "NN"};
624 struct acpi_buffer state = {0, NULL}; 601 struct acpi_buffer state = {0, NULL};
625 struct sst_acpi_package_context pkg_ctx; 602 struct snd_soc_acpi_package_context pkg_ctx;
626 bool pkg_found = false; 603 bool pkg_found = false;
627 604
628 state.length = sizeof(chan_package); 605 state.length = sizeof(chan_package);
@@ -634,7 +611,8 @@ static int snd_cht_mc_probe(struct platform_device *pdev)
634 pkg_ctx.state = &state; 611 pkg_ctx.state = &state;
635 pkg_ctx.data_valid = false; 612 pkg_ctx.data_valid = false;
636 613
637 pkg_found = sst_acpi_find_package_from_hid(mach->id, &pkg_ctx); 614 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id,
615 &pkg_ctx);
638 if (pkg_found) { 616 if (pkg_found) {
639 if (chan_package.aif_value == 1) { 617 if (chan_package.aif_value == 1) {
640 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n"); 618 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
@@ -682,14 +660,12 @@ static int snd_cht_mc_probe(struct platform_device *pdev)
682 cht_rt5645_cpu_dai_name; 660 cht_rt5645_cpu_dai_name;
683 } 661 }
684 662
685 if (is_valleyview()) { 663 drv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
686 drv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3"); 664 if (IS_ERR(drv->mclk)) {
687 if (IS_ERR(drv->mclk)) { 665 dev_err(&pdev->dev,
688 dev_err(&pdev->dev, 666 "Failed to get MCLK from pmc_plt_clk_3: %ld\n",
689 "Failed to get MCLK from pmc_plt_clk_3: %ld\n", 667 PTR_ERR(drv->mclk));
690 PTR_ERR(drv->mclk)); 668 return PTR_ERR(drv->mclk);
691 return PTR_ERR(drv->mclk);
692 }
693 } 669 }
694 670
695 snd_soc_card_set_drvdata(card, drv); 671 snd_soc_card_set_drvdata(card, drv);
diff --git a/sound/soc/intel/boards/cht_bsw_rt5672.c b/sound/soc/intel/boards/cht_bsw_rt5672.c
index f597d5582223..f8f21eee9b2d 100644
--- a/sound/soc/intel/boards/cht_bsw_rt5672.c
+++ b/sound/soc/intel/boards/cht_bsw_rt5672.c
@@ -20,14 +20,14 @@
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/clk.h> 22#include <linux/clk.h>
23#include <asm/cpu_device_id.h>
24#include <sound/pcm.h> 23#include <sound/pcm.h>
25#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
26#include <sound/soc.h> 25#include <sound/soc.h>
27#include <sound/jack.h> 26#include <sound/jack.h>
27#include <sound/soc-acpi.h>
28#include "../../codecs/rt5670.h" 28#include "../../codecs/rt5670.h"
29#include "../atom/sst-atom-controls.h" 29#include "../atom/sst-atom-controls.h"
30#include "../common/sst-acpi.h" 30
31 31
32/* The platform clock #3 outputs 19.2Mhz clock to codec as I2S MCLK */ 32/* The platform clock #3 outputs 19.2Mhz clock to codec as I2S MCLK */
33#define CHT_PLAT_CLK_3_HZ 19200000 33#define CHT_PLAT_CLK_3_HZ 19200000
@@ -51,18 +51,6 @@ static struct snd_soc_jack_pin cht_bsw_headset_pins[] = {
51 }, 51 },
52}; 52};
53 53
54static inline struct snd_soc_dai *cht_get_codec_dai(struct snd_soc_card *card)
55{
56 struct snd_soc_pcm_runtime *rtd;
57
58 list_for_each_entry(rtd, &card->rtd_list, list) {
59 if (!strncmp(rtd->codec_dai->name, CHT_CODEC_DAI,
60 strlen(CHT_CODEC_DAI)))
61 return rtd->codec_dai;
62 }
63 return NULL;
64}
65
66static int platform_clock_control(struct snd_soc_dapm_widget *w, 54static int platform_clock_control(struct snd_soc_dapm_widget *w,
67 struct snd_kcontrol *k, int event) 55 struct snd_kcontrol *k, int event)
68{ 56{
@@ -72,7 +60,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
72 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card); 60 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card);
73 int ret; 61 int ret;
74 62
75 codec_dai = cht_get_codec_dai(card); 63 codec_dai = snd_soc_card_get_codec_dai(card, CHT_CODEC_DAI);
76 if (!codec_dai) { 64 if (!codec_dai) {
77 dev_err(card->dev, "Codec dai not found; Unable to set platform clock\n"); 65 dev_err(card->dev, "Codec dai not found; Unable to set platform clock\n");
78 return -EIO; 66 return -EIO;
@@ -315,20 +303,12 @@ static struct snd_soc_dai_link cht_dailink[] = {
315 .dpcm_playback = 1, 303 .dpcm_playback = 1,
316 .ops = &cht_aif1_ops, 304 .ops = &cht_aif1_ops,
317 }, 305 },
318 [MERR_DPCM_COMPR] = {
319 .name = "Compressed Port",
320 .stream_name = "Compress",
321 .cpu_dai_name = "compress-cpu-dai",
322 .codec_dai_name = "snd-soc-dummy-dai",
323 .codec_name = "snd-soc-dummy",
324 .platform_name = "sst-mfld-platform",
325 },
326 306
327 /* Back End DAI links */ 307 /* Back End DAI links */
328 { 308 {
329 /* SSP2 - Codec */ 309 /* SSP2 - Codec */
330 .name = "SSP2-Codec", 310 .name = "SSP2-Codec",
331 .id = 1, 311 .id = 0,
332 .cpu_dai_name = "ssp2-port", 312 .cpu_dai_name = "ssp2-port",
333 .platform_name = "sst-mfld-platform", 313 .platform_name = "sst-mfld-platform",
334 .no_pcm = 1, 314 .no_pcm = 1,
@@ -348,9 +328,11 @@ static struct snd_soc_dai_link cht_dailink[] = {
348static int cht_suspend_pre(struct snd_soc_card *card) 328static int cht_suspend_pre(struct snd_soc_card *card)
349{ 329{
350 struct snd_soc_component *component; 330 struct snd_soc_component *component;
331 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card);
351 332
352 list_for_each_entry(component, &card->component_dev_list, card_list) { 333 list_for_each_entry(component, &card->component_dev_list, card_list) {
353 if (!strcmp(component->name, "i2c-10EC5670:00")) { 334 if (!strncmp(component->name,
335 ctx->codec_name, sizeof(ctx->codec_name))) {
354 struct snd_soc_codec *codec = snd_soc_component_to_codec(component); 336 struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
355 337
356 dev_dbg(codec->dev, "disabling jack detect before going to suspend.\n"); 338 dev_dbg(codec->dev, "disabling jack detect before going to suspend.\n");
@@ -364,9 +346,11 @@ static int cht_suspend_pre(struct snd_soc_card *card)
364static int cht_resume_post(struct snd_soc_card *card) 346static int cht_resume_post(struct snd_soc_card *card)
365{ 347{
366 struct snd_soc_component *component; 348 struct snd_soc_component *component;
349 struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card);
367 350
368 list_for_each_entry(component, &card->component_dev_list, card_list) { 351 list_for_each_entry(component, &card->component_dev_list, card_list) {
369 if (!strcmp(component->name, "i2c-10EC5670:00")) { 352 if (!strncmp(component->name,
353 ctx->codec_name, sizeof(ctx->codec_name))) {
370 struct snd_soc_codec *codec = snd_soc_component_to_codec(component); 354 struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
371 355
372 dev_dbg(codec->dev, "enabling jack detect for resume.\n"); 356 dev_dbg(codec->dev, "enabling jack detect for resume.\n");
@@ -380,7 +364,7 @@ static int cht_resume_post(struct snd_soc_card *card)
380 364
381/* SoC card */ 365/* SoC card */
382static struct snd_soc_card snd_soc_card_cht = { 366static struct snd_soc_card snd_soc_card_cht = {
383 .name = "cherrytrailcraudio", 367 .name = "cht-bsw-rt5672",
384 .owner = THIS_MODULE, 368 .owner = THIS_MODULE,
385 .dai_link = cht_dailink, 369 .dai_link = cht_dailink,
386 .num_links = ARRAY_SIZE(cht_dailink), 370 .num_links = ARRAY_SIZE(cht_dailink),
@@ -394,25 +378,13 @@ static struct snd_soc_card snd_soc_card_cht = {
394 .resume_post = cht_resume_post, 378 .resume_post = cht_resume_post,
395}; 379};
396 380
397static bool is_valleyview(void)
398{
399 static const struct x86_cpu_id cpu_ids[] = {
400 { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
401 {}
402 };
403
404 if (!x86_match_cpu(cpu_ids))
405 return false;
406 return true;
407}
408
409#define RT5672_I2C_DEFAULT "i2c-10EC5670:00" 381#define RT5672_I2C_DEFAULT "i2c-10EC5670:00"
410 382
411static int snd_cht_mc_probe(struct platform_device *pdev) 383static int snd_cht_mc_probe(struct platform_device *pdev)
412{ 384{
413 int ret_val = 0; 385 int ret_val = 0;
414 struct cht_mc_private *drv; 386 struct cht_mc_private *drv;
415 struct sst_acpi_mach *mach = pdev->dev.platform_data; 387 struct snd_soc_acpi_mach *mach = pdev->dev.platform_data;
416 const char *i2c_name; 388 const char *i2c_name;
417 int i; 389 int i;
418 390
@@ -424,7 +396,7 @@ static int snd_cht_mc_probe(struct platform_device *pdev)
424 396
425 /* fixup codec name based on HID */ 397 /* fixup codec name based on HID */
426 if (mach) { 398 if (mach) {
427 i2c_name = sst_acpi_find_name_from_hid(mach->id); 399 i2c_name = snd_soc_acpi_find_name_from_hid(mach->id);
428 if (i2c_name) { 400 if (i2c_name) {
429 snprintf(drv->codec_name, sizeof(drv->codec_name), 401 snprintf(drv->codec_name, sizeof(drv->codec_name),
430 "i2c-%s", i2c_name); 402 "i2c-%s", i2c_name);
@@ -439,14 +411,12 @@ static int snd_cht_mc_probe(struct platform_device *pdev)
439 } 411 }
440 } 412 }
441 413
442 if (is_valleyview()) { 414 drv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
443 drv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3"); 415 if (IS_ERR(drv->mclk)) {
444 if (IS_ERR(drv->mclk)) { 416 dev_err(&pdev->dev,
445 dev_err(&pdev->dev, 417 "Failed to get MCLK from pmc_plt_clk_3: %ld\n",
446 "Failed to get MCLK from pmc_plt_clk_3: %ld\n", 418 PTR_ERR(drv->mclk));
447 PTR_ERR(drv->mclk)); 419 return PTR_ERR(drv->mclk);
448 return PTR_ERR(drv->mclk);
449 }
450 } 420 }
451 snd_soc_card_set_drvdata(&snd_soc_card_cht, drv); 421 snd_soc_card_set_drvdata(&snd_soc_card_cht, drv);
452 422
diff --git a/sound/soc/intel/boards/kbl_rt5663_max98927.c b/sound/soc/intel/boards/kbl_rt5663_max98927.c
index 7f7607420706..6f9a8bcf20f3 100644
--- a/sound/soc/intel/boards/kbl_rt5663_max98927.c
+++ b/sound/soc/intel/boards/kbl_rt5663_max98927.c
@@ -17,6 +17,7 @@
17 * GNU General Public License for more details. 17 * GNU General Public License for more details.
18 */ 18 */
19 19
20#include <linux/input.h>
20#include <linux/module.h> 21#include <linux/module.h>
21#include <linux/platform_device.h> 22#include <linux/platform_device.h>
22#include <sound/core.h> 23#include <sound/core.h>
@@ -208,6 +209,7 @@ static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd)
208 int ret; 209 int ret;
209 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card); 210 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
210 struct snd_soc_codec *codec = rtd->codec; 211 struct snd_soc_codec *codec = rtd->codec;
212 struct snd_soc_jack *jack;
211 213
212 /* 214 /*
213 * Headset buttons map to the google Reference headset. 215 * Headset buttons map to the google Reference headset.
@@ -221,6 +223,13 @@ static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd)
221 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret); 223 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
222 return ret; 224 return ret;
223 } 225 }
226
227 jack = &ctx->kabylake_headset;
228 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_MEDIA);
229 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
230 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
231 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
232
224 rt5663_set_jack_detect(codec, &ctx->kabylake_headset); 233 rt5663_set_jack_detect(codec, &ctx->kabylake_headset);
225 return ret; 234 return ret;
226} 235}
@@ -341,13 +350,28 @@ static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
341 struct snd_interval *channels = hw_param_interval(params, 350 struct snd_interval *channels = hw_param_interval(params,
342 SNDRV_PCM_HW_PARAM_CHANNELS); 351 SNDRV_PCM_HW_PARAM_CHANNELS);
343 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 352 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
353 struct snd_soc_dpcm *dpcm = container_of(
354 params, struct snd_soc_dpcm, hw_params);
355 struct snd_soc_dai_link *fe_dai_link = dpcm->fe->dai_link;
356 struct snd_soc_dai_link *be_dai_link = dpcm->be->dai_link;
344 357
345 /* The ADSP will convert the FE rate to 48k, stereo */ 358 /*
346 rate->min = rate->max = 48000; 359 * The ADSP will convert the FE rate to 48k, stereo, 24 bit
347 channels->min = channels->max = 2; 360 */
348 /* set SSP1 to 24 bit */ 361 if (!strcmp(fe_dai_link->name, "Kbl Audio Port") ||
349 snd_mask_none(fmt); 362 !strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") ||
350 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE); 363 !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) {
364 rate->min = rate->max = 48000;
365 channels->min = channels->max = 2;
366 snd_mask_none(fmt);
367 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
368 }
369 /*
370 * The speaker on the SSP0 supports S16_LE and not S24_LE.
371 * thus changing the mask here
372 */
373 if (!strcmp(be_dai_link->name, "SSP0-Codec"))
374 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S16_LE);
351 375
352 return 0; 376 return 0;
353} 377}
@@ -390,6 +414,43 @@ static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
390 return 0; 414 return 0;
391} 415}
392 416
417static int kabylake_ssp0_hw_params(struct snd_pcm_substream *substream,
418 struct snd_pcm_hw_params *params)
419{
420 struct snd_soc_pcm_runtime *rtd = substream->private_data;
421 int ret = 0, j;
422
423 for (j = 0; j < rtd->num_codecs; j++) {
424 struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
425
426 if (!strcmp(codec_dai->component->name, MAXIM_DEV0_NAME)) {
427 /*
428 * Use channel 4 and 5 for the first amp
429 */
430 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x30, 3, 8, 16);
431 if (ret < 0) {
432 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
433 return ret;
434 }
435 }
436 if (!strcmp(codec_dai->component->name, MAXIM_DEV1_NAME)) {
437 /*
438 * Use channel 6 and 7 for the second amp
439 */
440 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xC0, 3, 8, 16);
441 if (ret < 0) {
442 dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
443 return ret;
444 }
445 }
446 }
447 return ret;
448}
449
450static struct snd_soc_ops kabylake_ssp0_ops = {
451 .hw_params = kabylake_ssp0_hw_params,
452};
453
393static unsigned int channels_dmic[] = { 454static unsigned int channels_dmic[] = {
394 2, 4, 455 2, 4,
395}; 456};
@@ -593,12 +654,13 @@ static struct snd_soc_dai_link kabylake_dais[] = {
593 .no_pcm = 1, 654 .no_pcm = 1,
594 .codecs = max98927_codec_components, 655 .codecs = max98927_codec_components,
595 .num_codecs = ARRAY_SIZE(max98927_codec_components), 656 .num_codecs = ARRAY_SIZE(max98927_codec_components),
596 .dai_fmt = SND_SOC_DAIFMT_I2S | 657 .dai_fmt = SND_SOC_DAIFMT_DSP_B |
597 SND_SOC_DAIFMT_NB_NF | 658 SND_SOC_DAIFMT_NB_NF |
598 SND_SOC_DAIFMT_CBS_CFS, 659 SND_SOC_DAIFMT_CBS_CFS,
599 .ignore_pmdown_time = 1, 660 .ignore_pmdown_time = 1,
600 .be_hw_params_fixup = kabylake_ssp_fixup, 661 .be_hw_params_fixup = kabylake_ssp_fixup,
601 .dpcm_playback = 1, 662 .dpcm_playback = 1,
663 .ops = &kabylake_ssp0_ops,
602 }, 664 },
603 { 665 {
604 /* SSP1 - Codec */ 666 /* SSP1 - Codec */
diff --git a/sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c b/sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c
index 88ff54220007..6072164f2d43 100644
--- a/sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c
+++ b/sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c
@@ -302,6 +302,7 @@ static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
302 * The ADSP will convert the FE rate to 48k, stereo, 24 bit 302 * The ADSP will convert the FE rate to 48k, stereo, 24 bit
303 */ 303 */
304 if (!strcmp(fe_dai_link->name, "Kbl Audio Port") || 304 if (!strcmp(fe_dai_link->name, "Kbl Audio Port") ||
305 !strcmp(fe_dai_link->name, "Kbl Audio Headset Playback") ||
305 !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) { 306 !strcmp(fe_dai_link->name, "Kbl Audio Capture Port")) {
306 rate->min = rate->max = 48000; 307 rate->min = rate->max = 48000;
307 channels->min = channels->max = 2; 308 channels->min = channels->max = 2;
@@ -604,6 +605,8 @@ static int kabylake_card_late_probe(struct snd_soc_card *card)
604 605
605 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) { 606 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
606 codec = pcm->codec_dai->codec; 607 codec = pcm->codec_dai->codec;
608 snprintf(jack_name, sizeof(jack_name),
609 "HDMI/DP,pcm=%d Jack", pcm->device);
607 err = snd_soc_card_jack_new(card, jack_name, 610 err = snd_soc_card_jack_new(card, jack_name,
608 SND_JACK_AVOUT, &ctx->kabylake_hdmi[i], 611 SND_JACK_AVOUT, &ctx->kabylake_hdmi[i],
609 NULL, 0); 612 NULL, 0);
diff --git a/sound/soc/intel/boards/skl_nau88l25_max98357a.c b/sound/soc/intel/boards/skl_nau88l25_max98357a.c
index 5ed0aa27b467..1b5a689dc99b 100644
--- a/sound/soc/intel/boards/skl_nau88l25_max98357a.c
+++ b/sound/soc/intel/boards/skl_nau88l25_max98357a.c
@@ -54,20 +54,6 @@ enum {
54 SKL_DPCM_AUDIO_HDMI3_PB, 54 SKL_DPCM_AUDIO_HDMI3_PB,
55}; 55};
56 56
57static inline struct snd_soc_dai *skl_get_codec_dai(struct snd_soc_card *card)
58{
59 struct snd_soc_pcm_runtime *rtd;
60
61 list_for_each_entry(rtd, &card->rtd_list, list) {
62
63 if (!strncmp(rtd->codec_dai->name, SKL_NUVOTON_CODEC_DAI,
64 strlen(SKL_NUVOTON_CODEC_DAI)))
65 return rtd->codec_dai;
66 }
67
68 return NULL;
69}
70
71static int platform_clock_control(struct snd_soc_dapm_widget *w, 57static int platform_clock_control(struct snd_soc_dapm_widget *w,
72 struct snd_kcontrol *k, int event) 58 struct snd_kcontrol *k, int event)
73{ 59{
@@ -76,7 +62,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
76 struct snd_soc_dai *codec_dai; 62 struct snd_soc_dai *codec_dai;
77 int ret; 63 int ret;
78 64
79 codec_dai = skl_get_codec_dai(card); 65 codec_dai = snd_soc_card_get_codec_dai(card, SKL_NUVOTON_CODEC_DAI);
80 if (!codec_dai) { 66 if (!codec_dai) {
81 dev_err(card->dev, "Codec dai not found; Unable to set platform clock\n"); 67 dev_err(card->dev, "Codec dai not found; Unable to set platform clock\n");
82 return -EIO; 68 return -EIO;
diff --git a/sound/soc/intel/boards/skl_nau88l25_ssm4567.c b/sound/soc/intel/boards/skl_nau88l25_ssm4567.c
index 01b8b140bb08..7bea4bc77481 100644
--- a/sound/soc/intel/boards/skl_nau88l25_ssm4567.c
+++ b/sound/soc/intel/boards/skl_nau88l25_ssm4567.c
@@ -57,20 +57,6 @@ enum {
57 SKL_DPCM_AUDIO_HDMI3_PB, 57 SKL_DPCM_AUDIO_HDMI3_PB,
58}; 58};
59 59
60static inline struct snd_soc_dai *skl_get_codec_dai(struct snd_soc_card *card)
61{
62 struct snd_soc_pcm_runtime *rtd;
63
64 list_for_each_entry(rtd, &card->rtd_list, list) {
65
66 if (!strncmp(rtd->codec_dai->name, SKL_NUVOTON_CODEC_DAI,
67 strlen(SKL_NUVOTON_CODEC_DAI)))
68 return rtd->codec_dai;
69 }
70
71 return NULL;
72}
73
74static const struct snd_kcontrol_new skylake_controls[] = { 60static const struct snd_kcontrol_new skylake_controls[] = {
75 SOC_DAPM_PIN_SWITCH("Headphone Jack"), 61 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
76 SOC_DAPM_PIN_SWITCH("Headset Mic"), 62 SOC_DAPM_PIN_SWITCH("Headset Mic"),
@@ -86,7 +72,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
86 struct snd_soc_dai *codec_dai; 72 struct snd_soc_dai *codec_dai;
87 int ret; 73 int ret;
88 74
89 codec_dai = skl_get_codec_dai(card); 75 codec_dai = snd_soc_card_get_codec_dai(card, SKL_NUVOTON_CODEC_DAI);
90 if (!codec_dai) { 76 if (!codec_dai) {
91 dev_err(card->dev, "Codec dai not found\n"); 77 dev_err(card->dev, "Codec dai not found\n");
92 return -EIO; 78 return -EIO;
diff --git a/sound/soc/intel/common/Makefile b/sound/soc/intel/common/Makefile
index 0e029f354f6b..7379d8830c39 100644
--- a/sound/soc/intel/common/Makefile
+++ b/sound/soc/intel/common/Makefile
@@ -1,11 +1,11 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2snd-soc-sst-dsp-objs := sst-dsp.o 2snd-soc-sst-dsp-objs := sst-dsp.o
3snd-soc-sst-acpi-objs := sst-acpi.o 3snd-soc-sst-acpi-objs := sst-acpi.o
4snd-soc-sst-match-objs := sst-match-acpi.o
5snd-soc-sst-ipc-objs := sst-ipc.o 4snd-soc-sst-ipc-objs := sst-ipc.o
6snd-soc-sst-firmware-objs := sst-firmware.o 5snd-soc-sst-firmware-objs := sst-firmware.o
6snd-soc-acpi-intel-match-objs := soc-acpi-intel-byt-match.o soc-acpi-intel-cht-match.o soc-acpi-intel-hsw-bdw-match.o
7 7
8obj-$(CONFIG_SND_SOC_INTEL_SST) += snd-soc-sst-dsp.o snd-soc-sst-ipc.o 8obj-$(CONFIG_SND_SOC_INTEL_SST) += snd-soc-sst-dsp.o snd-soc-sst-ipc.o
9obj-$(CONFIG_SND_SOC_INTEL_SST_ACPI) += snd-soc-sst-acpi.o 9obj-$(CONFIG_SND_SOC_INTEL_SST_ACPI) += snd-soc-sst-acpi.o
10obj-$(CONFIG_SND_SOC_INTEL_SST_MATCH) += snd-soc-sst-match.o
11obj-$(CONFIG_SND_SOC_INTEL_SST_FIRMWARE) += snd-soc-sst-firmware.o 10obj-$(CONFIG_SND_SOC_INTEL_SST_FIRMWARE) += snd-soc-sst-firmware.o
11obj-$(CONFIG_SND_SOC_ACPI_INTEL_MATCH) += snd-soc-acpi-intel-match.o
diff --git a/sound/soc/intel/common/soc-acpi-intel-byt-match.c b/sound/soc/intel/common/soc-acpi-intel-byt-match.c
new file mode 100644
index 000000000000..bfe1ca68a542
--- /dev/null
+++ b/sound/soc/intel/common/soc-acpi-intel-byt-match.c
@@ -0,0 +1,196 @@
1/*
2 * soc-apci-intel-byt-match.c - tables and support for BYT ACPI enumeration.
3 *
4 * Copyright (c) 2017, Intel Corporation.
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 */
16
17#include <linux/dmi.h>
18#include <sound/soc-acpi.h>
19#include <sound/soc-acpi-intel-match.h>
20
21static unsigned long byt_machine_id;
22
23#define BYT_THINKPAD_10 1
24
25static int byt_thinkpad10_quirk_cb(const struct dmi_system_id *id)
26{
27 byt_machine_id = BYT_THINKPAD_10;
28 return 1;
29}
30
31
32static const struct dmi_system_id byt_table[] = {
33 {
34 .callback = byt_thinkpad10_quirk_cb,
35 .matches = {
36 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
37 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad 10"),
38 },
39 },
40 {
41 .callback = byt_thinkpad10_quirk_cb,
42 .matches = {
43 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
44 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad Tablet B"),
45 },
46 },
47 {
48 .callback = byt_thinkpad10_quirk_cb,
49 .matches = {
50 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
51 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Miix 2 10"),
52 },
53 },
54 { }
55};
56
57static struct snd_soc_acpi_mach byt_thinkpad_10 = {
58 .id = "10EC5640",
59 .drv_name = "cht-bsw-rt5672",
60 .fw_filename = "intel/fw_sst_0f28.bin",
61 .board = "cht-bsw",
62 .sof_fw_filename = "intel/reef-byt.ri",
63 .sof_tplg_filename = "intel/reef-byt-rt5670.tplg",
64 .asoc_plat_name = "sst-mfld-platform",
65};
66
67static struct snd_soc_acpi_mach *byt_quirk(void *arg)
68{
69 struct snd_soc_acpi_mach *mach = arg;
70
71 dmi_check_system(byt_table);
72
73 if (byt_machine_id == BYT_THINKPAD_10)
74 return &byt_thinkpad_10;
75 else
76 return mach;
77}
78
79struct snd_soc_acpi_mach snd_soc_acpi_intel_baytrail_legacy_machines[] = {
80 {
81 .id = "10EC5640",
82 .drv_name = "byt-rt5640",
83 .fw_filename = "intel/fw_sst_0f28.bin-48kHz_i2s_master",
84 },
85 {
86 .id = "193C9890",
87 .drv_name = "byt-max98090",
88 .fw_filename = "intel/fw_sst_0f28.bin-48kHz_i2s_master",
89 },
90 {}
91};
92EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_baytrail_legacy_machines);
93
94struct snd_soc_acpi_mach snd_soc_acpi_intel_baytrail_machines[] = {
95 {
96 .id = "10EC5640",
97 .drv_name = "bytcr_rt5640",
98 .fw_filename = "intel/fw_sst_0f28.bin",
99 .board = "bytcr_rt5640",
100 .machine_quirk = byt_quirk,
101 .sof_fw_filename = "intel/reef-byt.ri",
102 .sof_tplg_filename = "intel/reef-byt-rt5640.tplg",
103 .asoc_plat_name = "sst-mfld-platform",
104 },
105 {
106 .id = "10EC5642",
107 .drv_name = "bytcr_rt5640",
108 .fw_filename = "intel/fw_sst_0f28.bin",
109 .board = "bytcr_rt5640",
110 .sof_fw_filename = "intel/reef-byt.ri",
111 .sof_tplg_filename = "intel/reef-byt-rt5640.tplg",
112 .asoc_plat_name = "sst-mfld-platform",
113 },
114 {
115 .id = "INTCCFFD",
116 .drv_name = "bytcr_rt5640",
117 .fw_filename = "intel/fw_sst_0f28.bin",
118 .board = "bytcr_rt5640",
119 .sof_fw_filename = "intel/reef-byt.ri",
120 .sof_tplg_filename = "intel/reef-byt-rt5640.tplg",
121 .asoc_plat_name = "sst-mfld-platform",
122 },
123 {
124 .id = "10EC5651",
125 .drv_name = "bytcr_rt5651",
126 .fw_filename = "intel/fw_sst_0f28.bin",
127 .board = "bytcr_rt5651",
128 .sof_fw_filename = "intel/reef-byt.ri",
129 .sof_tplg_filename = "intel/reef-byt-rt5651.tplg",
130 .asoc_plat_name = "sst-mfld-platform",
131 },
132 {
133 .id = "DLGS7212",
134 .drv_name = "bytcht_da7213",
135 .fw_filename = "intel/fw_sst_0f28.bin",
136 .board = "bytcht_da7213",
137 .sof_fw_filename = "intel/reef-byt.ri",
138 .sof_tplg_filename = "intel/reef-byt-da7213.tplg",
139 .asoc_plat_name = "sst-mfld-platform",
140 },
141 {
142 .id = "DLGS7213",
143 .drv_name = "bytcht_da7213",
144 .fw_filename = "intel/fw_sst_0f28.bin",
145 .board = "bytcht_da7213",
146 .sof_fw_filename = "intel/reef-byt.ri",
147 .sof_tplg_filename = "intel/reef-byt-da7213.tplg",
148 .asoc_plat_name = "sst-mfld-platform",
149 },
150 /* some Baytrail platforms rely on RT5645, use CHT machine driver */
151 {
152 .id = "10EC5645",
153 .drv_name = "cht-bsw-rt5645",
154 .fw_filename = "intel/fw_sst_0f28.bin",
155 .board = "cht-bsw",
156 .sof_fw_filename = "intel/reef-byt.ri",
157 .sof_tplg_filename = "intel/reef-byt-rt5645.tplg",
158 .asoc_plat_name = "sst-mfld-platform",
159 },
160 {
161 .id = "10EC5648",
162 .drv_name = "cht-bsw-rt5645",
163 .fw_filename = "intel/fw_sst_0f28.bin",
164 .board = "cht-bsw",
165 .sof_fw_filename = "intel/reef-byt.ri",
166 .sof_tplg_filename = "intel/reef-byt-rt5645.tplg",
167 .asoc_plat_name = "sst-mfld-platform",
168 },
169 /* use CHT driver to Baytrail Chromebooks */
170 {
171 .id = "193C9890",
172 .drv_name = "cht-bsw-max98090",
173 .fw_filename = "intel/fw_sst_0f28.bin",
174 .board = "cht-bsw",
175 .sof_fw_filename = "intel/reef-byt.ri",
176 .sof_tplg_filename = "intel/reef-byt-max98090.tplg",
177 .asoc_plat_name = "sst-mfld-platform",
178 },
179#if IS_ENABLED(CONFIG_SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH)
180 /*
181 * This is always last in the table so that it is selected only when
182 * enabled explicitly and there is no codec-related information in SSDT
183 */
184 {
185 .id = "80860F28",
186 .drv_name = "bytcht_nocodec",
187 .fw_filename = "intel/fw_sst_0f28.bin",
188 .board = "bytcht_nocodec",
189 },
190#endif
191 {},
192};
193EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_baytrail_machines);
194
195MODULE_LICENSE("GPL v2");
196MODULE_DESCRIPTION("Intel Common ACPI Match module");
diff --git a/sound/soc/intel/common/soc-acpi-intel-cht-match.c b/sound/soc/intel/common/soc-acpi-intel-cht-match.c
new file mode 100644
index 000000000000..b50a0d53846b
--- /dev/null
+++ b/sound/soc/intel/common/soc-acpi-intel-cht-match.c
@@ -0,0 +1,194 @@
1/*
2 * soc-apci-intel-cht-match.c - tables and support for CHT ACPI enumeration.
3 *
4 * Copyright (c) 2017, Intel Corporation.
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 */
16
17#include <linux/dmi.h>
18#include <sound/soc-acpi.h>
19#include <sound/soc-acpi-intel-match.h>
20
21static unsigned long cht_machine_id;
22
23#define CHT_SURFACE_MACH 1
24
25static int cht_surface_quirk_cb(const struct dmi_system_id *id)
26{
27 cht_machine_id = CHT_SURFACE_MACH;
28 return 1;
29}
30
31static const struct dmi_system_id cht_table[] = {
32 {
33 .callback = cht_surface_quirk_cb,
34 .matches = {
35 DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
36 DMI_MATCH(DMI_PRODUCT_NAME, "Surface 3"),
37 },
38 },
39 { }
40};
41
42static struct snd_soc_acpi_mach cht_surface_mach = {
43 .id = "10EC5640",
44 .drv_name = "cht-bsw-rt5645",
45 .fw_filename = "intel/fw_sst_22a8.bin",
46 .board = "cht-bsw",
47 .sof_fw_filename = "intel/reef-cht.ri",
48 .sof_tplg_filename = "intel/reef-cht-rt5645.tplg",
49 .asoc_plat_name = "sst-mfld-platform",
50};
51
52static struct snd_soc_acpi_mach *cht_quirk(void *arg)
53{
54 struct snd_soc_acpi_mach *mach = arg;
55
56 dmi_check_system(cht_table);
57
58 if (cht_machine_id == CHT_SURFACE_MACH)
59 return &cht_surface_mach;
60 else
61 return mach;
62}
63
64/* Cherryview-based platforms: CherryTrail and Braswell */
65struct snd_soc_acpi_mach snd_soc_acpi_intel_cherrytrail_machines[] = {
66 {
67 .id = "10EC5670",
68 .drv_name = "cht-bsw-rt5672",
69 .fw_filename = "intel/fw_sst_22a8.bin",
70 .board = "cht-bsw",
71 .sof_fw_filename = "intel/reef-cht.ri",
72 .sof_tplg_filename = "intel/reef-cht-rt5670.tplg",
73 .asoc_plat_name = "sst-mfld-platform",
74 },
75 {
76 .id = "10EC5672",
77 .drv_name = "cht-bsw-rt5672",
78 .fw_filename = "intel/fw_sst_22a8.bin",
79 .board = "cht-bsw",
80 .sof_fw_filename = "intel/reef-cht.ri",
81 .sof_tplg_filename = "intel/reef-cht-rt5670.tplg",
82 .asoc_plat_name = "sst-mfld-platform",
83 },
84 {
85 .id = "10EC5645",
86 .drv_name = "cht-bsw-rt5645",
87 .fw_filename = "intel/fw_sst_22a8.bin",
88 .board = "cht-bsw",
89 .sof_fw_filename = "intel/reef-cht.ri",
90 .sof_tplg_filename = "intel/reef-cht-rt5645.tplg",
91 .asoc_plat_name = "sst-mfld-platform",
92 },
93 {
94 .id = "10EC5650",
95 .drv_name = "cht-bsw-rt5645",
96 .fw_filename = "intel/fw_sst_22a8.bin",
97 .board = "cht-bsw",
98 .sof_fw_filename = "intel/reef-cht.ri",
99 .sof_tplg_filename = "intel/reef-cht-rt5645.tplg",
100 .asoc_plat_name = "sst-mfld-platform",
101 },
102 {
103 .id = "10EC3270",
104 .drv_name = "cht-bsw-rt5645",
105 .fw_filename = "intel/fw_sst_22a8.bin",
106 .board = "cht-bsw",
107 .sof_fw_filename = "intel/reef-cht.ri",
108 .sof_tplg_filename = "intel/reef-cht-rt5645.tplg",
109 .asoc_plat_name = "sst-mfld-platform",
110 },
111 {
112 .id = "193C9890",
113 .drv_name = "cht-bsw-max98090",
114 .fw_filename = "intel/fw_sst_22a8.bin",
115 .board = "cht-bsw",
116 .sof_fw_filename = "intel/reef-cht.ri",
117 .sof_tplg_filename = "intel/reef-cht-max98090.tplg",
118 .asoc_plat_name = "sst-mfld-platform",
119 },
120 {
121 .id = "DLGS7212",
122 .drv_name = "bytcht_da7213",
123 .fw_filename = "intel/fw_sst_22a8.bin",
124 .board = "bytcht_da7213",
125 .sof_fw_filename = "intel/reef-cht.ri",
126 .sof_tplg_filename = "intel/reef-cht-da7213.tplg",
127 .asoc_plat_name = "sst-mfld-platform",
128 },
129 {
130 .id = "DLGS7213",
131 .drv_name = "bytcht_da7213",
132 .fw_filename = "intel/fw_sst_22a8.bin",
133 .board = "bytcht_da7213",
134 .sof_fw_filename = "intel/reef-cht.ri",
135 .sof_tplg_filename = "intel/reef-cht-da7213.tplg",
136 .asoc_plat_name = "sst-mfld-platform",
137 },
138 {
139 .id = "ESSX8316",
140 .drv_name = "bytcht_es8316",
141 .fw_filename = "intel/fw_sst_22a8.bin",
142 .board = "bytcht_es8316",
143 .sof_fw_filename = "intel/reef-cht.ri",
144 .sof_tplg_filename = "intel/reef-cht-es8316.tplg",
145 .asoc_plat_name = "sst-mfld-platform",
146 },
147 /* some CHT-T platforms rely on RT5640, use Baytrail machine driver */
148 {
149 .id = "10EC5640",
150 .drv_name = "bytcr_rt5640",
151 .fw_filename = "intel/fw_sst_22a8.bin",
152 .board = "bytcr_rt5640",
153 .machine_quirk = cht_quirk,
154 .sof_fw_filename = "intel/reef-cht.ri",
155 .sof_tplg_filename = "intel/reef-cht-rt5640.tplg",
156 .asoc_plat_name = "sst-mfld-platform",
157 },
158 {
159 .id = "10EC3276",
160 .drv_name = "bytcr_rt5640",
161 .fw_filename = "intel/fw_sst_22a8.bin",
162 .board = "bytcr_rt5640",
163 .sof_fw_filename = "intel/reef-cht.ri",
164 .sof_tplg_filename = "intel/reef-cht-rt5640.tplg",
165 .asoc_plat_name = "sst-mfld-platform",
166 },
167 /* some CHT-T platforms rely on RT5651, use Baytrail machine driver */
168 {
169 .id = "10EC5651",
170 .drv_name = "bytcr_rt5651",
171 .fw_filename = "intel/fw_sst_22a8.bin",
172 .board = "bytcr_rt5651",
173 .sof_fw_filename = "intel/reef-cht.ri",
174 .sof_tplg_filename = "intel/reef-cht-rt5651.tplg",
175 .asoc_plat_name = "sst-mfld-platform",
176 },
177#if IS_ENABLED(CONFIG_SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH)
178 /*
179 * This is always last in the table so that it is selected only when
180 * enabled explicitly and there is no codec-related information in SSDT
181 */
182 {
183 .id = "808622A8",
184 .drv_name = "bytcht_nocodec",
185 .fw_filename = "intel/fw_sst_22a8.bin",
186 .board = "bytcht_nocodec",
187 },
188#endif
189 {},
190};
191EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_cherrytrail_machines);
192
193MODULE_LICENSE("GPL v2");
194MODULE_DESCRIPTION("Intel Common ACPI Match module");
diff --git a/sound/soc/intel/common/soc-acpi-intel-hsw-bdw-match.c b/sound/soc/intel/common/soc-acpi-intel-hsw-bdw-match.c
new file mode 100644
index 000000000000..e0e8c8c27528
--- /dev/null
+++ b/sound/soc/intel/common/soc-acpi-intel-hsw-bdw-match.c
@@ -0,0 +1,64 @@
1/*
2 * soc-apci-intel-hsw-bdw-match.c - tables and support for ACPI enumeration.
3 *
4 * Copyright (c) 2017, Intel Corporation.
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 */
16
17#include <linux/dmi.h>
18#include <sound/soc-acpi.h>
19#include <sound/soc-acpi-intel-match.h>
20
21struct snd_soc_acpi_mach snd_soc_acpi_intel_haswell_machines[] = {
22 {
23 .id = "INT33CA",
24 .drv_name = "haswell-audio",
25 .fw_filename = "intel/IntcSST1.bin",
26 .sof_fw_filename = "intel/reef-hsw.ri",
27 .sof_tplg_filename = "intel/reef-hsw.tplg",
28 .asoc_plat_name = "haswell-pcm-audio",
29 },
30 {}
31};
32EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_haswell_machines);
33
34struct snd_soc_acpi_mach snd_soc_acpi_intel_broadwell_machines[] = {
35 {
36 .id = "INT343A",
37 .drv_name = "broadwell-audio",
38 .fw_filename = "intel/IntcSST2.bin",
39 .sof_fw_filename = "intel/reef-bdw.ri",
40 .sof_tplg_filename = "intel/reef-bdw-rt286.tplg",
41 .asoc_plat_name = "haswell-pcm-audio",
42 },
43 {
44 .id = "RT5677CE",
45 .drv_name = "bdw-rt5677",
46 .fw_filename = "intel/IntcSST2.bin",
47 .sof_fw_filename = "intel/reef-bdw.ri",
48 .sof_tplg_filename = "intel/reef-bdw-rt286.tplg",
49 .asoc_plat_name = "haswell-pcm-audio",
50 },
51 {
52 .id = "INT33CA",
53 .drv_name = "haswell-audio",
54 .fw_filename = "intel/IntcSST2.bin",
55 .sof_fw_filename = "intel/reef-bdw.ri",
56 .sof_tplg_filename = "intel/reef-bdw-rt5640.tplg",
57 .asoc_plat_name = "haswell-pcm-audio",
58 },
59 {}
60};
61EXPORT_SYMBOL_GPL(snd_soc_acpi_intel_broadwell_machines);
62
63MODULE_LICENSE("GPL v2");
64MODULE_DESCRIPTION("Intel Common ACPI Match module");
diff --git a/sound/soc/intel/common/sst-acpi.c b/sound/soc/intel/common/sst-acpi.c
index 1285cc597b6b..cf6fbbd4e378 100644
--- a/sound/soc/intel/common/sst-acpi.c
+++ b/sound/soc/intel/common/sst-acpi.c
@@ -21,7 +21,8 @@
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22 22
23#include "sst-dsp.h" 23#include "sst-dsp.h"
24#include "sst-acpi.h" 24#include <sound/soc-acpi.h>
25#include <sound/soc-acpi-intel-match.h>
25 26
26#define SST_LPT_DSP_DMA_ADDR_OFFSET 0x0F0000 27#define SST_LPT_DSP_DMA_ADDR_OFFSET 0x0F0000
27#define SST_WPT_DSP_DMA_ADDR_OFFSET 0x0FE000 28#define SST_WPT_DSP_DMA_ADDR_OFFSET 0x0FE000
@@ -30,7 +31,7 @@
30/* Descriptor for setting up SST platform data */ 31/* Descriptor for setting up SST platform data */
31struct sst_acpi_desc { 32struct sst_acpi_desc {
32 const char *drv_name; 33 const char *drv_name;
33 struct sst_acpi_mach *machines; 34 struct snd_soc_acpi_mach *machines;
34 /* Platform resource indexes. Must set to -1 if not used */ 35 /* Platform resource indexes. Must set to -1 if not used */
35 int resindex_lpe_base; 36 int resindex_lpe_base;
36 int resindex_pcicfg_base; 37 int resindex_pcicfg_base;
@@ -49,7 +50,7 @@ struct sst_acpi_priv {
49 struct platform_device *pdev_pcm; 50 struct platform_device *pdev_pcm;
50 struct sst_pdata sst_pdata; 51 struct sst_pdata sst_pdata;
51 struct sst_acpi_desc *desc; 52 struct sst_acpi_desc *desc;
52 struct sst_acpi_mach *mach; 53 struct snd_soc_acpi_mach *mach;
53}; 54};
54 55
55static void sst_acpi_fw_cb(const struct firmware *fw, void *context) 56static void sst_acpi_fw_cb(const struct firmware *fw, void *context)
@@ -59,7 +60,7 @@ static void sst_acpi_fw_cb(const struct firmware *fw, void *context)
59 struct sst_acpi_priv *sst_acpi = platform_get_drvdata(pdev); 60 struct sst_acpi_priv *sst_acpi = platform_get_drvdata(pdev);
60 struct sst_pdata *sst_pdata = &sst_acpi->sst_pdata; 61 struct sst_pdata *sst_pdata = &sst_acpi->sst_pdata;
61 struct sst_acpi_desc *desc = sst_acpi->desc; 62 struct sst_acpi_desc *desc = sst_acpi->desc;
62 struct sst_acpi_mach *mach = sst_acpi->mach; 63 struct snd_soc_acpi_mach *mach = sst_acpi->mach;
63 64
64 sst_pdata->fw = fw; 65 sst_pdata->fw = fw;
65 if (!fw) { 66 if (!fw) {
@@ -85,7 +86,7 @@ static int sst_acpi_probe(struct platform_device *pdev)
85 struct device *dev = &pdev->dev; 86 struct device *dev = &pdev->dev;
86 struct sst_acpi_priv *sst_acpi; 87 struct sst_acpi_priv *sst_acpi;
87 struct sst_pdata *sst_pdata; 88 struct sst_pdata *sst_pdata;
88 struct sst_acpi_mach *mach; 89 struct snd_soc_acpi_mach *mach;
89 struct sst_acpi_desc *desc; 90 struct sst_acpi_desc *desc;
90 struct resource *mmio; 91 struct resource *mmio;
91 int ret = 0; 92 int ret = 0;
@@ -99,7 +100,7 @@ static int sst_acpi_probe(struct platform_device *pdev)
99 return -ENODEV; 100 return -ENODEV;
100 101
101 desc = (struct sst_acpi_desc *)id->driver_data; 102 desc = (struct sst_acpi_desc *)id->driver_data;
102 mach = sst_acpi_find_machine(desc->machines); 103 mach = snd_soc_acpi_find_machine(desc->machines);
103 if (mach == NULL) { 104 if (mach == NULL) {
104 dev_err(dev, "No matching ASoC machine driver found\n"); 105 dev_err(dev, "No matching ASoC machine driver found\n");
105 return -ENODEV; 106 return -ENODEV;
@@ -179,14 +180,9 @@ static int sst_acpi_remove(struct platform_device *pdev)
179 return 0; 180 return 0;
180} 181}
181 182
182static struct sst_acpi_mach haswell_machines[] = {
183 { "INT33CA", "haswell-audio", "intel/IntcSST1.bin", NULL, NULL, NULL },
184 {}
185};
186
187static struct sst_acpi_desc sst_acpi_haswell_desc = { 183static struct sst_acpi_desc sst_acpi_haswell_desc = {
188 .drv_name = "haswell-pcm-audio", 184 .drv_name = "haswell-pcm-audio",
189 .machines = haswell_machines, 185 .machines = snd_soc_acpi_intel_haswell_machines,
190 .resindex_lpe_base = 0, 186 .resindex_lpe_base = 0,
191 .resindex_pcicfg_base = 1, 187 .resindex_pcicfg_base = 1,
192 .resindex_fw_base = -1, 188 .resindex_fw_base = -1,
@@ -197,15 +193,9 @@ static struct sst_acpi_desc sst_acpi_haswell_desc = {
197 .dma_size = SST_LPT_DSP_DMA_SIZE, 193 .dma_size = SST_LPT_DSP_DMA_SIZE,
198}; 194};
199 195
200static struct sst_acpi_mach broadwell_machines[] = {
201 { "INT343A", "broadwell-audio", "intel/IntcSST2.bin", NULL, NULL, NULL },
202 { "RT5677CE", "bdw-rt5677", "intel/IntcSST2.bin", NULL, NULL, NULL },
203 {}
204};
205
206static struct sst_acpi_desc sst_acpi_broadwell_desc = { 196static struct sst_acpi_desc sst_acpi_broadwell_desc = {
207 .drv_name = "haswell-pcm-audio", 197 .drv_name = "haswell-pcm-audio",
208 .machines = broadwell_machines, 198 .machines = snd_soc_acpi_intel_broadwell_machines,
209 .resindex_lpe_base = 0, 199 .resindex_lpe_base = 0,
210 .resindex_pcicfg_base = 1, 200 .resindex_pcicfg_base = 1,
211 .resindex_fw_base = -1, 201 .resindex_fw_base = -1,
@@ -217,15 +207,9 @@ static struct sst_acpi_desc sst_acpi_broadwell_desc = {
217}; 207};
218 208
219#if !IS_ENABLED(CONFIG_SND_SST_IPC_ACPI) 209#if !IS_ENABLED(CONFIG_SND_SST_IPC_ACPI)
220static struct sst_acpi_mach baytrail_machines[] = {
221 { "10EC5640", "byt-rt5640", "intel/fw_sst_0f28.bin-48kHz_i2s_master", NULL, NULL, NULL },
222 { "193C9890", "byt-max98090", "intel/fw_sst_0f28.bin-48kHz_i2s_master", NULL, NULL, NULL },
223 {}
224};
225
226static struct sst_acpi_desc sst_acpi_baytrail_desc = { 210static struct sst_acpi_desc sst_acpi_baytrail_desc = {
227 .drv_name = "baytrail-pcm-audio", 211 .drv_name = "baytrail-pcm-audio",
228 .machines = baytrail_machines, 212 .machines = snd_soc_acpi_intel_baytrail_legacy_machines,
229 .resindex_lpe_base = 0, 213 .resindex_lpe_base = 0,
230 .resindex_pcicfg_base = 1, 214 .resindex_pcicfg_base = 1,
231 .resindex_fw_base = 2, 215 .resindex_fw_base = 2,
diff --git a/sound/soc/intel/common/sst-acpi.h b/sound/soc/intel/common/sst-acpi.h
deleted file mode 100644
index afe9b87b8bd5..000000000000
--- a/sound/soc/intel/common/sst-acpi.h
+++ /dev/null
@@ -1,82 +0,0 @@
1/*
2 * Copyright (C) 2013-15, Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License version
6 * 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
15#include <linux/stddef.h>
16#include <linux/acpi.h>
17
18struct sst_acpi_package_context {
19 char *name; /* package name */
20 int length; /* number of elements */
21 struct acpi_buffer *format;
22 struct acpi_buffer *state;
23 bool data_valid;
24};
25
26#if IS_ENABLED(CONFIG_ACPI)
27/* translation fron HID to I2C name, needed for DAI codec_name */
28const char *sst_acpi_find_name_from_hid(const u8 hid[ACPI_ID_LEN]);
29bool sst_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
30 struct sst_acpi_package_context *ctx);
31#else
32static inline const char *sst_acpi_find_name_from_hid(const u8 hid[ACPI_ID_LEN])
33{
34 return NULL;
35}
36static inline bool sst_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
37 struct sst_acpi_package_context *ctx)
38{
39 return false;
40}
41#endif
42
43/* acpi match */
44struct sst_acpi_mach *sst_acpi_find_machine(struct sst_acpi_mach *machines);
45
46/* acpi check hid */
47bool sst_acpi_check_hid(const u8 hid[ACPI_ID_LEN]);
48
49/* Descriptor for SST ASoC machine driver */
50struct sst_acpi_mach {
51 /* ACPI ID for the matching machine driver. Audio codec for instance */
52 const u8 id[ACPI_ID_LEN];
53 /* machine driver name */
54 const char *drv_name;
55 /* firmware file name */
56 const char *fw_filename;
57
58 /* board name */
59 const char *board;
60 struct sst_acpi_mach * (*machine_quirk)(void *arg);
61 const void *quirk_data;
62 void *pdata;
63};
64
65#define SST_ACPI_MAX_CODECS 3
66
67/**
68 * struct sst_codecs: Structure to hold secondary codec information apart from
69 * the matched one, this data will be passed to the quirk function to match
70 * with the ACPI detected devices
71 *
72 * @num_codecs: number of secondary codecs used in the platform
73 * @codecs: holds the codec IDs
74 *
75 */
76struct sst_codecs {
77 int num_codecs;
78 u8 codecs[SST_ACPI_MAX_CODECS][ACPI_ID_LEN];
79};
80
81/* check all codecs */
82struct sst_acpi_mach *sst_acpi_codec_list(void *arg);
diff --git a/sound/soc/intel/common/sst-firmware.c b/sound/soc/intel/common/sst-firmware.c
index a086c35f91bb..657afc02f1c4 100644
--- a/sound/soc/intel/common/sst-firmware.c
+++ b/sound/soc/intel/common/sst-firmware.c
@@ -19,6 +19,7 @@
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/firmware.h> 20#include <linux/firmware.h>
21#include <linux/export.h> 21#include <linux/export.h>
22#include <linux/module.h>
22#include <linux/platform_device.h> 23#include <linux/platform_device.h>
23#include <linux/dma-mapping.h> 24#include <linux/dma-mapping.h>
24#include <linux/dmaengine.h> 25#include <linux/dmaengine.h>
@@ -274,7 +275,6 @@ int sst_dma_new(struct sst_dsp *sst)
274 struct sst_pdata *sst_pdata = sst->pdata; 275 struct sst_pdata *sst_pdata = sst->pdata;
275 struct sst_dma *dma; 276 struct sst_dma *dma;
276 struct resource mem; 277 struct resource mem;
277 const char *dma_dev_name;
278 int ret = 0; 278 int ret = 0;
279 279
280 if (sst->pdata->resindex_dma_base == -1) 280 if (sst->pdata->resindex_dma_base == -1)
@@ -285,7 +285,6 @@ int sst_dma_new(struct sst_dsp *sst)
285 * is attached to the ADSP IP. */ 285 * is attached to the ADSP IP. */
286 switch (sst->pdata->dma_engine) { 286 switch (sst->pdata->dma_engine) {
287 case SST_DMA_TYPE_DW: 287 case SST_DMA_TYPE_DW:
288 dma_dev_name = "dw_dmac";
289 break; 288 break;
290 default: 289 default:
291 dev_err(sst->dev, "error: invalid DMA engine %d\n", 290 dev_err(sst->dev, "error: invalid DMA engine %d\n",
diff --git a/sound/soc/intel/skylake/skl-messages.c b/sound/soc/intel/skylake/skl-messages.c
index 89f70133c8e4..61b5bfa79d13 100644
--- a/sound/soc/intel/skylake/skl-messages.c
+++ b/sound/soc/intel/skylake/skl-messages.c
@@ -613,8 +613,10 @@ skip_buf_size_calc:
613} 613}
614 614
615#define DMA_CONTROL_ID 5 615#define DMA_CONTROL_ID 5
616#define DMA_I2S_BLOB_SIZE 21
616 617
617int skl_dsp_set_dma_control(struct skl_sst *ctx, struct skl_module_cfg *mconfig) 618int skl_dsp_set_dma_control(struct skl_sst *ctx, u32 *caps,
619 u32 caps_size, u32 node_id)
618{ 620{
619 struct skl_dma_control *dma_ctrl; 621 struct skl_dma_control *dma_ctrl;
620 struct skl_ipc_large_config_msg msg = {0}; 622 struct skl_ipc_large_config_msg msg = {0};
@@ -624,24 +626,27 @@ int skl_dsp_set_dma_control(struct skl_sst *ctx, struct skl_module_cfg *mconfig)
624 /* 626 /*
625 * if blob size zero, then return 627 * if blob size zero, then return
626 */ 628 */
627 if (mconfig->formats_config.caps_size == 0) 629 if (caps_size == 0)
628 return 0; 630 return 0;
629 631
630 msg.large_param_id = DMA_CONTROL_ID; 632 msg.large_param_id = DMA_CONTROL_ID;
631 msg.param_data_size = sizeof(struct skl_dma_control) + 633 msg.param_data_size = sizeof(struct skl_dma_control) + caps_size;
632 mconfig->formats_config.caps_size;
633 634
634 dma_ctrl = kzalloc(msg.param_data_size, GFP_KERNEL); 635 dma_ctrl = kzalloc(msg.param_data_size, GFP_KERNEL);
635 if (dma_ctrl == NULL) 636 if (dma_ctrl == NULL)
636 return -ENOMEM; 637 return -ENOMEM;
637 638
638 dma_ctrl->node_id = skl_get_node_id(ctx, mconfig); 639 dma_ctrl->node_id = node_id;
639 640
640 /* size in dwords */ 641 /*
641 dma_ctrl->config_length = mconfig->formats_config.caps_size / 4; 642 * NHLT blob may contain additional configs along with i2s blob.
643 * firmware expects only the i2s blob size as the config_length.
644 * So fix to i2s blob size.
645 * size in dwords.
646 */
647 dma_ctrl->config_length = DMA_I2S_BLOB_SIZE;
642 648
643 memcpy(dma_ctrl->config_data, mconfig->formats_config.caps, 649 memcpy(dma_ctrl->config_data, caps, caps_size);
644 mconfig->formats_config.caps_size);
645 650
646 err = skl_ipc_set_large_config(&ctx->ipc, &msg, (u32 *)dma_ctrl); 651 err = skl_ipc_set_large_config(&ctx->ipc, &msg, (u32 *)dma_ctrl);
647 652
@@ -702,18 +707,11 @@ static void skl_set_updown_mixer_format(struct skl_sst *ctx,
702 struct skl_module *module = mconfig->module; 707 struct skl_module *module = mconfig->module;
703 struct skl_module_iface *iface = &module->formats[mconfig->fmt_idx]; 708 struct skl_module_iface *iface = &module->formats[mconfig->fmt_idx];
704 struct skl_module_fmt *fmt = &iface->outputs[0].fmt; 709 struct skl_module_fmt *fmt = &iface->outputs[0].fmt;
705 int i = 0;
706 710
707 skl_set_base_module_format(ctx, mconfig, 711 skl_set_base_module_format(ctx, mconfig,
708 (struct skl_base_cfg *)mixer_mconfig); 712 (struct skl_base_cfg *)mixer_mconfig);
709 mixer_mconfig->out_ch_cfg = fmt->ch_cfg; 713 mixer_mconfig->out_ch_cfg = fmt->ch_cfg;
710 714 mixer_mconfig->ch_map = fmt->ch_map;
711 /* Select F/W default coefficient */
712 mixer_mconfig->coeff_sel = 0x0;
713
714 /* User coeff, don't care since we are selecting F/W defaults */
715 for (i = 0; i < UP_DOWN_MIXER_MAX_COEFF; i++)
716 mixer_mconfig->coeff[i] = 0xDEADBEEF;
717} 715}
718 716
719/* 717/*
diff --git a/sound/soc/intel/skylake/skl-nhlt.c b/sound/soc/intel/skylake/skl-nhlt.c
index e7d766d56c8e..d14c50a60289 100644
--- a/sound/soc/intel/skylake/skl-nhlt.c
+++ b/sound/soc/intel/skylake/skl-nhlt.c
@@ -20,6 +20,8 @@
20#include <linux/pci.h> 20#include <linux/pci.h>
21#include "skl.h" 21#include "skl.h"
22 22
23#define NHLT_ACPI_HEADER_SIG "NHLT"
24
23/* Unique identification for getting NHLT blobs */ 25/* Unique identification for getting NHLT blobs */
24static guid_t osc_guid = 26static guid_t osc_guid =
25 GUID_INIT(0xA69F886E, 0x6CEB, 0x4594, 27 GUID_INIT(0xA69F886E, 0x6CEB, 0x4594,
@@ -45,6 +47,13 @@ struct nhlt_acpi_table *skl_nhlt_init(struct device *dev)
45 memremap(nhlt_ptr->min_addr, nhlt_ptr->length, 47 memremap(nhlt_ptr->min_addr, nhlt_ptr->length,
46 MEMREMAP_WB); 48 MEMREMAP_WB);
47 ACPI_FREE(obj); 49 ACPI_FREE(obj);
50 if (nhlt_table && (strncmp(nhlt_table->header.signature,
51 NHLT_ACPI_HEADER_SIG,
52 strlen(NHLT_ACPI_HEADER_SIG)) != 0)) {
53 memunmap(nhlt_table);
54 dev_err(dev, "NHLT ACPI header signature incorrect\n");
55 return NULL;
56 }
48 return nhlt_table; 57 return nhlt_table;
49 } 58 }
50 59
diff --git a/sound/soc/intel/skylake/skl-pcm.c b/sound/soc/intel/skylake/skl-pcm.c
index 2b1e513b1680..1dd97479e0c0 100644
--- a/sound/soc/intel/skylake/skl-pcm.c
+++ b/sound/soc/intel/skylake/skl-pcm.c
@@ -355,7 +355,8 @@ static void skl_pcm_close(struct snd_pcm_substream *substream,
355 } 355 }
356 356
357 mconfig = skl_tplg_fe_get_cpr_module(dai, substream->stream); 357 mconfig = skl_tplg_fe_get_cpr_module(dai, substream->stream);
358 skl_tplg_d0i3_put(skl, mconfig->d0i3_caps); 358 if (mconfig)
359 skl_tplg_d0i3_put(skl, mconfig->d0i3_caps);
359 360
360 kfree(dma_params); 361 kfree(dma_params);
361} 362}
@@ -652,7 +653,7 @@ static const struct snd_soc_dai_ops skl_link_dai_ops = {
652 .trigger = skl_link_pcm_trigger, 653 .trigger = skl_link_pcm_trigger,
653}; 654};
654 655
655static struct snd_soc_dai_driver skl_platform_dai[] = { 656static struct snd_soc_dai_driver skl_fe_dai[] = {
656{ 657{
657 .name = "System Pin", 658 .name = "System Pin",
658 .ops = &skl_pcm_dai_ops, 659 .ops = &skl_pcm_dai_ops,
@@ -796,8 +797,10 @@ static struct snd_soc_dai_driver skl_platform_dai[] = {
796 .sig_bits = 32, 797 .sig_bits = 32,
797 }, 798 },
798}, 799},
800};
799 801
800/* BE CPU Dais */ 802/* BE CPU Dais */
803static struct snd_soc_dai_driver skl_platform_dai[] = {
801{ 804{
802 .name = "SSP0 Pin", 805 .name = "SSP0 Pin",
803 .ops = &skl_be_ssp_dai_ops, 806 .ops = &skl_be_ssp_dai_ops,
@@ -975,6 +978,14 @@ static struct snd_soc_dai_driver skl_platform_dai[] = {
975}, 978},
976}; 979};
977 980
981int skl_dai_load(struct snd_soc_component *cmp,
982 struct snd_soc_dai_driver *pcm_dai)
983{
984 pcm_dai->ops = &skl_pcm_dai_ops;
985
986 return 0;
987}
988
978static int skl_platform_open(struct snd_pcm_substream *substream) 989static int skl_platform_open(struct snd_pcm_substream *substream)
979{ 990{
980 struct snd_soc_pcm_runtime *rtd = substream->private_data; 991 struct snd_soc_pcm_runtime *rtd = substream->private_data;
@@ -1362,6 +1373,8 @@ int skl_platform_register(struct device *dev)
1362 int ret; 1373 int ret;
1363 struct hdac_ext_bus *ebus = dev_get_drvdata(dev); 1374 struct hdac_ext_bus *ebus = dev_get_drvdata(dev);
1364 struct skl *skl = ebus_to_skl(ebus); 1375 struct skl *skl = ebus_to_skl(ebus);
1376 struct snd_soc_dai_driver *dais;
1377 int num_dais = ARRAY_SIZE(skl_platform_dai);
1365 1378
1366 INIT_LIST_HEAD(&skl->ppl_list); 1379 INIT_LIST_HEAD(&skl->ppl_list);
1367 INIT_LIST_HEAD(&skl->bind_list); 1380 INIT_LIST_HEAD(&skl->bind_list);
@@ -1371,14 +1384,38 @@ int skl_platform_register(struct device *dev)
1371 dev_err(dev, "soc platform registration failed %d\n", ret); 1384 dev_err(dev, "soc platform registration failed %d\n", ret);
1372 return ret; 1385 return ret;
1373 } 1386 }
1387
1388 skl->dais = kmemdup(skl_platform_dai, sizeof(skl_platform_dai),
1389 GFP_KERNEL);
1390 if (!skl->dais) {
1391 ret = -ENOMEM;
1392 goto err;
1393 }
1394
1395 if (!skl->use_tplg_pcm) {
1396 dais = krealloc(skl->dais, sizeof(skl_fe_dai) +
1397 sizeof(skl_platform_dai), GFP_KERNEL);
1398 if (!dais) {
1399 ret = -ENOMEM;
1400 goto err;
1401 }
1402
1403 skl->dais = dais;
1404 memcpy(&skl->dais[ARRAY_SIZE(skl_platform_dai)], skl_fe_dai,
1405 sizeof(skl_fe_dai));
1406 num_dais += ARRAY_SIZE(skl_fe_dai);
1407 }
1408
1374 ret = snd_soc_register_component(dev, &skl_component, 1409 ret = snd_soc_register_component(dev, &skl_component,
1375 skl_platform_dai, 1410 skl->dais, num_dais);
1376 ARRAY_SIZE(skl_platform_dai));
1377 if (ret) { 1411 if (ret) {
1378 dev_err(dev, "soc component registration failed %d\n", ret); 1412 dev_err(dev, "soc component registration failed %d\n", ret);
1379 snd_soc_unregister_platform(dev); 1413 goto err;
1380 } 1414 }
1381 1415
1416 return 0;
1417err:
1418 snd_soc_unregister_platform(dev);
1382 return ret; 1419 return ret;
1383 1420
1384} 1421}
@@ -1398,5 +1435,7 @@ int skl_platform_unregister(struct device *dev)
1398 1435
1399 snd_soc_unregister_component(dev); 1436 snd_soc_unregister_component(dev);
1400 snd_soc_unregister_platform(dev); 1437 snd_soc_unregister_platform(dev);
1438 kfree(skl->dais);
1439
1401 return 0; 1440 return 0;
1402} 1441}
diff --git a/sound/soc/intel/skylake/skl-sst-utils.c b/sound/soc/intel/skylake/skl-sst-utils.c
index 369ef7ce981c..8ff89280d9fd 100644
--- a/sound/soc/intel/skylake/skl-sst-utils.c
+++ b/sound/soc/intel/skylake/skl-sst-utils.c
@@ -251,6 +251,7 @@ int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw,
251 struct uuid_module *module; 251 struct uuid_module *module;
252 struct firmware stripped_fw; 252 struct firmware stripped_fw;
253 unsigned int safe_file; 253 unsigned int safe_file;
254 int ret = 0;
254 255
255 /* Get the FW pointer to derive ADSP header */ 256 /* Get the FW pointer to derive ADSP header */
256 stripped_fw.data = fw->data; 257 stripped_fw.data = fw->data;
@@ -299,8 +300,10 @@ int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw,
299 300
300 for (i = 0; i < num_entry; i++, mod_entry++) { 301 for (i = 0; i < num_entry; i++, mod_entry++) {
301 module = kzalloc(sizeof(*module), GFP_KERNEL); 302 module = kzalloc(sizeof(*module), GFP_KERNEL);
302 if (!module) 303 if (!module) {
303 return -ENOMEM; 304 ret = -ENOMEM;
305 goto free_uuid_list;
306 }
304 307
305 uuid_bin = (uuid_le *)mod_entry->uuid.id; 308 uuid_bin = (uuid_le *)mod_entry->uuid.id;
306 memcpy(&module->uuid, uuid_bin, sizeof(module->uuid)); 309 memcpy(&module->uuid, uuid_bin, sizeof(module->uuid));
@@ -311,8 +314,8 @@ int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw,
311 size = sizeof(int) * mod_entry->instance_max_count; 314 size = sizeof(int) * mod_entry->instance_max_count;
312 module->instance_id = devm_kzalloc(ctx->dev, size, GFP_KERNEL); 315 module->instance_id = devm_kzalloc(ctx->dev, size, GFP_KERNEL);
313 if (!module->instance_id) { 316 if (!module->instance_id) {
314 kfree(module); 317 ret = -ENOMEM;
315 return -ENOMEM; 318 goto free_uuid_list;
316 } 319 }
317 320
318 list_add_tail(&module->list, &skl->uuid_list); 321 list_add_tail(&module->list, &skl->uuid_list);
@@ -323,6 +326,10 @@ int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw,
323 } 326 }
324 327
325 return 0; 328 return 0;
329
330free_uuid_list:
331 skl_freeup_uuid_list(skl);
332 return ret;
326} 333}
327 334
328void skl_freeup_uuid_list(struct skl_sst *ctx) 335void skl_freeup_uuid_list(struct skl_sst *ctx)
diff --git a/sound/soc/intel/skylake/skl-topology.c b/sound/soc/intel/skylake/skl-topology.c
index 22f768ca3c73..a072bcf209d2 100644
--- a/sound/soc/intel/skylake/skl-topology.c
+++ b/sound/soc/intel/skylake/skl-topology.c
@@ -2036,21 +2036,45 @@ static int skl_tplg_add_pipe(struct device *dev,
2036 return 0; 2036 return 0;
2037} 2037}
2038 2038
2039static int skl_tplg_fill_pin(struct device *dev, u32 tkn, 2039static int skl_tplg_get_uuid(struct device *dev, u8 *guid,
2040 struct snd_soc_tplg_vendor_uuid_elem *uuid_tkn)
2041{
2042 if (uuid_tkn->token == SKL_TKN_UUID) {
2043 memcpy(guid, &uuid_tkn->uuid, 16);
2044 return 0;
2045 }
2046
2047 dev_err(dev, "Not an UUID token %d\n", uuid_tkn->token);
2048
2049 return -EINVAL;
2050}
2051
2052static int skl_tplg_fill_pin(struct device *dev,
2053 struct snd_soc_tplg_vendor_value_elem *tkn_elem,
2040 struct skl_module_pin *m_pin, 2054 struct skl_module_pin *m_pin,
2041 int pin_index, u32 value) 2055 int pin_index)
2042{ 2056{
2043 switch (tkn) { 2057 int ret;
2058
2059 switch (tkn_elem->token) {
2044 case SKL_TKN_U32_PIN_MOD_ID: 2060 case SKL_TKN_U32_PIN_MOD_ID:
2045 m_pin[pin_index].id.module_id = value; 2061 m_pin[pin_index].id.module_id = tkn_elem->value;
2046 break; 2062 break;
2047 2063
2048 case SKL_TKN_U32_PIN_INST_ID: 2064 case SKL_TKN_U32_PIN_INST_ID:
2049 m_pin[pin_index].id.instance_id = value; 2065 m_pin[pin_index].id.instance_id = tkn_elem->value;
2066 break;
2067
2068 case SKL_TKN_UUID:
2069 ret = skl_tplg_get_uuid(dev, m_pin[pin_index].id.mod_uuid.b,
2070 (struct snd_soc_tplg_vendor_uuid_elem *)tkn_elem);
2071 if (ret < 0)
2072 return ret;
2073
2050 break; 2074 break;
2051 2075
2052 default: 2076 default:
2053 dev_err(dev, "%d Not a pin token\n", value); 2077 dev_err(dev, "%d Not a pin token\n", tkn_elem->token);
2054 return -EINVAL; 2078 return -EINVAL;
2055 } 2079 }
2056 2080
@@ -2083,9 +2107,7 @@ static int skl_tplg_fill_pins_info(struct device *dev,
2083 return -EINVAL; 2107 return -EINVAL;
2084 } 2108 }
2085 2109
2086 ret = skl_tplg_fill_pin(dev, tkn_elem->token, 2110 ret = skl_tplg_fill_pin(dev, tkn_elem, m_pin, pin_count);
2087 m_pin, pin_count, tkn_elem->value);
2088
2089 if (ret < 0) 2111 if (ret < 0)
2090 return ret; 2112 return ret;
2091 2113
@@ -2170,19 +2192,6 @@ static int skl_tplg_widget_fill_fmt(struct device *dev,
2170 return skl_tplg_fill_fmt(dev, dst_fmt, tkn, val); 2192 return skl_tplg_fill_fmt(dev, dst_fmt, tkn, val);
2171} 2193}
2172 2194
2173static int skl_tplg_get_uuid(struct device *dev, struct skl_module_cfg *mconfig,
2174 struct snd_soc_tplg_vendor_uuid_elem *uuid_tkn)
2175{
2176 if (uuid_tkn->token == SKL_TKN_UUID)
2177 memcpy(&mconfig->guid, &uuid_tkn->uuid, 16);
2178 else {
2179 dev_err(dev, "Not an UUID token tkn %d\n", uuid_tkn->token);
2180 return -EINVAL;
2181 }
2182
2183 return 0;
2184}
2185
2186static void skl_tplg_fill_pin_dynamic_val( 2195static void skl_tplg_fill_pin_dynamic_val(
2187 struct skl_module_pin *mpin, u32 pin_count, u32 value) 2196 struct skl_module_pin *mpin, u32 pin_count, u32 value)
2188{ 2197{
@@ -2382,7 +2391,7 @@ static int skl_tplg_get_token(struct device *dev,
2382 case SKL_TKN_U32_MAX_MCPS: 2391 case SKL_TKN_U32_MAX_MCPS:
2383 case SKL_TKN_U32_OBS: 2392 case SKL_TKN_U32_OBS:
2384 case SKL_TKN_U32_IBS: 2393 case SKL_TKN_U32_IBS:
2385 ret = skl_tplg_fill_res_tkn(dev, tkn_elem, res, dir, pin_index); 2394 ret = skl_tplg_fill_res_tkn(dev, tkn_elem, res, pin_index, dir);
2386 if (ret < 0) 2395 if (ret < 0)
2387 return ret; 2396 return ret;
2388 2397
@@ -2488,6 +2497,7 @@ static int skl_tplg_get_token(struct device *dev,
2488 2497
2489 case SKL_TKN_U32_PIN_MOD_ID: 2498 case SKL_TKN_U32_PIN_MOD_ID:
2490 case SKL_TKN_U32_PIN_INST_ID: 2499 case SKL_TKN_U32_PIN_INST_ID:
2500 case SKL_TKN_UUID:
2491 ret = skl_tplg_fill_pins_info(dev, 2501 ret = skl_tplg_fill_pins_info(dev,
2492 mconfig, tkn_elem, dir, 2502 mconfig, tkn_elem, dir,
2493 pin_index); 2503 pin_index);
@@ -2550,6 +2560,7 @@ static int skl_tplg_get_tokens(struct device *dev,
2550 struct snd_soc_tplg_vendor_value_elem *tkn_elem; 2560 struct snd_soc_tplg_vendor_value_elem *tkn_elem;
2551 int tkn_count = 0, ret; 2561 int tkn_count = 0, ret;
2552 int off = 0, tuple_size = 0; 2562 int off = 0, tuple_size = 0;
2563 bool is_module_guid = true;
2553 2564
2554 if (block_size <= 0) 2565 if (block_size <= 0)
2555 return -EINVAL; 2566 return -EINVAL;
@@ -2565,7 +2576,15 @@ static int skl_tplg_get_tokens(struct device *dev,
2565 continue; 2576 continue;
2566 2577
2567 case SND_SOC_TPLG_TUPLE_TYPE_UUID: 2578 case SND_SOC_TPLG_TUPLE_TYPE_UUID:
2568 ret = skl_tplg_get_uuid(dev, mconfig, array->uuid); 2579 if (is_module_guid) {
2580 ret = skl_tplg_get_uuid(dev, mconfig->guid,
2581 array->uuid);
2582 is_module_guid = false;
2583 } else {
2584 ret = skl_tplg_get_token(dev, array->value, skl,
2585 mconfig);
2586 }
2587
2569 if (ret < 0) 2588 if (ret < 0)
2570 return ret; 2589 return ret;
2571 2590
@@ -3331,6 +3350,7 @@ static struct snd_soc_tplg_ops skl_tplg_ops = {
3331 .io_ops = skl_tplg_kcontrol_ops, 3350 .io_ops = skl_tplg_kcontrol_ops,
3332 .io_ops_count = ARRAY_SIZE(skl_tplg_kcontrol_ops), 3351 .io_ops_count = ARRAY_SIZE(skl_tplg_kcontrol_ops),
3333 .manifest = skl_manifest_load, 3352 .manifest = skl_manifest_load,
3353 .dai_load = skl_dai_load,
3334}; 3354};
3335 3355
3336/* 3356/*
@@ -3404,7 +3424,7 @@ int skl_tplg_init(struct snd_soc_platform *platform, struct hdac_ext_bus *ebus)
3404 3424
3405 ret = request_firmware(&fw, skl->tplg_name, bus->dev); 3425 ret = request_firmware(&fw, skl->tplg_name, bus->dev);
3406 if (ret < 0) { 3426 if (ret < 0) {
3407 dev_err(bus->dev, "tplg fw %s load failed with %d\n", 3427 dev_info(bus->dev, "tplg fw %s load failed with %d, falling back to dfw_sst.bin",
3408 skl->tplg_name, ret); 3428 skl->tplg_name, ret);
3409 ret = request_firmware(&fw, "dfw_sst.bin", bus->dev); 3429 ret = request_firmware(&fw, "dfw_sst.bin", bus->dev);
3410 if (ret < 0) { 3430 if (ret < 0) {
diff --git a/sound/soc/intel/skylake/skl-topology.h b/sound/soc/intel/skylake/skl-topology.h
index 2717db92036b..b6496513fe55 100644
--- a/sound/soc/intel/skylake/skl-topology.h
+++ b/sound/soc/intel/skylake/skl-topology.h
@@ -34,7 +34,7 @@
34#define MAX_FIXED_DMIC_PARAMS_SIZE 727 34#define MAX_FIXED_DMIC_PARAMS_SIZE 727
35 35
36/* Maximum number of coefficients up down mixer module */ 36/* Maximum number of coefficients up down mixer module */
37#define UP_DOWN_MIXER_MAX_COEFF 6 37#define UP_DOWN_MIXER_MAX_COEFF 8
38 38
39#define MODULE_MAX_IN_PINS 8 39#define MODULE_MAX_IN_PINS 8
40#define MODULE_MAX_OUT_PINS 8 40#define MODULE_MAX_OUT_PINS 8
@@ -161,6 +161,7 @@ struct skl_up_down_mixer_cfg {
161 u32 coeff_sel; 161 u32 coeff_sel;
162 /* Pass the user coeff in this array */ 162 /* Pass the user coeff in this array */
163 s32 coeff[UP_DOWN_MIXER_MAX_COEFF]; 163 s32 coeff[UP_DOWN_MIXER_MAX_COEFF];
164 u32 ch_map;
164} __packed; 165} __packed;
165 166
166struct skl_algo_cfg { 167struct skl_algo_cfg {
@@ -455,8 +456,8 @@ static inline struct skl *get_skl_ctx(struct device *dev)
455 456
456int skl_tplg_be_update_params(struct snd_soc_dai *dai, 457int skl_tplg_be_update_params(struct snd_soc_dai *dai,
457 struct skl_pipe_params *params); 458 struct skl_pipe_params *params);
458int skl_dsp_set_dma_control(struct skl_sst *ctx, 459int skl_dsp_set_dma_control(struct skl_sst *ctx, u32 *caps,
459 struct skl_module_cfg *mconfig); 460 u32 caps_size, u32 node_id);
460void skl_tplg_set_be_dmic_config(struct snd_soc_dai *dai, 461void skl_tplg_set_be_dmic_config(struct snd_soc_dai *dai,
461 struct skl_pipe_params *params, int stream); 462 struct skl_pipe_params *params, int stream);
462int skl_tplg_init(struct snd_soc_platform *platform, 463int skl_tplg_init(struct snd_soc_platform *platform,
@@ -501,4 +502,7 @@ int skl_pcm_host_dma_prepare(struct device *dev,
501 struct skl_pipe_params *params); 502 struct skl_pipe_params *params);
502int skl_pcm_link_dma_prepare(struct device *dev, 503int skl_pcm_link_dma_prepare(struct device *dev,
503 struct skl_pipe_params *params); 504 struct skl_pipe_params *params);
505
506int skl_dai_load(struct snd_soc_component *cmp,
507 struct snd_soc_dai_driver *pcm_dai);
504#endif 508#endif
diff --git a/sound/soc/intel/skylake/skl.c b/sound/soc/intel/skylake/skl.c
index f94b484abb99..31d8634e8aa1 100644
--- a/sound/soc/intel/skylake/skl.c
+++ b/sound/soc/intel/skylake/skl.c
@@ -28,7 +28,7 @@
28#include <linux/firmware.h> 28#include <linux/firmware.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <sound/pcm.h> 30#include <sound/pcm.h>
31#include "../common/sst-acpi.h" 31#include <sound/soc-acpi.h>
32#include <sound/hda_register.h> 32#include <sound/hda_register.h>
33#include <sound/hdaudio.h> 33#include <sound/hdaudio.h>
34#include <sound/hda_i915.h> 34#include <sound/hda_i915.h>
@@ -439,10 +439,10 @@ static int skl_machine_device_register(struct skl *skl, void *driver_data)
439{ 439{
440 struct hdac_bus *bus = ebus_to_hbus(&skl->ebus); 440 struct hdac_bus *bus = ebus_to_hbus(&skl->ebus);
441 struct platform_device *pdev; 441 struct platform_device *pdev;
442 struct sst_acpi_mach *mach = driver_data; 442 struct snd_soc_acpi_mach *mach = driver_data;
443 int ret; 443 int ret;
444 444
445 mach = sst_acpi_find_machine(mach); 445 mach = snd_soc_acpi_find_machine(mach);
446 if (mach == NULL) { 446 if (mach == NULL) {
447 dev_err(bus->dev, "No matching machine driver found\n"); 447 dev_err(bus->dev, "No matching machine driver found\n");
448 return -ENODEV; 448 return -ENODEV;
@@ -462,8 +462,11 @@ static int skl_machine_device_register(struct skl *skl, void *driver_data)
462 return -EIO; 462 return -EIO;
463 } 463 }
464 464
465 if (mach->pdata) 465 if (mach->pdata) {
466 skl->use_tplg_pcm =
467 ((struct skl_machine_pdata *)mach->pdata)->use_tplg_pcm;
466 dev_set_drvdata(&pdev->dev, mach->pdata); 468 dev_set_drvdata(&pdev->dev, mach->pdata);
469 }
467 470
468 skl->i2s_dev = pdev; 471 skl->i2s_dev = pdev;
469 472
@@ -875,33 +878,36 @@ static void skl_remove(struct pci_dev *pci)
875 dev_set_drvdata(&pci->dev, NULL); 878 dev_set_drvdata(&pci->dev, NULL);
876} 879}
877 880
878static struct sst_codecs skl_codecs = { 881static struct snd_soc_acpi_codecs skl_codecs = {
879 .num_codecs = 1, 882 .num_codecs = 1,
880 .codecs = {"10508825"} 883 .codecs = {"10508825"}
881}; 884};
882 885
883static struct sst_codecs kbl_codecs = { 886static struct snd_soc_acpi_codecs kbl_codecs = {
884 .num_codecs = 1, 887 .num_codecs = 1,
885 .codecs = {"10508825"} 888 .codecs = {"10508825"}
886}; 889};
887 890
888static struct sst_codecs bxt_codecs = { 891static struct snd_soc_acpi_codecs bxt_codecs = {
889 .num_codecs = 1, 892 .num_codecs = 1,
890 .codecs = {"MX98357A"} 893 .codecs = {"MX98357A"}
891}; 894};
892 895
893static struct sst_codecs kbl_poppy_codecs = { 896static struct snd_soc_acpi_codecs kbl_poppy_codecs = {
894 .num_codecs = 1, 897 .num_codecs = 1,
895 .codecs = {"10EC5663"} 898 .codecs = {"10EC5663"}
896}; 899};
897 900
898static struct sst_codecs kbl_5663_5514_codecs = { 901static struct snd_soc_acpi_codecs kbl_5663_5514_codecs = {
899 .num_codecs = 2, 902 .num_codecs = 2,
900 .codecs = {"10EC5663", "10EC5514"} 903 .codecs = {"10EC5663", "10EC5514"}
901}; 904};
902 905
906static struct skl_machine_pdata cnl_pdata = {
907 .use_tplg_pcm = true,
908};
903 909
904static struct sst_acpi_mach sst_skl_devdata[] = { 910static struct snd_soc_acpi_mach sst_skl_devdata[] = {
905 { 911 {
906 .id = "INT343A", 912 .id = "INT343A",
907 .drv_name = "skl_alc286s_i2s", 913 .drv_name = "skl_alc286s_i2s",
@@ -911,7 +917,7 @@ static struct sst_acpi_mach sst_skl_devdata[] = {
911 .id = "INT343B", 917 .id = "INT343B",
912 .drv_name = "skl_n88l25_s4567", 918 .drv_name = "skl_n88l25_s4567",
913 .fw_filename = "intel/dsp_fw_release.bin", 919 .fw_filename = "intel/dsp_fw_release.bin",
914 .machine_quirk = sst_acpi_codec_list, 920 .machine_quirk = snd_soc_acpi_codec_list,
915 .quirk_data = &skl_codecs, 921 .quirk_data = &skl_codecs,
916 .pdata = &skl_dmic_data 922 .pdata = &skl_dmic_data
917 }, 923 },
@@ -919,14 +925,14 @@ static struct sst_acpi_mach sst_skl_devdata[] = {
919 .id = "MX98357A", 925 .id = "MX98357A",
920 .drv_name = "skl_n88l25_m98357a", 926 .drv_name = "skl_n88l25_m98357a",
921 .fw_filename = "intel/dsp_fw_release.bin", 927 .fw_filename = "intel/dsp_fw_release.bin",
922 .machine_quirk = sst_acpi_codec_list, 928 .machine_quirk = snd_soc_acpi_codec_list,
923 .quirk_data = &skl_codecs, 929 .quirk_data = &skl_codecs,
924 .pdata = &skl_dmic_data 930 .pdata = &skl_dmic_data
925 }, 931 },
926 {} 932 {}
927}; 933};
928 934
929static struct sst_acpi_mach sst_bxtp_devdata[] = { 935static struct snd_soc_acpi_mach sst_bxtp_devdata[] = {
930 { 936 {
931 .id = "INT343A", 937 .id = "INT343A",
932 .drv_name = "bxt_alc298s_i2s", 938 .drv_name = "bxt_alc298s_i2s",
@@ -936,13 +942,13 @@ static struct sst_acpi_mach sst_bxtp_devdata[] = {
936 .id = "DLGS7219", 942 .id = "DLGS7219",
937 .drv_name = "bxt_da7219_max98357a_i2s", 943 .drv_name = "bxt_da7219_max98357a_i2s",
938 .fw_filename = "intel/dsp_fw_bxtn.bin", 944 .fw_filename = "intel/dsp_fw_bxtn.bin",
939 .machine_quirk = sst_acpi_codec_list, 945 .machine_quirk = snd_soc_acpi_codec_list,
940 .quirk_data = &bxt_codecs, 946 .quirk_data = &bxt_codecs,
941 }, 947 },
942 {} 948 {}
943}; 949};
944 950
945static struct sst_acpi_mach sst_kbl_devdata[] = { 951static struct snd_soc_acpi_mach sst_kbl_devdata[] = {
946 { 952 {
947 .id = "INT343A", 953 .id = "INT343A",
948 .drv_name = "kbl_alc286s_i2s", 954 .drv_name = "kbl_alc286s_i2s",
@@ -952,7 +958,7 @@ static struct sst_acpi_mach sst_kbl_devdata[] = {
952 .id = "INT343B", 958 .id = "INT343B",
953 .drv_name = "kbl_n88l25_s4567", 959 .drv_name = "kbl_n88l25_s4567",
954 .fw_filename = "intel/dsp_fw_kbl.bin", 960 .fw_filename = "intel/dsp_fw_kbl.bin",
955 .machine_quirk = sst_acpi_codec_list, 961 .machine_quirk = snd_soc_acpi_codec_list,
956 .quirk_data = &kbl_codecs, 962 .quirk_data = &kbl_codecs,
957 .pdata = &skl_dmic_data 963 .pdata = &skl_dmic_data
958 }, 964 },
@@ -960,7 +966,7 @@ static struct sst_acpi_mach sst_kbl_devdata[] = {
960 .id = "MX98357A", 966 .id = "MX98357A",
961 .drv_name = "kbl_n88l25_m98357a", 967 .drv_name = "kbl_n88l25_m98357a",
962 .fw_filename = "intel/dsp_fw_kbl.bin", 968 .fw_filename = "intel/dsp_fw_kbl.bin",
963 .machine_quirk = sst_acpi_codec_list, 969 .machine_quirk = snd_soc_acpi_codec_list,
964 .quirk_data = &kbl_codecs, 970 .quirk_data = &kbl_codecs,
965 .pdata = &skl_dmic_data 971 .pdata = &skl_dmic_data
966 }, 972 },
@@ -968,7 +974,7 @@ static struct sst_acpi_mach sst_kbl_devdata[] = {
968 .id = "MX98927", 974 .id = "MX98927",
969 .drv_name = "kbl_r5514_5663_max", 975 .drv_name = "kbl_r5514_5663_max",
970 .fw_filename = "intel/dsp_fw_kbl.bin", 976 .fw_filename = "intel/dsp_fw_kbl.bin",
971 .machine_quirk = sst_acpi_codec_list, 977 .machine_quirk = snd_soc_acpi_codec_list,
972 .quirk_data = &kbl_5663_5514_codecs, 978 .quirk_data = &kbl_5663_5514_codecs,
973 .pdata = &skl_dmic_data 979 .pdata = &skl_dmic_data
974 }, 980 },
@@ -976,7 +982,7 @@ static struct sst_acpi_mach sst_kbl_devdata[] = {
976 .id = "MX98927", 982 .id = "MX98927",
977 .drv_name = "kbl_rt5663_m98927", 983 .drv_name = "kbl_rt5663_m98927",
978 .fw_filename = "intel/dsp_fw_kbl.bin", 984 .fw_filename = "intel/dsp_fw_kbl.bin",
979 .machine_quirk = sst_acpi_codec_list, 985 .machine_quirk = snd_soc_acpi_codec_list,
980 .quirk_data = &kbl_poppy_codecs, 986 .quirk_data = &kbl_poppy_codecs,
981 .pdata = &skl_dmic_data 987 .pdata = &skl_dmic_data
982 }, 988 },
@@ -989,7 +995,7 @@ static struct sst_acpi_mach sst_kbl_devdata[] = {
989 {} 995 {}
990}; 996};
991 997
992static struct sst_acpi_mach sst_glk_devdata[] = { 998static struct snd_soc_acpi_mach sst_glk_devdata[] = {
993 { 999 {
994 .id = "INT343A", 1000 .id = "INT343A",
995 .drv_name = "glk_alc298s_i2s", 1001 .drv_name = "glk_alc298s_i2s",
@@ -998,12 +1004,14 @@ static struct sst_acpi_mach sst_glk_devdata[] = {
998 {} 1004 {}
999}; 1005};
1000 1006
1001static const struct sst_acpi_mach sst_cnl_devdata[] = { 1007static const struct snd_soc_acpi_mach sst_cnl_devdata[] = {
1002 { 1008 {
1003 .id = "INT34C2", 1009 .id = "INT34C2",
1004 .drv_name = "cnl_rt274", 1010 .drv_name = "cnl_rt274",
1005 .fw_filename = "intel/dsp_fw_cnl.bin", 1011 .fw_filename = "intel/dsp_fw_cnl.bin",
1012 .pdata = &cnl_pdata,
1006 }, 1013 },
1014 {}
1007}; 1015};
1008 1016
1009/* PCI IDs */ 1017/* PCI IDs */
diff --git a/sound/soc/intel/skylake/skl.h b/sound/soc/intel/skylake/skl.h
index 8d9d6899f761..e00cde8200dd 100644
--- a/sound/soc/intel/skylake/skl.h
+++ b/sound/soc/intel/skylake/skl.h
@@ -53,6 +53,7 @@ struct skl {
53 struct platform_device *dmic_dev; 53 struct platform_device *dmic_dev;
54 struct platform_device *i2s_dev; 54 struct platform_device *i2s_dev;
55 struct snd_soc_platform *platform; 55 struct snd_soc_platform *platform;
56 struct snd_soc_dai_driver *dais;
56 57
57 struct nhlt_acpi_table *nhlt; /* nhlt ptr */ 58 struct nhlt_acpi_table *nhlt; /* nhlt ptr */
58 struct skl_sst *skl_sst; /* sst skl ctx */ 59 struct skl_sst *skl_sst; /* sst skl ctx */
@@ -73,6 +74,7 @@ struct skl {
73 struct skl_debug *debugfs; 74 struct skl_debug *debugfs;
74 u8 nr_modules; 75 u8 nr_modules;
75 struct skl_module **modules; 76 struct skl_module **modules;
77 bool use_tplg_pcm;
76}; 78};
77 79
78#define skl_to_ebus(s) (&(s)->ebus) 80#define skl_to_ebus(s) (&(s)->ebus)
@@ -85,9 +87,9 @@ struct skl_dma_params {
85 u8 stream_tag; 87 u8 stream_tag;
86}; 88};
87 89
88/* to pass dmic data */
89struct skl_machine_pdata { 90struct skl_machine_pdata {
90 u32 dmic_num; 91 u32 dmic_num;
92 bool use_tplg_pcm; /* use dais and dai links from topology */
91}; 93};
92 94
93struct skl_dsp_ops { 95struct skl_dsp_ops {
diff --git a/sound/soc/kirkwood/kirkwood-dma.c b/sound/soc/kirkwood/kirkwood-dma.c
index cf23af159acf..505b0ff03c3b 100644
--- a/sound/soc/kirkwood/kirkwood-dma.c
+++ b/sound/soc/kirkwood/kirkwood-dma.c
@@ -318,7 +318,7 @@ static void kirkwood_dma_free_dma_buffers(struct snd_pcm *pcm)
318 } 318 }
319} 319}
320 320
321struct snd_soc_platform_driver kirkwood_soc_platform = { 321const struct snd_soc_platform_driver kirkwood_soc_platform = {
322 .ops = &kirkwood_dma_ops, 322 .ops = &kirkwood_dma_ops,
323 .pcm_new = kirkwood_dma_new, 323 .pcm_new = kirkwood_dma_new,
324 .pcm_free = kirkwood_dma_free_dma_buffers, 324 .pcm_free = kirkwood_dma_free_dma_buffers,
diff --git a/sound/soc/kirkwood/kirkwood.h b/sound/soc/kirkwood/kirkwood.h
index 90e32a781424..783cb1a4f30e 100644
--- a/sound/soc/kirkwood/kirkwood.h
+++ b/sound/soc/kirkwood/kirkwood.h
@@ -143,6 +143,6 @@ struct kirkwood_dma_data {
143 int burst; 143 int burst;
144}; 144};
145 145
146extern struct snd_soc_platform_driver kirkwood_soc_platform; 146extern const struct snd_soc_platform_driver kirkwood_soc_platform;
147 147
148#endif 148#endif
diff --git a/sound/soc/omap/ams-delta.c b/sound/soc/omap/ams-delta.c
index 6c49f3d6fd96..d40219678700 100644
--- a/sound/soc/omap/ams-delta.c
+++ b/sound/soc/omap/ams-delta.c
@@ -260,7 +260,7 @@ static bool cx81801_cmd_pending;
260static bool ams_delta_muted; 260static bool ams_delta_muted;
261static DEFINE_SPINLOCK(ams_delta_lock); 261static DEFINE_SPINLOCK(ams_delta_lock);
262 262
263static void cx81801_timeout(unsigned long data) 263static void cx81801_timeout(struct timer_list *unused)
264{ 264{
265 int muted; 265 int muted;
266 266
@@ -349,7 +349,7 @@ static void cx81801_receive(struct tty_struct *tty,
349 /* First modem response, complete setup procedure */ 349 /* First modem response, complete setup procedure */
350 350
351 /* Initialize timer used for config pulse generation */ 351 /* Initialize timer used for config pulse generation */
352 setup_timer(&cx81801_timer, cx81801_timeout, 0); 352 timer_setup(&cx81801_timer, cx81801_timeout, 0);
353 353
354 v253_ops.receive_buf(tty, cp, fp, count); 354 v253_ops.receive_buf(tty, cp, fp, count);
355 355
diff --git a/sound/soc/omap/omap-hdmi-audio.c b/sound/soc/omap/omap-hdmi-audio.c
index 3e9cc4842a1d..8eeac7cab1c1 100644
--- a/sound/soc/omap/omap-hdmi-audio.c
+++ b/sound/soc/omap/omap-hdmi-audio.c
@@ -362,6 +362,9 @@ static int omap_hdmi_audio_probe(struct platform_device *pdev)
362 362
363 card->name = devm_kasprintf(dev, GFP_KERNEL, 363 card->name = devm_kasprintf(dev, GFP_KERNEL,
364 "HDMI %s", dev_name(ad->dssdev)); 364 "HDMI %s", dev_name(ad->dssdev));
365 if (!card->name)
366 return -ENOMEM;
367
365 card->owner = THIS_MODULE; 368 card->owner = THIS_MODULE;
366 card->dai_link = 369 card->dai_link =
367 devm_kzalloc(dev, sizeof(*(card->dai_link)), GFP_KERNEL); 370 devm_kzalloc(dev, sizeof(*(card->dai_link)), GFP_KERNEL);
diff --git a/sound/soc/pxa/pxa2xx-ac97.c b/sound/soc/pxa/pxa2xx-ac97.c
index f49bf02e5ec2..803818aabee9 100644
--- a/sound/soc/pxa/pxa2xx-ac97.c
+++ b/sound/soc/pxa/pxa2xx-ac97.c
@@ -29,21 +29,41 @@
29 29
30static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97) 30static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
31{ 31{
32 pxa2xx_ac97_try_warm_reset(ac97); 32 pxa2xx_ac97_try_warm_reset();
33 33
34 pxa2xx_ac97_finish_reset(ac97); 34 pxa2xx_ac97_finish_reset();
35} 35}
36 36
37static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97) 37static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
38{ 38{
39 pxa2xx_ac97_try_cold_reset(ac97); 39 pxa2xx_ac97_try_cold_reset();
40 40
41 pxa2xx_ac97_finish_reset(ac97); 41 pxa2xx_ac97_finish_reset();
42}
43
44static unsigned short pxa2xx_ac97_legacy_read(struct snd_ac97 *ac97,
45 unsigned short reg)
46{
47 int ret;
48
49 ret = pxa2xx_ac97_read(ac97->num, reg);
50 if (ret < 0)
51 return 0;
52 else
53 return (unsigned short)(ret & 0xffff);
54}
55
56static void pxa2xx_ac97_legacy_write(struct snd_ac97 *ac97,
57 unsigned short reg, unsigned short val)
58{
59 int ret;
60
61 ret = pxa2xx_ac97_write(ac97->num, reg, val);
42} 62}
43 63
44static struct snd_ac97_bus_ops pxa2xx_ac97_ops = { 64static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
45 .read = pxa2xx_ac97_read, 65 .read = pxa2xx_ac97_legacy_read,
46 .write = pxa2xx_ac97_write, 66 .write = pxa2xx_ac97_legacy_write,
47 .warm_reset = pxa2xx_ac97_warm_reset, 67 .warm_reset = pxa2xx_ac97_warm_reset,
48 .reset = pxa2xx_ac97_cold_reset, 68 .reset = pxa2xx_ac97_cold_reset,
49}; 69};
diff --git a/sound/soc/qcom/lpass-platform.c b/sound/soc/qcom/lpass-platform.c
index e1945e1772cd..caf71aab8196 100644
--- a/sound/soc/qcom/lpass-platform.c
+++ b/sound/soc/qcom/lpass-platform.c
@@ -74,7 +74,6 @@ static int lpass_platform_pcmops_open(struct snd_pcm_substream *substream)
74 data->i2s_port = cpu_dai->driver->id; 74 data->i2s_port = cpu_dai->driver->id;
75 runtime->private_data = data; 75 runtime->private_data = data;
76 76
77 dma_ch = 0;
78 if (v->alloc_dma_channel) 77 if (v->alloc_dma_channel)
79 dma_ch = v->alloc_dma_channel(drvdata, dir); 78 dma_ch = v->alloc_dma_channel(drvdata, dir);
80 else 79 else
@@ -122,7 +121,6 @@ static int lpass_platform_pcmops_close(struct snd_pcm_substream *substream)
122 struct lpass_pcm_data *data; 121 struct lpass_pcm_data *data;
123 122
124 data = runtime->private_data; 123 data = runtime->private_data;
125 v = drvdata->variant;
126 drvdata->substream[data->dma_ch] = NULL; 124 drvdata->substream[data->dma_ch] = NULL;
127 if (v->free_dma_channel) 125 if (v->free_dma_channel)
128 v->free_dma_channel(drvdata, data->dma_ch); 126 v->free_dma_channel(drvdata, data->dma_ch);
diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c
index 0513fe480353..d64fbbd50544 100644
--- a/sound/soc/rockchip/rk3399_gru_sound.c
+++ b/sound/soc/rockchip/rk3399_gru_sound.c
@@ -23,6 +23,7 @@
23#include <linux/of_gpio.h> 23#include <linux/of_gpio.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/spi/spi.h> 25#include <linux/spi/spi.h>
26#include <linux/i2c.h>
26#include <linux/input.h> 27#include <linux/input.h>
27#include <sound/core.h> 28#include <sound/core.h>
28#include <sound/jack.h> 29#include <sound/jack.h>
@@ -47,18 +48,7 @@ static const struct snd_soc_dapm_widget rockchip_dapm_widgets[] = {
47 SND_SOC_DAPM_SPK("Speakers", NULL), 48 SND_SOC_DAPM_SPK("Speakers", NULL),
48 SND_SOC_DAPM_MIC("Headset Mic", NULL), 49 SND_SOC_DAPM_MIC("Headset Mic", NULL),
49 SND_SOC_DAPM_MIC("Int Mic", NULL), 50 SND_SOC_DAPM_MIC("Int Mic", NULL),
50}; 51 SND_SOC_DAPM_LINE("HDMI", NULL),
51
52static const struct snd_soc_dapm_route rockchip_dapm_routes[] = {
53 /* Input Lines */
54 {"MIC", NULL, "Headset Mic"},
55 {"DMIC1L", NULL, "Int Mic"},
56 {"DMIC1R", NULL, "Int Mic"},
57
58 /* Output Lines */
59 {"Headphones", NULL, "HPL"},
60 {"Headphones", NULL, "HPR"},
61 {"Speakers", NULL, "Speaker"},
62}; 52};
63 53
64static const struct snd_kcontrol_new rockchip_controls[] = { 54static const struct snd_kcontrol_new rockchip_controls[] = {
@@ -66,6 +56,7 @@ static const struct snd_kcontrol_new rockchip_controls[] = {
66 SOC_DAPM_PIN_SWITCH("Speakers"), 56 SOC_DAPM_PIN_SWITCH("Speakers"),
67 SOC_DAPM_PIN_SWITCH("Headset Mic"), 57 SOC_DAPM_PIN_SWITCH("Headset Mic"),
68 SOC_DAPM_PIN_SWITCH("Int Mic"), 58 SOC_DAPM_PIN_SWITCH("Int Mic"),
59 SOC_DAPM_PIN_SWITCH("HDMI"),
69}; 60};
70 61
71static int rockchip_sound_max98357a_hw_params(struct snd_pcm_substream *substream, 62static int rockchip_sound_max98357a_hw_params(struct snd_pcm_substream *substream,
@@ -314,8 +305,6 @@ static struct snd_soc_card rockchip_sound_card = {
314 .owner = THIS_MODULE, 305 .owner = THIS_MODULE,
315 .dapm_widgets = rockchip_dapm_widgets, 306 .dapm_widgets = rockchip_dapm_widgets,
316 .num_dapm_widgets = ARRAY_SIZE(rockchip_dapm_widgets), 307 .num_dapm_widgets = ARRAY_SIZE(rockchip_dapm_widgets),
317 .dapm_routes = rockchip_dapm_routes,
318 .num_dapm_routes = ARRAY_SIZE(rockchip_dapm_routes),
319 .controls = rockchip_controls, 308 .controls = rockchip_controls,
320 .num_controls = ARRAY_SIZE(rockchip_controls), 309 .num_controls = ARRAY_SIZE(rockchip_controls),
321}; 310};
@@ -329,15 +318,6 @@ enum {
329 DAILINK_RT5514_DSP, 318 DAILINK_RT5514_DSP,
330}; 319};
331 320
332static const char * const dailink_compat[] = {
333 [DAILINK_CDNDP] = "rockchip,rk3399-cdn-dp",
334 [DAILINK_DA7219] = "dlg,da7219",
335 [DAILINK_DMIC] = "dmic-codec",
336 [DAILINK_MAX98357A] = "maxim,max98357a",
337 [DAILINK_RT5514] = "realtek,rt5514-i2c",
338 [DAILINK_RT5514_DSP] = "realtek,rt5514-spi",
339};
340
341static const struct snd_soc_dai_link rockchip_dais[] = { 321static const struct snd_soc_dai_link rockchip_dais[] = {
342 [DAILINK_CDNDP] = { 322 [DAILINK_CDNDP] = {
343 .name = "DP", 323 .name = "DP",
@@ -391,13 +371,117 @@ static const struct snd_soc_dai_link rockchip_dais[] = {
391 }, 371 },
392}; 372};
393 373
374static const struct snd_soc_dapm_route rockchip_sound_cdndp_routes[] = {
375 /* Output */
376 {"HDMI", NULL, "TX"},
377};
378
379static const struct snd_soc_dapm_route rockchip_sound_da7219_routes[] = {
380 /* Output */
381 {"Headphones", NULL, "HPL"},
382 {"Headphones", NULL, "HPR"},
383
384 /* Input */
385 {"MIC", NULL, "Headset Mic"},
386};
387
388static const struct snd_soc_dapm_route rockchip_sound_dmic_routes[] = {
389 /* Input */
390 {"DMic", NULL, "Int Mic"},
391};
392
393static const struct snd_soc_dapm_route rockchip_sound_max98357a_routes[] = {
394 /* Output */
395 {"Speakers", NULL, "Speaker"},
396};
397
398static const struct snd_soc_dapm_route rockchip_sound_rt5514_routes[] = {
399 /* Input */
400 {"DMIC1L", NULL, "Int Mic"},
401 {"DMIC1R", NULL, "Int Mic"},
402};
403
404struct rockchip_sound_route {
405 const struct snd_soc_dapm_route *routes;
406 int num_routes;
407};
408
409static const struct rockchip_sound_route rockchip_routes[] = {
410 [DAILINK_CDNDP] = {
411 .routes = rockchip_sound_cdndp_routes,
412 .num_routes = ARRAY_SIZE(rockchip_sound_cdndp_routes),
413 },
414 [DAILINK_DA7219] = {
415 .routes = rockchip_sound_da7219_routes,
416 .num_routes = ARRAY_SIZE(rockchip_sound_da7219_routes),
417 },
418 [DAILINK_DMIC] = {
419 .routes = rockchip_sound_dmic_routes,
420 .num_routes = ARRAY_SIZE(rockchip_sound_dmic_routes),
421 },
422 [DAILINK_MAX98357A] = {
423 .routes = rockchip_sound_max98357a_routes,
424 .num_routes = ARRAY_SIZE(rockchip_sound_max98357a_routes),
425 },
426 [DAILINK_RT5514] = {
427 .routes = rockchip_sound_rt5514_routes,
428 .num_routes = ARRAY_SIZE(rockchip_sound_rt5514_routes),
429 },
430 [DAILINK_RT5514_DSP] = {},
431};
432
433struct dailink_match_data {
434 const char *compatible;
435 struct bus_type *bus_type;
436};
437
438static const struct dailink_match_data dailink_match[] = {
439 [DAILINK_CDNDP] = {
440 .compatible = "rockchip,rk3399-cdn-dp",
441 },
442 [DAILINK_DA7219] = {
443 .compatible = "dlg,da7219",
444 },
445 [DAILINK_DMIC] = {
446 .compatible = "dmic-codec",
447 },
448 [DAILINK_MAX98357A] = {
449 .compatible = "maxim,max98357a",
450 },
451 [DAILINK_RT5514] = {
452 .compatible = "realtek,rt5514",
453 .bus_type = &i2c_bus_type,
454 },
455 [DAILINK_RT5514_DSP] = {
456 .compatible = "realtek,rt5514",
457 .bus_type = &spi_bus_type,
458 },
459};
460
461static int of_dev_node_match(struct device *dev, void *data)
462{
463 return dev->of_node == data;
464}
465
394static int rockchip_sound_codec_node_match(struct device_node *np_codec) 466static int rockchip_sound_codec_node_match(struct device_node *np_codec)
395{ 467{
468 struct device *dev;
396 int i; 469 int i;
397 470
398 for (i = 0; i < ARRAY_SIZE(dailink_compat); i++) { 471 for (i = 0; i < ARRAY_SIZE(dailink_match); i++) {
399 if (of_device_is_compatible(np_codec, dailink_compat[i])) 472 if (!of_device_is_compatible(np_codec,
400 return i; 473 dailink_match[i].compatible))
474 continue;
475
476 if (dailink_match[i].bus_type) {
477 dev = bus_find_device(dailink_match[i].bus_type, NULL,
478 np_codec, of_dev_node_match);
479 if (!dev)
480 continue;
481 put_device(dev);
482 }
483
484 return i;
401 } 485 }
402 return -1; 486 return -1;
403} 487}
@@ -408,16 +492,28 @@ static int rockchip_sound_of_parse_dais(struct device *dev,
408 struct device_node *np_cpu, *np_cpu0, *np_cpu1; 492 struct device_node *np_cpu, *np_cpu0, *np_cpu1;
409 struct device_node *np_codec; 493 struct device_node *np_codec;
410 struct snd_soc_dai_link *dai; 494 struct snd_soc_dai_link *dai;
495 struct snd_soc_dapm_route *routes;
411 int i, index; 496 int i, index;
497 int num_routes;
412 498
413 card->dai_link = devm_kzalloc(dev, sizeof(rockchip_dais), 499 card->dai_link = devm_kzalloc(dev, sizeof(rockchip_dais),
414 GFP_KERNEL); 500 GFP_KERNEL);
415 if (!card->dai_link) 501 if (!card->dai_link)
416 return -ENOMEM; 502 return -ENOMEM;
417 503
504 num_routes = 0;
505 for (i = 0; i < ARRAY_SIZE(rockchip_routes); i++)
506 num_routes += rockchip_routes[i].num_routes;
507 routes = devm_kzalloc(dev, num_routes * sizeof(*routes),
508 GFP_KERNEL);
509 if (!routes)
510 return -ENOMEM;
511 card->dapm_routes = routes;
512
418 np_cpu0 = of_parse_phandle(dev->of_node, "rockchip,cpu", 0); 513 np_cpu0 = of_parse_phandle(dev->of_node, "rockchip,cpu", 0);
419 np_cpu1 = of_parse_phandle(dev->of_node, "rockchip,cpu", 1); 514 np_cpu1 = of_parse_phandle(dev->of_node, "rockchip,cpu", 1);
420 515
516 card->num_dapm_routes = 0;
421 card->num_links = 0; 517 card->num_links = 0;
422 for (i = 0; i < ARRAY_SIZE(rockchip_dais); i++) { 518 for (i = 0; i < ARRAY_SIZE(rockchip_dais); i++) {
423 np_codec = of_parse_phandle(dev->of_node, 519 np_codec = of_parse_phandle(dev->of_node,
@@ -445,6 +541,17 @@ static int rockchip_sound_of_parse_dais(struct device *dev,
445 dai->codec_of_node = np_codec; 541 dai->codec_of_node = np_codec;
446 dai->platform_of_node = np_cpu; 542 dai->platform_of_node = np_cpu;
447 dai->cpu_of_node = np_cpu; 543 dai->cpu_of_node = np_cpu;
544
545 if (card->num_dapm_routes + rockchip_routes[index].num_routes >
546 num_routes) {
547 dev_err(dev, "Too many routes\n");
548 return -EINVAL;
549 }
550
551 memcpy(routes + card->num_dapm_routes,
552 rockchip_routes[index].routes,
553 rockchip_routes[index].num_routes * sizeof(*routes));
554 card->num_dapm_routes += rockchip_routes[index].num_routes;
448 } 555 }
449 556
450 return 0; 557 return 0;
diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c
index b6590467fd14..908211e1d6fc 100644
--- a/sound/soc/rockchip/rockchip_i2s.c
+++ b/sound/soc/rockchip/rockchip_i2s.c
@@ -692,7 +692,6 @@ static int rockchip_i2s_remove(struct platform_device *pdev)
692 if (!pm_runtime_status_suspended(&pdev->dev)) 692 if (!pm_runtime_status_suspended(&pdev->dev))
693 i2s_runtime_suspend(&pdev->dev); 693 i2s_runtime_suspend(&pdev->dev);
694 694
695 clk_disable_unprepare(i2s->mclk);
696 clk_disable_unprepare(i2s->hclk); 695 clk_disable_unprepare(i2s->hclk);
697 696
698 return 0; 697 return 0;
diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
index 10a4da06c0a1..233f1c9a4b6c 100644
--- a/sound/soc/samsung/i2s.c
+++ b/sound/soc/samsung/i2s.c
@@ -552,8 +552,11 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai,
552 } 552 }
553 553
554 ret = clk_prepare_enable(i2s->op_clk); 554 ret = clk_prepare_enable(i2s->op_clk);
555 if (ret) 555 if (ret) {
556 clk_put(i2s->op_clk);
557 i2s->op_clk = NULL;
556 goto err; 558 goto err;
559 }
557 i2s->rclk_srcrate = clk_get_rate(i2s->op_clk); 560 i2s->rclk_srcrate = clk_get_rate(i2s->op_clk);
558 561
559 /* Over-ride the other's */ 562 /* Over-ride the other's */
@@ -1096,6 +1099,7 @@ static struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev,
1096 i2s->pdev = pdev; 1099 i2s->pdev = pdev;
1097 i2s->pri_dai = NULL; 1100 i2s->pri_dai = NULL;
1098 i2s->sec_dai = NULL; 1101 i2s->sec_dai = NULL;
1102 i2s->i2s_dai_drv.id = 1;
1099 i2s->i2s_dai_drv.symmetric_rates = 1; 1103 i2s->i2s_dai_drv.symmetric_rates = 1;
1100 i2s->i2s_dai_drv.probe = samsung_i2s_dai_probe; 1104 i2s->i2s_dai_drv.probe = samsung_i2s_dai_probe;
1101 i2s->i2s_dai_drv.remove = samsung_i2s_dai_remove; 1105 i2s->i2s_dai_drv.remove = samsung_i2s_dai_remove;
@@ -1108,10 +1112,13 @@ static struct i2s_dai *i2s_alloc_dai(struct platform_device *pdev,
1108 i2s->i2s_dai_drv.playback.formats = SAMSUNG_I2S_FMTS; 1112 i2s->i2s_dai_drv.playback.formats = SAMSUNG_I2S_FMTS;
1109 1113
1110 if (!sec) { 1114 if (!sec) {
1115 i2s->i2s_dai_drv.name = SAMSUNG_I2S_DAI;
1111 i2s->i2s_dai_drv.capture.channels_min = 1; 1116 i2s->i2s_dai_drv.capture.channels_min = 1;
1112 i2s->i2s_dai_drv.capture.channels_max = 2; 1117 i2s->i2s_dai_drv.capture.channels_max = 2;
1113 i2s->i2s_dai_drv.capture.rates = i2s_dai_data->pcm_rates; 1118 i2s->i2s_dai_drv.capture.rates = i2s_dai_data->pcm_rates;
1114 i2s->i2s_dai_drv.capture.formats = SAMSUNG_I2S_FMTS; 1119 i2s->i2s_dai_drv.capture.formats = SAMSUNG_I2S_FMTS;
1120 } else {
1121 i2s->i2s_dai_drv.name = SAMSUNG_I2S_DAI_SEC;
1115 } 1122 }
1116 return i2s; 1123 return i2s;
1117} 1124}
@@ -1285,6 +1292,7 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1285 } 1292 }
1286 } 1293 }
1287 } 1294 }
1295 quirks &= ~(QUIRK_SEC_DAI | QUIRK_SUPPORTS_IDMA);
1288 1296
1289 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1297 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1290 pri_dai->addr = devm_ioremap_resource(&pdev->dev, res); 1298 pri_dai->addr = devm_ioremap_resource(&pdev->dev, res);
diff --git a/sound/soc/samsung/i2s.h b/sound/soc/samsung/i2s.h
index 21ff24e930db..79781de2f247 100644
--- a/sound/soc/samsung/i2s.h
+++ b/sound/soc/samsung/i2s.h
@@ -13,6 +13,9 @@
13#ifndef __SND_SOC_SAMSUNG_I2S_H 13#ifndef __SND_SOC_SAMSUNG_I2S_H
14#define __SND_SOC_SAMSUNG_I2S_H 14#define __SND_SOC_SAMSUNG_I2S_H
15 15
16#define SAMSUNG_I2S_DAI "samsung-i2s"
17#define SAMSUNG_I2S_DAI_SEC "samsung-i2s-sec"
18
16#define SAMSUNG_I2S_DIV_BCLK 1 19#define SAMSUNG_I2S_DIV_BCLK 1
17 20
18#define SAMSUNG_I2S_RCLKSRC_0 0 21#define SAMSUNG_I2S_RCLKSRC_0 0
diff --git a/sound/soc/samsung/tm2_wm5110.c b/sound/soc/samsung/tm2_wm5110.c
index 68698f3d72f9..a55d18703fe7 100644
--- a/sound/soc/samsung/tm2_wm5110.c
+++ b/sound/soc/samsung/tm2_wm5110.c
@@ -383,6 +383,7 @@ static struct snd_soc_dai_link tm2_dai_links[] = {
383 { 383 {
384 .name = "WM5110 AIF1", 384 .name = "WM5110 AIF1",
385 .stream_name = "HiFi Primary", 385 .stream_name = "HiFi Primary",
386 .cpu_dai_name = SAMSUNG_I2S_DAI,
386 .codec_dai_name = "wm5110-aif1", 387 .codec_dai_name = "wm5110-aif1",
387 .ops = &tm2_aif1_ops, 388 .ops = &tm2_aif1_ops,
388 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 389 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
@@ -390,6 +391,7 @@ static struct snd_soc_dai_link tm2_dai_links[] = {
390 }, { 391 }, {
391 .name = "WM5110 Voice", 392 .name = "WM5110 Voice",
392 .stream_name = "Voice call", 393 .stream_name = "Voice call",
394 .cpu_dai_name = SAMSUNG_I2S_DAI,
393 .codec_dai_name = "wm5110-aif2", 395 .codec_dai_name = "wm5110-aif2",
394 .ops = &tm2_aif2_ops, 396 .ops = &tm2_aif2_ops,
395 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 397 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
@@ -398,6 +400,7 @@ static struct snd_soc_dai_link tm2_dai_links[] = {
398 }, { 400 }, {
399 .name = "WM5110 BT", 401 .name = "WM5110 BT",
400 .stream_name = "Bluetooth", 402 .stream_name = "Bluetooth",
403 .cpu_dai_name = SAMSUNG_I2S_DAI,
401 .codec_dai_name = "wm5110-aif3", 404 .codec_dai_name = "wm5110-aif3",
402 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 405 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
403 SND_SOC_DAIFMT_CBM_CFM, 406 SND_SOC_DAIFMT_CBM_CFM,
@@ -436,8 +439,7 @@ static int tm2_probe(struct platform_device *pdev)
436 snd_soc_card_set_drvdata(card, priv); 439 snd_soc_card_set_drvdata(card, priv);
437 card->dev = dev; 440 card->dev = dev;
438 441
439 priv->gpio_mic_bias = devm_gpiod_get(dev, "mic-bias", 442 priv->gpio_mic_bias = devm_gpiod_get(dev, "mic-bias", GPIOD_OUT_HIGH);
440 GPIOF_OUT_INIT_LOW);
441 if (IS_ERR(priv->gpio_mic_bias)) { 443 if (IS_ERR(priv->gpio_mic_bias)) {
442 dev_err(dev, "Failed to get mic bias gpio\n"); 444 dev_err(dev, "Failed to get mic bias gpio\n");
443 return PTR_ERR(priv->gpio_mic_bias); 445 return PTR_ERR(priv->gpio_mic_bias);
@@ -477,7 +479,6 @@ static int tm2_probe(struct platform_device *pdev)
477 } 479 }
478 480
479 for (i = 0; i < card->num_links; i++) { 481 for (i = 0; i < card->num_links; i++) {
480 card->dai_link[i].cpu_dai_name = NULL;
481 card->dai_link[i].cpu_name = NULL; 482 card->dai_link[i].cpu_name = NULL;
482 card->dai_link[i].platform_name = NULL; 483 card->dai_link[i].platform_name = NULL;
483 card->dai_link[i].codec_of_node = codec_dai_node; 484 card->dai_link[i].codec_of_node = codec_dai_node;
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 6d3c7706d93f..c3aaf4788557 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -1932,14 +1932,9 @@ static int fsi_probe(struct platform_device *pdev)
1932 1932
1933 core = NULL; 1933 core = NULL;
1934 if (np) { 1934 if (np) {
1935 const struct of_device_id *of_id; 1935 core = of_device_get_match_data(&pdev->dev);
1936 1936 fsi_of_parse("fsia", np, &info.port_a, &pdev->dev);
1937 of_id = of_match_device(fsi_of_match, &pdev->dev); 1937 fsi_of_parse("fsib", np, &info.port_b, &pdev->dev);
1938 if (of_id) {
1939 core = of_id->data;
1940 fsi_of_parse("fsia", np, &info.port_a, &pdev->dev);
1941 fsi_of_parse("fsib", np, &info.port_b, &pdev->dev);
1942 }
1943 } else { 1938 } else {
1944 const struct platform_device_id *id_entry = pdev->id_entry; 1939 const struct platform_device_id *id_entry = pdev->id_entry;
1945 if (id_entry) 1940 if (id_entry)
diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c
index 938baff86ef2..8ddb08714faa 100644
--- a/sound/soc/sh/rcar/adg.c
+++ b/sound/soc/sh/rcar/adg.c
@@ -44,7 +44,6 @@ struct rsnd_adg {
44 44
45#define LRCLK_ASYNC (1 << 0) 45#define LRCLK_ASYNC (1 << 0)
46#define AUDIO_OUT_48 (1 << 1) 46#define AUDIO_OUT_48 (1 << 1)
47#define adg_mode_flags(adg) (adg->flags)
48 47
49#define for_each_rsnd_clk(pos, adg, i) \ 48#define for_each_rsnd_clk(pos, adg, i) \
50 for (i = 0; \ 49 for (i = 0; \
@@ -58,6 +57,13 @@ struct rsnd_adg {
58 i++) 57 i++)
59#define rsnd_priv_to_adg(priv) ((struct rsnd_adg *)(priv)->adg) 58#define rsnd_priv_to_adg(priv) ((struct rsnd_adg *)(priv)->adg)
60 59
60static const char * const clk_name[] = {
61 [CLKA] = "clk_a",
62 [CLKB] = "clk_b",
63 [CLKC] = "clk_c",
64 [CLKI] = "clk_i",
65};
66
61static u32 rsnd_adg_calculate_rbgx(unsigned long div) 67static u32 rsnd_adg_calculate_rbgx(unsigned long div)
62{ 68{
63 int i, ratio; 69 int i, ratio;
@@ -280,6 +286,7 @@ static void rsnd_adg_set_ssi_clk(struct rsnd_mod *ssi_mod, u32 val)
280 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); 286 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
281 struct rsnd_adg *adg = rsnd_priv_to_adg(priv); 287 struct rsnd_adg *adg = rsnd_priv_to_adg(priv);
282 struct rsnd_mod *adg_mod = rsnd_mod_get(adg); 288 struct rsnd_mod *adg_mod = rsnd_mod_get(adg);
289 struct device *dev = rsnd_priv_to_dev(priv);
283 int id = rsnd_mod_id(ssi_mod); 290 int id = rsnd_mod_id(ssi_mod);
284 int shift = (id % 4) * 8; 291 int shift = (id % 4) * 8;
285 u32 mask = 0xFF << shift; 292 u32 mask = 0xFF << shift;
@@ -306,12 +313,13 @@ static void rsnd_adg_set_ssi_clk(struct rsnd_mod *ssi_mod, u32 val)
306 rsnd_mod_bset(adg_mod, AUDIO_CLK_SEL2, mask, val); 313 rsnd_mod_bset(adg_mod, AUDIO_CLK_SEL2, mask, val);
307 break; 314 break;
308 } 315 }
316
317 dev_dbg(dev, "AUDIO_CLK_SEL is 0x%x\n", val);
309} 318}
310 319
311int rsnd_adg_clk_query(struct rsnd_priv *priv, unsigned int rate) 320int rsnd_adg_clk_query(struct rsnd_priv *priv, unsigned int rate)
312{ 321{
313 struct rsnd_adg *adg = rsnd_priv_to_adg(priv); 322 struct rsnd_adg *adg = rsnd_priv_to_adg(priv);
314 struct device *dev = rsnd_priv_to_dev(priv);
315 struct clk *clk; 323 struct clk *clk;
316 int i; 324 int i;
317 int sel_table[] = { 325 int sel_table[] = {
@@ -321,8 +329,6 @@ int rsnd_adg_clk_query(struct rsnd_priv *priv, unsigned int rate)
321 [CLKI] = 0x0, 329 [CLKI] = 0x0,
322 }; 330 };
323 331
324 dev_dbg(dev, "request clock = %d\n", rate);
325
326 /* 332 /*
327 * find suitable clock from 333 * find suitable clock from
328 * AUDIO_CLKA/AUDIO_CLKB/AUDIO_CLKC/AUDIO_CLKI. 334 * AUDIO_CLKA/AUDIO_CLKB/AUDIO_CLKC/AUDIO_CLKI.
@@ -366,8 +372,8 @@ int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *ssi_mod, unsigned int rate)
366 372
367 rsnd_adg_set_ssi_clk(ssi_mod, data); 373 rsnd_adg_set_ssi_clk(ssi_mod, data);
368 374
369 if (adg_mode_flags(adg) & LRCLK_ASYNC) { 375 if (rsnd_flags_has(adg, LRCLK_ASYNC)) {
370 if (adg_mode_flags(adg) & AUDIO_OUT_48) 376 if (rsnd_flags_has(adg, AUDIO_OUT_48))
371 ckr = 0x80000000; 377 ckr = 0x80000000;
372 } else { 378 } else {
373 if (0 == (rate % 8000)) 379 if (0 == (rate % 8000))
@@ -378,9 +384,10 @@ int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *ssi_mod, unsigned int rate)
378 rsnd_mod_write(adg_mod, BRRA, adg->rbga); 384 rsnd_mod_write(adg_mod, BRRA, adg->rbga);
379 rsnd_mod_write(adg_mod, BRRB, adg->rbgb); 385 rsnd_mod_write(adg_mod, BRRB, adg->rbgb);
380 386
381 dev_dbg(dev, "ADG: %s[%d] selects 0x%x for %d\n", 387 dev_dbg(dev, "CLKOUT is based on BRG%c (= %dHz)\n",
382 rsnd_mod_name(ssi_mod), rsnd_mod_id(ssi_mod), 388 (ckr) ? 'B' : 'A',
383 data, rate); 389 (ckr) ? adg->rbgb_rate_for_48khz :
390 adg->rbga_rate_for_441khz);
384 391
385 return 0; 392 return 0;
386} 393}
@@ -409,21 +416,12 @@ static void rsnd_adg_get_clkin(struct rsnd_priv *priv,
409{ 416{
410 struct device *dev = rsnd_priv_to_dev(priv); 417 struct device *dev = rsnd_priv_to_dev(priv);
411 struct clk *clk; 418 struct clk *clk;
412 static const char * const clk_name[] = {
413 [CLKA] = "clk_a",
414 [CLKB] = "clk_b",
415 [CLKC] = "clk_c",
416 [CLKI] = "clk_i",
417 };
418 int i; 419 int i;
419 420
420 for (i = 0; i < CLKMAX; i++) { 421 for (i = 0; i < CLKMAX; i++) {
421 clk = devm_clk_get(dev, clk_name[i]); 422 clk = devm_clk_get(dev, clk_name[i]);
422 adg->clk[i] = IS_ERR(clk) ? NULL : clk; 423 adg->clk[i] = IS_ERR(clk) ? NULL : clk;
423 } 424 }
424
425 for_each_rsnd_clk(clk, adg, i)
426 dev_dbg(dev, "clk %d : %p : %ld\n", i, clk, clk_get_rate(clk));
427} 425}
428 426
429static void rsnd_adg_get_clkout(struct rsnd_priv *priv, 427static void rsnd_adg_get_clkout(struct rsnd_priv *priv,
@@ -479,10 +477,10 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,
479 } 477 }
480 478
481 if (req_rate[0] % 48000 == 0) 479 if (req_rate[0] % 48000 == 0)
482 adg->flags = AUDIO_OUT_48; 480 rsnd_flags_set(adg, AUDIO_OUT_48);
483 481
484 if (of_get_property(np, "clkout-lr-asynchronous", NULL)) 482 if (of_get_property(np, "clkout-lr-asynchronous", NULL))
485 adg->flags = LRCLK_ASYNC; 483 rsnd_flags_set(adg, LRCLK_ASYNC);
486 484
487 /* 485 /*
488 * This driver is assuming that AUDIO_CLKA/AUDIO_CLKB/AUDIO_CLKC 486 * This driver is assuming that AUDIO_CLKA/AUDIO_CLKB/AUDIO_CLKC
@@ -512,7 +510,7 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,
512 adg->rbga_rate_for_441khz = rate / div; 510 adg->rbga_rate_for_441khz = rate / div;
513 ckr |= brg_table[i] << 20; 511 ckr |= brg_table[i] << 20;
514 if (req_441kHz_rate && 512 if (req_441kHz_rate &&
515 !(adg_mode_flags(adg) & AUDIO_OUT_48)) 513 !rsnd_flags_has(adg, AUDIO_OUT_48))
516 parent_clk_name = __clk_get_name(clk); 514 parent_clk_name = __clk_get_name(clk);
517 } 515 }
518 } 516 }
@@ -528,7 +526,7 @@ static void rsnd_adg_get_clkout(struct rsnd_priv *priv,
528 adg->rbgb_rate_for_48khz = rate / div; 526 adg->rbgb_rate_for_48khz = rate / div;
529 ckr |= brg_table[i] << 16; 527 ckr |= brg_table[i] << 16;
530 if (req_48kHz_rate && 528 if (req_48kHz_rate &&
531 (adg_mode_flags(adg) & AUDIO_OUT_48)) 529 rsnd_flags_has(adg, AUDIO_OUT_48))
532 parent_clk_name = __clk_get_name(clk); 530 parent_clk_name = __clk_get_name(clk);
533 } 531 }
534 } 532 }
@@ -572,12 +570,35 @@ rsnd_adg_get_clkout_end:
572 adg->ckr = ckr; 570 adg->ckr = ckr;
573 adg->rbga = rbga; 571 adg->rbga = rbga;
574 adg->rbgb = rbgb; 572 adg->rbgb = rbgb;
573}
574
575#ifdef DEBUG
576static void rsnd_adg_clk_dbg_info(struct rsnd_priv *priv, struct rsnd_adg *adg)
577{
578 struct device *dev = rsnd_priv_to_dev(priv);
579 struct clk *clk;
580 int i;
581
582 for_each_rsnd_clk(clk, adg, i)
583 dev_dbg(dev, "%s : %p : %ld\n",
584 clk_name[i], clk, clk_get_rate(clk));
575 585
576 for_each_rsnd_clkout(clk, adg, i)
577 dev_dbg(dev, "clkout %d : %p : %ld\n", i, clk, clk_get_rate(clk));
578 dev_dbg(dev, "BRGCKR = 0x%08x, BRRA/BRRB = 0x%x/0x%x\n", 586 dev_dbg(dev, "BRGCKR = 0x%08x, BRRA/BRRB = 0x%x/0x%x\n",
579 ckr, rbga, rbgb); 587 adg->ckr, adg->rbga, adg->rbgb);
588 dev_dbg(dev, "BRGA (for 44100 base) = %d\n", adg->rbga_rate_for_441khz);
589 dev_dbg(dev, "BRGB (for 48000 base) = %d\n", adg->rbgb_rate_for_48khz);
590
591 /*
592 * Actual CLKOUT will be exchanged in rsnd_adg_ssi_clk_try_start()
593 * by BRGCKR::BRGCKR_31
594 */
595 for_each_rsnd_clkout(clk, adg, i)
596 dev_dbg(dev, "clkout %d : %p : %ld\n", i,
597 clk, clk_get_rate(clk));
580} 598}
599#else
600#define rsnd_adg_clk_dbg_info(priv, adg)
601#endif
581 602
582int rsnd_adg_probe(struct rsnd_priv *priv) 603int rsnd_adg_probe(struct rsnd_priv *priv)
583{ 604{
@@ -596,6 +617,7 @@ int rsnd_adg_probe(struct rsnd_priv *priv)
596 617
597 rsnd_adg_get_clkin(priv, adg); 618 rsnd_adg_get_clkin(priv, adg);
598 rsnd_adg_get_clkout(priv, adg); 619 rsnd_adg_get_clkout(priv, adg);
620 rsnd_adg_clk_dbg_info(priv, adg);
599 621
600 priv->adg = adg; 622 priv->adg = adg;
601 623
diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
index 107133297e8d..c70eb2097816 100644
--- a/sound/soc/sh/rcar/core.c
+++ b/sound/soc/sh/rcar/core.c
@@ -121,14 +121,6 @@ void rsnd_mod_make_sure(struct rsnd_mod *mod, enum rsnd_mod_type type)
121 } 121 }
122} 122}
123 123
124char *rsnd_mod_name(struct rsnd_mod *mod)
125{
126 if (!mod || !mod->ops)
127 return "unknown";
128
129 return mod->ops->name;
130}
131
132struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io, 124struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io,
133 struct rsnd_mod *mod) 125 struct rsnd_mod *mod)
134{ 126{
@@ -172,8 +164,7 @@ int rsnd_mod_init(struct rsnd_priv *priv,
172 164
173void rsnd_mod_quit(struct rsnd_mod *mod) 165void rsnd_mod_quit(struct rsnd_mod *mod)
174{ 166{
175 if (mod->clk) 167 clk_unprepare(mod->clk);
176 clk_unprepare(mod->clk);
177 mod->clk = NULL; 168 mod->clk = NULL;
178} 169}
179 170
@@ -200,7 +191,10 @@ void rsnd_mod_interrupt(struct rsnd_mod *mod,
200int rsnd_io_is_working(struct rsnd_dai_stream *io) 191int rsnd_io_is_working(struct rsnd_dai_stream *io)
201{ 192{
202 /* see rsnd_dai_stream_init/quit() */ 193 /* see rsnd_dai_stream_init/quit() */
203 return !!io->substream; 194 if (io->substream)
195 return snd_pcm_running(io->substream);
196
197 return 0;
204} 198}
205 199
206int rsnd_runtime_channel_original(struct rsnd_dai_stream *io) 200int rsnd_runtime_channel_original(struct rsnd_dai_stream *io)
@@ -407,11 +401,9 @@ struct rsnd_mod *rsnd_mod_next(int *iterator,
407 401
408 for (; *iterator < max; (*iterator)++) { 402 for (; *iterator < max; (*iterator)++) {
409 type = (array) ? array[*iterator] : *iterator; 403 type = (array) ? array[*iterator] : *iterator;
410 mod = io->mod[type]; 404 mod = rsnd_io_to_mod(io, type);
411 if (!mod) 405 if (mod)
412 continue; 406 return mod;
413
414 return mod;
415 } 407 }
416 408
417 return NULL; 409 return NULL;
@@ -1242,6 +1234,33 @@ struct rsnd_kctrl_cfg *rsnd_kctrl_init_s(struct rsnd_kctrl_cfg_s *cfg)
1242 return &cfg->cfg; 1234 return &cfg->cfg;
1243} 1235}
1244 1236
1237const char * const volume_ramp_rate[] = {
1238 "128 dB/1 step", /* 00000 */
1239 "64 dB/1 step", /* 00001 */
1240 "32 dB/1 step", /* 00010 */
1241 "16 dB/1 step", /* 00011 */
1242 "8 dB/1 step", /* 00100 */
1243 "4 dB/1 step", /* 00101 */
1244 "2 dB/1 step", /* 00110 */
1245 "1 dB/1 step", /* 00111 */
1246 "0.5 dB/1 step", /* 01000 */
1247 "0.25 dB/1 step", /* 01001 */
1248 "0.125 dB/1 step", /* 01010 = VOLUME_RAMP_MAX_MIX */
1249 "0.125 dB/2 steps", /* 01011 */
1250 "0.125 dB/4 steps", /* 01100 */
1251 "0.125 dB/8 steps", /* 01101 */
1252 "0.125 dB/16 steps", /* 01110 */
1253 "0.125 dB/32 steps", /* 01111 */
1254 "0.125 dB/64 steps", /* 10000 */
1255 "0.125 dB/128 steps", /* 10001 */
1256 "0.125 dB/256 steps", /* 10010 */
1257 "0.125 dB/512 steps", /* 10011 */
1258 "0.125 dB/1024 steps", /* 10100 */
1259 "0.125 dB/2048 steps", /* 10101 */
1260 "0.125 dB/4096 steps", /* 10110 */
1261 "0.125 dB/8192 steps", /* 10111 = VOLUME_RAMP_MAX_DVC */
1262};
1263
1245int rsnd_kctrl_new(struct rsnd_mod *mod, 1264int rsnd_kctrl_new(struct rsnd_mod *mod,
1246 struct rsnd_dai_stream *io, 1265 struct rsnd_dai_stream *io,
1247 struct snd_soc_pcm_runtime *rtd, 1266 struct snd_soc_pcm_runtime *rtd,
diff --git a/sound/soc/sh/rcar/ctu.c b/sound/soc/sh/rcar/ctu.c
index e7f53f44165d..d201d551866d 100644
--- a/sound/soc/sh/rcar/ctu.c
+++ b/sound/soc/sh/rcar/ctu.c
@@ -81,8 +81,11 @@ struct rsnd_ctu {
81 struct rsnd_kctrl_cfg_m sv3; 81 struct rsnd_kctrl_cfg_m sv3;
82 struct rsnd_kctrl_cfg_s reset; 82 struct rsnd_kctrl_cfg_s reset;
83 int channels; 83 int channels;
84 u32 flags;
84}; 85};
85 86
87#define KCTRL_INITIALIZED (1 << 0)
88
86#define rsnd_ctu_nr(priv) ((priv)->ctu_nr) 89#define rsnd_ctu_nr(priv) ((priv)->ctu_nr)
87#define for_each_rsnd_ctu(pos, priv, i) \ 90#define for_each_rsnd_ctu(pos, priv, i) \
88 for ((i) = 0; \ 91 for ((i) = 0; \
@@ -130,7 +133,7 @@ static void rsnd_ctu_value_init(struct rsnd_dai_stream *io,
130 int i; 133 int i;
131 134
132 for (i = 0; i < RSND_MAX_CHANNELS; i++) { 135 for (i = 0; i < RSND_MAX_CHANNELS; i++) {
133 u32 val = ctu->pass.val[i]; 136 u32 val = rsnd_kctrl_valm(ctu->pass, i);
134 137
135 cpmdr |= val << (28 - (i * 4)); 138 cpmdr |= val << (28 - (i * 4));
136 139
@@ -147,44 +150,44 @@ static void rsnd_ctu_value_init(struct rsnd_dai_stream *io,
147 rsnd_mod_write(mod, CTU_SCMDR, scmdr); 150 rsnd_mod_write(mod, CTU_SCMDR, scmdr);
148 151
149 if (scmdr > 0) { 152 if (scmdr > 0) {
150 rsnd_mod_write(mod, CTU_SV00R, ctu->sv0.val[0]); 153 rsnd_mod_write(mod, CTU_SV00R, rsnd_kctrl_valm(ctu->sv0, 0));
151 rsnd_mod_write(mod, CTU_SV01R, ctu->sv0.val[1]); 154 rsnd_mod_write(mod, CTU_SV01R, rsnd_kctrl_valm(ctu->sv0, 1));
152 rsnd_mod_write(mod, CTU_SV02R, ctu->sv0.val[2]); 155 rsnd_mod_write(mod, CTU_SV02R, rsnd_kctrl_valm(ctu->sv0, 2));
153 rsnd_mod_write(mod, CTU_SV03R, ctu->sv0.val[3]); 156 rsnd_mod_write(mod, CTU_SV03R, rsnd_kctrl_valm(ctu->sv0, 3));
154 rsnd_mod_write(mod, CTU_SV04R, ctu->sv0.val[4]); 157 rsnd_mod_write(mod, CTU_SV04R, rsnd_kctrl_valm(ctu->sv0, 4));
155 rsnd_mod_write(mod, CTU_SV05R, ctu->sv0.val[5]); 158 rsnd_mod_write(mod, CTU_SV05R, rsnd_kctrl_valm(ctu->sv0, 5));
156 rsnd_mod_write(mod, CTU_SV06R, ctu->sv0.val[6]); 159 rsnd_mod_write(mod, CTU_SV06R, rsnd_kctrl_valm(ctu->sv0, 6));
157 rsnd_mod_write(mod, CTU_SV07R, ctu->sv0.val[7]); 160 rsnd_mod_write(mod, CTU_SV07R, rsnd_kctrl_valm(ctu->sv0, 7));
158 } 161 }
159 if (scmdr > 1) { 162 if (scmdr > 1) {
160 rsnd_mod_write(mod, CTU_SV10R, ctu->sv1.val[0]); 163 rsnd_mod_write(mod, CTU_SV10R, rsnd_kctrl_valm(ctu->sv1, 0));
161 rsnd_mod_write(mod, CTU_SV11R, ctu->sv1.val[1]); 164 rsnd_mod_write(mod, CTU_SV11R, rsnd_kctrl_valm(ctu->sv1, 1));
162 rsnd_mod_write(mod, CTU_SV12R, ctu->sv1.val[2]); 165 rsnd_mod_write(mod, CTU_SV12R, rsnd_kctrl_valm(ctu->sv1, 2));
163 rsnd_mod_write(mod, CTU_SV13R, ctu->sv1.val[3]); 166 rsnd_mod_write(mod, CTU_SV13R, rsnd_kctrl_valm(ctu->sv1, 3));
164 rsnd_mod_write(mod, CTU_SV14R, ctu->sv1.val[4]); 167 rsnd_mod_write(mod, CTU_SV14R, rsnd_kctrl_valm(ctu->sv1, 4));
165 rsnd_mod_write(mod, CTU_SV15R, ctu->sv1.val[5]); 168 rsnd_mod_write(mod, CTU_SV15R, rsnd_kctrl_valm(ctu->sv1, 5));
166 rsnd_mod_write(mod, CTU_SV16R, ctu->sv1.val[6]); 169 rsnd_mod_write(mod, CTU_SV16R, rsnd_kctrl_valm(ctu->sv1, 6));
167 rsnd_mod_write(mod, CTU_SV17R, ctu->sv1.val[7]); 170 rsnd_mod_write(mod, CTU_SV17R, rsnd_kctrl_valm(ctu->sv1, 7));
168 } 171 }
169 if (scmdr > 2) { 172 if (scmdr > 2) {
170 rsnd_mod_write(mod, CTU_SV20R, ctu->sv2.val[0]); 173 rsnd_mod_write(mod, CTU_SV20R, rsnd_kctrl_valm(ctu->sv2, 0));
171 rsnd_mod_write(mod, CTU_SV21R, ctu->sv2.val[1]); 174 rsnd_mod_write(mod, CTU_SV21R, rsnd_kctrl_valm(ctu->sv2, 1));
172 rsnd_mod_write(mod, CTU_SV22R, ctu->sv2.val[2]); 175 rsnd_mod_write(mod, CTU_SV22R, rsnd_kctrl_valm(ctu->sv2, 2));
173 rsnd_mod_write(mod, CTU_SV23R, ctu->sv2.val[3]); 176 rsnd_mod_write(mod, CTU_SV23R, rsnd_kctrl_valm(ctu->sv2, 3));
174 rsnd_mod_write(mod, CTU_SV24R, ctu->sv2.val[4]); 177 rsnd_mod_write(mod, CTU_SV24R, rsnd_kctrl_valm(ctu->sv2, 4));
175 rsnd_mod_write(mod, CTU_SV25R, ctu->sv2.val[5]); 178 rsnd_mod_write(mod, CTU_SV25R, rsnd_kctrl_valm(ctu->sv2, 5));
176 rsnd_mod_write(mod, CTU_SV26R, ctu->sv2.val[6]); 179 rsnd_mod_write(mod, CTU_SV26R, rsnd_kctrl_valm(ctu->sv2, 6));
177 rsnd_mod_write(mod, CTU_SV27R, ctu->sv2.val[7]); 180 rsnd_mod_write(mod, CTU_SV27R, rsnd_kctrl_valm(ctu->sv2, 7));
178 } 181 }
179 if (scmdr > 3) { 182 if (scmdr > 3) {
180 rsnd_mod_write(mod, CTU_SV30R, ctu->sv3.val[0]); 183 rsnd_mod_write(mod, CTU_SV30R, rsnd_kctrl_valm(ctu->sv3, 0));
181 rsnd_mod_write(mod, CTU_SV31R, ctu->sv3.val[1]); 184 rsnd_mod_write(mod, CTU_SV31R, rsnd_kctrl_valm(ctu->sv3, 1));
182 rsnd_mod_write(mod, CTU_SV32R, ctu->sv3.val[2]); 185 rsnd_mod_write(mod, CTU_SV32R, rsnd_kctrl_valm(ctu->sv3, 2));
183 rsnd_mod_write(mod, CTU_SV33R, ctu->sv3.val[3]); 186 rsnd_mod_write(mod, CTU_SV33R, rsnd_kctrl_valm(ctu->sv3, 3));
184 rsnd_mod_write(mod, CTU_SV34R, ctu->sv3.val[4]); 187 rsnd_mod_write(mod, CTU_SV34R, rsnd_kctrl_valm(ctu->sv3, 4));
185 rsnd_mod_write(mod, CTU_SV35R, ctu->sv3.val[5]); 188 rsnd_mod_write(mod, CTU_SV35R, rsnd_kctrl_valm(ctu->sv3, 5));
186 rsnd_mod_write(mod, CTU_SV36R, ctu->sv3.val[6]); 189 rsnd_mod_write(mod, CTU_SV36R, rsnd_kctrl_valm(ctu->sv3, 6));
187 rsnd_mod_write(mod, CTU_SV37R, ctu->sv3.val[7]); 190 rsnd_mod_write(mod, CTU_SV37R, rsnd_kctrl_valm(ctu->sv3, 7));
188 } 191 }
189 192
190 rsnd_mod_write(mod, CTU_CTUIR, 0); 193 rsnd_mod_write(mod, CTU_CTUIR, 0);
@@ -196,17 +199,17 @@ static void rsnd_ctu_value_reset(struct rsnd_dai_stream *io,
196 struct rsnd_ctu *ctu = rsnd_mod_to_ctu(mod); 199 struct rsnd_ctu *ctu = rsnd_mod_to_ctu(mod);
197 int i; 200 int i;
198 201
199 if (!ctu->reset.val) 202 if (!rsnd_kctrl_vals(ctu->reset))
200 return; 203 return;
201 204
202 for (i = 0; i < RSND_MAX_CHANNELS; i++) { 205 for (i = 0; i < RSND_MAX_CHANNELS; i++) {
203 ctu->pass.val[i] = 0; 206 rsnd_kctrl_valm(ctu->pass, i) = 0;
204 ctu->sv0.val[i] = 0; 207 rsnd_kctrl_valm(ctu->sv0, i) = 0;
205 ctu->sv1.val[i] = 0; 208 rsnd_kctrl_valm(ctu->sv1, i) = 0;
206 ctu->sv2.val[i] = 0; 209 rsnd_kctrl_valm(ctu->sv2, i) = 0;
207 ctu->sv3.val[i] = 0; 210 rsnd_kctrl_valm(ctu->sv3, i) = 0;
208 } 211 }
209 ctu->reset.val = 0; 212 rsnd_kctrl_vals(ctu->reset) = 0;
210} 213}
211 214
212static int rsnd_ctu_init(struct rsnd_mod *mod, 215static int rsnd_ctu_init(struct rsnd_mod *mod,
@@ -277,6 +280,9 @@ static int rsnd_ctu_pcm_new(struct rsnd_mod *mod,
277 struct rsnd_ctu *ctu = rsnd_mod_to_ctu(mod); 280 struct rsnd_ctu *ctu = rsnd_mod_to_ctu(mod);
278 int ret; 281 int ret;
279 282
283 if (rsnd_flags_has(ctu, KCTRL_INITIALIZED))
284 return 0;
285
280 /* CTU Pass */ 286 /* CTU Pass */
281 ret = rsnd_kctrl_new_m(mod, io, rtd, "CTU Pass", 287 ret = rsnd_kctrl_new_m(mod, io, rtd, "CTU Pass",
282 rsnd_kctrl_accept_anytime, 288 rsnd_kctrl_accept_anytime,
@@ -326,6 +332,8 @@ static int rsnd_ctu_pcm_new(struct rsnd_mod *mod,
326 rsnd_ctu_value_reset, 332 rsnd_ctu_value_reset,
327 &ctu->reset, 1); 333 &ctu->reset, 1);
328 334
335 rsnd_flags_set(ctu, KCTRL_INITIALIZED);
336
329 return ret; 337 return ret;
330} 338}
331 339
diff --git a/sound/soc/sh/rcar/dma.c b/sound/soc/sh/rcar/dma.c
index 041ec1080d52..fd557abfe390 100644
--- a/sound/soc/sh/rcar/dma.c
+++ b/sound/soc/sh/rcar/dma.c
@@ -60,6 +60,14 @@ struct rsnd_dma_ctrl {
60#define rsnd_dma_to_dmaen(dma) (&(dma)->dma.en) 60#define rsnd_dma_to_dmaen(dma) (&(dma)->dma.en)
61#define rsnd_dma_to_dmapp(dma) (&(dma)->dma.pp) 61#define rsnd_dma_to_dmapp(dma) (&(dma)->dma.pp)
62 62
63/* for DEBUG */
64static struct rsnd_mod_ops mem_ops = {
65 .name = "mem",
66};
67
68static struct rsnd_mod mem = {
69};
70
63/* 71/*
64 * Audio DMAC 72 * Audio DMAC
65 */ 73 */
@@ -211,11 +219,9 @@ static int rsnd_dmaen_nolock_start(struct rsnd_mod *mod,
211 dma->mod_from, 219 dma->mod_from,
212 dma->mod_to); 220 dma->mod_to);
213 if (IS_ERR_OR_NULL(dmaen->chan)) { 221 if (IS_ERR_OR_NULL(dmaen->chan)) {
214 int ret = PTR_ERR(dmaen->chan);
215
216 dmaen->chan = NULL; 222 dmaen->chan = NULL;
217 dev_err(dev, "can't get dma channel\n"); 223 dev_err(dev, "can't get dma channel\n");
218 return ret; 224 return -EIO;
219 } 225 }
220 226
221 return 0; 227 return 0;
@@ -747,20 +753,22 @@ static void rsnd_dma_of_path(struct rsnd_mod *this,
747 rsnd_mod_name(this), rsnd_mod_id(this)); 753 rsnd_mod_name(this), rsnd_mod_id(this));
748 for (i = 0; i <= idx; i++) { 754 for (i = 0; i <= idx; i++) {
749 dev_dbg(dev, " %s[%d]%s\n", 755 dev_dbg(dev, " %s[%d]%s\n",
750 rsnd_mod_name(mod[i]), rsnd_mod_id(mod[i]), 756 rsnd_mod_name(mod[i] ? mod[i] : &mem),
751 (mod[i] == *mod_from) ? " from" : 757 rsnd_mod_id (mod[i] ? mod[i] : &mem),
752 (mod[i] == *mod_to) ? " to" : ""); 758 (mod[i] == *mod_from) ? " from" :
759 (mod[i] == *mod_to) ? " to" : "");
753 } 760 }
754} 761}
755 762
756int rsnd_dma_attach(struct rsnd_dai_stream *io, struct rsnd_mod *mod, 763static int rsnd_dma_alloc(struct rsnd_dai_stream *io, struct rsnd_mod *mod,
757 struct rsnd_mod **dma_mod) 764 struct rsnd_mod **dma_mod)
758{ 765{
759 struct rsnd_mod *mod_from = NULL; 766 struct rsnd_mod *mod_from = NULL;
760 struct rsnd_mod *mod_to = NULL; 767 struct rsnd_mod *mod_to = NULL;
761 struct rsnd_priv *priv = rsnd_io_to_priv(io); 768 struct rsnd_priv *priv = rsnd_io_to_priv(io);
762 struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); 769 struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
763 struct device *dev = rsnd_priv_to_dev(priv); 770 struct device *dev = rsnd_priv_to_dev(priv);
771 struct rsnd_dma *dma;
764 struct rsnd_mod_ops *ops; 772 struct rsnd_mod_ops *ops;
765 enum rsnd_mod_type type; 773 enum rsnd_mod_type type;
766 int (*attach)(struct rsnd_dai_stream *io, struct rsnd_dma *dma, 774 int (*attach)(struct rsnd_dai_stream *io, struct rsnd_dma *dma,
@@ -800,40 +808,47 @@ int rsnd_dma_attach(struct rsnd_dai_stream *io, struct rsnd_mod *mod,
800 type = RSND_MOD_AUDMA; 808 type = RSND_MOD_AUDMA;
801 } 809 }
802 810
803 if (!(*dma_mod)) { 811 dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL);
804 struct rsnd_dma *dma; 812 if (!dma)
813 return -ENOMEM;
805 814
806 dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL); 815 *dma_mod = rsnd_mod_get(dma);
807 if (!dma)
808 return -ENOMEM;
809 816
810 *dma_mod = rsnd_mod_get(dma); 817 ret = rsnd_mod_init(priv, *dma_mod, ops, NULL,
818 rsnd_mod_get_status, type, dma_id);
819 if (ret < 0)
820 return ret;
811 821
812 ret = rsnd_mod_init(priv, *dma_mod, ops, NULL, 822 dev_dbg(dev, "%s[%d] %s[%d] -> %s[%d]\n",
813 rsnd_mod_get_status, type, dma_id); 823 rsnd_mod_name(*dma_mod), rsnd_mod_id(*dma_mod),
814 if (ret < 0) 824 rsnd_mod_name(mod_from ? mod_from : &mem),
815 return ret; 825 rsnd_mod_id (mod_from ? mod_from : &mem),
826 rsnd_mod_name(mod_to ? mod_to : &mem),
827 rsnd_mod_id (mod_to ? mod_to : &mem));
816 828
817 dev_dbg(dev, "%s[%d] %s[%d] -> %s[%d]\n", 829 ret = attach(io, dma, mod_from, mod_to);
818 rsnd_mod_name(*dma_mod), rsnd_mod_id(*dma_mod), 830 if (ret < 0)
819 rsnd_mod_name(mod_from), rsnd_mod_id(mod_from), 831 return ret;
820 rsnd_mod_name(mod_to), rsnd_mod_id(mod_to)); 832
833 dma->src_addr = rsnd_dma_addr(io, mod_from, is_play, 1);
834 dma->dst_addr = rsnd_dma_addr(io, mod_to, is_play, 0);
835 dma->mod_from = mod_from;
836 dma->mod_to = mod_to;
837
838 return 0;
839}
840
841int rsnd_dma_attach(struct rsnd_dai_stream *io, struct rsnd_mod *mod,
842 struct rsnd_mod **dma_mod)
843{
844 if (!(*dma_mod)) {
845 int ret = rsnd_dma_alloc(io, mod, dma_mod);
821 846
822 ret = attach(io, dma, mod_from, mod_to);
823 if (ret < 0) 847 if (ret < 0)
824 return ret; 848 return ret;
825
826 dma->src_addr = rsnd_dma_addr(io, mod_from, is_play, 1);
827 dma->dst_addr = rsnd_dma_addr(io, mod_to, is_play, 0);
828 dma->mod_from = mod_from;
829 dma->mod_to = mod_to;
830 } 849 }
831 850
832 ret = rsnd_dai_connect(*dma_mod, io, type); 851 return rsnd_dai_connect(*dma_mod, io, (*dma_mod)->type);
833 if (ret < 0)
834 return ret;
835
836 return 0;
837} 852}
838 853
839int rsnd_dma_probe(struct rsnd_priv *priv) 854int rsnd_dma_probe(struct rsnd_priv *priv)
@@ -866,5 +881,6 @@ int rsnd_dma_probe(struct rsnd_priv *priv)
866 881
867 priv->dma = dmac; 882 priv->dma = dmac;
868 883
869 return 0; 884 /* dummy mem mod for debug */
885 return rsnd_mod_init(NULL, &mem, &mem_ops, NULL, NULL, 0, 0);
870} 886}
diff --git a/sound/soc/sh/rcar/dvc.c b/sound/soc/sh/rcar/dvc.c
index 1743ade3cc55..dbe54f024d68 100644
--- a/sound/soc/sh/rcar/dvc.c
+++ b/sound/soc/sh/rcar/dvc.c
@@ -44,8 +44,11 @@ struct rsnd_dvc {
44 struct rsnd_kctrl_cfg_s ren; /* Ramp Enable */ 44 struct rsnd_kctrl_cfg_s ren; /* Ramp Enable */
45 struct rsnd_kctrl_cfg_s rup; /* Ramp Rate Up */ 45 struct rsnd_kctrl_cfg_s rup; /* Ramp Rate Up */
46 struct rsnd_kctrl_cfg_s rdown; /* Ramp Rate Down */ 46 struct rsnd_kctrl_cfg_s rdown; /* Ramp Rate Down */
47 u32 flags;
47}; 48};
48 49
50#define KCTRL_INITIALIZED (1 << 0)
51
49#define rsnd_dvc_get(priv, id) ((struct rsnd_dvc *)(priv->dvc) + id) 52#define rsnd_dvc_get(priv, id) ((struct rsnd_dvc *)(priv->dvc) + id)
50#define rsnd_dvc_nr(priv) ((priv)->dvc_nr) 53#define rsnd_dvc_nr(priv) ((priv)->dvc_nr)
51 54
@@ -58,33 +61,6 @@ struct rsnd_dvc {
58 ((pos) = (struct rsnd_dvc *)(priv)->dvc + i); \ 61 ((pos) = (struct rsnd_dvc *)(priv)->dvc + i); \
59 i++) 62 i++)
60 63
61static const char * const dvc_ramp_rate[] = {
62 "128 dB/1 step", /* 00000 */
63 "64 dB/1 step", /* 00001 */
64 "32 dB/1 step", /* 00010 */
65 "16 dB/1 step", /* 00011 */
66 "8 dB/1 step", /* 00100 */
67 "4 dB/1 step", /* 00101 */
68 "2 dB/1 step", /* 00110 */
69 "1 dB/1 step", /* 00111 */
70 "0.5 dB/1 step", /* 01000 */
71 "0.25 dB/1 step", /* 01001 */
72 "0.125 dB/1 step", /* 01010 */
73 "0.125 dB/2 steps", /* 01011 */
74 "0.125 dB/4 steps", /* 01100 */
75 "0.125 dB/8 steps", /* 01101 */
76 "0.125 dB/16 steps", /* 01110 */
77 "0.125 dB/32 steps", /* 01111 */
78 "0.125 dB/64 steps", /* 10000 */
79 "0.125 dB/128 steps", /* 10001 */
80 "0.125 dB/256 steps", /* 10010 */
81 "0.125 dB/512 steps", /* 10011 */
82 "0.125 dB/1024 steps", /* 10100 */
83 "0.125 dB/2048 steps", /* 10101 */
84 "0.125 dB/4096 steps", /* 10110 */
85 "0.125 dB/8192 steps", /* 10111 */
86};
87
88static void rsnd_dvc_activation(struct rsnd_mod *mod) 64static void rsnd_dvc_activation(struct rsnd_mod *mod)
89{ 65{
90 rsnd_mod_write(mod, DVC_SWRSR, 0); 66 rsnd_mod_write(mod, DVC_SWRSR, 0);
@@ -97,8 +73,9 @@ static void rsnd_dvc_halt(struct rsnd_mod *mod)
97 rsnd_mod_write(mod, DVC_SWRSR, 0); 73 rsnd_mod_write(mod, DVC_SWRSR, 0);
98} 74}
99 75
100#define rsnd_dvc_get_vrpdr(dvc) (dvc->rup.val << 8 | dvc->rdown.val) 76#define rsnd_dvc_get_vrpdr(dvc) (rsnd_kctrl_vals(dvc->rup) << 8 | \
101#define rsnd_dvc_get_vrdbr(dvc) (0x3ff - (dvc->volume.val[0] >> 13)) 77 rsnd_kctrl_vals(dvc->rdown))
78#define rsnd_dvc_get_vrdbr(dvc) (0x3ff - (rsnd_kctrl_valm(dvc->volume, 0) >> 13))
102 79
103static void rsnd_dvc_volume_parameter(struct rsnd_dai_stream *io, 80static void rsnd_dvc_volume_parameter(struct rsnd_dai_stream *io,
104 struct rsnd_mod *mod) 81 struct rsnd_mod *mod)
@@ -108,12 +85,12 @@ static void rsnd_dvc_volume_parameter(struct rsnd_dai_stream *io,
108 int i; 85 int i;
109 86
110 /* Enable Ramp */ 87 /* Enable Ramp */
111 if (dvc->ren.val) 88 if (rsnd_kctrl_vals(dvc->ren))
112 for (i = 0; i < RSND_MAX_CHANNELS; i++) 89 for (i = 0; i < RSND_MAX_CHANNELS; i++)
113 val[i] = dvc->volume.cfg.max; 90 val[i] = rsnd_kctrl_max(dvc->volume);
114 else 91 else
115 for (i = 0; i < RSND_MAX_CHANNELS; i++) 92 for (i = 0; i < RSND_MAX_CHANNELS; i++)
116 val[i] = dvc->volume.val[i]; 93 val[i] = rsnd_kctrl_valm(dvc->volume, i);
117 94
118 /* Enable Digital Volume */ 95 /* Enable Digital Volume */
119 rsnd_mod_write(mod, DVC_VOL0R, val[0]); 96 rsnd_mod_write(mod, DVC_VOL0R, val[0]);
@@ -143,7 +120,7 @@ static void rsnd_dvc_volume_init(struct rsnd_dai_stream *io,
143 dvucr |= 0x101; 120 dvucr |= 0x101;
144 121
145 /* Enable Ramp */ 122 /* Enable Ramp */
146 if (dvc->ren.val) { 123 if (rsnd_kctrl_vals(dvc->ren)) {
147 dvucr |= 0x10; 124 dvucr |= 0x10;
148 125
149 /* 126 /*
@@ -185,10 +162,10 @@ static void rsnd_dvc_volume_update(struct rsnd_dai_stream *io,
185 u32 vrdbr = 0; 162 u32 vrdbr = 0;
186 int i; 163 int i;
187 164
188 for (i = 0; i < dvc->mute.cfg.size; i++) 165 for (i = 0; i < rsnd_kctrl_size(dvc->mute); i++)
189 zcmcr |= (!!dvc->mute.cfg.val[i]) << i; 166 zcmcr |= (!!rsnd_kctrl_valm(dvc->mute, i)) << i;
190 167
191 if (dvc->ren.val) { 168 if (rsnd_kctrl_vals(dvc->ren)) {
192 vrpdr = rsnd_dvc_get_vrpdr(dvc); 169 vrpdr = rsnd_dvc_get_vrpdr(dvc);
193 vrdbr = rsnd_dvc_get_vrdbr(dvc); 170 vrdbr = rsnd_dvc_get_vrdbr(dvc);
194 } 171 }
@@ -254,6 +231,9 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
254 int channels = rsnd_rdai_channels_get(rdai); 231 int channels = rsnd_rdai_channels_get(rdai);
255 int ret; 232 int ret;
256 233
234 if (rsnd_flags_has(dvc, KCTRL_INITIALIZED))
235 return 0;
236
257 /* Volume */ 237 /* Volume */
258 ret = rsnd_kctrl_new_m(mod, io, rtd, 238 ret = rsnd_kctrl_new_m(mod, io, rtd,
259 is_play ? 239 is_play ?
@@ -292,7 +272,8 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
292 rsnd_kctrl_accept_anytime, 272 rsnd_kctrl_accept_anytime,
293 rsnd_dvc_volume_update, 273 rsnd_dvc_volume_update,
294 &dvc->rup, 274 &dvc->rup,
295 dvc_ramp_rate); 275 volume_ramp_rate,
276 VOLUME_RAMP_MAX_DVC);
296 if (ret < 0) 277 if (ret < 0)
297 return ret; 278 return ret;
298 279
@@ -302,11 +283,14 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
302 rsnd_kctrl_accept_anytime, 283 rsnd_kctrl_accept_anytime,
303 rsnd_dvc_volume_update, 284 rsnd_dvc_volume_update,
304 &dvc->rdown, 285 &dvc->rdown,
305 dvc_ramp_rate); 286 volume_ramp_rate,
287 VOLUME_RAMP_MAX_DVC);
306 288
307 if (ret < 0) 289 if (ret < 0)
308 return ret; 290 return ret;
309 291
292 rsnd_flags_set(dvc, KCTRL_INITIALIZED);
293
310 return 0; 294 return 0;
311} 295}
312 296
diff --git a/sound/soc/sh/rcar/mix.c b/sound/soc/sh/rcar/mix.c
index 6c4826c189a4..7998380766f6 100644
--- a/sound/soc/sh/rcar/mix.c
+++ b/sound/soc/sh/rcar/mix.c
@@ -7,6 +7,33 @@
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10
11/*
12 * CTUn MIXn
13 * +------+ +------+
14 * [SRC3 / SRC6] -> |CTU n0| -> [MIX n0| ->
15 * [SRC4 / SRC9] -> |CTU n1| -> [MIX n1| ->
16 * [SRC0 / SRC1] -> |CTU n2| -> [MIX n2| ->
17 * [SRC2 / SRC5] -> |CTU n3| -> [MIX n3| ->
18 * +------+ +------+
19 *
20 * ex)
21 * DAI0 : playback = <&src0 &ctu02 &mix0 &dvc0 &ssi0>;
22 * DAI1 : playback = <&src2 &ctu03 &mix0 &dvc0 &ssi0>;
23 *
24 * MIX Volume
25 * amixer set "MIX",0 100% // DAI0 Volume
26 * amixer set "MIX",1 100% // DAI1 Volume
27 *
28 * Volume Ramp
29 * amixer set "MIX Ramp Up Rate" "0.125 dB/1 step"
30 * amixer set "MIX Ramp Down Rate" "4 dB/1 step"
31 * amixer set "MIX Ramp" on
32 * aplay xxx.wav &
33 * amixer set "MIX",0 80% // DAI0 Volume Down
34 * amixer set "MIX",1 100% // DAI1 Volume Up
35 */
36
10#include "rsnd.h" 37#include "rsnd.h"
11 38
12#define MIX_NAME_SIZE 16 39#define MIX_NAME_SIZE 16
@@ -14,8 +41,27 @@
14 41
15struct rsnd_mix { 42struct rsnd_mix {
16 struct rsnd_mod mod; 43 struct rsnd_mod mod;
44 struct rsnd_kctrl_cfg_s volumeA; /* MDBAR */
45 struct rsnd_kctrl_cfg_s volumeB; /* MDBBR */
46 struct rsnd_kctrl_cfg_s volumeC; /* MDBCR */
47 struct rsnd_kctrl_cfg_s volumeD; /* MDBDR */
48 struct rsnd_kctrl_cfg_s ren; /* Ramp Enable */
49 struct rsnd_kctrl_cfg_s rup; /* Ramp Rate Up */
50 struct rsnd_kctrl_cfg_s rdw; /* Ramp Rate Down */
51 u32 flags;
17}; 52};
18 53
54#define ONCE_KCTRL_INITIALIZED (1 << 0)
55#define HAS_VOLA (1 << 1)
56#define HAS_VOLB (1 << 2)
57#define HAS_VOLC (1 << 3)
58#define HAS_VOLD (1 << 4)
59
60#define VOL_MAX 0x3ff
61
62#define rsnd_mod_to_mix(_mod) \
63 container_of((_mod), struct rsnd_mix, mod)
64
19#define rsnd_mix_get(priv, id) ((struct rsnd_mix *)(priv->mix) + id) 65#define rsnd_mix_get(priv, id) ((struct rsnd_mix *)(priv->mix) + id)
20#define rsnd_mix_nr(priv) ((priv)->mix_nr) 66#define rsnd_mix_nr(priv) ((priv)->mix_nr)
21#define for_each_rsnd_mix(pos, priv, i) \ 67#define for_each_rsnd_mix(pos, priv, i) \
@@ -36,26 +82,43 @@ static void rsnd_mix_halt(struct rsnd_mod *mod)
36 rsnd_mod_write(mod, MIX_SWRSR, 0); 82 rsnd_mod_write(mod, MIX_SWRSR, 0);
37} 83}
38 84
85#define rsnd_mix_get_vol(mix, X) \
86 rsnd_flags_has(mix, HAS_VOL##X) ? \
87 (VOL_MAX - rsnd_kctrl_vals(mix->volume##X)) : 0
39static void rsnd_mix_volume_parameter(struct rsnd_dai_stream *io, 88static void rsnd_mix_volume_parameter(struct rsnd_dai_stream *io,
40 struct rsnd_mod *mod) 89 struct rsnd_mod *mod)
41{ 90{
42 rsnd_mod_write(mod, MIX_MDBAR, 0); 91 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
43 rsnd_mod_write(mod, MIX_MDBBR, 0); 92 struct device *dev = rsnd_priv_to_dev(priv);
44 rsnd_mod_write(mod, MIX_MDBCR, 0); 93 struct rsnd_mix *mix = rsnd_mod_to_mix(mod);
45 rsnd_mod_write(mod, MIX_MDBDR, 0); 94 u32 volA = rsnd_mix_get_vol(mix, A);
95 u32 volB = rsnd_mix_get_vol(mix, B);
96 u32 volC = rsnd_mix_get_vol(mix, C);
97 u32 volD = rsnd_mix_get_vol(mix, D);
98
99 dev_dbg(dev, "MIX A/B/C/D = %02x/%02x/%02x/%02x\n",
100 volA, volB, volC, volD);
101
102 rsnd_mod_write(mod, MIX_MDBAR, volA);
103 rsnd_mod_write(mod, MIX_MDBBR, volB);
104 rsnd_mod_write(mod, MIX_MDBCR, volC);
105 rsnd_mod_write(mod, MIX_MDBDR, volD);
46} 106}
47 107
48static void rsnd_mix_volume_init(struct rsnd_dai_stream *io, 108static void rsnd_mix_volume_init(struct rsnd_dai_stream *io,
49 struct rsnd_mod *mod) 109 struct rsnd_mod *mod)
50{ 110{
111 struct rsnd_mix *mix = rsnd_mod_to_mix(mod);
112
51 rsnd_mod_write(mod, MIX_MIXIR, 1); 113 rsnd_mod_write(mod, MIX_MIXIR, 1);
52 114
53 /* General Information */ 115 /* General Information */
54 rsnd_mod_write(mod, MIX_ADINR, rsnd_runtime_channel_after_ctu(io)); 116 rsnd_mod_write(mod, MIX_ADINR, rsnd_runtime_channel_after_ctu(io));
55 117
56 /* volume step */ 118 /* volume step */
57 rsnd_mod_write(mod, MIX_MIXMR, 0); 119 rsnd_mod_write(mod, MIX_MIXMR, rsnd_kctrl_vals(mix->ren));
58 rsnd_mod_write(mod, MIX_MVPDR, 0); 120 rsnd_mod_write(mod, MIX_MVPDR, rsnd_kctrl_vals(mix->rup) << 8 |
121 rsnd_kctrl_vals(mix->rdw));
59 122
60 /* common volume parameter */ 123 /* common volume parameter */
61 rsnd_mix_volume_parameter(io, mod); 124 rsnd_mix_volume_parameter(io, mod);
@@ -109,11 +172,94 @@ static int rsnd_mix_quit(struct rsnd_mod *mod,
109 return 0; 172 return 0;
110} 173}
111 174
175static int rsnd_mix_pcm_new(struct rsnd_mod *mod,
176 struct rsnd_dai_stream *io,
177 struct snd_soc_pcm_runtime *rtd)
178{
179 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
180 struct device *dev = rsnd_priv_to_dev(priv);
181 struct rsnd_mix *mix = rsnd_mod_to_mix(mod);
182 struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
183 struct rsnd_kctrl_cfg_s *volume;
184 int ret;
185
186 switch (rsnd_mod_id(src_mod)) {
187 case 3:
188 case 6: /* MDBAR */
189 volume = &mix->volumeA;
190 rsnd_flags_set(mix, HAS_VOLA);
191 break;
192 case 4:
193 case 9: /* MDBBR */
194 volume = &mix->volumeB;
195 rsnd_flags_set(mix, HAS_VOLB);
196 break;
197 case 0:
198 case 1: /* MDBCR */
199 volume = &mix->volumeC;
200 rsnd_flags_set(mix, HAS_VOLC);
201 break;
202 case 2:
203 case 5: /* MDBDR */
204 volume = &mix->volumeD;
205 rsnd_flags_set(mix, HAS_VOLD);
206 break;
207 default:
208 dev_err(dev, "unknown SRC is connected\n");
209 return -EINVAL;
210 }
211
212 /* Volume */
213 ret = rsnd_kctrl_new_s(mod, io, rtd,
214 "MIX Playback Volume",
215 rsnd_kctrl_accept_anytime,
216 rsnd_mix_volume_update,
217 volume, VOL_MAX);
218 if (ret < 0)
219 return ret;
220 rsnd_kctrl_vals(*volume) = VOL_MAX;
221
222 if (rsnd_flags_has(mix, ONCE_KCTRL_INITIALIZED))
223 return ret;
224
225 /* Ramp */
226 ret = rsnd_kctrl_new_s(mod, io, rtd,
227 "MIX Ramp Switch",
228 rsnd_kctrl_accept_anytime,
229 rsnd_mix_volume_update,
230 &mix->ren, 1);
231 if (ret < 0)
232 return ret;
233
234 ret = rsnd_kctrl_new_e(mod, io, rtd,
235 "MIX Ramp Up Rate",
236 rsnd_kctrl_accept_anytime,
237 rsnd_mix_volume_update,
238 &mix->rup,
239 volume_ramp_rate,
240 VOLUME_RAMP_MAX_MIX);
241 if (ret < 0)
242 return ret;
243
244 ret = rsnd_kctrl_new_e(mod, io, rtd,
245 "MIX Ramp Down Rate",
246 rsnd_kctrl_accept_anytime,
247 rsnd_mix_volume_update,
248 &mix->rdw,
249 volume_ramp_rate,
250 VOLUME_RAMP_MAX_MIX);
251
252 rsnd_flags_set(mix, ONCE_KCTRL_INITIALIZED);
253
254 return ret;
255}
256
112static struct rsnd_mod_ops rsnd_mix_ops = { 257static struct rsnd_mod_ops rsnd_mix_ops = {
113 .name = MIX_NAME, 258 .name = MIX_NAME,
114 .probe = rsnd_mix_probe_, 259 .probe = rsnd_mix_probe_,
115 .init = rsnd_mix_init, 260 .init = rsnd_mix_init,
116 .quit = rsnd_mix_quit, 261 .quit = rsnd_mix_quit,
262 .pcm_new = rsnd_mix_pcm_new,
117}; 263};
118 264
119struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id) 265struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id)
diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h
index c5de71f2dc8c..57cd2bc773c2 100644
--- a/sound/soc/sh/rcar/rsnd.h
+++ b/sound/soc/sh/rcar/rsnd.h
@@ -355,8 +355,9 @@ struct rsnd_mod {
355#define __rsnd_mod_call_nolock_start 0 355#define __rsnd_mod_call_nolock_start 0
356#define __rsnd_mod_call_nolock_stop 1 356#define __rsnd_mod_call_nolock_stop 1
357 357
358#define rsnd_mod_to_priv(mod) ((mod)->priv) 358#define rsnd_mod_to_priv(mod) ((mod)->priv)
359#define rsnd_mod_id(mod) ((mod) ? (mod)->id : -1) 359#define rsnd_mod_name(mod) ((mod)->ops->name)
360#define rsnd_mod_id(mod) ((mod)->id)
360#define rsnd_mod_power_on(mod) clk_enable((mod)->clk) 361#define rsnd_mod_power_on(mod) clk_enable((mod)->clk)
361#define rsnd_mod_power_off(mod) clk_disable((mod)->clk) 362#define rsnd_mod_power_off(mod) clk_disable((mod)->clk)
362#define rsnd_mod_get(ip) (&(ip)->mod) 363#define rsnd_mod_get(ip) (&(ip)->mod)
@@ -371,7 +372,6 @@ int rsnd_mod_init(struct rsnd_priv *priv,
371 enum rsnd_mod_type type, 372 enum rsnd_mod_type type,
372 int id); 373 int id);
373void rsnd_mod_quit(struct rsnd_mod *mod); 374void rsnd_mod_quit(struct rsnd_mod *mod);
374char *rsnd_mod_name(struct rsnd_mod *mod);
375struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io, 375struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io,
376 struct rsnd_mod *mod); 376 struct rsnd_mod *mod);
377void rsnd_mod_interrupt(struct rsnd_mod *mod, 377void rsnd_mod_interrupt(struct rsnd_mod *mod,
@@ -601,6 +601,10 @@ struct rsnd_priv {
601#define rsnd_is_gen1(priv) (((priv)->flags & RSND_GEN_MASK) == RSND_GEN1) 601#define rsnd_is_gen1(priv) (((priv)->flags & RSND_GEN_MASK) == RSND_GEN1)
602#define rsnd_is_gen2(priv) (((priv)->flags & RSND_GEN_MASK) == RSND_GEN2) 602#define rsnd_is_gen2(priv) (((priv)->flags & RSND_GEN_MASK) == RSND_GEN2)
603 603
604#define rsnd_flags_has(p, f) ((p)->flags & (f))
605#define rsnd_flags_set(p, f) ((p)->flags |= (f))
606#define rsnd_flags_del(p, f) ((p)->flags &= ~(f))
607
604/* 608/*
605 * rsnd_kctrl 609 * rsnd_kctrl
606 */ 610 */
@@ -627,6 +631,10 @@ struct rsnd_kctrl_cfg_s {
627 struct rsnd_kctrl_cfg cfg; 631 struct rsnd_kctrl_cfg cfg;
628 u32 val; 632 u32 val;
629}; 633};
634#define rsnd_kctrl_size(x) ((x).cfg.size)
635#define rsnd_kctrl_max(x) ((x).cfg.max)
636#define rsnd_kctrl_valm(x, i) ((x).val[i]) /* = (x).cfg.val[i] */
637#define rsnd_kctrl_vals(x) ((x).val) /* = (x).cfg.val[0] */
630 638
631int rsnd_kctrl_accept_anytime(struct rsnd_dai_stream *io); 639int rsnd_kctrl_accept_anytime(struct rsnd_dai_stream *io);
632int rsnd_kctrl_accept_runtime(struct rsnd_dai_stream *io); 640int rsnd_kctrl_accept_runtime(struct rsnd_dai_stream *io);
@@ -652,9 +660,13 @@ int rsnd_kctrl_new(struct rsnd_mod *mod,
652 rsnd_kctrl_new(mod, io, rtd, name, accept, update, rsnd_kctrl_init_s(cfg), \ 660 rsnd_kctrl_new(mod, io, rtd, name, accept, update, rsnd_kctrl_init_s(cfg), \
653 NULL, 1, max) 661 NULL, 1, max)
654 662
655#define rsnd_kctrl_new_e(mod, io, rtd, name, accept, update, cfg, texts) \ 663#define rsnd_kctrl_new_e(mod, io, rtd, name, accept, update, cfg, texts, size) \
656 rsnd_kctrl_new(mod, io, rtd, name, accept, update, rsnd_kctrl_init_s(cfg), \ 664 rsnd_kctrl_new(mod, io, rtd, name, accept, update, rsnd_kctrl_init_s(cfg), \
657 texts, 1, ARRAY_SIZE(texts)) 665 texts, 1, size)
666
667extern const char * const volume_ramp_rate[];
668#define VOLUME_RAMP_MAX_DVC (0x17 + 1)
669#define VOLUME_RAMP_MAX_MIX (0x0a + 1)
658 670
659/* 671/*
660 * R-Car SSI 672 * R-Car SSI
diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c
index fffc07e72627..fece1e5f582f 100644
--- a/sound/soc/sh/rcar/ssi.c
+++ b/sound/soc/sh/rcar/ssi.c
@@ -101,9 +101,6 @@ struct rsnd_ssi {
101#define rsnd_ssi_get(priv, id) ((struct rsnd_ssi *)(priv->ssi) + id) 101#define rsnd_ssi_get(priv, id) ((struct rsnd_ssi *)(priv->ssi) + id)
102#define rsnd_ssi_nr(priv) ((priv)->ssi_nr) 102#define rsnd_ssi_nr(priv) ((priv)->ssi_nr)
103#define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod) 103#define rsnd_mod_to_ssi(_mod) container_of((_mod), struct rsnd_ssi, mod)
104#define rsnd_ssi_flags_has(p, f) ((p)->flags & f)
105#define rsnd_ssi_flags_set(p, f) ((p)->flags |= f)
106#define rsnd_ssi_flags_del(p, f) ((p)->flags = ((p)->flags & ~f))
107#define rsnd_ssi_is_parent(ssi, io) ((ssi) == rsnd_io_to_mod_ssip(io)) 104#define rsnd_ssi_is_parent(ssi, io) ((ssi) == rsnd_io_to_mod_ssip(io))
108#define rsnd_ssi_is_multi_slave(mod, io) \ 105#define rsnd_ssi_is_multi_slave(mod, io) \
109 (rsnd_ssi_multi_slaves(io) & (1 << rsnd_mod_id(mod))) 106 (rsnd_ssi_multi_slaves(io) & (1 << rsnd_mod_id(mod)))
@@ -116,10 +113,10 @@ int rsnd_ssi_hdmi_port(struct rsnd_dai_stream *io)
116 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io); 113 struct rsnd_mod *mod = rsnd_io_to_mod_ssi(io);
117 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 114 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
118 115
119 if (rsnd_ssi_flags_has(ssi, RSND_SSI_HDMI0)) 116 if (rsnd_flags_has(ssi, RSND_SSI_HDMI0))
120 return RSND_SSI_HDMI_PORT0; 117 return RSND_SSI_HDMI_PORT0;
121 118
122 if (rsnd_ssi_flags_has(ssi, RSND_SSI_HDMI1)) 119 if (rsnd_flags_has(ssi, RSND_SSI_HDMI1))
123 return RSND_SSI_HDMI_PORT1; 120 return RSND_SSI_HDMI_PORT1;
124 121
125 return 0; 122 return 0;
@@ -134,7 +131,7 @@ int rsnd_ssi_use_busif(struct rsnd_dai_stream *io)
134 if (!rsnd_ssi_is_dma_mode(mod)) 131 if (!rsnd_ssi_is_dma_mode(mod))
135 return 0; 132 return 0;
136 133
137 if (!(rsnd_ssi_flags_has(ssi, RSND_SSI_NO_BUSIF))) 134 if (!(rsnd_flags_has(ssi, RSND_SSI_NO_BUSIF)))
138 use_busif = 1; 135 use_busif = 1;
139 if (rsnd_io_to_mod_src(io)) 136 if (rsnd_io_to_mod_src(io))
140 use_busif = 1; 137 use_busif = 1;
@@ -198,10 +195,15 @@ static u32 rsnd_ssi_run_mods(struct rsnd_dai_stream *io)
198{ 195{
199 struct rsnd_mod *ssi_mod = rsnd_io_to_mod_ssi(io); 196 struct rsnd_mod *ssi_mod = rsnd_io_to_mod_ssi(io);
200 struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io); 197 struct rsnd_mod *ssi_parent_mod = rsnd_io_to_mod_ssip(io);
198 u32 mods;
201 199
202 return rsnd_ssi_multi_slaves_runtime(io) | 200 mods = rsnd_ssi_multi_slaves_runtime(io) |
203 1 << rsnd_mod_id(ssi_mod) | 201 1 << rsnd_mod_id(ssi_mod);
204 1 << rsnd_mod_id(ssi_parent_mod); 202
203 if (ssi_parent_mod)
204 mods |= 1 << rsnd_mod_id(ssi_parent_mod);
205
206 return mods;
205} 207}
206 208
207u32 rsnd_ssi_multi_slaves_runtime(struct rsnd_dai_stream *io) 209u32 rsnd_ssi_multi_slaves_runtime(struct rsnd_dai_stream *io)
@@ -601,15 +603,18 @@ static int rsnd_ssi_stop(struct rsnd_mod *mod,
601 if (rsnd_ssi_is_parent(mod, io)) 603 if (rsnd_ssi_is_parent(mod, io))
602 return 0; 604 return 0;
603 605
604 /*
605 * disable all IRQ,
606 * and, wait all data was sent
607 */
608 cr = ssi->cr_own | 606 cr = ssi->cr_own |
609 ssi->cr_clk; 607 ssi->cr_clk;
610 608
611 rsnd_mod_write(mod, SSICR, cr | EN); 609 /*
612 rsnd_ssi_status_check(mod, DIRQ); 610 * disable all IRQ,
611 * Playback: Wait all data was sent
612 * Capture: It might not receave data. Do nothing
613 */
614 if (rsnd_io_is_play(io)) {
615 rsnd_mod_write(mod, SSICR, cr | EN);
616 rsnd_ssi_status_check(mod, DIRQ);
617 }
613 618
614 /* 619 /*
615 * disable SSI, 620 * disable SSI,
@@ -793,13 +798,13 @@ static int rsnd_ssi_common_probe(struct rsnd_mod *mod,
793 * But it don't need to call request_irq() many times. 798 * But it don't need to call request_irq() many times.
794 * Let's control it by RSND_SSI_PROBED flag. 799 * Let's control it by RSND_SSI_PROBED flag.
795 */ 800 */
796 if (!rsnd_ssi_flags_has(ssi, RSND_SSI_PROBED)) { 801 if (!rsnd_flags_has(ssi, RSND_SSI_PROBED)) {
797 ret = request_irq(ssi->irq, 802 ret = request_irq(ssi->irq,
798 rsnd_ssi_interrupt, 803 rsnd_ssi_interrupt,
799 IRQF_SHARED, 804 IRQF_SHARED,
800 dev_name(dev), mod); 805 dev_name(dev), mod);
801 806
802 rsnd_ssi_flags_set(ssi, RSND_SSI_PROBED); 807 rsnd_flags_set(ssi, RSND_SSI_PROBED);
803 } 808 }
804 809
805 return ret; 810 return ret;
@@ -817,10 +822,10 @@ static int rsnd_ssi_common_remove(struct rsnd_mod *mod,
817 return 0; 822 return 0;
818 823
819 /* PIO will request IRQ again */ 824 /* PIO will request IRQ again */
820 if (rsnd_ssi_flags_has(ssi, RSND_SSI_PROBED)) { 825 if (rsnd_flags_has(ssi, RSND_SSI_PROBED)) {
821 free_irq(ssi->irq, mod); 826 free_irq(ssi->irq, mod);
822 827
823 rsnd_ssi_flags_del(ssi, RSND_SSI_PROBED); 828 rsnd_flags_del(ssi, RSND_SSI_PROBED);
824 } 829 }
825 830
826 return 0; 831 return 0;
@@ -1003,13 +1008,13 @@ static void __rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
1003 ssi = rsnd_mod_to_ssi(mod); 1008 ssi = rsnd_mod_to_ssi(mod);
1004 1009
1005 if (strstr(remote_ep->full_name, "hdmi0")) { 1010 if (strstr(remote_ep->full_name, "hdmi0")) {
1006 rsnd_ssi_flags_set(ssi, RSND_SSI_HDMI0); 1011 rsnd_flags_set(ssi, RSND_SSI_HDMI0);
1007 dev_dbg(dev, "%s[%d] connected to HDMI0\n", 1012 dev_dbg(dev, "%s[%d] connected to HDMI0\n",
1008 rsnd_mod_name(mod), rsnd_mod_id(mod)); 1013 rsnd_mod_name(mod), rsnd_mod_id(mod));
1009 } 1014 }
1010 1015
1011 if (strstr(remote_ep->full_name, "hdmi1")) { 1016 if (strstr(remote_ep->full_name, "hdmi1")) {
1012 rsnd_ssi_flags_set(ssi, RSND_SSI_HDMI1); 1017 rsnd_flags_set(ssi, RSND_SSI_HDMI1);
1013 dev_dbg(dev, "%s[%d] connected to HDMI1\n", 1018 dev_dbg(dev, "%s[%d] connected to HDMI1\n",
1014 rsnd_mod_name(mod), rsnd_mod_id(mod)); 1019 rsnd_mod_name(mod), rsnd_mod_id(mod));
1015 } 1020 }
@@ -1042,7 +1047,7 @@ int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod)
1042{ 1047{
1043 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 1048 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
1044 1049
1045 return !!(rsnd_ssi_flags_has(ssi, RSND_SSI_CLK_PIN_SHARE)); 1050 return !!(rsnd_flags_has(ssi, RSND_SSI_CLK_PIN_SHARE));
1046} 1051}
1047 1052
1048static u32 *rsnd_ssi_get_status(struct rsnd_dai_stream *io, 1053static u32 *rsnd_ssi_get_status(struct rsnd_dai_stream *io,
@@ -1112,6 +1117,9 @@ int rsnd_ssi_probe(struct rsnd_priv *priv)
1112 1117
1113 i = 0; 1118 i = 0;
1114 for_each_child_of_node(node, np) { 1119 for_each_child_of_node(node, np) {
1120 if (!of_device_is_available(np))
1121 goto skip;
1122
1115 ssi = rsnd_ssi_get(priv, i); 1123 ssi = rsnd_ssi_get(priv, i);
1116 1124
1117 snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d", 1125 snprintf(name, RSND_SSI_NAME_SIZE, "%s.%d",
@@ -1125,10 +1133,10 @@ int rsnd_ssi_probe(struct rsnd_priv *priv)
1125 } 1133 }
1126 1134
1127 if (of_get_property(np, "shared-pin", NULL)) 1135 if (of_get_property(np, "shared-pin", NULL))
1128 rsnd_ssi_flags_set(ssi, RSND_SSI_CLK_PIN_SHARE); 1136 rsnd_flags_set(ssi, RSND_SSI_CLK_PIN_SHARE);
1129 1137
1130 if (of_get_property(np, "no-busif", NULL)) 1138 if (of_get_property(np, "no-busif", NULL))
1131 rsnd_ssi_flags_set(ssi, RSND_SSI_NO_BUSIF); 1139 rsnd_flags_set(ssi, RSND_SSI_NO_BUSIF);
1132 1140
1133 ssi->irq = irq_of_parse_and_map(np, 0); 1141 ssi->irq = irq_of_parse_and_map(np, 0);
1134 if (!ssi->irq) { 1142 if (!ssi->irq) {
@@ -1148,7 +1156,7 @@ int rsnd_ssi_probe(struct rsnd_priv *priv)
1148 of_node_put(np); 1156 of_node_put(np);
1149 goto rsnd_ssi_probe_done; 1157 goto rsnd_ssi_probe_done;
1150 } 1158 }
1151 1159skip:
1152 i++; 1160 i++;
1153 } 1161 }
1154 1162
diff --git a/sound/soc/intel/common/sst-match-acpi.c b/sound/soc/soc-acpi.c
index 56d26f36a3cb..f21df28bc28e 100644
--- a/sound/soc/intel/common/sst-match-acpi.c
+++ b/sound/soc/soc-acpi.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * sst_match_apci.c - SST (LPE) match for ACPI enumeration. 2 * soc-apci.c - support for ACPI enumeration.
3 * 3 *
4 * Copyright (c) 2013-15, Intel Corporation. 4 * Copyright (c) 2013-15, Intel Corporation.
5 * 5 *
@@ -14,9 +14,9 @@
14 * more details. 14 * more details.
15 */ 15 */
16 16
17#include "sst-acpi.h" 17#include <sound/soc-acpi.h>
18 18
19static acpi_status sst_acpi_find_name(acpi_handle handle, u32 level, 19static acpi_status snd_soc_acpi_find_name(acpi_handle handle, u32 level,
20 void *context, void **ret) 20 void *context, void **ret)
21{ 21{
22 struct acpi_device *adev; 22 struct acpi_device *adev;
@@ -34,12 +34,12 @@ static acpi_status sst_acpi_find_name(acpi_handle handle, u32 level,
34 return AE_OK; 34 return AE_OK;
35} 35}
36 36
37const char *sst_acpi_find_name_from_hid(const u8 hid[ACPI_ID_LEN]) 37const char *snd_soc_acpi_find_name_from_hid(const u8 hid[ACPI_ID_LEN])
38{ 38{
39 const char *name = NULL; 39 const char *name = NULL;
40 acpi_status status; 40 acpi_status status;
41 41
42 status = acpi_get_devices(hid, sst_acpi_find_name, NULL, 42 status = acpi_get_devices(hid, snd_soc_acpi_find_name, NULL,
43 (void **)&name); 43 (void **)&name);
44 44
45 if (ACPI_FAILURE(status) || name[0] == '\0') 45 if (ACPI_FAILURE(status) || name[0] == '\0')
@@ -47,9 +47,9 @@ const char *sst_acpi_find_name_from_hid(const u8 hid[ACPI_ID_LEN])
47 47
48 return name; 48 return name;
49} 49}
50EXPORT_SYMBOL_GPL(sst_acpi_find_name_from_hid); 50EXPORT_SYMBOL_GPL(snd_soc_acpi_find_name_from_hid);
51 51
52static acpi_status sst_acpi_mach_match(acpi_handle handle, u32 level, 52static acpi_status snd_soc_acpi_mach_match(acpi_handle handle, u32 level,
53 void *context, void **ret) 53 void *context, void **ret)
54{ 54{
55 unsigned long long sta; 55 unsigned long long sta;
@@ -63,26 +63,27 @@ static acpi_status sst_acpi_mach_match(acpi_handle handle, u32 level,
63 return AE_OK; 63 return AE_OK;
64} 64}
65 65
66bool sst_acpi_check_hid(const u8 hid[ACPI_ID_LEN]) 66bool snd_soc_acpi_check_hid(const u8 hid[ACPI_ID_LEN])
67{ 67{
68 acpi_status status; 68 acpi_status status;
69 bool found = false; 69 bool found = false;
70 70
71 status = acpi_get_devices(hid, sst_acpi_mach_match, &found, NULL); 71 status = acpi_get_devices(hid, snd_soc_acpi_mach_match, &found, NULL);
72 72
73 if (ACPI_FAILURE(status)) 73 if (ACPI_FAILURE(status))
74 return false; 74 return false;
75 75
76 return found; 76 return found;
77} 77}
78EXPORT_SYMBOL_GPL(sst_acpi_check_hid); 78EXPORT_SYMBOL_GPL(snd_soc_acpi_check_hid);
79 79
80struct sst_acpi_mach *sst_acpi_find_machine(struct sst_acpi_mach *machines) 80struct snd_soc_acpi_mach *
81snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines)
81{ 82{
82 struct sst_acpi_mach *mach; 83 struct snd_soc_acpi_mach *mach;
83 84
84 for (mach = machines; mach->id[0]; mach++) { 85 for (mach = machines; mach->id[0]; mach++) {
85 if (sst_acpi_check_hid(mach->id) == true) { 86 if (snd_soc_acpi_check_hid(mach->id) == true) {
86 if (mach->machine_quirk == NULL) 87 if (mach->machine_quirk == NULL)
87 return mach; 88 return mach;
88 89
@@ -92,14 +93,14 @@ struct sst_acpi_mach *sst_acpi_find_machine(struct sst_acpi_mach *machines)
92 } 93 }
93 return NULL; 94 return NULL;
94} 95}
95EXPORT_SYMBOL_GPL(sst_acpi_find_machine); 96EXPORT_SYMBOL_GPL(snd_soc_acpi_find_machine);
96 97
97static acpi_status sst_acpi_find_package(acpi_handle handle, u32 level, 98static acpi_status snd_soc_acpi_find_package(acpi_handle handle, u32 level,
98 void *context, void **ret) 99 void *context, void **ret)
99{ 100{
100 struct acpi_device *adev; 101 struct acpi_device *adev;
101 acpi_status status = AE_OK; 102 acpi_status status = AE_OK;
102 struct sst_acpi_package_context *pkg_ctx = context; 103 struct snd_soc_acpi_package_context *pkg_ctx = context;
103 104
104 pkg_ctx->data_valid = false; 105 pkg_ctx->data_valid = false;
105 106
@@ -137,37 +138,38 @@ static acpi_status sst_acpi_find_package(acpi_handle handle, u32 level,
137 return AE_OK; 138 return AE_OK;
138} 139}
139 140
140bool sst_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN], 141bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
141 struct sst_acpi_package_context *ctx) 142 struct snd_soc_acpi_package_context *ctx)
142{ 143{
143 acpi_status status; 144 acpi_status status;
144 145
145 status = acpi_get_devices(hid, sst_acpi_find_package, ctx, NULL); 146 status = acpi_get_devices(hid, snd_soc_acpi_find_package, ctx, NULL);
146 147
147 if (ACPI_FAILURE(status) || !ctx->data_valid) 148 if (ACPI_FAILURE(status) || !ctx->data_valid)
148 return false; 149 return false;
149 150
150 return true; 151 return true;
151} 152}
152EXPORT_SYMBOL_GPL(sst_acpi_find_package_from_hid); 153EXPORT_SYMBOL_GPL(snd_soc_acpi_find_package_from_hid);
153 154
154struct sst_acpi_mach *sst_acpi_codec_list(void *arg) 155struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg)
155{ 156{
156 struct sst_acpi_mach *mach = arg; 157 struct snd_soc_acpi_mach *mach = arg;
157 struct sst_codecs *codec_list = (struct sst_codecs *) mach->quirk_data; 158 struct snd_soc_acpi_codecs *codec_list =
159 (struct snd_soc_acpi_codecs *) mach->quirk_data;
158 int i; 160 int i;
159 161
160 if (mach->quirk_data == NULL) 162 if (mach->quirk_data == NULL)
161 return mach; 163 return mach;
162 164
163 for (i = 0; i < codec_list->num_codecs; i++) { 165 for (i = 0; i < codec_list->num_codecs; i++) {
164 if (sst_acpi_check_hid(codec_list->codecs[i]) != true) 166 if (snd_soc_acpi_check_hid(codec_list->codecs[i]) != true)
165 return NULL; 167 return NULL;
166 } 168 }
167 169
168 return mach; 170 return mach;
169} 171}
170EXPORT_SYMBOL_GPL(sst_acpi_codec_list); 172EXPORT_SYMBOL_GPL(snd_soc_acpi_codec_list);
171 173
172MODULE_LICENSE("GPL v2"); 174MODULE_LICENSE("GPL v2");
173MODULE_DESCRIPTION("Intel Common ACPI Match module"); 175MODULE_DESCRIPTION("ALSA SoC ACPI module");
diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c
index 2cb8d3b55fbc..d9b1e6417fb9 100644
--- a/sound/soc/soc-compress.c
+++ b/sound/soc/soc-compress.c
@@ -30,8 +30,10 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
30{ 30{
31 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 31 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
32 struct snd_soc_platform *platform = rtd->platform; 32 struct snd_soc_platform *platform = rtd->platform;
33 struct snd_soc_component *component;
34 struct snd_soc_rtdcom_list *rtdcom;
33 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 35 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
34 int ret = 0; 36 int ret = 0, __ret;
35 37
36 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 38 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
37 39
@@ -44,7 +46,7 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
44 } 46 }
45 } 47 }
46 48
47 if (platform->driver->compr_ops && platform->driver->compr_ops->open) { 49 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->open) {
48 ret = platform->driver->compr_ops->open(cstream); 50 ret = platform->driver->compr_ops->open(cstream);
49 if (ret < 0) { 51 if (ret < 0) {
50 pr_err("compress asoc: can't open platform %s\n", 52 pr_err("compress asoc: can't open platform %s\n",
@@ -53,6 +55,27 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
53 } 55 }
54 } 56 }
55 57
58 for_each_rtdcom(rtd, rtdcom) {
59 component = rtdcom->component;
60
61 /* ignore duplication for now */
62 if (platform && (component == &platform->component))
63 continue;
64
65 if (!component->driver->compr_ops ||
66 !component->driver->compr_ops->open)
67 continue;
68
69 __ret = component->driver->compr_ops->open(cstream);
70 if (__ret < 0) {
71 pr_err("compress asoc: can't open platform %s\n",
72 component->name);
73 ret = __ret;
74 }
75 }
76 if (ret < 0)
77 goto machine_err;
78
56 if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->startup) { 79 if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->startup) {
57 ret = rtd->dai_link->compr_ops->startup(cstream); 80 ret = rtd->dai_link->compr_ops->startup(cstream);
58 if (ret < 0) { 81 if (ret < 0) {
@@ -68,7 +91,21 @@ static int soc_compr_open(struct snd_compr_stream *cstream)
68 return 0; 91 return 0;
69 92
70machine_err: 93machine_err:
71 if (platform->driver->compr_ops && platform->driver->compr_ops->free) 94 for_each_rtdcom(rtd, rtdcom) {
95 component = rtdcom->component;
96
97 /* ignore duplication for now */
98 if (platform && (component == &platform->component))
99 continue;
100
101 if (!component->driver->compr_ops ||
102 !component->driver->compr_ops->free)
103 continue;
104
105 component->driver->compr_ops->free(cstream);
106 }
107
108 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->free)
72 platform->driver->compr_ops->free(cstream); 109 platform->driver->compr_ops->free(cstream);
73plat_err: 110plat_err:
74 if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) 111 if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
@@ -84,11 +121,13 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
84 struct snd_pcm_substream *fe_substream = 121 struct snd_pcm_substream *fe_substream =
85 fe->pcm->streams[cstream->direction].substream; 122 fe->pcm->streams[cstream->direction].substream;
86 struct snd_soc_platform *platform = fe->platform; 123 struct snd_soc_platform *platform = fe->platform;
124 struct snd_soc_component *component;
125 struct snd_soc_rtdcom_list *rtdcom;
87 struct snd_soc_dai *cpu_dai = fe->cpu_dai; 126 struct snd_soc_dai *cpu_dai = fe->cpu_dai;
88 struct snd_soc_dpcm *dpcm; 127 struct snd_soc_dpcm *dpcm;
89 struct snd_soc_dapm_widget_list *list; 128 struct snd_soc_dapm_widget_list *list;
90 int stream; 129 int stream;
91 int ret = 0; 130 int ret = 0, __ret;
92 131
93 if (cstream->direction == SND_COMPRESS_PLAYBACK) 132 if (cstream->direction == SND_COMPRESS_PLAYBACK)
94 stream = SNDRV_PCM_STREAM_PLAYBACK; 133 stream = SNDRV_PCM_STREAM_PLAYBACK;
@@ -107,7 +146,7 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
107 } 146 }
108 147
109 148
110 if (platform->driver->compr_ops && platform->driver->compr_ops->open) { 149 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->open) {
111 ret = platform->driver->compr_ops->open(cstream); 150 ret = platform->driver->compr_ops->open(cstream);
112 if (ret < 0) { 151 if (ret < 0) {
113 pr_err("compress asoc: can't open platform %s\n", 152 pr_err("compress asoc: can't open platform %s\n",
@@ -116,6 +155,27 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream)
116 } 155 }
117 } 156 }
118 157
158 for_each_rtdcom(fe, rtdcom) {
159 component = rtdcom->component;
160
161 /* ignore duplication for now */
162 if (platform && (component == &platform->component))
163 continue;
164
165 if (!component->driver->compr_ops ||
166 !component->driver->compr_ops->open)
167 continue;
168
169 __ret = component->driver->compr_ops->open(cstream);
170 if (__ret < 0) {
171 pr_err("compress asoc: can't open platform %s\n",
172 component->name);
173 ret = __ret;
174 }
175 }
176 if (ret < 0)
177 goto machine_err;
178
119 if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->startup) { 179 if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->startup) {
120 ret = fe->dai_link->compr_ops->startup(cstream); 180 ret = fe->dai_link->compr_ops->startup(cstream);
121 if (ret < 0) { 181 if (ret < 0) {
@@ -167,7 +227,21 @@ fe_err:
167 if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown) 227 if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown)
168 fe->dai_link->compr_ops->shutdown(cstream); 228 fe->dai_link->compr_ops->shutdown(cstream);
169machine_err: 229machine_err:
170 if (platform->driver->compr_ops && platform->driver->compr_ops->free) 230 for_each_rtdcom(fe, rtdcom) {
231 component = rtdcom->component;
232
233 /* ignore duplication for now */
234 if (platform && (component == &platform->component))
235 continue;
236
237 if (!component->driver->compr_ops ||
238 !component->driver->compr_ops->free)
239 continue;
240
241 component->driver->compr_ops->free(cstream);
242 }
243
244 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->free)
171 platform->driver->compr_ops->free(cstream); 245 platform->driver->compr_ops->free(cstream);
172plat_err: 246plat_err:
173 if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) 247 if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
@@ -210,6 +284,8 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
210{ 284{
211 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 285 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
212 struct snd_soc_platform *platform = rtd->platform; 286 struct snd_soc_platform *platform = rtd->platform;
287 struct snd_soc_component *component;
288 struct snd_soc_rtdcom_list *rtdcom;
213 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 289 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
214 struct snd_soc_dai *codec_dai = rtd->codec_dai; 290 struct snd_soc_dai *codec_dai = rtd->codec_dai;
215 int stream; 291 int stream;
@@ -235,7 +311,21 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
235 if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->shutdown) 311 if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->shutdown)
236 rtd->dai_link->compr_ops->shutdown(cstream); 312 rtd->dai_link->compr_ops->shutdown(cstream);
237 313
238 if (platform->driver->compr_ops && platform->driver->compr_ops->free) 314 for_each_rtdcom(rtd, rtdcom) {
315 component = rtdcom->component;
316
317 /* ignore duplication for now */
318 if (platform && (component == &platform->component))
319 continue;
320
321 if (!component->driver->compr_ops ||
322 !component->driver->compr_ops->free)
323 continue;
324
325 component->driver->compr_ops->free(cstream);
326 }
327
328 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->free)
239 platform->driver->compr_ops->free(cstream); 329 platform->driver->compr_ops->free(cstream);
240 330
241 if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) 331 if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
@@ -267,6 +357,8 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
267{ 357{
268 struct snd_soc_pcm_runtime *fe = cstream->private_data; 358 struct snd_soc_pcm_runtime *fe = cstream->private_data;
269 struct snd_soc_platform *platform = fe->platform; 359 struct snd_soc_platform *platform = fe->platform;
360 struct snd_soc_component *component;
361 struct snd_soc_rtdcom_list *rtdcom;
270 struct snd_soc_dai *cpu_dai = fe->cpu_dai; 362 struct snd_soc_dai *cpu_dai = fe->cpu_dai;
271 struct snd_soc_dpcm *dpcm; 363 struct snd_soc_dpcm *dpcm;
272 int stream, ret; 364 int stream, ret;
@@ -304,9 +396,23 @@ static int soc_compr_free_fe(struct snd_compr_stream *cstream)
304 if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown) 396 if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->shutdown)
305 fe->dai_link->compr_ops->shutdown(cstream); 397 fe->dai_link->compr_ops->shutdown(cstream);
306 398
307 if (platform->driver->compr_ops && platform->driver->compr_ops->free) 399 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->free)
308 platform->driver->compr_ops->free(cstream); 400 platform->driver->compr_ops->free(cstream);
309 401
402 for_each_rtdcom(fe, rtdcom) {
403 component = rtdcom->component;
404
405 /* ignore duplication for now */
406 if (platform && (component == &platform->component))
407 continue;
408
409 if (!component->driver->compr_ops ||
410 !component->driver->compr_ops->free)
411 continue;
412
413 component->driver->compr_ops->free(cstream);
414 }
415
310 if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown) 416 if (cpu_dai->driver->cops && cpu_dai->driver->cops->shutdown)
311 cpu_dai->driver->cops->shutdown(cstream, cpu_dai); 417 cpu_dai->driver->cops->shutdown(cstream, cpu_dai);
312 418
@@ -319,18 +425,38 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
319 425
320 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 426 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
321 struct snd_soc_platform *platform = rtd->platform; 427 struct snd_soc_platform *platform = rtd->platform;
428 struct snd_soc_component *component;
429 struct snd_soc_rtdcom_list *rtdcom;
322 struct snd_soc_dai *codec_dai = rtd->codec_dai; 430 struct snd_soc_dai *codec_dai = rtd->codec_dai;
323 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 431 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
324 int ret = 0; 432 int ret = 0, __ret;
325 433
326 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 434 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
327 435
328 if (platform->driver->compr_ops && platform->driver->compr_ops->trigger) { 436 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->trigger) {
329 ret = platform->driver->compr_ops->trigger(cstream, cmd); 437 ret = platform->driver->compr_ops->trigger(cstream, cmd);
330 if (ret < 0) 438 if (ret < 0)
331 goto out; 439 goto out;
332 } 440 }
333 441
442 for_each_rtdcom(rtd, rtdcom) {
443 component = rtdcom->component;
444
445 /* ignore duplication for now */
446 if (platform && (component == &platform->component))
447 continue;
448
449 if (!component->driver->compr_ops ||
450 !component->driver->compr_ops->trigger)
451 continue;
452
453 __ret = component->driver->compr_ops->trigger(cstream, cmd);
454 if (__ret < 0)
455 ret = __ret;
456 }
457 if (ret < 0)
458 goto out;
459
334 if (cpu_dai->driver->cops && cpu_dai->driver->cops->trigger) 460 if (cpu_dai->driver->cops && cpu_dai->driver->cops->trigger)
335 cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai); 461 cpu_dai->driver->cops->trigger(cstream, cmd, cpu_dai);
336 462
@@ -353,16 +479,36 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd)
353{ 479{
354 struct snd_soc_pcm_runtime *fe = cstream->private_data; 480 struct snd_soc_pcm_runtime *fe = cstream->private_data;
355 struct snd_soc_platform *platform = fe->platform; 481 struct snd_soc_platform *platform = fe->platform;
482 struct snd_soc_component *component;
483 struct snd_soc_rtdcom_list *rtdcom;
356 struct snd_soc_dai *cpu_dai = fe->cpu_dai; 484 struct snd_soc_dai *cpu_dai = fe->cpu_dai;
357 int ret = 0, stream; 485 int ret = 0, __ret, stream;
358 486
359 if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN || 487 if (cmd == SND_COMPR_TRIGGER_PARTIAL_DRAIN ||
360 cmd == SND_COMPR_TRIGGER_DRAIN) { 488 cmd == SND_COMPR_TRIGGER_DRAIN) {
361 489
362 if (platform->driver->compr_ops && 490 if (platform &&
491 platform->driver->compr_ops &&
363 platform->driver->compr_ops->trigger) 492 platform->driver->compr_ops->trigger)
364 return platform->driver->compr_ops->trigger(cstream, 493 return platform->driver->compr_ops->trigger(cstream,
365 cmd); 494 cmd);
495
496 for_each_rtdcom(fe, rtdcom) {
497 component = rtdcom->component;
498
499 /* ignore duplication for now */
500 if (platform && (component == &platform->component))
501 continue;
502
503 if (!component->driver->compr_ops ||
504 !component->driver->compr_ops->trigger)
505 continue;
506
507 __ret = component->driver->compr_ops->trigger(cstream, cmd);
508 if (__ret < 0)
509 ret = __ret;
510 }
511 return ret;
366 } 512 }
367 513
368 if (cstream->direction == SND_COMPRESS_PLAYBACK) 514 if (cstream->direction == SND_COMPRESS_PLAYBACK)
@@ -379,12 +525,30 @@ static int soc_compr_trigger_fe(struct snd_compr_stream *cstream, int cmd)
379 goto out; 525 goto out;
380 } 526 }
381 527
382 if (platform->driver->compr_ops && platform->driver->compr_ops->trigger) { 528 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->trigger) {
383 ret = platform->driver->compr_ops->trigger(cstream, cmd); 529 ret = platform->driver->compr_ops->trigger(cstream, cmd);
384 if (ret < 0) 530 if (ret < 0)
385 goto out; 531 goto out;
386 } 532 }
387 533
534 for_each_rtdcom(fe, rtdcom) {
535 component = rtdcom->component;
536
537 /* ignore duplication for now */
538 if (platform && (component == &platform->component))
539 continue;
540
541 if (!component->driver->compr_ops ||
542 !component->driver->compr_ops->trigger)
543 continue;
544
545 __ret = component->driver->compr_ops->trigger(cstream, cmd);
546 if (__ret < 0)
547 ret = __ret;
548 }
549 if (ret < 0)
550 goto out;
551
388 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; 552 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE;
389 553
390 ret = dpcm_be_dai_trigger(fe, stream, cmd); 554 ret = dpcm_be_dai_trigger(fe, stream, cmd);
@@ -415,8 +579,10 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream,
415{ 579{
416 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 580 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
417 struct snd_soc_platform *platform = rtd->platform; 581 struct snd_soc_platform *platform = rtd->platform;
582 struct snd_soc_component *component;
583 struct snd_soc_rtdcom_list *rtdcom;
418 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 584 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
419 int ret = 0; 585 int ret = 0, __ret;
420 586
421 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 587 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
422 588
@@ -432,12 +598,30 @@ static int soc_compr_set_params(struct snd_compr_stream *cstream,
432 goto err; 598 goto err;
433 } 599 }
434 600
435 if (platform->driver->compr_ops && platform->driver->compr_ops->set_params) { 601 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->set_params) {
436 ret = platform->driver->compr_ops->set_params(cstream, params); 602 ret = platform->driver->compr_ops->set_params(cstream, params);
437 if (ret < 0) 603 if (ret < 0)
438 goto err; 604 goto err;
439 } 605 }
440 606
607 for_each_rtdcom(rtd, rtdcom) {
608 component = rtdcom->component;
609
610 /* ignore duplication for now */
611 if (platform && (component == &platform->component))
612 continue;
613
614 if (!component->driver->compr_ops ||
615 !component->driver->compr_ops->set_params)
616 continue;
617
618 __ret = component->driver->compr_ops->set_params(cstream, params);
619 if (__ret < 0)
620 ret = __ret;
621 }
622 if (ret < 0)
623 goto err;
624
441 if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->set_params) { 625 if (rtd->dai_link->compr_ops && rtd->dai_link->compr_ops->set_params) {
442 ret = rtd->dai_link->compr_ops->set_params(cstream); 626 ret = rtd->dai_link->compr_ops->set_params(cstream);
443 if (ret < 0) 627 if (ret < 0)
@@ -471,8 +655,10 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
471 struct snd_pcm_substream *fe_substream = 655 struct snd_pcm_substream *fe_substream =
472 fe->pcm->streams[cstream->direction].substream; 656 fe->pcm->streams[cstream->direction].substream;
473 struct snd_soc_platform *platform = fe->platform; 657 struct snd_soc_platform *platform = fe->platform;
658 struct snd_soc_component *component;
659 struct snd_soc_rtdcom_list *rtdcom;
474 struct snd_soc_dai *cpu_dai = fe->cpu_dai; 660 struct snd_soc_dai *cpu_dai = fe->cpu_dai;
475 int ret = 0, stream; 661 int ret = 0, __ret, stream;
476 662
477 if (cstream->direction == SND_COMPRESS_PLAYBACK) 663 if (cstream->direction == SND_COMPRESS_PLAYBACK)
478 stream = SNDRV_PCM_STREAM_PLAYBACK; 664 stream = SNDRV_PCM_STREAM_PLAYBACK;
@@ -487,12 +673,30 @@ static int soc_compr_set_params_fe(struct snd_compr_stream *cstream,
487 goto out; 673 goto out;
488 } 674 }
489 675
490 if (platform->driver->compr_ops && platform->driver->compr_ops->set_params) { 676 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->set_params) {
491 ret = platform->driver->compr_ops->set_params(cstream, params); 677 ret = platform->driver->compr_ops->set_params(cstream, params);
492 if (ret < 0) 678 if (ret < 0)
493 goto out; 679 goto out;
494 } 680 }
495 681
682 for_each_rtdcom(fe, rtdcom) {
683 component = rtdcom->component;
684
685 /* ignore duplication for now */
686 if (platform && (component == &platform->component))
687 continue;
688
689 if (!component->driver->compr_ops ||
690 !component->driver->compr_ops->set_params)
691 continue;
692
693 __ret = component->driver->compr_ops->set_params(cstream, params);
694 if (__ret < 0)
695 ret = __ret;
696 }
697 if (ret < 0)
698 goto out;
699
496 if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->set_params) { 700 if (fe->dai_link->compr_ops && fe->dai_link->compr_ops->set_params) {
497 ret = fe->dai_link->compr_ops->set_params(cstream); 701 ret = fe->dai_link->compr_ops->set_params(cstream);
498 if (ret < 0) 702 if (ret < 0)
@@ -531,8 +735,10 @@ static int soc_compr_get_params(struct snd_compr_stream *cstream,
531{ 735{
532 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 736 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
533 struct snd_soc_platform *platform = rtd->platform; 737 struct snd_soc_platform *platform = rtd->platform;
738 struct snd_soc_component *component;
739 struct snd_soc_rtdcom_list *rtdcom;
534 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 740 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
535 int ret = 0; 741 int ret = 0, __ret;
536 742
537 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 743 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
538 744
@@ -542,8 +748,27 @@ static int soc_compr_get_params(struct snd_compr_stream *cstream,
542 goto err; 748 goto err;
543 } 749 }
544 750
545 if (platform->driver->compr_ops && platform->driver->compr_ops->get_params) 751 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->get_params) {
546 ret = platform->driver->compr_ops->get_params(cstream, params); 752 ret = platform->driver->compr_ops->get_params(cstream, params);
753 if (ret < 0)
754 goto err;
755 }
756
757 for_each_rtdcom(rtd, rtdcom) {
758 component = rtdcom->component;
759
760 /* ignore duplication for now */
761 if (platform && (component == &platform->component))
762 continue;
763
764 if (!component->driver->compr_ops ||
765 !component->driver->compr_ops->get_params)
766 continue;
767
768 __ret = component->driver->compr_ops->get_params(cstream, params);
769 if (__ret < 0)
770 ret = __ret;
771 }
547 772
548err: 773err:
549 mutex_unlock(&rtd->pcm_mutex); 774 mutex_unlock(&rtd->pcm_mutex);
@@ -555,13 +780,35 @@ static int soc_compr_get_caps(struct snd_compr_stream *cstream,
555{ 780{
556 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 781 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
557 struct snd_soc_platform *platform = rtd->platform; 782 struct snd_soc_platform *platform = rtd->platform;
558 int ret = 0; 783 struct snd_soc_component *component;
784 struct snd_soc_rtdcom_list *rtdcom;
785 int ret = 0, __ret;
559 786
560 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 787 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
561 788
562 if (platform->driver->compr_ops && platform->driver->compr_ops->get_caps) 789 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->get_caps) {
563 ret = platform->driver->compr_ops->get_caps(cstream, caps); 790 ret = platform->driver->compr_ops->get_caps(cstream, caps);
791 if (ret < 0)
792 goto err;
793 }
794
795 for_each_rtdcom(rtd, rtdcom) {
796 component = rtdcom->component;
797
798 /* ignore duplication for now */
799 if (platform && (component == &platform->component))
800 continue;
564 801
802 if (!component->driver->compr_ops ||
803 !component->driver->compr_ops->get_caps)
804 continue;
805
806 __ret = component->driver->compr_ops->get_caps(cstream, caps);
807 if (__ret < 0)
808 ret = __ret;
809 }
810
811err:
565 mutex_unlock(&rtd->pcm_mutex); 812 mutex_unlock(&rtd->pcm_mutex);
566 return ret; 813 return ret;
567} 814}
@@ -571,13 +818,35 @@ static int soc_compr_get_codec_caps(struct snd_compr_stream *cstream,
571{ 818{
572 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 819 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
573 struct snd_soc_platform *platform = rtd->platform; 820 struct snd_soc_platform *platform = rtd->platform;
574 int ret = 0; 821 struct snd_soc_component *component;
822 struct snd_soc_rtdcom_list *rtdcom;
823 int ret = 0, __ret;
575 824
576 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 825 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
577 826
578 if (platform->driver->compr_ops && platform->driver->compr_ops->get_codec_caps) 827 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->get_codec_caps) {
579 ret = platform->driver->compr_ops->get_codec_caps(cstream, codec); 828 ret = platform->driver->compr_ops->get_codec_caps(cstream, codec);
829 if (ret < 0)
830 goto err;
831 }
832
833 for_each_rtdcom(rtd, rtdcom) {
834 component = rtdcom->component;
835
836 /* ignore duplication for now */
837 if (platform && (component == &platform->component))
838 continue;
580 839
840 if (!component->driver->compr_ops ||
841 !component->driver->compr_ops->get_codec_caps)
842 continue;
843
844 __ret = component->driver->compr_ops->get_codec_caps(cstream, codec);
845 if (__ret < 0)
846 ret = __ret;
847 }
848
849err:
581 mutex_unlock(&rtd->pcm_mutex); 850 mutex_unlock(&rtd->pcm_mutex);
582 return ret; 851 return ret;
583} 852}
@@ -586,8 +855,10 @@ static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
586{ 855{
587 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 856 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
588 struct snd_soc_platform *platform = rtd->platform; 857 struct snd_soc_platform *platform = rtd->platform;
858 struct snd_soc_component *component;
859 struct snd_soc_rtdcom_list *rtdcom;
589 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 860 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
590 int ret = 0; 861 int ret = 0, __ret;
591 862
592 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 863 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
593 864
@@ -597,8 +868,27 @@ static int soc_compr_ack(struct snd_compr_stream *cstream, size_t bytes)
597 goto err; 868 goto err;
598 } 869 }
599 870
600 if (platform->driver->compr_ops && platform->driver->compr_ops->ack) 871 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->ack) {
601 ret = platform->driver->compr_ops->ack(cstream, bytes); 872 ret = platform->driver->compr_ops->ack(cstream, bytes);
873 if (ret < 0)
874 goto err;
875 }
876
877 for_each_rtdcom(rtd, rtdcom) {
878 component = rtdcom->component;
879
880 /* ignore duplication for now */
881 if (platform && (component == &platform->component))
882 continue;
883
884 if (!component->driver->compr_ops ||
885 !component->driver->compr_ops->ack)
886 continue;
887
888 __ret = component->driver->compr_ops->ack(cstream, bytes);
889 if (__ret < 0)
890 ret = __ret;
891 }
602 892
603err: 893err:
604 mutex_unlock(&rtd->pcm_mutex); 894 mutex_unlock(&rtd->pcm_mutex);
@@ -610,7 +900,9 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream,
610{ 900{
611 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 901 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
612 struct snd_soc_platform *platform = rtd->platform; 902 struct snd_soc_platform *platform = rtd->platform;
613 int ret = 0; 903 struct snd_soc_component *component;
904 struct snd_soc_rtdcom_list *rtdcom;
905 int ret = 0, __ret;
614 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 906 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
615 907
616 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 908 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
@@ -618,9 +910,29 @@ static int soc_compr_pointer(struct snd_compr_stream *cstream,
618 if (cpu_dai->driver->cops && cpu_dai->driver->cops->pointer) 910 if (cpu_dai->driver->cops && cpu_dai->driver->cops->pointer)
619 cpu_dai->driver->cops->pointer(cstream, tstamp, cpu_dai); 911 cpu_dai->driver->cops->pointer(cstream, tstamp, cpu_dai);
620 912
621 if (platform->driver->compr_ops && platform->driver->compr_ops->pointer) 913 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->pointer) {
622 ret = platform->driver->compr_ops->pointer(cstream, tstamp); 914 ret = platform->driver->compr_ops->pointer(cstream, tstamp);
915 if (ret < 0)
916 goto err;
917 }
918
919 for_each_rtdcom(rtd, rtdcom) {
920 component = rtdcom->component;
921
922 /* ignore duplication for now */
923 if (platform && (component == &platform->component))
924 continue;
925
926 if (!component->driver->compr_ops ||
927 !component->driver->compr_ops->pointer)
928 continue;
623 929
930 __ret = component->driver->compr_ops->pointer(cstream, tstamp);
931 if (__ret < 0)
932 ret = __ret;
933 }
934
935err:
624 mutex_unlock(&rtd->pcm_mutex); 936 mutex_unlock(&rtd->pcm_mutex);
625 return ret; 937 return ret;
626} 938}
@@ -630,13 +942,34 @@ static int soc_compr_copy(struct snd_compr_stream *cstream,
630{ 942{
631 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 943 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
632 struct snd_soc_platform *platform = rtd->platform; 944 struct snd_soc_platform *platform = rtd->platform;
633 int ret = 0; 945 struct snd_soc_component *component;
946 struct snd_soc_rtdcom_list *rtdcom;
947 int ret = 0, __ret;
634 948
635 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 949 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
636 950
637 if (platform->driver->compr_ops && platform->driver->compr_ops->copy) 951 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->copy) {
638 ret = platform->driver->compr_ops->copy(cstream, buf, count); 952 ret = platform->driver->compr_ops->copy(cstream, buf, count);
953 if (ret < 0)
954 goto err;
955 }
956
957 for_each_rtdcom(rtd, rtdcom) {
958 component = rtdcom->component;
959
960 /* ignore duplication for now */
961 if (platform && (component == &platform->component))
962 continue;
963
964 if (!component->driver->compr_ops ||
965 !component->driver->compr_ops->copy)
966 continue;
639 967
968 __ret = component->driver->compr_ops->copy(cstream, buf, count);
969 if (__ret < 0)
970 ret = __ret;
971 }
972err:
640 mutex_unlock(&rtd->pcm_mutex); 973 mutex_unlock(&rtd->pcm_mutex);
641 return ret; 974 return ret;
642} 975}
@@ -646,8 +979,10 @@ static int soc_compr_set_metadata(struct snd_compr_stream *cstream,
646{ 979{
647 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 980 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
648 struct snd_soc_platform *platform = rtd->platform; 981 struct snd_soc_platform *platform = rtd->platform;
982 struct snd_soc_component *component;
983 struct snd_soc_rtdcom_list *rtdcom;
649 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 984 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
650 int ret = 0; 985 int ret = 0, __ret;
651 986
652 if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_metadata) { 987 if (cpu_dai->driver->cops && cpu_dai->driver->cops->set_metadata) {
653 ret = cpu_dai->driver->cops->set_metadata(cstream, metadata, cpu_dai); 988 ret = cpu_dai->driver->cops->set_metadata(cstream, metadata, cpu_dai);
@@ -655,8 +990,27 @@ static int soc_compr_set_metadata(struct snd_compr_stream *cstream,
655 return ret; 990 return ret;
656 } 991 }
657 992
658 if (platform->driver->compr_ops && platform->driver->compr_ops->set_metadata) 993 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->set_metadata) {
659 ret = platform->driver->compr_ops->set_metadata(cstream, metadata); 994 ret = platform->driver->compr_ops->set_metadata(cstream, metadata);
995 if (ret < 0)
996 return ret;
997 }
998
999 for_each_rtdcom(rtd, rtdcom) {
1000 component = rtdcom->component;
1001
1002 /* ignore duplication for now */
1003 if (platform && (component == &platform->component))
1004 continue;
1005
1006 if (!component->driver->compr_ops ||
1007 !component->driver->compr_ops->set_metadata)
1008 continue;
1009
1010 __ret = component->driver->compr_ops->set_metadata(cstream, metadata);
1011 if (__ret < 0)
1012 ret = __ret;
1013 }
660 1014
661 return ret; 1015 return ret;
662} 1016}
@@ -666,8 +1020,10 @@ static int soc_compr_get_metadata(struct snd_compr_stream *cstream,
666{ 1020{
667 struct snd_soc_pcm_runtime *rtd = cstream->private_data; 1021 struct snd_soc_pcm_runtime *rtd = cstream->private_data;
668 struct snd_soc_platform *platform = rtd->platform; 1022 struct snd_soc_platform *platform = rtd->platform;
1023 struct snd_soc_component *component;
1024 struct snd_soc_rtdcom_list *rtdcom;
669 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 1025 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
670 int ret = 0; 1026 int ret = 0, __ret;
671 1027
672 if (cpu_dai->driver->cops && cpu_dai->driver->cops->get_metadata) { 1028 if (cpu_dai->driver->cops && cpu_dai->driver->cops->get_metadata) {
673 ret = cpu_dai->driver->cops->get_metadata(cstream, metadata, cpu_dai); 1029 ret = cpu_dai->driver->cops->get_metadata(cstream, metadata, cpu_dai);
@@ -675,8 +1031,27 @@ static int soc_compr_get_metadata(struct snd_compr_stream *cstream,
675 return ret; 1031 return ret;
676 } 1032 }
677 1033
678 if (platform->driver->compr_ops && platform->driver->compr_ops->get_metadata) 1034 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->get_metadata) {
679 ret = platform->driver->compr_ops->get_metadata(cstream, metadata); 1035 ret = platform->driver->compr_ops->get_metadata(cstream, metadata);
1036 if (ret < 0)
1037 return ret;
1038 }
1039
1040 for_each_rtdcom(rtd, rtdcom) {
1041 component = rtdcom->component;
1042
1043 /* ignore duplication for now */
1044 if (platform && (component == &platform->component))
1045 continue;
1046
1047 if (!component->driver->compr_ops ||
1048 !component->driver->compr_ops->get_metadata)
1049 continue;
1050
1051 __ret = component->driver->compr_ops->get_metadata(cstream, metadata);
1052 if (__ret < 0)
1053 ret = __ret;
1054 }
680 1055
681 return ret; 1056 return ret;
682} 1057}
@@ -723,6 +1098,8 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
723{ 1098{
724 struct snd_soc_codec *codec = rtd->codec; 1099 struct snd_soc_codec *codec = rtd->codec;
725 struct snd_soc_platform *platform = rtd->platform; 1100 struct snd_soc_platform *platform = rtd->platform;
1101 struct snd_soc_component *component;
1102 struct snd_soc_rtdcom_list *rtdcom;
726 struct snd_soc_dai *codec_dai = rtd->codec_dai; 1103 struct snd_soc_dai *codec_dai = rtd->codec_dai;
727 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 1104 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
728 struct snd_compr *compr; 1105 struct snd_compr *compr;
@@ -798,9 +1175,25 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
798 memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops)); 1175 memcpy(compr->ops, &soc_compr_ops, sizeof(soc_compr_ops));
799 } 1176 }
800 1177
1178
801 /* Add copy callback for not memory mapped DSPs */ 1179 /* Add copy callback for not memory mapped DSPs */
802 if (platform->driver->compr_ops && platform->driver->compr_ops->copy) 1180 if (platform && platform->driver->compr_ops && platform->driver->compr_ops->copy)
1181 compr->ops->copy = soc_compr_copy;
1182
1183 for_each_rtdcom(rtd, rtdcom) {
1184 component = rtdcom->component;
1185
1186 /* ignore duplication for now */
1187 if (platform && (component == &platform->component))
1188 continue;
1189
1190 if (!component->driver->compr_ops ||
1191 !component->driver->compr_ops->copy)
1192 continue;
1193
803 compr->ops->copy = soc_compr_copy; 1194 compr->ops->copy = soc_compr_copy;
1195 }
1196
804 1197
805 mutex_init(&compr->lock); 1198 mutex_init(&compr->lock);
806 ret = snd_compress_new(rtd->card->snd_card, num, direction, 1199 ret = snd_compress_new(rtd->card->snd_card, num, direction,
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index fee4b0ef5566..c0edac80df34 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -614,6 +614,8 @@ struct snd_pcm_substream *snd_soc_get_dai_substream(struct snd_soc_card *card,
614} 614}
615EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream); 615EXPORT_SYMBOL_GPL(snd_soc_get_dai_substream);
616 616
617static const struct snd_soc_ops null_snd_soc_ops;
618
617static struct snd_soc_pcm_runtime *soc_new_pcm_runtime( 619static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
618 struct snd_soc_card *card, struct snd_soc_dai_link *dai_link) 620 struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
619{ 621{
@@ -626,6 +628,9 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
626 INIT_LIST_HEAD(&rtd->component_list); 628 INIT_LIST_HEAD(&rtd->component_list);
627 rtd->card = card; 629 rtd->card = card;
628 rtd->dai_link = dai_link; 630 rtd->dai_link = dai_link;
631 if (!rtd->dai_link->ops)
632 rtd->dai_link->ops = &null_snd_soc_ops;
633
629 rtd->codec_dais = kzalloc(sizeof(struct snd_soc_dai *) * 634 rtd->codec_dais = kzalloc(sizeof(struct snd_soc_dai *) *
630 dai_link->num_codecs, 635 dai_link->num_codecs,
631 GFP_KERNEL); 636 GFP_KERNEL);
@@ -639,8 +644,7 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
639 644
640static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd) 645static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
641{ 646{
642 if (rtd && rtd->codec_dais) 647 kfree(rtd->codec_dais);
643 kfree(rtd->codec_dais);
644 snd_soc_rtdcom_del_all(rtd); 648 snd_soc_rtdcom_del_all(rtd);
645 kfree(rtd); 649 kfree(rtd);
646} 650}
@@ -2632,7 +2636,7 @@ EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
2632int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, 2636int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2633 unsigned int freq, int dir) 2637 unsigned int freq, int dir)
2634{ 2638{
2635 if (dai->driver && dai->driver->ops->set_sysclk) 2639 if (dai->driver->ops->set_sysclk)
2636 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir); 2640 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
2637 2641
2638 return snd_soc_component_set_sysclk(dai->component, clk_id, 0, 2642 return snd_soc_component_set_sysclk(dai->component, clk_id, 0,
@@ -2700,7 +2704,7 @@ EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk);
2700int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, 2704int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2701 int div_id, int div) 2705 int div_id, int div)
2702{ 2706{
2703 if (dai->driver && dai->driver->ops->set_clkdiv) 2707 if (dai->driver->ops->set_clkdiv)
2704 return dai->driver->ops->set_clkdiv(dai, div_id, div); 2708 return dai->driver->ops->set_clkdiv(dai, div_id, div);
2705 else 2709 else
2706 return -EINVAL; 2710 return -EINVAL;
@@ -2720,7 +2724,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2720int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, 2724int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2721 unsigned int freq_in, unsigned int freq_out) 2725 unsigned int freq_in, unsigned int freq_out)
2722{ 2726{
2723 if (dai->driver && dai->driver->ops->set_pll) 2727 if (dai->driver->ops->set_pll)
2724 return dai->driver->ops->set_pll(dai, pll_id, source, 2728 return dai->driver->ops->set_pll(dai, pll_id, source,
2725 freq_in, freq_out); 2729 freq_in, freq_out);
2726 2730
@@ -2786,7 +2790,7 @@ EXPORT_SYMBOL_GPL(snd_soc_component_set_pll);
2786 */ 2790 */
2787int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio) 2791int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
2788{ 2792{
2789 if (dai->driver && dai->driver->ops->set_bclk_ratio) 2793 if (dai->driver->ops->set_bclk_ratio)
2790 return dai->driver->ops->set_bclk_ratio(dai, ratio); 2794 return dai->driver->ops->set_bclk_ratio(dai, ratio);
2791 else 2795 else
2792 return -EINVAL; 2796 return -EINVAL;
@@ -2796,7 +2800,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
2796/** 2800/**
2797 * snd_soc_dai_set_fmt - configure DAI hardware audio format. 2801 * snd_soc_dai_set_fmt - configure DAI hardware audio format.
2798 * @dai: DAI 2802 * @dai: DAI
2799 * @fmt: SND_SOC_DAIFMT_ format value. 2803 * @fmt: SND_SOC_DAIFMT_* format value.
2800 * 2804 *
2801 * Configures the DAI hardware format and clocking. 2805 * Configures the DAI hardware format and clocking.
2802 */ 2806 */
@@ -2860,7 +2864,7 @@ static int snd_soc_xlate_tdm_slot_mask(unsigned int slots,
2860int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, 2864int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2861 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) 2865 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
2862{ 2866{
2863 if (dai->driver && dai->driver->ops->xlate_tdm_slot_mask) 2867 if (dai->driver->ops->xlate_tdm_slot_mask)
2864 dai->driver->ops->xlate_tdm_slot_mask(slots, 2868 dai->driver->ops->xlate_tdm_slot_mask(slots,
2865 &tx_mask, &rx_mask); 2869 &tx_mask, &rx_mask);
2866 else 2870 else
@@ -2869,7 +2873,7 @@ int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2869 dai->tx_mask = tx_mask; 2873 dai->tx_mask = tx_mask;
2870 dai->rx_mask = rx_mask; 2874 dai->rx_mask = rx_mask;
2871 2875
2872 if (dai->driver && dai->driver->ops->set_tdm_slot) 2876 if (dai->driver->ops->set_tdm_slot)
2873 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, 2877 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
2874 slots, slot_width); 2878 slots, slot_width);
2875 else 2879 else
@@ -2893,7 +2897,7 @@ int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2893 unsigned int tx_num, unsigned int *tx_slot, 2897 unsigned int tx_num, unsigned int *tx_slot,
2894 unsigned int rx_num, unsigned int *rx_slot) 2898 unsigned int rx_num, unsigned int *rx_slot)
2895{ 2899{
2896 if (dai->driver && dai->driver->ops->set_channel_map) 2900 if (dai->driver->ops->set_channel_map)
2897 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot, 2901 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
2898 rx_num, rx_slot); 2902 rx_num, rx_slot);
2899 else 2903 else
@@ -2910,7 +2914,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2910 */ 2914 */
2911int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) 2915int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2912{ 2916{
2913 if (dai->driver && dai->driver->ops->set_tristate) 2917 if (dai->driver->ops->set_tristate)
2914 return dai->driver->ops->set_tristate(dai, tristate); 2918 return dai->driver->ops->set_tristate(dai, tristate);
2915 else 2919 else
2916 return -EINVAL; 2920 return -EINVAL;
@@ -3250,6 +3254,30 @@ static int snd_soc_component_stream_event(struct snd_soc_dapm_context *dapm,
3250 return component->driver->stream_event(component, event); 3254 return component->driver->stream_event(component, event);
3251} 3255}
3252 3256
3257static int snd_soc_component_drv_pcm_new(struct snd_soc_component *component,
3258 struct snd_soc_pcm_runtime *rtd)
3259{
3260 if (component->driver->pcm_new)
3261 return component->driver->pcm_new(rtd);
3262
3263 return 0;
3264}
3265
3266static void snd_soc_component_drv_pcm_free(struct snd_soc_component *component,
3267 struct snd_pcm *pcm)
3268{
3269 if (component->driver->pcm_free)
3270 component->driver->pcm_free(pcm);
3271}
3272
3273static int snd_soc_component_set_bias_level(struct snd_soc_dapm_context *dapm,
3274 enum snd_soc_bias_level level)
3275{
3276 struct snd_soc_component *component = dapm->component;
3277
3278 return component->driver->set_bias_level(component, level);
3279}
3280
3253static int snd_soc_component_initialize(struct snd_soc_component *component, 3281static int snd_soc_component_initialize(struct snd_soc_component *component,
3254 const struct snd_soc_component_driver *driver, struct device *dev) 3282 const struct snd_soc_component_driver *driver, struct device *dev)
3255{ 3283{
@@ -3270,16 +3298,21 @@ static int snd_soc_component_initialize(struct snd_soc_component *component,
3270 component->set_sysclk = component->driver->set_sysclk; 3298 component->set_sysclk = component->driver->set_sysclk;
3271 component->set_pll = component->driver->set_pll; 3299 component->set_pll = component->driver->set_pll;
3272 component->set_jack = component->driver->set_jack; 3300 component->set_jack = component->driver->set_jack;
3301 component->pcm_new = snd_soc_component_drv_pcm_new;
3302 component->pcm_free = snd_soc_component_drv_pcm_free;
3273 3303
3274 dapm = snd_soc_component_get_dapm(component); 3304 dapm = snd_soc_component_get_dapm(component);
3275 dapm->dev = dev; 3305 dapm->dev = dev;
3276 dapm->component = component; 3306 dapm->component = component;
3277 dapm->bias_level = SND_SOC_BIAS_OFF; 3307 dapm->bias_level = SND_SOC_BIAS_OFF;
3278 dapm->idle_bias_off = true; 3308 dapm->idle_bias_off = !driver->idle_bias_on;
3309 dapm->suspend_bias_off = driver->suspend_bias_off;
3279 if (driver->seq_notifier) 3310 if (driver->seq_notifier)
3280 dapm->seq_notifier = snd_soc_component_seq_notifier; 3311 dapm->seq_notifier = snd_soc_component_seq_notifier;
3281 if (driver->stream_event) 3312 if (driver->stream_event)
3282 dapm->stream_event = snd_soc_component_stream_event; 3313 dapm->stream_event = snd_soc_component_stream_event;
3314 if (driver->set_bias_level)
3315 dapm->set_bias_level = snd_soc_component_set_bias_level;
3283 3316
3284 INIT_LIST_HEAD(&component->dai_list); 3317 INIT_LIST_HEAD(&component->dai_list);
3285 mutex_init(&component->io_mutex); 3318 mutex_init(&component->io_mutex);
@@ -3371,19 +3404,49 @@ static void snd_soc_component_del_unlocked(struct snd_soc_component *component)
3371 list_del(&component->list); 3404 list_del(&component->list);
3372} 3405}
3373 3406
3374int snd_soc_register_component(struct device *dev, 3407#define ENDIANNESS_MAP(name) \
3375 const struct snd_soc_component_driver *component_driver, 3408 (SNDRV_PCM_FMTBIT_##name##LE | SNDRV_PCM_FMTBIT_##name##BE)
3376 struct snd_soc_dai_driver *dai_drv, 3409static u64 endianness_format_map[] = {
3377 int num_dai) 3410 ENDIANNESS_MAP(S16_),
3411 ENDIANNESS_MAP(U16_),
3412 ENDIANNESS_MAP(S24_),
3413 ENDIANNESS_MAP(U24_),
3414 ENDIANNESS_MAP(S32_),
3415 ENDIANNESS_MAP(U32_),
3416 ENDIANNESS_MAP(S24_3),
3417 ENDIANNESS_MAP(U24_3),
3418 ENDIANNESS_MAP(S20_3),
3419 ENDIANNESS_MAP(U20_3),
3420 ENDIANNESS_MAP(S18_3),
3421 ENDIANNESS_MAP(U18_3),
3422 ENDIANNESS_MAP(FLOAT_),
3423 ENDIANNESS_MAP(FLOAT64_),
3424 ENDIANNESS_MAP(IEC958_SUBFRAME_),
3425};
3426
3427/*
3428 * Fix up the DAI formats for endianness: codecs don't actually see
3429 * the endianness of the data but we're using the CPU format
3430 * definitions which do need to include endianness so we ensure that
3431 * codec DAIs always have both big and little endian variants set.
3432 */
3433static void convert_endianness_formats(struct snd_soc_pcm_stream *stream)
3378{ 3434{
3379 struct snd_soc_component *component; 3435 int i;
3380 int ret;
3381 3436
3382 component = kzalloc(sizeof(*component), GFP_KERNEL); 3437 for (i = 0; i < ARRAY_SIZE(endianness_format_map); i++)
3383 if (!component) { 3438 if (stream->formats & endianness_format_map[i])
3384 dev_err(dev, "ASoC: Failed to allocate memory\n"); 3439 stream->formats |= endianness_format_map[i];
3385 return -ENOMEM; 3440}
3386 } 3441
3442int snd_soc_add_component(struct device *dev,
3443 struct snd_soc_component *component,
3444 const struct snd_soc_component_driver *component_driver,
3445 struct snd_soc_dai_driver *dai_drv,
3446 int num_dai)
3447{
3448 int ret;
3449 int i;
3387 3450
3388 ret = snd_soc_component_initialize(component, component_driver, dev); 3451 ret = snd_soc_component_initialize(component, component_driver, dev);
3389 if (ret) 3452 if (ret)
@@ -3392,7 +3455,15 @@ int snd_soc_register_component(struct device *dev,
3392 component->ignore_pmdown_time = true; 3455 component->ignore_pmdown_time = true;
3393 component->registered_as_component = true; 3456 component->registered_as_component = true;
3394 3457
3395 ret = snd_soc_register_dais(component, dai_drv, num_dai, true); 3458 if (component_driver->endianness) {
3459 for (i = 0; i < num_dai; i++) {
3460 convert_endianness_formats(&dai_drv[i].playback);
3461 convert_endianness_formats(&dai_drv[i].capture);
3462 }
3463 }
3464
3465 ret = snd_soc_register_dais(component, dai_drv, num_dai,
3466 !component_driver->non_legacy_dai_naming);
3396 if (ret < 0) { 3467 if (ret < 0) {
3397 dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret); 3468 dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret);
3398 goto err_cleanup; 3469 goto err_cleanup;
@@ -3408,6 +3479,22 @@ err_free:
3408 kfree(component); 3479 kfree(component);
3409 return ret; 3480 return ret;
3410} 3481}
3482EXPORT_SYMBOL_GPL(snd_soc_add_component);
3483
3484int snd_soc_register_component(struct device *dev,
3485 const struct snd_soc_component_driver *component_driver,
3486 struct snd_soc_dai_driver *dai_drv,
3487 int num_dai)
3488{
3489 struct snd_soc_component *component;
3490
3491 component = kzalloc(sizeof(*component), GFP_KERNEL);
3492 if (!component)
3493 return -ENOMEM;
3494
3495 return snd_soc_add_component(dev, component, component_driver,
3496 dai_drv, num_dai);
3497}
3411EXPORT_SYMBOL_GPL(snd_soc_register_component); 3498EXPORT_SYMBOL_GPL(snd_soc_register_component);
3412 3499
3413/** 3500/**
@@ -3448,6 +3535,32 @@ void snd_soc_unregister_component(struct device *dev)
3448} 3535}
3449EXPORT_SYMBOL_GPL(snd_soc_unregister_component); 3536EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
3450 3537
3538struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
3539 const char *driver_name)
3540{
3541 struct snd_soc_component *component;
3542 struct snd_soc_component *ret;
3543
3544 ret = NULL;
3545 mutex_lock(&client_mutex);
3546 list_for_each_entry(component, &component_list, list) {
3547 if (dev != component->dev)
3548 continue;
3549
3550 if (driver_name &&
3551 (driver_name != component->driver->name) &&
3552 (strcmp(component->driver->name, driver_name) != 0))
3553 continue;
3554
3555 ret = component;
3556 break;
3557 }
3558 mutex_unlock(&client_mutex);
3559
3560 return ret;
3561}
3562EXPORT_SYMBOL_GPL(snd_soc_lookup_component);
3563
3451static int snd_soc_platform_drv_probe(struct snd_soc_component *component) 3564static int snd_soc_platform_drv_probe(struct snd_soc_component *component)
3452{ 3565{
3453 struct snd_soc_platform *platform = snd_soc_component_to_platform(component); 3566 struct snd_soc_platform *platform = snd_soc_component_to_platform(component);
@@ -3462,6 +3575,26 @@ static void snd_soc_platform_drv_remove(struct snd_soc_component *component)
3462 platform->driver->remove(platform); 3575 platform->driver->remove(platform);
3463} 3576}
3464 3577
3578static int snd_soc_platform_drv_pcm_new(struct snd_soc_component *component,
3579 struct snd_soc_pcm_runtime *rtd)
3580{
3581 struct snd_soc_platform *platform = snd_soc_component_to_platform(component);
3582
3583 if (platform->driver->pcm_new)
3584 return platform->driver->pcm_new(rtd);
3585
3586 return 0;
3587}
3588
3589static void snd_soc_platform_drv_pcm_free(struct snd_soc_component *component,
3590 struct snd_pcm *pcm)
3591{
3592 struct snd_soc_platform *platform = snd_soc_component_to_platform(component);
3593
3594 if (platform->driver->pcm_free)
3595 platform->driver->pcm_free(pcm);
3596}
3597
3465/** 3598/**
3466 * snd_soc_add_platform - Add a platform to the ASoC core 3599 * snd_soc_add_platform - Add a platform to the ASoC core
3467 * @dev: The parent device for the platform 3600 * @dev: The parent device for the platform
@@ -3485,6 +3618,10 @@ int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
3485 platform->component.probe = snd_soc_platform_drv_probe; 3618 platform->component.probe = snd_soc_platform_drv_probe;
3486 if (platform_drv->remove) 3619 if (platform_drv->remove)
3487 platform->component.remove = snd_soc_platform_drv_remove; 3620 platform->component.remove = snd_soc_platform_drv_remove;
3621 if (platform_drv->pcm_new)
3622 platform->component.pcm_new = snd_soc_platform_drv_pcm_new;
3623 if (platform_drv->pcm_free)
3624 platform->component.pcm_free = snd_soc_platform_drv_pcm_free;
3488 3625
3489#ifdef CONFIG_DEBUG_FS 3626#ifdef CONFIG_DEBUG_FS
3490 platform->component.debugfs_prefix = "platform"; 3627 platform->component.debugfs_prefix = "platform";
@@ -3582,39 +3719,6 @@ void snd_soc_unregister_platform(struct device *dev)
3582} 3719}
3583EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); 3720EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
3584 3721
3585static u64 codec_format_map[] = {
3586 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
3587 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
3588 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
3589 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
3590 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
3591 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
3592 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3593 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
3594 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
3595 SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
3596 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
3597 SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
3598 SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
3599 SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
3600 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
3601 | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
3602};
3603
3604/* Fix up the DAI formats for endianness: codecs don't actually see
3605 * the endianness of the data but we're using the CPU format
3606 * definitions which do need to include endianness so we ensure that
3607 * codec DAIs always have both big and little endian variants set.
3608 */
3609static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
3610{
3611 int i;
3612
3613 for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
3614 if (stream->formats & codec_format_map[i])
3615 stream->formats |= codec_format_map[i];
3616}
3617
3618static int snd_soc_codec_drv_probe(struct snd_soc_component *component) 3722static int snd_soc_codec_drv_probe(struct snd_soc_component *component)
3619{ 3723{
3620 struct snd_soc_codec *codec = snd_soc_component_to_codec(component); 3724 struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
@@ -3765,8 +3869,8 @@ int snd_soc_register_codec(struct device *dev,
3765 codec->component.regmap = codec_drv->get_regmap(dev); 3869 codec->component.regmap = codec_drv->get_regmap(dev);
3766 3870
3767 for (i = 0; i < num_dai; i++) { 3871 for (i = 0; i < num_dai; i++) {
3768 fixup_codec_formats(&dai_drv[i].playback); 3872 convert_endianness_formats(&dai_drv[i].playback);
3769 fixup_codec_formats(&dai_drv[i].capture); 3873 convert_endianness_formats(&dai_drv[i].capture);
3770 } 3874 }
3771 3875
3772 ret = snd_soc_register_dais(&codec->component, dai_drv, num_dai, false); 3876 ret = snd_soc_register_dais(&codec->component, dai_drv, num_dai, false);
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index dcef67a9bd48..a10b21cfc31e 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -2884,7 +2884,7 @@ int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
2884{ 2884{
2885 int i, r, ret = 0; 2885 int i, r, ret = 0;
2886 2886
2887 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); 2887 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2888 for (i = 0; i < num; i++) { 2888 for (i = 0; i < num; i++) {
2889 r = snd_soc_dapm_add_route(dapm, route); 2889 r = snd_soc_dapm_add_route(dapm, route);
2890 if (r < 0) { 2890 if (r < 0) {
@@ -2915,7 +2915,7 @@ int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm,
2915{ 2915{
2916 int i; 2916 int i;
2917 2917
2918 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); 2918 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
2919 for (i = 0; i < num; i++) { 2919 for (i = 0; i < num; i++) {
2920 snd_soc_dapm_del_route(dapm, route); 2920 snd_soc_dapm_del_route(dapm, route);
2921 route++; 2921 route++;
@@ -3681,7 +3681,7 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
3681 switch (event) { 3681 switch (event) {
3682 case SND_SOC_DAPM_PRE_PMU: 3682 case SND_SOC_DAPM_PRE_PMU:
3683 substream.stream = SNDRV_PCM_STREAM_CAPTURE; 3683 substream.stream = SNDRV_PCM_STREAM_CAPTURE;
3684 if (source->driver->ops && source->driver->ops->startup) { 3684 if (source->driver->ops->startup) {
3685 ret = source->driver->ops->startup(&substream, source); 3685 ret = source->driver->ops->startup(&substream, source);
3686 if (ret < 0) { 3686 if (ret < 0) {
3687 dev_err(source->dev, 3687 dev_err(source->dev,
@@ -3695,7 +3695,7 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
3695 goto out; 3695 goto out;
3696 3696
3697 substream.stream = SNDRV_PCM_STREAM_PLAYBACK; 3697 substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
3698 if (sink->driver->ops && sink->driver->ops->startup) { 3698 if (sink->driver->ops->startup) {
3699 ret = sink->driver->ops->startup(&substream, sink); 3699 ret = sink->driver->ops->startup(&substream, sink);
3700 if (ret < 0) { 3700 if (ret < 0) {
3701 dev_err(sink->dev, 3701 dev_err(sink->dev,
@@ -3725,13 +3725,13 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
3725 ret = 0; 3725 ret = 0;
3726 3726
3727 source->active--; 3727 source->active--;
3728 if (source->driver->ops && source->driver->ops->shutdown) { 3728 if (source->driver->ops->shutdown) {
3729 substream.stream = SNDRV_PCM_STREAM_CAPTURE; 3729 substream.stream = SNDRV_PCM_STREAM_CAPTURE;
3730 source->driver->ops->shutdown(&substream, source); 3730 source->driver->ops->shutdown(&substream, source);
3731 } 3731 }
3732 3732
3733 sink->active--; 3733 sink->active--;
3734 if (sink->driver->ops && sink->driver->ops->shutdown) { 3734 if (sink->driver->ops->shutdown) {
3735 substream.stream = SNDRV_PCM_STREAM_PLAYBACK; 3735 substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
3736 sink->driver->ops->shutdown(&substream, sink); 3736 sink->driver->ops->shutdown(&substream, sink);
3737 } 3737 }
@@ -3778,18 +3778,27 @@ static int snd_soc_dapm_dai_link_put(struct snd_kcontrol *kcontrol,
3778 return 0; 3778 return 0;
3779} 3779}
3780 3780
3781int snd_soc_dapm_new_pcm(struct snd_soc_card *card, 3781static void
3782 const struct snd_soc_pcm_stream *params, 3782snd_soc_dapm_free_kcontrol(struct snd_soc_card *card,
3783 unsigned int num_params, 3783 unsigned long *private_value,
3784 struct snd_soc_dapm_widget *source, 3784 int num_params,
3785 struct snd_soc_dapm_widget *sink) 3785 const char **w_param_text)
3786{
3787 int count;
3788
3789 devm_kfree(card->dev, (void *)*private_value);
3790 for (count = 0 ; count < num_params; count++)
3791 devm_kfree(card->dev, (void *)w_param_text[count]);
3792 devm_kfree(card->dev, w_param_text);
3793}
3794
3795static struct snd_kcontrol_new *
3796snd_soc_dapm_alloc_kcontrol(struct snd_soc_card *card,
3797 char *link_name,
3798 const struct snd_soc_pcm_stream *params,
3799 int num_params, const char **w_param_text,
3800 unsigned long *private_value)
3786{ 3801{
3787 struct snd_soc_dapm_widget template;
3788 struct snd_soc_dapm_widget *w;
3789 char *link_name;
3790 int ret, count;
3791 unsigned long private_value;
3792 const char **w_param_text;
3793 struct soc_enum w_param_enum[] = { 3802 struct soc_enum w_param_enum[] = {
3794 SOC_ENUM_SINGLE(0, 0, 0, NULL), 3803 SOC_ENUM_SINGLE(0, 0, 0, NULL),
3795 }; 3804 };
@@ -3798,19 +3807,9 @@ int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
3798 snd_soc_dapm_dai_link_get, 3807 snd_soc_dapm_dai_link_get,
3799 snd_soc_dapm_dai_link_put), 3808 snd_soc_dapm_dai_link_put),
3800 }; 3809 };
3810 struct snd_kcontrol_new *kcontrol_news;
3801 const struct snd_soc_pcm_stream *config = params; 3811 const struct snd_soc_pcm_stream *config = params;
3802 3812 int count;
3803 w_param_text = devm_kcalloc(card->dev, num_params,
3804 sizeof(char *), GFP_KERNEL);
3805 if (!w_param_text)
3806 return -ENOMEM;
3807
3808 link_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s-%s",
3809 source->name, sink->name);
3810 if (!link_name) {
3811 ret = -ENOMEM;
3812 goto outfree_w_param;
3813 }
3814 3813
3815 for (count = 0 ; count < num_params; count++) { 3814 for (count = 0 ; count < num_params; count++) {
3816 if (!config->stream_name) { 3815 if (!config->stream_name) {
@@ -3821,57 +3820,94 @@ int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
3821 devm_kasprintf(card->dev, GFP_KERNEL, 3820 devm_kasprintf(card->dev, GFP_KERNEL,
3822 "Anonymous Configuration %d", 3821 "Anonymous Configuration %d",
3823 count); 3822 count);
3824 if (!w_param_text[count]) {
3825 ret = -ENOMEM;
3826 goto outfree_link_name;
3827 }
3828 } else { 3823 } else {
3829 w_param_text[count] = devm_kmemdup(card->dev, 3824 w_param_text[count] = devm_kmemdup(card->dev,
3830 config->stream_name, 3825 config->stream_name,
3831 strlen(config->stream_name) + 1, 3826 strlen(config->stream_name) + 1,
3832 GFP_KERNEL); 3827 GFP_KERNEL);
3833 if (!w_param_text[count]) {
3834 ret = -ENOMEM;
3835 goto outfree_link_name;
3836 }
3837 } 3828 }
3829 if (!w_param_text[count])
3830 goto outfree_w_param;
3838 config++; 3831 config++;
3839 } 3832 }
3833
3840 w_param_enum[0].items = num_params; 3834 w_param_enum[0].items = num_params;
3841 w_param_enum[0].texts = w_param_text; 3835 w_param_enum[0].texts = w_param_text;
3842 3836
3843 memset(&template, 0, sizeof(template)); 3837 *private_value =
3844 template.reg = SND_SOC_NOPM;
3845 template.id = snd_soc_dapm_dai_link;
3846 template.name = link_name;
3847 template.event = snd_soc_dai_link_event;
3848 template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3849 SND_SOC_DAPM_PRE_PMD;
3850 template.num_kcontrols = 1;
3851 /* duplicate w_param_enum on heap so that memory persists */
3852 private_value =
3853 (unsigned long) devm_kmemdup(card->dev, 3838 (unsigned long) devm_kmemdup(card->dev,
3854 (void *)(kcontrol_dai_link[0].private_value), 3839 (void *)(kcontrol_dai_link[0].private_value),
3855 sizeof(struct soc_enum), GFP_KERNEL); 3840 sizeof(struct soc_enum), GFP_KERNEL);
3856 if (!private_value) { 3841 if (!*private_value) {
3857 dev_err(card->dev, "ASoC: Failed to create control for %s widget\n", 3842 dev_err(card->dev, "ASoC: Failed to create control for %s widget\n",
3858 link_name); 3843 link_name);
3859 ret = -ENOMEM; 3844 goto outfree_w_param;
3860 goto outfree_link_name;
3861 } 3845 }
3862 kcontrol_dai_link[0].private_value = private_value; 3846 kcontrol_dai_link[0].private_value = *private_value;
3863 /* duplicate kcontrol_dai_link on heap so that memory persists */ 3847 /* duplicate kcontrol_dai_link on heap so that memory persists */
3864 template.kcontrol_news = 3848 kcontrol_news = devm_kmemdup(card->dev, &kcontrol_dai_link[0],
3865 devm_kmemdup(card->dev, &kcontrol_dai_link[0],
3866 sizeof(struct snd_kcontrol_new), 3849 sizeof(struct snd_kcontrol_new),
3867 GFP_KERNEL); 3850 GFP_KERNEL);
3868 if (!template.kcontrol_news) { 3851 if (!kcontrol_news) {
3869 dev_err(card->dev, "ASoC: Failed to create control for %s widget\n", 3852 dev_err(card->dev, "ASoC: Failed to create control for %s widget\n",
3870 link_name); 3853 link_name);
3871 ret = -ENOMEM; 3854 goto outfree_w_param;
3872 goto outfree_private_value;
3873 } 3855 }
3856 return kcontrol_news;
3857
3858outfree_w_param:
3859 snd_soc_dapm_free_kcontrol(card, private_value, num_params, w_param_text);
3860 return NULL;
3861}
3862
3863int snd_soc_dapm_new_pcm(struct snd_soc_card *card,
3864 const struct snd_soc_pcm_stream *params,
3865 unsigned int num_params,
3866 struct snd_soc_dapm_widget *source,
3867 struct snd_soc_dapm_widget *sink)
3868{
3869 struct snd_soc_dapm_widget template;
3870 struct snd_soc_dapm_widget *w;
3871 const char **w_param_text;
3872 unsigned long private_value;
3873 char *link_name;
3874 int ret;
3875
3876 link_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s-%s",
3877 source->name, sink->name);
3878 if (!link_name)
3879 return -ENOMEM;
3880
3881 memset(&template, 0, sizeof(template));
3882 template.reg = SND_SOC_NOPM;
3883 template.id = snd_soc_dapm_dai_link;
3884 template.name = link_name;
3885 template.event = snd_soc_dai_link_event;
3886 template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
3887 SND_SOC_DAPM_PRE_PMD;
3888 template.kcontrol_news = NULL;
3889
3890 /* allocate memory for control, only in case of multiple configs */
3891 if (num_params > 1) {
3892 w_param_text = devm_kcalloc(card->dev, num_params,
3893 sizeof(char *), GFP_KERNEL);
3894 if (!w_param_text) {
3895 ret = -ENOMEM;
3896 goto param_fail;
3897 }
3874 3898
3899 template.num_kcontrols = 1;
3900 template.kcontrol_news =
3901 snd_soc_dapm_alloc_kcontrol(card,
3902 link_name, params, num_params,
3903 w_param_text, &private_value);
3904 if (!template.kcontrol_news) {
3905 ret = -ENOMEM;
3906 goto param_fail;
3907 }
3908 } else {
3909 w_param_text = NULL;
3910 }
3875 dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name); 3911 dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name);
3876 3912
3877 w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template); 3913 w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template);
@@ -3903,15 +3939,9 @@ outfree_w:
3903 devm_kfree(card->dev, w); 3939 devm_kfree(card->dev, w);
3904outfree_kcontrol_news: 3940outfree_kcontrol_news:
3905 devm_kfree(card->dev, (void *)template.kcontrol_news); 3941 devm_kfree(card->dev, (void *)template.kcontrol_news);
3906outfree_private_value: 3942 snd_soc_dapm_free_kcontrol(card, &private_value, num_params, w_param_text);
3907 devm_kfree(card->dev, (void *)private_value); 3943param_fail:
3908outfree_link_name:
3909 devm_kfree(card->dev, link_name); 3944 devm_kfree(card->dev, link_name);
3910outfree_w_param:
3911 for (count = 0 ; count < num_params; count++)
3912 devm_kfree(card->dev, (void *)w_param_text[count]);
3913 devm_kfree(card->dev, w_param_text);
3914
3915 return ret; 3945 return ret;
3916} 3946}
3917 3947
diff --git a/sound/soc/soc-io.c b/sound/soc/soc-io.c
index 9b3939049cef..20340ade20a7 100644
--- a/sound/soc/soc-io.c
+++ b/sound/soc/soc-io.c
@@ -41,6 +41,20 @@ int snd_soc_component_read(struct snd_soc_component *component,
41} 41}
42EXPORT_SYMBOL_GPL(snd_soc_component_read); 42EXPORT_SYMBOL_GPL(snd_soc_component_read);
43 43
44unsigned int snd_soc_component_read32(struct snd_soc_component *component,
45 unsigned int reg)
46{
47 unsigned int val;
48 int ret;
49
50 ret = snd_soc_component_read(component, reg, &val);
51 if (ret < 0)
52 return -1;
53
54 return val;
55}
56EXPORT_SYMBOL_GPL(snd_soc_component_read32);
57
44/** 58/**
45 * snd_soc_component_write() - Write register value 59 * snd_soc_component_write() - Write register value
46 * @component: Component to write to 60 * @component: Component to write to
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 94b88b897c3b..8075856668c2 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -133,16 +133,25 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream)
133 */ 133 */
134bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd) 134bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd)
135{ 135{
136 struct snd_soc_rtdcom_list *rtdcom;
137 struct snd_soc_component *component;
136 int i; 138 int i;
137 bool ignore = true; 139 bool ignore = true;
138 140
139 if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time) 141 if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time)
140 return true; 142 return true;
141 143
144 for_each_rtdcom(rtd, rtdcom) {
145 component = rtdcom->component;
146
147 ignore &= !component->driver->pmdown_time;
148 }
149
150 /* this will be removed */
142 for (i = 0; i < rtd->num_codecs; i++) 151 for (i = 0; i < rtd->num_codecs; i++)
143 ignore &= rtd->codec_dais[i]->component->ignore_pmdown_time; 152 ignore &= rtd->codec_dais[i]->component->ignore_pmdown_time;
144 153
145 return rtd->cpu_dai->component->ignore_pmdown_time && ignore; 154 return ignore;
146} 155}
147 156
148/** 157/**
@@ -459,7 +468,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
459 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 468 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
460 struct snd_soc_dai *codec_dai; 469 struct snd_soc_dai *codec_dai;
461 const char *codec_dai_name = "multicodec"; 470 const char *codec_dai_name = "multicodec";
462 int i, ret = 0; 471 int i, ret = 0, __ret;
463 472
464 pinctrl_pm_select_default_state(cpu_dai->dev); 473 pinctrl_pm_select_default_state(cpu_dai->dev);
465 for (i = 0; i < rtd->num_codecs; i++) 474 for (i = 0; i < rtd->num_codecs; i++)
@@ -474,7 +483,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
474 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 483 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
475 484
476 /* startup the audio subsystem */ 485 /* startup the audio subsystem */
477 if (cpu_dai->driver->ops && cpu_dai->driver->ops->startup) { 486 if (cpu_dai->driver->ops->startup) {
478 ret = cpu_dai->driver->ops->startup(substream, cpu_dai); 487 ret = cpu_dai->driver->ops->startup(substream, cpu_dai);
479 if (ret < 0) { 488 if (ret < 0) {
480 dev_err(cpu_dai->dev, "ASoC: can't open interface" 489 dev_err(cpu_dai->dev, "ASoC: can't open interface"
@@ -483,7 +492,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
483 } 492 }
484 } 493 }
485 494
486 if (platform->driver->ops && platform->driver->ops->open) { 495 if (platform && platform->driver->ops && platform->driver->ops->open) {
487 ret = platform->driver->ops->open(substream); 496 ret = platform->driver->ops->open(substream);
488 if (ret < 0) { 497 if (ret < 0) {
489 dev_err(platform->dev, "ASoC: can't open platform" 498 dev_err(platform->dev, "ASoC: can't open platform"
@@ -492,9 +501,32 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
492 } 501 }
493 } 502 }
494 503
504 ret = 0;
505 for_each_rtdcom(rtd, rtdcom) {
506 component = rtdcom->component;
507
508 /* ignore duplication for now */
509 if (platform && (component == &platform->component))
510 continue;
511
512 if (!component->driver->ops ||
513 !component->driver->ops->open)
514 continue;
515
516 __ret = component->driver->ops->open(substream);
517 if (__ret < 0) {
518 dev_err(component->dev,
519 "ASoC: can't open component %s: %d\n",
520 component->name, ret);
521 ret = __ret;
522 }
523 }
524 if (ret < 0)
525 goto component_err;
526
495 for (i = 0; i < rtd->num_codecs; i++) { 527 for (i = 0; i < rtd->num_codecs; i++) {
496 codec_dai = rtd->codec_dais[i]; 528 codec_dai = rtd->codec_dais[i];
497 if (codec_dai->driver->ops && codec_dai->driver->ops->startup) { 529 if (codec_dai->driver->ops->startup) {
498 ret = codec_dai->driver->ops->startup(substream, 530 ret = codec_dai->driver->ops->startup(substream,
499 codec_dai); 531 codec_dai);
500 if (ret < 0) { 532 if (ret < 0) {
@@ -511,7 +543,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
511 codec_dai->rx_mask = 0; 543 codec_dai->rx_mask = 0;
512 } 544 }
513 545
514 if (rtd->dai_link->ops && rtd->dai_link->ops->startup) { 546 if (rtd->dai_link->ops->startup) {
515 ret = rtd->dai_link->ops->startup(substream); 547 ret = rtd->dai_link->ops->startup(substream);
516 if (ret < 0) { 548 if (ret < 0) {
517 pr_err("ASoC: %s startup failed: %d\n", 549 pr_err("ASoC: %s startup failed: %d\n",
@@ -585,7 +617,7 @@ dynamic:
585 return 0; 617 return 0;
586 618
587config_err: 619config_err:
588 if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown) 620 if (rtd->dai_link->ops->shutdown)
589 rtd->dai_link->ops->shutdown(substream); 621 rtd->dai_link->ops->shutdown(substream);
590 622
591machine_err: 623machine_err:
@@ -598,7 +630,22 @@ codec_dai_err:
598 codec_dai->driver->ops->shutdown(substream, codec_dai); 630 codec_dai->driver->ops->shutdown(substream, codec_dai);
599 } 631 }
600 632
601 if (platform->driver->ops && platform->driver->ops->close) 633component_err:
634 for_each_rtdcom(rtd, rtdcom) {
635 component = rtdcom->component;
636
637 /* ignore duplication for now */
638 if (platform && (component == &platform->component))
639 continue;
640
641 if (!component->driver->ops ||
642 !component->driver->ops->close)
643 continue;
644
645 component->driver->ops->close(substream);
646 }
647
648 if (platform && platform->driver->ops && platform->driver->ops->close)
602 platform->driver->ops->close(substream); 649 platform->driver->ops->close(substream);
603 650
604platform_err: 651platform_err:
@@ -692,12 +739,26 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
692 codec_dai->driver->ops->shutdown(substream, codec_dai); 739 codec_dai->driver->ops->shutdown(substream, codec_dai);
693 } 740 }
694 741
695 if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown) 742 if (rtd->dai_link->ops->shutdown)
696 rtd->dai_link->ops->shutdown(substream); 743 rtd->dai_link->ops->shutdown(substream);
697 744
698 if (platform->driver->ops && platform->driver->ops->close) 745 if (platform && platform->driver->ops && platform->driver->ops->close)
699 platform->driver->ops->close(substream); 746 platform->driver->ops->close(substream);
700 747
748 for_each_rtdcom(rtd, rtdcom) {
749 component = rtdcom->component;
750
751 /* ignore duplication for now */
752 if (platform && (component == &platform->component))
753 continue;
754
755 if (!component->driver->ops ||
756 !component->driver->ops->close)
757 continue;
758
759 component->driver->ops->close(substream);
760 }
761
701 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 762 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
702 if (snd_soc_runtime_ignore_pmdown_time(rtd)) { 763 if (snd_soc_runtime_ignore_pmdown_time(rtd)) {
703 /* powered down playback stream now */ 764 /* powered down playback stream now */
@@ -745,13 +806,15 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
745{ 806{
746 struct snd_soc_pcm_runtime *rtd = substream->private_data; 807 struct snd_soc_pcm_runtime *rtd = substream->private_data;
747 struct snd_soc_platform *platform = rtd->platform; 808 struct snd_soc_platform *platform = rtd->platform;
809 struct snd_soc_component *component;
810 struct snd_soc_rtdcom_list *rtdcom;
748 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 811 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
749 struct snd_soc_dai *codec_dai; 812 struct snd_soc_dai *codec_dai;
750 int i, ret = 0; 813 int i, ret = 0;
751 814
752 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 815 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
753 816
754 if (rtd->dai_link->ops && rtd->dai_link->ops->prepare) { 817 if (rtd->dai_link->ops->prepare) {
755 ret = rtd->dai_link->ops->prepare(substream); 818 ret = rtd->dai_link->ops->prepare(substream);
756 if (ret < 0) { 819 if (ret < 0) {
757 dev_err(rtd->card->dev, "ASoC: machine prepare error:" 820 dev_err(rtd->card->dev, "ASoC: machine prepare error:"
@@ -760,7 +823,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
760 } 823 }
761 } 824 }
762 825
763 if (platform->driver->ops && platform->driver->ops->prepare) { 826 if (platform && platform->driver->ops && platform->driver->ops->prepare) {
764 ret = platform->driver->ops->prepare(substream); 827 ret = platform->driver->ops->prepare(substream);
765 if (ret < 0) { 828 if (ret < 0) {
766 dev_err(platform->dev, "ASoC: platform prepare error:" 829 dev_err(platform->dev, "ASoC: platform prepare error:"
@@ -769,9 +832,28 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
769 } 832 }
770 } 833 }
771 834
835 for_each_rtdcom(rtd, rtdcom) {
836 component = rtdcom->component;
837
838 /* ignore duplication for now */
839 if (platform && (component == &platform->component))
840 continue;
841
842 if (!component->driver->ops ||
843 !component->driver->ops->prepare)
844 continue;
845
846 ret = component->driver->ops->prepare(substream);
847 if (ret < 0) {
848 dev_err(component->dev,
849 "ASoC: platform prepare error: %d\n", ret);
850 goto out;
851 }
852 }
853
772 for (i = 0; i < rtd->num_codecs; i++) { 854 for (i = 0; i < rtd->num_codecs; i++) {
773 codec_dai = rtd->codec_dais[i]; 855 codec_dai = rtd->codec_dais[i];
774 if (codec_dai->driver->ops && codec_dai->driver->ops->prepare) { 856 if (codec_dai->driver->ops->prepare) {
775 ret = codec_dai->driver->ops->prepare(substream, 857 ret = codec_dai->driver->ops->prepare(substream,
776 codec_dai); 858 codec_dai);
777 if (ret < 0) { 859 if (ret < 0) {
@@ -783,7 +865,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
783 } 865 }
784 } 866 }
785 867
786 if (cpu_dai->driver->ops && cpu_dai->driver->ops->prepare) { 868 if (cpu_dai->driver->ops->prepare) {
787 ret = cpu_dai->driver->ops->prepare(substream, cpu_dai); 869 ret = cpu_dai->driver->ops->prepare(substream, cpu_dai);
788 if (ret < 0) { 870 if (ret < 0) {
789 dev_err(cpu_dai->dev, 871 dev_err(cpu_dai->dev,
@@ -829,7 +911,7 @@ int soc_dai_hw_params(struct snd_pcm_substream *substream,
829{ 911{
830 int ret; 912 int ret;
831 913
832 if (dai->driver->ops && dai->driver->ops->hw_params) { 914 if (dai->driver->ops->hw_params) {
833 ret = dai->driver->ops->hw_params(substream, params, dai); 915 ret = dai->driver->ops->hw_params(substream, params, dai);
834 if (ret < 0) { 916 if (ret < 0) {
835 dev_err(dai->dev, "ASoC: can't set %s hw params: %d\n", 917 dev_err(dai->dev, "ASoC: can't set %s hw params: %d\n",
@@ -851,16 +933,13 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
851{ 933{
852 struct snd_soc_pcm_runtime *rtd = substream->private_data; 934 struct snd_soc_pcm_runtime *rtd = substream->private_data;
853 struct snd_soc_platform *platform = rtd->platform; 935 struct snd_soc_platform *platform = rtd->platform;
936 struct snd_soc_component *component;
937 struct snd_soc_rtdcom_list *rtdcom;
854 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 938 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
855 int i, ret = 0; 939 int i, ret = 0, __ret;
856 940
857 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass); 941 mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
858 942 if (rtd->dai_link->ops->hw_params) {
859 ret = soc_pcm_params_symmetry(substream, params);
860 if (ret)
861 goto out;
862
863 if (rtd->dai_link->ops && rtd->dai_link->ops->hw_params) {
864 ret = rtd->dai_link->ops->hw_params(substream, params); 943 ret = rtd->dai_link->ops->hw_params(substream, params);
865 if (ret < 0) { 944 if (ret < 0) {
866 dev_err(rtd->card->dev, "ASoC: machine hw_params" 945 dev_err(rtd->card->dev, "ASoC: machine hw_params"
@@ -915,7 +994,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
915 if (ret < 0) 994 if (ret < 0)
916 goto interface_err; 995 goto interface_err;
917 996
918 if (platform->driver->ops && platform->driver->ops->hw_params) { 997 if (platform && platform->driver->ops && platform->driver->ops->hw_params) {
919 ret = platform->driver->ops->hw_params(substream, params); 998 ret = platform->driver->ops->hw_params(substream, params);
920 if (ret < 0) { 999 if (ret < 0) {
921 dev_err(platform->dev, "ASoC: %s hw params failed: %d\n", 1000 dev_err(platform->dev, "ASoC: %s hw params failed: %d\n",
@@ -924,18 +1003,62 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
924 } 1003 }
925 } 1004 }
926 1005
1006 ret = 0;
1007 for_each_rtdcom(rtd, rtdcom) {
1008 component = rtdcom->component;
1009
1010 /* ignore duplication for now */
1011 if (platform && (component == &platform->component))
1012 continue;
1013
1014 if (!component->driver->ops ||
1015 !component->driver->ops->hw_params)
1016 continue;
1017
1018 __ret = component->driver->ops->hw_params(substream, params);
1019 if (__ret < 0) {
1020 dev_err(component->dev,
1021 "ASoC: %s hw params failed: %d\n",
1022 component->name, ret);
1023 ret = __ret;
1024 }
1025 }
1026 if (ret < 0)
1027 goto component_err;
1028
927 /* store the parameters for each DAIs */ 1029 /* store the parameters for each DAIs */
928 cpu_dai->rate = params_rate(params); 1030 cpu_dai->rate = params_rate(params);
929 cpu_dai->channels = params_channels(params); 1031 cpu_dai->channels = params_channels(params);
930 cpu_dai->sample_bits = 1032 cpu_dai->sample_bits =
931 snd_pcm_format_physical_width(params_format(params)); 1033 snd_pcm_format_physical_width(params_format(params));
932 1034
1035 ret = soc_pcm_params_symmetry(substream, params);
1036 if (ret)
1037 goto component_err;
933out: 1038out:
934 mutex_unlock(&rtd->pcm_mutex); 1039 mutex_unlock(&rtd->pcm_mutex);
935 return ret; 1040 return ret;
936 1041
1042component_err:
1043 for_each_rtdcom(rtd, rtdcom) {
1044 component = rtdcom->component;
1045
1046 /* ignore duplication */
1047 if (platform && (component == &platform->component))
1048 continue;
1049
1050 if (!component->driver->ops ||
1051 !component->driver->ops->hw_free)
1052 continue;
1053
1054 component->driver->ops->hw_free(substream);
1055 }
1056
1057 if (platform && platform->driver->ops && platform->driver->ops->hw_free)
1058 platform->driver->ops->hw_free(substream);
1059
937platform_err: 1060platform_err:
938 if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_free) 1061 if (cpu_dai->driver->ops->hw_free)
939 cpu_dai->driver->ops->hw_free(substream, cpu_dai); 1062 cpu_dai->driver->ops->hw_free(substream, cpu_dai);
940 1063
941interface_err: 1064interface_err:
@@ -944,12 +1067,12 @@ interface_err:
944codec_err: 1067codec_err:
945 while (--i >= 0) { 1068 while (--i >= 0) {
946 struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; 1069 struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
947 if (codec_dai->driver->ops && codec_dai->driver->ops->hw_free) 1070 if (codec_dai->driver->ops->hw_free)
948 codec_dai->driver->ops->hw_free(substream, codec_dai); 1071 codec_dai->driver->ops->hw_free(substream, codec_dai);
949 codec_dai->rate = 0; 1072 codec_dai->rate = 0;
950 } 1073 }
951 1074
952 if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free) 1075 if (rtd->dai_link->ops->hw_free)
953 rtd->dai_link->ops->hw_free(substream); 1076 rtd->dai_link->ops->hw_free(substream);
954 1077
955 mutex_unlock(&rtd->pcm_mutex); 1078 mutex_unlock(&rtd->pcm_mutex);
@@ -963,6 +1086,8 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
963{ 1086{
964 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1087 struct snd_soc_pcm_runtime *rtd = substream->private_data;
965 struct snd_soc_platform *platform = rtd->platform; 1088 struct snd_soc_platform *platform = rtd->platform;
1089 struct snd_soc_component *component;
1090 struct snd_soc_rtdcom_list *rtdcom;
966 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 1091 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
967 struct snd_soc_dai *codec_dai; 1092 struct snd_soc_dai *codec_dai;
968 bool playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; 1093 bool playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
@@ -995,21 +1120,36 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
995 } 1120 }
996 1121
997 /* free any machine hw params */ 1122 /* free any machine hw params */
998 if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free) 1123 if (rtd->dai_link->ops->hw_free)
999 rtd->dai_link->ops->hw_free(substream); 1124 rtd->dai_link->ops->hw_free(substream);
1000 1125
1001 /* free any DMA resources */ 1126 /* free any DMA resources */
1002 if (platform->driver->ops && platform->driver->ops->hw_free) 1127 if (platform && platform->driver->ops && platform->driver->ops->hw_free)
1003 platform->driver->ops->hw_free(substream); 1128 platform->driver->ops->hw_free(substream);
1004 1129
1130 /* free any component resources */
1131 for_each_rtdcom(rtd, rtdcom) {
1132 component = rtdcom->component;
1133
1134 /* ignore duplication for now */
1135 if (platform && (component == &platform->component))
1136 continue;
1137
1138 if (!component->driver->ops ||
1139 !component->driver->ops->hw_free)
1140 continue;
1141
1142 component->driver->ops->hw_free(substream);
1143 }
1144
1005 /* now free hw params for the DAIs */ 1145 /* now free hw params for the DAIs */
1006 for (i = 0; i < rtd->num_codecs; i++) { 1146 for (i = 0; i < rtd->num_codecs; i++) {
1007 codec_dai = rtd->codec_dais[i]; 1147 codec_dai = rtd->codec_dais[i];
1008 if (codec_dai->driver->ops && codec_dai->driver->ops->hw_free) 1148 if (codec_dai->driver->ops->hw_free)
1009 codec_dai->driver->ops->hw_free(substream, codec_dai); 1149 codec_dai->driver->ops->hw_free(substream, codec_dai);
1010 } 1150 }
1011 1151
1012 if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_free) 1152 if (cpu_dai->driver->ops->hw_free)
1013 cpu_dai->driver->ops->hw_free(substream, cpu_dai); 1153 cpu_dai->driver->ops->hw_free(substream, cpu_dai);
1014 1154
1015 mutex_unlock(&rtd->pcm_mutex); 1155 mutex_unlock(&rtd->pcm_mutex);
@@ -1020,13 +1160,15 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1020{ 1160{
1021 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1161 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1022 struct snd_soc_platform *platform = rtd->platform; 1162 struct snd_soc_platform *platform = rtd->platform;
1163 struct snd_soc_component *component;
1164 struct snd_soc_rtdcom_list *rtdcom;
1023 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 1165 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1024 struct snd_soc_dai *codec_dai; 1166 struct snd_soc_dai *codec_dai;
1025 int i, ret; 1167 int i, ret;
1026 1168
1027 for (i = 0; i < rtd->num_codecs; i++) { 1169 for (i = 0; i < rtd->num_codecs; i++) {
1028 codec_dai = rtd->codec_dais[i]; 1170 codec_dai = rtd->codec_dais[i];
1029 if (codec_dai->driver->ops && codec_dai->driver->ops->trigger) { 1171 if (codec_dai->driver->ops->trigger) {
1030 ret = codec_dai->driver->ops->trigger(substream, 1172 ret = codec_dai->driver->ops->trigger(substream,
1031 cmd, codec_dai); 1173 cmd, codec_dai);
1032 if (ret < 0) 1174 if (ret < 0)
@@ -1034,19 +1176,35 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1034 } 1176 }
1035 } 1177 }
1036 1178
1037 if (platform->driver->ops && platform->driver->ops->trigger) { 1179 if (platform && platform->driver->ops && platform->driver->ops->trigger) {
1038 ret = platform->driver->ops->trigger(substream, cmd); 1180 ret = platform->driver->ops->trigger(substream, cmd);
1039 if (ret < 0) 1181 if (ret < 0)
1040 return ret; 1182 return ret;
1041 } 1183 }
1042 1184
1043 if (cpu_dai->driver->ops && cpu_dai->driver->ops->trigger) { 1185 for_each_rtdcom(rtd, rtdcom) {
1186 component = rtdcom->component;
1187
1188 /* ignore duplication for now */
1189 if (platform && (component == &platform->component))
1190 continue;
1191
1192 if (!component->driver->ops ||
1193 !component->driver->ops->trigger)
1194 continue;
1195
1196 ret = component->driver->ops->trigger(substream, cmd);
1197 if (ret < 0)
1198 return ret;
1199 }
1200
1201 if (cpu_dai->driver->ops->trigger) {
1044 ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai); 1202 ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai);
1045 if (ret < 0) 1203 if (ret < 0)
1046 return ret; 1204 return ret;
1047 } 1205 }
1048 1206
1049 if (rtd->dai_link->ops && rtd->dai_link->ops->trigger) { 1207 if (rtd->dai_link->ops->trigger) {
1050 ret = rtd->dai_link->ops->trigger(substream, cmd); 1208 ret = rtd->dai_link->ops->trigger(substream, cmd);
1051 if (ret < 0) 1209 if (ret < 0)
1052 return ret; 1210 return ret;
@@ -1065,8 +1223,7 @@ static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream,
1065 1223
1066 for (i = 0; i < rtd->num_codecs; i++) { 1224 for (i = 0; i < rtd->num_codecs; i++) {
1067 codec_dai = rtd->codec_dais[i]; 1225 codec_dai = rtd->codec_dais[i];
1068 if (codec_dai->driver->ops && 1226 if (codec_dai->driver->ops->bespoke_trigger) {
1069 codec_dai->driver->ops->bespoke_trigger) {
1070 ret = codec_dai->driver->ops->bespoke_trigger(substream, 1227 ret = codec_dai->driver->ops->bespoke_trigger(substream,
1071 cmd, codec_dai); 1228 cmd, codec_dai);
1072 if (ret < 0) 1229 if (ret < 0)
@@ -1074,7 +1231,7 @@ static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream,
1074 } 1231 }
1075 } 1232 }
1076 1233
1077 if (cpu_dai->driver->ops && cpu_dai->driver->ops->bespoke_trigger) { 1234 if (cpu_dai->driver->ops->bespoke_trigger) {
1078 ret = cpu_dai->driver->ops->bespoke_trigger(substream, cmd, cpu_dai); 1235 ret = cpu_dai->driver->ops->bespoke_trigger(substream, cmd, cpu_dai);
1079 if (ret < 0) 1236 if (ret < 0)
1080 return ret; 1237 return ret;
@@ -1090,6 +1247,8 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
1090{ 1247{
1091 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1248 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1092 struct snd_soc_platform *platform = rtd->platform; 1249 struct snd_soc_platform *platform = rtd->platform;
1250 struct snd_soc_component *component;
1251 struct snd_soc_rtdcom_list *rtdcom;
1093 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 1252 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1094 struct snd_soc_dai *codec_dai; 1253 struct snd_soc_dai *codec_dai;
1095 struct snd_pcm_runtime *runtime = substream->runtime; 1254 struct snd_pcm_runtime *runtime = substream->runtime;
@@ -1098,15 +1257,31 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
1098 snd_pcm_sframes_t codec_delay = 0; 1257 snd_pcm_sframes_t codec_delay = 0;
1099 int i; 1258 int i;
1100 1259
1101 if (platform->driver->ops && platform->driver->ops->pointer) 1260 if (platform && platform->driver->ops && platform->driver->ops->pointer)
1102 offset = platform->driver->ops->pointer(substream); 1261 offset = platform->driver->ops->pointer(substream);
1103 1262
1104 if (cpu_dai->driver->ops && cpu_dai->driver->ops->delay) 1263 for_each_rtdcom(rtd, rtdcom) {
1264 component = rtdcom->component;
1265
1266 /* ignore duplication for now */
1267 if (platform && (component == &platform->component))
1268 continue;
1269
1270 if (!component->driver->ops ||
1271 !component->driver->ops->pointer)
1272 continue;
1273
1274 /* FIXME: use 1st pointer */
1275 offset = component->driver->ops->pointer(substream);
1276 break;
1277 }
1278
1279 if (cpu_dai->driver->ops->delay)
1105 delay += cpu_dai->driver->ops->delay(substream, cpu_dai); 1280 delay += cpu_dai->driver->ops->delay(substream, cpu_dai);
1106 1281
1107 for (i = 0; i < rtd->num_codecs; i++) { 1282 for (i = 0; i < rtd->num_codecs; i++) {
1108 codec_dai = rtd->codec_dais[i]; 1283 codec_dai = rtd->codec_dais[i];
1109 if (codec_dai->driver->ops && codec_dai->driver->ops->delay) 1284 if (codec_dai->driver->ops->delay)
1110 codec_delay = max(codec_delay, 1285 codec_delay = max(codec_delay,
1111 codec_dai->driver->ops->delay(substream, 1286 codec_dai->driver->ops->delay(substream,
1112 codec_dai)); 1287 codec_dai));
@@ -2285,9 +2460,27 @@ static int soc_pcm_ioctl(struct snd_pcm_substream *substream,
2285{ 2460{
2286 struct snd_soc_pcm_runtime *rtd = substream->private_data; 2461 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2287 struct snd_soc_platform *platform = rtd->platform; 2462 struct snd_soc_platform *platform = rtd->platform;
2463 struct snd_soc_component *component;
2464 struct snd_soc_rtdcom_list *rtdcom;
2288 2465
2289 if (platform->driver->ops && platform->driver->ops->ioctl) 2466 if (platform && platform->driver->ops && platform->driver->ops->ioctl)
2290 return platform->driver->ops->ioctl(substream, cmd, arg); 2467 return platform->driver->ops->ioctl(substream, cmd, arg);
2468
2469 for_each_rtdcom(rtd, rtdcom) {
2470 component = rtdcom->component;
2471
2472 /* ignore duplication for now */
2473 if (platform && (component == &platform->component))
2474 continue;
2475
2476 if (!component->driver->ops ||
2477 !component->driver->ops->ioctl)
2478 continue;
2479
2480 /* FIXME: use 1st ioctl */
2481 return component->driver->ops->ioctl(substream, cmd, arg);
2482 }
2483
2291 return snd_pcm_lib_ioctl(substream, cmd, arg); 2484 return snd_pcm_lib_ioctl(substream, cmd, arg);
2292} 2485}
2293 2486
@@ -2632,12 +2825,163 @@ static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream)
2632 return ret; 2825 return ret;
2633} 2826}
2634 2827
2828static void soc_pcm_private_free(struct snd_pcm *pcm)
2829{
2830 struct snd_soc_pcm_runtime *rtd = pcm->private_data;
2831 struct snd_soc_rtdcom_list *rtdcom;
2832 struct snd_soc_component *component;
2833
2834 for_each_rtdcom(rtd, rtdcom) {
2835 /* need to sync the delayed work before releasing resources */
2836
2837 flush_delayed_work(&rtd->delayed_work);
2838 component = rtdcom->component;
2839
2840 if (component->pcm_free)
2841 component->pcm_free(component, pcm);
2842 }
2843}
2844
2845static int soc_rtdcom_ack(struct snd_pcm_substream *substream)
2846{
2847 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2848 struct snd_soc_rtdcom_list *rtdcom;
2849 struct snd_soc_component *component;
2850
2851 for_each_rtdcom(rtd, rtdcom) {
2852 component = rtdcom->component;
2853
2854 if (!component->driver->ops ||
2855 !component->driver->ops->ack)
2856 continue;
2857
2858 /* FIXME. it returns 1st ask now */
2859 return component->driver->ops->ack(substream);
2860 }
2861
2862 return -EINVAL;
2863}
2864
2865static int soc_rtdcom_copy_user(struct snd_pcm_substream *substream, int channel,
2866 unsigned long pos, void __user *buf,
2867 unsigned long bytes)
2868{
2869 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2870 struct snd_soc_rtdcom_list *rtdcom;
2871 struct snd_soc_component *component;
2872
2873 for_each_rtdcom(rtd, rtdcom) {
2874 component = rtdcom->component;
2875
2876 if (!component->driver->ops ||
2877 !component->driver->ops->copy_user)
2878 continue;
2879
2880 /* FIXME. it returns 1st copy now */
2881 return component->driver->ops->copy_user(substream, channel,
2882 pos, buf, bytes);
2883 }
2884
2885 return -EINVAL;
2886}
2887
2888static int soc_rtdcom_copy_kernel(struct snd_pcm_substream *substream, int channel,
2889 unsigned long pos, void *buf, unsigned long bytes)
2890{
2891 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2892 struct snd_soc_rtdcom_list *rtdcom;
2893 struct snd_soc_component *component;
2894
2895 for_each_rtdcom(rtd, rtdcom) {
2896 component = rtdcom->component;
2897
2898 if (!component->driver->ops ||
2899 !component->driver->ops->copy_kernel)
2900 continue;
2901
2902 /* FIXME. it returns 1st copy now */
2903 return component->driver->ops->copy_kernel(substream, channel,
2904 pos, buf, bytes);
2905 }
2906
2907 return -EINVAL;
2908}
2909
2910static int soc_rtdcom_fill_silence(struct snd_pcm_substream *substream, int channel,
2911 unsigned long pos, unsigned long bytes)
2912{
2913 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2914 struct snd_soc_rtdcom_list *rtdcom;
2915 struct snd_soc_component *component;
2916
2917 for_each_rtdcom(rtd, rtdcom) {
2918 component = rtdcom->component;
2919
2920 if (!component->driver->ops ||
2921 !component->driver->ops->fill_silence)
2922 continue;
2923
2924 /* FIXME. it returns 1st silence now */
2925 return component->driver->ops->fill_silence(substream, channel,
2926 pos, bytes);
2927 }
2928
2929 return -EINVAL;
2930}
2931
2932static struct page *soc_rtdcom_page(struct snd_pcm_substream *substream,
2933 unsigned long offset)
2934{
2935 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2936 struct snd_soc_rtdcom_list *rtdcom;
2937 struct snd_soc_component *component;
2938 struct page *page;
2939
2940 for_each_rtdcom(rtd, rtdcom) {
2941 component = rtdcom->component;
2942
2943 if (!component->driver->ops ||
2944 !component->driver->ops->page)
2945 continue;
2946
2947 /* FIXME. it returns 1st page now */
2948 page = component->driver->ops->page(substream, offset);
2949 if (page)
2950 return page;
2951 }
2952
2953 return NULL;
2954}
2955
2956static int soc_rtdcom_mmap(struct snd_pcm_substream *substream,
2957 struct vm_area_struct *vma)
2958{
2959 struct snd_soc_pcm_runtime *rtd = substream->private_data;
2960 struct snd_soc_rtdcom_list *rtdcom;
2961 struct snd_soc_component *component;
2962
2963 for_each_rtdcom(rtd, rtdcom) {
2964 component = rtdcom->component;
2965
2966 if (!component->driver->ops ||
2967 !component->driver->ops->mmap)
2968 continue;
2969
2970 /* FIXME. it returns 1st mmap now */
2971 return component->driver->ops->mmap(substream, vma);
2972 }
2973
2974 return -EINVAL;
2975}
2976
2635/* create a new pcm */ 2977/* create a new pcm */
2636int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) 2978int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
2637{ 2979{
2638 struct snd_soc_platform *platform = rtd->platform; 2980 struct snd_soc_platform *platform = rtd->platform;
2639 struct snd_soc_dai *codec_dai; 2981 struct snd_soc_dai *codec_dai;
2640 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 2982 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
2983 struct snd_soc_component *component;
2984 struct snd_soc_rtdcom_list *rtdcom;
2641 struct snd_pcm *pcm; 2985 struct snd_pcm *pcm;
2642 char new_name[64]; 2986 char new_name[64];
2643 int ret = 0, playback = 0, capture = 0; 2987 int ret = 0, playback = 0, capture = 0;
@@ -2732,7 +3076,28 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
2732 rtd->ops.ioctl = soc_pcm_ioctl; 3076 rtd->ops.ioctl = soc_pcm_ioctl;
2733 } 3077 }
2734 3078
2735 if (platform->driver->ops) { 3079 for_each_rtdcom(rtd, rtdcom) {
3080 const struct snd_pcm_ops *ops = rtdcom->component->driver->ops;
3081
3082 if (!ops)
3083 continue;
3084
3085 if (ops->ack)
3086 rtd->ops.ack = soc_rtdcom_ack;
3087 if (ops->copy_user)
3088 rtd->ops.copy_user = soc_rtdcom_copy_user;
3089 if (ops->copy_kernel)
3090 rtd->ops.copy_kernel = soc_rtdcom_copy_kernel;
3091 if (ops->fill_silence)
3092 rtd->ops.fill_silence = soc_rtdcom_fill_silence;
3093 if (ops->page)
3094 rtd->ops.page = soc_rtdcom_page;
3095 if (ops->mmap)
3096 rtd->ops.mmap = soc_rtdcom_mmap;
3097 }
3098
3099 /* overwrite */
3100 if (platform && platform->driver->ops) {
2736 rtd->ops.ack = platform->driver->ops->ack; 3101 rtd->ops.ack = platform->driver->ops->ack;
2737 rtd->ops.copy_user = platform->driver->ops->copy_user; 3102 rtd->ops.copy_user = platform->driver->ops->copy_user;
2738 rtd->ops.copy_kernel = platform->driver->ops->copy_kernel; 3103 rtd->ops.copy_kernel = platform->driver->ops->copy_kernel;
@@ -2747,17 +3112,22 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
2747 if (capture) 3112 if (capture)
2748 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &rtd->ops); 3113 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &rtd->ops);
2749 3114
2750 if (platform->driver->pcm_new) { 3115 for_each_rtdcom(rtd, rtdcom) {
2751 ret = platform->driver->pcm_new(rtd); 3116 component = rtdcom->component;
3117
3118 if (!component->pcm_new)
3119 continue;
3120
3121 ret = component->pcm_new(component, rtd);
2752 if (ret < 0) { 3122 if (ret < 0) {
2753 dev_err(platform->dev, 3123 dev_err(component->dev,
2754 "ASoC: pcm constructor failed: %d\n", 3124 "ASoC: pcm constructor failed: %d\n",
2755 ret); 3125 ret);
2756 return ret; 3126 return ret;
2757 } 3127 }
2758 } 3128 }
2759 3129
2760 pcm->private_free = platform->driver->pcm_free; 3130 pcm->private_free = soc_pcm_private_free;
2761out: 3131out:
2762 dev_info(rtd->card->dev, "%s <-> %s mapping ok\n", 3132 dev_info(rtd->card->dev, "%s <-> %s mapping ok\n",
2763 (rtd->num_codecs > 1) ? "multicodec" : rtd->codec_dai->name, 3133 (rtd->num_codecs > 1) ? "multicodec" : rtd->codec_dai->name,
diff --git a/sound/soc/stm/stm32_sai.c b/sound/soc/stm/stm32_sai.c
index 1258bef4dcb3..d6f71a3406e9 100644
--- a/sound/soc/stm/stm32_sai.c
+++ b/sound/soc/stm/stm32_sai.c
@@ -16,6 +16,7 @@
16 * details. 16 * details.
17 */ 17 */
18 18
19#include <linux/bitfield.h>
19#include <linux/clk.h> 20#include <linux/clk.h>
20#include <linux/delay.h> 21#include <linux/delay.h>
21#include <linux/module.h> 22#include <linux/module.h>
@@ -27,6 +28,16 @@
27 28
28#include "stm32_sai.h" 29#include "stm32_sai.h"
29 30
31static LIST_HEAD(sync_providers);
32static DEFINE_MUTEX(sync_mutex);
33
34struct sync_provider {
35 struct list_head link;
36 struct device_node *node;
37 int (*sync_conf)(void *data, int synco);
38 void *data;
39};
40
30static const struct stm32_sai_conf stm32_sai_conf_f4 = { 41static const struct stm32_sai_conf stm32_sai_conf_f4 = {
31 .version = SAI_STM32F4, 42 .version = SAI_STM32F4,
32}; 43};
@@ -41,23 +52,143 @@ static const struct of_device_id stm32_sai_ids[] = {
41 {} 52 {}
42}; 53};
43 54
55static int stm32_sai_sync_conf_client(struct stm32_sai_data *sai, int synci)
56{
57 int ret;
58
59 /* Enable peripheral clock to allow GCR register access */
60 ret = clk_prepare_enable(sai->pclk);
61 if (ret) {
62 dev_err(&sai->pdev->dev, "failed to enable clock: %d\n", ret);
63 return ret;
64 }
65
66 writel_relaxed(FIELD_PREP(SAI_GCR_SYNCIN_MASK, (synci - 1)), sai->base);
67
68 clk_disable_unprepare(sai->pclk);
69
70 return 0;
71}
72
73static int stm32_sai_sync_conf_provider(void *data, int synco)
74{
75 struct stm32_sai_data *sai = (struct stm32_sai_data *)data;
76 u32 prev_synco;
77 int ret;
78
79 /* Enable peripheral clock to allow GCR register access */
80 ret = clk_prepare_enable(sai->pclk);
81 if (ret) {
82 dev_err(&sai->pdev->dev, "failed to enable clock: %d\n", ret);
83 return ret;
84 }
85
86 dev_dbg(&sai->pdev->dev, "Set %s%s as synchro provider\n",
87 sai->pdev->dev.of_node->name,
88 synco == STM_SAI_SYNC_OUT_A ? "A" : "B");
89
90 prev_synco = FIELD_GET(SAI_GCR_SYNCOUT_MASK, readl_relaxed(sai->base));
91 if (prev_synco != STM_SAI_SYNC_OUT_NONE && synco != prev_synco) {
92 dev_err(&sai->pdev->dev, "%s%s already set as sync provider\n",
93 sai->pdev->dev.of_node->name,
94 prev_synco == STM_SAI_SYNC_OUT_A ? "A" : "B");
95 clk_disable_unprepare(sai->pclk);
96 return -EINVAL;
97 }
98
99 writel_relaxed(FIELD_PREP(SAI_GCR_SYNCOUT_MASK, synco), sai->base);
100
101 clk_disable_unprepare(sai->pclk);
102
103 return 0;
104}
105
106static int stm32_sai_set_sync_provider(struct device_node *np, int synco)
107{
108 struct sync_provider *provider;
109 int ret;
110
111 mutex_lock(&sync_mutex);
112 list_for_each_entry(provider, &sync_providers, link) {
113 if (provider->node == np) {
114 ret = provider->sync_conf(provider->data, synco);
115 mutex_unlock(&sync_mutex);
116 return ret;
117 }
118 }
119 mutex_unlock(&sync_mutex);
120
121 /* SAI sync provider not found */
122 return -ENODEV;
123}
124
125static int stm32_sai_set_sync(struct stm32_sai_data *sai,
126 struct device_node *np_provider,
127 int synco, int synci)
128{
129 int ret;
130
131 /* Configure sync client */
132 stm32_sai_sync_conf_client(sai, synci);
133
134 /* Configure sync provider */
135 ret = stm32_sai_set_sync_provider(np_provider, synco);
136
137 return ret;
138}
139
140static int stm32_sai_sync_add_provider(struct platform_device *pdev,
141 void *data)
142{
143 struct sync_provider *sp;
144
145 sp = devm_kzalloc(&pdev->dev, sizeof(*sp), GFP_KERNEL);
146 if (!sp)
147 return -ENOMEM;
148
149 sp->node = of_node_get(pdev->dev.of_node);
150 sp->data = data;
151 sp->sync_conf = &stm32_sai_sync_conf_provider;
152
153 mutex_lock(&sync_mutex);
154 list_add(&sp->link, &sync_providers);
155 mutex_unlock(&sync_mutex);
156
157 return 0;
158}
159
160static void stm32_sai_sync_del_provider(struct device_node *np)
161{
162 struct sync_provider *sp;
163
164 mutex_lock(&sync_mutex);
165 list_for_each_entry(sp, &sync_providers, link) {
166 if (sp->node == np) {
167 list_del(&sp->link);
168 of_node_put(sp->node);
169 break;
170 }
171 }
172 mutex_unlock(&sync_mutex);
173}
174
44static int stm32_sai_probe(struct platform_device *pdev) 175static int stm32_sai_probe(struct platform_device *pdev)
45{ 176{
46 struct device_node *np = pdev->dev.of_node; 177 struct device_node *np = pdev->dev.of_node;
47 struct stm32_sai_data *sai; 178 struct stm32_sai_data *sai;
48 struct reset_control *rst; 179 struct reset_control *rst;
49 struct resource *res; 180 struct resource *res;
50 void __iomem *base;
51 const struct of_device_id *of_id; 181 const struct of_device_id *of_id;
182 int ret;
52 183
53 sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL); 184 sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL);
54 if (!sai) 185 if (!sai)
55 return -ENOMEM; 186 return -ENOMEM;
56 187
57 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 188 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
58 base = devm_ioremap_resource(&pdev->dev, res); 189 sai->base = devm_ioremap_resource(&pdev->dev, res);
59 if (IS_ERR(base)) 190 if (IS_ERR(sai->base))
60 return PTR_ERR(base); 191 return PTR_ERR(sai->base);
61 192
62 of_id = of_match_device(stm32_sai_ids, &pdev->dev); 193 of_id = of_match_device(stm32_sai_ids, &pdev->dev);
63 if (of_id) 194 if (of_id)
@@ -65,6 +196,14 @@ static int stm32_sai_probe(struct platform_device *pdev)
65 else 196 else
66 return -EINVAL; 197 return -EINVAL;
67 198
199 if (!STM_SAI_IS_F4(sai)) {
200 sai->pclk = devm_clk_get(&pdev->dev, "pclk");
201 if (IS_ERR(sai->pclk)) {
202 dev_err(&pdev->dev, "missing bus clock pclk\n");
203 return PTR_ERR(sai->pclk);
204 }
205 }
206
68 sai->clk_x8k = devm_clk_get(&pdev->dev, "x8k"); 207 sai->clk_x8k = devm_clk_get(&pdev->dev, "x8k");
69 if (IS_ERR(sai->clk_x8k)) { 208 if (IS_ERR(sai->clk_x8k)) {
70 dev_err(&pdev->dev, "missing x8k parent clock\n"); 209 dev_err(&pdev->dev, "missing x8k parent clock\n");
@@ -85,23 +224,34 @@ static int stm32_sai_probe(struct platform_device *pdev)
85 } 224 }
86 225
87 /* reset */ 226 /* reset */
88 rst = reset_control_get_exclusive(&pdev->dev, NULL); 227 rst = devm_reset_control_get_exclusive(&pdev->dev, NULL);
89 if (!IS_ERR(rst)) { 228 if (!IS_ERR(rst)) {
90 reset_control_assert(rst); 229 reset_control_assert(rst);
91 udelay(2); 230 udelay(2);
92 reset_control_deassert(rst); 231 reset_control_deassert(rst);
93 } 232 }
94 233
234 ret = stm32_sai_sync_add_provider(pdev, sai);
235 if (ret < 0)
236 return ret;
237 sai->set_sync = &stm32_sai_set_sync;
238
95 sai->pdev = pdev; 239 sai->pdev = pdev;
96 platform_set_drvdata(pdev, sai); 240 platform_set_drvdata(pdev, sai);
97 241
98 return of_platform_populate(np, NULL, NULL, &pdev->dev); 242 ret = of_platform_populate(np, NULL, NULL, &pdev->dev);
243 if (ret < 0)
244 stm32_sai_sync_del_provider(np);
245
246 return ret;
99} 247}
100 248
101static int stm32_sai_remove(struct platform_device *pdev) 249static int stm32_sai_remove(struct platform_device *pdev)
102{ 250{
103 of_platform_depopulate(&pdev->dev); 251 of_platform_depopulate(&pdev->dev);
104 252
253 stm32_sai_sync_del_provider(pdev->dev.of_node);
254
105 return 0; 255 return 0;
106} 256}
107 257
diff --git a/sound/soc/stm/stm32_sai.h b/sound/soc/stm/stm32_sai.h
index 889974dc62d9..bb062e70de63 100644
--- a/sound/soc/stm/stm32_sai.h
+++ b/sound/soc/stm/stm32_sai.h
@@ -16,9 +16,11 @@
16 * details. 16 * details.
17 */ 17 */
18 18
19#include <linux/bitfield.h>
20
19/******************** SAI Register Map **************************************/ 21/******************** SAI Register Map **************************************/
20 22
21/* common register */ 23/* Global configuration register */
22#define STM_SAI_GCR 0x00 24#define STM_SAI_GCR 0x00
23 25
24/* Sub-block A&B registers offsets, relative to A&B sub-block addresses */ 26/* Sub-block A&B registers offsets, relative to A&B sub-block addresses */
@@ -37,12 +39,13 @@
37 39
38/******************** Bit definition for SAI_GCR register *******************/ 40/******************** Bit definition for SAI_GCR register *******************/
39#define SAI_GCR_SYNCIN_SHIFT 0 41#define SAI_GCR_SYNCIN_SHIFT 0
42#define SAI_GCR_SYNCIN_WDTH 2
40#define SAI_GCR_SYNCIN_MASK GENMASK(1, SAI_GCR_SYNCIN_SHIFT) 43#define SAI_GCR_SYNCIN_MASK GENMASK(1, SAI_GCR_SYNCIN_SHIFT)
41#define SAI_GCR_SYNCIN_SET(x) ((x) << SAI_GCR_SYNCIN_SHIFT) 44#define SAI_GCR_SYNCIN_MAX FIELD_GET(SAI_GCR_SYNCIN_MASK,\
45 SAI_GCR_SYNCIN_MASK)
42 46
43#define SAI_GCR_SYNCOUT_SHIFT 4 47#define SAI_GCR_SYNCOUT_SHIFT 4
44#define SAI_GCR_SYNCOUT_MASK GENMASK(5, SAI_GCR_SYNCOUT_SHIFT) 48#define SAI_GCR_SYNCOUT_MASK GENMASK(5, SAI_GCR_SYNCOUT_SHIFT)
45#define SAI_GCR_SYNCOUT_SET(x) ((x) << SAI_GCR_SYNCOUT_SHIFT)
46 49
47/******************* Bit definition for SAI_XCR1 register *******************/ 50/******************* Bit definition for SAI_XCR1 register *******************/
48#define SAI_XCR1_RX_TX_SHIFT 0 51#define SAI_XCR1_RX_TX_SHIFT 0
@@ -231,6 +234,12 @@
231#define STM_SAI_IS_F4(ip) ((ip)->conf->version == SAI_STM32F4) 234#define STM_SAI_IS_F4(ip) ((ip)->conf->version == SAI_STM32F4)
232#define STM_SAI_IS_H7(ip) ((ip)->conf->version == SAI_STM32H7) 235#define STM_SAI_IS_H7(ip) ((ip)->conf->version == SAI_STM32H7)
233 236
237enum stm32_sai_syncout {
238 STM_SAI_SYNC_OUT_NONE,
239 STM_SAI_SYNC_OUT_A,
240 STM_SAI_SYNC_OUT_B,
241};
242
234enum stm32_sai_version { 243enum stm32_sai_version {
235 SAI_STM32F4, 244 SAI_STM32F4,
236 SAI_STM32H7 245 SAI_STM32H7
@@ -247,15 +256,22 @@ struct stm32_sai_conf {
247/** 256/**
248 * struct stm32_sai_data - private data of SAI instance driver 257 * struct stm32_sai_data - private data of SAI instance driver
249 * @pdev: device data pointer 258 * @pdev: device data pointer
259 * @base: common register bank virtual base address
260 * @pclk: SAI bus clock
250 * @clk_x8k: SAI parent clock for sampling frequencies multiple of 8kHz 261 * @clk_x8k: SAI parent clock for sampling frequencies multiple of 8kHz
251 * @clk_x11k: SAI parent clock for sampling frequencies multiple of 11kHz 262 * @clk_x11k: SAI parent clock for sampling frequencies multiple of 11kHz
252 * @version: SOC version 263 * @version: SOC version
253 * @irq: SAI interrupt line 264 * @irq: SAI interrupt line
265 * @set_sync: pointer to synchro mode configuration callback
254 */ 266 */
255struct stm32_sai_data { 267struct stm32_sai_data {
256 struct platform_device *pdev; 268 struct platform_device *pdev;
269 void __iomem *base;
270 struct clk *pclk;
257 struct clk *clk_x8k; 271 struct clk *clk_x8k;
258 struct clk *clk_x11k; 272 struct clk *clk_x11k;
259 struct stm32_sai_conf *conf; 273 struct stm32_sai_conf *conf;
260 int irq; 274 int irq;
275 int (*set_sync)(struct stm32_sai_data *sai,
276 struct device_node *np_provider, int synco, int synci);
261}; 277};
diff --git a/sound/soc/stm/stm32_sai_sub.c b/sound/soc/stm/stm32_sai_sub.c
index 90d439613899..08583b958430 100644
--- a/sound/soc/stm/stm32_sai_sub.c
+++ b/sound/soc/stm/stm32_sai_sub.c
@@ -55,6 +55,12 @@
55#define STM_SAI_IS_SUB_B(x) ((x)->id == STM_SAI_B_ID) 55#define STM_SAI_IS_SUB_B(x) ((x)->id == STM_SAI_B_ID)
56#define STM_SAI_BLOCK_NAME(x) (((x)->id == STM_SAI_A_ID) ? "A" : "B") 56#define STM_SAI_BLOCK_NAME(x) (((x)->id == STM_SAI_A_ID) ? "A" : "B")
57 57
58#define SAI_SYNC_NONE 0x0
59#define SAI_SYNC_INTERNAL 0x1
60#define SAI_SYNC_EXTERNAL 0x2
61
62#define STM_SAI_HAS_EXT_SYNC(x) (!STM_SAI_IS_F4(sai->pdata))
63
58/** 64/**
59 * struct stm32_sai_sub_data - private data of SAI sub block (block A or B) 65 * struct stm32_sai_sub_data - private data of SAI sub block (block A or B)
60 * @pdev: device data pointer 66 * @pdev: device data pointer
@@ -65,6 +71,7 @@
65 * @cpu_dai: DAI runtime data pointer 71 * @cpu_dai: DAI runtime data pointer
66 * @substream: PCM substream data pointer 72 * @substream: PCM substream data pointer
67 * @pdata: SAI block parent data pointer 73 * @pdata: SAI block parent data pointer
74 * @np_sync_provider: synchronization provider node
68 * @sai_ck: kernel clock feeding the SAI clock generator 75 * @sai_ck: kernel clock feeding the SAI clock generator
69 * @phys_addr: SAI registers physical base address 76 * @phys_addr: SAI registers physical base address
70 * @mclk_rate: SAI block master clock frequency (Hz). set at init 77 * @mclk_rate: SAI block master clock frequency (Hz). set at init
@@ -73,6 +80,8 @@
73 * @master: SAI block mode flag. (true=master, false=slave) set at init 80 * @master: SAI block mode flag. (true=master, false=slave) set at init
74 * @fmt: SAI block format. relevant only for custom protocols. set at init 81 * @fmt: SAI block format. relevant only for custom protocols. set at init
75 * @sync: SAI block synchronization mode. (none, internal or external) 82 * @sync: SAI block synchronization mode. (none, internal or external)
83 * @synco: SAI block ext sync source (provider setting). (none, sub-block A/B)
84 * @synci: SAI block ext sync source (client setting). (SAI sync provider index)
76 * @fs_length: frame synchronization length. depends on protocol settings 85 * @fs_length: frame synchronization length. depends on protocol settings
77 * @slots: rx or tx slot number 86 * @slots: rx or tx slot number
78 * @slot_width: rx or tx slot width in bits 87 * @slot_width: rx or tx slot width in bits
@@ -88,6 +97,7 @@ struct stm32_sai_sub_data {
88 struct snd_soc_dai *cpu_dai; 97 struct snd_soc_dai *cpu_dai;
89 struct snd_pcm_substream *substream; 98 struct snd_pcm_substream *substream;
90 struct stm32_sai_data *pdata; 99 struct stm32_sai_data *pdata;
100 struct device_node *np_sync_provider;
91 struct clk *sai_ck; 101 struct clk *sai_ck;
92 dma_addr_t phys_addr; 102 dma_addr_t phys_addr;
93 unsigned int mclk_rate; 103 unsigned int mclk_rate;
@@ -96,6 +106,8 @@ struct stm32_sai_sub_data {
96 bool master; 106 bool master;
97 int fmt; 107 int fmt;
98 int sync; 108 int sync;
109 int synco;
110 int synci;
99 int fs_length; 111 int fs_length;
100 int slots; 112 int slots;
101 int slot_width; 113 int slot_width;
@@ -184,7 +196,6 @@ static const struct regmap_config stm32_sai_sub_regmap_config_h7 = {
184static irqreturn_t stm32_sai_isr(int irq, void *devid) 196static irqreturn_t stm32_sai_isr(int irq, void *devid)
185{ 197{
186 struct stm32_sai_sub_data *sai = (struct stm32_sai_sub_data *)devid; 198 struct stm32_sai_sub_data *sai = (struct stm32_sai_sub_data *)devid;
187 struct snd_pcm_substream *substream = sai->substream;
188 struct platform_device *pdev = sai->pdev; 199 struct platform_device *pdev = sai->pdev;
189 unsigned int sr, imr, flags; 200 unsigned int sr, imr, flags;
190 snd_pcm_state_t status = SNDRV_PCM_STATE_RUNNING; 201 snd_pcm_state_t status = SNDRV_PCM_STATE_RUNNING;
@@ -199,6 +210,11 @@ static irqreturn_t stm32_sai_isr(int irq, void *devid)
199 regmap_update_bits(sai->regmap, STM_SAI_CLRFR_REGX, SAI_XCLRFR_MASK, 210 regmap_update_bits(sai->regmap, STM_SAI_CLRFR_REGX, SAI_XCLRFR_MASK,
200 SAI_XCLRFR_MASK); 211 SAI_XCLRFR_MASK);
201 212
213 if (!sai->substream) {
214 dev_err(&pdev->dev, "Device stopped. Spurious IRQ 0x%x\n", sr);
215 return IRQ_NONE;
216 }
217
202 if (flags & SAI_XIMR_OVRUDRIE) { 218 if (flags & SAI_XIMR_OVRUDRIE) {
203 dev_err(&pdev->dev, "IRQ %s\n", 219 dev_err(&pdev->dev, "IRQ %s\n",
204 STM_SAI_IS_PLAYBACK(sai) ? "underrun" : "overrun"); 220 STM_SAI_IS_PLAYBACK(sai) ? "underrun" : "overrun");
@@ -227,9 +243,9 @@ static irqreturn_t stm32_sai_isr(int irq, void *devid)
227 } 243 }
228 244
229 if (status != SNDRV_PCM_STATE_RUNNING) { 245 if (status != SNDRV_PCM_STATE_RUNNING) {
230 snd_pcm_stream_lock(substream); 246 snd_pcm_stream_lock(sai->substream);
231 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); 247 snd_pcm_stop(sai->substream, SNDRV_PCM_STATE_XRUN);
232 snd_pcm_stream_unlock(substream); 248 snd_pcm_stream_unlock(sai->substream);
233 } 249 }
234 250
235 return IRQ_HANDLED; 251 return IRQ_HANDLED;
@@ -304,12 +320,15 @@ static int stm32_sai_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai, u32 tx_mask,
304static int stm32_sai_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) 320static int stm32_sai_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
305{ 321{
306 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); 322 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai);
307 int cr1 = 0, frcr = 0; 323 int cr1, frcr = 0;
308 int cr1_mask = 0, frcr_mask = 0; 324 int cr1_mask, frcr_mask = 0;
309 int ret; 325 int ret;
310 326
311 dev_dbg(cpu_dai->dev, "fmt %x\n", fmt); 327 dev_dbg(cpu_dai->dev, "fmt %x\n", fmt);
312 328
329 cr1_mask = SAI_XCR1_PRTCFG_MASK;
330 cr1 = SAI_XCR1_PRTCFG_SET(SAI_FREE_PROTOCOL);
331
313 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 332 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
314 /* SCK active high for all protocols */ 333 /* SCK active high for all protocols */
315 case SND_SOC_DAIFMT_I2S: 334 case SND_SOC_DAIFMT_I2S:
@@ -336,7 +355,7 @@ static int stm32_sai_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
336 return -EINVAL; 355 return -EINVAL;
337 } 356 }
338 357
339 cr1_mask |= SAI_XCR1_PRTCFG_MASK | SAI_XCR1_CKSTR; 358 cr1_mask |= SAI_XCR1_CKSTR;
340 frcr_mask |= SAI_XFRCR_FSPOL | SAI_XFRCR_FSOFF | 359 frcr_mask |= SAI_XFRCR_FSPOL | SAI_XFRCR_FSOFF |
341 SAI_XFRCR_FSDEF; 360 SAI_XFRCR_FSDEF;
342 361
@@ -380,6 +399,14 @@ static int stm32_sai_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
380 fmt & SND_SOC_DAIFMT_MASTER_MASK); 399 fmt & SND_SOC_DAIFMT_MASTER_MASK);
381 return -EINVAL; 400 return -EINVAL;
382 } 401 }
402
403 /* Set slave mode if sub-block is synchronized with another SAI */
404 if (sai->sync) {
405 dev_dbg(cpu_dai->dev, "Synchronized SAI configured as slave\n");
406 cr1 |= SAI_XCR1_SLAVE;
407 sai->master = false;
408 }
409
383 cr1_mask |= SAI_XCR1_SLAVE; 410 cr1_mask |= SAI_XCR1_SLAVE;
384 411
385 /* do not generate master by default */ 412 /* do not generate master by default */
@@ -412,8 +439,6 @@ static int stm32_sai_startup(struct snd_pcm_substream *substream,
412 } 439 }
413 440
414 /* Enable ITs */ 441 /* Enable ITs */
415 regmap_update_bits(sai->regmap, STM_SAI_SR_REGX,
416 SAI_XSR_MASK, (unsigned int)~SAI_XSR_MASK);
417 442
418 regmap_update_bits(sai->regmap, STM_SAI_CLRFR_REGX, 443 regmap_update_bits(sai->regmap, STM_SAI_CLRFR_REGX,
419 SAI_XCLRFR_MASK, SAI_XCLRFR_MASK); 444 SAI_XCLRFR_MASK, SAI_XCLRFR_MASK);
@@ -442,34 +467,33 @@ static int stm32_sai_set_config(struct snd_soc_dai *cpu_dai,
442{ 467{
443 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); 468 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai);
444 int cr1, cr1_mask, ret; 469 int cr1, cr1_mask, ret;
445 int fth = STM_SAI_FIFO_TH_HALF;
446 470
447 /* FIFO config */ 471 /*
472 * DMA bursts increment is set to 4 words.
473 * SAI fifo threshold is set to half fifo, to keep enough space
474 * for DMA incoming bursts.
475 */
448 regmap_update_bits(sai->regmap, STM_SAI_CR2_REGX, 476 regmap_update_bits(sai->regmap, STM_SAI_CR2_REGX,
449 SAI_XCR2_FFLUSH | SAI_XCR2_FTH_MASK, 477 SAI_XCR2_FFLUSH | SAI_XCR2_FTH_MASK,
450 SAI_XCR2_FFLUSH | SAI_XCR2_FTH_SET(fth)); 478 SAI_XCR2_FFLUSH |
479 SAI_XCR2_FTH_SET(STM_SAI_FIFO_TH_HALF));
451 480
452 /* Mode, data format and channel config */ 481 /* Mode, data format and channel config */
453 cr1 = SAI_XCR1_PRTCFG_SET(SAI_FREE_PROTOCOL); 482 cr1_mask = SAI_XCR1_DS_MASK;
454 switch (params_format(params)) { 483 switch (params_format(params)) {
455 case SNDRV_PCM_FORMAT_S8: 484 case SNDRV_PCM_FORMAT_S8:
456 cr1 |= SAI_XCR1_DS_SET(SAI_DATASIZE_8); 485 cr1 = SAI_XCR1_DS_SET(SAI_DATASIZE_8);
457 break; 486 break;
458 case SNDRV_PCM_FORMAT_S16_LE: 487 case SNDRV_PCM_FORMAT_S16_LE:
459 cr1 |= SAI_XCR1_DS_SET(SAI_DATASIZE_16); 488 cr1 = SAI_XCR1_DS_SET(SAI_DATASIZE_16);
460 break; 489 break;
461 case SNDRV_PCM_FORMAT_S32_LE: 490 case SNDRV_PCM_FORMAT_S32_LE:
462 cr1 |= SAI_XCR1_DS_SET(SAI_DATASIZE_32); 491 cr1 = SAI_XCR1_DS_SET(SAI_DATASIZE_32);
463 break; 492 break;
464 default: 493 default:
465 dev_err(cpu_dai->dev, "Data format not supported"); 494 dev_err(cpu_dai->dev, "Data format not supported");
466 return -EINVAL; 495 return -EINVAL;
467 } 496 }
468 cr1_mask = SAI_XCR1_DS_MASK | SAI_XCR1_PRTCFG_MASK;
469
470 cr1_mask |= SAI_XCR1_RX_TX;
471 if (STM_SAI_IS_CAPTURE(sai))
472 cr1 |= SAI_XCR1_RX_TX;
473 497
474 cr1_mask |= SAI_XCR1_MONO; 498 cr1_mask |= SAI_XCR1_MONO;
475 if ((sai->slots == 2) && (params_channels(params) == 1)) 499 if ((sai->slots == 2) && (params_channels(params) == 1))
@@ -481,10 +505,6 @@ static int stm32_sai_set_config(struct snd_soc_dai *cpu_dai,
481 return ret; 505 return ret;
482 } 506 }
483 507
484 /* DMA config */
485 sai->dma_params.maxburst = STM_SAI_FIFO_SIZE * fth / sizeof(u32);
486 snd_soc_dai_set_dma_data(cpu_dai, substream, (void *)&sai->dma_params);
487
488 return 0; 508 return 0;
489} 509}
490 510
@@ -691,6 +711,9 @@ static int stm32_sai_trigger(struct snd_pcm_substream *substream, int cmd,
691 case SNDRV_PCM_TRIGGER_STOP: 711 case SNDRV_PCM_TRIGGER_STOP:
692 dev_dbg(cpu_dai->dev, "Disable DMA and SAI\n"); 712 dev_dbg(cpu_dai->dev, "Disable DMA and SAI\n");
693 713
714 regmap_update_bits(sai->regmap, STM_SAI_IMR_REGX,
715 SAI_XIMR_MASK, 0);
716
694 regmap_update_bits(sai->regmap, STM_SAI_CR1_REGX, 717 regmap_update_bits(sai->regmap, STM_SAI_CR1_REGX,
695 SAI_XCR1_SAIEN, 718 SAI_XCR1_SAIEN,
696 (unsigned int)~SAI_XCR1_SAIEN); 719 (unsigned int)~SAI_XCR1_SAIEN);
@@ -725,9 +748,15 @@ static void stm32_sai_shutdown(struct snd_pcm_substream *substream,
725static int stm32_sai_dai_probe(struct snd_soc_dai *cpu_dai) 748static int stm32_sai_dai_probe(struct snd_soc_dai *cpu_dai)
726{ 749{
727 struct stm32_sai_sub_data *sai = dev_get_drvdata(cpu_dai->dev); 750 struct stm32_sai_sub_data *sai = dev_get_drvdata(cpu_dai->dev);
751 int cr1 = 0, cr1_mask;
728 752
729 sai->dma_params.addr = (dma_addr_t)(sai->phys_addr + STM_SAI_DR_REGX); 753 sai->dma_params.addr = (dma_addr_t)(sai->phys_addr + STM_SAI_DR_REGX);
730 sai->dma_params.maxburst = 1; 754 /*
755 * DMA supports 4, 8 or 16 burst sizes. Burst size 4 is the best choice,
756 * as it allows bytes, half-word and words transfers. (See DMA fifos
757 * constraints).
758 */
759 sai->dma_params.maxburst = 4;
731 /* Buswidth will be set by framework at runtime */ 760 /* Buswidth will be set by framework at runtime */
732 sai->dma_params.addr_width = DMA_SLAVE_BUSWIDTH_UNDEFINED; 761 sai->dma_params.addr_width = DMA_SLAVE_BUSWIDTH_UNDEFINED;
733 762
@@ -736,7 +765,21 @@ static int stm32_sai_dai_probe(struct snd_soc_dai *cpu_dai)
736 else 765 else
737 snd_soc_dai_init_dma_data(cpu_dai, NULL, &sai->dma_params); 766 snd_soc_dai_init_dma_data(cpu_dai, NULL, &sai->dma_params);
738 767
739 return 0; 768 cr1_mask = SAI_XCR1_RX_TX;
769 if (STM_SAI_IS_CAPTURE(sai))
770 cr1 |= SAI_XCR1_RX_TX;
771
772 /* Configure synchronization */
773 if (sai->sync == SAI_SYNC_EXTERNAL) {
774 /* Configure synchro client and provider */
775 sai->pdata->set_sync(sai->pdata, sai->np_sync_provider,
776 sai->synco, sai->synci);
777 }
778
779 cr1_mask |= SAI_XCR1_SYNCEN_MASK;
780 cr1 |= SAI_XCR1_SYNCEN_SET(sai->sync);
781
782 return regmap_update_bits(sai->regmap, STM_SAI_CR1_REGX, cr1_mask, cr1);
740} 783}
741 784
742static const struct snd_soc_dai_ops stm32_sai_pcm_dai_ops = { 785static const struct snd_soc_dai_ops stm32_sai_pcm_dai_ops = {
@@ -822,6 +865,8 @@ static int stm32_sai_sub_parse_of(struct platform_device *pdev,
822 struct device_node *np = pdev->dev.of_node; 865 struct device_node *np = pdev->dev.of_node;
823 struct resource *res; 866 struct resource *res;
824 void __iomem *base; 867 void __iomem *base;
868 struct of_phandle_args args;
869 int ret;
825 870
826 if (!np) 871 if (!np)
827 return -ENODEV; 872 return -ENODEV;
@@ -855,6 +900,69 @@ static int stm32_sai_sub_parse_of(struct platform_device *pdev,
855 return -EINVAL; 900 return -EINVAL;
856 } 901 }
857 902
903 /* Get synchronization property */
904 args.np = NULL;
905 ret = of_parse_phandle_with_fixed_args(np, "st,sync", 1, 0, &args);
906 if (ret < 0 && ret != -ENOENT) {
907 dev_err(&pdev->dev, "Failed to get st,sync property\n");
908 return ret;
909 }
910
911 sai->sync = SAI_SYNC_NONE;
912 if (args.np) {
913 if (args.np == np) {
914 dev_err(&pdev->dev, "%s sync own reference\n",
915 np->name);
916 of_node_put(args.np);
917 return -EINVAL;
918 }
919
920 sai->np_sync_provider = of_get_parent(args.np);
921 if (!sai->np_sync_provider) {
922 dev_err(&pdev->dev, "%s parent node not found\n",
923 np->name);
924 of_node_put(args.np);
925 return -ENODEV;
926 }
927
928 sai->sync = SAI_SYNC_INTERNAL;
929 if (sai->np_sync_provider != sai->pdata->pdev->dev.of_node) {
930 if (!STM_SAI_HAS_EXT_SYNC(sai)) {
931 dev_err(&pdev->dev,
932 "External synchro not supported\n");
933 of_node_put(args.np);
934 return -EINVAL;
935 }
936 sai->sync = SAI_SYNC_EXTERNAL;
937
938 sai->synci = args.args[0];
939 if (sai->synci < 1 ||
940 (sai->synci > (SAI_GCR_SYNCIN_MAX + 1))) {
941 dev_err(&pdev->dev, "Wrong SAI index\n");
942 of_node_put(args.np);
943 return -EINVAL;
944 }
945
946 if (of_property_match_string(args.np, "compatible",
947 "st,stm32-sai-sub-a") >= 0)
948 sai->synco = STM_SAI_SYNC_OUT_A;
949
950 if (of_property_match_string(args.np, "compatible",
951 "st,stm32-sai-sub-b") >= 0)
952 sai->synco = STM_SAI_SYNC_OUT_B;
953
954 if (!sai->synco) {
955 dev_err(&pdev->dev, "Unknown SAI sub-block\n");
956 of_node_put(args.np);
957 return -EINVAL;
958 }
959 }
960
961 dev_dbg(&pdev->dev, "%s synchronized with %s\n",
962 pdev->name, args.np->full_name);
963 }
964
965 of_node_put(args.np);
858 sai->sai_ck = devm_clk_get(&pdev->dev, "sai_ck"); 966 sai->sai_ck = devm_clk_get(&pdev->dev, "sai_ck");
859 if (IS_ERR(sai->sai_ck)) { 967 if (IS_ERR(sai->sai_ck)) {
860 dev_err(&pdev->dev, "Missing kernel clock sai_ck\n"); 968 dev_err(&pdev->dev, "Missing kernel clock sai_ck\n");
diff --git a/sound/soc/stm/stm32_spdifrx.c b/sound/soc/stm/stm32_spdifrx.c
index 84cc5678beba..b9bdefcd3e10 100644
--- a/sound/soc/stm/stm32_spdifrx.c
+++ b/sound/soc/stm/stm32_spdifrx.c
@@ -392,6 +392,12 @@ static int stm32_spdifrx_dma_ctrl_register(struct device *dev,
392{ 392{
393 int ret; 393 int ret;
394 394
395 spdifrx->ctrl_chan = dma_request_chan(dev, "rx-ctrl");
396 if (IS_ERR(spdifrx->ctrl_chan)) {
397 dev_err(dev, "dma_request_slave_channel failed\n");
398 return PTR_ERR(spdifrx->ctrl_chan);
399 }
400
395 spdifrx->dmab = devm_kzalloc(dev, sizeof(struct snd_dma_buffer), 401 spdifrx->dmab = devm_kzalloc(dev, sizeof(struct snd_dma_buffer),
396 GFP_KERNEL); 402 GFP_KERNEL);
397 if (!spdifrx->dmab) 403 if (!spdifrx->dmab)
@@ -406,12 +412,6 @@ static int stm32_spdifrx_dma_ctrl_register(struct device *dev,
406 return ret; 412 return ret;
407 } 413 }
408 414
409 spdifrx->ctrl_chan = dma_request_chan(dev, "rx-ctrl");
410 if (!spdifrx->ctrl_chan) {
411 dev_err(dev, "dma_request_slave_channel failed\n");
412 return -EINVAL;
413 }
414
415 spdifrx->slave_config.direction = DMA_DEV_TO_MEM; 415 spdifrx->slave_config.direction = DMA_DEV_TO_MEM;
416 spdifrx->slave_config.src_addr = (dma_addr_t)(spdifrx->phys_addr + 416 spdifrx->slave_config.src_addr = (dma_addr_t)(spdifrx->phys_addr +
417 STM32_SPDIFRX_CSR); 417 STM32_SPDIFRX_CSR);
@@ -423,7 +423,6 @@ static int stm32_spdifrx_dma_ctrl_register(struct device *dev,
423 &spdifrx->slave_config); 423 &spdifrx->slave_config);
424 if (ret < 0) { 424 if (ret < 0) {
425 dev_err(dev, "dmaengine_slave_config returned error %d\n", ret); 425 dev_err(dev, "dmaengine_slave_config returned error %d\n", ret);
426 dma_release_channel(spdifrx->ctrl_chan);
427 spdifrx->ctrl_chan = NULL; 426 spdifrx->ctrl_chan = NULL;
428 } 427 }
429 428
@@ -750,17 +749,21 @@ static int stm32_spdifrx_hw_params(struct snd_pcm_substream *substream,
750 switch (data_size) { 749 switch (data_size) {
751 case 16: 750 case 16:
752 fmt = SPDIFRX_DRFMT_PACKED; 751 fmt = SPDIFRX_DRFMT_PACKED;
753 spdifrx->dma_params.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
754 break; 752 break;
755 case 32: 753 case 32:
756 fmt = SPDIFRX_DRFMT_LEFT; 754 fmt = SPDIFRX_DRFMT_LEFT;
757 spdifrx->dma_params.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
758 break; 755 break;
759 default: 756 default:
760 dev_err(&spdifrx->pdev->dev, "Unexpected data format\n"); 757 dev_err(&spdifrx->pdev->dev, "Unexpected data format\n");
761 return -EINVAL; 758 return -EINVAL;
762 } 759 }
763 760
761 /*
762 * Set buswidth to 4 bytes for all data formats.
763 * Packed format: transfer 2 x 2 bytes samples
764 * Left format: transfer 1 x 3 bytes samples + 1 dummy byte
765 */
766 spdifrx->dma_params.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
764 snd_soc_dai_init_dma_data(cpu_dai, NULL, &spdifrx->dma_params); 767 snd_soc_dai_init_dma_data(cpu_dai, NULL, &spdifrx->dma_params);
765 768
766 return regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_CR, 769 return regmap_update_bits(spdifrx->regmap, STM32_SPDIFRX_CR,
@@ -958,7 +961,7 @@ static int stm32_spdifrx_probe(struct platform_device *pdev)
958 return 0; 961 return 0;
959 962
960error: 963error:
961 if (spdifrx->ctrl_chan) 964 if (!IS_ERR(spdifrx->ctrl_chan))
962 dma_release_channel(spdifrx->ctrl_chan); 965 dma_release_channel(spdifrx->ctrl_chan);
963 if (spdifrx->dmab) 966 if (spdifrx->dmab)
964 snd_dma_free_pages(spdifrx->dmab); 967 snd_dma_free_pages(spdifrx->dmab);
diff --git a/sound/soc/sunxi/sun4i-codec.c b/sound/soc/sunxi/sun4i-codec.c
index baa9007464ed..5da4efe7a550 100644
--- a/sound/soc/sunxi/sun4i-codec.c
+++ b/sound/soc/sunxi/sun4i-codec.c
@@ -346,11 +346,6 @@ static int sun4i_codec_prepare_capture(struct snd_pcm_substream *substream,
346 0x3 << 8, 346 0x3 << 8,
347 0x1 << 8); 347 0x1 << 8);
348 348
349 /* Fill most significant bits with valid data MSB */
350 regmap_field_update_bits(scodec->reg_adc_fifoc,
351 BIT(SUN4I_CODEC_ADC_FIFOC_RX_FIFO_MODE),
352 BIT(SUN4I_CODEC_ADC_FIFOC_RX_FIFO_MODE));
353
354 return 0; 349 return 0;
355} 350}
356 351
@@ -490,6 +485,30 @@ static int sun4i_codec_hw_params_capture(struct sun4i_codec *scodec,
490 BIT(SUN4I_CODEC_ADC_FIFOC_MONO_EN), 485 BIT(SUN4I_CODEC_ADC_FIFOC_MONO_EN),
491 0); 486 0);
492 487
488 /* Set the number of sample bits to either 16 or 24 bits */
489 if (hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS)->min == 32) {
490 regmap_field_update_bits(scodec->reg_adc_fifoc,
491 BIT(SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS),
492 BIT(SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS));
493
494 regmap_field_update_bits(scodec->reg_adc_fifoc,
495 BIT(SUN4I_CODEC_ADC_FIFOC_RX_FIFO_MODE),
496 0);
497
498 scodec->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
499 } else {
500 regmap_field_update_bits(scodec->reg_adc_fifoc,
501 BIT(SUN4I_CODEC_ADC_FIFOC_RX_SAMPLE_BITS),
502 0);
503
504 /* Fill most significant bits with valid data MSB */
505 regmap_field_update_bits(scodec->reg_adc_fifoc,
506 BIT(SUN4I_CODEC_ADC_FIFOC_RX_FIFO_MODE),
507 BIT(SUN4I_CODEC_ADC_FIFOC_RX_FIFO_MODE));
508
509 scodec->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
510 }
511
493 return 0; 512 return 0;
494} 513}
495 514
diff --git a/sound/soc/sunxi/sun8i-codec.c b/sound/soc/sunxi/sun8i-codec.c
index abfb710df7cb..3dd183be08a4 100644
--- a/sound/soc/sunxi/sun8i-codec.c
+++ b/sound/soc/sunxi/sun8i-codec.c
@@ -73,6 +73,7 @@
73#define SUN8I_SYS_SR_CTRL_AIF2_FS_MASK GENMASK(11, 8) 73#define SUN8I_SYS_SR_CTRL_AIF2_FS_MASK GENMASK(11, 8)
74#define SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ_MASK GENMASK(5, 4) 74#define SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ_MASK GENMASK(5, 4)
75#define SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV_MASK GENMASK(8, 6) 75#define SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV_MASK GENMASK(8, 6)
76#define SUN8I_AIF1CLK_CTRL_AIF1_BCLK_DIV_MASK GENMASK(12, 9)
76 77
77struct sun8i_codec { 78struct sun8i_codec {
78 struct device *dev; 79 struct device *dev;
@@ -170,11 +171,11 @@ static int sun8i_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
170 171
171 /* clock masters */ 172 /* clock masters */
172 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 173 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
173 case SND_SOC_DAIFMT_CBS_CFS: /* DAI Slave */ 174 case SND_SOC_DAIFMT_CBS_CFS: /* Codec slave, DAI master */
174 value = 0x0; /* Codec Master */ 175 value = 0x1;
175 break; 176 break;
176 case SND_SOC_DAIFMT_CBM_CFM: /* DAI Master */ 177 case SND_SOC_DAIFMT_CBM_CFM: /* Codec Master, DAI slave */
177 value = 0x1; /* Codec Slave */ 178 value = 0x0;
178 break; 179 break;
179 default: 180 default:
180 return -EINVAL; 181 return -EINVAL;
@@ -197,9 +198,20 @@ static int sun8i_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
197 regmap_update_bits(scodec->regmap, SUN8I_AIF1CLK_CTRL, 198 regmap_update_bits(scodec->regmap, SUN8I_AIF1CLK_CTRL,
198 BIT(SUN8I_AIF1CLK_CTRL_AIF1_BCLK_INV), 199 BIT(SUN8I_AIF1CLK_CTRL_AIF1_BCLK_INV),
199 value << SUN8I_AIF1CLK_CTRL_AIF1_BCLK_INV); 200 value << SUN8I_AIF1CLK_CTRL_AIF1_BCLK_INV);
201
202 /*
203 * It appears that the DAI and the codec don't share the same
204 * polarity for the LRCK signal when they mean 'normal' and
205 * 'inverted' in the datasheet.
206 *
207 * Since the DAI here is our regular i2s driver that have been
208 * tested with way more codecs than just this one, it means
209 * that the codec probably gets it backward, and we have to
210 * invert the value here.
211 */
200 regmap_update_bits(scodec->regmap, SUN8I_AIF1CLK_CTRL, 212 regmap_update_bits(scodec->regmap, SUN8I_AIF1CLK_CTRL,
201 BIT(SUN8I_AIF1CLK_CTRL_AIF1_LRCK_INV), 213 BIT(SUN8I_AIF1CLK_CTRL_AIF1_LRCK_INV),
202 value << SUN8I_AIF1CLK_CTRL_AIF1_LRCK_INV); 214 !value << SUN8I_AIF1CLK_CTRL_AIF1_LRCK_INV);
203 215
204 /* DAI format */ 216 /* DAI format */
205 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 217 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
@@ -226,12 +238,57 @@ static int sun8i_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
226 return 0; 238 return 0;
227} 239}
228 240
241struct sun8i_codec_clk_div {
242 u8 div;
243 u8 val;
244};
245
246static const struct sun8i_codec_clk_div sun8i_codec_bclk_div[] = {
247 { .div = 1, .val = 0 },
248 { .div = 2, .val = 1 },
249 { .div = 4, .val = 2 },
250 { .div = 6, .val = 3 },
251 { .div = 8, .val = 4 },
252 { .div = 12, .val = 5 },
253 { .div = 16, .val = 6 },
254 { .div = 24, .val = 7 },
255 { .div = 32, .val = 8 },
256 { .div = 48, .val = 9 },
257 { .div = 64, .val = 10 },
258 { .div = 96, .val = 11 },
259 { .div = 128, .val = 12 },
260 { .div = 192, .val = 13 },
261};
262
263static u8 sun8i_codec_get_bclk_div(struct sun8i_codec *scodec,
264 unsigned int rate,
265 unsigned int word_size)
266{
267 unsigned long clk_rate = clk_get_rate(scodec->clk_module);
268 unsigned int div = clk_rate / rate / word_size / 2;
269 unsigned int best_val = 0, best_diff = ~0;
270 int i;
271
272 for (i = 0; i < ARRAY_SIZE(sun8i_codec_bclk_div); i++) {
273 const struct sun8i_codec_clk_div *bdiv = &sun8i_codec_bclk_div[i];
274 unsigned int diff = abs(bdiv->div - div);
275
276 if (diff < best_diff) {
277 best_diff = diff;
278 best_val = bdiv->val;
279 }
280 }
281
282 return best_val;
283}
284
229static int sun8i_codec_hw_params(struct snd_pcm_substream *substream, 285static int sun8i_codec_hw_params(struct snd_pcm_substream *substream,
230 struct snd_pcm_hw_params *params, 286 struct snd_pcm_hw_params *params,
231 struct snd_soc_dai *dai) 287 struct snd_soc_dai *dai)
232{ 288{
233 struct sun8i_codec *scodec = snd_soc_codec_get_drvdata(dai->codec); 289 struct sun8i_codec *scodec = snd_soc_codec_get_drvdata(dai->codec);
234 int sample_rate; 290 int sample_rate;
291 u8 bclk_div;
235 292
236 /* 293 /*
237 * The CPU DAI handles only a sample of 16 bits. Configure the 294 * The CPU DAI handles only a sample of 16 bits. Configure the
@@ -241,6 +298,11 @@ static int sun8i_codec_hw_params(struct snd_pcm_substream *substream,
241 SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ_MASK, 298 SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ_MASK,
242 SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ_16); 299 SUN8I_AIF1CLK_CTRL_AIF1_WORD_SIZ_16);
243 300
301 bclk_div = sun8i_codec_get_bclk_div(scodec, params_rate(params), 16);
302 regmap_update_bits(scodec->regmap, SUN8I_AIF1CLK_CTRL,
303 SUN8I_AIF1CLK_CTRL_AIF1_BCLK_DIV_MASK,
304 bclk_div << SUN8I_AIF1CLK_CTRL_AIF1_BCLK_DIV);
305
244 regmap_update_bits(scodec->regmap, SUN8I_AIF1CLK_CTRL, 306 regmap_update_bits(scodec->regmap, SUN8I_AIF1CLK_CTRL,
245 SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV_MASK, 307 SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV_MASK,
246 SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV_16); 308 SUN8I_AIF1CLK_CTRL_AIF1_LRCK_DIV_16);
diff --git a/sound/soc/zte/zx-spdif.c b/sound/soc/zte/zx-spdif.c
index b143f9f682d2..17b6ce35037a 100644
--- a/sound/soc/zte/zx-spdif.c
+++ b/sound/soc/zte/zx-spdif.c
@@ -139,11 +139,11 @@ static int zx_spdif_hw_params(struct snd_pcm_substream *substream,
139{ 139{
140 struct zx_spdif_info *zx_spdif = dev_get_drvdata(socdai->dev); 140 struct zx_spdif_info *zx_spdif = dev_get_drvdata(socdai->dev);
141 struct zx_spdif_info *spdif = snd_soc_dai_get_drvdata(socdai); 141 struct zx_spdif_info *spdif = snd_soc_dai_get_drvdata(socdai);
142 struct snd_dmaengine_dai_dma_data *dma_data = &zx_spdif->dma_data; 142 struct snd_dmaengine_dai_dma_data *dma_data =
143 snd_soc_dai_get_dma_data(socdai, substream);
143 u32 val, ch_num, rate; 144 u32 val, ch_num, rate;
144 int ret; 145 int ret;
145 146
146 dma_data = snd_soc_dai_get_dma_data(socdai, substream);
147 dma_data->addr_width = params_width(params) >> 3; 147 dma_data->addr_width = params_width(params) >> 3;
148 148
149 val = readl_relaxed(zx_spdif->reg_base + ZX_CTRL); 149 val = readl_relaxed(zx_spdif->reg_base + ZX_CTRL);
diff --git a/sound/synth/emux/emux.c b/sound/synth/emux/emux.c
index b9981e8c0027..b840ff2dcfbb 100644
--- a/sound/synth/emux/emux.c
+++ b/sound/synth/emux/emux.c
@@ -53,7 +53,7 @@ int snd_emux_new(struct snd_emux **remu)
53 emu->max_voices = 0; 53 emu->max_voices = 0;
54 emu->use_time = 0; 54 emu->use_time = 0;
55 55
56 setup_timer(&emu->tlist, snd_emux_timer_callback, (unsigned long)emu); 56 timer_setup(&emu->tlist, snd_emux_timer_callback, 0);
57 emu->timer_active = 0; 57 emu->timer_active = 0;
58 58
59 *remu = emu; 59 *remu = emu;
diff --git a/sound/synth/emux/emux_oss.c b/sound/synth/emux/emux_oss.c
index de19e108974a..764ff4bc2089 100644
--- a/sound/synth/emux/emux_oss.c
+++ b/sound/synth/emux/emux_oss.c
@@ -430,7 +430,6 @@ gusspec_control(struct snd_emux *emu, struct snd_emux_port *port, int cmd,
430{ 430{
431 int voice; 431 int voice;
432 unsigned short p1; 432 unsigned short p1;
433 short p2;
434 int plong; 433 int plong;
435 struct snd_midi_channel *chan; 434 struct snd_midi_channel *chan;
436 435
@@ -445,7 +444,6 @@ gusspec_control(struct snd_emux *emu, struct snd_emux_port *port, int cmd,
445 chan = &port->chset.channels[voice]; 444 chan = &port->chset.channels[voice];
446 445
447 p1 = *(unsigned short *) &event[4]; 446 p1 = *(unsigned short *) &event[4];
448 p2 = *(short *) &event[6];
449 plong = *(int*) &event[4]; 447 plong = *(int*) &event[4];
450 448
451 switch (cmd) { 449 switch (cmd) {
diff --git a/sound/synth/emux/emux_synth.c b/sound/synth/emux/emux_synth.c
index 599551b5af44..9fa696b0dbde 100644
--- a/sound/synth/emux/emux_synth.c
+++ b/sound/synth/emux/emux_synth.c
@@ -202,9 +202,9 @@ snd_emux_note_off(void *p, int note, int vel, struct snd_midi_channel *chan)
202 * 202 *
203 * release the pending note-offs 203 * release the pending note-offs
204 */ 204 */
205void snd_emux_timer_callback(unsigned long data) 205void snd_emux_timer_callback(struct timer_list *t)
206{ 206{
207 struct snd_emux *emu = (struct snd_emux *) data; 207 struct snd_emux *emu = from_timer(emu, t, tlist);
208 struct snd_emux_voice *vp; 208 struct snd_emux_voice *vp;
209 unsigned long flags; 209 unsigned long flags;
210 int ch, do_again = 0; 210 int ch, do_again = 0;
diff --git a/sound/synth/emux/emux_voice.h b/sound/synth/emux/emux_voice.h
index a7073c371bcc..326fa8993d7b 100644
--- a/sound/synth/emux/emux_voice.h
+++ b/sound/synth/emux/emux_voice.h
@@ -55,7 +55,7 @@ void snd_emux_update_channel(struct snd_emux_port *port,
55 struct snd_midi_channel *chan, int update); 55 struct snd_midi_channel *chan, int update);
56void snd_emux_update_port(struct snd_emux_port *port, int update); 56void snd_emux_update_port(struct snd_emux_port *port, int update);
57 57
58void snd_emux_timer_callback(unsigned long data); 58void snd_emux_timer_callback(struct timer_list *t);
59 59
60/* emux_effect.c */ 60/* emux_effect.c */
61#ifdef SNDRV_EMUX_USE_RAW_EFFECT 61#ifdef SNDRV_EMUX_USE_RAW_EFFECT
diff --git a/sound/usb/6fire/chip.c b/sound/usb/6fire/chip.c
index c7641cb50616..17d5e3ee6d73 100644
--- a/sound/usb/6fire/chip.c
+++ b/sound/usb/6fire/chip.c
@@ -174,11 +174,9 @@ destroy_chip:
174static void usb6fire_chip_disconnect(struct usb_interface *intf) 174static void usb6fire_chip_disconnect(struct usb_interface *intf)
175{ 175{
176 struct sfire_chip *chip; 176 struct sfire_chip *chip;
177 struct snd_card *card;
178 177
179 chip = usb_get_intfdata(intf); 178 chip = usb_get_intfdata(intf);
180 if (chip) { /* if !chip, fw upload has been performed */ 179 if (chip) { /* if !chip, fw upload has been performed */
181 card = chip->card;
182 chip->intf_count--; 180 chip->intf_count--;
183 if (!chip->intf_count) { 181 if (!chip->intf_count) {
184 mutex_lock(&register_mutex); 182 mutex_lock(&register_mutex);
diff --git a/sound/usb/bcd2000/bcd2000.c b/sound/usb/bcd2000/bcd2000.c
index fc579f330601..d6c8b29fe430 100644
--- a/sound/usb/bcd2000/bcd2000.c
+++ b/sound/usb/bcd2000/bcd2000.c
@@ -342,6 +342,13 @@ static int bcd2000_init_midi(struct bcd2000 *bcd2k)
342 bcd2k->midi_out_buf, BUFSIZE, 342 bcd2k->midi_out_buf, BUFSIZE,
343 bcd2000_output_complete, bcd2k, 1); 343 bcd2000_output_complete, bcd2k, 1);
344 344
345 /* sanity checks of EPs before actually submitting */
346 if (usb_urb_ep_type_check(bcd2k->midi_in_urb) ||
347 usb_urb_ep_type_check(bcd2k->midi_out_urb)) {
348 dev_err(&bcd2k->dev->dev, "invalid MIDI EP\n");
349 return -EINVAL;
350 }
351
345 bcd2000_init_device(bcd2k); 352 bcd2000_init_device(bcd2k);
346 353
347 return 0; 354 return 0;
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index d8409d9ae55b..d55ca48de3ea 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -461,6 +461,13 @@ static int init_card(struct snd_usb_caiaqdev *cdev)
461 cdev->midi_out_buf, EP1_BUFSIZE, 461 cdev->midi_out_buf, EP1_BUFSIZE,
462 snd_usb_caiaq_midi_output_done, cdev); 462 snd_usb_caiaq_midi_output_done, cdev);
463 463
464 /* sanity checks of EPs before actually submitting */
465 if (usb_urb_ep_type_check(&cdev->ep1_in_urb) ||
466 usb_urb_ep_type_check(&cdev->midi_out_urb)) {
467 dev_err(dev, "invalid EPs\n");
468 return -EINVAL;
469 }
470
464 init_waitqueue_head(&cdev->ep1_wait_queue); 471 init_waitqueue_head(&cdev->ep1_wait_queue);
465 init_waitqueue_head(&cdev->prepare_wait_queue); 472 init_waitqueue_head(&cdev->prepare_wait_queue);
466 473
diff --git a/sound/usb/caiaq/input.c b/sound/usb/caiaq/input.c
index 4b3fb91deecd..e883659ea6e7 100644
--- a/sound/usb/caiaq/input.c
+++ b/sound/usb/caiaq/input.c
@@ -718,6 +718,9 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *cdev)
718 usb_rcvbulkpipe(usb_dev, 0x4), 718 usb_rcvbulkpipe(usb_dev, 0x4),
719 cdev->ep4_in_buf, EP4_BUFSIZE, 719 cdev->ep4_in_buf, EP4_BUFSIZE,
720 snd_usb_caiaq_ep4_reply_dispatch, cdev); 720 snd_usb_caiaq_ep4_reply_dispatch, cdev);
721 ret = usb_urb_ep_type_check(cdev->ep4_in_urb);
722 if (ret < 0)
723 goto exit_free_idev;
721 724
722 snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 5); 725 snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 5);
723 726
@@ -757,6 +760,9 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *cdev)
757 usb_rcvbulkpipe(usb_dev, 0x4), 760 usb_rcvbulkpipe(usb_dev, 0x4),
758 cdev->ep4_in_buf, EP4_BUFSIZE, 761 cdev->ep4_in_buf, EP4_BUFSIZE,
759 snd_usb_caiaq_ep4_reply_dispatch, cdev); 762 snd_usb_caiaq_ep4_reply_dispatch, cdev);
763 ret = usb_urb_ep_type_check(cdev->ep4_in_urb);
764 if (ret < 0)
765 goto exit_free_idev;
760 766
761 snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 5); 767 snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 5);
762 768
@@ -802,6 +808,9 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *cdev)
802 usb_rcvbulkpipe(usb_dev, 0x4), 808 usb_rcvbulkpipe(usb_dev, 0x4),
803 cdev->ep4_in_buf, EP4_BUFSIZE, 809 cdev->ep4_in_buf, EP4_BUFSIZE,
804 snd_usb_caiaq_ep4_reply_dispatch, cdev); 810 snd_usb_caiaq_ep4_reply_dispatch, cdev);
811 ret = usb_urb_ep_type_check(cdev->ep4_in_urb);
812 if (ret < 0)
813 goto exit_free_idev;
805 814
806 snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 5); 815 snd_usb_caiaq_set_auto_msg(cdev, 1, 10, 5);
807 break; 816 break;
diff --git a/sound/usb/hiface/pcm.c b/sound/usb/hiface/pcm.c
index 175d8d6b7f59..396c317115b1 100644
--- a/sound/usb/hiface/pcm.c
+++ b/sound/usb/hiface/pcm.c
@@ -541,6 +541,8 @@ static int hiface_pcm_init_urb(struct pcm_urb *urb,
541 usb_fill_bulk_urb(&urb->instance, chip->dev, 541 usb_fill_bulk_urb(&urb->instance, chip->dev,
542 usb_sndbulkpipe(chip->dev, ep), (void *)urb->buffer, 542 usb_sndbulkpipe(chip->dev, ep), (void *)urb->buffer,
543 PCM_PACKET_SIZE, handler, urb); 543 PCM_PACKET_SIZE, handler, urb);
544 if (usb_urb_ep_type_check(&urb->instance))
545 return -EINVAL;
544 init_usb_anchor(&urb->submitted); 546 init_usb_anchor(&urb->submitted);
545 547
546 return 0; 548 return 0;
@@ -599,9 +601,12 @@ int hiface_pcm_init(struct hiface_chip *chip, u8 extra_freq)
599 mutex_init(&rt->stream_mutex); 601 mutex_init(&rt->stream_mutex);
600 spin_lock_init(&rt->playback.lock); 602 spin_lock_init(&rt->playback.lock);
601 603
602 for (i = 0; i < PCM_N_URBS; i++) 604 for (i = 0; i < PCM_N_URBS; i++) {
603 hiface_pcm_init_urb(&rt->out_urbs[i], chip, OUT_EP, 605 ret = hiface_pcm_init_urb(&rt->out_urbs[i], chip, OUT_EP,
604 hiface_pcm_out_urb_handler); 606 hiface_pcm_out_urb_handler);
607 if (ret < 0)
608 return ret;
609 }
605 610
606 ret = snd_pcm_new(chip->card, "USB-SPDIF Audio", 0, 1, 0, &pcm); 611 ret = snd_pcm_new(chip->card, "USB-SPDIF Audio", 0, 1, 0, &pcm);
607 if (ret < 0) { 612 if (ret < 0) {
diff --git a/sound/usb/line6/capture.c b/sound/usb/line6/capture.c
index 7c812565f90d..947d6168f24a 100644
--- a/sound/usb/line6/capture.c
+++ b/sound/usb/line6/capture.c
@@ -248,7 +248,7 @@ static int snd_line6_capture_close(struct snd_pcm_substream *substream)
248} 248}
249 249
250/* capture operators */ 250/* capture operators */
251struct snd_pcm_ops snd_line6_capture_ops = { 251const struct snd_pcm_ops snd_line6_capture_ops = {
252 .open = snd_line6_capture_open, 252 .open = snd_line6_capture_open,
253 .close = snd_line6_capture_close, 253 .close = snd_line6_capture_close,
254 .ioctl = snd_pcm_lib_ioctl, 254 .ioctl = snd_pcm_lib_ioctl,
diff --git a/sound/usb/line6/capture.h b/sound/usb/line6/capture.h
index 890b21bff18c..b67ccc39fd25 100644
--- a/sound/usb/line6/capture.h
+++ b/sound/usb/line6/capture.h
@@ -17,7 +17,7 @@
17#include "driver.h" 17#include "driver.h"
18#include "pcm.h" 18#include "pcm.h"
19 19
20extern struct snd_pcm_ops snd_line6_capture_ops; 20extern const struct snd_pcm_ops snd_line6_capture_ops;
21 21
22extern void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf, 22extern void line6_capture_copy(struct snd_line6_pcm *line6pcm, char *fbuf,
23 int fsize); 23 int fsize);
diff --git a/sound/usb/line6/driver.c b/sound/usb/line6/driver.c
index c8f723c3a033..4f9613e5fc9e 100644
--- a/sound/usb/line6/driver.c
+++ b/sound/usb/line6/driver.c
@@ -78,6 +78,13 @@ static int line6_start_listen(struct usb_line6 *line6)
78 line6->buffer_listen, LINE6_BUFSIZE_LISTEN, 78 line6->buffer_listen, LINE6_BUFSIZE_LISTEN,
79 line6_data_received, line6); 79 line6_data_received, line6);
80 } 80 }
81
82 /* sanity checks of EP before actually submitting */
83 if (usb_urb_ep_type_check(line6->urb_listen)) {
84 dev_err(line6->ifcdev, "invalid control EP\n");
85 return -EINVAL;
86 }
87
81 line6->urb_listen->actual_length = 0; 88 line6->urb_listen->actual_length = 0;
82 err = usb_submit_urb(line6->urb_listen, GFP_ATOMIC); 89 err = usb_submit_urb(line6->urb_listen, GFP_ATOMIC);
83 return err; 90 return err;
@@ -168,26 +175,33 @@ static int line6_send_raw_message_async_part(struct message *msg,
168 } 175 }
169 176
170 msg->done += bytes; 177 msg->done += bytes;
171 retval = usb_submit_urb(urb, GFP_ATOMIC);
172 178
173 if (retval < 0) { 179 /* sanity checks of EP before actually submitting */
174 dev_err(line6->ifcdev, "%s: usb_submit_urb failed (%d)\n", 180 retval = usb_urb_ep_type_check(urb);
175 __func__, retval); 181 if (retval < 0)
176 usb_free_urb(urb); 182 goto error;
177 kfree(msg); 183
178 return retval; 184 retval = usb_submit_urb(urb, GFP_ATOMIC);
179 } 185 if (retval < 0)
186 goto error;
180 187
181 return 0; 188 return 0;
189
190 error:
191 dev_err(line6->ifcdev, "%s: usb_submit_urb failed (%d)\n",
192 __func__, retval);
193 usb_free_urb(urb);
194 kfree(msg);
195 return retval;
182} 196}
183 197
184/* 198/*
185 Setup and start timer. 199 Setup and start timer.
186*/ 200*/
187void line6_start_timer(struct timer_list *timer, unsigned long msecs, 201void line6_start_timer(struct timer_list *timer, unsigned long msecs,
188 void (*function)(unsigned long), unsigned long data) 202 void (*function)(struct timer_list *t))
189{ 203{
190 setup_timer(timer, function, data); 204 timer->function = (TIMER_FUNC_TYPE)function;
191 mod_timer(timer, jiffies + msecs_to_jiffies(msecs)); 205 mod_timer(timer, jiffies + msecs_to_jiffies(msecs));
192} 206}
193EXPORT_SYMBOL_GPL(line6_start_timer); 207EXPORT_SYMBOL_GPL(line6_start_timer);
diff --git a/sound/usb/line6/driver.h b/sound/usb/line6/driver.h
index dc97895547be..61425597eb61 100644
--- a/sound/usb/line6/driver.h
+++ b/sound/usb/line6/driver.h
@@ -198,8 +198,7 @@ extern int line6_send_sysex_message(struct usb_line6 *line6,
198extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr, 198extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr,
199 const char *buf, size_t count); 199 const char *buf, size_t count);
200extern void line6_start_timer(struct timer_list *timer, unsigned long msecs, 200extern void line6_start_timer(struct timer_list *timer, unsigned long msecs,
201 void (*function)(unsigned long), 201 void (*function)(struct timer_list *t));
202 unsigned long data);
203extern int line6_version_request_async(struct usb_line6 *line6); 202extern int line6_version_request_async(struct usb_line6 *line6);
204extern int line6_write_data(struct usb_line6 *line6, unsigned address, 203extern int line6_write_data(struct usb_line6 *line6, unsigned address,
205 void *data, unsigned datalen); 204 void *data, unsigned datalen);
diff --git a/sound/usb/line6/midi.c b/sound/usb/line6/midi.c
index 1d3a23b02d68..6d7cde56a355 100644
--- a/sound/usb/line6/midi.c
+++ b/sound/usb/line6/midi.c
@@ -130,16 +130,21 @@ static int send_midi_async(struct usb_line6 *line6, unsigned char *data,
130 transfer_buffer, length, midi_sent, line6, 130 transfer_buffer, length, midi_sent, line6,
131 line6->interval); 131 line6->interval);
132 urb->actual_length = 0; 132 urb->actual_length = 0;
133 retval = usb_submit_urb(urb, GFP_ATOMIC); 133 retval = usb_urb_ep_type_check(urb);
134 if (retval < 0)
135 goto error;
134 136
135 if (retval < 0) { 137 retval = usb_submit_urb(urb, GFP_ATOMIC);
136 dev_err(line6->ifcdev, "usb_submit_urb failed\n"); 138 if (retval < 0)
137 usb_free_urb(urb); 139 goto error;
138 return retval;
139 }
140 140
141 ++line6->line6midi->num_active_send_urbs; 141 ++line6->line6midi->num_active_send_urbs;
142 return 0; 142 return 0;
143
144 error:
145 dev_err(line6->ifcdev, "usb_submit_urb failed\n");
146 usb_free_urb(urb);
147 return retval;
143} 148}
144 149
145static int line6_midi_output_open(struct snd_rawmidi_substream *substream) 150static int line6_midi_output_open(struct snd_rawmidi_substream *substream)
diff --git a/sound/usb/line6/playback.c b/sound/usb/line6/playback.c
index 812d18191e01..819e9b2d1d6e 100644
--- a/sound/usb/line6/playback.c
+++ b/sound/usb/line6/playback.c
@@ -393,7 +393,7 @@ static int snd_line6_playback_close(struct snd_pcm_substream *substream)
393} 393}
394 394
395/* playback operators */ 395/* playback operators */
396struct snd_pcm_ops snd_line6_playback_ops = { 396const struct snd_pcm_ops snd_line6_playback_ops = {
397 .open = snd_line6_playback_open, 397 .open = snd_line6_playback_open,
398 .close = snd_line6_playback_close, 398 .close = snd_line6_playback_close,
399 .ioctl = snd_pcm_lib_ioctl, 399 .ioctl = snd_pcm_lib_ioctl,
diff --git a/sound/usb/line6/playback.h b/sound/usb/line6/playback.h
index 51fce29e8726..d8d3b8a07a72 100644
--- a/sound/usb/line6/playback.h
+++ b/sound/usb/line6/playback.h
@@ -27,7 +27,7 @@
27 */ 27 */
28#define USE_CLEAR_BUFFER_WORKAROUND 1 28#define USE_CLEAR_BUFFER_WORKAROUND 1
29 29
30extern struct snd_pcm_ops snd_line6_playback_ops; 30extern const struct snd_pcm_ops snd_line6_playback_ops;
31 31
32extern int line6_create_audio_out_urbs(struct snd_line6_pcm *line6pcm); 32extern int line6_create_audio_out_urbs(struct snd_line6_pcm *line6pcm);
33extern int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm); 33extern int line6_submit_audio_out_all_urbs(struct snd_line6_pcm *line6pcm);
diff --git a/sound/usb/line6/pod.c b/sound/usb/line6/pod.c
index 358224cc5638..020c81818951 100644
--- a/sound/usb/line6/pod.c
+++ b/sound/usb/line6/pod.c
@@ -174,7 +174,7 @@ static const char pod_version_header[] = {
174}; 174};
175 175
176/* forward declarations: */ 176/* forward declarations: */
177static void pod_startup2(unsigned long data); 177static void pod_startup2(struct timer_list *t);
178static void pod_startup3(struct usb_line6_pod *pod); 178static void pod_startup3(struct usb_line6_pod *pod);
179 179
180static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code, 180static char *pod_alloc_sysex_buffer(struct usb_line6_pod *pod, int code,
@@ -286,13 +286,12 @@ static void pod_startup1(struct usb_line6_pod *pod)
286 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_INIT); 286 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_INIT);
287 287
288 /* delay startup procedure: */ 288 /* delay startup procedure: */
289 line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2, 289 line6_start_timer(&pod->startup_timer, POD_STARTUP_DELAY, pod_startup2);
290 (unsigned long)pod);
291} 290}
292 291
293static void pod_startup2(unsigned long data) 292static void pod_startup2(struct timer_list *t)
294{ 293{
295 struct usb_line6_pod *pod = (struct usb_line6_pod *)data; 294 struct usb_line6_pod *pod = from_timer(pod, t, startup_timer);
296 struct usb_line6 *line6 = &pod->line6; 295 struct usb_line6 *line6 = &pod->line6;
297 296
298 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_VERSIONREQ); 297 CHECK_STARTUP_PROGRESS(pod->startup_progress, POD_STARTUP_VERSIONREQ);
@@ -413,7 +412,7 @@ static int pod_init(struct usb_line6 *line6,
413 line6->process_message = line6_pod_process_message; 412 line6->process_message = line6_pod_process_message;
414 line6->disconnect = line6_pod_disconnect; 413 line6->disconnect = line6_pod_disconnect;
415 414
416 init_timer(&pod->startup_timer); 415 timer_setup(&pod->startup_timer, NULL, 0);
417 INIT_WORK(&pod->startup_work, pod_startup4); 416 INIT_WORK(&pod->startup_work, pod_startup4);
418 417
419 /* create sysfs entries: */ 418 /* create sysfs entries: */
diff --git a/sound/usb/line6/podhd.c b/sound/usb/line6/podhd.c
index 451007c27743..36ed9c85c0eb 100644
--- a/sound/usb/line6/podhd.c
+++ b/sound/usb/line6/podhd.c
@@ -39,7 +39,8 @@ enum {
39 LINE6_PODHD500_1, 39 LINE6_PODHD500_1,
40 LINE6_PODX3, 40 LINE6_PODX3,
41 LINE6_PODX3LIVE, 41 LINE6_PODX3LIVE,
42 LINE6_PODHD500X 42 LINE6_PODHD500X,
43 LINE6_PODHDDESKTOP
43}; 44};
44 45
45struct usb_line6_podhd { 46struct usb_line6_podhd {
@@ -157,7 +158,7 @@ static struct line6_pcm_properties podx3_pcm_properties = {
157}; 158};
158static struct usb_driver podhd_driver; 159static struct usb_driver podhd_driver;
159 160
160static void podhd_startup_start_workqueue(unsigned long data); 161static void podhd_startup_start_workqueue(struct timer_list *t);
161static void podhd_startup_workqueue(struct work_struct *work); 162static void podhd_startup_workqueue(struct work_struct *work);
162static int podhd_startup_finalize(struct usb_line6_podhd *pod); 163static int podhd_startup_finalize(struct usb_line6_podhd *pod);
163 164
@@ -207,12 +208,12 @@ static void podhd_startup(struct usb_line6_podhd *pod)
207 208
208 /* delay startup procedure: */ 209 /* delay startup procedure: */
209 line6_start_timer(&pod->startup_timer, PODHD_STARTUP_DELAY, 210 line6_start_timer(&pod->startup_timer, PODHD_STARTUP_DELAY,
210 podhd_startup_start_workqueue, (unsigned long)pod); 211 podhd_startup_start_workqueue);
211} 212}
212 213
213static void podhd_startup_start_workqueue(unsigned long data) 214static void podhd_startup_start_workqueue(struct timer_list *t)
214{ 215{
215 struct usb_line6_podhd *pod = (struct usb_line6_podhd *)data; 216 struct usb_line6_podhd *pod = from_timer(pod, t, startup_timer);
216 217
217 CHECK_STARTUP_PROGRESS(pod->startup_progress, 218 CHECK_STARTUP_PROGRESS(pod->startup_progress,
218 PODHD_STARTUP_SCHEDULE_WORKQUEUE); 219 PODHD_STARTUP_SCHEDULE_WORKQUEUE);
@@ -318,7 +319,7 @@ static int podhd_init(struct usb_line6 *line6,
318 319
319 line6->disconnect = podhd_disconnect; 320 line6->disconnect = podhd_disconnect;
320 321
321 init_timer(&pod->startup_timer); 322 timer_setup(&pod->startup_timer, NULL, 0);
322 INIT_WORK(&pod->startup_work, podhd_startup_workqueue); 323 INIT_WORK(&pod->startup_work, podhd_startup_workqueue);
323 324
324 if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL) { 325 if (pod->line6.properties->capabilities & LINE6_CAP_CONTROL) {
@@ -379,6 +380,7 @@ static const struct usb_device_id podhd_id_table[] = {
379 { LINE6_IF_NUM(0x414A, 0), .driver_info = LINE6_PODX3 }, 380 { LINE6_IF_NUM(0x414A, 0), .driver_info = LINE6_PODX3 },
380 { LINE6_IF_NUM(0x414B, 0), .driver_info = LINE6_PODX3LIVE }, 381 { LINE6_IF_NUM(0x414B, 0), .driver_info = LINE6_PODX3LIVE },
381 { LINE6_IF_NUM(0x4159, 0), .driver_info = LINE6_PODHD500X }, 382 { LINE6_IF_NUM(0x4159, 0), .driver_info = LINE6_PODHD500X },
383 { LINE6_IF_NUM(0x4156, 0), .driver_info = LINE6_PODHDDESKTOP },
382 {} 384 {}
383}; 385};
384 386
@@ -465,6 +467,18 @@ static const struct line6_properties podhd_properties_table[] = {
465 .ep_audio_r = 0x86, 467 .ep_audio_r = 0x86,
466 .ep_audio_w = 0x02, 468 .ep_audio_w = 0x02,
467 }, 469 },
470 [LINE6_PODHDDESKTOP] = {
471 .id = "PODHDDESKTOP",
472 .name = "POD HDDESKTOP",
473 .capabilities = LINE6_CAP_CONTROL
474 | LINE6_CAP_PCM | LINE6_CAP_HWMON,
475 .altsetting = 1,
476 .ep_ctrl_r = 0x81,
477 .ep_ctrl_w = 0x01,
478 .ctrl_if = 1,
479 .ep_audio_r = 0x86,
480 .ep_audio_w = 0x02,
481 },
468}; 482};
469 483
470/* 484/*
diff --git a/sound/usb/line6/toneport.c b/sound/usb/line6/toneport.c
index ba7975c0d03d..750467fb95db 100644
--- a/sound/usb/line6/toneport.c
+++ b/sound/usb/line6/toneport.c
@@ -241,9 +241,9 @@ static int snd_toneport_source_put(struct snd_kcontrol *kcontrol,
241 return 1; 241 return 1;
242} 242}
243 243
244static void toneport_start_pcm(unsigned long arg) 244static void toneport_start_pcm(struct timer_list *t)
245{ 245{
246 struct usb_line6_toneport *toneport = (struct usb_line6_toneport *)arg; 246 struct usb_line6_toneport *toneport = from_timer(toneport, t, timer);
247 struct usb_line6 *line6 = &toneport->line6; 247 struct usb_line6 *line6 = &toneport->line6;
248 248
249 line6_pcm_acquire(line6->line6pcm, LINE6_STREAM_MONITOR, true); 249 line6_pcm_acquire(line6->line6pcm, LINE6_STREAM_MONITOR, true);
@@ -415,8 +415,7 @@ static int toneport_init(struct usb_line6 *line6,
415 struct usb_line6_toneport *toneport = (struct usb_line6_toneport *) line6; 415 struct usb_line6_toneport *toneport = (struct usb_line6_toneport *) line6;
416 416
417 toneport->type = id->driver_info; 417 toneport->type = id->driver_info;
418 setup_timer(&toneport->timer, toneport_start_pcm, 418 timer_setup(&toneport->timer, toneport_start_pcm, 0);
419 (unsigned long)toneport);
420 419
421 line6->disconnect = line6_toneport_disconnect; 420 line6->disconnect = line6_toneport_disconnect;
422 421
diff --git a/sound/usb/line6/variax.c b/sound/usb/line6/variax.c
index 0c4512d0382e..e8c852b2ce35 100644
--- a/sound/usb/line6/variax.c
+++ b/sound/usb/line6/variax.c
@@ -82,9 +82,9 @@ static const char variax_activate[] = {
82}; 82};
83 83
84/* forward declarations: */ 84/* forward declarations: */
85static void variax_startup2(unsigned long data); 85static void variax_startup2(struct timer_list *t);
86static void variax_startup4(unsigned long data); 86static void variax_startup4(struct timer_list *t);
87static void variax_startup5(unsigned long data); 87static void variax_startup5(struct timer_list *t);
88 88
89static void variax_activate_async(struct usb_line6_variax *variax, int a) 89static void variax_activate_async(struct usb_line6_variax *variax, int a)
90{ 90{
@@ -106,12 +106,12 @@ static void variax_startup1(struct usb_line6_variax *variax)
106 106
107 /* delay startup procedure: */ 107 /* delay startup procedure: */
108 line6_start_timer(&variax->startup_timer1, VARIAX_STARTUP_DELAY1, 108 line6_start_timer(&variax->startup_timer1, VARIAX_STARTUP_DELAY1,
109 variax_startup2, (unsigned long)variax); 109 variax_startup2);
110} 110}
111 111
112static void variax_startup2(unsigned long data) 112static void variax_startup2(struct timer_list *t)
113{ 113{
114 struct usb_line6_variax *variax = (struct usb_line6_variax *)data; 114 struct usb_line6_variax *variax = from_timer(variax, t, startup_timer1);
115 struct usb_line6 *line6 = &variax->line6; 115 struct usb_line6 *line6 = &variax->line6;
116 116
117 /* schedule another startup procedure until startup is complete: */ 117 /* schedule another startup procedure until startup is complete: */
@@ -120,7 +120,7 @@ static void variax_startup2(unsigned long data)
120 120
121 variax->startup_progress = VARIAX_STARTUP_VERSIONREQ; 121 variax->startup_progress = VARIAX_STARTUP_VERSIONREQ;
122 line6_start_timer(&variax->startup_timer1, VARIAX_STARTUP_DELAY1, 122 line6_start_timer(&variax->startup_timer1, VARIAX_STARTUP_DELAY1,
123 variax_startup2, (unsigned long)variax); 123 variax_startup2);
124 124
125 /* request firmware version: */ 125 /* request firmware version: */
126 line6_version_request_async(line6); 126 line6_version_request_async(line6);
@@ -132,12 +132,12 @@ static void variax_startup3(struct usb_line6_variax *variax)
132 132
133 /* delay startup procedure: */ 133 /* delay startup procedure: */
134 line6_start_timer(&variax->startup_timer2, VARIAX_STARTUP_DELAY3, 134 line6_start_timer(&variax->startup_timer2, VARIAX_STARTUP_DELAY3,
135 variax_startup4, (unsigned long)variax); 135 variax_startup4);
136} 136}
137 137
138static void variax_startup4(unsigned long data) 138static void variax_startup4(struct timer_list *t)
139{ 139{
140 struct usb_line6_variax *variax = (struct usb_line6_variax *)data; 140 struct usb_line6_variax *variax = from_timer(variax, t, startup_timer2);
141 141
142 CHECK_STARTUP_PROGRESS(variax->startup_progress, 142 CHECK_STARTUP_PROGRESS(variax->startup_progress,
143 VARIAX_STARTUP_ACTIVATE); 143 VARIAX_STARTUP_ACTIVATE);
@@ -145,12 +145,12 @@ static void variax_startup4(unsigned long data)
145 /* activate device: */ 145 /* activate device: */
146 variax_activate_async(variax, 1); 146 variax_activate_async(variax, 1);
147 line6_start_timer(&variax->startup_timer2, VARIAX_STARTUP_DELAY4, 147 line6_start_timer(&variax->startup_timer2, VARIAX_STARTUP_DELAY4,
148 variax_startup5, (unsigned long)variax); 148 variax_startup5);
149} 149}
150 150
151static void variax_startup5(unsigned long data) 151static void variax_startup5(struct timer_list *t)
152{ 152{
153 struct usb_line6_variax *variax = (struct usb_line6_variax *)data; 153 struct usb_line6_variax *variax = from_timer(variax, t, startup_timer2);
154 154
155 CHECK_STARTUP_PROGRESS(variax->startup_progress, 155 CHECK_STARTUP_PROGRESS(variax->startup_progress,
156 VARIAX_STARTUP_WORKQUEUE); 156 VARIAX_STARTUP_WORKQUEUE);
@@ -190,7 +190,7 @@ static void line6_variax_process_message(struct usb_line6 *line6)
190 } else if (memcmp(buf + 1, variax_init_done + 1, 190 } else if (memcmp(buf + 1, variax_init_done + 1,
191 sizeof(variax_init_done) - 1) == 0) { 191 sizeof(variax_init_done) - 1) == 0) {
192 /* notify of complete initialization: */ 192 /* notify of complete initialization: */
193 variax_startup4((unsigned long)variax); 193 variax_startup4(&variax->startup_timer2);
194 } 194 }
195 break; 195 break;
196 } 196 }
@@ -222,8 +222,8 @@ static int variax_init(struct usb_line6 *line6,
222 line6->process_message = line6_variax_process_message; 222 line6->process_message = line6_variax_process_message;
223 line6->disconnect = line6_variax_disconnect; 223 line6->disconnect = line6_variax_disconnect;
224 224
225 init_timer(&variax->startup_timer1); 225 timer_setup(&variax->startup_timer1, NULL, 0);
226 init_timer(&variax->startup_timer2); 226 timer_setup(&variax->startup_timer2, NULL, 0);
227 INIT_WORK(&variax->startup_work, variax_startup6); 227 INIT_WORK(&variax->startup_work, variax_startup6);
228 228
229 /* initialize USB buffers: */ 229 /* initialize USB buffers: */
diff --git a/sound/usb/midi.c b/sound/usb/midi.c
index a92e2b2a91ec..2c1aaa3292bf 100644
--- a/sound/usb/midi.c
+++ b/sound/usb/midi.c
@@ -352,9 +352,9 @@ static void snd_usbmidi_out_tasklet(unsigned long data)
352} 352}
353 353
354/* called after transfers had been interrupted due to some USB error */ 354/* called after transfers had been interrupted due to some USB error */
355static void snd_usbmidi_error_timer(unsigned long data) 355static void snd_usbmidi_error_timer(struct timer_list *t)
356{ 356{
357 struct snd_usb_midi *umidi = (struct snd_usb_midi *)data; 357 struct snd_usb_midi *umidi = from_timer(umidi, t, error_timer);
358 unsigned int i, j; 358 unsigned int i, j;
359 359
360 spin_lock(&umidi->disc_lock); 360 spin_lock(&umidi->disc_lock);
@@ -1282,6 +1282,7 @@ static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi *umidi,
1282 unsigned int pipe; 1282 unsigned int pipe;
1283 int length; 1283 int length;
1284 unsigned int i; 1284 unsigned int i;
1285 int err;
1285 1286
1286 rep->in = NULL; 1287 rep->in = NULL;
1287 ep = kzalloc(sizeof(*ep), GFP_KERNEL); 1288 ep = kzalloc(sizeof(*ep), GFP_KERNEL);
@@ -1292,8 +1293,8 @@ static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi *umidi,
1292 for (i = 0; i < INPUT_URBS; ++i) { 1293 for (i = 0; i < INPUT_URBS; ++i) {
1293 ep->urbs[i] = usb_alloc_urb(0, GFP_KERNEL); 1294 ep->urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1294 if (!ep->urbs[i]) { 1295 if (!ep->urbs[i]) {
1295 snd_usbmidi_in_endpoint_delete(ep); 1296 err = -ENOMEM;
1296 return -ENOMEM; 1297 goto error;
1297 } 1298 }
1298 } 1299 }
1299 if (ep_info->in_interval) 1300 if (ep_info->in_interval)
@@ -1305,8 +1306,8 @@ static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi *umidi,
1305 buffer = usb_alloc_coherent(umidi->dev, length, GFP_KERNEL, 1306 buffer = usb_alloc_coherent(umidi->dev, length, GFP_KERNEL,
1306 &ep->urbs[i]->transfer_dma); 1307 &ep->urbs[i]->transfer_dma);
1307 if (!buffer) { 1308 if (!buffer) {
1308 snd_usbmidi_in_endpoint_delete(ep); 1309 err = -ENOMEM;
1309 return -ENOMEM; 1310 goto error;
1310 } 1311 }
1311 if (ep_info->in_interval) 1312 if (ep_info->in_interval)
1312 usb_fill_int_urb(ep->urbs[i], umidi->dev, 1313 usb_fill_int_urb(ep->urbs[i], umidi->dev,
@@ -1318,10 +1319,20 @@ static int snd_usbmidi_in_endpoint_create(struct snd_usb_midi *umidi,
1318 pipe, buffer, length, 1319 pipe, buffer, length,
1319 snd_usbmidi_in_urb_complete, ep); 1320 snd_usbmidi_in_urb_complete, ep);
1320 ep->urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 1321 ep->urbs[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
1322 err = usb_urb_ep_type_check(ep->urbs[i]);
1323 if (err < 0) {
1324 dev_err(&umidi->dev->dev, "invalid MIDI in EP %x\n",
1325 ep_info->in_ep);
1326 goto error;
1327 }
1321 } 1328 }
1322 1329
1323 rep->in = ep; 1330 rep->in = ep;
1324 return 0; 1331 return 0;
1332
1333 error:
1334 snd_usbmidi_in_endpoint_delete(ep);
1335 return -ENOMEM;
1325} 1336}
1326 1337
1327/* 1338/*
@@ -1357,6 +1368,7 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi *umidi,
1357 unsigned int i; 1368 unsigned int i;
1358 unsigned int pipe; 1369 unsigned int pipe;
1359 void *buffer; 1370 void *buffer;
1371 int err;
1360 1372
1361 rep->out = NULL; 1373 rep->out = NULL;
1362 ep = kzalloc(sizeof(*ep), GFP_KERNEL); 1374 ep = kzalloc(sizeof(*ep), GFP_KERNEL);
@@ -1367,8 +1379,8 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi *umidi,
1367 for (i = 0; i < OUTPUT_URBS; ++i) { 1379 for (i = 0; i < OUTPUT_URBS; ++i) {
1368 ep->urbs[i].urb = usb_alloc_urb(0, GFP_KERNEL); 1380 ep->urbs[i].urb = usb_alloc_urb(0, GFP_KERNEL);
1369 if (!ep->urbs[i].urb) { 1381 if (!ep->urbs[i].urb) {
1370 snd_usbmidi_out_endpoint_delete(ep); 1382 err = -ENOMEM;
1371 return -ENOMEM; 1383 goto error;
1372 } 1384 }
1373 ep->urbs[i].ep = ep; 1385 ep->urbs[i].ep = ep;
1374 } 1386 }
@@ -1406,8 +1418,8 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi *umidi,
1406 ep->max_transfer, GFP_KERNEL, 1418 ep->max_transfer, GFP_KERNEL,
1407 &ep->urbs[i].urb->transfer_dma); 1419 &ep->urbs[i].urb->transfer_dma);
1408 if (!buffer) { 1420 if (!buffer) {
1409 snd_usbmidi_out_endpoint_delete(ep); 1421 err = -ENOMEM;
1410 return -ENOMEM; 1422 goto error;
1411 } 1423 }
1412 if (ep_info->out_interval) 1424 if (ep_info->out_interval)
1413 usb_fill_int_urb(ep->urbs[i].urb, umidi->dev, 1425 usb_fill_int_urb(ep->urbs[i].urb, umidi->dev,
@@ -1419,6 +1431,12 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi *umidi,
1419 pipe, buffer, ep->max_transfer, 1431 pipe, buffer, ep->max_transfer,
1420 snd_usbmidi_out_urb_complete, 1432 snd_usbmidi_out_urb_complete,
1421 &ep->urbs[i]); 1433 &ep->urbs[i]);
1434 err = usb_urb_ep_type_check(ep->urbs[i].urb);
1435 if (err < 0) {
1436 dev_err(&umidi->dev->dev, "invalid MIDI out EP %x\n",
1437 ep_info->out_ep);
1438 goto error;
1439 }
1422 ep->urbs[i].urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 1440 ep->urbs[i].urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
1423 } 1441 }
1424 1442
@@ -1437,6 +1455,10 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi *umidi,
1437 1455
1438 rep->out = ep; 1456 rep->out = ep;
1439 return 0; 1457 return 0;
1458
1459 error:
1460 snd_usbmidi_out_endpoint_delete(ep);
1461 return err;
1440} 1462}
1441 1463
1442/* 1464/*
@@ -2347,8 +2369,7 @@ int __snd_usbmidi_create(struct snd_card *card,
2347 usb_id = USB_ID(le16_to_cpu(umidi->dev->descriptor.idVendor), 2369 usb_id = USB_ID(le16_to_cpu(umidi->dev->descriptor.idVendor),
2348 le16_to_cpu(umidi->dev->descriptor.idProduct)); 2370 le16_to_cpu(umidi->dev->descriptor.idProduct));
2349 umidi->usb_id = usb_id; 2371 umidi->usb_id = usb_id;
2350 setup_timer(&umidi->error_timer, snd_usbmidi_error_timer, 2372 timer_setup(&umidi->error_timer, snd_usbmidi_error_timer, 0);
2351 (unsigned long)umidi);
2352 2373
2353 /* detect the endpoint(s) to use */ 2374 /* detect the endpoint(s) to use */
2354 memset(endpoints, 0, sizeof(endpoints)); 2375 memset(endpoints, 0, sizeof(endpoints));
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 20624320b753..77eecaa4db1f 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -1128,30 +1128,24 @@ bool snd_usb_get_sample_rate_quirk(struct snd_usb_audio *chip)
1128 /* devices which do not support reading the sample rate. */ 1128 /* devices which do not support reading the sample rate. */
1129 switch (chip->usb_id) { 1129 switch (chip->usb_id) {
1130 case USB_ID(0x041E, 0x4080): /* Creative Live Cam VF0610 */ 1130 case USB_ID(0x041E, 0x4080): /* Creative Live Cam VF0610 */
1131 case USB_ID(0x045E, 0x075D): /* MS Lifecam Cinema */
1132 case USB_ID(0x045E, 0x076D): /* MS Lifecam HD-5000 */
1133 case USB_ID(0x045E, 0x076E): /* MS Lifecam HD-5001 */
1134 case USB_ID(0x045E, 0x076F): /* MS Lifecam HD-6000 */
1135 case USB_ID(0x045E, 0x0772): /* MS Lifecam Studio */
1136 case USB_ID(0x045E, 0x0779): /* MS Lifecam HD-3000 */
1137 case USB_ID(0x047F, 0x02F7): /* Plantronics BT-600 */
1138 case USB_ID(0x047F, 0x0415): /* Plantronics BT-300 */
1139 case USB_ID(0x047F, 0xAA05): /* Plantronics DA45 */
1140 case USB_ID(0x047F, 0xC022): /* Plantronics C310 */
1141 case USB_ID(0x047F, 0xC02F): /* Plantronics P610 */
1142 case USB_ID(0x047F, 0xC036): /* Plantronics C520-M */
1143 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */ 1131 case USB_ID(0x04D8, 0xFEEA): /* Benchmark DAC1 Pre */
1144 case USB_ID(0x0556, 0x0014): /* Phoenix Audio TMX320VC */ 1132 case USB_ID(0x0556, 0x0014): /* Phoenix Audio TMX320VC */
1145 case USB_ID(0x05A3, 0x9420): /* ELP HD USB Camera */ 1133 case USB_ID(0x05A3, 0x9420): /* ELP HD USB Camera */
1146 case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */ 1134 case USB_ID(0x074D, 0x3553): /* Outlaw RR2150 (Micronas UAC3553B) */
1147 case USB_ID(0x1395, 0x740a): /* Sennheiser DECT */ 1135 case USB_ID(0x1395, 0x740a): /* Sennheiser DECT */
1148 case USB_ID(0x1901, 0x0191): /* GE B850V3 CP2114 audio interface */ 1136 case USB_ID(0x1901, 0x0191): /* GE B850V3 CP2114 audio interface */
1149 case USB_ID(0x1de7, 0x0013): /* Phoenix Audio MT202exe */
1150 case USB_ID(0x1de7, 0x0014): /* Phoenix Audio TMX320 */
1151 case USB_ID(0x1de7, 0x0114): /* Phoenix Audio MT202pcs */
1152 case USB_ID(0x21B4, 0x0081): /* AudioQuest DragonFly */ 1137 case USB_ID(0x21B4, 0x0081): /* AudioQuest DragonFly */
1153 return true; 1138 return true;
1154 } 1139 }
1140
1141 /* devices of these vendors don't support reading rate, either */
1142 switch (USB_ID_VENDOR(chip->usb_id)) {
1143 case 0x045E: /* MS Lifecam */
1144 case 0x047F: /* Plantronics */
1145 case 0x1de7: /* Phoenix Audio */
1146 return true;
1147 }
1148
1155 return false; 1149 return false;
1156} 1150}
1157 1151
diff --git a/sound/usb/usx2y/usb_stream.c b/sound/usb/usx2y/usb_stream.c
index e229abd21652..b0f8979ff2d2 100644
--- a/sound/usb/usx2y/usb_stream.c
+++ b/sound/usb/usx2y/usb_stream.c
@@ -56,7 +56,7 @@ check:
56 lb, s->period_size); 56 lb, s->period_size);
57} 57}
58 58
59static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize, 59static int init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
60 struct urb **urbs, char *transfer, 60 struct urb **urbs, char *transfer,
61 struct usb_device *dev, int pipe) 61 struct usb_device *dev, int pipe)
62{ 62{
@@ -77,6 +77,8 @@ static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
77 urb->interval = 1; 77 urb->interval = 1;
78 if (usb_pipeout(pipe)) 78 if (usb_pipeout(pipe))
79 continue; 79 continue;
80 if (usb_urb_ep_type_check(urb))
81 return -EINVAL;
80 82
81 urb->transfer_buffer_length = transfer_length; 83 urb->transfer_buffer_length = transfer_length;
82 desc = urb->iso_frame_desc; 84 desc = urb->iso_frame_desc;
@@ -87,9 +89,11 @@ static void init_pipe_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
87 desc[p].length = maxpacket; 89 desc[p].length = maxpacket;
88 } 90 }
89 } 91 }
92
93 return 0;
90} 94}
91 95
92static void init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize, 96static int init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
93 struct usb_device *dev, int in_pipe, int out_pipe) 97 struct usb_device *dev, int in_pipe, int out_pipe)
94{ 98{
95 struct usb_stream *s = sk->s; 99 struct usb_stream *s = sk->s;
@@ -103,9 +107,12 @@ static void init_urbs(struct usb_stream_kernel *sk, unsigned use_packsize,
103 sk->outurb[u] = usb_alloc_urb(sk->n_o_ps, GFP_KERNEL); 107 sk->outurb[u] = usb_alloc_urb(sk->n_o_ps, GFP_KERNEL);
104 } 108 }
105 109
106 init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe); 110 if (init_pipe_urbs(sk, use_packsize, sk->inurb, indata, dev, in_pipe) ||
107 init_pipe_urbs(sk, use_packsize, sk->outurb, sk->write_page, dev, 111 init_pipe_urbs(sk, use_packsize, sk->outurb, sk->write_page, dev,
108 out_pipe); 112 out_pipe))
113 return -EINVAL;
114
115 return 0;
109} 116}
110 117
111 118
@@ -226,7 +233,11 @@ struct usb_stream *usb_stream_new(struct usb_stream_kernel *sk,
226 else 233 else
227 sk->freqn = get_usb_high_speed_rate(sample_rate); 234 sk->freqn = get_usb_high_speed_rate(sample_rate);
228 235
229 init_urbs(sk, use_packsize, dev, in_pipe, out_pipe); 236 if (init_urbs(sk, use_packsize, dev, in_pipe, out_pipe) < 0) {
237 usb_stream_free(sk);
238 return NULL;
239 }
240
230 sk->s->state = usb_stream_stopped; 241 sk->s->state = usb_stream_stopped;
231out: 242out:
232 return sk->s; 243 return sk->s;
diff --git a/sound/usb/usx2y/usbusx2y.c b/sound/usb/usx2y/usbusx2y.c
index 4569c0efac0a..0ddf29267d70 100644
--- a/sound/usb/usx2y/usbusx2y.c
+++ b/sound/usb/usx2y/usbusx2y.c
@@ -279,6 +279,9 @@ int usX2Y_AsyncSeq04_init(struct usX2Ydev *usX2Y)
279 usX2Y->AS04.buffer + URB_DataLen_AsyncSeq*i, 0, 279 usX2Y->AS04.buffer + URB_DataLen_AsyncSeq*i, 0,
280 i_usX2Y_Out04Int, usX2Y 280 i_usX2Y_Out04Int, usX2Y
281 ); 281 );
282 err = usb_urb_ep_type_check(usX2Y->AS04.urb[i]);
283 if (err < 0)
284 break;
282 } 285 }
283 return err; 286 return err;
284} 287}
@@ -298,6 +301,8 @@ int usX2Y_In04_init(struct usX2Ydev *usX2Y)
298 usX2Y->In04Buf, 21, 301 usX2Y->In04Buf, 21,
299 i_usX2Y_In04Int, usX2Y, 302 i_usX2Y_In04Int, usX2Y,
300 10); 303 10);
304 if (usb_urb_ep_type_check(usX2Y->In04urb))
305 return -EINVAL;
301 return usb_submit_urb(usX2Y->In04urb, GFP_KERNEL); 306 return usb_submit_urb(usX2Y->In04urb, GFP_KERNEL);
302} 307}
303 308
diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c
index f93b355756e6..345e439aa95b 100644
--- a/sound/usb/usx2y/usbusx2yaudio.c
+++ b/sound/usb/usx2y/usbusx2yaudio.c
@@ -677,6 +677,9 @@ static int usX2Y_rate_set(struct usX2Ydev *usX2Y, int rate)
677 usb_fill_bulk_urb(us->urb[i], usX2Y->dev, usb_sndbulkpipe(usX2Y->dev, 4), 677 usb_fill_bulk_urb(us->urb[i], usX2Y->dev, usb_sndbulkpipe(usX2Y->dev, 4),
678 usbdata + i, 2, i_usX2Y_04Int, usX2Y); 678 usbdata + i, 2, i_usX2Y_04Int, usX2Y);
679 } 679 }
680 err = usb_urb_ep_type_check(us->urb[0]);
681 if (err < 0)
682 goto cleanup;
680 us->submitted = 0; 683 us->submitted = 0;
681 us->len = NOOF_SETRATE_URBS; 684 us->len = NOOF_SETRATE_URBS;
682 usX2Y->US04 = us; 685 usX2Y->US04 = us;