Commit 36b99942 authored by Mark Brown's avatar Mark Brown

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.
parents 79a8ccbd 047a0536
......@@ -19,11 +19,12 @@ 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"
convert-sample-format:
$ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-format"
patternProperties:
"^endpoint(@[0-9a-f]+)?":
$ref: /schemas/graph.yaml#/$defs/endpoint-base
......@@ -65,11 +66,11 @@ 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"
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
......
......@@ -27,11 +27,12 @@ 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"
convert-sample-format:
$ref: "/schemas/sound/dai-params.yaml#/$defs/dai-sample-format"
pa-gpios:
maxItems: 1
hp-det-gpio:
......
# 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-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
minimum: 8000
maximum: 192000
properties: {}
additionalProperties: true
......@@ -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 {
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment