Skip to contentSkip to conversation

DT binding for sample format conversion

PATCH Superseded Sameer Pujar 2 participants 6 messages Jul 27, 2022 – Aug 2, 2022

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover DT binding for sample format conversion

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.

Sameer Pujar (2):
ASoC: dt-bindings: Add sample format conversion
ASoC: simple-card-utils: Fixup DAI sample format

 .../devicetree/bindings/sound/audio-graph-port.yaml | 21 +++++++++++++++++++++
 .../devicetree/bindings/sound/audio-graph.yaml      | 11 +++++++++++
 .../devicetree/bindings/sound/simple-card.yaml      | 15 +++++++++++++++
 include/sound/simple_card_utils.h                   |  1 +
 sound/soc/generic/simple-card-utils.c               | 12 ++++++++++++
 5 files changed, 60 insertions(+)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 ASoC: dt-bindings: Add sample format conversion

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 simple-card and audio-graph based sound cards.

Cc Kuninori Morimoto <[email protected]>
---
 .../devicetree/bindings/sound/audio-graph-port.yaml | 21 +++++++++++++++++++++
 .../devicetree/bindings/sound/audio-graph.yaml      | 11 +++++++++++
 .../devicetree/bindings/sound/simple-card.yaml      | 15 +++++++++++++++
 3 files changed, 47 insertions(+)
Documentation/devicetree/bindings/sound/audio-graph-port.yaml +21 -0
index 5c36867..d7491038 100644
@@ -24,6 +24,17 @@ properties:
   convert-channels:
     description: CPU to Codec rate channels.
     $ref: /schemas/types.yaml#/definitions/uint32
+  convert-sample-format:
+    description: CPU to Codec sample format.
+      Value    Format
+        0        S8
+        2        S16_LE
+        6        S24_LE
+        10       S32_LE
+        32       S24_3LE
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [0, 2, 6, 10, 32]
+
 patternProperties:
   "^endpoint(@[0-9a-f]+)?":
     $ref: /schemas/graph.yaml#/$defs/endpoint-base
@@ -70,6 +81,16 @@ patternProperties:
       convert-channels:
         description: CPU to Codec rate channels.
         $ref: /schemas/types.yaml#/definitions/uint32
+      convert-sample-format:
+        description: CPU to Codec sample format.
+          Value    Format
+            0        S8
+            2        S16_LE
+            6        S24_LE
+            10       S32_LE
+            32       S24_3LE
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [0, 2, 6, 10, 32]
 
       dai-tdm-slot-width-map:
         description: Mapping of sample widths to slot widths. For hardware
Documentation/devicetree/bindings/sound/audio-graph.yaml +11 -0
index 4b46794..df8a994 100644
@@ -32,6 +32,17 @@ properties:
   convert-channels:
     description: CPU to Codec rate channels.
     $ref: /schemas/types.yaml#/definitions/uint32
+  convert-sample-format:
+    description: CPU to Codec sample format.
+      Value    Format
+        0        S8
+        2        S16_LE
+        6        S24_LE
+        10       S32_LE
+        32       S24_3LE
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [0, 2, 6, 10, 32]
+
   pa-gpios:
     maxItems: 1
   hp-det-gpio:
Documentation/devicetree/bindings/sound/simple-card.yaml +15 -0
index b261d49..6decd73 100644
@@ -77,6 +77,17 @@ definitions:
     description: CPU to Codec rate channels.
     $ref: /schemas/types.yaml#/definitions/uint32
 
+  convert-sample-format:
+    description: CPU to Codec sample format.
+      Value    Format
+        0        S8
+        2        S16_LE
+        6        S24_LE
+        10       S32_LE
+        32       S24_3LE
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [0, 2, 6, 10, 32]
+
   prefix:
     description: "device name prefix"
     $ref: /schemas/types.yaml#/definitions/string
@@ -191,6 +202,8 @@ properties:
     $ref: "#/definitions/convert-rate"
   simple-audio-card,convert-channels:
     $ref: "#/definitions/convert-channels"
+  simple-audio-card,convert-sample-format:
+    $ref: "#/definitions/convert-sample-format"
   simple-audio-card,prefix:
     $ref: "#/definitions/prefix"
   simple-audio-card,pin-switches:
@@ -234,6 +247,8 @@ patternProperties:
         $ref: "#/definitions/convert-rate"
       convert-channels:
         $ref: "#/definitions/convert-channels"
+      convert-sample-format:
+        $ref: "#/definitions/convert-sample-format"
       prefix:
         $ref: "#/definitions/prefix"
       pin-switches:
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 1/2] ASoC: dt-bindings: Add sample format conversion

Quoted 19 lines · Sameer Pujar

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 simple-card and audio-graph based sound cards.

Cc Kuninori Morimoto <[email protected]>
---
 .../devicetree/bindings/sound/audio-graph-port.yaml | 21 +++++++++++++++++++++
 .../devicetree/bindings/sound/audio-graph.yaml      | 11 +++++++++++
 .../devicetree/bindings/sound/simple-card.yaml      | 15 +++++++++++++++
 3 files changed, 47 insertions(+)
