Commit e2329eeb authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: soc-component: add soc_component_err()

At soc-component.c, it is good idea to indicate error function and
its component name if there was error.
This patch adds soc_component_err() for it.
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87pnafw8z2.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 536aba1d
...@@ -8,6 +8,28 @@ ...@@ -8,6 +8,28 @@
#include <linux/module.h> #include <linux/module.h>
#include <sound/soc.h> #include <sound/soc.h>
#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;
/* Negative values might be errors */
switch (ret) {
case -EPROBE_DEFER:
case -ENOTSUPP:
break;
default:
dev_err(component->dev,
"ASoC: error at %s on %s: %d\n",
func, component->name, ret);
}
return ret;
}
int snd_soc_component_initialize(struct snd_soc_component *component, int snd_soc_component_initialize(struct snd_soc_component *component,
const struct snd_soc_component_driver *driver, const struct snd_soc_component_driver *driver,
struct device *dev, const char *name) struct device *dev, const char *name)
...@@ -38,11 +60,13 @@ int snd_soc_component_set_sysclk(struct snd_soc_component *component, ...@@ -38,11 +60,13 @@ int snd_soc_component_set_sysclk(struct snd_soc_component *component,
int clk_id, int source, unsigned int freq, int clk_id, int source, unsigned int freq,
int dir) int dir)
{ {
int ret = -ENOTSUPP;
if (component->driver->set_sysclk) if (component->driver->set_sysclk)
return component->driver->set_sysclk(component, clk_id, source, ret = component->driver->set_sysclk(component, clk_id, source,
freq, dir); freq, dir);
return -ENOTSUPP; return soc_component_ret(component, ret);
} }
EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk); EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk);
...@@ -60,11 +84,13 @@ int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id, ...@@ -60,11 +84,13 @@ int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
int source, unsigned int freq_in, int source, unsigned int freq_in,
unsigned int freq_out) unsigned int freq_out)
{ {
int ret = -EINVAL;
if (component->driver->set_pll) if (component->driver->set_pll)
return component->driver->set_pll(component, pll_id, source, ret = component->driver->set_pll(component, pll_id, source,
freq_in, freq_out); freq_in, freq_out);
return -EINVAL; return soc_component_ret(component, ret);
} }
EXPORT_SYMBOL_GPL(snd_soc_component_set_pll); EXPORT_SYMBOL_GPL(snd_soc_component_set_pll);
...@@ -78,19 +104,23 @@ void snd_soc_component_seq_notifier(struct snd_soc_component *component, ...@@ -78,19 +104,23 @@ void snd_soc_component_seq_notifier(struct snd_soc_component *component,
int snd_soc_component_stream_event(struct snd_soc_component *component, int snd_soc_component_stream_event(struct snd_soc_component *component,
int event) int event)
{ {
int ret = 0;
if (component->driver->stream_event) if (component->driver->stream_event)
return component->driver->stream_event(component, event); ret = component->driver->stream_event(component, event);
return 0; return soc_component_ret(component, ret);
} }
int snd_soc_component_set_bias_level(struct snd_soc_component *component, int snd_soc_component_set_bias_level(struct snd_soc_component *component,
enum snd_soc_bias_level level) enum snd_soc_bias_level level)
{ {
int ret = 0;
if (component->driver->set_bias_level) if (component->driver->set_bias_level)
return component->driver->set_bias_level(component, level); ret = component->driver->set_bias_level(component, level);
return 0; return soc_component_ret(component, ret);
} }
static int soc_component_pin(struct snd_soc_component *component, static int soc_component_pin(struct snd_soc_component *component,
...@@ -103,17 +133,21 @@ static int soc_component_pin(struct snd_soc_component *component, ...@@ -103,17 +133,21 @@ static int soc_component_pin(struct snd_soc_component *component,
char *full_name; char *full_name;
int ret; int ret;
if (!component->name_prefix) if (!component->name_prefix) {
return pin_func(dapm, pin); ret = pin_func(dapm, pin);
goto end;
}
full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin); full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
if (!full_name) if (!full_name) {
return -ENOMEM; ret = -ENOMEM;
goto end;
}
ret = pin_func(dapm, full_name); ret = pin_func(dapm, full_name);
kfree(full_name); kfree(full_name);
end:
return ret; return soc_component_ret(component, ret);
} }
int snd_soc_component_enable_pin(struct snd_soc_component *component, int snd_soc_component_enable_pin(struct snd_soc_component *component,
...@@ -191,21 +225,25 @@ EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked); ...@@ -191,21 +225,25 @@ EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked);
int snd_soc_component_set_jack(struct snd_soc_component *component, int snd_soc_component_set_jack(struct snd_soc_component *component,
struct snd_soc_jack *jack, void *data) struct snd_soc_jack *jack, void *data)
{ {
int ret = -ENOTSUPP;
if (component->driver->set_jack) if (component->driver->set_jack)
return component->driver->set_jack(component, jack, data); ret = component->driver->set_jack(component, jack, data);
return -ENOTSUPP; return soc_component_ret(component, ret);
} }
EXPORT_SYMBOL_GPL(snd_soc_component_set_jack); EXPORT_SYMBOL_GPL(snd_soc_component_set_jack);
int snd_soc_component_module_get(struct snd_soc_component *component, int snd_soc_component_module_get(struct snd_soc_component *component,
int upon_open) int upon_open)
{ {
int ret = 0;
if (component->driver->module_get_upon_open == !!upon_open && if (component->driver->module_get_upon_open == !!upon_open &&
!try_module_get(component->dev->driver->owner)) !try_module_get(component->dev->driver->owner))
return -ENODEV; ret = -ENODEV;
return 0; return soc_component_ret(component, ret);
} }
void snd_soc_component_module_put(struct snd_soc_component *component, void snd_soc_component_module_put(struct snd_soc_component *component,
...@@ -218,52 +256,70 @@ void snd_soc_component_module_put(struct snd_soc_component *component, ...@@ -218,52 +256,70 @@ void snd_soc_component_module_put(struct snd_soc_component *component,
int snd_soc_component_open(struct snd_soc_component *component, int snd_soc_component_open(struct snd_soc_component *component,
struct snd_pcm_substream *substream) struct snd_pcm_substream *substream)
{ {
int ret = 0;
if (component->driver->open) if (component->driver->open)
return component->driver->open(component, substream); ret = component->driver->open(component, substream);
return 0;
return soc_component_ret(component, ret);
} }
int snd_soc_component_close(struct snd_soc_component *component, int snd_soc_component_close(struct snd_soc_component *component,
struct snd_pcm_substream *substream) struct snd_pcm_substream *substream)
{ {
int ret = 0;
if (component->driver->close) if (component->driver->close)
return component->driver->close(component, substream); ret = component->driver->close(component, substream);
return 0;
return soc_component_ret(component, ret);
} }
int snd_soc_component_prepare(struct snd_soc_component *component, int snd_soc_component_prepare(struct snd_soc_component *component,
struct snd_pcm_substream *substream) struct snd_pcm_substream *substream)
{ {
int ret = 0;
if (component->driver->prepare) if (component->driver->prepare)
return component->driver->prepare(component, substream); ret = component->driver->prepare(component, substream);
return 0;
return soc_component_ret(component, ret);
} }
int snd_soc_component_hw_params(struct snd_soc_component *component, int snd_soc_component_hw_params(struct snd_soc_component *component,
struct snd_pcm_substream *substream, struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params)
{ {
int ret = 0;
if (component->driver->hw_params) if (component->driver->hw_params)
return component->driver->hw_params(component, ret = component->driver->hw_params(component,
substream, params); substream, params);
return 0;
return soc_component_ret(component, ret);
} }
int snd_soc_component_hw_free(struct snd_soc_component *component, int snd_soc_component_hw_free(struct snd_soc_component *component,
struct snd_pcm_substream *substream) struct snd_pcm_substream *substream)
{ {
int ret = 0;
if (component->driver->hw_free) if (component->driver->hw_free)
return component->driver->hw_free(component, substream); ret = component->driver->hw_free(component, substream);
return 0;
return soc_component_ret(component, ret);
} }
int snd_soc_component_trigger(struct snd_soc_component *component, int snd_soc_component_trigger(struct snd_soc_component *component,
struct snd_pcm_substream *substream, struct snd_pcm_substream *substream,
int cmd) int cmd)
{ {
int ret = 0;
if (component->driver->trigger) if (component->driver->trigger)
return component->driver->trigger(component, substream, cmd); ret = component->driver->trigger(component, substream, cmd);
return 0;
return soc_component_ret(component, ret);
} }
void snd_soc_component_suspend(struct snd_soc_component *component) void snd_soc_component_suspend(struct snd_soc_component *component)
...@@ -287,10 +343,12 @@ int snd_soc_component_is_suspended(struct snd_soc_component *component) ...@@ -287,10 +343,12 @@ int snd_soc_component_is_suspended(struct snd_soc_component *component)
int snd_soc_component_probe(struct snd_soc_component *component) int snd_soc_component_probe(struct snd_soc_component *component)
{ {
int ret = 0;
if (component->driver->probe) if (component->driver->probe)
return component->driver->probe(component); ret = component->driver->probe(component);
return 0; return soc_component_ret(component, ret);
} }
void snd_soc_component_remove(struct snd_soc_component *component) void snd_soc_component_remove(struct snd_soc_component *component)
...@@ -302,20 +360,25 @@ void snd_soc_component_remove(struct snd_soc_component *component) ...@@ -302,20 +360,25 @@ void snd_soc_component_remove(struct snd_soc_component *component)
int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component, int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
struct device_node *ep) struct device_node *ep)
{ {
int ret = -ENOTSUPP;
if (component->driver->of_xlate_dai_id) if (component->driver->of_xlate_dai_id)
return component->driver->of_xlate_dai_id(component, ep); ret = component->driver->of_xlate_dai_id(component, ep);
return -ENOTSUPP; return soc_component_ret(component, ret);
} }
int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component, int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
struct of_phandle_args *args, struct of_phandle_args *args,
const char **dai_name) const char **dai_name)
{ {
int ret = -ENOTSUPP;
if (component->driver->of_xlate_dai_name) if (component->driver->of_xlate_dai_name)
return component->driver->of_xlate_dai_name(component, ret = component->driver->of_xlate_dai_name(component,
args, dai_name); args, dai_name);
return -ENOTSUPP;
return soc_component_ret(component, ret);
} }
void snd_soc_component_setup_regmap(struct snd_soc_component *component) void snd_soc_component_setup_regmap(struct snd_soc_component *component)
...@@ -392,8 +455,10 @@ int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream, ...@@ -392,8 +455,10 @@ int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
/* FIXME: use 1st ioctl */ /* FIXME: use 1st ioctl */
for_each_rtd_components(rtd, i, component) for_each_rtd_components(rtd, i, component)
if (component->driver->ioctl) if (component->driver->ioctl)
return component->driver->ioctl(component, substream, return soc_component_ret(
cmd, arg); component,
component->driver->ioctl(component,
substream, cmd, arg));
return snd_pcm_lib_ioctl(substream, cmd, arg); return snd_pcm_lib_ioctl(substream, cmd, arg);
} }
...@@ -409,7 +474,7 @@ int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream) ...@@ -409,7 +474,7 @@ int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream)
ret = component->driver->sync_stop(component, ret = component->driver->sync_stop(component,
substream); substream);
if (ret < 0) if (ret < 0)
return ret; soc_component_ret(component, ret);
} }
} }
...@@ -427,8 +492,11 @@ int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream, ...@@ -427,8 +492,11 @@ int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
/* FIXME. it returns 1st copy now */ /* FIXME. it returns 1st copy now */
for_each_rtd_components(rtd, i, component) for_each_rtd_components(rtd, i, component)
if (component->driver->copy_user) if (component->driver->copy_user)
return component->driver->copy_user( return soc_component_ret(
component, substream, channel, pos, buf, bytes); component,
component->driver->copy_user(
component, substream, channel,
pos, buf, bytes));
return -EINVAL; return -EINVAL;
} }
...@@ -464,8 +532,10 @@ int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream, ...@@ -464,8 +532,10 @@ int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
/* FIXME. it returns 1st mmap now */ /* FIXME. it returns 1st mmap now */
for_each_rtd_components(rtd, i, component) for_each_rtd_components(rtd, i, component)
if (component->driver->mmap) if (component->driver->mmap)
return component->driver->mmap(component, soc_component_ret(
substream, vma); component,
component->driver->mmap(component,
substream, vma));
return -EINVAL; return -EINVAL;
} }
...@@ -480,7 +550,7 @@ int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd) ...@@ -480,7 +550,7 @@ int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd)
if (component->driver->pcm_construct) { if (component->driver->pcm_construct) {
ret = component->driver->pcm_construct(component, rtd); ret = component->driver->pcm_construct(component, rtd);
if (ret < 0) if (ret < 0)
return ret; soc_component_ret(component, ret);
} }
} }
......
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