// SPDX-License-Identifier: GPL-2.0
//
// simple-card-utils.c
//
// Copyright (c) 2016 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
#include <dt-bindings/sound/audio-graph.h>
#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_graph.h>
#include <sound/jack.h>
#include <sound/pcm_params.h>
#include <sound/simple_card_utils.h>
#define simple_ret(priv, ret) _simple_ret(priv, __func__, ret)
static inline int _simple_ret(struct simple_util_priv *priv,
const char *func, int ret)
{
return snd_soc_ret(simple_priv_to_dev(priv), ret, "at %s()\n", func);
}
int simple_util_get_sample_fmt(struct simple_util_data *data)
{
int i;
int val = -EINVAL;
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)) {
val = of_sample_fmt_table[i].val;
break;
}
}
return val;
}
EXPORT_SYMBOL_GPL(simple_util_get_sample_fmt);
static void simple_fixup_sample_fmt(struct simple_util_data *data,
struct snd_pcm_hw_params *params)
{
int val;
struct snd_mask *mask = hw_param_mask(params,
SNDRV_PCM_HW_PARAM_FORMAT);
val = simple_util_get_sample_fmt(data);
if (val >= 0) {
snd_mask_none(mask);
snd_mask_set(mask, val);
}
}
void simple_util_parse_convert(struct device_node *np,
char *prefix,
struct simple_util_data *data)
{
char prop[128];
if (!np)
return;
if (!prefix)
prefix = "";
/* sampling rate convert */
snprintf(prop, sizeof(prop), "%s%s", prefix, "convert-rate");
of_property_read_u32(np, prop, &data