ASoC: add common snd_soc_ret() and use it

Each soc-xxx.c is using own snd_xxx_ret(), but we want to share it.
Let's add common snd_soc_ret() for it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://patch.msgid.link/87frkt2qlx.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Kuninori Morimoto 2025-02-05 00:16:10 +00:00 committed by Mark Brown
parent dabbd325b2
commit 943116ba2a
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
7 changed files with 47 additions and 84 deletions

View File

@ -539,6 +539,7 @@ int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
int snd_soc_params_to_bclk(const struct snd_pcm_hw_params *parms);
int snd_soc_tdm_params_to_bclk(const struct snd_pcm_hw_params *params,
int tdm_width, int tdm_slots, int slot_multiple);
int snd_soc_ret(const struct device *dev, int ret, const char *fmt, ...);
/* set runtime hw params */
static inline int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,

View File

@ -15,18 +15,8 @@
static inline int _soc_card_ret(struct snd_soc_card *card,
const char *func, int ret)
{
switch (ret) {
case -EPROBE_DEFER:
case -ENOTSUPP:
case 0:
break;
default:
dev_err(card->dev,
"ASoC: error at %s on %s: %d\n",
func, card->name, ret);
}
return ret;
return snd_soc_ret(card->dev, ret,
"at %s() on %s\n", func, card->name);
}
struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,

View File

@ -13,32 +13,20 @@
#include <sound/soc.h>
#include <linux/bitops.h>
#define soc_component_ret(dai, ret) _soc_component_ret(dai, __func__, ret, -1)
#define soc_component_ret_reg_rw(dai, ret, reg) _soc_component_ret(dai, __func__, ret, reg)
static inline int _soc_component_ret(struct snd_soc_component *component,
const char *func, int ret, int reg)
#define soc_component_ret(dai, ret) _soc_component_ret(dai, __func__, ret)
static inline int _soc_component_ret(struct snd_soc_component *component, const char *func, int ret)
{
/* Positive/Zero values are not errors */
if (ret >= 0)
return ret;
return snd_soc_ret(component->dev, ret,
"at %s() on %s\n", func, component->name);
}
/* Negative values might be errors */
switch (ret) {
case -EPROBE_DEFER:
case -ENOTSUPP:
break;
default:
if (reg == -1)
dev_err(component->dev,
"ASoC: error at %s on %s: %d\n",
func, component->name, ret);
else
dev_err(component->dev,
"ASoC: error at %s on %s for register: [0x%08x] %d\n",
func, component->name, reg, ret);
}
return ret;
#define soc_component_ret_reg_rw(dai, ret, reg) _soc_component_ret_reg_rw(dai, __func__, ret, reg)
static inline int _soc_component_ret_reg_rw(struct snd_soc_component *component,
const char *func, int ret, int reg)
{
return snd_soc_ret(component->dev, ret,
"at %s() on %s for register: [0x%08x]\n",
func, component->name, reg);
}
static inline int soc_component_field_shift(struct snd_soc_component *component,

View File

@ -14,22 +14,8 @@
static inline int _soc_dai_ret(const struct snd_soc_dai *dai,
const char *func, int ret)
{
/* Positive, Zero values are not errors */
if (ret >= 0)
return ret;
/* Negative values might be errors */
switch (ret) {
case -EPROBE_DEFER:
case -ENOTSUPP:
break;
default:
dev_err(dai->dev,
"ASoC: error at %s on %s: %d\n",
func, dai->name, ret);
}
return ret;
return snd_soc_ret(dai->dev, ret,
"at %s() on %s\n", func, dai->name);
}
/*

View File

@ -12,22 +12,8 @@
static inline int _soc_link_ret(struct snd_soc_pcm_runtime *rtd,
const char *func, int ret)
{
/* Positive, Zero values are not errors */
if (ret >= 0)
return ret;
/* Negative values might be errors */
switch (ret) {
case -EPROBE_DEFER:
case -ENOTSUPP:
break;
default:
dev_err(rtd->dev,
"ASoC: error at %s on %s: %d\n",
func, rtd->dai_link->name, ret);
}
return ret;
return snd_soc_ret(rtd->dev, ret,
"at %s() on %s\n", func, rtd->dai_link->name);
}
/*

View File

@ -30,22 +30,8 @@
static inline int _soc_pcm_ret(struct snd_soc_pcm_runtime *rtd,
const char *func, int ret)
{
/* Positive, Zero values are not errors */
if (ret >= 0)
return ret;
/* Negative values might be errors */
switch (ret) {
case -EPROBE_DEFER:
case -ENOTSUPP:
break;
default:
dev_err(rtd->dev,
"ASoC: error at %s on %s: %d\n",
func, rtd->dai_link->name, ret);
}
return ret;
return snd_soc_ret(rtd->dev, ret,
"at %s() on %s\n", func, rtd->dai_link->name);
}
/* is the current PCM operation for this FE ? */

View File

@ -15,6 +15,32 @@
#include <sound/pcm_params.h>
#include <sound/soc.h>
int snd_soc_ret(const struct device *dev, int ret, const char *fmt, ...)
{
struct va_format vaf;
va_list args;
/* Positive, Zero values are not errors */
if (ret >= 0)
return ret;
/* Negative values might be errors */
switch (ret) {
case -EPROBE_DEFER:
case -ENOTSUPP:
break;
default:
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
dev_err(dev, "ASoC error (%d): %pV", ret, &vaf);
}
return ret;
}
EXPORT_SYMBOL_GPL(snd_soc_ret);
int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots)
{
return sample_size * channels * tdm_slots;