aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2015-02-05 01:08:35 -0500
committerTakashi Iwai <tiwai@suse.de>2015-02-05 01:08:35 -0500
commita3ae255e3729c1bb4507412ea29be804f703d44c (patch)
treeedd1ca577dad5a0d701ae111519eaefa60896f98 /sound
parent3fe9cf390f6dc84f76b112b0a660967a84f9a81b (diff)
parent16ca41c6cc904d7eb9e92afc5f576e375c314f90 (diff)
Merge tag 'asoc-v3.20-2' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound into for-next
ASoC: Updates for v3.20 More updates for v3.20: - Lots of refactoring from Lars-Peter Clausen, moving drivers to more data driven initialization and rationalizing a lot of DAPM usage. - Much improved handling of CDCLK clocks on Samsung I2S controllers. - Lots of driver specific cleanups and feature improvements. - CODEC support for TI PCM514x and TLV320AIC3104 devices. - Board support for Tegra systems with Realtek RT5677. Conflicts: sound/soc/intel/sst-mfld-platform-pcm.c
Diffstat (limited to 'sound')
-rw-r--r--sound/core/pcm_lib.c85
-rw-r--r--sound/soc/Kconfig1
-rw-r--r--sound/soc/Makefile1
-rw-r--r--sound/soc/atmel/Kconfig2
-rw-r--r--sound/soc/atmel/atmel-pcm-dma.c12
-rw-r--r--sound/soc/atmel/atmel_ssc_dai.c132
-rw-r--r--sound/soc/atmel/sam9g20_wm8731.c31
-rw-r--r--sound/soc/au1x/db1200.c19
-rw-r--r--sound/soc/au1x/dbdma2.c6
-rw-r--r--sound/soc/au1x/dma.c6
-rw-r--r--sound/soc/codecs/88pm860x-codec.c4
-rw-r--r--sound/soc/codecs/Kconfig6
-rw-r--r--sound/soc/codecs/ad193x.c4
-rw-r--r--sound/soc/codecs/ak4671.c2
-rw-r--r--sound/soc/codecs/alc5623.c8
-rw-r--r--sound/soc/codecs/alc5632.c12
-rw-r--r--sound/soc/codecs/arizona.c78
-rw-r--r--sound/soc/codecs/arizona.h5
-rw-r--r--sound/soc/codecs/bt-sco.c2
-rw-r--r--sound/soc/codecs/cs35l32.c4
-rw-r--r--sound/soc/codecs/cs42l52.c4
-rw-r--r--sound/soc/codecs/cs42l56.c4
-rw-r--r--sound/soc/codecs/cs42l73.c4
-rw-r--r--sound/soc/codecs/da732x.c4
-rw-r--r--sound/soc/codecs/mc13783.c10
-rw-r--r--sound/soc/codecs/pcm3008.c4
-rw-r--r--sound/soc/codecs/pcm512x.c932
-rw-r--r--sound/soc/codecs/pcm512x.h109
-rw-r--r--sound/soc/codecs/rt286.c51
-rw-r--r--sound/soc/codecs/rt5631.c28
-rw-r--r--sound/soc/codecs/rt5640.c12
-rw-r--r--sound/soc/codecs/rt5645.c174
-rw-r--r--sound/soc/codecs/rt5645.h15
-rw-r--r--sound/soc/codecs/rt5651.c18
-rw-r--r--sound/soc/codecs/rt5670.c99
-rw-r--r--sound/soc/codecs/rt5670.h80
-rw-r--r--sound/soc/codecs/rt5677.c50
-rw-r--r--sound/soc/codecs/sgtl5000.c27
-rw-r--r--sound/soc/codecs/sn95031.c33
-rw-r--r--sound/soc/codecs/sta32x.c534
-rw-r--r--sound/soc/codecs/sta32x.h2
-rw-r--r--sound/soc/codecs/tlv320aic31xx.c9
-rw-r--r--sound/soc/codecs/tlv320aic3x.c349
-rw-r--r--sound/soc/codecs/tlv320dac33.c9
-rw-r--r--sound/soc/codecs/ts3a227e.c35
-rw-r--r--sound/soc/codecs/twl4030.c55
-rw-r--r--sound/soc/codecs/twl6040.c4
-rw-r--r--sound/soc/codecs/wm2000.c2
-rw-r--r--sound/soc/codecs/wm5100.c5
-rw-r--r--sound/soc/codecs/wm5102.c23
-rw-r--r--sound/soc/codecs/wm5110.c20
-rw-r--r--sound/soc/codecs/wm8350.c2
-rw-r--r--sound/soc/codecs/wm8400.c9
-rw-r--r--sound/soc/codecs/wm8731.c5
-rw-r--r--sound/soc/codecs/wm8770.c8
-rw-r--r--sound/soc/codecs/wm8804.c4
-rw-r--r--sound/soc/codecs/wm8900.c2
-rw-r--r--sound/soc/codecs/wm8903.c2
-rw-r--r--sound/soc/codecs/wm8904.c35
-rw-r--r--sound/soc/codecs/wm8955.c2
-rw-r--r--sound/soc/codecs/wm8958-dsp2.c2
-rw-r--r--sound/soc/codecs/wm8960.c51
-rw-r--r--sound/soc/codecs/wm8961.c4
-rw-r--r--sound/soc/codecs/wm8962.c6
-rw-r--r--sound/soc/codecs/wm8988.c6
-rw-r--r--sound/soc/codecs/wm8990.c9
-rw-r--r--sound/soc/codecs/wm8991.c9
-rw-r--r--sound/soc/codecs/wm8993.c2
-rw-r--r--sound/soc/codecs/wm8994.c23
-rw-r--r--sound/soc/codecs/wm8995.c20
-rw-r--r--sound/soc/codecs/wm8996.c8
-rw-r--r--sound/soc/codecs/wm8997.c11
-rw-r--r--sound/soc/codecs/wm9081.c2
-rw-r--r--sound/soc/codecs/wm9090.c2
-rw-r--r--sound/soc/codecs/wm9705.c16
-rw-r--r--sound/soc/codecs/wm9712.c12
-rw-r--r--sound/soc/codecs/wm9713.c14
-rw-r--r--sound/soc/codecs/wm_adsp.c6
-rw-r--r--sound/soc/codecs/wm_hubs.c10
-rw-r--r--sound/soc/davinci/Kconfig3
-rw-r--r--sound/soc/davinci/davinci-evm.c6
-rw-r--r--sound/soc/davinci/davinci-mcasp.c103
-rw-r--r--sound/soc/dwc/Kconfig1
-rw-r--r--sound/soc/dwc/designware_i2s.c281
-rw-r--r--sound/soc/fsl/eukrea-tlv320.c23
-rw-r--r--sound/soc/fsl/fsl_asrc.c5
-rw-r--r--sound/soc/fsl/fsl_asrc.h3
-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_spdif.c17
-rw-r--r--sound/soc/fsl/fsl_ssi.c10
-rw-r--r--sound/soc/fsl/fsl_utils.c27
-rw-r--r--sound/soc/fsl/fsl_utils.h3
-rw-r--r--sound/soc/fsl/imx-mc13783.c5
-rw-r--r--sound/soc/fsl/imx-spdif.c1
-rw-r--r--sound/soc/fsl/imx-ssi.c5
-rw-r--r--sound/soc/fsl/mx27vis-aic32x4.c12
-rw-r--r--sound/soc/fsl/wm1133-ev1.c16
-rw-r--r--sound/soc/generic/simple-card.c34
-rw-r--r--sound/soc/intel/broadwell.c10
-rw-r--r--sound/soc/intel/byt-rt5640.c12
-rw-r--r--sound/soc/intel/cht_bsw_rt5672.c14
-rw-r--r--sound/soc/intel/sst-baytrail-pcm.c6
-rw-r--r--sound/soc/intel/sst-dsp.c3
-rw-r--r--sound/soc/intel/sst-firmware.c2
-rw-r--r--sound/soc/intel/sst-haswell-dsp.c17
-rw-r--r--sound/soc/intel/sst-haswell-ipc.c9
-rw-r--r--sound/soc/intel/sst-haswell-pcm.c105
-rw-r--r--sound/soc/intel/sst-mfld-platform-pcm.c6
-rw-r--r--sound/soc/intel/sst/sst_acpi.c2
-rw-r--r--sound/soc/intel/sst/sst_loader.c3
-rw-r--r--sound/soc/mxs/mxs-saif.c10
-rw-r--r--sound/soc/mxs/mxs-saif.h1
-rw-r--r--sound/soc/mxs/mxs-sgtl5000.c27
-rw-r--r--sound/soc/nuc900/nuc900-pcm.c6
-rw-r--r--sound/soc/omap/ams-delta.c18
-rw-r--r--sound/soc/omap/omap-twl4030.c20
-rw-r--r--sound/soc/omap/rx51.c8
-rw-r--r--sound/soc/pxa/Kconfig2
-rw-r--r--sound/soc/pxa/corgi.c16
-rw-r--r--sound/soc/pxa/e740_wm9705.c20
-rw-r--r--sound/soc/pxa/e750_wm9705.c20
-rw-r--r--sound/soc/pxa/hx4700.c8
-rw-r--r--sound/soc/pxa/magician.c21
-rw-r--r--sound/soc/pxa/mioa701_wm9713.c2
-rw-r--r--sound/soc/pxa/palm27x.c15
-rw-r--r--sound/soc/pxa/raumfeld.c35
-rw-r--r--sound/soc/pxa/spitz.c22
-rw-r--r--sound/soc/pxa/ttc-dkb.c4
-rw-r--r--sound/soc/pxa/zylonite.c12
-rw-r--r--sound/soc/samsung/Kconfig4
-rw-r--r--sound/soc/samsung/goni_wm8994.c23
-rw-r--r--sound/soc/samsung/h1940_uda1380.c15
-rw-r--r--sound/soc/samsung/i2s.c362
-rw-r--r--sound/soc/samsung/jive_wm8750.c34
-rw-r--r--sound/soc/samsung/neo1973_wm8753.c25
-rw-r--r--sound/soc/samsung/odroidx2_max98090.c6
-rw-r--r--sound/soc/samsung/rx1950_uda1380.c15
-rw-r--r--sound/soc/samsung/s3c24xx_simtec.c20
-rw-r--r--sound/soc/samsung/s3c24xx_uda134x.c12
-rw-r--r--sound/soc/samsung/smartq_wm8987.c16
-rw-r--r--sound/soc/samsung/smdk_wm8580.c26
-rw-r--r--sound/soc/samsung/smdk_wm8580pcm.c19
-rw-r--r--sound/soc/samsung/smdk_wm8994pcm.c16
-rw-r--r--sound/soc/sh/dma-sh7760.c6
-rw-r--r--sound/soc/sh/fsi.c15
-rw-r--r--sound/soc/sh/migor.c12
-rw-r--r--sound/soc/sh/rcar/adg.c14
-rw-r--r--sound/soc/sh/rcar/core.c111
-rw-r--r--sound/soc/sh/rcar/dvc.c63
-rw-r--r--sound/soc/sh/rcar/gen.c15
-rw-r--r--sound/soc/sh/rcar/rsnd.h81
-rw-r--r--sound/soc/sh/rcar/src.c269
-rw-r--r--sound/soc/sh/rcar/ssi.c100
-rw-r--r--sound/soc/sh/siu_pcm.c1
-rw-r--r--sound/soc/soc-ac97.c36
-rw-r--r--sound/soc/soc-core.c204
-rw-r--r--sound/soc/soc-dapm.c20
-rw-r--r--sound/soc/soc-devres.c2
-rw-r--r--sound/soc/soc-generic-dmaengine-pcm.c15
-rw-r--r--sound/soc/tegra/Kconfig10
-rw-r--r--sound/soc/tegra/Makefile2
-rw-r--r--sound/soc/tegra/tegra_rt5677.c347
-rw-r--r--sound/soc/txx9/txx9aclc.c6
-rw-r--r--sound/soc/ux500/mop500_ab8500.c16
-rw-r--r--sound/soc/xtensa/Kconfig7
-rw-r--r--sound/soc/xtensa/Makefile3
-rw-r--r--sound/soc/xtensa/xtfpga-i2s.c675
168 files changed, 4971 insertions, 2074 deletions
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index db05e04d0070..ffd656012ab8 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -1015,6 +1015,60 @@ int snd_interval_list(struct snd_interval *i, unsigned int count,
1015 1015
1016EXPORT_SYMBOL(snd_interval_list); 1016EXPORT_SYMBOL(snd_interval_list);
1017 1017
1018/**
1019 * snd_interval_ranges - refine the interval value from the list of ranges
1020 * @i: the interval value to refine
1021 * @count: the number of elements in the list of ranges
1022 * @ranges: the ranges list
1023 * @mask: the bit-mask to evaluate
1024 *
1025 * Refines the interval value from the list of ranges.
1026 * When mask is non-zero, only the elements corresponding to bit 1 are
1027 * evaluated.
1028 *
1029 * Return: Positive if the value is changed, zero if it's not changed, or a
1030 * negative error code.
1031 */
1032int snd_interval_ranges(struct snd_interval *i, unsigned int count,
1033 const struct snd_interval *ranges, unsigned int mask)
1034{
1035 unsigned int k;
1036 struct snd_interval range_union;
1037 struct snd_interval range;
1038
1039 if (!count) {
1040 snd_interval_none(i);
1041 return -EINVAL;
1042 }
1043 snd_interval_any(&range_union);
1044 range_union.min = UINT_MAX;
1045 range_union.max = 0;
1046 for (k = 0; k < count; k++) {
1047 if (mask && !(mask & (1 << k)))
1048 continue;
1049 snd_interval_copy(&range, &ranges[k]);
1050 if (snd_interval_refine(&range, i) < 0)
1051 continue;
1052 if (snd_interval_empty(&range))
1053 continue;
1054
1055 if (range.min < range_union.min) {
1056 range_union.min = range.min;
1057 range_union.openmin = 1;
1058 }
1059 if (range.min == range_union.min && !range.openmin)
1060 range_union.openmin = 0;
1061 if (range.max > range_union.max) {
1062 range_union.max = range.max;
1063 range_union.openmax = 1;
1064 }
1065 if (range.max == range_union.max && !range.openmax)
1066 range_union.openmax = 0;
1067 }
1068 return snd_interval_refine(i, &range_union);
1069}
1070EXPORT_SYMBOL(snd_interval_ranges);
1071
1018static int snd_interval_step(struct snd_interval *i, unsigned int step) 1072static int snd_interval_step(struct snd_interval *i, unsigned int step)
1019{ 1073{
1020 unsigned int n; 1074 unsigned int n;
@@ -1221,6 +1275,37 @@ int snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime,
1221 1275
1222EXPORT_SYMBOL(snd_pcm_hw_constraint_list); 1276EXPORT_SYMBOL(snd_pcm_hw_constraint_list);
1223 1277
1278static int snd_pcm_hw_rule_ranges(struct snd_pcm_hw_params *params,
1279 struct snd_pcm_hw_rule *rule)
1280{
1281 struct snd_pcm_hw_constraint_ranges *r = rule->private;
1282 return snd_interval_ranges(hw_param_interval(params, rule->var),
1283 r->count, r->ranges, r->mask);
1284}
1285
1286
1287/**
1288 * snd_pcm_hw_constraint_ranges - apply list of range constraints to a parameter
1289 * @runtime: PCM runtime instance
1290 * @cond: condition bits
1291 * @var: hw_params variable to apply the list of range constraints
1292 * @r: ranges
1293 *
1294 * Apply the list of range constraints to an interval parameter.
1295 *
1296 * Return: Zero if successful, or a negative error code on failure.
1297 */
1298int snd_pcm_hw_constraint_ranges(struct snd_pcm_runtime *runtime,
1299 unsigned int cond,
1300 snd_pcm_hw_param_t var,
1301 const struct snd_pcm_hw_constraint_ranges *r)
1302{
1303 return snd_pcm_hw_rule_add(runtime, cond, var,
1304 snd_pcm_hw_rule_ranges, (void *)r,
1305 var, -1);
1306}
1307EXPORT_SYMBOL(snd_pcm_hw_constraint_ranges);
1308
1224static int snd_pcm_hw_rule_ratnums(struct snd_pcm_hw_params *params, 1309static int snd_pcm_hw_rule_ratnums(struct snd_pcm_hw_params *params,
1225 struct snd_pcm_hw_rule *rule) 1310 struct snd_pcm_hw_rule *rule)
1226{ 1311{
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig
index 7d5d6444a837..dcc79aa0236b 100644
--- a/sound/soc/Kconfig
+++ b/sound/soc/Kconfig
@@ -55,6 +55,7 @@ source "sound/soc/spear/Kconfig"
55source "sound/soc/tegra/Kconfig" 55source "sound/soc/tegra/Kconfig"
56source "sound/soc/txx9/Kconfig" 56source "sound/soc/txx9/Kconfig"
57source "sound/soc/ux500/Kconfig" 57source "sound/soc/ux500/Kconfig"
58source "sound/soc/xtensa/Kconfig"
58 59
59# Supported codecs 60# Supported codecs
60source "sound/soc/codecs/Kconfig" 61source "sound/soc/codecs/Kconfig"
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index 865e090c8061..5b3c8f67c8db 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -36,3 +36,4 @@ obj-$(CONFIG_SND_SOC) += spear/
36obj-$(CONFIG_SND_SOC) += tegra/ 36obj-$(CONFIG_SND_SOC) += tegra/
37obj-$(CONFIG_SND_SOC) += txx9/ 37obj-$(CONFIG_SND_SOC) += txx9/
38obj-$(CONFIG_SND_SOC) += ux500/ 38obj-$(CONFIG_SND_SOC) += ux500/
39obj-$(CONFIG_SND_SOC) += xtensa/
diff --git a/sound/soc/atmel/Kconfig b/sound/soc/atmel/Kconfig
index fb3878312bf8..1579e994acf8 100644
--- a/sound/soc/atmel/Kconfig
+++ b/sound/soc/atmel/Kconfig
@@ -45,7 +45,7 @@ config SND_ATMEL_SOC_WM8904
45 45
46config SND_AT91_SOC_SAM9X5_WM8731 46config SND_AT91_SOC_SAM9X5_WM8731
47 tristate "SoC Audio support for WM8731-based at91sam9x5 board" 47 tristate "SoC Audio support for WM8731-based at91sam9x5 board"
48 depends on ATMEL_SSC && SND_ATMEL_SOC && SOC_AT91SAM9X5 48 depends on ARCH_AT91 && ATMEL_SSC && SND_ATMEL_SOC
49 select SND_ATMEL_SOC_SSC 49 select SND_ATMEL_SOC_SSC
50 select SND_ATMEL_SOC_DMA 50 select SND_ATMEL_SOC_DMA
51 select SND_SOC_WM8731 51 select SND_SOC_WM8731
diff --git a/sound/soc/atmel/atmel-pcm-dma.c b/sound/soc/atmel/atmel-pcm-dma.c
index 33fb3bb133df..b8e7bad05eb1 100644
--- a/sound/soc/atmel/atmel-pcm-dma.c
+++ b/sound/soc/atmel/atmel-pcm-dma.c
@@ -105,13 +105,11 @@ static int atmel_pcm_configure_dma(struct snd_pcm_substream *substream,
105 return ret; 105 return ret;
106 } 106 }
107 107
108 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 108 slave_config->dst_addr = ssc->phybase + SSC_THR;
109 slave_config->dst_addr = ssc->phybase + SSC_THR; 109 slave_config->dst_maxburst = 1;
110 slave_config->dst_maxburst = 1; 110
111 } else { 111 slave_config->src_addr = ssc->phybase + SSC_RHR;
112 slave_config->src_addr = ssc->phybase + SSC_RHR; 112 slave_config->src_maxburst = 1;
113 slave_config->src_maxburst = 1;
114 }
115 113
116 prtd->dma_intr_handler = atmel_pcm_dma_irq; 114 prtd->dma_intr_handler = atmel_pcm_dma_irq;
117 115
diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c
index 99ff35e2a25d..fb0b7e8b08ff 100644
--- a/sound/soc/atmel/atmel_ssc_dai.c
+++ b/sound/soc/atmel/atmel_ssc_dai.c
@@ -204,6 +204,13 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream,
204 pr_debug("atmel_ssc_startup: SSC_SR=0x%u\n", 204 pr_debug("atmel_ssc_startup: SSC_SR=0x%u\n",
205 ssc_readl(ssc_p->ssc->regs, SR)); 205 ssc_readl(ssc_p->ssc->regs, SR));
206 206
207 /* Enable PMC peripheral clock for this SSC */
208 pr_debug("atmel_ssc_dai: Starting clock\n");
209 clk_enable(ssc_p->ssc->clk);
210
211 /* Reset the SSC to keep it at a clean status */
212 ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_SWRST));
213
207 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 214 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
208 dir = 0; 215 dir = 0;
209 dir_mask = SSC_DIR_MASK_PLAYBACK; 216 dir_mask = SSC_DIR_MASK_PLAYBACK;
@@ -250,11 +257,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream,
250 dma_params = ssc_p->dma_params[dir]; 257 dma_params = ssc_p->dma_params[dir];
251 258
252 if (dma_params != NULL) { 259 if (dma_params != NULL) {
253 ssc_writel(ssc_p->ssc->regs, CR, dma_params->mask->ssc_disable);
254 pr_debug("atmel_ssc_shutdown: %s disabled SSC_SR=0x%08x\n",
255 (dir ? "receive" : "transmit"),
256 ssc_readl(ssc_p->ssc->regs, SR));
257
258 dma_params->ssc = NULL; 260 dma_params->ssc = NULL;
259 dma_params->substream = NULL; 261 dma_params->substream = NULL;
260 ssc_p->dma_params[dir] = NULL; 262 ssc_p->dma_params[dir] = NULL;
@@ -266,10 +268,6 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream,
266 ssc_p->dir_mask &= ~dir_mask; 268 ssc_p->dir_mask &= ~dir_mask;
267 if (!ssc_p->dir_mask) { 269 if (!ssc_p->dir_mask) {
268 if (ssc_p->initialized) { 270 if (ssc_p->initialized) {
269 /* Shutdown the SSC clock. */
270 pr_debug("atmel_ssc_dai: Stopping clock\n");
271 clk_disable(ssc_p->ssc->clk);
272
273 free_irq(ssc_p->ssc->irq, ssc_p); 271 free_irq(ssc_p->ssc->irq, ssc_p);
274 ssc_p->initialized = 0; 272 ssc_p->initialized = 0;
275 } 273 }
@@ -280,6 +278,10 @@ static void atmel_ssc_shutdown(struct snd_pcm_substream *substream,
280 ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period = 0; 278 ssc_p->cmr_div = ssc_p->tcmr_period = ssc_p->rcmr_period = 0;
281 } 279 }
282 spin_unlock_irq(&ssc_p->lock); 280 spin_unlock_irq(&ssc_p->lock);
281
282 /* Shutdown the SSC clock. */
283 pr_debug("atmel_ssc_dai: Stopping clock\n");
284 clk_disable(ssc_p->ssc->clk);
283} 285}
284 286
285 287
@@ -348,7 +350,6 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
348 struct atmel_pcm_dma_params *dma_params; 350 struct atmel_pcm_dma_params *dma_params;
349 int dir, channels, bits; 351 int dir, channels, bits;
350 u32 tfmr, rfmr, tcmr, rcmr; 352 u32 tfmr, rfmr, tcmr, rcmr;
351 int start_event;
352 int ret; 353 int ret;
353 int fslen, fslen_ext; 354 int fslen, fslen_ext;
354 355
@@ -451,25 +452,10 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
451 break; 452 break;
452 453
453 case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM: 454 case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFM:
454 /* 455 /* I2S format, CODEC supplies BCLK and LRC clocks. */
455 * I2S format, CODEC supplies BCLK and LRC clocks.
456 *
457 * The SSC transmit clock is obtained from the BCLK signal on
458 * on the TK line, and the SSC receive clock is
459 * generated from the transmit clock.
460 *
461 * For single channel data, one sample is transferred
462 * on the falling edge of the LRC clock.
463 * For two channel data, one sample is
464 * transferred on both edges of the LRC clock.
465 */
466 start_event = ((channels == 1)
467 ? SSC_START_FALLING_RF
468 : SSC_START_EDGE_RF);
469
470 rcmr = SSC_BF(RCMR_PERIOD, 0) 456 rcmr = SSC_BF(RCMR_PERIOD, 0)
471 | SSC_BF(RCMR_STTDLY, START_DELAY) 457 | SSC_BF(RCMR_STTDLY, START_DELAY)
472 | SSC_BF(RCMR_START, start_event) 458 | SSC_BF(RCMR_START, SSC_START_FALLING_RF)
473 | SSC_BF(RCMR_CKI, SSC_CKI_RISING) 459 | SSC_BF(RCMR_CKI, SSC_CKI_RISING)
474 | SSC_BF(RCMR_CKO, SSC_CKO_NONE) 460 | SSC_BF(RCMR_CKO, SSC_CKO_NONE)
475 | SSC_BF(RCMR_CKS, ssc->clk_from_rk_pin ? 461 | SSC_BF(RCMR_CKS, ssc->clk_from_rk_pin ?
@@ -478,14 +464,14 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
478 rfmr = SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE) 464 rfmr = SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
479 | SSC_BF(RFMR_FSOS, SSC_FSOS_NONE) 465 | SSC_BF(RFMR_FSOS, SSC_FSOS_NONE)
480 | SSC_BF(RFMR_FSLEN, 0) 466 | SSC_BF(RFMR_FSLEN, 0)
481 | SSC_BF(RFMR_DATNB, 0) 467 | SSC_BF(RFMR_DATNB, (channels - 1))
482 | SSC_BIT(RFMR_MSBF) 468 | SSC_BIT(RFMR_MSBF)
483 | SSC_BF(RFMR_LOOP, 0) 469 | SSC_BF(RFMR_LOOP, 0)
484 | SSC_BF(RFMR_DATLEN, (bits - 1)); 470 | SSC_BF(RFMR_DATLEN, (bits - 1));
485 471
486 tcmr = SSC_BF(TCMR_PERIOD, 0) 472 tcmr = SSC_BF(TCMR_PERIOD, 0)
487 | SSC_BF(TCMR_STTDLY, START_DELAY) 473 | SSC_BF(TCMR_STTDLY, START_DELAY)
488 | SSC_BF(TCMR_START, start_event) 474 | SSC_BF(TCMR_START, SSC_START_FALLING_RF)
489 | SSC_BF(TCMR_CKI, SSC_CKI_FALLING) 475 | SSC_BF(TCMR_CKI, SSC_CKI_FALLING)
490 | SSC_BF(TCMR_CKO, SSC_CKO_NONE) 476 | SSC_BF(TCMR_CKO, SSC_CKO_NONE)
491 | SSC_BF(TCMR_CKS, ssc->clk_from_rk_pin ? 477 | SSC_BF(TCMR_CKS, ssc->clk_from_rk_pin ?
@@ -495,7 +481,55 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
495 | SSC_BF(TFMR_FSDEN, 0) 481 | SSC_BF(TFMR_FSDEN, 0)
496 | SSC_BF(TFMR_FSOS, SSC_FSOS_NONE) 482 | SSC_BF(TFMR_FSOS, SSC_FSOS_NONE)
497 | SSC_BF(TFMR_FSLEN, 0) 483 | SSC_BF(TFMR_FSLEN, 0)
498 | SSC_BF(TFMR_DATNB, 0) 484 | SSC_BF(TFMR_DATNB, (channels - 1))
485 | SSC_BIT(TFMR_MSBF)
486 | SSC_BF(TFMR_DATDEF, 0)
487 | SSC_BF(TFMR_DATLEN, (bits - 1));
488 break;
489
490 case SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBM_CFS:
491 /* I2S format, CODEC supplies BCLK, SSC supplies LRCLK. */
492 if (bits > 16 && !ssc->pdata->has_fslen_ext) {
493 dev_err(dai->dev,
494 "sample size %d is too large for SSC device\n",
495 bits);
496 return -EINVAL;
497 }
498
499 fslen_ext = (bits - 1) / 16;
500 fslen = (bits - 1) % 16;
501
502 rcmr = SSC_BF(RCMR_PERIOD, ssc_p->rcmr_period)
503 | SSC_BF(RCMR_STTDLY, START_DELAY)
504 | SSC_BF(RCMR_START, SSC_START_FALLING_RF)
505 | SSC_BF(RCMR_CKI, SSC_CKI_RISING)
506 | SSC_BF(RCMR_CKO, SSC_CKO_NONE)
507 | SSC_BF(RCMR_CKS, ssc->clk_from_rk_pin ?
508 SSC_CKS_PIN : SSC_CKS_CLOCK);
509
510 rfmr = SSC_BF(RFMR_FSLEN_EXT, fslen_ext)
511 | SSC_BF(RFMR_FSEDGE, SSC_FSEDGE_POSITIVE)
512 | SSC_BF(RFMR_FSOS, SSC_FSOS_NEGATIVE)
513 | SSC_BF(RFMR_FSLEN, fslen)
514 | SSC_BF(RFMR_DATNB, (channels - 1))
515 | SSC_BIT(RFMR_MSBF)
516 | SSC_BF(RFMR_LOOP, 0)
517 | SSC_BF(RFMR_DATLEN, (bits - 1));
518
519 tcmr = SSC_BF(TCMR_PERIOD, ssc_p->tcmr_period)
520 | SSC_BF(TCMR_STTDLY, START_DELAY)
521 | SSC_BF(TCMR_START, SSC_START_FALLING_RF)
522 | SSC_BF(TCMR_CKI, SSC_CKI_FALLING)
523 | SSC_BF(TCMR_CKO, SSC_CKO_NONE)
524 | SSC_BF(TCMR_CKS, ssc->clk_from_rk_pin ?
525 SSC_CKS_CLOCK : SSC_CKS_PIN);
526
527 tfmr = SSC_BF(TFMR_FSLEN_EXT, fslen_ext)
528 | SSC_BF(TFMR_FSEDGE, SSC_FSEDGE_NEGATIVE)
529 | SSC_BF(TFMR_FSDEN, 0)
530 | SSC_BF(TFMR_FSOS, SSC_FSOS_NEGATIVE)
531 | SSC_BF(TFMR_FSLEN, fslen)
532 | SSC_BF(TFMR_DATNB, (channels - 1))
499 | SSC_BIT(TFMR_MSBF) 533 | SSC_BIT(TFMR_MSBF)
500 | SSC_BF(TFMR_DATDEF, 0) 534 | SSC_BF(TFMR_DATDEF, 0)
501 | SSC_BF(TFMR_DATLEN, (bits - 1)); 535 | SSC_BF(TFMR_DATLEN, (bits - 1));
@@ -512,7 +546,7 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
512 rcmr = SSC_BF(RCMR_PERIOD, ssc_p->rcmr_period) 546 rcmr = SSC_BF(RCMR_PERIOD, ssc_p->rcmr_period)
513 | SSC_BF(RCMR_STTDLY, 1) 547 | SSC_BF(RCMR_STTDLY, 1)
514 | SSC_BF(RCMR_START, SSC_START_RISING_RF) 548 | SSC_BF(RCMR_START, SSC_START_RISING_RF)
515 | SSC_BF(RCMR_CKI, SSC_CKI_RISING) 549 | SSC_BF(RCMR_CKI, SSC_CKI_FALLING)
516 | SSC_BF(RCMR_CKO, SSC_CKO_NONE) 550 | SSC_BF(RCMR_CKO, SSC_CKO_NONE)
517 | SSC_BF(RCMR_CKS, SSC_CKS_DIV); 551 | SSC_BF(RCMR_CKS, SSC_CKS_DIV);
518 552
@@ -527,7 +561,7 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
527 tcmr = SSC_BF(TCMR_PERIOD, ssc_p->tcmr_period) 561 tcmr = SSC_BF(TCMR_PERIOD, ssc_p->tcmr_period)
528 | SSC_BF(TCMR_STTDLY, 1) 562 | SSC_BF(TCMR_STTDLY, 1)
529 | SSC_BF(TCMR_START, SSC_START_RISING_RF) 563 | SSC_BF(TCMR_START, SSC_START_RISING_RF)
530 | SSC_BF(TCMR_CKI, SSC_CKI_RISING) 564 | SSC_BF(TCMR_CKI, SSC_CKI_FALLING)
531 | SSC_BF(TCMR_CKO, SSC_CKO_CONTINUOUS) 565 | SSC_BF(TCMR_CKO, SSC_CKO_CONTINUOUS)
532 | SSC_BF(TCMR_CKS, SSC_CKS_DIV); 566 | SSC_BF(TCMR_CKS, SSC_CKS_DIV);
533 567
@@ -545,10 +579,6 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
545 /* 579 /*
546 * DSP/PCM Mode A format, CODEC supplies BCLK and LRC clocks. 580 * DSP/PCM Mode A format, CODEC supplies BCLK and LRC clocks.
547 * 581 *
548 * The SSC transmit clock is obtained from the BCLK signal on
549 * on the TK line, and the SSC receive clock is
550 * generated from the transmit clock.
551 *
552 * Data is transferred on first BCLK after LRC pulse rising 582 * Data is transferred on first BCLK after LRC pulse rising
553 * edge.If stereo, the right channel data is contiguous with 583 * edge.If stereo, the right channel data is contiguous with
554 * the left channel data. 584 * the left channel data.
@@ -556,7 +586,7 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
556 rcmr = SSC_BF(RCMR_PERIOD, 0) 586 rcmr = SSC_BF(RCMR_PERIOD, 0)
557 | SSC_BF(RCMR_STTDLY, START_DELAY) 587 | SSC_BF(RCMR_STTDLY, START_DELAY)
558 | SSC_BF(RCMR_START, SSC_START_RISING_RF) 588 | SSC_BF(RCMR_START, SSC_START_RISING_RF)
559 | SSC_BF(RCMR_CKI, SSC_CKI_RISING) 589 | SSC_BF(RCMR_CKI, SSC_CKI_FALLING)
560 | SSC_BF(RCMR_CKO, SSC_CKO_NONE) 590 | SSC_BF(RCMR_CKO, SSC_CKO_NONE)
561 | SSC_BF(RCMR_CKS, ssc->clk_from_rk_pin ? 591 | SSC_BF(RCMR_CKS, ssc->clk_from_rk_pin ?
562 SSC_CKS_PIN : SSC_CKS_CLOCK); 592 SSC_CKS_PIN : SSC_CKS_CLOCK);
@@ -597,23 +627,17 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
597 rcmr, rfmr, tcmr, tfmr); 627 rcmr, rfmr, tcmr, tfmr);
598 628
599 if (!ssc_p->initialized) { 629 if (!ssc_p->initialized) {
600 630 if (!ssc_p->ssc->pdata->use_dma) {
601 /* Enable PMC peripheral clock for this SSC */ 631 ssc_writel(ssc_p->ssc->regs, PDC_RPR, 0);
602 pr_debug("atmel_ssc_dai: Starting clock\n"); 632 ssc_writel(ssc_p->ssc->regs, PDC_RCR, 0);
603 clk_enable(ssc_p->ssc->clk); 633 ssc_writel(ssc_p->ssc->regs, PDC_RNPR, 0);
604 634 ssc_writel(ssc_p->ssc->regs, PDC_RNCR, 0);
605 /* Reset the SSC and its PDC registers */ 635
606 ssc_writel(ssc_p->ssc->regs, CR, SSC_BIT(CR_SWRST)); 636 ssc_writel(ssc_p->ssc->regs, PDC_TPR, 0);
607 637 ssc_writel(ssc_p->ssc->regs, PDC_TCR, 0);
608 ssc_writel(ssc_p->ssc->regs, PDC_RPR, 0); 638 ssc_writel(ssc_p->ssc->regs, PDC_TNPR, 0);
609 ssc_writel(ssc_p->ssc->regs, PDC_RCR, 0); 639 ssc_writel(ssc_p->ssc->regs, PDC_TNCR, 0);
610 ssc_writel(ssc_p->ssc->regs, PDC_RNPR, 0); 640 }
611 ssc_writel(ssc_p->ssc->regs, PDC_RNCR, 0);
612
613 ssc_writel(ssc_p->ssc->regs, PDC_TPR, 0);
614 ssc_writel(ssc_p->ssc->regs, PDC_TCR, 0);
615 ssc_writel(ssc_p->ssc->regs, PDC_TNPR, 0);
616 ssc_writel(ssc_p->ssc->regs, PDC_TNCR, 0);
617 641
618 ret = request_irq(ssc_p->ssc->irq, atmel_ssc_interrupt, 0, 642 ret = request_irq(ssc_p->ssc->irq, atmel_ssc_interrupt, 0,
619 ssc_p->name, ssc_p); 643 ssc_p->name, ssc_p);
diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c
index 66b66d0e7514..f5ad214663f9 100644
--- a/sound/soc/atmel/sam9g20_wm8731.c
+++ b/sound/soc/atmel/sam9g20_wm8731.c
@@ -47,7 +47,6 @@
47#include <sound/soc.h> 47#include <sound/soc.h>
48 48
49#include <asm/mach-types.h> 49#include <asm/mach-types.h>
50#include <mach/hardware.h>
51 50
52#include "../codecs/wm8731.h" 51#include "../codecs/wm8731.h"
53#include "atmel-pcm.h" 52#include "atmel-pcm.h"
@@ -64,33 +63,6 @@
64 63
65static struct clk *mclk; 64static struct clk *mclk;
66 65
67static int at91sam9g20ek_hw_params(struct snd_pcm_substream *substream,
68 struct snd_pcm_hw_params *params)
69{
70 struct snd_soc_pcm_runtime *rtd = substream->private_data;
71 struct snd_soc_dai *codec_dai = rtd->codec_dai;
72 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
73 int ret;
74
75 /* set codec DAI configuration */
76 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
77 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
78 if (ret < 0)
79 return ret;
80
81 /* set cpu DAI configuration */
82 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
83 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
84 if (ret < 0)
85 return ret;
86
87 return 0;
88}
89
90static struct snd_soc_ops at91sam9g20ek_ops = {
91 .hw_params = at91sam9g20ek_hw_params,
92};
93
94static int at91sam9g20ek_set_bias_level(struct snd_soc_card *card, 66static int at91sam9g20ek_set_bias_level(struct snd_soc_card *card,
95 struct snd_soc_dapm_context *dapm, 67 struct snd_soc_dapm_context *dapm,
96 enum snd_soc_bias_level level) 68 enum snd_soc_bias_level level)
@@ -173,7 +145,8 @@ static struct snd_soc_dai_link at91sam9g20ek_dai = {
173 .init = at91sam9g20ek_wm8731_init, 145 .init = at91sam9g20ek_wm8731_init,
174 .platform_name = "at91rm9200_ssc.0", 146 .platform_name = "at91rm9200_ssc.0",
175 .codec_name = "wm8731.0-001b", 147 .codec_name = "wm8731.0-001b",
176 .ops = &at91sam9g20ek_ops, 148 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
149 SND_SOC_DAIFMT_CBM_CFM,
177}; 150};
178 151
179static struct snd_soc_card snd_soc_at91sam9g20ek = { 152static struct snd_soc_card snd_soc_at91sam9g20ek = {
diff --git a/sound/soc/au1x/db1200.c b/sound/soc/au1x/db1200.c
index a747ac0b399f..c75995f2779c 100644
--- a/sound/soc/au1x/db1200.c
+++ b/sound/soc/au1x/db1200.c
@@ -91,27 +91,12 @@ static int db1200_i2s_startup(struct snd_pcm_substream *substream)
91{ 91{
92 struct snd_soc_pcm_runtime *rtd = substream->private_data; 92 struct snd_soc_pcm_runtime *rtd = substream->private_data;
93 struct snd_soc_dai *codec_dai = rtd->codec_dai; 93 struct snd_soc_dai *codec_dai = rtd->codec_dai;
94 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
95 int ret;
96 94
97 /* WM8731 has its own 12MHz crystal */ 95 /* WM8731 has its own 12MHz crystal */
98 snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL, 96 snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
99 12000000, SND_SOC_CLOCK_IN); 97 12000000, SND_SOC_CLOCK_IN);
100 98
101 /* codec is bitclock and lrclk master */ 99 return 0;
102 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_LEFT_J |
103 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
104 if (ret < 0)
105 goto out;
106
107 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_LEFT_J |
108 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
109 if (ret < 0)
110 goto out;
111
112 ret = 0;
113out:
114 return ret;
115} 100}
116 101
117static struct snd_soc_ops db1200_i2s_wm8731_ops = { 102static struct snd_soc_ops db1200_i2s_wm8731_ops = {
@@ -125,6 +110,8 @@ static struct snd_soc_dai_link db1200_i2s_dai = {
125 .cpu_dai_name = "au1xpsc_i2s.1", 110 .cpu_dai_name = "au1xpsc_i2s.1",
126 .platform_name = "au1xpsc-pcm.1", 111 .platform_name = "au1xpsc-pcm.1",
127 .codec_name = "wm8731.0-001b", 112 .codec_name = "wm8731.0-001b",
113 .dai_fmt = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF |
114 SND_SOC_DAIFMT_CBM_CFM,
128 .ops = &db1200_i2s_wm8731_ops, 115 .ops = &db1200_i2s_wm8731_ops,
129}; 116};
130 117
diff --git a/sound/soc/au1x/dbdma2.c b/sound/soc/au1x/dbdma2.c
index b06b8d8128c6..dd94fea72d5d 100644
--- a/sound/soc/au1x/dbdma2.c
+++ b/sound/soc/au1x/dbdma2.c
@@ -315,11 +315,6 @@ static struct snd_pcm_ops au1xpsc_pcm_ops = {
315 .pointer = au1xpsc_pcm_pointer, 315 .pointer = au1xpsc_pcm_pointer,
316}; 316};
317 317
318static void au1xpsc_pcm_free_dma_buffers(struct snd_pcm *pcm)
319{
320 snd_pcm_lib_preallocate_free_for_all(pcm);
321}
322
323static int au1xpsc_pcm_new(struct snd_soc_pcm_runtime *rtd) 318static int au1xpsc_pcm_new(struct snd_soc_pcm_runtime *rtd)
324{ 319{
325 struct snd_card *card = rtd->card->snd_card; 320 struct snd_card *card = rtd->card->snd_card;
@@ -335,7 +330,6 @@ static int au1xpsc_pcm_new(struct snd_soc_pcm_runtime *rtd)
335static struct snd_soc_platform_driver au1xpsc_soc_platform = { 330static struct snd_soc_platform_driver au1xpsc_soc_platform = {
336 .ops = &au1xpsc_pcm_ops, 331 .ops = &au1xpsc_pcm_ops,
337 .pcm_new = au1xpsc_pcm_new, 332 .pcm_new = au1xpsc_pcm_new,
338 .pcm_free = au1xpsc_pcm_free_dma_buffers,
339}; 333};
340 334
341static int au1xpsc_pcm_drvprobe(struct platform_device *pdev) 335static int au1xpsc_pcm_drvprobe(struct platform_device *pdev)
diff --git a/sound/soc/au1x/dma.c b/sound/soc/au1x/dma.c
index 6ffaaff469c7..24cc7f40d87a 100644
--- a/sound/soc/au1x/dma.c
+++ b/sound/soc/au1x/dma.c
@@ -287,11 +287,6 @@ static struct snd_pcm_ops alchemy_pcm_ops = {
287 .pointer = alchemy_pcm_pointer, 287 .pointer = alchemy_pcm_pointer,
288}; 288};
289 289
290static void alchemy_pcm_free_dma_buffers(struct snd_pcm *pcm)
291{
292 snd_pcm_lib_preallocate_free_for_all(pcm);
293}
294
295static int alchemy_pcm_new(struct snd_soc_pcm_runtime *rtd) 290static int alchemy_pcm_new(struct snd_soc_pcm_runtime *rtd)
296{ 291{
297 struct snd_pcm *pcm = rtd->pcm; 292 struct snd_pcm *pcm = rtd->pcm;
@@ -305,7 +300,6 @@ static int alchemy_pcm_new(struct snd_soc_pcm_runtime *rtd)
305static struct snd_soc_platform_driver alchemy_pcm_soc_platform = { 300static struct snd_soc_platform_driver alchemy_pcm_soc_platform = {
306 .ops = &alchemy_pcm_ops, 301 .ops = &alchemy_pcm_ops,
307 .pcm_new = alchemy_pcm_new, 302 .pcm_new = alchemy_pcm_new,
308 .pcm_free = alchemy_pcm_free_dma_buffers,
309}; 303};
310 304
311static int alchemy_pcm_drvprobe(struct platform_device *pdev) 305static int alchemy_pcm_drvprobe(struct platform_device *pdev)
diff --git a/sound/soc/codecs/88pm860x-codec.c b/sound/soc/codecs/88pm860x-codec.c
index a2bf27f4baab..a0f265327fdf 100644
--- a/sound/soc/codecs/88pm860x-codec.c
+++ b/sound/soc/codecs/88pm860x-codec.c
@@ -386,7 +386,7 @@ static int snd_soc_put_volsw_2r_out(struct snd_kcontrol *kcontrol,
386static int pm860x_rsync_event(struct snd_soc_dapm_widget *w, 386static int pm860x_rsync_event(struct snd_soc_dapm_widget *w,
387 struct snd_kcontrol *kcontrol, int event) 387 struct snd_kcontrol *kcontrol, int event)
388{ 388{
389 struct snd_soc_codec *codec = w->codec; 389 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
390 390
391 /* 391 /*
392 * In order to avoid current on the load, mute power-on and power-off 392 * In order to avoid current on the load, mute power-on and power-off
@@ -403,7 +403,7 @@ static int pm860x_rsync_event(struct snd_soc_dapm_widget *w,
403static int pm860x_dac_event(struct snd_soc_dapm_widget *w, 403static int pm860x_dac_event(struct snd_soc_dapm_widget *w,
404 struct snd_kcontrol *kcontrol, int event) 404 struct snd_kcontrol *kcontrol, int event)
405{ 405{
406 struct snd_soc_codec *codec = w->codec; 406 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
407 unsigned int dac = 0; 407 unsigned int dac = 0;
408 int data; 408 int data;
409 409
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 8349f982a586..3190eed43c38 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -525,7 +525,7 @@ config SND_SOC_RT5677
525 525
526config SND_SOC_RT5677_SPI 526config SND_SOC_RT5677_SPI
527 tristate 527 tristate
528 default SND_SOC_RT5677 528 default SND_SOC_RT5677 && SPI
529 529
530#Freescale sgtl5000 codec 530#Freescale sgtl5000 codec
531config SND_SOC_SGTL5000 531config SND_SOC_SGTL5000
@@ -580,7 +580,9 @@ config SND_SOC_SSM4567
580 depends on I2C 580 depends on I2C
581 581
582config SND_SOC_STA32X 582config SND_SOC_STA32X
583 tristate 583 tristate "STA326, STA328 and STA329 speaker amplifier"
584 depends on I2C
585 select REGMAP_I2C
584 586
585config SND_SOC_STA350 587config SND_SOC_STA350
586 tristate "STA350 speaker amplifier" 588 tristate "STA350 speaker amplifier"
diff --git a/sound/soc/codecs/ad193x.c b/sound/soc/codecs/ad193x.c
index 387530b0b0fd..17c953595660 100644
--- a/sound/soc/codecs/ad193x.c
+++ b/sound/soc/codecs/ad193x.c
@@ -333,8 +333,8 @@ static int ad193x_codec_probe(struct snd_soc_codec *codec)
333 regmap_write(ad193x->regmap, AD193X_DAC_CHNL_MUTE, 0x0); 333 regmap_write(ad193x->regmap, AD193X_DAC_CHNL_MUTE, 0x0);
334 /* de-emphasis: 48kHz, powedown dac */ 334 /* de-emphasis: 48kHz, powedown dac */
335 regmap_write(ad193x->regmap, AD193X_DAC_CTRL2, 0x1A); 335 regmap_write(ad193x->regmap, AD193X_DAC_CTRL2, 0x1A);
336 /* powerdown dac, dac in tdm mode */ 336 /* dac in tdm mode */
337 regmap_write(ad193x->regmap, AD193X_DAC_CTRL0, 0x41); 337 regmap_write(ad193x->regmap, AD193X_DAC_CTRL0, 0x40);
338 /* high-pass filter enable */ 338 /* high-pass filter enable */
339 regmap_write(ad193x->regmap, AD193X_ADC_CTRL0, 0x3); 339 regmap_write(ad193x->regmap, AD193X_ADC_CTRL0, 0x3);
340 /* sata delay=1, adc aux mode */ 340 /* sata delay=1, adc aux mode */
diff --git a/sound/soc/codecs/ak4671.c b/sound/soc/codecs/ak4671.c
index 686cacb0e835..632e89f793a7 100644
--- a/sound/soc/codecs/ak4671.c
+++ b/sound/soc/codecs/ak4671.c
@@ -163,7 +163,7 @@ static const struct snd_kcontrol_new ak4671_snd_controls[] = {
163static int ak4671_out2_event(struct snd_soc_dapm_widget *w, 163static int ak4671_out2_event(struct snd_soc_dapm_widget *w,
164 struct snd_kcontrol *kcontrol, int event) 164 struct snd_kcontrol *kcontrol, int event)
165{ 165{
166 struct snd_soc_codec *codec = w->codec; 166 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
167 167
168 switch (event) { 168 switch (event) {
169 case SND_SOC_DAPM_POST_PMU: 169 case SND_SOC_DAPM_POST_PMU:
diff --git a/sound/soc/codecs/alc5623.c b/sound/soc/codecs/alc5623.c
index bdf8c5ac8ca4..0e357996864b 100644
--- a/sound/soc/codecs/alc5623.c
+++ b/sound/soc/codecs/alc5623.c
@@ -55,18 +55,20 @@ static inline int alc5623_reset(struct snd_soc_codec *codec)
55static int amp_mixer_event(struct snd_soc_dapm_widget *w, 55static int amp_mixer_event(struct snd_soc_dapm_widget *w,
56 struct snd_kcontrol *kcontrol, int event) 56 struct snd_kcontrol *kcontrol, int event)
57{ 57{
58 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
59
58 /* to power-on/off class-d amp generators/speaker */ 60 /* to power-on/off class-d amp generators/speaker */
59 /* need to write to 'index-46h' register : */ 61 /* need to write to 'index-46h' register : */
60 /* so write index num (here 0x46) to reg 0x6a */ 62 /* so write index num (here 0x46) to reg 0x6a */
61 /* and then 0xffff/0 to reg 0x6c */ 63 /* and then 0xffff/0 to reg 0x6c */
62 snd_soc_write(w->codec, ALC5623_HID_CTRL_INDEX, 0x46); 64 snd_soc_write(codec, ALC5623_HID_CTRL_INDEX, 0x46);
63 65
64 switch (event) { 66 switch (event) {
65 case SND_SOC_DAPM_PRE_PMU: 67 case SND_SOC_DAPM_PRE_PMU:
66 snd_soc_write(w->codec, ALC5623_HID_CTRL_DATA, 0xFFFF); 68 snd_soc_write(codec, ALC5623_HID_CTRL_DATA, 0xFFFF);
67 break; 69 break;
68 case SND_SOC_DAPM_POST_PMD: 70 case SND_SOC_DAPM_POST_PMD:
69 snd_soc_write(w->codec, ALC5623_HID_CTRL_DATA, 0); 71 snd_soc_write(codec, ALC5623_HID_CTRL_DATA, 0);
70 break; 72 break;
71 } 73 }
72 74
diff --git a/sound/soc/codecs/alc5632.c b/sound/soc/codecs/alc5632.c
index d1fdbc266631..db3283abbe18 100644
--- a/sound/soc/codecs/alc5632.c
+++ b/sound/soc/codecs/alc5632.c
@@ -116,18 +116,20 @@ static inline int alc5632_reset(struct regmap *map)
116static int amp_mixer_event(struct snd_soc_dapm_widget *w, 116static int amp_mixer_event(struct snd_soc_dapm_widget *w,
117 struct snd_kcontrol *kcontrol, int event) 117 struct snd_kcontrol *kcontrol, int event)
118{ 118{
119 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
120
119 /* to power-on/off class-d amp generators/speaker */ 121 /* to power-on/off class-d amp generators/speaker */
120 /* need to write to 'index-46h' register : */ 122 /* need to write to 'index-46h' register : */
121 /* so write index num (here 0x46) to reg 0x6a */ 123 /* so write index num (here 0x46) to reg 0x6a */
122 /* and then 0xffff/0 to reg 0x6c */ 124 /* and then 0xffff/0 to reg 0x6c */
123 snd_soc_write(w->codec, ALC5632_HID_CTRL_INDEX, 0x46); 125 snd_soc_write(codec, ALC5632_HID_CTRL_INDEX, 0x46);
124 126
125 switch (event) { 127 switch (event) {
126 case SND_SOC_DAPM_PRE_PMU: 128 case SND_SOC_DAPM_PRE_PMU:
127 snd_soc_write(w->codec, ALC5632_HID_CTRL_DATA, 0xFFFF); 129 snd_soc_write(codec, ALC5632_HID_CTRL_DATA, 0xFFFF);
128 break; 130 break;
129 case SND_SOC_DAPM_POST_PMD: 131 case SND_SOC_DAPM_POST_PMD:
130 snd_soc_write(w->codec, ALC5632_HID_CTRL_DATA, 0); 132 snd_soc_write(codec, ALC5632_HID_CTRL_DATA, 0);
131 break; 133 break;
132 } 134 }
133 135
@@ -1066,7 +1068,7 @@ static int alc5632_probe(struct snd_soc_codec *codec)
1066 return 0; 1068 return 0;
1067} 1069}
1068 1070
1069static struct snd_soc_codec_driver soc_codec_device_alc5632 = { 1071static const struct snd_soc_codec_driver soc_codec_device_alc5632 = {
1070 .probe = alc5632_probe, 1072 .probe = alc5632_probe,
1071 .resume = alc5632_resume, 1073 .resume = alc5632_resume,
1072 .set_bias_level = alc5632_set_bias_level, 1074 .set_bias_level = alc5632_set_bias_level,
@@ -1080,7 +1082,7 @@ static struct snd_soc_codec_driver soc_codec_device_alc5632 = {
1080 .num_dapm_routes = ARRAY_SIZE(alc5632_dapm_routes), 1082 .num_dapm_routes = ARRAY_SIZE(alc5632_dapm_routes),
1081}; 1083};
1082 1084
1083static struct regmap_config alc5632_regmap = { 1085static const struct regmap_config alc5632_regmap = {
1084 .reg_bits = 8, 1086 .reg_bits = 8,
1085 .val_bits = 16, 1087 .val_bits = 16,
1086 1088
diff --git a/sound/soc/codecs/arizona.c b/sound/soc/codecs/arizona.c
index 9550d7433ad0..29202610dd0d 100644
--- a/sound/soc/codecs/arizona.c
+++ b/sound/soc/codecs/arizona.c
@@ -84,7 +84,7 @@ static int arizona_spk_ev(struct snd_soc_dapm_widget *w,
84 struct snd_kcontrol *kcontrol, 84 struct snd_kcontrol *kcontrol,
85 int event) 85 int event)
86{ 86{
87 struct snd_soc_codec *codec = w->codec; 87 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
88 struct arizona *arizona = dev_get_drvdata(codec->dev->parent); 88 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
89 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec); 89 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
90 bool manual_ena = false; 90 bool manual_ena = false;
@@ -692,7 +692,8 @@ static void arizona_in_set_vu(struct snd_soc_codec *codec, int ena)
692int arizona_in_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, 692int arizona_in_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol,
693 int event) 693 int event)
694{ 694{
695 struct arizona_priv *priv = snd_soc_codec_get_drvdata(w->codec); 695 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
696 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
696 unsigned int reg; 697 unsigned int reg;
697 698
698 if (w->shift % 2) 699 if (w->shift % 2)
@@ -705,25 +706,25 @@ int arizona_in_ev(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol,
705 priv->in_pending++; 706 priv->in_pending++;
706 break; 707 break;
707 case SND_SOC_DAPM_POST_PMU: 708 case SND_SOC_DAPM_POST_PMU:
708 snd_soc_update_bits(w->codec, reg, ARIZONA_IN1L_MUTE, 0); 709 snd_soc_update_bits(codec, reg, ARIZONA_IN1L_MUTE, 0);
709 710
710 /* If this is the last input pending then allow VU */ 711 /* If this is the last input pending then allow VU */
711 priv->in_pending--; 712 priv->in_pending--;
712 if (priv->in_pending == 0) { 713 if (priv->in_pending == 0) {
713 msleep(1); 714 msleep(1);
714 arizona_in_set_vu(w->codec, 1); 715 arizona_in_set_vu(codec, 1);
715 } 716 }
716 break; 717 break;
717 case SND_SOC_DAPM_PRE_PMD: 718 case SND_SOC_DAPM_PRE_PMD:
718 snd_soc_update_bits(w->codec, reg, 719 snd_soc_update_bits(codec, reg,
719 ARIZONA_IN1L_MUTE | ARIZONA_IN_VU, 720 ARIZONA_IN1L_MUTE | ARIZONA_IN_VU,
720 ARIZONA_IN1L_MUTE | ARIZONA_IN_VU); 721 ARIZONA_IN1L_MUTE | ARIZONA_IN_VU);
721 break; 722 break;
722 case SND_SOC_DAPM_POST_PMD: 723 case SND_SOC_DAPM_POST_PMD:
723 /* Disable volume updates if no inputs are enabled */ 724 /* Disable volume updates if no inputs are enabled */
724 reg = snd_soc_read(w->codec, ARIZONA_INPUT_ENABLES); 725 reg = snd_soc_read(codec, ARIZONA_INPUT_ENABLES);
725 if (reg == 0) 726 if (reg == 0)
726 arizona_in_set_vu(w->codec, 0); 727 arizona_in_set_vu(codec, 0);
727 } 728 }
728 729
729 return 0; 730 return 0;
@@ -734,7 +735,25 @@ int arizona_out_ev(struct snd_soc_dapm_widget *w,
734 struct snd_kcontrol *kcontrol, 735 struct snd_kcontrol *kcontrol,
735 int event) 736 int event)
736{ 737{
738 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
739 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
740
737 switch (event) { 741 switch (event) {
742 case SND_SOC_DAPM_PRE_PMU:
743 switch (w->shift) {
744 case ARIZONA_OUT1L_ENA_SHIFT:
745 case ARIZONA_OUT1R_ENA_SHIFT:
746 case ARIZONA_OUT2L_ENA_SHIFT:
747 case ARIZONA_OUT2R_ENA_SHIFT:
748 case ARIZONA_OUT3L_ENA_SHIFT:
749 case ARIZONA_OUT3R_ENA_SHIFT:
750 priv->out_up_pending++;
751 priv->out_up_delay += 17;
752 break;
753 default:
754 break;
755 }
756 break;
738 case SND_SOC_DAPM_POST_PMU: 757 case SND_SOC_DAPM_POST_PMU:
739 switch (w->shift) { 758 switch (w->shift) {
740 case ARIZONA_OUT1L_ENA_SHIFT: 759 case ARIZONA_OUT1L_ENA_SHIFT:
@@ -743,13 +762,50 @@ int arizona_out_ev(struct snd_soc_dapm_widget *w,
743 case ARIZONA_OUT2R_ENA_SHIFT: 762 case ARIZONA_OUT2R_ENA_SHIFT:
744 case ARIZONA_OUT3L_ENA_SHIFT: 763 case ARIZONA_OUT3L_ENA_SHIFT:
745 case ARIZONA_OUT3R_ENA_SHIFT: 764 case ARIZONA_OUT3R_ENA_SHIFT:
746 msleep(17); 765 priv->out_up_pending--;
766 if (!priv->out_up_pending) {
767 msleep(priv->out_up_delay);
768 priv->out_up_delay = 0;
769 }
747 break; 770 break;
748 771
749 default: 772 default:
750 break; 773 break;
751 } 774 }
752 break; 775 break;
776 case SND_SOC_DAPM_PRE_PMD:
777 switch (w->shift) {
778 case ARIZONA_OUT1L_ENA_SHIFT:
779 case ARIZONA_OUT1R_ENA_SHIFT:
780 case ARIZONA_OUT2L_ENA_SHIFT:
781 case ARIZONA_OUT2R_ENA_SHIFT:
782 case ARIZONA_OUT3L_ENA_SHIFT:
783 case ARIZONA_OUT3R_ENA_SHIFT:
784 priv->out_down_pending++;
785 priv->out_down_delay++;
786 break;
787 default:
788 break;
789 }
790 break;
791 case SND_SOC_DAPM_POST_PMD:
792 switch (w->shift) {
793 case ARIZONA_OUT1L_ENA_SHIFT:
794 case ARIZONA_OUT1R_ENA_SHIFT:
795 case ARIZONA_OUT2L_ENA_SHIFT:
796 case ARIZONA_OUT2R_ENA_SHIFT:
797 case ARIZONA_OUT3L_ENA_SHIFT:
798 case ARIZONA_OUT3R_ENA_SHIFT:
799 priv->out_down_pending--;
800 if (!priv->out_down_pending) {
801 msleep(priv->out_down_delay);
802 priv->out_down_delay = 0;
803 }
804 break;
805 default:
806 break;
807 }
808 break;
753 } 809 }
754 810
755 return 0; 811 return 0;
@@ -760,7 +816,8 @@ int arizona_hp_ev(struct snd_soc_dapm_widget *w,
760 struct snd_kcontrol *kcontrol, 816 struct snd_kcontrol *kcontrol,
761 int event) 817 int event)
762{ 818{
763 struct arizona_priv *priv = snd_soc_codec_get_drvdata(w->codec); 819 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
820 struct arizona_priv *priv = snd_soc_codec_get_drvdata(codec);
764 struct arizona *arizona = priv->arizona; 821 struct arizona *arizona = priv->arizona;
765 unsigned int mask = 1 << w->shift; 822 unsigned int mask = 1 << w->shift;
766 unsigned int val; 823 unsigned int val;
@@ -772,6 +829,9 @@ int arizona_hp_ev(struct snd_soc_dapm_widget *w,
772 case SND_SOC_DAPM_PRE_PMD: 829 case SND_SOC_DAPM_PRE_PMD:
773 val = 0; 830 val = 0;
774 break; 831 break;
832 case SND_SOC_DAPM_PRE_PMU:
833 case SND_SOC_DAPM_POST_PMD:
834 return arizona_out_ev(w, kcontrol, event);
775 default: 835 default:
776 return -EINVAL; 836 return -EINVAL;
777 } 837 }
diff --git a/sound/soc/codecs/arizona.h b/sound/soc/codecs/arizona.h
index 942cfb197b6d..11ff899b0272 100644
--- a/sound/soc/codecs/arizona.h
+++ b/sound/soc/codecs/arizona.h
@@ -77,6 +77,11 @@ struct arizona_priv {
77 int num_inputs; 77 int num_inputs;
78 unsigned int in_pending; 78 unsigned int in_pending;
79 79
80 unsigned int out_up_pending;
81 unsigned int out_up_delay;
82 unsigned int out_down_pending;
83 unsigned int out_down_delay;
84
80 unsigned int spk_ena:2; 85 unsigned int spk_ena:2;
81 unsigned int spk_ena_pending:1; 86 unsigned int spk_ena_pending:1;
82}; 87};
diff --git a/sound/soc/codecs/bt-sco.c b/sound/soc/codecs/bt-sco.c
index 5075bf0a7276..e7238b8904bc 100644
--- a/sound/soc/codecs/bt-sco.c
+++ b/sound/soc/codecs/bt-sco.c
@@ -86,5 +86,5 @@ static struct platform_driver bt_sco_driver = {
86module_platform_driver(bt_sco_driver); 86module_platform_driver(bt_sco_driver);
87 87
88MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); 88MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
89MODULE_DESCRIPTION("ASoC generic bluethooth sco link driver"); 89MODULE_DESCRIPTION("ASoC generic bluetooth sco link driver");
90MODULE_LICENSE("GPL"); 90MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cs35l32.c b/sound/soc/codecs/cs35l32.c
index ec55c590afd0..f2b8aad21274 100644
--- a/sound/soc/codecs/cs35l32.c
+++ b/sound/soc/codecs/cs35l32.c
@@ -264,7 +264,7 @@ static int cs35l32_codec_set_sysclk(struct snd_soc_codec *codec,
264 CS35L32_MCLK_DIV2_MASK | CS35L32_MCLK_RATIO_MASK, val); 264 CS35L32_MCLK_DIV2_MASK | CS35L32_MCLK_RATIO_MASK, val);
265} 265}
266 266
267static struct snd_soc_codec_driver soc_codec_dev_cs35l32 = { 267static const struct snd_soc_codec_driver soc_codec_dev_cs35l32 = {
268 .set_sysclk = cs35l32_codec_set_sysclk, 268 .set_sysclk = cs35l32_codec_set_sysclk,
269 269
270 .dapm_widgets = cs35l32_dapm_widgets, 270 .dapm_widgets = cs35l32_dapm_widgets,
@@ -288,7 +288,7 @@ static const struct reg_default cs35l32_monitor_patch[] = {
288 { 0x00, 0x00 }, 288 { 0x00, 0x00 },
289}; 289};
290 290
291static struct regmap_config cs35l32_regmap = { 291static const struct regmap_config cs35l32_regmap = {
292 .reg_bits = 8, 292 .reg_bits = 8,
293 .val_bits = 8, 293 .val_bits = 8,
294 294
diff --git a/sound/soc/codecs/cs42l52.c b/sound/soc/codecs/cs42l52.c
index 35fbef743fbe..1589e7a881d8 100644
--- a/sound/soc/codecs/cs42l52.c
+++ b/sound/soc/codecs/cs42l52.c
@@ -1103,7 +1103,7 @@ static int cs42l52_remove(struct snd_soc_codec *codec)
1103 return 0; 1103 return 0;
1104} 1104}
1105 1105
1106static struct snd_soc_codec_driver soc_codec_dev_cs42l52 = { 1106static const struct snd_soc_codec_driver soc_codec_dev_cs42l52 = {
1107 .probe = cs42l52_probe, 1107 .probe = cs42l52_probe,
1108 .remove = cs42l52_remove, 1108 .remove = cs42l52_remove,
1109 .set_bias_level = cs42l52_set_bias_level, 1109 .set_bias_level = cs42l52_set_bias_level,
@@ -1130,7 +1130,7 @@ static const struct reg_default cs42l52_threshold_patch[] = {
1130 1130
1131}; 1131};
1132 1132
1133static struct regmap_config cs42l52_regmap = { 1133static const struct regmap_config cs42l52_regmap = {
1134 .reg_bits = 8, 1134 .reg_bits = 8,
1135 .val_bits = 8, 1135 .val_bits = 8,
1136 1136
diff --git a/sound/soc/codecs/cs42l56.c b/sound/soc/codecs/cs42l56.c
index 2ddc7ac10ad7..cbc654fe48c7 100644
--- a/sound/soc/codecs/cs42l56.c
+++ b/sound/soc/codecs/cs42l56.c
@@ -1164,7 +1164,7 @@ static int cs42l56_remove(struct snd_soc_codec *codec)
1164 return 0; 1164 return 0;
1165} 1165}
1166 1166
1167static struct snd_soc_codec_driver soc_codec_dev_cs42l56 = { 1167static const struct snd_soc_codec_driver soc_codec_dev_cs42l56 = {
1168 .probe = cs42l56_probe, 1168 .probe = cs42l56_probe,
1169 .remove = cs42l56_remove, 1169 .remove = cs42l56_remove,
1170 .set_bias_level = cs42l56_set_bias_level, 1170 .set_bias_level = cs42l56_set_bias_level,
@@ -1179,7 +1179,7 @@ static struct snd_soc_codec_driver soc_codec_dev_cs42l56 = {
1179 .num_controls = ARRAY_SIZE(cs42l56_snd_controls), 1179 .num_controls = ARRAY_SIZE(cs42l56_snd_controls),
1180}; 1180};
1181 1181
1182static struct regmap_config cs42l56_regmap = { 1182static const struct regmap_config cs42l56_regmap = {
1183 .reg_bits = 8, 1183 .reg_bits = 8,
1184 .val_bits = 8, 1184 .val_bits = 8,
1185 1185
diff --git a/sound/soc/codecs/cs42l73.c b/sound/soc/codecs/cs42l73.c
index 7c55537c69cf..8ecedba79606 100644
--- a/sound/soc/codecs/cs42l73.c
+++ b/sound/soc/codecs/cs42l73.c
@@ -1347,7 +1347,7 @@ static int cs42l73_probe(struct snd_soc_codec *codec)
1347 return 0; 1347 return 0;
1348} 1348}
1349 1349
1350static struct snd_soc_codec_driver soc_codec_dev_cs42l73 = { 1350static const struct snd_soc_codec_driver soc_codec_dev_cs42l73 = {
1351 .probe = cs42l73_probe, 1351 .probe = cs42l73_probe,
1352 .set_bias_level = cs42l73_set_bias_level, 1352 .set_bias_level = cs42l73_set_bias_level,
1353 .suspend_bias_off = true, 1353 .suspend_bias_off = true,
@@ -1361,7 +1361,7 @@ static struct snd_soc_codec_driver soc_codec_dev_cs42l73 = {
1361 .num_controls = ARRAY_SIZE(cs42l73_snd_controls), 1361 .num_controls = ARRAY_SIZE(cs42l73_snd_controls),
1362}; 1362};
1363 1363
1364static struct regmap_config cs42l73_regmap = { 1364static const struct regmap_config cs42l73_regmap = {
1365 .reg_bits = 8, 1365 .reg_bits = 8,
1366 .val_bits = 8, 1366 .val_bits = 8,
1367 1367
diff --git a/sound/soc/codecs/da732x.c b/sound/soc/codecs/da732x.c
index 61b2f9a2eef1..ffe96175a8a5 100644
--- a/sound/soc/codecs/da732x.c
+++ b/sound/soc/codecs/da732x.c
@@ -609,7 +609,7 @@ static const struct snd_kcontrol_new da732x_snd_controls[] = {
609static int da732x_adc_event(struct snd_soc_dapm_widget *w, 609static int da732x_adc_event(struct snd_soc_dapm_widget *w,
610 struct snd_kcontrol *kcontrol, int event) 610 struct snd_kcontrol *kcontrol, int event)
611{ 611{
612 struct snd_soc_codec *codec = w->codec; 612 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
613 613
614 switch (event) { 614 switch (event) {
615 case SND_SOC_DAPM_POST_PMU: 615 case SND_SOC_DAPM_POST_PMU:
@@ -663,7 +663,7 @@ static int da732x_adc_event(struct snd_soc_dapm_widget *w,
663static int da732x_out_pga_event(struct snd_soc_dapm_widget *w, 663static int da732x_out_pga_event(struct snd_soc_dapm_widget *w,
664 struct snd_kcontrol *kcontrol, int event) 664 struct snd_kcontrol *kcontrol, int event)
665{ 665{
666 struct snd_soc_codec *codec = w->codec; 666 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
667 667
668 switch (event) { 668 switch (event) {
669 case SND_SOC_DAPM_POST_PMU: 669 case SND_SOC_DAPM_POST_PMU:
diff --git a/sound/soc/codecs/mc13783.c b/sound/soc/codecs/mc13783.c
index c1e441c2c8af..2ffb9a0570dc 100644
--- a/sound/soc/codecs/mc13783.c
+++ b/sound/soc/codecs/mc13783.c
@@ -328,16 +328,16 @@ static int mc13783_set_tdm_slot_dac(struct snd_soc_dai *dai,
328 } 328 }
329 329
330 switch (rx_mask) { 330 switch (rx_mask) {
331 case 0xfffffffc: 331 case 0x03:
332 val |= SSI_NETWORK_DAC_RXSLOT_0_1; 332 val |= SSI_NETWORK_DAC_RXSLOT_0_1;
333 break; 333 break;
334 case 0xfffffff3: 334 case 0x0c:
335 val |= SSI_NETWORK_DAC_RXSLOT_2_3; 335 val |= SSI_NETWORK_DAC_RXSLOT_2_3;
336 break; 336 break;
337 case 0xffffffcf: 337 case 0x30:
338 val |= SSI_NETWORK_DAC_RXSLOT_4_5; 338 val |= SSI_NETWORK_DAC_RXSLOT_4_5;
339 break; 339 break;
340 case 0xffffff3f: 340 case 0xc0:
341 val |= SSI_NETWORK_DAC_RXSLOT_6_7; 341 val |= SSI_NETWORK_DAC_RXSLOT_6_7;
342 break; 342 break;
343 default: 343 default:
@@ -360,7 +360,7 @@ static int mc13783_set_tdm_slot_codec(struct snd_soc_dai *dai,
360 if (slots != 4) 360 if (slots != 4)
361 return -EINVAL; 361 return -EINVAL;
362 362
363 if (tx_mask != 0xfffffffc) 363 if (tx_mask != 0x3)
364 return -EINVAL; 364 return -EINVAL;
365 365
366 val |= (0x00 << 2); /* primary timeslot RX/TX(?) is 0 */ 366 val |= (0x00 << 2); /* primary timeslot RX/TX(?) is 0 */
diff --git a/sound/soc/codecs/pcm3008.c b/sound/soc/codecs/pcm3008.c
index 7e73fa4b3183..8fb445f33f6f 100644
--- a/sound/soc/codecs/pcm3008.c
+++ b/sound/soc/codecs/pcm3008.c
@@ -32,7 +32,7 @@ static int pcm3008_dac_ev(struct snd_soc_dapm_widget *w,
32 struct snd_kcontrol *kcontrol, 32 struct snd_kcontrol *kcontrol,
33 int event) 33 int event)
34{ 34{
35 struct snd_soc_codec *codec = w->codec; 35 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
36 struct pcm3008_setup_data *setup = codec->dev->platform_data; 36 struct pcm3008_setup_data *setup = codec->dev->platform_data;
37 37
38 gpio_set_value_cansleep(setup->pdda_pin, 38 gpio_set_value_cansleep(setup->pdda_pin,
@@ -45,7 +45,7 @@ static int pcm3008_adc_ev(struct snd_soc_dapm_widget *w,
45 struct snd_kcontrol *kcontrol, 45 struct snd_kcontrol *kcontrol,
46 int event) 46 int event)
47{ 47{
48 struct snd_soc_codec *codec = w->codec; 48 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
49 struct pcm3008_setup_data *setup = codec->dev->platform_data; 49 struct pcm3008_setup_data *setup = codec->dev->platform_data;
50 50
51 gpio_set_value_cansleep(setup->pdad_pin, 51 gpio_set_value_cansleep(setup->pdad_pin,
diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c
index 30c673cdc12e..9974f201a08f 100644
--- a/sound/soc/codecs/pcm512x.c
+++ b/sound/soc/codecs/pcm512x.c
@@ -21,12 +21,19 @@
21#include <linux/pm_runtime.h> 21#include <linux/pm_runtime.h>
22#include <linux/regmap.h> 22#include <linux/regmap.h>
23#include <linux/regulator/consumer.h> 23#include <linux/regulator/consumer.h>
24#include <linux/gcd.h>
24#include <sound/soc.h> 25#include <sound/soc.h>
25#include <sound/soc-dapm.h> 26#include <sound/soc-dapm.h>
27#include <sound/pcm_params.h>
26#include <sound/tlv.h> 28#include <sound/tlv.h>
27 29
28#include "pcm512x.h" 30#include "pcm512x.h"
29 31
32#define DIV_ROUND_DOWN_ULL(ll, d) \
33 ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; })
34#define DIV_ROUND_CLOSEST_ULL(ll, d) \
35 ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; })
36
30#define PCM512x_NUM_SUPPLIES 3 37#define PCM512x_NUM_SUPPLIES 3
31static const char * const pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = { 38static const char * const pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = {
32 "AVDD", 39 "AVDD",
@@ -39,6 +46,14 @@ struct pcm512x_priv {
39 struct clk *sclk; 46 struct clk *sclk;
40 struct regulator_bulk_data supplies[PCM512x_NUM_SUPPLIES]; 47 struct regulator_bulk_data supplies[PCM512x_NUM_SUPPLIES];
41 struct notifier_block supply_nb[PCM512x_NUM_SUPPLIES]; 48 struct notifier_block supply_nb[PCM512x_NUM_SUPPLIES];
49 int fmt;
50 int pll_in;
51 int pll_out;
52 int pll_r;
53 int pll_j;
54 int pll_d;
55 int pll_p;
56 unsigned long real_pll;
42}; 57};
43 58
44/* 59/*
@@ -69,6 +84,7 @@ static const struct reg_default pcm512x_reg_defaults[] = {
69 { PCM512x_MUTE, 0x00 }, 84 { PCM512x_MUTE, 0x00 },
70 { PCM512x_DSP, 0x00 }, 85 { PCM512x_DSP, 0x00 },
71 { PCM512x_PLL_REF, 0x00 }, 86 { PCM512x_PLL_REF, 0x00 },
87 { PCM512x_DAC_REF, 0x00 },
72 { PCM512x_DAC_ROUTING, 0x11 }, 88 { PCM512x_DAC_ROUTING, 0x11 },
73 { PCM512x_DSP_PROGRAM, 0x01 }, 89 { PCM512x_DSP_PROGRAM, 0x01 },
74 { PCM512x_CLKDET, 0x00 }, 90 { PCM512x_CLKDET, 0x00 },
@@ -87,6 +103,25 @@ static const struct reg_default pcm512x_reg_defaults[] = {
87 { PCM512x_ANALOG_GAIN_BOOST, 0x00 }, 103 { PCM512x_ANALOG_GAIN_BOOST, 0x00 },
88 { PCM512x_VCOM_CTRL_1, 0x00 }, 104 { PCM512x_VCOM_CTRL_1, 0x00 },
89 { PCM512x_VCOM_CTRL_2, 0x01 }, 105 { PCM512x_VCOM_CTRL_2, 0x01 },
106 { PCM512x_BCLK_LRCLK_CFG, 0x00 },
107 { PCM512x_MASTER_MODE, 0x7c },
108 { PCM512x_GPIO_DACIN, 0x00 },
109 { PCM512x_GPIO_PLLIN, 0x00 },
110 { PCM512x_SYNCHRONIZE, 0x10 },
111 { PCM512x_PLL_COEFF_0, 0x00 },
112 { PCM512x_PLL_COEFF_1, 0x00 },
113 { PCM512x_PLL_COEFF_2, 0x00 },
114 { PCM512x_PLL_COEFF_3, 0x00 },
115 { PCM512x_PLL_COEFF_4, 0x00 },
116 { PCM512x_DSP_CLKDIV, 0x00 },
117 { PCM512x_DAC_CLKDIV, 0x00 },
118 { PCM512x_NCP_CLKDIV, 0x00 },
119 { PCM512x_OSR_CLKDIV, 0x00 },
120 { PCM512x_MASTER_CLKDIV_1, 0x00 },
121 { PCM512x_MASTER_CLKDIV_2, 0x00 },
122 { PCM512x_FS_SPEED_MODE, 0x00 },
123 { PCM512x_IDAC_1, 0x01 },
124 { PCM512x_IDAC_2, 0x00 },
90}; 125};
91 126
92static bool pcm512x_readable(struct device *dev, unsigned int reg) 127static bool pcm512x_readable(struct device *dev, unsigned int reg)
@@ -103,6 +138,10 @@ static bool pcm512x_readable(struct device *dev, unsigned int reg)
103 case PCM512x_DSP_GPIO_INPUT: 138 case PCM512x_DSP_GPIO_INPUT:
104 case PCM512x_MASTER_MODE: 139 case PCM512x_MASTER_MODE:
105 case PCM512x_PLL_REF: 140 case PCM512x_PLL_REF:
141 case PCM512x_DAC_REF:
142 case PCM512x_GPIO_DACIN:
143 case PCM512x_GPIO_PLLIN:
144 case PCM512x_SYNCHRONIZE:
106 case PCM512x_PLL_COEFF_0: 145 case PCM512x_PLL_COEFF_0:
107 case PCM512x_PLL_COEFF_1: 146 case PCM512x_PLL_COEFF_1:
108 case PCM512x_PLL_COEFF_2: 147 case PCM512x_PLL_COEFF_2:
@@ -143,6 +182,7 @@ static bool pcm512x_readable(struct device *dev, unsigned int reg)
143 case PCM512x_RATE_DET_2: 182 case PCM512x_RATE_DET_2:
144 case PCM512x_RATE_DET_3: 183 case PCM512x_RATE_DET_3:
145 case PCM512x_RATE_DET_4: 184 case PCM512x_RATE_DET_4:
185 case PCM512x_CLOCK_STATUS:
146 case PCM512x_ANALOG_MUTE_DET: 186 case PCM512x_ANALOG_MUTE_DET:
147 case PCM512x_GPIN: 187 case PCM512x_GPIN:
148 case PCM512x_DIGITAL_MUTE_DET: 188 case PCM512x_DIGITAL_MUTE_DET:
@@ -154,6 +194,8 @@ static bool pcm512x_readable(struct device *dev, unsigned int reg)
154 case PCM512x_VCOM_CTRL_1: 194 case PCM512x_VCOM_CTRL_1:
155 case PCM512x_VCOM_CTRL_2: 195 case PCM512x_VCOM_CTRL_2:
156 case PCM512x_CRAM_CTRL: 196 case PCM512x_CRAM_CTRL:
197 case PCM512x_FLEX_A:
198 case PCM512x_FLEX_B:
157 return true; 199 return true;
158 default: 200 default:
159 /* There are 256 raw register addresses */ 201 /* There are 256 raw register addresses */
@@ -170,6 +212,7 @@ static bool pcm512x_volatile(struct device *dev, unsigned int reg)
170 case PCM512x_RATE_DET_2: 212 case PCM512x_RATE_DET_2:
171 case PCM512x_RATE_DET_3: 213 case PCM512x_RATE_DET_3:
172 case PCM512x_RATE_DET_4: 214 case PCM512x_RATE_DET_4:
215 case PCM512x_CLOCK_STATUS:
173 case PCM512x_ANALOG_MUTE_DET: 216 case PCM512x_ANALOG_MUTE_DET:
174 case PCM512x_GPIN: 217 case PCM512x_GPIN:
175 case PCM512x_DIGITAL_MUTE_DET: 218 case PCM512x_DIGITAL_MUTE_DET:
@@ -277,7 +320,7 @@ SOC_ENUM("Auto Mute Time Right", pcm512x_autom_r),
277SOC_SINGLE("Auto Mute Mono Switch", PCM512x_DIGITAL_MUTE_3, 320SOC_SINGLE("Auto Mute Mono Switch", PCM512x_DIGITAL_MUTE_3,
278 PCM512x_ACTL_SHIFT, 1, 0), 321 PCM512x_ACTL_SHIFT, 1, 0),
279SOC_DOUBLE("Auto Mute Switch", PCM512x_DIGITAL_MUTE_3, PCM512x_AMLE_SHIFT, 322SOC_DOUBLE("Auto Mute Switch", PCM512x_DIGITAL_MUTE_3, PCM512x_AMLE_SHIFT,
280 PCM512x_AMLR_SHIFT, 1, 0), 323 PCM512x_AMRE_SHIFT, 1, 0),
281 324
282SOC_ENUM("Volume Ramp Down Rate", pcm512x_vndf), 325SOC_ENUM("Volume Ramp Down Rate", pcm512x_vndf),
283SOC_ENUM("Volume Ramp Down Step", pcm512x_vnds), 326SOC_ENUM("Volume Ramp Down Step", pcm512x_vnds),
@@ -303,6 +346,136 @@ static const struct snd_soc_dapm_route pcm512x_dapm_routes[] = {
303 { "OUTR", NULL, "DACR" }, 346 { "OUTR", NULL, "DACR" },
304}; 347};
305 348
349static const u32 pcm512x_dai_rates[] = {
350 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000,
351 88200, 96000, 176400, 192000, 384000,
352};
353
354static const struct snd_pcm_hw_constraint_list constraints_slave = {
355 .count = ARRAY_SIZE(pcm512x_dai_rates),
356 .list = pcm512x_dai_rates,
357};
358
359static int pcm512x_hw_rule_rate(struct snd_pcm_hw_params *params,
360 struct snd_pcm_hw_rule *rule)
361{
362 struct snd_interval ranges[2];
363 int frame_size;
364
365 frame_size = snd_soc_params_to_frame_size(params);
366 if (frame_size < 0)
367 return frame_size;
368
369 switch (frame_size) {
370 case 32:
371 /* No hole when the frame size is 32. */
372 return 0;
373 case 48:
374 case 64:
375 /* There is only one hole in the range of supported
376 * rates, but it moves with the frame size.
377 */
378 memset(ranges, 0, sizeof(ranges));
379 ranges[0].min = 8000;
380 ranges[0].max = 25000000 / frame_size / 2;
381 ranges[1].min = DIV_ROUND_UP(16000000, frame_size);
382 ranges[1].max = 384000;
383 break;
384 default:
385 return -EINVAL;
386 }
387
388 return snd_interval_ranges(hw_param_interval(params, rule->var),
389 ARRAY_SIZE(ranges), ranges, 0);
390}
391
392static int pcm512x_dai_startup_master(struct snd_pcm_substream *substream,
393 struct snd_soc_dai *dai)
394{
395 struct snd_soc_codec *codec = dai->codec;
396 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
397 struct device *dev = dai->dev;
398 struct snd_pcm_hw_constraint_ratnums *constraints_no_pll;
399 struct snd_ratnum *rats_no_pll;
400
401 if (IS_ERR(pcm512x->sclk)) {
402 dev_err(dev, "Need SCLK for master mode: %ld\n",
403 PTR_ERR(pcm512x->sclk));
404 return PTR_ERR(pcm512x->sclk);
405 }
406
407 if (pcm512x->pll_out)
408 return snd_pcm_hw_rule_add(substream->runtime, 0,
409 SNDRV_PCM_HW_PARAM_RATE,
410 pcm512x_hw_rule_rate,
411 NULL,
412 SNDRV_PCM_HW_PARAM_FRAME_BITS,
413 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
414
415 constraints_no_pll = devm_kzalloc(dev, sizeof(*constraints_no_pll),
416 GFP_KERNEL);
417 if (!constraints_no_pll)
418 return -ENOMEM;
419 constraints_no_pll->nrats = 1;
420 rats_no_pll = devm_kzalloc(dev, sizeof(*rats_no_pll), GFP_KERNEL);
421 if (!rats_no_pll)
422 return -ENOMEM;
423 constraints_no_pll->rats = rats_no_pll;
424 rats_no_pll->num = clk_get_rate(pcm512x->sclk) / 64;
425 rats_no_pll->den_min = 1;
426 rats_no_pll->den_max = 128;
427 rats_no_pll->den_step = 1;
428
429 return snd_pcm_hw_constraint_ratnums(substream->runtime, 0,
430 SNDRV_PCM_HW_PARAM_RATE,
431 constraints_no_pll);
432}
433
434static int pcm512x_dai_startup_slave(struct snd_pcm_substream *substream,
435 struct snd_soc_dai *dai)
436{
437 struct snd_soc_codec *codec = dai->codec;
438 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
439 struct device *dev = dai->dev;
440 struct regmap *regmap = pcm512x->regmap;
441
442 if (IS_ERR(pcm512x->sclk)) {
443 dev_info(dev, "No SCLK, using BCLK: %ld\n",
444 PTR_ERR(pcm512x->sclk));
445
446 /* Disable reporting of missing SCLK as an error */
447 regmap_update_bits(regmap, PCM512x_ERROR_DETECT,
448 PCM512x_IDCH, PCM512x_IDCH);
449
450 /* Switch PLL input to BCLK */
451 regmap_update_bits(regmap, PCM512x_PLL_REF,
452 PCM512x_SREF, PCM512x_SREF_BCK);
453 }
454
455 return snd_pcm_hw_constraint_list(substream->runtime, 0,
456 SNDRV_PCM_HW_PARAM_RATE,
457 &constraints_slave);
458}
459
460static int pcm512x_dai_startup(struct snd_pcm_substream *substream,
461 struct snd_soc_dai *dai)
462{
463 struct snd_soc_codec *codec = dai->codec;
464 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
465
466 switch (pcm512x->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
467 case SND_SOC_DAIFMT_CBM_CFM:
468 case SND_SOC_DAIFMT_CBM_CFS:
469 return pcm512x_dai_startup_master(substream, dai);
470
471 case SND_SOC_DAIFMT_CBS_CFS:
472 return pcm512x_dai_startup_slave(substream, dai);
473
474 default:
475 return -EINVAL;
476 }
477}
478
306static int pcm512x_set_bias_level(struct snd_soc_codec *codec, 479static int pcm512x_set_bias_level(struct snd_soc_codec *codec,
307 enum snd_soc_bias_level level) 480 enum snd_soc_bias_level level)
308{ 481{
@@ -340,17 +513,717 @@ static int pcm512x_set_bias_level(struct snd_soc_codec *codec,
340 return 0; 513 return 0;
341} 514}
342 515
516static unsigned long pcm512x_find_sck(struct snd_soc_dai *dai,
517 unsigned long bclk_rate)
518{
519 struct device *dev = dai->dev;
520 unsigned long sck_rate;
521 int pow2;
522
523 /* 64 MHz <= pll_rate <= 100 MHz, VREF mode */
524 /* 16 MHz <= sck_rate <= 25 MHz, VREF mode */
525
526 /* select sck_rate as a multiple of bclk_rate but still with
527 * as many factors of 2 as possible, as that makes it easier
528 * to find a fast DAC rate
529 */
530 pow2 = 1 << fls((25000000 - 16000000) / bclk_rate);
531 for (; pow2; pow2 >>= 1) {
532 sck_rate = rounddown(25000000, bclk_rate * pow2);
533 if (sck_rate >= 16000000)
534 break;
535 }
536 if (!pow2) {
537 dev_err(dev, "Impossible to generate a suitable SCK\n");
538 return 0;
539 }
540
541 dev_dbg(dev, "sck_rate %lu\n", sck_rate);
542 return sck_rate;
543}
544
545/* pll_rate = pllin_rate * R * J.D / P
546 * 1 <= R <= 16
547 * 1 <= J <= 63
548 * 0 <= D <= 9999
549 * 1 <= P <= 15
550 * 64 MHz <= pll_rate <= 100 MHz
551 * if D == 0
552 * 1 MHz <= pllin_rate / P <= 20 MHz
553 * else if D > 0
554 * 6.667 MHz <= pllin_rate / P <= 20 MHz
555 * 4 <= J <= 11
556 * R = 1
557 */
558static int pcm512x_find_pll_coeff(struct snd_soc_dai *dai,
559 unsigned long pllin_rate,
560 unsigned long pll_rate)
561{
562 struct device *dev = dai->dev;
563 struct snd_soc_codec *codec = dai->codec;
564 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
565 unsigned long common;
566 int R, J, D, P;
567 unsigned long K; /* 10000 * J.D */
568 unsigned long num;
569 unsigned long den;
570
571 common = gcd(pll_rate, pllin_rate);
572 dev_dbg(dev, "pll %lu pllin %lu common %lu\n",
573 pll_rate, pllin_rate, common);
574 num = pll_rate / common;
575 den = pllin_rate / common;
576
577 /* pllin_rate / P (or here, den) cannot be greater than 20 MHz */
578 if (pllin_rate / den > 20000000 && num < 8) {
579 num *= 20000000 / (pllin_rate / den);
580 den *= 20000000 / (pllin_rate / den);
581 }
582 dev_dbg(dev, "num / den = %lu / %lu\n", num, den);
583
584 P = den;
585 if (den <= 15 && num <= 16 * 63
586 && 1000000 <= pllin_rate / P && pllin_rate / P <= 20000000) {
587 /* Try the case with D = 0 */
588 D = 0;
589 /* factor 'num' into J and R, such that R <= 16 and J <= 63 */
590 for (R = 16; R; R--) {
591 if (num % R)
592 continue;
593 J = num / R;
594 if (J == 0 || J > 63)
595 continue;
596
597 dev_dbg(dev, "R * J / P = %d * %d / %d\n", R, J, P);
598 pcm512x->real_pll = pll_rate;
599 goto done;
600 }
601 /* no luck */
602 }
603
604 R = 1;
605
606 if (num > 0xffffffffUL / 10000)
607 goto fallback;
608
609 /* Try to find an exact pll_rate using the D > 0 case */
610 common = gcd(10000 * num, den);
611 num = 10000 * num / common;
612 den /= common;
613 dev_dbg(dev, "num %lu den %lu common %lu\n", num, den, common);
614
615 for (P = den; P <= 15; P++) {
616 if (pllin_rate / P < 6667000 || 200000000 < pllin_rate / P)
617 continue;
618 if (num * P % den)
619 continue;
620 K = num * P / den;
621 /* J == 12 is ok if D == 0 */
622 if (K < 40000 || K > 120000)
623 continue;
624
625 J = K / 10000;
626 D = K % 10000;
627 dev_dbg(dev, "J.D / P = %d.%04d / %d\n", J, D, P);
628 pcm512x->real_pll = pll_rate;
629 goto done;
630 }
631
632 /* Fall back to an approximate pll_rate */
633
634fallback:
635 /* find smallest possible P */
636 P = DIV_ROUND_UP(pllin_rate, 20000000);
637 if (!P)
638 P = 1;
639 else if (P > 15) {
640 dev_err(dev, "Need a slower clock as pll-input\n");
641 return -EINVAL;
642 }
643 if (pllin_rate / P < 6667000) {
644 dev_err(dev, "Need a faster clock as pll-input\n");
645 return -EINVAL;
646 }
647 K = DIV_ROUND_CLOSEST_ULL(10000ULL * pll_rate * P, pllin_rate);
648 if (K < 40000)
649 K = 40000;
650 /* J == 12 is ok if D == 0 */
651 if (K > 120000)
652 K = 120000;
653 J = K / 10000;
654 D = K % 10000;
655 dev_dbg(dev, "J.D / P ~ %d.%04d / %d\n", J, D, P);
656 pcm512x->real_pll = DIV_ROUND_DOWN_ULL((u64)K * pllin_rate, 10000 * P);
657
658done:
659 pcm512x->pll_r = R;
660 pcm512x->pll_j = J;
661 pcm512x->pll_d = D;
662 pcm512x->pll_p = P;
663 return 0;
664}
665
666static unsigned long pcm512x_pllin_dac_rate(struct snd_soc_dai *dai,
667 unsigned long osr_rate,
668 unsigned long pllin_rate)
669{
670 struct snd_soc_codec *codec = dai->codec;
671 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
672 unsigned long dac_rate;
673
674 if (!pcm512x->pll_out)
675 return 0; /* no PLL to bypass, force SCK as DAC input */
676
677 if (pllin_rate % osr_rate)
678 return 0; /* futile, quit early */
679
680 /* run DAC no faster than 6144000 Hz */
681 for (dac_rate = rounddown(6144000, osr_rate);
682 dac_rate;
683 dac_rate -= osr_rate) {
684
685 if (pllin_rate / dac_rate > 128)
686 return 0; /* DAC divider would be too big */
687
688 if (!(pllin_rate % dac_rate))
689 return dac_rate;
690
691 dac_rate -= osr_rate;
692 }
693
694 return 0;
695}
696
697static int pcm512x_set_dividers(struct snd_soc_dai *dai,
698 struct snd_pcm_hw_params *params)
699{
700 struct device *dev = dai->dev;
701 struct snd_soc_codec *codec = dai->codec;
702 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
703 unsigned long pllin_rate = 0;
704 unsigned long pll_rate;
705 unsigned long sck_rate;
706 unsigned long mck_rate;
707 unsigned long bclk_rate;
708 unsigned long sample_rate;
709 unsigned long osr_rate;
710 unsigned long dacsrc_rate;
711 int bclk_div;
712 int lrclk_div;
713 int dsp_div;
714 int dac_div;
715 unsigned long dac_rate;
716 int ncp_div;
717 int osr_div;
718 int ret;
719 int idac;
720 int fssp;
721 int gpio;
722
723 lrclk_div = snd_soc_params_to_frame_size(params);
724 if (lrclk_div == 0) {
725 dev_err(dev, "No LRCLK?\n");
726 return -EINVAL;
727 }
728
729 if (!pcm512x->pll_out) {
730 sck_rate = clk_get_rate(pcm512x->sclk);
731 bclk_div = params->rate_den * 64 / lrclk_div;
732 bclk_rate = DIV_ROUND_CLOSEST(sck_rate, bclk_div);
733
734 mck_rate = sck_rate;
735 } else {
736 ret = snd_soc_params_to_bclk(params);
737 if (ret < 0) {
738 dev_err(dev, "Failed to find suitable BCLK: %d\n", ret);
739 return ret;
740 }
741 if (ret == 0) {
742 dev_err(dev, "No BCLK?\n");
743 return -EINVAL;
744 }
745 bclk_rate = ret;
746
747 pllin_rate = clk_get_rate(pcm512x->sclk);
748
749 sck_rate = pcm512x_find_sck(dai, bclk_rate);
750 if (!sck_rate)
751 return -EINVAL;
752 pll_rate = 4 * sck_rate;
753
754 ret = pcm512x_find_pll_coeff(dai, pllin_rate, pll_rate);
755 if (ret != 0)
756 return ret;
757
758 ret = regmap_write(pcm512x->regmap,
759 PCM512x_PLL_COEFF_0, pcm512x->pll_p - 1);
760 if (ret != 0) {
761 dev_err(dev, "Failed to write PLL P: %d\n", ret);
762 return ret;
763 }
764
765 ret = regmap_write(pcm512x->regmap,
766 PCM512x_PLL_COEFF_1, pcm512x->pll_j);
767 if (ret != 0) {
768 dev_err(dev, "Failed to write PLL J: %d\n", ret);
769 return ret;
770 }
771
772 ret = regmap_write(pcm512x->regmap,
773 PCM512x_PLL_COEFF_2, pcm512x->pll_d >> 8);
774 if (ret != 0) {
775 dev_err(dev, "Failed to write PLL D msb: %d\n", ret);
776 return ret;
777 }
778
779 ret = regmap_write(pcm512x->regmap,
780 PCM512x_PLL_COEFF_3, pcm512x->pll_d & 0xff);
781 if (ret != 0) {
782 dev_err(dev, "Failed to write PLL D lsb: %d\n", ret);
783 return ret;
784 }
785
786 ret = regmap_write(pcm512x->regmap,
787 PCM512x_PLL_COEFF_4, pcm512x->pll_r - 1);
788 if (ret != 0) {
789 dev_err(dev, "Failed to write PLL R: %d\n", ret);
790 return ret;
791 }
792
793 mck_rate = pcm512x->real_pll;
794
795 bclk_div = DIV_ROUND_CLOSEST(sck_rate, bclk_rate);
796 }
797
798 if (bclk_div > 128) {
799 dev_err(dev, "Failed to find BCLK divider\n");
800 return -EINVAL;
801 }
802
803 /* the actual rate */
804 sample_rate = sck_rate / bclk_div / lrclk_div;
805 osr_rate = 16 * sample_rate;
806
807 /* run DSP no faster than 50 MHz */
808 dsp_div = mck_rate > 50000000 ? 2 : 1;
809
810 dac_rate = pcm512x_pllin_dac_rate(dai, osr_rate, pllin_rate);
811 if (dac_rate) {
812 /* the desired clock rate is "compatible" with the pll input
813 * clock, so use that clock as dac input instead of the pll
814 * output clock since the pll will introduce jitter and thus
815 * noise.
816 */
817 dev_dbg(dev, "using pll input as dac input\n");
818 ret = regmap_update_bits(pcm512x->regmap, PCM512x_DAC_REF,
819 PCM512x_SDAC, PCM512x_SDAC_GPIO);
820 if (ret != 0) {
821 dev_err(codec->dev,
822 "Failed to set gpio as dacref: %d\n", ret);
823 return ret;
824 }
825
826 gpio = PCM512x_GREF_GPIO1 + pcm512x->pll_in - 1;
827 ret = regmap_update_bits(pcm512x->regmap, PCM512x_GPIO_DACIN,
828 PCM512x_GREF, gpio);
829 if (ret != 0) {
830 dev_err(codec->dev,
831 "Failed to set gpio %d as dacin: %d\n",
832 pcm512x->pll_in, ret);
833 return ret;
834 }
835
836 dacsrc_rate = pllin_rate;
837 } else {
838 /* run DAC no faster than 6144000 Hz */
839 unsigned long dac_mul = 6144000 / osr_rate;
840 unsigned long sck_mul = sck_rate / osr_rate;
841
842 for (; dac_mul; dac_mul--) {
843 if (!(sck_mul % dac_mul))
844 break;
845 }
846 if (!dac_mul) {
847 dev_err(dev, "Failed to find DAC rate\n");
848 return -EINVAL;
849 }
850
851 dac_rate = dac_mul * osr_rate;
852 dev_dbg(dev, "dac_rate %lu sample_rate %lu\n",
853 dac_rate, sample_rate);
854
855 ret = regmap_update_bits(pcm512x->regmap, PCM512x_DAC_REF,
856 PCM512x_SDAC, PCM512x_SDAC_SCK);
857 if (ret != 0) {
858 dev_err(codec->dev,
859 "Failed to set sck as dacref: %d\n", ret);
860 return ret;
861 }
862
863 dacsrc_rate = sck_rate;
864 }
865
866 dac_div = DIV_ROUND_CLOSEST(dacsrc_rate, dac_rate);
867 if (dac_div > 128) {
868 dev_err(dev, "Failed to find DAC divider\n");
869 return -EINVAL;
870 }
871
872 ncp_div = DIV_ROUND_CLOSEST(dacsrc_rate / dac_div, 1536000);
873 if (ncp_div > 128 || dacsrc_rate / dac_div / ncp_div > 2048000) {
874 /* run NCP no faster than 2048000 Hz, but why? */
875 ncp_div = DIV_ROUND_UP(dacsrc_rate / dac_div, 2048000);
876 if (ncp_div > 128) {
877 dev_err(dev, "Failed to find NCP divider\n");
878 return -EINVAL;
879 }
880 }
881
882 osr_div = DIV_ROUND_CLOSEST(dac_rate, osr_rate);
883 if (osr_div > 128) {
884 dev_err(dev, "Failed to find OSR divider\n");
885 return -EINVAL;
886 }
887
888 idac = mck_rate / (dsp_div * sample_rate);
889
890 ret = regmap_write(pcm512x->regmap, PCM512x_DSP_CLKDIV, dsp_div - 1);
891 if (ret != 0) {
892 dev_err(dev, "Failed to write DSP divider: %d\n", ret);
893 return ret;
894 }
895
896 ret = regmap_write(pcm512x->regmap, PCM512x_DAC_CLKDIV, dac_div - 1);
897 if (ret != 0) {
898 dev_err(dev, "Failed to write DAC divider: %d\n", ret);
899 return ret;
900 }
901
902 ret = regmap_write(pcm512x->regmap, PCM512x_NCP_CLKDIV, ncp_div - 1);
903 if (ret != 0) {
904 dev_err(dev, "Failed to write NCP divider: %d\n", ret);
905 return ret;
906 }
907
908 ret = regmap_write(pcm512x->regmap, PCM512x_OSR_CLKDIV, osr_div - 1);
909 if (ret != 0) {
910 dev_err(dev, "Failed to write OSR divider: %d\n", ret);
911 return ret;
912 }
913
914 ret = regmap_write(pcm512x->regmap,
915 PCM512x_MASTER_CLKDIV_1, bclk_div - 1);
916 if (ret != 0) {
917 dev_err(dev, "Failed to write BCLK divider: %d\n", ret);
918 return ret;
919 }
920
921 ret = regmap_write(pcm512x->regmap,
922 PCM512x_MASTER_CLKDIV_2, lrclk_div - 1);
923 if (ret != 0) {
924 dev_err(dev, "Failed to write LRCLK divider: %d\n", ret);
925 return ret;
926 }
927
928 ret = regmap_write(pcm512x->regmap, PCM512x_IDAC_1, idac >> 8);
929 if (ret != 0) {
930 dev_err(dev, "Failed to write IDAC msb divider: %d\n", ret);
931 return ret;
932 }
933
934 ret = regmap_write(pcm512x->regmap, PCM512x_IDAC_2, idac & 0xff);
935 if (ret != 0) {
936 dev_err(dev, "Failed to write IDAC lsb divider: %d\n", ret);
937 return ret;
938 }
939
940 if (sample_rate <= 48000)
941 fssp = PCM512x_FSSP_48KHZ;
942 else if (sample_rate <= 96000)
943 fssp = PCM512x_FSSP_96KHZ;
944 else if (sample_rate <= 192000)
945 fssp = PCM512x_FSSP_192KHZ;
946 else
947 fssp = PCM512x_FSSP_384KHZ;
948 ret = regmap_update_bits(pcm512x->regmap, PCM512x_FS_SPEED_MODE,
949 PCM512x_FSSP, fssp);
950 if (ret != 0) {
951 dev_err(codec->dev, "Failed to set fs speed: %d\n", ret);
952 return ret;
953 }
954
955 dev_dbg(codec->dev, "DSP divider %d\n", dsp_div);
956 dev_dbg(codec->dev, "DAC divider %d\n", dac_div);
957 dev_dbg(codec->dev, "NCP divider %d\n", ncp_div);
958 dev_dbg(codec->dev, "OSR divider %d\n", osr_div);
959 dev_dbg(codec->dev, "BCK divider %d\n", bclk_div);
960 dev_dbg(codec->dev, "LRCK divider %d\n", lrclk_div);
961 dev_dbg(codec->dev, "IDAC %d\n", idac);
962 dev_dbg(codec->dev, "1<<FSSP %d\n", 1 << fssp);
963
964 return 0;
965}
966
967static int pcm512x_hw_params(struct snd_pcm_substream *substream,
968 struct snd_pcm_hw_params *params,
969 struct snd_soc_dai *dai)
970{
971 struct snd_soc_codec *codec = dai->codec;
972 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
973 int alen;
974 int gpio;
975 int clock_output;
976 int master_mode;
977 int ret;
978
979 dev_dbg(codec->dev, "hw_params %u Hz, %u channels\n",
980 params_rate(params),
981 params_channels(params));
982
983 switch (snd_pcm_format_width(params_format(params))) {
984 case 16:
985 alen = PCM512x_ALEN_16;
986 break;
987 case 20:
988 alen = PCM512x_ALEN_20;
989 break;
990 case 24:
991 alen = PCM512x_ALEN_24;
992 break;
993 case 32:
994 alen = PCM512x_ALEN_32;
995 break;
996 default:
997 dev_err(codec->dev, "Bad frame size: %d\n",
998 snd_pcm_format_width(params_format(params)));
999 return -EINVAL;
1000 }
1001
1002 switch (pcm512x->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1003 case SND_SOC_DAIFMT_CBS_CFS:
1004 ret = regmap_update_bits(pcm512x->regmap,
1005 PCM512x_BCLK_LRCLK_CFG,
1006 PCM512x_BCKP
1007 | PCM512x_BCKO | PCM512x_LRKO,
1008 0);
1009 if (ret != 0) {
1010 dev_err(codec->dev,
1011 "Failed to enable slave mode: %d\n", ret);
1012 return ret;
1013 }
1014
1015 ret = regmap_update_bits(pcm512x->regmap, PCM512x_ERROR_DETECT,
1016 PCM512x_DCAS, 0);
1017 if (ret != 0) {
1018 dev_err(codec->dev,
1019 "Failed to enable clock divider autoset: %d\n",
1020 ret);
1021 return ret;
1022 }
1023 return 0;
1024 case SND_SOC_DAIFMT_CBM_CFM:
1025 clock_output = PCM512x_BCKO | PCM512x_LRKO;
1026 master_mode = PCM512x_RLRK | PCM512x_RBCK;
1027 break;
1028 case SND_SOC_DAIFMT_CBM_CFS:
1029 clock_output = PCM512x_BCKO;
1030 master_mode = PCM512x_RBCK;
1031 break;
1032 default:
1033 return -EINVAL;
1034 }
1035
1036 ret = regmap_update_bits(pcm512x->regmap, PCM512x_I2S_1,
1037 PCM512x_ALEN, alen);
1038 if (ret != 0) {
1039 dev_err(codec->dev, "Failed to set frame size: %d\n", ret);
1040 return ret;
1041 }
1042
1043 if (pcm512x->pll_out) {
1044 ret = regmap_write(pcm512x->regmap, PCM512x_FLEX_A, 0x11);
1045 if (ret != 0) {
1046 dev_err(codec->dev, "Failed to set FLEX_A: %d\n", ret);
1047 return ret;
1048 }
1049
1050 ret = regmap_write(pcm512x->regmap, PCM512x_FLEX_B, 0xff);
1051 if (ret != 0) {
1052 dev_err(codec->dev, "Failed to set FLEX_B: %d\n", ret);
1053 return ret;
1054 }
1055
1056 ret = regmap_update_bits(pcm512x->regmap, PCM512x_ERROR_DETECT,
1057 PCM512x_IDFS | PCM512x_IDBK
1058 | PCM512x_IDSK | PCM512x_IDCH
1059 | PCM512x_IDCM | PCM512x_DCAS
1060 | PCM512x_IPLK,
1061 PCM512x_IDFS | PCM512x_IDBK
1062 | PCM512x_IDSK | PCM512x_IDCH
1063 | PCM512x_DCAS);
1064 if (ret != 0) {
1065 dev_err(codec->dev,
1066 "Failed to ignore auto-clock failures: %d\n",
1067 ret);
1068 return ret;
1069 }
1070 } else {
1071 ret = regmap_update_bits(pcm512x->regmap, PCM512x_ERROR_DETECT,
1072 PCM512x_IDFS | PCM512x_IDBK
1073 | PCM512x_IDSK | PCM512x_IDCH
1074 | PCM512x_IDCM | PCM512x_DCAS
1075 | PCM512x_IPLK,
1076 PCM512x_IDFS | PCM512x_IDBK
1077 | PCM512x_IDSK | PCM512x_IDCH
1078 | PCM512x_DCAS | PCM512x_IPLK);
1079 if (ret != 0) {
1080 dev_err(codec->dev,
1081 "Failed to ignore auto-clock failures: %d\n",
1082 ret);
1083 return ret;
1084 }
1085
1086 ret = regmap_update_bits(pcm512x->regmap, PCM512x_PLL_EN,
1087 PCM512x_PLLE, 0);
1088 if (ret != 0) {
1089 dev_err(codec->dev, "Failed to disable pll: %d\n", ret);
1090 return ret;
1091 }
1092 }
1093
1094 ret = pcm512x_set_dividers(dai, params);
1095 if (ret != 0)
1096 return ret;
1097
1098 if (pcm512x->pll_out) {
1099 ret = regmap_update_bits(pcm512x->regmap, PCM512x_PLL_REF,
1100 PCM512x_SREF, PCM512x_SREF_GPIO);
1101 if (ret != 0) {
1102 dev_err(codec->dev,
1103 "Failed to set gpio as pllref: %d\n", ret);
1104 return ret;
1105 }
1106
1107 gpio = PCM512x_GREF_GPIO1 + pcm512x->pll_in - 1;
1108 ret = regmap_update_bits(pcm512x->regmap, PCM512x_GPIO_PLLIN,
1109 PCM512x_GREF, gpio);
1110 if (ret != 0) {
1111 dev_err(codec->dev,
1112 "Failed to set gpio %d as pllin: %d\n",
1113 pcm512x->pll_in, ret);
1114 return ret;
1115 }
1116
1117 ret = regmap_update_bits(pcm512x->regmap, PCM512x_PLL_EN,
1118 PCM512x_PLLE, PCM512x_PLLE);
1119 if (ret != 0) {
1120 dev_err(codec->dev, "Failed to enable pll: %d\n", ret);
1121 return ret;
1122 }
1123 }
1124
1125 ret = regmap_update_bits(pcm512x->regmap, PCM512x_BCLK_LRCLK_CFG,
1126 PCM512x_BCKP | PCM512x_BCKO | PCM512x_LRKO,
1127 clock_output);
1128 if (ret != 0) {
1129 dev_err(codec->dev, "Failed to enable clock output: %d\n", ret);
1130 return ret;
1131 }
1132
1133 ret = regmap_update_bits(pcm512x->regmap, PCM512x_MASTER_MODE,
1134 PCM512x_RLRK | PCM512x_RBCK,
1135 master_mode);
1136 if (ret != 0) {
1137 dev_err(codec->dev, "Failed to enable master mode: %d\n", ret);
1138 return ret;
1139 }
1140
1141 if (pcm512x->pll_out) {
1142 gpio = PCM512x_G1OE << (pcm512x->pll_out - 1);
1143 ret = regmap_update_bits(pcm512x->regmap, PCM512x_GPIO_EN,
1144 gpio, gpio);
1145 if (ret != 0) {
1146 dev_err(codec->dev, "Failed to enable gpio %d: %d\n",
1147 pcm512x->pll_out, ret);
1148 return ret;
1149 }
1150
1151 gpio = PCM512x_GPIO_OUTPUT_1 + pcm512x->pll_out - 1;
1152 ret = regmap_update_bits(pcm512x->regmap, gpio,
1153 PCM512x_GxSL, PCM512x_GxSL_PLLCK);
1154 if (ret != 0) {
1155 dev_err(codec->dev, "Failed to output pll on %d: %d\n",
1156 ret, pcm512x->pll_out);
1157 return ret;
1158 }
1159
1160 gpio = PCM512x_G1OE << (4 - 1);
1161 ret = regmap_update_bits(pcm512x->regmap, PCM512x_GPIO_EN,
1162 gpio, gpio);
1163 if (ret != 0) {
1164 dev_err(codec->dev, "Failed to enable gpio %d: %d\n",
1165 4, ret);
1166 return ret;
1167 }
1168
1169 gpio = PCM512x_GPIO_OUTPUT_1 + 4 - 1;
1170 ret = regmap_update_bits(pcm512x->regmap, gpio,
1171 PCM512x_GxSL, PCM512x_GxSL_PLLLK);
1172 if (ret != 0) {
1173 dev_err(codec->dev,
1174 "Failed to output pll lock on %d: %d\n",
1175 ret, 4);
1176 return ret;
1177 }
1178 }
1179
1180 ret = regmap_update_bits(pcm512x->regmap, PCM512x_SYNCHRONIZE,
1181 PCM512x_RQSY, PCM512x_RQSY_HALT);
1182 if (ret != 0) {
1183 dev_err(codec->dev, "Failed to halt clocks: %d\n", ret);
1184 return ret;
1185 }
1186
1187 ret = regmap_update_bits(pcm512x->regmap, PCM512x_SYNCHRONIZE,
1188 PCM512x_RQSY, PCM512x_RQSY_RESUME);
1189 if (ret != 0) {
1190 dev_err(codec->dev, "Failed to resume clocks: %d\n", ret);
1191 return ret;
1192 }
1193
1194 return 0;
1195}
1196
1197static int pcm512x_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
1198{
1199 struct snd_soc_codec *codec = dai->codec;
1200 struct pcm512x_priv *pcm512x = snd_soc_codec_get_drvdata(codec);
1201
1202 pcm512x->fmt = fmt;
1203
1204 return 0;
1205}
1206
1207static const struct snd_soc_dai_ops pcm512x_dai_ops = {
1208 .startup = pcm512x_dai_startup,
1209 .hw_params = pcm512x_hw_params,
1210 .set_fmt = pcm512x_set_fmt,
1211};
1212
343static struct snd_soc_dai_driver pcm512x_dai = { 1213static struct snd_soc_dai_driver pcm512x_dai = {
344 .name = "pcm512x-hifi", 1214 .name = "pcm512x-hifi",
345 .playback = { 1215 .playback = {
346 .stream_name = "Playback", 1216 .stream_name = "Playback",
347 .channels_min = 2, 1217 .channels_min = 2,
348 .channels_max = 2, 1218 .channels_max = 2,
349 .rates = SNDRV_PCM_RATE_8000_192000, 1219 .rates = SNDRV_PCM_RATE_CONTINUOUS,
1220 .rate_min = 8000,
1221 .rate_max = 384000,
350 .formats = SNDRV_PCM_FMTBIT_S16_LE | 1222 .formats = SNDRV_PCM_FMTBIT_S16_LE |
351 SNDRV_PCM_FMTBIT_S24_LE | 1223 SNDRV_PCM_FMTBIT_S24_LE |
352 SNDRV_PCM_FMTBIT_S32_LE 1224 SNDRV_PCM_FMTBIT_S32_LE
353 }, 1225 },
1226 .ops = &pcm512x_dai_ops,
354}; 1227};
355 1228
356static struct snd_soc_codec_driver pcm512x_codec_driver = { 1229static struct snd_soc_codec_driver pcm512x_codec_driver = {
@@ -448,21 +1321,9 @@ int pcm512x_probe(struct device *dev, struct regmap *regmap)
448 } 1321 }
449 1322
450 pcm512x->sclk = devm_clk_get(dev, NULL); 1323 pcm512x->sclk = devm_clk_get(dev, NULL);
451 if (IS_ERR(pcm512x->sclk)) { 1324 if (PTR_ERR(pcm512x->sclk) == -EPROBE_DEFER)
452 if (PTR_ERR(pcm512x->sclk) == -EPROBE_DEFER) 1325 return -EPROBE_DEFER;
453 return -EPROBE_DEFER; 1326 if (!IS_ERR(pcm512x->sclk)) {
454
455 dev_info(dev, "No SCLK, using BCLK: %ld\n",
456 PTR_ERR(pcm512x->sclk));
457
458 /* Disable reporting of missing SCLK as an error */
459 regmap_update_bits(regmap, PCM512x_ERROR_DETECT,
460 PCM512x_IDCH, PCM512x_IDCH);
461
462 /* Switch PLL input to BCLK */
463 regmap_update_bits(regmap, PCM512x_PLL_REF,
464 PCM512x_SREF, PCM512x_SREF);
465 } else {
466 ret = clk_prepare_enable(pcm512x->sclk); 1327 ret = clk_prepare_enable(pcm512x->sclk);
467 if (ret != 0) { 1328 if (ret != 0) {
468 dev_err(dev, "Failed to enable SCLK: %d\n", ret); 1329 dev_err(dev, "Failed to enable SCLK: %d\n", ret);
@@ -483,6 +1344,43 @@ int pcm512x_probe(struct device *dev, struct regmap *regmap)
483 pm_runtime_enable(dev); 1344 pm_runtime_enable(dev);
484 pm_runtime_idle(dev); 1345 pm_runtime_idle(dev);
485 1346
1347#ifdef CONFIG_OF
1348 if (dev->of_node) {
1349 const struct device_node *np = dev->of_node;
1350 u32 val;
1351
1352 if (of_property_read_u32(np, "pll-in", &val) >= 0) {
1353 if (val > 6) {
1354 dev_err(dev, "Invalid pll-in\n");
1355 ret = -EINVAL;
1356 goto err_clk;
1357 }
1358 pcm512x->pll_in = val;
1359 }
1360
1361 if (of_property_read_u32(np, "pll-out", &val) >= 0) {
1362 if (val > 6) {
1363 dev_err(dev, "Invalid pll-out\n");
1364 ret = -EINVAL;
1365 goto err_clk;
1366 }
1367 pcm512x->pll_out = val;
1368 }
1369
1370 if (!pcm512x->pll_in != !pcm512x->pll_out) {
1371 dev_err(dev,
1372 "Error: both pll-in and pll-out, or none\n");
1373 ret = -EINVAL;
1374 goto err_clk;
1375 }
1376 if (pcm512x->pll_in && pcm512x->pll_in == pcm512x->pll_out) {
1377 dev_err(dev, "Error: pll-in == pll-out\n");
1378 ret = -EINVAL;
1379 goto err_clk;
1380 }
1381 }
1382#endif
1383
486 ret = snd_soc_register_codec(dev, &pcm512x_codec_driver, 1384 ret = snd_soc_register_codec(dev, &pcm512x_codec_driver,
487 &pcm512x_dai, 1); 1385 &pcm512x_dai, 1);
488 if (ret != 0) { 1386 if (ret != 0) {
diff --git a/sound/soc/codecs/pcm512x.h b/sound/soc/codecs/pcm512x.h
index 6ee76aaca09a..b7c310207223 100644
--- a/sound/soc/codecs/pcm512x.h
+++ b/sound/soc/codecs/pcm512x.h
@@ -37,6 +37,10 @@
37#define PCM512x_DSP_GPIO_INPUT (PCM512x_PAGE_BASE(0) + 10) 37#define PCM512x_DSP_GPIO_INPUT (PCM512x_PAGE_BASE(0) + 10)
38#define PCM512x_MASTER_MODE (PCM512x_PAGE_BASE(0) + 12) 38#define PCM512x_MASTER_MODE (PCM512x_PAGE_BASE(0) + 12)
39#define PCM512x_PLL_REF (PCM512x_PAGE_BASE(0) + 13) 39#define PCM512x_PLL_REF (PCM512x_PAGE_BASE(0) + 13)
40#define PCM512x_DAC_REF (PCM512x_PAGE_BASE(0) + 14)
41#define PCM512x_GPIO_DACIN (PCM512x_PAGE_BASE(0) + 16)
42#define PCM512x_GPIO_PLLIN (PCM512x_PAGE_BASE(0) + 18)
43#define PCM512x_SYNCHRONIZE (PCM512x_PAGE_BASE(0) + 19)
40#define PCM512x_PLL_COEFF_0 (PCM512x_PAGE_BASE(0) + 20) 44#define PCM512x_PLL_COEFF_0 (PCM512x_PAGE_BASE(0) + 20)
41#define PCM512x_PLL_COEFF_1 (PCM512x_PAGE_BASE(0) + 21) 45#define PCM512x_PLL_COEFF_1 (PCM512x_PAGE_BASE(0) + 21)
42#define PCM512x_PLL_COEFF_2 (PCM512x_PAGE_BASE(0) + 22) 46#define PCM512x_PLL_COEFF_2 (PCM512x_PAGE_BASE(0) + 22)
@@ -77,6 +81,7 @@
77#define PCM512x_RATE_DET_2 (PCM512x_PAGE_BASE(0) + 92) 81#define PCM512x_RATE_DET_2 (PCM512x_PAGE_BASE(0) + 92)
78#define PCM512x_RATE_DET_3 (PCM512x_PAGE_BASE(0) + 93) 82#define PCM512x_RATE_DET_3 (PCM512x_PAGE_BASE(0) + 93)
79#define PCM512x_RATE_DET_4 (PCM512x_PAGE_BASE(0) + 94) 83#define PCM512x_RATE_DET_4 (PCM512x_PAGE_BASE(0) + 94)
84#define PCM512x_CLOCK_STATUS (PCM512x_PAGE_BASE(0) + 95)
80#define PCM512x_ANALOG_MUTE_DET (PCM512x_PAGE_BASE(0) + 108) 85#define PCM512x_ANALOG_MUTE_DET (PCM512x_PAGE_BASE(0) + 108)
81#define PCM512x_GPIN (PCM512x_PAGE_BASE(0) + 119) 86#define PCM512x_GPIN (PCM512x_PAGE_BASE(0) + 119)
82#define PCM512x_DIGITAL_MUTE_DET (PCM512x_PAGE_BASE(0) + 120) 87#define PCM512x_DIGITAL_MUTE_DET (PCM512x_PAGE_BASE(0) + 120)
@@ -91,7 +96,10 @@
91 96
92#define PCM512x_CRAM_CTRL (PCM512x_PAGE_BASE(44) + 1) 97#define PCM512x_CRAM_CTRL (PCM512x_PAGE_BASE(44) + 1)
93 98
94#define PCM512x_MAX_REGISTER (PCM512x_PAGE_BASE(44) + 1) 99#define PCM512x_FLEX_A (PCM512x_PAGE_BASE(253) + 63)
100#define PCM512x_FLEX_B (PCM512x_PAGE_BASE(253) + 64)
101
102#define PCM512x_MAX_REGISTER (PCM512x_PAGE_BASE(253) + 64)
95 103
96/* Page 0, Register 1 - reset */ 104/* Page 0, Register 1 - reset */
97#define PCM512x_RSTR (1 << 0) 105#define PCM512x_RSTR (1 << 0)
@@ -108,8 +116,8 @@
108#define PCM512x_RQML_SHIFT 4 116#define PCM512x_RQML_SHIFT 4
109 117
110/* Page 0, Register 4 - PLL */ 118/* Page 0, Register 4 - PLL */
111#define PCM512x_PLCE (1 << 0) 119#define PCM512x_PLLE (1 << 0)
112#define PCM512x_RLCE_SHIFT 0 120#define PCM512x_PLLE_SHIFT 0
113#define PCM512x_PLCK (1 << 4) 121#define PCM512x_PLCK (1 << 4)
114#define PCM512x_PLCK_SHIFT 4 122#define PCM512x_PLCK_SHIFT 4
115 123
@@ -119,8 +127,66 @@
119#define PCM512x_DEMP (1 << 4) 127#define PCM512x_DEMP (1 << 4)
120#define PCM512x_DEMP_SHIFT 4 128#define PCM512x_DEMP_SHIFT 4
121 129
130/* Page 0, Register 8 - GPIO output enable */
131#define PCM512x_G1OE (1 << 0)
132#define PCM512x_G2OE (1 << 1)
133#define PCM512x_G3OE (1 << 2)
134#define PCM512x_G4OE (1 << 3)
135#define PCM512x_G5OE (1 << 4)
136#define PCM512x_G6OE (1 << 5)
137
138/* Page 0, Register 9 - BCK, LRCLK configuration */
139#define PCM512x_LRKO (1 << 0)
140#define PCM512x_LRKO_SHIFT 0
141#define PCM512x_BCKO (1 << 4)
142#define PCM512x_BCKO_SHIFT 4
143#define PCM512x_BCKP (1 << 5)
144#define PCM512x_BCKP_SHIFT 5
145
146/* Page 0, Register 12 - Master mode BCK, LRCLK reset */
147#define PCM512x_RLRK (1 << 0)
148#define PCM512x_RLRK_SHIFT 0
149#define PCM512x_RBCK (1 << 1)
150#define PCM512x_RBCK_SHIFT 1
151
122/* Page 0, Register 13 - PLL reference */ 152/* Page 0, Register 13 - PLL reference */
123#define PCM512x_SREF (1 << 4) 153#define PCM512x_SREF (7 << 4)
154#define PCM512x_SREF_SHIFT 4
155#define PCM512x_SREF_SCK (0 << 4)
156#define PCM512x_SREF_BCK (1 << 4)
157#define PCM512x_SREF_GPIO (3 << 4)
158
159/* Page 0, Register 14 - DAC reference */
160#define PCM512x_SDAC (7 << 4)
161#define PCM512x_SDAC_SHIFT 4
162#define PCM512x_SDAC_MCK (0 << 4)
163#define PCM512x_SDAC_PLL (1 << 4)
164#define PCM512x_SDAC_SCK (3 << 4)
165#define PCM512x_SDAC_BCK (4 << 4)
166#define PCM512x_SDAC_GPIO (5 << 4)
167
168/* Page 0, Register 16, 18 - GPIO source for DAC, PLL */
169#define PCM512x_GREF (7 << 0)
170#define PCM512x_GREF_SHIFT 0
171#define PCM512x_GREF_GPIO1 (0 << 0)
172#define PCM512x_GREF_GPIO2 (1 << 0)
173#define PCM512x_GREF_GPIO3 (2 << 0)
174#define PCM512x_GREF_GPIO4 (3 << 0)
175#define PCM512x_GREF_GPIO5 (4 << 0)
176#define PCM512x_GREF_GPIO6 (5 << 0)
177
178/* Page 0, Register 19 - synchronize */
179#define PCM512x_RQSY (1 << 0)
180#define PCM512x_RQSY_RESUME (0 << 0)
181#define PCM512x_RQSY_HALT (1 << 0)
182
183/* Page 0, Register 34 - fs speed mode */
184#define PCM512x_FSSP (3 << 0)
185#define PCM512x_FSSP_SHIFT 0
186#define PCM512x_FSSP_48KHZ (0 << 0)
187#define PCM512x_FSSP_96KHZ (1 << 0)
188#define PCM512x_FSSP_192KHZ (2 << 0)
189#define PCM512x_FSSP_384KHZ (3 << 0)
124 190
125/* Page 0, Register 37 - Error detection */ 191/* Page 0, Register 37 - Error detection */
126#define PCM512x_IPLK (1 << 0) 192#define PCM512x_IPLK (1 << 0)
@@ -131,6 +197,20 @@
131#define PCM512x_IDBK (1 << 5) 197#define PCM512x_IDBK (1 << 5)
132#define PCM512x_IDFS (1 << 6) 198#define PCM512x_IDFS (1 << 6)
133 199
200/* Page 0, Register 40 - I2S configuration */
201#define PCM512x_ALEN (3 << 0)
202#define PCM512x_ALEN_SHIFT 0
203#define PCM512x_ALEN_16 (0 << 0)
204#define PCM512x_ALEN_20 (1 << 0)
205#define PCM512x_ALEN_24 (2 << 0)
206#define PCM512x_ALEN_32 (3 << 0)
207#define PCM512x_AFMT (3 << 4)
208#define PCM512x_AFMT_SHIFT 4
209#define PCM512x_AFMT_I2S (0 << 4)
210#define PCM512x_AFMT_DSP (1 << 4)
211#define PCM512x_AFMT_RTJ (2 << 4)
212#define PCM512x_AFMT_LTJ (3 << 4)
213
134/* Page 0, Register 42 - DAC routing */ 214/* Page 0, Register 42 - DAC routing */
135#define PCM512x_AUPR_SHIFT 0 215#define PCM512x_AUPR_SHIFT 0
136#define PCM512x_AUPL_SHIFT 4 216#define PCM512x_AUPL_SHIFT 4
@@ -152,7 +232,26 @@
152/* Page 0, Register 65 - Digital mute enables */ 232/* Page 0, Register 65 - Digital mute enables */
153#define PCM512x_ACTL_SHIFT 2 233#define PCM512x_ACTL_SHIFT 2
154#define PCM512x_AMLE_SHIFT 1 234#define PCM512x_AMLE_SHIFT 1
155#define PCM512x_AMLR_SHIFT 0 235#define PCM512x_AMRE_SHIFT 0
236
237/* Page 0, Register 80-85, GPIO output selection */
238#define PCM512x_GxSL (31 << 0)
239#define PCM512x_GxSL_SHIFT 0
240#define PCM512x_GxSL_OFF (0 << 0)
241#define PCM512x_GxSL_DSP (1 << 0)
242#define PCM512x_GxSL_REG (2 << 0)
243#define PCM512x_GxSL_AMUTB (3 << 0)
244#define PCM512x_GxSL_AMUTL (4 << 0)
245#define PCM512x_GxSL_AMUTR (5 << 0)
246#define PCM512x_GxSL_CLKI (6 << 0)
247#define PCM512x_GxSL_SDOUT (7 << 0)
248#define PCM512x_GxSL_ANMUL (8 << 0)
249#define PCM512x_GxSL_ANMUR (9 << 0)
250#define PCM512x_GxSL_PLLLK (10 << 0)
251#define PCM512x_GxSL_CPCLK (11 << 0)
252#define PCM512x_GxSL_UV0_7 (14 << 0)
253#define PCM512x_GxSL_UV0_3 (15 << 0)
254#define PCM512x_GxSL_PLLCK (16 << 0)
156 255
157/* Page 1, Register 2 - analog volume control */ 256/* Page 1, Register 2 - analog volume control */
158#define PCM512x_RAGN_SHIFT 0 257#define PCM512x_RAGN_SHIFT 0
diff --git a/sound/soc/codecs/rt286.c b/sound/soc/codecs/rt286.c
index 1d1c7f8a9af2..8104d2285602 100644
--- a/sound/soc/codecs/rt286.c
+++ b/sound/soc/codecs/rt286.c
@@ -403,7 +403,8 @@ EXPORT_SYMBOL_GPL(rt286_mic_detect);
403static int is_mclk_mode(struct snd_soc_dapm_widget *source, 403static int is_mclk_mode(struct snd_soc_dapm_widget *source,
404 struct snd_soc_dapm_widget *sink) 404 struct snd_soc_dapm_widget *sink)
405{ 405{
406 struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(source->codec); 406 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
407 struct rt286_priv *rt286 = snd_soc_codec_get_drvdata(codec);
407 408
408 if (rt286->clk_id == RT286_SCLK_S_MCLK) 409 if (rt286->clk_id == RT286_SCLK_S_MCLK)
409 return 1; 410 return 1;
@@ -417,6 +418,8 @@ static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, 0, 1000, 0);
417static const struct snd_kcontrol_new rt286_snd_controls[] = { 418static const struct snd_kcontrol_new rt286_snd_controls[] = {
418 SOC_DOUBLE_R_TLV("DAC0 Playback Volume", RT286_DACL_GAIN, 419 SOC_DOUBLE_R_TLV("DAC0 Playback Volume", RT286_DACL_GAIN,
419 RT286_DACR_GAIN, 0, 0x7f, 0, out_vol_tlv), 420 RT286_DACR_GAIN, 0, 0x7f, 0, out_vol_tlv),
421 SOC_DOUBLE_R("ADC0 Capture Switch", RT286_ADCL_GAIN,
422 RT286_ADCR_GAIN, 7, 1, 1),
420 SOC_DOUBLE_R_TLV("ADC0 Capture Volume", RT286_ADCL_GAIN, 423 SOC_DOUBLE_R_TLV("ADC0 Capture Volume", RT286_ADCL_GAIN,
421 RT286_ADCR_GAIN, 0, 0x7f, 0, out_vol_tlv), 424 RT286_ADCR_GAIN, 0, 0x7f, 0, out_vol_tlv),
422 SOC_SINGLE_TLV("AMIC Volume", RT286_MIC_GAIN, 425 SOC_SINGLE_TLV("AMIC Volume", RT286_MIC_GAIN,
@@ -500,7 +503,7 @@ SOC_DAPM_ENUM("SPO source", rt286_spo_enum);
500static int rt286_spk_event(struct snd_soc_dapm_widget *w, 503static int rt286_spk_event(struct snd_soc_dapm_widget *w,
501 struct snd_kcontrol *kcontrol, int event) 504 struct snd_kcontrol *kcontrol, int event)
502{ 505{
503 struct snd_soc_codec *codec = w->codec; 506 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
504 507
505 switch (event) { 508 switch (event) {
506 case SND_SOC_DAPM_POST_PMU: 509 case SND_SOC_DAPM_POST_PMU:
@@ -522,7 +525,7 @@ static int rt286_spk_event(struct snd_soc_dapm_widget *w,
522static int rt286_set_dmic1_event(struct snd_soc_dapm_widget *w, 525static int rt286_set_dmic1_event(struct snd_soc_dapm_widget *w,
523 struct snd_kcontrol *kcontrol, int event) 526 struct snd_kcontrol *kcontrol, int event)
524{ 527{
525 struct snd_soc_codec *codec = w->codec; 528 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
526 529
527 switch (event) { 530 switch (event) {
528 case SND_SOC_DAPM_POST_PMU: 531 case SND_SOC_DAPM_POST_PMU:
@@ -538,36 +541,10 @@ static int rt286_set_dmic1_event(struct snd_soc_dapm_widget *w,
538 return 0; 541 return 0;
539} 542}
540 543
541static int rt286_adc_event(struct snd_soc_dapm_widget *w,
542 struct snd_kcontrol *kcontrol, int event)
543{
544 struct snd_soc_codec *codec = w->codec;
545 unsigned int nid;
546
547 nid = (w->reg >> 20) & 0xff;
548
549 switch (event) {
550 case SND_SOC_DAPM_POST_PMU:
551 snd_soc_update_bits(codec,
552 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, nid, 0),
553 0x7080, 0x7000);
554 break;
555 case SND_SOC_DAPM_PRE_PMD:
556 snd_soc_update_bits(codec,
557 VERB_CMD(AC_VERB_SET_AMP_GAIN_MUTE, nid, 0),
558 0x7080, 0x7080);
559 break;
560 default:
561 return 0;
562 }
563
564 return 0;
565}
566
567static int rt286_vref_event(struct snd_soc_dapm_widget *w, 544static int rt286_vref_event(struct snd_soc_dapm_widget *w,
568 struct snd_kcontrol *kcontrol, int event) 545 struct snd_kcontrol *kcontrol, int event)
569{ 546{
570 struct snd_soc_codec *codec = w->codec; 547 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
571 548
572 switch (event) { 549 switch (event) {
573 case SND_SOC_DAPM_PRE_PMU: 550 case SND_SOC_DAPM_PRE_PMU:
@@ -585,7 +562,7 @@ static int rt286_vref_event(struct snd_soc_dapm_widget *w,
585static int rt286_ldo2_event(struct snd_soc_dapm_widget *w, 562static int rt286_ldo2_event(struct snd_soc_dapm_widget *w,
586 struct snd_kcontrol *kcontrol, int event) 563 struct snd_kcontrol *kcontrol, int event)
587{ 564{
588 struct snd_soc_codec *codec = w->codec; 565 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
589 566
590 switch (event) { 567 switch (event) {
591 case SND_SOC_DAPM_POST_PMU: 568 case SND_SOC_DAPM_POST_PMU:
@@ -604,7 +581,7 @@ static int rt286_ldo2_event(struct snd_soc_dapm_widget *w,
604static int rt286_mic1_event(struct snd_soc_dapm_widget *w, 581static int rt286_mic1_event(struct snd_soc_dapm_widget *w,
605 struct snd_kcontrol *kcontrol, int event) 582 struct snd_kcontrol *kcontrol, int event)
606{ 583{
607 struct snd_soc_codec *codec = w->codec; 584 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
608 585
609 switch (event) { 586 switch (event) {
610 case SND_SOC_DAPM_PRE_PMU: 587 case SND_SOC_DAPM_PRE_PMU:
@@ -667,12 +644,10 @@ static const struct snd_soc_dapm_widget rt286_dapm_widgets[] = {
667 SND_SOC_DAPM_ADC("ADC 1", NULL, SND_SOC_NOPM, 0, 0), 644 SND_SOC_DAPM_ADC("ADC 1", NULL, SND_SOC_NOPM, 0, 0),
668 645
669 /* ADC Mux */ 646 /* ADC Mux */
670 SND_SOC_DAPM_MUX_E("ADC 0 Mux", RT286_SET_POWER(RT286_ADC_IN1), 0, 1, 647 SND_SOC_DAPM_MUX("ADC 0 Mux", RT286_SET_POWER(RT286_ADC_IN1), 0, 1,
671 &rt286_adc0_mux, rt286_adc_event, SND_SOC_DAPM_PRE_PMD | 648 &rt286_adc0_mux),
672 SND_SOC_DAPM_POST_PMU), 649 SND_SOC_DAPM_MUX("ADC 1 Mux", RT286_SET_POWER(RT286_ADC_IN2), 0, 1,
673 SND_SOC_DAPM_MUX_E("ADC 1 Mux", RT286_SET_POWER(RT286_ADC_IN2), 0, 1, 650 &rt286_adc1_mux),
674 &rt286_adc1_mux, rt286_adc_event, SND_SOC_DAPM_PRE_PMD |
675 SND_SOC_DAPM_POST_PMU),
676 651
677 /* Audio Interface */ 652 /* Audio Interface */
678 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0), 653 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
diff --git a/sound/soc/codecs/rt5631.c b/sound/soc/codecs/rt5631.c
index 6d7b7ca7d530..c61852742ee3 100644
--- a/sound/soc/codecs/rt5631.c
+++ b/sound/soc/codecs/rt5631.c
@@ -287,70 +287,78 @@ static const struct snd_kcontrol_new rt5631_snd_controls[] = {
287static int check_sysclk1_source(struct snd_soc_dapm_widget *source, 287static int check_sysclk1_source(struct snd_soc_dapm_widget *source,
288 struct snd_soc_dapm_widget *sink) 288 struct snd_soc_dapm_widget *sink)
289{ 289{
290 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
290 unsigned int reg; 291 unsigned int reg;
291 292
292 reg = snd_soc_read(source->codec, RT5631_GLOBAL_CLK_CTRL); 293 reg = snd_soc_read(codec, RT5631_GLOBAL_CLK_CTRL);
293 return reg & RT5631_SYSCLK_SOUR_SEL_PLL; 294 return reg & RT5631_SYSCLK_SOUR_SEL_PLL;
294} 295}
295 296
296static int check_dmic_used(struct snd_soc_dapm_widget *source, 297static int check_dmic_used(struct snd_soc_dapm_widget *source,
297 struct snd_soc_dapm_widget *sink) 298 struct snd_soc_dapm_widget *sink)
298{ 299{
299 struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(source->codec); 300 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
301 struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
300 return rt5631->dmic_used_flag; 302 return rt5631->dmic_used_flag;
301} 303}
302 304
303static int check_dacl_to_outmixl(struct snd_soc_dapm_widget *source, 305static int check_dacl_to_outmixl(struct snd_soc_dapm_widget *source,
304 struct snd_soc_dapm_widget *sink) 306 struct snd_soc_dapm_widget *sink)
305{ 307{
308 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
306 unsigned int reg; 309 unsigned int reg;
307 310
308 reg = snd_soc_read(source->codec, RT5631_OUTMIXER_L_CTRL); 311 reg = snd_soc_read(codec, RT5631_OUTMIXER_L_CTRL);
309 return !(reg & RT5631_M_DAC_L_TO_OUTMIXER_L); 312 return !(reg & RT5631_M_DAC_L_TO_OUTMIXER_L);
310} 313}
311 314
312static int check_dacr_to_outmixr(struct snd_soc_dapm_widget *source, 315static int check_dacr_to_outmixr(struct snd_soc_dapm_widget *source,
313 struct snd_soc_dapm_widget *sink) 316 struct snd_soc_dapm_widget *sink)
314{ 317{
318 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
315 unsigned int reg; 319 unsigned int reg;
316 320
317 reg = snd_soc_read(source->codec, RT5631_OUTMIXER_R_CTRL); 321 reg = snd_soc_read(codec, RT5631_OUTMIXER_R_CTRL);
318 return !(reg & RT5631_M_DAC_R_TO_OUTMIXER_R); 322 return !(reg & RT5631_M_DAC_R_TO_OUTMIXER_R);
319} 323}
320 324
321static int check_dacl_to_spkmixl(struct snd_soc_dapm_widget *source, 325static int check_dacl_to_spkmixl(struct snd_soc_dapm_widget *source,
322 struct snd_soc_dapm_widget *sink) 326 struct snd_soc_dapm_widget *sink)
323{ 327{
328 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
324 unsigned int reg; 329 unsigned int reg;
325 330
326 reg = snd_soc_read(source->codec, RT5631_SPK_MIXER_CTRL); 331 reg = snd_soc_read(codec, RT5631_SPK_MIXER_CTRL);
327 return !(reg & RT5631_M_DAC_L_TO_SPKMIXER_L); 332 return !(reg & RT5631_M_DAC_L_TO_SPKMIXER_L);
328} 333}
329 334
330static int check_dacr_to_spkmixr(struct snd_soc_dapm_widget *source, 335static int check_dacr_to_spkmixr(struct snd_soc_dapm_widget *source,
331 struct snd_soc_dapm_widget *sink) 336 struct snd_soc_dapm_widget *sink)
332{ 337{
338 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
333 unsigned int reg; 339 unsigned int reg;
334 340
335 reg = snd_soc_read(source->codec, RT5631_SPK_MIXER_CTRL); 341 reg = snd_soc_read(codec, RT5631_SPK_MIXER_CTRL);
336 return !(reg & RT5631_M_DAC_R_TO_SPKMIXER_R); 342 return !(reg & RT5631_M_DAC_R_TO_SPKMIXER_R);
337} 343}
338 344
339static int check_adcl_select(struct snd_soc_dapm_widget *source, 345static int check_adcl_select(struct snd_soc_dapm_widget *source,
340 struct snd_soc_dapm_widget *sink) 346 struct snd_soc_dapm_widget *sink)
341{ 347{
348 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
342 unsigned int reg; 349 unsigned int reg;
343 350
344 reg = snd_soc_read(source->codec, RT5631_ADC_REC_MIXER); 351 reg = snd_soc_read(codec, RT5631_ADC_REC_MIXER);
345 return !(reg & RT5631_M_MIC1_TO_RECMIXER_L); 352 return !(reg & RT5631_M_MIC1_TO_RECMIXER_L);
346} 353}
347 354
348static int check_adcr_select(struct snd_soc_dapm_widget *source, 355static int check_adcr_select(struct snd_soc_dapm_widget *source,
349 struct snd_soc_dapm_widget *sink) 356 struct snd_soc_dapm_widget *sink)
350{ 357{
358 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
351 unsigned int reg; 359 unsigned int reg;
352 360
353 reg = snd_soc_read(source->codec, RT5631_ADC_REC_MIXER); 361 reg = snd_soc_read(codec, RT5631_ADC_REC_MIXER);
354 return !(reg & RT5631_M_MIC2_TO_RECMIXER_R); 362 return !(reg & RT5631_M_MIC2_TO_RECMIXER_R);
355} 363}
356 364
@@ -556,7 +564,7 @@ static void depop_seq_mute_stage(struct snd_soc_codec *codec, int enable)
556static int hp_event(struct snd_soc_dapm_widget *w, 564static int hp_event(struct snd_soc_dapm_widget *w,
557 struct snd_kcontrol *kcontrol, int event) 565 struct snd_kcontrol *kcontrol, int event)
558{ 566{
559 struct snd_soc_codec *codec = w->codec; 567 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
560 struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec); 568 struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
561 569
562 switch (event) { 570 switch (event) {
@@ -590,7 +598,7 @@ static int hp_event(struct snd_soc_dapm_widget *w,
590static int set_dmic_params(struct snd_soc_dapm_widget *w, 598static int set_dmic_params(struct snd_soc_dapm_widget *w,
591 struct snd_kcontrol *kcontrol, int event) 599 struct snd_kcontrol *kcontrol, int event)
592{ 600{
593 struct snd_soc_codec *codec = w->codec; 601 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
594 struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec); 602 struct rt5631_priv *rt5631 = snd_soc_codec_get_drvdata(codec);
595 603
596 switch (rt5631->rx_rate) { 604 switch (rt5631->rx_rate) {
diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index c3f2decd643c..178e55d4d481 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -458,7 +458,7 @@ static const struct snd_kcontrol_new rt5640_specific_snd_controls[] = {
458static int set_dmic_clk(struct snd_soc_dapm_widget *w, 458static int set_dmic_clk(struct snd_soc_dapm_widget *w,
459 struct snd_kcontrol *kcontrol, int event) 459 struct snd_kcontrol *kcontrol, int event)
460{ 460{
461 struct snd_soc_codec *codec = w->codec; 461 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
462 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 462 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
463 int idx = -EINVAL; 463 int idx = -EINVAL;
464 464
@@ -475,9 +475,10 @@ static int set_dmic_clk(struct snd_soc_dapm_widget *w,
475static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source, 475static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source,
476 struct snd_soc_dapm_widget *sink) 476 struct snd_soc_dapm_widget *sink)
477{ 477{
478 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
478 unsigned int val; 479 unsigned int val;
479 480
480 val = snd_soc_read(source->codec, RT5640_GLB_CLK); 481 val = snd_soc_read(codec, RT5640_GLB_CLK);
481 val &= RT5640_SCLK_SRC_MASK; 482 val &= RT5640_SCLK_SRC_MASK;
482 if (val == RT5640_SCLK_SRC_PLL1) 483 if (val == RT5640_SCLK_SRC_PLL1)
483 return 1; 484 return 1;
@@ -963,7 +964,7 @@ static void rt5640_pmu_depop(struct snd_soc_codec *codec)
963static int rt5640_hp_event(struct snd_soc_dapm_widget *w, 964static int rt5640_hp_event(struct snd_soc_dapm_widget *w,
964 struct snd_kcontrol *kcontrol, int event) 965 struct snd_kcontrol *kcontrol, int event)
965{ 966{
966 struct snd_soc_codec *codec = w->codec; 967 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
967 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 968 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
968 969
969 switch (event) { 970 switch (event) {
@@ -987,7 +988,7 @@ static int rt5640_hp_event(struct snd_soc_dapm_widget *w,
987static int rt5640_hp_power_event(struct snd_soc_dapm_widget *w, 988static int rt5640_hp_power_event(struct snd_soc_dapm_widget *w,
988 struct snd_kcontrol *kcontrol, int event) 989 struct snd_kcontrol *kcontrol, int event)
989{ 990{
990 struct snd_soc_codec *codec = w->codec; 991 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
991 992
992 switch (event) { 993 switch (event) {
993 case SND_SOC_DAPM_POST_PMU: 994 case SND_SOC_DAPM_POST_PMU:
@@ -1003,7 +1004,7 @@ static int rt5640_hp_power_event(struct snd_soc_dapm_widget *w,
1003static int rt5640_hp_post_event(struct snd_soc_dapm_widget *w, 1004static int rt5640_hp_post_event(struct snd_soc_dapm_widget *w,
1004 struct snd_kcontrol *kcontrol, int event) 1005 struct snd_kcontrol *kcontrol, int event)
1005{ 1006{
1006 struct snd_soc_codec *codec = w->codec; 1007 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1007 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 1008 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
1008 1009
1009 switch (event) { 1010 switch (event) {
@@ -2124,6 +2125,7 @@ MODULE_DEVICE_TABLE(of, rt5640_of_match);
2124static struct acpi_device_id rt5640_acpi_match[] = { 2125static struct acpi_device_id rt5640_acpi_match[] = {
2125 { "INT33CA", 0 }, 2126 { "INT33CA", 0 },
2126 { "10EC5640", 0 }, 2127 { "10EC5640", 0 },
2128 { "10EC5642", 0 },
2127 { }, 2129 { },
2128}; 2130};
2129MODULE_DEVICE_TABLE(acpi, rt5640_acpi_match); 2131MODULE_DEVICE_TABLE(acpi, rt5640_acpi_match);
diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index 27141e2df878..3e16a889a806 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -31,6 +31,7 @@
31#include "rt5645.h" 31#include "rt5645.h"
32 32
33#define RT5645_DEVICE_ID 0x6308 33#define RT5645_DEVICE_ID 0x6308
34#define RT5650_DEVICE_ID 0x6419
34 35
35#define RT5645_PR_RANGE_BASE (0xff + 1) 36#define RT5645_PR_RANGE_BASE (0xff + 1)
36#define RT5645_PR_SPACING 0x100 37#define RT5645_PR_SPACING 0x100
@@ -59,6 +60,10 @@ static const struct reg_default init_list[] = {
59}; 60};
60#define RT5645_INIT_REG_LEN ARRAY_SIZE(init_list) 61#define RT5645_INIT_REG_LEN ARRAY_SIZE(init_list)
61 62
63static const struct reg_default rt5650_init_list[] = {
64 {0xf6, 0x0100},
65};
66
62static const struct reg_default rt5645_reg[] = { 67static const struct reg_default rt5645_reg[] = {
63 { 0x00, 0x0000 }, 68 { 0x00, 0x0000 },
64 { 0x01, 0xc8c8 }, 69 { 0x01, 0xc8c8 },
@@ -86,6 +91,7 @@ static const struct reg_default rt5645_reg[] = {
86 { 0x2a, 0x5656 }, 91 { 0x2a, 0x5656 },
87 { 0x2b, 0x5454 }, 92 { 0x2b, 0x5454 },
88 { 0x2c, 0xaaa0 }, 93 { 0x2c, 0xaaa0 },
94 { 0x2d, 0x0000 },
89 { 0x2f, 0x1002 }, 95 { 0x2f, 0x1002 },
90 { 0x31, 0x5000 }, 96 { 0x31, 0x5000 },
91 { 0x32, 0x0000 }, 97 { 0x32, 0x0000 },
@@ -193,6 +199,8 @@ static const struct reg_default rt5645_reg[] = {
193 { 0xdb, 0x0003 }, 199 { 0xdb, 0x0003 },
194 { 0xdc, 0x0049 }, 200 { 0xdc, 0x0049 },
195 { 0xdd, 0x001b }, 201 { 0xdd, 0x001b },
202 { 0xdf, 0x0008 },
203 { 0xe0, 0x4000 },
196 { 0xe6, 0x8000 }, 204 { 0xe6, 0x8000 },
197 { 0xe7, 0x0200 }, 205 { 0xe7, 0x0200 },
198 { 0xec, 0xb300 }, 206 { 0xec, 0xb300 },
@@ -242,6 +250,7 @@ static bool rt5645_volatile_register(struct device *dev, unsigned int reg)
242 case RT5645_IRQ_CTRL3: 250 case RT5645_IRQ_CTRL3:
243 case RT5645_INT_IRQ_ST: 251 case RT5645_INT_IRQ_ST:
244 case RT5645_IL_CMD: 252 case RT5645_IL_CMD:
253 case RT5650_4BTN_IL_CMD1:
245 case RT5645_VENDOR_ID: 254 case RT5645_VENDOR_ID:
246 case RT5645_VENDOR_ID1: 255 case RT5645_VENDOR_ID1:
247 case RT5645_VENDOR_ID2: 256 case RT5645_VENDOR_ID2:
@@ -287,6 +296,7 @@ static bool rt5645_readable_register(struct device *dev, unsigned int reg)
287 case RT5645_STO_DAC_MIXER: 296 case RT5645_STO_DAC_MIXER:
288 case RT5645_MONO_DAC_MIXER: 297 case RT5645_MONO_DAC_MIXER:
289 case RT5645_DIG_MIXER: 298 case RT5645_DIG_MIXER:
299 case RT5650_A_DAC_SOUR:
290 case RT5645_DIG_INF1_DATA: 300 case RT5645_DIG_INF1_DATA:
291 case RT5645_PDM_OUT_CTRL: 301 case RT5645_PDM_OUT_CTRL:
292 case RT5645_REC_L1_MIXER: 302 case RT5645_REC_L1_MIXER:
@@ -378,6 +388,8 @@ static bool rt5645_readable_register(struct device *dev, unsigned int reg)
378 case RT5645_IL_CMD: 388 case RT5645_IL_CMD:
379 case RT5645_IL_CMD2: 389 case RT5645_IL_CMD2:
380 case RT5645_IL_CMD3: 390 case RT5645_IL_CMD3:
391 case RT5650_4BTN_IL_CMD1:
392 case RT5650_4BTN_IL_CMD2:
381 case RT5645_DRC1_HL_CTRL1: 393 case RT5645_DRC1_HL_CTRL1:
382 case RT5645_DRC2_HL_CTRL1: 394 case RT5645_DRC2_HL_CTRL1:
383 case RT5645_ADC_MONO_HP_CTRL1: 395 case RT5645_ADC_MONO_HP_CTRL1:
@@ -527,7 +539,7 @@ static const struct snd_kcontrol_new rt5645_snd_controls[] = {
527static int set_dmic_clk(struct snd_soc_dapm_widget *w, 539static int set_dmic_clk(struct snd_soc_dapm_widget *w,
528 struct snd_kcontrol *kcontrol, int event) 540 struct snd_kcontrol *kcontrol, int event)
529{ 541{
530 struct snd_soc_codec *codec = w->codec; 542 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
531 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); 543 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
532 int idx = -EINVAL; 544 int idx = -EINVAL;
533 545
@@ -544,9 +556,10 @@ static int set_dmic_clk(struct snd_soc_dapm_widget *w,
544static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source, 556static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source,
545 struct snd_soc_dapm_widget *sink) 557 struct snd_soc_dapm_widget *sink)
546{ 558{
559 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
547 unsigned int val; 560 unsigned int val;
548 561
549 val = snd_soc_read(source->codec, RT5645_GLB_CLK); 562 val = snd_soc_read(codec, RT5645_GLB_CLK);
550 val &= RT5645_SCLK_SRC_MASK; 563 val &= RT5645_SCLK_SRC_MASK;
551 if (val == RT5645_SCLK_SRC_PLL1) 564 if (val == RT5645_SCLK_SRC_PLL1)
552 return 1; 565 return 1;
@@ -557,6 +570,7 @@ static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source,
557static int is_using_asrc(struct snd_soc_dapm_widget *source, 570static int is_using_asrc(struct snd_soc_dapm_widget *source,
558 struct snd_soc_dapm_widget *sink) 571 struct snd_soc_dapm_widget *sink)
559{ 572{
573 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
560 unsigned int reg, shift, val; 574 unsigned int reg, shift, val;
561 575
562 switch (source->shift) { 576 switch (source->shift) {
@@ -588,7 +602,7 @@ static int is_using_asrc(struct snd_soc_dapm_widget *source,
588 return 0; 602 return 0;
589 } 603 }
590 604
591 val = (snd_soc_read(source->codec, reg) >> shift) & 0xf; 605 val = (snd_soc_read(codec, reg) >> shift) & 0xf;
592 switch (val) { 606 switch (val) {
593 case 1: 607 case 1:
594 case 2: 608 case 2:
@@ -1007,6 +1021,44 @@ static SOC_ENUM_SINGLE_DECL(
1007static const struct snd_kcontrol_new rt5645_if1_adc_in_mux = 1021static const struct snd_kcontrol_new rt5645_if1_adc_in_mux =
1008 SOC_DAPM_ENUM("IF1 ADC IN source", rt5645_if1_adc_in_enum); 1022 SOC_DAPM_ENUM("IF1 ADC IN source", rt5645_if1_adc_in_enum);
1009 1023
1024/* MX-2d [3] [2] */
1025static const char * const rt5650_a_dac1_src[] = {
1026 "DAC1", "Stereo DAC Mixer"
1027};
1028
1029static SOC_ENUM_SINGLE_DECL(
1030 rt5650_a_dac1_l_enum, RT5650_A_DAC_SOUR,
1031 RT5650_A_DAC1_L_IN_SFT, rt5650_a_dac1_src);
1032
1033static const struct snd_kcontrol_new rt5650_a_dac1_l_mux =
1034 SOC_DAPM_ENUM("A DAC1 L source", rt5650_a_dac1_l_enum);
1035
1036static SOC_ENUM_SINGLE_DECL(
1037 rt5650_a_dac1_r_enum, RT5650_A_DAC_SOUR,
1038 RT5650_A_DAC1_R_IN_SFT, rt5650_a_dac1_src);
1039
1040static const struct snd_kcontrol_new rt5650_a_dac1_r_mux =
1041 SOC_DAPM_ENUM("A DAC1 R source", rt5650_a_dac1_r_enum);
1042
1043/* MX-2d [1] [0] */
1044static const char * const rt5650_a_dac2_src[] = {
1045 "Stereo DAC Mixer", "Mono DAC Mixer"
1046};
1047
1048static SOC_ENUM_SINGLE_DECL(
1049 rt5650_a_dac2_l_enum, RT5650_A_DAC_SOUR,
1050 RT5650_A_DAC2_L_IN_SFT, rt5650_a_dac2_src);
1051
1052static const struct snd_kcontrol_new rt5650_a_dac2_l_mux =
1053 SOC_DAPM_ENUM("A DAC2 L source", rt5650_a_dac2_l_enum);
1054
1055static SOC_ENUM_SINGLE_DECL(
1056 rt5650_a_dac2_r_enum, RT5650_A_DAC_SOUR,
1057 RT5650_A_DAC2_R_IN_SFT, rt5650_a_dac2_src);
1058
1059static const struct snd_kcontrol_new rt5650_a_dac2_r_mux =
1060 SOC_DAPM_ENUM("A DAC2 R source", rt5650_a_dac2_r_enum);
1061
1010/* MX-2F [13:12] */ 1062/* MX-2F [13:12] */
1011static const char * const rt5645_if2_adc_in_src[] = { 1063static const char * const rt5645_if2_adc_in_src[] = {
1012 "IF_ADC1", "IF_ADC2", "VAD_ADC" 1064 "IF_ADC1", "IF_ADC2", "VAD_ADC"
@@ -1144,18 +1196,23 @@ static void hp_amp_power(struct snd_soc_codec *codec, int on)
1144static int rt5645_hp_event(struct snd_soc_dapm_widget *w, 1196static int rt5645_hp_event(struct snd_soc_dapm_widget *w,
1145 struct snd_kcontrol *kcontrol, int event) 1197 struct snd_kcontrol *kcontrol, int event)
1146{ 1198{
1147 struct snd_soc_codec *codec = w->codec; 1199 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1148 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); 1200 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec);
1149 1201
1150 switch (event) { 1202 switch (event) {
1151 case SND_SOC_DAPM_POST_PMU: 1203 case SND_SOC_DAPM_POST_PMU:
1152 hp_amp_power(codec, 1); 1204 hp_amp_power(codec, 1);
1153 /* headphone unmute sequence */ 1205 /* headphone unmute sequence */
1154 snd_soc_update_bits(codec, RT5645_DEPOP_M3, RT5645_CP_FQ1_MASK | 1206 if (rt5645->codec_type == CODEC_TYPE_RT5650) {
1155 RT5645_CP_FQ2_MASK | RT5645_CP_FQ3_MASK, 1207 snd_soc_write(codec, RT5645_DEPOP_M3, 0x0737);
1156 (RT5645_CP_FQ_192_KHZ << RT5645_CP_FQ1_SFT) | 1208 } else {
1157 (RT5645_CP_FQ_12_KHZ << RT5645_CP_FQ2_SFT) | 1209 snd_soc_update_bits(codec, RT5645_DEPOP_M3,
1158 (RT5645_CP_FQ_192_KHZ << RT5645_CP_FQ3_SFT)); 1210 RT5645_CP_FQ1_MASK | RT5645_CP_FQ2_MASK |
1211 RT5645_CP_FQ3_MASK,
1212 (RT5645_CP_FQ_192_KHZ << RT5645_CP_FQ1_SFT) |
1213 (RT5645_CP_FQ_12_KHZ << RT5645_CP_FQ2_SFT) |
1214 (RT5645_CP_FQ_192_KHZ << RT5645_CP_FQ3_SFT));
1215 }
1159 regmap_write(rt5645->regmap, 1216 regmap_write(rt5645->regmap,
1160 RT5645_PR_BASE + RT5645_MAMP_INT_REG2, 0xfc00); 1217 RT5645_PR_BASE + RT5645_MAMP_INT_REG2, 0xfc00);
1161 snd_soc_update_bits(codec, RT5645_DEPOP_M1, 1218 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
@@ -1175,12 +1232,16 @@ static int rt5645_hp_event(struct snd_soc_dapm_widget *w,
1175 1232
1176 case SND_SOC_DAPM_PRE_PMD: 1233 case SND_SOC_DAPM_PRE_PMD:
1177 /* headphone mute sequence */ 1234 /* headphone mute sequence */
1178 snd_soc_update_bits(codec, RT5645_DEPOP_M3, 1235 if (rt5645->codec_type == CODEC_TYPE_RT5650) {
1179 RT5645_CP_FQ1_MASK | RT5645_CP_FQ2_MASK | 1236 snd_soc_write(codec, RT5645_DEPOP_M3, 0x0737);
1180 RT5645_CP_FQ3_MASK, 1237 } else {
1181 (RT5645_CP_FQ_96_KHZ << RT5645_CP_FQ1_SFT) | 1238 snd_soc_update_bits(codec, RT5645_DEPOP_M3,
1182 (RT5645_CP_FQ_12_KHZ << RT5645_CP_FQ2_SFT) | 1239 RT5645_CP_FQ1_MASK | RT5645_CP_FQ2_MASK |
1183 (RT5645_CP_FQ_96_KHZ << RT5645_CP_FQ3_SFT)); 1240 RT5645_CP_FQ3_MASK,
1241 (RT5645_CP_FQ_96_KHZ << RT5645_CP_FQ1_SFT) |
1242 (RT5645_CP_FQ_12_KHZ << RT5645_CP_FQ2_SFT) |
1243 (RT5645_CP_FQ_96_KHZ << RT5645_CP_FQ3_SFT));
1244 }
1184 regmap_write(rt5645->regmap, 1245 regmap_write(rt5645->regmap,
1185 RT5645_PR_BASE + RT5645_MAMP_INT_REG2, 0xfc00); 1246 RT5645_PR_BASE + RT5645_MAMP_INT_REG2, 0xfc00);
1186 snd_soc_update_bits(codec, RT5645_DEPOP_M1, 1247 snd_soc_update_bits(codec, RT5645_DEPOP_M1,
@@ -1205,7 +1266,7 @@ static int rt5645_hp_event(struct snd_soc_dapm_widget *w,
1205static int rt5645_spk_event(struct snd_soc_dapm_widget *w, 1266static int rt5645_spk_event(struct snd_soc_dapm_widget *w,
1206 struct snd_kcontrol *kcontrol, int event) 1267 struct snd_kcontrol *kcontrol, int event)
1207{ 1268{
1208 struct snd_soc_codec *codec = w->codec; 1269 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1209 1270
1210 switch (event) { 1271 switch (event) {
1211 case SND_SOC_DAPM_POST_PMU: 1272 case SND_SOC_DAPM_POST_PMU:
@@ -1232,7 +1293,7 @@ static int rt5645_spk_event(struct snd_soc_dapm_widget *w,
1232static int rt5645_lout_event(struct snd_soc_dapm_widget *w, 1293static int rt5645_lout_event(struct snd_soc_dapm_widget *w,
1233 struct snd_kcontrol *kcontrol, int event) 1294 struct snd_kcontrol *kcontrol, int event)
1234{ 1295{
1235 struct snd_soc_codec *codec = w->codec; 1296 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1236 1297
1237 switch (event) { 1298 switch (event) {
1238 case SND_SOC_DAPM_POST_PMU: 1299 case SND_SOC_DAPM_POST_PMU:
@@ -1262,7 +1323,7 @@ static int rt5645_lout_event(struct snd_soc_dapm_widget *w,
1262static int rt5645_bst2_event(struct snd_soc_dapm_widget *w, 1323static int rt5645_bst2_event(struct snd_soc_dapm_widget *w,
1263 struct snd_kcontrol *kcontrol, int event) 1324 struct snd_kcontrol *kcontrol, int event)
1264{ 1325{
1265 struct snd_soc_codec *codec = w->codec; 1326 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1266 1327
1267 switch (event) { 1328 switch (event) {
1268 case SND_SOC_DAPM_POST_PMU: 1329 case SND_SOC_DAPM_POST_PMU:
@@ -1574,6 +1635,17 @@ static const struct snd_soc_dapm_widget rt5645_dapm_widgets[] = {
1574 SND_SOC_DAPM_OUTPUT("SPOR"), 1635 SND_SOC_DAPM_OUTPUT("SPOR"),
1575}; 1636};
1576 1637
1638static const struct snd_soc_dapm_widget rt5650_specific_dapm_widgets[] = {
1639 SND_SOC_DAPM_MUX("A DAC1 L Mux", SND_SOC_NOPM,
1640 0, 0, &rt5650_a_dac1_l_mux),
1641 SND_SOC_DAPM_MUX("A DAC1 R Mux", SND_SOC_NOPM,
1642 0, 0, &rt5650_a_dac1_r_mux),
1643 SND_SOC_DAPM_MUX("A DAC2 L Mux", SND_SOC_NOPM,
1644 0, 0, &rt5650_a_dac2_l_mux),
1645 SND_SOC_DAPM_MUX("A DAC2 R Mux", SND_SOC_NOPM,
1646 0, 0, &rt5650_a_dac2_r_mux),
1647};
1648
1577static const struct snd_soc_dapm_route rt5645_dapm_routes[] = { 1649static const struct snd_soc_dapm_route rt5645_dapm_routes[] = {
1578 { "adc stereo1 filter", NULL, "ADC STO1 ASRC", is_using_asrc }, 1650 { "adc stereo1 filter", NULL, "ADC STO1 ASRC", is_using_asrc },
1579 { "adc stereo2 filter", NULL, "ADC STO2 ASRC", is_using_asrc }, 1651 { "adc stereo2 filter", NULL, "ADC STO2 ASRC", is_using_asrc },
@@ -1779,13 +1851,9 @@ static const struct snd_soc_dapm_route rt5645_dapm_routes[] = {
1779 { "DAC MIXR", "DAC R2 Switch", "DAC R2 Volume" }, 1851 { "DAC MIXR", "DAC R2 Switch", "DAC R2 Volume" },
1780 { "DAC MIXR", "DAC L2 Switch", "DAC L2 Volume" }, 1852 { "DAC MIXR", "DAC L2 Switch", "DAC L2 Volume" },
1781 1853
1782 { "DAC L1", NULL, "Stereo DAC MIXL" },
1783 { "DAC L1", NULL, "PLL1", is_sys_clk_from_pll }, 1854 { "DAC L1", NULL, "PLL1", is_sys_clk_from_pll },
1784 { "DAC R1", NULL, "Stereo DAC MIXR" },
1785 { "DAC R1", NULL, "PLL1", is_sys_clk_from_pll }, 1855 { "DAC R1", NULL, "PLL1", is_sys_clk_from_pll },
1786 { "DAC L2", NULL, "Mono DAC MIXL" },
1787 { "DAC L2", NULL, "PLL1", is_sys_clk_from_pll }, 1856 { "DAC L2", NULL, "PLL1", is_sys_clk_from_pll },
1788 { "DAC R2", NULL, "Mono DAC MIXR" },
1789 { "DAC R2", NULL, "PLL1", is_sys_clk_from_pll }, 1857 { "DAC R2", NULL, "PLL1", is_sys_clk_from_pll },
1790 1858
1791 { "SPK MIXL", "BST1 Switch", "BST1" }, 1859 { "SPK MIXL", "BST1 Switch", "BST1" },
@@ -1874,6 +1942,30 @@ static const struct snd_soc_dapm_route rt5645_dapm_routes[] = {
1874 { "SPOR", NULL, "SPK amp" }, 1942 { "SPOR", NULL, "SPK amp" },
1875}; 1943};
1876 1944
1945static const struct snd_soc_dapm_route rt5650_specific_dapm_routes[] = {
1946 { "A DAC1 L Mux", "DAC1", "DAC1 MIXL"},
1947 { "A DAC1 L Mux", "Stereo DAC Mixer", "Stereo DAC MIXL"},
1948 { "A DAC1 R Mux", "DAC1", "DAC1 MIXR"},
1949 { "A DAC1 R Mux", "Stereo DAC Mixer", "Stereo DAC MIXR"},
1950
1951 { "A DAC2 L Mux", "Stereo DAC Mixer", "Stereo DAC MIXL"},
1952 { "A DAC2 L Mux", "Mono DAC Mixer", "Mono DAC MIXL"},
1953 { "A DAC2 R Mux", "Stereo DAC Mixer", "Stereo DAC MIXR"},
1954 { "A DAC2 R Mux", "Mono DAC Mixer", "Mono DAC MIXR"},
1955
1956 { "DAC L1", NULL, "A DAC1 L Mux" },
1957 { "DAC R1", NULL, "A DAC1 R Mux" },
1958 { "DAC L2", NULL, "A DAC2 L Mux" },
1959 { "DAC R2", NULL, "A DAC2 R Mux" },
1960};
1961
1962static const struct snd_soc_dapm_route rt5645_specific_dapm_routes[] = {
1963 { "DAC L1", NULL, "Stereo DAC MIXL" },
1964 { "DAC R1", NULL, "Stereo DAC MIXR" },
1965 { "DAC L2", NULL, "Mono DAC MIXL" },
1966 { "DAC R2", NULL, "Mono DAC MIXR" },
1967};
1968
1877static int rt5645_hw_params(struct snd_pcm_substream *substream, 1969static int rt5645_hw_params(struct snd_pcm_substream *substream,
1878 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 1970 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
1879{ 1971{
@@ -2293,6 +2385,22 @@ static int rt5645_probe(struct snd_soc_codec *codec)
2293 2385
2294 rt5645->codec = codec; 2386 rt5645->codec = codec;
2295 2387
2388 switch (rt5645->codec_type) {
2389 case CODEC_TYPE_RT5645:
2390 snd_soc_dapm_add_routes(&codec->dapm,
2391 rt5645_specific_dapm_routes,
2392 ARRAY_SIZE(rt5645_specific_dapm_routes));
2393 break;
2394 case CODEC_TYPE_RT5650:
2395 snd_soc_dapm_new_controls(&codec->dapm,
2396 rt5650_specific_dapm_widgets,
2397 ARRAY_SIZE(rt5650_specific_dapm_widgets));
2398 snd_soc_dapm_add_routes(&codec->dapm,
2399 rt5650_specific_dapm_routes,
2400 ARRAY_SIZE(rt5650_specific_dapm_routes));
2401 break;
2402 }
2403
2296 rt5645_set_bias_level(codec, SND_SOC_BIAS_OFF); 2404 rt5645_set_bias_level(codec, SND_SOC_BIAS_OFF);
2297 2405
2298 snd_soc_update_bits(codec, RT5645_CHARGE_PUMP, 0x0300, 0x0200); 2406 snd_soc_update_bits(codec, RT5645_CHARGE_PUMP, 0x0300, 0x0200);
@@ -2424,6 +2532,7 @@ static const struct regmap_config rt5645_regmap = {
2424 2532
2425static const struct i2c_device_id rt5645_i2c_id[] = { 2533static const struct i2c_device_id rt5645_i2c_id[] = {
2426 { "rt5645", 0 }, 2534 { "rt5645", 0 },
2535 { "rt5650", 0 },
2427 { } 2536 { }
2428}; 2537};
2429MODULE_DEVICE_TABLE(i2c, rt5645_i2c_id); 2538MODULE_DEVICE_TABLE(i2c, rt5645_i2c_id);
@@ -2456,9 +2565,18 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
2456 } 2565 }
2457 2566
2458 regmap_read(rt5645->regmap, RT5645_VENDOR_ID2, &val); 2567 regmap_read(rt5645->regmap, RT5645_VENDOR_ID2, &val);
2459 if (val != RT5645_DEVICE_ID) { 2568
2569 switch (val) {
2570 case RT5645_DEVICE_ID:
2571 rt5645->codec_type = CODEC_TYPE_RT5645;
2572 break;
2573 case RT5650_DEVICE_ID:
2574 rt5645->codec_type = CODEC_TYPE_RT5650;
2575 break;
2576 default:
2460 dev_err(&i2c->dev, 2577 dev_err(&i2c->dev,
2461 "Device with ID register %x is not rt5645\n", val); 2578 "Device with ID register %x is not rt5645 or rt5650\n",
2579 val);
2462 return -ENODEV; 2580 return -ENODEV;
2463 } 2581 }
2464 2582
@@ -2469,6 +2587,14 @@ static int rt5645_i2c_probe(struct i2c_client *i2c,
2469 if (ret != 0) 2587 if (ret != 0)
2470 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret); 2588 dev_warn(&i2c->dev, "Failed to apply regmap patch: %d\n", ret);
2471 2589
2590 if (rt5645->codec_type == CODEC_TYPE_RT5650) {
2591 ret = regmap_register_patch(rt5645->regmap, rt5650_init_list,
2592 ARRAY_SIZE(rt5650_init_list));
2593 if (ret != 0)
2594 dev_warn(&i2c->dev, "Apply rt5650 patch failed: %d\n",
2595 ret);
2596 }
2597
2472 if (rt5645->pdata.in2_diff) 2598 if (rt5645->pdata.in2_diff)
2473 regmap_update_bits(rt5645->regmap, RT5645_IN2_CTRL, 2599 regmap_update_bits(rt5645->regmap, RT5645_IN2_CTRL,
2474 RT5645_IN_DF2, RT5645_IN_DF2); 2600 RT5645_IN_DF2, RT5645_IN_DF2);
diff --git a/sound/soc/codecs/rt5645.h b/sound/soc/codecs/rt5645.h
index a815e36a2bdb..74542310d3f0 100644
--- a/sound/soc/codecs/rt5645.h
+++ b/sound/soc/codecs/rt5645.h
@@ -47,6 +47,7 @@
47#define RT5645_STO_DAC_MIXER 0x2a 47#define RT5645_STO_DAC_MIXER 0x2a
48#define RT5645_MONO_DAC_MIXER 0x2b 48#define RT5645_MONO_DAC_MIXER 0x2b
49#define RT5645_DIG_MIXER 0x2c 49#define RT5645_DIG_MIXER 0x2c
50#define RT5650_A_DAC_SOUR 0x2d
50#define RT5645_DIG_INF1_DATA 0x2f 51#define RT5645_DIG_INF1_DATA 0x2f
51/* Mixer - PDM */ 52/* Mixer - PDM */
52#define RT5645_PDM_OUT_CTRL 0x31 53#define RT5645_PDM_OUT_CTRL 0x31
@@ -150,6 +151,8 @@
150#define RT5645_IL_CMD 0xdb 151#define RT5645_IL_CMD 0xdb
151#define RT5645_IL_CMD2 0xdc 152#define RT5645_IL_CMD2 0xdc
152#define RT5645_IL_CMD3 0xdd 153#define RT5645_IL_CMD3 0xdd
154#define RT5650_4BTN_IL_CMD1 0xdf
155#define RT5650_4BTN_IL_CMD2 0xe0
153#define RT5645_DRC1_HL_CTRL1 0xe7 156#define RT5645_DRC1_HL_CTRL1 0xe7
154#define RT5645_DRC2_HL_CTRL1 0xe9 157#define RT5645_DRC2_HL_CTRL1 0xe9
155#define RT5645_MUTI_DRC_CTRL1 0xea 158#define RT5645_MUTI_DRC_CTRL1 0xea
@@ -472,6 +475,12 @@
472#define RT5645_DAC_L2_DAC_R_VOL_MASK (0x1 << 4) 475#define RT5645_DAC_L2_DAC_R_VOL_MASK (0x1 << 4)
473#define RT5645_DAC_L2_DAC_R_VOL_SFT 4 476#define RT5645_DAC_L2_DAC_R_VOL_SFT 4
474 477
478/* Analog DAC1/2 Input Source Control (0x2d) */
479#define RT5650_A_DAC1_L_IN_SFT 3
480#define RT5650_A_DAC1_R_IN_SFT 2
481#define RT5650_A_DAC2_L_IN_SFT 1
482#define RT5650_A_DAC2_R_IN_SFT 0
483
475/* Digital Interface Data Control (0x2f) */ 484/* Digital Interface Data Control (0x2f) */
476#define RT5645_IF1_ADC2_IN_SEL (0x1 << 15) 485#define RT5645_IF1_ADC2_IN_SEL (0x1 << 15)
477#define RT5645_IF1_ADC2_IN_SFT 15 486#define RT5645_IF1_ADC2_IN_SFT 15
@@ -2175,6 +2184,11 @@ enum {
2175 RT5645_DMIC_DATA_GPIO11, 2184 RT5645_DMIC_DATA_GPIO11,
2176}; 2185};
2177 2186
2187enum {
2188 CODEC_TYPE_RT5645,
2189 CODEC_TYPE_RT5650,
2190};
2191
2178struct rt5645_priv { 2192struct rt5645_priv {
2179 struct snd_soc_codec *codec; 2193 struct snd_soc_codec *codec;
2180 struct rt5645_platform_data pdata; 2194 struct rt5645_platform_data pdata;
@@ -2184,6 +2198,7 @@ struct rt5645_priv {
2184 struct snd_soc_jack *mic_jack; 2198 struct snd_soc_jack *mic_jack;
2185 struct delayed_work jack_detect_work; 2199 struct delayed_work jack_detect_work;
2186 2200
2201 int codec_type;
2187 int sysclk; 2202 int sysclk;
2188 int sysclk_src; 2203 int sysclk_src;
2189 int lrck[RT5645_AIFS]; 2204 int lrck[RT5645_AIFS];
diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c
index bb0a3ab5416c..9f4c7be6d798 100644
--- a/sound/soc/codecs/rt5651.c
+++ b/sound/soc/codecs/rt5651.c
@@ -376,7 +376,7 @@ static const struct snd_kcontrol_new rt5651_snd_controls[] = {
376static int set_dmic_clk(struct snd_soc_dapm_widget *w, 376static int set_dmic_clk(struct snd_soc_dapm_widget *w,
377 struct snd_kcontrol *kcontrol, int event) 377 struct snd_kcontrol *kcontrol, int event)
378{ 378{
379 struct snd_soc_codec *codec = w->codec; 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 = -EINVAL;
382 382
@@ -394,9 +394,10 @@ static int set_dmic_clk(struct snd_soc_dapm_widget *w,
394static int is_sysclk_from_pll(struct snd_soc_dapm_widget *source, 394static int is_sysclk_from_pll(struct snd_soc_dapm_widget *source,
395 struct snd_soc_dapm_widget *sink) 395 struct snd_soc_dapm_widget *sink)
396{ 396{
397 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
397 unsigned int val; 398 unsigned int val;
398 399
399 val = snd_soc_read(source->codec, RT5651_GLB_CLK); 400 val = snd_soc_read(codec, RT5651_GLB_CLK);
400 val &= RT5651_SCLK_SRC_MASK; 401 val &= RT5651_SCLK_SRC_MASK;
401 if (val == RT5651_SCLK_SRC_PLL1) 402 if (val == RT5651_SCLK_SRC_PLL1)
402 return 1; 403 return 1;
@@ -731,7 +732,7 @@ static const struct snd_kcontrol_new rt5651_pdm_r_mux =
731static int rt5651_amp_power_event(struct snd_soc_dapm_widget *w, 732static int rt5651_amp_power_event(struct snd_soc_dapm_widget *w,
732 struct snd_kcontrol *kcontrol, int event) 733 struct snd_kcontrol *kcontrol, int event)
733{ 734{
734 struct snd_soc_codec *codec = w->codec; 735 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
735 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); 736 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec);
736 737
737 switch (event) { 738 switch (event) {
@@ -769,7 +770,7 @@ static int rt5651_amp_power_event(struct snd_soc_dapm_widget *w,
769static int rt5651_hp_event(struct snd_soc_dapm_widget *w, 770static int rt5651_hp_event(struct snd_soc_dapm_widget *w,
770 struct snd_kcontrol *kcontrol, int event) 771 struct snd_kcontrol *kcontrol, int event)
771{ 772{
772 struct snd_soc_codec *codec = w->codec; 773 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
773 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); 774 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec);
774 775
775 switch (event) { 776 switch (event) {
@@ -813,7 +814,8 @@ static int rt5651_hp_event(struct snd_soc_dapm_widget *w,
813static int rt5651_hp_post_event(struct snd_soc_dapm_widget *w, 814static int rt5651_hp_post_event(struct snd_soc_dapm_widget *w,
814 struct snd_kcontrol *kcontrol, int event) 815 struct snd_kcontrol *kcontrol, int event)
815{ 816{
816 struct snd_soc_codec *codec = w->codec; 817
818 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
817 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); 819 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec);
818 820
819 switch (event) { 821 switch (event) {
@@ -833,7 +835,7 @@ static int rt5651_hp_post_event(struct snd_soc_dapm_widget *w,
833static int rt5651_bst1_event(struct snd_soc_dapm_widget *w, 835static int rt5651_bst1_event(struct snd_soc_dapm_widget *w,
834 struct snd_kcontrol *kcontrol, int event) 836 struct snd_kcontrol *kcontrol, int event)
835{ 837{
836 struct snd_soc_codec *codec = w->codec; 838 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
837 839
838 switch (event) { 840 switch (event) {
839 case SND_SOC_DAPM_POST_PMU: 841 case SND_SOC_DAPM_POST_PMU:
@@ -856,7 +858,7 @@ static int rt5651_bst1_event(struct snd_soc_dapm_widget *w,
856static int rt5651_bst2_event(struct snd_soc_dapm_widget *w, 858static int rt5651_bst2_event(struct snd_soc_dapm_widget *w,
857 struct snd_kcontrol *kcontrol, int event) 859 struct snd_kcontrol *kcontrol, int event)
858{ 860{
859 struct snd_soc_codec *codec = w->codec; 861 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
860 862
861 switch (event) { 863 switch (event) {
862 case SND_SOC_DAPM_POST_PMU: 864 case SND_SOC_DAPM_POST_PMU:
@@ -879,7 +881,7 @@ static int rt5651_bst2_event(struct snd_soc_dapm_widget *w,
879static int rt5651_bst3_event(struct snd_soc_dapm_widget *w, 881static int rt5651_bst3_event(struct snd_soc_dapm_widget *w,
880 struct snd_kcontrol *kcontrol, int event) 882 struct snd_kcontrol *kcontrol, int event)
881{ 883{
882 struct snd_soc_codec *codec = w->codec; 884 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
883 885
884 switch (event) { 886 switch (event) {
885 case SND_SOC_DAPM_POST_PMU: 887 case SND_SOC_DAPM_POST_PMU:
diff --git a/sound/soc/codecs/rt5670.c b/sound/soc/codecs/rt5670.c
index 0a027bc94399..7b3d6b5992f1 100644
--- a/sound/soc/codecs/rt5670.c
+++ b/sound/soc/codecs/rt5670.c
@@ -500,7 +500,7 @@ static const struct snd_kcontrol_new rt5670_snd_controls[] = {
500static int set_dmic_clk(struct snd_soc_dapm_widget *w, 500static int set_dmic_clk(struct snd_soc_dapm_widget *w,
501 struct snd_kcontrol *kcontrol, int event) 501 struct snd_kcontrol *kcontrol, int event)
502{ 502{
503 struct snd_soc_codec *codec = w->codec; 503 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
504 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 504 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec);
505 int idx = -EINVAL; 505 int idx = -EINVAL;
506 506
@@ -517,9 +517,10 @@ static int set_dmic_clk(struct snd_soc_dapm_widget *w,
517static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source, 517static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source,
518 struct snd_soc_dapm_widget *sink) 518 struct snd_soc_dapm_widget *sink)
519{ 519{
520 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
520 unsigned int val; 521 unsigned int val;
521 522
522 val = snd_soc_read(source->codec, RT5670_GLB_CLK); 523 val = snd_soc_read(codec, RT5670_GLB_CLK);
523 val &= RT5670_SCLK_SRC_MASK; 524 val &= RT5670_SCLK_SRC_MASK;
524 if (val == RT5670_SCLK_SRC_PLL1) 525 if (val == RT5670_SCLK_SRC_PLL1)
525 return 1; 526 return 1;
@@ -530,6 +531,7 @@ static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source,
530static int is_using_asrc(struct snd_soc_dapm_widget *source, 531static int is_using_asrc(struct snd_soc_dapm_widget *source,
531 struct snd_soc_dapm_widget *sink) 532 struct snd_soc_dapm_widget *sink)
532{ 533{
534 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
533 unsigned int reg, shift, val; 535 unsigned int reg, shift, val;
534 536
535 switch (source->shift) { 537 switch (source->shift) {
@@ -565,7 +567,7 @@ static int is_using_asrc(struct snd_soc_dapm_widget *source,
565 return 0; 567 return 0;
566 } 568 }
567 569
568 val = (snd_soc_read(source->codec, reg) >> shift) & 0xf; 570 val = (snd_soc_read(codec, reg) >> shift) & 0xf;
569 switch (val) { 571 switch (val) {
570 case 1: 572 case 1:
571 case 2: 573 case 2:
@@ -590,6 +592,89 @@ static int can_use_asrc(struct snd_soc_dapm_widget *source,
590 return 0; 592 return 0;
591} 593}
592 594
595
596/**
597 * rt5670_sel_asrc_clk_src - select ASRC clock source for a set of filters
598 * @codec: SoC audio codec device.
599 * @filter_mask: mask of filters.
600 * @clk_src: clock source
601 *
602 * The ASRC function is for asynchronous MCLK and LRCK. Also, since RT5670 can
603 * only support standard 32fs or 64fs i2s format, ASRC should be enabled to
604 * support special i2s clock format such as Intel's 100fs(100 * sampling rate).
605 * ASRC function will track i2s clock and generate a corresponding system clock
606 * for codec. This function provides an API to select the clock source for a
607 * set of filters specified by the mask. And the codec driver will turn on ASRC
608 * for these filters if ASRC is selected as their clock source.
609 */
610int rt5670_sel_asrc_clk_src(struct snd_soc_codec *codec,
611 unsigned int filter_mask, unsigned int clk_src)
612{
613 unsigned int asrc2_mask = 0, asrc2_value = 0;
614 unsigned int asrc3_mask = 0, asrc3_value = 0;
615
616 if (clk_src > RT5670_CLK_SEL_SYS3)
617 return -EINVAL;
618
619 if (filter_mask & RT5670_DA_STEREO_FILTER) {
620 asrc2_mask |= RT5670_DA_STO_CLK_SEL_MASK;
621 asrc2_value = (asrc2_value & ~RT5670_DA_STO_CLK_SEL_MASK)
622 | (clk_src << RT5670_DA_STO_CLK_SEL_SFT);
623 }
624
625 if (filter_mask & RT5670_DA_MONO_L_FILTER) {
626 asrc2_mask |= RT5670_DA_MONOL_CLK_SEL_MASK;
627 asrc2_value = (asrc2_value & ~RT5670_DA_MONOL_CLK_SEL_MASK)
628 | (clk_src << RT5670_DA_MONOL_CLK_SEL_SFT);
629 }
630
631 if (filter_mask & RT5670_DA_MONO_R_FILTER) {
632 asrc2_mask |= RT5670_DA_MONOR_CLK_SEL_MASK;
633 asrc2_value = (asrc2_value & ~RT5670_DA_MONOR_CLK_SEL_MASK)
634 | (clk_src << RT5670_DA_MONOR_CLK_SEL_SFT);
635 }
636
637 if (filter_mask & RT5670_AD_STEREO_FILTER) {
638 asrc2_mask |= RT5670_AD_STO1_CLK_SEL_MASK;
639 asrc2_value = (asrc2_value & ~RT5670_AD_STO1_CLK_SEL_MASK)
640 | (clk_src << RT5670_AD_STO1_CLK_SEL_SFT);
641 }
642
643 if (filter_mask & RT5670_AD_MONO_L_FILTER) {
644 asrc3_mask |= RT5670_AD_MONOL_CLK_SEL_MASK;
645 asrc3_value = (asrc3_value & ~RT5670_AD_MONOL_CLK_SEL_MASK)
646 | (clk_src << RT5670_AD_MONOL_CLK_SEL_SFT);
647 }
648
649 if (filter_mask & RT5670_AD_MONO_R_FILTER) {
650 asrc3_mask |= RT5670_AD_MONOR_CLK_SEL_MASK;
651 asrc3_value = (asrc3_value & ~RT5670_AD_MONOR_CLK_SEL_MASK)
652 | (clk_src << RT5670_AD_MONOR_CLK_SEL_SFT);
653 }
654
655 if (filter_mask & RT5670_UP_RATE_FILTER) {
656 asrc3_mask |= RT5670_UP_CLK_SEL_MASK;
657 asrc3_value = (asrc3_value & ~RT5670_UP_CLK_SEL_MASK)
658 | (clk_src << RT5670_UP_CLK_SEL_SFT);
659 }
660
661 if (filter_mask & RT5670_DOWN_RATE_FILTER) {
662 asrc3_mask |= RT5670_DOWN_CLK_SEL_MASK;
663 asrc3_value = (asrc3_value & ~RT5670_DOWN_CLK_SEL_MASK)
664 | (clk_src << RT5670_DOWN_CLK_SEL_SFT);
665 }
666
667 if (asrc2_mask)
668 snd_soc_update_bits(codec, RT5670_ASRC_2,
669 asrc2_mask, asrc2_value);
670
671 if (asrc3_mask)
672 snd_soc_update_bits(codec, RT5670_ASRC_3,
673 asrc3_mask, asrc3_value);
674 return 0;
675}
676EXPORT_SYMBOL_GPL(rt5670_sel_asrc_clk_src);
677
593/* Digital Mixer */ 678/* Digital Mixer */
594static const struct snd_kcontrol_new rt5670_sto1_adc_l_mix[] = { 679static const struct snd_kcontrol_new rt5670_sto1_adc_l_mix[] = {
595 SOC_DAPM_SINGLE("ADC1 Switch", RT5670_STO1_ADC_MIXER, 680 SOC_DAPM_SINGLE("ADC1 Switch", RT5670_STO1_ADC_MIXER,
@@ -1148,7 +1233,7 @@ static const struct snd_kcontrol_new rt5670_vad_adc_mux =
1148static int rt5670_hp_power_event(struct snd_soc_dapm_widget *w, 1233static int rt5670_hp_power_event(struct snd_soc_dapm_widget *w,
1149 struct snd_kcontrol *kcontrol, int event) 1234 struct snd_kcontrol *kcontrol, int event)
1150{ 1235{
1151 struct snd_soc_codec *codec = w->codec; 1236 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1152 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 1237 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec);
1153 1238
1154 switch (event) { 1239 switch (event) {
@@ -1184,7 +1269,7 @@ static int rt5670_hp_power_event(struct snd_soc_dapm_widget *w,
1184static int rt5670_hp_event(struct snd_soc_dapm_widget *w, 1269static int rt5670_hp_event(struct snd_soc_dapm_widget *w,
1185 struct snd_kcontrol *kcontrol, int event) 1270 struct snd_kcontrol *kcontrol, int event)
1186{ 1271{
1187 struct snd_soc_codec *codec = w->codec; 1272 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1188 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 1273 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec);
1189 1274
1190 switch (event) { 1275 switch (event) {
@@ -1234,7 +1319,7 @@ static int rt5670_hp_event(struct snd_soc_dapm_widget *w,
1234static int rt5670_bst1_event(struct snd_soc_dapm_widget *w, 1319static int rt5670_bst1_event(struct snd_soc_dapm_widget *w,
1235 struct snd_kcontrol *kcontrol, int event) 1320 struct snd_kcontrol *kcontrol, int event)
1236{ 1321{
1237 struct snd_soc_codec *codec = w->codec; 1322 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1238 1323
1239 switch (event) { 1324 switch (event) {
1240 case SND_SOC_DAPM_POST_PMU: 1325 case SND_SOC_DAPM_POST_PMU:
@@ -1257,7 +1342,7 @@ static int rt5670_bst1_event(struct snd_soc_dapm_widget *w,
1257static int rt5670_bst2_event(struct snd_soc_dapm_widget *w, 1342static int rt5670_bst2_event(struct snd_soc_dapm_widget *w,
1258 struct snd_kcontrol *kcontrol, int event) 1343 struct snd_kcontrol *kcontrol, int event)
1259{ 1344{
1260 struct snd_soc_codec *codec = w->codec; 1345 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1261 1346
1262 switch (event) { 1347 switch (event) {
1263 case SND_SOC_DAPM_POST_PMU: 1348 case SND_SOC_DAPM_POST_PMU:
diff --git a/sound/soc/codecs/rt5670.h b/sound/soc/codecs/rt5670.h
index d11b9c207e26..21f8e18c13c4 100644
--- a/sound/soc/codecs/rt5670.h
+++ b/sound/soc/codecs/rt5670.h
@@ -1023,50 +1023,33 @@
1023#define RT5670_DMIC_2_M_NOR (0x0 << 8) 1023#define RT5670_DMIC_2_M_NOR (0x0 << 8)
1024#define RT5670_DMIC_2_M_ASYN (0x1 << 8) 1024#define RT5670_DMIC_2_M_ASYN (0x1 << 8)
1025 1025
1026/* ASRC clock source selection (0x84, 0x85) */
1027#define RT5670_CLK_SEL_SYS (0x0)
1028#define RT5670_CLK_SEL_I2S1_ASRC (0x1)
1029#define RT5670_CLK_SEL_I2S2_ASRC (0x2)
1030#define RT5670_CLK_SEL_I2S3_ASRC (0x3)
1031#define RT5670_CLK_SEL_SYS2 (0x5)
1032#define RT5670_CLK_SEL_SYS3 (0x6)
1033
1026/* ASRC Control 2 (0x84) */ 1034/* ASRC Control 2 (0x84) */
1027#define RT5670_MDA_L_M_MASK (0x1 << 15) 1035#define RT5670_DA_STO_CLK_SEL_MASK (0xf << 12)
1028#define RT5670_MDA_L_M_SFT 15 1036#define RT5670_DA_STO_CLK_SEL_SFT 12
1029#define RT5670_MDA_L_M_NOR (0x0 << 15) 1037#define RT5670_DA_MONOL_CLK_SEL_MASK (0xf << 8)
1030#define RT5670_MDA_L_M_ASYN (0x1 << 15) 1038#define RT5670_DA_MONOL_CLK_SEL_SFT 8
1031#define RT5670_MDA_R_M_MASK (0x1 << 14) 1039#define RT5670_DA_MONOR_CLK_SEL_MASK (0xf << 4)
1032#define RT5670_MDA_R_M_SFT 14 1040#define RT5670_DA_MONOR_CLK_SEL_SFT 4
1033#define RT5670_MDA_R_M_NOR (0x0 << 14) 1041#define RT5670_AD_STO1_CLK_SEL_MASK (0xf << 0)
1034#define RT5670_MDA_R_M_ASYN (0x1 << 14) 1042#define RT5670_AD_STO1_CLK_SEL_SFT 0
1035#define RT5670_MAD_L_M_MASK (0x1 << 13)
1036#define RT5670_MAD_L_M_SFT 13
1037#define RT5670_MAD_L_M_NOR (0x0 << 13)
1038#define RT5670_MAD_L_M_ASYN (0x1 << 13)
1039#define RT5670_MAD_R_M_MASK (0x1 << 12)
1040#define RT5670_MAD_R_M_SFT 12
1041#define RT5670_MAD_R_M_NOR (0x0 << 12)
1042#define RT5670_MAD_R_M_ASYN (0x1 << 12)
1043#define RT5670_ADC_M_MASK (0x1 << 11)
1044#define RT5670_ADC_M_SFT 11
1045#define RT5670_ADC_M_NOR (0x0 << 11)
1046#define RT5670_ADC_M_ASYN (0x1 << 11)
1047#define RT5670_STO_DAC_M_MASK (0x1 << 5)
1048#define RT5670_STO_DAC_M_SFT 5
1049#define RT5670_STO_DAC_M_NOR (0x0 << 5)
1050#define RT5670_STO_DAC_M_ASYN (0x1 << 5)
1051#define RT5670_I2S1_R_D_MASK (0x1 << 4)
1052#define RT5670_I2S1_R_D_SFT 4
1053#define RT5670_I2S1_R_D_DIS (0x0 << 4)
1054#define RT5670_I2S1_R_D_EN (0x1 << 4)
1055#define RT5670_I2S2_R_D_MASK (0x1 << 3)
1056#define RT5670_I2S2_R_D_SFT 3
1057#define RT5670_I2S2_R_D_DIS (0x0 << 3)
1058#define RT5670_I2S2_R_D_EN (0x1 << 3)
1059#define RT5670_PRE_SCLK_MASK (0x3)
1060#define RT5670_PRE_SCLK_SFT 0
1061#define RT5670_PRE_SCLK_512 (0x0)
1062#define RT5670_PRE_SCLK_1024 (0x1)
1063#define RT5670_PRE_SCLK_2048 (0x2)
1064 1043
1065/* ASRC Control 3 (0x85) */ 1044/* ASRC Control 3 (0x85) */
1066#define RT5670_I2S1_RATE_MASK (0xf << 12) 1045#define RT5670_UP_CLK_SEL_MASK (0xf << 12)
1067#define RT5670_I2S1_RATE_SFT 12 1046#define RT5670_UP_CLK_SEL_SFT 12
1068#define RT5670_I2S2_RATE_MASK (0xf << 8) 1047#define RT5670_DOWN_CLK_SEL_MASK (0xf << 8)
1069#define RT5670_I2S2_RATE_SFT 8 1048#define RT5670_DOWN_CLK_SEL_SFT 8
1049#define RT5670_AD_MONOL_CLK_SEL_MASK (0xf << 4)
1050#define RT5670_AD_MONOL_CLK_SEL_SFT 4
1051#define RT5670_AD_MONOR_CLK_SEL_MASK (0xf << 0)
1052#define RT5670_AD_MONOR_CLK_SEL_SFT 0
1070 1053
1071/* ASRC Control 4 (0x89) */ 1054/* ASRC Control 4 (0x89) */
1072#define RT5670_I2S1_PD_MASK (0x7 << 12) 1055#define RT5670_I2S1_PD_MASK (0x7 << 12)
@@ -1983,6 +1966,21 @@ enum {
1983 RT5670_DMIC_DATA_GPIO5, 1966 RT5670_DMIC_DATA_GPIO5,
1984}; 1967};
1985 1968
1969/* filter mask */
1970enum {
1971 RT5670_DA_STEREO_FILTER = 0x1,
1972 RT5670_DA_MONO_L_FILTER = (0x1 << 1),
1973 RT5670_DA_MONO_R_FILTER = (0x1 << 2),
1974 RT5670_AD_STEREO_FILTER = (0x1 << 3),
1975 RT5670_AD_MONO_L_FILTER = (0x1 << 4),
1976 RT5670_AD_MONO_R_FILTER = (0x1 << 5),
1977 RT5670_UP_RATE_FILTER = (0x1 << 6),
1978 RT5670_DOWN_RATE_FILTER = (0x1 << 7),
1979};
1980
1981int rt5670_sel_asrc_clk_src(struct snd_soc_codec *codec,
1982 unsigned int filter_mask, unsigned int clk_src);
1983
1986struct rt5670_priv { 1984struct rt5670_priv {
1987 struct snd_soc_codec *codec; 1985 struct snd_soc_codec *codec;
1988 struct rt5670_platform_data pdata; 1986 struct rt5670_platform_data pdata;
diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c
index d27630accf03..5d0bb8748dd1 100644
--- a/sound/soc/codecs/rt5677.c
+++ b/sound/soc/codecs/rt5677.c
@@ -702,6 +702,9 @@ static int rt5677_set_dsp_vad(struct snd_soc_codec *codec, bool on)
702 static bool activity; 702 static bool activity;
703 int ret; 703 int ret;
704 704
705 if (!IS_ENABLED(CONFIG_SND_SOC_RT5677_SPI))
706 return -ENXIO;
707
705 if (on && !activity) { 708 if (on && !activity) {
706 activity = true; 709 activity = true;
707 710
@@ -896,7 +899,7 @@ static const struct snd_kcontrol_new rt5677_snd_controls[] = {
896static int set_dmic_clk(struct snd_soc_dapm_widget *w, 899static int set_dmic_clk(struct snd_soc_dapm_widget *w,
897 struct snd_kcontrol *kcontrol, int event) 900 struct snd_kcontrol *kcontrol, int event)
898{ 901{
899 struct snd_soc_codec *codec = w->codec; 902 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
900 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 903 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
901 int idx = rl6231_calc_dmic_clk(rt5677->sysclk); 904 int idx = rl6231_calc_dmic_clk(rt5677->sysclk);
902 905
@@ -911,7 +914,8 @@ static int set_dmic_clk(struct snd_soc_dapm_widget *w,
911static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source, 914static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source,
912 struct snd_soc_dapm_widget *sink) 915 struct snd_soc_dapm_widget *sink)
913{ 916{
914 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(source->codec); 917 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
918 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
915 unsigned int val; 919 unsigned int val;
916 920
917 regmap_read(rt5677->regmap, RT5677_GLB_CLK1, &val); 921 regmap_read(rt5677->regmap, RT5677_GLB_CLK1, &val);
@@ -925,6 +929,8 @@ static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source,
925static int is_using_asrc(struct snd_soc_dapm_widget *source, 929static int is_using_asrc(struct snd_soc_dapm_widget *source,
926 struct snd_soc_dapm_widget *sink) 930 struct snd_soc_dapm_widget *sink)
927{ 931{
932 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
933 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
928 unsigned int reg, shift, val; 934 unsigned int reg, shift, val;
929 935
930 if (source->reg == RT5677_ASRC_1) { 936 if (source->reg == RT5677_ASRC_1) {
@@ -991,7 +997,9 @@ static int is_using_asrc(struct snd_soc_dapm_widget *source,
991 } 997 }
992 } 998 }
993 999
994 val = (snd_soc_read(source->codec, reg) >> shift) & 0xf; 1000 regmap_read(rt5677->regmap, reg, &val);
1001 val = (val >> shift) & 0xf;
1002
995 switch (val) { 1003 switch (val) {
996 case 1 ... 6: 1004 case 1 ... 6:
997 return 1; 1005 return 1;
@@ -2122,7 +2130,7 @@ static const struct snd_kcontrol_new rt5677_if2_dac7_tdm_sel_mux =
2122static int rt5677_bst1_event(struct snd_soc_dapm_widget *w, 2130static int rt5677_bst1_event(struct snd_soc_dapm_widget *w,
2123 struct snd_kcontrol *kcontrol, int event) 2131 struct snd_kcontrol *kcontrol, int event)
2124{ 2132{
2125 struct snd_soc_codec *codec = w->codec; 2133 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
2126 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 2134 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
2127 2135
2128 switch (event) { 2136 switch (event) {
@@ -2146,7 +2154,7 @@ static int rt5677_bst1_event(struct snd_soc_dapm_widget *w,
2146static int rt5677_bst2_event(struct snd_soc_dapm_widget *w, 2154static int rt5677_bst2_event(struct snd_soc_dapm_widget *w,
2147 struct snd_kcontrol *kcontrol, int event) 2155 struct snd_kcontrol *kcontrol, int event)
2148{ 2156{
2149 struct snd_soc_codec *codec = w->codec; 2157 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
2150 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 2158 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
2151 2159
2152 switch (event) { 2160 switch (event) {
@@ -2170,7 +2178,7 @@ static int rt5677_bst2_event(struct snd_soc_dapm_widget *w,
2170static int rt5677_set_pll1_event(struct snd_soc_dapm_widget *w, 2178static int rt5677_set_pll1_event(struct snd_soc_dapm_widget *w,
2171 struct snd_kcontrol *kcontrol, int event) 2179 struct snd_kcontrol *kcontrol, int event)
2172{ 2180{
2173 struct snd_soc_codec *codec = w->codec; 2181 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
2174 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 2182 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
2175 2183
2176 switch (event) { 2184 switch (event) {
@@ -2192,7 +2200,7 @@ static int rt5677_set_pll1_event(struct snd_soc_dapm_widget *w,
2192static int rt5677_set_pll2_event(struct snd_soc_dapm_widget *w, 2200static int rt5677_set_pll2_event(struct snd_soc_dapm_widget *w,
2193 struct snd_kcontrol *kcontrol, int event) 2201 struct snd_kcontrol *kcontrol, int event)
2194{ 2202{
2195 struct snd_soc_codec *codec = w->codec; 2203 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
2196 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 2204 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
2197 2205
2198 switch (event) { 2206 switch (event) {
@@ -2214,7 +2222,7 @@ static int rt5677_set_pll2_event(struct snd_soc_dapm_widget *w,
2214static int rt5677_set_micbias1_event(struct snd_soc_dapm_widget *w, 2222static int rt5677_set_micbias1_event(struct snd_soc_dapm_widget *w,
2215 struct snd_kcontrol *kcontrol, int event) 2223 struct snd_kcontrol *kcontrol, int event)
2216{ 2224{
2217 struct snd_soc_codec *codec = w->codec; 2225 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
2218 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 2226 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
2219 2227
2220 switch (event) { 2228 switch (event) {
@@ -2241,7 +2249,7 @@ static int rt5677_set_micbias1_event(struct snd_soc_dapm_widget *w,
2241static int rt5677_if1_adc_tdm_event(struct snd_soc_dapm_widget *w, 2249static int rt5677_if1_adc_tdm_event(struct snd_soc_dapm_widget *w,
2242 struct snd_kcontrol *kcontrol, int event) 2250 struct snd_kcontrol *kcontrol, int event)
2243{ 2251{
2244 struct snd_soc_codec *codec = w->codec; 2252 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
2245 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 2253 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
2246 unsigned int value; 2254 unsigned int value;
2247 2255
@@ -2264,7 +2272,7 @@ static int rt5677_if1_adc_tdm_event(struct snd_soc_dapm_widget *w,
2264static int rt5677_if2_adc_tdm_event(struct snd_soc_dapm_widget *w, 2272static int rt5677_if2_adc_tdm_event(struct snd_soc_dapm_widget *w,
2265 struct snd_kcontrol *kcontrol, int event) 2273 struct snd_kcontrol *kcontrol, int event)
2266{ 2274{
2267 struct snd_soc_codec *codec = w->codec; 2275 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
2268 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 2276 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
2269 unsigned int value; 2277 unsigned int value;
2270 2278
@@ -2287,7 +2295,7 @@ static int rt5677_if2_adc_tdm_event(struct snd_soc_dapm_widget *w,
2287static int rt5677_vref_event(struct snd_soc_dapm_widget *w, 2295static int rt5677_vref_event(struct snd_soc_dapm_widget *w,
2288 struct snd_kcontrol *kcontrol, int event) 2296 struct snd_kcontrol *kcontrol, int event)
2289{ 2297{
2290 struct snd_soc_codec *codec = w->codec; 2298 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
2291 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 2299 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
2292 2300
2293 switch (event) { 2301 switch (event) {
@@ -4098,7 +4106,8 @@ static int rt5677_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
4098 unsigned int rx_mask, int slots, int slot_width) 4106 unsigned int rx_mask, int slots, int slot_width)
4099{ 4107{
4100 struct snd_soc_codec *codec = dai->codec; 4108 struct snd_soc_codec *codec = dai->codec;
4101 unsigned int val = 0; 4109 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
4110 unsigned int val = 0, slot_width_25 = 0;
4102 4111
4103 if (rx_mask || tx_mask) 4112 if (rx_mask || tx_mask)
4104 val |= (1 << 12); 4113 val |= (1 << 12);
@@ -4122,6 +4131,8 @@ static int rt5677_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
4122 case 20: 4131 case 20:
4123 val |= (1 << 8); 4132 val |= (1 << 8);
4124 break; 4133 break;
4134 case 25:
4135 slot_width_25 = 0x8080;
4125 case 24: 4136 case 24:
4126 val |= (2 << 8); 4137 val |= (2 << 8);
4127 break; 4138 break;
@@ -4135,10 +4146,16 @@ static int rt5677_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
4135 4146
4136 switch (dai->id) { 4147 switch (dai->id) {
4137 case RT5677_AIF1: 4148 case RT5677_AIF1:
4138 snd_soc_update_bits(codec, RT5677_TDM1_CTRL1, 0x1f00, val); 4149 regmap_update_bits(rt5677->regmap, RT5677_TDM1_CTRL1, 0x1f00,
4150 val);
4151 regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, 0x8000,
4152 slot_width_25);
4139 break; 4153 break;
4140 case RT5677_AIF2: 4154 case RT5677_AIF2:
4141 snd_soc_update_bits(codec, RT5677_TDM2_CTRL1, 0x1f00, val); 4155 regmap_update_bits(rt5677->regmap, RT5677_TDM2_CTRL1, 0x1f00,
4156 val);
4157 regmap_update_bits(rt5677->regmap, RT5677_DIG_MISC, 0x80,
4158 slot_width_25);
4142 break; 4159 break;
4143 default: 4160 default:
4144 break; 4161 break;
@@ -4923,6 +4940,11 @@ static int rt5677_i2c_probe(struct i2c_client *i2c,
4923 RT5677_GPIO5_DIR_OUT); 4940 RT5677_GPIO5_DIR_OUT);
4924 } 4941 }
4925 4942
4943 if (rt5677->pdata.micbias1_vdd_3v3)
4944 regmap_update_bits(rt5677->regmap, RT5677_MICBIAS,
4945 RT5677_MICBIAS1_CTRL_VDD_MASK,
4946 RT5677_MICBIAS1_CTRL_VDD_3_3V);
4947
4926 rt5677_init_gpio(i2c); 4948 rt5677_init_gpio(i2c);
4927 rt5677_init_irq(i2c); 4949 rt5677_init_irq(i2c);
4928 4950
diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index 29cf7ce610f4..e182e6569bbd 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -155,18 +155,19 @@ struct sgtl5000_priv {
155static int mic_bias_event(struct snd_soc_dapm_widget *w, 155static int mic_bias_event(struct snd_soc_dapm_widget *w,
156 struct snd_kcontrol *kcontrol, int event) 156 struct snd_kcontrol *kcontrol, int event)
157{ 157{
158 struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(w->codec); 158 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
159 struct sgtl5000_priv *sgtl5000 = snd_soc_codec_get_drvdata(codec);
159 160
160 switch (event) { 161 switch (event) {
161 case SND_SOC_DAPM_POST_PMU: 162 case SND_SOC_DAPM_POST_PMU:
162 /* change mic bias resistor */ 163 /* change mic bias resistor */
163 snd_soc_update_bits(w->codec, SGTL5000_CHIP_MIC_CTRL, 164 snd_soc_update_bits(codec, SGTL5000_CHIP_MIC_CTRL,
164 SGTL5000_BIAS_R_MASK, 165 SGTL5000_BIAS_R_MASK,
165 sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT); 166 sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT);
166 break; 167 break;
167 168
168 case SND_SOC_DAPM_PRE_PMD: 169 case SND_SOC_DAPM_PRE_PMD:
169 snd_soc_update_bits(w->codec, SGTL5000_CHIP_MIC_CTRL, 170 snd_soc_update_bits(codec, SGTL5000_CHIP_MIC_CTRL,
170 SGTL5000_BIAS_R_MASK, 0); 171 SGTL5000_BIAS_R_MASK, 0);
171 break; 172 break;
172 } 173 }
@@ -181,11 +182,12 @@ static int mic_bias_event(struct snd_soc_dapm_widget *w,
181static int power_vag_event(struct snd_soc_dapm_widget *w, 182static int power_vag_event(struct snd_soc_dapm_widget *w,
182 struct snd_kcontrol *kcontrol, int event) 183 struct snd_kcontrol *kcontrol, int event)
183{ 184{
185 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
184 const u32 mask = SGTL5000_DAC_POWERUP | SGTL5000_ADC_POWERUP; 186 const u32 mask = SGTL5000_DAC_POWERUP | SGTL5000_ADC_POWERUP;
185 187
186 switch (event) { 188 switch (event) {
187 case SND_SOC_DAPM_POST_PMU: 189 case SND_SOC_DAPM_POST_PMU:
188 snd_soc_update_bits(w->codec, SGTL5000_CHIP_ANA_POWER, 190 snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
189 SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP); 191 SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
190 break; 192 break;
191 193
@@ -195,9 +197,9 @@ static int power_vag_event(struct snd_soc_dapm_widget *w,
195 * operational to prevent inadvertently starving the 197 * operational to prevent inadvertently starving the
196 * other one of them. 198 * other one of them.
197 */ 199 */
198 if ((snd_soc_read(w->codec, SGTL5000_CHIP_ANA_POWER) & 200 if ((snd_soc_read(codec, SGTL5000_CHIP_ANA_POWER) &
199 mask) != mask) { 201 mask) != mask) {
200 snd_soc_update_bits(w->codec, SGTL5000_CHIP_ANA_POWER, 202 snd_soc_update_bits(codec, SGTL5000_CHIP_ANA_POWER,
201 SGTL5000_VAG_POWERUP, 0); 203 SGTL5000_VAG_POWERUP, 0);
202 msleep(400); 204 msleep(400);
203 } 205 }
@@ -483,21 +485,21 @@ static int sgtl5000_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
483 /* setting i2s data format */ 485 /* setting i2s data format */
484 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 486 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
485 case SND_SOC_DAIFMT_DSP_A: 487 case SND_SOC_DAIFMT_DSP_A:
486 i2sctl |= SGTL5000_I2S_MODE_PCM; 488 i2sctl |= SGTL5000_I2S_MODE_PCM << SGTL5000_I2S_MODE_SHIFT;
487 break; 489 break;
488 case SND_SOC_DAIFMT_DSP_B: 490 case SND_SOC_DAIFMT_DSP_B:
489 i2sctl |= SGTL5000_I2S_MODE_PCM; 491 i2sctl |= SGTL5000_I2S_MODE_PCM << SGTL5000_I2S_MODE_SHIFT;
490 i2sctl |= SGTL5000_I2S_LRALIGN; 492 i2sctl |= SGTL5000_I2S_LRALIGN;
491 break; 493 break;
492 case SND_SOC_DAIFMT_I2S: 494 case SND_SOC_DAIFMT_I2S:
493 i2sctl |= SGTL5000_I2S_MODE_I2S_LJ; 495 i2sctl |= SGTL5000_I2S_MODE_I2S_LJ << SGTL5000_I2S_MODE_SHIFT;
494 break; 496 break;
495 case SND_SOC_DAIFMT_RIGHT_J: 497 case SND_SOC_DAIFMT_RIGHT_J:
496 i2sctl |= SGTL5000_I2S_MODE_RJ; 498 i2sctl |= SGTL5000_I2S_MODE_RJ << SGTL5000_I2S_MODE_SHIFT;
497 i2sctl |= SGTL5000_I2S_LRPOL; 499 i2sctl |= SGTL5000_I2S_LRPOL;
498 break; 500 break;
499 case SND_SOC_DAIFMT_LEFT_J: 501 case SND_SOC_DAIFMT_LEFT_J:
500 i2sctl |= SGTL5000_I2S_MODE_I2S_LJ; 502 i2sctl |= SGTL5000_I2S_MODE_I2S_LJ << SGTL5000_I2S_MODE_SHIFT;
501 i2sctl |= SGTL5000_I2S_LRALIGN; 503 i2sctl |= SGTL5000_I2S_LRALIGN;
502 break; 504 break;
503 default: 505 default:
@@ -1462,6 +1464,9 @@ static int sgtl5000_i2c_probe(struct i2c_client *client,
1462 if (ret) 1464 if (ret)
1463 return ret; 1465 return ret;
1464 1466
1467 /* Need 8 clocks before I2C accesses */
1468 udelay(1);
1469
1465 /* read chip information */ 1470 /* read chip information */
1466 ret = regmap_read(sgtl5000->regmap, SGTL5000_CHIP_ID, &reg); 1471 ret = regmap_read(sgtl5000->regmap, SGTL5000_CHIP_ID, &reg);
1467 if (ret) 1472 if (ret)
diff --git a/sound/soc/codecs/sn95031.c b/sound/soc/codecs/sn95031.c
index 1f451a1946eb..47b257e41809 100644
--- a/sound/soc/codecs/sn95031.c
+++ b/sound/soc/codecs/sn95031.c
@@ -233,16 +233,18 @@ static int sn95031_set_vaud_bias(struct snd_soc_codec *codec,
233static int sn95031_vhs_event(struct snd_soc_dapm_widget *w, 233static int sn95031_vhs_event(struct snd_soc_dapm_widget *w,
234 struct snd_kcontrol *kcontrol, int event) 234 struct snd_kcontrol *kcontrol, int event)
235{ 235{
236 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
237
236 if (SND_SOC_DAPM_EVENT_ON(event)) { 238 if (SND_SOC_DAPM_EVENT_ON(event)) {
237 pr_debug("VHS SND_SOC_DAPM_EVENT_ON doing rail startup now\n"); 239 pr_debug("VHS SND_SOC_DAPM_EVENT_ON doing rail startup now\n");
238 /* power up the rail */ 240 /* power up the rail */
239 snd_soc_write(w->codec, SN95031_VHSP, 0x3D); 241 snd_soc_write(codec, SN95031_VHSP, 0x3D);
240 snd_soc_write(w->codec, SN95031_VHSN, 0x3F); 242 snd_soc_write(codec, SN95031_VHSN, 0x3F);
241 msleep(1); 243 msleep(1);
242 } else if (SND_SOC_DAPM_EVENT_OFF(event)) { 244 } else if (SND_SOC_DAPM_EVENT_OFF(event)) {
243 pr_debug("VHS SND_SOC_DAPM_EVENT_OFF doing rail shutdown\n"); 245 pr_debug("VHS SND_SOC_DAPM_EVENT_OFF doing rail shutdown\n");
244 snd_soc_write(w->codec, SN95031_VHSP, 0xC4); 246 snd_soc_write(codec, SN95031_VHSP, 0xC4);
245 snd_soc_write(w->codec, SN95031_VHSN, 0x04); 247 snd_soc_write(codec, SN95031_VHSN, 0x04);
246 } 248 }
247 return 0; 249 return 0;
248} 250}
@@ -250,14 +252,16 @@ static int sn95031_vhs_event(struct snd_soc_dapm_widget *w,
250static int sn95031_vihf_event(struct snd_soc_dapm_widget *w, 252static int sn95031_vihf_event(struct snd_soc_dapm_widget *w,
251 struct snd_kcontrol *kcontrol, int event) 253 struct snd_kcontrol *kcontrol, int event)
252{ 254{
255 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
256
253 if (SND_SOC_DAPM_EVENT_ON(event)) { 257 if (SND_SOC_DAPM_EVENT_ON(event)) {
254 pr_debug("VIHF SND_SOC_DAPM_EVENT_ON doing rail startup now\n"); 258 pr_debug("VIHF SND_SOC_DAPM_EVENT_ON doing rail startup now\n");
255 /* power up the rail */ 259 /* power up the rail */
256 snd_soc_write(w->codec, SN95031_VIHF, 0x27); 260 snd_soc_write(codec, SN95031_VIHF, 0x27);
257 msleep(1); 261 msleep(1);
258 } else if (SND_SOC_DAPM_EVENT_OFF(event)) { 262 } else if (SND_SOC_DAPM_EVENT_OFF(event)) {
259 pr_debug("VIHF SND_SOC_DAPM_EVENT_OFF doing rail shutdown\n"); 263 pr_debug("VIHF SND_SOC_DAPM_EVENT_OFF doing rail shutdown\n");
260 snd_soc_write(w->codec, SN95031_VIHF, 0x24); 264 snd_soc_write(codec, SN95031_VIHF, 0x24);
261 } 265 }
262 return 0; 266 return 0;
263} 267}
@@ -265,6 +269,7 @@ static int sn95031_vihf_event(struct snd_soc_dapm_widget *w,
265static int sn95031_dmic12_event(struct snd_soc_dapm_widget *w, 269static int sn95031_dmic12_event(struct snd_soc_dapm_widget *w,
266 struct snd_kcontrol *k, int event) 270 struct snd_kcontrol *k, int event)
267{ 271{
272 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
268 unsigned int ldo = 0, clk_dir = 0, data_dir = 0; 273 unsigned int ldo = 0, clk_dir = 0, data_dir = 0;
269 274
270 if (SND_SOC_DAPM_EVENT_ON(event)) { 275 if (SND_SOC_DAPM_EVENT_ON(event)) {
@@ -273,15 +278,16 @@ static int sn95031_dmic12_event(struct snd_soc_dapm_widget *w,
273 data_dir = BIT(7); 278 data_dir = BIT(7);
274 } 279 }
275 /* program DMIC LDO, clock and set clock */ 280 /* program DMIC LDO, clock and set clock */
276 snd_soc_update_bits(w->codec, SN95031_MICBIAS, BIT(5)|BIT(4), ldo); 281 snd_soc_update_bits(codec, SN95031_MICBIAS, BIT(5)|BIT(4), ldo);
277 snd_soc_update_bits(w->codec, SN95031_DMICBUF0123, BIT(0), clk_dir); 282 snd_soc_update_bits(codec, SN95031_DMICBUF0123, BIT(0), clk_dir);
278 snd_soc_update_bits(w->codec, SN95031_DMICBUF0123, BIT(7), data_dir); 283 snd_soc_update_bits(codec, SN95031_DMICBUF0123, BIT(7), data_dir);
279 return 0; 284 return 0;
280} 285}
281 286
282static int sn95031_dmic34_event(struct snd_soc_dapm_widget *w, 287static int sn95031_dmic34_event(struct snd_soc_dapm_widget *w,
283 struct snd_kcontrol *k, int event) 288 struct snd_kcontrol *k, int event)
284{ 289{
290 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
285 unsigned int ldo = 0, clk_dir = 0, data_dir = 0; 291 unsigned int ldo = 0, clk_dir = 0, data_dir = 0;
286 292
287 if (SND_SOC_DAPM_EVENT_ON(event)) { 293 if (SND_SOC_DAPM_EVENT_ON(event)) {
@@ -290,22 +296,23 @@ static int sn95031_dmic34_event(struct snd_soc_dapm_widget *w,
290 data_dir = BIT(1); 296 data_dir = BIT(1);
291 } 297 }
292 /* program DMIC LDO, clock and set clock */ 298 /* program DMIC LDO, clock and set clock */
293 snd_soc_update_bits(w->codec, SN95031_MICBIAS, BIT(5)|BIT(4), ldo); 299 snd_soc_update_bits(codec, SN95031_MICBIAS, BIT(5)|BIT(4), ldo);
294 snd_soc_update_bits(w->codec, SN95031_DMICBUF0123, BIT(2), clk_dir); 300 snd_soc_update_bits(codec, SN95031_DMICBUF0123, BIT(2), clk_dir);
295 snd_soc_update_bits(w->codec, SN95031_DMICBUF45, BIT(1), data_dir); 301 snd_soc_update_bits(codec, SN95031_DMICBUF45, BIT(1), data_dir);
296 return 0; 302 return 0;
297} 303}
298 304
299static int sn95031_dmic56_event(struct snd_soc_dapm_widget *w, 305static int sn95031_dmic56_event(struct snd_soc_dapm_widget *w,
300 struct snd_kcontrol *k, int event) 306 struct snd_kcontrol *k, int event)
301{ 307{
308 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
302 unsigned int ldo = 0; 309 unsigned int ldo = 0;
303 310
304 if (SND_SOC_DAPM_EVENT_ON(event)) 311 if (SND_SOC_DAPM_EVENT_ON(event))
305 ldo = BIT(7)|BIT(6); 312 ldo = BIT(7)|BIT(6);
306 313
307 /* program DMIC LDO */ 314 /* program DMIC LDO */
308 snd_soc_update_bits(w->codec, SN95031_MICBIAS, BIT(7)|BIT(6), ldo); 315 snd_soc_update_bits(codec, SN95031_MICBIAS, BIT(7)|BIT(6), ldo);
309 return 0; 316 return 0;
310} 317}
311 318
diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c
index 7e18200dd6a9..3a1343fa109b 100644
--- a/sound/soc/codecs/sta32x.c
+++ b/sound/soc/codecs/sta32x.c
@@ -24,8 +24,11 @@
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/pm.h> 25#include <linux/pm.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/of_device.h>
28#include <linux/of_gpio.h>
27#include <linux/regmap.h> 29#include <linux/regmap.h>
28#include <linux/regulator/consumer.h> 30#include <linux/regulator/consumer.h>
31#include <linux/gpio/consumer.h>
29#include <linux/slab.h> 32#include <linux/slab.h>
30#include <linux/workqueue.h> 33#include <linux/workqueue.h>
31#include <sound/core.h> 34#include <sound/core.h>
@@ -102,6 +105,35 @@ static const struct reg_default sta32x_regs[] = {
102 { 0x2c, 0x0c }, 105 { 0x2c, 0x0c },
103}; 106};
104 107
108static const struct regmap_range sta32x_write_regs_range[] = {
109 regmap_reg_range(STA32X_CONFA, STA32X_AUTO2),
110 regmap_reg_range(STA32X_C1CFG, STA32X_FDRC2),
111};
112
113static const struct regmap_range sta32x_read_regs_range[] = {
114 regmap_reg_range(STA32X_CONFA, STA32X_AUTO2),
115 regmap_reg_range(STA32X_C1CFG, STA32X_FDRC2),
116};
117
118static const struct regmap_range sta32x_volatile_regs_range[] = {
119 regmap_reg_range(STA32X_CFADDR2, STA32X_CFUD),
120};
121
122static const struct regmap_access_table sta32x_write_regs = {
123 .yes_ranges = sta32x_write_regs_range,
124 .n_yes_ranges = ARRAY_SIZE(sta32x_write_regs_range),
125};
126
127static const struct regmap_access_table sta32x_read_regs = {
128 .yes_ranges = sta32x_read_regs_range,
129 .n_yes_ranges = ARRAY_SIZE(sta32x_read_regs_range),
130};
131
132static const struct regmap_access_table sta32x_volatile_regs = {
133 .yes_ranges = sta32x_volatile_regs_range,
134 .n_yes_ranges = ARRAY_SIZE(sta32x_volatile_regs_range),
135};
136
105/* regulator power supply names */ 137/* regulator power supply names */
106static const char *sta32x_supply_names[] = { 138static const char *sta32x_supply_names[] = {
107 "Vdda", /* analog supply, 3.3VV */ 139 "Vdda", /* analog supply, 3.3VV */
@@ -122,6 +154,8 @@ struct sta32x_priv {
122 u32 coef_shadow[STA32X_COEF_COUNT]; 154 u32 coef_shadow[STA32X_COEF_COUNT];
123 struct delayed_work watchdog_work; 155 struct delayed_work watchdog_work;
124 int shutdown; 156 int shutdown;
157 struct gpio_desc *gpiod_nreset;
158 struct mutex coeff_lock;
125}; 159};
126 160
127static const DECLARE_TLV_DB_SCALE(mvol_tlv, -12700, 50, 1); 161static const DECLARE_TLV_DB_SCALE(mvol_tlv, -12700, 50, 1);
@@ -155,37 +189,32 @@ static const char *sta32x_limiter_release_rate[] = {
155 "0.5116", "0.1370", "0.0744", "0.0499", "0.0360", "0.0299", 189 "0.5116", "0.1370", "0.0744", "0.0499", "0.0360", "0.0299",
156 "0.0264", "0.0208", "0.0198", "0.0172", "0.0147", "0.0137", 190 "0.0264", "0.0208", "0.0198", "0.0172", "0.0147", "0.0137",
157 "0.0134", "0.0117", "0.0110", "0.0104" }; 191 "0.0134", "0.0117", "0.0110", "0.0104" };
158 192static DECLARE_TLV_DB_RANGE(sta32x_limiter_ac_attack_tlv,
159static const unsigned int sta32x_limiter_ac_attack_tlv[] = {
160 TLV_DB_RANGE_HEAD(2),
161 0, 7, TLV_DB_SCALE_ITEM(-1200, 200, 0), 193 0, 7, TLV_DB_SCALE_ITEM(-1200, 200, 0),
162 8, 16, TLV_DB_SCALE_ITEM(300, 100, 0), 194 8, 16, TLV_DB_SCALE_ITEM(300, 100, 0),
163}; 195);
164 196
165static const unsigned int sta32x_limiter_ac_release_tlv[] = { 197static DECLARE_TLV_DB_RANGE(sta32x_limiter_ac_release_tlv,
166 TLV_DB_RANGE_HEAD(5),
167 0, 0, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 0), 198 0, 0, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 0),
168 1, 1, TLV_DB_SCALE_ITEM(-2900, 0, 0), 199 1, 1, TLV_DB_SCALE_ITEM(-2900, 0, 0),
169 2, 2, TLV_DB_SCALE_ITEM(-2000, 0, 0), 200 2, 2, TLV_DB_SCALE_ITEM(-2000, 0, 0),
170 3, 8, TLV_DB_SCALE_ITEM(-1400, 200, 0), 201 3, 8, TLV_DB_SCALE_ITEM(-1400, 200, 0),
171 8, 16, TLV_DB_SCALE_ITEM(-700, 100, 0), 202 8, 16, TLV_DB_SCALE_ITEM(-700, 100, 0),
172}; 203);
173 204
174static const unsigned int sta32x_limiter_drc_attack_tlv[] = { 205static DECLARE_TLV_DB_RANGE(sta32x_limiter_drc_attack_tlv,
175 TLV_DB_RANGE_HEAD(3),
176 0, 7, TLV_DB_SCALE_ITEM(-3100, 200, 0), 206 0, 7, TLV_DB_SCALE_ITEM(-3100, 200, 0),
177 8, 13, TLV_DB_SCALE_ITEM(-1600, 100, 0), 207 8, 13, TLV_DB_SCALE_ITEM(-1600, 100, 0),
178 14, 16, TLV_DB_SCALE_ITEM(-1000, 300, 0), 208 14, 16, TLV_DB_SCALE_ITEM(-1000, 300, 0),
179}; 209);
180 210
181static const unsigned int sta32x_limiter_drc_release_tlv[] = { 211static DECLARE_TLV_DB_RANGE(sta32x_limiter_drc_release_tlv,
182 TLV_DB_RANGE_HEAD(5),
183 0, 0, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 0), 212 0, 0, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 0),
184 1, 2, TLV_DB_SCALE_ITEM(-3800, 200, 0), 213 1, 2, TLV_DB_SCALE_ITEM(-3800, 200, 0),
185 3, 4, TLV_DB_SCALE_ITEM(-3300, 200, 0), 214 3, 4, TLV_DB_SCALE_ITEM(-3300, 200, 0),
186 5, 12, TLV_DB_SCALE_ITEM(-3000, 200, 0), 215 5, 12, TLV_DB_SCALE_ITEM(-3000, 200, 0),
187 13, 16, TLV_DB_SCALE_ITEM(-1500, 300, 0), 216 13, 16, TLV_DB_SCALE_ITEM(-1500, 300, 0),
188}; 217);
189 218
190static SOC_ENUM_SINGLE_DECL(sta32x_drc_ac_enum, 219static SOC_ENUM_SINGLE_DECL(sta32x_drc_ac_enum,
191 STA32X_CONFD, STA32X_CONFD_DRC_SHIFT, 220 STA32X_CONFD, STA32X_CONFD_DRC_SHIFT,
@@ -244,29 +273,42 @@ static int sta32x_coefficient_get(struct snd_kcontrol *kcontrol,
244 struct snd_ctl_elem_value *ucontrol) 273 struct snd_ctl_elem_value *ucontrol)
245{ 274{
246 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 275 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
276 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec);
247 int numcoef = kcontrol->private_value >> 16; 277 int numcoef = kcontrol->private_value >> 16;
248 int index = kcontrol->private_value & 0xffff; 278 int index = kcontrol->private_value & 0xffff;
249 unsigned int cfud; 279 unsigned int cfud, val;
250 int i; 280 int i, ret = 0;
281
282 mutex_lock(&sta32x->coeff_lock);
251 283
252 /* preserve reserved bits in STA32X_CFUD */ 284 /* preserve reserved bits in STA32X_CFUD */
253 cfud = snd_soc_read(codec, STA32X_CFUD) & 0xf0; 285 regmap_read(sta32x->regmap, STA32X_CFUD, &cfud);
254 /* chip documentation does not say if the bits are self clearing, 286 cfud &= 0xf0;
255 * so do it explicitly */ 287 /*
256 snd_soc_write(codec, STA32X_CFUD, cfud); 288 * chip documentation does not say if the bits are self clearing,
289 * so do it explicitly
290 */
291 regmap_write(sta32x->regmap, STA32X_CFUD, cfud);
257 292
258 snd_soc_write(codec, STA32X_CFADDR2, index); 293 regmap_write(sta32x->regmap, STA32X_CFADDR2, index);
259 if (numcoef == 1) 294 if (numcoef == 1) {
260 snd_soc_write(codec, STA32X_CFUD, cfud | 0x04); 295 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x04);
261 else if (numcoef == 5) 296 } else if (numcoef == 5) {
262 snd_soc_write(codec, STA32X_CFUD, cfud | 0x08); 297 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x08);
263 else 298 } else {
264 return -EINVAL; 299 ret = -EINVAL;
265 for (i = 0; i < 3 * numcoef; i++) 300 goto exit_unlock;
266 ucontrol->value.bytes.data[i] = 301 }
267 snd_soc_read(codec, STA32X_B1CF1 + i);
268 302
269 return 0; 303 for (i = 0; i < 3 * numcoef; i++) {
304 regmap_read(sta32x->regmap, STA32X_B1CF1 + i, &val);
305 ucontrol->value.bytes.data[i] = val;
306 }
307
308exit_unlock:
309 mutex_unlock(&sta32x->coeff_lock);
310
311 return ret;
270} 312}
271 313
272static int sta32x_coefficient_put(struct snd_kcontrol *kcontrol, 314static int sta32x_coefficient_put(struct snd_kcontrol *kcontrol,
@@ -280,24 +322,27 @@ static int sta32x_coefficient_put(struct snd_kcontrol *kcontrol,
280 int i; 322 int i;
281 323
282 /* preserve reserved bits in STA32X_CFUD */ 324 /* preserve reserved bits in STA32X_CFUD */
283 cfud = snd_soc_read(codec, STA32X_CFUD) & 0xf0; 325 regmap_read(sta32x->regmap, STA32X_CFUD, &cfud);
284 /* chip documentation does not say if the bits are self clearing, 326 cfud &= 0xf0;
285 * so do it explicitly */ 327 /*
286 snd_soc_write(codec, STA32X_CFUD, cfud); 328 * chip documentation does not say if the bits are self clearing,
329 * so do it explicitly
330 */
331 regmap_write(sta32x->regmap, STA32X_CFUD, cfud);
287 332
288 snd_soc_write(codec, STA32X_CFADDR2, index); 333 regmap_write(sta32x->regmap, STA32X_CFADDR2, index);
289 for (i = 0; i < numcoef && (index + i < STA32X_COEF_COUNT); i++) 334 for (i = 0; i < numcoef && (index + i < STA32X_COEF_COUNT); i++)
290 sta32x->coef_shadow[index + i] = 335 sta32x->coef_shadow[index + i] =
291 (ucontrol->value.bytes.data[3 * i] << 16) 336 (ucontrol->value.bytes.data[3 * i] << 16)
292 | (ucontrol->value.bytes.data[3 * i + 1] << 8) 337 | (ucontrol->value.bytes.data[3 * i + 1] << 8)
293 | (ucontrol->value.bytes.data[3 * i + 2]); 338 | (ucontrol->value.bytes.data[3 * i + 2]);
294 for (i = 0; i < 3 * numcoef; i++) 339 for (i = 0; i < 3 * numcoef; i++)
295 snd_soc_write(codec, STA32X_B1CF1 + i, 340 regmap_write(sta32x->regmap, STA32X_B1CF1 + i,
296 ucontrol->value.bytes.data[i]); 341 ucontrol->value.bytes.data[i]);
297 if (numcoef == 1) 342 if (numcoef == 1)
298 snd_soc_write(codec, STA32X_CFUD, cfud | 0x01); 343 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x01);
299 else if (numcoef == 5) 344 else if (numcoef == 5)
300 snd_soc_write(codec, STA32X_CFUD, cfud | 0x02); 345 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x02);
301 else 346 else
302 return -EINVAL; 347 return -EINVAL;
303 348
@@ -311,20 +356,23 @@ static int sta32x_sync_coef_shadow(struct snd_soc_codec *codec)
311 int i; 356 int i;
312 357
313 /* preserve reserved bits in STA32X_CFUD */ 358 /* preserve reserved bits in STA32X_CFUD */
314 cfud = snd_soc_read(codec, STA32X_CFUD) & 0xf0; 359 regmap_read(sta32x->regmap, STA32X_CFUD, &cfud);
360 cfud &= 0xf0;
315 361
316 for (i = 0; i < STA32X_COEF_COUNT; i++) { 362 for (i = 0; i < STA32X_COEF_COUNT; i++) {
317 snd_soc_write(codec, STA32X_CFADDR2, i); 363 regmap_write(sta32x->regmap, STA32X_CFADDR2, i);
318 snd_soc_write(codec, STA32X_B1CF1, 364 regmap_write(sta32x->regmap, STA32X_B1CF1,
319 (sta32x->coef_shadow[i] >> 16) & 0xff); 365 (sta32x->coef_shadow[i] >> 16) & 0xff);
320 snd_soc_write(codec, STA32X_B1CF2, 366 regmap_write(sta32x->regmap, STA32X_B1CF2,
321 (sta32x->coef_shadow[i] >> 8) & 0xff); 367 (sta32x->coef_shadow[i] >> 8) & 0xff);
322 snd_soc_write(codec, STA32X_B1CF3, 368 regmap_write(sta32x->regmap, STA32X_B1CF3,
323 (sta32x->coef_shadow[i]) & 0xff); 369 (sta32x->coef_shadow[i]) & 0xff);
324 /* chip documentation does not say if the bits are 370 /*
325 * self-clearing, so do it explicitly */ 371 * chip documentation does not say if the bits are
326 snd_soc_write(codec, STA32X_CFUD, cfud); 372 * self-clearing, so do it explicitly
327 snd_soc_write(codec, STA32X_CFUD, cfud | 0x01); 373 */
374 regmap_write(sta32x->regmap, STA32X_CFUD, cfud);
375 regmap_write(sta32x->regmap, STA32X_CFUD, cfud | 0x01);
328 } 376 }
329 return 0; 377 return 0;
330} 378}
@@ -336,11 +384,11 @@ static int sta32x_cache_sync(struct snd_soc_codec *codec)
336 int rc; 384 int rc;
337 385
338 /* mute during register sync */ 386 /* mute during register sync */
339 mute = snd_soc_read(codec, STA32X_MMUTE); 387 regmap_read(sta32x->regmap, STA32X_MMUTE, &mute);
340 snd_soc_write(codec, STA32X_MMUTE, mute | STA32X_MMUTE_MMUTE); 388 regmap_write(sta32x->regmap, STA32X_MMUTE, mute | STA32X_MMUTE_MMUTE);
341 sta32x_sync_coef_shadow(codec); 389 sta32x_sync_coef_shadow(codec);
342 rc = regcache_sync(sta32x->regmap); 390 rc = regcache_sync(sta32x->regmap);
343 snd_soc_write(codec, STA32X_MMUTE, mute); 391 regmap_write(sta32x->regmap, STA32X_MMUTE, mute);
344 return rc; 392 return rc;
345} 393}
346 394
@@ -508,17 +556,12 @@ static struct {
508}; 556};
509 557
510/* MCLK to fs clock ratios */ 558/* MCLK to fs clock ratios */
511static struct { 559static int mcs_ratio_table[3][7] = {
512 int ratio; 560 { 768, 512, 384, 256, 128, 576, 0 },
513 int mcs; 561 { 384, 256, 192, 128, 64, 0 },
514} mclk_ratios[3][7] = { 562 { 384, 256, 192, 128, 64, 0 },
515 { { 768, 0 }, { 512, 1 }, { 384, 2 }, { 256, 3 },
516 { 128, 4 }, { 576, 5 }, { 0, 0 } },
517 { { 384, 2 }, { 256, 3 }, { 192, 4 }, { 128, 5 }, {64, 0 }, { 0, 0 } },
518 { { 384, 2 }, { 256, 3 }, { 192, 4 }, { 128, 5 }, {64, 0 }, { 0, 0 } },
519}; 563};
520 564
521
522/** 565/**
523 * sta32x_set_dai_sysclk - configure MCLK 566 * sta32x_set_dai_sysclk - configure MCLK
524 * @codec_dai: the codec DAI 567 * @codec_dai: the codec DAI
@@ -543,46 +586,10 @@ static int sta32x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
543{ 586{
544 struct snd_soc_codec *codec = codec_dai->codec; 587 struct snd_soc_codec *codec = codec_dai->codec;
545 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); 588 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec);
546 int i, j, ir, fs;
547 unsigned int rates = 0;
548 unsigned int rate_min = -1;
549 unsigned int rate_max = 0;
550 589
551 pr_debug("mclk=%u\n", freq); 590 dev_dbg(codec->dev, "mclk=%u\n", freq);
552 sta32x->mclk = freq; 591 sta32x->mclk = freq;
553 592
554 if (sta32x->mclk) {
555 for (i = 0; i < ARRAY_SIZE(interpolation_ratios); i++) {
556 ir = interpolation_ratios[i].ir;
557 fs = interpolation_ratios[i].fs;
558 for (j = 0; mclk_ratios[ir][j].ratio; j++) {
559 if (mclk_ratios[ir][j].ratio * fs == freq) {
560 rates |= snd_pcm_rate_to_rate_bit(fs);
561 if (fs < rate_min)
562 rate_min = fs;
563 if (fs > rate_max)
564 rate_max = fs;
565 break;
566 }
567 }
568 }
569 /* FIXME: soc should support a rate list */
570 rates &= ~SNDRV_PCM_RATE_KNOT;
571
572 if (!rates) {
573 dev_err(codec->dev, "could not find a valid sample rate\n");
574 return -EINVAL;
575 }
576 } else {
577 /* enable all possible rates */
578 rates = STA32X_RATES;
579 rate_min = 32000;
580 rate_max = 192000;
581 }
582
583 codec_dai->driver->playback.rates = rates;
584 codec_dai->driver->playback.rate_min = rate_min;
585 codec_dai->driver->playback.rate_max = rate_max;
586 return 0; 593 return 0;
587} 594}
588 595
@@ -599,10 +606,7 @@ static int sta32x_set_dai_fmt(struct snd_soc_dai *codec_dai,
599{ 606{
600 struct snd_soc_codec *codec = codec_dai->codec; 607 struct snd_soc_codec *codec = codec_dai->codec;
601 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); 608 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec);
602 u8 confb = snd_soc_read(codec, STA32X_CONFB); 609 u8 confb = 0;
603
604 pr_debug("\n");
605 confb &= ~(STA32X_CONFB_C1IM | STA32X_CONFB_C2IM);
606 610
607 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 611 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
608 case SND_SOC_DAIFMT_CBS_CFS: 612 case SND_SOC_DAIFMT_CBS_CFS:
@@ -632,8 +636,8 @@ static int sta32x_set_dai_fmt(struct snd_soc_dai *codec_dai,
632 return -EINVAL; 636 return -EINVAL;
633 } 637 }
634 638
635 snd_soc_write(codec, STA32X_CONFB, confb); 639 return regmap_update_bits(sta32x->regmap, STA32X_CONFB,
636 return 0; 640 STA32X_CONFB_C1IM | STA32X_CONFB_C2IM, confb);
637} 641}
638 642
639/** 643/**
@@ -651,39 +655,55 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream,
651{ 655{
652 struct snd_soc_codec *codec = dai->codec; 656 struct snd_soc_codec *codec = dai->codec;
653 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); 657 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec);
654 unsigned int rate; 658 int i, mcs = -EINVAL, ir = -EINVAL;
655 int i, mcs = -1, ir = -1; 659 unsigned int confa, confb;
656 u8 confa, confb; 660 unsigned int rate, ratio;
661 int ret;
662
663 if (!sta32x->mclk) {
664 dev_err(codec->dev,
665 "sta32x->mclk is unset. Unable to determine ratio\n");
666 return -EIO;
667 }
657 668
658 rate = params_rate(params); 669 rate = params_rate(params);
659 pr_debug("rate: %u\n", rate); 670 ratio = sta32x->mclk / rate;
660 for (i = 0; i < ARRAY_SIZE(interpolation_ratios); i++) 671 dev_dbg(codec->dev, "rate: %u, ratio: %u\n", rate, ratio);
672
673 for (i = 0; i < ARRAY_SIZE(interpolation_ratios); i++) {
661 if (interpolation_ratios[i].fs == rate) { 674 if (interpolation_ratios[i].fs == rate) {
662 ir = interpolation_ratios[i].ir; 675 ir = interpolation_ratios[i].ir;
663 break; 676 break;
664 } 677 }
665 if (ir < 0) 678 }
679
680 if (ir < 0) {
681 dev_err(codec->dev, "Unsupported samplerate: %u\n", rate);
666 return -EINVAL; 682 return -EINVAL;
667 for (i = 0; mclk_ratios[ir][i].ratio; i++) 683 }
668 if (mclk_ratios[ir][i].ratio * rate == sta32x->mclk) { 684
669 mcs = mclk_ratios[ir][i].mcs; 685 for (i = 0; i < 6; i++) {
686 if (mcs_ratio_table[ir][i] == ratio) {
687 mcs = i;
670 break; 688 break;
671 } 689 }
672 if (mcs < 0) 690 }
691
692 if (mcs < 0) {
693 dev_err(codec->dev, "Unresolvable ratio: %u\n", ratio);
673 return -EINVAL; 694 return -EINVAL;
695 }
674 696
675 confa = snd_soc_read(codec, STA32X_CONFA); 697 confa = (ir << STA32X_CONFA_IR_SHIFT) |
676 confa &= ~(STA32X_CONFA_MCS_MASK | STA32X_CONFA_IR_MASK); 698 (mcs << STA32X_CONFA_MCS_SHIFT);
677 confa |= (ir << STA32X_CONFA_IR_SHIFT) | (mcs << STA32X_CONFA_MCS_SHIFT); 699 confb = 0;
678 700
679 confb = snd_soc_read(codec, STA32X_CONFB);
680 confb &= ~(STA32X_CONFB_SAI_MASK | STA32X_CONFB_SAIFB);
681 switch (params_width(params)) { 701 switch (params_width(params)) {
682 case 24: 702 case 24:
683 pr_debug("24bit\n"); 703 dev_dbg(codec->dev, "24bit\n");
684 /* fall through */ 704 /* fall through */
685 case 32: 705 case 32:
686 pr_debug("24bit or 32bit\n"); 706 dev_dbg(codec->dev, "24bit or 32bit\n");
687 switch (sta32x->format) { 707 switch (sta32x->format) {
688 case SND_SOC_DAIFMT_I2S: 708 case SND_SOC_DAIFMT_I2S:
689 confb |= 0x0; 709 confb |= 0x0;
@@ -698,7 +718,7 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream,
698 718
699 break; 719 break;
700 case 20: 720 case 20:
701 pr_debug("20bit\n"); 721 dev_dbg(codec->dev, "20bit\n");
702 switch (sta32x->format) { 722 switch (sta32x->format) {
703 case SND_SOC_DAIFMT_I2S: 723 case SND_SOC_DAIFMT_I2S:
704 confb |= 0x4; 724 confb |= 0x4;
@@ -713,7 +733,7 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream,
713 733
714 break; 734 break;
715 case 18: 735 case 18:
716 pr_debug("18bit\n"); 736 dev_dbg(codec->dev, "18bit\n");
717 switch (sta32x->format) { 737 switch (sta32x->format) {
718 case SND_SOC_DAIFMT_I2S: 738 case SND_SOC_DAIFMT_I2S:
719 confb |= 0x8; 739 confb |= 0x8;
@@ -728,7 +748,7 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream,
728 748
729 break; 749 break;
730 case 16: 750 case 16:
731 pr_debug("16bit\n"); 751 dev_dbg(codec->dev, "16bit\n");
732 switch (sta32x->format) { 752 switch (sta32x->format) {
733 case SND_SOC_DAIFMT_I2S: 753 case SND_SOC_DAIFMT_I2S:
734 confb |= 0x0; 754 confb |= 0x0;
@@ -746,8 +766,30 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream,
746 return -EINVAL; 766 return -EINVAL;
747 } 767 }
748 768
749 snd_soc_write(codec, STA32X_CONFA, confa); 769 ret = regmap_update_bits(sta32x->regmap, STA32X_CONFA,
750 snd_soc_write(codec, STA32X_CONFB, confb); 770 STA32X_CONFA_MCS_MASK | STA32X_CONFA_IR_MASK,
771 confa);
772 if (ret < 0)
773 return ret;
774
775 ret = regmap_update_bits(sta32x->regmap, STA32X_CONFB,
776 STA32X_CONFB_SAI_MASK | STA32X_CONFB_SAIFB,
777 confb);
778 if (ret < 0)
779 return ret;
780
781 return 0;
782}
783
784static int sta32x_startup_sequence(struct sta32x_priv *sta32x)
785{
786 if (sta32x->gpiod_nreset) {
787 gpiod_set_value(sta32x->gpiod_nreset, 0);
788 mdelay(1);
789 gpiod_set_value(sta32x->gpiod_nreset, 1);
790 mdelay(1);
791 }
792
751 return 0; 793 return 0;
752} 794}
753 795
@@ -766,14 +808,14 @@ static int sta32x_set_bias_level(struct snd_soc_codec *codec,
766 int ret; 808 int ret;
767 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); 809 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec);
768 810
769 pr_debug("level = %d\n", level); 811 dev_dbg(codec->dev, "level = %d\n", level);
770 switch (level) { 812 switch (level) {
771 case SND_SOC_BIAS_ON: 813 case SND_SOC_BIAS_ON:
772 break; 814 break;
773 815
774 case SND_SOC_BIAS_PREPARE: 816 case SND_SOC_BIAS_PREPARE:
775 /* Full power on */ 817 /* Full power on */
776 snd_soc_update_bits(codec, STA32X_CONFF, 818 regmap_update_bits(sta32x->regmap, STA32X_CONFF,
777 STA32X_CONFF_PWDN | STA32X_CONFF_EAPD, 819 STA32X_CONFF_PWDN | STA32X_CONFF_EAPD,
778 STA32X_CONFF_PWDN | STA32X_CONFF_EAPD); 820 STA32X_CONFF_PWDN | STA32X_CONFF_EAPD);
779 break; 821 break;
@@ -788,25 +830,28 @@ static int sta32x_set_bias_level(struct snd_soc_codec *codec,
788 return ret; 830 return ret;
789 } 831 }
790 832
833 sta32x_startup_sequence(sta32x);
791 sta32x_cache_sync(codec); 834 sta32x_cache_sync(codec);
792 sta32x_watchdog_start(sta32x); 835 sta32x_watchdog_start(sta32x);
793 } 836 }
794 837
795 /* Power up to mute */ 838 /* Power down */
796 /* FIXME */ 839 regmap_update_bits(sta32x->regmap, STA32X_CONFF,
797 snd_soc_update_bits(codec, STA32X_CONFF, 840 STA32X_CONFF_PWDN | STA32X_CONFF_EAPD,
798 STA32X_CONFF_PWDN | STA32X_CONFF_EAPD, 841 0);
799 STA32X_CONFF_PWDN | STA32X_CONFF_EAPD);
800 842
801 break; 843 break;
802 844
803 case SND_SOC_BIAS_OFF: 845 case SND_SOC_BIAS_OFF:
804 /* The chip runs through the power down sequence for us. */ 846 /* The chip runs through the power down sequence for us. */
805 snd_soc_update_bits(codec, STA32X_CONFF, 847 regmap_update_bits(sta32x->regmap, STA32X_CONFF,
806 STA32X_CONFF_PWDN | STA32X_CONFF_EAPD, 848 STA32X_CONFF_PWDN | STA32X_CONFF_EAPD, 0);
807 STA32X_CONFF_PWDN);
808 msleep(300); 849 msleep(300);
809 sta32x_watchdog_stop(sta32x); 850 sta32x_watchdog_stop(sta32x);
851
852 if (sta32x->gpiod_nreset)
853 gpiod_set_value(sta32x->gpiod_nreset, 0);
854
810 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), 855 regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies),
811 sta32x->supplies); 856 sta32x->supplies);
812 break; 857 break;
@@ -822,7 +867,7 @@ static const struct snd_soc_dai_ops sta32x_dai_ops = {
822}; 867};
823 868
824static struct snd_soc_dai_driver sta32x_dai = { 869static struct snd_soc_dai_driver sta32x_dai = {
825 .name = "STA32X", 870 .name = "sta32x-hifi",
826 .playback = { 871 .playback = {
827 .stream_name = "Playback", 872 .stream_name = "Playback",
828 .channels_min = 2, 873 .channels_min = 2,
@@ -836,11 +881,8 @@ static struct snd_soc_dai_driver sta32x_dai = {
836static int sta32x_probe(struct snd_soc_codec *codec) 881static int sta32x_probe(struct snd_soc_codec *codec)
837{ 882{
838 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec); 883 struct sta32x_priv *sta32x = snd_soc_codec_get_drvdata(codec);
884 struct sta32x_platform_data *pdata = sta32x->pdata;
839 int i, ret = 0, thermal = 0; 885 int i, ret = 0, thermal = 0;
840
841 sta32x->codec = codec;
842 sta32x->pdata = dev_get_platdata(codec->dev);
843
844 ret = regulator_bulk_enable(ARRAY_SIZE(sta32x->supplies), 886 ret = regulator_bulk_enable(ARRAY_SIZE(sta32x->supplies),
845 sta32x->supplies); 887 sta32x->supplies);
846 if (ret != 0) { 888 if (ret != 0) {
@@ -848,50 +890,73 @@ static int sta32x_probe(struct snd_soc_codec *codec)
848 return ret; 890 return ret;
849 } 891 }
850 892
851 /* Chip documentation explicitly requires that the reset values 893 ret = sta32x_startup_sequence(sta32x);
852 * of reserved register bits are left untouched. 894 if (ret < 0) {
853 * Write the register default value to cache for reserved registers, 895 dev_err(codec->dev, "Failed to startup device\n");
854 * so the write to the these registers are suppressed by the cache 896 return ret;
855 * restore code when it skips writes of default registers. 897 }
856 */ 898
857 regcache_cache_only(sta32x->regmap, true); 899 /* CONFA */
858 snd_soc_write(codec, STA32X_CONFC, 0xc2); 900 if (!pdata->thermal_warning_recovery)
859 snd_soc_write(codec, STA32X_CONFE, 0xc2);
860 snd_soc_write(codec, STA32X_CONFF, 0x5c);
861 snd_soc_write(codec, STA32X_MMUTE, 0x10);
862 snd_soc_write(codec, STA32X_AUTO1, 0x60);
863 snd_soc_write(codec, STA32X_AUTO3, 0x00);
864 snd_soc_write(codec, STA32X_C3CFG, 0x40);
865 regcache_cache_only(sta32x->regmap, false);
866
867 /* set thermal warning adjustment and recovery */
868 if (!(sta32x->pdata->thermal_conf & STA32X_THERMAL_ADJUSTMENT_ENABLE))
869 thermal |= STA32X_CONFA_TWAB; 901 thermal |= STA32X_CONFA_TWAB;
870 if (!(sta32x->pdata->thermal_conf & STA32X_THERMAL_RECOVERY_ENABLE)) 902 if (!pdata->thermal_warning_adjustment)
871 thermal |= STA32X_CONFA_TWRB; 903 thermal |= STA32X_CONFA_TWRB;
872 snd_soc_update_bits(codec, STA32X_CONFA, 904 if (!pdata->fault_detect_recovery)
873 STA32X_CONFA_TWAB | STA32X_CONFA_TWRB, 905 thermal |= STA32X_CONFA_FDRB;
874 thermal); 906 regmap_update_bits(sta32x->regmap, STA32X_CONFA,
907 STA32X_CONFA_TWAB | STA32X_CONFA_TWRB |
908 STA32X_CONFA_FDRB,
909 thermal);
910
911 /* CONFC */
912 regmap_update_bits(sta32x->regmap, STA32X_CONFC,
913 STA32X_CONFC_CSZ_MASK,
914 pdata->drop_compensation_ns
915 << STA32X_CONFC_CSZ_SHIFT);
916
917 /* CONFE */
918 regmap_update_bits(sta32x->regmap, STA32X_CONFE,
919 STA32X_CONFE_MPCV,
920 pdata->max_power_use_mpcc ?
921 STA32X_CONFE_MPCV : 0);
922 regmap_update_bits(sta32x->regmap, STA32X_CONFE,
923 STA32X_CONFE_MPC,
924 pdata->max_power_correction ?
925 STA32X_CONFE_MPC : 0);
926 regmap_update_bits(sta32x->regmap, STA32X_CONFE,
927 STA32X_CONFE_AME,
928 pdata->am_reduction_mode ?
929 STA32X_CONFE_AME : 0);
930 regmap_update_bits(sta32x->regmap, STA32X_CONFE,
931 STA32X_CONFE_PWMS,
932 pdata->odd_pwm_speed_mode ?
933 STA32X_CONFE_PWMS : 0);
934
935 /* CONFF */
936 regmap_update_bits(sta32x->regmap, STA32X_CONFF,
937 STA32X_CONFF_IDE,
938 pdata->invalid_input_detect_mute ?
939 STA32X_CONFF_IDE : 0);
875 940
876 /* select output configuration */ 941 /* select output configuration */
877 snd_soc_update_bits(codec, STA32X_CONFF, 942 regmap_update_bits(sta32x->regmap, STA32X_CONFF,
878 STA32X_CONFF_OCFG_MASK, 943 STA32X_CONFF_OCFG_MASK,
879 sta32x->pdata->output_conf 944 pdata->output_conf
880 << STA32X_CONFF_OCFG_SHIFT); 945 << STA32X_CONFF_OCFG_SHIFT);
881 946
882 /* channel to output mapping */ 947 /* channel to output mapping */
883 snd_soc_update_bits(codec, STA32X_C1CFG, 948 regmap_update_bits(sta32x->regmap, STA32X_C1CFG,
884 STA32X_CxCFG_OM_MASK, 949 STA32X_CxCFG_OM_MASK,
885 sta32x->pdata->ch1_output_mapping 950 pdata->ch1_output_mapping
886 << STA32X_CxCFG_OM_SHIFT); 951 << STA32X_CxCFG_OM_SHIFT);
887 snd_soc_update_bits(codec, STA32X_C2CFG, 952 regmap_update_bits(sta32x->regmap, STA32X_C2CFG,
888 STA32X_CxCFG_OM_MASK, 953 STA32X_CxCFG_OM_MASK,
889 sta32x->pdata->ch2_output_mapping 954 pdata->ch2_output_mapping
890 << STA32X_CxCFG_OM_SHIFT); 955 << STA32X_CxCFG_OM_SHIFT);
891 snd_soc_update_bits(codec, STA32X_C3CFG, 956 regmap_update_bits(sta32x->regmap, STA32X_C3CFG,
892 STA32X_CxCFG_OM_MASK, 957 STA32X_CxCFG_OM_MASK,
893 sta32x->pdata->ch3_output_mapping 958 pdata->ch3_output_mapping
894 << STA32X_CxCFG_OM_SHIFT); 959 << STA32X_CxCFG_OM_SHIFT);
895 960
896 /* initialize coefficient shadow RAM with reset values */ 961 /* initialize coefficient shadow RAM with reset values */
897 for (i = 4; i <= 49; i += 5) 962 for (i = 4; i <= 49; i += 5)
@@ -924,16 +989,6 @@ static int sta32x_remove(struct snd_soc_codec *codec)
924 return 0; 989 return 0;
925} 990}
926 991
927static bool sta32x_reg_is_volatile(struct device *dev, unsigned int reg)
928{
929 switch (reg) {
930 case STA32X_CONFA ... STA32X_L2ATRT:
931 case STA32X_MPCC1 ... STA32X_FDRC2:
932 return 0;
933 }
934 return 1;
935}
936
937static const struct snd_soc_codec_driver sta32x_codec = { 992static const struct snd_soc_codec_driver sta32x_codec = {
938 .probe = sta32x_probe, 993 .probe = sta32x_probe,
939 .remove = sta32x_remove, 994 .remove = sta32x_remove,
@@ -954,12 +1009,75 @@ static const struct regmap_config sta32x_regmap = {
954 .reg_defaults = sta32x_regs, 1009 .reg_defaults = sta32x_regs,
955 .num_reg_defaults = ARRAY_SIZE(sta32x_regs), 1010 .num_reg_defaults = ARRAY_SIZE(sta32x_regs),
956 .cache_type = REGCACHE_RBTREE, 1011 .cache_type = REGCACHE_RBTREE,
957 .volatile_reg = sta32x_reg_is_volatile, 1012 .wr_table = &sta32x_write_regs,
1013 .rd_table = &sta32x_read_regs,
1014 .volatile_table = &sta32x_volatile_regs,
958}; 1015};
959 1016
1017#ifdef CONFIG_OF
1018static const struct of_device_id st32x_dt_ids[] = {
1019 { .compatible = "st,sta32x", },
1020 { }
1021};
1022MODULE_DEVICE_TABLE(of, st32x_dt_ids);
1023
1024static int sta32x_probe_dt(struct device *dev, struct sta32x_priv *sta32x)
1025{
1026 struct device_node *np = dev->of_node;
1027 struct sta32x_platform_data *pdata;
1028 u16 tmp;
1029
1030 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
1031 if (!pdata)
1032 return -ENOMEM;
1033
1034 of_property_read_u8(np, "st,output-conf",
1035 &pdata->output_conf);
1036 of_property_read_u8(np, "st,ch1-output-mapping",
1037 &pdata->ch1_output_mapping);
1038 of_property_read_u8(np, "st,ch2-output-mapping",
1039 &pdata->ch2_output_mapping);
1040 of_property_read_u8(np, "st,ch3-output-mapping",
1041 &pdata->ch3_output_mapping);
1042
1043 if (of_get_property(np, "st,thermal-warning-recovery", NULL))
1044 pdata->thermal_warning_recovery = 1;
1045 if (of_get_property(np, "st,thermal-warning-adjustment", NULL))
1046 pdata->thermal_warning_adjustment = 1;
1047 if (of_get_property(np, "st,needs_esd_watchdog", NULL))
1048 pdata->needs_esd_watchdog = 1;
1049
1050 tmp = 140;
1051 of_property_read_u16(np, "st,drop-compensation-ns", &tmp);
1052 pdata->drop_compensation_ns = clamp_t(u16, tmp, 0, 300) / 20;
1053
1054 /* CONFE */
1055 if (of_get_property(np, "st,max-power-use-mpcc", NULL))
1056 pdata->max_power_use_mpcc = 1;
1057
1058 if (of_get_property(np, "st,max-power-correction", NULL))
1059 pdata->max_power_correction = 1;
1060
1061 if (of_get_property(np, "st,am-reduction-mode", NULL))
1062 pdata->am_reduction_mode = 1;
1063
1064 if (of_get_property(np, "st,odd-pwm-speed-mode", NULL))
1065 pdata->odd_pwm_speed_mode = 1;
1066
1067 /* CONFF */
1068 if (of_get_property(np, "st,invalid-input-detect-mute", NULL))
1069 pdata->invalid_input_detect_mute = 1;
1070
1071 sta32x->pdata = pdata;
1072
1073 return 0;
1074}
1075#endif
1076
960static int sta32x_i2c_probe(struct i2c_client *i2c, 1077static int sta32x_i2c_probe(struct i2c_client *i2c,
961 const struct i2c_device_id *id) 1078 const struct i2c_device_id *id)
962{ 1079{
1080 struct device *dev = &i2c->dev;
963 struct sta32x_priv *sta32x; 1081 struct sta32x_priv *sta32x;
964 int ret, i; 1082 int ret, i;
965 1083
@@ -968,6 +1086,29 @@ static int sta32x_i2c_probe(struct i2c_client *i2c,
968 if (!sta32x) 1086 if (!sta32x)
969 return -ENOMEM; 1087 return -ENOMEM;
970 1088
1089 mutex_init(&sta32x->coeff_lock);
1090 sta32x->pdata = dev_get_platdata(dev);
1091
1092#ifdef CONFIG_OF
1093 if (dev->of_node) {
1094 ret = sta32x_probe_dt(dev, sta32x);
1095 if (ret < 0)
1096 return ret;
1097 }
1098#endif
1099
1100 /* GPIOs */
1101 sta32x->gpiod_nreset = devm_gpiod_get(dev, "reset");
1102 if (IS_ERR(sta32x->gpiod_nreset)) {
1103 ret = PTR_ERR(sta32x->gpiod_nreset);
1104 if (ret != -ENOENT && ret != -ENOSYS)
1105 return ret;
1106
1107 sta32x->gpiod_nreset = NULL;
1108 } else {
1109 gpiod_direction_output(sta32x->gpiod_nreset, 0);
1110 }
1111
971 /* regulators */ 1112 /* regulators */
972 for (i = 0; i < ARRAY_SIZE(sta32x->supplies); i++) 1113 for (i = 0; i < ARRAY_SIZE(sta32x->supplies); i++)
973 sta32x->supplies[i].supply = sta32x_supply_names[i]; 1114 sta32x->supplies[i].supply = sta32x_supply_names[i];
@@ -982,15 +1123,15 @@ static int sta32x_i2c_probe(struct i2c_client *i2c,
982 sta32x->regmap = devm_regmap_init_i2c(i2c, &sta32x_regmap); 1123 sta32x->regmap = devm_regmap_init_i2c(i2c, &sta32x_regmap);
983 if (IS_ERR(sta32x->regmap)) { 1124 if (IS_ERR(sta32x->regmap)) {
984 ret = PTR_ERR(sta32x->regmap); 1125 ret = PTR_ERR(sta32x->regmap);
985 dev_err(&i2c->dev, "Failed to init regmap: %d\n", ret); 1126 dev_err(dev, "Failed to init regmap: %d\n", ret);
986 return ret; 1127 return ret;
987 } 1128 }
988 1129
989 i2c_set_clientdata(i2c, sta32x); 1130 i2c_set_clientdata(i2c, sta32x);
990 1131
991 ret = snd_soc_register_codec(&i2c->dev, &sta32x_codec, &sta32x_dai, 1); 1132 ret = snd_soc_register_codec(dev, &sta32x_codec, &sta32x_dai, 1);
992 if (ret != 0) 1133 if (ret < 0)
993 dev_err(&i2c->dev, "Failed to register codec (%d)\n", ret); 1134 dev_err(dev, "Failed to register codec (%d)\n", ret);
994 1135
995 return ret; 1136 return ret;
996} 1137}
@@ -1013,6 +1154,7 @@ static struct i2c_driver sta32x_i2c_driver = {
1013 .driver = { 1154 .driver = {
1014 .name = "sta32x", 1155 .name = "sta32x",
1015 .owner = THIS_MODULE, 1156 .owner = THIS_MODULE,
1157 .of_match_table = of_match_ptr(st32x_dt_ids),
1016 }, 1158 },
1017 .probe = sta32x_i2c_probe, 1159 .probe = sta32x_i2c_probe,
1018 .remove = sta32x_i2c_remove, 1160 .remove = sta32x_i2c_remove,
diff --git a/sound/soc/codecs/sta32x.h b/sound/soc/codecs/sta32x.h
index d8e32a6262ee..d3191c983d71 100644
--- a/sound/soc/codecs/sta32x.h
+++ b/sound/soc/codecs/sta32x.h
@@ -131,7 +131,7 @@
131#define STA32X_CONFF_OCFG_MASK 0x03 131#define STA32X_CONFF_OCFG_MASK 0x03
132#define STA32X_CONFF_OCFG_SHIFT 0 132#define STA32X_CONFF_OCFG_SHIFT 0
133#define STA32X_CONFF_IDE 0x04 133#define STA32X_CONFF_IDE 0x04
134#define STA32X_CONFF_IDE_SHIFT 3 134#define STA32X_CONFF_IDE_SHIFT 2
135#define STA32X_CONFF_BCLE 0x08 135#define STA32X_CONFF_BCLE 0x08
136#define STA32X_CONFF_ECLE 0x20 136#define STA32X_CONFF_ECLE 0x20
137#define STA32X_CONFF_PWDN 0x40 137#define STA32X_CONFF_PWDN 0x40
diff --git a/sound/soc/codecs/tlv320aic31xx.c b/sound/soc/codecs/tlv320aic31xx.c
index dc3223d6eca1..c86dd9aae157 100644
--- a/sound/soc/codecs/tlv320aic31xx.c
+++ b/sound/soc/codecs/tlv320aic31xx.c
@@ -349,7 +349,8 @@ static int aic31xx_wait_bits(struct aic31xx_priv *aic31xx, unsigned int reg,
349static int aic31xx_dapm_power_event(struct snd_soc_dapm_widget *w, 349static int aic31xx_dapm_power_event(struct snd_soc_dapm_widget *w,
350 struct snd_kcontrol *kcontrol, int event) 350 struct snd_kcontrol *kcontrol, int event)
351{ 351{
352 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(w->codec); 352 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
353 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
353 unsigned int reg = AIC31XX_DACFLAG1; 354 unsigned int reg = AIC31XX_DACFLAG1;
354 unsigned int mask; 355 unsigned int mask;
355 356
@@ -377,7 +378,7 @@ static int aic31xx_dapm_power_event(struct snd_soc_dapm_widget *w,
377 reg = AIC31XX_ADCFLAG; 378 reg = AIC31XX_ADCFLAG;
378 break; 379 break;
379 default: 380 default:
380 dev_err(w->codec->dev, "Unknown widget '%s' calling %s\n", 381 dev_err(codec->dev, "Unknown widget '%s' calling %s\n",
381 w->name, __func__); 382 w->name, __func__);
382 return -EINVAL; 383 return -EINVAL;
383 } 384 }
@@ -388,7 +389,7 @@ static int aic31xx_dapm_power_event(struct snd_soc_dapm_widget *w,
388 case SND_SOC_DAPM_POST_PMD: 389 case SND_SOC_DAPM_POST_PMD:
389 return aic31xx_wait_bits(aic31xx, reg, mask, 0, 5000, 100); 390 return aic31xx_wait_bits(aic31xx, reg, mask, 0, 5000, 100);
390 default: 391 default:
391 dev_dbg(w->codec->dev, 392 dev_dbg(codec->dev,
392 "Unhandled dapm widget event %d from %s\n", 393 "Unhandled dapm widget event %d from %s\n",
393 event, w->name); 394 event, w->name);
394 } 395 }
@@ -433,7 +434,7 @@ static const struct snd_kcontrol_new aic31xx_dapm_spr_switch =
433static int mic_bias_event(struct snd_soc_dapm_widget *w, 434static int mic_bias_event(struct snd_soc_dapm_widget *w,
434 struct snd_kcontrol *kcontrol, int event) 435 struct snd_kcontrol *kcontrol, int event)
435{ 436{
436 struct snd_soc_codec *codec = w->codec; 437 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
437 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec); 438 struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
438 439
439 switch (event) { 440 switch (event) {
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index b7ebce054b4e..51c4713ac6e3 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -87,6 +87,7 @@ struct aic3x_priv {
87#define AIC3X_MODEL_3X 0 87#define AIC3X_MODEL_3X 0
88#define AIC3X_MODEL_33 1 88#define AIC3X_MODEL_33 1
89#define AIC3X_MODEL_3007 2 89#define AIC3X_MODEL_3007 2
90#define AIC3X_MODEL_3104 3
90 u16 model; 91 u16 model;
91 92
92 /* Selects the micbias voltage */ 93 /* Selects the micbias voltage */
@@ -197,7 +198,7 @@ static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,
197static int mic_bias_event(struct snd_soc_dapm_widget *w, 198static int mic_bias_event(struct snd_soc_dapm_widget *w,
198 struct snd_kcontrol *kcontrol, int event) 199 struct snd_kcontrol *kcontrol, int event)
199{ 200{
200 struct snd_soc_codec *codec = w->codec; 201 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
201 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec); 202 struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
202 203
203 switch (event) { 204 switch (event) {
@@ -316,52 +317,37 @@ static const struct snd_kcontrol_new aic3x_snd_controls[] = {
316 * only for swapped L-to-R and R-to-L routes. See below stereo controls 317 * only for swapped L-to-R and R-to-L routes. See below stereo controls
317 * for direct L-to-L and R-to-R routes. 318 * for direct L-to-L and R-to-R routes.
318 */ 319 */
319 SOC_SINGLE_TLV("Left Line Mixer Line2R Bypass Volume",
320 LINE2R_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
321 SOC_SINGLE_TLV("Left Line Mixer PGAR Bypass Volume", 320 SOC_SINGLE_TLV("Left Line Mixer PGAR Bypass Volume",
322 PGAR_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv), 321 PGAR_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
323 SOC_SINGLE_TLV("Left Line Mixer DACR1 Playback Volume", 322 SOC_SINGLE_TLV("Left Line Mixer DACR1 Playback Volume",
324 DACR1_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv), 323 DACR1_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
325 324
326 SOC_SINGLE_TLV("Right Line Mixer Line2L Bypass Volume",
327 LINE2L_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
328 SOC_SINGLE_TLV("Right Line Mixer PGAL Bypass Volume", 325 SOC_SINGLE_TLV("Right Line Mixer PGAL Bypass Volume",
329 PGAL_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv), 326 PGAL_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
330 SOC_SINGLE_TLV("Right Line Mixer DACL1 Playback Volume", 327 SOC_SINGLE_TLV("Right Line Mixer DACL1 Playback Volume",
331 DACL1_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv), 328 DACL1_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
332 329
333 SOC_SINGLE_TLV("Left HP Mixer Line2R Bypass Volume",
334 LINE2R_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
335 SOC_SINGLE_TLV("Left HP Mixer PGAR Bypass Volume", 330 SOC_SINGLE_TLV("Left HP Mixer PGAR Bypass Volume",
336 PGAR_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv), 331 PGAR_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
337 SOC_SINGLE_TLV("Left HP Mixer DACR1 Playback Volume", 332 SOC_SINGLE_TLV("Left HP Mixer DACR1 Playback Volume",
338 DACR1_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv), 333 DACR1_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
339 334
340 SOC_SINGLE_TLV("Right HP Mixer Line2L Bypass Volume",
341 LINE2L_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
342 SOC_SINGLE_TLV("Right HP Mixer PGAL Bypass Volume", 335 SOC_SINGLE_TLV("Right HP Mixer PGAL Bypass Volume",
343 PGAL_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv), 336 PGAL_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
344 SOC_SINGLE_TLV("Right HP Mixer DACL1 Playback Volume", 337 SOC_SINGLE_TLV("Right HP Mixer DACL1 Playback Volume",
345 DACL1_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv), 338 DACL1_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
346 339
347 SOC_SINGLE_TLV("Left HPCOM Mixer Line2R Bypass Volume",
348 LINE2R_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
349 SOC_SINGLE_TLV("Left HPCOM Mixer PGAR Bypass Volume", 340 SOC_SINGLE_TLV("Left HPCOM Mixer PGAR Bypass Volume",
350 PGAR_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv), 341 PGAR_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
351 SOC_SINGLE_TLV("Left HPCOM Mixer DACR1 Playback Volume", 342 SOC_SINGLE_TLV("Left HPCOM Mixer DACR1 Playback Volume",
352 DACR1_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv), 343 DACR1_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
353 344
354 SOC_SINGLE_TLV("Right HPCOM Mixer Line2L Bypass Volume",
355 LINE2L_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
356 SOC_SINGLE_TLV("Right HPCOM Mixer PGAL Bypass Volume", 345 SOC_SINGLE_TLV("Right HPCOM Mixer PGAL Bypass Volume",
357 PGAL_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv), 346 PGAL_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
358 SOC_SINGLE_TLV("Right HPCOM Mixer DACL1 Playback Volume", 347 SOC_SINGLE_TLV("Right HPCOM Mixer DACL1 Playback Volume",
359 DACL1_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv), 348 DACL1_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
360 349
361 /* Stereo output controls for direct L-to-L and R-to-R routes */ 350 /* Stereo output controls for direct L-to-L and R-to-R routes */
362 SOC_DOUBLE_R_TLV("Line Line2 Bypass Volume",
363 LINE2L_2_LLOPM_VOL, LINE2R_2_RLOPM_VOL,
364 0, 118, 1, output_stage_tlv),
365 SOC_DOUBLE_R_TLV("Line PGA Bypass Volume", 351 SOC_DOUBLE_R_TLV("Line PGA Bypass Volume",
366 PGAL_2_LLOPM_VOL, PGAR_2_RLOPM_VOL, 352 PGAL_2_LLOPM_VOL, PGAR_2_RLOPM_VOL,
367 0, 118, 1, output_stage_tlv), 353 0, 118, 1, output_stage_tlv),
@@ -369,9 +355,6 @@ static const struct snd_kcontrol_new aic3x_snd_controls[] = {
369 DACL1_2_LLOPM_VOL, DACR1_2_RLOPM_VOL, 355 DACL1_2_LLOPM_VOL, DACR1_2_RLOPM_VOL,
370 0, 118, 1, output_stage_tlv), 356 0, 118, 1, output_stage_tlv),
371 357
372 SOC_DOUBLE_R_TLV("HP Line2 Bypass Volume",
373 LINE2L_2_HPLOUT_VOL, LINE2R_2_HPROUT_VOL,
374 0, 118, 1, output_stage_tlv),
375 SOC_DOUBLE_R_TLV("HP PGA Bypass Volume", 358 SOC_DOUBLE_R_TLV("HP PGA Bypass Volume",
376 PGAL_2_HPLOUT_VOL, PGAR_2_HPROUT_VOL, 359 PGAL_2_HPLOUT_VOL, PGAR_2_HPROUT_VOL,
377 0, 118, 1, output_stage_tlv), 360 0, 118, 1, output_stage_tlv),
@@ -379,9 +362,6 @@ static const struct snd_kcontrol_new aic3x_snd_controls[] = {
379 DACL1_2_HPLOUT_VOL, DACR1_2_HPROUT_VOL, 362 DACL1_2_HPLOUT_VOL, DACR1_2_HPROUT_VOL,
380 0, 118, 1, output_stage_tlv), 363 0, 118, 1, output_stage_tlv),
381 364
382 SOC_DOUBLE_R_TLV("HPCOM Line2 Bypass Volume",
383 LINE2L_2_HPLCOM_VOL, LINE2R_2_HPRCOM_VOL,
384 0, 118, 1, output_stage_tlv),
385 SOC_DOUBLE_R_TLV("HPCOM PGA Bypass Volume", 365 SOC_DOUBLE_R_TLV("HPCOM PGA Bypass Volume",
386 PGAL_2_HPLCOM_VOL, PGAR_2_HPRCOM_VOL, 366 PGAL_2_HPLCOM_VOL, PGAR_2_HPRCOM_VOL,
387 0, 118, 1, output_stage_tlv), 367 0, 118, 1, output_stage_tlv),
@@ -424,6 +404,45 @@ static const struct snd_kcontrol_new aic3x_snd_controls[] = {
424 SOC_ENUM("Output Driver Ramp-up step", aic3x_rampup_step_enum), 404 SOC_ENUM("Output Driver Ramp-up step", aic3x_rampup_step_enum),
425}; 405};
426 406
407/* For other than tlv320aic3104 */
408static const struct snd_kcontrol_new aic3x_extra_snd_controls[] = {
409 /*
410 * Output controls that map to output mixer switches. Note these are
411 * only for swapped L-to-R and R-to-L routes. See below stereo controls
412 * for direct L-to-L and R-to-R routes.
413 */
414 SOC_SINGLE_TLV("Left Line Mixer Line2R Bypass Volume",
415 LINE2R_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
416
417 SOC_SINGLE_TLV("Right Line Mixer Line2L Bypass Volume",
418 LINE2L_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
419
420 SOC_SINGLE_TLV("Left HP Mixer Line2R Bypass Volume",
421 LINE2R_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
422
423 SOC_SINGLE_TLV("Right HP Mixer Line2L Bypass Volume",
424 LINE2L_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
425
426 SOC_SINGLE_TLV("Left HPCOM Mixer Line2R Bypass Volume",
427 LINE2R_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
428
429 SOC_SINGLE_TLV("Right HPCOM Mixer Line2L Bypass Volume",
430 LINE2L_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
431
432 /* Stereo output controls for direct L-to-L and R-to-R routes */
433 SOC_DOUBLE_R_TLV("Line Line2 Bypass Volume",
434 LINE2L_2_LLOPM_VOL, LINE2R_2_RLOPM_VOL,
435 0, 118, 1, output_stage_tlv),
436
437 SOC_DOUBLE_R_TLV("HP Line2 Bypass Volume",
438 LINE2L_2_HPLOUT_VOL, LINE2R_2_HPROUT_VOL,
439 0, 118, 1, output_stage_tlv),
440
441 SOC_DOUBLE_R_TLV("HPCOM Line2 Bypass Volume",
442 LINE2L_2_HPLCOM_VOL, LINE2R_2_HPRCOM_VOL,
443 0, 118, 1, output_stage_tlv),
444};
445
427static const struct snd_kcontrol_new aic3x_mono_controls[] = { 446static const struct snd_kcontrol_new aic3x_mono_controls[] = {
428 SOC_DOUBLE_R_TLV("Mono Line2 Bypass Volume", 447 SOC_DOUBLE_R_TLV("Mono Line2 Bypass Volume",
429 LINE2L_2_MONOLOPM_VOL, LINE2R_2_MONOLOPM_VOL, 448 LINE2L_2_MONOLOPM_VOL, LINE2R_2_MONOLOPM_VOL,
@@ -464,22 +483,24 @@ SOC_DAPM_ENUM("Route", aic3x_right_hpcom_enum);
464 483
465/* Left Line Mixer */ 484/* Left Line Mixer */
466static const struct snd_kcontrol_new aic3x_left_line_mixer_controls[] = { 485static const struct snd_kcontrol_new aic3x_left_line_mixer_controls[] = {
467 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_LLOPM_VOL, 7, 1, 0),
468 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_LLOPM_VOL, 7, 1, 0), 486 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_LLOPM_VOL, 7, 1, 0),
469 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_LLOPM_VOL, 7, 1, 0), 487 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_LLOPM_VOL, 7, 1, 0),
470 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_LLOPM_VOL, 7, 1, 0),
471 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_LLOPM_VOL, 7, 1, 0), 488 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_LLOPM_VOL, 7, 1, 0),
472 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_LLOPM_VOL, 7, 1, 0), 489 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_LLOPM_VOL, 7, 1, 0),
490 /* Not on tlv320aic3104 */
491 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_LLOPM_VOL, 7, 1, 0),
492 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_LLOPM_VOL, 7, 1, 0),
473}; 493};
474 494
475/* Right Line Mixer */ 495/* Right Line Mixer */
476static const struct snd_kcontrol_new aic3x_right_line_mixer_controls[] = { 496static const struct snd_kcontrol_new aic3x_right_line_mixer_controls[] = {
477 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_RLOPM_VOL, 7, 1, 0),
478 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_RLOPM_VOL, 7, 1, 0), 497 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_RLOPM_VOL, 7, 1, 0),
479 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_RLOPM_VOL, 7, 1, 0), 498 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_RLOPM_VOL, 7, 1, 0),
480 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_RLOPM_VOL, 7, 1, 0),
481 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_RLOPM_VOL, 7, 1, 0), 499 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_RLOPM_VOL, 7, 1, 0),
482 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_RLOPM_VOL, 7, 1, 0), 500 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_RLOPM_VOL, 7, 1, 0),
501 /* Not on tlv320aic3104 */
502 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_RLOPM_VOL, 7, 1, 0),
503 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_RLOPM_VOL, 7, 1, 0),
483}; 504};
484 505
485/* Mono Mixer */ 506/* Mono Mixer */
@@ -494,42 +515,46 @@ static const struct snd_kcontrol_new aic3x_mono_mixer_controls[] = {
494 515
495/* Left HP Mixer */ 516/* Left HP Mixer */
496static const struct snd_kcontrol_new aic3x_left_hp_mixer_controls[] = { 517static const struct snd_kcontrol_new aic3x_left_hp_mixer_controls[] = {
497 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPLOUT_VOL, 7, 1, 0),
498 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPLOUT_VOL, 7, 1, 0), 518 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPLOUT_VOL, 7, 1, 0),
499 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPLOUT_VOL, 7, 1, 0), 519 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPLOUT_VOL, 7, 1, 0),
500 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPLOUT_VOL, 7, 1, 0),
501 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPLOUT_VOL, 7, 1, 0), 520 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPLOUT_VOL, 7, 1, 0),
502 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPLOUT_VOL, 7, 1, 0), 521 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPLOUT_VOL, 7, 1, 0),
522 /* Not on tlv320aic3104 */
523 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPLOUT_VOL, 7, 1, 0),
524 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPLOUT_VOL, 7, 1, 0),
503}; 525};
504 526
505/* Right HP Mixer */ 527/* Right HP Mixer */
506static const struct snd_kcontrol_new aic3x_right_hp_mixer_controls[] = { 528static const struct snd_kcontrol_new aic3x_right_hp_mixer_controls[] = {
507 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPROUT_VOL, 7, 1, 0),
508 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPROUT_VOL, 7, 1, 0), 529 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPROUT_VOL, 7, 1, 0),
509 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPROUT_VOL, 7, 1, 0), 530 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPROUT_VOL, 7, 1, 0),
510 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPROUT_VOL, 7, 1, 0),
511 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPROUT_VOL, 7, 1, 0), 531 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPROUT_VOL, 7, 1, 0),
512 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPROUT_VOL, 7, 1, 0), 532 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPROUT_VOL, 7, 1, 0),
533 /* Not on tlv320aic3104 */
534 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPROUT_VOL, 7, 1, 0),
535 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPROUT_VOL, 7, 1, 0),
513}; 536};
514 537
515/* Left HPCOM Mixer */ 538/* Left HPCOM Mixer */
516static const struct snd_kcontrol_new aic3x_left_hpcom_mixer_controls[] = { 539static const struct snd_kcontrol_new aic3x_left_hpcom_mixer_controls[] = {
517 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPLCOM_VOL, 7, 1, 0),
518 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPLCOM_VOL, 7, 1, 0), 540 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPLCOM_VOL, 7, 1, 0),
519 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPLCOM_VOL, 7, 1, 0), 541 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPLCOM_VOL, 7, 1, 0),
520 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPLCOM_VOL, 7, 1, 0),
521 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPLCOM_VOL, 7, 1, 0), 542 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPLCOM_VOL, 7, 1, 0),
522 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPLCOM_VOL, 7, 1, 0), 543 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPLCOM_VOL, 7, 1, 0),
544 /* Not on tlv320aic3104 */
545 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPLCOM_VOL, 7, 1, 0),
546 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPLCOM_VOL, 7, 1, 0),
523}; 547};
524 548
525/* Right HPCOM Mixer */ 549/* Right HPCOM Mixer */
526static const struct snd_kcontrol_new aic3x_right_hpcom_mixer_controls[] = { 550static const struct snd_kcontrol_new aic3x_right_hpcom_mixer_controls[] = {
527 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPRCOM_VOL, 7, 1, 0),
528 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPRCOM_VOL, 7, 1, 0), 551 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPRCOM_VOL, 7, 1, 0),
529 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPRCOM_VOL, 7, 1, 0), 552 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPRCOM_VOL, 7, 1, 0),
530 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPRCOM_VOL, 7, 1, 0),
531 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPRCOM_VOL, 7, 1, 0), 553 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPRCOM_VOL, 7, 1, 0),
532 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPRCOM_VOL, 7, 1, 0), 554 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPRCOM_VOL, 7, 1, 0),
555 /* Not on tlv320aic3104 */
556 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPRCOM_VOL, 7, 1, 0),
557 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPRCOM_VOL, 7, 1, 0),
533}; 558};
534 559
535/* Left PGA Mixer */ 560/* Left PGA Mixer */
@@ -550,6 +575,22 @@ static const struct snd_kcontrol_new aic3x_right_pga_mixer_controls[] = {
550 SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1), 575 SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1),
551}; 576};
552 577
578/* Left PGA Mixer for tlv320aic3104 */
579static const struct snd_kcontrol_new aic3104_left_pga_mixer_controls[] = {
580 SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_LADC_CTRL, 3, 1, 1),
581 SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_LADC_CTRL, 3, 1, 1),
582 SOC_DAPM_SINGLE_AIC3X("Mic2L Switch", MIC3LR_2_LADC_CTRL, 4, 1, 1),
583 SOC_DAPM_SINGLE_AIC3X("Mic2R Switch", MIC3LR_2_LADC_CTRL, 0, 1, 1),
584};
585
586/* Right PGA Mixer for tlv320aic3104 */
587static const struct snd_kcontrol_new aic3104_right_pga_mixer_controls[] = {
588 SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_RADC_CTRL, 3, 1, 1),
589 SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_RADC_CTRL, 3, 1, 1),
590 SOC_DAPM_SINGLE_AIC3X("Mic2L Switch", MIC3LR_2_RADC_CTRL, 4, 1, 1),
591 SOC_DAPM_SINGLE_AIC3X("Mic2R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1),
592};
593
553/* Left Line1 Mux */ 594/* Left Line1 Mux */
554static const struct snd_kcontrol_new aic3x_left_line1l_mux_controls = 595static const struct snd_kcontrol_new aic3x_left_line1l_mux_controls =
555SOC_DAPM_ENUM("Route", aic3x_line1l_2_l_enum); 596SOC_DAPM_ENUM("Route", aic3x_line1l_2_l_enum);
@@ -593,26 +634,56 @@ static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
593 634
594 /* Inputs to Left ADC */ 635 /* Inputs to Left ADC */
595 SND_SOC_DAPM_ADC("Left ADC", "Left Capture", LINE1L_2_LADC_CTRL, 2, 0), 636 SND_SOC_DAPM_ADC("Left ADC", "Left Capture", LINE1L_2_LADC_CTRL, 2, 0),
596 SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0,
597 &aic3x_left_pga_mixer_controls[0],
598 ARRAY_SIZE(aic3x_left_pga_mixer_controls)),
599 SND_SOC_DAPM_MUX("Left Line1L Mux", SND_SOC_NOPM, 0, 0, 637 SND_SOC_DAPM_MUX("Left Line1L Mux", SND_SOC_NOPM, 0, 0,
600 &aic3x_left_line1l_mux_controls), 638 &aic3x_left_line1l_mux_controls),
601 SND_SOC_DAPM_MUX("Left Line1R Mux", SND_SOC_NOPM, 0, 0, 639 SND_SOC_DAPM_MUX("Left Line1R Mux", SND_SOC_NOPM, 0, 0,
602 &aic3x_left_line1r_mux_controls), 640 &aic3x_left_line1r_mux_controls),
603 SND_SOC_DAPM_MUX("Left Line2L Mux", SND_SOC_NOPM, 0, 0,
604 &aic3x_left_line2_mux_controls),
605 641
606 /* Inputs to Right ADC */ 642 /* Inputs to Right ADC */
607 SND_SOC_DAPM_ADC("Right ADC", "Right Capture", 643 SND_SOC_DAPM_ADC("Right ADC", "Right Capture",
608 LINE1R_2_RADC_CTRL, 2, 0), 644 LINE1R_2_RADC_CTRL, 2, 0),
609 SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0,
610 &aic3x_right_pga_mixer_controls[0],
611 ARRAY_SIZE(aic3x_right_pga_mixer_controls)),
612 SND_SOC_DAPM_MUX("Right Line1L Mux", SND_SOC_NOPM, 0, 0, 645 SND_SOC_DAPM_MUX("Right Line1L Mux", SND_SOC_NOPM, 0, 0,
613 &aic3x_right_line1l_mux_controls), 646 &aic3x_right_line1l_mux_controls),
614 SND_SOC_DAPM_MUX("Right Line1R Mux", SND_SOC_NOPM, 0, 0, 647 SND_SOC_DAPM_MUX("Right Line1R Mux", SND_SOC_NOPM, 0, 0,
615 &aic3x_right_line1r_mux_controls), 648 &aic3x_right_line1r_mux_controls),
649
650 /* Mic Bias */
651 SND_SOC_DAPM_SUPPLY("Mic Bias", MICBIAS_CTRL, 6, 0,
652 mic_bias_event,
653 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
654
655 SND_SOC_DAPM_OUTPUT("LLOUT"),
656 SND_SOC_DAPM_OUTPUT("RLOUT"),
657 SND_SOC_DAPM_OUTPUT("HPLOUT"),
658 SND_SOC_DAPM_OUTPUT("HPROUT"),
659 SND_SOC_DAPM_OUTPUT("HPLCOM"),
660 SND_SOC_DAPM_OUTPUT("HPRCOM"),
661
662 SND_SOC_DAPM_INPUT("LINE1L"),
663 SND_SOC_DAPM_INPUT("LINE1R"),
664
665 /*
666 * Virtual output pin to detection block inside codec. This can be
667 * used to keep codec bias on if gpio or detection features are needed.
668 * Force pin on or construct a path with an input jack and mic bias
669 * widgets.
670 */
671 SND_SOC_DAPM_OUTPUT("Detection"),
672};
673
674/* For other than tlv320aic3104 */
675static const struct snd_soc_dapm_widget aic3x_extra_dapm_widgets[] = {
676 /* Inputs to Left ADC */
677 SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0,
678 &aic3x_left_pga_mixer_controls[0],
679 ARRAY_SIZE(aic3x_left_pga_mixer_controls)),
680 SND_SOC_DAPM_MUX("Left Line2L Mux", SND_SOC_NOPM, 0, 0,
681 &aic3x_left_line2_mux_controls),
682
683 /* Inputs to Right ADC */
684 SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0,
685 &aic3x_right_pga_mixer_controls[0],
686 ARRAY_SIZE(aic3x_right_pga_mixer_controls)),
616 SND_SOC_DAPM_MUX("Right Line2R Mux", SND_SOC_NOPM, 0, 0, 687 SND_SOC_DAPM_MUX("Right Line2R Mux", SND_SOC_NOPM, 0, 0,
617 &aic3x_right_line2_mux_controls), 688 &aic3x_right_line2_mux_controls),
618 689
@@ -637,11 +708,6 @@ static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
637 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 32", 708 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 32",
638 AIC3X_ASD_INTF_CTRLA, 0, 3, 3, 0), 709 AIC3X_ASD_INTF_CTRLA, 0, 3, 3, 0),
639 710
640 /* Mic Bias */
641 SND_SOC_DAPM_SUPPLY("Mic Bias", MICBIAS_CTRL, 6, 0,
642 mic_bias_event,
643 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
644
645 /* Output mixers */ 711 /* Output mixers */
646 SND_SOC_DAPM_MIXER("Left Line Mixer", SND_SOC_NOPM, 0, 0, 712 SND_SOC_DAPM_MIXER("Left Line Mixer", SND_SOC_NOPM, 0, 0,
647 &aic3x_left_line_mixer_controls[0], 713 &aic3x_left_line_mixer_controls[0],
@@ -662,27 +728,46 @@ static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
662 &aic3x_right_hpcom_mixer_controls[0], 728 &aic3x_right_hpcom_mixer_controls[0],
663 ARRAY_SIZE(aic3x_right_hpcom_mixer_controls)), 729 ARRAY_SIZE(aic3x_right_hpcom_mixer_controls)),
664 730
665 SND_SOC_DAPM_OUTPUT("LLOUT"),
666 SND_SOC_DAPM_OUTPUT("RLOUT"),
667 SND_SOC_DAPM_OUTPUT("HPLOUT"),
668 SND_SOC_DAPM_OUTPUT("HPROUT"),
669 SND_SOC_DAPM_OUTPUT("HPLCOM"),
670 SND_SOC_DAPM_OUTPUT("HPRCOM"),
671
672 SND_SOC_DAPM_INPUT("MIC3L"), 731 SND_SOC_DAPM_INPUT("MIC3L"),
673 SND_SOC_DAPM_INPUT("MIC3R"), 732 SND_SOC_DAPM_INPUT("MIC3R"),
674 SND_SOC_DAPM_INPUT("LINE1L"),
675 SND_SOC_DAPM_INPUT("LINE1R"),
676 SND_SOC_DAPM_INPUT("LINE2L"), 733 SND_SOC_DAPM_INPUT("LINE2L"),
677 SND_SOC_DAPM_INPUT("LINE2R"), 734 SND_SOC_DAPM_INPUT("LINE2R"),
735};
678 736
679 /* 737/* For tlv320aic3104 */
680 * Virtual output pin to detection block inside codec. This can be 738static const struct snd_soc_dapm_widget aic3104_extra_dapm_widgets[] = {
681 * used to keep codec bias on if gpio or detection features are needed. 739 /* Inputs to Left ADC */
682 * Force pin on or construct a path with an input jack and mic bias 740 SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0,
683 * widgets. 741 &aic3104_left_pga_mixer_controls[0],
684 */ 742 ARRAY_SIZE(aic3104_left_pga_mixer_controls)),
685 SND_SOC_DAPM_OUTPUT("Detection"), 743
744 /* Inputs to Right ADC */
745 SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0,
746 &aic3104_right_pga_mixer_controls[0],
747 ARRAY_SIZE(aic3104_right_pga_mixer_controls)),
748
749 /* Output mixers */
750 SND_SOC_DAPM_MIXER("Left Line Mixer", SND_SOC_NOPM, 0, 0,
751 &aic3x_left_line_mixer_controls[0],
752 ARRAY_SIZE(aic3x_left_line_mixer_controls) - 2),
753 SND_SOC_DAPM_MIXER("Right Line Mixer", SND_SOC_NOPM, 0, 0,
754 &aic3x_right_line_mixer_controls[0],
755 ARRAY_SIZE(aic3x_right_line_mixer_controls) - 2),
756 SND_SOC_DAPM_MIXER("Left HP Mixer", SND_SOC_NOPM, 0, 0,
757 &aic3x_left_hp_mixer_controls[0],
758 ARRAY_SIZE(aic3x_left_hp_mixer_controls) - 2),
759 SND_SOC_DAPM_MIXER("Right HP Mixer", SND_SOC_NOPM, 0, 0,
760 &aic3x_right_hp_mixer_controls[0],
761 ARRAY_SIZE(aic3x_right_hp_mixer_controls) - 2),
762 SND_SOC_DAPM_MIXER("Left HPCOM Mixer", SND_SOC_NOPM, 0, 0,
763 &aic3x_left_hpcom_mixer_controls[0],
764 ARRAY_SIZE(aic3x_left_hpcom_mixer_controls) - 2),
765 SND_SOC_DAPM_MIXER("Right HPCOM Mixer", SND_SOC_NOPM, 0, 0,
766 &aic3x_right_hpcom_mixer_controls[0],
767 ARRAY_SIZE(aic3x_right_hpcom_mixer_controls) - 2),
768
769 SND_SOC_DAPM_INPUT("MIC2L"),
770 SND_SOC_DAPM_INPUT("MIC2R"),
686}; 771};
687 772
688static const struct snd_soc_dapm_widget aic3x_dapm_mono_widgets[] = { 773static const struct snd_soc_dapm_widget aic3x_dapm_mono_widgets[] = {
@@ -712,17 +797,10 @@ static const struct snd_soc_dapm_route intercon[] = {
712 {"Left Line1R Mux", "single-ended", "LINE1R"}, 797 {"Left Line1R Mux", "single-ended", "LINE1R"},
713 {"Left Line1R Mux", "differential", "LINE1R"}, 798 {"Left Line1R Mux", "differential", "LINE1R"},
714 799
715 {"Left Line2L Mux", "single-ended", "LINE2L"},
716 {"Left Line2L Mux", "differential", "LINE2L"},
717
718 {"Left PGA Mixer", "Line1L Switch", "Left Line1L Mux"}, 800 {"Left PGA Mixer", "Line1L Switch", "Left Line1L Mux"},
719 {"Left PGA Mixer", "Line1R Switch", "Left Line1R Mux"}, 801 {"Left PGA Mixer", "Line1R Switch", "Left Line1R Mux"},
720 {"Left PGA Mixer", "Line2L Switch", "Left Line2L Mux"},
721 {"Left PGA Mixer", "Mic3L Switch", "MIC3L"},
722 {"Left PGA Mixer", "Mic3R Switch", "MIC3R"},
723 802
724 {"Left ADC", NULL, "Left PGA Mixer"}, 803 {"Left ADC", NULL, "Left PGA Mixer"},
725 {"Left ADC", NULL, "GPIO1 dmic modclk"},
726 804
727 /* Right Input */ 805 /* Right Input */
728 {"Right Line1R Mux", "single-ended", "LINE1R"}, 806 {"Right Line1R Mux", "single-ended", "LINE1R"},
@@ -730,25 +808,10 @@ static const struct snd_soc_dapm_route intercon[] = {
730 {"Right Line1L Mux", "single-ended", "LINE1L"}, 808 {"Right Line1L Mux", "single-ended", "LINE1L"},
731 {"Right Line1L Mux", "differential", "LINE1L"}, 809 {"Right Line1L Mux", "differential", "LINE1L"},
732 810
733 {"Right Line2R Mux", "single-ended", "LINE2R"},
734 {"Right Line2R Mux", "differential", "LINE2R"},
735
736 {"Right PGA Mixer", "Line1L Switch", "Right Line1L Mux"}, 811 {"Right PGA Mixer", "Line1L Switch", "Right Line1L Mux"},
737 {"Right PGA Mixer", "Line1R Switch", "Right Line1R Mux"}, 812 {"Right PGA Mixer", "Line1R Switch", "Right Line1R Mux"},
738 {"Right PGA Mixer", "Line2R Switch", "Right Line2R Mux"},
739 {"Right PGA Mixer", "Mic3L Switch", "MIC3L"},
740 {"Right PGA Mixer", "Mic3R Switch", "MIC3R"},
741 813
742 {"Right ADC", NULL, "Right PGA Mixer"}, 814 {"Right ADC", NULL, "Right PGA Mixer"},
743 {"Right ADC", NULL, "GPIO1 dmic modclk"},
744
745 /*
746 * Logical path between digital mic enable and GPIO1 modulator clock
747 * output function
748 */
749 {"GPIO1 dmic modclk", NULL, "DMic Rate 128"},
750 {"GPIO1 dmic modclk", NULL, "DMic Rate 64"},
751 {"GPIO1 dmic modclk", NULL, "DMic Rate 32"},
752 815
753 /* Left DAC Output */ 816 /* Left DAC Output */
754 {"Left DAC Mux", "DAC_L1", "Left DAC"}, 817 {"Left DAC Mux", "DAC_L1", "Left DAC"},
@@ -761,10 +824,8 @@ static const struct snd_soc_dapm_route intercon[] = {
761 {"Right DAC Mux", "DAC_R3", "Right DAC"}, 824 {"Right DAC Mux", "DAC_R3", "Right DAC"},
762 825
763 /* Left Line Output */ 826 /* Left Line Output */
764 {"Left Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
765 {"Left Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, 827 {"Left Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
766 {"Left Line Mixer", "DACL1 Switch", "Left DAC Mux"}, 828 {"Left Line Mixer", "DACL1 Switch", "Left DAC Mux"},
767 {"Left Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
768 {"Left Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, 829 {"Left Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
769 {"Left Line Mixer", "DACR1 Switch", "Right DAC Mux"}, 830 {"Left Line Mixer", "DACR1 Switch", "Right DAC Mux"},
770 831
@@ -773,10 +834,8 @@ static const struct snd_soc_dapm_route intercon[] = {
773 {"LLOUT", NULL, "Left Line Out"}, 834 {"LLOUT", NULL, "Left Line Out"},
774 835
775 /* Right Line Output */ 836 /* Right Line Output */
776 {"Right Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
777 {"Right Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, 837 {"Right Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
778 {"Right Line Mixer", "DACL1 Switch", "Left DAC Mux"}, 838 {"Right Line Mixer", "DACL1 Switch", "Left DAC Mux"},
779 {"Right Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
780 {"Right Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, 839 {"Right Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
781 {"Right Line Mixer", "DACR1 Switch", "Right DAC Mux"}, 840 {"Right Line Mixer", "DACR1 Switch", "Right DAC Mux"},
782 841
@@ -785,10 +844,8 @@ static const struct snd_soc_dapm_route intercon[] = {
785 {"RLOUT", NULL, "Right Line Out"}, 844 {"RLOUT", NULL, "Right Line Out"},
786 845
787 /* Left HP Output */ 846 /* Left HP Output */
788 {"Left HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
789 {"Left HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, 847 {"Left HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
790 {"Left HP Mixer", "DACL1 Switch", "Left DAC Mux"}, 848 {"Left HP Mixer", "DACL1 Switch", "Left DAC Mux"},
791 {"Left HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
792 {"Left HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, 849 {"Left HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
793 {"Left HP Mixer", "DACR1 Switch", "Right DAC Mux"}, 850 {"Left HP Mixer", "DACR1 Switch", "Right DAC Mux"},
794 851
@@ -797,10 +854,8 @@ static const struct snd_soc_dapm_route intercon[] = {
797 {"HPLOUT", NULL, "Left HP Out"}, 854 {"HPLOUT", NULL, "Left HP Out"},
798 855
799 /* Right HP Output */ 856 /* Right HP Output */
800 {"Right HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
801 {"Right HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, 857 {"Right HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
802 {"Right HP Mixer", "DACL1 Switch", "Left DAC Mux"}, 858 {"Right HP Mixer", "DACL1 Switch", "Left DAC Mux"},
803 {"Right HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
804 {"Right HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, 859 {"Right HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
805 {"Right HP Mixer", "DACR1 Switch", "Right DAC Mux"}, 860 {"Right HP Mixer", "DACR1 Switch", "Right DAC Mux"},
806 861
@@ -809,10 +864,8 @@ static const struct snd_soc_dapm_route intercon[] = {
809 {"HPROUT", NULL, "Right HP Out"}, 864 {"HPROUT", NULL, "Right HP Out"},
810 865
811 /* Left HPCOM Output */ 866 /* Left HPCOM Output */
812 {"Left HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
813 {"Left HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, 867 {"Left HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
814 {"Left HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"}, 868 {"Left HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"},
815 {"Left HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
816 {"Left HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, 869 {"Left HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
817 {"Left HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"}, 870 {"Left HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"},
818 871
@@ -823,10 +876,8 @@ static const struct snd_soc_dapm_route intercon[] = {
823 {"HPLCOM", NULL, "Left HP Com"}, 876 {"HPLCOM", NULL, "Left HP Com"},
824 877
825 /* Right HPCOM Output */ 878 /* Right HPCOM Output */
826 {"Right HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
827 {"Right HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, 879 {"Right HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
828 {"Right HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"}, 880 {"Right HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"},
829 {"Right HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
830 {"Right HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, 881 {"Right HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
831 {"Right HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"}, 882 {"Right HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"},
832 883
@@ -839,6 +890,72 @@ static const struct snd_soc_dapm_route intercon[] = {
839 {"HPRCOM", NULL, "Right HP Com"}, 890 {"HPRCOM", NULL, "Right HP Com"},
840}; 891};
841 892
893/* For other than tlv320aic3104 */
894static const struct snd_soc_dapm_route intercon_extra[] = {
895 /* Left Input */
896 {"Left Line2L Mux", "single-ended", "LINE2L"},
897 {"Left Line2L Mux", "differential", "LINE2L"},
898
899 {"Left PGA Mixer", "Line2L Switch", "Left Line2L Mux"},
900 {"Left PGA Mixer", "Mic3L Switch", "MIC3L"},
901 {"Left PGA Mixer", "Mic3R Switch", "MIC3R"},
902
903 {"Left ADC", NULL, "GPIO1 dmic modclk"},
904
905 /* Right Input */
906 {"Right Line2R Mux", "single-ended", "LINE2R"},
907 {"Right Line2R Mux", "differential", "LINE2R"},
908
909 {"Right PGA Mixer", "Line2R Switch", "Right Line2R Mux"},
910 {"Right PGA Mixer", "Mic3L Switch", "MIC3L"},
911 {"Right PGA Mixer", "Mic3R Switch", "MIC3R"},
912
913 {"Right ADC", NULL, "GPIO1 dmic modclk"},
914
915 /*
916 * Logical path between digital mic enable and GPIO1 modulator clock
917 * output function
918 */
919 {"GPIO1 dmic modclk", NULL, "DMic Rate 128"},
920 {"GPIO1 dmic modclk", NULL, "DMic Rate 64"},
921 {"GPIO1 dmic modclk", NULL, "DMic Rate 32"},
922
923 /* Left Line Output */
924 {"Left Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
925 {"Left Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
926
927 /* Right Line Output */
928 {"Right Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
929 {"Right Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
930
931 /* Left HP Output */
932 {"Left HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
933 {"Left HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
934
935 /* Right HP Output */
936 {"Right HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
937 {"Right HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
938
939 /* Left HPCOM Output */
940 {"Left HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
941 {"Left HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
942
943 /* Right HPCOM Output */
944 {"Right HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
945 {"Right HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
946};
947
948/* For tlv320aic3104 */
949static const struct snd_soc_dapm_route intercon_extra_3104[] = {
950 /* Left Input */
951 {"Left PGA Mixer", "Mic2L Switch", "MIC2L"},
952 {"Left PGA Mixer", "Mic2R Switch", "MIC2R"},
953
954 /* Right Input */
955 {"Right PGA Mixer", "Mic2L Switch", "MIC2L"},
956 {"Right PGA Mixer", "Mic2R Switch", "MIC2R"},
957};
958
842static const struct snd_soc_dapm_route intercon_mono[] = { 959static const struct snd_soc_dapm_route intercon_mono[] = {
843 /* Mono Output */ 960 /* Mono Output */
844 {"Mono Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, 961 {"Mono Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
@@ -867,17 +984,31 @@ static int aic3x_add_widgets(struct snd_soc_codec *codec)
867 switch (aic3x->model) { 984 switch (aic3x->model) {
868 case AIC3X_MODEL_3X: 985 case AIC3X_MODEL_3X:
869 case AIC3X_MODEL_33: 986 case AIC3X_MODEL_33:
987 snd_soc_dapm_new_controls(dapm, aic3x_extra_dapm_widgets,
988 ARRAY_SIZE(aic3x_extra_dapm_widgets));
989 snd_soc_dapm_add_routes(dapm, intercon_extra,
990 ARRAY_SIZE(intercon_extra));
870 snd_soc_dapm_new_controls(dapm, aic3x_dapm_mono_widgets, 991 snd_soc_dapm_new_controls(dapm, aic3x_dapm_mono_widgets,
871 ARRAY_SIZE(aic3x_dapm_mono_widgets)); 992 ARRAY_SIZE(aic3x_dapm_mono_widgets));
872 snd_soc_dapm_add_routes(dapm, intercon_mono, 993 snd_soc_dapm_add_routes(dapm, intercon_mono,
873 ARRAY_SIZE(intercon_mono)); 994 ARRAY_SIZE(intercon_mono));
874 break; 995 break;
875 case AIC3X_MODEL_3007: 996 case AIC3X_MODEL_3007:
997 snd_soc_dapm_new_controls(dapm, aic3x_extra_dapm_widgets,
998 ARRAY_SIZE(aic3x_extra_dapm_widgets));
999 snd_soc_dapm_add_routes(dapm, intercon_extra,
1000 ARRAY_SIZE(intercon_extra));
876 snd_soc_dapm_new_controls(dapm, aic3007_dapm_widgets, 1001 snd_soc_dapm_new_controls(dapm, aic3007_dapm_widgets,
877 ARRAY_SIZE(aic3007_dapm_widgets)); 1002 ARRAY_SIZE(aic3007_dapm_widgets));
878 snd_soc_dapm_add_routes(dapm, intercon_3007, 1003 snd_soc_dapm_add_routes(dapm, intercon_3007,
879 ARRAY_SIZE(intercon_3007)); 1004 ARRAY_SIZE(intercon_3007));
880 break; 1005 break;
1006 case AIC3X_MODEL_3104:
1007 snd_soc_dapm_new_controls(dapm, aic3104_extra_dapm_widgets,
1008 ARRAY_SIZE(aic3104_extra_dapm_widgets));
1009 snd_soc_dapm_add_routes(dapm, intercon_extra_3104,
1010 ARRAY_SIZE(intercon_extra_3104));
1011 break;
881 } 1012 }
882 1013
883 return 0; 1014 return 0;
@@ -1046,7 +1177,7 @@ static int aic3x_prepare(struct snd_pcm_substream *substream,
1046 delay += aic3x->tdm_delay; 1177 delay += aic3x->tdm_delay;
1047 1178
1048 /* Configure data delay */ 1179 /* Configure data delay */
1049 snd_soc_write(codec, AIC3X_ASD_INTF_CTRLC, aic3x->tdm_delay); 1180 snd_soc_write(codec, AIC3X_ASD_INTF_CTRLC, delay);
1050 1181
1051 return 0; 1182 return 0;
1052} 1183}
@@ -1438,23 +1569,33 @@ static int aic3x_probe(struct snd_soc_codec *codec)
1438 aic3x_init(codec); 1569 aic3x_init(codec);
1439 1570
1440 if (aic3x->setup) { 1571 if (aic3x->setup) {
1441 /* setup GPIO functions */ 1572 if (aic3x->model != AIC3X_MODEL_3104) {
1442 snd_soc_write(codec, AIC3X_GPIO1_REG, 1573 /* setup GPIO functions */
1443 (aic3x->setup->gpio_func[0] & 0xf) << 4); 1574 snd_soc_write(codec, AIC3X_GPIO1_REG,
1444 snd_soc_write(codec, AIC3X_GPIO2_REG, 1575 (aic3x->setup->gpio_func[0] & 0xf) << 4);
1445 (aic3x->setup->gpio_func[1] & 0xf) << 4); 1576 snd_soc_write(codec, AIC3X_GPIO2_REG,
1577 (aic3x->setup->gpio_func[1] & 0xf) << 4);
1578 } else {
1579 dev_warn(codec->dev, "GPIO functionality is not supported on tlv320aic3104\n");
1580 }
1446 } 1581 }
1447 1582
1448 switch (aic3x->model) { 1583 switch (aic3x->model) {
1449 case AIC3X_MODEL_3X: 1584 case AIC3X_MODEL_3X:
1450 case AIC3X_MODEL_33: 1585 case AIC3X_MODEL_33:
1586 snd_soc_add_codec_controls(codec, aic3x_extra_snd_controls,
1587 ARRAY_SIZE(aic3x_extra_snd_controls));
1451 snd_soc_add_codec_controls(codec, aic3x_mono_controls, 1588 snd_soc_add_codec_controls(codec, aic3x_mono_controls,
1452 ARRAY_SIZE(aic3x_mono_controls)); 1589 ARRAY_SIZE(aic3x_mono_controls));
1453 break; 1590 break;
1454 case AIC3X_MODEL_3007: 1591 case AIC3X_MODEL_3007:
1592 snd_soc_add_codec_controls(codec, aic3x_extra_snd_controls,
1593 ARRAY_SIZE(aic3x_extra_snd_controls));
1455 snd_soc_add_codec_controls(codec, 1594 snd_soc_add_codec_controls(codec,
1456 &aic3x_classd_amp_gain_ctrl, 1); 1595 &aic3x_classd_amp_gain_ctrl, 1);
1457 break; 1596 break;
1597 case AIC3X_MODEL_3104:
1598 break;
1458 } 1599 }
1459 1600
1460 /* set mic bias voltage */ 1601 /* set mic bias voltage */
@@ -1522,6 +1663,7 @@ static const struct i2c_device_id aic3x_i2c_id[] = {
1522 { "tlv320aic33", AIC3X_MODEL_33 }, 1663 { "tlv320aic33", AIC3X_MODEL_33 },
1523 { "tlv320aic3007", AIC3X_MODEL_3007 }, 1664 { "tlv320aic3007", AIC3X_MODEL_3007 },
1524 { "tlv320aic3106", AIC3X_MODEL_3X }, 1665 { "tlv320aic3106", AIC3X_MODEL_3X },
1666 { "tlv320aic3104", AIC3X_MODEL_3104 },
1525 { } 1667 { }
1526}; 1668};
1527MODULE_DEVICE_TABLE(i2c, aic3x_i2c_id); 1669MODULE_DEVICE_TABLE(i2c, aic3x_i2c_id);
@@ -1673,6 +1815,7 @@ static const struct of_device_id tlv320aic3x_of_match[] = {
1673 { .compatible = "ti,tlv320aic33" }, 1815 { .compatible = "ti,tlv320aic33" },
1674 { .compatible = "ti,tlv320aic3007" }, 1816 { .compatible = "ti,tlv320aic3007" },
1675 { .compatible = "ti,tlv320aic3106" }, 1817 { .compatible = "ti,tlv320aic3106" },
1818 { .compatible = "ti,tlv320aic3104" },
1676 {}, 1819 {},
1677}; 1820};
1678MODULE_DEVICE_TABLE(of, tlv320aic3x_of_match); 1821MODULE_DEVICE_TABLE(of, tlv320aic3x_of_match);
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index 0fe2ced5b09f..4e3e607dec13 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -423,17 +423,18 @@ exit:
423static int dac33_playback_event(struct snd_soc_dapm_widget *w, 423static int dac33_playback_event(struct snd_soc_dapm_widget *w,
424 struct snd_kcontrol *kcontrol, int event) 424 struct snd_kcontrol *kcontrol, int event)
425{ 425{
426 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(w->codec); 426 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
427 struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
427 428
428 switch (event) { 429 switch (event) {
429 case SND_SOC_DAPM_PRE_PMU: 430 case SND_SOC_DAPM_PRE_PMU:
430 if (likely(dac33->substream)) { 431 if (likely(dac33->substream)) {
431 dac33_calculate_times(dac33->substream, w->codec); 432 dac33_calculate_times(dac33->substream, codec);
432 dac33_prepare_chip(dac33->substream, w->codec); 433 dac33_prepare_chip(dac33->substream, codec);
433 } 434 }
434 break; 435 break;
435 case SND_SOC_DAPM_POST_PMD: 436 case SND_SOC_DAPM_POST_PMD:
436 dac33_disable_digital(w->codec); 437 dac33_disable_digital(codec);
437 break; 438 break;
438 } 439 }
439 return 0; 440 return 0;
diff --git a/sound/soc/codecs/ts3a227e.c b/sound/soc/codecs/ts3a227e.c
index 9f2dced046de..9fd80ac1897f 100644
--- a/sound/soc/codecs/ts3a227e.c
+++ b/sound/soc/codecs/ts3a227e.c
@@ -20,6 +20,8 @@
20#include <sound/jack.h> 20#include <sound/jack.h>
21#include <sound/soc.h> 21#include <sound/soc.h>
22 22
23#include "ts3a227e.h"
24
23struct ts3a227e { 25struct ts3a227e {
24 struct regmap *regmap; 26 struct regmap *regmap;
25 struct snd_soc_jack *jack; 27 struct snd_soc_jack *jack;
@@ -79,6 +81,10 @@ static const int ts3a227e_buttons[] = {
79/* TS3A227E_REG_SETTING_2 0x05 */ 81/* TS3A227E_REG_SETTING_2 0x05 */
80#define KP_ENABLE 0x04 82#define KP_ENABLE 0x04
81 83
84/* TS3A227E_REG_SETTING_3 0x06 */
85#define MICBIAS_SETTING_SFT (3)
86#define MICBIAS_SETTING_MASK (0x7 << MICBIAS_SETTING_SFT)
87
82/* TS3A227E_REG_ACCESSORY_STATUS 0x0b */ 88/* TS3A227E_REG_ACCESSORY_STATUS 0x0b */
83#define TYPE_3_POLE 0x01 89#define TYPE_3_POLE 0x01
84#define TYPE_4_POLE_OMTP 0x02 90#define TYPE_4_POLE_OMTP 0x02
@@ -221,9 +227,9 @@ int ts3a227e_enable_jack_detect(struct snd_soc_component *component,
221 struct ts3a227e *ts3a227e = snd_soc_component_get_drvdata(component); 227 struct ts3a227e *ts3a227e = snd_soc_component_get_drvdata(component);
222 228
223 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_MEDIA); 229 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_MEDIA);
224 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP); 230 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
225 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); 231 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
226 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); 232 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
227 233
228 ts3a227e->jack = jack; 234 ts3a227e->jack = jack;
229 ts3a227e_jack_report(ts3a227e); 235 ts3a227e_jack_report(ts3a227e);
@@ -248,6 +254,21 @@ static const struct regmap_config ts3a227e_regmap_config = {
248 .num_reg_defaults = ARRAY_SIZE(ts3a227e_reg_defaults), 254 .num_reg_defaults = ARRAY_SIZE(ts3a227e_reg_defaults),
249}; 255};
250 256
257static int ts3a227e_parse_dt(struct ts3a227e *ts3a227e, struct device_node *np)
258{
259 u32 micbias;
260 int err;
261
262 err = of_property_read_u32(np, "ti,micbias", &micbias);
263 if (!err) {
264 regmap_update_bits(ts3a227e->regmap, TS3A227E_REG_SETTING_3,
265 MICBIAS_SETTING_MASK,
266 (micbias & 0x07) << MICBIAS_SETTING_SFT);
267 }
268
269 return 0;
270}
271
251static int ts3a227e_i2c_probe(struct i2c_client *i2c, 272static int ts3a227e_i2c_probe(struct i2c_client *i2c,
252 const struct i2c_device_id *id) 273 const struct i2c_device_id *id)
253{ 274{
@@ -266,6 +287,14 @@ static int ts3a227e_i2c_probe(struct i2c_client *i2c,
266 if (IS_ERR(ts3a227e->regmap)) 287 if (IS_ERR(ts3a227e->regmap))
267 return PTR_ERR(ts3a227e->regmap); 288 return PTR_ERR(ts3a227e->regmap);
268 289
290 if (dev->of_node) {
291 ret = ts3a227e_parse_dt(ts3a227e, dev->of_node);
292 if (ret) {
293 dev_err(dev, "Failed to parse device tree: %d\n", ret);
294 return ret;
295 }
296 }
297
269 ret = devm_request_threaded_irq(dev, i2c->irq, NULL, ts3a227e_interrupt, 298 ret = devm_request_threaded_irq(dev, i2c->irq, NULL, ts3a227e_interrupt,
270 IRQF_TRIGGER_LOW | IRQF_ONESHOT, 299 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
271 "TS3A227E", ts3a227e); 300 "TS3A227E", ts3a227e);
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index 44af3188afb9..d04693e9cf9f 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -567,12 +567,13 @@ static const struct snd_kcontrol_new twl4030_dapm_dbypassv_control =
567static int pin_name##pga_event(struct snd_soc_dapm_widget *w, \ 567static int pin_name##pga_event(struct snd_soc_dapm_widget *w, \
568 struct snd_kcontrol *kcontrol, int event) \ 568 struct snd_kcontrol *kcontrol, int event) \
569{ \ 569{ \
570 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec); \ 570 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); \
571 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); \
571 \ 572 \
572 switch (event) { \ 573 switch (event) { \
573 case SND_SOC_DAPM_POST_PMU: \ 574 case SND_SOC_DAPM_POST_PMU: \
574 twl4030->pin_name##_enabled = 1; \ 575 twl4030->pin_name##_enabled = 1; \
575 twl4030_write(w->codec, reg, twl4030_read(w->codec, reg)); \ 576 twl4030_write(codec, reg, twl4030_read(codec, reg)); \
576 break; \ 577 break; \
577 case SND_SOC_DAPM_POST_PMD: \ 578 case SND_SOC_DAPM_POST_PMD: \
578 twl4030->pin_name##_enabled = 0; \ 579 twl4030->pin_name##_enabled = 0; \
@@ -621,12 +622,14 @@ static void handsfree_ramp(struct snd_soc_codec *codec, int reg, int ramp)
621static int handsfreelpga_event(struct snd_soc_dapm_widget *w, 622static int handsfreelpga_event(struct snd_soc_dapm_widget *w,
622 struct snd_kcontrol *kcontrol, int event) 623 struct snd_kcontrol *kcontrol, int event)
623{ 624{
625 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
626
624 switch (event) { 627 switch (event) {
625 case SND_SOC_DAPM_POST_PMU: 628 case SND_SOC_DAPM_POST_PMU:
626 handsfree_ramp(w->codec, TWL4030_REG_HFL_CTL, 1); 629 handsfree_ramp(codec, TWL4030_REG_HFL_CTL, 1);
627 break; 630 break;
628 case SND_SOC_DAPM_POST_PMD: 631 case SND_SOC_DAPM_POST_PMD:
629 handsfree_ramp(w->codec, TWL4030_REG_HFL_CTL, 0); 632 handsfree_ramp(codec, TWL4030_REG_HFL_CTL, 0);
630 break; 633 break;
631 } 634 }
632 return 0; 635 return 0;
@@ -635,12 +638,14 @@ static int handsfreelpga_event(struct snd_soc_dapm_widget *w,
635static int handsfreerpga_event(struct snd_soc_dapm_widget *w, 638static int handsfreerpga_event(struct snd_soc_dapm_widget *w,
636 struct snd_kcontrol *kcontrol, int event) 639 struct snd_kcontrol *kcontrol, int event)
637{ 640{
641 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
642
638 switch (event) { 643 switch (event) {
639 case SND_SOC_DAPM_POST_PMU: 644 case SND_SOC_DAPM_POST_PMU:
640 handsfree_ramp(w->codec, TWL4030_REG_HFR_CTL, 1); 645 handsfree_ramp(codec, TWL4030_REG_HFR_CTL, 1);
641 break; 646 break;
642 case SND_SOC_DAPM_POST_PMD: 647 case SND_SOC_DAPM_POST_PMD:
643 handsfree_ramp(w->codec, TWL4030_REG_HFR_CTL, 0); 648 handsfree_ramp(codec, TWL4030_REG_HFR_CTL, 0);
644 break; 649 break;
645 } 650 }
646 return 0; 651 return 0;
@@ -649,19 +654,23 @@ static int handsfreerpga_event(struct snd_soc_dapm_widget *w,
649static int vibramux_event(struct snd_soc_dapm_widget *w, 654static int vibramux_event(struct snd_soc_dapm_widget *w,
650 struct snd_kcontrol *kcontrol, int event) 655 struct snd_kcontrol *kcontrol, int event)
651{ 656{
652 twl4030_write(w->codec, TWL4030_REG_VIBRA_SET, 0xff); 657 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
658
659 twl4030_write(codec, TWL4030_REG_VIBRA_SET, 0xff);
653 return 0; 660 return 0;
654} 661}
655 662
656static int apll_event(struct snd_soc_dapm_widget *w, 663static int apll_event(struct snd_soc_dapm_widget *w,
657 struct snd_kcontrol *kcontrol, int event) 664 struct snd_kcontrol *kcontrol, int event)
658{ 665{
666 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
667
659 switch (event) { 668 switch (event) {
660 case SND_SOC_DAPM_PRE_PMU: 669 case SND_SOC_DAPM_PRE_PMU:
661 twl4030_apll_enable(w->codec, 1); 670 twl4030_apll_enable(codec, 1);
662 break; 671 break;
663 case SND_SOC_DAPM_POST_PMD: 672 case SND_SOC_DAPM_POST_PMD:
664 twl4030_apll_enable(w->codec, 0); 673 twl4030_apll_enable(codec, 0);
665 break; 674 break;
666 } 675 }
667 return 0; 676 return 0;
@@ -670,23 +679,24 @@ static int apll_event(struct snd_soc_dapm_widget *w,
670static int aif_event(struct snd_soc_dapm_widget *w, 679static int aif_event(struct snd_soc_dapm_widget *w,
671 struct snd_kcontrol *kcontrol, int event) 680 struct snd_kcontrol *kcontrol, int event)
672{ 681{
682 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
673 u8 audio_if; 683 u8 audio_if;
674 684
675 audio_if = twl4030_read(w->codec, TWL4030_REG_AUDIO_IF); 685 audio_if = twl4030_read(codec, TWL4030_REG_AUDIO_IF);
676 switch (event) { 686 switch (event) {
677 case SND_SOC_DAPM_PRE_PMU: 687 case SND_SOC_DAPM_PRE_PMU:
678 /* Enable AIF */ 688 /* Enable AIF */
679 /* enable the PLL before we use it to clock the DAI */ 689 /* enable the PLL before we use it to clock the DAI */
680 twl4030_apll_enable(w->codec, 1); 690 twl4030_apll_enable(codec, 1);
681 691
682 twl4030_write(w->codec, TWL4030_REG_AUDIO_IF, 692 twl4030_write(codec, TWL4030_REG_AUDIO_IF,
683 audio_if | TWL4030_AIF_EN); 693 audio_if | TWL4030_AIF_EN);
684 break; 694 break;
685 case SND_SOC_DAPM_POST_PMD: 695 case SND_SOC_DAPM_POST_PMD:
686 /* disable the DAI before we stop it's source PLL */ 696 /* disable the DAI before we stop it's source PLL */
687 twl4030_write(w->codec, TWL4030_REG_AUDIO_IF, 697 twl4030_write(codec, TWL4030_REG_AUDIO_IF,
688 audio_if & ~TWL4030_AIF_EN); 698 audio_if & ~TWL4030_AIF_EN);
689 twl4030_apll_enable(w->codec, 0); 699 twl4030_apll_enable(codec, 0);
690 break; 700 break;
691 } 701 }
692 return 0; 702 return 0;
@@ -758,20 +768,21 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
758static int headsetlpga_event(struct snd_soc_dapm_widget *w, 768static int headsetlpga_event(struct snd_soc_dapm_widget *w,
759 struct snd_kcontrol *kcontrol, int event) 769 struct snd_kcontrol *kcontrol, int event)
760{ 770{
761 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec); 771 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
772 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
762 773
763 switch (event) { 774 switch (event) {
764 case SND_SOC_DAPM_POST_PMU: 775 case SND_SOC_DAPM_POST_PMU:
765 /* Do the ramp-up only once */ 776 /* Do the ramp-up only once */
766 if (!twl4030->hsr_enabled) 777 if (!twl4030->hsr_enabled)
767 headset_ramp(w->codec, 1); 778 headset_ramp(codec, 1);
768 779
769 twl4030->hsl_enabled = 1; 780 twl4030->hsl_enabled = 1;
770 break; 781 break;
771 case SND_SOC_DAPM_POST_PMD: 782 case SND_SOC_DAPM_POST_PMD:
772 /* Do the ramp-down only if both headsetL/R is disabled */ 783 /* Do the ramp-down only if both headsetL/R is disabled */
773 if (!twl4030->hsr_enabled) 784 if (!twl4030->hsr_enabled)
774 headset_ramp(w->codec, 0); 785 headset_ramp(codec, 0);
775 786
776 twl4030->hsl_enabled = 0; 787 twl4030->hsl_enabled = 0;
777 break; 788 break;
@@ -782,20 +793,21 @@ static int headsetlpga_event(struct snd_soc_dapm_widget *w,
782static int headsetrpga_event(struct snd_soc_dapm_widget *w, 793static int headsetrpga_event(struct snd_soc_dapm_widget *w,
783 struct snd_kcontrol *kcontrol, int event) 794 struct snd_kcontrol *kcontrol, int event)
784{ 795{
785 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec); 796 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
797 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
786 798
787 switch (event) { 799 switch (event) {
788 case SND_SOC_DAPM_POST_PMU: 800 case SND_SOC_DAPM_POST_PMU:
789 /* Do the ramp-up only once */ 801 /* Do the ramp-up only once */
790 if (!twl4030->hsl_enabled) 802 if (!twl4030->hsl_enabled)
791 headset_ramp(w->codec, 1); 803 headset_ramp(codec, 1);
792 804
793 twl4030->hsr_enabled = 1; 805 twl4030->hsr_enabled = 1;
794 break; 806 break;
795 case SND_SOC_DAPM_POST_PMD: 807 case SND_SOC_DAPM_POST_PMD:
796 /* Do the ramp-down only if both headsetL/R is disabled */ 808 /* Do the ramp-down only if both headsetL/R is disabled */
797 if (!twl4030->hsl_enabled) 809 if (!twl4030->hsl_enabled)
798 headset_ramp(w->codec, 0); 810 headset_ramp(codec, 0);
799 811
800 twl4030->hsr_enabled = 0; 812 twl4030->hsr_enabled = 0;
801 break; 813 break;
@@ -806,7 +818,8 @@ static int headsetrpga_event(struct snd_soc_dapm_widget *w,
806static int digimic_event(struct snd_soc_dapm_widget *w, 818static int digimic_event(struct snd_soc_dapm_widget *w,
807 struct snd_kcontrol *kcontrol, int event) 819 struct snd_kcontrol *kcontrol, int event)
808{ 820{
809 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec); 821 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
822 struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
810 struct twl4030_codec_data *pdata = twl4030->pdata; 823 struct twl4030_codec_data *pdata = twl4030->pdata;
811 824
812 if (pdata && pdata->digimic_delay) 825 if (pdata && pdata->digimic_delay)
diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c
index 90f47f988b3f..aeec27b6f1af 100644
--- a/sound/soc/codecs/twl6040.c
+++ b/sound/soc/codecs/twl6040.c
@@ -234,7 +234,7 @@ static int headset_power_mode(struct snd_soc_codec *codec, int high_perf)
234static int twl6040_hs_dac_event(struct snd_soc_dapm_widget *w, 234static int twl6040_hs_dac_event(struct snd_soc_dapm_widget *w,
235 struct snd_kcontrol *kcontrol, int event) 235 struct snd_kcontrol *kcontrol, int event)
236{ 236{
237 struct snd_soc_codec *codec = w->codec; 237 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
238 u8 hslctl, hsrctl; 238 u8 hslctl, hsrctl;
239 239
240 /* 240 /*
@@ -261,7 +261,7 @@ static int twl6040_hs_dac_event(struct snd_soc_dapm_widget *w,
261static int twl6040_ep_drv_event(struct snd_soc_dapm_widget *w, 261static int twl6040_ep_drv_event(struct snd_soc_dapm_widget *w,
262 struct snd_kcontrol *kcontrol, int event) 262 struct snd_kcontrol *kcontrol, int event)
263{ 263{
264 struct snd_soc_codec *codec = w->codec; 264 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
265 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec); 265 struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
266 int ret = 0; 266 int ret = 0;
267 267
diff --git a/sound/soc/codecs/wm2000.c b/sound/soc/codecs/wm2000.c
index 34ef65c52a7d..8d9de49a5052 100644
--- a/sound/soc/codecs/wm2000.c
+++ b/sound/soc/codecs/wm2000.c
@@ -683,7 +683,7 @@ static const struct snd_kcontrol_new wm2000_controls[] = {
683static int wm2000_anc_power_event(struct snd_soc_dapm_widget *w, 683static int wm2000_anc_power_event(struct snd_soc_dapm_widget *w,
684 struct snd_kcontrol *kcontrol, int event) 684 struct snd_kcontrol *kcontrol, int event)
685{ 685{
686 struct snd_soc_codec *codec = w->codec; 686 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
687 struct wm2000_priv *wm2000 = dev_get_drvdata(codec->dev); 687 struct wm2000_priv *wm2000 = dev_get_drvdata(codec->dev);
688 int ret; 688 int ret;
689 689
diff --git a/sound/soc/codecs/wm5100.c b/sound/soc/codecs/wm5100.c
index b80970dc2d2f..ea09db585aa1 100644
--- a/sound/soc/codecs/wm5100.c
+++ b/sound/soc/codecs/wm5100.c
@@ -775,7 +775,8 @@ static int wm5100_out_ev(struct snd_soc_dapm_widget *w,
775 struct snd_kcontrol *kcontrol, 775 struct snd_kcontrol *kcontrol,
776 int event) 776 int event)
777{ 777{
778 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(w->codec); 778 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
779 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
779 780
780 switch (w->reg) { 781 switch (w->reg) {
781 case WM5100_CHANNEL_ENABLES_1: 782 case WM5100_CHANNEL_ENABLES_1:
@@ -839,7 +840,7 @@ static int wm5100_post_ev(struct snd_soc_dapm_widget *w,
839 struct snd_kcontrol *kcontrol, 840 struct snd_kcontrol *kcontrol,
840 int event) 841 int event)
841{ 842{
842 struct snd_soc_codec *codec = w->codec; 843 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
843 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec); 844 struct wm5100_priv *wm5100 = snd_soc_codec_get_drvdata(codec);
844 int ret; 845 int ret;
845 846
diff --git a/sound/soc/codecs/wm5102.c b/sound/soc/codecs/wm5102.c
index f439ae052128..6d0fe0ac95a3 100644
--- a/sound/soc/codecs/wm5102.c
+++ b/sound/soc/codecs/wm5102.c
@@ -28,6 +28,7 @@
28 28
29#include <linux/mfd/arizona/core.h> 29#include <linux/mfd/arizona/core.h>
30#include <linux/mfd/arizona/registers.h> 30#include <linux/mfd/arizona/registers.h>
31#include <asm/unaligned.h>
31 32
32#include "arizona.h" 33#include "arizona.h"
33#include "wm5102.h" 34#include "wm5102.h"
@@ -580,7 +581,7 @@ static const struct reg_default wm5102_sysclk_revb_patch[] = {
580static int wm5102_sysclk_ev(struct snd_soc_dapm_widget *w, 581static int wm5102_sysclk_ev(struct snd_soc_dapm_widget *w,
581 struct snd_kcontrol *kcontrol, int event) 582 struct snd_kcontrol *kcontrol, int event)
582{ 583{
583 struct snd_soc_codec *codec = w->codec; 584 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
584 struct arizona *arizona = dev_get_drvdata(codec->dev->parent); 585 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
585 struct regmap *regmap = arizona->regmap; 586 struct regmap *regmap = arizona->regmap;
586 const struct reg_default *patch = NULL; 587 const struct reg_default *patch = NULL;
@@ -617,11 +618,10 @@ static int wm5102_out_comp_coeff_get(struct snd_kcontrol *kcontrol,
617{ 618{
618 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); 619 struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
619 struct arizona *arizona = dev_get_drvdata(codec->dev->parent); 620 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
620 uint16_t data;
621 621
622 mutex_lock(&arizona->dac_comp_lock); 622 mutex_lock(&arizona->dac_comp_lock);
623 data = cpu_to_be16(arizona->dac_comp_coeff); 623 put_unaligned_be16(arizona->dac_comp_coeff,
624 memcpy(ucontrol->value.bytes.data, &data, sizeof(data)); 624 ucontrol->value.bytes.data);
625 mutex_unlock(&arizona->dac_comp_lock); 625 mutex_unlock(&arizona->dac_comp_lock);
626 626
627 return 0; 627 return 0;
@@ -1272,19 +1272,24 @@ SND_SOC_DAPM_MUX("AEC Loopback", ARIZONA_DAC_AEC_CONTROL_1,
1272 1272
1273SND_SOC_DAPM_PGA_E("OUT1L", SND_SOC_NOPM, 1273SND_SOC_DAPM_PGA_E("OUT1L", SND_SOC_NOPM,
1274 ARIZONA_OUT1L_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev, 1274 ARIZONA_OUT1L_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev,
1275 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 1275 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
1276 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
1276SND_SOC_DAPM_PGA_E("OUT1R", SND_SOC_NOPM, 1277SND_SOC_DAPM_PGA_E("OUT1R", SND_SOC_NOPM,
1277 ARIZONA_OUT1R_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev, 1278 ARIZONA_OUT1R_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev,
1278 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 1279 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
1280 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
1279SND_SOC_DAPM_PGA_E("OUT2L", ARIZONA_OUTPUT_ENABLES_1, 1281SND_SOC_DAPM_PGA_E("OUT2L", ARIZONA_OUTPUT_ENABLES_1,
1280 ARIZONA_OUT2L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 1282 ARIZONA_OUT2L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev,
1281 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 1283 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
1284 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
1282SND_SOC_DAPM_PGA_E("OUT2R", ARIZONA_OUTPUT_ENABLES_1, 1285SND_SOC_DAPM_PGA_E("OUT2R", ARIZONA_OUTPUT_ENABLES_1,
1283 ARIZONA_OUT2R_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 1286 ARIZONA_OUT2R_ENA_SHIFT, 0, NULL, 0, arizona_out_ev,
1284 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 1287 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
1288 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
1285SND_SOC_DAPM_PGA_E("OUT3L", ARIZONA_OUTPUT_ENABLES_1, 1289SND_SOC_DAPM_PGA_E("OUT3L", ARIZONA_OUTPUT_ENABLES_1,
1286 ARIZONA_OUT3L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 1290 ARIZONA_OUT3L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev,
1287 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 1291 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
1292 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
1288SND_SOC_DAPM_PGA_E("OUT5L", ARIZONA_OUTPUT_ENABLES_1, 1293SND_SOC_DAPM_PGA_E("OUT5L", ARIZONA_OUTPUT_ENABLES_1,
1289 ARIZONA_OUT5L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 1294 ARIZONA_OUT5L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev,
1290 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 1295 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
diff --git a/sound/soc/codecs/wm5110.c b/sound/soc/codecs/wm5110.c
index 4456b38a3ef5..fbaeddb3e903 100644
--- a/sound/soc/codecs/wm5110.c
+++ b/sound/soc/codecs/wm5110.c
@@ -134,7 +134,7 @@ static const struct reg_default wm5110_sysclk_revd_patch[] = {
134static int wm5110_sysclk_ev(struct snd_soc_dapm_widget *w, 134static int wm5110_sysclk_ev(struct snd_soc_dapm_widget *w,
135 struct snd_kcontrol *kcontrol, int event) 135 struct snd_kcontrol *kcontrol, int event)
136{ 136{
137 struct snd_soc_codec *codec = w->codec; 137 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
138 struct arizona *arizona = dev_get_drvdata(codec->dev->parent); 138 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
139 struct regmap *regmap = arizona->regmap; 139 struct regmap *regmap = arizona->regmap;
140 const struct reg_default *patch = NULL; 140 const struct reg_default *patch = NULL;
@@ -905,22 +905,28 @@ SND_SOC_DAPM_AIF_IN("AIF3RX2", NULL, 0,
905 905
906SND_SOC_DAPM_PGA_E("OUT1L", SND_SOC_NOPM, 906SND_SOC_DAPM_PGA_E("OUT1L", SND_SOC_NOPM,
907 ARIZONA_OUT1L_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev, 907 ARIZONA_OUT1L_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev,
908 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 908 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
909 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
909SND_SOC_DAPM_PGA_E("OUT1R", SND_SOC_NOPM, 910SND_SOC_DAPM_PGA_E("OUT1R", SND_SOC_NOPM,
910 ARIZONA_OUT1R_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev, 911 ARIZONA_OUT1R_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev,
911 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 912 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
913 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
912SND_SOC_DAPM_PGA_E("OUT2L", ARIZONA_OUTPUT_ENABLES_1, 914SND_SOC_DAPM_PGA_E("OUT2L", ARIZONA_OUTPUT_ENABLES_1,
913 ARIZONA_OUT2L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 915 ARIZONA_OUT2L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev,
914 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 916 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
917 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
915SND_SOC_DAPM_PGA_E("OUT2R", ARIZONA_OUTPUT_ENABLES_1, 918SND_SOC_DAPM_PGA_E("OUT2R", ARIZONA_OUTPUT_ENABLES_1,
916 ARIZONA_OUT2R_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 919 ARIZONA_OUT2R_ENA_SHIFT, 0, NULL, 0, arizona_out_ev,
917 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 920 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
921 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
918SND_SOC_DAPM_PGA_E("OUT3L", ARIZONA_OUTPUT_ENABLES_1, 922SND_SOC_DAPM_PGA_E("OUT3L", ARIZONA_OUTPUT_ENABLES_1,
919 ARIZONA_OUT3L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 923 ARIZONA_OUT3L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev,
920 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 924 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
925 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
921SND_SOC_DAPM_PGA_E("OUT3R", ARIZONA_OUTPUT_ENABLES_1, 926SND_SOC_DAPM_PGA_E("OUT3R", ARIZONA_OUTPUT_ENABLES_1,
922 ARIZONA_OUT3R_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 927 ARIZONA_OUT3R_ENA_SHIFT, 0, NULL, 0, arizona_out_ev,
923 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 928 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
929 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
924SND_SOC_DAPM_PGA_E("OUT5L", ARIZONA_OUTPUT_ENABLES_1, 930SND_SOC_DAPM_PGA_E("OUT5L", ARIZONA_OUTPUT_ENABLES_1,
925 ARIZONA_OUT5L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 931 ARIZONA_OUT5L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev,
926 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 932 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c
index 574579b98872..c81a9eab3e3e 100644
--- a/sound/soc/codecs/wm8350.c
+++ b/sound/soc/codecs/wm8350.c
@@ -259,7 +259,7 @@ static void wm8350_pga_work(struct work_struct *work)
259static int pga_event(struct snd_soc_dapm_widget *w, 259static int pga_event(struct snd_soc_dapm_widget *w,
260 struct snd_kcontrol *kcontrol, int event) 260 struct snd_kcontrol *kcontrol, int event)
261{ 261{
262 struct snd_soc_codec *codec = w->codec; 262 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
263 struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec); 263 struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec);
264 struct wm8350_output *out; 264 struct wm8350_output *out;
265 265
diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c
index 8ee446987aa9..b0d84e552fca 100644
--- a/sound/soc/codecs/wm8400.c
+++ b/sound/soc/codecs/wm8400.c
@@ -324,6 +324,7 @@ SOC_SINGLE("RIN34 Mute Switch", WM8400_RIGHT_LINE_INPUT_3_4_VOLUME,
324static int outmixer_event (struct snd_soc_dapm_widget *w, 324static int outmixer_event (struct snd_soc_dapm_widget *w,
325 struct snd_kcontrol * kcontrol, int event) 325 struct snd_kcontrol * kcontrol, int event)
326{ 326{
327 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
327 struct soc_mixer_control *mc = 328 struct soc_mixer_control *mc =
328 (struct soc_mixer_control *)kcontrol->private_value; 329 (struct soc_mixer_control *)kcontrol->private_value;
329 u32 reg_shift = mc->shift; 330 u32 reg_shift = mc->shift;
@@ -332,7 +333,7 @@ static int outmixer_event (struct snd_soc_dapm_widget *w,
332 333
333 switch (reg_shift) { 334 switch (reg_shift) {
334 case WM8400_SPEAKER_MIXER | (WM8400_LDSPK << 8) : 335 case WM8400_SPEAKER_MIXER | (WM8400_LDSPK << 8) :
335 reg = snd_soc_read(w->codec, WM8400_OUTPUT_MIXER1); 336 reg = snd_soc_read(codec, WM8400_OUTPUT_MIXER1);
336 if (reg & WM8400_LDLO) { 337 if (reg & WM8400_LDLO) {
337 printk(KERN_WARNING 338 printk(KERN_WARNING
338 "Cannot set as Output Mixer 1 LDLO Set\n"); 339 "Cannot set as Output Mixer 1 LDLO Set\n");
@@ -340,7 +341,7 @@ static int outmixer_event (struct snd_soc_dapm_widget *w,
340 } 341 }
341 break; 342 break;
342 case WM8400_SPEAKER_MIXER | (WM8400_RDSPK << 8): 343 case WM8400_SPEAKER_MIXER | (WM8400_RDSPK << 8):
343 reg = snd_soc_read(w->codec, WM8400_OUTPUT_MIXER2); 344 reg = snd_soc_read(codec, WM8400_OUTPUT_MIXER2);
344 if (reg & WM8400_RDRO) { 345 if (reg & WM8400_RDRO) {
345 printk(KERN_WARNING 346 printk(KERN_WARNING
346 "Cannot set as Output Mixer 2 RDRO Set\n"); 347 "Cannot set as Output Mixer 2 RDRO Set\n");
@@ -348,7 +349,7 @@ static int outmixer_event (struct snd_soc_dapm_widget *w,
348 } 349 }
349 break; 350 break;
350 case WM8400_OUTPUT_MIXER1 | (WM8400_LDLO << 8): 351 case WM8400_OUTPUT_MIXER1 | (WM8400_LDLO << 8):
351 reg = snd_soc_read(w->codec, WM8400_SPEAKER_MIXER); 352 reg = snd_soc_read(codec, WM8400_SPEAKER_MIXER);
352 if (reg & WM8400_LDSPK) { 353 if (reg & WM8400_LDSPK) {
353 printk(KERN_WARNING 354 printk(KERN_WARNING
354 "Cannot set as Speaker Mixer LDSPK Set\n"); 355 "Cannot set as Speaker Mixer LDSPK Set\n");
@@ -356,7 +357,7 @@ static int outmixer_event (struct snd_soc_dapm_widget *w,
356 } 357 }
357 break; 358 break;
358 case WM8400_OUTPUT_MIXER2 | (WM8400_RDRO << 8): 359 case WM8400_OUTPUT_MIXER2 | (WM8400_RDRO << 8):
359 reg = snd_soc_read(w->codec, WM8400_SPEAKER_MIXER); 360 reg = snd_soc_read(codec, WM8400_SPEAKER_MIXER);
360 if (reg & WM8400_RDSPK) { 361 if (reg & WM8400_RDSPK) {
361 printk(KERN_WARNING 362 printk(KERN_WARNING
362 "Cannot set as Speaker Mixer RDSPK Set\n"); 363 "Cannot set as Speaker Mixer RDSPK Set\n");
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index b9211b42f6e9..098c143f44d6 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -217,7 +217,8 @@ SND_SOC_DAPM_INPUT("LLINEIN"),
217static int wm8731_check_osc(struct snd_soc_dapm_widget *source, 217static int wm8731_check_osc(struct snd_soc_dapm_widget *source,
218 struct snd_soc_dapm_widget *sink) 218 struct snd_soc_dapm_widget *sink)
219{ 219{
220 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(source->codec); 220 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
221 struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
221 222
222 return wm8731->sysclk_type == WM8731_SYSCLK_XTAL; 223 return wm8731->sysclk_type == WM8731_SYSCLK_XTAL;
223} 224}
@@ -717,6 +718,8 @@ static int wm8731_i2c_probe(struct i2c_client *i2c,
717 if (wm8731 == NULL) 718 if (wm8731 == NULL)
718 return -ENOMEM; 719 return -ENOMEM;
719 720
721 mutex_init(&wm8731->lock);
722
720 wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap); 723 wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap);
721 if (IS_ERR(wm8731->regmap)) { 724 if (IS_ERR(wm8731->regmap)) {
722 ret = PTR_ERR(wm8731->regmap); 725 ret = PTR_ERR(wm8731->regmap);
diff --git a/sound/soc/codecs/wm8770.c b/sound/soc/codecs/wm8770.c
index 180e7a098726..53e977da2f86 100644
--- a/sound/soc/codecs/wm8770.c
+++ b/sound/soc/codecs/wm8770.c
@@ -308,9 +308,7 @@ static const struct snd_soc_dapm_route wm8770_intercon[] = {
308static int vout12supply_event(struct snd_soc_dapm_widget *w, 308static int vout12supply_event(struct snd_soc_dapm_widget *w,
309 struct snd_kcontrol *kcontrol, int event) 309 struct snd_kcontrol *kcontrol, int event)
310{ 310{
311 struct snd_soc_codec *codec; 311 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
312
313 codec = w->codec;
314 312
315 switch (event) { 313 switch (event) {
316 case SND_SOC_DAPM_PRE_PMU: 314 case SND_SOC_DAPM_PRE_PMU:
@@ -327,9 +325,7 @@ static int vout12supply_event(struct snd_soc_dapm_widget *w,
327static int vout34supply_event(struct snd_soc_dapm_widget *w, 325static int vout34supply_event(struct snd_soc_dapm_widget *w,
328 struct snd_kcontrol *kcontrol, int event) 326 struct snd_kcontrol *kcontrol, int event)
329{ 327{
330 struct snd_soc_codec *codec; 328 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
331
332 codec = w->codec;
333 329
334 switch (event) { 330 switch (event) {
335 case SND_SOC_DAPM_PRE_PMU: 331 case SND_SOC_DAPM_PRE_PMU:
diff --git a/sound/soc/codecs/wm8804.c b/sound/soc/codecs/wm8804.c
index 1315f7642503..b2b0e68f707e 100644
--- a/sound/soc/codecs/wm8804.c
+++ b/sound/soc/codecs/wm8804.c
@@ -648,7 +648,7 @@ static struct snd_soc_dai_driver wm8804_dai = {
648 .symmetric_rates = 1 648 .symmetric_rates = 1
649}; 649};
650 650
651static struct snd_soc_codec_driver soc_codec_dev_wm8804 = { 651static const struct snd_soc_codec_driver soc_codec_dev_wm8804 = {
652 .probe = wm8804_probe, 652 .probe = wm8804_probe,
653 .remove = wm8804_remove, 653 .remove = wm8804_remove,
654 .set_bias_level = wm8804_set_bias_level, 654 .set_bias_level = wm8804_set_bias_level,
@@ -664,7 +664,7 @@ static const struct of_device_id wm8804_of_match[] = {
664}; 664};
665MODULE_DEVICE_TABLE(of, wm8804_of_match); 665MODULE_DEVICE_TABLE(of, wm8804_of_match);
666 666
667static struct regmap_config wm8804_regmap_config = { 667static const struct regmap_config wm8804_regmap_config = {
668 .reg_bits = 8, 668 .reg_bits = 8,
669 .val_bits = 8, 669 .val_bits = 8,
670 670
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
index 3a0d4b7d692f..2eb986c19b88 100644
--- a/sound/soc/codecs/wm8900.c
+++ b/sound/soc/codecs/wm8900.c
@@ -224,7 +224,7 @@ static void wm8900_reset(struct snd_soc_codec *codec)
224static int wm8900_hp_event(struct snd_soc_dapm_widget *w, 224static int wm8900_hp_event(struct snd_soc_dapm_widget *w,
225 struct snd_kcontrol *kcontrol, int event) 225 struct snd_kcontrol *kcontrol, int event)
226{ 226{
227 struct snd_soc_codec *codec = w->codec; 227 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
228 u16 hpctl1 = snd_soc_read(codec, WM8900_REG_HPCTL1); 228 u16 hpctl1 = snd_soc_read(codec, WM8900_REG_HPCTL1);
229 229
230 switch (event) { 230 switch (event) {
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c
index cc6b0ef98a34..dde462c082be 100644
--- a/sound/soc/codecs/wm8903.c
+++ b/sound/soc/codecs/wm8903.c
@@ -260,7 +260,7 @@ static int wm8903_cp_event(struct snd_soc_dapm_widget *w,
260static int wm8903_dcs_event(struct snd_soc_dapm_widget *w, 260static int wm8903_dcs_event(struct snd_soc_dapm_widget *w,
261 struct snd_kcontrol *kcontrol, int event) 261 struct snd_kcontrol *kcontrol, int event)
262{ 262{
263 struct snd_soc_codec *codec = w->codec; 263 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
264 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec); 264 struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
265 265
266 switch (event) { 266 switch (event) {
diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c
index 75b87c5c0f04..d3b3f57668cc 100644
--- a/sound/soc/codecs/wm8904.c
+++ b/sound/soc/codecs/wm8904.c
@@ -673,7 +673,7 @@ static int cp_event(struct snd_soc_dapm_widget *w,
673static int sysclk_event(struct snd_soc_dapm_widget *w, 673static int sysclk_event(struct snd_soc_dapm_widget *w,
674 struct snd_kcontrol *kcontrol, int event) 674 struct snd_kcontrol *kcontrol, int event)
675{ 675{
676 struct snd_soc_codec *codec = w->codec; 676 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
677 struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec); 677 struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
678 678
679 switch (event) { 679 switch (event) {
@@ -711,7 +711,7 @@ static int sysclk_event(struct snd_soc_dapm_widget *w,
711static int out_pga_event(struct snd_soc_dapm_widget *w, 711static int out_pga_event(struct snd_soc_dapm_widget *w,
712 struct snd_kcontrol *kcontrol, int event) 712 struct snd_kcontrol *kcontrol, int event)
713{ 713{
714 struct snd_soc_codec *codec = w->codec; 714 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
715 struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec); 715 struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
716 int reg, val; 716 int reg, val;
717 int dcs_mask; 717 int dcs_mask;
@@ -2105,6 +2105,24 @@ static const struct regmap_config wm8904_regmap = {
2105 .num_reg_defaults = ARRAY_SIZE(wm8904_reg_defaults), 2105 .num_reg_defaults = ARRAY_SIZE(wm8904_reg_defaults),
2106}; 2106};
2107 2107
2108#ifdef CONFIG_OF
2109static enum wm8904_type wm8904_data = WM8904;
2110static enum wm8904_type wm8912_data = WM8912;
2111
2112static const struct of_device_id wm8904_of_match[] = {
2113 {
2114 .compatible = "wlf,wm8904",
2115 .data = &wm8904_data,
2116 }, {
2117 .compatible = "wlf,wm8912",
2118 .data = &wm8912_data,
2119 }, {
2120 /* sentinel */
2121 }
2122};
2123MODULE_DEVICE_TABLE(of, wm8904_of_match);
2124#endif
2125
2108static int wm8904_i2c_probe(struct i2c_client *i2c, 2126static int wm8904_i2c_probe(struct i2c_client *i2c,
2109 const struct i2c_device_id *id) 2127 const struct i2c_device_id *id)
2110{ 2128{
@@ -2132,7 +2150,17 @@ static int wm8904_i2c_probe(struct i2c_client *i2c,
2132 return ret; 2150 return ret;
2133 } 2151 }
2134 2152
2135 wm8904->devtype = id->driver_data; 2153 if (i2c->dev.of_node) {
2154 const struct of_device_id *match;
2155
2156 match = of_match_node(wm8904_of_match, i2c->dev.of_node);
2157 if (match == NULL)
2158 return -EINVAL;
2159 wm8904->devtype = *((enum wm8904_type *)match->data);
2160 } else {
2161 wm8904->devtype = id->driver_data;
2162 }
2163
2136 i2c_set_clientdata(i2c, wm8904); 2164 i2c_set_clientdata(i2c, wm8904);
2137 wm8904->pdata = i2c->dev.platform_data; 2165 wm8904->pdata = i2c->dev.platform_data;
2138 2166
@@ -2266,6 +2294,7 @@ static struct i2c_driver wm8904_i2c_driver = {
2266 .driver = { 2294 .driver = {
2267 .name = "wm8904", 2295 .name = "wm8904",
2268 .owner = THIS_MODULE, 2296 .owner = THIS_MODULE,
2297 .of_match_table = of_match_ptr(wm8904_of_match),
2269 }, 2298 },
2270 .probe = wm8904_i2c_probe, 2299 .probe = wm8904_i2c_probe,
2271 .remove = wm8904_i2c_remove, 2300 .remove = wm8904_i2c_remove,
diff --git a/sound/soc/codecs/wm8955.c b/sound/soc/codecs/wm8955.c
index 1173f7fef5a7..1ab2d462afad 100644
--- a/sound/soc/codecs/wm8955.c
+++ b/sound/soc/codecs/wm8955.c
@@ -333,7 +333,7 @@ static int wm8955_configure_clocking(struct snd_soc_codec *codec)
333static int wm8955_sysclk(struct snd_soc_dapm_widget *w, 333static int wm8955_sysclk(struct snd_soc_dapm_widget *w,
334 struct snd_kcontrol *kcontrol, int event) 334 struct snd_kcontrol *kcontrol, int event)
335{ 335{
336 struct snd_soc_codec *codec = w->codec; 336 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
337 int ret = 0; 337 int ret = 0;
338 338
339 /* Always disable the clocks - if we're doing reconfiguration this 339 /* Always disable the clocks - if we're doing reconfiguration this
diff --git a/sound/soc/codecs/wm8958-dsp2.c b/sound/soc/codecs/wm8958-dsp2.c
index 3cbc82b33292..c799cca5abeb 100644
--- a/sound/soc/codecs/wm8958-dsp2.c
+++ b/sound/soc/codecs/wm8958-dsp2.c
@@ -418,7 +418,7 @@ static void wm8958_dsp_apply(struct snd_soc_codec *codec, int path, int start)
418int wm8958_aif_ev(struct snd_soc_dapm_widget *w, 418int wm8958_aif_ev(struct snd_soc_dapm_widget *w,
419 struct snd_kcontrol *kcontrol, int event) 419 struct snd_kcontrol *kcontrol, int event)
420{ 420{
421 struct snd_soc_codec *codec = w->codec; 421 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
422 int i; 422 int i;
423 423
424 switch (event) { 424 switch (event) {
diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c
index a96eb497a379..cf8fecf97f2c 100644
--- a/sound/soc/codecs/wm8960.c
+++ b/sound/soc/codecs/wm8960.c
@@ -15,6 +15,7 @@
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/clk.h>
18#include <linux/i2c.h> 19#include <linux/i2c.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
20#include <sound/core.h> 21#include <sound/core.h>
@@ -117,6 +118,7 @@ static bool wm8960_volatile(struct device *dev, unsigned int reg)
117} 118}
118 119
119struct wm8960_priv { 120struct wm8960_priv {
121 struct clk *mclk;
120 struct regmap *regmap; 122 struct regmap *regmap;
121 int (*set_bias_level)(struct snd_soc_codec *, 123 int (*set_bias_level)(struct snd_soc_codec *,
122 enum snd_soc_bias_level level); 124 enum snd_soc_bias_level level);
@@ -618,14 +620,38 @@ static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
618 enum snd_soc_bias_level level) 620 enum snd_soc_bias_level level)
619{ 621{
620 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 622 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
623 int ret;
621 624
622 switch (level) { 625 switch (level) {
623 case SND_SOC_BIAS_ON: 626 case SND_SOC_BIAS_ON:
624 break; 627 break;
625 628
626 case SND_SOC_BIAS_PREPARE: 629 case SND_SOC_BIAS_PREPARE:
627 /* Set VMID to 2x50k */ 630 switch (codec->dapm.bias_level) {
628 snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x80); 631 case SND_SOC_BIAS_STANDBY:
632 if (!IS_ERR(wm8960->mclk)) {
633 ret = clk_prepare_enable(wm8960->mclk);
634 if (ret) {
635 dev_err(codec->dev,
636 "Failed to enable MCLK: %d\n",
637 ret);
638 return ret;
639 }
640 }
641
642 /* Set VMID to 2x50k */
643 snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x80);
644 break;
645
646 case SND_SOC_BIAS_ON:
647 if (!IS_ERR(wm8960->mclk))
648 clk_disable_unprepare(wm8960->mclk);
649 break;
650
651 default:
652 break;
653 }
654
629 break; 655 break;
630 656
631 case SND_SOC_BIAS_STANDBY: 657 case SND_SOC_BIAS_STANDBY:
@@ -674,7 +700,7 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
674 enum snd_soc_bias_level level) 700 enum snd_soc_bias_level level)
675{ 701{
676 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); 702 struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
677 int reg; 703 int reg, ret;
678 704
679 switch (level) { 705 switch (level) {
680 case SND_SOC_BIAS_ON: 706 case SND_SOC_BIAS_ON:
@@ -715,9 +741,22 @@ static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
715 WM8960_VREF, WM8960_VREF); 741 WM8960_VREF, WM8960_VREF);
716 742
717 msleep(100); 743 msleep(100);
744
745 if (!IS_ERR(wm8960->mclk)) {
746 ret = clk_prepare_enable(wm8960->mclk);
747 if (ret) {
748 dev_err(codec->dev,
749 "Failed to enable MCLK: %d\n",
750 ret);
751 return ret;
752 }
753 }
718 break; 754 break;
719 755
720 case SND_SOC_BIAS_ON: 756 case SND_SOC_BIAS_ON:
757 if (!IS_ERR(wm8960->mclk))
758 clk_disable_unprepare(wm8960->mclk);
759
721 /* Enable anti-pop mode */ 760 /* Enable anti-pop mode */
722 snd_soc_update_bits(codec, WM8960_APOP1, 761 snd_soc_update_bits(codec, WM8960_APOP1,
723 WM8960_POBCTRL | WM8960_SOFT_ST | 762 WM8960_POBCTRL | WM8960_SOFT_ST |
@@ -1002,6 +1041,12 @@ static int wm8960_i2c_probe(struct i2c_client *i2c,
1002 if (wm8960 == NULL) 1041 if (wm8960 == NULL)
1003 return -ENOMEM; 1042 return -ENOMEM;
1004 1043
1044 wm8960->mclk = devm_clk_get(&i2c->dev, "mclk");
1045 if (IS_ERR(wm8960->mclk)) {
1046 if (PTR_ERR(wm8960->mclk) == -EPROBE_DEFER)
1047 return -EPROBE_DEFER;
1048 }
1049
1005 wm8960->regmap = devm_regmap_init_i2c(i2c, &wm8960_regmap); 1050 wm8960->regmap = devm_regmap_init_i2c(i2c, &wm8960_regmap);
1006 if (IS_ERR(wm8960->regmap)) 1051 if (IS_ERR(wm8960->regmap))
1007 return PTR_ERR(wm8960->regmap); 1052 return PTR_ERR(wm8960->regmap);
diff --git a/sound/soc/codecs/wm8961.c b/sound/soc/codecs/wm8961.c
index eeffd05384b4..95e2c1bfc809 100644
--- a/sound/soc/codecs/wm8961.c
+++ b/sound/soc/codecs/wm8961.c
@@ -194,7 +194,7 @@ static bool wm8961_readable(struct device *dev, unsigned int reg)
194static int wm8961_hp_event(struct snd_soc_dapm_widget *w, 194static int wm8961_hp_event(struct snd_soc_dapm_widget *w,
195 struct snd_kcontrol *kcontrol, int event) 195 struct snd_kcontrol *kcontrol, int event)
196{ 196{
197 struct snd_soc_codec *codec = w->codec; 197 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
198 u16 hp_reg = snd_soc_read(codec, WM8961_ANALOGUE_HP_0); 198 u16 hp_reg = snd_soc_read(codec, WM8961_ANALOGUE_HP_0);
199 u16 cp_reg = snd_soc_read(codec, WM8961_CHARGE_PUMP_1); 199 u16 cp_reg = snd_soc_read(codec, WM8961_CHARGE_PUMP_1);
200 u16 pwr_reg = snd_soc_read(codec, WM8961_PWR_MGMT_2); 200 u16 pwr_reg = snd_soc_read(codec, WM8961_PWR_MGMT_2);
@@ -286,7 +286,7 @@ static int wm8961_hp_event(struct snd_soc_dapm_widget *w,
286static int wm8961_spk_event(struct snd_soc_dapm_widget *w, 286static int wm8961_spk_event(struct snd_soc_dapm_widget *w,
287 struct snd_kcontrol *kcontrol, int event) 287 struct snd_kcontrol *kcontrol, int event)
288{ 288{
289 struct snd_soc_codec *codec = w->codec; 289 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
290 u16 pwr_reg = snd_soc_read(codec, WM8961_PWR_MGMT_2); 290 u16 pwr_reg = snd_soc_read(codec, WM8961_PWR_MGMT_2);
291 u16 spk_reg = snd_soc_read(codec, WM8961_CLASS_D_CONTROL_1); 291 u16 spk_reg = snd_soc_read(codec, WM8961_CLASS_D_CONTROL_1);
292 292
diff --git a/sound/soc/codecs/wm8962.c b/sound/soc/codecs/wm8962.c
index d32d554f5b34..118b0034ba23 100644
--- a/sound/soc/codecs/wm8962.c
+++ b/sound/soc/codecs/wm8962.c
@@ -1866,7 +1866,7 @@ static int cp_event(struct snd_soc_dapm_widget *w,
1866static int hp_event(struct snd_soc_dapm_widget *w, 1866static int hp_event(struct snd_soc_dapm_widget *w,
1867 struct snd_kcontrol *kcontrol, int event) 1867 struct snd_kcontrol *kcontrol, int event)
1868{ 1868{
1869 struct snd_soc_codec *codec = w->codec; 1869 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1870 int timeout; 1870 int timeout;
1871 int reg; 1871 int reg;
1872 int expected = (WM8962_DCS_STARTUP_DONE_HP1L | 1872 int expected = (WM8962_DCS_STARTUP_DONE_HP1L |
@@ -1960,7 +1960,7 @@ static int hp_event(struct snd_soc_dapm_widget *w,
1960static int out_pga_event(struct snd_soc_dapm_widget *w, 1960static int out_pga_event(struct snd_soc_dapm_widget *w,
1961 struct snd_kcontrol *kcontrol, int event) 1961 struct snd_kcontrol *kcontrol, int event)
1962{ 1962{
1963 struct snd_soc_codec *codec = w->codec; 1963 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1964 int reg; 1964 int reg;
1965 1965
1966 switch (w->shift) { 1966 switch (w->shift) {
@@ -1993,7 +1993,7 @@ static int out_pga_event(struct snd_soc_dapm_widget *w,
1993static int dsp2_event(struct snd_soc_dapm_widget *w, 1993static int dsp2_event(struct snd_soc_dapm_widget *w,
1994 struct snd_kcontrol *kcontrol, int event) 1994 struct snd_kcontrol *kcontrol, int event)
1995{ 1995{
1996 struct snd_soc_codec *codec = w->codec; 1996 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1997 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec); 1997 struct wm8962_priv *wm8962 = snd_soc_codec_get_drvdata(codec);
1998 1998
1999 switch (event) { 1999 switch (event) {
diff --git a/sound/soc/codecs/wm8988.c b/sound/soc/codecs/wm8988.c
index e418199155a8..24968aa8618a 100644
--- a/sound/soc/codecs/wm8988.c
+++ b/sound/soc/codecs/wm8988.c
@@ -244,7 +244,7 @@ SOC_DOUBLE_R_TLV("Output 2 Playback Volume", WM8988_LOUT2V, WM8988_ROUT2V,
244static int wm8988_lrc_control(struct snd_soc_dapm_widget *w, 244static int wm8988_lrc_control(struct snd_soc_dapm_widget *w,
245 struct snd_kcontrol *kcontrol, int event) 245 struct snd_kcontrol *kcontrol, int event)
246{ 246{
247 struct snd_soc_codec *codec = w->codec; 247 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
248 u16 adctl2 = snd_soc_read(codec, WM8988_ADCTL2); 248 u16 adctl2 = snd_soc_read(codec, WM8988_ADCTL2);
249 249
250 /* Use the DAC to gate LRC if active, otherwise use ADC */ 250 /* Use the DAC to gate LRC if active, otherwise use ADC */
@@ -813,7 +813,7 @@ static int wm8988_probe(struct snd_soc_codec *codec)
813 return 0; 813 return 0;
814} 814}
815 815
816static struct snd_soc_codec_driver soc_codec_dev_wm8988 = { 816static const struct snd_soc_codec_driver soc_codec_dev_wm8988 = {
817 .probe = wm8988_probe, 817 .probe = wm8988_probe,
818 .set_bias_level = wm8988_set_bias_level, 818 .set_bias_level = wm8988_set_bias_level,
819 .suspend_bias_off = true, 819 .suspend_bias_off = true,
@@ -826,7 +826,7 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8988 = {
826 .num_dapm_routes = ARRAY_SIZE(wm8988_dapm_routes), 826 .num_dapm_routes = ARRAY_SIZE(wm8988_dapm_routes),
827}; 827};
828 828
829static struct regmap_config wm8988_regmap = { 829static const struct regmap_config wm8988_regmap = {
830 .reg_bits = 7, 830 .reg_bits = 7,
831 .val_bits = 9, 831 .val_bits = 9,
832 832
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c
index 8a584229310a..c93bffcb3cfb 100644
--- a/sound/soc/codecs/wm8990.c
+++ b/sound/soc/codecs/wm8990.c
@@ -374,13 +374,14 @@ SOC_SINGLE("RIN34 Mute Switch", WM8990_RIGHT_LINE_INPUT_3_4_VOLUME,
374static int outmixer_event(struct snd_soc_dapm_widget *w, 374static int outmixer_event(struct snd_soc_dapm_widget *w,
375 struct snd_kcontrol *kcontrol, int event) 375 struct snd_kcontrol *kcontrol, int event)
376{ 376{
377 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
377 u32 reg_shift = kcontrol->private_value & 0xfff; 378 u32 reg_shift = kcontrol->private_value & 0xfff;
378 int ret = 0; 379 int ret = 0;
379 u16 reg; 380 u16 reg;
380 381
381 switch (reg_shift) { 382 switch (reg_shift) {
382 case WM8990_SPEAKER_MIXER | (WM8990_LDSPK_BIT << 8) : 383 case WM8990_SPEAKER_MIXER | (WM8990_LDSPK_BIT << 8) :
383 reg = snd_soc_read(w->codec, WM8990_OUTPUT_MIXER1); 384 reg = snd_soc_read(codec, WM8990_OUTPUT_MIXER1);
384 if (reg & WM8990_LDLO) { 385 if (reg & WM8990_LDLO) {
385 printk(KERN_WARNING 386 printk(KERN_WARNING
386 "Cannot set as Output Mixer 1 LDLO Set\n"); 387 "Cannot set as Output Mixer 1 LDLO Set\n");
@@ -388,7 +389,7 @@ static int outmixer_event(struct snd_soc_dapm_widget *w,
388 } 389 }
389 break; 390 break;
390 case WM8990_SPEAKER_MIXER | (WM8990_RDSPK_BIT << 8): 391 case WM8990_SPEAKER_MIXER | (WM8990_RDSPK_BIT << 8):
391 reg = snd_soc_read(w->codec, WM8990_OUTPUT_MIXER2); 392 reg = snd_soc_read(codec, WM8990_OUTPUT_MIXER2);
392 if (reg & WM8990_RDRO) { 393 if (reg & WM8990_RDRO) {
393 printk(KERN_WARNING 394 printk(KERN_WARNING
394 "Cannot set as Output Mixer 2 RDRO Set\n"); 395 "Cannot set as Output Mixer 2 RDRO Set\n");
@@ -396,7 +397,7 @@ static int outmixer_event(struct snd_soc_dapm_widget *w,
396 } 397 }
397 break; 398 break;
398 case WM8990_OUTPUT_MIXER1 | (WM8990_LDLO_BIT << 8): 399 case WM8990_OUTPUT_MIXER1 | (WM8990_LDLO_BIT << 8):
399 reg = snd_soc_read(w->codec, WM8990_SPEAKER_MIXER); 400 reg = snd_soc_read(codec, WM8990_SPEAKER_MIXER);
400 if (reg & WM8990_LDSPK) { 401 if (reg & WM8990_LDSPK) {
401 printk(KERN_WARNING 402 printk(KERN_WARNING
402 "Cannot set as Speaker Mixer LDSPK Set\n"); 403 "Cannot set as Speaker Mixer LDSPK Set\n");
@@ -404,7 +405,7 @@ static int outmixer_event(struct snd_soc_dapm_widget *w,
404 } 405 }
405 break; 406 break;
406 case WM8990_OUTPUT_MIXER2 | (WM8990_RDRO_BIT << 8): 407 case WM8990_OUTPUT_MIXER2 | (WM8990_RDRO_BIT << 8):
407 reg = snd_soc_read(w->codec, WM8990_SPEAKER_MIXER); 408 reg = snd_soc_read(codec, WM8990_SPEAKER_MIXER);
408 if (reg & WM8990_RDSPK) { 409 if (reg & WM8990_RDSPK) {
409 printk(KERN_WARNING 410 printk(KERN_WARNING
410 "Cannot set as Speaker Mixer RDSPK Set\n"); 411 "Cannot set as Speaker Mixer RDSPK Set\n");
diff --git a/sound/soc/codecs/wm8991.c b/sound/soc/codecs/wm8991.c
index b0ac2c3e31b9..49df0dc607e6 100644
--- a/sound/soc/codecs/wm8991.c
+++ b/sound/soc/codecs/wm8991.c
@@ -382,13 +382,14 @@ static const struct snd_kcontrol_new wm8991_snd_controls[] = {
382static int outmixer_event(struct snd_soc_dapm_widget *w, 382static int outmixer_event(struct snd_soc_dapm_widget *w,
383 struct snd_kcontrol *kcontrol, int event) 383 struct snd_kcontrol *kcontrol, int event)
384{ 384{
385 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
385 u32 reg_shift = kcontrol->private_value & 0xfff; 386 u32 reg_shift = kcontrol->private_value & 0xfff;
386 int ret = 0; 387 int ret = 0;
387 u16 reg; 388 u16 reg;
388 389
389 switch (reg_shift) { 390 switch (reg_shift) {
390 case WM8991_SPEAKER_MIXER | (WM8991_LDSPK_BIT << 8): 391 case WM8991_SPEAKER_MIXER | (WM8991_LDSPK_BIT << 8):
391 reg = snd_soc_read(w->codec, WM8991_OUTPUT_MIXER1); 392 reg = snd_soc_read(codec, WM8991_OUTPUT_MIXER1);
392 if (reg & WM8991_LDLO) { 393 if (reg & WM8991_LDLO) {
393 printk(KERN_WARNING 394 printk(KERN_WARNING
394 "Cannot set as Output Mixer 1 LDLO Set\n"); 395 "Cannot set as Output Mixer 1 LDLO Set\n");
@@ -397,7 +398,7 @@ static int outmixer_event(struct snd_soc_dapm_widget *w,
397 break; 398 break;
398 399
399 case WM8991_SPEAKER_MIXER | (WM8991_RDSPK_BIT << 8): 400 case WM8991_SPEAKER_MIXER | (WM8991_RDSPK_BIT << 8):
400 reg = snd_soc_read(w->codec, WM8991_OUTPUT_MIXER2); 401 reg = snd_soc_read(codec, WM8991_OUTPUT_MIXER2);
401 if (reg & WM8991_RDRO) { 402 if (reg & WM8991_RDRO) {
402 printk(KERN_WARNING 403 printk(KERN_WARNING
403 "Cannot set as Output Mixer 2 RDRO Set\n"); 404 "Cannot set as Output Mixer 2 RDRO Set\n");
@@ -406,7 +407,7 @@ static int outmixer_event(struct snd_soc_dapm_widget *w,
406 break; 407 break;
407 408
408 case WM8991_OUTPUT_MIXER1 | (WM8991_LDLO_BIT << 8): 409 case WM8991_OUTPUT_MIXER1 | (WM8991_LDLO_BIT << 8):
409 reg = snd_soc_read(w->codec, WM8991_SPEAKER_MIXER); 410 reg = snd_soc_read(codec, WM8991_SPEAKER_MIXER);
410 if (reg & WM8991_LDSPK) { 411 if (reg & WM8991_LDSPK) {
411 printk(KERN_WARNING 412 printk(KERN_WARNING
412 "Cannot set as Speaker Mixer LDSPK Set\n"); 413 "Cannot set as Speaker Mixer LDSPK Set\n");
@@ -415,7 +416,7 @@ static int outmixer_event(struct snd_soc_dapm_widget *w,
415 break; 416 break;
416 417
417 case WM8991_OUTPUT_MIXER2 | (WM8991_RDRO_BIT << 8): 418 case WM8991_OUTPUT_MIXER2 | (WM8991_RDRO_BIT << 8):
418 reg = snd_soc_read(w->codec, WM8991_SPEAKER_MIXER); 419 reg = snd_soc_read(codec, WM8991_SPEAKER_MIXER);
419 if (reg & WM8991_RDSPK) { 420 if (reg & WM8991_RDSPK) {
420 printk(KERN_WARNING 421 printk(KERN_WARNING
421 "Cannot set as Speaker Mixer RDSPK Set\n"); 422 "Cannot set as Speaker Mixer RDSPK Set\n");
diff --git a/sound/soc/codecs/wm8993.c b/sound/soc/codecs/wm8993.c
index 53c6fe359496..2e70a270eb28 100644
--- a/sound/soc/codecs/wm8993.c
+++ b/sound/soc/codecs/wm8993.c
@@ -810,7 +810,7 @@ SOC_SINGLE_TLV("EQ5 Volume", WM8993_EQ6, 0, 24, 0, eq_tlv),
810static int clk_sys_event(struct snd_soc_dapm_widget *w, 810static int clk_sys_event(struct snd_soc_dapm_widget *w,
811 struct snd_kcontrol *kcontrol, int event) 811 struct snd_kcontrol *kcontrol, int event)
812{ 812{
813 struct snd_soc_codec *codec = w->codec; 813 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
814 814
815 switch (event) { 815 switch (event) {
816 case SND_SOC_DAPM_PRE_PMU: 816 case SND_SOC_DAPM_PRE_PMU:
diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
index 1b97de2e4e67..4fbc7689339a 100644
--- a/sound/soc/codecs/wm8994.c
+++ b/sound/soc/codecs/wm8994.c
@@ -249,7 +249,8 @@ static int configure_clock(struct snd_soc_codec *codec)
249static int check_clk_sys(struct snd_soc_dapm_widget *source, 249static int check_clk_sys(struct snd_soc_dapm_widget *source,
250 struct snd_soc_dapm_widget *sink) 250 struct snd_soc_dapm_widget *sink)
251{ 251{
252 int reg = snd_soc_read(source->codec, WM8994_CLOCKING_1); 252 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
253 int reg = snd_soc_read(codec, WM8994_CLOCKING_1);
253 const char *clk; 254 const char *clk;
254 255
255 /* Check what we're currently using for CLK_SYS */ 256 /* Check what we're currently using for CLK_SYS */
@@ -806,7 +807,7 @@ static void active_dereference(struct snd_soc_codec *codec)
806static int clk_sys_event(struct snd_soc_dapm_widget *w, 807static int clk_sys_event(struct snd_soc_dapm_widget *w,
807 struct snd_kcontrol *kcontrol, int event) 808 struct snd_kcontrol *kcontrol, int event)
808{ 809{
809 struct snd_soc_codec *codec = w->codec; 810 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
810 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 811 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
811 812
812 switch (event) { 813 switch (event) {
@@ -981,7 +982,7 @@ static void vmid_dereference(struct snd_soc_codec *codec)
981static int vmid_event(struct snd_soc_dapm_widget *w, 982static int vmid_event(struct snd_soc_dapm_widget *w,
982 struct snd_kcontrol *kcontrol, int event) 983 struct snd_kcontrol *kcontrol, int event)
983{ 984{
984 struct snd_soc_codec *codec = w->codec; 985 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
985 986
986 switch (event) { 987 switch (event) {
987 case SND_SOC_DAPM_PRE_PMU: 988 case SND_SOC_DAPM_PRE_PMU:
@@ -1037,7 +1038,7 @@ static bool wm8994_check_class_w_digital(struct snd_soc_codec *codec)
1037static int aif1clk_ev(struct snd_soc_dapm_widget *w, 1038static int aif1clk_ev(struct snd_soc_dapm_widget *w,
1038 struct snd_kcontrol *kcontrol, int event) 1039 struct snd_kcontrol *kcontrol, int event)
1039{ 1040{
1040 struct snd_soc_codec *codec = w->codec; 1041 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1041 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 1042 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1042 struct wm8994 *control = wm8994->wm8994; 1043 struct wm8994 *control = wm8994->wm8994;
1043 int mask = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA; 1044 int mask = WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA;
@@ -1135,7 +1136,7 @@ static int aif1clk_ev(struct snd_soc_dapm_widget *w,
1135static int aif2clk_ev(struct snd_soc_dapm_widget *w, 1136static int aif2clk_ev(struct snd_soc_dapm_widget *w,
1136 struct snd_kcontrol *kcontrol, int event) 1137 struct snd_kcontrol *kcontrol, int event)
1137{ 1138{
1138 struct snd_soc_codec *codec = w->codec; 1139 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1139 int i; 1140 int i;
1140 int dac; 1141 int dac;
1141 int adc; 1142 int adc;
@@ -1220,7 +1221,7 @@ static int aif2clk_ev(struct snd_soc_dapm_widget *w,
1220static int aif1clk_late_ev(struct snd_soc_dapm_widget *w, 1221static int aif1clk_late_ev(struct snd_soc_dapm_widget *w,
1221 struct snd_kcontrol *kcontrol, int event) 1222 struct snd_kcontrol *kcontrol, int event)
1222{ 1223{
1223 struct snd_soc_codec *codec = w->codec; 1224 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1224 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 1225 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1225 1226
1226 switch (event) { 1227 switch (event) {
@@ -1238,7 +1239,7 @@ static int aif1clk_late_ev(struct snd_soc_dapm_widget *w,
1238static int aif2clk_late_ev(struct snd_soc_dapm_widget *w, 1239static int aif2clk_late_ev(struct snd_soc_dapm_widget *w,
1239 struct snd_kcontrol *kcontrol, int event) 1240 struct snd_kcontrol *kcontrol, int event)
1240{ 1241{
1241 struct snd_soc_codec *codec = w->codec; 1242 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1242 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 1243 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1243 1244
1244 switch (event) { 1245 switch (event) {
@@ -1256,7 +1257,7 @@ static int aif2clk_late_ev(struct snd_soc_dapm_widget *w,
1256static int late_enable_ev(struct snd_soc_dapm_widget *w, 1257static int late_enable_ev(struct snd_soc_dapm_widget *w,
1257 struct snd_kcontrol *kcontrol, int event) 1258 struct snd_kcontrol *kcontrol, int event)
1258{ 1259{
1259 struct snd_soc_codec *codec = w->codec; 1260 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1260 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 1261 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1261 1262
1262 switch (event) { 1263 switch (event) {
@@ -1289,7 +1290,7 @@ static int late_enable_ev(struct snd_soc_dapm_widget *w,
1289static int late_disable_ev(struct snd_soc_dapm_widget *w, 1290static int late_disable_ev(struct snd_soc_dapm_widget *w,
1290 struct snd_kcontrol *kcontrol, int event) 1291 struct snd_kcontrol *kcontrol, int event)
1291{ 1292{
1292 struct snd_soc_codec *codec = w->codec; 1293 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1293 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec); 1294 struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
1294 1295
1295 switch (event) { 1296 switch (event) {
@@ -1331,7 +1332,7 @@ static int micbias_ev(struct snd_soc_dapm_widget *w,
1331static int dac_ev(struct snd_soc_dapm_widget *w, 1332static int dac_ev(struct snd_soc_dapm_widget *w,
1332 struct snd_kcontrol *kcontrol, int event) 1333 struct snd_kcontrol *kcontrol, int event)
1333{ 1334{
1334 struct snd_soc_codec *codec = w->codec; 1335 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1335 unsigned int mask = 1 << w->shift; 1336 unsigned int mask = 1 << w->shift;
1336 1337
1337 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5, 1338 snd_soc_update_bits(codec, WM8994_POWER_MANAGEMENT_5,
@@ -1372,7 +1373,7 @@ SOC_DAPM_SINGLE("DAC1 Switch", WM8994_SPEAKER_MIXER, 0, 1, 0),
1372static int post_ev(struct snd_soc_dapm_widget *w, 1373static int post_ev(struct snd_soc_dapm_widget *w,
1373 struct snd_kcontrol *kcontrol, int event) 1374 struct snd_kcontrol *kcontrol, int event)
1374{ 1375{
1375 struct snd_soc_codec *codec = w->codec; 1376 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1376 dev_dbg(codec->dev, "SRC status: %x\n", 1377 dev_dbg(codec->dev, "SRC status: %x\n",
1377 snd_soc_read(codec, 1378 snd_soc_read(codec,
1378 WM8994_RATE_STATUS)); 1379 WM8994_RATE_STATUS));
diff --git a/sound/soc/codecs/wm8995.c b/sound/soc/codecs/wm8995.c
index c280f0a3a424..66103c2b012e 100644
--- a/sound/soc/codecs/wm8995.c
+++ b/sound/soc/codecs/wm8995.c
@@ -44,7 +44,7 @@ static const char *wm8995_supply_names[WM8995_NUM_SUPPLIES] = {
44 "MICVDD" 44 "MICVDD"
45}; 45};
46 46
47static struct reg_default wm8995_reg_defaults[] = { 47static const struct reg_default wm8995_reg_defaults[] = {
48 { 0, 0x8995 }, 48 { 0, 0x8995 },
49 { 5, 0x0100 }, 49 { 5, 0x0100 },
50 { 16, 0x000b }, 50 { 16, 0x000b },
@@ -534,10 +534,11 @@ static void wm8995_update_class_w(struct snd_soc_codec *codec)
534static int check_clk_sys(struct snd_soc_dapm_widget *source, 534static int check_clk_sys(struct snd_soc_dapm_widget *source,
535 struct snd_soc_dapm_widget *sink) 535 struct snd_soc_dapm_widget *sink)
536{ 536{
537 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
537 unsigned int reg; 538 unsigned int reg;
538 const char *clk; 539 const char *clk;
539 540
540 reg = snd_soc_read(source->codec, WM8995_CLOCKING_1); 541 reg = snd_soc_read(codec, WM8995_CLOCKING_1);
541 /* Check what we're currently using for CLK_SYS */ 542 /* Check what we're currently using for CLK_SYS */
542 if (reg & WM8995_SYSCLK_SRC) 543 if (reg & WM8995_SYSCLK_SRC)
543 clk = "AIF2CLK"; 544 clk = "AIF2CLK";
@@ -560,9 +561,7 @@ static int wm8995_put_class_w(struct snd_kcontrol *kcontrol,
560static int hp_supply_event(struct snd_soc_dapm_widget *w, 561static int hp_supply_event(struct snd_soc_dapm_widget *w,
561 struct snd_kcontrol *kcontrol, int event) 562 struct snd_kcontrol *kcontrol, int event)
562{ 563{
563 struct snd_soc_codec *codec; 564 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
564
565 codec = w->codec;
566 565
567 switch (event) { 566 switch (event) {
568 case SND_SOC_DAPM_PRE_PMU: 567 case SND_SOC_DAPM_PRE_PMU:
@@ -611,10 +610,9 @@ static void dc_servo_cmd(struct snd_soc_codec *codec,
611static int hp_event(struct snd_soc_dapm_widget *w, 610static int hp_event(struct snd_soc_dapm_widget *w,
612 struct snd_kcontrol *kcontrol, int event) 611 struct snd_kcontrol *kcontrol, int event)
613{ 612{
614 struct snd_soc_codec *codec; 613 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
615 unsigned int reg; 614 unsigned int reg;
616 615
617 codec = w->codec;
618 reg = snd_soc_read(codec, WM8995_ANALOGUE_HP_1); 616 reg = snd_soc_read(codec, WM8995_ANALOGUE_HP_1);
619 617
620 switch (event) { 618 switch (event) {
@@ -761,9 +759,7 @@ static int configure_clock(struct snd_soc_codec *codec)
761static int clk_sys_event(struct snd_soc_dapm_widget *w, 759static int clk_sys_event(struct snd_soc_dapm_widget *w,
762 struct snd_kcontrol *kcontrol, int event) 760 struct snd_kcontrol *kcontrol, int event)
763{ 761{
764 struct snd_soc_codec *codec; 762 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
765
766 codec = w->codec;
767 763
768 switch (event) { 764 switch (event) {
769 case SND_SOC_DAPM_PRE_PMU: 765 case SND_SOC_DAPM_PRE_PMU:
@@ -2190,7 +2186,7 @@ static struct snd_soc_dai_driver wm8995_dai[] = {
2190 } 2186 }
2191}; 2187};
2192 2188
2193static struct snd_soc_codec_driver soc_codec_dev_wm8995 = { 2189static const struct snd_soc_codec_driver soc_codec_dev_wm8995 = {
2194 .probe = wm8995_probe, 2190 .probe = wm8995_probe,
2195 .remove = wm8995_remove, 2191 .remove = wm8995_remove,
2196 .set_bias_level = wm8995_set_bias_level, 2192 .set_bias_level = wm8995_set_bias_level,
@@ -2204,7 +2200,7 @@ static struct snd_soc_codec_driver soc_codec_dev_wm8995 = {
2204 .num_dapm_routes = ARRAY_SIZE(wm8995_intercon), 2200 .num_dapm_routes = ARRAY_SIZE(wm8995_intercon),
2205}; 2201};
2206 2202
2207static struct regmap_config wm8995_regmap = { 2203static const struct regmap_config wm8995_regmap = {
2208 .reg_bits = 16, 2204 .reg_bits = 16,
2209 .val_bits = 16, 2205 .val_bits = 16,
2210 2206
diff --git a/sound/soc/codecs/wm8996.c b/sound/soc/codecs/wm8996.c
index b1dcc11c1b23..dc92d5e4e942 100644
--- a/sound/soc/codecs/wm8996.c
+++ b/sound/soc/codecs/wm8996.c
@@ -599,7 +599,7 @@ static void wm8996_bg_disable(struct snd_soc_codec *codec)
599static int bg_event(struct snd_soc_dapm_widget *w, 599static int bg_event(struct snd_soc_dapm_widget *w,
600 struct snd_kcontrol *kcontrol, int event) 600 struct snd_kcontrol *kcontrol, int event)
601{ 601{
602 struct snd_soc_codec *codec = w->codec; 602 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
603 int ret = 0; 603 int ret = 0;
604 604
605 switch (event) { 605 switch (event) {
@@ -634,7 +634,8 @@ static int cp_event(struct snd_soc_dapm_widget *w,
634static int rmv_short_event(struct snd_soc_dapm_widget *w, 634static int rmv_short_event(struct snd_soc_dapm_widget *w,
635 struct snd_kcontrol *kcontrol, int event) 635 struct snd_kcontrol *kcontrol, int event)
636{ 636{
637 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(w->codec); 637 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
638 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
638 639
639 /* Record which outputs we enabled */ 640 /* Record which outputs we enabled */
640 switch (event) { 641 switch (event) {
@@ -758,7 +759,8 @@ static void wm8996_seq_notifier(struct snd_soc_dapm_context *dapm,
758static int dcs_start(struct snd_soc_dapm_widget *w, 759static int dcs_start(struct snd_soc_dapm_widget *w,
759 struct snd_kcontrol *kcontrol, int event) 760 struct snd_kcontrol *kcontrol, int event)
760{ 761{
761 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(w->codec); 762 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
763 struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec);
762 764
763 switch (event) { 765 switch (event) {
764 case SND_SOC_DAPM_POST_PMU: 766 case SND_SOC_DAPM_POST_PMU:
diff --git a/sound/soc/codecs/wm8997.c b/sound/soc/codecs/wm8997.c
index 7e8bfe27566b..a4d11770630c 100644
--- a/sound/soc/codecs/wm8997.c
+++ b/sound/soc/codecs/wm8997.c
@@ -84,7 +84,7 @@ static const struct reg_default wm8997_sysclk_reva_patch[] = {
84static int wm8997_sysclk_ev(struct snd_soc_dapm_widget *w, 84static int wm8997_sysclk_ev(struct snd_soc_dapm_widget *w,
85 struct snd_kcontrol *kcontrol, int event) 85 struct snd_kcontrol *kcontrol, int event)
86{ 86{
87 struct snd_soc_codec *codec = w->codec; 87 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
88 struct arizona *arizona = dev_get_drvdata(codec->dev->parent); 88 struct arizona *arizona = dev_get_drvdata(codec->dev->parent);
89 struct regmap *regmap = arizona->regmap; 89 struct regmap *regmap = arizona->regmap;
90 const struct reg_default *patch = NULL; 90 const struct reg_default *patch = NULL;
@@ -610,13 +610,16 @@ SND_SOC_DAPM_MUX("AEC Loopback", ARIZONA_DAC_AEC_CONTROL_1,
610 610
611SND_SOC_DAPM_PGA_E("OUT1L", SND_SOC_NOPM, 611SND_SOC_DAPM_PGA_E("OUT1L", SND_SOC_NOPM,
612 ARIZONA_OUT1L_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev, 612 ARIZONA_OUT1L_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev,
613 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 613 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
614 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
614SND_SOC_DAPM_PGA_E("OUT1R", SND_SOC_NOPM, 615SND_SOC_DAPM_PGA_E("OUT1R", SND_SOC_NOPM,
615 ARIZONA_OUT1R_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev, 616 ARIZONA_OUT1R_ENA_SHIFT, 0, NULL, 0, arizona_hp_ev,
616 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 617 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
618 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
617SND_SOC_DAPM_PGA_E("OUT3L", ARIZONA_OUTPUT_ENABLES_1, 619SND_SOC_DAPM_PGA_E("OUT3L", ARIZONA_OUTPUT_ENABLES_1,
618 ARIZONA_OUT3L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 620 ARIZONA_OUT3L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev,
619 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 621 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD |
622 SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
620SND_SOC_DAPM_PGA_E("OUT5L", ARIZONA_OUTPUT_ENABLES_1, 623SND_SOC_DAPM_PGA_E("OUT5L", ARIZONA_OUTPUT_ENABLES_1,
621 ARIZONA_OUT5L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev, 624 ARIZONA_OUT5L_ENA_SHIFT, 0, NULL, 0, arizona_out_ev,
622 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU), 625 SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMU),
diff --git a/sound/soc/codecs/wm9081.c b/sound/soc/codecs/wm9081.c
index b1d946facd57..13a3f335ea5b 100644
--- a/sound/soc/codecs/wm9081.c
+++ b/sound/soc/codecs/wm9081.c
@@ -734,7 +734,7 @@ static int configure_clock(struct snd_soc_codec *codec)
734static int clk_sys_event(struct snd_soc_dapm_widget *w, 734static int clk_sys_event(struct snd_soc_dapm_widget *w,
735 struct snd_kcontrol *kcontrol, int event) 735 struct snd_kcontrol *kcontrol, int event)
736{ 736{
737 struct snd_soc_codec *codec = w->codec; 737 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
738 struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec); 738 struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec);
739 739
740 /* This should be done on init() for bypass paths */ 740 /* This should be done on init() for bypass paths */
diff --git a/sound/soc/codecs/wm9090.c b/sound/soc/codecs/wm9090.c
index 6ffe8dc4f3fa..60d243c904f5 100644
--- a/sound/soc/codecs/wm9090.c
+++ b/sound/soc/codecs/wm9090.c
@@ -254,7 +254,7 @@ SOC_SINGLE_TLV("MIXOUTR IN2B Volume", WM9090_OUTPUT_MIXER4, 0, 3, 1,
254static int hp_ev(struct snd_soc_dapm_widget *w, 254static int hp_ev(struct snd_soc_dapm_widget *w,
255 struct snd_kcontrol *kcontrol, int event) 255 struct snd_kcontrol *kcontrol, int event)
256{ 256{
257 struct snd_soc_codec *codec = w->codec; 257 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
258 unsigned int reg = snd_soc_read(codec, WM9090_ANALOGUE_HP_0); 258 unsigned int reg = snd_soc_read(codec, WM9090_ANALOGUE_HP_0);
259 259
260 switch (event) { 260 switch (event) {
diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c
index 3eddb18fefd1..5cc457ef8894 100644
--- a/sound/soc/codecs/wm9705.c
+++ b/sound/soc/codecs/wm9705.c
@@ -344,23 +344,27 @@ static int wm9705_soc_probe(struct snd_soc_codec *codec)
344 struct snd_ac97 *ac97; 344 struct snd_ac97 *ac97;
345 int ret = 0; 345 int ret = 0;
346 346
347 ac97 = snd_soc_new_ac97_codec(codec); 347 ac97 = snd_soc_alloc_ac97_codec(codec);
348 if (IS_ERR(ac97)) { 348 if (IS_ERR(ac97)) {
349 ret = PTR_ERR(ac97); 349 ret = PTR_ERR(ac97);
350 dev_err(codec->dev, "Failed to register AC97 codec\n"); 350 dev_err(codec->dev, "Failed to register AC97 codec\n");
351 return ret; 351 return ret;
352 } 352 }
353 353
354 snd_soc_codec_set_drvdata(codec, ac97);
355
356 ret = wm9705_reset(codec); 354 ret = wm9705_reset(codec);
357 if (ret) 355 if (ret)
358 goto reset_err; 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);
359 363
360 return 0; 364 return 0;
361 365
362reset_err: 366err_put_device:
363 snd_soc_free_ac97_codec(ac97); 367 put_device(&ac97->dev);
364 return ret; 368 return ret;
365} 369}
366 370
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
index e04643d2bb24..9517571e820d 100644
--- a/sound/soc/codecs/wm9712.c
+++ b/sound/soc/codecs/wm9712.c
@@ -666,7 +666,7 @@ static int wm9712_soc_probe(struct snd_soc_codec *codec)
666 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); 666 struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec);
667 int ret = 0; 667 int ret = 0;
668 668
669 wm9712->ac97 = snd_soc_new_ac97_codec(codec); 669 wm9712->ac97 = snd_soc_alloc_ac97_codec(codec);
670 if (IS_ERR(wm9712->ac97)) { 670 if (IS_ERR(wm9712->ac97)) {
671 ret = PTR_ERR(wm9712->ac97); 671 ret = PTR_ERR(wm9712->ac97);
672 dev_err(codec->dev, "Failed to register AC97 codec: %d\n", ret); 672 dev_err(codec->dev, "Failed to register AC97 codec: %d\n", ret);
@@ -675,15 +675,19 @@ static int wm9712_soc_probe(struct snd_soc_codec *codec)
675 675
676 ret = wm9712_reset(codec, 0); 676 ret = wm9712_reset(codec, 0);
677 if (ret < 0) 677 if (ret < 0)
678 goto reset_err; 678 goto err_put_device;
679
680 ret = device_add(&wm9712->ac97->dev);
681 if (ret)
682 goto err_put_device;
679 683
680 /* set alc mux to none */ 684 /* set alc mux to none */
681 ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000); 685 ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000);
682 686
683 return 0; 687 return 0;
684 688
685reset_err: 689err_put_device:
686 snd_soc_free_ac97_codec(wm9712->ac97); 690 put_device(&wm9712->ac97->dev);
687 return ret; 691 return ret;
688} 692}
689 693
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
index 71b9d5b0734d..68222917b396 100644
--- a/sound/soc/codecs/wm9713.c
+++ b/sound/soc/codecs/wm9713.c
@@ -217,7 +217,7 @@ SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
217static int wm9713_voice_shutdown(struct snd_soc_dapm_widget *w, 217static int wm9713_voice_shutdown(struct snd_soc_dapm_widget *w,
218 struct snd_kcontrol *kcontrol, int event) 218 struct snd_kcontrol *kcontrol, int event)
219{ 219{
220 struct snd_soc_codec *codec = w->codec; 220 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
221 u16 status, rate; 221 u16 status, rate;
222 222
223 if (WARN_ON(event != SND_SOC_DAPM_PRE_PMD)) 223 if (WARN_ON(event != SND_SOC_DAPM_PRE_PMD))
@@ -1225,7 +1225,7 @@ static int wm9713_soc_probe(struct snd_soc_codec *codec)
1225 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); 1225 struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
1226 int ret = 0, reg; 1226 int ret = 0, reg;
1227 1227
1228 wm9713->ac97 = snd_soc_new_ac97_codec(codec); 1228 wm9713->ac97 = snd_soc_alloc_ac97_codec(codec);
1229 if (IS_ERR(wm9713->ac97)) 1229 if (IS_ERR(wm9713->ac97))
1230 return PTR_ERR(wm9713->ac97); 1230 return PTR_ERR(wm9713->ac97);
1231 1231
@@ -1234,7 +1234,11 @@ static int wm9713_soc_probe(struct snd_soc_codec *codec)
1234 wm9713_reset(codec, 0); 1234 wm9713_reset(codec, 0);
1235 ret = wm9713_reset(codec, 1); 1235 ret = wm9713_reset(codec, 1);
1236 if (ret < 0) 1236 if (ret < 0)
1237 goto reset_err; 1237 goto err_put_device;
1238
1239 ret = device_add(&wm9713->ac97->dev);
1240 if (ret)
1241 goto err_put_device;
1238 1242
1239 /* unmute the adc - move to kcontrol */ 1243 /* unmute the adc - move to kcontrol */
1240 reg = ac97_read(codec, AC97_CD) & 0x7fff; 1244 reg = ac97_read(codec, AC97_CD) & 0x7fff;
@@ -1242,8 +1246,8 @@ static int wm9713_soc_probe(struct snd_soc_codec *codec)
1242 1246
1243 return 0; 1247 return 0;
1244 1248
1245reset_err: 1249err_put_device:
1246 snd_soc_free_ac97_codec(wm9713->ac97); 1250 put_device(&wm9713->ac97->dev);
1247 return ret; 1251 return ret;
1248} 1252}
1249 1253
diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c
index 720d6e852986..ff67b334065b 100644
--- a/sound/soc/codecs/wm_adsp.c
+++ b/sound/soc/codecs/wm_adsp.c
@@ -1373,7 +1373,7 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w,
1373 struct snd_kcontrol *kcontrol, 1373 struct snd_kcontrol *kcontrol,
1374 int event) 1374 int event)
1375{ 1375{
1376 struct snd_soc_codec *codec = w->codec; 1376 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1377 struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec); 1377 struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec);
1378 struct wm_adsp *dsp = &dsps[w->shift]; 1378 struct wm_adsp *dsp = &dsps[w->shift];
1379 struct wm_adsp_alg_region *alg_region; 1379 struct wm_adsp_alg_region *alg_region;
@@ -1605,7 +1605,7 @@ err:
1605int wm_adsp2_early_event(struct snd_soc_dapm_widget *w, 1605int wm_adsp2_early_event(struct snd_soc_dapm_widget *w,
1606 struct snd_kcontrol *kcontrol, int event) 1606 struct snd_kcontrol *kcontrol, int event)
1607{ 1607{
1608 struct snd_soc_codec *codec = w->codec; 1608 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1609 struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec); 1609 struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec);
1610 struct wm_adsp *dsp = &dsps[w->shift]; 1610 struct wm_adsp *dsp = &dsps[w->shift];
1611 1611
@@ -1626,7 +1626,7 @@ EXPORT_SYMBOL_GPL(wm_adsp2_early_event);
1626int wm_adsp2_event(struct snd_soc_dapm_widget *w, 1626int wm_adsp2_event(struct snd_soc_dapm_widget *w,
1627 struct snd_kcontrol *kcontrol, int event) 1627 struct snd_kcontrol *kcontrol, int event)
1628{ 1628{
1629 struct snd_soc_codec *codec = w->codec; 1629 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
1630 struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec); 1630 struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec);
1631 struct wm_adsp *dsp = &dsps[w->shift]; 1631 struct wm_adsp *dsp = &dsps[w->shift];
1632 struct wm_adsp_alg_region *alg_region; 1632 struct wm_adsp_alg_region *alg_region;
diff --git a/sound/soc/codecs/wm_hubs.c b/sound/soc/codecs/wm_hubs.c
index 374537d5e179..8366e19657a7 100644
--- a/sound/soc/codecs/wm_hubs.c
+++ b/sound/soc/codecs/wm_hubs.c
@@ -500,7 +500,7 @@ SOC_SINGLE_TLV("LINEOUT2 Volume", WM8993_LINE_OUTPUTS_VOLUME, 0, 1, 1,
500static int hp_supply_event(struct snd_soc_dapm_widget *w, 500static int hp_supply_event(struct snd_soc_dapm_widget *w,
501 struct snd_kcontrol *kcontrol, int event) 501 struct snd_kcontrol *kcontrol, int event)
502{ 502{
503 struct snd_soc_codec *codec = w->codec; 503 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
504 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 504 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
505 505
506 switch (event) { 506 switch (event) {
@@ -542,7 +542,7 @@ static int hp_supply_event(struct snd_soc_dapm_widget *w,
542static int hp_event(struct snd_soc_dapm_widget *w, 542static int hp_event(struct snd_soc_dapm_widget *w,
543 struct snd_kcontrol *kcontrol, int event) 543 struct snd_kcontrol *kcontrol, int event)
544{ 544{
545 struct snd_soc_codec *codec = w->codec; 545 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
546 unsigned int reg = snd_soc_read(codec, WM8993_ANALOGUE_HP_0); 546 unsigned int reg = snd_soc_read(codec, WM8993_ANALOGUE_HP_0);
547 547
548 switch (event) { 548 switch (event) {
@@ -594,7 +594,7 @@ static int hp_event(struct snd_soc_dapm_widget *w,
594static int earpiece_event(struct snd_soc_dapm_widget *w, 594static int earpiece_event(struct snd_soc_dapm_widget *w,
595 struct snd_kcontrol *control, int event) 595 struct snd_kcontrol *control, int event)
596{ 596{
597 struct snd_soc_codec *codec = w->codec; 597 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
598 u16 reg = snd_soc_read(codec, WM8993_ANTIPOP1) & ~WM8993_HPOUT2_IN_ENA; 598 u16 reg = snd_soc_read(codec, WM8993_ANTIPOP1) & ~WM8993_HPOUT2_IN_ENA;
599 599
600 switch (event) { 600 switch (event) {
@@ -619,7 +619,7 @@ static int earpiece_event(struct snd_soc_dapm_widget *w,
619static int lineout_event(struct snd_soc_dapm_widget *w, 619static int lineout_event(struct snd_soc_dapm_widget *w,
620 struct snd_kcontrol *control, int event) 620 struct snd_kcontrol *control, int event)
621{ 621{
622 struct snd_soc_codec *codec = w->codec; 622 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
623 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 623 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
624 bool *flag; 624 bool *flag;
625 625
@@ -649,7 +649,7 @@ static int lineout_event(struct snd_soc_dapm_widget *w,
649static int micbias_event(struct snd_soc_dapm_widget *w, 649static int micbias_event(struct snd_soc_dapm_widget *w,
650 struct snd_kcontrol *kcontrol, int event) 650 struct snd_kcontrol *kcontrol, int event)
651{ 651{
652 struct snd_soc_codec *codec = w->codec; 652 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
653 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec); 653 struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
654 654
655 switch (w->shift) { 655 switch (w->shift) {
diff --git a/sound/soc/davinci/Kconfig b/sound/soc/davinci/Kconfig
index 8e948c63f3d9..2b81ca418d2a 100644
--- a/sound/soc/davinci/Kconfig
+++ b/sound/soc/davinci/Kconfig
@@ -58,13 +58,12 @@ choice
58 depends on MACH_DAVINCI_DM365_EVM 58 depends on MACH_DAVINCI_DM365_EVM
59 59
60config SND_DM365_AIC3X_CODEC 60config SND_DM365_AIC3X_CODEC
61 bool "Audio Codec - AIC3101" 61 tristate "Audio Codec - AIC3101"
62 help 62 help
63 Say Y if you want to add support for AIC3101 audio codec 63 Say Y if you want to add support for AIC3101 audio codec
64 64
65config SND_DM365_VOICE_CODEC 65config SND_DM365_VOICE_CODEC
66 tristate "Voice Codec - CQ93VC" 66 tristate "Voice Codec - CQ93VC"
67 depends on SND_DAVINCI_SOC
68 select MFD_DAVINCI_VOICECODEC 67 select MFD_DAVINCI_VOICECODEC
69 select SND_DAVINCI_SOC_VCIF 68 select SND_DAVINCI_SOC_VCIF
70 select SND_SOC_CQ0093VC 69 select SND_SOC_CQ0093VC
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c
index 158cb3d1db70..b6bb5947a8a8 100644
--- a/sound/soc/davinci/davinci-evm.c
+++ b/sound/soc/davinci/davinci-evm.c
@@ -14,7 +14,6 @@
14#include <linux/timer.h> 14#include <linux/timer.h>
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/platform_data/edma.h>
18#include <linux/i2c.h> 17#include <linux/i2c.h>
19#include <linux/of_platform.h> 18#include <linux/of_platform.h>
20#include <linux/clk.h> 19#include <linux/clk.h>
@@ -25,11 +24,6 @@
25#include <asm/dma.h> 24#include <asm/dma.h>
26#include <asm/mach-types.h> 25#include <asm/mach-types.h>
27 26
28#include <linux/edma.h>
29
30#include "davinci-pcm.h"
31#include "davinci-i2s.h"
32
33struct snd_soc_card_drvdata_davinci { 27struct snd_soc_card_drvdata_davinci {
34 struct clk *mclk; 28 struct clk *mclk;
35 unsigned sysclk; 29 unsigned sysclk;
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index 30b94d4f9c5d..de3b155a5011 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -364,6 +364,20 @@ static irqreturn_t davinci_mcasp_rx_irq_handler(int irq, void *data)
364 return IRQ_RETVAL(handled_mask); 364 return IRQ_RETVAL(handled_mask);
365} 365}
366 366
367static irqreturn_t davinci_mcasp_common_irq_handler(int irq, void *data)
368{
369 struct davinci_mcasp *mcasp = (struct davinci_mcasp *)data;
370 irqreturn_t ret = IRQ_NONE;
371
372 if (mcasp->substreams[SNDRV_PCM_STREAM_PLAYBACK])
373 ret = davinci_mcasp_tx_irq_handler(irq, data);
374
375 if (mcasp->substreams[SNDRV_PCM_STREAM_CAPTURE])
376 ret |= davinci_mcasp_rx_irq_handler(irq, data);
377
378 return ret;
379}
380
367static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai, 381static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
368 unsigned int fmt) 382 unsigned int fmt)
369{ 383{
@@ -1313,16 +1327,19 @@ static struct davinci_mcasp_pdata *davinci_mcasp_set_pdata_from_of(
1313 1327
1314 pdata->tx_dma_channel = dma_spec.args[0]; 1328 pdata->tx_dma_channel = dma_spec.args[0];
1315 1329
1316 ret = of_property_match_string(np, "dma-names", "rx"); 1330 /* RX is not valid in DIT mode */
1317 if (ret < 0) 1331 if (pdata->op_mode != DAVINCI_MCASP_DIT_MODE) {
1318 goto nodata; 1332 ret = of_property_match_string(np, "dma-names", "rx");
1333 if (ret < 0)
1334 goto nodata;
1319 1335
1320 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret, 1336 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
1321 &dma_spec); 1337 &dma_spec);
1322 if (ret < 0) 1338 if (ret < 0)
1323 goto nodata; 1339 goto nodata;
1324 1340
1325 pdata->rx_dma_channel = dma_spec.args[0]; 1341 pdata->rx_dma_channel = dma_spec.args[0];
1342 }
1326 1343
1327 ret = of_property_read_u32(np, "tx-num-evt", &val); 1344 ret = of_property_read_u32(np, "tx-num-evt", &val);
1328 if (ret >= 0) 1345 if (ret >= 0)
@@ -1441,6 +1458,23 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1441 1458
1442 mcasp->dev = &pdev->dev; 1459 mcasp->dev = &pdev->dev;
1443 1460
1461 irq = platform_get_irq_byname(pdev, "common");
1462 if (irq >= 0) {
1463 irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_common\n",
1464 dev_name(&pdev->dev));
1465 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
1466 davinci_mcasp_common_irq_handler,
1467 IRQF_ONESHOT | IRQF_SHARED,
1468 irq_name, mcasp);
1469 if (ret) {
1470 dev_err(&pdev->dev, "common IRQ request failed\n");
1471 goto err;
1472 }
1473
1474 mcasp->irq_request[SNDRV_PCM_STREAM_PLAYBACK] = XUNDRN;
1475 mcasp->irq_request[SNDRV_PCM_STREAM_CAPTURE] = ROVRN;
1476 }
1477
1444 irq = platform_get_irq_byname(pdev, "rx"); 1478 irq = platform_get_irq_byname(pdev, "rx");
1445 if (irq >= 0) { 1479 if (irq >= 0) {
1446 irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_rx\n", 1480 irq_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s_rx\n",
@@ -1501,19 +1535,34 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1501 else 1535 else
1502 dma_data->filter_data = &dma_params->channel; 1536 dma_data->filter_data = &dma_params->channel;
1503 1537
1504 dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_CAPTURE]; 1538 /* RX is not valid in DIT mode */
1505 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE]; 1539 if (mcasp->op_mode != DAVINCI_MCASP_DIT_MODE) {
1506 dma_params->asp_chan_q = pdata->asp_chan_q; 1540 dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_CAPTURE];
1507 dma_params->ram_chan_q = pdata->ram_chan_q; 1541 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE];
1508 dma_params->sram_pool = pdata->sram_pool; 1542 dma_params->asp_chan_q = pdata->asp_chan_q;
1509 dma_params->sram_size = pdata->sram_size_capture; 1543 dma_params->ram_chan_q = pdata->ram_chan_q;
1510 if (dat) 1544 dma_params->sram_pool = pdata->sram_pool;
1511 dma_params->dma_addr = dat->start; 1545 dma_params->sram_size = pdata->sram_size_capture;
1512 else 1546 if (dat)
1513 dma_params->dma_addr = mem->start + pdata->rx_dma_offset; 1547 dma_params->dma_addr = dat->start;
1514 1548 else
1515 /* Unconditional dmaengine stuff */ 1549 dma_params->dma_addr = mem->start + pdata->rx_dma_offset;
1516 dma_data->addr = dma_params->dma_addr; 1550
1551 /* Unconditional dmaengine stuff */
1552 dma_data->addr = dma_params->dma_addr;
1553
1554 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1555 if (res)
1556 dma_params->channel = res->start;
1557 else
1558 dma_params->channel = pdata->rx_dma_channel;
1559
1560 /* dmaengine filter data for DT and non-DT boot */
1561 if (pdev->dev.of_node)
1562 dma_data->filter_data = "rx";
1563 else
1564 dma_data->filter_data = &dma_params->channel;
1565 }
1517 1566
1518 if (mcasp->version < MCASP_VERSION_3) { 1567 if (mcasp->version < MCASP_VERSION_3) {
1519 mcasp->fifo_base = DAVINCI_MCASP_V2_AFIFO_BASE; 1568 mcasp->fifo_base = DAVINCI_MCASP_V2_AFIFO_BASE;
@@ -1523,18 +1572,6 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
1523 mcasp->fifo_base = DAVINCI_MCASP_V3_AFIFO_BASE; 1572 mcasp->fifo_base = DAVINCI_MCASP_V3_AFIFO_BASE;
1524 } 1573 }
1525 1574
1526 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1527 if (res)
1528 dma_params->channel = res->start;
1529 else
1530 dma_params->channel = pdata->rx_dma_channel;
1531
1532 /* dmaengine filter data for DT and non-DT boot */
1533 if (pdev->dev.of_node)
1534 dma_data->filter_data = "rx";
1535 else
1536 dma_data->filter_data = &dma_params->channel;
1537
1538 dev_set_drvdata(&pdev->dev, mcasp); 1575 dev_set_drvdata(&pdev->dev, mcasp);
1539 1576
1540 mcasp_reparent_fck(pdev); 1577 mcasp_reparent_fck(pdev);
diff --git a/sound/soc/dwc/Kconfig b/sound/soc/dwc/Kconfig
index e334900cf0b8..d50e08517dce 100644
--- a/sound/soc/dwc/Kconfig
+++ b/sound/soc/dwc/Kconfig
@@ -1,6 +1,7 @@
1config SND_DESIGNWARE_I2S 1config SND_DESIGNWARE_I2S
2 tristate "Synopsys I2S Device Driver" 2 tristate "Synopsys I2S Device Driver"
3 depends on CLKDEV_LOOKUP 3 depends on CLKDEV_LOOKUP
4 select SND_SOC_GENERIC_DMAENGINE_PCM
4 help 5 help
5 Say Y or M if you want to add support for I2S driver for 6 Say Y or M if you want to add support for I2S driver for
6 Synopsys desigwnware I2S device. The device supports upto 7 Synopsys desigwnware I2S device. The device supports upto
diff --git a/sound/soc/dwc/designware_i2s.c b/sound/soc/dwc/designware_i2s.c
index 06d3a34ac90a..a3e97b46b64e 100644
--- a/sound/soc/dwc/designware_i2s.c
+++ b/sound/soc/dwc/designware_i2s.c
@@ -22,6 +22,7 @@
22#include <sound/pcm.h> 22#include <sound/pcm.h>
23#include <sound/pcm_params.h> 23#include <sound/pcm_params.h>
24#include <sound/soc.h> 24#include <sound/soc.h>
25#include <sound/dmaengine_pcm.h>
25 26
26/* common register for all channel */ 27/* common register for all channel */
27#define IER 0x000 28#define IER 0x000
@@ -54,9 +55,39 @@
54#define I2S_COMP_VERSION 0x01F8 55#define I2S_COMP_VERSION 0x01F8
55#define I2S_COMP_TYPE 0x01FC 56#define I2S_COMP_TYPE 0x01FC
56 57
58/*
59 * Component parameter register fields - define the I2S block's
60 * configuration.
61 */
62#define COMP1_TX_WORDSIZE_3(r) (((r) & GENMASK(27, 25)) >> 25)
63#define COMP1_TX_WORDSIZE_2(r) (((r) & GENMASK(24, 22)) >> 22)
64#define COMP1_TX_WORDSIZE_1(r) (((r) & GENMASK(21, 19)) >> 19)
65#define COMP1_TX_WORDSIZE_0(r) (((r) & GENMASK(18, 16)) >> 16)
66#define COMP1_TX_CHANNELS(r) (((r) & GENMASK(10, 9)) >> 9)
67#define COMP1_RX_CHANNELS(r) (((r) & GENMASK(8, 7)) >> 7)
68#define COMP1_RX_ENABLED(r) (((r) & BIT(6)) >> 6)
69#define COMP1_TX_ENABLED(r) (((r) & BIT(5)) >> 5)
70#define COMP1_MODE_EN(r) (((r) & BIT(4)) >> 4)
71#define COMP1_FIFO_DEPTH_GLOBAL(r) (((r) & GENMASK(3, 2)) >> 2)
72#define COMP1_APB_DATA_WIDTH(r) (((r) & GENMASK(1, 0)) >> 0)
73
74#define COMP2_RX_WORDSIZE_3(r) (((r) & GENMASK(12, 10)) >> 10)
75#define COMP2_RX_WORDSIZE_2(r) (((r) & GENMASK(9, 7)) >> 7)
76#define COMP2_RX_WORDSIZE_1(r) (((r) & GENMASK(5, 3)) >> 3)
77#define COMP2_RX_WORDSIZE_0(r) (((r) & GENMASK(2, 0)) >> 0)
78
79/* Number of entries in WORDSIZE and DATA_WIDTH parameter registers */
80#define COMP_MAX_WORDSIZE (1 << 3)
81#define COMP_MAX_DATA_WIDTH (1 << 2)
82
57#define MAX_CHANNEL_NUM 8 83#define MAX_CHANNEL_NUM 8
58#define MIN_CHANNEL_NUM 2 84#define MIN_CHANNEL_NUM 2
59 85
86union dw_i2s_snd_dma_data {
87 struct i2s_dma_data pd;
88 struct snd_dmaengine_dai_dma_data dt;
89};
90
60struct dw_i2s_dev { 91struct dw_i2s_dev {
61 void __iomem *i2s_base; 92 void __iomem *i2s_base;
62 struct clk *clk; 93 struct clk *clk;
@@ -65,8 +96,8 @@ struct dw_i2s_dev {
65 struct device *dev; 96 struct device *dev;
66 97
67 /* data related to DMA transfers b/w i2s and DMAC */ 98 /* data related to DMA transfers b/w i2s and DMAC */
68 struct i2s_dma_data play_dma_data; 99 union dw_i2s_snd_dma_data play_dma_data;
69 struct i2s_dma_data capture_dma_data; 100 union dw_i2s_snd_dma_data capture_dma_data;
70 struct i2s_clk_config_data config; 101 struct i2s_clk_config_data config;
71 int (*i2s_clk_cfg)(struct i2s_clk_config_data *config); 102 int (*i2s_clk_cfg)(struct i2s_clk_config_data *config);
72}; 103};
@@ -153,7 +184,7 @@ static int dw_i2s_startup(struct snd_pcm_substream *substream,
153 struct snd_soc_dai *cpu_dai) 184 struct snd_soc_dai *cpu_dai)
154{ 185{
155 struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(cpu_dai); 186 struct dw_i2s_dev *dev = snd_soc_dai_get_drvdata(cpu_dai);
156 struct i2s_dma_data *dma_data = NULL; 187 union dw_i2s_snd_dma_data *dma_data = NULL;
157 188
158 if (!(dev->capability & DWC_I2S_RECORD) && 189 if (!(dev->capability & DWC_I2S_RECORD) &&
159 (substream->stream == SNDRV_PCM_STREAM_CAPTURE)) 190 (substream->stream == SNDRV_PCM_STREAM_CAPTURE))
@@ -242,13 +273,21 @@ static int dw_i2s_hw_params(struct snd_pcm_substream *substream,
242 273
243 config->sample_rate = params_rate(params); 274 config->sample_rate = params_rate(params);
244 275
245 if (!dev->i2s_clk_cfg) 276 if (dev->i2s_clk_cfg) {
246 return -EINVAL; 277 ret = dev->i2s_clk_cfg(config);
278 if (ret < 0) {
279 dev_err(dev->dev, "runtime audio clk config fail\n");
280 return ret;
281 }
282 } else {
283 u32 bitclk = config->sample_rate * config->data_width * 2;
247 284
248 ret = dev->i2s_clk_cfg(config); 285 ret = clk_set_rate(dev->clk, bitclk);
249 if (ret < 0) { 286 if (ret) {
250 dev_err(dev->dev, "runtime audio clk config fail\n"); 287 dev_err(dev->dev, "Can't set I2S clock rate: %d\n",
251 return ret; 288 ret);
289 return ret;
290 }
252 } 291 }
253 292
254 return 0; 293 return 0;
@@ -335,39 +374,152 @@ static int dw_i2s_resume(struct snd_soc_dai *dai)
335#define dw_i2s_resume NULL 374#define dw_i2s_resume NULL
336#endif 375#endif
337 376
338static void dw_configure_dai_by_pd(struct dw_i2s_dev *dev, 377/*
378 * The following tables allow a direct lookup of various parameters
379 * defined in the I2S block's configuration in terms of sound system
380 * parameters. Each table is sized to the number of entries possible
381 * according to the number of configuration bits describing an I2S
382 * block parameter.
383 */
384
385/* Maximum bit resolution of a channel - not uniformly spaced */
386static const u32 fifo_width[COMP_MAX_WORDSIZE] = {
387 12, 16, 20, 24, 32, 0, 0, 0
388};
389
390/* Width of (DMA) bus */
391static const u32 bus_widths[COMP_MAX_DATA_WIDTH] = {
392 DMA_SLAVE_BUSWIDTH_1_BYTE,
393 DMA_SLAVE_BUSWIDTH_2_BYTES,
394 DMA_SLAVE_BUSWIDTH_4_BYTES,
395 DMA_SLAVE_BUSWIDTH_UNDEFINED
396};
397
398/* PCM format to support channel resolution */
399static const u32 formats[COMP_MAX_WORDSIZE] = {
400 SNDRV_PCM_FMTBIT_S16_LE,
401 SNDRV_PCM_FMTBIT_S16_LE,
402 SNDRV_PCM_FMTBIT_S24_LE,
403 SNDRV_PCM_FMTBIT_S24_LE,
404 SNDRV_PCM_FMTBIT_S32_LE,
405 0,
406 0,
407 0
408};
409
410static int dw_configure_dai(struct dw_i2s_dev *dev,
339 struct snd_soc_dai_driver *dw_i2s_dai, 411 struct snd_soc_dai_driver *dw_i2s_dai,
340 struct resource *res, 412 unsigned int rates)
341 const struct i2s_platform_data *pdata)
342{ 413{
343 /* Set DMA slaves info */ 414 /*
344 415 * Read component parameter registers to extract
345 dev->play_dma_data.data = pdata->play_dma_data; 416 * the I2S block's configuration.
346 dev->capture_dma_data.data = pdata->capture_dma_data; 417 */
347 dev->play_dma_data.addr = res->start + I2S_TXDMA; 418 u32 comp1 = i2s_read_reg(dev->i2s_base, I2S_COMP_PARAM_1);
348 dev->capture_dma_data.addr = res->start + I2S_RXDMA; 419 u32 comp2 = i2s_read_reg(dev->i2s_base, I2S_COMP_PARAM_2);
349 dev->play_dma_data.max_burst = 16; 420 u32 idx;
350 dev->capture_dma_data.max_burst = 16; 421
351 dev->play_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; 422 if (COMP1_TX_ENABLED(comp1)) {
352 dev->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
353 dev->play_dma_data.filter = pdata->filter;
354 dev->capture_dma_data.filter = pdata->filter;
355
356 if (pdata->cap & DWC_I2S_PLAY) {
357 dev_dbg(dev->dev, " designware: play supported\n"); 423 dev_dbg(dev->dev, " designware: play supported\n");
424 idx = COMP1_TX_WORDSIZE_0(comp1);
425 if (WARN_ON(idx >= ARRAY_SIZE(formats)))
426 return -EINVAL;
358 dw_i2s_dai->playback.channels_min = MIN_CHANNEL_NUM; 427 dw_i2s_dai->playback.channels_min = MIN_CHANNEL_NUM;
359 dw_i2s_dai->playback.channels_max = pdata->channel; 428 dw_i2s_dai->playback.channels_max =
360 dw_i2s_dai->playback.formats = pdata->snd_fmts; 429 1 << (COMP1_TX_CHANNELS(comp1) + 1);
361 dw_i2s_dai->playback.rates = pdata->snd_rates; 430 dw_i2s_dai->playback.formats = formats[idx];
431 dw_i2s_dai->playback.rates = rates;
362 } 432 }
363 433
364 if (pdata->cap & DWC_I2S_RECORD) { 434 if (COMP1_RX_ENABLED(comp1)) {
365 dev_dbg(dev->dev, "designware: record supported\n"); 435 dev_dbg(dev->dev, "designware: record supported\n");
436 idx = COMP2_RX_WORDSIZE_0(comp2);
437 if (WARN_ON(idx >= ARRAY_SIZE(formats)))
438 return -EINVAL;
366 dw_i2s_dai->capture.channels_min = MIN_CHANNEL_NUM; 439 dw_i2s_dai->capture.channels_min = MIN_CHANNEL_NUM;
367 dw_i2s_dai->capture.channels_max = pdata->channel; 440 dw_i2s_dai->capture.channels_max =
368 dw_i2s_dai->capture.formats = pdata->snd_fmts; 441 1 << (COMP1_RX_CHANNELS(comp1) + 1);
369 dw_i2s_dai->capture.rates = pdata->snd_rates; 442 dw_i2s_dai->capture.formats = formats[idx];
443 dw_i2s_dai->capture.rates = rates;
370 } 444 }
445
446 return 0;
447}
448
449static int dw_configure_dai_by_pd(struct dw_i2s_dev *dev,
450 struct snd_soc_dai_driver *dw_i2s_dai,
451 struct resource *res,
452 const struct i2s_platform_data *pdata)
453{
454 u32 comp1 = i2s_read_reg(dev->i2s_base, I2S_COMP_PARAM_1);
455 u32 idx = COMP1_APB_DATA_WIDTH(comp1);
456 int ret;
457
458 if (WARN_ON(idx >= ARRAY_SIZE(bus_widths)))
459 return -EINVAL;
460
461 ret = dw_configure_dai(dev, dw_i2s_dai, pdata->snd_rates);
462 if (ret < 0)
463 return ret;
464
465 /* Set DMA slaves info */
466 dev->play_dma_data.pd.data = pdata->play_dma_data;
467 dev->capture_dma_data.pd.data = pdata->capture_dma_data;
468 dev->play_dma_data.pd.addr = res->start + I2S_TXDMA;
469 dev->capture_dma_data.pd.addr = res->start + I2S_RXDMA;
470 dev->play_dma_data.pd.max_burst = 16;
471 dev->capture_dma_data.pd.max_burst = 16;
472 dev->play_dma_data.pd.addr_width = bus_widths[idx];
473 dev->capture_dma_data.pd.addr_width = bus_widths[idx];
474 dev->play_dma_data.pd.filter = pdata->filter;
475 dev->capture_dma_data.pd.filter = pdata->filter;
476
477 return 0;
478}
479
480static int dw_configure_dai_by_dt(struct dw_i2s_dev *dev,
481 struct snd_soc_dai_driver *dw_i2s_dai,
482 struct resource *res)
483{
484 u32 comp1 = i2s_read_reg(dev->i2s_base, I2S_COMP_PARAM_1);
485 u32 comp2 = i2s_read_reg(dev->i2s_base, I2S_COMP_PARAM_2);
486 u32 fifo_depth = 1 << (1 + COMP1_FIFO_DEPTH_GLOBAL(comp1));
487 u32 idx = COMP1_APB_DATA_WIDTH(comp1);
488 u32 idx2;
489 int ret;
490
491 if (WARN_ON(idx >= ARRAY_SIZE(bus_widths)))
492 return -EINVAL;
493
494 ret = dw_configure_dai(dev, dw_i2s_dai, SNDRV_PCM_RATE_8000_192000);
495 if (ret < 0)
496 return ret;
497
498 if (COMP1_TX_ENABLED(comp1)) {
499 idx2 = COMP1_TX_WORDSIZE_0(comp1);
500
501 dev->capability |= DWC_I2S_PLAY;
502 dev->play_dma_data.dt.addr = res->start + I2S_TXDMA;
503 dev->play_dma_data.dt.addr_width = bus_widths[idx];
504 dev->play_dma_data.dt.chan_name = "TX";
505 dev->play_dma_data.dt.fifo_size = fifo_depth *
506 (fifo_width[idx2]) >> 8;
507 dev->play_dma_data.dt.maxburst = 16;
508 }
509 if (COMP1_RX_ENABLED(comp1)) {
510 idx2 = COMP2_RX_WORDSIZE_0(comp2);
511
512 dev->capability |= DWC_I2S_RECORD;
513 dev->capture_dma_data.dt.addr = res->start + I2S_RXDMA;
514 dev->capture_dma_data.dt.addr_width = bus_widths[idx];
515 dev->capture_dma_data.dt.chan_name = "RX";
516 dev->capture_dma_data.dt.fifo_size = fifo_depth *
517 (fifo_width[idx2] >> 8);
518 dev->capture_dma_data.dt.maxburst = 16;
519 }
520
521 return 0;
522
371} 523}
372 524
373static int dw_i2s_probe(struct platform_device *pdev) 525static int dw_i2s_probe(struct platform_device *pdev)
@@ -378,11 +530,6 @@ static int dw_i2s_probe(struct platform_device *pdev)
378 int ret; 530 int ret;
379 struct snd_soc_dai_driver *dw_i2s_dai; 531 struct snd_soc_dai_driver *dw_i2s_dai;
380 532
381 if (!pdata) {
382 dev_err(&pdev->dev, "Invalid platform data\n");
383 return -EINVAL;
384 }
385
386 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); 533 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
387 if (!dev) { 534 if (!dev) {
388 dev_warn(&pdev->dev, "kzalloc fail\n"); 535 dev_warn(&pdev->dev, "kzalloc fail\n");
@@ -403,32 +550,54 @@ static int dw_i2s_probe(struct platform_device *pdev)
403 return PTR_ERR(dev->i2s_base); 550 return PTR_ERR(dev->i2s_base);
404 551
405 dev->dev = &pdev->dev; 552 dev->dev = &pdev->dev;
406 dw_configure_dai_by_pd(dev, dw_i2s_dai, res, pdata); 553 if (pdata) {
554 ret = dw_configure_dai_by_pd(dev, dw_i2s_dai, res, pdata);
555 if (ret < 0)
556 return ret;
557
558 dev->capability = pdata->cap;
559 dev->i2s_clk_cfg = pdata->i2s_clk_cfg;
560 if (!dev->i2s_clk_cfg) {
561 dev_err(&pdev->dev, "no clock configure method\n");
562 return -ENODEV;
563 }
407 564
408 dev->capability = pdata->cap; 565 dev->clk = devm_clk_get(&pdev->dev, NULL);
409 dev->i2s_clk_cfg = pdata->i2s_clk_cfg; 566 } else {
410 dev->clk = clk_get(&pdev->dev, NULL); 567 ret = dw_configure_dai_by_dt(dev, dw_i2s_dai, res);
568 if (ret < 0)
569 return ret;
570
571 dev->clk = devm_clk_get(&pdev->dev, "i2sclk");
572 }
411 if (IS_ERR(dev->clk)) 573 if (IS_ERR(dev->clk))
412 return PTR_ERR(dev->clk); 574 return PTR_ERR(dev->clk);
413 575
414 ret = clk_enable(dev->clk); 576 ret = clk_prepare_enable(dev->clk);
415 if (ret < 0) 577 if (ret < 0)
416 goto err_clk_put; 578 return ret;
417 579
418 dev_set_drvdata(&pdev->dev, dev); 580 dev_set_drvdata(&pdev->dev, dev);
419 ret = snd_soc_register_component(&pdev->dev, &dw_i2s_component, 581 ret = devm_snd_soc_register_component(&pdev->dev, &dw_i2s_component,
420 dw_i2s_dai, 1); 582 dw_i2s_dai, 1);
421 if (ret != 0) { 583 if (ret != 0) {
422 dev_err(&pdev->dev, "not able to register dai\n"); 584 dev_err(&pdev->dev, "not able to register dai\n");
423 goto err_clk_disable; 585 goto err_clk_disable;
424 } 586 }
425 587
588 if (!pdata) {
589 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0);
590 if (ret) {
591 dev_err(&pdev->dev,
592 "Could not register PCM: %d\n", ret);
593 goto err_clk_disable;
594 }
595 }
596
426 return 0; 597 return 0;
427 598
428err_clk_disable: 599err_clk_disable:
429 clk_disable(dev->clk); 600 clk_disable_unprepare(dev->clk);
430err_clk_put:
431 clk_put(dev->clk);
432 return ret; 601 return ret;
433} 602}
434 603
@@ -436,18 +605,26 @@ static int dw_i2s_remove(struct platform_device *pdev)
436{ 605{
437 struct dw_i2s_dev *dev = dev_get_drvdata(&pdev->dev); 606 struct dw_i2s_dev *dev = dev_get_drvdata(&pdev->dev);
438 607
439 snd_soc_unregister_component(&pdev->dev); 608 clk_disable_unprepare(dev->clk);
440
441 clk_put(dev->clk);
442 609
443 return 0; 610 return 0;
444} 611}
445 612
613#ifdef CONFIG_OF
614static const struct of_device_id dw_i2s_of_match[] = {
615 { .compatible = "snps,designware-i2s", },
616 {},
617};
618
619MODULE_DEVICE_TABLE(of, dw_i2s_of_match);
620#endif
621
446static struct platform_driver dw_i2s_driver = { 622static struct platform_driver dw_i2s_driver = {
447 .probe = dw_i2s_probe, 623 .probe = dw_i2s_probe,
448 .remove = dw_i2s_remove, 624 .remove = dw_i2s_remove,
449 .driver = { 625 .driver = {
450 .name = "designware-i2s", 626 .name = "designware-i2s",
627 .of_match_table = of_match_ptr(dw_i2s_of_match),
451 }, 628 },
452}; 629};
453 630
diff --git a/sound/soc/fsl/eukrea-tlv320.c b/sound/soc/fsl/eukrea-tlv320.c
index 9ce70fc67b09..e1aa3834b101 100644
--- a/sound/soc/fsl/eukrea-tlv320.c
+++ b/sound/soc/fsl/eukrea-tlv320.c
@@ -42,25 +42,6 @@ static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
42 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 42 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
43 int ret; 43 int ret;
44 44
45 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
46 SND_SOC_DAIFMT_NB_NF |
47 SND_SOC_DAIFMT_CBM_CFM);
48 /* fsl_ssi lacks the set_fmt ops. */
49 if (ret && ret != -ENOTSUPP) {
50 dev_err(cpu_dai->dev,
51 "Failed to set the cpu dai format.\n");
52 return ret;
53 }
54
55 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
56 SND_SOC_DAIFMT_NB_NF |
57 SND_SOC_DAIFMT_CBM_CFM);
58 if (ret) {
59 dev_err(cpu_dai->dev,
60 "Failed to set the codec format.\n");
61 return ret;
62 }
63
64 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 45 ret = snd_soc_dai_set_sysclk(codec_dai, 0,
65 CODEC_CLOCK, SND_SOC_CLOCK_OUT); 46 CODEC_CLOCK, SND_SOC_CLOCK_OUT);
66 if (ret) { 47 if (ret) {
@@ -69,7 +50,7 @@ static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
69 return ret; 50 return ret;
70 } 51 }
71 52
72 snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0); 53 snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 2, 0);
73 54
74 ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0, 55 ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0,
75 SND_SOC_CLOCK_IN); 56 SND_SOC_CLOCK_IN);
@@ -91,6 +72,8 @@ static struct snd_soc_dai_link eukrea_tlv320_dai = {
91 .name = "tlv320aic23", 72 .name = "tlv320aic23",
92 .stream_name = "TLV320AIC23", 73 .stream_name = "TLV320AIC23",
93 .codec_dai_name = "tlv320aic23-hifi", 74 .codec_dai_name = "tlv320aic23-hifi",
75 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
76 SND_SOC_DAIFMT_CBM_CFM,
94 .ops = &eukrea_tlv320_snd_ops, 77 .ops = &eukrea_tlv320_snd_ops,
95}; 78};
96 79
diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c
index 026a80117540..c068494bae30 100644
--- a/sound/soc/fsl/fsl_asrc.c
+++ b/sound/soc/fsl/fsl_asrc.c
@@ -818,7 +818,6 @@ static int fsl_asrc_probe(struct platform_device *pdev)
818 return -ENOMEM; 818 return -ENOMEM;
819 819
820 asrc_priv->pdev = pdev; 820 asrc_priv->pdev = pdev;
821 strncpy(asrc_priv->name, np->name, sizeof(asrc_priv->name) - 1);
822 821
823 /* Get the addresses and IRQ */ 822 /* Get the addresses and IRQ */
824 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 823 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -837,12 +836,12 @@ static int fsl_asrc_probe(struct platform_device *pdev)
837 836
838 irq = platform_get_irq(pdev, 0); 837 irq = platform_get_irq(pdev, 0);
839 if (irq < 0) { 838 if (irq < 0) {
840 dev_err(&pdev->dev, "no irq for node %s\n", np->full_name); 839 dev_err(&pdev->dev, "no irq for node %s\n", pdev->name);
841 return irq; 840 return irq;
842 } 841 }
843 842
844 ret = devm_request_irq(&pdev->dev, irq, fsl_asrc_isr, 0, 843 ret = devm_request_irq(&pdev->dev, irq, fsl_asrc_isr, 0,
845 asrc_priv->name, asrc_priv); 844 dev_name(&pdev->dev), asrc_priv);
846 if (ret) { 845 if (ret) {
847 dev_err(&pdev->dev, "failed to claim irq %u: %d\n", irq, ret); 846 dev_err(&pdev->dev, "failed to claim irq %u: %d\n", irq, ret);
848 return ret; 847 return ret;
diff --git a/sound/soc/fsl/fsl_asrc.h b/sound/soc/fsl/fsl_asrc.h
index a3f211f53c23..4aed63c4b431 100644
--- a/sound/soc/fsl/fsl_asrc.h
+++ b/sound/soc/fsl/fsl_asrc.h
@@ -433,7 +433,6 @@ struct fsl_asrc_pair {
433 * @channel_avail: non-occupied channel numbers 433 * @channel_avail: non-occupied channel numbers
434 * @asrc_rate: default sample rate for ASoC Back-Ends 434 * @asrc_rate: default sample rate for ASoC Back-Ends
435 * @asrc_width: default sample width for ASoC Back-Ends 435 * @asrc_width: default sample width for ASoC Back-Ends
436 * @name: driver name
437 */ 436 */
438struct fsl_asrc { 437struct fsl_asrc {
439 struct snd_dmaengine_dai_dma_data dma_params_rx; 438 struct snd_dmaengine_dai_dma_data dma_params_rx;
@@ -452,8 +451,6 @@ struct fsl_asrc {
452 451
453 int asrc_rate; 452 int asrc_rate;
454 int asrc_width; 453 int asrc_width;
455
456 char name[32];
457}; 454};
458 455
459extern struct snd_soc_platform_driver fsl_asrc_platform; 456extern struct snd_soc_platform_driver fsl_asrc_platform;
diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c
index 1c08ab13637c..5c7597191e3f 100644
--- a/sound/soc/fsl/fsl_esai.c
+++ b/sound/soc/fsl/fsl_esai.c
@@ -774,7 +774,7 @@ static int fsl_esai_probe(struct platform_device *pdev)
774 774
775 irq = platform_get_irq(pdev, 0); 775 irq = platform_get_irq(pdev, 0);
776 if (irq < 0) { 776 if (irq < 0) {
777 dev_err(&pdev->dev, "no irq for node %s\n", np->full_name); 777 dev_err(&pdev->dev, "no irq for node %s\n", pdev->name);
778 return irq; 778 return irq;
779 } 779 }
780 780
diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
index 032d2d33619c..ec79c3d5e65e 100644
--- a/sound/soc/fsl/fsl_sai.c
+++ b/sound/soc/fsl/fsl_sai.c
@@ -612,7 +612,7 @@ static int fsl_sai_probe(struct platform_device *pdev)
612 612
613 irq = platform_get_irq(pdev, 0); 613 irq = platform_get_irq(pdev, 0);
614 if (irq < 0) { 614 if (irq < 0) {
615 dev_err(&pdev->dev, "no irq for node %s\n", np->full_name); 615 dev_err(&pdev->dev, "no irq for node %s\n", pdev->name);
616 return irq; 616 return irq;
617 } 617 }
618 618
diff --git a/sound/soc/fsl/fsl_spdif.c b/sound/soc/fsl/fsl_spdif.c
index af0429421fc8..75870c0ea2c9 100644
--- a/sound/soc/fsl/fsl_spdif.c
+++ b/sound/soc/fsl/fsl_spdif.c
@@ -90,7 +90,6 @@ struct spdif_mixer_control {
90 * @sysclk: system clock for rx clock rate measurement 90 * @sysclk: system clock for rx clock rate measurement
91 * @dma_params_tx: DMA parameters for transmit channel 91 * @dma_params_tx: DMA parameters for transmit channel
92 * @dma_params_rx: DMA parameters for receive channel 92 * @dma_params_rx: DMA parameters for receive channel
93 * @name: driver name
94 */ 93 */
95struct fsl_spdif_priv { 94struct fsl_spdif_priv {
96 struct spdif_mixer_control fsl_spdif_control; 95 struct spdif_mixer_control fsl_spdif_control;
@@ -109,12 +108,8 @@ struct fsl_spdif_priv {
109 struct clk *sysclk; 108 struct clk *sysclk;
110 struct snd_dmaengine_dai_dma_data dma_params_tx; 109 struct snd_dmaengine_dai_dma_data dma_params_tx;
111 struct snd_dmaengine_dai_dma_data dma_params_rx; 110 struct snd_dmaengine_dai_dma_data dma_params_rx;
112
113 /* The name space will be allocated dynamically */
114 char name[0];
115}; 111};
116 112
117
118/* DPLL locked and lock loss interrupt handler */ 113/* DPLL locked and lock loss interrupt handler */
119static void spdif_irq_dpll_lock(struct fsl_spdif_priv *spdif_priv) 114static void spdif_irq_dpll_lock(struct fsl_spdif_priv *spdif_priv)
120{ 115{
@@ -1169,19 +1164,15 @@ static int fsl_spdif_probe(struct platform_device *pdev)
1169 if (!np) 1164 if (!np)
1170 return -ENODEV; 1165 return -ENODEV;
1171 1166
1172 spdif_priv = devm_kzalloc(&pdev->dev, 1167 spdif_priv = devm_kzalloc(&pdev->dev, sizeof(*spdif_priv), GFP_KERNEL);
1173 sizeof(struct fsl_spdif_priv) + strlen(np->name) + 1,
1174 GFP_KERNEL);
1175 if (!spdif_priv) 1168 if (!spdif_priv)
1176 return -ENOMEM; 1169 return -ENOMEM;
1177 1170
1178 strcpy(spdif_priv->name, np->name);
1179
1180 spdif_priv->pdev = pdev; 1171 spdif_priv->pdev = pdev;
1181 1172
1182 /* Initialize this copy of the CPU DAI driver structure */ 1173 /* Initialize this copy of the CPU DAI driver structure */
1183 memcpy(&spdif_priv->cpu_dai_drv, &fsl_spdif_dai, sizeof(fsl_spdif_dai)); 1174 memcpy(&spdif_priv->cpu_dai_drv, &fsl_spdif_dai, sizeof(fsl_spdif_dai));
1184 spdif_priv->cpu_dai_drv.name = spdif_priv->name; 1175 spdif_priv->cpu_dai_drv.name = dev_name(&pdev->dev);
1185 1176
1186 /* Get the addresses and IRQ */ 1177 /* Get the addresses and IRQ */
1187 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1178 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1198,12 +1189,12 @@ static int fsl_spdif_probe(struct platform_device *pdev)
1198 1189
1199 irq = platform_get_irq(pdev, 0); 1190 irq = platform_get_irq(pdev, 0);
1200 if (irq < 0) { 1191 if (irq < 0) {
1201 dev_err(&pdev->dev, "no irq for node %s\n", np->full_name); 1192 dev_err(&pdev->dev, "no irq for node %s\n", pdev->name);
1202 return irq; 1193 return irq;
1203 } 1194 }
1204 1195
1205 ret = devm_request_irq(&pdev->dev, irq, spdif_isr, 0, 1196 ret = devm_request_irq(&pdev->dev, irq, spdif_isr, 0,
1206 spdif_priv->name, spdif_priv); 1197 dev_name(&pdev->dev), spdif_priv);
1207 if (ret) { 1198 if (ret) {
1208 dev_err(&pdev->dev, "could not claim irq %u\n", irq); 1199 dev_err(&pdev->dev, "could not claim irq %u\n", irq);
1209 return ret; 1200 return ret;
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index 059496ed9ad7..2595611e8a6d 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -160,7 +160,7 @@ struct fsl_ssi_soc_data {
160 */ 160 */
161struct fsl_ssi_private { 161struct fsl_ssi_private {
162 struct regmap *regs; 162 struct regmap *regs;
163 unsigned int irq; 163 int irq;
164 struct snd_soc_dai_driver cpu_dai_drv; 164 struct snd_soc_dai_driver cpu_dai_drv;
165 165
166 unsigned int dai_fmt; 166 unsigned int dai_fmt;
@@ -992,8 +992,8 @@ static int fsl_ssi_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai, u32 tx_mask,
992 regmap_update_bits(regs, CCSR_SSI_SCR, CCSR_SSI_SCR_SSIEN, 992 regmap_update_bits(regs, CCSR_SSI_SCR, CCSR_SSI_SCR_SSIEN,
993 CCSR_SSI_SCR_SSIEN); 993 CCSR_SSI_SCR_SSIEN);
994 994
995 regmap_write(regs, CCSR_SSI_STMSK, tx_mask); 995 regmap_write(regs, CCSR_SSI_STMSK, ~tx_mask);
996 regmap_write(regs, CCSR_SSI_SRMSK, rx_mask); 996 regmap_write(regs, CCSR_SSI_SRMSK, ~rx_mask);
997 997
998 regmap_update_bits(regs, CCSR_SSI_SCR, CCSR_SSI_SCR_SSIEN, val); 998 regmap_update_bits(regs, CCSR_SSI_SCR, CCSR_SSI_SCR_SSIEN, val);
999 999
@@ -1362,8 +1362,8 @@ static int fsl_ssi_probe(struct platform_device *pdev)
1362 } 1362 }
1363 1363
1364 ssi_private->irq = platform_get_irq(pdev, 0); 1364 ssi_private->irq = platform_get_irq(pdev, 0);
1365 if (ssi_private->irq < 0) { 1365 if (!ssi_private->irq) {
1366 dev_err(&pdev->dev, "no irq for node %s\n", np->full_name); 1366 dev_err(&pdev->dev, "no irq for node %s\n", pdev->name);
1367 return ssi_private->irq; 1367 return ssi_private->irq;
1368 } 1368 }
1369 1369
diff --git a/sound/soc/fsl/fsl_utils.c b/sound/soc/fsl/fsl_utils.c
index 2ac7755da876..b9e42b503a37 100644
--- a/sound/soc/fsl/fsl_utils.c
+++ b/sound/soc/fsl/fsl_utils.c
@@ -86,33 +86,6 @@ int fsl_asoc_get_dma_channel(struct device_node *ssi_np,
86} 86}
87EXPORT_SYMBOL(fsl_asoc_get_dma_channel); 87EXPORT_SYMBOL(fsl_asoc_get_dma_channel);
88 88
89/**
90 * fsl_asoc_xlate_tdm_slot_mask - generate TDM slot TX/RX mask.
91 *
92 * @slots: Number of slots in use.
93 * @tx_mask: bitmask representing active TX slots.
94 * @rx_mask: bitmask representing active RX slots.
95 *
96 * This function used to generate the TDM slot TX/RX mask. And the TX/RX
97 * mask will use a 0 bit for an active slot as default, and the default
98 * active bits are at the LSB of the mask value.
99 */
100int fsl_asoc_xlate_tdm_slot_mask(unsigned int slots,
101 unsigned int *tx_mask,
102 unsigned int *rx_mask)
103{
104 if (!slots)
105 return -EINVAL;
106
107 if (tx_mask)
108 *tx_mask = ~((1 << slots) - 1);
109 if (rx_mask)
110 *rx_mask = ~((1 << slots) - 1);
111
112 return 0;
113}
114EXPORT_SYMBOL_GPL(fsl_asoc_xlate_tdm_slot_mask);
115
116MODULE_AUTHOR("Timur Tabi <timur@freescale.com>"); 89MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
117MODULE_DESCRIPTION("Freescale ASoC utility code"); 90MODULE_DESCRIPTION("Freescale ASoC utility code");
118MODULE_LICENSE("GPL v2"); 91MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/fsl/fsl_utils.h b/sound/soc/fsl/fsl_utils.h
index df535db40313..1687b66ef18e 100644
--- a/sound/soc/fsl/fsl_utils.h
+++ b/sound/soc/fsl/fsl_utils.h
@@ -22,7 +22,4 @@ int fsl_asoc_get_dma_channel(struct device_node *ssi_np, const char *name,
22 struct snd_soc_dai_link *dai, 22 struct snd_soc_dai_link *dai,
23 unsigned int *dma_channel_id, 23 unsigned int *dma_channel_id,
24 unsigned int *dma_id); 24 unsigned int *dma_id);
25int fsl_asoc_xlate_tdm_slot_mask(unsigned int slots,
26 unsigned int *tx_mask,
27 unsigned int *rx_mask);
28#endif /* _FSL_UTILS_H */ 25#endif /* _FSL_UTILS_H */
diff --git a/sound/soc/fsl/imx-mc13783.c b/sound/soc/fsl/imx-mc13783.c
index 6bf5bce01a92..9e6493d4e7ff 100644
--- a/sound/soc/fsl/imx-mc13783.c
+++ b/sound/soc/fsl/imx-mc13783.c
@@ -37,8 +37,7 @@ static int imx_mc13783_hifi_hw_params(struct snd_pcm_substream *substream,
37 struct snd_soc_dai *codec_dai = rtd->codec_dai; 37 struct snd_soc_dai *codec_dai = rtd->codec_dai;
38 int ret; 38 int ret;
39 39
40 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xfffffffc, 0xfffffffc, 40 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 0x3, 4, 16);
41 4, 16);
42 if (ret) 41 if (ret)
43 return ret; 42 return ret;
44 43
@@ -46,7 +45,7 @@ static int imx_mc13783_hifi_hw_params(struct snd_pcm_substream *substream,
46 if (ret) 45 if (ret)
47 return ret; 46 return ret;
48 47
49 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x0, 0xfffffffc, 2, 16); 48 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 2, 16);
50 if (ret) 49 if (ret)
51 return ret; 50 return ret;
52 51
diff --git a/sound/soc/fsl/imx-spdif.c b/sound/soc/fsl/imx-spdif.c
index e94704f1b9ee..33da26a12457 100644
--- a/sound/soc/fsl/imx-spdif.c
+++ b/sound/soc/fsl/imx-spdif.c
@@ -60,6 +60,7 @@ static int imx_spdif_audio_probe(struct platform_device *pdev)
60 data->card.dev = &pdev->dev; 60 data->card.dev = &pdev->dev;
61 data->card.dai_link = &data->dai; 61 data->card.dai_link = &data->dai;
62 data->card.num_links = 1; 62 data->card.num_links = 1;
63 data->card.owner = THIS_MODULE;
63 64
64 ret = snd_soc_of_parse_card_name(&data->card, "model"); 65 ret = snd_soc_of_parse_card_name(&data->card, "model");
65 if (ret) 66 if (ret)
diff --git a/sound/soc/fsl/imx-ssi.c b/sound/soc/fsl/imx-ssi.c
index fa801e17c51e..461ce27b884f 100644
--- a/sound/soc/fsl/imx-ssi.c
+++ b/sound/soc/fsl/imx-ssi.c
@@ -74,8 +74,8 @@ static int imx_ssi_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai,
74 sccr |= SSI_STCCR_DC(slots - 1); 74 sccr |= SSI_STCCR_DC(slots - 1);
75 writel(sccr, ssi->base + SSI_SRCCR); 75 writel(sccr, ssi->base + SSI_SRCCR);
76 76
77 writel(tx_mask, ssi->base + SSI_STMSK); 77 writel(~tx_mask, ssi->base + SSI_STMSK);
78 writel(rx_mask, ssi->base + SSI_SRMSK); 78 writel(~rx_mask, ssi->base + SSI_SRMSK);
79 79
80 return 0; 80 return 0;
81} 81}
@@ -340,7 +340,6 @@ static const struct snd_soc_dai_ops imx_ssi_pcm_dai_ops = {
340 .set_fmt = imx_ssi_set_dai_fmt, 340 .set_fmt = imx_ssi_set_dai_fmt,
341 .set_clkdiv = imx_ssi_set_dai_clkdiv, 341 .set_clkdiv = imx_ssi_set_dai_clkdiv,
342 .set_sysclk = imx_ssi_set_dai_sysclk, 342 .set_sysclk = imx_ssi_set_dai_sysclk,
343 .xlate_tdm_slot_mask = fsl_asoc_xlate_tdm_slot_mask,
344 .set_tdm_slot = imx_ssi_set_dai_tdm_slot, 343 .set_tdm_slot = imx_ssi_set_dai_tdm_slot,
345 .trigger = imx_ssi_trigger, 344 .trigger = imx_ssi_trigger,
346}; 345};
diff --git a/sound/soc/fsl/mx27vis-aic32x4.c b/sound/soc/fsl/mx27vis-aic32x4.c
index b1ced7b8d80c..198eeb3f3f7a 100644
--- a/sound/soc/fsl/mx27vis-aic32x4.c
+++ b/sound/soc/fsl/mx27vis-aic32x4.c
@@ -55,16 +55,6 @@ static int mx27vis_aic32x4_hw_params(struct snd_pcm_substream *substream,
55 struct snd_soc_dai *codec_dai = rtd->codec_dai; 55 struct snd_soc_dai *codec_dai = rtd->codec_dai;
56 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 56 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
57 int ret; 57 int ret;
58 u32 dai_format;
59
60 dai_format = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
61 SND_SOC_DAIFMT_CBM_CFM;
62
63 /* set codec DAI configuration */
64 snd_soc_dai_set_fmt(codec_dai, dai_format);
65
66 /* set cpu DAI configuration */
67 snd_soc_dai_set_fmt(cpu_dai, dai_format);
68 58
69 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 59 ret = snd_soc_dai_set_sysclk(codec_dai, 0,
70 25000000, SND_SOC_CLOCK_OUT); 60 25000000, SND_SOC_CLOCK_OUT);
@@ -164,6 +154,8 @@ static struct snd_soc_dai_link mx27vis_aic32x4_dai = {
164 .platform_name = "imx-ssi.0", 154 .platform_name = "imx-ssi.0",
165 .codec_name = "tlv320aic32x4.0-0018", 155 .codec_name = "tlv320aic32x4.0-0018",
166 .cpu_dai_name = "imx-ssi.0", 156 .cpu_dai_name = "imx-ssi.0",
157 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
158 SND_SOC_DAIFMT_CBM_CFM,
167 .ops = &mx27vis_aic32x4_snd_ops, 159 .ops = &mx27vis_aic32x4_snd_ops,
168}; 160};
169 161
diff --git a/sound/soc/fsl/wm1133-ev1.c b/sound/soc/fsl/wm1133-ev1.c
index 804749a6c61e..a958937ab405 100644
--- a/sound/soc/fsl/wm1133-ev1.c
+++ b/sound/soc/fsl/wm1133-ev1.c
@@ -87,7 +87,6 @@ static int wm1133_ev1_hw_params(struct snd_pcm_substream *substream,
87 snd_pcm_format_t format = params_format(params); 87 snd_pcm_format_t format = params_format(params);
88 unsigned int rate = params_rate(params); 88 unsigned int rate = params_rate(params);
89 unsigned int channels = params_channels(params); 89 unsigned int channels = params_channels(params);
90 u32 dai_format;
91 90
92 /* find the correct audio parameters */ 91 /* find the correct audio parameters */
93 for (i = 0; i < ARRAY_SIZE(wm8350_audio); i++) { 92 for (i = 0; i < ARRAY_SIZE(wm8350_audio); i++) {
@@ -104,22 +103,13 @@ static int wm1133_ev1_hw_params(struct snd_pcm_substream *substream,
104 /* codec FLL input is 14.75 MHz from MCLK */ 103 /* codec FLL input is 14.75 MHz from MCLK */
105 snd_soc_dai_set_pll(codec_dai, 0, 0, 14750000, wm8350_audio[i].sysclk); 104 snd_soc_dai_set_pll(codec_dai, 0, 0, 14750000, wm8350_audio[i].sysclk);
106 105
107 dai_format = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
108 SND_SOC_DAIFMT_CBM_CFM;
109
110 /* set codec DAI configuration */
111 snd_soc_dai_set_fmt(codec_dai, dai_format);
112
113 /* set cpu DAI configuration */
114 snd_soc_dai_set_fmt(cpu_dai, dai_format);
115
116 /* TODO: The SSI driver should figure this out for us */ 106 /* TODO: The SSI driver should figure this out for us */
117 switch (channels) { 107 switch (channels) {
118 case 2: 108 case 2:
119 snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0); 109 snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 2, 0);
120 break; 110 break;
121 case 1: 111 case 1:
122 snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffe, 0xffffffe, 1, 0); 112 snd_soc_dai_set_tdm_slot(cpu_dai, 0x1, 0x1, 1, 0);
123 break; 113 break;
124 default: 114 default:
125 return -EINVAL; 115 return -EINVAL;
@@ -244,6 +234,8 @@ static struct snd_soc_dai_link wm1133_ev1_dai = {
244 .init = wm1133_ev1_init, 234 .init = wm1133_ev1_init,
245 .ops = &wm1133_ev1_ops, 235 .ops = &wm1133_ev1_ops,
246 .symmetric_rates = 1, 236 .symmetric_rates = 1,
237 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
238 SND_SOC_DAIFMT_CBM_CFM,
247}; 239};
248 240
249static struct snd_soc_card wm1133_ev1 = { 241static struct snd_soc_card wm1133_ev1 = {
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 7fe3009b1c43..f7c6734bd5da 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -39,6 +39,37 @@ struct simple_card_data {
39#define simple_priv_to_link(priv, i) ((priv)->snd_card.dai_link + i) 39#define simple_priv_to_link(priv, i) ((priv)->snd_card.dai_link + i)
40#define simple_priv_to_props(priv, i) ((priv)->dai_props + i) 40#define simple_priv_to_props(priv, i) ((priv)->dai_props + i)
41 41
42static int asoc_simple_card_startup(struct snd_pcm_substream *substream)
43{
44 struct snd_soc_pcm_runtime *rtd = substream->private_data;
45 struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
46 struct simple_dai_props *dai_props =
47 &priv->dai_props[rtd - rtd->card->rtd];
48 int ret;
49
50 ret = clk_prepare_enable(dai_props->cpu_dai.clk);
51 if (ret)
52 return ret;
53
54 ret = clk_prepare_enable(dai_props->codec_dai.clk);
55 if (ret)
56 clk_disable_unprepare(dai_props->cpu_dai.clk);
57
58 return ret;
59}
60
61static void asoc_simple_card_shutdown(struct snd_pcm_substream *substream)
62{
63 struct snd_soc_pcm_runtime *rtd = substream->private_data;
64 struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
65 struct simple_dai_props *dai_props =
66 &priv->dai_props[rtd - rtd->card->rtd];
67
68 clk_disable_unprepare(dai_props->cpu_dai.clk);
69
70 clk_disable_unprepare(dai_props->codec_dai.clk);
71}
72
42static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream, 73static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream,
43 struct snd_pcm_hw_params *params) 74 struct snd_pcm_hw_params *params)
44{ 75{
@@ -58,6 +89,8 @@ static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream,
58} 89}
59 90
60static struct snd_soc_ops asoc_simple_card_ops = { 91static struct snd_soc_ops asoc_simple_card_ops = {
92 .startup = asoc_simple_card_startup,
93 .shutdown = asoc_simple_card_shutdown,
61 .hw_params = asoc_simple_card_hw_params, 94 .hw_params = asoc_simple_card_hw_params,
62}; 95};
63 96
@@ -219,6 +252,7 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
219 } 252 }
220 253
221 dai->sysclk = clk_get_rate(clk); 254 dai->sysclk = clk_get_rate(clk);
255 dai->clk = clk;
222 } else if (!of_property_read_u32(np, "system-clock-frequency", &val)) { 256 } else if (!of_property_read_u32(np, "system-clock-frequency", &val)) {
223 dai->sysclk = val; 257 dai->sysclk = val;
224 } else { 258 } else {
diff --git a/sound/soc/intel/broadwell.c b/sound/soc/intel/broadwell.c
index 7cf95d5d5d80..9cf7d01479ad 100644
--- a/sound/soc/intel/broadwell.c
+++ b/sound/soc/intel/broadwell.c
@@ -140,8 +140,6 @@ static struct snd_soc_ops broadwell_rt286_ops = {
140 140
141static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd) 141static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd)
142{ 142{
143 struct snd_soc_codec *codec = rtd->codec;
144 struct snd_soc_dapm_context *dapm = &codec->dapm;
145 struct sst_pdata *pdata = dev_get_platdata(rtd->platform->dev); 143 struct sst_pdata *pdata = dev_get_platdata(rtd->platform->dev);
146 struct sst_hsw *broadwell = pdata->dsp; 144 struct sst_hsw *broadwell = pdata->dsp;
147 int ret; 145 int ret;
@@ -155,14 +153,6 @@ static int broadwell_rtd_init(struct snd_soc_pcm_runtime *rtd)
155 return ret; 153 return ret;
156 } 154 }
157 155
158 /* always connected - check HP for jack detect */
159 snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
160 snd_soc_dapm_enable_pin(dapm, "Speaker");
161 snd_soc_dapm_enable_pin(dapm, "Mic Jack");
162 snd_soc_dapm_enable_pin(dapm, "Line Jack");
163 snd_soc_dapm_enable_pin(dapm, "DMIC1");
164 snd_soc_dapm_enable_pin(dapm, "DMIC2");
165
166 return 0; 156 return 0;
167} 157}
168 158
diff --git a/sound/soc/intel/byt-rt5640.c b/sound/soc/intel/byt-rt5640.c
index 0cba7830c5e9..354eaad886e1 100644
--- a/sound/soc/intel/byt-rt5640.c
+++ b/sound/soc/intel/byt-rt5640.c
@@ -132,7 +132,6 @@ static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
132{ 132{
133 int ret; 133 int ret;
134 struct snd_soc_codec *codec = runtime->codec; 134 struct snd_soc_codec *codec = runtime->codec;
135 struct snd_soc_dapm_context *dapm = &codec->dapm;
136 struct snd_soc_card *card = runtime->card; 135 struct snd_soc_card *card = runtime->card;
137 const struct snd_soc_dapm_route *custom_map; 136 const struct snd_soc_dapm_route *custom_map;
138 int num_routes; 137 int num_routes;
@@ -161,7 +160,7 @@ static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
161 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map); 160 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
162 } 161 }
163 162
164 ret = snd_soc_dapm_add_routes(dapm, custom_map, num_routes); 163 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
165 if (ret) 164 if (ret)
166 return ret; 165 return ret;
167 166
@@ -171,13 +170,8 @@ static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
171 return ret; 170 return ret;
172 } 171 }
173 172
174 snd_soc_dapm_ignore_suspend(dapm, "HPOL"); 173 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
175 snd_soc_dapm_ignore_suspend(dapm, "HPOR"); 174 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
176
177 snd_soc_dapm_ignore_suspend(dapm, "SPOLP");
178 snd_soc_dapm_ignore_suspend(dapm, "SPOLN");
179 snd_soc_dapm_ignore_suspend(dapm, "SPORP");
180 snd_soc_dapm_ignore_suspend(dapm, "SPORN");
181 175
182 return ret; 176 return ret;
183} 177}
diff --git a/sound/soc/intel/cht_bsw_rt5672.c b/sound/soc/intel/cht_bsw_rt5672.c
index a406c6104897..ff016621583a 100644
--- a/sound/soc/intel/cht_bsw_rt5672.c
+++ b/sound/soc/intel/cht_bsw_rt5672.c
@@ -140,6 +140,7 @@ static int cht_codec_init(struct snd_soc_pcm_runtime *runtime)
140{ 140{
141 int ret; 141 int ret;
142 struct snd_soc_dai *codec_dai = runtime->codec_dai; 142 struct snd_soc_dai *codec_dai = runtime->codec_dai;
143 struct snd_soc_codec *codec = codec_dai->codec;
143 144
144 /* TDM 4 slots 24 bit, set Rx & Tx bitmask to 4 active slots */ 145 /* TDM 4 slots 24 bit, set Rx & Tx bitmask to 4 active slots */
145 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0xF, 4, 24); 146 ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xF, 0xF, 4, 24);
@@ -148,6 +149,19 @@ static int cht_codec_init(struct snd_soc_pcm_runtime *runtime)
148 return ret; 149 return ret;
149 } 150 }
150 151
152 /* Select codec ASRC clock source to track I2S1 clock, because codec
153 * is in slave mode and 100fs I2S format (BCLK = 100 * LRCLK) cannot
154 * be supported by RT5672. Otherwise, ASRC will be disabled and cause
155 * noise.
156 */
157 rt5670_sel_asrc_clk_src(codec,
158 RT5670_DA_STEREO_FILTER
159 | RT5670_DA_MONO_L_FILTER
160 | RT5670_DA_MONO_R_FILTER
161 | RT5670_AD_STEREO_FILTER
162 | RT5670_AD_MONO_L_FILTER
163 | RT5670_AD_MONO_R_FILTER,
164 RT5670_CLK_SEL_I2S1_ASRC);
151 return 0; 165 return 0;
152} 166}
153 167
diff --git a/sound/soc/intel/sst-baytrail-pcm.c b/sound/soc/intel/sst-baytrail-pcm.c
index 3bb6288d8b4d..224c49c9f135 100644
--- a/sound/soc/intel/sst-baytrail-pcm.c
+++ b/sound/soc/intel/sst-baytrail-pcm.c
@@ -320,11 +320,6 @@ static struct snd_pcm_ops sst_byt_pcm_ops = {
320 .mmap = sst_byt_pcm_mmap, 320 .mmap = sst_byt_pcm_mmap,
321}; 321};
322 322
323static void sst_byt_pcm_free(struct snd_pcm *pcm)
324{
325 snd_pcm_lib_preallocate_free_for_all(pcm);
326}
327
328static int sst_byt_pcm_new(struct snd_soc_pcm_runtime *rtd) 323static int sst_byt_pcm_new(struct snd_soc_pcm_runtime *rtd)
329{ 324{
330 struct snd_pcm *pcm = rtd->pcm; 325 struct snd_pcm *pcm = rtd->pcm;
@@ -403,7 +398,6 @@ static struct snd_soc_platform_driver byt_soc_platform = {
403 .remove = sst_byt_pcm_remove, 398 .remove = sst_byt_pcm_remove,
404 .ops = &sst_byt_pcm_ops, 399 .ops = &sst_byt_pcm_ops,
405 .pcm_new = sst_byt_pcm_new, 400 .pcm_new = sst_byt_pcm_new,
406 .pcm_free = sst_byt_pcm_free,
407}; 401};
408 402
409static const struct snd_soc_component_driver byt_dai_component = { 403static const struct snd_soc_component_driver byt_dai_component = {
diff --git a/sound/soc/intel/sst-dsp.c b/sound/soc/intel/sst-dsp.c
index 86e410845670..64e94212d2d2 100644
--- a/sound/soc/intel/sst-dsp.c
+++ b/sound/soc/intel/sst-dsp.c
@@ -410,8 +410,7 @@ void sst_dsp_free(struct sst_dsp *sst)
410 if (sst->ops->free) 410 if (sst->ops->free)
411 sst->ops->free(sst); 411 sst->ops->free(sst);
412 412
413 if (sst->dma) 413 sst_dma_free(sst->dma);
414 sst_dma_free(sst->dma);
415} 414}
416EXPORT_SYMBOL_GPL(sst_dsp_free); 415EXPORT_SYMBOL_GPL(sst_dsp_free);
417 416
diff --git a/sound/soc/intel/sst-firmware.c b/sound/soc/intel/sst-firmware.c
index a2ae2c5f2e9f..5f71ef607a57 100644
--- a/sound/soc/intel/sst-firmware.c
+++ b/sound/soc/intel/sst-firmware.c
@@ -791,6 +791,7 @@ int sst_module_alloc_blocks(struct sst_module *module)
791 struct sst_block_allocator ba; 791 struct sst_block_allocator ba;
792 int ret; 792 int ret;
793 793
794 memset(&ba, 0, sizeof(ba));
794 ba.size = module->size; 795 ba.size = module->size;
795 ba.type = module->type; 796 ba.type = module->type;
796 ba.offset = module->offset; 797 ba.offset = module->offset;
@@ -864,6 +865,7 @@ int sst_module_runtime_alloc_blocks(struct sst_module_runtime *runtime,
864 if (module->persistent_size == 0) 865 if (module->persistent_size == 0)
865 return 0; 866 return 0;
866 867
868 memset(&ba, 0, sizeof(ba));
867 ba.size = module->persistent_size; 869 ba.size = module->persistent_size;
868 ba.type = SST_MEM_DRAM; 870 ba.type = SST_MEM_DRAM;
869 871
diff --git a/sound/soc/intel/sst-haswell-dsp.c b/sound/soc/intel/sst-haswell-dsp.c
index 57039b00efc2..c42ffae5fe9f 100644
--- a/sound/soc/intel/sst-haswell-dsp.c
+++ b/sound/soc/intel/sst-haswell-dsp.c
@@ -306,7 +306,7 @@ static void hsw_reset(struct sst_dsp *sst)
306static int hsw_set_dsp_D0(struct sst_dsp *sst) 306static int hsw_set_dsp_D0(struct sst_dsp *sst)
307{ 307{
308 int tries = 10; 308 int tries = 10;
309 u32 reg; 309 u32 reg, fw_dump_bit;
310 310
311 /* Disable core clock gating (VDRTCTL2.DCLCGE = 0) */ 311 /* Disable core clock gating (VDRTCTL2.DCLCGE = 0) */
312 reg = readl(sst->addr.pci_cfg + SST_VDRTCTL2); 312 reg = readl(sst->addr.pci_cfg + SST_VDRTCTL2);
@@ -368,7 +368,9 @@ finish:
368 can't be accessed, please enable each block before accessing. */ 368 can't be accessed, please enable each block before accessing. */
369 reg = readl(sst->addr.pci_cfg + SST_VDRTCTL0); 369 reg = readl(sst->addr.pci_cfg + SST_VDRTCTL0);
370 reg |= SST_VDRTCL0_DSRAMPGE_MASK | SST_VDRTCL0_ISRAMPGE_MASK; 370 reg |= SST_VDRTCL0_DSRAMPGE_MASK | SST_VDRTCL0_ISRAMPGE_MASK;
371 writel(reg, sst->addr.pci_cfg + SST_VDRTCTL0); 371 /* for D0, always enable the block(DSRAM[0]) used for FW dump */
372 fw_dump_bit = 1 << SST_VDRTCL0_DSRAMPGE_SHIFT;
373 writel(reg & ~fw_dump_bit, sst->addr.pci_cfg + SST_VDRTCTL0);
372 374
373 375
374 /* disable DMA finish function for SSP0 & SSP1 */ 376 /* disable DMA finish function for SSP0 & SSP1 */
@@ -491,6 +493,7 @@ static const struct sst_sram_shift sram_shift[] = {
491 {SST_DEV_ID_LYNX_POINT, 6, 16}, /* lp */ 493 {SST_DEV_ID_LYNX_POINT, 6, 16}, /* lp */
492 {SST_DEV_ID_WILDCAT_POINT, 2, 12}, /* wpt */ 494 {SST_DEV_ID_WILDCAT_POINT, 2, 12}, /* wpt */
493}; 495};
496
494static u32 hsw_block_get_bit(struct sst_mem_block *block) 497static u32 hsw_block_get_bit(struct sst_mem_block *block)
495{ 498{
496 u32 bit = 0, shift = 0, index; 499 u32 bit = 0, shift = 0, index;
@@ -587,7 +590,9 @@ static int hsw_block_disable(struct sst_mem_block *block)
587 590
588 val = readl(sst->addr.pci_cfg + SST_VDRTCTL0); 591 val = readl(sst->addr.pci_cfg + SST_VDRTCTL0);
589 bit = hsw_block_get_bit(block); 592 bit = hsw_block_get_bit(block);
590 writel(val | bit, sst->addr.pci_cfg + SST_VDRTCTL0); 593 /* don't disable DSRAM[0], keep it always enable for FW dump*/
594 if (bit != (1 << SST_VDRTCL0_DSRAMPGE_SHIFT))
595 writel(val | bit, sst->addr.pci_cfg + SST_VDRTCTL0);
591 596
592 /* wait 18 DSP clock ticks */ 597 /* wait 18 DSP clock ticks */
593 udelay(10); 598 udelay(10);
@@ -612,7 +617,7 @@ static int hsw_init(struct sst_dsp *sst, struct sst_pdata *pdata)
612 const struct sst_adsp_memregion *region; 617 const struct sst_adsp_memregion *region;
613 struct device *dev; 618 struct device *dev;
614 int ret = -ENODEV, i, j, region_count; 619 int ret = -ENODEV, i, j, region_count;
615 u32 offset, size; 620 u32 offset, size, fw_dump_bit;
616 621
617 dev = sst->dma_dev; 622 dev = sst->dma_dev;
618 623
@@ -669,9 +674,11 @@ static int hsw_init(struct sst_dsp *sst, struct sst_pdata *pdata)
669 } 674 }
670 } 675 }
671 676
677 /* always enable the block(DSRAM[0]) used for FW dump */
678 fw_dump_bit = 1 << SST_VDRTCL0_DSRAMPGE_SHIFT;
672 /* set default power gating control, enable power gating control for all blocks. that is, 679 /* set default power gating control, enable power gating control for all blocks. that is,
673 can't be accessed, please enable each block before accessing. */ 680 can't be accessed, please enable each block before accessing. */
674 writel(0xffffffff, sst->addr.pci_cfg + SST_VDRTCTL0); 681 writel(0xffffffff & ~fw_dump_bit, sst->addr.pci_cfg + SST_VDRTCTL0);
675 682
676 return 0; 683 return 0;
677} 684}
diff --git a/sound/soc/intel/sst-haswell-ipc.c b/sound/soc/intel/sst-haswell-ipc.c
index 5bf14040c24a..a282179a3064 100644
--- a/sound/soc/intel/sst-haswell-ipc.c
+++ b/sound/soc/intel/sst-haswell-ipc.c
@@ -94,6 +94,8 @@
94/* Mailbox */ 94/* Mailbox */
95#define IPC_MAX_MAILBOX_BYTES 256 95#define IPC_MAX_MAILBOX_BYTES 256
96 96
97#define INVALID_STREAM_HW_ID 0xffffffff
98
97/* Global Message - Types and Replies */ 99/* Global Message - Types and Replies */
98enum ipc_glb_type { 100enum ipc_glb_type {
99 IPC_GLB_GET_FW_VERSION = 0, /* Retrieves firmware version */ 101 IPC_GLB_GET_FW_VERSION = 0, /* Retrieves firmware version */
@@ -275,7 +277,6 @@ struct sst_hsw {
275 /* FW config */ 277 /* FW config */
276 struct sst_hsw_ipc_fw_ready fw_ready; 278 struct sst_hsw_ipc_fw_ready fw_ready;
277 struct sst_hsw_ipc_fw_version version; 279 struct sst_hsw_ipc_fw_version version;
278 struct sst_module *scratch;
279 bool fw_done; 280 bool fw_done;
280 struct sst_fw *sst_fw; 281 struct sst_fw *sst_fw;
281 282
@@ -651,11 +652,11 @@ static void hsw_notification_work(struct work_struct *work)
651 } 652 }
652 653
653 /* tell DSP that notification has been handled */ 654 /* tell DSP that notification has been handled */
654 sst_dsp_shim_update_bits_unlocked(hsw->dsp, SST_IPCD, 655 sst_dsp_shim_update_bits(hsw->dsp, SST_IPCD,
655 SST_IPCD_BUSY | SST_IPCD_DONE, SST_IPCD_DONE); 656 SST_IPCD_BUSY | SST_IPCD_DONE, SST_IPCD_DONE);
656 657
657 /* unmask busy interrupt */ 658 /* unmask busy interrupt */
658 sst_dsp_shim_update_bits_unlocked(hsw->dsp, SST_IMRX, SST_IMRX_BUSY, 0); 659 sst_dsp_shim_update_bits(hsw->dsp, SST_IMRX, SST_IMRX_BUSY, 0);
659} 660}
660 661
661static struct ipc_message *reply_find_msg(struct sst_hsw *hsw, u32 header) 662static struct ipc_message *reply_find_msg(struct sst_hsw *hsw, u32 header)
@@ -1208,6 +1209,7 @@ struct sst_hsw_stream *sst_hsw_stream_new(struct sst_hsw *hsw, int id,
1208 return NULL; 1209 return NULL;
1209 1210
1210 spin_lock_irqsave(&sst->spinlock, flags); 1211 spin_lock_irqsave(&sst->spinlock, flags);
1212 stream->reply.stream_hw_id = INVALID_STREAM_HW_ID;
1211 list_add(&stream->node, &hsw->stream_list); 1213 list_add(&stream->node, &hsw->stream_list);
1212 stream->notify_position = notify_position; 1214 stream->notify_position = notify_position;
1213 stream->pdata = data; 1215 stream->pdata = data;
@@ -2132,7 +2134,6 @@ void sst_hsw_dsp_free(struct device *dev, struct sst_pdata *pdata)
2132 dma_free_coherent(hsw->dsp->dma_dev, SST_HSW_DX_CONTEXT_SIZE, 2134 dma_free_coherent(hsw->dsp->dma_dev, SST_HSW_DX_CONTEXT_SIZE,
2133 hsw->dx_context, hsw->dx_context_paddr); 2135 hsw->dx_context, hsw->dx_context_paddr);
2134 sst_dsp_free(hsw->dsp); 2136 sst_dsp_free(hsw->dsp);
2135 kfree(hsw->scratch);
2136 kthread_stop(hsw->tx_thread); 2137 kthread_stop(hsw->tx_thread);
2137 kfree(hsw->msg); 2138 kfree(hsw->msg);
2138} 2139}
diff --git a/sound/soc/intel/sst-haswell-pcm.c b/sound/soc/intel/sst-haswell-pcm.c
index 619525200705..ad7f4a51e138 100644
--- a/sound/soc/intel/sst-haswell-pcm.c
+++ b/sound/soc/intel/sst-haswell-pcm.c
@@ -78,7 +78,6 @@ static const u32 volume_map[] = {
78#define HSW_PCM_DAI_ID_OFFLOAD0 1 78#define HSW_PCM_DAI_ID_OFFLOAD0 1
79#define HSW_PCM_DAI_ID_OFFLOAD1 2 79#define HSW_PCM_DAI_ID_OFFLOAD1 2
80#define HSW_PCM_DAI_ID_LOOPBACK 3 80#define HSW_PCM_DAI_ID_LOOPBACK 3
81#define HSW_PCM_DAI_ID_CAPTURE 4
82 81
83 82
84static const struct snd_pcm_hardware hsw_pcm_hardware = { 83static const struct snd_pcm_hardware hsw_pcm_hardware = {
@@ -99,6 +98,7 @@ static const struct snd_pcm_hardware hsw_pcm_hardware = {
99 98
100struct hsw_pcm_module_map { 99struct hsw_pcm_module_map {
101 int dai_id; 100 int dai_id;
101 int stream;
102 enum sst_hsw_module_id mod_id; 102 enum sst_hsw_module_id mod_id;
103}; 103};
104 104
@@ -135,7 +135,17 @@ struct hsw_priv_data {
135 struct snd_dma_buffer dmab[HSW_PCM_COUNT][2]; 135 struct snd_dma_buffer dmab[HSW_PCM_COUNT][2];
136 136
137 /* DAI data */ 137 /* DAI data */
138 struct hsw_pcm_data pcm[HSW_PCM_COUNT]; 138 struct hsw_pcm_data pcm[HSW_PCM_COUNT][2];
139};
140
141
142/* static mappings between PCMs and modules - may be dynamic in future */
143static struct hsw_pcm_module_map mod_map[] = {
144 {HSW_PCM_DAI_ID_SYSTEM, 0, SST_HSW_MODULE_PCM_SYSTEM},
145 {HSW_PCM_DAI_ID_OFFLOAD0, 0, SST_HSW_MODULE_PCM},
146 {HSW_PCM_DAI_ID_OFFLOAD1, 0, SST_HSW_MODULE_PCM},
147 {HSW_PCM_DAI_ID_LOOPBACK, 1, SST_HSW_MODULE_PCM_REFERENCE},
148 {HSW_PCM_DAI_ID_SYSTEM, 1, SST_HSW_MODULE_PCM_CAPTURE},
139}; 149};
140 150
141static u32 hsw_notify_pointer(struct sst_hsw_stream *stream, void *data); 151static u32 hsw_notify_pointer(struct sst_hsw_stream *stream, void *data);
@@ -168,9 +178,14 @@ static int hsw_stream_volume_put(struct snd_kcontrol *kcontrol,
168 (struct soc_mixer_control *)kcontrol->private_value; 178 (struct soc_mixer_control *)kcontrol->private_value;
169 struct hsw_priv_data *pdata = 179 struct hsw_priv_data *pdata =
170 snd_soc_platform_get_drvdata(platform); 180 snd_soc_platform_get_drvdata(platform);
171 struct hsw_pcm_data *pcm_data = &pdata->pcm[mc->reg]; 181 struct hsw_pcm_data *pcm_data;
172 struct sst_hsw *hsw = pdata->hsw; 182 struct sst_hsw *hsw = pdata->hsw;
173 u32 volume; 183 u32 volume;
184 int dai, stream;
185
186 dai = mod_map[mc->reg].dai_id;
187 stream = mod_map[mc->reg].stream;
188 pcm_data = &pdata->pcm[dai][stream];
174 189
175 mutex_lock(&pcm_data->mutex); 190 mutex_lock(&pcm_data->mutex);
176 pm_runtime_get_sync(pdata->dev); 191 pm_runtime_get_sync(pdata->dev);
@@ -212,9 +227,14 @@ static int hsw_stream_volume_get(struct snd_kcontrol *kcontrol,
212 (struct soc_mixer_control *)kcontrol->private_value; 227 (struct soc_mixer_control *)kcontrol->private_value;
213 struct hsw_priv_data *pdata = 228 struct hsw_priv_data *pdata =
214 snd_soc_platform_get_drvdata(platform); 229 snd_soc_platform_get_drvdata(platform);
215 struct hsw_pcm_data *pcm_data = &pdata->pcm[mc->reg]; 230 struct hsw_pcm_data *pcm_data;
216 struct sst_hsw *hsw = pdata->hsw; 231 struct sst_hsw *hsw = pdata->hsw;
217 u32 volume; 232 u32 volume;
233 int dai, stream;
234
235 dai = mod_map[mc->reg].dai_id;
236 stream = mod_map[mc->reg].stream;
237 pcm_data = &pdata->pcm[dai][stream];
218 238
219 mutex_lock(&pcm_data->mutex); 239 mutex_lock(&pcm_data->mutex);
220 pm_runtime_get_sync(pdata->dev); 240 pm_runtime_get_sync(pdata->dev);
@@ -309,7 +329,7 @@ static const struct snd_kcontrol_new hsw_volume_controls[] = {
309 ARRAY_SIZE(volume_map) - 1, 0, 329 ARRAY_SIZE(volume_map) - 1, 0,
310 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv), 330 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
311 /* Mic Capture volume */ 331 /* Mic Capture volume */
312 SOC_DOUBLE_EXT_TLV("Mic Capture Volume", 0, 0, 8, 332 SOC_DOUBLE_EXT_TLV("Mic Capture Volume", 4, 0, 8,
313 ARRAY_SIZE(volume_map) - 1, 0, 333 ARRAY_SIZE(volume_map) - 1, 0,
314 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv), 334 hsw_stream_volume_get, hsw_stream_volume_put, hsw_vol_tlv),
315}; 335};
@@ -353,7 +373,7 @@ static int hsw_pcm_hw_params(struct snd_pcm_substream *substream,
353 struct snd_pcm_runtime *runtime = substream->runtime; 373 struct snd_pcm_runtime *runtime = substream->runtime;
354 struct hsw_priv_data *pdata = 374 struct hsw_priv_data *pdata =
355 snd_soc_platform_get_drvdata(rtd->platform); 375 snd_soc_platform_get_drvdata(rtd->platform);
356 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd); 376 struct hsw_pcm_data *pcm_data;
357 struct sst_hsw *hsw = pdata->hsw; 377 struct sst_hsw *hsw = pdata->hsw;
358 struct sst_module *module_data; 378 struct sst_module *module_data;
359 struct sst_dsp *dsp; 379 struct sst_dsp *dsp;
@@ -362,7 +382,10 @@ static int hsw_pcm_hw_params(struct snd_pcm_substream *substream,
362 enum sst_hsw_stream_path_id path_id; 382 enum sst_hsw_stream_path_id path_id;
363 u32 rate, bits, map, pages, module_id; 383 u32 rate, bits, map, pages, module_id;
364 u8 channels; 384 u8 channels;
365 int ret; 385 int ret, dai;
386
387 dai = mod_map[rtd->cpu_dai->id].dai_id;
388 pcm_data = &pdata->pcm[dai][substream->stream];
366 389
367 /* check if we are being called a subsequent time */ 390 /* check if we are being called a subsequent time */
368 if (pcm_data->allocated) { 391 if (pcm_data->allocated) {
@@ -552,8 +575,12 @@ static int hsw_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
552 struct snd_soc_pcm_runtime *rtd = substream->private_data; 575 struct snd_soc_pcm_runtime *rtd = substream->private_data;
553 struct hsw_priv_data *pdata = 576 struct hsw_priv_data *pdata =
554 snd_soc_platform_get_drvdata(rtd->platform); 577 snd_soc_platform_get_drvdata(rtd->platform);
555 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd); 578 struct hsw_pcm_data *pcm_data;
556 struct sst_hsw *hsw = pdata->hsw; 579 struct sst_hsw *hsw = pdata->hsw;
580 int dai;
581
582 dai = mod_map[rtd->cpu_dai->id].dai_id;
583 pcm_data = &pdata->pcm[dai][substream->stream];
557 584
558 switch (cmd) { 585 switch (cmd) {
559 case SNDRV_PCM_TRIGGER_START: 586 case SNDRV_PCM_TRIGGER_START:
@@ -597,11 +624,16 @@ static snd_pcm_uframes_t hsw_pcm_pointer(struct snd_pcm_substream *substream)
597 struct snd_pcm_runtime *runtime = substream->runtime; 624 struct snd_pcm_runtime *runtime = substream->runtime;
598 struct hsw_priv_data *pdata = 625 struct hsw_priv_data *pdata =
599 snd_soc_platform_get_drvdata(rtd->platform); 626 snd_soc_platform_get_drvdata(rtd->platform);
600 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd); 627 struct hsw_pcm_data *pcm_data;
601 struct sst_hsw *hsw = pdata->hsw; 628 struct sst_hsw *hsw = pdata->hsw;
602 snd_pcm_uframes_t offset; 629 snd_pcm_uframes_t offset;
603 uint64_t ppos; 630 uint64_t ppos;
604 u32 position = sst_hsw_get_dsp_position(hsw, pcm_data->stream); 631 u32 position;
632 int dai;
633
634 dai = mod_map[rtd->cpu_dai->id].dai_id;
635 pcm_data = &pdata->pcm[dai][substream->stream];
636 position = sst_hsw_get_dsp_position(hsw, pcm_data->stream);
605 637
606 offset = bytes_to_frames(runtime, position); 638 offset = bytes_to_frames(runtime, position);
607 ppos = sst_hsw_get_dsp_presentation_position(hsw, pcm_data->stream); 639 ppos = sst_hsw_get_dsp_presentation_position(hsw, pcm_data->stream);
@@ -618,8 +650,10 @@ static int hsw_pcm_open(struct snd_pcm_substream *substream)
618 snd_soc_platform_get_drvdata(rtd->platform); 650 snd_soc_platform_get_drvdata(rtd->platform);
619 struct hsw_pcm_data *pcm_data; 651 struct hsw_pcm_data *pcm_data;
620 struct sst_hsw *hsw = pdata->hsw; 652 struct sst_hsw *hsw = pdata->hsw;
653 int dai;
621 654
622 pcm_data = &pdata->pcm[rtd->cpu_dai->id]; 655 dai = mod_map[rtd->cpu_dai->id].dai_id;
656 pcm_data = &pdata->pcm[dai][substream->stream];
623 657
624 mutex_lock(&pcm_data->mutex); 658 mutex_lock(&pcm_data->mutex);
625 pm_runtime_get_sync(pdata->dev); 659 pm_runtime_get_sync(pdata->dev);
@@ -648,9 +682,12 @@ static int hsw_pcm_close(struct snd_pcm_substream *substream)
648 struct snd_soc_pcm_runtime *rtd = substream->private_data; 682 struct snd_soc_pcm_runtime *rtd = substream->private_data;
649 struct hsw_priv_data *pdata = 683 struct hsw_priv_data *pdata =
650 snd_soc_platform_get_drvdata(rtd->platform); 684 snd_soc_platform_get_drvdata(rtd->platform);
651 struct hsw_pcm_data *pcm_data = snd_soc_pcm_get_drvdata(rtd); 685 struct hsw_pcm_data *pcm_data;
652 struct sst_hsw *hsw = pdata->hsw; 686 struct sst_hsw *hsw = pdata->hsw;
653 int ret; 687 int ret, dai;
688
689 dai = mod_map[rtd->cpu_dai->id].dai_id;
690 pcm_data = &pdata->pcm[dai][substream->stream];
654 691
655 mutex_lock(&pcm_data->mutex); 692 mutex_lock(&pcm_data->mutex);
656 ret = sst_hsw_stream_reset(hsw, pcm_data->stream); 693 ret = sst_hsw_stream_reset(hsw, pcm_data->stream);
@@ -685,15 +722,6 @@ static struct snd_pcm_ops hsw_pcm_ops = {
685 .page = snd_pcm_sgbuf_ops_page, 722 .page = snd_pcm_sgbuf_ops_page,
686}; 723};
687 724
688/* static mappings between PCMs and modules - may be dynamic in future */
689static struct hsw_pcm_module_map mod_map[] = {
690 {HSW_PCM_DAI_ID_SYSTEM, SST_HSW_MODULE_PCM_SYSTEM},
691 {HSW_PCM_DAI_ID_OFFLOAD0, SST_HSW_MODULE_PCM},
692 {HSW_PCM_DAI_ID_OFFLOAD1, SST_HSW_MODULE_PCM},
693 {HSW_PCM_DAI_ID_LOOPBACK, SST_HSW_MODULE_PCM_REFERENCE},
694 {HSW_PCM_DAI_ID_CAPTURE, SST_HSW_MODULE_PCM_CAPTURE},
695};
696
697static int hsw_pcm_create_modules(struct hsw_priv_data *pdata) 725static int hsw_pcm_create_modules(struct hsw_priv_data *pdata)
698{ 726{
699 struct sst_hsw *hsw = pdata->hsw; 727 struct sst_hsw *hsw = pdata->hsw;
@@ -701,7 +729,7 @@ static int hsw_pcm_create_modules(struct hsw_priv_data *pdata)
701 int i; 729 int i;
702 730
703 for (i = 0; i < ARRAY_SIZE(mod_map); i++) { 731 for (i = 0; i < ARRAY_SIZE(mod_map); i++) {
704 pcm_data = &pdata->pcm[i]; 732 pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream];
705 733
706 /* create new runtime module, use same offset if recreated */ 734 /* create new runtime module, use same offset if recreated */
707 pcm_data->runtime = sst_hsw_runtime_module_create(hsw, 735 pcm_data->runtime = sst_hsw_runtime_module_create(hsw,
@@ -716,7 +744,7 @@ static int hsw_pcm_create_modules(struct hsw_priv_data *pdata)
716 744
717err: 745err:
718 for (--i; i >= 0; i--) { 746 for (--i; i >= 0; i--) {
719 pcm_data = &pdata->pcm[i]; 747 pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream];
720 sst_hsw_runtime_module_free(pcm_data->runtime); 748 sst_hsw_runtime_module_free(pcm_data->runtime);
721 } 749 }
722 750
@@ -729,17 +757,12 @@ static void hsw_pcm_free_modules(struct hsw_priv_data *pdata)
729 int i; 757 int i;
730 758
731 for (i = 0; i < ARRAY_SIZE(mod_map); i++) { 759 for (i = 0; i < ARRAY_SIZE(mod_map); i++) {
732 pcm_data = &pdata->pcm[i]; 760 pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream];
733 761
734 sst_hsw_runtime_module_free(pcm_data->runtime); 762 sst_hsw_runtime_module_free(pcm_data->runtime);
735 } 763 }
736} 764}
737 765
738static void hsw_pcm_free(struct snd_pcm *pcm)
739{
740 snd_pcm_lib_preallocate_free_for_all(pcm);
741}
742
743static int hsw_pcm_new(struct snd_soc_pcm_runtime *rtd) 766static int hsw_pcm_new(struct snd_soc_pcm_runtime *rtd)
744{ 767{
745 struct snd_pcm *pcm = rtd->pcm; 768 struct snd_pcm *pcm = rtd->pcm;
@@ -762,7 +785,10 @@ static int hsw_pcm_new(struct snd_soc_pcm_runtime *rtd)
762 return ret; 785 return ret;
763 } 786 }
764 } 787 }
765 priv_data->pcm[rtd->cpu_dai->id].hsw_pcm = pcm; 788 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream)
789 priv_data->pcm[rtd->cpu_dai->id][SNDRV_PCM_STREAM_PLAYBACK].hsw_pcm = pcm;
790 if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream)
791 priv_data->pcm[rtd->cpu_dai->id][SNDRV_PCM_STREAM_CAPTURE].hsw_pcm = pcm;
766 792
767 return ret; 793 return ret;
768} 794}
@@ -871,10 +897,9 @@ static int hsw_pcm_probe(struct snd_soc_platform *platform)
871 /* allocate DSP buffer page tables */ 897 /* allocate DSP buffer page tables */
872 for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) { 898 for (i = 0; i < ARRAY_SIZE(hsw_dais); i++) {
873 899
874 mutex_init(&priv_data->pcm[i].mutex);
875
876 /* playback */ 900 /* playback */
877 if (hsw_dais[i].playback.channels_min) { 901 if (hsw_dais[i].playback.channels_min) {
902 mutex_init(&priv_data->pcm[i][SNDRV_PCM_STREAM_PLAYBACK].mutex);
878 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dma_dev, 903 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dma_dev,
879 PAGE_SIZE, &priv_data->dmab[i][0]); 904 PAGE_SIZE, &priv_data->dmab[i][0]);
880 if (ret < 0) 905 if (ret < 0)
@@ -883,6 +908,7 @@ static int hsw_pcm_probe(struct snd_soc_platform *platform)
883 908
884 /* capture */ 909 /* capture */
885 if (hsw_dais[i].capture.channels_min) { 910 if (hsw_dais[i].capture.channels_min) {
911 mutex_init(&priv_data->pcm[i][SNDRV_PCM_STREAM_CAPTURE].mutex);
886 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dma_dev, 912 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, dma_dev,
887 PAGE_SIZE, &priv_data->dmab[i][1]); 913 PAGE_SIZE, &priv_data->dmab[i][1]);
888 if (ret < 0) 914 if (ret < 0)
@@ -936,7 +962,6 @@ static struct snd_soc_platform_driver hsw_soc_platform = {
936 .remove = hsw_pcm_remove, 962 .remove = hsw_pcm_remove,
937 .ops = &hsw_pcm_ops, 963 .ops = &hsw_pcm_ops,
938 .pcm_new = hsw_pcm_new, 964 .pcm_new = hsw_pcm_new,
939 .pcm_free = hsw_pcm_free,
940}; 965};
941 966
942static const struct snd_soc_component_driver hsw_dai_component = { 967static const struct snd_soc_component_driver hsw_dai_component = {
@@ -1081,8 +1106,8 @@ static void hsw_pcm_complete(struct device *dev)
1081 return; 1106 return;
1082 } 1107 }
1083 1108
1084 for (i = 0; i < HSW_PCM_DAI_ID_CAPTURE + 1; i++) { 1109 for (i = 0; i < ARRAY_SIZE(mod_map); i++) {
1085 pcm_data = &pdata->pcm[i]; 1110 pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream];
1086 1111
1087 if (!pcm_data->substream) 1112 if (!pcm_data->substream)
1088 continue; 1113 continue;
@@ -1115,8 +1140,8 @@ static int hsw_pcm_prepare(struct device *dev)
1115 if (pdata->pm_state == HSW_PM_STATE_D3) 1140 if (pdata->pm_state == HSW_PM_STATE_D3)
1116 return 0; 1141 return 0;
1117 /* suspend all active streams */ 1142 /* suspend all active streams */
1118 for (i = 0; i < HSW_PCM_DAI_ID_CAPTURE + 1; i++) { 1143 for (i = 0; i < ARRAY_SIZE(mod_map); i++) {
1119 pcm_data = &pdata->pcm[i]; 1144 pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream];
1120 1145
1121 if (!pcm_data->substream) 1146 if (!pcm_data->substream)
1122 continue; 1147 continue;
@@ -1134,8 +1159,8 @@ static int hsw_pcm_prepare(struct device *dev)
1134 sst_hsw_dsp_runtime_suspend(hsw); 1159 sst_hsw_dsp_runtime_suspend(hsw);
1135 1160
1136 /* preserve persistent memory */ 1161 /* preserve persistent memory */
1137 for (i = 0; i < HSW_PCM_DAI_ID_CAPTURE + 1; i++) { 1162 for (i = 0; i < ARRAY_SIZE(mod_map); i++) {
1138 pcm_data = &pdata->pcm[i]; 1163 pcm_data = &pdata->pcm[mod_map[i].dai_id][mod_map[i].stream];
1139 1164
1140 if (!pcm_data->substream) 1165 if (!pcm_data->substream)
1141 continue; 1166 continue;
diff --git a/sound/soc/intel/sst-mfld-platform-pcm.c b/sound/soc/intel/sst-mfld-platform-pcm.c
index 2d80c4e12997..7523cbef8780 100644
--- a/sound/soc/intel/sst-mfld-platform-pcm.c
+++ b/sound/soc/intel/sst-mfld-platform-pcm.c
@@ -643,11 +643,6 @@ static struct snd_pcm_ops sst_platform_ops = {
643 .pointer = sst_platform_pcm_pointer, 643 .pointer = sst_platform_pcm_pointer,
644}; 644};
645 645
646static void sst_pcm_free(struct snd_pcm *pcm)
647{
648 snd_pcm_lib_preallocate_free_for_all(pcm);
649}
650
651static int sst_pcm_new(struct snd_soc_pcm_runtime *rtd) 646static int sst_pcm_new(struct snd_soc_pcm_runtime *rtd)
652{ 647{
653 struct snd_soc_dai *dai = rtd->cpu_dai; 648 struct snd_soc_dai *dai = rtd->cpu_dai;
@@ -678,7 +673,6 @@ static struct snd_soc_platform_driver sst_soc_platform_drv = {
678 .ops = &sst_platform_ops, 673 .ops = &sst_platform_ops,
679 .compr_ops = &sst_platform_compr_ops, 674 .compr_ops = &sst_platform_compr_ops,
680 .pcm_new = sst_pcm_new, 675 .pcm_new = sst_pcm_new,
681 .pcm_free = sst_pcm_free,
682}; 676};
683 677
684static const struct snd_soc_component_driver sst_component = { 678static const struct snd_soc_component_driver sst_component = {
diff --git a/sound/soc/intel/sst/sst_acpi.c b/sound/soc/intel/sst/sst_acpi.c
index c3fbcdec6a15..43bc1c4b9207 100644
--- a/sound/soc/intel/sst/sst_acpi.c
+++ b/sound/soc/intel/sst/sst_acpi.c
@@ -352,6 +352,8 @@ static struct sst_machines sst_acpi_bytcr[] = {
352static struct sst_machines sst_acpi_chv[] = { 352static struct sst_machines sst_acpi_chv[] = {
353 {"10EC5670", "cht-bsw", "cht-bsw-rt5672", NULL, "fw_sst_22a8.bin", 353 {"10EC5670", "cht-bsw", "cht-bsw-rt5672", NULL, "fw_sst_22a8.bin",
354 &chv_platform_data }, 354 &chv_platform_data },
355 {"10EC5645", "cht-bsw", "cht-bsw-rt5645", NULL, "fw_sst_22a8.bin",
356 &chv_platform_data },
355 {}, 357 {},
356}; 358};
357 359
diff --git a/sound/soc/intel/sst/sst_loader.c b/sound/soc/intel/sst/sst_loader.c
index b580f96e25e5..7888cd707853 100644
--- a/sound/soc/intel/sst/sst_loader.c
+++ b/sound/soc/intel/sst/sst_loader.c
@@ -324,8 +324,7 @@ void sst_firmware_load_cb(const struct firmware *fw, void *context)
324 324
325 if (ctx->sst_state != SST_RESET || 325 if (ctx->sst_state != SST_RESET ||
326 ctx->fw_in_mem != NULL) { 326 ctx->fw_in_mem != NULL) {
327 if (fw != NULL) 327 release_firmware(fw);
328 release_firmware(fw);
329 mutex_unlock(&ctx->sst_lock); 328 mutex_unlock(&ctx->sst_lock);
330 return; 329 return;
331 } 330 }
diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c
index d9865082160c..c866ade28ad0 100644
--- a/sound/soc/mxs/mxs-saif.c
+++ b/sound/soc/mxs/mxs-saif.c
@@ -710,7 +710,7 @@ static int mxs_saif_probe(struct platform_device *pdev)
710 struct device_node *np = pdev->dev.of_node; 710 struct device_node *np = pdev->dev.of_node;
711 struct resource *iores; 711 struct resource *iores;
712 struct mxs_saif *saif; 712 struct mxs_saif *saif;
713 int ret = 0; 713 int irq, ret = 0;
714 struct device_node *master; 714 struct device_node *master;
715 715
716 if (!np) 716 if (!np)
@@ -763,16 +763,16 @@ static int mxs_saif_probe(struct platform_device *pdev)
763 if (IS_ERR(saif->base)) 763 if (IS_ERR(saif->base))
764 return PTR_ERR(saif->base); 764 return PTR_ERR(saif->base);
765 765
766 saif->irq = platform_get_irq(pdev, 0); 766 irq = platform_get_irq(pdev, 0);
767 if (saif->irq < 0) { 767 if (irq < 0) {
768 ret = saif->irq; 768 ret = irq;
769 dev_err(&pdev->dev, "failed to get irq resource: %d\n", 769 dev_err(&pdev->dev, "failed to get irq resource: %d\n",
770 ret); 770 ret);
771 return ret; 771 return ret;
772 } 772 }
773 773
774 saif->dev = &pdev->dev; 774 saif->dev = &pdev->dev;
775 ret = devm_request_irq(&pdev->dev, saif->irq, mxs_saif_irq, 0, 775 ret = devm_request_irq(&pdev->dev, irq, mxs_saif_irq, 0,
776 dev_name(&pdev->dev), saif); 776 dev_name(&pdev->dev), saif);
777 if (ret) { 777 if (ret) {
778 dev_err(&pdev->dev, "failed to request irq\n"); 778 dev_err(&pdev->dev, "failed to request irq\n");
diff --git a/sound/soc/mxs/mxs-saif.h b/sound/soc/mxs/mxs-saif.h
index fbaf7badfdfb..9a4c0b291b9e 100644
--- a/sound/soc/mxs/mxs-saif.h
+++ b/sound/soc/mxs/mxs-saif.h
@@ -116,7 +116,6 @@ struct mxs_saif {
116 unsigned int mclk; 116 unsigned int mclk;
117 unsigned int mclk_in_use; 117 unsigned int mclk_in_use;
118 void __iomem *base; 118 void __iomem *base;
119 int irq;
120 unsigned int id; 119 unsigned int id;
121 unsigned int master_id; 120 unsigned int master_id;
122 unsigned int cur_rate; 121 unsigned int cur_rate;
diff --git a/sound/soc/mxs/mxs-sgtl5000.c b/sound/soc/mxs/mxs-sgtl5000.c
index 6f1916b71815..6e6fce6a14ba 100644
--- a/sound/soc/mxs/mxs-sgtl5000.c
+++ b/sound/soc/mxs/mxs-sgtl5000.c
@@ -36,7 +36,7 @@ static int mxs_sgtl5000_hw_params(struct snd_pcm_substream *substream,
36 struct snd_soc_dai *codec_dai = rtd->codec_dai; 36 struct snd_soc_dai *codec_dai = rtd->codec_dai;
37 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 37 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
38 unsigned int rate = params_rate(params); 38 unsigned int rate = params_rate(params);
39 u32 dai_format, mclk; 39 u32 mclk;
40 int ret; 40 int ret;
41 41
42 /* sgtl5000 does not support 512*rate when in 96000 fs */ 42 /* sgtl5000 does not support 512*rate when in 96000 fs */
@@ -65,26 +65,6 @@ static int mxs_sgtl5000_hw_params(struct snd_pcm_substream *substream,
65 return ret; 65 return ret;
66 } 66 }
67 67
68 /* set codec to slave mode */
69 dai_format = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
70 SND_SOC_DAIFMT_CBS_CFS;
71
72 /* set codec DAI configuration */
73 ret = snd_soc_dai_set_fmt(codec_dai, dai_format);
74 if (ret) {
75 dev_err(codec_dai->dev, "Failed to set dai format to %08x\n",
76 dai_format);
77 return ret;
78 }
79
80 /* set cpu DAI configuration */
81 ret = snd_soc_dai_set_fmt(cpu_dai, dai_format);
82 if (ret) {
83 dev_err(cpu_dai->dev, "Failed to set dai format to %08x\n",
84 dai_format);
85 return ret;
86 }
87
88 return 0; 68 return 0;
89} 69}
90 70
@@ -92,17 +72,22 @@ static struct snd_soc_ops mxs_sgtl5000_hifi_ops = {
92 .hw_params = mxs_sgtl5000_hw_params, 72 .hw_params = mxs_sgtl5000_hw_params,
93}; 73};
94 74
75#define MXS_SGTL5000_DAI_FMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \
76 SND_SOC_DAIFMT_CBS_CFS)
77
95static struct snd_soc_dai_link mxs_sgtl5000_dai[] = { 78static struct snd_soc_dai_link mxs_sgtl5000_dai[] = {
96 { 79 {
97 .name = "HiFi Tx", 80 .name = "HiFi Tx",
98 .stream_name = "HiFi Playback", 81 .stream_name = "HiFi Playback",
99 .codec_dai_name = "sgtl5000", 82 .codec_dai_name = "sgtl5000",
83 .dai_fmt = MXS_SGTL5000_DAI_FMT,
100 .ops = &mxs_sgtl5000_hifi_ops, 84 .ops = &mxs_sgtl5000_hifi_ops,
101 .playback_only = true, 85 .playback_only = true,
102 }, { 86 }, {
103 .name = "HiFi Rx", 87 .name = "HiFi Rx",
104 .stream_name = "HiFi Capture", 88 .stream_name = "HiFi Capture",
105 .codec_dai_name = "sgtl5000", 89 .codec_dai_name = "sgtl5000",
90 .dai_fmt = MXS_SGTL5000_DAI_FMT,
106 .ops = &mxs_sgtl5000_hifi_ops, 91 .ops = &mxs_sgtl5000_hifi_ops,
107 .capture_only = true, 92 .capture_only = true,
108 }, 93 },
diff --git a/sound/soc/nuc900/nuc900-pcm.c b/sound/soc/nuc900/nuc900-pcm.c
index b779a3d9b5dd..b809fa909e4d 100644
--- a/sound/soc/nuc900/nuc900-pcm.c
+++ b/sound/soc/nuc900/nuc900-pcm.c
@@ -306,11 +306,6 @@ static struct snd_pcm_ops nuc900_dma_ops = {
306 .mmap = nuc900_dma_mmap, 306 .mmap = nuc900_dma_mmap,
307}; 307};
308 308
309static void nuc900_dma_free_dma_buffers(struct snd_pcm *pcm)
310{
311 snd_pcm_lib_preallocate_free_for_all(pcm);
312}
313
314static int nuc900_dma_new(struct snd_soc_pcm_runtime *rtd) 309static int nuc900_dma_new(struct snd_soc_pcm_runtime *rtd)
315{ 310{
316 struct snd_card *card = rtd->card->snd_card; 311 struct snd_card *card = rtd->card->snd_card;
@@ -330,7 +325,6 @@ static int nuc900_dma_new(struct snd_soc_pcm_runtime *rtd)
330static struct snd_soc_platform_driver nuc900_soc_platform = { 325static struct snd_soc_platform_driver nuc900_soc_platform = {
331 .ops = &nuc900_dma_ops, 326 .ops = &nuc900_dma_ops,
332 .pcm_new = nuc900_dma_new, 327 .pcm_new = nuc900_dma_new,
333 .pcm_free = nuc900_dma_free_dma_buffers,
334}; 328};
335 329
336static int nuc900_soc_platform_probe(struct platform_device *pdev) 330static int nuc900_soc_platform_probe(struct platform_device *pdev)
diff --git a/sound/soc/omap/ams-delta.c b/sound/soc/omap/ams-delta.c
index 4c6afb75eea6..706613077c15 100644
--- a/sound/soc/omap/ams-delta.c
+++ b/sound/soc/omap/ams-delta.c
@@ -412,21 +412,7 @@ static struct tty_ldisc_ops cx81801_ops = {
412 * over the modem port. 412 * over the modem port.
413 */ 413 */
414 414
415static int ams_delta_hw_params(struct snd_pcm_substream *substream, 415static struct snd_soc_ops ams_delta_ops;
416 struct snd_pcm_hw_params *params)
417{
418 struct snd_soc_pcm_runtime *rtd = substream->private_data;
419
420 /* Set cpu DAI configuration */
421 return snd_soc_dai_set_fmt(rtd->cpu_dai,
422 SND_SOC_DAIFMT_DSP_A |
423 SND_SOC_DAIFMT_NB_NF |
424 SND_SOC_DAIFMT_CBM_CFM);
425}
426
427static struct snd_soc_ops ams_delta_ops = {
428 .hw_params = ams_delta_hw_params,
429};
430 416
431 417
432/* Digital mute implemented using modem/CPU multiplexer. 418/* Digital mute implemented using modem/CPU multiplexer.
@@ -546,6 +532,8 @@ static struct snd_soc_dai_link ams_delta_dai_link = {
546 .platform_name = "omap-mcbsp.1", 532 .platform_name = "omap-mcbsp.1",
547 .codec_name = "cx20442-codec", 533 .codec_name = "cx20442-codec",
548 .ops = &ams_delta_ops, 534 .ops = &ams_delta_ops,
535 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF |
536 SND_SOC_DAIFMT_CBM_CFM,
549}; 537};
550 538
551/* Audio card driver */ 539/* Audio card driver */
diff --git a/sound/soc/omap/omap-twl4030.c b/sound/soc/omap/omap-twl4030.c
index 5e551c762b7a..fb1f6bb87cd4 100644
--- a/sound/soc/omap/omap-twl4030.c
+++ b/sound/soc/omap/omap-twl4030.c
@@ -53,11 +53,7 @@ static int omap_twl4030_hw_params(struct snd_pcm_substream *substream,
53 struct snd_pcm_hw_params *params) 53 struct snd_pcm_hw_params *params)
54{ 54{
55 struct snd_soc_pcm_runtime *rtd = substream->private_data; 55 struct snd_soc_pcm_runtime *rtd = substream->private_data;
56 struct snd_soc_dai *codec_dai = rtd->codec_dai;
57 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
58 struct snd_soc_card *card = rtd->card;
59 unsigned int fmt; 56 unsigned int fmt;
60 int ret;
61 57
62 switch (params_channels(params)) { 58 switch (params_channels(params)) {
63 case 2: /* Stereo I2S mode */ 59 case 2: /* Stereo I2S mode */
@@ -74,21 +70,7 @@ static int omap_twl4030_hw_params(struct snd_pcm_substream *substream,
74 return -EINVAL; 70 return -EINVAL;
75 } 71 }
76 72
77 /* Set codec DAI configuration */ 73 return snd_soc_runtime_set_dai_fmt(rtd, fmt);
78 ret = snd_soc_dai_set_fmt(codec_dai, fmt);
79 if (ret < 0) {
80 dev_err(card->dev, "can't set codec DAI configuration\n");
81 return ret;
82 }
83
84 /* Set cpu DAI configuration */
85 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
86 if (ret < 0) {
87 dev_err(card->dev, "can't set cpu DAI configuration\n");
88 return ret;
89 }
90
91 return 0;
92} 74}
93 75
94static struct snd_soc_ops omap_twl4030_ops = { 76static struct snd_soc_ops omap_twl4030_ops = {
diff --git a/sound/soc/omap/rx51.c b/sound/soc/omap/rx51.c
index 04896d6252a2..7f299357c2d2 100644
--- a/sound/soc/omap/rx51.c
+++ b/sound/soc/omap/rx51.c
@@ -250,14 +250,14 @@ static const struct snd_soc_dapm_route audio_map[] = {
250 {"FM Transmitter", NULL, "LLOUT"}, 250 {"FM Transmitter", NULL, "LLOUT"},
251 {"FM Transmitter", NULL, "RLOUT"}, 251 {"FM Transmitter", NULL, "RLOUT"},
252 252
253 {"DMic Rate 64", NULL, "Mic Bias"}, 253 {"DMic Rate 64", NULL, "DMic"},
254 {"Mic Bias", NULL, "DMic"}, 254 {"DMic", NULL, "Mic Bias"},
255 255
256 {"b LINE2R", NULL, "MONO_LOUT"}, 256 {"b LINE2R", NULL, "MONO_LOUT"},
257 {"Earphone", NULL, "b HPLOUT"}, 257 {"Earphone", NULL, "b HPLOUT"},
258 258
259 {"LINE1L", NULL, "b Mic Bias"}, 259 {"LINE1L", NULL, "HS Mic"},
260 {"b Mic Bias", NULL, "HS Mic"} 260 {"HS Mic", NULL, "b Mic Bias"},
261}; 261};
262 262
263static const char * const spk_function[] = {"Off", "On"}; 263static const char * const spk_function[] = {"Off", "On"};
diff --git a/sound/soc/pxa/Kconfig b/sound/soc/pxa/Kconfig
index 2434b6d61675..39cea80846c3 100644
--- a/sound/soc/pxa/Kconfig
+++ b/sound/soc/pxa/Kconfig
@@ -140,7 +140,7 @@ config SND_PXA910_SOC
140 Marvell PXA910 reference platform. 140 Marvell PXA910 reference platform.
141 141
142config SND_SOC_TTC_DKB 142config SND_SOC_TTC_DKB
143 bool "SoC Audio support for TTC DKB" 143 tristate "SoC Audio support for TTC DKB"
144 depends on SND_PXA910_SOC && MACH_TTC_DKB && I2C=y 144 depends on SND_PXA910_SOC && MACH_TTC_DKB && I2C=y
145 select PXA_SSP 145 select PXA_SSP
146 select SND_PXA_SOC_SSP 146 select SND_PXA_SOC_SSP
diff --git a/sound/soc/pxa/corgi.c b/sound/soc/pxa/corgi.c
index b7cd0a71fd70..3580d10c9f28 100644
--- a/sound/soc/pxa/corgi.c
+++ b/sound/soc/pxa/corgi.c
@@ -259,20 +259,6 @@ static const struct snd_kcontrol_new wm8731_corgi_controls[] = {
259 corgi_set_spk), 259 corgi_set_spk),
260}; 260};
261 261
262/*
263 * Logic for a wm8731 as connected on a Sharp SL-C7x0 Device
264 */
265static int corgi_wm8731_init(struct snd_soc_pcm_runtime *rtd)
266{
267 struct snd_soc_codec *codec = rtd->codec;
268 struct snd_soc_dapm_context *dapm = &codec->dapm;
269
270 snd_soc_dapm_nc_pin(dapm, "LLINEIN");
271 snd_soc_dapm_nc_pin(dapm, "RLINEIN");
272
273 return 0;
274}
275
276/* corgi digital audio interface glue - connects codec <--> CPU */ 262/* corgi digital audio interface glue - connects codec <--> CPU */
277static struct snd_soc_dai_link corgi_dai = { 263static struct snd_soc_dai_link corgi_dai = {
278 .name = "WM8731", 264 .name = "WM8731",
@@ -281,7 +267,6 @@ static struct snd_soc_dai_link corgi_dai = {
281 .codec_dai_name = "wm8731-hifi", 267 .codec_dai_name = "wm8731-hifi",
282 .platform_name = "pxa-pcm-audio", 268 .platform_name = "pxa-pcm-audio",
283 .codec_name = "wm8731.0-001b", 269 .codec_name = "wm8731.0-001b",
284 .init = corgi_wm8731_init,
285 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 270 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
286 SND_SOC_DAIFMT_CBS_CFS, 271 SND_SOC_DAIFMT_CBS_CFS,
287 .ops = &corgi_ops, 272 .ops = &corgi_ops,
@@ -300,6 +285,7 @@ static struct snd_soc_card corgi = {
300 .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets), 285 .num_dapm_widgets = ARRAY_SIZE(wm8731_dapm_widgets),
301 .dapm_routes = corgi_audio_map, 286 .dapm_routes = corgi_audio_map,
302 .num_dapm_routes = ARRAY_SIZE(corgi_audio_map), 287 .num_dapm_routes = ARRAY_SIZE(corgi_audio_map),
288 .fully_routed = true,
303}; 289};
304 290
305static int corgi_probe(struct platform_device *pdev) 291static int corgi_probe(struct platform_device *pdev)
diff --git a/sound/soc/pxa/e740_wm9705.c b/sound/soc/pxa/e740_wm9705.c
index 7c691aae8af2..d72e124a3676 100644
--- a/sound/soc/pxa/e740_wm9705.c
+++ b/sound/soc/pxa/e740_wm9705.c
@@ -88,24 +88,6 @@ static const struct snd_soc_dapm_route audio_map[] = {
88 {"Mic Amp", NULL, "Mic (Internal)"}, 88 {"Mic Amp", NULL, "Mic (Internal)"},
89}; 89};
90 90
91static int e740_ac97_init(struct snd_soc_pcm_runtime *rtd)
92{
93 struct snd_soc_codec *codec = rtd->codec;
94 struct snd_soc_dapm_context *dapm = &codec->dapm;
95
96 snd_soc_dapm_nc_pin(dapm, "HPOUTL");
97 snd_soc_dapm_nc_pin(dapm, "HPOUTR");
98 snd_soc_dapm_nc_pin(dapm, "PHONE");
99 snd_soc_dapm_nc_pin(dapm, "LINEINL");
100 snd_soc_dapm_nc_pin(dapm, "LINEINR");
101 snd_soc_dapm_nc_pin(dapm, "CDINL");
102 snd_soc_dapm_nc_pin(dapm, "CDINR");
103 snd_soc_dapm_nc_pin(dapm, "PCBEEP");
104 snd_soc_dapm_nc_pin(dapm, "MIC2");
105
106 return 0;
107}
108
109static struct snd_soc_dai_link e740_dai[] = { 91static struct snd_soc_dai_link e740_dai[] = {
110 { 92 {
111 .name = "AC97", 93 .name = "AC97",
@@ -114,7 +96,6 @@ static struct snd_soc_dai_link e740_dai[] = {
114 .codec_dai_name = "wm9705-hifi", 96 .codec_dai_name = "wm9705-hifi",
115 .platform_name = "pxa-pcm-audio", 97 .platform_name = "pxa-pcm-audio",
116 .codec_name = "wm9705-codec", 98 .codec_name = "wm9705-codec",
117 .init = e740_ac97_init,
118 }, 99 },
119 { 100 {
120 .name = "AC97 Aux", 101 .name = "AC97 Aux",
@@ -136,6 +117,7 @@ static struct snd_soc_card e740 = {
136 .num_dapm_widgets = ARRAY_SIZE(e740_dapm_widgets), 117 .num_dapm_widgets = ARRAY_SIZE(e740_dapm_widgets),
137 .dapm_routes = audio_map, 118 .dapm_routes = audio_map,
138 .num_dapm_routes = ARRAY_SIZE(audio_map), 119 .num_dapm_routes = ARRAY_SIZE(audio_map),
120 .fully_routed = true,
139}; 121};
140 122
141static struct gpio e740_audio_gpios[] = { 123static struct gpio e740_audio_gpios[] = {
diff --git a/sound/soc/pxa/e750_wm9705.c b/sound/soc/pxa/e750_wm9705.c
index 30544b65b5a8..48f2d7c2e68c 100644
--- a/sound/soc/pxa/e750_wm9705.c
+++ b/sound/soc/pxa/e750_wm9705.c
@@ -70,24 +70,6 @@ static const struct snd_soc_dapm_route audio_map[] = {
70 {"MIC1", NULL, "Mic (Internal)"}, 70 {"MIC1", NULL, "Mic (Internal)"},
71}; 71};
72 72
73static int e750_ac97_init(struct snd_soc_pcm_runtime *rtd)
74{
75 struct snd_soc_codec *codec = rtd->codec;
76 struct snd_soc_dapm_context *dapm = &codec->dapm;
77
78 snd_soc_dapm_nc_pin(dapm, "LOUT");
79 snd_soc_dapm_nc_pin(dapm, "ROUT");
80 snd_soc_dapm_nc_pin(dapm, "PHONE");
81 snd_soc_dapm_nc_pin(dapm, "LINEINL");
82 snd_soc_dapm_nc_pin(dapm, "LINEINR");
83 snd_soc_dapm_nc_pin(dapm, "CDINL");
84 snd_soc_dapm_nc_pin(dapm, "CDINR");
85 snd_soc_dapm_nc_pin(dapm, "PCBEEP");
86 snd_soc_dapm_nc_pin(dapm, "MIC2");
87
88 return 0;
89}
90
91static struct snd_soc_dai_link e750_dai[] = { 73static struct snd_soc_dai_link e750_dai[] = {
92 { 74 {
93 .name = "AC97", 75 .name = "AC97",
@@ -96,7 +78,6 @@ static struct snd_soc_dai_link e750_dai[] = {
96 .codec_dai_name = "wm9705-hifi", 78 .codec_dai_name = "wm9705-hifi",
97 .platform_name = "pxa-pcm-audio", 79 .platform_name = "pxa-pcm-audio",
98 .codec_name = "wm9705-codec", 80 .codec_name = "wm9705-codec",
99 .init = e750_ac97_init,
100 /* use ops to check startup state */ 81 /* use ops to check startup state */
101 }, 82 },
102 { 83 {
@@ -119,6 +100,7 @@ static struct snd_soc_card e750 = {
119 .num_dapm_widgets = ARRAY_SIZE(e750_dapm_widgets), 100 .num_dapm_widgets = ARRAY_SIZE(e750_dapm_widgets),
120 .dapm_routes = audio_map, 101 .dapm_routes = audio_map,
121 .num_dapm_routes = ARRAY_SIZE(audio_map), 102 .num_dapm_routes = ARRAY_SIZE(audio_map),
103 .fully_routed = true,
122}; 104};
123 105
124static struct gpio e750_audio_gpios[] = { 106static struct gpio e750_audio_gpios[] = {
diff --git a/sound/soc/pxa/hx4700.c b/sound/soc/pxa/hx4700.c
index ce26551052a3..73eb5ddf9753 100644
--- a/sound/soc/pxa/hx4700.c
+++ b/sound/soc/pxa/hx4700.c
@@ -127,15 +127,8 @@ static const struct snd_soc_dapm_route hx4700_audio_map[] = {
127static int hx4700_ak4641_init(struct snd_soc_pcm_runtime *rtd) 127static int hx4700_ak4641_init(struct snd_soc_pcm_runtime *rtd)
128{ 128{
129 struct snd_soc_codec *codec = rtd->codec; 129 struct snd_soc_codec *codec = rtd->codec;
130 struct snd_soc_dapm_context *dapm = &codec->dapm;
131 int err; 130 int err;
132 131
133 /* NC codec pins */
134 /* FIXME: is anything connected here? */
135 snd_soc_dapm_nc_pin(dapm, "MOUT1");
136 snd_soc_dapm_nc_pin(dapm, "MICEXT");
137 snd_soc_dapm_nc_pin(dapm, "AUX");
138
139 /* Jack detection API stuff */ 132 /* Jack detection API stuff */
140 err = snd_soc_jack_new(codec, "Headphone Jack", 133 err = snd_soc_jack_new(codec, "Headphone Jack",
141 SND_JACK_HEADPHONE, &hs_jack); 134 SND_JACK_HEADPHONE, &hs_jack);
@@ -184,6 +177,7 @@ static struct snd_soc_card snd_soc_card_hx4700 = {
184 .num_dapm_widgets = ARRAY_SIZE(hx4700_dapm_widgets), 177 .num_dapm_widgets = ARRAY_SIZE(hx4700_dapm_widgets),
185 .dapm_routes = hx4700_audio_map, 178 .dapm_routes = hx4700_audio_map,
186 .num_dapm_routes = ARRAY_SIZE(hx4700_audio_map), 179 .num_dapm_routes = ARRAY_SIZE(hx4700_audio_map),
180 .fully_routed = true,
187}; 181};
188 182
189static struct gpio hx4700_audio_gpios[] = { 183static struct gpio hx4700_audio_gpios[] = {
diff --git a/sound/soc/pxa/magician.c b/sound/soc/pxa/magician.c
index 259e048681c0..241d0be42d7a 100644
--- a/sound/soc/pxa/magician.c
+++ b/sound/soc/pxa/magician.c
@@ -391,25 +391,6 @@ static const struct snd_kcontrol_new uda1380_magician_controls[] = {
391 magician_get_input, magician_set_input), 391 magician_get_input, magician_set_input),
392}; 392};
393 393
394/*
395 * Logic for a uda1380 as connected on a HTC Magician
396 */
397static int magician_uda1380_init(struct snd_soc_pcm_runtime *rtd)
398{
399 struct snd_soc_codec *codec = rtd->codec;
400 struct snd_soc_dapm_context *dapm = &codec->dapm;
401
402 /* NC codec pins */
403 snd_soc_dapm_nc_pin(dapm, "VOUTLHP");
404 snd_soc_dapm_nc_pin(dapm, "VOUTRHP");
405
406 /* FIXME: is anything connected here? */
407 snd_soc_dapm_nc_pin(dapm, "VINL");
408 snd_soc_dapm_nc_pin(dapm, "VINR");
409
410 return 0;
411}
412
413/* magician digital audio interface glue - connects codec <--> CPU */ 394/* magician digital audio interface glue - connects codec <--> CPU */
414static struct snd_soc_dai_link magician_dai[] = { 395static struct snd_soc_dai_link magician_dai[] = {
415{ 396{
@@ -419,7 +400,6 @@ static struct snd_soc_dai_link magician_dai[] = {
419 .codec_dai_name = "uda1380-hifi-playback", 400 .codec_dai_name = "uda1380-hifi-playback",
420 .platform_name = "pxa-pcm-audio", 401 .platform_name = "pxa-pcm-audio",
421 .codec_name = "uda1380-codec.0-0018", 402 .codec_name = "uda1380-codec.0-0018",
422 .init = magician_uda1380_init,
423 .ops = &magician_playback_ops, 403 .ops = &magician_playback_ops,
424}, 404},
425{ 405{
@@ -446,6 +426,7 @@ static struct snd_soc_card snd_soc_card_magician = {
446 .num_dapm_widgets = ARRAY_SIZE(uda1380_dapm_widgets), 426 .num_dapm_widgets = ARRAY_SIZE(uda1380_dapm_widgets),
447 .dapm_routes = audio_map, 427 .dapm_routes = audio_map,
448 .num_dapm_routes = ARRAY_SIZE(audio_map), 428 .num_dapm_routes = ARRAY_SIZE(audio_map),
429 .fully_routed = true,
449}; 430};
450 431
451static struct platform_device *magician_snd_device; 432static struct platform_device *magician_snd_device;
diff --git a/sound/soc/pxa/mioa701_wm9713.c b/sound/soc/pxa/mioa701_wm9713.c
index 396dbd51a64f..a9615a574546 100644
--- a/sound/soc/pxa/mioa701_wm9713.c
+++ b/sound/soc/pxa/mioa701_wm9713.c
@@ -81,7 +81,7 @@ static int rear_amp_power(struct snd_soc_codec *codec, int power)
81static int rear_amp_event(struct snd_soc_dapm_widget *widget, 81static int rear_amp_event(struct snd_soc_dapm_widget *widget,
82 struct snd_kcontrol *kctl, int event) 82 struct snd_kcontrol *kctl, int event)
83{ 83{
84 struct snd_soc_codec *codec = widget->codec; 84 struct snd_soc_codec *codec = widget->dapm->card->rtd[0].codec;
85 85
86 return rear_amp_power(codec, SND_SOC_DAPM_EVENT_ON(event)); 86 return rear_amp_power(codec, SND_SOC_DAPM_EVENT_ON(event));
87} 87}
diff --git a/sound/soc/pxa/palm27x.c b/sound/soc/pxa/palm27x.c
index 1eebca2f0a97..910336c5ebeb 100644
--- a/sound/soc/pxa/palm27x.c
+++ b/sound/soc/pxa/palm27x.c
@@ -68,7 +68,7 @@ static const struct snd_soc_dapm_route audio_map[] = {
68 {"Ext. Speaker", NULL, "ROUT2"}, 68 {"Ext. Speaker", NULL, "ROUT2"},
69 69
70 /* mic connected to MIC1 */ 70 /* mic connected to MIC1 */
71 {"Ext. Microphone", NULL, "MIC1"}, 71 {"MIC1", NULL, "Ext. Microphone"},
72}; 72};
73 73
74static struct snd_soc_card palm27x_asoc; 74static struct snd_soc_card palm27x_asoc;
@@ -76,18 +76,8 @@ static struct snd_soc_card palm27x_asoc;
76static int palm27x_ac97_init(struct snd_soc_pcm_runtime *rtd) 76static int palm27x_ac97_init(struct snd_soc_pcm_runtime *rtd)
77{ 77{
78 struct snd_soc_codec *codec = rtd->codec; 78 struct snd_soc_codec *codec = rtd->codec;
79 struct snd_soc_dapm_context *dapm = &codec->dapm;
80 int err; 79 int err;
81 80
82 /* not connected pins */
83 snd_soc_dapm_nc_pin(dapm, "OUT3");
84 snd_soc_dapm_nc_pin(dapm, "MONOOUT");
85 snd_soc_dapm_nc_pin(dapm, "LINEINL");
86 snd_soc_dapm_nc_pin(dapm, "LINEINR");
87 snd_soc_dapm_nc_pin(dapm, "PCBEEP");
88 snd_soc_dapm_nc_pin(dapm, "PHONE");
89 snd_soc_dapm_nc_pin(dapm, "MIC2");
90
91 /* Jack detection API stuff */ 81 /* Jack detection API stuff */
92 err = snd_soc_jack_new(codec, "Headphone Jack", 82 err = snd_soc_jack_new(codec, "Headphone Jack",
93 SND_JACK_HEADPHONE, &hs_jack); 83 SND_JACK_HEADPHONE, &hs_jack);
@@ -133,7 +123,8 @@ static struct snd_soc_card palm27x_asoc = {
133 .dapm_widgets = palm27x_dapm_widgets, 123 .dapm_widgets = palm27x_dapm_widgets,
134 .num_dapm_widgets = ARRAY_SIZE(palm27x_dapm_widgets), 124 .num_dapm_widgets = ARRAY_SIZE(palm27x_dapm_widgets),
135 .dapm_routes = audio_map, 125 .dapm_routes = audio_map,
136 .num_dapm_routes = ARRAY_SIZE(audio_map) 126 .num_dapm_routes = ARRAY_SIZE(audio_map),
127 .fully_routed = true,
137}; 128};
138 129
139static int palm27x_asoc_probe(struct platform_device *pdev) 130static int palm27x_asoc_probe(struct platform_device *pdev)
diff --git a/sound/soc/pxa/raumfeld.c b/sound/soc/pxa/raumfeld.c
index 083706595495..552b763005ed 100644
--- a/sound/soc/pxa/raumfeld.c
+++ b/sound/soc/pxa/raumfeld.c
@@ -88,7 +88,7 @@ static int raumfeld_cs4270_hw_params(struct snd_pcm_substream *substream,
88 struct snd_soc_pcm_runtime *rtd = substream->private_data; 88 struct snd_soc_pcm_runtime *rtd = substream->private_data;
89 struct snd_soc_dai *codec_dai = rtd->codec_dai; 89 struct snd_soc_dai *codec_dai = rtd->codec_dai;
90 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 90 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
91 unsigned int fmt, clk = 0; 91 unsigned int clk = 0;
92 int ret = 0; 92 int ret = 0;
93 93
94 switch (params_rate(params)) { 94 switch (params_rate(params)) {
@@ -112,15 +112,6 @@ static int raumfeld_cs4270_hw_params(struct snd_pcm_substream *substream,
112 return -EINVAL; 112 return -EINVAL;
113 } 113 }
114 114
115 fmt = SND_SOC_DAIFMT_I2S |
116 SND_SOC_DAIFMT_NB_NF |
117 SND_SOC_DAIFMT_CBS_CFS;
118
119 /* setup the CODEC DAI */
120 ret = snd_soc_dai_set_fmt(codec_dai, fmt);
121 if (ret < 0)
122 return ret;
123
124 ret = snd_soc_dai_set_sysclk(codec_dai, 0, clk, 0); 115 ret = snd_soc_dai_set_sysclk(codec_dai, 0, clk, 0);
125 if (ret < 0) 116 if (ret < 0)
126 return ret; 117 return ret;
@@ -130,10 +121,6 @@ static int raumfeld_cs4270_hw_params(struct snd_pcm_substream *substream,
130 if (ret < 0) 121 if (ret < 0)
131 return ret; 122 return ret;
132 123
133 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
134 if (ret < 0)
135 return ret;
136
137 ret = snd_soc_dai_set_clkdiv(cpu_dai, PXA_SSP_DIV_SCR, 4); 124 ret = snd_soc_dai_set_clkdiv(cpu_dai, PXA_SSP_DIV_SCR, 4);
138 if (ret < 0) 125 if (ret < 0)
139 return ret; 126 return ret;
@@ -169,9 +156,8 @@ static int raumfeld_ak4104_hw_params(struct snd_pcm_substream *substream,
169 struct snd_pcm_hw_params *params) 156 struct snd_pcm_hw_params *params)
170{ 157{
171 struct snd_soc_pcm_runtime *rtd = substream->private_data; 158 struct snd_soc_pcm_runtime *rtd = substream->private_data;
172 struct snd_soc_dai *codec_dai = rtd->codec_dai;
173 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 159 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
174 int fmt, ret = 0, clk = 0; 160 int ret = 0, clk = 0;
175 161
176 switch (params_rate(params)) { 162 switch (params_rate(params)) {
177 case 44100: 163 case 44100:
@@ -194,22 +180,11 @@ static int raumfeld_ak4104_hw_params(struct snd_pcm_substream *substream,
194 return -EINVAL; 180 return -EINVAL;
195 } 181 }
196 182
197 fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF;
198
199 /* setup the CODEC DAI */
200 ret = snd_soc_dai_set_fmt(codec_dai, fmt | SND_SOC_DAIFMT_CBS_CFS);
201 if (ret < 0)
202 return ret;
203
204 /* setup the CPU DAI */ 183 /* setup the CPU DAI */
205 ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, 0, clk); 184 ret = snd_soc_dai_set_pll(cpu_dai, 0, 0, 0, clk);
206 if (ret < 0) 185 if (ret < 0)
207 return ret; 186 return ret;
208 187
209 ret = snd_soc_dai_set_fmt(cpu_dai, fmt | SND_SOC_DAIFMT_CBS_CFS);
210 if (ret < 0)
211 return ret;
212
213 ret = snd_soc_dai_set_clkdiv(cpu_dai, PXA_SSP_DIV_SCR, 4); 188 ret = snd_soc_dai_set_clkdiv(cpu_dai, PXA_SSP_DIV_SCR, 4);
214 if (ret < 0) 189 if (ret < 0)
215 return ret; 190 return ret;
@@ -233,6 +208,9 @@ static struct snd_soc_ops raumfeld_ak4104_ops = {
233 .platform_name = "pxa-pcm-audio", \ 208 .platform_name = "pxa-pcm-audio", \
234 .codec_dai_name = "cs4270-hifi", \ 209 .codec_dai_name = "cs4270-hifi", \
235 .codec_name = "cs4270.0-0048", \ 210 .codec_name = "cs4270.0-0048", \
211 .dai_fmt = SND_SOC_DAIFMT_I2S | \
212 SND_SOC_DAIFMT_NB_NF | \
213 SND_SOC_DAIFMT_CBS_CFS, \
236 .ops = &raumfeld_cs4270_ops, \ 214 .ops = &raumfeld_cs4270_ops, \
237} 215}
238 216
@@ -243,6 +221,9 @@ static struct snd_soc_ops raumfeld_ak4104_ops = {
243 .cpu_dai_name = "pxa-ssp-dai.1", \ 221 .cpu_dai_name = "pxa-ssp-dai.1", \
244 .codec_dai_name = "ak4104-hifi", \ 222 .codec_dai_name = "ak4104-hifi", \
245 .platform_name = "pxa-pcm-audio", \ 223 .platform_name = "pxa-pcm-audio", \
224 .dai_fmt = SND_SOC_DAIFMT_I2S | \
225 SND_SOC_DAIFMT_NB_NF | \
226 SND_SOC_DAIFMT_CBS_CFS, \
246 .ops = &raumfeld_ak4104_ops, \ 227 .ops = &raumfeld_ak4104_ops, \
247 .codec_name = "spi0.0", \ 228 .codec_name = "spi0.0", \
248} 229}
diff --git a/sound/soc/pxa/spitz.c b/sound/soc/pxa/spitz.c
index a6d680acd907..461123ad5ff2 100644
--- a/sound/soc/pxa/spitz.c
+++ b/sound/soc/pxa/spitz.c
@@ -256,26 +256,6 @@ static const struct snd_kcontrol_new wm8750_spitz_controls[] = {
256 spitz_set_spk), 256 spitz_set_spk),
257}; 257};
258 258
259/*
260 * Logic for a wm8750 as connected on a Sharp SL-Cxx00 Device
261 */
262static int spitz_wm8750_init(struct snd_soc_pcm_runtime *rtd)
263{
264 struct snd_soc_codec *codec = rtd->codec;
265 struct snd_soc_dapm_context *dapm = &codec->dapm;
266
267 /* NC codec pins */
268 snd_soc_dapm_nc_pin(dapm, "RINPUT1");
269 snd_soc_dapm_nc_pin(dapm, "LINPUT2");
270 snd_soc_dapm_nc_pin(dapm, "RINPUT2");
271 snd_soc_dapm_nc_pin(dapm, "LINPUT3");
272 snd_soc_dapm_nc_pin(dapm, "RINPUT3");
273 snd_soc_dapm_nc_pin(dapm, "OUT3");
274 snd_soc_dapm_nc_pin(dapm, "MONO1");
275
276 return 0;
277}
278
279/* spitz digital audio interface glue - connects codec <--> CPU */ 259/* spitz digital audio interface glue - connects codec <--> CPU */
280static struct snd_soc_dai_link spitz_dai = { 260static struct snd_soc_dai_link spitz_dai = {
281 .name = "wm8750", 261 .name = "wm8750",
@@ -284,7 +264,6 @@ static struct snd_soc_dai_link spitz_dai = {
284 .codec_dai_name = "wm8750-hifi", 264 .codec_dai_name = "wm8750-hifi",
285 .platform_name = "pxa-pcm-audio", 265 .platform_name = "pxa-pcm-audio",
286 .codec_name = "wm8750.0-001b", 266 .codec_name = "wm8750.0-001b",
287 .init = spitz_wm8750_init,
288 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 267 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
289 SND_SOC_DAIFMT_CBS_CFS, 268 SND_SOC_DAIFMT_CBS_CFS,
290 .ops = &spitz_ops, 269 .ops = &spitz_ops,
@@ -303,6 +282,7 @@ static struct snd_soc_card snd_soc_spitz = {
303 .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets), 282 .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
304 .dapm_routes = spitz_audio_map, 283 .dapm_routes = spitz_audio_map,
305 .num_dapm_routes = ARRAY_SIZE(spitz_audio_map), 284 .num_dapm_routes = ARRAY_SIZE(spitz_audio_map),
285 .fully_routed = true,
306}; 286};
307 287
308static int spitz_probe(struct platform_device *pdev) 288static int spitz_probe(struct platform_device *pdev)
diff --git a/sound/soc/pxa/ttc-dkb.c b/sound/soc/pxa/ttc-dkb.c
index e3d7257ad09c..5001dbb9b257 100644
--- a/sound/soc/pxa/ttc-dkb.c
+++ b/sound/soc/pxa/ttc-dkb.c
@@ -76,10 +76,6 @@ static const struct snd_soc_dapm_route ttc_audio_map[] = {
76static int ttc_pm860x_init(struct snd_soc_pcm_runtime *rtd) 76static int ttc_pm860x_init(struct snd_soc_pcm_runtime *rtd)
77{ 77{
78 struct snd_soc_codec *codec = rtd->codec; 78 struct snd_soc_codec *codec = rtd->codec;
79 struct snd_soc_dapm_context *dapm = &codec->dapm;
80
81 snd_soc_dapm_disable_pin(dapm, "Headset Mic 2");
82 snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
83 79
84 /* Headset jack detection */ 80 /* Headset jack detection */
85 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE 81 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE
diff --git a/sound/soc/pxa/zylonite.c b/sound/soc/pxa/zylonite.c
index 23bf991e95d5..8f301c72ee5e 100644
--- a/sound/soc/pxa/zylonite.c
+++ b/sound/soc/pxa/zylonite.c
@@ -130,16 +130,6 @@ static int zylonite_voice_hw_params(struct snd_pcm_substream *substream,
130 if (ret < 0) 130 if (ret < 0)
131 return ret; 131 return ret;
132 132
133 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
134 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
135 if (ret < 0)
136 return ret;
137
138 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
139 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
140 if (ret < 0)
141 return ret;
142
143 return 0; 133 return 0;
144} 134}
145 135
@@ -172,6 +162,8 @@ static struct snd_soc_dai_link zylonite_dai[] = {
172 .platform_name = "pxa-pcm-audio", 162 .platform_name = "pxa-pcm-audio",
173 .cpu_dai_name = "pxa-ssp-dai.2", 163 .cpu_dai_name = "pxa-ssp-dai.2",
174 .codec_dai_name = "wm9713-voice", 164 .codec_dai_name = "wm9713-voice",
165 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
166 SND_SOC_DAIFMT_CBS_CFS,
175 .ops = &zylonite_voice_ops, 167 .ops = &zylonite_voice_ops,
176}, 168},
177}; 169};
diff --git a/sound/soc/samsung/Kconfig b/sound/soc/samsung/Kconfig
index fc67f97f19f6..e817a2f43ea8 100644
--- a/sound/soc/samsung/Kconfig
+++ b/sound/soc/samsung/Kconfig
@@ -54,7 +54,7 @@ config SND_SOC_SAMSUNG_JIVE_WM8750
54config SND_SOC_SAMSUNG_SMDK_WM8580 54config SND_SOC_SAMSUNG_SMDK_WM8580
55 tristate "SoC I2S Audio support for WM8580 on SMDK" 55 tristate "SoC I2S Audio support for WM8580 on SMDK"
56 depends on SND_SOC_SAMSUNG && (MACH_SMDK6410 || MACH_SMDKC100 || MACH_SMDKV210 || MACH_SMDKC110) 56 depends on SND_SOC_SAMSUNG && (MACH_SMDK6410 || MACH_SMDKC100 || MACH_SMDKV210 || MACH_SMDKC110)
57 depends on REGMAP_I2C 57 depends on I2C
58 select SND_SOC_WM8580 58 select SND_SOC_WM8580
59 select SND_SAMSUNG_I2S 59 select SND_SAMSUNG_I2S
60 help 60 help
@@ -167,7 +167,7 @@ config SND_SOC_SAMSUNG_SMDK_SPDIF
167config SND_SOC_SMDK_WM8580_PCM 167config SND_SOC_SMDK_WM8580_PCM
168 tristate "SoC PCM Audio support for WM8580 on SMDK" 168 tristate "SoC PCM Audio support for WM8580 on SMDK"
169 depends on SND_SOC_SAMSUNG && (MACH_SMDKV210 || MACH_SMDKC110) 169 depends on SND_SOC_SAMSUNG && (MACH_SMDKV210 || MACH_SMDKC110)
170 depends on REGMAP_I2C 170 depends on I2C
171 select SND_SOC_WM8580 171 select SND_SOC_WM8580
172 select SND_SAMSUNG_PCM 172 select SND_SAMSUNG_PCM
173 help 173 help
diff --git a/sound/soc/samsung/goni_wm8994.c b/sound/soc/samsung/goni_wm8994.c
index 3b527dcfc0aa..fad56b9e7369 100644
--- a/sound/soc/samsung/goni_wm8994.c
+++ b/sound/soc/samsung/goni_wm8994.c
@@ -136,22 +136,9 @@ static int goni_hifi_hw_params(struct snd_pcm_substream *substream,
136{ 136{
137 struct snd_soc_pcm_runtime *rtd = substream->private_data; 137 struct snd_soc_pcm_runtime *rtd = substream->private_data;
138 struct snd_soc_dai *codec_dai = rtd->codec_dai; 138 struct snd_soc_dai *codec_dai = rtd->codec_dai;
139 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
140 unsigned int pll_out = 24000000; 139 unsigned int pll_out = 24000000;
141 int ret = 0; 140 int ret = 0;
142 141
143 /* set the cpu DAI configuration */
144 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
145 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
146 if (ret < 0)
147 return ret;
148
149 /* set codec DAI configuration */
150 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
151 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
152 if (ret < 0)
153 return ret;
154
155 /* set the codec FLL */ 142 /* set the codec FLL */
156 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, 0, pll_out, 143 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL1, 0, pll_out,
157 params_rate(params) * 256); 144 params_rate(params) * 256);
@@ -182,12 +169,6 @@ static int goni_voice_hw_params(struct snd_pcm_substream *substream,
182 if (params_rate(params) != 8000) 169 if (params_rate(params) != 8000)
183 return -EINVAL; 170 return -EINVAL;
184 171
185 /* set codec DAI configuration */
186 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_LEFT_J |
187 SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM);
188 if (ret < 0)
189 return ret;
190
191 /* set the codec FLL */ 172 /* set the codec FLL */
192 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2, 0, pll_out, 173 ret = snd_soc_dai_set_pll(codec_dai, WM8994_FLL2, 0, pll_out,
193 params_rate(params) * 256); 174 params_rate(params) * 256);
@@ -234,6 +215,8 @@ static struct snd_soc_dai_link goni_dai[] = {
234 .codec_dai_name = "wm8994-aif1", 215 .codec_dai_name = "wm8994-aif1",
235 .platform_name = "samsung-i2s.0", 216 .platform_name = "samsung-i2s.0",
236 .codec_name = "wm8994-codec.0-001a", 217 .codec_name = "wm8994-codec.0-001a",
218 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
219 SND_SOC_DAIFMT_CBM_CFM,
237 .init = goni_wm8994_init, 220 .init = goni_wm8994_init,
238 .ops = &goni_hifi_ops, 221 .ops = &goni_hifi_ops,
239}, { 222}, {
@@ -242,6 +225,8 @@ static struct snd_soc_dai_link goni_dai[] = {
242 .cpu_dai_name = "goni-voice-dai", 225 .cpu_dai_name = "goni-voice-dai",
243 .codec_dai_name = "wm8994-aif2", 226 .codec_dai_name = "wm8994-aif2",
244 .codec_name = "wm8994-codec.0-001a", 227 .codec_name = "wm8994-codec.0-001a",
228 .dai_fmt = SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_IB_IF |
229 SND_SOC_DAIFMT_CBM_CFM,
245 .ops = &goni_voice_ops, 230 .ops = &goni_voice_ops,
246}, 231},
247}; 232};
diff --git a/sound/soc/samsung/h1940_uda1380.c b/sound/soc/samsung/h1940_uda1380.c
index f2d7980d7ddc..59b044255b78 100644
--- a/sound/soc/samsung/h1940_uda1380.c
+++ b/sound/soc/samsung/h1940_uda1380.c
@@ -76,7 +76,6 @@ static int h1940_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 *cpu_dai = rtd->cpu_dai; 78 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
79 struct snd_soc_dai *codec_dai = rtd->codec_dai;
80 int div; 79 int div;
81 int ret; 80 int ret;
82 unsigned int rate = params_rate(params); 81 unsigned int rate = params_rate(params);
@@ -95,18 +94,6 @@ static int h1940_hw_params(struct snd_pcm_substream *substream,
95 return -EINVAL; 94 return -EINVAL;
96 } 95 }
97 96
98 /* set codec DAI configuration */
99 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
100 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
101 if (ret < 0)
102 return ret;
103
104 /* set cpu DAI configuration */
105 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
106 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
107 if (ret < 0)
108 return ret;
109
110 /* select clock source */ 97 /* select clock source */
111 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C24XX_CLKSRC_PCLK, rate, 98 ret = snd_soc_dai_set_sysclk(cpu_dai, S3C24XX_CLKSRC_PCLK, rate,
112 SND_SOC_CLOCK_OUT); 99 SND_SOC_CLOCK_OUT);
@@ -207,6 +194,8 @@ static struct snd_soc_dai_link h1940_uda1380_dai[] = {
207 .init = h1940_uda1380_init, 194 .init = h1940_uda1380_init,
208 .platform_name = "s3c24xx-iis", 195 .platform_name = "s3c24xx-iis",
209 .codec_name = "uda1380-codec.0-001a", 196 .codec_name = "uda1380-codec.0-001a",
197 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
198 SND_SOC_DAIFMT_CBS_CFS,
210 .ops = &h1940_ops, 199 .ops = &h1940_ops,
211 }, 200 },
212}; 201};
diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
index b5a80c528d86..b92ab40d2be6 100644
--- a/sound/soc/samsung/i2s.c
+++ b/sound/soc/samsung/i2s.c
@@ -10,9 +10,11 @@
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12 12
13#include <dt-bindings/sound/samsung-i2s.h>
13#include <linux/delay.h> 14#include <linux/delay.h>
14#include <linux/slab.h> 15#include <linux/slab.h>
15#include <linux/clk.h> 16#include <linux/clk.h>
17#include <linux/clk-provider.h>
16#include <linux/io.h> 18#include <linux/io.h>
17#include <linux/module.h> 19#include <linux/module.h>
18#include <linux/of.h> 20#include <linux/of.h>
@@ -59,10 +61,8 @@ struct samsung_i2s_dai_data {
59struct i2s_dai { 61struct i2s_dai {
60 /* Platform device for this DAI */ 62 /* Platform device for this DAI */
61 struct platform_device *pdev; 63 struct platform_device *pdev;
62 /* IOREMAP'd SFRs */ 64 /* Memory mapped SFR region */
63 void __iomem *addr; 65 void __iomem *addr;
64 /* Physical base address of SFRs */
65 u32 base;
66 /* Rate of RCLK source clock */ 66 /* Rate of RCLK source clock */
67 unsigned long rclk_srcrate; 67 unsigned long rclk_srcrate;
68 /* Frame Clock */ 68 /* Frame Clock */
@@ -83,8 +83,6 @@ struct i2s_dai {
83#define DAI_OPENED (1 << 0) /* Dai is opened */ 83#define DAI_OPENED (1 << 0) /* Dai is opened */
84#define DAI_MANAGER (1 << 1) /* Dai is the manager */ 84#define DAI_MANAGER (1 << 1) /* Dai is the manager */
85 unsigned mode; 85 unsigned mode;
86 /* CDCLK pin direction: 0 - input, 1 - output */
87 unsigned int cdclk_out:1;
88 /* Driver for this DAI */ 86 /* Driver for this DAI */
89 struct snd_soc_dai_driver i2s_dai_drv; 87 struct snd_soc_dai_driver i2s_dai_drv;
90 /* DMA parameters */ 88 /* DMA parameters */
@@ -95,8 +93,15 @@ struct i2s_dai {
95 u32 suspend_i2smod; 93 u32 suspend_i2smod;
96 u32 suspend_i2scon; 94 u32 suspend_i2scon;
97 u32 suspend_i2spsr; 95 u32 suspend_i2spsr;
98 unsigned long gpios[7]; /* i2s gpio line numbers */
99 const struct samsung_i2s_variant_regs *variant_regs; 96 const struct samsung_i2s_variant_regs *variant_regs;
97
98 /* Spinlock protecting access to the device's registers */
99 spinlock_t spinlock;
100 spinlock_t *lock;
101
102 /* Below fields are only valid if this is the primary FIFO */
103 struct clk *clk_table[3];
104 struct clk_onecell_data clk_data;
100}; 105};
101 106
102/* Lock for cross i/f checks */ 107/* Lock for cross i/f checks */
@@ -133,10 +138,16 @@ static inline bool tx_active(struct i2s_dai *i2s)
133 return active ? true : false; 138 return active ? true : false;
134} 139}
135 140
141/* Return pointer to the other DAI */
142static inline struct i2s_dai *get_other_dai(struct i2s_dai *i2s)
143{
144 return i2s->pri_dai ? : i2s->sec_dai;
145}
146
136/* If the other interface of the controller is transmitting data */ 147/* If the other interface of the controller is transmitting data */
137static inline bool other_tx_active(struct i2s_dai *i2s) 148static inline bool other_tx_active(struct i2s_dai *i2s)
138{ 149{
139 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 150 struct i2s_dai *other = get_other_dai(i2s);
140 151
141 return tx_active(other); 152 return tx_active(other);
142} 153}
@@ -163,7 +174,7 @@ static inline bool rx_active(struct i2s_dai *i2s)
163/* If the other interface of the controller is receiving data */ 174/* If the other interface of the controller is receiving data */
164static inline bool other_rx_active(struct i2s_dai *i2s) 175static inline bool other_rx_active(struct i2s_dai *i2s)
165{ 176{
166 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 177 struct i2s_dai *other = get_other_dai(i2s);
167 178
168 return rx_active(other); 179 return rx_active(other);
169} 180}
@@ -464,18 +475,23 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai,
464 int clk_id, unsigned int rfs, int dir) 475 int clk_id, unsigned int rfs, int dir)
465{ 476{
466 struct i2s_dai *i2s = to_info(dai); 477 struct i2s_dai *i2s = to_info(dai);
467 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 478 struct i2s_dai *other = get_other_dai(i2s);
468 u32 mod = readl(i2s->addr + I2SMOD);
469 const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs; 479 const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs;
470 unsigned int cdcon_mask = 1 << i2s_regs->cdclkcon_off; 480 unsigned int cdcon_mask = 1 << i2s_regs->cdclkcon_off;
471 unsigned int rsrc_mask = 1 << i2s_regs->rclksrc_off; 481 unsigned int rsrc_mask = 1 << i2s_regs->rclksrc_off;
482 u32 mod, mask, val = 0;
483
484 spin_lock(i2s->lock);
485 mod = readl(i2s->addr + I2SMOD);
486 spin_unlock(i2s->lock);
472 487
473 switch (clk_id) { 488 switch (clk_id) {
474 case SAMSUNG_I2S_OPCLK: 489 case SAMSUNG_I2S_OPCLK:
475 mod &= ~MOD_OPCLK_MASK; 490 mask = MOD_OPCLK_MASK;
476 mod |= dir; 491 val = dir;
477 break; 492 break;
478 case SAMSUNG_I2S_CDCLK: 493 case SAMSUNG_I2S_CDCLK:
494 mask = 1 << i2s_regs->cdclkcon_off;
479 /* Shouldn't matter in GATING(CLOCK_IN) mode */ 495 /* Shouldn't matter in GATING(CLOCK_IN) mode */
480 if (dir == SND_SOC_CLOCK_IN) 496 if (dir == SND_SOC_CLOCK_IN)
481 rfs = 0; 497 rfs = 0;
@@ -492,15 +508,15 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai,
492 } 508 }
493 509
494 if (dir == SND_SOC_CLOCK_IN) 510 if (dir == SND_SOC_CLOCK_IN)
495 mod |= 1 << i2s_regs->cdclkcon_off; 511 val = 1 << i2s_regs->cdclkcon_off;
496 else
497 mod &= ~(1 << i2s_regs->cdclkcon_off);
498 512
499 i2s->rfs = rfs; 513 i2s->rfs = rfs;
500 break; 514 break;
501 515
502 case SAMSUNG_I2S_RCLKSRC_0: /* clock corrsponding to IISMOD[10] := 0 */ 516 case SAMSUNG_I2S_RCLKSRC_0: /* clock corrsponding to IISMOD[10] := 0 */
503 case SAMSUNG_I2S_RCLKSRC_1: /* clock corrsponding to IISMOD[10] := 1 */ 517 case SAMSUNG_I2S_RCLKSRC_1: /* clock corrsponding to IISMOD[10] := 1 */
518 mask = 1 << i2s_regs->rclksrc_off;
519
504 if ((i2s->quirks & QUIRK_NO_MUXPSR) 520 if ((i2s->quirks & QUIRK_NO_MUXPSR)
505 || (clk_id == SAMSUNG_I2S_RCLKSRC_0)) 521 || (clk_id == SAMSUNG_I2S_RCLKSRC_0))
506 clk_id = 0; 522 clk_id = 0;
@@ -550,18 +566,19 @@ static int i2s_set_sysclk(struct snd_soc_dai *dai,
550 return 0; 566 return 0;
551 } 567 }
552 568
553 if (clk_id == 0) 569 if (clk_id == 1)
554 mod &= ~(1 << i2s_regs->rclksrc_off); 570 val = 1 << i2s_regs->rclksrc_off;
555 else
556 mod |= 1 << i2s_regs->rclksrc_off;
557
558 break; 571 break;
559 default: 572 default:
560 dev_err(&i2s->pdev->dev, "We don't serve that!\n"); 573 dev_err(&i2s->pdev->dev, "We don't serve that!\n");
561 return -EINVAL; 574 return -EINVAL;
562 } 575 }
563 576
577 spin_lock(i2s->lock);
578 mod = readl(i2s->addr + I2SMOD);
579 mod = (mod & ~mask) | val;
564 writel(mod, i2s->addr + I2SMOD); 580 writel(mod, i2s->addr + I2SMOD);
581 spin_unlock(i2s->lock);
565 582
566 return 0; 583 return 0;
567} 584}
@@ -570,9 +587,8 @@ static int i2s_set_fmt(struct snd_soc_dai *dai,
570 unsigned int fmt) 587 unsigned int fmt)
571{ 588{
572 struct i2s_dai *i2s = to_info(dai); 589 struct i2s_dai *i2s = to_info(dai);
573 u32 mod = readl(i2s->addr + I2SMOD);
574 int lrp_shift, sdf_shift, sdf_mask, lrp_rlow, mod_slave; 590 int lrp_shift, sdf_shift, sdf_mask, lrp_rlow, mod_slave;
575 u32 tmp = 0; 591 u32 mod, tmp = 0;
576 592
577 lrp_shift = i2s->variant_regs->lrp_off; 593 lrp_shift = i2s->variant_regs->lrp_off;
578 sdf_shift = i2s->variant_regs->sdf_off; 594 sdf_shift = i2s->variant_regs->sdf_off;
@@ -632,12 +648,15 @@ static int i2s_set_fmt(struct snd_soc_dai *dai,
632 return -EINVAL; 648 return -EINVAL;
633 } 649 }
634 650
651 spin_lock(i2s->lock);
652 mod = readl(i2s->addr + I2SMOD);
635 /* 653 /*
636 * Don't change the I2S mode if any controller is active on this 654 * Don't change the I2S mode if any controller is active on this
637 * channel. 655 * channel.
638 */ 656 */
639 if (any_active(i2s) && 657 if (any_active(i2s) &&
640 ((mod & (sdf_mask | lrp_rlow | mod_slave)) != tmp)) { 658 ((mod & (sdf_mask | lrp_rlow | mod_slave)) != tmp)) {
659 spin_unlock(i2s->lock);
641 dev_err(&i2s->pdev->dev, 660 dev_err(&i2s->pdev->dev,
642 "%s:%d Other DAI busy\n", __func__, __LINE__); 661 "%s:%d Other DAI busy\n", __func__, __LINE__);
643 return -EAGAIN; 662 return -EAGAIN;
@@ -646,6 +665,7 @@ static int i2s_set_fmt(struct snd_soc_dai *dai,
646 mod &= ~(sdf_mask | lrp_rlow | mod_slave); 665 mod &= ~(sdf_mask | lrp_rlow | mod_slave);
647 mod |= tmp; 666 mod |= tmp;
648 writel(mod, i2s->addr + I2SMOD); 667 writel(mod, i2s->addr + I2SMOD);
668 spin_unlock(i2s->lock);
649 669
650 return 0; 670 return 0;
651} 671}
@@ -654,16 +674,16 @@ static int i2s_hw_params(struct snd_pcm_substream *substream,
654 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) 674 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
655{ 675{
656 struct i2s_dai *i2s = to_info(dai); 676 struct i2s_dai *i2s = to_info(dai);
657 u32 mod = readl(i2s->addr + I2SMOD); 677 u32 mod, mask = 0, val = 0;
658 678
659 if (!is_secondary(i2s)) 679 if (!is_secondary(i2s))
660 mod &= ~(MOD_DC2_EN | MOD_DC1_EN); 680 mask |= (MOD_DC2_EN | MOD_DC1_EN);
661 681
662 switch (params_channels(params)) { 682 switch (params_channels(params)) {
663 case 6: 683 case 6:
664 mod |= MOD_DC2_EN; 684 val |= MOD_DC2_EN;
665 case 4: 685 case 4:
666 mod |= MOD_DC1_EN; 686 val |= MOD_DC1_EN;
667 break; 687 break;
668 case 2: 688 case 2:
669 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 689 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
@@ -685,44 +705,49 @@ static int i2s_hw_params(struct snd_pcm_substream *substream,
685 } 705 }
686 706
687 if (is_secondary(i2s)) 707 if (is_secondary(i2s))
688 mod &= ~MOD_BLCS_MASK; 708 mask |= MOD_BLCS_MASK;
689 else 709 else
690 mod &= ~MOD_BLCP_MASK; 710 mask |= MOD_BLCP_MASK;
691 711
692 if (is_manager(i2s)) 712 if (is_manager(i2s))
693 mod &= ~MOD_BLC_MASK; 713 mask |= MOD_BLC_MASK;
694 714
695 switch (params_width(params)) { 715 switch (params_width(params)) {
696 case 8: 716 case 8:
697 if (is_secondary(i2s)) 717 if (is_secondary(i2s))
698 mod |= MOD_BLCS_8BIT; 718 val |= MOD_BLCS_8BIT;
699 else 719 else
700 mod |= MOD_BLCP_8BIT; 720 val |= MOD_BLCP_8BIT;
701 if (is_manager(i2s)) 721 if (is_manager(i2s))
702 mod |= MOD_BLC_8BIT; 722 val |= MOD_BLC_8BIT;
703 break; 723 break;
704 case 16: 724 case 16:
705 if (is_secondary(i2s)) 725 if (is_secondary(i2s))
706 mod |= MOD_BLCS_16BIT; 726 val |= MOD_BLCS_16BIT;
707 else 727 else
708 mod |= MOD_BLCP_16BIT; 728 val |= MOD_BLCP_16BIT;
709 if (is_manager(i2s)) 729 if (is_manager(i2s))
710 mod |= MOD_BLC_16BIT; 730 val |= MOD_BLC_16BIT;
711 break; 731 break;
712 case 24: 732 case 24:
713 if (is_secondary(i2s)) 733 if (is_secondary(i2s))
714 mod |= MOD_BLCS_24BIT; 734 val |= MOD_BLCS_24BIT;
715 else 735 else
716 mod |= MOD_BLCP_24BIT; 736 val |= MOD_BLCP_24BIT;
717 if (is_manager(i2s)) 737 if (is_manager(i2s))
718 mod |= MOD_BLC_24BIT; 738 val |= MOD_BLC_24BIT;
719 break; 739 break;
720 default: 740 default:
721 dev_err(&i2s->pdev->dev, "Format(%d) not supported\n", 741 dev_err(&i2s->pdev->dev, "Format(%d) not supported\n",
722 params_format(params)); 742 params_format(params));
723 return -EINVAL; 743 return -EINVAL;
724 } 744 }
745
746 spin_lock(i2s->lock);
747 mod = readl(i2s->addr + I2SMOD);
748 mod = (mod & ~mask) | val;
725 writel(mod, i2s->addr + I2SMOD); 749 writel(mod, i2s->addr + I2SMOD);
750 spin_unlock(i2s->lock);
726 751
727 samsung_asoc_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture); 752 samsung_asoc_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture);
728 753
@@ -736,7 +761,7 @@ static int i2s_startup(struct snd_pcm_substream *substream,
736 struct snd_soc_dai *dai) 761 struct snd_soc_dai *dai)
737{ 762{
738 struct i2s_dai *i2s = to_info(dai); 763 struct i2s_dai *i2s = to_info(dai);
739 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 764 struct i2s_dai *other = get_other_dai(i2s);
740 unsigned long flags; 765 unsigned long flags;
741 766
742 spin_lock_irqsave(&lock, flags); 767 spin_lock_irqsave(&lock, flags);
@@ -753,9 +778,6 @@ static int i2s_startup(struct snd_pcm_substream *substream,
753 778
754 spin_unlock_irqrestore(&lock, flags); 779 spin_unlock_irqrestore(&lock, flags);
755 780
756 if (!is_opened(other) && i2s->cdclk_out)
757 i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
758 0, SND_SOC_CLOCK_OUT);
759 return 0; 781 return 0;
760} 782}
761 783
@@ -763,38 +785,27 @@ static void i2s_shutdown(struct snd_pcm_substream *substream,
763 struct snd_soc_dai *dai) 785 struct snd_soc_dai *dai)
764{ 786{
765 struct i2s_dai *i2s = to_info(dai); 787 struct i2s_dai *i2s = to_info(dai);
766 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 788 struct i2s_dai *other = get_other_dai(i2s);
767 unsigned long flags; 789 unsigned long flags;
768 const struct samsung_i2s_variant_regs *i2s_regs = i2s->variant_regs;
769 790
770 spin_lock_irqsave(&lock, flags); 791 spin_lock_irqsave(&lock, flags);
771 792
772 i2s->mode &= ~DAI_OPENED; 793 i2s->mode &= ~DAI_OPENED;
773 i2s->mode &= ~DAI_MANAGER; 794 i2s->mode &= ~DAI_MANAGER;
774 795
775 if (is_opened(other)) { 796 if (is_opened(other))
776 other->mode |= DAI_MANAGER; 797 other->mode |= DAI_MANAGER;
777 } else { 798
778 u32 mod = readl(i2s->addr + I2SMOD);
779 i2s->cdclk_out = !(mod & (1 << i2s_regs->cdclkcon_off));
780 if (other)
781 other->cdclk_out = i2s->cdclk_out;
782 }
783 /* Reset any constraint on RFS and BFS */ 799 /* Reset any constraint on RFS and BFS */
784 i2s->rfs = 0; 800 i2s->rfs = 0;
785 i2s->bfs = 0; 801 i2s->bfs = 0;
786 802
787 spin_unlock_irqrestore(&lock, flags); 803 spin_unlock_irqrestore(&lock, flags);
788
789 /* Gate CDCLK by default */
790 if (!is_opened(other))
791 i2s_set_sysclk(dai, SAMSUNG_I2S_CDCLK,
792 0, SND_SOC_CLOCK_IN);
793} 804}
794 805
795static int config_setup(struct i2s_dai *i2s) 806static int config_setup(struct i2s_dai *i2s)
796{ 807{
797 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 808 struct i2s_dai *other = get_other_dai(i2s);
798 unsigned rfs, bfs, blc; 809 unsigned rfs, bfs, blc;
799 u32 psr; 810 u32 psr;
800 811
@@ -864,10 +875,10 @@ static int i2s_trigger(struct snd_pcm_substream *substream,
864 case SNDRV_PCM_TRIGGER_START: 875 case SNDRV_PCM_TRIGGER_START:
865 case SNDRV_PCM_TRIGGER_RESUME: 876 case SNDRV_PCM_TRIGGER_RESUME:
866 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 877 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
867 local_irq_save(flags); 878 spin_lock_irqsave(i2s->lock, flags);
868 879
869 if (config_setup(i2s)) { 880 if (config_setup(i2s)) {
870 local_irq_restore(flags); 881 spin_unlock_irqrestore(i2s->lock, flags);
871 return -EINVAL; 882 return -EINVAL;
872 } 883 }
873 884
@@ -876,12 +887,12 @@ static int i2s_trigger(struct snd_pcm_substream *substream,
876 else 887 else
877 i2s_txctrl(i2s, 1); 888 i2s_txctrl(i2s, 1);
878 889
879 local_irq_restore(flags); 890 spin_unlock_irqrestore(i2s->lock, flags);
880 break; 891 break;
881 case SNDRV_PCM_TRIGGER_STOP: 892 case SNDRV_PCM_TRIGGER_STOP:
882 case SNDRV_PCM_TRIGGER_SUSPEND: 893 case SNDRV_PCM_TRIGGER_SUSPEND:
883 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 894 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
884 local_irq_save(flags); 895 spin_lock_irqsave(i2s->lock, flags);
885 896
886 if (capture) { 897 if (capture) {
887 i2s_rxctrl(i2s, 0); 898 i2s_rxctrl(i2s, 0);
@@ -891,7 +902,7 @@ static int i2s_trigger(struct snd_pcm_substream *substream,
891 i2s_fifo(i2s, FIC_TXFLUSH); 902 i2s_fifo(i2s, FIC_TXFLUSH);
892 } 903 }
893 904
894 local_irq_restore(flags); 905 spin_unlock_irqrestore(i2s->lock, flags);
895 break; 906 break;
896 } 907 }
897 908
@@ -902,7 +913,7 @@ static int i2s_set_clkdiv(struct snd_soc_dai *dai,
902 int div_id, int div) 913 int div_id, int div)
903{ 914{
904 struct i2s_dai *i2s = to_info(dai); 915 struct i2s_dai *i2s = to_info(dai);
905 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 916 struct i2s_dai *other = get_other_dai(i2s);
906 917
907 switch (div_id) { 918 switch (div_id) {
908 case SAMSUNG_I2S_DIV_BCLK: 919 case SAMSUNG_I2S_DIV_BCLK:
@@ -971,58 +982,36 @@ static int i2s_resume(struct snd_soc_dai *dai)
971static int samsung_i2s_dai_probe(struct snd_soc_dai *dai) 982static int samsung_i2s_dai_probe(struct snd_soc_dai *dai)
972{ 983{
973 struct i2s_dai *i2s = to_info(dai); 984 struct i2s_dai *i2s = to_info(dai);
974 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai; 985 struct i2s_dai *other = get_other_dai(i2s);
975 int ret; 986 unsigned long flags;
976 987
977 if (other && other->clk) { /* If this is probe on secondary */ 988 if (is_secondary(i2s)) { /* If this is probe on the secondary DAI */
978 samsung_asoc_init_dma_data(dai, &other->sec_dai->dma_playback, 989 samsung_asoc_init_dma_data(dai, &other->sec_dai->dma_playback,
979 NULL); 990 NULL);
980 goto probe_exit; 991 } else {
981 } 992 samsung_asoc_init_dma_data(dai, &i2s->dma_playback,
982 993 &i2s->dma_capture);
983 i2s->addr = ioremap(i2s->base, 0x100);
984 if (i2s->addr == NULL) {
985 dev_err(&i2s->pdev->dev, "cannot ioremap registers\n");
986 return -ENXIO;
987 }
988
989 i2s->clk = clk_get(&i2s->pdev->dev, "iis");
990 if (IS_ERR(i2s->clk)) {
991 dev_err(&i2s->pdev->dev, "failed to get i2s_clock\n");
992 iounmap(i2s->addr);
993 return PTR_ERR(i2s->clk);
994 }
995
996 ret = clk_prepare_enable(i2s->clk);
997 if (ret != 0) {
998 dev_err(&i2s->pdev->dev, "failed to enable clock: %d\n", ret);
999 return ret;
1000 }
1001
1002 samsung_asoc_init_dma_data(dai, &i2s->dma_playback, &i2s->dma_capture);
1003
1004 if (other) {
1005 other->addr = i2s->addr;
1006 other->clk = i2s->clk;
1007 }
1008 994
1009 if (i2s->quirks & QUIRK_NEED_RSTCLR) 995 if (i2s->quirks & QUIRK_NEED_RSTCLR)
1010 writel(CON_RSTCLR, i2s->addr + I2SCON); 996 writel(CON_RSTCLR, i2s->addr + I2SCON);
1011 997
1012 if (i2s->quirks & QUIRK_SUPPORTS_IDMA) 998 if (i2s->quirks & QUIRK_SUPPORTS_IDMA)
1013 idma_reg_addr_init(i2s->addr, 999 idma_reg_addr_init(i2s->addr,
1014 i2s->sec_dai->idma_playback.dma_addr); 1000 i2s->sec_dai->idma_playback.dma_addr);
1001 }
1015 1002
1016probe_exit:
1017 /* Reset any constraint on RFS and BFS */ 1003 /* Reset any constraint on RFS and BFS */
1018 i2s->rfs = 0; 1004 i2s->rfs = 0;
1019 i2s->bfs = 0; 1005 i2s->bfs = 0;
1020 i2s->rclk_srcrate = 0; 1006 i2s->rclk_srcrate = 0;
1007
1008 spin_lock_irqsave(i2s->lock, flags);
1021 i2s_txctrl(i2s, 0); 1009 i2s_txctrl(i2s, 0);
1022 i2s_rxctrl(i2s, 0); 1010 i2s_rxctrl(i2s, 0);
1023 i2s_fifo(i2s, FIC_TXFLUSH); 1011 i2s_fifo(i2s, FIC_TXFLUSH);
1024 i2s_fifo(other, FIC_TXFLUSH); 1012 i2s_fifo(other, FIC_TXFLUSH);
1025 i2s_fifo(i2s, FIC_RXFLUSH); 1013 i2s_fifo(i2s, FIC_RXFLUSH);
1014 spin_unlock_irqrestore(i2s->lock, flags);
1026 1015
1027 /* Gate CDCLK by default */ 1016 /* Gate CDCLK by default */
1028 if (!is_opened(other)) 1017 if (!is_opened(other))
@@ -1035,21 +1024,15 @@ probe_exit:
1035static int samsung_i2s_dai_remove(struct snd_soc_dai *dai) 1024static int samsung_i2s_dai_remove(struct snd_soc_dai *dai)
1036{ 1025{
1037 struct i2s_dai *i2s = snd_soc_dai_get_drvdata(dai); 1026 struct i2s_dai *i2s = snd_soc_dai_get_drvdata(dai);
1038 struct i2s_dai *other = i2s->pri_dai ? : i2s->sec_dai;
1039
1040 if (!other || !other->clk) {
1041 1027
1042 if (i2s->quirks & QUIRK_NEED_RSTCLR) 1028 if (!is_secondary(i2s)) {
1029 if (i2s->quirks & QUIRK_NEED_RSTCLR) {
1030 spin_lock(i2s->lock);
1043 writel(0, i2s->addr + I2SCON); 1031 writel(0, i2s->addr + I2SCON);
1044 1032 spin_unlock(i2s->lock);
1045 clk_disable_unprepare(i2s->clk); 1033 }
1046 clk_put(i2s->clk);
1047
1048 iounmap(i2s->addr);
1049 } 1034 }
1050 1035
1051 i2s->clk = NULL;
1052
1053 return 0; 1036 return 0;
1054} 1037}
1055 1038
@@ -1124,15 +1107,14 @@ static const struct of_device_id exynos_i2s_match[];
1124static inline const struct samsung_i2s_dai_data *samsung_i2s_get_driver_data( 1107static inline const struct samsung_i2s_dai_data *samsung_i2s_get_driver_data(
1125 struct platform_device *pdev) 1108 struct platform_device *pdev)
1126{ 1109{
1127#ifdef CONFIG_OF 1110 if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
1128 if (pdev->dev.of_node) {
1129 const struct of_device_id *match; 1111 const struct of_device_id *match;
1130 match = of_match_node(exynos_i2s_match, pdev->dev.of_node); 1112 match = of_match_node(exynos_i2s_match, pdev->dev.of_node);
1131 return match->data; 1113 return match ? match->data : NULL;
1132 } else 1114 } else {
1133#endif
1134 return (struct samsung_i2s_dai_data *) 1115 return (struct samsung_i2s_dai_data *)
1135 platform_get_device_id(pdev)->driver_data; 1116 platform_get_device_id(pdev)->driver_data;
1117 }
1136} 1118}
1137 1119
1138#ifdef CONFIG_PM 1120#ifdef CONFIG_PM
@@ -1155,6 +1137,87 @@ static int i2s_runtime_resume(struct device *dev)
1155} 1137}
1156#endif /* CONFIG_PM */ 1138#endif /* CONFIG_PM */
1157 1139
1140static void i2s_unregister_clocks(struct i2s_dai *i2s)
1141{
1142 int i;
1143
1144 for (i = 0; i < i2s->clk_data.clk_num; i++) {
1145 if (!IS_ERR(i2s->clk_table[i]))
1146 clk_unregister(i2s->clk_table[i]);
1147 }
1148}
1149
1150static void i2s_unregister_clock_provider(struct platform_device *pdev)
1151{
1152 struct i2s_dai *i2s = dev_get_drvdata(&pdev->dev);
1153
1154 of_clk_del_provider(pdev->dev.of_node);
1155 i2s_unregister_clocks(i2s);
1156}
1157
1158static int i2s_register_clock_provider(struct platform_device *pdev)
1159{
1160 struct device *dev = &pdev->dev;
1161 struct i2s_dai *i2s = dev_get_drvdata(dev);
1162 const char *clk_name[2] = { "i2s_opclk0", "i2s_opclk1" };
1163 const char *p_names[2] = { NULL };
1164 const struct samsung_i2s_variant_regs *reg_info = i2s->variant_regs;
1165 struct clk *rclksrc;
1166 int ret, i;
1167
1168 /* Register the clock provider only if it's expected in the DTB */
1169 if (!of_find_property(dev->of_node, "#clock-cells", NULL))
1170 return 0;
1171
1172 /* Get the RCLKSRC mux clock parent clock names */
1173 for (i = 0; i < ARRAY_SIZE(p_names); i++) {
1174 rclksrc = clk_get(dev, clk_name[i]);
1175 if (IS_ERR(rclksrc))
1176 continue;
1177 p_names[i] = __clk_get_name(rclksrc);
1178 clk_put(rclksrc);
1179 }
1180
1181 if (!(i2s->quirks & QUIRK_NO_MUXPSR)) {
1182 /* Activate the prescaler */
1183 u32 val = readl(i2s->addr + I2SPSR);
1184 writel(val | PSR_PSREN, i2s->addr + I2SPSR);
1185
1186 i2s->clk_table[CLK_I2S_RCLK_SRC] = clk_register_mux(NULL,
1187 "i2s_rclksrc", p_names, ARRAY_SIZE(p_names),
1188 CLK_SET_RATE_NO_REPARENT | CLK_SET_RATE_PARENT,
1189 i2s->addr + I2SMOD, reg_info->rclksrc_off,
1190 1, 0, i2s->lock);
1191
1192 i2s->clk_table[CLK_I2S_RCLK_PSR] = clk_register_divider(NULL,
1193 "i2s_presc", "i2s_rclksrc",
1194 CLK_SET_RATE_PARENT,
1195 i2s->addr + I2SPSR, 8, 6, 0, i2s->lock);
1196
1197 p_names[0] = "i2s_presc";
1198 i2s->clk_data.clk_num = 2;
1199 }
1200 of_property_read_string_index(dev->of_node,
1201 "clock-output-names", 0, &clk_name[0]);
1202
1203 i2s->clk_table[CLK_I2S_CDCLK] = clk_register_gate(NULL, clk_name[0],
1204 p_names[0], CLK_SET_RATE_PARENT,
1205 i2s->addr + I2SMOD, reg_info->cdclkcon_off,
1206 CLK_GATE_SET_TO_DISABLE, i2s->lock);
1207
1208 i2s->clk_data.clk_num += 1;
1209 i2s->clk_data.clks = i2s->clk_table;
1210
1211 ret = of_clk_add_provider(dev->of_node, of_clk_src_onecell_get,
1212 &i2s->clk_data);
1213 if (ret < 0) {
1214 dev_err(dev, "failed to add clock provider: %d\n", ret);
1215 i2s_unregister_clocks(i2s);
1216 }
1217
1218 return ret;
1219}
1220
1158static int samsung_i2s_probe(struct platform_device *pdev) 1221static int samsung_i2s_probe(struct platform_device *pdev)
1159{ 1222{
1160 struct i2s_dai *pri_dai, *sec_dai = NULL; 1223 struct i2s_dai *pri_dai, *sec_dai = NULL;
@@ -1164,7 +1227,7 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1164 u32 regs_base, quirks = 0, idma_addr = 0; 1227 u32 regs_base, quirks = 0, idma_addr = 0;
1165 struct device_node *np = pdev->dev.of_node; 1228 struct device_node *np = pdev->dev.of_node;
1166 const struct samsung_i2s_dai_data *i2s_dai_data; 1229 const struct samsung_i2s_dai_data *i2s_dai_data;
1167 int ret = 0; 1230 int ret;
1168 1231
1169 /* Call during Seconday interface registration */ 1232 /* Call during Seconday interface registration */
1170 i2s_dai_data = samsung_i2s_get_driver_data(pdev); 1233 i2s_dai_data = samsung_i2s_get_driver_data(pdev);
@@ -1175,11 +1238,13 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1175 dev_err(&pdev->dev, "Unable to get drvdata\n"); 1238 dev_err(&pdev->dev, "Unable to get drvdata\n");
1176 return -EFAULT; 1239 return -EFAULT;
1177 } 1240 }
1178 devm_snd_soc_register_component(&sec_dai->pdev->dev, 1241 ret = devm_snd_soc_register_component(&sec_dai->pdev->dev,
1179 &samsung_i2s_component, 1242 &samsung_i2s_component,
1180 &sec_dai->i2s_dai_drv, 1); 1243 &sec_dai->i2s_dai_drv, 1);
1181 samsung_asoc_dma_platform_register(&pdev->dev); 1244 if (ret != 0)
1182 return 0; 1245 return ret;
1246
1247 return samsung_asoc_dma_platform_register(&pdev->dev);
1183 } 1248 }
1184 1249
1185 pri_dai = i2s_alloc_dai(pdev, false); 1250 pri_dai = i2s_alloc_dai(pdev, false);
@@ -1188,6 +1253,9 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1188 return -ENOMEM; 1253 return -ENOMEM;
1189 } 1254 }
1190 1255
1256 spin_lock_init(&pri_dai->spinlock);
1257 pri_dai->lock = &pri_dai->spinlock;
1258
1191 if (!np) { 1259 if (!np) {
1192 res = platform_get_resource(pdev, IORESOURCE_DMA, 0); 1260 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1193 if (!res) { 1261 if (!res) {
@@ -1229,25 +1297,29 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1229 } 1297 }
1230 1298
1231 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1299 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1232 if (!res) { 1300 pri_dai->addr = devm_ioremap_resource(&pdev->dev, res);
1233 dev_err(&pdev->dev, "Unable to get I2S SFR address\n"); 1301 if (IS_ERR(pri_dai->addr))
1234 return -ENXIO; 1302 return PTR_ERR(pri_dai->addr);
1235 }
1236 1303
1237 if (!request_mem_region(res->start, resource_size(res),
1238 "samsung-i2s")) {
1239 dev_err(&pdev->dev, "Unable to request SFR region\n");
1240 return -EBUSY;
1241 }
1242 regs_base = res->start; 1304 regs_base = res->start;
1243 1305
1306 pri_dai->clk = devm_clk_get(&pdev->dev, "iis");
1307 if (IS_ERR(pri_dai->clk)) {
1308 dev_err(&pdev->dev, "Failed to get iis clock\n");
1309 return PTR_ERR(pri_dai->clk);
1310 }
1311
1312 ret = clk_prepare_enable(pri_dai->clk);
1313 if (ret != 0) {
1314 dev_err(&pdev->dev, "failed to enable clock: %d\n", ret);
1315 return ret;
1316 }
1244 pri_dai->dma_playback.dma_addr = regs_base + I2STXD; 1317 pri_dai->dma_playback.dma_addr = regs_base + I2STXD;
1245 pri_dai->dma_capture.dma_addr = regs_base + I2SRXD; 1318 pri_dai->dma_capture.dma_addr = regs_base + I2SRXD;
1246 pri_dai->dma_playback.ch_name = "tx"; 1319 pri_dai->dma_playback.ch_name = "tx";
1247 pri_dai->dma_capture.ch_name = "rx"; 1320 pri_dai->dma_capture.ch_name = "rx";
1248 pri_dai->dma_playback.dma_size = 4; 1321 pri_dai->dma_playback.dma_size = 4;
1249 pri_dai->dma_capture.dma_size = 4; 1322 pri_dai->dma_capture.dma_size = 4;
1250 pri_dai->base = regs_base;
1251 pri_dai->quirks = quirks; 1323 pri_dai->quirks = quirks;
1252 pri_dai->variant_regs = i2s_dai_data->i2s_variant_regs; 1324 pri_dai->variant_regs = i2s_dai_data->i2s_variant_regs;
1253 1325
@@ -1258,10 +1330,10 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1258 sec_dai = i2s_alloc_dai(pdev, true); 1330 sec_dai = i2s_alloc_dai(pdev, true);
1259 if (!sec_dai) { 1331 if (!sec_dai) {
1260 dev_err(&pdev->dev, "Unable to alloc I2S_sec\n"); 1332 dev_err(&pdev->dev, "Unable to alloc I2S_sec\n");
1261 ret = -ENOMEM; 1333 return -ENOMEM;
1262 goto err;
1263 } 1334 }
1264 1335
1336 sec_dai->lock = &pri_dai->spinlock;
1265 sec_dai->variant_regs = pri_dai->variant_regs; 1337 sec_dai->variant_regs = pri_dai->variant_regs;
1266 sec_dai->dma_playback.dma_addr = regs_base + I2STXDS; 1338 sec_dai->dma_playback.dma_addr = regs_base + I2STXDS;
1267 sec_dai->dma_playback.ch_name = "tx-sec"; 1339 sec_dai->dma_playback.ch_name = "tx-sec";
@@ -1273,7 +1345,8 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1273 } 1345 }
1274 1346
1275 sec_dai->dma_playback.dma_size = 4; 1347 sec_dai->dma_playback.dma_size = 4;
1276 sec_dai->base = regs_base; 1348 sec_dai->addr = pri_dai->addr;
1349 sec_dai->clk = pri_dai->clk;
1277 sec_dai->quirks = quirks; 1350 sec_dai->quirks = quirks;
1278 sec_dai->idma_playback.dma_addr = idma_addr; 1351 sec_dai->idma_playback.dma_addr = idma_addr;
1279 sec_dai->pri_dai = pri_dai; 1352 sec_dai->pri_dai = pri_dai;
@@ -1282,8 +1355,7 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1282 1355
1283 if (i2s_pdata && i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) { 1356 if (i2s_pdata && i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
1284 dev_err(&pdev->dev, "Unable to configure gpio\n"); 1357 dev_err(&pdev->dev, "Unable to configure gpio\n");
1285 ret = -EINVAL; 1358 return -EINVAL;
1286 goto err;
1287 } 1359 }
1288 1360
1289 devm_snd_soc_register_component(&pri_dai->pdev->dev, 1361 devm_snd_soc_register_component(&pri_dai->pdev->dev,
@@ -1292,32 +1364,30 @@ static int samsung_i2s_probe(struct platform_device *pdev)
1292 1364
1293 pm_runtime_enable(&pdev->dev); 1365 pm_runtime_enable(&pdev->dev);
1294 1366
1295 samsung_asoc_dma_platform_register(&pdev->dev); 1367 ret = samsung_asoc_dma_platform_register(&pdev->dev);
1296 1368 if (ret != 0)
1297 return 0; 1369 return ret;
1298err:
1299 if (res)
1300 release_mem_region(regs_base, resource_size(res));
1301 1370
1302 return ret; 1371 return i2s_register_clock_provider(pdev);
1303} 1372}
1304 1373
1305static int samsung_i2s_remove(struct platform_device *pdev) 1374static int samsung_i2s_remove(struct platform_device *pdev)
1306{ 1375{
1307 struct i2s_dai *i2s, *other; 1376 struct i2s_dai *i2s, *other;
1308 struct resource *res;
1309 1377
1310 i2s = dev_get_drvdata(&pdev->dev); 1378 i2s = dev_get_drvdata(&pdev->dev);
1311 other = i2s->pri_dai ? : i2s->sec_dai; 1379 other = get_other_dai(i2s);
1312 1380
1313 if (other) { 1381 if (other) {
1314 other->pri_dai = NULL; 1382 other->pri_dai = NULL;
1315 other->sec_dai = NULL; 1383 other->sec_dai = NULL;
1316 } else { 1384 } else {
1317 pm_runtime_disable(&pdev->dev); 1385 pm_runtime_disable(&pdev->dev);
1318 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1386 }
1319 if (res) 1387
1320 release_mem_region(res->start, resource_size(res)); 1388 if (!is_secondary(i2s)) {
1389 i2s_unregister_clock_provider(pdev);
1390 clk_disable_unprepare(i2s->clk);
1321 } 1391 }
1322 1392
1323 i2s->pri_dai = NULL; 1393 i2s->pri_dai = NULL;
diff --git a/sound/soc/samsung/jive_wm8750.c b/sound/soc/samsung/jive_wm8750.c
index b5f6abd9d221..7fcb51faa2a0 100644
--- a/sound/soc/samsung/jive_wm8750.c
+++ b/sound/soc/samsung/jive_wm8750.c
@@ -61,20 +61,6 @@ static int jive_hw_params(struct snd_pcm_substream *substream,
61 s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params), 61 s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params),
62 s3c_i2sv2_get_clock(cpu_dai)); 62 s3c_i2sv2_get_clock(cpu_dai));
63 63
64 /* set codec DAI configuration */
65 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
66 SND_SOC_DAIFMT_NB_NF |
67 SND_SOC_DAIFMT_CBS_CFS);
68 if (ret < 0)
69 return ret;
70
71 /* set cpu DAI configuration */
72 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
73 SND_SOC_DAIFMT_NB_NF |
74 SND_SOC_DAIFMT_CBS_CFS);
75 if (ret < 0)
76 return ret;
77
78 /* set the codec system clock for DAC and ADC */ 64 /* set the codec system clock for DAC and ADC */
79 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk, 65 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
80 SND_SOC_CLOCK_IN); 66 SND_SOC_CLOCK_IN);
@@ -97,22 +83,6 @@ static struct snd_soc_ops jive_ops = {
97 .hw_params = jive_hw_params, 83 .hw_params = jive_hw_params,
98}; 84};
99 85
100static int jive_wm8750_init(struct snd_soc_pcm_runtime *rtd)
101{
102 struct snd_soc_codec *codec = rtd->codec;
103 struct snd_soc_dapm_context *dapm = &codec->dapm;
104
105 /* These endpoints are not being used. */
106 snd_soc_dapm_nc_pin(dapm, "LINPUT2");
107 snd_soc_dapm_nc_pin(dapm, "RINPUT2");
108 snd_soc_dapm_nc_pin(dapm, "LINPUT3");
109 snd_soc_dapm_nc_pin(dapm, "RINPUT3");
110 snd_soc_dapm_nc_pin(dapm, "OUT3");
111 snd_soc_dapm_nc_pin(dapm, "MONO");
112
113 return 0;
114}
115
116static struct snd_soc_dai_link jive_dai = { 86static struct snd_soc_dai_link jive_dai = {
117 .name = "wm8750", 87 .name = "wm8750",
118 .stream_name = "WM8750", 88 .stream_name = "WM8750",
@@ -120,7 +90,8 @@ static struct snd_soc_dai_link jive_dai = {
120 .codec_dai_name = "wm8750-hifi", 90 .codec_dai_name = "wm8750-hifi",
121 .platform_name = "s3c2412-i2s", 91 .platform_name = "s3c2412-i2s",
122 .codec_name = "wm8750.0-001a", 92 .codec_name = "wm8750.0-001a",
123 .init = jive_wm8750_init, 93 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
94 SND_SOC_DAIFMT_CBS_CFS,
124 .ops = &jive_ops, 95 .ops = &jive_ops,
125}; 96};
126 97
@@ -135,6 +106,7 @@ static struct snd_soc_card snd_soc_machine_jive = {
135 .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets), 106 .num_dapm_widgets = ARRAY_SIZE(wm8750_dapm_widgets),
136 .dapm_routes = audio_map, 107 .dapm_routes = audio_map,
137 .num_dapm_routes = ARRAY_SIZE(audio_map), 108 .num_dapm_routes = ARRAY_SIZE(audio_map),
109 .fully_routed = true,
138}; 110};
139 111
140static struct platform_device *jive_snd_device; 112static struct platform_device *jive_snd_device;
diff --git a/sound/soc/samsung/neo1973_wm8753.c b/sound/soc/samsung/neo1973_wm8753.c
index 9b4a09f14b6c..65602b935377 100644
--- a/sound/soc/samsung/neo1973_wm8753.c
+++ b/sound/soc/samsung/neo1973_wm8753.c
@@ -70,20 +70,6 @@ static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
70 break; 70 break;
71 } 71 }
72 72
73 /* set codec DAI configuration */
74 ret = snd_soc_dai_set_fmt(codec_dai,
75 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
76 SND_SOC_DAIFMT_CBM_CFM);
77 if (ret < 0)
78 return ret;
79
80 /* set cpu DAI configuration */
81 ret = snd_soc_dai_set_fmt(cpu_dai,
82 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
83 SND_SOC_DAIFMT_CBM_CFM);
84 if (ret < 0)
85 return ret;
86
87 /* set the codec system clock for DAC and ADC */ 73 /* set the codec system clock for DAC and ADC */
88 ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_MCLK, pll_out, 74 ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_MCLK, pll_out,
89 SND_SOC_CLOCK_IN); 75 SND_SOC_CLOCK_IN);
@@ -151,13 +137,6 @@ static int neo1973_voice_hw_params(struct snd_pcm_substream *substream,
151 137
152 pcmdiv = WM8753_PCM_DIV_6; /* 2.048 MHz */ 138 pcmdiv = WM8753_PCM_DIV_6; /* 2.048 MHz */
153 139
154 /* todo: gg check mode (DSP_B) against CSR datasheet */
155 /* set codec DAI configuration */
156 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B |
157 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
158 if (ret < 0)
159 return ret;
160
161 /* set the codec system clock for DAC and ADC */ 140 /* set the codec system clock for DAC and ADC */
162 ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_PCMCLK, 12288000, 141 ret = snd_soc_dai_set_sysclk(codec_dai, WM8753_PCMCLK, 12288000,
163 SND_SOC_CLOCK_IN); 142 SND_SOC_CLOCK_IN);
@@ -300,6 +279,8 @@ static struct snd_soc_dai_link neo1973_dai[] = {
300 .cpu_dai_name = "s3c24xx-iis", 279 .cpu_dai_name = "s3c24xx-iis",
301 .codec_dai_name = "wm8753-hifi", 280 .codec_dai_name = "wm8753-hifi",
302 .codec_name = "wm8753.0-001a", 281 .codec_name = "wm8753.0-001a",
282 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
283 SND_SOC_DAIFMT_CBM_CFM,
303 .init = neo1973_wm8753_init, 284 .init = neo1973_wm8753_init,
304 .ops = &neo1973_hifi_ops, 285 .ops = &neo1973_hifi_ops,
305}, 286},
@@ -309,6 +290,8 @@ static struct snd_soc_dai_link neo1973_dai[] = {
309 .cpu_dai_name = "bt-sco-pcm", 290 .cpu_dai_name = "bt-sco-pcm",
310 .codec_dai_name = "wm8753-voice", 291 .codec_dai_name = "wm8753-voice",
311 .codec_name = "wm8753.0-001a", 292 .codec_name = "wm8753.0-001a",
293 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
294 SND_SOC_DAIFMT_CBS_CFS,
312 .ops = &neo1973_voice_ops, 295 .ops = &neo1973_voice_ops,
313}, 296},
314}; 297};
diff --git a/sound/soc/samsung/odroidx2_max98090.c b/sound/soc/samsung/odroidx2_max98090.c
index fa4f1d2f69bf..596f1180a369 100644
--- a/sound/soc/samsung/odroidx2_max98090.c
+++ b/sound/soc/samsung/odroidx2_max98090.c
@@ -21,6 +21,8 @@ struct odroidx2_drv_data {
21/* The I2S CDCLK output clock frequency for the MAX98090 codec */ 21/* The I2S CDCLK output clock frequency for the MAX98090 codec */
22#define MAX98090_MCLK 19200000 22#define MAX98090_MCLK 19200000
23 23
24static struct snd_soc_dai_link odroidx2_dai[];
25
24static int odroidx2_late_probe(struct snd_soc_card *card) 26static int odroidx2_late_probe(struct snd_soc_card *card)
25{ 27{
26 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai; 28 struct snd_soc_dai *codec_dai = card->rtd[0].codec_dai;
@@ -29,7 +31,9 @@ static int odroidx2_late_probe(struct snd_soc_card *card)
29 31
30 ret = snd_soc_dai_set_sysclk(codec_dai, 0, MAX98090_MCLK, 32 ret = snd_soc_dai_set_sysclk(codec_dai, 0, MAX98090_MCLK,
31 SND_SOC_CLOCK_IN); 33 SND_SOC_CLOCK_IN);
32 if (ret < 0) 34
35 if (ret < 0 || of_find_property(odroidx2_dai[0].codec_of_node,
36 "clocks", NULL))
33 return ret; 37 return ret;
34 38
35 /* Set the cpu DAI configuration in order to use CDCLK */ 39 /* Set the cpu DAI configuration in order to use CDCLK */
diff --git a/sound/soc/samsung/rx1950_uda1380.c b/sound/soc/samsung/rx1950_uda1380.c
index 37688ebbb2b4..873f2cb4bebe 100644
--- a/sound/soc/samsung/rx1950_uda1380.c
+++ b/sound/soc/samsung/rx1950_uda1380.c
@@ -89,6 +89,8 @@ static struct snd_soc_dai_link rx1950_uda1380_dai[] = {
89 .init = rx1950_uda1380_init, 89 .init = rx1950_uda1380_init,
90 .platform_name = "s3c24xx-iis", 90 .platform_name = "s3c24xx-iis",
91 .codec_name = "uda1380-codec.0-001a", 91 .codec_name = "uda1380-codec.0-001a",
92 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
93 SND_SOC_DAIFMT_CBS_CFS,
92 .ops = &rx1950_ops, 94 .ops = &rx1950_ops,
93 }, 95 },
94}; 96};
@@ -154,7 +156,6 @@ static int rx1950_hw_params(struct snd_pcm_substream *substream,
154{ 156{
155 struct snd_soc_pcm_runtime *rtd = substream->private_data; 157 struct snd_soc_pcm_runtime *rtd = substream->private_data;
156 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 158 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
157 struct snd_soc_dai *codec_dai = rtd->codec_dai;
158 int div; 159 int div;
159 int ret; 160 int ret;
160 unsigned int rate = params_rate(params); 161 unsigned int rate = params_rate(params);
@@ -181,18 +182,6 @@ static int rx1950_hw_params(struct snd_pcm_substream *substream,
181 return -EINVAL; 182 return -EINVAL;
182 } 183 }
183 184
184 /* set codec DAI configuration */
185 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
186 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
187 if (ret < 0)
188 return ret;
189
190 /* set cpu DAI configuration */
191 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
192 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
193 if (ret < 0)
194 return ret;
195
196 /* select clock source */ 185 /* select clock source */
197 ret = snd_soc_dai_set_sysclk(cpu_dai, clk_source, rate, 186 ret = snd_soc_dai_set_sysclk(cpu_dai, clk_source, rate,
198 SND_SOC_CLOCK_OUT); 187 SND_SOC_CLOCK_OUT);
diff --git a/sound/soc/samsung/s3c24xx_simtec.c b/sound/soc/samsung/s3c24xx_simtec.c
index 2c015f62ead6..dcc008d1e1ab 100644
--- a/sound/soc/samsung/s3c24xx_simtec.c
+++ b/sound/soc/samsung/s3c24xx_simtec.c
@@ -169,24 +169,6 @@ static int simtec_hw_params(struct snd_pcm_substream *substream,
169 struct snd_soc_dai *cpu_dai = rtd->cpu_dai; 169 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
170 int ret; 170 int ret;
171 171
172 /* Set the CODEC as the bus clock master, I2S */
173 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
174 SND_SOC_DAIFMT_NB_NF |
175 SND_SOC_DAIFMT_CBM_CFM);
176 if (ret) {
177 pr_err("%s: failed set cpu dai format\n", __func__);
178 return ret;
179 }
180
181 /* Set the CODEC as the bus clock master */
182 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
183 SND_SOC_DAIFMT_NB_NF |
184 SND_SOC_DAIFMT_CBM_CFM);
185 if (ret) {
186 pr_err("%s: failed set codec dai format\n", __func__);
187 return ret;
188 }
189
190 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 172 ret = snd_soc_dai_set_sysclk(codec_dai, 0,
191 CODEC_CLOCK, SND_SOC_CLOCK_IN); 173 CODEC_CLOCK, SND_SOC_CLOCK_IN);
192 if (ret) { 174 if (ret) {
@@ -320,6 +302,8 @@ int simtec_audio_core_probe(struct platform_device *pdev,
320 int ret; 302 int ret;
321 303
322 card->dai_link->ops = &simtec_snd_ops; 304 card->dai_link->ops = &simtec_snd_ops;
305 card->dai_link->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
306 SND_SOC_DAIFMT_CBM_CFM;
323 307
324 pdata = pdev->dev.platform_data; 308 pdata = pdev->dev.platform_data;
325 if (!pdata) { 309 if (!pdata) {
diff --git a/sound/soc/samsung/s3c24xx_uda134x.c b/sound/soc/samsung/s3c24xx_uda134x.c
index 9c6f7db56f60..50849e137fc0 100644
--- a/sound/soc/samsung/s3c24xx_uda134x.c
+++ b/sound/soc/samsung/s3c24xx_uda134x.c
@@ -173,16 +173,6 @@ static int s3c24xx_uda134x_hw_params(struct snd_pcm_substream *substream,
173 return -EINVAL; 173 return -EINVAL;
174 } 174 }
175 175
176 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
177 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
178 if (ret < 0)
179 return ret;
180
181 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
182 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
183 if (ret < 0)
184 return ret;
185
186 ret = snd_soc_dai_set_sysclk(cpu_dai, clk_source , clk, 176 ret = snd_soc_dai_set_sysclk(cpu_dai, clk_source , clk,
187 SND_SOC_CLOCK_IN); 177 SND_SOC_CLOCK_IN);
188 if (ret < 0) 178 if (ret < 0)
@@ -223,6 +213,8 @@ static struct snd_soc_dai_link s3c24xx_uda134x_dai_link = {
223 .codec_name = "uda134x-codec", 213 .codec_name = "uda134x-codec",
224 .codec_dai_name = "uda134x-hifi", 214 .codec_dai_name = "uda134x-hifi",
225 .cpu_dai_name = "s3c24xx-iis", 215 .cpu_dai_name = "s3c24xx-iis",
216 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
217 SND_SOC_DAIFMT_CBS_CFS,
226 .ops = &s3c24xx_uda134x_ops, 218 .ops = &s3c24xx_uda134x_ops,
227 .platform_name = "s3c24xx-iis", 219 .platform_name = "s3c24xx-iis",
228}; 220};
diff --git a/sound/soc/samsung/smartq_wm8987.c b/sound/soc/samsung/smartq_wm8987.c
index 9b0ffacab790..8291d2a5f152 100644
--- a/sound/soc/samsung/smartq_wm8987.c
+++ b/sound/soc/samsung/smartq_wm8987.c
@@ -56,20 +56,6 @@ static int smartq_hifi_hw_params(struct snd_pcm_substream *substream,
56 break; 56 break;
57 } 57 }
58 58
59 /* set codec DAI configuration */
60 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
61 SND_SOC_DAIFMT_NB_NF |
62 SND_SOC_DAIFMT_CBS_CFS);
63 if (ret < 0)
64 return ret;
65
66 /* set cpu DAI configuration */
67 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
68 SND_SOC_DAIFMT_NB_NF |
69 SND_SOC_DAIFMT_CBS_CFS);
70 if (ret < 0)
71 return ret;
72
73 /* Use PCLK for I2S signal generation */ 59 /* Use PCLK for I2S signal generation */
74 ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0, 60 ret = snd_soc_dai_set_sysclk(cpu_dai, SAMSUNG_I2S_RCLKSRC_0,
75 0, SND_SOC_CLOCK_IN); 61 0, SND_SOC_CLOCK_IN);
@@ -199,6 +185,8 @@ static struct snd_soc_dai_link smartq_dai[] = {
199 .platform_name = "samsung-i2s.0", 185 .platform_name = "samsung-i2s.0",
200 .codec_name = "wm8750.0-0x1a", 186 .codec_name = "wm8750.0-0x1a",
201 .init = smartq_wm8987_init, 187 .init = smartq_wm8987_init,
188 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
189 SND_SOC_DAIFMT_CBS_CFS,
202 .ops = &smartq_hifi_ops, 190 .ops = &smartq_hifi_ops,
203 }, 191 },
204}; 192};
diff --git a/sound/soc/samsung/smdk_wm8580.c b/sound/soc/samsung/smdk_wm8580.c
index b1a519f83b29..548bfd993788 100644
--- a/sound/soc/samsung/smdk_wm8580.c
+++ b/sound/soc/samsung/smdk_wm8580.c
@@ -32,7 +32,6 @@ static int smdk_hw_params(struct snd_pcm_substream *substream,
32 struct snd_pcm_hw_params *params) 32 struct snd_pcm_hw_params *params)
33{ 33{
34 struct snd_soc_pcm_runtime *rtd = substream->private_data; 34 struct snd_soc_pcm_runtime *rtd = substream->private_data;
35 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
36 struct snd_soc_dai *codec_dai = rtd->codec_dai; 35 struct snd_soc_dai *codec_dai = rtd->codec_dai;
37 unsigned int pll_out; 36 unsigned int pll_out;
38 int bfs, rfs, ret; 37 int bfs, rfs, ret;
@@ -77,20 +76,6 @@ static int smdk_hw_params(struct snd_pcm_substream *substream,
77 } 76 }
78 pll_out = params_rate(params) * rfs; 77 pll_out = params_rate(params) * rfs;
79 78
80 /* Set the Codec DAI configuration */
81 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
82 | SND_SOC_DAIFMT_NB_NF
83 | SND_SOC_DAIFMT_CBM_CFM);
84 if (ret < 0)
85 return ret;
86
87 /* Set the AP DAI configuration */
88 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
89 | SND_SOC_DAIFMT_NB_NF
90 | SND_SOC_DAIFMT_CBM_CFM);
91 if (ret < 0)
92 return ret;
93
94 /* Set WM8580 to drive MCLK from its PLLA */ 79 /* Set WM8580 to drive MCLK from its PLLA */
95 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK, 80 ret = snd_soc_dai_set_clkdiv(codec_dai, WM8580_MCLK,
96 WM8580_CLKSRC_PLLA); 81 WM8580_CLKSRC_PLLA);
@@ -151,13 +136,10 @@ static const struct snd_soc_dapm_route smdk_wm8580_audio_map[] = {
151 136
152static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd) 137static int smdk_wm8580_init_paiftx(struct snd_soc_pcm_runtime *rtd)
153{ 138{
154 struct snd_soc_codec *codec = rtd->codec;
155 struct snd_soc_dapm_context *dapm = &codec->dapm;
156
157 /* Enabling the microphone requires the fitting of a 0R 139 /* Enabling the microphone requires the fitting of a 0R
158 * resistor to connect the line from the microphone jack. 140 * resistor to connect the line from the microphone jack.
159 */ 141 */
160 snd_soc_dapm_disable_pin(dapm, "MicIn"); 142 snd_soc_dapm_disable_pin(&rtd->card->dapm, "MicIn");
161 143
162 return 0; 144 return 0;
163} 145}
@@ -168,6 +150,9 @@ enum {
168 SEC_PLAYBACK, 150 SEC_PLAYBACK,
169}; 151};
170 152
153#define SMDK_DAI_FMT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | \
154 SND_SOC_DAIFMT_CBM_CFM)
155
171static struct snd_soc_dai_link smdk_dai[] = { 156static struct snd_soc_dai_link smdk_dai[] = {
172 [PRI_PLAYBACK] = { /* Primary Playback i/f */ 157 [PRI_PLAYBACK] = { /* Primary Playback i/f */
173 .name = "WM8580 PAIF RX", 158 .name = "WM8580 PAIF RX",
@@ -176,6 +161,7 @@ static struct snd_soc_dai_link smdk_dai[] = {
176 .codec_dai_name = "wm8580-hifi-playback", 161 .codec_dai_name = "wm8580-hifi-playback",
177 .platform_name = "samsung-i2s.0", 162 .platform_name = "samsung-i2s.0",
178 .codec_name = "wm8580.0-001b", 163 .codec_name = "wm8580.0-001b",
164 .dai_fmt = SMDK_DAI_FMT,
179 .ops = &smdk_ops, 165 .ops = &smdk_ops,
180 }, 166 },
181 [PRI_CAPTURE] = { /* Primary Capture i/f */ 167 [PRI_CAPTURE] = { /* Primary Capture i/f */
@@ -185,6 +171,7 @@ static struct snd_soc_dai_link smdk_dai[] = {
185 .codec_dai_name = "wm8580-hifi-capture", 171 .codec_dai_name = "wm8580-hifi-capture",
186 .platform_name = "samsung-i2s.0", 172 .platform_name = "samsung-i2s.0",
187 .codec_name = "wm8580.0-001b", 173 .codec_name = "wm8580.0-001b",
174 .dai_fmt = SMDK_DAI_FMT,
188 .init = smdk_wm8580_init_paiftx, 175 .init = smdk_wm8580_init_paiftx,
189 .ops = &smdk_ops, 176 .ops = &smdk_ops,
190 }, 177 },
@@ -195,6 +182,7 @@ static struct snd_soc_dai_link smdk_dai[] = {
195 .codec_dai_name = "wm8580-hifi-playback", 182 .codec_dai_name = "wm8580-hifi-playback",
196 .platform_name = "samsung-i2s-sec", 183 .platform_name = "samsung-i2s-sec",
197 .codec_name = "wm8580.0-001b", 184 .codec_name = "wm8580.0-001b",
185 .dai_fmt = SMDK_DAI_FMT,
198 .ops = &smdk_ops, 186 .ops = &smdk_ops,
199 }, 187 },
200}; 188};
diff --git a/sound/soc/samsung/smdk_wm8580pcm.c b/sound/soc/samsung/smdk_wm8580pcm.c
index 05c609c62de9..6deec5234c92 100644
--- a/sound/soc/samsung/smdk_wm8580pcm.c
+++ b/sound/soc/samsung/smdk_wm8580pcm.c
@@ -62,20 +62,6 @@ static int smdk_wm8580_pcm_hw_params(struct snd_pcm_substream *substream,
62 62
63 rfs = mclk_freq / params_rate(params) / 2; 63 rfs = mclk_freq / params_rate(params) / 2;
64 64
65 /* Set the codec DAI configuration */
66 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B
67 | SND_SOC_DAIFMT_IB_NF
68 | SND_SOC_DAIFMT_CBS_CFS);
69 if (ret < 0)
70 return ret;
71
72 /* Set the cpu DAI configuration */
73 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_B
74 | SND_SOC_DAIFMT_IB_NF
75 | SND_SOC_DAIFMT_CBS_CFS);
76 if (ret < 0)
77 return ret;
78
79 if (mclk_freq == xtal_freq) { 65 if (mclk_freq == xtal_freq) {
80 ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_MCLK, 66 ret = snd_soc_dai_set_sysclk(codec_dai, WM8580_CLKSRC_MCLK,
81 mclk_freq, SND_SOC_CLOCK_IN); 67 mclk_freq, SND_SOC_CLOCK_IN);
@@ -121,6 +107,9 @@ static struct snd_soc_ops smdk_wm8580_pcm_ops = {
121 .hw_params = smdk_wm8580_pcm_hw_params, 107 .hw_params = smdk_wm8580_pcm_hw_params,
122}; 108};
123 109
110#define SMDK_DAI_FMT (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF | \
111 SND_SOC_DAIFMT_CBS_CFS)
112
124static struct snd_soc_dai_link smdk_dai[] = { 113static struct snd_soc_dai_link smdk_dai[] = {
125 { 114 {
126 .name = "WM8580 PAIF PCM RX", 115 .name = "WM8580 PAIF PCM RX",
@@ -129,6 +118,7 @@ static struct snd_soc_dai_link smdk_dai[] = {
129 .codec_dai_name = "wm8580-hifi-playback", 118 .codec_dai_name = "wm8580-hifi-playback",
130 .platform_name = "samsung-audio", 119 .platform_name = "samsung-audio",
131 .codec_name = "wm8580.0-001b", 120 .codec_name = "wm8580.0-001b",
121 .dai_fmt = SMDK_DAI_FMT,
132 .ops = &smdk_wm8580_pcm_ops, 122 .ops = &smdk_wm8580_pcm_ops,
133 }, { 123 }, {
134 .name = "WM8580 PAIF PCM TX", 124 .name = "WM8580 PAIF PCM TX",
@@ -137,6 +127,7 @@ static struct snd_soc_dai_link smdk_dai[] = {
137 .codec_dai_name = "wm8580-hifi-capture", 127 .codec_dai_name = "wm8580-hifi-capture",
138 .platform_name = "samsung-pcm.0", 128 .platform_name = "samsung-pcm.0",
139 .codec_name = "wm8580.0-001b", 129 .codec_name = "wm8580.0-001b",
130 .dai_fmt = SMDK_DAI_FMT,
140 .ops = &smdk_wm8580_pcm_ops, 131 .ops = &smdk_wm8580_pcm_ops,
141 }, 132 },
142}; 133};
diff --git a/sound/soc/samsung/smdk_wm8994pcm.c b/sound/soc/samsung/smdk_wm8994pcm.c
index c470e8eed6e1..b1c89ec2d999 100644
--- a/sound/soc/samsung/smdk_wm8994pcm.c
+++ b/sound/soc/samsung/smdk_wm8994pcm.c
@@ -68,20 +68,6 @@ static int smdk_wm8994_pcm_hw_params(struct snd_pcm_substream *substream,
68 68
69 mclk_freq = params_rate(params) * rfs; 69 mclk_freq = params_rate(params) * rfs;
70 70
71 /* Set the codec DAI configuration */
72 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_B
73 | SND_SOC_DAIFMT_IB_NF
74 | SND_SOC_DAIFMT_CBS_CFS);
75 if (ret < 0)
76 return ret;
77
78 /* Set the cpu DAI configuration */
79 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_B
80 | SND_SOC_DAIFMT_IB_NF
81 | SND_SOC_DAIFMT_CBS_CFS);
82 if (ret < 0)
83 return ret;
84
85 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1, 71 ret = snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_FLL1,
86 mclk_freq, SND_SOC_CLOCK_IN); 72 mclk_freq, SND_SOC_CLOCK_IN);
87 if (ret < 0) 73 if (ret < 0)
@@ -118,6 +104,8 @@ static struct snd_soc_dai_link smdk_dai[] = {
118 .codec_dai_name = "wm8994-aif1", 104 .codec_dai_name = "wm8994-aif1",
119 .platform_name = "samsung-pcm.0", 105 .platform_name = "samsung-pcm.0",
120 .codec_name = "wm8994-codec", 106 .codec_name = "wm8994-codec",
107 .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF |
108 SND_SOC_DAIFMT_CBS_CFS,
121 .ops = &smdk_wm8994_pcm_ops, 109 .ops = &smdk_wm8994_pcm_ops,
122 }, 110 },
123}; 111};
diff --git a/sound/soc/sh/dma-sh7760.c b/sound/soc/sh/dma-sh7760.c
index a5b2c4ea90d9..fd11404a3bc7 100644
--- a/sound/soc/sh/dma-sh7760.c
+++ b/sound/soc/sh/dma-sh7760.c
@@ -305,11 +305,6 @@ static struct snd_pcm_ops camelot_pcm_ops = {
305 .pointer = camelot_pos, 305 .pointer = camelot_pos,
306}; 306};
307 307
308static void camelot_pcm_free(struct snd_pcm *pcm)
309{
310 snd_pcm_lib_preallocate_free_for_all(pcm);
311}
312
313static int camelot_pcm_new(struct snd_soc_pcm_runtime *rtd) 308static int camelot_pcm_new(struct snd_soc_pcm_runtime *rtd)
314{ 309{
315 struct snd_pcm *pcm = rtd->pcm; 310 struct snd_pcm *pcm = rtd->pcm;
@@ -328,7 +323,6 @@ static int camelot_pcm_new(struct snd_soc_pcm_runtime *rtd)
328static struct snd_soc_platform_driver sh7760_soc_platform = { 323static struct snd_soc_platform_driver sh7760_soc_platform = {
329 .ops = &camelot_pcm_ops, 324 .ops = &camelot_pcm_ops,
330 .pcm_new = camelot_pcm_new, 325 .pcm_new = camelot_pcm_new,
331 .pcm_free = camelot_pcm_free,
332}; 326};
333 327
334static int sh7760_soc_platform_probe(struct platform_device *pdev) 328static int sh7760_soc_platform_probe(struct platform_device *pdev)
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 8869971d7884..b87b22e88e43 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -820,12 +820,9 @@ static int fsi_clk_enable(struct device *dev,
820 return ret; 820 return ret;
821 } 821 }
822 822
823 if (clock->xck) 823 clk_enable(clock->xck);
824 clk_enable(clock->xck); 824 clk_enable(clock->ick);
825 if (clock->ick) 825 clk_enable(clock->div);
826 clk_enable(clock->ick);
827 if (clock->div)
828 clk_enable(clock->div);
829 826
830 clock->count++; 827 clock->count++;
831 } 828 }
@@ -1765,11 +1762,6 @@ static struct snd_pcm_ops fsi_pcm_ops = {
1765#define PREALLOC_BUFFER (32 * 1024) 1762#define PREALLOC_BUFFER (32 * 1024)
1766#define PREALLOC_BUFFER_MAX (32 * 1024) 1763#define PREALLOC_BUFFER_MAX (32 * 1024)
1767 1764
1768static void fsi_pcm_free(struct snd_pcm *pcm)
1769{
1770 snd_pcm_lib_preallocate_free_for_all(pcm);
1771}
1772
1773static int fsi_pcm_new(struct snd_soc_pcm_runtime *rtd) 1765static int fsi_pcm_new(struct snd_soc_pcm_runtime *rtd)
1774{ 1766{
1775 return snd_pcm_lib_preallocate_pages_for_all( 1767 return snd_pcm_lib_preallocate_pages_for_all(
@@ -1821,7 +1813,6 @@ static struct snd_soc_dai_driver fsi_soc_dai[] = {
1821static struct snd_soc_platform_driver fsi_soc_platform = { 1813static struct snd_soc_platform_driver fsi_soc_platform = {
1822 .ops = &fsi_pcm_ops, 1814 .ops = &fsi_pcm_ops,
1823 .pcm_new = fsi_pcm_new, 1815 .pcm_new = fsi_pcm_new,
1824 .pcm_free = fsi_pcm_free,
1825}; 1816};
1826 1817
1827static const struct snd_soc_component_driver fsi_soc_component = { 1818static const struct snd_soc_component_driver fsi_soc_component = {
diff --git a/sound/soc/sh/migor.c b/sound/soc/sh/migor.c
index c58c2529f103..82f582344fe7 100644
--- a/sound/soc/sh/migor.c
+++ b/sound/soc/sh/migor.c
@@ -63,16 +63,6 @@ static int migor_hw_params(struct snd_pcm_substream *substream,
63 if (ret < 0) 63 if (ret < 0)
64 return ret; 64 return ret;
65 65
66 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_NB_IF |
67 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS);
68 if (ret < 0)
69 return ret;
70
71 ret = snd_soc_dai_set_fmt(rtd->cpu_dai, SND_SOC_DAIFMT_NB_IF |
72 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS);
73 if (ret < 0)
74 return ret;
75
76 codec_freq = rate * 512; 66 codec_freq = rate * 512;
77 /* 67 /*
78 * This propagates the parent frequency change to children and 68 * This propagates the parent frequency change to children and
@@ -144,6 +134,8 @@ static struct snd_soc_dai_link migor_dai = {
144 .codec_dai_name = "wm8978-hifi", 134 .codec_dai_name = "wm8978-hifi",
145 .platform_name = "siu-pcm-audio", 135 .platform_name = "siu-pcm-audio",
146 .codec_name = "wm8978.0-001a", 136 .codec_name = "wm8978.0-001a",
137 .dai_fmt = SND_SOC_DAIFMT_NB_IF | SND_SOC_DAIFMT_I2S |
138 SND_SOC_DAIFMT_CBS_CFS,
147 .ops = &migor_dai_ops, 139 .ops = &migor_dai_ops,
148}; 140};
149 141
diff --git a/sound/soc/sh/rcar/adg.c b/sound/soc/sh/rcar/adg.c
index 14d1a7193469..7ac35c9d1cb8 100644
--- a/sound/soc/sh/rcar/adg.c
+++ b/sound/soc/sh/rcar/adg.c
@@ -57,8 +57,7 @@ static u32 rsnd_adg_ssi_ws_timing_gen2(struct rsnd_dai_stream *io)
57 return (0x6 + ws) << 8; 57 return (0x6 + ws) << 8;
58} 58}
59 59
60int rsnd_adg_set_cmd_timsel_gen2(struct rsnd_dai *rdai, 60int rsnd_adg_set_cmd_timsel_gen2(struct rsnd_mod *mod,
61 struct rsnd_mod *mod,
62 struct rsnd_dai_stream *io) 61 struct rsnd_dai_stream *io)
63{ 62{
64 int id = rsnd_mod_id(mod); 63 int id = rsnd_mod_id(mod);
@@ -75,12 +74,11 @@ int rsnd_adg_set_cmd_timsel_gen2(struct rsnd_dai *rdai,
75 return 0; 74 return 0;
76} 75}
77 76
78static int rsnd_adg_set_src_timsel_gen2(struct rsnd_dai *rdai, 77static int rsnd_adg_set_src_timsel_gen2(struct rsnd_mod *mod,
79 struct rsnd_mod *mod,
80 struct rsnd_dai_stream *io, 78 struct rsnd_dai_stream *io,
81 u32 timsel) 79 u32 timsel)
82{ 80{
83 int is_play = rsnd_dai_is_play(rdai, io); 81 int is_play = rsnd_io_is_play(io);
84 int id = rsnd_mod_id(mod); 82 int id = rsnd_mod_id(mod);
85 int shift = (id % 2) ? 16 : 0; 83 int shift = (id % 2) ? 16 : 0;
86 u32 mask, ws; 84 u32 mask, ws;
@@ -122,7 +120,6 @@ static int rsnd_adg_set_src_timsel_gen2(struct rsnd_dai *rdai,
122} 120}
123 121
124int rsnd_adg_set_convert_clk_gen2(struct rsnd_mod *mod, 122int rsnd_adg_set_convert_clk_gen2(struct rsnd_mod *mod,
125 struct rsnd_dai *rdai,
126 struct rsnd_dai_stream *io, 123 struct rsnd_dai_stream *io,
127 unsigned int src_rate, 124 unsigned int src_rate,
128 unsigned int dst_rate) 125 unsigned int dst_rate)
@@ -178,7 +175,7 @@ int rsnd_adg_set_convert_clk_gen2(struct rsnd_mod *mod,
178 return -EIO; 175 return -EIO;
179 } 176 }
180 177
181 ret = rsnd_adg_set_src_timsel_gen2(rdai, mod, io, val); 178 ret = rsnd_adg_set_src_timsel_gen2(mod, io, val);
182 if (ret < 0) { 179 if (ret < 0) {
183 dev_err(dev, "timsel error\n"); 180 dev_err(dev, "timsel error\n");
184 return ret; 181 return ret;
@@ -190,12 +187,11 @@ int rsnd_adg_set_convert_clk_gen2(struct rsnd_mod *mod,
190} 187}
191 188
192int rsnd_adg_set_convert_timing_gen2(struct rsnd_mod *mod, 189int rsnd_adg_set_convert_timing_gen2(struct rsnd_mod *mod,
193 struct rsnd_dai *rdai,
194 struct rsnd_dai_stream *io) 190 struct rsnd_dai_stream *io)
195{ 191{
196 u32 val = rsnd_adg_ssi_ws_timing_gen2(io); 192 u32 val = rsnd_adg_ssi_ws_timing_gen2(io);
197 193
198 return rsnd_adg_set_src_timsel_gen2(rdai, mod, io, val); 194 return rsnd_adg_set_src_timsel_gen2(mod, io, val);
199} 195}
200 196
201int rsnd_adg_set_convert_clk_gen1(struct rsnd_priv *priv, 197int rsnd_adg_set_convert_clk_gen1(struct rsnd_priv *priv,
diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
index 75308bbc2ce8..1b53605f7154 100644
--- a/sound/soc/sh/rcar/core.c
+++ b/sound/soc/sh/rcar/core.c
@@ -149,16 +149,16 @@ char *rsnd_mod_dma_name(struct rsnd_mod *mod)
149 return mod->ops->dma_name(mod); 149 return mod->ops->dma_name(mod);
150} 150}
151 151
152void rsnd_mod_init(struct rsnd_priv *priv, 152void rsnd_mod_init(struct rsnd_mod *mod,
153 struct rsnd_mod *mod,
154 struct rsnd_mod_ops *ops, 153 struct rsnd_mod_ops *ops,
154 struct clk *clk,
155 enum rsnd_mod_type type, 155 enum rsnd_mod_type type,
156 int id) 156 int id)
157{ 157{
158 mod->priv = priv;
159 mod->id = id; 158 mod->id = id;
160 mod->ops = ops; 159 mod->ops = ops;
161 mod->type = type; 160 mod->type = type;
161 mod->clk = clk;
162} 162}
163 163
164/* 164/*
@@ -412,7 +412,7 @@ u32 rsnd_get_adinr(struct rsnd_mod *mod)
412/* 412/*
413 * rsnd_dai functions 413 * rsnd_dai functions
414 */ 414 */
415#define __rsnd_mod_call(mod, func, rdai...) \ 415#define __rsnd_mod_call(mod, func, param...) \
416({ \ 416({ \
417 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \ 417 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \
418 struct device *dev = rsnd_priv_to_dev(priv); \ 418 struct device *dev = rsnd_priv_to_dev(priv); \
@@ -422,18 +422,18 @@ u32 rsnd_get_adinr(struct rsnd_mod *mod)
422 if ((mod->status & mask) == call) { \ 422 if ((mod->status & mask) == call) { \
423 dev_dbg(dev, "%s[%d] %s\n", \ 423 dev_dbg(dev, "%s[%d] %s\n", \
424 rsnd_mod_name(mod), rsnd_mod_id(mod), #func); \ 424 rsnd_mod_name(mod), rsnd_mod_id(mod), #func); \
425 ret = (mod)->ops->func(mod, rdai); \ 425 ret = (mod)->ops->func(mod, param); \
426 mod->status = (mod->status & ~mask) | (~call & mask); \ 426 mod->status = (mod->status & ~mask) | (~call & mask); \
427 } \ 427 } \
428 ret; \ 428 ret; \
429}) 429})
430 430
431#define rsnd_mod_call(mod, func, rdai...) \ 431#define rsnd_mod_call(mod, func, param...) \
432 (!(mod) ? -ENODEV : \ 432 (!(mod) ? -ENODEV : \
433 !((mod)->ops->func) ? 0 : \ 433 !((mod)->ops->func) ? 0 : \
434 __rsnd_mod_call(mod, func, rdai)) 434 __rsnd_mod_call(mod, func, param))
435 435
436#define rsnd_dai_call(fn, io, rdai...) \ 436#define rsnd_dai_call(fn, io, param...) \
437({ \ 437({ \
438 struct rsnd_mod *mod; \ 438 struct rsnd_mod *mod; \
439 int ret = 0, i; \ 439 int ret = 0, i; \
@@ -441,7 +441,7 @@ u32 rsnd_get_adinr(struct rsnd_mod *mod)
441 mod = (io)->mod[i]; \ 441 mod = (io)->mod[i]; \
442 if (!mod) \ 442 if (!mod) \
443 continue; \ 443 continue; \
444 ret = rsnd_mod_call(mod, fn, rdai); \ 444 ret = rsnd_mod_call(mod, fn, param); \
445 if (ret < 0) \ 445 if (ret < 0) \
446 break; \ 446 break; \
447 } \ 447 } \
@@ -477,17 +477,7 @@ static void rsnd_dai_disconnect(struct rsnd_mod *mod,
477 io->mod[mod->type] = NULL; 477 io->mod[mod->type] = NULL;
478} 478}
479 479
480int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai) 480struct rsnd_dai *rsnd_rdai_get(struct rsnd_priv *priv, int id)
481{
482 int id = rdai - priv->rdai;
483
484 if ((id < 0) || (id >= rsnd_rdai_nr(priv)))
485 return -EINVAL;
486
487 return id;
488}
489
490struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id)
491{ 481{
492 if ((id < 0) || (id >= rsnd_rdai_nr(priv))) 482 if ((id < 0) || (id >= rsnd_rdai_nr(priv)))
493 return NULL; 483 return NULL;
@@ -499,12 +489,7 @@ static struct rsnd_dai *rsnd_dai_to_rdai(struct snd_soc_dai *dai)
499{ 489{
500 struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai); 490 struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai);
501 491
502 return rsnd_dai_get(priv, dai->id); 492 return rsnd_rdai_get(priv, dai->id);
503}
504
505int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io)
506{
507 return &rdai->playback == io;
508} 493}
509 494
510/* 495/*
@@ -598,20 +583,20 @@ static int rsnd_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
598 if (ret < 0) 583 if (ret < 0)
599 goto dai_trigger_end; 584 goto dai_trigger_end;
600 585
601 ret = rsnd_dai_call(init, io, rdai); 586 ret = rsnd_dai_call(init, io, priv);
602 if (ret < 0) 587 if (ret < 0)
603 goto dai_trigger_end; 588 goto dai_trigger_end;
604 589
605 ret = rsnd_dai_call(start, io, rdai); 590 ret = rsnd_dai_call(start, io, priv);
606 if (ret < 0) 591 if (ret < 0)
607 goto dai_trigger_end; 592 goto dai_trigger_end;
608 break; 593 break;
609 case SNDRV_PCM_TRIGGER_STOP: 594 case SNDRV_PCM_TRIGGER_STOP:
610 ret = rsnd_dai_call(stop, io, rdai); 595 ret = rsnd_dai_call(stop, io, priv);
611 if (ret < 0) 596 if (ret < 0)
612 goto dai_trigger_end; 597 goto dai_trigger_end;
613 598
614 ret = rsnd_dai_call(quit, io, rdai); 599 ret = rsnd_dai_call(quit, io, priv);
615 if (ret < 0) 600 if (ret < 0)
616 goto dai_trigger_end; 601 goto dai_trigger_end;
617 602
@@ -873,15 +858,15 @@ static int rsnd_dai_probe(struct platform_device *pdev,
873 priv->rdai = rdai; 858 priv->rdai = rdai;
874 859
875 for (i = 0; i < dai_nr; i++) { 860 for (i = 0; i < dai_nr; i++) {
876 rdai[i].info = &info->dai_info[i];
877 861
878 pmod = rdai[i].info->playback.ssi; 862 pmod = info->dai_info[i].playback.ssi;
879 cmod = rdai[i].info->capture.ssi; 863 cmod = info->dai_info[i].capture.ssi;
880 864
881 /* 865 /*
882 * init rsnd_dai 866 * init rsnd_dai
883 */ 867 */
884 snprintf(rdai[i].name, RSND_DAI_NAME_SIZE, "rsnd-dai.%d", i); 868 snprintf(rdai[i].name, RSND_DAI_NAME_SIZE, "rsnd-dai.%d", i);
869 rdai[i].priv = priv;
885 870
886 /* 871 /*
887 * init snd_soc_dai_driver 872 * init snd_soc_dai_driver
@@ -895,6 +880,7 @@ static int rsnd_dai_probe(struct platform_device *pdev,
895 drv[i].playback.channels_max = 2; 880 drv[i].playback.channels_max = 2;
896 881
897 rdai[i].playback.info = &info->dai_info[i].playback; 882 rdai[i].playback.info = &info->dai_info[i].playback;
883 rdai[i].playback.rdai = rdai + i;
898 rsnd_path_init(priv, &rdai[i], &rdai[i].playback); 884 rsnd_path_init(priv, &rdai[i], &rdai[i].playback);
899 } 885 }
900 if (cmod) { 886 if (cmod) {
@@ -904,6 +890,7 @@ static int rsnd_dai_probe(struct platform_device *pdev,
904 drv[i].capture.channels_max = 2; 890 drv[i].capture.channels_max = 2;
905 891
906 rdai[i].capture.info = &info->dai_info[i].capture; 892 rdai[i].capture.info = &info->dai_info[i].capture;
893 rdai[i].capture.rdai = rdai + i;
907 rsnd_path_init(priv, &rdai[i], &rdai[i].capture); 894 rsnd_path_init(priv, &rdai[i], &rdai[i].capture);
908 } 895 }
909 896
@@ -1037,7 +1024,6 @@ static int rsnd_kctrl_put(struct snd_kcontrol *kctrl,
1037} 1024}
1038 1025
1039static int __rsnd_kctrl_new(struct rsnd_mod *mod, 1026static int __rsnd_kctrl_new(struct rsnd_mod *mod,
1040 struct rsnd_dai *rdai,
1041 struct snd_soc_pcm_runtime *rtd, 1027 struct snd_soc_pcm_runtime *rtd,
1042 const unsigned char *name, 1028 const unsigned char *name,
1043 struct rsnd_kctrl_cfg *cfg, 1029 struct rsnd_kctrl_cfg *cfg,
@@ -1060,16 +1046,24 @@ static int __rsnd_kctrl_new(struct rsnd_mod *mod,
1060 return -ENOMEM; 1046 return -ENOMEM;
1061 1047
1062 ret = snd_ctl_add(card, kctrl); 1048 ret = snd_ctl_add(card, kctrl);
1063 if (ret < 0) 1049 if (ret < 0) {
1050 snd_ctl_free_one(kctrl);
1064 return ret; 1051 return ret;
1052 }
1065 1053
1066 cfg->update = update; 1054 cfg->update = update;
1055 cfg->card = card;
1056 cfg->kctrl = kctrl;
1067 1057
1068 return 0; 1058 return 0;
1069} 1059}
1070 1060
1061void _rsnd_kctrl_remove(struct rsnd_kctrl_cfg *cfg)
1062{
1063 snd_ctl_remove(cfg->card, cfg->kctrl);
1064}
1065
1071int rsnd_kctrl_new_m(struct rsnd_mod *mod, 1066int rsnd_kctrl_new_m(struct rsnd_mod *mod,
1072 struct rsnd_dai *rdai,
1073 struct snd_soc_pcm_runtime *rtd, 1067 struct snd_soc_pcm_runtime *rtd,
1074 const unsigned char *name, 1068 const unsigned char *name,
1075 void (*update)(struct rsnd_mod *mod), 1069 void (*update)(struct rsnd_mod *mod),
@@ -1079,11 +1073,10 @@ int rsnd_kctrl_new_m(struct rsnd_mod *mod,
1079 _cfg->cfg.max = max; 1073 _cfg->cfg.max = max;
1080 _cfg->cfg.size = RSND_DVC_CHANNELS; 1074 _cfg->cfg.size = RSND_DVC_CHANNELS;
1081 _cfg->cfg.val = _cfg->val; 1075 _cfg->cfg.val = _cfg->val;
1082 return __rsnd_kctrl_new(mod, rdai, rtd, name, &_cfg->cfg, update); 1076 return __rsnd_kctrl_new(mod, rtd, name, &_cfg->cfg, update);
1083} 1077}
1084 1078
1085int rsnd_kctrl_new_s(struct rsnd_mod *mod, 1079int rsnd_kctrl_new_s(struct rsnd_mod *mod,
1086 struct rsnd_dai *rdai,
1087 struct snd_soc_pcm_runtime *rtd, 1080 struct snd_soc_pcm_runtime *rtd,
1088 const unsigned char *name, 1081 const unsigned char *name,
1089 void (*update)(struct rsnd_mod *mod), 1082 void (*update)(struct rsnd_mod *mod),
@@ -1093,11 +1086,10 @@ int rsnd_kctrl_new_s(struct rsnd_mod *mod,
1093 _cfg->cfg.max = max; 1086 _cfg->cfg.max = max;
1094 _cfg->cfg.size = 1; 1087 _cfg->cfg.size = 1;
1095 _cfg->cfg.val = &_cfg->val; 1088 _cfg->cfg.val = &_cfg->val;
1096 return __rsnd_kctrl_new(mod, rdai, rtd, name, &_cfg->cfg, update); 1089 return __rsnd_kctrl_new(mod, rtd, name, &_cfg->cfg, update);
1097} 1090}
1098 1091
1099int rsnd_kctrl_new_e(struct rsnd_mod *mod, 1092int rsnd_kctrl_new_e(struct rsnd_mod *mod,
1100 struct rsnd_dai *rdai,
1101 struct snd_soc_pcm_runtime *rtd, 1093 struct snd_soc_pcm_runtime *rtd,
1102 const unsigned char *name, 1094 const unsigned char *name,
1103 struct rsnd_kctrl_cfg_s *_cfg, 1095 struct rsnd_kctrl_cfg_s *_cfg,
@@ -1109,7 +1101,7 @@ int rsnd_kctrl_new_e(struct rsnd_mod *mod,
1109 _cfg->cfg.size = 1; 1101 _cfg->cfg.size = 1;
1110 _cfg->cfg.val = &_cfg->val; 1102 _cfg->cfg.val = &_cfg->val;
1111 _cfg->cfg.texts = texts; 1103 _cfg->cfg.texts = texts;
1112 return __rsnd_kctrl_new(mod, rdai, rtd, name, &_cfg->cfg, update); 1104 return __rsnd_kctrl_new(mod, rtd, name, &_cfg->cfg, update);
1113} 1105}
1114 1106
1115/* 1107/*
@@ -1125,11 +1117,11 @@ static int rsnd_pcm_new(struct snd_soc_pcm_runtime *rtd)
1125 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai); 1117 struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
1126 int ret; 1118 int ret;
1127 1119
1128 ret = rsnd_dai_call(pcm_new, &rdai->playback, rdai, rtd); 1120 ret = rsnd_dai_call(pcm_new, &rdai->playback, rtd);
1129 if (ret) 1121 if (ret)
1130 return ret; 1122 return ret;
1131 1123
1132 ret = rsnd_dai_call(pcm_new, &rdai->capture, rdai, rtd); 1124 ret = rsnd_dai_call(pcm_new, &rdai->capture, rtd);
1133 if (ret) 1125 if (ret)
1134 return ret; 1126 return ret;
1135 1127
@@ -1140,15 +1132,9 @@ static int rsnd_pcm_new(struct snd_soc_pcm_runtime *rtd)
1140 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX); 1132 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
1141} 1133}
1142 1134
1143static void rsnd_pcm_free(struct snd_pcm *pcm)
1144{
1145 snd_pcm_lib_preallocate_free_for_all(pcm);
1146}
1147
1148static struct snd_soc_platform_driver rsnd_soc_platform = { 1135static struct snd_soc_platform_driver rsnd_soc_platform = {
1149 .ops = &rsnd_pcm_ops, 1136 .ops = &rsnd_pcm_ops,
1150 .pcm_new = rsnd_pcm_new, 1137 .pcm_new = rsnd_pcm_new,
1151 .pcm_free = rsnd_pcm_free,
1152}; 1138};
1153 1139
1154static const struct snd_soc_component_driver rsnd_soc_component = { 1140static const struct snd_soc_component_driver rsnd_soc_component = {
@@ -1156,13 +1142,11 @@ static const struct snd_soc_component_driver rsnd_soc_component = {
1156}; 1142};
1157 1143
1158static int rsnd_rdai_continuance_probe(struct rsnd_priv *priv, 1144static int rsnd_rdai_continuance_probe(struct rsnd_priv *priv,
1159 struct rsnd_dai *rdai, 1145 struct rsnd_dai_stream *io)
1160 int is_play)
1161{ 1146{
1162 struct rsnd_dai_stream *io = is_play ? &rdai->playback : &rdai->capture;
1163 int ret; 1147 int ret;
1164 1148
1165 ret = rsnd_dai_call(probe, io, rdai); 1149 ret = rsnd_dai_call(probe, io, priv);
1166 if (ret == -EAGAIN) { 1150 if (ret == -EAGAIN) {
1167 /* 1151 /*
1168 * Fallback to PIO mode 1152 * Fallback to PIO mode
@@ -1175,7 +1159,7 @@ static int rsnd_rdai_continuance_probe(struct rsnd_priv *priv,
1175 * rsnd_dma_init() 1159 * rsnd_dma_init()
1176 * rsnd_ssi_fallback() 1160 * rsnd_ssi_fallback()
1177 */ 1161 */
1178 rsnd_dai_call(remove, io, rdai); 1162 rsnd_dai_call(remove, io, priv);
1179 1163
1180 /* 1164 /*
1181 * remove SRC/DVC from DAI, 1165 * remove SRC/DVC from DAI,
@@ -1186,13 +1170,13 @@ static int rsnd_rdai_continuance_probe(struct rsnd_priv *priv,
1186 /* 1170 /*
1187 * fallback 1171 * fallback
1188 */ 1172 */
1189 rsnd_dai_call(fallback, io, rdai); 1173 rsnd_dai_call(fallback, io, priv);
1190 1174
1191 /* 1175 /*
1192 * retry to "probe". 1176 * retry to "probe".
1193 * DAI has SSI which is PIO mode only now. 1177 * DAI has SSI which is PIO mode only now.
1194 */ 1178 */
1195 ret = rsnd_dai_call(probe, io, rdai); 1179 ret = rsnd_dai_call(probe, io, priv);
1196 } 1180 }
1197 1181
1198 return ret; 1182 return ret;
@@ -1259,11 +1243,11 @@ static int rsnd_probe(struct platform_device *pdev)
1259 } 1243 }
1260 1244
1261 for_each_rsnd_dai(rdai, priv, i) { 1245 for_each_rsnd_dai(rdai, priv, i) {
1262 ret = rsnd_rdai_continuance_probe(priv, rdai, 1); 1246 ret = rsnd_rdai_continuance_probe(priv, &rdai->playback);
1263 if (ret) 1247 if (ret)
1264 goto exit_snd_probe; 1248 goto exit_snd_probe;
1265 1249
1266 ret = rsnd_rdai_continuance_probe(priv, rdai, 0); 1250 ret = rsnd_rdai_continuance_probe(priv, &rdai->capture);
1267 if (ret) 1251 if (ret)
1268 goto exit_snd_probe; 1252 goto exit_snd_probe;
1269 } 1253 }
@@ -1295,8 +1279,8 @@ exit_snd_soc:
1295 snd_soc_unregister_platform(dev); 1279 snd_soc_unregister_platform(dev);
1296exit_snd_probe: 1280exit_snd_probe:
1297 for_each_rsnd_dai(rdai, priv, i) { 1281 for_each_rsnd_dai(rdai, priv, i) {
1298 rsnd_dai_call(remove, &rdai->playback, rdai); 1282 rsnd_dai_call(remove, &rdai->playback, priv);
1299 rsnd_dai_call(remove, &rdai->capture, rdai); 1283 rsnd_dai_call(remove, &rdai->capture, priv);
1300 } 1284 }
1301 1285
1302 return ret; 1286 return ret;
@@ -1311,10 +1295,13 @@ static int rsnd_remove(struct platform_device *pdev)
1311 pm_runtime_disable(&pdev->dev); 1295 pm_runtime_disable(&pdev->dev);
1312 1296
1313 for_each_rsnd_dai(rdai, priv, i) { 1297 for_each_rsnd_dai(rdai, priv, i) {
1314 ret |= rsnd_dai_call(remove, &rdai->playback, rdai); 1298 ret |= rsnd_dai_call(remove, &rdai->playback, priv);
1315 ret |= rsnd_dai_call(remove, &rdai->capture, rdai); 1299 ret |= rsnd_dai_call(remove, &rdai->capture, priv);
1316 } 1300 }
1317 1301
1302 snd_soc_unregister_component(&pdev->dev);
1303 snd_soc_unregister_platform(&pdev->dev);
1304
1318 return ret; 1305 return ret;
1319} 1306}
1320 1307
diff --git a/sound/soc/sh/rcar/dvc.c b/sound/soc/sh/rcar/dvc.c
index 5380a4827ba7..d7f9ed959c4e 100644
--- a/sound/soc/sh/rcar/dvc.c
+++ b/sound/soc/sh/rcar/dvc.c
@@ -17,7 +17,6 @@
17struct rsnd_dvc { 17struct rsnd_dvc {
18 struct rsnd_dvc_platform_info *info; /* rcar_snd.h */ 18 struct rsnd_dvc_platform_info *info; /* rcar_snd.h */
19 struct rsnd_mod mod; 19 struct rsnd_mod mod;
20 struct clk *clk;
21 struct rsnd_kctrl_cfg_m volume; 20 struct rsnd_kctrl_cfg_m volume;
22 struct rsnd_kctrl_cfg_m mute; 21 struct rsnd_kctrl_cfg_m mute;
23 struct rsnd_kctrl_cfg_s ren; /* Ramp Enable */ 22 struct rsnd_kctrl_cfg_s ren; /* Ramp Enable */
@@ -118,9 +117,8 @@ static void rsnd_dvc_volume_update(struct rsnd_mod *mod)
118} 117}
119 118
120static int rsnd_dvc_probe_gen2(struct rsnd_mod *mod, 119static int rsnd_dvc_probe_gen2(struct rsnd_mod *mod,
121 struct rsnd_dai *rdai) 120 struct rsnd_priv *priv)
122{ 121{
123 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
124 struct device *dev = rsnd_priv_to_dev(priv); 122 struct device *dev = rsnd_priv_to_dev(priv);
125 123
126 dev_dbg(dev, "%s[%d] (Gen2) is probed\n", 124 dev_dbg(dev, "%s[%d] (Gen2) is probed\n",
@@ -129,12 +127,24 @@ static int rsnd_dvc_probe_gen2(struct rsnd_mod *mod,
129 return 0; 127 return 0;
130} 128}
131 129
130static int rsnd_dvc_remove_gen2(struct rsnd_mod *mod,
131 struct rsnd_priv *priv)
132{
133 struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod);
134
135 rsnd_kctrl_remove(dvc->volume);
136 rsnd_kctrl_remove(dvc->mute);
137 rsnd_kctrl_remove(dvc->ren);
138 rsnd_kctrl_remove(dvc->rup);
139 rsnd_kctrl_remove(dvc->rdown);
140
141 return 0;
142}
143
132static int rsnd_dvc_init(struct rsnd_mod *dvc_mod, 144static int rsnd_dvc_init(struct rsnd_mod *dvc_mod,
133 struct rsnd_dai *rdai) 145 struct rsnd_priv *priv)
134{ 146{
135 struct rsnd_dvc *dvc = rsnd_mod_to_dvc(dvc_mod);
136 struct rsnd_dai_stream *io = rsnd_mod_to_io(dvc_mod); 147 struct rsnd_dai_stream *io = rsnd_mod_to_io(dvc_mod);
137 struct rsnd_priv *priv = rsnd_mod_to_priv(dvc_mod);
138 struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io); 148 struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
139 struct device *dev = rsnd_priv_to_dev(priv); 149 struct device *dev = rsnd_priv_to_dev(priv);
140 int dvc_id = rsnd_mod_id(dvc_mod); 150 int dvc_id = rsnd_mod_id(dvc_mod);
@@ -153,7 +163,7 @@ static int rsnd_dvc_init(struct rsnd_mod *dvc_mod,
153 return -EINVAL; 163 return -EINVAL;
154 } 164 }
155 165
156 clk_prepare_enable(dvc->clk); 166 rsnd_mod_hw_start(dvc_mod);
157 167
158 /* 168 /*
159 * fixme 169 * fixme
@@ -173,23 +183,21 @@ static int rsnd_dvc_init(struct rsnd_mod *dvc_mod,
173 183
174 rsnd_mod_write(dvc_mod, DVC_DVUIR, 0); 184 rsnd_mod_write(dvc_mod, DVC_DVUIR, 0);
175 185
176 rsnd_adg_set_cmd_timsel_gen2(rdai, dvc_mod, io); 186 rsnd_adg_set_cmd_timsel_gen2(dvc_mod, io);
177 187
178 return 0; 188 return 0;
179} 189}
180 190
181static int rsnd_dvc_quit(struct rsnd_mod *mod, 191static int rsnd_dvc_quit(struct rsnd_mod *mod,
182 struct rsnd_dai *rdai) 192 struct rsnd_priv *priv)
183{ 193{
184 struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod); 194 rsnd_mod_hw_stop(mod);
185
186 clk_disable_unprepare(dvc->clk);
187 195
188 return 0; 196 return 0;
189} 197}
190 198
191static int rsnd_dvc_start(struct rsnd_mod *mod, 199static int rsnd_dvc_start(struct rsnd_mod *mod,
192 struct rsnd_dai *rdai) 200 struct rsnd_priv *priv)
193{ 201{
194 rsnd_mod_write(mod, CMD_CTRL, 0x10); 202 rsnd_mod_write(mod, CMD_CTRL, 0x10);
195 203
@@ -197,7 +205,7 @@ static int rsnd_dvc_start(struct rsnd_mod *mod,
197} 205}
198 206
199static int rsnd_dvc_stop(struct rsnd_mod *mod, 207static int rsnd_dvc_stop(struct rsnd_mod *mod,
200 struct rsnd_dai *rdai) 208 struct rsnd_priv *priv)
201{ 209{
202 rsnd_mod_write(mod, CMD_CTRL, 0); 210 rsnd_mod_write(mod, CMD_CTRL, 0);
203 211
@@ -205,16 +213,16 @@ static int rsnd_dvc_stop(struct rsnd_mod *mod,
205} 213}
206 214
207static int rsnd_dvc_pcm_new(struct rsnd_mod *mod, 215static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
208 struct rsnd_dai *rdai,
209 struct snd_soc_pcm_runtime *rtd) 216 struct snd_soc_pcm_runtime *rtd)
210{ 217{
211 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 218 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
212 struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod); 219 struct rsnd_dvc *dvc = rsnd_mod_to_dvc(mod);
220 int is_play = rsnd_io_is_play(io);
213 int ret; 221 int ret;
214 222
215 /* Volume */ 223 /* Volume */
216 ret = rsnd_kctrl_new_m(mod, rdai, rtd, 224 ret = rsnd_kctrl_new_m(mod, rtd,
217 rsnd_dai_is_play(rdai, io) ? 225 is_play ?
218 "DVC Out Playback Volume" : "DVC In Capture Volume", 226 "DVC Out Playback Volume" : "DVC In Capture Volume",
219 rsnd_dvc_volume_update, 227 rsnd_dvc_volume_update,
220 &dvc->volume, 0x00800000 - 1); 228 &dvc->volume, 0x00800000 - 1);
@@ -222,8 +230,8 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
222 return ret; 230 return ret;
223 231
224 /* Mute */ 232 /* Mute */
225 ret = rsnd_kctrl_new_m(mod, rdai, rtd, 233 ret = rsnd_kctrl_new_m(mod, rtd,
226 rsnd_dai_is_play(rdai, io) ? 234 is_play ?
227 "DVC Out Mute Switch" : "DVC In Mute Switch", 235 "DVC Out Mute Switch" : "DVC In Mute Switch",
228 rsnd_dvc_volume_update, 236 rsnd_dvc_volume_update,
229 &dvc->mute, 1); 237 &dvc->mute, 1);
@@ -231,16 +239,16 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
231 return ret; 239 return ret;
232 240
233 /* Ramp */ 241 /* Ramp */
234 ret = rsnd_kctrl_new_s(mod, rdai, rtd, 242 ret = rsnd_kctrl_new_s(mod, rtd,
235 rsnd_dai_is_play(rdai, io) ? 243 is_play ?
236 "DVC Out Ramp Switch" : "DVC In Ramp Switch", 244 "DVC Out Ramp Switch" : "DVC In Ramp Switch",
237 rsnd_dvc_volume_update, 245 rsnd_dvc_volume_update,
238 &dvc->ren, 1); 246 &dvc->ren, 1);
239 if (ret < 0) 247 if (ret < 0)
240 return ret; 248 return ret;
241 249
242 ret = rsnd_kctrl_new_e(mod, rdai, rtd, 250 ret = rsnd_kctrl_new_e(mod, rtd,
243 rsnd_dai_is_play(rdai, io) ? 251 is_play ?
244 "DVC Out Ramp Up Rate" : "DVC In Ramp Up Rate", 252 "DVC Out Ramp Up Rate" : "DVC In Ramp Up Rate",
245 &dvc->rup, 253 &dvc->rup,
246 rsnd_dvc_volume_update, 254 rsnd_dvc_volume_update,
@@ -248,8 +256,8 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
248 if (ret < 0) 256 if (ret < 0)
249 return ret; 257 return ret;
250 258
251 ret = rsnd_kctrl_new_e(mod, rdai, rtd, 259 ret = rsnd_kctrl_new_e(mod, rtd,
252 rsnd_dai_is_play(rdai, io) ? 260 is_play ?
253 "DVC Out Ramp Down Rate" : "DVC In Ramp Down Rate", 261 "DVC Out Ramp Down Rate" : "DVC In Ramp Down Rate",
254 &dvc->rdown, 262 &dvc->rdown,
255 rsnd_dvc_volume_update, 263 rsnd_dvc_volume_update,
@@ -264,6 +272,7 @@ static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
264static struct rsnd_mod_ops rsnd_dvc_ops = { 272static struct rsnd_mod_ops rsnd_dvc_ops = {
265 .name = DVC_NAME, 273 .name = DVC_NAME,
266 .probe = rsnd_dvc_probe_gen2, 274 .probe = rsnd_dvc_probe_gen2,
275 .remove = rsnd_dvc_remove_gen2,
267 .init = rsnd_dvc_init, 276 .init = rsnd_dvc_init,
268 .quit = rsnd_dvc_quit, 277 .quit = rsnd_dvc_quit,
269 .start = rsnd_dvc_start, 278 .start = rsnd_dvc_start,
@@ -356,9 +365,9 @@ int rsnd_dvc_probe(struct platform_device *pdev,
356 return PTR_ERR(clk); 365 return PTR_ERR(clk);
357 366
358 dvc->info = &info->dvc_info[i]; 367 dvc->info = &info->dvc_info[i];
359 dvc->clk = clk;
360 368
361 rsnd_mod_init(priv, &dvc->mod, &rsnd_dvc_ops, RSND_MOD_DVC, i); 369 rsnd_mod_init(&dvc->mod, &rsnd_dvc_ops,
370 clk, RSND_MOD_DVC, i);
362 371
363 dev_dbg(dev, "CMD%d probed\n", i); 372 dev_dbg(dev, "CMD%d probed\n", i);
364 } 373 }
diff --git a/sound/soc/sh/rcar/gen.c b/sound/soc/sh/rcar/gen.c
index 87a6f2d62775..de0685f2abae 100644
--- a/sound/soc/sh/rcar/gen.c
+++ b/sound/soc/sh/rcar/gen.c
@@ -309,8 +309,13 @@ static int rsnd_gen2_probe(struct platform_device *pdev,
309 RSND_GEN_M_REG(SRC_BUSIF_MODE, 0x0, 0x20), 309 RSND_GEN_M_REG(SRC_BUSIF_MODE, 0x0, 0x20),
310 RSND_GEN_M_REG(SRC_ROUTE_MODE0, 0xc, 0x20), 310 RSND_GEN_M_REG(SRC_ROUTE_MODE0, 0xc, 0x20),
311 RSND_GEN_M_REG(SRC_CTRL, 0x10, 0x20), 311 RSND_GEN_M_REG(SRC_CTRL, 0x10, 0x20),
312 RSND_GEN_M_REG(SRC_INT_ENABLE0, 0x18, 0x20),
312 RSND_GEN_M_REG(CMD_ROUTE_SLCT, 0x18c, 0x20), 313 RSND_GEN_M_REG(CMD_ROUTE_SLCT, 0x18c, 0x20),
313 RSND_GEN_M_REG(CMD_CTRL, 0x190, 0x20), 314 RSND_GEN_M_REG(CMD_CTRL, 0x190, 0x20),
315 RSND_GEN_S_REG(SCU_SYS_STATUS0, 0x1c8),
316 RSND_GEN_S_REG(SCU_SYS_INT_EN0, 0x1cc),
317 RSND_GEN_S_REG(SCU_SYS_STATUS1, 0x1d0),
318 RSND_GEN_S_REG(SCU_SYS_INT_EN1, 0x1c4),
314 RSND_GEN_M_REG(SRC_SWRSR, 0x200, 0x40), 319 RSND_GEN_M_REG(SRC_SWRSR, 0x200, 0x40),
315 RSND_GEN_M_REG(SRC_SRCIR, 0x204, 0x40), 320 RSND_GEN_M_REG(SRC_SRCIR, 0x204, 0x40),
316 RSND_GEN_M_REG(SRC_ADINR, 0x214, 0x40), 321 RSND_GEN_M_REG(SRC_ADINR, 0x214, 0x40),
@@ -403,6 +408,16 @@ static int rsnd_gen1_probe(struct platform_device *pdev,
403 RSND_GEN_M_REG(SRC_IFSVR, 0x220, 0x40), 408 RSND_GEN_M_REG(SRC_IFSVR, 0x220, 0x40),
404 RSND_GEN_M_REG(SRC_SRCCR, 0x224, 0x40), 409 RSND_GEN_M_REG(SRC_SRCCR, 0x224, 0x40),
405 RSND_GEN_M_REG(SRC_MNFSR, 0x228, 0x40), 410 RSND_GEN_M_REG(SRC_MNFSR, 0x228, 0x40),
411 /*
412 * ADD US
413 *
414 * SRC_STATUS
415 * SRC_INT_EN
416 * SCU_SYS_STATUS0
417 * SCU_SYS_STATUS1
418 * SCU_SYS_INT_EN0
419 * SCU_SYS_INT_EN1
420 */
406 }; 421 };
407 struct rsnd_regmap_field_conf conf_adg[] = { 422 struct rsnd_regmap_field_conf conf_adg[] = {
408 RSND_GEN_S_REG(BRRA, 0x00), 423 RSND_GEN_S_REG(BRRA, 0x00),
diff --git a/sound/soc/sh/rcar/rsnd.h b/sound/soc/sh/rcar/rsnd.h
index 5826c8abf794..e7914bd610e2 100644
--- a/sound/soc/sh/rcar/rsnd.h
+++ b/sound/soc/sh/rcar/rsnd.h
@@ -44,6 +44,8 @@ enum rsnd_reg {
44 RSND_REG_SRC_IFSCR, 44 RSND_REG_SRC_IFSCR,
45 RSND_REG_SRC_IFSVR, 45 RSND_REG_SRC_IFSVR,
46 RSND_REG_SRC_SRCCR, 46 RSND_REG_SRC_SRCCR,
47 RSND_REG_SCU_SYS_STATUS0,
48 RSND_REG_SCU_SYS_INT_EN0,
47 RSND_REG_CMD_ROUTE_SLCT, 49 RSND_REG_CMD_ROUTE_SLCT,
48 RSND_REG_DVC_SWRSR, 50 RSND_REG_DVC_SWRSR,
49 RSND_REG_DVC_DVUIR, 51 RSND_REG_DVC_DVUIR,
@@ -94,6 +96,9 @@ enum rsnd_reg {
94 RSND_REG_SHARE23, 96 RSND_REG_SHARE23,
95 RSND_REG_SHARE24, 97 RSND_REG_SHARE24,
96 RSND_REG_SHARE25, 98 RSND_REG_SHARE25,
99 RSND_REG_SHARE26,
100 RSND_REG_SHARE27,
101 RSND_REG_SHARE28,
97 102
98 RSND_REG_MAX, 103 RSND_REG_MAX,
99}; 104};
@@ -135,6 +140,9 @@ enum rsnd_reg {
135#define RSND_REG_DVC_VRCTR RSND_REG_SHARE23 140#define RSND_REG_DVC_VRCTR RSND_REG_SHARE23
136#define RSND_REG_DVC_VRPDR RSND_REG_SHARE24 141#define RSND_REG_DVC_VRPDR RSND_REG_SHARE24
137#define RSND_REG_DVC_VRDBR RSND_REG_SHARE25 142#define RSND_REG_DVC_VRDBR RSND_REG_SHARE25
143#define RSND_REG_SCU_SYS_STATUS1 RSND_REG_SHARE26
144#define RSND_REG_SCU_SYS_INT_EN1 RSND_REG_SHARE27
145#define RSND_REG_SRC_INT_ENABLE0 RSND_REG_SHARE28
138 146
139struct rsnd_of_data; 147struct rsnd_of_data;
140struct rsnd_priv; 148struct rsnd_priv;
@@ -182,9 +190,9 @@ void rsnd_dma_quit(struct rsnd_priv *priv,
182 * R-Car sound mod 190 * R-Car sound mod
183 */ 191 */
184enum rsnd_mod_type { 192enum rsnd_mod_type {
185 RSND_MOD_SRC = 0, 193 RSND_MOD_DVC = 0,
194 RSND_MOD_SRC,
186 RSND_MOD_SSI, 195 RSND_MOD_SSI,
187 RSND_MOD_DVC,
188 RSND_MOD_MAX, 196 RSND_MOD_MAX,
189}; 197};
190 198
@@ -192,32 +200,31 @@ struct rsnd_mod_ops {
192 char *name; 200 char *name;
193 char* (*dma_name)(struct rsnd_mod *mod); 201 char* (*dma_name)(struct rsnd_mod *mod);
194 int (*probe)(struct rsnd_mod *mod, 202 int (*probe)(struct rsnd_mod *mod,
195 struct rsnd_dai *rdai); 203 struct rsnd_priv *priv);
196 int (*remove)(struct rsnd_mod *mod, 204 int (*remove)(struct rsnd_mod *mod,
197 struct rsnd_dai *rdai); 205 struct rsnd_priv *priv);
198 int (*init)(struct rsnd_mod *mod, 206 int (*init)(struct rsnd_mod *mod,
199 struct rsnd_dai *rdai); 207 struct rsnd_priv *priv);
200 int (*quit)(struct rsnd_mod *mod, 208 int (*quit)(struct rsnd_mod *mod,
201 struct rsnd_dai *rdai); 209 struct rsnd_priv *priv);
202 int (*start)(struct rsnd_mod *mod, 210 int (*start)(struct rsnd_mod *mod,
203 struct rsnd_dai *rdai); 211 struct rsnd_priv *priv);
204 int (*stop)(struct rsnd_mod *mod, 212 int (*stop)(struct rsnd_mod *mod,
205 struct rsnd_dai *rdai); 213 struct rsnd_priv *priv);
206 int (*pcm_new)(struct rsnd_mod *mod, 214 int (*pcm_new)(struct rsnd_mod *mod,
207 struct rsnd_dai *rdai,
208 struct snd_soc_pcm_runtime *rtd); 215 struct snd_soc_pcm_runtime *rtd);
209 int (*fallback)(struct rsnd_mod *mod, 216 int (*fallback)(struct rsnd_mod *mod,
210 struct rsnd_dai *rdai); 217 struct rsnd_priv *priv);
211}; 218};
212 219
213struct rsnd_dai_stream; 220struct rsnd_dai_stream;
214struct rsnd_mod { 221struct rsnd_mod {
215 int id; 222 int id;
216 enum rsnd_mod_type type; 223 enum rsnd_mod_type type;
217 struct rsnd_priv *priv;
218 struct rsnd_mod_ops *ops; 224 struct rsnd_mod_ops *ops;
219 struct rsnd_dma dma; 225 struct rsnd_dma dma;
220 struct rsnd_dai_stream *io; 226 struct rsnd_dai_stream *io;
227 struct clk *clk;
221 u32 status; 228 u32 status;
222}; 229};
223/* 230/*
@@ -248,15 +255,17 @@ struct rsnd_mod {
248#define __rsnd_mod_call_pcm_new 0 255#define __rsnd_mod_call_pcm_new 0
249#define __rsnd_mod_call_fallback 0 256#define __rsnd_mod_call_fallback 0
250 257
251#define rsnd_mod_to_priv(mod) ((mod)->priv) 258#define rsnd_mod_to_priv(mod) (rsnd_io_to_priv(rsnd_mod_to_io(mod)))
252#define rsnd_mod_to_dma(mod) (&(mod)->dma) 259#define rsnd_mod_to_dma(mod) (&(mod)->dma)
253#define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma) 260#define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma)
254#define rsnd_mod_to_io(mod) ((mod)->io) 261#define rsnd_mod_to_io(mod) ((mod)->io)
255#define rsnd_mod_id(mod) ((mod)->id) 262#define rsnd_mod_id(mod) ((mod)->id)
263#define rsnd_mod_hw_start(mod) clk_prepare_enable((mod)->clk)
264#define rsnd_mod_hw_stop(mod) clk_disable_unprepare((mod)->clk)
256 265
257void rsnd_mod_init(struct rsnd_priv *priv, 266void rsnd_mod_init(struct rsnd_mod *mod,
258 struct rsnd_mod *mod,
259 struct rsnd_mod_ops *ops, 267 struct rsnd_mod_ops *ops,
268 struct clk *clk,
260 enum rsnd_mod_type type, 269 enum rsnd_mod_type type,
261 int id); 270 int id);
262char *rsnd_mod_name(struct rsnd_mod *mod); 271char *rsnd_mod_name(struct rsnd_mod *mod);
@@ -270,6 +279,7 @@ struct rsnd_dai_stream {
270 struct snd_pcm_substream *substream; 279 struct snd_pcm_substream *substream;
271 struct rsnd_mod *mod[RSND_MOD_MAX]; 280 struct rsnd_mod *mod[RSND_MOD_MAX];
272 struct rsnd_dai_path_info *info; /* rcar_snd.h */ 281 struct rsnd_dai_path_info *info; /* rcar_snd.h */
282 struct rsnd_dai *rdai;
273 int byte_pos; 283 int byte_pos;
274 int period_pos; 284 int period_pos;
275 int byte_per_period; 285 int byte_per_period;
@@ -278,12 +288,18 @@ struct rsnd_dai_stream {
278#define rsnd_io_to_mod_ssi(io) ((io)->mod[RSND_MOD_SSI]) 288#define rsnd_io_to_mod_ssi(io) ((io)->mod[RSND_MOD_SSI])
279#define rsnd_io_to_mod_src(io) ((io)->mod[RSND_MOD_SRC]) 289#define rsnd_io_to_mod_src(io) ((io)->mod[RSND_MOD_SRC])
280#define rsnd_io_to_mod_dvc(io) ((io)->mod[RSND_MOD_DVC]) 290#define rsnd_io_to_mod_dvc(io) ((io)->mod[RSND_MOD_DVC])
291#define rsnd_io_to_rdai(io) ((io)->rdai)
292#define rsnd_io_to_priv(io) (rsnd_rdai_to_priv(rsnd_io_to_rdai(io)))
293#define rsnd_io_is_play(io) (&rsnd_io_to_rdai(io)->playback == io)
294#define rsnd_io_to_runtime(io) ((io)->substream ? \
295 (io)->substream->runtime : NULL)
296
281 297
282struct rsnd_dai { 298struct rsnd_dai {
283 char name[RSND_DAI_NAME_SIZE]; 299 char name[RSND_DAI_NAME_SIZE];
284 struct rsnd_dai_platform_info *info; /* rcar_snd.h */
285 struct rsnd_dai_stream playback; 300 struct rsnd_dai_stream playback;
286 struct rsnd_dai_stream capture; 301 struct rsnd_dai_stream capture;
302 struct rsnd_priv *priv;
287 303
288 unsigned int clk_master:1; 304 unsigned int clk_master:1;
289 unsigned int bit_clk_inv:1; 305 unsigned int bit_clk_inv:1;
@@ -293,22 +309,18 @@ struct rsnd_dai {
293}; 309};
294 310
295#define rsnd_rdai_nr(priv) ((priv)->rdai_nr) 311#define rsnd_rdai_nr(priv) ((priv)->rdai_nr)
312#define rsnd_rdai_is_clk_master(rdai) ((rdai)->clk_master)
313#define rsnd_rdai_to_priv(rdai) ((rdai)->priv)
296#define for_each_rsnd_dai(rdai, priv, i) \ 314#define for_each_rsnd_dai(rdai, priv, i) \
297 for (i = 0; \ 315 for (i = 0; \
298 (i < rsnd_rdai_nr(priv)) && \ 316 (i < rsnd_rdai_nr(priv)) && \
299 ((rdai) = rsnd_dai_get(priv, i)); \ 317 ((rdai) = rsnd_rdai_get(priv, i)); \
300 i++) 318 i++)
301 319
302struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id); 320struct rsnd_dai *rsnd_rdai_get(struct rsnd_priv *priv, int id);
303int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io);
304int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai);
305#define rsnd_dai_get_platform_info(rdai) ((rdai)->info)
306#define rsnd_io_to_runtime(io) ((io)->substream ? \
307 (io)->substream->runtime : NULL)
308 321
309void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt); 322void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt);
310int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional); 323int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional);
311#define rsnd_dai_is_clk_master(rdai) ((rdai)->clk_master)
312 324
313/* 325/*
314 * R-Car Gen1/Gen2 326 * R-Car Gen1/Gen2
@@ -339,15 +351,12 @@ int rsnd_adg_set_convert_clk_gen1(struct rsnd_priv *priv,
339 unsigned int src_rate, 351 unsigned int src_rate,
340 unsigned int dst_rate); 352 unsigned int dst_rate);
341int rsnd_adg_set_convert_clk_gen2(struct rsnd_mod *mod, 353int rsnd_adg_set_convert_clk_gen2(struct rsnd_mod *mod,
342 struct rsnd_dai *rdai,
343 struct rsnd_dai_stream *io, 354 struct rsnd_dai_stream *io,
344 unsigned int src_rate, 355 unsigned int src_rate,
345 unsigned int dst_rate); 356 unsigned int dst_rate);
346int rsnd_adg_set_convert_timing_gen2(struct rsnd_mod *mod, 357int rsnd_adg_set_convert_timing_gen2(struct rsnd_mod *mod,
347 struct rsnd_dai *rdai,
348 struct rsnd_dai_stream *io); 358 struct rsnd_dai_stream *io);
349int rsnd_adg_set_cmd_timsel_gen2(struct rsnd_dai *rdai, 359int rsnd_adg_set_cmd_timsel_gen2(struct rsnd_mod *mod,
350 struct rsnd_mod *mod,
351 struct rsnd_dai_stream *io); 360 struct rsnd_dai_stream *io);
352 361
353/* 362/*
@@ -427,6 +436,8 @@ struct rsnd_kctrl_cfg {
427 u32 *val; 436 u32 *val;
428 const char * const *texts; 437 const char * const *texts;
429 void (*update)(struct rsnd_mod *mod); 438 void (*update)(struct rsnd_mod *mod);
439 struct snd_card *card;
440 struct snd_kcontrol *kctrl;
430}; 441};
431 442
432#define RSND_DVC_CHANNELS 2 443#define RSND_DVC_CHANNELS 2
@@ -440,22 +451,22 @@ struct rsnd_kctrl_cfg_s {
440 u32 val; 451 u32 val;
441}; 452};
442 453
454void _rsnd_kctrl_remove(struct rsnd_kctrl_cfg *cfg);
455#define rsnd_kctrl_remove(_cfg) _rsnd_kctrl_remove(&((_cfg).cfg))
456
443int rsnd_kctrl_new_m(struct rsnd_mod *mod, 457int rsnd_kctrl_new_m(struct rsnd_mod *mod,
444 struct rsnd_dai *rdai,
445 struct snd_soc_pcm_runtime *rtd, 458 struct snd_soc_pcm_runtime *rtd,
446 const unsigned char *name, 459 const unsigned char *name,
447 void (*update)(struct rsnd_mod *mod), 460 void (*update)(struct rsnd_mod *mod),
448 struct rsnd_kctrl_cfg_m *_cfg, 461 struct rsnd_kctrl_cfg_m *_cfg,
449 u32 max); 462 u32 max);
450int rsnd_kctrl_new_s(struct rsnd_mod *mod, 463int rsnd_kctrl_new_s(struct rsnd_mod *mod,
451 struct rsnd_dai *rdai,
452 struct snd_soc_pcm_runtime *rtd, 464 struct snd_soc_pcm_runtime *rtd,
453 const unsigned char *name, 465 const unsigned char *name,
454 void (*update)(struct rsnd_mod *mod), 466 void (*update)(struct rsnd_mod *mod),
455 struct rsnd_kctrl_cfg_s *_cfg, 467 struct rsnd_kctrl_cfg_s *_cfg,
456 u32 max); 468 u32 max);
457int rsnd_kctrl_new_e(struct rsnd_mod *mod, 469int rsnd_kctrl_new_e(struct rsnd_mod *mod,
458 struct rsnd_dai *rdai,
459 struct snd_soc_pcm_runtime *rtd, 470 struct snd_soc_pcm_runtime *rtd,
460 const unsigned char *name, 471 const unsigned char *name,
461 struct rsnd_kctrl_cfg_s *_cfg, 472 struct rsnd_kctrl_cfg_s *_cfg,
@@ -474,14 +485,10 @@ unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
474 struct rsnd_dai_stream *io, 485 struct rsnd_dai_stream *io,
475 struct snd_pcm_runtime *runtime); 486 struct snd_pcm_runtime *runtime);
476int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod, 487int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
477 struct rsnd_dai *rdai,
478 int use_busif); 488 int use_busif);
479int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod, 489int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod);
480 struct rsnd_dai *rdai); 490int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod);
481int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod, 491int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod);
482 struct rsnd_dai *rdai);
483int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod,
484 struct rsnd_dai *rdai);
485 492
486#define rsnd_src_nr(priv) ((priv)->src_nr) 493#define rsnd_src_nr(priv) ((priv)->src_nr)
487 494
diff --git a/sound/soc/sh/rcar/src.c b/sound/soc/sh/rcar/src.c
index eede3ac6eed2..81c182b4bad5 100644
--- a/sound/soc/sh/rcar/src.c
+++ b/sound/soc/sh/rcar/src.c
@@ -12,10 +12,17 @@
12 12
13#define SRC_NAME "src" 13#define SRC_NAME "src"
14 14
15/* SRCx_STATUS */
16#define OUF_SRCO ((1 << 12) | (1 << 13))
17#define OUF_SRCI ((1 << 9) | (1 << 8))
18
19/* SCU_SYSTEM_STATUS0/1 */
20#define OUF_SRC(id) ((1 << (id + 16)) | (1 << id))
21
15struct rsnd_src { 22struct rsnd_src {
16 struct rsnd_src_platform_info *info; /* rcar_snd.h */ 23 struct rsnd_src_platform_info *info; /* rcar_snd.h */
17 struct rsnd_mod mod; 24 struct rsnd_mod mod;
18 struct clk *clk; 25 int err;
19}; 26};
20 27
21#define RSND_SRC_NAME_SIZE 16 28#define RSND_SRC_NAME_SIZE 16
@@ -107,10 +114,10 @@ struct rsnd_src {
107 * Gen1/Gen2 common functions 114 * Gen1/Gen2 common functions
108 */ 115 */
109int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod, 116int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
110 struct rsnd_dai *rdai,
111 int use_busif) 117 int use_busif)
112{ 118{
113 struct rsnd_dai_stream *io = rsnd_mod_to_io(ssi_mod); 119 struct rsnd_dai_stream *io = rsnd_mod_to_io(ssi_mod);
120 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
114 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 121 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
115 int ssi_id = rsnd_mod_id(ssi_mod); 122 int ssi_id = rsnd_mod_id(ssi_mod);
116 123
@@ -140,7 +147,7 @@ int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
140 if (shift >= 0) 147 if (shift >= 0)
141 rsnd_mod_bset(ssi_mod, SSI_MODE1, 148 rsnd_mod_bset(ssi_mod, SSI_MODE1,
142 0x3 << shift, 149 0x3 << shift,
143 rsnd_dai_is_clk_master(rdai) ? 150 rsnd_rdai_is_clk_master(rdai) ?
144 0x2 << shift : 0x1 << shift); 151 0x2 << shift : 0x1 << shift);
145 } 152 }
146 153
@@ -174,8 +181,7 @@ int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
174 return 0; 181 return 0;
175} 182}
176 183
177int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod, 184int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod)
178 struct rsnd_dai *rdai)
179{ 185{
180 /* 186 /*
181 * DMA settings for SSIU 187 * DMA settings for SSIU
@@ -185,8 +191,7 @@ int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod,
185 return 0; 191 return 0;
186} 192}
187 193
188int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod, 194int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod)
189 struct rsnd_dai *rdai)
190{ 195{
191 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); 196 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
192 197
@@ -202,8 +207,7 @@ int rsnd_src_ssi_irq_enable(struct rsnd_mod *ssi_mod,
202 return 0; 207 return 0;
203} 208}
204 209
205int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod, 210int rsnd_src_ssi_irq_disable(struct rsnd_mod *ssi_mod)
206 struct rsnd_dai *rdai)
207{ 211{
208 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod); 212 struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
209 213
@@ -240,8 +244,7 @@ unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
240 return rate; 244 return rate;
241} 245}
242 246
243static int rsnd_src_set_convert_rate(struct rsnd_mod *mod, 247static int rsnd_src_set_convert_rate(struct rsnd_mod *mod)
244 struct rsnd_dai *rdai)
245{ 248{
246 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 249 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
247 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 250 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
@@ -273,12 +276,13 @@ static int rsnd_src_set_convert_rate(struct rsnd_mod *mod,
273 return 0; 276 return 0;
274} 277}
275 278
276static int rsnd_src_init(struct rsnd_mod *mod, 279static int rsnd_src_init(struct rsnd_mod *mod)
277 struct rsnd_dai *rdai)
278{ 280{
279 struct rsnd_src *src = rsnd_mod_to_src(mod); 281 struct rsnd_src *src = rsnd_mod_to_src(mod);
280 282
281 clk_prepare_enable(src->clk); 283 rsnd_mod_hw_start(mod);
284
285 src->err = 0;
282 286
283 /* 287 /*
284 * Initialize the operation of the SRC internal circuits 288 * Initialize the operation of the SRC internal circuits
@@ -290,11 +294,16 @@ static int rsnd_src_init(struct rsnd_mod *mod,
290} 294}
291 295
292static int rsnd_src_quit(struct rsnd_mod *mod, 296static int rsnd_src_quit(struct rsnd_mod *mod,
293 struct rsnd_dai *rdai) 297 struct rsnd_priv *priv)
294{ 298{
295 struct rsnd_src *src = rsnd_mod_to_src(mod); 299 struct rsnd_src *src = rsnd_mod_to_src(mod);
300 struct device *dev = rsnd_priv_to_dev(priv);
301
302 rsnd_mod_hw_stop(mod);
296 303
297 clk_disable_unprepare(src->clk); 304 if (src->err)
305 dev_warn(dev, "%s[%d] under/over flow err = %d\n",
306 rsnd_mod_name(mod), rsnd_mod_id(mod), src->err);
298 307
299 return 0; 308 return 0;
300} 309}
@@ -319,8 +328,7 @@ static int rsnd_src_stop(struct rsnd_mod *mod)
319/* 328/*
320 * Gen1 functions 329 * Gen1 functions
321 */ 330 */
322static int rsnd_src_set_route_gen1(struct rsnd_mod *mod, 331static int rsnd_src_set_route_gen1(struct rsnd_mod *mod)
323 struct rsnd_dai *rdai)
324{ 332{
325 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 333 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
326 struct src_route_config { 334 struct src_route_config {
@@ -348,7 +356,7 @@ static int rsnd_src_set_route_gen1(struct rsnd_mod *mod,
348 /* 356 /*
349 * SRC_ROUTE_SELECT 357 * SRC_ROUTE_SELECT
350 */ 358 */
351 val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2; 359 val = rsnd_io_is_play(io) ? 0x1 : 0x2;
352 val = val << routes[id].shift; 360 val = val << routes[id].shift;
353 mask = routes[id].mask << routes[id].shift; 361 mask = routes[id].mask << routes[id].shift;
354 362
@@ -357,8 +365,7 @@ static int rsnd_src_set_route_gen1(struct rsnd_mod *mod,
357 return 0; 365 return 0;
358} 366}
359 367
360static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod, 368static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod)
361 struct rsnd_dai *rdai)
362{ 369{
363 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 370 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
364 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 371 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
@@ -416,13 +423,12 @@ static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod,
416 return 0; 423 return 0;
417} 424}
418 425
419static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod, 426static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod)
420 struct rsnd_dai *rdai)
421{ 427{
422 struct rsnd_src *src = rsnd_mod_to_src(mod); 428 struct rsnd_src *src = rsnd_mod_to_src(mod);
423 int ret; 429 int ret;
424 430
425 ret = rsnd_src_set_convert_rate(mod, rdai); 431 ret = rsnd_src_set_convert_rate(mod);
426 if (ret < 0) 432 if (ret < 0)
427 return ret; 433 return ret;
428 434
@@ -443,9 +449,8 @@ static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod,
443} 449}
444 450
445static int rsnd_src_probe_gen1(struct rsnd_mod *mod, 451static int rsnd_src_probe_gen1(struct rsnd_mod *mod,
446 struct rsnd_dai *rdai) 452 struct rsnd_priv *priv)
447{ 453{
448 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
449 struct device *dev = rsnd_priv_to_dev(priv); 454 struct device *dev = rsnd_priv_to_dev(priv);
450 455
451 dev_dbg(dev, "%s[%d] (Gen1) is probed\n", 456 dev_dbg(dev, "%s[%d] (Gen1) is probed\n",
@@ -455,23 +460,23 @@ static int rsnd_src_probe_gen1(struct rsnd_mod *mod,
455} 460}
456 461
457static int rsnd_src_init_gen1(struct rsnd_mod *mod, 462static int rsnd_src_init_gen1(struct rsnd_mod *mod,
458 struct rsnd_dai *rdai) 463 struct rsnd_priv *priv)
459{ 464{
460 int ret; 465 int ret;
461 466
462 ret = rsnd_src_init(mod, rdai); 467 ret = rsnd_src_init(mod);
463 if (ret < 0) 468 if (ret < 0)
464 return ret; 469 return ret;
465 470
466 ret = rsnd_src_set_route_gen1(mod, rdai); 471 ret = rsnd_src_set_route_gen1(mod);
467 if (ret < 0) 472 if (ret < 0)
468 return ret; 473 return ret;
469 474
470 ret = rsnd_src_set_convert_rate_gen1(mod, rdai); 475 ret = rsnd_src_set_convert_rate_gen1(mod);
471 if (ret < 0) 476 if (ret < 0)
472 return ret; 477 return ret;
473 478
474 ret = rsnd_src_set_convert_timing_gen1(mod, rdai); 479 ret = rsnd_src_set_convert_timing_gen1(mod);
475 if (ret < 0) 480 if (ret < 0)
476 return ret; 481 return ret;
477 482
@@ -479,7 +484,7 @@ static int rsnd_src_init_gen1(struct rsnd_mod *mod,
479} 484}
480 485
481static int rsnd_src_start_gen1(struct rsnd_mod *mod, 486static int rsnd_src_start_gen1(struct rsnd_mod *mod,
482 struct rsnd_dai *rdai) 487 struct rsnd_priv *priv)
483{ 488{
484 int id = rsnd_mod_id(mod); 489 int id = rsnd_mod_id(mod);
485 490
@@ -489,7 +494,7 @@ static int rsnd_src_start_gen1(struct rsnd_mod *mod,
489} 494}
490 495
491static int rsnd_src_stop_gen1(struct rsnd_mod *mod, 496static int rsnd_src_stop_gen1(struct rsnd_mod *mod,
492 struct rsnd_dai *rdai) 497 struct rsnd_priv *priv)
493{ 498{
494 int id = rsnd_mod_id(mod); 499 int id = rsnd_mod_id(mod);
495 500
@@ -510,8 +515,111 @@ static struct rsnd_mod_ops rsnd_src_gen1_ops = {
510/* 515/*
511 * Gen2 functions 516 * Gen2 functions
512 */ 517 */
513static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod, 518#define rsnd_src_irq_enable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 1)
514 struct rsnd_dai *rdai) 519#define rsnd_src_irq_disable_gen2(mod) rsnd_src_irq_ctrol_gen2(mod, 0)
520static void rsnd_src_irq_ctrol_gen2(struct rsnd_mod *mod, int enable)
521{
522 struct rsnd_src *src = rsnd_mod_to_src(mod);
523 u32 sys_int_val, int_val, sys_int_mask;
524 int irq = src->info->irq;
525 int id = rsnd_mod_id(mod);
526
527 sys_int_val =
528 sys_int_mask = OUF_SRC(id);
529 int_val = 0x3300;
530
531 /*
532 * IRQ is not supported on non-DT
533 * see
534 * rsnd_src_probe_gen2()
535 */
536 if ((irq <= 0) || !enable) {
537 sys_int_val = 0;
538 int_val = 0;
539 }
540
541 rsnd_mod_write(mod, SRC_INT_ENABLE0, int_val);
542 rsnd_mod_bset(mod, SCU_SYS_INT_EN0, sys_int_mask, sys_int_val);
543 rsnd_mod_bset(mod, SCU_SYS_INT_EN1, sys_int_mask, sys_int_val);
544}
545
546static void rsnd_src_error_clear_gen2(struct rsnd_mod *mod)
547{
548 u32 val = OUF_SRC(rsnd_mod_id(mod));
549
550 rsnd_mod_bset(mod, SCU_SYS_STATUS0, val, val);
551 rsnd_mod_bset(mod, SCU_SYS_STATUS1, val, val);
552}
553
554static bool rsnd_src_error_record_gen2(struct rsnd_mod *mod)
555{
556 u32 val = OUF_SRC(rsnd_mod_id(mod));
557 bool ret = false;
558
559 if ((rsnd_mod_read(mod, SCU_SYS_STATUS0) & val) ||
560 (rsnd_mod_read(mod, SCU_SYS_STATUS1) & val)) {
561 struct rsnd_src *src = rsnd_mod_to_src(mod);
562
563 src->err++;
564 ret = true;
565 }
566
567 /* clear error static */
568 rsnd_src_error_clear_gen2(mod);
569
570 return ret;
571}
572
573static int _rsnd_src_start_gen2(struct rsnd_mod *mod)
574{
575 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
576 u32 val = rsnd_io_to_mod_dvc(io) ? 0x01 : 0x11;
577
578 rsnd_mod_write(mod, SRC_CTRL, val);
579
580 rsnd_src_error_clear_gen2(mod);
581
582 rsnd_src_start(mod);
583
584 rsnd_src_irq_enable_gen2(mod);
585
586 return 0;
587}
588
589static int _rsnd_src_stop_gen2(struct rsnd_mod *mod)
590{
591 rsnd_src_irq_disable_gen2(mod);
592
593 rsnd_mod_write(mod, SRC_CTRL, 0);
594
595 rsnd_src_error_record_gen2(mod);
596
597 return rsnd_src_stop(mod);
598}
599
600static irqreturn_t rsnd_src_interrupt_gen2(int irq, void *data)
601{
602 struct rsnd_mod *mod = data;
603 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
604
605 if (!io)
606 return IRQ_NONE;
607
608 if (rsnd_src_error_record_gen2(mod)) {
609 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
610 struct device *dev = rsnd_priv_to_dev(priv);
611
612 _rsnd_src_stop_gen2(mod);
613 _rsnd_src_start_gen2(mod);
614
615 dev_dbg(dev, "%s[%d] restart\n",
616 rsnd_mod_name(mod), rsnd_mod_id(mod));
617 }
618
619 return IRQ_HANDLED;
620}
621
622static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod)
515{ 623{
516 struct rsnd_priv *priv = rsnd_mod_to_priv(mod); 624 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
517 struct device *dev = rsnd_priv_to_dev(priv); 625 struct device *dev = rsnd_priv_to_dev(priv);
@@ -535,7 +643,7 @@ static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod,
535 return -EINVAL; 643 return -EINVAL;
536 } 644 }
537 645
538 ret = rsnd_src_set_convert_rate(mod, rdai); 646 ret = rsnd_src_set_convert_rate(mod);
539 if (ret < 0) 647 if (ret < 0)
540 return ret; 648 return ret;
541 649
@@ -563,8 +671,7 @@ static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod,
563 return 0; 671 return 0;
564} 672}
565 673
566static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod, 674static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod)
567 struct rsnd_dai *rdai)
568{ 675{
569 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 676 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
570 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 677 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
@@ -573,59 +680,78 @@ static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod,
573 int ret; 680 int ret;
574 681
575 if (convert_rate) 682 if (convert_rate)
576 ret = rsnd_adg_set_convert_clk_gen2(mod, rdai, io, 683 ret = rsnd_adg_set_convert_clk_gen2(mod, io,
577 runtime->rate, 684 runtime->rate,
578 convert_rate); 685 convert_rate);
579 else 686 else
580 ret = rsnd_adg_set_convert_timing_gen2(mod, rdai, io); 687 ret = rsnd_adg_set_convert_timing_gen2(mod, io);
581 688
582 return ret; 689 return ret;
583} 690}
584 691
585static int rsnd_src_probe_gen2(struct rsnd_mod *mod, 692static int rsnd_src_probe_gen2(struct rsnd_mod *mod,
586 struct rsnd_dai *rdai) 693 struct rsnd_priv *priv)
587{ 694{
588 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
589 struct rsnd_src *src = rsnd_mod_to_src(mod); 695 struct rsnd_src *src = rsnd_mod_to_src(mod);
590 struct device *dev = rsnd_priv_to_dev(priv); 696 struct device *dev = rsnd_priv_to_dev(priv);
697 int irq = src->info->irq;
591 int ret; 698 int ret;
592 699
700 if (irq > 0) {
701 /*
702 * IRQ is not supported on non-DT
703 * see
704 * rsnd_src_irq_enable_gen2()
705 */
706 ret = devm_request_irq(dev, irq,
707 rsnd_src_interrupt_gen2,
708 IRQF_SHARED,
709 dev_name(dev), mod);
710 if (ret)
711 goto rsnd_src_probe_gen2_fail;
712 }
713
593 ret = rsnd_dma_init(priv, 714 ret = rsnd_dma_init(priv,
594 rsnd_mod_to_dma(mod), 715 rsnd_mod_to_dma(mod),
595 rsnd_info_is_playback(priv, src), 716 rsnd_info_is_playback(priv, src),
596 src->info->dma_id); 717 src->info->dma_id);
597 if (ret < 0) 718 if (ret)
598 dev_err(dev, "%s[%d] (Gen2) failed\n", 719 goto rsnd_src_probe_gen2_fail;
599 rsnd_mod_name(mod), rsnd_mod_id(mod)); 720
600 else 721 dev_dbg(dev, "%s[%d] (Gen2) is probed\n",
601 dev_dbg(dev, "%s[%d] (Gen2) is probed\n", 722 rsnd_mod_name(mod), rsnd_mod_id(mod));
602 rsnd_mod_name(mod), rsnd_mod_id(mod)); 723
724 return ret;
725
726rsnd_src_probe_gen2_fail:
727 dev_err(dev, "%s[%d] (Gen2) failed\n",
728 rsnd_mod_name(mod), rsnd_mod_id(mod));
603 729
604 return ret; 730 return ret;
605} 731}
606 732
607static int rsnd_src_remove_gen2(struct rsnd_mod *mod, 733static int rsnd_src_remove_gen2(struct rsnd_mod *mod,
608 struct rsnd_dai *rdai) 734 struct rsnd_priv *priv)
609{ 735{
610 rsnd_dma_quit(rsnd_mod_to_priv(mod), rsnd_mod_to_dma(mod)); 736 rsnd_dma_quit(priv, rsnd_mod_to_dma(mod));
611 737
612 return 0; 738 return 0;
613} 739}
614 740
615static int rsnd_src_init_gen2(struct rsnd_mod *mod, 741static int rsnd_src_init_gen2(struct rsnd_mod *mod,
616 struct rsnd_dai *rdai) 742 struct rsnd_priv *priv)
617{ 743{
618 int ret; 744 int ret;
619 745
620 ret = rsnd_src_init(mod, rdai); 746 ret = rsnd_src_init(mod);
621 if (ret < 0) 747 if (ret < 0)
622 return ret; 748 return ret;
623 749
624 ret = rsnd_src_set_convert_rate_gen2(mod, rdai); 750 ret = rsnd_src_set_convert_rate_gen2(mod);
625 if (ret < 0) 751 if (ret < 0)
626 return ret; 752 return ret;
627 753
628 ret = rsnd_src_set_convert_timing_gen2(mod, rdai); 754 ret = rsnd_src_set_convert_timing_gen2(mod);
629 if (ret < 0) 755 if (ret < 0)
630 return ret; 756 return ret;
631 757
@@ -633,29 +759,23 @@ static int rsnd_src_init_gen2(struct rsnd_mod *mod,
633} 759}
634 760
635static int rsnd_src_start_gen2(struct rsnd_mod *mod, 761static int rsnd_src_start_gen2(struct rsnd_mod *mod,
636 struct rsnd_dai *rdai) 762 struct rsnd_priv *priv)
637{ 763{
638 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 764 rsnd_dma_start(rsnd_mod_to_dma(mod));
639 struct rsnd_src *src = rsnd_mod_to_src(mod);
640 u32 val = rsnd_io_to_mod_dvc(io) ? 0x01 : 0x11;
641
642 rsnd_dma_start(rsnd_mod_to_dma(&src->mod));
643 765
644 rsnd_mod_write(mod, SRC_CTRL, val); 766 return _rsnd_src_start_gen2(mod);
645
646 return rsnd_src_start(mod);
647} 767}
648 768
649static int rsnd_src_stop_gen2(struct rsnd_mod *mod, 769static int rsnd_src_stop_gen2(struct rsnd_mod *mod,
650 struct rsnd_dai *rdai) 770 struct rsnd_priv *priv)
651{ 771{
652 struct rsnd_src *src = rsnd_mod_to_src(mod); 772 int ret;
653 773
654 rsnd_mod_write(mod, SRC_CTRL, 0); 774 ret = _rsnd_src_stop_gen2(mod);
655 775
656 rsnd_dma_stop(rsnd_mod_to_dma(&src->mod)); 776 rsnd_dma_stop(rsnd_mod_to_dma(mod));
657 777
658 return rsnd_src_stop(mod); 778 return ret;
659} 779}
660 780
661static struct rsnd_mod_ops rsnd_src_gen2_ops = { 781static struct rsnd_mod_ops rsnd_src_gen2_ops = {
@@ -681,10 +801,11 @@ static void rsnd_of_parse_src(struct platform_device *pdev,
681 struct rsnd_priv *priv) 801 struct rsnd_priv *priv)
682{ 802{
683 struct device_node *src_node; 803 struct device_node *src_node;
804 struct device_node *np;
684 struct rcar_snd_info *info = rsnd_priv_to_info(priv); 805 struct rcar_snd_info *info = rsnd_priv_to_info(priv);
685 struct rsnd_src_platform_info *src_info; 806 struct rsnd_src_platform_info *src_info;
686 struct device *dev = &pdev->dev; 807 struct device *dev = &pdev->dev;
687 int nr; 808 int nr, i;
688 809
689 if (!of_data) 810 if (!of_data)
690 return; 811 return;
@@ -708,6 +829,13 @@ static void rsnd_of_parse_src(struct platform_device *pdev,
708 info->src_info = src_info; 829 info->src_info = src_info;
709 info->src_info_nr = nr; 830 info->src_info_nr = nr;
710 831
832 i = 0;
833 for_each_child_of_node(src_node, np) {
834 src_info[i].irq = irq_of_parse_and_map(np, 0);
835
836 i++;
837 }
838
711rsnd_of_parse_src_end: 839rsnd_of_parse_src_end:
712 of_node_put(src_node); 840 of_node_put(src_node);
713} 841}
@@ -761,9 +889,8 @@ int rsnd_src_probe(struct platform_device *pdev,
761 return PTR_ERR(clk); 889 return PTR_ERR(clk);
762 890
763 src->info = &info->src_info[i]; 891 src->info = &info->src_info[i];
764 src->clk = clk;
765 892
766 rsnd_mod_init(priv, &src->mod, ops, RSND_MOD_SRC, i); 893 rsnd_mod_init(&src->mod, ops, clk, RSND_MOD_SRC, i);
767 894
768 dev_dbg(dev, "SRC%d probed\n", i); 895 dev_dbg(dev, "SRC%d probed\n", i);
769 } 896 }
diff --git a/sound/soc/sh/rcar/ssi.c b/sound/soc/sh/rcar/ssi.c
index 3844fbef4664..9e7b627c08e2 100644
--- a/sound/soc/sh/rcar/ssi.c
+++ b/sound/soc/sh/rcar/ssi.c
@@ -60,17 +60,14 @@
60#define SSI_NAME "ssi" 60#define SSI_NAME "ssi"
61 61
62struct rsnd_ssi { 62struct rsnd_ssi {
63 struct clk *clk;
64 struct rsnd_ssi_platform_info *info; /* rcar_snd.h */ 63 struct rsnd_ssi_platform_info *info; /* rcar_snd.h */
65 struct rsnd_ssi *parent; 64 struct rsnd_ssi *parent;
66 struct rsnd_mod mod; 65 struct rsnd_mod mod;
67 66
68 struct rsnd_dai *rdai;
69 u32 cr_own; 67 u32 cr_own;
70 u32 cr_clk; 68 u32 cr_clk;
71 int err; 69 int err;
72 unsigned int usrcnt; 70 unsigned int usrcnt;
73 unsigned int rate;
74}; 71};
75 72
76#define for_each_rsnd_ssi(pos, priv, i) \ 73#define for_each_rsnd_ssi(pos, priv, i) \
@@ -128,7 +125,7 @@ static void rsnd_ssi_status_check(struct rsnd_mod *mod,
128static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi, 125static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
129 struct rsnd_dai_stream *io) 126 struct rsnd_dai_stream *io)
130{ 127{
131 struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod); 128 struct rsnd_priv *priv = rsnd_io_to_priv(io);
132 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 129 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
133 struct device *dev = rsnd_priv_to_dev(priv); 130 struct device *dev = rsnd_priv_to_dev(priv);
134 int i, j, ret; 131 int i, j, ret;
@@ -157,7 +154,6 @@ static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
157 154
158 ret = rsnd_adg_ssi_clk_try_start(&ssi->mod, main_rate); 155 ret = rsnd_adg_ssi_clk_try_start(&ssi->mod, main_rate);
159 if (0 == ret) { 156 if (0 == ret) {
160 ssi->rate = rate;
161 ssi->cr_clk = FORCE | SWL_32 | 157 ssi->cr_clk = FORCE | SWL_32 |
162 SCKD | SWSD | CKDV(j); 158 SCKD | SWSD | CKDV(j);
163 159
@@ -176,26 +172,25 @@ static int rsnd_ssi_master_clk_start(struct rsnd_ssi *ssi,
176 172
177static void rsnd_ssi_master_clk_stop(struct rsnd_ssi *ssi) 173static void rsnd_ssi_master_clk_stop(struct rsnd_ssi *ssi)
178{ 174{
179 ssi->rate = 0;
180 ssi->cr_clk = 0; 175 ssi->cr_clk = 0;
181 rsnd_adg_ssi_clk_stop(&ssi->mod); 176 rsnd_adg_ssi_clk_stop(&ssi->mod);
182} 177}
183 178
184static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi, 179static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
185 struct rsnd_dai *rdai,
186 struct rsnd_dai_stream *io) 180 struct rsnd_dai_stream *io)
187{ 181{
188 struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod); 182 struct rsnd_priv *priv = rsnd_io_to_priv(io);
183 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
189 struct device *dev = rsnd_priv_to_dev(priv); 184 struct device *dev = rsnd_priv_to_dev(priv);
190 u32 cr_mode; 185 u32 cr_mode;
191 u32 cr; 186 u32 cr;
192 187
193 if (0 == ssi->usrcnt) { 188 if (0 == ssi->usrcnt) {
194 clk_prepare_enable(ssi->clk); 189 rsnd_mod_hw_start(&ssi->mod);
195 190
196 if (rsnd_dai_is_clk_master(rdai)) { 191 if (rsnd_rdai_is_clk_master(rdai)) {
197 if (rsnd_ssi_clk_from_parent(ssi)) 192 if (rsnd_ssi_clk_from_parent(ssi))
198 rsnd_ssi_hw_start(ssi->parent, rdai, io); 193 rsnd_ssi_hw_start(ssi->parent, io);
199 else 194 else
200 rsnd_ssi_master_clk_start(ssi, io); 195 rsnd_ssi_master_clk_start(ssi, io);
201 } 196 }
@@ -214,7 +209,7 @@ static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
214 rsnd_mod_write(&ssi->mod, SSICR, cr); 209 rsnd_mod_write(&ssi->mod, SSICR, cr);
215 210
216 /* enable WS continue */ 211 /* enable WS continue */
217 if (rsnd_dai_is_clk_master(rdai)) 212 if (rsnd_rdai_is_clk_master(rdai))
218 rsnd_mod_write(&ssi->mod, SSIWSR, CONT); 213 rsnd_mod_write(&ssi->mod, SSIWSR, CONT);
219 214
220 /* clear error status */ 215 /* clear error status */
@@ -226,10 +221,11 @@ static void rsnd_ssi_hw_start(struct rsnd_ssi *ssi,
226 rsnd_mod_name(&ssi->mod), rsnd_mod_id(&ssi->mod)); 221 rsnd_mod_name(&ssi->mod), rsnd_mod_id(&ssi->mod));
227} 222}
228 223
229static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi, 224static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi)
230 struct rsnd_dai *rdai)
231{ 225{
232 struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod); 226 struct rsnd_priv *priv = rsnd_mod_to_priv(&ssi->mod);
227 struct rsnd_dai_stream *io = rsnd_mod_to_io(&ssi->mod);
228 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
233 struct device *dev = rsnd_priv_to_dev(priv); 229 struct device *dev = rsnd_priv_to_dev(priv);
234 u32 cr; 230 u32 cr;
235 231
@@ -256,14 +252,14 @@ static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi,
256 rsnd_mod_write(&ssi->mod, SSICR, cr); /* disabled all */ 252 rsnd_mod_write(&ssi->mod, SSICR, cr); /* disabled all */
257 rsnd_ssi_status_check(&ssi->mod, IIRQ); 253 rsnd_ssi_status_check(&ssi->mod, IIRQ);
258 254
259 if (rsnd_dai_is_clk_master(rdai)) { 255 if (rsnd_rdai_is_clk_master(rdai)) {
260 if (rsnd_ssi_clk_from_parent(ssi)) 256 if (rsnd_ssi_clk_from_parent(ssi))
261 rsnd_ssi_hw_stop(ssi->parent, rdai); 257 rsnd_ssi_hw_stop(ssi->parent);
262 else 258 else
263 rsnd_ssi_master_clk_stop(ssi); 259 rsnd_ssi_master_clk_stop(ssi);
264 } 260 }
265 261
266 clk_disable_unprepare(ssi->clk); 262 rsnd_mod_hw_stop(&ssi->mod);
267 } 263 }
268 264
269 dev_dbg(dev, "%s[%d] hw stopped\n", 265 dev_dbg(dev, "%s[%d] hw stopped\n",
@@ -274,10 +270,11 @@ static void rsnd_ssi_hw_stop(struct rsnd_ssi *ssi,
274 * SSI mod common functions 270 * SSI mod common functions
275 */ 271 */
276static int rsnd_ssi_init(struct rsnd_mod *mod, 272static int rsnd_ssi_init(struct rsnd_mod *mod,
277 struct rsnd_dai *rdai) 273 struct rsnd_priv *priv)
278{ 274{
279 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 275 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
280 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 276 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
277 struct rsnd_dai *rdai = rsnd_io_to_rdai(io);
281 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 278 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
282 u32 cr; 279 u32 cr;
283 280
@@ -311,13 +308,12 @@ static int rsnd_ssi_init(struct rsnd_mod *mod,
311 cr |= SDTA; 308 cr |= SDTA;
312 if (rdai->sys_delay) 309 if (rdai->sys_delay)
313 cr |= DEL; 310 cr |= DEL;
314 if (rsnd_dai_is_play(rdai, io)) 311 if (rsnd_io_is_play(io))
315 cr |= TRMD; 312 cr |= TRMD;
316 313
317 /* 314 /*
318 * set ssi parameter 315 * set ssi parameter
319 */ 316 */
320 ssi->rdai = rdai;
321 ssi->cr_own = cr; 317 ssi->cr_own = cr;
322 ssi->err = -1; /* ignore 1st error */ 318 ssi->err = -1; /* ignore 1st error */
323 319
@@ -325,16 +321,15 @@ static int rsnd_ssi_init(struct rsnd_mod *mod,
325} 321}
326 322
327static int rsnd_ssi_quit(struct rsnd_mod *mod, 323static int rsnd_ssi_quit(struct rsnd_mod *mod,
328 struct rsnd_dai *rdai) 324 struct rsnd_priv *priv)
329{ 325{
330 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 326 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
331 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
332 struct device *dev = rsnd_priv_to_dev(priv); 327 struct device *dev = rsnd_priv_to_dev(priv);
333 328
334 if (ssi->err > 0) 329 if (ssi->err > 0)
335 dev_warn(dev, "ssi under/over flow err = %d\n", ssi->err); 330 dev_warn(dev, "%s[%d] under/over flow err = %d\n",
331 rsnd_mod_name(mod), rsnd_mod_id(mod), ssi->err);
336 332
337 ssi->rdai = NULL;
338 ssi->cr_own = 0; 333 ssi->cr_own = 0;
339 ssi->err = 0; 334 ssi->err = 0;
340 335
@@ -353,32 +348,32 @@ static void rsnd_ssi_record_error(struct rsnd_ssi *ssi, u32 status)
353} 348}
354 349
355static int rsnd_ssi_start(struct rsnd_mod *mod, 350static int rsnd_ssi_start(struct rsnd_mod *mod,
356 struct rsnd_dai *rdai) 351 struct rsnd_priv *priv)
357{ 352{
358 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 353 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
359 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 354 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
360 355
361 rsnd_src_ssiu_start(mod, rdai, rsnd_ssi_use_busif(mod)); 356 rsnd_src_ssiu_start(mod, rsnd_ssi_use_busif(mod));
362 357
363 rsnd_ssi_hw_start(ssi, rdai, io); 358 rsnd_ssi_hw_start(ssi, io);
364 359
365 rsnd_src_ssi_irq_enable(mod, rdai); 360 rsnd_src_ssi_irq_enable(mod);
366 361
367 return 0; 362 return 0;
368} 363}
369 364
370static int rsnd_ssi_stop(struct rsnd_mod *mod, 365static int rsnd_ssi_stop(struct rsnd_mod *mod,
371 struct rsnd_dai *rdai) 366 struct rsnd_priv *priv)
372{ 367{
373 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 368 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
374 369
375 rsnd_src_ssi_irq_disable(mod, rdai); 370 rsnd_src_ssi_irq_disable(mod);
376 371
377 rsnd_ssi_record_error(ssi, rsnd_mod_read(mod, SSISR)); 372 rsnd_ssi_record_error(ssi, rsnd_mod_read(mod, SSISR));
378 373
379 rsnd_ssi_hw_stop(ssi, rdai); 374 rsnd_ssi_hw_stop(ssi);
380 375
381 rsnd_src_ssiu_stop(mod, rdai); 376 rsnd_src_ssiu_stop(mod);
382 377
383 return 0; 378 return 0;
384} 379}
@@ -386,16 +381,17 @@ static int rsnd_ssi_stop(struct rsnd_mod *mod,
386static irqreturn_t rsnd_ssi_interrupt(int irq, void *data) 381static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
387{ 382{
388 struct rsnd_ssi *ssi = data; 383 struct rsnd_ssi *ssi = data;
389 struct rsnd_dai *rdai = ssi->rdai;
390 struct rsnd_mod *mod = &ssi->mod; 384 struct rsnd_mod *mod = &ssi->mod;
385 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
391 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod); 386 struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
387 int is_dma = rsnd_ssi_is_dma_mode(mod);
392 u32 status = rsnd_mod_read(mod, SSISR); 388 u32 status = rsnd_mod_read(mod, SSISR);
393 389
394 if (!io) 390 if (!io)
395 return IRQ_NONE; 391 return IRQ_NONE;
396 392
397 /* PIO only */ 393 /* PIO only */
398 if (status & DIRQ) { 394 if (!is_dma && (status & DIRQ)) {
399 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io); 395 struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
400 u32 *buf = (u32 *)(runtime->dma_area + 396 u32 *buf = (u32 *)(runtime->dma_area +
401 rsnd_dai_pointer_offset(io, 0)); 397 rsnd_dai_pointer_offset(io, 0));
@@ -405,7 +401,7 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
405 * directly as 32bit data 401 * directly as 32bit data
406 * see rsnd_ssi_init() 402 * see rsnd_ssi_init()
407 */ 403 */
408 if (rsnd_dai_is_play(rdai, io)) 404 if (rsnd_io_is_play(io))
409 rsnd_mod_write(mod, SSITDR, *buf); 405 rsnd_mod_write(mod, SSITDR, *buf);
410 else 406 else
411 *buf = rsnd_mod_read(mod, SSIRDR); 407 *buf = rsnd_mod_read(mod, SSIRDR);
@@ -415,14 +411,13 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
415 411
416 /* PIO / DMA */ 412 /* PIO / DMA */
417 if (status & (UIRQ | OIRQ)) { 413 if (status & (UIRQ | OIRQ)) {
418 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
419 struct device *dev = rsnd_priv_to_dev(priv); 414 struct device *dev = rsnd_priv_to_dev(priv);
420 415
421 /* 416 /*
422 * restart SSI 417 * restart SSI
423 */ 418 */
424 rsnd_ssi_stop(mod, rdai); 419 rsnd_ssi_stop(mod, priv);
425 rsnd_ssi_start(mod, rdai); 420 rsnd_ssi_start(mod, priv);
426 421
427 dev_dbg(dev, "%s[%d] restart\n", 422 dev_dbg(dev, "%s[%d] restart\n",
428 rsnd_mod_name(mod), rsnd_mod_id(mod)); 423 rsnd_mod_name(mod), rsnd_mod_id(mod));
@@ -437,9 +432,8 @@ static irqreturn_t rsnd_ssi_interrupt(int irq, void *data)
437 * SSI PIO 432 * SSI PIO
438 */ 433 */
439static int rsnd_ssi_pio_probe(struct rsnd_mod *mod, 434static int rsnd_ssi_pio_probe(struct rsnd_mod *mod,
440 struct rsnd_dai *rdai) 435 struct rsnd_priv *priv)
441{ 436{
442 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
443 struct device *dev = rsnd_priv_to_dev(priv); 437 struct device *dev = rsnd_priv_to_dev(priv);
444 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 438 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
445 int ret; 439 int ret;
@@ -468,9 +462,8 @@ static struct rsnd_mod_ops rsnd_ssi_pio_ops = {
468}; 462};
469 463
470static int rsnd_ssi_dma_probe(struct rsnd_mod *mod, 464static int rsnd_ssi_dma_probe(struct rsnd_mod *mod,
471 struct rsnd_dai *rdai) 465 struct rsnd_priv *priv)
472{ 466{
473 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
474 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 467 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
475 struct device *dev = rsnd_priv_to_dev(priv); 468 struct device *dev = rsnd_priv_to_dev(priv);
476 int dma_id = ssi->info->dma_id; 469 int dma_id = ssi->info->dma_id;
@@ -503,14 +496,13 @@ rsnd_ssi_dma_probe_fail:
503} 496}
504 497
505static int rsnd_ssi_dma_remove(struct rsnd_mod *mod, 498static int rsnd_ssi_dma_remove(struct rsnd_mod *mod,
506 struct rsnd_dai *rdai) 499 struct rsnd_priv *priv)
507{ 500{
508 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
509 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod); 501 struct rsnd_ssi *ssi = rsnd_mod_to_ssi(mod);
510 struct device *dev = rsnd_priv_to_dev(priv); 502 struct device *dev = rsnd_priv_to_dev(priv);
511 int irq = ssi->info->irq; 503 int irq = ssi->info->irq;
512 504
513 rsnd_dma_quit(rsnd_mod_to_priv(mod), rsnd_mod_to_dma(mod)); 505 rsnd_dma_quit(priv, rsnd_mod_to_dma(mod));
514 506
515 /* PIO will request IRQ again */ 507 /* PIO will request IRQ again */
516 devm_free_irq(dev, irq, ssi); 508 devm_free_irq(dev, irq, ssi);
@@ -519,9 +511,8 @@ static int rsnd_ssi_dma_remove(struct rsnd_mod *mod,
519} 511}
520 512
521static int rsnd_ssi_fallback(struct rsnd_mod *mod, 513static int rsnd_ssi_fallback(struct rsnd_mod *mod,
522 struct rsnd_dai *rdai) 514 struct rsnd_priv *priv)
523{ 515{
524 struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
525 struct device *dev = rsnd_priv_to_dev(priv); 516 struct device *dev = rsnd_priv_to_dev(priv);
526 517
527 /* 518 /*
@@ -540,25 +531,25 @@ static int rsnd_ssi_fallback(struct rsnd_mod *mod,
540} 531}
541 532
542static int rsnd_ssi_dma_start(struct rsnd_mod *mod, 533static int rsnd_ssi_dma_start(struct rsnd_mod *mod,
543 struct rsnd_dai *rdai) 534 struct rsnd_priv *priv)
544{ 535{
545 struct rsnd_dma *dma = rsnd_mod_to_dma(mod); 536 struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
546 537
547 rsnd_ssi_start(mod, rdai);
548
549 rsnd_dma_start(dma); 538 rsnd_dma_start(dma);
550 539
540 rsnd_ssi_start(mod, priv);
541
551 return 0; 542 return 0;
552} 543}
553 544
554static int rsnd_ssi_dma_stop(struct rsnd_mod *mod, 545static int rsnd_ssi_dma_stop(struct rsnd_mod *mod,
555 struct rsnd_dai *rdai) 546 struct rsnd_priv *priv)
556{ 547{
557 struct rsnd_dma *dma = rsnd_mod_to_dma(mod); 548 struct rsnd_dma *dma = rsnd_mod_to_dma(mod);
558 549
559 rsnd_dma_stop(dma); 550 rsnd_ssi_stop(mod, priv);
560 551
561 rsnd_ssi_stop(mod, rdai); 552 rsnd_dma_stop(dma);
562 553
563 return 0; 554 return 0;
564} 555}
@@ -734,7 +725,6 @@ int rsnd_ssi_probe(struct platform_device *pdev,
734 return PTR_ERR(clk); 725 return PTR_ERR(clk);
735 726
736 ssi->info = pinfo; 727 ssi->info = pinfo;
737 ssi->clk = clk;
738 728
739 ops = &rsnd_ssi_non_ops; 729 ops = &rsnd_ssi_non_ops;
740 if (pinfo->dma_id > 0) 730 if (pinfo->dma_id > 0)
@@ -742,7 +732,7 @@ int rsnd_ssi_probe(struct platform_device *pdev,
742 else if (rsnd_ssi_pio_available(ssi)) 732 else if (rsnd_ssi_pio_available(ssi))
743 ops = &rsnd_ssi_pio_ops; 733 ops = &rsnd_ssi_pio_ops;
744 734
745 rsnd_mod_init(priv, &ssi->mod, ops, RSND_MOD_SSI, i); 735 rsnd_mod_init(&ssi->mod, ops, clk, RSND_MOD_SSI, i);
746 736
747 rsnd_ssi_parent_clk_setup(priv, ssi); 737 rsnd_ssi_parent_clk_setup(priv, ssi);
748 } 738 }
diff --git a/sound/soc/sh/siu_pcm.c b/sound/soc/sh/siu_pcm.c
index 32eb6da2d2bd..82902f56e82f 100644
--- a/sound/soc/sh/siu_pcm.c
+++ b/sound/soc/sh/siu_pcm.c
@@ -589,7 +589,6 @@ static void siu_pcm_free(struct snd_pcm *pcm)
589 tasklet_kill(&port_info->playback.tasklet); 589 tasklet_kill(&port_info->playback.tasklet);
590 590
591 siu_free_port(port_info); 591 siu_free_port(port_info);
592 snd_pcm_lib_preallocate_free_for_all(pcm);
593 592
594 dev_dbg(pcm->card->dev, "%s\n", __func__); 593 dev_dbg(pcm->card->dev, "%s\n", __func__);
595} 594}
diff --git a/sound/soc/soc-ac97.c b/sound/soc/soc-ac97.c
index 2e10e9a38376..08d7259bbaab 100644
--- a/sound/soc/soc-ac97.c
+++ b/sound/soc/soc-ac97.c
@@ -48,15 +48,18 @@ static void soc_ac97_device_release(struct device *dev)
48} 48}
49 49
50/** 50/**
51 * snd_soc_new_ac97_codec - initailise AC97 device 51 * snd_soc_alloc_ac97_codec() - Allocate new a AC'97 device
52 * @codec: audio codec 52 * @codec: The CODEC for which to create the AC'97 device
53 * 53 *
54 * Initialises AC97 codec resources for use by ad-hoc devices only. 54 * Allocated a new snd_ac97 device and intializes it, but does not yet register
55 * it. The caller is responsible to either call device_add(&ac97->dev) to
56 * register the device, or to call put_device(&ac97->dev) to free the device.
57 *
58 * Returns: A snd_ac97 device or a PTR_ERR in case of an error.
55 */ 59 */
56struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec) 60struct snd_ac97 *snd_soc_alloc_ac97_codec(struct snd_soc_codec *codec)
57{ 61{
58 struct snd_ac97 *ac97; 62 struct snd_ac97 *ac97;
59 int ret;
60 63
61 ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL); 64 ac97 = kzalloc(sizeof(struct snd_ac97), GFP_KERNEL);
62 if (ac97 == NULL) 65 if (ac97 == NULL)
@@ -73,7 +76,28 @@ struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec)
73 codec->component.card->snd_card->number, 0, 76 codec->component.card->snd_card->number, 0,
74 codec->component.name); 77 codec->component.name);
75 78
76 ret = device_register(&ac97->dev); 79 device_initialize(&ac97->dev);
80
81 return ac97;
82}
83EXPORT_SYMBOL(snd_soc_alloc_ac97_codec);
84
85/**
86 * snd_soc_new_ac97_codec - initailise AC97 device
87 * @codec: audio codec
88 *
89 * Initialises AC97 codec resources for use by ad-hoc devices only.
90 */
91struct snd_ac97 *snd_soc_new_ac97_codec(struct snd_soc_codec *codec)
92{
93 struct snd_ac97 *ac97;
94 int ret;
95
96 ac97 = snd_soc_alloc_ac97_codec(codec);
97 if (IS_ERR(ac97))
98 return ac97;
99
100 ret = device_add(&ac97->dev);
77 if (ret) { 101 if (ret) {
78 put_device(&ac97->dev); 102 put_device(&ac97->dev);
79 return ERR_PTR(ret); 103 return ERR_PTR(ret);
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index c024962ba500..d94434d6138e 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -191,6 +191,39 @@ static ssize_t pmdown_time_set(struct device *dev,
191 191
192static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set); 192static DEVICE_ATTR(pmdown_time, 0644, pmdown_time_show, pmdown_time_set);
193 193
194static struct attribute *soc_dev_attrs[] = {
195 &dev_attr_codec_reg.attr,
196 &dev_attr_pmdown_time.attr,
197 NULL
198};
199
200static umode_t soc_dev_attr_is_visible(struct kobject *kobj,
201 struct attribute *attr, int idx)
202{
203 struct device *dev = kobj_to_dev(kobj);
204 struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
205
206 if (attr == &dev_attr_pmdown_time.attr)
207 return attr->mode; /* always visible */
208 return rtd->codec ? attr->mode : 0; /* enabled only with codec */
209}
210
211static const struct attribute_group soc_dapm_dev_group = {
212 .attrs = soc_dapm_dev_attrs,
213 .is_visible = soc_dev_attr_is_visible,
214};
215
216static const struct attribute_group soc_dev_roup = {
217 .attrs = soc_dev_attrs,
218 .is_visible = soc_dev_attr_is_visible,
219};
220
221static const struct attribute_group *soc_dev_attr_groups[] = {
222 &soc_dapm_dev_group,
223 &soc_dev_roup,
224 NULL
225};
226
194#ifdef CONFIG_DEBUG_FS 227#ifdef CONFIG_DEBUG_FS
195static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf, 228static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
196 size_t count, loff_t *ppos) 229 size_t count, loff_t *ppos)
@@ -949,8 +982,6 @@ static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order)
949 982
950 /* unregister the rtd device */ 983 /* unregister the rtd device */
951 if (rtd->dev_registered) { 984 if (rtd->dev_registered) {
952 device_remove_file(rtd->dev, &dev_attr_pmdown_time);
953 device_remove_file(rtd->dev, &dev_attr_codec_reg);
954 device_unregister(rtd->dev); 985 device_unregister(rtd->dev);
955 rtd->dev_registered = 0; 986 rtd->dev_registered = 0;
956 } 987 }
@@ -1120,6 +1151,7 @@ static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd,
1120 device_initialize(rtd->dev); 1151 device_initialize(rtd->dev);
1121 rtd->dev->parent = rtd->card->dev; 1152 rtd->dev->parent = rtd->card->dev;
1122 rtd->dev->release = rtd_release; 1153 rtd->dev->release = rtd_release;
1154 rtd->dev->groups = soc_dev_attr_groups;
1123 dev_set_name(rtd->dev, "%s", name); 1155 dev_set_name(rtd->dev, "%s", name);
1124 dev_set_drvdata(rtd->dev, rtd); 1156 dev_set_drvdata(rtd->dev, rtd);
1125 mutex_init(&rtd->pcm_mutex); 1157 mutex_init(&rtd->pcm_mutex);
@@ -1136,23 +1168,6 @@ static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd,
1136 return ret; 1168 return ret;
1137 } 1169 }
1138 rtd->dev_registered = 1; 1170 rtd->dev_registered = 1;
1139
1140 if (rtd->codec) {
1141 /* add DAPM sysfs entries for this codec */
1142 ret = snd_soc_dapm_sys_add(rtd->dev);
1143 if (ret < 0)
1144 dev_err(rtd->dev,
1145 "ASoC: failed to add codec dapm sysfs entries: %d\n",
1146 ret);
1147
1148 /* add codec sysfs entries */
1149 ret = device_create_file(rtd->dev, &dev_attr_codec_reg);
1150 if (ret < 0)
1151 dev_err(rtd->dev,
1152 "ASoC: failed to add codec sysfs files: %d\n",
1153 ret);
1154 }
1155
1156 return 0; 1171 return 0;
1157} 1172}
1158 1173
@@ -1308,11 +1323,6 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
1308 } 1323 }
1309#endif 1324#endif
1310 1325
1311 ret = device_create_file(rtd->dev, &dev_attr_pmdown_time);
1312 if (ret < 0)
1313 dev_warn(rtd->dev, "ASoC: failed to add pmdown_time sysfs: %d\n",
1314 ret);
1315
1316 if (cpu_dai->driver->compress_dai) { 1326 if (cpu_dai->driver->compress_dai) {
1317 /*create compress_device"*/ 1327 /*create compress_device"*/
1318 ret = soc_new_compress(rtd, num); 1328 ret = soc_new_compress(rtd, num);
@@ -1427,11 +1437,76 @@ static int snd_soc_init_codec_cache(struct snd_soc_codec *codec)
1427 return 0; 1437 return 0;
1428} 1438}
1429 1439
1440/**
1441 * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime
1442 * @rtd: The runtime for which the DAI link format should be changed
1443 * @dai_fmt: The new DAI link format
1444 *
1445 * This function updates the DAI link format for all DAIs connected to the DAI
1446 * link for the specified runtime.
1447 *
1448 * Note: For setups with a static format set the dai_fmt field in the
1449 * corresponding snd_dai_link struct instead of using this function.
1450 *
1451 * Returns 0 on success, otherwise a negative error code.
1452 */
1453int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
1454 unsigned int dai_fmt)
1455{
1456 struct snd_soc_dai **codec_dais = rtd->codec_dais;
1457 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1458 unsigned int i;
1459 int ret;
1460
1461 for (i = 0; i < rtd->num_codecs; i++) {
1462 struct snd_soc_dai *codec_dai = codec_dais[i];
1463
1464 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
1465 if (ret != 0 && ret != -ENOTSUPP) {
1466 dev_warn(codec_dai->dev,
1467 "ASoC: Failed to set DAI format: %d\n", ret);
1468 return ret;
1469 }
1470 }
1471
1472 /* Flip the polarity for the "CPU" end of a CODEC<->CODEC link */
1473 if (cpu_dai->codec) {
1474 unsigned int inv_dai_fmt;
1475
1476 inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK;
1477 switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1478 case SND_SOC_DAIFMT_CBM_CFM:
1479 inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
1480 break;
1481 case SND_SOC_DAIFMT_CBM_CFS:
1482 inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
1483 break;
1484 case SND_SOC_DAIFMT_CBS_CFM:
1485 inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
1486 break;
1487 case SND_SOC_DAIFMT_CBS_CFS:
1488 inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
1489 break;
1490 }
1491
1492 dai_fmt = inv_dai_fmt;
1493 }
1494
1495 ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
1496 if (ret != 0 && ret != -ENOTSUPP) {
1497 dev_warn(cpu_dai->dev,
1498 "ASoC: Failed to set DAI format: %d\n", ret);
1499 return ret;
1500 }
1501
1502 return 0;
1503}
1504EXPORT_SYMBOL_GPL(snd_soc_runtime_set_dai_fmt);
1505
1430static int snd_soc_instantiate_card(struct snd_soc_card *card) 1506static int snd_soc_instantiate_card(struct snd_soc_card *card)
1431{ 1507{
1432 struct snd_soc_codec *codec; 1508 struct snd_soc_codec *codec;
1433 struct snd_soc_dai_link *dai_link; 1509 int ret, i, order;
1434 int ret, i, order, dai_fmt;
1435 1510
1436 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT); 1511 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
1437 1512
@@ -1542,60 +1617,9 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
1542 card->num_dapm_routes); 1617 card->num_dapm_routes);
1543 1618
1544 for (i = 0; i < card->num_links; i++) { 1619 for (i = 0; i < card->num_links; i++) {
1545 struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; 1620 if (card->dai_link[i].dai_fmt)
1546 dai_link = &card->dai_link[i]; 1621 snd_soc_runtime_set_dai_fmt(&card->rtd[i],
1547 dai_fmt = dai_link->dai_fmt; 1622 card->dai_link[i].dai_fmt);
1548
1549 if (dai_fmt) {
1550 struct snd_soc_dai **codec_dais = rtd->codec_dais;
1551 int j;
1552
1553 for (j = 0; j < rtd->num_codecs; j++) {
1554 struct snd_soc_dai *codec_dai = codec_dais[j];
1555
1556 ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
1557 if (ret != 0 && ret != -ENOTSUPP)
1558 dev_warn(codec_dai->dev,
1559 "ASoC: Failed to set DAI format: %d\n",
1560 ret);
1561 }
1562 }
1563
1564 /* If this is a regular CPU link there will be a platform */
1565 if (dai_fmt &&
1566 (dai_link->platform_name || dai_link->platform_of_node)) {
1567 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1568 dai_fmt);
1569 if (ret != 0 && ret != -ENOTSUPP)
1570 dev_warn(card->rtd[i].cpu_dai->dev,
1571 "ASoC: Failed to set DAI format: %d\n",
1572 ret);
1573 } else if (dai_fmt) {
1574 /* Flip the polarity for the "CPU" end */
1575 dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
1576 switch (dai_link->dai_fmt &
1577 SND_SOC_DAIFMT_MASTER_MASK) {
1578 case SND_SOC_DAIFMT_CBM_CFM:
1579 dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
1580 break;
1581 case SND_SOC_DAIFMT_CBM_CFS:
1582 dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
1583 break;
1584 case SND_SOC_DAIFMT_CBS_CFM:
1585 dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
1586 break;
1587 case SND_SOC_DAIFMT_CBS_CFS:
1588 dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
1589 break;
1590 }
1591
1592 ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
1593 dai_fmt);
1594 if (ret != 0 && ret != -ENOTSUPP)
1595 dev_warn(card->rtd[i].cpu_dai->dev,
1596 "ASoC: Failed to set DAI format: %d\n",
1597 ret);
1598 }
1599 } 1623 }
1600 1624
1601 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname), 1625 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
@@ -2116,15 +2140,27 @@ static int snd_soc_xlate_tdm_slot_mask(unsigned int slots,
2116} 2140}
2117 2141
2118/** 2142/**
2119 * snd_soc_dai_set_tdm_slot - configure DAI TDM. 2143 * snd_soc_dai_set_tdm_slot() - Configures a DAI for TDM operation
2120 * @dai: DAI 2144 * @dai: The DAI to configure
2121 * @tx_mask: bitmask representing active TX slots. 2145 * @tx_mask: bitmask representing active TX slots.
2122 * @rx_mask: bitmask representing active RX slots. 2146 * @rx_mask: bitmask representing active RX slots.
2123 * @slots: Number of slots in use. 2147 * @slots: Number of slots in use.
2124 * @slot_width: Width in bits for each slot. 2148 * @slot_width: Width in bits for each slot.
2125 * 2149 *
2126 * Configures a DAI for TDM operation. Both mask and slots are codec and DAI 2150 * This function configures the specified DAI for TDM operation. @slot contains
2127 * specific. 2151 * the total number of slots of the TDM stream and @slot_with the width of each
2152 * slot in bit clock cycles. @tx_mask and @rx_mask are bitmasks specifying the
2153 * active slots of the TDM stream for the specified DAI, i.e. which slots the
2154 * DAI should write to or read from. If a bit is set the corresponding slot is
2155 * active, if a bit is cleared the corresponding slot is inactive. Bit 0 maps to
2156 * the first slot, bit 1 to the second slot and so on. The first active slot
2157 * maps to the first channel of the DAI, the second active slot to the second
2158 * channel and so on.
2159 *
2160 * TDM mode can be disabled by passing 0 for @slots. In this case @tx_mask,
2161 * @rx_mask and @slot_width will be ignored.
2162 *
2163 * Returns 0 on success, a negative error code otherwise.
2128 */ 2164 */
2129int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, 2165int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2130 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) 2166 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index ea496842ee83..b6f88202b8c9 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -517,8 +517,8 @@ static int soc_dapm_update_bits(struct snd_soc_dapm_context *dapm,
517{ 517{
518 if (!dapm->component) 518 if (!dapm->component)
519 return -EIO; 519 return -EIO;
520 return snd_soc_component_update_bits_async(dapm->component, reg, 520 return snd_soc_component_update_bits(dapm->component, reg,
521 mask, value); 521 mask, value);
522} 522}
523 523
524static int soc_dapm_test_bits(struct snd_soc_dapm_context *dapm, 524static int soc_dapm_test_bits(struct snd_soc_dapm_context *dapm,
@@ -2127,15 +2127,10 @@ static ssize_t dapm_widget_show(struct device *dev,
2127 2127
2128static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL); 2128static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
2129 2129
2130int snd_soc_dapm_sys_add(struct device *dev) 2130struct attribute *soc_dapm_dev_attrs[] = {
2131{ 2131 &dev_attr_dapm_widget.attr,
2132 return device_create_file(dev, &dev_attr_dapm_widget); 2132 NULL
2133} 2133};
2134
2135static void snd_soc_dapm_sys_remove(struct device *dev)
2136{
2137 device_remove_file(dev, &dev_attr_dapm_widget);
2138}
2139 2134
2140static void dapm_free_path(struct snd_soc_dapm_path *path) 2135static void dapm_free_path(struct snd_soc_dapm_path *path)
2141{ 2136{
@@ -3144,8 +3139,6 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
3144 } 3139 }
3145 3140
3146 w->dapm = dapm; 3141 w->dapm = dapm;
3147 if (dapm->component)
3148 w->codec = dapm->component->codec;
3149 INIT_LIST_HEAD(&w->sources); 3142 INIT_LIST_HEAD(&w->sources);
3150 INIT_LIST_HEAD(&w->sinks); 3143 INIT_LIST_HEAD(&w->sinks);
3151 INIT_LIST_HEAD(&w->list); 3144 INIT_LIST_HEAD(&w->list);
@@ -3830,7 +3823,6 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
3830 */ 3823 */
3831void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm) 3824void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
3832{ 3825{
3833 snd_soc_dapm_sys_remove(dapm->dev);
3834 dapm_debugfs_cleanup(dapm); 3826 dapm_debugfs_cleanup(dapm);
3835 dapm_free_widgets(dapm); 3827 dapm_free_widgets(dapm);
3836 list_del(&dapm->list); 3828 list_del(&dapm->list);
diff --git a/sound/soc/soc-devres.c b/sound/soc/soc-devres.c
index 057e5ef7dcce..a57921eeee81 100644
--- a/sound/soc/soc-devres.c
+++ b/sound/soc/soc-devres.c
@@ -60,7 +60,7 @@ static void devm_platform_release(struct device *dev, void *res)
60/** 60/**
61 * devm_snd_soc_register_platform - resource managed platform registration 61 * devm_snd_soc_register_platform - resource managed platform registration
62 * @dev: Device used to manage platform 62 * @dev: Device used to manage platform
63 * @platform: platform to register 63 * @platform_drv: platform to register
64 * 64 *
65 * Register a platform driver with automatic unregistration when the device is 65 * Register a platform driver with automatic unregistration when the device is
66 * unregistered. 66 * unregistered.
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
index b329b84bc5af..4864392bfcba 100644
--- a/sound/soc/soc-generic-dmaengine-pcm.c
+++ b/sound/soc/soc-generic-dmaengine-pcm.c
@@ -200,11 +200,6 @@ static int dmaengine_pcm_open(struct snd_pcm_substream *substream)
200 return snd_dmaengine_pcm_open(substream, chan); 200 return snd_dmaengine_pcm_open(substream, chan);
201} 201}
202 202
203static void dmaengine_pcm_free(struct snd_pcm *pcm)
204{
205 snd_pcm_lib_preallocate_free_for_all(pcm);
206}
207
208static struct dma_chan *dmaengine_pcm_compat_request_channel( 203static struct dma_chan *dmaengine_pcm_compat_request_channel(
209 struct snd_soc_pcm_runtime *rtd, 204 struct snd_soc_pcm_runtime *rtd,
210 struct snd_pcm_substream *substream) 205 struct snd_pcm_substream *substream)
@@ -283,8 +278,7 @@ static int dmaengine_pcm_new(struct snd_soc_pcm_runtime *rtd)
283 if (!pcm->chan[i]) { 278 if (!pcm->chan[i]) {
284 dev_err(rtd->platform->dev, 279 dev_err(rtd->platform->dev,
285 "Missing dma channel for stream: %d\n", i); 280 "Missing dma channel for stream: %d\n", i);
286 ret = -EINVAL; 281 return -EINVAL;
287 goto err_free;
288 } 282 }
289 283
290 ret = snd_pcm_lib_preallocate_pages(substream, 284 ret = snd_pcm_lib_preallocate_pages(substream,
@@ -293,7 +287,7 @@ static int dmaengine_pcm_new(struct snd_soc_pcm_runtime *rtd)
293 prealloc_buffer_size, 287 prealloc_buffer_size,
294 max_buffer_size); 288 max_buffer_size);
295 if (ret) 289 if (ret)
296 goto err_free; 290 return ret;
297 291
298 /* 292 /*
299 * This will only return false if we know for sure that at least 293 * This will only return false if we know for sure that at least
@@ -307,10 +301,6 @@ static int dmaengine_pcm_new(struct snd_soc_pcm_runtime *rtd)
307 } 301 }
308 302
309 return 0; 303 return 0;
310
311err_free:
312 dmaengine_pcm_free(rtd->pcm);
313 return ret;
314} 304}
315 305
316static snd_pcm_uframes_t dmaengine_pcm_pointer( 306static snd_pcm_uframes_t dmaengine_pcm_pointer(
@@ -341,7 +331,6 @@ static const struct snd_soc_platform_driver dmaengine_pcm_platform = {
341 }, 331 },
342 .ops = &dmaengine_pcm_ops, 332 .ops = &dmaengine_pcm_ops,
343 .pcm_new = dmaengine_pcm_new, 333 .pcm_new = dmaengine_pcm_new,
344 .pcm_free = dmaengine_pcm_free,
345}; 334};
346 335
347static const char * const dmaengine_pcm_dma_channel_names[] = { 336static const char * const dmaengine_pcm_dma_channel_names[] = {
diff --git a/sound/soc/tegra/Kconfig b/sound/soc/tegra/Kconfig
index 31198cf7f88d..a6768f832c6f 100644
--- a/sound/soc/tegra/Kconfig
+++ b/sound/soc/tegra/Kconfig
@@ -128,3 +128,13 @@ config SND_SOC_TEGRA_MAX98090
128 help 128 help
129 Say Y or M here if you want to add support for SoC audio on Tegra 129 Say Y or M here if you want to add support for SoC audio on Tegra
130 boards using the MAX98090 codec, such as Venice2. 130 boards using the MAX98090 codec, such as Venice2.
131
132config SND_SOC_TEGRA_RT5677
133 tristate "SoC Audio support for Tegra boards using a RT5677 codec"
134 depends on SND_SOC_TEGRA && I2C && GPIOLIB
135 select SND_SOC_TEGRA20_I2S if ARCH_TEGRA_2x_SOC
136 select SND_SOC_TEGRA30_I2S if ARCH_TEGRA_3x_SOC
137 select SND_SOC_RT5677
138 help
139 Say Y or M here if you want to add support for SoC audio on Tegra
140 boards using the RT5677 codec, such as Ryu.
diff --git a/sound/soc/tegra/Makefile b/sound/soc/tegra/Makefile
index 5ae588cd96c4..9171655ad843 100644
--- a/sound/soc/tegra/Makefile
+++ b/sound/soc/tegra/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_SND_SOC_TEGRA30_I2S) += snd-soc-tegra30-i2s.o
19 19
20# Tegra machine Support 20# Tegra machine Support
21snd-soc-tegra-rt5640-objs := tegra_rt5640.o 21snd-soc-tegra-rt5640-objs := tegra_rt5640.o
22snd-soc-tegra-rt5677-objs := tegra_rt5677.o
22snd-soc-tegra-wm8753-objs := tegra_wm8753.o 23snd-soc-tegra-wm8753-objs := tegra_wm8753.o
23snd-soc-tegra-wm8903-objs := tegra_wm8903.o 24snd-soc-tegra-wm8903-objs := tegra_wm8903.o
24snd-soc-tegra-wm9712-objs := tegra_wm9712.o 25snd-soc-tegra-wm9712-objs := tegra_wm9712.o
@@ -27,6 +28,7 @@ snd-soc-tegra-alc5632-objs := tegra_alc5632.o
27snd-soc-tegra-max98090-objs := tegra_max98090.o 28snd-soc-tegra-max98090-objs := tegra_max98090.o
28 29
29obj-$(CONFIG_SND_SOC_TEGRA_RT5640) += snd-soc-tegra-rt5640.o 30obj-$(CONFIG_SND_SOC_TEGRA_RT5640) += snd-soc-tegra-rt5640.o
31obj-$(CONFIG_SND_SOC_TEGRA_RT5677) += snd-soc-tegra-rt5677.o
30obj-$(CONFIG_SND_SOC_TEGRA_WM8753) += snd-soc-tegra-wm8753.o 32obj-$(CONFIG_SND_SOC_TEGRA_WM8753) += snd-soc-tegra-wm8753.o
31obj-$(CONFIG_SND_SOC_TEGRA_WM8903) += snd-soc-tegra-wm8903.o 33obj-$(CONFIG_SND_SOC_TEGRA_WM8903) += snd-soc-tegra-wm8903.o
32obj-$(CONFIG_SND_SOC_TEGRA_WM9712) += snd-soc-tegra-wm9712.o 34obj-$(CONFIG_SND_SOC_TEGRA_WM9712) += snd-soc-tegra-wm9712.o
diff --git a/sound/soc/tegra/tegra_rt5677.c b/sound/soc/tegra/tegra_rt5677.c
new file mode 100644
index 000000000000..e4cf978a6e3a
--- /dev/null
+++ b/sound/soc/tegra/tegra_rt5677.c
@@ -0,0 +1,347 @@
1/*
2* tegra_rt5677.c - Tegra machine ASoC driver for boards using RT5677 codec.
3 *
4 * Copyright (c) 2014, The Chromium OS Authors. 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 * Based on code copyright/by:
19 *
20 * Copyright (C) 2010-2012 - NVIDIA, Inc.
21 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net>
22 * (c) 2009, 2010 Nvidia Graphics Pvt. Ltd.
23 * Copyright 2007 Wolfson Microelectronics PLC.
24 */
25
26#include <linux/module.h>
27#include <linux/platform_device.h>
28#include <linux/slab.h>
29#include <linux/gpio.h>
30#include <linux/of_gpio.h>
31
32#include <sound/core.h>
33#include <sound/jack.h>
34#include <sound/pcm.h>
35#include <sound/pcm_params.h>
36#include <sound/soc.h>
37
38#include "../codecs/rt5677.h"
39
40#include "tegra_asoc_utils.h"
41
42#define DRV_NAME "tegra-snd-rt5677"
43
44struct tegra_rt5677 {
45 struct tegra_asoc_utils_data util_data;
46 int gpio_hp_det;
47 int gpio_hp_en;
48 int gpio_mic_present;
49 int gpio_dmic_clk_en;
50};
51
52static int tegra_rt5677_asoc_hw_params(struct snd_pcm_substream *substream,
53 struct snd_pcm_hw_params *params)
54{
55 struct snd_soc_pcm_runtime *rtd = substream->private_data;
56 struct snd_soc_dai *codec_dai = rtd->codec_dai;
57 struct snd_soc_card *card = rtd->card;
58 struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
59 int srate, mclk, err;
60
61 srate = params_rate(params);
62 mclk = 256 * srate;
63
64 err = tegra_asoc_utils_set_rate(&machine->util_data, srate, mclk);
65 if (err < 0) {
66 dev_err(card->dev, "Can't configure clocks\n");
67 return err;
68 }
69
70 err = snd_soc_dai_set_sysclk(codec_dai, RT5677_SCLK_S_MCLK, mclk,
71 SND_SOC_CLOCK_IN);
72 if (err < 0) {
73 dev_err(card->dev, "codec_dai clock not set\n");
74 return err;
75 }
76
77 return 0;
78}
79
80static int tegra_rt5677_event_hp(struct snd_soc_dapm_widget *w,
81 struct snd_kcontrol *k, int event)
82{
83 struct snd_soc_dapm_context *dapm = w->dapm;
84 struct snd_soc_card *card = dapm->card;
85 struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
86
87 if (!gpio_is_valid(machine->gpio_hp_en))
88 return 0;
89
90 gpio_set_value_cansleep(machine->gpio_hp_en,
91 SND_SOC_DAPM_EVENT_ON(event));
92
93 return 0;
94}
95
96static struct snd_soc_ops tegra_rt5677_ops = {
97 .hw_params = tegra_rt5677_asoc_hw_params,
98};
99
100static struct snd_soc_jack tegra_rt5677_hp_jack;
101
102static struct snd_soc_jack_pin tegra_rt5677_hp_jack_pins = {
103 .pin = "Headphone",
104 .mask = SND_JACK_HEADPHONE,
105};
106static struct snd_soc_jack_gpio tegra_rt5677_hp_jack_gpio = {
107 .name = "Headphone detection",
108 .report = SND_JACK_HEADPHONE,
109 .debounce_time = 150,
110};
111
112static struct snd_soc_jack tegra_rt5677_mic_jack;
113
114static struct snd_soc_jack_pin tegra_rt5677_mic_jack_pins = {
115 .pin = "Headset Mic",
116 .mask = SND_JACK_MICROPHONE,
117};
118
119static struct snd_soc_jack_gpio tegra_rt5677_mic_jack_gpio = {
120 .name = "Headset Mic detection",
121 .report = SND_JACK_MICROPHONE,
122 .debounce_time = 150,
123 .invert = 1
124};
125
126static const struct snd_soc_dapm_widget tegra_rt5677_dapm_widgets[] = {
127 SND_SOC_DAPM_SPK("Speaker", NULL),
128 SND_SOC_DAPM_HP("Headphone", tegra_rt5677_event_hp),
129 SND_SOC_DAPM_MIC("Headset Mic", NULL),
130 SND_SOC_DAPM_MIC("Internal Mic 1", NULL),
131 SND_SOC_DAPM_MIC("Internal Mic 2", NULL),
132};
133
134static const struct snd_kcontrol_new tegra_rt5677_controls[] = {
135 SOC_DAPM_PIN_SWITCH("Speaker"),
136 SOC_DAPM_PIN_SWITCH("Headphone"),
137 SOC_DAPM_PIN_SWITCH("Headset Mic"),
138 SOC_DAPM_PIN_SWITCH("Internal Mic 1"),
139 SOC_DAPM_PIN_SWITCH("Internal Mic 2"),
140};
141
142static int tegra_rt5677_asoc_init(struct snd_soc_pcm_runtime *rtd)
143{
144 struct snd_soc_dai *codec_dai = rtd->codec_dai;
145 struct snd_soc_codec *codec = codec_dai->codec;
146 struct snd_soc_dapm_context *dapm = &codec->dapm;
147 struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(rtd->card);
148
149 snd_soc_jack_new(codec, "Headphone Jack", SND_JACK_HEADPHONE,
150 &tegra_rt5677_hp_jack);
151 snd_soc_jack_add_pins(&tegra_rt5677_hp_jack, 1,
152 &tegra_rt5677_hp_jack_pins);
153
154 if (gpio_is_valid(machine->gpio_hp_det)) {
155 tegra_rt5677_hp_jack_gpio.gpio = machine->gpio_hp_det;
156 snd_soc_jack_add_gpios(&tegra_rt5677_hp_jack, 1,
157 &tegra_rt5677_hp_jack_gpio);
158 }
159
160
161 snd_soc_jack_new(codec, "Mic Jack", SND_JACK_MICROPHONE,
162 &tegra_rt5677_mic_jack);
163 snd_soc_jack_add_pins(&tegra_rt5677_mic_jack, 1,
164 &tegra_rt5677_mic_jack_pins);
165
166 if (gpio_is_valid(machine->gpio_mic_present)) {
167 tegra_rt5677_mic_jack_gpio.gpio = machine->gpio_mic_present;
168 snd_soc_jack_add_gpios(&tegra_rt5677_mic_jack, 1,
169 &tegra_rt5677_mic_jack_gpio);
170 }
171
172 snd_soc_dapm_force_enable_pin(dapm, "MICBIAS1");
173
174 return 0;
175}
176
177static int tegra_rt5677_card_remove(struct snd_soc_card *card)
178{
179 struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
180
181 if (gpio_is_valid(machine->gpio_hp_det)) {
182 snd_soc_jack_free_gpios(&tegra_rt5677_hp_jack, 1,
183 &tegra_rt5677_hp_jack_gpio);
184 }
185
186 if (gpio_is_valid(machine->gpio_mic_present)) {
187 snd_soc_jack_free_gpios(&tegra_rt5677_mic_jack, 1,
188 &tegra_rt5677_mic_jack_gpio);
189 }
190
191 return 0;
192}
193
194static struct snd_soc_dai_link tegra_rt5677_dai = {
195 .name = "RT5677",
196 .stream_name = "RT5677 PCM",
197 .codec_dai_name = "rt5677-aif1",
198 .init = tegra_rt5677_asoc_init,
199 .ops = &tegra_rt5677_ops,
200 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
201 SND_SOC_DAIFMT_CBS_CFS,
202};
203
204static struct snd_soc_card snd_soc_tegra_rt5677 = {
205 .name = "tegra-rt5677",
206 .owner = THIS_MODULE,
207 .remove = tegra_rt5677_card_remove,
208 .dai_link = &tegra_rt5677_dai,
209 .num_links = 1,
210 .controls = tegra_rt5677_controls,
211 .num_controls = ARRAY_SIZE(tegra_rt5677_controls),
212 .dapm_widgets = tegra_rt5677_dapm_widgets,
213 .num_dapm_widgets = ARRAY_SIZE(tegra_rt5677_dapm_widgets),
214 .fully_routed = true,
215};
216
217static int tegra_rt5677_probe(struct platform_device *pdev)
218{
219 struct device_node *np = pdev->dev.of_node;
220 struct snd_soc_card *card = &snd_soc_tegra_rt5677;
221 struct tegra_rt5677 *machine;
222 int ret;
223
224 machine = devm_kzalloc(&pdev->dev,
225 sizeof(struct tegra_rt5677), GFP_KERNEL);
226 if (!machine)
227 return -ENOMEM;
228
229 card->dev = &pdev->dev;
230 platform_set_drvdata(pdev, card);
231 snd_soc_card_set_drvdata(card, machine);
232
233 machine->gpio_hp_det = of_get_named_gpio(np, "nvidia,hp-det-gpios", 0);
234 if (machine->gpio_hp_det == -EPROBE_DEFER)
235 return -EPROBE_DEFER;
236
237 machine->gpio_mic_present = of_get_named_gpio(np,
238 "nvidia,mic-present-gpios", 0);
239 if (machine->gpio_mic_present == -EPROBE_DEFER)
240 return -EPROBE_DEFER;
241
242 machine->gpio_hp_en = of_get_named_gpio(np, "nvidia,hp-en-gpios", 0);
243 if (machine->gpio_hp_en == -EPROBE_DEFER)
244 return -EPROBE_DEFER;
245 if (gpio_is_valid(machine->gpio_hp_en)) {
246 ret = devm_gpio_request_one(&pdev->dev, machine->gpio_hp_en,
247 GPIOF_OUT_INIT_LOW, "hp_en");
248 if (ret) {
249 dev_err(card->dev, "cannot get hp_en gpio\n");
250 return ret;
251 }
252 }
253
254 machine->gpio_dmic_clk_en = of_get_named_gpio(np,
255 "nvidia,dmic-clk-en-gpios", 0);
256 if (machine->gpio_dmic_clk_en == -EPROBE_DEFER)
257 return -EPROBE_DEFER;
258 if (gpio_is_valid(machine->gpio_dmic_clk_en)) {
259 ret = devm_gpio_request_one(&pdev->dev,
260 machine->gpio_dmic_clk_en,
261 GPIOF_OUT_INIT_HIGH, "dmic_clk_en");
262 if (ret) {
263 dev_err(card->dev, "cannot get dmic_clk_en gpio\n");
264 return ret;
265 }
266 }
267
268 ret = snd_soc_of_parse_card_name(card, "nvidia,model");
269 if (ret)
270 goto err;
271
272 ret = snd_soc_of_parse_audio_routing(card, "nvidia,audio-routing");
273 if (ret)
274 goto err;
275
276 tegra_rt5677_dai.codec_of_node = of_parse_phandle(np,
277 "nvidia,audio-codec", 0);
278 if (!tegra_rt5677_dai.codec_of_node) {
279 dev_err(&pdev->dev,
280 "Property 'nvidia,audio-codec' missing or invalid\n");
281 ret = -EINVAL;
282 goto err;
283 }
284
285 tegra_rt5677_dai.cpu_of_node = of_parse_phandle(np,
286 "nvidia,i2s-controller", 0);
287 if (!tegra_rt5677_dai.cpu_of_node) {
288 dev_err(&pdev->dev,
289 "Property 'nvidia,i2s-controller' missing or invalid\n");
290 ret = -EINVAL;
291 goto err;
292 }
293 tegra_rt5677_dai.platform_of_node = tegra_rt5677_dai.cpu_of_node;
294
295 ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
296 if (ret)
297 goto err;
298
299 ret = snd_soc_register_card(card);
300 if (ret) {
301 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
302 ret);
303 goto err_fini_utils;
304 }
305
306 return 0;
307
308err_fini_utils:
309 tegra_asoc_utils_fini(&machine->util_data);
310err:
311 return ret;
312}
313
314static int tegra_rt5677_remove(struct platform_device *pdev)
315{
316 struct snd_soc_card *card = platform_get_drvdata(pdev);
317 struct tegra_rt5677 *machine = snd_soc_card_get_drvdata(card);
318
319 snd_soc_unregister_card(card);
320
321 tegra_asoc_utils_fini(&machine->util_data);
322
323 return 0;
324}
325
326static const struct of_device_id tegra_rt5677_of_match[] = {
327 { .compatible = "nvidia,tegra-audio-rt5677", },
328 {},
329};
330
331static struct platform_driver tegra_rt5677_driver = {
332 .driver = {
333 .name = DRV_NAME,
334 .owner = THIS_MODULE,
335 .pm = &snd_soc_pm_ops,
336 .of_match_table = tegra_rt5677_of_match,
337 },
338 .probe = tegra_rt5677_probe,
339 .remove = tegra_rt5677_remove,
340};
341module_platform_driver(tegra_rt5677_driver);
342
343MODULE_AUTHOR("Anatol Pomozov <anatol@google.com>");
344MODULE_DESCRIPTION("Tegra+RT5677 machine ASoC driver");
345MODULE_LICENSE("GPL v2");
346MODULE_ALIAS("platform:" DRV_NAME);
347MODULE_DEVICE_TABLE(of, tegra_rt5677_of_match);
diff --git a/sound/soc/txx9/txx9aclc.c b/sound/soc/txx9/txx9aclc.c
index 070e44e251ce..88eacfd83da6 100644
--- a/sound/soc/txx9/txx9aclc.c
+++ b/sound/soc/txx9/txx9aclc.c
@@ -282,11 +282,6 @@ static struct snd_pcm_ops txx9aclc_pcm_ops = {
282 .pointer = txx9aclc_pcm_pointer, 282 .pointer = txx9aclc_pcm_pointer,
283}; 283};
284 284
285static void txx9aclc_pcm_free_dma_buffers(struct snd_pcm *pcm)
286{
287 snd_pcm_lib_preallocate_free_for_all(pcm);
288}
289
290static int txx9aclc_pcm_new(struct snd_soc_pcm_runtime *rtd) 285static int txx9aclc_pcm_new(struct snd_soc_pcm_runtime *rtd)
291{ 286{
292 struct snd_card *card = rtd->card->snd_card; 287 struct snd_card *card = rtd->card->snd_card;
@@ -412,7 +407,6 @@ static struct snd_soc_platform_driver txx9aclc_soc_platform = {
412 .remove = txx9aclc_pcm_remove, 407 .remove = txx9aclc_pcm_remove,
413 .ops = &txx9aclc_pcm_ops, 408 .ops = &txx9aclc_pcm_ops,
414 .pcm_new = txx9aclc_pcm_new, 409 .pcm_new = txx9aclc_pcm_new,
415 .pcm_free = txx9aclc_pcm_free_dma_buffers,
416}; 410};
417 411
418static int txx9aclc_soc_platform_probe(struct platform_device *pdev) 412static int txx9aclc_soc_platform_probe(struct platform_device *pdev)
diff --git a/sound/soc/ux500/mop500_ab8500.c b/sound/soc/ux500/mop500_ab8500.c
index be4f1ac7cd5e..aa65370db82a 100644
--- a/sound/soc/ux500/mop500_ab8500.c
+++ b/sound/soc/ux500/mop500_ab8500.c
@@ -290,21 +290,9 @@ static int mop500_ab8500_hw_params(struct snd_pcm_substream *substream,
290 SND_SOC_DAIFMT_GATED; 290 SND_SOC_DAIFMT_GATED;
291 } 291 }
292 292
293 ret = snd_soc_dai_set_fmt(codec_dai, fmt); 293 ret = snd_soc_runtime_set_dai_fmt(rtd, fmt);
294 if (ret < 0) { 294 if (ret)
295 dev_err(dev,
296 "%s: ERROR: snd_soc_dai_set_fmt failed for codec_dai (ret = %d)!\n",
297 __func__, ret);
298 return ret;
299 }
300
301 ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
302 if (ret < 0) {
303 dev_err(dev,
304 "%s: ERROR: snd_soc_dai_set_fmt failed for cpu_dai (ret = %d)!\n",
305 __func__, ret);
306 return ret; 295 return ret;
307 }
308 296
309 /* Setup TDM-slots */ 297 /* Setup TDM-slots */
310 298
diff --git a/sound/soc/xtensa/Kconfig b/sound/soc/xtensa/Kconfig
new file mode 100644
index 000000000000..c201beb36de6
--- /dev/null
+++ b/sound/soc/xtensa/Kconfig
@@ -0,0 +1,7 @@
1config SND_SOC_XTFPGA_I2S
2 tristate "XTFPGA I2S master"
3 select REGMAP_MMIO
4 help
5 Say Y or M if you want to add support for codecs attached to the
6 I2S interface on XTFPGA daughter board. You will also need to select
7 the drivers for the rest of XTFPGA audio subsystem.
diff --git a/sound/soc/xtensa/Makefile b/sound/soc/xtensa/Makefile
new file mode 100644
index 000000000000..15efbf914226
--- /dev/null
+++ b/sound/soc/xtensa/Makefile
@@ -0,0 +1,3 @@
1snd-soc-xtfpga-i2s-objs := xtfpga-i2s.o
2
3obj-$(CONFIG_SND_SOC_XTFPGA_I2S) += snd-soc-xtfpga-i2s.o
diff --git a/sound/soc/xtensa/xtfpga-i2s.c b/sound/soc/xtensa/xtfpga-i2s.c
new file mode 100644
index 000000000000..1cfb19e12949
--- /dev/null
+++ b/sound/soc/xtensa/xtfpga-i2s.c
@@ -0,0 +1,675 @@
1/*
2 * Xtfpga I2S controller driver
3 *
4 * Copyright (c) 2014 Cadence Design Systems Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/clk.h>
12#include <linux/io.h>
13#include <linux/module.h>
14#include <linux/of.h>
15#include <linux/platform_device.h>
16#include <linux/pm_runtime.h>
17#include <sound/pcm_params.h>
18#include <sound/soc.h>
19
20#define DRV_NAME "xtfpga-i2s"
21
22#define XTFPGA_I2S_VERSION 0x00
23#define XTFPGA_I2S_CONFIG 0x04
24#define XTFPGA_I2S_INT_MASK 0x08
25#define XTFPGA_I2S_INT_STATUS 0x0c
26#define XTFPGA_I2S_CHAN0_DATA 0x10
27#define XTFPGA_I2S_CHAN1_DATA 0x14
28#define XTFPGA_I2S_CHAN2_DATA 0x18
29#define XTFPGA_I2S_CHAN3_DATA 0x1c
30
31#define XTFPGA_I2S_CONFIG_TX_ENABLE 0x1
32#define XTFPGA_I2S_CONFIG_INT_ENABLE 0x2
33#define XTFPGA_I2S_CONFIG_LEFT 0x4
34#define XTFPGA_I2S_CONFIG_RATIO_BASE 8
35#define XTFPGA_I2S_CONFIG_RATIO_MASK 0x0000ff00
36#define XTFPGA_I2S_CONFIG_RES_BASE 16
37#define XTFPGA_I2S_CONFIG_RES_MASK 0x003f0000
38#define XTFPGA_I2S_CONFIG_LEVEL_BASE 24
39#define XTFPGA_I2S_CONFIG_LEVEL_MASK 0x0f000000
40#define XTFPGA_I2S_CONFIG_CHANNEL_BASE 28
41
42#define XTFPGA_I2S_INT_UNDERRUN 0x1
43#define XTFPGA_I2S_INT_LEVEL 0x2
44#define XTFPGA_I2S_INT_VALID 0x3
45
46#define XTFPGA_I2S_FIFO_SIZE 8192
47
48/*
49 * I2S controller operation:
50 *
51 * Enabling TX: output 1 period of zeros (starting with left channel)
52 * and then queued data.
53 *
54 * Level status and interrupt: whenever FIFO level is below FIFO trigger,
55 * level status is 1 and an IRQ is asserted (if enabled).
56 *
57 * Underrun status and interrupt: whenever FIFO is empty, underrun status
58 * is 1 and an IRQ is asserted (if enabled).
59 */
60struct xtfpga_i2s {
61 struct device *dev;
62 struct clk *clk;
63 struct regmap *regmap;
64 void __iomem *regs;
65
66 /* current playback substream. NULL if not playing.
67 *
68 * Access to that field is synchronized between the interrupt handler
69 * and userspace through RCU.
70 *
71 * Interrupt handler (threaded part) does PIO on substream data in RCU
72 * read-side critical section. Trigger callback sets and clears the
73 * pointer when the playback is started and stopped with
74 * rcu_assign_pointer. When userspace is about to free the playback
75 * stream in the pcm_close callback it synchronizes with the interrupt
76 * handler by means of synchronize_rcu call.
77 */
78 struct snd_pcm_substream *tx_substream;
79 unsigned (*tx_fn)(struct xtfpga_i2s *i2s,
80 struct snd_pcm_runtime *runtime,
81 unsigned tx_ptr);
82 unsigned tx_ptr; /* next frame index in the sample buffer */
83
84 /* current fifo level estimate.
85 * Doesn't have to be perfectly accurate, but must be not less than
86 * the actual FIFO level in order to avoid stall on push attempt.
87 */
88 unsigned tx_fifo_level;
89
90 /* FIFO level at which level interrupt occurs */
91 unsigned tx_fifo_low;
92
93 /* maximal FIFO level */
94 unsigned tx_fifo_high;
95};
96
97static bool xtfpga_i2s_wr_reg(struct device *dev, unsigned int reg)
98{
99 return reg >= XTFPGA_I2S_CONFIG;
100}
101
102static bool xtfpga_i2s_rd_reg(struct device *dev, unsigned int reg)
103{
104 return reg < XTFPGA_I2S_CHAN0_DATA;
105}
106
107static bool xtfpga_i2s_volatile_reg(struct device *dev, unsigned int reg)
108{
109 return reg == XTFPGA_I2S_INT_STATUS;
110}
111
112static const struct regmap_config xtfpga_i2s_regmap_config = {
113 .reg_bits = 32,
114 .reg_stride = 4,
115 .val_bits = 32,
116 .max_register = XTFPGA_I2S_CHAN3_DATA,
117 .writeable_reg = xtfpga_i2s_wr_reg,
118 .readable_reg = xtfpga_i2s_rd_reg,
119 .volatile_reg = xtfpga_i2s_volatile_reg,
120 .cache_type = REGCACHE_FLAT,
121};
122
123/* Generate functions that do PIO from TX DMA area to FIFO for all supported
124 * stream formats.
125 * Functions will be called xtfpga_pcm_tx_<channels>x<sample bits>, e.g.
126 * xtfpga_pcm_tx_2x16 for 16-bit stereo.
127 *
128 * FIFO consists of 32-bit words, one word per channel, always 2 channels.
129 * If I2S interface is configured with smaller sample resolution, only
130 * the LSB of each word is used.
131 */
132#define xtfpga_pcm_tx_fn(channels, sample_bits) \
133static unsigned xtfpga_pcm_tx_##channels##x##sample_bits( \
134 struct xtfpga_i2s *i2s, struct snd_pcm_runtime *runtime, \
135 unsigned tx_ptr) \
136{ \
137 const u##sample_bits (*p)[channels] = \
138 (void *)runtime->dma_area; \
139\
140 for (; i2s->tx_fifo_level < i2s->tx_fifo_high; \
141 i2s->tx_fifo_level += 2) { \
142 iowrite32(p[tx_ptr][0], \
143 i2s->regs + XTFPGA_I2S_CHAN0_DATA); \
144 iowrite32(p[tx_ptr][channels - 1], \
145 i2s->regs + XTFPGA_I2S_CHAN0_DATA); \
146 if (++tx_ptr >= runtime->buffer_size) \
147 tx_ptr = 0; \
148 } \
149 return tx_ptr; \
150}
151
152xtfpga_pcm_tx_fn(1, 16)
153xtfpga_pcm_tx_fn(2, 16)
154xtfpga_pcm_tx_fn(1, 32)
155xtfpga_pcm_tx_fn(2, 32)
156
157#undef xtfpga_pcm_tx_fn
158
159static bool xtfpga_pcm_push_tx(struct xtfpga_i2s *i2s)
160{
161 struct snd_pcm_substream *tx_substream;
162 bool tx_active;
163
164 rcu_read_lock();
165 tx_substream = rcu_dereference(i2s->tx_substream);
166 tx_active = tx_substream && snd_pcm_running(tx_substream);
167 if (tx_active) {
168 unsigned tx_ptr = ACCESS_ONCE(i2s->tx_ptr);
169 unsigned new_tx_ptr = i2s->tx_fn(i2s, tx_substream->runtime,
170 tx_ptr);
171
172 cmpxchg(&i2s->tx_ptr, tx_ptr, new_tx_ptr);
173 }
174 rcu_read_unlock();
175
176 return tx_active;
177}
178
179static void xtfpga_pcm_refill_fifo(struct xtfpga_i2s *i2s)
180{
181 unsigned int_status;
182 unsigned i;
183
184 regmap_read(i2s->regmap, XTFPGA_I2S_INT_STATUS,
185 &int_status);
186
187 for (i = 0; i < 2; ++i) {
188 bool tx_active = xtfpga_pcm_push_tx(i2s);
189
190 regmap_write(i2s->regmap, XTFPGA_I2S_INT_STATUS,
191 XTFPGA_I2S_INT_VALID);
192 if (tx_active)
193 regmap_read(i2s->regmap, XTFPGA_I2S_INT_STATUS,
194 &int_status);
195
196 if (!tx_active ||
197 !(int_status & XTFPGA_I2S_INT_LEVEL))
198 break;
199
200 /* After the push the level IRQ is still asserted,
201 * means FIFO level is below tx_fifo_low. Estimate
202 * it as tx_fifo_low.
203 */
204 i2s->tx_fifo_level = i2s->tx_fifo_low;
205 }
206
207 if (!(int_status & XTFPGA_I2S_INT_LEVEL))
208 regmap_write(i2s->regmap, XTFPGA_I2S_INT_MASK,
209 XTFPGA_I2S_INT_VALID);
210 else if (!(int_status & XTFPGA_I2S_INT_UNDERRUN))
211 regmap_write(i2s->regmap, XTFPGA_I2S_INT_MASK,
212 XTFPGA_I2S_INT_UNDERRUN);
213
214 if (!(int_status & XTFPGA_I2S_INT_UNDERRUN))
215 regmap_update_bits(i2s->regmap, XTFPGA_I2S_CONFIG,
216 XTFPGA_I2S_CONFIG_INT_ENABLE |
217 XTFPGA_I2S_CONFIG_TX_ENABLE,
218 XTFPGA_I2S_CONFIG_INT_ENABLE |
219 XTFPGA_I2S_CONFIG_TX_ENABLE);
220 else
221 regmap_update_bits(i2s->regmap, XTFPGA_I2S_CONFIG,
222 XTFPGA_I2S_CONFIG_INT_ENABLE |
223 XTFPGA_I2S_CONFIG_TX_ENABLE, 0);
224}
225
226static irqreturn_t xtfpga_i2s_threaded_irq_handler(int irq, void *dev_id)
227{
228 struct xtfpga_i2s *i2s = dev_id;
229 struct snd_pcm_substream *tx_substream;
230 unsigned config, int_status, int_mask;
231
232 regmap_read(i2s->regmap, XTFPGA_I2S_CONFIG, &config);
233 regmap_read(i2s->regmap, XTFPGA_I2S_INT_MASK, &int_mask);
234 regmap_read(i2s->regmap, XTFPGA_I2S_INT_STATUS, &int_status);
235
236 if (!(config & XTFPGA_I2S_CONFIG_INT_ENABLE) ||
237 !(int_status & int_mask & XTFPGA_I2S_INT_VALID))
238 return IRQ_NONE;
239
240 /* Update FIFO level estimate in accordance with interrupt status
241 * register.
242 */
243 if (int_status & XTFPGA_I2S_INT_UNDERRUN) {
244 i2s->tx_fifo_level = 0;
245 regmap_update_bits(i2s->regmap, XTFPGA_I2S_CONFIG,
246 XTFPGA_I2S_CONFIG_TX_ENABLE, 0);
247 } else {
248 /* The FIFO isn't empty, but is below tx_fifo_low. Estimate
249 * it as tx_fifo_low.
250 */
251 i2s->tx_fifo_level = i2s->tx_fifo_low;
252 }
253
254 rcu_read_lock();
255 tx_substream = rcu_dereference(i2s->tx_substream);
256
257 if (tx_substream && snd_pcm_running(tx_substream)) {
258 snd_pcm_period_elapsed(tx_substream);
259 if (int_status & XTFPGA_I2S_INT_UNDERRUN)
260 dev_dbg_ratelimited(i2s->dev, "%s: underrun\n",
261 __func__);
262 }
263 rcu_read_unlock();
264
265 /* Refill FIFO, update allowed IRQ reasons, enable IRQ if FIFO is
266 * not empty.
267 */
268 xtfpga_pcm_refill_fifo(i2s);
269
270 return IRQ_HANDLED;
271}
272
273static int xtfpga_i2s_startup(struct snd_pcm_substream *substream,
274 struct snd_soc_dai *dai)
275{
276 struct xtfpga_i2s *i2s = snd_soc_dai_get_drvdata(dai);
277
278 snd_soc_dai_set_dma_data(dai, substream, i2s);
279 return 0;
280}
281
282static int xtfpga_i2s_hw_params(struct snd_pcm_substream *substream,
283 struct snd_pcm_hw_params *params,
284 struct snd_soc_dai *dai)
285{
286 struct xtfpga_i2s *i2s = snd_soc_dai_get_drvdata(dai);
287 unsigned srate = params_rate(params);
288 unsigned channels = params_channels(params);
289 unsigned period_size = params_period_size(params);
290 unsigned sample_size = snd_pcm_format_width(params_format(params));
291 unsigned freq, ratio, level;
292 int err;
293
294 regmap_update_bits(i2s->regmap, XTFPGA_I2S_CONFIG,
295 XTFPGA_I2S_CONFIG_RES_MASK,
296 sample_size << XTFPGA_I2S_CONFIG_RES_BASE);
297
298 freq = 256 * srate;
299 err = clk_set_rate(i2s->clk, freq);
300 if (err < 0)
301 return err;
302
303 /* ratio field of the config register controls MCLK->I2S clock
304 * derivation: I2S clock = MCLK / (2 * (ratio + 2)).
305 *
306 * So with MCLK = 256 * sample rate ratio is 0 for 32 bit stereo
307 * and 2 for 16 bit stereo.
308 */
309 ratio = (freq - (srate * sample_size * 8)) /
310 (srate * sample_size * 4);
311
312 regmap_update_bits(i2s->regmap, XTFPGA_I2S_CONFIG,
313 XTFPGA_I2S_CONFIG_RATIO_MASK,
314 ratio << XTFPGA_I2S_CONFIG_RATIO_BASE);
315
316 i2s->tx_fifo_low = XTFPGA_I2S_FIFO_SIZE / 2;
317
318 /* period_size * 2: FIFO always gets 2 samples per frame */
319 for (level = 1;
320 i2s->tx_fifo_low / 2 >= period_size * 2 &&
321 level < (XTFPGA_I2S_CONFIG_LEVEL_MASK >>
322 XTFPGA_I2S_CONFIG_LEVEL_BASE); ++level)
323 i2s->tx_fifo_low /= 2;
324
325 i2s->tx_fifo_high = 2 * i2s->tx_fifo_low;
326
327 regmap_update_bits(i2s->regmap, XTFPGA_I2S_CONFIG,
328 XTFPGA_I2S_CONFIG_LEVEL_MASK,
329 level << XTFPGA_I2S_CONFIG_LEVEL_BASE);
330
331 dev_dbg(i2s->dev,
332 "%s srate: %u, channels: %u, sample_size: %u, period_size: %u\n",
333 __func__, srate, channels, sample_size, period_size);
334 dev_dbg(i2s->dev, "%s freq: %u, ratio: %u, level: %u\n",
335 __func__, freq, ratio, level);
336
337 return 0;
338}
339
340static int xtfpga_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
341 unsigned int fmt)
342{
343 if ((fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF)
344 return -EINVAL;
345 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS)
346 return -EINVAL;
347 if ((fmt & SND_SOC_DAIFMT_FORMAT_MASK) != SND_SOC_DAIFMT_I2S)
348 return -EINVAL;
349
350 return 0;
351}
352
353/* PCM */
354
355static const struct snd_pcm_hardware xtfpga_pcm_hardware = {
356 .info = SNDRV_PCM_INFO_INTERLEAVED |
357 SNDRV_PCM_INFO_MMAP_VALID |
358 SNDRV_PCM_INFO_BLOCK_TRANSFER,
359 .formats = SNDRV_PCM_FMTBIT_S16_LE |
360 SNDRV_PCM_FMTBIT_S32_LE,
361 .channels_min = 1,
362 .channels_max = 2,
363 .period_bytes_min = 2,
364 .period_bytes_max = XTFPGA_I2S_FIFO_SIZE / 2 * 8,
365 .periods_min = 2,
366 .periods_max = XTFPGA_I2S_FIFO_SIZE * 8 / 2,
367 .buffer_bytes_max = XTFPGA_I2S_FIFO_SIZE * 8,
368 .fifo_size = 16,
369};
370
371static int xtfpga_pcm_open(struct snd_pcm_substream *substream)
372{
373 struct snd_pcm_runtime *runtime = substream->runtime;
374 struct snd_soc_pcm_runtime *rtd = substream->private_data;
375 void *p;
376
377 snd_soc_set_runtime_hwparams(substream, &xtfpga_pcm_hardware);
378 p = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
379 runtime->private_data = p;
380
381 return 0;
382}
383
384static int xtfpga_pcm_close(struct snd_pcm_substream *substream)
385{
386 synchronize_rcu();
387 return 0;
388}
389
390static int xtfpga_pcm_hw_params(struct snd_pcm_substream *substream,
391 struct snd_pcm_hw_params *hw_params)
392{
393 int ret;
394 struct snd_pcm_runtime *runtime = substream->runtime;
395 struct xtfpga_i2s *i2s = runtime->private_data;
396 unsigned channels = params_channels(hw_params);
397
398 switch (channels) {
399 case 1:
400 case 2:
401 break;
402
403 default:
404 return -EINVAL;
405
406 }
407
408 switch (params_format(hw_params)) {
409 case SNDRV_PCM_FORMAT_S16_LE:
410 i2s->tx_fn = (channels == 1) ?
411 xtfpga_pcm_tx_1x16 :
412 xtfpga_pcm_tx_2x16;
413 break;
414
415 case SNDRV_PCM_FORMAT_S32_LE:
416 i2s->tx_fn = (channels == 1) ?
417 xtfpga_pcm_tx_1x32 :
418 xtfpga_pcm_tx_2x32;
419 break;
420
421 default:
422 return -EINVAL;
423 }
424
425 ret = snd_pcm_lib_malloc_pages(substream,
426 params_buffer_bytes(hw_params));
427 return ret;
428}
429
430static int xtfpga_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
431{
432 int ret = 0;
433 struct snd_pcm_runtime *runtime = substream->runtime;
434 struct xtfpga_i2s *i2s = runtime->private_data;
435
436 switch (cmd) {
437 case SNDRV_PCM_TRIGGER_START:
438 case SNDRV_PCM_TRIGGER_RESUME:
439 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
440 ACCESS_ONCE(i2s->tx_ptr) = 0;
441 rcu_assign_pointer(i2s->tx_substream, substream);
442 xtfpga_pcm_refill_fifo(i2s);
443 break;
444
445 case SNDRV_PCM_TRIGGER_STOP:
446 case SNDRV_PCM_TRIGGER_SUSPEND:
447 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
448 rcu_assign_pointer(i2s->tx_substream, NULL);
449 break;
450
451 default:
452 ret = -EINVAL;
453 break;
454 }
455 return ret;
456}
457
458static snd_pcm_uframes_t xtfpga_pcm_pointer(struct snd_pcm_substream *substream)
459{
460 struct snd_pcm_runtime *runtime = substream->runtime;
461 struct xtfpga_i2s *i2s = runtime->private_data;
462 snd_pcm_uframes_t pos = ACCESS_ONCE(i2s->tx_ptr);
463
464 return pos < runtime->buffer_size ? pos : 0;
465}
466
467static int xtfpga_pcm_new(struct snd_soc_pcm_runtime *rtd)
468{
469 struct snd_card *card = rtd->card->snd_card;
470 size_t size = xtfpga_pcm_hardware.buffer_bytes_max;
471
472 return snd_pcm_lib_preallocate_pages_for_all(rtd->pcm,
473 SNDRV_DMA_TYPE_DEV,
474 card->dev, size, size);
475}
476
477static void xtfpga_pcm_free(struct snd_pcm *pcm)
478{
479 snd_pcm_lib_preallocate_free_for_all(pcm);
480}
481
482static const struct snd_pcm_ops xtfpga_pcm_ops = {
483 .open = xtfpga_pcm_open,
484 .close = xtfpga_pcm_close,
485 .ioctl = snd_pcm_lib_ioctl,
486 .hw_params = xtfpga_pcm_hw_params,
487 .trigger = xtfpga_pcm_trigger,
488 .pointer = xtfpga_pcm_pointer,
489};
490
491static const struct snd_soc_platform_driver xtfpga_soc_platform = {
492 .pcm_new = xtfpga_pcm_new,
493 .pcm_free = xtfpga_pcm_free,
494 .ops = &xtfpga_pcm_ops,
495};
496
497static const struct snd_soc_component_driver xtfpga_i2s_component = {
498 .name = DRV_NAME,
499};
500
501static const struct snd_soc_dai_ops xtfpga_i2s_dai_ops = {
502 .startup = xtfpga_i2s_startup,
503 .hw_params = xtfpga_i2s_hw_params,
504 .set_fmt = xtfpga_i2s_set_fmt,
505};
506
507static struct snd_soc_dai_driver xtfpga_i2s_dai[] = {
508 {
509 .name = "xtfpga-i2s",
510 .id = 0,
511 .playback = {
512 .channels_min = 1,
513 .channels_max = 2,
514 .rates = SNDRV_PCM_RATE_8000_96000,
515 .formats = SNDRV_PCM_FMTBIT_S16_LE |
516 SNDRV_PCM_FMTBIT_S32_LE,
517 },
518 .ops = &xtfpga_i2s_dai_ops,
519 },
520};
521
522static int xtfpga_i2s_runtime_suspend(struct device *dev)
523{
524 struct xtfpga_i2s *i2s = dev_get_drvdata(dev);
525
526 clk_disable_unprepare(i2s->clk);
527 return 0;
528}
529
530static int xtfpga_i2s_runtime_resume(struct device *dev)
531{
532 struct xtfpga_i2s *i2s = dev_get_drvdata(dev);
533 int ret;
534
535 ret = clk_prepare_enable(i2s->clk);
536 if (ret) {
537 dev_err(dev, "clk_prepare_enable failed: %d\n", ret);
538 return ret;
539 }
540 return 0;
541}
542
543static int xtfpga_i2s_probe(struct platform_device *pdev)
544{
545 struct xtfpga_i2s *i2s;
546 struct resource *mem;
547 int err, irq;
548
549 i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL);
550 if (!i2s) {
551 err = -ENOMEM;
552 goto err;
553 }
554 platform_set_drvdata(pdev, i2s);
555 i2s->dev = &pdev->dev;
556 dev_dbg(&pdev->dev, "dev: %p, i2s: %p\n", &pdev->dev, i2s);
557
558 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
559 i2s->regs = devm_ioremap_resource(&pdev->dev, mem);
560 if (IS_ERR(i2s->regs)) {
561 err = PTR_ERR(i2s->regs);
562 goto err;
563 }
564
565 i2s->regmap = devm_regmap_init_mmio(&pdev->dev, i2s->regs,
566 &xtfpga_i2s_regmap_config);
567 if (IS_ERR(i2s->regmap)) {
568 dev_err(&pdev->dev, "regmap init failed\n");
569 err = PTR_ERR(i2s->regmap);
570 goto err;
571 }
572
573 i2s->clk = devm_clk_get(&pdev->dev, NULL);
574 if (IS_ERR(i2s->clk)) {
575 dev_err(&pdev->dev, "couldn't get clock\n");
576 err = PTR_ERR(i2s->clk);
577 goto err;
578 }
579
580 regmap_write(i2s->regmap, XTFPGA_I2S_CONFIG,
581 (0x1 << XTFPGA_I2S_CONFIG_CHANNEL_BASE));
582 regmap_write(i2s->regmap, XTFPGA_I2S_INT_STATUS, XTFPGA_I2S_INT_VALID);
583 regmap_write(i2s->regmap, XTFPGA_I2S_INT_MASK, XTFPGA_I2S_INT_UNDERRUN);
584
585 irq = platform_get_irq(pdev, 0);
586 if (irq < 0) {
587 dev_err(&pdev->dev, "No IRQ resource\n");
588 err = irq;
589 goto err;
590 }
591 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
592 xtfpga_i2s_threaded_irq_handler,
593 IRQF_SHARED | IRQF_ONESHOT,
594 pdev->name, i2s);
595 if (err < 0) {
596 dev_err(&pdev->dev, "request_irq failed\n");
597 goto err;
598 }
599
600 err = snd_soc_register_platform(&pdev->dev, &xtfpga_soc_platform);
601 if (err < 0) {
602 dev_err(&pdev->dev, "couldn't register platform\n");
603 goto err;
604 }
605 err = devm_snd_soc_register_component(&pdev->dev,
606 &xtfpga_i2s_component,
607 xtfpga_i2s_dai,
608 ARRAY_SIZE(xtfpga_i2s_dai));
609 if (err < 0) {
610 dev_err(&pdev->dev, "couldn't register component\n");
611 goto err_unregister_platform;
612 }
613
614 pm_runtime_enable(&pdev->dev);
615 if (!pm_runtime_enabled(&pdev->dev)) {
616 err = xtfpga_i2s_runtime_resume(&pdev->dev);
617 if (err)
618 goto err_pm_disable;
619 }
620 return 0;
621
622err_pm_disable:
623 pm_runtime_disable(&pdev->dev);
624err_unregister_platform:
625 snd_soc_unregister_platform(&pdev->dev);
626err:
627 dev_err(&pdev->dev, "%s: err = %d\n", __func__, err);
628 return err;
629}
630
631static int xtfpga_i2s_remove(struct platform_device *pdev)
632{
633 struct xtfpga_i2s *i2s = dev_get_drvdata(&pdev->dev);
634
635 snd_soc_unregister_platform(&pdev->dev);
636 if (i2s->regmap && !IS_ERR(i2s->regmap)) {
637 regmap_write(i2s->regmap, XTFPGA_I2S_CONFIG, 0);
638 regmap_write(i2s->regmap, XTFPGA_I2S_INT_MASK, 0);
639 regmap_write(i2s->regmap, XTFPGA_I2S_INT_STATUS,
640 XTFPGA_I2S_INT_VALID);
641 }
642 pm_runtime_disable(&pdev->dev);
643 if (!pm_runtime_status_suspended(&pdev->dev))
644 xtfpga_i2s_runtime_suspend(&pdev->dev);
645 return 0;
646}
647
648#ifdef CONFIG_OF
649static const struct of_device_id xtfpga_i2s_of_match[] = {
650 { .compatible = "cdns,xtfpga-i2s", },
651 {},
652};
653MODULE_DEVICE_TABLE(of, xtfpga_i2s_of_match);
654#endif
655
656static const struct dev_pm_ops xtfpga_i2s_pm_ops = {
657 SET_RUNTIME_PM_OPS(xtfpga_i2s_runtime_suspend,
658 xtfpga_i2s_runtime_resume, NULL)
659};
660
661static struct platform_driver xtfpga_i2s_driver = {
662 .probe = xtfpga_i2s_probe,
663 .remove = xtfpga_i2s_remove,
664 .driver = {
665 .name = "xtfpga-i2s",
666 .of_match_table = of_match_ptr(xtfpga_i2s_of_match),
667 .pm = &xtfpga_i2s_pm_ops,
668 },
669};
670
671module_platform_driver(xtfpga_i2s_driver);
672
673MODULE_AUTHOR("Max Filippov <jcmvbkbc@gmail.com>");
674MODULE_DESCRIPTION("xtfpga I2S controller driver");
675MODULE_LICENSE("GPL v2");