Skip to content

Commit 36b9994

Browse files
committed
DT binding for sample format conversion
Merge series from Sameer Pujar <spujar@nvidia.com>: 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.
2 parents 79a8ccb + 047a053 commit 36b9994

File tree

5 files changed

+89
-12
lines changed

5 files changed

+89
-12
lines changed

Documentation/devicetree/bindings/sound/audio-graph-port.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ properties:
1919
description: "device name prefix"
2020
$ref: /schemas/types.yaml#/definitions/string
2121
convert-rate:
22-
description: CPU to Codec rate convert.
23-
$ref: /schemas/types.yaml#/definitions/uint32
22+
$ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-rate"
2423
convert-channels:
25-
description: CPU to Codec rate channels.
26-
$ref: /schemas/types.yaml#/definitions/uint32
24+
$ref: "/schemas/sound/dai-params.yaml#/$defs/dai-channels"
25+
convert-sample-format:
26+
$ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-format"
27+
2728
patternProperties:
2829
"^endpoint(@[0-9a-f]+)?":
2930
$ref: /schemas/graph.yaml#/$defs/endpoint-base
@@ -65,11 +66,11 @@ patternProperties:
6566
- msb
6667
- lsb
6768
convert-rate:
68-
description: CPU to Codec rate convert.
69-
$ref: /schemas/types.yaml#/definitions/uint32
69+
$ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-rate"
7070
convert-channels:
71-
description: CPU to Codec rate channels.
72-
$ref: /schemas/types.yaml#/definitions/uint32
71+
$ref: "/schemas/sound/dai-params.yaml#/$defs/dai-channels"
72+
convert-sample-format:
73+
$ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-format"
7374

7475
dai-tdm-slot-width-map:
7576
description: Mapping of sample widths to slot widths. For hardware

Documentation/devicetree/bindings/sound/audio-graph.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ properties:
2727
description: User specified audio sound widgets.
2828
$ref: /schemas/types.yaml#/definitions/non-unique-string-array
2929
convert-rate:
30-
description: CPU to Codec rate convert.
31-
$ref: /schemas/types.yaml#/definitions/uint32
30+
$ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-rate"
3231
convert-channels:
33-
description: CPU to Codec rate channels.
34-
$ref: /schemas/types.yaml#/definitions/uint32
32+
$ref: "/schemas/sound/dai-params.yaml#/$defs/dai-channels"
33+
convert-sample-format:
34+
$ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-format"
35+
3536
pa-gpios:
3637
maxItems: 1
3738
hp-det-gpio:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/sound/dai-params.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Digital Audio Interface (DAI) Stream Parameters
8+
9+
maintainers:
10+
- Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
11+
12+
select: false
13+
14+
$defs:
15+
16+
dai-channels:
17+
description: Number of audio channels used by DAI
18+
$ref: /schemas/types.yaml#/definitions/uint32
19+
minimum: 1
20+
maximum: 32
21+
22+
dai-sample-format:
23+
description: Audio sample format used by DAI
24+
$ref: /schemas/types.yaml#/definitions/string
25+
enum:
26+
- s8
27+
- s16_le
28+
- s24_le
29+
- s24_3le
30+
- s32_le
31+
32+
dai-sample-rate:
33+
description: Audio sample rate used by DAI
34+
$ref: /schemas/types.yaml#/definitions/uint32
35+
minimum: 8000
36+
maximum: 192000
37+
38+
properties: {}
39+
40+
additionalProperties: true

include/sound/simple_card_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct asoc_simple_dai {
3939
struct asoc_simple_data {
4040
u32 convert_rate;
4141
u32 convert_channels;
42+
const char *convert_sample_format;
4243
};
4344

4445
struct asoc_simple_jack {

sound/soc/generic/simple-card-utils.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,33 @@
1515
#include <sound/pcm_params.h>
1616
#include <sound/simple_card_utils.h>
1717

18+
static void asoc_simple_fixup_sample_fmt(struct asoc_simple_data *data,
19+
struct snd_pcm_hw_params *params)
20+
{
21+
int i;
22+
struct snd_mask *mask = hw_param_mask(params,
23+
SNDRV_PCM_HW_PARAM_FORMAT);
24+
struct {
25+
char *fmt;
26+
u32 val;
27+
} of_sample_fmt_table[] = {
28+
{ "s8", SNDRV_PCM_FORMAT_S8},
29+
{ "s16_le", SNDRV_PCM_FORMAT_S16_LE},
30+
{ "s24_le", SNDRV_PCM_FORMAT_S24_LE},
31+
{ "s24_3le", SNDRV_PCM_FORMAT_S24_3LE},
32+
{ "s32_le", SNDRV_PCM_FORMAT_S32_LE},
33+
};
34+
35+
for (i = 0; i < ARRAY_SIZE(of_sample_fmt_table); i++) {
36+
if (!strcmp(data->convert_sample_format,
37+
of_sample_fmt_table[i].fmt)) {
38+
snd_mask_none(mask);
39+
snd_mask_set(mask, of_sample_fmt_table[i].val);
40+
break;
41+
}
42+
}
43+
}
44+
1845
void asoc_simple_convert_fixup(struct asoc_simple_data *data,
1946
struct snd_pcm_hw_params *params)
2047
{
@@ -30,6 +57,9 @@ void asoc_simple_convert_fixup(struct asoc_simple_data *data,
3057
if (data->convert_channels)
3158
channels->min =
3259
channels->max = data->convert_channels;
60+
61+
if (data->convert_sample_format)
62+
asoc_simple_fixup_sample_fmt(data, params);
3363
}
3464
EXPORT_SYMBOL_GPL(asoc_simple_convert_fixup);
3565

@@ -49,6 +79,10 @@ void asoc_simple_parse_convert(struct device_node *np,
4979
/* channels transfer */
5080
snprintf(prop, sizeof(prop), "%s%s", prefix, "convert-channels");
5181
of_property_read_u32(np, prop, &data->convert_channels);
82+
83+
/* convert sample format */
84+
snprintf(prop, sizeof(prop), "%s%s", prefix, "convert-sample-format");
85+
of_property_read_string(np, prop, &data->convert_sample_format);
5286
}
5387
EXPORT_SYMBOL_GPL(asoc_simple_parse_convert);
5488

0 commit comments

Comments
 (0)