[PATCH 0/2] 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(+)
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.
Signed-off-by: Sameer Pujar spujar@nvidia.com Cc: Kuninori Morimoto kuninori.morimoto.gx@renesas.com --- .../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(+)
diff --git a/Documentation/devicetree/bindings/sound/audio-graph-port.yaml b/Documentation/devicetree/bindings/sound/audio-graph-port.yaml index 5c36867..d7491038 100644 --- a/Documentation/devicetree/bindings/sound/audio-graph-port.yaml +++ b/Documentation/devicetree/bindings/sound/audio-graph-port.yaml @@ -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 diff --git a/Documentation/devicetree/bindings/sound/audio-graph.yaml b/Documentation/devicetree/bindings/sound/audio-graph.yaml index 4b46794..df8a994 100644 --- a/Documentation/devicetree/bindings/sound/audio-graph.yaml +++ b/Documentation/devicetree/bindings/sound/audio-graph.yaml @@ -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: diff --git a/Documentation/devicetree/bindings/sound/simple-card.yaml b/Documentation/devicetree/bindings/sound/simple-card.yaml index b261d49..6decd73 100644 --- a/Documentation/devicetree/bindings/sound/simple-card.yaml +++ b/Documentation/devicetree/bindings/sound/simple-card.yaml @@ -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:
On 27/07/2022 16:26, 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 simple-card and audio-graph based sound cards.
Signed-off-by: Sameer Pujar spujar@nvidia.com Cc: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
.../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(+)
diff --git a/Documentation/devicetree/bindings/sound/audio-graph-port.yaml b/Documentation/devicetree/bindings/sound/audio-graph-port.yaml index 5c36867..d7491038 100644 --- a/Documentation/devicetree/bindings/sound/audio-graph-port.yaml +++ b/Documentation/devicetree/bindings/sound/audio-graph-port.yaml @@ -24,6 +24,17 @@ properties: convert-channels: description: CPU to Codec rate channels. $ref: /schemas/types.yaml#/definitions/uint32
Missing blank line.
- 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?
- $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
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
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..df8a994 100644 --- a/Documentation/devicetree/bindings/sound/audio-graph.yaml +++ b/Documentation/devicetree/bindings/sound/audio-graph.yaml @@ -32,6 +32,17 @@ properties: convert-channels: description: CPU to Codec rate channels. $ref: /schemas/types.yaml#/definitions/uint32
Ditto
- 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
- $ref: /schemas/types.yaml#/definitions/uint32
- enum: [0, 2, 6, 10, 32]
- pa-gpios: maxItems: 1 hp-det-gpio:
diff --git a/Documentation/devicetree/bindings/sound/simple-card.yaml b/Documentation/devicetree/bindings/sound/simple-card.yaml index b261d49..6decd73 100644 --- a/Documentation/devicetree/bindings/sound/simple-card.yaml +++ b/Documentation/devicetree/bindings/sound/simple-card.yaml @@ -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
Wait, you now put the same property in four different places. Don't you have something which could be shared?
Best regards, Krzysztof
On 28-07-2022 17:52, Krzysztof Kozlowski wrote:
On 27/07/2022 16:26, 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 simple-card and audio-graph based sound cards.
Signed-off-by: Sameer Pujar spujar@nvidia.com Cc: Kuninori Morimoto kuninori.morimoto.gx@renesas.com
.../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(+)
diff --git a/Documentation/devicetree/bindings/sound/audio-graph-port.yaml b/Documentation/devicetree/bindings/sound/audio-graph-port.yaml index 5c36867..d7491038 100644 --- a/Documentation/devicetree/bindings/sound/audio-graph-port.yaml +++ b/Documentation/devicetree/bindings/sound/audio-graph-port.yaml @@ -24,6 +24,17 @@ properties: convert-channels: description: CPU to Codec rate channels. $ref: /schemas/types.yaml#/definitions/uint32
Missing blank line.
will fix.
- 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?
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.
[...]
diff --git a/Documentation/devicetree/bindings/sound/simple-card.yaml b/Documentation/devicetree/bindings/sound/simple-card.yaml index b261d49..6decd73 100644 --- a/Documentation/devicetree/bindings/sound/simple-card.yaml +++ b/Documentation/devicetree/bindings/sound/simple-card.yaml @@ -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
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.
On 29/07/2022 06:11, Sameer Pujar wrote:
diff --git a/Documentation/devicetree/bindings/sound/simple-card.yaml b/Documentation/devicetree/bindings/sound/simple-card.yaml index b261d49..6decd73 100644 --- a/Documentation/devicetree/bindings/sound/simple-card.yaml +++ b/Documentation/devicetree/bindings/sound/simple-card.yaml @@ -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
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
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 | 12 ++++++++++++ 2 files changed, 13 insertions(+)
diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h index ab55f40..39ea57d 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; + int 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..6ce5102 100644 --- a/sound/soc/generic/simple-card-utils.c +++ b/sound/soc/generic/simple-card-utils.c @@ -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);
participants (2)
-
Krzysztof Kozlowski
-
Sameer Pujar