alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/3] DT binding for sample format conversion
@ 2022-08-08  5:27 Sameer Pujar
  2022-08-08  5:27 ` [PATCH v3 1/3] ASoC: dt-bindings: Definitions for DAI params Sameer Pujar
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Sameer Pujar @ 2022-08-08  5:27 UTC (permalink / raw)
  To: broonie, lgirdwood, robh+dt, krzysztof.kozlowski+dt, perex,
	tiwai, kuninori.morimoto.gx
  Cc: Sameer Pujar, devicetree, alsa-devel, linux-kernel

DT binding properties are available to fixup rate and channel
parameters of a DAI. This series extends this to sample format
conversion as well. With this now DAI PCM parameters (channels,
sample rate and sample format) can be fixed up as necessary in
an audio path.

Changelog:
==========
  v2->v3:
  -------
    * Fix DT binding errors in simple-card.yaml
    * Drop simple-card binding changes from the series since
      there is no usage requirement. It can be extended later
      when necessary.
    * Use definitions instead of properties in the common schema
      and re-use this in audio-graph related bindings.

  v1->v2:
  -------
    * Move DAI params properties to a new schema and re-use this
      for simple-card and audio-graph-card.
    * Use string type for DAI format binding as suggested by
      Krzysztof.


Sameer Pujar (3):
  ASoC: dt-bindings: Definitions for DAI params
  ASoC: dt-bindings: Add sample format conversion
  ASoC: simple-card-utils: Fixup DAI sample format

 .../bindings/sound/audio-graph-port.yaml           | 17 ++++-----
 .../devicetree/bindings/sound/audio-graph.yaml     |  9 ++---
 .../devicetree/bindings/sound/dai-params.yaml      | 40 ++++++++++++++++++++++
 include/sound/simple_card_utils.h                  |  1 +
 sound/soc/generic/simple-card-utils.c              | 34 ++++++++++++++++++
 5 files changed, 89 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/dai-params.yaml

-- 
2.7.4


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

* [PATCH v3 1/3] ASoC: dt-bindings: Definitions for DAI params
  2022-08-08  5:27 [PATCH v3 0/3] DT binding for sample format conversion Sameer Pujar
@ 2022-08-08  5:27 ` Sameer Pujar
  2022-08-08  5:27 ` [PATCH v3 2/3] ASoC: dt-bindings: Add sample format conversion Sameer Pujar
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Sameer Pujar @ 2022-08-08  5:27 UTC (permalink / raw)
  To: broonie, lgirdwood, robh+dt, krzysztof.kozlowski+dt, perex,
	tiwai, kuninori.morimoto.gx
  Cc: Sameer Pujar, devicetree, alsa-devel, linux-kernel

The "convert-channels" and "convert-rate" bindings are available for
audio-graph-card and are documented in the audio-graph-port.yaml and
the audio-graph.yaml. There is duplication of property details at
multiple places.

Introduce a new schema to have common definitions for DAI params and
these can be re-used in other schemas wherever applicable. Presently
update audio-graph-card bindings to use these definitions. If required
simple-card bindings can be extended to make use of common definitions.

Signed-off-by: Sameer Pujar <spujar@nvidia.com>
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 .../bindings/sound/audio-graph-port.yaml           | 13 ++++------
 .../devicetree/bindings/sound/audio-graph.yaml     |  7 +++--
 .../devicetree/bindings/sound/dai-params.yaml      | 30 ++++++++++++++++++++++
 3 files changed, 38 insertions(+), 12 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/dai-params.yaml

diff --git a/Documentation/devicetree/bindings/sound/audio-graph-port.yaml b/Documentation/devicetree/bindings/sound/audio-graph-port.yaml
index 5c36867..fa3931b 100644
--- a/Documentation/devicetree/bindings/sound/audio-graph-port.yaml
+++ b/Documentation/devicetree/bindings/sound/audio-graph-port.yaml
@@ -19,11 +19,10 @@ properties:
     description: "device name prefix"
     $ref: /schemas/types.yaml#/definitions/string
   convert-rate:
-    description: CPU to Codec rate convert.
-    $ref: /schemas/types.yaml#/definitions/uint32
+    $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-rate"
   convert-channels:
-    description: CPU to Codec rate channels.
-    $ref: /schemas/types.yaml#/definitions/uint32
+    $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-channels"
+
 patternProperties:
   "^endpoint(@[0-9a-f]+)?":
     $ref: /schemas/graph.yaml#/$defs/endpoint-base
@@ -65,11 +64,9 @@ patternProperties:
             - msb
             - lsb
       convert-rate:
-        description: CPU to Codec rate convert.
-        $ref: /schemas/types.yaml#/definitions/uint32
+        $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-rate"
       convert-channels:
-        description: CPU to Codec rate channels.
-        $ref: /schemas/types.yaml#/definitions/uint32
+        $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-channels"
 
       dai-tdm-slot-width-map:
         description: Mapping of sample widths to slot widths. For hardware
diff --git a/Documentation/devicetree/bindings/sound/audio-graph.yaml b/Documentation/devicetree/bindings/sound/audio-graph.yaml
index 4b46794..ffee5c9 100644
--- a/Documentation/devicetree/bindings/sound/audio-graph.yaml
+++ b/Documentation/devicetree/bindings/sound/audio-graph.yaml
@@ -27,11 +27,10 @@ properties:
     description: User specified audio sound widgets.
     $ref: /schemas/types.yaml#/definitions/non-unique-string-array
   convert-rate:
-    description: CPU to Codec rate convert.
-    $ref: /schemas/types.yaml#/definitions/uint32
+    $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-rate"
   convert-channels:
-    description: CPU to Codec rate channels.
-    $ref: /schemas/types.yaml#/definitions/uint32
+    $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-channels"
+
   pa-gpios:
     maxItems: 1
   hp-det-gpio:
diff --git a/Documentation/devicetree/bindings/sound/dai-params.yaml b/Documentation/devicetree/bindings/sound/dai-params.yaml
new file mode 100644
index 0000000..f1421a0
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/dai-params.yaml
@@ -0,0 +1,30 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/dai-params.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Digital Audio Interface (DAI) Stream Parameters
+
+maintainers:
+  - Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
+
+select: false
+
+$defs:
+
+  dai-channels:
+    description: Number of audio channels used by DAI
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 1
+    maximum: 32
+
+  dai-sample-rate:
+    description: Audio sample rate used by DAI
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 8000
+    maximum: 192000
+
+properties: {}
+
+additionalProperties: true
-- 
2.7.4


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

* [PATCH v3 2/3] ASoC: dt-bindings: Add sample format conversion
  2022-08-08  5:27 [PATCH v3 0/3] DT binding for sample format conversion Sameer Pujar
  2022-08-08  5:27 ` [PATCH v3 1/3] ASoC: dt-bindings: Definitions for DAI params Sameer Pujar
