aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
Diffstat (limited to 'sound')
-rw-r--r--sound/ac97_bus.c62
-rw-r--r--sound/core/pcm_native.c2
-rw-r--r--sound/firewire/amdtp.c5
-rw-r--r--sound/firewire/amdtp.h2
-rw-r--r--sound/firewire/fireworks/fireworks.c8
-rw-r--r--sound/firewire/fireworks/fireworks.h1
-rw-r--r--sound/firewire/fireworks/fireworks_stream.c9
-rw-r--r--sound/hda/ext/hdac_ext_controller.c6
-rw-r--r--sound/hda/ext/hdac_ext_stream.c2
-rw-r--r--sound/hda/hdac_i915.c5
-rw-r--r--sound/pci/hda/hda_generic.c2
-rw-r--r--sound/pci/hda/hda_intel.c32
-rw-r--r--sound/pci/hda/patch_cirrus.c4
-rw-r--r--sound/pci/hda/patch_hdmi.c4
-rw-r--r--sound/pci/hda/patch_realtek.c137
-rw-r--r--sound/pci/hda/patch_sigmatel.c3
-rw-r--r--sound/pci/oxygen/oxygen_mixer.c2
-rw-r--r--sound/soc/Kconfig4
-rw-r--r--sound/soc/Makefile4
-rw-r--r--sound/soc/atmel/atmel_ssc_dai.c2
-rw-r--r--sound/soc/au1x/dbdma2.c11
-rw-r--r--sound/soc/au1x/dma.c11
-rw-r--r--sound/soc/au1x/psc-i2s.c16
-rw-r--r--sound/soc/bcm/bcm2835-i2s.c2
-rw-r--r--sound/soc/blackfin/bf5xx-ac97-pcm.c10
-rw-r--r--sound/soc/blackfin/bf5xx-i2s-pcm.c10
-rw-r--r--sound/soc/blackfin/bfin-eval-adau1x61.c1
-rw-r--r--sound/soc/codecs/88pm860x-codec.c4
-rw-r--r--sound/soc/codecs/Kconfig21
-rw-r--r--sound/soc/codecs/Makefile8
-rw-r--r--sound/soc/codecs/ad1980.c36
-rw-r--r--sound/soc/codecs/adau1373.c1
-rw-r--r--sound/soc/codecs/adau1701.c1
-rw-r--r--sound/soc/codecs/adau1761-i2c.c1
-rw-r--r--sound/soc/codecs/adau1781-i2c.c1
-rw-r--r--sound/soc/codecs/adau1977-i2c.c1
-rw-r--r--sound/soc/codecs/adav803.c1
-rw-r--r--sound/soc/codecs/adav80x.c3
-rw-r--r--sound/soc/codecs/ak4535.c1
-rw-r--r--sound/soc/codecs/ak4641.c1
-rw-r--r--sound/soc/codecs/ak4642.c34
-rw-r--r--sound/soc/codecs/ak4671.c1
-rw-r--r--sound/soc/codecs/alc5623.c1
-rw-r--r--sound/soc/codecs/alc5632.c3
-rw-r--r--sound/soc/codecs/arizona.c129
-rw-r--r--sound/soc/codecs/arizona.h20
-rw-r--r--sound/soc/codecs/cs35l32.c60
-rw-r--r--sound/soc/codecs/cs35l32.h2
-rw-r--r--sound/soc/codecs/cs4265.c29
-rw-r--r--sound/soc/codecs/cs4270.c1
-rw-r--r--sound/soc/codecs/cs4271-i2c.c1
-rw-r--r--sound/soc/codecs/cs42l51-i2c.c1
-rw-r--r--sound/soc/codecs/cs42l52.c58
-rw-r--r--sound/soc/codecs/cs42l56.c50
-rw-r--r--sound/soc/codecs/cs42l73.c101
-rw-r--r--sound/soc/codecs/cs42xx8-i2c.c4
-rw-r--r--sound/soc/codecs/cs42xx8.c19
-rw-r--r--sound/soc/codecs/cs42xx8.h1
-rw-r--r--sound/soc/codecs/cs4349.c392
-rw-r--r--sound/soc/codecs/cs4349.h136
-rw-r--r--sound/soc/codecs/da7210.c7
-rw-r--r--sound/soc/codecs/da7213.c3
-rw-r--r--sound/soc/codecs/da732x.c15
-rw-r--r--sound/soc/codecs/da9055.c4
-rw-r--r--sound/soc/codecs/gtm601.c95
-rw-r--r--sound/soc/codecs/ics43432.c76
-rw-r--r--sound/soc/codecs/isabelle.c11
-rw-r--r--sound/soc/codecs/lm4857.c1
-rw-r--r--sound/soc/codecs/lm49453.c19
-rw-r--r--sound/soc/codecs/max9768.c64
-rw-r--r--sound/soc/codecs/max98088.c306
-rw-r--r--sound/soc/codecs/max98088.h2
-rw-r--r--sound/soc/codecs/max98090.c129
-rw-r--r--sound/soc/codecs/max98090.h1
-rw-r--r--sound/soc/codecs/max98095.c319
-rw-r--r--sound/soc/codecs/max98357a.c25
-rw-r--r--sound/soc/codecs/max9850.c1
-rw-r--r--sound/soc/codecs/max9877.c19
-rw-r--r--sound/soc/codecs/max98925.c4
-rw-r--r--sound/soc/codecs/mc13783.c6
-rw-r--r--sound/soc/codecs/ml26124.c3
-rw-r--r--sound/soc/codecs/pcm1681.c16
-rw-r--r--sound/soc/codecs/pcm512x-i2c.c1
-rw-r--r--sound/soc/codecs/rl6231.c104
-rw-r--r--sound/soc/codecs/rl6231.h1
-rw-r--r--sound/soc/codecs/rt286.c11
-rw-r--r--sound/soc/codecs/rt298.c1271
-rw-r--r--sound/soc/codecs/rt298.h206
-rw-r--r--sound/soc/codecs/rt5631.c1
-rw-r--r--sound/soc/codecs/rt5640.c52
-rw-r--r--sound/soc/codecs/rt5645.c439
-rw-r--r--sound/soc/codecs/rt5645.h31
-rw-r--r--sound/soc/codecs/rt5651.c12
-rw-r--r--sound/soc/codecs/rt5670.c14
-rw-r--r--sound/soc/codecs/rt5677-spi.c233
-rw-r--r--sound/soc/codecs/rt5677-spi.h8
-rw-r--r--sound/soc/codecs/rt5677.c152
-rw-r--r--sound/soc/codecs/rt5677.h5
-rw-r--r--sound/soc/codecs/sgtl5000.c1
-rw-r--r--sound/soc/codecs/sgtl5000.h2
-rw-r--r--sound/soc/codecs/si476x.c2
-rw-r--r--sound/soc/codecs/sirf-audio-codec.c4
-rw-r--r--sound/soc/codecs/ssm2518.c10
-rw-r--r--sound/soc/codecs/ssm2602-i2c.c1
-rw-r--r--sound/soc/codecs/ssm4567.c42
-rw-r--r--sound/soc/codecs/sta32x.c1
-rw-r--r--sound/soc/codecs/sta350.c1
-rw-r--r--sound/soc/codecs/sta529.c4
-rw-r--r--sound/soc/codecs/stac9766.c57
-rw-r--r--sound/soc/codecs/tas2552.c5
-rw-r--r--sound/soc/codecs/tas5086.c1
-rw-r--r--sound/soc/codecs/tas571x.c2
-rw-r--r--sound/soc/codecs/tfa9879.c3
-rw-r--r--sound/soc/codecs/tlv320aic31xx.c3
-rw-r--r--sound/soc/codecs/tlv320aic32x4.c1
-rw-r--r--sound/soc/codecs/tlv320aic3x.c3
-rw-r--r--sound/soc/codecs/tlv320dac33.c1
-rw-r--r--sound/soc/codecs/tpa6130a2.c1
-rw-r--r--sound/soc/codecs/ts3a227e.c48
-rw-r--r--sound/soc/codecs/uda1380.c1
-rw-r--r--sound/soc/codecs/wm1250-ev1.c1
-rw-r--r--sound/soc/codecs/wm2000.c1
-rw-r--r--sound/soc/codecs/wm2200.c7
-rw-r--r--sound/soc/codecs/wm5100.c5
-rw-r--r--sound/soc/codecs/wm5102.c27
-rw-r--r--sound/soc/codecs/wm5110.c30
-rw-r--r--sound/soc/codecs/wm8510.c2
-rw-r--r--sound/soc/codecs/wm8523.c2
-rw-r--r--sound/soc/codecs/wm8580.c2
-rw-r--r--sound/soc/codecs/wm8711.c1
-rw-r--r--sound/soc/codecs/wm8728.c1
-rw-r--r--sound/soc/codecs/wm8731.c1
-rw-r--r--sound/soc/codecs/wm8737.c1
-rw-r--r--sound/soc/codecs/wm8741.c1
-rw-r--r--sound/soc/codecs/wm8750.c1
-rw-r--r--sound/soc/codecs/wm8753.c1
-rw-r--r--sound/soc/codecs/wm8776.c1
-rw-r--r--sound/soc/codecs/wm8804-i2c.c1
-rw-r--r--sound/soc/codecs/wm8900.c1
-rw-r--r--sound/soc/codecs/wm8903.c1
-rw-r--r--sound/soc/codecs/wm8904.c1
-rw-r--r--sound/soc/codecs/wm8940.c1
-rw-r--r--sound/soc/codecs/wm8955.c1
-rw-r--r--sound/soc/codecs/wm8960.c1
-rw-r--r--sound/soc/codecs/wm8961.c1
-rw-r--r--sound/soc/codecs/wm8962.c7
-rw-r--r--sound/soc/codecs/wm8971.c1
-rw-r--r--sound/soc/codecs/wm8974.c1
-rw-r--r--sound/soc/codecs/wm8978.c1
-rw-r--r--sound/soc/codecs/wm8983.c1
-rw-r--r--sound/soc/codecs/wm8985.c1
-rw-r--r--sound/soc/codecs/wm8988.c1
-rw-r--r--sound/soc/codecs/wm8990.c1
-rw-r--r--sound/soc/codecs/wm8991.c1
-rw-r--r--sound/soc/codecs/wm8993.c5
-rw-r--r--sound/soc/codecs/wm8994.c18
-rw-r--r--sound/soc/codecs/wm8995.c1
-rw-r--r--sound/soc/codecs/wm8996.c3
-rw-r--r--sound/soc/codecs/wm8997.c20
-rw-r--r--sound/soc/codecs/wm9081.c3
-rw-r--r--sound/soc/codecs/wm9090.c1
-rw-r--r--sound/soc/codecs/wm9705.c40
-rw-r--r--sound/soc/codecs/wm9712.c45
-rw-r--r--sound/soc/codecs/wm9713.c48
-rw-r--r--sound/soc/codecs/wm9713.h2
-rw-r--r--sound/soc/davinci/davinci-i2s.c25
-rw-r--r--sound/soc/davinci/davinci-mcasp.c18
-rw-r--r--sound/soc/davinci/davinci-vcif.c14
-rw-r--r--sound/soc/fsl/eukrea-tlv320.c2
-rw-r--r--sound/soc/fsl/fsl-asoc-card.c16
-rw-r--r--sound/soc/fsl/fsl_asrc.c25
-rw-r--r--sound/soc/fsl/fsl_esai.c2
-rw-r--r--sound/soc/fsl/fsl_sai.c2
-rw-r--r--sound/soc/fsl/fsl_sai.h15
-rw-r--r--sound/soc/fsl/fsl_spdif.c25
-rw-r--r--sound/soc/fsl/fsl_ssi.c70
-rw-r--r--sound/soc/fsl/imx-pcm-dma.c25
-rw-r--r--sound/soc/fsl/imx-pcm.h9
-rw-r--r--sound/soc/fsl/imx-ssi.c2
-rw-r--r--sound/soc/generic/simple-card.c9
-rw-r--r--sound/soc/intel/Kconfig29
-rw-r--r--sound/soc/intel/Makefile3
-rw-r--r--sound/soc/intel/atom/sst-atom-controls.c6
-rw-r--r--sound/soc/intel/atom/sst-mfld-platform-pcm.c1
-rw-r--r--sound/soc/intel/atom/sst-mfld-platform.h1
-rw-r--r--sound/soc/intel/atom/sst/sst_drv_interface.c23
-rw-r--r--sound/soc/intel/atom/sst/sst_ipc.c3
-rw-r--r--sound/soc/intel/baytrail/sst-baytrail-ipc.c2
-rw-r--r--sound/soc/intel/boards/byt-max98090.c1
-rw-r--r--sound/soc/intel/boards/byt-rt5640.c1
-rw-r--r--sound/soc/intel/boards/bytcr_rt5640.c1
-rw-r--r--sound/soc/intel/boards/cht_bsw_max98090_ti.c23
-rw-r--r--sound/soc/intel/boards/cht_bsw_rt5645.c2
-rw-r--r--sound/soc/intel/boards/cht_bsw_rt5672.c1
-rw-r--r--sound/soc/intel/common/sst-dsp-priv.h23
-rw-r--r--sound/soc/intel/common/sst-dsp.c71
-rw-r--r--sound/soc/intel/common/sst-dsp.h6
-rw-r--r--sound/soc/intel/haswell/sst-haswell-ipc.c2
-rw-r--r--sound/soc/intel/skylake/Makefile9
-rw-r--r--sound/soc/intel/skylake/skl-messages.c884
-rw-r--r--sound/soc/intel/skylake/skl-nhlt.c140
-rw-r--r--sound/soc/intel/skylake/skl-nhlt.h106
-rw-r--r--sound/soc/intel/skylake/skl-pcm.c916
-rw-r--r--sound/soc/intel/skylake/skl-sst-cldma.c327
-rw-r--r--sound/soc/intel/skylake/skl-sst-cldma.h251
-rw-r--r--sound/soc/intel/skylake/skl-sst-dsp.c342
-rw-r--r--sound/soc/intel/skylake/skl-sst-dsp.h145
-rw-r--r--sound/soc/intel/skylake/skl-sst-ipc.c771
-rw-r--r--sound/soc/intel/skylake/skl-sst-ipc.h125
-rw-r--r--sound/soc/intel/skylake/skl-sst.c280
-rw-r--r--sound/soc/intel/skylake/skl-topology.h286
-rw-r--r--sound/soc/intel/skylake/skl-tplg-interface.h88
-rw-r--r--sound/soc/intel/skylake/skl.c536
-rw-r--r--sound/soc/intel/skylake/skl.h84
-rw-r--r--sound/soc/kirkwood/kirkwood-dma.c4
-rw-r--r--sound/soc/mediatek/mt8173-max98090.c19
-rw-r--r--sound/soc/mediatek/mt8173-rt5650-rt5676.c21
-rw-r--r--sound/soc/mediatek/mtk-afe-common.h8
-rw-r--r--sound/soc/mediatek/mtk-afe-pcm.c91
-rw-r--r--sound/soc/nuc900/nuc900-pcm.c9
-rw-r--r--sound/soc/omap/mcbsp.c20
-rw-r--r--sound/soc/omap/omap-hdmi-audio.c10
-rw-r--r--sound/soc/omap/omap3pandora.c6
-rw-r--r--sound/soc/pxa/mmp-pcm.c9
-rw-r--r--sound/soc/pxa/pxa-ssp.c11
-rw-r--r--sound/soc/pxa/pxa2xx-i2s.c11
-rw-r--r--sound/soc/pxa/pxa2xx-pcm.c9
-rw-r--r--sound/soc/qcom/Kconfig7
-rw-r--r--sound/soc/qcom/lpass-cpu.c2
-rw-r--r--sound/soc/qcom/lpass-ipq806x.c2
-rw-r--r--sound/soc/qcom/lpass.h2
-rw-r--r--sound/soc/rockchip/Kconfig19
-rw-r--r--sound/soc/rockchip/Makefile6
-rw-r--r--sound/soc/rockchip/rockchip_i2s.c8
-rw-r--r--sound/soc/rockchip/rockchip_max98090.c236
-rw-r--r--sound/soc/rockchip/rockchip_rt5645.c225
-rw-r--r--sound/soc/samsung/arndale_rt5631.c11
-rw-r--r--sound/soc/samsung/snow.c1
-rw-r--r--sound/soc/sh/dma-sh7760.c9
-rw-r--r--sound/soc/sh/fsi.c1
-rw-r--r--sound/soc/sh/rcar/Makefile2
-rw-r--r--sound/soc/sh/rcar/core.c195
-rw-r--r--sound/soc/sh/rcar/ctu.c171
-rw-r--r--sound/soc/sh/rcar/dma.c128
-rw-r--r--sound/soc/sh/rcar/dvc.c73
-rw-r--r--sound/soc/sh/rcar/gen.c33
-rw-r--r--sound/soc/sh/rcar/mix.c200
-rw-r--r--sound/soc/sh/rcar/rsnd.h111
-rw-r--r--sound/soc/sh/rcar/rsrc-card.c22
-rw-r--r--sound/soc/sh/rcar/src.c117
-rw-r--r--sound/soc/sh/rcar/ssi.c4
-rw-r--r--sound/soc/sh/ssi.c12
-rw-r--r--sound/soc/soc-ac97.c30
-rw-r--r--sound/soc/soc-core.c87
-rw-r--r--sound/soc/soc-dapm.c538
-rw-r--r--sound/soc/soc-pcm.c16
-rw-r--r--sound/soc/soc-topology.c87
-rw-r--r--sound/soc/spear/spdif_in.c20
-rw-r--r--sound/soc/spear/spear_pcm.c2
-rw-r--r--sound/soc/sti/Kconfig11
-rw-r--r--sound/soc/sti/Makefile4
-rw-r--r--sound/soc/sti/sti_uniperif.c254
-rw-r--r--sound/soc/sti/uniperif.h1229
-rw-r--r--sound/soc/sti/uniperif_player.c1110
-rw-r--r--sound/soc/sti/uniperif_reader.c362
-rw-r--r--sound/soc/zte/zx296702-i2s.c4
-rw-r--r--sound/soc/zte/zx296702-spdif.c4
-rw-r--r--sound/sparc/amd7930.c1
-rw-r--r--sound/usb/card.c2
-rw-r--r--sound/usb/line6/pcm.c9
-rw-r--r--sound/usb/mixer_maps.c24
-rw-r--r--sound/usb/quirks-table.h68
272 files changed, 14235 insertions, 2835 deletions
diff --git a/sound/ac97_bus.c b/sound/ac97_bus.c
index 2b50cbe6aca9..55791a0b3943 100644
--- a/sound/ac97_bus.c
+++ b/sound/ac97_bus.c
@@ -18,6 +18,68 @@
18#include <sound/ac97_codec.h> 18#include <sound/ac97_codec.h>
19 19
20/* 20/*
21 * snd_ac97_check_id() - Reads and checks the vendor ID of the device
22 * @ac97: The AC97 device to check
23 * @id: The ID to compare to
24 * @id_mask: Mask that is applied to the device ID before comparing to @id
25 *
26 * If @id is 0 this function returns true if the read device vendor ID is
27 * a valid ID. If @id is non 0 this functions returns true if @id
28 * matches the read vendor ID. Otherwise the function returns false.
29 */
30static bool snd_ac97_check_id(struct snd_ac97 *ac97, unsigned int id,
31 unsigned int id_mask)
32{
33 ac97->id = ac97->bus->ops->read(ac97, AC97_VENDOR_ID1) << 16;
34 ac97->id |= ac97->bus->ops->read(ac97, AC97_VENDOR_ID2);
35
36 if (ac97->id == 0x0 || ac97->id == 0xffffffff)
37 return false;
38
39 if (id != 0 && id != (ac97->id & id_mask))
40 return false;
41
42 return true;
43}
44
45/**
46 * snd_ac97_reset() - Reset AC'97 device
47 * @ac97: The AC'97 device to reset
48 * @try_warm: Try a warm reset first
49 * @id: Expected device vendor ID
50 * @id_mask: Mask that is applied to the device ID before comparing to @id
51 *
52 * This function resets the AC'97 device. If @try_warm is true the function
53 * first performs a warm reset. If the warm reset is successful the function
54 * returns 1. Otherwise or if @try_warm is false the function issues cold reset
55 * followed by a warm reset. If this is successful the function returns 0,
56 * otherwise a negative error code. If @id is 0 any valid device ID will be
57 * accepted, otherwise only the ID that matches @id and @id_mask is accepted.
58 */
59int snd_ac97_reset(struct snd_ac97 *ac97, bool try_warm, unsigned int id,
60 unsigned int id_mask)
61{
62 struct snd_ac97_bus_ops *ops = ac97->bus->ops;
63
64 if (try_warm && ops->warm_reset) {
65 ops->warm_reset(ac97);
66 if (snd_ac97_check_id(ac97, id, id_mask))
67 return 1;
68 }
69
70 if (ops->reset)
71 ops->reset(ac97);
72 if (ops->warm_reset)
73 ops->warm_reset(ac97);
74
75 if (snd_ac97_check_id(ac97, id, id_mask))
76 return 0;
77
78 return -ENODEV;
79}
80EXPORT_SYMBOL_GPL(snd_ac97_reset);
81
82/*
21 * Let drivers decide whether they want to support given codec from their 83 * Let drivers decide whether they want to support given codec from their
22 * probe method. Drivers have direct access to the struct snd_ac97 84 * probe method. Drivers have direct access to the struct snd_ac97
23 * structure and may decide based on the id field amongst other things. 85 * structure and may decide based on the id field amongst other things.
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index d126c03361ae..75888dd38a7f 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -85,7 +85,7 @@ static DECLARE_RWSEM(snd_pcm_link_rwsem);
85void snd_pcm_stream_lock(struct snd_pcm_substream *substream) 85void snd_pcm_stream_lock(struct snd_pcm_substream *substream)
86{ 86{
87 if (substream->pcm->nonatomic) { 87 if (substream->pcm->nonatomic) {
88 down_read(&snd_pcm_link_rwsem); 88 down_read_nested(&snd_pcm_link_rwsem, SINGLE_DEPTH_NESTING);
89 mutex_lock(&substream->self_group.mutex); 89 mutex_lock(&substream->self_group.mutex);
90 } else { 90 } else {
91 read_lock(&snd_pcm_link_rwlock); 91 read_lock(&snd_pcm_link_rwlock);
diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
index 7bb988fa6b6d..2a153d260836 100644
--- a/sound/firewire/amdtp.c
+++ b/sound/firewire/amdtp.c
@@ -740,8 +740,9 @@ static int handle_in_packet(struct amdtp_stream *s,
740 s->data_block_counter != UINT_MAX) 740 s->data_block_counter != UINT_MAX)
741 data_block_counter = s->data_block_counter; 741 data_block_counter = s->data_block_counter;
742 742
743 if (((s->flags & CIP_SKIP_DBC_ZERO_CHECK) && data_block_counter == 0) || 743 if (((s->flags & CIP_SKIP_DBC_ZERO_CHECK) &&
744 (s->data_block_counter == UINT_MAX)) { 744 data_block_counter == s->tx_first_dbc) ||
745 s->data_block_counter == UINT_MAX) {
745 lost = false; 746 lost = false;
746 } else if (!(s->flags & CIP_DBC_IS_END_EVENT)) { 747 } else if (!(s->flags & CIP_DBC_IS_END_EVENT)) {
747 lost = data_block_counter != s->data_block_counter; 748 lost = data_block_counter != s->data_block_counter;
diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
index 26b909329e54..b2cf9e75693b 100644
--- a/sound/firewire/amdtp.h
+++ b/sound/firewire/amdtp.h
@@ -157,6 +157,8 @@ struct amdtp_stream {
157 157
158 /* quirk: fixed interval of dbc between previos/current packets. */ 158 /* quirk: fixed interval of dbc between previos/current packets. */
159 unsigned int tx_dbc_interval; 159 unsigned int tx_dbc_interval;
160 /* quirk: indicate the value of dbc field in a first packet. */
161 unsigned int tx_first_dbc;
160 162
161 bool callbacked; 163 bool callbacked;
162 wait_queue_head_t callback_wait; 164 wait_queue_head_t callback_wait;
diff --git a/sound/firewire/fireworks/fireworks.c b/sound/firewire/fireworks/fireworks.c
index 2682e7e3e5c9..c94a432f7cc6 100644
--- a/sound/firewire/fireworks/fireworks.c
+++ b/sound/firewire/fireworks/fireworks.c
@@ -248,8 +248,16 @@ efw_probe(struct fw_unit *unit,
248 err = get_hardware_info(efw); 248 err = get_hardware_info(efw);
249 if (err < 0) 249 if (err < 0)
250 goto error; 250 goto error;
251 /* AudioFire8 (since 2009) and AudioFirePre8 */
251 if (entry->model_id == MODEL_ECHO_AUDIOFIRE_9) 252 if (entry->model_id == MODEL_ECHO_AUDIOFIRE_9)
252 efw->is_af9 = true; 253 efw->is_af9 = true;
254 /* These models uses the same firmware. */
255 if (entry->model_id == MODEL_ECHO_AUDIOFIRE_2 ||
256 entry->model_id == MODEL_ECHO_AUDIOFIRE_4 ||
257 entry->model_id == MODEL_ECHO_AUDIOFIRE_9 ||
258 entry->model_id == MODEL_GIBSON_RIP ||
259 entry->model_id == MODEL_GIBSON_GOLDTOP)
260 efw->is_fireworks3 = true;
253 261
254 snd_efw_proc_init(efw); 262 snd_efw_proc_init(efw);
255 263
diff --git a/sound/firewire/fireworks/fireworks.h b/sound/firewire/fireworks/fireworks.h
index 4f0201a95222..084d414b228c 100644
--- a/sound/firewire/fireworks/fireworks.h
+++ b/sound/firewire/fireworks/fireworks.h
@@ -71,6 +71,7 @@ struct snd_efw {
71 71
72 /* for quirks */ 72 /* for quirks */
73 bool is_af9; 73 bool is_af9;
74 bool is_fireworks3;
74 u32 firmware_version; 75 u32 firmware_version;
75 76
76 unsigned int midi_in_ports; 77 unsigned int midi_in_ports;
diff --git a/sound/firewire/fireworks/fireworks_stream.c b/sound/firewire/fireworks/fireworks_stream.c
index c55db1bddc80..7e353f1f7bff 100644
--- a/sound/firewire/fireworks/fireworks_stream.c
+++ b/sound/firewire/fireworks/fireworks_stream.c
@@ -172,6 +172,15 @@ int snd_efw_stream_init_duplex(struct snd_efw *efw)
172 efw->tx_stream.flags |= CIP_DBC_IS_END_EVENT; 172 efw->tx_stream.flags |= CIP_DBC_IS_END_EVENT;
173 /* Fireworks reset dbc at bus reset. */ 173 /* Fireworks reset dbc at bus reset. */
174 efw->tx_stream.flags |= CIP_SKIP_DBC_ZERO_CHECK; 174 efw->tx_stream.flags |= CIP_SKIP_DBC_ZERO_CHECK;
175 /*
176 * But Recent firmwares starts packets with non-zero dbc.
177 * Driver version 5.7.6 installs firmware version 5.7.3.
178 */
179 if (efw->is_fireworks3 &&
180 (efw->firmware_version == 0x5070000 ||
181 efw->firmware_version == 0x5070300 ||
182 efw->firmware_version == 0x5080000))
183 efw->tx_stream.tx_first_dbc = 0x02;
175 /* AudioFire9 always reports wrong dbs. */ 184 /* AudioFire9 always reports wrong dbs. */
176 if (efw->is_af9) 185 if (efw->is_af9)
177 efw->tx_stream.flags |= CIP_WRONG_DBS; 186 efw->tx_stream.flags |= CIP_WRONG_DBS;
diff --git a/sound/hda/ext/hdac_ext_controller.c b/sound/hda/ext/hdac_ext_controller.c
index b2da19b60f4e..358f16195483 100644
--- a/sound/hda/ext/hdac_ext_controller.c
+++ b/sound/hda/ext/hdac_ext_controller.c
@@ -44,16 +44,10 @@ int snd_hdac_ext_bus_parse_capabilities(struct hdac_ext_bus *ebus)
44 44
45 offset = snd_hdac_chip_readl(bus, LLCH); 45 offset = snd_hdac_chip_readl(bus, LLCH);
46 46
47 if (offset < 0)
48 return -EIO;
49
50 /* Lets walk the linked capabilities list */ 47 /* Lets walk the linked capabilities list */
51 do { 48 do {
52 cur_cap = _snd_hdac_chip_read(l, bus, offset); 49 cur_cap = _snd_hdac_chip_read(l, bus, offset);
53 50
54 if (cur_cap < 0)
55 return -EIO;
56
57 dev_dbg(bus->dev, "Capability version: 0x%x\n", 51 dev_dbg(bus->dev, "Capability version: 0x%x\n",
58 ((cur_cap & AZX_CAP_HDR_VER_MASK) >> AZX_CAP_HDR_VER_OFF)); 52 ((cur_cap & AZX_CAP_HDR_VER_MASK) >> AZX_CAP_HDR_VER_OFF));
59 53
diff --git a/sound/hda/ext/hdac_ext_stream.c b/sound/hda/ext/hdac_ext_stream.c
index f8ffbdbb450d..3de47dd1a76d 100644
--- a/sound/hda/ext/hdac_ext_stream.c
+++ b/sound/hda/ext/hdac_ext_stream.c
@@ -299,7 +299,7 @@ hdac_ext_host_stream_assign(struct hdac_ext_bus *ebus,
299 if (stream->direction != substream->stream) 299 if (stream->direction != substream->stream)
300 continue; 300 continue;
301 301
302 if (stream->opened) { 302 if (!stream->opened) {
303 if (!hstream->decoupled) 303 if (!hstream->decoupled)
304 snd_hdac_ext_stream_decouple(ebus, hstream, true); 304 snd_hdac_ext_stream_decouple(ebus, hstream, true);
305 res = hstream; 305 res = hstream;
diff --git a/sound/hda/hdac_i915.c b/sound/hda/hdac_i915.c
index 442500e06b7c..5676b849379d 100644
--- a/sound/hda/hdac_i915.c
+++ b/sound/hda/hdac_i915.c
@@ -56,8 +56,11 @@ int snd_hdac_display_power(struct hdac_bus *bus, bool enable)
56 enable ? "enable" : "disable"); 56 enable ? "enable" : "disable");
57 57
58 if (enable) { 58 if (enable) {
59 if (!bus->i915_power_refcount++) 59 if (!bus->i915_power_refcount++) {
60 acomp->ops->get_power(acomp->dev); 60 acomp->ops->get_power(acomp->dev);
61 snd_hdac_set_codec_wakeup(bus, true);
62 snd_hdac_set_codec_wakeup(bus, false);
63 }
61 } else { 64 } else {
62 WARN_ON(!bus->i915_power_refcount); 65 WARN_ON(!bus->i915_power_refcount);
63 if (!--bus->i915_power_refcount) 66 if (!--bus->i915_power_refcount)
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index ac0db1679f09..b077bb644434 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -5175,7 +5175,7 @@ static int alt_playback_pcm_open(struct hda_pcm_stream *hinfo,
5175 int err = 0; 5175 int err = 0;
5176 5176
5177 mutex_lock(&spec->pcm_mutex); 5177 mutex_lock(&spec->pcm_mutex);
5178 if (!spec->indep_hp_enabled) 5178 if (spec->indep_hp && !spec->indep_hp_enabled)
5179 err = -EBUSY; 5179 err = -EBUSY;
5180 else 5180 else
5181 spec->active_streams |= 1 << STREAM_INDEP_HP; 5181 spec->active_streams |= 1 << STREAM_INDEP_HP;
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 745535d1840a..c38c68f57938 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -867,7 +867,7 @@ static int azx_suspend(struct device *dev)
867 867
868 chip = card->private_data; 868 chip = card->private_data;
869 hda = container_of(chip, struct hda_intel, chip); 869 hda = container_of(chip, struct hda_intel, chip);
870 if (chip->disabled || hda->init_failed) 870 if (chip->disabled || hda->init_failed || !chip->running)
871 return 0; 871 return 0;
872 872
873 bus = azx_bus(chip); 873 bus = azx_bus(chip);
@@ -902,7 +902,7 @@ static int azx_resume(struct device *dev)
902 902
903 chip = card->private_data; 903 chip = card->private_data;
904 hda = container_of(chip, struct hda_intel, chip); 904 hda = container_of(chip, struct hda_intel, chip);
905 if (chip->disabled || hda->init_failed) 905 if (chip->disabled || hda->init_failed || !chip->running)
906 return 0; 906 return 0;
907 907
908 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL 908 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL
@@ -979,14 +979,16 @@ static int azx_runtime_resume(struct device *dev)
979 if (!azx_has_pm_runtime(chip)) 979 if (!azx_has_pm_runtime(chip))
980 return 0; 980 return 0;
981 981
982 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL 982 if (chip->driver_caps & AZX_DCAPS_I915_POWERWELL) {
983 && hda->need_i915_power) { 983 bus = azx_bus(chip);
984 bus = azx_bus(chip); 984 if (hda->need_i915_power) {
985 snd_hdac_display_power(bus, true); 985 snd_hdac_display_power(bus, true);
986 haswell_set_bclk(hda); 986 haswell_set_bclk(hda);
987 /* toggle codec wakeup bit for STATESTS read */ 987 } else {
988 snd_hdac_set_codec_wakeup(bus, true); 988 /* toggle codec wakeup bit for STATESTS read */
989 snd_hdac_set_codec_wakeup(bus, false); 989 snd_hdac_set_codec_wakeup(bus, true);
990 snd_hdac_set_codec_wakeup(bus, false);
991 }
990 } 992 }
991 993
992 /* Read STATESTS before controller reset */ 994 /* Read STATESTS before controller reset */
@@ -1025,7 +1027,7 @@ static int azx_runtime_idle(struct device *dev)
1025 return 0; 1027 return 0;
1026 1028
1027 if (!power_save_controller || !azx_has_pm_runtime(chip) || 1029 if (!power_save_controller || !azx_has_pm_runtime(chip) ||
1028 azx_bus(chip)->codec_powered) 1030 azx_bus(chip)->codec_powered || !chip->running)
1029 return -EBUSY; 1031 return -EBUSY;
1030 1032
1031 return 0; 1033 return 0;
@@ -2182,6 +2184,8 @@ static const struct pci_device_id azx_ids[] = {
2182 /* ATI HDMI */ 2184 /* ATI HDMI */
2183 { PCI_DEVICE(0x1002, 0x1308), 2185 { PCI_DEVICE(0x1002, 0x1308),
2184 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS }, 2186 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2187 { PCI_DEVICE(0x1002, 0x157a),
2188 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2185 { PCI_DEVICE(0x1002, 0x793b), 2189 { PCI_DEVICE(0x1002, 0x793b),
2186 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI }, 2190 .driver_data = AZX_DRIVER_ATIHDMI | AZX_DCAPS_PRESET_ATI_HDMI },
2187 { PCI_DEVICE(0x1002, 0x7919), 2191 { PCI_DEVICE(0x1002, 0x7919),
@@ -2236,8 +2240,14 @@ static const struct pci_device_id azx_ids[] = {
2236 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS }, 2240 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2237 { PCI_DEVICE(0x1002, 0xaab0), 2241 { PCI_DEVICE(0x1002, 0xaab0),
2238 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS }, 2242 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2243 { PCI_DEVICE(0x1002, 0xaac0),
2244 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2239 { PCI_DEVICE(0x1002, 0xaac8), 2245 { PCI_DEVICE(0x1002, 0xaac8),
2240 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS }, 2246 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2247 { PCI_DEVICE(0x1002, 0xaad8),
2248 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2249 { PCI_DEVICE(0x1002, 0xaae8),
2250 .driver_data = AZX_DRIVER_ATIHDMI_NS | AZX_DCAPS_PRESET_ATI_HDMI_NS },
2241 /* VIA VT8251/VT8237A */ 2251 /* VIA VT8251/VT8237A */
2242 { PCI_DEVICE(0x1106, 0x3288), 2252 { PCI_DEVICE(0x1106, 0x3288),
2243 .driver_data = AZX_DRIVER_VIA | AZX_DCAPS_POSFIX_VIA }, 2253 .driver_data = AZX_DRIVER_VIA | AZX_DCAPS_POSFIX_VIA },
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index 25ccf781fbe7..584a0343ab0c 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -999,9 +999,7 @@ static void cs4210_spdif_automute(struct hda_codec *codec,
999 999
1000 spec->spdif_present = spdif_present; 1000 spec->spdif_present = spdif_present;
1001 /* SPDIF TX on/off */ 1001 /* SPDIF TX on/off */
1002 if (spdif_present) 1002 snd_hda_set_pin_ctl(codec, spdif_pin, spdif_present ? PIN_OUT : 0);
1003 snd_hda_set_pin_ctl(codec, spdif_pin,
1004 spdif_present ? PIN_OUT : 0);
1005 1003
1006 cs_automute(codec); 1004 cs_automute(codec);
1007} 1005}
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 2f2433845d04..a97db5fc8a15 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -3512,6 +3512,7 @@ static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
3512{ .id = 0x10de0070, .name = "GPU 70 HDMI/DP", .patch = patch_nvhdmi }, 3512{ .id = 0x10de0070, .name = "GPU 70 HDMI/DP", .patch = patch_nvhdmi },
3513{ .id = 0x10de0071, .name = "GPU 71 HDMI/DP", .patch = patch_nvhdmi }, 3513{ .id = 0x10de0071, .name = "GPU 71 HDMI/DP", .patch = patch_nvhdmi },
3514{ .id = 0x10de0072, .name = "GPU 72 HDMI/DP", .patch = patch_nvhdmi }, 3514{ .id = 0x10de0072, .name = "GPU 72 HDMI/DP", .patch = patch_nvhdmi },
3515{ .id = 0x10de007d, .name = "GPU 7d HDMI/DP", .patch = patch_nvhdmi },
3515{ .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch }, 3516{ .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch },
3516{ .id = 0x11069f80, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi }, 3517{ .id = 0x11069f80, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
3517{ .id = 0x11069f81, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi }, 3518{ .id = 0x11069f81, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
@@ -3527,6 +3528,7 @@ static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
3527{ .id = 0x80862807, .name = "Haswell HDMI", .patch = patch_generic_hdmi }, 3528{ .id = 0x80862807, .name = "Haswell HDMI", .patch = patch_generic_hdmi },
3528{ .id = 0x80862808, .name = "Broadwell HDMI", .patch = patch_generic_hdmi }, 3529{ .id = 0x80862808, .name = "Broadwell HDMI", .patch = patch_generic_hdmi },
3529{ .id = 0x80862809, .name = "Skylake HDMI", .patch = patch_generic_hdmi }, 3530{ .id = 0x80862809, .name = "Skylake HDMI", .patch = patch_generic_hdmi },
3531{ .id = 0x8086280a, .name = "Broxton HDMI", .patch = patch_generic_hdmi },
3530{ .id = 0x80862880, .name = "CedarTrail HDMI", .patch = patch_generic_hdmi }, 3532{ .id = 0x80862880, .name = "CedarTrail HDMI", .patch = patch_generic_hdmi },
3531{ .id = 0x80862882, .name = "Valleyview2 HDMI", .patch = patch_generic_hdmi }, 3533{ .id = 0x80862882, .name = "Valleyview2 HDMI", .patch = patch_generic_hdmi },
3532{ .id = 0x80862883, .name = "Braswell HDMI", .patch = patch_generic_hdmi }, 3534{ .id = 0x80862883, .name = "Braswell HDMI", .patch = patch_generic_hdmi },
@@ -3575,6 +3577,7 @@ MODULE_ALIAS("snd-hda-codec-id:10de0067");
3575MODULE_ALIAS("snd-hda-codec-id:10de0070"); 3577MODULE_ALIAS("snd-hda-codec-id:10de0070");
3576MODULE_ALIAS("snd-hda-codec-id:10de0071"); 3578MODULE_ALIAS("snd-hda-codec-id:10de0071");
3577MODULE_ALIAS("snd-hda-codec-id:10de0072"); 3579MODULE_ALIAS("snd-hda-codec-id:10de0072");
3580MODULE_ALIAS("snd-hda-codec-id:10de007d");
3578MODULE_ALIAS("snd-hda-codec-id:10de8001"); 3581MODULE_ALIAS("snd-hda-codec-id:10de8001");
3579MODULE_ALIAS("snd-hda-codec-id:11069f80"); 3582MODULE_ALIAS("snd-hda-codec-id:11069f80");
3580MODULE_ALIAS("snd-hda-codec-id:11069f81"); 3583MODULE_ALIAS("snd-hda-codec-id:11069f81");
@@ -3591,6 +3594,7 @@ MODULE_ALIAS("snd-hda-codec-id:80862806");
3591MODULE_ALIAS("snd-hda-codec-id:80862807"); 3594MODULE_ALIAS("snd-hda-codec-id:80862807");
3592MODULE_ALIAS("snd-hda-codec-id:80862808"); 3595MODULE_ALIAS("snd-hda-codec-id:80862808");
3593MODULE_ALIAS("snd-hda-codec-id:80862809"); 3596MODULE_ALIAS("snd-hda-codec-id:80862809");
3597MODULE_ALIAS("snd-hda-codec-id:8086280a");
3594MODULE_ALIAS("snd-hda-codec-id:80862880"); 3598MODULE_ALIAS("snd-hda-codec-id:80862880");
3595MODULE_ALIAS("snd-hda-codec-id:80862882"); 3599MODULE_ALIAS("snd-hda-codec-id:80862882");
3596MODULE_ALIAS("snd-hda-codec-id:80862883"); 3600MODULE_ALIAS("snd-hda-codec-id:80862883");
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index b3b44681d3cf..374ea53288ca 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -2222,7 +2222,7 @@ static const struct snd_pci_quirk alc882_fixup_tbl[] = {
2222 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF), 2222 SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
2223 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF), 2223 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
2224 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF), 2224 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
2225 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF), 2225 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_MBA11_VREF),
2226 2226
2227 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD), 2227 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
2228 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD), 2228 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
@@ -4441,6 +4441,55 @@ static void alc290_fixup_mono_speakers(struct hda_codec *codec,
4441 } 4441 }
4442} 4442}
4443 4443
4444/* Hook to update amp GPIO4 for automute */
4445static void alc280_hp_gpio4_automute_hook(struct hda_codec *codec,
4446 struct hda_jack_callback *jack)
4447{
4448 struct alc_spec *spec = codec->spec;
4449
4450 snd_hda_gen_hp_automute(codec, jack);
4451 /* mute_led_polarity is set to 0, so we pass inverted value here */
4452 alc_update_gpio_led(codec, 0x10, !spec->gen.hp_jack_present);
4453}
4454
4455/* Manage GPIOs for HP EliteBook Folio 9480m.
4456 *
4457 * GPIO4 is the headphone amplifier power control
4458 * GPIO3 is the audio output mute indicator LED
4459 */
4460
4461static void alc280_fixup_hp_9480m(struct hda_codec *codec,
4462 const struct hda_fixup *fix,
4463 int action)
4464{
4465 struct alc_spec *spec = codec->spec;
4466 static const struct hda_verb gpio_init[] = {
4467 { 0x01, AC_VERB_SET_GPIO_MASK, 0x18 },
4468 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x18 },
4469 {}
4470 };
4471
4472 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
4473 /* Set the hooks to turn the headphone amp on/off
4474 * as needed
4475 */
4476 spec->gen.vmaster_mute.hook = alc_fixup_gpio_mute_hook;
4477 spec->gen.hp_automute_hook = alc280_hp_gpio4_automute_hook;
4478
4479 /* The GPIOs are currently off */
4480 spec->gpio_led = 0;
4481
4482 /* GPIO3 is connected to the output mute LED,
4483 * high is on, low is off
4484 */
4485 spec->mute_led_polarity = 0;
4486 spec->gpio_mute_led_mask = 0x08;
4487
4488 /* Initialize GPIO configuration */
4489 snd_hda_add_verbs(codec, gpio_init);
4490 }
4491}
4492
4444/* for hda_fixup_thinkpad_acpi() */ 4493/* for hda_fixup_thinkpad_acpi() */
4445#include "thinkpad_helper.c" 4494#include "thinkpad_helper.c"
4446 4495
@@ -4521,6 +4570,7 @@ enum {
4521 ALC286_FIXUP_HP_GPIO_LED, 4570 ALC286_FIXUP_HP_GPIO_LED,
4522 ALC280_FIXUP_HP_GPIO2_MIC_HOTKEY, 4571 ALC280_FIXUP_HP_GPIO2_MIC_HOTKEY,
4523 ALC280_FIXUP_HP_DOCK_PINS, 4572 ALC280_FIXUP_HP_DOCK_PINS,
4573 ALC280_FIXUP_HP_9480M,
4524 ALC288_FIXUP_DELL_HEADSET_MODE, 4574 ALC288_FIXUP_DELL_HEADSET_MODE,
4525 ALC288_FIXUP_DELL1_MIC_NO_PRESENCE, 4575 ALC288_FIXUP_DELL1_MIC_NO_PRESENCE,
4526 ALC288_FIXUP_DELL_XPS_13_GPIO6, 4576 ALC288_FIXUP_DELL_XPS_13_GPIO6,
@@ -5011,7 +5061,7 @@ static const struct hda_fixup alc269_fixups[] = {
5011 { 0x14, 0x90170110 }, 5061 { 0x14, 0x90170110 },
5012 { 0x17, 0x40000008 }, 5062 { 0x17, 0x40000008 },
5013 { 0x18, 0x411111f0 }, 5063 { 0x18, 0x411111f0 },
5014 { 0x19, 0x411111f0 }, 5064 { 0x19, 0x01a1913c },
5015 { 0x1a, 0x411111f0 }, 5065 { 0x1a, 0x411111f0 },
5016 { 0x1b, 0x411111f0 }, 5066 { 0x1b, 0x411111f0 },
5017 { 0x1d, 0x40f89b2d }, 5067 { 0x1d, 0x40f89b2d },
@@ -5043,6 +5093,10 @@ static const struct hda_fixup alc269_fixups[] = {
5043 .chained = true, 5093 .chained = true,
5044 .chain_id = ALC280_FIXUP_HP_GPIO4 5094 .chain_id = ALC280_FIXUP_HP_GPIO4
5045 }, 5095 },
5096 [ALC280_FIXUP_HP_9480M] = {
5097 .type = HDA_FIXUP_FUNC,
5098 .v.func = alc280_fixup_hp_9480m,
5099 },
5046 [ALC288_FIXUP_DELL_HEADSET_MODE] = { 5100 [ALC288_FIXUP_DELL_HEADSET_MODE] = {
5047 .type = HDA_FIXUP_FUNC, 5101 .type = HDA_FIXUP_FUNC,
5048 .v.func = alc_fixup_headset_mode_dell_alc288, 5102 .v.func = alc_fixup_headset_mode_dell_alc288,
@@ -5131,9 +5185,12 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5131 SND_PCI_QUIRK(0x1028, 0x064a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), 5185 SND_PCI_QUIRK(0x1028, 0x064a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
5132 SND_PCI_QUIRK(0x1028, 0x064b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), 5186 SND_PCI_QUIRK(0x1028, 0x064b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
5133 SND_PCI_QUIRK(0x1028, 0x0665, "Dell XPS 13", ALC288_FIXUP_DELL_XPS_13), 5187 SND_PCI_QUIRK(0x1028, 0x0665, "Dell XPS 13", ALC288_FIXUP_DELL_XPS_13),
5188 SND_PCI_QUIRK(0x1028, 0x069a, "Dell Vostro 5480", ALC290_FIXUP_SUBWOOFER_HSJACK),
5134 SND_PCI_QUIRK(0x1028, 0x06c7, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE), 5189 SND_PCI_QUIRK(0x1028, 0x06c7, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE),
5135 SND_PCI_QUIRK(0x1028, 0x06d9, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), 5190 SND_PCI_QUIRK(0x1028, 0x06d9, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
5136 SND_PCI_QUIRK(0x1028, 0x06da, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), 5191 SND_PCI_QUIRK(0x1028, 0x06da, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
5192 SND_PCI_QUIRK(0x1028, 0x06de, "Dell", ALC292_FIXUP_DISABLE_AAMIX),
5193 SND_PCI_QUIRK(0x1028, 0x06db, "Dell", ALC292_FIXUP_DISABLE_AAMIX),
5137 SND_PCI_QUIRK(0x1028, 0x164a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), 5194 SND_PCI_QUIRK(0x1028, 0x164a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
5138 SND_PCI_QUIRK(0x1028, 0x164b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), 5195 SND_PCI_QUIRK(0x1028, 0x164b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
5139 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2), 5196 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
@@ -5161,6 +5218,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5161 SND_PCI_QUIRK(0x103c, 0x22b7, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 5218 SND_PCI_QUIRK(0x103c, 0x22b7, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
5162 SND_PCI_QUIRK(0x103c, 0x22bf, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 5219 SND_PCI_QUIRK(0x103c, 0x22bf, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
5163 SND_PCI_QUIRK(0x103c, 0x22cf, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 5220 SND_PCI_QUIRK(0x103c, 0x22cf, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
5221 SND_PCI_QUIRK(0x103c, 0x22db, "HP", ALC280_FIXUP_HP_9480M),
5164 SND_PCI_QUIRK(0x103c, 0x22dc, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 5222 SND_PCI_QUIRK(0x103c, 0x22dc, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
5165 SND_PCI_QUIRK(0x103c, 0x22fb, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 5223 SND_PCI_QUIRK(0x103c, 0x22fb, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
5166 /* ALC290 */ 5224 /* ALC290 */
@@ -5234,6 +5292,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
5234 SND_PCI_QUIRK(0x17aa, 0x220c, "Thinkpad T440s", ALC292_FIXUP_TPT440_DOCK), 5292 SND_PCI_QUIRK(0x17aa, 0x220c, "Thinkpad T440s", ALC292_FIXUP_TPT440_DOCK),
5235 SND_PCI_QUIRK(0x17aa, 0x220e, "Thinkpad T440p", ALC292_FIXUP_TPT440_DOCK), 5293 SND_PCI_QUIRK(0x17aa, 0x220e, "Thinkpad T440p", ALC292_FIXUP_TPT440_DOCK),
5236 SND_PCI_QUIRK(0x17aa, 0x2210, "Thinkpad T540p", ALC292_FIXUP_TPT440_DOCK), 5294 SND_PCI_QUIRK(0x17aa, 0x2210, "Thinkpad T540p", ALC292_FIXUP_TPT440_DOCK),
5295 SND_PCI_QUIRK(0x17aa, 0x2211, "Thinkpad W541", ALC292_FIXUP_TPT440_DOCK),
5237 SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad T440", ALC292_FIXUP_TPT440_DOCK), 5296 SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad T440", ALC292_FIXUP_TPT440_DOCK),
5238 SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad X240", ALC292_FIXUP_TPT440_DOCK), 5297 SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad X240", ALC292_FIXUP_TPT440_DOCK),
5239 SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 5298 SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
@@ -5343,8 +5402,6 @@ static const struct hda_model_fixup alc269_fixup_models[] = {
5343 {0x19, 0x411111f0}, \ 5402 {0x19, 0x411111f0}, \
5344 {0x1a, 0x411111f0}, \ 5403 {0x1a, 0x411111f0}, \
5345 {0x1b, 0x411111f0}, \ 5404 {0x1b, 0x411111f0}, \
5346 {0x1d, 0x40700001}, \
5347 {0x1e, 0x411111f0}, \
5348 {0x21, 0x02211020} 5405 {0x21, 0x02211020}
5349 5406
5350#define ALC282_STANDARD_PINS \ 5407#define ALC282_STANDARD_PINS \
@@ -5375,8 +5432,7 @@ static const struct hda_model_fixup alc269_fixup_models[] = {
5375 {0x15, 0x0221401f}, \ 5432 {0x15, 0x0221401f}, \
5376 {0x1a, 0x411111f0}, \ 5433 {0x1a, 0x411111f0}, \
5377 {0x1b, 0x411111f0}, \ 5434 {0x1b, 0x411111f0}, \
5378 {0x1d, 0x40700001}, \ 5435 {0x1d, 0x40700001}
5379 {0x1e, 0x411111f0}
5380 5436
5381#define ALC298_STANDARD_PINS \ 5437#define ALC298_STANDARD_PINS \
5382 {0x18, 0x411111f0}, \ 5438 {0x18, 0x411111f0}, \
@@ -5408,6 +5464,39 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
5408 {0x1d, 0x40700001}, 5464 {0x1d, 0x40700001},
5409 {0x21, 0x02211030}), 5465 {0x21, 0x02211030}),
5410 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE, 5466 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5467 {0x12, 0x40000000},
5468 {0x14, 0x90170130},
5469 {0x17, 0x411111f0},
5470 {0x18, 0x411111f0},
5471 {0x19, 0x411111f0},
5472 {0x1a, 0x411111f0},
5473 {0x1b, 0x01014020},
5474 {0x1d, 0x4054c029},
5475 {0x1e, 0x411111f0},
5476 {0x21, 0x0221103f}),
5477 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5478 {0x12, 0x40000000},
5479 {0x14, 0x90170150},
5480 {0x17, 0x411111f0},
5481 {0x18, 0x411111f0},
5482 {0x19, 0x411111f0},
5483 {0x1a, 0x411111f0},
5484 {0x1b, 0x02011020},
5485 {0x1d, 0x4054c029},
5486 {0x1e, 0x411111f0},
5487 {0x21, 0x0221105f}),
5488 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5489 {0x12, 0x40000000},
5490 {0x14, 0x90170110},
5491 {0x17, 0x411111f0},
5492 {0x18, 0x411111f0},
5493 {0x19, 0x411111f0},
5494 {0x1a, 0x411111f0},
5495 {0x1b, 0x01014020},
5496 {0x1d, 0x4054c029},
5497 {0x1e, 0x411111f0},
5498 {0x21, 0x0221101f}),
5499 SND_HDA_PIN_QUIRK(0x10ec0255, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5411 {0x12, 0x90a60160}, 5500 {0x12, 0x90a60160},
5412 {0x14, 0x90170120}, 5501 {0x14, 0x90170120},
5413 {0x17, 0x90170140}, 5502 {0x17, 0x90170140},
@@ -5469,10 +5558,19 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
5469 {0x21, 0x02211030}), 5558 {0x21, 0x02211030}),
5470 SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE, 5559 SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5471 ALC256_STANDARD_PINS, 5560 ALC256_STANDARD_PINS,
5472 {0x13, 0x40000000}), 5561 {0x13, 0x40000000},
5562 {0x1d, 0x40700001},
5563 {0x1e, 0x411111f0}),
5564 SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5565 ALC256_STANDARD_PINS,
5566 {0x13, 0x411111f0},
5567 {0x1d, 0x40700001},
5568 {0x1e, 0x411111f0}),
5473 SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE, 5569 SND_HDA_PIN_QUIRK(0x10ec0256, 0x1028, "Dell", ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
5474 ALC256_STANDARD_PINS, 5570 ALC256_STANDARD_PINS,
5475 {0x13, 0x411111f0}), 5571 {0x13, 0x411111f0},
5572 {0x1d, 0x4077992d},
5573 {0x1e, 0x411111ff}),
5476 SND_HDA_PIN_QUIRK(0x10ec0280, 0x103c, "HP", ALC280_FIXUP_HP_GPIO4, 5574 SND_HDA_PIN_QUIRK(0x10ec0280, 0x103c, "HP", ALC280_FIXUP_HP_GPIO4,
5477 {0x12, 0x90a60130}, 5575 {0x12, 0x90a60130},
5478 {0x13, 0x40000000}, 5576 {0x13, 0x40000000},
@@ -5635,35 +5733,48 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
5635 {0x13, 0x411111f0}, 5733 {0x13, 0x411111f0},
5636 {0x16, 0x01014020}, 5734 {0x16, 0x01014020},
5637 {0x18, 0x411111f0}, 5735 {0x18, 0x411111f0},
5638 {0x19, 0x01a19030}), 5736 {0x19, 0x01a19030},
5737 {0x1e, 0x411111f0}),
5639 SND_HDA_PIN_QUIRK(0x10ec0292, 0x1028, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE, 5738 SND_HDA_PIN_QUIRK(0x10ec0292, 0x1028, "Dell", ALC269_FIXUP_DELL2_MIC_NO_PRESENCE,
5640 ALC292_STANDARD_PINS, 5739 ALC292_STANDARD_PINS,
5641 {0x12, 0x90a60140}, 5740 {0x12, 0x90a60140},
5642 {0x13, 0x411111f0}, 5741 {0x13, 0x411111f0},
5643 {0x16, 0x01014020}, 5742 {0x16, 0x01014020},
5644 {0x18, 0x02a19031}, 5743 {0x18, 0x02a19031},
5645 {0x19, 0x01a1903e}), 5744 {0x19, 0x01a1903e},
5745 {0x1e, 0x411111f0}),
5646 SND_HDA_PIN_QUIRK(0x10ec0292, 0x1028, "Dell", ALC269_FIXUP_DELL3_MIC_NO_PRESENCE, 5746 SND_HDA_PIN_QUIRK(0x10ec0292, 0x1028, "Dell", ALC269_FIXUP_DELL3_MIC_NO_PRESENCE,
5647 ALC292_STANDARD_PINS, 5747 ALC292_STANDARD_PINS,
5648 {0x12, 0x90a60140}, 5748 {0x12, 0x90a60140},
5649 {0x13, 0x411111f0}, 5749 {0x13, 0x411111f0},
5650 {0x16, 0x411111f0}, 5750 {0x16, 0x411111f0},
5651 {0x18, 0x411111f0}, 5751 {0x18, 0x411111f0},
5652 {0x19, 0x411111f0}), 5752 {0x19, 0x411111f0},
5753 {0x1e, 0x411111f0}),
5653 SND_HDA_PIN_QUIRK(0x10ec0293, 0x1028, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE, 5754 SND_HDA_PIN_QUIRK(0x10ec0293, 0x1028, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE,
5654 ALC292_STANDARD_PINS, 5755 ALC292_STANDARD_PINS,
5655 {0x12, 0x40000000}, 5756 {0x12, 0x40000000},
5656 {0x13, 0x90a60140}, 5757 {0x13, 0x90a60140},
5657 {0x16, 0x21014020}, 5758 {0x16, 0x21014020},
5658 {0x18, 0x411111f0}, 5759 {0x18, 0x411111f0},
5659 {0x19, 0x21a19030}), 5760 {0x19, 0x21a19030},
5761 {0x1e, 0x411111f0}),
5660 SND_HDA_PIN_QUIRK(0x10ec0293, 0x1028, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE, 5762 SND_HDA_PIN_QUIRK(0x10ec0293, 0x1028, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE,
5661 ALC292_STANDARD_PINS, 5763 ALC292_STANDARD_PINS,
5662 {0x12, 0x40000000}, 5764 {0x12, 0x40000000},
5663 {0x13, 0x90a60140}, 5765 {0x13, 0x90a60140},
5664 {0x16, 0x411111f0}, 5766 {0x16, 0x411111f0},
5665 {0x18, 0x411111f0}, 5767 {0x18, 0x411111f0},
5666 {0x19, 0x411111f0}), 5768 {0x19, 0x411111f0},
5769 {0x1e, 0x411111f0}),
5770 SND_HDA_PIN_QUIRK(0x10ec0293, 0x1028, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE,
5771 ALC292_STANDARD_PINS,
5772 {0x12, 0x40000000},
5773 {0x13, 0x90a60140},
5774 {0x16, 0x21014020},
5775 {0x18, 0x411111f0},
5776 {0x19, 0x21a19030},
5777 {0x1e, 0x411111ff}),
5667 SND_HDA_PIN_QUIRK(0x10ec0298, 0x1028, "Dell", ALC298_FIXUP_DELL1_MIC_NO_PRESENCE, 5778 SND_HDA_PIN_QUIRK(0x10ec0298, 0x1028, "Dell", ALC298_FIXUP_DELL1_MIC_NO_PRESENCE,
5668 ALC298_STANDARD_PINS, 5779 ALC298_STANDARD_PINS,
5669 {0x12, 0x90a60130}, 5780 {0x12, 0x90a60130},
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index dcc7fe91244c..9d947aef2c8b 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -2920,7 +2920,8 @@ static const struct snd_pci_quirk stac92hd83xxx_fixup_tbl[] = {
2920 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x148a, 2920 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x148a,
2921 "HP Mini", STAC_92HD83XXX_HP_LED), 2921 "HP Mini", STAC_92HD83XXX_HP_LED),
2922 SND_PCI_QUIRK_VENDOR(PCI_VENDOR_ID_HP, "HP", STAC_92HD83XXX_HP), 2922 SND_PCI_QUIRK_VENDOR(PCI_VENDOR_ID_HP, "HP", STAC_92HD83XXX_HP),
2923 SND_PCI_QUIRK(PCI_VENDOR_ID_TOSHIBA, 0xfa91, 2923 /* match both for 0xfa91 and 0xfa93 */
2924 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_TOSHIBA, 0xfffd, 0xfa91,
2924 "Toshiba Satellite S50D", STAC_92HD83XXX_GPIO10_EAPD), 2925 "Toshiba Satellite S50D", STAC_92HD83XXX_GPIO10_EAPD),
2925 {} /* terminator */ 2926 {} /* terminator */
2926}; 2927};
diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index 6492bca8c70f..4ca12665ff73 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -88,7 +88,7 @@ static int dac_mute_put(struct snd_kcontrol *ctl,
88 int changed; 88 int changed;
89 89
90 mutex_lock(&chip->mutex); 90 mutex_lock(&chip->mutex);
91 changed = !value->value.integer.value[0] != chip->dac_mute; 91 changed = (!value->value.integer.value[0]) != chip->dac_mute;
92 if (changed) { 92 if (changed) {
93 chip->dac_mute = !value->value.integer.value[0]; 93 chip->dac_mute = !value->value.integer.value[0];
94 chip->model.update_dac_mute(chip); 94 chip->model.update_dac_mute(chip);
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig
index 2ae9619443d1..225bfda414e9 100644
--- a/sound/soc/Kconfig
+++ b/sound/soc/Kconfig
@@ -30,6 +30,9 @@ config SND_SOC_GENERIC_DMAENGINE_PCM
30 bool 30 bool
31 select SND_DMAENGINE_PCM 31 select SND_DMAENGINE_PCM
32 32
33config SND_SOC_TOPOLOGY
34 bool
35
33# All the supported SoCs 36# All the supported SoCs
34source "sound/soc/adi/Kconfig" 37source "sound/soc/adi/Kconfig"
35source "sound/soc/atmel/Kconfig" 38source "sound/soc/atmel/Kconfig"
@@ -54,6 +57,7 @@ source "sound/soc/samsung/Kconfig"
54source "sound/soc/sh/Kconfig" 57source "sound/soc/sh/Kconfig"
55source "sound/soc/sirf/Kconfig" 58source "sound/soc/sirf/Kconfig"
56source "sound/soc/spear/Kconfig" 59source "sound/soc/spear/Kconfig"
60source "sound/soc/sti/Kconfig"
57source "sound/soc/tegra/Kconfig" 61source "sound/soc/tegra/Kconfig"
58source "sound/soc/txx9/Kconfig" 62source "sound/soc/txx9/Kconfig"
59source "sound/soc/ux500/Kconfig" 63source "sound/soc/ux500/Kconfig"
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index e189903fabf4..134aca150a50 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -1,6 +1,9 @@
1snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o 1snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o
2snd-soc-core-objs += soc-pcm.o soc-compress.o soc-io.o soc-devres.o soc-ops.o 2snd-soc-core-objs += soc-pcm.o soc-compress.o soc-io.o soc-devres.o soc-ops.o
3
4ifneq ($(CONFIG_SND_SOC_TOPOLOGY),)
3snd-soc-core-objs += soc-topology.o 5snd-soc-core-objs += soc-topology.o
6endif
4 7
5ifneq ($(CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM),) 8ifneq ($(CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM),)
6snd-soc-core-objs += soc-generic-dmaengine-pcm.o 9snd-soc-core-objs += soc-generic-dmaengine-pcm.o
@@ -36,6 +39,7 @@ obj-$(CONFIG_SND_SOC) += samsung/
36obj-$(CONFIG_SND_SOC) += sh/ 39obj-$(CONFIG_SND_SOC) += sh/
37obj-$(CONFIG_SND_SOC) += sirf/ 40obj-$(CONFIG_SND_SOC) += sirf/
38obj-$(CONFIG_SND_SOC) += spear/ 41obj-$(CONFIG_SND_SOC) += spear/
42obj-$(CONFIG_SND_SOC) += sti/
39obj-$(CONFIG_SND_SOC) += tegra/ 43obj-$(CONFIG_SND_SOC) += tegra/
40obj-$(CONFIG_SND_SOC) += txx9/ 44obj-$(CONFIG_SND_SOC) += txx9/
41obj-$(CONFIG_SND_SOC) += ux500/ 45obj-$(CONFIG_SND_SOC) += ux500/
diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c
index 841d05946b88..ba8def5665c4 100644
--- a/sound/soc/atmel/atmel_ssc_dai.c
+++ b/sound/soc/atmel/atmel_ssc_dai.c
@@ -290,7 +290,7 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream,
290 int dir, dir_mask; 290 int dir, dir_mask;
291 int ret; 291 int ret;
292 292
293 pr_debug("atmel_ssc_startup: SSC_SR=0x%u\n", 293 pr_debug("atmel_ssc_startup: SSC_SR=0x%x\n",
294 ssc_readl(ssc_p->ssc->regs, SR)); 294 ssc_readl(ssc_p->ssc->regs, SR));
295 295
296 /* Enable PMC peripheral clock for this SSC */ 296 /* Enable PMC peripheral clock for this SSC */
diff --git a/sound/soc/au1x/dbdma2.c b/sound/soc/au1x/dbdma2.c
index dd94fea72d5d..5741c0aa6c03 100644
--- a/sound/soc/au1x/dbdma2.c
+++ b/sound/soc/au1x/dbdma2.c
@@ -344,14 +344,8 @@ static int au1xpsc_pcm_drvprobe(struct platform_device *pdev)
344 344
345 platform_set_drvdata(pdev, dmadata); 345 platform_set_drvdata(pdev, dmadata);
346 346
347 return snd_soc_register_platform(&pdev->dev, &au1xpsc_soc_platform); 347 return devm_snd_soc_register_platform(&pdev->dev,
348} 348 &au1xpsc_soc_platform);
349
350static int au1xpsc_pcm_drvremove(struct platform_device *pdev)
351{
352 snd_soc_unregister_platform(&pdev->dev);
353
354 return 0;
355} 349}
356 350
357static struct platform_driver au1xpsc_pcm_driver = { 351static struct platform_driver au1xpsc_pcm_driver = {
@@ -359,7 +353,6 @@ static struct platform_driver au1xpsc_pcm_driver = {
359 .name = "au1xpsc-pcm", 353 .name = "au1xpsc-pcm",
360 }, 354 },
361 .probe = au1xpsc_pcm_drvprobe, 355 .probe = au1xpsc_pcm_drvprobe,
362 .remove = au1xpsc_pcm_drvremove,
363}; 356};
364 357
365module_platform_driver(au1xpsc_pcm_driver); 358module_platform_driver(au1xpsc_pcm_driver);
diff --git a/sound/soc/au1x/dma.c b/sound/soc/au1x/dma.c
index 24cc7f40d87a..fcf5a9adde81 100644
--- a/sound/soc/au1x/dma.c
+++ b/sound/soc/au1x/dma.c
@@ -312,14 +312,8 @@ static int alchemy_pcm_drvprobe(struct platform_device *pdev)
312 312
313 platform_set_drvdata(pdev, ctx); 313 platform_set_drvdata(pdev, ctx);
314 314
315 return snd_soc_register_platform(&pdev->dev, &alchemy_pcm_soc_platform); 315 return devm_snd_soc_register_platform(&pdev->dev,
316} 316 &alchemy_pcm_soc_platform);
317
318static int alchemy_pcm_drvremove(struct platform_device *pdev)
319{
320 snd_soc_unregister_platform(&pdev->dev);
321
322 return 0;
323} 317}
324 318
325static struct platform_driver alchemy_pcmdma_driver = { 319static struct platform_driver alchemy_pcmdma_driver = {
@@ -327,7 +321,6 @@ static struct platform_driver alchemy_pcmdma_driver = {
327 .name = "alchemy-pcm-dma", 321 .name = "alchemy-pcm-dma",
328 }, 322 },
329 .probe = alchemy_pcm_drvprobe, 323 .probe = alchemy_pcm_drvprobe,
330 .remove = alchemy_pcm_drvremove,
331}; 324};
332 325
333module_platform_driver(alchemy_pcmdma_driver); 326module_platform_driver(alchemy_pcmdma_driver);
diff --git a/sound/soc/au1x/psc-i2s.c b/sound/soc/au1x/psc-i2s.c
index e742ef668496..38e853add96e 100644
--- a/sound/soc/au1x/psc-i2s.c
+++ b/sound/soc/au1x/psc-i2s.c
@@ -305,19 +305,9 @@ static int au1xpsc_i2s_drvprobe(struct platform_device *pdev)
305 return -ENOMEM; 305 return -ENOMEM;
306 306
307 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 307 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
308 if (!iores) 308 wd->mmio = devm_ioremap_resource(&pdev->dev, iores);
309 return -ENODEV; 309 if (IS_ERR(wd->mmio))
310 310 return PTR_ERR(wd->mmio);
311 ret = -EBUSY;
312 if (!devm_request_mem_region(&pdev->dev, iores->start,
313 resource_size(iores),
314 pdev->name))
315 return -EBUSY;
316
317 wd->mmio = devm_ioremap(&pdev->dev, iores->start,
318 resource_size(iores));
319 if (!wd->mmio)
320 return -EBUSY;
321 311
322 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0); 312 dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0);
323 if (!dmares) 313 if (!dmares)
diff --git a/sound/soc/bcm/bcm2835-i2s.c b/sound/soc/bcm/bcm2835-i2s.c
index 03fa1cbf8ec1..8c435beb263d 100644
--- a/sound/soc/bcm/bcm2835-i2s.c
+++ b/sound/soc/bcm/bcm2835-i2s.c
@@ -862,6 +862,8 @@ static const struct of_device_id bcm2835_i2s_of_match[] = {
862 {}, 862 {},
863}; 863};
864 864
865MODULE_DEVICE_TABLE(of, bcm2835_i2s_of_match);
866
865static struct platform_driver bcm2835_i2s_driver = { 867static struct platform_driver bcm2835_i2s_driver = {
866 .probe = bcm2835_i2s_probe, 868 .probe = bcm2835_i2s_probe,
867 .driver = { 869 .driver = {
diff --git a/sound/soc/blackfin/bf5xx-ac97-pcm.c b/sound/soc/blackfin/bf5xx-ac97-pcm.c
index 238913e030e0..02ad2606fa19 100644
--- a/sound/soc/blackfin/bf5xx-ac97-pcm.c
+++ b/sound/soc/blackfin/bf5xx-ac97-pcm.c
@@ -450,13 +450,8 @@ static struct snd_soc_platform_driver bf5xx_ac97_soc_platform = {
450 450
451static int bf5xx_soc_platform_probe(struct platform_device *pdev) 451static int bf5xx_soc_platform_probe(struct platform_device *pdev)
452{ 452{
453 return snd_soc_register_platform(&pdev->dev, &bf5xx_ac97_soc_platform); 453 return devm_snd_soc_register_platform(&pdev->dev,
454} 454 &bf5xx_ac97_soc_platform);
455
456static int bf5xx_soc_platform_remove(struct platform_device *pdev)
457{
458 snd_soc_unregister_platform(&pdev->dev);
459 return 0;
460} 455}
461 456
462static struct platform_driver bf5xx_pcm_driver = { 457static struct platform_driver bf5xx_pcm_driver = {
@@ -465,7 +460,6 @@ static struct platform_driver bf5xx_pcm_driver = {
465 }, 460 },
466 461
467 .probe = bf5xx_soc_platform_probe, 462 .probe = bf5xx_soc_platform_probe,
468 .remove = bf5xx_soc_platform_remove,
469}; 463};
470 464
471module_platform_driver(bf5xx_pcm_driver); 465module_platform_driver(bf5xx_pcm_driver);
diff --git a/sound/soc/blackfin/bf5xx-i2s-pcm.c b/sound/soc/blackfin/bf5xx-i2s-pcm.c
index d95477afcc67..6cba211da32e 100644
--- a/sound/soc/blackfin/bf5xx-i2s-pcm.c
+++ b/sound/soc/blackfin/bf5xx-i2s-pcm.c
@@ -342,13 +342,8 @@ static struct snd_soc_platform_driver bf5xx_i2s_soc_platform = {
342 342
343static int bfin_i2s_soc_platform_probe(struct platform_device *pdev) 343static int bfin_i2s_soc_platform_probe(struct platform_device *pdev)
344{ 344{
345 return snd_soc_register_platform(&pdev->dev, &bf5xx_i2s_soc_platform); 345 return devm_snd_soc_register_platform(&pdev->dev,
346} 346 &bf5xx_i2s_soc_platform);
347
348static int bfin_i2s_soc_platform_remove(struct platform_device *pdev)
349{
350 snd_soc_unregister_platform(&pdev->dev);
351 return 0;
352} 347}
353 348
354static struct platform_driver bfin_i2s_pcm_driver = { 349static struct platform_driver bfin_i2s_pcm_driver = {
@@ -357,7 +352,6 @@ static struct platform_driver bfin_i2s_pcm_driver = {
357 }, 352 },
358 353
359 .probe = bfin_i2s_soc_platform_probe, 354 .probe = bfin_i2s_soc_platform_probe,
360 .remove = bfin_i2s_soc_platform_remove,
361}; 355};
362 356
363module_platform_driver(bfin_i2s_pcm_driver); 357module_platform_driver(bfin_i2s_pcm_driver);
diff --git a/sound/soc/blackfin/bfin-eval-adau1x61.c b/sound/soc/blackfin/bfin-eval-adau1x61.c
index 4229f76daec9..fddfe00c9d69 100644
--- a/sound/soc/blackfin/bfin-eval-adau1x61.c
+++ b/sound/soc/blackfin/bfin-eval-adau1x61.c
@@ -108,6 +108,7 @@ static struct snd_soc_dai_link bfin_eval_adau1x61_dai = {
108 108
109static struct snd_soc_card bfin_eval_adau1x61 = { 109static struct snd_soc_card bfin_eval_adau1x61 = {
110 .name = "bfin-eval-adau1x61", 110 .name = "bfin-eval-adau1x61",
111 .owner = THIS_MODULE,
111 .driver_name = "eval-adau1x61", 112 .driver_name = "eval-adau1x61",
112 .dai_link = &bfin_eval_adau1x61_dai, 113 .dai_link = &bfin_eval_adau1x61_dai,
113 .num_links = 1, 114 .num_links = 1,
diff --git a/sound/soc/codecs/88pm860x-codec.c b/sound/soc/codecs/88pm860x-codec.c
index 38b3dad9d48a..4d91a6aa696b 100644
--- a/sound/soc/codecs/88pm860x-codec.c
+++ b/sound/soc/codecs/88pm860x-codec.c
@@ -1028,10 +1028,8 @@ static int pm860x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
1028 1028
1029 if (dir == PM860X_CLK_DIR_OUT) 1029 if (dir == PM860X_CLK_DIR_OUT)
1030 pm860x->dir = PM860X_CLK_DIR_OUT; 1030 pm860x->dir = PM860X_CLK_DIR_OUT;
1031 else { 1031 else /* Slave mode is not supported */
1032 pm860x->dir = PM860X_CLK_DIR_IN;
1033 return -EINVAL; 1032 return -EINVAL;
1034 }
1035 1033
1036 return 0; 1034 return 0;
1037} 1035}
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index e20834818bcb..0c9733ecd17f 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -53,6 +53,7 @@ config SND_SOC_ALL_CODECS
53 select SND_SOC_CS4271_I2C if I2C 53 select SND_SOC_CS4271_I2C if I2C
54 select SND_SOC_CS4271_SPI if SPI_MASTER 54 select SND_SOC_CS4271_SPI if SPI_MASTER
55 select SND_SOC_CS42XX8_I2C if I2C 55 select SND_SOC_CS42XX8_I2C if I2C
56 select SND_SOC_CS4349 if I2C
56 select SND_SOC_CX20442 if TTY 57 select SND_SOC_CX20442 if TTY
57 select SND_SOC_DA7210 if SND_SOC_I2C_AND_SPI 58 select SND_SOC_DA7210 if SND_SOC_I2C_AND_SPI
58 select SND_SOC_DA7213 if I2C 59 select SND_SOC_DA7213 if I2C
@@ -62,6 +63,8 @@ config SND_SOC_ALL_CODECS
62 select SND_SOC_BT_SCO 63 select SND_SOC_BT_SCO
63 select SND_SOC_ES8328_SPI if SPI_MASTER 64 select SND_SOC_ES8328_SPI if SPI_MASTER
64 select SND_SOC_ES8328_I2C if I2C 65 select SND_SOC_ES8328_I2C if I2C
66 select SND_SOC_GTM601
67 select SND_SOC_ICS43432
65 select SND_SOC_ISABELLE if I2C 68 select SND_SOC_ISABELLE if I2C
66 select SND_SOC_JZ4740_CODEC 69 select SND_SOC_JZ4740_CODEC
67 select SND_SOC_LM4857 if I2C 70 select SND_SOC_LM4857 if I2C
@@ -83,6 +86,7 @@ config SND_SOC_ALL_CODECS
83 select SND_SOC_PCM512x_I2C if I2C 86 select SND_SOC_PCM512x_I2C if I2C
84 select SND_SOC_PCM512x_SPI if SPI_MASTER 87 select SND_SOC_PCM512x_SPI if SPI_MASTER
85 select SND_SOC_RT286 if I2C 88 select SND_SOC_RT286 if I2C
89 select SND_SOC_RT298 if I2C
86 select SND_SOC_RT5631 if I2C 90 select SND_SOC_RT5631 if I2C
87 select SND_SOC_RT5640 if I2C 91 select SND_SOC_RT5640 if I2C
88 select SND_SOC_RT5645 if I2C 92 select SND_SOC_RT5645 if I2C
@@ -404,6 +408,11 @@ config SND_SOC_CS42XX8_I2C
404 select SND_SOC_CS42XX8 408 select SND_SOC_CS42XX8
405 select REGMAP_I2C 409 select REGMAP_I2C
406 410
411# Cirrus Logic CS4349 HiFi DAC
412config SND_SOC_CS4349
413 tristate "Cirrus Logic CS4349 CODEC"
414 depends on I2C
415
407config SND_SOC_CX20442 416config SND_SOC_CX20442
408 tristate 417 tristate
409 depends on TTY 418 depends on TTY
@@ -447,6 +456,12 @@ config SND_SOC_ES8328_SPI
447 tristate 456 tristate
448 select SND_SOC_ES8328 457 select SND_SOC_ES8328
449 458
459config SND_SOC_GTM601
460 tristate 'GTM601 UMTS modem audio codec'
461
462config SND_SOC_ICS43432
463 tristate
464
450config SND_SOC_ISABELLE 465config SND_SOC_ISABELLE
451 tristate 466 tristate
452 467
@@ -513,12 +528,18 @@ config SND_SOC_RL6231
513config SND_SOC_RL6347A 528config SND_SOC_RL6347A
514 tristate 529 tristate
515 default y if SND_SOC_RT286=y 530 default y if SND_SOC_RT286=y
531 default y if SND_SOC_RT298=y
516 default m if SND_SOC_RT286=m 532 default m if SND_SOC_RT286=m
533 default m if SND_SOC_RT298=m
517 534
518config SND_SOC_RT286 535config SND_SOC_RT286
519 tristate 536 tristate
520 depends on I2C 537 depends on I2C
521 538
539config SND_SOC_RT298
540 tristate
541 depends on I2C
542
522config SND_SOC_RT5631 543config SND_SOC_RT5631
523 tristate "Realtek ALC5631/RT5631 CODEC" 544 tristate "Realtek ALC5631/RT5631 CODEC"
524 depends on I2C 545 depends on I2C
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 7b4ce1b6e624..4a32077954ae 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -45,6 +45,7 @@ snd-soc-cs4271-i2c-objs := cs4271-i2c.o
45snd-soc-cs4271-spi-objs := cs4271-spi.o 45snd-soc-cs4271-spi-objs := cs4271-spi.o
46snd-soc-cs42xx8-objs := cs42xx8.o 46snd-soc-cs42xx8-objs := cs42xx8.o
47snd-soc-cs42xx8-i2c-objs := cs42xx8-i2c.o 47snd-soc-cs42xx8-i2c-objs := cs42xx8-i2c.o
48snd-soc-cs4349-objs := cs4349.o
48snd-soc-cx20442-objs := cx20442.o 49snd-soc-cx20442-objs := cx20442.o
49snd-soc-da7210-objs := da7210.o 50snd-soc-da7210-objs := da7210.o
50snd-soc-da7213-objs := da7213.o 51snd-soc-da7213-objs := da7213.o
@@ -55,6 +56,8 @@ snd-soc-dmic-objs := dmic.o
55snd-soc-es8328-objs := es8328.o 56snd-soc-es8328-objs := es8328.o
56snd-soc-es8328-i2c-objs := es8328-i2c.o 57snd-soc-es8328-i2c-objs := es8328-i2c.o
57snd-soc-es8328-spi-objs := es8328-spi.o 58snd-soc-es8328-spi-objs := es8328-spi.o
59snd-soc-gtm601-objs := gtm601.o
60snd-soc-ics43432-objs := ics43432.o
58snd-soc-isabelle-objs := isabelle.o 61snd-soc-isabelle-objs := isabelle.o
59snd-soc-jz4740-codec-objs := jz4740.o 62snd-soc-jz4740-codec-objs := jz4740.o
60snd-soc-l3-objs := l3.o 63snd-soc-l3-objs := l3.o
@@ -79,6 +82,7 @@ snd-soc-pcm512x-spi-objs := pcm512x-spi.o
79snd-soc-rl6231-objs := rl6231.o 82snd-soc-rl6231-objs := rl6231.o
80snd-soc-rl6347a-objs := rl6347a.o 83snd-soc-rl6347a-objs := rl6347a.o
81snd-soc-rt286-objs := rt286.o 84snd-soc-rt286-objs := rt286.o
85snd-soc-rt298-objs := rt298.o
82snd-soc-rt5631-objs := rt5631.o 86snd-soc-rt5631-objs := rt5631.o
83snd-soc-rt5640-objs := rt5640.o 87snd-soc-rt5640-objs := rt5640.o
84snd-soc-rt5645-objs := rt5645.o 88snd-soc-rt5645-objs := rt5645.o
@@ -233,6 +237,7 @@ obj-$(CONFIG_SND_SOC_CS4271_I2C) += snd-soc-cs4271-i2c.o
233obj-$(CONFIG_SND_SOC_CS4271_SPI) += snd-soc-cs4271-spi.o 237obj-$(CONFIG_SND_SOC_CS4271_SPI) += snd-soc-cs4271-spi.o
234obj-$(CONFIG_SND_SOC_CS42XX8) += snd-soc-cs42xx8.o 238obj-$(CONFIG_SND_SOC_CS42XX8) += snd-soc-cs42xx8.o
235obj-$(CONFIG_SND_SOC_CS42XX8_I2C) += snd-soc-cs42xx8-i2c.o 239obj-$(CONFIG_SND_SOC_CS42XX8_I2C) += snd-soc-cs42xx8-i2c.o
240obj-$(CONFIG_SND_SOC_CS4349) += snd-soc-cs4349.o
236obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o 241obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o
237obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o 242obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o
238obj-$(CONFIG_SND_SOC_DA7213) += snd-soc-da7213.o 243obj-$(CONFIG_SND_SOC_DA7213) += snd-soc-da7213.o
@@ -243,6 +248,8 @@ obj-$(CONFIG_SND_SOC_DMIC) += snd-soc-dmic.o
243obj-$(CONFIG_SND_SOC_ES8328) += snd-soc-es8328.o 248obj-$(CONFIG_SND_SOC_ES8328) += snd-soc-es8328.o
244obj-$(CONFIG_SND_SOC_ES8328_I2C)+= snd-soc-es8328-i2c.o 249obj-$(CONFIG_SND_SOC_ES8328_I2C)+= snd-soc-es8328-i2c.o
245obj-$(CONFIG_SND_SOC_ES8328_SPI)+= snd-soc-es8328-spi.o 250obj-$(CONFIG_SND_SOC_ES8328_SPI)+= snd-soc-es8328-spi.o
251obj-$(CONFIG_SND_SOC_GTM601) += snd-soc-gtm601.o
252obj-$(CONFIG_SND_SOC_ICS43432) += snd-soc-ics43432.o
246obj-$(CONFIG_SND_SOC_ISABELLE) += snd-soc-isabelle.o 253obj-$(CONFIG_SND_SOC_ISABELLE) += snd-soc-isabelle.o
247obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o 254obj-$(CONFIG_SND_SOC_JZ4740_CODEC) += snd-soc-jz4740-codec.o
248obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o 255obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
@@ -267,6 +274,7 @@ obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o
267obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o 274obj-$(CONFIG_SND_SOC_RL6231) += snd-soc-rl6231.o
268obj-$(CONFIG_SND_SOC_RL6347A) += snd-soc-rl6347a.o 275obj-$(CONFIG_SND_SOC_RL6347A) += snd-soc-rl6347a.o
269obj-$(CONFIG_SND_SOC_RT286) += snd-soc-rt286.o 276obj-$(CONFIG_SND_SOC_RT286) += snd-soc-rt286.o
277obj-$(CONFIG_SND_SOC_RT298) += snd-soc-rt298.o
270obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o 278obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
271obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o 279obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
272obj-$(CONFIG_SND_SOC_RT5645) += snd-soc-rt5645.o 280obj-$(CONFIG_SND_SOC_RT5645) += snd-soc-rt5645.o
diff --git a/sound/soc/codecs/ad1980.c b/sound/soc/codecs/ad1980.c
index 3cc69a626454..9ef20dbccbe3 100644
--- a/sound/soc/codecs/ad1980.c
+++ b/sound/soc/codecs/ad1980.c
@@ -202,19 +202,21 @@ static struct snd_soc_dai_driver ad1980_dai = {
202 .formats = SND_SOC_STD_AC97_FMTS, }, 202 .formats = SND_SOC_STD_AC97_FMTS, },
203}; 203};
204 204
205#define AD1980_VENDOR_ID 0x41445300
206#define AD1980_VENDOR_MASK 0xffffff00
207
205static int ad1980_reset(struct snd_soc_codec *codec, int try_warm) 208static int ad1980_reset(struct snd_soc_codec *codec, int try_warm)
206{ 209{
207 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec); 210 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
208 unsigned int retry_cnt = 0; 211 unsigned int retry_cnt = 0;
212 int ret;
209 213
210 do { 214 do {
211 if (try_warm && soc_ac97_ops->warm_reset) { 215 ret = snd_ac97_reset(ac97, true, AD1980_VENDOR_ID,
212 soc_ac97_ops->warm_reset(ac97); 216 AD1980_VENDOR_MASK);
213 if (snd_soc_read(codec, AC97_RESET) == 0x0090) 217 if (ret >= 0)
214 return 1; 218 return 0;
215 }
216 219
217 soc_ac97_ops->reset(ac97);
218 /* 220 /*
219 * Set bit 16slot in register 74h, then every slot will has only 221 * Set bit 16slot in register 74h, then every slot will has only
220 * 16 bits. This command is sent out in 20bit mode, in which 222 * 16 bits. This command is sent out in 20bit mode, in which
@@ -223,8 +225,6 @@ static int ad1980_reset(struct snd_soc_codec *codec, int try_warm)
223 */ 225 */
224 snd_soc_write(codec, AC97_AD_SERIAL_CFG, 0x9900); 226 snd_soc_write(codec, AC97_AD_SERIAL_CFG, 0x9900);
225 227
226 if (snd_soc_read(codec, AC97_RESET) == 0x0090)
227 return 0;
228 } while (retry_cnt++ < 10); 228 } while (retry_cnt++ < 10);
229 229
230 dev_err(codec->dev, "Failed to reset: AC97 link error\n"); 230 dev_err(codec->dev, "Failed to reset: AC97 link error\n");
@@ -240,7 +240,7 @@ static int ad1980_soc_probe(struct snd_soc_codec *codec)
240 u16 vendor_id2; 240 u16 vendor_id2;
241 u16 ext_status; 241 u16 ext_status;
242 242
243 ac97 = snd_soc_new_ac97_codec(codec); 243 ac97 = snd_soc_new_ac97_codec(codec, 0, 0);
244 if (IS_ERR(ac97)) { 244 if (IS_ERR(ac97)) {
245 ret = PTR_ERR(ac97); 245 ret = PTR_ERR(ac97);
246 dev_err(codec->dev, "Failed to register AC97 codec: %d\n", ret); 246 dev_err(codec->dev, "Failed to register AC97 codec: %d\n", ret);
@@ -260,22 +260,10 @@ static int ad1980_soc_probe(struct snd_soc_codec *codec)
260 if (ret < 0) 260 if (ret < 0)
261 goto reset_err; 261 goto reset_err;
262 262
263 /* Read out vendor ID to make sure it is ad1980 */
264 if (snd_soc_read(codec, AC97_VENDOR_ID1) != 0x4144) {
265 ret = -ENODEV;
266 goto reset_err;
267 }
268
269 vendor_id2 = snd_soc_read(codec, AC97_VENDOR_ID2); 263 vendor_id2 = snd_soc_read(codec, AC97_VENDOR_ID2);
270 264 if (vendor_id2 == 0x5374) {
271 if (vendor_id2 != 0x5370) { 265 dev_warn(codec->dev,
272 if (vendor_id2 != 0x5374) { 266 "Found AD1981 - only 2/2 IN/OUT Channels supported\n");
273 ret = -ENODEV;
274 goto reset_err;
275 } else {
276 dev_warn(codec->dev,
277 "Found AD1981 - only 2/2 IN/OUT Channels supported\n");
278 }
279 } 267 }
280 268
281 /* unmute captures and playbacks volume */ 269 /* unmute captures and playbacks volume */
diff --git a/sound/soc/codecs/adau1373.c b/sound/soc/codecs/adau1373.c
index a43160254929..6c96860f46de 100644
--- a/sound/soc/codecs/adau1373.c
+++ b/sound/soc/codecs/adau1373.c
@@ -1534,7 +1534,6 @@ MODULE_DEVICE_TABLE(i2c, adau1373_i2c_id);
1534static struct i2c_driver adau1373_i2c_driver = { 1534static struct i2c_driver adau1373_i2c_driver = {
1535 .driver = { 1535 .driver = {
1536 .name = "adau1373", 1536 .name = "adau1373",
1537 .owner = THIS_MODULE,
1538 }, 1537 },
1539 .probe = adau1373_i2c_probe, 1538 .probe = adau1373_i2c_probe,
1540 .remove = adau1373_i2c_remove, 1539 .remove = adau1373_i2c_remove,
diff --git a/sound/soc/codecs/adau1701.c b/sound/soc/codecs/adau1701.c
index ff7f846e3b76..de53c0d7bf10 100644
--- a/sound/soc/codecs/adau1701.c
+++ b/sound/soc/codecs/adau1701.c
@@ -915,7 +915,6 @@ MODULE_DEVICE_TABLE(i2c, adau1701_i2c_id);
915static struct i2c_driver adau1701_i2c_driver = { 915static struct i2c_driver adau1701_i2c_driver = {
916 .driver = { 916 .driver = {
917 .name = "adau1701", 917 .name = "adau1701",
918 .owner = THIS_MODULE,
919 .of_match_table = of_match_ptr(adau1701_dt_ids), 918 .of_match_table = of_match_ptr(adau1701_dt_ids),
920 }, 919 },
921 .probe = adau1701_i2c_probe, 920 .probe = adau1701_i2c_probe,
diff --git a/sound/soc/codecs/adau1761-i2c.c b/sound/soc/codecs/adau1761-i2c.c
index 862796dec693..348ccb17d3cc 100644
--- a/sound/soc/codecs/adau1761-i2c.c
+++ b/sound/soc/codecs/adau1761-i2c.c
@@ -47,7 +47,6 @@ MODULE_DEVICE_TABLE(i2c, adau1761_i2c_ids);
47static struct i2c_driver adau1761_i2c_driver = { 47static struct i2c_driver adau1761_i2c_driver = {
48 .driver = { 48 .driver = {
49 .name = "adau1761", 49 .name = "adau1761",
50 .owner = THIS_MODULE,
51 }, 50 },
52 .probe = adau1761_i2c_probe, 51 .probe = adau1761_i2c_probe,
53 .remove = adau1761_i2c_remove, 52 .remove = adau1761_i2c_remove,
diff --git a/sound/soc/codecs/adau1781-i2c.c b/sound/soc/codecs/adau1781-i2c.c
index 2ce4362ccec1..0e32bba92339 100644
--- a/sound/soc/codecs/adau1781-i2c.c
+++ b/sound/soc/codecs/adau1781-i2c.c
@@ -45,7 +45,6 @@ MODULE_DEVICE_TABLE(i2c, adau1781_i2c_ids);
45static struct i2c_driver adau1781_i2c_driver = { 45static struct i2c_driver adau1781_i2c_driver = {
46 .driver = { 46 .driver = {
47 .name = "adau1781", 47 .name = "adau1781",
48 .owner = THIS_MODULE,
49 }, 48 },
50 .probe = adau1781_i2c_probe, 49 .probe = adau1781_i2c_probe,
51 .remove = adau1781_i2c_remove, 50 .remove = adau1781_i2c_remove,
diff --git a/sound/soc/codecs/adau1977-i2c.c b/sound/soc/codecs/adau1977-i2c.c
index 9700e8c838c9..21e7394a972a 100644
--- a/sound/soc/codecs/adau1977-i2c.c
+++ b/sound/soc/codecs/adau1977-i2c.c
@@ -46,7 +46,6 @@ MODULE_DEVICE_TABLE(i2c, adau1977_i2c_ids);
46static struct i2c_driver adau1977_i2c_driver = { 46static struct i2c_driver adau1977_i2c_driver = {
47 .driver = { 47 .driver = {
48 .name = "adau1977", 48 .name = "adau1977",
49 .owner = THIS_MODULE,
50 }, 49 },
51 .probe = adau1977_i2c_probe, 50 .probe = adau1977_i2c_probe,
52 .remove = adau1977_i2c_remove, 51 .remove = adau1977_i2c_remove,
diff --git a/sound/soc/codecs/adav803.c b/sound/soc/codecs/adav803.c
index 66d9fce34e62..52881faedcf6 100644
--- a/sound/soc/codecs/adav803.c
+++ b/sound/soc/codecs/adav803.c
@@ -36,7 +36,6 @@ static int adav803_remove(struct i2c_client *client)
36static struct i2c_driver adav803_driver = { 36static struct i2c_driver adav803_driver = {
37 .driver = { 37 .driver = {
38 .name = "adav803", 38 .name = "adav803",
39 .owner = THIS_MODULE,
40 }, 39 },
41 .probe = adav803_probe, 40 .probe = adav803_probe,
42 .remove = adav803_remove, 41 .remove = adav803_remove,
diff --git a/sound/soc/codecs/adav80x.c b/sound/soc/codecs/adav80x.c
index 36d842570745..198c924551b7 100644
--- a/sound/soc/codecs/adav80x.c
+++ b/sound/soc/codecs/adav80x.c
@@ -113,7 +113,7 @@
113 113
114#define ADAV80X_PLL_OUTE_SYSCLKPD(x) BIT(2 - (x)) 114#define ADAV80X_PLL_OUTE_SYSCLKPD(x) BIT(2 - (x))
115 115
116static struct reg_default adav80x_reg_defaults[] = { 116static const struct reg_default adav80x_reg_defaults[] = {
117 { ADAV80X_PLAYBACK_CTRL, 0x01 }, 117 { ADAV80X_PLAYBACK_CTRL, 0x01 },
118 { ADAV80X_AUX_IN_CTRL, 0x01 }, 118 { ADAV80X_AUX_IN_CTRL, 0x01 },
119 { ADAV80X_REC_CTRL, 0x02 }, 119 { ADAV80X_REC_CTRL, 0x02 },
@@ -865,7 +865,6 @@ const struct regmap_config adav80x_regmap_config = {
865 .val_bits = 8, 865 .val_bits = 8,
866 .pad_bits = 1, 866 .pad_bits = 1,
867 .reg_bits = 7, 867 .reg_bits = 7,
868 .read_flag_mask = 0x01,
869 868
870 .max_register = ADAV80X_PLL_OUTE, 869 .max_register = ADAV80X_PLL_OUTE,
871 870
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c
index 8670861e5bec..54428c64387b 100644
--- a/sound/soc/codecs/ak4535.c
+++ b/sound/soc/codecs/ak4535.c
@@ -444,7 +444,6 @@ MODULE_DEVICE_TABLE(i2c, ak4535_i2c_id);
444static struct i2c_driver ak4535_i2c_driver = { 444static struct i2c_driver ak4535_i2c_driver = {
445 .driver = { 445 .driver = {
446 .name = "ak4535", 446 .name = "ak4535",
447 .owner = THIS_MODULE,
448 }, 447 },
449 .probe = ak4535_i2c_probe, 448 .probe = ak4535_i2c_probe,
450 .remove = ak4535_i2c_remove, 449 .remove = ak4535_i2c_remove,
diff --git a/sound/soc/codecs/ak4641.c b/sound/soc/codecs/ak4641.c
index 2d0ff4595ea0..b14176f8d884 100644
--- a/sound/soc/codecs/ak4641.c
+++ b/sound/soc/codecs/ak4641.c
@@ -609,7 +609,6 @@ MODULE_DEVICE_TABLE(i2c, ak4641_i2c_id);
609static struct i2c_driver ak4641_i2c_driver = { 609static struct i2c_driver ak4641_i2c_driver = {
610 .driver = { 610 .driver = {
611 .name = "ak4641", 611 .name = "ak4641",
612 .owner = THIS_MODULE,
613 }, 612 },
614 .probe = ak4641_i2c_probe, 613 .probe = ak4641_i2c_probe,
615 .remove = ak4641_i2c_remove, 614 .remove = ak4641_i2c_remove,
diff --git a/sound/soc/codecs/ak4642.c b/sound/soc/codecs/ak4642.c
index 7c0f6552c229..4a90143d0e90 100644
--- a/sound/soc/codecs/ak4642.c
+++ b/sound/soc/codecs/ak4642.c
@@ -64,12 +64,15 @@
64#define FIL1_0 0x1c 64#define FIL1_0 0x1c
65#define FIL1_1 0x1d 65#define FIL1_1 0x1d
66#define FIL1_2 0x1e 66#define FIL1_2 0x1e
67#define FIL1_3 0x1f 67#define FIL1_3 0x1f /* The maximum valid register for ak4642 */
68#define PW_MGMT4 0x20 68#define PW_MGMT4 0x20
69#define MD_CTL5 0x21 69#define MD_CTL5 0x21
70#define LO_MS 0x22 70#define LO_MS 0x22
71#define HP_MS 0x23 71#define HP_MS 0x23
72#define SPK_MS 0x24 72#define SPK_MS 0x24 /* The maximum valid register for ak4643 */
73#define EQ_FBEQAB 0x25
74#define EQ_FBEQCD 0x26
75#define EQ_FBEQE 0x27 /* The maximum valid register for ak4648 */
73 76
74/* PW_MGMT1*/ 77/* PW_MGMT1*/
75#define PMVCM (1 << 6) /* VCOM Power Management */ 78#define PMVCM (1 << 6) /* VCOM Power Management */
@@ -241,7 +244,7 @@ static const struct snd_soc_dapm_route ak4642_intercon[] = {
241/* 244/*
242 * ak4642 register cache 245 * ak4642 register cache
243 */ 246 */
244static const struct reg_default ak4642_reg[] = { 247static const struct reg_default ak4643_reg[] = {
245 { 0, 0x00 }, { 1, 0x00 }, { 2, 0x01 }, { 3, 0x00 }, 248 { 0, 0x00 }, { 1, 0x00 }, { 2, 0x01 }, { 3, 0x00 },
246 { 4, 0x02 }, { 5, 0x00 }, { 6, 0x00 }, { 7, 0x00 }, 249 { 4, 0x02 }, { 5, 0x00 }, { 6, 0x00 }, { 7, 0x00 },
247 { 8, 0xe1 }, { 9, 0xe1 }, { 10, 0x18 }, { 11, 0x00 }, 250 { 8, 0xe1 }, { 9, 0xe1 }, { 10, 0x18 }, { 11, 0x00 },
@@ -254,6 +257,14 @@ static const struct reg_default ak4642_reg[] = {
254 { 36, 0x00 }, 257 { 36, 0x00 },
255}; 258};
256 259
260/* The default settings for 0x0 ~ 0x1f registers are the same for ak4642
261 and ak4643. So we reuse the ak4643 reg_default for ak4642.
262 The valid registers for ak4642 are 0x0 ~ 0x1f which is a subset of ak4643,
263 so define NUM_AK4642_REG_DEFAULTS for ak4642.
264*/
265#define ak4642_reg ak4643_reg
266#define NUM_AK4642_REG_DEFAULTS (FIL1_3 + 1)
267
257static const struct reg_default ak4648_reg[] = { 268static const struct reg_default ak4648_reg[] = {
258 { 0, 0x00 }, { 1, 0x00 }, { 2, 0x01 }, { 3, 0x00 }, 269 { 0, 0x00 }, { 1, 0x00 }, { 2, 0x01 }, { 3, 0x00 },
259 { 4, 0x02 }, { 5, 0x00 }, { 6, 0x00 }, { 7, 0x00 }, 270 { 4, 0x02 }, { 5, 0x00 }, { 6, 0x00 }, { 7, 0x00 },
@@ -535,15 +546,23 @@ static struct snd_soc_codec_driver soc_codec_dev_ak4642 = {
535static const struct regmap_config ak4642_regmap = { 546static const struct regmap_config ak4642_regmap = {
536 .reg_bits = 8, 547 .reg_bits = 8,
537 .val_bits = 8, 548 .val_bits = 8,
538 .max_register = ARRAY_SIZE(ak4642_reg) + 1, 549 .max_register = FIL1_3,
539 .reg_defaults = ak4642_reg, 550 .reg_defaults = ak4642_reg,
540 .num_reg_defaults = ARRAY_SIZE(ak4642_reg), 551 .num_reg_defaults = NUM_AK4642_REG_DEFAULTS,
552};
553
554static const struct regmap_config ak4643_regmap = {
555 .reg_bits = 8,
556 .val_bits = 8,
557 .max_register = SPK_MS,
558 .reg_defaults = ak4643_reg,
559 .num_reg_defaults = ARRAY_SIZE(ak4643_reg),
541}; 560};
542 561
543static const struct regmap_config ak4648_regmap = { 562static const struct regmap_config ak4648_regmap = {
544 .reg_bits = 8, 563 .reg_bits = 8,
545 .val_bits = 8, 564 .val_bits = 8,
546 .max_register = ARRAY_SIZE(ak4648_reg) + 1, 565 .max_register = EQ_FBEQE,
547 .reg_defaults = ak4648_reg, 566 .reg_defaults = ak4648_reg,
548 .num_reg_defaults = ARRAY_SIZE(ak4648_reg), 567 .num_reg_defaults = ARRAY_SIZE(ak4648_reg),
549}; 568};
@@ -553,7 +572,7 @@ static const struct ak4642_drvdata ak4642_drvdata = {
553}; 572};
554 573
555static const struct ak4642_drvdata ak4643_drvdata = { 574static const struct ak4642_drvdata ak4643_drvdata = {
556 .regmap_config = &ak4642_regmap, 575 .regmap_config = &ak4643_regmap,
557}; 576};
558 577
559static const struct ak4642_drvdata ak4648_drvdata = { 578static const struct ak4642_drvdata ak4648_drvdata = {
@@ -626,7 +645,6 @@ MODULE_DEVICE_TABLE(i2c, ak4642_i2c_id);
626static struct i2c_driver ak4642_i2c_driver = { 645static struct i2c_driver ak4642_i2c_driver = {
627 .driver = { 646 .driver = {
628 .name = "ak4642-codec", 647 .name = "ak4642-codec",
629 .owner = THIS_MODULE,
630 .of_match_table = ak4642_of_match, 648 .of_match_table = ak4642_of_match,
631 }, 649 },
632 .probe = ak4642_i2c_probe, 650 .probe = ak4642_i2c_probe,
diff --git a/sound/soc/codecs/ak4671.c b/sound/soc/codecs/ak4671.c
index 0e59063aeb6f..c73a9f6914b6 100644
--- a/sound/soc/codecs/ak4671.c
+++ b/sound/soc/codecs/ak4671.c
@@ -663,7 +663,6 @@ MODULE_DEVICE_TABLE(i2c, ak4671_i2c_id);
663static struct i2c_driver ak4671_i2c_driver = { 663static struct i2c_driver ak4671_i2c_driver = {
664 .driver = { 664 .driver = {
665 .name = "ak4671-codec", 665 .name = "ak4671-codec",
666 .owner = THIS_MODULE,
667 }, 666 },
668 .probe = ak4671_i2c_probe, 667 .probe = ak4671_i2c_probe,
669 .remove = ak4671_i2c_remove, 668 .remove = ak4671_i2c_remove,
diff --git a/sound/soc/codecs/alc5623.c b/sound/soc/codecs/alc5623.c
index 0fc24e0d518c..cf99c4e90acc 100644
--- a/sound/soc/codecs/alc5623.c
+++ b/sound/soc/codecs/alc5623.c
@@ -1085,7 +1085,6 @@ MODULE_DEVICE_TABLE(of, alc5623_of_match);
1085static struct i2c_driver alc5623_i2c_driver = { 1085static struct i2c_driver alc5623_i2c_driver = {
1086 .driver = { 1086 .driver = {
1087 .name = "alc562x-codec", 1087 .name = "alc562x-codec",
1088 .owner = THIS_MODULE,
1089 .of_match_table = of_match_ptr(alc5623_of_match), 1088 .of_match_table = of_match_ptr(alc5623_of_match),
1090 }, 1089 },
1091 .probe = alc5623_i2c_probe, 1090 .probe = alc5623_i2c_probe,
diff --git a/sound/soc/codecs/alc5632.c b/sound/soc/codecs/alc5632.c
index 607a63b9705f..ef6de511dc7e 100644
--- a/sound/soc/codecs/alc5632.c
+++ b/sound/soc/codecs/alc5632.c
@@ -35,7 +35,7 @@
35/* 35/*
36 * ALC5632 register cache 36 * ALC5632 register cache
37 */ 37 */
38static struct reg_default alc5632_reg_defaults[] = { 38static const struct reg_default alc5632_reg_defaults[] = {
39 { 2, 0x8080 }, /* R2 - Speaker Output Volume */ 39 { 2, 0x8080 }, /* R2 - Speaker Output Volume */
40 { 4, 0x8080 }, /* R4 - Headphone Output Volume */ 40 { 4, 0x8080 }, /* R4 - Headphone Output Volume */
41 { 6, 0x8080 }, /* R6 - AUXOUT Volume */ 41 { 6, 0x8080 }, /* R6 - AUXOUT Volume */
@@ -1183,7 +1183,6 @@ MODULE_DEVICE_TABLE(of, alc5632_of_match);
1183static struct i2c_driver alc5632_i2c_driver = { 1183static struct i2c_driver alc5632_i2c_driver = {
1184 .driver = { 1184 .driver = {
1185 .name = "alc5632", 1185 .name = "alc5632",
1186 .owner = THIS_MODULE,
1187 .of_match_table = of_match_ptr(alc5632_of_match), 1186 .of_match_table = of_match_ptr(alc5632_of_match),
1188 }, 1187 },
1189 .probe = alc5632_i2c_probe, 1188 .probe = alc5632_i2c_probe,
diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
index 802e05eae3e9..8a2221ab3d10 100644
--- a/sound/soc/codecs/arizona.c
+++ b/sound/soc/codecs/arizona.c
@@ -1366,7 +1366,7 @@ static void arizona_wm5102_set_dac_comp(struct snd_soc_codec *codec,
1366{ 1366{
1367 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec); 1367 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
1368 struct arizona *arizona = priv->arizona; 1368 struct arizona *arizona = priv->arizona;
1369 struct reg_default dac_comp[] = { 1369 struct reg_sequence dac_comp[] = {
1370 { 0x80, 0x3 }, 1370 { 0x80, 0x3 },
1371 { ARIZONA_DAC_COMP_1, 0 }, 1371 { ARIZONA_DAC_COMP_1, 0 },
1372 { ARIZONA_DAC_COMP_2, 0 }, 1372 { ARIZONA_DAC_COMP_2, 0 },
@@ -1504,7 +1504,7 @@ static int arizona_hw_params(struct snd_pcm_substream *substream,
1504 else 1504 else
1505 rates = &arizona_48k_bclk_rates[0]; 1505 rates = &arizona_48k_bclk_rates[0];
1506 1506
1507 wl = snd_pcm_format_width(params_format(params)); 1507 wl = params_width(params);
1508 1508
1509 if (tdm_slots) { 1509 if (tdm_slots) {
1510 arizona_aif_dbg(dai, "Configuring for %d %d bit TDM slots\n", 1510 arizona_aif_dbg(dai, "Configuring for %d %d bit TDM slots\n",
@@ -1756,17 +1756,6 @@ int arizona_init_dai(struct arizona_priv *priv, int id)
1756} 1756}
1757EXPORT_SYMBOL_GPL(arizona_init_dai); 1757EXPORT_SYMBOL_GPL(arizona_init_dai);
1758 1758
1759static irqreturn_t arizona_fll_clock_ok(int irq, void *data)
1760{
1761 struct arizona_fll *fll = data;
1762
1763 arizona_fll_dbg(fll, "clock OK\n");
1764
1765 complete(&fll->ok);
1766
1767 return IRQ_HANDLED;
1768}
1769
1770static struct { 1759static struct {
1771 unsigned int min; 1760 unsigned int min;
1772 unsigned int max; 1761 unsigned int max;
@@ -2048,17 +2037,18 @@ static int arizona_is_enabled_fll(struct arizona_fll *fll)
2048static int arizona_enable_fll(struct arizona_fll *fll) 2037static int arizona_enable_fll(struct arizona_fll *fll)
2049{ 2038{
2050 struct arizona *arizona = fll->arizona; 2039 struct arizona *arizona = fll->arizona;
2051 unsigned long time_left;
2052 bool use_sync = false; 2040 bool use_sync = false;
2053 int already_enabled = arizona_is_enabled_fll(fll); 2041 int already_enabled = arizona_is_enabled_fll(fll);
2054 struct arizona_fll_cfg cfg; 2042 struct arizona_fll_cfg cfg;
2043 int i;
2044 unsigned int val;
2055 2045
2056 if (already_enabled < 0) 2046 if (already_enabled < 0)
2057 return already_enabled; 2047 return already_enabled;
2058 2048
2059 if (already_enabled) { 2049 if (already_enabled) {
2060 /* Facilitate smooth refclk across the transition */ 2050 /* Facilitate smooth refclk across the transition */
2061 regmap_update_bits_async(fll->arizona->regmap, fll->base + 0x7, 2051 regmap_update_bits_async(fll->arizona->regmap, fll->base + 0x9,
2062 ARIZONA_FLL1_GAIN_MASK, 0); 2052 ARIZONA_FLL1_GAIN_MASK, 0);
2063 regmap_update_bits_async(fll->arizona->regmap, fll->base + 1, 2053 regmap_update_bits_async(fll->arizona->regmap, fll->base + 1,
2064 ARIZONA_FLL1_FREERUN, 2054 ARIZONA_FLL1_FREERUN,
@@ -2110,9 +2100,6 @@ static int arizona_enable_fll(struct arizona_fll *fll)
2110 if (!already_enabled) 2100 if (!already_enabled)
2111 pm_runtime_get(arizona->dev); 2101 pm_runtime_get(arizona->dev);
2112 2102
2113 /* Clear any pending completions */
2114 try_wait_for_completion(&fll->ok);
2115
2116 regmap_update_bits_async(arizona->regmap, fll->base + 1, 2103 regmap_update_bits_async(arizona->regmap, fll->base + 1,
2117 ARIZONA_FLL1_ENA, ARIZONA_FLL1_ENA); 2104 ARIZONA_FLL1_ENA, ARIZONA_FLL1_ENA);
2118 if (use_sync) 2105 if (use_sync)
@@ -2124,10 +2111,24 @@ static int arizona_enable_fll(struct arizona_fll *fll)
2124 regmap_update_bits_async(arizona->regmap, fll->base + 1, 2111 regmap_update_bits_async(arizona->regmap, fll->base + 1,
2125 ARIZONA_FLL1_FREERUN, 0); 2112 ARIZONA_FLL1_FREERUN, 0);
2126 2113
2127 time_left = wait_for_completion_timeout(&fll->ok, 2114 arizona_fll_dbg(fll, "Waiting for FLL lock...\n");
2128 msecs_to_jiffies(250)); 2115 val = 0;
2129 if (time_left == 0) 2116 for (i = 0; i < 15; i++) {
2117 if (i < 5)
2118 usleep_range(200, 400);
2119 else
2120 msleep(20);
2121
2122 regmap_read(arizona->regmap,
2123 ARIZONA_INTERRUPT_RAW_STATUS_5,
2124 &val);
2125 if (val & (ARIZONA_FLL1_CLOCK_OK_STS << (fll->id - 1)))
2126 break;
2127 }
2128 if (i == 15)
2130 arizona_fll_warn(fll, "Timed out waiting for lock\n"); 2129 arizona_fll_warn(fll, "Timed out waiting for lock\n");
2130 else
2131 arizona_fll_dbg(fll, "FLL locked (%d polls)\n", i);
2131 2132
2132 return 0; 2133 return 0;
2133} 2134}
@@ -2212,11 +2213,8 @@ EXPORT_SYMBOL_GPL(arizona_set_fll);
2212int arizona_init_fll(struct arizona *arizona, int id, int base, int lock_irq, 2213int arizona_init_fll(struct arizona *arizona, int id, int base, int lock_irq,
2213 int ok_irq, struct arizona_fll *fll) 2214 int ok_irq, struct arizona_fll *fll)
2214{ 2215{
2215 int ret;
2216 unsigned int val; 2216 unsigned int val;
2217 2217
2218 init_completion(&fll->ok);
2219
2220 fll->id = id; 2218 fll->id = id;
2221 fll->base = base; 2219 fll->base = base;
2222 fll->arizona = arizona; 2220 fll->arizona = arizona;
@@ -2238,13 +2236,6 @@ int arizona_init_fll(struct arizona *arizona, int id, int base, int lock_irq,
2238 snprintf(fll->clock_ok_name, sizeof(fll->clock_ok_name), 2236 snprintf(fll->clock_ok_name, sizeof(fll->clock_ok_name),
2239 "FLL%d clock OK", id); 2237 "FLL%d clock OK", id);
2240 2238
2241 ret = arizona_request_irq(arizona, ok_irq, fll->clock_ok_name,
2242 arizona_fll_clock_ok, fll);
2243 if (ret != 0) {
2244 dev_err(arizona->dev, "Failed to get FLL%d clock OK IRQ: %d\n",
2245 id, ret);
2246 }
2247
2248 regmap_update_bits(arizona->regmap, fll->base + 1, 2239 regmap_update_bits(arizona->regmap, fll->base + 1,
2249 ARIZONA_FLL1_FREERUN, 0); 2240 ARIZONA_FLL1_FREERUN, 0);
2250 2241
@@ -2313,6 +2304,82 @@ const struct snd_kcontrol_new arizona_adsp2_rate_controls[] = {
2313}; 2304};
2314EXPORT_SYMBOL_GPL(arizona_adsp2_rate_controls); 2305EXPORT_SYMBOL_GPL(arizona_adsp2_rate_controls);
2315 2306
2307static bool arizona_eq_filter_unstable(bool mode, __be16 _a, __be16 _b)
2308{
2309 s16 a = be16_to_cpu(_a);
2310 s16 b = be16_to_cpu(_b);
2311
2312 if (!mode) {
2313 return abs(a) >= 4096;
2314 } else {
2315 if (abs(b) >= 4096)
2316 return true;
2317
2318 return (abs((a << 16) / (4096 - b)) >= 4096 << 4);
2319 }
2320}
2321
2322int arizona_eq_coeff_put(struct snd_kcontrol *kcontrol,
2323 struct snd_ctl_elem_value *ucontrol)
2324{
2325 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
2326 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
2327 struct soc_bytes *params = (void *)kcontrol->private_value;
2328 unsigned int val;
2329 __be16 *data;
2330 int len;
2331 int ret;
2332
2333 len = params->num_regs * regmap_get_val_bytes(arizona->regmap);
2334
2335 data = kmemdup(ucontrol->value.bytes.data, len, GFP_KERNEL | GFP_DMA);
2336 if (!data)
2337 return -ENOMEM;
2338
2339 data[0] &= cpu_to_be16(ARIZONA_EQ1_B1_MODE);
2340
2341 if (arizona_eq_filter_unstable(!!data[0], data[1], data[2]) ||
2342 arizona_eq_filter_unstable(true, data[4], data[5]) ||
2343 arizona_eq_filter_unstable(true, data[8], data[9]) ||
2344 arizona_eq_filter_unstable(true, data[12], data[13]) ||
2345 arizona_eq_filter_unstable(false, data[16], data[17])) {
2346 dev_err(arizona->dev, "Rejecting unstable EQ coefficients\n");
2347 ret = -EINVAL;
2348 goto out;
2349 }
2350
2351 ret = regmap_read(arizona->regmap, params->base, &val);
2352 if (ret != 0)
2353 goto out;
2354
2355 val &= ~ARIZONA_EQ1_B1_MODE;
2356 data[0] |= cpu_to_be16(val);
2357
2358 ret = regmap_raw_write(arizona->regmap, params->base, data, len);
2359
2360out:
2361 kfree(data);
2362 return ret;
2363}
2364EXPORT_SYMBOL_GPL(arizona_eq_coeff_put);
2365
2366int arizona_lhpf_coeff_put(struct snd_kcontrol *kcontrol,
2367 struct snd_ctl_elem_value *ucontrol)
2368{
2369 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
2370 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
2371 __be16 *data = (__be16 *)ucontrol->value.bytes.data;
2372 s16 val = be16_to_cpu(*data);
2373
2374 if (abs(val) >= 4096) {
2375 dev_err(arizona->dev, "Rejecting unstable LHPF coefficients\n");
2376 return -EINVAL;
2377 }
2378
2379 return snd_soc_bytes_put(kcontrol, ucontrol);
2380}
2381EXPORT_SYMBOL_GPL(arizona_lhpf_coeff_put);
2382
2316MODULE_DESCRIPTION("ASoC Wolfson Arizona class device support"); 2383MODULE_DESCRIPTION("ASoC Wolfson Arizona class device support");
2317MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 2384MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
2318MODULE_LICENSE("GPL"); 2385MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/arizona.h b/sound/soc/codecs/arizona.h
index 43deb0462309..ada0a418ff4b 100644
--- a/sound/soc/codecs/arizona.h
+++ b/sound/soc/codecs/arizona.h
@@ -194,6 +194,20 @@ extern int arizona_mixer_values[ARIZONA_NUM_MIXER_INPUTS];
194 ARIZONA_MIXER_ROUTES(name " Preloader", name "L"), \ 194 ARIZONA_MIXER_ROUTES(name " Preloader", name "L"), \
195 ARIZONA_MIXER_ROUTES(name " Preloader", name "R") 195 ARIZONA_MIXER_ROUTES(name " Preloader", name "R")
196 196
197#define ARIZONA_EQ_CONTROL(xname, xbase) \
198{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
199 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
200 .put = arizona_eq_coeff_put, .private_value = \
201 ((unsigned long)&(struct soc_bytes) { .base = xbase, \
202 .num_regs = 20, .mask = ~ARIZONA_EQ1_B1_MODE }) }
203
204#define ARIZONA_LHPF_CONTROL(xname, xbase) \
205{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
206 .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
207 .put = arizona_lhpf_coeff_put, .private_value = \
208 ((unsigned long)&(struct soc_bytes) { .base = xbase, \
209 .num_regs = 1 }) }
210
197#define ARIZONA_RATE_ENUM_SIZE 4 211#define ARIZONA_RATE_ENUM_SIZE 4
198extern const char *arizona_rate_text[ARIZONA_RATE_ENUM_SIZE]; 212extern const char *arizona_rate_text[ARIZONA_RATE_ENUM_SIZE];
199extern const int arizona_rate_val[ARIZONA_RATE_ENUM_SIZE]; 213extern const int arizona_rate_val[ARIZONA_RATE_ENUM_SIZE];
@@ -229,6 +243,11 @@ extern int arizona_hp_ev(struct snd_soc_dapm_widget *w,
229 struct snd_kcontrol *kcontrol, 243 struct snd_kcontrol *kcontrol,
230 int event); 244 int event);
231 245
246extern int arizona_eq_coeff_put(struct snd_kcontrol *kcontrol,
247 struct snd_ctl_elem_value *ucontrol);
248extern int arizona_lhpf_coeff_put(struct snd_kcontrol *kcontrol,
249 struct snd_ctl_elem_value *ucontrol);
250
232extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id, 251extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
233 int source, unsigned int freq, int dir); 252 int source, unsigned int freq, int dir);
234 253
@@ -242,7 +261,6 @@ struct arizona_fll {
242 int id; 261 int id;
243 unsigned int base; 262 unsigned int base;
244 unsigned int vco_mult; 263 unsigned int vco_mult;
245 struct completion ok;
246 264
247 unsigned int fout; 265 unsigned int fout;
248 int sync_src; 266 int sync_src;
diff --git a/sound/soc/codecs/cs35l32.c b/sound/soc/codecs/cs35l32.c
index 8f40025b7e7c..44c30fe3e315 100644
--- a/sound/soc/codecs/cs35l32.c
+++ b/sound/soc/codecs/cs35l32.c
@@ -74,33 +74,8 @@ static const struct reg_default cs35l32_reg_defaults[] = {
74static bool cs35l32_readable_register(struct device *dev, unsigned int reg) 74static bool cs35l32_readable_register(struct device *dev, unsigned int reg)
75{ 75{
76 switch (reg) { 76 switch (reg) {
77 case CS35L32_DEVID_AB: 77 case CS35L32_DEVID_AB ... CS35L32_AUDIO_LED_MNGR:
78 case CS35L32_DEVID_CD: 78 case CS35L32_ADSP_CTL ... CS35L32_FLASH_INHIBIT:
79 case CS35L32_DEVID_E:
80 case CS35L32_FAB_ID:
81 case CS35L32_REV_ID:
82 case CS35L32_PWRCTL1:
83 case CS35L32_PWRCTL2:
84 case CS35L32_CLK_CTL:
85 case CS35L32_BATT_THRESHOLD:
86 case CS35L32_VMON:
87 case CS35L32_BST_CPCP_CTL:
88 case CS35L32_IMON_SCALING:
89 case CS35L32_AUDIO_LED_MNGR:
90 case CS35L32_ADSP_CTL:
91 case CS35L32_CLASSD_CTL:
92 case CS35L32_PROTECT_CTL:
93 case CS35L32_INT_MASK_1:
94 case CS35L32_INT_MASK_2:
95 case CS35L32_INT_MASK_3:
96 case CS35L32_INT_STATUS_1:
97 case CS35L32_INT_STATUS_2:
98 case CS35L32_INT_STATUS_3:
99 case CS35L32_LED_STATUS:
100 case CS35L32_FLASH_MODE:
101 case CS35L32_MOVIE_MODE:
102 case CS35L32_FLASH_TIMER:
103 case CS35L32_FLASH_INHIBIT:
104 return true; 79 return true;
105 default: 80 default:
106 return false; 81 return false;
@@ -110,15 +85,8 @@ static bool cs35l32_readable_register(struct device *dev, unsigned int reg)
110static bool cs35l32_volatile_register(struct device *dev, unsigned int reg) 85static bool cs35l32_volatile_register(struct device *dev, unsigned int reg)
111{ 86{
112 switch (reg) { 87 switch (reg) {
113 case CS35L32_DEVID_AB: 88 case CS35L32_DEVID_AB ... CS35L32_REV_ID:
114 case CS35L32_DEVID_CD: 89 case CS35L32_INT_STATUS_1 ... CS35L32_LED_STATUS:
115 case CS35L32_DEVID_E:
116 case CS35L32_FAB_ID:
117 case CS35L32_REV_ID:
118 case CS35L32_INT_STATUS_1:
119 case CS35L32_INT_STATUS_2:
120 case CS35L32_INT_STATUS_3:
121 case CS35L32_LED_STATUS:
122 return true; 90 return true;
123 default: 91 default:
124 return false; 92 return false;
@@ -128,10 +96,7 @@ static bool cs35l32_volatile_register(struct device *dev, unsigned int reg)
128static bool cs35l32_precious_register(struct device *dev, unsigned int reg) 96static bool cs35l32_precious_register(struct device *dev, unsigned int reg)
129{ 97{
130 switch (reg) { 98 switch (reg) {
131 case CS35L32_INT_STATUS_1: 99 case CS35L32_INT_STATUS_1 ... CS35L32_LED_STATUS:
132 case CS35L32_INT_STATUS_2:
133 case CS35L32_INT_STATUS_3:
134 case CS35L32_LED_STATUS:
135 return true; 100 return true;
136 default: 101 default:
137 return false; 102 return false;
@@ -276,7 +241,7 @@ static const struct snd_soc_codec_driver soc_codec_dev_cs35l32 = {
276}; 241};
277 242
278/* Current and threshold powerup sequence Pg37 in datasheet */ 243/* Current and threshold powerup sequence Pg37 in datasheet */
279static const struct reg_default cs35l32_monitor_patch[] = { 244static const struct reg_sequence cs35l32_monitor_patch[] = {
280 245
281 { 0x00, 0x99 }, 246 { 0x00, 0x99 },
282 { 0x48, 0x17 }, 247 { 0x48, 0x17 },
@@ -441,8 +406,7 @@ static int cs35l32_i2c_probe(struct i2c_client *i2c_client,
441 if (IS_ERR(cs35l32->reset_gpio)) 406 if (IS_ERR(cs35l32->reset_gpio))
442 return PTR_ERR(cs35l32->reset_gpio); 407 return PTR_ERR(cs35l32->reset_gpio);
443 408
444 if (cs35l32->reset_gpio) 409 gpiod_set_value_cansleep(cs35l32->reset_gpio, 1);
445 gpiod_set_value_cansleep(cs35l32->reset_gpio, 1);
446 410
447 /* initialize codec */ 411 /* initialize codec */
448 ret = regmap_read(cs35l32->regmap, CS35L32_DEVID_AB, &reg); 412 ret = regmap_read(cs35l32->regmap, CS35L32_DEVID_AB, &reg);
@@ -536,8 +500,7 @@ static int cs35l32_i2c_remove(struct i2c_client *i2c_client)
536 snd_soc_unregister_codec(&i2c_client->dev); 500 snd_soc_unregister_codec(&i2c_client->dev);
537 501
538 /* Hold down reset */ 502 /* Hold down reset */
539 if (cs35l32->reset_gpio) 503 gpiod_set_value_cansleep(cs35l32->reset_gpio, 0);
540 gpiod_set_value_cansleep(cs35l32->reset_gpio, 0);
541 504
542 return 0; 505 return 0;
543} 506}
@@ -551,8 +514,7 @@ static int cs35l32_runtime_suspend(struct device *dev)
551 regcache_mark_dirty(cs35l32->regmap); 514 regcache_mark_dirty(cs35l32->regmap);
552 515
553 /* Hold down reset */ 516 /* Hold down reset */
554 if (cs35l32->reset_gpio) 517 gpiod_set_value_cansleep(cs35l32->reset_gpio, 0);
555 gpiod_set_value_cansleep(cs35l32->reset_gpio, 0);
556 518
557 /* remove power */ 519 /* remove power */
558 regulator_bulk_disable(ARRAY_SIZE(cs35l32->supplies), 520 regulator_bulk_disable(ARRAY_SIZE(cs35l32->supplies),
@@ -575,8 +537,7 @@ static int cs35l32_runtime_resume(struct device *dev)
575 return ret; 537 return ret;
576 } 538 }
577 539
578 if (cs35l32->reset_gpio) 540 gpiod_set_value_cansleep(cs35l32->reset_gpio, 1);
579 gpiod_set_value_cansleep(cs35l32->reset_gpio, 1);
580 541
581 regcache_cache_only(cs35l32->regmap, false); 542 regcache_cache_only(cs35l32->regmap, false);
582 regcache_sync(cs35l32->regmap); 543 regcache_sync(cs35l32->regmap);
@@ -607,7 +568,6 @@ MODULE_DEVICE_TABLE(i2c, cs35l32_id);
607static struct i2c_driver cs35l32_i2c_driver = { 568static struct i2c_driver cs35l32_i2c_driver = {
608 .driver = { 569 .driver = {
609 .name = "cs35l32", 570 .name = "cs35l32",
610 .owner = THIS_MODULE,
611 .pm = &cs35l32_runtime_pm, 571 .pm = &cs35l32_runtime_pm,
612 .of_match_table = cs35l32_of_match, 572 .of_match_table = cs35l32_of_match,
613 }, 573 },
diff --git a/sound/soc/codecs/cs35l32.h b/sound/soc/codecs/cs35l32.h
index 31ab804a22bc..1d6c2508cd41 100644
--- a/sound/soc/codecs/cs35l32.h
+++ b/sound/soc/codecs/cs35l32.h
@@ -80,7 +80,7 @@ struct cs35l32_platform_data {
80#define CS35L32_GAIN_MGR_MASK 0x08 80#define CS35L32_GAIN_MGR_MASK 0x08
81#define CS35L32_ADSP_SHARE_MASK 0x08 81#define CS35L32_ADSP_SHARE_MASK 0x08
82#define CS35L32_ADSP_DATACFG_MASK 0x30 82#define CS35L32_ADSP_DATACFG_MASK 0x30
83#define CS35L32_SDOUT_3ST 0x80 83#define CS35L32_SDOUT_3ST 0x08
84#define CS35L32_BATT_REC_MASK 0x0E 84#define CS35L32_BATT_REC_MASK 0x0E
85#define CS35L32_BATT_THRESH_MASK 0x30 85#define CS35L32_BATT_THRESH_MASK 0x30
86 86
diff --git a/sound/soc/codecs/cs4265.c b/sound/soc/codecs/cs4265.c
index d7ec4756e45b..55db19ddc5ff 100644
--- a/sound/soc/codecs/cs4265.c
+++ b/sound/soc/codecs/cs4265.c
@@ -60,23 +60,7 @@ static const struct reg_default cs4265_reg_defaults[] = {
60static bool cs4265_readable_register(struct device *dev, unsigned int reg) 60static bool cs4265_readable_register(struct device *dev, unsigned int reg)
61{ 61{
62 switch (reg) { 62 switch (reg) {
63 case CS4265_PWRCTL: 63 case CS4265_CHIP_ID ... CS4265_SPDIF_CTL2:
64 case CS4265_DAC_CTL:
65 case CS4265_ADC_CTL:
66 case CS4265_MCLK_FREQ:
67 case CS4265_SIG_SEL:
68 case CS4265_CHB_PGA_CTL:
69 case CS4265_CHA_PGA_CTL:
70 case CS4265_ADC_CTL2:
71 case CS4265_DAC_CHA_VOL:
72 case CS4265_DAC_CHB_VOL:
73 case CS4265_DAC_CTL2:
74 case CS4265_SPDIF_CTL1:
75 case CS4265_SPDIF_CTL2:
76 case CS4265_INT_MASK:
77 case CS4265_STATUS_MODE_MSB:
78 case CS4265_STATUS_MODE_LSB:
79 case CS4265_CHIP_ID:
80 return true; 64 return true;
81 default: 65 default:
82 return false; 66 return false;
@@ -457,14 +441,14 @@ static int cs4265_pcm_hw_params(struct snd_pcm_substream *substream,
457 case SND_SOC_DAIFMT_RIGHT_J: 441 case SND_SOC_DAIFMT_RIGHT_J:
458 if (params_width(params) == 16) { 442 if (params_width(params) == 16) {
459 snd_soc_update_bits(codec, CS4265_DAC_CTL, 443 snd_soc_update_bits(codec, CS4265_DAC_CTL,
460 CS4265_DAC_CTL_DIF, (1 << 5)); 444 CS4265_DAC_CTL_DIF, (2 << 4));
461 snd_soc_update_bits(codec, CS4265_SPDIF_CTL2, 445 snd_soc_update_bits(codec, CS4265_SPDIF_CTL2,
462 CS4265_SPDIF_CTL2_DIF, (1 << 7)); 446 CS4265_SPDIF_CTL2_DIF, (2 << 6));
463 } else { 447 } else {
464 snd_soc_update_bits(codec, CS4265_DAC_CTL, 448 snd_soc_update_bits(codec, CS4265_DAC_CTL,
465 CS4265_DAC_CTL_DIF, (3 << 5)); 449 CS4265_DAC_CTL_DIF, (3 << 4));
466 snd_soc_update_bits(codec, CS4265_SPDIF_CTL2, 450 snd_soc_update_bits(codec, CS4265_SPDIF_CTL2,
467 CS4265_SPDIF_CTL2_DIF, (1 << 7)); 451 CS4265_SPDIF_CTL2_DIF, (3 << 6));
468 } 452 }
469 break; 453 break;
470 case SND_SOC_DAIFMT_LEFT_J: 454 case SND_SOC_DAIFMT_LEFT_J:
@@ -473,7 +457,7 @@ static int cs4265_pcm_hw_params(struct snd_pcm_substream *substream,
473 snd_soc_update_bits(codec, CS4265_ADC_CTL, 457 snd_soc_update_bits(codec, CS4265_ADC_CTL,
474 CS4265_ADC_DIF, 0); 458 CS4265_ADC_DIF, 0);
475 snd_soc_update_bits(codec, CS4265_SPDIF_CTL2, 459 snd_soc_update_bits(codec, CS4265_SPDIF_CTL2,
476 CS4265_SPDIF_CTL2_DIF, (1 << 6)); 460 CS4265_SPDIF_CTL2_DIF, 0);
477 461
478 break; 462 break;
479 default: 463 default:
@@ -658,7 +642,6 @@ MODULE_DEVICE_TABLE(i2c, cs4265_id);
658static struct i2c_driver cs4265_i2c_driver = { 642static struct i2c_driver cs4265_i2c_driver = {
659 .driver = { 643 .driver = {
660 .name = "cs4265", 644 .name = "cs4265",
661 .owner = THIS_MODULE,
662 .of_match_table = cs4265_of_match, 645 .of_match_table = cs4265_of_match,
663 }, 646 },
664 .id_table = cs4265_id, 647 .id_table = cs4265_id,
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
index e6d4ff9fd992..e07807d96b68 100644
--- a/sound/soc/codecs/cs4270.c
+++ b/sound/soc/codecs/cs4270.c
@@ -751,7 +751,6 @@ MODULE_DEVICE_TABLE(i2c, cs4270_id);
751static struct i2c_driver cs4270_i2c_driver = { 751static struct i2c_driver cs4270_i2c_driver = {
752 .driver = { 752 .driver = {
753 .name = "cs4270", 753 .name = "cs4270",
754 .owner = THIS_MODULE,
755 .of_match_table = cs4270_of_match, 754 .of_match_table = cs4270_of_match,
756 }, 755 },
757 .id_table = cs4270_id, 756 .id_table = cs4270_id,
diff --git a/sound/soc/codecs/cs4271-i2c.c b/sound/soc/codecs/cs4271-i2c.c
index b264da030340..dcb3223d7d8f 100644
--- a/sound/soc/codecs/cs4271-i2c.c
+++ b/sound/soc/codecs/cs4271-i2c.c
@@ -48,7 +48,6 @@ MODULE_DEVICE_TABLE(i2c, cs4271_i2c_id);
48static struct i2c_driver cs4271_i2c_driver = { 48static struct i2c_driver cs4271_i2c_driver = {
49 .driver = { 49 .driver = {
50 .name = "cs4271", 50 .name = "cs4271",
51 .owner = THIS_MODULE,
52 .of_match_table = of_match_ptr(cs4271_dt_ids), 51 .of_match_table = of_match_ptr(cs4271_dt_ids),
53 }, 52 },
54 .probe = cs4271_i2c_probe, 53 .probe = cs4271_i2c_probe,
diff --git a/sound/soc/codecs/cs42l51-i2c.c b/sound/soc/codecs/cs42l51-i2c.c
index c40428f25ba5..9bad478474fa 100644
--- a/sound/soc/codecs/cs42l51-i2c.c
+++ b/sound/soc/codecs/cs42l51-i2c.c
@@ -45,7 +45,6 @@ static int cs42l51_i2c_remove(struct i2c_client *i2c)
45static struct i2c_driver cs42l51_i2c_driver = { 45static struct i2c_driver cs42l51_i2c_driver = {
46 .driver = { 46 .driver = {
47 .name = "cs42l51", 47 .name = "cs42l51",
48 .owner = THIS_MODULE,
49 .of_match_table = cs42l51_of_match, 48 .of_match_table = cs42l51_of_match,
50 }, 49 },
51 .probe = cs42l51_i2c_probe, 50 .probe = cs42l51_i2c_probe,
diff --git a/sound/soc/codecs/cs42l52.c b/sound/soc/codecs/cs42l52.c
index 4de52c9957ac..b256424d3f9a 100644
--- a/sound/soc/codecs/cs42l52.c
+++ b/sound/soc/codecs/cs42l52.c
@@ -110,58 +110,7 @@ static const struct reg_default cs42l52_reg_defaults[] = {
110static bool cs42l52_readable_register(struct device *dev, unsigned int reg) 110static bool cs42l52_readable_register(struct device *dev, unsigned int reg)
111{ 111{
112 switch (reg) { 112 switch (reg) {
113 case CS42L52_CHIP: 113 case CS42L52_CHIP ... CS42L52_CHARGE_PUMP:
114 case CS42L52_PWRCTL1:
115 case CS42L52_PWRCTL2:
116 case CS42L52_PWRCTL3:
117 case CS42L52_CLK_CTL:
118 case CS42L52_IFACE_CTL1:
119 case CS42L52_IFACE_CTL2:
120 case CS42L52_ADC_PGA_A:
121 case CS42L52_ADC_PGA_B:
122 case CS42L52_ANALOG_HPF_CTL:
123 case CS42L52_ADC_HPF_FREQ:
124 case CS42L52_ADC_MISC_CTL:
125 case CS42L52_PB_CTL1:
126 case CS42L52_MISC_CTL:
127 case CS42L52_PB_CTL2:
128 case CS42L52_MICA_CTL:
129 case CS42L52_MICB_CTL:
130 case CS42L52_PGAA_CTL:
131 case CS42L52_PGAB_CTL:
132 case CS42L52_PASSTHRUA_VOL:
133 case CS42L52_PASSTHRUB_VOL:
134 case CS42L52_ADCA_VOL:
135 case CS42L52_ADCB_VOL:
136 case CS42L52_ADCA_MIXER_VOL:
137 case CS42L52_ADCB_MIXER_VOL:
138 case CS42L52_PCMA_MIXER_VOL:
139 case CS42L52_PCMB_MIXER_VOL:
140 case CS42L52_BEEP_FREQ:
141 case CS42L52_BEEP_VOL:
142 case CS42L52_BEEP_TONE_CTL:
143 case CS42L52_TONE_CTL:
144 case CS42L52_MASTERA_VOL:
145 case CS42L52_MASTERB_VOL:
146 case CS42L52_HPA_VOL:
147 case CS42L52_HPB_VOL:
148 case CS42L52_SPKA_VOL:
149 case CS42L52_SPKB_VOL:
150 case CS42L52_ADC_PCM_MIXER:
151 case CS42L52_LIMITER_CTL1:
152 case CS42L52_LIMITER_CTL2:
153 case CS42L52_LIMITER_AT_RATE:
154 case CS42L52_ALC_CTL:
155 case CS42L52_ALC_RATE:
156 case CS42L52_ALC_THRESHOLD:
157 case CS42L52_NOISE_GATE_CTL:
158 case CS42L52_CLK_STATUS:
159 case CS42L52_BATT_COMPEN:
160 case CS42L52_BATT_LEVEL:
161 case CS42L52_SPK_STATUS:
162 case CS42L52_TEM_CTL:
163 case CS42L52_THE_FOLDBACK:
164 case CS42L52_CHARGE_PUMP:
165 return true; 114 return true;
166 default: 115 default:
167 return false; 116 return false;
@@ -919,7 +868,7 @@ static int cs42l52_set_bias_level(struct snd_soc_codec *codec,
919 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_U20_3LE | \ 868 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_U20_3LE | \
920 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_U24_LE) 869 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_U24_LE)
921 870
922static struct snd_soc_dai_ops cs42l52_ops = { 871static const struct snd_soc_dai_ops cs42l52_ops = {
923 .hw_params = cs42l52_pcm_hw_params, 872 .hw_params = cs42l52_pcm_hw_params,
924 .digital_mute = cs42l52_digital_mute, 873 .digital_mute = cs42l52_digital_mute,
925 .set_fmt = cs42l52_set_fmt, 874 .set_fmt = cs42l52_set_fmt,
@@ -1118,7 +1067,7 @@ static const struct snd_soc_codec_driver soc_codec_dev_cs42l52 = {
1118}; 1067};
1119 1068
1120/* Current and threshold powerup sequence Pg37 */ 1069/* Current and threshold powerup sequence Pg37 */
1121static const struct reg_default cs42l52_threshold_patch[] = { 1070static const struct reg_sequence cs42l52_threshold_patch[] = {
1122 1071
1123 { 0x00, 0x99 }, 1072 { 0x00, 0x99 },
1124 { 0x3E, 0xBA }, 1073 { 0x3E, 0xBA },
@@ -1285,7 +1234,6 @@ MODULE_DEVICE_TABLE(i2c, cs42l52_id);
1285static struct i2c_driver cs42l52_i2c_driver = { 1234static struct i2c_driver cs42l52_i2c_driver = {
1286 .driver = { 1235 .driver = {
1287 .name = "cs42l52", 1236 .name = "cs42l52",
1288 .owner = THIS_MODULE,
1289 .of_match_table = cs42l52_of_match, 1237 .of_match_table = cs42l52_of_match,
1290 }, 1238 },
1291 .id_table = cs42l52_id, 1239 .id_table = cs42l52_id,
diff --git a/sound/soc/codecs/cs42l56.c b/sound/soc/codecs/cs42l56.c
index 1e11ba45a79f..52fe7a5ac408 100644
--- a/sound/soc/codecs/cs42l56.c
+++ b/sound/soc/codecs/cs42l56.c
@@ -115,52 +115,7 @@ static const struct reg_default cs42l56_reg_defaults[] = {
115static bool cs42l56_readable_register(struct device *dev, unsigned int reg) 115static bool cs42l56_readable_register(struct device *dev, unsigned int reg)
116{ 116{
117 switch (reg) { 117 switch (reg) {
118 case CS42L56_CHIP_ID_1: 118 case CS42L56_CHIP_ID_1 ... CS42L56_LIM_ATTACK_RATE:
119 case CS42L56_CHIP_ID_2:
120 case CS42L56_PWRCTL_1:
121 case CS42L56_PWRCTL_2:
122 case CS42L56_CLKCTL_1:
123 case CS42L56_CLKCTL_2:
124 case CS42L56_SERIAL_FMT:
125 case CS42L56_CLASSH_CTL:
126 case CS42L56_MISC_CTL:
127 case CS42L56_INT_STATUS:
128 case CS42L56_PLAYBACK_CTL:
129 case CS42L56_DSP_MUTE_CTL:
130 case CS42L56_ADCA_MIX_VOLUME:
131 case CS42L56_ADCB_MIX_VOLUME:
132 case CS42L56_PCMA_MIX_VOLUME:
133 case CS42L56_PCMB_MIX_VOLUME:
134 case CS42L56_ANAINPUT_ADV_VOLUME:
135 case CS42L56_DIGINPUT_ADV_VOLUME:
136 case CS42L56_MASTER_A_VOLUME:
137 case CS42L56_MASTER_B_VOLUME:
138 case CS42L56_BEEP_FREQ_ONTIME:
139 case CS42L56_BEEP_FREQ_OFFTIME:
140 case CS42L56_BEEP_TONE_CFG:
141 case CS42L56_TONE_CTL:
142 case CS42L56_CHAN_MIX_SWAP:
143 case CS42L56_AIN_REFCFG_ADC_MUX:
144 case CS42L56_HPF_CTL:
145 case CS42L56_MISC_ADC_CTL:
146 case CS42L56_GAIN_BIAS_CTL:
147 case CS42L56_PGAA_MUX_VOLUME:
148 case CS42L56_PGAB_MUX_VOLUME:
149 case CS42L56_ADCA_ATTENUATOR:
150 case CS42L56_ADCB_ATTENUATOR:
151 case CS42L56_ALC_EN_ATTACK_RATE:
152 case CS42L56_ALC_RELEASE_RATE:
153 case CS42L56_ALC_THRESHOLD:
154 case CS42L56_NOISE_GATE_CTL:
155 case CS42L56_ALC_LIM_SFT_ZC:
156 case CS42L56_AMUTE_HPLO_MUX:
157 case CS42L56_HPA_VOLUME:
158 case CS42L56_HPB_VOLUME:
159 case CS42L56_LOA_VOLUME:
160 case CS42L56_LOB_VOLUME:
161 case CS42L56_LIM_THRESHOLD_CTL:
162 case CS42L56_LIM_CTL_RELEASE_RATE:
163 case CS42L56_LIM_ATTACK_RATE:
164 return true; 119 return true;
165 default: 120 default:
166 return false; 121 return false;
@@ -989,7 +944,7 @@ static int cs42l56_set_bias_level(struct snd_soc_codec *codec,
989 SNDRV_PCM_FMTBIT_S32_LE) 944 SNDRV_PCM_FMTBIT_S32_LE)
990 945
991 946
992static struct snd_soc_dai_ops cs42l56_ops = { 947static const struct snd_soc_dai_ops cs42l56_ops = {
993 .hw_params = cs42l56_pcm_hw_params, 948 .hw_params = cs42l56_pcm_hw_params,
994 .digital_mute = cs42l56_digital_mute, 949 .digital_mute = cs42l56_digital_mute,
995 .set_fmt = cs42l56_set_dai_fmt, 950 .set_fmt = cs42l56_set_dai_fmt,
@@ -1408,7 +1363,6 @@ MODULE_DEVICE_TABLE(i2c, cs42l56_id);
1408static struct i2c_driver cs42l56_i2c_driver = { 1363static struct i2c_driver cs42l56_i2c_driver = {
1409 .driver = { 1364 .driver = {
1410 .name = "cs42l56", 1365 .name = "cs42l56",
1411 .owner = THIS_MODULE,
1412 .of_match_table = cs42l56_of_match, 1366 .of_match_table = cs42l56_of_match,
1413 }, 1367 },
1414 .id_table = cs42l56_id, 1368 .id_table = cs42l56_id,
diff --git a/sound/soc/codecs/cs42l73.c b/sound/soc/codecs/cs42l73.c
index b7853b9d3a60..a8f468689d26 100644
--- a/sound/soc/codecs/cs42l73.c
+++ b/sound/soc/codecs/cs42l73.c
@@ -153,100 +153,8 @@ static bool cs42l73_volatile_register(struct device *dev, unsigned int reg)
153static bool cs42l73_readable_register(struct device *dev, unsigned int reg) 153static bool cs42l73_readable_register(struct device *dev, unsigned int reg)
154{ 154{
155 switch (reg) { 155 switch (reg) {
156 case CS42L73_DEVID_AB: 156 case CS42L73_DEVID_AB ... CS42L73_DEVID_E:
157 case CS42L73_DEVID_CD: 157 case CS42L73_REVID ... CS42L73_IM2:
158 case CS42L73_DEVID_E:
159 case CS42L73_REVID:
160 case CS42L73_PWRCTL1:
161 case CS42L73_PWRCTL2:
162 case CS42L73_PWRCTL3:
163 case CS42L73_CPFCHC:
164 case CS42L73_OLMBMSDC:
165 case CS42L73_DMMCC:
166 case CS42L73_XSPC:
167 case CS42L73_XSPMMCC:
168 case CS42L73_ASPC:
169 case CS42L73_ASPMMCC:
170 case CS42L73_VSPC:
171 case CS42L73_VSPMMCC:
172 case CS42L73_VXSPFS:
173 case CS42L73_MIOPC:
174 case CS42L73_ADCIPC:
175 case CS42L73_MICAPREPGAAVOL:
176 case CS42L73_MICBPREPGABVOL:
177 case CS42L73_IPADVOL:
178 case CS42L73_IPBDVOL:
179 case CS42L73_PBDC:
180 case CS42L73_HLADVOL:
181 case CS42L73_HLBDVOL:
182 case CS42L73_SPKDVOL:
183 case CS42L73_ESLDVOL:
184 case CS42L73_HPAAVOL:
185 case CS42L73_HPBAVOL:
186 case CS42L73_LOAAVOL:
187 case CS42L73_LOBAVOL:
188 case CS42L73_STRINV:
189 case CS42L73_XSPINV:
190 case CS42L73_ASPINV:
191 case CS42L73_VSPINV:
192 case CS42L73_LIMARATEHL:
193 case CS42L73_LIMRRATEHL:
194 case CS42L73_LMAXHL:
195 case CS42L73_LIMARATESPK:
196 case CS42L73_LIMRRATESPK:
197 case CS42L73_LMAXSPK:
198 case CS42L73_LIMARATEESL:
199 case CS42L73_LIMRRATEESL:
200 case CS42L73_LMAXESL:
201 case CS42L73_ALCARATE:
202 case CS42L73_ALCRRATE:
203 case CS42L73_ALCMINMAX:
204 case CS42L73_NGCAB:
205 case CS42L73_ALCNGMC:
206 case CS42L73_MIXERCTL:
207 case CS42L73_HLAIPAA:
208 case CS42L73_HLBIPBA:
209 case CS42L73_HLAXSPAA:
210 case CS42L73_HLBXSPBA:
211 case CS42L73_HLAASPAA:
212 case CS42L73_HLBASPBA:
213 case CS42L73_HLAVSPMA:
214 case CS42L73_HLBVSPMA:
215 case CS42L73_XSPAIPAA:
216 case CS42L73_XSPBIPBA:
217 case CS42L73_XSPAXSPAA:
218 case CS42L73_XSPBXSPBA:
219 case CS42L73_XSPAASPAA:
220 case CS42L73_XSPAASPBA:
221 case CS42L73_XSPAVSPMA:
222 case CS42L73_XSPBVSPMA:
223 case CS42L73_ASPAIPAA:
224 case CS42L73_ASPBIPBA:
225 case CS42L73_ASPAXSPAA:
226 case CS42L73_ASPBXSPBA:
227 case CS42L73_ASPAASPAA:
228 case CS42L73_ASPBASPBA:
229 case CS42L73_ASPAVSPMA:
230 case CS42L73_ASPBVSPMA:
231 case CS42L73_VSPAIPAA:
232 case CS42L73_VSPBIPBA:
233 case CS42L73_VSPAXSPAA:
234 case CS42L73_VSPBXSPBA:
235 case CS42L73_VSPAASPAA:
236 case CS42L73_VSPBASPBA:
237 case CS42L73_VSPAVSPMA:
238 case CS42L73_VSPBVSPMA:
239 case CS42L73_MMIXCTL:
240 case CS42L73_SPKMIPMA:
241 case CS42L73_SPKMXSPA:
242 case CS42L73_SPKMASPA:
243 case CS42L73_SPKMVSPMA:
244 case CS42L73_ESLMIPMA:
245 case CS42L73_ESLMXSPA:
246 case CS42L73_ESLMASPA:
247 case CS42L73_ESLMVSPMA:
248 case CS42L73_IM1:
249 case CS42L73_IM2:
250 return true; 158 return true;
251 default: 159 default:
252 return false; 160 return false;
@@ -1236,8 +1144,8 @@ static int cs42l73_set_tristate(struct snd_soc_dai *dai, int tristate)
1236 struct snd_soc_codec *codec = dai->codec; 1144 struct snd_soc_codec *codec = dai->codec;
1237 int id = dai->id; 1145 int id = dai->id;
1238 1146
1239 return snd_soc_update_bits(codec, CS42L73_SPC(id), 1147 return snd_soc_update_bits(codec, CS42L73_SPC(id), CS42L73_SP_3ST,
1240 0x7F, tristate << 7); 1148 tristate << 7);
1241} 1149}
1242 1150
1243static const struct snd_pcm_hw_constraint_list constraints_12_24 = { 1151static const struct snd_pcm_hw_constraint_list constraints_12_24 = {
@@ -1491,7 +1399,6 @@ MODULE_DEVICE_TABLE(i2c, cs42l73_id);
1491static struct i2c_driver cs42l73_i2c_driver = { 1399static struct i2c_driver cs42l73_i2c_driver = {
1492 .driver = { 1400 .driver = {
1493 .name = "cs42l73", 1401 .name = "cs42l73",
1494 .owner = THIS_MODULE,
1495 .of_match_table = cs42l73_of_match, 1402 .of_match_table = cs42l73_of_match,
1496 }, 1403 },
1497 .id_table = cs42l73_id, 1404 .id_table = cs42l73_id,
diff --git a/sound/soc/codecs/cs42xx8-i2c.c b/sound/soc/codecs/cs42xx8-i2c.c
index 657dce27eade..800c1d549347 100644
--- a/sound/soc/codecs/cs42xx8-i2c.c
+++ b/sound/soc/codecs/cs42xx8-i2c.c
@@ -20,7 +20,7 @@
20static int cs42xx8_i2c_probe(struct i2c_client *i2c, 20static int cs42xx8_i2c_probe(struct i2c_client *i2c,
21 const struct i2c_device_id *id) 21 const struct i2c_device_id *id)
22{ 22{
23 u32 ret = cs42xx8_probe(&i2c->dev, 23 int ret = cs42xx8_probe(&i2c->dev,
24 devm_regmap_init_i2c(i2c, &cs42xx8_regmap_config)); 24 devm_regmap_init_i2c(i2c, &cs42xx8_regmap_config));
25 if (ret) 25 if (ret)
26 return ret; 26 return ret;
@@ -49,8 +49,8 @@ MODULE_DEVICE_TABLE(i2c, cs42xx8_i2c_id);
49static struct i2c_driver cs42xx8_i2c_driver = { 49static struct i2c_driver cs42xx8_i2c_driver = {
50 .driver = { 50 .driver = {
51 .name = "cs42xx8", 51 .name = "cs42xx8",
52 .owner = THIS_MODULE,
53 .pm = &cs42xx8_pm, 52 .pm = &cs42xx8_pm,
53 .of_match_table = cs42xx8_of_match,
54 }, 54 },
55 .probe = cs42xx8_i2c_probe, 55 .probe = cs42xx8_i2c_probe,
56 .remove = cs42xx8_i2c_remove, 56 .remove = cs42xx8_i2c_remove,
diff --git a/sound/soc/codecs/cs42xx8.c b/sound/soc/codecs/cs42xx8.c
index e1d46862e81f..d562e1b9a5d1 100644
--- a/sound/soc/codecs/cs42xx8.c
+++ b/sound/soc/codecs/cs42xx8.c
@@ -425,7 +425,7 @@ const struct cs42xx8_driver_data cs42888_data = {
425}; 425};
426EXPORT_SYMBOL_GPL(cs42888_data); 426EXPORT_SYMBOL_GPL(cs42888_data);
427 427
428static const struct of_device_id cs42xx8_of_match[] = { 428const struct of_device_id cs42xx8_of_match[] = {
429 { .compatible = "cirrus,cs42448", .data = &cs42448_data, }, 429 { .compatible = "cirrus,cs42448", .data = &cs42448_data, },
430 { .compatible = "cirrus,cs42888", .data = &cs42888_data, }, 430 { .compatible = "cirrus,cs42888", .data = &cs42888_data, },
431 { /* sentinel */ } 431 { /* sentinel */ }
@@ -435,16 +435,24 @@ EXPORT_SYMBOL_GPL(cs42xx8_of_match);
435 435
436int cs42xx8_probe(struct device *dev, struct regmap *regmap) 436int cs42xx8_probe(struct device *dev, struct regmap *regmap)
437{ 437{
438 const struct of_device_id *of_id = of_match_device(cs42xx8_of_match, dev); 438 const struct of_device_id *of_id;
439 struct cs42xx8_priv *cs42xx8; 439 struct cs42xx8_priv *cs42xx8;
440 int ret, val, i; 440 int ret, val, i;
441 441
442 if (IS_ERR(regmap)) {
443 ret = PTR_ERR(regmap);
444 dev_err(dev, "failed to allocate regmap: %d\n", ret);
445 return ret;
446 }
447
442 cs42xx8 = devm_kzalloc(dev, sizeof(*cs42xx8), GFP_KERNEL); 448 cs42xx8 = devm_kzalloc(dev, sizeof(*cs42xx8), GFP_KERNEL);
443 if (cs42xx8 == NULL) 449 if (cs42xx8 == NULL)
444 return -ENOMEM; 450 return -ENOMEM;
445 451
452 cs42xx8->regmap = regmap;
446 dev_set_drvdata(dev, cs42xx8); 453 dev_set_drvdata(dev, cs42xx8);
447 454
455 of_id = of_match_device(cs42xx8_of_match, dev);
448 if (of_id) 456 if (of_id)
449 cs42xx8->drvdata = of_id->data; 457 cs42xx8->drvdata = of_id->data;
450 458
@@ -482,13 +490,6 @@ int cs42xx8_probe(struct device *dev, struct regmap *regmap)
482 /* Make sure hardware reset done */ 490 /* Make sure hardware reset done */
483 msleep(5); 491 msleep(5);
484 492
485 cs42xx8->regmap = regmap;
486 if (IS_ERR(cs42xx8->regmap)) {
487 ret = PTR_ERR(cs42xx8->regmap);
488 dev_err(dev, "failed to allocate regmap: %d\n", ret);
489 goto err_enable;
490 }
491
492 /* 493 /*
493 * We haven't marked the chip revision as volatile due to 494 * We haven't marked the chip revision as volatile due to
494 * sharing a register with the right input volume; explicitly 495 * sharing a register with the right input volume; explicitly
diff --git a/sound/soc/codecs/cs42xx8.h b/sound/soc/codecs/cs42xx8.h
index b2c10e537ef6..d36c61b6df74 100644
--- a/sound/soc/codecs/cs42xx8.h
+++ b/sound/soc/codecs/cs42xx8.h
@@ -22,6 +22,7 @@ extern const struct dev_pm_ops cs42xx8_pm;
22extern const struct cs42xx8_driver_data cs42448_data; 22extern const struct cs42xx8_driver_data cs42448_data;
23extern const struct cs42xx8_driver_data cs42888_data; 23extern const struct cs42xx8_driver_data cs42888_data;
24extern const struct regmap_config cs42xx8_regmap_config; 24extern const struct regmap_config cs42xx8_regmap_config;
25extern const struct of_device_id cs42xx8_of_match[];
25int cs42xx8_probe(struct device *dev, struct regmap *regmap); 26int cs42xx8_probe(struct device *dev, struct regmap *regmap);
26 27
27/* CS42888 register map */ 28/* CS42888 register map */
diff --git a/sound/soc/codecs/cs4349.c b/sound/soc/codecs/cs4349.c
new file mode 100644
index 000000000000..0ac8fc5ed4ae
--- /dev/null
+++ b/sound/soc/codecs/cs4349.c
@@ -0,0 +1,392 @@
1/*
2 * cs4349.c -- CS4349 ALSA Soc Audio driver
3 *
4 * Copyright 2015 Cirrus Logic, Inc.
5 *
6 * Authors: Tim Howe <Tim.Howe@cirrus.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/module.h>
14#include <linux/moduleparam.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/delay.h>
18#include <linux/gpio.h>
19#include <linux/gpio/consumer.h>
20#include <linux/platform_device.h>
21#include <linux/pm.h>
22#include <linux/i2c.h>
23#include <linux/of_device.h>
24#include <linux/regmap.h>
25#include <linux/slab.h>
26#include <sound/core.h>
27#include <sound/pcm.h>
28#include <sound/pcm_params.h>
29#include <sound/soc.h>
30#include <sound/soc-dapm.h>
31#include <sound/initval.h>
32#include <sound/tlv.h>
33#include "cs4349.h"
34
35
36static const struct reg_default cs4349_reg_defaults[] = {
37 { 2, 0x00 }, /* r02 - Mode Control */
38 { 3, 0x09 }, /* r03 - Volume, Mixing and Inversion Control */
39 { 4, 0x81 }, /* r04 - Mute Control */
40 { 5, 0x00 }, /* r05 - Channel A Volume Control */
41 { 6, 0x00 }, /* r06 - Channel B Volume Control */
42 { 7, 0xB1 }, /* r07 - Ramp and Filter Control */
43 { 8, 0x1C }, /* r08 - Misc. Control */
44};
45
46/* Private data for the CS4349 */
47struct cs4349_private {
48 struct regmap *regmap;
49 struct gpio_desc *reset_gpio;
50 unsigned int mode;
51 int rate;
52};
53
54static bool cs4349_readable_register(struct device *dev, unsigned int reg)
55{
56 switch (reg) {
57 case CS4349_CHIPID ... CS4349_MISC:
58 return true;
59 default:
60 return false;
61 }
62}
63
64static bool cs4349_writeable_register(struct device *dev, unsigned int reg)
65{
66 switch (reg) {
67 case CS4349_MODE ... CS4349_MISC:
68 return true;
69 default:
70 return false;
71 }
72}
73
74static int cs4349_set_dai_fmt(struct snd_soc_dai *codec_dai,
75 unsigned int format)
76{
77 struct snd_soc_codec *codec = codec_dai->codec;
78 struct cs4349_private *cs4349 = snd_soc_codec_get_drvdata(codec);
79 unsigned int fmt;
80
81 fmt = format & SND_SOC_DAIFMT_FORMAT_MASK;
82
83 switch (fmt) {
84 case SND_SOC_DAIFMT_I2S:
85 case SND_SOC_DAIFMT_LEFT_J:
86 case SND_SOC_DAIFMT_RIGHT_J:
87 cs4349->mode = format & SND_SOC_DAIFMT_FORMAT_MASK;
88 break;
89 default:
90 return -EINVAL;
91 }
92
93 return 0;
94}
95
96static int cs4349_pcm_hw_params(struct snd_pcm_substream *substream,
97 struct snd_pcm_hw_params *params,
98 struct snd_soc_dai *dai)
99{
100 struct snd_soc_codec *codec = dai->codec;
101 struct cs4349_private *cs4349 = snd_soc_codec_get_drvdata(codec);
102 int fmt, ret;
103
104 cs4349->rate = params_rate(params);
105
106 switch (cs4349->mode) {
107 case SND_SOC_DAIFMT_I2S:
108 fmt = DIF_I2S;
109 break;
110 case SND_SOC_DAIFMT_LEFT_J:
111 fmt = DIF_LEFT_JST;
112 break;
113 case SND_SOC_DAIFMT_RIGHT_J:
114 switch (params_width(params)) {
115 case 16:
116 fmt = DIF_RGHT_JST16;
117 break;
118 case 24:
119 fmt = DIF_RGHT_JST24;
120 break;
121 default:
122 return -EINVAL;
123 }
124 break;
125 default:
126 return -EINVAL;
127 }
128
129 ret = snd_soc_update_bits(codec, CS4349_MODE, DIF_MASK,
130 MODE_FORMAT(fmt));
131 if (ret < 0)
132 return ret;
133
134 return 0;
135}
136
137static int cs4349_digital_mute(struct snd_soc_dai *dai, int mute)
138{
139 struct snd_soc_codec *codec = dai->codec;
140 int reg;
141
142 reg = 0;
143 if (mute)
144 reg = MUTE_AB_MASK;
145
146 return snd_soc_update_bits(codec, CS4349_MUTE, MUTE_AB_MASK, reg);
147}
148
149static DECLARE_TLV_DB_SCALE(dig_tlv, -12750, 50, 0);
150
151static const char * const chan_mix_texts[] = {
152 "Mute", "MuteA", "MuteA SwapB", "MuteA MonoB", "SwapA MuteB",
153 "BothR", "Swap", "SwapA MonoB", "MuteB", "Normal", "BothL",
154 "MonoB", "MonoA MuteB", "MonoA", "MonoA SwapB", "Mono",
155 /*Normal == Channel A = Left, Channel B = Right*/
156};
157
158static const char * const fm_texts[] = {
159 "Auto", "Single", "Double", "Quad",
160};
161
162static const char * const deemph_texts[] = {
163 "None", "44.1k", "48k", "32k",
164};
165
166static const char * const softr_zeroc_texts[] = {
167 "Immediate", "Zero Cross", "Soft Ramp", "SR on ZC",
168};
169
170static int deemph_values[] = {
171 0, 4, 8, 12,
172};
173
174static int softr_zeroc_values[] = {
175 0, 64, 128, 192,
176};
177
178static const struct soc_enum chan_mix_enum =
179 SOC_ENUM_SINGLE(CS4349_VMI, 0,
180 ARRAY_SIZE(chan_mix_texts),
181 chan_mix_texts);
182
183static const struct soc_enum fm_mode_enum =
184 SOC_ENUM_SINGLE(CS4349_MODE, 0,
185 ARRAY_SIZE(fm_texts),
186 fm_texts);
187
188static SOC_VALUE_ENUM_SINGLE_DECL(deemph_enum, CS4349_MODE, 0, DEM_MASK,
189 deemph_texts, deemph_values);
190
191static SOC_VALUE_ENUM_SINGLE_DECL(softr_zeroc_enum, CS4349_RMPFLT, 0,
192 SR_ZC_MASK, softr_zeroc_texts,
193 softr_zeroc_values);
194
195static const struct snd_kcontrol_new cs4349_snd_controls[] = {
196 SOC_DOUBLE_R_TLV("Master Playback Volume",
197 CS4349_VOLA, CS4349_VOLB, 0, 0xFF, 1, dig_tlv),
198 SOC_ENUM("Functional Mode", fm_mode_enum),
199 SOC_ENUM("De-Emphasis Control", deemph_enum),
200 SOC_ENUM("Soft Ramp Zero Cross Control", softr_zeroc_enum),
201 SOC_ENUM("Channel Mixer", chan_mix_enum),
202 SOC_SINGLE("VolA = VolB Switch", CS4349_VMI, 7, 1, 0),
203 SOC_SINGLE("InvertA Switch", CS4349_VMI, 6, 1, 0),
204 SOC_SINGLE("InvertB Switch", CS4349_VMI, 5, 1, 0),
205 SOC_SINGLE("Auto-Mute Switch", CS4349_MUTE, 7, 1, 0),
206 SOC_SINGLE("MUTEC A = B Switch", CS4349_MUTE, 5, 1, 0),
207 SOC_SINGLE("Soft Ramp Up Switch", CS4349_RMPFLT, 5, 1, 0),
208 SOC_SINGLE("Soft Ramp Down Switch", CS4349_RMPFLT, 4, 1, 0),
209 SOC_SINGLE("Slow Roll Off Filter Switch", CS4349_RMPFLT, 2, 1, 0),
210 SOC_SINGLE("Freeze Switch", CS4349_MISC, 5, 1, 0),
211 SOC_SINGLE("Popguard Switch", CS4349_MISC, 4, 1, 0),
212};
213
214static const struct snd_soc_dapm_widget cs4349_dapm_widgets[] = {
215 SND_SOC_DAPM_DAC("HiFi DAC", NULL, SND_SOC_NOPM, 0, 0),
216
217 SND_SOC_DAPM_OUTPUT("OutputA"),
218 SND_SOC_DAPM_OUTPUT("OutputB"),
219};
220
221static const struct snd_soc_dapm_route cs4349_routes[] = {
222 {"DAC Playback", NULL, "OutputA"},
223 {"DAC Playback", NULL, "OutputB"},
224
225 {"OutputA", NULL, "HiFi DAC"},
226 {"OutputB", NULL, "HiFi DAC"},
227};
228
229#define CS4349_PCM_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
230 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \
231 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE | \
232 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \
233 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \
234 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE | \
235 SNDRV_PCM_FMTBIT_S32_LE)
236
237#define CS4349_PCM_RATES SNDRV_PCM_RATE_8000_192000
238
239static const struct snd_soc_dai_ops cs4349_dai_ops = {
240 .hw_params = cs4349_pcm_hw_params,
241 .set_fmt = cs4349_set_dai_fmt,
242 .digital_mute = cs4349_digital_mute,
243};
244
245static struct snd_soc_dai_driver cs4349_dai = {
246 .name = "cs4349_hifi",
247 .playback = {
248 .stream_name = "DAC Playback",
249 .channels_min = 1,
250 .channels_max = 2,
251 .rates = CS4349_PCM_RATES,
252 .formats = CS4349_PCM_FORMATS,
253 },
254 .ops = &cs4349_dai_ops,
255 .symmetric_rates = 1,
256};
257
258static struct snd_soc_codec_driver soc_codec_dev_cs4349 = {
259 .controls = cs4349_snd_controls,
260 .num_controls = ARRAY_SIZE(cs4349_snd_controls),
261
262 .dapm_widgets = cs4349_dapm_widgets,
263 .num_dapm_widgets = ARRAY_SIZE(cs4349_dapm_widgets),
264 .dapm_routes = cs4349_routes,
265 .num_dapm_routes = ARRAY_SIZE(cs4349_routes),
266};
267
268static const struct regmap_config cs4349_regmap = {
269 .reg_bits = 8,
270 .val_bits = 8,
271
272 .max_register = CS4349_MISC,
273 .reg_defaults = cs4349_reg_defaults,
274 .num_reg_defaults = ARRAY_SIZE(cs4349_reg_defaults),
275 .readable_reg = cs4349_readable_register,
276 .writeable_reg = cs4349_writeable_register,
277 .cache_type = REGCACHE_RBTREE,
278};
279
280static int cs4349_i2c_probe(struct i2c_client *client,
281 const struct i2c_device_id *id)
282{
283 struct cs4349_private *cs4349;
284 int ret;
285
286 cs4349 = devm_kzalloc(&client->dev, sizeof(*cs4349), GFP_KERNEL);
287 if (!cs4349)
288 return -ENOMEM;
289
290 cs4349->regmap = devm_regmap_init_i2c(client, &cs4349_regmap);
291 if (IS_ERR(cs4349->regmap)) {
292 ret = PTR_ERR(cs4349->regmap);
293 dev_err(&client->dev, "regmap_init() failed: %d\n", ret);
294 return ret;
295 }
296
297 /* Reset the Device */
298 cs4349->reset_gpio = devm_gpiod_get_optional(&client->dev,
299 "reset", GPIOD_OUT_LOW);
300 if (IS_ERR(cs4349->reset_gpio))
301 return PTR_ERR(cs4349->reset_gpio);
302
303 gpiod_set_value_cansleep(cs4349->reset_gpio, 1);
304
305 i2c_set_clientdata(client, cs4349);
306
307 return snd_soc_register_codec(&client->dev, &soc_codec_dev_cs4349,
308 &cs4349_dai, 1);
309}
310
311static int cs4349_i2c_remove(struct i2c_client *client)
312{
313 struct cs4349_private *cs4349 = i2c_get_clientdata(client);
314
315 snd_soc_unregister_codec(&client->dev);
316
317 /* Hold down reset */
318 gpiod_set_value_cansleep(cs4349->reset_gpio, 0);
319
320 return 0;
321}
322
323#ifdef CONFIG_PM
324static int cs4349_runtime_suspend(struct device *dev)
325{
326 struct cs4349_private *cs4349 = dev_get_drvdata(dev);
327 int ret;
328
329 ret = regmap_update_bits(cs4349->regmap, CS4349_MISC, PWR_DWN, PWR_DWN);
330 if (ret < 0)
331 return ret;
332
333 regcache_cache_only(cs4349->regmap, true);
334
335 /* Hold down reset */
336 gpiod_set_value_cansleep(cs4349->reset_gpio, 0);
337
338 return 0;
339}
340
341static int cs4349_runtime_resume(struct device *dev)
342{
343 struct cs4349_private *cs4349 = dev_get_drvdata(dev);
344 int ret;
345
346 ret = regmap_update_bits(cs4349->regmap, CS4349_MISC, PWR_DWN, 0);
347 if (ret < 0)
348 return ret;
349
350 gpiod_set_value_cansleep(cs4349->reset_gpio, 1);
351
352 regcache_cache_only(cs4349->regmap, false);
353 regcache_sync(cs4349->regmap);
354
355 return 0;
356}
357#endif
358
359static const struct dev_pm_ops cs4349_runtime_pm = {
360 SET_RUNTIME_PM_OPS(cs4349_runtime_suspend, cs4349_runtime_resume,
361 NULL)
362};
363
364static const struct of_device_id cs4349_of_match[] = {
365 { .compatible = "cirrus,cs4349", },
366 {},
367};
368
369MODULE_DEVICE_TABLE(of, cs4349_of_match);
370
371static const struct i2c_device_id cs4349_i2c_id[] = {
372 {"cs4349", 0},
373 {}
374};
375
376MODULE_DEVICE_TABLE(i2c, cs4349_i2c_id);
377
378static struct i2c_driver cs4349_i2c_driver = {
379 .driver = {
380 .name = "cs4349",
381 .of_match_table = cs4349_of_match,
382 },
383 .id_table = cs4349_i2c_id,
384 .probe = cs4349_i2c_probe,
385 .remove = cs4349_i2c_remove,
386};
387
388module_i2c_driver(cs4349_i2c_driver);
389
390MODULE_AUTHOR("Tim Howe <tim.howe@cirrus.com>");
391MODULE_DESCRIPTION("Cirrus Logic CS4349 ALSA SoC Codec Driver");
392MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cs4349.h b/sound/soc/codecs/cs4349.h
new file mode 100644
index 000000000000..d58c06a25358
--- /dev/null
+++ b/sound/soc/codecs/cs4349.h
@@ -0,0 +1,136 @@
1/*
2 * ALSA SoC CS4349 codec driver
3 *
4 * Copyright 2015 Cirrus Logic, Inc.
5 *
6 * Author: Tim Howe <Tim.Howe@cirrus.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 */
18
19#ifndef __CS4349_H__
20#define __CS4349_H__
21
22/* CS4349 registers addresses */
23#define CS4349_CHIPID 0x01 /* Device and Rev ID, Read Only */
24#define CS4349_MODE 0x02 /* Mode Control */
25#define CS4349_VMI 0x03 /* Volume, Mixing, Inversion Control */
26#define CS4349_MUTE 0x04 /* Mute Control */
27#define CS4349_VOLA 0x05 /* DAC Channel A Volume Control */
28#define CS4349_VOLB 0x06 /* DAC Channel B Volume Control */
29#define CS4349_RMPFLT 0x07 /* Ramp and Filter Control */
30#define CS4349_MISC 0x08 /* Power Down,Freeze Control,Pop Stop*/
31
32#define CS4349_I2C_INCR 0x80
33
34
35/* Device and Revision ID */
36#define CS4349_REVA 0xF0 /* Rev A */
37#define CS4349_REVB 0xF1 /* Rev B */
38#define CS4349_REVC2 0xFF /* Rev C2 */
39
40
41/* PDN_DONE Poll Maximum
42 * If soft ramp is set it will take much longer to power down
43 * the system.
44 */
45#define PDN_POLL_MAX 900
46
47
48/* Bitfield Definitions */
49
50/* CS4349_MODE */
51/* (Digital Interface Format, De-Emphasis Control, Functional Mode */
52#define DIF2 (1 << 6)
53#define DIF1 (1 << 5)
54#define DIF0 (1 << 4)
55#define DEM1 (1 << 3)
56#define DEM0 (1 << 2)
57#define FM1 (1 << 1)
58#define DIF_LEFT_JST 0x00
59#define DIF_I2S 0x01
60#define DIF_RGHT_JST16 0x02
61#define DIF_RGHT_JST24 0x03
62#define DIF_TDM0 0x04
63#define DIF_TDM1 0x05
64#define DIF_TDM2 0x06
65#define DIF_TDM3 0x07
66#define DIF_MASK 0x70
67#define MODE_FORMAT(x) (((x)&7)<<4)
68#define DEM_MASK 0x0C
69#define NO_DEM 0x00
70#define DEM_441 0x04
71#define DEM_48K 0x08
72#define DEM_32K 0x0C
73#define FM_AUTO 0x00
74#define FM_SNGL 0x01
75#define FM_DBL 0x02
76#define FM_QUAD 0x03
77#define FM_SNGL_MIN 30000
78#define FM_SNGL_MAX 54000
79#define FM_DBL_MAX 108000
80#define FM_QUAD_MAX 216000
81#define FM_MASK 0x03
82
83/* CS4349_VMI (VMI = Volume, Mixing and Inversion Controls) */
84#define VOLBISA (1 << 7)
85#define VOLAISB (1 << 7)
86/* INVERT_A only available for Left Jstfd, Right Jstfd16 and Right Jstfd24 */
87#define INVERT_A (1 << 6)
88/* INVERT_B only available for Left Jstfd, Right Jstfd16 and Right Jstfd24 */
89#define INVERT_B (1 << 5)
90#define ATAPI3 (1 << 3)
91#define ATAPI2 (1 << 2)
92#define ATAPI1 (1 << 1)
93#define ATAPI0 (1 << 0)
94#define MUTEAB 0x00
95#define MUTEA_RIGHTB 0x01
96#define MUTEA_LEFTB 0x02
97#define MUTEA_SUMLRDIV2B 0x03
98#define RIGHTA_MUTEB 0x04
99#define RIGHTA_RIGHTB 0x05
100#define RIGHTA_LEFTB 0x06
101#define RIGHTA_SUMLRDIV2B 0x07
102#define LEFTA_MUTEB 0x08
103#define LEFTA_RIGHTB 0x09 /* Default */
104#define LEFTA_LEFTB 0x0A
105#define LEFTA_SUMLRDIV2B 0x0B
106#define SUMLRDIV2A_MUTEB 0x0C
107#define SUMLRDIV2A_RIGHTB 0x0D
108#define SUMLRDIV2A_LEFTB 0x0E
109#define SUMLRDIV2_AB 0x0F
110#define CHMIX_MASK 0x0F
111
112/* CS4349_MUTE */
113#define AUTOMUTE (1 << 7)
114#define MUTEC_AB (1 << 5)
115#define MUTE_A (1 << 4)
116#define MUTE_B (1 << 3)
117#define MUTE_AB_MASK 0x18
118
119/* CS4349_RMPFLT (Ramp and Filter Control) */
120#define SCZ1 (1 << 7)
121#define SCZ0 (1 << 6)
122#define RMP_UP (1 << 5)
123#define RMP_DN (1 << 4)
124#define FILT_SEL (1 << 2)
125#define IMMDT_CHNG 0x31
126#define ZEROCRSS 0x71
127#define SOFT_RMP 0xB1
128#define SFTRMP_ZEROCRSS 0xF1
129#define SR_ZC_MASK 0xC0
130
131/* CS4349_MISC */
132#define PWR_DWN (1 << 7)
133#define FREEZE (1 << 5)
134#define POPG_EN (1 << 4)
135
136#endif /* __CS4349_H__ */
diff --git a/sound/soc/codecs/da7210.c b/sound/soc/codecs/da7210.c
index 21810e5f3321..c7b3e927c606 100644
--- a/sound/soc/codecs/da7210.c
+++ b/sound/soc/codecs/da7210.c
@@ -680,7 +680,7 @@ struct da7210_priv {
680 int master; 680 int master;
681}; 681};
682 682
683static struct reg_default da7210_reg_defaults[] = { 683static const struct reg_default da7210_reg_defaults[] = {
684 { 0x00, 0x00 }, 684 { 0x00, 0x00 },
685 { 0x01, 0x11 }, 685 { 0x01, 0x11 },
686 { 0x03, 0x00 }, 686 { 0x03, 0x00 },
@@ -1182,7 +1182,7 @@ static struct snd_soc_codec_driver soc_codec_dev_da7210 = {
1182 1182
1183#if IS_ENABLED(CONFIG_I2C) 1183#if IS_ENABLED(CONFIG_I2C)
1184 1184
1185static struct reg_default da7210_regmap_i2c_patch[] = { 1185static const struct reg_sequence da7210_regmap_i2c_patch[] = {
1186 1186
1187 /* System controller master disable */ 1187 /* System controller master disable */
1188 { DA7210_STARTUP1, 0x00 }, 1188 { DA7210_STARTUP1, 0x00 },
@@ -1259,7 +1259,6 @@ MODULE_DEVICE_TABLE(i2c, da7210_i2c_id);
1259static struct i2c_driver da7210_i2c_driver = { 1259static struct i2c_driver da7210_i2c_driver = {
1260 .driver = { 1260 .driver = {
1261 .name = "da7210", 1261 .name = "da7210",
1262 .owner = THIS_MODULE,
1263 }, 1262 },
1264 .probe = da7210_i2c_probe, 1263 .probe = da7210_i2c_probe,
1265 .remove = da7210_i2c_remove, 1264 .remove = da7210_i2c_remove,
@@ -1269,7 +1268,7 @@ static struct i2c_driver da7210_i2c_driver = {
1269 1268
1270#if defined(CONFIG_SPI_MASTER) 1269#if defined(CONFIG_SPI_MASTER)
1271 1270
1272static struct reg_default da7210_regmap_spi_patch[] = { 1271static const struct reg_sequence da7210_regmap_spi_patch[] = {
1273 /* Dummy read to give two pulses over nCS for SPI */ 1272 /* Dummy read to give two pulses over nCS for SPI */
1274 { DA7210_AUX2, 0x00 }, 1273 { DA7210_AUX2, 0x00 },
1275 { DA7210_AUX2, 0x00 }, 1274 { DA7210_AUX2, 0x00 },
diff --git a/sound/soc/codecs/da7213.c b/sound/soc/codecs/da7213.c
index 238e48a3a4fe..47fc3bec8a9c 100644
--- a/sound/soc/codecs/da7213.c
+++ b/sound/soc/codecs/da7213.c
@@ -954,7 +954,7 @@ static const struct snd_soc_dapm_route da7213_audio_map[] = {
954 {"LINE", NULL, "Lineout PGA"}, 954 {"LINE", NULL, "Lineout PGA"},
955}; 955};
956 956
957static struct reg_default da7213_reg_defaults[] = { 957static const struct reg_default da7213_reg_defaults[] = {
958 { DA7213_DIG_ROUTING_DAI, 0x10 }, 958 { DA7213_DIG_ROUTING_DAI, 0x10 },
959 { DA7213_SR, 0x0A }, 959 { DA7213_SR, 0x0A },
960 { DA7213_REFERENCES, 0x80 }, 960 { DA7213_REFERENCES, 0x80 },
@@ -1585,7 +1585,6 @@ MODULE_DEVICE_TABLE(i2c, da7213_i2c_id);
1585static struct i2c_driver da7213_i2c_driver = { 1585static struct i2c_driver da7213_i2c_driver = {
1586 .driver = { 1586 .driver = {
1587 .name = "da7213", 1587 .name = "da7213",
1588 .owner = THIS_MODULE,
1589 }, 1588 },
1590 .probe = da7213_i2c_probe, 1589 .probe = da7213_i2c_probe,
1591 .remove = da7213_remove, 1590 .remove = da7213_remove,
diff --git a/sound/soc/codecs/da732x.c b/sound/soc/codecs/da732x.c
index 207523686bd5..1d5a89c5164b 100644
--- a/sound/soc/codecs/da732x.c
+++ b/sound/soc/codecs/da732x.c
@@ -43,7 +43,7 @@ struct da732x_priv {
43/* 43/*
44 * da732x register cache - default settings 44 * da732x register cache - default settings
45 */ 45 */
46static struct reg_default da732x_reg_cache[] = { 46static const struct reg_default da732x_reg_cache[] = {
47 { DA732X_REG_REF1 , 0x02 }, 47 { DA732X_REG_REF1 , 0x02 },
48 { DA732X_REG_BIAS_EN , 0x80 }, 48 { DA732X_REG_BIAS_EN , 0x80 },
49 { DA732X_REG_BIAS1 , 0x00 }, 49 { DA732X_REG_BIAS1 , 0x00 },
@@ -1196,13 +1196,7 @@ static int da732x_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
1196#define DA732X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 1196#define DA732X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1197 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 1197 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
1198 1198
1199static struct snd_soc_dai_ops da732x_dai1_ops = { 1199static const struct snd_soc_dai_ops da732x_dai_ops = {
1200 .hw_params = da732x_hw_params,
1201 .set_fmt = da732x_set_dai_fmt,
1202 .set_sysclk = da732x_set_dai_sysclk,
1203};
1204
1205static struct snd_soc_dai_ops da732x_dai2_ops = {
1206 .hw_params = da732x_hw_params, 1200 .hw_params = da732x_hw_params,
1207 .set_fmt = da732x_set_dai_fmt, 1201 .set_fmt = da732x_set_dai_fmt,
1208 .set_sysclk = da732x_set_dai_sysclk, 1202 .set_sysclk = da732x_set_dai_sysclk,
@@ -1227,7 +1221,7 @@ static struct snd_soc_dai_driver da732x_dai[] = {
1227 .rates = DA732X_RATES, 1221 .rates = DA732X_RATES,
1228 .formats = DA732X_FORMATS, 1222 .formats = DA732X_FORMATS,
1229 }, 1223 },
1230 .ops = &da732x_dai1_ops, 1224 .ops = &da732x_dai_ops,
1231 }, 1225 },
1232 { 1226 {
1233 .name = "DA732X_AIFB", 1227 .name = "DA732X_AIFB",
@@ -1247,7 +1241,7 @@ static struct snd_soc_dai_driver da732x_dai[] = {
1247 .rates = DA732X_RATES, 1241 .rates = DA732X_RATES,
1248 .formats = DA732X_FORMATS, 1242 .formats = DA732X_FORMATS,
1249 }, 1243 },
1250 .ops = &da732x_dai2_ops, 1244 .ops = &da732x_dai_ops,
1251 }, 1245 },
1252}; 1246};
1253 1247
@@ -1572,7 +1566,6 @@ MODULE_DEVICE_TABLE(i2c, da732x_i2c_id);
1572static struct i2c_driver da732x_i2c_driver = { 1566static struct i2c_driver da732x_i2c_driver = {
1573 .driver = { 1567 .driver = {
1574 .name = "da7320", 1568 .name = "da7320",
1575 .owner = THIS_MODULE,
1576 }, 1569 },
1577 .probe = da732x_i2c_probe, 1570 .probe = da732x_i2c_probe,
1578 .remove = da732x_i2c_remove, 1571 .remove = da732x_i2c_remove,
diff --git a/sound/soc/codecs/da9055.c b/sound/soc/codecs/da9055.c
index 66bb446473b8..19635d830b47 100644
--- a/sound/soc/codecs/da9055.c
+++ b/sound/soc/codecs/da9055.c
@@ -948,7 +948,7 @@ struct da9055_priv {
948 struct da9055_platform_data *pdata; 948 struct da9055_platform_data *pdata;
949}; 949};
950 950
951static struct reg_default da9055_reg_defaults[] = { 951static const struct reg_default da9055_reg_defaults[] = {
952 { 0x21, 0x10 }, 952 { 0x21, 0x10 },
953 { 0x22, 0x0A }, 953 { 0x22, 0x0A },
954 { 0x23, 0x00 }, 954 { 0x23, 0x00 },
@@ -1533,12 +1533,12 @@ static const struct of_device_id da9055_of_match[] = {
1533 { .compatible = "dlg,da9055-codec", }, 1533 { .compatible = "dlg,da9055-codec", },
1534 { } 1534 { }
1535}; 1535};
1536MODULE_DEVICE_TABLE(of, da9055_of_match);
1536 1537
1537/* I2C codec control layer */ 1538/* I2C codec control layer */
1538static struct i2c_driver da9055_i2c_driver = { 1539static struct i2c_driver da9055_i2c_driver = {
1539 .driver = { 1540 .driver = {
1540 .name = "da9055-codec", 1541 .name = "da9055-codec",
1541 .owner = THIS_MODULE,
1542 .of_match_table = of_match_ptr(da9055_of_match), 1542 .of_match_table = of_match_ptr(da9055_of_match),
1543 }, 1543 },
1544 .probe = da9055_i2c_probe, 1544 .probe = da9055_i2c_probe,
diff --git a/sound/soc/codecs/gtm601.c b/sound/soc/codecs/gtm601.c
new file mode 100644
index 000000000000..0b80052996d3
--- /dev/null
+++ b/sound/soc/codecs/gtm601.c
@@ -0,0 +1,95 @@
1/*
2 * This is a simple driver for the GTM601 Voice PCM interface
3 *
4 * Copyright (C) 2015 Goldelico GmbH
5 *
6 * Author: Marek Belisko <marek@goldelico.com>
7 *
8 * Based on wm8727.c driver
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/init.h>
16#include <linux/slab.h>
17#include <linux/module.h>
18#include <linux/kernel.h>
19#include <linux/device.h>
20#include <sound/core.h>
21#include <sound/pcm.h>
22#include <sound/ac97_codec.h>
23#include <sound/initval.h>
24#include <sound/soc.h>
25
26static const struct snd_soc_dapm_widget gtm601_dapm_widgets[] = {
27 SND_SOC_DAPM_OUTPUT("AOUT"),
28 SND_SOC_DAPM_INPUT("AIN"),
29};
30
31static const struct snd_soc_dapm_route gtm601_dapm_routes[] = {
32 { "AOUT", NULL, "Playback" },
33 { "Capture", NULL, "AIN" },
34};
35
36static struct snd_soc_dai_driver gtm601_dai = {
37 .name = "gtm601",
38 .playback = {
39 .stream_name = "Playback",
40 .channels_min = 1,
41 .channels_max = 1,
42 .rates = SNDRV_PCM_RATE_8000,
43 .formats = SNDRV_PCM_FMTBIT_S16_LE,
44 },
45 .capture = {
46 .stream_name = "Capture",
47 .channels_min = 1,
48 .channels_max = 1,
49 .rates = SNDRV_PCM_RATE_8000,
50 .formats = SNDRV_PCM_FMTBIT_S16_LE,
51 },
52};
53
54static const struct snd_soc_codec_driver soc_codec_dev_gtm601 = {
55 .dapm_widgets = gtm601_dapm_widgets,
56 .num_dapm_widgets = ARRAY_SIZE(gtm601_dapm_widgets),
57 .dapm_routes = gtm601_dapm_routes,
58 .num_dapm_routes = ARRAY_SIZE(gtm601_dapm_routes),
59};
60
61static int gtm601_platform_probe(struct platform_device *pdev)
62{
63 return snd_soc_register_codec(&pdev->dev,
64 &soc_codec_dev_gtm601, &gtm601_dai, 1);
65}
66
67static int gtm601_platform_remove(struct platform_device *pdev)
68{
69 snd_soc_unregister_codec(&pdev->dev);
70 return 0;
71}
72
73#if defined(CONFIG_OF)
74static const struct of_device_id gtm601_codec_of_match[] = {
75 { .compatible = "option,gtm601", },
76 {},
77};
78MODULE_DEVICE_TABLE(of, gtm601_codec_of_match);
79#endif
80
81static struct platform_driver gtm601_codec_driver = {
82 .driver = {
83 .name = "gtm601",
84 .of_match_table = of_match_ptr(gtm601_codec_of_match),
85 },
86 .probe = gtm601_platform_probe,
87 .remove = gtm601_platform_remove,
88};
89
90module_platform_driver(gtm601_codec_driver);
91
92MODULE_DESCRIPTION("ASoC gtm601 driver");
93MODULE_AUTHOR("Marek Belisko <marek@goldelico.com>");
94MODULE_LICENSE("GPL");
95MODULE_ALIAS("platform:gtm601");
diff --git a/sound/soc/codecs/ics43432.c b/sound/soc/codecs/ics43432.c
new file mode 100644
index 000000000000..dd850b93938d
--- /dev/null
+++ b/sound/soc/codecs/ics43432.c
@@ -0,0 +1,76 @@
1/*
2 * I2S MEMS microphone driver for InvenSense ICS-43432
3 *
4 * - Non configurable.
5 * - I2S interface, 64 BCLs per frame, 32 bits per channel, 24 bit data
6 *
7 * Copyright (c) 2015 Axis Communications AB
8 *
9 * Licensed under GPL v2.
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/slab.h>
15#include <sound/core.h>
16#include <sound/pcm.h>
17#include <sound/pcm_params.h>
18#include <sound/soc.h>
19#include <sound/initval.h>
20#include <sound/tlv.h>
21
22#define ICS43432_RATE_MIN 7190 /* Hz, from data sheet */
23#define ICS43432_RATE_MAX 52800 /* Hz, from data sheet */
24
25#define ICS43432_FORMATS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32)
26
27static struct snd_soc_dai_driver ics43432_dai = {
28 .name = "ics43432-hifi",
29 .capture = {
30 .stream_name = "Capture",
31 .channels_min = 1,
32 .channels_max = 2,
33 .rate_min = ICS43432_RATE_MIN,
34 .rate_max = ICS43432_RATE_MAX,
35 .rates = SNDRV_PCM_RATE_CONTINUOUS,
36 .formats = ICS43432_FORMATS,
37 },
38};
39
40static struct snd_soc_codec_driver ics43432_codec_driver = {
41};
42
43static int ics43432_probe(struct platform_device *pdev)
44{
45 return snd_soc_register_codec(&pdev->dev, &ics43432_codec_driver,
46 &ics43432_dai, 1);
47}
48
49static int ics43432_remove(struct platform_device *pdev)
50{
51 snd_soc_unregister_codec(&pdev->dev);
52 return 0;
53}
54
55#ifdef CONFIG_OF
56static const struct of_device_id ics43432_ids[] = {
57 { .compatible = "invensense,ics43432", },
58 { }
59};
60MODULE_DEVICE_TABLE(of, ics43432_ids);
61#endif
62
63static struct platform_driver ics43432_driver = {
64 .driver = {
65 .name = "ics43432",
66 .of_match_table = of_match_ptr(ics43432_ids),
67 },
68 .probe = ics43432_probe,
69 .remove = ics43432_remove,
70};
71
72module_platform_driver(ics43432_driver);
73
74MODULE_DESCRIPTION("ASoC ICS43432 driver");
75MODULE_AUTHOR("Ricard Wanderlof <ricardw@axis.com>");
76MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/codecs/isabelle.c b/sound/soc/codecs/isabelle.c
index ebd90283c960..be448373d39a 100644
--- a/sound/soc/codecs/isabelle.c
+++ b/sound/soc/codecs/isabelle.c
@@ -33,7 +33,7 @@
33 33
34 34
35/* Register default values for ISABELLE driver. */ 35/* Register default values for ISABELLE driver. */
36static struct reg_default isabelle_reg_defs[] = { 36static const struct reg_default isabelle_reg_defs[] = {
37 { 0, 0x00 }, 37 { 0, 0x00 },
38 { 1, 0x00 }, 38 { 1, 0x00 },
39 { 2, 0x00 }, 39 { 2, 0x00 },
@@ -1016,25 +1016,25 @@ static int isabelle_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
1016#define ISABELLE_FORMATS (SNDRV_PCM_FMTBIT_S20_3LE |\ 1016#define ISABELLE_FORMATS (SNDRV_PCM_FMTBIT_S20_3LE |\
1017 SNDRV_PCM_FMTBIT_S32_LE) 1017 SNDRV_PCM_FMTBIT_S32_LE)
1018 1018
1019static struct snd_soc_dai_ops isabelle_hs_dai_ops = { 1019static const struct snd_soc_dai_ops isabelle_hs_dai_ops = {
1020 .hw_params = isabelle_hw_params, 1020 .hw_params = isabelle_hw_params,
1021 .set_fmt = isabelle_set_dai_fmt, 1021 .set_fmt = isabelle_set_dai_fmt,
1022 .digital_mute = isabelle_hs_mute, 1022 .digital_mute = isabelle_hs_mute,
1023}; 1023};
1024 1024
1025static struct snd_soc_dai_ops isabelle_hf_dai_ops = { 1025static const struct snd_soc_dai_ops isabelle_hf_dai_ops = {
1026 .hw_params = isabelle_hw_params, 1026 .hw_params = isabelle_hw_params,
1027 .set_fmt = isabelle_set_dai_fmt, 1027 .set_fmt = isabelle_set_dai_fmt,
1028 .digital_mute = isabelle_hf_mute, 1028 .digital_mute = isabelle_hf_mute,
1029}; 1029};
1030 1030
1031static struct snd_soc_dai_ops isabelle_line_dai_ops = { 1031static const struct snd_soc_dai_ops isabelle_line_dai_ops = {
1032 .hw_params = isabelle_hw_params, 1032 .hw_params = isabelle_hw_params,
1033 .set_fmt = isabelle_set_dai_fmt, 1033 .set_fmt = isabelle_set_dai_fmt,
1034 .digital_mute = isabelle_line_mute, 1034 .digital_mute = isabelle_line_mute,
1035}; 1035};
1036 1036
1037static struct snd_soc_dai_ops isabelle_ul_dai_ops = { 1037static const struct snd_soc_dai_ops isabelle_ul_dai_ops = {
1038 .hw_params = isabelle_hw_params, 1038 .hw_params = isabelle_hw_params,
1039 .set_fmt = isabelle_set_dai_fmt, 1039 .set_fmt = isabelle_set_dai_fmt,
1040}; 1040};
@@ -1149,7 +1149,6 @@ MODULE_DEVICE_TABLE(i2c, isabelle_i2c_id);
1149static struct i2c_driver isabelle_i2c_driver = { 1149static struct i2c_driver isabelle_i2c_driver = {
1150 .driver = { 1150 .driver = {
1151 .name = "isabelle", 1151 .name = "isabelle",
1152 .owner = THIS_MODULE,
1153 }, 1152 },
1154 .probe = isabelle_i2c_probe, 1153 .probe = isabelle_i2c_probe,
1155 .remove = isabelle_i2c_remove, 1154 .remove = isabelle_i2c_remove,
diff --git a/sound/soc/codecs/lm4857.c b/sound/soc/codecs/lm4857.c
index 99ffc49aa779..558de1053f73 100644
--- a/sound/soc/codecs/lm4857.c
+++ b/sound/soc/codecs/lm4857.c
@@ -142,7 +142,6 @@ MODULE_DEVICE_TABLE(i2c, lm4857_i2c_id);
142static struct i2c_driver lm4857_i2c_driver = { 142static struct i2c_driver lm4857_i2c_driver = {
143 .driver = { 143 .driver = {
144 .name = "lm4857", 144 .name = "lm4857",
145 .owner = THIS_MODULE,
146 }, 145 },
147 .probe = lm4857_i2c_probe, 146 .probe = lm4857_i2c_probe,
148 .id_table = lm4857_i2c_id, 147 .id_table = lm4857_i2c_id,
diff --git a/sound/soc/codecs/lm49453.c b/sound/soc/codecs/lm49453.c
index 6600aa0a33dc..9af5640e3446 100644
--- a/sound/soc/codecs/lm49453.c
+++ b/sound/soc/codecs/lm49453.c
@@ -30,7 +30,7 @@
30#include <asm/div64.h> 30#include <asm/div64.h>
31#include "lm49453.h" 31#include "lm49453.h"
32 32
33static struct reg_default lm49453_reg_defs[] = { 33static const struct reg_default lm49453_reg_defs[] = {
34 { 0, 0x00 }, 34 { 0, 0x00 },
35 { 1, 0x00 }, 35 { 1, 0x00 },
36 { 2, 0x00 }, 36 { 2, 0x00 },
@@ -188,7 +188,6 @@ static struct reg_default lm49453_reg_defs[] = {
188/* codec private data */ 188/* codec private data */
189struct lm49453_priv { 189struct lm49453_priv {
190 struct regmap *regmap; 190 struct regmap *regmap;
191 int fs_rate;
192}; 191};
193 192
194/* capture path controls */ 193/* capture path controls */
@@ -1112,13 +1111,10 @@ static int lm49453_hw_params(struct snd_pcm_substream *substream,
1112 struct snd_soc_dai *dai) 1111 struct snd_soc_dai *dai)
1113{ 1112{
1114 struct snd_soc_codec *codec = dai->codec; 1113 struct snd_soc_codec *codec = dai->codec;
1115 struct lm49453_priv *lm49453 = snd_soc_codec_get_drvdata(codec);
1116 u16 clk_div = 0; 1114 u16 clk_div = 0;
1117 1115
1118 lm49453->fs_rate = params_rate(params);
1119
1120 /* Setting DAC clock dividers based on substream sample rate. */ 1116 /* Setting DAC clock dividers based on substream sample rate. */
1121 switch (lm49453->fs_rate) { 1117 switch (params_rate(params)) {
1122 case 8000: 1118 case 8000:
1123 case 16000: 1119 case 16000:
1124 case 32000: 1120 case 32000:
@@ -1291,35 +1287,35 @@ static int lm49453_set_bias_level(struct snd_soc_codec *codec,
1291#define LM49453_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 1287#define LM49453_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1292 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 1288 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
1293 1289
1294static struct snd_soc_dai_ops lm49453_headset_dai_ops = { 1290static const struct snd_soc_dai_ops lm49453_headset_dai_ops = {
1295 .hw_params = lm49453_hw_params, 1291 .hw_params = lm49453_hw_params,
1296 .set_sysclk = lm49453_set_dai_sysclk, 1292 .set_sysclk = lm49453_set_dai_sysclk,
1297 .set_fmt = lm49453_set_dai_fmt, 1293 .set_fmt = lm49453_set_dai_fmt,
1298 .digital_mute = lm49453_hp_mute, 1294 .digital_mute = lm49453_hp_mute,
1299}; 1295};
1300 1296
1301static struct snd_soc_dai_ops lm49453_speaker_dai_ops = { 1297static const struct snd_soc_dai_ops lm49453_speaker_dai_ops = {
1302 .hw_params = lm49453_hw_params, 1298 .hw_params = lm49453_hw_params,
1303 .set_sysclk = lm49453_set_dai_sysclk, 1299 .set_sysclk = lm49453_set_dai_sysclk,
1304 .set_fmt = lm49453_set_dai_fmt, 1300 .set_fmt = lm49453_set_dai_fmt,
1305 .digital_mute = lm49453_ls_mute, 1301 .digital_mute = lm49453_ls_mute,
1306}; 1302};
1307 1303
1308static struct snd_soc_dai_ops lm49453_haptic_dai_ops = { 1304static const struct snd_soc_dai_ops lm49453_haptic_dai_ops = {
1309 .hw_params = lm49453_hw_params, 1305 .hw_params = lm49453_hw_params,
1310 .set_sysclk = lm49453_set_dai_sysclk, 1306 .set_sysclk = lm49453_set_dai_sysclk,
1311 .set_fmt = lm49453_set_dai_fmt, 1307 .set_fmt = lm49453_set_dai_fmt,
1312 .digital_mute = lm49453_ha_mute, 1308 .digital_mute = lm49453_ha_mute,
1313}; 1309};
1314 1310
1315static struct snd_soc_dai_ops lm49453_ep_dai_ops = { 1311static const struct snd_soc_dai_ops lm49453_ep_dai_ops = {
1316 .hw_params = lm49453_hw_params, 1312 .hw_params = lm49453_hw_params,
1317 .set_sysclk = lm49453_set_dai_sysclk, 1313 .set_sysclk = lm49453_set_dai_sysclk,
1318 .set_fmt = lm49453_set_dai_fmt, 1314 .set_fmt = lm49453_set_dai_fmt,
1319 .digital_mute = lm49453_ep_mute, 1315 .digital_mute = lm49453_ep_mute,
1320}; 1316};
1321 1317
1322static struct snd_soc_dai_ops lm49453_lineout_dai_ops = { 1318static const struct snd_soc_dai_ops lm49453_lineout_dai_ops = {
1323 .hw_params = lm49453_hw_params, 1319 .hw_params = lm49453_hw_params,
1324 .set_sysclk = lm49453_set_dai_sysclk, 1320 .set_sysclk = lm49453_set_dai_sysclk,
1325 .set_fmt = lm49453_set_dai_fmt, 1321 .set_fmt = lm49453_set_dai_fmt,
@@ -1460,7 +1456,6 @@ MODULE_DEVICE_TABLE(i2c, lm49453_i2c_id);
1460static struct i2c_driver lm49453_i2c_driver = { 1456static struct i2c_driver lm49453_i2c_driver = {
1461 .driver = { 1457 .driver = {
1462 .name = "lm49453", 1458 .name = "lm49453",
1463 .owner = THIS_MODULE,
1464 }, 1459 },
1465 .probe = lm49453_i2c_probe, 1460 .probe = lm49453_i2c_probe,
1466 .remove = lm49453_i2c_remove, 1461 .remove = lm49453_i2c_remove,
diff --git a/sound/soc/codecs/max9768.c b/sound/soc/codecs/max9768.c
index e1c196a41930..bd41128c6f0b 100644
--- a/sound/soc/codecs/max9768.c
+++ b/sound/soc/codecs/max9768.c
@@ -35,7 +35,7 @@ struct max9768 {
35 u32 flags; 35 u32 flags;
36}; 36};
37 37
38static struct reg_default max9768_default_regs[] = { 38static const struct reg_default max9768_default_regs[] = {
39 { 0, 0 }, 39 { 0, 0 },
40 { 3, MAX9768_CTRL_FILTERLESS}, 40 { 3, MAX9768_CTRL_FILTERLESS},
41}; 41};
@@ -43,8 +43,8 @@ static struct reg_default max9768_default_regs[] = {
43static int max9768_get_gpio(struct snd_kcontrol *kcontrol, 43static int max9768_get_gpio(struct snd_kcontrol *kcontrol,
44 struct snd_ctl_elem_value *ucontrol) 44 struct snd_ctl_elem_value *ucontrol)
45{ 45{
46 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 46 struct snd_soc_component *c = snd_soc_kcontrol_component(kcontrol);
47 struct max9768 *max9768 = snd_soc_codec_get_drvdata(codec); 47 struct max9768 *max9768 = snd_soc_component_get_drvdata(c);
48 int val = gpio_get_value_cansleep(max9768->mute_gpio); 48 int val = gpio_get_value_cansleep(max9768->mute_gpio);
49 49
50 ucontrol->value.integer.value[0] = !val; 50 ucontrol->value.integer.value[0] = !val;
@@ -55,8 +55,8 @@ static int max9768_get_gpio(struct snd_kcontrol *kcontrol,
55static int max9768_set_gpio(struct snd_kcontrol *kcontrol, 55static int max9768_set_gpio(struct snd_kcontrol *kcontrol,
56 struct snd_ctl_elem_value *ucontrol) 56 struct snd_ctl_elem_value *ucontrol)
57{ 57{
58 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 58 struct snd_soc_component *c = snd_soc_kcontrol_component(kcontrol);
59 struct max9768 *max9768 = snd_soc_codec_get_drvdata(codec); 59 struct max9768 *max9768 = snd_soc_component_get_drvdata(c);
60 60
61 gpio_set_value_cansleep(max9768->mute_gpio, !ucontrol->value.integer.value[0]); 61 gpio_set_value_cansleep(max9768->mute_gpio, !ucontrol->value.integer.value[0]);
62 62
@@ -130,19 +130,20 @@ static const struct snd_soc_dapm_route max9768_dapm_routes[] = {
130 { "OUT-", NULL, "IN" }, 130 { "OUT-", NULL, "IN" },
131}; 131};
132 132
133static int max9768_probe(struct snd_soc_codec *codec) 133static int max9768_probe(struct snd_soc_component *component)
134{ 134{
135 struct max9768 *max9768 = snd_soc_codec_get_drvdata(codec); 135 struct max9768 *max9768 = snd_soc_component_get_drvdata(component);
136 int ret; 136 int ret;
137 137
138 if (max9768->flags & MAX9768_FLAG_CLASSIC_PWM) { 138 if (max9768->flags & MAX9768_FLAG_CLASSIC_PWM) {
139 ret = snd_soc_write(codec, MAX9768_CTRL, MAX9768_CTRL_PWM); 139 ret = regmap_write(max9768->regmap, MAX9768_CTRL,
140 MAX9768_CTRL_PWM);
140 if (ret) 141 if (ret)
141 return ret; 142 return ret;
142 } 143 }
143 144
144 if (gpio_is_valid(max9768->mute_gpio)) { 145 if (gpio_is_valid(max9768->mute_gpio)) {
145 ret = snd_soc_add_codec_controls(codec, max9768_mute, 146 ret = snd_soc_add_component_controls(component, max9768_mute,
146 ARRAY_SIZE(max9768_mute)); 147 ARRAY_SIZE(max9768_mute));
147 if (ret) 148 if (ret)
148 return ret; 149 return ret;
@@ -151,7 +152,7 @@ static int max9768_probe(struct snd_soc_codec *codec)
151 return 0; 152 return 0;
152} 153}
153 154
154static struct snd_soc_codec_driver max9768_codec_driver = { 155static struct snd_soc_component_driver max9768_component_driver = {
155 .probe = max9768_probe, 156 .probe = max9768_probe,
156 .controls = max9768_volume, 157 .controls = max9768_volume,
157 .num_controls = ARRAY_SIZE(max9768_volume), 158 .num_controls = ARRAY_SIZE(max9768_volume),
@@ -183,11 +184,13 @@ static int max9768_i2c_probe(struct i2c_client *client,
183 184
184 if (pdata) { 185 if (pdata) {
185 /* Mute on powerup to avoid clicks */ 186 /* Mute on powerup to avoid clicks */
186 err = gpio_request_one(pdata->mute_gpio, GPIOF_INIT_HIGH, "MAX9768 Mute"); 187 err = devm_gpio_request_one(&client->dev, pdata->mute_gpio,
188 GPIOF_INIT_HIGH, "MAX9768 Mute");
187 max9768->mute_gpio = err ?: pdata->mute_gpio; 189 max9768->mute_gpio = err ?: pdata->mute_gpio;
188 190
189 /* Activate chip by releasing shutdown, enables I2C */ 191 /* Activate chip by releasing shutdown, enables I2C */
190 err = gpio_request_one(pdata->shdn_gpio, GPIOF_INIT_HIGH, "MAX9768 Shutdown"); 192 err = devm_gpio_request_one(&client->dev, pdata->shdn_gpio,
193 GPIOF_INIT_HIGH, "MAX9768 Shutdown");
191 max9768->shdn_gpio = err ?: pdata->shdn_gpio; 194 max9768->shdn_gpio = err ?: pdata->shdn_gpio;
192 195
193 max9768->flags = pdata->flags; 196 max9768->flags = pdata->flags;
@@ -199,38 +202,11 @@ static int max9768_i2c_probe(struct i2c_client *client,
199 i2c_set_clientdata(client, max9768); 202 i2c_set_clientdata(client, max9768);
200 203
201 max9768->regmap = devm_regmap_init_i2c(client, &max9768_i2c_regmap_config); 204 max9768->regmap = devm_regmap_init_i2c(client, &max9768_i2c_regmap_config);
202 if (IS_ERR(max9768->regmap)) { 205 if (IS_ERR(max9768->regmap))
203 err = PTR_ERR(max9768->regmap); 206 return PTR_ERR(max9768->regmap);
204 goto err_gpio_free;
205 }
206
207 err = snd_soc_register_codec(&client->dev, &max9768_codec_driver, NULL, 0);
208 if (err)
209 goto err_gpio_free;
210
211 return 0;
212
213 err_gpio_free:
214 if (gpio_is_valid(max9768->shdn_gpio))
215 gpio_free(max9768->shdn_gpio);
216 if (gpio_is_valid(max9768->mute_gpio))
217 gpio_free(max9768->mute_gpio);
218
219 return err;
220}
221
222static int max9768_i2c_remove(struct i2c_client *client)
223{
224 struct max9768 *max9768 = i2c_get_clientdata(client);
225 207
226 snd_soc_unregister_codec(&client->dev); 208 return devm_snd_soc_register_component(&client->dev,
227 209 &max9768_component_driver, NULL, 0);
228 if (gpio_is_valid(max9768->shdn_gpio))
229 gpio_free(max9768->shdn_gpio);
230 if (gpio_is_valid(max9768->mute_gpio))
231 gpio_free(max9768->mute_gpio);
232
233 return 0;
234} 210}
235 211
236static const struct i2c_device_id max9768_i2c_id[] = { 212static const struct i2c_device_id max9768_i2c_id[] = {
@@ -242,10 +218,8 @@ MODULE_DEVICE_TABLE(i2c, max9768_i2c_id);
242static struct i2c_driver max9768_i2c_driver = { 218static struct i2c_driver max9768_i2c_driver = {
243 .driver = { 219 .driver = {
244 .name = "max9768", 220 .name = "max9768",
245 .owner = THIS_MODULE,
246 }, 221 },
247 .probe = max9768_i2c_probe, 222 .probe = max9768_i2c_probe,
248 .remove = max9768_i2c_remove,
249 .id_table = max9768_i2c_id, 223 .id_table = max9768_i2c_id,
250}; 224};
251module_i2c_driver(max9768_i2c_driver); 225module_i2c_driver(max9768_i2c_driver);
diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index d0f45348bfbb..2c2df1790fd3 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -258,292 +258,36 @@ static const struct reg_default max98088_reg[] = {
258 { 0xc9, 0x00 }, /* C9 DAI2 biquad */ 258 { 0xc9, 0x00 }, /* C9 DAI2 biquad */
259}; 259};
260 260
261static struct {
262 int readable;
263 int writable;
264 int vol;
265} max98088_access[M98088_REG_CNT] = {
266 { 0xFF, 0xFF, 1 }, /* 00 IRQ status */
267 { 0xFF, 0x00, 1 }, /* 01 MIC status */
268 { 0xFF, 0x00, 1 }, /* 02 jack status */
269 { 0x1F, 0x1F, 1 }, /* 03 battery voltage */
270 { 0xFF, 0xFF, 0 }, /* 04 */
271 { 0xFF, 0xFF, 0 }, /* 05 */
272 { 0xFF, 0xFF, 0 }, /* 06 */
273 { 0xFF, 0xFF, 0 }, /* 07 */
274 { 0xFF, 0xFF, 0 }, /* 08 */
275 { 0xFF, 0xFF, 0 }, /* 09 */
276 { 0xFF, 0xFF, 0 }, /* 0A */
277 { 0xFF, 0xFF, 0 }, /* 0B */
278 { 0xFF, 0xFF, 0 }, /* 0C */
279 { 0xFF, 0xFF, 0 }, /* 0D */
280 { 0xFF, 0xFF, 0 }, /* 0E */
281 { 0xFF, 0xFF, 0 }, /* 0F interrupt enable */
282
283 { 0xFF, 0xFF, 0 }, /* 10 master clock */
284 { 0xFF, 0xFF, 0 }, /* 11 DAI1 clock mode */
285 { 0xFF, 0xFF, 0 }, /* 12 DAI1 clock control */
286 { 0xFF, 0xFF, 0 }, /* 13 DAI1 clock control */
287 { 0xFF, 0xFF, 0 }, /* 14 DAI1 format */
288 { 0xFF, 0xFF, 0 }, /* 15 DAI1 clock */
289 { 0xFF, 0xFF, 0 }, /* 16 DAI1 config */
290 { 0xFF, 0xFF, 0 }, /* 17 DAI1 TDM */
291 { 0xFF, 0xFF, 0 }, /* 18 DAI1 filters */
292 { 0xFF, 0xFF, 0 }, /* 19 DAI2 clock mode */
293 { 0xFF, 0xFF, 0 }, /* 1A DAI2 clock control */
294 { 0xFF, 0xFF, 0 }, /* 1B DAI2 clock control */
295 { 0xFF, 0xFF, 0 }, /* 1C DAI2 format */
296 { 0xFF, 0xFF, 0 }, /* 1D DAI2 clock */
297 { 0xFF, 0xFF, 0 }, /* 1E DAI2 config */
298 { 0xFF, 0xFF, 0 }, /* 1F DAI2 TDM */
299
300 { 0xFF, 0xFF, 0 }, /* 20 DAI2 filters */
301 { 0xFF, 0xFF, 0 }, /* 21 data config */
302 { 0xFF, 0xFF, 0 }, /* 22 DAC mixer */
303 { 0xFF, 0xFF, 0 }, /* 23 left ADC mixer */
304 { 0xFF, 0xFF, 0 }, /* 24 right ADC mixer */
305 { 0xFF, 0xFF, 0 }, /* 25 left HP mixer */
306 { 0xFF, 0xFF, 0 }, /* 26 right HP mixer */
307 { 0xFF, 0xFF, 0 }, /* 27 HP control */
308 { 0xFF, 0xFF, 0 }, /* 28 left REC mixer */
309 { 0xFF, 0xFF, 0 }, /* 29 right REC mixer */
310 { 0xFF, 0xFF, 0 }, /* 2A REC control */
311 { 0xFF, 0xFF, 0 }, /* 2B left SPK mixer */
312 { 0xFF, 0xFF, 0 }, /* 2C right SPK mixer */
313 { 0xFF, 0xFF, 0 }, /* 2D SPK control */
314 { 0xFF, 0xFF, 0 }, /* 2E sidetone */
315 { 0xFF, 0xFF, 0 }, /* 2F DAI1 playback level */
316
317 { 0xFF, 0xFF, 0 }, /* 30 DAI1 playback level */
318 { 0xFF, 0xFF, 0 }, /* 31 DAI2 playback level */
319 { 0xFF, 0xFF, 0 }, /* 32 DAI2 playbakc level */
320 { 0xFF, 0xFF, 0 }, /* 33 left ADC level */
321 { 0xFF, 0xFF, 0 }, /* 34 right ADC level */
322 { 0xFF, 0xFF, 0 }, /* 35 MIC1 level */
323 { 0xFF, 0xFF, 0 }, /* 36 MIC2 level */
324 { 0xFF, 0xFF, 0 }, /* 37 INA level */
325 { 0xFF, 0xFF, 0 }, /* 38 INB level */
326 { 0xFF, 0xFF, 0 }, /* 39 left HP volume */
327 { 0xFF, 0xFF, 0 }, /* 3A right HP volume */
328 { 0xFF, 0xFF, 0 }, /* 3B left REC volume */
329 { 0xFF, 0xFF, 0 }, /* 3C right REC volume */
330 { 0xFF, 0xFF, 0 }, /* 3D left SPK volume */
331 { 0xFF, 0xFF, 0 }, /* 3E right SPK volume */
332 { 0xFF, 0xFF, 0 }, /* 3F MIC config */
333
334 { 0xFF, 0xFF, 0 }, /* 40 MIC threshold */
335 { 0xFF, 0xFF, 0 }, /* 41 excursion limiter filter */
336 { 0xFF, 0xFF, 0 }, /* 42 excursion limiter threshold */
337 { 0xFF, 0xFF, 0 }, /* 43 ALC */
338 { 0xFF, 0xFF, 0 }, /* 44 power limiter threshold */
339 { 0xFF, 0xFF, 0 }, /* 45 power limiter config */
340 { 0xFF, 0xFF, 0 }, /* 46 distortion limiter config */
341 { 0xFF, 0xFF, 0 }, /* 47 audio input */
342 { 0xFF, 0xFF, 0 }, /* 48 microphone */
343 { 0xFF, 0xFF, 0 }, /* 49 level control */
344 { 0xFF, 0xFF, 0 }, /* 4A bypass switches */
345 { 0xFF, 0xFF, 0 }, /* 4B jack detect */
346 { 0xFF, 0xFF, 0 }, /* 4C input enable */
347 { 0xFF, 0xFF, 0 }, /* 4D output enable */
348 { 0xFF, 0xFF, 0 }, /* 4E bias control */
349 { 0xFF, 0xFF, 0 }, /* 4F DAC power */
350
351 { 0xFF, 0xFF, 0 }, /* 50 DAC power */
352 { 0xFF, 0xFF, 0 }, /* 51 system */
353 { 0xFF, 0xFF, 0 }, /* 52 DAI1 EQ1 */
354 { 0xFF, 0xFF, 0 }, /* 53 DAI1 EQ1 */
355 { 0xFF, 0xFF, 0 }, /* 54 DAI1 EQ1 */
356 { 0xFF, 0xFF, 0 }, /* 55 DAI1 EQ1 */
357 { 0xFF, 0xFF, 0 }, /* 56 DAI1 EQ1 */
358 { 0xFF, 0xFF, 0 }, /* 57 DAI1 EQ1 */
359 { 0xFF, 0xFF, 0 }, /* 58 DAI1 EQ1 */
360 { 0xFF, 0xFF, 0 }, /* 59 DAI1 EQ1 */
361 { 0xFF, 0xFF, 0 }, /* 5A DAI1 EQ1 */
362 { 0xFF, 0xFF, 0 }, /* 5B DAI1 EQ1 */
363 { 0xFF, 0xFF, 0 }, /* 5C DAI1 EQ2 */
364 { 0xFF, 0xFF, 0 }, /* 5D DAI1 EQ2 */
365 { 0xFF, 0xFF, 0 }, /* 5E DAI1 EQ2 */
366 { 0xFF, 0xFF, 0 }, /* 5F DAI1 EQ2 */
367
368 { 0xFF, 0xFF, 0 }, /* 60 DAI1 EQ2 */
369 { 0xFF, 0xFF, 0 }, /* 61 DAI1 EQ2 */
370 { 0xFF, 0xFF, 0 }, /* 62 DAI1 EQ2 */
371 { 0xFF, 0xFF, 0 }, /* 63 DAI1 EQ2 */
372 { 0xFF, 0xFF, 0 }, /* 64 DAI1 EQ2 */
373 { 0xFF, 0xFF, 0 }, /* 65 DAI1 EQ2 */
374 { 0xFF, 0xFF, 0 }, /* 66 DAI1 EQ3 */
375 { 0xFF, 0xFF, 0 }, /* 67 DAI1 EQ3 */
376 { 0xFF, 0xFF, 0 }, /* 68 DAI1 EQ3 */
377 { 0xFF, 0xFF, 0 }, /* 69 DAI1 EQ3 */
378 { 0xFF, 0xFF, 0 }, /* 6A DAI1 EQ3 */
379 { 0xFF, 0xFF, 0 }, /* 6B DAI1 EQ3 */
380 { 0xFF, 0xFF, 0 }, /* 6C DAI1 EQ3 */
381 { 0xFF, 0xFF, 0 }, /* 6D DAI1 EQ3 */
382 { 0xFF, 0xFF, 0 }, /* 6E DAI1 EQ3 */
383 { 0xFF, 0xFF, 0 }, /* 6F DAI1 EQ3 */
384
385 { 0xFF, 0xFF, 0 }, /* 70 DAI1 EQ4 */
386 { 0xFF, 0xFF, 0 }, /* 71 DAI1 EQ4 */
387 { 0xFF, 0xFF, 0 }, /* 72 DAI1 EQ4 */
388 { 0xFF, 0xFF, 0 }, /* 73 DAI1 EQ4 */
389 { 0xFF, 0xFF, 0 }, /* 74 DAI1 EQ4 */
390 { 0xFF, 0xFF, 0 }, /* 75 DAI1 EQ4 */
391 { 0xFF, 0xFF, 0 }, /* 76 DAI1 EQ4 */
392 { 0xFF, 0xFF, 0 }, /* 77 DAI1 EQ4 */
393 { 0xFF, 0xFF, 0 }, /* 78 DAI1 EQ4 */
394 { 0xFF, 0xFF, 0 }, /* 79 DAI1 EQ4 */
395 { 0xFF, 0xFF, 0 }, /* 7A DAI1 EQ5 */
396 { 0xFF, 0xFF, 0 }, /* 7B DAI1 EQ5 */
397 { 0xFF, 0xFF, 0 }, /* 7C DAI1 EQ5 */
398 { 0xFF, 0xFF, 0 }, /* 7D DAI1 EQ5 */
399 { 0xFF, 0xFF, 0 }, /* 7E DAI1 EQ5 */
400 { 0xFF, 0xFF, 0 }, /* 7F DAI1 EQ5 */
401
402 { 0xFF, 0xFF, 0 }, /* 80 DAI1 EQ5 */
403 { 0xFF, 0xFF, 0 }, /* 81 DAI1 EQ5 */
404 { 0xFF, 0xFF, 0 }, /* 82 DAI1 EQ5 */
405 { 0xFF, 0xFF, 0 }, /* 83 DAI1 EQ5 */
406 { 0xFF, 0xFF, 0 }, /* 84 DAI2 EQ1 */
407 { 0xFF, 0xFF, 0 }, /* 85 DAI2 EQ1 */
408 { 0xFF, 0xFF, 0 }, /* 86 DAI2 EQ1 */
409 { 0xFF, 0xFF, 0 }, /* 87 DAI2 EQ1 */
410 { 0xFF, 0xFF, 0 }, /* 88 DAI2 EQ1 */
411 { 0xFF, 0xFF, 0 }, /* 89 DAI2 EQ1 */
412 { 0xFF, 0xFF, 0 }, /* 8A DAI2 EQ1 */
413 { 0xFF, 0xFF, 0 }, /* 8B DAI2 EQ1 */
414 { 0xFF, 0xFF, 0 }, /* 8C DAI2 EQ1 */
415 { 0xFF, 0xFF, 0 }, /* 8D DAI2 EQ1 */
416 { 0xFF, 0xFF, 0 }, /* 8E DAI2 EQ2 */
417 { 0xFF, 0xFF, 0 }, /* 8F DAI2 EQ2 */
418
419 { 0xFF, 0xFF, 0 }, /* 90 DAI2 EQ2 */
420 { 0xFF, 0xFF, 0 }, /* 91 DAI2 EQ2 */
421 { 0xFF, 0xFF, 0 }, /* 92 DAI2 EQ2 */
422 { 0xFF, 0xFF, 0 }, /* 93 DAI2 EQ2 */
423 { 0xFF, 0xFF, 0 }, /* 94 DAI2 EQ2 */
424 { 0xFF, 0xFF, 0 }, /* 95 DAI2 EQ2 */
425 { 0xFF, 0xFF, 0 }, /* 96 DAI2 EQ2 */
426 { 0xFF, 0xFF, 0 }, /* 97 DAI2 EQ2 */
427 { 0xFF, 0xFF, 0 }, /* 98 DAI2 EQ3 */
428 { 0xFF, 0xFF, 0 }, /* 99 DAI2 EQ3 */
429 { 0xFF, 0xFF, 0 }, /* 9A DAI2 EQ3 */
430 { 0xFF, 0xFF, 0 }, /* 9B DAI2 EQ3 */
431 { 0xFF, 0xFF, 0 }, /* 9C DAI2 EQ3 */
432 { 0xFF, 0xFF, 0 }, /* 9D DAI2 EQ3 */
433 { 0xFF, 0xFF, 0 }, /* 9E DAI2 EQ3 */
434 { 0xFF, 0xFF, 0 }, /* 9F DAI2 EQ3 */
435
436 { 0xFF, 0xFF, 0 }, /* A0 DAI2 EQ3 */
437 { 0xFF, 0xFF, 0 }, /* A1 DAI2 EQ3 */
438 { 0xFF, 0xFF, 0 }, /* A2 DAI2 EQ4 */
439 { 0xFF, 0xFF, 0 }, /* A3 DAI2 EQ4 */
440 { 0xFF, 0xFF, 0 }, /* A4 DAI2 EQ4 */
441 { 0xFF, 0xFF, 0 }, /* A5 DAI2 EQ4 */
442 { 0xFF, 0xFF, 0 }, /* A6 DAI2 EQ4 */
443 { 0xFF, 0xFF, 0 }, /* A7 DAI2 EQ4 */
444 { 0xFF, 0xFF, 0 }, /* A8 DAI2 EQ4 */
445 { 0xFF, 0xFF, 0 }, /* A9 DAI2 EQ4 */
446 { 0xFF, 0xFF, 0 }, /* AA DAI2 EQ4 */
447 { 0xFF, 0xFF, 0 }, /* AB DAI2 EQ4 */
448 { 0xFF, 0xFF, 0 }, /* AC DAI2 EQ5 */
449 { 0xFF, 0xFF, 0 }, /* AD DAI2 EQ5 */
450 { 0xFF, 0xFF, 0 }, /* AE DAI2 EQ5 */
451 { 0xFF, 0xFF, 0 }, /* AF DAI2 EQ5 */
452
453 { 0xFF, 0xFF, 0 }, /* B0 DAI2 EQ5 */
454 { 0xFF, 0xFF, 0 }, /* B1 DAI2 EQ5 */
455 { 0xFF, 0xFF, 0 }, /* B2 DAI2 EQ5 */
456 { 0xFF, 0xFF, 0 }, /* B3 DAI2 EQ5 */
457 { 0xFF, 0xFF, 0 }, /* B4 DAI2 EQ5 */
458 { 0xFF, 0xFF, 0 }, /* B5 DAI2 EQ5 */
459 { 0xFF, 0xFF, 0 }, /* B6 DAI1 biquad */
460 { 0xFF, 0xFF, 0 }, /* B7 DAI1 biquad */
461 { 0xFF, 0xFF, 0 }, /* B8 DAI1 biquad */
462 { 0xFF, 0xFF, 0 }, /* B9 DAI1 biquad */
463 { 0xFF, 0xFF, 0 }, /* BA DAI1 biquad */
464 { 0xFF, 0xFF, 0 }, /* BB DAI1 biquad */
465 { 0xFF, 0xFF, 0 }, /* BC DAI1 biquad */
466 { 0xFF, 0xFF, 0 }, /* BD DAI1 biquad */
467 { 0xFF, 0xFF, 0 }, /* BE DAI1 biquad */
468 { 0xFF, 0xFF, 0 }, /* BF DAI1 biquad */
469
470 { 0xFF, 0xFF, 0 }, /* C0 DAI2 biquad */
471 { 0xFF, 0xFF, 0 }, /* C1 DAI2 biquad */
472 { 0xFF, 0xFF, 0 }, /* C2 DAI2 biquad */
473 { 0xFF, 0xFF, 0 }, /* C3 DAI2 biquad */
474 { 0xFF, 0xFF, 0 }, /* C4 DAI2 biquad */
475 { 0xFF, 0xFF, 0 }, /* C5 DAI2 biquad */
476 { 0xFF, 0xFF, 0 }, /* C6 DAI2 biquad */
477 { 0xFF, 0xFF, 0 }, /* C7 DAI2 biquad */
478 { 0xFF, 0xFF, 0 }, /* C8 DAI2 biquad */
479 { 0xFF, 0xFF, 0 }, /* C9 DAI2 biquad */
480 { 0x00, 0x00, 0 }, /* CA */
481 { 0x00, 0x00, 0 }, /* CB */
482 { 0x00, 0x00, 0 }, /* CC */
483 { 0x00, 0x00, 0 }, /* CD */
484 { 0x00, 0x00, 0 }, /* CE */
485 { 0x00, 0x00, 0 }, /* CF */
486
487 { 0x00, 0x00, 0 }, /* D0 */
488 { 0x00, 0x00, 0 }, /* D1 */
489 { 0x00, 0x00, 0 }, /* D2 */
490 { 0x00, 0x00, 0 }, /* D3 */
491 { 0x00, 0x00, 0 }, /* D4 */
492 { 0x00, 0x00, 0 }, /* D5 */
493 { 0x00, 0x00, 0 }, /* D6 */
494 { 0x00, 0x00, 0 }, /* D7 */
495 { 0x00, 0x00, 0 }, /* D8 */
496 { 0x00, 0x00, 0 }, /* D9 */
497 { 0x00, 0x00, 0 }, /* DA */
498 { 0x00, 0x00, 0 }, /* DB */
499 { 0x00, 0x00, 0 }, /* DC */
500 { 0x00, 0x00, 0 }, /* DD */
501 { 0x00, 0x00, 0 }, /* DE */
502 { 0x00, 0x00, 0 }, /* DF */
503
504 { 0x00, 0x00, 0 }, /* E0 */
505 { 0x00, 0x00, 0 }, /* E1 */
506 { 0x00, 0x00, 0 }, /* E2 */
507 { 0x00, 0x00, 0 }, /* E3 */
508 { 0x00, 0x00, 0 }, /* E4 */
509 { 0x00, 0x00, 0 }, /* E5 */
510 { 0x00, 0x00, 0 }, /* E6 */
511 { 0x00, 0x00, 0 }, /* E7 */
512 { 0x00, 0x00, 0 }, /* E8 */
513 { 0x00, 0x00, 0 }, /* E9 */
514 { 0x00, 0x00, 0 }, /* EA */
515 { 0x00, 0x00, 0 }, /* EB */
516 { 0x00, 0x00, 0 }, /* EC */
517 { 0x00, 0x00, 0 }, /* ED */
518 { 0x00, 0x00, 0 }, /* EE */
519 { 0x00, 0x00, 0 }, /* EF */
520
521 { 0x00, 0x00, 0 }, /* F0 */
522 { 0x00, 0x00, 0 }, /* F1 */
523 { 0x00, 0x00, 0 }, /* F2 */
524 { 0x00, 0x00, 0 }, /* F3 */
525 { 0x00, 0x00, 0 }, /* F4 */
526 { 0x00, 0x00, 0 }, /* F5 */
527 { 0x00, 0x00, 0 }, /* F6 */
528 { 0x00, 0x00, 0 }, /* F7 */
529 { 0x00, 0x00, 0 }, /* F8 */
530 { 0x00, 0x00, 0 }, /* F9 */
531 { 0x00, 0x00, 0 }, /* FA */
532 { 0x00, 0x00, 0 }, /* FB */
533 { 0x00, 0x00, 0 }, /* FC */
534 { 0x00, 0x00, 0 }, /* FD */
535 { 0x00, 0x00, 0 }, /* FE */
536 { 0xFF, 0x00, 1 }, /* FF */
537};
538
539static bool max98088_readable_register(struct device *dev, unsigned int reg) 261static bool max98088_readable_register(struct device *dev, unsigned int reg)
540{ 262{
541 return max98088_access[reg].readable; 263 switch (reg) {
264 case M98088_REG_00_IRQ_STATUS ... 0xC9:
265 case M98088_REG_FF_REV_ID:
266 return true;
267 default:
268 return false;
269 }
270}
271
272static bool max98088_writeable_register(struct device *dev, unsigned int reg)
273{
274 switch (reg) {
275 case M98088_REG_03_BATTERY_VOLTAGE ... 0xC9:
276 return true;
277 default:
278 return false;
279 }
542} 280}
543 281
544static bool max98088_volatile_register(struct device *dev, unsigned int reg) 282static bool max98088_volatile_register(struct device *dev, unsigned int reg)
545{ 283{
546 return max98088_access[reg].vol; 284 switch (reg) {
285 case M98088_REG_00_IRQ_STATUS ... M98088_REG_03_BATTERY_VOLTAGE:
286 case M98088_REG_FF_REV_ID:
287 return true;
288 default:
289 return false;
290 }
547} 291}
548 292
549static const struct regmap_config max98088_regmap = { 293static const struct regmap_config max98088_regmap = {
@@ -551,6 +295,7 @@ static const struct regmap_config max98088_regmap = {
551 .val_bits = 8, 295 .val_bits = 8,
552 296
553 .readable_reg = max98088_readable_register, 297 .readable_reg = max98088_readable_register,
298 .writeable_reg = max98088_writeable_register,
554 .volatile_reg = max98088_volatile_register, 299 .volatile_reg = max98088_volatile_register,
555 .max_register = 0xff, 300 .max_register = 0xff,
556 301
@@ -2011,7 +1756,6 @@ MODULE_DEVICE_TABLE(i2c, max98088_i2c_id);
2011static struct i2c_driver max98088_i2c_driver = { 1756static struct i2c_driver max98088_i2c_driver = {
2012 .driver = { 1757 .driver = {
2013 .name = "max98088", 1758 .name = "max98088",
2014 .owner = THIS_MODULE,
2015 }, 1759 },
2016 .probe = max98088_i2c_probe, 1760 .probe = max98088_i2c_probe,
2017 .remove = max98088_i2c_remove, 1761 .remove = max98088_i2c_remove,
diff --git a/sound/soc/codecs/max98088.h b/sound/soc/codecs/max98088.h
index be89a4f4aab8..efa39bf46742 100644
--- a/sound/soc/codecs/max98088.h
+++ b/sound/soc/codecs/max98088.h
@@ -16,7 +16,7 @@
16 */ 16 */
17#define M98088_REG_00_IRQ_STATUS 0x00 17#define M98088_REG_00_IRQ_STATUS 0x00
18#define M98088_REG_01_MIC_STATUS 0x01 18#define M98088_REG_01_MIC_STATUS 0x01
19#define M98088_REG_02_JACK_STAUS 0x02 19#define M98088_REG_02_JACK_STATUS 0x02
20#define M98088_REG_03_BATTERY_VOLTAGE 0x03 20#define M98088_REG_03_BATTERY_VOLTAGE 0x03
21#define M98088_REG_0F_IRQ_ENABLE 0x0F 21#define M98088_REG_0F_IRQ_ENABLE 0x0F
22#define M98088_REG_10_SYS_CLK 0x10 22#define M98088_REG_10_SYS_CLK 0x10
diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c
index 78268f0514e9..cdf534e7a285 100644
--- a/sound/soc/codecs/max98090.c
+++ b/sound/soc/codecs/max98090.c
@@ -267,75 +267,8 @@ static bool max98090_volatile_register(struct device *dev, unsigned int reg)
267static bool max98090_readable_register(struct device *dev, unsigned int reg) 267static bool max98090_readable_register(struct device *dev, unsigned int reg)
268{ 268{
269 switch (reg) { 269 switch (reg) {
270 case M98090_REG_DEVICE_STATUS: 270 case M98090_REG_DEVICE_STATUS ... M98090_REG_INTERRUPT_S:
271 case M98090_REG_JACK_STATUS: 271 case M98090_REG_LINE_INPUT_CONFIG ... 0xD1:
272 case M98090_REG_INTERRUPT_S:
273 case M98090_REG_RESERVED:
274 case M98090_REG_LINE_INPUT_CONFIG:
275 case M98090_REG_LINE_INPUT_LEVEL:
276 case M98090_REG_INPUT_MODE:
277 case M98090_REG_MIC1_INPUT_LEVEL:
278 case M98090_REG_MIC2_INPUT_LEVEL:
279 case M98090_REG_MIC_BIAS_VOLTAGE:
280 case M98090_REG_DIGITAL_MIC_ENABLE:
281 case M98090_REG_DIGITAL_MIC_CONFIG:
282 case M98090_REG_LEFT_ADC_MIXER:
283 case M98090_REG_RIGHT_ADC_MIXER:
284 case M98090_REG_LEFT_ADC_LEVEL:
285 case M98090_REG_RIGHT_ADC_LEVEL:
286 case M98090_REG_ADC_BIQUAD_LEVEL:
287 case M98090_REG_ADC_SIDETONE:
288 case M98090_REG_SYSTEM_CLOCK:
289 case M98090_REG_CLOCK_MODE:
290 case M98090_REG_CLOCK_RATIO_NI_MSB:
291 case M98090_REG_CLOCK_RATIO_NI_LSB:
292 case M98090_REG_CLOCK_RATIO_MI_MSB:
293 case M98090_REG_CLOCK_RATIO_MI_LSB:
294 case M98090_REG_MASTER_MODE:
295 case M98090_REG_INTERFACE_FORMAT:
296 case M98090_REG_TDM_CONTROL:
297 case M98090_REG_TDM_FORMAT:
298 case M98090_REG_IO_CONFIGURATION:
299 case M98090_REG_FILTER_CONFIG:
300 case M98090_REG_DAI_PLAYBACK_LEVEL:
301 case M98090_REG_DAI_PLAYBACK_LEVEL_EQ:
302 case M98090_REG_LEFT_HP_MIXER:
303 case M98090_REG_RIGHT_HP_MIXER:
304 case M98090_REG_HP_CONTROL:
305 case M98090_REG_LEFT_HP_VOLUME:
306 case M98090_REG_RIGHT_HP_VOLUME:
307 case M98090_REG_LEFT_SPK_MIXER:
308 case M98090_REG_RIGHT_SPK_MIXER:
309 case M98090_REG_SPK_CONTROL:
310 case M98090_REG_LEFT_SPK_VOLUME:
311 case M98090_REG_RIGHT_SPK_VOLUME:
312 case M98090_REG_DRC_TIMING:
313 case M98090_REG_DRC_COMPRESSOR:
314 case M98090_REG_DRC_EXPANDER:
315 case M98090_REG_DRC_GAIN:
316 case M98090_REG_RCV_LOUTL_MIXER:
317 case M98090_REG_RCV_LOUTL_CONTROL:
318 case M98090_REG_RCV_LOUTL_VOLUME:
319 case M98090_REG_LOUTR_MIXER:
320 case M98090_REG_LOUTR_CONTROL:
321 case M98090_REG_LOUTR_VOLUME:
322 case M98090_REG_JACK_DETECT:
323 case M98090_REG_INPUT_ENABLE:
324 case M98090_REG_OUTPUT_ENABLE:
325 case M98090_REG_LEVEL_CONTROL:
326 case M98090_REG_DSP_FILTER_ENABLE:
327 case M98090_REG_BIAS_CONTROL:
328 case M98090_REG_DAC_CONTROL:
329 case M98090_REG_ADC_CONTROL:
330 case M98090_REG_DEVICE_SHUTDOWN:
331 case M98090_REG_EQUALIZER_BASE ... M98090_REG_EQUALIZER_BASE + 0x68:
332 case M98090_REG_RECORD_BIQUAD_BASE ... M98090_REG_RECORD_BIQUAD_BASE + 0x0E:
333 case M98090_REG_DMIC3_VOLUME:
334 case M98090_REG_DMIC4_VOLUME:
335 case M98090_REG_DMIC34_BQ_PREATTEN:
336 case M98090_REG_RECORD_TDM_SLOT:
337 case M98090_REG_SAMPLE_RATE:
338 case M98090_REG_DMIC34_BIQUAD_BASE ... M98090_REG_DMIC34_BIQUAD_BASE + 0x0E:
339 case M98090_REG_REVISION_ID: 272 case M98090_REG_REVISION_ID:
340 return true; 273 return true;
341 default: 274 default:
@@ -850,6 +783,19 @@ static int max98090_micinput_event(struct snd_soc_dapm_widget *w,
850 return 0; 783 return 0;
851} 784}
852 785
786static int max98090_shdn_event(struct snd_soc_dapm_widget *w,
787 struct snd_kcontrol *kcontrol, int event)
788{
789 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
790 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
791
792 if (event & SND_SOC_DAPM_POST_PMU)
793 max98090->shdn_pending = true;
794
795 return 0;
796
797}
798
853static const char *mic1_mux_text[] = { "IN12", "IN56" }; 799static const char *mic1_mux_text[] = { "IN12", "IN56" };
854 800
855static SOC_ENUM_SINGLE_DECL(mic1_mux_enum, 801static SOC_ENUM_SINGLE_DECL(mic1_mux_enum,
@@ -1158,9 +1104,11 @@ static const struct snd_soc_dapm_widget max98090_dapm_widgets[] = {
1158 SND_SOC_DAPM_SUPPLY("SDOEN", M98090_REG_IO_CONFIGURATION, 1104 SND_SOC_DAPM_SUPPLY("SDOEN", M98090_REG_IO_CONFIGURATION,
1159 M98090_SDOEN_SHIFT, 0, NULL, 0), 1105 M98090_SDOEN_SHIFT, 0, NULL, 0),
1160 SND_SOC_DAPM_SUPPLY("DMICL_ENA", M98090_REG_DIGITAL_MIC_ENABLE, 1106 SND_SOC_DAPM_SUPPLY("DMICL_ENA", M98090_REG_DIGITAL_MIC_ENABLE,
1161 M98090_DIGMICL_SHIFT, 0, NULL, 0), 1107 M98090_DIGMICL_SHIFT, 0, max98090_shdn_event,
1108 SND_SOC_DAPM_POST_PMU),
1162 SND_SOC_DAPM_SUPPLY("DMICR_ENA", M98090_REG_DIGITAL_MIC_ENABLE, 1109 SND_SOC_DAPM_SUPPLY("DMICR_ENA", M98090_REG_DIGITAL_MIC_ENABLE,
1163 M98090_DIGMICR_SHIFT, 0, NULL, 0), 1110 M98090_DIGMICR_SHIFT, 0, max98090_shdn_event,
1111 SND_SOC_DAPM_POST_PMU),
1164 SND_SOC_DAPM_SUPPLY("AHPF", M98090_REG_FILTER_CONFIG, 1112 SND_SOC_DAPM_SUPPLY("AHPF", M98090_REG_FILTER_CONFIG,
1165 M98090_AHPF_SHIFT, 0, NULL, 0), 1113 M98090_AHPF_SHIFT, 0, NULL, 0),
1166 1114
@@ -1205,10 +1153,12 @@ static const struct snd_soc_dapm_widget max98090_dapm_widgets[] = {
1205 &max98090_right_adc_mixer_controls[0], 1153 &max98090_right_adc_mixer_controls[0],
1206 ARRAY_SIZE(max98090_right_adc_mixer_controls)), 1154 ARRAY_SIZE(max98090_right_adc_mixer_controls)),
1207 1155
1208 SND_SOC_DAPM_ADC("ADCL", NULL, M98090_REG_INPUT_ENABLE, 1156 SND_SOC_DAPM_ADC_E("ADCL", NULL, M98090_REG_INPUT_ENABLE,
1209 M98090_ADLEN_SHIFT, 0), 1157 M98090_ADLEN_SHIFT, 0, max98090_shdn_event,
1210 SND_SOC_DAPM_ADC("ADCR", NULL, M98090_REG_INPUT_ENABLE, 1158 SND_SOC_DAPM_POST_PMU),
1211 M98090_ADREN_SHIFT, 0), 1159 SND_SOC_DAPM_ADC_E("ADCR", NULL, M98090_REG_INPUT_ENABLE,
1160 M98090_ADREN_SHIFT, 0, max98090_shdn_event,
1161 SND_SOC_DAPM_POST_PMU),
1212 1162
1213 SND_SOC_DAPM_AIF_OUT("AIFOUTL", "HiFi Capture", 0, 1163 SND_SOC_DAPM_AIF_OUT("AIFOUTL", "HiFi Capture", 0,
1214 SND_SOC_NOPM, 0, 0), 1164 SND_SOC_NOPM, 0, 0),
@@ -1801,10 +1751,13 @@ static int max98090_set_bias_level(struct snd_soc_codec *codec,
1801 if (IS_ERR(max98090->mclk)) 1751 if (IS_ERR(max98090->mclk))
1802 break; 1752 break;
1803 1753
1804 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON) 1754 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON) {
1805 clk_disable_unprepare(max98090->mclk); 1755 clk_disable_unprepare(max98090->mclk);
1806 else 1756 } else {
1807 clk_prepare_enable(max98090->mclk); 1757 ret = clk_prepare_enable(max98090->mclk);
1758 if (ret)
1759 return ret;
1760 }
1808 break; 1761 break;
1809 1762
1810 case SND_SOC_BIAS_STANDBY: 1763 case SND_SOC_BIAS_STANDBY:
@@ -2383,7 +2336,7 @@ EXPORT_SYMBOL_GPL(max98090_mic_detect);
2383#define MAX98090_RATES SNDRV_PCM_RATE_8000_96000 2336#define MAX98090_RATES SNDRV_PCM_RATE_8000_96000
2384#define MAX98090_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE) 2337#define MAX98090_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE)
2385 2338
2386static struct snd_soc_dai_ops max98090_dai_ops = { 2339static const struct snd_soc_dai_ops max98090_dai_ops = {
2387 .set_sysclk = max98090_dai_set_sysclk, 2340 .set_sysclk = max98090_dai_set_sysclk,
2388 .set_fmt = max98090_dai_set_fmt, 2341 .set_fmt = max98090_dai_set_fmt,
2389 .set_tdm_slot = max98090_set_tdm_slot, 2342 .set_tdm_slot = max98090_set_tdm_slot,
@@ -2536,9 +2489,26 @@ static int max98090_remove(struct snd_soc_codec *codec)
2536 return 0; 2489 return 0;
2537} 2490}
2538 2491
2492static void max98090_seq_notifier(struct snd_soc_dapm_context *dapm,
2493 enum snd_soc_dapm_type event, int subseq)
2494{
2495 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
2496 struct max98090_priv *max98090 = snd_soc_codec_get_drvdata(codec);
2497
2498 if (max98090->shdn_pending) {
2499 snd_soc_update_bits(codec, M98090_REG_DEVICE_SHUTDOWN,
2500 M98090_SHDNN_MASK, 0);
2501 msleep(40);
2502 snd_soc_update_bits(codec, M98090_REG_DEVICE_SHUTDOWN,
2503 M98090_SHDNN_MASK, M98090_SHDNN_MASK);
2504 max98090->shdn_pending = false;
2505 }
2506}
2507
2539static struct snd_soc_codec_driver soc_codec_dev_max98090 = { 2508static struct snd_soc_codec_driver soc_codec_dev_max98090 = {
2540 .probe = max98090_probe, 2509 .probe = max98090_probe,
2541 .remove = max98090_remove, 2510 .remove = max98090_remove,
2511 .seq_notifier = max98090_seq_notifier,
2542 .set_bias_level = max98090_set_bias_level, 2512 .set_bias_level = max98090_set_bias_level,
2543}; 2513};
2544 2514
@@ -2714,7 +2684,6 @@ MODULE_DEVICE_TABLE(acpi, max98090_acpi_match);
2714static struct i2c_driver max98090_i2c_driver = { 2684static struct i2c_driver max98090_i2c_driver = {
2715 .driver = { 2685 .driver = {
2716 .name = "max98090", 2686 .name = "max98090",
2717 .owner = THIS_MODULE,
2718 .pm = &max98090_pm, 2687 .pm = &max98090_pm,
2719 .of_match_table = of_match_ptr(max98090_of_match), 2688 .of_match_table = of_match_ptr(max98090_of_match),
2720 .acpi_match_table = ACPI_PTR(max98090_acpi_match), 2689 .acpi_match_table = ACPI_PTR(max98090_acpi_match),
diff --git a/sound/soc/codecs/max98090.h b/sound/soc/codecs/max98090.h
index 21ff743f5af2..bc610d9a9ecb 100644
--- a/sound/soc/codecs/max98090.h
+++ b/sound/soc/codecs/max98090.h
@@ -1543,6 +1543,7 @@ struct max98090_priv {
1543 unsigned int pa2en; 1543 unsigned int pa2en;
1544 unsigned int sidetone; 1544 unsigned int sidetone;
1545 bool master; 1545 bool master;
1546 bool shdn_pending;
1546}; 1547};
1547 1548
1548int max98090_mic_detect(struct snd_soc_codec *codec, 1549int max98090_mic_detect(struct snd_soc_codec *codec,
diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c
index 9a46d3dcf703..ad4909e17327 100644
--- a/sound/soc/codecs/max98095.c
+++ b/sound/soc/codecs/max98095.c
@@ -202,300 +202,36 @@ static const struct reg_default max98095_reg_def[] = {
202 { 0xff, 0x00 }, /* FF */ 202 { 0xff, 0x00 }, /* FF */
203}; 203};
204 204
205static struct {
206 int readable;
207 int writable;
208} max98095_access[M98095_REG_CNT] = {
209 { 0x00, 0x00 }, /* 00 */
210 { 0xFF, 0x00 }, /* 01 */
211 { 0xFF, 0x00 }, /* 02 */
212 { 0xFF, 0x00 }, /* 03 */
213 { 0xFF, 0x00 }, /* 04 */
214 { 0xFF, 0x00 }, /* 05 */
215 { 0xFF, 0x00 }, /* 06 */
216 { 0xFF, 0x00 }, /* 07 */
217 { 0xFF, 0x00 }, /* 08 */
218 { 0xFF, 0x00 }, /* 09 */
219 { 0xFF, 0x00 }, /* 0A */
220 { 0xFF, 0x00 }, /* 0B */
221 { 0xFF, 0x00 }, /* 0C */
222 { 0xFF, 0x00 }, /* 0D */
223 { 0xFF, 0x00 }, /* 0E */
224 { 0xFF, 0x9F }, /* 0F */
225 { 0xFF, 0xFF }, /* 10 */
226 { 0xFF, 0xFF }, /* 11 */
227 { 0xFF, 0xFF }, /* 12 */
228 { 0xFF, 0xFF }, /* 13 */
229 { 0xFF, 0xFF }, /* 14 */
230 { 0xFF, 0xFF }, /* 15 */
231 { 0xFF, 0xFF }, /* 16 */
232 { 0xFF, 0xFF }, /* 17 */
233 { 0xFF, 0xFF }, /* 18 */
234 { 0xFF, 0xFF }, /* 19 */
235 { 0xFF, 0xFF }, /* 1A */
236 { 0xFF, 0xFF }, /* 1B */
237 { 0xFF, 0xFF }, /* 1C */
238 { 0xFF, 0xFF }, /* 1D */
239 { 0xFF, 0x77 }, /* 1E */
240 { 0xFF, 0x77 }, /* 1F */
241 { 0xFF, 0x77 }, /* 20 */
242 { 0xFF, 0x77 }, /* 21 */
243 { 0xFF, 0x77 }, /* 22 */
244 { 0xFF, 0x77 }, /* 23 */
245 { 0xFF, 0xFF }, /* 24 */
246 { 0xFF, 0x7F }, /* 25 */
247 { 0xFF, 0x31 }, /* 26 */
248 { 0xFF, 0xFF }, /* 27 */
249 { 0xFF, 0xFF }, /* 28 */
250 { 0xFF, 0xFF }, /* 29 */
251 { 0xFF, 0xF7 }, /* 2A */
252 { 0xFF, 0x2F }, /* 2B */
253 { 0xFF, 0xEF }, /* 2C */
254 { 0xFF, 0xFF }, /* 2D */
255 { 0xFF, 0xFF }, /* 2E */
256 { 0xFF, 0xFF }, /* 2F */
257 { 0xFF, 0xFF }, /* 30 */
258 { 0xFF, 0xFF }, /* 31 */
259 { 0xFF, 0xFF }, /* 32 */
260 { 0xFF, 0xFF }, /* 33 */
261 { 0xFF, 0xF7 }, /* 34 */
262 { 0xFF, 0x2F }, /* 35 */
263 { 0xFF, 0xCF }, /* 36 */
264 { 0xFF, 0xFF }, /* 37 */
265 { 0xFF, 0xFF }, /* 38 */
266 { 0xFF, 0xFF }, /* 39 */
267 { 0xFF, 0xFF }, /* 3A */
268 { 0xFF, 0xFF }, /* 3B */
269 { 0xFF, 0xFF }, /* 3C */
270 { 0xFF, 0xFF }, /* 3D */
271 { 0xFF, 0xF7 }, /* 3E */
272 { 0xFF, 0x2F }, /* 3F */
273 { 0xFF, 0xCF }, /* 40 */
274 { 0xFF, 0xFF }, /* 41 */
275 { 0xFF, 0x77 }, /* 42 */
276 { 0xFF, 0xFF }, /* 43 */
277 { 0xFF, 0xFF }, /* 44 */
278 { 0xFF, 0xFF }, /* 45 */
279 { 0xFF, 0xFF }, /* 46 */
280 { 0xFF, 0xFF }, /* 47 */
281 { 0xFF, 0xFF }, /* 48 */
282 { 0xFF, 0x0F }, /* 49 */
283 { 0xFF, 0xFF }, /* 4A */
284 { 0xFF, 0xFF }, /* 4B */
285 { 0xFF, 0x3F }, /* 4C */
286 { 0xFF, 0x3F }, /* 4D */
287 { 0xFF, 0x3F }, /* 4E */
288 { 0xFF, 0xFF }, /* 4F */
289 { 0xFF, 0x7F }, /* 50 */
290 { 0xFF, 0x7F }, /* 51 */
291 { 0xFF, 0x0F }, /* 52 */
292 { 0xFF, 0x3F }, /* 53 */
293 { 0xFF, 0x3F }, /* 54 */
294 { 0xFF, 0x3F }, /* 55 */
295 { 0xFF, 0xFF }, /* 56 */
296 { 0xFF, 0xFF }, /* 57 */
297 { 0xFF, 0xBF }, /* 58 */
298 { 0xFF, 0x1F }, /* 59 */
299 { 0xFF, 0xBF }, /* 5A */
300 { 0xFF, 0x1F }, /* 5B */
301 { 0xFF, 0xBF }, /* 5C */
302 { 0xFF, 0x3F }, /* 5D */
303 { 0xFF, 0x3F }, /* 5E */
304 { 0xFF, 0x7F }, /* 5F */
305 { 0xFF, 0x7F }, /* 60 */
306 { 0xFF, 0x47 }, /* 61 */
307 { 0xFF, 0x9F }, /* 62 */
308 { 0xFF, 0x9F }, /* 63 */
309 { 0xFF, 0x9F }, /* 64 */
310 { 0xFF, 0x9F }, /* 65 */
311 { 0xFF, 0x9F }, /* 66 */
312 { 0xFF, 0xBF }, /* 67 */
313 { 0xFF, 0xBF }, /* 68 */
314 { 0xFF, 0xFF }, /* 69 */
315 { 0xFF, 0xFF }, /* 6A */
316 { 0xFF, 0x7F }, /* 6B */
317 { 0xFF, 0xF7 }, /* 6C */
318 { 0xFF, 0xFF }, /* 6D */
319 { 0xFF, 0xFF }, /* 6E */
320 { 0xFF, 0x1F }, /* 6F */
321 { 0xFF, 0xF7 }, /* 70 */
322 { 0xFF, 0xFF }, /* 71 */
323 { 0xFF, 0xFF }, /* 72 */
324 { 0xFF, 0x1F }, /* 73 */
325 { 0xFF, 0xF7 }, /* 74 */
326 { 0xFF, 0xFF }, /* 75 */
327 { 0xFF, 0xFF }, /* 76 */
328 { 0xFF, 0x1F }, /* 77 */
329 { 0xFF, 0xF7 }, /* 78 */
330 { 0xFF, 0xFF }, /* 79 */
331 { 0xFF, 0xFF }, /* 7A */
332 { 0xFF, 0x1F }, /* 7B */
333 { 0xFF, 0xF7 }, /* 7C */
334 { 0xFF, 0xFF }, /* 7D */
335 { 0xFF, 0xFF }, /* 7E */
336 { 0xFF, 0x1F }, /* 7F */
337 { 0xFF, 0xF7 }, /* 80 */
338 { 0xFF, 0xFF }, /* 81 */
339 { 0xFF, 0xFF }, /* 82 */
340 { 0xFF, 0x1F }, /* 83 */
341 { 0xFF, 0x7F }, /* 84 */
342 { 0xFF, 0x0F }, /* 85 */
343 { 0xFF, 0xD8 }, /* 86 */
344 { 0xFF, 0xFF }, /* 87 */
345 { 0xFF, 0xEF }, /* 88 */
346 { 0xFF, 0xFE }, /* 89 */
347 { 0xFF, 0xFE }, /* 8A */
348 { 0xFF, 0xFF }, /* 8B */
349 { 0xFF, 0xFF }, /* 8C */
350 { 0xFF, 0x3F }, /* 8D */
351 { 0xFF, 0xFF }, /* 8E */
352 { 0xFF, 0x3F }, /* 8F */
353 { 0xFF, 0x8F }, /* 90 */
354 { 0xFF, 0xFF }, /* 91 */
355 { 0xFF, 0x3F }, /* 92 */
356 { 0xFF, 0xFF }, /* 93 */
357 { 0xFF, 0xFF }, /* 94 */
358 { 0xFF, 0x0F }, /* 95 */
359 { 0xFF, 0x3F }, /* 96 */
360 { 0xFF, 0x8C }, /* 97 */
361 { 0x00, 0x00 }, /* 98 */
362 { 0x00, 0x00 }, /* 99 */
363 { 0x00, 0x00 }, /* 9A */
364 { 0x00, 0x00 }, /* 9B */
365 { 0x00, 0x00 }, /* 9C */
366 { 0x00, 0x00 }, /* 9D */
367 { 0x00, 0x00 }, /* 9E */
368 { 0x00, 0x00 }, /* 9F */
369 { 0x00, 0x00 }, /* A0 */
370 { 0x00, 0x00 }, /* A1 */
371 { 0x00, 0x00 }, /* A2 */
372 { 0x00, 0x00 }, /* A3 */
373 { 0x00, 0x00 }, /* A4 */
374 { 0x00, 0x00 }, /* A5 */
375 { 0x00, 0x00 }, /* A6 */
376 { 0x00, 0x00 }, /* A7 */
377 { 0x00, 0x00 }, /* A8 */
378 { 0x00, 0x00 }, /* A9 */
379 { 0x00, 0x00 }, /* AA */
380 { 0x00, 0x00 }, /* AB */
381 { 0x00, 0x00 }, /* AC */
382 { 0x00, 0x00 }, /* AD */
383 { 0x00, 0x00 }, /* AE */
384 { 0x00, 0x00 }, /* AF */
385 { 0x00, 0x00 }, /* B0 */
386 { 0x00, 0x00 }, /* B1 */
387 { 0x00, 0x00 }, /* B2 */
388 { 0x00, 0x00 }, /* B3 */
389 { 0x00, 0x00 }, /* B4 */
390 { 0x00, 0x00 }, /* B5 */
391 { 0x00, 0x00 }, /* B6 */
392 { 0x00, 0x00 }, /* B7 */
393 { 0x00, 0x00 }, /* B8 */
394 { 0x00, 0x00 }, /* B9 */
395 { 0x00, 0x00 }, /* BA */
396 { 0x00, 0x00 }, /* BB */
397 { 0x00, 0x00 }, /* BC */
398 { 0x00, 0x00 }, /* BD */
399 { 0x00, 0x00 }, /* BE */
400 { 0x00, 0x00 }, /* BF */
401 { 0x00, 0x00 }, /* C0 */
402 { 0x00, 0x00 }, /* C1 */
403 { 0x00, 0x00 }, /* C2 */
404 { 0x00, 0x00 }, /* C3 */
405 { 0x00, 0x00 }, /* C4 */
406 { 0x00, 0x00 }, /* C5 */
407 { 0x00, 0x00 }, /* C6 */
408 { 0x00, 0x00 }, /* C7 */
409 { 0x00, 0x00 }, /* C8 */
410 { 0x00, 0x00 }, /* C9 */
411 { 0x00, 0x00 }, /* CA */
412 { 0x00, 0x00 }, /* CB */
413 { 0x00, 0x00 }, /* CC */
414 { 0x00, 0x00 }, /* CD */
415 { 0x00, 0x00 }, /* CE */
416 { 0x00, 0x00 }, /* CF */
417 { 0x00, 0x00 }, /* D0 */
418 { 0x00, 0x00 }, /* D1 */
419 { 0x00, 0x00 }, /* D2 */
420 { 0x00, 0x00 }, /* D3 */
421 { 0x00, 0x00 }, /* D4 */
422 { 0x00, 0x00 }, /* D5 */
423 { 0x00, 0x00 }, /* D6 */
424 { 0x00, 0x00 }, /* D7 */
425 { 0x00, 0x00 }, /* D8 */
426 { 0x00, 0x00 }, /* D9 */
427 { 0x00, 0x00 }, /* DA */
428 { 0x00, 0x00 }, /* DB */
429 { 0x00, 0x00 }, /* DC */
430 { 0x00, 0x00 }, /* DD */
431 { 0x00, 0x00 }, /* DE */
432 { 0x00, 0x00 }, /* DF */
433 { 0x00, 0x00 }, /* E0 */
434 { 0x00, 0x00 }, /* E1 */
435 { 0x00, 0x00 }, /* E2 */
436 { 0x00, 0x00 }, /* E3 */
437 { 0x00, 0x00 }, /* E4 */
438 { 0x00, 0x00 }, /* E5 */
439 { 0x00, 0x00 }, /* E6 */
440 { 0x00, 0x00 }, /* E7 */
441 { 0x00, 0x00 }, /* E8 */
442 { 0x00, 0x00 }, /* E9 */
443 { 0x00, 0x00 }, /* EA */
444 { 0x00, 0x00 }, /* EB */
445 { 0x00, 0x00 }, /* EC */
446 { 0x00, 0x00 }, /* ED */
447 { 0x00, 0x00 }, /* EE */
448 { 0x00, 0x00 }, /* EF */
449 { 0x00, 0x00 }, /* F0 */
450 { 0x00, 0x00 }, /* F1 */
451 { 0x00, 0x00 }, /* F2 */
452 { 0x00, 0x00 }, /* F3 */
453 { 0x00, 0x00 }, /* F4 */
454 { 0x00, 0x00 }, /* F5 */
455 { 0x00, 0x00 }, /* F6 */
456 { 0x00, 0x00 }, /* F7 */
457 { 0x00, 0x00 }, /* F8 */
458 { 0x00, 0x00 }, /* F9 */
459 { 0x00, 0x00 }, /* FA */
460 { 0x00, 0x00 }, /* FB */
461 { 0x00, 0x00 }, /* FC */
462 { 0x00, 0x00 }, /* FD */
463 { 0x00, 0x00 }, /* FE */
464 { 0xFF, 0x00 }, /* FF */
465};
466
467static bool max98095_readable(struct device *dev, unsigned int reg) 205static bool max98095_readable(struct device *dev, unsigned int reg)
468{ 206{
469 if (reg >= M98095_REG_CNT) 207 switch (reg) {
470 return 0; 208 case M98095_001_HOST_INT_STS ... M98095_097_PWR_SYS:
471 return max98095_access[reg].readable != 0; 209 case M98095_0FF_REV_ID:
210 return true;
211 default:
212 return false;
213 }
472} 214}
473 215
474static bool max98095_volatile(struct device *dev, unsigned int reg) 216static bool max98095_writeable(struct device *dev, unsigned int reg)
475{ 217{
476 if (reg > M98095_REG_MAX_CACHED)
477 return 1;
478
479 switch (reg) { 218 switch (reg) {
480 case M98095_000_HOST_DATA: 219 case M98095_00F_HOST_CFG ... M98095_097_PWR_SYS:
481 case M98095_001_HOST_INT_STS: 220 return true;
482 case M98095_002_HOST_RSP_STS: 221 default:
483 case M98095_003_HOST_CMD_STS: 222 return false;
484 case M98095_004_CODEC_STS:
485 case M98095_005_DAI1_ALC_STS:
486 case M98095_006_DAI2_ALC_STS:
487 case M98095_007_JACK_AUTO_STS:
488 case M98095_008_JACK_MANUAL_STS:
489 case M98095_009_JACK_VBAT_STS:
490 case M98095_00A_ACC_ADC_STS:
491 case M98095_00B_MIC_NG_AGC_STS:
492 case M98095_00C_SPK_L_VOLT_STS:
493 case M98095_00D_SPK_R_VOLT_STS:
494 case M98095_00E_TEMP_SENSOR_STS:
495 return 1;
496 } 223 }
224}
497 225
498 return 0; 226static bool max98095_volatile(struct device *dev, unsigned int reg)
227{
228 switch (reg) {
229 case M98095_000_HOST_DATA ... M98095_00E_TEMP_SENSOR_STS:
230 case M98095_REG_MAX_CACHED + 1 ... M98095_0FF_REV_ID:
231 return true;
232 default:
233 return false;
234 }
499} 235}
500 236
501static const struct regmap_config max98095_regmap = { 237static const struct regmap_config max98095_regmap = {
@@ -508,6 +244,7 @@ static const struct regmap_config max98095_regmap = {
508 .cache_type = REGCACHE_RBTREE, 244 .cache_type = REGCACHE_RBTREE,
509 245
510 .readable_reg = max98095_readable, 246 .readable_reg = max98095_readable,
247 .writeable_reg = max98095_writeable,
511 .volatile_reg = max98095_volatile, 248 .volatile_reg = max98095_volatile,
512}; 249};
513 250
@@ -1653,10 +1390,13 @@ static int max98095_set_bias_level(struct snd_soc_codec *codec,
1653 if (IS_ERR(max98095->mclk)) 1390 if (IS_ERR(max98095->mclk))
1654 break; 1391 break;
1655 1392
1656 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON) 1393 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON) {
1657 clk_disable_unprepare(max98095->mclk); 1394 clk_disable_unprepare(max98095->mclk);
1658 else 1395 } else {
1659 clk_prepare_enable(max98095->mclk); 1396 ret = clk_prepare_enable(max98095->mclk);
1397 if (ret)
1398 return ret;
1399 }
1660 break; 1400 break;
1661 1401
1662 case SND_SOC_BIAS_STANDBY: 1402 case SND_SOC_BIAS_STANDBY:
@@ -2431,7 +2171,6 @@ MODULE_DEVICE_TABLE(of, max98095_of_match);
2431static struct i2c_driver max98095_i2c_driver = { 2171static struct i2c_driver max98095_i2c_driver = {
2432 .driver = { 2172 .driver = {
2433 .name = "max98095", 2173 .name = "max98095",
2434 .owner = THIS_MODULE,
2435 .of_match_table = of_match_ptr(max98095_of_match), 2174 .of_match_table = of_match_ptr(max98095_of_match),
2436 }, 2175 },
2437 .probe = max98095_i2c_probe, 2176 .probe = max98095_i2c_probe,
diff --git a/sound/soc/codecs/max98357a.c b/sound/soc/codecs/max98357a.c
index 3a2fda08a893..f5e3dce2633a 100644
--- a/sound/soc/codecs/max98357a.c
+++ b/sound/soc/codecs/max98357a.c
@@ -31,6 +31,9 @@ static int max98357a_daiops_trigger(struct snd_pcm_substream *substream,
31{ 31{
32 struct gpio_desc *sdmode = snd_soc_dai_get_drvdata(dai); 32 struct gpio_desc *sdmode = snd_soc_dai_get_drvdata(dai);
33 33
34 if (!sdmode)
35 return 0;
36
34 switch (cmd) { 37 switch (cmd) {
35 case SNDRV_PCM_TRIGGER_START: 38 case SNDRV_PCM_TRIGGER_START:
36 case SNDRV_PCM_TRIGGER_RESUME: 39 case SNDRV_PCM_TRIGGER_RESUME:
@@ -48,24 +51,21 @@ static int max98357a_daiops_trigger(struct snd_pcm_substream *substream,
48} 51}
49 52
50static const struct snd_soc_dapm_widget max98357a_dapm_widgets[] = { 53static const struct snd_soc_dapm_widget max98357a_dapm_widgets[] = {
51 SND_SOC_DAPM_DAC("SDMode", NULL, SND_SOC_NOPM, 0, 0),
52 SND_SOC_DAPM_OUTPUT("Speaker"), 54 SND_SOC_DAPM_OUTPUT("Speaker"),
53}; 55};
54 56
55static const struct snd_soc_dapm_route max98357a_dapm_routes[] = { 57static const struct snd_soc_dapm_route max98357a_dapm_routes[] = {
56 {"Speaker", NULL, "SDMode"}, 58 {"Speaker", NULL, "HiFi Playback"},
57}; 59};
58 60
59static int max98357a_codec_probe(struct snd_soc_codec *codec) 61static int max98357a_codec_probe(struct snd_soc_codec *codec)
60{ 62{
61 struct gpio_desc *sdmode; 63 struct gpio_desc *sdmode;
62 64
63 sdmode = devm_gpiod_get(codec->dev, "sdmode", GPIOD_OUT_LOW); 65 sdmode = devm_gpiod_get_optional(codec->dev, "sdmode", GPIOD_OUT_LOW);
64 if (IS_ERR(sdmode)) { 66 if (IS_ERR(sdmode))
65 dev_err(codec->dev, "%s() unable to get sdmode GPIO: %ld\n",
66 __func__, PTR_ERR(sdmode));
67 return PTR_ERR(sdmode); 67 return PTR_ERR(sdmode);
68 } 68
69 snd_soc_codec_set_drvdata(codec, sdmode); 69 snd_soc_codec_set_drvdata(codec, sdmode);
70 70
71 return 0; 71 return 0;
@@ -79,7 +79,7 @@ static struct snd_soc_codec_driver max98357a_codec_driver = {
79 .num_dapm_routes = ARRAY_SIZE(max98357a_dapm_routes), 79 .num_dapm_routes = ARRAY_SIZE(max98357a_dapm_routes),
80}; 80};
81 81
82static struct snd_soc_dai_ops max98357a_dai_ops = { 82static const struct snd_soc_dai_ops max98357a_dai_ops = {
83 .trigger = max98357a_daiops_trigger, 83 .trigger = max98357a_daiops_trigger,
84}; 84};
85 85
@@ -104,15 +104,8 @@ static struct snd_soc_dai_driver max98357a_dai_driver = {
104 104
105static int max98357a_platform_probe(struct platform_device *pdev) 105static int max98357a_platform_probe(struct platform_device *pdev)
106{ 106{
107 int ret; 107 return snd_soc_register_codec(&pdev->dev, &max98357a_codec_driver,
108
109 ret = snd_soc_register_codec(&pdev->dev, &max98357a_codec_driver,
110 &max98357a_dai_driver, 1); 108 &max98357a_dai_driver, 1);
111 if (ret)
112 dev_err(&pdev->dev, "%s() error registering codec driver: %d\n",
113 __func__, ret);
114
115 return ret;
116} 109}
117 110
118static int max98357a_platform_remove(struct platform_device *pdev) 111static int max98357a_platform_remove(struct platform_device *pdev)
diff --git a/sound/soc/codecs/max9850.c b/sound/soc/codecs/max9850.c
index 481d58f1cb3f..7c990521638c 100644
--- a/sound/soc/codecs/max9850.c
+++ b/sound/soc/codecs/max9850.c
@@ -352,7 +352,6 @@ MODULE_DEVICE_TABLE(i2c, max9850_i2c_id);
352static struct i2c_driver max9850_i2c_driver = { 352static struct i2c_driver max9850_i2c_driver = {
353 .driver = { 353 .driver = {
354 .name = "max9850", 354 .name = "max9850",
355 .owner = THIS_MODULE,
356 }, 355 },
357 .probe = max9850_i2c_probe, 356 .probe = max9850_i2c_probe,
358 .remove = max9850_i2c_remove, 357 .remove = max9850_i2c_remove,
diff --git a/sound/soc/codecs/max9877.c b/sound/soc/codecs/max9877.c
index 29549cdbf4c1..fb448dde018d 100644
--- a/sound/soc/codecs/max9877.c
+++ b/sound/soc/codecs/max9877.c
@@ -20,9 +20,7 @@
20 20
21#include "max9877.h" 21#include "max9877.h"
22 22
23static struct regmap *regmap; 23static const struct reg_default max9877_regs[] = {
24
25static struct reg_default max9877_regs[] = {
26 { 0, 0x40 }, 24 { 0, 0x40 },
27 { 1, 0x00 }, 25 { 1, 0x00 },
28 { 2, 0x00 }, 26 { 2, 0x00 },
@@ -123,7 +121,7 @@ static const struct snd_soc_dapm_route max9877_dapm_routes[] = {
123 { "HPR", NULL, "SHDN" }, 121 { "HPR", NULL, "SHDN" },
124}; 122};
125 123
126static const struct snd_soc_codec_driver max9877_codec = { 124static const struct snd_soc_component_driver max9877_component_driver = {
127 .controls = max9877_controls, 125 .controls = max9877_controls,
128 .num_controls = ARRAY_SIZE(max9877_controls), 126 .num_controls = ARRAY_SIZE(max9877_controls),
129 127
@@ -145,6 +143,7 @@ static const struct regmap_config max9877_regmap = {
145static int max9877_i2c_probe(struct i2c_client *client, 143static int max9877_i2c_probe(struct i2c_client *client,
146 const struct i2c_device_id *id) 144 const struct i2c_device_id *id)
147{ 145{
146 struct regmap *regmap;
148 int i; 147 int i;
149 148
150 regmap = devm_regmap_init_i2c(client, &max9877_regmap); 149 regmap = devm_regmap_init_i2c(client, &max9877_regmap);
@@ -155,14 +154,8 @@ static int max9877_i2c_probe(struct i2c_client *client,
155 for (i = 0; i < ARRAY_SIZE(max9877_regs); i++) 154 for (i = 0; i < ARRAY_SIZE(max9877_regs); i++)
156 regmap_write(regmap, max9877_regs[i].reg, max9877_regs[i].def); 155 regmap_write(regmap, max9877_regs[i].reg, max9877_regs[i].def);
157 156
158 return snd_soc_register_codec(&client->dev, &max9877_codec, NULL, 0); 157 return devm_snd_soc_register_component(&client->dev,
159} 158 &max9877_component_driver, NULL, 0);
160
161static int max9877_i2c_remove(struct i2c_client *client)
162{
163 snd_soc_unregister_codec(&client->dev);
164
165 return 0;
166} 159}
167 160
168static const struct i2c_device_id max9877_i2c_id[] = { 161static const struct i2c_device_id max9877_i2c_id[] = {
@@ -174,10 +167,8 @@ MODULE_DEVICE_TABLE(i2c, max9877_i2c_id);
174static struct i2c_driver max9877_i2c_driver = { 167static struct i2c_driver max9877_i2c_driver = {
175 .driver = { 168 .driver = {
176 .name = "max9877", 169 .name = "max9877",
177 .owner = THIS_MODULE,
178 }, 170 },
179 .probe = max9877_i2c_probe, 171 .probe = max9877_i2c_probe,
180 .remove = max9877_i2c_remove,
181 .id_table = max9877_i2c_id, 172 .id_table = max9877_i2c_id,
182}; 173};
183 174
diff --git a/sound/soc/codecs/max98925.c b/sound/soc/codecs/max98925.c
index aad664225dc3..ebb648aea8c6 100644
--- a/sound/soc/codecs/max98925.c
+++ b/sound/soc/codecs/max98925.c
@@ -271,8 +271,6 @@ static inline int max98925_rate_value(struct snd_soc_codec *codec,
271 break; 271 break;
272 } 272 }
273 } 273 }
274 dev_dbg(codec->dev, "%s: sample rate is %d, returning %d\n",
275 __func__, rate_table[i].rate, *value);
276 return ret; 274 return ret;
277} 275}
278 276
@@ -523,7 +521,6 @@ static int max98925_probe(struct snd_soc_codec *codec)
523 struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec); 521 struct max98925_priv *max98925 = snd_soc_codec_get_drvdata(codec);
524 522
525 max98925->codec = codec; 523 max98925->codec = codec;
526 codec->control_data = max98925->regmap;
527 regmap_write(max98925->regmap, MAX98925_GLOBAL_ENABLE, 0x00); 524 regmap_write(max98925->regmap, MAX98925_GLOBAL_ENABLE, 0x00);
528 /* It's not the default but we need to set DAI_DLY */ 525 /* It's not the default but we need to set DAI_DLY */
529 regmap_write(max98925->regmap, 526 regmap_write(max98925->regmap,
@@ -639,7 +636,6 @@ MODULE_DEVICE_TABLE(of, max98925_of_match);
639static struct i2c_driver max98925_i2c_driver = { 636static struct i2c_driver max98925_i2c_driver = {
640 .driver = { 637 .driver = {
641 .name = "max98925", 638 .name = "max98925",
642 .owner = THIS_MODULE,
643 .of_match_table = of_match_ptr(max98925_of_match), 639 .of_match_table = of_match_ptr(max98925_of_match),
644 .pm = NULL, 640 .pm = NULL,
645 }, 641 },
diff --git a/sound/soc/codecs/mc13783.c b/sound/soc/codecs/mc13783.c
index 3d44fc50e4d0..3e770cbe7f0f 100644
--- a/sound/soc/codecs/mc13783.c
+++ b/sound/soc/codecs/mc13783.c
@@ -650,14 +650,14 @@ static int mc13783_remove(struct snd_soc_codec *codec)
650#define MC13783_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 650#define MC13783_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
651 SNDRV_PCM_FMTBIT_S24_LE) 651 SNDRV_PCM_FMTBIT_S24_LE)
652 652
653static struct snd_soc_dai_ops mc13783_ops_dac = { 653static const struct snd_soc_dai_ops mc13783_ops_dac = {
654 .hw_params = mc13783_pcm_hw_params_dac, 654 .hw_params = mc13783_pcm_hw_params_dac,
655 .set_fmt = mc13783_set_fmt_async, 655 .set_fmt = mc13783_set_fmt_async,
656 .set_sysclk = mc13783_set_sysclk_dac, 656 .set_sysclk = mc13783_set_sysclk_dac,
657 .set_tdm_slot = mc13783_set_tdm_slot_dac, 657 .set_tdm_slot = mc13783_set_tdm_slot_dac,
658}; 658};
659 659
660static struct snd_soc_dai_ops mc13783_ops_codec = { 660static const struct snd_soc_dai_ops mc13783_ops_codec = {
661 .hw_params = mc13783_pcm_hw_params_codec, 661 .hw_params = mc13783_pcm_hw_params_codec,
662 .set_fmt = mc13783_set_fmt_async, 662 .set_fmt = mc13783_set_fmt_async,
663 .set_sysclk = mc13783_set_sysclk_codec, 663 .set_sysclk = mc13783_set_sysclk_codec,
@@ -698,7 +698,7 @@ static struct snd_soc_dai_driver mc13783_dai_async[] = {
698 }, 698 },
699}; 699};
700 700
701static struct snd_soc_dai_ops mc13783_ops_sync = { 701static const struct snd_soc_dai_ops mc13783_ops_sync = {
702 .hw_params = mc13783_pcm_hw_params_sync, 702 .hw_params = mc13783_pcm_hw_params_sync,
703 .set_fmt = mc13783_set_fmt_sync, 703 .set_fmt = mc13783_set_fmt_sync,
704 .set_sysclk = mc13783_set_sysclk_sync, 704 .set_sysclk = mc13783_set_sysclk_sync,
diff --git a/sound/soc/codecs/ml26124.c b/sound/soc/codecs/ml26124.c
index b74118e019fb..f561c78b9e0e 100644
--- a/sound/soc/codecs/ml26124.c
+++ b/sound/soc/codecs/ml26124.c
@@ -199,7 +199,7 @@ static const struct clk_coeff coeff_div[] = {
199 {12288000, 48000, 0xc, 0x0, 0x30, 0x0, 0x4}, 199 {12288000, 48000, 0xc, 0x0, 0x30, 0x0, 0x4},
200}; 200};
201 201
202static struct reg_default ml26124_reg[] = { 202static const struct reg_default ml26124_reg[] = {
203 /* CLOCK control Register */ 203 /* CLOCK control Register */
204 {0x00, 0x00 }, /* Sampling Rate */ 204 {0x00, 0x00 }, /* Sampling Rate */
205 {0x02, 0x00}, /* PLL NL */ 205 {0x02, 0x00}, /* PLL NL */
@@ -597,7 +597,6 @@ MODULE_DEVICE_TABLE(i2c, ml26124_i2c_id);
597static struct i2c_driver ml26124_i2c_driver = { 597static struct i2c_driver ml26124_i2c_driver = {
598 .driver = { 598 .driver = {
599 .name = "ml26124", 599 .name = "ml26124",
600 .owner = THIS_MODULE,
601 }, 600 },
602 .probe = ml26124_i2c_probe, 601 .probe = ml26124_i2c_probe,
603 .remove = ml26124_i2c_remove, 602 .remove = ml26124_i2c_remove,
diff --git a/sound/soc/codecs/pcm1681.c b/sound/soc/codecs/pcm1681.c
index 477e13d30971..58325234285c 100644
--- a/sound/soc/codecs/pcm1681.c
+++ b/sound/soc/codecs/pcm1681.c
@@ -95,17 +95,22 @@ static int pcm1681_set_deemph(struct snd_soc_codec *codec)
95 struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec); 95 struct pcm1681_private *priv = snd_soc_codec_get_drvdata(codec);
96 int i = 0, val = -1, enable = 0; 96 int i = 0, val = -1, enable = 0;
97 97
98 if (priv->deemph) 98 if (priv->deemph) {
99 for (i = 0; i < ARRAY_SIZE(pcm1681_deemph); i++) 99 for (i = 0; i < ARRAY_SIZE(pcm1681_deemph); i++) {
100 if (pcm1681_deemph[i] == priv->rate) 100 if (pcm1681_deemph[i] == priv->rate) {
101 val = i; 101 val = i;
102 break;
103 }
104 }
105 }
102 106
103 if (val != -1) { 107 if (val != -1) {
104 regmap_update_bits(priv->regmap, PCM1681_DEEMPH_CONTROL, 108 regmap_update_bits(priv->regmap, PCM1681_DEEMPH_CONTROL,
105 PCM1681_DEEMPH_RATE_MASK, val); 109 PCM1681_DEEMPH_RATE_MASK, val << 3);
106 enable = 1; 110 enable = 1;
107 } else 111 } else {
108 enable = 0; 112 enable = 0;
113 }
109 114
110 /* enable/disable deemphasis functionality */ 115 /* enable/disable deemphasis functionality */
111 return regmap_update_bits(priv->regmap, PCM1681_DEEMPH_CONTROL, 116 return regmap_update_bits(priv->regmap, PCM1681_DEEMPH_CONTROL,
@@ -330,7 +335,6 @@ static int pcm1681_i2c_remove(struct i2c_client *client)
330static struct i2c_driver pcm1681_i2c_driver = { 335static struct i2c_driver pcm1681_i2c_driver = {
331 .driver = { 336 .driver = {
332 .name = "pcm1681", 337 .name = "pcm1681",
333 .owner = THIS_MODULE,
334 .of_match_table = of_match_ptr(pcm1681_dt_ids), 338 .of_match_table = of_match_ptr(pcm1681_dt_ids),
335 }, 339 },
336 .id_table = pcm1681_i2c_id, 340 .id_table = pcm1681_i2c_id,
diff --git a/sound/soc/codecs/pcm512x-i2c.c b/sound/soc/codecs/pcm512x-i2c.c
index dcdfac0ffeb1..dbff416e38be 100644
--- a/sound/soc/codecs/pcm512x-i2c.c
+++ b/sound/soc/codecs/pcm512x-i2c.c
@@ -67,7 +67,6 @@ static struct i2c_driver pcm512x_i2c_driver = {
67 .id_table = pcm512x_i2c_id, 67 .id_table = pcm512x_i2c_id,
68 .driver = { 68 .driver = {
69 .name = "pcm512x", 69 .name = "pcm512x",
70 .owner = THIS_MODULE,
71 .of_match_table = pcm512x_of_match, 70 .of_match_table = pcm512x_of_match,
72 .pm = &pcm512x_pm_ops, 71 .pm = &pcm512x_pm_ops,
73 }, 72 },
diff --git a/sound/soc/codecs/rl6231.c b/sound/soc/codecs/rl6231.c
index 56650d6c2f53..aca479fa7670 100644
--- a/sound/soc/codecs/rl6231.c
+++ b/sound/soc/codecs/rl6231.c
@@ -11,38 +11,98 @@
11 */ 11 */
12 12
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/regmap.h>
14 15
15#include "rl6231.h" 16#include "rl6231.h"
16 17
17/** 18/**
18 * rl6231_calc_dmic_clk - Calculate the parameter of dmic. 19 * rl6231_get_pre_div - Return the value of pre divider.
20 *
21 * @map: map for setting.
22 * @reg: register.
23 * @sft: shift.
24 *
25 * Return the value of pre divider from given register value.
26 * Return negative error code for unexpected register value.
27 */
28int rl6231_get_pre_div(struct regmap *map, unsigned int reg, int sft)
29{
30 int pd, val;
31
32 regmap_read(map, reg, &val);
33
34 val = (val >> sft) & 0x7;
35
36 switch (val) {
37 case 0:
38 case 1:
39 case 2:
40 case 3:
41 pd = val + 1;
42 break;
43 case 4:
44 pd = 6;
45 break;
46 case 5:
47 pd = 8;
48 break;
49 case 6:
50 pd = 12;
51 break;
52 case 7:
53 pd = 16;
54 break;
55 default:
56 pd = -EINVAL;
57 break;
58 }
59
60 return pd;
61}
62EXPORT_SYMBOL_GPL(rl6231_get_pre_div);
63
64/**
65 * rl6231_calc_dmic_clk - Calculate the frequency divider parameter of dmic.
19 * 66 *
20 * @rate: base clock rate. 67 * @rate: base clock rate.
21 * 68 *
22 * Choose dmic clock between 1MHz and 3MHz. 69 * Choose divider parameter that gives the highest possible DMIC frequency in
23 * It is better for clock to approximate 3MHz. 70 * 1MHz - 3MHz range.
24 */ 71 */
25int rl6231_calc_dmic_clk(int rate) 72int rl6231_calc_dmic_clk(int rate)
26{ 73{
27 int div[] = {2, 3, 4, 6, 8, 12}, idx = -EINVAL; 74 int div[] = {2, 3, 4, 6, 8, 12};
28 int i, red, bound, temp; 75 int i;
76
77 if (rate < 1000000 * div[0]) {
78 pr_warn("Base clock rate %d is too low\n", rate);
79 return -EINVAL;
80 }
29 81
30 red = 3000000 * 12;
31 for (i = 0; i < ARRAY_SIZE(div); i++) { 82 for (i = 0; i < ARRAY_SIZE(div); i++) {
32 bound = div[i] * 3000000; 83 /* find divider that gives DMIC frequency below 3MHz */
33 if (rate > bound) 84 if (3000000 * div[i] >= rate)
34 continue; 85 return i;
35 temp = bound - rate;
36 if (temp < red) {
37 red = temp;
38 idx = i;
39 }
40 } 86 }
41 87
42 return idx; 88 pr_warn("Base clock rate %d is too high\n", rate);
89 return -EINVAL;
43} 90}
44EXPORT_SYMBOL_GPL(rl6231_calc_dmic_clk); 91EXPORT_SYMBOL_GPL(rl6231_calc_dmic_clk);
45 92
93struct pll_calc_map {
94 unsigned int pll_in;
95 unsigned int pll_out;
96 int k;
97 int n;
98 int m;
99 bool m_bp;
100};
101
102static const struct pll_calc_map pll_preset_table[] = {
103 {19200000, 24576000, 3, 30, 3, false},
104};
105
46/** 106/**
47 * rl6231_pll_calc - Calcualte PLL M/N/K code. 107 * rl6231_pll_calc - Calcualte PLL M/N/K code.
48 * @freq_in: external clock provided to codec. 108 * @freq_in: external clock provided to codec.
@@ -57,7 +117,7 @@ int rl6231_pll_calc(const unsigned int freq_in,
57 const unsigned int freq_out, struct rl6231_pll_code *pll_code) 117 const unsigned int freq_out, struct rl6231_pll_code *pll_code)
58{ 118{
59 int max_n = RL6231_PLL_N_MAX, max_m = RL6231_PLL_M_MAX; 119 int max_n = RL6231_PLL_N_MAX, max_m = RL6231_PLL_M_MAX;
60 int k, red, n_t, pll_out, in_t, out_t; 120 int i, k, red, n_t, pll_out, in_t, out_t;
61 int n = 0, m = 0, m_t = 0; 121 int n = 0, m = 0, m_t = 0;
62 int red_t = abs(freq_out - freq_in); 122 int red_t = abs(freq_out - freq_in);
63 bool bypass = false; 123 bool bypass = false;
@@ -65,6 +125,18 @@ int rl6231_pll_calc(const unsigned int freq_in,
65 if (RL6231_PLL_INP_MAX < freq_in || RL6231_PLL_INP_MIN > freq_in) 125 if (RL6231_PLL_INP_MAX < freq_in || RL6231_PLL_INP_MIN > freq_in)
66 return -EINVAL; 126 return -EINVAL;
67 127
128 for (i = 0; i < ARRAY_SIZE(pll_preset_table); i++) {
129 if (freq_in == pll_preset_table[i].pll_in &&
130 freq_out == pll_preset_table[i].pll_out) {
131 k = pll_preset_table[i].k;
132 m = pll_preset_table[i].m;
133 n = pll_preset_table[i].n;
134 bypass = pll_preset_table[i].m_bp;
135 pr_debug("Use preset PLL parameter table\n");
136 goto code_find;
137 }
138 }
139
68 k = 100000000 / freq_out - 2; 140 k = 100000000 / freq_out - 2;
69 if (k > RL6231_PLL_K_MAX) 141 if (k > RL6231_PLL_K_MAX)
70 k = RL6231_PLL_K_MAX; 142 k = RL6231_PLL_K_MAX;
diff --git a/sound/soc/codecs/rl6231.h b/sound/soc/codecs/rl6231.h
index 0f7b057ed736..4c77b441fba2 100644
--- a/sound/soc/codecs/rl6231.h
+++ b/sound/soc/codecs/rl6231.h
@@ -30,5 +30,6 @@ int rl6231_calc_dmic_clk(int rate);
30int rl6231_pll_calc(const unsigned int freq_in, 30int rl6231_pll_calc(const unsigned int freq_in,
31 const unsigned int freq_out, struct rl6231_pll_code *pll_code); 31 const unsigned int freq_out, struct rl6231_pll_code *pll_code);
32int rl6231_get_clk_info(int sclk, int rate); 32int rl6231_get_clk_info(int sclk, int rate);
33int rl6231_get_pre_div(struct regmap *map, unsigned int reg, int sft);
33 34
34#endif /* __RL6231_H__ */ 35#endif /* __RL6231_H__ */
diff --git a/sound/soc/codecs/rt286.c b/sound/soc/codecs/rt286.c
index 5c43e263b2c1..bd9365885f73 100644
--- a/sound/soc/codecs/rt286.c
+++ b/sound/soc/codecs/rt286.c
@@ -38,7 +38,7 @@
38#define RT288_VENDOR_ID 0x10ec0288 38#define RT288_VENDOR_ID 0x10ec0288
39 39
40struct rt286_priv { 40struct rt286_priv {
41 struct reg_default *index_cache; 41 const struct reg_default *index_cache;
42 int index_cache_size; 42 int index_cache_size;
43 struct regmap *regmap; 43 struct regmap *regmap;
44 struct snd_soc_codec *codec; 44 struct snd_soc_codec *codec;
@@ -50,7 +50,7 @@ struct rt286_priv {
50 int clk_id; 50 int clk_id;
51}; 51};
52 52
53static struct reg_default rt286_index_def[] = { 53static const struct reg_default rt286_index_def[] = {
54 { 0x01, 0xaaaa }, 54 { 0x01, 0xaaaa },
55 { 0x02, 0x8aaa }, 55 { 0x02, 0x8aaa },
56 { 0x03, 0x0002 }, 56 { 0x03, 0x0002 },
@@ -1108,7 +1108,7 @@ static const struct acpi_device_id rt286_acpi_match[] = {
1108}; 1108};
1109MODULE_DEVICE_TABLE(acpi, rt286_acpi_match); 1109MODULE_DEVICE_TABLE(acpi, rt286_acpi_match);
1110 1110
1111static struct dmi_system_id force_combo_jack_table[] = { 1111static const struct dmi_system_id force_combo_jack_table[] = {
1112 { 1112 {
1113 .ident = "Intel Wilson Beach", 1113 .ident = "Intel Wilson Beach",
1114 .matches = { 1114 .matches = {
@@ -1118,7 +1118,7 @@ static struct dmi_system_id force_combo_jack_table[] = {
1118 { } 1118 { }
1119}; 1119};
1120 1120
1121static struct dmi_system_id dmi_dell_dino[] = { 1121static const struct dmi_system_id dmi_dell_dino[] = {
1122 { 1122 {
1123 .ident = "Dell Dino", 1123 .ident = "Dell Dino",
1124 .matches = { 1124 .matches = {
@@ -1157,7 +1157,7 @@ static int rt286_i2c_probe(struct i2c_client *i2c,
1157 } 1157 }
1158 if (val != RT286_VENDOR_ID && val != RT288_VENDOR_ID) { 1158 if (val != RT286_VENDOR_ID && val != RT288_VENDOR_ID) {
1159 dev_err(&i2c->dev, 1159 dev_err(&i2c->dev,
1160 "Device with ID register %x is not rt286\n", val); 1160 "Device with ID register %#x is not rt286\n", val);
1161 return -ENODEV; 1161 return -ENODEV;
1162 } 1162 }
1163 1163
@@ -1259,7 +1259,6 @@ static int rt286_i2c_remove(struct i2c_client *i2c)
1259static struct i2c_driver rt286_i2c_driver = { 1259static struct i2c_driver rt286_i2c_driver = {
1260 .driver = { 1260 .driver = {
1261 .name = "rt286", 1261 .name = "rt286",
1262 .owner = THIS_MODULE,
1263 .acpi_match_table = ACPI_PTR(rt286_acpi_match), 1262 .acpi_match_table = ACPI_PTR(rt286_acpi_match),
1264 }, 1263 },
1265 .probe = rt286_i2c_probe, 1264 .probe = rt286_i2c_probe,
diff --git a/sound/soc/codecs/rt298.c b/sound/soc/codecs/rt298.c
new file mode 100644
index 000000000000..3c2f0f8d6266
--- /dev/null
+++ b/sound/soc/codecs/rt298.c
@@ -0,0 +1,1271 @@
1/*
2 * rt298.c -- RT298 ALSA SoC audio codec driver
3 *
4 * Copyright 2015 Realtek Semiconductor Corp.
5 * Author: Bard Liao <bardliao@realtek.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/init.h>
15#include <linux/delay.h>
16#include <linux/pm.h>
17#include <linux/i2c.h>
18#include <linux/platform_device.h>
19#include <linux/spi/spi.h>
20#include <linux/acpi.h>
21#include <sound/core.h>
22#include <sound/pcm.h>
23#include <sound/pcm_params.h>
24#include <sound/soc.h>
25#include <sound/soc-dapm.h>
26#include <sound/initval.h>
27#include <sound/tlv.h>
28#include <sound/jack.h>
29#include <linux/workqueue.h>
30#include <sound/rt298.h>
31#include <sound/hda_verbs.h>
32
33#include "rl6347a.h"
34#include "rt298.h"
35
36#define RT298_VENDOR_ID 0x10ec0298
37
38struct rt298_priv {
39 struct reg_default *index_cache;
40 int index_cache_size;
41 struct regmap *regmap;
42 struct snd_soc_codec *codec;
43 struct rt298_platform_data pdata;
44 struct i2c_client *i2c;
45 struct snd_soc_jack *jack;
46 struct delayed_work jack_detect_work;
47 int sys_clk;
48 int clk_id;
49 int is_hp_in;
50};
51
52static struct reg_default rt298_index_def[] = {
53 { 0x01, 0xaaaa },
54 { 0x02, 0x8aaa },
55 { 0x03, 0x0002 },
56 { 0x04, 0xaf01 },
57 { 0x08, 0x000d },
58 { 0x09, 0xd810 },
59 { 0x0a, 0x0120 },
60 { 0x0b, 0x0000 },
61 { 0x0d, 0x2800 },
62 { 0x0f, 0x0000 },
63 { 0x19, 0x0a17 },
64 { 0x20, 0x0020 },
65 { 0x33, 0x0208 },
66 { 0x46, 0x0300 },
67 { 0x49, 0x0004 },
68 { 0x4f, 0x50e9 },
69 { 0x50, 0x2000 },
70 { 0x63, 0x2902 },
71 { 0x67, 0x1111 },
72 { 0x68, 0x1016 },
73 { 0x69, 0x273f },
74};
75#define INDEX_CACHE_SIZE ARRAY_SIZE(rt298_index_def)
76
77static const struct reg_default rt298_reg[] = {
78 { 0x00170500, 0x00000400 },
79 { 0x00220000, 0x00000031 },
80 { 0x00239000, 0x0000007f },
81 { 0x0023a000, 0x0000007f },
82 { 0x00270500, 0x00000400 },
83 { 0x00370500, 0x00000400 },
84 { 0x00870500, 0x00000400 },
85 { 0x00920000, 0x00000031 },
86 { 0x00935000, 0x000000c3 },
87 { 0x00936000, 0x000000c3 },
88 { 0x00970500, 0x00000400 },
89 { 0x00b37000, 0x00000097 },
90 { 0x00b37200, 0x00000097 },
91 { 0x00b37300, 0x00000097 },
92 { 0x00c37000, 0x00000000 },
93 { 0x00c37100, 0x00000080 },
94 { 0x01270500, 0x00000400 },
95 { 0x01370500, 0x00000400 },
96 { 0x01371f00, 0x411111f0 },
97 { 0x01439000, 0x00000080 },
98 { 0x0143a000, 0x00000080 },
99 { 0x01470700, 0x00000000 },
100 { 0x01470500, 0x00000400 },
101 { 0x01470c00, 0x00000000 },
102 { 0x01470100, 0x00000000 },
103 { 0x01837000, 0x00000000 },
104 { 0x01870500, 0x00000400 },
105 { 0x02050000, 0x00000000 },
106 { 0x02139000, 0x00000080 },
107 { 0x0213a000, 0x00000080 },
108 { 0x02170100, 0x00000000 },
109 { 0x02170500, 0x00000400 },
110 { 0x02170700, 0x00000000 },
111 { 0x02270100, 0x00000000 },
112 { 0x02370100, 0x00000000 },
113 { 0x01870700, 0x00000020 },
114 { 0x00830000, 0x000000c3 },
115 { 0x00930000, 0x000000c3 },
116 { 0x01270700, 0x00000000 },
117};
118
119static bool rt298_volatile_register(struct device *dev, unsigned int reg)
120{
121 switch (reg) {
122 case 0 ... 0xff:
123 case RT298_GET_PARAM(AC_NODE_ROOT, AC_PAR_VENDOR_ID):
124 case RT298_GET_HP_SENSE:
125 case RT298_GET_MIC1_SENSE:
126 case RT298_PROC_COEF:
127 case VERB_CMD(AC_VERB_GET_EAPD_BTLENABLE, RT298_MIC1, 0):
128 case VERB_CMD(AC_VERB_GET_EAPD_BTLENABLE, RT298_SPK_OUT, 0):
129 case VERB_CMD(AC_VERB_GET_EAPD_BTLENABLE, RT298_HP_OUT, 0):
130 return true;
131 default:
132 return true;
133 }
134
135
136}
137
138static bool rt298_readable_register(struct device *dev, unsigned int reg)
139{
140 switch (reg) {
141 case 0 ... 0xff:
142 case RT298_GET_PARAM(AC_NODE_ROOT, AC_PAR_VENDOR_ID):
143 case RT298_GET_HP_SENSE:
144 case RT298_GET_MIC1_SENSE:
145 case RT298_SET_AUDIO_POWER:
146 case RT298_SET_HPO_POWER:
147 case RT298_SET_SPK_POWER:
148 case RT298_SET_DMIC1_POWER:
149 case RT298_SPK_MUX:
150 case RT298_HPO_MUX:
151 case RT298_ADC0_MUX:
152 case RT298_ADC1_MUX:
153 case RT298_SET_MIC1:
154 case RT298_SET_PIN_HPO:
155 case RT298_SET_PIN_SPK:
156 case RT298_SET_PIN_DMIC1:
157 case RT298_SPK_EAPD:
158 case RT298_SET_AMP_GAIN_HPO:
159 case RT298_SET_DMIC2_DEFAULT:
160 case RT298_DACL_GAIN:
161 case RT298_DACR_GAIN:
162 case RT298_ADCL_GAIN:
163 case RT298_ADCR_GAIN:
164 case RT298_MIC_GAIN:
165 case RT298_SPOL_GAIN:
166 case RT298_SPOR_GAIN:
167 case RT298_HPOL_GAIN:
168 case RT298_HPOR_GAIN:
169 case RT298_F_DAC_SWITCH:
170 case RT298_F_RECMIX_SWITCH:
171 case RT298_REC_MIC_SWITCH:
172 case RT298_REC_I2S_SWITCH:
173 case RT298_REC_LINE_SWITCH:
174 case RT298_REC_BEEP_SWITCH:
175 case RT298_DAC_FORMAT:
176 case RT298_ADC_FORMAT:
177 case RT298_COEF_INDEX:
178 case RT298_PROC_COEF:
179 case RT298_SET_AMP_GAIN_ADC_IN1:
180 case RT298_SET_AMP_GAIN_ADC_IN2:
181 case RT298_SET_POWER(RT298_DAC_OUT1):
182 case RT298_SET_POWER(RT298_DAC_OUT2):
183 case RT298_SET_POWER(RT298_ADC_IN1):
184 case RT298_SET_POWER(RT298_ADC_IN2):
185 case RT298_SET_POWER(RT298_DMIC2):
186 case RT298_SET_POWER(RT298_MIC1):
187 case VERB_CMD(AC_VERB_GET_EAPD_BTLENABLE, RT298_MIC1, 0):
188 case VERB_CMD(AC_VERB_GET_EAPD_BTLENABLE, RT298_SPK_OUT, 0):
189 case VERB_CMD(AC_VERB_GET_EAPD_BTLENABLE, RT298_HP_OUT, 0):
190 return true;
191 default:
192 return false;
193 }
194}
195
196#ifdef CONFIG_PM
197static void rt298_index_sync(struct snd_soc_codec *codec)
198{
199 struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec);
200 int i;
201
202 for (i = 0; i < INDEX_CACHE_SIZE; i++) {
203 snd_soc_write(codec, rt298->index_cache[i].reg,
204 rt298->index_cache[i].def);
205 }
206}
207#endif
208
209static int rt298_support_power_controls[] = {
210 RT298_DAC_OUT1,
211 RT298_DAC_OUT2,
212 RT298_ADC_IN1,
213 RT298_ADC_IN2,
214 RT298_MIC1,
215 RT298_DMIC1,
216 RT298_DMIC2,
217 RT298_SPK_OUT,
218 RT298_HP_OUT,
219};
220#define RT298_POWER_REG_LEN ARRAY_SIZE(rt298_support_power_controls)
221
222static int rt298_jack_detect(struct rt298_priv *rt298, bool *hp, bool *mic)
223{
224 struct snd_soc_dapm_context *dapm;
225 unsigned int val, buf;
226
227 *hp = false;
228 *mic = false;
229
230 if (!rt298->codec)
231 return -EINVAL;
232
233 dapm = snd_soc_codec_get_dapm(rt298->codec);
234
235 if (rt298->pdata.cbj_en) {
236 regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf);
237 *hp = buf & 0x80000000;
238 if (*hp == rt298->is_hp_in)
239 return -1;
240 rt298->is_hp_in = *hp;
241 if (*hp) {
242 /* power on HV,VERF */
243 regmap_update_bits(rt298->regmap,
244 RT298_DC_GAIN, 0x200, 0x200);
245
246 snd_soc_dapm_force_enable_pin(dapm, "HV");
247 snd_soc_dapm_force_enable_pin(dapm, "VREF");
248 /* power LDO1 */
249 snd_soc_dapm_force_enable_pin(dapm, "LDO1");
250 snd_soc_dapm_sync(dapm);
251
252 regmap_write(rt298->regmap, RT298_SET_MIC1, 0x24);
253 msleep(50);
254
255 regmap_update_bits(rt298->regmap,
256 RT298_CBJ_CTRL1, 0xfcc0, 0xd400);
257 msleep(300);
258 regmap_read(rt298->regmap, RT298_CBJ_CTRL2, &val);
259
260 if (0x0070 == (val & 0x0070)) {
261 *mic = true;
262 } else {
263 regmap_update_bits(rt298->regmap,
264 RT298_CBJ_CTRL1, 0xfcc0, 0xe400);
265 msleep(300);
266 regmap_read(rt298->regmap,
267 RT298_CBJ_CTRL2, &val);
268 if (0x0070 == (val & 0x0070))
269 *mic = true;
270 else
271 *mic = false;
272 }
273 regmap_update_bits(rt298->regmap,
274 RT298_DC_GAIN, 0x200, 0x0);
275
276 } else {
277 *mic = false;
278 regmap_write(rt298->regmap, RT298_SET_MIC1, 0x20);
279 }
280 } else {
281 regmap_read(rt298->regmap, RT298_GET_HP_SENSE, &buf);
282 *hp = buf & 0x80000000;
283 regmap_read(rt298->regmap, RT298_GET_MIC1_SENSE, &buf);
284 *mic = buf & 0x80000000;
285 }
286
287 snd_soc_dapm_disable_pin(dapm, "HV");
288 snd_soc_dapm_disable_pin(dapm, "VREF");
289 if (!*hp)
290 snd_soc_dapm_disable_pin(dapm, "LDO1");
291 snd_soc_dapm_sync(dapm);
292
293 pr_debug("*hp = %d *mic = %d\n", *hp, *mic);
294
295 return 0;
296}
297
298static void rt298_jack_detect_work(struct work_struct *work)
299{
300 struct rt298_priv *rt298 =
301 container_of(work, struct rt298_priv, jack_detect_work.work);
302 int status = 0;
303 bool hp = false;
304 bool mic = false;
305
306 if (rt298_jack_detect(rt298, &hp, &mic) < 0)
307 return;
308
309 if (hp == true)
310 status |= SND_JACK_HEADPHONE;
311
312 if (mic == true)
313 status |= SND_JACK_MICROPHONE;
314
315 snd_soc_jack_report(rt298->jack, status,
316 SND_JACK_MICROPHONE | SND_JACK_HEADPHONE);
317}
318
319int rt298_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
320{
321 struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec);
322
323 rt298->jack = jack;
324
325 /* Send an initial empty report */
326 snd_soc_jack_report(rt298->jack, 0,
327 SND_JACK_MICROPHONE | SND_JACK_HEADPHONE);
328
329 return 0;
330}
331EXPORT_SYMBOL_GPL(rt298_mic_detect);
332
333static int is_mclk_mode(struct snd_soc_dapm_widget *source,
334 struct snd_soc_dapm_widget *sink)
335{
336 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
337 struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec);
338
339 if (rt298->clk_id == RT298_SCLK_S_MCLK)
340 return 1;
341 else
342 return 0;
343}
344
345static const DECLARE_TLV_DB_SCALE(out_vol_tlv, -6350, 50, 0);
346static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, 0, 1000, 0);
347
348static const struct snd_kcontrol_new rt298_snd_controls[] = {
349 SOC_DOUBLE_R_TLV("DAC0 Playback Volume", RT298_DACL_GAIN,
350 RT298_DACR_GAIN, 0, 0x7f, 0, out_vol_tlv),
351 SOC_DOUBLE_R_TLV("ADC0 Capture Volume", RT298_ADCL_GAIN,
352 RT298_ADCR_GAIN, 0, 0x7f, 0, out_vol_tlv),
353 SOC_SINGLE_TLV("AMIC Volume", RT298_MIC_GAIN,
354 0, 0x3, 0, mic_vol_tlv),
355 SOC_DOUBLE_R("Speaker Playback Switch", RT298_SPOL_GAIN,
356 RT298_SPOR_GAIN, RT298_MUTE_SFT, 1, 1),
357};
358
359/* Digital Mixer */
360static const struct snd_kcontrol_new rt298_front_mix[] = {
361 SOC_DAPM_SINGLE("DAC Switch", RT298_F_DAC_SWITCH,
362 RT298_MUTE_SFT, 1, 1),
363 SOC_DAPM_SINGLE("RECMIX Switch", RT298_F_RECMIX_SWITCH,
364 RT298_MUTE_SFT, 1, 1),
365};
366
367/* Analog Input Mixer */
368static const struct snd_kcontrol_new rt298_rec_mix[] = {
369 SOC_DAPM_SINGLE("Mic1 Switch", RT298_REC_MIC_SWITCH,
370 RT298_MUTE_SFT, 1, 1),
371 SOC_DAPM_SINGLE("I2S Switch", RT298_REC_I2S_SWITCH,
372 RT298_MUTE_SFT, 1, 1),
373 SOC_DAPM_SINGLE("Line1 Switch", RT298_REC_LINE_SWITCH,
374 RT298_MUTE_SFT, 1, 1),
375 SOC_DAPM_SINGLE("Beep Switch", RT298_REC_BEEP_SWITCH,
376 RT298_MUTE_SFT, 1, 1),
377};
378
379static const struct snd_kcontrol_new spo_enable_control =
380 SOC_DAPM_SINGLE("Switch", RT298_SET_PIN_SPK,
381 RT298_SET_PIN_SFT, 1, 0);
382
383static const struct snd_kcontrol_new hpol_enable_control =
384 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT298_HPOL_GAIN,
385 RT298_MUTE_SFT, 1, 1);
386
387static const struct snd_kcontrol_new hpor_enable_control =
388 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT298_HPOR_GAIN,
389 RT298_MUTE_SFT, 1, 1);
390
391/* ADC0 source */
392static const char * const rt298_adc_src[] = {
393 "Mic", "RECMIX", "Dmic"
394};
395
396static const int rt298_adc_values[] = {
397 0, 4, 5,
398};
399
400static SOC_VALUE_ENUM_SINGLE_DECL(
401 rt298_adc0_enum, RT298_ADC0_MUX, RT298_ADC_SEL_SFT,
402 RT298_ADC_SEL_MASK, rt298_adc_src, rt298_adc_values);
403
404static const struct snd_kcontrol_new rt298_adc0_mux =
405 SOC_DAPM_ENUM("ADC 0 source", rt298_adc0_enum);
406
407static SOC_VALUE_ENUM_SINGLE_DECL(
408 rt298_adc1_enum, RT298_ADC1_MUX, RT298_ADC_SEL_SFT,
409 RT298_ADC_SEL_MASK, rt298_adc_src, rt298_adc_values);
410
411static const struct snd_kcontrol_new rt298_adc1_mux =
412 SOC_DAPM_ENUM("ADC 1 source", rt298_adc1_enum);
413
414static const char * const rt298_dac_src[] = {
415 "Front", "Surround"
416};
417/* HP-OUT source */
418static SOC_ENUM_SINGLE_DECL(rt298_hpo_enum, RT298_HPO_MUX,
419 0, rt298_dac_src);
420
421static const struct snd_kcontrol_new rt298_hpo_mux =
422SOC_DAPM_ENUM("HPO source", rt298_hpo_enum);
423
424/* SPK-OUT source */
425static SOC_ENUM_SINGLE_DECL(rt298_spo_enum, RT298_SPK_MUX,
426 0, rt298_dac_src);
427
428static const struct snd_kcontrol_new rt298_spo_mux =
429SOC_DAPM_ENUM("SPO source", rt298_spo_enum);
430
431static int rt298_spk_event(struct snd_soc_dapm_widget *w,
432 struct snd_kcontrol *kcontrol, int event)
433{
434 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
435
436 switch (event) {
437 case SND_SOC_DAPM_POST_PMU:
438 snd_soc_write(codec,
439 RT298_SPK_EAPD, RT298_SET_EAPD_HIGH);
440 break;
441 case SND_SOC_DAPM_PRE_PMD:
442 snd_soc_write(codec,
443 RT298_SPK_EAPD, RT298_SET_EAPD_LOW);
444 break;
445
446 default:
447 return 0;
448 }
449
450 return 0;
451}
452
453static int rt298_set_dmic1_event(struct snd_soc_dapm_widget *w,
454 struct snd_kcontrol *kcontrol, int event)
455{
456 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
457
458 switch (event) {
459 case SND_SOC_DAPM_POST_PMU:
460 snd_soc_write(codec, RT298_SET_PIN_DMIC1, 0x20);
461 break;
462 case SND_SOC_DAPM_PRE_PMD:
463 snd_soc_write(codec, RT298_SET_PIN_DMIC1, 0);
464 break;
465 default:
466 return 0;
467 }
468
469 return 0;
470}
471
472static int rt298_adc_event(struct snd_soc_dapm_widget *w,
473 struct snd_kcontrol *kcontrol, int event)
474{
475 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
476 unsigned int nid;
477
478 nid = (w->reg >> 20) & 0xff;
479
480 switch (event) {
481 case SND_SOC_DAPM_POST_PMU:
482 snd_soc_update_bits(codec,
483 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, nid, 0),
484 0x7080, 0x7000);
485 break;
486 case SND_SOC_DAPM_PRE_PMD:
487 snd_soc_update_bits(codec,
488 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, nid, 0),
489 0x7080, 0x7080);
490 break;
491 default:
492 return 0;
493 }
494
495 return 0;
496}
497
498static int rt298_mic1_event(struct snd_soc_dapm_widget *w,
499 struct snd_kcontrol *kcontrol, int event)
500{
501 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
502
503 switch (event) {
504 case SND_SOC_DAPM_PRE_PMU:
505 snd_soc_update_bits(codec,
506 RT298_A_BIAS_CTRL3, 0xc000, 0x8000);
507 snd_soc_update_bits(codec,
508 RT298_A_BIAS_CTRL2, 0xc000, 0x8000);
509 break;
510 case SND_SOC_DAPM_POST_PMD:
511 snd_soc_update_bits(codec,
512 RT298_A_BIAS_CTRL3, 0xc000, 0x0000);
513 snd_soc_update_bits(codec,
514 RT298_A_BIAS_CTRL2, 0xc000, 0x0000);
515 break;
516 default:
517 return 0;
518 }
519
520 return 0;
521}
522
523static int rt298_vref_event(struct snd_soc_dapm_widget *w,
524 struct snd_kcontrol *kcontrol, int event)
525{
526 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
527
528 switch (event) {
529 case SND_SOC_DAPM_PRE_PMU:
530 snd_soc_update_bits(codec,
531 RT298_CBJ_CTRL1, 0x0400, 0x0000);
532 mdelay(50);
533 break;
534 default:
535 return 0;
536 }
537
538 return 0;
539}
540
541static const struct snd_soc_dapm_widget rt298_dapm_widgets[] = {
542
543 SND_SOC_DAPM_SUPPLY_S("HV", 1, RT298_POWER_CTRL1,
544 12, 1, NULL, 0),
545 SND_SOC_DAPM_SUPPLY("VREF", RT298_POWER_CTRL1,
546 0, 1, rt298_vref_event, SND_SOC_DAPM_PRE_PMU),
547 SND_SOC_DAPM_SUPPLY_S("BG_MBIAS", 1, RT298_POWER_CTRL2,
548 1, 0, NULL, 0),
549 SND_SOC_DAPM_SUPPLY_S("LDO1", 1, RT298_POWER_CTRL2,
550 2, 0, NULL, 0),
551 SND_SOC_DAPM_SUPPLY_S("LDO2", 1, RT298_POWER_CTRL2,
552 3, 0, NULL, 0),
553 SND_SOC_DAPM_SUPPLY_S("VREF1", 1, RT298_POWER_CTRL2,
554 4, 1, NULL, 0),
555 SND_SOC_DAPM_SUPPLY_S("LV", 2, RT298_POWER_CTRL1,
556 13, 1, NULL, 0),
557
558
559 SND_SOC_DAPM_SUPPLY("MCLK MODE", RT298_PLL_CTRL1,
560 5, 0, NULL, 0),
561 SND_SOC_DAPM_SUPPLY("MIC1 Input Buffer", SND_SOC_NOPM,
562 0, 0, rt298_mic1_event, SND_SOC_DAPM_PRE_PMU |
563 SND_SOC_DAPM_POST_PMD),
564
565 /* Input Lines */
566 SND_SOC_DAPM_INPUT("DMIC1 Pin"),
567 SND_SOC_DAPM_INPUT("DMIC2 Pin"),
568 SND_SOC_DAPM_INPUT("MIC1"),
569 SND_SOC_DAPM_INPUT("LINE1"),
570 SND_SOC_DAPM_INPUT("Beep"),
571
572 /* DMIC */
573 SND_SOC_DAPM_PGA_E("DMIC1", RT298_SET_POWER(RT298_DMIC1), 0, 1,
574 NULL, 0, rt298_set_dmic1_event,
575 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
576 SND_SOC_DAPM_PGA("DMIC2", RT298_SET_POWER(RT298_DMIC2), 0, 1,
577 NULL, 0),
578 SND_SOC_DAPM_SUPPLY("DMIC Receiver", SND_SOC_NOPM,
579 0, 0, NULL, 0),
580
581 /* REC Mixer */
582 SND_SOC_DAPM_MIXER("RECMIX", SND_SOC_NOPM, 0, 0,
583 rt298_rec_mix, ARRAY_SIZE(rt298_rec_mix)),
584
585 /* ADCs */
586 SND_SOC_DAPM_ADC("ADC 0", NULL, SND_SOC_NOPM, 0, 0),
587 SND_SOC_DAPM_ADC("ADC 1", NULL, SND_SOC_NOPM, 0, 0),
588
589 /* ADC Mux */
590 SND_SOC_DAPM_MUX_E("ADC 0 Mux", RT298_SET_POWER(RT298_ADC_IN1), 0, 1,
591 &rt298_adc0_mux, rt298_adc_event, SND_SOC_DAPM_PRE_PMD |
592 SND_SOC_DAPM_POST_PMU),
593 SND_SOC_DAPM_MUX_E("ADC 1 Mux", RT298_SET_POWER(RT298_ADC_IN2), 0, 1,
594 &rt298_adc1_mux, rt298_adc_event, SND_SOC_DAPM_PRE_PMD |
595 SND_SOC_DAPM_POST_PMU),
596
597 /* Audio Interface */
598 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
599 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM, 0, 0),
600 SND_SOC_DAPM_AIF_IN("AIF2RX", "AIF2 Playback", 0, SND_SOC_NOPM, 0, 0),
601 SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0, SND_SOC_NOPM, 0, 0),
602
603 /* Output Side */
604 /* DACs */
605 SND_SOC_DAPM_DAC("DAC 0", NULL, SND_SOC_NOPM, 0, 0),
606 SND_SOC_DAPM_DAC("DAC 1", NULL, SND_SOC_NOPM, 0, 0),
607
608 /* Output Mux */
609 SND_SOC_DAPM_MUX("SPK Mux", SND_SOC_NOPM, 0, 0, &rt298_spo_mux),
610 SND_SOC_DAPM_MUX("HPO Mux", SND_SOC_NOPM, 0, 0, &rt298_hpo_mux),
611
612 SND_SOC_DAPM_SUPPLY("HP Power", RT298_SET_PIN_HPO,
613 RT298_SET_PIN_SFT, 0, NULL, 0),
614
615 /* Output Mixer */
616 SND_SOC_DAPM_MIXER("Front", RT298_SET_POWER(RT298_DAC_OUT1), 0, 1,
617 rt298_front_mix, ARRAY_SIZE(rt298_front_mix)),
618 SND_SOC_DAPM_PGA("Surround", RT298_SET_POWER(RT298_DAC_OUT2), 0, 1,
619 NULL, 0),
620
621 /* Output Pga */
622 SND_SOC_DAPM_SWITCH_E("SPO", SND_SOC_NOPM, 0, 0,
623 &spo_enable_control, rt298_spk_event,
624 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
625 SND_SOC_DAPM_SWITCH("HPO L", SND_SOC_NOPM, 0, 0,
626 &hpol_enable_control),
627 SND_SOC_DAPM_SWITCH("HPO R", SND_SOC_NOPM, 0, 0,
628 &hpor_enable_control),
629
630 /* Output Lines */
631 SND_SOC_DAPM_OUTPUT("SPOL"),
632 SND_SOC_DAPM_OUTPUT("SPOR"),
633 SND_SOC_DAPM_OUTPUT("HPO Pin"),
634 SND_SOC_DAPM_OUTPUT("SPDIF"),
635};
636
637static const struct snd_soc_dapm_route rt298_dapm_routes[] = {
638
639 {"ADC 0", NULL, "MCLK MODE", is_mclk_mode},
640 {"ADC 1", NULL, "MCLK MODE", is_mclk_mode},
641 {"Front", NULL, "MCLK MODE", is_mclk_mode},
642 {"Surround", NULL, "MCLK MODE", is_mclk_mode},
643
644 {"HP Power", NULL, "LDO1"},
645 {"HP Power", NULL, "LDO2"},
646 {"HP Power", NULL, "LV"},
647 {"HP Power", NULL, "VREF1"},
648 {"HP Power", NULL, "BG_MBIAS"},
649
650 {"MIC1", NULL, "LDO1"},
651 {"MIC1", NULL, "LDO2"},
652 {"MIC1", NULL, "HV"},
653 {"MIC1", NULL, "LV"},
654 {"MIC1", NULL, "VREF"},
655 {"MIC1", NULL, "VREF1"},
656 {"MIC1", NULL, "BG_MBIAS"},
657 {"MIC1", NULL, "MIC1 Input Buffer"},
658
659 {"SPO", NULL, "LDO1"},
660 {"SPO", NULL, "LDO2"},
661 {"SPO", NULL, "HV"},
662 {"SPO", NULL, "LV"},
663 {"SPO", NULL, "VREF"},
664 {"SPO", NULL, "VREF1"},
665 {"SPO", NULL, "BG_MBIAS"},
666
667 {"DMIC1", NULL, "DMIC1 Pin"},
668 {"DMIC2", NULL, "DMIC2 Pin"},
669 {"DMIC1", NULL, "DMIC Receiver"},
670 {"DMIC2", NULL, "DMIC Receiver"},
671
672 {"RECMIX", "Beep Switch", "Beep"},
673 {"RECMIX", "Line1 Switch", "LINE1"},
674 {"RECMIX", "Mic1 Switch", "MIC1"},
675
676 {"ADC 0 Mux", "Dmic", "DMIC1"},
677 {"ADC 0 Mux", "RECMIX", "RECMIX"},
678 {"ADC 0 Mux", "Mic", "MIC1"},
679 {"ADC 1 Mux", "Dmic", "DMIC2"},
680 {"ADC 1 Mux", "RECMIX", "RECMIX"},
681 {"ADC 1 Mux", "Mic", "MIC1"},
682
683 {"ADC 0", NULL, "ADC 0 Mux"},
684 {"ADC 1", NULL, "ADC 1 Mux"},
685
686 {"AIF1TX", NULL, "ADC 0"},
687 {"AIF2TX", NULL, "ADC 1"},
688
689 {"DAC 0", NULL, "AIF1RX"},
690 {"DAC 1", NULL, "AIF2RX"},
691
692 {"Front", "DAC Switch", "DAC 0"},
693 {"Front", "RECMIX Switch", "RECMIX"},
694
695 {"Surround", NULL, "DAC 1"},
696
697 {"SPK Mux", "Front", "Front"},
698 {"SPK Mux", "Surround", "Surround"},
699
700 {"HPO Mux", "Front", "Front"},
701 {"HPO Mux", "Surround", "Surround"},
702
703 {"SPO", "Switch", "SPK Mux"},
704 {"HPO L", "Switch", "HPO Mux"},
705 {"HPO R", "Switch", "HPO Mux"},
706 {"HPO L", NULL, "HP Power"},
707 {"HPO R", NULL, "HP Power"},
708
709 {"SPOL", NULL, "SPO"},
710 {"SPOR", NULL, "SPO"},
711 {"HPO Pin", NULL, "HPO L"},
712 {"HPO Pin", NULL, "HPO R"},
713};
714
715static int rt298_hw_params(struct snd_pcm_substream *substream,
716 struct snd_pcm_hw_params *params,
717 struct snd_soc_dai *dai)
718{
719 struct snd_soc_codec *codec = dai->codec;
720 struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec);
721 unsigned int val = 0;
722 int d_len_code;
723
724 switch (params_rate(params)) {
725 /* bit 14 0:48K 1:44.1K */
726 case 44100:
727 case 48000:
728 break;
729 default:
730 dev_err(codec->dev, "Unsupported sample rate %d\n",
731 params_rate(params));
732 return -EINVAL;
733 }
734 switch (rt298->sys_clk) {
735 case 12288000:
736 case 24576000:
737 if (params_rate(params) != 48000) {
738 dev_err(codec->dev, "Sys_clk is not matched (%d %d)\n",
739 params_rate(params), rt298->sys_clk);
740 return -EINVAL;
741 }
742 break;
743 case 11289600:
744 case 22579200:
745 if (params_rate(params) != 44100) {
746 dev_err(codec->dev, "Sys_clk is not matched (%d %d)\n",
747 params_rate(params), rt298->sys_clk);
748 return -EINVAL;
749 }
750 break;
751 }
752
753 if (params_channels(params) <= 16) {
754 /* bit 3:0 Number of Channel */
755 val |= (params_channels(params) - 1);
756 } else {
757 dev_err(codec->dev, "Unsupported channels %d\n",
758 params_channels(params));
759 return -EINVAL;
760 }
761
762 d_len_code = 0;
763 switch (params_width(params)) {
764 /* bit 6:4 Bits per Sample */
765 case 16:
766 d_len_code = 0;
767 val |= (0x1 << 4);
768 break;
769 case 32:
770 d_len_code = 2;
771 val |= (0x4 << 4);
772 break;
773 case 20:
774 d_len_code = 1;
775 val |= (0x2 << 4);
776 break;
777 case 24:
778 d_len_code = 2;
779 val |= (0x3 << 4);
780 break;
781 case 8:
782 d_len_code = 3;
783 break;
784 default:
785 return -EINVAL;
786 }
787
788 snd_soc_update_bits(codec,
789 RT298_I2S_CTRL1, 0x0018, d_len_code << 3);
790 dev_dbg(codec->dev, "format val = 0x%x\n", val);
791
792 snd_soc_update_bits(codec, RT298_DAC_FORMAT, 0x407f, val);
793 snd_soc_update_bits(codec, RT298_ADC_FORMAT, 0x407f, val);
794
795 return 0;
796}
797
798static int rt298_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
799{
800 struct snd_soc_codec *codec = dai->codec;
801
802 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
803 case SND_SOC_DAIFMT_CBM_CFM:
804 snd_soc_update_bits(codec,
805 RT298_I2S_CTRL1, 0x800, 0x800);
806 break;
807 case SND_SOC_DAIFMT_CBS_CFS:
808 snd_soc_update_bits(codec,
809 RT298_I2S_CTRL1, 0x800, 0x0);
810 break;
811 default:
812 return -EINVAL;
813 }
814
815 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
816 case SND_SOC_DAIFMT_I2S:
817 snd_soc_update_bits(codec,
818 RT298_I2S_CTRL1, 0x300, 0x0);
819 break;
820 case SND_SOC_DAIFMT_LEFT_J:
821 snd_soc_update_bits(codec,
822 RT298_I2S_CTRL1, 0x300, 0x1 << 8);
823 break;
824 case SND_SOC_DAIFMT_DSP_A:
825 snd_soc_update_bits(codec,
826 RT298_I2S_CTRL1, 0x300, 0x2 << 8);
827 break;
828 case SND_SOC_DAIFMT_DSP_B:
829 snd_soc_update_bits(codec,
830 RT298_I2S_CTRL1, 0x300, 0x3 << 8);
831 break;
832 default:
833 return -EINVAL;
834 }
835 /* bit 15 Stream Type 0:PCM 1:Non-PCM */
836 snd_soc_update_bits(codec, RT298_DAC_FORMAT, 0x8000, 0);
837 snd_soc_update_bits(codec, RT298_ADC_FORMAT, 0x8000, 0);
838
839 return 0;
840}
841
842static int rt298_set_dai_sysclk(struct snd_soc_dai *dai,
843 int clk_id, unsigned int freq, int dir)
844{
845 struct snd_soc_codec *codec = dai->codec;
846 struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec);
847
848 dev_dbg(codec->dev, "%s freq=%d\n", __func__, freq);
849
850 if (RT298_SCLK_S_MCLK == clk_id) {
851 snd_soc_update_bits(codec,
852 RT298_I2S_CTRL2, 0x0100, 0x0);
853 snd_soc_update_bits(codec,
854 RT298_PLL_CTRL1, 0x20, 0x20);
855 } else {
856 snd_soc_update_bits(codec,
857 RT298_I2S_CTRL2, 0x0100, 0x0100);
858 snd_soc_update_bits(codec,
859 RT298_PLL_CTRL, 0x4, 0x4);
860 snd_soc_update_bits(codec,
861 RT298_PLL_CTRL1, 0x20, 0x0);
862 }
863
864 switch (freq) {
865 case 19200000:
866 if (RT298_SCLK_S_MCLK == clk_id) {
867 dev_err(codec->dev, "Should not use MCLK\n");
868 return -EINVAL;
869 }
870 snd_soc_update_bits(codec,
871 RT298_I2S_CTRL2, 0x40, 0x40);
872 break;
873 case 24000000:
874 if (RT298_SCLK_S_MCLK == clk_id) {
875 dev_err(codec->dev, "Should not use MCLK\n");
876 return -EINVAL;
877 }
878 snd_soc_update_bits(codec,
879 RT298_I2S_CTRL2, 0x40, 0x0);
880 break;
881 case 12288000:
882 case 11289600:
883 snd_soc_update_bits(codec,
884 RT298_I2S_CTRL2, 0x8, 0x0);
885 snd_soc_update_bits(codec,
886 RT298_CLK_DIV, 0xfc1e, 0x0004);
887 break;
888 case 24576000:
889 case 22579200:
890 snd_soc_update_bits(codec,
891 RT298_I2S_CTRL2, 0x8, 0x8);
892 snd_soc_update_bits(codec,
893 RT298_CLK_DIV, 0xfc1e, 0x5406);
894 break;
895 default:
896 dev_err(codec->dev, "Unsupported system clock\n");
897 return -EINVAL;
898 }
899
900 rt298->sys_clk = freq;
901 rt298->clk_id = clk_id;
902
903 return 0;
904}
905
906static int rt298_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
907{
908 struct snd_soc_codec *codec = dai->codec;
909
910 dev_dbg(codec->dev, "%s ratio=%d\n", __func__, ratio);
911 if (50 == ratio)
912 snd_soc_update_bits(codec,
913 RT298_I2S_CTRL1, 0x1000, 0x1000);
914 else
915 snd_soc_update_bits(codec,
916 RT298_I2S_CTRL1, 0x1000, 0x0);
917
918
919 return 0;
920}
921
922static int rt298_set_bias_level(struct snd_soc_codec *codec,
923 enum snd_soc_bias_level level)
924{
925 switch (level) {
926 case SND_SOC_BIAS_PREPARE:
927 if (SND_SOC_BIAS_STANDBY ==
928 snd_soc_codec_get_bias_level(codec)) {
929 snd_soc_write(codec,
930 RT298_SET_AUDIO_POWER, AC_PWRST_D0);
931 snd_soc_update_bits(codec, 0x0d, 0x200, 0x200);
932 snd_soc_update_bits(codec, 0x52, 0x80, 0x0);
933 mdelay(20);
934 snd_soc_update_bits(codec, 0x0d, 0x200, 0x0);
935 snd_soc_update_bits(codec, 0x52, 0x80, 0x80);
936 }
937 break;
938
939 case SND_SOC_BIAS_ON:
940 mdelay(30);
941 snd_soc_update_bits(codec,
942 RT298_CBJ_CTRL1, 0x0400, 0x0400);
943
944 break;
945
946 case SND_SOC_BIAS_STANDBY:
947 snd_soc_write(codec,
948 RT298_SET_AUDIO_POWER, AC_PWRST_D3);
949 snd_soc_update_bits(codec,
950 RT298_CBJ_CTRL1, 0x0400, 0x0000);
951 break;
952
953 default:
954 break;
955 }
956
957 return 0;
958}
959
960static irqreturn_t rt298_irq(int irq, void *data)
961{
962 struct rt298_priv *rt298 = data;
963 bool hp = false;
964 bool mic = false;
965 int ret, status = 0;
966
967 ret = rt298_jack_detect(rt298, &hp, &mic);
968
969 /* Clear IRQ */
970 regmap_update_bits(rt298->regmap, RT298_IRQ_CTRL, 0x1, 0x1);
971
972 if (ret == 0) {
973 if (hp == true)
974 status |= SND_JACK_HEADPHONE;
975
976 if (mic == true)
977 status |= SND_JACK_MICROPHONE;
978
979 snd_soc_jack_report(rt298->jack, status,
980 SND_JACK_MICROPHONE | SND_JACK_HEADPHONE);
981
982 pm_wakeup_event(&rt298->i2c->dev, 300);
983 }
984
985 return IRQ_HANDLED;
986}
987
988static int rt298_probe(struct snd_soc_codec *codec)
989{
990 struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec);
991
992 rt298->codec = codec;
993
994 if (rt298->i2c->irq) {
995 regmap_update_bits(rt298->regmap,
996 RT298_IRQ_CTRL, 0x2, 0x2);
997
998 INIT_DELAYED_WORK(&rt298->jack_detect_work,
999 rt298_jack_detect_work);
1000 schedule_delayed_work(&rt298->jack_detect_work,
1001 msecs_to_jiffies(1250));
1002 }
1003
1004 return 0;
1005}
1006
1007static int rt298_remove(struct snd_soc_codec *codec)
1008{
1009 struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec);
1010
1011 cancel_delayed_work_sync(&rt298->jack_detect_work);
1012
1013 return 0;
1014}
1015
1016#ifdef CONFIG_PM
1017static int rt298_suspend(struct snd_soc_codec *codec)
1018{
1019 struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec);
1020
1021 rt298->is_hp_in = -1;
1022 regcache_cache_only(rt298->regmap, true);
1023 regcache_mark_dirty(rt298->regmap);
1024
1025 return 0;
1026}
1027
1028static int rt298_resume(struct snd_soc_codec *codec)
1029{
1030 struct rt298_priv *rt298 = snd_soc_codec_get_drvdata(codec);
1031
1032 regcache_cache_only(rt298->regmap, false);
1033 rt298_index_sync(codec);
1034 regcache_sync(rt298->regmap);
1035
1036 return 0;
1037}
1038#else
1039#define rt298_suspend NULL
1040#define rt298_resume NULL
1041#endif
1042
1043#define RT298_STEREO_RATES (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
1044#define RT298_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1045 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
1046
1047static const struct snd_soc_dai_ops rt298_aif_dai_ops = {
1048 .hw_params = rt298_hw_params,
1049 .set_fmt = rt298_set_dai_fmt,
1050 .set_sysclk = rt298_set_dai_sysclk,
1051 .set_bclk_ratio = rt298_set_bclk_ratio,
1052};
1053
1054static struct snd_soc_dai_driver rt298_dai[] = {
1055 {
1056 .name = "rt298-aif1",
1057 .id = RT298_AIF1,
1058 .playback = {
1059 .stream_name = "AIF1 Playback",
1060 .channels_min = 1,
1061 .channels_max = 2,
1062 .rates = RT298_STEREO_RATES,
1063 .formats = RT298_FORMATS,
1064 },
1065 .capture = {
1066 .stream_name = "AIF1 Capture",
1067 .channels_min = 1,
1068 .channels_max = 2,
1069 .rates = RT298_STEREO_RATES,
1070 .formats = RT298_FORMATS,
1071 },
1072 .ops = &rt298_aif_dai_ops,
1073 .symmetric_rates = 1,
1074 },
1075 {
1076 .name = "rt298-aif2",
1077 .id = RT298_AIF2,
1078 .playback = {
1079 .stream_name = "AIF2 Playback",
1080 .channels_min = 1,
1081 .channels_max = 2,
1082 .rates = RT298_STEREO_RATES,
1083 .formats = RT298_FORMATS,
1084 },
1085 .capture = {
1086 .stream_name = "AIF2 Capture",
1087 .channels_min = 1,
1088 .channels_max = 2,
1089 .rates = RT298_STEREO_RATES,
1090 .formats = RT298_FORMATS,
1091 },
1092 .ops = &rt298_aif_dai_ops,
1093 .symmetric_rates = 1,
1094 },
1095
1096};
1097
1098static struct snd_soc_codec_driver soc_codec_dev_rt298 = {
1099 .probe = rt298_probe,
1100 .remove = rt298_remove,
1101 .suspend = rt298_suspend,
1102 .resume = rt298_resume,
1103 .set_bias_level = rt298_set_bias_level,
1104 .idle_bias_off = true,
1105 .controls = rt298_snd_controls,
1106 .num_controls = ARRAY_SIZE(rt298_snd_controls),
1107 .dapm_widgets = rt298_dapm_widgets,
1108 .num_dapm_widgets = ARRAY_SIZE(rt298_dapm_widgets),
1109 .dapm_routes = rt298_dapm_routes,
1110 .num_dapm_routes = ARRAY_SIZE(rt298_dapm_routes),
1111};
1112
1113static const struct regmap_config rt298_regmap = {
1114 .reg_bits = 32,
1115 .val_bits = 32,
1116 .max_register = 0x02370100,
1117 .volatile_reg = rt298_volatile_register,
1118 .readable_reg = rt298_readable_register,
1119 .reg_write = rl6347a_hw_write,
1120 .reg_read = rl6347a_hw_read,
1121 .cache_type = REGCACHE_RBTREE,
1122 .reg_defaults = rt298_reg,
1123 .num_reg_defaults = ARRAY_SIZE(rt298_reg),
1124};
1125
1126static const struct i2c_device_id rt298_i2c_id[] = {
1127 {"rt298", 0},
1128 {}
1129};
1130MODULE_DEVICE_TABLE(i2c, rt298_i2c_id);
1131
1132static const struct acpi_device_id rt298_acpi_match[] = {
1133 { "INT343A", 0 },
1134 {},
1135};
1136MODULE_DEVICE_TABLE(acpi, rt298_acpi_match);
1137
1138static int rt298_i2c_probe(struct i2c_client *i2c,
1139 const struct i2c_device_id *id)
1140{
1141 struct rt298_platform_data *pdata = dev_get_platdata(&i2c->dev);
1142 struct rt298_priv *rt298;
1143 struct device *dev = &i2c->dev;
1144 const struct acpi_device_id *acpiid;
1145 int i, ret;
1146
1147 rt298 = devm_kzalloc(&i2c->dev, sizeof(*rt298),
1148 GFP_KERNEL);
1149 if (NULL == rt298)
1150 return -ENOMEM;
1151
1152 rt298->regmap = devm_regmap_init(&i2c->dev, NULL, i2c, &rt298_regmap);
1153 if (IS_ERR(rt298->regmap)) {
1154 ret = PTR_ERR(rt298->regmap);
1155 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
1156 ret);
1157 return ret;
1158 }
1159
1160 regmap_read(rt298->regmap,
1161 RT298_GET_PARAM(AC_NODE_ROOT, AC_PAR_VENDOR_ID), &ret);
1162 if (ret != RT298_VENDOR_ID) {
1163 dev_err(&i2c->dev,
1164 "Device with ID register %#x is not rt298\n", ret);
1165 return -ENODEV;
1166 }
1167
1168 rt298->index_cache = rt298_index_def;
1169 rt298->index_cache_size = INDEX_CACHE_SIZE;
1170 rt298->i2c = i2c;
1171 i2c_set_clientdata(i2c, rt298);
1172
1173 /* restore codec default */
1174 for (i = 0; i < INDEX_CACHE_SIZE; i++)
1175 regmap_write(rt298->regmap, rt298->index_cache[i].reg,
1176 rt298->index_cache[i].def);
1177 for (i = 0; i < ARRAY_SIZE(rt298_reg); i++)
1178 regmap_write(rt298->regmap, rt298_reg[i].reg,
1179 rt298_reg[i].def);
1180
1181 if (pdata)
1182 rt298->pdata = *pdata;
1183
1184 /* enable jack combo mode on supported devices */
1185 acpiid = acpi_match_device(dev->driver->acpi_match_table, dev);
1186 if (acpiid) {
1187 rt298->pdata = *(struct rt298_platform_data *)
1188 acpiid->driver_data;
1189 }
1190
1191 /* VREF Charging */
1192 regmap_update_bits(rt298->regmap, 0x04, 0x80, 0x80);
1193 regmap_update_bits(rt298->regmap, 0x1b, 0x860, 0x860);
1194 /* Vref2 */
1195 regmap_update_bits(rt298->regmap, 0x08, 0x20, 0x20);
1196
1197 regmap_write(rt298->regmap, RT298_SET_AUDIO_POWER, AC_PWRST_D3);
1198
1199 for (i = 0; i < RT298_POWER_REG_LEN; i++)
1200 regmap_write(rt298->regmap,
1201 RT298_SET_POWER(rt298_support_power_controls[i]),
1202 AC_PWRST_D1);
1203
1204 if (!rt298->pdata.cbj_en) {
1205 regmap_write(rt298->regmap, RT298_CBJ_CTRL2, 0x0000);
1206 regmap_write(rt298->regmap, RT298_MIC1_DET_CTRL, 0x0816);
1207 regmap_update_bits(rt298->regmap,
1208 RT298_CBJ_CTRL1, 0xf000, 0xb000);
1209 } else {
1210 regmap_update_bits(rt298->regmap,
1211 RT298_CBJ_CTRL1, 0xf000, 0x5000);
1212 }
1213
1214 mdelay(10);
1215
1216 if (!rt298->pdata.gpio2_en)
1217 regmap_write(rt298->regmap, RT298_SET_DMIC2_DEFAULT, 0x4000);
1218 else
1219 regmap_write(rt298->regmap, RT298_SET_DMIC2_DEFAULT, 0);
1220
1221 mdelay(10);
1222
1223 regmap_write(rt298->regmap, RT298_MISC_CTRL1, 0x0000);
1224 regmap_update_bits(rt298->regmap,
1225 RT298_WIND_FILTER_CTRL, 0x0082, 0x0082);
1226 regmap_update_bits(rt298->regmap, RT298_IRQ_CTRL, 0x2, 0x2);
1227 rt298->is_hp_in = -1;
1228
1229 if (rt298->i2c->irq) {
1230 ret = request_threaded_irq(rt298->i2c->irq, NULL, rt298_irq,
1231 IRQF_TRIGGER_HIGH | IRQF_ONESHOT, "rt298", rt298);
1232 if (ret != 0) {
1233 dev_err(&i2c->dev,
1234 "Failed to reguest IRQ: %d\n", ret);
1235 return ret;
1236 }
1237 }
1238
1239 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt298,
1240 rt298_dai, ARRAY_SIZE(rt298_dai));
1241
1242 return ret;
1243}
1244
1245static int rt298_i2c_remove(struct i2c_client *i2c)
1246{
1247 struct rt298_priv *rt298 = i2c_get_clientdata(i2c);
1248
1249 if (i2c->irq)
1250 free_irq(i2c->irq, rt298);
1251 snd_soc_unregister_codec(&i2c->dev);
1252
1253 return 0;
1254}
1255
1256
1257static struct i2c_driver rt298_i2c_driver = {
1258 .driver = {
1259 .name = "rt298",
1260 .acpi_match_table = ACPI_PTR(rt298_acpi_match),
1261 },
1262 .probe = rt298_i2c_probe,
1263 .remove = rt298_i2c_remove,
1264 .id_table = rt298_i2c_id,
1265};
1266
1267module_i2c_driver(rt298_i2c_driver);
1268
1269MODULE_DESCRIPTION("ASoC RT298 driver");
1270MODULE_AUTHOR("Bard Liao <bardliao@realtek.com>");
1271MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/rt298.h b/sound/soc/codecs/rt298.h
new file mode 100644
index 000000000000..31da16265f2b
--- /dev/null
+++ b/sound/soc/codecs/rt298.h
@@ -0,0 +1,206 @@
1/*
2 * rt298.h -- RT298 ALSA SoC audio driver
3 *
4 * Copyright 2011 Realtek Microelectronics
5 * Author: Johnny Hsu <johnnyhsu@realtek.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef __RT298_H__
13#define __RT298_H__
14
15#define VERB_CMD(V, N, D) ((N << 20) | (V << 8) | D)
16
17#define RT298_AUDIO_FUNCTION_GROUP 0x01
18#define RT298_DAC_OUT1 0x02
19#define RT298_DAC_OUT2 0x03
20#define RT298_DIG_CVT 0x06
21#define RT298_ADC_IN1 0x09
22#define RT298_ADC_IN2 0x08
23#define RT298_MIXER_IN 0x0b
24#define RT298_MIXER_OUT1 0x0c
25#define RT298_MIXER_OUT2 0x0d
26#define RT298_DMIC1 0x12
27#define RT298_DMIC2 0x13
28#define RT298_SPK_OUT 0x14
29#define RT298_MIC1 0x18
30#define RT298_LINE1 0x1a
31#define RT298_BEEP 0x1d
32#define RT298_SPDIF 0x1e
33#define RT298_VENDOR_REGISTERS 0x20
34#define RT298_HP_OUT 0x21
35#define RT298_MIXER_IN1 0x22
36#define RT298_MIXER_IN2 0x23
37
38#define RT298_SET_PIN_SFT 6
39#define RT298_SET_PIN_ENABLE 0x40
40#define RT298_SET_PIN_DISABLE 0
41#define RT298_SET_EAPD_HIGH 0x2
42#define RT298_SET_EAPD_LOW 0
43
44#define RT298_MUTE_SFT 7
45
46/* Verb commands */
47#define RT298_GET_PARAM(NID, PARAM) VERB_CMD(AC_VERB_PARAMETERS, NID, PARAM)
48#define RT298_SET_POWER(NID) VERB_CMD(AC_VERB_SET_POWER_STATE, NID, 0)
49#define RT298_SET_AUDIO_POWER RT298_SET_POWER(RT298_AUDIO_FUNCTION_GROUP)
50#define RT298_SET_HPO_POWER RT298_SET_POWER(RT298_HP_OUT)
51#define RT298_SET_SPK_POWER RT298_SET_POWER(RT298_SPK_OUT)
52#define RT298_SET_DMIC1_POWER RT298_SET_POWER(RT298_DMIC1)
53#define RT298_SPK_MUX\
54 VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT298_SPK_OUT, 0)
55#define RT298_HPO_MUX\
56 VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT298_HP_OUT, 0)
57#define RT298_ADC0_MUX\
58 VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT298_MIXER_IN1, 0)
59#define RT298_ADC1_MUX\
60 VERB_CMD(AC_VERB_SET_CONNECT_SEL, RT298_MIXER_IN2, 0)
61#define RT298_SET_MIC1\
62 VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_MIC1, 0)
63#define RT298_SET_PIN_HPO\
64 VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_HP_OUT, 0)
65#define RT298_SET_PIN_SPK\
66 VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_SPK_OUT, 0)
67#define RT298_SET_PIN_DMIC1\
68 VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_DMIC1, 0)
69#define RT298_SET_PIN_SPDIF\
70 VERB_CMD(AC_VERB_SET_PIN_WIDGET_CONTROL, RT298_SPDIF, 0)
71#define RT298_SET_PIN_DIG_CVT\
72 VERB_CMD(AC_VERB_SET_DIGI_CONVERT_1, RT298_DIG_CVT, 0)
73#define RT298_SPK_EAPD\
74 VERB_CMD(AC_VERB_SET_EAPD_BTLENABLE, RT298_SPK_OUT, 0)
75#define RT298_SET_AMP_GAIN_HPO\
76 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_HP_OUT, 0)
77#define RT298_SET_AMP_GAIN_ADC_IN1\
78 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_ADC_IN1, 0)
79#define RT298_SET_AMP_GAIN_ADC_IN2\
80 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_ADC_IN2, 0)
81#define RT298_GET_HP_SENSE\
82 VERB_CMD(AC_VERB_GET_PIN_SENSE, RT298_HP_OUT, 0)
83#define RT298_GET_MIC1_SENSE\
84 VERB_CMD(AC_VERB_GET_PIN_SENSE, RT298_MIC1, 0)
85#define RT298_SET_DMIC2_DEFAULT\
86 VERB_CMD(AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, RT298_DMIC2, 0)
87#define RT298_SET_SPDIF_DEFAULT\
88 VERB_CMD(AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, RT298_SPDIF, 0)
89#define RT298_DACL_GAIN\
90 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_DAC_OUT1, 0xa000)
91#define RT298_DACR_GAIN\
92 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_DAC_OUT1, 0x9000)
93#define RT298_ADCL_GAIN\
94 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_ADC_IN1, 0x6000)
95#define RT298_ADCR_GAIN\
96 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_ADC_IN1, 0x5000)
97#define RT298_MIC_GAIN\
98 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIC1, 0x7000)
99#define RT298_SPOL_GAIN\
100 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_SPK_OUT, 0xa000)
101#define RT298_SPOR_GAIN\
102 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_SPK_OUT, 0x9000)
103#define RT298_HPOL_GAIN\
104 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_HP_OUT, 0xa000)
105#define RT298_HPOR_GAIN\
106 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_HP_OUT, 0x9000)
107#define RT298_F_DAC_SWITCH\
108 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_OUT1, 0x7000)
109#define RT298_F_RECMIX_SWITCH\
110 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_OUT1, 0x7100)
111#define RT298_REC_MIC_SWITCH\
112 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_IN, 0x7000)
113#define RT298_REC_I2S_SWITCH\
114 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_IN, 0x7100)
115#define RT298_REC_LINE_SWITCH\
116 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_IN, 0x7200)
117#define RT298_REC_BEEP_SWITCH\
118 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, RT298_MIXER_IN, 0x7300)
119#define RT298_DAC_FORMAT\
120 VERB_CMD(AC_VERB_SET_STREAM_FORMAT, RT298_DAC_OUT1, 0)
121#define RT298_ADC_FORMAT\
122 VERB_CMD(AC_VERB_SET_STREAM_FORMAT, RT298_ADC_IN1, 0)
123#define RT298_COEF_INDEX\
124 VERB_CMD(AC_VERB_SET_COEF_INDEX, RT298_VENDOR_REGISTERS, 0)
125#define RT298_PROC_COEF\
126 VERB_CMD(AC_VERB_SET_PROC_COEF, RT298_VENDOR_REGISTERS, 0)
127
128/* Index registers */
129#define RT298_A_BIAS_CTRL1 0x01
130#define RT298_A_BIAS_CTRL2 0x02
131#define RT298_POWER_CTRL1 0x03
132#define RT298_A_BIAS_CTRL3 0x04
133#define RT298_POWER_CTRL2 0x08
134#define RT298_I2S_CTRL1 0x09
135#define RT298_I2S_CTRL2 0x0a
136#define RT298_CLK_DIV 0x0b
137#define RT298_DC_GAIN 0x0d
138#define RT298_POWER_CTRL3 0x0f
139#define RT298_MIC1_DET_CTRL 0x19
140#define RT298_MISC_CTRL1 0x20
141#define RT298_IRQ_CTRL 0x33
142#define RT298_WIND_FILTER_CTRL 0x46
143#define RT298_PLL_CTRL1 0x49
144#define RT298_CBJ_CTRL1 0x4f
145#define RT298_CBJ_CTRL2 0x50
146#define RT298_PLL_CTRL 0x63
147#define RT298_DEPOP_CTRL1 0x66
148#define RT298_DEPOP_CTRL2 0x67
149#define RT298_DEPOP_CTRL3 0x68
150#define RT298_DEPOP_CTRL4 0x69
151
152/* SPDIF (0x06) */
153#define RT298_SPDIF_SEL_SFT 0
154#define RT298_SPDIF_SEL_PCM0 0
155#define RT298_SPDIF_SEL_PCM1 1
156#define RT298_SPDIF_SEL_SPOUT 2
157#define RT298_SPDIF_SEL_PP 3
158
159/* RECMIX (0x0b) */
160#define RT298_M_REC_BEEP_SFT 0
161#define RT298_M_REC_LINE1_SFT 1
162#define RT298_M_REC_MIC1_SFT 2
163#define RT298_M_REC_I2S_SFT 3
164
165/* Front (0x0c) */
166#define RT298_M_FRONT_DAC_SFT 0
167#define RT298_M_FRONT_REC_SFT 1
168
169/* SPK-OUT (0x14) */
170#define RT298_M_SPK_MUX_SFT 14
171#define RT298_SPK_SEL_MASK 0x1
172#define RT298_SPK_SEL_SFT 0
173#define RT298_SPK_SEL_F 0
174#define RT298_SPK_SEL_S 1
175
176/* HP-OUT (0x21) */
177#define RT298_M_HP_MUX_SFT 14
178#define RT298_HP_SEL_MASK 0x1
179#define RT298_HP_SEL_SFT 0
180#define RT298_HP_SEL_F 0
181#define RT298_HP_SEL_S 1
182
183/* ADC (0x22) (0x23) */
184#define RT298_ADC_SEL_MASK 0x7
185#define RT298_ADC_SEL_SFT 0
186#define RT298_ADC_SEL_SURR 0
187#define RT298_ADC_SEL_FRONT 1
188#define RT298_ADC_SEL_DMIC 2
189#define RT298_ADC_SEL_BEEP 4
190#define RT298_ADC_SEL_LINE1 5
191#define RT298_ADC_SEL_I2S 6
192#define RT298_ADC_SEL_MIC1 7
193
194#define RT298_SCLK_S_MCLK 0
195#define RT298_SCLK_S_PLL 1
196
197enum {
198 RT298_AIF1,
199 RT298_AIF2,
200 RT298_AIFS,
201};
202
203int rt298_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack);
204
205#endif /* __RT298_H__ */
206
diff --git a/sound/soc/codecs/rt5631.c b/sound/soc/codecs/rt5631.c
index 058167c80d71..d8771020299d 100644
--- a/sound/soc/codecs/rt5631.c
+++ b/sound/soc/codecs/rt5631.c
@@ -1725,7 +1725,6 @@ static int rt5631_i2c_remove(struct i2c_client *client)
1725static struct i2c_driver rt5631_i2c_driver = { 1725static struct i2c_driver rt5631_i2c_driver = {
1726 .driver = { 1726 .driver = {
1727 .name = "rt5631", 1727 .name = "rt5631",
1728 .owner = THIS_MODULE,
1729 .of_match_table = of_match_ptr(rt5631_i2c_dt_ids), 1728 .of_match_table = of_match_ptr(rt5631_i2c_dt_ids),
1730 }, 1729 },
1731 .probe = rt5631_i2c_probe, 1730 .probe = rt5631_i2c_probe,
diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index 9bc78e57513d..b4139d3da334 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -51,7 +51,7 @@ static const struct regmap_range_cfg rt5640_ranges[] = {
51 .window_len = 0x1, }, 51 .window_len = 0x1, },
52}; 52};
53 53
54static const struct reg_default init_list[] = { 54static const struct reg_sequence init_list[] = {
55 {RT5640_PR_BASE + 0x3d, 0x3600}, 55 {RT5640_PR_BASE + 0x3d, 0x3600},
56 {RT5640_PR_BASE + 0x12, 0x0aa8}, 56 {RT5640_PR_BASE + 0x12, 0x0aa8},
57 {RT5640_PR_BASE + 0x14, 0x0aaa}, 57 {RT5640_PR_BASE + 0x14, 0x0aaa},
@@ -459,10 +459,11 @@ static int set_dmic_clk(struct snd_soc_dapm_widget *w,
459{ 459{
460 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); 460 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
461 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 461 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
462 int idx = -EINVAL; 462 int idx, rate;
463
464 idx = rl6231_calc_dmic_clk(rt5640->sysclk);
465 463
464 rate = rt5640->sysclk / rl6231_get_pre_div(rt5640->regmap,
465 RT5640_ADDA_CLK1, RT5640_I2S_PD1_SFT);
466 idx = rl6231_calc_dmic_clk(rate);
466 if (idx < 0) 467 if (idx < 0)
467 dev_err(codec->dev, "Failed to set DMIC clock\n"); 468 dev_err(codec->dev, "Failed to set DMIC clock\n");
468 else 469 else
@@ -984,6 +985,35 @@ static int rt5640_hp_event(struct snd_soc_dapm_widget *w,
984 return 0; 985 return 0;
985} 986}
986 987
988static int rt5640_lout_event(struct snd_soc_dapm_widget *w,
989 struct snd_kcontrol *kcontrol, int event)
990{
991 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
992
993 switch (event) {
994 case SND_SOC_DAPM_POST_PMU:
995 hp_amp_power_on(codec);
996 snd_soc_update_bits(codec, RT5640_PWR_ANLG1,
997 RT5640_PWR_LM, RT5640_PWR_LM);
998 snd_soc_update_bits(codec, RT5640_OUTPUT,
999 RT5640_L_MUTE | RT5640_R_MUTE, 0);
1000 break;
1001
1002 case SND_SOC_DAPM_PRE_PMD:
1003 snd_soc_update_bits(codec, RT5640_OUTPUT,
1004 RT5640_L_MUTE | RT5640_R_MUTE,
1005 RT5640_L_MUTE | RT5640_R_MUTE);
1006 snd_soc_update_bits(codec, RT5640_PWR_ANLG1,
1007 RT5640_PWR_LM, 0);
1008 break;
1009
1010 default:
1011 return 0;
1012 }
1013
1014 return 0;
1015}
1016
987static int rt5640_hp_power_event(struct snd_soc_dapm_widget *w, 1017static int rt5640_hp_power_event(struct snd_soc_dapm_widget *w,
988 struct snd_kcontrol *kcontrol, int event) 1018 struct snd_kcontrol *kcontrol, int event)
989{ 1019{
@@ -1179,13 +1209,16 @@ static const struct snd_soc_dapm_widget rt5640_dapm_widgets[] = {
1179 0, rt5640_spo_l_mix, ARRAY_SIZE(rt5640_spo_l_mix)), 1209 0, rt5640_spo_l_mix, ARRAY_SIZE(rt5640_spo_l_mix)),
1180 SND_SOC_DAPM_MIXER("SPOR MIX", SND_SOC_NOPM, 0, 1210 SND_SOC_DAPM_MIXER("SPOR MIX", SND_SOC_NOPM, 0,
1181 0, rt5640_spo_r_mix, ARRAY_SIZE(rt5640_spo_r_mix)), 1211 0, rt5640_spo_r_mix, ARRAY_SIZE(rt5640_spo_r_mix)),
1182 SND_SOC_DAPM_MIXER("LOUT MIX", RT5640_PWR_ANLG1, RT5640_PWR_LM_BIT, 0, 1212 SND_SOC_DAPM_MIXER("LOUT MIX", SND_SOC_NOPM, 0, 0,
1183 rt5640_lout_mix, ARRAY_SIZE(rt5640_lout_mix)), 1213 rt5640_lout_mix, ARRAY_SIZE(rt5640_lout_mix)),
1184 SND_SOC_DAPM_SUPPLY_S("Improve HP Amp Drv", 1, SND_SOC_NOPM, 1214 SND_SOC_DAPM_SUPPLY_S("Improve HP Amp Drv", 1, SND_SOC_NOPM,
1185 0, 0, rt5640_hp_power_event, SND_SOC_DAPM_POST_PMU), 1215 0, 0, rt5640_hp_power_event, SND_SOC_DAPM_POST_PMU),
1186 SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM, 0, 0, 1216 SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM, 0, 0,
1187 rt5640_hp_event, 1217 rt5640_hp_event,
1188 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 1218 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
1219 SND_SOC_DAPM_PGA_S("LOUT amp", 1, SND_SOC_NOPM, 0, 0,
1220 rt5640_lout_event,
1221 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
1189 SND_SOC_DAPM_SUPPLY("HP L Amp", RT5640_PWR_ANLG1, 1222 SND_SOC_DAPM_SUPPLY("HP L Amp", RT5640_PWR_ANLG1,
1190 RT5640_PWR_HP_L_BIT, 0, NULL, 0), 1223 RT5640_PWR_HP_L_BIT, 0, NULL, 0),
1191 SND_SOC_DAPM_SUPPLY("HP R Amp", RT5640_PWR_ANLG1, 1224 SND_SOC_DAPM_SUPPLY("HP R Amp", RT5640_PWR_ANLG1,
@@ -1500,8 +1533,10 @@ static const struct snd_soc_dapm_route rt5640_dapm_routes[] = {
1500 {"HP R Playback", "Switch", "HP Amp"}, 1533 {"HP R Playback", "Switch", "HP Amp"},
1501 {"HPOL", NULL, "HP L Playback"}, 1534 {"HPOL", NULL, "HP L Playback"},
1502 {"HPOR", NULL, "HP R Playback"}, 1535 {"HPOR", NULL, "HP R Playback"},
1503 {"LOUTL", NULL, "LOUT MIX"}, 1536
1504 {"LOUTR", NULL, "LOUT MIX"}, 1537 {"LOUT amp", NULL, "LOUT MIX"},
1538 {"LOUTL", NULL, "LOUT amp"},
1539 {"LOUTR", NULL, "LOUT amp"},
1505}; 1540};
1506 1541
1507static const struct snd_soc_dapm_route rt5640_specific_dapm_routes[] = { 1542static const struct snd_soc_dapm_route rt5640_specific_dapm_routes[] = {
@@ -2207,7 +2242,7 @@ static int rt5640_i2c_probe(struct i2c_client *i2c,
2207 regmap_read(rt5640->regmap, RT5640_VENDOR_ID2, &val); 2242 regmap_read(rt5640->regmap, RT5640_VENDOR_ID2, &val);
2208 if (val != RT5640_DEVICE_ID) { 2243 if (val != RT5640_DEVICE_ID) {
2209 dev_err(&i2c->dev, 2244 dev_err(&i2c->dev,
2210 "Device with ID register %x is not rt5640/39\n", val); 2245 "Device with ID register %#x is not rt5640/39\n", val);
2211 return -ENODEV; 2246 return -ENODEV;
2212 } 2247 }
2213 2248
@@ -2242,7 +2277,6 @@ static int rt5640_i2c_remove(struct i2c_client *i2c)
2242static struct i2c_driver rt5640_i2c_driver = { 2277static struct i2c_driver rt5640_i2c_driver = {
2243 .driver = { 2278 .driver = {
2244 .name = "rt5640", 2279 .name = "rt5640",
2245 .owner = THIS_MODULE,
2246 .acpi_match_table = ACPI_PTR(rt5640_acpi_match), 2280 .acpi_match_table = ACPI_PTR(rt5640_acpi_match),
2247 .of_match_table = of_match_ptr(rt5640_of_match), 2281 .of_match_table = of_match_ptr(rt5640_of_match),
2248 }, 2282 },
diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index 9ce311e088fc..1e70736cc970 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -21,6 +21,7 @@
21#include <linux/gpio/consumer.h> 21#include <linux/gpio/consumer.h>
22#include <linux/acpi.h> 22#include <linux/acpi.h>
23#include <linux/dmi.h> 23#include <linux/dmi.h>
24#include <linux/regulator/consumer.h>
24#include <sound/core.h> 25#include <sound/core.h>
25#include <sound/pcm.h> 26#include <sound/pcm.h>
26#include <sound/pcm_params.h> 27#include <sound/pcm_params.h>
@@ -54,7 +55,7 @@ static const struct regmap_range_cfg rt5645_ranges[] = {
54 }, 55 },
55}; 56};
56 57
57static const struct reg_default init_list[] = { 58static const struct reg_sequence init_list[] = {
58 {RT5645_PR_BASE + 0x3d, 0x3600}, 59 {RT5645_PR_BASE + 0x3d, 0x3600},
59 {RT5645_PR_BASE + 0x1c, 0xfd20}, 60 {RT5645_PR_BASE + 0x1c, 0xfd20},
60 {RT5645_PR_BASE + 0x20, 0x611f}, 61 {RT5645_PR_BASE + 0x20, 0x611f},
@@ -63,7 +64,7 @@ static const struct reg_default init_list[] = {
63}; 64};
64#define RT5645_INIT_REG_LEN ARRAY_SIZE(init_list) 65#define RT5645_INIT_REG_LEN ARRAY_SIZE(init_list)
65 66
66static const struct reg_default rt5650_init_list[] = { 67static const struct reg_sequence rt5650_init_list[] = {
67 {0xf6, 0x0100}, 68 {0xf6, 0x0100},
68}; 69};
69 70
@@ -223,6 +224,39 @@ static const struct reg_default rt5645_reg[] = {
223 { 0xff, 0x6308 }, 224 { 0xff, 0x6308 },
224}; 225};
225 226
227static const char *const rt5645_supply_names[] = {
228 "avdd",
229 "cpvdd",
230};
231
232struct rt5645_priv {
233 struct snd_soc_codec *codec;
234 struct rt5645_platform_data pdata;
235 struct regmap *regmap;
236 struct i2c_client *i2c;
237 struct gpio_desc *gpiod_hp_det;
238 struct snd_soc_jack *hp_jack;
239 struct snd_soc_jack *mic_jack;
240 struct snd_soc_jack *btn_jack;
241 struct delayed_work jack_detect_work;
242 struct regulator_bulk_data supplies[ARRAY_SIZE(rt5645_supply_names)];
243
244 int codec_type;
245 int sysclk;
246 int sysclk_src;
247 int lrck[RT5645_AIFS];
248 int bclk[RT5645_AIFS];
249 int master[RT5645_AIFS];
250
251 int pll_src;
252 int pll_in;
253 int pll_out;
254
255 int jack_type;
256 bool en_button_func;
257 bool hp_on;
258};
259
226static int rt5645_reset(struct snd_soc_codec *codec) 260static int rt5645_reset(struct snd_soc_codec *codec)
227{ 261{
228 return snd_soc_write(codec, RT5645_RESET, 0); 262 return snd_soc_write(codec, RT5645_RESET, 0);
@@ -360,6 +394,7 @@ static bool rt5645_readable_register(struct device *dev, unsigned int reg)
360 case RT5645_DEPOP_M1: 394 case RT5645_DEPOP_M1:
361 case RT5645_DEPOP_M2: 395 case RT5645_DEPOP_M2:
362 case RT5645_DEPOP_M3: 396 case RT5645_DEPOP_M3:
397 case RT5645_CHARGE_PUMP:
363 case RT5645_MICBIAS: 398 case RT5645_MICBIAS:
364 case RT5645_A_JD_CTRL1: 399 case RT5645_A_JD_CTRL1:
365 case RT5645_VAD_CTRL4: 400 case RT5645_VAD_CTRL4:
@@ -510,10 +545,11 @@ static int set_dmic_clk(struct snd_soc_dapm_widget *w,
510{ 545{
511 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); 546 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
512 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); 547 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
513 int idx = -EINVAL; 548 int idx, rate;
514
515 idx = rl6231_calc_dmic_clk(rt5645->sysclk);
516 549
550 rate = rt5645->sysclk / rl6231_get_pre_div(rt5645->regmap,
551 RT5645_ADDA_CLK1, RT5645_I2S_PD1_SFT);
552 idx = rl6231_calc_dmic_clk(rate);
517 if (idx < 0) 553 if (idx < 0)
518 dev_err(codec->dev, "Failed to set DMIC clock\n"); 554 dev_err(codec->dev, "Failed to set DMIC clock\n");
519 else 555 else
@@ -1331,15 +1367,23 @@ static void hp_amp_power(struct snd_soc_codec *codec, int on)
1331 if (on) { 1367 if (on) {
1332 if (hp_amp_power_count <= 0) { 1368 if (hp_amp_power_count <= 0) {
1333 if (rt5645->codec_type == CODEC_TYPE_RT5650) { 1369 if (rt5645->codec_type == CODEC_TYPE_RT5650) {
1370 snd_soc_write(codec, RT5645_DEPOP_M2, 0x3100);
1334 snd_soc_write(codec, RT5645_CHARGE_PUMP, 1371 snd_soc_write(codec, RT5645_CHARGE_PUMP,
1335 0x0e06); 1372 0x0e06);
1336 snd_soc_write(codec, RT5645_DEPOP_M1, 0x001d); 1373 snd_soc_write(codec, RT5645_DEPOP_M1, 0x000d);
1374 regmap_write(rt5645->regmap, RT5645_PR_BASE +
1375 RT5645_HP_DCC_INT1, 0x9f01);
1376 msleep(20);
1377 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
1378 RT5645_HP_CO_MASK, RT5645_HP_CO_EN);
1337 regmap_write(rt5645->regmap, RT5645_PR_BASE + 1379 regmap_write(rt5645->regmap, RT5645_PR_BASE +
1338 0x3e, 0x7400); 1380 0x3e, 0x7400);
1339 snd_soc_write(codec, RT5645_DEPOP_M3, 0x0737); 1381 snd_soc_write(codec, RT5645_DEPOP_M3, 0x0737);
1340 regmap_write(rt5645->regmap, RT5645_PR_BASE + 1382 regmap_write(rt5645->regmap, RT5645_PR_BASE +
1341 RT5645_MAMP_INT_REG2, 0xfc00); 1383 RT5645_MAMP_INT_REG2, 0xfc00);
1342 snd_soc_write(codec, RT5645_DEPOP_M2, 0x1140); 1384 snd_soc_write(codec, RT5645_DEPOP_M2, 0x1140);
1385 mdelay(5);
1386 rt5645->hp_on = true;
1343 } else { 1387 } else {
1344 /* depop parameters */ 1388 /* depop parameters */
1345 snd_soc_update_bits(codec, RT5645_DEPOP_M2, 1389 snd_soc_update_bits(codec, RT5645_DEPOP_M2,
@@ -1553,6 +1597,27 @@ static int rt5645_bst2_event(struct snd_soc_dapm_widget *w,
1553 return 0; 1597 return 0;
1554} 1598}
1555 1599
1600static int rt5650_hp_event(struct snd_soc_dapm_widget *w,
1601 struct snd_kcontrol *k, int event)
1602{
1603 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1604 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
1605
1606 switch (event) {
1607 case SND_SOC_DAPM_POST_PMU:
1608 if (rt5645->hp_on) {
1609 msleep(100);
1610 rt5645->hp_on = false;
1611 }
1612 break;
1613
1614 default:
1615 return 0;
1616 }
1617
1618 return 0;
1619}
1620
1556static const struct snd_soc_dapm_widget rt5645_dapm_widgets[] = { 1621static const struct snd_soc_dapm_widget rt5645_dapm_widgets[] = {
1557 SND_SOC_DAPM_SUPPLY("LDO2", RT5645_PWR_MIXER, 1622 SND_SOC_DAPM_SUPPLY("LDO2", RT5645_PWR_MIXER,
1558 RT5645_PWR_LDO2_BIT, 0, NULL, 0), 1623 RT5645_PWR_LDO2_BIT, 0, NULL, 0),
@@ -1697,15 +1762,6 @@ static const struct snd_soc_dapm_widget rt5645_dapm_widgets[] = {
1697 SND_SOC_DAPM_PGA("IF1_ADC4", SND_SOC_NOPM, 0, 0, NULL, 0), 1762 SND_SOC_DAPM_PGA("IF1_ADC4", SND_SOC_NOPM, 0, 0, NULL, 0),
1698 1763
1699 /* IF1 2 Mux */ 1764 /* IF1 2 Mux */
1700 SND_SOC_DAPM_MUX("RT5645 IF1 ADC1 Swap Mux", SND_SOC_NOPM,
1701 0, 0, &rt5645_if1_adc1_in_mux),
1702 SND_SOC_DAPM_MUX("RT5645 IF1 ADC2 Swap Mux", SND_SOC_NOPM,
1703 0, 0, &rt5645_if1_adc2_in_mux),
1704 SND_SOC_DAPM_MUX("RT5645 IF1 ADC3 Swap Mux", SND_SOC_NOPM,
1705 0, 0, &rt5645_if1_adc3_in_mux),
1706 SND_SOC_DAPM_MUX("RT5645 IF1 ADC Mux", SND_SOC_NOPM,
1707 0, 0, &rt5645_if1_adc_in_mux),
1708
1709 SND_SOC_DAPM_MUX("IF2 ADC Mux", SND_SOC_NOPM, 1765 SND_SOC_DAPM_MUX("IF2 ADC Mux", SND_SOC_NOPM,
1710 0, 0, &rt5645_if2_adc_in_mux), 1766 0, 0, &rt5645_if2_adc_in_mux),
1711 1767
@@ -1716,14 +1772,6 @@ static const struct snd_soc_dapm_widget rt5645_dapm_widgets[] = {
1716 SND_SOC_DAPM_PGA("IF1 DAC1", SND_SOC_NOPM, 0, 0, NULL, 0), 1772 SND_SOC_DAPM_PGA("IF1 DAC1", SND_SOC_NOPM, 0, 0, NULL, 0),
1717 SND_SOC_DAPM_PGA("IF1 DAC2", SND_SOC_NOPM, 0, 0, NULL, 0), 1773 SND_SOC_DAPM_PGA("IF1 DAC2", SND_SOC_NOPM, 0, 0, NULL, 0),
1718 SND_SOC_DAPM_PGA("IF1 DAC3", SND_SOC_NOPM, 0, 0, NULL, 0), 1774 SND_SOC_DAPM_PGA("IF1 DAC3", SND_SOC_NOPM, 0, 0, NULL, 0),
1719 SND_SOC_DAPM_MUX("RT5645 IF1 DAC1 L Mux", SND_SOC_NOPM, 0, 0,
1720 &rt5645_if1_dac0_tdm_sel_mux),
1721 SND_SOC_DAPM_MUX("RT5645 IF1 DAC1 R Mux", SND_SOC_NOPM, 0, 0,
1722 &rt5645_if1_dac1_tdm_sel_mux),
1723 SND_SOC_DAPM_MUX("RT5645 IF1 DAC2 L Mux", SND_SOC_NOPM, 0, 0,
1724 &rt5645_if1_dac2_tdm_sel_mux),
1725 SND_SOC_DAPM_MUX("RT5645 IF1 DAC2 R Mux", SND_SOC_NOPM, 0, 0,
1726 &rt5645_if1_dac3_tdm_sel_mux),
1727 SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM, 0, 0, NULL, 0), 1775 SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM, 0, 0, NULL, 0),
1728 SND_SOC_DAPM_PGA("IF1 ADC L", SND_SOC_NOPM, 0, 0, NULL, 0), 1776 SND_SOC_DAPM_PGA("IF1 ADC L", SND_SOC_NOPM, 0, 0, NULL, 0),
1729 SND_SOC_DAPM_PGA("IF1 ADC R", SND_SOC_NOPM, 0, 0, NULL, 0), 1777 SND_SOC_DAPM_PGA("IF1 ADC R", SND_SOC_NOPM, 0, 0, NULL, 0),
@@ -1854,6 +1902,26 @@ static const struct snd_soc_dapm_widget rt5645_dapm_widgets[] = {
1854 SND_SOC_DAPM_OUTPUT("PDM1R"), 1902 SND_SOC_DAPM_OUTPUT("PDM1R"),
1855 SND_SOC_DAPM_OUTPUT("SPOL"), 1903 SND_SOC_DAPM_OUTPUT("SPOL"),
1856 SND_SOC_DAPM_OUTPUT("SPOR"), 1904 SND_SOC_DAPM_OUTPUT("SPOR"),
1905 SND_SOC_DAPM_POST("DAPM_POST", rt5650_hp_event),
1906};
1907
1908static const struct snd_soc_dapm_widget rt5645_specific_dapm_widgets[] = {
1909 SND_SOC_DAPM_MUX("RT5645 IF1 DAC1 L Mux", SND_SOC_NOPM, 0, 0,
1910 &rt5645_if1_dac0_tdm_sel_mux),
1911 SND_SOC_DAPM_MUX("RT5645 IF1 DAC1 R Mux", SND_SOC_NOPM, 0, 0,
1912 &rt5645_if1_dac1_tdm_sel_mux),
1913 SND_SOC_DAPM_MUX("RT5645 IF1 DAC2 L Mux", SND_SOC_NOPM, 0, 0,
1914 &rt5645_if1_dac2_tdm_sel_mux),
1915 SND_SOC_DAPM_MUX("RT5645 IF1 DAC2 R Mux", SND_SOC_NOPM, 0, 0,
1916 &rt5645_if1_dac3_tdm_sel_mux),
1917 SND_SOC_DAPM_MUX("RT5645 IF1 ADC Mux", SND_SOC_NOPM,
1918 0, 0, &rt5645_if1_adc_in_mux),
1919 SND_SOC_DAPM_MUX("RT5645 IF1 ADC1 Swap Mux", SND_SOC_NOPM,
1920 0, 0, &rt5645_if1_adc1_in_mux),
1921 SND_SOC_DAPM_MUX("RT5645 IF1 ADC2 Swap Mux", SND_SOC_NOPM,
1922 0, 0, &rt5645_if1_adc2_in_mux),
1923 SND_SOC_DAPM_MUX("RT5645 IF1 ADC3 Swap Mux", SND_SOC_NOPM,
1924 0, 0, &rt5645_if1_adc3_in_mux),
1857}; 1925};
1858 1926
1859static const struct snd_soc_dapm_widget rt5650_specific_dapm_widgets[] = { 1927static const struct snd_soc_dapm_widget rt5650_specific_dapm_widgets[] = {
@@ -2642,7 +2710,7 @@ static int rt5645_set_bias_level(struct snd_soc_codec *codec,
2642 2710
2643 switch (level) { 2711 switch (level) {
2644 case SND_SOC_BIAS_PREPARE: 2712 case SND_SOC_BIAS_PREPARE:
2645 if (SND_SOC_BIAS_STANDBY == codec->dapm.bias_level) { 2713 if (SND_SOC_BIAS_STANDBY == snd_soc_codec_get_bias_level(codec)) {
2646 snd_soc_update_bits(codec, RT5645_PWR_ANLG1, 2714 snd_soc_update_bits(codec, RT5645_PWR_ANLG1,
2647 RT5645_PWR_VREF1 | RT5645_PWR_MB | 2715 RT5645_PWR_VREF1 | RT5645_PWR_MB |
2648 RT5645_PWR_BG | RT5645_PWR_VREF2, 2716 RT5645_PWR_BG | RT5645_PWR_VREF2,
@@ -2686,94 +2754,15 @@ static int rt5645_set_bias_level(struct snd_soc_codec *codec,
2686 return 0; 2754 return 0;
2687} 2755}
2688 2756
2689static int rt5650_calibration(struct rt5645_priv *rt5645)
2690{
2691 int val, i;
2692 int ret = -1;
2693
2694 regcache_cache_bypass(rt5645->regmap, true);
2695 regmap_write(rt5645->regmap, RT5645_RESET, 0);
2696 regmap_write(rt5645->regmap, RT5645_GEN_CTRL3, 0x0800);
2697 regmap_write(rt5645->regmap, RT5645_PR_BASE + RT5645_CHOP_DAC_ADC,
2698 0x3600);
2699 regmap_write(rt5645->regmap, RT5645_PR_BASE + 0x25, 0x7000);
2700 regmap_write(rt5645->regmap, RT5645_I2S1_SDP, 0x8008);
2701 /* headset type */
2702 regmap_write(rt5645->regmap, RT5645_GEN_CTRL1, 0x2061);
2703 regmap_write(rt5645->regmap, RT5645_CHARGE_PUMP, 0x0006);
2704 regmap_write(rt5645->regmap, RT5645_PWR_ANLG1, 0x2012);
2705 regmap_write(rt5645->regmap, RT5645_PWR_MIXER, 0x0002);
2706 regmap_write(rt5645->regmap, RT5645_PWR_VOL, 0x0020);
2707 regmap_write(rt5645->regmap, RT5645_JD_CTRL3, 0x00f0);
2708 regmap_write(rt5645->regmap, RT5645_IN1_CTRL1, 0x0006);
2709 regmap_write(rt5645->regmap, RT5645_IN1_CTRL2, 0x1827);
2710 regmap_write(rt5645->regmap, RT5645_IN1_CTRL2, 0x0827);
2711 msleep(400);
2712 /* Inline command */
2713 regmap_write(rt5645->regmap, RT5645_DEPOP_M1, 0x0001);
2714 regmap_write(rt5645->regmap, RT5650_4BTN_IL_CMD2, 0xc000);
2715 regmap_write(rt5645->regmap, RT5650_4BTN_IL_CMD1, 0x0008);
2716 /* Calbration */
2717 regmap_write(rt5645->regmap, RT5645_GLB_CLK, 0x8000);
2718 regmap_write(rt5645->regmap, RT5645_DEPOP_M1, 0x0000);
2719 regmap_write(rt5645->regmap, RT5650_4BTN_IL_CMD2, 0xc000);
2720 regmap_write(rt5645->regmap, RT5650_4BTN_IL_CMD1, 0x0008);
2721 regmap_write(rt5645->regmap, RT5645_PWR_DIG2, 0x8800);
2722 regmap_write(rt5645->regmap, RT5645_PWR_ANLG1, 0xe8fa);
2723 regmap_write(rt5645->regmap, RT5645_PWR_ANLG2, 0x8c04);
2724 regmap_write(rt5645->regmap, RT5645_DEPOP_M2, 0x3100);
2725 regmap_write(rt5645->regmap, RT5645_CHARGE_PUMP, 0x0e06);
2726 regmap_write(rt5645->regmap, RT5645_BASS_BACK, 0x8a13);
2727 regmap_write(rt5645->regmap, RT5645_GEN_CTRL3, 0x0820);
2728 regmap_write(rt5645->regmap, RT5645_DEPOP_M1, 0x000d);
2729 /* Power on and Calbration */
2730 regmap_write(rt5645->regmap, RT5645_PR_BASE + RT5645_HP_DCC_INT1,
2731 0x9f01);
2732 msleep(200);
2733 for (i = 0; i < 5; i++) {
2734 regmap_read(rt5645->regmap, RT5645_PR_BASE + 0x7a, &val);
2735 if (val != 0 && val != 0x3f3f) {
2736 ret = 0;
2737 break;
2738 }
2739 msleep(50);
2740 }
2741 pr_debug("%s: PR-7A = 0x%x\n", __func__, val);
2742
2743 /* mute */
2744 regmap_write(rt5645->regmap, RT5645_PR_BASE + 0x3e, 0x7400);
2745 regmap_write(rt5645->regmap, RT5645_DEPOP_M3, 0x0737);
2746 regmap_write(rt5645->regmap, RT5645_PR_BASE + RT5645_MAMP_INT_REG2,
2747 0xfc00);
2748 regmap_write(rt5645->regmap, RT5645_DEPOP_M2, 0x1140);
2749 regmap_write(rt5645->regmap, RT5645_DEPOP_M1, 0x0000);
2750 regmap_write(rt5645->regmap, RT5645_GEN_CTRL2, 0x4020);
2751 regmap_write(rt5645->regmap, RT5645_PWR_ANLG2, 0x0006);
2752 regmap_write(rt5645->regmap, RT5645_PWR_DIG2, 0x0000);
2753 msleep(350);
2754
2755 regcache_cache_bypass(rt5645->regmap, false);
2756
2757 return ret;
2758}
2759
2760static void rt5645_enable_push_button_irq(struct snd_soc_codec *codec, 2757static void rt5645_enable_push_button_irq(struct snd_soc_codec *codec,
2761 bool enable) 2758 bool enable)
2762{ 2759{
2763 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); 2760 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
2764 2761
2765 if (enable) { 2762 if (enable) {
2766 snd_soc_dapm_mutex_lock(&codec->dapm); 2763 snd_soc_dapm_force_enable_pin(dapm, "ADC L power");
2767 snd_soc_dapm_force_enable_pin_unlocked(&codec->dapm, 2764 snd_soc_dapm_force_enable_pin(dapm, "ADC R power");
2768 "ADC L power"); 2765 snd_soc_dapm_sync(dapm);
2769 snd_soc_dapm_force_enable_pin_unlocked(&codec->dapm,
2770 "ADC R power");
2771 snd_soc_dapm_force_enable_pin_unlocked(&codec->dapm,
2772 "LDO2");
2773 snd_soc_dapm_force_enable_pin_unlocked(&codec->dapm,
2774 "Mic Det Power");
2775 snd_soc_dapm_sync_unlocked(&codec->dapm);
2776 snd_soc_dapm_mutex_unlock(&codec->dapm);
2777 2766
2778 snd_soc_update_bits(codec, 2767 snd_soc_update_bits(codec,
2779 RT5645_INT_IRQ_ST, 0x8, 0x8); 2768 RT5645_INT_IRQ_ST, 0x8, 0x8);
@@ -2786,36 +2775,26 @@ static void rt5645_enable_push_button_irq(struct snd_soc_codec *codec,
2786 snd_soc_update_bits(codec, RT5650_4BTN_IL_CMD2, 0x8000, 0x0); 2775 snd_soc_update_bits(codec, RT5650_4BTN_IL_CMD2, 0x8000, 0x0);
2787 snd_soc_update_bits(codec, RT5645_INT_IRQ_ST, 0x8, 0x0); 2776 snd_soc_update_bits(codec, RT5645_INT_IRQ_ST, 0x8, 0x0);
2788 2777
2789 snd_soc_dapm_mutex_lock(&codec->dapm); 2778 snd_soc_dapm_disable_pin(dapm, "ADC L power");
2790 snd_soc_dapm_disable_pin_unlocked(&codec->dapm, 2779 snd_soc_dapm_disable_pin(dapm, "ADC R power");
2791 "ADC L power"); 2780 snd_soc_dapm_sync(dapm);
2792 snd_soc_dapm_disable_pin_unlocked(&codec->dapm,
2793 "ADC R power");
2794 if (rt5645->pdata.jd_mode == 0)
2795 snd_soc_dapm_disable_pin_unlocked(&codec->dapm,
2796 "LDO2");
2797 snd_soc_dapm_disable_pin_unlocked(&codec->dapm,
2798 "Mic Det Power");
2799 snd_soc_dapm_sync_unlocked(&codec->dapm);
2800 snd_soc_dapm_mutex_unlock(&codec->dapm);
2801 } 2781 }
2802} 2782}
2803 2783
2804static int rt5645_jack_detect(struct snd_soc_codec *codec, int jack_insert) 2784static int rt5645_jack_detect(struct snd_soc_codec *codec, int jack_insert)
2805{ 2785{
2786 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
2806 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); 2787 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
2807 unsigned int val; 2788 unsigned int val;
2808 2789
2809 if (jack_insert) { 2790 if (jack_insert) {
2810 regmap_write(rt5645->regmap, RT5645_CHARGE_PUMP, 0x0006); 2791 regmap_write(rt5645->regmap, RT5645_CHARGE_PUMP, 0x0006);
2811 2792
2812 if (codec->component.card->instantiated) { 2793 /* for jack type detect */
2813 /* for jack type detect */ 2794 snd_soc_dapm_force_enable_pin(dapm, "LDO2");
2814 snd_soc_dapm_force_enable_pin(&codec->dapm, "LDO2"); 2795 snd_soc_dapm_force_enable_pin(dapm, "Mic Det Power");
2815 snd_soc_dapm_force_enable_pin(&codec->dapm, 2796 snd_soc_dapm_sync(dapm);
2816 "Mic Det Power"); 2797 if (!dapm->card->instantiated) {
2817 snd_soc_dapm_sync(&codec->dapm);
2818 } else {
2819 /* Power up necessary bits for JD if dapm is 2798 /* Power up necessary bits for JD if dapm is
2820 not ready yet */ 2799 not ready yet */
2821 regmap_update_bits(rt5645->regmap, RT5645_PWR_ANLG1, 2800 regmap_update_bits(rt5645->regmap, RT5645_PWR_ANLG1,
@@ -2828,14 +2807,15 @@ static int rt5645_jack_detect(struct snd_soc_codec *codec, int jack_insert)
2828 } 2807 }
2829 2808
2830 regmap_write(rt5645->regmap, RT5645_JD_CTRL3, 0x00f0); 2809 regmap_write(rt5645->regmap, RT5645_JD_CTRL3, 0x00f0);
2831 regmap_write(rt5645->regmap, RT5645_IN1_CTRL1, 0x0006); 2810 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2,
2832 regmap_update_bits(rt5645->regmap, 2811 RT5645_CBJ_MN_JD, RT5645_CBJ_MN_JD);
2833 RT5645_IN1_CTRL2, 0x1000, 0x1000); 2812 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1,
2813 RT5645_CBJ_BST1_EN, RT5645_CBJ_BST1_EN);
2834 msleep(100); 2814 msleep(100);
2835 regmap_update_bits(rt5645->regmap, 2815 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2,
2836 RT5645_IN1_CTRL2, 0x1000, 0x0000); 2816 RT5645_CBJ_MN_JD, 0);
2837 2817
2838 msleep(450); 2818 msleep(600);
2839 regmap_read(rt5645->regmap, RT5645_IN1_CTRL3, &val); 2819 regmap_read(rt5645->regmap, RT5645_IN1_CTRL3, &val);
2840 val &= 0x7; 2820 val &= 0x7;
2841 dev_dbg(codec->dev, "val = %d\n", val); 2821 dev_dbg(codec->dev, "val = %d\n", val);
@@ -2846,43 +2826,46 @@ static int rt5645_jack_detect(struct snd_soc_codec *codec, int jack_insert)
2846 rt5645_enable_push_button_irq(codec, true); 2826 rt5645_enable_push_button_irq(codec, true);
2847 } 2827 }
2848 } else { 2828 } else {
2849 if (codec->component.card->instantiated) { 2829 snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
2850 snd_soc_dapm_disable_pin(&codec->dapm, 2830 snd_soc_dapm_sync(dapm);
2851 "Mic Det Power");
2852 snd_soc_dapm_sync(&codec->dapm);
2853 } else
2854 regmap_update_bits(rt5645->regmap,
2855 RT5645_PWR_VOL, RT5645_PWR_MIC_DET, 0);
2856 rt5645->jack_type = SND_JACK_HEADPHONE; 2831 rt5645->jack_type = SND_JACK_HEADPHONE;
2857 } 2832 }
2858 2833
2834 snd_soc_update_bits(codec, RT5645_CHARGE_PUMP, 0x0300, 0x0200);
2835 snd_soc_write(codec, RT5645_DEPOP_M1, 0x001d);
2836 snd_soc_write(codec, RT5645_DEPOP_M1, 0x0001);
2859 } else { /* jack out */ 2837 } else { /* jack out */
2860 rt5645->jack_type = 0; 2838 rt5645->jack_type = 0;
2839
2840 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2,
2841 RT5645_CBJ_MN_JD, RT5645_CBJ_MN_JD);
2842 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1,
2843 RT5645_CBJ_BST1_EN, 0);
2844
2861 if (rt5645->en_button_func) 2845 if (rt5645->en_button_func)
2862 rt5645_enable_push_button_irq(codec, false); 2846 rt5645_enable_push_button_irq(codec, false);
2863 else { 2847
2864 if (codec->component.card->instantiated) { 2848 if (rt5645->pdata.jd_mode == 0)
2865 if (rt5645->pdata.jd_mode == 0) 2849 snd_soc_dapm_disable_pin(dapm, "LDO2");
2866 snd_soc_dapm_disable_pin(&codec->dapm, 2850 snd_soc_dapm_disable_pin(dapm, "Mic Det Power");
2867 "LDO2"); 2851 snd_soc_dapm_sync(dapm);
2868 snd_soc_dapm_disable_pin(&codec->dapm,
2869 "Mic Det Power");
2870 snd_soc_dapm_sync(&codec->dapm);
2871 } else {
2872 if (rt5645->pdata.jd_mode == 0)
2873 regmap_update_bits(rt5645->regmap,
2874 RT5645_PWR_MIXER,
2875 RT5645_PWR_LDO2, 0);
2876 regmap_update_bits(rt5645->regmap,
2877 RT5645_PWR_VOL, RT5645_PWR_MIC_DET, 0);
2878 }
2879 }
2880 } 2852 }
2881 2853
2882 return rt5645->jack_type; 2854 return rt5645->jack_type;
2883} 2855}
2884 2856
2885static int rt5645_irq_detection(struct rt5645_priv *rt5645); 2857static int rt5645_button_detect(struct snd_soc_codec *codec)
2858{
2859 int btn_type, val;
2860
2861 val = snd_soc_read(codec, RT5650_4BTN_IL_CMD1);
2862 pr_debug("val=0x%x\n", val);
2863 btn_type = val & 0xfff0;
2864 snd_soc_write(codec, RT5650_4BTN_IL_CMD1, val);
2865
2866 return btn_type;
2867}
2868
2886static irqreturn_t rt5645_irq(int irq, void *data); 2869static irqreturn_t rt5645_irq(int irq, void *data);
2887 2870
2888int rt5645_set_jack_detect(struct snd_soc_codec *codec, 2871int rt5645_set_jack_detect(struct snd_soc_codec *codec,
@@ -2913,36 +2896,11 @@ static void rt5645_jack_detect_work(struct work_struct *work)
2913{ 2896{
2914 struct rt5645_priv *rt5645 = 2897 struct rt5645_priv *rt5645 =
2915 container_of(work, struct rt5645_priv, jack_detect_work.work); 2898 container_of(work, struct rt5645_priv, jack_detect_work.work);
2916
2917 rt5645_irq_detection(rt5645);
2918}
2919
2920static irqreturn_t rt5645_irq(int irq, void *data)
2921{
2922 struct rt5645_priv *rt5645 = data;
2923
2924 queue_delayed_work(system_power_efficient_wq,
2925 &rt5645->jack_detect_work, msecs_to_jiffies(250));
2926
2927 return IRQ_HANDLED;
2928}
2929
2930static int rt5645_button_detect(struct snd_soc_codec *codec)
2931{
2932 int btn_type, val;
2933
2934 val = snd_soc_read(codec, RT5650_4BTN_IL_CMD1);
2935 pr_debug("val=0x%x\n", val);
2936 btn_type = val & 0xfff0;
2937 snd_soc_write(codec, RT5650_4BTN_IL_CMD1, val);
2938
2939 return btn_type;
2940}
2941
2942static int rt5645_irq_detection(struct rt5645_priv *rt5645)
2943{
2944 int val, btn_type, gpio_state = 0, report = 0; 2899 int val, btn_type, gpio_state = 0, report = 0;
2945 2900
2901 if (!rt5645->codec)
2902 return;
2903
2946 switch (rt5645->pdata.jd_mode) { 2904 switch (rt5645->pdata.jd_mode) {
2947 case 0: /* Not using rt5645 JD */ 2905 case 0: /* Not using rt5645 JD */
2948 if (rt5645->gpiod_hp_det) { 2906 if (rt5645->gpiod_hp_det) {
@@ -2955,7 +2913,7 @@ static int rt5645_irq_detection(struct rt5645_priv *rt5645)
2955 report, SND_JACK_HEADPHONE); 2913 report, SND_JACK_HEADPHONE);
2956 snd_soc_jack_report(rt5645->mic_jack, 2914 snd_soc_jack_report(rt5645->mic_jack,
2957 report, SND_JACK_MICROPHONE); 2915 report, SND_JACK_MICROPHONE);
2958 return report; 2916 return;
2959 case 1: /* 2 port */ 2917 case 1: /* 2 port */
2960 val = snd_soc_read(rt5645->codec, RT5645_A_JD_CTRL1) & 0x0070; 2918 val = snd_soc_read(rt5645->codec, RT5645_A_JD_CTRL1) & 0x0070;
2961 break; 2919 break;
@@ -3037,27 +2995,39 @@ static int rt5645_irq_detection(struct rt5645_priv *rt5645)
3037 snd_soc_jack_report(rt5645->btn_jack, 2995 snd_soc_jack_report(rt5645->btn_jack,
3038 report, SND_JACK_BTN_0 | SND_JACK_BTN_1 | 2996 report, SND_JACK_BTN_0 | SND_JACK_BTN_1 |
3039 SND_JACK_BTN_2 | SND_JACK_BTN_3); 2997 SND_JACK_BTN_2 | SND_JACK_BTN_3);
2998}
2999
3000static irqreturn_t rt5645_irq(int irq, void *data)
3001{
3002 struct rt5645_priv *rt5645 = data;
3003
3004 queue_delayed_work(system_power_efficient_wq,
3005 &rt5645->jack_detect_work, msecs_to_jiffies(250));
3040 3006
3041 return report; 3007 return IRQ_HANDLED;
3042} 3008}
3043 3009
3044static int rt5645_probe(struct snd_soc_codec *codec) 3010static int rt5645_probe(struct snd_soc_codec *codec)
3045{ 3011{
3012 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
3046 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); 3013 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
3047 3014
3048 rt5645->codec = codec; 3015 rt5645->codec = codec;
3049 3016
3050 switch (rt5645->codec_type) { 3017 switch (rt5645->codec_type) {
3051 case CODEC_TYPE_RT5645: 3018 case CODEC_TYPE_RT5645:
3052 snd_soc_dapm_add_routes(&codec->dapm, 3019 snd_soc_dapm_new_controls(dapm,
3020 rt5645_specific_dapm_widgets,
3021 ARRAY_SIZE(rt5645_specific_dapm_widgets));
3022 snd_soc_dapm_add_routes(dapm,
3053 rt5645_specific_dapm_routes, 3023 rt5645_specific_dapm_routes,
3054 ARRAY_SIZE(rt5645_specific_dapm_routes)); 3024 ARRAY_SIZE(rt5645_specific_dapm_routes));
3055 break; 3025 break;
3056 case CODEC_TYPE_RT5650: 3026 case CODEC_TYPE_RT5650:
3057 snd_soc_dapm_new_controls(&codec->dapm, 3027 snd_soc_dapm_new_controls(dapm,
3058 rt5650_specific_dapm_widgets, 3028 rt5650_specific_dapm_widgets,
3059 ARRAY_SIZE(rt5650_specific_dapm_widgets)); 3029 ARRAY_SIZE(rt5650_specific_dapm_widgets));
3060 snd_soc_dapm_add_routes(&codec->dapm, 3030 snd_soc_dapm_add_routes(dapm,
3061 rt5650_specific_dapm_routes, 3031 rt5650_specific_dapm_routes,
3062 ARRAY_SIZE(rt5650_specific_dapm_routes)); 3032 ARRAY_SIZE(rt5650_specific_dapm_routes));
3063 break; 3033 break;
@@ -3067,9 +3037,9 @@ static int rt5645_probe(struct snd_soc_codec *codec)
3067 3037
3068 /* for JD function */ 3038 /* for JD function */
3069 if (rt5645->pdata.jd_mode) { 3039 if (rt5645->pdata.jd_mode) {
3070 snd_soc_dapm_force_enable_pin(&codec->dapm, "JD Power"); 3040 snd_soc_dapm_force_enable_pin(dapm, "JD Power");
3071 snd_soc_dapm_force_enable_pin(&codec->dapm, "LDO2"); 3041 snd_soc_dapm_force_enable_pin(dapm, "LDO2");
3072 snd_soc_dapm_sync(&codec->dapm); 3042 snd_soc_dapm_sync(dapm);
3073 } 3043 }
3074 3044
3075 return 0; 3045 return 0;
@@ -3110,7 +3080,7 @@ static int rt5645_resume(struct snd_soc_codec *codec)
3110#define RT5645_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 3080#define RT5645_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
3111 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8) 3081 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
3112 3082
3113static struct snd_soc_dai_ops rt5645_aif_dai_ops = { 3083static const struct snd_soc_dai_ops rt5645_aif_dai_ops = {
3114 .hw_params = rt5645_hw_params, 3084 .hw_params = rt5645_hw_params,
3115 .set_fmt = rt5645_set_dai_fmt, 3085 .set_fmt = rt5645_set_dai_fmt,
3116 .set_sysclk = rt5645_set_dai_sysclk, 3086 .set_sysclk = rt5645_set_dai_sysclk,
@@ -3221,7 +3191,7 @@ static int strago_quirk_cb(const struct dmi_system_id *id)
3221 return 1; 3191 return 1;
3222} 3192}
3223 3193
3224static struct dmi_system_id dmi_platform_intel_braswell[] = { 3194static const struct dmi_system_id dmi_platform_intel_braswell[] = {
3225 { 3195 {
3226 .ident = "Intel Strago", 3196 .ident = "Intel Strago",
3227 .callback = strago_quirk_cb, 3197 .callback = strago_quirk_cb,
@@ -3229,6 +3199,13 @@ static struct dmi_system_id dmi_platform_intel_braswell[] = {
3229 DMI_MATCH(DMI_PRODUCT_NAME, "Strago"), 3199 DMI_MATCH(DMI_PRODUCT_NAME, "Strago"),
3230 }, 3200 },
3231 }, 3201 },
3202 {
3203 .ident = "Google Celes",
3204 .callback = strago_quirk_cb,
3205 .matches = {
3206 DMI_MATCH(DMI_PRODUCT_NAME, "Celes"),
3207 },
3208 },
3232 { } 3209 { }
3233}; 3210};
3234 3211
@@ -3251,7 +3228,7 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
3251{ 3228{
3252 struct rt5645_platform_data *pdata = dev_get_platdata(&i2c->dev); 3229 struct rt5645_platform_data *pdata = dev_get_platdata(&i2c->dev);
3253 struct rt5645_priv *rt5645; 3230 struct rt5645_priv *rt5645;
3254 int ret; 3231 int ret, i;
3255 unsigned int val; 3232 unsigned int val;
3256 3233
3257 rt5645 = devm_kzalloc(&i2c->dev, sizeof(struct rt5645_priv), 3234 rt5645 = devm_kzalloc(&i2c->dev, sizeof(struct rt5645_priv),
@@ -3285,6 +3262,24 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
3285 return ret; 3262 return ret;
3286 } 3263 }
3287 3264
3265 for (i = 0; i < ARRAY_SIZE(rt5645->supplies); i++)
3266 rt5645->supplies[i].supply = rt5645_supply_names[i];
3267
3268 ret = devm_regulator_bulk_get(&i2c->dev,
3269 ARRAY_SIZE(rt5645->supplies),
3270 rt5645->supplies);
3271 if (ret) {
3272 dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret);
3273 return ret;
3274 }
3275
3276 ret = regulator_bulk_enable(ARRAY_SIZE(rt5645->supplies),
3277 rt5645->supplies);
3278 if (ret) {
3279 dev_err(&i2c->dev, "Failed to enable supplies: %d\n", ret);
3280 return ret;
3281 }
3282
3288 regmap_read(rt5645->regmap, RT5645_VENDOR_ID2, &val); 3283 regmap_read(rt5645->regmap, RT5645_VENDOR_ID2, &val);
3289 3284
3290 switch (val) { 3285 switch (val) {
@@ -3296,16 +3291,10 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
3296 break; 3291 break;
3297 default: 3292 default:
3298 dev_err(&i2c->dev, 3293 dev_err(&i2c->dev,
3299 "Device with ID register %x is not rt5645 or rt5650\n", 3294 "Device with ID register %#x is not rt5645 or rt5650\n",
3300 val); 3295 val);
3301 return -ENODEV; 3296 ret = -ENODEV;
3302 } 3297 goto err_enable;
3303
3304 if (rt5645->codec_type == CODEC_TYPE_RT5650) {
3305 ret = rt5650_calibration(rt5645);
3306
3307 if (ret < 0)
3308 pr_err("calibration failed!\n");
3309 } 3298 }
3310 3299
3311 regmap_write(rt5645->regmap, RT5645_RESET, 0); 3300 regmap_write(rt5645->regmap, RT5645_RESET, 0);
@@ -3338,6 +3327,8 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
3338 break; 3327 break;
3339 3328
3340 case RT5645_DMIC_DATA_GPIO5: 3329 case RT5645_DMIC_DATA_GPIO5:
3330 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
3331 RT5645_I2S2_DAC_PIN_MASK, RT5645_I2S2_DAC_PIN_GPIO);
3341 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1, 3332 regmap_update_bits(rt5645->regmap, RT5645_DMIC_CTRL1,
3342 RT5645_DMIC_1_DP_MASK, RT5645_DMIC_1_DP_GPIO5); 3333 RT5645_DMIC_1_DP_MASK, RT5645_DMIC_1_DP_GPIO5);
3343 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1, 3334 regmap_update_bits(rt5645->regmap, RT5645_GPIO_CTRL1,
@@ -3393,8 +3384,6 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
3393 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3, 3384 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3,
3394 RT5645_IRQ_CLK_GATE_CTRL, 3385 RT5645_IRQ_CLK_GATE_CTRL,
3395 RT5645_IRQ_CLK_GATE_CTRL); 3386 RT5645_IRQ_CLK_GATE_CTRL);
3396 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1,
3397 RT5645_CBJ_BST1_EN, RT5645_CBJ_BST1_EN);
3398 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS, 3387 regmap_update_bits(rt5645->regmap, RT5645_MICBIAS,
3399 RT5645_IRQ_CLK_INT, RT5645_IRQ_CLK_INT); 3388 RT5645_IRQ_CLK_INT, RT5645_IRQ_CLK_INT);
3400 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2, 3389 regmap_update_bits(rt5645->regmap, RT5645_IRQ_CTRL2,
@@ -3434,12 +3423,25 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
3434 ret = request_threaded_irq(rt5645->i2c->irq, NULL, rt5645_irq, 3423 ret = request_threaded_irq(rt5645->i2c->irq, NULL, rt5645_irq,
3435 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING 3424 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
3436 | IRQF_ONESHOT, "rt5645", rt5645); 3425 | IRQF_ONESHOT, "rt5645", rt5645);
3437 if (ret) 3426 if (ret) {
3438 dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret); 3427 dev_err(&i2c->dev, "Failed to reguest IRQ: %d\n", ret);
3428 goto err_enable;
3429 }
3439 } 3430 }
3440 3431
3441 return snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5645, 3432 ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_rt5645,
3442 rt5645_dai, ARRAY_SIZE(rt5645_dai)); 3433 rt5645_dai, ARRAY_SIZE(rt5645_dai));
3434 if (ret)
3435 goto err_irq;
3436
3437 return 0;
3438
3439err_irq:
3440 if (rt5645->i2c->irq)
3441 free_irq(rt5645->i2c->irq, rt5645);
3442err_enable:
3443 regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies);
3444 return ret;
3443} 3445}
3444 3446
3445static int rt5645_i2c_remove(struct i2c_client *i2c) 3447static int rt5645_i2c_remove(struct i2c_client *i2c)
@@ -3452,18 +3454,31 @@ static int rt5645_i2c_remove(struct i2c_client *i2c)
3452 cancel_delayed_work_sync(&rt5645->jack_detect_work); 3454 cancel_delayed_work_sync(&rt5645->jack_detect_work);
3453 3455
3454 snd_soc_unregister_codec(&i2c->dev); 3456 snd_soc_unregister_codec(&i2c->dev);
3457 regulator_bulk_disable(ARRAY_SIZE(rt5645->supplies), rt5645->supplies);
3455 3458
3456 return 0; 3459 return 0;
3457} 3460}
3458 3461
3462static void rt5645_i2c_shutdown(struct i2c_client *i2c)
3463{
3464 struct rt5645_priv *rt5645 = i2c_get_clientdata(i2c);
3465
3466 regmap_update_bits(rt5645->regmap, RT5645_GEN_CTRL3,
3467 RT5645_RING2_SLEEVE_GND, RT5645_RING2_SLEEVE_GND);
3468 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL2, RT5645_CBJ_MN_JD,
3469 RT5645_CBJ_MN_JD);
3470 regmap_update_bits(rt5645->regmap, RT5645_IN1_CTRL1, RT5645_CBJ_BST1_EN,
3471 0);
3472}
3473
3459static struct i2c_driver rt5645_i2c_driver = { 3474static struct i2c_driver rt5645_i2c_driver = {
3460 .driver = { 3475 .driver = {
3461 .name = "rt5645", 3476 .name = "rt5645",
3462 .owner = THIS_MODULE,
3463 .acpi_match_table = ACPI_PTR(rt5645_acpi_match), 3477 .acpi_match_table = ACPI_PTR(rt5645_acpi_match),
3464 }, 3478 },
3465 .probe = rt5645_i2c_probe, 3479 .probe = rt5645_i2c_probe,
3466 .remove = rt5645_i2c_remove, 3480 .remove = rt5645_i2c_remove,
3481 .shutdown = rt5645_i2c_shutdown,
3467 .id_table = rt5645_i2c_id, 3482 .id_table = rt5645_i2c_id,
3468}; 3483};
3469module_i2c_driver(rt5645_i2c_driver); 3484module_i2c_driver(rt5645_i2c_driver);
diff --git a/sound/soc/codecs/rt5645.h b/sound/soc/codecs/rt5645.h
index 0353a6a273ab..0e4cfc6ac649 100644
--- a/sound/soc/codecs/rt5645.h
+++ b/sound/soc/codecs/rt5645.h
@@ -1693,6 +1693,10 @@
1693#define RT5645_GP6_PIN_SFT 6 1693#define RT5645_GP6_PIN_SFT 6
1694#define RT5645_GP6_PIN_GPIO6 (0x0 << 6) 1694#define RT5645_GP6_PIN_GPIO6 (0x0 << 6)
1695#define RT5645_GP6_PIN_DMIC2_SDA (0x1 << 6) 1695#define RT5645_GP6_PIN_DMIC2_SDA (0x1 << 6)
1696#define RT5645_I2S2_DAC_PIN_MASK (0x1 << 4)
1697#define RT5645_I2S2_DAC_PIN_SFT 4
1698#define RT5645_I2S2_DAC_PIN_I2S (0x0 << 4)
1699#define RT5645_I2S2_DAC_PIN_GPIO (0x1 << 4)
1696#define RT5645_GP8_PIN_MASK (0x1 << 3) 1700#define RT5645_GP8_PIN_MASK (0x1 << 3)
1697#define RT5645_GP8_PIN_SFT 3 1701#define RT5645_GP8_PIN_SFT 3
1698#define RT5645_GP8_PIN_GPIO8 (0x0 << 3) 1702#define RT5645_GP8_PIN_GPIO8 (0x0 << 3)
@@ -2111,6 +2115,7 @@ enum {
2111#define RT5645_JD_PSV_MODE (0x1 << 12) 2115#define RT5645_JD_PSV_MODE (0x1 << 12)
2112#define RT5645_IRQ_CLK_GATE_CTRL (0x1 << 11) 2116#define RT5645_IRQ_CLK_GATE_CTRL (0x1 << 11)
2113#define RT5645_MICINDET_MANU (0x1 << 7) 2117#define RT5645_MICINDET_MANU (0x1 << 7)
2118#define RT5645_RING2_SLEEVE_GND (0x1 << 5)
2114 2119
2115/* Vendor ID (0xfd) */ 2120/* Vendor ID (0xfd) */
2116#define RT5645_VER_C 0x2 2121#define RT5645_VER_C 0x2
@@ -2177,32 +2182,6 @@ enum {
2177int rt5645_sel_asrc_clk_src(struct snd_soc_codec *codec, 2182int rt5645_sel_asrc_clk_src(struct snd_soc_codec *codec,
2178 unsigned int filter_mask, unsigned int clk_src); 2183 unsigned int filter_mask, unsigned int clk_src);
2179 2184
2180struct rt5645_priv {
2181 struct snd_soc_codec *codec;
2182 struct rt5645_platform_data pdata;
2183 struct regmap *regmap;
2184 struct i2c_client *i2c;
2185 struct gpio_desc *gpiod_hp_det;
2186 struct snd_soc_jack *hp_jack;
2187 struct snd_soc_jack *mic_jack;
2188 struct snd_soc_jack *btn_jack;
2189 struct delayed_work jack_detect_work;
2190
2191 int codec_type;
2192 int sysclk;
2193 int sysclk_src;
2194 int lrck[RT5645_AIFS];
2195 int bclk[RT5645_AIFS];
2196 int master[RT5645_AIFS];
2197
2198 int pll_src;
2199 int pll_in;
2200 int pll_out;
2201
2202 int jack_type;
2203 bool en_button_func;
2204};
2205
2206int rt5645_set_jack_detect(struct snd_soc_codec *codec, 2185int rt5645_set_jack_detect(struct snd_soc_codec *codec,
2207 struct snd_soc_jack *hp_jack, struct snd_soc_jack *mic_jack, 2186 struct snd_soc_jack *hp_jack, struct snd_soc_jack *mic_jack,
2208 struct snd_soc_jack *btn_jack); 2187 struct snd_soc_jack *btn_jack);
diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c
index a3506e193abc..8f7159ba6ca2 100644
--- a/sound/soc/codecs/rt5651.c
+++ b/sound/soc/codecs/rt5651.c
@@ -46,7 +46,7 @@ static const struct regmap_range_cfg rt5651_ranges[] = {
46 .window_len = 0x1, }, 46 .window_len = 0x1, },
47}; 47};
48 48
49static struct reg_default init_list[] = { 49static const struct reg_sequence init_list[] = {
50 {RT5651_PR_BASE + 0x3d, 0x3e00}, 50 {RT5651_PR_BASE + 0x3d, 0x3e00},
51}; 51};
52 52
@@ -378,10 +378,11 @@ static int set_dmic_clk(struct snd_soc_dapm_widget *w,
378{ 378{
379 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); 379 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
380 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); 380 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec);
381 int idx = -EINVAL; 381 int idx, rate;
382
383 idx = rl6231_calc_dmic_clk(rt5651->sysclk);
384 382
383 rate = rt5651->sysclk / rl6231_get_pre_div(rt5651->regmap,
384 RT5651_ADDA_CLK1, RT5651_I2S_PD1_SFT);
385 idx = rl6231_calc_dmic_clk(rate);
385 if (idx < 0) 386 if (idx < 0)
386 dev_err(codec->dev, "Failed to set DMIC clock\n"); 387 dev_err(codec->dev, "Failed to set DMIC clock\n");
387 else 388 else
@@ -1769,7 +1770,7 @@ static int rt5651_i2c_probe(struct i2c_client *i2c,
1769 regmap_read(rt5651->regmap, RT5651_DEVICE_ID, &ret); 1770 regmap_read(rt5651->regmap, RT5651_DEVICE_ID, &ret);
1770 if (ret != RT5651_DEVICE_ID_VALUE) { 1771 if (ret != RT5651_DEVICE_ID_VALUE) {
1771 dev_err(&i2c->dev, 1772 dev_err(&i2c->dev,
1772 "Device with ID register %x is not rt5651\n", ret); 1773 "Device with ID register %#x is not rt5651\n", ret);
1773 return -ENODEV; 1774 return -ENODEV;
1774 } 1775 }
1775 1776
@@ -1806,7 +1807,6 @@ static int rt5651_i2c_remove(struct i2c_client *i2c)
1806static struct i2c_driver rt5651_i2c_driver = { 1807static struct i2c_driver rt5651_i2c_driver = {
1807 .driver = { 1808 .driver = {
1808 .name = "rt5651", 1809 .name = "rt5651",
1809 .owner = THIS_MODULE,
1810 }, 1810 },
1811 .probe = rt5651_i2c_probe, 1811 .probe = rt5651_i2c_probe,
1812 .remove = rt5651_i2c_remove, 1812 .remove = rt5651_i2c_remove,
diff --git a/sound/soc/codecs/rt5670.c b/sound/soc/codecs/rt5670.c
index a9123d414178..177748af94fc 100644
--- a/sound/soc/codecs/rt5670.c
+++ b/sound/soc/codecs/rt5670.c
@@ -51,7 +51,7 @@ static const struct regmap_range_cfg rt5670_ranges[] = {
51 .window_len = 0x1, }, 51 .window_len = 0x1, },
52}; 52};
53 53
54static const struct reg_default init_list[] = { 54static const struct reg_sequence init_list[] = {
55 { RT5670_PR_BASE + 0x14, 0x9a8a }, 55 { RT5670_PR_BASE + 0x14, 0x9a8a },
56 { RT5670_PR_BASE + 0x38, 0x3ba1 }, 56 { RT5670_PR_BASE + 0x38, 0x3ba1 },
57 { RT5670_PR_BASE + 0x3d, 0x3640 }, 57 { RT5670_PR_BASE + 0x3d, 0x3640 },
@@ -683,10 +683,11 @@ static int set_dmic_clk(struct snd_soc_dapm_widget *w,
683{ 683{
684 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); 684 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
685 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 685 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec);
686 int idx = -EINVAL; 686 int idx, rate;
687
688 idx = rl6231_calc_dmic_clk(rt5670->sysclk);
689 687
688 rate = rt5670->sysclk / rl6231_get_pre_div(rt5670->regmap,
689 RT5670_ADDA_CLK1, RT5670_I2S_PD1_SFT);
690 idx = rl6231_calc_dmic_clk(rate);
690 if (idx < 0) 691 if (idx < 0)
691 dev_err(codec->dev, "Failed to set DMIC clock\n"); 692 dev_err(codec->dev, "Failed to set DMIC clock\n");
692 else 693 else
@@ -2720,7 +2721,7 @@ static int rt5670_resume(struct snd_soc_codec *codec)
2720#define RT5670_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 2721#define RT5670_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
2721 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8) 2722 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
2722 2723
2723static struct snd_soc_dai_ops rt5670_aif_dai_ops = { 2724static const struct snd_soc_dai_ops rt5670_aif_dai_ops = {
2724 .hw_params = rt5670_hw_params, 2725 .hw_params = rt5670_hw_params,
2725 .set_fmt = rt5670_set_dai_fmt, 2726 .set_fmt = rt5670_set_dai_fmt,
2726 .set_sysclk = rt5670_set_dai_sysclk, 2727 .set_sysclk = rt5670_set_dai_sysclk,
@@ -2863,7 +2864,7 @@ static int rt5670_i2c_probe(struct i2c_client *i2c,
2863 regmap_read(rt5670->regmap, RT5670_VENDOR_ID2, &val); 2864 regmap_read(rt5670->regmap, RT5670_VENDOR_ID2, &val);
2864 if (val != RT5670_DEVICE_ID) { 2865 if (val != RT5670_DEVICE_ID) {
2865 dev_err(&i2c->dev, 2866 dev_err(&i2c->dev,
2866 "Device with ID register %x is not rt5670/72\n", val); 2867 "Device with ID register %#x is not rt5670/72\n", val);
2867 return -ENODEV; 2868 return -ENODEV;
2868 } 2869 }
2869 2870
@@ -3043,7 +3044,6 @@ static int rt5670_i2c_remove(struct i2c_client *i2c)
3043static struct i2c_driver rt5670_i2c_driver = { 3044static struct i2c_driver rt5670_i2c_driver = {
3044 .driver = { 3045 .driver = {
3045 .name = "rt5670", 3046 .name = "rt5670",
3046 .owner = THIS_MODULE,
3047 .acpi_match_table = ACPI_PTR(rt5670_acpi_match), 3047 .acpi_match_table = ACPI_PTR(rt5670_acpi_match),
3048 }, 3048 },
3049 .probe = rt5670_i2c_probe, 3049 .probe = rt5670_i2c_probe,
diff --git a/sound/soc/codecs/rt5677-spi.c b/sound/soc/codecs/rt5677-spi.c
index ef6348cb9157..3505aafbade4 100644
--- a/sound/soc/codecs/rt5677-spi.c
+++ b/sound/soc/codecs/rt5677-spi.c
@@ -31,84 +31,197 @@
31 31
32#include "rt5677-spi.h" 32#include "rt5677-spi.h"
33 33
34#define RT5677_SPI_BURST_LEN 240
35#define RT5677_SPI_HEADER 5
36#define RT5677_SPI_FREQ 6000000
37
38/* The AddressPhase and DataPhase of SPI commands are MSB first on the wire.
39 * DataPhase word size of 16-bit commands is 2 bytes.
40 * DataPhase word size of 32-bit commands is 4 bytes.
41 * DataPhase word size of burst commands is 8 bytes.
42 * The DSP CPU is little-endian.
43 */
44#define RT5677_SPI_WRITE_BURST 0x5
45#define RT5677_SPI_READ_BURST 0x4
46#define RT5677_SPI_WRITE_32 0x3
47#define RT5677_SPI_READ_32 0x2
48#define RT5677_SPI_WRITE_16 0x1
49#define RT5677_SPI_READ_16 0x0
50
34static struct spi_device *g_spi; 51static struct spi_device *g_spi;
52static DEFINE_MUTEX(spi_mutex);
35 53
36/** 54/* Select a suitable transfer command for the next transfer to ensure
37 * rt5677_spi_write - Write data to SPI. 55 * the transfer address is always naturally aligned while minimizing
38 * @txbuf: Data Buffer for writing. 56 * the total number of transfers required.
39 * @len: Data length. 57 *
58 * 3 transfer commands are available:
59 * RT5677_SPI_READ/WRITE_16: Transfer 2 bytes
60 * RT5677_SPI_READ/WRITE_32: Transfer 4 bytes
61 * RT5677_SPI_READ/WRITE_BURST: Transfer any multiples of 8 bytes
62 *
63 * For example, reading 260 bytes at 0x60030002 uses the following commands:
64 * 0x60030002 RT5677_SPI_READ_16 2 bytes
65 * 0x60030004 RT5677_SPI_READ_32 4 bytes
66 * 0x60030008 RT5677_SPI_READ_BURST 240 bytes
67 * 0x600300F8 RT5677_SPI_READ_BURST 8 bytes
68 * 0x60030100 RT5677_SPI_READ_32 4 bytes
69 * 0x60030104 RT5677_SPI_READ_16 2 bytes
40 * 70 *
71 * Input:
72 * @read: true for read commands; false for write commands
73 * @align: alignment of the next transfer address
74 * @remain: number of bytes remaining to transfer
41 * 75 *
42 * Returns true for success. 76 * Output:
77 * @len: number of bytes to transfer with the selected command
78 * Returns the selected command
43 */ 79 */
44int rt5677_spi_write(u8 *txbuf, size_t len) 80static u8 rt5677_spi_select_cmd(bool read, u32 align, u32 remain, u32 *len)
45{ 81{
46 int status; 82 u8 cmd;
47 83
48 status = spi_write(g_spi, txbuf, len); 84 if (align == 2 || align == 6 || remain == 2) {
49 85 cmd = RT5677_SPI_READ_16;
50 if (status) 86 *len = 2;
51 dev_err(&g_spi->dev, "rt5677_spi_write error %d\n", status); 87 } else if (align == 4 || remain <= 6) {
52 88 cmd = RT5677_SPI_READ_32;
53 return status; 89 *len = 4;
90 } else {
91 cmd = RT5677_SPI_READ_BURST;
92 *len = min_t(u32, remain & ~7, RT5677_SPI_BURST_LEN);
93 }
94 return read ? cmd : cmd + 1;
54} 95}
55EXPORT_SYMBOL_GPL(rt5677_spi_write);
56 96
57/** 97/* Copy dstlen bytes from src to dst, while reversing byte order for each word.
58 * rt5677_spi_burst_write - Write data to SPI by rt5677 dsp memory address. 98 * If srclen < dstlen, zeros are padded.
59 * @addr: Start address.
60 * @txbuf: Data Buffer for writng.
61 * @len: Data length, it must be a multiple of 8.
62 *
63 *
64 * Returns true for success.
65 */ 99 */
66int rt5677_spi_burst_write(u32 addr, const struct firmware *fw) 100static void rt5677_spi_reverse(u8 *dst, u32 dstlen, const u8 *src, u32 srclen)
67{ 101{
68 u8 spi_cmd = RT5677_SPI_CMD_BURST_WRITE; 102 u32 w, i, si;
69 u8 *write_buf; 103 u32 word_size = min_t(u32, dstlen, 8);
70 unsigned int i, end, offset = 0; 104
71 105 for (w = 0; w < dstlen; w += word_size) {
72 write_buf = kmalloc(RT5677_SPI_BUF_LEN + 6, GFP_KERNEL); 106 for (i = 0; i < word_size; i++) {
73 107 si = w + word_size - i - 1;
74 if (write_buf == NULL) 108 dst[w + i] = si < srclen ? src[si] : 0;
75 return -ENOMEM;
76
77 while (offset < fw->size) {
78 if (offset + RT5677_SPI_BUF_LEN <= fw->size)
79 end = RT5677_SPI_BUF_LEN;
80 else
81 end = fw->size % RT5677_SPI_BUF_LEN;
82
83 write_buf[0] = spi_cmd;
84 write_buf[1] = ((addr + offset) & 0xff000000) >> 24;
85 write_buf[2] = ((addr + offset) & 0x00ff0000) >> 16;
86 write_buf[3] = ((addr + offset) & 0x0000ff00) >> 8;
87 write_buf[4] = ((addr + offset) & 0x000000ff) >> 0;
88
89 for (i = 0; i < end; i += 8) {
90 write_buf[i + 12] = fw->data[offset + i + 0];
91 write_buf[i + 11] = fw->data[offset + i + 1];
92 write_buf[i + 10] = fw->data[offset + i + 2];
93 write_buf[i + 9] = fw->data[offset + i + 3];
94 write_buf[i + 8] = fw->data[offset + i + 4];
95 write_buf[i + 7] = fw->data[offset + i + 5];
96 write_buf[i + 6] = fw->data[offset + i + 6];
97 write_buf[i + 5] = fw->data[offset + i + 7];
98 } 109 }
110 }
111}
99 112
100 write_buf[end + 5] = spi_cmd; 113/* Read DSP address space using SPI. addr and len have to be 2-byte aligned. */
114int rt5677_spi_read(u32 addr, void *rxbuf, size_t len)
115{
116 u32 offset;
117 int status = 0;
118 struct spi_transfer t[2];
119 struct spi_message m;
120 /* +4 bytes is for the DummyPhase following the AddressPhase */
121 u8 header[RT5677_SPI_HEADER + 4];
122 u8 body[RT5677_SPI_BURST_LEN];
123 u8 spi_cmd;
124 u8 *cb = rxbuf;
125
126 if (!g_spi)
127 return -ENODEV;
128
129 if ((addr & 1) || (len & 1)) {
130 dev_err(&g_spi->dev, "Bad read align 0x%x(%zu)\n", addr, len);
131 return -EACCES;
132 }
101 133
102 rt5677_spi_write(write_buf, end + 6); 134 memset(t, 0, sizeof(t));
135 t[0].tx_buf = header;
136 t[0].len = sizeof(header);
137 t[0].speed_hz = RT5677_SPI_FREQ;
138 t[1].rx_buf = body;
139 t[1].speed_hz = RT5677_SPI_FREQ;
140 spi_message_init_with_transfers(&m, t, ARRAY_SIZE(t));
141
142 for (offset = 0; offset < len; offset += t[1].len) {
143 spi_cmd = rt5677_spi_select_cmd(true, (addr + offset) & 7,
144 len - offset, &t[1].len);
145
146 /* Construct SPI message header */
147 header[0] = spi_cmd;
148 header[1] = ((addr + offset) & 0xff000000) >> 24;
149 header[2] = ((addr + offset) & 0x00ff0000) >> 16;
150 header[3] = ((addr + offset) & 0x0000ff00) >> 8;
151 header[4] = ((addr + offset) & 0x000000ff) >> 0;
152
153 mutex_lock(&spi_mutex);
154 status |= spi_sync(g_spi, &m);
155 mutex_unlock(&spi_mutex);
156
157 /* Copy data back to caller buffer */
158 rt5677_spi_reverse(cb + offset, t[1].len, body, t[1].len);
159 }
160 return status;
161}
162EXPORT_SYMBOL_GPL(rt5677_spi_read);
103 163
104 offset += RT5677_SPI_BUF_LEN; 164/* Write DSP address space using SPI. addr has to be 2-byte aligned.
165 * If len is not 2-byte aligned, an extra byte of zero is written at the end
166 * as padding.
167 */
168int rt5677_spi_write(u32 addr, const void *txbuf, size_t len)
169{
170 u32 offset, len_with_pad = len;
171 int status = 0;
172 struct spi_transfer t;
173 struct spi_message m;
174 /* +1 byte is for the DummyPhase following the DataPhase */
175 u8 buf[RT5677_SPI_HEADER + RT5677_SPI_BURST_LEN + 1];
176 u8 *body = buf + RT5677_SPI_HEADER;
177 u8 spi_cmd;
178 const u8 *cb = txbuf;
179
180 if (!g_spi)
181 return -ENODEV;
182
183 if (addr & 1) {
184 dev_err(&g_spi->dev, "Bad write align 0x%x(%zu)\n", addr, len);
185 return -EACCES;
105 } 186 }
106 187
107 kfree(write_buf); 188 if (len & 1)
189 len_with_pad = len + 1;
190
191 memset(&t, 0, sizeof(t));
192 t.tx_buf = buf;
193 t.speed_hz = RT5677_SPI_FREQ;
194 spi_message_init_with_transfers(&m, &t, 1);
195
196 for (offset = 0; offset < len_with_pad;) {
197 spi_cmd = rt5677_spi_select_cmd(false, (addr + offset) & 7,
198 len_with_pad - offset, &t.len);
199
200 /* Construct SPI message header */
201 buf[0] = spi_cmd;
202 buf[1] = ((addr + offset) & 0xff000000) >> 24;
203 buf[2] = ((addr + offset) & 0x00ff0000) >> 16;
204 buf[3] = ((addr + offset) & 0x0000ff00) >> 8;
205 buf[4] = ((addr + offset) & 0x000000ff) >> 0;
206
207 /* Fetch data from caller buffer */
208 rt5677_spi_reverse(body, t.len, cb + offset, len - offset);
209 offset += t.len;
210 t.len += RT5677_SPI_HEADER + 1;
211
212 mutex_lock(&spi_mutex);
213 status |= spi_sync(g_spi, &m);
214 mutex_unlock(&spi_mutex);
215 }
216 return status;
217}
218EXPORT_SYMBOL_GPL(rt5677_spi_write);
108 219
109 return 0; 220int rt5677_spi_write_firmware(u32 addr, const struct firmware *fw)
221{
222 return rt5677_spi_write(addr, fw->data, fw->size);
110} 223}
111EXPORT_SYMBOL_GPL(rt5677_spi_burst_write); 224EXPORT_SYMBOL_GPL(rt5677_spi_write_firmware);
112 225
113static int rt5677_spi_probe(struct spi_device *spi) 226static int rt5677_spi_probe(struct spi_device *spi)
114{ 227{
diff --git a/sound/soc/codecs/rt5677-spi.h b/sound/soc/codecs/rt5677-spi.h
index ec41b2b3b2ca..662db16cfb6a 100644
--- a/sound/soc/codecs/rt5677-spi.h
+++ b/sound/soc/codecs/rt5677-spi.h
@@ -12,10 +12,8 @@
12#ifndef __RT5677_SPI_H__ 12#ifndef __RT5677_SPI_H__
13#define __RT5677_SPI_H__ 13#define __RT5677_SPI_H__
14 14
15#define RT5677_SPI_BUF_LEN 240 15int rt5677_spi_read(u32 addr, void *rxbuf, size_t len);
16#define RT5677_SPI_CMD_BURST_WRITE 0x05 16int rt5677_spi_write(u32 addr, const void *txbuf, size_t len);
17 17int rt5677_spi_write_firmware(u32 addr, const struct firmware *fw);
18int rt5677_spi_write(u8 *txbuf, size_t len);
19int rt5677_spi_burst_write(u32 addr, const struct firmware *fw);
20 18
21#endif /* __RT5677_SPI_H__ */ 19#endif /* __RT5677_SPI_H__ */
diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c
index 31d969ac1192..b7de51b09c35 100644
--- a/sound/soc/codecs/rt5677.c
+++ b/sound/soc/codecs/rt5677.c
@@ -15,13 +15,12 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/pm.h> 17#include <linux/pm.h>
18#include <linux/of_gpio.h>
19#include <linux/regmap.h> 18#include <linux/regmap.h>
20#include <linux/i2c.h> 19#include <linux/i2c.h>
21#include <linux/platform_device.h> 20#include <linux/platform_device.h>
22#include <linux/spi/spi.h> 21#include <linux/spi/spi.h>
23#include <linux/firmware.h> 22#include <linux/firmware.h>
24#include <linux/gpio.h> 23#include <linux/property.h>
25#include <sound/core.h> 24#include <sound/core.h>
26#include <sound/pcm.h> 25#include <sound/pcm.h>
27#include <sound/pcm_params.h> 26#include <sound/pcm_params.h>
@@ -54,7 +53,7 @@ static const struct regmap_range_cfg rt5677_ranges[] = {
54 }, 53 },
55}; 54};
56 55
57static const struct reg_default init_list[] = { 56static const struct reg_sequence init_list[] = {
58 {RT5677_ASRC_12, 0x0018}, 57 {RT5677_ASRC_12, 0x0018},
59 {RT5677_PR_BASE + 0x3d, 0x364d}, 58 {RT5677_PR_BASE + 0x3d, 0x364d},
60 {RT5677_PR_BASE + 0x17, 0x4fc0}, 59 {RT5677_PR_BASE + 0x17, 0x4fc0},
@@ -746,14 +745,14 @@ static int rt5677_set_dsp_vad(struct snd_soc_codec *codec, bool on)
746 ret = request_firmware(&rt5677->fw1, RT5677_FIRMWARE1, 745 ret = request_firmware(&rt5677->fw1, RT5677_FIRMWARE1,
747 codec->dev); 746 codec->dev);
748 if (ret == 0) { 747 if (ret == 0) {
749 rt5677_spi_burst_write(0x50000000, rt5677->fw1); 748 rt5677_spi_write_firmware(0x50000000, rt5677->fw1);
750 release_firmware(rt5677->fw1); 749 release_firmware(rt5677->fw1);
751 } 750 }
752 751
753 ret = request_firmware(&rt5677->fw2, RT5677_FIRMWARE2, 752 ret = request_firmware(&rt5677->fw2, RT5677_FIRMWARE2,
754 codec->dev); 753 codec->dev);
755 if (ret == 0) { 754 if (ret == 0) {
756 rt5677_spi_burst_write(0x60000000, rt5677->fw2); 755 rt5677_spi_write_firmware(0x60000000, rt5677->fw2);
757 release_firmware(rt5677->fw2); 756 release_firmware(rt5677->fw2);
758 } 757 }
759 758
@@ -917,8 +916,11 @@ static int set_dmic_clk(struct snd_soc_dapm_widget *w,
917{ 916{
918 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); 917 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
919 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 918 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
920 int idx = rl6231_calc_dmic_clk(rt5677->lrck[RT5677_AIF1] << 8); 919 int idx, rate;
921 920
921 rate = rt5677->sysclk / rl6231_get_pre_div(rt5677->regmap,
922 RT5677_CLK_TREE_CTRL1, RT5677_I2S_PD1_SFT);
923 idx = rl6231_calc_dmic_clk(rate);
922 if (idx < 0) 924 if (idx < 0)
923 dev_err(codec->dev, "Failed to set DMIC clock\n"); 925 dev_err(codec->dev, "Failed to set DMIC clock\n");
924 else 926 else
@@ -4764,10 +4766,8 @@ static int rt5677_remove(struct snd_soc_codec *codec)
4764 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 4766 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
4765 4767
4766 regmap_write(rt5677->regmap, RT5677_RESET, 0x10ec); 4768 regmap_write(rt5677->regmap, RT5677_RESET, 0x10ec);
4767 if (gpio_is_valid(rt5677->pow_ldo2)) 4769 gpiod_set_value_cansleep(rt5677->pow_ldo2, 0);
4768 gpio_set_value_cansleep(rt5677->pow_ldo2, 0); 4770 gpiod_set_value_cansleep(rt5677->reset_pin, 0);
4769 if (gpio_is_valid(rt5677->reset_pin))
4770 gpio_set_value_cansleep(rt5677->reset_pin, 0);
4771 4771
4772 return 0; 4772 return 0;
4773} 4773}
@@ -4781,10 +4781,8 @@ static int rt5677_suspend(struct snd_soc_codec *codec)
4781 regcache_cache_only(rt5677->regmap, true); 4781 regcache_cache_only(rt5677->regmap, true);
4782 regcache_mark_dirty(rt5677->regmap); 4782 regcache_mark_dirty(rt5677->regmap);
4783 4783
4784 if (gpio_is_valid(rt5677->pow_ldo2)) 4784 gpiod_set_value_cansleep(rt5677->pow_ldo2, 0);
4785 gpio_set_value_cansleep(rt5677->pow_ldo2, 0); 4785 gpiod_set_value_cansleep(rt5677->reset_pin, 0);
4786 if (gpio_is_valid(rt5677->reset_pin))
4787 gpio_set_value_cansleep(rt5677->reset_pin, 0);
4788 } 4786 }
4789 4787
4790 return 0; 4788 return 0;
@@ -4795,12 +4793,9 @@ static int rt5677_resume(struct snd_soc_codec *codec)
4795 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 4793 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
4796 4794
4797 if (!rt5677->dsp_vad_en) { 4795 if (!rt5677->dsp_vad_en) {
4798 if (gpio_is_valid(rt5677->pow_ldo2)) 4796 gpiod_set_value_cansleep(rt5677->pow_ldo2, 1);
4799 gpio_set_value_cansleep(rt5677->pow_ldo2, 1); 4797 gpiod_set_value_cansleep(rt5677->reset_pin, 1);
4800 if (gpio_is_valid(rt5677->reset_pin)) 4798 if (rt5677->pow_ldo2 || rt5677->reset_pin)
4801 gpio_set_value_cansleep(rt5677->reset_pin, 1);
4802 if (gpio_is_valid(rt5677->pow_ldo2) ||
4803 gpio_is_valid(rt5677->reset_pin))
4804 msleep(10); 4799 msleep(10);
4805 4800
4806 regcache_cache_only(rt5677->regmap, false); 4801 regcache_cache_only(rt5677->regmap, false);
@@ -4863,7 +4858,7 @@ static int rt5677_write(void *context, unsigned int reg, unsigned int val)
4863#define RT5677_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 4858#define RT5677_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
4864 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8) 4859 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
4865 4860
4866static struct snd_soc_dai_ops rt5677_aif_dai_ops = { 4861static const struct snd_soc_dai_ops rt5677_aif_dai_ops = {
4867 .hw_params = rt5677_hw_params, 4862 .hw_params = rt5677_hw_params,
4868 .set_fmt = rt5677_set_dai_fmt, 4863 .set_fmt = rt5677_set_dai_fmt,
4869 .set_sysclk = rt5677_set_dai_sysclk, 4864 .set_sysclk = rt5677_set_dai_sysclk,
@@ -5024,45 +5019,29 @@ static const struct i2c_device_id rt5677_i2c_id[] = {
5024}; 5019};
5025MODULE_DEVICE_TABLE(i2c, rt5677_i2c_id); 5020MODULE_DEVICE_TABLE(i2c, rt5677_i2c_id);
5026 5021
5027static int rt5677_parse_dt(struct rt5677_priv *rt5677, struct device_node *np) 5022static void rt5677_read_device_properties(struct rt5677_priv *rt5677,
5023 struct device *dev)
5028{ 5024{
5029 rt5677->pdata.in1_diff = of_property_read_bool(np, 5025 rt5677->pdata.in1_diff = device_property_read_bool(dev,
5030 "realtek,in1-differential"); 5026 "realtek,in1-differential");
5031 rt5677->pdata.in2_diff = of_property_read_bool(np, 5027 rt5677->pdata.in2_diff = device_property_read_bool(dev,
5032 "realtek,in2-differential"); 5028 "realtek,in2-differential");
5033 rt5677->pdata.lout1_diff = of_property_read_bool(np, 5029 rt5677->pdata.lout1_diff = device_property_read_bool(dev,
5034 "realtek,lout1-differential"); 5030 "realtek,lout1-differential");
5035 rt5677->pdata.lout2_diff = of_property_read_bool(np, 5031 rt5677->pdata.lout2_diff = device_property_read_bool(dev,
5036 "realtek,lout2-differential"); 5032 "realtek,lout2-differential");
5037 rt5677->pdata.lout3_diff = of_property_read_bool(np, 5033 rt5677->pdata.lout3_diff = device_property_read_bool(dev,
5038 "realtek,lout3-differential"); 5034 "realtek,lout3-differential");
5039 5035
5040 rt5677->pow_ldo2 = of_get_named_gpio(np, 5036 device_property_read_u8_array(dev, "realtek,gpio-config",
5041 "realtek,pow-ldo2-gpio", 0); 5037 rt5677->pdata.gpio_config, RT5677_GPIO_NUM);
5042 rt5677->reset_pin = of_get_named_gpio(np, 5038
5043 "realtek,reset-gpio", 0); 5039 device_property_read_u32(dev, "realtek,jd1-gpio",
5044 5040 &rt5677->pdata.jd1_gpio);
5045 /* 5041 device_property_read_u32(dev, "realtek,jd2-gpio",
5046 * POW_LDO2 is optional (it may be statically tied on the board). 5042 &rt5677->pdata.jd2_gpio);
5047 * -ENOENT means that the property doesn't exist, i.e. there is no 5043 device_property_read_u32(dev, "realtek,jd3-gpio",
5048 * GPIO, so is not an error. Any other error code means the property 5044 &rt5677->pdata.jd3_gpio);
5049 * exists, but could not be parsed.
5050 */
5051 if (!gpio_is_valid(rt5677->pow_ldo2) &&
5052 (rt5677->pow_ldo2 != -ENOENT))
5053 return rt5677->pow_ldo2;
5054 if (!gpio_is_valid(rt5677->reset_pin) &&
5055 (rt5677->reset_pin != -ENOENT))
5056 return rt5677->reset_pin;
5057
5058 of_property_read_u8_array(np, "realtek,gpio-config",
5059 rt5677->pdata.gpio_config, RT5677_GPIO_NUM);
5060
5061 of_property_read_u32(np, "realtek,jd1-gpio", &rt5677->pdata.jd1_gpio);
5062 of_property_read_u32(np, "realtek,jd2-gpio", &rt5677->pdata.jd2_gpio);
5063 of_property_read_u32(np, "realtek,jd3-gpio", &rt5677->pdata.jd3_gpio);
5064
5065 return 0;
5066} 5045}
5067 5046
5068static struct regmap_irq rt5677_irqs[] = { 5047static struct regmap_irq rt5677_irqs[] = {
@@ -5145,43 +5124,29 @@ static int rt5677_i2c_probe(struct i2c_client *i2c,
5145 5124
5146 if (pdata) 5125 if (pdata)
5147 rt5677->pdata = *pdata; 5126 rt5677->pdata = *pdata;
5127 else
5128 rt5677_read_device_properties(rt5677, &i2c->dev);
5148 5129
5149 if (i2c->dev.of_node) { 5130 /* pow-ldo2 and reset are optional. The codec pins may be statically
5150 ret = rt5677_parse_dt(rt5677, i2c->dev.of_node); 5131 * connected on the board without gpios. If the gpio device property
5151 if (ret) { 5132 * isn't specified, devm_gpiod_get_optional returns NULL.
5152 dev_err(&i2c->dev, "Failed to parse device tree: %d\n", 5133 */
5153 ret); 5134 rt5677->pow_ldo2 = devm_gpiod_get_optional(&i2c->dev,
5154 return ret; 5135 "realtek,pow-ldo2", GPIOD_OUT_HIGH);
5155 } 5136 if (IS_ERR(rt5677->pow_ldo2)) {
5156 } else { 5137 ret = PTR_ERR(rt5677->pow_ldo2);
5157 rt5677->pow_ldo2 = -EINVAL; 5138 dev_err(&i2c->dev, "Failed to request POW_LDO2: %d\n", ret);
5158 rt5677->reset_pin = -EINVAL; 5139 return ret;
5159 }
5160
5161 if (gpio_is_valid(rt5677->pow_ldo2)) {
5162 ret = devm_gpio_request_one(&i2c->dev, rt5677->pow_ldo2,
5163 GPIOF_OUT_INIT_HIGH,
5164 "RT5677 POW_LDO2");
5165 if (ret < 0) {
5166 dev_err(&i2c->dev, "Failed to request POW_LDO2 %d: %d\n",
5167 rt5677->pow_ldo2, ret);
5168 return ret;
5169 }
5170 } 5140 }
5171 5141 rt5677->reset_pin = devm_gpiod_get_optional(&i2c->dev,
5172 if (gpio_is_valid(rt5677->reset_pin)) { 5142 "realtek,reset", GPIOD_OUT_HIGH);
5173 ret = devm_gpio_request_one(&i2c->dev, rt5677->reset_pin, 5143 if (IS_ERR(rt5677->reset_pin)) {
5174 GPIOF_OUT_INIT_HIGH, 5144 ret = PTR_ERR(rt5677->reset_pin);
5175 "RT5677 RESET"); 5145 dev_err(&i2c->dev, "Failed to request RESET: %d\n", ret);
5176 if (ret < 0) { 5146 return ret;
5177 dev_err(&i2c->dev, "Failed to request RESET %d: %d\n",
5178 rt5677->reset_pin, ret);
5179 return ret;
5180 }
5181 } 5147 }
5182 5148
5183 if (gpio_is_valid(rt5677->pow_ldo2) || 5149 if (rt5677->pow_ldo2 || rt5677->reset_pin) {
5184 gpio_is_valid(rt5677->reset_pin)) {
5185 /* Wait a while until I2C bus becomes available. The datasheet 5150 /* Wait a while until I2C bus becomes available. The datasheet
5186 * does not specify the exact we should wait but startup 5151 * does not specify the exact we should wait but startup
5187 * sequence mentiones at least a few milliseconds. 5152 * sequence mentiones at least a few milliseconds.
@@ -5209,7 +5174,7 @@ static int rt5677_i2c_probe(struct i2c_client *i2c,
5209 regmap_read(rt5677->regmap, RT5677_VENDOR_ID2, &val); 5174 regmap_read(rt5677->regmap, RT5677_VENDOR_ID2, &val);
5210 if (val != RT5677_DEVICE_ID) { 5175 if (val != RT5677_DEVICE_ID) {
5211 dev_err(&i2c->dev, 5176 dev_err(&i2c->dev,
5212 "Device with ID register %x is not rt5677\n", val); 5177 "Device with ID register %#x is not rt5677\n", val);
5213 return -ENODEV; 5178 return -ENODEV;
5214 } 5179 }
5215 5180
@@ -5273,7 +5238,6 @@ static int rt5677_i2c_remove(struct i2c_client *i2c)
5273static struct i2c_driver rt5677_i2c_driver = { 5238static struct i2c_driver rt5677_i2c_driver = {
5274 .driver = { 5239 .driver = {
5275 .name = "rt5677", 5240 .name = "rt5677",
5276 .owner = THIS_MODULE,
5277 }, 5241 },
5278 .probe = rt5677_i2c_probe, 5242 .probe = rt5677_i2c_probe,
5279 .remove = rt5677_i2c_remove, 5243 .remove = rt5677_i2c_remove,
diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h
index 7eca38a23255..d46855a42c40 100644
--- a/sound/soc/codecs/rt5677.h
+++ b/sound/soc/codecs/rt5677.h
@@ -14,6 +14,7 @@
14 14
15#include <sound/rt5677.h> 15#include <sound/rt5677.h>
16#include <linux/gpio/driver.h> 16#include <linux/gpio/driver.h>
17#include <linux/gpio/consumer.h>
17 18
18/* Info */ 19/* Info */
19#define RT5677_RESET 0x00 20#define RT5677_RESET 0x00
@@ -1775,8 +1776,8 @@ struct rt5677_priv {
1775 int pll_src; 1776 int pll_src;
1776 int pll_in; 1777 int pll_in;
1777 int pll_out; 1778 int pll_out;
1778 int pow_ldo2; /* POW_LDO2 pin */ 1779 struct gpio_desc *pow_ldo2; /* POW_LDO2 pin */
1779 int reset_pin; /* RESET pin */ 1780 struct gpio_desc *reset_pin; /* RESET pin */
1780 enum rt5677_type type; 1781 enum rt5677_type type;
1781#ifdef CONFIG_GPIOLIB 1782#ifdef CONFIG_GPIOLIB
1782 struct gpio_chip gpio_chip; 1783 struct gpio_chip gpio_chip;
diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index e673f6ceb521..f3e646757215 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -1601,7 +1601,6 @@ MODULE_DEVICE_TABLE(of, sgtl5000_dt_ids);
1601static struct i2c_driver sgtl5000_i2c_driver = { 1601static struct i2c_driver sgtl5000_i2c_driver = {
1602 .driver = { 1602 .driver = {
1603 .name = "sgtl5000", 1603 .name = "sgtl5000",
1604 .owner = THIS_MODULE,
1605 .of_match_table = sgtl5000_dt_ids, 1604 .of_match_table = sgtl5000_dt_ids,
1606 }, 1605 },
1607 .probe = sgtl5000_i2c_probe, 1606 .probe = sgtl5000_i2c_probe,
diff --git a/sound/soc/codecs/sgtl5000.h b/sound/soc/codecs/sgtl5000.h
index bd7a344bf8c5..1c317de26176 100644
--- a/sound/soc/codecs/sgtl5000.h
+++ b/sound/soc/codecs/sgtl5000.h
@@ -275,7 +275,7 @@
275#define SGTL5000_BIAS_CTRL_MASK 0x000e 275#define SGTL5000_BIAS_CTRL_MASK 0x000e
276#define SGTL5000_BIAS_CTRL_SHIFT 1 276#define SGTL5000_BIAS_CTRL_SHIFT 1
277#define SGTL5000_BIAS_CTRL_WIDTH 3 277#define SGTL5000_BIAS_CTRL_WIDTH 3
278#define SGTL5000_SMALL_POP 0 278#define SGTL5000_SMALL_POP 1
279 279
280/* 280/*
281 * SGTL5000_CHIP_MIC_CTRL 281 * SGTL5000_CHIP_MIC_CTRL
diff --git a/sound/soc/codecs/si476x.c b/sound/soc/codecs/si476x.c
index 3e72964280c6..a8402d0af0ea 100644
--- a/sound/soc/codecs/si476x.c
+++ b/sound/soc/codecs/si476x.c
@@ -208,7 +208,7 @@ out:
208 return err; 208 return err;
209} 209}
210 210
211static struct snd_soc_dai_ops si476x_dai_ops = { 211static const struct snd_soc_dai_ops si476x_dai_ops = {
212 .hw_params = si476x_codec_hw_params, 212 .hw_params = si476x_codec_hw_params,
213 .set_fmt = si476x_codec_set_dai_fmt, 213 .set_fmt = si476x_codec_set_dai_fmt,
214}; 214};
diff --git a/sound/soc/codecs/sirf-audio-codec.c b/sound/soc/codecs/sirf-audio-codec.c
index 29cb44256044..6bfd25c289d1 100644
--- a/sound/soc/codecs/sirf-audio-codec.c
+++ b/sound/soc/codecs/sirf-audio-codec.c
@@ -370,11 +370,11 @@ static int sirf_audio_codec_trigger(struct snd_pcm_substream *substream,
370 return 0; 370 return 0;
371} 371}
372 372
373struct snd_soc_dai_ops sirf_audio_codec_dai_ops = { 373static const struct snd_soc_dai_ops sirf_audio_codec_dai_ops = {
374 .trigger = sirf_audio_codec_trigger, 374 .trigger = sirf_audio_codec_trigger,
375}; 375};
376 376
377struct snd_soc_dai_driver sirf_audio_codec_dai = { 377static struct snd_soc_dai_driver sirf_audio_codec_dai = {
378 .name = "sirf-audio-codec", 378 .name = "sirf-audio-codec",
379 .playback = { 379 .playback = {
380 .stream_name = "Playback", 380 .stream_name = "Playback",
diff --git a/sound/soc/codecs/ssm2518.c b/sound/soc/codecs/ssm2518.c
index f30de7639bb9..ddb0203fc649 100644
--- a/sound/soc/codecs/ssm2518.c
+++ b/sound/soc/codecs/ssm2518.c
@@ -806,6 +806,14 @@ static int ssm2518_i2c_remove(struct i2c_client *client)
806 return 0; 806 return 0;
807} 807}
808 808
809#ifdef CONFIG_OF
810static const struct of_device_id ssm2518_dt_ids[] = {
811 { .compatible = "adi,ssm2518", },
812 { }
813};
814MODULE_DEVICE_TABLE(of, ssm2518_dt_ids);
815#endif
816
809static const struct i2c_device_id ssm2518_i2c_ids[] = { 817static const struct i2c_device_id ssm2518_i2c_ids[] = {
810 { "ssm2518", 0 }, 818 { "ssm2518", 0 },
811 { } 819 { }
@@ -815,7 +823,7 @@ MODULE_DEVICE_TABLE(i2c, ssm2518_i2c_ids);
815static struct i2c_driver ssm2518_driver = { 823static struct i2c_driver ssm2518_driver = {
816 .driver = { 824 .driver = {
817 .name = "ssm2518", 825 .name = "ssm2518",
818 .owner = THIS_MODULE, 826 .of_match_table = of_match_ptr(ssm2518_dt_ids),
819 }, 827 },
820 .probe = ssm2518_i2c_probe, 828 .probe = ssm2518_i2c_probe,
821 .remove = ssm2518_i2c_remove, 829 .remove = ssm2518_i2c_remove,
diff --git a/sound/soc/codecs/ssm2602-i2c.c b/sound/soc/codecs/ssm2602-i2c.c
index 0d9779d6bfda..173ba85ff59e 100644
--- a/sound/soc/codecs/ssm2602-i2c.c
+++ b/sound/soc/codecs/ssm2602-i2c.c
@@ -52,7 +52,6 @@ MODULE_DEVICE_TABLE(of, ssm2602_of_match);
52static struct i2c_driver ssm2602_i2c_driver = { 52static struct i2c_driver ssm2602_i2c_driver = {
53 .driver = { 53 .driver = {
54 .name = "ssm2602", 54 .name = "ssm2602",
55 .owner = THIS_MODULE,
56 .of_match_table = ssm2602_of_match, 55 .of_match_table = ssm2602_of_match,
57 }, 56 },
58 .probe = ssm2602_i2c_probe, 57 .probe = ssm2602_i2c_probe,
diff --git a/sound/soc/codecs/ssm4567.c b/sound/soc/codecs/ssm4567.c
index 938d2cb6d78b..e619d5651b09 100644
--- a/sound/soc/codecs/ssm4567.c
+++ b/sound/soc/codecs/ssm4567.c
@@ -10,6 +10,7 @@
10 * Licensed under the GPL-2. 10 * Licensed under the GPL-2.
11 */ 11 */
12 12
13#include <linux/acpi.h>
13#include <linux/module.h> 14#include <linux/module.h>
14#include <linux/init.h> 15#include <linux/init.h>
15#include <linux/i2c.h> 16#include <linux/i2c.h>
@@ -173,6 +174,12 @@ static const struct snd_soc_dapm_widget ssm4567_dapm_widgets[] = {
173 SND_SOC_DAPM_SWITCH("Amplifier Boost", SSM4567_REG_POWER_CTRL, 3, 1, 174 SND_SOC_DAPM_SWITCH("Amplifier Boost", SSM4567_REG_POWER_CTRL, 3, 1,
174 &ssm4567_amplifier_boost_control), 175 &ssm4567_amplifier_boost_control),
175 176
177 SND_SOC_DAPM_SIGGEN("Sense"),
178
179 SND_SOC_DAPM_PGA("Current Sense", SSM4567_REG_POWER_CTRL, 4, 1, NULL, 0),
180 SND_SOC_DAPM_PGA("Voltage Sense", SSM4567_REG_POWER_CTRL, 5, 1, NULL, 0),
181 SND_SOC_DAPM_PGA("VBAT Sense", SSM4567_REG_POWER_CTRL, 6, 1, NULL, 0),
182
176 SND_SOC_DAPM_OUTPUT("OUT"), 183 SND_SOC_DAPM_OUTPUT("OUT"),
177}; 184};
178 185
@@ -180,6 +187,13 @@ static const struct snd_soc_dapm_route ssm4567_routes[] = {
180 { "OUT", NULL, "Amplifier Boost" }, 187 { "OUT", NULL, "Amplifier Boost" },
181 { "Amplifier Boost", "Switch", "DAC" }, 188 { "Amplifier Boost", "Switch", "DAC" },
182 { "OUT", NULL, "DAC" }, 189 { "OUT", NULL, "DAC" },
190
191 { "Current Sense", NULL, "Sense" },
192 { "Voltage Sense", NULL, "Sense" },
193 { "VBAT Sense", NULL, "Sense" },
194 { "Capture Sense", NULL, "Current Sense" },
195 { "Capture Sense", NULL, "Voltage Sense" },
196 { "Capture Sense", NULL, "VBAT Sense" },
183}; 197};
184 198
185static int ssm4567_hw_params(struct snd_pcm_substream *substream, 199static int ssm4567_hw_params(struct snd_pcm_substream *substream,
@@ -315,7 +329,13 @@ static int ssm4567_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
315 if (invert_fclk) 329 if (invert_fclk)
316 ctrl1 |= SSM4567_SAI_CTRL_1_FSYNC; 330 ctrl1 |= SSM4567_SAI_CTRL_1_FSYNC;
317 331
318 return regmap_write(ssm4567->regmap, SSM4567_REG_SAI_CTRL_1, ctrl1); 332 return regmap_update_bits(ssm4567->regmap, SSM4567_REG_SAI_CTRL_1,
333 SSM4567_SAI_CTRL_1_BCLK |
334 SSM4567_SAI_CTRL_1_FSYNC |
335 SSM4567_SAI_CTRL_1_LJ |
336 SSM4567_SAI_CTRL_1_TDM |
337 SSM4567_SAI_CTRL_1_PDM,
338 ctrl1);
319} 339}
320 340
321static int ssm4567_set_power(struct ssm4567 *ssm4567, bool enable) 341static int ssm4567_set_power(struct ssm4567 *ssm4567, bool enable)
@@ -381,6 +401,14 @@ static struct snd_soc_dai_driver ssm4567_dai = {
381 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | 401 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |
382 SNDRV_PCM_FMTBIT_S32, 402 SNDRV_PCM_FMTBIT_S32,
383 }, 403 },
404 .capture = {
405 .stream_name = "Capture Sense",
406 .channels_min = 1,
407 .channels_max = 1,
408 .rates = SNDRV_PCM_RATE_8000_192000,
409 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |
410 SNDRV_PCM_FMTBIT_S32,
411 },
384 .ops = &ssm4567_dai_ops, 412 .ops = &ssm4567_dai_ops,
385}; 413};
386 414
@@ -450,10 +478,20 @@ static const struct i2c_device_id ssm4567_i2c_ids[] = {
450}; 478};
451MODULE_DEVICE_TABLE(i2c, ssm4567_i2c_ids); 479MODULE_DEVICE_TABLE(i2c, ssm4567_i2c_ids);
452 480
481#ifdef CONFIG_ACPI
482
483static const struct acpi_device_id ssm4567_acpi_match[] = {
484 { "INT343B", 0 },
485 {},
486};
487MODULE_DEVICE_TABLE(acpi, ssm4567_acpi_match);
488
489#endif
490
453static struct i2c_driver ssm4567_driver = { 491static struct i2c_driver ssm4567_driver = {
454 .driver = { 492 .driver = {
455 .name = "ssm4567", 493 .name = "ssm4567",
456 .owner = THIS_MODULE, 494 .acpi_match_table = ACPI_PTR(ssm4567_acpi_match),
457 }, 495 },
458 .probe = ssm4567_i2c_probe, 496 .probe = ssm4567_i2c_probe,
459 .remove = ssm4567_i2c_remove, 497 .remove = ssm4567_i2c_remove,
diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c
index 60eff36260cb..a9844b2ac829 100644
--- a/sound/soc/codecs/sta32x.c
+++ b/sound/soc/codecs/sta32x.c
@@ -1144,7 +1144,6 @@ MODULE_DEVICE_TABLE(i2c, sta32x_i2c_id);
1144static struct i2c_driver sta32x_i2c_driver = { 1144static struct i2c_driver sta32x_i2c_driver = {
1145 .driver = { 1145 .driver = {
1146 .name = "sta32x", 1146 .name = "sta32x",
1147 .owner = THIS_MODULE,
1148 .of_match_table = of_match_ptr(st32x_dt_ids), 1147 .of_match_table = of_match_ptr(st32x_dt_ids),
1149 }, 1148 },
1150 .probe = sta32x_i2c_probe, 1149 .probe = sta32x_i2c_probe,
diff --git a/sound/soc/codecs/sta350.c b/sound/soc/codecs/sta350.c
index bd819a3f205a..33a4612f0a07 100644
--- a/sound/soc/codecs/sta350.c
+++ b/sound/soc/codecs/sta350.c
@@ -1264,7 +1264,6 @@ MODULE_DEVICE_TABLE(i2c, sta350_i2c_id);
1264static struct i2c_driver sta350_i2c_driver = { 1264static struct i2c_driver sta350_i2c_driver = {
1265 .driver = { 1265 .driver = {
1266 .name = "sta350", 1266 .name = "sta350",
1267 .owner = THIS_MODULE,
1268 .of_match_table = of_match_ptr(st350_dt_ids), 1267 .of_match_table = of_match_ptr(st350_dt_ids),
1269 }, 1268 },
1270 .probe = sta350_i2c_probe, 1269 .probe = sta350_i2c_probe,
diff --git a/sound/soc/codecs/sta529.c b/sound/soc/codecs/sta529.c
index 4f70378b2cfb..2cdaca943a8c 100644
--- a/sound/soc/codecs/sta529.c
+++ b/sound/soc/codecs/sta529.c
@@ -339,9 +339,6 @@ static int sta529_i2c_probe(struct i2c_client *i2c,
339 struct sta529 *sta529; 339 struct sta529 *sta529;
340 int ret; 340 int ret;
341 341
342 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
343 return -EINVAL;
344
345 sta529 = devm_kzalloc(&i2c->dev, sizeof(struct sta529), GFP_KERNEL); 342 sta529 = devm_kzalloc(&i2c->dev, sizeof(struct sta529), GFP_KERNEL);
346 if (!sta529) 343 if (!sta529)
347 return -ENOMEM; 344 return -ENOMEM;
@@ -379,7 +376,6 @@ MODULE_DEVICE_TABLE(i2c, sta529_i2c_id);
379static struct i2c_driver sta529_i2c_driver = { 376static struct i2c_driver sta529_i2c_driver = {
380 .driver = { 377 .driver = {
381 .name = "sta529", 378 .name = "sta529",
382 .owner = THIS_MODULE,
383 }, 379 },
384 .probe = sta529_i2c_probe, 380 .probe = sta529_i2c_probe,
385 .remove = sta529_i2c_remove, 381 .remove = sta529_i2c_remove,
diff --git a/sound/soc/codecs/stac9766.c b/sound/soc/codecs/stac9766.c
index ed4cca7f6779..0945c51df003 100644
--- a/sound/soc/codecs/stac9766.c
+++ b/sound/soc/codecs/stac9766.c
@@ -28,6 +28,9 @@
28 28
29#include "stac9766.h" 29#include "stac9766.h"
30 30
31#define STAC9766_VENDOR_ID 0x83847666
32#define STAC9766_VENDOR_ID_MASK 0xffffffff
33
31/* 34/*
32 * STAC9766 register cache 35 * STAC9766 register cache
33 */ 36 */
@@ -239,45 +242,12 @@ static int stac9766_set_bias_level(struct snd_soc_codec *codec,
239 return 0; 242 return 0;
240} 243}
241 244
242static int stac9766_reset(struct snd_soc_codec *codec, int try_warm)
243{
244 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
245
246 if (try_warm && soc_ac97_ops->warm_reset) {
247 soc_ac97_ops->warm_reset(ac97);
248 if (stac9766_ac97_read(codec, 0) == stac9766_reg[0])
249 return 1;
250 }
251
252 soc_ac97_ops->reset(ac97);
253 if (soc_ac97_ops->warm_reset)
254 soc_ac97_ops->warm_reset(ac97);
255 if (stac9766_ac97_read(codec, 0) != stac9766_reg[0])
256 return -EIO;
257 return 0;
258}
259
260static int stac9766_codec_resume(struct snd_soc_codec *codec) 245static int stac9766_codec_resume(struct snd_soc_codec *codec)
261{ 246{
262 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec); 247 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
263 u16 id, reset;
264 248
265 reset = 0; 249 return snd_ac97_reset(ac97, true, STAC9766_VENDOR_ID,
266 /* give the codec an AC97 warm reset to start the link */ 250 STAC9766_VENDOR_ID_MASK);
267reset:
268 if (reset > 5) {
269 dev_err(codec->dev, "Failed to resume\n");
270 return -EIO;
271 }
272 ac97->bus->ops->warm_reset(ac97);
273 id = soc_ac97_ops->read(ac97, AC97_VENDOR_ID2);
274 if (id != 0x4c13) {
275 stac9766_reset(codec, 0);
276 reset++;
277 goto reset;
278 }
279
280 return 0;
281} 251}
282 252
283static const struct snd_soc_dai_ops stac9766_dai_ops_analog = { 253static const struct snd_soc_dai_ops stac9766_dai_ops_analog = {
@@ -330,28 +300,15 @@ static struct snd_soc_dai_driver stac9766_dai[] = {
330static int stac9766_codec_probe(struct snd_soc_codec *codec) 300static int stac9766_codec_probe(struct snd_soc_codec *codec)
331{ 301{
332 struct snd_ac97 *ac97; 302 struct snd_ac97 *ac97;
333 int ret = 0;
334 303
335 ac97 = snd_soc_new_ac97_codec(codec); 304 ac97 = snd_soc_new_ac97_codec(codec, STAC9766_VENDOR_ID,
305 STAC9766_VENDOR_ID_MASK);
336 if (IS_ERR(ac97)) 306 if (IS_ERR(ac97))
337 return PTR_ERR(ac97); 307 return PTR_ERR(ac97);
338 308
339 snd_soc_codec_set_drvdata(codec, ac97); 309 snd_soc_codec_set_drvdata(codec, ac97);
340 310
341 /* do a cold reset for the controller and then try
342 * a warm reset followed by an optional cold reset for codec */
343 stac9766_reset(codec, 0);
344 ret = stac9766_reset(codec, 1);
345 if (ret < 0) {
346 dev_err(codec->dev, "Failed to reset: AC97 link error\n");
347 goto codec_err;
348 }
349
350 return 0; 311 return 0;
351
352codec_err:
353 snd_soc_free_ac97_codec(ac97);
354 return ret;
355} 312}
356 313
357static int stac9766_codec_remove(struct snd_soc_codec *codec) 314static int stac9766_codec_remove(struct snd_soc_codec *codec)
diff --git a/sound/soc/codecs/tas2552.c b/sound/soc/codecs/tas2552.c
index 4f25a7d0efa2..2f6a65afe5d2 100644
--- a/sound/soc/codecs/tas2552.c
+++ b/sound/soc/codecs/tas2552.c
@@ -38,7 +38,7 @@
38 38
39#include "tas2552.h" 39#include "tas2552.h"
40 40
41static struct reg_default tas2552_reg_defs[] = { 41static const struct reg_default tas2552_reg_defs[] = {
42 {TAS2552_CFG_1, 0x22}, 42 {TAS2552_CFG_1, 0x22},
43 {TAS2552_CFG_3, 0x80}, 43 {TAS2552_CFG_3, 0x80},
44 {TAS2552_DOUT, 0x00}, 44 {TAS2552_DOUT, 0x00},
@@ -520,7 +520,7 @@ static const struct dev_pm_ops tas2552_pm = {
520 NULL) 520 NULL)
521}; 521};
522 522
523static struct snd_soc_dai_ops tas2552_speaker_dai_ops = { 523static const struct snd_soc_dai_ops tas2552_speaker_dai_ops = {
524 .hw_params = tas2552_hw_params, 524 .hw_params = tas2552_hw_params,
525 .prepare = tas2552_prepare, 525 .prepare = tas2552_prepare,
526 .set_sysclk = tas2552_set_dai_sysclk, 526 .set_sysclk = tas2552_set_dai_sysclk,
@@ -769,7 +769,6 @@ MODULE_DEVICE_TABLE(of, tas2552_of_match);
769static struct i2c_driver tas2552_i2c_driver = { 769static struct i2c_driver tas2552_i2c_driver = {
770 .driver = { 770 .driver = {
771 .name = "tas2552", 771 .name = "tas2552",
772 .owner = THIS_MODULE,
773 .of_match_table = of_match_ptr(tas2552_of_match), 772 .of_match_table = of_match_ptr(tas2552_of_match),
774 .pm = &tas2552_pm, 773 .pm = &tas2552_pm,
775 }, 774 },
diff --git a/sound/soc/codecs/tas5086.c b/sound/soc/codecs/tas5086.c
index 32942bed34b1..0a49fc851577 100644
--- a/sound/soc/codecs/tas5086.c
+++ b/sound/soc/codecs/tas5086.c
@@ -994,7 +994,6 @@ static int tas5086_i2c_remove(struct i2c_client *i2c)
994static struct i2c_driver tas5086_i2c_driver = { 994static struct i2c_driver tas5086_i2c_driver = {
995 .driver = { 995 .driver = {
996 .name = "tas5086", 996 .name = "tas5086",
997 .owner = THIS_MODULE,
998 .of_match_table = of_match_ptr(tas5086_dt_ids), 997 .of_match_table = of_match_ptr(tas5086_dt_ids),
999 }, 998 },
1000 .id_table = tas5086_i2c_id, 999 .id_table = tas5086_i2c_id,
diff --git a/sound/soc/codecs/tas571x.c b/sound/soc/codecs/tas571x.c
index 85bcc374c8e8..39307ad41a34 100644
--- a/sound/soc/codecs/tas571x.c
+++ b/sound/soc/codecs/tas571x.c
@@ -179,7 +179,7 @@ static int tas571x_set_bias_level(struct snd_soc_codec *codec,
179 case SND_SOC_BIAS_PREPARE: 179 case SND_SOC_BIAS_PREPARE:
180 break; 180 break;
181 case SND_SOC_BIAS_STANDBY: 181 case SND_SOC_BIAS_STANDBY:
182 if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 182 if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) {
183 if (!IS_ERR(priv->mclk)) { 183 if (!IS_ERR(priv->mclk)) {
184 ret = clk_prepare_enable(priv->mclk); 184 ret = clk_prepare_enable(priv->mclk);
185 if (ret) { 185 if (ret) {
diff --git a/sound/soc/codecs/tfa9879.c b/sound/soc/codecs/tfa9879.c
index aab0af681e8c..cb5310d89c0f 100644
--- a/sound/soc/codecs/tfa9879.c
+++ b/sound/soc/codecs/tfa9879.c
@@ -160,7 +160,7 @@ static int tfa9879_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
160 return 0; 160 return 0;
161} 161}
162 162
163static struct reg_default tfa9879_regs[] = { 163static const struct reg_default tfa9879_regs[] = {
164 { TFA9879_DEVICE_CONTROL, 0x0000 }, /* 0x00 */ 164 { TFA9879_DEVICE_CONTROL, 0x0000 }, /* 0x00 */
165 { TFA9879_SERIAL_INTERFACE_1, 0x0a18 }, /* 0x01 */ 165 { TFA9879_SERIAL_INTERFACE_1, 0x0a18 }, /* 0x01 */
166 { TFA9879_PCM_IOM2_FORMAT_1, 0x0007 }, /* 0x02 */ 166 { TFA9879_PCM_IOM2_FORMAT_1, 0x0007 }, /* 0x02 */
@@ -314,7 +314,6 @@ MODULE_DEVICE_TABLE(i2c, tfa9879_i2c_id);
314static struct i2c_driver tfa9879_i2c_driver = { 314static struct i2c_driver tfa9879_i2c_driver = {
315 .driver = { 315 .driver = {
316 .name = "tfa9879", 316 .name = "tfa9879",
317 .owner = THIS_MODULE,
318 }, 317 },
319 .probe = tfa9879_i2c_probe, 318 .probe = tfa9879_i2c_probe,
320 .remove = tfa9879_i2c_remove, 319 .remove = tfa9879_i2c_remove,
diff --git a/sound/soc/codecs/tlv320aic31xx.c b/sound/soc/codecs/tlv320aic31xx.c
index c4c960f592a1..ee4def4f819f 100644
--- a/sound/soc/codecs/tlv320aic31xx.c
+++ b/sound/soc/codecs/tlv320aic31xx.c
@@ -1121,7 +1121,7 @@ static struct snd_soc_codec_driver soc_codec_driver_aic31xx = {
1121 .num_dapm_routes = ARRAY_SIZE(aic31xx_audio_map), 1121 .num_dapm_routes = ARRAY_SIZE(aic31xx_audio_map),
1122}; 1122};
1123 1123
1124static struct snd_soc_dai_ops aic31xx_dai_ops = { 1124static const struct snd_soc_dai_ops aic31xx_dai_ops = {
1125 .hw_params = aic31xx_hw_params, 1125 .hw_params = aic31xx_hw_params,
1126 .set_sysclk = aic31xx_set_dai_sysclk, 1126 .set_sysclk = aic31xx_set_dai_sysclk,
1127 .set_fmt = aic31xx_set_dai_fmt, 1127 .set_fmt = aic31xx_set_dai_fmt,
@@ -1283,7 +1283,6 @@ MODULE_DEVICE_TABLE(i2c, aic31xx_i2c_id);
1283static struct i2c_driver aic31xx_i2c_driver = { 1283static struct i2c_driver aic31xx_i2c_driver = {
1284 .driver = { 1284 .driver = {
1285 .name = "tlv320aic31xx-codec", 1285 .name = "tlv320aic31xx-codec",
1286 .owner = THIS_MODULE,
1287 .of_match_table = of_match_ptr(tlv320aic31xx_of_match), 1286 .of_match_table = of_match_ptr(tlv320aic31xx_of_match),
1288 }, 1287 },
1289 .probe = aic31xx_i2c_probe, 1288 .probe = aic31xx_i2c_probe,
diff --git a/sound/soc/codecs/tlv320aic32x4.c b/sound/soc/codecs/tlv320aic32x4.c
index ad6cb90e5f9b..f2d3191961e1 100644
--- a/sound/soc/codecs/tlv320aic32x4.c
+++ b/sound/soc/codecs/tlv320aic32x4.c
@@ -871,7 +871,6 @@ MODULE_DEVICE_TABLE(of, aic32x4_of_id);
871static struct i2c_driver aic32x4_i2c_driver = { 871static struct i2c_driver aic32x4_i2c_driver = {
872 .driver = { 872 .driver = {
873 .name = "tlv320aic32x4", 873 .name = "tlv320aic32x4",
874 .owner = THIS_MODULE,
875 .of_match_table = aic32x4_of_id, 874 .of_match_table = aic32x4_of_id,
876 }, 875 },
877 .probe = aic32x4_i2c_probe, 876 .probe = aic32x4_i2c_probe,
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index a7cf19b53fb2..1a82b19b2644 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -1668,7 +1668,7 @@ static const struct i2c_device_id aic3x_i2c_id[] = {
1668}; 1668};
1669MODULE_DEVICE_TABLE(i2c, aic3x_i2c_id); 1669MODULE_DEVICE_TABLE(i2c, aic3x_i2c_id);
1670 1670
1671static const struct reg_default aic3007_class_d[] = { 1671static const struct reg_sequence aic3007_class_d[] = {
1672 /* Class-D speaker driver init; datasheet p. 46 */ 1672 /* Class-D speaker driver init; datasheet p. 46 */
1673 { AIC3X_PAGE_SELECT, 0x0D }, 1673 { AIC3X_PAGE_SELECT, 0x0D },
1674 { 0xD, 0x0D }, 1674 { 0xD, 0x0D },
@@ -1825,7 +1825,6 @@ MODULE_DEVICE_TABLE(of, tlv320aic3x_of_match);
1825static struct i2c_driver aic3x_i2c_driver = { 1825static struct i2c_driver aic3x_i2c_driver = {
1826 .driver = { 1826 .driver = {
1827 .name = "tlv320aic3x-codec", 1827 .name = "tlv320aic3x-codec",
1828 .owner = THIS_MODULE,
1829 .of_match_table = of_match_ptr(tlv320aic3x_of_match), 1828 .of_match_table = of_match_ptr(tlv320aic3x_of_match),
1830 }, 1829 },
1831 .probe = aic3x_i2c_probe, 1830 .probe = aic3x_i2c_probe,
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index d67a311f0e75..781398fb2841 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -1585,7 +1585,6 @@ MODULE_DEVICE_TABLE(i2c, tlv320dac33_i2c_id);
1585static struct i2c_driver tlv320dac33_i2c_driver = { 1585static struct i2c_driver tlv320dac33_i2c_driver = {
1586 .driver = { 1586 .driver = {
1587 .name = "tlv320dac33-codec", 1587 .name = "tlv320dac33-codec",
1588 .owner = THIS_MODULE,
1589 }, 1588 },
1590 .probe = dac33_i2c_probe, 1589 .probe = dac33_i2c_probe,
1591 .remove = dac33_i2c_remove, 1590 .remove = dac33_i2c_remove,
diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c
index 6fac9e034c48..265c4c38804d 100644
--- a/sound/soc/codecs/tpa6130a2.c
+++ b/sound/soc/codecs/tpa6130a2.c
@@ -488,7 +488,6 @@ MODULE_DEVICE_TABLE(of, tpa6130a2_of_match);
488static struct i2c_driver tpa6130a2_i2c_driver = { 488static struct i2c_driver tpa6130a2_i2c_driver = {
489 .driver = { 489 .driver = {
490 .name = "tpa6130a2", 490 .name = "tpa6130a2",
491 .owner = THIS_MODULE,
492 .of_match_table = of_match_ptr(tpa6130a2_of_match), 491 .of_match_table = of_match_ptr(tpa6130a2_of_match),
493 }, 492 },
494 .probe = tpa6130a2_probe, 493 .probe = tpa6130a2_probe,
diff --git a/sound/soc/codecs/ts3a227e.c b/sound/soc/codecs/ts3a227e.c
index 12232d7db4c5..43568435c208 100644
--- a/sound/soc/codecs/ts3a227e.c
+++ b/sound/soc/codecs/ts3a227e.c
@@ -23,11 +23,13 @@
23#include "ts3a227e.h" 23#include "ts3a227e.h"
24 24
25struct ts3a227e { 25struct ts3a227e {
26 struct device *dev;
26 struct regmap *regmap; 27 struct regmap *regmap;
27 struct snd_soc_jack *jack; 28 struct snd_soc_jack *jack;
28 bool plugged; 29 bool plugged;
29 bool mic_present; 30 bool mic_present;
30 unsigned int buttons_held; 31 unsigned int buttons_held;
32 int irq;
31}; 33};
32 34
33/* Button values to be reported on the jack */ 35/* Button values to be reported on the jack */
@@ -189,16 +191,28 @@ static irqreturn_t ts3a227e_interrupt(int irq, void *data)
189 struct ts3a227e *ts3a227e = (struct ts3a227e *)data; 191 struct ts3a227e *ts3a227e = (struct ts3a227e *)data;
190 struct regmap *regmap = ts3a227e->regmap; 192 struct regmap *regmap = ts3a227e->regmap;
191 unsigned int int_reg, kp_int_reg, acc_reg, i; 193 unsigned int int_reg, kp_int_reg, acc_reg, i;
194 struct device *dev = ts3a227e->dev;
195 int ret;
192 196
193 /* Check for plug/unplug. */ 197 /* Check for plug/unplug. */
194 regmap_read(regmap, TS3A227E_REG_INTERRUPT, &int_reg); 198 ret = regmap_read(regmap, TS3A227E_REG_INTERRUPT, &int_reg);
199 if (ret) {
200 dev_err(dev, "failed to clear interrupt ret=%d\n", ret);
201 return IRQ_NONE;
202 }
203
195 if (int_reg & (DETECTION_COMPLETE_EVENT | INS_REM_EVENT)) { 204 if (int_reg & (DETECTION_COMPLETE_EVENT | INS_REM_EVENT)) {
196 regmap_read(regmap, TS3A227E_REG_ACCESSORY_STATUS, &acc_reg); 205 regmap_read(regmap, TS3A227E_REG_ACCESSORY_STATUS, &acc_reg);
197 ts3a227e_new_jack_state(ts3a227e, acc_reg); 206 ts3a227e_new_jack_state(ts3a227e, acc_reg);
198 } 207 }
199 208
200 /* Report any key events. */ 209 /* Report any key events. */
201 regmap_read(regmap, TS3A227E_REG_KP_INTERRUPT, &kp_int_reg); 210 ret = regmap_read(regmap, TS3A227E_REG_KP_INTERRUPT, &kp_int_reg);
211 if (ret) {
212 dev_err(dev, "failed to clear key interrupt ret=%d\n", ret);
213 return IRQ_NONE;
214 }
215
202 for (i = 0; i < TS3A227E_NUM_BUTTONS; i++) { 216 for (i = 0; i < TS3A227E_NUM_BUTTONS; i++) {
203 if (kp_int_reg & PRESS_MASK(i)) 217 if (kp_int_reg & PRESS_MASK(i))
204 ts3a227e->buttons_held |= (1 << i); 218 ts3a227e->buttons_held |= (1 << i);
@@ -283,6 +297,8 @@ static int ts3a227e_i2c_probe(struct i2c_client *i2c,
283 return -ENOMEM; 297 return -ENOMEM;
284 298
285 i2c_set_clientdata(i2c, ts3a227e); 299 i2c_set_clientdata(i2c, ts3a227e);
300 ts3a227e->dev = dev;
301 ts3a227e->irq = i2c->irq;
286 302
287 ts3a227e->regmap = devm_regmap_init_i2c(i2c, &ts3a227e_regmap_config); 303 ts3a227e->regmap = devm_regmap_init_i2c(i2c, &ts3a227e_regmap_config);
288 if (IS_ERR(ts3a227e->regmap)) 304 if (IS_ERR(ts3a227e->regmap))
@@ -320,6 +336,32 @@ static int ts3a227e_i2c_probe(struct i2c_client *i2c,
320 return 0; 336 return 0;
321} 337}
322 338
339#ifdef CONFIG_PM_SLEEP
340static int ts3a227e_suspend(struct device *dev)
341{
342 struct ts3a227e *ts3a227e = dev_get_drvdata(dev);
343
344 dev_dbg(ts3a227e->dev, "suspend disable irq\n");
345 disable_irq(ts3a227e->irq);
346
347 return 0;
348}
349
350static int ts3a227e_resume(struct device *dev)
351{
352 struct ts3a227e *ts3a227e = dev_get_drvdata(dev);
353
354 dev_dbg(ts3a227e->dev, "resume enable irq\n");
355 enable_irq(ts3a227e->irq);
356
357 return 0;
358}
359#endif
360
361static const struct dev_pm_ops ts3a227e_pm = {
362 SET_SYSTEM_SLEEP_PM_OPS(ts3a227e_suspend, ts3a227e_resume)
363};
364
323static const struct i2c_device_id ts3a227e_i2c_ids[] = { 365static const struct i2c_device_id ts3a227e_i2c_ids[] = {
324 { "ts3a227e", 0 }, 366 { "ts3a227e", 0 },
325 { } 367 { }
@@ -335,7 +377,7 @@ MODULE_DEVICE_TABLE(of, ts3a227e_of_match);
335static struct i2c_driver ts3a227e_driver = { 377static struct i2c_driver ts3a227e_driver = {
336 .driver = { 378 .driver = {
337 .name = "ts3a227e", 379 .name = "ts3a227e",
338 .owner = THIS_MODULE, 380 .pm = &ts3a227e_pm,
339 .of_match_table = of_match_ptr(ts3a227e_of_match), 381 .of_match_table = of_match_ptr(ts3a227e_of_match),
340 }, 382 },
341 .probe = ts3a227e_i2c_probe, 383 .probe = ts3a227e_i2c_probe,
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c
index 6e159f59d219..5cafb16ccf1a 100644
--- a/sound/soc/codecs/uda1380.c
+++ b/sound/soc/codecs/uda1380.c
@@ -810,7 +810,6 @@ MODULE_DEVICE_TABLE(i2c, uda1380_i2c_id);
810static struct i2c_driver uda1380_i2c_driver = { 810static struct i2c_driver uda1380_i2c_driver = {
811 .driver = { 811 .driver = {
812 .name = "uda1380-codec", 812 .name = "uda1380-codec",
813 .owner = THIS_MODULE,
814 }, 813 },
815 .probe = uda1380_i2c_probe, 814 .probe = uda1380_i2c_probe,
816 .remove = uda1380_i2c_remove, 815 .remove = uda1380_i2c_remove,
diff --git a/sound/soc/codecs/wm1250-ev1.c b/sound/soc/codecs/wm1250-ev1.c
index 048f00568260..ec45c5b220b1 100644
--- a/sound/soc/codecs/wm1250-ev1.c
+++ b/sound/soc/codecs/wm1250-ev1.c
@@ -251,7 +251,6 @@ MODULE_DEVICE_TABLE(i2c, wm1250_ev1_i2c_id);
251static struct i2c_driver wm1250_ev1_i2c_driver = { 251static struct i2c_driver wm1250_ev1_i2c_driver = {
252 .driver = { 252 .driver = {
253 .name = "wm1250-ev1", 253 .name = "wm1250-ev1",
254 .owner = THIS_MODULE,
255 }, 254 },
256 .probe = wm1250_ev1_probe, 255 .probe = wm1250_ev1_probe,
257 .remove = wm1250_ev1_remove, 256 .remove = wm1250_ev1_remove,
diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c
index 21d5402e343f..786abd02b140 100644
--- a/sound/soc/codecs/wm2000.c
+++ b/sound/soc/codecs/wm2000.c
@@ -942,7 +942,6 @@ MODULE_DEVICE_TABLE(i2c, wm2000_i2c_id);
942static struct i2c_driver wm2000_i2c_driver = { 942static struct i2c_driver wm2000_i2c_driver = {
943 .driver = { 943 .driver = {
944 .name = "wm2000", 944 .name = "wm2000",
945 .owner = THIS_MODULE,
946 }, 945 },
947 .probe = wm2000_i2c_probe, 946 .probe = wm2000_i2c_probe,
948 .remove = wm2000_i2c_remove, 947 .remove = wm2000_i2c_remove,
diff --git a/sound/soc/codecs/wm2200.c b/sound/soc/codecs/wm2200.c
index c83083285e53..35199fc1f6ca 100644
--- a/sound/soc/codecs/wm2200.c
+++ b/sound/soc/codecs/wm2200.c
@@ -166,7 +166,7 @@ static const struct wm_adsp_region wm2200_dsp2_regions[] = {
166 { .type = WMFW_ADSP1_ZM, .base = WM2200_DSP2_ZM_BASE }, 166 { .type = WMFW_ADSP1_ZM, .base = WM2200_DSP2_ZM_BASE },
167}; 167};
168 168
169static struct reg_default wm2200_reg_defaults[] = { 169static const struct reg_default wm2200_reg_defaults[] = {
170 { 0x000B, 0x0000 }, /* R11 - Tone Generator 1 */ 170 { 0x000B, 0x0000 }, /* R11 - Tone Generator 1 */
171 { 0x0102, 0x0000 }, /* R258 - Clocking 3 */ 171 { 0x0102, 0x0000 }, /* R258 - Clocking 3 */
172 { 0x0103, 0x0011 }, /* R259 - Clocking 4 */ 172 { 0x0103, 0x0011 }, /* R259 - Clocking 4 */
@@ -897,7 +897,7 @@ static bool wm2200_readable_register(struct device *dev, unsigned int reg)
897 } 897 }
898} 898}
899 899
900static const struct reg_default wm2200_reva_patch[] = { 900static const struct reg_sequence wm2200_reva_patch[] = {
901 { 0x07, 0x0003 }, 901 { 0x07, 0x0003 },
902 { 0x102, 0x0200 }, 902 { 0x102, 0x0200 },
903 { 0x203, 0x0084 }, 903 { 0x203, 0x0084 },
@@ -2481,7 +2481,7 @@ static int wm2200_runtime_resume(struct device *dev)
2481} 2481}
2482#endif 2482#endif
2483 2483
2484static struct dev_pm_ops wm2200_pm = { 2484static const struct dev_pm_ops wm2200_pm = {
2485 SET_RUNTIME_PM_OPS(wm2200_runtime_suspend, wm2200_runtime_resume, 2485 SET_RUNTIME_PM_OPS(wm2200_runtime_suspend, wm2200_runtime_resume,
2486 NULL) 2486 NULL)
2487}; 2487};
@@ -2495,7 +2495,6 @@ MODULE_DEVICE_TABLE(i2c, wm2200_i2c_id);
2495static struct i2c_driver wm2200_i2c_driver = { 2495static struct i2c_driver wm2200_i2c_driver = {
2496 .driver = { 2496 .driver = {
2497 .name = "wm2200", 2497 .name = "wm2200",
2498 .owner = THIS_MODULE,
2499 .pm = &wm2200_pm, 2498 .pm = &wm2200_pm,
2500 }, 2499 },
2501 .probe = wm2200_i2c_probe, 2500 .probe = wm2200_i2c_probe,
diff --git a/sound/soc/codecs/wm5100.c b/sound/soc/codecs/wm5100.c
index 4c10cd88c1af..3695b1dcbaf7 100644
--- a/sound/soc/codecs/wm5100.c
+++ b/sound/soc/codecs/wm5100.c
@@ -1247,7 +1247,7 @@ static const struct snd_soc_dapm_route wm5100_dapm_routes[] = {
1247 { "PWM2", NULL, "PWM2 Driver" }, 1247 { "PWM2", NULL, "PWM2 Driver" },
1248}; 1248};
1249 1249
1250static const struct reg_default wm5100_reva_patches[] = { 1250static const struct reg_sequence wm5100_reva_patches[] = {
1251 { WM5100_AUDIO_IF_1_10, 0 }, 1251 { WM5100_AUDIO_IF_1_10, 0 },
1252 { WM5100_AUDIO_IF_1_11, 1 }, 1252 { WM5100_AUDIO_IF_1_11, 1 },
1253 { WM5100_AUDIO_IF_1_12, 2 }, 1253 { WM5100_AUDIO_IF_1_12, 2 },
@@ -2708,7 +2708,7 @@ static int wm5100_runtime_resume(struct device *dev)
2708} 2708}
2709#endif 2709#endif
2710 2710
2711static struct dev_pm_ops wm5100_pm = { 2711static const struct dev_pm_ops wm5100_pm = {
2712 SET_RUNTIME_PM_OPS(wm5100_runtime_suspend, wm5100_runtime_resume, 2712 SET_RUNTIME_PM_OPS(wm5100_runtime_suspend, wm5100_runtime_resume,
2713 NULL) 2713 NULL)
2714}; 2714};
@@ -2722,7 +2722,6 @@ MODULE_DEVICE_TABLE(i2c, wm5100_i2c_id);
2722static struct i2c_driver wm5100_i2c_driver = { 2722static struct i2c_driver wm5100_i2c_driver = {
2723 .driver = { 2723 .driver = {
2724 .name = "wm5100", 2724 .name = "wm5100",
2725 .owner = THIS_MODULE,
2726 .pm = &wm5100_pm, 2725 .pm = &wm5100_pm,
2727 }, 2726 },
2728 .probe = wm5100_i2c_probe, 2727 .probe = wm5100_i2c_probe,
diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
index d097f09e50f2..64637d1cf4e5 100644
--- a/sound/soc/codecs/wm5102.c
+++ b/sound/soc/codecs/wm5102.c
@@ -788,8 +788,7 @@ ARIZONA_MIXER_CONTROLS("EQ2", ARIZONA_EQ2MIX_INPUT_1_SOURCE),
788ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE), 788ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE),
789ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE), 789ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE),
790 790
791SND_SOC_BYTES("EQ1 Coefficients", ARIZONA_EQ1_3, 19), 791ARIZONA_EQ_CONTROL("EQ1 Coefficients", ARIZONA_EQ1_2),
792SOC_SINGLE("EQ1 Mode Switch", ARIZONA_EQ1_2, ARIZONA_EQ1_B1_MODE, 1, 0),
793SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT, 792SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT,
794 24, 0, eq_tlv), 793 24, 0, eq_tlv),
795SOC_SINGLE_TLV("EQ1 B2 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B2_GAIN_SHIFT, 794SOC_SINGLE_TLV("EQ1 B2 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B2_GAIN_SHIFT,
@@ -801,8 +800,7 @@ SOC_SINGLE_TLV("EQ1 B4 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B4_GAIN_SHIFT,
801SOC_SINGLE_TLV("EQ1 B5 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B5_GAIN_SHIFT, 800SOC_SINGLE_TLV("EQ1 B5 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B5_GAIN_SHIFT,
802 24, 0, eq_tlv), 801 24, 0, eq_tlv),
803 802
804SND_SOC_BYTES("EQ2 Coefficients", ARIZONA_EQ2_3, 19), 803ARIZONA_EQ_CONTROL("EQ2 Coefficients", ARIZONA_EQ2_2),
805SOC_SINGLE("EQ2 Mode Switch", ARIZONA_EQ2_2, ARIZONA_EQ2_B1_MODE, 1, 0),
806SOC_SINGLE_TLV("EQ2 B1 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B1_GAIN_SHIFT, 804SOC_SINGLE_TLV("EQ2 B1 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B1_GAIN_SHIFT,
807 24, 0, eq_tlv), 805 24, 0, eq_tlv),
808SOC_SINGLE_TLV("EQ2 B2 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B2_GAIN_SHIFT, 806SOC_SINGLE_TLV("EQ2 B2 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B2_GAIN_SHIFT,
@@ -814,8 +812,7 @@ SOC_SINGLE_TLV("EQ2 B4 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B4_GAIN_SHIFT,
814SOC_SINGLE_TLV("EQ2 B5 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B5_GAIN_SHIFT, 812SOC_SINGLE_TLV("EQ2 B5 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B5_GAIN_SHIFT,
815 24, 0, eq_tlv), 813 24, 0, eq_tlv),
816 814
817SND_SOC_BYTES("EQ3 Coefficients", ARIZONA_EQ3_3, 19), 815ARIZONA_EQ_CONTROL("EQ3 Coefficients", ARIZONA_EQ3_2),
818SOC_SINGLE("EQ3 Mode Switch", ARIZONA_EQ3_2, ARIZONA_EQ3_B1_MODE, 1, 0),
819SOC_SINGLE_TLV("EQ3 B1 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B1_GAIN_SHIFT, 816SOC_SINGLE_TLV("EQ3 B1 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B1_GAIN_SHIFT,
820 24, 0, eq_tlv), 817 24, 0, eq_tlv),
821SOC_SINGLE_TLV("EQ3 B2 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B2_GAIN_SHIFT, 818SOC_SINGLE_TLV("EQ3 B2 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B2_GAIN_SHIFT,
@@ -827,8 +824,7 @@ SOC_SINGLE_TLV("EQ3 B4 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B4_GAIN_SHIFT,
827SOC_SINGLE_TLV("EQ3 B5 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B5_GAIN_SHIFT, 824SOC_SINGLE_TLV("EQ3 B5 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B5_GAIN_SHIFT,
828 24, 0, eq_tlv), 825 24, 0, eq_tlv),
829 826
830SND_SOC_BYTES("EQ4 Coefficients", ARIZONA_EQ4_3, 19), 827ARIZONA_EQ_CONTROL("EQ4 Coefficients", ARIZONA_EQ4_2),
831SOC_SINGLE("EQ4 Mode Switch", ARIZONA_EQ4_2, ARIZONA_EQ4_B1_MODE, 1, 0),
832SOC_SINGLE_TLV("EQ4 B1 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B1_GAIN_SHIFT, 828SOC_SINGLE_TLV("EQ4 B1 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B1_GAIN_SHIFT,
833 24, 0, eq_tlv), 829 24, 0, eq_tlv),
834SOC_SINGLE_TLV("EQ4 B2 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B2_GAIN_SHIFT, 830SOC_SINGLE_TLV("EQ4 B2 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B2_GAIN_SHIFT,
@@ -851,10 +847,10 @@ ARIZONA_MIXER_CONTROLS("LHPF2", ARIZONA_HPLP2MIX_INPUT_1_SOURCE),
851ARIZONA_MIXER_CONTROLS("LHPF3", ARIZONA_HPLP3MIX_INPUT_1_SOURCE), 847ARIZONA_MIXER_CONTROLS("LHPF3", ARIZONA_HPLP3MIX_INPUT_1_SOURCE),
852ARIZONA_MIXER_CONTROLS("LHPF4", ARIZONA_HPLP4MIX_INPUT_1_SOURCE), 848ARIZONA_MIXER_CONTROLS("LHPF4", ARIZONA_HPLP4MIX_INPUT_1_SOURCE),
853 849
854SND_SOC_BYTES("LHPF1 Coefficients", ARIZONA_HPLPF1_2, 1), 850ARIZONA_LHPF_CONTROL("LHPF1 Coefficients", ARIZONA_HPLPF1_2),
855SND_SOC_BYTES("LHPF2 Coefficients", ARIZONA_HPLPF2_2, 1), 851ARIZONA_LHPF_CONTROL("LHPF2 Coefficients", ARIZONA_HPLPF2_2),
856SND_SOC_BYTES("LHPF3 Coefficients", ARIZONA_HPLPF3_2, 1), 852ARIZONA_LHPF_CONTROL("LHPF3 Coefficients", ARIZONA_HPLPF3_2),
857SND_SOC_BYTES("LHPF4 Coefficients", ARIZONA_HPLPF4_2, 1), 853ARIZONA_LHPF_CONTROL("LHPF4 Coefficients", ARIZONA_HPLPF4_2),
858 854
859ARIZONA_MIXER_CONTROLS("DSP1L", ARIZONA_DSP1LMIX_INPUT_1_SOURCE), 855ARIZONA_MIXER_CONTROLS("DSP1L", ARIZONA_DSP1LMIX_INPUT_1_SOURCE),
860ARIZONA_MIXER_CONTROLS("DSP1R", ARIZONA_DSP1RMIX_INPUT_1_SOURCE), 856ARIZONA_MIXER_CONTROLS("DSP1R", ARIZONA_DSP1RMIX_INPUT_1_SOURCE),
@@ -1883,7 +1879,7 @@ static int wm5102_codec_probe(struct snd_soc_codec *codec)
1883 ret = snd_soc_add_codec_controls(codec, 1879 ret = snd_soc_add_codec_controls(codec,
1884 arizona_adsp2_rate_controls, 1); 1880 arizona_adsp2_rate_controls, 1);
1885 if (ret) 1881 if (ret)
1886 return ret; 1882 goto err_adsp2_codec_probe;
1887 1883
1888 arizona_init_spk(codec); 1884 arizona_init_spk(codec);
1889 arizona_init_gpio(codec); 1885 arizona_init_gpio(codec);
@@ -1893,6 +1889,11 @@ static int wm5102_codec_probe(struct snd_soc_codec *codec)
1893 priv->core.arizona->dapm = dapm; 1889 priv->core.arizona->dapm = dapm;
1894 1890
1895 return 0; 1891 return 0;
1892
1893err_adsp2_codec_probe:
1894 wm_adsp2_codec_remove(&priv->core.adsp[0], codec);
1895
1896 return ret;
1896} 1897}
1897 1898
1898static int wm5102_codec_remove(struct snd_soc_codec *codec) 1899static int wm5102_codec_remove(struct snd_soc_codec *codec)
diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c
index 709fcc6169d8..2d1168c768d9 100644
--- a/sound/soc/codecs/wm5110.c
+++ b/sound/soc/codecs/wm5110.c
@@ -247,8 +247,7 @@ ARIZONA_MIXER_CONTROLS("EQ2", ARIZONA_EQ2MIX_INPUT_1_SOURCE),
247ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE), 247ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE),
248ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE), 248ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE),
249 249
250SND_SOC_BYTES("EQ1 Coefficients", ARIZONA_EQ1_3, 19), 250ARIZONA_EQ_CONTROL("EQ1 Coefficients", ARIZONA_EQ1_2),
251SOC_SINGLE("EQ1 Mode Switch", ARIZONA_EQ1_2, ARIZONA_EQ1_B1_MODE, 1, 0),
252SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT, 251SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT,
253 24, 0, eq_tlv), 252 24, 0, eq_tlv),
254SOC_SINGLE_TLV("EQ1 B2 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B2_GAIN_SHIFT, 253SOC_SINGLE_TLV("EQ1 B2 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B2_GAIN_SHIFT,
@@ -260,8 +259,7 @@ SOC_SINGLE_TLV("EQ1 B4 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B4_GAIN_SHIFT,
260SOC_SINGLE_TLV("EQ1 B5 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B5_GAIN_SHIFT, 259SOC_SINGLE_TLV("EQ1 B5 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B5_GAIN_SHIFT,
261 24, 0, eq_tlv), 260 24, 0, eq_tlv),
262 261
263SND_SOC_BYTES("EQ2 Coefficients", ARIZONA_EQ2_3, 19), 262ARIZONA_EQ_CONTROL("EQ2 Coefficients", ARIZONA_EQ2_2),
264SOC_SINGLE("EQ2 Mode Switch", ARIZONA_EQ2_2, ARIZONA_EQ2_B1_MODE, 1, 0),
265SOC_SINGLE_TLV("EQ2 B1 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B1_GAIN_SHIFT, 263SOC_SINGLE_TLV("EQ2 B1 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B1_GAIN_SHIFT,
266 24, 0, eq_tlv), 264 24, 0, eq_tlv),
267SOC_SINGLE_TLV("EQ2 B2 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B2_GAIN_SHIFT, 265SOC_SINGLE_TLV("EQ2 B2 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B2_GAIN_SHIFT,
@@ -273,8 +271,7 @@ SOC_SINGLE_TLV("EQ2 B4 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B4_GAIN_SHIFT,
273SOC_SINGLE_TLV("EQ2 B5 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B5_GAIN_SHIFT, 271SOC_SINGLE_TLV("EQ2 B5 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B5_GAIN_SHIFT,
274 24, 0, eq_tlv), 272 24, 0, eq_tlv),
275 273
276SND_SOC_BYTES("EQ3 Coefficients", ARIZONA_EQ3_3, 19), 274ARIZONA_EQ_CONTROL("EQ3 Coefficients", ARIZONA_EQ3_2),
277SOC_SINGLE("EQ3 Mode Switch", ARIZONA_EQ3_2, ARIZONA_EQ3_B1_MODE, 1, 0),
278SOC_SINGLE_TLV("EQ3 B1 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B1_GAIN_SHIFT, 275SOC_SINGLE_TLV("EQ3 B1 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B1_GAIN_SHIFT,
279 24, 0, eq_tlv), 276 24, 0, eq_tlv),
280SOC_SINGLE_TLV("EQ3 B2 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B2_GAIN_SHIFT, 277SOC_SINGLE_TLV("EQ3 B2 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B2_GAIN_SHIFT,
@@ -286,8 +283,7 @@ SOC_SINGLE_TLV("EQ3 B4 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B4_GAIN_SHIFT,
286SOC_SINGLE_TLV("EQ3 B5 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B5_GAIN_SHIFT, 283SOC_SINGLE_TLV("EQ3 B5 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B5_GAIN_SHIFT,
287 24, 0, eq_tlv), 284 24, 0, eq_tlv),
288 285
289SND_SOC_BYTES("EQ4 Coefficients", ARIZONA_EQ4_3, 19), 286ARIZONA_EQ_CONTROL("EQ4 Coefficients", ARIZONA_EQ4_2),
290SOC_SINGLE("EQ4 Mode Switch", ARIZONA_EQ4_2, ARIZONA_EQ4_B1_MODE, 1, 0),
291SOC_SINGLE_TLV("EQ4 B1 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B1_GAIN_SHIFT, 287SOC_SINGLE_TLV("EQ4 B1 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B1_GAIN_SHIFT,
292 24, 0, eq_tlv), 288 24, 0, eq_tlv),
293SOC_SINGLE_TLV("EQ4 B2 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B2_GAIN_SHIFT, 289SOC_SINGLE_TLV("EQ4 B2 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B2_GAIN_SHIFT,
@@ -314,10 +310,10 @@ ARIZONA_MIXER_CONTROLS("LHPF2", ARIZONA_HPLP2MIX_INPUT_1_SOURCE),
314ARIZONA_MIXER_CONTROLS("LHPF3", ARIZONA_HPLP3MIX_INPUT_1_SOURCE), 310ARIZONA_MIXER_CONTROLS("LHPF3", ARIZONA_HPLP3MIX_INPUT_1_SOURCE),
315ARIZONA_MIXER_CONTROLS("LHPF4", ARIZONA_HPLP4MIX_INPUT_1_SOURCE), 311ARIZONA_MIXER_CONTROLS("LHPF4", ARIZONA_HPLP4MIX_INPUT_1_SOURCE),
316 312
317SND_SOC_BYTES("LHPF1 Coefficients", ARIZONA_HPLPF1_2, 1), 313ARIZONA_LHPF_CONTROL("LHPF1 Coefficients", ARIZONA_HPLPF1_2),
318SND_SOC_BYTES("LHPF2 Coefficients", ARIZONA_HPLPF2_2, 1), 314ARIZONA_LHPF_CONTROL("LHPF2 Coefficients", ARIZONA_HPLPF2_2),
319SND_SOC_BYTES("LHPF3 Coefficients", ARIZONA_HPLPF3_2, 1), 315ARIZONA_LHPF_CONTROL("LHPF3 Coefficients", ARIZONA_HPLPF3_2),
320SND_SOC_BYTES("LHPF4 Coefficients", ARIZONA_HPLPF4_2, 1), 316ARIZONA_LHPF_CONTROL("LHPF4 Coefficients", ARIZONA_HPLPF4_2),
321 317
322SOC_ENUM("LHPF1 Mode", arizona_lhpf1_mode), 318SOC_ENUM("LHPF1 Mode", arizona_lhpf1_mode),
323SOC_ENUM("LHPF2 Mode", arizona_lhpf2_mode), 319SOC_ENUM("LHPF2 Mode", arizona_lhpf2_mode),
@@ -1611,18 +1607,24 @@ static int wm5110_codec_probe(struct snd_soc_codec *codec)
1611 for (i = 0; i < WM5110_NUM_ADSP; ++i) { 1607 for (i = 0; i < WM5110_NUM_ADSP; ++i) {
1612 ret = wm_adsp2_codec_probe(&priv->core.adsp[i], codec); 1608 ret = wm_adsp2_codec_probe(&priv->core.adsp[i], codec);
1613 if (ret) 1609 if (ret)
1614 return ret; 1610 goto err_adsp2_codec_probe;
1615 } 1611 }
1616 1612
1617 ret = snd_soc_add_codec_controls(codec, 1613 ret = snd_soc_add_codec_controls(codec,
1618 arizona_adsp2_rate_controls, 1614 arizona_adsp2_rate_controls,
1619 WM5110_NUM_ADSP); 1615 WM5110_NUM_ADSP);
1620 if (ret) 1616 if (ret)
1621 return ret; 1617 goto err_adsp2_codec_probe;
1622 1618
1623 snd_soc_dapm_disable_pin(dapm, "HAPTICS"); 1619 snd_soc_dapm_disable_pin(dapm, "HAPTICS");
1624 1620
1625 return 0; 1621 return 0;
1622
1623err_adsp2_codec_probe:
1624 for (--i; i >= 0; --i)
1625 wm_adsp2_codec_remove(&priv->core.adsp[i], codec);
1626
1627 return ret;
1626} 1628}
1627 1629
1628static int wm5110_codec_remove(struct snd_soc_codec *codec) 1630static int wm5110_codec_remove(struct snd_soc_codec *codec)
diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c
index dac5beb4d023..b098a83a44d8 100644
--- a/sound/soc/codecs/wm8510.c
+++ b/sound/soc/codecs/wm8510.c
@@ -598,6 +598,7 @@ static const struct of_device_id wm8510_of_match[] = {
598 { .compatible = "wlf,wm8510" }, 598 { .compatible = "wlf,wm8510" },
599 { }, 599 { },
600}; 600};
601MODULE_DEVICE_TABLE(of, wm8510_of_match);
601 602
602static const struct regmap_config wm8510_regmap = { 603static const struct regmap_config wm8510_regmap = {
603 .reg_bits = 7, 604 .reg_bits = 7,
@@ -690,7 +691,6 @@ MODULE_DEVICE_TABLE(i2c, wm8510_i2c_id);
690static struct i2c_driver wm8510_i2c_driver = { 691static struct i2c_driver wm8510_i2c_driver = {
691 .driver = { 692 .driver = {
692 .name = "wm8510", 693 .name = "wm8510",
693 .owner = THIS_MODULE,
694 .of_match_table = wm8510_of_match, 694 .of_match_table = wm8510_of_match,
695 }, 695 },
696 .probe = wm8510_i2c_probe, 696 .probe = wm8510_i2c_probe,
diff --git a/sound/soc/codecs/wm8523.c b/sound/soc/codecs/wm8523.c
index 43ea8ae5f871..aa287a3965e7 100644
--- a/sound/soc/codecs/wm8523.c
+++ b/sound/soc/codecs/wm8523.c
@@ -430,6 +430,7 @@ static const struct of_device_id wm8523_of_match[] = {
430 { .compatible = "wlf,wm8523" }, 430 { .compatible = "wlf,wm8523" },
431 { }, 431 { },
432}; 432};
433MODULE_DEVICE_TABLE(of, wm8523_of_match);
433 434
434static const struct regmap_config wm8523_regmap = { 435static const struct regmap_config wm8523_regmap = {
435 .reg_bits = 8, 436 .reg_bits = 8,
@@ -534,7 +535,6 @@ MODULE_DEVICE_TABLE(i2c, wm8523_i2c_id);
534static struct i2c_driver wm8523_i2c_driver = { 535static struct i2c_driver wm8523_i2c_driver = {
535 .driver = { 536 .driver = {
536 .name = "wm8523", 537 .name = "wm8523",
537 .owner = THIS_MODULE,
538 .of_match_table = wm8523_of_match, 538 .of_match_table = wm8523_of_match,
539 }, 539 },
540 .probe = wm8523_i2c_probe, 540 .probe = wm8523_i2c_probe,
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c
index 759a7928ac3e..66602bf02f6e 100644
--- a/sound/soc/codecs/wm8580.c
+++ b/sound/soc/codecs/wm8580.c
@@ -916,6 +916,7 @@ static const struct of_device_id wm8580_of_match[] = {
916 { .compatible = "wlf,wm8580" }, 916 { .compatible = "wlf,wm8580" },
917 { }, 917 { },
918}; 918};
919MODULE_DEVICE_TABLE(of, wm8580_of_match);
919 920
920static const struct regmap_config wm8580_regmap = { 921static const struct regmap_config wm8580_regmap = {
921 .reg_bits = 7, 922 .reg_bits = 7,
@@ -978,7 +979,6 @@ MODULE_DEVICE_TABLE(i2c, wm8580_i2c_id);
978static struct i2c_driver wm8580_i2c_driver = { 979static struct i2c_driver wm8580_i2c_driver = {
979 .driver = { 980 .driver = {
980 .name = "wm8580", 981 .name = "wm8580",
981 .owner = THIS_MODULE,
982 .of_match_table = wm8580_of_match, 982 .of_match_table = wm8580_of_match,
983 }, 983 },
984 .probe = wm8580_i2c_probe, 984 .probe = wm8580_i2c_probe,
diff --git a/sound/soc/codecs/wm8711.c b/sound/soc/codecs/wm8711.c
index cc8251f09f8a..44b9e0ae7451 100644
--- a/sound/soc/codecs/wm8711.c
+++ b/sound/soc/codecs/wm8711.c
@@ -478,7 +478,6 @@ MODULE_DEVICE_TABLE(i2c, wm8711_i2c_id);
478static struct i2c_driver wm8711_i2c_driver = { 478static struct i2c_driver wm8711_i2c_driver = {
479 .driver = { 479 .driver = {
480 .name = "wm8711", 480 .name = "wm8711",
481 .owner = THIS_MODULE,
482 .of_match_table = wm8711_of_match, 481 .of_match_table = wm8711_of_match,
483 }, 482 },
484 .probe = wm8711_i2c_probe, 483 .probe = wm8711_i2c_probe,
diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c
index f1a173e6ec33..cd7b02413ccf 100644
--- a/sound/soc/codecs/wm8728.c
+++ b/sound/soc/codecs/wm8728.c
@@ -319,7 +319,6 @@ MODULE_DEVICE_TABLE(i2c, wm8728_i2c_id);
319static struct i2c_driver wm8728_i2c_driver = { 319static struct i2c_driver wm8728_i2c_driver = {
320 .driver = { 320 .driver = {
321 .name = "wm8728", 321 .name = "wm8728",
322 .owner = THIS_MODULE,
323 .of_match_table = wm8728_of_match, 322 .of_match_table = wm8728_of_match,
324 }, 323 },
325 .probe = wm8728_i2c_probe, 324 .probe = wm8728_i2c_probe,
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index 915ea11ad4b6..4846842522f3 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -789,7 +789,6 @@ MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id);
789static struct i2c_driver wm8731_i2c_driver = { 789static struct i2c_driver wm8731_i2c_driver = {
790 .driver = { 790 .driver = {
791 .name = "wm8731", 791 .name = "wm8731",
792 .owner = THIS_MODULE,
793 .of_match_table = wm8731_of_match, 792 .of_match_table = wm8731_of_match,
794 }, 793 },
795 .probe = wm8731_i2c_probe, 794 .probe = wm8731_i2c_probe,
diff --git a/sound/soc/codecs/wm8737.c b/sound/soc/codecs/wm8737.c
index 6ad606fd8b69..b54a7b78f562 100644
--- a/sound/soc/codecs/wm8737.c
+++ b/sound/soc/codecs/wm8737.c
@@ -657,7 +657,6 @@ MODULE_DEVICE_TABLE(i2c, wm8737_i2c_id);
657static struct i2c_driver wm8737_i2c_driver = { 657static struct i2c_driver wm8737_i2c_driver = {
658 .driver = { 658 .driver = {
659 .name = "wm8737", 659 .name = "wm8737",
660 .owner = THIS_MODULE,
661 .of_match_table = wm8737_of_match, 660 .of_match_table = wm8737_of_match,
662 }, 661 },
663 .probe = wm8737_i2c_probe, 662 .probe = wm8737_i2c_probe,
diff --git a/sound/soc/codecs/wm8741.c b/sound/soc/codecs/wm8741.c
index b34623786e35..430fa7ded713 100644
--- a/sound/soc/codecs/wm8741.c
+++ b/sound/soc/codecs/wm8741.c
@@ -633,7 +633,6 @@ MODULE_DEVICE_TABLE(i2c, wm8741_i2c_id);
633static struct i2c_driver wm8741_i2c_driver = { 633static struct i2c_driver wm8741_i2c_driver = {
634 .driver = { 634 .driver = {
635 .name = "wm8741", 635 .name = "wm8741",
636 .owner = THIS_MODULE,
637 .of_match_table = wm8741_of_match, 636 .of_match_table = wm8741_of_match,
638 }, 637 },
639 .probe = wm8741_i2c_probe, 638 .probe = wm8741_i2c_probe,
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c
index 56d89b0865fa..873933a7966f 100644
--- a/sound/soc/codecs/wm8750.c
+++ b/sound/soc/codecs/wm8750.c
@@ -826,7 +826,6 @@ MODULE_DEVICE_TABLE(i2c, wm8750_i2c_id);
826static struct i2c_driver wm8750_i2c_driver = { 826static struct i2c_driver wm8750_i2c_driver = {
827 .driver = { 827 .driver = {
828 .name = "wm8750", 828 .name = "wm8750",
829 .owner = THIS_MODULE,
830 .of_match_table = wm8750_of_match, 829 .of_match_table = wm8750_of_match,
831 }, 830 },
832 .probe = wm8750_i2c_probe, 831 .probe = wm8750_i2c_probe,
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index feb2997a377a..b5e50ffbf99f 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -1609,7 +1609,6 @@ MODULE_DEVICE_TABLE(i2c, wm8753_i2c_id);
1609static struct i2c_driver wm8753_i2c_driver = { 1609static struct i2c_driver wm8753_i2c_driver = {
1610 .driver = { 1610 .driver = {
1611 .name = "wm8753", 1611 .name = "wm8753",
1612 .owner = THIS_MODULE,
1613 .of_match_table = wm8753_of_match, 1612 .of_match_table = wm8753_of_match,
1614 }, 1613 },
1615 .probe = wm8753_i2c_probe, 1614 .probe = wm8753_i2c_probe,
diff --git a/sound/soc/codecs/wm8776.c b/sound/soc/codecs/wm8776.c
index ece9b4456767..592866dd60c7 100644
--- a/sound/soc/codecs/wm8776.c
+++ b/sound/soc/codecs/wm8776.c
@@ -536,7 +536,6 @@ MODULE_DEVICE_TABLE(i2c, wm8776_i2c_id);
536static struct i2c_driver wm8776_i2c_driver = { 536static struct i2c_driver wm8776_i2c_driver = {
537 .driver = { 537 .driver = {
538 .name = "wm8776", 538 .name = "wm8776",
539 .owner = THIS_MODULE,
540 .of_match_table = wm8776_of_match, 539 .of_match_table = wm8776_of_match,
541 }, 540 },
542 .probe = wm8776_i2c_probe, 541 .probe = wm8776_i2c_probe,
diff --git a/sound/soc/codecs/wm8804-i2c.c b/sound/soc/codecs/wm8804-i2c.c
index 6596f5f3a0c3..f27464c2c5ba 100644
--- a/sound/soc/codecs/wm8804-i2c.c
+++ b/sound/soc/codecs/wm8804-i2c.c
@@ -49,7 +49,6 @@ MODULE_DEVICE_TABLE(of, wm8804_of_match);
49static struct i2c_driver wm8804_i2c_driver = { 49static struct i2c_driver wm8804_i2c_driver = {
50 .driver = { 50 .driver = {
51 .name = "wm8804", 51 .name = "wm8804",
52 .owner = THIS_MODULE,
53 .pm = &wm8804_pm, 52 .pm = &wm8804_pm,
54 .of_match_table = wm8804_of_match, 53 .of_match_table = wm8804_of_match,
55 }, 54 },
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
index f3759ec5a863..98900aa66dc3 100644
--- a/sound/soc/codecs/wm8900.c
+++ b/sound/soc/codecs/wm8900.c
@@ -1312,7 +1312,6 @@ MODULE_DEVICE_TABLE(i2c, wm8900_i2c_id);
1312static struct i2c_driver wm8900_i2c_driver = { 1312static struct i2c_driver wm8900_i2c_driver = {
1313 .driver = { 1313 .driver = {
1314 .name = "wm8900", 1314 .name = "wm8900",
1315 .owner = THIS_MODULE,
1316 }, 1315 },
1317 .probe = wm8900_i2c_probe, 1316 .probe = wm8900_i2c_probe,
1318 .remove = wm8900_i2c_remove, 1317 .remove = wm8900_i2c_remove,
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c
index b5322c1544fb..b011253459af 100644
--- a/sound/soc/codecs/wm8903.c
+++ b/sound/soc/codecs/wm8903.c
@@ -2193,7 +2193,6 @@ MODULE_DEVICE_TABLE(i2c, wm8903_i2c_id);
2193static struct i2c_driver wm8903_i2c_driver = { 2193static struct i2c_driver wm8903_i2c_driver = {
2194 .driver = { 2194 .driver = {
2195 .name = "wm8903", 2195 .name = "wm8903",
2196 .owner = THIS_MODULE,
2197 .of_match_table = wm8903_of_match, 2196 .of_match_table = wm8903_of_match,
2198 }, 2197 },
2199 .probe = wm8903_i2c_probe, 2198 .probe = wm8903_i2c_probe,
diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c
index 265a4a58a2d1..145f5f9d581b 100644
--- a/sound/soc/codecs/wm8904.c
+++ b/sound/soc/codecs/wm8904.c
@@ -2292,7 +2292,6 @@ MODULE_DEVICE_TABLE(i2c, wm8904_i2c_id);
2292static struct i2c_driver wm8904_i2c_driver = { 2292static struct i2c_driver wm8904_i2c_driver = {
2293 .driver = { 2293 .driver = {
2294 .name = "wm8904", 2294 .name = "wm8904",
2295 .owner = THIS_MODULE,
2296 .of_match_table = of_match_ptr(wm8904_of_match), 2295 .of_match_table = of_match_ptr(wm8904_of_match),
2297 }, 2296 },
2298 .probe = wm8904_i2c_probe, 2297 .probe = wm8904_i2c_probe,
diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c
index 98ef0ba5c2a4..f6f9395ea38e 100644
--- a/sound/soc/codecs/wm8940.c
+++ b/sound/soc/codecs/wm8940.c
@@ -787,7 +787,6 @@ MODULE_DEVICE_TABLE(i2c, wm8940_i2c_id);
787static struct i2c_driver wm8940_i2c_driver = { 787static struct i2c_driver wm8940_i2c_driver = {
788 .driver = { 788 .driver = {
789 .name = "wm8940", 789 .name = "wm8940",
790 .owner = THIS_MODULE,
791 }, 790 },
792 .probe = wm8940_i2c_probe, 791 .probe = wm8940_i2c_probe,
793 .remove = wm8940_i2c_remove, 792 .remove = wm8940_i2c_remove,
diff --git a/sound/soc/codecs/wm8955.c b/sound/soc/codecs/wm8955.c
index 2d591c24704b..12e4435f00f8 100644
--- a/sound/soc/codecs/wm8955.c
+++ b/sound/soc/codecs/wm8955.c
@@ -1009,7 +1009,6 @@ MODULE_DEVICE_TABLE(i2c, wm8955_i2c_id);
1009static struct i2c_driver wm8955_i2c_driver = { 1009static struct i2c_driver wm8955_i2c_driver = {
1010 .driver = { 1010 .driver = {
1011 .name = "wm8955", 1011 .name = "wm8955",
1012 .owner = THIS_MODULE,
1013 }, 1012 },
1014 .probe = wm8955_i2c_probe, 1013 .probe = wm8955_i2c_probe,
1015 .remove = wm8955_i2c_remove, 1014 .remove = wm8955_i2c_remove,
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c
index 94c5c4681ce5..1ed0720b41f0 100644
--- a/sound/soc/codecs/wm8960.c
+++ b/sound/soc/codecs/wm8960.c
@@ -1216,7 +1216,6 @@ MODULE_DEVICE_TABLE(of, wm8960_of_match);
1216static struct i2c_driver wm8960_i2c_driver = { 1216static struct i2c_driver wm8960_i2c_driver = {
1217 .driver = { 1217 .driver = {
1218 .name = "wm8960", 1218 .name = "wm8960",
1219 .owner = THIS_MODULE,
1220 .of_match_table = wm8960_of_match, 1219 .of_match_table = wm8960_of_match,
1221 }, 1220 },
1222 .probe = wm8960_i2c_probe, 1221 .probe = wm8960_i2c_probe,
diff --git a/sound/soc/codecs/wm8961.c b/sound/soc/codecs/wm8961.c
index a057662632ff..20a010344fd5 100644
--- a/sound/soc/codecs/wm8961.c
+++ b/sound/soc/codecs/wm8961.c
@@ -982,7 +982,6 @@ MODULE_DEVICE_TABLE(i2c, wm8961_i2c_id);
982static struct i2c_driver wm8961_i2c_driver = { 982static struct i2c_driver wm8961_i2c_driver = {
983 .driver = { 983 .driver = {
984 .name = "wm8961", 984 .name = "wm8961",
985 .owner = THIS_MODULE,
986 }, 985 },
987 .probe = wm8961_i2c_probe, 986 .probe = wm8961_i2c_probe,
988 .remove = wm8961_i2c_remove, 987 .remove = wm8961_i2c_remove,
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index c5748fd4f296..5c01707d4999 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -113,7 +113,7 @@ WM8962_REGULATOR_EVENT(5)
113WM8962_REGULATOR_EVENT(6) 113WM8962_REGULATOR_EVENT(6)
114WM8962_REGULATOR_EVENT(7) 114WM8962_REGULATOR_EVENT(7)
115 115
116static struct reg_default wm8962_reg[] = { 116static const struct reg_default wm8962_reg[] = {
117 { 0, 0x009F }, /* R0 - Left Input volume */ 117 { 0, 0x009F }, /* R0 - Left Input volume */
118 { 1, 0x049F }, /* R1 - Right Input volume */ 118 { 1, 0x049F }, /* R1 - Right Input volume */
119 { 2, 0x0000 }, /* R2 - HPOUTL volume */ 119 { 2, 0x0000 }, /* R2 - HPOUTL volume */
@@ -3495,7 +3495,7 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8962 = {
3495}; 3495};
3496 3496
3497/* Improve power consumption for IN4 DC measurement mode */ 3497/* Improve power consumption for IN4 DC measurement mode */
3498static const struct reg_default wm8962_dc_measure[] = { 3498static const struct reg_sequence wm8962_dc_measure[] = {
3499 { 0xfd, 0x1 }, 3499 { 0xfd, 0x1 },
3500 { 0xcc, 0x40 }, 3500 { 0xcc, 0x40 },
3501 { 0xfd, 0 }, 3501 { 0xfd, 0 },
@@ -3859,7 +3859,7 @@ static int wm8962_runtime_suspend(struct device *dev)
3859} 3859}
3860#endif 3860#endif
3861 3861
3862static struct dev_pm_ops wm8962_pm = { 3862static const struct dev_pm_ops wm8962_pm = {
3863 SET_RUNTIME_PM_OPS(wm8962_runtime_suspend, wm8962_runtime_resume, NULL) 3863 SET_RUNTIME_PM_OPS(wm8962_runtime_suspend, wm8962_runtime_resume, NULL)
3864}; 3864};
3865 3865
@@ -3878,7 +3878,6 @@ MODULE_DEVICE_TABLE(of, wm8962_of_match);
3878static struct i2c_driver wm8962_i2c_driver = { 3878static struct i2c_driver wm8962_i2c_driver = {
3879 .driver = { 3879 .driver = {
3880 .name = "wm8962", 3880 .name = "wm8962",
3881 .owner = THIS_MODULE,
3882 .of_match_table = wm8962_of_match, 3881 .of_match_table = wm8962_of_match,
3883 .pm = &wm8962_pm, 3882 .pm = &wm8962_pm,
3884 }, 3883 },
diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c
index b51184c4e816..2cdde32c43c6 100644
--- a/sound/soc/codecs/wm8971.c
+++ b/sound/soc/codecs/wm8971.c
@@ -710,7 +710,6 @@ MODULE_DEVICE_TABLE(i2c, wm8971_i2c_id);
710static struct i2c_driver wm8971_i2c_driver = { 710static struct i2c_driver wm8971_i2c_driver = {
711 .driver = { 711 .driver = {
712 .name = "wm8971", 712 .name = "wm8971",
713 .owner = THIS_MODULE,
714 }, 713 },
715 .probe = wm8971_i2c_probe, 714 .probe = wm8971_i2c_probe,
716 .remove = wm8971_i2c_remove, 715 .remove = wm8971_i2c_remove,
diff --git a/sound/soc/codecs/wm8974.c b/sound/soc/codecs/wm8974.c
index 33b16a7ba82e..0a60677397b3 100644
--- a/sound/soc/codecs/wm8974.c
+++ b/sound/soc/codecs/wm8974.c
@@ -634,7 +634,6 @@ MODULE_DEVICE_TABLE(i2c, wm8974_i2c_id);
634static struct i2c_driver wm8974_i2c_driver = { 634static struct i2c_driver wm8974_i2c_driver = {
635 .driver = { 635 .driver = {
636 .name = "wm8974", 636 .name = "wm8974",
637 .owner = THIS_MODULE,
638 }, 637 },
639 .probe = wm8974_i2c_probe, 638 .probe = wm8974_i2c_probe,
640 .remove = wm8974_i2c_remove, 639 .remove = wm8974_i2c_remove,
diff --git a/sound/soc/codecs/wm8978.c b/sound/soc/codecs/wm8978.c
index cfc8cdf49970..d36d6001fbb7 100644
--- a/sound/soc/codecs/wm8978.c
+++ b/sound/soc/codecs/wm8978.c
@@ -1072,7 +1072,6 @@ MODULE_DEVICE_TABLE(i2c, wm8978_i2c_id);
1072static struct i2c_driver wm8978_i2c_driver = { 1072static struct i2c_driver wm8978_i2c_driver = {
1073 .driver = { 1073 .driver = {
1074 .name = "wm8978", 1074 .name = "wm8978",
1075 .owner = THIS_MODULE,
1076 }, 1075 },
1077 .probe = wm8978_i2c_probe, 1076 .probe = wm8978_i2c_probe,
1078 .remove = wm8978_i2c_remove, 1077 .remove = wm8978_i2c_remove,
diff --git a/sound/soc/codecs/wm8983.c b/sound/soc/codecs/wm8983.c
index 2fdd2c6cc09d..f6861cc4c321 100644
--- a/sound/soc/codecs/wm8983.c
+++ b/sound/soc/codecs/wm8983.c
@@ -1133,7 +1133,6 @@ MODULE_DEVICE_TABLE(i2c, wm8983_i2c_id);
1133static struct i2c_driver wm8983_i2c_driver = { 1133static struct i2c_driver wm8983_i2c_driver = {
1134 .driver = { 1134 .driver = {
1135 .name = "wm8983", 1135 .name = "wm8983",
1136 .owner = THIS_MODULE,
1137 }, 1136 },
1138 .probe = wm8983_i2c_probe, 1137 .probe = wm8983_i2c_probe,
1139 .remove = wm8983_i2c_remove, 1138 .remove = wm8983_i2c_remove,
diff --git a/sound/soc/codecs/wm8985.c b/sound/soc/codecs/wm8985.c
index 8a85f5004d41..9c3c1517a4f3 100644
--- a/sound/soc/codecs/wm8985.c
+++ b/sound/soc/codecs/wm8985.c
@@ -1144,7 +1144,6 @@ MODULE_DEVICE_TABLE(i2c, wm8985_i2c_id);
1144static struct i2c_driver wm8985_i2c_driver = { 1144static struct i2c_driver wm8985_i2c_driver = {
1145 .driver = { 1145 .driver = {
1146 .name = "wm8985", 1146 .name = "wm8985",
1147 .owner = THIS_MODULE,
1148 }, 1147 },
1149 .probe = wm8985_i2c_probe, 1148 .probe = wm8985_i2c_probe,
1150 .remove = wm8985_i2c_remove, 1149 .remove = wm8985_i2c_remove,
diff --git a/sound/soc/codecs/wm8988.c b/sound/soc/codecs/wm8988.c
index f13a995af277..c88ce99ce9e1 100644
--- a/sound/soc/codecs/wm8988.c
+++ b/sound/soc/codecs/wm8988.c
@@ -919,7 +919,6 @@ MODULE_DEVICE_TABLE(i2c, wm8988_i2c_id);
919static struct i2c_driver wm8988_i2c_driver = { 919static struct i2c_driver wm8988_i2c_driver = {
920 .driver = { 920 .driver = {
921 .name = "wm8988", 921 .name = "wm8988",
922 .owner = THIS_MODULE,
923 }, 922 },
924 .probe = wm8988_i2c_probe, 923 .probe = wm8988_i2c_probe,
925 .remove = wm8988_i2c_remove, 924 .remove = wm8988_i2c_remove,
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c
index 1993fd2a6f15..83d72d8bc51b 100644
--- a/sound/soc/codecs/wm8990.c
+++ b/sound/soc/codecs/wm8990.c
@@ -1356,7 +1356,6 @@ MODULE_DEVICE_TABLE(i2c, wm8990_i2c_id);
1356static struct i2c_driver wm8990_i2c_driver = { 1356static struct i2c_driver wm8990_i2c_driver = {
1357 .driver = { 1357 .driver = {
1358 .name = "wm8990", 1358 .name = "wm8990",
1359 .owner = THIS_MODULE,
1360 }, 1359 },
1361 .probe = wm8990_i2c_probe, 1360 .probe = wm8990_i2c_probe,
1362 .remove = wm8990_i2c_remove, 1361 .remove = wm8990_i2c_remove,
diff --git a/sound/soc/codecs/wm8991.c b/sound/soc/codecs/wm8991.c
index 44a677720828..709d16e338d9 100644
--- a/sound/soc/codecs/wm8991.c
+++ b/sound/soc/codecs/wm8991.c
@@ -1363,7 +1363,6 @@ MODULE_DEVICE_TABLE(i2c, wm8991_i2c_id);
1363static struct i2c_driver wm8991_i2c_driver = { 1363static struct i2c_driver wm8991_i2c_driver = {
1364 .driver = { 1364 .driver = {
1365 .name = "wm8991", 1365 .name = "wm8991",
1366 .owner = THIS_MODULE,
1367 }, 1366 },
1368 .probe = wm8991_i2c_probe, 1367 .probe = wm8991_i2c_probe,
1369 .remove = wm8991_i2c_remove, 1368 .remove = wm8991_i2c_remove,
diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c
index 8a8db8605dc2..ac9efd63dbef 100644
--- a/sound/soc/codecs/wm8993.c
+++ b/sound/soc/codecs/wm8993.c
@@ -41,7 +41,7 @@ static const char *wm8993_supply_names[WM8993_NUM_SUPPLIES] = {
41 "SPKVDD", 41 "SPKVDD",
42}; 42};
43 43
44static struct reg_default wm8993_reg_defaults[] = { 44static const struct reg_default wm8993_reg_defaults[] = {
45 { 1, 0x0000 }, /* R1 - Power Management (1) */ 45 { 1, 0x0000 }, /* R1 - Power Management (1) */
46 { 2, 0x6000 }, /* R2 - Power Management (2) */ 46 { 2, 0x6000 }, /* R2 - Power Management (2) */
47 { 3, 0x0000 }, /* R3 - Power Management (3) */ 47 { 3, 0x0000 }, /* R3 - Power Management (3) */
@@ -1595,7 +1595,7 @@ static int wm8993_resume(struct snd_soc_codec *codec)
1595#endif 1595#endif
1596 1596
1597/* Tune DC servo configuration */ 1597/* Tune DC servo configuration */
1598static struct reg_default wm8993_regmap_patch[] = { 1598static const struct reg_sequence wm8993_regmap_patch[] = {
1599 { 0x44, 3 }, 1599 { 0x44, 3 },
1600 { 0x56, 3 }, 1600 { 0x56, 3 },
1601 { 0x44, 0 }, 1601 { 0x44, 0 },
@@ -1742,7 +1742,6 @@ MODULE_DEVICE_TABLE(i2c, wm8993_i2c_id);
1742static struct i2c_driver wm8993_i2c_driver = { 1742static struct i2c_driver wm8993_i2c_driver = {
1743 .driver = { 1743 .driver = {
1744 .name = "wm8993", 1744 .name = "wm8993",
1745 .owner = THIS_MODULE,
1746 }, 1745 },
1747 .probe = wm8993_i2c_probe, 1746 .probe = wm8993_i2c_probe,
1748 .remove = wm8993_i2c_remove, 1747 .remove = wm8993_i2c_remove,
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index 962e1d31a629..2ccbb322df77 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -1942,14 +1942,16 @@ static const struct snd_soc_dapm_route intercon[] = {
1942 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" }, 1942 { "AIF2ADCDAT", NULL, "AIF2ADC Mux" },
1943 1943
1944 /* AIF3 output */ 1944 /* AIF3 output */
1945 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1L" }, 1945 { "AIF3ADC Mux", "AIF1ADCDAT", "AIF1ADC1L" },
1946 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC1R" }, 1946 { "AIF3ADC Mux", "AIF1ADCDAT", "AIF1ADC1R" },
1947 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2L" }, 1947 { "AIF3ADC Mux", "AIF1ADCDAT", "AIF1ADC2L" },
1948 { "AIF3ADCDAT", "AIF1ADCDAT", "AIF1ADC2R" }, 1948 { "AIF3ADC Mux", "AIF1ADCDAT", "AIF1ADC2R" },
1949 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCL" }, 1949 { "AIF3ADC Mux", "AIF2ADCDAT", "AIF2ADCL" },
1950 { "AIF3ADCDAT", "AIF2ADCDAT", "AIF2ADCR" }, 1950 { "AIF3ADC Mux", "AIF2ADCDAT", "AIF2ADCR" },
1951 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACL" }, 1951 { "AIF3ADC Mux", "AIF2DACDAT", "AIF2DACL" },
1952 { "AIF3ADCDAT", "AIF2DACDAT", "AIF2DACR" }, 1952 { "AIF3ADC Mux", "AIF2DACDAT", "AIF2DACR" },
1953
1954 { "AIF3ADCDAT", NULL, "AIF3ADC Mux" },
1953 1955
1954 /* Loopback */ 1956 /* Loopback */
1955 { "AIF1 Loopback", "ADCDAT", "AIF1ADCDAT" }, 1957 { "AIF1 Loopback", "ADCDAT", "AIF1ADCDAT" },
diff --git a/sound/soc/codecs/wm8995.c b/sound/soc/codecs/wm8995.c
index 505b65f5734f..eda52a96c1fa 100644
--- a/sound/soc/codecs/wm8995.c
+++ b/sound/soc/codecs/wm8995.c
@@ -2298,7 +2298,6 @@ MODULE_DEVICE_TABLE(i2c, wm8995_i2c_id);
2298static struct i2c_driver wm8995_i2c_driver = { 2298static struct i2c_driver wm8995_i2c_driver = {
2299 .driver = { 2299 .driver = {
2300 .name = "wm8995", 2300 .name = "wm8995",
2301 .owner = THIS_MODULE,
2302 }, 2301 },
2303 .probe = wm8995_i2c_probe, 2302 .probe = wm8995_i2c_probe,
2304 .remove = wm8995_i2c_remove, 2303 .remove = wm8995_i2c_remove,
diff --git a/sound/soc/codecs/wm8996.c b/sound/soc/codecs/wm8996.c
index 3dd063f682b2..66c09556da79 100644
--- a/sound/soc/codecs/wm8996.c
+++ b/sound/soc/codecs/wm8996.c
@@ -117,7 +117,7 @@ WM8996_REGULATOR_EVENT(0)
117WM8996_REGULATOR_EVENT(1) 117WM8996_REGULATOR_EVENT(1)
118WM8996_REGULATOR_EVENT(2) 118WM8996_REGULATOR_EVENT(2)
119 119
120static struct reg_default wm8996_reg[] = { 120static const struct reg_default wm8996_reg[] = {
121 { WM8996_POWER_MANAGEMENT_1, 0x0 }, 121 { WM8996_POWER_MANAGEMENT_1, 0x0 },
122 { WM8996_POWER_MANAGEMENT_2, 0x0 }, 122 { WM8996_POWER_MANAGEMENT_2, 0x0 },
123 { WM8996_POWER_MANAGEMENT_3, 0x0 }, 123 { WM8996_POWER_MANAGEMENT_3, 0x0 },
@@ -3100,7 +3100,6 @@ MODULE_DEVICE_TABLE(i2c, wm8996_i2c_id);
3100static struct i2c_driver wm8996_i2c_driver = { 3100static struct i2c_driver wm8996_i2c_driver = {
3101 .driver = { 3101 .driver = {
3102 .name = "wm8996", 3102 .name = "wm8996",
3103 .owner = THIS_MODULE,
3104 }, 3103 },
3105 .probe = wm8996_i2c_probe, 3104 .probe = wm8996_i2c_probe,
3106 .remove = wm8996_i2c_remove, 3105 .remove = wm8996_i2c_remove,
diff --git a/sound/soc/codecs/wm8997.c b/sound/soc/codecs/wm8997.c
index 4134dc7e1243..b4dba3a02aba 100644
--- a/sound/soc/codecs/wm8997.c
+++ b/sound/soc/codecs/wm8997.c
@@ -174,8 +174,7 @@ ARIZONA_MIXER_CONTROLS("EQ2", ARIZONA_EQ2MIX_INPUT_1_SOURCE),
174ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE), 174ARIZONA_MIXER_CONTROLS("EQ3", ARIZONA_EQ3MIX_INPUT_1_SOURCE),
175ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE), 175ARIZONA_MIXER_CONTROLS("EQ4", ARIZONA_EQ4MIX_INPUT_1_SOURCE),
176 176
177SND_SOC_BYTES("EQ1 Coefficients", ARIZONA_EQ1_3, 19), 177ARIZONA_EQ_CONTROL("EQ1 Coefficients", ARIZONA_EQ1_2),
178SOC_SINGLE("EQ1 Mode Switch", ARIZONA_EQ1_2, ARIZONA_EQ1_B1_MODE, 1, 0),
179SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT, 178SOC_SINGLE_TLV("EQ1 B1 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B1_GAIN_SHIFT,
180 24, 0, eq_tlv), 179 24, 0, eq_tlv),
181SOC_SINGLE_TLV("EQ1 B2 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B2_GAIN_SHIFT, 180SOC_SINGLE_TLV("EQ1 B2 Volume", ARIZONA_EQ1_1, ARIZONA_EQ1_B2_GAIN_SHIFT,
@@ -187,8 +186,7 @@ SOC_SINGLE_TLV("EQ1 B4 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B4_GAIN_SHIFT,
187SOC_SINGLE_TLV("EQ1 B5 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B5_GAIN_SHIFT, 186SOC_SINGLE_TLV("EQ1 B5 Volume", ARIZONA_EQ1_2, ARIZONA_EQ1_B5_GAIN_SHIFT,
188 24, 0, eq_tlv), 187 24, 0, eq_tlv),
189 188
190SND_SOC_BYTES("EQ2 Coefficients", ARIZONA_EQ2_3, 19), 189ARIZONA_EQ_CONTROL("EQ2 Coefficients", ARIZONA_EQ2_2),
191SOC_SINGLE("EQ2 Mode Switch", ARIZONA_EQ2_2, ARIZONA_EQ2_B1_MODE, 1, 0),
192SOC_SINGLE_TLV("EQ2 B1 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B1_GAIN_SHIFT, 190SOC_SINGLE_TLV("EQ2 B1 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B1_GAIN_SHIFT,
193 24, 0, eq_tlv), 191 24, 0, eq_tlv),
194SOC_SINGLE_TLV("EQ2 B2 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B2_GAIN_SHIFT, 192SOC_SINGLE_TLV("EQ2 B2 Volume", ARIZONA_EQ2_1, ARIZONA_EQ2_B2_GAIN_SHIFT,
@@ -200,8 +198,7 @@ SOC_SINGLE_TLV("EQ2 B4 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B4_GAIN_SHIFT,
200SOC_SINGLE_TLV("EQ2 B5 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B5_GAIN_SHIFT, 198SOC_SINGLE_TLV("EQ2 B5 Volume", ARIZONA_EQ2_2, ARIZONA_EQ2_B5_GAIN_SHIFT,
201 24, 0, eq_tlv), 199 24, 0, eq_tlv),
202 200
203SND_SOC_BYTES("EQ3 Coefficients", ARIZONA_EQ3_3, 19), 201ARIZONA_EQ_CONTROL("EQ3 Coefficients", ARIZONA_EQ3_2),
204SOC_SINGLE("EQ3 Mode Switch", ARIZONA_EQ3_2, ARIZONA_EQ3_B1_MODE, 1, 0),
205SOC_SINGLE_TLV("EQ3 B1 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B1_GAIN_SHIFT, 202SOC_SINGLE_TLV("EQ3 B1 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B1_GAIN_SHIFT,
206 24, 0, eq_tlv), 203 24, 0, eq_tlv),
207SOC_SINGLE_TLV("EQ3 B2 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B2_GAIN_SHIFT, 204SOC_SINGLE_TLV("EQ3 B2 Volume", ARIZONA_EQ3_1, ARIZONA_EQ3_B2_GAIN_SHIFT,
@@ -213,8 +210,7 @@ SOC_SINGLE_TLV("EQ3 B4 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B4_GAIN_SHIFT,
213SOC_SINGLE_TLV("EQ3 B5 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B5_GAIN_SHIFT, 210SOC_SINGLE_TLV("EQ3 B5 Volume", ARIZONA_EQ3_2, ARIZONA_EQ3_B5_GAIN_SHIFT,
214 24, 0, eq_tlv), 211 24, 0, eq_tlv),
215 212
216SND_SOC_BYTES("EQ4 Coefficients", ARIZONA_EQ4_3, 19), 213ARIZONA_EQ_CONTROL("EQ4 Coefficients", ARIZONA_EQ4_2),
217SOC_SINGLE("EQ4 Mode Switch", ARIZONA_EQ4_2, ARIZONA_EQ4_B1_MODE, 1, 0),
218SOC_SINGLE_TLV("EQ4 B1 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B1_GAIN_SHIFT, 214SOC_SINGLE_TLV("EQ4 B1 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B1_GAIN_SHIFT,
219 24, 0, eq_tlv), 215 24, 0, eq_tlv),
220SOC_SINGLE_TLV("EQ4 B2 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B2_GAIN_SHIFT, 216SOC_SINGLE_TLV("EQ4 B2 Volume", ARIZONA_EQ4_1, ARIZONA_EQ4_B2_GAIN_SHIFT,
@@ -242,10 +238,10 @@ SOC_ENUM("LHPF2 Mode", arizona_lhpf2_mode),
242SOC_ENUM("LHPF3 Mode", arizona_lhpf3_mode), 238SOC_ENUM("LHPF3 Mode", arizona_lhpf3_mode),
243SOC_ENUM("LHPF4 Mode", arizona_lhpf4_mode), 239SOC_ENUM("LHPF4 Mode", arizona_lhpf4_mode),
244 240
245SND_SOC_BYTES("LHPF1 Coefficients", ARIZONA_HPLPF1_2, 1), 241ARIZONA_LHPF_CONTROL("LHPF1 Coefficients", ARIZONA_HPLPF1_2),
246SND_SOC_BYTES("LHPF2 Coefficients", ARIZONA_HPLPF2_2, 1), 242ARIZONA_LHPF_CONTROL("LHPF2 Coefficients", ARIZONA_HPLPF2_2),
247SND_SOC_BYTES("LHPF3 Coefficients", ARIZONA_HPLPF3_2, 1), 243ARIZONA_LHPF_CONTROL("LHPF3 Coefficients", ARIZONA_HPLPF3_2),
248SND_SOC_BYTES("LHPF4 Coefficients", ARIZONA_HPLPF4_2, 1), 244ARIZONA_LHPF_CONTROL("LHPF4 Coefficients", ARIZONA_HPLPF4_2),
249 245
250SOC_ENUM("ISRC1 FSL", arizona_isrc_fsl[0]), 246SOC_ENUM("ISRC1 FSL", arizona_isrc_fsl[0]),
251SOC_ENUM("ISRC2 FSL", arizona_isrc_fsl[1]), 247SOC_ENUM("ISRC2 FSL", arizona_isrc_fsl[1]),
diff --git a/sound/soc/codecs/wm9081.c b/sound/soc/codecs/wm9081.c
index 8a8b1c0f9142..45223a20331f 100644
--- a/sound/soc/codecs/wm9081.c
+++ b/sound/soc/codecs/wm9081.c
@@ -30,7 +30,7 @@
30#include <sound/wm9081.h> 30#include <sound/wm9081.h>
31#include "wm9081.h" 31#include "wm9081.h"
32 32
33static struct reg_default wm9081_reg[] = { 33static const struct reg_default wm9081_reg[] = {
34 { 2, 0x00B9 }, /* R2 - Analogue Lineout */ 34 { 2, 0x00B9 }, /* R2 - Analogue Lineout */
35 { 3, 0x00B9 }, /* R3 - Analogue Speaker PGA */ 35 { 3, 0x00B9 }, /* R3 - Analogue Speaker PGA */
36 { 4, 0x0001 }, /* R4 - VMID Control */ 36 { 4, 0x0001 }, /* R4 - VMID Control */
@@ -1378,7 +1378,6 @@ MODULE_DEVICE_TABLE(i2c, wm9081_i2c_id);
1378static struct i2c_driver wm9081_i2c_driver = { 1378static struct i2c_driver wm9081_i2c_driver = {
1379 .driver = { 1379 .driver = {
1380 .name = "wm9081", 1380 .name = "wm9081",
1381 .owner = THIS_MODULE,
1382 }, 1381 },
1383 .probe = wm9081_i2c_probe, 1382 .probe = wm9081_i2c_probe,
1384 .remove = wm9081_i2c_remove, 1383 .remove = wm9081_i2c_remove,
diff --git a/sound/soc/codecs/wm9090.c b/sound/soc/codecs/wm9090.c
index 13d23fc797db..12baf725d4a5 100644
--- a/sound/soc/codecs/wm9090.c
+++ b/sound/soc/codecs/wm9090.c
@@ -636,7 +636,6 @@ MODULE_DEVICE_TABLE(i2c, wm9090_id);
636static struct i2c_driver wm9090_i2c_driver = { 636static struct i2c_driver wm9090_i2c_driver = {
637 .driver = { 637 .driver = {
638 .name = "wm9090", 638 .name = "wm9090",
639 .owner = THIS_MODULE,
640 }, 639 },
641 .probe = wm9090_i2c_probe, 640 .probe = wm9090_i2c_probe,
642 .remove = wm9090_i2c_remove, 641 .remove = wm9090_i2c_remove,
diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c
index 5cc457ef8894..744842c76a60 100644
--- a/sound/soc/codecs/wm9705.c
+++ b/sound/soc/codecs/wm9705.c
@@ -22,6 +22,9 @@
22 22
23#include "wm9705.h" 23#include "wm9705.h"
24 24
25#define WM9705_VENDOR_ID 0x574d4c05
26#define WM9705_VENDOR_ID_MASK 0xffffffff
27
25/* 28/*
26 * WM9705 register cache 29 * WM9705 register cache
27 */ 30 */
@@ -293,21 +296,6 @@ static struct snd_soc_dai_driver wm9705_dai[] = {
293 } 296 }
294}; 297};
295 298
296static int wm9705_reset(struct snd_soc_codec *codec)
297{
298 struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec);
299
300 if (soc_ac97_ops->reset) {
301 soc_ac97_ops->reset(ac97);
302 if (ac97_read(codec, 0) == wm9705_reg[0])
303 return 0; /* Success */
304 }
305
306 dev_err(codec->dev, "Failed to reset: AC97 link error\n");
307
308 return -EIO;
309}
310
311#ifdef CONFIG_PM 299#ifdef CONFIG_PM
312static int wm9705_soc_suspend(struct snd_soc_codec *codec) 300static int wm9705_soc_suspend(struct snd_soc_codec *codec)
313{ 301{
@@ -324,7 +312,8 @@ static int wm9705_soc_resume(struct snd_soc_codec *codec)
324 int i, ret; 312 int i, ret;
325 u16 *cache = codec->reg_cache; 313 u16 *cache = codec->reg_cache;
326 314
327 ret = wm9705_reset(codec); 315 ret = snd_ac97_reset(ac97, true, WM9705_VENDOR_ID,
316 WM9705_VENDOR_ID_MASK);
328 if (ret < 0) 317 if (ret < 0)
329 return ret; 318 return ret;
330 319
@@ -342,30 +331,17 @@ static int wm9705_soc_resume(struct snd_soc_codec *codec)
342static int wm9705_soc_probe(struct snd_soc_codec *codec) 331static int wm9705_soc_probe(struct snd_soc_codec *codec)
343{ 332{
344 struct snd_ac97 *ac97; 333 struct snd_ac97 *ac97;
345 int ret = 0;
346 334
347 ac97 = snd_soc_alloc_ac97_codec(codec); 335 ac97 = snd_soc_new_ac97_codec(codec, WM9705_VENDOR_ID,
336 WM9705_VENDOR_ID_MASK);
348 if (IS_ERR(ac97)) { 337 if (IS_ERR(ac97)) {
349 ret = PTR_ERR(ac97);
350 dev_err(codec->dev, "Failed to register AC97 codec\n"); 338 dev_err(codec->dev, "Failed to register AC97 codec\n");
351 return ret; 339 return PTR_ERR(ac97);
352 } 340 }
353 341
354 ret = wm9705_reset(codec);
355 if (ret)
356 goto err_put_device;
357
358 ret = device_add(&ac97->dev);
359 if (ret)
360 goto err_put_device;
361
362 snd_soc_codec_set_drvdata(codec, ac97); 342 snd_soc_codec_set_drvdata(codec, ac97);
363 343
364 return 0; 344 return 0;
365
366err_put_device:
367 put_device(&ac97->dev);
368 return ret;
369} 345}
370 346
371static int wm9705_soc_remove(struct snd_soc_codec *codec) 347static int wm9705_soc_remove(struct snd_soc_codec *codec)
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
index 1fda104dfc45..488a92224249 100644
--- a/sound/soc/codecs/wm9712.c
+++ b/sound/soc/codecs/wm9712.c
@@ -23,6 +23,9 @@
23#include <sound/tlv.h> 23#include <sound/tlv.h>
24#include "wm9712.h" 24#include "wm9712.h"
25 25
26#define WM9712_VENDOR_ID 0x574d4c12
27#define WM9712_VENDOR_ID_MASK 0xffffffff
28
26struct wm9712_priv { 29struct wm9712_priv {
27 struct snd_ac97 *ac97; 30 struct snd_ac97 *ac97;
28 unsigned int hp_mixer[2]; 31 unsigned int hp_mixer[2];
@@ -613,35 +616,14 @@ static int wm9712_set_bias_level(struct snd_soc_codec *codec,
613 return 0; 616 return 0;
614} 617}
615 618
616static int wm9712_reset(struct snd_soc_codec *codec, int try_warm)
617{
618 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec);
619
620 if (try_warm && soc_ac97_ops->warm_reset) {
621 soc_ac97_ops->warm_reset(wm9712->ac97);
622 if (ac97_read(codec, 0) == wm9712_reg[0])
623 return 1;
624 }
625
626 soc_ac97_ops->reset(wm9712->ac97);
627 if (soc_ac97_ops->warm_reset)
628 soc_ac97_ops->warm_reset(wm9712->ac97);
629 if (ac97_read(codec, 0) != wm9712_reg[0])
630 goto err;
631 return 0;
632
633err:
634 dev_err(codec->dev, "Failed to reset: AC97 link error\n");
635 return -EIO;
636}
637
638static int wm9712_soc_resume(struct snd_soc_codec *codec) 619static int wm9712_soc_resume(struct snd_soc_codec *codec)
639{ 620{
640 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); 621 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec);
641 int i, ret; 622 int i, ret;
642 u16 *cache = codec->reg_cache; 623 u16 *cache = codec->reg_cache;
643 624
644 ret = wm9712_reset(codec, 1); 625 ret = snd_ac97_reset(wm9712->ac97, true, WM9712_VENDOR_ID,
626 WM9712_VENDOR_ID_MASK);
645 if (ret < 0) 627 if (ret < 0)
646 return ret; 628 return ret;
647 629
@@ -663,31 +645,20 @@ static int wm9712_soc_resume(struct snd_soc_codec *codec)
663static int wm9712_soc_probe(struct snd_soc_codec *codec) 645static int wm9712_soc_probe(struct snd_soc_codec *codec)
664{ 646{
665 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); 647 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec);
666 int ret = 0; 648 int ret;
667 649
668 wm9712->ac97 = snd_soc_alloc_ac97_codec(codec); 650 wm9712->ac97 = snd_soc_new_ac97_codec(codec, WM9712_VENDOR_ID,
651 WM9712_VENDOR_ID_MASK);
669 if (IS_ERR(wm9712->ac97)) { 652 if (IS_ERR(wm9712->ac97)) {
670 ret = PTR_ERR(wm9712->ac97); 653 ret = PTR_ERR(wm9712->ac97);
671 dev_err(codec->dev, "Failed to register AC97 codec: %d\n", ret); 654 dev_err(codec->dev, "Failed to register AC97 codec: %d\n", ret);
672 return ret; 655 return ret;
673 } 656 }
674 657
675 ret = wm9712_reset(codec, 0);
676 if (ret < 0)
677 goto err_put_device;
678
679 ret = device_add(&wm9712->ac97->dev);
680 if (ret)
681 goto err_put_device;
682
683 /* set alc mux to none */ 658 /* set alc mux to none */
684 ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000); 659 ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000);
685 660
686 return 0; 661 return 0;
687
688err_put_device:
689 put_device(&wm9712->ac97->dev);
690 return ret;
691} 662}
692 663
693static int wm9712_soc_remove(struct snd_soc_codec *codec) 664static int wm9712_soc_remove(struct snd_soc_codec *codec)
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
index 89cd2d6f57c0..955e6511af56 100644
--- a/sound/soc/codecs/wm9713.c
+++ b/sound/soc/codecs/wm9713.c
@@ -29,6 +29,9 @@
29 29
30#include "wm9713.h" 30#include "wm9713.h"
31 31
32#define WM9713_VENDOR_ID 0x574d4c13
33#define WM9713_VENDOR_ID_MASK 0xffffffff
34
32struct wm9713_priv { 35struct wm9713_priv {
33 struct snd_ac97 *ac97; 36 struct snd_ac97 *ac97;
34 u32 pll_in; /* PLL input frequency */ 37 u32 pll_in; /* PLL input frequency */
@@ -1123,28 +1126,6 @@ static struct snd_soc_dai_driver wm9713_dai[] = {
1123 }, 1126 },
1124}; 1127};
1125 1128
1126int wm9713_reset(struct snd_soc_codec *codec, int try_warm)
1127{
1128 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
1129
1130 if (try_warm && soc_ac97_ops->warm_reset) {
1131 soc_ac97_ops->warm_reset(wm9713->ac97);
1132 if (ac97_read(codec, 0) == wm9713_reg[0])
1133 return 1;
1134 }
1135
1136 soc_ac97_ops->reset(wm9713->ac97);
1137 if (soc_ac97_ops->warm_reset)
1138 soc_ac97_ops->warm_reset(wm9713->ac97);
1139 if (ac97_read(codec, 0) != wm9713_reg[0]) {
1140 dev_err(codec->dev, "Failed to reset: AC97 link error\n");
1141 return -EIO;
1142 }
1143
1144 return 0;
1145}
1146EXPORT_SYMBOL_GPL(wm9713_reset);
1147
1148static int wm9713_set_bias_level(struct snd_soc_codec *codec, 1129static int wm9713_set_bias_level(struct snd_soc_codec *codec,
1149 enum snd_soc_bias_level level) 1130 enum snd_soc_bias_level level)
1150{ 1131{
@@ -1196,7 +1177,8 @@ static int wm9713_soc_resume(struct snd_soc_codec *codec)
1196 int i, ret; 1177 int i, ret;
1197 u16 *cache = codec->reg_cache; 1178 u16 *cache = codec->reg_cache;
1198 1179
1199 ret = wm9713_reset(codec, 1); 1180 ret = snd_ac97_reset(wm9713->ac97, true, WM9713_VENDOR_ID,
1181 WM9713_VENDOR_ID_MASK);
1200 if (ret < 0) 1182 if (ret < 0)
1201 return ret; 1183 return ret;
1202 1184
@@ -1222,32 +1204,18 @@ static int wm9713_soc_resume(struct snd_soc_codec *codec)
1222static int wm9713_soc_probe(struct snd_soc_codec *codec) 1204static int wm9713_soc_probe(struct snd_soc_codec *codec)
1223{ 1205{
1224 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); 1206 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
1225 int ret = 0, reg; 1207 int reg;
1226 1208
1227 wm9713->ac97 = snd_soc_alloc_ac97_codec(codec); 1209 wm9713->ac97 = snd_soc_new_ac97_codec(codec, WM9713_VENDOR_ID,
1210 WM9713_VENDOR_ID_MASK);
1228 if (IS_ERR(wm9713->ac97)) 1211 if (IS_ERR(wm9713->ac97))
1229 return PTR_ERR(wm9713->ac97); 1212 return PTR_ERR(wm9713->ac97);
1230 1213
1231 /* do a cold reset for the controller and then try
1232 * a warm reset followed by an optional cold reset for codec */
1233 wm9713_reset(codec, 0);
1234 ret = wm9713_reset(codec, 1);
1235 if (ret < 0)
1236 goto err_put_device;
1237
1238 ret = device_add(&wm9713->ac97->dev);
1239 if (ret)
1240 goto err_put_device;
1241
1242 /* unmute the adc - move to kcontrol */ 1214 /* unmute the adc - move to kcontrol */
1243 reg = ac97_read(codec, AC97_CD) & 0x7fff; 1215 reg = ac97_read(codec, AC97_CD) & 0x7fff;
1244 ac97_write(codec, AC97_CD, reg); 1216 ac97_write(codec, AC97_CD, reg);
1245 1217
1246 return 0; 1218 return 0;
1247
1248err_put_device:
1249 put_device(&wm9713->ac97->dev);
1250 return ret;
1251} 1219}
1252 1220
1253static int wm9713_soc_remove(struct snd_soc_codec *codec) 1221static int wm9713_soc_remove(struct snd_soc_codec *codec)
diff --git a/sound/soc/codecs/wm9713.h b/sound/soc/codecs/wm9713.h
index 793da863a03d..53df11b1f727 100644
--- a/sound/soc/codecs/wm9713.h
+++ b/sound/soc/codecs/wm9713.h
@@ -45,6 +45,4 @@
45#define WM9713_DAI_AC97_AUX 1 45#define WM9713_DAI_AC97_AUX 1
46#define WM9713_DAI_PCM_VOICE 2 46#define WM9713_DAI_PCM_VOICE 2
47 47
48int wm9713_reset(struct snd_soc_codec *codec, int try_warm);
49
50#endif 48#endif
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c
index 56cb4d95637d..ec98548a5fc9 100644
--- a/sound/soc/davinci/davinci-i2s.c
+++ b/sound/soc/davinci/davinci-i2s.c
@@ -651,23 +651,15 @@ static const struct snd_soc_component_driver davinci_i2s_component = {
651static int davinci_i2s_probe(struct platform_device *pdev) 651static int davinci_i2s_probe(struct platform_device *pdev)
652{ 652{
653 struct davinci_mcbsp_dev *dev; 653 struct davinci_mcbsp_dev *dev;
654 struct resource *mem, *ioarea, *res; 654 struct resource *mem, *res;
655 void __iomem *io_base;
655 int *dma; 656 int *dma;
656 int ret; 657 int ret;
657 658
658 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 659 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
659 if (!mem) { 660 io_base = devm_ioremap_resource(&pdev->dev, mem);
660 dev_err(&pdev->dev, "no mem resource?\n"); 661 if (IS_ERR(io_base))
661 return -ENODEV; 662 return PTR_ERR(io_base);
662 }
663
664 ioarea = devm_request_mem_region(&pdev->dev, mem->start,
665 resource_size(mem),
666 pdev->name);
667 if (!ioarea) {
668 dev_err(&pdev->dev, "McBSP region already claimed\n");
669 return -EBUSY;
670 }
671 663
672 dev = devm_kzalloc(&pdev->dev, sizeof(struct davinci_mcbsp_dev), 664 dev = devm_kzalloc(&pdev->dev, sizeof(struct davinci_mcbsp_dev),
673 GFP_KERNEL); 665 GFP_KERNEL);
@@ -679,12 +671,7 @@ static int davinci_i2s_probe(struct platform_device *pdev)
679 return -ENODEV; 671 return -ENODEV;
680 clk_enable(dev->clk); 672 clk_enable(dev->clk);
681 673
682 dev->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); 674 dev->base = io_base;
683 if (!dev->base) {
684 dev_err(&pdev->dev, "ioremap failed\n");
685 ret = -ENOMEM;
686 goto err_release_clk;
687 }
688 675
689 dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr = 676 dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
690 (dma_addr_t)(mem->start + DAVINCI_MCBSP_DXR_REG); 677 (dma_addr_t)(mem->start + DAVINCI_MCBSP_DXR_REG);
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index b960e626dad9..add6bb99661d 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -1613,7 +1613,7 @@ static int davinci_mcasp_get_dma_type(struct davinci_mcasp *mcasp)
1613static int davinci_mcasp_probe(struct platform_device *pdev) 1613static int davinci_mcasp_probe(struct platform_device *pdev)
1614{ 1614{
1615 struct snd_dmaengine_dai_dma_data *dma_data; 1615 struct snd_dmaengine_dai_dma_data *dma_data;
1616 struct resource *mem, *ioarea, *res, *dat; 1616 struct resource *mem, *res, *dat;
1617 struct davinci_mcasp_pdata *pdata; 1617 struct davinci_mcasp_pdata *pdata;
1618 struct davinci_mcasp *mcasp; 1618 struct davinci_mcasp *mcasp;
1619 char *irq_name; 1619 char *irq_name;
@@ -1648,22 +1648,12 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1648 } 1648 }
1649 } 1649 }
1650 1650
1651 ioarea = devm_request_mem_region(&pdev->dev, mem->start, 1651 mcasp->base = devm_ioremap_resource(&pdev->dev, mem);
1652 resource_size(mem), pdev->name); 1652 if (IS_ERR(mcasp->base))
1653 if (!ioarea) { 1653 return PTR_ERR(mcasp->base);
1654 dev_err(&pdev->dev, "Audio region already claimed\n");
1655 return -EBUSY;
1656 }
1657 1654
1658 pm_runtime_enable(&pdev->dev); 1655 pm_runtime_enable(&pdev->dev);
1659 1656
1660 mcasp->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
1661 if (!mcasp->base) {
1662 dev_err(&pdev->dev, "ioremap failed\n");
1663 ret = -ENOMEM;
1664 goto err;
1665 }
1666
1667 mcasp->op_mode = pdata->op_mode; 1657 mcasp->op_mode = pdata->op_mode;
1668 /* sanity check for tdm slots parameter */ 1658 /* sanity check for tdm slots parameter */
1669 if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE) { 1659 if (mcasp->op_mode == DAVINCI_MCASP_IIS_MODE) {
diff --git a/sound/soc/davinci/davinci-vcif.c b/sound/soc/davinci/davinci-vcif.c
index fabd05f24aeb..c77d9218795a 100644
--- a/sound/soc/davinci/davinci-vcif.c
+++ b/sound/soc/davinci/davinci-vcif.c
@@ -231,8 +231,9 @@ static int davinci_vcif_probe(struct platform_device *pdev)
231 231
232 dev_set_drvdata(&pdev->dev, davinci_vcif_dev); 232 dev_set_drvdata(&pdev->dev, davinci_vcif_dev);
233 233
234 ret = snd_soc_register_component(&pdev->dev, &davinci_vcif_component, 234 ret = devm_snd_soc_register_component(&pdev->dev,
235 &davinci_vcif_dai, 1); 235 &davinci_vcif_component,
236 &davinci_vcif_dai, 1);
236 if (ret != 0) { 237 if (ret != 0) {
237 dev_err(&pdev->dev, "could not register dai\n"); 238 dev_err(&pdev->dev, "could not register dai\n");
238 return ret; 239 return ret;
@@ -241,23 +242,14 @@ static int davinci_vcif_probe(struct platform_device *pdev)
241 ret = edma_pcm_platform_register(&pdev->dev); 242 ret = edma_pcm_platform_register(&pdev->dev);
242 if (ret) { 243 if (ret) {
243 dev_err(&pdev->dev, "register PCM failed: %d\n", ret); 244 dev_err(&pdev->dev, "register PCM failed: %d\n", ret);
244 snd_soc_unregister_component(&pdev->dev);
245 return ret; 245 return ret;
246 } 246 }
247 247
248 return 0; 248 return 0;
249} 249}
250 250
251static int davinci_vcif_remove(struct platform_device *pdev)
252{
253 snd_soc_unregister_component(&pdev->dev);
254
255 return 0;
256}
257
258static struct platform_driver davinci_vcif_driver = { 251static struct platform_driver davinci_vcif_driver = {
259 .probe = davinci_vcif_probe, 252 .probe = davinci_vcif_probe,
260 .remove = davinci_vcif_remove,
261 .driver = { 253 .driver = {
262 .name = "davinci-vcif", 254 .name = "davinci-vcif",
263 }, 255 },
diff --git a/sound/soc/fsl/eukrea-tlv320.c b/sound/soc/fsl/eukrea-tlv320.c
index e1aa3834b101..883087f2b092 100644
--- a/sound/soc/fsl/eukrea-tlv320.c
+++ b/sound/soc/fsl/eukrea-tlv320.c
@@ -182,7 +182,7 @@ static int eukrea_tlv320_probe(struct platform_device *pdev)
182 ); 182 );
183 } else { 183 } else {
184 if (np) { 184 if (np) {
185 /* The eukrea,asoc-tlv320 driver was explicitely 185 /* The eukrea,asoc-tlv320 driver was explicitly
186 * requested (through the device tree). 186 * requested (through the device tree).
187 */ 187 */
188 dev_err(&pdev->dev, 188 dev_err(&pdev->dev,
diff --git a/sound/soc/fsl/fsl-asoc-card.c b/sound/soc/fsl/fsl-asoc-card.c
index de438871040b..5aeb6ed4827e 100644
--- a/sound/soc/fsl/fsl-asoc-card.c
+++ b/sound/soc/fsl/fsl-asoc-card.c
@@ -23,6 +23,7 @@
23 23
24#include "../codecs/sgtl5000.h" 24#include "../codecs/sgtl5000.h"
25#include "../codecs/wm8962.h" 25#include "../codecs/wm8962.h"
26#include "../codecs/wm8960.h"
26 27
27#define RX 0 28#define RX 0
28#define TX 1 29#define TX 1
@@ -407,6 +408,7 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
407 struct fsl_asoc_card_priv *priv; 408 struct fsl_asoc_card_priv *priv;
408 struct i2c_client *codec_dev; 409 struct i2c_client *codec_dev;
409 struct clk *codec_clk; 410 struct clk *codec_clk;
411 const char *codec_dai_name;
410 u32 width; 412 u32 width;
411 int ret; 413 int ret;
412 414
@@ -459,6 +461,7 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
459 461
460 /* Diversify the card configurations */ 462 /* Diversify the card configurations */
461 if (of_device_is_compatible(np, "fsl,imx-audio-cs42888")) { 463 if (of_device_is_compatible(np, "fsl,imx-audio-cs42888")) {
464 codec_dai_name = "cs42888";
462 priv->card.set_bias_level = NULL; 465 priv->card.set_bias_level = NULL;
463 priv->cpu_priv.sysclk_freq[TX] = priv->codec_priv.mclk_freq; 466 priv->cpu_priv.sysclk_freq[TX] = priv->codec_priv.mclk_freq;
464 priv->cpu_priv.sysclk_freq[RX] = priv->codec_priv.mclk_freq; 467 priv->cpu_priv.sysclk_freq[RX] = priv->codec_priv.mclk_freq;
@@ -467,14 +470,22 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
467 priv->cpu_priv.slot_width = 32; 470 priv->cpu_priv.slot_width = 32;
468 priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; 471 priv->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
469 } else if (of_device_is_compatible(np, "fsl,imx-audio-sgtl5000")) { 472 } else if (of_device_is_compatible(np, "fsl,imx-audio-sgtl5000")) {
473 codec_dai_name = "sgtl5000";
470 priv->codec_priv.mclk_id = SGTL5000_SYSCLK; 474 priv->codec_priv.mclk_id = SGTL5000_SYSCLK;
471 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; 475 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
472 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8962")) { 476 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8962")) {
477 codec_dai_name = "wm8962";
473 priv->card.set_bias_level = fsl_asoc_card_set_bias_level; 478 priv->card.set_bias_level = fsl_asoc_card_set_bias_level;
474 priv->codec_priv.mclk_id = WM8962_SYSCLK_MCLK; 479 priv->codec_priv.mclk_id = WM8962_SYSCLK_MCLK;
475 priv->codec_priv.fll_id = WM8962_SYSCLK_FLL; 480 priv->codec_priv.fll_id = WM8962_SYSCLK_FLL;
476 priv->codec_priv.pll_id = WM8962_FLL; 481 priv->codec_priv.pll_id = WM8962_FLL;
477 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; 482 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
483 } else if (of_device_is_compatible(np, "fsl,imx-audio-wm8960")) {
484 codec_dai_name = "wm8960-hifi";
485 priv->card.set_bias_level = fsl_asoc_card_set_bias_level;
486 priv->codec_priv.fll_id = WM8960_SYSCLK_AUTO;
487 priv->codec_priv.pll_id = WM8960_SYSCLK_AUTO;
488 priv->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
478 } else { 489 } else {
479 dev_err(&pdev->dev, "unknown Device Tree compatible\n"); 490 dev_err(&pdev->dev, "unknown Device Tree compatible\n");
480 return -EINVAL; 491 return -EINVAL;
@@ -521,7 +532,7 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
521 /* Normal DAI Link */ 532 /* Normal DAI Link */
522 priv->dai_link[0].cpu_of_node = cpu_np; 533 priv->dai_link[0].cpu_of_node = cpu_np;
523 priv->dai_link[0].codec_of_node = codec_np; 534 priv->dai_link[0].codec_of_node = codec_np;
524 priv->dai_link[0].codec_dai_name = codec_dev->name; 535 priv->dai_link[0].codec_dai_name = codec_dai_name;
525 priv->dai_link[0].platform_of_node = cpu_np; 536 priv->dai_link[0].platform_of_node = cpu_np;
526 priv->dai_link[0].dai_fmt = priv->dai_fmt; 537 priv->dai_link[0].dai_fmt = priv->dai_fmt;
527 priv->card.num_links = 1; 538 priv->card.num_links = 1;
@@ -530,7 +541,7 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
530 /* DPCM DAI Links only if ASRC exsits */ 541 /* DPCM DAI Links only if ASRC exsits */
531 priv->dai_link[1].cpu_of_node = asrc_np; 542 priv->dai_link[1].cpu_of_node = asrc_np;
532 priv->dai_link[1].platform_of_node = asrc_np; 543 priv->dai_link[1].platform_of_node = asrc_np;
533 priv->dai_link[2].codec_dai_name = codec_dev->name; 544 priv->dai_link[2].codec_dai_name = codec_dai_name;
534 priv->dai_link[2].codec_of_node = codec_np; 545 priv->dai_link[2].codec_of_node = codec_np;
535 priv->dai_link[2].cpu_of_node = cpu_np; 546 priv->dai_link[2].cpu_of_node = cpu_np;
536 priv->dai_link[2].dai_fmt = priv->dai_fmt; 547 priv->dai_link[2].dai_fmt = priv->dai_fmt;
@@ -578,6 +589,7 @@ static const struct of_device_id fsl_asoc_card_dt_ids[] = {
578 { .compatible = "fsl,imx-audio-cs42888", }, 589 { .compatible = "fsl,imx-audio-cs42888", },
579 { .compatible = "fsl,imx-audio-sgtl5000", }, 590 { .compatible = "fsl,imx-audio-sgtl5000", },
580 { .compatible = "fsl,imx-audio-wm8962", }, 591 { .compatible = "fsl,imx-audio-wm8962", },
592 { .compatible = "fsl,imx-audio-wm8960", },
581 {} 593 {}
582}; 594};
583 595
diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c
index c068494bae30..9f087d4f73ed 100644
--- a/sound/soc/fsl/fsl_asrc.c
+++ b/sound/soc/fsl/fsl_asrc.c
@@ -931,14 +931,29 @@ static int fsl_asrc_probe(struct platform_device *pdev)
931static int fsl_asrc_runtime_resume(struct device *dev) 931static int fsl_asrc_runtime_resume(struct device *dev)
932{ 932{
933 struct fsl_asrc *asrc_priv = dev_get_drvdata(dev); 933 struct fsl_asrc *asrc_priv = dev_get_drvdata(dev);
934 int i; 934 int i, ret;
935 935
936 clk_prepare_enable(asrc_priv->mem_clk); 936 ret = clk_prepare_enable(asrc_priv->mem_clk);
937 clk_prepare_enable(asrc_priv->ipg_clk); 937 if (ret)
938 for (i = 0; i < ASRC_CLK_MAX_NUM; i++) 938 return ret;
939 clk_prepare_enable(asrc_priv->asrck_clk[i]); 939 ret = clk_prepare_enable(asrc_priv->ipg_clk);
940 if (ret)
941 goto disable_mem_clk;
942 for (i = 0; i < ASRC_CLK_MAX_NUM; i++) {
943 ret = clk_prepare_enable(asrc_priv->asrck_clk[i]);
944 if (ret)
945 goto disable_asrck_clk;
946 }
940 947
941 return 0; 948 return 0;
949
950disable_asrck_clk:
951 for (i--; i >= 0; i--)
952 clk_disable_unprepare(asrc_priv->asrck_clk[i]);
953 clk_disable_unprepare(asrc_priv->ipg_clk);
954disable_mem_clk:
955 clk_disable_unprepare(asrc_priv->mem_clk);
956 return ret;
942} 957}
943 958
944static int fsl_asrc_runtime_suspend(struct device *dev) 959static int fsl_asrc_runtime_suspend(struct device *dev)
diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c
index 5c7597191e3f..8c2ddc1ea954 100644
--- a/sound/soc/fsl/fsl_esai.c
+++ b/sound/soc/fsl/fsl_esai.c
@@ -839,7 +839,7 @@ static int fsl_esai_probe(struct platform_device *pdev)
839 return ret; 839 return ret;
840 } 840 }
841 841
842 ret = imx_pcm_dma_init(pdev); 842 ret = imx_pcm_dma_init(pdev, IMX_ESAI_DMABUF_SIZE);
843 if (ret) 843 if (ret)
844 dev_err(&pdev->dev, "failed to init imx pcm dma: %d\n", ret); 844 dev_err(&pdev->dev, "failed to init imx pcm dma: %d\n", ret);
845 845
diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
index 5c73bea7b11e..a18fd92c4a85 100644
--- a/sound/soc/fsl/fsl_sai.c
+++ b/sound/soc/fsl/fsl_sai.c
@@ -791,7 +791,7 @@ static int fsl_sai_probe(struct platform_device *pdev)
791 return ret; 791 return ret;
792 792
793 if (sai->sai_on_imx) 793 if (sai->sai_on_imx)
794 return imx_pcm_dma_init(pdev); 794 return imx_pcm_dma_init(pdev, IMX_SAI_DMABUF_SIZE);
795 else 795 else
796 return devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); 796 return devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
797} 797}
diff --git a/sound/soc/fsl/fsl_sai.h b/sound/soc/fsl/fsl_sai.h
index 066280953c85..b95fbc3f68eb 100644
--- a/sound/soc/fsl/fsl_sai.h
+++ b/sound/soc/fsl/fsl_sai.h
@@ -13,7 +13,8 @@
13 13
14#define FSL_SAI_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\ 14#define FSL_SAI_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
15 SNDRV_PCM_FMTBIT_S20_3LE |\ 15 SNDRV_PCM_FMTBIT_S20_3LE |\
16 SNDRV_PCM_FMTBIT_S24_LE) 16 SNDRV_PCM_FMTBIT_S24_LE |\
17 SNDRV_PCM_FMTBIT_S32_LE)
17 18
18/* SAI Register Map Register */ 19/* SAI Register Map Register */
19#define FSL_SAI_TCSR 0x00 /* SAI Transmit Control */ 20#define FSL_SAI_TCSR 0x00 /* SAI Transmit Control */
@@ -45,7 +46,7 @@
45#define FSL_SAI_xFR(tx) (tx ? FSL_SAI_TFR : FSL_SAI_RFR) 46#define FSL_SAI_xFR(tx) (tx ? FSL_SAI_TFR : FSL_SAI_RFR)
46#define FSL_SAI_xMR(tx) (tx ? FSL_SAI_TMR : FSL_SAI_RMR) 47#define FSL_SAI_xMR(tx) (tx ? FSL_SAI_TMR : FSL_SAI_RMR)
47 48
48/* SAI Transmit/Recieve Control Register */ 49/* SAI Transmit/Receive Control Register */
49#define FSL_SAI_CSR_TERE BIT(31) 50#define FSL_SAI_CSR_TERE BIT(31)
50#define FSL_SAI_CSR_FR BIT(25) 51#define FSL_SAI_CSR_FR BIT(25)
51#define FSL_SAI_CSR_SR BIT(24) 52#define FSL_SAI_CSR_SR BIT(24)
@@ -67,10 +68,10 @@
67#define FSL_SAI_CSR_FRIE BIT(8) 68#define FSL_SAI_CSR_FRIE BIT(8)
68#define FSL_SAI_CSR_FRDE BIT(0) 69#define FSL_SAI_CSR_FRDE BIT(0)
69 70
70/* SAI Transmit and Recieve Configuration 1 Register */ 71/* SAI Transmit and Receive Configuration 1 Register */
71#define FSL_SAI_CR1_RFW_MASK 0x1f 72#define FSL_SAI_CR1_RFW_MASK 0x1f
72 73
73/* SAI Transmit and Recieve Configuration 2 Register */ 74/* SAI Transmit and Receive Configuration 2 Register */
74#define FSL_SAI_CR2_SYNC BIT(30) 75#define FSL_SAI_CR2_SYNC BIT(30)
75#define FSL_SAI_CR2_MSEL_MASK (0x3 << 26) 76#define FSL_SAI_CR2_MSEL_MASK (0x3 << 26)
76#define FSL_SAI_CR2_MSEL_BUS 0 77#define FSL_SAI_CR2_MSEL_BUS 0
@@ -82,12 +83,12 @@
82#define FSL_SAI_CR2_BCD_MSTR BIT(24) 83#define FSL_SAI_CR2_BCD_MSTR BIT(24)
83#define FSL_SAI_CR2_DIV_MASK 0xff 84#define FSL_SAI_CR2_DIV_MASK 0xff
84 85
85/* SAI Transmit and Recieve Configuration 3 Register */ 86/* SAI Transmit and Receive Configuration 3 Register */
86#define FSL_SAI_CR3_TRCE BIT(16) 87#define FSL_SAI_CR3_TRCE BIT(16)
87#define FSL_SAI_CR3_WDFL(x) (x) 88#define FSL_SAI_CR3_WDFL(x) (x)
88#define FSL_SAI_CR3_WDFL_MASK 0x1f 89#define FSL_SAI_CR3_WDFL_MASK 0x1f
89 90
90/* SAI Transmit and Recieve Configuration 4 Register */ 91/* SAI Transmit and Receive Configuration 4 Register */
91#define FSL_SAI_CR4_FRSZ(x) (((x) - 1) << 16) 92#define FSL_SAI_CR4_FRSZ(x) (((x) - 1) << 16)
92#define FSL_SAI_CR4_FRSZ_MASK (0x1f << 16) 93#define FSL_SAI_CR4_FRSZ_MASK (0x1f << 16)
93#define FSL_SAI_CR4_SYWD(x) (((x) - 1) << 8) 94#define FSL_SAI_CR4_SYWD(x) (((x) - 1) << 8)
@@ -97,7 +98,7 @@
97#define FSL_SAI_CR4_FSP BIT(1) 98#define FSL_SAI_CR4_FSP BIT(1)
98#define FSL_SAI_CR4_FSD_MSTR BIT(0) 99#define FSL_SAI_CR4_FSD_MSTR BIT(0)
99 100
100/* SAI Transmit and Recieve Configuration 5 Register */ 101/* SAI Transmit and Receive Configuration 5 Register */
101#define FSL_SAI_CR5_WNW(x) (((x) - 1) << 24) 102#define FSL_SAI_CR5_WNW(x) (((x) - 1) << 24)
102#define FSL_SAI_CR5_WNW_MASK (0x1f << 24) 103#define FSL_SAI_CR5_WNW_MASK (0x1f << 24)
103#define FSL_SAI_CR5_W0W(x) (((x) - 1) << 16) 104#define FSL_SAI_CR5_W0W(x) (((x) - 1) << 16)
diff --git a/sound/soc/fsl/fsl_spdif.c b/sound/soc/fsl/fsl_spdif.c
index 8e932219cb3a..ab729f2426fe 100644
--- a/sound/soc/fsl/fsl_spdif.c
+++ b/sound/soc/fsl/fsl_spdif.c
@@ -454,7 +454,8 @@ static int fsl_spdif_startup(struct snd_pcm_substream *substream,
454 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(rtd->cpu_dai); 454 struct fsl_spdif_priv *spdif_priv = snd_soc_dai_get_drvdata(rtd->cpu_dai);
455 struct platform_device *pdev = spdif_priv->pdev; 455 struct platform_device *pdev = spdif_priv->pdev;
456 struct regmap *regmap = spdif_priv->regmap; 456 struct regmap *regmap = spdif_priv->regmap;
457 u32 scr, mask, i; 457 u32 scr, mask;
458 int i;
458 int ret; 459 int ret;
459 460
460 /* Reset module and interrupts only for first initialization */ 461 /* Reset module and interrupts only for first initialization */
@@ -482,13 +483,18 @@ static int fsl_spdif_startup(struct snd_pcm_substream *substream,
482 mask = SCR_TXFIFO_AUTOSYNC_MASK | SCR_TXFIFO_CTRL_MASK | 483 mask = SCR_TXFIFO_AUTOSYNC_MASK | SCR_TXFIFO_CTRL_MASK |
483 SCR_TXSEL_MASK | SCR_USRC_SEL_MASK | 484 SCR_TXSEL_MASK | SCR_USRC_SEL_MASK |
484 SCR_TXFIFO_FSEL_MASK; 485 SCR_TXFIFO_FSEL_MASK;
485 for (i = 0; i < SPDIF_TXRATE_MAX; i++) 486 for (i = 0; i < SPDIF_TXRATE_MAX; i++) {
486 clk_prepare_enable(spdif_priv->txclk[i]); 487 ret = clk_prepare_enable(spdif_priv->txclk[i]);
488 if (ret)
489 goto disable_txclk;
490 }
487 } else { 491 } else {
488 scr = SCR_RXFIFO_FSEL_IF8 | SCR_RXFIFO_AUTOSYNC; 492 scr = SCR_RXFIFO_FSEL_IF8 | SCR_RXFIFO_AUTOSYNC;
489 mask = SCR_RXFIFO_FSEL_MASK | SCR_RXFIFO_AUTOSYNC_MASK| 493 mask = SCR_RXFIFO_FSEL_MASK | SCR_RXFIFO_AUTOSYNC_MASK|
490 SCR_RXFIFO_CTL_MASK | SCR_RXFIFO_OFF_MASK; 494 SCR_RXFIFO_CTL_MASK | SCR_RXFIFO_OFF_MASK;
491 clk_prepare_enable(spdif_priv->rxclk); 495 ret = clk_prepare_enable(spdif_priv->rxclk);
496 if (ret)
497 goto err;
492 } 498 }
493 regmap_update_bits(regmap, REG_SPDIF_SCR, mask, scr); 499 regmap_update_bits(regmap, REG_SPDIF_SCR, mask, scr);
494 500
@@ -497,6 +503,9 @@ static int fsl_spdif_startup(struct snd_pcm_substream *substream,
497 503
498 return 0; 504 return 0;
499 505
506disable_txclk:
507 for (i--; i >= 0; i--)
508 clk_disable_unprepare(spdif_priv->txclk[i]);
500err: 509err:
501 clk_disable_unprepare(spdif_priv->coreclk); 510 clk_disable_unprepare(spdif_priv->coreclk);
502 511
@@ -707,7 +716,7 @@ static int fsl_spdif_subcode_get(struct snd_kcontrol *kcontrol,
707 return ret; 716 return ret;
708} 717}
709 718
710/* Q-subcode infomation. The byte size is SPDIF_UBITS_SIZE/8 */ 719/* Q-subcode information. The byte size is SPDIF_UBITS_SIZE/8 */
711static int fsl_spdif_qinfo(struct snd_kcontrol *kcontrol, 720static int fsl_spdif_qinfo(struct snd_kcontrol *kcontrol,
712 struct snd_ctl_elem_info *uinfo) 721 struct snd_ctl_elem_info *uinfo)
713{ 722{
@@ -739,7 +748,7 @@ static int fsl_spdif_qget(struct snd_kcontrol *kcontrol,
739 return ret; 748 return ret;
740} 749}
741 750
742/* Valid bit infomation */ 751/* Valid bit information */
743static int fsl_spdif_vbit_info(struct snd_kcontrol *kcontrol, 752static int fsl_spdif_vbit_info(struct snd_kcontrol *kcontrol,
744 struct snd_ctl_elem_info *uinfo) 753 struct snd_ctl_elem_info *uinfo)
745{ 754{
@@ -767,7 +776,7 @@ static int fsl_spdif_vbit_get(struct snd_kcontrol *kcontrol,
767 return 0; 776 return 0;
768} 777}
769 778
770/* DPLL lock infomation */ 779/* DPLL lock information */
771static int fsl_spdif_rxrate_info(struct snd_kcontrol *kcontrol, 780static int fsl_spdif_rxrate_info(struct snd_kcontrol *kcontrol,
772 struct snd_ctl_elem_info *uinfo) 781 struct snd_ctl_elem_info *uinfo)
773{ 782{
@@ -1255,7 +1264,7 @@ static int fsl_spdif_probe(struct platform_device *pdev)
1255 return ret; 1264 return ret;
1256 } 1265 }
1257 1266
1258 ret = imx_pcm_dma_init(pdev); 1267 ret = imx_pcm_dma_init(pdev, IMX_SPDIF_DMABUF_SIZE);
1259 if (ret) 1268 if (ret)
1260 dev_err(&pdev->dev, "imx_pcm_dma_init failed: %d\n", ret); 1269 dev_err(&pdev->dev, "imx_pcm_dma_init failed: %d\n", ret);
1261 1270
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index c7647e066cfd..8ec6fb208ea0 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -156,7 +156,7 @@ struct fsl_ssi_soc_data {
156 * 156 *
157 * @dbg_stats: Debugging statistics 157 * @dbg_stats: Debugging statistics
158 * 158 *
159 * @soc: SoC specifc data 159 * @soc: SoC specific data
160 */ 160 */
161struct fsl_ssi_private { 161struct fsl_ssi_private {
162 struct regmap *regs; 162 struct regmap *regs;
@@ -633,7 +633,7 @@ static int fsl_ssi_set_bclk(struct snd_pcm_substream *substream,
633 sub *= 100000; 633 sub *= 100000;
634 do_div(sub, freq); 634 do_div(sub, freq);
635 635
636 if (sub < savesub) { 636 if (sub < savesub && !(i == 0 && psr == 0 && div2 == 0)) {
637 baudrate = tmprate; 637 baudrate = tmprate;
638 savesub = sub; 638 savesub = sub;
639 pm = i; 639 pm = i;
@@ -900,14 +900,16 @@ static int _fsl_ssi_set_dai_fmt(struct device *dev,
900 scr &= ~CCSR_SSI_SCR_SYS_CLK_EN; 900 scr &= ~CCSR_SSI_SCR_SYS_CLK_EN;
901 break; 901 break;
902 default: 902 default:
903 return -EINVAL; 903 if (!fsl_ssi_is_ac97(ssi_private))
904 return -EINVAL;
904 } 905 }
905 906
906 stcr |= strcr; 907 stcr |= strcr;
907 srcr |= strcr; 908 srcr |= strcr;
908 909
909 if (ssi_private->cpu_dai_drv.symmetric_rates) { 910 if (ssi_private->cpu_dai_drv.symmetric_rates
910 /* Need to clear RXDIR when using SYNC mode */ 911 || fsl_ssi_is_ac97(ssi_private)) {
912 /* Need to clear RXDIR when using SYNC or AC97 mode */
911 srcr &= ~CCSR_SSI_SRCR_RXDIR; 913 srcr &= ~CCSR_SSI_SRCR_RXDIR;
912 scr |= CCSR_SSI_SCR_SYN; 914 scr |= CCSR_SSI_SCR_SYN;
913 } 915 }
@@ -1101,6 +1103,7 @@ static const struct snd_soc_component_driver fsl_ssi_component = {
1101 1103
1102static struct snd_soc_dai_driver fsl_ssi_ac97_dai = { 1104static struct snd_soc_dai_driver fsl_ssi_ac97_dai = {
1103 .bus_control = true, 1105 .bus_control = true,
1106 .probe = fsl_ssi_dai_probe,
1104 .playback = { 1107 .playback = {
1105 .stream_name = "AC97 Playback", 1108 .stream_name = "AC97 Playback",
1106 .channels_min = 2, 1109 .channels_min = 2,
@@ -1127,10 +1130,17 @@ static void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
1127 struct regmap *regs = fsl_ac97_data->regs; 1130 struct regmap *regs = fsl_ac97_data->regs;
1128 unsigned int lreg; 1131 unsigned int lreg;
1129 unsigned int lval; 1132 unsigned int lval;
1133 int ret;
1130 1134
1131 if (reg > 0x7f) 1135 if (reg > 0x7f)
1132 return; 1136 return;
1133 1137
1138 ret = clk_prepare_enable(fsl_ac97_data->clk);
1139 if (ret) {
1140 pr_err("ac97 write clk_prepare_enable failed: %d\n",
1141 ret);
1142 return;
1143 }
1134 1144
1135 lreg = reg << 12; 1145 lreg = reg << 12;
1136 regmap_write(regs, CCSR_SSI_SACADD, lreg); 1146 regmap_write(regs, CCSR_SSI_SACADD, lreg);
@@ -1141,6 +1151,8 @@ static void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
1141 regmap_update_bits(regs, CCSR_SSI_SACNT, CCSR_SSI_SACNT_RDWR_MASK, 1151 regmap_update_bits(regs, CCSR_SSI_SACNT, CCSR_SSI_SACNT_RDWR_MASK,
1142 CCSR_SSI_SACNT_WR); 1152 CCSR_SSI_SACNT_WR);
1143 udelay(100); 1153 udelay(100);
1154
1155 clk_disable_unprepare(fsl_ac97_data->clk);
1144} 1156}
1145 1157
1146static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97, 1158static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97,
@@ -1151,6 +1163,14 @@ static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97,
1151 unsigned short val = -1; 1163 unsigned short val = -1;
1152 u32 reg_val; 1164 u32 reg_val;
1153 unsigned int lreg; 1165 unsigned int lreg;
1166 int ret;
1167
1168 ret = clk_prepare_enable(fsl_ac97_data->clk);
1169 if (ret) {
1170 pr_err("ac97 read clk_prepare_enable failed: %d\n",
1171 ret);
1172 return -1;
1173 }
1154 1174
1155 lreg = (reg & 0x7f) << 12; 1175 lreg = (reg & 0x7f) << 12;
1156 regmap_write(regs, CCSR_SSI_SACADD, lreg); 1176 regmap_write(regs, CCSR_SSI_SACADD, lreg);
@@ -1162,6 +1182,8 @@ static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97,
1162 regmap_read(regs, CCSR_SSI_SACDAT, &reg_val); 1182 regmap_read(regs, CCSR_SSI_SACDAT, &reg_val);
1163 val = (reg_val >> 4) & 0xffff; 1183 val = (reg_val >> 4) & 0xffff;
1164 1184
1185 clk_disable_unprepare(fsl_ac97_data->clk);
1186
1165 return val; 1187 return val;
1166} 1188}
1167 1189
@@ -1210,7 +1232,7 @@ static int fsl_ssi_imx_probe(struct platform_device *pdev,
1210 } 1232 }
1211 } 1233 }
1212 1234
1213 /* For those SLAVE implementations, we ingore non-baudclk cases 1235 /* For those SLAVE implementations, we ignore non-baudclk cases
1214 * and, instead, abandon MASTER mode that needs baud clock. 1236 * and, instead, abandon MASTER mode that needs baud clock.
1215 */ 1237 */
1216 ssi_private->baudclk = devm_clk_get(&pdev->dev, "baud"); 1238 ssi_private->baudclk = devm_clk_get(&pdev->dev, "baud");
@@ -1257,7 +1279,7 @@ static int fsl_ssi_imx_probe(struct platform_device *pdev,
1257 if (ret) 1279 if (ret)
1258 goto error_pcm; 1280 goto error_pcm;
1259 } else { 1281 } else {
1260 ret = imx_pcm_dma_init(pdev); 1282 ret = imx_pcm_dma_init(pdev, IMX_SSI_DMABUF_SIZE);
1261 if (ret) 1283 if (ret)
1262 goto error_pcm; 1284 goto error_pcm;
1263 } 1285 }
@@ -1320,7 +1342,11 @@ static int fsl_ssi_probe(struct platform_device *pdev)
1320 1342
1321 fsl_ac97_data = ssi_private; 1343 fsl_ac97_data = ssi_private;
1322 1344
1323 snd_soc_set_ac97_ops_of_reset(&fsl_ssi_ac97_ops, pdev); 1345 ret = snd_soc_set_ac97_ops_of_reset(&fsl_ssi_ac97_ops, pdev);
1346 if (ret) {
1347 dev_err(&pdev->dev, "could not set AC'97 ops\n");
1348 return ret;
1349 }
1324 } else { 1350 } else {
1325 /* Initialize this copy of the CPU DAI driver structure */ 1351 /* Initialize this copy of the CPU DAI driver structure */
1326 memcpy(&ssi_private->cpu_dai_drv, &fsl_ssi_dai_template, 1352 memcpy(&ssi_private->cpu_dai_drv, &fsl_ssi_dai_template,
@@ -1357,7 +1383,9 @@ static int fsl_ssi_probe(struct platform_device *pdev)
1357 1383
1358 /* Are the RX and the TX clocks locked? */ 1384 /* Are the RX and the TX clocks locked? */
1359 if (!of_find_property(np, "fsl,ssi-asynchronous", NULL)) { 1385 if (!of_find_property(np, "fsl,ssi-asynchronous", NULL)) {
1360 ssi_private->cpu_dai_drv.symmetric_rates = 1; 1386 if (!fsl_ssi_is_ac97(ssi_private))
1387 ssi_private->cpu_dai_drv.symmetric_rates = 1;
1388
1361 ssi_private->cpu_dai_drv.symmetric_channels = 1; 1389 ssi_private->cpu_dai_drv.symmetric_channels = 1;
1362 ssi_private->cpu_dai_drv.symmetric_samplebits = 1; 1390 ssi_private->cpu_dai_drv.symmetric_samplebits = 1;
1363 } 1391 }
@@ -1434,6 +1462,27 @@ done:
1434 _fsl_ssi_set_dai_fmt(&pdev->dev, ssi_private, 1462 _fsl_ssi_set_dai_fmt(&pdev->dev, ssi_private,
1435 ssi_private->dai_fmt); 1463 ssi_private->dai_fmt);
1436 1464
1465 if (fsl_ssi_is_ac97(ssi_private)) {
1466 u32 ssi_idx;
1467
1468 ret = of_property_read_u32(np, "cell-index", &ssi_idx);
1469 if (ret) {
1470 dev_err(&pdev->dev, "cannot get SSI index property\n");
1471 goto error_sound_card;
1472 }
1473
1474 ssi_private->pdev =
1475 platform_device_register_data(NULL,
1476 "ac97-codec", ssi_idx, NULL, 0);
1477 if (IS_ERR(ssi_private->pdev)) {
1478 ret = PTR_ERR(ssi_private->pdev);
1479 dev_err(&pdev->dev,
1480 "failed to register AC97 codec platform: %d\n",
1481 ret);
1482 goto error_sound_card;
1483 }
1484 }
1485
1437 return 0; 1486 return 0;
1438 1487
1439error_sound_card: 1488error_sound_card:
@@ -1458,6 +1507,9 @@ static int fsl_ssi_remove(struct platform_device *pdev)
1458 if (ssi_private->soc->imx) 1507 if (ssi_private->soc->imx)
1459 fsl_ssi_imx_clean(pdev, ssi_private); 1508 fsl_ssi_imx_clean(pdev, ssi_private);
1460 1509
1510 if (fsl_ssi_is_ac97(ssi_private))
1511 snd_soc_set_ac97_ops(NULL);
1512
1461 return 0; 1513 return 0;
1462} 1514}
1463 1515
diff --git a/sound/soc/fsl/imx-pcm-dma.c b/sound/soc/fsl/imx-pcm-dma.c
index 0db94f492e97..1fc01ed3279d 100644
--- a/sound/soc/fsl/imx-pcm-dma.c
+++ b/sound/soc/fsl/imx-pcm-dma.c
@@ -40,7 +40,7 @@ static const struct snd_pcm_hardware imx_pcm_hardware = {
40 SNDRV_PCM_INFO_MMAP_VALID | 40 SNDRV_PCM_INFO_MMAP_VALID |
41 SNDRV_PCM_INFO_PAUSE | 41 SNDRV_PCM_INFO_PAUSE |
42 SNDRV_PCM_INFO_RESUME, 42 SNDRV_PCM_INFO_RESUME,
43 .buffer_bytes_max = IMX_SSI_DMABUF_SIZE, 43 .buffer_bytes_max = IMX_DEFAULT_DMABUF_SIZE,
44 .period_bytes_min = 128, 44 .period_bytes_min = 128,
45 .period_bytes_max = 65535, /* Limited by SDMA engine */ 45 .period_bytes_max = 65535, /* Limited by SDMA engine */
46 .periods_min = 2, 46 .periods_min = 2,
@@ -52,13 +52,30 @@ static const struct snd_dmaengine_pcm_config imx_dmaengine_pcm_config = {
52 .pcm_hardware = &imx_pcm_hardware, 52 .pcm_hardware = &imx_pcm_hardware,
53 .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config, 53 .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
54 .compat_filter_fn = filter, 54 .compat_filter_fn = filter,
55 .prealloc_buffer_size = IMX_SSI_DMABUF_SIZE, 55 .prealloc_buffer_size = IMX_DEFAULT_DMABUF_SIZE,
56}; 56};
57 57
58int imx_pcm_dma_init(struct platform_device *pdev) 58int imx_pcm_dma_init(struct platform_device *pdev, size_t size)
59{ 59{
60 struct snd_dmaengine_pcm_config *config;
61 struct snd_pcm_hardware *pcm_hardware;
62
63 config = devm_kzalloc(&pdev->dev,
64 sizeof(struct snd_dmaengine_pcm_config), GFP_KERNEL);
65 *config = imx_dmaengine_pcm_config;
66 if (size)
67 config->prealloc_buffer_size = size;
68
69 pcm_hardware = devm_kzalloc(&pdev->dev,
70 sizeof(struct snd_pcm_hardware), GFP_KERNEL);
71 *pcm_hardware = imx_pcm_hardware;
72 if (size)
73 pcm_hardware->buffer_bytes_max = size;
74
75 config->pcm_hardware = pcm_hardware;
76
60 return devm_snd_dmaengine_pcm_register(&pdev->dev, 77 return devm_snd_dmaengine_pcm_register(&pdev->dev,
61 &imx_dmaengine_pcm_config, 78 config,
62 SND_DMAENGINE_PCM_FLAG_COMPAT); 79 SND_DMAENGINE_PCM_FLAG_COMPAT);
63} 80}
64EXPORT_SYMBOL_GPL(imx_pcm_dma_init); 81EXPORT_SYMBOL_GPL(imx_pcm_dma_init);
diff --git a/sound/soc/fsl/imx-pcm.h b/sound/soc/fsl/imx-pcm.h
index c79cb27473be..133c4470acad 100644
--- a/sound/soc/fsl/imx-pcm.h
+++ b/sound/soc/fsl/imx-pcm.h
@@ -20,6 +20,11 @@
20 */ 20 */
21#define IMX_SSI_DMABUF_SIZE (64 * 1024) 21#define IMX_SSI_DMABUF_SIZE (64 * 1024)
22 22
23#define IMX_DEFAULT_DMABUF_SIZE (64 * 1024)
24#define IMX_SAI_DMABUF_SIZE (64 * 1024)
25#define IMX_SPDIF_DMABUF_SIZE (64 * 1024)
26#define IMX_ESAI_DMABUF_SIZE (256 * 1024)
27
23static inline void 28static inline void
24imx_pcm_dma_params_init_data(struct imx_dma_data *dma_data, 29imx_pcm_dma_params_init_data(struct imx_dma_data *dma_data,
25 int dma, enum sdma_peripheral_type peripheral_type) 30 int dma, enum sdma_peripheral_type peripheral_type)
@@ -39,9 +44,9 @@ struct imx_pcm_fiq_params {
39}; 44};
40 45
41#if IS_ENABLED(CONFIG_SND_SOC_IMX_PCM_DMA) 46#if IS_ENABLED(CONFIG_SND_SOC_IMX_PCM_DMA)
42int imx_pcm_dma_init(struct platform_device *pdev); 47int imx_pcm_dma_init(struct platform_device *pdev, size_t size);
43#else 48#else
44static inline int imx_pcm_dma_init(struct platform_device *pdev) 49static inline int imx_pcm_dma_init(struct platform_device *pdev, size_t size)
45{ 50{
46 return -ENODEV; 51 return -ENODEV;
47} 52}
diff --git a/sound/soc/fsl/imx-ssi.c b/sound/soc/fsl/imx-ssi.c
index 461ce27b884f..48b2d24dd1f0 100644
--- a/sound/soc/fsl/imx-ssi.c
+++ b/sound/soc/fsl/imx-ssi.c
@@ -603,7 +603,7 @@ static int imx_ssi_probe(struct platform_device *pdev)
603 ssi->fiq_params.dma_params_tx = &ssi->dma_params_tx; 603 ssi->fiq_params.dma_params_tx = &ssi->dma_params_tx;
604 604
605 ssi->fiq_init = imx_pcm_fiq_init(pdev, &ssi->fiq_params); 605 ssi->fiq_init = imx_pcm_fiq_init(pdev, &ssi->fiq_params);
606 ssi->dma_init = imx_pcm_dma_init(pdev); 606 ssi->dma_init = imx_pcm_dma_init(pdev, IMX_SSI_DMABUF_SIZE);
607 607
608 if (ssi->fiq_init && ssi->dma_init) { 608 if (ssi->fiq_init && ssi->dma_init) {
609 ret = ssi->fiq_init; 609 ret = ssi->fiq_init;
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index d5554939146e..3ff76d419436 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -76,6 +76,7 @@ static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream,
76{ 76{
77 struct snd_soc_pcm_runtime *rtd = substream->private_data; 77 struct snd_soc_pcm_runtime *rtd = substream->private_data;
78 struct snd_soc_dai *codec_dai = rtd->codec_dai; 78 struct snd_soc_dai *codec_dai = rtd->codec_dai;
79 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
79 struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card); 80 struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
80 struct simple_dai_props *dai_props = 81 struct simple_dai_props *dai_props =
81 &priv->dai_props[rtd - rtd->card->rtd]; 82 &priv->dai_props[rtd - rtd->card->rtd];
@@ -91,8 +92,16 @@ static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream,
91 mclk = params_rate(params) * mclk_fs; 92 mclk = params_rate(params) * mclk_fs;
92 ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, 93 ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
93 SND_SOC_CLOCK_IN); 94 SND_SOC_CLOCK_IN);
95 if (ret && ret != -ENOTSUPP)
96 goto err;
97
98 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
99 SND_SOC_CLOCK_OUT);
100 if (ret && ret != -ENOTSUPP)
101 goto err;
94 } 102 }
95 103
104err:
96 return ret; 105 return ret;
97} 106}
98 107
diff --git a/sound/soc/intel/Kconfig b/sound/soc/intel/Kconfig
index f3060a4ca040..05fde5e6e257 100644
--- a/sound/soc/intel/Kconfig
+++ b/sound/soc/intel/Kconfig
@@ -26,14 +26,9 @@ config SND_SST_IPC_ACPI
26 depends on ACPI 26 depends on ACPI
27 27
28config SND_SOC_INTEL_SST 28config SND_SOC_INTEL_SST
29 tristate "ASoC support for Intel(R) Smart Sound Technology" 29 tristate
30 select SND_SOC_INTEL_SST_ACPI if ACPI 30 select SND_SOC_INTEL_SST_ACPI if ACPI
31 depends on (X86 || COMPILE_TEST) 31 depends on (X86 || COMPILE_TEST)
32 depends on DW_DMAC_CORE
33 help
34 This adds support for Intel(R) Smart Sound Technology (SST).
35 Say Y if you have such a device
36 If unsure select "N".
37 32
38config SND_SOC_INTEL_SST_ACPI 33config SND_SOC_INTEL_SST_ACPI
39 tristate 34 tristate
@@ -46,8 +41,9 @@ config SND_SOC_INTEL_BAYTRAIL
46 41
47config SND_SOC_INTEL_HASWELL_MACH 42config SND_SOC_INTEL_HASWELL_MACH
48 tristate "ASoC Audio DSP support for Intel Haswell Lynxpoint" 43 tristate "ASoC Audio DSP support for Intel Haswell Lynxpoint"
49 depends on SND_SOC_INTEL_SST && X86_INTEL_LPSS && I2C && \ 44 depends on X86_INTEL_LPSS && I2C && I2C_DESIGNWARE_PLATFORM
50 I2C_DESIGNWARE_PLATFORM 45 depends on DW_DMAC_CORE
46 select SND_SOC_INTEL_SST
51 select SND_SOC_INTEL_HASWELL 47 select SND_SOC_INTEL_HASWELL
52 select SND_SOC_RT5640 48 select SND_SOC_RT5640
53 help 49 help
@@ -58,7 +54,9 @@ config SND_SOC_INTEL_HASWELL_MACH
58 54
59config SND_SOC_INTEL_BYT_RT5640_MACH 55config SND_SOC_INTEL_BYT_RT5640_MACH
60 tristate "ASoC Audio driver for Intel Baytrail with RT5640 codec" 56 tristate "ASoC Audio driver for Intel Baytrail with RT5640 codec"
61 depends on SND_SOC_INTEL_SST && X86_INTEL_LPSS && I2C 57 depends on X86_INTEL_LPSS && I2C
58 depends on DW_DMAC_CORE
59 select SND_SOC_INTEL_SST
62 select SND_SOC_INTEL_BAYTRAIL 60 select SND_SOC_INTEL_BAYTRAIL
63 select SND_SOC_RT5640 61 select SND_SOC_RT5640
64 help 62 help
@@ -67,7 +65,9 @@ config SND_SOC_INTEL_BYT_RT5640_MACH
67 65
68config SND_SOC_INTEL_BYT_MAX98090_MACH 66config SND_SOC_INTEL_BYT_MAX98090_MACH
69 tristate "ASoC Audio driver for Intel Baytrail with MAX98090 codec" 67 tristate "ASoC Audio driver for Intel Baytrail with MAX98090 codec"
70 depends on SND_SOC_INTEL_SST && X86_INTEL_LPSS && I2C 68 depends on X86_INTEL_LPSS && I2C
69 depends on DW_DMAC_CORE
70 select SND_SOC_INTEL_SST
71 select SND_SOC_INTEL_BAYTRAIL 71 select SND_SOC_INTEL_BAYTRAIL
72 select SND_SOC_MAX98090 72 select SND_SOC_MAX98090
73 help 73 help
@@ -76,8 +76,10 @@ config SND_SOC_INTEL_BYT_MAX98090_MACH
76 76
77config SND_SOC_INTEL_BROADWELL_MACH 77config SND_SOC_INTEL_BROADWELL_MACH
78 tristate "ASoC Audio DSP support for Intel Broadwell Wildcatpoint" 78 tristate "ASoC Audio DSP support for Intel Broadwell Wildcatpoint"
79 depends on SND_SOC_INTEL_SST && X86_INTEL_LPSS && DW_DMAC && \ 79 depends on X86_INTEL_LPSS && I2C && DW_DMAC && \
80 I2C_DESIGNWARE_PLATFORM 80 I2C_DESIGNWARE_PLATFORM
81 depends on DW_DMAC_CORE
82 select SND_SOC_INTEL_SST
81 select SND_SOC_INTEL_HASWELL 83 select SND_SOC_INTEL_HASWELL
82 select SND_SOC_RT286 84 select SND_SOC_RT286
83 help 85 help
@@ -132,3 +134,8 @@ config SND_SOC_INTEL_CHT_BSW_MAX98090_TI_MACH
132 This adds support for ASoC machine driver for Intel(R) Cherrytrail & Braswell 134 This adds support for ASoC machine driver for Intel(R) Cherrytrail & Braswell
133 platforms with MAX98090 audio codec it also can support TI jack chip as aux device. 135 platforms with MAX98090 audio codec it also can support TI jack chip as aux device.
134 If unsure select "N". 136 If unsure select "N".
137
138config SND_SOC_INTEL_SKYLAKE
139 tristate
140 select SND_HDA_EXT_CORE
141 select SND_SOC_INTEL_SST
diff --git a/sound/soc/intel/Makefile b/sound/soc/intel/Makefile
index 3853ec2ddbc7..2b45435e6245 100644
--- a/sound/soc/intel/Makefile
+++ b/sound/soc/intel/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_SND_SOC_INTEL_SST) += common/
5obj-$(CONFIG_SND_SOC_INTEL_HASWELL) += haswell/ 5obj-$(CONFIG_SND_SOC_INTEL_HASWELL) += haswell/
6obj-$(CONFIG_SND_SOC_INTEL_BAYTRAIL) += baytrail/ 6obj-$(CONFIG_SND_SOC_INTEL_BAYTRAIL) += baytrail/
7obj-$(CONFIG_SND_SST_MFLD_PLATFORM) += atom/ 7obj-$(CONFIG_SND_SST_MFLD_PLATFORM) += atom/
8obj-$(CONFIG_SND_SOC_INTEL_SKYLAKE) += skylake/
8 9
9# Machine support 10# Machine support
10obj-$(CONFIG_SND_SOC_INTEL_SST) += boards/ 11obj-$(CONFIG_SND_SOC) += boards/
diff --git a/sound/soc/intel/atom/sst-atom-controls.c b/sound/soc/intel/atom/sst-atom-controls.c
index 31e9b9ecbb8a..d55388e082e1 100644
--- a/sound/soc/intel/atom/sst-atom-controls.c
+++ b/sound/soc/intel/atom/sst-atom-controls.c
@@ -132,7 +132,7 @@ static int sst_send_slot_map(struct sst_data *drv)
132 sizeof(cmd.header) + cmd.header.length); 132 sizeof(cmd.header) + cmd.header.length);
133} 133}
134 134
135int sst_slot_enum_info(struct snd_kcontrol *kcontrol, 135static int sst_slot_enum_info(struct snd_kcontrol *kcontrol,
136 struct snd_ctl_elem_info *uinfo) 136 struct snd_ctl_elem_info *uinfo)
137{ 137{
138 struct sst_enum *e = (struct sst_enum *)kcontrol->private_value; 138 struct sst_enum *e = (struct sst_enum *)kcontrol->private_value;
@@ -1298,7 +1298,7 @@ int sst_send_pipe_gains(struct snd_soc_dai *dai, int stream, int mute)
1298 dev_dbg(dai->dev, "Stream name=%s\n", 1298 dev_dbg(dai->dev, "Stream name=%s\n",
1299 dai->playback_widget->name); 1299 dai->playback_widget->name);
1300 w = dai->playback_widget; 1300 w = dai->playback_widget;
1301 list_for_each_entry(p, &w->sinks, list_source) { 1301 snd_soc_dapm_widget_for_each_sink_path(w, p) {
1302 if (p->connected && !p->connected(w, p->sink)) 1302 if (p->connected && !p->connected(w, p->sink))
1303 continue; 1303 continue;
1304 1304
@@ -1317,7 +1317,7 @@ int sst_send_pipe_gains(struct snd_soc_dai *dai, int stream, int mute)
1317 dev_dbg(dai->dev, "Stream name=%s\n", 1317 dev_dbg(dai->dev, "Stream name=%s\n",
1318 dai->capture_widget->name); 1318 dai->capture_widget->name);
1319 w = dai->capture_widget; 1319 w = dai->capture_widget;
1320 list_for_each_entry(p, &w->sources, list_sink) { 1320 snd_soc_dapm_widget_for_each_source_path(w, p) {
1321 if (p->connected && !p->connected(w, p->sink)) 1321 if (p->connected && !p->connected(w, p->sink))
1322 continue; 1322 continue;
1323 1323
diff --git a/sound/soc/intel/atom/sst-mfld-platform-pcm.c b/sound/soc/intel/atom/sst-mfld-platform-pcm.c
index 641ebe61dc08..683e50116152 100644
--- a/sound/soc/intel/atom/sst-mfld-platform-pcm.c
+++ b/sound/soc/intel/atom/sst-mfld-platform-pcm.c
@@ -33,7 +33,6 @@
33 33
34struct sst_device *sst; 34struct sst_device *sst;
35static DEFINE_MUTEX(sst_lock); 35static DEFINE_MUTEX(sst_lock);
36extern struct snd_compr_ops sst_platform_compr_ops;
37 36
38int sst_register_dsp(struct sst_device *dev) 37int sst_register_dsp(struct sst_device *dev)
39{ 38{
diff --git a/sound/soc/intel/atom/sst-mfld-platform.h b/sound/soc/intel/atom/sst-mfld-platform.h
index 2409b23eeacf..cb32cc7e5ec1 100644
--- a/sound/soc/intel/atom/sst-mfld-platform.h
+++ b/sound/soc/intel/atom/sst-mfld-platform.h
@@ -25,6 +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;
28 29
29#define SST_MONO 1 30#define SST_MONO 1
30#define SST_STEREO 2 31#define SST_STEREO 2
diff --git a/sound/soc/intel/atom/sst/sst_drv_interface.c b/sound/soc/intel/atom/sst/sst_drv_interface.c
index 620da1d1b9e3..ce689c5af5ab 100644
--- a/sound/soc/intel/atom/sst/sst_drv_interface.c
+++ b/sound/soc/intel/atom/sst/sst_drv_interface.c
@@ -42,6 +42,11 @@
42#define MIN_FRAGMENT_SIZE (50 * 1024) 42#define MIN_FRAGMENT_SIZE (50 * 1024)
43#define MAX_FRAGMENT_SIZE (1024 * 1024) 43#define MAX_FRAGMENT_SIZE (1024 * 1024)
44#define SST_GET_BYTES_PER_SAMPLE(pcm_wd_sz) (((pcm_wd_sz + 15) >> 4) << 1) 44#define SST_GET_BYTES_PER_SAMPLE(pcm_wd_sz) (((pcm_wd_sz + 15) >> 4) << 1)
45#ifdef CONFIG_PM
46#define GET_USAGE_COUNT(dev) (atomic_read(&dev->power.usage_count))
47#else
48#define GET_USAGE_COUNT(dev) 1
49#endif
45 50
46int free_stream_context(struct intel_sst_drv *ctx, unsigned int str_id) 51int free_stream_context(struct intel_sst_drv *ctx, unsigned int str_id)
47{ 52{
@@ -141,17 +146,12 @@ static int sst_power_control(struct device *dev, bool state)
141 int ret = 0; 146 int ret = 0;
142 int usage_count = 0; 147 int usage_count = 0;
143 148
144#ifdef CONFIG_PM
145 usage_count = atomic_read(&dev->power.usage_count);
146#else
147 usage_count = 1;
148#endif
149
150 if (state == true) { 149 if (state == true) {
151 ret = pm_runtime_get_sync(dev); 150 ret = pm_runtime_get_sync(dev);
152 151 usage_count = GET_USAGE_COUNT(dev);
153 dev_dbg(ctx->dev, "Enable: pm usage count: %d\n", usage_count); 152 dev_dbg(ctx->dev, "Enable: pm usage count: %d\n", usage_count);
154 if (ret < 0) { 153 if (ret < 0) {
154 pm_runtime_put_sync(dev);
155 dev_err(ctx->dev, "Runtime get failed with err: %d\n", ret); 155 dev_err(ctx->dev, "Runtime get failed with err: %d\n", ret);
156 return ret; 156 return ret;
157 } 157 }
@@ -164,6 +164,7 @@ static int sst_power_control(struct device *dev, bool state)
164 } 164 }
165 } 165 }
166 } else { 166 } else {
167 usage_count = GET_USAGE_COUNT(dev);
167 dev_dbg(ctx->dev, "Disable: pm usage count: %d\n", usage_count); 168 dev_dbg(ctx->dev, "Disable: pm usage count: %d\n", usage_count);
168 return sst_pm_runtime_put(ctx); 169 return sst_pm_runtime_put(ctx);
169 } 170 }
@@ -204,8 +205,10 @@ static int sst_cdev_open(struct device *dev,
204 struct intel_sst_drv *ctx = dev_get_drvdata(dev); 205 struct intel_sst_drv *ctx = dev_get_drvdata(dev);
205 206
206 retval = pm_runtime_get_sync(ctx->dev); 207 retval = pm_runtime_get_sync(ctx->dev);
207 if (retval < 0) 208 if (retval < 0) {
209 pm_runtime_put_sync(ctx->dev);
208 return retval; 210 return retval;
211 }
209 212
210 str_id = sst_get_stream(ctx, str_params); 213 str_id = sst_get_stream(ctx, str_params);
211 if (str_id > 0) { 214 if (str_id > 0) {
@@ -672,8 +675,10 @@ static int sst_send_byte_stream(struct device *dev,
672 if (NULL == bytes) 675 if (NULL == bytes)
673 return -EINVAL; 676 return -EINVAL;
674 ret_val = pm_runtime_get_sync(ctx->dev); 677 ret_val = pm_runtime_get_sync(ctx->dev);
675 if (ret_val < 0) 678 if (ret_val < 0) {
679 pm_runtime_put_sync(ctx->dev);
676 return ret_val; 680 return ret_val;
681 }
677 682
678 ret_val = sst_send_byte_stream_mrfld(ctx, bytes); 683 ret_val = sst_send_byte_stream_mrfld(ctx, bytes);
679 sst_pm_runtime_put(ctx); 684 sst_pm_runtime_put(ctx);
diff --git a/sound/soc/intel/atom/sst/sst_ipc.c b/sound/soc/intel/atom/sst/sst_ipc.c
index 5a278618466c..3dc7358828b3 100644
--- a/sound/soc/intel/atom/sst/sst_ipc.c
+++ b/sound/soc/intel/atom/sst/sst_ipc.c
@@ -352,10 +352,9 @@ void sst_process_reply_mrfld(struct intel_sst_drv *sst_drv_ctx,
352 * copy from mailbox 352 * copy from mailbox
353 **/ 353 **/
354 if (msg_high.part.large) { 354 if (msg_high.part.large) {
355 data = kzalloc(msg_low, GFP_KERNEL); 355 data = kmemdup((void *)msg->mailbox_data, msg_low, GFP_KERNEL);
356 if (!data) 356 if (!data)
357 return; 357 return;
358 memcpy(data, (void *) msg->mailbox_data, msg_low);
359 /* Copy command id so that we can use to put sst to reset */ 358 /* Copy command id so that we can use to put sst to reset */
360 dsp_hdr = (struct ipc_dsp_hdr *)data; 359 dsp_hdr = (struct ipc_dsp_hdr *)data;
361 cmd_id = dsp_hdr->cmd_id; 360 cmd_id = dsp_hdr->cmd_id;
diff --git a/sound/soc/intel/baytrail/sst-baytrail-ipc.c b/sound/soc/intel/baytrail/sst-baytrail-ipc.c
index 4c01bb43928d..5bbaa667bec1 100644
--- a/sound/soc/intel/baytrail/sst-baytrail-ipc.c
+++ b/sound/soc/intel/baytrail/sst-baytrail-ipc.c
@@ -701,6 +701,8 @@ int sst_byt_dsp_init(struct device *dev, struct sst_pdata *pdata)
701 if (byt == NULL) 701 if (byt == NULL)
702 return -ENOMEM; 702 return -ENOMEM;
703 703
704 byt->dev = dev;
705
704 ipc = &byt->ipc; 706 ipc = &byt->ipc;
705 ipc->dev = dev; 707 ipc->dev = dev;
706 ipc->ops.tx_msg = byt_tx_msg; 708 ipc->ops.tx_msg = byt_tx_msg;
diff --git a/sound/soc/intel/boards/byt-max98090.c b/sound/soc/intel/boards/byt-max98090.c
index 7ab8cc9fbfd5..d9f81b8d915d 100644
--- a/sound/soc/intel/boards/byt-max98090.c
+++ b/sound/soc/intel/boards/byt-max98090.c
@@ -126,6 +126,7 @@ static struct snd_soc_dai_link byt_max98090_dais[] = {
126 126
127static struct snd_soc_card byt_max98090_card = { 127static struct snd_soc_card byt_max98090_card = {
128 .name = "byt-max98090", 128 .name = "byt-max98090",
129 .owner = THIS_MODULE,
129 .dai_link = byt_max98090_dais, 130 .dai_link = byt_max98090_dais,
130 .num_links = ARRAY_SIZE(byt_max98090_dais), 131 .num_links = ARRAY_SIZE(byt_max98090_dais),
131 .dapm_widgets = byt_max98090_widgets, 132 .dapm_widgets = byt_max98090_widgets,
diff --git a/sound/soc/intel/boards/byt-rt5640.c b/sound/soc/intel/boards/byt-rt5640.c
index ae89b9b966d9..de9788a3fd06 100644
--- a/sound/soc/intel/boards/byt-rt5640.c
+++ b/sound/soc/intel/boards/byt-rt5640.c
@@ -197,6 +197,7 @@ static struct snd_soc_dai_link byt_rt5640_dais[] = {
197 197
198static struct snd_soc_card byt_rt5640_card = { 198static struct snd_soc_card byt_rt5640_card = {
199 .name = "byt-rt5640", 199 .name = "byt-rt5640",
200 .owner = THIS_MODULE,
200 .dai_link = byt_rt5640_dais, 201 .dai_link = byt_rt5640_dais,
201 .num_links = ARRAY_SIZE(byt_rt5640_dais), 202 .num_links = ARRAY_SIZE(byt_rt5640_dais),
202 .dapm_widgets = byt_rt5640_widgets, 203 .dapm_widgets = byt_rt5640_widgets,
diff --git a/sound/soc/intel/boards/bytcr_rt5640.c b/sound/soc/intel/boards/bytcr_rt5640.c
index 7f55d59024a8..c4453120b11a 100644
--- a/sound/soc/intel/boards/bytcr_rt5640.c
+++ b/sound/soc/intel/boards/bytcr_rt5640.c
@@ -185,6 +185,7 @@ static struct snd_soc_dai_link byt_dailink[] = {
185/* SoC card */ 185/* SoC card */
186static struct snd_soc_card snd_soc_card_byt = { 186static struct snd_soc_card snd_soc_card_byt = {
187 .name = "baytrailcraudio", 187 .name = "baytrailcraudio",
188 .owner = THIS_MODULE,
188 .dai_link = byt_dailink, 189 .dai_link = byt_dailink,
189 .num_links = ARRAY_SIZE(byt_dailink), 190 .num_links = ARRAY_SIZE(byt_dailink),
190 .dapm_widgets = byt_dapm_widgets, 191 .dapm_widgets = byt_dapm_widgets,
diff --git a/sound/soc/intel/boards/cht_bsw_max98090_ti.c b/sound/soc/intel/boards/cht_bsw_max98090_ti.c
index d604ee80eda4..49f4869cec48 100644
--- a/sound/soc/intel/boards/cht_bsw_max98090_ti.c
+++ b/sound/soc/intel/boards/cht_bsw_max98090_ti.c
@@ -69,12 +69,12 @@ static const struct snd_soc_dapm_route cht_audio_map[] = {
69 {"Headphone", NULL, "HPR"}, 69 {"Headphone", NULL, "HPR"},
70 {"Ext Spk", NULL, "SPKL"}, 70 {"Ext Spk", NULL, "SPKL"},
71 {"Ext Spk", NULL, "SPKR"}, 71 {"Ext Spk", NULL, "SPKR"},
72 {"AIF1 Playback", NULL, "ssp2 Tx"}, 72 {"HiFi Playback", NULL, "ssp2 Tx"},
73 {"ssp2 Tx", NULL, "codec_out0"}, 73 {"ssp2 Tx", NULL, "codec_out0"},
74 {"ssp2 Tx", NULL, "codec_out1"}, 74 {"ssp2 Tx", NULL, "codec_out1"},
75 {"codec_in0", NULL, "ssp2 Rx" }, 75 {"codec_in0", NULL, "ssp2 Rx" },
76 {"codec_in1", NULL, "ssp2 Rx" }, 76 {"codec_in1", NULL, "ssp2 Rx" },
77 {"ssp2 Rx", NULL, "AIF1 Capture"}, 77 {"ssp2 Rx", NULL, "HiFi Capture"},
78}; 78};
79 79
80static const struct snd_kcontrol_new cht_mc_controls[] = { 80static const struct snd_kcontrol_new cht_mc_controls[] = {
@@ -104,21 +104,17 @@ static int cht_aif1_hw_params(struct snd_pcm_substream *substream,
104static int cht_ti_jack_event(struct notifier_block *nb, 104static int cht_ti_jack_event(struct notifier_block *nb,
105 unsigned long event, void *data) 105 unsigned long event, void *data)
106{ 106{
107
108 struct snd_soc_jack *jack = (struct snd_soc_jack *)data; 107 struct snd_soc_jack *jack = (struct snd_soc_jack *)data;
109 struct snd_soc_dai *codec_dai = jack->card->rtd->codec_dai; 108 struct snd_soc_dapm_context *dapm = &jack->card->dapm;
110 struct snd_soc_codec *codec = codec_dai->codec;
111 109
112 if (event & SND_JACK_MICROPHONE) { 110 if (event & SND_JACK_MICROPHONE) {
113 111 snd_soc_dapm_force_enable_pin(dapm, "SHDN");
114 snd_soc_dapm_force_enable_pin(&codec->dapm, "SHDN"); 112 snd_soc_dapm_force_enable_pin(dapm, "MICBIAS");
115 snd_soc_dapm_force_enable_pin(&codec->dapm, "MICBIAS"); 113 snd_soc_dapm_sync(dapm);
116 snd_soc_dapm_sync(&codec->dapm);
117 } else { 114 } else {
118 115 snd_soc_dapm_disable_pin(dapm, "MICBIAS");
119 snd_soc_dapm_disable_pin(&codec->dapm, "MICBIAS"); 116 snd_soc_dapm_disable_pin(dapm, "SHDN");
120 snd_soc_dapm_disable_pin(&codec->dapm, "SHDN"); 117 snd_soc_dapm_sync(dapm);
121 snd_soc_dapm_sync(&codec->dapm);
122 } 118 }
123 119
124 return 0; 120 return 0;
@@ -279,6 +275,7 @@ static struct snd_soc_dai_link cht_dailink[] = {
279/* SoC card */ 275/* SoC card */
280static struct snd_soc_card snd_soc_card_cht = { 276static struct snd_soc_card snd_soc_card_cht = {
281 .name = "chtmax98090", 277 .name = "chtmax98090",
278 .owner = THIS_MODULE,
282 .dai_link = cht_dailink, 279 .dai_link = cht_dailink,
283 .num_links = ARRAY_SIZE(cht_dailink), 280 .num_links = ARRAY_SIZE(cht_dailink),
284 .aux_dev = &cht_max98090_headset_dev, 281 .aux_dev = &cht_max98090_headset_dev,
diff --git a/sound/soc/intel/boards/cht_bsw_rt5645.c b/sound/soc/intel/boards/cht_bsw_rt5645.c
index bdcaf467842a..7be8461e4d3b 100644
--- a/sound/soc/intel/boards/cht_bsw_rt5645.c
+++ b/sound/soc/intel/boards/cht_bsw_rt5645.c
@@ -305,6 +305,7 @@ static struct snd_soc_dai_link cht_dailink[] = {
305/* SoC card */ 305/* SoC card */
306static struct snd_soc_card snd_soc_card_chtrt5645 = { 306static struct snd_soc_card snd_soc_card_chtrt5645 = {
307 .name = "chtrt5645", 307 .name = "chtrt5645",
308 .owner = THIS_MODULE,
308 .dai_link = cht_dailink, 309 .dai_link = cht_dailink,
309 .num_links = ARRAY_SIZE(cht_dailink), 310 .num_links = ARRAY_SIZE(cht_dailink),
310 .dapm_widgets = cht_dapm_widgets, 311 .dapm_widgets = cht_dapm_widgets,
@@ -317,6 +318,7 @@ static struct snd_soc_card snd_soc_card_chtrt5645 = {
317 318
318static struct snd_soc_card snd_soc_card_chtrt5650 = { 319static struct snd_soc_card snd_soc_card_chtrt5650 = {
319 .name = "chtrt5650", 320 .name = "chtrt5650",
321 .owner = THIS_MODULE,
320 .dai_link = cht_dailink, 322 .dai_link = cht_dailink,
321 .num_links = ARRAY_SIZE(cht_dailink), 323 .num_links = ARRAY_SIZE(cht_dailink),
322 .dapm_widgets = cht_dapm_widgets, 324 .dapm_widgets = cht_dapm_widgets,
diff --git a/sound/soc/intel/boards/cht_bsw_rt5672.c b/sound/soc/intel/boards/cht_bsw_rt5672.c
index 2c9cc5be439e..23fe04075142 100644
--- a/sound/soc/intel/boards/cht_bsw_rt5672.c
+++ b/sound/soc/intel/boards/cht_bsw_rt5672.c
@@ -323,6 +323,7 @@ static int cht_resume_post(struct snd_soc_card *card)
323/* SoC card */ 323/* SoC card */
324static struct snd_soc_card snd_soc_card_cht = { 324static struct snd_soc_card snd_soc_card_cht = {
325 .name = "cherrytrailcraudio", 325 .name = "cherrytrailcraudio",
326 .owner = THIS_MODULE,
326 .dai_link = cht_dailink, 327 .dai_link = cht_dailink,
327 .num_links = ARRAY_SIZE(cht_dailink), 328 .num_links = ARRAY_SIZE(cht_dailink),
328 .dapm_widgets = cht_dapm_widgets, 329 .dapm_widgets = cht_dapm_widgets,
diff --git a/sound/soc/intel/common/sst-dsp-priv.h b/sound/soc/intel/common/sst-dsp-priv.h
index 396d54510350..cbd568eac033 100644
--- a/sound/soc/intel/common/sst-dsp-priv.h
+++ b/sound/soc/intel/common/sst-dsp-priv.h
@@ -22,6 +22,8 @@
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <linux/firmware.h> 23#include <linux/firmware.h>
24 24
25#include "../skylake/skl-sst-dsp.h"
26
25struct sst_mem_block; 27struct sst_mem_block;
26struct sst_module; 28struct sst_module;
27struct sst_fw; 29struct sst_fw;
@@ -258,6 +260,8 @@ struct sst_mem_block {
258 */ 260 */
259struct sst_dsp { 261struct sst_dsp {
260 262
263 /* Shared for all platforms */
264
261 /* runtime */ 265 /* runtime */
262 struct sst_dsp_device *sst_dev; 266 struct sst_dsp_device *sst_dev;
263 spinlock_t spinlock; /* IPC locking */ 267 spinlock_t spinlock; /* IPC locking */
@@ -268,10 +272,6 @@ struct sst_dsp {
268 int irq; 272 int irq;
269 u32 id; 273 u32 id;
270 274
271 /* list of free and used ADSP memory blocks */
272 struct list_head used_block_list;
273 struct list_head free_block_list;
274
275 /* operations */ 275 /* operations */
276 struct sst_ops *ops; 276 struct sst_ops *ops;
277 277
@@ -284,6 +284,12 @@ struct sst_dsp {
284 /* mailbox */ 284 /* mailbox */
285 struct sst_mailbox mailbox; 285 struct sst_mailbox mailbox;
286 286
287 /* HSW/Byt data */
288
289 /* list of free and used ADSP memory blocks */
290 struct list_head used_block_list;
291 struct list_head free_block_list;
292
287 /* SST FW files loaded and their modules */ 293 /* SST FW files loaded and their modules */
288 struct list_head module_list; 294 struct list_head module_list;
289 struct list_head fw_list; 295 struct list_head fw_list;
@@ -299,6 +305,15 @@ struct sst_dsp {
299 /* DMA FW loading */ 305 /* DMA FW loading */
300 struct sst_dma *dma; 306 struct sst_dma *dma;
301 bool fw_use_dma; 307 bool fw_use_dma;
308
309 /* SKL data */
310
311 /* To allocate CL dma buffers */
312 struct skl_dsp_loader_ops dsp_ops;
313 struct skl_dsp_fw_ops fw_ops;
314 int sst_state;
315 struct skl_cl_dev cl_dev;
316 u32 intr_status;
302}; 317};
303 318
304/* Size optimised DRAM/IRAM memcpy */ 319/* Size optimised DRAM/IRAM memcpy */
diff --git a/sound/soc/intel/common/sst-dsp.c b/sound/soc/intel/common/sst-dsp.c
index 64e94212d2d2..a627236dd1f5 100644
--- a/sound/soc/intel/common/sst-dsp.c
+++ b/sound/soc/intel/common/sst-dsp.c
@@ -20,6 +20,7 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/delay.h>
23 24
24#include "sst-dsp.h" 25#include "sst-dsp.h"
25#include "sst-dsp-priv.h" 26#include "sst-dsp-priv.h"
@@ -196,6 +197,22 @@ int sst_dsp_shim_update_bits64_unlocked(struct sst_dsp *sst, u32 offset,
196} 197}
197EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits64_unlocked); 198EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits64_unlocked);
198 199
200/* This is for registers bits with attribute RWC */
201void sst_dsp_shim_update_bits_forced_unlocked(struct sst_dsp *sst, u32 offset,
202 u32 mask, u32 value)
203{
204 unsigned int old, new;
205 u32 ret;
206
207 ret = sst_dsp_shim_read_unlocked(sst, offset);
208
209 old = ret;
210 new = (old & (~mask)) | (value & mask);
211
212 sst_dsp_shim_write_unlocked(sst, offset, new);
213}
214EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits_forced_unlocked);
215
199int sst_dsp_shim_update_bits(struct sst_dsp *sst, u32 offset, 216int sst_dsp_shim_update_bits(struct sst_dsp *sst, u32 offset,
200 u32 mask, u32 value) 217 u32 mask, u32 value)
201{ 218{
@@ -222,6 +239,60 @@ int sst_dsp_shim_update_bits64(struct sst_dsp *sst, u32 offset,
222} 239}
223EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits64); 240EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits64);
224 241
242/* This is for registers bits with attribute RWC */
243void sst_dsp_shim_update_bits_forced(struct sst_dsp *sst, u32 offset,
244 u32 mask, u32 value)
245{
246 unsigned long flags;
247
248 spin_lock_irqsave(&sst->spinlock, flags);
249 sst_dsp_shim_update_bits_forced_unlocked(sst, offset, mask, value);
250 spin_unlock_irqrestore(&sst->spinlock, flags);
251}
252EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits_forced);
253
254int sst_dsp_register_poll(struct sst_dsp *ctx, u32 offset, u32 mask,
255 u32 target, u32 timeout, char *operation)
256{
257 int time, ret;
258 u32 reg;
259 bool done = false;
260
261 /*
262 * we will poll for couple of ms using mdelay, if not successful
263 * then go to longer sleep using usleep_range
264 */
265
266 /* check if set state successful */
267 for (time = 0; time < 5; time++) {
268 if ((sst_dsp_shim_read_unlocked(ctx, offset) & mask) == target) {
269 done = true;
270 break;
271 }
272 mdelay(1);
273 }
274
275 if (done == false) {
276 /* sleeping in 10ms steps so adjust timeout value */
277 timeout /= 10;
278
279 for (time = 0; time < timeout; time++) {
280 if ((sst_dsp_shim_read_unlocked(ctx, offset) & mask) == target)
281 break;
282
283 usleep_range(5000, 10000);
284 }
285 }
286
287 reg = sst_dsp_shim_read_unlocked(ctx, offset);
288 dev_info(ctx->dev, "FW Poll Status: reg=%#x %s %s\n", reg, operation,
289 (time < timeout) ? "successful" : "timedout");
290 ret = time < timeout ? 0 : -ETIME;
291
292 return ret;
293}
294EXPORT_SYMBOL_GPL(sst_dsp_register_poll);
295
225void sst_dsp_dump(struct sst_dsp *sst) 296void sst_dsp_dump(struct sst_dsp *sst)
226{ 297{
227 if (sst->ops->dump) 298 if (sst->ops->dump)
diff --git a/sound/soc/intel/common/sst-dsp.h b/sound/soc/intel/common/sst-dsp.h
index 96aeb2556ad4..1f45f18715c0 100644
--- a/sound/soc/intel/common/sst-dsp.h
+++ b/sound/soc/intel/common/sst-dsp.h
@@ -230,6 +230,8 @@ void sst_dsp_shim_write64(struct sst_dsp *sst, u32 offset, u64 value);
230u64 sst_dsp_shim_read64(struct sst_dsp *sst, u32 offset); 230u64 sst_dsp_shim_read64(struct sst_dsp *sst, u32 offset);
231int sst_dsp_shim_update_bits64(struct sst_dsp *sst, u32 offset, 231int sst_dsp_shim_update_bits64(struct sst_dsp *sst, u32 offset,
232 u64 mask, u64 value); 232 u64 mask, u64 value);
233void sst_dsp_shim_update_bits_forced(struct sst_dsp *sst, u32 offset,
234 u32 mask, u32 value);
233 235
234/* SHIM Read / Write Unlocked for callers already holding sst lock */ 236/* SHIM Read / Write Unlocked for callers already holding sst lock */
235void sst_dsp_shim_write_unlocked(struct sst_dsp *sst, u32 offset, u32 value); 237void sst_dsp_shim_write_unlocked(struct sst_dsp *sst, u32 offset, u32 value);
@@ -240,6 +242,8 @@ void sst_dsp_shim_write64_unlocked(struct sst_dsp *sst, u32 offset, u64 value);
240u64 sst_dsp_shim_read64_unlocked(struct sst_dsp *sst, u32 offset); 242u64 sst_dsp_shim_read64_unlocked(struct sst_dsp *sst, u32 offset);
241int sst_dsp_shim_update_bits64_unlocked(struct sst_dsp *sst, u32 offset, 243int sst_dsp_shim_update_bits64_unlocked(struct sst_dsp *sst, u32 offset,
242 u64 mask, u64 value); 244 u64 mask, u64 value);
245void sst_dsp_shim_update_bits_forced_unlocked(struct sst_dsp *sst, u32 offset,
246 u32 mask, u32 value);
243 247
244/* Internal generic low-level SST IO functions - can be overidden */ 248/* Internal generic low-level SST IO functions - can be overidden */
245void sst_shim32_write(void __iomem *addr, u32 offset, u32 value); 249void sst_shim32_write(void __iomem *addr, u32 offset, u32 value);
@@ -278,6 +282,8 @@ void sst_dsp_inbox_read(struct sst_dsp *dsp, void *message, size_t bytes);
278void sst_dsp_outbox_write(struct sst_dsp *dsp, void *message, size_t bytes); 282void sst_dsp_outbox_write(struct sst_dsp *dsp, void *message, size_t bytes);
279void sst_dsp_outbox_read(struct sst_dsp *dsp, void *message, size_t bytes); 283void sst_dsp_outbox_read(struct sst_dsp *dsp, void *message, size_t bytes);
280void sst_dsp_mailbox_dump(struct sst_dsp *dsp, size_t bytes); 284void sst_dsp_mailbox_dump(struct sst_dsp *dsp, size_t bytes);
285int sst_dsp_register_poll(struct sst_dsp *dsp, u32 offset, u32 mask,
286 u32 expected_value, u32 timeout, char *operation);
281 287
282/* Debug */ 288/* Debug */
283void sst_dsp_dump(struct sst_dsp *sst); 289void sst_dsp_dump(struct sst_dsp *sst);
diff --git a/sound/soc/intel/haswell/sst-haswell-ipc.c b/sound/soc/intel/haswell/sst-haswell-ipc.c
index f95f271aab0c..f6efa9d4acad 100644
--- a/sound/soc/intel/haswell/sst-haswell-ipc.c
+++ b/sound/soc/intel/haswell/sst-haswell-ipc.c
@@ -2119,6 +2119,8 @@ int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata)
2119 if (hsw == NULL) 2119 if (hsw == NULL)
2120 return -ENOMEM; 2120 return -ENOMEM;
2121 2121
2122 hsw->dev = dev;
2123
2122 ipc = &hsw->ipc; 2124 ipc = &hsw->ipc;
2123 ipc->dev = dev; 2125 ipc->dev = dev;
2124 ipc->ops.tx_msg = hsw_tx_msg; 2126 ipc->ops.tx_msg = hsw_tx_msg;
diff --git a/sound/soc/intel/skylake/Makefile b/sound/soc/intel/skylake/Makefile
new file mode 100644
index 000000000000..27db22178204
--- /dev/null
+++ b/sound/soc/intel/skylake/Makefile
@@ -0,0 +1,9 @@
1snd-soc-skl-objs := skl.o skl-pcm.o skl-nhlt.o skl-messages.o
2
3obj-$(CONFIG_SND_SOC_INTEL_SKYLAKE) += snd-soc-skl.o
4
5# Skylake IPC Support
6snd-soc-skl-ipc-objs := skl-sst-ipc.o skl-sst-dsp.o skl-sst-cldma.o \
7 skl-sst.o
8
9obj-$(CONFIG_SND_SOC_INTEL_SKYLAKE) += snd-soc-skl-ipc.o
diff --git a/sound/soc/intel/skylake/skl-messages.c b/sound/soc/intel/skylake/skl-messages.c
new file mode 100644
index 000000000000..826d4fd8930a
--- /dev/null
+++ b/sound/soc/intel/skylake/skl-messages.c
@@ -0,0 +1,884 @@
1/*
2 * skl-message.c - HDA DSP interface for FW registration, Pipe and Module
3 * configurations
4 *
5 * Copyright (C) 2015 Intel Corp
6 * Author:Rafal Redzimski <rafal.f.redzimski@intel.com>
7 * Jeeja KP <jeeja.kp@intel.com>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as version 2, as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 */
19
20#include <linux/slab.h>
21#include <linux/pci.h>
22#include <sound/core.h>
23#include <sound/pcm.h>
24#include "skl-sst-dsp.h"
25#include "skl-sst-ipc.h"
26#include "skl.h"
27#include "../common/sst-dsp.h"
28#include "../common/sst-dsp-priv.h"
29#include "skl-topology.h"
30#include "skl-tplg-interface.h"
31
32static int skl_alloc_dma_buf(struct device *dev,
33 struct snd_dma_buffer *dmab, size_t size)
34{
35 struct hdac_ext_bus *ebus = dev_get_drvdata(dev);
36 struct hdac_bus *bus = ebus_to_hbus(ebus);
37
38 if (!bus)
39 return -ENODEV;
40
41 return bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, size, dmab);
42}
43
44static int skl_free_dma_buf(struct device *dev, struct snd_dma_buffer *dmab)
45{
46 struct hdac_ext_bus *ebus = dev_get_drvdata(dev);
47 struct hdac_bus *bus = ebus_to_hbus(ebus);
48
49 if (!bus)
50 return -ENODEV;
51
52 bus->io_ops->dma_free_pages(bus, dmab);
53
54 return 0;
55}
56
57int skl_init_dsp(struct skl *skl)
58{
59 void __iomem *mmio_base;
60 struct hdac_ext_bus *ebus = &skl->ebus;
61 struct hdac_bus *bus = ebus_to_hbus(ebus);
62 int irq = bus->irq;
63 struct skl_dsp_loader_ops loader_ops;
64 int ret;
65
66 loader_ops.alloc_dma_buf = skl_alloc_dma_buf;
67 loader_ops.free_dma_buf = skl_free_dma_buf;
68
69 /* enable ppcap interrupt */
70 snd_hdac_ext_bus_ppcap_enable(&skl->ebus, true);
71 snd_hdac_ext_bus_ppcap_int_enable(&skl->ebus, true);
72
73 /* read the BAR of the ADSP MMIO */
74 mmio_base = pci_ioremap_bar(skl->pci, 4);
75 if (mmio_base == NULL) {
76 dev_err(bus->dev, "ioremap error\n");
77 return -ENXIO;
78 }
79
80 ret = skl_sst_dsp_init(bus->dev, mmio_base, irq,
81 loader_ops, &skl->skl_sst);
82
83 dev_dbg(bus->dev, "dsp registration status=%d\n", ret);
84
85 return ret;
86}
87
88void skl_free_dsp(struct skl *skl)
89{
90 struct hdac_ext_bus *ebus = &skl->ebus;
91 struct hdac_bus *bus = ebus_to_hbus(ebus);
92 struct skl_sst *ctx = skl->skl_sst;
93
94 /* disable ppcap interrupt */
95 snd_hdac_ext_bus_ppcap_int_enable(&skl->ebus, false);
96
97 skl_sst_dsp_cleanup(bus->dev, ctx);
98 if (ctx->dsp->addr.lpe)
99 iounmap(ctx->dsp->addr.lpe);
100}
101
102int skl_suspend_dsp(struct skl *skl)
103{
104 struct skl_sst *ctx = skl->skl_sst;
105 int ret;
106
107 /* if ppcap is not supported return 0 */
108 if (!skl->ebus.ppcap)
109 return 0;
110
111 ret = skl_dsp_sleep(ctx->dsp);
112 if (ret < 0)
113 return ret;
114
115 /* disable ppcap interrupt */
116 snd_hdac_ext_bus_ppcap_int_enable(&skl->ebus, false);
117 snd_hdac_ext_bus_ppcap_enable(&skl->ebus, false);
118
119 return 0;
120}
121
122int skl_resume_dsp(struct skl *skl)
123{
124 struct skl_sst *ctx = skl->skl_sst;
125
126 /* if ppcap is not supported return 0 */
127 if (!skl->ebus.ppcap)
128 return 0;
129
130 /* enable ppcap interrupt */
131 snd_hdac_ext_bus_ppcap_enable(&skl->ebus, true);
132 snd_hdac_ext_bus_ppcap_int_enable(&skl->ebus, true);
133
134 return skl_dsp_wake(ctx->dsp);
135}
136
137enum skl_bitdepth skl_get_bit_depth(int params)
138{
139 switch (params) {
140 case 8:
141 return SKL_DEPTH_8BIT;
142
143 case 16:
144 return SKL_DEPTH_16BIT;
145
146 case 24:
147 return SKL_DEPTH_24BIT;
148
149 case 32:
150 return SKL_DEPTH_32BIT;
151
152 default:
153 return SKL_DEPTH_INVALID;
154
155 }
156}
157
158static u32 skl_create_channel_map(enum skl_ch_cfg ch_cfg)
159{
160 u32 config;
161
162 switch (ch_cfg) {
163 case SKL_CH_CFG_MONO:
164 config = (0xFFFFFFF0 | SKL_CHANNEL_LEFT);
165 break;
166
167 case SKL_CH_CFG_STEREO:
168 config = (0xFFFFFF00 | SKL_CHANNEL_LEFT
169 | (SKL_CHANNEL_RIGHT << 4));
170 break;
171
172 case SKL_CH_CFG_2_1:
173 config = (0xFFFFF000 | SKL_CHANNEL_LEFT
174 | (SKL_CHANNEL_RIGHT << 4)
175 | (SKL_CHANNEL_LFE << 8));
176 break;
177
178 case SKL_CH_CFG_3_0:
179 config = (0xFFFFF000 | SKL_CHANNEL_LEFT
180 | (SKL_CHANNEL_CENTER << 4)
181 | (SKL_CHANNEL_RIGHT << 8));
182 break;
183
184 case SKL_CH_CFG_3_1:
185 config = (0xFFFF0000 | SKL_CHANNEL_LEFT
186 | (SKL_CHANNEL_CENTER << 4)
187 | (SKL_CHANNEL_RIGHT << 8)
188 | (SKL_CHANNEL_LFE << 12));
189 break;
190
191 case SKL_CH_CFG_QUATRO:
192 config = (0xFFFF0000 | SKL_CHANNEL_LEFT
193 | (SKL_CHANNEL_RIGHT << 4)
194 | (SKL_CHANNEL_LEFT_SURROUND << 8)
195 | (SKL_CHANNEL_RIGHT_SURROUND << 12));
196 break;
197
198 case SKL_CH_CFG_4_0:
199 config = (0xFFFF0000 | SKL_CHANNEL_LEFT
200 | (SKL_CHANNEL_CENTER << 4)
201 | (SKL_CHANNEL_RIGHT << 8)
202 | (SKL_CHANNEL_CENTER_SURROUND << 12));
203 break;
204
205 case SKL_CH_CFG_5_0:
206 config = (0xFFF00000 | SKL_CHANNEL_LEFT
207 | (SKL_CHANNEL_CENTER << 4)
208 | (SKL_CHANNEL_RIGHT << 8)
209 | (SKL_CHANNEL_LEFT_SURROUND << 12)
210 | (SKL_CHANNEL_RIGHT_SURROUND << 16));
211 break;
212
213 case SKL_CH_CFG_5_1:
214 config = (0xFF000000 | SKL_CHANNEL_CENTER
215 | (SKL_CHANNEL_LEFT << 4)
216 | (SKL_CHANNEL_RIGHT << 8)
217 | (SKL_CHANNEL_LEFT_SURROUND << 12)
218 | (SKL_CHANNEL_RIGHT_SURROUND << 16)
219 | (SKL_CHANNEL_LFE << 20));
220 break;
221
222 case SKL_CH_CFG_DUAL_MONO:
223 config = (0xFFFFFF00 | SKL_CHANNEL_LEFT
224 | (SKL_CHANNEL_LEFT << 4));
225 break;
226
227 case SKL_CH_CFG_I2S_DUAL_STEREO_0:
228 config = (0xFFFFFF00 | SKL_CHANNEL_LEFT
229 | (SKL_CHANNEL_RIGHT << 4));
230 break;
231
232 case SKL_CH_CFG_I2S_DUAL_STEREO_1:
233 config = (0xFFFF00FF | (SKL_CHANNEL_LEFT << 8)
234 | (SKL_CHANNEL_RIGHT << 12));
235 break;
236
237 default:
238 config = 0xFFFFFFFF;
239 break;
240
241 }
242
243 return config;
244}
245
246/*
247 * Each module in DSP expects a base module configuration, which consists of
248 * PCM format information, which we calculate in driver and resource values
249 * which are read from widget information passed through topology binary
250 * This is send when we create a module with INIT_INSTANCE IPC msg
251 */
252static void skl_set_base_module_format(struct skl_sst *ctx,
253 struct skl_module_cfg *mconfig,
254 struct skl_base_cfg *base_cfg)
255{
256 struct skl_module_fmt *format = &mconfig->in_fmt;
257
258 base_cfg->audio_fmt.number_of_channels = (u8)format->channels;
259
260 base_cfg->audio_fmt.s_freq = format->s_freq;
261 base_cfg->audio_fmt.bit_depth = format->bit_depth;
262 base_cfg->audio_fmt.valid_bit_depth = format->valid_bit_depth;
263 base_cfg->audio_fmt.ch_cfg = format->ch_cfg;
264
265 dev_dbg(ctx->dev, "bit_depth=%x valid_bd=%x ch_config=%x\n",
266 format->bit_depth, format->valid_bit_depth,
267 format->ch_cfg);
268
269 base_cfg->audio_fmt.channel_map = skl_create_channel_map(
270 base_cfg->audio_fmt.ch_cfg);
271
272 base_cfg->audio_fmt.interleaving = SKL_INTERLEAVING_PER_CHANNEL;
273
274 base_cfg->cps = mconfig->mcps;
275 base_cfg->ibs = mconfig->ibs;
276 base_cfg->obs = mconfig->obs;
277}
278
279/*
280 * Copies copier capabilities into copier module and updates copier module
281 * config size.
282 */
283static void skl_copy_copier_caps(struct skl_module_cfg *mconfig,
284 struct skl_cpr_cfg *cpr_mconfig)
285{
286 if (mconfig->formats_config.caps_size == 0)
287 return;
288
289 memcpy(cpr_mconfig->gtw_cfg.config_data,
290 mconfig->formats_config.caps,
291 mconfig->formats_config.caps_size);
292
293 cpr_mconfig->gtw_cfg.config_length =
294 (mconfig->formats_config.caps_size) / 4;
295}
296
297/*
298 * Calculate the gatewat settings required for copier module, type of
299 * gateway and index of gateway to use
300 */
301static void skl_setup_cpr_gateway_cfg(struct skl_sst *ctx,
302 struct skl_module_cfg *mconfig,
303 struct skl_cpr_cfg *cpr_mconfig)
304{
305 union skl_connector_node_id node_id = {0};
306 struct skl_pipe_params *params = mconfig->pipe->p_params;
307
308 switch (mconfig->dev_type) {
309 case SKL_DEVICE_BT:
310 node_id.node.dma_type =
311 (SKL_CONN_SOURCE == mconfig->hw_conn_type) ?
312 SKL_DMA_I2S_LINK_OUTPUT_CLASS :
313 SKL_DMA_I2S_LINK_INPUT_CLASS;
314 node_id.node.vindex = params->host_dma_id +
315 (mconfig->vbus_id << 3);
316 break;
317
318 case SKL_DEVICE_I2S:
319 node_id.node.dma_type =
320 (SKL_CONN_SOURCE == mconfig->hw_conn_type) ?
321 SKL_DMA_I2S_LINK_OUTPUT_CLASS :
322 SKL_DMA_I2S_LINK_INPUT_CLASS;
323 node_id.node.vindex = params->host_dma_id +
324 (mconfig->time_slot << 1) +
325 (mconfig->vbus_id << 3);
326 break;
327
328 case SKL_DEVICE_DMIC:
329 node_id.node.dma_type = SKL_DMA_DMIC_LINK_INPUT_CLASS;
330 node_id.node.vindex = mconfig->vbus_id +
331 (mconfig->time_slot);
332 break;
333
334 case SKL_DEVICE_HDALINK:
335 node_id.node.dma_type =
336 (SKL_CONN_SOURCE == mconfig->hw_conn_type) ?
337 SKL_DMA_HDA_LINK_OUTPUT_CLASS :
338 SKL_DMA_HDA_LINK_INPUT_CLASS;
339 node_id.node.vindex = params->link_dma_id;
340 break;
341
342 default:
343 node_id.node.dma_type =
344 (SKL_CONN_SOURCE == mconfig->hw_conn_type) ?
345 SKL_DMA_HDA_HOST_OUTPUT_CLASS :
346 SKL_DMA_HDA_HOST_INPUT_CLASS;
347 node_id.node.vindex = params->host_dma_id;
348 break;
349 }
350
351 cpr_mconfig->gtw_cfg.node_id = node_id.val;
352
353 if (SKL_CONN_SOURCE == mconfig->hw_conn_type)
354 cpr_mconfig->gtw_cfg.dma_buffer_size = 2 * mconfig->obs;
355 else
356 cpr_mconfig->gtw_cfg.dma_buffer_size = 2 * mconfig->ibs;
357
358 cpr_mconfig->cpr_feature_mask = 0;
359 cpr_mconfig->gtw_cfg.config_length = 0;
360
361 skl_copy_copier_caps(mconfig, cpr_mconfig);
362}
363
364static void skl_setup_out_format(struct skl_sst *ctx,
365 struct skl_module_cfg *mconfig,
366 struct skl_audio_data_format *out_fmt)
367{
368 struct skl_module_fmt *format = &mconfig->out_fmt;
369
370 out_fmt->number_of_channels = (u8)format->channels;
371 out_fmt->s_freq = format->s_freq;
372 out_fmt->bit_depth = format->bit_depth;
373 out_fmt->valid_bit_depth = format->valid_bit_depth;
374 out_fmt->ch_cfg = format->ch_cfg;
375
376 out_fmt->channel_map = skl_create_channel_map(out_fmt->ch_cfg);
377 out_fmt->interleaving = SKL_INTERLEAVING_PER_CHANNEL;
378
379 dev_dbg(ctx->dev, "copier out format chan=%d fre=%d bitdepth=%d\n",
380 out_fmt->number_of_channels, format->s_freq, format->bit_depth);
381}
382
383/*
384 * DSP needs SRC module for frequency conversion, SRC takes base module
385 * configuration and the target frequency as extra parameter passed as src
386 * config
387 */
388static void skl_set_src_format(struct skl_sst *ctx,
389 struct skl_module_cfg *mconfig,
390 struct skl_src_module_cfg *src_mconfig)
391{
392 struct skl_module_fmt *fmt = &mconfig->out_fmt;
393
394 skl_set_base_module_format(ctx, mconfig,
395 (struct skl_base_cfg *)src_mconfig);
396
397 src_mconfig->src_cfg = fmt->s_freq;
398}
399
400/*
401 * DSP needs updown module to do channel conversion. updown module take base
402 * module configuration and channel configuration
403 * It also take coefficients and now we have defaults applied here
404 */
405static void skl_set_updown_mixer_format(struct skl_sst *ctx,
406 struct skl_module_cfg *mconfig,
407 struct skl_up_down_mixer_cfg *mixer_mconfig)
408{
409 struct skl_module_fmt *fmt = &mconfig->out_fmt;
410 int i = 0;
411
412 skl_set_base_module_format(ctx, mconfig,
413 (struct skl_base_cfg *)mixer_mconfig);
414 mixer_mconfig->out_ch_cfg = fmt->ch_cfg;
415
416 /* Select F/W default coefficient */
417 mixer_mconfig->coeff_sel = 0x0;
418
419 /* User coeff, don't care since we are selecting F/W defaults */
420 for (i = 0; i < UP_DOWN_MIXER_MAX_COEFF; i++)
421 mixer_mconfig->coeff[i] = 0xDEADBEEF;
422}
423
424/*
425 * 'copier' is DSP internal module which copies data from Host DMA (HDA host
426 * dma) or link (hda link, SSP, PDM)
427 * Here we calculate the copier module parameters, like PCM format, output
428 * format, gateway settings
429 * copier_module_config is sent as input buffer with INIT_INSTANCE IPC msg
430 */
431static void skl_set_copier_format(struct skl_sst *ctx,
432 struct skl_module_cfg *mconfig,
433 struct skl_cpr_cfg *cpr_mconfig)
434{
435 struct skl_audio_data_format *out_fmt = &cpr_mconfig->out_fmt;
436 struct skl_base_cfg *base_cfg = (struct skl_base_cfg *)cpr_mconfig;
437
438 skl_set_base_module_format(ctx, mconfig, base_cfg);
439
440 skl_setup_out_format(ctx, mconfig, out_fmt);
441 skl_setup_cpr_gateway_cfg(ctx, mconfig, cpr_mconfig);
442}
443
444static u16 skl_get_module_param_size(struct skl_sst *ctx,
445 struct skl_module_cfg *mconfig)
446{
447 u16 param_size;
448
449 switch (mconfig->m_type) {
450 case SKL_MODULE_TYPE_COPIER:
451 param_size = sizeof(struct skl_cpr_cfg);
452 param_size += mconfig->formats_config.caps_size;
453 return param_size;
454
455 case SKL_MODULE_TYPE_SRCINT:
456 return sizeof(struct skl_src_module_cfg);
457
458 case SKL_MODULE_TYPE_UPDWMIX:
459 return sizeof(struct skl_up_down_mixer_cfg);
460
461 default:
462 /*
463 * return only base cfg when no specific module type is
464 * specified
465 */
466 return sizeof(struct skl_base_cfg);
467 }
468
469 return 0;
470}
471
472/*
473 * DSP firmware supports various modules like copier, SRC, updown etc.
474 * These modules required various parameters to be calculated and sent for
475 * the module initialization to DSP. By default a generic module needs only
476 * base module format configuration
477 */
478
479static int skl_set_module_format(struct skl_sst *ctx,
480 struct skl_module_cfg *module_config,
481 u16 *module_config_size,
482 void **param_data)
483{
484 u16 param_size;
485
486 param_size = skl_get_module_param_size(ctx, module_config);
487
488 *param_data = kzalloc(param_size, GFP_KERNEL);
489 if (NULL == *param_data)
490 return -ENOMEM;
491
492 *module_config_size = param_size;
493
494 switch (module_config->m_type) {
495 case SKL_MODULE_TYPE_COPIER:
496 skl_set_copier_format(ctx, module_config, *param_data);
497 break;
498
499 case SKL_MODULE_TYPE_SRCINT:
500 skl_set_src_format(ctx, module_config, *param_data);
501 break;
502
503 case SKL_MODULE_TYPE_UPDWMIX:
504 skl_set_updown_mixer_format(ctx, module_config, *param_data);
505 break;
506
507 default:
508 skl_set_base_module_format(ctx, module_config, *param_data);
509 break;
510
511 }
512
513 dev_dbg(ctx->dev, "Module type=%d config size: %d bytes\n",
514 module_config->id.module_id, param_size);
515 print_hex_dump(KERN_DEBUG, "Module params:", DUMP_PREFIX_OFFSET, 8, 4,
516 *param_data, param_size, false);
517 return 0;
518}
519
520static int skl_get_queue_index(struct skl_module_pin *mpin,
521 struct skl_module_inst_id id, int max)
522{
523 int i;
524
525 for (i = 0; i < max; i++) {
526 if (mpin[i].id.module_id == id.module_id &&
527 mpin[i].id.instance_id == id.instance_id)
528 return i;
529 }
530
531 return -EINVAL;
532}
533
534/*
535 * Allocates queue for each module.
536 * if dynamic, the pin_index is allocated 0 to max_pin.
537 * In static, the pin_index is fixed based on module_id and instance id
538 */
539static int skl_alloc_queue(struct skl_module_pin *mpin,
540 struct skl_module_inst_id id, int max)
541{
542 int i;
543
544 /*
545 * if pin in dynamic, find first free pin
546 * otherwise find match module and instance id pin as topology will
547 * ensure a unique pin is assigned to this so no need to
548 * allocate/free
549 */
550 for (i = 0; i < max; i++) {
551 if (mpin[i].is_dynamic) {
552 if (!mpin[i].in_use) {
553 mpin[i].in_use = true;
554 mpin[i].id.module_id = id.module_id;
555 mpin[i].id.instance_id = id.instance_id;
556 return i;
557 }
558 } else {
559 if (mpin[i].id.module_id == id.module_id &&
560 mpin[i].id.instance_id == id.instance_id)
561 return i;
562 }
563 }
564
565 return -EINVAL;
566}
567
568static void skl_free_queue(struct skl_module_pin *mpin, int q_index)
569{
570 if (mpin[q_index].is_dynamic) {
571 mpin[q_index].in_use = false;
572 mpin[q_index].id.module_id = 0;
573 mpin[q_index].id.instance_id = 0;
574 }
575}
576
577/*
578 * A module needs to be instanataited in DSP. A mdoule is present in a
579 * collection of module referred as a PIPE.
580 * We first calculate the module format, based on module type and then
581 * invoke the DSP by sending IPC INIT_INSTANCE using ipc helper
582 */
583int skl_init_module(struct skl_sst *ctx,
584 struct skl_module_cfg *mconfig, char *param)
585{
586 u16 module_config_size = 0;
587 void *param_data = NULL;
588 int ret;
589 struct skl_ipc_init_instance_msg msg;
590
591 dev_dbg(ctx->dev, "%s: module_id = %d instance=%d\n", __func__,
592 mconfig->id.module_id, mconfig->id.instance_id);
593
594 if (mconfig->pipe->state != SKL_PIPE_CREATED) {
595 dev_err(ctx->dev, "Pipe not created state= %d pipe_id= %d\n",
596 mconfig->pipe->state, mconfig->pipe->ppl_id);
597 return -EIO;
598 }
599
600 ret = skl_set_module_format(ctx, mconfig,
601 &module_config_size, &param_data);
602 if (ret < 0) {
603 dev_err(ctx->dev, "Failed to set module format ret=%d\n", ret);
604 return ret;
605 }
606
607 msg.module_id = mconfig->id.module_id;
608 msg.instance_id = mconfig->id.instance_id;
609 msg.ppl_instance_id = mconfig->pipe->ppl_id;
610 msg.param_data_size = module_config_size;
611 msg.core_id = mconfig->core_id;
612
613 ret = skl_ipc_init_instance(&ctx->ipc, &msg, param_data);
614 if (ret < 0) {
615 dev_err(ctx->dev, "Failed to init instance ret=%d\n", ret);
616 kfree(param_data);
617 return ret;
618 }
619 mconfig->m_state = SKL_MODULE_INIT_DONE;
620
621 return ret;
622}
623
624static void skl_dump_bind_info(struct skl_sst *ctx, struct skl_module_cfg
625 *src_module, struct skl_module_cfg *dst_module)
626{
627 dev_dbg(ctx->dev, "%s: src module_id = %d src_instance=%d\n",
628 __func__, src_module->id.module_id, src_module->id.instance_id);
629 dev_dbg(ctx->dev, "%s: dst_module=%d dst_instacne=%d\n", __func__,
630 dst_module->id.module_id, dst_module->id.instance_id);
631
632 dev_dbg(ctx->dev, "src_module state = %d dst module state = %d\n",
633 src_module->m_state, dst_module->m_state);
634}
635
636/*
637 * On module freeup, we need to unbind the module with modules
638 * it is already bind.
639 * Find the pin allocated and unbind then using bind_unbind IPC
640 */
641int skl_unbind_modules(struct skl_sst *ctx,
642 struct skl_module_cfg *src_mcfg,
643 struct skl_module_cfg *dst_mcfg)
644{
645 int ret;
646 struct skl_ipc_bind_unbind_msg msg;
647 struct skl_module_inst_id src_id = src_mcfg->id;
648 struct skl_module_inst_id dst_id = dst_mcfg->id;
649 int in_max = dst_mcfg->max_in_queue;
650 int out_max = src_mcfg->max_out_queue;
651 int src_index, dst_index;
652
653 skl_dump_bind_info(ctx, src_mcfg, dst_mcfg);
654
655 if (src_mcfg->m_state != SKL_MODULE_BIND_DONE)
656 return 0;
657
658 /*
659 * if intra module unbind, check if both modules are BIND,
660 * then send unbind
661 */
662 if ((src_mcfg->pipe->ppl_id != dst_mcfg->pipe->ppl_id) &&
663 dst_mcfg->m_state != SKL_MODULE_BIND_DONE)
664 return 0;
665 else if (src_mcfg->m_state < SKL_MODULE_INIT_DONE &&
666 dst_mcfg->m_state < SKL_MODULE_INIT_DONE)
667 return 0;
668
669 /* get src queue index */
670 src_index = skl_get_queue_index(src_mcfg->m_out_pin, dst_id, out_max);
671 if (src_index < 0)
672 return -EINVAL;
673
674 msg.src_queue = src_mcfg->m_out_pin[src_index].pin_index;
675
676 /* get dst queue index */
677 dst_index = skl_get_queue_index(dst_mcfg->m_in_pin, src_id, in_max);
678 if (dst_index < 0)
679 return -EINVAL;
680
681 msg.dst_queue = dst_mcfg->m_in_pin[dst_index].pin_index;
682
683 msg.module_id = src_mcfg->id.module_id;
684 msg.instance_id = src_mcfg->id.instance_id;
685 msg.dst_module_id = dst_mcfg->id.module_id;
686 msg.dst_instance_id = dst_mcfg->id.instance_id;
687 msg.bind = false;
688
689 ret = skl_ipc_bind_unbind(&ctx->ipc, &msg);
690 if (!ret) {
691 src_mcfg->m_state = SKL_MODULE_UNINIT;
692 /* free queue only if unbind is success */
693 skl_free_queue(src_mcfg->m_out_pin, src_index);
694 skl_free_queue(dst_mcfg->m_in_pin, dst_index);
695 }
696
697 return ret;
698}
699
700/*
701 * Once a module is instantiated it need to be 'bind' with other modules in
702 * the pipeline. For binding we need to find the module pins which are bind
703 * together
704 * This function finds the pins and then sends bund_unbind IPC message to
705 * DSP using IPC helper
706 */
707int skl_bind_modules(struct skl_sst *ctx,
708 struct skl_module_cfg *src_mcfg,
709 struct skl_module_cfg *dst_mcfg)
710{
711 int ret;
712 struct skl_ipc_bind_unbind_msg msg;
713 struct skl_module_inst_id src_id = src_mcfg->id;
714 struct skl_module_inst_id dst_id = dst_mcfg->id;
715 int in_max = dst_mcfg->max_in_queue;
716 int out_max = src_mcfg->max_out_queue;
717 int src_index, dst_index;
718
719 skl_dump_bind_info(ctx, src_mcfg, dst_mcfg);
720
721 if (src_mcfg->m_state < SKL_MODULE_INIT_DONE &&
722 dst_mcfg->m_state < SKL_MODULE_INIT_DONE)
723 return 0;
724
725 src_index = skl_alloc_queue(src_mcfg->m_out_pin, dst_id, out_max);
726 if (src_index < 0)
727 return -EINVAL;
728
729 msg.src_queue = src_mcfg->m_out_pin[src_index].pin_index;
730 dst_index = skl_alloc_queue(dst_mcfg->m_in_pin, src_id, in_max);
731 if (dst_index < 0) {
732 skl_free_queue(src_mcfg->m_out_pin, src_index);
733 return -EINVAL;
734 }
735
736 msg.dst_queue = dst_mcfg->m_in_pin[dst_index].pin_index;
737
738 dev_dbg(ctx->dev, "src queue = %d dst queue =%d\n",
739 msg.src_queue, msg.dst_queue);
740
741 msg.module_id = src_mcfg->id.module_id;
742 msg.instance_id = src_mcfg->id.instance_id;
743 msg.dst_module_id = dst_mcfg->id.module_id;
744 msg.dst_instance_id = dst_mcfg->id.instance_id;
745 msg.bind = true;
746
747 ret = skl_ipc_bind_unbind(&ctx->ipc, &msg);
748
749 if (!ret) {
750 src_mcfg->m_state = SKL_MODULE_BIND_DONE;
751 } else {
752 /* error case , if IPC fails, clear the queue index */
753 skl_free_queue(src_mcfg->m_out_pin, src_index);
754 skl_free_queue(dst_mcfg->m_in_pin, dst_index);
755 }
756
757 return ret;
758}
759
760static int skl_set_pipe_state(struct skl_sst *ctx, struct skl_pipe *pipe,
761 enum skl_ipc_pipeline_state state)
762{
763 dev_dbg(ctx->dev, "%s: pipe_satate = %d\n", __func__, state);
764
765 return skl_ipc_set_pipeline_state(&ctx->ipc, pipe->ppl_id, state);
766}
767
768/*
769 * A pipeline is a collection of modules. Before a module in instantiated a
770 * pipeline needs to be created for it.
771 * This function creates pipeline, by sending create pipeline IPC messages
772 * to FW
773 */
774int skl_create_pipeline(struct skl_sst *ctx, struct skl_pipe *pipe)
775{
776 int ret;
777
778 dev_dbg(ctx->dev, "%s: pipe_id = %d\n", __func__, pipe->ppl_id);
779
780 ret = skl_ipc_create_pipeline(&ctx->ipc, pipe->memory_pages,
781 pipe->pipe_priority, pipe->ppl_id);
782 if (ret < 0) {
783 dev_err(ctx->dev, "Failed to create pipeline\n");
784 return ret;
785 }
786
787 pipe->state = SKL_PIPE_CREATED;
788
789 return 0;
790}
791
792/*
793 * A pipeline needs to be deleted on cleanup. If a pipeline is running, then
794 * pause the pipeline first and then delete it
795 * The pipe delete is done by sending delete pipeline IPC. DSP will stop the
796 * DMA engines and releases resources
797 */
798int skl_delete_pipe(struct skl_sst *ctx, struct skl_pipe *pipe)
799{
800 int ret;
801
802 dev_dbg(ctx->dev, "%s: pipe = %d\n", __func__, pipe->ppl_id);
803
804 /* If pipe is not started, do not try to stop the pipe in FW. */
805 if (pipe->state > SKL_PIPE_STARTED) {
806 ret = skl_set_pipe_state(ctx, pipe, PPL_PAUSED);
807 if (ret < 0) {
808 dev_err(ctx->dev, "Failed to stop pipeline\n");
809 return ret;
810 }
811
812 pipe->state = SKL_PIPE_PAUSED;
813 } else {
814 /* If pipe was not created in FW, do not try to delete it */
815 if (pipe->state < SKL_PIPE_CREATED)
816 return 0;
817
818 ret = skl_ipc_delete_pipeline(&ctx->ipc, pipe->ppl_id);
819 if (ret < 0)
820 dev_err(ctx->dev, "Failed to delete pipeline\n");
821 }
822
823 return ret;
824}
825
826/*
827 * A pipeline is also a scheduling entity in DSP which can be run, stopped
828 * For processing data the pipe need to be run by sending IPC set pipe state
829 * to DSP
830 */
831int skl_run_pipe(struct skl_sst *ctx, struct skl_pipe *pipe)
832{
833 int ret;
834
835 dev_dbg(ctx->dev, "%s: pipe = %d\n", __func__, pipe->ppl_id);
836
837 /* If pipe was not created in FW, do not try to pause or delete */
838 if (pipe->state < SKL_PIPE_CREATED)
839 return 0;
840
841 /* Pipe has to be paused before it is started */
842 ret = skl_set_pipe_state(ctx, pipe, PPL_PAUSED);
843 if (ret < 0) {
844 dev_err(ctx->dev, "Failed to pause pipe\n");
845 return ret;
846 }
847
848 pipe->state = SKL_PIPE_PAUSED;
849
850 ret = skl_set_pipe_state(ctx, pipe, PPL_RUNNING);
851 if (ret < 0) {
852 dev_err(ctx->dev, "Failed to start pipe\n");
853 return ret;
854 }
855
856 pipe->state = SKL_PIPE_STARTED;
857
858 return 0;
859}
860
861/*
862 * Stop the pipeline by sending set pipe state IPC
863 * DSP doesnt implement stop so we always send pause message
864 */
865int skl_stop_pipe(struct skl_sst *ctx, struct skl_pipe *pipe)
866{
867 int ret;
868
869 dev_dbg(ctx->dev, "In %s pipe=%d\n", __func__, pipe->ppl_id);
870
871 /* If pipe was not created in FW, do not try to pause or delete */
872 if (pipe->state < SKL_PIPE_PAUSED)
873 return 0;
874
875 ret = skl_set_pipe_state(ctx, pipe, PPL_PAUSED);
876 if (ret < 0) {
877 dev_dbg(ctx->dev, "Failed to stop pipe\n");
878 return ret;
879 }
880
881 pipe->state = SKL_PIPE_CREATED;
882
883 return 0;
884}
diff --git a/sound/soc/intel/skylake/skl-nhlt.c b/sound/soc/intel/skylake/skl-nhlt.c
new file mode 100644
index 000000000000..13036b19d7e5
--- /dev/null
+++ b/sound/soc/intel/skylake/skl-nhlt.c
@@ -0,0 +1,140 @@
1/*
2 * skl-nhlt.c - Intel SKL Platform NHLT parsing
3 *
4 * Copyright (C) 2015 Intel Corp
5 * Author: Sanjiv Kumar <sanjiv.kumar@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 *
19 */
20#include "skl.h"
21
22/* Unique identification for getting NHLT blobs */
23static u8 OSC_UUID[16] = {0x6E, 0x88, 0x9F, 0xA6, 0xEB, 0x6C, 0x94, 0x45,
24 0xA4, 0x1F, 0x7B, 0x5D, 0xCE, 0x24, 0xC5, 0x53};
25
26#define DSDT_NHLT_PATH "\\_SB.PCI0.HDAS"
27
28void __iomem *skl_nhlt_init(struct device *dev)
29{
30 acpi_handle handle;
31 union acpi_object *obj;
32 struct nhlt_resource_desc *nhlt_ptr = NULL;
33
34 if (ACPI_FAILURE(acpi_get_handle(NULL, DSDT_NHLT_PATH, &handle))) {
35 dev_err(dev, "Requested NHLT device not found\n");
36 return NULL;
37 }
38
39 obj = acpi_evaluate_dsm(handle, OSC_UUID, 1, 1, NULL);
40 if (obj && obj->type == ACPI_TYPE_BUFFER) {
41 nhlt_ptr = (struct nhlt_resource_desc *)obj->buffer.pointer;
42
43 return ioremap_cache(nhlt_ptr->min_addr, nhlt_ptr->length);
44 }
45
46 dev_err(dev, "device specific method to extract NHLT blob failed\n");
47 return NULL;
48}
49
50void skl_nhlt_free(void __iomem *addr)
51{
52 iounmap(addr);
53 addr = NULL;
54}
55
56static struct nhlt_specific_cfg *skl_get_specific_cfg(
57 struct device *dev, struct nhlt_fmt *fmt,
58 u8 no_ch, u32 rate, u16 bps)
59{
60 struct nhlt_specific_cfg *sp_config;
61 struct wav_fmt *wfmt;
62 struct nhlt_fmt_cfg *fmt_config = fmt->fmt_config;
63 int i;
64
65 dev_dbg(dev, "Format count =%d\n", fmt->fmt_count);
66
67 for (i = 0; i < fmt->fmt_count; i++) {
68 wfmt = &fmt_config->fmt_ext.fmt;
69 dev_dbg(dev, "ch=%d fmt=%d s_rate=%d\n", wfmt->channels,
70 wfmt->bits_per_sample, wfmt->samples_per_sec);
71 if (wfmt->channels == no_ch && wfmt->samples_per_sec == rate &&
72 wfmt->bits_per_sample == bps) {
73 sp_config = &fmt_config->config;
74
75 return sp_config;
76 }
77
78 fmt_config = (struct nhlt_fmt_cfg *)(fmt_config->config.caps +
79 fmt_config->config.size);
80 }
81
82 return NULL;
83}
84
85static void dump_config(struct device *dev, u32 instance_id, u8 linktype,
86 u8 s_fmt, u8 num_channels, u32 s_rate, u8 dirn, u16 bps)
87{
88 dev_dbg(dev, "Input configuration\n");
89 dev_dbg(dev, "ch=%d fmt=%d s_rate=%d\n", num_channels, s_fmt, s_rate);
90 dev_dbg(dev, "vbus_id=%d link_type=%d\n", instance_id, linktype);
91 dev_dbg(dev, "bits_per_sample=%d\n", bps);
92}
93
94static bool skl_check_ep_match(struct device *dev, struct nhlt_endpoint *epnt,
95 u32 instance_id, u8 link_type, u8 dirn)
96{
97 dev_dbg(dev, "vbus_id=%d link_type=%d dir=%d\n",
98 epnt->virtual_bus_id, epnt->linktype, epnt->direction);
99
100 if ((epnt->virtual_bus_id == instance_id) &&
101 (epnt->linktype == link_type) &&
102 (epnt->direction == dirn))
103 return true;
104 else
105 return false;
106}
107
108struct nhlt_specific_cfg
109*skl_get_ep_blob(struct skl *skl, u32 instance, u8 link_type,
110 u8 s_fmt, u8 num_ch, u32 s_rate, u8 dirn)
111{
112 struct nhlt_fmt *fmt;
113 struct nhlt_endpoint *epnt;
114 struct hdac_bus *bus = ebus_to_hbus(&skl->ebus);
115 struct device *dev = bus->dev;
116 struct nhlt_specific_cfg *sp_config;
117 struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt;
118 u16 bps = num_ch * s_fmt;
119 u8 j;
120
121 dump_config(dev, instance, link_type, s_fmt, num_ch, s_rate, dirn, bps);
122
123 epnt = (struct nhlt_endpoint *)nhlt->desc;
124
125 dev_dbg(dev, "endpoint count =%d\n", nhlt->endpoint_count);
126
127 for (j = 0; j < nhlt->endpoint_count; j++) {
128 if (skl_check_ep_match(dev, epnt, instance, link_type, dirn)) {
129 fmt = (struct nhlt_fmt *)(epnt->config.caps +
130 epnt->config.size);
131 sp_config = skl_get_specific_cfg(dev, fmt, num_ch, s_rate, bps);
132 if (sp_config)
133 return sp_config;
134 }
135
136 epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
137 }
138
139 return NULL;
140}
diff --git a/sound/soc/intel/skylake/skl-nhlt.h b/sound/soc/intel/skylake/skl-nhlt.h
new file mode 100644
index 000000000000..3769f9fefe2b
--- /dev/null
+++ b/sound/soc/intel/skylake/skl-nhlt.h
@@ -0,0 +1,106 @@
1/*
2 * skl-nhlt.h - Intel HDA Platform NHLT header
3 *
4 * Copyright (C) 2015 Intel Corp
5 * Author: Sanjiv Kumar <sanjiv.kumar@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 *
19 */
20#ifndef __SKL_NHLT_H__
21#define __SKL_NHLT_H__
22
23#include <linux/acpi.h>
24
25struct wav_fmt {
26 u16 fmt_tag;
27 u16 channels;
28 u32 samples_per_sec;
29 u32 avg_bytes_per_sec;
30 u16 block_align;
31 u16 bits_per_sample;
32 u16 cb_size;
33} __packed;
34
35struct wav_fmt_ext {
36 struct wav_fmt fmt;
37 union samples {
38 u16 valid_bits_per_sample;
39 u16 samples_per_block;
40 u16 reserved;
41 } sample;
42 u32 channel_mask;
43 u8 sub_fmt[16];
44} __packed;
45
46enum nhlt_link_type {
47 NHLT_LINK_HDA = 0,
48 NHLT_LINK_DSP = 1,
49 NHLT_LINK_DMIC = 2,
50 NHLT_LINK_SSP = 3,
51 NHLT_LINK_INVALID
52};
53
54enum nhlt_device_type {
55 NHLT_DEVICE_BT = 0,
56 NHLT_DEVICE_DMIC = 1,
57 NHLT_DEVICE_I2S = 4,
58 NHLT_DEVICE_INVALID
59};
60
61struct nhlt_specific_cfg {
62 u32 size;
63 u8 caps[0];
64} __packed;
65
66struct nhlt_fmt_cfg {
67 struct wav_fmt_ext fmt_ext;
68 struct nhlt_specific_cfg config;
69} __packed;
70
71struct nhlt_fmt {
72 u8 fmt_count;
73 struct nhlt_fmt_cfg fmt_config[0];
74} __packed;
75
76struct nhlt_endpoint {
77 u32 length;
78 u8 linktype;
79 u8 instance_id;
80 u16 vendor_id;
81 u16 device_id;
82 u16 revision_id;
83 u32 subsystem_id;
84 u8 device_type;
85 u8 direction;
86 u8 virtual_bus_id;
87 struct nhlt_specific_cfg config;
88} __packed;
89
90struct nhlt_acpi_table {
91 struct acpi_table_header header;
92 u8 endpoint_count;
93 struct nhlt_endpoint desc[0];
94} __packed;
95
96struct nhlt_resource_desc {
97 u32 extra;
98 u16 flags;
99 u64 addr_spc_gra;
100 u64 min_addr;
101 u64 max_addr;
102 u64 addr_trans_offset;
103 u64 length;
104} __packed;
105
106#endif
diff --git a/sound/soc/intel/skylake/skl-pcm.c b/sound/soc/intel/skylake/skl-pcm.c
new file mode 100644
index 000000000000..7d617bf493bc
--- /dev/null
+++ b/sound/soc/intel/skylake/skl-pcm.c
@@ -0,0 +1,916 @@
1/*
2 * skl-pcm.c -ASoC HDA Platform driver file implementing PCM functionality
3 *
4 * Copyright (C) 2014-2015 Intel Corp
5 * Author: Jeeja KP <jeeja.kp@intel.com>
6 *
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; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19 *
20 */
21
22#include <linux/pci.h>
23#include <linux/pm_runtime.h>
24#include <sound/pcm_params.h>
25#include <sound/soc.h>
26#include "skl.h"
27
28#define HDA_MONO 1
29#define HDA_STEREO 2
30
31static struct snd_pcm_hardware azx_pcm_hw = {
32 .info = (SNDRV_PCM_INFO_MMAP |
33 SNDRV_PCM_INFO_INTERLEAVED |
34 SNDRV_PCM_INFO_BLOCK_TRANSFER |
35 SNDRV_PCM_INFO_MMAP_VALID |
36 SNDRV_PCM_INFO_PAUSE |
37 SNDRV_PCM_INFO_SYNC_START |
38 SNDRV_PCM_INFO_HAS_WALL_CLOCK | /* legacy */
39 SNDRV_PCM_INFO_HAS_LINK_ATIME |
40 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP),
41 .formats = SNDRV_PCM_FMTBIT_S16_LE,
42 .rates = SNDRV_PCM_RATE_48000,
43 .rate_min = 48000,
44 .rate_max = 48000,
45 .channels_min = 2,
46 .channels_max = 2,
47 .buffer_bytes_max = AZX_MAX_BUF_SIZE,
48 .period_bytes_min = 128,
49 .period_bytes_max = AZX_MAX_BUF_SIZE / 2,
50 .periods_min = 2,
51 .periods_max = AZX_MAX_FRAG,
52 .fifo_size = 0,
53};
54
55static inline
56struct hdac_ext_stream *get_hdac_ext_stream(struct snd_pcm_substream *substream)
57{
58 return substream->runtime->private_data;
59}
60
61static struct hdac_ext_bus *get_bus_ctx(struct snd_pcm_substream *substream)
62{
63 struct hdac_ext_stream *stream = get_hdac_ext_stream(substream);
64 struct hdac_stream *hstream = hdac_stream(stream);
65 struct hdac_bus *bus = hstream->bus;
66
67 return hbus_to_ebus(bus);
68}
69
70static int skl_substream_alloc_pages(struct hdac_ext_bus *ebus,
71 struct snd_pcm_substream *substream,
72 size_t size)
73{
74 struct hdac_ext_stream *stream = get_hdac_ext_stream(substream);
75
76 hdac_stream(stream)->bufsize = 0;
77 hdac_stream(stream)->period_bytes = 0;
78 hdac_stream(stream)->format_val = 0;
79
80 return snd_pcm_lib_malloc_pages(substream, size);
81}
82
83static int skl_substream_free_pages(struct hdac_bus *bus,
84 struct snd_pcm_substream *substream)
85{
86 return snd_pcm_lib_free_pages(substream);
87}
88
89static void skl_set_pcm_constrains(struct hdac_ext_bus *ebus,
90 struct snd_pcm_runtime *runtime)
91{
92 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
93
94 /* avoid wrap-around with wall-clock */
95 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_TIME,
96 20, 178000000);
97}
98
99static enum hdac_ext_stream_type skl_get_host_stream_type(struct hdac_ext_bus *ebus)
100{
101 if (ebus->ppcap)
102 return HDAC_EXT_STREAM_TYPE_HOST;
103 else
104 return HDAC_EXT_STREAM_TYPE_COUPLED;
105}
106
107static int skl_pcm_open(struct snd_pcm_substream *substream,
108 struct snd_soc_dai *dai)
109{
110 struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
111 struct hdac_ext_stream *stream;
112 struct snd_pcm_runtime *runtime = substream->runtime;
113 struct skl_dma_params *dma_params;
114 int ret;
115
116 dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
117 ret = pm_runtime_get_sync(dai->dev);
118 if (ret)
119 return ret;
120
121 stream = snd_hdac_ext_stream_assign(ebus, substream,
122 skl_get_host_stream_type(ebus));
123 if (stream == NULL)
124 return -EBUSY;
125
126 skl_set_pcm_constrains(ebus, runtime);
127
128 /*
129 * disable WALLCLOCK timestamps for capture streams
130 * until we figure out how to handle digital inputs
131 */
132 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
133 runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_WALL_CLOCK; /* legacy */
134 runtime->hw.info &= ~SNDRV_PCM_INFO_HAS_LINK_ATIME;
135 }
136
137 runtime->private_data = stream;
138
139 dma_params = kzalloc(sizeof(*dma_params), GFP_KERNEL);
140 if (!dma_params)
141 return -ENOMEM;
142
143 dma_params->stream_tag = hdac_stream(stream)->stream_tag;
144 snd_soc_dai_set_dma_data(dai, substream, dma_params);
145
146 dev_dbg(dai->dev, "stream tag set in dma params=%d\n",
147 dma_params->stream_tag);
148 snd_pcm_set_sync(substream);
149
150 return 0;
151}
152
153static int skl_get_format(struct snd_pcm_substream *substream,
154 struct snd_soc_dai *dai)
155{
156 struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream);
157 struct skl_dma_params *dma_params;
158 struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
159 int format_val = 0;
160
161 if (ebus->ppcap) {
162 struct snd_pcm_runtime *runtime = substream->runtime;
163
164 format_val = snd_hdac_calc_stream_format(runtime->rate,
165 runtime->channels,
166 runtime->format,
167 32, 0);
168 } else {
169 struct snd_soc_dai *codec_dai = rtd->codec_dai;
170
171 dma_params = snd_soc_dai_get_dma_data(codec_dai, substream);
172 if (dma_params)
173 format_val = dma_params->format;
174 }
175
176 return format_val;
177}
178
179static int skl_pcm_prepare(struct snd_pcm_substream *substream,
180 struct snd_soc_dai *dai)
181{
182 struct hdac_ext_stream *stream = get_hdac_ext_stream(substream);
183 unsigned int format_val;
184 int err;
185
186 dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
187 if (hdac_stream(stream)->prepared) {
188 dev_dbg(dai->dev, "already stream is prepared - returning\n");
189 return 0;
190 }
191
192 format_val = skl_get_format(substream, dai);
193 dev_dbg(dai->dev, "stream_tag=%d formatvalue=%d\n",
194 hdac_stream(stream)->stream_tag, format_val);
195 snd_hdac_stream_reset(hdac_stream(stream));
196
197 err = snd_hdac_stream_set_params(hdac_stream(stream), format_val);
198 if (err < 0)
199 return err;
200
201 err = snd_hdac_stream_setup(hdac_stream(stream));
202 if (err < 0)
203 return err;
204
205 hdac_stream(stream)->prepared = 1;
206
207 return err;
208}
209
210static int skl_pcm_hw_params(struct snd_pcm_substream *substream,
211 struct snd_pcm_hw_params *params,
212 struct snd_soc_dai *dai)
213{
214 struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
215 struct hdac_ext_stream *stream = get_hdac_ext_stream(substream);
216 struct snd_pcm_runtime *runtime = substream->runtime;
217 int ret, dma_id;
218
219 dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
220 ret = skl_substream_alloc_pages(ebus, substream,
221 params_buffer_bytes(params));
222 if (ret < 0)
223 return ret;
224
225 dev_dbg(dai->dev, "format_val, rate=%d, ch=%d, format=%d\n",
226 runtime->rate, runtime->channels, runtime->format);
227
228 dma_id = hdac_stream(stream)->stream_tag - 1;
229 dev_dbg(dai->dev, "dma_id=%d\n", dma_id);
230
231 return 0;
232}
233
234static void skl_pcm_close(struct snd_pcm_substream *substream,
235 struct snd_soc_dai *dai)
236{
237 struct hdac_ext_stream *stream = get_hdac_ext_stream(substream);
238 struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
239 struct skl_dma_params *dma_params = NULL;
240
241 dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
242
243 snd_hdac_ext_stream_release(stream, skl_get_host_stream_type(ebus));
244
245 dma_params = snd_soc_dai_get_dma_data(dai, substream);
246 /*
247 * now we should set this to NULL as we are freeing by the
248 * dma_params
249 */
250 snd_soc_dai_set_dma_data(dai, substream, NULL);
251
252 pm_runtime_mark_last_busy(dai->dev);
253 pm_runtime_put_autosuspend(dai->dev);
254 kfree(dma_params);
255}
256
257static int skl_pcm_hw_free(struct snd_pcm_substream *substream,
258 struct snd_soc_dai *dai)
259{
260 struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
261 struct hdac_ext_stream *stream = get_hdac_ext_stream(substream);
262
263 dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
264
265 snd_hdac_stream_cleanup(hdac_stream(stream));
266 hdac_stream(stream)->prepared = 0;
267
268 return skl_substream_free_pages(ebus_to_hbus(ebus), substream);
269}
270
271static int skl_link_hw_params(struct snd_pcm_substream *substream,
272 struct snd_pcm_hw_params *params,
273 struct snd_soc_dai *dai)
274{
275 struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
276 struct hdac_ext_stream *link_dev;
277 struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream);
278 struct skl_dma_params *dma_params;
279 struct snd_soc_dai *codec_dai = rtd->codec_dai;
280 int dma_id;
281
282 pr_debug("%s\n", __func__);
283 link_dev = snd_hdac_ext_stream_assign(ebus, substream,
284 HDAC_EXT_STREAM_TYPE_LINK);
285 if (!link_dev)
286 return -EBUSY;
287
288 snd_soc_dai_set_dma_data(dai, substream, (void *)link_dev);
289
290 /* set the stream tag in the codec dai dma params */
291 dma_params = (struct skl_dma_params *)
292 snd_soc_dai_get_dma_data(codec_dai, substream);
293 if (dma_params)
294 dma_params->stream_tag = hdac_stream(link_dev)->stream_tag;
295 snd_soc_dai_set_dma_data(codec_dai, substream, (void *)dma_params);
296 dma_id = hdac_stream(link_dev)->stream_tag - 1;
297
298 return 0;
299}
300
301static int skl_link_pcm_prepare(struct snd_pcm_substream *substream,
302 struct snd_soc_dai *dai)
303{
304 struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream);
305 struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
306 struct hdac_ext_stream *link_dev =
307 snd_soc_dai_get_dma_data(dai, substream);
308 unsigned int format_val = 0;
309 struct skl_dma_params *dma_params;
310 struct snd_soc_dai *codec_dai = rtd->codec_dai;
311 struct snd_pcm_hw_params *params;
312 struct snd_interval *channels, *rate;
313 struct hdac_ext_link *link;
314
315 dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
316 if (link_dev->link_prepared) {
317 dev_dbg(dai->dev, "already stream is prepared - returning\n");
318 return 0;
319 }
320 params = devm_kzalloc(dai->dev, sizeof(*params), GFP_KERNEL);
321 if (params == NULL)
322 return -ENOMEM;
323
324 channels = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
325 channels->min = channels->max = substream->runtime->channels;
326 rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
327 rate->min = rate->max = substream->runtime->rate;
328 snd_mask_set(&params->masks[SNDRV_PCM_HW_PARAM_FORMAT -
329 SNDRV_PCM_HW_PARAM_FIRST_MASK],
330 substream->runtime->format);
331
332
333 dma_params = (struct skl_dma_params *)
334 snd_soc_dai_get_dma_data(codec_dai, substream);
335 if (dma_params)
336 format_val = dma_params->format;
337 dev_dbg(dai->dev, "stream_tag=%d formatvalue=%d codec_dai_name=%s\n",
338 hdac_stream(link_dev)->stream_tag, format_val, codec_dai->name);
339
340 snd_hdac_ext_link_stream_reset(link_dev);
341
342 snd_hdac_ext_link_stream_setup(link_dev, format_val);
343
344 link = snd_hdac_ext_bus_get_link(ebus, rtd->codec->component.name);
345 if (!link)
346 return -EINVAL;
347
348 snd_hdac_ext_link_set_stream_id(link, hdac_stream(link_dev)->stream_tag);
349 link_dev->link_prepared = 1;
350
351 return 0;
352}
353
354static int skl_link_pcm_trigger(struct snd_pcm_substream *substream,
355 int cmd, struct snd_soc_dai *dai)
356{
357 struct hdac_ext_stream *link_dev =
358 snd_soc_dai_get_dma_data(dai, substream);
359
360 dev_dbg(dai->dev, "In %s cmd=%d\n", __func__, cmd);
361 switch (cmd) {
362 case SNDRV_PCM_TRIGGER_START:
363 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
364 case SNDRV_PCM_TRIGGER_RESUME:
365 snd_hdac_ext_link_stream_start(link_dev);
366 break;
367
368 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
369 case SNDRV_PCM_TRIGGER_SUSPEND:
370 case SNDRV_PCM_TRIGGER_STOP:
371 snd_hdac_ext_link_stream_clear(link_dev);
372 break;
373
374 default:
375 return -EINVAL;
376 }
377 return 0;
378}
379
380static int skl_link_hw_free(struct snd_pcm_substream *substream,
381 struct snd_soc_dai *dai)
382{
383 struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
384 struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream);
385 struct hdac_ext_stream *link_dev =
386 snd_soc_dai_get_dma_data(dai, substream);
387 struct hdac_ext_link *link;
388
389 dev_dbg(dai->dev, "%s: %s\n", __func__, dai->name);
390
391 link_dev->link_prepared = 0;
392
393 link = snd_hdac_ext_bus_get_link(ebus, rtd->codec->component.name);
394 if (!link)
395 return -EINVAL;
396
397 snd_hdac_ext_link_clear_stream_id(link, hdac_stream(link_dev)->stream_tag);
398 snd_hdac_ext_stream_release(link_dev, HDAC_EXT_STREAM_TYPE_LINK);
399 return 0;
400}
401
402static int skl_hda_be_startup(struct snd_pcm_substream *substream,
403 struct snd_soc_dai *dai)
404{
405 return pm_runtime_get_sync(dai->dev);
406}
407
408static void skl_hda_be_shutdown(struct snd_pcm_substream *substream,
409 struct snd_soc_dai *dai)
410{
411 pm_runtime_mark_last_busy(dai->dev);
412 pm_runtime_put_autosuspend(dai->dev);
413}
414
415static struct snd_soc_dai_ops skl_pcm_dai_ops = {
416 .startup = skl_pcm_open,
417 .shutdown = skl_pcm_close,
418 .prepare = skl_pcm_prepare,
419 .hw_params = skl_pcm_hw_params,
420 .hw_free = skl_pcm_hw_free,
421};
422
423static struct snd_soc_dai_ops skl_dmic_dai_ops = {
424 .startup = skl_hda_be_startup,
425 .shutdown = skl_hda_be_shutdown,
426};
427
428static struct snd_soc_dai_ops skl_link_dai_ops = {
429 .startup = skl_hda_be_startup,
430 .prepare = skl_link_pcm_prepare,
431 .hw_params = skl_link_hw_params,
432 .hw_free = skl_link_hw_free,
433 .trigger = skl_link_pcm_trigger,
434 .shutdown = skl_hda_be_shutdown,
435};
436
437static struct snd_soc_dai_driver skl_platform_dai[] = {
438{
439 .name = "System Pin",
440 .ops = &skl_pcm_dai_ops,
441 .playback = {
442 .stream_name = "System Playback",
443 .channels_min = HDA_MONO,
444 .channels_max = HDA_STEREO,
445 .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_8000,
446 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
447 },
448 .capture = {
449 .stream_name = "System Capture",
450 .channels_min = HDA_MONO,
451 .channels_max = HDA_STEREO,
452 .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000,
453 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
454 },
455},
456{
457 .name = "Reference Pin",
458 .ops = &skl_pcm_dai_ops,
459 .capture = {
460 .stream_name = "Reference Capture",
461 .channels_min = HDA_MONO,
462 .channels_max = HDA_STEREO,
463 .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000,
464 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
465 },
466},
467{
468 .name = "Deepbuffer Pin",
469 .ops = &skl_pcm_dai_ops,
470 .playback = {
471 .stream_name = "Deepbuffer Playback",
472 .channels_min = HDA_STEREO,
473 .channels_max = HDA_STEREO,
474 .rates = SNDRV_PCM_RATE_48000,
475 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
476 },
477},
478{
479 .name = "LowLatency Pin",
480 .ops = &skl_pcm_dai_ops,
481 .playback = {
482 .stream_name = "Low Latency Playback",
483 .channels_min = HDA_STEREO,
484 .channels_max = HDA_STEREO,
485 .rates = SNDRV_PCM_RATE_48000,
486 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
487 },
488},
489/* BE CPU Dais */
490{
491 .name = "iDisp Pin",
492 .ops = &skl_link_dai_ops,
493 .playback = {
494 .stream_name = "iDisp Tx",
495 .channels_min = HDA_STEREO,
496 .channels_max = HDA_STEREO,
497 .rates = SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_48000,
498 .formats = SNDRV_PCM_FMTBIT_S16_LE,
499 },
500},
501{
502 .name = "DMIC01 Pin",
503 .ops = &skl_dmic_dai_ops,
504 .capture = {
505 .stream_name = "DMIC01 Rx",
506 .channels_min = HDA_STEREO,
507 .channels_max = HDA_STEREO,
508 .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000,
509 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
510 },
511},
512{
513 .name = "DMIC23 Pin",
514 .ops = &skl_dmic_dai_ops,
515 .capture = {
516 .stream_name = "DMIC23 Rx",
517 .channels_min = HDA_STEREO,
518 .channels_max = HDA_STEREO,
519 .rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_16000,
520 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
521 },
522},
523{
524 .name = "HD-Codec Pin",
525 .ops = &skl_link_dai_ops,
526 .playback = {
527 .stream_name = "HD-Codec Tx",
528 .channels_min = HDA_STEREO,
529 .channels_max = HDA_STEREO,
530 .rates = SNDRV_PCM_RATE_48000,
531 .formats = SNDRV_PCM_FMTBIT_S16_LE,
532 },
533 .capture = {
534 .stream_name = "HD-Codec Rx",
535 .channels_min = HDA_STEREO,
536 .channels_max = HDA_STEREO,
537 .rates = SNDRV_PCM_RATE_48000,
538 .formats = SNDRV_PCM_FMTBIT_S16_LE,
539 },
540},
541{
542 .name = "HD-Codec-SPK Pin",
543 .ops = &skl_link_dai_ops,
544 .playback = {
545 .stream_name = "HD-Codec-SPK Tx",
546 .channels_min = HDA_STEREO,
547 .channels_max = HDA_STEREO,
548 .rates = SNDRV_PCM_RATE_48000,
549 .formats = SNDRV_PCM_FMTBIT_S16_LE,
550 },
551},
552{
553 .name = "HD-Codec-AMIC Pin",
554 .ops = &skl_link_dai_ops,
555 .capture = {
556 .stream_name = "HD-Codec-AMIC Rx",
557 .channels_min = HDA_STEREO,
558 .channels_max = HDA_STEREO,
559 .rates = SNDRV_PCM_RATE_48000,
560 .formats = SNDRV_PCM_FMTBIT_S16_LE,
561 },
562},
563};
564
565static int skl_platform_open(struct snd_pcm_substream *substream)
566{
567 struct snd_pcm_runtime *runtime;
568 struct snd_soc_pcm_runtime *rtd = substream->private_data;
569 struct snd_soc_dai_link *dai_link = rtd->dai_link;
570
571 dev_dbg(rtd->cpu_dai->dev, "In %s:%s\n", __func__,
572 dai_link->cpu_dai_name);
573
574 runtime = substream->runtime;
575 snd_soc_set_runtime_hwparams(substream, &azx_pcm_hw);
576
577 return 0;
578}
579
580static int skl_pcm_trigger(struct snd_pcm_substream *substream,
581 int cmd)
582{
583 struct hdac_ext_bus *ebus = get_bus_ctx(substream);
584 struct hdac_bus *bus = ebus_to_hbus(ebus);
585 struct hdac_ext_stream *stream;
586 struct snd_pcm_substream *s;
587 bool start;
588 int sbits = 0;
589 unsigned long cookie;
590 struct hdac_stream *hstr;
591
592 stream = get_hdac_ext_stream(substream);
593 hstr = hdac_stream(stream);
594
595 dev_dbg(bus->dev, "In %s cmd=%d\n", __func__, cmd);
596
597 if (!hstr->prepared)
598 return -EPIPE;
599
600 switch (cmd) {
601 case SNDRV_PCM_TRIGGER_START:
602 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
603 case SNDRV_PCM_TRIGGER_RESUME:
604 start = true;
605 break;
606
607 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
608 case SNDRV_PCM_TRIGGER_SUSPEND:
609 case SNDRV_PCM_TRIGGER_STOP:
610 start = false;
611 break;
612
613 default:
614 return -EINVAL;
615 }
616
617 snd_pcm_group_for_each_entry(s, substream) {
618 if (s->pcm->card != substream->pcm->card)
619 continue;
620 stream = get_hdac_ext_stream(s);
621 sbits |= 1 << hdac_stream(stream)->index;
622 snd_pcm_trigger_done(s, substream);
623 }
624
625 spin_lock_irqsave(&bus->reg_lock, cookie);
626
627 /* first, set SYNC bits of corresponding streams */
628 snd_hdac_stream_sync_trigger(hstr, true, sbits, AZX_REG_SSYNC);
629
630 snd_pcm_group_for_each_entry(s, substream) {
631 if (s->pcm->card != substream->pcm->card)
632 continue;
633 stream = get_hdac_ext_stream(s);
634 if (start)
635 snd_hdac_stream_start(hdac_stream(stream), true);
636 else
637 snd_hdac_stream_stop(hdac_stream(stream));
638 }
639 spin_unlock_irqrestore(&bus->reg_lock, cookie);
640
641 snd_hdac_stream_sync(hstr, start, sbits);
642
643 spin_lock_irqsave(&bus->reg_lock, cookie);
644
645 /* reset SYNC bits */
646 snd_hdac_stream_sync_trigger(hstr, false, sbits, AZX_REG_SSYNC);
647 if (start)
648 snd_hdac_stream_timecounter_init(hstr, sbits);
649 spin_unlock_irqrestore(&bus->reg_lock, cookie);
650
651 return 0;
652}
653
654static int skl_dsp_trigger(struct snd_pcm_substream *substream,
655 int cmd)
656{
657 struct hdac_ext_bus *ebus = get_bus_ctx(substream);
658 struct hdac_bus *bus = ebus_to_hbus(ebus);
659 struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream);
660 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
661 struct hdac_ext_stream *stream;
662 int start;
663 unsigned long cookie;
664 struct hdac_stream *hstr;
665
666 dev_dbg(bus->dev, "In %s cmd=%d streamname=%s\n", __func__, cmd, cpu_dai->name);
667
668 stream = get_hdac_ext_stream(substream);
669 hstr = hdac_stream(stream);
670
671 if (!hstr->prepared)
672 return -EPIPE;
673
674 switch (cmd) {
675 case SNDRV_PCM_TRIGGER_START:
676 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
677 case SNDRV_PCM_TRIGGER_RESUME:
678 start = 1;
679 break;
680
681 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
682 case SNDRV_PCM_TRIGGER_SUSPEND:
683 case SNDRV_PCM_TRIGGER_STOP:
684 start = 0;
685 break;
686
687 default:
688 return -EINVAL;
689 }
690
691 spin_lock_irqsave(&bus->reg_lock, cookie);
692
693 if (start)
694 snd_hdac_stream_start(hdac_stream(stream), true);
695 else
696 snd_hdac_stream_stop(hdac_stream(stream));
697
698 if (start)
699 snd_hdac_stream_timecounter_init(hstr, 0);
700
701 spin_unlock_irqrestore(&bus->reg_lock, cookie);
702
703 return 0;
704}
705static int skl_platform_pcm_trigger(struct snd_pcm_substream *substream,
706 int cmd)
707{
708 struct hdac_ext_bus *ebus = get_bus_ctx(substream);
709
710 if (ebus->ppcap)
711 return skl_dsp_trigger(substream, cmd);
712 else
713 return skl_pcm_trigger(substream, cmd);
714}
715
716/* calculate runtime delay from LPIB */
717static int skl_get_delay_from_lpib(struct hdac_ext_bus *ebus,
718 struct hdac_ext_stream *sstream,
719 unsigned int pos)
720{
721 struct hdac_bus *bus = ebus_to_hbus(ebus);
722 struct hdac_stream *hstream = hdac_stream(sstream);
723 struct snd_pcm_substream *substream = hstream->substream;
724 int stream = substream->stream;
725 unsigned int lpib_pos = snd_hdac_stream_get_pos_lpib(hstream);
726 int delay;
727
728 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
729 delay = pos - lpib_pos;
730 else
731 delay = lpib_pos - pos;
732
733 if (delay < 0) {
734 if (delay >= hstream->delay_negative_threshold)
735 delay = 0;
736 else
737 delay += hstream->bufsize;
738 }
739
740 if (delay >= hstream->period_bytes) {
741 dev_info(bus->dev,
742 "Unstable LPIB (%d >= %d); disabling LPIB delay counting\n",
743 delay, hstream->period_bytes);
744 delay = 0;
745 }
746
747 return bytes_to_frames(substream->runtime, delay);
748}
749
750static unsigned int skl_get_position(struct hdac_ext_stream *hstream,
751 int codec_delay)
752{
753 struct hdac_stream *hstr = hdac_stream(hstream);
754 struct snd_pcm_substream *substream = hstr->substream;
755 struct hdac_ext_bus *ebus = get_bus_ctx(substream);
756 unsigned int pos;
757 int delay;
758
759 /* use the position buffer as default */
760 pos = snd_hdac_stream_get_pos_posbuf(hdac_stream(hstream));
761
762 if (pos >= hdac_stream(hstream)->bufsize)
763 pos = 0;
764
765 if (substream->runtime) {
766 delay = skl_get_delay_from_lpib(ebus, hstream, pos)
767 + codec_delay;
768 substream->runtime->delay += delay;
769 }
770
771 return pos;
772}
773
774static snd_pcm_uframes_t skl_platform_pcm_pointer
775 (struct snd_pcm_substream *substream)
776{
777 struct hdac_ext_stream *hstream = get_hdac_ext_stream(substream);
778
779 return bytes_to_frames(substream->runtime,
780 skl_get_position(hstream, 0));
781}
782
783static u64 skl_adjust_codec_delay(struct snd_pcm_substream *substream,
784 u64 nsec)
785{
786 struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream);
787 struct snd_soc_dai *codec_dai = rtd->codec_dai;
788 u64 codec_frames, codec_nsecs;
789
790 if (!codec_dai->driver->ops->delay)
791 return nsec;
792
793 codec_frames = codec_dai->driver->ops->delay(substream, codec_dai);
794 codec_nsecs = div_u64(codec_frames * 1000000000LL,
795 substream->runtime->rate);
796
797 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
798 return nsec + codec_nsecs;
799
800 return (nsec > codec_nsecs) ? nsec - codec_nsecs : 0;
801}
802
803static int skl_get_time_info(struct snd_pcm_substream *substream,
804 struct timespec *system_ts, struct timespec *audio_ts,
805 struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
806 struct snd_pcm_audio_tstamp_report *audio_tstamp_report)
807{
808 struct hdac_ext_stream *sstream = get_hdac_ext_stream(substream);
809 struct hdac_stream *hstr = hdac_stream(sstream);
810 u64 nsec;
811
812 if ((substream->runtime->hw.info & SNDRV_PCM_INFO_HAS_LINK_ATIME) &&
813 (audio_tstamp_config->type_requested == SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK)) {
814
815 snd_pcm_gettime(substream->runtime, system_ts);
816
817 nsec = timecounter_read(&hstr->tc);
818 nsec = div_u64(nsec, 3); /* can be optimized */
819 if (audio_tstamp_config->report_delay)
820 nsec = skl_adjust_codec_delay(substream, nsec);
821
822 *audio_ts = ns_to_timespec(nsec);
823
824 audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK;
825 audio_tstamp_report->accuracy_report = 1; /* rest of struct is valid */
826 audio_tstamp_report->accuracy = 42; /* 24MHzWallClk == 42ns resolution */
827
828 } else {
829 audio_tstamp_report->actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT;
830 }
831
832 return 0;
833}
834
835static struct snd_pcm_ops skl_platform_ops = {
836 .open = skl_platform_open,
837 .ioctl = snd_pcm_lib_ioctl,
838 .trigger = skl_platform_pcm_trigger,
839 .pointer = skl_platform_pcm_pointer,
840 .get_time_info = skl_get_time_info,
841 .mmap = snd_pcm_lib_default_mmap,
842 .page = snd_pcm_sgbuf_ops_page,
843};
844
845static void skl_pcm_free(struct snd_pcm *pcm)
846{
847 snd_pcm_lib_preallocate_free_for_all(pcm);
848}
849
850#define MAX_PREALLOC_SIZE (32 * 1024 * 1024)
851
852static int skl_pcm_new(struct snd_soc_pcm_runtime *rtd)
853{
854 struct snd_soc_dai *dai = rtd->cpu_dai;
855 struct hdac_ext_bus *ebus = dev_get_drvdata(dai->dev);
856 struct snd_pcm *pcm = rtd->pcm;
857 unsigned int size;
858 int retval = 0;
859 struct skl *skl = ebus_to_skl(ebus);
860
861 if (dai->driver->playback.channels_min ||
862 dai->driver->capture.channels_min) {
863 /* buffer pre-allocation */
864 size = CONFIG_SND_HDA_PREALLOC_SIZE * 1024;
865 if (size > MAX_PREALLOC_SIZE)
866 size = MAX_PREALLOC_SIZE;
867 retval = snd_pcm_lib_preallocate_pages_for_all(pcm,
868 SNDRV_DMA_TYPE_DEV_SG,
869 snd_dma_pci_data(skl->pci),
870 size, MAX_PREALLOC_SIZE);
871 if (retval) {
872 dev_err(dai->dev, "dma buffer allocationf fail\n");
873 return retval;
874 }
875 }
876
877 return retval;
878}
879
880static struct snd_soc_platform_driver skl_platform_drv = {
881 .ops = &skl_platform_ops,
882 .pcm_new = skl_pcm_new,
883 .pcm_free = skl_pcm_free,
884};
885
886static const struct snd_soc_component_driver skl_component = {
887 .name = "pcm",
888};
889
890int skl_platform_register(struct device *dev)
891{
892 int ret;
893
894 ret = snd_soc_register_platform(dev, &skl_platform_drv);
895 if (ret) {
896 dev_err(dev, "soc platform registration failed %d\n", ret);
897 return ret;
898 }
899 ret = snd_soc_register_component(dev, &skl_component,
900 skl_platform_dai,
901 ARRAY_SIZE(skl_platform_dai));
902 if (ret) {
903 dev_err(dev, "soc component registration failed %d\n", ret);
904 snd_soc_unregister_platform(dev);
905 }
906
907 return ret;
908
909}
910
911int skl_platform_unregister(struct device *dev)
912{
913 snd_soc_unregister_component(dev);
914 snd_soc_unregister_platform(dev);
915 return 0;
916}
diff --git a/sound/soc/intel/skylake/skl-sst-cldma.c b/sound/soc/intel/skylake/skl-sst-cldma.c
new file mode 100644
index 000000000000..44748ba98da2
--- /dev/null
+++ b/sound/soc/intel/skylake/skl-sst-cldma.c
@@ -0,0 +1,327 @@
1/*
2 * skl-sst-cldma.c - Code Loader DMA handler
3 *
4 * Copyright (C) 2015, Intel Corporation.
5 * Author: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as version 2, as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
18#include <linux/device.h>
19#include <linux/mm.h>
20#include <linux/kthread.h>
21#include "../common/sst-dsp.h"
22#include "../common/sst-dsp-priv.h"
23
24static void skl_cldma_int_enable(struct sst_dsp *ctx)
25{
26 sst_dsp_shim_update_bits_unlocked(ctx, SKL_ADSP_REG_ADSPIC,
27 SKL_ADSPIC_CL_DMA, SKL_ADSPIC_CL_DMA);
28}
29
30void skl_cldma_int_disable(struct sst_dsp *ctx)
31{
32 sst_dsp_shim_update_bits_unlocked(ctx,
33 SKL_ADSP_REG_ADSPIC, SKL_ADSPIC_CL_DMA, 0);
34}
35
36/* Code loader helper APIs */
37static void skl_cldma_setup_bdle(struct sst_dsp *ctx,
38 struct snd_dma_buffer *dmab_data,
39 u32 **bdlp, int size, int with_ioc)
40{
41 u32 *bdl = *bdlp;
42
43 ctx->cl_dev.frags = 0;
44 while (size > 0) {
45 phys_addr_t addr = virt_to_phys(dmab_data->area +
46 (ctx->cl_dev.frags * ctx->cl_dev.bufsize));
47
48 bdl[0] = cpu_to_le32(lower_32_bits(addr));
49 bdl[1] = cpu_to_le32(upper_32_bits(addr));
50
51 bdl[2] = cpu_to_le32(ctx->cl_dev.bufsize);
52
53 size -= ctx->cl_dev.bufsize;
54 bdl[3] = (size || !with_ioc) ? 0 : cpu_to_le32(0x01);
55
56 bdl += 4;
57 ctx->cl_dev.frags++;
58 }
59}
60
61/*
62 * Setup controller
63 * Configure the registers to update the dma buffer address and
64 * enable interrupts.
65 * Note: Using the channel 1 for transfer
66 */
67static void skl_cldma_setup_controller(struct sst_dsp *ctx,
68 struct snd_dma_buffer *dmab_bdl, unsigned int max_size,
69 u32 count)
70{
71 sst_dsp_shim_write(ctx, SKL_ADSP_REG_CL_SD_BDLPL,
72 CL_SD_BDLPLBA(dmab_bdl->addr));
73 sst_dsp_shim_write(ctx, SKL_ADSP_REG_CL_SD_BDLPU,
74 CL_SD_BDLPUBA(dmab_bdl->addr));
75
76 sst_dsp_shim_write(ctx, SKL_ADSP_REG_CL_SD_CBL, max_size);
77 sst_dsp_shim_write(ctx, SKL_ADSP_REG_CL_SD_LVI, count - 1);
78 sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_CL_SD_CTL,
79 CL_SD_CTL_IOCE_MASK, CL_SD_CTL_IOCE(1));
80 sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_CL_SD_CTL,
81 CL_SD_CTL_FEIE_MASK, CL_SD_CTL_FEIE(1));
82 sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_CL_SD_CTL,
83 CL_SD_CTL_DEIE_MASK, CL_SD_CTL_DEIE(1));
84 sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_CL_SD_CTL,
85 CL_SD_CTL_STRM_MASK, CL_SD_CTL_STRM(FW_CL_STREAM_NUMBER));
86}
87
88static void skl_cldma_setup_spb(struct sst_dsp *ctx,
89 unsigned int size, bool enable)
90{
91 if (enable)
92 sst_dsp_shim_update_bits_unlocked(ctx,
93 SKL_ADSP_REG_CL_SPBFIFO_SPBFCCTL,
94 CL_SPBFIFO_SPBFCCTL_SPIBE_MASK,
95 CL_SPBFIFO_SPBFCCTL_SPIBE(1));
96
97 sst_dsp_shim_write_unlocked(ctx, SKL_ADSP_REG_CL_SPBFIFO_SPIB, size);
98}
99
100static void skl_cldma_cleanup_spb(struct sst_dsp *ctx)
101{
102 sst_dsp_shim_update_bits_unlocked(ctx,
103 SKL_ADSP_REG_CL_SPBFIFO_SPBFCCTL,
104 CL_SPBFIFO_SPBFCCTL_SPIBE_MASK,
105 CL_SPBFIFO_SPBFCCTL_SPIBE(0));
106
107 sst_dsp_shim_write_unlocked(ctx, SKL_ADSP_REG_CL_SPBFIFO_SPIB, 0);
108}
109
110static void skl_cldma_trigger(struct sst_dsp *ctx, bool enable)
111{
112 if (enable)
113 sst_dsp_shim_update_bits_unlocked(ctx,
114 SKL_ADSP_REG_CL_SD_CTL,
115 CL_SD_CTL_RUN_MASK, CL_SD_CTL_RUN(1));
116 else
117 sst_dsp_shim_update_bits_unlocked(ctx,
118 SKL_ADSP_REG_CL_SD_CTL,
119 CL_SD_CTL_RUN_MASK, CL_SD_CTL_RUN(0));
120}
121
122static void skl_cldma_cleanup(struct sst_dsp *ctx)
123{
124 skl_cldma_cleanup_spb(ctx);
125
126 sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_CL_SD_CTL,
127 CL_SD_CTL_IOCE_MASK, CL_SD_CTL_IOCE(0));
128 sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_CL_SD_CTL,
129 CL_SD_CTL_FEIE_MASK, CL_SD_CTL_FEIE(0));
130 sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_CL_SD_CTL,
131 CL_SD_CTL_DEIE_MASK, CL_SD_CTL_DEIE(0));
132 sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_CL_SD_CTL,
133 CL_SD_CTL_STRM_MASK, CL_SD_CTL_STRM(0));
134
135 sst_dsp_shim_write(ctx, SKL_ADSP_REG_CL_SD_BDLPL, CL_SD_BDLPLBA(0));
136 sst_dsp_shim_write(ctx, SKL_ADSP_REG_CL_SD_BDLPU, 0);
137
138 sst_dsp_shim_write(ctx, SKL_ADSP_REG_CL_SD_CBL, 0);
139 sst_dsp_shim_write(ctx, SKL_ADSP_REG_CL_SD_LVI, 0);
140}
141
142static int skl_cldma_wait_interruptible(struct sst_dsp *ctx)
143{
144 int ret = 0;
145
146 if (!wait_event_timeout(ctx->cl_dev.wait_queue,
147 ctx->cl_dev.wait_condition,
148 msecs_to_jiffies(SKL_WAIT_TIMEOUT))) {
149 dev_err(ctx->dev, "%s: Wait timeout\n", __func__);
150 ret = -EIO;
151 goto cleanup;
152 }
153
154 dev_dbg(ctx->dev, "%s: Event wake\n", __func__);
155 if (ctx->cl_dev.wake_status != SKL_CL_DMA_BUF_COMPLETE) {
156 dev_err(ctx->dev, "%s: DMA Error\n", __func__);
157 ret = -EIO;
158 }
159
160cleanup:
161 ctx->cl_dev.wake_status = SKL_CL_DMA_STATUS_NONE;
162 return ret;
163}
164
165static void skl_cldma_stop(struct sst_dsp *ctx)
166{
167 ctx->cl_dev.ops.cl_trigger(ctx, false);
168}
169
170static void skl_cldma_fill_buffer(struct sst_dsp *ctx, unsigned int size,
171 const void *curr_pos, bool intr_enable, bool trigger)
172{
173 dev_dbg(ctx->dev, "Size: %x, intr_enable: %d\n", size, intr_enable);
174 dev_dbg(ctx->dev, "buf_pos_index:%d, trigger:%d\n",
175 ctx->cl_dev.dma_buffer_offset, trigger);
176 dev_dbg(ctx->dev, "spib position: %d\n", ctx->cl_dev.curr_spib_pos);
177
178 memcpy(ctx->cl_dev.dmab_data.area + ctx->cl_dev.dma_buffer_offset,
179 curr_pos, size);
180
181 if (ctx->cl_dev.curr_spib_pos == ctx->cl_dev.bufsize)
182 ctx->cl_dev.dma_buffer_offset = 0;
183 else
184 ctx->cl_dev.dma_buffer_offset = ctx->cl_dev.curr_spib_pos;
185
186 ctx->cl_dev.wait_condition = false;
187
188 if (intr_enable)
189 skl_cldma_int_enable(ctx);
190
191 ctx->cl_dev.ops.cl_setup_spb(ctx, ctx->cl_dev.curr_spib_pos, trigger);
192 if (trigger)
193 ctx->cl_dev.ops.cl_trigger(ctx, true);
194}
195
196/*
197 * The CL dma doesn't have any way to update the transfer status until a BDL
198 * buffer is fully transferred
199 *
200 * So Copying is divided in two parts.
201 * 1. Interrupt on buffer done where the size to be transferred is more than
202 * ring buffer size.
203 * 2. Polling on fw register to identify if data left to transferred doesn't
204 * fill the ring buffer. Caller takes care of polling the required status
205 * register to identify the transfer status.
206 */
207static int
208skl_cldma_copy_to_buf(struct sst_dsp *ctx, const void *bin, u32 total_size)
209{
210 int ret = 0;
211 bool start = true;
212 unsigned int excess_bytes;
213 u32 size;
214 unsigned int bytes_left = total_size;
215 const void *curr_pos = bin;
216
217 if (total_size <= 0)
218 return -EINVAL;
219
220 dev_dbg(ctx->dev, "%s: Total binary size: %u\n", __func__, bytes_left);
221
222 while (bytes_left) {
223 if (bytes_left > ctx->cl_dev.bufsize) {
224
225 /*
226 * dma transfers only till the write pointer as
227 * updated in spib
228 */
229 if (ctx->cl_dev.curr_spib_pos == 0)
230 ctx->cl_dev.curr_spib_pos = ctx->cl_dev.bufsize;
231
232 size = ctx->cl_dev.bufsize;
233 skl_cldma_fill_buffer(ctx, size, curr_pos, true, start);
234
235 start = false;
236 ret = skl_cldma_wait_interruptible(ctx);
237 if (ret < 0) {
238 skl_cldma_stop(ctx);
239 return ret;
240 }
241
242 } else {
243 skl_cldma_int_disable(ctx);
244
245 if ((ctx->cl_dev.curr_spib_pos + bytes_left)
246 <= ctx->cl_dev.bufsize) {
247 ctx->cl_dev.curr_spib_pos += bytes_left;
248 } else {
249 excess_bytes = bytes_left -
250 (ctx->cl_dev.bufsize -
251 ctx->cl_dev.curr_spib_pos);
252 ctx->cl_dev.curr_spib_pos = excess_bytes;
253 }
254
255 size = bytes_left;
256 skl_cldma_fill_buffer(ctx, size,
257 curr_pos, false, start);
258 }
259 bytes_left -= size;
260 curr_pos = curr_pos + size;
261 }
262
263 return ret;
264}
265
266void skl_cldma_process_intr(struct sst_dsp *ctx)
267{
268 u8 cl_dma_intr_status;
269
270 cl_dma_intr_status =
271 sst_dsp_shim_read_unlocked(ctx, SKL_ADSP_REG_CL_SD_STS);
272
273 if (!(cl_dma_intr_status & SKL_CL_DMA_SD_INT_COMPLETE))
274 ctx->cl_dev.wake_status = SKL_CL_DMA_ERR;
275 else
276 ctx->cl_dev.wake_status = SKL_CL_DMA_BUF_COMPLETE;
277
278 ctx->cl_dev.wait_condition = true;
279 wake_up(&ctx->cl_dev.wait_queue);
280}
281
282int skl_cldma_prepare(struct sst_dsp *ctx)
283{
284 int ret;
285 u32 *bdl;
286
287 ctx->cl_dev.bufsize = SKL_MAX_BUFFER_SIZE;
288
289 /* Allocate cl ops */
290 ctx->cl_dev.ops.cl_setup_bdle = skl_cldma_setup_bdle;
291 ctx->cl_dev.ops.cl_setup_controller = skl_cldma_setup_controller;
292 ctx->cl_dev.ops.cl_setup_spb = skl_cldma_setup_spb;
293 ctx->cl_dev.ops.cl_cleanup_spb = skl_cldma_cleanup_spb;
294 ctx->cl_dev.ops.cl_trigger = skl_cldma_trigger;
295 ctx->cl_dev.ops.cl_cleanup_controller = skl_cldma_cleanup;
296 ctx->cl_dev.ops.cl_copy_to_dmabuf = skl_cldma_copy_to_buf;
297 ctx->cl_dev.ops.cl_stop_dma = skl_cldma_stop;
298
299 /* Allocate buffer*/
300 ret = ctx->dsp_ops.alloc_dma_buf(ctx->dev,
301 &ctx->cl_dev.dmab_data, ctx->cl_dev.bufsize);
302 if (ret < 0) {
303 dev_err(ctx->dev, "Alloc buffer for base fw failed: %x", ret);
304 return ret;
305 }
306 /* Setup Code loader BDL */
307 ret = ctx->dsp_ops.alloc_dma_buf(ctx->dev,
308 &ctx->cl_dev.dmab_bdl, PAGE_SIZE);
309 if (ret < 0) {
310 dev_err(ctx->dev, "Alloc buffer for blde failed: %x", ret);
311 ctx->dsp_ops.free_dma_buf(ctx->dev, &ctx->cl_dev.dmab_data);
312 return ret;
313 }
314 bdl = (u32 *)ctx->cl_dev.dmab_bdl.area;
315
316 /* Allocate BDLs */
317 ctx->cl_dev.ops.cl_setup_bdle(ctx, &ctx->cl_dev.dmab_data,
318 &bdl, ctx->cl_dev.bufsize, 1);
319 ctx->cl_dev.ops.cl_setup_controller(ctx, &ctx->cl_dev.dmab_bdl,
320 ctx->cl_dev.bufsize, ctx->cl_dev.frags);
321
322 ctx->cl_dev.curr_spib_pos = 0;
323 ctx->cl_dev.dma_buffer_offset = 0;
324 init_waitqueue_head(&ctx->cl_dev.wait_queue);
325
326 return ret;
327}
diff --git a/sound/soc/intel/skylake/skl-sst-cldma.h b/sound/soc/intel/skylake/skl-sst-cldma.h
new file mode 100644
index 000000000000..99e4c86b6358
--- /dev/null
+++ b/sound/soc/intel/skylake/skl-sst-cldma.h
@@ -0,0 +1,251 @@
1/*
2 * Intel Code Loader DMA support
3 *
4 * Copyright (C) 2015, Intel Corporation.
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 version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#ifndef SKL_SST_CLDMA_H_
17#define SKL_SST_CLDMA_H_
18
19#define FW_CL_STREAM_NUMBER 0x1
20
21#define DMA_ADDRESS_128_BITS_ALIGNMENT 7
22#define BDL_ALIGN(x) (x >> DMA_ADDRESS_128_BITS_ALIGNMENT)
23
24#define SKL_ADSPIC_CL_DMA 0x2
25#define SKL_ADSPIS_CL_DMA 0x2
26#define SKL_CL_DMA_SD_INT_DESC_ERR 0x10 /* Descriptor error interrupt */
27#define SKL_CL_DMA_SD_INT_FIFO_ERR 0x08 /* FIFO error interrupt */
28#define SKL_CL_DMA_SD_INT_COMPLETE 0x04 /* Buffer completion interrupt */
29
30/* Intel HD Audio Code Loader DMA Registers */
31
32#define HDA_ADSP_LOADER_BASE 0x80
33
34/* Stream Registers */
35#define SKL_ADSP_REG_CL_SD_CTL (HDA_ADSP_LOADER_BASE + 0x00)
36#define SKL_ADSP_REG_CL_SD_STS (HDA_ADSP_LOADER_BASE + 0x03)
37#define SKL_ADSP_REG_CL_SD_LPIB (HDA_ADSP_LOADER_BASE + 0x04)
38#define SKL_ADSP_REG_CL_SD_CBL (HDA_ADSP_LOADER_BASE + 0x08)
39#define SKL_ADSP_REG_CL_SD_LVI (HDA_ADSP_LOADER_BASE + 0x0c)
40#define SKL_ADSP_REG_CL_SD_FIFOW (HDA_ADSP_LOADER_BASE + 0x0e)
41#define SKL_ADSP_REG_CL_SD_FIFOSIZE (HDA_ADSP_LOADER_BASE + 0x10)
42#define SKL_ADSP_REG_CL_SD_FORMAT (HDA_ADSP_LOADER_BASE + 0x12)
43#define SKL_ADSP_REG_CL_SD_FIFOL (HDA_ADSP_LOADER_BASE + 0x14)
44#define SKL_ADSP_REG_CL_SD_BDLPL (HDA_ADSP_LOADER_BASE + 0x18)
45#define SKL_ADSP_REG_CL_SD_BDLPU (HDA_ADSP_LOADER_BASE + 0x1c)
46
47/* CL: Software Position Based FIFO Capability Registers */
48#define SKL_ADSP_REG_CL_SPBFIFO (HDA_ADSP_LOADER_BASE + 0x20)
49#define SKL_ADSP_REG_CL_SPBFIFO_SPBFCH (SKL_ADSP_REG_CL_SPBFIFO + 0x0)
50#define SKL_ADSP_REG_CL_SPBFIFO_SPBFCCTL (SKL_ADSP_REG_CL_SPBFIFO + 0x4)
51#define SKL_ADSP_REG_CL_SPBFIFO_SPIB (SKL_ADSP_REG_CL_SPBFIFO + 0x8)
52#define SKL_ADSP_REG_CL_SPBFIFO_MAXFIFOS (SKL_ADSP_REG_CL_SPBFIFO + 0xc)
53
54/* CL: Stream Descriptor x Control */
55
56/* Stream Reset */
57#define CL_SD_CTL_SRST_SHIFT 0
58#define CL_SD_CTL_SRST_MASK (1 << CL_SD_CTL_SRST_SHIFT)
59#define CL_SD_CTL_SRST(x) \
60 ((x << CL_SD_CTL_SRST_SHIFT) & CL_SD_CTL_SRST_MASK)
61
62/* Stream Run */
63#define CL_SD_CTL_RUN_SHIFT 1
64#define CL_SD_CTL_RUN_MASK (1 << CL_SD_CTL_RUN_SHIFT)
65#define CL_SD_CTL_RUN(x) \
66 ((x << CL_SD_CTL_RUN_SHIFT) & CL_SD_CTL_RUN_MASK)
67
68/* Interrupt On Completion Enable */
69#define CL_SD_CTL_IOCE_SHIFT 2
70#define CL_SD_CTL_IOCE_MASK (1 << CL_SD_CTL_IOCE_SHIFT)
71#define CL_SD_CTL_IOCE(x) \
72 ((x << CL_SD_CTL_IOCE_SHIFT) & CL_SD_CTL_IOCE_MASK)
73
74/* FIFO Error Interrupt Enable */
75#define CL_SD_CTL_FEIE_SHIFT 3
76#define CL_SD_CTL_FEIE_MASK (1 << CL_SD_CTL_FEIE_SHIFT)
77#define CL_SD_CTL_FEIE(x) \
78 ((x << CL_SD_CTL_FEIE_SHIFT) & CL_SD_CTL_FEIE_MASK)
79
80/* Descriptor Error Interrupt Enable */
81#define CL_SD_CTL_DEIE_SHIFT 4
82#define CL_SD_CTL_DEIE_MASK (1 << CL_SD_CTL_DEIE_SHIFT)
83#define CL_SD_CTL_DEIE(x) \
84 ((x << CL_SD_CTL_DEIE_SHIFT) & CL_SD_CTL_DEIE_MASK)
85
86/* FIFO Limit Change */
87#define CL_SD_CTL_FIFOLC_SHIFT 5
88#define CL_SD_CTL_FIFOLC_MASK (1 << CL_SD_CTL_FIFOLC_SHIFT)
89#define CL_SD_CTL_FIFOLC(x) \
90 ((x << CL_SD_CTL_FIFOLC_SHIFT) & CL_SD_CTL_FIFOLC_MASK)
91
92/* Stripe Control */
93#define CL_SD_CTL_STRIPE_SHIFT 16
94#define CL_SD_CTL_STRIPE_MASK (0x3 << CL_SD_CTL_STRIPE_SHIFT)
95#define CL_SD_CTL_STRIPE(x) \
96 ((x << CL_SD_CTL_STRIPE_SHIFT) & CL_SD_CTL_STRIPE_MASK)
97
98/* Traffic Priority */
99#define CL_SD_CTL_TP_SHIFT 18
100#define CL_SD_CTL_TP_MASK (1 << CL_SD_CTL_TP_SHIFT)
101#define CL_SD_CTL_TP(x) \
102 ((x << CL_SD_CTL_TP_SHIFT) & CL_SD_CTL_TP_MASK)
103
104/* Bidirectional Direction Control */
105#define CL_SD_CTL_DIR_SHIFT 19
106#define CL_SD_CTL_DIR_MASK (1 << CL_SD_CTL_DIR_SHIFT)
107#define CL_SD_CTL_DIR(x) \
108 ((x << CL_SD_CTL_DIR_SHIFT) & CL_SD_CTL_DIR_MASK)
109
110/* Stream Number */
111#define CL_SD_CTL_STRM_SHIFT 20
112#define CL_SD_CTL_STRM_MASK (0xf << CL_SD_CTL_STRM_SHIFT)
113#define CL_SD_CTL_STRM(x) \
114 ((x << CL_SD_CTL_STRM_SHIFT) & CL_SD_CTL_STRM_MASK)
115
116/* CL: Stream Descriptor x Status */
117
118/* Buffer Completion Interrupt Status */
119#define CL_SD_STS_BCIS(x) CL_SD_CTL_IOCE(x)
120
121/* FIFO Error */
122#define CL_SD_STS_FIFOE(x) CL_SD_CTL_FEIE(x)
123
124/* Descriptor Error */
125#define CL_SD_STS_DESE(x) CL_SD_CTL_DEIE(x)
126
127/* FIFO Ready */
128#define CL_SD_STS_FIFORDY(x) CL_SD_CTL_FIFOLC(x)
129
130
131/* CL: Stream Descriptor x Last Valid Index */
132#define CL_SD_LVI_SHIFT 0
133#define CL_SD_LVI_MASK (0xff << CL_SD_LVI_SHIFT)
134#define CL_SD_LVI(x) ((x << CL_SD_LVI_SHIFT) & CL_SD_LVI_MASK)
135
136/* CL: Stream Descriptor x FIFO Eviction Watermark */
137#define CL_SD_FIFOW_SHIFT 0
138#define CL_SD_FIFOW_MASK (0x7 << CL_SD_FIFOW_SHIFT)
139#define CL_SD_FIFOW(x) \
140 ((x << CL_SD_FIFOW_SHIFT) & CL_SD_FIFOW_MASK)
141
142/* CL: Stream Descriptor x Buffer Descriptor List Pointer Lower Base Address */
143
144/* Protect Bits */
145#define CL_SD_BDLPLBA_PROT_SHIFT 0
146#define CL_SD_BDLPLBA_PROT_MASK (1 << CL_SD_BDLPLBA_PROT_SHIFT)
147#define CL_SD_BDLPLBA_PROT(x) \
148 ((x << CL_SD_BDLPLBA_PROT_SHIFT) & CL_SD_BDLPLBA_PROT_MASK)
149
150/* Buffer Descriptor List Lower Base Address */
151#define CL_SD_BDLPLBA_SHIFT 7
152#define CL_SD_BDLPLBA_MASK (0x1ffffff << CL_SD_BDLPLBA_SHIFT)
153#define CL_SD_BDLPLBA(x) \
154 ((BDL_ALIGN(lower_32_bits(x)) << CL_SD_BDLPLBA_SHIFT) & CL_SD_BDLPLBA_MASK)
155
156/* Buffer Descriptor List Upper Base Address */
157#define CL_SD_BDLPUBA_SHIFT 0
158#define CL_SD_BDLPUBA_MASK (0xffffffff << CL_SD_BDLPUBA_SHIFT)
159#define CL_SD_BDLPUBA(x) \
160 ((upper_32_bits(x) << CL_SD_BDLPUBA_SHIFT) & CL_SD_BDLPUBA_MASK)
161
162/*
163 * Code Loader - Software Position Based FIFO
164 * Capability Registers x Software Position Based FIFO Header
165 */
166
167/* Next Capability Pointer */
168#define CL_SPBFIFO_SPBFCH_PTR_SHIFT 0
169#define CL_SPBFIFO_SPBFCH_PTR_MASK (0xff << CL_SPBFIFO_SPBFCH_PTR_SHIFT)
170#define CL_SPBFIFO_SPBFCH_PTR(x) \
171 ((x << CL_SPBFIFO_SPBFCH_PTR_SHIFT) & CL_SPBFIFO_SPBFCH_PTR_MASK)
172
173/* Capability Identifier */
174#define CL_SPBFIFO_SPBFCH_ID_SHIFT 16
175#define CL_SPBFIFO_SPBFCH_ID_MASK (0xfff << CL_SPBFIFO_SPBFCH_ID_SHIFT)
176#define CL_SPBFIFO_SPBFCH_ID(x) \
177 ((x << CL_SPBFIFO_SPBFCH_ID_SHIFT) & CL_SPBFIFO_SPBFCH_ID_MASK)
178
179/* Capability Version */
180#define CL_SPBFIFO_SPBFCH_VER_SHIFT 28
181#define CL_SPBFIFO_SPBFCH_VER_MASK (0xf << CL_SPBFIFO_SPBFCH_VER_SHIFT)
182#define CL_SPBFIFO_SPBFCH_VER(x) \
183 ((x << CL_SPBFIFO_SPBFCH_VER_SHIFT) & CL_SPBFIFO_SPBFCH_VER_MASK)
184
185/* Software Position in Buffer Enable */
186#define CL_SPBFIFO_SPBFCCTL_SPIBE_SHIFT 0
187#define CL_SPBFIFO_SPBFCCTL_SPIBE_MASK (1 << CL_SPBFIFO_SPBFCCTL_SPIBE_SHIFT)
188#define CL_SPBFIFO_SPBFCCTL_SPIBE(x) \
189 ((x << CL_SPBFIFO_SPBFCCTL_SPIBE_SHIFT) & CL_SPBFIFO_SPBFCCTL_SPIBE_MASK)
190
191/* SST IPC SKL defines */
192#define SKL_WAIT_TIMEOUT 500 /* 500 msec */
193#define SKL_MAX_BUFFER_SIZE (32 * PAGE_SIZE)
194
195enum skl_cl_dma_wake_states {
196 SKL_CL_DMA_STATUS_NONE = 0,
197 SKL_CL_DMA_BUF_COMPLETE,
198 SKL_CL_DMA_ERR, /* TODO: Expand the error states */
199};
200
201struct sst_dsp;
202
203struct skl_cl_dev_ops {
204 void (*cl_setup_bdle)(struct sst_dsp *ctx,
205 struct snd_dma_buffer *dmab_data,
206 u32 **bdlp, int size, int with_ioc);
207 void (*cl_setup_controller)(struct sst_dsp *ctx,
208 struct snd_dma_buffer *dmab_bdl,
209 unsigned int max_size, u32 page_count);
210 void (*cl_setup_spb)(struct sst_dsp *ctx,
211 unsigned int size, bool enable);
212 void (*cl_cleanup_spb)(struct sst_dsp *ctx);
213 void (*cl_trigger)(struct sst_dsp *ctx, bool enable);
214 void (*cl_cleanup_controller)(struct sst_dsp *ctx);
215 int (*cl_copy_to_dmabuf)(struct sst_dsp *ctx,
216 const void *bin, u32 size);
217 void (*cl_stop_dma)(struct sst_dsp *ctx);
218};
219
220/**
221 * skl_cl_dev - holds information for code loader dma transfer
222 *
223 * @dmab_data: buffer pointer
224 * @dmab_bdl: buffer descriptor list
225 * @bufsize: ring buffer size
226 * @frags: Last valid buffer descriptor index in the BDL
227 * @curr_spib_pos: Current position in ring buffer
228 * @dma_buffer_offset: dma buffer offset
229 * @ops: operations supported on CL dma
230 * @wait_queue: wait queue to wake for wake event
231 * @wake_status: DMA wake status
232 * @wait_condition: condition to wait on wait queue
233 * @cl_dma_lock: for synchronized access to cldma
234 */
235struct skl_cl_dev {
236 struct snd_dma_buffer dmab_data;
237 struct snd_dma_buffer dmab_bdl;
238
239 unsigned int bufsize;
240 unsigned int frags;
241
242 unsigned int curr_spib_pos;
243 unsigned int dma_buffer_offset;
244 struct skl_cl_dev_ops ops;
245
246 wait_queue_head_t wait_queue;
247 int wake_status;
248 bool wait_condition;
249};
250
251#endif /* SKL_SST_CLDMA_H_ */
diff --git a/sound/soc/intel/skylake/skl-sst-dsp.c b/sound/soc/intel/skylake/skl-sst-dsp.c
new file mode 100644
index 000000000000..94875b008b0b
--- /dev/null
+++ b/sound/soc/intel/skylake/skl-sst-dsp.c
@@ -0,0 +1,342 @@
1/*
2 * skl-sst-dsp.c - SKL SST library generic function
3 *
4 * Copyright (C) 2014-15, Intel Corporation.
5 * Author:Rafal Redzimski <rafal.f.redzimski@intel.com>
6 * Jeeja KP <jeeja.kp@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 version 2, as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 */
18#include <sound/pcm.h>
19
20#include "../common/sst-dsp.h"
21#include "../common/sst-ipc.h"
22#include "../common/sst-dsp-priv.h"
23#include "skl-sst-ipc.h"
24
25/* various timeout values */
26#define SKL_DSP_PU_TO 50
27#define SKL_DSP_PD_TO 50
28#define SKL_DSP_RESET_TO 50
29
30void skl_dsp_set_state_locked(struct sst_dsp *ctx, int state)
31{
32 mutex_lock(&ctx->mutex);
33 ctx->sst_state = state;
34 mutex_unlock(&ctx->mutex);
35}
36
37static int skl_dsp_core_set_reset_state(struct sst_dsp *ctx)
38{
39 int ret;
40
41 /* update bits */
42 sst_dsp_shim_update_bits_unlocked(ctx,
43 SKL_ADSP_REG_ADSPCS, SKL_ADSPCS_CRST_MASK,
44 SKL_ADSPCS_CRST(SKL_DSP_CORES_MASK));
45
46 /* poll with timeout to check if operation successful */
47 ret = sst_dsp_register_poll(ctx,
48 SKL_ADSP_REG_ADSPCS,
49 SKL_ADSPCS_CRST_MASK,
50 SKL_ADSPCS_CRST(SKL_DSP_CORES_MASK),
51 SKL_DSP_RESET_TO,
52 "Set reset");
53 if ((sst_dsp_shim_read_unlocked(ctx, SKL_ADSP_REG_ADSPCS) &
54 SKL_ADSPCS_CRST(SKL_DSP_CORES_MASK)) !=
55 SKL_ADSPCS_CRST(SKL_DSP_CORES_MASK)) {
56 dev_err(ctx->dev, "Set reset state failed\n");
57 ret = -EIO;
58 }
59
60 return ret;
61}
62
63static int skl_dsp_core_unset_reset_state(struct sst_dsp *ctx)
64{
65 int ret;
66
67 dev_dbg(ctx->dev, "In %s\n", __func__);
68
69 /* update bits */
70 sst_dsp_shim_update_bits_unlocked(ctx, SKL_ADSP_REG_ADSPCS,
71 SKL_ADSPCS_CRST_MASK, 0);
72
73 /* poll with timeout to check if operation successful */
74 ret = sst_dsp_register_poll(ctx,
75 SKL_ADSP_REG_ADSPCS,
76 SKL_ADSPCS_CRST_MASK,
77 0,
78 SKL_DSP_RESET_TO,
79 "Unset reset");
80
81 if ((sst_dsp_shim_read_unlocked(ctx, SKL_ADSP_REG_ADSPCS) &
82 SKL_ADSPCS_CRST(SKL_DSP_CORES_MASK)) != 0) {
83 dev_err(ctx->dev, "Unset reset state failed\n");
84 ret = -EIO;
85 }
86
87 return ret;
88}
89
90static bool is_skl_dsp_core_enable(struct sst_dsp *ctx)
91{
92 int val;
93 bool is_enable;
94
95 val = sst_dsp_shim_read_unlocked(ctx, SKL_ADSP_REG_ADSPCS);
96
97 is_enable = ((val & SKL_ADSPCS_CPA(SKL_DSP_CORES_MASK)) &&
98 (val & SKL_ADSPCS_SPA(SKL_DSP_CORES_MASK)) &&
99 !(val & SKL_ADSPCS_CRST(SKL_DSP_CORES_MASK)) &&
100 !(val & SKL_ADSPCS_CSTALL(SKL_DSP_CORES_MASK)));
101
102 dev_dbg(ctx->dev, "DSP core is enabled=%d\n", is_enable);
103 return is_enable;
104}
105
106static int skl_dsp_reset_core(struct sst_dsp *ctx)
107{
108 /* stall core */
109 sst_dsp_shim_write_unlocked(ctx, SKL_ADSP_REG_ADSPCS,
110 sst_dsp_shim_read_unlocked(ctx, SKL_ADSP_REG_ADSPCS) &
111 SKL_ADSPCS_CSTALL(SKL_DSP_CORES_MASK));
112
113 /* set reset state */
114 return skl_dsp_core_set_reset_state(ctx);
115}
116
117static int skl_dsp_start_core(struct sst_dsp *ctx)
118{
119 int ret;
120
121 /* unset reset state */
122 ret = skl_dsp_core_unset_reset_state(ctx);
123 if (ret < 0) {
124 dev_dbg(ctx->dev, "dsp unset reset fails\n");
125 return ret;
126 }
127
128 /* run core */
129 dev_dbg(ctx->dev, "run core...\n");
130 sst_dsp_shim_write_unlocked(ctx, SKL_ADSP_REG_ADSPCS,
131 sst_dsp_shim_read_unlocked(ctx, SKL_ADSP_REG_ADSPCS) &
132 ~SKL_ADSPCS_CSTALL(SKL_DSP_CORES_MASK));
133
134 if (!is_skl_dsp_core_enable(ctx)) {
135 skl_dsp_reset_core(ctx);
136 dev_err(ctx->dev, "DSP core enable failed\n");
137 ret = -EIO;
138 }
139
140 return ret;
141}
142
143static int skl_dsp_core_power_up(struct sst_dsp *ctx)
144{
145 int ret;
146
147 /* update bits */
148 sst_dsp_shim_update_bits_unlocked(ctx, SKL_ADSP_REG_ADSPCS,
149 SKL_ADSPCS_SPA_MASK, SKL_ADSPCS_SPA(SKL_DSP_CORES_MASK));
150
151 /* poll with timeout to check if operation successful */
152 ret = sst_dsp_register_poll(ctx,
153 SKL_ADSP_REG_ADSPCS,
154 SKL_ADSPCS_CPA_MASK,
155 SKL_ADSPCS_CPA(SKL_DSP_CORES_MASK),
156 SKL_DSP_PU_TO,
157 "Power up");
158
159 if ((sst_dsp_shim_read_unlocked(ctx, SKL_ADSP_REG_ADSPCS) &
160 SKL_ADSPCS_CPA(SKL_DSP_CORES_MASK)) !=
161 SKL_ADSPCS_CPA(SKL_DSP_CORES_MASK)) {
162 dev_err(ctx->dev, "DSP core power up failed\n");
163 ret = -EIO;
164 }
165
166 return ret;
167}
168
169static int skl_dsp_core_power_down(struct sst_dsp *ctx)
170{
171 /* update bits */
172 sst_dsp_shim_update_bits_unlocked(ctx, SKL_ADSP_REG_ADSPCS,
173 SKL_ADSPCS_SPA_MASK, 0);
174
175 /* poll with timeout to check if operation successful */
176 return sst_dsp_register_poll(ctx,
177 SKL_ADSP_REG_ADSPCS,
178 SKL_ADSPCS_SPA_MASK,
179 0,
180 SKL_DSP_PD_TO,
181 "Power down");
182}
183
184static int skl_dsp_enable_core(struct sst_dsp *ctx)
185{
186 int ret;
187
188 /* power up */
189 ret = skl_dsp_core_power_up(ctx);
190 if (ret < 0) {
191 dev_dbg(ctx->dev, "dsp core power up failed\n");
192 return ret;
193 }
194
195 return skl_dsp_start_core(ctx);
196}
197
198int skl_dsp_disable_core(struct sst_dsp *ctx)
199{
200 int ret;
201
202 ret = skl_dsp_reset_core(ctx);
203 if (ret < 0) {
204 dev_err(ctx->dev, "dsp core reset failed\n");
205 return ret;
206 }
207
208 /* power down core*/
209 ret = skl_dsp_core_power_down(ctx);
210 if (ret < 0) {
211 dev_err(ctx->dev, "dsp core power down failed\n");
212 return ret;
213 }
214
215 if (is_skl_dsp_core_enable(ctx)) {
216 dev_err(ctx->dev, "DSP core disable failed\n");
217 ret = -EIO;
218 }
219
220 return ret;
221}
222
223int skl_dsp_boot(struct sst_dsp *ctx)
224{
225 int ret;
226
227 if (is_skl_dsp_core_enable(ctx)) {
228 dev_dbg(ctx->dev, "dsp core is already enabled, so reset the dap core\n");
229 ret = skl_dsp_reset_core(ctx);
230 if (ret < 0) {
231 dev_err(ctx->dev, "dsp reset failed\n");
232 return ret;
233 }
234
235 ret = skl_dsp_start_core(ctx);
236 if (ret < 0) {
237 dev_err(ctx->dev, "dsp start failed\n");
238 return ret;
239 }
240 } else {
241 dev_dbg(ctx->dev, "disable and enable to make sure DSP is invalid state\n");
242 ret = skl_dsp_disable_core(ctx);
243
244 if (ret < 0) {
245 dev_err(ctx->dev, "dsp disable core failes\n");
246 return ret;
247 }
248 ret = skl_dsp_enable_core(ctx);
249 }
250
251 return ret;
252}
253
254irqreturn_t skl_dsp_sst_interrupt(int irq, void *dev_id)
255{
256 struct sst_dsp *ctx = dev_id;
257 u32 val;
258 irqreturn_t result = IRQ_NONE;
259
260 spin_lock(&ctx->spinlock);
261
262 val = sst_dsp_shim_read_unlocked(ctx, SKL_ADSP_REG_ADSPIS);
263 ctx->intr_status = val;
264
265 if (val & SKL_ADSPIS_IPC) {
266 skl_ipc_int_disable(ctx);
267 result = IRQ_WAKE_THREAD;
268 }
269
270 if (val & SKL_ADSPIS_CL_DMA) {
271 skl_cldma_int_disable(ctx);
272 result = IRQ_WAKE_THREAD;
273 }
274
275 spin_unlock(&ctx->spinlock);
276
277 return result;
278}
279
280int skl_dsp_wake(struct sst_dsp *ctx)
281{
282 return ctx->fw_ops.set_state_D0(ctx);
283}
284EXPORT_SYMBOL_GPL(skl_dsp_wake);
285
286int skl_dsp_sleep(struct sst_dsp *ctx)
287{
288 return ctx->fw_ops.set_state_D3(ctx);
289}
290EXPORT_SYMBOL_GPL(skl_dsp_sleep);
291
292struct sst_dsp *skl_dsp_ctx_init(struct device *dev,
293 struct sst_dsp_device *sst_dev, int irq)
294{
295 int ret;
296 struct sst_dsp *sst;
297
298 sst = devm_kzalloc(dev, sizeof(*sst), GFP_KERNEL);
299 if (sst == NULL)
300 return NULL;
301
302 spin_lock_init(&sst->spinlock);
303 mutex_init(&sst->mutex);
304 sst->dev = dev;
305 sst->sst_dev = sst_dev;
306 sst->irq = irq;
307 sst->ops = sst_dev->ops;
308 sst->thread_context = sst_dev->thread_context;
309
310 /* Initialise SST Audio DSP */
311 if (sst->ops->init) {
312 ret = sst->ops->init(sst, NULL);
313 if (ret < 0)
314 return NULL;
315 }
316
317 /* Register the ISR */
318 ret = request_threaded_irq(sst->irq, sst->ops->irq_handler,
319 sst_dev->thread, IRQF_SHARED, "AudioDSP", sst);
320 if (ret) {
321 dev_err(sst->dev, "unable to grab threaded IRQ %d, disabling device\n",
322 sst->irq);
323 return NULL;
324 }
325
326 return sst;
327}
328
329void skl_dsp_free(struct sst_dsp *dsp)
330{
331 skl_ipc_int_disable(dsp);
332
333 free_irq(dsp->irq, dsp);
334 skl_dsp_disable_core(dsp);
335}
336EXPORT_SYMBOL_GPL(skl_dsp_free);
337
338bool is_skl_dsp_running(struct sst_dsp *ctx)
339{
340 return (ctx->sst_state == SKL_DSP_RUNNING);
341}
342EXPORT_SYMBOL_GPL(is_skl_dsp_running);
diff --git a/sound/soc/intel/skylake/skl-sst-dsp.h b/sound/soc/intel/skylake/skl-sst-dsp.h
new file mode 100644
index 000000000000..6bfcef449bdc
--- /dev/null
+++ b/sound/soc/intel/skylake/skl-sst-dsp.h
@@ -0,0 +1,145 @@
1/*
2 * Skylake SST DSP Support
3 *
4 * Copyright (C) 2014-15, Intel Corporation.
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 version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#ifndef __SKL_SST_DSP_H__
17#define __SKL_SST_DSP_H__
18
19#include <linux/interrupt.h>
20#include <sound/memalloc.h>
21#include "skl-sst-cldma.h"
22
23struct sst_dsp;
24struct skl_sst;
25struct sst_dsp_device;
26
27/* Intel HD Audio General DSP Registers */
28#define SKL_ADSP_GEN_BASE 0x0
29#define SKL_ADSP_REG_ADSPCS (SKL_ADSP_GEN_BASE + 0x04)
30#define SKL_ADSP_REG_ADSPIC (SKL_ADSP_GEN_BASE + 0x08)
31#define SKL_ADSP_REG_ADSPIS (SKL_ADSP_GEN_BASE + 0x0C)
32#define SKL_ADSP_REG_ADSPIC2 (SKL_ADSP_GEN_BASE + 0x10)
33#define SKL_ADSP_REG_ADSPIS2 (SKL_ADSP_GEN_BASE + 0x14)
34
35/* Intel HD Audio Inter-Processor Communication Registers */
36#define SKL_ADSP_IPC_BASE 0x40
37#define SKL_ADSP_REG_HIPCT (SKL_ADSP_IPC_BASE + 0x00)
38#define SKL_ADSP_REG_HIPCTE (SKL_ADSP_IPC_BASE + 0x04)
39#define SKL_ADSP_REG_HIPCI (SKL_ADSP_IPC_BASE + 0x08)
40#define SKL_ADSP_REG_HIPCIE (SKL_ADSP_IPC_BASE + 0x0C)
41#define SKL_ADSP_REG_HIPCCTL (SKL_ADSP_IPC_BASE + 0x10)
42
43/* HIPCI */
44#define SKL_ADSP_REG_HIPCI_BUSY BIT(31)
45
46/* HIPCIE */
47#define SKL_ADSP_REG_HIPCIE_DONE BIT(30)
48
49/* HIPCCTL */
50#define SKL_ADSP_REG_HIPCCTL_DONE BIT(1)
51#define SKL_ADSP_REG_HIPCCTL_BUSY BIT(0)
52
53/* HIPCT */
54#define SKL_ADSP_REG_HIPCT_BUSY BIT(31)
55
56/* Intel HD Audio SRAM Window 1 */
57#define SKL_ADSP_SRAM1_BASE 0xA000
58
59#define SKL_ADSP_MMIO_LEN 0x10000
60
61#define SKL_ADSP_W0_STAT_SZ 0x800
62
63#define SKL_ADSP_W0_UP_SZ 0x800
64
65#define SKL_ADSP_W1_SZ 0x1000
66
67#define SKL_FW_STS_MASK 0xf
68
69#define SKL_FW_INIT 0x1
70#define SKL_FW_RFW_START 0xf
71
72#define SKL_ADSPIC_IPC 1
73#define SKL_ADSPIS_IPC 1
74
75/* ADSPCS - Audio DSP Control & Status */
76#define SKL_DSP_CORES 1
77#define SKL_DSP_CORE0_MASK 1
78#define SKL_DSP_CORES_MASK ((1 << SKL_DSP_CORES) - 1)
79
80/* Core Reset - asserted high */
81#define SKL_ADSPCS_CRST_SHIFT 0
82#define SKL_ADSPCS_CRST_MASK (SKL_DSP_CORES_MASK << SKL_ADSPCS_CRST_SHIFT)
83#define SKL_ADSPCS_CRST(x) ((x << SKL_ADSPCS_CRST_SHIFT) & SKL_ADSPCS_CRST_MASK)
84
85/* Core run/stall - when set to '1' core is stalled */
86#define SKL_ADSPCS_CSTALL_SHIFT 8
87#define SKL_ADSPCS_CSTALL_MASK (SKL_DSP_CORES_MASK << \
88 SKL_ADSPCS_CSTALL_SHIFT)
89#define SKL_ADSPCS_CSTALL(x) ((x << SKL_ADSPCS_CSTALL_SHIFT) & \
90 SKL_ADSPCS_CSTALL_MASK)
91
92/* Set Power Active - when set to '1' turn cores on */
93#define SKL_ADSPCS_SPA_SHIFT 16
94#define SKL_ADSPCS_SPA_MASK (SKL_DSP_CORES_MASK << SKL_ADSPCS_SPA_SHIFT)
95#define SKL_ADSPCS_SPA(x) ((x << SKL_ADSPCS_SPA_SHIFT) & SKL_ADSPCS_SPA_MASK)
96
97/* Current Power Active - power status of cores, set by hardware */
98#define SKL_ADSPCS_CPA_SHIFT 24
99#define SKL_ADSPCS_CPA_MASK (SKL_DSP_CORES_MASK << SKL_ADSPCS_CPA_SHIFT)
100#define SKL_ADSPCS_CPA(x) ((x << SKL_ADSPCS_CPA_SHIFT) & SKL_ADSPCS_CPA_MASK)
101
102#define SST_DSP_POWER_D0 0x0 /* full On */
103#define SST_DSP_POWER_D3 0x3 /* Off */
104
105enum skl_dsp_states {
106 SKL_DSP_RUNNING = 1,
107 SKL_DSP_RESET,
108};
109
110struct skl_dsp_fw_ops {
111 int (*load_fw)(struct sst_dsp *ctx);
112 /* FW module parser/loader */
113 int (*parse_fw)(struct sst_dsp *ctx);
114 int (*set_state_D0)(struct sst_dsp *ctx);
115 int (*set_state_D3)(struct sst_dsp *ctx);
116 unsigned int (*get_fw_errcode)(struct sst_dsp *ctx);
117};
118
119struct skl_dsp_loader_ops {
120 int (*alloc_dma_buf)(struct device *dev,
121 struct snd_dma_buffer *dmab, size_t size);
122 int (*free_dma_buf)(struct device *dev,
123 struct snd_dma_buffer *dmab);
124};
125
126void skl_cldma_process_intr(struct sst_dsp *ctx);
127void skl_cldma_int_disable(struct sst_dsp *ctx);
128int skl_cldma_prepare(struct sst_dsp *ctx);
129
130void skl_dsp_set_state_locked(struct sst_dsp *ctx, int state);
131struct sst_dsp *skl_dsp_ctx_init(struct device *dev,
132 struct sst_dsp_device *sst_dev, int irq);
133int skl_dsp_disable_core(struct sst_dsp *ctx);
134bool is_skl_dsp_running(struct sst_dsp *ctx);
135irqreturn_t skl_dsp_sst_interrupt(int irq, void *dev_id);
136int skl_dsp_wake(struct sst_dsp *ctx);
137int skl_dsp_sleep(struct sst_dsp *ctx);
138void skl_dsp_free(struct sst_dsp *dsp);
139
140int skl_dsp_boot(struct sst_dsp *ctx);
141int skl_sst_dsp_init(struct device *dev, void __iomem *mmio_base, int irq,
142 struct skl_dsp_loader_ops dsp_ops, struct skl_sst **dsp);
143void skl_sst_dsp_cleanup(struct device *dev, struct skl_sst *ctx);
144
145#endif /*__SKL_SST_DSP_H__*/
diff --git a/sound/soc/intel/skylake/skl-sst-ipc.c b/sound/soc/intel/skylake/skl-sst-ipc.c
new file mode 100644
index 000000000000..937a0a3a63a0
--- /dev/null
+++ b/sound/soc/intel/skylake/skl-sst-ipc.c
@@ -0,0 +1,771 @@
1/*
2 * skl-sst-ipc.c - Intel skl IPC Support
3 *
4 * Copyright (C) 2014-15, Intel Corporation.
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 version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15#include <linux/device.h>
16
17#include "../common/sst-dsp.h"
18#include "../common/sst-dsp-priv.h"
19#include "skl-sst-dsp.h"
20#include "skl-sst-ipc.h"
21
22
23#define IPC_IXC_STATUS_BITS 24
24
25/* Global Message - Generic */
26#define IPC_GLB_TYPE_SHIFT 24
27#define IPC_GLB_TYPE_MASK (0xf << IPC_GLB_TYPE_SHIFT)
28#define IPC_GLB_TYPE(x) ((x) << IPC_GLB_TYPE_SHIFT)
29
30/* Global Message - Reply */
31#define IPC_GLB_REPLY_STATUS_SHIFT 24
32#define IPC_GLB_REPLY_STATUS_MASK ((0x1 << IPC_GLB_REPLY_STATUS_SHIFT) - 1)
33#define IPC_GLB_REPLY_STATUS(x) ((x) << IPC_GLB_REPLY_STATUS_SHIFT)
34
35#define IPC_TIMEOUT_MSECS 3000
36
37#define IPC_EMPTY_LIST_SIZE 8
38
39#define IPC_MSG_TARGET_SHIFT 30
40#define IPC_MSG_TARGET_MASK 0x1
41#define IPC_MSG_TARGET(x) (((x) & IPC_MSG_TARGET_MASK) \
42 << IPC_MSG_TARGET_SHIFT)
43
44#define IPC_MSG_DIR_SHIFT 29
45#define IPC_MSG_DIR_MASK 0x1
46#define IPC_MSG_DIR(x) (((x) & IPC_MSG_DIR_MASK) \
47 << IPC_MSG_DIR_SHIFT)
48/* Global Notification Message */
49#define IPC_GLB_NOTIFY_TYPE_SHIFT 16
50#define IPC_GLB_NOTIFY_TYPE_MASK 0xFF
51#define IPC_GLB_NOTIFY_TYPE(x) (((x) >> IPC_GLB_NOTIFY_TYPE_SHIFT) \
52 & IPC_GLB_NOTIFY_TYPE_MASK)
53
54#define IPC_GLB_NOTIFY_MSG_TYPE_SHIFT 24
55#define IPC_GLB_NOTIFY_MSG_TYPE_MASK 0x1F
56#define IPC_GLB_NOTIFY_MSG_TYPE(x) (((x) >> IPC_GLB_NOTIFY_MSG_TYPE_SHIFT) \
57 & IPC_GLB_NOTIFY_MSG_TYPE_MASK)
58
59#define IPC_GLB_NOTIFY_RSP_SHIFT 29
60#define IPC_GLB_NOTIFY_RSP_MASK 0x1
61#define IPC_GLB_NOTIFY_RSP_TYPE(x) (((x) >> IPC_GLB_NOTIFY_RSP_SHIFT) \
62 & IPC_GLB_NOTIFY_RSP_MASK)
63
64/* Pipeline operations */
65
66/* Create pipeline message */
67#define IPC_PPL_MEM_SIZE_SHIFT 0
68#define IPC_PPL_MEM_SIZE_MASK 0x7FF
69#define IPC_PPL_MEM_SIZE(x) (((x) & IPC_PPL_MEM_SIZE_MASK) \
70 << IPC_PPL_MEM_SIZE_SHIFT)
71
72#define IPC_PPL_TYPE_SHIFT 11
73#define IPC_PPL_TYPE_MASK 0x1F
74#define IPC_PPL_TYPE(x) (((x) & IPC_PPL_TYPE_MASK) \
75 << IPC_PPL_TYPE_SHIFT)
76
77#define IPC_INSTANCE_ID_SHIFT 16
78#define IPC_INSTANCE_ID_MASK 0xFF
79#define IPC_INSTANCE_ID(x) (((x) & IPC_INSTANCE_ID_MASK) \
80 << IPC_INSTANCE_ID_SHIFT)
81
82/* Set pipeline state message */
83#define IPC_PPL_STATE_SHIFT 0
84#define IPC_PPL_STATE_MASK 0x1F
85#define IPC_PPL_STATE(x) (((x) & IPC_PPL_STATE_MASK) \
86 << IPC_PPL_STATE_SHIFT)
87
88/* Module operations primary register */
89#define IPC_MOD_ID_SHIFT 0
90#define IPC_MOD_ID_MASK 0xFFFF
91#define IPC_MOD_ID(x) (((x) & IPC_MOD_ID_MASK) \
92 << IPC_MOD_ID_SHIFT)
93
94#define IPC_MOD_INSTANCE_ID_SHIFT 16
95#define IPC_MOD_INSTANCE_ID_MASK 0xFF
96#define IPC_MOD_INSTANCE_ID(x) (((x) & IPC_MOD_INSTANCE_ID_MASK) \
97 << IPC_MOD_INSTANCE_ID_SHIFT)
98
99/* Init instance message extension register */
100#define IPC_PARAM_BLOCK_SIZE_SHIFT 0
101#define IPC_PARAM_BLOCK_SIZE_MASK 0xFFFF
102#define IPC_PARAM_BLOCK_SIZE(x) (((x) & IPC_PARAM_BLOCK_SIZE_MASK) \
103 << IPC_PARAM_BLOCK_SIZE_SHIFT)
104
105#define IPC_PPL_INSTANCE_ID_SHIFT 16
106#define IPC_PPL_INSTANCE_ID_MASK 0xFF
107#define IPC_PPL_INSTANCE_ID(x) (((x) & IPC_PPL_INSTANCE_ID_MASK) \
108 << IPC_PPL_INSTANCE_ID_SHIFT)
109
110#define IPC_CORE_ID_SHIFT 24
111#define IPC_CORE_ID_MASK 0x1F
112#define IPC_CORE_ID(x) (((x) & IPC_CORE_ID_MASK) \
113 << IPC_CORE_ID_SHIFT)
114
115/* Bind/Unbind message extension register */
116#define IPC_DST_MOD_ID_SHIFT 0
117#define IPC_DST_MOD_ID(x) (((x) & IPC_MOD_ID_MASK) \
118 << IPC_DST_MOD_ID_SHIFT)
119
120#define IPC_DST_MOD_INSTANCE_ID_SHIFT 16
121#define IPC_DST_MOD_INSTANCE_ID(x) (((x) & IPC_MOD_INSTANCE_ID_MASK) \
122 << IPC_DST_MOD_INSTANCE_ID_SHIFT)
123
124#define IPC_DST_QUEUE_SHIFT 24
125#define IPC_DST_QUEUE_MASK 0x7
126#define IPC_DST_QUEUE(x) (((x) & IPC_DST_QUEUE_MASK) \
127 << IPC_DST_QUEUE_SHIFT)
128
129#define IPC_SRC_QUEUE_SHIFT 27
130#define IPC_SRC_QUEUE_MASK 0x7
131#define IPC_SRC_QUEUE(x) (((x) & IPC_SRC_QUEUE_MASK) \
132 << IPC_SRC_QUEUE_SHIFT)
133
134/* Save pipeline messgae extension register */
135#define IPC_DMA_ID_SHIFT 0
136#define IPC_DMA_ID_MASK 0x1F
137#define IPC_DMA_ID(x) (((x) & IPC_DMA_ID_MASK) \
138 << IPC_DMA_ID_SHIFT)
139/* Large Config message extension register */
140#define IPC_DATA_OFFSET_SZ_SHIFT 0
141#define IPC_DATA_OFFSET_SZ_MASK 0xFFFFF
142#define IPC_DATA_OFFSET_SZ(x) (((x) & IPC_DATA_OFFSET_SZ_MASK) \
143 << IPC_DATA_OFFSET_SZ_SHIFT)
144#define IPC_DATA_OFFSET_SZ_CLEAR ~(IPC_DATA_OFFSET_SZ_MASK \
145 << IPC_DATA_OFFSET_SZ_SHIFT)
146
147#define IPC_LARGE_PARAM_ID_SHIFT 20
148#define IPC_LARGE_PARAM_ID_MASK 0xFF
149#define IPC_LARGE_PARAM_ID(x) (((x) & IPC_LARGE_PARAM_ID_MASK) \
150 << IPC_LARGE_PARAM_ID_SHIFT)
151
152#define IPC_FINAL_BLOCK_SHIFT 28
153#define IPC_FINAL_BLOCK_MASK 0x1
154#define IPC_FINAL_BLOCK(x) (((x) & IPC_FINAL_BLOCK_MASK) \
155 << IPC_FINAL_BLOCK_SHIFT)
156
157#define IPC_INITIAL_BLOCK_SHIFT 29
158#define IPC_INITIAL_BLOCK_MASK 0x1
159#define IPC_INITIAL_BLOCK(x) (((x) & IPC_INITIAL_BLOCK_MASK) \
160 << IPC_INITIAL_BLOCK_SHIFT)
161#define IPC_INITIAL_BLOCK_CLEAR ~(IPC_INITIAL_BLOCK_MASK \
162 << IPC_INITIAL_BLOCK_SHIFT)
163
164enum skl_ipc_msg_target {
165 IPC_FW_GEN_MSG = 0,
166 IPC_MOD_MSG = 1
167};
168
169enum skl_ipc_msg_direction {
170 IPC_MSG_REQUEST = 0,
171 IPC_MSG_REPLY = 1
172};
173
174/* Global Message Types */
175enum skl_ipc_glb_type {
176 IPC_GLB_GET_FW_VERSION = 0, /* Retrieves firmware version */
177 IPC_GLB_LOAD_MULTIPLE_MODS = 15,
178 IPC_GLB_UNLOAD_MULTIPLE_MODS = 16,
179 IPC_GLB_CREATE_PPL = 17,
180 IPC_GLB_DELETE_PPL = 18,
181 IPC_GLB_SET_PPL_STATE = 19,
182 IPC_GLB_GET_PPL_STATE = 20,
183 IPC_GLB_GET_PPL_CONTEXT_SIZE = 21,
184 IPC_GLB_SAVE_PPL = 22,
185 IPC_GLB_RESTORE_PPL = 23,
186 IPC_GLB_NOTIFY = 26,
187 IPC_GLB_MAX_IPC_MSG_NUMBER = 31 /* Maximum message number */
188};
189
190enum skl_ipc_glb_reply {
191 IPC_GLB_REPLY_SUCCESS = 0,
192
193 IPC_GLB_REPLY_UNKNOWN_MSG_TYPE = 1,
194 IPC_GLB_REPLY_ERROR_INVALID_PARAM = 2,
195
196 IPC_GLB_REPLY_BUSY = 3,
197 IPC_GLB_REPLY_PENDING = 4,
198 IPC_GLB_REPLY_FAILURE = 5,
199 IPC_GLB_REPLY_INVALID_REQUEST = 6,
200
201 IPC_GLB_REPLY_OUT_OF_MEMORY = 7,
202 IPC_GLB_REPLY_OUT_OF_MIPS = 8,
203
204 IPC_GLB_REPLY_INVALID_RESOURCE_ID = 9,
205 IPC_GLB_REPLY_INVALID_RESOURCE_STATE = 10,
206
207 IPC_GLB_REPLY_MOD_MGMT_ERROR = 100,
208 IPC_GLB_REPLY_MOD_LOAD_CL_FAILED = 101,
209 IPC_GLB_REPLY_MOD_LOAD_INVALID_HASH = 102,
210
211 IPC_GLB_REPLY_MOD_UNLOAD_INST_EXIST = 103,
212 IPC_GLB_REPLY_MOD_NOT_INITIALIZED = 104,
213
214 IPC_GLB_REPLY_INVALID_CONFIG_PARAM_ID = 120,
215 IPC_GLB_REPLY_INVALID_CONFIG_DATA_LEN = 121,
216 IPC_GLB_REPLY_GATEWAY_NOT_INITIALIZED = 140,
217 IPC_GLB_REPLY_GATEWAY_NOT_EXIST = 141,
218
219 IPC_GLB_REPLY_PPL_NOT_INITIALIZED = 160,
220 IPC_GLB_REPLY_PPL_NOT_EXIST = 161,
221 IPC_GLB_REPLY_PPL_SAVE_FAILED = 162,
222 IPC_GLB_REPLY_PPL_RESTORE_FAILED = 163,
223
224 IPC_MAX_STATUS = ((1<<IPC_IXC_STATUS_BITS)-1)
225};
226
227enum skl_ipc_notification_type {
228 IPC_GLB_NOTIFY_GLITCH = 0,
229 IPC_GLB_NOTIFY_OVERRUN = 1,
230 IPC_GLB_NOTIFY_UNDERRUN = 2,
231 IPC_GLB_NOTIFY_END_STREAM = 3,
232 IPC_GLB_NOTIFY_PHRASE_DETECTED = 4,
233 IPC_GLB_NOTIFY_RESOURCE_EVENT = 5,
234 IPC_GLB_NOTIFY_LOG_BUFFER_STATUS = 6,
235 IPC_GLB_NOTIFY_TIMESTAMP_CAPTURED = 7,
236 IPC_GLB_NOTIFY_FW_READY = 8
237};
238
239/* Module Message Types */
240enum skl_ipc_module_msg {
241 IPC_MOD_INIT_INSTANCE = 0,
242 IPC_MOD_CONFIG_GET = 1,
243 IPC_MOD_CONFIG_SET = 2,
244 IPC_MOD_LARGE_CONFIG_GET = 3,
245 IPC_MOD_LARGE_CONFIG_SET = 4,
246 IPC_MOD_BIND = 5,
247 IPC_MOD_UNBIND = 6,
248 IPC_MOD_SET_DX = 7
249};
250
251static void skl_ipc_tx_data_copy(struct ipc_message *msg, char *tx_data,
252 size_t tx_size)
253{
254 if (tx_size)
255 memcpy(msg->tx_data, tx_data, tx_size);
256}
257
258static bool skl_ipc_is_dsp_busy(struct sst_dsp *dsp)
259{
260 u32 hipci;
261
262 hipci = sst_dsp_shim_read_unlocked(dsp, SKL_ADSP_REG_HIPCI);
263 return (hipci & SKL_ADSP_REG_HIPCI_BUSY);
264}
265
266/* Lock to be held by caller */
267static void skl_ipc_tx_msg(struct sst_generic_ipc *ipc, struct ipc_message *msg)
268{
269 struct skl_ipc_header *header = (struct skl_ipc_header *)(&msg->header);
270
271 if (msg->tx_size)
272 sst_dsp_outbox_write(ipc->dsp, msg->tx_data, msg->tx_size);
273 sst_dsp_shim_write_unlocked(ipc->dsp, SKL_ADSP_REG_HIPCIE,
274 header->extension);
275 sst_dsp_shim_write_unlocked(ipc->dsp, SKL_ADSP_REG_HIPCI,
276 header->primary | SKL_ADSP_REG_HIPCI_BUSY);
277}
278
279static struct ipc_message *skl_ipc_reply_get_msg(struct sst_generic_ipc *ipc,
280 u64 ipc_header)
281{
282 struct ipc_message *msg = NULL;
283 struct skl_ipc_header *header = (struct skl_ipc_header *)(&ipc_header);
284
285 if (list_empty(&ipc->rx_list)) {
286 dev_err(ipc->dev, "ipc: rx list is empty but received 0x%x\n",
287 header->primary);
288 goto out;
289 }
290
291 msg = list_first_entry(&ipc->rx_list, struct ipc_message, list);
292
293out:
294 return msg;
295
296}
297
298static int skl_ipc_process_notification(struct sst_generic_ipc *ipc,
299 struct skl_ipc_header header)
300{
301 struct skl_sst *skl = container_of(ipc, struct skl_sst, ipc);
302
303 if (IPC_GLB_NOTIFY_MSG_TYPE(header.primary)) {
304 switch (IPC_GLB_NOTIFY_TYPE(header.primary)) {
305
306 case IPC_GLB_NOTIFY_UNDERRUN:
307 dev_err(ipc->dev, "FW Underrun %x\n", header.primary);
308 break;
309
310 case IPC_GLB_NOTIFY_RESOURCE_EVENT:
311 dev_err(ipc->dev, "MCPS Budget Violation: %x\n",
312 header.primary);
313 break;
314
315 case IPC_GLB_NOTIFY_FW_READY:
316 skl->boot_complete = true;
317 wake_up(&skl->boot_wait);
318 break;
319
320 default:
321 dev_err(ipc->dev, "ipc: Unhandled error msg=%x",
322 header.primary);
323 break;
324 }
325 }
326
327 return 0;
328}
329
330static void skl_ipc_process_reply(struct sst_generic_ipc *ipc,
331 struct skl_ipc_header header)
332{
333 struct ipc_message *msg;
334 u32 reply = header.primary & IPC_GLB_REPLY_STATUS_MASK;
335 u64 *ipc_header = (u64 *)(&header);
336
337 msg = skl_ipc_reply_get_msg(ipc, *ipc_header);
338 if (msg == NULL) {
339 dev_dbg(ipc->dev, "ipc: rx list is empty\n");
340 return;
341 }
342
343 /* first process the header */
344 switch (reply) {
345 case IPC_GLB_REPLY_SUCCESS:
346 dev_info(ipc->dev, "ipc FW reply %x: success\n", header.primary);
347 break;
348
349 case IPC_GLB_REPLY_OUT_OF_MEMORY:
350 dev_err(ipc->dev, "ipc fw reply: %x: no memory\n", header.primary);
351 msg->errno = -ENOMEM;
352 break;
353
354 case IPC_GLB_REPLY_BUSY:
355 dev_err(ipc->dev, "ipc fw reply: %x: Busy\n", header.primary);
356 msg->errno = -EBUSY;
357 break;
358
359 default:
360 dev_err(ipc->dev, "Unknown ipc reply: 0x%x", reply);
361 msg->errno = -EINVAL;
362 break;
363 }
364
365 if (reply != IPC_GLB_REPLY_SUCCESS) {
366 dev_err(ipc->dev, "ipc FW reply: reply=%d", reply);
367 dev_err(ipc->dev, "FW Error Code: %u\n",
368 ipc->dsp->fw_ops.get_fw_errcode(ipc->dsp));
369 }
370
371 list_del(&msg->list);
372 sst_ipc_tx_msg_reply_complete(ipc, msg);
373}
374
375irqreturn_t skl_dsp_irq_thread_handler(int irq, void *context)
376{
377 struct sst_dsp *dsp = context;
378 struct skl_sst *skl = sst_dsp_get_thread_context(dsp);
379 struct sst_generic_ipc *ipc = &skl->ipc;
380 struct skl_ipc_header header = {0};
381 u32 hipcie, hipct, hipcte;
382 int ipc_irq = 0;
383
384 if (dsp->intr_status & SKL_ADSPIS_CL_DMA)
385 skl_cldma_process_intr(dsp);
386
387 /* Here we handle IPC interrupts only */
388 if (!(dsp->intr_status & SKL_ADSPIS_IPC))
389 return IRQ_NONE;
390
391 hipcie = sst_dsp_shim_read_unlocked(dsp, SKL_ADSP_REG_HIPCIE);
392 hipct = sst_dsp_shim_read_unlocked(dsp, SKL_ADSP_REG_HIPCT);
393
394 /* reply message from DSP */
395 if (hipcie & SKL_ADSP_REG_HIPCIE_DONE) {
396 sst_dsp_shim_update_bits(dsp, SKL_ADSP_REG_HIPCCTL,
397 SKL_ADSP_REG_HIPCCTL_DONE, 0);
398
399 /* clear DONE bit - tell DSP we have completed the operation */
400 sst_dsp_shim_update_bits_forced(dsp, SKL_ADSP_REG_HIPCIE,
401 SKL_ADSP_REG_HIPCIE_DONE, SKL_ADSP_REG_HIPCIE_DONE);
402
403 ipc_irq = 1;
404
405 /* unmask Done interrupt */
406 sst_dsp_shim_update_bits(dsp, SKL_ADSP_REG_HIPCCTL,
407 SKL_ADSP_REG_HIPCCTL_DONE, SKL_ADSP_REG_HIPCCTL_DONE);
408 }
409
410 /* New message from DSP */
411 if (hipct & SKL_ADSP_REG_HIPCT_BUSY) {
412 hipcte = sst_dsp_shim_read_unlocked(dsp, SKL_ADSP_REG_HIPCTE);
413 header.primary = hipct;
414 header.extension = hipcte;
415 dev_dbg(dsp->dev, "IPC irq: Firmware respond primary:%x",
416 header.primary);
417 dev_dbg(dsp->dev, "IPC irq: Firmware respond extension:%x",
418 header.extension);
419
420 if (IPC_GLB_NOTIFY_RSP_TYPE(header.primary)) {
421 /* Handle Immediate reply from DSP Core */
422 skl_ipc_process_reply(ipc, header);
423 } else {
424 dev_dbg(dsp->dev, "IPC irq: Notification from firmware\n");
425 skl_ipc_process_notification(ipc, header);
426 }
427 /* clear busy interrupt */
428 sst_dsp_shim_update_bits_forced(dsp, SKL_ADSP_REG_HIPCT,
429 SKL_ADSP_REG_HIPCT_BUSY, SKL_ADSP_REG_HIPCT_BUSY);
430 ipc_irq = 1;
431 }
432
433 if (ipc_irq == 0)
434 return IRQ_NONE;
435
436 skl_ipc_int_enable(dsp);
437
438 /* continue to send any remaining messages... */
439 queue_kthread_work(&ipc->kworker, &ipc->kwork);
440
441 return IRQ_HANDLED;
442}
443
444void skl_ipc_int_enable(struct sst_dsp *ctx)
445{
446 sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_ADSPIC,
447 SKL_ADSPIC_IPC, SKL_ADSPIC_IPC);
448}
449
450void skl_ipc_int_disable(struct sst_dsp *ctx)
451{
452 sst_dsp_shim_update_bits_unlocked(ctx, SKL_ADSP_REG_ADSPIC,
453 SKL_ADSPIC_IPC, 0);
454}
455
456void skl_ipc_op_int_enable(struct sst_dsp *ctx)
457{
458 /* enable IPC DONE interrupt */
459 sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_HIPCCTL,
460 SKL_ADSP_REG_HIPCCTL_DONE, SKL_ADSP_REG_HIPCCTL_DONE);
461
462 /* Enable IPC BUSY interrupt */
463 sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_HIPCCTL,
464 SKL_ADSP_REG_HIPCCTL_BUSY, SKL_ADSP_REG_HIPCCTL_BUSY);
465}
466
467bool skl_ipc_int_status(struct sst_dsp *ctx)
468{
469 return sst_dsp_shim_read_unlocked(ctx,
470 SKL_ADSP_REG_ADSPIS) & SKL_ADSPIS_IPC;
471}
472
473int skl_ipc_init(struct device *dev, struct skl_sst *skl)
474{
475 struct sst_generic_ipc *ipc;
476 int err;
477
478 ipc = &skl->ipc;
479 ipc->dsp = skl->dsp;
480 ipc->dev = dev;
481
482 ipc->tx_data_max_size = SKL_ADSP_W1_SZ;
483 ipc->rx_data_max_size = SKL_ADSP_W0_UP_SZ;
484
485 err = sst_ipc_init(ipc);
486 if (err)
487 return err;
488
489 ipc->ops.tx_msg = skl_ipc_tx_msg;
490 ipc->ops.tx_data_copy = skl_ipc_tx_data_copy;
491 ipc->ops.is_dsp_busy = skl_ipc_is_dsp_busy;
492
493 return 0;
494}
495
496void skl_ipc_free(struct sst_generic_ipc *ipc)
497{
498 /* Disable IPC DONE interrupt */
499 sst_dsp_shim_update_bits(ipc->dsp, SKL_ADSP_REG_HIPCCTL,
500 SKL_ADSP_REG_HIPCCTL_DONE, 0);
501
502 /* Disable IPC BUSY interrupt */
503 sst_dsp_shim_update_bits(ipc->dsp, SKL_ADSP_REG_HIPCCTL,
504 SKL_ADSP_REG_HIPCCTL_BUSY, 0);
505
506 sst_ipc_fini(ipc);
507}
508
509int skl_ipc_create_pipeline(struct sst_generic_ipc *ipc,
510 u16 ppl_mem_size, u8 ppl_type, u8 instance_id)
511{
512 struct skl_ipc_header header = {0};
513 u64 *ipc_header = (u64 *)(&header);
514 int ret;
515
516 header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG);
517 header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST);
518 header.primary |= IPC_GLB_TYPE(IPC_GLB_CREATE_PPL);
519 header.primary |= IPC_INSTANCE_ID(instance_id);
520 header.primary |= IPC_PPL_TYPE(ppl_type);
521 header.primary |= IPC_PPL_MEM_SIZE(ppl_mem_size);
522
523 dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary);
524 ret = sst_ipc_tx_message_wait(ipc, *ipc_header, NULL, 0, NULL, 0);
525 if (ret < 0) {
526 dev_err(ipc->dev, "ipc: create pipeline fail, err: %d\n", ret);
527 return ret;
528 }
529
530 return ret;
531}
532EXPORT_SYMBOL_GPL(skl_ipc_create_pipeline);
533
534int skl_ipc_delete_pipeline(struct sst_generic_ipc *ipc, u8 instance_id)
535{
536 struct skl_ipc_header header = {0};
537 u64 *ipc_header = (u64 *)(&header);
538 int ret;
539
540 header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG);
541 header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST);
542 header.primary |= IPC_GLB_TYPE(IPC_GLB_DELETE_PPL);
543 header.primary |= IPC_INSTANCE_ID(instance_id);
544
545 dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary);
546 ret = sst_ipc_tx_message_wait(ipc, *ipc_header, NULL, 0, NULL, 0);
547 if (ret < 0) {
548 dev_err(ipc->dev, "ipc: delete pipeline failed, err %d\n", ret);
549 return ret;
550 }
551
552 return 0;
553}
554EXPORT_SYMBOL_GPL(skl_ipc_delete_pipeline);
555
556int skl_ipc_set_pipeline_state(struct sst_generic_ipc *ipc,
557 u8 instance_id, enum skl_ipc_pipeline_state state)
558{
559 struct skl_ipc_header header = {0};
560 u64 *ipc_header = (u64 *)(&header);
561 int ret;
562
563 header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG);
564 header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST);
565 header.primary |= IPC_GLB_TYPE(IPC_GLB_SET_PPL_STATE);
566 header.primary |= IPC_INSTANCE_ID(instance_id);
567 header.primary |= IPC_PPL_STATE(state);
568
569 dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary);
570 ret = sst_ipc_tx_message_wait(ipc, *ipc_header, NULL, 0, NULL, 0);
571 if (ret < 0) {
572 dev_err(ipc->dev, "ipc: set pipeline state failed, err: %d\n", ret);
573 return ret;
574 }
575 return ret;
576}
577EXPORT_SYMBOL_GPL(skl_ipc_set_pipeline_state);
578
579int
580skl_ipc_save_pipeline(struct sst_generic_ipc *ipc, u8 instance_id, int dma_id)
581{
582 struct skl_ipc_header header = {0};
583 u64 *ipc_header = (u64 *)(&header);
584 int ret;
585
586 header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG);
587 header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST);
588 header.primary |= IPC_GLB_TYPE(IPC_GLB_SAVE_PPL);
589 header.primary |= IPC_INSTANCE_ID(instance_id);
590
591 header.extension = IPC_DMA_ID(dma_id);
592 dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary);
593 ret = sst_ipc_tx_message_wait(ipc, *ipc_header, NULL, 0, NULL, 0);
594 if (ret < 0) {
595 dev_err(ipc->dev, "ipc: save pipeline failed, err: %d\n", ret);
596 return ret;
597 }
598
599 return ret;
600}
601EXPORT_SYMBOL_GPL(skl_ipc_save_pipeline);
602
603int skl_ipc_restore_pipeline(struct sst_generic_ipc *ipc, u8 instance_id)
604{
605 struct skl_ipc_header header = {0};
606 u64 *ipc_header = (u64 *)(&header);
607 int ret;
608
609 header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG);
610 header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST);
611 header.primary |= IPC_GLB_TYPE(IPC_GLB_RESTORE_PPL);
612 header.primary |= IPC_INSTANCE_ID(instance_id);
613
614 dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary);
615 ret = sst_ipc_tx_message_wait(ipc, *ipc_header, NULL, 0, NULL, 0);
616 if (ret < 0) {
617 dev_err(ipc->dev, "ipc: restore pipeline failed, err: %d\n", ret);
618 return ret;
619 }
620
621 return ret;
622}
623EXPORT_SYMBOL_GPL(skl_ipc_restore_pipeline);
624
625int skl_ipc_set_dx(struct sst_generic_ipc *ipc, u8 instance_id,
626 u16 module_id, struct skl_ipc_dxstate_info *dx)
627{
628 struct skl_ipc_header header = {0};
629 u64 *ipc_header = (u64 *)(&header);
630 int ret;
631
632 header.primary = IPC_MSG_TARGET(IPC_MOD_MSG);
633 header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST);
634 header.primary |= IPC_GLB_TYPE(IPC_MOD_SET_DX);
635 header.primary |= IPC_MOD_INSTANCE_ID(instance_id);
636 header.primary |= IPC_MOD_ID(module_id);
637
638 dev_dbg(ipc->dev, "In %s primary =%x ext=%x\n", __func__,
639 header.primary, header.extension);
640 ret = sst_ipc_tx_message_wait(ipc, *ipc_header,
641 dx, sizeof(dx), NULL, 0);
642 if (ret < 0) {
643 dev_err(ipc->dev, "ipc: set dx failed, err %d\n", ret);
644 return ret;
645 }
646
647 return ret;
648}
649EXPORT_SYMBOL_GPL(skl_ipc_set_dx);
650
651int skl_ipc_init_instance(struct sst_generic_ipc *ipc,
652 struct skl_ipc_init_instance_msg *msg, void *param_data)
653{
654 struct skl_ipc_header header = {0};
655 u64 *ipc_header = (u64 *)(&header);
656 int ret;
657 u32 *buffer = (u32 *)param_data;
658 /* param_block_size must be in dwords */
659 u16 param_block_size = msg->param_data_size / sizeof(u32);
660
661 print_hex_dump(KERN_DEBUG, NULL, DUMP_PREFIX_NONE,
662 16, 4, buffer, param_block_size, false);
663
664 header.primary = IPC_MSG_TARGET(IPC_MOD_MSG);
665 header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST);
666 header.primary |= IPC_GLB_TYPE(IPC_MOD_INIT_INSTANCE);
667 header.primary |= IPC_MOD_INSTANCE_ID(msg->instance_id);
668 header.primary |= IPC_MOD_ID(msg->module_id);
669
670 header.extension = IPC_CORE_ID(msg->core_id);
671 header.extension |= IPC_PPL_INSTANCE_ID(msg->ppl_instance_id);
672 header.extension |= IPC_PARAM_BLOCK_SIZE(param_block_size);
673
674 dev_dbg(ipc->dev, "In %s primary =%x ext=%x\n", __func__,
675 header.primary, header.extension);
676 ret = sst_ipc_tx_message_wait(ipc, *ipc_header, param_data,
677 msg->param_data_size, NULL, 0);
678
679 if (ret < 0) {
680 dev_err(ipc->dev, "ipc: init instance failed\n");
681 return ret;
682 }
683
684 return ret;
685}
686EXPORT_SYMBOL_GPL(skl_ipc_init_instance);
687
688int skl_ipc_bind_unbind(struct sst_generic_ipc *ipc,
689 struct skl_ipc_bind_unbind_msg *msg)
690{
691 struct skl_ipc_header header = {0};
692 u64 *ipc_header = (u64 *)(&header);
693 u8 bind_unbind = msg->bind ? IPC_MOD_BIND : IPC_MOD_UNBIND;
694 int ret;
695
696 header.primary = IPC_MSG_TARGET(IPC_MOD_MSG);
697 header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST);
698 header.primary |= IPC_GLB_TYPE(bind_unbind);
699 header.primary |= IPC_MOD_INSTANCE_ID(msg->instance_id);
700 header.primary |= IPC_MOD_ID(msg->module_id);
701
702 header.extension = IPC_DST_MOD_ID(msg->dst_module_id);
703 header.extension |= IPC_DST_MOD_INSTANCE_ID(msg->dst_instance_id);
704 header.extension |= IPC_DST_QUEUE(msg->dst_queue);
705 header.extension |= IPC_SRC_QUEUE(msg->src_queue);
706
707 dev_dbg(ipc->dev, "In %s hdr=%x ext=%x\n", __func__, header.primary,
708 header.extension);
709 ret = sst_ipc_tx_message_wait(ipc, *ipc_header, NULL, 0, NULL, 0);
710 if (ret < 0) {
711 dev_err(ipc->dev, "ipc: bind/unbind faileden");
712 return ret;
713 }
714
715 return ret;
716}
717EXPORT_SYMBOL_GPL(skl_ipc_bind_unbind);
718
719int skl_ipc_set_large_config(struct sst_generic_ipc *ipc,
720 struct skl_ipc_large_config_msg *msg, u32 *param)
721{
722 struct skl_ipc_header header = {0};
723 u64 *ipc_header = (u64 *)(&header);
724 int ret = 0;
725 size_t sz_remaining, tx_size, data_offset;
726
727 header.primary = IPC_MSG_TARGET(IPC_MOD_MSG);
728 header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST);
729 header.primary |= IPC_GLB_TYPE(IPC_MOD_LARGE_CONFIG_SET);
730 header.primary |= IPC_MOD_INSTANCE_ID(msg->instance_id);
731 header.primary |= IPC_MOD_ID(msg->module_id);
732
733 header.extension = IPC_DATA_OFFSET_SZ(msg->param_data_size);
734 header.extension |= IPC_LARGE_PARAM_ID(msg->large_param_id);
735 header.extension |= IPC_FINAL_BLOCK(0);
736 header.extension |= IPC_INITIAL_BLOCK(1);
737
738 sz_remaining = msg->param_data_size;
739 data_offset = 0;
740 while (sz_remaining != 0) {
741 tx_size = sz_remaining > SKL_ADSP_W1_SZ
742 ? SKL_ADSP_W1_SZ : sz_remaining;
743 if (tx_size == sz_remaining)
744 header.extension |= IPC_FINAL_BLOCK(1);
745
746 dev_dbg(ipc->dev, "In %s primary=%#x ext=%#x\n", __func__,
747 header.primary, header.extension);
748 dev_dbg(ipc->dev, "transmitting offset: %#x, size: %#x\n",
749 (unsigned)data_offset, (unsigned)tx_size);
750 ret = sst_ipc_tx_message_wait(ipc, *ipc_header,
751 ((char *)param) + data_offset,
752 tx_size, NULL, 0);
753 if (ret < 0) {
754 dev_err(ipc->dev,
755 "ipc: set large config fail, err: %d\n", ret);
756 return ret;
757 }
758 sz_remaining -= tx_size;
759 data_offset = msg->param_data_size - sz_remaining;
760
761 /* clear the fields */
762 header.extension &= IPC_INITIAL_BLOCK_CLEAR;
763 header.extension &= IPC_DATA_OFFSET_SZ_CLEAR;
764 /* fill the fields */
765 header.extension |= IPC_INITIAL_BLOCK(0);
766 header.extension |= IPC_DATA_OFFSET_SZ(data_offset);
767 }
768
769 return ret;
770}
771EXPORT_SYMBOL_GPL(skl_ipc_set_large_config);
diff --git a/sound/soc/intel/skylake/skl-sst-ipc.h b/sound/soc/intel/skylake/skl-sst-ipc.h
new file mode 100644
index 000000000000..9f5f67202858
--- /dev/null
+++ b/sound/soc/intel/skylake/skl-sst-ipc.h
@@ -0,0 +1,125 @@
1/*
2 * Intel SKL IPC Support
3 *
4 * Copyright (C) 2014-15, Intel Corporation.
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 version 2, as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
16#ifndef __SKL_IPC_H
17#define __SKL_IPC_H
18
19#include <linux/kthread.h>
20#include <linux/irqreturn.h>
21#include "../common/sst-ipc.h"
22
23struct sst_dsp;
24struct skl_sst;
25struct sst_generic_ipc;
26
27enum skl_ipc_pipeline_state {
28 PPL_INVALID_STATE = 0,
29 PPL_UNINITIALIZED = 1,
30 PPL_RESET = 2,
31 PPL_PAUSED = 3,
32 PPL_RUNNING = 4,
33 PPL_ERROR_STOP = 5,
34 PPL_SAVED = 6,
35 PPL_RESTORED = 7
36};
37
38struct skl_ipc_dxstate_info {
39 u32 core_mask;
40 u32 dx_mask;
41};
42
43struct skl_ipc_header {
44 u32 primary;
45 u32 extension;
46};
47
48struct skl_sst {
49 struct device *dev;
50 struct sst_dsp *dsp;
51
52 /* boot */
53 wait_queue_head_t boot_wait;
54 bool boot_complete;
55
56 /* IPC messaging */
57 struct sst_generic_ipc ipc;
58};
59
60struct skl_ipc_init_instance_msg {
61 u32 module_id;
62 u32 instance_id;
63 u16 param_data_size;
64 u8 ppl_instance_id;
65 u8 core_id;
66};
67
68struct skl_ipc_bind_unbind_msg {
69 u32 module_id;
70 u32 instance_id;
71 u32 dst_module_id;
72 u32 dst_instance_id;
73 u8 src_queue;
74 u8 dst_queue;
75 bool bind;
76};
77
78struct skl_ipc_large_config_msg {
79 u32 module_id;
80 u32 instance_id;
81 u32 large_param_id;
82 u32 param_data_size;
83};
84
85#define SKL_IPC_BOOT_MSECS 3000
86
87#define SKL_IPC_D3_MASK 0
88#define SKL_IPC_D0_MASK 3
89
90irqreturn_t skl_dsp_irq_thread_handler(int irq, void *context);
91
92int skl_ipc_create_pipeline(struct sst_generic_ipc *sst_ipc,
93 u16 ppl_mem_size, u8 ppl_type, u8 instance_id);
94
95int skl_ipc_delete_pipeline(struct sst_generic_ipc *sst_ipc, u8 instance_id);
96
97int skl_ipc_set_pipeline_state(struct sst_generic_ipc *sst_ipc,
98 u8 instance_id, enum skl_ipc_pipeline_state state);
99
100int skl_ipc_save_pipeline(struct sst_generic_ipc *ipc,
101 u8 instance_id, int dma_id);
102
103int skl_ipc_restore_pipeline(struct sst_generic_ipc *ipc, u8 instance_id);
104
105int skl_ipc_init_instance(struct sst_generic_ipc *sst_ipc,
106 struct skl_ipc_init_instance_msg *msg, void *param_data);
107
108int skl_ipc_bind_unbind(struct sst_generic_ipc *sst_ipc,
109 struct skl_ipc_bind_unbind_msg *msg);
110
111int skl_ipc_set_dx(struct sst_generic_ipc *ipc,
112 u8 instance_id, u16 module_id, struct skl_ipc_dxstate_info *dx);
113
114int skl_ipc_set_large_config(struct sst_generic_ipc *ipc,
115 struct skl_ipc_large_config_msg *msg, u32 *param);
116
117void skl_ipc_int_enable(struct sst_dsp *dsp);
118void skl_ipc_op_int_enable(struct sst_dsp *ctx);
119void skl_ipc_int_disable(struct sst_dsp *dsp);
120
121bool skl_ipc_int_status(struct sst_dsp *dsp);
122void skl_ipc_free(struct sst_generic_ipc *ipc);
123int skl_ipc_init(struct device *dev, struct skl_sst *skl);
124
125#endif /* __SKL_IPC_H */
diff --git a/sound/soc/intel/skylake/skl-sst.c b/sound/soc/intel/skylake/skl-sst.c
new file mode 100644
index 000000000000..c18ea51b7484
--- /dev/null
+++ b/sound/soc/intel/skylake/skl-sst.c
@@ -0,0 +1,280 @@
1/*
2 * skl-sst.c - HDA DSP library functions for SKL platform
3 *
4 * Copyright (C) 2014-15, Intel Corporation.
5 * Author:Rafal Redzimski <rafal.f.redzimski@intel.com>
6 * Jeeja KP <jeeja.kp@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 version 2, as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 */
18
19#include <linux/module.h>
20#include <linux/delay.h>
21#include <linux/device.h>
22#include "../common/sst-dsp.h"
23#include "../common/sst-dsp-priv.h"
24#include "../common/sst-ipc.h"
25#include "skl-sst-ipc.h"
26
27#define SKL_BASEFW_TIMEOUT 300
28#define SKL_INIT_TIMEOUT 1000
29
30/* Intel HD Audio SRAM Window 0*/
31#define SKL_ADSP_SRAM0_BASE 0x8000
32
33/* Firmware status window */
34#define SKL_ADSP_FW_STATUS SKL_ADSP_SRAM0_BASE
35#define SKL_ADSP_ERROR_CODE (SKL_ADSP_FW_STATUS + 0x4)
36
37#define SKL_INSTANCE_ID 0
38#define SKL_BASE_FW_MODULE_ID 0
39
40static bool skl_check_fw_status(struct sst_dsp *ctx, u32 status)
41{
42 u32 cur_sts;
43
44 cur_sts = sst_dsp_shim_read(ctx, SKL_ADSP_FW_STATUS) & SKL_FW_STS_MASK;
45
46 return (cur_sts == status);
47}
48
49static int skl_transfer_firmware(struct sst_dsp *ctx,
50 const void *basefw, u32 base_fw_size)
51{
52 int ret = 0;
53
54 ret = ctx->cl_dev.ops.cl_copy_to_dmabuf(ctx, basefw, base_fw_size);
55 if (ret < 0)
56 return ret;
57
58 ret = sst_dsp_register_poll(ctx,
59 SKL_ADSP_FW_STATUS,
60 SKL_FW_STS_MASK,
61 SKL_FW_RFW_START,
62 SKL_BASEFW_TIMEOUT,
63 "Firmware boot");
64
65 ctx->cl_dev.ops.cl_stop_dma(ctx);
66
67 return ret;
68}
69
70static int skl_load_base_firmware(struct sst_dsp *ctx)
71{
72 int ret = 0, i;
73 const struct firmware *fw = NULL;
74 struct skl_sst *skl = ctx->thread_context;
75 u32 reg;
76
77 ret = request_firmware(&fw, "dsp_fw_release.bin", ctx->dev);
78 if (ret < 0) {
79 dev_err(ctx->dev, "Request firmware failed %d\n", ret);
80 skl_dsp_disable_core(ctx);
81 return -EIO;
82 }
83
84 /* enable Interrupt */
85 skl_ipc_int_enable(ctx);
86 skl_ipc_op_int_enable(ctx);
87
88 /* check ROM Status */
89 for (i = SKL_INIT_TIMEOUT; i > 0; --i) {
90 if (skl_check_fw_status(ctx, SKL_FW_INIT)) {
91 dev_dbg(ctx->dev,
92 "ROM loaded, we can continue with FW loading\n");
93 break;
94 }
95 mdelay(1);
96 }
97 if (!i) {
98 reg = sst_dsp_shim_read(ctx, SKL_ADSP_FW_STATUS);
99 dev_err(ctx->dev,
100 "Timeout waiting for ROM init done, reg:0x%x\n", reg);
101 ret = -EIO;
102 goto skl_load_base_firmware_failed;
103 }
104
105 ret = skl_transfer_firmware(ctx, fw->data, fw->size);
106 if (ret < 0) {
107 dev_err(ctx->dev, "Transfer firmware failed%d\n", ret);
108 goto skl_load_base_firmware_failed;
109 } else {
110 ret = wait_event_timeout(skl->boot_wait, skl->boot_complete,
111 msecs_to_jiffies(SKL_IPC_BOOT_MSECS));
112 if (ret == 0) {
113 dev_err(ctx->dev, "DSP boot failed, FW Ready timed-out\n");
114 ret = -EIO;
115 goto skl_load_base_firmware_failed;
116 }
117
118 dev_dbg(ctx->dev, "Download firmware successful%d\n", ret);
119 skl_dsp_set_state_locked(ctx, SKL_DSP_RUNNING);
120 }
121 release_firmware(fw);
122
123 return 0;
124
125skl_load_base_firmware_failed:
126 skl_dsp_disable_core(ctx);
127 release_firmware(fw);
128 return ret;
129}
130
131static int skl_set_dsp_D0(struct sst_dsp *ctx)
132{
133 int ret;
134
135 ret = skl_load_base_firmware(ctx);
136 if (ret < 0) {
137 dev_err(ctx->dev, "unable to load firmware\n");
138 return ret;
139 }
140
141 skl_dsp_set_state_locked(ctx, SKL_DSP_RUNNING);
142
143 return ret;
144}
145
146static int skl_set_dsp_D3(struct sst_dsp *ctx)
147{
148 int ret;
149 struct skl_ipc_dxstate_info dx;
150 struct skl_sst *skl = ctx->thread_context;
151
152 dev_dbg(ctx->dev, "In %s:\n", __func__);
153 mutex_lock(&ctx->mutex);
154 if (!is_skl_dsp_running(ctx)) {
155 mutex_unlock(&ctx->mutex);
156 return 0;
157 }
158 mutex_unlock(&ctx->mutex);
159
160 dx.core_mask = SKL_DSP_CORE0_MASK;
161 dx.dx_mask = SKL_IPC_D3_MASK;
162 ret = skl_ipc_set_dx(&skl->ipc, SKL_INSTANCE_ID, SKL_BASE_FW_MODULE_ID, &dx);
163 if (ret < 0) {
164 dev_err(ctx->dev, "Failed to set DSP to D3 state\n");
165 return ret;
166 }
167
168 ret = skl_dsp_disable_core(ctx);
169 if (ret < 0) {
170 dev_err(ctx->dev, "disable dsp core failed ret: %d\n", ret);
171 ret = -EIO;
172 }
173 skl_dsp_set_state_locked(ctx, SKL_DSP_RESET);
174
175 return ret;
176}
177
178static unsigned int skl_get_errorcode(struct sst_dsp *ctx)
179{
180 return sst_dsp_shim_read(ctx, SKL_ADSP_ERROR_CODE);
181}
182
183static struct skl_dsp_fw_ops skl_fw_ops = {
184 .set_state_D0 = skl_set_dsp_D0,
185 .set_state_D3 = skl_set_dsp_D3,
186 .load_fw = skl_load_base_firmware,
187 .get_fw_errcode = skl_get_errorcode,
188};
189
190static struct sst_ops skl_ops = {
191 .irq_handler = skl_dsp_sst_interrupt,
192 .write = sst_shim32_write,
193 .read = sst_shim32_read,
194 .ram_read = sst_memcpy_fromio_32,
195 .ram_write = sst_memcpy_toio_32,
196 .free = skl_dsp_free,
197};
198
199static struct sst_dsp_device skl_dev = {
200 .thread = skl_dsp_irq_thread_handler,
201 .ops = &skl_ops,
202};
203
204int skl_sst_dsp_init(struct device *dev, void __iomem *mmio_base, int irq,
205 struct skl_dsp_loader_ops dsp_ops, struct skl_sst **dsp)
206{
207 struct skl_sst *skl;
208 struct sst_dsp *sst;
209 int ret;
210
211 skl = devm_kzalloc(dev, sizeof(*skl), GFP_KERNEL);
212 if (skl == NULL)
213 return -ENOMEM;
214
215 skl->dev = dev;
216 skl_dev.thread_context = skl;
217
218 skl->dsp = skl_dsp_ctx_init(dev, &skl_dev, irq);
219 if (!skl->dsp) {
220 dev_err(skl->dev, "%s: no device\n", __func__);
221 return -ENODEV;
222 }
223
224 sst = skl->dsp;
225
226 sst->addr.lpe = mmio_base;
227 sst->addr.shim = mmio_base;
228 sst_dsp_mailbox_init(sst, (SKL_ADSP_SRAM0_BASE + SKL_ADSP_W0_STAT_SZ),
229 SKL_ADSP_W0_UP_SZ, SKL_ADSP_SRAM1_BASE, SKL_ADSP_W1_SZ);
230
231 sst->dsp_ops = dsp_ops;
232 sst->fw_ops = skl_fw_ops;
233
234 ret = skl_ipc_init(dev, skl);
235 if (ret)
236 return ret;
237
238 skl->boot_complete = false;
239 init_waitqueue_head(&skl->boot_wait);
240
241 ret = skl_dsp_boot(sst);
242 if (ret < 0) {
243 dev_err(skl->dev, "Boot dsp core failed ret: %d", ret);
244 goto free_ipc;
245 }
246
247 ret = skl_cldma_prepare(sst);
248 if (ret < 0) {
249 dev_err(dev, "CL dma prepare failed : %d", ret);
250 goto free_ipc;
251 }
252
253
254 ret = sst->fw_ops.load_fw(sst);
255 if (ret < 0) {
256 dev_err(dev, "Load base fw failed : %d", ret);
257 return ret;
258 }
259
260 if (dsp)
261 *dsp = skl;
262
263 return 0;
264
265free_ipc:
266 skl_ipc_free(&skl->ipc);
267 return ret;
268}
269EXPORT_SYMBOL_GPL(skl_sst_dsp_init);
270
271void skl_sst_dsp_cleanup(struct device *dev, struct skl_sst *ctx)
272{
273 skl_ipc_free(&ctx->ipc);
274 ctx->dsp->cl_dev.ops.cl_cleanup_controller(ctx->dsp);
275 ctx->dsp->ops->free(ctx->dsp);
276}
277EXPORT_SYMBOL_GPL(skl_sst_dsp_cleanup);
278
279MODULE_LICENSE("GPL v2");
280MODULE_DESCRIPTION("Intel Skylake IPC driver");
diff --git a/sound/soc/intel/skylake/skl-topology.h b/sound/soc/intel/skylake/skl-topology.h
new file mode 100644
index 000000000000..8c7767baa94f
--- /dev/null
+++ b/sound/soc/intel/skylake/skl-topology.h
@@ -0,0 +1,286 @@
1/*
2 * skl_topology.h - Intel HDA Platform topology header file
3 *
4 * Copyright (C) 2014-15 Intel Corp
5 * Author: Jeeja KP <jeeja.kp@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 *
19 */
20
21#ifndef __SKL_TOPOLOGY_H__
22#define __SKL_TOPOLOGY_H__
23
24#include <linux/types.h>
25
26#include <sound/hdaudio_ext.h>
27#include <sound/soc.h>
28#include "skl.h"
29#include "skl-tplg-interface.h"
30
31#define BITS_PER_BYTE 8
32#define MAX_TS_GROUPS 8
33#define MAX_DMIC_TS_GROUPS 4
34#define MAX_FIXED_DMIC_PARAMS_SIZE 727
35
36/* Maximum number of coefficients up down mixer module */
37#define UP_DOWN_MIXER_MAX_COEFF 6
38
39enum skl_channel_index {
40 SKL_CHANNEL_LEFT = 0,
41 SKL_CHANNEL_RIGHT = 1,
42 SKL_CHANNEL_CENTER = 2,
43 SKL_CHANNEL_LEFT_SURROUND = 3,
44 SKL_CHANNEL_CENTER_SURROUND = 3,
45 SKL_CHANNEL_RIGHT_SURROUND = 4,
46 SKL_CHANNEL_LFE = 7,
47 SKL_CHANNEL_INVALID = 0xF,
48};
49
50enum skl_bitdepth {
51 SKL_DEPTH_8BIT = 8,
52 SKL_DEPTH_16BIT = 16,
53 SKL_DEPTH_24BIT = 24,
54 SKL_DEPTH_32BIT = 32,
55 SKL_DEPTH_INVALID
56};
57
58enum skl_interleaving {
59 /* [s1_ch1...s1_chN,...,sM_ch1...sM_chN] */
60 SKL_INTERLEAVING_PER_CHANNEL = 0,
61 /* [s1_ch1...sM_ch1,...,s1_chN...sM_chN] */
62 SKL_INTERLEAVING_PER_SAMPLE = 1,
63};
64
65enum skl_s_freq {
66 SKL_FS_8000 = 8000,
67 SKL_FS_11025 = 11025,
68 SKL_FS_12000 = 12000,
69 SKL_FS_16000 = 16000,
70 SKL_FS_22050 = 22050,
71 SKL_FS_24000 = 24000,
72 SKL_FS_32000 = 32000,
73 SKL_FS_44100 = 44100,
74 SKL_FS_48000 = 48000,
75 SKL_FS_64000 = 64000,
76 SKL_FS_88200 = 88200,
77 SKL_FS_96000 = 96000,
78 SKL_FS_128000 = 128000,
79 SKL_FS_176400 = 176400,
80 SKL_FS_192000 = 192000,
81 SKL_FS_INVALID
82};
83
84enum skl_widget_type {
85 SKL_WIDGET_VMIXER = 1,
86 SKL_WIDGET_MIXER = 2,
87 SKL_WIDGET_PGA = 3,
88 SKL_WIDGET_MUX = 4
89};
90
91struct skl_audio_data_format {
92 enum skl_s_freq s_freq;
93 enum skl_bitdepth bit_depth;
94 u32 channel_map;
95 enum skl_ch_cfg ch_cfg;
96 enum skl_interleaving interleaving;
97 u8 number_of_channels;
98 u8 valid_bit_depth;
99 u8 sample_type;
100 u8 reserved[1];
101} __packed;
102
103struct skl_base_cfg {
104 u32 cps;
105 u32 ibs;
106 u32 obs;
107 u32 is_pages;
108 struct skl_audio_data_format audio_fmt;
109};
110
111struct skl_cpr_gtw_cfg {
112 u32 node_id;
113 u32 dma_buffer_size;
114 u32 config_length;
115 /* not mandatory; required only for DMIC/I2S */
116 u32 config_data[1];
117} __packed;
118
119struct skl_cpr_cfg {
120 struct skl_base_cfg base_cfg;
121 struct skl_audio_data_format out_fmt;
122 u32 cpr_feature_mask;
123 struct skl_cpr_gtw_cfg gtw_cfg;
124} __packed;
125
126
127struct skl_src_module_cfg {
128 struct skl_base_cfg base_cfg;
129 enum skl_s_freq src_cfg;
130} __packed;
131
132struct skl_up_down_mixer_cfg {
133 struct skl_base_cfg base_cfg;
134 enum skl_ch_cfg out_ch_cfg;
135 /* This should be set to 1 if user coefficients are required */
136 u32 coeff_sel;
137 /* Pass the user coeff in this array */
138 s32 coeff[UP_DOWN_MIXER_MAX_COEFF];
139} __packed;
140
141enum skl_dma_type {
142 SKL_DMA_HDA_HOST_OUTPUT_CLASS = 0,
143 SKL_DMA_HDA_HOST_INPUT_CLASS = 1,
144 SKL_DMA_HDA_HOST_INOUT_CLASS = 2,
145 SKL_DMA_HDA_LINK_OUTPUT_CLASS = 8,
146 SKL_DMA_HDA_LINK_INPUT_CLASS = 9,
147 SKL_DMA_HDA_LINK_INOUT_CLASS = 0xA,
148 SKL_DMA_DMIC_LINK_INPUT_CLASS = 0xB,
149 SKL_DMA_I2S_LINK_OUTPUT_CLASS = 0xC,
150 SKL_DMA_I2S_LINK_INPUT_CLASS = 0xD,
151};
152
153union skl_ssp_dma_node {
154 u8 val;
155 struct {
156 u8 dual_mono:1;
157 u8 time_slot:3;
158 u8 i2s_instance:4;
159 } dma_node;
160};
161
162union skl_connector_node_id {
163 u32 val;
164 struct {
165 u32 vindex:8;
166 u32 dma_type:4;
167 u32 rsvd:20;
168 } node;
169};
170
171struct skl_module_fmt {
172 u32 channels;
173 u32 s_freq;
174 u32 bit_depth;
175 u32 valid_bit_depth;
176 u32 ch_cfg;
177};
178
179struct skl_module_inst_id {
180 u32 module_id;
181 u32 instance_id;
182};
183
184struct skl_module_pin {
185 struct skl_module_inst_id id;
186 u8 pin_index;
187 bool is_dynamic;
188 bool in_use;
189};
190
191struct skl_specific_cfg {
192 u32 caps_size;
193 u32 *caps;
194};
195
196enum skl_pipe_state {
197 SKL_PIPE_INVALID = 0,
198 SKL_PIPE_CREATED = 1,
199 SKL_PIPE_PAUSED = 2,
200 SKL_PIPE_STARTED = 3
201};
202
203struct skl_pipe_module {
204 struct snd_soc_dapm_widget *w;
205 struct list_head node;
206};
207
208struct skl_pipe_params {
209 u8 host_dma_id;
210 u8 link_dma_id;
211 u32 ch;
212 u32 s_freq;
213 u32 s_fmt;
214 u8 linktype;
215 int stream;
216};
217
218struct skl_pipe {
219 u8 ppl_id;
220 u8 pipe_priority;
221 u16 conn_type;
222 u32 memory_pages;
223 struct skl_pipe_params *p_params;
224 enum skl_pipe_state state;
225 struct list_head w_list;
226};
227
228enum skl_module_state {
229 SKL_MODULE_UNINIT = 0,
230 SKL_MODULE_INIT_DONE = 1,
231 SKL_MODULE_LOADED = 2,
232 SKL_MODULE_UNLOADED = 3,
233 SKL_MODULE_BIND_DONE = 4
234};
235
236struct skl_module_cfg {
237 struct skl_module_inst_id id;
238 struct skl_module_fmt in_fmt;
239 struct skl_module_fmt out_fmt;
240 u8 max_in_queue;
241 u8 max_out_queue;
242 u8 in_queue_mask;
243 u8 out_queue_mask;
244 u8 in_queue;
245 u8 out_queue;
246 u32 mcps;
247 u32 ibs;
248 u32 obs;
249 u8 is_loadable;
250 u8 core_id;
251 u8 dev_type;
252 u8 dma_id;
253 u8 time_slot;
254 u32 params_fixup;
255 u32 converter;
256 u32 vbus_id;
257 struct skl_module_pin *m_in_pin;
258 struct skl_module_pin *m_out_pin;
259 enum skl_module_type m_type;
260 enum skl_hw_conn_type hw_conn_type;
261 enum skl_module_state m_state;
262 struct skl_pipe *pipe;
263 struct skl_specific_cfg formats_config;
264};
265
266int skl_create_pipeline(struct skl_sst *ctx, struct skl_pipe *pipe);
267
268int skl_run_pipe(struct skl_sst *ctx, struct skl_pipe *pipe);
269
270int skl_pause_pipe(struct skl_sst *ctx, struct skl_pipe *pipe);
271
272int skl_delete_pipe(struct skl_sst *ctx, struct skl_pipe *pipe);
273
274int skl_stop_pipe(struct skl_sst *ctx, struct skl_pipe *pipe);
275
276int skl_init_module(struct skl_sst *ctx, struct skl_module_cfg *module_config,
277 char *param);
278
279int skl_bind_modules(struct skl_sst *ctx, struct skl_module_cfg
280 *src_module, struct skl_module_cfg *dst_module);
281
282int skl_unbind_modules(struct skl_sst *ctx, struct skl_module_cfg
283 *src_module, struct skl_module_cfg *dst_module);
284
285enum skl_bitdepth skl_get_bit_depth(int params);
286#endif
diff --git a/sound/soc/intel/skylake/skl-tplg-interface.h b/sound/soc/intel/skylake/skl-tplg-interface.h
new file mode 100644
index 000000000000..a50689825bca
--- /dev/null
+++ b/sound/soc/intel/skylake/skl-tplg-interface.h
@@ -0,0 +1,88 @@
1/*
2 * skl-tplg-interface.h - Intel DSP FW private data interface
3 *
4 * Copyright (C) 2015 Intel Corp
5 * Author: Jeeja KP <jeeja.kp@intel.com>
6 * Nilofer, Samreen <samreen.nilofer@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 version 2, as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 */
18
19#ifndef __HDA_TPLG_INTERFACE_H__
20#define __HDA_TPLG_INTERFACE_H__
21
22/**
23 * enum skl_ch_cfg - channel configuration
24 *
25 * @SKL_CH_CFG_MONO: One channel only
26 * @SKL_CH_CFG_STEREO: L & R
27 * @SKL_CH_CFG_2_1: L, R & LFE
28 * @SKL_CH_CFG_3_0: L, C & R
29 * @SKL_CH_CFG_3_1: L, C, R & LFE
30 * @SKL_CH_CFG_QUATRO: L, R, Ls & Rs
31 * @SKL_CH_CFG_4_0: L, C, R & Cs
32 * @SKL_CH_CFG_5_0: L, C, R, Ls & Rs
33 * @SKL_CH_CFG_5_1: L, C, R, Ls, Rs & LFE
34 * @SKL_CH_CFG_DUAL_MONO: One channel replicated in two
35 * @SKL_CH_CFG_I2S_DUAL_STEREO_0: Stereo(L,R) in 4 slots, 1st stream:[ L, R, -, - ]
36 * @SKL_CH_CFG_I2S_DUAL_STEREO_1: Stereo(L,R) in 4 slots, 2nd stream:[ -, -, L, R ]
37 * @SKL_CH_CFG_INVALID: Invalid
38 */
39enum skl_ch_cfg {
40 SKL_CH_CFG_MONO = 0,
41 SKL_CH_CFG_STEREO = 1,
42 SKL_CH_CFG_2_1 = 2,
43 SKL_CH_CFG_3_0 = 3,
44 SKL_CH_CFG_3_1 = 4,
45 SKL_CH_CFG_QUATRO = 5,
46 SKL_CH_CFG_4_0 = 6,
47 SKL_CH_CFG_5_0 = 7,
48 SKL_CH_CFG_5_1 = 8,
49 SKL_CH_CFG_DUAL_MONO = 9,
50 SKL_CH_CFG_I2S_DUAL_STEREO_0 = 10,
51 SKL_CH_CFG_I2S_DUAL_STEREO_1 = 11,
52 SKL_CH_CFG_INVALID
53};
54
55enum skl_module_type {
56 SKL_MODULE_TYPE_MIXER = 0,
57 SKL_MODULE_TYPE_COPIER,
58 SKL_MODULE_TYPE_UPDWMIX,
59 SKL_MODULE_TYPE_SRCINT
60};
61
62enum skl_core_affinity {
63 SKL_AFFINITY_CORE_0 = 0,
64 SKL_AFFINITY_CORE_1,
65 SKL_AFFINITY_CORE_MAX
66};
67
68enum skl_pipe_conn_type {
69 SKL_PIPE_CONN_TYPE_NONE = 0,
70 SKL_PIPE_CONN_TYPE_FE,
71 SKL_PIPE_CONN_TYPE_BE
72};
73
74enum skl_hw_conn_type {
75 SKL_CONN_NONE = 0,
76 SKL_CONN_SOURCE = 1,
77 SKL_CONN_SINK = 2
78};
79
80enum skl_dev_type {
81 SKL_DEVICE_BT = 0x0,
82 SKL_DEVICE_DMIC = 0x1,
83 SKL_DEVICE_I2S = 0x2,
84 SKL_DEVICE_SLIMBUS = 0x3,
85 SKL_DEVICE_HDALINK = 0x4,
86 SKL_DEVICE_NONE
87};
88#endif
diff --git a/sound/soc/intel/skylake/skl.c b/sound/soc/intel/skylake/skl.c
new file mode 100644
index 000000000000..348d094e81d6
--- /dev/null
+++ b/sound/soc/intel/skylake/skl.c
@@ -0,0 +1,536 @@
1/*
2 * skl.c - Implementation of ASoC Intel SKL HD Audio driver
3 *
4 * Copyright (C) 2014-2015 Intel Corp
5 * Author: Jeeja KP <jeeja.kp@intel.com>
6 *
7 * Derived mostly from Intel HDA driver with following copyrights:
8 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
9 * PeiSen Hou <pshou@realtek.com.tw>
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; version 2 of the License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 */
23
24#include <linux/module.h>
25#include <linux/pci.h>
26#include <linux/pm_runtime.h>
27#include <linux/platform_device.h>
28#include <sound/pcm.h>
29#include "skl.h"
30
31/*
32 * initialize the PCI registers
33 */
34static void skl_update_pci_byte(struct pci_dev *pci, unsigned int reg,
35 unsigned char mask, unsigned char val)
36{
37 unsigned char data;
38
39 pci_read_config_byte(pci, reg, &data);
40 data &= ~mask;
41 data |= (val & mask);
42 pci_write_config_byte(pci, reg, data);
43}
44
45static void skl_init_pci(struct skl *skl)
46{
47 struct hdac_ext_bus *ebus = &skl->ebus;
48
49 /*
50 * Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
51 * TCSEL == Traffic Class Select Register, which sets PCI express QOS
52 * Ensuring these bits are 0 clears playback static on some HD Audio
53 * codecs.
54 * The PCI register TCSEL is defined in the Intel manuals.
55 */
56 dev_dbg(ebus_to_hbus(ebus)->dev, "Clearing TCSEL\n");
57 skl_update_pci_byte(skl->pci, AZX_PCIREG_TCSEL, 0x07, 0);
58}
59
60/* called from IRQ */
61static void skl_stream_update(struct hdac_bus *bus, struct hdac_stream *hstr)
62{
63 snd_pcm_period_elapsed(hstr->substream);
64}
65
66static irqreturn_t skl_interrupt(int irq, void *dev_id)
67{
68 struct hdac_ext_bus *ebus = dev_id;
69 struct hdac_bus *bus = ebus_to_hbus(ebus);
70 u32 status;
71
72 if (!pm_runtime_active(bus->dev))
73 return IRQ_NONE;
74
75 spin_lock(&bus->reg_lock);
76
77 status = snd_hdac_chip_readl(bus, INTSTS);
78 if (status == 0 || status == 0xffffffff) {
79 spin_unlock(&bus->reg_lock);
80 return IRQ_NONE;
81 }
82
83 /* clear rirb int */
84 status = snd_hdac_chip_readb(bus, RIRBSTS);
85 if (status & RIRB_INT_MASK) {
86 if (status & RIRB_INT_RESPONSE)
87 snd_hdac_bus_update_rirb(bus);
88 snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK);
89 }
90
91 spin_unlock(&bus->reg_lock);
92
93 return snd_hdac_chip_readl(bus, INTSTS) ? IRQ_WAKE_THREAD : IRQ_HANDLED;
94}
95
96static irqreturn_t skl_threaded_handler(int irq, void *dev_id)
97{
98 struct hdac_ext_bus *ebus = dev_id;
99 struct hdac_bus *bus = ebus_to_hbus(ebus);
100 u32 status;
101
102 status = snd_hdac_chip_readl(bus, INTSTS);
103
104 snd_hdac_bus_handle_stream_irq(bus, status, skl_stream_update);
105
106 return IRQ_HANDLED;
107}
108
109static int skl_acquire_irq(struct hdac_ext_bus *ebus, int do_disconnect)
110{
111 struct skl *skl = ebus_to_skl(ebus);
112 struct hdac_bus *bus = ebus_to_hbus(ebus);
113 int ret;
114
115 ret = request_threaded_irq(skl->pci->irq, skl_interrupt,
116 skl_threaded_handler,
117 IRQF_SHARED,
118 KBUILD_MODNAME, ebus);
119 if (ret) {
120 dev_err(bus->dev,
121 "unable to grab IRQ %d, disabling device\n",
122 skl->pci->irq);
123 return ret;
124 }
125
126 bus->irq = skl->pci->irq;
127 pci_intx(skl->pci, 1);
128
129 return 0;
130}
131
132#ifdef CONFIG_PM_SLEEP
133/*
134 * power management
135 */
136static int skl_suspend(struct device *dev)
137{
138 struct pci_dev *pci = to_pci_dev(dev);
139 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
140 struct hdac_bus *bus = ebus_to_hbus(ebus);
141
142 snd_hdac_bus_stop_chip(bus);
143 snd_hdac_bus_enter_link_reset(bus);
144
145 return 0;
146}
147
148static int skl_resume(struct device *dev)
149{
150 struct pci_dev *pci = to_pci_dev(dev);
151 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
152 struct hdac_bus *bus = ebus_to_hbus(ebus);
153 struct skl *hda = ebus_to_skl(ebus);
154
155 skl_init_pci(hda);
156
157 snd_hdac_bus_init_chip(bus, 1);
158
159 return 0;
160}
161#endif /* CONFIG_PM_SLEEP */
162
163#ifdef CONFIG_PM
164static int skl_runtime_suspend(struct device *dev)
165{
166 struct pci_dev *pci = to_pci_dev(dev);
167 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
168 struct hdac_bus *bus = ebus_to_hbus(ebus);
169
170 dev_dbg(bus->dev, "in %s\n", __func__);
171
172 /* enable controller wake up event */
173 snd_hdac_chip_updatew(bus, WAKEEN, 0, STATESTS_INT_MASK);
174
175 snd_hdac_bus_stop_chip(bus);
176 snd_hdac_bus_enter_link_reset(bus);
177
178 return 0;
179}
180
181static int skl_runtime_resume(struct device *dev)
182{
183 struct pci_dev *pci = to_pci_dev(dev);
184 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
185 struct hdac_bus *bus = ebus_to_hbus(ebus);
186 struct skl *hda = ebus_to_skl(ebus);
187 int status;
188
189 dev_dbg(bus->dev, "in %s\n", __func__);
190
191 /* Read STATESTS before controller reset */
192 status = snd_hdac_chip_readw(bus, STATESTS);
193
194 skl_init_pci(hda);
195 snd_hdac_bus_init_chip(bus, true);
196 /* disable controller Wake Up event */
197 snd_hdac_chip_updatew(bus, WAKEEN, STATESTS_INT_MASK, 0);
198
199 return 0;
200}
201#endif /* CONFIG_PM */
202
203static const struct dev_pm_ops skl_pm = {
204 SET_SYSTEM_SLEEP_PM_OPS(skl_suspend, skl_resume)
205 SET_RUNTIME_PM_OPS(skl_runtime_suspend, skl_runtime_resume, NULL)
206};
207
208/*
209 * destructor
210 */
211static int skl_free(struct hdac_ext_bus *ebus)
212{
213 struct skl *skl = ebus_to_skl(ebus);
214 struct hdac_bus *bus = ebus_to_hbus(ebus);
215
216 skl->init_failed = 1; /* to be sure */
217
218 snd_hdac_ext_stop_streams(ebus);
219
220 if (bus->irq >= 0)
221 free_irq(bus->irq, (void *)bus);
222 if (bus->remap_addr)
223 iounmap(bus->remap_addr);
224
225 snd_hdac_bus_free_stream_pages(bus);
226 snd_hdac_stream_free_all(ebus);
227 snd_hdac_link_free_all(ebus);
228 pci_release_regions(skl->pci);
229 pci_disable_device(skl->pci);
230
231 snd_hdac_ext_bus_exit(ebus);
232
233 return 0;
234}
235
236static int skl_dmic_device_register(struct skl *skl)
237{
238 struct hdac_bus *bus = ebus_to_hbus(&skl->ebus);
239 struct platform_device *pdev;
240 int ret;
241
242 /* SKL has one dmic port, so allocate dmic device for this */
243 pdev = platform_device_alloc("dmic-codec", -1);
244 if (!pdev) {
245 dev_err(bus->dev, "failed to allocate dmic device\n");
246 return -ENOMEM;
247 }
248
249 ret = platform_device_add(pdev);
250 if (ret) {
251 dev_err(bus->dev, "failed to add dmic device: %d\n", ret);
252 platform_device_put(pdev);
253 return ret;
254 }
255 skl->dmic_dev = pdev;
256
257 return 0;
258}
259
260static void skl_dmic_device_unregister(struct skl *skl)
261{
262 if (skl->dmic_dev)
263 platform_device_unregister(skl->dmic_dev);
264}
265
266/*
267 * Probe the given codec address
268 */
269static int probe_codec(struct hdac_ext_bus *ebus, int addr)
270{
271 struct hdac_bus *bus = ebus_to_hbus(ebus);
272 unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
273 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
274 unsigned int res;
275
276 mutex_lock(&bus->cmd_mutex);
277 snd_hdac_bus_send_cmd(bus, cmd);
278 snd_hdac_bus_get_response(bus, addr, &res);
279 mutex_unlock(&bus->cmd_mutex);
280 if (res == -1)
281 return -EIO;
282 dev_dbg(bus->dev, "codec #%d probed OK\n", addr);
283
284 return snd_hdac_ext_bus_device_init(ebus, addr);
285}
286
287/* Codec initialization */
288static int skl_codec_create(struct hdac_ext_bus *ebus)
289{
290 struct hdac_bus *bus = ebus_to_hbus(ebus);
291 int c, max_slots;
292
293 max_slots = HDA_MAX_CODECS;
294
295 /* First try to probe all given codec slots */
296 for (c = 0; c < max_slots; c++) {
297 if ((bus->codec_mask & (1 << c))) {
298 if (probe_codec(ebus, c) < 0) {
299 /*
300 * Some BIOSen give you wrong codec addresses
301 * that don't exist
302 */
303 dev_warn(bus->dev,
304 "Codec #%d probe error; disabling it...\n", c);
305 bus->codec_mask &= ~(1 << c);
306 /*
307 * More badly, accessing to a non-existing
308 * codec often screws up the controller bus,
309 * and disturbs the further communications.
310 * Thus if an error occurs during probing,
311 * better to reset the controller bus to get
312 * back to the sanity state.
313 */
314 snd_hdac_bus_stop_chip(bus);
315 snd_hdac_bus_init_chip(bus, true);
316 }
317 }
318 }
319
320 return 0;
321}
322
323static const struct hdac_bus_ops bus_core_ops = {
324 .command = snd_hdac_bus_send_cmd,
325 .get_response = snd_hdac_bus_get_response,
326};
327
328/*
329 * constructor
330 */
331static int skl_create(struct pci_dev *pci,
332 const struct hdac_io_ops *io_ops,
333 struct skl **rskl)
334{
335 struct skl *skl;
336 struct hdac_ext_bus *ebus;
337
338 int err;
339
340 *rskl = NULL;
341
342 err = pci_enable_device(pci);
343 if (err < 0)
344 return err;
345
346 skl = devm_kzalloc(&pci->dev, sizeof(*skl), GFP_KERNEL);
347 if (!skl) {
348 pci_disable_device(pci);
349 return -ENOMEM;
350 }
351 ebus = &skl->ebus;
352 snd_hdac_ext_bus_init(ebus, &pci->dev, &bus_core_ops, io_ops);
353 ebus->bus.use_posbuf = 1;
354 skl->pci = pci;
355
356 ebus->bus.bdl_pos_adj = 0;
357
358 *rskl = skl;
359
360 return 0;
361}
362
363static int skl_first_init(struct hdac_ext_bus *ebus)
364{
365 struct skl *skl = ebus_to_skl(ebus);
366 struct hdac_bus *bus = ebus_to_hbus(ebus);
367 struct pci_dev *pci = skl->pci;
368 int err;
369 unsigned short gcap;
370 int cp_streams, pb_streams, start_idx;
371
372 err = pci_request_regions(pci, "Skylake HD audio");
373 if (err < 0)
374 return err;
375
376 bus->addr = pci_resource_start(pci, 0);
377 bus->remap_addr = pci_ioremap_bar(pci, 0);
378 if (bus->remap_addr == NULL) {
379 dev_err(bus->dev, "ioremap error\n");
380 return -ENXIO;
381 }
382
383 snd_hdac_ext_bus_parse_capabilities(ebus);
384
385 if (skl_acquire_irq(ebus, 0) < 0)
386 return -EBUSY;
387
388 pci_set_master(pci);
389 synchronize_irq(bus->irq);
390
391 gcap = snd_hdac_chip_readw(bus, GCAP);
392 dev_dbg(bus->dev, "chipset global capabilities = 0x%x\n", gcap);
393
394 /* allow 64bit DMA address if supported by H/W */
395 if (!dma_set_mask(bus->dev, DMA_BIT_MASK(64))) {
396 dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(64));
397 } else {
398 dma_set_mask(bus->dev, DMA_BIT_MASK(32));
399 dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(32));
400 }
401
402 /* read number of streams from GCAP register */
403 cp_streams = (gcap >> 8) & 0x0f;
404 pb_streams = (gcap >> 12) & 0x0f;
405
406 if (!pb_streams && !cp_streams)
407 return -EIO;
408
409 ebus->num_streams = cp_streams + pb_streams;
410
411 /* initialize streams */
412 snd_hdac_ext_stream_init_all
413 (ebus, 0, cp_streams, SNDRV_PCM_STREAM_CAPTURE);
414 start_idx = cp_streams;
415 snd_hdac_ext_stream_init_all
416 (ebus, start_idx, pb_streams, SNDRV_PCM_STREAM_PLAYBACK);
417
418 err = snd_hdac_bus_alloc_stream_pages(bus);
419 if (err < 0)
420 return err;
421
422 /* initialize chip */
423 skl_init_pci(skl);
424
425 snd_hdac_bus_init_chip(bus, true);
426
427 /* codec detection */
428 if (!bus->codec_mask) {
429 dev_err(bus->dev, "no codecs found!\n");
430 return -ENODEV;
431 }
432
433 return 0;
434}
435
436static int skl_probe(struct pci_dev *pci,
437 const struct pci_device_id *pci_id)
438{
439 struct skl *skl;
440 struct hdac_ext_bus *ebus = NULL;
441 struct hdac_bus *bus = NULL;
442 int err;
443
444 /* we use ext core ops, so provide NULL for ops here */
445 err = skl_create(pci, NULL, &skl);
446 if (err < 0)
447 return err;
448
449 ebus = &skl->ebus;
450 bus = ebus_to_hbus(ebus);
451
452 err = skl_first_init(ebus);
453 if (err < 0)
454 goto out_free;
455
456 pci_set_drvdata(skl->pci, ebus);
457
458 /* check if dsp is there */
459 if (ebus->ppcap) {
460 /* TODO register with dsp IPC */
461 dev_dbg(bus->dev, "Register dsp\n");
462 }
463
464 if (ebus->mlcap)
465 snd_hdac_ext_bus_get_ml_capabilities(ebus);
466
467 /* create device for soc dmic */
468 err = skl_dmic_device_register(skl);
469 if (err < 0)
470 goto out_free;
471
472 /* register platform dai and controls */
473 err = skl_platform_register(bus->dev);
474 if (err < 0)
475 goto out_dmic_free;
476
477 /* create codec instances */
478 err = skl_codec_create(ebus);
479 if (err < 0)
480 goto out_unregister;
481
482 /*configure PM */
483 pm_runtime_set_autosuspend_delay(bus->dev, SKL_SUSPEND_DELAY);
484 pm_runtime_use_autosuspend(bus->dev);
485 pm_runtime_put_noidle(bus->dev);
486 pm_runtime_allow(bus->dev);
487
488 return 0;
489
490out_unregister:
491 skl_platform_unregister(bus->dev);
492out_dmic_free:
493 skl_dmic_device_unregister(skl);
494out_free:
495 skl->init_failed = 1;
496 skl_free(ebus);
497
498 return err;
499}
500
501static void skl_remove(struct pci_dev *pci)
502{
503 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
504 struct skl *skl = ebus_to_skl(ebus);
505
506 if (pci_dev_run_wake(pci))
507 pm_runtime_get_noresume(&pci->dev);
508 pci_dev_put(pci);
509 skl_platform_unregister(&pci->dev);
510 skl_dmic_device_unregister(skl);
511 skl_free(ebus);
512 dev_set_drvdata(&pci->dev, NULL);
513}
514
515/* PCI IDs */
516static const struct pci_device_id skl_ids[] = {
517 /* Sunrise Point-LP */
518 { PCI_DEVICE(0x8086, 0x9d70), 0},
519 { 0, }
520};
521MODULE_DEVICE_TABLE(pci, skl_ids);
522
523/* pci_driver definition */
524static struct pci_driver skl_driver = {
525 .name = KBUILD_MODNAME,
526 .id_table = skl_ids,
527 .probe = skl_probe,
528 .remove = skl_remove,
529 .driver = {
530 .pm = &skl_pm,
531 },
532};
533module_pci_driver(skl_driver);
534
535MODULE_LICENSE("GPL v2");
536MODULE_DESCRIPTION("Intel Skylake ASoC HDA driver");
diff --git a/sound/soc/intel/skylake/skl.h b/sound/soc/intel/skylake/skl.h
new file mode 100644
index 000000000000..f7fdbb02947f
--- /dev/null
+++ b/sound/soc/intel/skylake/skl.h
@@ -0,0 +1,84 @@
1/*
2 * skl.h - HD Audio skylake defintions.
3 *
4 * Copyright (C) 2015 Intel Corp
5 * Author: Jeeja KP <jeeja.kp@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 *
19 */
20
21#ifndef __SOUND_SOC_SKL_H
22#define __SOUND_SOC_SKL_H
23
24#include <sound/hda_register.h>
25#include <sound/hdaudio_ext.h>
26#include "skl-nhlt.h"
27
28#define SKL_SUSPEND_DELAY 2000
29
30/* Vendor Specific Registers */
31#define AZX_REG_VS_EM1 0x1000
32#define AZX_REG_VS_INRC 0x1004
33#define AZX_REG_VS_OUTRC 0x1008
34#define AZX_REG_VS_FIFOTRK 0x100C
35#define AZX_REG_VS_FIFOTRK2 0x1010
36#define AZX_REG_VS_EM2 0x1030
37#define AZX_REG_VS_EM3L 0x1038
38#define AZX_REG_VS_EM3U 0x103C
39#define AZX_REG_VS_EM4L 0x1040
40#define AZX_REG_VS_EM4U 0x1044
41#define AZX_REG_VS_LTRC 0x1048
42#define AZX_REG_VS_D0I3C 0x104A
43#define AZX_REG_VS_PCE 0x104B
44#define AZX_REG_VS_L2MAGC 0x1050
45#define AZX_REG_VS_L2LAHPT 0x1054
46#define AZX_REG_VS_SDXDPIB_XBASE 0x1084
47#define AZX_REG_VS_SDXDPIB_XINTERVAL 0x20
48#define AZX_REG_VS_SDXEFIFOS_XBASE 0x1094
49#define AZX_REG_VS_SDXEFIFOS_XINTERVAL 0x20
50
51struct skl {
52 struct hdac_ext_bus ebus;
53 struct pci_dev *pci;
54
55 unsigned int init_failed:1; /* delayed init failed */
56 struct platform_device *dmic_dev;
57
58 void __iomem *nhlt; /* nhlt ptr */
59 struct skl_sst *skl_sst; /* sst skl ctx */
60};
61
62#define skl_to_ebus(s) (&(s)->ebus)
63#define ebus_to_skl(sbus) \
64 container_of(sbus, struct skl, sbus)
65
66/* to pass dai dma data */
67struct skl_dma_params {
68 u32 format;
69 u8 stream_tag;
70};
71
72int skl_platform_unregister(struct device *dev);
73int skl_platform_register(struct device *dev);
74
75void __iomem *skl_nhlt_init(struct device *dev);
76void skl_nhlt_free(void __iomem *addr);
77struct nhlt_specific_cfg *skl_get_ep_blob(struct skl *skl, u32 instance,
78 u8 link_type, u8 s_fmt, u8 no_ch, u32 s_rate, u8 dirn);
79
80int skl_init_dsp(struct skl *skl);
81void skl_free_dsp(struct skl *skl);
82int skl_suspend_dsp(struct skl *skl);
83int skl_resume_dsp(struct skl *skl);
84#endif /* __SOUND_SOC_SKL_H */
diff --git a/sound/soc/kirkwood/kirkwood-dma.c b/sound/soc/kirkwood/kirkwood-dma.c
index 4cf2245950d7..dbfdfe99c69d 100644
--- a/sound/soc/kirkwood/kirkwood-dma.c
+++ b/sound/soc/kirkwood/kirkwood-dma.c
@@ -148,10 +148,14 @@ static int kirkwood_dma_open(struct snd_pcm_substream *substream)
148 dram = mv_mbus_dram_info(); 148 dram = mv_mbus_dram_info();
149 addr = substream->dma_buffer.addr; 149 addr = substream->dma_buffer.addr;
150 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 150 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
151 if (priv->substream_play)
152 return -EBUSY;
151 priv->substream_play = substream; 153 priv->substream_play = substream;
152 kirkwood_dma_conf_mbus_windows(priv->io, 154 kirkwood_dma_conf_mbus_windows(priv->io,
153 KIRKWOOD_PLAYBACK_WIN, addr, dram); 155 KIRKWOOD_PLAYBACK_WIN, addr, dram);
154 } else { 156 } else {
157 if (priv->substream_rec)
158 return -EBUSY;
155 priv->substream_rec = substream; 159 priv->substream_rec = substream;
156 kirkwood_dma_conf_mbus_windows(priv->io, 160 kirkwood_dma_conf_mbus_windows(priv->io,
157 KIRKWOOD_RECORD_WIN, addr, dram); 161 KIRKWOOD_RECORD_WIN, addr, dram);
diff --git a/sound/soc/mediatek/mt8173-max98090.c b/sound/soc/mediatek/mt8173-max98090.c
index 4d44b5803e55..684e8a78bed0 100644
--- a/sound/soc/mediatek/mt8173-max98090.c
+++ b/sound/soc/mediatek/mt8173-max98090.c
@@ -103,7 +103,6 @@ static struct snd_soc_dai_link mt8173_max98090_dais[] = {
103 .name = "MAX98090 Playback", 103 .name = "MAX98090 Playback",
104 .stream_name = "MAX98090 Playback", 104 .stream_name = "MAX98090 Playback",
105 .cpu_dai_name = "DL1", 105 .cpu_dai_name = "DL1",
106 .platform_name = "11220000.mt8173-afe-pcm",
107 .codec_name = "snd-soc-dummy", 106 .codec_name = "snd-soc-dummy",
108 .codec_dai_name = "snd-soc-dummy-dai", 107 .codec_dai_name = "snd-soc-dummy-dai",
109 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 108 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
@@ -114,7 +113,6 @@ static struct snd_soc_dai_link mt8173_max98090_dais[] = {
114 .name = "MAX98090 Capture", 113 .name = "MAX98090 Capture",
115 .stream_name = "MAX98090 Capture", 114 .stream_name = "MAX98090 Capture",
116 .cpu_dai_name = "VUL", 115 .cpu_dai_name = "VUL",
117 .platform_name = "11220000.mt8173-afe-pcm",
118 .codec_name = "snd-soc-dummy", 116 .codec_name = "snd-soc-dummy",
119 .codec_dai_name = "snd-soc-dummy-dai", 117 .codec_dai_name = "snd-soc-dummy-dai",
120 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 118 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
@@ -125,7 +123,6 @@ static struct snd_soc_dai_link mt8173_max98090_dais[] = {
125 { 123 {
126 .name = "Codec", 124 .name = "Codec",
127 .cpu_dai_name = "I2S", 125 .cpu_dai_name = "I2S",
128 .platform_name = "11220000.mt8173-afe-pcm",
129 .no_pcm = 1, 126 .no_pcm = 1,
130 .codec_dai_name = "HiFi", 127 .codec_dai_name = "HiFi",
131 .init = mt8173_max98090_init, 128 .init = mt8173_max98090_init,
@@ -139,6 +136,7 @@ static struct snd_soc_dai_link mt8173_max98090_dais[] = {
139 136
140static struct snd_soc_card mt8173_max98090_card = { 137static struct snd_soc_card mt8173_max98090_card = {
141 .name = "mt8173-max98090", 138 .name = "mt8173-max98090",
139 .owner = THIS_MODULE,
142 .dai_link = mt8173_max98090_dais, 140 .dai_link = mt8173_max98090_dais,
143 .num_links = ARRAY_SIZE(mt8173_max98090_dais), 141 .num_links = ARRAY_SIZE(mt8173_max98090_dais),
144 .controls = mt8173_max98090_controls, 142 .controls = mt8173_max98090_controls,
@@ -152,9 +150,21 @@ static struct snd_soc_card mt8173_max98090_card = {
152static int mt8173_max98090_dev_probe(struct platform_device *pdev) 150static int mt8173_max98090_dev_probe(struct platform_device *pdev)
153{ 151{
154 struct snd_soc_card *card = &mt8173_max98090_card; 152 struct snd_soc_card *card = &mt8173_max98090_card;
155 struct device_node *codec_node; 153 struct device_node *codec_node, *platform_node;
156 int ret, i; 154 int ret, i;
157 155
156 platform_node = of_parse_phandle(pdev->dev.of_node,
157 "mediatek,platform", 0);
158 if (!platform_node) {
159 dev_err(&pdev->dev, "Property 'platform' missing or invalid\n");
160 return -EINVAL;
161 }
162 for (i = 0; i < card->num_links; i++) {
163 if (mt8173_max98090_dais[i].platform_name)
164 continue;
165 mt8173_max98090_dais[i].platform_of_node = platform_node;
166 }
167
158 codec_node = of_parse_phandle(pdev->dev.of_node, 168 codec_node = of_parse_phandle(pdev->dev.of_node,
159 "mediatek,audio-codec", 0); 169 "mediatek,audio-codec", 0);
160 if (!codec_node) { 170 if (!codec_node) {
@@ -193,7 +203,6 @@ MODULE_DEVICE_TABLE(of, mt8173_max98090_dt_match);
193static struct platform_driver mt8173_max98090_driver = { 203static struct platform_driver mt8173_max98090_driver = {
194 .driver = { 204 .driver = {
195 .name = "mt8173-max98090", 205 .name = "mt8173-max98090",
196 .owner = THIS_MODULE,
197 .of_match_table = mt8173_max98090_dt_match, 206 .of_match_table = mt8173_max98090_dt_match,
198#ifdef CONFIG_PM 207#ifdef CONFIG_PM
199 .pm = &snd_soc_pm_ops, 208 .pm = &snd_soc_pm_ops,
diff --git a/sound/soc/mediatek/mt8173-rt5650-rt5676.c b/sound/soc/mediatek/mt8173-rt5650-rt5676.c
index 094055323059..86cf9752f18a 100644
--- a/sound/soc/mediatek/mt8173-rt5650-rt5676.c
+++ b/sound/soc/mediatek/mt8173-rt5650-rt5676.c
@@ -138,7 +138,6 @@ static struct snd_soc_dai_link mt8173_rt5650_rt5676_dais[] = {
138 .name = "rt5650_rt5676 Playback", 138 .name = "rt5650_rt5676 Playback",
139 .stream_name = "rt5650_rt5676 Playback", 139 .stream_name = "rt5650_rt5676 Playback",
140 .cpu_dai_name = "DL1", 140 .cpu_dai_name = "DL1",
141 .platform_name = "11220000.mt8173-afe-pcm",
142 .codec_name = "snd-soc-dummy", 141 .codec_name = "snd-soc-dummy",
143 .codec_dai_name = "snd-soc-dummy-dai", 142 .codec_dai_name = "snd-soc-dummy-dai",
144 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 143 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
@@ -149,7 +148,6 @@ static struct snd_soc_dai_link mt8173_rt5650_rt5676_dais[] = {
149 .name = "rt5650_rt5676 Capture", 148 .name = "rt5650_rt5676 Capture",
150 .stream_name = "rt5650_rt5676 Capture", 149 .stream_name = "rt5650_rt5676 Capture",
151 .cpu_dai_name = "VUL", 150 .cpu_dai_name = "VUL",
152 .platform_name = "11220000.mt8173-afe-pcm",
153 .codec_name = "snd-soc-dummy", 151 .codec_name = "snd-soc-dummy",
154 .codec_dai_name = "snd-soc-dummy-dai", 152 .codec_dai_name = "snd-soc-dummy-dai",
155 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST}, 153 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
@@ -161,7 +159,6 @@ static struct snd_soc_dai_link mt8173_rt5650_rt5676_dais[] = {
161 { 159 {
162 .name = "Codec", 160 .name = "Codec",
163 .cpu_dai_name = "I2S", 161 .cpu_dai_name = "I2S",
164 .platform_name = "11220000.mt8173-afe-pcm",
165 .no_pcm = 1, 162 .no_pcm = 1,
166 .codecs = mt8173_rt5650_rt5676_codecs, 163 .codecs = mt8173_rt5650_rt5676_codecs,
167 .num_codecs = 2, 164 .num_codecs = 2,
@@ -194,6 +191,7 @@ static struct snd_soc_codec_conf mt8173_rt5650_rt5676_codec_conf[] = {
194 191
195static struct snd_soc_card mt8173_rt5650_rt5676_card = { 192static struct snd_soc_card mt8173_rt5650_rt5676_card = {
196 .name = "mtk-rt5650-rt5676", 193 .name = "mtk-rt5650-rt5676",
194 .owner = THIS_MODULE,
197 .dai_link = mt8173_rt5650_rt5676_dais, 195 .dai_link = mt8173_rt5650_rt5676_dais,
198 .num_links = ARRAY_SIZE(mt8173_rt5650_rt5676_dais), 196 .num_links = ARRAY_SIZE(mt8173_rt5650_rt5676_dais),
199 .codec_conf = mt8173_rt5650_rt5676_codec_conf, 197 .codec_conf = mt8173_rt5650_rt5676_codec_conf,
@@ -209,7 +207,21 @@ static struct snd_soc_card mt8173_rt5650_rt5676_card = {
209static int mt8173_rt5650_rt5676_dev_probe(struct platform_device *pdev) 207static int mt8173_rt5650_rt5676_dev_probe(struct platform_device *pdev)
210{ 208{
211 struct snd_soc_card *card = &mt8173_rt5650_rt5676_card; 209 struct snd_soc_card *card = &mt8173_rt5650_rt5676_card;
212 int ret; 210 struct device_node *platform_node;
211 int i, ret;
212
213 platform_node = of_parse_phandle(pdev->dev.of_node,
214 "mediatek,platform", 0);
215 if (!platform_node) {
216 dev_err(&pdev->dev, "Property 'platform' missing or invalid\n");
217 return -EINVAL;
218 }
219
220 for (i = 0; i < card->num_links; i++) {
221 if (mt8173_rt5650_rt5676_dais[i].platform_name)
222 continue;
223 mt8173_rt5650_rt5676_dais[i].platform_of_node = platform_node;
224 }
213 225
214 mt8173_rt5650_rt5676_codecs[0].of_node = 226 mt8173_rt5650_rt5676_codecs[0].of_node =
215 of_parse_phandle(pdev->dev.of_node, "mediatek,audio-codec", 0); 227 of_parse_phandle(pdev->dev.of_node, "mediatek,audio-codec", 0);
@@ -258,7 +270,6 @@ MODULE_DEVICE_TABLE(of, mt8173_rt5650_rt5676_dt_match);
258static struct platform_driver mt8173_rt5650_rt5676_driver = { 270static struct platform_driver mt8173_rt5650_rt5676_driver = {
259 .driver = { 271 .driver = {
260 .name = "mtk-rt5650-rt5676", 272 .name = "mtk-rt5650-rt5676",
261 .owner = THIS_MODULE,
262 .of_match_table = mt8173_rt5650_rt5676_dt_match, 273 .of_match_table = mt8173_rt5650_rt5676_dt_match,
263#ifdef CONFIG_PM 274#ifdef CONFIG_PM
264 .pm = &snd_soc_pm_ops, 275 .pm = &snd_soc_pm_ops,
diff --git a/sound/soc/mediatek/mtk-afe-common.h b/sound/soc/mediatek/mtk-afe-common.h
index a88b17511fdf..cc4393cb1130 100644
--- a/sound/soc/mediatek/mtk-afe-common.h
+++ b/sound/soc/mediatek/mtk-afe-common.h
@@ -98,12 +98,4 @@ struct mtk_afe_memif {
98 const struct mtk_afe_irq_data *irqdata; 98 const struct mtk_afe_irq_data *irqdata;
99}; 99};
100 100
101struct mtk_afe {
102 /* address for ioremap audio hardware register */
103 void __iomem *base_addr;
104 struct device *dev;
105 struct regmap *regmap;
106 struct mtk_afe_memif memif[MTK_AFE_MEMIF_NUM];
107 struct clk *clocks[MTK_CLK_NUM];
108};
109#endif 101#endif
diff --git a/sound/soc/mediatek/mtk-afe-pcm.c b/sound/soc/mediatek/mtk-afe-pcm.c
index cc228db5fb76..d190fe017559 100644
--- a/sound/soc/mediatek/mtk-afe-pcm.c
+++ b/sound/soc/mediatek/mtk-afe-pcm.c
@@ -45,18 +45,21 @@
45/* Memory interface */ 45/* Memory interface */
46#define AFE_DL1_BASE 0x0040 46#define AFE_DL1_BASE 0x0040
47#define AFE_DL1_CUR 0x0044 47#define AFE_DL1_CUR 0x0044
48#define AFE_DL1_END 0x0048
48#define AFE_DL2_BASE 0x0050 49#define AFE_DL2_BASE 0x0050
49#define AFE_DL2_CUR 0x0054 50#define AFE_DL2_CUR 0x0054
50#define AFE_AWB_BASE 0x0070 51#define AFE_AWB_BASE 0x0070
51#define AFE_AWB_CUR 0x007c 52#define AFE_AWB_CUR 0x007c
52#define AFE_VUL_BASE 0x0080 53#define AFE_VUL_BASE 0x0080
53#define AFE_VUL_CUR 0x008c 54#define AFE_VUL_CUR 0x008c
55#define AFE_VUL_END 0x0088
54#define AFE_DAI_BASE 0x0090 56#define AFE_DAI_BASE 0x0090
55#define AFE_DAI_CUR 0x009c 57#define AFE_DAI_CUR 0x009c
56#define AFE_MOD_PCM_BASE 0x0330 58#define AFE_MOD_PCM_BASE 0x0330
57#define AFE_MOD_PCM_CUR 0x033c 59#define AFE_MOD_PCM_CUR 0x033c
58#define AFE_HDMI_OUT_BASE 0x0374 60#define AFE_HDMI_OUT_BASE 0x0374
59#define AFE_HDMI_OUT_CUR 0x0378 61#define AFE_HDMI_OUT_CUR 0x0378
62#define AFE_HDMI_OUT_END 0x037c
60 63
61#define AFE_ADDA2_TOP_CON0 0x0600 64#define AFE_ADDA2_TOP_CON0 0x0600
62 65
@@ -127,6 +130,34 @@ enum afe_tdm_ch_start {
127 AFE_TDM_CH_ZERO, 130 AFE_TDM_CH_ZERO,
128}; 131};
129 132
133static const unsigned int mtk_afe_backup_list[] = {
134 AUDIO_TOP_CON0,
135 AFE_CONN1,
136 AFE_CONN2,
137 AFE_CONN7,
138 AFE_CONN8,
139 AFE_DAC_CON1,
140 AFE_DL1_BASE,
141 AFE_DL1_END,
142 AFE_VUL_BASE,
143 AFE_VUL_END,
144 AFE_HDMI_OUT_BASE,
145 AFE_HDMI_OUT_END,
146 AFE_HDMI_CONN0,
147 AFE_DAC_CON0,
148};
149
150struct mtk_afe {
151 /* address for ioremap audio hardware register */
152 void __iomem *base_addr;
153 struct device *dev;
154 struct regmap *regmap;
155 struct mtk_afe_memif memif[MTK_AFE_MEMIF_NUM];
156 struct clk *clocks[MTK_CLK_NUM];
157 unsigned int backup_regs[ARRAY_SIZE(mtk_afe_backup_list)];
158 bool suspended;
159};
160
130static const struct snd_pcm_hardware mtk_afe_hardware = { 161static const struct snd_pcm_hardware mtk_afe_hardware = {
131 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 162 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
132 SNDRV_PCM_INFO_MMAP_VALID), 163 SNDRV_PCM_INFO_MMAP_VALID),
@@ -722,11 +753,53 @@ static const struct snd_soc_dai_ops mtk_afe_hdmi_ops = {
722 753
723}; 754};
724 755
756static int mtk_afe_runtime_suspend(struct device *dev);
757static int mtk_afe_runtime_resume(struct device *dev);
758
759static int mtk_afe_dai_suspend(struct snd_soc_dai *dai)
760{
761 struct mtk_afe *afe = snd_soc_dai_get_drvdata(dai);
762 int i;
763
764 dev_dbg(afe->dev, "%s\n", __func__);
765 if (pm_runtime_status_suspended(afe->dev) || afe->suspended)
766 return 0;
767
768 for (i = 0; i < ARRAY_SIZE(mtk_afe_backup_list); i++)
769 regmap_read(afe->regmap, mtk_afe_backup_list[i],
770 &afe->backup_regs[i]);
771
772 afe->suspended = true;
773 mtk_afe_runtime_suspend(afe->dev);
774 return 0;
775}
776
777static int mtk_afe_dai_resume(struct snd_soc_dai *dai)
778{
779 struct mtk_afe *afe = snd_soc_dai_get_drvdata(dai);
780 int i = 0;
781
782 dev_dbg(afe->dev, "%s\n", __func__);
783 if (pm_runtime_status_suspended(afe->dev) || !afe->suspended)
784 return 0;
785
786 mtk_afe_runtime_resume(afe->dev);
787
788 for (i = 0; i < ARRAY_SIZE(mtk_afe_backup_list); i++)
789 regmap_write(afe->regmap, mtk_afe_backup_list[i],
790 afe->backup_regs[i]);
791
792 afe->suspended = false;
793 return 0;
794}
795
725static struct snd_soc_dai_driver mtk_afe_pcm_dais[] = { 796static struct snd_soc_dai_driver mtk_afe_pcm_dais[] = {
726 /* FE DAIs: memory intefaces to CPU */ 797 /* FE DAIs: memory intefaces to CPU */
727 { 798 {
728 .name = "DL1", /* downlink 1 */ 799 .name = "DL1", /* downlink 1 */
729 .id = MTK_AFE_MEMIF_DL1, 800 .id = MTK_AFE_MEMIF_DL1,
801 .suspend = mtk_afe_dai_suspend,
802 .resume = mtk_afe_dai_resume,
730 .playback = { 803 .playback = {
731 .stream_name = "DL1", 804 .stream_name = "DL1",
732 .channels_min = 1, 805 .channels_min = 1,
@@ -738,6 +811,8 @@ static struct snd_soc_dai_driver mtk_afe_pcm_dais[] = {
738 }, { 811 }, {
739 .name = "VUL", /* voice uplink */ 812 .name = "VUL", /* voice uplink */
740 .id = MTK_AFE_MEMIF_VUL, 813 .id = MTK_AFE_MEMIF_VUL,
814 .suspend = mtk_afe_dai_suspend,
815 .resume = mtk_afe_dai_resume,
741 .capture = { 816 .capture = {
742 .stream_name = "VUL", 817 .stream_name = "VUL",
743 .channels_min = 1, 818 .channels_min = 1,
@@ -774,6 +849,8 @@ static struct snd_soc_dai_driver mtk_afe_hdmi_dais[] = {
774 { 849 {
775 .name = "HDMI", 850 .name = "HDMI",
776 .id = MTK_AFE_MEMIF_HDMI, 851 .id = MTK_AFE_MEMIF_HDMI,
852 .suspend = mtk_afe_dai_suspend,
853 .resume = mtk_afe_dai_resume,
777 .playback = { 854 .playback = {
778 .stream_name = "HDMI", 855 .stream_name = "HDMI",
779 .channels_min = 2, 856 .channels_min = 2,
@@ -820,10 +897,6 @@ static const struct snd_kcontrol_new mtk_afe_o10_mix[] = {
820}; 897};
821 898
822static const struct snd_soc_dapm_widget mtk_afe_pcm_widgets[] = { 899static const struct snd_soc_dapm_widget mtk_afe_pcm_widgets[] = {
823 /* Backend DAIs */
824 SND_SOC_DAPM_AIF_IN("I2S Capture", NULL, 0, SND_SOC_NOPM, 0, 0),
825 SND_SOC_DAPM_AIF_OUT("I2S Playback", NULL, 0, SND_SOC_NOPM, 0, 0),
826
827 /* inter-connections */ 900 /* inter-connections */
828 SND_SOC_DAPM_MIXER("I05", SND_SOC_NOPM, 0, 0, NULL, 0), 901 SND_SOC_DAPM_MIXER("I05", SND_SOC_NOPM, 0, 0, NULL, 0),
829 SND_SOC_DAPM_MIXER("I06", SND_SOC_NOPM, 0, 0, NULL, 0), 902 SND_SOC_DAPM_MIXER("I06", SND_SOC_NOPM, 0, 0, NULL, 0),
@@ -855,11 +928,6 @@ static const struct snd_soc_dapm_route mtk_afe_pcm_routes[] = {
855 { "O10", "I18 Switch", "I18" }, 928 { "O10", "I18 Switch", "I18" },
856}; 929};
857 930
858static const struct snd_soc_dapm_widget mtk_afe_hdmi_widgets[] = {
859 /* Backend DAIs */
860 SND_SOC_DAPM_AIF_OUT("HDMIO Playback", NULL, 0, SND_SOC_NOPM, 0, 0),
861};
862
863static const struct snd_soc_dapm_route mtk_afe_hdmi_routes[] = { 931static const struct snd_soc_dapm_route mtk_afe_hdmi_routes[] = {
864 {"HDMIO Playback", NULL, "HDMI"}, 932 {"HDMIO Playback", NULL, "HDMI"},
865}; 933};
@@ -874,8 +942,6 @@ static const struct snd_soc_component_driver mtk_afe_pcm_dai_component = {
874 942
875static const struct snd_soc_component_driver mtk_afe_hdmi_dai_component = { 943static const struct snd_soc_component_driver mtk_afe_hdmi_dai_component = {
876 .name = "mtk-afe-hdmi-dai", 944 .name = "mtk-afe-hdmi-dai",
877 .dapm_widgets = mtk_afe_hdmi_widgets,
878 .num_dapm_widgets = ARRAY_SIZE(mtk_afe_hdmi_widgets),
879 .dapm_routes = mtk_afe_hdmi_routes, 945 .dapm_routes = mtk_afe_hdmi_routes,
880 .num_dapm_routes = ARRAY_SIZE(mtk_afe_hdmi_routes), 946 .num_dapm_routes = ARRAY_SIZE(mtk_afe_hdmi_routes),
881}; 947};
@@ -1199,6 +1265,8 @@ err_pm_disable:
1199static int mtk_afe_pcm_dev_remove(struct platform_device *pdev) 1265static int mtk_afe_pcm_dev_remove(struct platform_device *pdev)
1200{ 1266{
1201 pm_runtime_disable(&pdev->dev); 1267 pm_runtime_disable(&pdev->dev);
1268 if (!pm_runtime_status_suspended(&pdev->dev))
1269 mtk_afe_runtime_suspend(&pdev->dev);
1202 snd_soc_unregister_component(&pdev->dev); 1270 snd_soc_unregister_component(&pdev->dev);
1203 snd_soc_unregister_platform(&pdev->dev); 1271 snd_soc_unregister_platform(&pdev->dev);
1204 return 0; 1272 return 0;
@@ -1218,7 +1286,6 @@ static const struct dev_pm_ops mtk_afe_pm_ops = {
1218static struct platform_driver mtk_afe_pcm_driver = { 1286static struct platform_driver mtk_afe_pcm_driver = {
1219 .driver = { 1287 .driver = {
1220 .name = "mtk-afe-pcm", 1288 .name = "mtk-afe-pcm",
1221 .owner = THIS_MODULE,
1222 .of_match_table = mtk_afe_pcm_dt_match, 1289 .of_match_table = mtk_afe_pcm_dt_match,
1223 .pm = &mtk_afe_pm_ops, 1290 .pm = &mtk_afe_pm_ops,
1224 }, 1291 },
diff --git a/sound/soc/nuc900/nuc900-pcm.c b/sound/soc/nuc900/nuc900-pcm.c
index 5ae5ca15b6d6..e09326158bc2 100644
--- a/sound/soc/nuc900/nuc900-pcm.c
+++ b/sound/soc/nuc900/nuc900-pcm.c
@@ -308,13 +308,7 @@ static struct snd_soc_platform_driver nuc900_soc_platform = {
308 308
309static int nuc900_soc_platform_probe(struct platform_device *pdev) 309static int nuc900_soc_platform_probe(struct platform_device *pdev)
310{ 310{
311 return snd_soc_register_platform(&pdev->dev, &nuc900_soc_platform); 311 return devm_snd_soc_register_platform(&pdev->dev, &nuc900_soc_platform);
312}
313
314static int nuc900_soc_platform_remove(struct platform_device *pdev)
315{
316 snd_soc_unregister_platform(&pdev->dev);
317 return 0;
318} 312}
319 313
320static struct platform_driver nuc900_pcm_driver = { 314static struct platform_driver nuc900_pcm_driver = {
@@ -323,7 +317,6 @@ static struct platform_driver nuc900_pcm_driver = {
323 }, 317 },
324 318
325 .probe = nuc900_soc_platform_probe, 319 .probe = nuc900_soc_platform_probe,
326 .remove = nuc900_soc_platform_remove,
327}; 320};
328 321
329module_platform_driver(nuc900_pcm_driver); 322module_platform_driver(nuc900_pcm_driver);
diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c
index 68a125205375..c7563e230c7d 100644
--- a/sound/soc/omap/mcbsp.c
+++ b/sound/soc/omap/mcbsp.c
@@ -965,25 +965,15 @@ int omap_mcbsp_init(struct platform_device *pdev)
965 mcbsp->free = true; 965 mcbsp->free = true;
966 966
967 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu"); 967 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
968 if (!res) { 968 if (!res)
969 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 969 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
970 if (!res) { 970
971 dev_err(mcbsp->dev, "invalid memory resource\n"); 971 mcbsp->io_base = devm_ioremap_resource(&pdev->dev, res);
972 return -ENOMEM; 972 if (IS_ERR(mcbsp->io_base))
973 } 973 return PTR_ERR(mcbsp->io_base);
974 }
975 if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res),
976 dev_name(&pdev->dev))) {
977 dev_err(mcbsp->dev, "memory region already claimed\n");
978 return -ENODEV;
979 }
980 974
981 mcbsp->phys_base = res->start; 975 mcbsp->phys_base = res->start;
982 mcbsp->reg_cache_size = resource_size(res); 976 mcbsp->reg_cache_size = resource_size(res);
983 mcbsp->io_base = devm_ioremap(&pdev->dev, res->start,
984 resource_size(res));
985 if (!mcbsp->io_base)
986 return -ENOMEM;
987 977
988 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma"); 978 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma");
989 if (!res) 979 if (!res)
diff --git a/sound/soc/omap/omap-hdmi-audio.c b/sound/soc/omap/omap-hdmi-audio.c
index aeef25c0cb3d..584b2372339e 100644
--- a/sound/soc/omap/omap-hdmi-audio.c
+++ b/sound/soc/omap/omap-hdmi-audio.c
@@ -81,7 +81,15 @@ static int hdmi_dai_startup(struct snd_pcm_substream *substream,
81 ret = snd_pcm_hw_constraint_step(substream->runtime, 0, 81 ret = snd_pcm_hw_constraint_step(substream->runtime, 0,
82 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 128); 82 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 128);
83 if (ret < 0) { 83 if (ret < 0) {
84 dev_err(dai->dev, "could not apply constraint\n"); 84 dev_err(dai->dev, "Could not apply period constraint: %d\n",
85 ret);
86 return ret;
87 }
88 ret = snd_pcm_hw_constraint_step(substream->runtime, 0,
89 SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 128);
90 if (ret < 0) {
91 dev_err(dai->dev, "Could not apply buffer constraint: %d\n",
92 ret);
85 return ret; 93 return ret;
86 } 94 }
87 95
diff --git a/sound/soc/omap/omap3pandora.c b/sound/soc/omap/omap3pandora.c
index 076bec606d78..732e749a1f8e 100644
--- a/sound/soc/omap/omap3pandora.c
+++ b/sound/soc/omap/omap3pandora.c
@@ -154,8 +154,7 @@ static const struct snd_soc_dapm_route omap3pandora_map[] = {
154 154
155static int omap3pandora_out_init(struct snd_soc_pcm_runtime *rtd) 155static int omap3pandora_out_init(struct snd_soc_pcm_runtime *rtd)
156{ 156{
157 struct snd_soc_codec *codec = rtd->codec; 157 struct snd_soc_dapm_context *dapm = &rtd->card->dapm;
158 struct snd_soc_dapm_context *dapm = &codec->dapm;
159 158
160 /* All TWL4030 output pins are floating */ 159 /* All TWL4030 output pins are floating */
161 snd_soc_dapm_nc_pin(dapm, "EARPIECE"); 160 snd_soc_dapm_nc_pin(dapm, "EARPIECE");
@@ -174,8 +173,7 @@ static int omap3pandora_out_init(struct snd_soc_pcm_runtime *rtd)
174 173
175static int omap3pandora_in_init(struct snd_soc_pcm_runtime *rtd) 174static int omap3pandora_in_init(struct snd_soc_pcm_runtime *rtd)
176{ 175{
177 struct snd_soc_codec *codec = rtd->codec; 176 struct snd_soc_dapm_context *dapm = &rtd->card->dapm;
178 struct snd_soc_dapm_context *dapm = &codec->dapm;
179 177
180 /* Not comnnected */ 178 /* Not comnnected */
181 snd_soc_dapm_nc_pin(dapm, "HSMIC"); 179 snd_soc_dapm_nc_pin(dapm, "HSMIC");
diff --git a/sound/soc/pxa/mmp-pcm.c b/sound/soc/pxa/mmp-pcm.c
index 1eb45dcfb8e8..51e790d006f5 100644
--- a/sound/soc/pxa/mmp-pcm.c
+++ b/sound/soc/pxa/mmp-pcm.c
@@ -232,13 +232,7 @@ static int mmp_pcm_probe(struct platform_device *pdev)
232 mmp_pcm_hardware[SNDRV_PCM_STREAM_CAPTURE].period_bytes_max = 232 mmp_pcm_hardware[SNDRV_PCM_STREAM_CAPTURE].period_bytes_max =
233 pdata->period_max_capture; 233 pdata->period_max_capture;
234 } 234 }
235 return snd_soc_register_platform(&pdev->dev, &mmp_soc_platform); 235 return devm_snd_soc_register_platform(&pdev->dev, &mmp_soc_platform);
236}
237
238static int mmp_pcm_remove(struct platform_device *pdev)
239{
240 snd_soc_unregister_platform(&pdev->dev);
241 return 0;
242} 236}
243 237
244static struct platform_driver mmp_pcm_driver = { 238static struct platform_driver mmp_pcm_driver = {
@@ -247,7 +241,6 @@ static struct platform_driver mmp_pcm_driver = {
247 }, 241 },
248 242
249 .probe = mmp_pcm_probe, 243 .probe = mmp_pcm_probe,
250 .remove = mmp_pcm_remove,
251}; 244};
252 245
253module_platform_driver(mmp_pcm_driver); 246module_platform_driver(mmp_pcm_driver);
diff --git a/sound/soc/pxa/pxa-ssp.c b/sound/soc/pxa/pxa-ssp.c
index fbe2e93d6edc..3da485ec1de7 100644
--- a/sound/soc/pxa/pxa-ssp.c
+++ b/sound/soc/pxa/pxa-ssp.c
@@ -813,14 +813,8 @@ static const struct of_device_id pxa_ssp_of_ids[] = {
813 813
814static int asoc_ssp_probe(struct platform_device *pdev) 814static int asoc_ssp_probe(struct platform_device *pdev)
815{ 815{
816 return snd_soc_register_component(&pdev->dev, &pxa_ssp_component, 816 return devm_snd_soc_register_component(&pdev->dev, &pxa_ssp_component,
817 &pxa_ssp_dai, 1); 817 &pxa_ssp_dai, 1);
818}
819
820static int asoc_ssp_remove(struct platform_device *pdev)
821{
822 snd_soc_unregister_component(&pdev->dev);
823 return 0;
824} 818}
825 819
826static struct platform_driver asoc_ssp_driver = { 820static struct platform_driver asoc_ssp_driver = {
@@ -830,7 +824,6 @@ static struct platform_driver asoc_ssp_driver = {
830 }, 824 },
831 825
832 .probe = asoc_ssp_probe, 826 .probe = asoc_ssp_probe,
833 .remove = asoc_ssp_remove,
834}; 827};
835 828
836module_platform_driver(asoc_ssp_driver); 829module_platform_driver(asoc_ssp_driver);
diff --git a/sound/soc/pxa/pxa2xx-i2s.c b/sound/soc/pxa/pxa2xx-i2s.c
index e68290c15328..6b4e40036910 100644
--- a/sound/soc/pxa/pxa2xx-i2s.c
+++ b/sound/soc/pxa/pxa2xx-i2s.c
@@ -367,19 +367,12 @@ static const struct snd_soc_component_driver pxa_i2s_component = {
367 367
368static int pxa2xx_i2s_drv_probe(struct platform_device *pdev) 368static int pxa2xx_i2s_drv_probe(struct platform_device *pdev)
369{ 369{
370 return snd_soc_register_component(&pdev->dev, &pxa_i2s_component, 370 return devm_snd_soc_register_component(&pdev->dev, &pxa_i2s_component,
371 &pxa_i2s_dai, 1); 371 &pxa_i2s_dai, 1);
372}
373
374static int pxa2xx_i2s_drv_remove(struct platform_device *pdev)
375{
376 snd_soc_unregister_component(&pdev->dev);
377 return 0;
378} 372}
379 373
380static struct platform_driver pxa2xx_i2s_driver = { 374static struct platform_driver pxa2xx_i2s_driver = {
381 .probe = pxa2xx_i2s_drv_probe, 375 .probe = pxa2xx_i2s_drv_probe,
382 .remove = pxa2xx_i2s_drv_remove,
383 376
384 .driver = { 377 .driver = {
385 .name = "pxa2xx-i2s", 378 .name = "pxa2xx-i2s",
diff --git a/sound/soc/pxa/pxa2xx-pcm.c b/sound/soc/pxa/pxa2xx-pcm.c
index a51c9da66614..831ee37d2e3e 100644
--- a/sound/soc/pxa/pxa2xx-pcm.c
+++ b/sound/soc/pxa/pxa2xx-pcm.c
@@ -124,13 +124,7 @@ static struct snd_soc_platform_driver pxa2xx_soc_platform = {
124 124
125static int pxa2xx_soc_platform_probe(struct platform_device *pdev) 125static int pxa2xx_soc_platform_probe(struct platform_device *pdev)
126{ 126{
127 return snd_soc_register_platform(&pdev->dev, &pxa2xx_soc_platform); 127 return devm_snd_soc_register_platform(&pdev->dev, &pxa2xx_soc_platform);
128}
129
130static int pxa2xx_soc_platform_remove(struct platform_device *pdev)
131{
132 snd_soc_unregister_platform(&pdev->dev);
133 return 0;
134} 128}
135 129
136#ifdef CONFIG_OF 130#ifdef CONFIG_OF
@@ -147,7 +141,6 @@ static struct platform_driver pxa_pcm_driver = {
147 }, 141 },
148 142
149 .probe = pxa2xx_soc_platform_probe, 143 .probe = pxa2xx_soc_platform_probe,
150 .remove = pxa2xx_soc_platform_remove,
151}; 144};
152 145
153module_platform_driver(pxa_pcm_driver); 146module_platform_driver(pxa_pcm_driver);
diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig
index 807fedfa1c76..3cc252e55468 100644
--- a/sound/soc/qcom/Kconfig
+++ b/sound/soc/qcom/Kconfig
@@ -1,5 +1,6 @@
1config SND_SOC_QCOM 1config SND_SOC_QCOM
2 tristate "ASoC support for QCOM platforms" 2 tristate "ASoC support for QCOM platforms"
3 depends on ARCH_QCOM || COMPILE_TEST
3 help 4 help
4 Say Y or M if you want to add support to use audio devices 5 Say Y or M if you want to add support to use audio devices
5 in Qualcomm Technologies SOC-based platforms. 6 in Qualcomm Technologies SOC-based platforms.
@@ -14,19 +15,17 @@ config SND_SOC_LPASS_PLATFORM
14 15
15config SND_SOC_LPASS_IPQ806X 16config SND_SOC_LPASS_IPQ806X
16 tristate 17 tristate
17 depends on SND_SOC_QCOM
18 select SND_SOC_LPASS_CPU 18 select SND_SOC_LPASS_CPU
19 select SND_SOC_LPASS_PLATFORM 19 select SND_SOC_LPASS_PLATFORM
20 20
21config SND_SOC_LPASS_APQ8016 21config SND_SOC_LPASS_APQ8016
22 tristate 22 tristate
23 depends on SND_SOC_QCOM
24 select SND_SOC_LPASS_CPU 23 select SND_SOC_LPASS_CPU
25 select SND_SOC_LPASS_PLATFORM 24 select SND_SOC_LPASS_PLATFORM
26 25
27config SND_SOC_STORM 26config SND_SOC_STORM
28 tristate "ASoC I2S support for Storm boards" 27 tristate "ASoC I2S support for Storm boards"
29 depends on SND_SOC_QCOM && (ARCH_QCOM || COMPILE_TEST) 28 depends on SND_SOC_QCOM
30 select SND_SOC_LPASS_IPQ806X 29 select SND_SOC_LPASS_IPQ806X
31 select SND_SOC_MAX98357A 30 select SND_SOC_MAX98357A
32 help 31 help
@@ -35,7 +34,7 @@ config SND_SOC_STORM
35 34
36config SND_SOC_APQ8016_SBC 35config SND_SOC_APQ8016_SBC
37 tristate "SoC Audio support for APQ8016 SBC platforms" 36 tristate "SoC Audio support for APQ8016 SBC platforms"
38 depends on SND_SOC_QCOM && (ARCH_QCOM || COMPILE_TEST) 37 depends on SND_SOC_QCOM
39 select SND_SOC_LPASS_APQ8016 38 select SND_SOC_LPASS_APQ8016
40 help 39 help
41 Support for Qualcomm Technologies LPASS audio block in 40 Support for Qualcomm Technologies LPASS audio block in
diff --git a/sound/soc/qcom/lpass-cpu.c b/sound/soc/qcom/lpass-cpu.c
index 23f3d59e6d09..97bc2023f08a 100644
--- a/sound/soc/qcom/lpass-cpu.c
+++ b/sound/soc/qcom/lpass-cpu.c
@@ -235,7 +235,7 @@ static int lpass_cpu_daiops_trigger(struct snd_pcm_substream *substream,
235 return ret; 235 return ret;
236} 236}
237 237
238struct snd_soc_dai_ops asoc_qcom_lpass_cpu_dai_ops = { 238const struct snd_soc_dai_ops asoc_qcom_lpass_cpu_dai_ops = {
239 .set_sysclk = lpass_cpu_daiops_set_sysclk, 239 .set_sysclk = lpass_cpu_daiops_set_sysclk,
240 .startup = lpass_cpu_daiops_startup, 240 .startup = lpass_cpu_daiops_startup,
241 .shutdown = lpass_cpu_daiops_shutdown, 241 .shutdown = lpass_cpu_daiops_shutdown,
diff --git a/sound/soc/qcom/lpass-ipq806x.c b/sound/soc/qcom/lpass-ipq806x.c
index 7356d3a766d6..7a4167952711 100644
--- a/sound/soc/qcom/lpass-ipq806x.c
+++ b/sound/soc/qcom/lpass-ipq806x.c
@@ -73,7 +73,7 @@ static int ipq806x_lpass_free_dma_channel(struct lpass_data *drvdata, int chan)
73 return 0; 73 return 0;
74} 74}
75 75
76struct lpass_variant ipq806x_data = { 76static struct lpass_variant ipq806x_data = {
77 .i2sctrl_reg_base = 0x0010, 77 .i2sctrl_reg_base = 0x0010,
78 .i2sctrl_reg_stride = 0x04, 78 .i2sctrl_reg_stride = 0x04,
79 .i2s_ports = 5, 79 .i2s_ports = 5,
diff --git a/sound/soc/qcom/lpass.h b/sound/soc/qcom/lpass.h
index d6e86c119e74..0b63e2e5bcc9 100644
--- a/sound/soc/qcom/lpass.h
+++ b/sound/soc/qcom/lpass.h
@@ -93,6 +93,6 @@ int asoc_qcom_lpass_platform_register(struct platform_device *);
93int asoc_qcom_lpass_cpu_platform_remove(struct platform_device *pdev); 93int asoc_qcom_lpass_cpu_platform_remove(struct platform_device *pdev);
94int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev); 94int asoc_qcom_lpass_cpu_platform_probe(struct platform_device *pdev);
95int asoc_qcom_lpass_cpu_dai_probe(struct snd_soc_dai *dai); 95int asoc_qcom_lpass_cpu_dai_probe(struct snd_soc_dai *dai);
96extern struct snd_soc_dai_ops asoc_qcom_lpass_cpu_dai_ops; 96extern const struct snd_soc_dai_ops asoc_qcom_lpass_cpu_dai_ops;
97 97
98#endif /* __LPASS_H__ */ 98#endif /* __LPASS_H__ */
diff --git a/sound/soc/rockchip/Kconfig b/sound/soc/rockchip/Kconfig
index e18182699d83..58bae8e2cf5f 100644
--- a/sound/soc/rockchip/Kconfig
+++ b/sound/soc/rockchip/Kconfig
@@ -14,3 +14,22 @@ config SND_SOC_ROCKCHIP_I2S
14 Say Y or M if you want to add support for I2S driver for 14 Say Y or M if you want to add support for I2S driver for
15 Rockchip I2S device. The device supports upto maximum of 15 Rockchip I2S device. The device supports upto maximum of
16 8 channels each for play and record. 16 8 channels each for play and record.
17
18config SND_SOC_ROCKCHIP_MAX98090
19 tristate "ASoC support for Rockchip boards using a MAX98090 codec"
20 depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB
21 select SND_SOC_ROCKCHIP_I2S
22 select SND_SOC_MAX98090
23 select SND_SOC_TS3A227E
24 help
25 Say Y or M here if you want to add support for SoC audio on Rockchip
26 boards using the MAX98090 codec, such as Veyron.
27
28config SND_SOC_ROCKCHIP_RT5645
29 tristate "ASoC support for Rockchip boards using a RT5645/RT5650 codec"
30 depends on SND_SOC_ROCKCHIP && I2C && GPIOLIB
31 select SND_SOC_ROCKCHIP_I2S
32 select SND_SOC_RT5645
33 help
34 Say Y or M here if you want to add support for SoC audio on Rockchip
35 boards using the RT5645/RT5650 codec, such as Veyron.
diff --git a/sound/soc/rockchip/Makefile b/sound/soc/rockchip/Makefile
index b9219092b47f..1bc1dc3c729a 100644
--- a/sound/soc/rockchip/Makefile
+++ b/sound/soc/rockchip/Makefile
@@ -2,3 +2,9 @@
2snd-soc-i2s-objs := rockchip_i2s.o 2snd-soc-i2s-objs := rockchip_i2s.o
3 3
4obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-i2s.o 4obj-$(CONFIG_SND_SOC_ROCKCHIP_I2S) += snd-soc-i2s.o
5
6snd-soc-rockchip-max98090-objs := rockchip_max98090.o
7snd-soc-rockchip-rt5645-objs := rockchip_rt5645.o
8
9obj-$(CONFIG_SND_SOC_ROCKCHIP_MAX98090) += snd-soc-rockchip-max98090.o
10obj-$(CONFIG_SND_SOC_ROCKCHIP_RT5645) += snd-soc-rockchip-rt5645.o
diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c
index acb5be53bfb4..b93610212e3d 100644
--- a/sound/soc/rockchip/rockchip_i2s.c
+++ b/sound/soc/rockchip/rockchip_i2s.c
@@ -483,16 +483,14 @@ static int rockchip_i2s_probe(struct platform_device *pdev)
483 goto err_suspend; 483 goto err_suspend;
484 } 484 }
485 485
486 ret = snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); 486 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
487 if (ret) { 487 if (ret) {
488 dev_err(&pdev->dev, "Could not register PCM\n"); 488 dev_err(&pdev->dev, "Could not register PCM\n");
489 goto err_pcm_register; 489 return ret;
490 } 490 }
491 491
492 return 0; 492 return 0;
493 493
494err_pcm_register:
495 snd_dmaengine_pcm_unregister(&pdev->dev);
496err_suspend: 494err_suspend:
497 if (!pm_runtime_status_suspended(&pdev->dev)) 495 if (!pm_runtime_status_suspended(&pdev->dev))
498 i2s_runtime_suspend(&pdev->dev); 496 i2s_runtime_suspend(&pdev->dev);
@@ -512,8 +510,6 @@ static int rockchip_i2s_remove(struct platform_device *pdev)
512 510
513 clk_disable_unprepare(i2s->mclk); 511 clk_disable_unprepare(i2s->mclk);
514 clk_disable_unprepare(i2s->hclk); 512 clk_disable_unprepare(i2s->hclk);
515 snd_dmaengine_pcm_unregister(&pdev->dev);
516 snd_soc_unregister_component(&pdev->dev);
517 513
518 return 0; 514 return 0;
519} 515}
diff --git a/sound/soc/rockchip/rockchip_max98090.c b/sound/soc/rockchip/rockchip_max98090.c
new file mode 100644
index 000000000000..26567b10393a
--- /dev/null
+++ b/sound/soc/rockchip/rockchip_max98090.c
@@ -0,0 +1,236 @@
1/*
2 * Rockchip machine ASoC driver for boards using a MAX90809 CODEC.
3 *
4 * Copyright (c) 2014, ROCKCHIP CORPORATION. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20#include <linux/module.h>
21#include <linux/platform_device.h>
22#include <linux/slab.h>
23#include <linux/gpio.h>
24#include <linux/of_gpio.h>
25#include <sound/core.h>
26#include <sound/jack.h>
27#include <sound/pcm.h>
28#include <sound/pcm_params.h>
29#include <sound/soc.h>
30
31#include "rockchip_i2s.h"
32#include "../codecs/ts3a227e.h"
33
34#define DRV_NAME "rockchip-snd-max98090"
35
36static struct snd_soc_jack headset_jack;
37static struct snd_soc_jack_pin headset_jack_pins[] = {
38 {
39 .pin = "Headset Jack",
40 .mask = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE |
41 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
42 SND_JACK_BTN_2 | SND_JACK_BTN_3,
43 },
44};
45
46static const struct snd_soc_dapm_widget rk_dapm_widgets[] = {
47 SND_SOC_DAPM_HP("Headphone", NULL),
48 SND_SOC_DAPM_MIC("Headset Mic", NULL),
49 SND_SOC_DAPM_MIC("Int Mic", NULL),
50 SND_SOC_DAPM_SPK("Speaker", NULL),
51};
52
53static const struct snd_soc_dapm_route rk_audio_map[] = {
54 {"IN34", NULL, "Headset Mic"},
55 {"IN34", NULL, "MICBIAS"},
56 {"MICBIAS", NULL, "Headset Mic"},
57 {"DMICL", NULL, "Int Mic"},
58 {"Headphone", NULL, "HPL"},
59 {"Headphone", NULL, "HPR"},
60 {"Speaker", NULL, "SPKL"},
61 {"Speaker", NULL, "SPKR"},
62};
63
64static const struct snd_kcontrol_new rk_mc_controls[] = {
65 SOC_DAPM_PIN_SWITCH("Headphone"),
66 SOC_DAPM_PIN_SWITCH("Headset Mic"),
67 SOC_DAPM_PIN_SWITCH("Int Mic"),
68 SOC_DAPM_PIN_SWITCH("Speaker"),
69};
70
71static int rk_aif1_hw_params(struct snd_pcm_substream *substream,
72 struct snd_pcm_hw_params *params)
73{
74 int ret = 0;
75 struct snd_soc_pcm_runtime *rtd = substream->private_data;
76 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
77 struct snd_soc_dai *codec_dai = rtd->codec_dai;
78 int mclk;
79
80 switch (params_rate(params)) {
81 case 8000:
82 case 16000:
83 case 48000:
84 case 96000:
85 mclk = 12288000;
86 break;
87 case 44100:
88 mclk = 11289600;
89 break;
90 default:
91 return -EINVAL;
92 }
93
94 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
95 SND_SOC_CLOCK_OUT);
96 if (ret < 0) {
97 dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret);
98 return ret;
99 }
100
101 ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
102 SND_SOC_CLOCK_IN);
103 if (ret < 0) {
104 dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret);
105 return ret;
106 }
107
108 return ret;
109}
110
111static int rk_init(struct snd_soc_pcm_runtime *runtime)
112{
113 /* Enable Headset and 4 Buttons Jack detection */
114 return snd_soc_card_jack_new(runtime->card, "Headset Jack",
115 SND_JACK_HEADSET |
116 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
117 SND_JACK_BTN_2 | SND_JACK_BTN_3,
118 &headset_jack,
119 headset_jack_pins,
120 ARRAY_SIZE(headset_jack_pins));
121}
122
123static int rk_98090_headset_init(struct snd_soc_component *component)
124{
125 return ts3a227e_enable_jack_detect(component, &headset_jack);
126}
127
128static struct snd_soc_ops rk_aif1_ops = {
129 .hw_params = rk_aif1_hw_params,
130};
131
132static struct snd_soc_aux_dev rk_98090_headset_dev = {
133 .name = "Headset Chip",
134 .init = rk_98090_headset_init,
135};
136
137static struct snd_soc_dai_link rk_dailink = {
138 .name = "max98090",
139 .stream_name = "Audio",
140 .codec_dai_name = "HiFi",
141 .init = rk_init,
142 .ops = &rk_aif1_ops,
143 /* set max98090 as slave */
144 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
145 SND_SOC_DAIFMT_CBS_CFS,
146};
147
148static struct snd_soc_card snd_soc_card_rk = {
149 .name = "ROCKCHIP-I2S",
150 .owner = THIS_MODULE,
151 .dai_link = &rk_dailink,
152 .num_links = 1,
153 .aux_dev = &rk_98090_headset_dev,
154 .num_aux_devs = 1,
155 .dapm_widgets = rk_dapm_widgets,
156 .num_dapm_widgets = ARRAY_SIZE(rk_dapm_widgets),
157 .dapm_routes = rk_audio_map,
158 .num_dapm_routes = ARRAY_SIZE(rk_audio_map),
159 .controls = rk_mc_controls,
160 .num_controls = ARRAY_SIZE(rk_mc_controls),
161};
162
163static int snd_rk_mc_probe(struct platform_device *pdev)
164{
165 int ret = 0;
166 struct snd_soc_card *card = &snd_soc_card_rk;
167 struct device_node *np = pdev->dev.of_node;
168
169 /* register the soc card */
170 card->dev = &pdev->dev;
171
172 rk_dailink.codec_of_node = of_parse_phandle(np,
173 "rockchip,audio-codec", 0);
174 if (!rk_dailink.codec_of_node) {
175 dev_err(&pdev->dev,
176 "Property 'rockchip,audio-codec' missing or invalid\n");
177 return -EINVAL;
178 }
179
180 rk_dailink.cpu_of_node = of_parse_phandle(np,
181 "rockchip,i2s-controller", 0);
182 if (!rk_dailink.cpu_of_node) {
183 dev_err(&pdev->dev,
184 "Property 'rockchip,i2s-controller' missing or invalid\n");
185 return -EINVAL;
186 }
187
188 rk_dailink.platform_of_node = rk_dailink.cpu_of_node;
189
190 rk_98090_headset_dev.codec_of_node = of_parse_phandle(np,
191 "rockchip,headset-codec", 0);
192 if (!rk_98090_headset_dev.codec_of_node) {
193 dev_err(&pdev->dev,
194 "Property 'rockchip,headset-codec' missing/invalid\n");
195 return -EINVAL;
196 }
197
198 ret = snd_soc_of_parse_card_name(card, "rockchip,model");
199 if (ret) {
200 dev_err(&pdev->dev,
201 "Soc parse card name failed %d\n", ret);
202 return ret;
203 }
204
205 ret = devm_snd_soc_register_card(&pdev->dev, card);
206 if (ret) {
207 dev_err(&pdev->dev,
208 "Soc register card failed %d\n", ret);
209 return ret;
210 }
211
212 return ret;
213}
214
215static const struct of_device_id rockchip_max98090_of_match[] = {
216 { .compatible = "rockchip,rockchip-audio-max98090", },
217 {},
218};
219
220MODULE_DEVICE_TABLE(of, rockchip_max98090_of_match);
221
222static struct platform_driver snd_rk_mc_driver = {
223 .probe = snd_rk_mc_probe,
224 .driver = {
225 .name = DRV_NAME,
226 .pm = &snd_soc_pm_ops,
227 .of_match_table = rockchip_max98090_of_match,
228 },
229};
230
231module_platform_driver(snd_rk_mc_driver);
232
233MODULE_AUTHOR("jianqun <jay.xu@rock-chips.com>");
234MODULE_DESCRIPTION("Rockchip max98090 machine ASoC driver");
235MODULE_LICENSE("GPL v2");
236MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/sound/soc/rockchip/rockchip_rt5645.c b/sound/soc/rockchip/rockchip_rt5645.c
new file mode 100644
index 000000000000..68c62e4c2316
--- /dev/null
+++ b/sound/soc/rockchip/rockchip_rt5645.c
@@ -0,0 +1,225 @@
1/*
2 * Rockchip machine ASoC driver for boards using a RT5645/RT5650 CODEC.
3 *
4 * Copyright (c) 2015, ROCKCHIP CORPORATION. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20#include <linux/module.h>
21#include <linux/platform_device.h>
22#include <linux/slab.h>
23#include <linux/gpio.h>
24#include <linux/of_gpio.h>
25#include <linux/delay.h>
26#include <sound/core.h>
27#include <sound/jack.h>
28#include <sound/pcm.h>
29#include <sound/pcm_params.h>
30#include <sound/soc.h>
31#include "rockchip_i2s.h"
32
33#define DRV_NAME "rockchip-snd-rt5645"
34
35static struct snd_soc_jack headset_jack;
36
37/* Jack detect via rt5645 driver. */
38extern int rt5645_set_jack_detect(struct snd_soc_codec *codec,
39 struct snd_soc_jack *hp_jack, struct snd_soc_jack *mic_jack,
40 struct snd_soc_jack *btn_jack);
41
42static const struct snd_soc_dapm_widget rk_dapm_widgets[] = {
43 SND_SOC_DAPM_HP("Headphones", NULL),
44 SND_SOC_DAPM_SPK("Speakers", NULL),
45 SND_SOC_DAPM_MIC("Headset Mic", NULL),
46 SND_SOC_DAPM_MIC("Int Mic", NULL),
47};
48
49static const struct snd_soc_dapm_route rk_audio_map[] = {
50 /* Input Lines */
51 {"DMIC L2", NULL, "Int Mic"},
52 {"DMIC R2", NULL, "Int Mic"},
53 {"RECMIXL", NULL, "Headset Mic"},
54 {"RECMIXR", NULL, "Headset Mic"},
55
56 /* Output Lines */
57 {"Headphones", NULL, "HPOR"},
58 {"Headphones", NULL, "HPOL"},
59 {"Speakers", NULL, "SPOL"},
60 {"Speakers", NULL, "SPOR"},
61};
62
63static const struct snd_kcontrol_new rk_mc_controls[] = {
64 SOC_DAPM_PIN_SWITCH("Headphones"),
65 SOC_DAPM_PIN_SWITCH("Speakers"),
66 SOC_DAPM_PIN_SWITCH("Headset Mic"),
67 SOC_DAPM_PIN_SWITCH("Int Mic"),
68};
69
70static int rk_aif1_hw_params(struct snd_pcm_substream *substream,
71 struct snd_pcm_hw_params *params)
72{
73 int ret = 0;
74 struct snd_soc_pcm_runtime *rtd = substream->private_data;
75 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
76 struct snd_soc_dai *codec_dai = rtd->codec_dai;
77 int mclk;
78
79 switch (params_rate(params)) {
80 case 8000:
81 case 16000:
82 case 48000:
83 case 96000:
84 mclk = 12288000;
85 break;
86 case 44100:
87 mclk = 11289600;
88 break;
89 default:
90 return -EINVAL;
91 }
92
93 ret = snd_soc_dai_set_sysclk(cpu_dai, 0, mclk,
94 SND_SOC_CLOCK_OUT);
95 if (ret < 0) {
96 dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret);
97 return ret;
98 }
99
100 ret = snd_soc_dai_set_sysclk(codec_dai, 0, mclk,
101 SND_SOC_CLOCK_IN);
102 if (ret < 0) {
103 dev_err(codec_dai->dev, "Can't set codec clock %d\n", ret);
104 return ret;
105 }
106
107 return ret;
108}
109
110static int rk_init(struct snd_soc_pcm_runtime *runtime)
111{
112 struct snd_soc_card *card = runtime->card;
113 int ret;
114
115 /* Enable Headset and 4 Buttons Jack detection */
116 ret = snd_soc_card_jack_new(card, "Headset Jack",
117 SND_JACK_HEADPHONE | SND_JACK_MICROPHONE |
118 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
119 SND_JACK_BTN_2 | SND_JACK_BTN_3,
120 &headset_jack, NULL, 0);
121 if (ret) {
122 dev_err(card->dev, "New Headset Jack failed! (%d)\n", ret);
123 return ret;
124 }
125
126 return rt5645_set_jack_detect(runtime->codec,
127 &headset_jack,
128 &headset_jack,
129 &headset_jack);
130}
131
132static struct snd_soc_ops rk_aif1_ops = {
133 .hw_params = rk_aif1_hw_params,
134};
135
136static struct snd_soc_dai_link rk_dailink = {
137 .name = "rt5645",
138 .stream_name = "rt5645 PCM",
139 .codec_dai_name = "rt5645-aif1",
140 .init = rk_init,
141 .ops = &rk_aif1_ops,
142 /* set rt5645 as slave */
143 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
144 SND_SOC_DAIFMT_CBS_CFS,
145};
146
147static struct snd_soc_card snd_soc_card_rk = {
148 .name = "I2S-RT5650",
149 .owner = THIS_MODULE,
150 .dai_link = &rk_dailink,
151 .num_links = 1,
152 .dapm_widgets = rk_dapm_widgets,
153 .num_dapm_widgets = ARRAY_SIZE(rk_dapm_widgets),
154 .dapm_routes = rk_audio_map,
155 .num_dapm_routes = ARRAY_SIZE(rk_audio_map),
156 .controls = rk_mc_controls,
157 .num_controls = ARRAY_SIZE(rk_mc_controls),
158};
159
160static int snd_rk_mc_probe(struct platform_device *pdev)
161{
162 int ret = 0;
163 struct snd_soc_card *card = &snd_soc_card_rk;
164 struct device_node *np = pdev->dev.of_node;
165
166 /* register the soc card */
167 card->dev = &pdev->dev;
168
169 rk_dailink.codec_of_node = of_parse_phandle(np,
170 "rockchip,audio-codec", 0);
171 if (!rk_dailink.codec_of_node) {
172 dev_err(&pdev->dev,
173 "Property 'rockchip,audio-codec' missing or invalid\n");
174 return -EINVAL;
175 }
176
177 rk_dailink.cpu_of_node = of_parse_phandle(np,
178 "rockchip,i2s-controller", 0);
179 if (!rk_dailink.cpu_of_node) {
180 dev_err(&pdev->dev,
181 "Property 'rockchip,i2s-controller' missing or invalid\n");
182 return -EINVAL;
183 }
184
185 rk_dailink.platform_of_node = rk_dailink.cpu_of_node;
186
187 ret = snd_soc_of_parse_card_name(card, "rockchip,model");
188 if (ret) {
189 dev_err(&pdev->dev,
190 "Soc parse card name failed %d\n", ret);
191 return ret;
192 }
193
194 ret = devm_snd_soc_register_card(&pdev->dev, card);
195 if (ret) {
196 dev_err(&pdev->dev,
197 "Soc register card failed %d\n", ret);
198 return ret;
199 }
200
201 return ret;
202}
203
204static const struct of_device_id rockchip_rt5645_of_match[] = {
205 { .compatible = "rockchip,rockchip-audio-rt5645", },
206 {},
207};
208
209MODULE_DEVICE_TABLE(of, rockchip_rt5645_of_match);
210
211static struct platform_driver snd_rk_mc_driver = {
212 .probe = snd_rk_mc_probe,
213 .driver = {
214 .name = DRV_NAME,
215 .pm = &snd_soc_pm_ops,
216 .of_match_table = rockchip_rt5645_of_match,
217 },
218};
219
220module_platform_driver(snd_rk_mc_driver);
221
222MODULE_AUTHOR("Xing Zheng <zhengxing@rock-chips.com>");
223MODULE_DESCRIPTION("Rockchip rt5645 machine ASoC driver");
224MODULE_LICENSE("GPL v2");
225MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/sound/soc/samsung/arndale_rt5631.c b/sound/soc/samsung/arndale_rt5631.c
index 8bf2e2c4bafb..ee1fda92f2f4 100644
--- a/sound/soc/samsung/arndale_rt5631.c
+++ b/sound/soc/samsung/arndale_rt5631.c
@@ -71,6 +71,7 @@ static struct snd_soc_dai_link arndale_rt5631_dai[] = {
71 71
72static struct snd_soc_card arndale_rt5631 = { 72static struct snd_soc_card arndale_rt5631 = {
73 .name = "Arndale RT5631", 73 .name = "Arndale RT5631",
74 .owner = THIS_MODULE,
74 .dai_link = arndale_rt5631_dai, 75 .dai_link = arndale_rt5631_dai,
75 .num_links = ARRAY_SIZE(arndale_rt5631_dai), 76 .num_links = ARRAY_SIZE(arndale_rt5631_dai),
76}; 77};
@@ -116,15 +117,6 @@ static int arndale_audio_probe(struct platform_device *pdev)
116 return ret; 117 return ret;
117} 118}
118 119
119static int arndale_audio_remove(struct platform_device *pdev)
120{
121 struct snd_soc_card *card = platform_get_drvdata(pdev);
122
123 snd_soc_unregister_card(card);
124
125 return 0;
126}
127
128static const struct of_device_id samsung_arndale_rt5631_of_match[] __maybe_unused = { 120static const struct of_device_id samsung_arndale_rt5631_of_match[] __maybe_unused = {
129 { .compatible = "samsung,arndale-rt5631", }, 121 { .compatible = "samsung,arndale-rt5631", },
130 { .compatible = "samsung,arndale-alc5631", }, 122 { .compatible = "samsung,arndale-alc5631", },
@@ -139,7 +131,6 @@ static struct platform_driver arndale_audio_driver = {
139 .of_match_table = of_match_ptr(samsung_arndale_rt5631_of_match), 131 .of_match_table = of_match_ptr(samsung_arndale_rt5631_of_match),
140 }, 132 },
141 .probe = arndale_audio_probe, 133 .probe = arndale_audio_probe,
142 .remove = arndale_audio_remove,
143}; 134};
144 135
145module_platform_driver(arndale_audio_driver); 136module_platform_driver(arndale_audio_driver);
diff --git a/sound/soc/samsung/snow.c b/sound/soc/samsung/snow.c
index 7651dc924161..07ce2cfa4845 100644
--- a/sound/soc/samsung/snow.c
+++ b/sound/soc/samsung/snow.c
@@ -56,6 +56,7 @@ static int snow_late_probe(struct snd_soc_card *card)
56 56
57static struct snd_soc_card snow_snd = { 57static struct snd_soc_card snow_snd = {
58 .name = "Snow-I2S", 58 .name = "Snow-I2S",
59 .owner = THIS_MODULE,
59 .dai_link = snow_dai, 60 .dai_link = snow_dai,
60 .num_links = ARRAY_SIZE(snow_dai), 61 .num_links = ARRAY_SIZE(snow_dai),
61 62
diff --git a/sound/soc/sh/dma-sh7760.c b/sound/soc/sh/dma-sh7760.c
index fd11404a3bc7..8fad4441c87d 100644
--- a/sound/soc/sh/dma-sh7760.c
+++ b/sound/soc/sh/dma-sh7760.c
@@ -327,13 +327,7 @@ static struct snd_soc_platform_driver sh7760_soc_platform = {
327 327
328static int sh7760_soc_platform_probe(struct platform_device *pdev) 328static int sh7760_soc_platform_probe(struct platform_device *pdev)
329{ 329{
330 return snd_soc_register_platform(&pdev->dev, &sh7760_soc_platform); 330 return devm_snd_soc_register_platform(&pdev->dev, &sh7760_soc_platform);
331}
332
333static int sh7760_soc_platform_remove(struct platform_device *pdev)
334{
335 snd_soc_unregister_platform(&pdev->dev);
336 return 0;
337} 331}
338 332
339static struct platform_driver sh7760_pcm_driver = { 333static struct platform_driver sh7760_pcm_driver = {
@@ -342,7 +336,6 @@ static struct platform_driver sh7760_pcm_driver = {
342 }, 336 },
343 337
344 .probe = sh7760_soc_platform_probe, 338 .probe = sh7760_soc_platform_probe,
345 .remove = sh7760_soc_platform_remove,
346}; 339};
347 340
348module_platform_driver(sh7760_pcm_driver); 341module_platform_driver(sh7760_pcm_driver);
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 142c066eaee2..0215c78cbddf 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -1911,7 +1911,6 @@ MODULE_DEVICE_TABLE(of, fsi_of_match);
1911 1911
1912static const struct platform_device_id fsi_id_table[] = { 1912static const struct platform_device_id fsi_id_table[] = {
1913 { "sh_fsi", (kernel_ulong_t)&fsi1_core }, 1913 { "sh_fsi", (kernel_ulong_t)&fsi1_core },
1914 { "sh_fsi2", (kernel_ulong_t)&fsi2_core },
1915 {}, 1914 {},
1916}; 1915};
1917MODULE_DEVICE_TABLE(platform, fsi_id_table); 1916MODULE_DEVICE_TABLE(platform, fsi_id_table);
diff --git a/sound/soc/sh/rcar/Makefile b/sound/soc/sh/rcar/Makefile
index f1b445173fba..8b258501aa35 100644
--- a/sound/soc/sh/rcar/Makefile
+++ b/sound/soc/sh/rcar/Makefile
@@ -1,4 +1,4 @@
1snd-soc-rcar-objs := core.o gen.o dma.o src.o adg.o ssi.o dvc.o 1snd-soc-rcar-objs := core.o gen.o dma.o adg.o ssi.o src.o ctu.o mix.o dvc.o
2obj-$(CONFIG_SND_SOC_RCAR) += snd-soc-rcar.o 2obj-$(CONFIG_SND_SOC_RCAR) += snd-soc-rcar.o
3 3
4snd-soc-rsrc-card-objs := rsrc-card.o 4snd-soc-rsrc-card-objs := rsrc-card.o
diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
index f1e5920654f6..f3feed5ce9b6 100644
--- a/sound/soc/sh/rcar/core.c
+++ b/sound/soc/sh/rcar/core.c
@@ -203,9 +203,9 @@ int rsnd_io_is_working(struct rsnd_dai_stream *io)
203} 203}
204 204
205/* 205/*
206 * settting function 206 * ADINR function
207 */ 207 */
208u32 rsnd_get_adinr(struct rsnd_mod *mod, struct rsnd_dai_stream *io) 208u32 rsnd_get_adinr_bit(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
209{ 209{
210 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 210 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
211 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 211 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
@@ -227,6 +227,64 @@ u32 rsnd_get_adinr(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
227 return adinr; 227 return adinr;
228} 228}
229 229
230u32 rsnd_get_adinr_chan(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
231{
232 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
233 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
234 struct device *dev = rsnd_priv_to_dev(priv);
235 u32 chan = runtime->channels;
236
237 switch (chan) {
238 case 1:
239 case 2:
240 case 4:
241 case 6:
242 case 8:
243 break;
244 default:
245 dev_warn(dev, "not supported channel\n");
246 chan = 0;
247 break;
248 }
249
250 return chan;
251}
252
253/*
254 * DALIGN function
255 */
256u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
257{
258 struct rsnd_mod *src = rsnd_io_to_mod_src(io);
259 struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io);
260 struct rsnd_mod *target = src ? src : ssi;
261 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
262 u32 val = 0x76543210;
263 u32 mask = ~0;
264
265 mask <<= runtime->channels * 4;
266 val = val & mask;
267
268 switch (runtime->sample_bits) {
269 case 16:
270 val |= 0x67452301 & ~mask;
271 break;
272 case 32:
273 val |= 0x76543210 & ~mask;
274 break;
275 }
276
277 /*
278 * exchange channeles on SRC if possible,
279 * otherwise, R/L volume settings on DVC
280 * changes inverted channels
281 */
282 if (mod == target)
283 return val;
284 else
285 return 0x76543210;
286}
287
230/* 288/*
231 * rsnd_dai functions 289 * rsnd_dai functions
232 */ 290 */
@@ -242,9 +300,9 @@ u32 rsnd_get_adinr(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
242 if (val == __rsnd_mod_call_##func) { \ 300 if (val == __rsnd_mod_call_##func) { \
243 called = 1; \ 301 called = 1; \
244 ret = (mod)->ops->func(mod, io, param); \ 302 ret = (mod)->ops->func(mod, io, param); \
245 mod->status = (mod->status & ~mask) + \
246 (add << __rsnd_mod_shift_##func); \
247 } \ 303 } \
304 mod->status = (mod->status & ~mask) + \
305 (add << __rsnd_mod_shift_##func); \
248 dev_dbg(dev, "%s[%d] 0x%08x %s\n", \ 306 dev_dbg(dev, "%s[%d] 0x%08x %s\n", \
249 rsnd_mod_name(mod), rsnd_mod_id(mod), mod->status, \ 307 rsnd_mod_name(mod), rsnd_mod_id(mod), mod->status, \
250 called ? #func : ""); \ 308 called ? #func : ""); \
@@ -274,21 +332,21 @@ u32 rsnd_get_adinr(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
274static int rsnd_dai_connect(struct rsnd_mod *mod, 332static int rsnd_dai_connect(struct rsnd_mod *mod,
275 struct rsnd_dai_stream *io) 333 struct rsnd_dai_stream *io)
276{ 334{
335 struct rsnd_priv *priv;
336 struct device *dev;
337
277 if (!mod) 338 if (!mod)
278 return -EIO; 339 return -EIO;
279 340
280 if (io->mod[mod->type]) { 341 priv = rsnd_mod_to_priv(mod);
281 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 342 dev = rsnd_priv_to_dev(priv);
282 struct device *dev = rsnd_priv_to_dev(priv);
283
284 dev_err(dev, "%s[%d] is not empty\n",
285 rsnd_mod_name(mod),
286 rsnd_mod_id(mod));
287 return -EIO;
288 }
289 343
290 io->mod[mod->type] = mod; 344 io->mod[mod->type] = mod;
291 345
346 dev_dbg(dev, "%s[%d] is connected to io (%s)\n",
347 rsnd_mod_name(mod), rsnd_mod_id(mod),
348 rsnd_io_is_play(io) ? "Playback" : "Capture");
349
292 return 0; 350 return 0;
293} 351}
294 352
@@ -517,7 +575,7 @@ static const struct snd_soc_dai_ops rsnd_soc_dai_ops = {
517 .set_fmt = rsnd_soc_dai_set_fmt, 575 .set_fmt = rsnd_soc_dai_set_fmt,
518}; 576};
519 577
520#define rsnd_path_parse(priv, io, type) \ 578#define rsnd_path_add(priv, io, type) \
521({ \ 579({ \
522 struct rsnd_mod *mod; \ 580 struct rsnd_mod *mod; \
523 int ret = 0; \ 581 int ret = 0; \
@@ -533,7 +591,7 @@ static const struct snd_soc_dai_ops rsnd_soc_dai_ops = {
533 ret; \ 591 ret; \
534}) 592})
535 593
536#define rsnd_path_break(priv, io, type) \ 594#define rsnd_path_remove(priv, io, type) \
537{ \ 595{ \
538 struct rsnd_mod *mod; \ 596 struct rsnd_mod *mod; \
539 int id = -1; \ 597 int id = -1; \
@@ -547,6 +605,79 @@ static const struct snd_soc_dai_ops rsnd_soc_dai_ops = {
547 } \ 605 } \
548} 606}
549 607
608void rsnd_path_parse(struct rsnd_priv *priv,
609 struct rsnd_dai_stream *io)
610{
611 struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
612 struct rsnd_mod *mix = rsnd_io_to_mod_mix(io);
613 struct rsnd_mod *src = rsnd_io_to_mod_src(io);
614 struct rsnd_mod *cmd;
615 struct device *dev = rsnd_priv_to_dev(priv);
616 u32 data;
617
618 /* Gen1 is not supported */
619 if (rsnd_is_gen1(priv))
620 return;
621
622 if (!mix && !dvc)
623 return;
624
625 if (mix) {
626 struct rsnd_dai *rdai;
627 int i;
628 u32 path[] = {
629 [0] = 0,
630 [1] = 1 << 0,
631 [2] = 0,
632 [3] = 0,
633 [4] = 0,
634 [5] = 1 << 8
635 };
636
637 /*
638 * it is assuming that integrater is well understanding about
639 * data path. Here doesn't check impossible connection,
640 * like src2 + src5
641 */
642 data = 0;
643 for_each_rsnd_dai(rdai, priv, i) {
644 io = &rdai->playback;
645 if (mix == rsnd_io_to_mod_mix(io))
646 data |= path[rsnd_mod_id(src)];
647
648 io = &rdai->capture;
649 if (mix == rsnd_io_to_mod_mix(io))
650 data |= path[rsnd_mod_id(src)];
651 }
652
653 /*
654 * We can't use ctu = rsnd_io_ctu() here.
655 * Since, ID of dvc/mix are 0 or 1 (= same as CMD number)
656 * but ctu IDs are 0 - 7 (= CTU00 - CTU13)
657 */
658 cmd = mix;
659 } else {
660 u32 path[] = {
661 [0] = 0x30000,
662 [1] = 0x30001,
663 [2] = 0x40000,
664 [3] = 0x10000,
665 [4] = 0x20000,
666 [5] = 0x40100
667 };
668
669 data = path[rsnd_mod_id(src)];
670
671 cmd = dvc;
672 }
673
674 dev_dbg(dev, "ctu/mix path = 0x%08x", data);
675
676 rsnd_mod_write(cmd, CMD_ROUTE_SLCT, data);
677
678 rsnd_mod_write(cmd, CMD_CTRL, 0x10);
679}
680
550static int rsnd_path_init(struct rsnd_priv *priv, 681static int rsnd_path_init(struct rsnd_priv *priv,
551 struct rsnd_dai *rdai, 682 struct rsnd_dai *rdai,
552 struct rsnd_dai_stream *io) 683 struct rsnd_dai_stream *io)
@@ -564,18 +695,28 @@ static int rsnd_path_init(struct rsnd_priv *priv,
564 * using fixed path. 695 * using fixed path.
565 */ 696 */
566 697
698 /* SSI */
699 ret = rsnd_path_add(priv, io, ssi);
700 if (ret < 0)
701 return ret;
702
567 /* SRC */ 703 /* SRC */
568 ret = rsnd_path_parse(priv, io, src); 704 ret = rsnd_path_add(priv, io, src);
569 if (ret < 0) 705 if (ret < 0)
570 return ret; 706 return ret;
571 707
572 /* SSI */ 708 /* CTU */
573 ret = rsnd_path_parse(priv, io, ssi); 709 ret = rsnd_path_add(priv, io, ctu);
710 if (ret < 0)
711 return ret;
712
713 /* MIX */
714 ret = rsnd_path_add(priv, io, mix);
574 if (ret < 0) 715 if (ret < 0)
575 return ret; 716 return ret;
576 717
577 /* DVC */ 718 /* DVC */
578 ret = rsnd_path_parse(priv, io, dvc); 719 ret = rsnd_path_add(priv, io, dvc);
579 if (ret < 0) 720 if (ret < 0)
580 return ret; 721 return ret;
581 722
@@ -589,13 +730,15 @@ static void rsnd_of_parse_dai(struct platform_device *pdev,
589 struct device_node *dai_node, *dai_np; 730 struct device_node *dai_node, *dai_np;
590 struct device_node *ssi_node, *ssi_np; 731 struct device_node *ssi_node, *ssi_np;
591 struct device_node *src_node, *src_np; 732 struct device_node *src_node, *src_np;
733 struct device_node *ctu_node, *ctu_np;
734 struct device_node *mix_node, *mix_np;
592 struct device_node *dvc_node, *dvc_np; 735 struct device_node *dvc_node, *dvc_np;
593 struct device_node *playback, *capture; 736 struct device_node *playback, *capture;
594 struct rsnd_dai_platform_info *dai_info; 737 struct rsnd_dai_platform_info *dai_info;
595 struct rcar_snd_info *info = rsnd_priv_to_info(priv); 738 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
596 struct device *dev = &pdev->dev; 739 struct device *dev = &pdev->dev;
597 int nr, i; 740 int nr, i;
598 int dai_i, ssi_i, src_i, dvc_i; 741 int dai_i, ssi_i, src_i, ctu_i, mix_i, dvc_i;
599 742
600 if (!of_data) 743 if (!of_data)
601 return; 744 return;
@@ -621,6 +764,8 @@ static void rsnd_of_parse_dai(struct platform_device *pdev,
621 764
622 ssi_node = of_get_child_by_name(dev->of_node, "rcar_sound,ssi"); 765 ssi_node = of_get_child_by_name(dev->of_node, "rcar_sound,ssi");
623 src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src"); 766 src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src");
767 ctu_node = of_get_child_by_name(dev->of_node, "rcar_sound,ctu");
768 mix_node = of_get_child_by_name(dev->of_node, "rcar_sound,mix");
624 dvc_node = of_get_child_by_name(dev->of_node, "rcar_sound,dvc"); 769 dvc_node = of_get_child_by_name(dev->of_node, "rcar_sound,dvc");
625 770
626#define mod_parse(name) \ 771#define mod_parse(name) \
@@ -657,6 +802,8 @@ if (name##_node) { \
657 802
658 mod_parse(ssi); 803 mod_parse(ssi);
659 mod_parse(src); 804 mod_parse(src);
805 mod_parse(ctu);
806 mod_parse(mix);
660 mod_parse(dvc); 807 mod_parse(dvc);
661 808
662 of_node_put(playback); 809 of_node_put(playback);
@@ -1033,8 +1180,8 @@ static int rsnd_rdai_continuance_probe(struct rsnd_priv *priv,
1033 /* 1180 /*
1034 * remove SRC/DVC from DAI, 1181 * remove SRC/DVC from DAI,
1035 */ 1182 */
1036 rsnd_path_break(priv, io, src); 1183 rsnd_path_remove(priv, io, src);
1037 rsnd_path_break(priv, io, dvc); 1184 rsnd_path_remove(priv, io, dvc);
1038 1185
1039 /* 1186 /*
1040 * fallback 1187 * fallback
@@ -1069,6 +1216,8 @@ static int rsnd_probe(struct platform_device *pdev)
1069 rsnd_dma_probe, 1216 rsnd_dma_probe,
1070 rsnd_ssi_probe, 1217 rsnd_ssi_probe,
1071 rsnd_src_probe, 1218 rsnd_src_probe,
1219 rsnd_ctu_probe,
1220 rsnd_mix_probe,
1072 rsnd_dvc_probe, 1221 rsnd_dvc_probe,
1073 rsnd_adg_probe, 1222 rsnd_adg_probe,
1074 rsnd_dai_probe, 1223 rsnd_dai_probe,
@@ -1164,6 +1313,8 @@ static int rsnd_remove(struct platform_device *pdev)
1164 struct rsnd_priv *priv) = { 1313 struct rsnd_priv *priv) = {
1165 rsnd_ssi_remove, 1314 rsnd_ssi_remove,
1166 rsnd_src_remove, 1315 rsnd_src_remove,
1316 rsnd_ctu_remove,
1317 rsnd_mix_remove,
1167 rsnd_dvc_remove, 1318 rsnd_dvc_remove,
1168 }; 1319 };
1169 int ret = 0, i; 1320 int ret = 0, i;
diff --git a/sound/soc/sh/rcar/ctu.c b/sound/soc/sh/rcar/ctu.c
new file mode 100644
index 000000000000..05498bba5874
--- /dev/null
+++ b/sound/soc/sh/rcar/ctu.c
@@ -0,0 +1,171 @@
1/*
2 * ctu.c
3 *
4 * Copyright (c) 2015 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
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#include "rsnd.h"
11
12#define CTU_NAME_SIZE 16
13#define CTU_NAME "ctu"
14
15struct rsnd_ctu {
16 struct rsnd_ctu_platform_info *info; /* rcar_snd.h */
17 struct rsnd_mod mod;
18};
19
20#define rsnd_ctu_nr(priv) ((priv)->ctu_nr)
21#define for_each_rsnd_ctu(pos, priv, i) \
22 for ((i) = 0; \
23 ((i) < rsnd_ctu_nr(priv)) && \
24 ((pos) = (struct rsnd_ctu *)(priv)->ctu + i); \
25 i++)
26
27#define rsnd_ctu_initialize_lock(mod) __rsnd_ctu_initialize_lock(mod, 1)
28#define rsnd_ctu_initialize_unlock(mod) __rsnd_ctu_initialize_lock(mod, 0)
29static void __rsnd_ctu_initialize_lock(struct rsnd_mod *mod, u32 enable)
30{
31 rsnd_mod_write(mod, CTU_CTUIR, enable);
32}
33
34static int rsnd_ctu_init(struct rsnd_mod *mod,
35 struct rsnd_dai_stream *io,
36 struct rsnd_priv *priv)
37{
38 rsnd_mod_hw_start(mod);
39
40 rsnd_ctu_initialize_lock(mod);
41
42 rsnd_mod_write(mod, CTU_ADINR, rsnd_get_adinr_chan(mod, io));
43
44 rsnd_ctu_initialize_unlock(mod);
45
46 return 0;
47}
48
49static int rsnd_ctu_quit(struct rsnd_mod *mod,
50 struct rsnd_dai_stream *io,
51 struct rsnd_priv *priv)
52{
53 rsnd_mod_hw_stop(mod);
54
55 return 0;
56}
57
58static struct rsnd_mod_ops rsnd_ctu_ops = {
59 .name = CTU_NAME,
60 .init = rsnd_ctu_init,
61 .quit = rsnd_ctu_quit,
62};
63
64struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id)
65{
66 if (WARN_ON(id < 0 || id >= rsnd_ctu_nr(priv)))
67 id = 0;
68
69 return &((struct rsnd_ctu *)(priv->ctu) + id)->mod;
70}
71
72static void rsnd_of_parse_ctu(struct platform_device *pdev,
73 const struct rsnd_of_data *of_data,
74 struct rsnd_priv *priv)
75{
76 struct device_node *node;
77 struct rsnd_ctu_platform_info *ctu_info;
78 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
79 struct device *dev = &pdev->dev;
80 int nr;
81
82 if (!of_data)
83 return;
84
85 node = of_get_child_by_name(dev->of_node, "rcar_sound,ctu");
86 if (!node)
87 return;
88
89 nr = of_get_child_count(node);
90 if (!nr)
91 goto rsnd_of_parse_ctu_end;
92
93 ctu_info = devm_kzalloc(dev,
94 sizeof(struct rsnd_ctu_platform_info) * nr,
95 GFP_KERNEL);
96 if (!ctu_info) {
97 dev_err(dev, "ctu info allocation error\n");
98 goto rsnd_of_parse_ctu_end;
99 }
100
101 info->ctu_info = ctu_info;
102 info->ctu_info_nr = nr;
103
104rsnd_of_parse_ctu_end:
105 of_node_put(node);
106
107}
108
109int rsnd_ctu_probe(struct platform_device *pdev,
110 const struct rsnd_of_data *of_data,
111 struct rsnd_priv *priv)
112{
113 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
114 struct device *dev = rsnd_priv_to_dev(priv);
115 struct rsnd_ctu *ctu;
116 struct clk *clk;
117 char name[CTU_NAME_SIZE];
118 int i, nr, ret;
119
120 /* This driver doesn't support Gen1 at this point */
121 if (rsnd_is_gen1(priv)) {
122 dev_warn(dev, "CTU is not supported on Gen1\n");
123 return -EINVAL;
124 }
125
126 rsnd_of_parse_ctu(pdev, of_data, priv);
127
128 nr = info->ctu_info_nr;
129 if (!nr)
130 return 0;
131
132 ctu = devm_kzalloc(dev, sizeof(*ctu) * nr, GFP_KERNEL);
133 if (!ctu)
134 return -ENOMEM;
135
136 priv->ctu_nr = nr;
137 priv->ctu = ctu;
138
139 for_each_rsnd_ctu(ctu, priv, i) {
140 /*
141 * CTU00, CTU01, CTU02, CTU03 => CTU0
142 * CTU10, CTU11, CTU12, CTU13 => CTU1
143 */
144 snprintf(name, CTU_NAME_SIZE, "%s.%d",
145 CTU_NAME, i / 4);
146
147 clk = devm_clk_get(dev, name);
148 if (IS_ERR(clk))
149 return PTR_ERR(clk);
150
151 ctu->info = &info->ctu_info[i];
152
153 ret = rsnd_mod_init(priv, &ctu->mod, &rsnd_ctu_ops,
154 clk, RSND_MOD_CTU, i);
155 if (ret)
156 return ret;
157 }
158
159 return 0;
160}
161
162void rsnd_ctu_remove(struct platform_device *pdev,
163 struct rsnd_priv *priv)
164{
165 struct rsnd_ctu *ctu;
166 int i;
167
168 for_each_rsnd_ctu(ctu, priv, i) {
169 rsnd_mod_quit(&ctu->mod);
170 }
171}
diff --git a/sound/soc/sh/rcar/dma.c b/sound/soc/sh/rcar/dma.c
index d306e298c63d..bfbb8a5e93bd 100644
--- a/sound/soc/sh/rcar/dma.c
+++ b/sound/soc/sh/rcar/dma.c
@@ -27,6 +27,15 @@ struct rsnd_dma_ctrl {
27 int dmapp_num; 27 int dmapp_num;
28}; 28};
29 29
30struct rsnd_dma_ops {
31 char *name;
32 void (*start)(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
33 void (*stop)(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
34 int (*init)(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id,
35 struct rsnd_mod *mod_from, struct rsnd_mod *mod_to);
36 void (*quit)(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
37};
38
30#define rsnd_priv_to_dmac(p) ((struct rsnd_dma_ctrl *)(p)->dma) 39#define rsnd_priv_to_dmac(p) ((struct rsnd_dma_ctrl *)(p)->dma)
31 40
32/* 41/*
@@ -168,7 +177,7 @@ static int rsnd_dmaen_init(struct rsnd_dai_stream *io,
168 dma_cap_set(DMA_SLAVE, mask); 177 dma_cap_set(DMA_SLAVE, mask);
169 178
170 dmaen->chan = dma_request_channel(mask, shdma_chan_filter, 179 dmaen->chan = dma_request_channel(mask, shdma_chan_filter,
171 (void *)id); 180 (void *)(uintptr_t)id);
172 } 181 }
173 if (IS_ERR_OR_NULL(dmaen->chan)) { 182 if (IS_ERR_OR_NULL(dmaen->chan)) {
174 dmaen->chan = NULL; 183 dmaen->chan = NULL;
@@ -182,7 +191,8 @@ static int rsnd_dmaen_init(struct rsnd_dai_stream *io,
182 cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 191 cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
183 cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; 192 cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
184 193
185 dev_dbg(dev, "dma : %pad -> %pad\n", 194 dev_dbg(dev, "%s %pad -> %pad\n",
195 dma->ops->name,
186 &cfg.src_addr, &cfg.dst_addr); 196 &cfg.src_addr, &cfg.dst_addr);
187 197
188 ret = dmaengine_slave_config(dmaen->chan, &cfg); 198 ret = dmaengine_slave_config(dmaen->chan, &cfg);
@@ -215,6 +225,7 @@ static void rsnd_dmaen_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
215} 225}
216 226
217static struct rsnd_dma_ops rsnd_dmaen_ops = { 227static struct rsnd_dma_ops rsnd_dmaen_ops = {
228 .name = "audmac",
218 .start = rsnd_dmaen_start, 229 .start = rsnd_dmaen_start,
219 .stop = rsnd_dmaen_stop, 230 .stop = rsnd_dmaen_stop,
220 .init = rsnd_dmaen_init, 231 .init = rsnd_dmaen_init,
@@ -360,6 +371,7 @@ static int rsnd_dmapp_init(struct rsnd_dai_stream *io,
360} 371}
361 372
362static struct rsnd_dma_ops rsnd_dmapp_ops = { 373static struct rsnd_dma_ops rsnd_dmapp_ops = {
374 .name = "audmac-pp",
363 .start = rsnd_dmapp_start, 375 .start = rsnd_dmapp_start,
364 .stop = rsnd_dmapp_stop, 376 .stop = rsnd_dmapp_stop,
365 .init = rsnd_dmapp_init, 377 .init = rsnd_dmapp_init,
@@ -414,7 +426,9 @@ rsnd_gen2_dma_addr(struct rsnd_dai_stream *io,
414 phys_addr_t src_reg = rsnd_gen_get_phy_addr(priv, RSND_GEN2_SCU); 426 phys_addr_t src_reg = rsnd_gen_get_phy_addr(priv, RSND_GEN2_SCU);
415 int is_ssi = !!(rsnd_io_to_mod_ssi(io) == mod); 427 int is_ssi = !!(rsnd_io_to_mod_ssi(io) == mod);
416 int use_src = !!rsnd_io_to_mod_src(io); 428 int use_src = !!rsnd_io_to_mod_src(io);
417 int use_dvc = !!rsnd_io_to_mod_dvc(io); 429 int use_cmd = !!rsnd_io_to_mod_dvc(io) ||
430 !!rsnd_io_to_mod_mix(io) ||
431 !!rsnd_io_to_mod_ctu(io);
418 int id = rsnd_mod_id(mod); 432 int id = rsnd_mod_id(mod);
419 struct dma_addr { 433 struct dma_addr {
420 dma_addr_t out_addr; 434 dma_addr_t out_addr;
@@ -452,7 +466,7 @@ rsnd_gen2_dma_addr(struct rsnd_dai_stream *io,
452 }; 466 };
453 467
454 /* it shouldn't happen */ 468 /* it shouldn't happen */
455 if (use_dvc && !use_src) 469 if (use_cmd && !use_src)
456 dev_err(dev, "DVC is selected without SRC\n"); 470 dev_err(dev, "DVC is selected without SRC\n");
457 471
458 /* use SSIU or SSI ? */ 472 /* use SSIU or SSI ? */
@@ -460,8 +474,8 @@ rsnd_gen2_dma_addr(struct rsnd_dai_stream *io,
460 is_ssi++; 474 is_ssi++;
461 475
462 return (is_from) ? 476 return (is_from) ?
463 dma_addrs[is_ssi][is_play][use_src + use_dvc].out_addr : 477 dma_addrs[is_ssi][is_play][use_src + use_cmd].out_addr :
464 dma_addrs[is_ssi][is_play][use_src + use_dvc].in_addr; 478 dma_addrs[is_ssi][is_play][use_src + use_cmd].in_addr;
465} 479}
466 480
467static dma_addr_t rsnd_dma_addr(struct rsnd_dai_stream *io, 481static dma_addr_t rsnd_dma_addr(struct rsnd_dai_stream *io,
@@ -482,7 +496,7 @@ static dma_addr_t rsnd_dma_addr(struct rsnd_dai_stream *io,
482 return rsnd_gen2_dma_addr(io, mod, is_play, is_from); 496 return rsnd_gen2_dma_addr(io, mod, is_play, is_from);
483} 497}
484 498
485#define MOD_MAX 4 /* MEM/SSI/SRC/DVC */ 499#define MOD_MAX (RSND_MOD_MAX + 1) /* +Memory */
486static void rsnd_dma_of_path(struct rsnd_dma *dma, 500static void rsnd_dma_of_path(struct rsnd_dma *dma,
487 struct rsnd_dai_stream *io, 501 struct rsnd_dai_stream *io,
488 int is_play, 502 int is_play,
@@ -492,55 +506,81 @@ static void rsnd_dma_of_path(struct rsnd_dma *dma,
492 struct rsnd_mod *this = rsnd_dma_to_mod(dma); 506 struct rsnd_mod *this = rsnd_dma_to_mod(dma);
493 struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io); 507 struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io);
494 struct rsnd_mod *src = rsnd_io_to_mod_src(io); 508 struct rsnd_mod *src = rsnd_io_to_mod_src(io);
509 struct rsnd_mod *ctu = rsnd_io_to_mod_ctu(io);
510 struct rsnd_mod *mix = rsnd_io_to_mod_mix(io);
495 struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io); 511 struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
496 struct rsnd_mod *mod[MOD_MAX]; 512 struct rsnd_mod *mod[MOD_MAX];
497 int i, index; 513 struct rsnd_mod *mod_start, *mod_end;
514 struct rsnd_priv *priv = rsnd_mod_to_priv(this);
515 struct device *dev = rsnd_priv_to_dev(priv);
516 int nr, i;
498 517
518 if (!ssi)
519 return;
499 520
500 for (i = 0; i < MOD_MAX; i++) 521 nr = 0;
522 for (i = 0; i < MOD_MAX; i++) {
501 mod[i] = NULL; 523 mod[i] = NULL;
524 nr += !!rsnd_io_to_mod(io, i);
525 }
502 526
503 /* 527 /*
504 * in play case... 528 * [S] -*-> [E]
529 * [S] -*-> SRC -o-> [E]
530 * [S] -*-> SRC -> DVC -o-> [E]
531 * [S] -*-> SRC -> CTU -> MIX -> DVC -o-> [E]
505 * 532 *
506 * src -> dst 533 * playback [S] = mem
534 * [E] = SSI
507 * 535 *
508 * mem -> SSI 536 * capture [S] = SSI
509 * mem -> SRC -> SSI 537 * [E] = mem
510 * mem -> SRC -> DVC -> SSI 538 *
539 * -*-> Audio DMAC
540 * -o-> Audio DMAC peri peri
511 */ 541 */
512 mod[0] = NULL; /* for "mem" */ 542 mod_start = (is_play) ? NULL : ssi;
513 index = 1; 543 mod_end = (is_play) ? ssi : NULL;
514 for (i = 1; i < MOD_MAX; i++) {
515 if (!src) {
516 mod[i] = ssi;
517 } else if (!dvc) {
518 mod[i] = src;
519 src = NULL;
520 } else {
521 if ((!is_play) && (this == src))
522 this = dvc;
523 544
524 mod[i] = (is_play) ? src : dvc; 545 mod[0] = mod_start;
525 i++; 546 for (i = 1; i < nr; i++) {
526 mod[i] = (is_play) ? dvc : src; 547 if (src) {
548 mod[i] = src;
527 src = NULL; 549 src = NULL;
550 } else if (ctu) {
551 mod[i] = ctu;
552 ctu = NULL;
553 } else if (mix) {
554 mod[i] = mix;
555 mix = NULL;
556 } else if (dvc) {
557 mod[i] = dvc;
528 dvc = NULL; 558 dvc = NULL;
529 } 559 }
530
531 if (mod[i] == this)
532 index = i;
533
534 if (mod[i] == ssi)
535 break;
536 } 560 }
561 mod[i] = mod_end;
537 562
538 if (is_play) { 563 /*
539 *mod_from = mod[index - 1]; 564 * | SSI | SRC |
540 *mod_to = mod[index]; 565 * -------------+-----+-----+
566 * is_play | o | * |
567 * !is_play | * | o |
568 */
569 if ((this == ssi) == (is_play)) {
570 *mod_from = mod[nr - 1];
571 *mod_to = mod[nr];
541 } else { 572 } else {
542 *mod_from = mod[index]; 573 *mod_from = mod[0];
543 *mod_to = mod[index - 1]; 574 *mod_to = mod[1];
575 }
576
577 dev_dbg(dev, "module connection (this is %s[%d])\n",
578 rsnd_mod_name(this), rsnd_mod_id(this));
579 for (i = 0; i <= nr; i++) {
580 dev_dbg(dev, " %s[%d]%s\n",
581 rsnd_mod_name(mod[i]), rsnd_mod_id(mod[i]),
582 (mod[i] == *mod_from) ? " from" :
583 (mod[i] == *mod_to) ? " to" : "");
544 } 584 }
545} 585}
546 586
@@ -568,10 +608,11 @@ void rsnd_dma_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
568 608
569int rsnd_dma_init(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id) 609int rsnd_dma_init(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id)
570{ 610{
571 struct rsnd_mod *mod_from; 611 struct rsnd_mod *mod_from = NULL;
572 struct rsnd_mod *mod_to; 612 struct rsnd_mod *mod_to = NULL;
573 struct rsnd_priv *priv = rsnd_io_to_priv(io); 613 struct rsnd_priv *priv = rsnd_io_to_priv(io);
574 struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv); 614 struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
615 struct device *dev = rsnd_priv_to_dev(priv);
575 int is_play = rsnd_io_is_play(io); 616 int is_play = rsnd_io_is_play(io);
576 617
577 /* 618 /*
@@ -598,6 +639,11 @@ int rsnd_dma_init(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id)
598 if (rsnd_is_gen1(priv)) 639 if (rsnd_is_gen1(priv))
599 dma->ops = &rsnd_dmaen_ops; 640 dma->ops = &rsnd_dmaen_ops;
600 641
642 dev_dbg(dev, "%s %s[%d] -> %s[%d]\n",
643 dma->ops->name,
644 rsnd_mod_name(mod_from), rsnd_mod_id(mod_from),
645 rsnd_mod_name(mod_to), rsnd_mod_id(mod_to));
646
601 return dma->ops->init(io, dma, id, mod_from, mod_to); 647 return dma->ops->init(io, dma, id, mod_from, mod_to);
602} 648}
603 649
diff --git a/sound/soc/sh/rcar/dvc.c b/sound/soc/sh/rcar/dvc.c
index 36fc020cbc18..57796387d482 100644
--- a/sound/soc/sh/rcar/dvc.c
+++ b/sound/soc/sh/rcar/dvc.c
@@ -24,6 +24,7 @@ struct rsnd_dvc {
24 struct rsnd_kctrl_cfg_s rdown; /* Ramp Rate Down */ 24 struct rsnd_kctrl_cfg_s rdown; /* Ramp Rate Down */
25}; 25};
26 26
27#define rsnd_dvc_nr(priv) ((priv)->dvc_nr)
27#define rsnd_dvc_of_node(priv) \ 28#define rsnd_dvc_of_node(priv) \
28 of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,dvc") 29 of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,dvc")
29 30
@@ -63,6 +64,19 @@ static const char * const dvc_ramp_rate[] = {
63 "0.125 dB/8192 steps", /* 10111 */ 64 "0.125 dB/8192 steps", /* 10111 */
64}; 65};
65 66
67static void rsnd_dvc_soft_reset(struct rsnd_mod *mod)
68{
69 rsnd_mod_write(mod, DVC_SWRSR, 0);
70 rsnd_mod_write(mod, DVC_SWRSR, 1);
71}
72
73#define rsnd_dvc_initialize_lock(mod) __rsnd_dvc_initialize_lock(mod, 1)
74#define rsnd_dvc_initialize_unlock(mod) __rsnd_dvc_initialize_lock(mod, 0)
75static void __rsnd_dvc_initialize_lock(struct rsnd_mod *mod, u32 enable)
76{
77 rsnd_mod_write(mod, DVC_DVUIR, enable);
78}
79
66static void rsnd_dvc_volume_update(struct rsnd_dai_stream *io, 80static void rsnd_dvc_volume_update(struct rsnd_dai_stream *io,
67 struct rsnd_mod *mod) 81 struct rsnd_mod *mod)
68{ 82{
@@ -135,49 +149,24 @@ static int rsnd_dvc_remove_gen2(struct rsnd_mod *mod,
135 return 0; 149 return 0;
136} 150}
137 151
138static int rsnd_dvc_init(struct rsnd_mod *dvc_mod, 152static int rsnd_dvc_init(struct rsnd_mod *mod,
139 struct rsnd_dai_stream *io, 153 struct rsnd_dai_stream *io,
140 struct rsnd_priv *priv) 154 struct rsnd_priv *priv)
141{ 155{
142 struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io); 156 rsnd_mod_hw_start(mod);
143 struct device *dev = rsnd_priv_to_dev(priv);
144 int dvc_id = rsnd_mod_id(dvc_mod);
145 int src_id = rsnd_mod_id(src_mod);
146 u32 route[] = {
147 [0] = 0x30000,
148 [1] = 0x30001,
149 [2] = 0x40000,
150 [3] = 0x10000,
151 [4] = 0x20000,
152 [5] = 0x40100
153 };
154
155 if (src_id >= ARRAY_SIZE(route)) {
156 dev_err(dev, "DVC%d isn't connected to SRC%d\n", dvc_id, src_id);
157 return -EINVAL;
158 }
159
160 rsnd_mod_hw_start(dvc_mod);
161 157
162 /* 158 rsnd_dvc_soft_reset(mod);
163 * fixme
164 * it doesn't support CTU/MIX
165 */
166 rsnd_mod_write(dvc_mod, CMD_ROUTE_SLCT, route[src_id]);
167 159
168 rsnd_mod_write(dvc_mod, DVC_SWRSR, 0); 160 rsnd_dvc_initialize_lock(mod);
169 rsnd_mod_write(dvc_mod, DVC_SWRSR, 1);
170 161
171 rsnd_mod_write(dvc_mod, DVC_DVUIR, 1); 162 rsnd_path_parse(priv, io);
172 163
173 rsnd_mod_write(dvc_mod, DVC_ADINR, rsnd_get_adinr(dvc_mod, io)); 164 rsnd_mod_write(mod, DVC_ADINR, rsnd_get_adinr_bit(mod, io));
174 165
175 /* ch0/ch1 Volume */ 166 /* ch0/ch1 Volume */
176 rsnd_dvc_volume_update(io, dvc_mod); 167 rsnd_dvc_volume_update(io, mod);
177 168
178 rsnd_mod_write(dvc_mod, DVC_DVUIR, 0); 169 rsnd_adg_set_cmd_timsel_gen2(mod, io);
179
180 rsnd_adg_set_cmd_timsel_gen2(dvc_mod, io);
181 170
182 return 0; 171 return 0;
183} 172}
@@ -195,6 +184,8 @@ static int rsnd_dvc_start(struct rsnd_mod *mod,
195 struct rsnd_dai_stream *io, 184 struct rsnd_dai_stream *io,
196 struct rsnd_priv *priv) 185 struct rsnd_priv *priv)
197{ 186{
187 rsnd_dvc_initialize_unlock(mod);
188
198 rsnd_mod_write(mod, CMD_CTRL, 0x10); 189 rsnd_mod_write(mod, CMD_CTRL, 0x10);
199 190
200 return 0; 191 return 0;
@@ -341,23 +332,21 @@ int rsnd_dvc_probe(struct platform_device *pdev,
341 char name[RSND_DVC_NAME_SIZE]; 332 char name[RSND_DVC_NAME_SIZE];
342 int i, nr, ret; 333 int i, nr, ret;
343 334
344 rsnd_of_parse_dvc(pdev, of_data, priv);
345
346 nr = info->dvc_info_nr;
347 if (!nr)
348 return 0;
349
350 /* This driver doesn't support Gen1 at this point */ 335 /* This driver doesn't support Gen1 at this point */
351 if (rsnd_is_gen1(priv)) { 336 if (rsnd_is_gen1(priv)) {
352 dev_warn(dev, "CMD is not supported on Gen1\n"); 337 dev_warn(dev, "CMD is not supported on Gen1\n");
353 return -EINVAL; 338 return -EINVAL;
354 } 339 }
355 340
341 rsnd_of_parse_dvc(pdev, of_data, priv);
342
343 nr = info->dvc_info_nr;
344 if (!nr)
345 return 0;
346
356 dvc = devm_kzalloc(dev, sizeof(*dvc) * nr, GFP_KERNEL); 347 dvc = devm_kzalloc(dev, sizeof(*dvc) * nr, GFP_KERNEL);
357 if (!dvc) { 348 if (!dvc)
358 dev_err(dev, "CMD allocate failed\n");
359 return -ENOMEM; 349 return -ENOMEM;
360 }
361 350
362 priv->dvc_nr = nr; 351 priv->dvc_nr = nr;
363 priv->dvc = dvc; 352 priv->dvc = dvc;
diff --git a/sound/soc/sh/rcar/gen.c b/sound/soc/sh/rcar/gen.c
index 8c7dc51b1c4f..f04d17bc6e3d 100644
--- a/sound/soc/sh/rcar/gen.c
+++ b/sound/soc/sh/rcar/gen.c
@@ -103,6 +103,22 @@ void rsnd_write(struct rsnd_priv *priv,
103 regmap_fields_write(gen->regs[reg], rsnd_mod_id(mod), data); 103 regmap_fields_write(gen->regs[reg], rsnd_mod_id(mod), data);
104} 104}
105 105
106void rsnd_force_write(struct rsnd_priv *priv,
107 struct rsnd_mod *mod,
108 enum rsnd_reg reg, u32 data)
109{
110 struct device *dev = rsnd_priv_to_dev(priv);
111 struct rsnd_gen *gen = rsnd_priv_to_gen(priv);
112
113 if (!rsnd_is_accessible_reg(priv, gen, reg))
114 return;
115
116 dev_dbg(dev, "w %s[%d] - %4d : %08x\n",
117 rsnd_mod_name(mod), rsnd_mod_id(mod), reg, data);
118
119 regmap_fields_force_write(gen->regs[reg], rsnd_mod_id(mod), data);
120}
121
106void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, 122void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod,
107 enum rsnd_reg reg, u32 mask, u32 data) 123 enum rsnd_reg reg, u32 mask, u32 data)
108{ 124{
@@ -200,12 +216,13 @@ static int rsnd_gen2_probe(struct platform_device *pdev,
200 /* FIXME: it needs SSI_MODE2/3 in the future */ 216 /* FIXME: it needs SSI_MODE2/3 in the future */
201 RSND_GEN_M_REG(SSI_BUSIF_MODE, 0x0, 0x80), 217 RSND_GEN_M_REG(SSI_BUSIF_MODE, 0x0, 0x80),
202 RSND_GEN_M_REG(SSI_BUSIF_ADINR, 0x4, 0x80), 218 RSND_GEN_M_REG(SSI_BUSIF_ADINR, 0x4, 0x80),
203 RSND_GEN_M_REG(BUSIF_DALIGN, 0x8, 0x80), 219 RSND_GEN_M_REG(SSI_BUSIF_DALIGN,0x8, 0x80),
204 RSND_GEN_M_REG(SSI_CTRL, 0x10, 0x80), 220 RSND_GEN_M_REG(SSI_CTRL, 0x10, 0x80),
205 RSND_GEN_M_REG(INT_ENABLE, 0x18, 0x80), 221 RSND_GEN_M_REG(SSI_INT_ENABLE, 0x18, 0x80),
206 }; 222 };
207 struct rsnd_regmap_field_conf conf_scu[] = { 223 struct rsnd_regmap_field_conf conf_scu[] = {
208 RSND_GEN_M_REG(SRC_BUSIF_MODE, 0x0, 0x20), 224 RSND_GEN_M_REG(SRC_BUSIF_MODE, 0x0, 0x20),
225 RSND_GEN_M_REG(SRC_BUSIF_DALIGN,0x8, 0x20),
209 RSND_GEN_M_REG(SRC_ROUTE_MODE0, 0xc, 0x20), 226 RSND_GEN_M_REG(SRC_ROUTE_MODE0, 0xc, 0x20),
210 RSND_GEN_M_REG(SRC_CTRL, 0x10, 0x20), 227 RSND_GEN_M_REG(SRC_CTRL, 0x10, 0x20),
211 RSND_GEN_M_REG(SRC_INT_ENABLE0, 0x18, 0x20), 228 RSND_GEN_M_REG(SRC_INT_ENABLE0, 0x18, 0x20),
@@ -223,6 +240,18 @@ static int rsnd_gen2_probe(struct platform_device *pdev,
223 RSND_GEN_M_REG(SRC_SRCCR, 0x224, 0x40), 240 RSND_GEN_M_REG(SRC_SRCCR, 0x224, 0x40),
224 RSND_GEN_M_REG(SRC_BSDSR, 0x22c, 0x40), 241 RSND_GEN_M_REG(SRC_BSDSR, 0x22c, 0x40),
225 RSND_GEN_M_REG(SRC_BSISR, 0x238, 0x40), 242 RSND_GEN_M_REG(SRC_BSISR, 0x238, 0x40),
243 RSND_GEN_M_REG(CTU_CTUIR, 0x504, 0x100),
244 RSND_GEN_M_REG(CTU_ADINR, 0x508, 0x100),
245 RSND_GEN_M_REG(MIX_SWRSR, 0xd00, 0x40),
246 RSND_GEN_M_REG(MIX_MIXIR, 0xd04, 0x40),
247 RSND_GEN_M_REG(MIX_ADINR, 0xd08, 0x40),
248 RSND_GEN_M_REG(MIX_MIXMR, 0xd10, 0x40),
249 RSND_GEN_M_REG(MIX_MVPDR, 0xd14, 0x40),
250 RSND_GEN_M_REG(MIX_MDBAR, 0xd18, 0x40),
251 RSND_GEN_M_REG(MIX_MDBBR, 0xd1c, 0x40),
252 RSND_GEN_M_REG(MIX_MDBCR, 0xd20, 0x40),
253 RSND_GEN_M_REG(MIX_MDBDR, 0xd24, 0x40),
254 RSND_GEN_M_REG(MIX_MDBER, 0xd28, 0x40),
226 RSND_GEN_M_REG(DVC_SWRSR, 0xe00, 0x100), 255 RSND_GEN_M_REG(DVC_SWRSR, 0xe00, 0x100),
227 RSND_GEN_M_REG(DVC_DVUIR, 0xe04, 0x100), 256 RSND_GEN_M_REG(DVC_DVUIR, 0xe04, 0x100),
228 RSND_GEN_M_REG(DVC_ADINR, 0xe08, 0x100), 257 RSND_GEN_M_REG(DVC_ADINR, 0xe08, 0x100),
diff --git a/sound/soc/sh/rcar/mix.c b/sound/soc/sh/rcar/mix.c
new file mode 100644
index 000000000000..0d5c102db6f5
--- /dev/null
+++ b/sound/soc/sh/rcar/mix.c
@@ -0,0 +1,200 @@
1/*
2 * mix.c
3 *
4 * Copyright (c) 2015 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
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#include "rsnd.h"
11
12#define MIX_NAME_SIZE 16
13#define MIX_NAME "mix"
14
15struct rsnd_mix {
16 struct rsnd_mix_platform_info *info; /* rcar_snd.h */
17 struct rsnd_mod mod;
18};
19
20#define rsnd_mix_nr(priv) ((priv)->mix_nr)
21#define for_each_rsnd_mix(pos, priv, i) \
22 for ((i) = 0; \
23 ((i) < rsnd_mix_nr(priv)) && \
24 ((pos) = (struct rsnd_mix *)(priv)->mix + i); \
25 i++)
26
27
28static void rsnd_mix_soft_reset(struct rsnd_mod *mod)
29{
30 rsnd_mod_write(mod, MIX_SWRSR, 0);
31 rsnd_mod_write(mod, MIX_SWRSR, 1);
32}
33
34#define rsnd_mix_initialize_lock(mod) __rsnd_mix_initialize_lock(mod, 1)
35#define rsnd_mix_initialize_unlock(mod) __rsnd_mix_initialize_lock(mod, 0)
36static void __rsnd_mix_initialize_lock(struct rsnd_mod *mod, u32 enable)
37{
38 rsnd_mod_write(mod, MIX_MIXIR, enable);
39}
40
41static void rsnd_mix_volume_update(struct rsnd_dai_stream *io,
42 struct rsnd_mod *mod)
43{
44
45 /* Disable MIX dB setting */
46 rsnd_mod_write(mod, MIX_MDBER, 0);
47
48 rsnd_mod_write(mod, MIX_MDBAR, 0);
49 rsnd_mod_write(mod, MIX_MDBBR, 0);
50 rsnd_mod_write(mod, MIX_MDBCR, 0);
51 rsnd_mod_write(mod, MIX_MDBDR, 0);
52
53 /* Enable MIX dB setting */
54 rsnd_mod_write(mod, MIX_MDBER, 1);
55}
56
57static int rsnd_mix_init(struct rsnd_mod *mod,
58 struct rsnd_dai_stream *io,
59 struct rsnd_priv *priv)
60{
61 rsnd_mod_hw_start(mod);
62
63 rsnd_mix_soft_reset(mod);
64
65 rsnd_mix_initialize_lock(mod);
66
67 rsnd_mod_write(mod, MIX_ADINR, rsnd_get_adinr_chan(mod, io));
68
69 rsnd_path_parse(priv, io);
70
71 /* volume step */
72 rsnd_mod_write(mod, MIX_MIXMR, 0);
73 rsnd_mod_write(mod, MIX_MVPDR, 0);
74
75 rsnd_mix_volume_update(io, mod);
76
77 rsnd_mix_initialize_unlock(mod);
78
79 return 0;
80}
81
82static int rsnd_mix_quit(struct rsnd_mod *mod,
83 struct rsnd_dai_stream *io,
84 struct rsnd_priv *priv)
85{
86 rsnd_mod_hw_stop(mod);
87
88 return 0;
89}
90
91static struct rsnd_mod_ops rsnd_mix_ops = {
92 .name = MIX_NAME,
93 .init = rsnd_mix_init,
94 .quit = rsnd_mix_quit,
95};
96
97struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id)
98{
99 if (WARN_ON(id < 0 || id >= rsnd_mix_nr(priv)))
100 id = 0;
101
102 return &((struct rsnd_mix *)(priv->mix) + id)->mod;
103}
104
105static void rsnd_of_parse_mix(struct platform_device *pdev,
106 const struct rsnd_of_data *of_data,
107 struct rsnd_priv *priv)
108{
109 struct device_node *node;
110 struct rsnd_mix_platform_info *mix_info;
111 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
112 struct device *dev = &pdev->dev;
113 int nr;
114
115 if (!of_data)
116 return;
117
118 node = of_get_child_by_name(dev->of_node, "rcar_sound,mix");
119 if (!node)
120 return;
121
122 nr = of_get_child_count(node);
123 if (!nr)
124 goto rsnd_of_parse_mix_end;
125
126 mix_info = devm_kzalloc(dev,
127 sizeof(struct rsnd_mix_platform_info) * nr,
128 GFP_KERNEL);
129 if (!mix_info) {
130 dev_err(dev, "mix info allocation error\n");
131 goto rsnd_of_parse_mix_end;
132 }
133
134 info->mix_info = mix_info;
135 info->mix_info_nr = nr;
136
137rsnd_of_parse_mix_end:
138 of_node_put(node);
139
140}
141
142int rsnd_mix_probe(struct platform_device *pdev,
143 const struct rsnd_of_data *of_data,
144 struct rsnd_priv *priv)
145{
146 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
147 struct device *dev = rsnd_priv_to_dev(priv);
148 struct rsnd_mix *mix;
149 struct clk *clk;
150 char name[MIX_NAME_SIZE];
151 int i, nr, ret;
152
153 /* This driver doesn't support Gen1 at this point */
154 if (rsnd_is_gen1(priv)) {
155 dev_warn(dev, "MIX is not supported on Gen1\n");
156 return -EINVAL;
157 }
158
159 rsnd_of_parse_mix(pdev, of_data, priv);
160
161 nr = info->mix_info_nr;
162 if (!nr)
163 return 0;
164
165 mix = devm_kzalloc(dev, sizeof(*mix) * nr, GFP_KERNEL);
166 if (!mix)
167 return -ENOMEM;
168
169 priv->mix_nr = nr;
170 priv->mix = mix;
171
172 for_each_rsnd_mix(mix, priv, i) {
173 snprintf(name, MIX_NAME_SIZE, "%s.%d",
174 MIX_NAME, i);
175
176 clk = devm_clk_get(dev, name);
177 if (IS_ERR(clk))
178 return PTR_ERR(clk);
179
180 mix->info = &info->mix_info[i];
181
182 ret = rsnd_mod_init(priv, &mix->mod, &rsnd_mix_ops,
183 clk, RSND_MOD_MIX, i);
184 if (ret)
185 return ret;
186 }
187
188 return 0;
189}
190
191void rsnd_mix_remove(struct platform_device *pdev,
192 struct rsnd_priv *priv)
193{
194 struct rsnd_mix *mix;
195 int i;
196
197 for_each_rsnd_mix(mix, priv, i) {
198 rsnd_mod_quit(&mix->mod);
199 }
200}
diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h
index 09fcc54a8ee0..7a0e52b4640a 100644
--- a/sound/soc/sh/rcar/rsnd.h
+++ b/sound/soc/sh/rcar/rsnd.h
@@ -47,6 +47,18 @@ enum rsnd_reg {
47 RSND_REG_SCU_SYS_STATUS0, 47 RSND_REG_SCU_SYS_STATUS0,
48 RSND_REG_SCU_SYS_INT_EN0, 48 RSND_REG_SCU_SYS_INT_EN0,
49 RSND_REG_CMD_ROUTE_SLCT, 49 RSND_REG_CMD_ROUTE_SLCT,
50 RSND_REG_CTU_CTUIR,
51 RSND_REG_CTU_ADINR,
52 RSND_REG_MIX_SWRSR,
53 RSND_REG_MIX_MIXIR,
54 RSND_REG_MIX_ADINR,
55 RSND_REG_MIX_MIXMR,
56 RSND_REG_MIX_MVPDR,
57 RSND_REG_MIX_MDBAR,
58 RSND_REG_MIX_MDBBR,
59 RSND_REG_MIX_MDBCR,
60 RSND_REG_MIX_MDBDR,
61 RSND_REG_MIX_MDBER,
50 RSND_REG_DVC_SWRSR, 62 RSND_REG_DVC_SWRSR,
51 RSND_REG_DVC_DVUIR, 63 RSND_REG_DVC_DVUIR,
52 RSND_REG_DVC_ADINR, 64 RSND_REG_DVC_ADINR,
@@ -99,6 +111,7 @@ enum rsnd_reg {
99 RSND_REG_SHARE26, 111 RSND_REG_SHARE26,
100 RSND_REG_SHARE27, 112 RSND_REG_SHARE27,
101 RSND_REG_SHARE28, 113 RSND_REG_SHARE28,
114 RSND_REG_SHARE29,
102 115
103 RSND_REG_MAX, 116 RSND_REG_MAX,
104}; 117};
@@ -119,7 +132,7 @@ enum rsnd_reg {
119#define RSND_REG_SSI_CTRL RSND_REG_SHARE02 132#define RSND_REG_SSI_CTRL RSND_REG_SHARE02
120#define RSND_REG_SSI_BUSIF_MODE RSND_REG_SHARE03 133#define RSND_REG_SSI_BUSIF_MODE RSND_REG_SHARE03
121#define RSND_REG_SSI_BUSIF_ADINR RSND_REG_SHARE04 134#define RSND_REG_SSI_BUSIF_ADINR RSND_REG_SHARE04
122#define RSND_REG_INT_ENABLE RSND_REG_SHARE05 135#define RSND_REG_SSI_INT_ENABLE RSND_REG_SHARE05
123#define RSND_REG_SRC_BSDSR RSND_REG_SHARE06 136#define RSND_REG_SRC_BSDSR RSND_REG_SHARE06
124#define RSND_REG_SRC_BSISR RSND_REG_SHARE07 137#define RSND_REG_SRC_BSISR RSND_REG_SHARE07
125#define RSND_REG_DIV_EN RSND_REG_SHARE08 138#define RSND_REG_DIV_EN RSND_REG_SHARE08
@@ -136,13 +149,14 @@ enum rsnd_reg {
136#define RSND_REG_AUDIO_CLK_SEL2 RSND_REG_SHARE19 149#define RSND_REG_AUDIO_CLK_SEL2 RSND_REG_SHARE19
137#define RSND_REG_CMD_CTRL RSND_REG_SHARE20 150#define RSND_REG_CMD_CTRL RSND_REG_SHARE20
138#define RSND_REG_CMDOUT_TIMSEL RSND_REG_SHARE21 151#define RSND_REG_CMDOUT_TIMSEL RSND_REG_SHARE21
139#define RSND_REG_BUSIF_DALIGN RSND_REG_SHARE22 152#define RSND_REG_SSI_BUSIF_DALIGN RSND_REG_SHARE22
140#define RSND_REG_DVC_VRCTR RSND_REG_SHARE23 153#define RSND_REG_DVC_VRCTR RSND_REG_SHARE23
141#define RSND_REG_DVC_VRPDR RSND_REG_SHARE24 154#define RSND_REG_DVC_VRPDR RSND_REG_SHARE24
142#define RSND_REG_DVC_VRDBR RSND_REG_SHARE25 155#define RSND_REG_DVC_VRDBR RSND_REG_SHARE25
143#define RSND_REG_SCU_SYS_STATUS1 RSND_REG_SHARE26 156#define RSND_REG_SCU_SYS_STATUS1 RSND_REG_SHARE26
144#define RSND_REG_SCU_SYS_INT_EN1 RSND_REG_SHARE27 157#define RSND_REG_SCU_SYS_INT_EN1 RSND_REG_SHARE27
145#define RSND_REG_SRC_INT_ENABLE0 RSND_REG_SHARE28 158#define RSND_REG_SRC_INT_ENABLE0 RSND_REG_SHARE28
159#define RSND_REG_SRC_BUSIF_DALIGN RSND_REG_SHARE29
146 160
147struct rsnd_of_data; 161struct rsnd_of_data;
148struct rsnd_priv; 162struct rsnd_priv;
@@ -157,27 +171,28 @@ struct rsnd_dai_stream;
157 rsnd_read(rsnd_mod_to_priv(m), m, RSND_REG_##r) 171 rsnd_read(rsnd_mod_to_priv(m), m, RSND_REG_##r)
158#define rsnd_mod_write(m, r, d) \ 172#define rsnd_mod_write(m, r, d) \
159 rsnd_write(rsnd_mod_to_priv(m), m, RSND_REG_##r, d) 173 rsnd_write(rsnd_mod_to_priv(m), m, RSND_REG_##r, d)
174#define rsnd_mod_force_write(m, r, d) \
175 rsnd_force_write(rsnd_mod_to_priv(m), m, RSND_REG_##r, d)
160#define rsnd_mod_bset(m, r, s, d) \ 176#define rsnd_mod_bset(m, r, s, d) \
161 rsnd_bset(rsnd_mod_to_priv(m), m, RSND_REG_##r, s, d) 177 rsnd_bset(rsnd_mod_to_priv(m), m, RSND_REG_##r, s, d)
162 178
163u32 rsnd_read(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg); 179u32 rsnd_read(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg);
164void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod, 180void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod,
165 enum rsnd_reg reg, u32 data); 181 enum rsnd_reg reg, u32 data);
182void rsnd_force_write(struct rsnd_priv *priv, struct rsnd_mod *mod,
183 enum rsnd_reg reg, u32 data);
166void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg, 184void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg,
167 u32 mask, u32 data); 185 u32 mask, u32 data);
168u32 rsnd_get_adinr(struct rsnd_mod *mod, struct rsnd_dai_stream *io); 186u32 rsnd_get_adinr_bit(struct rsnd_mod *mod, struct rsnd_dai_stream *io);
187u32 rsnd_get_adinr_chan(struct rsnd_mod *mod, struct rsnd_dai_stream *io);
188u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io);
189void rsnd_path_parse(struct rsnd_priv *priv,
190 struct rsnd_dai_stream *io);
169 191
170/* 192/*
171 * R-Car DMA 193 * R-Car DMA
172 */ 194 */
173struct rsnd_dma; 195struct rsnd_dma;
174struct rsnd_dma_ops {
175 void (*start)(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
176 void (*stop)(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
177 int (*init)(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id,
178 struct rsnd_mod *mod_from, struct rsnd_mod *mod_to);
179 void (*quit)(struct rsnd_dai_stream *io, struct rsnd_dma *dma);
180};
181 196
182struct rsnd_dmaen { 197struct rsnd_dmaen {
183 struct dma_chan *chan; 198 struct dma_chan *chan;
@@ -217,6 +232,8 @@ struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node,
217 */ 232 */
218enum rsnd_mod_type { 233enum rsnd_mod_type {
219 RSND_MOD_DVC = 0, 234 RSND_MOD_DVC = 0,
235 RSND_MOD_MIX,
236 RSND_MOD_CTU,
220 RSND_MOD_SRC, 237 RSND_MOD_SRC,
221 RSND_MOD_SSI, 238 RSND_MOD_SSI,
222 RSND_MOD_MAX, 239 RSND_MOD_MAX,
@@ -312,7 +329,7 @@ struct rsnd_mod {
312 329
313#define rsnd_mod_to_priv(mod) ((mod)->priv) 330#define rsnd_mod_to_priv(mod) ((mod)->priv)
314#define rsnd_mod_to_dma(mod) (&(mod)->dma) 331#define rsnd_mod_to_dma(mod) (&(mod)->dma)
315#define rsnd_mod_id(mod) ((mod)->id) 332#define rsnd_mod_id(mod) ((mod) ? (mod)->id : -1)
316#define rsnd_mod_hw_start(mod) clk_enable((mod)->clk) 333#define rsnd_mod_hw_start(mod) clk_enable((mod)->clk)
317#define rsnd_mod_hw_stop(mod) clk_disable((mod)->clk) 334#define rsnd_mod_hw_stop(mod) clk_disable((mod)->clk)
318 335
@@ -345,9 +362,12 @@ struct rsnd_dai_stream {
345 int byte_per_period; 362 int byte_per_period;
346 int next_period_byte; 363 int next_period_byte;
347}; 364};
348#define rsnd_io_to_mod_ssi(io) ((io)->mod[RSND_MOD_SSI]) 365#define rsnd_io_to_mod(io, i) ((i) < RSND_MOD_MAX ? (io)->mod[(i)] : NULL)
349#define rsnd_io_to_mod_src(io) ((io)->mod[RSND_MOD_SRC]) 366#define rsnd_io_to_mod_ssi(io) rsnd_io_to_mod((io), RSND_MOD_SSI)
350#define rsnd_io_to_mod_dvc(io) ((io)->mod[RSND_MOD_DVC]) 367#define rsnd_io_to_mod_src(io) rsnd_io_to_mod((io), RSND_MOD_SRC)
368#define rsnd_io_to_mod_ctu(io) rsnd_io_to_mod((io), RSND_MOD_CTU)
369#define rsnd_io_to_mod_mix(io) rsnd_io_to_mod((io), RSND_MOD_MIX)
370#define rsnd_io_to_mod_dvc(io) rsnd_io_to_mod((io), RSND_MOD_DVC)
351#define rsnd_io_to_rdai(io) ((io)->rdai) 371#define rsnd_io_to_rdai(io) ((io)->rdai)
352#define rsnd_io_to_priv(io) (rsnd_rdai_to_priv(rsnd_io_to_rdai(io))) 372#define rsnd_io_to_priv(io) (rsnd_rdai_to_priv(rsnd_io_to_rdai(io)))
353#define rsnd_io_is_play(io) (&rsnd_io_to_rdai(io)->playback == io) 373#define rsnd_io_is_play(io) (&rsnd_io_to_rdai(io)->playback == io)
@@ -437,12 +457,6 @@ struct rsnd_priv {
437 void *gen; 457 void *gen;
438 458
439 /* 459 /*
440 * below value will be filled on rsnd_src_probe()
441 */
442 void *src;
443 int src_nr;
444
445 /*
446 * below value will be filled on rsnd_adg_probe() 460 * below value will be filled on rsnd_adg_probe()
447 */ 461 */
448 void *adg; 462 void *adg;
@@ -459,6 +473,24 @@ struct rsnd_priv {
459 int ssi_nr; 473 int ssi_nr;
460 474
461 /* 475 /*
476 * below value will be filled on rsnd_src_probe()
477 */
478 void *src;
479 int src_nr;
480
481 /*
482 * below value will be filled on rsnd_ctu_probe()
483 */
484 void *ctu;
485 int ctu_nr;
486
487 /*
488 * below value will be filled on rsnd_mix_probe()
489 */
490 void *mix;
491 int mix_nr;
492
493 /*
462 * below value will be filled on rsnd_dvc_probe() 494 * below value will be filled on rsnd_dvc_probe()
463 */ 495 */
464 void *dvc; 496 void *dvc;
@@ -531,6 +563,19 @@ int rsnd_kctrl_new_e(struct rsnd_mod *mod,
531 u32 max); 563 u32 max);
532 564
533/* 565/*
566 * R-Car SSI
567 */
568int rsnd_ssi_probe(struct platform_device *pdev,
569 const struct rsnd_of_data *of_data,
570 struct rsnd_priv *priv);
571void rsnd_ssi_remove(struct platform_device *pdev,
572 struct rsnd_priv *priv);
573struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id);
574int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod);
575int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod);
576int rsnd_ssi_use_busif(struct rsnd_dai_stream *io, struct rsnd_mod *mod);
577
578/*
534 * R-Car SRC 579 * R-Car SRC
535 */ 580 */
536int rsnd_src_probe(struct platform_device *pdev, 581int rsnd_src_probe(struct platform_device *pdev,
@@ -550,20 +595,27 @@ int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod,
550int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod); 595int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod);
551int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod); 596int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod);
552 597
553#define rsnd_src_nr(priv) ((priv)->src_nr) 598/*
599 * R-Car CTU
600 */
601int rsnd_ctu_probe(struct platform_device *pdev,
602 const struct rsnd_of_data *of_data,
603 struct rsnd_priv *priv);
604
605void rsnd_ctu_remove(struct platform_device *pdev,
606 struct rsnd_priv *priv);
607struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id);
554 608
555/* 609/*
556 * R-Car SSI 610 * R-Car MIX
557 */ 611 */
558int rsnd_ssi_probe(struct platform_device *pdev, 612int rsnd_mix_probe(struct platform_device *pdev,
559 const struct rsnd_of_data *of_data, 613 const struct rsnd_of_data *of_data,
560 struct rsnd_priv *priv); 614 struct rsnd_priv *priv);
561void rsnd_ssi_remove(struct platform_device *pdev, 615
616void rsnd_mix_remove(struct platform_device *pdev,
562 struct rsnd_priv *priv); 617 struct rsnd_priv *priv);
563struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id); 618struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id);
564int rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod);
565int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod);
566int rsnd_ssi_use_busif(struct rsnd_dai_stream *io, struct rsnd_mod *mod);
567 619
568/* 620/*
569 * R-Car DVC 621 * R-Car DVC
@@ -575,7 +627,4 @@ void rsnd_dvc_remove(struct platform_device *pdev,
575 struct rsnd_priv *priv); 627 struct rsnd_priv *priv);
576struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id); 628struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id);
577 629
578#define rsnd_dvc_nr(priv) ((priv)->dvc_nr)
579
580
581#endif 630#endif
diff --git a/sound/soc/sh/rcar/rsrc-card.c b/sound/soc/sh/rcar/rsrc-card.c
index 84e935711e29..d61db9c385ea 100644
--- a/sound/soc/sh/rcar/rsrc-card.c
+++ b/sound/soc/sh/rcar/rsrc-card.c
@@ -41,6 +41,7 @@ static const struct rsrc_card_of_data routes_of_ssi0_ak4642 = {
41static const struct of_device_id rsrc_card_of_match[] = { 41static const struct of_device_id rsrc_card_of_match[] = {
42 { .compatible = "renesas,rsrc-card,lager", .data = &routes_of_ssi0_ak4642 }, 42 { .compatible = "renesas,rsrc-card,lager", .data = &routes_of_ssi0_ak4642 },
43 { .compatible = "renesas,rsrc-card,koelsch", .data = &routes_of_ssi0_ak4642 }, 43 { .compatible = "renesas,rsrc-card,koelsch", .data = &routes_of_ssi0_ak4642 },
44 { .compatible = "renesas,rsrc-card", },
44 {}, 45 {},
45}; 46};
46MODULE_DEVICE_TABLE(of, rsrc_card_of_match); 47MODULE_DEVICE_TABLE(of, rsrc_card_of_match);
@@ -242,8 +243,15 @@ static int rsrc_card_parse_links(struct device_node *np,
242 snd_soc_of_get_dai_name(np, &dai_link->codec_dai_name); 243 snd_soc_of_get_dai_name(np, &dai_link->codec_dai_name);
243 244
244 /* additional name prefix */ 245 /* additional name prefix */
245 priv->codec_conf.of_node = dai_link->codec_of_node; 246 if (of_data) {
246 priv->codec_conf.name_prefix = of_data->prefix; 247 priv->codec_conf.of_node = dai_link->codec_of_node;
248 priv->codec_conf.name_prefix = of_data->prefix;
249 } else {
250 snd_soc_of_parse_audio_prefix(&priv->snd_card,
251 &priv->codec_conf,
252 dai_link->codec_of_node,
253 "audio-prefix");
254 }
247 255
248 /* set dai_name */ 256 /* set dai_name */
249 snprintf(dai_props->dai_name, DAI_NAME_NUM, "be.%s", 257 snprintf(dai_props->dai_name, DAI_NAME_NUM, "be.%s",
@@ -361,8 +369,14 @@ static int rsrc_card_parse_of(struct device_node *node,
361 priv->snd_card.num_links = num; 369 priv->snd_card.num_links = num;
362 priv->snd_card.codec_conf = &priv->codec_conf; 370 priv->snd_card.codec_conf = &priv->codec_conf;
363 priv->snd_card.num_configs = 1; 371 priv->snd_card.num_configs = 1;
364 priv->snd_card.of_dapm_routes = of_data->routes; 372
365 priv->snd_card.num_of_dapm_routes = of_data->num_routes; 373 if (of_data) {
374 priv->snd_card.of_dapm_routes = of_data->routes;
375 priv->snd_card.num_of_dapm_routes = of_data->num_routes;
376 } else {
377 snd_soc_of_parse_audio_routing(&priv->snd_card,
378 "audio-routing");
379 }
366 380
367 /* Parse the card name from DT */ 381 /* Parse the card name from DT */
368 snd_soc_of_parse_card_name(&priv->snd_card, "card-name"); 382 snd_soc_of_parse_card_name(&priv->snd_card, "card-name");
diff --git a/sound/soc/sh/rcar/src.c b/sound/soc/sh/rcar/src.c
index c61c17180142..89a18e102feb 100644
--- a/sound/soc/sh/rcar/src.c
+++ b/sound/soc/sh/rcar/src.c
@@ -30,6 +30,7 @@ struct rsnd_src {
30 30
31#define RSND_SRC_NAME_SIZE 16 31#define RSND_SRC_NAME_SIZE 16
32 32
33#define rsnd_src_nr(priv) ((priv)->src_nr)
33#define rsnd_enable_sync_convert(src) ((src)->sen.val) 34#define rsnd_enable_sync_convert(src) ((src)->sen.val)
34#define rsnd_src_of_node(priv) \ 35#define rsnd_src_of_node(priv) \
35 of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,src") 36 of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, "rcar_sound,src")
@@ -117,6 +118,20 @@ struct rsnd_src {
117/* 118/*
118 * Gen1/Gen2 common functions 119 * Gen1/Gen2 common functions
119 */ 120 */
121static void rsnd_src_soft_reset(struct rsnd_mod *mod)
122{
123 rsnd_mod_write(mod, SRC_SWRSR, 0);
124 rsnd_mod_write(mod, SRC_SWRSR, 1);
125}
126
127
128#define rsnd_src_initialize_lock(mod) __rsnd_src_initialize_lock(mod, 1)
129#define rsnd_src_initialize_unlock(mod) __rsnd_src_initialize_lock(mod, 0)
130static void __rsnd_src_initialize_lock(struct rsnd_mod *mod, u32 enable)
131{
132 rsnd_mod_write(mod, SRC_SRCIR, enable);
133}
134
120static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io, 135static struct dma_chan *rsnd_src_dma_req(struct rsnd_dai_stream *io,
121 struct rsnd_mod *mod) 136 struct rsnd_mod *mod)
122{ 137{
@@ -133,7 +148,6 @@ int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
133 int use_busif) 148 int use_busif)
134{ 149{
135 struct rsnd_dai *rdai = rsnd_io_to_rdai(io); 150 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
136 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
137 int ssi_id = rsnd_mod_id(ssi_mod); 151 int ssi_id = rsnd_mod_id(ssi_mod);
138 152
139 /* 153 /*
@@ -170,27 +184,14 @@ int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
170 * DMA settings for SSIU 184 * DMA settings for SSIU
171 */ 185 */
172 if (use_busif) { 186 if (use_busif) {
173 u32 val = 0x76543210; 187 u32 val = rsnd_get_dalign(ssi_mod, io);
174 u32 mask = ~0;
175 188
176 rsnd_mod_write(ssi_mod, SSI_BUSIF_ADINR, 189 rsnd_mod_write(ssi_mod, SSI_BUSIF_ADINR,
177 rsnd_get_adinr(ssi_mod, io)); 190 rsnd_get_adinr_bit(ssi_mod, io));
178 rsnd_mod_write(ssi_mod, SSI_BUSIF_MODE, 1); 191 rsnd_mod_write(ssi_mod, SSI_BUSIF_MODE, 1);
179 rsnd_mod_write(ssi_mod, SSI_CTRL, 0x1); 192 rsnd_mod_write(ssi_mod, SSI_CTRL, 0x1);
180 193
181 mask <<= runtime->channels * 4; 194 rsnd_mod_write(ssi_mod, SSI_BUSIF_DALIGN, val);
182 val = val & mask;
183
184 switch (runtime->sample_bits) {
185 case 16:
186 val |= 0x67452301 & ~mask;
187 break;
188 case 32:
189 val |= 0x76543210 & ~mask;
190 break;
191 }
192 rsnd_mod_write(ssi_mod, BUSIF_DALIGN, val);
193
194 } 195 }
195 196
196 return 0; 197 return 0;
@@ -215,10 +216,9 @@ int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod)
215 return 0; 216 return 0;
216 217
217 /* enable SSI interrupt if Gen2 */ 218 /* enable SSI interrupt if Gen2 */
218 if (rsnd_ssi_is_dma_mode(ssi_mod)) 219 rsnd_mod_write(ssi_mod, SSI_INT_ENABLE,
219 rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0e000000); 220 rsnd_ssi_is_dma_mode(ssi_mod) ?
220 else 221 0x0e000000 : 0x0f000000);
221 rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0f000000);
222 222
223 return 0; 223 return 0;
224} 224}
@@ -231,7 +231,7 @@ int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod)
231 return 0; 231 return 0;
232 232
233 /* disable SSI interrupt if Gen2 */ 233 /* disable SSI interrupt if Gen2 */
234 rsnd_mod_write(ssi_mod, INT_ENABLE, 0x00000000); 234 rsnd_mod_write(ssi_mod, SSI_INT_ENABLE, 0x00000000);
235 235
236 return 0; 236 return 0;
237} 237}
@@ -294,12 +294,8 @@ static int rsnd_src_set_convert_rate(struct rsnd_mod *mod,
294 if (convert_rate) 294 if (convert_rate)
295 fsrate = 0x0400000 / convert_rate * runtime->rate; 295 fsrate = 0x0400000 / convert_rate * runtime->rate;
296 296
297 /* set/clear soft reset */
298 rsnd_mod_write(mod, SRC_SWRSR, 0);
299 rsnd_mod_write(mod, SRC_SWRSR, 1);
300
301 /* Set channel number and output bit length */ 297 /* Set channel number and output bit length */
302 rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr(mod, io)); 298 rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr_bit(mod, io));
303 299
304 /* Enable the initial value of IFS */ 300 /* Enable the initial value of IFS */
305 if (fsrate) { 301 if (fsrate) {
@@ -358,17 +354,15 @@ static int rsnd_src_init(struct rsnd_mod *mod,
358 354
359 rsnd_mod_hw_start(mod); 355 rsnd_mod_hw_start(mod);
360 356
357 rsnd_src_soft_reset(mod);
358
359 rsnd_src_initialize_lock(mod);
360
361 src->err = 0; 361 src->err = 0;
362 362
363 /* reset sync convert_rate */ 363 /* reset sync convert_rate */
364 src->sync.val = 0; 364 src->sync.val = 0;
365 365
366 /*
367 * Initialize the operation of the SRC internal circuits
368 * see rsnd_src_start()
369 */
370 rsnd_mod_write(mod, SRC_SRCIR, 1);
371
372 return 0; 366 return 0;
373} 367}
374 368
@@ -395,11 +389,7 @@ static int rsnd_src_quit(struct rsnd_mod *mod,
395 389
396static int rsnd_src_start(struct rsnd_mod *mod) 390static int rsnd_src_start(struct rsnd_mod *mod)
397{ 391{
398 /* 392 rsnd_src_initialize_unlock(mod);
399 * Cancel the initialization and operate the SRC function
400 * see rsnd_src_init()
401 */
402 rsnd_mod_write(mod, SRC_SRCIR, 0);
403 393
404 return 0; 394 return 0;
405} 395}
@@ -617,6 +607,14 @@ static void rsnd_src_irq_ctrol_gen2(struct rsnd_mod *mod, int enable)
617 int_val = 0; 607 int_val = 0;
618 } 608 }
619 609
610 /*
611 * WORKAROUND
612 *
613 * ignore over flow error when rsnd_enable_sync_convert()
614 */
615 if (rsnd_enable_sync_convert(src))
616 sys_int_val = sys_int_val & 0xffff;
617
620 rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val); 618 rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val);
621 rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val); 619 rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val);
622 rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val); 620 rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val);
@@ -632,11 +630,22 @@ static void rsnd_src_error_clear_gen2(struct rsnd_mod *mod)
632 630
633static bool rsnd_src_error_record_gen2(struct rsnd_mod *mod) 631static bool rsnd_src_error_record_gen2(struct rsnd_mod *mod)
634{ 632{
635 u32 val = OUF_SRC(rsnd_mod_id(mod)); 633 struct rsnd_src *src = rsnd_mod_to_src(mod);
634 u32 val0, val1;
636 bool ret = false; 635 bool ret = false;
637 636
638 if ((rsnd_mod_read(mod, SCU_SYS_STATUS0) & val) || 637 val0 = val1 = OUF_SRC(rsnd_mod_id(mod));
639 (rsnd_mod_read(mod, SCU_SYS_STATUS1) & val)) { 638
639 /*
640 * WORKAROUND
641 *
642 * ignore over flow error when rsnd_enable_sync_convert()
643 */
644 if (rsnd_enable_sync_convert(src))
645 val0 = val0 & 0xffff;
646
647 if ((rsnd_mod_read(mod, SCU_SYS_STATUS0) & val0) ||
648 (rsnd_mod_read(mod, SCU_SYS_STATUS1) & val1)) {
640 struct rsnd_src *src = rsnd_mod_to_src(mod); 649 struct rsnd_src *src = rsnd_mod_to_src(mod);
641 650
642 src->err++; 651 src->err++;
@@ -652,7 +661,20 @@ static bool rsnd_src_error_record_gen2(struct rsnd_mod *mod)
652static int _rsnd_src_start_gen2(struct rsnd_mod *mod, 661static int _rsnd_src_start_gen2(struct rsnd_mod *mod,
653 struct rsnd_dai_stream *io) 662 struct rsnd_dai_stream *io)
654{ 663{
655 u32 val = rsnd_io_to_mod_dvc(io) ? 0x01 : 0x11; 664 struct rsnd_src *src = rsnd_mod_to_src(mod);
665 u32 val;
666
667 val = rsnd_get_dalign(mod, io);
668
669 rsnd_mod_write(mod, SRC_BUSIF_DALIGN, val);
670
671 /*
672 * WORKAROUND
673 *
674 * Enable SRC output if you want to use sync convert together with DVC
675 */
676 val = (rsnd_io_to_mod_dvc(io) && !rsnd_enable_sync_convert(src)) ?
677 0x01 : 0x11;
656 678
657 rsnd_mod_write(mod, SRC_CTRL, val); 679 rsnd_mod_write(mod, SRC_CTRL, val);
658 680
@@ -922,13 +944,6 @@ static int rsnd_src_pcm_new(struct rsnd_mod *mod,
922 return 0; 944 return 0;
923 945
924 /* 946 /*
925 * We can't use SRC sync convert
926 * if it has DVC
927 */
928 if (rsnd_io_to_mod_dvc(io))
929 return 0;
930
931 /*
932 * enable sync convert 947 * enable sync convert
933 */ 948 */
934 ret = rsnd_kctrl_new_s(mod, io, rtd, 949 ret = rsnd_kctrl_new_s(mod, io, rtd,
@@ -1047,10 +1062,8 @@ int rsnd_src_probe(struct platform_device *pdev,
1047 return 0; 1062 return 0;
1048 1063
1049 src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL); 1064 src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL);
1050 if (!src) { 1065 if (!src)
1051 dev_err(dev, "SRC allocate failed\n");
1052 return -ENOMEM; 1066 return -ENOMEM;
1053 }
1054 1067
1055 priv->src_nr = nr; 1068 priv->src_nr = nr;
1056 priv->src = src; 1069 priv->src = src;
diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c
index 2fbe59f7f9b5..d45b9a7e324e 100644
--- a/sound/soc/sh/rcar/ssi.c
+++ b/sound/soc/sh/rcar/ssi.c
@@ -770,10 +770,8 @@ int rsnd_ssi_probe(struct platform_device *pdev,
770 */ 770 */
771 nr = info->ssi_info_nr; 771 nr = info->ssi_info_nr;
772 ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL); 772 ssi = devm_kzalloc(dev, sizeof(*ssi) * nr, GFP_KERNEL);
773 if (!ssi) { 773 if (!ssi)
774 dev_err(dev, "SSI allocate failed\n");
775 return -ENOMEM; 774 return -ENOMEM;
776 }
777 775
778 priv->ssi = ssi; 776 priv->ssi = ssi;
779 priv->ssi_nr = nr; 777 priv->ssi_nr = nr;
diff --git a/sound/soc/sh/ssi.c b/sound/soc/sh/ssi.c
index ab13146e4f82..89ed1b107ac5 100644
--- a/sound/soc/sh/ssi.c
+++ b/sound/soc/sh/ssi.c
@@ -385,14 +385,9 @@ static const struct snd_soc_component_driver sh4_ssi_component = {
385 385
386static int sh4_soc_dai_probe(struct platform_device *pdev) 386static int sh4_soc_dai_probe(struct platform_device *pdev)
387{ 387{
388 return snd_soc_register_component(&pdev->dev, &sh4_ssi_component, 388 return devm_snd_soc_register_component(&pdev->dev, &sh4_ssi_component,
389 sh4_ssi_dai, ARRAY_SIZE(sh4_ssi_dai)); 389 sh4_ssi_dai,
390} 390 ARRAY_SIZE(sh4_ssi_dai));
391
392static int sh4_soc_dai_remove(struct platform_device *pdev)
393{
394 snd_soc_unregister_component(&pdev->dev);
395 return 0;
396} 391}
397 392
398static struct platform_driver sh4_ssi_driver = { 393static struct platform_driver sh4_ssi_driver = {
@@ -401,7 +396,6 @@ static struct platform_driver sh4_ssi_driver = {
401 }, 396 },
402 397
403 .probe = sh4_soc_dai_probe, 398 .probe = sh4_soc_dai_probe,
404 .remove = sh4_soc_dai_remove,
405}; 399};
406 400
407module_platform_driver(sh4_ssi_driver); 401module_platform_driver(sh4_ssi_driver);
diff --git a/sound/soc/soc-ac97.c b/sound/soc/soc-ac97.c
index 08d7259bbaab..d40efc9fe0a9 100644
--- a/sound/soc/soc-ac97.c
+++ b/sound/soc/soc-ac97.c
@@ -85,10 +85,19 @@ EXPORT_SYMBOL(snd_soc_alloc_ac97_codec);
85/** 85/**
86 * snd_soc_new_ac97_codec - initailise AC97 device 86 * snd_soc_new_ac97_codec - initailise AC97 device
87 * @codec: audio codec 87 * @codec: audio codec
88 * @id: The expected device ID
89 * @id_mask: Mask that is applied to the device ID before comparing with @id
88 * 90 *
89 * Initialises AC97 codec resources for use by ad-hoc devices only. 91 * Initialises AC97 codec resources for use by ad-hoc devices only.
92 *
93 * If @id is not 0 this function will reset the device, then read the ID from
94 * the device and check if it matches the expected ID. If it doesn't match an
95 * error will be returned and device will not be registered.
96 *
97 * Returns: A PTR_ERR() on failure or a valid snd_ac97 struct on success.
90 */ 98 */
91struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec) 99struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
100 unsigned int id, unsigned int id_mask)
92{ 101{
93 struct snd_ac97 *ac97; 102 struct snd_ac97 *ac97;
94 int ret; 103 int ret;
@@ -97,13 +106,24 @@ struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec)
97 if (IS_ERR(ac97)) 106 if (IS_ERR(ac97))
98 return ac97; 107 return ac97;
99 108
100 ret = device_add(&ac97->dev); 109 if (id) {
101 if (ret) { 110 ret = snd_ac97_reset(ac97, false, id, id_mask);
102 put_device(&ac97->dev); 111 if (ret < 0) {
103 return ERR_PTR(ret); 112 dev_err(codec->dev, "Failed to reset AC97 device: %d\n",
113 ret);
114 goto err_put_device;
115 }
104 } 116 }
105 117
118 ret = device_add(&ac97->dev);
119 if (ret)
120 goto err_put_device;
121
106 return ac97; 122 return ac97;
123
124err_put_device:
125 put_device(&ac97->dev);
126 return ERR_PTR(ret);
107} 127}
108EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec); 128EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
109 129
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 3a4a5c0e3f97..6173d15236c3 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -654,10 +654,12 @@ int snd_soc_suspend(struct device *dev)
654 654
655 /* suspend all CODECs */ 655 /* suspend all CODECs */
656 list_for_each_entry(codec, &card->codec_dev_list, card_list) { 656 list_for_each_entry(codec, &card->codec_dev_list, card_list) {
657 struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
658
657 /* If there are paths active then the CODEC will be held with 659 /* If there are paths active then the CODEC will be held with
658 * bias _ON and should not be suspended. */ 660 * bias _ON and should not be suspended. */
659 if (!codec->suspended) { 661 if (!codec->suspended) {
660 switch (codec->dapm.bias_level) { 662 switch (snd_soc_dapm_get_bias_level(dapm)) {
661 case SND_SOC_BIAS_STANDBY: 663 case SND_SOC_BIAS_STANDBY:
662 /* 664 /*
663 * If the CODEC is capable of idle 665 * If the CODEC is capable of idle
@@ -665,7 +667,7 @@ int snd_soc_suspend(struct device *dev)
665 * means it's doing something, 667 * means it's doing something,
666 * otherwise fall through. 668 * otherwise fall through.
667 */ 669 */
668 if (codec->dapm.idle_bias_off) { 670 if (dapm->idle_bias_off) {
669 dev_dbg(codec->dev, 671 dev_dbg(codec->dev,
670 "ASoC: idle_bias_off CODEC on over suspend\n"); 672 "ASoC: idle_bias_off CODEC on over suspend\n");
671 break; 673 break;
@@ -978,7 +980,7 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
978 980
979static void soc_remove_component(struct snd_soc_component *component) 981static void soc_remove_component(struct snd_soc_component *component)
980{ 982{
981 if (!component->probed) 983 if (!component->card)
982 return; 984 return;
983 985
984 /* This is a HACK and will be removed soon */ 986 /* This is a HACK and will be removed soon */
@@ -991,7 +993,7 @@ static void soc_remove_component(struct snd_soc_component *component)
991 snd_soc_dapm_free(snd_soc_component_get_dapm(component)); 993 snd_soc_dapm_free(snd_soc_component_get_dapm(component));
992 994
993 soc_cleanup_component_debugfs(component); 995 soc_cleanup_component_debugfs(component);
994 component->probed = 0; 996 component->card = NULL;
995 module_put(component->dev->driver->owner); 997 module_put(component->dev->driver->owner);
996} 998}
997 999
@@ -1102,16 +1104,26 @@ static int soc_probe_component(struct snd_soc_card *card,
1102 struct snd_soc_dai *dai; 1104 struct snd_soc_dai *dai;
1103 int ret; 1105 int ret;
1104 1106
1105 if (component->probed) 1107 if (!strcmp(component->name, "snd-soc-dummy"))
1106 return 0; 1108 return 0;
1107 1109
1108 component->card = card; 1110 if (component->card) {
1109 dapm->card = card; 1111 if (component->card != card) {
1110 soc_set_name_prefix(card, component); 1112 dev_err(component->dev,
1113 "Trying to bind component to card \"%s\" but is already bound to card \"%s\"\n",
1114 card->name, component->card->name);
1115 return -ENODEV;
1116 }
1117 return 0;
1118 }
1111 1119
1112 if (!try_module_get(component->dev->driver->owner)) 1120 if (!try_module_get(component->dev->driver->owner))
1113 return -ENODEV; 1121 return -ENODEV;
1114 1122
1123 component->card = card;
1124 dapm->card = card;
1125 soc_set_name_prefix(card, component);
1126
1115 soc_init_component_debugfs(component); 1127 soc_init_component_debugfs(component);
1116 1128
1117 if (component->dapm_widgets) { 1129 if (component->dapm_widgets) {
@@ -1155,7 +1167,6 @@ static int soc_probe_component(struct snd_soc_card *card,
1155 snd_soc_dapm_add_routes(dapm, component->dapm_routes, 1167 snd_soc_dapm_add_routes(dapm, component->dapm_routes,
1156 component->num_dapm_routes); 1168 component->num_dapm_routes);
1157 1169
1158 component->probed = 1;
1159 list_add(&dapm->list, &card->dapm_list); 1170 list_add(&dapm->list, &card->dapm_list);
1160 1171
1161 /* This is a HACK and will be removed soon */ 1172 /* This is a HACK and will be removed soon */
@@ -1166,6 +1177,7 @@ static int soc_probe_component(struct snd_soc_card *card,
1166 1177
1167err_probe: 1178err_probe:
1168 soc_cleanup_component_debugfs(component); 1179 soc_cleanup_component_debugfs(component);
1180 component->card = NULL;
1169 module_put(component->dev->driver->owner); 1181 module_put(component->dev->driver->owner);
1170 1182
1171 return ret; 1183 return ret;
@@ -1449,7 +1461,7 @@ static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1449 rtd->dev_registered = 0; 1461 rtd->dev_registered = 0;
1450 } 1462 }
1451 1463
1452 if (component && component->probed) 1464 if (component)
1453 soc_remove_component(component); 1465 soc_remove_component(component);
1454} 1466}
1455 1467
@@ -1716,6 +1728,7 @@ card_probe_error:
1716 if (card->remove) 1728 if (card->remove)
1717 card->remove(card); 1729 card->remove(card);
1718 1730
1731 snd_soc_dapm_free(&card->dapm);
1719 soc_cleanup_card_debugfs(card); 1732 soc_cleanup_card_debugfs(card);
1720 snd_card_free(card->snd_card); 1733 snd_card_free(card->snd_card);
1721 1734
@@ -2127,7 +2140,7 @@ EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
2127/** 2140/**
2128 * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio. 2141 * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
2129 * @dai: DAI 2142 * @dai: DAI
2130 * @ratio Ratio of BCLK to Sample rate. 2143 * @ratio: Ratio of BCLK to Sample rate.
2131 * 2144 *
2132 * Configures the DAI for a preset BCLK to sample rate ratio. 2145 * Configures the DAI for a preset BCLK to sample rate ratio.
2133 */ 2146 */
@@ -2651,10 +2664,7 @@ static int snd_soc_component_initialize(struct snd_soc_component *component,
2651 component->probe = component->driver->probe; 2664 component->probe = component->driver->probe;
2652 component->remove = component->driver->remove; 2665 component->remove = component->driver->remove;
2653 2666
2654 if (!component->dapm_ptr) 2667 dapm = &component->dapm;
2655 component->dapm_ptr = &component->dapm;
2656
2657 dapm = component->dapm_ptr;
2658 dapm->dev = dev; 2668 dapm->dev = dev;
2659 dapm->component = component; 2669 dapm->component = component;
2660 dapm->bias_level = SND_SOC_BIAS_OFF; 2670 dapm->bias_level = SND_SOC_BIAS_OFF;
@@ -2798,6 +2808,7 @@ EXPORT_SYMBOL_GPL(snd_soc_register_component);
2798/** 2808/**
2799 * snd_soc_unregister_component - Unregister a component from the ASoC core 2809 * snd_soc_unregister_component - Unregister a component from the ASoC core
2800 * 2810 *
2811 * @dev: The device to unregister
2801 */ 2812 */
2802void snd_soc_unregister_component(struct device *dev) 2813void snd_soc_unregister_component(struct device *dev)
2803{ 2814{
@@ -2838,7 +2849,7 @@ static void snd_soc_platform_drv_remove(struct snd_soc_component *component)
2838 * snd_soc_add_platform - Add a platform to the ASoC core 2849 * snd_soc_add_platform - Add a platform to the ASoC core
2839 * @dev: The parent device for the platform 2850 * @dev: The parent device for the platform
2840 * @platform: The platform to add 2851 * @platform: The platform to add
2841 * @platform_driver: The driver for the platform 2852 * @platform_drv: The driver for the platform
2842 */ 2853 */
2843int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform, 2854int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
2844 const struct snd_soc_platform_driver *platform_drv) 2855 const struct snd_soc_platform_driver *platform_drv)
@@ -2877,7 +2888,8 @@ EXPORT_SYMBOL_GPL(snd_soc_add_platform);
2877/** 2888/**
2878 * snd_soc_register_platform - Register a platform with the ASoC core 2889 * snd_soc_register_platform - Register a platform with the ASoC core
2879 * 2890 *
2880 * @platform: platform to register 2891 * @dev: The device for the platform
2892 * @platform_drv: The driver for the platform
2881 */ 2893 */
2882int snd_soc_register_platform(struct device *dev, 2894int snd_soc_register_platform(struct device *dev,
2883 const struct snd_soc_platform_driver *platform_drv) 2895 const struct snd_soc_platform_driver *platform_drv)
@@ -2938,7 +2950,7 @@ EXPORT_SYMBOL_GPL(snd_soc_lookup_platform);
2938/** 2950/**
2939 * snd_soc_unregister_platform - Unregister a platform from the ASoC core 2951 * snd_soc_unregister_platform - Unregister a platform from the ASoC core
2940 * 2952 *
2941 * @platform: platform to unregister 2953 * @dev: platform to unregister
2942 */ 2954 */
2943void snd_soc_unregister_platform(struct device *dev) 2955void snd_soc_unregister_platform(struct device *dev)
2944{ 2956{
@@ -3029,13 +3041,17 @@ static int snd_soc_codec_set_bias_level(struct snd_soc_dapm_context *dapm,
3029/** 3041/**
3030 * snd_soc_register_codec - Register a codec with the ASoC core 3042 * snd_soc_register_codec - Register a codec with the ASoC core
3031 * 3043 *
3032 * @codec: codec to register 3044 * @dev: The parent device for this codec
3045 * @codec_drv: Codec driver
3046 * @dai_drv: The associated DAI driver
3047 * @num_dai: Number of DAIs
3033 */ 3048 */
3034int snd_soc_register_codec(struct device *dev, 3049int snd_soc_register_codec(struct device *dev,
3035 const struct snd_soc_codec_driver *codec_drv, 3050 const struct snd_soc_codec_driver *codec_drv,
3036 struct snd_soc_dai_driver *dai_drv, 3051 struct snd_soc_dai_driver *dai_drv,
3037 int num_dai) 3052 int num_dai)
3038{ 3053{
3054 struct snd_soc_dapm_context *dapm;
3039 struct snd_soc_codec *codec; 3055 struct snd_soc_codec *codec;
3040 struct snd_soc_dai *dai; 3056 struct snd_soc_dai *dai;
3041 int ret, i; 3057 int ret, i;
@@ -3046,7 +3062,6 @@ int snd_soc_register_codec(struct device *dev,
3046 if (codec == NULL) 3062 if (codec == NULL)
3047 return -ENOMEM; 3063 return -ENOMEM;
3048 3064
3049 codec->component.dapm_ptr = &codec->dapm;
3050 codec->component.codec = codec; 3065 codec->component.codec = codec;
3051 3066
3052 ret = snd_soc_component_initialize(&codec->component, 3067 ret = snd_soc_component_initialize(&codec->component,
@@ -3076,12 +3091,14 @@ int snd_soc_register_codec(struct device *dev,
3076 if (codec_drv->read) 3091 if (codec_drv->read)
3077 codec->component.read = snd_soc_codec_drv_read; 3092 codec->component.read = snd_soc_codec_drv_read;
3078 codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time; 3093 codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time;
3079 codec->dapm.idle_bias_off = codec_drv->idle_bias_off; 3094
3080 codec->dapm.suspend_bias_off = codec_drv->suspend_bias_off; 3095 dapm = snd_soc_codec_get_dapm(codec);
3096 dapm->idle_bias_off = codec_drv->idle_bias_off;
3097 dapm->suspend_bias_off = codec_drv->suspend_bias_off;
3081 if (codec_drv->seq_notifier) 3098 if (codec_drv->seq_notifier)
3082 codec->dapm.seq_notifier = codec_drv->seq_notifier; 3099 dapm->seq_notifier = codec_drv->seq_notifier;
3083 if (codec_drv->set_bias_level) 3100 if (codec_drv->set_bias_level)
3084 codec->dapm.set_bias_level = snd_soc_codec_set_bias_level; 3101 dapm->set_bias_level = snd_soc_codec_set_bias_level;
3085 codec->dev = dev; 3102 codec->dev = dev;
3086 codec->driver = codec_drv; 3103 codec->driver = codec_drv;
3087 codec->component.val_bytes = codec_drv->reg_word_size; 3104 codec->component.val_bytes = codec_drv->reg_word_size;
@@ -3128,7 +3145,7 @@ EXPORT_SYMBOL_GPL(snd_soc_register_codec);
3128/** 3145/**
3129 * snd_soc_unregister_codec - Unregister a codec from the ASoC core 3146 * snd_soc_unregister_codec - Unregister a codec from the ASoC core
3130 * 3147 *
3131 * @codec: codec to unregister 3148 * @dev: codec to unregister
3132 */ 3149 */
3133void snd_soc_unregister_codec(struct device *dev) 3150void snd_soc_unregister_codec(struct device *dev)
3134{ 3151{
@@ -3303,6 +3320,26 @@ int snd_soc_of_parse_tdm_slot(struct device_node *np,
3303} 3320}
3304EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot); 3321EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot);
3305 3322
3323void snd_soc_of_parse_audio_prefix(struct snd_soc_card *card,
3324 struct snd_soc_codec_conf *codec_conf,
3325 struct device_node *of_node,
3326 const char *propname)
3327{
3328 struct device_node *np = card->dev->of_node;
3329 const char *str;
3330 int ret;
3331
3332 ret = of_property_read_string(np, propname, &str);
3333 if (ret < 0) {
3334 /* no prefix is not error */
3335 return;
3336 }
3337
3338 codec_conf->of_node = of_node;
3339 codec_conf->name_prefix = str;
3340}
3341EXPORT_SYMBOL_GPL(snd_soc_of_parse_audio_prefix);
3342
3306int snd_soc_of_parse_audio_routing(struct snd_soc_card *card, 3343int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
3307 const char *propname) 3344 const char *propname)
3308{ 3345{
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index aa327c92480c..f4bf21a5539b 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -47,6 +47,13 @@
47 47
48#define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++; 48#define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++;
49 49
50#define SND_SOC_DAPM_DIR_REVERSE(x) ((x == SND_SOC_DAPM_DIR_IN) ? \
51 SND_SOC_DAPM_DIR_OUT : SND_SOC_DAPM_DIR_IN)
52
53#define snd_soc_dapm_for_each_direction(dir) \
54 for ((dir) = SND_SOC_DAPM_DIR_IN; (dir) <= SND_SOC_DAPM_DIR_OUT; \
55 (dir)++)
56
50static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm, 57static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
51 struct snd_soc_dapm_widget *wsource, struct snd_soc_dapm_widget *wsink, 58 struct snd_soc_dapm_widget *wsource, struct snd_soc_dapm_widget *wsink,
52 const char *control, 59 const char *control,
@@ -167,45 +174,59 @@ static void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason)
167} 174}
168 175
169/* 176/*
170 * dapm_widget_invalidate_input_paths() - Invalidate the cached number of input 177 * Common implementation for dapm_widget_invalidate_input_paths() and
171 * paths 178 * dapm_widget_invalidate_output_paths(). The function is inlined since the
172 * @w: The widget for which to invalidate the cached number of input paths 179 * combined size of the two specialized functions is only marginally larger then
173 * 180 * the size of the generic function and at the same time the fast path of the
174 * The function resets the cached number of inputs for the specified widget and 181 * specialized functions is significantly smaller than the generic function.
175 * all widgets that can be reached via outgoing paths from the widget.
176 *
177 * This function must be called if the number of input paths for a widget might
178 * have changed. E.g. if the source state of a widget changes or a path is added
179 * or activated with the widget as the sink.
180 */ 182 */
181static void dapm_widget_invalidate_input_paths(struct snd_soc_dapm_widget *w) 183static __always_inline void dapm_widget_invalidate_paths(
184 struct snd_soc_dapm_widget *w, enum snd_soc_dapm_direction dir)
182{ 185{
183 struct snd_soc_dapm_widget *sink; 186 enum snd_soc_dapm_direction rdir = SND_SOC_DAPM_DIR_REVERSE(dir);
187 struct snd_soc_dapm_widget *node;
184 struct snd_soc_dapm_path *p; 188 struct snd_soc_dapm_path *p;
185 LIST_HEAD(list); 189 LIST_HEAD(list);
186 190
187 dapm_assert_locked(w->dapm); 191 dapm_assert_locked(w->dapm);
188 192
189 if (w->inputs == -1) 193 if (w->endpoints[dir] == -1)
190 return; 194 return;
191 195
192 w->inputs = -1;
193 list_add_tail(&w->work_list, &list); 196 list_add_tail(&w->work_list, &list);
197 w->endpoints[dir] = -1;
194 198
195 list_for_each_entry(w, &list, work_list) { 199 list_for_each_entry(w, &list, work_list) {
196 list_for_each_entry(p, &w->sinks, list_source) { 200 snd_soc_dapm_widget_for_each_path(w, dir, p) {
197 if (p->is_supply || p->weak || !p->connect) 201 if (p->is_supply || p->weak || !p->connect)
198 continue; 202 continue;
199 sink = p->sink; 203 node = p->node[rdir];
200 if (sink->inputs != -1) { 204 if (node->endpoints[dir] != -1) {
201 sink->inputs = -1; 205 node->endpoints[dir] = -1;
202 list_add_tail(&sink->work_list, &list); 206 list_add_tail(&node->work_list, &list);
203 } 207 }
204 } 208 }
205 } 209 }
206} 210}
207 211
208/* 212/*
213 * dapm_widget_invalidate_input_paths() - Invalidate the cached number of
214 * input paths
215 * @w: The widget for which to invalidate the cached number of input paths
216 *
217 * Resets the cached number of inputs for the specified widget and all widgets
218 * that can be reached via outcoming paths from the widget.
219 *
220 * This function must be called if the number of output paths for a widget might
221 * have changed. E.g. if the source state of a widget changes or a path is added
222 * or activated with the widget as the sink.
223 */
224static void dapm_widget_invalidate_input_paths(struct snd_soc_dapm_widget *w)
225{
226 dapm_widget_invalidate_paths(w, SND_SOC_DAPM_DIR_IN);
227}
228
229/*
209 * dapm_widget_invalidate_output_paths() - Invalidate the cached number of 230 * dapm_widget_invalidate_output_paths() - Invalidate the cached number of
210 * output paths 231 * output paths
211 * @w: The widget for which to invalidate the cached number of output paths 232 * @w: The widget for which to invalidate the cached number of output paths
@@ -219,29 +240,7 @@ static void dapm_widget_invalidate_input_paths(struct snd_soc_dapm_widget *w)
219 */ 240 */
220static void dapm_widget_invalidate_output_paths(struct snd_soc_dapm_widget *w) 241static void dapm_widget_invalidate_output_paths(struct snd_soc_dapm_widget *w)
221{ 242{
222 struct snd_soc_dapm_widget *source; 243 dapm_widget_invalidate_paths(w, SND_SOC_DAPM_DIR_OUT);
223 struct snd_soc_dapm_path *p;
224 LIST_HEAD(list);
225
226 dapm_assert_locked(w->dapm);
227
228 if (w->outputs == -1)
229 return;
230
231 w->outputs = -1;
232 list_add_tail(&w->work_list, &list);
233
234 list_for_each_entry(w, &list, work_list) {
235 list_for_each_entry(p, &w->sources, list_sink) {
236 if (p->is_supply || p->weak || !p->connect)
237 continue;
238 source = p->source;
239 if (source->outputs != -1) {
240 source->outputs = -1;
241 list_add_tail(&source->work_list, &list);
242 }
243 }
244 }
245} 244}
246 245
247/* 246/*
@@ -270,9 +269,9 @@ static void dapm_path_invalidate(struct snd_soc_dapm_path *p)
270 * endpoints is either connected or disconnected that sum won't change, 269 * endpoints is either connected or disconnected that sum won't change,
271 * so there is no need to re-check the path. 270 * so there is no need to re-check the path.
272 */ 271 */
273 if (p->source->inputs != 0) 272 if (p->source->endpoints[SND_SOC_DAPM_DIR_IN] != 0)
274 dapm_widget_invalidate_input_paths(p->sink); 273 dapm_widget_invalidate_input_paths(p->sink);
275 if (p->sink->outputs != 0) 274 if (p->sink->endpoints[SND_SOC_DAPM_DIR_OUT] != 0)
276 dapm_widget_invalidate_output_paths(p->source); 275 dapm_widget_invalidate_output_paths(p->source);
277} 276}
278 277
@@ -283,11 +282,11 @@ void dapm_mark_endpoints_dirty(struct snd_soc_card *card)
283 mutex_lock(&card->dapm_mutex); 282 mutex_lock(&card->dapm_mutex);
284 283
285 list_for_each_entry(w, &card->widgets, list) { 284 list_for_each_entry(w, &card->widgets, list) {
286 if (w->is_sink || w->is_source) { 285 if (w->is_ep) {
287 dapm_mark_dirty(w, "Rechecking endpoints"); 286 dapm_mark_dirty(w, "Rechecking endpoints");
288 if (w->is_sink) 287 if (w->is_ep & SND_SOC_DAPM_EP_SINK)
289 dapm_widget_invalidate_output_paths(w); 288 dapm_widget_invalidate_output_paths(w);
290 if (w->is_source) 289 if (w->is_ep & SND_SOC_DAPM_EP_SOURCE)
291 dapm_widget_invalidate_input_paths(w); 290 dapm_widget_invalidate_input_paths(w);
292 } 291 }
293 } 292 }
@@ -358,9 +357,10 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
358 data->widget = 357 data->widget =
359 snd_soc_dapm_new_control_unlocked(widget->dapm, 358 snd_soc_dapm_new_control_unlocked(widget->dapm,
360 &template); 359 &template);
360 kfree(name);
361 if (!data->widget) { 361 if (!data->widget) {
362 ret = -ENOMEM; 362 ret = -ENOMEM;
363 goto err_name; 363 goto err_data;
364 } 364 }
365 } 365 }
366 break; 366 break;
@@ -389,11 +389,12 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
389 389
390 data->value = template.on_val; 390 data->value = template.on_val;
391 391
392 data->widget = snd_soc_dapm_new_control(widget->dapm, 392 data->widget = snd_soc_dapm_new_control_unlocked(
393 &template); 393 widget->dapm, &template);
394 kfree(name);
394 if (!data->widget) { 395 if (!data->widget) {
395 ret = -ENOMEM; 396 ret = -ENOMEM;
396 goto err_name; 397 goto err_data;
397 } 398 }
398 399
399 snd_soc_dapm_add_path(widget->dapm, data->widget, 400 snd_soc_dapm_add_path(widget->dapm, data->widget,
@@ -408,8 +409,6 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
408 409
409 return 0; 410 return 0;
410 411
411err_name:
412 kfree(name);
413err_data: 412err_data:
414 kfree(data); 413 kfree(data);
415 return ret; 414 return ret;
@@ -418,8 +417,6 @@ err_data:
418static void dapm_kcontrol_free(struct snd_kcontrol *kctl) 417static void dapm_kcontrol_free(struct snd_kcontrol *kctl)
419{ 418{
420 struct dapm_kcontrol_data *data = snd_kcontrol_chip(kctl); 419 struct dapm_kcontrol_data *data = snd_kcontrol_chip(kctl);
421 if (data->widget)
422 kfree(data->widget->name);
423 kfree(data->wlist); 420 kfree(data->wlist);
424 kfree(data); 421 kfree(data);
425} 422}
@@ -896,7 +893,7 @@ static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
896 /* add kcontrol */ 893 /* add kcontrol */
897 for (i = 0; i < w->num_kcontrols; i++) { 894 for (i = 0; i < w->num_kcontrols; i++) {
898 /* match name */ 895 /* match name */
899 list_for_each_entry(path, &w->sources, list_sink) { 896 snd_soc_dapm_widget_for_each_source_path(w, path) {
900 /* mixer/mux paths name must match control name */ 897 /* mixer/mux paths name must match control name */
901 if (path->name != (char *)w->kcontrol_news[i].name) 898 if (path->name != (char *)w->kcontrol_news[i].name)
902 continue; 899 continue;
@@ -925,18 +922,18 @@ static int dapm_new_mixer(struct snd_soc_dapm_widget *w)
925static int dapm_new_mux(struct snd_soc_dapm_widget *w) 922static int dapm_new_mux(struct snd_soc_dapm_widget *w)
926{ 923{
927 struct snd_soc_dapm_context *dapm = w->dapm; 924 struct snd_soc_dapm_context *dapm = w->dapm;
925 enum snd_soc_dapm_direction dir;
928 struct snd_soc_dapm_path *path; 926 struct snd_soc_dapm_path *path;
929 struct list_head *paths;
930 const char *type; 927 const char *type;
931 int ret; 928 int ret;
932 929
933 switch (w->id) { 930 switch (w->id) {
934 case snd_soc_dapm_mux: 931 case snd_soc_dapm_mux:
935 paths = &w->sources; 932 dir = SND_SOC_DAPM_DIR_OUT;
936 type = "mux"; 933 type = "mux";
937 break; 934 break;
938 case snd_soc_dapm_demux: 935 case snd_soc_dapm_demux:
939 paths = &w->sinks; 936 dir = SND_SOC_DAPM_DIR_IN;
940 type = "demux"; 937 type = "demux";
941 break; 938 break;
942 default: 939 default:
@@ -950,7 +947,7 @@ static int dapm_new_mux(struct snd_soc_dapm_widget *w)
950 return -EINVAL; 947 return -EINVAL;
951 } 948 }
952 949
953 if (list_empty(paths)) { 950 if (list_empty(&w->edges[dir])) {
954 dev_err(dapm->dev, "ASoC: %s %s has no paths\n", type, w->name); 951 dev_err(dapm->dev, "ASoC: %s %s has no paths\n", type, w->name);
955 return -EINVAL; 952 return -EINVAL;
956 } 953 }
@@ -959,16 +956,9 @@ static int dapm_new_mux(struct snd_soc_dapm_widget *w)
959 if (ret < 0) 956 if (ret < 0)
960 return ret; 957 return ret;
961 958
962 if (w->id == snd_soc_dapm_mux) { 959 snd_soc_dapm_widget_for_each_path(w, dir, path) {
963 list_for_each_entry(path, &w->sources, list_sink) { 960 if (path->name)
964 if (path->name) 961 dapm_kcontrol_add_path(w->kcontrols[0], path);
965 dapm_kcontrol_add_path(w->kcontrols[0], path);
966 }
967 } else {
968 list_for_each_entry(path, &w->sinks, list_source) {
969 if (path->name)
970 dapm_kcontrol_add_path(w->kcontrols[0], path);
971 }
972 } 962 }
973 963
974 return 0; 964 return 0;
@@ -1034,66 +1024,59 @@ static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
1034 } 1024 }
1035} 1025}
1036 1026
1037/* add widget to list if it's not already in the list */ 1027static int dapm_widget_list_create(struct snd_soc_dapm_widget_list **list,
1038static int dapm_list_add_widget(struct snd_soc_dapm_widget_list **list, 1028 struct list_head *widgets)
1039 struct snd_soc_dapm_widget *w)
1040{ 1029{
1041 struct snd_soc_dapm_widget_list *wlist; 1030 struct snd_soc_dapm_widget *w;
1042 int wlistsize, wlistentries, i; 1031 struct list_head *it;
1043 1032 unsigned int size = 0;
1044 if (*list == NULL) 1033 unsigned int i = 0;
1045 return -EINVAL;
1046
1047 wlist = *list;
1048 1034
1049 /* is this widget already in the list */ 1035 list_for_each(it, widgets)
1050 for (i = 0; i < wlist->num_widgets; i++) { 1036 size++;
1051 if (wlist->widgets[i] == w)
1052 return 0;
1053 }
1054 1037
1055 /* allocate some new space */ 1038 *list = kzalloc(sizeof(**list) + size * sizeof(*w), GFP_KERNEL);
1056 wlistentries = wlist->num_widgets + 1; 1039 if (*list == NULL)
1057 wlistsize = sizeof(struct snd_soc_dapm_widget_list) +
1058 wlistentries * sizeof(struct snd_soc_dapm_widget *);
1059 *list = krealloc(wlist, wlistsize, GFP_KERNEL);
1060 if (*list == NULL) {
1061 dev_err(w->dapm->dev, "ASoC: can't allocate widget list for %s\n",
1062 w->name);
1063 return -ENOMEM; 1040 return -ENOMEM;
1064 }
1065 wlist = *list;
1066 1041
1067 /* insert the widget */ 1042 list_for_each_entry(w, widgets, work_list)
1068 dev_dbg(w->dapm->dev, "ASoC: added %s in widget list pos %d\n", 1043 (*list)->widgets[i++] = w;
1069 w->name, wlist->num_widgets);
1070 1044
1071 wlist->widgets[wlist->num_widgets] = w; 1045 (*list)->num_widgets = i;
1072 wlist->num_widgets++; 1046
1073 return 1; 1047 return 0;
1074} 1048}
1075 1049
1076/* 1050/*
1077 * Recursively check for a completed path to an active or physically connected 1051 * Common implementation for is_connected_output_ep() and
1078 * output widget. Returns number of complete paths. 1052 * is_connected_input_ep(). The function is inlined since the combined size of
1053 * the two specialized functions is only marginally larger then the size of the
1054 * generic function and at the same time the fast path of the specialized
1055 * functions is significantly smaller than the generic function.
1079 */ 1056 */
1080static int is_connected_output_ep(struct snd_soc_dapm_widget *widget, 1057static __always_inline int is_connected_ep(struct snd_soc_dapm_widget *widget,
1081 struct snd_soc_dapm_widget_list **list) 1058 struct list_head *list, enum snd_soc_dapm_direction dir,
1059 int (*fn)(struct snd_soc_dapm_widget *, struct list_head *))
1082{ 1060{
1061 enum snd_soc_dapm_direction rdir = SND_SOC_DAPM_DIR_REVERSE(dir);
1083 struct snd_soc_dapm_path *path; 1062 struct snd_soc_dapm_path *path;
1084 int con = 0; 1063 int con = 0;
1085 1064
1086 if (widget->outputs >= 0) 1065 if (widget->endpoints[dir] >= 0)
1087 return widget->outputs; 1066 return widget->endpoints[dir];
1088 1067
1089 DAPM_UPDATE_STAT(widget, path_checks); 1068 DAPM_UPDATE_STAT(widget, path_checks);
1090 1069
1091 if (widget->is_sink && widget->connected) { 1070 /* do we need to add this widget to the list ? */
1092 widget->outputs = snd_soc_dapm_suspend_check(widget); 1071 if (list)
1093 return widget->outputs; 1072 list_add_tail(&widget->work_list, list);
1073
1074 if ((widget->is_ep & SND_SOC_DAPM_DIR_TO_EP(dir)) && widget->connected) {
1075 widget->endpoints[dir] = snd_soc_dapm_suspend_check(widget);
1076 return widget->endpoints[dir];
1094 } 1077 }
1095 1078
1096 list_for_each_entry(path, &widget->sinks, list_source) { 1079 snd_soc_dapm_widget_for_each_path(widget, rdir, path) {
1097 DAPM_UPDATE_STAT(widget, neighbour_checks); 1080 DAPM_UPDATE_STAT(widget, neighbour_checks);
1098 1081
1099 if (path->weak || path->is_supply) 1082 if (path->weak || path->is_supply)
@@ -1102,91 +1085,40 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget,
1102 if (path->walking) 1085 if (path->walking)
1103 return 1; 1086 return 1;
1104 1087
1105 trace_snd_soc_dapm_output_path(widget, path); 1088 trace_snd_soc_dapm_path(widget, dir, path);
1106 1089
1107 if (path->connect) { 1090 if (path->connect) {
1108 path->walking = 1; 1091 path->walking = 1;
1109 1092 con += fn(path->node[dir], list);
1110 /* do we need to add this widget to the list ? */
1111 if (list) {
1112 int err;
1113 err = dapm_list_add_widget(list, path->sink);
1114 if (err < 0) {
1115 dev_err(widget->dapm->dev,
1116 "ASoC: could not add widget %s\n",
1117 widget->name);
1118 path->walking = 0;
1119 return con;
1120 }
1121 }
1122
1123 con += is_connected_output_ep(path->sink, list);
1124
1125 path->walking = 0; 1093 path->walking = 0;
1126 } 1094 }
1127 } 1095 }
1128 1096
1129 widget->outputs = con; 1097 widget->endpoints[dir] = con;
1130 1098
1131 return con; 1099 return con;
1132} 1100}
1133 1101
1134/* 1102/*
1135 * Recursively check for a completed path to an active or physically connected 1103 * Recursively check for a completed path to an active or physically connected
1104 * output widget. Returns number of complete paths.
1105 */
1106static int is_connected_output_ep(struct snd_soc_dapm_widget *widget,
1107 struct list_head *list)
1108{
1109 return is_connected_ep(widget, list, SND_SOC_DAPM_DIR_OUT,
1110 is_connected_output_ep);
1111}
1112
1113/*
1114 * Recursively check for a completed path to an active or physically connected
1136 * input widget. Returns number of complete paths. 1115 * input widget. Returns number of complete paths.
1137 */ 1116 */
1138static int is_connected_input_ep(struct snd_soc_dapm_widget *widget, 1117static int is_connected_input_ep(struct snd_soc_dapm_widget *widget,
1139 struct snd_soc_dapm_widget_list **list) 1118 struct list_head *list)
1140{ 1119{
1141 struct snd_soc_dapm_path *path; 1120 return is_connected_ep(widget, list, SND_SOC_DAPM_DIR_IN,
1142 int con = 0; 1121 is_connected_input_ep);
1143
1144 if (widget->inputs >= 0)
1145 return widget->inputs;
1146
1147 DAPM_UPDATE_STAT(widget, path_checks);
1148
1149 if (widget->is_source && widget->connected) {
1150 widget->inputs = snd_soc_dapm_suspend_check(widget);
1151 return widget->inputs;
1152 }
1153
1154 list_for_each_entry(path, &widget->sources, list_sink) {
1155 DAPM_UPDATE_STAT(widget, neighbour_checks);
1156
1157 if (path->weak || path->is_supply)
1158 continue;
1159
1160 if (path->walking)
1161 return 1;
1162
1163 trace_snd_soc_dapm_input_path(widget, path);
1164
1165 if (path->connect) {
1166 path->walking = 1;
1167
1168 /* do we need to add this widget to the list ? */
1169 if (list) {
1170 int err;
1171 err = dapm_list_add_widget(list, path->source);
1172 if (err < 0) {
1173 dev_err(widget->dapm->dev,
1174 "ASoC: could not add widget %s\n",
1175 widget->name);
1176 path->walking = 0;
1177 return con;
1178 }
1179 }
1180
1181 con += is_connected_input_ep(path->source, list);
1182
1183 path->walking = 0;
1184 }
1185 }
1186
1187 widget->inputs = con;
1188
1189 return con;
1190} 1122}
1191 1123
1192/** 1124/**
@@ -1206,7 +1138,9 @@ int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
1206{ 1138{
1207 struct snd_soc_card *card = dai->component->card; 1139 struct snd_soc_card *card = dai->component->card;
1208 struct snd_soc_dapm_widget *w; 1140 struct snd_soc_dapm_widget *w;
1141 LIST_HEAD(widgets);
1209 int paths; 1142 int paths;
1143 int ret;
1210 1144
1211 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); 1145 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME);
1212 1146
@@ -1215,14 +1149,21 @@ int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream,
1215 * to reset the cached number of inputs and outputs. 1149 * to reset the cached number of inputs and outputs.
1216 */ 1150 */
1217 list_for_each_entry(w, &card->widgets, list) { 1151 list_for_each_entry(w, &card->widgets, list) {
1218 w->inputs = -1; 1152 w->endpoints[SND_SOC_DAPM_DIR_IN] = -1;
1219 w->outputs = -1; 1153 w->endpoints[SND_SOC_DAPM_DIR_OUT] = -1;
1220 } 1154 }
1221 1155
1222 if (stream == SNDRV_PCM_STREAM_PLAYBACK) 1156 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
1223 paths = is_connected_output_ep(dai->playback_widget, list); 1157 paths = is_connected_output_ep(dai->playback_widget, &widgets);
1224 else 1158 else
1225 paths = is_connected_input_ep(dai->capture_widget, list); 1159 paths = is_connected_input_ep(dai->capture_widget, &widgets);
1160
1161 /* Drop starting point */
1162 list_del(widgets.next);
1163
1164 ret = dapm_widget_list_create(list, &widgets);
1165 if (ret)
1166 paths = ret;
1226 1167
1227 trace_snd_soc_dapm_connected(paths, stream); 1168 trace_snd_soc_dapm_connected(paths, stream);
1228 mutex_unlock(&card->dapm_mutex); 1169 mutex_unlock(&card->dapm_mutex);
@@ -1323,7 +1264,7 @@ static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
1323 DAPM_UPDATE_STAT(w, power_checks); 1264 DAPM_UPDATE_STAT(w, power_checks);
1324 1265
1325 /* Check if one of our outputs is connected */ 1266 /* Check if one of our outputs is connected */
1326 list_for_each_entry(path, &w->sinks, list_source) { 1267 snd_soc_dapm_widget_for_each_sink_path(w, path) {
1327 DAPM_UPDATE_STAT(w, neighbour_checks); 1268 DAPM_UPDATE_STAT(w, neighbour_checks);
1328 1269
1329 if (path->weak) 1270 if (path->weak)
@@ -1747,12 +1688,12 @@ static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power,
1747 /* If we changed our power state perhaps our neigbours changed 1688 /* If we changed our power state perhaps our neigbours changed
1748 * also. 1689 * also.
1749 */ 1690 */
1750 list_for_each_entry(path, &w->sources, list_sink) 1691 snd_soc_dapm_widget_for_each_source_path(w, path)
1751 dapm_widget_set_peer_power(path->source, power, path->connect); 1692 dapm_widget_set_peer_power(path->source, power, path->connect);
1752 1693
1753 /* Supplies can't affect their outputs, only their inputs */ 1694 /* Supplies can't affect their outputs, only their inputs */
1754 if (!w->is_supply) { 1695 if (!w->is_supply) {
1755 list_for_each_entry(path, &w->sinks, list_source) 1696 snd_soc_dapm_widget_for_each_sink_path(w, path)
1756 dapm_widget_set_peer_power(path->sink, power, 1697 dapm_widget_set_peer_power(path->sink, power,
1757 path->connect); 1698 path->connect);
1758 } 1699 }
@@ -1952,6 +1893,8 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
1952 size_t count, loff_t *ppos) 1893 size_t count, loff_t *ppos)
1953{ 1894{
1954 struct snd_soc_dapm_widget *w = file->private_data; 1895 struct snd_soc_dapm_widget *w = file->private_data;
1896 struct snd_soc_card *card = w->dapm->card;
1897 enum snd_soc_dapm_direction dir, rdir;
1955 char *buf; 1898 char *buf;
1956 int in, out; 1899 int in, out;
1957 ssize_t ret; 1900 ssize_t ret;
@@ -1961,6 +1904,8 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
1961 if (!buf) 1904 if (!buf)
1962 return -ENOMEM; 1905 return -ENOMEM;
1963 1906
1907 mutex_lock(&card->dapm_mutex);
1908
1964 /* Supply widgets are not handled by is_connected_{input,output}_ep() */ 1909 /* Supply widgets are not handled by is_connected_{input,output}_ep() */
1965 if (w->is_supply) { 1910 if (w->is_supply) {
1966 in = 0; 1911 in = 0;
@@ -1986,27 +1931,25 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
1986 w->sname, 1931 w->sname,
1987 w->active ? "active" : "inactive"); 1932 w->active ? "active" : "inactive");
1988 1933
1989 list_for_each_entry(p, &w->sources, list_sink) { 1934 snd_soc_dapm_for_each_direction(dir) {
1990 if (p->connected && !p->connected(w, p->source)) 1935 rdir = SND_SOC_DAPM_DIR_REVERSE(dir);
1991 continue; 1936 snd_soc_dapm_widget_for_each_path(w, dir, p) {
1937 if (p->connected && !p->connected(w, p->node[rdir]))
1938 continue;
1992 1939
1993 if (p->connect) 1940 if (!p->connect)
1994 ret += snprintf(buf + ret, PAGE_SIZE - ret, 1941 continue;
1995 " in \"%s\" \"%s\"\n",
1996 p->name ? p->name : "static",
1997 p->source->name);
1998 }
1999 list_for_each_entry(p, &w->sinks, list_source) {
2000 if (p->connected && !p->connected(w, p->sink))
2001 continue;
2002 1942
2003 if (p->connect)
2004 ret += snprintf(buf + ret, PAGE_SIZE - ret, 1943 ret += snprintf(buf + ret, PAGE_SIZE - ret,
2005 " out \"%s\" \"%s\"\n", 1944 " %s \"%s\" \"%s\"\n",
1945 (rdir == SND_SOC_DAPM_DIR_IN) ? "in" : "out",
2006 p->name ? p->name : "static", 1946 p->name ? p->name : "static",
2007 p->sink->name); 1947 p->node[rdir]->name);
1948 }
2008 } 1949 }
2009 1950
1951 mutex_unlock(&card->dapm_mutex);
1952
2010 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 1953 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
2011 1954
2012 kfree(buf); 1955 kfree(buf);
@@ -2220,14 +2163,16 @@ int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context *dapm,
2220} 2163}
2221EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power); 2164EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power);
2222 2165
2223static ssize_t dapm_widget_show_codec(struct snd_soc_codec *codec, char *buf) 2166static ssize_t dapm_widget_show_component(struct snd_soc_component *cmpnt,
2167 char *buf)
2224{ 2168{
2169 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(cmpnt);
2225 struct snd_soc_dapm_widget *w; 2170 struct snd_soc_dapm_widget *w;
2226 int count = 0; 2171 int count = 0;
2227 char *state = "not set"; 2172 char *state = "not set";
2228 2173
2229 list_for_each_entry(w, &codec->component.card->widgets, list) { 2174 list_for_each_entry(w, &cmpnt->card->widgets, list) {
2230 if (w->dapm != &codec->dapm) 2175 if (w->dapm != dapm)
2231 continue; 2176 continue;
2232 2177
2233 /* only display widgets that burnm power */ 2178 /* only display widgets that burnm power */
@@ -2255,7 +2200,7 @@ static ssize_t dapm_widget_show_codec(struct snd_soc_codec *codec, char *buf)
2255 } 2200 }
2256 } 2201 }
2257 2202
2258 switch (codec->dapm.bias_level) { 2203 switch (snd_soc_dapm_get_bias_level(dapm)) {
2259 case SND_SOC_BIAS_ON: 2204 case SND_SOC_BIAS_ON:
2260 state = "On"; 2205 state = "On";
2261 break; 2206 break;
@@ -2281,11 +2226,16 @@ static ssize_t dapm_widget_show(struct device *dev,
2281 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); 2226 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
2282 int i, count = 0; 2227 int i, count = 0;
2283 2228
2229 mutex_lock(&rtd->card->dapm_mutex);
2230
2284 for (i = 0; i < rtd->num_codecs; i++) { 2231 for (i = 0; i < rtd->num_codecs; i++) {
2285 struct snd_soc_codec *codec = rtd->codec_dais[i]->codec; 2232 struct snd_soc_component *cmpnt = rtd->codec_dais[i]->component;
2286 count += dapm_widget_show_codec(codec, buf + count); 2233
2234 count += dapm_widget_show_component(cmpnt, buf + count);
2287 } 2235 }
2288 2236
2237 mutex_unlock(&rtd->card->dapm_mutex);
2238
2289 return count; 2239 return count;
2290} 2240}
2291 2241
@@ -2298,37 +2248,43 @@ struct attribute *soc_dapm_dev_attrs[] = {
2298 2248
2299static void dapm_free_path(struct snd_soc_dapm_path *path) 2249static void dapm_free_path(struct snd_soc_dapm_path *path)
2300{ 2250{
2301 list_del(&path->list_sink); 2251 list_del(&path->list_node[SND_SOC_DAPM_DIR_IN]);
2302 list_del(&path->list_source); 2252 list_del(&path->list_node[SND_SOC_DAPM_DIR_OUT]);
2303 list_del(&path->list_kcontrol); 2253 list_del(&path->list_kcontrol);
2304 list_del(&path->list); 2254 list_del(&path->list);
2305 kfree(path); 2255 kfree(path);
2306} 2256}
2307 2257
2258void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w)
2259{
2260 struct snd_soc_dapm_path *p, *next_p;
2261 enum snd_soc_dapm_direction dir;
2262
2263 list_del(&w->list);
2264 /*
2265 * remove source and sink paths associated to this widget.
2266 * While removing the path, remove reference to it from both
2267 * source and sink widgets so that path is removed only once.
2268 */
2269 snd_soc_dapm_for_each_direction(dir) {
2270 snd_soc_dapm_widget_for_each_path_safe(w, dir, p, next_p)
2271 dapm_free_path(p);
2272 }
2273
2274 kfree(w->kcontrols);
2275 kfree_const(w->name);
2276 kfree(w);
2277}
2278
2308/* free all dapm widgets and resources */ 2279/* free all dapm widgets and resources */
2309static void dapm_free_widgets(struct snd_soc_dapm_context *dapm) 2280static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
2310{ 2281{
2311 struct snd_soc_dapm_widget *w, *next_w; 2282 struct snd_soc_dapm_widget *w, *next_w;
2312 struct snd_soc_dapm_path *p, *next_p;
2313 2283
2314 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) { 2284 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
2315 if (w->dapm != dapm) 2285 if (w->dapm != dapm)
2316 continue; 2286 continue;
2317 list_del(&w->list); 2287 snd_soc_dapm_free_widget(w);
2318 /*
2319 * remove source and sink paths associated to this widget.
2320 * While removing the path, remove reference to it from both
2321 * source and sink widgets so that path is removed only once.
2322 */
2323 list_for_each_entry_safe(p, next_p, &w->sources, list_sink)
2324 dapm_free_path(p);
2325
2326 list_for_each_entry_safe(p, next_p, &w->sinks, list_source)
2327 dapm_free_path(p);
2328
2329 kfree(w->kcontrols);
2330 kfree(w->name);
2331 kfree(w);
2332 } 2288 }
2333} 2289}
2334 2290
@@ -2434,20 +2390,22 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
2434 */ 2390 */
2435static void dapm_update_widget_flags(struct snd_soc_dapm_widget *w) 2391static void dapm_update_widget_flags(struct snd_soc_dapm_widget *w)
2436{ 2392{
2393 enum snd_soc_dapm_direction dir;
2437 struct snd_soc_dapm_path *p; 2394 struct snd_soc_dapm_path *p;
2395 unsigned int ep;
2438 2396
2439 switch (w->id) { 2397 switch (w->id) {
2440 case snd_soc_dapm_input: 2398 case snd_soc_dapm_input:
2441 /* On a fully routed card a input is never a source */ 2399 /* On a fully routed card a input is never a source */
2442 if (w->dapm->card->fully_routed) 2400 if (w->dapm->card->fully_routed)
2443 break; 2401 return;
2444 w->is_source = 1; 2402 ep = SND_SOC_DAPM_EP_SOURCE;
2445 list_for_each_entry(p, &w->sources, list_sink) { 2403 snd_soc_dapm_widget_for_each_source_path(w, p) {
2446 if (p->source->id == snd_soc_dapm_micbias || 2404 if (p->source->id == snd_soc_dapm_micbias ||
2447 p->source->id == snd_soc_dapm_mic || 2405 p->source->id == snd_soc_dapm_mic ||
2448 p->source->id == snd_soc_dapm_line || 2406 p->source->id == snd_soc_dapm_line ||
2449 p->source->id == snd_soc_dapm_output) { 2407 p->source->id == snd_soc_dapm_output) {
2450 w->is_source = 0; 2408 ep = 0;
2451 break; 2409 break;
2452 } 2410 }
2453 } 2411 }
@@ -2455,25 +2413,30 @@ static void dapm_update_widget_flags(struct snd_soc_dapm_widget *w)
2455 case snd_soc_dapm_output: 2413 case snd_soc_dapm_output:
2456 /* On a fully routed card a output is never a sink */ 2414 /* On a fully routed card a output is never a sink */
2457 if (w->dapm->card->fully_routed) 2415 if (w->dapm->card->fully_routed)
2458 break; 2416 return;
2459 w->is_sink = 1; 2417 ep = SND_SOC_DAPM_EP_SINK;
2460 list_for_each_entry(p, &w->sinks, list_source) { 2418 snd_soc_dapm_widget_for_each_sink_path(w, p) {
2461 if (p->sink->id == snd_soc_dapm_spk || 2419 if (p->sink->id == snd_soc_dapm_spk ||
2462 p->sink->id == snd_soc_dapm_hp || 2420 p->sink->id == snd_soc_dapm_hp ||
2463 p->sink->id == snd_soc_dapm_line || 2421 p->sink->id == snd_soc_dapm_line ||
2464 p->sink->id == snd_soc_dapm_input) { 2422 p->sink->id == snd_soc_dapm_input) {
2465 w->is_sink = 0; 2423 ep = 0;
2466 break; 2424 break;
2467 } 2425 }
2468 } 2426 }
2469 break; 2427 break;
2470 case snd_soc_dapm_line: 2428 case snd_soc_dapm_line:
2471 w->is_sink = !list_empty(&w->sources); 2429 ep = 0;
2472 w->is_source = !list_empty(&w->sinks); 2430 snd_soc_dapm_for_each_direction(dir) {
2431 if (!list_empty(&w->edges[dir]))
2432 ep |= SND_SOC_DAPM_DIR_TO_EP(dir);
2433 }
2473 break; 2434 break;
2474 default: 2435 default:
2475 break; 2436 return;
2476 } 2437 }
2438
2439 w->is_ep = ep;
2477} 2440}
2478 2441
2479static int snd_soc_dapm_check_dynamic_path(struct snd_soc_dapm_context *dapm, 2442static int snd_soc_dapm_check_dynamic_path(struct snd_soc_dapm_context *dapm,
@@ -2526,6 +2489,8 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
2526 int (*connected)(struct snd_soc_dapm_widget *source, 2489 int (*connected)(struct snd_soc_dapm_widget *source,
2527 struct snd_soc_dapm_widget *sink)) 2490 struct snd_soc_dapm_widget *sink))
2528{ 2491{
2492 struct snd_soc_dapm_widget *widgets[2];
2493 enum snd_soc_dapm_direction dir;
2529 struct snd_soc_dapm_path *path; 2494 struct snd_soc_dapm_path *path;
2530 int ret; 2495 int ret;
2531 2496
@@ -2558,13 +2523,14 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
2558 if (!path) 2523 if (!path)
2559 return -ENOMEM; 2524 return -ENOMEM;
2560 2525
2561 path->source = wsource; 2526 path->node[SND_SOC_DAPM_DIR_IN] = wsource;
2562 path->sink = wsink; 2527 path->node[SND_SOC_DAPM_DIR_OUT] = wsink;
2528 widgets[SND_SOC_DAPM_DIR_IN] = wsource;
2529 widgets[SND_SOC_DAPM_DIR_OUT] = wsink;
2530
2563 path->connected = connected; 2531 path->connected = connected;
2564 INIT_LIST_HEAD(&path->list); 2532 INIT_LIST_HEAD(&path->list);
2565 INIT_LIST_HEAD(&path->list_kcontrol); 2533 INIT_LIST_HEAD(&path->list_kcontrol);
2566 INIT_LIST_HEAD(&path->list_source);
2567 INIT_LIST_HEAD(&path->list_sink);
2568 2534
2569 if (wsource->is_supply || wsink->is_supply) 2535 if (wsource->is_supply || wsink->is_supply)
2570 path->is_supply = 1; 2536 path->is_supply = 1;
@@ -2602,14 +2568,13 @@ static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm,
2602 } 2568 }
2603 2569
2604 list_add(&path->list, &dapm->card->paths); 2570 list_add(&path->list, &dapm->card->paths);
2605 list_add(&path->list_sink, &wsink->sources); 2571 snd_soc_dapm_for_each_direction(dir)
2606 list_add(&path->list_source, &wsource->sinks); 2572 list_add(&path->list_node[dir], &widgets[dir]->edges[dir]);
2607
2608 dapm_update_widget_flags(wsource);
2609 dapm_update_widget_flags(wsink);
2610 2573
2611 dapm_mark_dirty(wsource, "Route added"); 2574 snd_soc_dapm_for_each_direction(dir) {
2612 dapm_mark_dirty(wsink, "Route added"); 2575 dapm_update_widget_flags(widgets[dir]);
2576 dapm_mark_dirty(widgets[dir], "Route added");
2577 }
2613 2578
2614 if (dapm->card->instantiated && path->connect) 2579 if (dapm->card->instantiated && path->connect)
2615 dapm_path_invalidate(path); 2580 dapm_path_invalidate(path);
@@ -2857,7 +2822,7 @@ static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm,
2857 dev_warn(dapm->dev, "ASoC: Ignoring control for weak route %s->%s\n", 2822 dev_warn(dapm->dev, "ASoC: Ignoring control for weak route %s->%s\n",
2858 route->source, route->sink); 2823 route->source, route->sink);
2859 2824
2860 list_for_each_entry(path, &source->sinks, list_source) { 2825 snd_soc_dapm_widget_for_each_sink_path(source, path) {
2861 if (path->sink == sink) { 2826 if (path->sink == sink) {
2862 path->weak = 1; 2827 path->weak = 1;
2863 count++; 2828 count++;
@@ -2911,7 +2876,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes);
2911 2876
2912/** 2877/**
2913 * snd_soc_dapm_new_widgets - add new dapm widgets 2878 * snd_soc_dapm_new_widgets - add new dapm widgets
2914 * @dapm: DAPM context 2879 * @card: card to be checked for new dapm widgets
2915 * 2880 *
2916 * Checks the codec for any new dapm widgets and creates them if found. 2881 * Checks the codec for any new dapm widgets and creates them if found.
2917 * 2882 *
@@ -3291,6 +3256,7 @@ struct snd_soc_dapm_widget *
3291snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm, 3256snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
3292 const struct snd_soc_dapm_widget *widget) 3257 const struct snd_soc_dapm_widget *widget)
3293{ 3258{
3259 enum snd_soc_dapm_direction dir;
3294 struct snd_soc_dapm_widget *w; 3260 struct snd_soc_dapm_widget *w;
3295 const char *prefix; 3261 const char *prefix;
3296 int ret; 3262 int ret;
@@ -3334,16 +3300,10 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
3334 } 3300 }
3335 3301
3336 prefix = soc_dapm_prefix(dapm); 3302 prefix = soc_dapm_prefix(dapm);
3337 if (prefix) { 3303 if (prefix)
3338 w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, widget->name); 3304 w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, widget->name);
3339 if (widget->sname) 3305 else
3340 w->sname = kasprintf(GFP_KERNEL, "%s %s", prefix, 3306 w->name = kstrdup_const(widget->name, GFP_KERNEL);
3341 widget->sname);
3342 } else {
3343 w->name = kasprintf(GFP_KERNEL, "%s", widget->name);
3344 if (widget->sname)
3345 w->sname = kasprintf(GFP_KERNEL, "%s", widget->sname);
3346 }
3347 if (w->name == NULL) { 3307 if (w->name == NULL) {
3348 kfree(w); 3308 kfree(w);
3349 return NULL; 3309 return NULL;
@@ -3351,27 +3311,27 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
3351 3311
3352 switch (w->id) { 3312 switch (w->id) {
3353 case snd_soc_dapm_mic: 3313 case snd_soc_dapm_mic:
3354 w->is_source = 1; 3314 w->is_ep = SND_SOC_DAPM_EP_SOURCE;
3355 w->power_check = dapm_generic_check_power; 3315 w->power_check = dapm_generic_check_power;
3356 break; 3316 break;
3357 case snd_soc_dapm_input: 3317 case snd_soc_dapm_input:
3358 if (!dapm->card->fully_routed) 3318 if (!dapm->card->fully_routed)
3359 w->is_source = 1; 3319 w->is_ep = SND_SOC_DAPM_EP_SOURCE;
3360 w->power_check = dapm_generic_check_power; 3320 w->power_check = dapm_generic_check_power;
3361 break; 3321 break;
3362 case snd_soc_dapm_spk: 3322 case snd_soc_dapm_spk:
3363 case snd_soc_dapm_hp: 3323 case snd_soc_dapm_hp:
3364 w->is_sink = 1; 3324 w->is_ep = SND_SOC_DAPM_EP_SINK;
3365 w->power_check = dapm_generic_check_power; 3325 w->power_check = dapm_generic_check_power;
3366 break; 3326 break;
3367 case snd_soc_dapm_output: 3327 case snd_soc_dapm_output:
3368 if (!dapm->card->fully_routed) 3328 if (!dapm->card->fully_routed)
3369 w->is_sink = 1; 3329 w->is_ep = SND_SOC_DAPM_EP_SINK;
3370 w->power_check = dapm_generic_check_power; 3330 w->power_check = dapm_generic_check_power;
3371 break; 3331 break;
3372 case snd_soc_dapm_vmid: 3332 case snd_soc_dapm_vmid:
3373 case snd_soc_dapm_siggen: 3333 case snd_soc_dapm_siggen:
3374 w->is_source = 1; 3334 w->is_ep = SND_SOC_DAPM_EP_SOURCE;
3375 w->power_check = dapm_always_on_check_power; 3335 w->power_check = dapm_always_on_check_power;
3376 break; 3336 break;
3377 case snd_soc_dapm_mux: 3337 case snd_soc_dapm_mux:
@@ -3405,14 +3365,14 @@ snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm,
3405 } 3365 }
3406 3366
3407 w->dapm = dapm; 3367 w->dapm = dapm;
3408 INIT_LIST_HEAD(&w->sources);
3409 INIT_LIST_HEAD(&w->sinks);
3410 INIT_LIST_HEAD(&w->list); 3368 INIT_LIST_HEAD(&w->list);
3411 INIT_LIST_HEAD(&w->dirty); 3369 INIT_LIST_HEAD(&w->dirty);
3412 list_add_tail(&w->list, &dapm->card->widgets); 3370 list_add_tail(&w->list, &dapm->card->widgets);
3413 3371
3414 w->inputs = -1; 3372 snd_soc_dapm_for_each_direction(dir) {
3415 w->outputs = -1; 3373 INIT_LIST_HEAD(&w->edges[dir]);
3374 w->endpoints[dir] = -1;
3375 }
3416 3376
3417 /* machine layer set ups unconnected pins and insertions */ 3377 /* machine layer set ups unconnected pins and insertions */
3418 w->connected = 1; 3378 w->connected = 1;
@@ -3466,19 +3426,17 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
3466 int ret; 3426 int ret;
3467 3427
3468 if (WARN_ON(!config) || 3428 if (WARN_ON(!config) ||
3469 WARN_ON(list_empty(&w->sources) || list_empty(&w->sinks))) 3429 WARN_ON(list_empty(&w->edges[SND_SOC_DAPM_DIR_OUT]) ||
3430 list_empty(&w->edges[SND_SOC_DAPM_DIR_IN])))
3470 return -EINVAL; 3431 return -EINVAL;
3471 3432
3472 /* We only support a single source and sink, pick the first */ 3433 /* We only support a single source and sink, pick the first */
3473 source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path, 3434 source_p = list_first_entry(&w->edges[SND_SOC_DAPM_DIR_OUT],
3474 list_sink); 3435 struct snd_soc_dapm_path,
3475 sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path, 3436 list_node[SND_SOC_DAPM_DIR_OUT]);
3476 list_source); 3437 sink_p = list_first_entry(&w->edges[SND_SOC_DAPM_DIR_IN],
3477 3438 struct snd_soc_dapm_path,
3478 if (WARN_ON(!source_p || !sink_p) || 3439 list_node[SND_SOC_DAPM_DIR_IN]);
3479 WARN_ON(!sink_p->source || !source_p->sink) ||
3480 WARN_ON(!source_p->source || !sink_p->sink))
3481 return -EINVAL;
3482 3440
3483 source = source_p->source->priv; 3441 source = source_p->source->priv;
3484 sink = sink_p->sink->priv; 3442 sink = sink_p->sink->priv;
@@ -3792,7 +3750,7 @@ int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card)
3792 break; 3750 break;
3793 } 3751 }
3794 3752
3795 if (!w->sname || !strstr(w->sname, dai_w->name)) 3753 if (!w->sname || !strstr(w->sname, dai_w->sname))
3796 continue; 3754 continue;
3797 3755
3798 if (dai_w->id == snd_soc_dapm_dai_in) { 3756 if (dai_w->id == snd_soc_dapm_dai_in) {
@@ -3820,11 +3778,6 @@ static void dapm_connect_dai_link_widgets(struct snd_soc_card *card,
3820 for (i = 0; i < rtd->num_codecs; i++) { 3778 for (i = 0; i < rtd->num_codecs; i++) {
3821 struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; 3779 struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
3822 3780
3823 /* there is no point in connecting BE DAI links with dummies */
3824 if (snd_soc_dai_is_dummy(codec_dai) ||
3825 snd_soc_dai_is_dummy(cpu_dai))
3826 continue;
3827
3828 /* connect BE DAI playback if widgets are valid */ 3781 /* connect BE DAI playback if widgets are valid */
3829 if (codec_dai->playback_widget && cpu_dai->playback_widget) { 3782 if (codec_dai->playback_widget && cpu_dai->playback_widget) {
3830 source = cpu_dai->playback_widget; 3783 source = cpu_dai->playback_widget;
@@ -3855,6 +3808,7 @@ static void soc_dapm_dai_stream_event(struct snd_soc_dai *dai, int stream,
3855 int event) 3808 int event)
3856{ 3809{
3857 struct snd_soc_dapm_widget *w; 3810 struct snd_soc_dapm_widget *w;
3811 unsigned int ep;
3858 3812
3859 if (stream == SNDRV_PCM_STREAM_PLAYBACK) 3813 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
3860 w = dai->playback_widget; 3814 w = dai->playback_widget;
@@ -3864,12 +3818,22 @@ static void soc_dapm_dai_stream_event(struct snd_soc_dai *dai, int stream,
3864 if (w) { 3818 if (w) {
3865 dapm_mark_dirty(w, "stream event"); 3819 dapm_mark_dirty(w, "stream event");
3866 3820
3821 if (w->id == snd_soc_dapm_dai_in) {
3822 ep = SND_SOC_DAPM_EP_SOURCE;
3823 dapm_widget_invalidate_input_paths(w);
3824 } else {
3825 ep = SND_SOC_DAPM_EP_SINK;
3826 dapm_widget_invalidate_output_paths(w);
3827 }
3828
3867 switch (event) { 3829 switch (event) {
3868 case SND_SOC_DAPM_STREAM_START: 3830 case SND_SOC_DAPM_STREAM_START:
3869 w->active = 1; 3831 w->active = 1;
3832 w->is_ep = ep;
3870 break; 3833 break;
3871 case SND_SOC_DAPM_STREAM_STOP: 3834 case SND_SOC_DAPM_STREAM_STOP:
3872 w->active = 0; 3835 w->active = 0;
3836 w->is_ep = 0;
3873 break; 3837 break;
3874 case SND_SOC_DAPM_STREAM_SUSPEND: 3838 case SND_SOC_DAPM_STREAM_SUSPEND:
3875 case SND_SOC_DAPM_STREAM_RESUME: 3839 case SND_SOC_DAPM_STREAM_RESUME:
@@ -3877,14 +3841,6 @@ static void soc_dapm_dai_stream_event(struct snd_soc_dai *dai, int stream,
3877 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: 3841 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
3878 break; 3842 break;
3879 } 3843 }
3880
3881 if (w->id == snd_soc_dapm_dai_in) {
3882 w->is_source = w->active;
3883 dapm_widget_invalidate_input_paths(w);
3884 } else {
3885 w->is_sink = w->active;
3886 dapm_widget_invalidate_output_paths(w);
3887 }
3888 } 3844 }
3889} 3845}
3890 3846
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 256b9c91aa94..70e4b9d8bdcd 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1231,24 +1231,17 @@ static int widget_in_list(struct snd_soc_dapm_widget_list *list,
1231} 1231}
1232 1232
1233int dpcm_path_get(struct snd_soc_pcm_runtime *fe, 1233int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
1234 int stream, struct snd_soc_dapm_widget_list **list_) 1234 int stream, struct snd_soc_dapm_widget_list **list)
1235{ 1235{
1236 struct snd_soc_dai *cpu_dai = fe->cpu_dai; 1236 struct snd_soc_dai *cpu_dai = fe->cpu_dai;
1237 struct snd_soc_dapm_widget_list *list;
1238 int paths; 1237 int paths;
1239 1238
1240 list = kzalloc(sizeof(struct snd_soc_dapm_widget_list) +
1241 sizeof(struct snd_soc_dapm_widget *), GFP_KERNEL);
1242 if (list == NULL)
1243 return -ENOMEM;
1244
1245 /* get number of valid DAI paths and their widgets */ 1239 /* get number of valid DAI paths and their widgets */
1246 paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, &list); 1240 paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, list);
1247 1241
1248 dev_dbg(fe->dev, "ASoC: found %d audio %s paths\n", paths, 1242 dev_dbg(fe->dev, "ASoC: found %d audio %s paths\n", paths,
1249 stream ? "capture" : "playback"); 1243 stream ? "capture" : "playback");
1250 1244
1251 *list_ = list;
1252 return paths; 1245 return paths;
1253} 1246}
1254 1247
@@ -1306,7 +1299,12 @@ static int dpcm_add_paths(struct snd_soc_pcm_runtime *fe, int stream,
1306 1299
1307 switch (list->widgets[i]->id) { 1300 switch (list->widgets[i]->id) {
1308 case snd_soc_dapm_dai_in: 1301 case snd_soc_dapm_dai_in:
1302 if (stream != SNDRV_PCM_STREAM_PLAYBACK)
1303 continue;
1304 break;
1309 case snd_soc_dapm_dai_out: 1305 case snd_soc_dapm_dai_out:
1306 if (stream != SNDRV_PCM_STREAM_CAPTURE)
1307 continue;
1310 break; 1308 break;
1311 default: 1309 default:
1312 continue; 1310 continue;
diff --git a/sound/soc/soc-topology.c b/sound/soc/soc-topology.c
index d0960683c409..f4e92d35316e 100644
--- a/sound/soc/soc-topology.c
+++ b/sound/soc/soc-topology.c
@@ -33,6 +33,7 @@
33#include <sound/soc.h> 33#include <sound/soc.h>
34#include <sound/soc-dapm.h> 34#include <sound/soc-dapm.h>
35#include <sound/soc-topology.h> 35#include <sound/soc-topology.h>
36#include <sound/tlv.h>
36 37
37/* 38/*
38 * We make several passes over the data (since it wont necessarily be ordered) 39 * We make several passes over the data (since it wont necessarily be ordered)
@@ -144,7 +145,7 @@ static const struct snd_soc_tplg_kcontrol_ops io_ops[] = {
144 {SND_SOC_TPLG_CTL_STROBE, snd_soc_get_strobe, 145 {SND_SOC_TPLG_CTL_STROBE, snd_soc_get_strobe,
145 snd_soc_put_strobe, NULL}, 146 snd_soc_put_strobe, NULL},
146 {SND_SOC_TPLG_DAPM_CTL_VOLSW, snd_soc_dapm_get_volsw, 147 {SND_SOC_TPLG_DAPM_CTL_VOLSW, snd_soc_dapm_get_volsw,
147 snd_soc_dapm_put_volsw, NULL}, 148 snd_soc_dapm_put_volsw, snd_soc_info_volsw},
148 {SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE, snd_soc_dapm_get_enum_double, 149 {SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE, snd_soc_dapm_get_enum_double,
149 snd_soc_dapm_put_enum_double, snd_soc_info_enum_double}, 150 snd_soc_dapm_put_enum_double, snd_soc_info_enum_double},
150 {SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT, snd_soc_dapm_get_enum_double, 151 {SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT, snd_soc_dapm_get_enum_double,
@@ -534,7 +535,7 @@ static int soc_tplg_kcontrol_bind_io(struct snd_soc_tplg_ctl_hdr *hdr,
534 k->put = bops[i].put; 535 k->put = bops[i].put;
535 if (k->get == NULL && bops[i].id == hdr->ops.get) 536 if (k->get == NULL && bops[i].id == hdr->ops.get)
536 k->get = bops[i].get; 537 k->get = bops[i].get;
537 if (k->info == NULL && ops[i].id == hdr->ops.info) 538 if (k->info == NULL && bops[i].id == hdr->ops.info)
538 k->info = bops[i].info; 539 k->info = bops[i].info;
539 } 540 }
540 541
@@ -579,29 +580,51 @@ static int soc_tplg_init_kcontrol(struct soc_tplg *tplg,
579 return 0; 580 return 0;
580} 581}
581 582
583
584static int soc_tplg_create_tlv_db_scale(struct soc_tplg *tplg,
585 struct snd_kcontrol_new *kc, struct snd_soc_tplg_tlv_dbscale *scale)
586{
587 unsigned int item_len = 2 * sizeof(unsigned int);
588 unsigned int *p;
589
590 p = kzalloc(item_len + 2 * sizeof(unsigned int), GFP_KERNEL);
591 if (!p)
592 return -ENOMEM;
593
594 p[0] = SNDRV_CTL_TLVT_DB_SCALE;
595 p[1] = item_len;
596 p[2] = scale->min;
597 p[3] = (scale->step & TLV_DB_SCALE_MASK)
598 | (scale->mute ? TLV_DB_SCALE_MUTE : 0);
599
600 kc->tlv.p = (void *)p;
601 return 0;
602}
603
582static int soc_tplg_create_tlv(struct soc_tplg *tplg, 604static int soc_tplg_create_tlv(struct soc_tplg *tplg,
583 struct snd_kcontrol_new *kc, u32 tlv_size) 605 struct snd_kcontrol_new *kc, struct snd_soc_tplg_ctl_hdr *tc)
584{ 606{
585 struct snd_soc_tplg_ctl_tlv *tplg_tlv; 607 struct snd_soc_tplg_ctl_tlv *tplg_tlv;
586 struct snd_ctl_tlv *tlv;
587 608
588 if (tlv_size == 0) 609 if (!(tc->access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE))
589 return 0; 610 return 0;
590 611
591 tplg_tlv = (struct snd_soc_tplg_ctl_tlv *) tplg->pos; 612 if (tc->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) {
592 tplg->pos += tlv_size; 613 kc->tlv.c = snd_soc_bytes_tlv_callback;
593 614 } else {
594 tlv = kzalloc(sizeof(*tlv) + tlv_size, GFP_KERNEL); 615 tplg_tlv = &tc->tlv;
595 if (tlv == NULL) 616 switch (tplg_tlv->type) {
596 return -ENOMEM; 617 case SNDRV_CTL_TLVT_DB_SCALE:
597 618 return soc_tplg_create_tlv_db_scale(tplg, kc,
598 dev_dbg(tplg->dev, " created TLV type %d size %d bytes\n", 619 &tplg_tlv->scale);
599 tplg_tlv->numid, tplg_tlv->size);
600 620
601 tlv->numid = tplg_tlv->numid; 621 /* TODO: add support for other TLV types */
602 tlv->length = tplg_tlv->size; 622 default:
603 memcpy(tlv->tlv, tplg_tlv + 1, tplg_tlv->size); 623 dev_dbg(tplg->dev, "Unsupported TLV type %d\n",
604 kc->tlv.p = (void *)tlv; 624 tplg_tlv->type);
625 return -EINVAL;
626 }
627 }
605 628
606 return 0; 629 return 0;
607} 630}
@@ -773,7 +796,7 @@ static int soc_tplg_dmixer_create(struct soc_tplg *tplg, unsigned int count,
773 } 796 }
774 797
775 /* create any TLV data */ 798 /* create any TLV data */
776 soc_tplg_create_tlv(tplg, &kc, mc->hdr.tlv_size); 799 soc_tplg_create_tlv(tplg, &kc, &mc->hdr);
777 800
778 /* register control here */ 801 /* register control here */
779 err = soc_tplg_add_kcontrol(tplg, &kc, 802 err = soc_tplg_add_kcontrol(tplg, &kc,
@@ -1351,6 +1374,7 @@ static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg,
1351 template.reg = w->reg; 1374 template.reg = w->reg;
1352 template.shift = w->shift; 1375 template.shift = w->shift;
1353 template.mask = w->mask; 1376 template.mask = w->mask;
1377 template.subseq = w->subseq;
1354 template.on_val = w->invert ? 0 : 1; 1378 template.on_val = w->invert ? 0 : 1;
1355 template.off_val = w->invert ? 1 : 0; 1379 template.off_val = w->invert ? 1 : 0;
1356 template.ignore_suspend = w->ignore_suspend; 1380 template.ignore_suspend = w->ignore_suspend;
@@ -1734,7 +1758,6 @@ void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
1734 u32 index) 1758 u32 index)
1735{ 1759{
1736 struct snd_soc_dapm_widget *w, *next_w; 1760 struct snd_soc_dapm_widget *w, *next_w;
1737 struct snd_soc_dapm_path *p, *next_p;
1738 1761
1739 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) { 1762 list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
1740 1763
@@ -1746,31 +1769,9 @@ void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm,
1746 if (w->dobj.index != index && 1769 if (w->dobj.index != index &&
1747 w->dobj.index != SND_SOC_TPLG_INDEX_ALL) 1770 w->dobj.index != SND_SOC_TPLG_INDEX_ALL)
1748 continue; 1771 continue;
1749
1750 list_del(&w->list);
1751
1752 /*
1753 * remove source and sink paths associated to this widget.
1754 * While removing the path, remove reference to it from both
1755 * source and sink widgets so that path is removed only once.
1756 */
1757 list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
1758 list_del(&p->list_sink);
1759 list_del(&p->list_source);
1760 list_del(&p->list);
1761 kfree(p);
1762 }
1763 list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
1764 list_del(&p->list_sink);
1765 list_del(&p->list_source);
1766 list_del(&p->list);
1767 kfree(p);
1768 }
1769 /* check and free and dynamic widget kcontrols */ 1772 /* check and free and dynamic widget kcontrols */
1770 snd_soc_tplg_widget_remove(w); 1773 snd_soc_tplg_widget_remove(w);
1771 kfree(w->kcontrols); 1774 snd_soc_dapm_free_widget(w);
1772 kfree(w->name);
1773 kfree(w);
1774 } 1775 }
1775} 1776}
1776EXPORT_SYMBOL_GPL(snd_soc_tplg_widget_remove_all); 1777EXPORT_SYMBOL_GPL(snd_soc_tplg_widget_remove_all);
diff --git a/sound/soc/spear/spdif_in.c b/sound/soc/spear/spdif_in.c
index a4028601da01..977a078eb92f 100644
--- a/sound/soc/spear/spdif_in.c
+++ b/sound/soc/spear/spdif_in.c
@@ -203,35 +203,25 @@ static int spdif_in_probe(struct platform_device *pdev)
203 struct spdif_in_dev *host; 203 struct spdif_in_dev *host;
204 struct spear_spdif_platform_data *pdata; 204 struct spear_spdif_platform_data *pdata;
205 struct resource *res, *res_fifo; 205 struct resource *res, *res_fifo;
206 void __iomem *io_base;
206 int ret; 207 int ret;
207 208
208 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 209 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
209 if (!res) 210 io_base = devm_ioremap_resource(&pdev->dev, res);
210 return -EINVAL; 211 if (IS_ERR(io_base))
212 return PTR_ERR(io_base);
211 213
212 res_fifo = platform_get_resource(pdev, IORESOURCE_IO, 0); 214 res_fifo = platform_get_resource(pdev, IORESOURCE_IO, 0);
213 if (!res_fifo) 215 if (!res_fifo)
214 return -EINVAL; 216 return -EINVAL;
215 217
216 if (!devm_request_mem_region(&pdev->dev, res->start,
217 resource_size(res), pdev->name)) {
218 dev_warn(&pdev->dev, "Failed to get memory resourse\n");
219 return -ENOENT;
220 }
221
222 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); 218 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
223 if (!host) { 219 if (!host) {
224 dev_warn(&pdev->dev, "kzalloc fail\n"); 220 dev_warn(&pdev->dev, "kzalloc fail\n");
225 return -ENOMEM; 221 return -ENOMEM;
226 } 222 }
227 223
228 host->io_base = devm_ioremap(&pdev->dev, res->start, 224 host->io_base = io_base;
229 resource_size(res));
230 if (!host->io_base) {
231 dev_warn(&pdev->dev, "ioremap failed\n");
232 return -ENOMEM;
233 }
234
235 host->irq = platform_get_irq(pdev, 0); 225 host->irq = platform_get_irq(pdev, 0);
236 if (host->irq < 0) 226 if (host->irq < 0)
237 return -EINVAL; 227 return -EINVAL;
diff --git a/sound/soc/spear/spear_pcm.c b/sound/soc/spear/spear_pcm.c
index a7dc3c56f44d..e8476da157cd 100644
--- a/sound/soc/spear/spear_pcm.c
+++ b/sound/soc/spear/spear_pcm.c
@@ -44,7 +44,7 @@ int devm_spear_pcm_platform_register(struct device *dev,
44 *config = spear_dmaengine_pcm_config; 44 *config = spear_dmaengine_pcm_config;
45 config->compat_filter_fn = filter; 45 config->compat_filter_fn = filter;
46 46
47 return snd_dmaengine_pcm_register(dev, config, 47 return devm_snd_dmaengine_pcm_register(dev, config,
48 SND_DMAENGINE_PCM_FLAG_NO_DT | 48 SND_DMAENGINE_PCM_FLAG_NO_DT |
49 SND_DMAENGINE_PCM_FLAG_COMPAT); 49 SND_DMAENGINE_PCM_FLAG_COMPAT);
50} 50}
diff --git a/sound/soc/sti/Kconfig b/sound/soc/sti/Kconfig
new file mode 100644
index 000000000000..64a690077023
--- /dev/null
+++ b/sound/soc/sti/Kconfig
@@ -0,0 +1,11 @@
1#
2# STM SoC audio configuration
3#
4menuconfig SND_SOC_STI
5 tristate "SoC Audio support for STI System-On-Chip"
6 depends on SND_SOC
7 depends on ARCH_STI || COMPILE_TEST
8 select SND_SOC_GENERIC_DMAENGINE_PCM
9 help
10 Say Y if you want to enable ASoC-support for
11 any of the STI platforms (e.g. STIH416).
diff --git a/sound/soc/sti/Makefile b/sound/soc/sti/Makefile
new file mode 100644
index 000000000000..4b188d2d76b8
--- /dev/null
+++ b/sound/soc/sti/Makefile
@@ -0,0 +1,4 @@
1# STI platform support
2snd-soc-sti-objs := sti_uniperif.o uniperif_player.o uniperif_reader.o
3
4obj-$(CONFIG_SND_SOC_STI) += snd-soc-sti.o
diff --git a/sound/soc/sti/sti_uniperif.c b/sound/soc/sti/sti_uniperif.c
new file mode 100644
index 000000000000..39bcefe5eea0
--- /dev/null
+++ b/sound/soc/sti/sti_uniperif.c
@@ -0,0 +1,254 @@
1/*
2 * Copyright (C) STMicroelectronics SA 2015
3 * Authors: Arnaud Pouliquen <arnaud.pouliquen@st.com>
4 * for STMicroelectronics.
5 * License terms: GNU General Public License (GPL), version 2
6 */
7
8#include <linux/module.h>
9#include <linux/pinctrl/consumer.h>
10
11#include "uniperif.h"
12
13/*
14 * sti_uniperiph_dai_create_ctrl
15 * This function is used to create Ctrl associated to DAI but also pcm device.
16 * Request is done by front end to associate ctrl with pcm device id
17 */
18static int sti_uniperiph_dai_create_ctrl(struct snd_soc_dai *dai)
19{
20 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
21 struct uniperif *uni = priv->dai_data.uni;
22 struct snd_kcontrol_new *ctrl;
23 int i;
24
25 if (!uni->num_ctrls)
26 return 0;
27
28 for (i = 0; i < uni->num_ctrls; i++) {
29 /*
30 * Several Control can have same name. Controls are indexed on
31 * Uniperipheral instance ID
32 */
33 ctrl = &uni->snd_ctrls[i];
34 ctrl->index = uni->info->id;
35 ctrl->device = uni->info->id;
36 }
37
38 return snd_soc_add_dai_controls(dai, uni->snd_ctrls, uni->num_ctrls);
39}
40
41/*
42 * DAI
43 */
44int sti_uniperiph_dai_hw_params(struct snd_pcm_substream *substream,
45 struct snd_pcm_hw_params *params,
46 struct snd_soc_dai *dai)
47{
48 struct snd_dmaengine_dai_dma_data *dma_data;
49 int transfer_size;
50
51 transfer_size = params_channels(params) * UNIPERIF_FIFO_FRAMES;
52
53 dma_data = snd_soc_dai_get_dma_data(dai, substream);
54 dma_data->maxburst = transfer_size;
55
56 return 0;
57}
58
59int sti_uniperiph_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
60{
61 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
62
63 priv->dai_data.uni->daifmt = fmt;
64
65 return 0;
66}
67
68static int sti_uniperiph_dai_suspend(struct snd_soc_dai *dai)
69{
70 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
71 struct uniperif *uni = priv->dai_data.uni;
72 int ret;
73
74 /* The uniperipheral should be in stopped state */
75 if (uni->state != UNIPERIF_STATE_STOPPED) {
76 dev_err(uni->dev, "%s: invalid uni state( %d)",
77 __func__, (int)uni->state);
78 return -EBUSY;
79 }
80
81 /* Pinctrl: switch pinstate to sleep */
82 ret = pinctrl_pm_select_sleep_state(uni->dev);
83 if (ret)
84 dev_err(uni->dev, "%s: failed to select pinctrl state",
85 __func__);
86
87 return ret;
88}
89
90static int sti_uniperiph_dai_resume(struct snd_soc_dai *dai)
91{
92 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
93 struct uniperif *uni = priv->dai_data.uni;
94 int ret;
95
96 if (of_device_is_compatible(dai->dev->of_node, "st,sti-uni-player")) {
97 ret = uni_player_resume(uni);
98 if (ret)
99 return ret;
100 }
101
102 /* pinctrl: switch pinstate to default */
103 ret = pinctrl_pm_select_default_state(uni->dev);
104 if (ret)
105 dev_err(uni->dev, "%s: failed to select pinctrl state",
106 __func__);
107
108 return ret;
109}
110
111static int sti_uniperiph_dai_probe(struct snd_soc_dai *dai)
112{
113 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
114 struct sti_uniperiph_dai *dai_data = &priv->dai_data;
115
116 /* DMA settings*/
117 if (of_device_is_compatible(dai->dev->of_node, "st,sti-uni-player"))
118 snd_soc_dai_init_dma_data(dai, &dai_data->dma_data, NULL);
119 else
120 snd_soc_dai_init_dma_data(dai, NULL, &dai_data->dma_data);
121
122 dai_data->dma_data.addr = dai_data->uni->fifo_phys_address;
123 dai_data->dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
124
125 return sti_uniperiph_dai_create_ctrl(dai);
126}
127
128static const struct snd_soc_dai_driver sti_uniperiph_dai_template = {
129 .probe = sti_uniperiph_dai_probe,
130 .suspend = sti_uniperiph_dai_suspend,
131 .resume = sti_uniperiph_dai_resume
132};
133
134static const struct snd_soc_component_driver sti_uniperiph_dai_component = {
135 .name = "sti_cpu_dai",
136};
137
138static int sti_uniperiph_cpu_dai_of(struct device_node *node,
139 struct sti_uniperiph_data *priv)
140{
141 const char *str;
142 int ret;
143 struct device *dev = &priv->pdev->dev;
144 struct sti_uniperiph_dai *dai_data = &priv->dai_data;
145 struct snd_soc_dai_driver *dai = priv->dai;
146 struct snd_soc_pcm_stream *stream;
147 struct uniperif *uni;
148
149 uni = devm_kzalloc(dev, sizeof(*uni), GFP_KERNEL);
150 if (!uni)
151 return -ENOMEM;
152
153 *dai = sti_uniperiph_dai_template;
154 ret = of_property_read_string(node, "dai-name", &str);
155 if (ret < 0) {
156 dev_err(dev, "%s: dai name missing.\n", __func__);
157 return -EINVAL;
158 }
159 dai->name = str;
160
161 /* Get resources */
162 uni->mem_region = platform_get_resource(priv->pdev, IORESOURCE_MEM, 0);
163
164 if (!uni->mem_region) {
165 dev_err(dev, "Failed to get memory resource");
166 return -ENODEV;
167 }
168
169 uni->base = devm_ioremap_resource(dev, uni->mem_region);
170
171 if (IS_ERR(uni->base))
172 return PTR_ERR(uni->base);
173
174 uni->fifo_phys_address = uni->mem_region->start +
175 UNIPERIF_FIFO_DATA_OFFSET(uni);
176
177 uni->irq = platform_get_irq(priv->pdev, 0);
178 if (uni->irq < 0) {
179 dev_err(dev, "Failed to get IRQ resource");
180 return -ENXIO;
181 }
182
183 dai_data->uni = uni;
184
185 if (of_device_is_compatible(node, "st,sti-uni-player")) {
186 uni_player_init(priv->pdev, uni);
187 stream = &dai->playback;
188 } else {
189 uni_reader_init(priv->pdev, uni);
190 stream = &dai->capture;
191 }
192 dai->ops = uni->dai_ops;
193
194 stream->stream_name = dai->name;
195 stream->channels_min = uni->hw->channels_min;
196 stream->channels_max = uni->hw->channels_max;
197 stream->rates = uni->hw->rates;
198 stream->formats = uni->hw->formats;
199
200 return 0;
201}
202
203static const struct snd_dmaengine_pcm_config dmaengine_pcm_config = {
204 .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
205};
206
207static int sti_uniperiph_probe(struct platform_device *pdev)
208{
209 struct sti_uniperiph_data *priv;
210 struct device_node *node = pdev->dev.of_node;
211 int ret;
212
213 /* Allocate the private data and the CPU_DAI array */
214 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
215 if (!priv)
216 return -ENOMEM;
217 priv->dai = devm_kzalloc(&pdev->dev, sizeof(*priv->dai), GFP_KERNEL);
218 if (!priv->dai)
219 return -ENOMEM;
220
221 priv->pdev = pdev;
222
223 ret = sti_uniperiph_cpu_dai_of(node, priv);
224
225 dev_set_drvdata(&pdev->dev, priv);
226
227 ret = devm_snd_soc_register_component(&pdev->dev,
228 &sti_uniperiph_dai_component,
229 priv->dai, 1);
230 if (ret < 0)
231 return ret;
232
233 return devm_snd_dmaengine_pcm_register(&pdev->dev,
234 &dmaengine_pcm_config, 0);
235}
236
237static const struct of_device_id snd_soc_sti_match[] = {
238 { .compatible = "st,sti-uni-player", },
239 { .compatible = "st,sti-uni-reader", },
240 {},
241};
242
243static struct platform_driver sti_uniperiph_driver = {
244 .driver = {
245 .name = "sti-uniperiph-dai",
246 .of_match_table = snd_soc_sti_match,
247 },
248 .probe = sti_uniperiph_probe,
249};
250module_platform_driver(sti_uniperiph_driver);
251
252MODULE_DESCRIPTION("uniperipheral DAI driver");
253MODULE_AUTHOR("Arnaud Pouliquen <arnaud.pouliquen@st.com>");
254MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/sti/uniperif.h b/sound/soc/sti/uniperif.h
new file mode 100644
index 000000000000..f0fd5a9944e9
--- /dev/null
+++ b/sound/soc/sti/uniperif.h
@@ -0,0 +1,1229 @@
1/*
2 * Copyright (C) STMicroelectronics SA 2015
3 * Authors: Arnaud Pouliquen <arnaud.pouliquen@st.com>
4 * for STMicroelectronics.
5 * License terms: GNU General Public License (GPL), version 2
6 */
7
8#ifndef __SND_ST_AUD_UNIPERIF_H
9#define __SND_ST_AUD_UNIPERIF_H
10
11#include <linux/regmap.h>
12
13#include <sound/dmaengine_pcm.h>
14
15/*
16 * Register access macros
17 */
18
19#define GET_UNIPERIF_REG(ip, offset, shift, mask) \
20 ((readl_relaxed(ip->base + offset) >> shift) & mask)
21#define SET_UNIPERIF_REG(ip, offset, shift, mask, value) \
22 writel_relaxed(((readl_relaxed(ip->base + offset) & \
23 ~(mask << shift)) | (((value) & mask) << shift)), ip->base + offset)
24#define SET_UNIPERIF_BIT_REG(ip, offset, shift, mask, value) \
25 writel_relaxed((((value) & mask) << shift), ip->base + offset)
26
27/*
28 * AUD_UNIPERIF_SOFT_RST reg
29 */
30
31#define UNIPERIF_SOFT_RST_OFFSET(ip) 0x0000
32#define GET_UNIPERIF_SOFT_RST(ip) \
33 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? \
34 readl_relaxed(ip->base + UNIPERIF_SOFT_RST_OFFSET(ip)) : 0)
35#define SET_UNIPERIF_SOFT_RST(ip, value) \
36 writel_relaxed(value, ip->base + UNIPERIF_SOFT_RST_OFFSET(ip))
37
38/* SOFT_RST */
39#define UNIPERIF_SOFT_RST_SOFT_RST_SHIFT(ip) 0x0
40#define UNIPERIF_SOFT_RST_SOFT_RST_MASK(ip) 0x1
41#define SET_UNIPERIF_SOFT_RST_SOFT_RST(ip) \
42 SET_UNIPERIF_BIT_REG(ip, \
43 UNIPERIF_SOFT_RST_OFFSET(ip), \
44 UNIPERIF_SOFT_RST_SOFT_RST_SHIFT(ip), \
45 UNIPERIF_SOFT_RST_SOFT_RST_MASK(ip), 1)
46#define GET_UNIPERIF_SOFT_RST_SOFT_RST(ip) \
47 GET_UNIPERIF_REG(ip, \
48 UNIPERIF_SOFT_RST_OFFSET(ip), \
49 UNIPERIF_SOFT_RST_SOFT_RST_SHIFT(ip), \
50 UNIPERIF_SOFT_RST_SOFT_RST_MASK(ip))
51
52/*
53 * AUD_UNIPERIF_FIFO_DATA reg
54 */
55
56#define UNIPERIF_FIFO_DATA_OFFSET(ip) 0x0004
57#define SET_UNIPERIF_DATA(ip, value) \
58 writel_relaxed(value, ip->base + UNIPERIF_FIFO_DATA_OFFSET(ip))
59
60/*
61 * AUD_UNIPERIF_CHANNEL_STA_REGN reg
62 */
63
64#define UNIPERIF_CHANNEL_STA_REGN(ip, n) (0x0060 + (4 * n))
65#define GET_UNIPERIF_CHANNEL_STA_REGN(ip) \
66 readl_relaxed(ip->base + UNIPERIF_CHANNEL_STA_REGN(ip, n))
67#define SET_UNIPERIF_CHANNEL_STA_REGN(ip, n, value) \
68 writel_relaxed(value, ip->base + \
69 UNIPERIF_CHANNEL_STA_REGN(ip, n))
70
71#define UNIPERIF_CHANNEL_STA_REG0_OFFSET(ip) 0x0060
72#define GET_UNIPERIF_CHANNEL_STA_REG0(ip) \
73 readl_relaxed(ip->base + UNIPERIF_CHANNEL_STA_REG0_OFFSET(ip))
74#define SET_UNIPERIF_CHANNEL_STA_REG0(ip, value) \
75 writel_relaxed(value, ip->base + UNIPERIF_CHANNEL_STA_REG0_OFFSET(ip))
76
77#define UNIPERIF_CHANNEL_STA_REG1_OFFSET(ip) 0x0064
78#define GET_UNIPERIF_CHANNEL_STA_REG1(ip) \
79 readl_relaxed(ip->base + UNIPERIF_CHANNEL_STA_REG1_OFFSET(ip))
80#define SET_UNIPERIF_CHANNEL_STA_REG1(ip, value) \
81 writel_relaxed(value, ip->base + UNIPERIF_CHANNEL_STA_REG1_OFFSET(ip))
82
83#define UNIPERIF_CHANNEL_STA_REG2_OFFSET(ip) 0x0068
84#define GET_UNIPERIF_CHANNEL_STA_REG2(ip) \
85 readl_relaxed(ip->base + UNIPERIF_CHANNEL_STA_REG2_OFFSET(ip))
86#define SET_UNIPERIF_CHANNEL_STA_REG2(ip, value) \
87 writel_relaxed(value, ip->base + UNIPERIF_CHANNEL_STA_REG2_OFFSET(ip))
88
89#define UNIPERIF_CHANNEL_STA_REG3_OFFSET(ip) 0x006C
90#define GET_UNIPERIF_CHANNEL_STA_REG3(ip) \
91 readl_relaxed(ip->base + UNIPERIF_CHANNEL_STA_REG3_OFFSET(ip))
92#define SET_UNIPERIF_CHANNEL_STA_REG3(ip, value) \
93 writel_relaxed(value, ip->base + UNIPERIF_CHANNEL_STA_REG3_OFFSET(ip))
94
95#define UNIPERIF_CHANNEL_STA_REG4_OFFSET(ip) 0x0070
96#define GET_UNIPERIF_CHANNEL_STA_REG4(ip) \
97 readl_relaxed(ip->base + UNIPERIF_CHANNEL_STA_REG4_OFFSET(ip))
98#define SET_UNIPERIF_CHANNEL_STA_REG4(ip, value) \
99 writel_relaxed(value, ip->base + UNIPERIF_CHANNEL_STA_REG4_OFFSET(ip))
100
101#define UNIPERIF_CHANNEL_STA_REG5_OFFSET(ip) 0x0074
102#define GET_UNIPERIF_CHANNEL_STA_REG5(ip) \
103 readl_relaxed(ip->base + UNIPERIF_CHANNEL_STA_REG5_OFFSET(ip))
104#define SET_UNIPERIF_CHANNEL_STA_REG5(ip, value) \
105 writel_relaxed(value, ip->base + UNIPERIF_CHANNEL_STA_REG5_OFFSET(ip))
106
107/*
108 * AUD_UNIPERIF_ITS reg
109 */
110
111#define UNIPERIF_ITS_OFFSET(ip) 0x000C
112#define GET_UNIPERIF_ITS(ip) \
113 readl_relaxed(ip->base + UNIPERIF_ITS_OFFSET(ip))
114
115/* MEM_BLK_READ */
116#define UNIPERIF_ITS_MEM_BLK_READ_SHIFT(ip) 5
117#define UNIPERIF_ITS_MEM_BLK_READ_MASK(ip) \
118 (BIT(UNIPERIF_ITS_MEM_BLK_READ_SHIFT(ip)))
119
120/* FIFO_ERROR */
121#define UNIPERIF_ITS_FIFO_ERROR_SHIFT(ip) \
122 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 0 : 8)
123#define UNIPERIF_ITS_FIFO_ERROR_MASK(ip) \
124 (BIT(UNIPERIF_ITS_FIFO_ERROR_SHIFT(ip)))
125
126/* DMA_ERROR */
127#define UNIPERIF_ITS_DMA_ERROR_SHIFT(ip) 9
128#define UNIPERIF_ITS_DMA_ERROR_MASK(ip) \
129 (BIT(UNIPERIF_ITS_DMA_ERROR_SHIFT(ip)))
130
131/* UNDERFLOW_REC_DONE */
132#define UNIPERIF_ITS_UNDERFLOW_REC_DONE_SHIFT(ip) \
133 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? -1 : 12)
134#define UNIPERIF_ITS_UNDERFLOW_REC_DONE_MASK(ip) \
135 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? \
136 0 : (BIT(UNIPERIF_ITS_UNDERFLOW_REC_DONE_SHIFT(ip))))
137
138/* UNDERFLOW_REC_FAILED */
139#define UNIPERIF_ITS_UNDERFLOW_REC_FAILED_SHIFT(ip) \
140 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? -1 : 13)
141#define UNIPERIF_ITS_UNDERFLOW_REC_FAILED_MASK(ip) \
142 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? \
143 0 : (BIT(UNIPERIF_ITS_UNDERFLOW_REC_FAILED_SHIFT(ip))))
144
145/*
146 * AUD_UNIPERIF_ITS_BCLR reg
147 */
148
149/* FIFO_ERROR */
150#define UNIPERIF_ITS_BCLR_FIFO_ERROR_SHIFT(ip) \
151 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 0 : 8)
152#define UNIPERIF_ITS_BCLR_FIFO_ERROR_MASK(ip) \
153 (BIT(UNIPERIF_ITS_BCLR_FIFO_ERROR_SHIFT(ip)))
154#define SET_UNIPERIF_ITS_BCLR_FIFO_ERROR(ip) \
155 SET_UNIPERIF_ITS_BCLR(ip, \
156 UNIPERIF_ITS_BCLR_FIFO_ERROR_MASK(ip))
157
158#define UNIPERIF_ITS_BCLR_OFFSET(ip) 0x0010
159#define SET_UNIPERIF_ITS_BCLR(ip, value) \
160 writel_relaxed(value, ip->base + UNIPERIF_ITS_BCLR_OFFSET(ip))
161
162/*
163 * AUD_UNIPERIF_ITM reg
164 */
165
166#define UNIPERIF_ITM_OFFSET(ip) 0x0018
167#define GET_UNIPERIF_ITM(ip) \
168 readl_relaxed(ip->base + UNIPERIF_ITM_OFFSET(ip))
169
170/* FIFO_ERROR */
171#define UNIPERIF_ITM_FIFO_ERROR_SHIFT(ip) \
172 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 0 : 8)
173#define UNIPERIF_ITM_FIFO_ERROR_MASK(ip) \
174 (BIT(UNIPERIF_ITM_FIFO_ERROR_SHIFT(ip)))
175
176/* UNDERFLOW_REC_DONE */
177#define UNIPERIF_ITM_UNDERFLOW_REC_DONE_SHIFT(ip) \
178 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? -1 : 12)
179#define UNIPERIF_ITM_UNDERFLOW_REC_DONE_MASK(ip) \
180 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? \
181 0 : (BIT(UNIPERIF_ITM_UNDERFLOW_REC_DONE_SHIFT(ip))))
182
183/* UNDERFLOW_REC_FAILED */
184#define UNIPERIF_ITM_UNDERFLOW_REC_FAILED_SHIFT(ip) \
185 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? -1 : 13)
186#define UNIPERIF_ITM_UNDERFLOW_REC_FAILED_MASK(ip) \
187 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? \
188 0 : (BIT(UNIPERIF_ITM_UNDERFLOW_REC_FAILED_SHIFT(ip))))
189
190/*
191 * AUD_UNIPERIF_ITM_BCLR reg
192 */
193
194#define UNIPERIF_ITM_BCLR_OFFSET(ip) 0x001c
195#define SET_UNIPERIF_ITM_BCLR(ip, value) \
196 writel_relaxed(value, ip->base + UNIPERIF_ITM_BCLR_OFFSET(ip))
197
198/* FIFO_ERROR */
199#define UNIPERIF_ITM_BCLR_FIFO_ERROR_SHIFT(ip) \
200 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 0 : 8)
201#define UNIPERIF_ITM_BCLR_FIFO_ERROR_MASK(ip) \
202 (BIT(UNIPERIF_ITM_BCLR_FIFO_ERROR_SHIFT(ip)))
203#define SET_UNIPERIF_ITM_BCLR_FIFO_ERROR(ip) \
204 SET_UNIPERIF_ITM_BCLR(ip, \
205 UNIPERIF_ITM_BCLR_FIFO_ERROR_MASK(ip))
206
207/* DMA_ERROR */
208#define UNIPERIF_ITM_BCLR_DMA_ERROR_SHIFT(ip) 9
209#define UNIPERIF_ITM_BCLR_DMA_ERROR_MASK(ip) \
210 (BIT(UNIPERIF_ITM_BCLR_DMA_ERROR_SHIFT(ip)))
211#define SET_UNIPERIF_ITM_BCLR_DMA_ERROR(ip) \
212 SET_UNIPERIF_ITM_BCLR(ip, \
213 UNIPERIF_ITM_BCLR_DMA_ERROR_MASK(ip))
214
215/*
216 * AUD_UNIPERIF_ITM_BSET reg
217 */
218
219#define UNIPERIF_ITM_BSET_OFFSET(ip) 0x0020
220#define SET_UNIPERIF_ITM_BSET(ip, value) \
221 writel_relaxed(value, ip->base + UNIPERIF_ITM_BSET_OFFSET(ip))
222
223/* FIFO_ERROR */
224#define UNIPERIF_ITM_BSET_FIFO_ERROR_SHIFT(ip) \
225 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 0 : 8)
226#define UNIPERIF_ITM_BSET_FIFO_ERROR_MASK(ip) \
227 (BIT(UNIPERIF_ITM_BSET_FIFO_ERROR_SHIFT(ip)))
228#define SET_UNIPERIF_ITM_BSET_FIFO_ERROR(ip) \
229 SET_UNIPERIF_ITM_BSET(ip, \
230 UNIPERIF_ITM_BSET_FIFO_ERROR_MASK(ip))
231
232/* MEM_BLK_READ */
233#define UNIPERIF_ITM_BSET_MEM_BLK_READ_SHIFT(ip) 5
234#define UNIPERIF_ITM_BSET_MEM_BLK_READ_MASK(ip) \
235 (BIT(UNIPERIF_ITM_BSET_MEM_BLK_READ_SHIFT(ip)))
236#define SET_UNIPERIF_ITM_BSET_MEM_BLK_READ(ip) \
237 SET_UNIPERIF_ITM_BSET(ip, \
238 UNIPERIF_ITM_BSET_MEM_BLK_READ_MASK(ip))
239
240/* DMA_ERROR */
241#define UNIPERIF_ITM_BSET_DMA_ERROR_SHIFT(ip) 9
242#define UNIPERIF_ITM_BSET_DMA_ERROR_MASK(ip) \
243 (BIT(UNIPERIF_ITM_BSET_DMA_ERROR_SHIFT(ip)))
244#define SET_UNIPERIF_ITM_BSET_DMA_ERROR(ip) \
245 SET_UNIPERIF_ITM_BSET(ip, \
246 UNIPERIF_ITM_BSET_DMA_ERROR_MASK(ip))
247
248/* UNDERFLOW_REC_DONE */
249#define UNIPERIF_ITM_BSET_UNDERFLOW_REC_DONE_SHIFT(ip) \
250 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? -1 : 12)
251#define UNIPERIF_ITM_BSET_UNDERFLOW_REC_DONE_MASK(ip) \
252 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? \
253 0 : (BIT(UNIPERIF_ITM_BSET_UNDERFLOW_REC_DONE_SHIFT(ip))))
254#define SET_UNIPERIF_ITM_BSET_UNDERFLOW_REC_DONE(ip) \
255 SET_UNIPERIF_ITM_BSET(ip, \
256 UNIPERIF_ITM_BSET_UNDERFLOW_REC_DONE_MASK(ip))
257
258/* UNDERFLOW_REC_FAILED */
259#define UNIPERIF_ITM_BSET_UNDERFLOW_REC_FAILED_SHIFT(ip) \
260 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? -1 : 13)
261#define UNIPERIF_ITM_BSET_UNDERFLOW_REC_FAILED_MASK(ip) \
262 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? \
263 0 : (BIT(UNIPERIF_ITM_BSET_UNDERFLOW_REC_FAILED_SHIFT(ip))))
264#define SET_UNIPERIF_ITM_BSET_UNDERFLOW_REC_FAILED(ip) \
265 SET_UNIPERIF_ITM_BSET(ip, \
266 UNIPERIF_ITM_BSET_UNDERFLOW_REC_FAILED_MASK(ip))
267
268/*
269 * UNIPERIF_CONFIG reg
270 */
271
272#define UNIPERIF_CONFIG_OFFSET(ip) 0x0040
273#define GET_UNIPERIF_CONFIG(ip) \
274 readl_relaxed(ip->base + UNIPERIF_CONFIG_OFFSET(ip))
275#define SET_UNIPERIF_CONFIG(ip, value) \
276 writel_relaxed(value, ip->base + UNIPERIF_CONFIG_OFFSET(ip))
277
278/* PARITY_CNTR */
279#define UNIPERIF_CONFIG_PARITY_CNTR_SHIFT(ip) 0
280#define UNIPERIF_CONFIG_PARITY_CNTR_MASK(ip) 0x1
281#define GET_UNIPERIF_CONFIG_PARITY_CNTR(ip) \
282 GET_UNIPERIF_REG(ip, \
283 UNIPERIF_CONFIG_OFFSET(ip), \
284 UNIPERIF_CONFIG_PARITY_CNTR_SHIFT(ip), \
285 UNIPERIF_CONFIG_PARITY_CNTR_MASK(ip))
286#define SET_UNIPERIF_CONFIG_PARITY_CNTR_BY_HW(ip) \
287 SET_UNIPERIF_REG(ip, \
288 UNIPERIF_CONFIG_OFFSET(ip), \
289 UNIPERIF_CONFIG_PARITY_CNTR_SHIFT(ip), \
290 UNIPERIF_CONFIG_PARITY_CNTR_MASK(ip), 0)
291#define SET_UNIPERIF_CONFIG_PARITY_CNTR_BY_SW(ip) \
292 SET_UNIPERIF_REG(ip, \
293 UNIPERIF_CONFIG_OFFSET(ip), \
294 UNIPERIF_CONFIG_PARITY_CNTR_SHIFT(ip), \
295 UNIPERIF_CONFIG_PARITY_CNTR_MASK(ip), 1)
296
297/* CHANNEL_STA_CNTR */
298#define UNIPERIF_CONFIG_CHANNEL_STA_CNTR_SHIFT(ip) 1
299#define UNIPERIF_CONFIG_CHANNEL_STA_CNTR_MASK(ip) 0x1
300#define GET_UNIPERIF_CONFIG_CHANNEL_STA_CNTR(ip) \
301 GET_UNIPERIF_REG(ip, \
302 UNIPERIF_CONFIG_OFFSET(ip), \
303 UNIPERIF_CONFIG_CHANNEL_STA_CNTR_SHIFT(ip), \
304 UNIPERIF_CONFIG_CHANNEL_STA_CNTR_MASK(ip))
305#define SET_UNIPERIF_CONFIG_CHANNEL_STA_CNTR_BY_SW(ip) \
306 SET_UNIPERIF_REG(ip, \
307 UNIPERIF_CONFIG_OFFSET(ip), \
308 UNIPERIF_CONFIG_CHANNEL_STA_CNTR_SHIFT(ip), \
309 UNIPERIF_CONFIG_CHANNEL_STA_CNTR_MASK(ip), 0)
310#define SET_UNIPERIF_CONFIG_CHANNEL_STA_CNTR_BY_HW(ip) \
311 SET_UNIPERIF_REG(ip, \
312 UNIPERIF_CONFIG_OFFSET(ip), \
313 UNIPERIF_CONFIG_CHANNEL_STA_CNTR_SHIFT(ip), \
314 UNIPERIF_CONFIG_CHANNEL_STA_CNTR_MASK(ip), 1)
315
316/* USER_DAT_CNTR */
317#define UNIPERIF_CONFIG_USER_DAT_CNTR_SHIFT(ip) 2
318#define UNIPERIF_CONFIG_USER_DAT_CNTR_MASK(ip) 0x1
319#define GET_UNIPERIF_CONFIG_USER_DAT_CNTR(ip) \
320 GET_UNIPERIF_REG(ip, \
321 UNIPERIF_CONFIG_OFFSET(ip), \
322 UNIPERIF_CONFIG_USER_DAT_CNTR_SHIFT(ip), \
323 UNIPERIF_CONFIG_USER_DAT_CNTR_MASK(ip))
324#define SET_UNIPERIF_CONFIG_USER_DAT_CNTR_BY_HW(ip) \
325 SET_UNIPERIF_REG(ip, \
326 UNIPERIF_CONFIG_OFFSET(ip), \
327 UNIPERIF_CONFIG_USER_DAT_CNTR_SHIFT(ip), \
328 UNIPERIF_CONFIG_USER_DAT_CNTR_MASK(ip), 1)
329#define SET_UNIPERIF_CONFIG_USER_DAT_CNTR_BY_SW(ip) \
330 SET_UNIPERIF_REG(ip, \
331 UNIPERIF_CONFIG_OFFSET(ip), \
332 UNIPERIF_CONFIG_USER_DAT_CNTR_SHIFT(ip), \
333 UNIPERIF_CONFIG_USER_DAT_CNTR_MASK(ip), 0)
334
335/* VALIDITY_DAT_CNTR */
336#define UNIPERIF_CONFIG_VALIDITY_DAT_CNTR_SHIFT(ip) 3
337#define UNIPERIF_CONFIG_VALIDITY_DAT_CNTR_MASK(ip) 0x1
338#define GET_UNIPERIF_CONFIG_VALIDITY_DAT_CNTR(ip) \
339 GET_UNIPERIF_REG(ip, \
340 UNIPERIF_CONFIG_OFFSET(ip), \
341 UNIPERIF_CONFIG_VALIDITY_DAT_CNTR_SHIFT(ip), \
342 UNIPERIF_CONFIG_VALIDITY_DAT_CNTR_MASK(ip))
343#define SET_UNIPERIF_CONFIG_VALIDITY_DAT_CNTR_BY_SW(ip) \
344 SET_UNIPERIF_REG(ip, \
345 UNIPERIF_CONFIG_OFFSET(ip), \
346 UNIPERIF_CONFIG_VALIDITY_DAT_CNTR_SHIFT(ip), \
347 UNIPERIF_CONFIG_VALIDITY_DAT_CNTR_MASK(ip), 0)
348#define SET_UNIPERIF_CONFIG_VALIDITY_DAT_CNTR_BY_HW(ip) \
349 SET_UNIPERIF_REG(ip, \
350 UNIPERIF_CONFIG_OFFSET(ip), \
351 UNIPERIF_CONFIG_VALIDITY_DAT_CNTR_SHIFT(ip), \
352 UNIPERIF_CONFIG_VALIDITY_DAT_CNTR_MASK(ip), 1)
353
354/* ONE_BIT_AUD_SUPPORT */
355#define UNIPERIF_CONFIG_ONE_BIT_AUD_SHIFT(ip) 4
356#define UNIPERIF_CONFIG_ONE_BIT_AUD_MASK(ip) 0x1
357#define GET_UNIPERIF_CONFIG_ONE_BIT_AUD(ip) \
358 GET_UNIPERIF_REG(ip, \
359 UNIPERIF_CONFIG_OFFSET(ip), \
360 UNIPERIF_CONFIG_ONE_BIT_AUD_SHIFT(ip), \
361 UNIPERIF_CONFIG_ONE_BIT_AUD_MASK(ip))
362#define SET_UNIPERIF_CONFIG_ONE_BIT_AUD_DISABLE(ip) \
363 SET_UNIPERIF_REG(ip, \
364 UNIPERIF_CONFIG_OFFSET(ip), \
365 UNIPERIF_CONFIG_ONE_BIT_AUD_SHIFT(ip), \
366 UNIPERIF_CONFIG_ONE_BIT_AUD_MASK(ip), 0)
367#define SET_UNIPERIF_CONFIG_ONE_BIT_AUD_ENABLE(ip) \
368 SET_UNIPERIF_REG(ip, \
369 UNIPERIF_CONFIG_OFFSET(ip), \
370 UNIPERIF_CONFIG_ONE_BIT_AUD_SHIFT(ip), \
371 UNIPERIF_CONFIG_ONE_BIT_AUD_MASK(ip), 1)
372
373/* MEMORY_FMT */
374#define UNIPERIF_CONFIG_MEM_FMT_SHIFT(ip) 5
375#define UNIPERIF_CONFIG_MEM_FMT_MASK(ip) 0x1
376#define VALUE_UNIPERIF_CONFIG_MEM_FMT_16_0(ip) 0
377#define VALUE_UNIPERIF_CONFIG_MEM_FMT_16_16(ip) 1
378#define GET_UNIPERIF_CONFIG_MEM_FMT(ip) \
379 GET_UNIPERIF_REG(ip, \
380 UNIPERIF_CONFIG_OFFSET(ip), \
381 UNIPERIF_CONFIG_MEM_FMT_SHIFT(ip), \
382 UNIPERIF_CONFIG_MEM_FMT_MASK(ip))
383#define SET_UNIPERIF_CONFIG_MEM_FMT(ip, value) \
384 SET_UNIPERIF_REG(ip, \
385 UNIPERIF_CONFIG_OFFSET(ip), \
386 UNIPERIF_CONFIG_MEM_FMT_SHIFT(ip), \
387 UNIPERIF_CONFIG_MEM_FMT_MASK(ip), value)
388#define SET_UNIPERIF_CONFIG_MEM_FMT_16_0(ip) \
389 SET_UNIPERIF_CONFIG_MEM_FMT(ip, \
390 VALUE_UNIPERIF_CONFIG_MEM_FMT_16_0(ip))
391#define SET_UNIPERIF_CONFIG_MEM_FMT_16_16(ip) \
392 SET_UNIPERIF_CONFIG_MEM_FMT(ip, \
393 VALUE_UNIPERIF_CONFIG_MEM_FMT_16_16(ip))
394
395/* REPEAT_CHL_STS */
396#define UNIPERIF_CONFIG_REPEAT_CHL_STS_SHIFT(ip) 6
397#define UNIPERIF_CONFIG_REPEAT_CHL_STS_MASK(ip) 0x1
398#define GET_UNIPERIF_CONFIG_REPEAT_CHL_STS(ip) \
399 GET_UNIPERIF_REG(ip, \
400 UNIPERIF_CONFIG_OFFSET(ip), \
401 UNIPERIF_CONFIG_REPEAT_CHL_STS_SHIFT(ip), \
402 UNIPERIF_CONFIG_REPEAT_CHL_STS_MASK(ip))
403#define SET_UNIPERIF_CONFIG_REPEAT_CHL_STS_ENABLE(ip) \
404 SET_UNIPERIF_REG(ip, \
405 UNIPERIF_CONFIG_OFFSET(ip), \
406 UNIPERIF_CONFIG_REPEAT_CHL_STS_SHIFT(ip), \
407 UNIPERIF_CONFIG_REPEAT_CHL_STS_MASK(ip), 0)
408#define SET_UNIPERIF_CONFIG_REPEAT_CHL_STS_DISABLE(ip) \
409 SET_UNIPERIF_REG(ip, \
410 UNIPERIF_CONFIG_OFFSET(ip), \
411 UNIPERIF_CONFIG_REPEAT_CHL_STS_SHIFT(ip), \
412 UNIPERIF_CONFIG_REPEAT_CHL_STS_MASK(ip), 1)
413
414/* BACK_STALL_REQ */
415#define UNIPERIF_CONFIG_BACK_STALL_REQ_SHIFT(ip) \
416 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 7 : -1)
417#define UNIPERIF_CONFIG_BACK_STALL_REQ_MASK(ip) 0x1
418#define GET_UNIPERIF_CONFIG_BACK_STALL_REQ(ip) \
419 GET_UNIPERIF_REG(ip, \
420 UNIPERIF_CONFIG_OFFSET(ip), \
421 UNIPERIF_CONFIG_BACK_STALL_REQ_SHIFT(ip), \
422 UNIPERIF_CONFIG_BACK_STALL_REQ_MASK(ip))
423#define SET_UNIPERIF_CONFIG_BACK_STALL_REQ_DISABLE(ip) \
424 SET_UNIPERIF_REG(ip, \
425 UNIPERIF_CONFIG_OFFSET(ip), \
426 UNIPERIF_CONFIG_BACK_STALL_REQ_SHIFT(ip), \
427 UNIPERIF_CONFIG_BACK_STALL_REQ_MASK(ip), 0)
428#define SET_UNIPERIF_CONFIG_BACK_STALL_REQ_ENABLE(ip) \
429 SET_UNIPERIF_REG(ip, \
430 UNIPERIF_CONFIG_OFFSET(ip), \
431 UNIPERIF_CONFIG_BACK_STALL_REQ_SHIFT(ip), \
432 UNIPERIF_CONFIG_BACK_STALL_REQ_MASK(ip), 1)
433
434/* FDMA_TRIGGER_LIMIT */
435#define UNIPERIF_CONFIG_DMA_TRIG_LIMIT_SHIFT(ip) 8
436#define UNIPERIF_CONFIG_DMA_TRIG_LIMIT_MASK(ip) 0x7F
437#define GET_UNIPERIF_CONFIG_DMA_TRIG_LIMIT(ip) \
438 GET_UNIPERIF_REG(ip, \
439 UNIPERIF_CONFIG_OFFSET(ip), \
440 UNIPERIF_CONFIG_DMA_TRIG_LIMIT_SHIFT(ip), \
441 UNIPERIF_CONFIG_DMA_TRIG_LIMIT_MASK(ip))
442#define SET_UNIPERIF_CONFIG_DMA_TRIG_LIMIT(ip, value) \
443 SET_UNIPERIF_REG(ip, \
444 UNIPERIF_CONFIG_OFFSET(ip), \
445 UNIPERIF_CONFIG_DMA_TRIG_LIMIT_SHIFT(ip), \
446 UNIPERIF_CONFIG_DMA_TRIG_LIMIT_MASK(ip), value)
447
448/* CHL_STS_UPDATE */
449#define UNIPERIF_CONFIG_CHL_STS_UPDATE_SHIFT(ip) \
450 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 16 : -1)
451#define UNIPERIF_CONFIG_CHL_STS_UPDATE_MASK(ip) 0x1
452#define GET_UNIPERIF_CONFIG_CHL_STS_UPDATE(ip) \
453 GET_UNIPERIF_REG(ip, \
454 UNIPERIF_CONFIG_OFFSET(ip), \
455 UNIPERIF_CONFIG_CHL_STS_UPDATE_SHIFT(ip), \
456 UNIPERIF_CONFIG_CHL_STS_UPDATE_MASK(ip))
457#define SET_UNIPERIF_CONFIG_CHL_STS_UPDATE(ip) \
458 SET_UNIPERIF_REG(ip, \
459 UNIPERIF_CONFIG_OFFSET(ip), \
460 UNIPERIF_CONFIG_CHL_STS_UPDATE_SHIFT(ip), \
461 UNIPERIF_CONFIG_CHL_STS_UPDATE_MASK(ip), 1)
462
463/* IDLE_MOD */
464#define UNIPERIF_CONFIG_IDLE_MOD_SHIFT(ip) 18
465#define UNIPERIF_CONFIG_IDLE_MOD_MASK(ip) 0x1
466#define GET_UNIPERIF_CONFIG_IDLE_MOD(ip) \
467 GET_UNIPERIF_REG(ip, \
468 UNIPERIF_CONFIG_OFFSET(ip), \
469 UNIPERIF_CONFIG_IDLE_MOD_SHIFT(ip), \
470 UNIPERIF_CONFIG_IDLE_MOD_MASK(ip))
471#define SET_UNIPERIF_CONFIG_IDLE_MOD_DISABLE(ip) \
472 SET_UNIPERIF_REG(ip, \
473 UNIPERIF_CONFIG_OFFSET(ip), \
474 UNIPERIF_CONFIG_IDLE_MOD_SHIFT(ip), \
475 UNIPERIF_CONFIG_IDLE_MOD_MASK(ip), 0)
476#define SET_UNIPERIF_CONFIG_IDLE_MOD_ENABLE(ip) \
477 SET_UNIPERIF_REG(ip, \
478 UNIPERIF_CONFIG_OFFSET(ip), \
479 UNIPERIF_CONFIG_IDLE_MOD_SHIFT(ip), \
480 UNIPERIF_CONFIG_IDLE_MOD_MASK(ip), 1)
481
482/* SUBFRAME_SELECTION */
483#define UNIPERIF_CONFIG_SUBFRAME_SEL_SHIFT(ip) 19
484#define UNIPERIF_CONFIG_SUBFRAME_SEL_MASK(ip) 0x1
485#define GET_UNIPERIF_CONFIG_SUBFRAME_SEL(ip) \
486 GET_UNIPERIF_REG(ip, \
487 UNIPERIF_CONFIG_OFFSET(ip), \
488 UNIPERIF_CONFIG_SUBFRAME_SEL_SHIFT(ip), \
489 UNIPERIF_CONFIG_SUBFRAME_SEL_MASK(ip))
490#define SET_UNIPERIF_CONFIG_SUBFRAME_SEL_SUBF1_SUBF0(ip) \
491 SET_UNIPERIF_REG(ip, \
492 UNIPERIF_CONFIG_OFFSET(ip), \
493 UNIPERIF_CONFIG_SUBFRAME_SEL_SHIFT(ip), \
494 UNIPERIF_CONFIG_SUBFRAME_SEL_MASK(ip), 1)
495#define SET_UNIPERIF_CONFIG_SUBFRAME_SEL_SUBF0_SUBF1(ip) \
496 SET_UNIPERIF_REG(ip, \
497 UNIPERIF_CONFIG_OFFSET(ip), \
498 UNIPERIF_CONFIG_SUBFRAME_SEL_SHIFT(ip), \
499 UNIPERIF_CONFIG_SUBFRAME_SEL_MASK(ip), 0)
500
501/* FULL_SW_CONTROL */
502#define UNIPERIF_CONFIG_SPDIF_SW_CTRL_SHIFT(ip) 20
503#define UNIPERIF_CONFIG_SPDIF_SW_CTRL_MASK(ip) 0x1
504#define GET_UNIPERIF_CONFIG_SPDIF_SW_CTRL(ip) \
505 GET_UNIPERIF_REG(ip, \
506 UNIPERIF_CONFIG_OFFSET(ip), \
507 UNIPERIF_CONFIG_SPDIF_SW_CTRL_SHIFT(ip), \
508 UNIPERIF_CONFIG_SPDIF_SW_CTRL_MASK(ip))
509#define SET_UNIPERIF_CONFIG_SPDIF_SW_CTRL_ENABLE(ip) \
510 SET_UNIPERIF_REG(ip, \
511 UNIPERIF_CONFIG_OFFSET(ip), \
512 UNIPERIF_CONFIG_SPDIF_SW_CTRL_SHIFT(ip), \
513 UNIPERIF_CONFIG_SPDIF_SW_CTRL_MASK(ip), 1)
514#define SET_UNIPERIF_CONFIG_SPDIF_SW_CTRL_DISABLE(ip) \
515 SET_UNIPERIF_REG(ip, \
516 UNIPERIF_CONFIG_OFFSET(ip), \
517 UNIPERIF_CONFIG_SPDIF_SW_CTRL_SHIFT(ip), \
518 UNIPERIF_CONFIG_SPDIF_SW_CTRL_MASK(ip), 0)
519
520/* MASTER_CLKEDGE */
521#define UNIPERIF_CONFIG_MSTR_CLKEDGE_SHIFT(ip) \
522 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 24 : -1)
523#define UNIPERIF_CONFIG_MSTR_CLKEDGE_MASK(ip) 0x1
524#define GET_UNIPERIF_CONFIG_MSTR_CLKEDGE(ip) \
525 GET_UNIPERIF_REG(ip, \
526 UNIPERIF_CONFIG_OFFSET(ip), \
527 UNIPERIF_CONFIG_MSTR_CLKEDGE_SHIFT(ip), \
528 UNIPERIF_CONFIG_MSTR_CLKEDGE_MASK(ip))
529#define SET_UNIPERIF_CONFIG_MSTR_CLKEDGE_FALLING(ip) \
530 SET_UNIPERIF_REG(ip, \
531 UNIPERIF_CONFIG_OFFSET(ip), \
532 UNIPERIF_CONFIG_MSTR_CLKEDGE_SHIFT(ip), \
533 UNIPERIF_CONFIG_MSTR_CLKEDGE_MASK(ip), 1)
534#define SET_UNIPERIF_CONFIG_MSTR_CLKEDGE_RISING(ip) \
535 SET_UNIPERIF_REG(ip, \
536 UNIPERIF_CONFIG_OFFSET(ip), \
537 UNIPERIF_CONFIG_MSTR_CLKEDGE_SHIFT(ip), \
538 UNIPERIF_CONFIG_MSTR_CLKEDGE_MASK(ip), 0)
539
540/*
541 * UNIPERIF_CTRL reg
542 */
543
544#define UNIPERIF_CTRL_OFFSET(ip) 0x0044
545#define GET_UNIPERIF_CTRL(ip) \
546 readl_relaxed(ip->base + UNIPERIF_CTRL_OFFSET(ip))
547#define SET_UNIPERIF_CTRL(ip, value) \
548 writel_relaxed(value, ip->base + UNIPERIF_CTRL_OFFSET(ip))
549
550/* OPERATION */
551#define UNIPERIF_CTRL_OPERATION_SHIFT(ip) 0
552#define UNIPERIF_CTRL_OPERATION_MASK(ip) 0x7
553#define GET_UNIPERIF_CTRL_OPERATION(ip) \
554 GET_UNIPERIF_REG(ip, \
555 UNIPERIF_CTRL_OFFSET(ip), \
556 UNIPERIF_CTRL_OPERATION_SHIFT(ip), \
557 UNIPERIF_CTRL_OPERATION_MASK(ip))
558#define VALUE_UNIPERIF_CTRL_OPERATION_OFF(ip) 0
559#define SET_UNIPERIF_CTRL_OPERATION_OFF(ip) \
560 SET_UNIPERIF_REG(ip, \
561 UNIPERIF_CTRL_OFFSET(ip), \
562 UNIPERIF_CTRL_OPERATION_SHIFT(ip), \
563 UNIPERIF_CTRL_OPERATION_MASK(ip), \
564 VALUE_UNIPERIF_CTRL_OPERATION_OFF(ip))
565#define VALUE_UNIPERIF_CTRL_OPERATION_MUTE_PCM_NULL(ip) \
566 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 1 : -1)
567#define SET_UNIPERIF_CTRL_OPERATION_MUTE_PCM_NULL(ip) \
568 SET_UNIPERIF_REG(ip, \
569 UNIPERIF_CTRL_OFFSET(ip), \
570 UNIPERIF_CTRL_OPERATION_SHIFT(ip), \
571 UNIPERIF_CTRL_OPERATION_MASK(ip), \
572 VALUE_UNIPERIF_CTRL_OPERATION_MUTE_PCM_NULL(ip))
573#define VALUE_UNIPERIF_CTRL_OPERATION_MUTE_PAUSE_BURST(ip) \
574 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 2 : -1)
575#define SET_UNIPERIF_CTRL_OPERATION_MUTE_PAUSE_BURST(ip) \
576 SET_UNIPERIF_REG(ip, \
577 UNIPERIF_CTRL_OFFSET(ip), \
578 UNIPERIF_CTRL_OPERATION_SHIFT(ip), \
579 UNIPERIF_CTRL_OPERATION_MASK(ip), \
580 VALUE_UNIPERIF_CTRL_OPERATION_MUTE_PAUSE_BURST(ip))
581#define VALUE_UNIPERIF_CTRL_OPERATION_PCM_DATA(ip) 3
582#define SET_UNIPERIF_CTRL_OPERATION_PCM_DATA(ip) \
583 SET_UNIPERIF_REG(ip, \
584 UNIPERIF_CTRL_OFFSET(ip), \
585 UNIPERIF_CTRL_OPERATION_SHIFT(ip), \
586 UNIPERIF_CTRL_OPERATION_MASK(ip), \
587 VALUE_UNIPERIF_CTRL_OPERATION_PCM_DATA(ip))
588/* This is the same as above! */
589#define VALUE_UNIPERIF_CTRL_OPERATION_AUDIO_DATA(ip) 3
590#define SET_UNIPERIF_CTRL_OPERATION_AUDIO_DATA(ip) \
591 SET_UNIPERIF_REG(ip, \
592 UNIPERIF_CTRL_OFFSET(ip), \
593 UNIPERIF_CTRL_OPERATION_SHIFT(ip), \
594 UNIPERIF_CTRL_OPERATION_MASK(ip), \
595 VALUE_UNIPERIF_CTRL_OPERATION_AUDIO_DATA(ip))
596#define VALUE_UNIPERIF_CTRL_OPERATION_ENC_DATA(ip) 4
597#define SET_UNIPERIF_CTRL_OPERATION_ENC_DATA(ip) \
598 SET_UNIPERIF_REG(ip, \
599 UNIPERIF_CTRL_OFFSET(ip), \
600 UNIPERIF_CTRL_OPERATION_SHIFT(ip), \
601 UNIPERIF_CTRL_OPERATION_MASK(ip), \
602 VALUE_UNIPERIF_CTRL_OPERATION_ENC_DATA(ip))
603#define VALUE_UNIPERIF_CTRL_OPERATION_CD_DATA(ip) \
604 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 5 : -1)
605#define SET_UNIPERIF_CTRL_OPERATION_CD_DATA(ip) \
606 SET_UNIPERIF_REG(ip, \
607 UNIPERIF_CTRL_OFFSET(ip), \
608 UNIPERIF_CTRL_OPERATION_SHIFT(ip), \
609 UNIPERIF_CTRL_OPERATION_MASK(ip), \
610 VALUE_UNIPERIF_CTRL_OPERATION_CD_DATA(ip))
611#define VALUE_UNIPERIF_CTRL_OPERATION_STANDBY(ip) \
612 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? -1 : 7)
613#define SET_UNIPERIF_CTRL_OPERATION_STANDBY(ip) \
614 SET_UNIPERIF_REG(ip, \
615 UNIPERIF_CTRL_OFFSET(ip), \
616 UNIPERIF_CTRL_OPERATION_SHIFT(ip), \
617 UNIPERIF_CTRL_OPERATION_MASK(ip), \
618 VALUE_UNIPERIF_CTRL_OPERATION_STANDBY(ip))
619
620/* EXIT_STBY_ON_EOBLOCK */
621#define UNIPERIF_CTRL_EXIT_STBY_ON_EOBLOCK_SHIFT(ip) \
622 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? -1 : 3)
623#define UNIPERIF_CTRL_EXIT_STBY_ON_EOBLOCK_MASK(ip) 0x1
624#define GET_UNIPERIF_CTRL_EXIT_STBY_ON_EOBLOCK(ip) \
625 GET_UNIPERIF_REG(ip, \
626 UNIPERIF_CTRL_OFFSET(ip), \
627 UNIPERIF_CTRL_EXIT_STBY_ON_EOBLOCK_SHIFT(ip), \
628 UNIPERIF_CTRL_EXIT_STBY_ON_EOBLOCK_MASK(ip))
629#define SET_UNIPERIF_CTRL_EXIT_STBY_ON_EOBLOCK_OFF(ip) \
630 SET_UNIPERIF_REG(ip, \
631 UNIPERIF_CTRL_OFFSET(ip), \
632 UNIPERIF_CTRL_EXIT_STBY_ON_EOBLOCK_SHIFT(ip), \
633 UNIPERIF_CTRL_EXIT_STBY_ON_EOBLOCK_MASK(ip), 0)
634#define SET_UNIPERIF_CTRL_EXIT_STBY_ON_EOBLOCK_ON(ip) \
635 SET_UNIPERIF_REG(ip, \
636 UNIPERIF_CTRL_OFFSET(ip), \
637 UNIPERIF_CTRL_EXIT_STBY_ON_EOBLOCK_SHIFT(ip), \
638 UNIPERIF_CTRL_EXIT_STBY_ON_EOBLOCK_MASK(ip), 1)
639
640/* ROUNDING */
641#define UNIPERIF_CTRL_ROUNDING_SHIFT(ip) 4
642#define UNIPERIF_CTRL_ROUNDING_MASK(ip) 0x1
643#define GET_UNIPERIF_CTRL_ROUNDING(ip) \
644 GET_UNIPERIF_REG(ip, \
645 UNIPERIF_CTRL_OFFSET(ip), \
646 UNIPERIF_CTRL_ROUNDING_SHIFT(ip), \
647 UNIPERIF_CTRL_ROUNDING_MASK(ip))
648#define SET_UNIPERIF_CTRL_ROUNDING_OFF(ip) \
649 SET_UNIPERIF_REG(ip, \
650 UNIPERIF_CTRL_OFFSET(ip), \
651 UNIPERIF_CTRL_ROUNDING_SHIFT(ip), \
652 UNIPERIF_CTRL_ROUNDING_MASK(ip), 0)
653#define SET_UNIPERIF_CTRL_ROUNDING_ON(ip) \
654 SET_UNIPERIF_REG(ip, \
655 UNIPERIF_CTRL_OFFSET(ip), \
656 UNIPERIF_CTRL_ROUNDING_SHIFT(ip), \
657 UNIPERIF_CTRL_ROUNDING_MASK(ip), 1)
658
659/* DIVIDER */
660#define UNIPERIF_CTRL_DIVIDER_SHIFT(ip) 5
661#define UNIPERIF_CTRL_DIVIDER_MASK(ip) 0xff
662#define GET_UNIPERIF_CTRL_DIVIDER(ip) \
663 GET_UNIPERIF_REG(ip, \
664 UNIPERIF_CTRL_OFFSET(ip), \
665 UNIPERIF_CTRL_DIVIDER_SHIFT(ip), \
666 UNIPERIF_CTRL_DIVIDER_MASK(ip))
667#define SET_UNIPERIF_CTRL_DIVIDER(ip, value) \
668 SET_UNIPERIF_REG(ip, \
669 UNIPERIF_CTRL_OFFSET(ip), \
670 UNIPERIF_CTRL_DIVIDER_SHIFT(ip), \
671 UNIPERIF_CTRL_DIVIDER_MASK(ip), value)
672
673/* BYTE_SWAP */
674#define UNIPERIF_CTRL_BYTE_SWP_SHIFT(ip) \
675 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 13 : -1)
676#define UNIPERIF_CTRL_BYTE_SWP_MASK(ip) 0x1
677#define GET_UNIPERIF_CTRL_BYTE_SWP(ip) \
678 GET_UNIPERIF_REG(ip, \
679 UNIPERIF_CTRL_OFFSET(ip), \
680 UNIPERIF_CTRL_BYTE_SWP_SHIFT(ip), \
681 UNIPERIF_CTRL_BYTE_SWP_MASK(ip))
682#define SET_UNIPERIF_CTRL_BYTE_SWP_OFF(ip) \
683 SET_UNIPERIF_REG(ip, \
684 UNIPERIF_CTRL_OFFSET(ip), \
685 UNIPERIF_CTRL_BYTE_SWP_SHIFT(ip), \
686 UNIPERIF_CTRL_BYTE_SWP_MASK(ip), 0)
687#define SET_UNIPERIF_CTRL_BYTE_SWP_ON(ip) \
688 SET_UNIPERIF_REG(ip, \
689 UNIPERIF_CTRL_OFFSET(ip), \
690 UNIPERIF_CTRL_BYTE_SWP_SHIFT(ip), \
691 UNIPERIF_CTRL_BYTE_SWP_MASK(ip), 1)
692
693/* ZERO_STUFFING_HW_SW */
694#define UNIPERIF_CTRL_ZERO_STUFF_SHIFT(ip) \
695 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 14 : -1)
696#define UNIPERIF_CTRL_ZERO_STUFF_MASK(ip) 0x1
697#define GET_UNIPERIF_CTRL_ZERO_STUFF(ip) \
698 GET_UNIPERIF_REG(ip, \
699 UNIPERIF_CTRL_OFFSET(ip), \
700 UNIPERIF_CTRL_ZERO_STUFF_SHIFT(ip), \
701 UNIPERIF_CTRL_ZERO_STUFF_MASK(ip))
702#define SET_UNIPERIF_CTRL_ZERO_STUFF_HW(ip) \
703 SET_UNIPERIF_REG(ip, \
704 UNIPERIF_CTRL_OFFSET(ip), \
705 UNIPERIF_CTRL_ZERO_STUFF_SHIFT(ip), \
706 UNIPERIF_CTRL_ZERO_STUFF_MASK(ip), 1)
707#define SET_UNIPERIF_CTRL_ZERO_STUFF_SW(ip) \
708 SET_UNIPERIF_REG(ip, \
709 UNIPERIF_CTRL_OFFSET(ip), \
710 UNIPERIF_CTRL_ZERO_STUFF_SHIFT(ip), \
711 UNIPERIF_CTRL_ZERO_STUFF_MASK(ip), 0)
712
713/* SPDIF_LAT */
714#define UNIPERIF_CTRL_SPDIF_LAT_SHIFT(ip) \
715 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 16 : -1)
716#define UNIPERIF_CTRL_SPDIF_LAT_MASK(ip) 0x1
717#define GET_UNIPERIF_CTRL_SPDIF_LAT(ip) \
718 GET_UNIPERIF_REG(ip, \
719 UNIPERIF_CTRL_OFFSET(ip), \
720 UNIPERIF_CTRL_SPDIF_LAT_SHIFT(ip), \
721 UNIPERIF_CTRL_SPDIF_LAT_MASK(ip))
722#define SET_UNIPERIF_CTRL_SPDIF_LAT_ON(ip) \
723 SET_UNIPERIF_REG(ip, \
724 UNIPERIF_CTRL_OFFSET(ip), \
725 UNIPERIF_CTRL_SPDIF_LAT_SHIFT(ip), \
726 UNIPERIF_CTRL_SPDIF_LAT_MASK(ip), 1)
727#define SET_UNIPERIF_CTRL_SPDIF_LAT_OFF(ip) \
728 SET_UNIPERIF_REG(ip, \
729 UNIPERIF_CTRL_OFFSET(ip), \
730 UNIPERIF_CTRL_SPDIF_LAT_SHIFT(ip), \
731 UNIPERIF_CTRL_SPDIF_LAT_MASK(ip), 0)
732
733/* EN_SPDIF_FORMATTING */
734#define UNIPERIF_CTRL_SPDIF_FMT_SHIFT(ip) 17
735#define UNIPERIF_CTRL_SPDIF_FMT_MASK(ip) 0x1
736#define GET_UNIPERIF_CTRL_SPDIF_FMT(ip) \
737 GET_UNIPERIF_REG(ip, \
738 UNIPERIF_CTRL_OFFSET(ip), \
739 UNIPERIF_CTRL_SPDIF_FMT_SHIFT(ip), \
740 UNIPERIF_CTRL_SPDIF_FMT_MASK(ip))
741#define SET_UNIPERIF_CTRL_SPDIF_FMT_ON(ip) \
742 SET_UNIPERIF_REG(ip, \
743 UNIPERIF_CTRL_OFFSET(ip), \
744 UNIPERIF_CTRL_SPDIF_FMT_SHIFT(ip), \
745 UNIPERIF_CTRL_SPDIF_FMT_MASK(ip), 1)
746#define SET_UNIPERIF_CTRL_SPDIF_FMT_OFF(ip) \
747 SET_UNIPERIF_REG(ip, \
748 UNIPERIF_CTRL_OFFSET(ip), \
749 UNIPERIF_CTRL_SPDIF_FMT_SHIFT(ip), \
750 UNIPERIF_CTRL_SPDIF_FMT_MASK(ip), 0)
751
752/* READER_OUT_SELECT */
753#define UNIPERIF_CTRL_READER_OUT_SEL_SHIFT(ip) \
754 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 18 : -1)
755#define UNIPERIF_CTRL_READER_OUT_SEL_MASK(ip) 0x1
756#define GET_UNIPERIF_CTRL_READER_OUT_SEL(ip) \
757 GET_UNIPERIF_REG(ip, \
758 UNIPERIF_CTRL_OFFSET(ip), \
759 UNIPERIF_CTRL_READER_OUT_SEL_SHIFT(ip), \
760 UNIPERIF_CTRL_READER_OUT_SEL_MASK(ip))
761#define SET_UNIPERIF_CTRL_READER_OUT_SEL_IN_MEM(ip) \
762 SET_UNIPERIF_REG(ip, \
763 UNIPERIF_CTRL_OFFSET(ip), \
764 UNIPERIF_CTRL_READER_OUT_SEL_SHIFT(ip), \
765 UNIPERIF_CTRL_READER_OUT_SEL_MASK(ip), 0)
766#define SET_UNIPERIF_CTRL_READER_OUT_SEL_ON_I2S_LINE(ip) \
767 SET_UNIPERIF_REG(ip, \
768 UNIPERIF_CTRL_OFFSET(ip), \
769 UNIPERIF_CTRL_READER_OUT_SEL_SHIFT(ip), \
770 CORAUD_UNIPERIF_CTRL_READER_OUT_SEL_MASK(ip), 1)
771
772/* UNDERFLOW_REC_WINDOW */
773#define UNIPERIF_CTRL_UNDERFLOW_REC_WINDOW_SHIFT(ip) 20
774#define UNIPERIF_CTRL_UNDERFLOW_REC_WINDOW_MASK(ip) 0xff
775#define GET_UNIPERIF_CTRL_UNDERFLOW_REC_WINDOW(ip) \
776 GET_UNIPERIF_REG(ip, \
777 UNIPERIF_CTRL_OFFSET(ip), \
778 UNIPERIF_CTRL_UNDERFLOW_REC_WINDOW_SHIFT(ip), \
779 UNIPERIF_CTRL_UNDERFLOW_REC_WINDOW_MASK(ip))
780#define SET_UNIPERIF_CTRL_UNDERFLOW_REC_WINDOW(ip, value) \
781 SET_UNIPERIF_REG(ip, \
782 UNIPERIF_CTRL_OFFSET(ip), \
783 UNIPERIF_CTRL_UNDERFLOW_REC_WINDOW_SHIFT(ip), \
784 UNIPERIF_CTRL_UNDERFLOW_REC_WINDOW_MASK(ip), value)
785
786/*
787 * UNIPERIF_I2S_FMT a.k.a UNIPERIF_FORMAT reg
788 */
789
790#define UNIPERIF_I2S_FMT_OFFSET(ip) 0x0048
791#define GET_UNIPERIF_I2S_FMT(ip) \
792 readl_relaxed(ip->base + UNIPERIF_I2S_FMT_OFFSET(ip))
793#define SET_UNIPERIF_I2S_FMT(ip, value) \
794 writel_relaxed(value, ip->base + UNIPERIF_I2S_FMT_OFFSET(ip))
795
796/* NBIT */
797#define UNIPERIF_I2S_FMT_NBIT_SHIFT(ip) 0
798#define UNIPERIF_I2S_FMT_NBIT_MASK(ip) 0x1
799#define GET_UNIPERIF_I2S_FMT_NBIT(ip) \
800 GET_UNIPERIF_REG(ip, \
801 UNIPERIF_I2S_FMT_OFFSET(ip), \
802 UNIPERIF_I2S_FMT_NBIT_SHIFT(ip), \
803 UNIPERIF_I2S_FMT_NBIT_MASK(ip))
804#define SET_UNIPERIF_I2S_FMT_NBIT_32(ip) \
805 SET_UNIPERIF_REG(ip, \
806 UNIPERIF_I2S_FMT_OFFSET(ip), \
807 UNIPERIF_I2S_FMT_NBIT_SHIFT(ip), \
808 UNIPERIF_I2S_FMT_NBIT_MASK(ip), 0)
809#define SET_UNIPERIF_I2S_FMT_NBIT_16(ip) \
810 SET_UNIPERIF_REG(ip, \
811 UNIPERIF_I2S_FMT_OFFSET(ip), \
812 UNIPERIF_I2S_FMT_NBIT_SHIFT(ip), \
813 UNIPERIF_I2S_FMT_NBIT_MASK(ip), 1)
814
815/* DATA_SIZE */
816#define UNIPERIF_I2S_FMT_DATA_SIZE_SHIFT(ip) 1
817#define UNIPERIF_I2S_FMT_DATA_SIZE_MASK(ip) 0x7
818#define GET_UNIPERIF_I2S_FMT_DATA_SIZE(ip) \
819 GET_UNIPERIF_REG(ip, \
820 UNIPERIF_I2S_FMT_OFFSET(ip), \
821 UNIPERIF_I2S_FMT_DATA_SIZE_SHIFT(ip), \
822 UNIPERIF_I2S_FMT_DATA_SIZE_MASK(ip))
823#define SET_UNIPERIF_I2S_FMT_DATA_SIZE_16(ip) \
824 SET_UNIPERIF_REG(ip, \
825 UNIPERIF_I2S_FMT_OFFSET(ip), \
826 UNIPERIF_I2S_FMT_DATA_SIZE_SHIFT(ip), \
827 UNIPERIF_I2S_FMT_DATA_SIZE_MASK(ip), 0)
828#define SET_UNIPERIF_I2S_FMT_DATA_SIZE_18(ip) \
829 SET_UNIPERIF_REG(ip, \
830 UNIPERIF_I2S_FMT_OFFSET(ip), \
831 UNIPERIF_I2S_FMT_DATA_SIZE_SHIFT(ip), \
832 UNIPERIF_I2S_FMT_DATA_SIZE_MASK(ip), 1)
833#define SET_UNIPERIF_I2S_FMT_DATA_SIZE_20(ip) \
834 SET_UNIPERIF_REG(ip, \
835 UNIPERIF_I2S_FMT_OFFSET(ip), \
836 UNIPERIF_I2S_FMT_DATA_SIZE_SHIFT(ip), \
837 UNIPERIF_I2S_FMT_DATA_SIZE_MASK(ip), 2)
838#define SET_UNIPERIF_I2S_FMT_DATA_SIZE_24(ip) \
839 SET_UNIPERIF_REG(ip, \
840 UNIPERIF_I2S_FMT_OFFSET(ip), \
841 UNIPERIF_I2S_FMT_DATA_SIZE_SHIFT(ip), \
842 UNIPERIF_I2S_FMT_DATA_SIZE_MASK(ip), 3)
843#define SET_UNIPERIF_I2S_FMTL_DATA_SIZE_28(ip) \
844 SET_UNIPERIF_REG(ip, \
845 UNIPERIF_I2S_FMT_OFFSET(ip), \
846 UNIPERIF_I2S_FMT_DATA_SIZE_SHIFT(ip), \
847 UNIPERIF_I2S_FMT_DATA_SIZE_MASK(ip), 4)
848#define SET_UNIPERIF_I2S_FMT_DATA_SIZE_32(ip) \
849 SET_UNIPERIF_REG(ip, \
850 UNIPERIF_I2S_FMT_OFFSET(ip), \
851 UNIPERIF_I2S_FMT_DATA_SIZE_SHIFT(ip), \
852 UNIPERIF_I2S_FMT_DATA_SIZE_MASK(ip), 5)
853
854/* LR_POL */
855#define UNIPERIF_I2S_FMT_LR_POL_SHIFT(ip) 4
856#define UNIPERIF_I2S_FMT_LR_POL_MASK(ip) 0x1
857#define VALUE_UNIPERIF_I2S_FMT_LR_POL_LOW(ip) 0x0
858#define VALUE_UNIPERIF_I2S_FMT_LR_POL_HIG(ip) 0x1
859#define GET_UNIPERIF_I2S_FMT_LR_POL(ip) \
860 GET_UNIPERIF_REG(ip, \
861 UNIPERIF_I2S_FMT_OFFSET(ip), \
862 UNIPERIF_I2S_FMT_LR_POL_SHIFT(ip), \
863 UNIPERIF_I2S_FMT_LR_POL_MASK(ip))
864#define SET_UNIPERIF_I2S_FMT_LR_POL(ip, value) \
865 SET_UNIPERIF_REG(ip, \
866 UNIPERIF_I2S_FMT_OFFSET(ip), \
867 UNIPERIF_I2S_FMT_LR_POL_SHIFT(ip), \
868 UNIPERIF_I2S_FMT_LR_POL_MASK(ip), value)
869#define SET_UNIPERIF_I2S_FMT_LR_POL_LOW(ip) \
870 SET_UNIPERIF_I2S_FMT_LR_POL(ip, \
871 VALUE_UNIPERIF_I2S_FMT_LR_POL_LOW(ip))
872#define SET_UNIPERIF_I2S_FMT_LR_POL_HIG(ip) \
873 SET_UNIPERIF_I2S_FMT_LR_POL(ip, \
874 VALUE_UNIPERIF_I2S_FMT_LR_POL_HIG(ip))
875
876/* SCLK_EDGE */
877#define UNIPERIF_I2S_FMT_SCLK_EDGE_SHIFT(ip) 5
878#define UNIPERIF_I2S_FMT_SCLK_EDGE_MASK(ip) 0x1
879#define GET_UNIPERIF_I2S_FMT_SCLK_EDGE(ip) \
880 GET_UNIPERIF_REG(ip, \
881 UNIPERIF_I2S_FMT_OFFSET(ip), \
882 UNIPERIF_I2S_FMT_SCLK_EDGE_SHIFT(ip), \
883 UNIPERIF_I2S_FMT_SCLK_EDGE_MASK(ip))
884#define SET_UNIPERIF_I2S_FMT_SCLK_EDGE_RISING(ip) \
885 SET_UNIPERIF_REG(ip, \
886 UNIPERIF_I2S_FMT_OFFSET(ip), \
887 UNIPERIF_I2S_FMT_SCLK_EDGE_SHIFT(ip), \
888 UNIPERIF_I2S_FMT_SCLK_EDGE_MASK(ip), 0)
889#define SET_UNIPERIF_I2S_FMT_SCLK_EDGE_FALLING(ip) \
890 SET_UNIPERIF_REG(ip, \
891 UNIPERIF_I2S_FMT_OFFSET(ip), \
892 UNIPERIF_I2S_FMT_SCLK_EDGE_SHIFT(ip), \
893 UNIPERIF_I2S_FMT_SCLK_EDGE_MASK(ip), 1)
894
895/* PADDING */
896#define UNIPERIF_I2S_FMT_PADDING_SHIFT(ip) 6
897#define UNIPERIF_I2S_FMT_PADDING_MASK(ip) 0x1
898#define UNIPERIF_I2S_FMT_PADDING_MASK(ip) 0x1
899#define VALUE_UNIPERIF_I2S_FMT_PADDING_I2S_MODE(ip) 0x0
900#define VALUE_UNIPERIF_I2S_FMT_PADDING_SONY_MODE(ip) 0x1
901#define GET_UNIPERIF_I2S_FMT_PADDING(ip) \
902 GET_UNIPERIF_REG(ip, \
903 UNIPERIF_I2S_FMT_OFFSET(ip), \
904 UNIPERIF_I2S_FMT_PADDING_SHIFT(ip), \
905 UNIPERIF_I2S_FMT_PADDING_MASK(ip))
906#define SET_UNIPERIF_I2S_FMT_PADDING(ip, value) \
907 SET_UNIPERIF_REG(ip, \
908 UNIPERIF_I2S_FMT_OFFSET(ip), \
909 UNIPERIF_I2S_FMT_PADDING_SHIFT(ip), \
910 UNIPERIF_I2S_FMT_PADDING_MASK(ip), value)
911#define SET_UNIPERIF_I2S_FMT_PADDING_I2S_MODE(ip) \
912 SET_UNIPERIF_I2S_FMT_PADDING(ip, \
913 VALUE_UNIPERIF_I2S_FMT_PADDING_I2S_MODE(ip))
914#define SET_UNIPERIF_I2S_FMT_PADDING_SONY_MODE(ip) \
915 SET_UNIPERIF_I2S_FMT_PADDING(ip, \
916 VALUE_UNIPERIF_I2S_FMT_PADDING_SONY_MODE(ip))
917
918/* ALIGN */
919#define UNIPERIF_I2S_FMT_ALIGN_SHIFT(ip) 7
920#define UNIPERIF_I2S_FMT_ALIGN_MASK(ip) 0x1
921#define GET_UNIPERIF_I2S_FMT_ALIGN(ip) \
922 GET_UNIPERIF_REG(ip, \
923 UNIPERIF_I2S_FMT_OFFSET(ip), \
924 UNIPERIF_I2S_FMT_ALIGN_SHIFT(ip), \
925 UNIPERIF_I2S_FMT_ALIGN_MASK(ip))
926#define SET_UNIPERIF_I2S_FMT_ALIGN_LEFT(ip) \
927 SET_UNIPERIF_REG(ip, \
928 UNIPERIF_I2S_FMT_OFFSET(ip), \
929 UNIPERIF_I2S_FMT_ALIGN_SHIFT(ip), \
930 UNIPERIF_I2S_FMT_ALIGN_MASK(ip), 0)
931#define SET_UNIPERIF_I2S_FMT_ALIGN_RIGHT(ip) \
932 SET_UNIPERIF_REG(ip, \
933 UNIPERIF_I2S_FMT_OFFSET(ip), \
934 UNIPERIF_I2S_FMT_ALIGN_SHIFT(ip), \
935 UNIPERIF_I2S_FMT_ALIGN_MASK(ip), 1)
936
937/* ORDER */
938#define UNIPERIF_I2S_FMT_ORDER_SHIFT(ip) 8
939#define UNIPERIF_I2S_FMT_ORDER_MASK(ip) 0x1
940#define GET_UNIPERIF_I2S_FMT_ORDER(ip) \
941 GET_UNIPERIF_REG(ip, \
942 UNIPERIF_I2S_FMT_OFFSET(ip), \
943 UNIPERIF_I2S_FMT_ORDER_SHIFT(ip), \
944 UNIPERIF_I2S_FMT_ORDER_MASK(ip))
945#define SET_UNIPERIF_I2S_FMT_ORDER_LSB(ip) \
946 SET_UNIPERIF_REG(ip, \
947 UNIPERIF_I2S_FMT_OFFSET(ip), \
948 UNIPERIF_I2S_FMT_ORDER_SHIFT(ip), \
949 UNIPERIF_I2S_FMT_ORDER_MASK(ip), 0)
950#define SET_UNIPERIF_I2S_FMT_ORDER_MSB(ip) \
951 SET_UNIPERIF_REG(ip, \
952 UNIPERIF_I2S_FMT_OFFSET(ip), \
953 UNIPERIF_I2S_FMT_ORDER_SHIFT(ip), \
954 UNIPERIF_I2S_FMT_ORDER_MASK(ip), 1)
955
956/* NUM_CH */
957#define UNIPERIF_I2S_FMT_NUM_CH_SHIFT(ip) 9
958#define UNIPERIF_I2S_FMT_NUM_CH_MASK(ip) 0x7
959#define GET_UNIPERIF_I2S_FMT_NUM_CH(ip) \
960 GET_UNIPERIF_REG(ip, \
961 UNIPERIF_I2S_FMT_OFFSET(ip), \
962 UNIPERIF_I2S_FMT_NUM_CH_SHIFT(ip), \
963 UNIPERIF_I2S_FMT_NUM_CH_MASK(ip))
964#define SET_UNIPERIF_I2S_FMT_NUM_CH(ip, value) \
965 SET_UNIPERIF_REG(ip, \
966 UNIPERIF_I2S_FMT_OFFSET(ip), \
967 UNIPERIF_I2S_FMT_NUM_CH_SHIFT(ip), \
968 UNIPERIF_I2S_FMT_NUM_CH_MASK(ip), value)
969
970/* NO_OF_SAMPLES_TO_READ */
971#define UNIPERIF_I2S_FMT_NO_OF_SAMPLES_TO_READ_SHIFT(ip) 12
972#define UNIPERIF_I2S_FMT_NO_OF_SAMPLES_TO_READ_MASK(ip) 0xfffff
973#define GET_UNIPERIF_I2S_FMT_NO_OF_SAMPLES_TO_READ(ip) \
974 GET_UNIPERIF_REG(ip, \
975 UNIPERIF_I2S_FMT_OFFSET(ip), \
976 UNIPERIF_I2S_FMT_NO_OF_SAMPLES_TO_READ_SHIFT(ip), \
977 UNIPERIF_I2S_FMT_NO_OF_SAMPLES_TO_READ_MASK(ip))
978#define SET_UNIPERIF_I2S_FMT_NO_OF_SAMPLES_TO_READ(ip, value) \
979 SET_UNIPERIF_REG(ip, \
980 UNIPERIF_I2S_FMT_OFFSET(ip), \
981 UNIPERIF_I2S_FMT_NO_OF_SAMPLES_TO_READ_SHIFT(ip), \
982 UNIPERIF_I2S_FMT_NO_OF_SAMPLES_TO_READ_MASK(ip), value)
983
984/*
985 * UNIPERIF_BIT_CONTROL reg
986 */
987
988#define UNIPERIF_BIT_CONTROL_OFFSET(ip) \
989 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? -1 : 0x004c)
990#define GET_UNIPERIF_BIT_CONTROL(ip) \
991 readl_relaxed(ip->base + UNIPERIF_BIT_CONTROL_OFFSET(ip))
992#define SET_UNIPERIF_BIT_CONTROL(ip, value) \
993 writel_relaxed(value, ip->base + UNIPERIF_BIT_CONTROL_OFFSET(ip))
994
995/* CLR_UNDERFLOW_DURATION */
996#define UNIPERIF_BIT_CONTROL_CLR_UNDERFLOW_DURATION_SHIFT(ip) 0
997#define UNIPERIF_BIT_CONTROL_CLR_UNDERFLOW_DURATION_MASK(ip) 0x1
998#define GET_UNIPERIF_BIT_CONTROL_CLR_UNDERFLOW_DURATION(ip) \
999 GET_UNIPERIF_REG(ip, \
1000 UNIPERIF_BIT_CONTROL_OFFSET(ip), \
1001 UNIPERIF_BIT_CONTROL_CLR_UNDERFLOW_DURATION_SHIFT(ip), \
1002 UNIPERIF_BIT_CONTROL_CLR_UNDERFLOW_DURATION_MASK(ip))
1003#define SET_UNIPERIF_BIT_CONTROL_CLR_UNDERFLOW_DURATION(ip) \
1004 SET_UNIPERIF_REG(ip, \
1005 UNIPERIF_BIT_CONTROL_OFFSET(ip), \
1006 UNIPERIF_BIT_CONTROL_CLR_UNDERFLOW_DURATION_SHIFT(ip), \
1007 UNIPERIF_BIT_CONTROL_CLR_UNDERFLOW_DURATION_MASK(ip), 1)
1008
1009/* CHL_STS_UPDATE */
1010#define UNIPERIF_BIT_CONTROL_CHL_STS_UPDATE_SHIFT(ip) 1
1011#define UNIPERIF_BIT_CONTROL_CHL_STS_UPDATE_MASK(ip) 0x1
1012#define GET_UNIPERIF_BIT_CONTROL_CHL_STS_UPDATE(ip) \
1013 GET_UNIPERIF_REG(ip, \
1014 UNIPERIF_BIT_CONTROL_OFFSET(ip), \
1015 UNIPERIF_BIT_CONTROL_CHL_STS_UPDATE_SHIFT(ip), \
1016 UNIPERIF_BIT_CONTROL_CHL_STS_UPDATE_MASK(ip))
1017#define SET_UNIPERIF_BIT_CONTROL_CHL_STS_UPDATE(ip) \
1018 SET_UNIPERIF_BIT_REG(ip, \
1019 UNIPERIF_BIT_CONTROL_OFFSET(ip), \
1020 UNIPERIF_BIT_CONTROL_CHL_STS_UPDATE_SHIFT(ip), \
1021 UNIPERIF_BIT_CONTROL_CHL_STS_UPDATE_MASK(ip), 1)
1022
1023/*
1024 * UNIPERIF_STATUS_1 reg
1025 */
1026
1027#define UNIPERIF_STATUS_1_OFFSET(ip) 0x0050
1028#define GET_UNIPERIF_STATUS_1(ip) \
1029 readl_relaxed(ip->base + UNIPERIF_STATUS_1_OFFSET(ip))
1030#define SET_UNIPERIF_STATUS_1(ip, value) \
1031 writel_relaxed(value, ip->base + UNIPERIF_STATUS_1_OFFSET(ip))
1032
1033/* UNDERFLOW_DURATION */
1034#define UNIPERIF_STATUS_1_UNDERFLOW_DURATION_SHIFT(ip) \
1035 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? -1 : 0)
1036#define UNIPERIF_STATUS_1_UNDERFLOW_DURATION_MASK(ip) 0xff
1037#define GET_UNIPERIF_STATUS_1_UNDERFLOW_DURATION(ip) \
1038 GET_UNIPERIF_REG(ip, \
1039 UNIPERIF_STATUS_1_OFFSET(ip), \
1040 UNIPERIF_STATUS_1_UNDERFLOW_DURATION_SHIFT(ip), \
1041 UNIPERIF_STATUS_1_UNDERFLOW_DURATION_MASK(ip))
1042#define SET_UNIPERIF_STATUS_1_UNDERFLOW_DURATION(ip, value) \
1043 SET_UNIPERIF_REG(ip, \
1044 UNIPERIF_STATUS_1_OFFSET(ip), \
1045 UNIPERIF_STATUS_1_UNDERFLOW_DURATION_SHIFT(ip), \
1046 UNIPERIF_STATUS_1_UNDERFLOW_DURATION_MASK(ip), value)
1047
1048/*
1049 * AUD_UNIPERIF_CHANNEL_STA_REGN reg
1050 */
1051
1052#define UNIPERIF_CHANNEL_STA_REGN(ip, n) (0x0060 + (4 * n))
1053#define GET_UNIPERIF_CHANNEL_STA_REGN(ip) \
1054 readl_relaxed(ip->base + UNIPERIF_CHANNEL_STA_REGN(ip, n))
1055#define SET_UNIPERIF_CHANNEL_STA_REGN(ip, n, value) \
1056 writel_relaxed(value, ip->base + \
1057 UNIPERIF_CHANNEL_STA_REGN(ip, n))
1058
1059/*
1060 * AUD_UNIPERIF_USER_VALIDITY reg
1061 */
1062
1063#define UNIPERIF_USER_VALIDITY_OFFSET(ip) 0x0090
1064#define GET_UNIPERIF_USER_VALIDITY(ip) \
1065 readl_relaxed(ip->base + UNIPERIF_USER_VALIDITY_OFFSET(ip))
1066#define SET_UNIPERIF_USER_VALIDITY(ip, value) \
1067 writel_relaxed(value, ip->base + UNIPERIF_USER_VALIDITY_OFFSET(ip))
1068
1069/* VALIDITY_LEFT_AND_RIGHT */
1070#define UNIPERIF_USER_VALIDITY_VALIDITY_LR_SHIFT(ip) 0
1071#define UNIPERIF_USER_VALIDITY_VALIDITY_LR_MASK(ip) 0x3
1072#define GET_UNIPERIF_USER_VALIDITY_VALIDITY_LR(ip) \
1073 GET_UNIPERIF_REG(ip, \
1074 UNIPERIF_USER_VALIDITY_OFFSET(ip), \
1075 UNIPERIF_USER_VALIDITY_VALIDITY_LR_SHIFT(ip), \
1076 UNIPERIF_USER_VALIDITY_VALIDITY_LR_MASK(ip))
1077#define SET_UNIPERIF_USER_VALIDITY_VALIDITY_LR(ip, value) \
1078 SET_UNIPERIF_REG(ip, \
1079 UNIPERIF_USER_VALIDITY_OFFSET(ip), \
1080 UNIPERIF_USER_VALIDITY_VALIDITY_LR_SHIFT(ip), \
1081 UNIPERIF_USER_VALIDITY_VALIDITY_LR_MASK(ip), \
1082 value ? 0x3 : 0)
1083
1084/*
1085 * UNIPERIF_DBG_STANDBY_LEFT_SP reg
1086 */
1087#define UNIPERIF_DBG_STANDBY_LEFT_SP_OFFSET(ip) 0x0150
1088#define UNIPERIF_DBG_STANDBY_LEFT_SP_SHIFT(ip) \
1089 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? -1 : 0)
1090#define UNIPERIF_DBG_STANDBY_LEFT_SP_MASK(ip) \
1091 ((ip)->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0 ? 0 : 0xFFFFFF)
1092#define GET_UNIPERIF_DBG_STANDBY_LEFT_SP(ip) \
1093 GET_UNIPERIF_REG(ip, \
1094 UNIPERIF_DBG_STANDBY_LEFT_SP_OFFSET(ip), \
1095 UNIPERIF_DBG_STANDBY_LEFT_SP_SHIFT(ip), \
1096 UNIPERIF_DBG_STANDBY_LEFT_SP_MASK(ip))
1097#define SET_UNIPERIF_DBG_STANDBY_LEFT_SP(ip, value) \
1098 SET_UNIPERIF_REG(ip, \
1099 UNIPERIF_DBG_STANDBY_LEFT_SP_OFFSET(ip), \
1100 UNIPERIF_DBG_STANDBY_LEFT_SP_SHIFT(ip), \
1101 UNIPERIF_DBG_STANDBY_LEFT_SP_MASK(ip), value)
1102
1103/*
1104 * uniperipheral IP capabilities
1105 */
1106
1107#define UNIPERIF_FIFO_SIZE 70 /* FIFO is 70 cells deep */
1108#define UNIPERIF_FIFO_FRAMES 4 /* FDMA trigger limit in frames */
1109
1110/*
1111 * Uniperipheral IP revisions
1112 */
1113enum uniperif_version {
1114 SND_ST_UNIPERIF_VERSION_UNKNOWN,
1115 /* SASG1 (Orly), Newman */
1116 SND_ST_UNIPERIF_VERSION_C6AUD0_UNI_1_0,
1117 /* SASC1, SASG2 (Orly2) */
1118 SND_ST_UNIPERIF_VERSION_UNI_PLR_1_0,
1119 /* SASC1, SASG2 (Orly2), TELSS, Cannes */
1120 SND_ST_UNIPERIF_VERSION_UNI_RDR_1_0,
1121 /* TELSS (SASC1) */
1122 SND_ST_UNIPERIF_VERSION_TDM_PLR_1_0,
1123 /* Cannes/Monaco */
1124 SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0
1125};
1126
1127enum uniperif_type {
1128 SND_ST_UNIPERIF_PLAYER_TYPE_NONE,
1129 SND_ST_UNIPERIF_PLAYER_TYPE_HDMI,
1130 SND_ST_UNIPERIF_PLAYER_TYPE_PCM,
1131 SND_ST_UNIPERIF_PLAYER_TYPE_SPDIF
1132};
1133
1134enum uniperif_state {
1135 UNIPERIF_STATE_STOPPED,
1136 UNIPERIF_STATE_STARTED,
1137 UNIPERIF_STATE_STANDBY,
1138 UNIPERIF_STATE_UNDERFLOW,
1139 UNIPERIF_STATE_OVERFLOW = UNIPERIF_STATE_UNDERFLOW,
1140 UNIPERIF_STATE_XRUN
1141};
1142
1143enum uniperif_iec958_encoding_mode {
1144 UNIPERIF_IEC958_ENCODING_MODE_PCM,
1145 UNIPERIF_IEC958_ENCODING_MODE_ENCODED
1146};
1147
1148struct uniperif_info {
1149 int id; /* instance value of the uniperipheral IP */
1150 enum uniperif_type player_type;
1151 int underflow_enabled; /* Underflow recovery mode */
1152};
1153
1154struct uniperif_iec958_settings {
1155 enum uniperif_iec958_encoding_mode encoding_mode;
1156 struct snd_aes_iec958 iec958;
1157};
1158
1159struct uniperif {
1160 /* System information */
1161 struct uniperif_info *info;
1162 struct device *dev;
1163 int ver; /* IP version, used by register access macros */
1164 struct regmap_field *clk_sel;
1165
1166 /* capabilities */
1167 const struct snd_pcm_hardware *hw;
1168
1169 /* Resources */
1170 struct resource *mem_region;
1171 void __iomem *base;
1172 unsigned long fifo_phys_address;
1173 int irq;
1174
1175 /* Clocks */
1176 struct clk *clk;
1177 int mclk;
1178 int clk_adj;
1179
1180 /* Runtime data */
1181 enum uniperif_state state;
1182
1183 struct snd_pcm_substream *substream;
1184
1185 /* Specific to IEC958 player */
1186 struct uniperif_iec958_settings stream_settings;
1187 struct mutex ctrl_lock; /* For resource updated by stream and controls*/
1188
1189 /*alsa ctrl*/
1190 struct snd_kcontrol_new *snd_ctrls;
1191 int num_ctrls;
1192
1193 /* dai properties */
1194 unsigned int daifmt;
1195
1196 /* DAI callbacks */
1197 const struct snd_soc_dai_ops *dai_ops;
1198};
1199
1200struct sti_uniperiph_dai {
1201 int stream;
1202 struct uniperif *uni;
1203 struct snd_dmaengine_dai_dma_data dma_data;
1204};
1205
1206struct sti_uniperiph_data {
1207 struct platform_device *pdev;
1208 struct snd_soc_dai_driver *dai;
1209 struct sti_uniperiph_dai dai_data;
1210};
1211
1212/* uniperiph player*/
1213int uni_player_init(struct platform_device *pdev,
1214 struct uniperif *uni_player);
1215int uni_player_resume(struct uniperif *player);
1216
1217/* uniperiph reader */
1218int uni_reader_init(struct platform_device *pdev,
1219 struct uniperif *uni_reader);
1220
1221/* common */
1222int sti_uniperiph_dai_set_fmt(struct snd_soc_dai *dai,
1223 unsigned int fmt);
1224
1225int sti_uniperiph_dai_hw_params(struct snd_pcm_substream *substream,
1226 struct snd_pcm_hw_params *params,
1227 struct snd_soc_dai *dai);
1228
1229#endif
diff --git a/sound/soc/sti/uniperif_player.c b/sound/soc/sti/uniperif_player.c
new file mode 100644
index 000000000000..f6eefe1b8f8f
--- /dev/null
+++ b/sound/soc/sti/uniperif_player.c
@@ -0,0 +1,1110 @@
1/*
2 * Copyright (C) STMicroelectronics SA 2015
3 * Authors: Arnaud Pouliquen <arnaud.pouliquen@st.com>
4 * for STMicroelectronics.
5 * License terms: GNU General Public License (GPL), version 2
6 */
7
8#include <linux/clk.h>
9#include <linux/delay.h>
10#include <linux/io.h>
11#include <linux/mfd/syscon.h>
12
13#include <sound/asoundef.h>
14#include <sound/soc.h>
15
16#include "uniperif.h"
17
18/*
19 * Some hardware-related definitions
20 */
21
22/* sys config registers definitions */
23#define SYS_CFG_AUDIO_GLUE 0xA4
24#define SYS_CFG_AUDI0_GLUE_PCM_CLKX 8
25
26/*
27 * Driver specific types.
28 */
29#define UNIPERIF_PLAYER_TYPE_IS_HDMI(p) \
30 ((p)->info->player_type == SND_ST_UNIPERIF_PLAYER_TYPE_HDMI)
31#define UNIPERIF_PLAYER_TYPE_IS_PCM(p) \
32 ((p)->info->player_type == SND_ST_UNIPERIF_PLAYER_TYPE_PCM)
33#define UNIPERIF_PLAYER_TYPE_IS_SPDIF(p) \
34 ((p)->info->player_type == SND_ST_UNIPERIF_PLAYER_TYPE_SPDIF)
35#define UNIPERIF_PLAYER_TYPE_IS_IEC958(p) \
36 (UNIPERIF_PLAYER_TYPE_IS_HDMI(p) || \
37 UNIPERIF_PLAYER_TYPE_IS_SPDIF(p))
38
39#define UNIPERIF_PLAYER_CLK_ADJ_MIN -999999
40#define UNIPERIF_PLAYER_CLK_ADJ_MAX 1000000
41
42/*
43 * Note: snd_pcm_hardware is linked to DMA controller but is declared here to
44 * integrate DAI_CPU capability in term of rate and supported channels
45 */
46static const struct snd_pcm_hardware uni_player_pcm_hw = {
47 .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
48 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP |
49 SNDRV_PCM_INFO_MMAP_VALID,
50 .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE,
51
52 .rates = SNDRV_PCM_RATE_CONTINUOUS,
53 .rate_min = 8000,
54 .rate_max = 192000,
55
56 .channels_min = 2,
57 .channels_max = 8,
58
59 .periods_min = 2,
60 .periods_max = 48,
61
62 .period_bytes_min = 128,
63 .period_bytes_max = 64 * PAGE_SIZE,
64 .buffer_bytes_max = 256 * PAGE_SIZE
65};
66
67static inline int reset_player(struct uniperif *player)
68{
69 int count = 10;
70
71 if (player->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0) {
72 while (GET_UNIPERIF_SOFT_RST_SOFT_RST(player) && count) {
73 udelay(5);
74 count--;
75 }
76 }
77
78 if (!count) {
79 dev_err(player->dev, "Failed to reset uniperif");
80 return -EIO;
81 }
82
83 return 0;
84}
85
86/*
87 * uni_player_irq_handler
88 * In case of error audio stream is stopped; stop action is protected via PCM
89 * stream lock to avoid race condition with trigger callback.
90 */
91static irqreturn_t uni_player_irq_handler(int irq, void *dev_id)
92{
93 irqreturn_t ret = IRQ_NONE;
94 struct uniperif *player = dev_id;
95 unsigned int status;
96 unsigned int tmp;
97
98 if (player->state == UNIPERIF_STATE_STOPPED) {
99 /* Unexpected IRQ: do nothing */
100 return IRQ_NONE;
101 }
102
103 /* Get interrupt status & clear them immediately */
104 status = GET_UNIPERIF_ITS(player);
105 SET_UNIPERIF_ITS_BCLR(player, status);
106
107 /* Check for fifo error (underrun) */
108 if (unlikely(status & UNIPERIF_ITS_FIFO_ERROR_MASK(player))) {
109 dev_err(player->dev, "FIFO underflow error detected");
110
111 /* Interrupt is just for information when underflow recovery */
112 if (player->info->underflow_enabled) {
113 /* Update state to underflow */
114 player->state = UNIPERIF_STATE_UNDERFLOW;
115
116 } else {
117 /* Disable interrupt so doesn't continually fire */
118 SET_UNIPERIF_ITM_BCLR_FIFO_ERROR(player);
119
120 /* Stop the player */
121 snd_pcm_stream_lock(player->substream);
122 snd_pcm_stop(player->substream, SNDRV_PCM_STATE_XRUN);
123 snd_pcm_stream_unlock(player->substream);
124 }
125
126 ret = IRQ_HANDLED;
127 }
128
129 /* Check for dma error (overrun) */
130 if (unlikely(status & UNIPERIF_ITS_DMA_ERROR_MASK(player))) {
131 dev_err(player->dev, "DMA error detected");
132
133 /* Disable interrupt so doesn't continually fire */
134 SET_UNIPERIF_ITM_BCLR_DMA_ERROR(player);
135
136 /* Stop the player */
137 snd_pcm_stream_lock(player->substream);
138 snd_pcm_stop(player->substream, SNDRV_PCM_STATE_XRUN);
139 snd_pcm_stream_unlock(player->substream);
140
141 ret = IRQ_HANDLED;
142 }
143
144 /* Check for underflow recovery done */
145 if (unlikely(status & UNIPERIF_ITM_UNDERFLOW_REC_DONE_MASK(player))) {
146 if (!player->info->underflow_enabled) {
147 dev_err(player->dev, "unexpected Underflow recovering");
148 return -EPERM;
149 }
150 /* Read the underflow recovery duration */
151 tmp = GET_UNIPERIF_STATUS_1_UNDERFLOW_DURATION(player);
152
153 /* Clear the underflow recovery duration */
154 SET_UNIPERIF_BIT_CONTROL_CLR_UNDERFLOW_DURATION(player);
155
156 /* Update state to started */
157 player->state = UNIPERIF_STATE_STARTED;
158
159 ret = IRQ_HANDLED;
160 }
161
162 /* Check if underflow recovery failed */
163 if (unlikely(status &
164 UNIPERIF_ITM_UNDERFLOW_REC_FAILED_MASK(player))) {
165 dev_err(player->dev, "Underflow recovery failed");
166
167 /* Stop the player */
168 snd_pcm_stream_lock(player->substream);
169 snd_pcm_stop(player->substream, SNDRV_PCM_STATE_XRUN);
170 snd_pcm_stream_unlock(player->substream);
171
172 ret = IRQ_HANDLED;
173 }
174
175 return ret;
176}
177
178static int uni_player_clk_set_rate(struct uniperif *player, unsigned long rate)
179{
180 int rate_adjusted, rate_achieved, delta, ret;
181 int adjustment = player->clk_adj;
182
183 /*
184 * a
185 * F = f + --------- * f = f + d
186 * 1000000
187 *
188 * a
189 * d = --------- * f
190 * 1000000
191 *
192 * where:
193 * f - nominal rate
194 * a - adjustment in ppm (parts per milion)
195 * F - rate to be set in synthesizer
196 * d - delta (difference) between f and F
197 */
198 if (adjustment < 0) {
199 /* div64_64 operates on unsigned values... */
200 delta = -1;
201 adjustment = -adjustment;
202 } else {
203 delta = 1;
204 }
205 /* 500000 ppm is 0.5, which is used to round up values */
206 delta *= (int)div64_u64((uint64_t)rate *
207 (uint64_t)adjustment + 500000, 1000000);
208 rate_adjusted = rate + delta;
209
210 /* Adjusted rate should never be == 0 */
211 if (!rate_adjusted)
212 return -EINVAL;
213
214 ret = clk_set_rate(player->clk, rate_adjusted);
215 if (ret < 0)
216 return ret;
217
218 rate_achieved = clk_get_rate(player->clk);
219 if (!rate_achieved)
220 /* If value is 0 means that clock or parent not valid */
221 return -EINVAL;
222
223 /*
224 * Using ALSA's adjustment control, we can modify the rate to be up
225 * to twice as much as requested, but no more
226 */
227 delta = rate_achieved - rate;
228 if (delta < 0) {
229 /* div64_64 operates on unsigned values... */
230 delta = -delta;
231 adjustment = -1;
232 } else {
233 adjustment = 1;
234 }
235 /* Frequency/2 is added to round up result */
236 adjustment *= (int)div64_u64((uint64_t)delta * 1000000 + rate / 2,
237 rate);
238 player->clk_adj = adjustment;
239 return 0;
240}
241
242static void uni_player_set_channel_status(struct uniperif *player,
243 struct snd_pcm_runtime *runtime)
244{
245 int n;
246 unsigned int status;
247
248 /*
249 * Some AVRs and TVs require the channel status to contain a correct
250 * sampling frequency. If no sample rate is already specified, then
251 * set one.
252 */
253 mutex_lock(&player->ctrl_lock);
254 if (runtime && (player->stream_settings.iec958.status[3]
255 == IEC958_AES3_CON_FS_NOTID)) {
256 switch (runtime->rate) {
257 case 22050:
258 player->stream_settings.iec958.status[3] =
259 IEC958_AES3_CON_FS_22050;
260 break;
261 case 44100:
262 player->stream_settings.iec958.status[3] =
263 IEC958_AES3_CON_FS_44100;
264 break;
265 case 88200:
266 player->stream_settings.iec958.status[3] =
267 IEC958_AES3_CON_FS_88200;
268 break;
269 case 176400:
270 player->stream_settings.iec958.status[3] =
271 IEC958_AES3_CON_FS_176400;
272 break;
273 case 24000:
274 player->stream_settings.iec958.status[3] =
275 IEC958_AES3_CON_FS_24000;
276 break;
277 case 48000:
278 player->stream_settings.iec958.status[3] =
279 IEC958_AES3_CON_FS_48000;
280 break;
281 case 96000:
282 player->stream_settings.iec958.status[3] =
283 IEC958_AES3_CON_FS_96000;
284 break;
285 case 192000:
286 player->stream_settings.iec958.status[3] =
287 IEC958_AES3_CON_FS_192000;
288 break;
289 case 32000:
290 player->stream_settings.iec958.status[3] =
291 IEC958_AES3_CON_FS_32000;
292 break;
293 default:
294 /* Mark as sampling frequency not indicated */
295 player->stream_settings.iec958.status[3] =
296 IEC958_AES3_CON_FS_NOTID;
297 break;
298 }
299 }
300
301 /* Audio mode:
302 * Use audio mode status to select PCM or encoded mode
303 */
304 if (player->stream_settings.iec958.status[0] & IEC958_AES0_NONAUDIO)
305 player->stream_settings.encoding_mode =
306 UNIPERIF_IEC958_ENCODING_MODE_ENCODED;
307 else
308 player->stream_settings.encoding_mode =
309 UNIPERIF_IEC958_ENCODING_MODE_PCM;
310
311 if (player->stream_settings.encoding_mode ==
312 UNIPERIF_IEC958_ENCODING_MODE_PCM)
313 /* Clear user validity bits */
314 SET_UNIPERIF_USER_VALIDITY_VALIDITY_LR(player, 0);
315 else
316 /* Set user validity bits */
317 SET_UNIPERIF_USER_VALIDITY_VALIDITY_LR(player, 1);
318
319 /* Program the new channel status */
320 for (n = 0; n < 6; ++n) {
321 status =
322 player->stream_settings.iec958.status[0 + (n * 4)] & 0xf;
323 status |=
324 player->stream_settings.iec958.status[1 + (n * 4)] << 8;
325 status |=
326 player->stream_settings.iec958.status[2 + (n * 4)] << 16;
327 status |=
328 player->stream_settings.iec958.status[3 + (n * 4)] << 24;
329 SET_UNIPERIF_CHANNEL_STA_REGN(player, n, status);
330 }
331 mutex_unlock(&player->ctrl_lock);
332
333 /* Update the channel status */
334 if (player->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0)
335 SET_UNIPERIF_CONFIG_CHL_STS_UPDATE(player);
336 else
337 SET_UNIPERIF_BIT_CONTROL_CHL_STS_UPDATE(player);
338}
339
340static int uni_player_prepare_iec958(struct uniperif *player,
341 struct snd_pcm_runtime *runtime)
342{
343 int clk_div;
344
345 clk_div = player->mclk / runtime->rate;
346
347 /* Oversampling must be multiple of 128 as iec958 frame is 32-bits */
348 if ((clk_div % 128) || (clk_div <= 0)) {
349 dev_err(player->dev, "%s: invalid clk_div %d",
350 __func__, clk_div);
351 return -EINVAL;
352 }
353
354 switch (runtime->format) {
355 case SNDRV_PCM_FORMAT_S16_LE:
356 /* 16/16 memory format */
357 SET_UNIPERIF_CONFIG_MEM_FMT_16_16(player);
358 /* 16-bits per sub-frame */
359 SET_UNIPERIF_I2S_FMT_NBIT_32(player);
360 /* Set 16-bit sample precision */
361 SET_UNIPERIF_I2S_FMT_DATA_SIZE_16(player);
362 break;
363 case SNDRV_PCM_FORMAT_S32_LE:
364 /* 16/0 memory format */
365 SET_UNIPERIF_CONFIG_MEM_FMT_16_0(player);
366 /* 32-bits per sub-frame */
367 SET_UNIPERIF_I2S_FMT_NBIT_32(player);
368 /* Set 24-bit sample precision */
369 SET_UNIPERIF_I2S_FMT_DATA_SIZE_24(player);
370 break;
371 default:
372 dev_err(player->dev, "format not supported");
373 return -EINVAL;
374 }
375
376 /* Set parity to be calculated by the hardware */
377 SET_UNIPERIF_CONFIG_PARITY_CNTR_BY_HW(player);
378
379 /* Set channel status bits to be inserted by the hardware */
380 SET_UNIPERIF_CONFIG_CHANNEL_STA_CNTR_BY_HW(player);
381
382 /* Set user data bits to be inserted by the hardware */
383 SET_UNIPERIF_CONFIG_USER_DAT_CNTR_BY_HW(player);
384
385 /* Set validity bits to be inserted by the hardware */
386 SET_UNIPERIF_CONFIG_VALIDITY_DAT_CNTR_BY_HW(player);
387
388 /* Set full software control to disabled */
389 SET_UNIPERIF_CONFIG_SPDIF_SW_CTRL_DISABLE(player);
390
391 SET_UNIPERIF_CTRL_ZERO_STUFF_HW(player);
392
393 /* Update the channel status */
394 uni_player_set_channel_status(player, runtime);
395
396 /* Clear the user validity user bits */
397 SET_UNIPERIF_USER_VALIDITY_VALIDITY_LR(player, 0);
398
399 /* Disable one-bit audio mode */
400 SET_UNIPERIF_CONFIG_ONE_BIT_AUD_DISABLE(player);
401
402 /* Enable consecutive frames repetition of Z preamble (not for HBRA) */
403 SET_UNIPERIF_CONFIG_REPEAT_CHL_STS_ENABLE(player);
404
405 /* Change to SUF0_SUBF1 and left/right channels swap! */
406 SET_UNIPERIF_CONFIG_SUBFRAME_SEL_SUBF1_SUBF0(player);
407
408 /* Set data output as MSB first */
409 SET_UNIPERIF_I2S_FMT_ORDER_MSB(player);
410
411 if (player->stream_settings.encoding_mode ==
412 UNIPERIF_IEC958_ENCODING_MODE_ENCODED)
413 SET_UNIPERIF_CTRL_EXIT_STBY_ON_EOBLOCK_ON(player);
414 else
415 SET_UNIPERIF_CTRL_EXIT_STBY_ON_EOBLOCK_OFF(player);
416
417 SET_UNIPERIF_I2S_FMT_NUM_CH(player, runtime->channels / 2);
418
419 /* Set rounding to off */
420 SET_UNIPERIF_CTRL_ROUNDING_OFF(player);
421
422 /* Set clock divisor */
423 SET_UNIPERIF_CTRL_DIVIDER(player, clk_div / 128);
424
425 /* Set the spdif latency to not wait before starting player */
426 SET_UNIPERIF_CTRL_SPDIF_LAT_OFF(player);
427
428 /*
429 * Ensure iec958 formatting is off. It will be enabled in function
430 * uni_player_start() at the same time as the operation
431 * mode is set to work around a silicon issue.
432 */
433 if (player->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0)
434 SET_UNIPERIF_CTRL_SPDIF_FMT_OFF(player);
435 else
436 SET_UNIPERIF_CTRL_SPDIF_FMT_ON(player);
437
438 return 0;
439}
440
441static int uni_player_prepare_pcm(struct uniperif *player,
442 struct snd_pcm_runtime *runtime)
443{
444 int output_frame_size, slot_width, clk_div;
445
446 /* Force slot width to 32 in I2S mode (HW constraint) */
447 if ((player->daifmt & SND_SOC_DAIFMT_FORMAT_MASK) ==
448 SND_SOC_DAIFMT_I2S) {
449 slot_width = 32;
450 } else {
451 switch (runtime->format) {
452 case SNDRV_PCM_FORMAT_S16_LE:
453 slot_width = 16;
454 break;
455 default:
456 slot_width = 32;
457 break;
458 }
459 }
460 output_frame_size = slot_width * runtime->channels;
461
462 clk_div = player->mclk / runtime->rate;
463 /*
464 * For 32 bits subframe clk_div must be a multiple of 128,
465 * for 16 bits must be a multiple of 64
466 */
467 if ((slot_width == 32) && (clk_div % 128)) {
468 dev_err(player->dev, "%s: invalid clk_div", __func__);
469 return -EINVAL;
470 }
471
472 if ((slot_width == 16) && (clk_div % 64)) {
473 dev_err(player->dev, "%s: invalid clk_div", __func__);
474 return -EINVAL;
475 }
476
477 /*
478 * Number of bits per subframe (which is one channel sample)
479 * on output - Transfer 16 or 32 bits from FIFO
480 */
481 switch (slot_width) {
482 case 32:
483 SET_UNIPERIF_I2S_FMT_NBIT_32(player);
484 SET_UNIPERIF_I2S_FMT_DATA_SIZE_32(player);
485 break;
486 case 16:
487 SET_UNIPERIF_I2S_FMT_NBIT_16(player);
488 SET_UNIPERIF_I2S_FMT_DATA_SIZE_16(player);
489 break;
490 default:
491 dev_err(player->dev, "subframe format not supported");
492 return -EINVAL;
493 }
494
495 /* Configure data memory format */
496 switch (runtime->format) {
497 case SNDRV_PCM_FORMAT_S16_LE:
498 /* One data word contains two samples */
499 SET_UNIPERIF_CONFIG_MEM_FMT_16_16(player);
500 break;
501
502 case SNDRV_PCM_FORMAT_S32_LE:
503 /*
504 * Actually "16 bits/0 bits" means "32/28/24/20/18/16 bits
505 * on the left than zeros (if less than 32 bytes)"... ;-)
506 */
507 SET_UNIPERIF_CONFIG_MEM_FMT_16_0(player);
508 break;
509
510 default:
511 dev_err(player->dev, "format not supported");
512 return -EINVAL;
513 }
514
515 /* Set rounding to off */
516 SET_UNIPERIF_CTRL_ROUNDING_OFF(player);
517
518 /* Set clock divisor */
519 SET_UNIPERIF_CTRL_DIVIDER(player, clk_div / (2 * output_frame_size));
520
521 /* Number of channelsmust be even*/
522 if ((runtime->channels % 2) || (runtime->channels < 2) ||
523 (runtime->channels > 10)) {
524 dev_err(player->dev, "%s: invalid nb of channels", __func__);
525 return -EINVAL;
526 }
527
528 SET_UNIPERIF_I2S_FMT_NUM_CH(player, runtime->channels / 2);
529
530 /* Set 1-bit audio format to disabled */
531 SET_UNIPERIF_CONFIG_ONE_BIT_AUD_DISABLE(player);
532
533 SET_UNIPERIF_I2S_FMT_ORDER_MSB(player);
534 SET_UNIPERIF_I2S_FMT_SCLK_EDGE_FALLING(player);
535
536 /* No iec958 formatting as outputting to DAC */
537 SET_UNIPERIF_CTRL_SPDIF_FMT_OFF(player);
538
539 return 0;
540}
541
542/*
543 * ALSA uniperipheral iec958 controls
544 */
545static int uni_player_ctl_iec958_info(struct snd_kcontrol *kcontrol,
546 struct snd_ctl_elem_info *uinfo)
547{
548 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
549 uinfo->count = 1;
550
551 return 0;
552}
553
554static int uni_player_ctl_iec958_get(struct snd_kcontrol *kcontrol,
555 struct snd_ctl_elem_value *ucontrol)
556{
557 struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
558 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
559 struct uniperif *player = priv->dai_data.uni;
560 struct snd_aes_iec958 *iec958 = &player->stream_settings.iec958;
561
562 mutex_lock(&player->ctrl_lock);
563 ucontrol->value.iec958.status[0] = iec958->status[0];
564 ucontrol->value.iec958.status[1] = iec958->status[1];
565 ucontrol->value.iec958.status[2] = iec958->status[2];
566 ucontrol->value.iec958.status[3] = iec958->status[3];
567 mutex_unlock(&player->ctrl_lock);
568 return 0;
569}
570
571static int uni_player_ctl_iec958_put(struct snd_kcontrol *kcontrol,
572 struct snd_ctl_elem_value *ucontrol)
573{
574 struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
575 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
576 struct uniperif *player = priv->dai_data.uni;
577 struct snd_aes_iec958 *iec958 = &player->stream_settings.iec958;
578
579 mutex_lock(&player->ctrl_lock);
580 iec958->status[0] = ucontrol->value.iec958.status[0];
581 iec958->status[1] = ucontrol->value.iec958.status[1];
582 iec958->status[2] = ucontrol->value.iec958.status[2];
583 iec958->status[3] = ucontrol->value.iec958.status[3];
584 mutex_unlock(&player->ctrl_lock);
585
586 uni_player_set_channel_status(player, NULL);
587
588 return 0;
589}
590
591static struct snd_kcontrol_new uni_player_iec958_ctl = {
592 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
593 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
594 .info = uni_player_ctl_iec958_info,
595 .get = uni_player_ctl_iec958_get,
596 .put = uni_player_ctl_iec958_put,
597};
598
599/*
600 * uniperif rate adjustement control
601 */
602static int snd_sti_clk_adjustment_info(struct snd_kcontrol *kcontrol,
603 struct snd_ctl_elem_info *uinfo)
604{
605 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
606 uinfo->count = 1;
607 uinfo->value.integer.min = UNIPERIF_PLAYER_CLK_ADJ_MIN;
608 uinfo->value.integer.max = UNIPERIF_PLAYER_CLK_ADJ_MAX;
609 uinfo->value.integer.step = 1;
610
611 return 0;
612}
613
614static int snd_sti_clk_adjustment_get(struct snd_kcontrol *kcontrol,
615 struct snd_ctl_elem_value *ucontrol)
616{
617 struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
618 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
619 struct uniperif *player = priv->dai_data.uni;
620
621 mutex_lock(&player->ctrl_lock);
622 ucontrol->value.integer.value[0] = player->clk_adj;
623 mutex_unlock(&player->ctrl_lock);
624
625 return 0;
626}
627
628static int snd_sti_clk_adjustment_put(struct snd_kcontrol *kcontrol,
629 struct snd_ctl_elem_value *ucontrol)
630{
631 struct snd_soc_dai *dai = snd_kcontrol_chip(kcontrol);
632 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
633 struct uniperif *player = priv->dai_data.uni;
634 int ret = 0;
635
636 if ((ucontrol->value.integer.value[0] < UNIPERIF_PLAYER_CLK_ADJ_MIN) ||
637 (ucontrol->value.integer.value[0] > UNIPERIF_PLAYER_CLK_ADJ_MAX))
638 return -EINVAL;
639
640 mutex_lock(&player->ctrl_lock);
641 player->clk_adj = ucontrol->value.integer.value[0];
642
643 if (player->mclk)
644 ret = uni_player_clk_set_rate(player, player->mclk);
645 mutex_unlock(&player->ctrl_lock);
646
647 return ret;
648}
649
650static struct snd_kcontrol_new uni_player_clk_adj_ctl = {
651 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
652 .name = "PCM Playback Oversampling Freq. Adjustment",
653 .info = snd_sti_clk_adjustment_info,
654 .get = snd_sti_clk_adjustment_get,
655 .put = snd_sti_clk_adjustment_put,
656};
657
658static struct snd_kcontrol_new *snd_sti_pcm_ctl[] = {
659 &uni_player_clk_adj_ctl,
660};
661
662static struct snd_kcontrol_new *snd_sti_iec_ctl[] = {
663 &uni_player_iec958_ctl,
664 &uni_player_clk_adj_ctl,
665};
666
667static int uni_player_startup(struct snd_pcm_substream *substream,
668 struct snd_soc_dai *dai)
669{
670 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
671 struct uniperif *player = priv->dai_data.uni;
672
673 player->clk_adj = 0;
674
675 return 0;
676}
677
678static int uni_player_set_sysclk(struct snd_soc_dai *dai, int clk_id,
679 unsigned int freq, int dir)
680{
681 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
682 struct uniperif *player = priv->dai_data.uni;
683 int ret;
684
685 if (dir == SND_SOC_CLOCK_IN)
686 return 0;
687
688 if (clk_id != 0)
689 return -EINVAL;
690
691 mutex_lock(&player->ctrl_lock);
692 ret = uni_player_clk_set_rate(player, freq);
693 if (!ret)
694 player->mclk = freq;
695 mutex_unlock(&player->ctrl_lock);
696
697 return ret;
698}
699
700static int uni_player_prepare(struct snd_pcm_substream *substream,
701 struct snd_soc_dai *dai)
702{
703 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
704 struct uniperif *player = priv->dai_data.uni;
705 struct snd_pcm_runtime *runtime = substream->runtime;
706 int transfer_size, trigger_limit;
707 int ret;
708
709 /* The player should be stopped */
710 if (player->state != UNIPERIF_STATE_STOPPED) {
711 dev_err(player->dev, "%s: invalid player state %d", __func__,
712 player->state);
713 return -EINVAL;
714 }
715
716 /* Calculate transfer size (in fifo cells and bytes) for frame count */
717 transfer_size = runtime->channels * UNIPERIF_FIFO_FRAMES;
718
719 /* Calculate number of empty cells available before asserting DREQ */
720 if (player->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0) {
721 trigger_limit = UNIPERIF_FIFO_SIZE - transfer_size;
722 } else {
723 /*
724 * Since SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0
725 * FDMA_TRIGGER_LIMIT also controls when the state switches
726 * from OFF or STANDBY to AUDIO DATA.
727 */
728 trigger_limit = transfer_size;
729 }
730
731 /* Trigger limit must be an even number */
732 if ((!trigger_limit % 2) || (trigger_limit != 1 && transfer_size % 2) ||
733 (trigger_limit > UNIPERIF_CONFIG_DMA_TRIG_LIMIT_MASK(player))) {
734 dev_err(player->dev, "invalid trigger limit %d", trigger_limit);
735 return -EINVAL;
736 }
737
738 SET_UNIPERIF_CONFIG_DMA_TRIG_LIMIT(player, trigger_limit);
739
740 /* Uniperipheral setup depends on player type */
741 switch (player->info->player_type) {
742 case SND_ST_UNIPERIF_PLAYER_TYPE_HDMI:
743 ret = uni_player_prepare_iec958(player, runtime);
744 break;
745 case SND_ST_UNIPERIF_PLAYER_TYPE_PCM:
746 ret = uni_player_prepare_pcm(player, runtime);
747 break;
748 case SND_ST_UNIPERIF_PLAYER_TYPE_SPDIF:
749 ret = uni_player_prepare_iec958(player, runtime);
750 break;
751 default:
752 dev_err(player->dev, "invalid player type");
753 return -EINVAL;
754 }
755
756 if (ret)
757 return ret;
758
759 switch (player->daifmt & SND_SOC_DAIFMT_INV_MASK) {
760 case SND_SOC_DAIFMT_NB_NF:
761 SET_UNIPERIF_I2S_FMT_LR_POL_LOW(player);
762 SET_UNIPERIF_I2S_FMT_SCLK_EDGE_RISING(player);
763 break;
764 case SND_SOC_DAIFMT_NB_IF:
765 SET_UNIPERIF_I2S_FMT_LR_POL_HIG(player);
766 SET_UNIPERIF_I2S_FMT_SCLK_EDGE_RISING(player);
767 break;
768 case SND_SOC_DAIFMT_IB_NF:
769 SET_UNIPERIF_I2S_FMT_LR_POL_LOW(player);
770 SET_UNIPERIF_I2S_FMT_SCLK_EDGE_FALLING(player);
771 break;
772 case SND_SOC_DAIFMT_IB_IF:
773 SET_UNIPERIF_I2S_FMT_LR_POL_HIG(player);
774 SET_UNIPERIF_I2S_FMT_SCLK_EDGE_FALLING(player);
775 break;
776 }
777
778 switch (player->daifmt & SND_SOC_DAIFMT_FORMAT_MASK) {
779 case SND_SOC_DAIFMT_I2S:
780 SET_UNIPERIF_I2S_FMT_ALIGN_LEFT(player);
781 SET_UNIPERIF_I2S_FMT_PADDING_I2S_MODE(player);
782 break;
783 case SND_SOC_DAIFMT_LEFT_J:
784 SET_UNIPERIF_I2S_FMT_ALIGN_LEFT(player);
785 SET_UNIPERIF_I2S_FMT_PADDING_SONY_MODE(player);
786 break;
787 case SND_SOC_DAIFMT_RIGHT_J:
788 SET_UNIPERIF_I2S_FMT_ALIGN_RIGHT(player);
789 SET_UNIPERIF_I2S_FMT_PADDING_SONY_MODE(player);
790 break;
791 default:
792 dev_err(player->dev, "format not supported");
793 return -EINVAL;
794 }
795
796 SET_UNIPERIF_I2S_FMT_NO_OF_SAMPLES_TO_READ(player, 0);
797
798 /* Reset uniperipheral player */
799 SET_UNIPERIF_SOFT_RST_SOFT_RST(player);
800
801 return reset_player(player);
802}
803
804static int uni_player_start(struct uniperif *player)
805{
806 int ret;
807
808 /* The player should be stopped */
809 if (player->state != UNIPERIF_STATE_STOPPED) {
810 dev_err(player->dev, "%s: invalid player state", __func__);
811 return -EINVAL;
812 }
813
814 ret = clk_prepare_enable(player->clk);
815 if (ret) {
816 dev_err(player->dev, "%s: Failed to enable clock", __func__);
817 return ret;
818 }
819
820 /* Clear any pending interrupts */
821 SET_UNIPERIF_ITS_BCLR(player, GET_UNIPERIF_ITS(player));
822
823 /* Set the interrupt mask */
824 SET_UNIPERIF_ITM_BSET_DMA_ERROR(player);
825 SET_UNIPERIF_ITM_BSET_FIFO_ERROR(player);
826
827 /* Enable underflow recovery interrupts */
828 if (player->info->underflow_enabled) {
829 SET_UNIPERIF_ITM_BSET_UNDERFLOW_REC_DONE(player);
830 SET_UNIPERIF_ITM_BSET_UNDERFLOW_REC_FAILED(player);
831 }
832
833 /* Reset uniperipheral player */
834 SET_UNIPERIF_SOFT_RST_SOFT_RST(player);
835
836 ret = reset_player(player);
837 if (ret < 0)
838 return ret;
839
840 /*
841 * Does not use IEC61937 features of the uniperipheral hardware.
842 * Instead it performs IEC61937 in software and inserts it directly
843 * into the audio data stream. As such, when encoded mode is selected,
844 * linear pcm mode is still used, but with the differences of the
845 * channel status bits set for encoded mode and the validity bits set.
846 */
847 SET_UNIPERIF_CTRL_OPERATION_PCM_DATA(player);
848
849 /*
850 * If iec958 formatting is required for hdmi or spdif, then it must be
851 * enabled after the operation mode is set. If set prior to this, it
852 * will not take affect and hang the player.
853 */
854 if (player->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0)
855 if (UNIPERIF_PLAYER_TYPE_IS_IEC958(player))
856 SET_UNIPERIF_CTRL_SPDIF_FMT_ON(player);
857
858 /* Force channel status update (no update if clk disable) */
859 if (player->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0)
860 SET_UNIPERIF_CONFIG_CHL_STS_UPDATE(player);
861 else
862 SET_UNIPERIF_BIT_CONTROL_CHL_STS_UPDATE(player);
863
864 /* Update state to started */
865 player->state = UNIPERIF_STATE_STARTED;
866
867 return 0;
868}
869
870static int uni_player_stop(struct uniperif *player)
871{
872 int ret;
873
874 /* The player should not be in stopped state */
875 if (player->state == UNIPERIF_STATE_STOPPED) {
876 dev_err(player->dev, "%s: invalid player state", __func__);
877 return -EINVAL;
878 }
879
880 /* Turn the player off */
881 SET_UNIPERIF_CTRL_OPERATION_OFF(player);
882
883 /* Soft reset the player */
884 SET_UNIPERIF_SOFT_RST_SOFT_RST(player);
885
886 ret = reset_player(player);
887 if (ret < 0)
888 return ret;
889
890 /* Disable interrupts */
891 SET_UNIPERIF_ITM_BCLR(player, GET_UNIPERIF_ITM(player));
892
893 /* Disable clock */
894 clk_disable_unprepare(player->clk);
895
896 /* Update state to stopped and return */
897 player->state = UNIPERIF_STATE_STOPPED;
898
899 return 0;
900}
901
902int uni_player_resume(struct uniperif *player)
903{
904 int ret;
905
906 /* Select the frequency synthesizer clock */
907 if (player->clk_sel) {
908 ret = regmap_field_write(player->clk_sel, 1);
909 if (ret) {
910 dev_err(player->dev,
911 "%s: Failed to select freq synth clock",
912 __func__);
913 return ret;
914 }
915 }
916
917 SET_UNIPERIF_CONFIG_BACK_STALL_REQ_DISABLE(player);
918 SET_UNIPERIF_CTRL_ROUNDING_OFF(player);
919 SET_UNIPERIF_CTRL_SPDIF_LAT_OFF(player);
920 SET_UNIPERIF_CONFIG_IDLE_MOD_DISABLE(player);
921
922 return 0;
923}
924EXPORT_SYMBOL_GPL(uni_player_resume);
925
926static int uni_player_trigger(struct snd_pcm_substream *substream,
927 int cmd, struct snd_soc_dai *dai)
928{
929 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
930 struct uniperif *player = priv->dai_data.uni;
931
932 switch (cmd) {
933 case SNDRV_PCM_TRIGGER_START:
934 return uni_player_start(player);
935 case SNDRV_PCM_TRIGGER_STOP:
936 return uni_player_stop(player);
937 case SNDRV_PCM_TRIGGER_RESUME:
938 return uni_player_resume(player);
939 default:
940 return -EINVAL;
941 }
942}
943
944static void uni_player_shutdown(struct snd_pcm_substream *substream,
945 struct snd_soc_dai *dai)
946{
947 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
948 struct uniperif *player = priv->dai_data.uni;
949
950 if (player->state != UNIPERIF_STATE_STOPPED)
951 /* Stop the player */
952 uni_player_stop(player);
953}
954
955static int uni_player_parse_dt_clk_glue(struct platform_device *pdev,
956 struct uniperif *player)
957{
958 int bit_offset;
959 struct device_node *node = pdev->dev.of_node;
960 struct regmap *regmap;
961
962 bit_offset = SYS_CFG_AUDI0_GLUE_PCM_CLKX + player->info->id;
963
964 regmap = syscon_regmap_lookup_by_phandle(node, "st,syscfg");
965
966 if (regmap) {
967 struct reg_field regfield =
968 REG_FIELD(SYS_CFG_AUDIO_GLUE, bit_offset, bit_offset);
969
970 player->clk_sel = regmap_field_alloc(regmap, regfield);
971 } else {
972 dev_err(&pdev->dev, "sti-audio-clk-glue syscf not found\n");
973 return -EINVAL;
974 }
975
976 return 0;
977}
978
979static int uni_player_parse_dt(struct platform_device *pdev,
980 struct uniperif *player)
981{
982 struct uniperif_info *info;
983 struct device *dev = &pdev->dev;
984 struct device_node *pnode = pdev->dev.of_node;
985 const char *mode;
986
987 /* Allocate memory for the info structure */
988 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
989 if (!info)
990 return -ENOMEM;
991
992 of_property_read_u32(pnode, "version", &player->ver);
993 if (player->ver == SND_ST_UNIPERIF_VERSION_UNKNOWN) {
994 dev_err(dev, "Unknown uniperipheral version ");
995 return -EINVAL;
996 }
997 /* Underflow recovery is only supported on later ip revisions */
998 if (player->ver >= SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0)
999 info->underflow_enabled = 1;
1000
1001 of_property_read_u32(pnode, "uniperiph-id", &info->id);
1002
1003 /* Read the device mode property */
1004 of_property_read_string(pnode, "mode", &mode);
1005
1006 if (strcasecmp(mode, "hdmi") == 0)
1007 info->player_type = SND_ST_UNIPERIF_PLAYER_TYPE_HDMI;
1008 else if (strcasecmp(mode, "pcm") == 0)
1009 info->player_type = SND_ST_UNIPERIF_PLAYER_TYPE_PCM;
1010 else if (strcasecmp(mode, "spdif") == 0)
1011 info->player_type = SND_ST_UNIPERIF_PLAYER_TYPE_SPDIF;
1012 else
1013 info->player_type = SND_ST_UNIPERIF_PLAYER_TYPE_NONE;
1014
1015 /* Save the info structure */
1016 player->info = info;
1017
1018 /* Get the PCM_CLK_SEL bit from audio-glue-ctrl SoC register */
1019 if (uni_player_parse_dt_clk_glue(pdev, player))
1020 return -EINVAL;
1021
1022 return 0;
1023}
1024
1025static const struct snd_soc_dai_ops uni_player_dai_ops = {
1026 .startup = uni_player_startup,
1027 .shutdown = uni_player_shutdown,
1028 .prepare = uni_player_prepare,
1029 .trigger = uni_player_trigger,
1030 .hw_params = sti_uniperiph_dai_hw_params,
1031 .set_fmt = sti_uniperiph_dai_set_fmt,
1032 .set_sysclk = uni_player_set_sysclk
1033};
1034
1035int uni_player_init(struct platform_device *pdev,
1036 struct uniperif *player)
1037{
1038 int ret = 0;
1039
1040 player->dev = &pdev->dev;
1041 player->state = UNIPERIF_STATE_STOPPED;
1042 player->hw = &uni_player_pcm_hw;
1043 player->dai_ops = &uni_player_dai_ops;
1044
1045 ret = uni_player_parse_dt(pdev, player);
1046
1047 if (ret < 0) {
1048 dev_err(player->dev, "Failed to parse DeviceTree");
1049 return ret;
1050 }
1051
1052 /* Get uniperif resource */
1053 player->clk = of_clk_get(pdev->dev.of_node, 0);
1054 if (IS_ERR(player->clk))
1055 ret = PTR_ERR(player->clk);
1056
1057 /* Select the frequency synthesizer clock */
1058 if (player->clk_sel) {
1059 ret = regmap_field_write(player->clk_sel, 1);
1060 if (ret) {
1061 dev_err(player->dev,
1062 "%s: Failed to select freq synth clock",
1063 __func__);
1064 return ret;
1065 }
1066 }
1067
1068 ret = devm_request_irq(&pdev->dev, player->irq,
1069 uni_player_irq_handler, IRQF_SHARED,
1070 dev_name(&pdev->dev), player);
1071 if (ret < 0)
1072 return ret;
1073
1074 mutex_init(&player->ctrl_lock);
1075
1076 /* Ensure that disabled by default */
1077 SET_UNIPERIF_CONFIG_BACK_STALL_REQ_DISABLE(player);
1078 SET_UNIPERIF_CTRL_ROUNDING_OFF(player);
1079 SET_UNIPERIF_CTRL_SPDIF_LAT_OFF(player);
1080 SET_UNIPERIF_CONFIG_IDLE_MOD_DISABLE(player);
1081
1082 if (UNIPERIF_PLAYER_TYPE_IS_IEC958(player)) {
1083 /* Set default iec958 status bits */
1084
1085 /* Consumer, PCM, copyright, 2ch, mode 0 */
1086 player->stream_settings.iec958.status[0] = 0x00;
1087 /* Broadcast reception category */
1088 player->stream_settings.iec958.status[1] =
1089 IEC958_AES1_CON_GENERAL;
1090 /* Do not take into account source or channel number */
1091 player->stream_settings.iec958.status[2] =
1092 IEC958_AES2_CON_SOURCE_UNSPEC;
1093 /* Sampling frequency not indicated */
1094 player->stream_settings.iec958.status[3] =
1095 IEC958_AES3_CON_FS_NOTID;
1096 /* Max sample word 24-bit, sample word length not indicated */
1097 player->stream_settings.iec958.status[4] =
1098 IEC958_AES4_CON_MAX_WORDLEN_24 |
1099 IEC958_AES4_CON_WORDLEN_24_20;
1100
1101 player->num_ctrls = ARRAY_SIZE(snd_sti_iec_ctl);
1102 player->snd_ctrls = snd_sti_iec_ctl[0];
1103 } else {
1104 player->num_ctrls = ARRAY_SIZE(snd_sti_pcm_ctl);
1105 player->snd_ctrls = snd_sti_pcm_ctl[0];
1106 }
1107
1108 return 0;
1109}
1110EXPORT_SYMBOL_GPL(uni_player_init);
diff --git a/sound/soc/sti/uniperif_reader.c b/sound/soc/sti/uniperif_reader.c
new file mode 100644
index 000000000000..c502626f339b
--- /dev/null
+++ b/sound/soc/sti/uniperif_reader.c
@@ -0,0 +1,362 @@
1/*
2 * Copyright (C) STMicroelectronics SA 2015
3 * Authors: Arnaud Pouliquen <arnaud.pouliquen@st.com>
4 * for STMicroelectronics.
5 * License terms: GNU General Public License (GPL), version 2
6 */
7
8#include <linux/clk.h>
9#include <linux/delay.h>
10#include <linux/io.h>
11
12#include <sound/soc.h>
13
14#include "uniperif.h"
15
16/*
17 * Note: snd_pcm_hardware is linked to DMA controller but is declared here to
18 * integrate unireader capability in term of rate and supported channels
19 */
20static const struct snd_pcm_hardware uni_reader_pcm_hw = {
21 .info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
22 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_MMAP |
23 SNDRV_PCM_INFO_MMAP_VALID,
24 .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE,
25
26 .rates = SNDRV_PCM_RATE_CONTINUOUS,
27 .rate_min = 8000,
28 .rate_max = 96000,
29
30 .channels_min = 2,
31 .channels_max = 8,
32
33 .periods_min = 2,
34 .periods_max = 48,
35
36 .period_bytes_min = 128,
37 .period_bytes_max = 64 * PAGE_SIZE,
38 .buffer_bytes_max = 256 * PAGE_SIZE
39};
40
41/*
42 * uni_reader_irq_handler
43 * In case of error audio stream is stopped; stop action is protected via PCM
44 * stream lock to avoid race condition with trigger callback.
45 */
46static irqreturn_t uni_reader_irq_handler(int irq, void *dev_id)
47{
48 irqreturn_t ret = IRQ_NONE;
49 struct uniperif *reader = dev_id;
50 unsigned int status;
51
52 if (reader->state == UNIPERIF_STATE_STOPPED) {
53 /* Unexpected IRQ: do nothing */
54 dev_warn(reader->dev, "unexpected IRQ ");
55 return IRQ_HANDLED;
56 }
57
58 /* Get interrupt status & clear them immediately */
59 status = GET_UNIPERIF_ITS(reader);
60 SET_UNIPERIF_ITS_BCLR(reader, status);
61
62 /* Check for fifo overflow error */
63 if (unlikely(status & UNIPERIF_ITS_FIFO_ERROR_MASK(reader))) {
64 dev_err(reader->dev, "FIFO error detected");
65
66 snd_pcm_stream_lock(reader->substream);
67 snd_pcm_stop(reader->substream, SNDRV_PCM_STATE_XRUN);
68 snd_pcm_stream_unlock(reader->substream);
69
70 return IRQ_HANDLED;
71 }
72
73 return ret;
74}
75
76static int uni_reader_prepare(struct snd_pcm_substream *substream,
77 struct snd_soc_dai *dai)
78{
79 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
80 struct uniperif *reader = priv->dai_data.uni;
81 struct snd_pcm_runtime *runtime = substream->runtime;
82 int transfer_size, trigger_limit;
83 int slot_width;
84 int count = 10;
85
86 /* The reader should be stopped */
87 if (reader->state != UNIPERIF_STATE_STOPPED) {
88 dev_err(reader->dev, "%s: invalid reader state %d", __func__,
89 reader->state);
90 return -EINVAL;
91 }
92
93 /* Calculate transfer size (in fifo cells and bytes) for frame count */
94 transfer_size = runtime->channels * UNIPERIF_FIFO_FRAMES;
95
96 /* Calculate number of empty cells available before asserting DREQ */
97 if (reader->ver < SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0)
98 trigger_limit = UNIPERIF_FIFO_SIZE - transfer_size;
99 else
100 /*
101 * Since SND_ST_UNIPERIF_VERSION_UNI_PLR_TOP_1_0
102 * FDMA_TRIGGER_LIMIT also controls when the state switches
103 * from OFF or STANDBY to AUDIO DATA.
104 */
105 trigger_limit = transfer_size;
106
107 /* Trigger limit must be an even number */
108 if ((!trigger_limit % 2) ||
109 (trigger_limit != 1 && transfer_size % 2) ||
110 (trigger_limit > UNIPERIF_CONFIG_DMA_TRIG_LIMIT_MASK(reader))) {
111 dev_err(reader->dev, "invalid trigger limit %d", trigger_limit);
112 return -EINVAL;
113 }
114
115 SET_UNIPERIF_CONFIG_DMA_TRIG_LIMIT(reader, trigger_limit);
116
117 switch (reader->daifmt & SND_SOC_DAIFMT_INV_MASK) {
118 case SND_SOC_DAIFMT_IB_IF:
119 case SND_SOC_DAIFMT_NB_IF:
120 SET_UNIPERIF_I2S_FMT_LR_POL_HIG(reader);
121 break;
122 default:
123 SET_UNIPERIF_I2S_FMT_LR_POL_LOW(reader);
124 }
125
126 /* Force slot width to 32 in I2S mode */
127 if ((reader->daifmt & SND_SOC_DAIFMT_FORMAT_MASK)
128 == SND_SOC_DAIFMT_I2S) {
129 slot_width = 32;
130 } else {
131 switch (runtime->format) {
132 case SNDRV_PCM_FORMAT_S16_LE:
133 slot_width = 16;
134 break;
135 default:
136 slot_width = 32;
137 break;
138 }
139 }
140
141 /* Number of bits per subframe (i.e one channel sample) on input. */
142 switch (slot_width) {
143 case 32:
144 SET_UNIPERIF_I2S_FMT_NBIT_32(reader);
145 SET_UNIPERIF_I2S_FMT_DATA_SIZE_32(reader);
146 break;
147 case 16:
148 SET_UNIPERIF_I2S_FMT_NBIT_16(reader);
149 SET_UNIPERIF_I2S_FMT_DATA_SIZE_16(reader);
150 break;
151 default:
152 dev_err(reader->dev, "subframe format not supported");
153 return -EINVAL;
154 }
155
156 /* Configure data memory format */
157 switch (runtime->format) {
158 case SNDRV_PCM_FORMAT_S16_LE:
159 /* One data word contains two samples */
160 SET_UNIPERIF_CONFIG_MEM_FMT_16_16(reader);
161 break;
162
163 case SNDRV_PCM_FORMAT_S32_LE:
164 /*
165 * Actually "16 bits/0 bits" means "32/28/24/20/18/16 bits
166 * on the MSB then zeros (if less than 32 bytes)"...
167 */
168 SET_UNIPERIF_CONFIG_MEM_FMT_16_0(reader);
169 break;
170
171 default:
172 dev_err(reader->dev, "format not supported");
173 return -EINVAL;
174 }
175
176 switch (reader->daifmt & SND_SOC_DAIFMT_FORMAT_MASK) {
177 case SND_SOC_DAIFMT_I2S:
178 SET_UNIPERIF_I2S_FMT_ALIGN_LEFT(reader);
179 SET_UNIPERIF_I2S_FMT_PADDING_I2S_MODE(reader);
180 break;
181 case SND_SOC_DAIFMT_LEFT_J:
182 SET_UNIPERIF_I2S_FMT_ALIGN_LEFT(reader);
183 SET_UNIPERIF_I2S_FMT_PADDING_SONY_MODE(reader);
184 break;
185 case SND_SOC_DAIFMT_RIGHT_J:
186 SET_UNIPERIF_I2S_FMT_ALIGN_RIGHT(reader);
187 SET_UNIPERIF_I2S_FMT_PADDING_SONY_MODE(reader);
188 break;
189 default:
190 dev_err(reader->dev, "format not supported");
191 return -EINVAL;
192 }
193
194 SET_UNIPERIF_I2S_FMT_ORDER_MSB(reader);
195
196 /* Data clocking (changing) on the rising edge */
197 SET_UNIPERIF_I2S_FMT_SCLK_EDGE_RISING(reader);
198
199 /* Number of channels must be even */
200
201 if ((runtime->channels % 2) || (runtime->channels < 2) ||
202 (runtime->channels > 10)) {
203 dev_err(reader->dev, "%s: invalid nb of channels", __func__);
204 return -EINVAL;
205 }
206
207 SET_UNIPERIF_I2S_FMT_NUM_CH(reader, runtime->channels / 2);
208
209 /* Clear any pending interrupts */
210 SET_UNIPERIF_ITS_BCLR(reader, GET_UNIPERIF_ITS(reader));
211
212 SET_UNIPERIF_I2S_FMT_NO_OF_SAMPLES_TO_READ(reader, 0);
213
214 /* Set the interrupt mask */
215 SET_UNIPERIF_ITM_BSET_DMA_ERROR(reader);
216 SET_UNIPERIF_ITM_BSET_FIFO_ERROR(reader);
217 SET_UNIPERIF_ITM_BSET_MEM_BLK_READ(reader);
218
219 /* Enable underflow recovery interrupts */
220 if (reader->info->underflow_enabled) {
221 SET_UNIPERIF_ITM_BSET_UNDERFLOW_REC_DONE(reader);
222 SET_UNIPERIF_ITM_BSET_UNDERFLOW_REC_FAILED(reader);
223 }
224
225 /* Reset uniperipheral reader */
226 SET_UNIPERIF_SOFT_RST_SOFT_RST(reader);
227
228 while (GET_UNIPERIF_SOFT_RST_SOFT_RST(reader)) {
229 udelay(5);
230 count--;
231 }
232 if (!count) {
233 dev_err(reader->dev, "Failed to reset uniperif");
234 return -EIO;
235 }
236
237 return 0;
238}
239
240static int uni_reader_start(struct uniperif *reader)
241{
242 /* The reader should be stopped */
243 if (reader->state != UNIPERIF_STATE_STOPPED) {
244 dev_err(reader->dev, "%s: invalid reader state", __func__);
245 return -EINVAL;
246 }
247
248 /* Enable reader interrupts (and clear possible stalled ones) */
249 SET_UNIPERIF_ITS_BCLR_FIFO_ERROR(reader);
250 SET_UNIPERIF_ITM_BSET_FIFO_ERROR(reader);
251
252 /* Launch the reader */
253 SET_UNIPERIF_CTRL_OPERATION_PCM_DATA(reader);
254
255 /* Update state to started */
256 reader->state = UNIPERIF_STATE_STARTED;
257 return 0;
258}
259
260static int uni_reader_stop(struct uniperif *reader)
261{
262 /* The reader should not be in stopped state */
263 if (reader->state == UNIPERIF_STATE_STOPPED) {
264 dev_err(reader->dev, "%s: invalid reader state", __func__);
265 return -EINVAL;
266 }
267
268 /* Turn the reader off */
269 SET_UNIPERIF_CTRL_OPERATION_OFF(reader);
270
271 /* Disable interrupts */
272 SET_UNIPERIF_ITM_BCLR(reader, GET_UNIPERIF_ITM(reader));
273
274 /* Update state to stopped and return */
275 reader->state = UNIPERIF_STATE_STOPPED;
276
277 return 0;
278}
279
280static int uni_reader_trigger(struct snd_pcm_substream *substream,
281 int cmd, struct snd_soc_dai *dai)
282{
283 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
284 struct uniperif *reader = priv->dai_data.uni;
285
286 switch (cmd) {
287 case SNDRV_PCM_TRIGGER_START:
288 return uni_reader_start(reader);
289 case SNDRV_PCM_TRIGGER_STOP:
290 return uni_reader_stop(reader);
291 default:
292 return -EINVAL;
293 }
294}
295
296static void uni_reader_shutdown(struct snd_pcm_substream *substream,
297 struct snd_soc_dai *dai)
298{
299 struct sti_uniperiph_data *priv = snd_soc_dai_get_drvdata(dai);
300 struct uniperif *reader = priv->dai_data.uni;
301
302 if (reader->state != UNIPERIF_STATE_STOPPED) {
303 /* Stop the reader */
304 uni_reader_stop(reader);
305 }
306}
307
308static int uni_reader_parse_dt(struct platform_device *pdev,
309 struct uniperif *reader)
310{
311 struct uniperif_info *info;
312 struct device_node *node = pdev->dev.of_node;
313
314 /* Allocate memory for the info structure */
315 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
316 if (!info)
317 return -ENOMEM;
318
319 of_property_read_u32(node, "version", &reader->ver);
320
321 /* Save the info structure */
322 reader->info = info;
323
324 return 0;
325}
326
327static const struct snd_soc_dai_ops uni_reader_dai_ops = {
328 .shutdown = uni_reader_shutdown,
329 .prepare = uni_reader_prepare,
330 .trigger = uni_reader_trigger,
331 .hw_params = sti_uniperiph_dai_hw_params,
332 .set_fmt = sti_uniperiph_dai_set_fmt,
333};
334
335int uni_reader_init(struct platform_device *pdev,
336 struct uniperif *reader)
337{
338 int ret = 0;
339
340 reader->dev = &pdev->dev;
341 reader->state = UNIPERIF_STATE_STOPPED;
342 reader->hw = &uni_reader_pcm_hw;
343 reader->dai_ops = &uni_reader_dai_ops;
344
345 dev_err(reader->dev, "%s: enter\n", __func__);
346 ret = uni_reader_parse_dt(pdev, reader);
347 if (ret < 0) {
348 dev_err(reader->dev, "Failed to parse DeviceTree");
349 return ret;
350 }
351
352 ret = devm_request_irq(&pdev->dev, reader->irq,
353 uni_reader_irq_handler, IRQF_SHARED,
354 dev_name(&pdev->dev), reader);
355 if (ret < 0) {
356 dev_err(&pdev->dev, "Failed to request IRQ");
357 return -EBUSY;
358 }
359
360 return 0;
361}
362EXPORT_SYMBOL_GPL(uni_reader_init);
diff --git a/sound/soc/zte/zx296702-i2s.c b/sound/soc/zte/zx296702-i2s.c
index 98d96e1b17e0..1930c42e1f55 100644
--- a/sound/soc/zte/zx296702-i2s.c
+++ b/sound/soc/zte/zx296702-i2s.c
@@ -393,9 +393,9 @@ static int zx_i2s_probe(struct platform_device *pdev)
393 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 393 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
394 zx_i2s->mapbase = res->start; 394 zx_i2s->mapbase = res->start;
395 zx_i2s->reg_base = devm_ioremap_resource(&pdev->dev, res); 395 zx_i2s->reg_base = devm_ioremap_resource(&pdev->dev, res);
396 if (!zx_i2s->reg_base) { 396 if (IS_ERR(zx_i2s->reg_base)) {
397 dev_err(&pdev->dev, "ioremap failed!\n"); 397 dev_err(&pdev->dev, "ioremap failed!\n");
398 return -EIO; 398 return PTR_ERR(zx_i2s->reg_base);
399 } 399 }
400 400
401 writel_relaxed(0, zx_i2s->reg_base + ZX_I2S_FIFO_CTRL); 401 writel_relaxed(0, zx_i2s->reg_base + ZX_I2S_FIFO_CTRL);
diff --git a/sound/soc/zte/zx296702-spdif.c b/sound/soc/zte/zx296702-spdif.c
index 11a0e46a1156..26265ce4caca 100644
--- a/sound/soc/zte/zx296702-spdif.c
+++ b/sound/soc/zte/zx296702-spdif.c
@@ -322,9 +322,9 @@ static int zx_spdif_probe(struct platform_device *pdev)
322 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 322 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
323 zx_spdif->mapbase = res->start; 323 zx_spdif->mapbase = res->start;
324 zx_spdif->reg_base = devm_ioremap_resource(&pdev->dev, res); 324 zx_spdif->reg_base = devm_ioremap_resource(&pdev->dev, res);
325 if (!zx_spdif->reg_base) { 325 if (IS_ERR(zx_spdif->reg_base)) {
326 dev_err(&pdev->dev, "ioremap failed!\n"); 326 dev_err(&pdev->dev, "ioremap failed!\n");
327 return -EIO; 327 return PTR_ERR(zx_spdif->reg_base);
328 } 328 }
329 329
330 zx_spdif_dev_init(zx_spdif->reg_base); 330 zx_spdif_dev_init(zx_spdif->reg_base);
diff --git a/sound/sparc/amd7930.c b/sound/sparc/amd7930.c
index 1b1a89e80d13..784ceb85b2d9 100644
--- a/sound/sparc/amd7930.c
+++ b/sound/sparc/amd7930.c
@@ -956,6 +956,7 @@ static int snd_amd7930_create(struct snd_card *card,
956 if (!amd->regs) { 956 if (!amd->regs) {
957 snd_printk(KERN_ERR 957 snd_printk(KERN_ERR
958 "amd7930-%d: Unable to map chip registers.\n", dev); 958 "amd7930-%d: Unable to map chip registers.\n", dev);
959 kfree(amd);
959 return -EIO; 960 return -EIO;
960 } 961 }
961 962
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 1fab9778807a..0450593980fd 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -638,7 +638,7 @@ int snd_usb_autoresume(struct snd_usb_audio *chip)
638 int err = -ENODEV; 638 int err = -ENODEV;
639 639
640 down_read(&chip->shutdown_rwsem); 640 down_read(&chip->shutdown_rwsem);
641 if (chip->probing && chip->in_pm) 641 if (chip->probing || chip->in_pm)
642 err = 0; 642 err = 0;
643 else if (!chip->shutdown) 643 else if (!chip->shutdown)
644 err = usb_autopm_get_interface(chip->pm_intf); 644 err = usb_autopm_get_interface(chip->pm_intf);
diff --git a/sound/usb/line6/pcm.c b/sound/usb/line6/pcm.c
index 8461d6bf992f..204cc074adb9 100644
--- a/sound/usb/line6/pcm.c
+++ b/sound/usb/line6/pcm.c
@@ -186,12 +186,8 @@ static int line6_stream_start(struct snd_line6_pcm *line6pcm, int direction,
186 int ret = 0; 186 int ret = 0;
187 187
188 spin_lock_irqsave(&pstr->lock, flags); 188 spin_lock_irqsave(&pstr->lock, flags);
189 if (!test_and_set_bit(type, &pstr->running)) { 189 if (!test_and_set_bit(type, &pstr->running) &&
190 if (pstr->active_urbs || pstr->unlink_urbs) { 190 !(pstr->active_urbs || pstr->unlink_urbs)) {
191 ret = -EBUSY;
192 goto error;
193 }
194
195 pstr->count = 0; 191 pstr->count = 0;
196 /* Submit all currently available URBs */ 192 /* Submit all currently available URBs */
197 if (direction == SNDRV_PCM_STREAM_PLAYBACK) 193 if (direction == SNDRV_PCM_STREAM_PLAYBACK)
@@ -199,7 +195,6 @@ static int line6_stream_start(struct snd_line6_pcm *line6pcm, int direction,
199 else 195 else
200 ret = line6_submit_audio_in_all_urbs(line6pcm); 196 ret = line6_submit_audio_in_all_urbs(line6pcm);
201 } 197 }
202 error:
203 if (ret < 0) 198 if (ret < 0)
204 clear_bit(type, &pstr->running); 199 clear_bit(type, &pstr->running);
205 spin_unlock_irqrestore(&pstr->lock, flags); 200 spin_unlock_irqrestore(&pstr->lock, flags);
diff --git a/sound/usb/mixer_maps.c b/sound/usb/mixer_maps.c
index e5000da9e9d7..6a803eff87f7 100644
--- a/sound/usb/mixer_maps.c
+++ b/sound/usb/mixer_maps.c
@@ -341,6 +341,20 @@ static const struct usbmix_name_map scms_usb3318_map[] = {
341 { 0 } 341 { 0 }
342}; 342};
343 343
344/* Bose companion 5, the dB conversion factor is 16 instead of 256 */
345static struct usbmix_dB_map bose_companion5_dB = {-5006, -6};
346static struct usbmix_name_map bose_companion5_map[] = {
347 { 3, NULL, .dB = &bose_companion5_dB },
348 { 0 } /* terminator */
349};
350
351/* Dragonfly DAC 1.2, the dB conversion factor is 1 instead of 256 */
352static struct usbmix_dB_map dragonfly_1_2_dB = {0, 5000};
353static struct usbmix_name_map dragonfly_1_2_map[] = {
354 { 7, NULL, .dB = &dragonfly_1_2_dB },
355 { 0 } /* terminator */
356};
357
344/* 358/*
345 * Control map entries 359 * Control map entries
346 */ 360 */
@@ -451,6 +465,16 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = {
451 .id = USB_ID(0x25c4, 0x0003), 465 .id = USB_ID(0x25c4, 0x0003),
452 .map = scms_usb3318_map, 466 .map = scms_usb3318_map,
453 }, 467 },
468 {
469 /* Bose Companion 5 */
470 .id = USB_ID(0x05a7, 0x1020),
471 .map = bose_companion5_map,
472 },
473 {
474 /* Dragonfly DAC 1.2 */
475 .id = USB_ID(0x21b4, 0x0081),
476 .map = dragonfly_1_2_map,
477 },
454 { 0 } /* terminator */ 478 { 0 } /* terminator */
455}; 479};
456 480
diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
index 2f6d3e9a1bcd..e4756651a52c 100644
--- a/sound/usb/quirks-table.h
+++ b/sound/usb/quirks-table.h
@@ -2512,6 +2512,74 @@ YAMAHA_DEVICE(0x7010, "UB99"),
2512 } 2512 }
2513}, 2513},
2514 2514
2515/* Steinberg devices */
2516{
2517 /* Steinberg MI2 */
2518 USB_DEVICE_VENDOR_SPEC(0x0a4e, 0x2040),
2519 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
2520 .ifnum = QUIRK_ANY_INTERFACE,
2521 .type = QUIRK_COMPOSITE,
2522 .data = & (const struct snd_usb_audio_quirk[]) {
2523 {
2524 .ifnum = 0,
2525 .type = QUIRK_AUDIO_STANDARD_INTERFACE
2526 },
2527 {
2528 .ifnum = 1,
2529 .type = QUIRK_AUDIO_STANDARD_INTERFACE
2530 },
2531 {
2532 .ifnum = 2,
2533 .type = QUIRK_AUDIO_STANDARD_INTERFACE
2534 },
2535 {
2536 .ifnum = 3,
2537 .type = QUIRK_MIDI_FIXED_ENDPOINT,
2538 .data = &(const struct snd_usb_midi_endpoint_info) {
2539 .out_cables = 0x0001,
2540 .in_cables = 0x0001
2541 }
2542 },
2543 {
2544 .ifnum = -1
2545 }
2546 }
2547 }
2548},
2549{
2550 /* Steinberg MI4 */
2551 USB_DEVICE_VENDOR_SPEC(0x0a4e, 0x4040),
2552 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
2553 .ifnum = QUIRK_ANY_INTERFACE,
2554 .type = QUIRK_COMPOSITE,
2555 .data = & (const struct snd_usb_audio_quirk[]) {
2556 {
2557 .ifnum = 0,
2558 .type = QUIRK_AUDIO_STANDARD_INTERFACE
2559 },
2560 {
2561 .ifnum = 1,
2562 .type = QUIRK_AUDIO_STANDARD_INTERFACE
2563 },
2564 {
2565 .ifnum = 2,
2566 .type = QUIRK_AUDIO_STANDARD_INTERFACE
2567 },
2568 {
2569 .ifnum = 3,
2570 .type = QUIRK_MIDI_FIXED_ENDPOINT,
2571 .data = &(const struct snd_usb_midi_endpoint_info) {
2572 .out_cables = 0x0001,
2573 .in_cables = 0x0001
2574 }
2575 },
2576 {
2577 .ifnum = -1
2578 }
2579 }
2580 }
2581},
2582
2515/* TerraTec devices */ 2583/* TerraTec devices */
2516{ 2584{
2517 USB_DEVICE_VENDOR_SPEC(0x0ccd, 0x0012), 2585 USB_DEVICE_VENDOR_SPEC(0x0ccd, 0x0012),