From 94f99c875c109e51decf0d8c25ec2c946db20c56 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 16 Jun 2014 18:13:01 +0200 Subject: ASoC: Move name_prefix from CODEC to component Move the name_prefix from the CODEC struct to the component struct. This will eventually allow to specify prefixes for all types of components. It is also necessary to make the DAPM code component type independent (i.e. a DAPM context does not need to know whether it belongs to a CODEC or a platform or something else). Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- include/sound/soc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/sound') diff --git a/include/sound/soc.h b/include/sound/soc.h index ed9e2d7e5fdc..e1cce0042f8a 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -682,6 +682,7 @@ struct snd_soc_component_driver { struct snd_soc_component { const char *name; int id; + const char *name_prefix; struct device *dev; unsigned int active; @@ -710,7 +711,6 @@ struct snd_soc_component { /* SoC Audio Codec device */ struct snd_soc_codec { const char *name; - const char *name_prefix; int id; struct device *dev; const struct snd_soc_codec_driver *driver; -- cgit v1.2.3-58-ga151 From f4333203ec933f9272c90c7add01774ec2cf94d3 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 16 Jun 2014 18:13:02 +0200 Subject: ASoC: Move name and id from CODEC/platform to component The component struct already has a name and id field which are initialized to the same values as the same fields in the CODEC and platform structs. So remove them from the CODEC and platform structs and used the ones from the component struct instead. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- include/sound/soc.h | 4 ---- include/trace/events/asoc.h | 6 ++--- sound/soc/codecs/tlv320dac33.c | 2 +- sound/soc/soc-cache.c | 7 +++--- sound/soc/soc-compress.c | 8 ++++--- sound/soc/soc-core.c | 53 ++++++++++++++++-------------------------- sound/soc/soc-dapm.c | 8 +++---- sound/soc/soc-pcm.c | 4 ++-- 8 files changed, 38 insertions(+), 54 deletions(-) (limited to 'include/sound') diff --git a/include/sound/soc.h b/include/sound/soc.h index e1cce0042f8a..f64bf9452466 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -710,8 +710,6 @@ struct snd_soc_component { /* SoC Audio Codec device */ struct snd_soc_codec { - const char *name; - int id; struct device *dev; const struct snd_soc_codec_driver *driver; @@ -848,8 +846,6 @@ struct snd_soc_platform_driver { }; struct snd_soc_platform { - const char *name; - int id; struct device *dev; const struct snd_soc_platform_driver *driver; diff --git a/include/trace/events/asoc.h b/include/trace/events/asoc.h index c75c795a377b..0194a641e4e2 100644 --- a/include/trace/events/asoc.h +++ b/include/trace/events/asoc.h @@ -296,17 +296,17 @@ TRACE_EVENT(snd_soc_cache_sync, TP_ARGS(codec, type, status), TP_STRUCT__entry( - __string( name, codec->name ) + __string( name, codec->component.name) __string( status, status ) __string( type, type ) __field( int, id ) ), TP_fast_assign( - __assign_str(name, codec->name); + __assign_str(name, codec->component.name); __assign_str(status, status); __assign_str(type, type); - __entry->id = codec->id; + __entry->id = codec->component.id; ), TP_printk("codec=%s.%d type=%s status=%s", __get_str(name), diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c index df3a7506c023..ff006cc95520 100644 --- a/sound/soc/codecs/tlv320dac33.c +++ b/sound/soc/codecs/tlv320dac33.c @@ -1404,7 +1404,7 @@ static int dac33_soc_probe(struct snd_soc_codec *codec) if (dac33->irq >= 0) { ret = request_irq(dac33->irq, dac33_interrupt_handler, IRQF_TRIGGER_RISING, - codec->name, codec); + codec->component.name, codec); if (ret < 0) { dev_err(codec->dev, "Could not request IRQ%d (%d)\n", dac33->irq, ret); diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c index 00e70b6c7da2..a9f82b5aba9d 100644 --- a/sound/soc/soc-cache.c +++ b/sound/soc/soc-cache.c @@ -78,7 +78,7 @@ int snd_soc_cache_init(struct snd_soc_codec *codec) mutex_init(&codec->cache_rw_mutex); dev_dbg(codec->dev, "ASoC: Initializing cache for %s codec\n", - codec->name); + codec->component.name); if (codec_drv->reg_cache_default) codec->reg_cache = kmemdup(codec_drv->reg_cache_default, @@ -98,8 +98,7 @@ int snd_soc_cache_init(struct snd_soc_codec *codec) int snd_soc_cache_exit(struct snd_soc_codec *codec) { dev_dbg(codec->dev, "ASoC: Destroying cache for %s codec\n", - codec->name); - + codec->component.name); kfree(codec->reg_cache); codec->reg_cache = NULL; return 0; @@ -192,7 +191,7 @@ int snd_soc_cache_sync(struct snd_soc_codec *codec) return 0; dev_dbg(codec->dev, "ASoC: Syncing cache for %s codec\n", - codec->name); + codec->component.name); trace_snd_soc_cache_sync(codec, name, "start"); ret = snd_soc_flat_cache_sync(codec); if (!ret) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 10f7f1da2aca..f96fb96b2678 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -37,7 +37,8 @@ static int soc_compr_open(struct snd_compr_stream *cstream) if (platform->driver->compr_ops && platform->driver->compr_ops->open) { ret = platform->driver->compr_ops->open(cstream); if (ret < 0) { - pr_err("compress asoc: can't open platform %s\n", platform->name); + pr_err("compress asoc: can't open platform %s\n", + platform->component.name); goto out; } } @@ -84,7 +85,8 @@ static int soc_compr_open_fe(struct snd_compr_stream *cstream) if (platform->driver->compr_ops && platform->driver->compr_ops->open) { ret = platform->driver->compr_ops->open(cstream); if (ret < 0) { - pr_err("compress asoc: can't open platform %s\n", platform->name); + pr_err("compress asoc: can't open platform %s\n", + platform->component.name); goto out; } } @@ -680,7 +682,7 @@ int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) ret = snd_compress_new(rtd->card->snd_card, num, direction, compr); if (ret < 0) { pr_err("compress asoc: can't create compress for codec %s\n", - codec->name); + codec->component.name); goto compr_err; } diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index ba822e927187..b8cc88a9f947 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -274,7 +274,7 @@ static void soc_init_codec_debugfs(struct snd_soc_codec *codec) { struct dentry *debugfs_card_root = codec->card->debugfs_card_root; - codec->debugfs_codec_root = debugfs_create_dir(codec->name, + codec->debugfs_codec_root = debugfs_create_dir(codec->component.name, debugfs_card_root); if (!codec->debugfs_codec_root) { dev_warn(codec->dev, @@ -306,8 +306,8 @@ static void soc_init_platform_debugfs(struct snd_soc_platform *platform) { struct dentry *debugfs_card_root = platform->card->debugfs_card_root; - platform->debugfs_platform_root = debugfs_create_dir(platform->name, - debugfs_card_root); + platform->debugfs_platform_root = debugfs_create_dir( + platform->component.name, debugfs_card_root); if (!platform->debugfs_platform_root) { dev_warn(platform->dev, "ASoC: Failed to create platform debugfs directory\n"); @@ -335,7 +335,7 @@ static ssize_t codec_list_read_file(struct file *file, char __user *user_buf, list_for_each_entry(codec, &codec_list, list) { len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", - codec->name); + codec->component.name); if (len >= 0) ret += len; if (ret > PAGE_SIZE) { @@ -406,7 +406,7 @@ static ssize_t platform_list_read_file(struct file *file, list_for_each_entry(platform, &platform_list, list) { len = snprintf(buf + ret, PAGE_SIZE - ret, "%s\n", - platform->name); + platform->component.name); if (len >= 0) ret += len; if (ret > PAGE_SIZE) { @@ -528,7 +528,7 @@ static int soc_ac97_dev_register(struct snd_soc_codec *codec) codec->ac97->dev.release = soc_ac97_device_release; dev_set_name(&codec->ac97->dev, "%d-%d:%s", - codec->card->snd_card->number, 0, codec->name); + codec->card->snd_card->number, 0, codec->component.name); err = device_register(&codec->ac97->dev); if (err < 0) { dev_err(codec->dev, "ASoC: Can't register ac97 bus\n"); @@ -857,7 +857,7 @@ static struct snd_soc_codec *soc_find_codec(const struct device_node *codec_of_n if (codec->dev->of_node != codec_of_node) continue; } else { - if (strcmp(codec->name, codec_name)) + if (strcmp(codec->component.name, codec_name)) continue; } @@ -945,7 +945,7 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num) dai_link->platform_of_node) continue; } else { - if (strcmp(platform->name, platform_name)) + if (strcmp(platform->component.name, platform_name)) continue; } @@ -1177,7 +1177,7 @@ static int soc_probe_codec(struct snd_soc_card *card, WARN(codec->dapm.idle_bias_off && codec->dapm.bias_level != SND_SOC_BIAS_OFF, "codec %s can not start from non-off bias with idle_bias_off==1\n", - codec->name); + codec->component.name); } if (driver->controls) @@ -1647,7 +1647,8 @@ static struct snd_soc_codec *soc_find_matching_codec(struct snd_soc_card *card, if (aux_dev->codec_of_node && (codec->dev->of_node != aux_dev->codec_of_node)) continue; - if (aux_dev->codec_name && strcmp(codec->name, aux_dev->codec_name)) + if (aux_dev->codec_name && + strcmp(codec->component.name, aux_dev->codec_name)) continue; return codec; } @@ -4131,11 +4132,6 @@ int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform, { int ret; - /* create platform component name */ - platform->name = fmt_single_name(dev, &platform->id); - if (platform->name == NULL) - return -ENOMEM; - platform->dev = dev; platform->driver = platform_drv; platform->dapm.dev = dev; @@ -4161,7 +4157,8 @@ int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform, list_add(&platform->list, &platform_list); mutex_unlock(&client_mutex); - dev_dbg(dev, "ASoC: Registered platform '%s'\n", platform->name); + dev_dbg(dev, "ASoC: Registered platform '%s'\n", + platform->component.name); return 0; } @@ -4205,8 +4202,7 @@ void snd_soc_remove_platform(struct snd_soc_platform *platform) mutex_unlock(&client_mutex); dev_dbg(platform->dev, "ASoC: Unregistered platform '%s'\n", - platform->name); - kfree(platform->name); + platform->component.name); } EXPORT_SYMBOL_GPL(snd_soc_remove_platform); @@ -4312,13 +4308,6 @@ int snd_soc_register_codec(struct device *dev, if (codec == NULL) return -ENOMEM; - /* create CODEC component name */ - codec->name = fmt_single_name(dev, &codec->id); - if (codec->name == NULL) { - ret = -ENOMEM; - goto fail_codec; - } - if (codec_drv->write) codec->component.write = snd_soc_codec_drv_write; if (codec_drv->read) @@ -4368,19 +4357,17 @@ int snd_soc_register_codec(struct device *dev, codec, dai_drv, num_dai, false); if (ret < 0) { dev_err(codec->dev, "ASoC: Failed to regster component: %d\n", ret); - goto fail_codec_name; + goto fail_codec; } - dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n", codec->name); + dev_dbg(codec->dev, "ASoC: Registered codec '%s'\n", + codec->component.name); return 0; -fail_codec_name: +fail_codec: mutex_lock(&client_mutex); list_del(&codec->list); mutex_unlock(&client_mutex); - - kfree(codec->name); -fail_codec: kfree(codec); return ret; } @@ -4408,10 +4395,10 @@ found: list_del(&codec->list); mutex_unlock(&client_mutex); - dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", codec->name); + dev_dbg(codec->dev, "ASoC: Unregistered codec '%s'\n", + codec->component.name); snd_soc_cache_exit(codec); - kfree(codec->name); kfree(codec); } EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 2f29b289a333..074e9ce136f8 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -3400,8 +3400,8 @@ void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card) source = cpu_dai->playback_widget; sink = codec_dai->playback_widget; dev_dbg(rtd->dev, "connected DAI link %s:%s -> %s:%s\n", - cpu_dai->codec->name, source->name, - codec_dai->platform->name, sink->name); + cpu_dai->component->name, source->name, + codec_dai->component->name, sink->name); snd_soc_dapm_add_path(&card->dapm, source, sink, NULL, NULL); @@ -3412,8 +3412,8 @@ void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card) source = codec_dai->capture_widget; sink = cpu_dai->capture_widget; dev_dbg(rtd->dev, "connected DAI link %s:%s -> %s:%s\n", - codec_dai->codec->name, source->name, - cpu_dai->platform->name, sink->name); + codec_dai->component->name, source->name, + cpu_dai->component->name, sink->name); snd_soc_dapm_add_path(&card->dapm, source, sink, NULL, NULL); diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 54d18f22a33e..9b78bb619bec 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -376,7 +376,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) ret = platform->driver->ops->open(substream); if (ret < 0) { dev_err(platform->dev, "ASoC: can't open platform" - " %s: %d\n", platform->name, ret); + " %s: %d\n", platform->component.name, ret); goto platform_err; } } @@ -707,7 +707,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, ret = platform->driver->ops->hw_params(substream, params); if (ret < 0) { dev_err(platform->dev, "ASoC: %s hw params failed: %d\n", - platform->name, ret); + platform->component.name, ret); goto platform_err; } } -- cgit v1.2.3-58-ga151 From 7df3788410e674423375b88e2d95c46e4015f5f5 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 16 Jun 2014 18:13:04 +0200 Subject: ASoC: Auto disconnect pins from all DAPM contexts Currently only pins in CODEC DAPM contexts are automatically marked as non-connected if the card has the fully_routed flag set. This makes sense since widgets which qualify for auto-disconnection are only found in CODEC DAPM contexts. But with componentisation this is going to change, so consider all widgets for auto-disconnection. Also it is probably faster to walk the widgets list only once rather than once for each CODEC. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- include/sound/soc-dapm.h | 2 +- sound/soc/soc-core.c | 3 +-- sound/soc/soc-dapm.c | 27 +++++++++++---------------- 3 files changed, 13 insertions(+), 19 deletions(-) (limited to 'include/sound') diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 6b59471cdf44..8db627cc2fbe 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h @@ -431,7 +431,7 @@ int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context *dapm, const char *pin); int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm, const char *pin); -void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec); +void snd_soc_dapm_auto_nc_pins(struct snd_soc_card *card); /* Mostly internal - should not normally be used */ void dapm_mark_io_dirty(struct snd_soc_dapm_context *dapm); diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 0944da66538d..bca8a7150a4a 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1928,8 +1928,7 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) } if (card->fully_routed) - list_for_each_entry(codec, &card->codec_dev_list, card_list) - snd_soc_dapm_auto_nc_codec_pins(codec); + snd_soc_dapm_auto_nc_pins(card); snd_soc_dapm_new_widgets(card); diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 074e9ce136f8..3ccbf9ba04b2 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -3763,36 +3763,31 @@ static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card, } /** - * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins - * @codec: The codec whose pins should be processed + * snd_soc_dapm_auto_nc_pins - call snd_soc_dapm_nc_pin for unused pins + * @card: The card whose pins should be processed * - * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec - * which are unused. Pins are used if they are connected externally to the - * codec, whether that be to some other device, or a loop-back connection to - * the codec itself. + * Automatically call snd_soc_dapm_nc_pin() for any external pins in the card + * which are unused. Pins are used if they are connected externally to a + * component, whether that be to some other device, or a loop-back connection to + * the component itself. */ -void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec) +void snd_soc_dapm_auto_nc_pins(struct snd_soc_card *card) { - struct snd_soc_card *card = codec->card; - struct snd_soc_dapm_context *dapm = &codec->dapm; struct snd_soc_dapm_widget *w; - dev_dbg(codec->dev, "ASoC: Auto NC: DAPMs: card:%p codec:%p\n", - &card->dapm, &codec->dapm); + dev_dbg(card->dev, "ASoC: Auto NC: DAPMs: card:%p\n", &card->dapm); list_for_each_entry(w, &card->widgets, list) { - if (w->dapm != dapm) - continue; switch (w->id) { case snd_soc_dapm_input: case snd_soc_dapm_output: case snd_soc_dapm_micbias: - dev_dbg(codec->dev, "ASoC: Auto NC: Checking widget %s\n", + dev_dbg(card->dev, "ASoC: Auto NC: Checking widget %s\n", w->name); if (!snd_soc_dapm_widget_in_card_paths(card, w)) { - dev_dbg(codec->dev, + dev_dbg(card->dev, "... Not in map; disabling\n"); - snd_soc_dapm_nc_pin(dapm, w->name); + snd_soc_dapm_nc_pin(w->dapm, w->name); } break; default: -- cgit v1.2.3-58-ga151 From 68f831c2724ab72c0088471b2ed1dc99e81948ef Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 16 Jun 2014 18:13:05 +0200 Subject: ASoC: Add a set_bias_level() callback to the DAPM context struct Currently the DAPM code directly looks at the CODEC driver struct to get a handle to the set_bias_level() callback. This patch adds a new set_bias_level() callback to the DAPM context struct. The DAPM code will use this new callback instead of the CODEC callback. For CODECs the new callback is set up to call the CODEC specific set_bias_level callback(). Not looking directly at the CODEC driver struct will allow non CODEC DAPM contexts to implement a set_bias_level() callback. This is also similar to how the seq_notifier() and stream_event() callbacks are currently handled. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- include/sound/soc-dapm.h | 2 ++ sound/soc/soc-core.c | 10 ++++++++++ sound/soc/soc-dapm.c | 11 +++-------- 3 files changed, 15 insertions(+), 8 deletions(-) (limited to 'include/sound') diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 8db627cc2fbe..3a5c4f969c04 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h @@ -601,6 +601,8 @@ struct snd_soc_dapm_context { struct list_head list; int (*stream_event)(struct snd_soc_dapm_context *dapm, int event); + int (*set_bias_level)(struct snd_soc_dapm_context *dapm, + enum snd_soc_bias_level level); #ifdef CONFIG_DEBUG_FS struct dentry *debugfs_dapm; diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index bca8a7150a4a..10e13c43bc54 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -4285,6 +4285,14 @@ static int snd_soc_codec_drv_read(struct snd_soc_component *component, return 0; } +static int snd_soc_codec_set_bias_level(struct snd_soc_dapm_context *dapm, + enum snd_soc_bias_level level) +{ + struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); + + return codec->driver->set_bias_level(codec, level); +} + /** * snd_soc_register_codec - Register a codec with the ASoC core * @@ -4322,6 +4330,8 @@ int snd_soc_register_codec(struct device *dev, codec->dapm.component = &codec->component; codec->dapm.seq_notifier = codec_drv->seq_notifier; codec->dapm.stream_event = codec_drv->stream_event; + if (codec_drv->set_bias_level) + codec->dapm.set_bias_level = snd_soc_codec_set_bias_level; codec->dev = dev; codec->driver = codec_drv; codec->component.val_bytes = codec_drv->reg_word_size; diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index fab1a8813abf..6c94a6b3fce7 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -427,15 +427,10 @@ static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm, if (ret != 0) goto out; - if (dapm->codec) { - if (dapm->codec->driver->set_bias_level) - ret = dapm->codec->driver->set_bias_level(dapm->codec, - level); - else - dapm->bias_level = level; - } else if (!card || dapm != &card->dapm) { + if (dapm->set_bias_level) + ret = dapm->set_bias_level(dapm, level); + else if (!card || dapm != &card->dapm) dapm->bias_level = level; - } if (ret != 0) goto out; -- cgit v1.2.3-58-ga151 From ce0fc93ae56e2ba50ff8c220d69e4e860e889320 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 16 Jun 2014 18:13:06 +0200 Subject: ASoC: Add DAPM support at the component level This patch adds full DAPM support at the component level. Previously there was only full DAPM support for CODECs and partial DAPM support (e.g. no Mixers nor MUXs) for platforms. Having DAPM support at the component level will allow all types of components to use DAPM and also help in consolidating the DAPM support between CODECs and platforms. Since the DAPM context is directly embedded into the snd_soc_codec and snd_soc_platform struct and the 'dapm' field is directly referenced in a lot of drivers moving the field just right now is not possible without causing code churn. The approach this patch takes is to add two new fields to the component struct. One field which is the pointer to the actual DAPM context used by the component and one DAPM context that will be used as the default if no other context was specified. For CODECs and platforms the pointer is initialized to point to the CODEC or platform DAPM context. All generic code when referencing a component's DAPM struct will go via the pointer. This will make it possible to eventually seamlessly move the DAPM context from snd_soc_codec and snd_soc_platform struct over once all direct references have been eliminated. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- include/sound/soc-dapm.h | 2 + include/sound/soc.h | 30 ++++++++++++++ sound/soc/soc-core.c | 19 ++++++--- sound/soc/soc-dapm.c | 100 ++++++++++++++++++++++++++++++----------------- 4 files changed, 110 insertions(+), 41 deletions(-) (limited to 'include/sound') diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index 3a5c4f969c04..e292683ee694 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h @@ -441,6 +441,8 @@ int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream, struct snd_soc_dapm_widget_list **list); struct snd_soc_codec *snd_soc_dapm_kcontrol_codec(struct snd_kcontrol *kcontrol); +struct snd_soc_dapm_context *snd_soc_dapm_kcontrol_dapm( + struct snd_kcontrol *kcontrol); /* dapm widget types */ enum snd_soc_dapm_type { diff --git a/include/sound/soc.h b/include/sound/soc.h index f64bf9452466..a21dfecba56b 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -706,6 +706,10 @@ struct snd_soc_component { int val_bytes; struct mutex io_mutex; + + /* Don't use these, use snd_soc_component_get_dapm() */ + struct snd_soc_dapm_context dapm; + struct snd_soc_dapm_context *dapm_ptr; }; /* SoC Audio Codec device */ @@ -1160,6 +1164,21 @@ static inline struct snd_soc_platform *snd_soc_component_to_platform( return container_of(component, struct snd_soc_platform, component); } +/** + * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is + * embedded in + * @dapm: The DAPM context to cast to the component + * + * This function must only be used on DAPM contexts that are known to be part of + * a component (e.g. in a component driver). Otherwise the behavior is + * undefined. + */ +static inline struct snd_soc_component *snd_soc_dapm_to_component( + struct snd_soc_dapm_context *dapm) +{ + return container_of(dapm, struct snd_soc_component, dapm); +} + /** * snd_soc_dapm_to_codec() - Casts a DAPM context to the CODEC it is embedded in * @dapm: The DAPM context to cast to the CODEC @@ -1187,6 +1206,17 @@ static inline struct snd_soc_platform *snd_soc_dapm_to_platform( return container_of(dapm, struct snd_soc_platform, dapm); } +/** + * snd_soc_component_get_dapm() - Returns the DAPM context associated with a + * component + * @component: The component for which to get the DAPM context + */ +static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm( + struct snd_soc_component *component) +{ + return component->dapm_ptr; +} + /* codec IO */ unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg); int snd_soc_write(struct snd_soc_codec *codec, unsigned int reg, diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 10e13c43bc54..f519a9f7571c 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3997,6 +3997,8 @@ err: static int snd_soc_component_initialize(struct snd_soc_component *component, const struct snd_soc_component_driver *driver, struct device *dev) { + struct snd_soc_dapm_context *dapm; + component->name = fmt_single_name(dev, &component->id); if (!component->name) { dev_err(dev, "ASoC: Failed to allocate name\n"); @@ -4006,6 +4008,14 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, component->dev = dev; component->driver = driver; + if (!component->dapm_ptr) + component->dapm_ptr = &component->dapm; + + dapm = component->dapm_ptr; + dapm->dev = dev; + dapm->component = component; + dapm->bias_level = SND_SOC_BIAS_OFF; + INIT_LIST_HEAD(&component->dai_list); mutex_init(&component->io_mutex); @@ -4131,6 +4141,8 @@ int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform, { int ret; + platform->component.dapm_ptr = &platform->dapm; + ret = snd_soc_component_initialize(&platform->component, &platform_drv->component_driver, dev); if (ret) @@ -4138,9 +4150,7 @@ int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform, platform->dev = dev; platform->driver = platform_drv; - platform->dapm.dev = dev; platform->dapm.platform = platform; - platform->dapm.component = &platform->component; platform->dapm.stream_event = platform_drv->stream_event; if (platform_drv->write) platform->component.write = snd_soc_platform_drv_write; @@ -4314,6 +4324,8 @@ int snd_soc_register_codec(struct device *dev, if (codec == NULL) return -ENOMEM; + codec->component.dapm_ptr = &codec->dapm; + ret = snd_soc_component_initialize(&codec->component, &codec_drv->component_driver, dev); if (ret) @@ -4324,10 +4336,7 @@ int snd_soc_register_codec(struct device *dev, if (codec_drv->read) codec->component.read = snd_soc_codec_drv_read; codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time; - codec->dapm.bias_level = SND_SOC_BIAS_OFF; - codec->dapm.dev = dev; codec->dapm.codec = codec; - codec->dapm.component = &codec->component; codec->dapm.seq_notifier = codec_drv->seq_notifier; codec->dapm.stream_event = codec_drv->stream_event; if (codec_drv->set_bias_level) diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 6c94a6b3fce7..4702b926a6a0 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -349,13 +349,28 @@ static bool dapm_kcontrol_set_value(const struct snd_kcontrol *kcontrol, return true; } +/** + * snd_soc_dapm_kcontrol_dapm() - Returns the dapm context associated to a + * kcontrol + * @kcontrol: The kcontrol + * + * Note: This function must only be used on kcontrols that are known to have + * been registered for a CODEC. Otherwise the behaviour is undefined. + */ +struct snd_soc_dapm_context *snd_soc_dapm_kcontrol_dapm( + struct snd_kcontrol *kcontrol) +{ + return dapm_kcontrol_get_wlist(kcontrol)->widgets[0]->dapm; +} +EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_dapm); + /** * snd_soc_dapm_kcontrol_codec() - Returns the codec associated to a kcontrol * @kcontrol: The kcontrol */ struct snd_soc_codec *snd_soc_dapm_kcontrol_codec(struct snd_kcontrol *kcontrol) { - return dapm_kcontrol_get_wlist(kcontrol)->widgets[0]->codec; + return snd_soc_dapm_to_codec(snd_soc_dapm_kcontrol_dapm(kcontrol)); } EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_codec); @@ -382,23 +397,31 @@ static const char *soc_dapm_prefix(struct snd_soc_dapm_context *dapm) return dapm->component->name_prefix; } -static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg, +static int soc_dapm_read(struct snd_soc_dapm_context *dapm, int reg, unsigned int *value) { - if (!w->dapm->component) + if (!dapm->component) return -EIO; - return snd_soc_component_read(w->dapm->component, reg, value); + return snd_soc_component_read(dapm->component, reg, value); } -static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, +static int soc_dapm_update_bits(struct snd_soc_dapm_context *dapm, int reg, unsigned int mask, unsigned int value) { - if (!w->dapm->component) + if (!dapm->component) return -EIO; - return snd_soc_component_update_bits_async(w->dapm->component, reg, + return snd_soc_component_update_bits_async(dapm->component, reg, mask, value); } +static int soc_dapm_test_bits(struct snd_soc_dapm_context *dapm, + int reg, unsigned int mask, unsigned int value) +{ + if (!dapm->component) + return -EIO; + return snd_soc_component_test_bits(dapm->component, reg, mask, value); +} + static void soc_dapm_async_complete(struct snd_soc_dapm_context *dapm) { if (dapm->component) @@ -454,7 +477,7 @@ static int dapm_connect_mux(struct snd_soc_dapm_context *dapm, int i; if (e->reg != SND_SOC_NOPM) { - soc_widget_read(dest, e->reg, &val); + soc_dapm_read(dapm, e->reg, &val); val = (val >> e->shift_l) & e->mask; item = snd_soc_enum_val_to_item(e, val); } else { @@ -498,7 +521,7 @@ static void dapm_set_mixer_path_status(struct snd_soc_dapm_widget *w, unsigned int val; if (reg != SND_SOC_NOPM) { - soc_widget_read(w, reg, &val); + soc_dapm_read(w->dapm, reg, &val); val = (val >> shift) & mask; if (invert) val = max - val; @@ -1306,16 +1329,18 @@ static void dapm_seq_check_event(struct snd_soc_card *card, static void dapm_seq_run_coalesced(struct snd_soc_card *card, struct list_head *pending) { + struct snd_soc_dapm_context *dapm; struct snd_soc_dapm_widget *w; int reg; unsigned int value = 0; unsigned int mask = 0; - reg = list_first_entry(pending, struct snd_soc_dapm_widget, - power_list)->reg; + w = list_first_entry(pending, struct snd_soc_dapm_widget, power_list); + reg = w->reg; + dapm = w->dapm; list_for_each_entry(w, pending, power_list) { - WARN_ON(reg != w->reg); + WARN_ON(reg != w->reg || dapm != w->dapm); w->power = w->new_power; mask |= w->mask << w->shift; @@ -1324,7 +1349,7 @@ static void dapm_seq_run_coalesced(struct snd_soc_card *card, else value |= w->off_val << w->shift; - pop_dbg(w->dapm->dev, card->pop_time, + pop_dbg(dapm->dev, card->pop_time, "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n", w->name, reg, value, mask); @@ -1337,14 +1362,12 @@ static void dapm_seq_run_coalesced(struct snd_soc_card *card, /* Any widget will do, they should all be updating the * same register. */ - w = list_first_entry(pending, struct snd_soc_dapm_widget, - power_list); - pop_dbg(w->dapm->dev, card->pop_time, + pop_dbg(dapm->dev, card->pop_time, "pop test : Applying 0x%x/0x%x to %x in %dms\n", value, mask, reg, card->pop_time); pop_wait(card->pop_time); - soc_widget_update_bits(w, reg, mask, value); + soc_dapm_update_bits(dapm, reg, mask, value); } list_for_each_entry(w, pending, power_list) { @@ -1490,7 +1513,8 @@ static void dapm_widget_update(struct snd_soc_card *card) if (!w) return; - ret = soc_widget_update_bits(w, update->reg, update->mask, update->val); + ret = soc_dapm_update_bits(w->dapm, update->reg, update->mask, + update->val); if (ret < 0) dev_err(w->dapm->dev, "ASoC: %s DAPM update failed: %d\n", w->name, ret); @@ -2672,7 +2696,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_card *card) /* Read the initial power state from the device */ if (w->reg >= 0) { - soc_widget_read(w, w->reg, &val); + soc_dapm_read(w->dapm, w->reg, &val); val = val >> w->shift; val &= w->mask; if (val == w->on_val) @@ -2703,8 +2727,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); - struct snd_soc_card *card = codec->card; + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); + struct snd_soc_card *card = dapm->card; struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; int reg = mc->reg; @@ -2713,17 +2737,20 @@ int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, unsigned int mask = (1 << fls(max)) - 1; unsigned int invert = mc->invert; unsigned int val; + int ret = 0; if (snd_soc_volsw_is_stereo(mc)) - dev_warn(codec->dapm.dev, + dev_warn(dapm->dev, "ASoC: Control '%s' is stereo, which is not supported\n", kcontrol->id.name); mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); - if (dapm_kcontrol_is_powered(kcontrol) && reg != SND_SOC_NOPM) - val = (snd_soc_read(codec, reg) >> shift) & mask; - else + if (dapm_kcontrol_is_powered(kcontrol) && reg != SND_SOC_NOPM) { + ret = soc_dapm_read(dapm, reg, &val); + val = (val >> shift) & mask; + } else { val = dapm_kcontrol_get_value(kcontrol); + } mutex_unlock(&card->dapm_mutex); if (invert) @@ -2731,7 +2758,7 @@ int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, else ucontrol->value.integer.value[0] = val; - return 0; + return ret; } EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw); @@ -2747,8 +2774,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw); int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); - struct snd_soc_card *card = codec->card; + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); + struct snd_soc_card *card = dapm->card; struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; int reg = mc->reg; @@ -2762,7 +2789,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, int ret = 0; if (snd_soc_volsw_is_stereo(mc)) - dev_warn(codec->dapm.dev, + dev_warn(dapm->dev, "ASoC: Control '%s' is stereo, which is not supported\n", kcontrol->id.name); @@ -2780,7 +2807,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, mask = mask << shift; val = val << shift; - reg_change = snd_soc_test_bits(codec, reg, mask, val); + reg_change = soc_dapm_test_bits(dapm, reg, mask, val); } if (change || reg_change) { @@ -2819,12 +2846,13 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; unsigned int reg_val, val; + int ret = 0; if (e->reg != SND_SOC_NOPM) - reg_val = snd_soc_read(codec, e->reg); + ret = soc_dapm_read(dapm, e->reg, ®_val); else reg_val = dapm_kcontrol_get_value(kcontrol); @@ -2836,7 +2864,7 @@ int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, ucontrol->value.enumerated.item[1] = val; } - return 0; + return ret; } EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double); @@ -2852,8 +2880,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double); int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { - struct snd_soc_codec *codec = snd_soc_dapm_kcontrol_codec(kcontrol); - struct snd_soc_card *card = codec->card; + struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); + struct snd_soc_card *card = dapm->card; struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; unsigned int *item = ucontrol->value.enumerated.item; unsigned int val, change; @@ -2876,7 +2904,7 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); if (e->reg != SND_SOC_NOPM) - change = snd_soc_test_bits(codec, e->reg, mask, val); + change = soc_dapm_test_bits(dapm, e->reg, mask, val); else change = dapm_kcontrol_set_value(kcontrol, val); -- cgit v1.2.3-58-ga151 From bc9af9fa9b89cb74eed020066d882abf238fad69 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 16 Jun 2014 18:13:07 +0200 Subject: ASoC: Use component DAPM context for platforms The snd_soc_platform dapm field is not accessed outside of the ASoC core. Switch it over to using the snd_soc_component DAPM context. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- include/sound/soc.h | 4 +--- sound/soc/soc-core.c | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 16 deletions(-) (limited to 'include/sound') diff --git a/include/sound/soc.h b/include/sound/soc.h index a21dfecba56b..84ebc079c92f 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -862,8 +862,6 @@ struct snd_soc_platform { struct snd_soc_component component; - struct snd_soc_dapm_context dapm; - #ifdef CONFIG_DEBUG_FS struct dentry *debugfs_platform_root; #endif @@ -1203,7 +1201,7 @@ static inline struct snd_soc_codec *snd_soc_dapm_to_codec( static inline struct snd_soc_platform *snd_soc_dapm_to_platform( struct snd_soc_dapm_context *dapm) { - return container_of(dapm, struct snd_soc_platform, dapm); + return snd_soc_component_to_platform(snd_soc_dapm_to_component(dapm)); } /** diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index f519a9f7571c..711e99c43be3 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -314,7 +314,7 @@ static void soc_init_platform_debugfs(struct snd_soc_platform *platform) return; } - snd_soc_dapm_debugfs_init(&platform->dapm, + snd_soc_dapm_debugfs_init(&platform->component.dapm, platform->debugfs_platform_root); } @@ -974,7 +974,7 @@ static int soc_remove_platform(struct snd_soc_platform *platform) } /* Make sure all DAPM widgets are freed */ - snd_soc_dapm_free(&platform->dapm); + snd_soc_dapm_free(&platform->component.dapm); soc_cleanup_platform_debugfs(platform); platform->probed = 0; @@ -1210,7 +1210,7 @@ static int soc_probe_platform(struct snd_soc_card *card, struct snd_soc_dai *dai; platform->card = card; - platform->dapm.card = card; + platform->component.dapm.card = card; if (!try_module_get(platform->dev->driver->owner)) return -ENODEV; @@ -1218,7 +1218,7 @@ static int soc_probe_platform(struct snd_soc_card *card, soc_init_platform_debugfs(platform); if (driver->dapm_widgets) - snd_soc_dapm_new_controls(&platform->dapm, + snd_soc_dapm_new_controls(&platform->component.dapm, driver->dapm_widgets, driver->num_dapm_widgets); /* Create DAPM widgets for each DAI stream */ @@ -1226,10 +1226,11 @@ static int soc_probe_platform(struct snd_soc_card *card, if (component->dev != platform->dev) continue; list_for_each_entry(dai, &component->dai_list, list) - snd_soc_dapm_new_dai_widgets(&platform->dapm, dai); + snd_soc_dapm_new_dai_widgets(&platform->component.dapm, + dai); } - platform->dapm.idle_bias_off = 1; + platform->component.dapm.idle_bias_off = 1; if (driver->probe) { ret = driver->probe(platform); @@ -1244,13 +1245,13 @@ static int soc_probe_platform(struct snd_soc_card *card, snd_soc_add_platform_controls(platform, driver->controls, driver->num_controls); if (driver->dapm_routes) - snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes, - driver->num_dapm_routes); + snd_soc_dapm_add_routes(&platform->component.dapm, + driver->dapm_routes, driver->num_dapm_routes); /* mark platform as probed and add to card platform list */ platform->probed = 1; list_add(&platform->card_list, &card->platform_dev_list); - list_add(&platform->dapm.list, &card->dapm_list); + list_add(&platform->component.dapm.list, &card->dapm_list); return 0; @@ -4141,8 +4142,6 @@ int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform, { int ret; - platform->component.dapm_ptr = &platform->dapm; - ret = snd_soc_component_initialize(&platform->component, &platform_drv->component_driver, dev); if (ret) @@ -4150,8 +4149,8 @@ int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform, platform->dev = dev; platform->driver = platform_drv; - platform->dapm.platform = platform; - platform->dapm.stream_event = platform_drv->stream_event; + platform->component.dapm.platform = platform; + platform->component.dapm.stream_event = platform_drv->stream_event; if (platform_drv->write) platform->component.write = snd_soc_platform_drv_write; if (platform_drv->read) -- cgit v1.2.3-58-ga151 From 14e8bdebfbc1d5c8804b3520233b2d4e516056bc Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 16 Jun 2014 18:13:08 +0200 Subject: ASoC: Add component level stream_event() and seq_notifier() support This patch adds stream_event() and seq_notifier() callbacks similar to those found in the snd_soc_codec_driver and snd_soc_platform driver struct to the snd_soc_component_driver struct. This is meant to unify the handling of these callbacks across different types of components and will eventually allow their removal from the CODEC and platfrom driver structs. The new callbacks are slightly different from the old ones in that they take a snd_soc_component as a parameter rather than a snd_soc_dapm_context. This was done since otherwise casting from the DAPM context to the component would typically be the first thing to do in the callback. And the interface becomes slightly cleaner by passing a snd_soc_component to all callbacks in the snd_soc_component_driver struct. The patch also already removes the stream_event() callback from the snd_soc_codec_driver and snd_soc_platform_driver structs as it is currently unused. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- include/sound/soc.h | 9 +++------ sound/soc/soc-core.c | 25 ++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 9 deletions(-) (limited to 'include/sound') diff --git a/include/sound/soc.h b/include/sound/soc.h index 84ebc079c92f..9a5b4f6fe847 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -677,6 +677,9 @@ struct snd_soc_component_driver { int (*of_xlate_dai_name)(struct snd_soc_component *component, struct of_phandle_args *args, const char **dai_name); + void (*seq_notifier)(struct snd_soc_component *, enum snd_soc_dapm_type, + int subseq); + int (*stream_event)(struct snd_soc_component *, int event); }; struct snd_soc_component { @@ -792,9 +795,6 @@ struct snd_soc_codec_driver { void (*seq_notifier)(struct snd_soc_dapm_context *, enum snd_soc_dapm_type, int); - /* codec stream completion event */ - int (*stream_event)(struct snd_soc_dapm_context *dapm, int event); - bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */ /* probe ordering - for components with runtime dependencies */ @@ -836,9 +836,6 @@ struct snd_soc_platform_driver { /* platform stream compress ops */ const struct snd_compr_ops *compr_ops; - /* platform stream completion event */ - int (*stream_event)(struct snd_soc_dapm_context *dapm, int event); - /* probe ordering - for components with runtime dependencies */ int probe_order; int remove_order; diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 711e99c43be3..5fe732fdfd59 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -3995,6 +3995,22 @@ err: return ret; } +static void snd_soc_component_seq_notifier(struct snd_soc_dapm_context *dapm, + enum snd_soc_dapm_type type, int subseq) +{ + struct snd_soc_component *component = dapm->component; + + component->driver->seq_notifier(component, type, subseq); +} + +static int snd_soc_component_stream_event(struct snd_soc_dapm_context *dapm, + int event) +{ + struct snd_soc_component *component = dapm->component; + + return component->driver->stream_event(component, event); +} + static int snd_soc_component_initialize(struct snd_soc_component *component, const struct snd_soc_component_driver *driver, struct device *dev) { @@ -4016,6 +4032,10 @@ static int snd_soc_component_initialize(struct snd_soc_component *component, dapm->dev = dev; dapm->component = component; dapm->bias_level = SND_SOC_BIAS_OFF; + if (driver->seq_notifier) + dapm->seq_notifier = snd_soc_component_seq_notifier; + if (driver->stream_event) + dapm->stream_event = snd_soc_component_stream_event; INIT_LIST_HEAD(&component->dai_list); mutex_init(&component->io_mutex); @@ -4150,7 +4170,6 @@ int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform, platform->dev = dev; platform->driver = platform_drv; platform->component.dapm.platform = platform; - platform->component.dapm.stream_event = platform_drv->stream_event; if (platform_drv->write) platform->component.write = snd_soc_platform_drv_write; if (platform_drv->read) @@ -4336,8 +4355,8 @@ int snd_soc_register_codec(struct device *dev, codec->component.read = snd_soc_codec_drv_read; codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time; codec->dapm.codec = codec; - codec->dapm.seq_notifier = codec_drv->seq_notifier; - codec->dapm.stream_event = codec_drv->stream_event; + if (codec_drv->seq_notifier) + codec->dapm.seq_notifier = codec_drv->seq_notifier; if (codec_drv->set_bias_level) codec->dapm.set_bias_level = snd_soc_codec_set_bias_level; codec->dev = dev; -- cgit v1.2.3-58-ga151 From 9420d97b3f8672478696ae9c3e33051243e1f4a0 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 16 Jun 2014 18:13:10 +0200 Subject: ASoC: dapm: Remove DAI DAPM context The DAI DAPM context was added in commit be09ad90 ("ASoC: core: Add platform DAI widget mapping") and the only user was removed again in commit ae10e7e8f ("ASoC: core: Only add platform DAI widgets once."). Now that we have a per component DAPM context it is unlikely that we'll need the DAI DAPM context again. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- include/sound/soc-dai.h | 1 - sound/soc/soc-core.c | 12 +----------- 2 files changed, 1 insertion(+), 12 deletions(-) (limited to 'include/sound') diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h index 688f2ba8009f..031be2ab75d0 100644 --- a/include/sound/soc-dai.h +++ b/include/sound/soc-dai.h @@ -257,7 +257,6 @@ struct snd_soc_dai { struct snd_soc_dapm_widget *playback_widget; struct snd_soc_dapm_widget *capture_widget; - struct snd_soc_dapm_context dapm; /* DAI DMA data */ void *playback_dma_data; diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 5fe732fdfd59..995a4b7f87eb 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1048,11 +1048,8 @@ static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order) cpu_dai->name, err); } cpu_dai->probed = 0; - - if (!cpu_dai->codec) { - snd_soc_dapm_free(&cpu_dai->dapm); + if (!cpu_dai->codec) module_put(cpu_dai->dev->driver->owner); - } } } @@ -1510,11 +1507,8 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) if (!cpu_dai->probed && cpu_dai->driver->probe_order == order) { if (!cpu_dai->codec) { - cpu_dai->dapm.card = card; if (!try_module_get(cpu_dai->dev->driver->owner)) return -ENODEV; - - list_add(&cpu_dai->dapm.list, &card->dapm_list); } if (cpu_dai->driver->probe) { @@ -3975,13 +3969,9 @@ static int snd_soc_register_dais(struct snd_soc_component *component, dai->component = component; dai->dev = dev; dai->driver = &dai_drv[i]; - dai->dapm.dev = dev; if (!dai->driver->ops) dai->driver->ops = &null_dai_ops; - if (!dai->codec) - dai->dapm.idle_bias_off = 1; - list_add(&dai->list, &component->dai_list); dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name); -- cgit v1.2.3-58-ga151 From 88a8fe3df65fa0229b04f1c03411062230091cdd Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Mon, 16 Jun 2014 18:13:11 +0200 Subject: ASoC: dapm: Remove platform field from widget and dapm context struct The platform field in the snd_soc_dapm_widget and snd_soc_dapm_context structs is now unused can be removed. New code that wants to get the platform for a widget or dapm context should use snd_soc_dapm_to_platform(w->dapm) or snd_soc_dapm_to_platform(dapm). Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- include/sound/soc-dapm.h | 2 -- sound/soc/soc-core.c | 1 - sound/soc/soc-dapm.c | 1 - 3 files changed, 4 deletions(-) (limited to 'include/sound') diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h index e292683ee694..aac04ff84eea 100644 --- a/include/sound/soc-dapm.h +++ b/include/sound/soc-dapm.h @@ -526,7 +526,6 @@ struct snd_soc_dapm_widget { const char *name; /* widget name */ const char *sname; /* stream name */ struct snd_soc_codec *codec; - struct snd_soc_platform *platform; struct list_head list; struct snd_soc_dapm_context *dapm; @@ -595,7 +594,6 @@ struct snd_soc_dapm_context { struct device *dev; /* from parent - for debug */ struct snd_soc_component *component; /* parent component */ struct snd_soc_codec *codec; /* parent codec */ - struct snd_soc_platform *platform; /* parent platform */ struct snd_soc_card *card; /* parent card */ /* used during DAPM updates */ diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 995a4b7f87eb..19c1e9588e05 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -4159,7 +4159,6 @@ int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform, platform->dev = dev; platform->driver = platform_drv; - platform->component.dapm.platform = platform; if (platform_drv->write) platform->component.write = snd_soc_platform_drv_write; if (platform_drv->read) diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 4702b926a6a0..4bf08cffd1f1 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -3097,7 +3097,6 @@ snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, w->dapm = dapm; w->codec = dapm->codec; - w->platform = dapm->platform; INIT_LIST_HEAD(&w->sources); INIT_LIST_HEAD(&w->sinks); INIT_LIST_HEAD(&w->list); -- cgit v1.2.3-58-ga151 From 88bd870f02dff5c9445286e185f21873f25a977f Mon Sep 17 00:00:00 2001 From: Benoit Cousson Date: Tue, 8 Jul 2014 23:19:34 +0200 Subject: ASoC: core: Add initial support for DAI multicodec DAI link assumes a one to one mapping between CPU DAI and CODEC. In some cases, the same CPU DAI can be connected to several codecs. This is the case for example, if you connect two mono codecs to the same I2S link in order to have a stereo card. The current ASoC implementation does not allow such setup. Add support for DAI links composed of a single CPU DAI and multiple CODECs. Sound cards have to pass the CODECs array in the corresponding DAI link through a new 'snd_soc_dai_link_component' struct. Each CODEC in this array is described in the same manner single CODEC DAIs are (either DT/OF node or codec_name). Multi-codec links are not supported in the case of CODEC to CODEC links. Just print a warning if it happens. Based on an original code done by Misael. Signed-off-by: Benoit Cousson Signed-off-by: Misael Lopez Cruz Signed-off-by: Fabien Parent Tested-by: Lars-Peter Clausen Reviewed-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- include/sound/soc-dai.h | 4 + include/sound/soc.h | 13 +++ sound/soc/soc-core.c | 293 +++++++++++++++++++++++++++++++++--------------- 3 files changed, 220 insertions(+), 90 deletions(-) (limited to 'include/sound') diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h index 031be2ab75d0..e8b3080d196a 100644 --- a/include/sound/soc-dai.h +++ b/include/sound/soc-dai.h @@ -272,6 +272,10 @@ struct snd_soc_dai { struct snd_soc_codec *codec; struct snd_soc_component *component; + /* CODEC TDM slot masks and params (for fixup) */ + unsigned int tx_mask; + unsigned int rx_mask; + struct snd_soc_card *card; struct list_head list; diff --git a/include/sound/soc.h b/include/sound/soc.h index 9a5b4f6fe847..f2142cf3f243 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -846,6 +846,12 @@ struct snd_soc_platform_driver { int (*bespoke_trigger)(struct snd_pcm_substream *, int); }; +struct snd_soc_dai_link_component { + const char *name; + const struct device_node *of_node; + const char *dai_name; +}; + struct snd_soc_platform { struct device *dev; const struct snd_soc_platform_driver *driver; @@ -891,6 +897,10 @@ struct snd_soc_dai_link { const struct device_node *codec_of_node; /* You MUST specify the DAI name within the codec */ const char *codec_dai_name; + + struct snd_soc_dai_link_component *codecs; + unsigned int num_codecs; + /* * You MAY specify the link's platform/PCM/DMA driver, either by * device name, or by DT/OF node, but not both. Some forms of link @@ -1089,6 +1099,9 @@ struct snd_soc_pcm_runtime { struct snd_soc_dai *codec_dai; struct snd_soc_dai *cpu_dai; + struct snd_soc_dai **codec_dais; + unsigned int num_codecs; + struct delayed_work delayed_work; #ifdef CONFIG_DEBUG_FS struct dentry *debugfs_dpcm_root; diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index c32d8399e770..6e47610f73a0 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -576,7 +576,7 @@ int snd_soc_suspend(struct device *dev) { struct snd_soc_card *card = dev_get_drvdata(dev); struct snd_soc_codec *codec; - int i; + int i, j; /* If the initialization of this soc device failed, there is no codec * associated with it. Just bail out in this case. @@ -596,14 +596,17 @@ int snd_soc_suspend(struct device *dev) /* mute any active DACs */ for (i = 0; i < card->num_rtd; i++) { - struct snd_soc_dai *dai = card->rtd[i].codec_dai; - struct snd_soc_dai_driver *drv = dai->driver; if (card->rtd[i].dai_link->ignore_suspend) continue; - if (drv->ops->digital_mute && dai->playback_active) - drv->ops->digital_mute(dai, 1); + for (j = 0; j < card->rtd[i].num_codecs; j++) { + struct snd_soc_dai *dai = card->rtd[i].codec_dais[j]; + struct snd_soc_dai_driver *drv = dai->driver; + + if (drv->ops->digital_mute && dai->playback_active) + drv->ops->digital_mute(dai, 1); + } } /* suspend all pcms */ @@ -634,8 +637,12 @@ int snd_soc_suspend(struct device *dev) /* close any waiting streams and save state */ for (i = 0; i < card->num_rtd; i++) { + struct snd_soc_dai **codec_dais = card->rtd[i].codec_dais; flush_delayed_work(&card->rtd[i].delayed_work); - card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level; + for (j = 0; j < card->rtd[i].num_codecs; j++) { + codec_dais[j]->codec->dapm.suspend_bias_level = + codec_dais[j]->codec->dapm.bias_level; + } } for (i = 0; i < card->num_rtd; i++) { @@ -719,7 +726,7 @@ static void soc_resume_deferred(struct work_struct *work) struct snd_soc_card *card = container_of(work, struct snd_soc_card, deferred_resume_work); struct snd_soc_codec *codec; - int i; + int i, j; /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, * so userspace apps are blocked from touching us @@ -780,14 +787,17 @@ static void soc_resume_deferred(struct work_struct *work) /* unmute any active DACs */ for (i = 0; i < card->num_rtd; i++) { - struct snd_soc_dai *dai = card->rtd[i].codec_dai; - struct snd_soc_dai_driver *drv = dai->driver; if (card->rtd[i].dai_link->ignore_suspend) continue; - if (drv->ops->digital_mute && dai->playback_active) - drv->ops->digital_mute(dai, 0); + for (j = 0; j < card->rtd[i].num_codecs; j++) { + struct snd_soc_dai *dai = card->rtd[i].codec_dais[j]; + struct snd_soc_dai_driver *drv = dai->driver; + + if (drv->ops->digital_mute && dai->playback_active) + drv->ops->digital_mute(dai, 0); + } } for (i = 0; i < card->num_rtd; i++) { @@ -832,12 +842,19 @@ int snd_soc_resume(struct device *dev) /* activate pins from sleep state */ for (i = 0; i < card->num_rtd; i++) { - struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; - struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai; + struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; + struct snd_soc_dai **codec_dais = rtd->codec_dais; + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + int j; + if (cpu_dai->active) pinctrl_pm_select_default_state(cpu_dai->dev); - if (codec_dai->active) - pinctrl_pm_select_default_state(codec_dai->dev); + + for (j = 0; j < rtd->num_codecs; j++) { + struct snd_soc_dai *codec_dai = codec_dais[j]; + if (codec_dai->active) + pinctrl_pm_select_default_state(codec_dai->dev); + } } /* AC97 devices might have other drivers hanging off them so @@ -869,8 +886,9 @@ EXPORT_SYMBOL_GPL(snd_soc_resume); static const struct snd_soc_dai_ops null_dai_ops = { }; -static struct snd_soc_codec *soc_find_codec(const struct device_node *codec_of_node, - const char *codec_name) +static struct snd_soc_codec *soc_find_codec( + const struct device_node *codec_of_node, + const char *codec_name) { struct snd_soc_codec *codec; @@ -908,9 +926,12 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num) struct snd_soc_dai_link *dai_link = &card->dai_link[num]; struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; struct snd_soc_component *component; + struct snd_soc_dai_link_component *codecs = dai_link->codecs; + struct snd_soc_dai **codec_dais = rtd->codec_dais; struct snd_soc_platform *platform; struct snd_soc_dai *cpu_dai; const char *platform_name; + int i; dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num); @@ -937,24 +958,30 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num) return -EPROBE_DEFER; } - /* Find CODEC from registered list */ - rtd->codec = soc_find_codec(dai_link->codec_of_node, - dai_link->codec_name); - if (!rtd->codec) { - dev_err(card->dev, "ASoC: CODEC %s not registered\n", - dai_link->codec_name); - return -EPROBE_DEFER; - } + rtd->num_codecs = dai_link->num_codecs; - /* Find CODEC DAI from registered list */ - rtd->codec_dai = soc_find_codec_dai(rtd->codec, - dai_link->codec_dai_name); - if (!rtd->codec_dai) { - dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n", - dai_link->codec_dai_name); - return -EPROBE_DEFER; + /* Find CODEC from registered CODECs */ + for (i = 0; i < rtd->num_codecs; i++) { + struct snd_soc_codec *codec; + codec = soc_find_codec(codecs[i].of_node, codecs[i].name); + if (!codec) { + dev_err(card->dev, "ASoC: CODEC %s not registered\n", + codecs[i].name); + return -EPROBE_DEFER; + } + + codec_dais[i] = soc_find_codec_dai(codec, codecs[i].dai_name); + if (!codec_dais[i]) { + dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n", + codecs[i].dai_name); + return -EPROBE_DEFER; + } } + /* Single codec links expect codec and codec_dai in runtime data */ + rtd->codec_dai = codec_dais[0]; + rtd->codec = rtd->codec_dai->codec; + /* if there's no platform we match on the empty platform */ platform_name = dai_link->platform_name; if (!platform_name && !dai_link->platform_of_node) @@ -1045,8 +1072,8 @@ static void soc_remove_codec_dai(struct snd_soc_dai *codec_dai, int order) static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order) { struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; - struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai; - int err; + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + int i, err; /* unregister the rtd device */ if (rtd->dev_registered) { @@ -1057,7 +1084,8 @@ static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order) } /* remove the CODEC DAI */ - soc_remove_codec_dai(codec_dai, order); + for (i = 0; i < rtd->num_codecs; i++) + soc_remove_codec_dai(rtd->codec_dais[i], order); /* remove the cpu_dai */ if (cpu_dai && cpu_dai->probed && @@ -1080,9 +1108,9 @@ static void soc_remove_link_components(struct snd_soc_card *card, int num, { struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; struct snd_soc_dai *cpu_dai = rtd->cpu_dai; - struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_platform *platform = rtd->platform; struct snd_soc_codec *codec; + int i; /* remove the platform */ if (platform && platform->probed && @@ -1091,8 +1119,8 @@ static void soc_remove_link_components(struct snd_soc_card *card, int num, } /* remove the CODEC-side CODEC */ - if (codec_dai) { - codec = codec_dai->codec; + for (i = 0; i < rtd->num_codecs; i++) { + codec = rtd->codec_dais[i]->codec; if (codec && codec->probed && codec->driver->remove_order == order) soc_remove_codec(codec); @@ -1335,9 +1363,8 @@ static int soc_probe_link_components(struct snd_soc_card *card, int num, { struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; struct snd_soc_dai *cpu_dai = rtd->cpu_dai; - struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_platform *platform = rtd->platform; - int ret; + int i, ret; /* probe the CPU-side component, if it is a CODEC */ if (cpu_dai->codec && @@ -1348,12 +1375,14 @@ static int soc_probe_link_components(struct snd_soc_card *card, int num, return ret; } - /* probe the CODEC-side component */ - if (!codec_dai->codec->probed && - codec_dai->codec->driver->probe_order == order) { - ret = soc_probe_codec(card, codec_dai->codec); - if (ret < 0) - return ret; + /* probe the CODEC-side components */ + for (i = 0; i < rtd->num_codecs; i++) { + if (!rtd->codec_dais[i]->codec->probed && + rtd->codec_dais[i]->codec->driver->probe_order == order) { + ret = soc_probe_codec(card, rtd->codec_dais[i]->codec); + if (ret < 0) + return ret; + } } /* probe the platform */ @@ -1400,6 +1429,9 @@ static int soc_link_dai_widgets(struct snd_soc_card *card, struct snd_soc_dapm_widget *play_w, *capture_w; int ret; + if (rtd->num_codecs > 1) + dev_warn(card->dev, "ASoC: Multiple codecs not supported yet\n"); + /* link the DAI widgets */ play_w = codec_dai->playback_widget; capture_w = cpu_dai->capture_widget; @@ -1432,19 +1464,18 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) { struct snd_soc_dai_link *dai_link = &card->dai_link[num]; struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; - struct snd_soc_codec *codec = rtd->codec; struct snd_soc_platform *platform = rtd->platform; - struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *cpu_dai = rtd->cpu_dai; - int ret; + int i, ret; dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n", card->name, num, order); /* config components */ cpu_dai->platform = platform; - codec_dai->card = card; cpu_dai->card = card; + for (i = 0; i < rtd->num_codecs; i++) + rtd->codec_dais[i]->card = card; /* set default power off timeout */ rtd->pmdown_time = pmdown_time; @@ -1471,9 +1502,11 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) } /* probe the CODEC DAI */ - ret = soc_probe_codec_dai(card, codec_dai, order); - if (ret) - return ret; + for (i = 0; i < rtd->num_codecs; i++) { + ret = soc_probe_codec_dai(card, rtd->codec_dais[i], order); + if (ret) + return ret; + } /* complete DAI probe during last probe */ if (order != SND_SOC_COMP_ORDER_LAST) @@ -1541,8 +1574,11 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) } /* add platform data for AC97 devices */ - if (rtd->codec_dai->driver->ac97_control) - snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata); + for (i = 0; i < rtd->num_codecs; i++) { + if (rtd->codec_dais[i]->driver->ac97_control) + snd_ac97_dev_add_pdata(rtd->codec_dais[i]->codec->ac97, + rtd->cpu_dai->ac97_pdata); + } return 0; } @@ -1580,11 +1616,6 @@ static int soc_register_ac97_codec(struct snd_soc_codec *codec, return 0; } -static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) -{ - return soc_register_ac97_codec(rtd->codec, rtd->codec_dai); -} - static void soc_unregister_ac97_codec(struct snd_soc_codec *codec) { if (codec->ac97_registered) { @@ -1593,9 +1624,30 @@ static void soc_unregister_ac97_codec(struct snd_soc_codec *codec) } } +static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) +{ + int i, ret; + + for (i = 0; i < rtd->num_codecs; i++) { + struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; + + ret = soc_register_ac97_codec(codec_dai->codec, codec_dai); + if (ret) { + while (--i >= 0) + soc_unregister_ac97_codec(codec_dai->codec); + return ret; + } + } + + return 0; +} + static void soc_unregister_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) { - soc_unregister_ac97_codec(rtd->codec); + int i; + + for (i = 0; i < rtd->num_codecs; i++) + soc_unregister_ac97_codec(rtd->codec_dais[i]->codec); } #endif @@ -1794,16 +1846,23 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) card->num_dapm_routes); for (i = 0; i < card->num_links; i++) { + struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; dai_link = &card->dai_link[i]; dai_fmt = dai_link->dai_fmt; if (dai_fmt) { - ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai, - dai_fmt); - if (ret != 0 && ret != -ENOTSUPP) - dev_warn(card->rtd[i].codec_dai->dev, - "ASoC: Failed to set DAI format: %d\n", - ret); + struct snd_soc_dai **codec_dais = rtd->codec_dais; + int j; + + for (j = 0; j < rtd->num_codecs; j++) { + struct snd_soc_dai *codec_dai = codec_dais[j]; + + ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt); + if (ret != 0 && ret != -ENOTSUPP) + dev_warn(codec_dai->dev, + "ASoC: Failed to set DAI format: %d\n", + ret); + } } /* If this is a regular CPU link there will be a platform */ @@ -2002,10 +2061,15 @@ int snd_soc_poweroff(struct device *dev) /* deactivate pins to sleep state */ for (i = 0; i < card->num_rtd; i++) { - struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; - struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai; - pinctrl_pm_select_sleep_state(codec_dai->dev); + struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + int j; + pinctrl_pm_select_sleep_state(cpu_dai->dev); + for (j = 0; j < rtd->num_codecs; j++) { + struct snd_soc_dai *codec_dai = rtd->codec_dais[j]; + pinctrl_pm_select_sleep_state(codec_dai->dev); + } } return 0; @@ -3585,6 +3649,9 @@ int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, else snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask); + dai->tx_mask = tx_mask; + dai->rx_mask = rx_mask; + if (dai->driver && dai->driver->ops->set_tdm_slot) return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask, slots, slot_width); @@ -3657,6 +3724,33 @@ int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute, } EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); +static int snd_soc_init_multicodec(struct snd_soc_card *card, + struct snd_soc_dai_link *dai_link) +{ + /* Legacy codec/codec_dai link is a single entry in multicodec */ + if (dai_link->codec_name || dai_link->codec_of_node || + dai_link->codec_dai_name) { + dai_link->num_codecs = 1; + + dai_link->codecs = devm_kzalloc(card->dev, + sizeof(struct snd_soc_dai_link_component), + GFP_KERNEL); + if (!dai_link->codecs) + return -ENOMEM; + + dai_link->codecs[0].name = dai_link->codec_name; + dai_link->codecs[0].of_node = dai_link->codec_of_node; + dai_link->codecs[0].dai_name = dai_link->codec_dai_name; + } + + if (!dai_link->codecs) { + dev_err(card->dev, "ASoC: DAI link has no CODECs\n"); + return -EINVAL; + } + + return 0; +} + /** * snd_soc_register_card - Register a card with the ASoC core * @@ -3665,7 +3759,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute); */ int snd_soc_register_card(struct snd_soc_card *card) { - int i, ret; + int i, j, ret; if (!card->name || !card->dev) return -EINVAL; @@ -3673,22 +3767,29 @@ int snd_soc_register_card(struct snd_soc_card *card) for (i = 0; i < card->num_links; i++) { struct snd_soc_dai_link *link = &card->dai_link[i]; - /* - * Codec must be specified by 1 of name or OF node, - * not both or neither. - */ - if (!!link->codec_name == !!link->codec_of_node) { - dev_err(card->dev, - "ASoC: Neither/both codec name/of_node are set for %s\n", - link->name); - return -EINVAL; + ret = snd_soc_init_multicodec(card, link); + if (ret) { + dev_err(card->dev, "ASoC: failed to init multicodec\n"); + return ret; } - /* Codec DAI name must be specified */ - if (!link->codec_dai_name) { - dev_err(card->dev, - "ASoC: codec_dai_name not set for %s\n", - link->name); - return -EINVAL; + + for (j = 0; j < link->num_codecs; j++) { + /* + * Codec must be specified by 1 of name or OF node, + * not both or neither. + */ + if (!!link->codecs[j].name == + !!link->codecs[j].of_node) { + dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n", + link->name); + return -EINVAL; + } + /* Codec DAI name must be specified */ + if (!link->codecs[j].dai_name) { + dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n", + link->name); + return -EINVAL; + } } /* @@ -3744,6 +3845,12 @@ int snd_soc_register_card(struct snd_soc_card *card) for (i = 0; i < card->num_links; i++) { card->rtd[i].card = card; card->rtd[i].dai_link = &card->dai_link[i]; + card->rtd[i].codec_dais = devm_kzalloc(card->dev, + sizeof(struct snd_soc_dai *) * + (card->rtd[i].dai_link->num_codecs), + GFP_KERNEL); + if (card->rtd[i].codec_dais == NULL) + return -ENOMEM; } for (i = 0; i < card->num_aux_devs; i++) @@ -3760,10 +3867,16 @@ int snd_soc_register_card(struct snd_soc_card *card) /* deactivate pins to sleep state */ for (i = 0; i < card->num_rtd; i++) { - struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai; - struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai; - if (!codec_dai->active) - pinctrl_pm_select_sleep_state(codec_dai->dev); + struct snd_soc_pcm_runtime *rtd = &card->rtd[i]; + struct snd_soc_dai *cpu_dai = rtd->cpu_dai; + int j; + + for (j = 0; j < rtd->num_codecs; j++) { + struct snd_soc_dai *codec_dai = rtd->codec_dais[j]; + if (!codec_dai->active) + pinctrl_pm_select_sleep_state(codec_dai->dev); + } + if (!cpu_dai->active) pinctrl_pm_select_sleep_state(cpu_dai->dev); } -- cgit v1.2.3-58-ga151 From 93e6958a3674d2fa42e2c24ad5156e65da1d8621 Mon Sep 17 00:00:00 2001 From: Benoit Cousson Date: Tue, 8 Jul 2014 23:19:38 +0200 Subject: ASoC: pcm: Add soc_dai_hw_params helper Add a function helper to factorize the hw_params code. Suggested by Lars-Peter Clausen Signed-off-by: Benoit Cousson Tested-by: Lars-Peter Clausen Reviewed-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- include/sound/soc.h | 4 ++++ sound/soc/soc-dapm.c | 28 ++++++++-------------------- sound/soc/soc-pcm.c | 43 ++++++++++++++++++++++++------------------- 3 files changed, 36 insertions(+), 39 deletions(-) (limited to 'include/sound') diff --git a/include/sound/soc.h b/include/sound/soc.h index f2142cf3f243..98555f833ab4 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -436,6 +436,10 @@ int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, int snd_soc_platform_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_platform *platform); +int soc_dai_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai); + /* Jack reporting */ int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type, struct snd_soc_jack *jack); diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 5c63c3b49f3f..9a047f360993 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -3214,27 +3214,15 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, switch (event) { case SND_SOC_DAPM_PRE_PMU: - if (source->driver->ops && source->driver->ops->hw_params) { - substream.stream = SNDRV_PCM_STREAM_CAPTURE; - ret = source->driver->ops->hw_params(&substream, - params, source); - if (ret != 0) { - dev_err(source->dev, - "ASoC: hw_params() failed: %d\n", ret); - goto out; - } - } + substream.stream = SNDRV_PCM_STREAM_CAPTURE; + ret = soc_dai_hw_params(&substream, params, source); + if (ret < 0) + goto out; - if (sink->driver->ops && sink->driver->ops->hw_params) { - substream.stream = SNDRV_PCM_STREAM_PLAYBACK; - ret = sink->driver->ops->hw_params(&substream, params, - sink); - if (ret != 0) { - dev_err(sink->dev, - "ASoC: hw_params() failed: %d\n", ret); - goto out; - } - } + substream.stream = SNDRV_PCM_STREAM_PLAYBACK; + ret = soc_dai_hw_params(&substream, params, sink); + if (ret < 0) + goto out; break; case SND_SOC_DAPM_POST_PMU: diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index ec56d1831a86..3ec87d8aa181 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -789,6 +789,24 @@ static void soc_pcm_codec_params_fixup(struct snd_pcm_hw_params *params, interval->max = channels; } +int soc_dai_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + int ret; + + if (dai->driver->ops && dai->driver->ops->hw_params) { + ret = dai->driver->ops->hw_params(substream, params, dai); + if (ret < 0) { + dev_err(dai->dev, "ASoC: can't set %s hw params: %d\n", + dai->name, ret); + return ret; + } + } + + return 0; +} + /* * Called by ALSA when the hardware params are set by application. This * function can also be called multiple times and can allocate buffers @@ -832,17 +850,9 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, soc_pcm_codec_params_fixup(&codec_params, codec_dai->rx_mask); - if (codec_dai->driver->ops && - codec_dai->driver->ops->hw_params) { - ret = codec_dai->driver->ops->hw_params(substream, - &codec_params, codec_dai); - if (ret < 0) { - dev_err(codec_dai->dev, - "ASoC: can't set %s hw params: %d\n", - codec_dai->name, ret); - goto codec_err; - } - } + ret = soc_dai_hw_params(substream, &codec_params, codec_dai); + if(ret < 0) + goto codec_err; codec_dai->rate = params_rate(&codec_params); codec_dai->channels = params_channels(&codec_params); @@ -850,14 +860,9 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, params_format(&codec_params)); } - if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_params) { - ret = cpu_dai->driver->ops->hw_params(substream, params, cpu_dai); - if (ret < 0) { - dev_err(cpu_dai->dev, "ASoC: %s hw params failed: %d\n", - cpu_dai->name, ret); - goto interface_err; - } - } + ret = soc_dai_hw_params(substream, params, cpu_dai); + if (ret < 0) + goto interface_err; if (platform->driver->ops && platform->driver->ops->hw_params) { ret = platform->driver->ops->hw_params(substream, params); -- cgit v1.2.3-58-ga151 From 9898e1ccf5af70ad2d03d5b77c591fb243c0f021 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 17 Jul 2014 22:01:05 +0200 Subject: ASoC: Remove per card platform list The platform_dev_list was added in commit f0fba2ad1b ("ASoC: multi-component - ASoC Multi-Component Support") and while platforms are added and remove from that list it is otherwise unused. This patch removes it again. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- include/sound/soc.h | 3 --- sound/soc/soc-core.c | 2 -- 2 files changed, 5 deletions(-) (limited to 'include/sound') diff --git a/include/sound/soc.h b/include/sound/soc.h index 98555f833ab4..1f5b4901415e 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -865,7 +865,6 @@ struct snd_soc_platform { struct snd_soc_card *card; struct list_head list; - struct list_head card_list; struct snd_soc_component component; @@ -1056,7 +1055,6 @@ struct snd_soc_card { /* lists of probed devices belonging to this card */ struct list_head codec_dev_list; - struct list_head platform_dev_list; struct list_head widgets; struct list_head paths; @@ -1299,7 +1297,6 @@ static inline void *snd_soc_pcm_get_drvdata(struct snd_soc_pcm_runtime *rtd) static inline void snd_soc_initialize_card_lists(struct snd_soc_card *card) { INIT_LIST_HEAD(&card->codec_dev_list); - INIT_LIST_HEAD(&card->platform_dev_list); INIT_LIST_HEAD(&card->widgets); INIT_LIST_HEAD(&card->paths); INIT_LIST_HEAD(&card->dapm_list); diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 6e47610f73a0..a5edb31ddfff 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1027,7 +1027,6 @@ static int soc_remove_platform(struct snd_soc_platform *platform) soc_cleanup_platform_debugfs(platform); platform->probed = 0; - list_del(&platform->card_list); module_put(platform->dev->driver->owner); return 0; @@ -1297,7 +1296,6 @@ static int soc_probe_platform(struct snd_soc_card *card, /* mark platform as probed and add to card platform list */ platform->probed = 1; - list_add(&platform->card_list, &card->platform_dev_list); list_add(&platform->component.dapm.list, &card->dapm_list); return 0; -- cgit v1.2.3-58-ga151 From 00200107a296cad3a950049a5ad7134a0d962b8d Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 17 Jul 2014 22:01:07 +0200 Subject: ASoC: Move card field form platform/codec to component Both the snd_soc_codec and snd_soc_platform struct do have a pointer to the parent card and both handle this pointer in mostly the same way. This patch moves the card field to the component level which will allow further code consolidation between platforms and CODECS. Since there are only a handful of users of the snd_soc_codec struct's card field (and none of the snd_soc_platform's) these are update in this patch as well, which allows it to be removed from the snd_soc_codec struct. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- include/sound/soc.h | 3 +-- sound/soc/codecs/ac97.c | 4 ++-- sound/soc/codecs/cx20442.c | 6 +++--- sound/soc/codecs/uda134x.c | 2 +- sound/soc/codecs/wm8960.c | 2 +- sound/soc/codecs/wm_adsp.c | 4 ++-- sound/soc/omap/ams-delta.c | 2 +- sound/soc/soc-core.c | 19 ++++++++++--------- sound/soc/soc-dapm.c | 2 +- sound/soc/soc-jack.c | 4 ++-- 10 files changed, 24 insertions(+), 24 deletions(-) (limited to 'include/sound') diff --git a/include/sound/soc.h b/include/sound/soc.h index 1f5b4901415e..5ee6ddde4831 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -691,6 +691,7 @@ struct snd_soc_component { int id; const char *name_prefix; struct device *dev; + struct snd_soc_card *card; unsigned int active; @@ -725,7 +726,6 @@ struct snd_soc_codec { const struct snd_soc_codec_driver *driver; struct mutex mutex; - struct snd_soc_card *card; struct list_head list; struct list_head card_list; @@ -863,7 +863,6 @@ struct snd_soc_platform { unsigned int suspended:1; /* platform is suspended */ unsigned int probed:1; - struct snd_soc_card *card; struct list_head list; struct snd_soc_component component; diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c index 8d9ba4ba4bfe..e889e1b84192 100644 --- a/sound/soc/codecs/ac97.c +++ b/sound/soc/codecs/ac97.c @@ -89,8 +89,8 @@ static int ac97_soc_probe(struct snd_soc_codec *codec) int ret; /* add codec as bus device for standard ac97 */ - ret = snd_ac97_bus(codec->card->snd_card, 0, soc_ac97_ops, NULL, - &ac97_bus); + ret = snd_ac97_bus(codec->component.card->snd_card, 0, soc_ac97_ops, + NULL, &ac97_bus); if (ret < 0) return ret; diff --git a/sound/soc/codecs/cx20442.c b/sound/soc/codecs/cx20442.c index d5fd00a64748..4ba60eb2cde1 100644 --- a/sound/soc/codecs/cx20442.c +++ b/sound/soc/codecs/cx20442.c @@ -253,7 +253,7 @@ static void v253_close(struct tty_struct *tty) /* Prevent the codec driver from further accessing the modem */ codec->hw_write = NULL; cx20442->control_data = NULL; - codec->card->pop_time = 0; + codec->component.card->pop_time = 0; } /* Line discipline .hangup() */ @@ -281,7 +281,7 @@ static void v253_receive(struct tty_struct *tty, /* Set up codec driver access to modem controls */ cx20442->control_data = tty; codec->hw_write = (hw_write_t)tty->ops->write; - codec->card->pop_time = 1; + codec->component.card->pop_time = 1; } } @@ -372,7 +372,7 @@ static int cx20442_codec_probe(struct snd_soc_codec *codec) snd_soc_codec_set_drvdata(codec, cx20442); codec->hw_write = NULL; - codec->card->pop_time = 0; + codec->component.card->pop_time = 0; return 0; } diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c index edf27acc1d77..12fc0aed7503 100644 --- a/sound/soc/codecs/uda134x.c +++ b/sound/soc/codecs/uda134x.c @@ -479,7 +479,7 @@ static struct snd_soc_dai_driver uda134x_dai = { static int uda134x_soc_probe(struct snd_soc_codec *codec) { struct uda134x_priv *uda134x; - struct uda134x_platform_data *pd = codec->card->dev->platform_data; + struct uda134x_platform_data *pd = codec->component.card->dev->platform_data; const struct snd_soc_dapm_widget *widgets; unsigned num_widgets; diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index a145d0431b63..e96349b04ba6 100644 --- a/sound/soc/codecs/wm8960.c +++ b/sound/soc/codecs/wm8960.c @@ -472,7 +472,7 @@ static int wm8960_add_widgets(struct snd_soc_codec *codec) * list each time to find the desired power state do so now * and save the result. */ - list_for_each_entry(w, &codec->card->widgets, list) { + list_for_each_entry(w, &codec->component.card->widgets, list) { if (w->dapm != &codec->dapm) continue; if (strcmp(w->name, "LOUT1 PGA") == 0) diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c index 060027182dcb..fb86f072fa67 100644 --- a/sound/soc/codecs/wm_adsp.c +++ b/sound/soc/codecs/wm_adsp.c @@ -1382,7 +1382,7 @@ int wm_adsp1_event(struct snd_soc_dapm_widget *w, int ret; int val; - dsp->card = codec->card; + dsp->card = codec->component.card; switch (event) { case SND_SOC_DAPM_POST_PMU: @@ -1617,7 +1617,7 @@ int wm_adsp2_early_event(struct snd_soc_dapm_widget *w, struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec); struct wm_adsp *dsp = &dsps[w->shift]; - dsp->card = codec->card; + dsp->card = codec->component.card; switch (event) { case SND_SOC_DAPM_PRE_PMU: diff --git a/sound/soc/omap/ams-delta.c b/sound/soc/omap/ams-delta.c index 0cc41f94de4e..8c9cc64a9dfb 100644 --- a/sound/soc/omap/ams-delta.c +++ b/sound/soc/omap/ams-delta.c @@ -301,7 +301,7 @@ static int cx81801_open(struct tty_struct *tty) static void cx81801_close(struct tty_struct *tty) { struct snd_soc_codec *codec = tty->disc_data; - struct snd_soc_dapm_context *dapm = &codec->card->dapm; + struct snd_soc_dapm_context *dapm = &codec->component.card->dapm; del_timer_sync(&cx81801_timer); diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index a5edb31ddfff..a0ae3d2263d1 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -292,7 +292,7 @@ static struct dentry *soc_debugfs_create_dir(struct dentry *parent, static void soc_init_codec_debugfs(struct snd_soc_codec *codec) { - struct dentry *debugfs_card_root = codec->card->debugfs_card_root; + struct dentry *debugfs_card_root = codec->component.card->debugfs_card_root; codec->debugfs_codec_root = soc_debugfs_create_dir(debugfs_card_root, "codec:%s", @@ -325,7 +325,7 @@ static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec) static void soc_init_platform_debugfs(struct snd_soc_platform *platform) { - struct dentry *debugfs_card_root = platform->card->debugfs_card_root; + struct dentry *debugfs_card_root = platform->component.card->debugfs_card_root; platform->debugfs_platform_root = soc_debugfs_create_dir(debugfs_card_root, "platform:%s", @@ -546,11 +546,12 @@ static int soc_ac97_dev_register(struct snd_soc_codec *codec) int err; codec->ac97->dev.bus = &ac97_bus_type; - codec->ac97->dev.parent = codec->card->dev; + codec->ac97->dev.parent = codec->component.card->dev; codec->ac97->dev.release = soc_ac97_device_release; dev_set_name(&codec->ac97->dev, "%d-%d:%s", - codec->card->snd_card->number, 0, codec->component.name); + codec->component.card->snd_card->number, 0, + codec->component.name); err = device_register(&codec->ac97->dev); if (err < 0) { dev_err(codec->dev, "ASoC: Can't register ac97 bus\n"); @@ -1179,7 +1180,7 @@ static int soc_probe_codec(struct snd_soc_card *card, const struct snd_soc_codec_driver *driver = codec->driver; struct snd_soc_dai *dai; - codec->card = card; + codec->component.card = card; codec->dapm.card = card; soc_set_name_prefix(card, &codec->component); @@ -1255,7 +1256,7 @@ static int soc_probe_platform(struct snd_soc_card *card, struct snd_soc_component *component; struct snd_soc_dai *dai; - platform->card = card; + platform->component.card = card; platform->component.dapm.card = card; if (!try_module_get(platform->dev->driver->owner)) @@ -2406,7 +2407,7 @@ EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol); int snd_soc_add_codec_controls(struct snd_soc_codec *codec, const struct snd_kcontrol_new *controls, int num_controls) { - struct snd_card *card = codec->card->snd_card; + struct snd_card *card = codec->component.card->snd_card; return snd_soc_add_controls(card, codec->dev, controls, num_controls, codec->component.name_prefix, &codec->component); @@ -2426,7 +2427,7 @@ EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls); int snd_soc_add_platform_controls(struct snd_soc_platform *platform, const struct snd_kcontrol_new *controls, int num_controls) { - struct snd_card *card = platform->card->snd_card; + struct snd_card *card = platform->component.card->snd_card; return snd_soc_add_controls(card, platform->dev, controls, num_controls, NULL, &platform->component); @@ -3101,7 +3102,7 @@ EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range); int snd_soc_limit_volume(struct snd_soc_codec *codec, const char *name, int max) { - struct snd_card *card = codec->card->snd_card; + struct snd_card *card = codec->component.card->snd_card; struct snd_kcontrol *kctl; struct soc_mixer_control *mc; int found = 0; diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 8cb68a38ad19..8348352dc2c6 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c @@ -2090,7 +2090,7 @@ static ssize_t dapm_widget_show_codec(struct snd_soc_codec *codec, char *buf) int count = 0; char *state = "not set"; - list_for_each_entry(w, &codec->card->widgets, list) { + list_for_each_entry(w, &codec->component.card->widgets, list) { if (w->dapm != &codec->dapm) continue; diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c index d0d98810af91..ab47fea997a3 100644 --- a/sound/soc/soc-jack.c +++ b/sound/soc/soc-jack.c @@ -43,7 +43,7 @@ int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type, INIT_LIST_HEAD(&jack->jack_zones); BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier); - return snd_jack_new(codec->card->snd_card, id, type, &jack->jack); + return snd_jack_new(codec->component.card->snd_card, id, type, &jack->jack); } EXPORT_SYMBOL_GPL(snd_soc_jack_new); @@ -260,7 +260,7 @@ static void snd_soc_jack_gpio_detect(struct snd_soc_jack_gpio *gpio) static irqreturn_t gpio_handler(int irq, void *data) { struct snd_soc_jack_gpio *gpio = data; - struct device *dev = gpio->jack->codec->card->dev; + struct device *dev = gpio->jack->codec->component.card->dev; trace_snd_soc_jack_irq(gpio->name); -- cgit v1.2.3-58-ga151 From 0f2780ad4c2a398528c7bb1572158d6e894e5dd2 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 17 Jul 2014 22:01:08 +0200 Subject: ASoC: Add function to register component controls We have now everything in place to actual let a component register controls. Add a function which allows to do so. Also update snd_soc_add_codec_controls() and snd_soc_platform_controls() to use this new function internally. And while we are at it also change the num_controls parameter of those two functions from int to unsigned int. Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- include/sound/soc.h | 6 ++++-- sound/soc/soc-core.c | 35 +++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 12 deletions(-) (limited to 'include/sound') diff --git a/include/sound/soc.h b/include/sound/soc.h index 5ee6ddde4831..50ff6f3459aa 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -507,10 +507,12 @@ struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, const char *prefix); struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card, const char *name); +int snd_soc_add_component_controls(struct snd_soc_component *component, + const struct snd_kcontrol_new *controls, unsigned int num_controls); int snd_soc_add_codec_controls(struct snd_soc_codec *codec, - const struct snd_kcontrol_new *controls, int num_controls); + const struct snd_kcontrol_new *controls, unsigned int num_controls); int snd_soc_add_platform_controls(struct snd_soc_platform *platform, - const struct snd_kcontrol_new *controls, int num_controls); + const struct snd_kcontrol_new *controls, unsigned int num_controls); int snd_soc_add_card_controls(struct snd_soc_card *soc_card, const struct snd_kcontrol_new *controls, int num_controls); int snd_soc_add_dai_controls(struct snd_soc_dai *dai, diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index a0ae3d2263d1..28caa63ae526 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -2393,6 +2393,25 @@ struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card, } EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol); +/** + * snd_soc_add_component_controls - Add an array of controls to a component. + * + * @component: Component to add controls to + * @controls: Array of controls to add + * @num_controls: Number of elements in the array + * + * Return: 0 for success, else error. + */ +int snd_soc_add_component_controls(struct snd_soc_component *component, + const struct snd_kcontrol_new *controls, unsigned int num_controls) +{ + struct snd_card *card = component->card->snd_card; + + return snd_soc_add_controls(card, component->dev, controls, + num_controls, component->name_prefix, component); +} +EXPORT_SYMBOL_GPL(snd_soc_add_component_controls); + /** * snd_soc_add_codec_controls - add an array of controls to a codec. * Convenience function to add a list of controls. Many codecs were @@ -2405,12 +2424,10 @@ EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol); * Return 0 for success, else error. */ int snd_soc_add_codec_controls(struct snd_soc_codec *codec, - const struct snd_kcontrol_new *controls, int num_controls) + const struct snd_kcontrol_new *controls, unsigned int num_controls) { - struct snd_card *card = codec->component.card->snd_card; - - return snd_soc_add_controls(card, codec->dev, controls, num_controls, - codec->component.name_prefix, &codec->component); + return snd_soc_add_component_controls(&codec->component, controls, + num_controls); } EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls); @@ -2425,12 +2442,10 @@ EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls); * Return 0 for success, else error. */ int snd_soc_add_platform_controls(struct snd_soc_platform *platform, - const struct snd_kcontrol_new *controls, int num_controls) + const struct snd_kcontrol_new *controls, unsigned int num_controls) { - struct snd_card *card = platform->component.card->snd_card; - - return snd_soc_add_controls(card, platform->dev, controls, num_controls, - NULL, &platform->component); + return snd_soc_add_component_controls(&platform->component, controls, + num_controls); } EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls); -- cgit v1.2.3-58-ga151