@ 2022-08-08  5:27 ` Sameer Pujar
  2022-08-09 20:15   ` Rob Herring
  2022-08-08  5:27 ` [PATCH v3 3/3] ASoC: simple-card-utils: Fixup DAI sample format Sameer Pujar
  2022-08-15 16:23 ` [PATCH v3 0/3] DT binding for sample format conversion Mark Brown
  3 siblings, 1 reply; 6+ messages in thread
From: Sameer Pujar @ 2022-08-08  5:27 UTC (permalink / raw)
  To: broonie, lgirdwood, robh+dt, krzysztof.kozlowski+dt, perex,
	tiwai, kuninori.morimoto.gx
  Cc: Sameer Pujar, devicetree, alsa-devel, linux-kernel

Presently "convert-channels" and "convert-rate" DT bindings are available
for channel and rate fixups respectively.

Similarly add "convert-sample-format" binding to fixup DAI sample format
as well. This is added to audio-graph-card based bindings.

Signed-off-by: Sameer Pujar <spujar@nvidia.com>
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 Documentation/devicetree/bindings/sound/audio-graph-port.yaml |  4 ++++
 Documentation/devicetree/bindings/sound/audio-graph.yaml      |  2 ++
 Documentation/devicetree/bindings/sound/dai-params.yaml       | 10 ++++++++++
 3 files changed, 16 insertions(+)

diff --git a/Documentation/devicetree/bindings/sound/audio-graph-port.yaml b/Documentation/devicetree/bindings/sound/audio-graph-port.yaml
index fa3931b..7ff7a4a 100644
--- a/Documentation/devicetree/bindings/sound/audio-graph-port.yaml
+++ b/Documentation/devicetree/bindings/sound/audio-graph-port.yaml
@@ -22,6 +22,8 @@ properties:
     $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-rate"
   convert-channels:
     $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-channels"
+  convert-sample-format:
+    $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-format"
 
 patternProperties:
   "^endpoint(@[0-9a-f]+)?":
@@ -67,6 +69,8 @@ patternProperties:
         $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-rate"
       convert-channels:
         $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-channels"
+      convert-sample-format:
+        $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-format"
 
       dai-tdm-slot-width-map:
         description: Mapping of sample widths to slot widths. For hardware
diff --git a/Documentation/devicetree/bindings/sound/audio-graph.yaml b/Documentation/devicetree/bindings/sound/audio-graph.yaml
index ffee5c9..aaa99c2 100644
--- a/Documentation/devicetree/bindings/sound/audio-graph.yaml
+++ b/Documentation/devicetree/bindings/sound/audio-graph.yaml
@@ -30,6 +30,8 @@ properties:
     $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-rate"
   convert-channels:
     $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-channels"