Documentation/devicetree/bindings/sound/audio-graph-port.yaml +0 -0
index 5c36867..d7491038 100644

Documentation/devicetree/bindings/sound/audio-graph-port.yaml properties: · line 26

Quoted 3 lines
Documentation/devicetree/bindings/sound/audio-graph-port.yaml +0 -0
@@ -24,6 +24,17 @@ properties:
   convert-channels:
     description: CPU to Codec rate channels.
     $ref: /schemas/types.yaml#/definitions/uint32

Missing blank line.

Documentation/devicetree/bindings/sound/audio-graph-port.yaml properties: · line 34

Quoted 8 lines
Documentation/devicetree/bindings/sound/audio-graph-port.yaml +8 -0
+  convert-sample-format:
+    description: CPU to Codec sample format.
+      Value    Format
+        0        S8
+        2        S16_LE
+        6        S24_LE
+        10       S32_LE
+        32       S24_3LE

Why some random set of integers? Just use string, must more descriptive and you do not embed programming model to DT... unless there is some reason for this approach?

Documentation/devicetree/bindings/sound/audio-graph-port.yaml patternProperties: · line 83

Quoted 10 lines
Documentation/devicetree/bindings/sound/audio-graph-port.yaml +3 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [0, 2, 6, 10, 32]
+
 patternProperties:
   "^endpoint(@[0-9a-f]+)?":
     $ref: /schemas/graph.yaml#/$defs/endpoint-base
@@ -70,6 +81,16 @@ patternProperties:
       convert-channels:
         description: CPU to Codec rate channels.
         $ref: /schemas/types.yaml#/definitions/uint32

Ditto

Documentation/devicetree/bindings/sound/audio-graph-port.yaml properties: · line 36

Quoted 10 lines
Documentation/devicetree/bindings/sound/audio-graph-port.yaml +10 -0
+      convert-sample-format:
+        description: CPU to Codec sample format.
+          Value    Format
+            0        S8
+            2        S16_LE
+            6        S24_LE
+            10       S32_LE
+            32       S24_3LE
+        $ref: /schemas/types.yaml#/definitions/uint32
+        enum: [0, 2, 6, 10, 32]

Ditto

Documentation/devicetree/bindings/sound/audio-graph.yaml properties: · line 34

Quoted 11 lines
Documentation/devicetree/bindings/sound/audio-graph-port.yaml +0 -0
       dai-tdm-slot-width-map:
         description: Mapping of sample widths to slot widths. For hardware
Documentation/devicetree/bindings/sound/audio-graph.yaml +0 -0
index 4b46794..df8a994 100644
@@ -32,6 +32,17 @@ properties:
   convert-channels:
     description: CPU to Codec rate channels.
     $ref: /schemas/types.yaml#/definitions/uint32

Ditto

Documentation/devicetree/bindings/sound/audio-graph.yaml properties: · line 42

Quoted 8 lines
Documentation/devicetree/bindings/sound/audio-graph.yaml +8 -0
+  convert-sample-format:
+    description: CPU to Codec sample format.
+      Value    Format
+        0        S8
+        2        S16_LE
+        6        S24_LE
+        10       S32_LE
+        32       S24_3LE

Ditto

Quoted 13 lines
Documentation/devicetree/bindings/sound/audio-graph.yaml +3 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [0, 2, 6, 10, 32]
+
   pa-gpios:
     maxItems: 1
   hp-det-gpio:
Documentation/devicetree/bindings/sound/simple-card.yaml +0 -0
index b261d49..6decd73 100644
@@ -77,6 +77,17 @@ definitions:
     description: CPU to Codec rate channels.
     $ref: /schemas/types.yaml#/definitions/uint32

Documentation/devicetree/bindings/sound/simple-card.yaml definitions: · line 88

Quoted 10 lines
Documentation/devicetree/bindings/sound/simple-card.yaml +9 -0
 
+  convert-sample-format:
+    description: CPU to Codec sample format.
+      Value    Format
+        0        S8
+        2        S16_LE
+        6        S24_LE
+        10       S32_LE
+        32       S24_3LE
+    $ref: /schemas/types.yaml#/definitions/uint32

Wait, you now put the same property in four different places. Don't you have something which could be shared?

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH 1/2] ASoC: dt-bindings: Add sample format conversion

Quoted 15 lines · Krzysztof Kozlowski
Quoted 14 lines · Sameer Pujar

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 simple-card and audio-graph based sound cards.

Cc Kuninori Morimoto <[email protected]>
---
  .../devicetree/bindings/sound/audio-graph-port.yaml | 21 +++++++++++++++++++++
  .../devicetree/bindings/sound/audio-graph.yaml      | 11 +++++++++++
  .../devicetree/bindings/sound/simple-card.yaml      | 15 +++++++++++++++
  3 files changed, 47 insertions(+)
Quoted 9 lines

