All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: Intel: Multiple I/O PCM format support for pipe
@ 2020-04-02 14:41 Mateusz Gorski
  2020-04-02 15:33 ` Pierre-Louis Bossart
  0 siblings, 1 reply; 2+ messages in thread
From: Mateusz Gorski @ 2020-04-02 14:41 UTC (permalink / raw)
  To: alsa-devel; +Cc: cezary.rojewski, Pavan K, tiwai, Mateusz Gorski, S

If a pipe supports multiple input/output formats, kcontrol is
created and selection of pipe input and output configuration
is done based on control set.
Effectively allows user to select configuration using amixer settings.

Signed-off-by: Mateusz Gorski <mateusz.gorski@linux.intel.com>
Signed-off-by: S, Pavan K <pavan.k.s@intel.com>
---
 include/uapi/sound/skl-tplg-interface.h |   1 +
 sound/soc/intel/skylake/skl-topology.c  | 110 ++++++++++++++++++++++++
 sound/soc/intel/skylake/skl-topology.h  |   1 +
 3 files changed, 112 insertions(+)

diff --git a/include/uapi/sound/skl-tplg-interface.h b/include/uapi/sound/skl-tplg-interface.h
index 9eee32f5e407..f2711186c81f 100644
--- a/include/uapi/sound/skl-tplg-interface.h
+++ b/include/uapi/sound/skl-tplg-interface.h
@@ -18,6 +18,7 @@
  */
 #define SKL_CONTROL_TYPE_BYTE_TLV	0x100
 #define SKL_CONTROL_TYPE_MIC_SELECT	0x102
+#define SKL_CONTROL_TYPE_MULTI_IO_SELECT	0x103
 
 #define HDA_SST_CFG_MAX	900 /* size of copier cfg*/
 #define MAX_IN_QUEUE 8
diff --git a/sound/soc/intel/skylake/skl-topology.c b/sound/soc/intel/skylake/skl-topology.c
index 344b06df0e15..de60b6873666 100644
--- a/sound/soc/intel/skylake/skl-topology.c
+++ b/sound/soc/intel/skylake/skl-topology.c
@@ -578,6 +578,38 @@ static int skl_tplg_unload_pipe_modules(struct skl_dev *skl,
 	return ret;
 }
 
+static bool skl_tplg_is_multi_fmt(struct skl_dev *skl, struct skl_pipe *pipe)
+{
+	int i;
+	struct skl_pipe_fmt *cur_fmt;
+	struct skl_pipe_fmt *next_fmt;
+
+	if (pipe->nr_cfgs <= 1)
+		return false;
+
+	if (pipe->conn_type != SKL_PIPE_CONN_TYPE_FE)
+		return true;
+
+	for (i = 0; i < pipe->nr_cfgs - 1; i++) {
+		if (pipe->direction == SNDRV_PCM_STREAM_PLAYBACK) {
+			cur_fmt = &pipe->configs[i].out_fmt;
+			next_fmt = &pipe->configs[i+1].out_fmt;
+		} else {
+			cur_fmt = &pipe->configs[i].in_fmt;
+			next_fmt = &pipe->configs[i+1].in_fmt;
+		}
+
+		if (!CHECK_HW_PARAMS(cur_fmt->channels, cur_fmt->freq,
+				     cur_fmt->bps,
+				     next_fmt->channels,
+				     next_fmt->freq,
+				     next_fmt->bps))
+			return true;
+	}
+
+	return false;
+}
+
 /*
  * Here, we select pipe format based on the pipe type and pipe
  * direction to determine the current config index for the pipeline.
@@ -600,6 +632,14 @@ skl_tplg_get_pipe_config(struct skl_dev *skl, struct skl_module_cfg *mconfig)
 		return 0;
 	}
 
+	if (skl_tplg_is_multi_fmt(skl, pipe)) {
+		pipe->cur_config_idx = pipe->pipe_config_idx;
+		pipe->memory_pages = pconfig->mem_pages;
+		dev_dbg(skl->dev, "found pipe config idx:%d\n",
+			pipe->cur_config_idx);
+		return 0;
+	}
+
 	if (pipe->conn_type == SKL_PIPE_CONN_TYPE_NONE) {
 		dev_dbg(skl->dev, "No conn_type detected, take 0th config\n");
 		pipe->cur_config_idx = 0;
@@ -1314,6 +1354,71 @@ static int skl_tplg_pga_event(struct snd_soc_dapm_widget *w,
 	return 0;
 }
 
+static int skl_tplg_multi_config_get(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+		snd_soc_kcontrol_component(kcontrol);
+	struct hdac_bus *bus = snd_soc_component_get_drvdata(component);
+	struct skl_dev *skl = bus_to_skl(bus);
+	struct skl_pipeline *ppl;
+	struct skl_pipe *pipe = NULL;
+	u32 *pipe_id;
+	struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value;
+
+	if (!ec)
+		return -EINVAL;
+
+	pipe_id = ec->dobj.private;
+
+	list_for_each_entry(ppl, &skl->ppl_list, node) {
+		if (ppl->pipe->ppl_id == *pipe_id) {
+			pipe = ppl->pipe;
+			break;
+		}
+	}
+	if (!pipe)
+		return -EIO;
+
+	ucontrol->value.enumerated.item[0]  =  pipe->pipe_config_idx;
+
+	return 0;
+}
+
+static int skl_tplg_multi_config_set(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =
+	       snd_soc_kcontrol_component(kcontrol);
+	struct hdac_bus *bus = snd_soc_component_get_drvdata(component);
+	struct skl_dev *skl = bus_to_skl(bus);
+	struct skl_pipeline *ppl;
+	struct skl_pipe *pipe = NULL;
+	struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value;
+	u32 *pipe_id;
+
+	if (!ec)
+		return -EINVAL;
+
+	if (ucontrol->value.enumerated.item[0] > ec->items)
+		return -EINVAL;
+
+	pipe_id = ec->dobj.private;
+
+	list_for_each_entry(ppl, &skl->ppl_list, node) {
+		if (ppl->pipe->ppl_id == *pipe_id) {
+			pipe = ppl->pipe;
+			break;
+		}
+	}
+	if (!pipe)
+		return -EIO;
+
+	pipe->pipe_config_idx = ucontrol->value.enumerated.item[0];
+
+	return 0;
+}
+
 static int skl_tplg_tlv_control_get(struct snd_kcontrol *kcontrol,
 			unsigned int __user *data, unsigned int size)
 {
@@ -1853,6 +1958,11 @@ static const struct snd_soc_tplg_kcontrol_ops skl_tplg_kcontrol_ops[] = {
 		.get = skl_tplg_mic_control_get,
 		.put = skl_tplg_mic_control_set,
 	},
+	{
+		.id = SKL_CONTROL_TYPE_MULTI_IO_SELECT,
+		.get = skl_tplg_multi_config_get,
+		.put = skl_tplg_multi_config_set,
+	},
 };
 
 static int skl_tplg_fill_pipe_cfg(struct device *dev,
diff --git a/sound/soc/intel/skylake/skl-topology.h b/sound/soc/intel/skylake/skl-topology.h
index e967800dbb62..06576147cc29 100644
--- a/sound/soc/intel/skylake/skl-topology.h
+++ b/sound/soc/intel/skylake/skl-topology.h
@@ -306,6 +306,7 @@ struct skl_pipe {
 	struct skl_path_config configs[SKL_MAX_PATH_CONFIGS];
 	struct list_head w_list;
 	bool passthru;
+	u32 pipe_config_idx;
 };
 
 enum skl_module_state {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ASoC: Intel: Multiple I/O PCM format support for pipe
  2020-04-02 14:41 [PATCH] ASoC: Intel: Multiple I/O PCM format support for pipe Mateusz Gorski
@ 2020-04-02 15:33 ` Pierre-Louis Bossart
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre-Louis Bossart @ 2020-04-02 15:33 UTC (permalink / raw)
  To: Mateusz Gorski, alsa-devel; +Cc: cezary.rojewski, Pavan K, tiwai