+  convert-sample-format:
+    $ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-format"
 
   pa-gpios:
     maxItems: 1
diff --git a/Documentation/devicetree/bindings/sound/dai-params.yaml b/Documentation/devicetree/bindings/sound/dai-params.yaml
index f1421a0..f5fb71f 100644
--- a/Documentation/devicetree/bindings/sound/dai-params.yaml
+++ b/Documentation/devicetree/bindings/sound/dai-params.yaml
@@ -19,6 +19,16 @@ $defs:
     minimum: 1
     maximum: 32
 
+  dai-sample-format:
+    description: Audio sample format used by DAI
+    $ref: /schemas/types.yaml#/definitions/string
+    enum:
+      - s8
+      - s16_le
+      - s24_le
+      - s24_3le
+      - s32_le
+
   dai-sample-rate:
     description: Audio sample rate used by DAI
     $ref: /schemas/types.yaml#/definitions/uint32
-- 
2.7.4


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

* [PATCH v3 3/3] ASoC: simple-card-utils: Fixup DAI sample format
  2022-08-08  5:27 [PATCH v3 0/3] DT binding for sample format conversion Sameer Pujar
  2022-08-08  5:27 ` [PATCH v3 1/3] ASoC: dt-bindings: Definitions for DAI params Sameer Pujar
  2022-08-08  5:27 ` [PATCH v3 2/3] ASoC: dt-bindings: Add sample format conversion Sameer Pujar
@ 2022-08-08  5:27 ` Sameer Pujar
  2022-08-15 16:23 ` [PATCH v3 0/3] DT binding for sample format conversion Mark Brown
  3 siblings, 0 replies; 6+ messages in thread
From: Sameer Pujar @ 2022-08-08  5:27 UTC (permalink / raw)
  To: broonie, lgirdwood, robh+dt, krzysztof.kozlowski+dt, perex,
	tiwai, kuninori.morimoto.gx
  Cc: Sameer Pujar, devicetree, alsa-devel, linux-kernel

Parse "convert-sample-format" DT binding and fixup the sample format
as applicable. This is similar to the existing "convert-channels" and
"convert-rate" properties for channels and rate fixup respectively.

Signed-off-by: Sameer Pujar <spujar@nvidia.com>
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 include/sound/simple_card_utils.h     |  1 +
 sound/soc/generic/simple-card-utils.c | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h
