summaryrefslogtreecommitdiff
path: root/sound/soc/soc-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r--sound/soc/soc-core.c1249
1 files changed, 834 insertions, 415 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 434e61b46983..e4b21bf39e59 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -32,6 +32,7 @@
#include <linux/of_graph.h>
#include <linux/dmi.h>
#include <linux/acpi.h>
+#include <linux/string_choices.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
@@ -72,7 +73,7 @@ static ssize_t pmdown_time_show(struct device *dev,
{
struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev);
- return sprintf(buf, "%ld\n", rtd->pmdown_time);
+ return sysfs_emit(buf, "%ld\n", rtd->pmdown_time);
}
static ssize_t pmdown_time_store(struct device *dev,
@@ -107,11 +108,11 @@ static umode_t soc_dev_attr_is_visible(struct kobject *kobj,
if (attr == &dev_attr_pmdown_time.attr)
return attr->mode; /* always visible */
- return rtd->num_codecs ? attr->mode : 0; /* enabled only with codec */
+ return rtd->dai_link->num_codecs ? attr->mode : 0; /* enabled only with codec */
}
static const struct attribute_group soc_dapm_dev_group = {
- .attrs = soc_dapm_dev_attrs,
+ .attrs = snd_soc_dapm_dev_attrs,
.is_visible = soc_dev_attr_is_visible,
};
@@ -150,7 +151,7 @@ static void soc_init_component_debugfs(struct snd_soc_component *component)
component->card->debugfs_card_root);
}
- snd_soc_dapm_debugfs_init(snd_soc_component_get_dapm(component),
+ snd_soc_dapm_debugfs_init(snd_soc_component_to_dapm(component),
component->debugfs_root);
}
@@ -202,7 +203,7 @@ static void soc_init_card_debugfs(struct snd_soc_card *card)
debugfs_create_u32("dapm_pop_time", 0644, card->debugfs_card_root,
&card->pop_time);
- snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
+ snd_soc_dapm_debugfs_init(snd_soc_card_to_dapm(card), card->debugfs_card_root);
}
static void soc_cleanup_card_debugfs(struct snd_soc_card *card)
@@ -238,6 +239,81 @@ static inline void snd_soc_debugfs_exit(void) { }
#endif
+static int snd_soc_is_match_dai_args(const struct of_phandle_args *args1,
+ const struct of_phandle_args *args2)
+{
+ if (!args1 || !args2)
+ return 0;
+
+ if (args1->np != args2->np)
+ return 0;
+
+ for (int i = 0; i < args1->args_count; i++)
+ if (args1->args[i] != args2->args[i])
+ return 0;
+
+ return 1;
+}
+
+static inline int snd_soc_dlc_component_is_empty(struct snd_soc_dai_link_component *dlc)
+{
+ return !(dlc->dai_args || dlc->name || dlc->of_node);
+}
+
+static inline int snd_soc_dlc_component_is_invalid(struct snd_soc_dai_link_component *dlc)
+{
+ return (dlc->name && dlc->of_node);
+}
+
+static inline int snd_soc_dlc_dai_is_empty(struct snd_soc_dai_link_component *dlc)
+{
+ return !(dlc->dai_args || dlc->dai_name);
+}
+
+static int snd_soc_is_matching_dai(const struct snd_soc_dai_link_component *dlc,
+ struct snd_soc_dai *dai)
+{
+ if (!dlc)
+ return 0;
+
+ if (dlc->dai_args)
+ return snd_soc_is_match_dai_args(dai->driver->dai_args, dlc->dai_args);
+
+ if (!dlc->dai_name)
+ return 1;
+
+ /* see snd_soc_dai_name_get() */
+
+ if (dai->driver->name &&
+ strcmp(dlc->dai_name, dai->driver->name) == 0)
+ return 1;
+
+ if (strcmp(dlc->dai_name, dai->name) == 0)
+ return 1;
+
+ if (dai->component->name &&
+ strcmp(dlc->dai_name, dai->component->name) == 0)
+ return 1;
+
+ return 0;
+}
+
+const char *snd_soc_dai_name_get(const struct snd_soc_dai *dai)
+{
+ /* see snd_soc_is_matching_dai() */
+ if (dai->driver->name)
+ return dai->driver->name;
+
+ if (dai->name)
+ return dai->name;
+
+ if (dai->component->name)
+ return dai->component->name;
+
+ return NULL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dai_name_get);
+
static int snd_soc_rtd_add_component(struct snd_soc_pcm_runtime *rtd,
struct snd_soc_component *component)
{
@@ -251,8 +327,8 @@ static int snd_soc_rtd_add_component(struct snd_soc_pcm_runtime *rtd,
}
/* see for_each_rtd_components */
- rtd->components[rtd->num_components] = component;
- rtd->num_components++;
+ rtd->num_components++; // increment flex array count at first
+ rtd->components[rtd->num_components - 1] = component;
return 0;
}
@@ -293,20 +369,25 @@ struct snd_soc_component
*snd_soc_lookup_component_nolocked(struct device *dev, const char *driver_name)
{
struct snd_soc_component *component;
- struct snd_soc_component *found_component;
- found_component = NULL;
for_each_component(component) {
- if ((dev == component->dev) &&
- (!driver_name ||
- (driver_name == component->driver->name) ||
- (strcmp(component->driver->name, driver_name) == 0))) {
- found_component = component;
- break;
- }
+ if (dev != component->dev)
+ continue;
+
+ if (!driver_name)
+ return component;
+
+ if (!component->driver->name)
+ continue;
+
+ if (component->driver->name == driver_name)
+ return component;
+
+ if (strcmp(component->driver->name, driver_name) == 0)
+ return component;
}
- return found_component;
+ return NULL;
}
EXPORT_SYMBOL_GPL(snd_soc_lookup_component_nolocked);
@@ -345,17 +426,17 @@ EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
*/
void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
{
- struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
+ struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
int playback = SNDRV_PCM_STREAM_PLAYBACK;
- mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
+ snd_soc_dpcm_mutex_lock(rtd);
dev_dbg(rtd->dev,
"ASoC: pop wq checking: %s status: %s waiting: %s\n",
codec_dai->driver->playback.stream_name,
snd_soc_dai_stream_active(codec_dai, playback) ?
"active" : "inactive",
- rtd->pop_wait ? "yes" : "no");
+ str_yes_no(rtd->pop_wait));
/* are we waiting on this codec DAI stream */
if (rtd->pop_wait == 1) {
@@ -364,7 +445,7 @@ void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
SND_SOC_DAPM_STREAM_STOP);
}
- mutex_unlock(&rtd->card->pcm_mutex);
+ snd_soc_dpcm_mutex_unlock(rtd);
}
EXPORT_SYMBOL_GPL(snd_soc_close_delayed_work);
@@ -419,7 +500,6 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
{
struct snd_soc_pcm_runtime *rtd;
- struct snd_soc_component *component;
struct device *dev;
int ret;
int stream;
@@ -446,10 +526,10 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
* for rtd
*/
rtd = devm_kzalloc(dev,
- sizeof(*rtd) +
- sizeof(*component) * (dai_link->num_cpus +
- dai_link->num_codecs +
- dai_link->num_platforms),
+ struct_size(rtd, components,
+ dai_link->num_cpus +
+ dai_link->num_codecs +
+ dai_link->num_platforms),
GFP_KERNEL);
if (!rtd) {
device_unregister(dev);
@@ -465,6 +545,11 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
dev_set_drvdata(dev, rtd);
INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
+ if ((dai_link->num_cpus + dai_link->num_codecs) == 0) {
+ dev_err(dev, "ASoC: it has no CPU or codec DAIs\n");
+ goto free_rtd;
+ }
+
/*
* for rtd->dais
*/
@@ -479,14 +564,13 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
* ^cpu_dais ^codec_dais
* |--- num_cpus ---|--- num_codecs --|
* see
- * asoc_rtd_to_cpu()
- * asoc_rtd_to_codec()
+ * snd_soc_rtd_to_cpu()
+ * snd_soc_rtd_to_codec()
*/
- rtd->num_cpus = dai_link->num_cpus;
- rtd->num_codecs = dai_link->num_codecs;
rtd->card = card;
rtd->dai_link = dai_link;
- rtd->num = card->num_rtd++;
+ rtd->id = card->num_rtd++;
+ rtd->pmdown_time = pmdown_time; /* default power off timeout */
/* see for_each_card_rtds */
list_add_tail(&rtd->list, &card->rtd_list);
@@ -502,6 +586,28 @@ free_rtd:
return NULL;
}
+static void snd_soc_fill_dummy_dai(struct snd_soc_card *card)
+{
+ struct snd_soc_dai_link *dai_link;
+ int i;
+
+ /*
+ * COMP_DUMMY() creates size 0 array on dai_link.
+ * Fill it as dummy DAI in case of CPU/Codec here.
+ * Do nothing for Platform.
+ */
+ for_each_card_prelinks(card, i, dai_link) {
+ if (dai_link->num_cpus == 0 && dai_link->cpus) {
+ dai_link->num_cpus = 1;
+ dai_link->cpus = &snd_soc_dummy_dlc;
+ }
+ if (dai_link->num_codecs == 0 && dai_link->codecs) {
+ dai_link->num_codecs = 1;
+ dai_link->codecs = &snd_soc_dummy_dlc;
+ }
+ }
+}
+
static void snd_soc_flush_all_delayed_work(struct snd_soc_card *card)
{
struct snd_soc_pcm_runtime *rtd;
@@ -554,7 +660,7 @@ int snd_soc_suspend(struct device *dev)
int i;
/* If the card is not initialized yet there is nothing to do */
- if (!card->instantiated)
+ if (!snd_soc_card_is_instantiated(card))
return 0;
/*
@@ -585,8 +691,8 @@ int snd_soc_suspend(struct device *dev)
soc_dapm_suspend_resume(card, SND_SOC_DAPM_STREAM_SUSPEND);
/* Recheck all endpoints too, their state is affected by suspend */
- dapm_mark_endpoints_dirty(card);
- snd_soc_dapm_sync(&card->dapm);
+ snd_soc_dapm_mark_endpoints_dirty(card);
+ snd_soc_dapm_sync(snd_soc_card_to_dapm(card));
/* suspend all COMPONENTs */
for_each_card_rtds(card, rtd) {
@@ -595,8 +701,7 @@ int snd_soc_suspend(struct device *dev)
continue;
for_each_rtd_components(rtd, i, component) {
- struct snd_soc_dapm_context *dapm =
- snd_soc_component_get_dapm(component);
+ struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
/*
* ignore if component was already suspended
@@ -616,7 +721,7 @@ int snd_soc_suspend(struct device *dev)
* means it's doing something,
* otherwise fall through.
*/
- if (dapm->idle_bias_off) {
+ if (!snd_soc_dapm_get_idle_bias(dapm)) {
dev_dbg(component->dev,
"ASoC: idle_bias_off CODEC on over suspend\n");
break;
@@ -682,8 +787,8 @@ static void soc_resume_deferred(struct work_struct *work)
dev_dbg(card->dev, "ASoC: resume work completed\n");
/* Recheck all endpoints too, their state is affected by suspend */
- dapm_mark_endpoints_dirty(card);
- snd_soc_dapm_sync(&card->dapm);
+ snd_soc_dapm_mark_endpoints_dirty(card);
+ snd_soc_dapm_sync(snd_soc_card_to_dapm(card));
/* userspace can access us now we are back as we were before */
snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
@@ -696,7 +801,7 @@ int snd_soc_resume(struct device *dev)
struct snd_soc_component *component;
/* If the card is not initialized yet there is nothing to do */
- if (!card->instantiated)
+ if (!snd_soc_card_is_instantiated(card))
return 0;
/* activate pins from sleep state */
@@ -735,6 +840,20 @@ static struct device_node
return of_node;
}
+struct of_phandle_args *snd_soc_copy_dai_args(struct device *dev,
+ const struct of_phandle_args *args)
+{
+ struct of_phandle_args *ret = devm_kzalloc(dev, sizeof(*ret), GFP_KERNEL);
+
+ if (!ret)
+ return NULL;
+
+ *ret = *args;
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_copy_dai_args);
+
static int snd_soc_is_matching_component(
const struct snd_soc_dai_link_component *dlc,
struct snd_soc_component *component)
@@ -744,6 +863,15 @@ static int snd_soc_is_matching_component(
if (!dlc)
return 0;
+ if (dlc->dai_args) {
+ struct snd_soc_dai *dai;
+
+ for_each_component_dais(component, dai)
+ if (snd_soc_is_matching_dai(dlc, dai))
+ return 1;
+ return 0;
+ }
+
component_of_node = soc_component_to_node(component);
if (dlc->of_node && component_of_node != dlc->of_node)
@@ -796,18 +924,11 @@ struct snd_soc_dai *snd_soc_find_dai(
lockdep_assert_held(&client_mutex);
/* Find CPU DAI from registered DAIs */
- for_each_component(component) {
- if (!snd_soc_is_matching_component(dlc, component))
- continue;
- for_each_component_dais(component, dai) {
- if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)
- && (!dai->driver->name
- || strcmp(dai->driver->name, dlc->dai_name)))
- continue;
-
- return dai;
- }
- }
+ for_each_component(component)
+ if (snd_soc_is_matching_component(dlc, component))
+ for_each_component_dais(component, dai)
+ if (snd_soc_is_matching_dai(dlc, dai))
+ return dai;
return NULL;
}
@@ -830,99 +951,188 @@ static int soc_dai_link_sanity_check(struct snd_soc_card *card,
struct snd_soc_dai_link *link)
{
int i;
- struct snd_soc_dai_link_component *cpu, *codec, *platform;
+ struct snd_soc_dai_link_component *dlc;
- for_each_link_codecs(link, i, codec) {
+ /* Codec check */
+ for_each_link_codecs(link, i, dlc) {
/*
* Codec must be specified by 1 of name or OF node,
* not both or neither.
*/
- if (!!codec->name == !!codec->of_node) {
- dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n",
- link->name);
- return -EINVAL;
- }
+ if (snd_soc_dlc_component_is_invalid(dlc))
+ goto component_invalid;
+
+ if (snd_soc_dlc_component_is_empty(dlc))
+ goto component_empty;
/* Codec DAI name must be specified */
- if (!codec->dai_name) {
- dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n",
- link->name);
- return -EINVAL;
- }
+ if (snd_soc_dlc_dai_is_empty(dlc))
+ goto dai_empty;
/*
* Defer card registration if codec component is not added to
* component list.
*/
- if (!soc_find_component(codec)) {
- dev_dbg(card->dev,
- "ASoC: codec component %s not found for link %s\n",
- codec->name, link->name);
- return -EPROBE_DEFER;
- }
+ if (!soc_find_component(dlc))
+ goto component_not_found;
}
- for_each_link_platforms(link, i, platform) {
+ /* Platform check */
+ for_each_link_platforms(link, i, dlc) {
/*
* Platform may be specified by either name or OF node, but it
* can be left unspecified, then no components will be inserted
* in the rtdcom list
*/
- if (!!platform->name == !!platform->of_node) {
- dev_err(card->dev,
- "ASoC: Neither/both platform name/of_node are set for %s\n",
- link->name);
- return -EINVAL;
- }
+ if (snd_soc_dlc_component_is_invalid(dlc))
+ goto component_invalid;
+
+ if (snd_soc_dlc_component_is_empty(dlc))
+ goto component_empty;
/*
* Defer card registration if platform component is not added to
* component list.
*/
- if (!soc_find_component(platform)) {
- dev_dbg(card->dev,
- "ASoC: platform component %s not found for link %s\n",
- platform->name, link->name);
- return -EPROBE_DEFER;
- }
+ if (!soc_find_component(dlc))
+ goto component_not_found;
}
- for_each_link_cpus(link, i, cpu) {
+ /* CPU check */
+ for_each_link_cpus(link, i, dlc) {
/*
* CPU device may be specified by either name or OF node, but
* can be left unspecified, and will be matched based on DAI
* name alone..
*/
- if (cpu->name && cpu->of_node) {
- dev_err(card->dev,
- "ASoC: Neither/both cpu name/of_node are set for %s\n",
- link->name);
- return -EINVAL;
- }
+ if (snd_soc_dlc_component_is_invalid(dlc))
+ goto component_invalid;
- /*
- * Defer card registration if cpu dai component is not added to
- * component list.
- */
- if ((cpu->of_node || cpu->name) &&
- !soc_find_component(cpu)) {
- dev_dbg(card->dev,
- "ASoC: cpu component %s not found for link %s\n",
- cpu->name, link->name);
- return -EPROBE_DEFER;
+
+ if (snd_soc_dlc_component_is_empty(dlc)) {
+ /*
+ * At least one of CPU DAI name or CPU device name/node must be specified
+ */
+ if (snd_soc_dlc_dai_is_empty(dlc))
+ goto component_dai_empty;
+ } else {
+ /*
+ * Defer card registration if Component is not added
+ */
+ if (!soc_find_component(dlc))
+ goto component_not_found;
}
+ }
- /*
- * At least one of CPU DAI name or CPU device name/node must be
- * specified
- */
- if (!cpu->dai_name &&
- !(cpu->name || cpu->of_node)) {
+ return 0;
+
+component_invalid:
+ dev_err(card->dev, "ASoC: Both Component name/of_node are set for %s\n", link->name);
+ return -EINVAL;
+
+component_empty:
+ dev_err(card->dev, "ASoC: Neither Component name/of_node are set for %s\n", link->name);
+ return -EINVAL;
+
+component_not_found:
+ dev_dbg(card->dev, "ASoC: Component %s not found for link %s\n", dlc->name, link->name);
+ return -EPROBE_DEFER;
+
+dai_empty:
+ dev_err(card->dev, "ASoC: DAI name is not set for %s\n", link->name);
+ return -EINVAL;
+
+component_dai_empty:
+ dev_err(card->dev, "ASoC: Neither DAI/Component name/of_node are set for %s\n", link->name);
+ return -EINVAL;
+}
+
+#define MAX_DEFAULT_CH_MAP_SIZE 8
+static struct snd_soc_dai_link_ch_map default_ch_map_sync[MAX_DEFAULT_CH_MAP_SIZE] = {
+ { .cpu = 0, .codec = 0 },
+ { .cpu = 1, .codec = 1 },
+ { .cpu = 2, .codec = 2 },
+ { .cpu = 3, .codec = 3 },
+ { .cpu = 4, .codec = 4 },
+ { .cpu = 5, .codec = 5 },
+ { .cpu = 6, .codec = 6 },
+ { .cpu = 7, .codec = 7 },
+};
+static struct snd_soc_dai_link_ch_map default_ch_map_1cpu[MAX_DEFAULT_CH_MAP_SIZE] = {
+ { .cpu = 0, .codec = 0 },
+ { .cpu = 0, .codec = 1 },
+ { .cpu = 0, .codec = 2 },
+ { .cpu = 0, .codec = 3 },
+ { .cpu = 0, .codec = 4 },
+ { .cpu = 0, .codec = 5 },
+ { .cpu = 0, .codec = 6 },
+ { .cpu = 0, .codec = 7 },
+};
+static struct snd_soc_dai_link_ch_map default_ch_map_1codec[MAX_DEFAULT_CH_MAP_SIZE] = {
+ { .cpu = 0, .codec = 0 },
+ { .cpu = 1, .codec = 0 },
+ { .cpu = 2, .codec = 0 },
+ { .cpu = 3, .codec = 0 },
+ { .cpu = 4, .codec = 0 },
+ { .cpu = 5, .codec = 0 },
+ { .cpu = 6, .codec = 0 },
+ { .cpu = 7, .codec = 0 },
+};
+static int snd_soc_compensate_channel_connection_map(struct snd_soc_card *card,
+ struct snd_soc_dai_link *dai_link)
+{
+ struct snd_soc_dai_link_ch_map *ch_maps;
+ int i;
+
+ /*
+ * dai_link->ch_maps indicates how CPU/Codec are connected.
+ * It will be a map seen from a larger number of DAI.
+ * see
+ * soc.h :: [dai_link->ch_maps Image sample]
+ */
+
+ /* it should have ch_maps if connection was N:M */
+ if (dai_link->num_cpus > 1 && dai_link->num_codecs > 1 &&
+ dai_link->num_cpus != dai_link->num_codecs && !dai_link->ch_maps) {
+ dev_err(card->dev, "need to have ch_maps when N:M connection (%s)",
+ dai_link->name);
+ return -EINVAL;
+ }
+
+ /* do nothing if it has own maps */
+ if (dai_link->ch_maps)
+ goto sanity_check;
+
+ /* check default map size */
+ if (dai_link->num_cpus > MAX_DEFAULT_CH_MAP_SIZE ||
+ dai_link->num_codecs > MAX_DEFAULT_CH_MAP_SIZE) {
+ dev_err(card->dev, "soc-core.c needs update default_connection_maps");
+ return -EINVAL;
+ }
+
+ /* Compensate missing map for ... */
+ if (dai_link->num_cpus == dai_link->num_codecs)
+ dai_link->ch_maps = default_ch_map_sync; /* for 1:1 or N:N */
+ else if (dai_link->num_cpus < dai_link->num_codecs)
+ dai_link->ch_maps = default_ch_map_1cpu; /* for 1:N */
+ else
+ dai_link->ch_maps = default_ch_map_1codec; /* for N:1 */
+
+sanity_check:
+ dev_dbg(card->dev, "dai_link %s\n", dai_link->stream_name);
+ for_each_link_ch_maps(dai_link, i, ch_maps) {
+ if ((ch_maps->cpu >= dai_link->num_cpus) ||
+ (ch_maps->codec >= dai_link->num_codecs)) {
dev_err(card->dev,
- "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
- link->name);
+ "unexpected dai_link->ch_maps[%d] index (cpu(%d/%d) codec(%d/%d))",
+ i,
+ ch_maps->cpu, dai_link->num_cpus,
+ ch_maps->codec, dai_link->num_codecs);
return -EINVAL;
}
+
+ dev_dbg(card->dev, " [%d] cpu%d <-> codec%d\n",
+ i, ch_maps->cpu, ch_maps->codec);
}
return 0;
@@ -938,10 +1148,10 @@ static int soc_dai_link_sanity_check(struct snd_soc_card *card,
void snd_soc_remove_pcm_runtime(struct snd_soc_card *card,
struct snd_soc_pcm_runtime *rtd)
{
- lockdep_assert_held(&client_mutex);
+ if (!rtd)
+ return;
- /* release machine specific resources */
- snd_soc_link_exit(rtd);
+ lockdep_assert_held(&client_mutex);
/*
* Notify the machine driver for extra destruction
@@ -963,13 +1173,13 @@ EXPORT_SYMBOL_GPL(snd_soc_remove_pcm_runtime);
* topology component. And machine drivers can still define static
* DAI links in dai_link array.
*/
-int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
- struct snd_soc_dai_link *dai_link)
+static int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
+ struct snd_soc_dai_link *dai_link)
{
struct snd_soc_pcm_runtime *rtd;
struct snd_soc_dai_link_component *codec, *platform, *cpu;
struct snd_soc_component *component;
- int i, ret;
+ int i, id, ret;
lockdep_assert_held(&client_mutex);
@@ -994,25 +1204,25 @@ int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
return -ENOMEM;
for_each_link_cpus(dai_link, i, cpu) {
- asoc_rtd_to_cpu(rtd, i) = snd_soc_find_dai(cpu);
- if (!asoc_rtd_to_cpu(rtd, i)) {
+ snd_soc_rtd_to_cpu(rtd, i) = snd_soc_find_dai(cpu);
+ if (!snd_soc_rtd_to_cpu(rtd, i)) {
dev_info(card->dev, "ASoC: CPU DAI %s not registered\n",
cpu->dai_name);
goto _err_defer;
}
- snd_soc_rtd_add_component(rtd, asoc_rtd_to_cpu(rtd, i)->component);
+ snd_soc_rtd_add_component(rtd, snd_soc_rtd_to_cpu(rtd, i)->component);
}
/* Find CODEC from registered CODECs */
for_each_link_codecs(dai_link, i, codec) {
- asoc_rtd_to_codec(rtd, i) = snd_soc_find_dai(codec);
- if (!asoc_rtd_to_codec(rtd, i)) {
+ snd_soc_rtd_to_codec(rtd, i) = snd_soc_find_dai(codec);
+ if (!snd_soc_rtd_to_codec(rtd, i)) {
dev_info(card->dev, "ASoC: CODEC DAI %s not registered\n",
codec->dai_name);
goto _err_defer;
}
- snd_soc_rtd_add_component(rtd, asoc_rtd_to_codec(rtd, i)->component);
+ snd_soc_rtd_add_component(rtd, snd_soc_rtd_to_codec(rtd, i)->component);
}
/* Find PLATFORM from registered PLATFORMs */
@@ -1021,23 +1231,66 @@ int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
if (!snd_soc_is_matching_component(platform, component))
continue;
+ if (snd_soc_component_is_dummy(component) && component->num_dai)
+ continue;
+
snd_soc_rtd_add_component(rtd, component);
}
}
+ /*
+ * Most drivers will register their PCMs using DAI link ordering but
+ * topology based drivers can use the DAI link id field to set PCM
+ * device number and then use rtd + a base offset of the BEs.
+ *
+ * FIXME
+ *
+ * This should be implemented by using "dai_link" feature instead of
+ * "component" feature.
+ */
+ id = rtd->id;
+ for_each_rtd_components(rtd, i, component) {
+ if (!component->driver->use_dai_pcm_id)
+ continue;
+
+ if (rtd->dai_link->no_pcm)
+ id += component->driver->be_pcm_base;
+ else
+ id = rtd->dai_link->id;
+ }
+ rtd->id = id;
+
return 0;
_err_defer:
snd_soc_remove_pcm_runtime(card, rtd);
return -EPROBE_DEFER;
}
-EXPORT_SYMBOL_GPL(snd_soc_add_pcm_runtime);
+
+int snd_soc_add_pcm_runtimes(struct snd_soc_card *card,
+ struct snd_soc_dai_link *dai_link,
+ int num_dai_link)
+{
+ for (int i = 0; i < num_dai_link; i++) {
+ int ret;
+
+ ret = snd_soc_compensate_channel_connection_map(card, dai_link + i);
+ if (ret < 0)
+ return ret;
+
+ ret = snd_soc_add_pcm_runtime(card, dai_link + i);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_add_pcm_runtimes);
static void snd_soc_runtime_get_dai_fmt(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_dai_link *dai_link = rtd->dai_link;
struct snd_soc_dai *dai, *not_used;
- struct device *dev = rtd->dev;
u64 pos, possible_fmt;
unsigned int mask = 0, dai_fmt = 0;
int i, j, priority, pri, until;
@@ -1079,8 +1332,6 @@ static void snd_soc_runtime_get_dai_fmt(struct snd_soc_pcm_runtime *rtd)
*/
until = snd_soc_dai_get_fmt_max_priority(rtd);
for (priority = 1; priority <= until; priority++) {
-
- dev_dbg(dev, "priority = %d\n", priority);
for_each_rtd_dais(rtd, j, not_used) {
possible_fmt = ULLONG_MAX;
@@ -1089,7 +1340,6 @@ static void snd_soc_runtime_get_dai_fmt(struct snd_soc_pcm_runtime *rtd)
pri = (j >= i) ? priority : priority - 1;
fmt = snd_soc_dai_get_fmt(dai, pri);
- dev_dbg(dev, "%s: (pri, fmt) = (%d, %016llX)\n", dai->name, pri, fmt);
possible_fmt &= fmt;
}
if (possible_fmt)
@@ -1099,8 +1349,6 @@ static void snd_soc_runtime_get_dai_fmt(struct snd_soc_pcm_runtime *rtd)
/* Not Found */
return;
found:
- dev_dbg(dev, "found auto selected format: %016llX\n", possible_fmt);
-
/*
* convert POSSIBLE_DAIFMT to DAIFMT
*
@@ -1114,7 +1362,7 @@ found:
*
* To avoid such issue, loop from 63 to 0 here.
* Small number of SND_SOC_POSSIBLE_xxx will be Hi priority.
- * Basic/Default settings of each part and aboves are defined
+ * Basic/Default settings of each part and above are defined
* as Hi priority (= small number) of SND_SOC_POSSIBLE_xxx.
*/
for (i = 63; i >= 0; i--) {
@@ -1214,31 +1462,46 @@ int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
{
struct snd_soc_dai *cpu_dai;
struct snd_soc_dai *codec_dai;
- unsigned int inv_dai_fmt;
+ unsigned int ext_fmt;
unsigned int i;
int ret;
if (!dai_fmt)
return 0;
+ /*
+ * dai_fmt has 4 types
+ * 1. SND_SOC_DAIFMT_FORMAT_MASK
+ * 2. SND_SOC_DAIFMT_CLOCK
+ * 3. SND_SOC_DAIFMT_INV
+ * 4. SND_SOC_DAIFMT_CLOCK_PROVIDER
+ *
+ * 4. CLOCK_PROVIDER is set from Codec perspective in dai_fmt. So it will be flipped
+ * when this function calls set_fmt() for CPU (CBx_CFx -> Bx_Cx). see below.
+ * This mean, we can't set CPU/Codec both are clock consumer for example.
+ * New idea handles 4. in each dai->ext_fmt. It can keep compatibility.
+ *
+ * Legacy
+ * dai_fmt includes 1, 2, 3, 4
+ *
+ * New idea
+ * dai_fmt includes 1, 2, 3
+ * ext_fmt includes 4
+ */
for_each_rtd_codec_dais(rtd, i, codec_dai) {
- ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
+ ext_fmt = rtd->dai_link->codecs[i].ext_fmt;
+ ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt | ext_fmt);
if (ret != 0 && ret != -ENOTSUPP)
return ret;
}
- /*
- * Flip the polarity for the "CPU" end of a CODEC<->CODEC link
- */
- inv_dai_fmt = snd_soc_daifmt_clock_provider_fliped(dai_fmt);
+ /* Flip the polarity for the "CPU" end of link */
+ /* Will effect only for 4. SND_SOC_DAIFMT_CLOCK_PROVIDER */
+ dai_fmt = snd_soc_daifmt_clock_provider_flipped(dai_fmt);
for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
- unsigned int fmt = dai_fmt;
-
- if (snd_soc_component_is_codec(cpu_dai->component))
- fmt = inv_dai_fmt;
-
- ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
+ ext_fmt = rtd->dai_link->cpus[i].ext_fmt;
+ ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt | ext_fmt);
if (ret != 0 && ret != -ENOTSUPP)
return ret;
}
@@ -1251,12 +1514,8 @@ static int soc_init_pcm_runtime(struct snd_soc_card *card,
struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_dai_link *dai_link = rtd->dai_link;
- struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
- struct snd_soc_component *component;
- int ret, num, i;
-
- /* set default power off timeout */
- rtd->pmdown_time = pmdown_time;
+ struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
+ int ret;
/* do machine specific initialization */
ret = snd_soc_link_init(rtd);
@@ -1266,42 +1525,34 @@ static int soc_init_pcm_runtime(struct snd_soc_card *card,
snd_soc_runtime_get_dai_fmt(rtd);
ret = snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt);
if (ret)
- return ret;
+ goto err;
/* add DPCM sysfs entries */
soc_dpcm_debugfs_add(rtd);
- num = rtd->num;
-
- /*
- * most drivers will register their PCMs using DAI link ordering but
- * topology based drivers can use the DAI link id field to set PCM
- * device number and then use rtd + a base offset of the BEs.
- */
- for_each_rtd_components(rtd, i, component) {
- if (!component->driver->use_dai_pcm_id)
- continue;
-
- if (rtd->dai_link->no_pcm)
- num += component->driver->be_pcm_base;
- else
- num = rtd->dai_link->id;
- }
-
/* create compress_device if possible */
- ret = snd_soc_dai_compress_new(cpu_dai, rtd, num);
+ ret = snd_soc_dai_compress_new(cpu_dai, rtd);
if (ret != -ENOTSUPP)
- return ret;
+ goto err;
/* create the pcm */
- ret = soc_new_pcm(rtd, num);
+ ret = soc_new_pcm(rtd);
if (ret < 0) {
dev_err(card->dev, "ASoC: can't create pcm %s :%d\n",
dai_link->stream_name, ret);
- return ret;
+ goto err;
}
- return snd_soc_pcm_dai_new(rtd);
+ ret = snd_soc_pcm_dai_new(rtd);
+ if (ret < 0)
+ goto err;
+
+ rtd->initialized = true;
+
+ return 0;
+err:
+ snd_soc_link_exit(rtd);
+ return ret;
}
static void soc_set_name_prefix(struct snd_soc_card *card,
@@ -1343,7 +1594,7 @@ static void soc_remove_component(struct snd_soc_component *component,
snd_soc_component_remove(component);
list_del_init(&component->card_list);
- snd_soc_dapm_free(snd_soc_component_get_dapm(component));
+ snd_soc_dapm_free(snd_soc_component_to_dapm(component));
soc_cleanup_component_debugfs(component);
component->card = NULL;
snd_soc_component_module_put_when_remove(component);
@@ -1352,8 +1603,7 @@ static void soc_remove_component(struct snd_soc_component *component,
static int soc_probe_component(struct snd_soc_card *card,
struct snd_soc_component *component)
{
- struct snd_soc_dapm_context *dapm =
- snd_soc_component_get_dapm(component);
+ struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
struct snd_soc_dai *dai;
int probed = 0;
int ret;
@@ -1364,8 +1614,8 @@ static int soc_probe_component(struct snd_soc_card *card,
if (component->card) {
if (component->card != card) {
dev_err(component->dev,
- "Trying to bind component to card \"%s\" but is already bound to card \"%s\"\n",
- card->name, component->card->name);
+ "Trying to bind component \"%s\" to card \"%s\" but is already bound to card \"%s\"\n",
+ component->name, card->name, component->card->name);
return -ENODEV;
}
return 0;
@@ -1405,8 +1655,8 @@ static int soc_probe_component(struct snd_soc_card *card,
if (ret < 0)
goto err_probe;
- WARN(dapm->idle_bias_off &&
- dapm->bias_level != SND_SOC_BIAS_OFF,
+ WARN(!snd_soc_dapm_get_idle_bias(dapm) &&
+ snd_soc_dapm_get_bias_level(dapm) != SND_SOC_BIAS_OFF,
"codec %s can not start from non-off bias with idle_bias_off==1\n",
component->name);
probed = 1;
@@ -1429,18 +1679,8 @@ static int soc_probe_component(struct snd_soc_card *card,
ret = snd_soc_dapm_add_routes(dapm,
component->driver->dapm_routes,
component->driver->num_dapm_routes);
- if (ret < 0) {
- if (card->disable_route_checks) {
- dev_info(card->dev,
- "%s: disable_route_checks set, ignoring errors on add_routes\n",
- __func__);
- } else {
- dev_err(card->dev,
- "%s: snd_soc_dapm_add_routes failed: %d\n",
- __func__, ret);
- goto err_probe;
- }
- }
+ if (ret < 0)
+ goto err_probe;
/* see for_each_card_components */
list_add(&component->card_list, &card->component_dev_list);
@@ -1472,11 +1712,6 @@ static int soc_probe_link_dais(struct snd_soc_card *card)
for_each_comp_order(order) {
for_each_card_rtds(card, rtd) {
-
- dev_dbg(card->dev,
- "ASoC: probe %s dai link %d late %d\n",
- card->name, rtd->num, order);
-
/* probe all rtd connected DAIs in good order */
ret = snd_soc_pcm_dai_probe(rtd, order);
if (ret)
@@ -1664,10 +1899,9 @@ static void append_dmi_string(struct snd_soc_card *card, const char *str)
/**
* snd_soc_set_dmi_name() - Register DMI names to card
* @card: The card to register DMI names
- * @flavour: The flavour "differentiator" for the card amongst its peers.
*
* An Intel machine driver may be used by many different devices but are
- * difficult for userspace to differentiate, since machine drivers ususally
+ * difficult for userspace to differentiate, since machine drivers usually
* use their own name as the card short name and leave the card long name
* blank. To differentiate such devices and fix bugs due to lack of
* device-specific configurations, this function allows DMI info to be used
@@ -1688,11 +1922,11 @@ static void append_dmi_string(struct snd_soc_card *card, const char *str)
* We only keep number and alphabet characters and a few separator characters
* in the card long name since UCM in the user space uses the card long names
* as card configuration directory names and AudoConf cannot support special
- * charactors like SPACE.
+ * characters like SPACE.
*
* Returns 0 on success, otherwise a negative error code.
*/
-int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
+static int snd_soc_set_dmi_name(struct snd_soc_card *card)
{
const char *vendor, *product, *board;
@@ -1736,16 +1970,16 @@ int snd_soc_set_dmi_name(struct snd_soc_card *card, const char *flavour)
return 0;
}
- /* Add flavour to dmi long name */
- if (flavour)
- append_dmi_string(card, flavour);
-
/* set the card long name */
card->long_name = card->dmi_longname;
return 0;
}
-EXPORT_SYMBOL_GPL(snd_soc_set_dmi_name);
+#else
+static inline int snd_soc_set_dmi_name(struct snd_soc_card *card)
+{
+ return 0;
+}
#endif /* CONFIG_DMI */
static void soc_check_tplg_fes(struct snd_soc_card *card)
@@ -1793,25 +2027,7 @@ match:
dai_link->platforms->name = component->name;
/* convert non BE into BE */
- if (!dai_link->no_pcm) {
- dai_link->no_pcm = 1;
-
- if (dai_link->dpcm_playback)
- dev_warn(card->dev,
- "invalid configuration, dailink %s has flags no_pcm=0 and dpcm_playback=1\n",
- dai_link->name);
- if (dai_link->dpcm_capture)
- dev_warn(card->dev,
- "invalid configuration, dailink %s has flags no_pcm=0 and dpcm_capture=1\n",
- dai_link->name);
-
- /* convert normal link into DPCM one */
- if (!(dai_link->dpcm_playback ||
- dai_link->dpcm_capture)) {
- dai_link->dpcm_playback = !dai_link->capture_only;
- dai_link->dpcm_capture = !dai_link->playback_only;
- }
- }
+ dai_link->no_pcm = 1;
/*
* override any BE fixups
@@ -1848,21 +2064,22 @@ match:
}
}
-#define soc_setup_card_name(name, name1, name2, norm) \
- __soc_setup_card_name(name, sizeof(name), name1, name2, norm)
-static void __soc_setup_card_name(char *name, int len,
- const char *name1, const char *name2,
- int normalization)
+#define soc_setup_card_name(card, name, name1, name2) \
+ __soc_setup_card_name(card, name, sizeof(name), name1, name2)
+static void __soc_setup_card_name(struct snd_soc_card *card,
+ char *name, int len,
+ const char *name1, const char *name2)
{
+ const char *src = name1 ? name1 : name2;
int i;
- snprintf(name, len, "%s", name1 ? name1 : name2);
+ snprintf(name, len, "%s", src);
- if (!normalization)
+ if (name != card->snd_card->driver)
return;
/*
- * Name normalization
+ * Name normalization (driver field)
*
* The driver name is somewhat special, as it's used as a key for
* searches in the user-space.
@@ -1882,6 +2099,14 @@ static void __soc_setup_card_name(char *name, int len,
break;
}
}
+
+ /*
+ * The driver field should contain a valid string from the user view.
+ * The wrapping usually does not work so well here. Set a smaller string
+ * in the specific ASoC driver.
+ */
+ if (strlen(src) > len - 1)
+ dev_err(card->dev, "ASoC: driver name too long '%s' -> '%s'\n", src, name);
}
static void soc_cleanup_card_resources(struct snd_soc_card *card)
@@ -1893,6 +2118,10 @@ static void soc_cleanup_card_resources(struct snd_soc_card *card)
snd_soc_dapm_shutdown(card);
+ /* release machine specific resources */
+ for_each_card_rtds(card, rtd)
+ if (rtd->initialized)
+ snd_soc_link_exit(rtd);
/* remove and free each DAI */
soc_remove_link_dais(card);
soc_remove_link_components(card);
@@ -1904,7 +2133,7 @@ static void soc_cleanup_card_resources(struct snd_soc_card *card)
soc_remove_aux_devices(card);
soc_unbind_aux_dev(card);
- snd_soc_dapm_free(&card->dapm);
+ snd_soc_dapm_free(snd_soc_card_to_dapm(card));
soc_cleanup_card_debugfs(card);
/* remove the card */
@@ -1916,18 +2145,13 @@ static void soc_cleanup_card_resources(struct snd_soc_card *card)
}
}
-static void snd_soc_unbind_card(struct snd_soc_card *card, bool unregister)
+static void snd_soc_unbind_card(struct snd_soc_card *card)
{
- if (card->instantiated) {
+ if (snd_soc_card_is_instantiated(card)) {
card->instantiated = false;
snd_soc_flush_all_delayed_work(card);
soc_cleanup_card_resources(card);
- if (!unregister)
- list_add(&card->list, &unbind_card_list);
- } else {
- if (unregister)
- list_del(&card->list);
}
}
@@ -1935,13 +2159,13 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
{
struct snd_soc_pcm_runtime *rtd;
struct snd_soc_component *component;
- struct snd_soc_dai_link *dai_link;
- int ret, i;
+ struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card);
+ int ret;
- mutex_lock(&client_mutex);
- mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
+ snd_soc_card_mutex_lock_root(card);
+ snd_soc_fill_dummy_dai(card);
- snd_soc_dapm_init(&card->dapm, card, NULL);
+ snd_soc_dapm_init(dapm, card, NULL);
/* check whether any platform is ignore machine FE and using topology */
soc_check_tplg_fes(card);
@@ -1953,11 +2177,9 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
/* add predefined DAI links to the list */
card->num_rtd = 0;
- for_each_card_prelinks(card, i, dai_link) {
- ret = snd_soc_add_pcm_runtime(card, dai_link);
- if (ret < 0)
- goto probe_end;
- }
+ ret = snd_soc_add_pcm_runtimes(card, card->dai_link, card->num_links);
+ if (ret < 0)
+ goto probe_end;
/* card bind complete so register a sound card */
ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
@@ -1973,12 +2195,12 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
soc_resume_init(card);
- ret = snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
+ ret = snd_soc_dapm_new_controls(dapm, card->dapm_widgets,
card->num_dapm_widgets);
if (ret < 0)
goto probe_end;
- ret = snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets,
+ ret = snd_soc_dapm_new_controls(dapm, card->of_dapm_widgets,
card->num_of_dapm_widgets);
if (ret < 0)
goto probe_end;
@@ -1991,8 +2213,10 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
/* probe all components used by DAI links on this card */
ret = soc_probe_link_components(card);
if (ret < 0) {
- dev_err(card->dev,
- "ASoC: failed to instantiate card %d\n", ret);
+ if (ret != -EPROBE_DEFER) {
+ dev_err(card->dev,
+ "ASoC: failed to instantiate card %d\n", ret);
+ }
goto probe_end;
}
@@ -2026,35 +2250,25 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
if (ret < 0)
goto probe_end;
- ret = snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
+ ret = snd_soc_dapm_add_routes(dapm, card->dapm_routes,
card->num_dapm_routes);
- if (ret < 0) {
- if (card->disable_route_checks) {
- dev_info(card->dev,
- "%s: disable_route_checks set, ignoring errors on add_routes\n",
- __func__);
- } else {
- dev_err(card->dev,
- "%s: snd_soc_dapm_add_routes failed: %d\n",
- __func__, ret);
- goto probe_end;
- }
- }
+ if (ret < 0)
+ goto probe_end;
- ret = snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes,
+ ret = snd_soc_dapm_add_routes(dapm, card->of_dapm_routes,
card->num_of_dapm_routes);
if (ret < 0)
goto probe_end;
/* try to set some sane longname if DMI is available */
- snd_soc_set_dmi_name(card, NULL);
+ snd_soc_set_dmi_name(card);
- soc_setup_card_name(card->snd_card->shortname,
- card->name, NULL, 0);
- soc_setup_card_name(card->snd_card->longname,
- card->long_name, card->name, 0);
- soc_setup_card_name(card->snd_card->driver,
- card->driver_name, card->name, 1);
+ soc_setup_card_name(card, card->snd_card->shortname,
+ card->name, NULL);
+ soc_setup_card_name(card, card->snd_card->longname,
+ card->long_name, card->name);
+ soc_setup_card_name(card, card->snd_card->driver,
+ card->driver_name, card->name);
if (card->components) {
/* the current implementation of snd_component_add() accepts */
@@ -2074,6 +2288,7 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
goto probe_end;
snd_soc_dapm_new_widgets(card);
+ snd_soc_card_fixup_controls(card);
ret = snd_card_register(card->snd_card);
if (ret < 0) {
@@ -2083,8 +2298,8 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
}
card->instantiated = 1;
- dapm_mark_endpoints_dirty(card);
- snd_soc_dapm_sync(&card->dapm);
+ snd_soc_dapm_mark_endpoints_dirty(card);
+ snd_soc_dapm_sync(dapm);
/* deactivate pins to sleep state */
for_each_card_components(card, component)
@@ -2094,9 +2309,49 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
probe_end:
if (ret < 0)
soc_cleanup_card_resources(card);
+ snd_soc_card_mutex_unlock(card);
- mutex_unlock(&card->mutex);
- mutex_unlock(&client_mutex);
+ return ret;
+}
+
+static void devm_card_bind_release(struct device *dev, void *res)
+{
+ snd_soc_unregister_card(*(struct snd_soc_card **)res);
+}
+
+static int devm_snd_soc_bind_card(struct device *dev, struct snd_soc_card *card)
+{
+ struct snd_soc_card **ptr;
+ int ret;
+
+ ptr = devres_alloc(devm_card_bind_release, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return -ENOMEM;
+
+ ret = snd_soc_bind_card(card);
+ if (ret == 0 || ret == -EPROBE_DEFER) {
+ *ptr = card;
+ devres_add(dev, ptr);
+ } else {
+ devres_free(ptr);
+ }
+
+ return ret;
+}
+
+static int snd_soc_rebind_card(struct snd_soc_card *card)
+{
+ int ret;
+
+ if (card->devres_dev) {
+ devres_destroy(card->devres_dev, devm_card_bind_release, NULL, NULL);
+ ret = devm_snd_soc_bind_card(card->devres_dev, card);
+ } else {
+ ret = snd_soc_bind_card(card);
+ }
+
+ if (ret != -EPROBE_DEFER)
+ list_del_init(&card->list);
return ret;
}
@@ -2128,7 +2383,7 @@ int snd_soc_poweroff(struct device *dev)
struct snd_soc_card *card = dev_get_drvdata(dev);
struct snd_soc_component *component;
- if (!card->instantiated)
+ if (!snd_soc_card_is_instantiated(card))
return 0;
/*
@@ -2270,7 +2525,7 @@ EXPORT_SYMBOL_GPL(snd_soc_add_card_controls);
/**
* snd_soc_add_dai_controls - add an array of controls to a DAI.
- * Convienience function to add a list of controls.
+ * Convenience function to add a list of controls.
*
* @dai: DAI to add controls to
* @controls: array of controls to add
@@ -2296,6 +2551,8 @@ EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
*/
int snd_soc_register_card(struct snd_soc_card *card)
{
+ int ret;
+
if (!card->name || !card->dev)
return -EINVAL;
@@ -2316,7 +2573,21 @@ int snd_soc_register_card(struct snd_soc_card *card)
mutex_init(&card->dapm_mutex);
mutex_init(&card->pcm_mutex);
- return snd_soc_bind_card(card);
+ mutex_lock(&client_mutex);
+
+ if (card->devres_dev) {
+ ret = devm_snd_soc_bind_card(card->devres_dev, card);
+ if (ret == -EPROBE_DEFER) {
+ list_add(&card->list, &unbind_card_list);
+ ret = 0;
+ }
+ } else {
+ ret = snd_soc_bind_card(card);
+ }
+
+ mutex_unlock(&client_mutex);
+
+ return ret;
}
EXPORT_SYMBOL_GPL(snd_soc_register_card);
@@ -2326,14 +2597,13 @@ EXPORT_SYMBOL_GPL(snd_soc_register_card);
* @card: Card to unregister
*
*/
-int snd_soc_unregister_card(struct snd_soc_card *card)
+void snd_soc_unregister_card(struct snd_soc_card *card)
{
mutex_lock(&client_mutex);
- snd_soc_unbind_card(card, true);
+ snd_soc_unbind_card(card);
+ list_del(&card->list);
mutex_unlock(&client_mutex);
dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
-
- return 0;
}
EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
@@ -2346,6 +2616,7 @@ static char *fmt_single_name(struct device *dev, int *id)
const char *devname = dev_name(dev);
char *found, *name;
unsigned int id1, id2;
+ int __id;
if (devname == NULL)
return NULL;
@@ -2358,10 +2629,10 @@ static char *fmt_single_name(struct device *dev, int *id)
found = strstr(name, dev->driver->name);
if (found) {
/* get ID */
- if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
+ if (sscanf(&found[strlen(dev->driver->name)], ".%d", &__id) == 1) {
/* discard ID from name if ID == -1 */
- if (*id == -1)
+ if (__id == -1)
found[strlen(dev->driver->name)] = '\0';
}
@@ -2369,16 +2640,19 @@ static char *fmt_single_name(struct device *dev, int *id)
} else if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
/* create unique ID number from I2C addr and bus */
- *id = ((id1 & 0xffff) << 16) + id2;
+ __id = ((id1 & 0xffff) << 16) + id2;
devm_kfree(dev, name);
/* sanitize component name for DAI link creation */
name = devm_kasprintf(dev, GFP_KERNEL, "%s.%s", dev->driver->name, devname);
} else {
- *id = 0;
+ __id = 0;
}
+ if (id)
+ *id = __id;
+
return name;
}
@@ -2425,8 +2699,6 @@ struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
struct device *dev = component->dev;
struct snd_soc_dai *dai;
- dev_dbg(dev, "ASoC: dynamically register DAI %s\n", dev_name(dev));
-
lockdep_assert_held(&client_mutex);
dai = devm_kzalloc(dev, sizeof(*dai), GFP_KERNEL);
@@ -2465,6 +2737,7 @@ struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
return dai;
}
+EXPORT_SYMBOL_GPL(snd_soc_register_dai);
/**
* snd_soc_unregister_dais - Unregister DAIs from the ASoC core
@@ -2496,7 +2769,7 @@ static int snd_soc_register_dais(struct snd_soc_component *component,
for (i = 0; i < count; i++) {
dai = snd_soc_register_dai(component, dai_drv + i, count == 1 &&
- !snd_soc_component_is_codec(component));
+ component->driver->legacy_dai_naming);
if (dai == NULL) {
ret = -ENOMEM;
goto err;
@@ -2546,23 +2819,19 @@ static void convert_endianness_formats(struct snd_soc_pcm_stream *stream)
stream->formats |= endianness_format_map[i];
}
-static void snd_soc_try_rebind_card(void)
-{
- struct snd_soc_card *card, *c;
-
- list_for_each_entry_safe(card, c, &unbind_card_list, list)
- if (!snd_soc_bind_card(card))
- list_del(&card->list);
-}
-
static void snd_soc_del_component_unlocked(struct snd_soc_component *component)
{
struct snd_soc_card *card = component->card;
+ bool instantiated;
snd_soc_unregister_dais(component);
- if (card)
- snd_soc_unbind_card(card, false);
+ if (card) {
+ instantiated = card->instantiated;
+ snd_soc_unbind_card(card);
+ if (instantiated)
+ list_add(&card->list, &unbind_card_list);
+ }
list_del(&component->list);
}
@@ -2577,15 +2846,22 @@ int snd_soc_component_initialize(struct snd_soc_component *component,
INIT_LIST_HEAD(&component->list);
mutex_init(&component->io_mutex);
- component->name = fmt_single_name(dev, &component->id);
if (!component->name) {
- dev_err(dev, "ASoC: Failed to allocate name\n");
- return -ENOMEM;
+ component->name = fmt_single_name(dev, NULL);
+ if (!component->name) {
+ dev_err(dev, "ASoC: Failed to allocate name\n");
+ return -ENOMEM;
+ }
}
component->dev = dev;
component->driver = driver;
+#ifdef CONFIG_DEBUG_FS
+ if (!component->debugfs_prefix)
+ component->debugfs_prefix = driver->debugfs_prefix;
+#endif
+
return 0;
}
EXPORT_SYMBOL_GPL(snd_soc_component_initialize);
@@ -2594,6 +2870,7 @@ int snd_soc_add_component(struct snd_soc_component *component,
struct snd_soc_dai_driver *dai_drv,
int num_dai)
{
+ struct snd_soc_card *card, *c;
int ret;
int i;
@@ -2624,15 +2901,14 @@ int snd_soc_add_component(struct snd_soc_component *component,
/* see for_each_component */
list_add(&component->list, &component_list);
+ list_for_each_entry_safe(card, c, &unbind_card_list, list)
+ snd_soc_rebind_card(card);
+
err_cleanup:
if (ret < 0)
snd_soc_del_component_unlocked(component);
mutex_unlock(&client_mutex);
-
- if (ret == 0)
- snd_soc_try_rebind_card();
-
return ret;
}
EXPORT_SYMBOL_GPL(snd_soc_add_component);
@@ -2667,34 +2943,14 @@ EXPORT_SYMBOL_GPL(snd_soc_register_component);
void snd_soc_unregister_component_by_driver(struct device *dev,
const struct snd_soc_component_driver *component_driver)
{
- struct snd_soc_component *component;
+ const char *driver_name = NULL;
- if (!component_driver)
- return;
+ if (component_driver)
+ driver_name = component_driver->name;
mutex_lock(&client_mutex);
- component = snd_soc_lookup_component_nolocked(dev, component_driver->name);
- if (!component)
- goto out;
-
- snd_soc_del_component_unlocked(component);
-
-out:
- mutex_unlock(&client_mutex);
-}
-EXPORT_SYMBOL_GPL(snd_soc_unregister_component_by_driver);
-
-/**
- * snd_soc_unregister_component - Unregister all related component
- * from the ASoC core
- *
- * @dev: The device to unregister
- */
-void snd_soc_unregister_component(struct device *dev)
-{
- mutex_lock(&client_mutex);
while (1) {
- struct snd_soc_component *component = snd_soc_lookup_component_nolocked(dev, NULL);
+ struct snd_soc_component *component = snd_soc_lookup_component_nolocked(dev, driver_name);
if (!component)
break;
@@ -2703,7 +2959,7 @@ void snd_soc_unregister_component(struct device *dev)
}
mutex_unlock(&client_mutex);
}
-EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
+EXPORT_SYMBOL_GPL(snd_soc_unregister_component_by_driver);
/* Retrieve a card's name from device tree */
int snd_soc_of_parse_card_name(struct snd_soc_card *card,
@@ -2757,6 +3013,11 @@ int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
"ASoC: Property '%s' does not exist\n", propname);
return -EINVAL;
}
+ if (!num_widgets) {
+ dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
+ propname);
+ return -EINVAL;
+ }
if (num_widgets & 1) {
dev_err(card->dev,
"ASoC: Property '%s' length is not even\n", propname);
@@ -2764,11 +3025,6 @@ int snd_soc_of_parse_audio_simple_widgets(struct snd_soc_card *card,
}
num_widgets /= 2;
- if (!num_widgets) {
- dev_err(card->dev, "ASoC: Property '%s's length is zero\n",
- propname);
- return -EINVAL;
- }
widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets),
GFP_KERNEL);
@@ -2832,7 +3088,7 @@ int snd_soc_of_parse_pin_switches(struct snd_soc_card *card, const char *prop)
unsigned int i, nb_controls;
int ret;
- if (!of_property_read_bool(dev->of_node, prop))
+ if (!of_property_present(dev->of_node, prop))
return 0;
strings = devm_kcalloc(dev, nb_controls_max,
@@ -2906,28 +3162,30 @@ int snd_soc_of_parse_tdm_slot(struct device_node *np,
if (rx_mask)
snd_soc_of_get_slot_mask(np, "dai-tdm-slot-rx-mask", rx_mask);
- if (of_property_read_bool(np, "dai-tdm-slot-num")) {
- ret = of_property_read_u32(np, "dai-tdm-slot-num", &val);
- if (ret)
- return ret;
-
- if (slots)
- *slots = val;
- }
-
- if (of_property_read_bool(np, "dai-tdm-slot-width")) {
- ret = of_property_read_u32(np, "dai-tdm-slot-width", &val);
- if (ret)
- return ret;
+ ret = of_property_read_u32(np, "dai-tdm-slot-num", &val);
+ if (ret && ret != -EINVAL)
+ return ret;
+ if (!ret && slots)
+ *slots = val;
- if (slot_width)
- *slot_width = val;
- }
+ ret = of_property_read_u32(np, "dai-tdm-slot-width", &val);
+ if (ret && ret != -EINVAL)
+ return ret;
+ if (!ret && slot_width)
+ *slot_width = val;
return 0;
}
EXPORT_SYMBOL_GPL(snd_soc_of_parse_tdm_slot);
+void snd_soc_dlc_use_cpu_as_platform(struct snd_soc_dai_link_component *platforms,
+ struct snd_soc_dai_link_component *cpus)
+{
+ platforms->of_node = cpus->of_node;
+ platforms->dai_args = cpus->dai_args;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dlc_use_cpu_as_platform);
+
void snd_soc_of_parse_node_prefix(struct device_node *np,
struct snd_soc_codec_conf *codec_conf,
struct device_node *of_node,
@@ -3029,7 +3287,7 @@ int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname)
}
EXPORT_SYMBOL_GPL(snd_soc_of_parse_aux_devs);
-unsigned int snd_soc_daifmt_clock_provider_fliped(unsigned int dai_fmt)
+unsigned int snd_soc_daifmt_clock_provider_flipped(unsigned int dai_fmt)
{
unsigned int inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK;
@@ -3050,7 +3308,7 @@ unsigned int snd_soc_daifmt_clock_provider_fliped(unsigned int dai_fmt)
return inv_dai_fmt;
}
-EXPORT_SYMBOL_GPL(snd_soc_daifmt_clock_provider_fliped);
+EXPORT_SYMBOL_GPL(snd_soc_daifmt_clock_provider_flipped);
unsigned int snd_soc_daifmt_clock_provider_from_bitmap(unsigned int bit_frame)
{
@@ -3138,10 +3396,10 @@ unsigned int snd_soc_daifmt_parse_format(struct device_node *np,
* SND_SOC_DAIFMT_INV_MASK area
*/
snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix);
- bit = !!of_get_property(np, prop, NULL);
+ bit = of_property_read_bool(np, prop);
snprintf(prop, sizeof(prop), "%sframe-inversion", prefix);
- frame = !!of_get_property(np, prop, NULL);
+ frame = of_property_read_bool(np, prop);
switch ((bit << 4) + frame) {
case 0x11:
@@ -3170,6 +3428,9 @@ unsigned int snd_soc_daifmt_parse_clock_provider_raw(struct device_node *np,
char prop[128];
unsigned int bit, frame;
+ if (!np)
+ return 0;
+
if (!prefix)
prefix = "";
@@ -3178,12 +3439,12 @@ unsigned int snd_soc_daifmt_parse_clock_provider_raw(struct device_node *np,
* check "[prefix]frame-master"
*/
snprintf(prop, sizeof(prop), "%sbitclock-master", prefix);
- bit = !!of_get_property(np, prop, NULL);
+ bit = of_property_present(np, prop);
if (bit && bitclkmaster)
*bitclkmaster = of_parse_phandle(np, prop, 0);
snprintf(prop, sizeof(prop), "%sframe-master", prefix);
- frame = !!of_get_property(np, prop, NULL);
+ frame = of_property_present(np, prop);
if (frame && framemaster)
*framemaster = of_parse_phandle(np, prop, 0);
@@ -3196,14 +3457,49 @@ unsigned int snd_soc_daifmt_parse_clock_provider_raw(struct device_node *np,
}
EXPORT_SYMBOL_GPL(snd_soc_daifmt_parse_clock_provider_raw);
+int snd_soc_get_stream_cpu(const struct snd_soc_dai_link *dai_link, int stream)
+{
+ /*
+ * [Normal]
+ *
+ * Playback
+ * CPU : SNDRV_PCM_STREAM_PLAYBACK
+ * Codec: SNDRV_PCM_STREAM_PLAYBACK
+ *
+ * Capture
+ * CPU : SNDRV_PCM_STREAM_CAPTURE
+ * Codec: SNDRV_PCM_STREAM_CAPTURE
+ */
+ if (!dai_link->c2c_params)
+ return stream;
+
+ /*
+ * [Codec2Codec]
+ *
+ * Playback
+ * CPU : SNDRV_PCM_STREAM_CAPTURE
+ * Codec: SNDRV_PCM_STREAM_PLAYBACK
+ *
+ * Capture
+ * CPU : SNDRV_PCM_STREAM_PLAYBACK
+ * Codec: SNDRV_PCM_STREAM_CAPTURE
+ */
+ if (stream == SNDRV_PCM_STREAM_CAPTURE)
+ return SNDRV_PCM_STREAM_PLAYBACK;
+
+ return SNDRV_PCM_STREAM_CAPTURE;
+}
+EXPORT_SYMBOL_GPL(snd_soc_get_stream_cpu);
+
int snd_soc_get_dai_id(struct device_node *ep)
{
struct snd_soc_component *component;
- struct snd_soc_dai_link_component dlc;
+ struct snd_soc_dai_link_component dlc = {
+ .of_node = of_graph_get_port_parent(ep),
+ };
int ret;
- dlc.of_node = of_graph_get_port_parent(ep);
- dlc.name = NULL;
+
/*
* For example HDMI case, HDMI has video/sound port,
* but ALSA SoC needs sound port number only.
@@ -3223,8 +3519,7 @@ int snd_soc_get_dai_id(struct device_node *ep)
}
EXPORT_SYMBOL_GPL(snd_soc_get_dai_id);
-int snd_soc_get_dai_name(const struct of_phandle_args *args,
- const char **dai_name)
+int snd_soc_get_dlc(const struct of_phandle_args *args, struct snd_soc_dai_link_component *dlc)
{
struct snd_soc_component *pos;
int ret = -EPROBE_DEFER;
@@ -3233,10 +3528,10 @@ int snd_soc_get_dai_name(const struct of_phandle_args *args,
for_each_component(pos) {
struct device_node *component_of_node = soc_component_to_node(pos);
- if (component_of_node != args->np)
+ if (component_of_node != args->np || !pos->num_dai)
continue;
- ret = snd_soc_component_of_xlate_dai_name(pos, args, dai_name);
+ ret = snd_soc_component_of_xlate_dai_name(pos, args, &dlc->dai_name);
if (ret == -ENOTSUPP) {
struct snd_soc_dai *dai;
int id = -1;
@@ -3267,9 +3562,7 @@ int snd_soc_get_dai_name(const struct of_phandle_args *args,
id--;
}
- *dai_name = dai->driver->name;
- if (!*dai_name)
- *dai_name = pos->name;
+ dlc->dai_name = snd_soc_dai_name_get(dai);
} else if (ret) {
/*
* if another error than ENOTSUPP is returned go on and
@@ -3282,30 +3575,114 @@ int snd_soc_get_dai_name(const struct of_phandle_args *args,
break;
}
+
+ if (ret == 0)
+ dlc->of_node = args->np;
+
mutex_unlock(&client_mutex);
return ret;
}
-EXPORT_SYMBOL_GPL(snd_soc_get_dai_name);
+EXPORT_SYMBOL_GPL(snd_soc_get_dlc);
-int snd_soc_of_get_dai_name(struct device_node *of_node,
- const char **dai_name)
+int snd_soc_of_get_dlc(struct device_node *of_node,
+ struct of_phandle_args *args,
+ struct snd_soc_dai_link_component *dlc,
+ int index)
{
- struct of_phandle_args args;
+ struct of_phandle_args __args;
int ret;
+ if (!args)
+ args = &__args;
+
ret = of_parse_phandle_with_args(of_node, "sound-dai",
- "#sound-dai-cells", 0, &args);
+ "#sound-dai-cells", index, args);
if (ret)
return ret;
- ret = snd_soc_get_dai_name(&args, dai_name);
+ return snd_soc_get_dlc(args, dlc);
+}
+EXPORT_SYMBOL_GPL(snd_soc_of_get_dlc);
- of_node_put(args.np);
+int snd_soc_get_dai_name(const struct of_phandle_args *args,
+ const char **dai_name)
+{
+ struct snd_soc_dai_link_component dlc;
+ int ret = snd_soc_get_dlc(args, &dlc);
+
+ if (ret == 0)
+ *dai_name = dlc.dai_name;
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_get_dai_name);
+
+int snd_soc_of_get_dai_name(struct device_node *of_node,
+ const char **dai_name, int index)
+{
+ struct snd_soc_dai_link_component dlc;
+ int ret = snd_soc_of_get_dlc(of_node, NULL, &dlc, index);
+
+ if (ret == 0)
+ *dai_name = dlc.dai_name;
return ret;
}
EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
+struct snd_soc_dai *snd_soc_get_dai_via_args(const struct of_phandle_args *dai_args)
+{
+ struct snd_soc_dai *dai;
+ struct snd_soc_component *component;
+
+ mutex_lock(&client_mutex);
+ for_each_component(component) {
+ for_each_component_dais(component, dai)
+ if (snd_soc_is_match_dai_args(dai->driver->dai_args, dai_args))
+ goto found;
+ }
+ dai = NULL;
+found:
+ mutex_unlock(&client_mutex);
+ return dai;
+}
+EXPORT_SYMBOL_GPL(snd_soc_get_dai_via_args);
+
+static void __snd_soc_of_put_component(struct snd_soc_dai_link_component *component)
+{
+ if (component->of_node) {
+ of_node_put(component->of_node);
+ component->of_node = NULL;
+ }
+}
+
+static int __snd_soc_of_get_dai_link_component_alloc(
+ struct device *dev, struct device_node *of_node,
+ struct snd_soc_dai_link_component **ret_component,
+ int *ret_num)
+{
+ struct snd_soc_dai_link_component *component;
+ int num;
+
+ /* Count the number of CPUs/CODECs */
+ num = of_count_phandle_with_args(of_node, "sound-dai", "#sound-dai-cells");
+ if (num <= 0) {
+ if (num == -ENOENT)
+ dev_err(dev, "No 'sound-dai' property\n");
+ else
+ dev_err(dev, "Bad phandle in 'sound-dai'\n");
+ return num;
+ }
+ component = devm_kcalloc(dev, num, sizeof(*component), GFP_KERNEL);
+ if (!component)
+ return -ENOMEM;
+
+ *ret_component = component;
+ *ret_num = num;
+
+ return 0;
+}
+
/*
* snd_soc_of_put_dai_link_codecs - Dereference device nodes in the codecs array
* @dai_link: DAI link
@@ -3317,12 +3694,8 @@ void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link)
struct snd_soc_dai_link_component *component;
int index;
- for_each_link_codecs(dai_link, index, component) {
- if (!component->of_node)
- break;
- of_node_put(component->of_node);
- component->of_node = NULL;
- }
+ for_each_link_codecs(dai_link, index, component)
+ __snd_soc_of_put_component(component);
}
EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_codecs);
@@ -3344,41 +3717,19 @@ int snd_soc_of_get_dai_link_codecs(struct device *dev,
struct device_node *of_node,
struct snd_soc_dai_link *dai_link)
{
- struct of_phandle_args args;
struct snd_soc_dai_link_component *component;
- char *name;
- int index, num_codecs, ret;
-
- /* Count the number of CODECs */
- name = "sound-dai";
- num_codecs = of_count_phandle_with_args(of_node, name,
- "#sound-dai-cells");
- if (num_codecs <= 0) {
- if (num_codecs == -ENOENT)
- dev_err(dev, "No 'sound-dai' property\n");
- else
- dev_err(dev, "Bad phandle in 'sound-dai'\n");
- return num_codecs;
- }
- component = devm_kcalloc(dev,
- num_codecs, sizeof(*component),
- GFP_KERNEL);
- if (!component)
- return -ENOMEM;
- dai_link->codecs = component;
- dai_link->num_codecs = num_codecs;
+ int index, ret;
+
+ ret = __snd_soc_of_get_dai_link_component_alloc(dev, of_node,
+ &dai_link->codecs, &dai_link->num_codecs);
+ if (ret < 0)
+ return ret;
/* Parse the list */
for_each_link_codecs(dai_link, index, component) {
- ret = of_parse_phandle_with_args(of_node, name,
- "#sound-dai-cells",
- index, &args);
+ ret = snd_soc_of_get_dlc(of_node, NULL, component, index);
if (ret)
goto err;
- component->of_node = args.np;
- ret = snd_soc_get_dai_name(&args, &component->dai_name);
- if (ret < 0)
- goto err;
}
return 0;
err:
@@ -3389,12 +3740,80 @@ err:
}
EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_codecs);
+/*
+ * snd_soc_of_put_dai_link_cpus - Dereference device nodes in the codecs array
+ * @dai_link: DAI link
+ *
+ * Dereference device nodes acquired by snd_soc_of_get_dai_link_cpus().
+ */
+void snd_soc_of_put_dai_link_cpus(struct snd_soc_dai_link *dai_link)
+{
+ struct snd_soc_dai_link_component *component;
+ int index;
+
+ for_each_link_cpus(dai_link, index, component)
+ __snd_soc_of_put_component(component);
+}
+EXPORT_SYMBOL_GPL(snd_soc_of_put_dai_link_cpus);
+
+/*
+ * snd_soc_of_get_dai_link_cpus - Parse a list of CPU DAIs in the devicetree
+ * @dev: Card device
+ * @of_node: Device node
+ * @dai_link: DAI link
+ *
+ * Is analogous to snd_soc_of_get_dai_link_codecs but parses a list of CPU DAIs
+ * instead.
+ *
+ * Returns 0 for success
+ */
+int snd_soc_of_get_dai_link_cpus(struct device *dev,
+ struct device_node *of_node,
+ struct snd_soc_dai_link *dai_link)
+{
+ struct snd_soc_dai_link_component *component;
+ int index, ret;
+
+ /* Count the number of CPUs */
+ ret = __snd_soc_of_get_dai_link_component_alloc(dev, of_node,
+ &dai_link->cpus, &dai_link->num_cpus);
+ if (ret < 0)
+ return ret;
+
+ /* Parse the list */
+ for_each_link_cpus(dai_link, index, component) {
+ ret = snd_soc_of_get_dlc(of_node, NULL, component, index);
+ if (ret)
+ goto err;
+ }
+ return 0;
+err:
+ snd_soc_of_put_dai_link_cpus(dai_link);
+ dai_link->cpus = NULL;
+ dai_link->num_cpus = 0;
+ return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_link_cpus);
+
static int __init snd_soc_init(void)
{
+ int ret;
+
snd_soc_debugfs_init();
- snd_soc_util_init();
+ ret = snd_soc_util_init();
+ if (ret)
+ goto err_util_init;
+
+ ret = platform_driver_register(&soc_driver);
+ if (ret)
+ goto err_register;
+ return 0;
- return platform_driver_register(&soc_driver);
+err_register:
+ snd_soc_util_exit();
+err_util_init:
+ snd_soc_debugfs_exit();
+ return ret;
}
module_init(snd_soc_init);