On 4/2/20 9:41 AM, Mateusz Gorski wrote:
> If a pipe supports multiple input/output formats, kcontrol is
> created and selection of pipe input and output configuration
> is done based on control set.
> Effectively allows user to select configuration using amixer settings.

I don't get the direction, sorry.

If a platform has two digital microphones, the user could configure 4-ch 
capture - the NHLT information on number of microphones is ignored?

Or are you expecting user space (e.g. UCM) to retrieve the number of 
microphones from the card component string and program the new control 
accordingly?

> 
> Signed-off-by: Mateusz Gorski <mateusz.gorski@linux.intel.com>
> Signed-off-by: S, Pavan K <pavan.k.s@intel.com>
> ---
>   include/uapi/sound/skl-tplg-interface.h |   1 +
>   sound/soc/intel/skylake/skl-topology.c  | 110 ++++++++++++++++++++++++
>   sound/soc/intel/skylake/skl-topology.h  |   1 +
>   3 files changed, 112 insertions(+)
> 
> diff --git a/include/uapi/sound/skl-tplg-interface.h b/include/uapi/sound/skl-tplg-interface.h
> index 9eee32f5e407..f2711186c81f 100644
> --- a/include/uapi/sound/skl-tplg-interface.h
> +++ b/include/uapi/sound/skl-tplg-interface.h
> @@ -18,6 +18,7 @@
>    */
>   #define SKL_CONTROL_TYPE_BYTE_TLV	0x100
>   #define SKL_CONTROL_TYPE_MIC_SELECT	0x102
> +#define SKL_CONTROL_TYPE_MULTI_IO_SELECT	0x103
>   
>   #define HDA_SST_CFG_MAX	900 /* size of copier cfg*/
>   #define MAX_IN_QUEUE 8
> diff --git a/sound/soc/intel/skylake/skl-topology.c b/sound/soc/intel/skylake/skl-topology.c
> index 344b06df0e15..de60b6873666 100644
> --- a/sound/soc/intel/skylake/skl-topology.c
> +++ b/sound/soc/intel/skylake/skl-topology.c
> @@ -578,6 +578,38 @@ static int skl_tplg_unload_pipe_modules(struct skl_dev *skl,
>   	return ret;
>   }
>   
> +static bool skl_tplg_is_multi_fmt(struct skl_dev *skl, struct skl_pipe *pipe)
> +{
> +	int i;
> +	struct skl_pipe_fmt *cur_fmt;
> +	struct skl_pipe_fmt *next_fmt;
> +
> +	if (pipe->nr_cfgs <= 1)
> +		return false;
> +
> +	if (pipe->conn_type != SKL_PIPE_CONN_TYPE_FE)
> +		return true;
> +
> +	for (i = 0; i < pipe->nr_cfgs - 1; i++) {
> +		if (pipe->direction == SNDRV_PCM_STREAM_PLAYBACK) {
> +			cur_fmt = &pipe->configs[i].out_fmt;
> +			next_fmt = &pipe->configs[i+1].out_fmt;
> +		} else {
> +			cur_fmt = &pipe->configs[i].in_fmt;
> +			next_fmt = &pipe->configs[i+1].in_fmt;
> +		}
> +
> +		if (!CHECK_HW_PARAMS(cur_fmt->channels, cur_fmt->freq,
> +				     cur_fmt->bps,
> +				     next_fmt->channels,
> +				     next_fmt->freq,
> +				     next_fmt->bps))
> +			return true;
> +	}
> +
> +	return false;
> +}
> +
>   /*
>    * Here, we select pipe format based on the pipe type and pipe
>    * direction to determine the current config index for the pipeline.
> @@ -600,6 +632,14 @@ skl_tplg_get_pipe_config(struct skl_dev *skl, struct skl_module_cfg *mconfig)
>   		return 0;
>   	}
>   
> +	if (skl_tplg_is_multi_fmt(skl, pipe)) {
> +		pipe->cur_config_idx = pipe->pipe_config_idx;
> +		pipe->memory_pages = pconfig->mem_pages;
> +		dev_dbg(skl->dev, "found pipe config idx:%d\n",
> +			pipe->cur_config_idx);
> +		return 0;
> +	}
> +
>   	if (pipe->conn_type == SKL_PIPE_CONN_TYPE_NONE) {
>   		dev_dbg(skl->dev, "No conn_type detected, take 0th config\n");
>   		pipe->cur_config_idx = 0;
> @@ -1314,6 +1354,71 @@ static int skl_tplg_pga_event(struct snd_soc_dapm_widget *w,
>   	return 0;
>   }
>   
> +static int skl_tplg_multi_config_get(struct snd_kcontrol *kcontrol,
> +			struct snd_ctl_elem_value *ucontrol)
> +{
> +	struct snd_soc_component *component =
> +		snd_soc_kcontrol_component(kcontrol);
> +	struct hdac_bus *bus = snd_soc_component_get_drvdata(component);
> +	struct skl_dev *skl = bus_to_skl(bus);
> +	struct skl_pipeline *ppl;
> +	struct skl_pipe *pipe = NULL;
> +	u32 *pipe_id;
> +	struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value;
> +
> +	if (!ec)
> +		return -EINVAL;
> +
> +	pipe_id = ec->dobj.private;
> +
> +	list_for_each_entry(ppl, &skl->ppl_list, node) {
> +		if (ppl->pipe->ppl_id == *pipe_id) {
> +			pipe = ppl->pipe;
> +			break;
> +		}
> +	}
> +	if (!pipe)
> +		return -EIO;
> +
> +	ucontrol->value.enumerated.item[0]  =  pipe->pipe_config_idx;
> +
> +	return 0;
> +}
> +
> +static int skl_tplg_multi_config_set(struct snd_kcontrol *kcontrol,
> +			struct snd_ctl_elem_value *ucontrol)
> +{
> +	struct snd_soc_component *component =
> +	       snd_soc_kcontrol_component(kcontrol);
> +	struct hdac_bus *bus = snd_soc_component_get_drvdata(component);
> +	struct skl_dev *skl = bus_to_skl(bus);
> +	struct skl_pipeline *ppl;
> +	struct skl_pipe *pipe = NULL;
> +	struct soc_enum *ec = (struct soc_enum *)kcontrol->private_value;
> +	u32 *pipe_id;
> +
> +	if (!ec)
> +		return -EINVAL;
> +
> +	if (ucontrol->value.enumerated.item[0] > ec->items)
> +		return -EINVAL;
> +
> +	pipe_id = ec->dobj.private;
> +
> +	list_for_each_entry(ppl, &skl->ppl_list, node) {
> +		if (ppl->pipe->ppl_id == *pipe_id) {
> +			pipe = ppl->pipe;
> +			break;
> +		}
> +	}
> +	if (!pipe)
> +		return -EIO;
> +
> +	pipe->pipe_config_idx = ucontrol->value.enumerated.item[0];
> +
> +	return 0;
> +}
> +
>   static int skl_tplg_tlv_control_get(struct snd_kcontrol *kcontrol,
>   			unsigned int __user *data, unsigned int size)
>   {
> @@ -1853,6 +1958,11 @@ static const struct snd_soc_tplg_kcontrol_ops skl_tplg_kcontrol_ops[] = {
>   		.get = skl_tplg_mic_control_get,
>   		.put = skl_tplg_mic_control_set,
>   	},
> +	{
> +		.id = SKL_CONTROL_TYPE_MULTI_IO_SELECT,
> +		.get = skl_tplg_multi_config_get,
> +		.put = skl_tplg_multi_config_set,
> +	},
>   };
>   
>   static int skl_tplg_fill_pipe_cfg(struct device *dev,
> diff --git a/sound/soc/intel/skylake/skl-topology.h b/sound/soc/intel/skylake/skl-topology.h
> index e967800dbb62..06576147cc29 100644
> --- a/sound/soc/intel/skylake/skl-topology.h
> +++ b/sound/soc/intel/skylake/skl-topology.h
> @@ -306,6 +306,7 @@ struct skl_pipe {
>   	struct skl_path_config configs[SKL_MAX_PATH_CONFIGS];
>   	struct list_head w_list;
>   	bool passthru;
> +	u32 pipe_config_idx;
>   };
>   
>   enum skl_module_state {
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-02 15:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-02 14:41 [PATCH] ASoC: Intel: Multiple I/O PCM format support for pipe Mateusz Gorski
2020-04-02 15:33 ` Pierre-Louis Bossart

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.