Documentation/devicetree/bindings/sound/audio-graph-port.yaml properties: · line 26

Quoted 8 lines
Documentation/devicetree/bindings/sound/audio-graph-port.yaml +0 -0
index 5c36867..d7491038 100644
@@ -24,6 +24,17 @@ properties:
    convert-channels:
      description: CPU to Codec rate channels.
      $ref: /schemas/types.yaml#/definitions/uint32

Missing blank line.

will fix.

Quoted 9 lines

Documentation/devicetree/bindings/sound/audio-graph-port.yaml properties: · line 34

Quoted 9 lines
Documentation/devicetree/bindings/sound/audio-graph-port.yaml +8 -0
+  convert-sample-format:
+    description: CPU to Codec sample format.
+      Value    Format
+        0        S8
+        2        S16_LE
+        6        S24_LE
+        10       S32_LE
+        32       S24_3LE
Quoted 3 lines

Why some random set of integers? Just use string, must more descriptive and you do not embed programming model to DT... unless there is some reason for this approach?

I referenced it from similar usage in fsl,easrc.yaml for binding "fsl,asrc-format" and driver can directly use it. However agree with above and let me use strings here.

[...]

Quoted 17 lines
Documentation/devicetree/bindings/sound/simple-card.yaml +9 -0
index b261d49..6decd73 100644
@@ -77,6 +77,17 @@ definitions:
      description: CPU to Codec rate channels.
      $ref: /schemas/types.yaml#/definitions/uint32
 
+  convert-sample-format:
+    description: CPU to Codec sample format.
+      Value    Format
+        0        S8
+        2        S16_LE
+        6        S24_LE
+        10       S32_LE
+        32       S24_3LE
+    $ref: /schemas/types.yaml#/definitions/uint32
Quoted 3 lines

Wait, you now put the same property in four different places. Don't you have something which could be shared?

There is no shared schema between simple-card.yaml and others. I will have to create a new doc to share these definitions.

#4 lore raw

Re: [PATCH 1/2] ASoC: dt-bindings: Add sample format conversion

Quoted 8 lines · Sameer Pujar
Quoted 8 lines
Documentation/devicetree/bindings/sound/simple-card.yaml +0 -0
index b261d49..6decd73 100644
@@ -77,6 +77,17 @@ definitions:
      description: CPU to Codec rate channels.
      $ref: /schemas/types.yaml#/definitions/uint32
 
Quoted 14 lines
Quoted 9 lines
Documentation/devicetree/bindings/sound/simple-card.yaml +9 -0
+  convert-sample-format:
+    description: CPU to Codec sample format.
+      Value    Format
+        0        S8
+        2        S16_LE
+        6        S24_LE
+        10       S32_LE
+        32       S24_3LE
+    $ref: /schemas/types.yaml#/definitions/uint32
Quoted 3 lines

Wait, you now put the same property in four different places. Don't you have something which could be shared?

There is no shared schema between simple-card.yaml and others. I will have to create a new doc to share these definitions.

OK

Best regards,
Krzysztof

#5 lore raw

PATCH 2/2 ASoC: simple-card-utils: Fixup DAI sample format

In reply to Sameer Pujar

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.

Cc Kuninori Morimoto <[email protected]>
---
 include/sound/simple_card_utils.h     |  1 +
 sound/soc/generic/simple-card-utils.c | 12 ++++++++++++
 2 files changed, 13 insertions(+)
include/sound/simple_card_utils.h +1 -0
index ab55f40..39ea57d 100644
@@ -39,6 +39,7 @@ struct asoc_simple_dai {
 struct asoc_simple_data {
 	u32 convert_rate;
 	u32 convert_channels;
+	int convert_sample_format;
 };
 
 struct asoc_simple_jack {
sound/soc/generic/simple-card-utils.c +12 -0
index 4a29e31..6ce5102 100644
@@ -22,6 +22,8 @@ void asoc_simple_convert_fixup(struct asoc_simple_data *data,
 						SNDRV_PCM_HW_PARAM_RATE);
 	struct snd_interval *channels = hw_param_interval(params,
 						SNDRV_PCM_HW_PARAM_CHANNELS);
+	struct snd_mask *mask = hw_param_mask(params,
+						SNDRV_PCM_HW_PARAM_FORMAT);
 
 	if (data->convert_rate)
 		rate->min =
@@ -30,6 +32,11 @@ 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 >= 0) {
+		snd_mask_none(mask);
+		snd_mask_set(mask, data->convert_sample_format);
+	}
 }
 EXPORT_SYMBOL_GPL(asoc_simple_convert_fixup);
 
@@ -49,6 +56,11 @@ 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 */
+	data->convert_sample_format = -EINVAL;
+	snprintf(prop, sizeof(prop), "%s%s", prefix, "convert-sample-format");
+	of_property_read_u32(np, prop, &data->convert_sample_format);
 }
 EXPORT_SYMBOL_GPL(asoc_simple_parse_convert);
 
Signature · 1 line
2.7.4