index ab55f40..a0b827f 100644
--- a/include/sound/simple_card_utils.h
+++ b/include/sound/simple_card_utils.h
@@ -39,6 +39,7 @@ struct asoc_simple_dai {
 struct asoc_simple_data {
 	u32 convert_rate;
 	u32 convert_channels;
+	const char *convert_sample_format;
 };
 
 struct asoc_simple_jack {
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 4a29e31..1b201dd 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -15,6 +15,33 @@
 #include <sound/pcm_params.h>
 #include <sound/simple_card_utils.h>
 
+static void asoc_simple_fixup_sample_fmt(struct asoc_simple_data *data,
+					 struct snd_pcm_hw_params *params)
+{
+	int i;
+	struct snd_mask *mask = hw_param_mask(params,
+					      SNDRV_PCM_HW_PARAM_FORMAT);
+	struct {
+		char *fmt;
+		u32 val;
+	} of_sample_fmt_table[] = {
+		{ "s8",		SNDRV_PCM_FORMAT_S8},
+		{ "s16_le",	SNDRV_PCM_FORMAT_S16_LE},
+		{ "s24_le",	SNDRV_PCM_FORMAT_S24_LE},
+		{ "s24_3le",	SNDRV_PCM_FORMAT_S24_3LE},
+		{ "s32_le",	SNDRV_PCM_FORMAT_S32_LE},
+	};
+
+	for (i = 0; i < ARRAY_SIZE(of_sample_fmt_table); i++) {
+		if (!strcmp(data->convert_sample_format,
+			    of_sample_fmt_table[i].fmt)) {
+			snd_mask_none(mask);
+			snd_mask_set(mask, of_sample_fmt_table[i].val);
+			break;
+		}
+	}
+}
+
 void asoc_simple_convert_fixup(struct asoc_simple_data *data,
 			       struct snd_pcm_hw_params *params)
 {
@@ -30,6 +57,9 @@ void asoc_simple_convert_fixup(struct asoc_simple_data *data,
 	if (data->convert_channels)
 		channels->min =
 		channels->max = data->convert_channels;
+
+	if (data->convert_sample_format)
+		asoc_simple_fixup_sample_fmt(data, params);
 }
 EXPORT_SYMBOL_GPL(asoc_simple_convert_fixup);
 
@@ -49,6 +79,10 @@ void asoc_simple_parse_convert(struct device_node *np,
 	/* channels transfer */
 	snprintf(prop, sizeof(prop), "%s%s", prefix, "convert-channels");
 	of_property_read_u32(np, prop, &data->convert_channels);
+
+	/* convert sample format */
+	snprintf(prop, sizeof(prop), "%s%s", prefix, "convert-sample-format");
+	of_property_read_string(np, prop, &data->convert_sample_format);
 }
 EXPORT_SYMBOL_GPL(asoc_simple_parse_convert);
 
-- 
2.7.4


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

* Re: [PATCH v3 2/3] ASoC: dt-bindings: Add sample format conversion
  2022-08-08  5:27 ` [PATCH v3 2/3] ASoC: dt-bindings: Add sample format conversion Sameer Pujar
@ 2022-08-09 20:15   ` Rob Herring
  0 siblings, 0 replies; 6+ messages in thread
From: Rob Herring @ 2022-08-09 20:15 UTC (permalink / raw)
  To: Sameer Pujar
  Cc: devicetree, alsa-devel, kuninori.morimoto.gx, tiwai, lgirdwood,
	robh+dt, linux-kernel, broonie, krzysztof.kozlowski+dt

On Mon, 08 Aug 2022 10:57:31 +0530, Sameer Pujar wrote:
> Presently "convert-channels" and "convert-rate" DT bindings are available
> for channel and rate fixups respectively.
> 
> Similarly add "convert-sample-format" binding to fixup DAI sample format
> as well. This is added to audio-graph-card based bindings.
> 
> Signed-off-by: Sameer Pujar <spujar@nvidia.com>
> Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> ---
>  Documentation/devicetree/bindings/sound/audio-graph-port.yaml |  4 ++++
>  Documentation/devicetree/bindings/sound/audio-graph.yaml      |  2 ++
>  Documentation/devicetree/bindings/sound/dai-params.yaml       | 10 ++++++++++
>  3 files changed, 16 insertions(+)
> 

Reviewed-by: Rob Herring <robh@kernel.org>

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

* Re: [PATCH v3 0/3] DT binding for sample format conversion
  2022-08-08  5:27 [PATCH v3 0/3] DT binding for sample format conversion Sameer Pujar
                   ` (2 preceding siblings ...)
  2022-08-08  5:27 ` [PATCH v3 3/3] ASoC: simple-card-utils: Fixup DAI sample format Sameer Pujar
@ 2022-08-15 16:23 ` Mark Brown
  3 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2022-08-15 16:23 UTC (permalink / raw)
  To: lgirdwood, Sameer Pujar, robh+dt, tiwai, krzysztof.kozlowski+dt,
	kuninori.morimoto.gx, perex
  Cc: devicetree, alsa-devel, linux-kernel

On Mon, 8 Aug 2022 10:57:29 +0530, Sameer Pujar wrote:
> DT binding properties are available to fixup rate and channel
> parameters of a DAI. This series extends this to sample format
> conversion as well. With this now DAI PCM parameters (channels,
> sample rate and sample format) can be fixed up as necessary in
> an audio path.
> 
> Changelog:
> ==========
>   v2->v3:
>   -------
>     * Fix DT binding errors in simple-card.yaml
>     * Drop simple-card binding changes from the series since
>       there is no usage requirement. It can be extended later
>       when necessary.
>     * Use definitions instead of properties in the common schema
>       and re-use this in audio-graph related bindings.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/3] ASoC: dt-bindings: Definitions for DAI params
      commit: b79b6220a753995b80054916f1f8f037113d8d93
[2/3] ASoC: dt-bindings: Add sample format conversion
      commit: 955927873d82c5127e31e618703d804033a93e4f
[3/3] ASoC: simple-card-utils: Fixup DAI sample format
      commit: 047a05366f4bb2e32eabbd3c8990d1d91ab87c89

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

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

end of thread, other threads:[~2022-08-15 16:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-08  5:27 [PATCH v3 0/3] DT binding for sample format conversion Sameer Pujar
2022-08-08  5:27 ` [PATCH v3 1/3] ASoC: dt-bindings: Definitions for DAI params Sameer Pujar
2022-08-08  5:27 ` [PATCH v3 2/3] ASoC: dt-bindings: Add sample format conversion Sameer Pujar
2022-08-09 20:15   ` Rob Herring
2022-08-08  5:27 ` [PATCH v3 3/3] ASoC: simple-card-utils: Fixup DAI sample format Sameer Pujar
2022-08-15 16:23 ` [PATCH v3 0/3] DT binding for sample format conversion Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).