Skip to contentSkip to conversation

Add mrfld DSP topology and widgets

PATCH Applied Subhransu S. Prusty 3 participants 46 messages Aug 4, 2014 – Aug 19, 2014

Subsystems (3)

v4 of 7 Applied Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add mrfld DSP topology and widgets

This patch series adds DPCM and DAPM widgets to handle DSP topology in the SST platform driver for merrifield.

Changes in v4:
Removed print messages for kzalloc failure as per review comments from Takashi.

Subhransu S. Prusty (2):
ASoC: Intel: mrfld: set private data for cpu-dai
ASoC: Export dapm_kcontrol_get_value

Vinod Koul (10):
ASoC: Intel: mfld-pcm: add FE and BE ops
ASoC: intel: mfld-pcm: don't call trigger ops to DSP for internal
streams
ASoC: Intel: add mrfld DSP defines
ASoC: Intel: mrfld: add bytes control for modules
ASoC: Intel: mrfld: add the gain controls
ASoC: Intel: mfld-pcm: add control for powering up/down dsp
ASoC: Intel: mrfld: add DSP core controls
ASoC: Intel: mrfld: add the DSP DAPM widgets
ASoC: Intel: mfld-pcm: add the fe & be dai ops
ASoC: Intel: mrfld: add the DSP mixers

 include/sound/soc-dapm.h                |    1 +
 sound/soc/intel/Makefile                |    3 +-
 sound/soc/intel/sst-atom-controls.c     | 1256 +++++++++++++++++++++++++++++++
 sound/soc/intel/sst-atom-controls.h     |  844 ++++++++++++++++++++-
 sound/soc/intel/sst-mfld-platform-pcm.c |  192 ++++-
 sound/soc/intel/sst-mfld-platform.h     |    8 +
 sound/soc/soc-dapm.c                    |    3 +-
 7 files changed, 2269 insertions(+), 38 deletions(-)
 create mode 100644 sound/soc/intel/sst-atom-controls.c
Signature · 1 line
1.9.0
#1 lore raw

PATCH v4 1/12 ASoC: Intel: mfld-pcm: add FE and BE ops

From: Vinod Koul <[email protected]>

Now that we have added code for managing DSP pipelines we need to add the code for DSPs FrontEnd and Backend dai.

---
 sound/soc/intel/sst-mfld-platform-pcm.c | 113 ++++++++++++++++++++++++--------
 1 file changed, 84 insertions(+), 29 deletions(-)
sound/soc/intel/sst-mfld-platform-pcm.c +84 -29
index a89ff7e18e1a..364034024cee 100644
@@ -101,35 +101,6 @@ static struct sst_dev_stream_map dpcm_strm_map[] = {
 	{MERR_DPCM_AUDIO, 0, SNDRV_PCM_STREAM_CAPTURE, PIPE_PCM1_OUT, SST_TASK_ID_MEDIA, 0},
 };
 
