Skip to content

Commit 047a053

Browse files
pujarsbroonie
authored andcommitted
ASoC: simple-card-utils: Fixup DAI sample format
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> Link: https://lore.kernel.org/r/1659936452-2254-4-git-send-email-spujar@nvidia.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 9559278 commit 047a053

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

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)