[PATCH v2 09/12] ASoC: soc-component: add snd_soc_component_init()
Kuninori Morimoto
kuninori.morimoto.gx at renesas.com
Thu Jun 4 10:07:54 CEST 2020
From: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
we wantn't to directly access to component related parameter
as much as possible to keep encapsulation.
This patch adds snd_soc_component_init() for it.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx at renesas.com>
---
include/sound/soc-component.h | 3 +++
sound/soc/soc-component.c | 16 ++++++++++++++++
sound/soc/soc-core.c | 23 ++++++++++++-----------
3 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/include/sound/soc-component.h b/include/sound/soc-component.h
index bb26d55a9289..aea0eb0c3fcc 100644
--- a/include/sound/soc-component.h
+++ b/include/sound/soc-component.h
@@ -327,6 +327,9 @@ static inline int snd_soc_component_cache_sync(
int snd_soc_component_initialize(struct snd_soc_component *component,
const struct snd_soc_component_driver *driver,
struct device *dev, const char *name);
+void snd_soc_component_set_aux(struct snd_soc_component *component,
+ struct snd_soc_aux_dev *aux);
+int snd_soc_component_init(struct snd_soc_component *component);
/* component IO */
int snd_soc_component_read(struct snd_soc_component *component,
diff --git a/sound/soc/soc-component.c b/sound/soc/soc-component.c
index 150b02be0219..7624ff5b67d3 100644
--- a/sound/soc/soc-component.c
+++ b/sound/soc/soc-component.c
@@ -46,6 +46,22 @@ int snd_soc_component_initialize(struct snd_soc_component *component,
return 0;
}
+void snd_soc_component_set_aux(struct snd_soc_component *component,
+ struct snd_soc_aux_dev *aux)
+{
+ component->init = (aux) ? aux->init : NULL;
+}
+
+int snd_soc_component_init(struct snd_soc_component *component)
+{
+ int ret = 0;
+
+ if (component->init)
+ ret = component->init(component);
+
+ return soc_component_ret(component, ret);
+}
+
/**
* snd_soc_component_set_sysclk - configure COMPONENT system or master clock.
* @component: COMPONENT
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 7e22facf14ea..73f2decfc2fe 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1207,15 +1207,14 @@ static int soc_probe_component(struct snd_soc_card *card,
component->name);
probed = 1;
- /* machine specific init */
- if (component->init) {
- ret = component->init(component);
- if (ret < 0) {
- dev_err(component->dev,
- "Failed to do machine specific init %d\n", ret);
- goto err_probe;
- }
- }
+ /*
+ * machine specific init
+ * see
+ * snd_soc_component_set_aux()
+ */
+ ret = snd_soc_component_init(component);
+ if (ret < 0)
+ goto err_probe;
ret = snd_soc_add_component_controls(component,
component->driver->controls,
@@ -1329,7 +1328,8 @@ static void soc_unbind_aux_dev(struct snd_soc_card *card)
struct snd_soc_component *component, *_component;
for_each_card_auxs_safe(card, component, _component) {
- component->init = NULL;
+ /* for snd_soc_component_init() */
+ snd_soc_component_set_aux(component, NULL);
list_del(&component->card_aux_list);
}
}
@@ -1346,7 +1346,8 @@ static int soc_bind_aux_dev(struct snd_soc_card *card)
if (!component)
return -EPROBE_DEFER;
- component->init = aux->init;
+ /* for snd_soc_component_init() */
+ snd_soc_component_set_aux(component, aux);
/* see for_each_card_auxs */
list_add(&component->card_aux_list, &card->aux_comp_list);
}
--
2.17.1
More information about the Alsa-devel
mailing list