-/* MFLD - MSIC */
-static struct snd_soc_dai_driver sst_platform_dai[] = {
-{
-	.name = "Headset-cpu-dai",
-	.id = 0,
-	.playback = {
-		.channels_min = SST_STEREO,
-		.channels_max = SST_STEREO,
-		.rates = SNDRV_PCM_RATE_48000,
-		.formats = SNDRV_PCM_FMTBIT_S24_LE,
-	},
-	.capture = {
-		.channels_min = 1,
-		.channels_max = 5,
-		.rates = SNDRV_PCM_RATE_48000,
-		.formats = SNDRV_PCM_FMTBIT_S24_LE,
-	},
-},
-{
-	.name = "Compress-cpu-dai",
-	.compress_dai = 1,
-	.playback = {
-		.channels_min = SST_STEREO,
-		.channels_max = SST_STEREO,
-		.rates = SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000,
-		.formats = SNDRV_PCM_FMTBIT_S16_LE,
-	},
-},
-};
 
 /* helper functions */
 void sst_set_stream_status(struct sst_runtime_stream *stream,
@@ -441,6 +412,90 @@ static struct snd_soc_dai_ops sst_media_dai_ops = {
 	.hw_free = sst_media_hw_free,
 };
 
+static struct snd_soc_dai_driver sst_platform_dai[] = {
+{
+	.name = "media-cpu-dai",
+	.ops = &sst_media_dai_ops,
+	.playback = {
+		.stream_name = "Headset Playback",
+		.channels_min = SST_STEREO,
+		.channels_max = SST_STEREO,
+		.rates = SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+	},
+	.capture = {
+		.stream_name = "Headset Capture",
+		.channels_min = 1,
+		.channels_max = 2,
+		.rates = SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+	},
+},
+{
+	.name = "compress-cpu-dai",
+	.compress_dai = 1,
+	.playback = {
+		.stream_name = "Compress Playback",
+		.channels_min = SST_STEREO,
+		.channels_max = SST_STEREO,
+		.rates = SNDRV_PCM_RATE_48000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+	},
+},
+/*BE CPU  Dais */
+{
+	.name = "ssp0-port",
+	.playback = {
+		.stream_name = "ssp0 Tx",
+		.channels_min = SST_STEREO,
+		.channels_max = SST_STEREO,
+		.rates = SNDRV_PCM_RATE_48000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+	},
+	.capture = {
+		.stream_name = "ssp0 Rx",
+		.channels_min = SST_STEREO,
+		.channels_max = SST_STEREO,
+		.rates = SNDRV_PCM_RATE_48000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+	},
+},
+{
+	.name = "ssp1-port",
+	.playback = {
+		.stream_name = "ssp1 Tx",
+		.channels_min = SST_STEREO,
+		.channels_max = SST_STEREO,
+		.rates = SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_48000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+	},
+	.capture = {
+		.stream_name = "ssp1 Rx",
+		.channels_min = SST_STEREO,
+		.channels_max = SST_STEREO,
+		.rates = SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_48000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+	},
+},
+{
+	.name = "ssp2-port",
+	.playback = {
+		.stream_name = "ssp2 Tx",
+		.channels_min = SST_STEREO,
+		.channels_max = SST_STEREO,
+		.rates = SNDRV_PCM_RATE_48000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+	},
+	.capture = {
+		.stream_name = "ssp2 Rx",
+		.channels_min = SST_STEREO,
+		.channels_max = SST_STEREO,
+		.rates = SNDRV_PCM_RATE_48000,
+		.formats = SNDRV_PCM_FMTBIT_S16_LE,
+	},
+},
+};
+
 static int sst_platform_open(struct snd_pcm_substream *substream)
 {
 	struct snd_pcm_runtime *runtime;
Signature · 1 line
1.9.0
maintainer
#2 lore raw

Re: [v4 01/12] ASoC: Intel: mfld-pcm: add FE and BE ops

Quoted 4 lines · Subhransu S. Prusty

From: Vinod Koul <[email protected]>

Now that we have added code for managing DSP pipelines we need to add the code for DSPs FrontEnd and Backend dai.

This would be a lot easier to apply if the changelog were clearer, I can't tell how we get from having code to manage the pipelines to needing or wanting this code. Is the current code broken and this a bug fix or is this preparing for future changes? The changelog says that this is adding ops but the diff is adding DAIs none of which have any ops defined.

I'm also a bit surprised to see this without anything to add routes between the front and back ends or updates to the machine drivers for new DAI names - won't this cause problems for the machine drivers?

#3 lore raw

PATCH v4 2/12 ASoC: Intel: mrfld: set private data for cpu-dai

In reply to Subhransu S. Prusty

We set the driver private data for media dai so that we can use in media operations

---
 sound/soc/intel/sst-mfld-platform-pcm.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
sound/soc/intel/sst-mfld-platform-pcm.c +13 -5
index 364034024cee..821c9970548c 100644
@@ -223,7 +223,7 @@ int sst_fill_stream_params(void *substream,
 }
 
 static int sst_platform_alloc_stream(struct snd_pcm_substream *substream,
-		struct snd_soc_platform *platform)
+		struct snd_soc_dai *dai)
 {
 	struct sst_runtime_stream *stream =
 			substream->runtime->private_data;
@@ -231,7 +231,7 @@ static int sst_platform_alloc_stream(struct snd_pcm_substream *substream,
 	struct snd_sst_params str_params = {0};
 	struct snd_sst_alloc_params_ext alloc_params = {0};
 	int ret_val = 0;
-	struct sst_data *ctx = snd_soc_platform_get_drvdata(platform);
+	struct sst_data *ctx = snd_soc_dai_get_drvdata(dai);
 
 	/* set codec params and inform SST driver the same */
 	sst_fill_pcm_params(substream, &param);
@@ -347,10 +347,10 @@ static void sst_media_close(struct snd_pcm_substream *substream,
 	kfree(stream);
 }
 
-static inline unsigned int get_current_pipe_id(struct snd_soc_platform *platform,
+static inline unsigned int get_current_pipe_id(struct snd_soc_dai *dai,
 					       struct snd_pcm_substream *substream)
 {
-	struct sst_data *sst = snd_soc_platform_get_drvdata(platform);
+	struct sst_data *sst = snd_soc_dai_get_drvdata(dai);
 	struct sst_dev_stream_map *map = sst->pdata->pdev_strm_map;
 	struct sst_runtime_stream *stream =
 			substream->runtime->private_data;
@@ -376,7 +376,7 @@ static int sst_media_prepare(struct snd_pcm_substream *substream,
 		return ret_val;
 	}
 
-	ret_val = sst_platform_alloc_stream(substream, dai->platform);
+	ret_val = sst_platform_alloc_stream(substream, dai);
 	if (ret_val <= 0)
 		return ret_val;
 	snprintf(substream->pcm->id, sizeof(substream->pcm->id),
@@ -412,8 +412,16 @@ static struct snd_soc_dai_ops sst_media_dai_ops = {
 	.hw_free = sst_media_hw_free,
 };
 
+static int sst_media_dai_probe(struct snd_soc_dai *cpu_dai)
+{
+	struct sst_data *sst = dev_get_drvdata(cpu_dai->dev);
+
+	snd_soc_dai_set_drvdata(cpu_dai, sst);
+	return 0;
+}
 static struct snd_soc_dai_driver sst_platform_dai[] = {
 {
+	.probe = sst_media_dai_probe,
 	.name = "media-cpu-dai",
 	.ops = &sst_media_dai_ops,
 	.playback = {
Signature · 1 line
1.9.0
maintainer
#4 lore raw

Re: [v4 02/12] ASoC: Intel: mrfld: set private data for cpu-dai

Quoted 2 lines · Subhransu S. Prusty

We set the driver private data for media dai so that we can use in media operations

This is another one where making the changelog clearer - as far as I can tell what this is actually doing is moving the existing private data from being per platform to being per DAI. That actually seems OK and I would've applied this but it looks like it depends on patch 1.

This lack of clarity is a frequent issue with both of these DSP serieses, it's really slowing down review since they're quite big and hard to read.

sound/soc/intel/sst-mfld-platform-pcm.c static struct snd_soc_dai_ops sst_media_dai_ops = { · line 422

Quoted 8 lines
sound/soc/intel/sst-mfld-platform-pcm.c +7 -0
+static int sst_media_dai_probe(struct snd_soc_dai *cpu_dai)
+{
+	struct sst_data *sst = dev_get_drvdata(cpu_dai->dev);
+
+	snd_soc_dai_set_drvdata(cpu_dai, sst);
+	return 0;
+}
 static struct snd_soc_dai_driver sst_platform_dai[] = {

Missing blank line here - this is a frequent issue with this code.

#5 lore raw

Re: [alsa-devel] [v4 02/12] ASoC: Intel: mrfld: set private data for cpu-dai

Quoted 10 lines · Mark Brown
Quoted 2 lines · Subhransu S. Prusty

We set the driver private data for media dai so that we can use in media operations

This is another one where making the changelog clearer - as far as I can tell what this is actually doing is moving the existing private data from being per platform to being per DAI. That actually seems OK and I would've applied this but it looks like it depends on patch 1.

Will take care.

Quoted 14 lines

This lack of clarity is a frequent issue with both of these DSP serieses, it's really slowing down review since they're quite big and hard to read.

sound/soc/intel/sst-mfld-platform-pcm.c static struct snd_soc_dai_ops sst_media_dai_ops = { · line 422

Quoted 8 lines
sound/soc/intel/sst-mfld-platform-pcm.c +7 -0
+static int sst_media_dai_probe(struct snd_soc_dai *cpu_dai)
+{
+	struct sst_data *sst = dev_get_drvdata(cpu_dai->dev);
+
+	snd_soc_dai_set_drvdata(cpu_dai, sst);
+	return 0;
+}
 static struct snd_soc_dai_driver sst_platform_dai[] = {

Missing blank line here - this is a frequent issue with this code.

Signature · 4 lines
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#6 lore raw

Re: [v4 02/12] ASoC: Intel: mrfld: set private data for cpu-dai

In reply to Mark Brown
Quoted 10 lines · Mark Brown
Quoted 2 lines · Subhransu S. Prusty

We set the driver private data for media dai so that we can use in media operations

This is another one where making the changelog clearer - as far as I can tell what this is actually doing is moving the existing private data from being per platform to being per DAI. That actually seems OK and I would've applied this but it looks like it depends on patch 1.

Will take care.

Quoted 14 lines

This lack of clarity is a frequent issue with both of these DSP serieses, it's really slowing down review since they're quite big and hard to read.

sound/soc/intel/sst-mfld-platform-pcm.c static struct snd_soc_dai_ops sst_media_dai_ops = { · line 422

Quoted 8 lines
sound/soc/intel/sst-mfld-platform-pcm.c +7 -0
+static int sst_media_dai_probe(struct snd_soc_dai *cpu_dai)
+{
+	struct sst_data *sst = dev_get_drvdata(cpu_dai->dev);
+
+	snd_soc_dai_set_drvdata(cpu_dai, sst);
+	return 0;
+}
 static struct snd_soc_dai_driver sst_platform_dai[] = {

Missing blank line here - this is a frequent issue with this code.

#7 lore raw

Re: [v4 02/12] ASoC: Intel: mrfld: set private data for cpu-dai

In reply to Subhransu S. Prusty

[...]

sound/soc/intel/sst-mfld-platform-pcm.c static struct snd_soc_dai_ops sst_media_dai_ops = { · line 419

Quoted 5 lines
sound/soc/intel/sst-mfld-platform-pcm.c +5 -0
+static int sst_media_dai_probe(struct snd_soc_dai *cpu_dai)
+{
+	struct sst_data *sst = dev_get_drvdata(cpu_dai->dev);
+
+	snd_soc_dai_set_drvdata(cpu_dai, sst);

snd_soc_dai_set_drvdata does dev_set_drvdata(dai->dev, data) internally, so this function does:

	dev_set_drvdata(cpu_dai->dev, dev_get_drvdata(cpu_dai->dev));

That's pretty much a noop.

Quoted 9 lines
sound/soc/intel/sst-mfld-platform-pcm.c +3 -0
+	return 0;
+}
  static struct snd_soc_dai_driver sst_platform_dai[] = {
  {
+	.probe = sst_media_dai_probe,
  	.name = "media-cpu-dai",
  	.ops = &sst_media_dai_ops,
  	.playback = {
#8 lore raw

Re: [alsa-devel] [v4 02/12] ASoC: Intel: mrfld: set private data for cpu-dai

Quoted 10 lines · Lars-Peter Clausen

[...]

sound/soc/intel/sst-mfld-platform-pcm.c static struct snd_soc_dai_ops sst_media_dai_ops = { · line 419

Quoted 5 lines
sound/soc/intel/sst-mfld-platform-pcm.c +5 -0
+static int sst_media_dai_probe(struct snd_soc_dai *cpu_dai)
+{
+	struct sst_data *sst = dev_get_drvdata(cpu_dai->dev);
+
+	snd_soc_dai_set_drvdata(cpu_dai, sst);

snd_soc_dai_set_drvdata does dev_set_drvdata(dai->dev, data) internally, so this function does:

Quoted 4 lines
	dev_set_drvdata(cpu_dai->dev, dev_get_drvdata(cpu_dai->dev));

That's pretty much a noop.

Agree. Intention was to use snd_soc_dai_* API. Anyway will remove and use dev_get_drvdata(dai->dev) directly.

Signature · 4 lines
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#9 lore raw

Re: [v4 02/12] ASoC: Intel: mrfld: set private data for cpu-dai

Quoted 11 lines · Subhransu S. Prusty
Quoted 10 lines · Lars-Peter Clausen

[...]

sound/soc/intel/sst-mfld-platform-pcm.c static struct snd_soc_dai_ops sst_media_dai_ops = { · line 419

Quoted 5 lines
sound/soc/intel/sst-mfld-platform-pcm.c +5 -0
+static int sst_media_dai_probe(struct snd_soc_dai *cpu_dai)
+{
+	struct sst_data *sst = dev_get_drvdata(cpu_dai->dev);
+
+	snd_soc_dai_set_drvdata(cpu_dai, sst);

snd_soc_dai_set_drvdata does dev_set_drvdata(dai->dev, data) internally, so this function does:

Quoted 8 lines
Quoted 4 lines
	dev_set_drvdata(cpu_dai->dev, dev_get_drvdata(cpu_dai->dev));

That's pretty much a noop.

Agree. Intention was to use snd_soc_dai_* API. Anyway will remove and use dev_get_drvdata(dai->dev) directly.

It's totally fine to use snd_soc_dai_get_drvdata() through the driver. It's just that this probe function does nothing and can be removed.

#10 lore raw

Re: [v4 02/12] ASoC: Intel: mrfld: set private data for cpu-dai

In reply to Lars-Peter Clausen
Quoted 10 lines · Lars-Peter Clausen

[...]

sound/soc/intel/sst-mfld-platform-pcm.c static struct snd_soc_dai_ops sst_media_dai_ops = { · line 419

Quoted 5 lines
sound/soc/intel/sst-mfld-platform-pcm.c +5 -0
+static int sst_media_dai_probe(struct snd_soc_dai *cpu_dai)
+{
+	struct sst_data *sst = dev_get_drvdata(cpu_dai->dev);
+
+	snd_soc_dai_set_drvdata(cpu_dai, sst);

snd_soc_dai_set_drvdata does dev_set_drvdata(dai->dev, data) internally, so this function does:

Quoted 4 lines
	dev_set_drvdata(cpu_dai->dev, dev_get_drvdata(cpu_dai->dev));

That's pretty much a noop.

Agree. Intention was to use snd_soc_dai_* API. Anyway will remove and use dev_get_drvdata(dai->dev) directly.

#11 lore raw

PATCH v4 3/12 ASoC: intel: mfld-pcm: don't call trigger ops to DSP for internal streams

In reply to Subhransu S. Prusty

From: Vinod Koul <[email protected]>

For internal stream i.e. BE we have don't need trigger ops as that would be handled by DAPM for us in subsequent patches

---
 sound/soc/intel/sst-mfld-platform-pcm.c | 2 ++
 1 file changed, 2 insertions(+)
sound/soc/intel/sst-mfld-platform-pcm.c +2 -0
index 821c9970548c..a36c5bf67eff 100644
@@ -524,6 +524,8 @@ static int sst_platform_pcm_trigger(struct snd_pcm_substream *substream,
 	int status;
 
 	pr_debug("sst_platform_pcm_trigger called\n");
+	if (substream->pcm->internal)
+		return 0;
 	stream = substream->runtime->private_data;
 	str_id = stream->stream_info.str_id;
 	switch (cmd) {
Signature · 1 line
1.9.0
#12 lore raw

PATCH v4 4/12 ASoC: Intel: add mrfld DSP defines

In reply to Subhransu S. Prusty

From: Vinod Koul <[email protected]>

We define the DSP commands,structures here which will be used to send the IPCs

---
 sound/soc/intel/Makefile                |   3 +-
 sound/soc/intel/sst-atom-controls.c     |  39 +++++
 sound/soc/intel/sst-atom-controls.h     | 286 +++++++++++++++++++++++++++++++-
 sound/soc/intel/sst-mfld-platform-pcm.c |   8 +-
 sound/soc/intel/sst-mfld-platform.h     |   3 +
 5 files changed, 335 insertions(+), 4 deletions(-)
 create mode 100644 sound/soc/intel/sst-atom-controls.c
sound/soc/intel/Makefile +2 -1
index 7acbfc43a0c6..f841786dad15 100644
@@ -2,7 +2,8 @@
 snd-soc-sst-dsp-objs := sst-dsp.o sst-firmware.o
 snd-soc-sst-acpi-objs := sst-acpi.o
 
-snd-soc-sst-mfld-platform-objs := sst-mfld-platform-pcm.o sst-mfld-platform-compress.o
+snd-soc-sst-mfld-platform-objs := sst-mfld-platform-pcm.o \
+	sst-mfld-platform-compress.o sst-atom-controls.o
 snd-soc-mfld-machine-objs := mfld_machine.o
 
 obj-$(CONFIG_SND_SST_MFLD_PLATFORM) += snd-soc-sst-mfld-platform.o
sound/soc/intel/sst-atom-controls.c new file +39 -0
new file mode 100644
index 000000000000..ace3c4a59b14
@@ -0,0 +1,39 @@
+/*
+ *  sst-atom-controls.c - Intel MID Platform driver DPCM ALSA controls for Mrfld
+ *
+ *  Copyright (C) 2013-14 Intel Corp
+ *  Author: Omair Mohammed Abdullah <[email protected]>
+ *	Vinod Koul <[email protected]>
+ *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/slab.h>
+#include <sound/soc.h>
+#include <sound/tlv.h>
+#include "sst-mfld-platform.h"
+#include "sst-atom-controls.h"
+
+int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
+{
+	int ret = 0;
+	struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
+
+	drv->byte_stream = devm_kzalloc(platform->dev,
+					SST_MAX_BIN_BYTES, GFP_KERNEL);
+	if (!drv->byte_stream)
+		return -ENOMEM;
+
+	return ret;
+}
sound/soc/intel/sst-atom-controls.h +284 -2

301 lines not on this page · raw message

sound/soc/intel/sst-mfld-platform-pcm.c +7 -1
index a36c5bf67eff..c71893ce3d93 100644
@@ -615,7 +615,13 @@ static int sst_pcm_new(struct snd_soc_pcm_runtime *rtd)
 	return retval;
 }
 
-static struct snd_soc_platform_driver sst_soc_platform_drv = {
+static int sst_soc_probe(struct snd_soc_platform *platform)
+{
+	return sst_dsp_init_v2_dpcm(platform);
+}
+
+static struct snd_soc_platform_driver sst_soc_platform_drv  = {
+	.probe		= sst_soc_probe,
 	.ops		= &sst_platform_ops,
 	.compr_ops	= &sst_platform_compr_ops,
 	.pcm_new	= sst_pcm_new,
sound/soc/intel/sst-mfld-platform.h +3 -0
index d4c28b8fb471..faaba10c1dff 100644
@@ -143,6 +143,8 @@ struct sst_device {
 };
 
 struct sst_data;
+
+int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform);
 void sst_set_stream_status(struct sst_runtime_stream *stream, int state);
 int sst_fill_stream_params(void *substream, const struct sst_data *ctx,
 			   struct snd_sst_params *str_params, bool is_compress);
@@ -157,6 +159,7 @@ struct sst_algo_int_control_v2 {
 struct sst_data {
 	struct platform_device *pdev;
 	struct sst_platform_data *pdata;
+	char *byte_stream;
 	struct mutex lock;
 };
 int sst_register_dsp(struct sst_device *sst);
Signature · 1 line
1.9.0
maintainer Applied
#13 lore raw

Re: [v4 04/12] ASoC: Intel: add mrfld DSP defines

Quoted 3 lines · Subhransu S. Prusty

From: Vinod Koul <[email protected]>

We define the DSP commands,structures here which will be used to send the IPCs

Applied, thanks.

#14 lore raw

PATCH v4 5/12 ASoC: Intel: mrfld: add bytes control for modules

In reply to Subhransu S. Prusty

From: Vinod Koul <[email protected]>

This patch add support for various modules like eq etc for mrfld DSP. All these modules will be exposed to usermode as bytes controls.

---
 sound/soc/intel/sst-atom-controls.c | 172 ++++++++++++++++++++++++++++++++++++
 sound/soc/intel/sst-atom-controls.h | 130 +++++++++++++++++++++++++++
 2 files changed, 302 insertions(+)
sound/soc/intel/sst-atom-controls.c +172 -0
index ace3c4a59b14..9f41741ddf8a 100644
@@ -25,6 +25,176 @@
 #include "sst-mfld-platform.h"
 #include "sst-atom-controls.h"
 
+static inline void sst_fill_byte_control(char *param,
+					 u8 ipc_msg, u8 block,
+					 u8 task_id, u8 pipe_id,
+					 u16 len, void *cmd_data)
+{
+
+	struct snd_sst_bytes_v2 *byte_data = (struct snd_sst_bytes_v2 *)param;
+
+	byte_data->type = SST_CMD_BYTES_SET;
+	byte_data->ipc_msg = ipc_msg;
+	byte_data->block = block;
+	byte_data->task_id = task_id;
+	byte_data->pipe_id = pipe_id;
+
+	if (len > SST_MAX_BIN_BYTES - sizeof(*byte_data)) {
+		WARN(1, "%s: command length too big (%u)", __func__, len); /* this happens only if code is wrong */
+		len = SST_MAX_BIN_BYTES - sizeof(*byte_data);
+	}
+	byte_data->len = len;
+	memcpy(byte_data->bytes, cmd_data, len);
+	print_hex_dump_bytes("writing to lpe: ", DUMP_PREFIX_OFFSET,
+			     byte_data, len + sizeof(*byte_data));
+}
+
+static int sst_fill_and_send_cmd_unlocked(struct sst_data *drv,
+				 u8 ipc_msg, u8 block, u8 task_id, u8 pipe_id,
+				 void *cmd_data, u16 len)
+{
+	sst_fill_byte_control(drv->byte_stream, ipc_msg, block, task_id, pipe_id,
+			      len, cmd_data);
+	return sst->ops->send_byte_stream(sst->dev,
+			(struct snd_sst_bytes_v2 *)drv->byte_stream);
+}
+
+/**
+ * sst_fill_and_send_cmd - generate the IPC message and send it to the FW
+ * @ipc_msg:	type of IPC (CMD, SET_PARAMS, GET_PARAMS)
+ * @cmd_data:	the IPC payload
+ */
+static int sst_fill_and_send_cmd(struct sst_data *drv,
+				 u8 ipc_msg, u8 block, u8 task_id, u8 pipe_id,
+				 void *cmd_data, u16 len)
+{
+	int ret;
+
+	mutex_lock(&drv->lock);
+	ret = sst_fill_and_send_cmd_unlocked(drv, ipc_msg, block, task_id, pipe_id,
+					     cmd_data, len);
+	mutex_unlock(&drv->lock);
+
+	return ret;
+}
+
+static void sst_send_algo_cmd(struct sst_data *drv,
+			      struct sst_algo_control *bc)
+{
+	int len;
+	struct sst_cmd_set_params *cmd;
+
+	if (bc->params == NULL)
+		return;
+
+	/* bc->max includes sizeof algos + length field */
+	len = sizeof(cmd->dst) + sizeof(cmd->command_id) + bc->max;
+
+	cmd = kzalloc(len, GFP_KERNEL);
+	if (cmd == NULL)
+		return;
+
+	SST_FILL_DESTINATION(2, cmd->dst, bc->pipe_id, bc->module_id);
+	cmd->command_id = bc->cmd_id;
+	memcpy(cmd->params, bc->params, bc->max);
+
+	sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_SET_PARAMS,
+				SST_FLAG_BLOCKED, bc->task_id, 0, cmd, len);
+	kfree(cmd);
+}
+
+static int sst_algo_bytes_ctl_info(struct snd_kcontrol *kcontrol,
+			    struct snd_ctl_elem_info *uinfo)
+{
+	struct sst_algo_control *bc = (void *)kcontrol->private_value;
+	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
+	uinfo->count = bc->max;
+
+	/* allocate space to cache the algo parameters in the driver */
+	if (bc->params == NULL) {
+		bc->params = devm_kzalloc(component->dev, bc->max, GFP_KERNEL);
+		if (bc->params == NULL)
+			return -ENOMEM;
+	}
+	return 0;
+}
+
+static int sst_algo_control_get(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *ucontrol)
+{
+	struct sst_algo_control *bc = (void *)kcontrol->private_value;
+
+	switch (bc->type) {
+	case SST_ALGO_PARAMS:
+		if (bc->params)
+			memcpy(ucontrol->value.bytes.data, bc->params, bc->max);
+		break;
+	case SST_ALGO_BYPASS:
+		ucontrol->value.integer.value[0] = bc->bypass ? 1 : 0;
+		pr_debug("%s: bypass  %d\n", __func__, bc->bypass);
+		break;
+	default:
+		pr_err("Invalid Input- algo type:%d\n", bc->type);
+		return -EINVAL;
+
+	}
+	return 0;
+}
+
+static int sst_algo_control_set(struct snd_kcontrol *kcontrol,
+				struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_platform *platform =  snd_soc_kcontrol_platform(kcontrol);
+	struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
+	struct sst_algo_control *bc = (void *)kcontrol->private_value;
+
+	pr_debug("in %s control_name=%s\n", __func__, kcontrol->id.name);
+	mutex_lock(&drv->lock);
+	switch (bc->type) {
+	case SST_ALGO_PARAMS:
+		if (bc->params)
+			memcpy(bc->params, ucontrol->value.bytes.data, bc->max);
+		break;
+	case SST_ALGO_BYPASS:
+		bc->bypass = !!ucontrol->value.integer.value[0];
+		break;
+	default:
+		mutex_unlock(&drv->lock);
+		pr_err("Invalid Input- algo type:%d\n", bc->type);
+		return -EINVAL;
+	}
+	/*if pipe is enabled, need to send the algo params from here */
+	if (bc->w && bc->w->power)
+		sst_send_algo_cmd(drv, bc);
+	mutex_unlock(&drv->lock);
+
+	return 0;
+}
+
+static const struct snd_kcontrol_new sst_algo_controls[] = {
+	SST_ALGO_KCONTROL_BYTES("media_loop1_out", "fir", 272, SST_MODULE_ID_FIR_24,
+		 SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_VB_SET_FIR),
+	SST_ALGO_KCONTROL_BYTES("media_loop1_out", "iir", 300, SST_MODULE_ID_IIR_24,
+		SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
+	SST_ALGO_KCONTROL_BYTES("media_loop1_out", "mdrp", 286, SST_MODULE_ID_MDRP,
+		SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_SET_MDRP),
+	SST_ALGO_KCONTROL_BYTES("media_loop2_out", "fir", 272, SST_MODULE_ID_FIR_24,
+		SST_PATH_INDEX_MEDIA_LOOP2_OUT, 0, SST_TASK_SBA, SBA_VB_SET_FIR),
+	SST_ALGO_KCONTROL_BYTES("media_loop2_out", "iir", 300, SST_MODULE_ID_IIR_24,
+		SST_PATH_INDEX_MEDIA_LOOP2_OUT, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
+	SST_ALGO_KCONTROL_BYTES("media_loop2_out", "mdrp", 286, SST_MODULE_ID_MDRP,
+		SST_PATH_INDEX_MEDIA_LOOP2_OUT, 0, SST_TASK_SBA, SBA_SET_MDRP),
+	SST_ALGO_KCONTROL_BYTES("sprot_loop_out", "lpro", 192, SST_MODULE_ID_SPROT,
+		SST_PATH_INDEX_SPROT_LOOP_OUT, 0, SST_TASK_SBA, SBA_VB_LPRO),
+	SST_ALGO_KCONTROL_BYTES("codec_in0", "dcr", 52, SST_MODULE_ID_FILT_DCR,
+		SST_PATH_INDEX_CODEC_IN0, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
+	SST_ALGO_KCONTROL_BYTES("codec_in1", "dcr", 52, SST_MODULE_ID_FILT_DCR,
+		SST_PATH_INDEX_CODEC_IN1, 0, SST_TASK_SBA, SBA_VB_SET_IIR),
+
+};
+
 int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
 {
 	int ret = 0;
@@ -35,5 +205,7 @@ int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
 	if (!drv->byte_stream)
 		return -ENOMEM;
 
+	snd_soc_add_platform_controls(platform, sst_algo_controls,
+			ARRAY_SIZE(sst_algo_controls));
 	return ret;
 }
sound/soc/intel/sst-atom-controls.h +130 -0

134 lines not on this page · raw message

Signature · 1 line
1.9.0
maintainer
#15 lore raw

Re: [v4 05/12] ASoC: Intel: mrfld: add bytes control for modules

Quoted 4 lines · Subhransu S. Prusty

From: Vinod Koul <[email protected]>

This patch add support for various modules like eq etc for mrfld DSP. All these modules will be exposed to usermode as bytes controls.

Indeed they are actually exposed by this code.

sound/soc/intel/sst-atom-controls.c line 31

Quoted 4 lines
sound/soc/intel/sst-atom-controls.c +4 -0
+static inline void sst_fill_byte_control(char *param,
+					 u8 ipc_msg, u8 block,
+					 u8 task_id, u8 pipe_id,
+					 u16 len, void *cmd_data)

Let the compiler figure out if this should be inline, this doesn't seem something that should obviously be inline and isn't in a header.

sound/soc/intel/sst-atom-controls.c line 45

Quoted 4 lines
sound/soc/intel/sst-atom-controls.c +4 -0
+	if (len > SST_MAX_BIN_BYTES - sizeof(*byte_data)) {
+		WARN(1, "%s: command length too big (%u)", __func__, len); /* this happens only if code is wrong */
+		len = SST_MAX_BIN_BYTES - sizeof(*byte_data);
+	}

Coding style, 80 columns. Since the only caller can return an error code you could do that here too.

sound/soc/intel/sst-atom-controls.c line 60

Quoted 9 lines
sound/soc/intel/sst-atom-controls.c +9 -0
+static int sst_fill_and_send_cmd_unlocked(struct sst_data *drv,
+				 u8 ipc_msg, u8 block, u8 task_id, u8 pipe_id,
+				 void *cmd_data, u16 len)
+{
+	sst_fill_byte_control(drv->byte_stream, ipc_msg, block, task_id, pipe_id,
+			      len, cmd_data);
+	return sst->ops->send_byte_stream(sst->dev,
+			(struct snd_sst_bytes_v2 *)drv->byte_stream);
+}

There's a lot of casting going on in this code.

Quoted 7 lines
sound/soc/intel/sst-atom-controls.c +7 -0
+static int sst_algo_bytes_ctl_info(struct snd_kcontrol *kcontrol,
+			    struct snd_ctl_elem_info *uinfo)
+{
+	struct sst_algo_control *bc = (void *)kcontrol->private_value;
+	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;

sound/soc/intel/sst-atom-controls.c line 122

Quoted 10 lines
sound/soc/intel/sst-atom-controls.c +10 -0
+	uinfo->count = bc->max;
+
+	/* allocate space to cache the algo parameters in the driver */
+	if (bc->params == NULL) {
+		bc->params = devm_kzalloc(component->dev, bc->max, GFP_KERNEL);
+		if (bc->params == NULL)
+			return -ENOMEM;
+	}
+	return 0;
+}

I wouldn't expect an info call to be allocating anything - why is it doing that? It's not looking at the alocated data except to see if the allocation succeeded. What happens if someone manages to do a get or set without having first done an info and why aren't we doing any allocation on initialisation?

sound/soc/intel/sst-atom-controls.c line 137

Quoted 4 lines
sound/soc/intel/sst-atom-controls.c +4 -0
+	case SST_ALGO_BYPASS:
+		ucontrol->value.integer.value[0] = bc->bypass ? 1 : 0;
+		pr_debug("%s: bypass  %d\n", __func__, bc->bypass);
+		break;

Is bypass not a boolean value already, and shouldn't these just end up with controls called something "Switch" - they look to be just directly usable switches?

Review

Quoted 2 lines
(quoted diff) +2 -0
+	default:
+		pr_err("Invalid Input- algo type:%d\n", bc->type);

dev_err().

sound/soc/intel/sst-atom-controls.c line 159

Quoted 5 lines
sound/soc/intel/sst-atom-controls.c +5 -0
+	switch (bc->type) {
+	case SST_ALGO_PARAMS:
+		if (bc->params)
+			memcpy(bc->params, ucontrol->value.bytes.data, bc->max);
+		break;

So if bc->params didn't get allocated somehow we just silently drop the set?

sound/soc/intel/sst-atom-controls.c line 170

Quoted 3 lines
sound/soc/intel/sst-atom-controls.c +3 -0
+	/*if pipe is enabled, need to send the algo params from here */
+	if (bc->w && bc->w->power)
+		sst_send_algo_cmd(drv, bc);

sst_send_algo_cmd() should be returning an eror code (it doesn't but the functions it calls can).

I'm not seeing any code to restore these controls on power up here.

#16 lore raw

Re: [alsa-devel] [v4 05/12] ASoC: Intel: mrfld: add bytes control for modules

Quoted 9 lines · Mark Brown
Quoted 4 lines · Subhransu S. Prusty

From: Vinod Koul <[email protected]>

This patch add support for various modules like eq etc for mrfld DSP. All these modules will be exposed to usermode as bytes controls.

Indeed they are actually exposed by this code.

Quoted 7 lines

sound/soc/intel/sst-atom-controls.c line 31

Quoted 4 lines
sound/soc/intel/sst-atom-controls.c +4 -0
+static inline void sst_fill_byte_control(char *param,
+					 u8 ipc_msg, u8 block,
+					 u8 task_id, u8 pipe_id,
+					 u16 len, void *cmd_data)

Let the compiler figure out if this should be inline, this doesn't seem something that should obviously be inline and isn't in a header.

Ok

Quoted 8 lines

sound/soc/intel/sst-atom-controls.c line 45

Quoted 5 lines
sound/soc/intel/sst-atom-controls.c +4 -0
+	if (len > SST_MAX_BIN_BYTES - sizeof(*byte_data)) {
+		WARN(1, "%s: command length too big (%u)", __func__, len); /* this happens only if code is wrong */
+		len = SST_MAX_BIN_BYTES - sizeof(*byte_data);
+	}

Coding style, 80 columns. Since the only caller can return an error code you could do that here too.

Yes.

Quoted 12 lines

sound/soc/intel/sst-atom-controls.c line 60

Quoted 10 lines
sound/soc/intel/sst-atom-controls.c +9 -0
+static int sst_fill_and_send_cmd_unlocked(struct sst_data *drv,
+				 u8 ipc_msg, u8 block, u8 task_id, u8 pipe_id,
+				 void *cmd_data, u16 len)
+{
+	sst_fill_byte_control(drv->byte_stream, ipc_msg, block, task_id, pipe_id,
+			      len, cmd_data);
+	return sst->ops->send_byte_stream(sst->dev,
+			(struct snd_sst_bytes_v2 *)drv->byte_stream);
+}

There's a lot of casting going on in this code.

Not required. Should have been removed.

Quoted 16 lines
Quoted 16 lines
sound/soc/intel/sst-atom-controls.c +15 -0
+static int sst_algo_bytes_ctl_info(struct snd_kcontrol *kcontrol,
+			    struct snd_ctl_elem_info *uinfo)
+{
+	struct sst_algo_control *bc = (void *)kcontrol->private_value;
+	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
+	uinfo->count = bc->max;
+
+	/* allocate space to cache the algo parameters in the driver */
+	if (bc->params == NULL) {
+		bc->params = devm_kzalloc(component->dev, bc->max, GFP_KERNEL);
+		if (bc->params == NULL)
+			return -ENOMEM;
+	}
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return 0;
+}

I wouldn't expect an info call to be allocating anything - why is it doing that? It's not looking at the alocated data except to see if the allocation succeeded. What happens if someone manages to do a get or set without having first done an info and why aren't we doing any allocation on initialisation?

Will move after control initialization.

Quoted 9 lines

sound/soc/intel/sst-atom-controls.c line 137

Quoted 5 lines
sound/soc/intel/sst-atom-controls.c +4 -0
+	case SST_ALGO_BYPASS:
+		ucontrol->value.integer.value[0] = bc->bypass ? 1 : 0;
+		pr_debug("%s: bypass  %d\n", __func__, bc->bypass);
+		break;

Is bypass not a boolean value already, and shouldn't these just end up with controls called something "Switch" - they look to be just directly usable switches?

Actually BYPASS is not required. Will remove.

Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+	default:
+		pr_err("Invalid Input- algo type:%d\n", bc->type);

dev_err().

We are using pr_err() in all the error conditions for our driver. If it is really required to change, we can submit a single patch to change to dev_err() once the patches are merged.

Quoted 9 lines

sound/soc/intel/sst-atom-controls.c line 159

Quoted 6 lines
sound/soc/intel/sst-atom-controls.c +5 -0
+	switch (bc->type) {
+	case SST_ALGO_PARAMS:
+		if (bc->params)
+			memcpy(bc->params, ucontrol->value.bytes.data, bc->max);
+		break;

So if bc->params didn't get allocated somehow we just silently drop the set?

With above params initialization changes this check will not be required any more.

Quoted 9 lines

sound/soc/intel/sst-atom-controls.c line 170

Quoted 4 lines
sound/soc/intel/sst-atom-controls.c +3 -0
+	/*if pipe is enabled, need to send the algo params from here */
+	if (bc->w && bc->w->power)
+		sst_send_algo_cmd(drv, bc);

sst_send_algo_cmd() should be returning an eror code (it doesn't but the functions it calls can).

I'm not seeing any code to restore these controls on power up here.

Will take care of the return code.

sst_find_and_send_pipe_algo takes care of restoring the controls on power up.

Signature · 4 lines
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#17 lore raw

Re: [alsa-devel] [v4 05/12] ASoC: Intel: mrfld: add bytes control for modules

Quoted 29 lines · Subhransu S. Prusty
Quoted 19 lines · Mark Brown
Quoted 17 lines · Subhransu S. Prusty

From: Vinod Koul <[email protected]>

sound/soc/intel/sst-atom-controls.c +15 -0
+static int sst_algo_bytes_ctl_info(struct snd_kcontrol *kcontrol,
+			    struct snd_ctl_elem_info *uinfo)
+{
+	struct sst_algo_control *bc = (void *)kcontrol->private_value;
+	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
+	uinfo->count = bc->max;
+
+	/* allocate space to cache the algo parameters in the driver */
+	if (bc->params == NULL) {
+		bc->params = devm_kzalloc(component->dev, bc->max, GFP_KERNEL);
+		if (bc->params == NULL)
+			return -ENOMEM;
+	}
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return 0;
+}

I wouldn't expect an info call to be allocating anything - why is it doing that? It's not looking at the alocated data except to see if the allocation succeeded. What happens if someone manages to do a get or set without having first done an info and why aren't we doing any allocation on initialisation?

Quoted 1 line

Will move after control initialization.

As I have to initialize the params, and if it's done in probe after control creation, it's required to iterate over the controls list and match certain pattern to find the control and then initialize. This doesn't look elegant. Instead I would prefer adding an init callback in the control to do this operation. What do you recommend?

Signature · 4 lines
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
maintainer
#18 lore raw

Re: [v4 05/12] ASoC: Intel: mrfld: add bytes control for modules

Quoted 8 lines · Subhransu S. Prusty
Quoted 5 lines · Subhransu S. Prusty
Quoted 5 lines

I wouldn't expect an info call to be allocating anything - why is it doing that? It's not looking at the alocated data except to see if the allocation succeeded. What happens if someone manages to do a get or set without having first done an info and why aren't we doing any allocation on initialisation?

Quoted 7 lines
Quoted 1 line

Will move after control initialization.

As I have to initialize the params, and if it's done in probe after control creation, it's required to iterate over the controls list and match certain pattern to find the control and then initialize. This doesn't look elegant. Instead I would prefer adding an init callback in the control to do this operation. What do you recommend?

Something like that sounds reasonable, or doing it when writing to the control - the point is that info() is a terrible place to do this for the reasons outline above.

#19 lore raw

Re: [v4 05/12] ASoC: Intel: mrfld: add bytes control for modules

In reply to Subhransu S. Prusty
Quoted 29 lines · Subhransu S. Prusty
Quoted 19 lines · Mark Brown
Quoted 17 lines · Subhransu S. Prusty

From: Vinod Koul <[email protected]>

sound/soc/intel/sst-atom-controls.c +15 -0
+static int sst_algo_bytes_ctl_info(struct snd_kcontrol *kcontrol,
+			    struct snd_ctl_elem_info *uinfo)
+{
+	struct sst_algo_control *bc = (void *)kcontrol->private_value;
+	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
+	uinfo->count = bc->max;
+
+	/* allocate space to cache the algo parameters in the driver */
+	if (bc->params == NULL) {
+		bc->params = devm_kzalloc(component->dev, bc->max, GFP_KERNEL);
+		if (bc->params == NULL)
+			return -ENOMEM;
+	}
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return 0;
+}

I wouldn't expect an info call to be allocating anything - why is it doing that? It's not looking at the alocated data except to see if the allocation succeeded. What happens if someone manages to do a get or set without having first done an info and why aren't we doing any allocation on initialisation?

Quoted 1 line

Will move after control initialization.

As I have to initialize the params, and if it's done in probe after control creation, it's required to iterate over the controls list and match certain pattern to find the control and then initialize. This doesn't look elegant. Instead I would prefer adding an init callback in the control to do this operation. What do you recommend?

maintainer
#20 lore raw

Re: [v4 05/12] ASoC: Intel: mrfld: add bytes control for modules

In reply to Subhransu S. Prusty
Quoted 10 lines · Subhransu S. Prusty
Quoted 4 lines · Mark Brown

Review

Quoted 2 lines
(quoted diff) +2 -0
+	default:
+		pr_err("Invalid Input- algo type:%d\n", bc->type);

dev_err().

We are using pr_err() in all the error conditions for our driver. If it is really required to change, we can submit a single patch to change to dev_err() once the patches are merged.

Better yet, submit the fix first. It's definitely better practice not to use pr_ when you have a device.

#21 lore raw

Re: [v4 05/12] ASoC: Intel: mrfld: add bytes control for modules

In reply to Mark Brown
Quoted 9 lines · Mark Brown
Quoted 4 lines · Subhransu S. Prusty

From: Vinod Koul <[email protected]>

This patch add support for various modules like eq etc for mrfld DSP. All these modules will be exposed to usermode as bytes controls.

Indeed they are actually exposed by this code.

Quoted 7 lines

sound/soc/intel/sst-atom-controls.c line 31

Quoted 4 lines
sound/soc/intel/sst-atom-controls.c +4 -0
+static inline void sst_fill_byte_control(char *param,
+					 u8 ipc_msg, u8 block,
+					 u8 task_id, u8 pipe_id,
+					 u16 len, void *cmd_data)

Let the compiler figure out if this should be inline, this doesn't seem something that should obviously be inline and isn't in a header.

Ok

Quoted 8 lines

sound/soc/intel/sst-atom-controls.c line 45

Quoted 5 lines
sound/soc/intel/sst-atom-controls.c +4 -0
+	if (len > SST_MAX_BIN_BYTES - sizeof(*byte_data)) {
+		WARN(1, "%s: command length too big (%u)", __func__, len); /* this happens only if code is wrong */
+		len = SST_MAX_BIN_BYTES - sizeof(*byte_data);
+	}

Coding style, 80 columns. Since the only caller can return an error code you could do that here too.

Yes.

Quoted 12 lines

sound/soc/intel/sst-atom-controls.c line 60

Quoted 10 lines
sound/soc/intel/sst-atom-controls.c +9 -0
+static int sst_fill_and_send_cmd_unlocked(struct sst_data *drv,
+				 u8 ipc_msg, u8 block, u8 task_id, u8 pipe_id,
+				 void *cmd_data, u16 len)
+{
+	sst_fill_byte_control(drv->byte_stream, ipc_msg, block, task_id, pipe_id,
+			      len, cmd_data);
+	return sst->ops->send_byte_stream(sst->dev,
+			(struct snd_sst_bytes_v2 *)drv->byte_stream);
+}

There's a lot of casting going on in this code.

Not required. Should have been removed.

Quoted 16 lines
Quoted 16 lines
sound/soc/intel/sst-atom-controls.c +15 -0
+static int sst_algo_bytes_ctl_info(struct snd_kcontrol *kcontrol,
+			    struct snd_ctl_elem_info *uinfo)
+{
+	struct sst_algo_control *bc = (void *)kcontrol->private_value;
+	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
+	uinfo->count = bc->max;
+
+	/* allocate space to cache the algo parameters in the driver */
+	if (bc->params == NULL) {
+		bc->params = devm_kzalloc(component->dev, bc->max, GFP_KERNEL);
+		if (bc->params == NULL)
+			return -ENOMEM;
+	}
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return 0;
+}

I wouldn't expect an info call to be allocating anything - why is it doing that? It's not looking at the alocated data except to see if the allocation succeeded. What happens if someone manages to do a get or set without having first done an info and why aren't we doing any allocation on initialisation?

Will move after control initialization.

Quoted 9 lines

sound/soc/intel/sst-atom-controls.c line 137

Quoted 5 lines
sound/soc/intel/sst-atom-controls.c +4 -0
+	case SST_ALGO_BYPASS:
+		ucontrol->value.integer.value[0] = bc->bypass ? 1 : 0;
+		pr_debug("%s: bypass  %d\n", __func__, bc->bypass);
+		break;

Is bypass not a boolean value already, and shouldn't these just end up with controls called something "Switch" - they look to be just directly usable switches?

Actually BYPASS is not required. Will remove.

Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+	default:
+		pr_err("Invalid Input- algo type:%d\n", bc->type);

dev_err().

We are using pr_err() in all the error conditions for our driver. If it is really required to change, we can submit a single patch to change to dev_err() once the patches are merged.

Quoted 9 lines

sound/soc/intel/sst-atom-controls.c line 159

Quoted 6 lines
sound/soc/intel/sst-atom-controls.c +5 -0
+	switch (bc->type) {
+	case SST_ALGO_PARAMS:
+		if (bc->params)
+			memcpy(bc->params, ucontrol->value.bytes.data, bc->max);
+		break;

So if bc->params didn't get allocated somehow we just silently drop the set?

With above params initialization changes this check will not be required any more.

Quoted 9 lines

sound/soc/intel/sst-atom-controls.c line 170

Quoted 4 lines
sound/soc/intel/sst-atom-controls.c +3 -0
+	/*if pipe is enabled, need to send the algo params from here */
+	if (bc->w && bc->w->power)
+		sst_send_algo_cmd(drv, bc);

sst_send_algo_cmd() should be returning an eror code (it doesn't but the functions it calls can).

I'm not seeing any code to restore these controls on power up here.

Will take care of the return code.

sst_find_and_send_pipe_algo takes care of restoring the controls on power up.

#22 lore raw

PATCH v4 6/12 ASoC: Intel: mrfld: add the gain controls

In reply to Subhransu S. Prusty

From: Vinod Koul <[email protected]>

The DSP has various gain modules in the path, add these as ALSA gain controls

---
 sound/soc/intel/sst-atom-controls.c | 168 +++++++++++++++++++++++++++++++++++-
 sound/soc/intel/sst-atom-controls.h | 119 +++++++++++++++++++++++++
 2 files changed, 286 insertions(+), 1 deletion(-)
sound/soc/intel/sst-atom-controls.c +167 -1
index 9f41741ddf8a..afb59131ec09 100644
@@ -173,6 +173,161 @@ static int sst_algo_control_set(struct snd_kcontrol *kcontrol,
 	return 0;
 }
 
+static int sst_gain_ctl_info(struct snd_kcontrol *kcontrol,
+	struct snd_ctl_elem_info *uinfo)
+{
+	struct sst_gain_mixer_control *mc = (void *)kcontrol->private_value;
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+	uinfo->count = mc->stereo ? 2 : 1;
+	uinfo->value.integer.min = mc->min;
+	uinfo->value.integer.max = mc->max;
+	return 0;
+}
+
+/**
+ * sst_send_gain_cmd - send the gain algorithm IPC to the FW
+ * @gv:		the stored value of gain (also contains rampduration)
+ * @mute:	flag that indicates whether this was called from the
+ *		digital_mute callback or directly. If called from the
+ *		digital_mute callback, module will be muted/unmuted based on this
+ *		flag. The flag is always 0 if called directly.
+ *
+ * The user-set gain value is sent only if the user-controllable 'mute' control
+ * is OFF (indicated by gv->mute). Otherwise, the mute value (MIN value) is
+ * sent.
+ */
+static void sst_send_gain_cmd(struct sst_data *drv, struct sst_gain_value *gv,
+			      u16 task_id, u16 loc_id, u16 module_id, int mute)
+{
+	struct sst_cmd_set_gain_dual cmd;
+
+	pr_debug("%s\n", __func__);
+
+	cmd.header.command_id = MMX_SET_GAIN;
+	SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
+	cmd.gain_cell_num = 1;
+
+	if (mute || gv->mute) {
+		cmd.cell_gains[0].cell_gain_left = SST_GAIN_MIN_VALUE;
+		cmd.cell_gains[0].cell_gain_right = SST_GAIN_MIN_VALUE;
+	} else {
+		cmd.cell_gains[0].cell_gain_left = gv->l_gain;
+		cmd.cell_gains[0].cell_gain_right = gv->r_gain;
+	}
+	SST_FILL_DESTINATION(2, cmd.cell_gains[0].dest,
+			     loc_id, module_id);
+	cmd.cell_gains[0].gain_time_constant = gv->ramp_duration;
+
+	cmd.header.length = sizeof(struct sst_cmd_set_gain_dual)
+				- sizeof(struct sst_dsp_header);
+
+	sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_SET_PARAMS,
+				SST_FLAG_BLOCKED, task_id, 0, &cmd,
+			      sizeof(cmd.header) + cmd.header.length);
+}
+
+static int sst_gain_get(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_value *ucontrol)
+{
+	struct sst_gain_mixer_control *mc = (void *)kcontrol->private_value;
+	struct sst_gain_value *gv = mc->gain_val;
+
+	switch (mc->type) {
+	case SST_GAIN_TLV:
+		ucontrol->value.integer.value[0] = gv->l_gain;
+		ucontrol->value.integer.value[1] = gv->r_gain;
+		break;
+	case SST_GAIN_MUTE:
+		ucontrol->value.integer.value[0] = gv->mute ? 1 : 0;
+		break;
+	case SST_GAIN_RAMP_DURATION:
+		ucontrol->value.integer.value[0] = gv->ramp_duration;
+		break;
+	default:
+		pr_err("Invalid Input- gain type:%d\n", mc->type);
+		return -EINVAL;
+	};
+	return 0;
+}
+
+static int sst_gain_put(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_platform *platform =  snd_soc_kcontrol_platform(kcontrol);
+	struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
+	struct sst_gain_mixer_control *mc = (void *)kcontrol->private_value;
+	struct sst_gain_value *gv = mc->gain_val;
+
+	mutex_lock(&drv->lock);
+	switch (mc->type) {
+	case SST_GAIN_TLV:
+		gv->l_gain = ucontrol->value.integer.value[0];
+		gv->r_gain = ucontrol->value.integer.value[1];
+		pr_debug("%s: %s: Volume %d, %d\n", __func__, mc->pname, gv->l_gain, gv->r_gain);
+		break;
+	case SST_GAIN_MUTE:
+		gv->mute = !!ucontrol->value.integer.value[0];
+		pr_debug("%s: %s: Mute %d\n", __func__, mc->pname, gv->mute);
+		break;
+	case SST_GAIN_RAMP_DURATION:
+		gv->ramp_duration = ucontrol->value.integer.value[0];
+		pr_debug("%s: %s: RampDuration %d\n", __func__, mc->pname, gv->ramp_duration);
+		break;
+	default:
+		mutex_unlock(&drv->lock);
+		pr_err("Invalid Input- gain type:%d\n", mc->type);
+		return -EINVAL;
+	};
+
+	if (mc->w && mc->w->power)
+		sst_send_gain_cmd(drv, gv, mc->task_id,
+				mc->pipe_id | mc->instance_id, mc->module_id, 0);
+	mutex_unlock(&drv->lock);
+	return 0;
+}
+
+static const DECLARE_TLV_DB_SCALE(sst_gain_tlv_common, SST_GAIN_MIN_VALUE * 10, 10, 0);
+
+/* Gain helper with min/max set */
+#define SST_GAIN(name, path_id, task_id, instance, gain_var)				\
+	SST_GAIN_KCONTROLS(name, "gain", SST_GAIN_MIN_VALUE, SST_GAIN_MAX_VALUE,	\
+		SST_GAIN_TC_MIN, SST_GAIN_TC_MAX,					\
+		sst_gain_get, sst_gain_put,						\
+		SST_MODULE_ID_GAIN_CELL, path_id, instance, task_id,			\
+		sst_gain_tlv_common, gain_var)
+
+#define SST_VOLUME(name, path_id, task_id, instance, gain_var)				\
+	SST_GAIN_KCONTROLS(name, "volume", SST_GAIN_MIN_VALUE, SST_GAIN_MAX_VALUE,	\
+		SST_GAIN_TC_MIN, SST_GAIN_TC_MAX,					\
+		sst_gain_get, sst_gain_put,						\
+		SST_MODULE_ID_VOLUME, path_id, instance, task_id,			\
+		sst_gain_tlv_common, gain_var)
+
+#define SST_NUM_GAINS 36
+static struct sst_gain_value sst_gains[SST_NUM_GAINS];
+
+static const struct snd_kcontrol_new sst_gain_controls[] = {
+	SST_GAIN("media0_in", SST_PATH_INDEX_MEDIA0_IN, SST_TASK_MMX, 0, &sst_gains[0]),
+	SST_GAIN("media1_in", SST_PATH_INDEX_MEDIA1_IN, SST_TASK_MMX, 0, &sst_gains[1]),
+	SST_GAIN("media2_in", SST_PATH_INDEX_MEDIA2_IN, SST_TASK_MMX, 0, &sst_gains[2]),
+	SST_GAIN("media3_in", SST_PATH_INDEX_MEDIA3_IN, SST_TASK_MMX, 0, &sst_gains[3]),
+
+	SST_GAIN("pcm0_in", SST_PATH_INDEX_PCM0_IN, SST_TASK_SBA, 0, &sst_gains[4]),
+	SST_GAIN("pcm1_in", SST_PATH_INDEX_PCM1_IN, SST_TASK_SBA, 0, &sst_gains[5]),
+	SST_GAIN("pcm1_out", SST_PATH_INDEX_PCM1_OUT, SST_TASK_SBA, 0, &sst_gains[7]),
+	SST_GAIN("pcm2_out", SST_PATH_INDEX_PCM2_OUT, SST_TASK_SBA, 0, &sst_gains[8]),
+
+	SST_GAIN("codec_in0", SST_PATH_INDEX_CODEC_IN0, SST_TASK_SBA, 0, &sst_gains[20]),
+	SST_GAIN("codec_in1", SST_PATH_INDEX_CODEC_IN1, SST_TASK_SBA, 0, &sst_gains[21]),
+	SST_GAIN("codec_out0", SST_PATH_INDEX_CODEC_OUT0, SST_TASK_SBA, 0, &sst_gains[22]),
+	SST_GAIN("codec_out1", SST_PATH_INDEX_CODEC_OUT1, SST_TASK_SBA, 0, &sst_gains[23]),
+	SST_GAIN("media_loop1_out", SST_PATH_INDEX_MEDIA_LOOP1_OUT, SST_TASK_SBA, 0, &sst_gains[30]),
+	SST_GAIN("media_loop2_out", SST_PATH_INDEX_MEDIA_LOOP2_OUT, SST_TASK_SBA, 0, &sst_gains[31]),
+	SST_GAIN("sprot_loop_out", SST_PATH_INDEX_SPROT_LOOP_OUT, SST_TASK_SBA, 0, &sst_gains[32]),
+	SST_VOLUME("media0_in", SST_PATH_INDEX_MEDIA0_IN, SST_TASK_MMX, 0, &sst_gains[33]),
+};
+
 static const struct snd_kcontrol_new sst_algo_controls[] = {
 	SST_ALGO_KCONTROL_BYTES("media_loop1_out", "fir", 272, SST_MODULE_ID_FIR_24,
 		 SST_PATH_INDEX_MEDIA_LOOP1_OUT, 0, SST_TASK_SBA, SBA_VB_SET_FIR),
@@ -197,7 +352,7 @@ static const struct snd_kcontrol_new sst_algo_controls[] = {
 
 int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
 {
-	int ret = 0;
+	int i, ret = 0;
 	struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
 
 	drv->byte_stream = devm_kzalloc(platform->dev,
@@ -205,6 +360,17 @@ int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
 	if (!drv->byte_stream)
 		return -ENOMEM;
 
+
+	for (i = 0; i < SST_NUM_GAINS; i++) {
+		sst_gains[i].mute = SST_GAIN_MUTE_DEFAULT;
+		sst_gains[i].l_gain = SST_GAIN_VOLUME_DEFAULT;
+		sst_gains[i].r_gain = SST_GAIN_VOLUME_DEFAULT;
+		sst_gains[i].ramp_duration = SST_GAIN_RAMP_DURATION_DEFAULT;
+	}
+
+	snd_soc_add_platform_controls(platform, sst_gain_controls,
+			ARRAY_SIZE(sst_gain_controls));
+
 	snd_soc_add_platform_controls(platform, sst_algo_controls,
 			ARRAY_SIZE(sst_algo_controls));
 	return ret;
sound/soc/intel/sst-atom-controls.h +119 -0

135 lines not on this page · raw message

Signature · 1 line
1.9.0
maintainer
#23 lore raw

Re: [v4 06/12] ASoC: Intel: mrfld: add the gain controls

sound/soc/intel/sst-atom-controls.c static int sst_algo_control_set(struct snd_kcontrol *kcontrol, · line 311

Quoted 2 lines · Subhransu S. Prusty
sound/soc/intel/sst-atom-controls.c +2 -0
+static const struct snd_kcontrol_new sst_gain_controls[] = {
+	SST_GAIN("media0_in", SST_PATH_INDEX_MEDIA0_IN, SST_TASK_MMX, 0, &sst_gains[0]),

Media0 Capture Volume - all the controls here look like they should have standard ALSA style names.

#24 lore raw

Re: [alsa-devel] [v4 06/12] ASoC: Intel: mrfld: add the gain controls

Quoted 7 lines · Mark Brown

sound/soc/intel/sst-atom-controls.c static int sst_algo_control_set(struct snd_kcontrol *kcontrol, · line 311

Quoted 2 lines · Subhransu S. Prusty
sound/soc/intel/sst-atom-controls.c +2 -0
+static const struct snd_kcontrol_new sst_gain_controls[] = {
+	SST_GAIN("media0_in", SST_PATH_INDEX_MEDIA0_IN, SST_TASK_MMX, 0, &sst_gains[0]),

Media0 Capture Volume - all the controls here look like they should have standard ALSA style names.

Ok

Signature · 4 lines
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#25 lore raw

Re: [v4 06/12] ASoC: Intel: mrfld: add the gain controls

In reply to Mark Brown
Quoted 7 lines · Mark Brown

sound/soc/intel/sst-atom-controls.c static int sst_algo_control_set(struct snd_kcontrol *kcontrol, · line 311

Quoted 2 lines · Subhransu S. Prusty
sound/soc/intel/sst-atom-controls.c +2 -0
+static const struct snd_kcontrol_new sst_gain_controls[] = {
+	SST_GAIN("media0_in", SST_PATH_INDEX_MEDIA0_IN, SST_TASK_MMX, 0, &sst_gains[0]),

Media0 Capture Volume - all the controls here look like they should have standard ALSA style names.

Ok

#26 lore raw

PATCH v4 7/12 ASoC: Intel: mfld-pcm: add control for powering up/down dsp

In reply to Subhransu S. Prusty

From: Vinod Koul <[email protected]>

When we have PCM (FE/BE) opened or DAPM widgets triggered we need power up/down DSP accordingly. The DSP will do ref count of these requests i.e. link these runtime_get/put calls of DSP

---
 sound/soc/intel/sst-mfld-platform-pcm.c | 14 ++++++++++++++
 sound/soc/intel/sst-mfld-platform.h     |  1 +
 2 files changed, 15 insertions(+)
sound/soc/intel/sst-mfld-platform-pcm.c +14 -0
index c71893ce3d93..60ee6ad4b626 100644
@@ -292,6 +292,16 @@ static int sst_platform_init_stream(struct snd_pcm_substream *substream)
 
 }
 
+static inline int power_up_sst(struct sst_runtime_stream *stream)
+{
+	return stream->ops->power(sst->dev, true);
+}
+
+static inline int power_down_sst(struct sst_runtime_stream *stream)
+{
+	return stream->ops->power(sst->dev, false);
+}
+
 static int sst_media_open(struct snd_pcm_substream *substream,
 		struct snd_soc_dai *dai)
 {
@@ -321,6 +331,8 @@ static int sst_media_open(struct snd_pcm_substream *substream,
 	/* allocate memory for SST API set */
 	runtime->private_data = stream;
 
+	power_up_sst(stream);
+
 	/* Make sure, that the period size is always even */
 	snd_pcm_hw_constraint_step(substream->runtime, 0,
 			   SNDRV_PCM_HW_PARAM_PERIODS, 2);
@@ -340,6 +352,8 @@ static void sst_media_close(struct snd_pcm_substream *substream,
 	int ret_val = 0, str_id;
 
 	stream = substream->runtime->private_data;
+	power_down_sst(stream);
+
 	str_id = stream->stream_info.str_id;
 	if (str_id)
 		ret_val = stream->ops->close(sst->dev, str_id);
sound/soc/intel/sst-mfld-platform.h +1 -0
index faaba10c1dff..1f42b9ce5554 100644
@@ -122,6 +122,7 @@ struct sst_ops {
 	int (*stream_read_tstamp) (struct device *dev, struct pcm_stream_info *str_info);
 	int (*send_byte_stream)(struct device *dev, struct snd_sst_bytes_v2 *bytes);
 	int (*close) (struct device *dev, unsigned int str_id);
+	int (*power)(struct device *dev, bool state);
 };
 
 struct sst_runtime_stream {
Signature · 1 line
1.9.0
maintainer
#27 lore raw

Re: [v4 07/12] ASoC: Intel: mfld-pcm: add control for powering up/down dsp

sound/soc/intel/sst-mfld-platform-pcm.c static int sst_platform_init_stream(struct snd_pcm_substream *substream) · line 303

Quoted 9 lines · Subhransu S. Prusty
sound/soc/intel/sst-mfld-platform-pcm.c +9 -0
+static inline int power_up_sst(struct sst_runtime_stream *stream)
+{
+	return stream->ops->power(sst->dev, true);
+}
+
+static inline int power_down_sst(struct sst_runtime_stream *stream)
+{
+	return stream->ops->power(sst->dev, false);
+}

These return values are ignored. Shouldn't we be syncing out control values on power changes?

#28 lore raw

PATCH v4 8/12 ASoC: Intel: mrfld: add DSP core controls

In reply to Subhransu S. Prusty

From: Vinod Koul <[email protected]>

This patch adds core controls like interleavers, SSP BEs, and also logic of sending pipeline and module commands to the DSP

---
 sound/soc/intel/sst-atom-controls.c | 635 +++++++++++++++++++++++++++++++++++-
 sound/soc/intel/sst-atom-controls.h | 309 ++++++++++++++++++
 2 files changed, 943 insertions(+), 1 deletion(-)
sound/soc/intel/sst-atom-controls.c +634 -1
index afb59131ec09..5a181b32c247 100644
@@ -78,6 +78,153 @@ static int sst_fill_and_send_cmd(struct sst_data *drv,
 	return ret;
 }
 
+/*
+ * slot map value is a bitfield where each bit represents a FW channel
+ *
+ *			3 2 1 0		# 0 = codec0, 1 = codec1
+ *			RLRLRLRL	# 3, 4 = reserved
+ *
+ * e.g. slot 0 rx map =	00001100b -> data from slot 0 goes into codec_in1 L,R
+ */
+static u8 sst_ssp_slot_map[SST_MAX_TDM_SLOTS] = {
+	0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, /* default rx map */
+};
+
+/*
+ * channel map value is a bitfield where each bit represents a slot
+ *
+ *			  76543210	# 0 = slot 0, 1 = slot 1
+ *
+ * e.g. codec1_0 tx map = 00000101b -> data from codec_out1_0 goes into slot 0, 2
+ */
+static u8 sst_ssp_channel_map[SST_MAX_TDM_SLOTS] = {
+	0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, /* default tx map */
+};
+
+static void sst_send_slot_map(struct sst_data *drv)
+{
+	struct sst_param_sba_ssp_slot_map cmd;
+
+	pr_debug("Enter: %s\n", __func__);
+
+	SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
+	cmd.header.command_id = SBA_SET_SSP_SLOT_MAP;
+	cmd.header.length = sizeof(struct sst_param_sba_ssp_slot_map)
+				- sizeof(struct sst_dsp_header);
+
+	cmd.param_id = SBA_SET_SSP_SLOT_MAP;
+	cmd.param_len = sizeof(cmd.rx_slot_map) + sizeof(cmd.tx_slot_map) + sizeof(cmd.ssp_index);
+	cmd.ssp_index = SSP_CODEC;
+
+	memcpy(cmd.rx_slot_map, &sst_ssp_slot_map[0], sizeof(cmd.rx_slot_map));
+	memcpy(cmd.tx_slot_map, &sst_ssp_channel_map[0], sizeof(cmd.tx_slot_map));
+
+	sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_SET_PARAMS,
+			SST_FLAG_BLOCKED, SST_TASK_SBA, 0, &cmd,
+			      sizeof(cmd.header) + cmd.header.length);
+}
+
+int sst_slot_enum_info(struct snd_kcontrol *kcontrol,
+		       struct snd_ctl_elem_info *uinfo)
+{
+	struct sst_enum *e = (struct sst_enum *)kcontrol->private_value;
+
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+	uinfo->count = 1;
+	uinfo->value.enumerated.items = e->max;
+
+	if (uinfo->value.enumerated.item > e->max - 1)
+		uinfo->value.enumerated.item = e->max - 1;
+	strcpy(uinfo->value.enumerated.name,
+		e->texts[uinfo->value.enumerated.item]);
+	return 0;
+}
+
+/**
+ * sst_slot_get - get the status of the interleaver/deinterleaver control
+ *
+ * Searches the map where the control status is stored, and gets the
+ * channel/slot which is currently set for this enumerated control. Since it is
+ * an enumerated control, there is only one possible value.
+ */
+static int sst_slot_get(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_value *ucontrol)
+{
+	struct sst_enum *e = (void *)kcontrol->private_value;
+	unsigned int ctl_no = e->reg;
+	unsigned int is_tx = e->tx;
+	unsigned int val, mux;
+	u8 *map = is_tx ? sst_ssp_channel_map : sst_ssp_slot_map;
+
+	val = 1 << ctl_no;
+	/* search which slot/channel has this bit set - there should be only one */
+	for (mux = e->max; mux > 0;  mux--)
+		if (map[mux - 1] & val)
+			break;
+
+	ucontrol->value.enumerated.item[0] = mux;
+	pr_debug("%s: %s - %s map = %#x\n", __func__, is_tx ? "tx channel" : "rx slot",
+		 e->texts[mux], mux ? map[mux - 1] : -1);
+	return 0;
+}
+
+/**
+ * sst_slot_put - set the status of interleaver/deinterleaver control
+ *
+ * (de)interleaver controls are defined in opposite sense to be user-friendly
+ *
+ * Instead of the enum value being the value written to the register, it is the
+ * register address; and the kcontrol number (register num) is the value written
+ * to the register. This is so that there can be only one value for each
+ * slot/channel since there is only one control for each slot/channel.
+ *
+ * This means that whenever an enum is set, we need to clear the bit
+ * for that kcontrol_no for all the interleaver OR deinterleaver registers
+ */
+static int sst_slot_put(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_platform *platform =  snd_soc_kcontrol_platform(kcontrol);
+	struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
+	struct sst_enum *e = (void *)kcontrol->private_value;
+	int i;
+	unsigned int ctl_no = e->reg;
+	unsigned int is_tx = e->tx;
+	unsigned int slot_channel_no;
+	unsigned int val, mux;
+	u8 *map;
+
+	mutex_lock(&drv->lock);
+	map = is_tx ? sst_ssp_channel_map : sst_ssp_slot_map;
+
+	val = 1 << ctl_no;
+	mux = ucontrol->value.enumerated.item[0];
+	if (mux > e->max - 1) {
+		mutex_unlock(&drv->lock);
+		return -EINVAL;
+	}
+
+
+	/* first clear all registers of this bit */
+	for (i = 0; i < e->max; i++)
+		map[i] &= ~val;
+
+	if (mux == 0) /* kctl set to 'none' */
+		return 0;
+
+	/* offset by one to take "None" into account */
+	slot_channel_no = mux - 1;
+	map[slot_channel_no] |= val;
+
+	pr_debug("%s: %s %s map = %#x\n", __func__, is_tx ? "tx channel" : "rx slot",
+		 e->texts[mux], map[slot_channel_no]);
+
+	if (e->w && e->w->power)
+		sst_send_slot_map(drv);
+	mutex_unlock(&drv->lock);
+	return 0;
+}
+
 static void sst_send_algo_cmd(struct sst_data *drv,
 			      struct sst_algo_control *bc)
 {
@@ -103,7 +250,28 @@ static void sst_send_algo_cmd(struct sst_data *drv,
 	kfree(cmd);
 }
 
-static int sst_algo_bytes_ctl_info(struct snd_kcontrol *kcontrol,
+/**
+ * sst_find_and_send_pipe_algo - send all the algo parameters for a pipe
+ *
+ * The algos which are in each pipeline are sent to the firmware one by one
+ */
+static void sst_find_and_send_pipe_algo(struct sst_data *drv,
+					const char *pipe, struct sst_ids *ids)
+{
+	struct sst_algo_control *bc;
+	struct sst_module *algo = NULL;
+
+	pr_debug("Enter: %s, widget=%s\n", __func__, pipe);
+
+	list_for_each_entry(algo, &ids->algo_list, node) {
+		bc = (void *)algo->kctl->private_value;
+
+		pr_debug("Found algo control name=%s pipe=%s\n", algo->kctl->id.name, pipe);
+		sst_send_algo_cmd(drv, bc);
+	}
+}
+
+int sst_algo_bytes_ctl_info(struct snd_kcontrol *kcontrol,
 			    struct snd_ctl_elem_info *uinfo)
 {
 	struct sst_algo_control *bc = (void *)kcontrol->private_value;
@@ -287,8 +455,270 @@ static int sst_gain_put(struct snd_kcontrol *kcontrol,
 	return 0;
 }
 
+static void sst_set_pipe_gain(struct sst_ids *ids, struct sst_data *drv, int mute);
+
+static void sst_send_pipe_module_params(struct snd_soc_dapm_widget *w,
+		struct snd_kcontrol *kcontrol)
+{
+	struct snd_soc_platform *platform =  snd_soc_kcontrol_platform(kcontrol);
+	struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
+	struct sst_ids *ids = w->priv;
+
+	sst_find_and_send_pipe_algo(drv, w->name, ids);
+	sst_set_pipe_gain(ids, drv, 0);
+}
+
+static int sst_generic_modules_event(struct snd_soc_dapm_widget *w,
+				     struct snd_kcontrol *k, int event)
+{
+	if (SND_SOC_DAPM_EVENT_ON(event))
+		sst_send_pipe_module_params(w, k);
+	return 0;
+}
+
 static const DECLARE_TLV_DB_SCALE(sst_gain_tlv_common, SST_GAIN_MIN_VALUE * 10, 10, 0);
 
+/* Look up table to convert MIXER SW bit regs to SWM inputs */
+static const uint swm_mixer_input_ids[SST_SWM_INPUT_COUNT] = {
+	[SST_IP_CODEC0]		= SST_SWM_IN_CODEC0,
+	[SST_IP_CODEC1]		= SST_SWM_IN_CODEC1,
+	[SST_IP_LOOP0]		= SST_SWM_IN_SPROT_LOOP,
+	[SST_IP_LOOP1]		= SST_SWM_IN_MEDIA_LOOP1,
+	[SST_IP_LOOP2]		= SST_SWM_IN_MEDIA_LOOP2,
+	[SST_IP_PCM0]		= SST_SWM_IN_PCM0,
+	[SST_IP_PCM1]		= SST_SWM_IN_PCM1,
+	[SST_IP_MEDIA0]		= SST_SWM_IN_MEDIA0,
+	[SST_IP_MEDIA1]		= SST_SWM_IN_MEDIA1,
+	[SST_IP_MEDIA2]		= SST_SWM_IN_MEDIA2,
+	[SST_IP_MEDIA3]		= SST_SWM_IN_MEDIA3,
+};
+static void sst_set_pipe_gain(struct sst_ids *ids, struct sst_data *drv, int mute)
+{
+	struct sst_gain_mixer_control *mc;
+	struct sst_gain_value *gv;
+	struct sst_module *gain = NULL;
+
+	list_for_each_entry(gain, &ids->gain_list, node) {
+		struct snd_kcontrol *kctl = gain->kctl;
+
+		pr_debug("control name=%s\n", kctl->id.name);
+		mc = (void *)kctl->private_value;
+		gv = mc->gain_val;
+
+		sst_send_gain_cmd(drv, gv, mc->task_id,
+				mc->pipe_id | mc->instance_id, mc->module_id, mute);
+	}
+}
+void sst_handle_vb_timer(struct snd_soc_dai *dai, bool enable)
+{
+	struct sst_cmd_generic cmd;
+	struct sst_data *drv = snd_soc_dai_get_drvdata(dai);
+	static int timer_usage;
+
+	if (enable)
+		cmd.header.command_id = SBA_VB_START;
+	else
+		cmd.header.command_id = SBA_IDLE;
+	pr_debug("%s: enable=%u, usage=%d\n", __func__, enable, timer_usage);
+
+	SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
+	cmd.header.length = 0;
+
+	if (enable)
+		sst->ops->power(sst->dev, true);
+
+	mutex_lock(&drv->lock);
+	if (enable)
+		timer_usage++;
+	else
+		timer_usage--;
+
+	/* Send the command only if this call is the first enable or last
+	 * disable
+	 */
+	if ((enable && (timer_usage == 1)) ||
+	    (!enable && (timer_usage == 0)))
+		sst_fill_and_send_cmd_unlocked(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
+				      SST_TASK_SBA, 0, &cmd,
+				      sizeof(cmd.header) + cmd.header.length);
+	mutex_unlock(&drv->lock);
+
+	if (!enable)
+		sst->ops->power(sst->dev, false);
+}
+
+/**
+ * sst_ssp_config - contains SSP configuration for media UC
+ */
+static const struct sst_ssp_config sst_ssp_configs = {
+	.ssp_id = SSP_CODEC,
+	.bits_per_slot = 24,
+	.slots = 4,
+	.ssp_mode = SSP_MODE_MASTER,
+	.pcm_mode = SSP_PCM_MODE_NETWORK,
+	.duplex = SSP_DUPLEX,
+	.ssp_protocol = SSP_MODE_PCM,
+	.fs_width = 1,
+	.fs_frequency = SSP_FS_48_KHZ,
+	.active_slot_map = 0xF,
+	.start_delay = 0,
+};
+
+void send_ssp_cmd(struct snd_soc_dai *dai, const char *id, bool enable)
+{
+	struct sst_cmd_sba_hw_set_ssp cmd;
+	struct sst_data *drv = snd_soc_dai_get_drvdata(dai);
+	const struct sst_ssp_config *config;
+
+	pr_err("Enter:%s, enable=%d port_name=%s\n", __func__, enable, id);
+
+	SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
+	cmd.header.command_id = SBA_HW_SET_SSP;
+	cmd.header.length = sizeof(struct sst_cmd_sba_hw_set_ssp)
+				- sizeof(struct sst_dsp_header);
+
+	config = &sst_ssp_configs;
+	pr_debug("%s: ssp_id: %u\n", __func__, config->ssp_id);
+
+	if (enable)
+		cmd.switch_state = SST_SWITCH_ON;
+	else
+		cmd.switch_state = SST_SWITCH_OFF;
+
+	cmd.selection = config->ssp_id;
+	cmd.nb_bits_per_slots = config->bits_per_slot;
+	cmd.nb_slots = config->slots;
+	cmd.mode = config->ssp_mode | (config->pcm_mode << 1);
+	cmd.duplex = config->duplex;
+	cmd.active_tx_slot_map = config->active_slot_map;
+	cmd.active_rx_slot_map = config->active_slot_map;
+	cmd.frame_sync_frequency = config->fs_frequency;
+	cmd.frame_sync_polarity = SSP_FS_ACTIVE_HIGH;
+	cmd.data_polarity = 1;
+	cmd.frame_sync_width = config->fs_width;
+	cmd.ssp_protocol = config->ssp_protocol;
+	cmd.start_delay = config->start_delay;
+	cmd.reserved1 = cmd.reserved2 = 0xFF;
+
+	sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
+				SST_TASK_SBA, 0, &cmd,
+				sizeof(cmd.header) + cmd.header.length);
+}
+
+static int sst_set_be_modules(struct snd_soc_dapm_widget *w,
+			 struct snd_kcontrol *k, int event)
+{
+	struct snd_soc_platform *platform =  snd_soc_kcontrol_platform(k);
+	struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
+
+	pr_debug("Enter: %s, widget=%s\n", __func__, w->name);
+
+	if (SND_SOC_DAPM_EVENT_ON(event)) {
+		sst_send_slot_map(drv);
+		sst_send_pipe_module_params(w, k);
+	}
+	return 0;
+}
+
+static int sst_set_media_path(struct snd_soc_dapm_widget *w,
+			      struct snd_kcontrol *k, int event)
+{
+	struct sst_cmd_set_media_path cmd;
+	struct snd_soc_platform *platform =  snd_soc_kcontrol_platform(k);
+	struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
+	struct sst_ids *ids = w->priv;
+
+	pr_debug("%s: widget=%s\n", __func__, w->name);
+	pr_debug("%s: task=%u, location=%#x\n", __func__,
+				ids->task_id, ids->location_id);
+
+	if (SND_SOC_DAPM_EVENT_ON(event))
+		cmd.switch_state = SST_PATH_ON;
+	else
+		cmd.switch_state = SST_PATH_OFF;
+
+	SST_FILL_DESTINATION(2, cmd.header.dst,
+			     ids->location_id, SST_DEFAULT_MODULE_ID);
+
+	/* MMX_SET_MEDIA_PATH == SBA_SET_MEDIA_PATH */
+	cmd.header.command_id = MMX_SET_MEDIA_PATH;
+	cmd.header.length = sizeof(struct sst_cmd_set_media_path)
+				- sizeof(struct sst_dsp_header);
+
+	sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
+			      ids->task_id, 0, &cmd,
+			      sizeof(cmd.header) + cmd.header.length);
+
+	if (SND_SOC_DAPM_EVENT_ON(event))
+		sst_send_pipe_module_params(w, k);
+	return 0;
+}
+
+static int sst_set_media_loop(struct snd_soc_dapm_widget *w,
+			struct snd_kcontrol *k, int event)
+{
+	struct sst_cmd_sba_set_media_loop_map cmd;
+	struct snd_soc_platform *platform =  snd_soc_kcontrol_platform(k);
+	struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
+	struct sst_ids *ids = w->priv;
+
+	pr_debug("Enter:%s, widget=%s\n", __func__, w->name);
+	if (SND_SOC_DAPM_EVENT_ON(event))
+		cmd.switch_state = SST_SWITCH_ON;
+	else
+		cmd.switch_state = SST_SWITCH_OFF;
+
+	SST_FILL_DESTINATION(2, cmd.header.dst,
+			     ids->location_id, SST_DEFAULT_MODULE_ID);
+
+	cmd.header.command_id = SBA_SET_MEDIA_LOOP_MAP;
+	cmd.header.length = sizeof(struct sst_cmd_sba_set_media_loop_map)
+				 - sizeof(struct sst_dsp_header);
+	cmd.param.part.cfg.rate = 2; /* 48khz */
+
+	cmd.param.part.cfg.format = ids->format; /* stereo/Mono */
+	cmd.param.part.cfg.s_length = 1; /* 24bit left justified*/
+	cmd.map = 0; /* Algo sequence: Gain - DRP - FIR - IIR  */
+
+	sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
+			      SST_TASK_SBA, 0, &cmd,
+			      sizeof(cmd.header) + cmd.header.length);
+	if (SND_SOC_DAPM_EVENT_ON(event))
+		sst_send_pipe_module_params(w, k);
+	return 0;
+}
+
+static const char * const slot_names[] = {
+	"none",
+	"slot 0", "slot 1", "slot 2", "slot 3",
+	"slot 4", "slot 5", "slot 6", "slot 7", /* not supported by FW */
+};
+
+static const char * const channel_names[] = {
+	"none",
+	"codec_out0_0", "codec_out0_1", "codec_out1_0", "codec_out1_1",
+	"codec_out2_0", "codec_out2_1", "codec_out3_0", "codec_out3_1", /* not supported by FW */
+};
+
+#define SST_INTERLEAVER(xpname, slot_name, slotno) \
+	SST_SSP_SLOT_CTL(xpname, "interleaver", slot_name, slotno, true, \
+			 channel_names, sst_slot_get, sst_slot_put)
+
+#define SST_DEINTERLEAVER(xpname, channel_name, channel_no) \
+	SST_SSP_SLOT_CTL(xpname, "deinterleaver", channel_name, channel_no, false, \
+			 slot_names, sst_slot_get, sst_slot_put)
+
+static const struct snd_kcontrol_new sst_slot_controls[] = {
+	SST_INTERLEAVER("codec_out", "slot 0", 0),
+	SST_INTERLEAVER("codec_out", "slot 1", 1),
+	SST_INTERLEAVER("codec_out", "slot 2", 2),
+	SST_INTERLEAVER("codec_out", "slot 3", 3),
+	SST_DEINTERLEAVER("codec_in", "codec_in0_0", 0),
+	SST_DEINTERLEAVER("codec_in", "codec_in0_1", 1),
+	SST_DEINTERLEAVER("codec_in", "codec_in1_0", 2),
+	SST_DEINTERLEAVER("codec_in", "codec_in1_1", 3),
+};
+
 /* Gain helper with min/max set */
 #define SST_GAIN(name, path_id, task_id, instance, gain_var)				\
 	SST_GAIN_KCONTROLS(name, "gain", SST_GAIN_MIN_VALUE, SST_GAIN_MAX_VALUE,	\
@@ -350,6 +780,204 @@ static const struct snd_kcontrol_new sst_algo_controls[] = {
 
 };
 
+static inline bool is_sst_dapm_widget(struct snd_soc_dapm_widget *w)
+{
+	if ((w->id == snd_soc_dapm_pga) ||
+	    (w->id == snd_soc_dapm_aif_in) ||
+	    (w->id == snd_soc_dapm_aif_out) ||
+	    (w->id == snd_soc_dapm_input) ||
+	    (w->id == snd_soc_dapm_output) ||
+	    (w->id == snd_soc_dapm_mixer))
+		return true;
+	else
+		return false;
+}
+
+/**
+ * sst_send_pipe_gains - send gains for the front-end DAIs
+ *
+ * The gains in the pipes connected to the front-ends are muted/unmuted
+ * automatically via the digital_mute() DAPM callback. This function sends the
+ * gains for the front-end pipes.
+ */
+int sst_send_pipe_gains(struct snd_soc_dai *dai, int stream, int mute)
+{
+	struct sst_data *drv = snd_soc_dai_get_drvdata(dai);
+	struct snd_soc_dapm_widget *w;
+	struct snd_soc_dapm_path *p = NULL;
+
+	pr_debug("%s: enter, dai-name=%s dir=%d\n", __func__, dai->name, stream);
+
+	if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		pr_debug("Stream name=%s\n", dai->playback_widget->name);
+		w = dai->playback_widget;
+		list_for_each_entry(p, &w->sinks, list_source) {
+			if (p->connected && !p->connected(w, p->sink))
+				continue;
+
+			if (p->connect && p->sink->power && is_sst_dapm_widget(p->sink)) {
+				struct sst_ids *ids = p->sink->priv;
+
+				pr_debug("send gains for widget=%s\n", p->sink->name);
+				sst_set_pipe_gain(ids, drv, mute);
+			}
+		}
+	} else {
+		pr_debug("Stream name=%s\n", dai->capture_widget->name);
+		w = dai->capture_widget;
+		list_for_each_entry(p, &w->sources, list_sink) {
+			if (p->connected && !p->connected(w, p->sink))
+				continue;
+
+			if (p->connect &&  p->source->power && is_sst_dapm_widget(p->source)) {
+				struct sst_ids *ids = p->source->priv;
+
+				pr_debug("send gain for widget=%s\n", p->source->name);
+				sst_set_pipe_gain(ids, drv, mute);
+			}
+		}
+	}
+	return 0;
+}
+
+/**
+ * sst_fill_module_list - populate the list of modules/gains for a pipe
+ *
+ *
+ * Fills the widget pointer in the kcontrol private data, and also fills the
+ * kcontrol pointer in the widget private data.
+ *
+ * Widget pointer is used to send the algo/gain in the .put() handler if the
+ * widget is powerd on.
+ *
+ * Kcontrol pointer is used to send the algo/gain in the widget power ON/OFF
+ * event handler. Each widget (pipe) has multiple algos stored in the algo_list.
+ */
+static int sst_fill_module_list(struct snd_kcontrol *kctl,
+	 struct snd_soc_dapm_widget *w, int type)
+{
+	struct sst_module *module = NULL;
+	struct snd_soc_platform *platform =  snd_soc_kcontrol_platform(kctl);
+	struct sst_ids *ids = w->priv;
+
+	module = devm_kzalloc(platform->dev, sizeof(*module), GFP_KERNEL);
+	if (!module)
+		return -ENOMEM;
+
+	if (type == SST_MODULE_GAIN) {
+		struct sst_gain_mixer_control *mc = (void *)kctl->private_value;
+
+		mc->w = w;
+		module->kctl = kctl;
+		list_add_tail(&module->node, &ids->gain_list);
+	} else if (type == SST_MODULE_ALGO) {
+		struct sst_algo_control *bc = (void *)kctl->private_value;
+
+		bc->w = w;
+		module->kctl = kctl;
+		list_add_tail(&module->node, &ids->algo_list);
+	}
+
+	return 0;
+}
+
+/**
+ * sst_fill_widget_module_info - fill list of gains/algos for the pipe
+ * @widget:	pipe modelled as a DAPM widget
+ *
+ * Fill the list of gains/algos for the widget by looking at all the card
+ * controls and comparing the name of the widget with the first part of control
+ * name. First part of control name contains the pipe name (widget name).
+ */
+static int sst_fill_widget_module_info(struct snd_soc_dapm_widget *w,
+	struct snd_soc_platform *platform)
+{
+	struct snd_kcontrol *kctl;
+	int index, ret = 0;
+	struct snd_card *card = platform->component.card->snd_card;
+	char *idx;
+
+	down_read(&card->controls_rwsem);
+
+	list_for_each_entry(kctl, &card->controls, list) {
+		idx = strstr(kctl->id.name, " ");
+		if (idx == NULL)
+			continue;
+		index  = strlen(kctl->id.name) - strlen(idx);
+		if (strstr(kctl->id.name, "volume") &&
+		    !strncmp(kctl->id.name, w->name, index))
+			ret = sst_fill_module_list(kctl, w, SST_MODULE_GAIN);
+		else if (strstr(kctl->id.name, "params") &&
+			 !strncmp(kctl->id.name, w->name, index))
+			ret = sst_fill_module_list(kctl, w, SST_MODULE_ALGO);
+		else if (strstr(kctl->id.name, "mute") &&
+			 !strncmp(kctl->id.name, w->name, index)) {
+			struct sst_gain_mixer_control *mc = (void *)kctl->private_value;
+
+			mc->w = w;
+		} else if (strstr(kctl->id.name, "interleaver") &&
+			 !strncmp(kctl->id.name, w->name, index)) {
+			struct sst_enum *e = (void *)kctl->private_value;
+
+			e->w = w;
+		} else if (strstr(kctl->id.name, "deinterleaver") &&
+			 !strncmp(kctl->id.name, w->name, index)) {
+
+			struct sst_enum *e = (void *)kctl->private_value;
+
+			e->w = w;
+		}
+		if (ret < 0) {
+			up_read(&card->controls_rwsem);
+			return ret;
+		}
+	}
+	up_read(&card->controls_rwsem);
+	return 0;
+}
+
+/**
+ * sst_fill_linked_widgets - fill the parent pointer for the linked widget
+ */
+static void sst_fill_linked_widgets(struct snd_soc_platform *platform,
+						struct sst_ids *ids)
+{
+	struct snd_soc_dapm_widget *w;
+	unsigned int len = strlen(ids->parent_wname);
+
+	list_for_each_entry(w, &platform->component.card->widgets, list) {
+		if (!strncmp(ids->parent_wname, w->name, len)) {
+			ids->parent_w = w;
+			break;
+		}
+	}
+}
+
+/**
+ * sst_map_modules_to_pipe - fill algo/gains list for all pipes
+ */
+static int sst_map_modules_to_pipe(struct snd_soc_platform *platform)
+{
+	struct snd_soc_dapm_widget *w;
+	int ret = 0;
+
+	list_for_each_entry(w, &platform->component.card->widgets, list) {
+		if (platform && is_sst_dapm_widget(w) && (w->priv)) {
+			struct sst_ids *ids = w->priv;
+
+			pr_debug("widget type=%d name=%s\n", w->id, w->name);
+			INIT_LIST_HEAD(&ids->algo_list);
+			INIT_LIST_HEAD(&ids->gain_list);
+			ret = sst_fill_widget_module_info(w, platform);
+			if (ret < 0)
+				return ret;
+			/* fill linked widgets */
+			if (ids->parent_wname !=  NULL)
+				sst_fill_linked_widgets(platform, ids);
+		}
+	}
+	return 0;
+}
 int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
 {
 	int i, ret = 0;
@@ -373,5 +1001,10 @@ int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
 
 	snd_soc_add_platform_controls(platform, sst_algo_controls,
 			ARRAY_SIZE(sst_algo_controls));
+	snd_soc_add_platform_controls(platform, sst_slot_controls,
+			ARRAY_SIZE(sst_slot_controls));
+
+	ret = sst_map_modules_to_pipe(platform);
+
 	return ret;
 }
sound/soc/intel/sst-atom-controls.h +309 -0

335 lines not on this page · raw message

Signature · 1 line
1.9.0
#29 lore raw

PATCH v4 9/12 ASoC: Export dapm_kcontrol_get_value

In reply to Subhransu S. Prusty

The DSP driver needs to know widget control value in its event handler for widgets like mixers. This is required in the subsequent patches

---
 include/sound/soc-dapm.h | 1 +
 sound/soc/soc-dapm.c     | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
include/sound/soc-dapm.h +1 -0
index aac04ff84eea..6ae0a1952ad7 100644
@@ -432,6 +432,7 @@ int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context *dapm,
 int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
 				const char *pin);
 void snd_soc_dapm_auto_nc_pins(struct snd_soc_card *card);
+unsigned int dapm_kcontrol_get_value(const struct snd_kcontrol *kcontrol);
 
 /* Mostly internal - should not normally be used */
 void dapm_mark_io_dirty(struct snd_soc_dapm_context *dapm);
sound/soc/soc-dapm.c +2 -1
index 8348352dc2c6..08c79f09034f 100644
@@ -326,12 +326,13 @@ static struct list_head *dapm_kcontrol_get_path_list(
 	list_for_each_entry(path, dapm_kcontrol_get_path_list(kcontrol), \
 		list_kcontrol)
 
-static unsigned int dapm_kcontrol_get_value(const struct snd_kcontrol *kcontrol)
+unsigned int dapm_kcontrol_get_value(const struct snd_kcontrol *kcontrol)
 {
 	struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol);
 
 	return data->value;
 }
+EXPORT_SYMBOL_GPL(dapm_kcontrol_get_value);
 
 static bool dapm_kcontrol_set_value(const struct snd_kcontrol *kcontrol,
 	unsigned int value)
Signature · 1 line
1.9.0
#30 lore raw

PATCH v4 10/12 ASoC: Intel: mrfld: add the DSP DAPM widgets

In reply to Subhransu S. Prusty

From: Vinod Koul <[email protected]>

This patch adds all DAPM widgets and the event handlers for DSP expect the mixers. Since we are still discussing mixer update and is dependent upon component series

---
 sound/soc/intel/sst-atom-controls.c | 220 ++++++++++++++++++++++++++++++++++++
 sound/soc/intel/sst-mfld-platform.h |   4 +
 2 files changed, 224 insertions(+)
sound/soc/intel/sst-atom-controls.c +220 -0
index 5a181b32c247..029e6960ca73 100644
@@ -492,6 +492,39 @@ static const uint swm_mixer_input_ids[SST_SWM_INPUT_COUNT] = {
 	[SST_IP_MEDIA2]		= SST_SWM_IN_MEDIA2,
 	[SST_IP_MEDIA3]		= SST_SWM_IN_MEDIA3,
 };
+
+/**
+ * fill_swm_input - fill in the SWM input ids given the register
+ *
+ * The register value is a bit-field inicated which mixer inputs are ON. Use the
+ * lookup table to get the input-id and fill it in the structure.
+ */
+static int fill_swm_input(struct swm_input_ids *swm_input, unsigned int reg)
+{
+	uint i, is_set, nb_inputs = 0;
+	u16 input_loc_id;
+
+	pr_debug("%s: reg: %#x\n", __func__, reg);
+	for (i = 0; i < SST_SWM_INPUT_COUNT; i++) {
+		is_set = reg & BIT(i);
+		if (!is_set)
+			continue;
+
+		input_loc_id = swm_mixer_input_ids[i];
+		SST_FILL_DESTINATION(2, swm_input->input_id,
+				     input_loc_id, SST_DEFAULT_MODULE_ID);
+		nb_inputs++;
+		swm_input++;
+		pr_debug("input id: %#x, nb_inputs: %d\n", input_loc_id, nb_inputs);
+
+		if (nb_inputs == SST_CMD_SWM_MAX_INPUTS) {
+			pr_warn("%s: SET_SWM cmd max inputs reached", __func__);
+			break;
+		}
+	}
+	return nb_inputs;
+}
+
 static void sst_set_pipe_gain(struct sst_ids *ids, struct sst_data *drv, int mute)
 {
 	struct sst_gain_mixer_control *mc;
@@ -509,6 +542,109 @@ static void sst_set_pipe_gain(struct sst_ids *ids, struct sst_data *drv, int mut
 				mc->pipe_id | mc->instance_id, mc->module_id, mute);
 	}
 }
+
+static int sst_swm_mixer_event(struct snd_soc_dapm_widget *w,
+			struct snd_kcontrol *k, int event)
+{
+	struct sst_cmd_set_swm cmd;
+	struct snd_soc_platform *platform = snd_soc_dapm_to_platform(w->dapm);
+	struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
+	struct sst_ids *ids = w->priv;
+	bool set_mixer = false;
+	struct soc_mixer_control *mc;
+	int val = 0;
+	int i = 0;
+
+	pr_debug("%s: widget = %s\n", __func__, w->name);
+	for (i = 0; i < w->num_kcontrols; i++) {
+		if (dapm_kcontrol_get_value(w->kcontrols[i])) {
+			mc = (struct soc_mixer_control *)(w->kcontrols[i])->private_value;
+			val |= 1 << mc->shift;
+		}
+	}
+	pr_debug("%s: val = %#x\n", __func__, val);
+
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+	case SND_SOC_DAPM_POST_PMD:
+		set_mixer = true;
+		break;
+	case SND_SOC_DAPM_POST_REG:
+		if (w->power)
+			set_mixer = true;
+		break;
+	default:
+		set_mixer = false;
+	}
+
+	if (set_mixer == false)
+		return 0;
+
+	if (SND_SOC_DAPM_EVENT_ON(event) ||
+	    event == SND_SOC_DAPM_POST_REG)
+		cmd.switch_state = SST_SWM_ON;
+	else
+		cmd.switch_state = SST_SWM_OFF;
+
+	SST_FILL_DEFAULT_DESTINATION(cmd.header.dst);
+	/* MMX_SET_SWM == SBA_SET_SWM */
+	cmd.header.command_id = SBA_SET_SWM;
+
+	SST_FILL_DESTINATION(2, cmd.output_id,
+			     ids->location_id, SST_DEFAULT_MODULE_ID);
+	cmd.nb_inputs =	fill_swm_input(&cmd.input[0], val);
+	cmd.header.length = offsetof(struct sst_cmd_set_swm, input) - sizeof(struct sst_dsp_header)
+				+ (cmd.nb_inputs * sizeof(cmd.input[0]));
+
+	sst_fill_and_send_cmd(drv, SST_IPC_IA_CMD, SST_FLAG_BLOCKED,
+			      ids->task_id, 0, &cmd,
+			      sizeof(cmd.header) + cmd.header.length);
+	return 0;
+}
+
+/* SBA mixers - 16 inputs */
+#define SST_SBA_DECLARE_MIX_CONTROLS(kctl_name)						\
+	static const struct snd_kcontrol_new kctl_name[] = {				\
+		SOC_DAPM_SINGLE("codec_in0", SND_SOC_NOPM, SST_IP_CODEC0, 1, 0),	\
+		SOC_DAPM_SINGLE("codec_in1", SND_SOC_NOPM, SST_IP_CODEC1, 1, 0),	\
+		SOC_DAPM_SINGLE("sprot_loop_in", SND_SOC_NOPM, SST_IP_LOOP0, 1, 0),	\
+		SOC_DAPM_SINGLE("media_loop1_in", SND_SOC_NOPM, SST_IP_LOOP1, 1, 0),	\
+		SOC_DAPM_SINGLE("media_loop2_in", SND_SOC_NOPM, SST_IP_LOOP2, 1, 0),	\
+		SOC_DAPM_SINGLE("pcm0_in", SND_SOC_NOPM, SST_IP_PCM0, 1, 0),		\
+		SOC_DAPM_SINGLE("pcm1_in", SND_SOC_NOPM, SST_IP_PCM1, 1, 0),		\
+	}
+
+#define SST_SBA_MIXER_GRAPH_MAP(mix_name)			\
+	{ mix_name, "codec_in0",	"codec_in0" },		\
+	{ mix_name, "codec_in1",	"codec_in1" },		\
+	{ mix_name, "sprot_loop_in",	"sprot_loop_in" },	\
+	{ mix_name, "media_loop1_in",	"media_loop1_in" },	\
+	{ mix_name, "media_loop2_in",	"media_loop2_in" },	\
+	{ mix_name, "pcm0_in",		"pcm0_in" },		\
+	{ mix_name, "pcm1_in",		"pcm1_in" }
+
+#define SST_MMX_DECLARE_MIX_CONTROLS(kctl_name)			\
+	static const struct snd_kcontrol_new kctl_name[] = {			\
+		SOC_DAPM_SINGLE("media0_in", SND_SOC_NOPM, SST_IP_MEDIA0, 1, 0),	\
+		SOC_DAPM_SINGLE("media1_in", SND_SOC_NOPM, SST_IP_MEDIA1, 1, 0),	\
+		SOC_DAPM_SINGLE("media2_in", SND_SOC_NOPM, SST_IP_MEDIA2, 1, 0),	\
+		SOC_DAPM_SINGLE("media3_in", SND_SOC_NOPM, SST_IP_MEDIA3, 1, 0),	\
+	}
+
+SST_MMX_DECLARE_MIX_CONTROLS(sst_mix_media0_controls);
+SST_MMX_DECLARE_MIX_CONTROLS(sst_mix_media1_controls);
+
+/* 18 SBA mixers */
+SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_pcm0_controls);
+SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_pcm1_controls);
+SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_pcm2_controls);
+SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_sprot_l0_controls);
+SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_media_l1_controls);
+SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_media_l2_controls);
+SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_voip_controls);
+SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_codec0_controls);
+SST_SBA_DECLARE_MIX_CONTROLS(sst_mix_codec1_controls);
+
 void sst_handle_vb_timer(struct snd_soc_dai *dai, bool enable)
 {
 	struct sst_cmd_generic cmd;
@@ -688,6 +824,83 @@ static int sst_set_media_loop(struct snd_soc_dapm_widget *w,
 	return 0;
 }
 
+static const struct snd_soc_dapm_widget sst_dapm_widgets[] = {
+	SST_AIF_IN("codec_in0", sst_set_be_modules),
+	SST_AIF_IN("codec_in1", sst_set_be_modules),
+	SST_AIF_OUT("codec_out0", sst_set_be_modules),
+	SST_AIF_OUT("codec_out1", sst_set_be_modules),
+
+	/* Media Paths */
+	/* MediaX IN paths are set via ALLOC, so no SET_MEDIA_PATH command */
+	SST_PATH_INPUT("media0_in", SST_TASK_MMX, SST_SWM_IN_MEDIA0, sst_generic_modules_event),
+	SST_PATH_INPUT("media1_in", SST_TASK_MMX, SST_SWM_IN_MEDIA1, NULL),
+	SST_PATH_INPUT("media2_in", SST_TASK_MMX, SST_SWM_IN_MEDIA2, sst_set_media_path),
+	SST_PATH_INPUT("media3_in", SST_TASK_MMX, SST_SWM_IN_MEDIA3, NULL),
+	SST_PATH_OUTPUT("media0_out", SST_TASK_MMX, SST_SWM_OUT_MEDIA0, sst_set_media_path),
+	SST_PATH_OUTPUT("media1_out", SST_TASK_MMX, SST_SWM_OUT_MEDIA1, sst_set_media_path),
+
+	/* SBA PCM Paths */
+	SST_PATH_INPUT("pcm0_in", SST_TASK_SBA, SST_SWM_IN_PCM0, sst_set_media_path),
+	SST_PATH_INPUT("pcm1_in", SST_TASK_SBA, SST_SWM_IN_PCM1, sst_set_media_path),
+	SST_PATH_OUTPUT("pcm0_out", SST_TASK_SBA, SST_SWM_OUT_PCM0, sst_set_media_path),
+	SST_PATH_OUTPUT("pcm1_out", SST_TASK_SBA, SST_SWM_OUT_PCM1, sst_set_media_path),
+	SST_PATH_OUTPUT("pcm2_out", SST_TASK_SBA, SST_SWM_OUT_PCM2, sst_set_media_path),
+
+	/* SBA Loops */
+	SST_PATH_INPUT("sprot_loop_in", SST_TASK_SBA, SST_SWM_IN_SPROT_LOOP, NULL),
+	SST_PATH_INPUT("media_loop1_in", SST_TASK_SBA, SST_SWM_IN_MEDIA_LOOP1, NULL),
+	SST_PATH_INPUT("media_loop2_in", SST_TASK_SBA, SST_SWM_IN_MEDIA_LOOP2, NULL),
+	SST_PATH_MEDIA_LOOP_OUTPUT("sprot_loop_out", SST_TASK_SBA, SST_SWM_OUT_SPROT_LOOP, SST_FMT_MONO, sst_set_media_loop),
+	SST_PATH_MEDIA_LOOP_OUTPUT("media_loop1_out", SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP1, SST_FMT_MONO, sst_set_media_loop),
+	SST_PATH_MEDIA_LOOP_OUTPUT("media_loop2_out", SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP2, SST_FMT_STEREO, sst_set_media_loop),
+
+	/* Media Mixers */
+};
+
+static const struct snd_soc_dapm_route intercon[] = {
+	{"media0_in", NULL, "Compress Playback"},
+	{"media1_in", NULL, "Headset Playback"},
+	{"media2_in", NULL, "pcm0_out"},
+
+	{"media0_out mix 0", "media0_in", "media0_in"},
+	{"media0_out mix 0", "media1_in", "media1_in"},
+	{"media0_out mix 0", "media2_in", "media2_in"},
+	{"media0_out mix 0", "media3_in", "media3_in"},
+	{"media1_out mix 0", "media0_in", "media0_in"},
+	{"media1_out mix 0", "media1_in", "media1_in"},
+	{"media1_out mix 0", "media2_in", "media2_in"},
+	{"media1_out mix 0", "media3_in", "media3_in"},
+
+	{"media0_out", NULL, "media0_out mix 0"},
+	{"media1_out", NULL, "media1_out mix 0"},
+	{"pcm0_in", NULL, "media0_out"},
+	{"pcm1_in", NULL, "media1_out"},
+
+	{"Headset Capture", NULL, "pcm1_out"},
+	{"Headset Capture", NULL, "pcm2_out"},
+	{"pcm0_out", NULL, "pcm0_out mix 0"},
+	SST_SBA_MIXER_GRAPH_MAP("pcm0_out mix 0"),
+	{"pcm1_out", NULL, "pcm1_out mix 0"},
+	SST_SBA_MIXER_GRAPH_MAP("pcm1_out mix 0"),
+	{"pcm2_out", NULL, "pcm2_out mix 0"},
+	SST_SBA_MIXER_GRAPH_MAP("pcm2_out mix 0"),
+
+	{"media_loop1_in", NULL, "media_loop1_out"},
+	{"media_loop1_out", NULL, "media_loop1_out mix 0"},
+	SST_SBA_MIXER_GRAPH_MAP("media_loop1_out mix 0"),
+	{"media_loop2_in", NULL, "media_loop2_out"},
+	{"media_loop2_out", NULL, "media_loop2_out mix 0"},
+	SST_SBA_MIXER_GRAPH_MAP("media_loop2_out mix 0"),
+	{"sprot_loop_in", NULL, "sprot_loop_out"},
+	{"sprot_loop_out", NULL, "sprot_loop_out mix 0"},
+	SST_SBA_MIXER_GRAPH_MAP("sprot_loop_out mix 0"),
+
+	{"codec_out0", NULL, "codec_out0 mix 0"},
+	SST_SBA_MIXER_GRAPH_MAP("codec_out0 mix 0"),
+	{"codec_out1", NULL, "codec_out1 mix 0"},
+	SST_SBA_MIXER_GRAPH_MAP("codec_out1 mix 0"),
+
+};
 static const char * const slot_names[] = {
 	"none",
 	"slot 0", "slot 1", "slot 2", "slot 3",
@@ -981,6 +1194,8 @@ static int sst_map_modules_to_pipe(struct snd_soc_platform *platform)
 int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
 {
 	int i, ret = 0;
+	struct snd_soc_dapm_context *dapm =
+			snd_soc_component_get_dapm(&platform->component);
 	struct sst_data *drv = snd_soc_platform_get_drvdata(platform);
 
 	drv->byte_stream = devm_kzalloc(platform->dev,
@@ -988,6 +1203,11 @@ int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform)
 	if (!drv->byte_stream)
 		return -ENOMEM;
 
+	snd_soc_dapm_new_controls(dapm, sst_dapm_widgets,
+			ARRAY_SIZE(sst_dapm_widgets));
+	snd_soc_dapm_add_routes(dapm, intercon,
+			ARRAY_SIZE(intercon));
+	snd_soc_dapm_new_widgets(dapm->card);
 
 	for (i = 0; i < SST_NUM_GAINS; i++) {
 		sst_gains[i].mute = SST_GAIN_MUTE_DEFAULT;
sound/soc/intel/sst-mfld-platform.h +4 -0
index 1f42b9ce5554..09ecf44f33fb 100644
@@ -146,6 +146,10 @@ struct sst_device {
 struct sst_data;
 
 int sst_dsp_init_v2_dpcm(struct snd_soc_platform *platform);
+int sst_send_pipe_gains(struct snd_soc_dai *dai, int stream, int mute);
+void send_ssp_cmd(struct snd_soc_dai *dai, const char *id, bool enable);
+void sst_handle_vb_timer(struct snd_soc_dai *dai, bool enable);
+
 void sst_set_stream_status(struct sst_runtime_stream *stream, int state);
 int sst_fill_stream_params(void *substream, const struct sst_data *ctx,
 			   struct snd_sst_params *str_params, bool is_compress);
Signature · 1 line
1.9.0
maintainer
#31 lore raw

Re: [v4 10/12] ASoC: Intel: mrfld: add the DSP DAPM widgets

sound/soc/intel/sst-atom-controls.c static void sst_set_pipe_gain(struct sst_ids *ids, struct sst_data *drv, int mut · line 564

Quoted 7 lines · Subhransu S. Prusty
sound/soc/intel/sst-atom-controls.c +7 -0
+	pr_debug("%s: widget = %s\n", __func__, w->name);
+	for (i = 0; i < w->num_kcontrols; i++) {
+		if (dapm_kcontrol_get_value(w->kcontrols[i])) {
+			mc = (struct soc_mixer_control *)(w->kcontrols[i])->private_value;
+			val |= 1 << mc->shift;
+		}
+	}

All my concerns about this still stand - using something called _get_value() to do something other than read the control value (which this does - it uses it as a boolean then does something else to read the value) which doesn't seem good.

#32 lore raw

Re: [alsa-devel] [v4 10/12] ASoC: Intel: mrfld: add the DSP DAPM widgets

Quoted 14 lines · Mark Brown

sound/soc/intel/sst-atom-controls.c static void sst_set_pipe_gain(struct sst_ids *ids, struct sst_data *drv, int mut · line 564

Quoted 7 lines · Subhransu S. Prusty
sound/soc/intel/sst-atom-controls.c +7 -0
+	pr_debug("%s: widget = %s\n", __func__, w->name);
+	for (i = 0; i < w->num_kcontrols; i++) {
+		if (dapm_kcontrol_get_value(w->kcontrols[i])) {
+			mc = (struct soc_mixer_control *)(w->kcontrols[i])->private_value;
+			val |= 1 << mc->shift;
+		}
+	}

All my concerns about this still stand - using something called _get_value() to do something other than read the control value (which this does - it uses it as a boolean then does something else to read the value) which doesn't seem good.

I think this can be optimized. This need a bit of rework in the code, but need to check. But this would need an assumption that the controls are created in order.

for (i = 0; i < w->num_kcontrols; i++) {
	if (dapm_kcontrol_get_value(w->kcontrols[i])) {
		val |= 1 << i;
}

Is this ok?

Signature · 4 lines
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
maintainer
#33 lore raw

Re: [v4 10/12] ASoC: Intel: mrfld: add the DSP DAPM widgets

Quoted 20 lines · Subhransu S. Prusty
Quoted 14 lines · Mark Brown

sound/soc/intel/sst-atom-controls.c static void sst_set_pipe_gain(struct sst_ids *ids, struct sst_data *drv, int mut · line 564

Quoted 7 lines · Subhransu S. Prusty
sound/soc/intel/sst-atom-controls.c +7 -0
+	pr_debug("%s: widget = %s\n", __func__, w->name);
+	for (i = 0; i < w->num_kcontrols; i++) {
+		if (dapm_kcontrol_get_value(w->kcontrols[i])) {
+			mc = (struct soc_mixer_control *)(w->kcontrols[i])->private_value;
+			val |= 1 << mc->shift;
+		}
+	}

All my concerns about this still stand - using something called _get_value() to do something other than read the control value (which this does - it uses it as a boolean then does something else to read the value) which doesn't seem good.

I think this can be optimized. This need a bit of rework in the code, but need to check. But this would need an assumption that the controls are created in order.

Quoted 6 lines
for (i = 0; i < w->num_kcontrols; i++) {
	if (dapm_kcontrol_get_value(w->kcontrols[i])) {
		val |= 1 << i;
}

Is this ok?

No, that doesn't seem safe. Why not read the data from the control - if we were calling a function which returned the value that'd be much clearer.

#34 lore raw

Re: [alsa-devel] [v4 10/12] ASoC: Intel: mrfld: add the DSP DAPM widgets

Quoted 26 lines · Mark Brown
Quoted 24 lines · Subhransu S. Prusty
Quoted 14 lines · Mark Brown

sound/soc/intel/sst-atom-controls.c static void sst_set_pipe_gain(struct sst_ids *ids, struct sst_data *drv, int mut · line 564

Quoted 7 lines · Subhransu S. Prusty
sound/soc/intel/sst-atom-controls.c +7 -0
+	pr_debug("%s: widget = %s\n", __func__, w->name);
+	for (i = 0; i < w->num_kcontrols; i++) {
+		if (dapm_kcontrol_get_value(w->kcontrols[i])) {
+			mc = (struct soc_mixer_control *)(w->kcontrols[i])->private_value;
+			val |= 1 << mc->shift;
+		}
+	}

All my concerns about this still stand - using something called _get_value() to do something other than read the control value (which this does - it uses it as a boolean then does something else to read the value) which doesn't seem good.

I think this can be optimized. This need a bit of rework in the code, but need to check. But this would need an assumption that the controls are created in order.

for (i = 0; i < w->num_kcontrols; i++) {
	if (dapm_kcontrol_get_value(w->kcontrols[i])) {
		val |= 1 << i;
}
Quoted 5 lines
Quoted 1 line

Is this ok?

No, that doesn't seem safe. Why not read the data from the control - if we were calling a function which returned the value that'd be much clearer.

So lets step back and see what is required here.

I get a mixer update for one of the inputs of the mixer. This needs to be communicated to the DSP via the IPC. But the IPC expects that we send all the values of all the inputs of a mixer to the DSP.

That is why here we are reading the all mixer inputs to find the values and send the bitmap of all inputs.

So from the driver if I have to find out what is the value of the inputs in mixer, how do I do that, is there a simpler way? Or should we push this/<something else> into framework to query

--

Signature · 4 lines
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
maintainer
#35 lore raw

Re: [v4 10/12] ASoC: Intel: mrfld: add the DSP DAPM widgets

Quoted 19 lines · Subhransu S. Prusty
Quoted 10 lines · Mark Brown
Quoted 6 lines
for (i = 0; i < w->num_kcontrols; i++) {
	if (dapm_kcontrol_get_value(w->kcontrols[i])) {
		val |= 1 << i;
}

Is this ok?

No, that doesn't seem safe. Why not read the data from the control - if we were calling a function which returned the value that'd be much clearer.

So lets step back and see what is required here.

I get a mixer update for one of the inputs of the mixer. This needs to be communicated to the DSP via the IPC. But the IPC expects that we send all the values of all the inputs of a mixer to the DSP.

Quoted 6 lines

That is why here we are reading the all mixer inputs to find the values and send the bitmap of all inputs.

So from the driver if I have to find out what is the value of the inputs in mixer, how do I do that, is there a simpler way? Or should we push this/<something else> into framework to query

The problem is that it looks like you are reading the value from the control, treating it as a boolean and discarding it.

#36 lore raw

Re: [alsa-devel] [v4 10/12] ASoC: Intel: mrfld: add the DSP DAPM widgets

Quoted 23 lines · Mark Brown
Quoted 21 lines · Subhransu S. Prusty
Quoted 10 lines · Mark Brown
Quoted 6 lines
for (i = 0; i < w->num_kcontrols; i++) {
	if (dapm_kcontrol_get_value(w->kcontrols[i])) {
		val |= 1 << i;
}

Is this ok?

No, that doesn't seem safe. Why not read the data from the control - if we were calling a function which returned the value that'd be much clearer.

So lets step back and see what is required here.

I get a mixer update for one of the inputs of the mixer. This needs to be communicated to the DSP via the IPC. But the IPC expects that we send all the values of all the inputs of a mixer to the DSP.

That is why here we are reading the all mixer inputs to find the values and send the bitmap of all inputs.

Quoted 6 lines
Quoted 3 lines

So from the driver if I have to find out what is the value of the inputs in mixer, how do I do that, is there a simpler way? Or should we push this/<something else> into framework to query

The problem is that it looks like you are reading the value from the control, treating it as a boolean and discarding it.

Well the mixer input is on/off, so it should be treated as boolean. How will it have any other value.

Btw I am thinking to create an API dapm_kcontrol_get_mixer_values() which can give me bit map of all the mixer inputs, so I can use it and send IPCs to the DSP.

Signature · 4 lines
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
maintainer
#37 lore raw

Re: [v4 10/12] ASoC: Intel: mrfld: add the DSP DAPM widgets

Quoted 7 lines · Subhransu S. Prusty
Quoted 2 lines · Mark Brown

The problem is that it looks like you are reading the value from the control, treating it as a boolean and discarding it.

Well the mixer input is on/off, so it should be treated as boolean. How will it have any other value.

OK, so you're trying to read a boolean value. Perhaps what you need here is some comments then - the way you fiddle about with the bitmasks afterwards doesn't make it sufficient obvious.

#38 lore raw

Re: [v4 10/12] ASoC: Intel: mrfld: add the DSP DAPM widgets

In reply to Mark Brown
Quoted 23 lines · Mark Brown
Quoted 21 lines · Subhransu S. Prusty
Quoted 10 lines · Mark Brown
Quoted 6 lines
for (i = 0; i < w->num_kcontrols; i++) {
	if (dapm_kcontrol_get_value(w->kcontrols[i])) {
		val |= 1 << i;
}

Is this ok?

No, that doesn't seem safe. Why not read the data from the control - if we were calling a function which returned the value that'd be much clearer.

So lets step back and see what is required here.

I get a mixer update for one of the inputs of the mixer. This needs to be communicated to the DSP via the IPC. But the IPC expects that we send all the values of all the inputs of a mixer to the DSP.

That is why here we are reading the all mixer inputs to find the values and send the bitmap of all inputs.

Quoted 6 lines
Quoted 3 lines

So from the driver if I have to find out what is the value of the inputs in mixer, how do I do that, is there a simpler way? Or should we push this/<something else> into framework to query

The problem is that it looks like you are reading the value from the control, treating it as a boolean and discarding it.

Well the mixer input is on/off, so it should be treated as boolean. How will it have any other value.

Btw I am thinking to create an API dapm_kcontrol_get_mixer_values() which can give me bit map of all the mixer inputs, so I can use it and send IPCs to the DSP.

#39 lore raw

Re: [v4 10/12] ASoC: Intel: mrfld: add the DSP DAPM widgets

In reply to Mark Brown
Quoted 26 lines · Mark Brown
Quoted 24 lines · Subhransu S. Prusty
Quoted 14 lines · Mark Brown

sound/soc/intel/sst-atom-controls.c static void sst_set_pipe_gain(struct sst_ids *ids, struct sst_data *drv, int mut · line 564

Quoted 7 lines · Subhransu S. Prusty
sound/soc/intel/sst-atom-controls.c +7 -0
+	pr_debug("%s: widget = %s\n", __func__, w->name);
+	for (i = 0; i < w->num_kcontrols; i++) {
+		if (dapm_kcontrol_get_value(w->kcontrols[i])) {
+			mc = (struct soc_mixer_control *)(w->kcontrols[i])->private_value;
+			val |= 1 << mc->shift;
+		}
+	}

All my concerns about this still stand - using something called _get_value() to do something other than read the control value (which this does - it uses it as a boolean then does something else to read the value) which doesn't seem good.

I think this can be optimized. This need a bit of rework in the code, but need to check. But this would need an assumption that the controls are created in order.

for (i = 0; i < w->num_kcontrols; i++) {
	if (dapm_kcontrol_get_value(w->kcontrols[i])) {
		val |= 1 << i;
}
Quoted 5 lines
Quoted 1 line

Is this ok?

No, that doesn't seem safe. Why not read the data from the control - if we were calling a function which returned the value that'd be much clearer.

So lets step back and see what is required here.

I get a mixer update for one of the inputs of the mixer. This needs to be communicated to the DSP via the IPC. But the IPC expects that we send all the values of all the inputs of a mixer to the DSP.

That is why here we are reading the all mixer inputs to find the values and send the bitmap of all inputs.

So from the driver if I have to find out what is the value of the inputs in mixer, how do I do that, is there a simpler way? Or should we push this/<something else> into framework to query

--

#40 lore raw

Re: [v4 10/12] ASoC: Intel: mrfld: add the DSP DAPM widgets

In reply to Mark Brown
Quoted 14 lines · Mark Brown

sound/soc/intel/sst-atom-controls.c static void sst_set_pipe_gain(struct sst_ids *ids, struct sst_data *drv, int mut · line 564

Quoted 7 lines · Subhransu S. Prusty
sound/soc/intel/sst-atom-controls.c +7 -0
+	pr_debug("%s: widget = %s\n", __func__, w->name);
+	for (i = 0; i < w->num_kcontrols; i++) {
+		if (dapm_kcontrol_get_value(w->kcontrols[i])) {
+			mc = (struct soc_mixer_control *)(w->kcontrols[i])->private_value;
+			val |= 1 << mc->shift;
+		}
+	}

All my concerns about this still stand - using something called _get_value() to do something other than read the control value (which this does - it uses it as a boolean then does something else to read the value) which doesn't seem good.

I think this can be optimized. This need a bit of rework in the code, but need to check. But this would need an assumption that the controls are created in order.

for (i = 0; i < w->num_kcontrols; i++) {
	if (dapm_kcontrol_get_value(w->kcontrols[i])) {
		val |= 1 << i;
}

Is this ok?

#41 lore raw

PATCH v4 11/12 ASoC: Intel: mfld-pcm: add the fe & be dai ops

In reply to Subhransu S. Prusty

From: Vinod Koul <[email protected]>

Now that the DSP topology is added, add the FE and BE dai ops for controls DSP as well mute/unmute of FE through ASoC

---
 sound/soc/intel/sst-mfld-platform-pcm.c | 39 +++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
sound/soc/intel/sst-mfld-platform-pcm.c +39 -0
index 60ee6ad4b626..4e5d2f379a26 100644
@@ -101,6 +101,11 @@ static struct sst_dev_stream_map dpcm_strm_map[] = {
 	{MERR_DPCM_AUDIO, 0, SNDRV_PCM_STREAM_CAPTURE, PIPE_PCM1_OUT, SST_TASK_ID_MEDIA, 0},
 };
 
+static int sst_media_digital_mute(struct snd_soc_dai *dai, int mute, int stream)
+{
+
+	return sst_send_pipe_gains(dai, stream, mute);
+}
 
 /* helper functions */
 void sst_set_stream_status(struct sst_runtime_stream *stream,
@@ -418,12 +423,41 @@ static int sst_media_hw_free(struct snd_pcm_substream *substream,
 	return snd_pcm_lib_free_pages(substream);
 }
 
+static int sst_enable_ssp(struct snd_pcm_substream *substream,
+			struct snd_soc_dai *dai)
+{
+	if (!dai->active) {
+		sst_handle_vb_timer(dai, true);
+		send_ssp_cmd(dai, dai->name, 1);
+	}
+	return 0;
+}
+
+static void sst_disable_ssp(struct snd_pcm_substream *substream,
+			struct snd_soc_dai *dai)
+{
+	if (!dai->active) {
+		send_ssp_cmd(dai, dai->name, 0);
+		sst_handle_vb_timer(dai, false);
+	}
+}
+
 static struct snd_soc_dai_ops sst_media_dai_ops = {
 	.startup = sst_media_open,
 	.shutdown = sst_media_close,
 	.prepare = sst_media_prepare,
 	.hw_params = sst_media_hw_params,
 	.hw_free = sst_media_hw_free,
+	.mute_stream = sst_media_digital_mute,
+};
+
+static struct snd_soc_dai_ops sst_compr_dai_ops = {
+	.mute_stream = sst_media_digital_mute,
+};
+
+static struct snd_soc_dai_ops sst_be_dai_ops = {
+	.startup = sst_enable_ssp,
+	.shutdown = sst_disable_ssp,
 };
 
 static int sst_media_dai_probe(struct snd_soc_dai *cpu_dai)
@@ -433,6 +467,7 @@ static int sst_media_dai_probe(struct snd_soc_dai *cpu_dai)
 	snd_soc_dai_set_drvdata(cpu_dai, sst);
 	return 0;
 }
+
 static struct snd_soc_dai_driver sst_platform_dai[] = {
 {
 	.probe = sst_media_dai_probe,
@@ -456,6 +491,7 @@ static struct snd_soc_dai_driver sst_platform_dai[] = {
 {
 	.name = "compress-cpu-dai",
 	.compress_dai = 1,
+	.ops = &sst_compr_dai_ops,
 	.playback = {
 		.stream_name = "Compress Playback",
 		.channels_min = SST_STEREO,
@@ -467,6 +503,7 @@ static struct snd_soc_dai_driver sst_platform_dai[] = {
 /*BE CPU  Dais */
 {
 	.name = "ssp0-port",
+	.ops = &sst_be_dai_ops,
 	.playback = {
 		.stream_name = "ssp0 Tx",
 		.channels_min = SST_STEREO,
@@ -484,6 +521,7 @@ static struct snd_soc_dai_driver sst_platform_dai[] = {
 },
 {
 	.name = "ssp1-port",
+	.ops = &sst_be_dai_ops,
 	.playback = {
 		.stream_name = "ssp1 Tx",
 		.channels_min = SST_STEREO,
@@ -501,6 +539,7 @@ static struct snd_soc_dai_driver sst_platform_dai[] = {
 },
 {
 	.name = "ssp2-port",
+	.ops = &sst_be_dai_ops,
 	.playback = {
 		.stream_name = "ssp2 Tx",
 		.channels_min = SST_STEREO,
Signature · 1 line
1.9.0
maintainer
#42 lore raw

Re: [v4 11/12] ASoC: Intel: mfld-pcm: add the fe & be dai ops

Quoted 4 lines · Subhransu S. Prusty

From: Vinod Koul <[email protected]>

Now that the DSP topology is added, add the FE and BE dai ops for controls DSP as well mute/unmute of FE through ASoC

It really seems like patch 1 should be part of this change, it'd be much more obvious what's going on then (though the concerns about breaking machine drivers still stand).

Please also try to keep your changelogs comfortably below 80 columns (this is over 80 columns).

#43 lore raw

Re: [v4 11/12] ASoC: Intel: mfld-pcm: add the fe & be dai ops

Quoted 6 lines · Mark Brown
Quoted 4 lines · Subhransu S. Prusty

From: Vinod Koul <[email protected]>

Now that the DSP topology is added, add the FE and BE dai ops for controls DSP as well mute/unmute of FE through ASoC

Quoted 6 lines

It really seems like patch 1 should be part of this change, it'd be much more obvious what's going on then (though the concerns about breaking machine drivers still stand).

Please also try to keep your changelogs comfortably below 80 columns (this is over 80 columns).

Will squash the patches.

#44 lore raw

Re: [alsa-devel] [v4 11/12] ASoC: Intel: mfld-pcm: add the fe & be dai ops

In reply to Mark Brown
Quoted 6 lines · Mark Brown
Quoted 4 lines · Subhransu S. Prusty

From: Vinod Koul <[email protected]>

Now that the DSP topology is added, add the FE and BE dai ops for controls DSP as well mute/unmute of FE through ASoC

Quoted 6 lines

It really seems like patch 1 should be part of this change, it'd be much more obvious what's going on then (though the concerns about breaking machine drivers still stand).

Please also try to keep your changelogs comfortably below 80 columns (this is over 80 columns).

Will squash the patches.

Signature · 4 lines
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#45 lore raw

PATCH v4 12/12 ASoC: Intel: mrfld: add the DSP mixers

In reply to Subhransu S. Prusty

From: Vinod Koul <[email protected]>

---
 sound/soc/intel/sst-atom-controls.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
sound/soc/intel/sst-atom-controls.c +26 -0
index 029e6960ca73..a681abe1ff06 100644
@@ -855,6 +855,32 @@ static const struct snd_soc_dapm_widget sst_dapm_widgets[] = {
 	SST_PATH_MEDIA_LOOP_OUTPUT("media_loop2_out", SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP2, SST_FMT_STEREO, sst_set_media_loop),
 
 	/* Media Mixers */
+	SST_SWM_MIXER("media0_out mix 0", SND_SOC_NOPM, SST_TASK_MMX, SST_SWM_OUT_MEDIA0,
+		      sst_mix_media0_controls, sst_swm_mixer_event),
+	SST_SWM_MIXER("media1_out mix 0", SND_SOC_NOPM, SST_TASK_MMX, SST_SWM_OUT_MEDIA1,
+		      sst_mix_media1_controls, sst_swm_mixer_event),
+
+	/* SBA PCM mixers */
+	SST_SWM_MIXER("pcm0_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_PCM0,
+		      sst_mix_pcm0_controls, sst_swm_mixer_event),
+	SST_SWM_MIXER("pcm1_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_PCM1,
+		      sst_mix_pcm1_controls, sst_swm_mixer_event),
+	SST_SWM_MIXER("pcm2_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_PCM2,
+		      sst_mix_pcm2_controls, sst_swm_mixer_event),
+
+	/* SBA Loop mixers */
+	SST_SWM_MIXER("sprot_loop_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_SPROT_LOOP,
+		      sst_mix_sprot_l0_controls, sst_swm_mixer_event),
+	SST_SWM_MIXER("media_loop1_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP1,
+		      sst_mix_media_l1_controls, sst_swm_mixer_event),
+	SST_SWM_MIXER("media_loop2_out mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_MEDIA_LOOP2,
+		      sst_mix_media_l2_controls, sst_swm_mixer_event),
+
+	/* SBA Backend mixers */
+	SST_SWM_MIXER("codec_out0 mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_CODEC0,
+		      sst_mix_codec0_controls, sst_swm_mixer_event),
+	SST_SWM_MIXER("codec_out1 mix 0", SND_SOC_NOPM, SST_TASK_SBA, SST_SWM_OUT_CODEC1,
+		      sst_mix_codec1_controls, sst_swm_mixer_event),
 };
 
 static const struct snd_soc_dapm_route intercon[] = {
Signature · 1 line
1.9.0