Lines Matching +full:i2c +full:- +full:topology

1 // SPDX-License-Identifier: GPL-2.0+
3 // soc-core.c -- ALSA SoC Audio Layer
11 // with code, comments and ideas from :-
39 #include <sound/soc-dpcm.h>
40 #include <sound/soc-topology.h>
41 #include <sound/soc-link.h>
75 return sprintf(buf, "%ld\n", rtd->pmdown_time); in pmdown_time_show()
85 ret = kstrtol(buf, 10, &rtd->pmdown_time); in pmdown_time_store()
109 return attr->mode; /* always visible */ in soc_dev_attr_is_visible()
110 return rtd->num_codecs ? attr->mode : 0; /* enabled only with codec */ in soc_dev_attr_is_visible()
135 if (!component->card->debugfs_card_root) in soc_init_component_debugfs()
138 if (component->debugfs_prefix) { in soc_init_component_debugfs()
142 component->debugfs_prefix, component->name); in soc_init_component_debugfs()
144 component->debugfs_root = debugfs_create_dir(name, in soc_init_component_debugfs()
145 component->card->debugfs_card_root); in soc_init_component_debugfs()
149 component->debugfs_root = debugfs_create_dir(component->name, in soc_init_component_debugfs()
150 component->card->debugfs_card_root); in soc_init_component_debugfs()
154 component->debugfs_root); in soc_init_component_debugfs()
159 if (!component->debugfs_root) in soc_cleanup_component_debugfs()
161 debugfs_remove_recursive(component->debugfs_root); in soc_cleanup_component_debugfs()
162 component->debugfs_root = NULL; in soc_cleanup_component_debugfs()
174 seq_printf(m, "%s\n", dai->name); in dai_list_show()
189 seq_printf(m, "%s\n", component->name); in component_list_show()
199 card->debugfs_card_root = debugfs_create_dir(card->name, in soc_init_card_debugfs()
202 debugfs_create_u32("dapm_pop_time", 0644, card->debugfs_card_root, in soc_init_card_debugfs()
203 &card->pop_time); in soc_init_card_debugfs()
205 snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root); in soc_init_card_debugfs()
210 debugfs_remove_recursive(card->debugfs_card_root); in soc_cleanup_card_debugfs()
211 card->debugfs_card_root = NULL; in soc_cleanup_card_debugfs()
273 rtd->components[rtd->num_components] = component; in snd_soc_rtd_add_component()
274 rtd->num_components++; in snd_soc_rtd_add_component()
297 const char *component_name = component->driver->name; in snd_soc_rtdcom_lookup()
319 if ((dev == component->dev) && in snd_soc_lookup_component_nolocked()
321 (driver_name == component->driver->name) || in snd_soc_lookup_component_nolocked()
322 (strcmp(component->driver->name, driver_name) == 0))) { in snd_soc_lookup_component_nolocked()
352 if (rtd->dai_link == dai_link) in snd_soc_get_pcm_runtime()
355 dev_dbg(card->dev, "ASoC: failed to find rtd %s\n", dai_link->name); in snd_soc_get_pcm_runtime()
370 mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); in snd_soc_close_delayed_work()
372 dev_dbg(rtd->dev, in snd_soc_close_delayed_work()
374 codec_dai->driver->playback.stream_name, in snd_soc_close_delayed_work()
377 rtd->pop_wait ? "yes" : "no"); in snd_soc_close_delayed_work()
380 if (rtd->pop_wait == 1) { in snd_soc_close_delayed_work()
381 rtd->pop_wait = 0; in snd_soc_close_delayed_work()
386 mutex_unlock(&rtd->card->pcm_mutex); in snd_soc_close_delayed_work()
392 /* "dev" means "rtd->dev" */ in soc_release_rtd_dev()
401 list_del(&rtd->list); in soc_free_pcm_runtime()
403 if (delayed_work_pending(&rtd->delayed_work)) in soc_free_pcm_runtime()
404 flush_delayed_work(&rtd->delayed_work); in soc_free_pcm_runtime()
408 * we don't need to call kfree() for rtd->dev in soc_free_pcm_runtime()
412 * We don't need rtd->dev NULL check, because in soc_free_pcm_runtime()
418 * because it was created from dev (= rtd->dev) in soc_free_pcm_runtime()
423 * rtd->dev = dev in soc_free_pcm_runtime()
425 device_unregister(rtd->dev); in soc_free_pcm_runtime()
433 if (rtd->close_delayed_work_func) in close_delayed_work()
434 rtd->close_delayed_work_func(rtd); in close_delayed_work()
447 * for rtd->dev in soc_new_pcm_runtime()
453 dev->parent = card->dev; in soc_new_pcm_runtime()
454 dev->release = soc_release_rtd_dev; in soc_new_pcm_runtime()
456 dev_set_name(dev, "%s", dai_link->name); in soc_new_pcm_runtime()
469 sizeof(*component) * (dai_link->num_cpus + in soc_new_pcm_runtime()
470 dai_link->num_codecs + in soc_new_pcm_runtime()
471 dai_link->num_platforms), in soc_new_pcm_runtime()
478 rtd->dev = dev; in soc_new_pcm_runtime()
479 INIT_LIST_HEAD(&rtd->list); in soc_new_pcm_runtime()
481 INIT_LIST_HEAD(&rtd->dpcm[stream].be_clients); in soc_new_pcm_runtime()
482 INIT_LIST_HEAD(&rtd->dpcm[stream].fe_clients); in soc_new_pcm_runtime()
485 INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work); in soc_new_pcm_runtime()
488 * for rtd->dais in soc_new_pcm_runtime()
490 rtd->dais = devm_kcalloc(dev, dai_link->num_cpus + dai_link->num_codecs, in soc_new_pcm_runtime()
493 if (!rtd->dais) in soc_new_pcm_runtime()
499 * |--- num_cpus ---|--- num_codecs --| in soc_new_pcm_runtime()
504 rtd->num_cpus = dai_link->num_cpus; in soc_new_pcm_runtime()
505 rtd->num_codecs = dai_link->num_codecs; in soc_new_pcm_runtime()
506 rtd->card = card; in soc_new_pcm_runtime()
507 rtd->dai_link = dai_link; in soc_new_pcm_runtime()
508 rtd->num = card->num_rtd++; in soc_new_pcm_runtime()
511 list_add_tail(&rtd->list, &card->rtd_list); in soc_new_pcm_runtime()
529 flush_delayed_work(&rtd->delayed_work); in snd_soc_flush_all_delayed_work()
542 if (rtd->dai_link->ignore_suspend) in soc_playback_digital_mute()
559 if (rtd->dai_link->ignore_suspend) in soc_dapm_suspend_resume()
576 if (!card->instantiated) in snd_soc_suspend()
581 * suspend before that's finished - wait for it to complete. in snd_soc_suspend()
583 snd_power_wait(card->snd_card); in snd_soc_suspend()
586 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot); in snd_soc_suspend()
593 if (rtd->dai_link->ignore_suspend) in snd_soc_suspend()
596 snd_pcm_suspend_all(rtd->pcm); in snd_soc_suspend()
608 snd_soc_dapm_sync(&card->dapm); in snd_soc_suspend()
613 if (rtd->dai_link->ignore_suspend) in snd_soc_suspend()
638 if (dapm->idle_bias_off) { in snd_soc_suspend()
639 dev_dbg(component->dev, in snd_soc_suspend()
647 if (component->regmap) in snd_soc_suspend()
648 regcache_mark_dirty(component->regmap); in snd_soc_suspend()
650 pinctrl_pm_select_sleep_state(component->dev); in snd_soc_suspend()
653 dev_dbg(component->dev, in snd_soc_suspend()
668 * setting our codec back up, which can be very slow on I2C
682 dev_dbg(card->dev, "ASoC: starting resume work\n"); in soc_resume_deferred()
685 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2); in soc_resume_deferred()
701 dev_dbg(card->dev, "ASoC: resume work completed\n"); in soc_resume_deferred()
705 snd_soc_dapm_sync(&card->dapm); in soc_resume_deferred()
708 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0); in soc_resume_deferred()
718 if (!card->instantiated) in snd_soc_resume()
724 pinctrl_pm_select_default_state(component->dev); in snd_soc_resume()
727 if (!schedule_work(&card->deferred_resume_work)) in snd_soc_resume()
737 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); in soc_resume_init()
752 of_node = component->dev->of_node; in soc_component_to_node()
753 if (!of_node && component->dev->parent) in soc_component_to_node()
754 of_node = component->dev->parent->of_node; in soc_component_to_node()
770 if (dlc->of_node && component_of_node != dlc->of_node) in snd_soc_is_matching_component()
772 if (dlc->name && strcmp(component->name, dlc->name)) in snd_soc_is_matching_component()
801 * snd_soc_find_dai - Find a registered DAI
824 if (dlc->dai_name && strcmp(dai->name, dlc->dai_name) in snd_soc_find_dai()
825 && (!dai->driver->name in snd_soc_find_dai()
826 || strcmp(dai->driver->name, dlc->dai_name))) in snd_soc_find_dai()
861 if (!!codec->name == !!codec->of_node) { in soc_dai_link_sanity_check()
862 dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n", in soc_dai_link_sanity_check()
863 link->name); in soc_dai_link_sanity_check()
864 return -EINVAL; in soc_dai_link_sanity_check()
868 if (!codec->dai_name) { in soc_dai_link_sanity_check()
869 dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n", in soc_dai_link_sanity_check()
870 link->name); in soc_dai_link_sanity_check()
871 return -EINVAL; in soc_dai_link_sanity_check()
879 dev_dbg(card->dev, in soc_dai_link_sanity_check()
881 codec->name, link->name); in soc_dai_link_sanity_check()
882 return -EPROBE_DEFER; in soc_dai_link_sanity_check()
892 if (!!platform->name == !!platform->of_node) { in soc_dai_link_sanity_check()
893 dev_err(card->dev, in soc_dai_link_sanity_check()
895 link->name); in soc_dai_link_sanity_check()
896 return -EINVAL; in soc_dai_link_sanity_check()
904 dev_dbg(card->dev, in soc_dai_link_sanity_check()
906 platform->name, link->name); in soc_dai_link_sanity_check()
907 return -EPROBE_DEFER; in soc_dai_link_sanity_check()
917 if (cpu->name && cpu->of_node) { in soc_dai_link_sanity_check()
918 dev_err(card->dev, in soc_dai_link_sanity_check()
920 link->name); in soc_dai_link_sanity_check()
921 return -EINVAL; in soc_dai_link_sanity_check()
928 if ((cpu->of_node || cpu->name) && in soc_dai_link_sanity_check()
930 dev_dbg(card->dev, in soc_dai_link_sanity_check()
932 cpu->name, link->name); in soc_dai_link_sanity_check()
933 return -EPROBE_DEFER; in soc_dai_link_sanity_check()
940 if (!cpu->dai_name && in soc_dai_link_sanity_check()
941 !(cpu->name || cpu->of_node)) { in soc_dai_link_sanity_check()
942 dev_err(card->dev, in soc_dai_link_sanity_check()
944 link->name); in soc_dai_link_sanity_check()
945 return -EINVAL; in soc_dai_link_sanity_check()
953 * snd_soc_remove_pcm_runtime - Remove a pcm_runtime from card
970 snd_soc_card_remove_dai_link(card, rtd->dai_link); in snd_soc_remove_pcm_runtime()
977 * snd_soc_add_pcm_runtime - Add a pcm_runtime dynamically via dai_link
983 * Note: Topology can use this API to add pcm_runtime when probing the
984 * topology component. And machine drivers can still define static
1004 if (dai_link->ignore) in snd_soc_add_pcm_runtime()
1007 dev_dbg(card->dev, "ASoC: binding %s\n", dai_link->name); in snd_soc_add_pcm_runtime()
1015 return -ENOMEM; in snd_soc_add_pcm_runtime()
1020 dev_info(card->dev, "ASoC: CPU DAI %s not registered\n", in snd_soc_add_pcm_runtime()
1021 cpu->dai_name); in snd_soc_add_pcm_runtime()
1024 snd_soc_rtd_add_component(rtd, asoc_rtd_to_cpu(rtd, i)->component); in snd_soc_add_pcm_runtime()
1031 dev_info(card->dev, "ASoC: CODEC DAI %s not registered\n", in snd_soc_add_pcm_runtime()
1032 codec->dai_name); in snd_soc_add_pcm_runtime()
1036 snd_soc_rtd_add_component(rtd, asoc_rtd_to_codec(rtd, i)->component); in snd_soc_add_pcm_runtime()
1053 return -EPROBE_DEFER; in snd_soc_add_pcm_runtime()
1059 struct snd_soc_dai_link *dai_link = rtd->dai_link; in snd_soc_runtime_get_dai_fmt()
1061 struct device *dev = rtd->dev; in snd_soc_runtime_get_dai_fmt()
1111 pri = (j >= i) ? priority : priority - 1; in snd_soc_runtime_get_dai_fmt()
1113 dev_dbg(dev, "%s: (pri, fmt) = (%d, %016llX)\n", dai->name, pri, fmt); in snd_soc_runtime_get_dai_fmt()
1141 for (i = 63; i >= 0; i--) { in snd_soc_runtime_get_dai_fmt()
1200 * In such case, user want to auto-select non-limitation part, in snd_soc_runtime_get_dai_fmt()
1208 if (!(dai_link->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK)) in snd_soc_runtime_get_dai_fmt()
1210 if (!(dai_link->dai_fmt & SND_SOC_DAIFMT_CLOCK_MASK)) in snd_soc_runtime_get_dai_fmt()
1212 if (!(dai_link->dai_fmt & SND_SOC_DAIFMT_INV_MASK)) in snd_soc_runtime_get_dai_fmt()
1214 if (!(dai_link->dai_fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK)) in snd_soc_runtime_get_dai_fmt()
1217 dai_link->dai_fmt |= (dai_fmt & mask); in snd_soc_runtime_get_dai_fmt()
1221 * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime
1244 if (ret != 0 && ret != -ENOTSUPP) in snd_soc_runtime_set_dai_fmt()
1249 * Flip the polarity for the "CPU" end of a CODEC<->CODEC link in snd_soc_runtime_set_dai_fmt()
1257 if (cpu_dai->component->driver->non_legacy_dai_naming) in snd_soc_runtime_set_dai_fmt()
1261 if (ret != 0 && ret != -ENOTSUPP) in snd_soc_runtime_set_dai_fmt()
1272 struct snd_soc_dai_link *dai_link = rtd->dai_link; in soc_init_pcm_runtime()
1278 rtd->pmdown_time = pmdown_time; in soc_init_pcm_runtime()
1286 if (dai_link->dai_fmt) { in soc_init_pcm_runtime()
1287 ret = snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt); in soc_init_pcm_runtime()
1295 num = rtd->num; in soc_init_pcm_runtime()
1299 * topology based drivers can use the DAI link id field to set PCM in soc_init_pcm_runtime()
1303 if (!component->driver->use_dai_pcm_id) in soc_init_pcm_runtime()
1306 if (rtd->dai_link->no_pcm) in soc_init_pcm_runtime()
1307 num += component->driver->be_pcm_base; in soc_init_pcm_runtime()
1309 num = rtd->dai_link->id; in soc_init_pcm_runtime()
1314 if (ret != -ENOTSUPP) in soc_init_pcm_runtime()
1320 dev_err(card->dev, "ASoC: can't create pcm %s :%d\n", in soc_init_pcm_runtime()
1321 dai_link->stream_name, ret); in soc_init_pcm_runtime()
1335 for (i = 0; i < card->num_configs; i++) { in soc_set_name_prefix()
1336 struct snd_soc_codec_conf *map = &card->codec_conf[i]; in soc_set_name_prefix()
1338 if (snd_soc_is_matching_component(&map->dlc, component) && in soc_set_name_prefix()
1339 map->name_prefix) { in soc_set_name_prefix()
1340 component->name_prefix = map->name_prefix; in soc_set_name_prefix()
1349 ret = of_property_read_string(of_node, "sound-name-prefix", &str); in soc_set_name_prefix()
1353 component->name_prefix = str; in soc_set_name_prefix()
1360 if (!component->card) in soc_remove_component()
1369 list_del_init(&component->card_list); in soc_remove_component()
1372 component->card = NULL; in soc_remove_component()
1388 if (component->card) { in soc_probe_component()
1389 if (component->card != card) { in soc_probe_component()
1390 dev_err(component->dev, in soc_probe_component()
1392 card->name, component->card->name); in soc_probe_component()
1393 return -ENODEV; in soc_probe_component()
1402 component->card = card; in soc_probe_component()
1410 component->driver->dapm_widgets, in soc_probe_component()
1411 component->driver->num_dapm_widgets); in soc_probe_component()
1414 dev_err(component->dev, in soc_probe_component()
1422 dev_err(component->dev, in soc_probe_component()
1432 WARN(dapm->idle_bias_off && in soc_probe_component()
1433 dapm->bias_level != SND_SOC_BIAS_OFF, in soc_probe_component()
1434 "codec %s can not start from non-off bias with idle_bias_off==1\n", in soc_probe_component()
1435 component->name); in soc_probe_component()
1448 component->driver->controls, in soc_probe_component()
1449 component->driver->num_controls); in soc_probe_component()
1454 component->driver->dapm_routes, in soc_probe_component()
1455 component->driver->num_dapm_routes); in soc_probe_component()
1457 if (card->disable_route_checks) { in soc_probe_component()
1458 dev_info(card->dev, in soc_probe_component()
1462 dev_err(card->dev, in soc_probe_component()
1470 list_add(&component->card_list, &card->component_dev_list); in soc_probe_component()
1500 dev_dbg(card->dev, in soc_probe_link_dais()
1502 card->name, rtd->num, order); in soc_probe_link_dais()
1523 if (component->driver->remove_order != order) in soc_remove_link_components()
1541 if (component->driver->probe_order != order) in soc_probe_link_components()
1561 list_del(&component->card_aux_list); in soc_unbind_aux_dev()
1573 component = soc_find_component(&aux->dlc); in soc_bind_aux_dev()
1575 return -EPROBE_DEFER; in soc_bind_aux_dev()
1580 list_add(&component->card_aux_list, &card->aux_comp_list); in soc_bind_aux_dev()
1593 if (component->driver->probe_order != order) in soc_probe_aux_devices()
1612 if (comp->driver->remove_order == order) in soc_remove_aux_devices()
1621 * "Type2 - Board Manufacturer" or "Type1 - TBD by OEM"), it will be taken
1635 * Trim special characters, and replace '-' with '_' since '-' is used to
1647 else if (name[i] == '-') in cleanup_dmi_name()
1672 * Append a string to card->dmi_longname with character cleanups.
1676 char *dst = card->dmi_longname; in append_dmi_string()
1677 size_t dst_len = sizeof(card->dmi_longname); in append_dmi_string()
1681 snprintf(dst + len, dst_len - len, "-%s", str); in append_dmi_string()
1683 len++; /* skip the separator "-" */ in append_dmi_string()
1689 * snd_soc_set_dmi_name() - Register DMI names to card
1697 * device-specific configurations, this function allows DMI info to be used
1699 * "vendor-product-version-board"
1700 * (Character '-' is used to separate different DMI fields here).
1701 * This will help the user space to load the device-specific Use Case Manager
1705 * DellInc.-XPS139343-01-0310JH
1706 * ASUSTeKCOMPUTERINC.-T100TA-1.0-T100TA
1707 * Circuitco-MinnowboardMaxD0PLATFORM-D0-MinnowBoardMAX
1710 * the extra differentiation, like "vendor-product-version-board-flavor".
1723 if (card->long_name) in snd_soc_set_dmi_name()
1729 /* make up dmi long name as: vendor-product-version-board */ in snd_soc_set_dmi_name()
1732 dev_warn(card->dev, "ASoC: no DMI vendor name!\n"); in snd_soc_set_dmi_name()
1736 snprintf(card->dmi_longname, sizeof(card->dmi_longname), "%s", vendor); in snd_soc_set_dmi_name()
1737 cleanup_dmi_name(card->dmi_longname); in snd_soc_set_dmi_name()
1746 * some vendors like Lenovo may only put a self-explanatory in snd_soc_set_dmi_name()
1759 dev_warn(card->dev, "ASoC: no DMI board/product name!\n"); in snd_soc_set_dmi_name()
1768 card->long_name = card->dmi_longname; in snd_soc_set_dmi_name()
1785 if (!component->driver->ignore_machine) in soc_check_tplg_fes()
1789 if (!strcmp(component->driver->ignore_machine, in soc_check_tplg_fes()
1790 card->dev->driver->name)) in soc_check_tplg_fes()
1792 if (strcmp(component->driver->ignore_machine, in soc_check_tplg_fes()
1793 dev_name(card->dev))) in soc_check_tplg_fes()
1800 if (dai_link->dynamic) { in soc_check_tplg_fes()
1801 dai_link->ignore = true; in soc_check_tplg_fes()
1805 dev_dbg(card->dev, "info: override BE DAI link %s\n", in soc_check_tplg_fes()
1806 card->dai_link[i].name); in soc_check_tplg_fes()
1809 if (!dai_link->platforms) { in soc_check_tplg_fes()
1810 dev_err(card->dev, "init platform error"); in soc_check_tplg_fes()
1814 if (component->dev->of_node) in soc_check_tplg_fes()
1815 dai_link->platforms->of_node = component->dev->of_node; in soc_check_tplg_fes()
1817 dai_link->platforms->name = component->name; in soc_check_tplg_fes()
1820 if (!dai_link->no_pcm) { in soc_check_tplg_fes()
1821 dai_link->no_pcm = 1; in soc_check_tplg_fes()
1823 if (dai_link->dpcm_playback) in soc_check_tplg_fes()
1824 dev_warn(card->dev, in soc_check_tplg_fes()
1826 dai_link->name); in soc_check_tplg_fes()
1827 if (dai_link->dpcm_capture) in soc_check_tplg_fes()
1828 dev_warn(card->dev, in soc_check_tplg_fes()
1830 dai_link->name); in soc_check_tplg_fes()
1833 if (!(dai_link->dpcm_playback || in soc_check_tplg_fes()
1834 dai_link->dpcm_capture)) { in soc_check_tplg_fes()
1835 dai_link->dpcm_playback = !dai_link->capture_only; in soc_check_tplg_fes()
1836 dai_link->dpcm_capture = !dai_link->playback_only; in soc_check_tplg_fes()
1845 dai_link->be_hw_params_fixup = in soc_check_tplg_fes()
1846 component->driver->be_hw_params_fixup; in soc_check_tplg_fes()
1852 if (!dai_link->stream_name) in soc_check_tplg_fes()
1853 dai_link->stream_name = dai_link->name; in soc_check_tplg_fes()
1856 /* Inform userspace we are using alternate topology */ in soc_check_tplg_fes()
1857 if (component->driver->topology_name_prefix) { in soc_check_tplg_fes()
1859 /* topology shortname created? */ in soc_check_tplg_fes()
1860 if (!card->topology_shortname_created) { in soc_check_tplg_fes()
1861 comp_drv = component->driver; in soc_check_tplg_fes()
1863 snprintf(card->topology_shortname, 32, "%s-%s", in soc_check_tplg_fes()
1864 comp_drv->topology_name_prefix, in soc_check_tplg_fes()
1865 card->name); in soc_check_tplg_fes()
1866 card->topology_shortname_created = true; in soc_check_tplg_fes()
1869 /* use topology shortname */ in soc_check_tplg_fes()
1870 card->name = card->topology_shortname; in soc_check_tplg_fes()
1892 * searches in the user-space. in __soc_setup_card_name()
1895 * "abcd??efg" -> "abcd__efg" in __soc_setup_card_name()
1900 case '-': in __soc_setup_card_name()
1915 if (card->snd_card) in soc_cleanup_card_resources()
1916 snd_card_disconnect_sync(card->snd_card); in soc_cleanup_card_resources()
1931 snd_soc_dapm_free(&card->dapm); in soc_cleanup_card_resources()
1937 if (card->snd_card) { in soc_cleanup_card_resources()
1938 snd_card_free(card->snd_card); in soc_cleanup_card_resources()
1939 card->snd_card = NULL; in soc_cleanup_card_resources()
1945 if (card->instantiated) { in snd_soc_unbind_card()
1946 card->instantiated = false; in snd_soc_unbind_card()
1951 list_add(&card->list, &unbind_card_list); in snd_soc_unbind_card()
1954 list_del(&card->list); in snd_soc_unbind_card()
1966 mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT); in snd_soc_bind_card()
1968 snd_soc_dapm_init(&card->dapm, card, NULL); in snd_soc_bind_card()
1970 /* check whether any platform is ignore machine FE and using topology */ in snd_soc_bind_card()
1979 card->num_rtd = 0; in snd_soc_bind_card()
1987 ret = snd_card_new(card->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, in snd_soc_bind_card()
1988 card->owner, 0, &card->snd_card); in snd_soc_bind_card()
1990 dev_err(card->dev, in snd_soc_bind_card()
1992 card->name, ret); in snd_soc_bind_card()
2000 ret = snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets, in snd_soc_bind_card()
2001 card->num_dapm_widgets); in snd_soc_bind_card()
2005 ret = snd_soc_dapm_new_controls(&card->dapm, card->of_dapm_widgets, in snd_soc_bind_card()
2006 card->num_of_dapm_widgets); in snd_soc_bind_card()
2018 dev_err(card->dev, in snd_soc_bind_card()
2026 dev_err(card->dev, in snd_soc_bind_card()
2034 dev_err(card->dev, in snd_soc_bind_card()
2048 ret = snd_soc_add_card_controls(card, card->controls, in snd_soc_bind_card()
2049 card->num_controls); in snd_soc_bind_card()
2053 ret = snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes, in snd_soc_bind_card()
2054 card->num_dapm_routes); in snd_soc_bind_card()
2056 if (card->disable_route_checks) { in snd_soc_bind_card()
2057 dev_info(card->dev, in snd_soc_bind_card()
2061 dev_err(card->dev, in snd_soc_bind_card()
2068 ret = snd_soc_dapm_add_routes(&card->dapm, card->of_dapm_routes, in snd_soc_bind_card()
2069 card->num_of_dapm_routes); in snd_soc_bind_card()
2076 soc_setup_card_name(card->snd_card->shortname, in snd_soc_bind_card()
2077 card->name, NULL, 0); in snd_soc_bind_card()
2078 soc_setup_card_name(card->snd_card->longname, in snd_soc_bind_card()
2079 card->long_name, card->name, 0); in snd_soc_bind_card()
2080 soc_setup_card_name(card->snd_card->driver, in snd_soc_bind_card()
2081 card->driver_name, card->name, 1); in snd_soc_bind_card()
2083 if (card->components) { in snd_soc_bind_card()
2088 ret = snd_component_add(card->snd_card, card->components); in snd_soc_bind_card()
2090 dev_err(card->dev, "ASoC: %s snd_component_add() failed: %d\n", in snd_soc_bind_card()
2091 card->name, ret); in snd_soc_bind_card()
2102 ret = snd_card_register(card->snd_card); in snd_soc_bind_card()
2104 dev_err(card->dev, "ASoC: failed to register soundcard %d\n", in snd_soc_bind_card()
2109 card->instantiated = 1; in snd_soc_bind_card()
2111 snd_soc_dapm_sync(&card->dapm); in snd_soc_bind_card()
2116 pinctrl_pm_select_sleep_state(component->dev); in snd_soc_bind_card()
2122 mutex_unlock(&card->mutex); in snd_soc_bind_card()
2138 return -EINVAL; in soc_probe()
2140 dev_warn(&pdev->dev, in soc_probe()
2142 card->name); in soc_probe()
2145 card->dev = &pdev->dev; in soc_probe()
2147 return devm_snd_soc_register_card(&pdev->dev, card); in soc_probe()
2155 if (!card->instantiated) in snd_soc_poweroff()
2159 * Flush out pmdown_time work - we actually do want to run it in snd_soc_poweroff()
2168 pinctrl_pm_select_sleep_state(component->dev); in snd_soc_poweroff()
2187 .name = "soc-audio",
2194 * snd_soc_cnew - create new control
2245 control->name, prefix)); in snd_soc_add_controls()
2248 control->name, err); in snd_soc_add_controls()
2257 * snd_soc_add_component_controls - Add an array of controls to a component.
2268 struct snd_card *card = component->card->snd_card; in snd_soc_add_component_controls()
2270 return snd_soc_add_controls(card, component->dev, controls, in snd_soc_add_component_controls()
2271 num_controls, component->name_prefix, component); in snd_soc_add_component_controls()
2276 * snd_soc_add_card_controls - add an array of controls to a SoC card.
2288 struct snd_card *card = soc_card->snd_card; in snd_soc_add_card_controls()
2290 return snd_soc_add_controls(card, soc_card->dev, controls, num_controls, in snd_soc_add_card_controls()
2296 * snd_soc_add_dai_controls - add an array of controls to a DAI.
2308 struct snd_card *card = dai->component->card->snd_card; in snd_soc_add_dai_controls()
2310 return snd_soc_add_controls(card, dai->dev, controls, num_controls, in snd_soc_add_dai_controls()
2316 * snd_soc_register_card - Register a card with the ASoC core
2323 if (!card->name || !card->dev) in snd_soc_register_card()
2324 return -EINVAL; in snd_soc_register_card()
2326 dev_set_drvdata(card->dev, card); in snd_soc_register_card()
2328 INIT_LIST_HEAD(&card->widgets); in snd_soc_register_card()
2329 INIT_LIST_HEAD(&card->paths); in snd_soc_register_card()
2330 INIT_LIST_HEAD(&card->dapm_list); in snd_soc_register_card()
2331 INIT_LIST_HEAD(&card->aux_comp_list); in snd_soc_register_card()
2332 INIT_LIST_HEAD(&card->component_dev_list); in snd_soc_register_card()
2333 INIT_LIST_HEAD(&card->list); in snd_soc_register_card()
2334 INIT_LIST_HEAD(&card->rtd_list); in snd_soc_register_card()
2335 INIT_LIST_HEAD(&card->dapm_dirty); in snd_soc_register_card()
2336 INIT_LIST_HEAD(&card->dobj_list); in snd_soc_register_card()
2338 card->instantiated = 0; in snd_soc_register_card()
2339 mutex_init(&card->mutex); in snd_soc_register_card()
2340 mutex_init(&card->dapm_mutex); in snd_soc_register_card()
2341 mutex_init(&card->pcm_mutex); in snd_soc_register_card()
2342 spin_lock_init(&card->dpcm_lock); in snd_soc_register_card()
2349 * snd_soc_unregister_card - Unregister a card with the ASoC core
2359 dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name); in snd_soc_unregister_card()
2366 * Simplify DAI link configuration by removing ".-1" from device names
2383 found = strstr(name, dev->driver->name); in fmt_single_name()
2386 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) { in fmt_single_name()
2388 /* discard ID from name if ID == -1 */ in fmt_single_name()
2389 if (*id == -1) in fmt_single_name()
2390 found[strlen(dev->driver->name)] = '\0'; in fmt_single_name()
2393 /* I2C component devices are named "bus-addr" */ in fmt_single_name()
2394 } else if (sscanf(name, "%x-%x", &id1, &id2) == 2) { in fmt_single_name()
2396 /* create unique ID number from I2C addr and bus */ in fmt_single_name()
2402 name = devm_kasprintf(dev, GFP_KERNEL, "%s.%s", dev->driver->name, devname); in fmt_single_name()
2412 * any ".-1" and using the DAI name (instead of device name).
2417 if (dai_drv->name == NULL) { in fmt_multiple_name()
2419 "ASoC: error - multiple DAI %s registered with no name\n", in fmt_multiple_name()
2424 return devm_kstrdup(dev, dai_drv->name, GFP_KERNEL); in fmt_multiple_name()
2429 dev_dbg(dai->dev, "ASoC: Unregistered DAI '%s'\n", dai->name); in snd_soc_unregister_dai()
2430 list_del(&dai->list); in snd_soc_unregister_dai()
2435 * snd_soc_register_dai - Register a DAI dynamically & create its widgets
2439 * @legacy_dai_naming: if %true, use legacy single-name format;
2440 * if %false, use multiple-name format;
2442 * Topology can use this API to register DAIs when probing a component.
2450 struct device *dev = component->dev; in snd_soc_register_dai()
2462 * Back in the old days when we still had component-less DAIs, in snd_soc_register_dai()
2463 * instead of having a static name, component-less DAIs would in snd_soc_register_dai()
2467 * component-less anymore. in snd_soc_register_dai()
2470 (dai_drv->id == 0 || dai_drv->name == NULL)) { in snd_soc_register_dai()
2471 dai->name = fmt_single_name(dev, &dai->id); in snd_soc_register_dai()
2473 dai->name = fmt_multiple_name(dev, dai_drv); in snd_soc_register_dai()
2474 if (dai_drv->id) in snd_soc_register_dai()
2475 dai->id = dai_drv->id; in snd_soc_register_dai()
2477 dai->id = component->num_dai; in snd_soc_register_dai()
2479 if (!dai->name) in snd_soc_register_dai()
2482 dai->component = component; in snd_soc_register_dai()
2483 dai->dev = dev; in snd_soc_register_dai()
2484 dai->driver = dai_drv; in snd_soc_register_dai()
2487 list_add_tail(&dai->list, &component->dai_list); in snd_soc_register_dai()
2488 component->num_dai++; in snd_soc_register_dai()
2490 dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name); in snd_soc_register_dai()
2495 * snd_soc_unregister_dais - Unregister DAIs from the ASoC core
2508 * snd_soc_register_dais - Register a DAI with the ASoC core
2524 !component->driver->non_legacy_dai_naming); in snd_soc_register_dais()
2526 ret = -ENOMEM; in snd_soc_register_dais()
2570 if (stream->formats & endianness_format_map[i]) in convert_endianness_formats()
2571 stream->formats |= endianness_format_map[i]; in convert_endianness_formats()
2580 list_del(&card->list); in snd_soc_try_rebind_card()
2585 struct snd_soc_card *card = component->card; in snd_soc_del_component_unlocked()
2592 list_del(&component->list); in snd_soc_del_component_unlocked()
2599 INIT_LIST_HEAD(&component->dai_list); in snd_soc_component_initialize()
2600 INIT_LIST_HEAD(&component->dobj_list); in snd_soc_component_initialize()
2601 INIT_LIST_HEAD(&component->card_list); in snd_soc_component_initialize()
2602 INIT_LIST_HEAD(&component->list); in snd_soc_component_initialize()
2603 mutex_init(&component->io_mutex); in snd_soc_component_initialize()
2605 component->name = fmt_single_name(dev, &component->id); in snd_soc_component_initialize()
2606 if (!component->name) { in snd_soc_component_initialize()
2608 return -ENOMEM; in snd_soc_component_initialize()
2611 component->dev = dev; in snd_soc_component_initialize()
2612 component->driver = driver; in snd_soc_component_initialize()
2627 if (component->driver->endianness) { in snd_soc_add_component()
2636 dev_err(component->dev, "ASoC: Failed to register DAIs: %d\n", in snd_soc_add_component()
2641 if (!component->driver->write && !component->driver->read) { in snd_soc_add_component()
2642 if (!component->regmap) in snd_soc_add_component()
2643 component->regmap = dev_get_regmap(component->dev, in snd_soc_add_component()
2645 if (component->regmap) in snd_soc_add_component()
2650 list_add(&component->list, &component_list); in snd_soc_add_component()
2675 return -ENOMEM; in snd_soc_register_component()
2686 * snd_soc_unregister_component_by_driver - Unregister component using a given driver
2701 component = snd_soc_lookup_component_nolocked(dev, component_driver->name); in snd_soc_unregister_component_by_driver()
2713 * snd_soc_unregister_component - Unregister all related component
2740 if (!card->dev) { in snd_soc_of_parse_card_name()
2741 pr_err("card->dev is not set before calling %s\n", __func__); in snd_soc_of_parse_card_name()
2742 return -EINVAL; in snd_soc_of_parse_card_name()
2745 np = card->dev->of_node; in snd_soc_of_parse_card_name()
2747 ret = of_property_read_string_index(np, propname, 0, &card->name); in snd_soc_of_parse_card_name()
2750 * card->name was previously set, which is checked later in in snd_soc_of_parse_card_name()
2753 if (ret < 0 && ret != -EINVAL) { in snd_soc_of_parse_card_name()
2754 dev_err(card->dev, in snd_soc_of_parse_card_name()
2774 struct device_node *np = card->dev->of_node; in snd_soc_of_parse_audio_simple_widgets()
2781 dev_err(card->dev, in snd_soc_of_parse_audio_simple_widgets()
2783 return -EINVAL; in snd_soc_of_parse_audio_simple_widgets()
2786 dev_err(card->dev, in snd_soc_of_parse_audio_simple_widgets()
2788 return -EINVAL; in snd_soc_of_parse_audio_simple_widgets()
2793 dev_err(card->dev, "ASoC: Property '%s's length is zero\n", in snd_soc_of_parse_audio_simple_widgets()
2795 return -EINVAL; in snd_soc_of_parse_audio_simple_widgets()
2798 widgets = devm_kcalloc(card->dev, num_widgets, sizeof(*widgets), in snd_soc_of_parse_audio_simple_widgets()
2801 dev_err(card->dev, in snd_soc_of_parse_audio_simple_widgets()
2803 return -ENOMEM; in snd_soc_of_parse_audio_simple_widgets()
2810 dev_err(card->dev, in snd_soc_of_parse_audio_simple_widgets()
2813 return -EINVAL; in snd_soc_of_parse_audio_simple_widgets()
2825 dev_err(card->dev, in snd_soc_of_parse_audio_simple_widgets()
2828 return -EINVAL; in snd_soc_of_parse_audio_simple_widgets()
2835 dev_err(card->dev, in snd_soc_of_parse_audio_simple_widgets()
2838 return -EINVAL; in snd_soc_of_parse_audio_simple_widgets()
2844 card->of_dapm_widgets = widgets; in snd_soc_of_parse_audio_simple_widgets()
2845 card->num_of_dapm_widgets = num_widgets; in snd_soc_of_parse_audio_simple_widgets()
2880 snd_soc_of_get_slot_mask(np, "dai-tdm-slot-tx-mask", tx_mask); in snd_soc_of_parse_tdm_slot()
2882 snd_soc_of_get_slot_mask(np, "dai-tdm-slot-rx-mask", rx_mask); in snd_soc_of_parse_tdm_slot()
2884 if (of_property_read_bool(np, "dai-tdm-slot-num")) { in snd_soc_of_parse_tdm_slot()
2885 ret = of_property_read_u32(np, "dai-tdm-slot-num", &val); in snd_soc_of_parse_tdm_slot()
2893 if (of_property_read_bool(np, "dai-tdm-slot-width")) { in snd_soc_of_parse_tdm_slot()
2894 ret = of_property_read_u32(np, "dai-tdm-slot-width", &val); in snd_soc_of_parse_tdm_slot()
2920 codec_conf->dlc.of_node = of_node; in snd_soc_of_parse_node_prefix()
2921 codec_conf->name_prefix = str; in snd_soc_of_parse_node_prefix()
2928 struct device_node *np = card->dev->of_node; in snd_soc_of_parse_audio_routing()
2935 dev_err(card->dev, in snd_soc_of_parse_audio_routing()
2938 return -EINVAL; in snd_soc_of_parse_audio_routing()
2942 routes = devm_kcalloc(card->dev, num_routes, sizeof(*routes), in snd_soc_of_parse_audio_routing()
2945 dev_err(card->dev, in snd_soc_of_parse_audio_routing()
2947 return -ENOMEM; in snd_soc_of_parse_audio_routing()
2954 dev_err(card->dev, in snd_soc_of_parse_audio_routing()
2957 return -EINVAL; in snd_soc_of_parse_audio_routing()
2962 dev_err(card->dev, in snd_soc_of_parse_audio_routing()
2965 return -EINVAL; in snd_soc_of_parse_audio_routing()
2969 card->num_of_dapm_routes = num_routes; in snd_soc_of_parse_audio_routing()
2970 card->of_dapm_routes = routes; in snd_soc_of_parse_audio_routing()
2978 struct device_node *node = card->dev->of_node; in snd_soc_of_parse_aux_devs()
2983 if (num == -ENOENT) { in snd_soc_of_parse_aux_devs()
2986 dev_err(card->dev, "ASOC: Property '%s' could not be read: %d\n", in snd_soc_of_parse_aux_devs()
2991 aux = devm_kcalloc(card->dev, num, sizeof(*aux), GFP_KERNEL); in snd_soc_of_parse_aux_devs()
2993 return -ENOMEM; in snd_soc_of_parse_aux_devs()
2994 card->aux_dev = aux; in snd_soc_of_parse_aux_devs()
2995 card->num_aux_devs = num; in snd_soc_of_parse_aux_devs()
2998 aux->dlc.of_node = of_parse_phandle(node, propname, i); in snd_soc_of_parse_aux_devs()
2999 if (!aux->dlc.of_node) in snd_soc_of_parse_aux_devs()
3000 return -EINVAL; in snd_soc_of_parse_aux_devs()
3080 * check "dai-format = xxx" in snd_soc_daifmt_parse_format()
3084 ret = of_property_read_string(np, "dai-format", &str); in snd_soc_daifmt_parse_format()
3101 * check "[prefix]continuous-clock" in snd_soc_daifmt_parse_format()
3104 snprintf(prop, sizeof(prop), "%scontinuous-clock", prefix); in snd_soc_daifmt_parse_format()
3111 * check "[prefix]bitclock-inversion" in snd_soc_daifmt_parse_format()
3112 * check "[prefix]frame-inversion" in snd_soc_daifmt_parse_format()
3115 snprintf(prop, sizeof(prop), "%sbitclock-inversion", prefix); in snd_soc_daifmt_parse_format()
3118 snprintf(prop, sizeof(prop), "%sframe-inversion", prefix); in snd_soc_daifmt_parse_format()
3152 * check "[prefix]bitclock-master" in snd_soc_daifmt_parse_clock_provider_raw()
3153 * check "[prefix]frame-master" in snd_soc_daifmt_parse_clock_provider_raw()
3155 snprintf(prop, sizeof(prop), "%sbitclock-master", prefix); in snd_soc_daifmt_parse_clock_provider_raw()
3160 snprintf(prop, sizeof(prop), "%sframe-master", prefix); in snd_soc_daifmt_parse_clock_provider_raw()
3188 ret = -ENOTSUPP; in snd_soc_get_dai_id()
3205 int ret = -EPROBE_DEFER; in snd_soc_get_dai_name()
3211 if (component_of_node != args->np) in snd_soc_get_dai_name()
3215 if (ret == -ENOTSUPP) { in snd_soc_get_dai_name()
3217 int id = -1; in snd_soc_get_dai_name()
3219 switch (args->args_count) { in snd_soc_get_dai_name()
3224 id = args->args[0]; in snd_soc_get_dai_name()
3231 if (id < 0 || id >= pos->num_dai) { in snd_soc_get_dai_name()
3232 ret = -EINVAL; in snd_soc_get_dai_name()
3242 id--; in snd_soc_get_dai_name()
3245 *dai_name = dai->driver->name; in snd_soc_get_dai_name()
3247 *dai_name = pos->name; in snd_soc_get_dai_name()
3271 ret = of_parse_phandle_with_args(of_node, "sound-dai", in snd_soc_of_get_dai_name()
3272 "#sound-dai-cells", 0, &args); in snd_soc_of_get_dai_name()
3285 * snd_soc_of_put_dai_link_codecs - Dereference device nodes in the codecs array
3296 if (!component->of_node) in snd_soc_of_put_dai_link_codecs()
3298 of_node_put(component->of_node); in snd_soc_of_put_dai_link_codecs()
3299 component->of_node = NULL; in snd_soc_of_put_dai_link_codecs()
3305 * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree
3311 * 'sound-dai'.
3328 name = "sound-dai"; in snd_soc_of_get_dai_link_codecs()
3330 "#sound-dai-cells"); in snd_soc_of_get_dai_link_codecs()
3332 if (num_codecs == -ENOENT) in snd_soc_of_get_dai_link_codecs()
3333 dev_err(dev, "No 'sound-dai' property\n"); in snd_soc_of_get_dai_link_codecs()
3335 dev_err(dev, "Bad phandle in 'sound-dai'\n"); in snd_soc_of_get_dai_link_codecs()
3342 return -ENOMEM; in snd_soc_of_get_dai_link_codecs()
3343 dai_link->codecs = component; in snd_soc_of_get_dai_link_codecs()
3344 dai_link->num_codecs = num_codecs; in snd_soc_of_get_dai_link_codecs()
3349 "#sound-dai-cells", in snd_soc_of_get_dai_link_codecs()
3353 component->of_node = args.np; in snd_soc_of_get_dai_link_codecs()
3354 ret = snd_soc_get_dai_name(&args, &component->dai_name); in snd_soc_of_get_dai_link_codecs()
3361 dai_link->codecs = NULL; in snd_soc_of_get_dai_link_codecs()
3362 dai_link->num_codecs = 0; in snd_soc_of_get_dai_link_codecs()
3389 MODULE_ALIAS("platform:soc-audio");