Lines Matching +full:warn +full:- +full:soc +full:- +full:level

1 // SPDX-License-Identifier: GPL-2.0+
3 // soc-dapm.c -- ALSA SoC Dynamic Audio Power Management
12 // o Platform power domain - can support external components i.e. amps and
15 // o Jack insertion power event initiation - e.g. hp insertion will enable
37 #include <sound/soc.h>
42 #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++;
67 /* dapm power sequences - make this per codec in the future */
152 if (dapm->card && dapm->card->instantiated) in dapm_assert_locked()
153 lockdep_assert_held(&dapm->card->dapm_mutex); in dapm_assert_locked()
185 return !list_empty(&w->dirty); in dapm_dirty_widget()
190 dapm_assert_locked(w->dapm); in dapm_mark_dirty()
193 dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n", in dapm_mark_dirty()
194 w->name, reason); in dapm_mark_dirty()
195 list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty); in dapm_mark_dirty()
214 dapm_assert_locked(w->dapm); in dapm_widget_invalidate_paths()
216 if (w->endpoints[dir] == -1) in dapm_widget_invalidate_paths()
219 list_add_tail(&w->work_list, &list); in dapm_widget_invalidate_paths()
220 w->endpoints[dir] = -1; in dapm_widget_invalidate_paths()
224 if (p->is_supply || p->weak || !p->connect) in dapm_widget_invalidate_paths()
226 node = p->node[rdir]; in dapm_widget_invalidate_paths()
227 if (node->endpoints[dir] != -1) { in dapm_widget_invalidate_paths()
228 node->endpoints[dir] = -1; in dapm_widget_invalidate_paths()
229 list_add_tail(&node->work_list, &list); in dapm_widget_invalidate_paths()
236 * dapm_widget_invalidate_input_paths() - Invalidate the cached number of
253 * dapm_widget_invalidate_output_paths() - Invalidate the cached number of
270 * dapm_path_invalidate() - Invalidates the cached number of inputs and outputs
286 if (p->weak || p->is_supply) in dapm_path_invalidate()
293 * so there is no need to re-check the path. in dapm_path_invalidate()
295 if (p->source->endpoints[SND_SOC_DAPM_DIR_IN] != 0) in dapm_path_invalidate()
296 dapm_widget_invalidate_input_paths(p->sink); in dapm_path_invalidate()
297 if (p->sink->endpoints[SND_SOC_DAPM_DIR_OUT] != 0) in dapm_path_invalidate()
298 dapm_widget_invalidate_output_paths(p->source); in dapm_path_invalidate()
305 mutex_lock(&card->dapm_mutex); in dapm_mark_endpoints_dirty()
308 if (w->is_ep) { in dapm_mark_endpoints_dirty()
310 if (w->is_ep & SND_SOC_DAPM_EP_SINK) in dapm_mark_endpoints_dirty()
312 if (w->is_ep & SND_SOC_DAPM_EP_SOURCE) in dapm_mark_endpoints_dirty()
317 mutex_unlock(&card->dapm_mutex); in dapm_mark_endpoints_dirty()
332 * w->name is duplicated in caller, but w->sname isn't. in dapm_cnew_widget()
335 if (_widget->sname) { in dapm_cnew_widget()
336 w->sname = kstrdup_const(_widget->sname, GFP_KERNEL); in dapm_cnew_widget()
337 if (!w->sname) { in dapm_cnew_widget()
363 return -ENOMEM; in dapm_kcontrol_data_alloc()
365 INIT_LIST_HEAD(&data->paths); in dapm_kcontrol_data_alloc()
367 switch (widget->id) { in dapm_kcontrol_data_alloc()
371 mc = (struct soc_mixer_control *)kcontrol->private_value; in dapm_kcontrol_data_alloc()
373 if (mc->autodisable) { in dapm_kcontrol_data_alloc()
377 dev_warn(widget->dapm->dev, in dapm_kcontrol_data_alloc()
384 ret = -ENOMEM; in dapm_kcontrol_data_alloc()
389 template.reg = mc->reg; in dapm_kcontrol_data_alloc()
390 template.mask = (1 << fls(mc->max)) - 1; in dapm_kcontrol_data_alloc()
391 template.shift = mc->shift; in dapm_kcontrol_data_alloc()
392 if (mc->invert) in dapm_kcontrol_data_alloc()
393 template.off_val = mc->max; in dapm_kcontrol_data_alloc()
400 data->value = template.on_val; in dapm_kcontrol_data_alloc()
402 data->widget = in dapm_kcontrol_data_alloc()
403 snd_soc_dapm_new_control_unlocked(widget->dapm, in dapm_kcontrol_data_alloc()
406 if (IS_ERR(data->widget)) { in dapm_kcontrol_data_alloc()
407 ret = PTR_ERR(data->widget); in dapm_kcontrol_data_alloc()
414 e = (struct soc_enum *)kcontrol->private_value; in dapm_kcontrol_data_alloc()
416 if (e->autodisable) { in dapm_kcontrol_data_alloc()
422 ret = -ENOMEM; in dapm_kcontrol_data_alloc()
427 template.reg = e->reg; in dapm_kcontrol_data_alloc()
428 template.mask = e->mask; in dapm_kcontrol_data_alloc()
429 template.shift = e->shift_l; in dapm_kcontrol_data_alloc()
435 data->value = template.on_val; in dapm_kcontrol_data_alloc()
437 data->widget = snd_soc_dapm_new_control_unlocked( in dapm_kcontrol_data_alloc()
438 widget->dapm, &template); in dapm_kcontrol_data_alloc()
440 if (IS_ERR(data->widget)) { in dapm_kcontrol_data_alloc()
441 ret = PTR_ERR(data->widget); in dapm_kcontrol_data_alloc()
445 snd_soc_dapm_add_path(widget->dapm, data->widget, in dapm_kcontrol_data_alloc()
447 } else if (e->reg != SND_SOC_NOPM) { in dapm_kcontrol_data_alloc()
448 data->value = soc_dapm_read(widget->dapm, e->reg) & in dapm_kcontrol_data_alloc()
449 (e->mask << e->shift_l); in dapm_kcontrol_data_alloc()
456 kcontrol->private_data = data; in dapm_kcontrol_data_alloc()
469 list_del(&data->paths); in dapm_kcontrol_free()
470 kfree(data->wlist); in dapm_kcontrol_free()
479 return data->wlist; in dapm_kcontrol_get_wlist()
489 if (data->wlist) in dapm_kcontrol_add_widget()
490 n = data->wlist->num_widgets + 1; in dapm_kcontrol_add_widget()
494 new_wlist = krealloc(data->wlist, in dapm_kcontrol_add_widget()
498 return -ENOMEM; in dapm_kcontrol_add_widget()
500 new_wlist->widgets[n - 1] = widget; in dapm_kcontrol_add_widget()
501 new_wlist->num_widgets = n; in dapm_kcontrol_add_widget()
503 data->wlist = new_wlist; in dapm_kcontrol_add_widget()
513 list_add_tail(&path->list_kcontrol, &data->paths); in dapm_kcontrol_add_path()
520 if (!data->widget) in dapm_kcontrol_is_powered()
523 return data->widget->power; in dapm_kcontrol_is_powered()
531 return &data->paths; in dapm_kcontrol_get_path_list()
542 return data->value; in dapm_kcontrol_get_value()
551 if (data->value == value) in dapm_kcontrol_set_value()
554 if (data->widget) { in dapm_kcontrol_set_value()
555 switch (dapm_kcontrol_get_wlist(kcontrol)->widgets[0]->id) { in dapm_kcontrol_set_value()
559 data->widget->on_val = value & data->widget->mask; in dapm_kcontrol_set_value()
563 data->widget->on_val = value >> data->widget->shift; in dapm_kcontrol_set_value()
566 data->widget->on_val = value; in dapm_kcontrol_set_value()
571 data->value = value; in dapm_kcontrol_set_value()
577 * snd_soc_dapm_kcontrol_widget() - Returns the widget associated to a
584 return dapm_kcontrol_get_wlist(kcontrol)->widgets[0]; in snd_soc_dapm_kcontrol_widget()
589 * snd_soc_dapm_kcontrol_dapm() - Returns the dapm context associated to a
599 return dapm_kcontrol_get_wlist(kcontrol)->widgets[0]->dapm; in snd_soc_dapm_kcontrol_dapm()
607 lockdep_assert_held(&card->dapm_mutex); in dapm_reset()
609 memset(&card->dapm_stats, 0, sizeof(card->dapm_stats)); in dapm_reset()
612 w->new_power = w->power; in dapm_reset()
613 w->power_checked = false; in dapm_reset()
619 if (!dapm->component) in soc_dapm_prefix()
621 return dapm->component->name_prefix; in soc_dapm_prefix()
626 if (!dapm->component) in soc_dapm_read()
627 return -EIO; in soc_dapm_read()
628 return snd_soc_component_read(dapm->component, reg); in soc_dapm_read()
634 if (!dapm->component) in soc_dapm_update_bits()
635 return -EIO; in soc_dapm_update_bits()
636 return snd_soc_component_update_bits(dapm->component, reg, in soc_dapm_update_bits()
643 if (!dapm->component) in soc_dapm_test_bits()
644 return -EIO; in soc_dapm_test_bits()
645 return snd_soc_component_test_bits(dapm->component, reg, mask, value); in soc_dapm_test_bits()
650 if (dapm->component) in soc_dapm_async_complete()
651 snd_soc_component_async_complete(dapm->component); in soc_dapm_async_complete()
657 struct snd_soc_dapm_widget *w = wcache->widget; in dapm_wcache_lookup()
660 struct list_head *wlist = &w->dapm->card->widgets; in dapm_wcache_lookup()
665 if (!strcmp(name, w->name)) in dapm_wcache_lookup()
679 wcache->widget = w; in dapm_wcache_update()
683 * snd_soc_dapm_force_bias_level() - Sets the DAPM bias level
684 * @dapm: The DAPM context for which to set the level
685 * @level: The level to set
687 * Forces the DAPM bias level to a specific state. It will call the bias level
688 * callback of DAPM context with the specified level. This will even happen if
689 * the context is already at the same level. Furthermore it will not go through
690 * the normal bias level sequencing, meaning any intermediate states between the
693 * Note that the change in bias level is only temporary and the next time
694 * snd_soc_dapm_sync() is called the state will be set to the level as
700 enum snd_soc_bias_level level) in snd_soc_dapm_force_bias_level() argument
704 if (dapm->component) in snd_soc_dapm_force_bias_level()
705 ret = snd_soc_component_set_bias_level(dapm->component, level); in snd_soc_dapm_force_bias_level()
708 dapm->bias_level = level; in snd_soc_dapm_force_bias_level()
715 * snd_soc_dapm_set_bias_level - set the bias level for the system
717 * @level: level to configure
719 * Configure the bias (power) levels for the SoC audio device.
724 enum snd_soc_bias_level level) in snd_soc_dapm_set_bias_level() argument
726 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_set_bias_level()
729 trace_snd_soc_bias_level_start(card, level); in snd_soc_dapm_set_bias_level()
731 ret = snd_soc_card_set_bias_level(card, dapm, level); in snd_soc_dapm_set_bias_level()
735 if (!card || dapm != &card->dapm) in snd_soc_dapm_set_bias_level()
736 ret = snd_soc_dapm_force_bias_level(dapm, level); in snd_soc_dapm_set_bias_level()
741 ret = snd_soc_card_set_bias_level_post(card, dapm, level); in snd_soc_dapm_set_bias_level()
743 trace_snd_soc_bias_level_done(card, level); in snd_soc_dapm_set_bias_level()
753 const struct snd_kcontrol_new *kcontrol = &w->kcontrol_news[0]; in dapm_connect_mux()
754 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in dapm_connect_mux()
758 if (e->reg != SND_SOC_NOPM) { in dapm_connect_mux()
760 val = soc_dapm_read(dapm, e->reg); in dapm_connect_mux()
761 val = (val >> e->shift_l) & e->mask; in dapm_connect_mux()
773 i = match_string(e->texts, e->items, control_name); in dapm_connect_mux()
775 return -ENODEV; in dapm_connect_mux()
777 path->name = e->texts[i]; in dapm_connect_mux()
778 path->connect = (i == item); in dapm_connect_mux()
788 p->sink->kcontrol_news[i].private_value; in dapm_set_mixer_path_status()
789 unsigned int reg = mc->reg; in dapm_set_mixer_path_status()
790 unsigned int invert = mc->invert; in dapm_set_mixer_path_status()
793 unsigned int shift = mc->shift; in dapm_set_mixer_path_status()
794 unsigned int max = mc->max; in dapm_set_mixer_path_status()
795 unsigned int mask = (1 << fls(max)) - 1; in dapm_set_mixer_path_status()
796 unsigned int val = soc_dapm_read(p->sink->dapm, reg); in dapm_set_mixer_path_status()
811 if (reg != mc->rreg) in dapm_set_mixer_path_status()
812 val = soc_dapm_read(p->sink->dapm, mc->rreg); in dapm_set_mixer_path_status()
813 val = (val >> mc->rshift) & mask; in dapm_set_mixer_path_status()
818 val = max - val; in dapm_set_mixer_path_status()
819 p->connect = !!val; in dapm_set_mixer_path_status()
827 p->connect = invert; in dapm_set_mixer_path_status()
838 for (i = 0; i < path->sink->num_kcontrols; i++) { in dapm_connect_mixer()
839 if (!strcmp(control_name, path->sink->kcontrol_news[i].name)) { in dapm_connect_mixer()
840 path->name = path->sink->kcontrol_news[i].name; in dapm_connect_mixer()
845 return -ENODEV; in dapm_connect_mixer()
858 for_each_card_widgets(dapm->card, w) { in dapm_is_shared_kcontrol()
859 if (w == kcontrolw || w->dapm != kcontrolw->dapm) in dapm_is_shared_kcontrol()
861 for (i = 0; i < w->num_kcontrols; i++) { in dapm_is_shared_kcontrol()
862 if (&w->kcontrol_news[i] == kcontrol_new) { in dapm_is_shared_kcontrol()
863 if (w->kcontrols) in dapm_is_shared_kcontrol()
864 *kcontrol = w->kcontrols[i]; in dapm_is_shared_kcontrol()
880 struct snd_soc_dapm_context *dapm = w->dapm; in dapm_create_or_share_kcontrol()
881 struct snd_card *card = dapm->card->snd_card; in dapm_create_or_share_kcontrol()
897 shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[kci], in dapm_create_or_share_kcontrol()
905 switch (w->id) { in dapm_create_or_share_kcontrol()
924 return -EINVAL; in dapm_create_or_share_kcontrol()
936 w->name + prefix_len, in dapm_create_or_share_kcontrol()
937 w->kcontrol_news[kci].name); in dapm_create_or_share_kcontrol()
939 return -ENOMEM; in dapm_create_or_share_kcontrol()
944 name = w->name + prefix_len; in dapm_create_or_share_kcontrol()
947 name = w->kcontrol_news[kci].name; in dapm_create_or_share_kcontrol()
950 kcontrol = snd_soc_cnew(&w->kcontrol_news[kci], NULL, name, in dapm_create_or_share_kcontrol()
953 ret = -ENOMEM; in dapm_create_or_share_kcontrol()
957 kcontrol->private_free = dapm_kcontrol_free; in dapm_create_or_share_kcontrol()
967 dev_err(dapm->dev, in dapm_create_or_share_kcontrol()
969 w->name, name, ret); in dapm_create_or_share_kcontrol()
976 w->kcontrols[kci] = kcontrol; in dapm_create_or_share_kcontrol()
992 for (i = 0; i < w->num_kcontrols; i++) { in dapm_new_mixer()
996 if (path->name != (char *)w->kcontrol_news[i].name) in dapm_new_mixer()
999 if (!w->kcontrols[i]) { in dapm_new_mixer()
1005 dapm_kcontrol_add_path(w->kcontrols[i], path); in dapm_new_mixer()
1007 data = snd_kcontrol_chip(w->kcontrols[i]); in dapm_new_mixer()
1008 if (data->widget) in dapm_new_mixer()
1009 snd_soc_dapm_add_path(data->widget->dapm, in dapm_new_mixer()
1010 data->widget, in dapm_new_mixer()
1011 path->source, in dapm_new_mixer()
1022 struct snd_soc_dapm_context *dapm = w->dapm; in dapm_new_mux()
1028 switch (w->id) { in dapm_new_mux()
1038 return -EINVAL; in dapm_new_mux()
1041 if (w->num_kcontrols != 1) { in dapm_new_mux()
1042 dev_err(dapm->dev, in dapm_new_mux()
1044 w->name); in dapm_new_mux()
1045 return -EINVAL; in dapm_new_mux()
1048 if (list_empty(&w->edges[dir])) { in dapm_new_mux()
1049 dev_err(dapm->dev, "ASoC: %s %s has no paths\n", type, w->name); in dapm_new_mux()
1050 return -EINVAL; in dapm_new_mux()
1058 if (path->name) in dapm_new_mux()
1059 dapm_kcontrol_add_path(w->kcontrols[0], path); in dapm_new_mux()
1070 for (i = 0; i < w->num_kcontrols; i++) { in dapm_new_pga()
1083 struct snd_soc_pcm_runtime *rtd = w->priv; in dapm_new_dai_link()
1086 if (rtd->dai_link->num_params <= 1) in dapm_new_dai_link()
1090 for (i = 0; i < w->num_kcontrols; i++) { in dapm_new_dai_link()
1091 struct snd_soc_dapm_context *dapm = w->dapm; in dapm_new_dai_link()
1092 struct snd_card *card = dapm->card->snd_card; in dapm_new_dai_link()
1093 struct snd_kcontrol *kcontrol = snd_soc_cnew(&w->kcontrol_news[i], in dapm_new_dai_link()
1094 w, w->name, NULL); in dapm_new_dai_link()
1098 dev_err(dapm->dev, in dapm_new_dai_link()
1100 w->name, w->kcontrol_news[i].name, ret); in dapm_new_dai_link()
1103 kcontrol->private_data = w; in dapm_new_dai_link()
1104 w->kcontrols[i] = kcontrol; in dapm_new_dai_link()
1111 * the ALSA card - when we are suspending the ALSA state for the card
1116 int level = snd_power_get_state(widget->dapm->card->snd_card); in snd_soc_dapm_suspend_check() local
1118 switch (level) { in snd_soc_dapm_suspend_check()
1121 if (widget->ignore_suspend) in snd_soc_dapm_suspend_check()
1122 dev_dbg(widget->dapm->dev, "ASoC: %s ignoring suspend\n", in snd_soc_dapm_suspend_check()
1123 widget->name); in snd_soc_dapm_suspend_check()
1124 return widget->ignore_suspend; in snd_soc_dapm_suspend_check()
1148 return -ENOMEM; in dapm_widget_list_create()
1151 (*list)->widgets[i++] = w; in dapm_widget_list_create()
1153 (*list)->num_widgets = i; in dapm_widget_list_create()
1169 widget->endpoints[dir] = -1; in invalidate_paths_ep()
1172 if (path->weak || path->is_supply) in invalidate_paths_ep()
1175 if (path->walking) in invalidate_paths_ep()
1178 if (path->connect) { in invalidate_paths_ep()
1179 path->walking = 1; in invalidate_paths_ep()
1180 invalidate_paths_ep(path->node[dir], dir); in invalidate_paths_ep()
1181 path->walking = 0; in invalidate_paths_ep()
1205 if (widget->endpoints[dir] >= 0) in is_connected_ep()
1206 return widget->endpoints[dir]; in is_connected_ep()
1212 list_add_tail(&widget->work_list, list); in is_connected_ep()
1219 if ((widget->is_ep & SND_SOC_DAPM_DIR_TO_EP(dir)) && widget->connected) { in is_connected_ep()
1220 widget->endpoints[dir] = snd_soc_dapm_suspend_check(widget); in is_connected_ep()
1221 return widget->endpoints[dir]; in is_connected_ep()
1227 if (path->weak || path->is_supply) in is_connected_ep()
1230 if (path->walking) in is_connected_ep()
1235 if (path->connect) { in is_connected_ep()
1236 path->walking = 1; in is_connected_ep()
1237 con += fn(path->node[dir], list, custom_stop_condition); in is_connected_ep()
1238 path->walking = 0; in is_connected_ep()
1242 widget->endpoints[dir] = con; in is_connected_ep()
1284 * snd_soc_dapm_dai_get_connected_widgets - query audio path and it's widgets.
1285 * @dai: the soc DAI.
1307 struct snd_soc_card *card = dai->component->card; in snd_soc_dapm_dai_get_connected_widgets()
1313 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_dai_get_connected_widgets()
1316 w = dai->playback_widget; in snd_soc_dapm_dai_get_connected_widgets()
1321 w = dai->capture_widget; in snd_soc_dapm_dai_get_connected_widgets()
1335 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_dai_get_connected_widgets()
1355 soc_dapm_async_complete(w->dapm); in dapm_regulator_event()
1358 if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) { in dapm_regulator_event()
1359 ret = regulator_allow_bypass(w->regulator, false); in dapm_regulator_event()
1361 dev_warn(w->dapm->dev, in dapm_regulator_event()
1363 w->name, ret); in dapm_regulator_event()
1366 return regulator_enable(w->regulator); in dapm_regulator_event()
1368 if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) { in dapm_regulator_event()
1369 ret = regulator_allow_bypass(w->regulator, true); in dapm_regulator_event()
1371 dev_warn(w->dapm->dev, in dapm_regulator_event()
1373 w->name, ret); in dapm_regulator_event()
1376 return regulator_disable_deferred(w->regulator, w->shift); in dapm_regulator_event()
1387 struct snd_soc_dapm_pinctrl_priv *priv = w->priv; in dapm_pinctrl_event()
1388 struct pinctrl *p = w->pinctrl; in dapm_pinctrl_event()
1392 return -EIO; in dapm_pinctrl_event()
1395 s = pinctrl_lookup_state(p, priv->active_state); in dapm_pinctrl_event()
1397 s = pinctrl_lookup_state(p, priv->sleep_state); in dapm_pinctrl_event()
1412 if (!w->clk) in dapm_clock_event()
1413 return -EIO; in dapm_clock_event()
1415 soc_dapm_async_complete(w->dapm); in dapm_clock_event()
1418 return clk_prepare_enable(w->clk); in dapm_clock_event()
1420 clk_disable_unprepare(w->clk); in dapm_clock_event()
1430 if (w->power_checked) in dapm_widget_power_check()
1431 return w->new_power; in dapm_widget_power_check()
1433 if (w->force) in dapm_widget_power_check()
1434 w->new_power = 1; in dapm_widget_power_check()
1436 w->new_power = w->power_check(w); in dapm_widget_power_check()
1438 w->power_checked = true; in dapm_widget_power_check()
1440 return w->new_power; in dapm_widget_power_check()
1466 if (path->weak) in dapm_supply_check_power()
1469 if (path->connected && in dapm_supply_check_power()
1470 !path->connected(path->source, path->sink)) in dapm_supply_check_power()
1473 if (dapm_widget_power_check(path->sink)) in dapm_supply_check_power()
1482 return w->connected; in dapm_always_on_check_power()
1499 WARN_ONCE(sort[a->id] == 0, "offset a->id %d not initialized\n", a->id); in dapm_seq_compare()
1500 WARN_ONCE(sort[b->id] == 0, "offset b->id %d not initialized\n", b->id); in dapm_seq_compare()
1502 if (sort[a->id] != sort[b->id]) in dapm_seq_compare()
1503 return sort[a->id] - sort[b->id]; in dapm_seq_compare()
1504 if (a->subseq != b->subseq) { in dapm_seq_compare()
1506 return a->subseq - b->subseq; in dapm_seq_compare()
1508 return b->subseq - a->subseq; in dapm_seq_compare()
1510 if (a->reg != b->reg) in dapm_seq_compare()
1511 return a->reg - b->reg; in dapm_seq_compare()
1512 if (a->dapm != b->dapm) in dapm_seq_compare()
1513 return (unsigned long)a->dapm - (unsigned long)b->dapm; in dapm_seq_compare()
1527 list_add_tail(&new_widget->power_list, &w->power_list); in dapm_seq_insert()
1531 list_add_tail(&new_widget->power_list, list); in dapm_seq_insert()
1566 WARN(1, "Unknown event %d\n", event); in dapm_seq_check_event()
1570 if (w->new_power != power) in dapm_seq_check_event()
1573 if (w->event && (w->event_flags & event)) { in dapm_seq_check_event()
1576 pop_dbg(w->dapm->dev, card->pop_time, "pop test : %s %s\n", in dapm_seq_check_event()
1577 w->name, ev_name); in dapm_seq_check_event()
1578 soc_dapm_async_complete(w->dapm); in dapm_seq_check_event()
1580 ret = w->event(w, NULL, event); in dapm_seq_check_event()
1583 dev_err(w->dapm->dev, "ASoC: %s: %s event failed: %d\n", in dapm_seq_check_event()
1584 ev_name, w->name, ret); in dapm_seq_check_event()
1599 reg = w->reg; in dapm_seq_run_coalesced()
1600 dapm = w->dapm; in dapm_seq_run_coalesced()
1603 WARN_ON(reg != w->reg || dapm != w->dapm); in dapm_seq_run_coalesced()
1604 w->power = w->new_power; in dapm_seq_run_coalesced()
1606 mask |= w->mask << w->shift; in dapm_seq_run_coalesced()
1607 if (w->power) in dapm_seq_run_coalesced()
1608 value |= w->on_val << w->shift; in dapm_seq_run_coalesced()
1610 value |= w->off_val << w->shift; in dapm_seq_run_coalesced()
1612 pop_dbg(dapm->dev, card->pop_time, in dapm_seq_run_coalesced()
1614 w->name, reg, value, mask); in dapm_seq_run_coalesced()
1626 pop_dbg(dapm->dev, card->pop_time, in dapm_seq_run_coalesced()
1628 value, mask, reg, card->pop_time); in dapm_seq_run_coalesced()
1629 pop_wait(card->pop_time); in dapm_seq_run_coalesced()
1641 * We walk over a pre-sorted list of widgets to apply power to. In
1653 int cur_sort = -1; in dapm_seq_run()
1654 int cur_subseq = -1; in dapm_seq_run()
1669 if (sort[w->id] != cur_sort || w->reg != cur_reg || in dapm_seq_run()
1670 w->dapm != cur_dapm || w->subseq != cur_subseq) { in dapm_seq_run()
1674 if (cur_dapm && cur_dapm->component) { in dapm_seq_run()
1678 cur_dapm->component, in dapm_seq_run()
1682 if (cur_dapm && w->dapm != cur_dapm) in dapm_seq_run()
1686 cur_sort = -1; in dapm_seq_run()
1692 switch (w->id) { in dapm_seq_run()
1694 if (!w->event) in dapm_seq_run()
1698 ret = w->event(w, in dapm_seq_run()
1701 ret = w->event(w, in dapm_seq_run()
1706 if (!w->event) in dapm_seq_run()
1710 ret = w->event(w, in dapm_seq_run()
1713 ret = w->event(w, in dapm_seq_run()
1719 cur_sort = sort[w->id]; in dapm_seq_run()
1720 cur_subseq = w->subseq; in dapm_seq_run()
1721 cur_reg = w->reg; in dapm_seq_run()
1722 cur_dapm = w->dapm; in dapm_seq_run()
1723 list_move(&w->power_list, &pending); in dapm_seq_run()
1728 dev_err(w->dapm->dev, in dapm_seq_run()
1735 if (cur_dapm && cur_dapm->component) { in dapm_seq_run()
1739 cur_dapm->component, in dapm_seq_run()
1749 struct snd_soc_dapm_update *update = card->update; in dapm_widget_update()
1755 if (!update || !dapm_kcontrol_is_powered(update->kcontrol)) in dapm_widget_update()
1758 wlist = dapm_kcontrol_get_wlist(update->kcontrol); in dapm_widget_update()
1761 if (w->event && (w->event_flags & SND_SOC_DAPM_PRE_REG)) { in dapm_widget_update()
1762 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG); in dapm_widget_update()
1764 dev_err(w->dapm->dev, "ASoC: %s DAPM pre-event failed: %d\n", in dapm_widget_update()
1765 w->name, ret); in dapm_widget_update()
1772 ret = soc_dapm_update_bits(w->dapm, update->reg, update->mask, in dapm_widget_update()
1773 update->val); in dapm_widget_update()
1775 dev_err(w->dapm->dev, "ASoC: %s DAPM update failed: %d\n", in dapm_widget_update()
1776 w->name, ret); in dapm_widget_update()
1778 if (update->has_second_set) { in dapm_widget_update()
1779 ret = soc_dapm_update_bits(w->dapm, update->reg2, in dapm_widget_update()
1780 update->mask2, update->val2); in dapm_widget_update()
1782 dev_err(w->dapm->dev, in dapm_widget_update()
1784 w->name, ret); in dapm_widget_update()
1788 if (w->event && (w->event_flags & SND_SOC_DAPM_POST_REG)) { in dapm_widget_update()
1789 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG); in dapm_widget_update()
1791 dev_err(w->dapm->dev, "ASoC: %s DAPM post-event failed: %d\n", in dapm_widget_update()
1792 w->name, ret); in dapm_widget_update()
1797 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1806 if (d->bias_level == SND_SOC_BIAS_OFF && in dapm_pre_sequence_async()
1807 d->target_bias_level != SND_SOC_BIAS_OFF) { in dapm_pre_sequence_async()
1808 if (d->dev && cookie) in dapm_pre_sequence_async()
1809 pm_runtime_get_sync(d->dev); in dapm_pre_sequence_async()
1813 dev_err(d->dev, in dapm_pre_sequence_async()
1818 if ((d->target_bias_level == SND_SOC_BIAS_ON && in dapm_pre_sequence_async()
1819 d->bias_level != SND_SOC_BIAS_ON) || in dapm_pre_sequence_async()
1820 (d->target_bias_level != SND_SOC_BIAS_ON && in dapm_pre_sequence_async()
1821 d->bias_level == SND_SOC_BIAS_ON)) { in dapm_pre_sequence_async()
1824 dev_err(d->dev, in dapm_pre_sequence_async()
1829 /* Async callback run prior to DAPM sequences - brings to their final
1838 if (d->bias_level == SND_SOC_BIAS_PREPARE && in dapm_post_sequence_async()
1839 (d->target_bias_level == SND_SOC_BIAS_STANDBY || in dapm_post_sequence_async()
1840 d->target_bias_level == SND_SOC_BIAS_OFF)) { in dapm_post_sequence_async()
1843 dev_err(d->dev, "ASoC: Failed to apply standby bias: %d\n", in dapm_post_sequence_async()
1848 if (d->bias_level == SND_SOC_BIAS_STANDBY && in dapm_post_sequence_async()
1849 d->target_bias_level == SND_SOC_BIAS_OFF) { in dapm_post_sequence_async()
1852 dev_err(d->dev, "ASoC: Failed to turn off bias: %d\n", in dapm_post_sequence_async()
1855 if (d->dev && cookie) in dapm_post_sequence_async()
1856 pm_runtime_put(d->dev); in dapm_post_sequence_async()
1860 if (d->bias_level == SND_SOC_BIAS_PREPARE && in dapm_post_sequence_async()
1861 d->target_bias_level == SND_SOC_BIAS_ON) { in dapm_post_sequence_async()
1864 dev_err(d->dev, "ASoC: Failed to apply active bias: %d\n", in dapm_post_sequence_async()
1880 if (power != peer->power) in dapm_widget_set_peer_power()
1890 if (w->power == power) in dapm_widget_set_power()
1899 dapm_widget_set_peer_power(path->source, power, path->connect); in dapm_widget_set_power()
1902 if (!w->is_supply) { in dapm_widget_set_power()
1904 dapm_widget_set_peer_power(path->sink, power, in dapm_widget_set_power()
1905 path->connect); in dapm_widget_set_power()
1920 switch (w->id) { in dapm_power_one_widget()
1938 if (dapm->idle_bias_off) in dapm_idle_bias_off()
1941 switch (snd_power_get_state(dapm->card->snd_card)) { in dapm_idle_bias_off()
1944 return dapm->suspend_bias_off; in dapm_idle_bias_off()
1954 * A complete path is a route that has valid endpoints i.e.:-
1971 lockdep_assert_held(&card->dapm_mutex); in dapm_power_widgets()
1977 d->target_bias_level = SND_SOC_BIAS_OFF; in dapm_power_widgets()
1979 d->target_bias_level = SND_SOC_BIAS_STANDBY; in dapm_power_widgets()
1990 list_for_each_entry(w, &card->dapm_dirty, dirty) { in dapm_power_widgets()
1995 switch (w->id) { in dapm_power_widgets()
2001 list_del_init(&w->dirty); in dapm_power_widgets()
2005 if (w->new_power) { in dapm_power_widgets()
2006 d = w->dapm; in dapm_power_widgets()
2015 switch (w->id) { in dapm_power_widgets()
2024 if (d->target_bias_level < SND_SOC_BIAS_STANDBY) in dapm_power_widgets()
2025 d->target_bias_level = SND_SOC_BIAS_STANDBY; in dapm_power_widgets()
2028 d->target_bias_level = SND_SOC_BIAS_ON; in dapm_power_widgets()
2040 if (d->target_bias_level > bias) in dapm_power_widgets()
2041 bias = d->target_bias_level; in dapm_power_widgets()
2044 d->target_bias_level = bias; in dapm_power_widgets()
2049 dapm_pre_sequence_async(&card->dapm, 0); in dapm_power_widgets()
2052 if (d != &card->dapm && d->bias_level != d->target_bias_level) in dapm_power_widgets()
2076 if (d != &card->dapm && d->bias_level != d->target_bias_level) in dapm_power_widgets()
2082 dapm_post_sequence_async(&card->dapm, 0); in dapm_power_widgets()
2086 if (!d->component) in dapm_power_widgets()
2089 ret = snd_soc_component_stream_event(d->component, event); in dapm_power_widgets()
2094 pop_dbg(card->dev, card->pop_time, in dapm_power_widgets()
2095 "DAPM sequencing finished, waiting %dms\n", card->pop_time); in dapm_power_widgets()
2096 pop_wait(card->pop_time); in dapm_power_widgets()
2108 struct snd_soc_dapm_widget *w = file->private_data; in dapm_widget_power_read_file()
2109 struct snd_soc_card *card = w->dapm->card; in dapm_widget_power_read_file()
2118 return -ENOMEM; in dapm_widget_power_read_file()
2120 mutex_lock(&card->dapm_mutex); in dapm_widget_power_read_file()
2123 if (w->is_supply) { in dapm_widget_power_read_file()
2132 w->name, w->power ? "On" : "Off", in dapm_widget_power_read_file()
2133 w->force ? " (forced)" : "", in, out); in dapm_widget_power_read_file()
2135 if (w->reg >= 0) in dapm_widget_power_read_file()
2136 ret += scnprintf(buf + ret, PAGE_SIZE - ret, in dapm_widget_power_read_file()
2137 " - R%d(0x%x) mask 0x%x", in dapm_widget_power_read_file()
2138 w->reg, w->reg, w->mask << w->shift); in dapm_widget_power_read_file()
2140 ret += scnprintf(buf + ret, PAGE_SIZE - ret, "\n"); in dapm_widget_power_read_file()
2142 if (w->sname) in dapm_widget_power_read_file()
2143 ret += scnprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n", in dapm_widget_power_read_file()
2144 w->sname, in dapm_widget_power_read_file()
2145 w->active ? "active" : "inactive"); in dapm_widget_power_read_file()
2150 if (p->connected && !p->connected(p->source, p->sink)) in dapm_widget_power_read_file()
2153 if (!p->connect) in dapm_widget_power_read_file()
2156 ret += scnprintf(buf + ret, PAGE_SIZE - ret, in dapm_widget_power_read_file()
2159 p->name ? p->name : "static", in dapm_widget_power_read_file()
2160 p->node[rdir]->name); in dapm_widget_power_read_file()
2164 mutex_unlock(&card->dapm_mutex); in dapm_widget_power_read_file()
2181 struct snd_soc_dapm_context *dapm = file->private_data; in dapm_bias_read_file()
2182 char *level; in dapm_bias_read_file() local
2184 switch (dapm->bias_level) { in dapm_bias_read_file()
2186 level = "On\n"; in dapm_bias_read_file()
2189 level = "Prepare\n"; in dapm_bias_read_file()
2192 level = "Standby\n"; in dapm_bias_read_file()
2195 level = "Off\n"; in dapm_bias_read_file()
2198 WARN(1, "Unknown bias_level %d\n", dapm->bias_level); in dapm_bias_read_file()
2199 level = "Unknown\n"; in dapm_bias_read_file()
2203 return simple_read_from_buffer(user_buf, count, ppos, level, in dapm_bias_read_file()
2204 strlen(level)); in dapm_bias_read_file()
2219 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent); in snd_soc_dapm_debugfs_init()
2221 debugfs_create_file("bias_level", 0444, dapm->debugfs_dapm, dapm, in snd_soc_dapm_debugfs_init()
2227 struct snd_soc_dapm_context *dapm = w->dapm; in dapm_debugfs_add_widget()
2229 if (!dapm->debugfs_dapm || !w->name) in dapm_debugfs_add_widget()
2232 debugfs_create_file(w->name, 0444, dapm->debugfs_dapm, w, in dapm_debugfs_add_widget()
2238 debugfs_remove_recursive(dapm->debugfs_dapm); in dapm_debugfs_cleanup()
2239 dapm->debugfs_dapm = NULL; in dapm_debugfs_cleanup()
2259 * soc_dapm_connect_path() - Connects or disconnects a path
2268 if (path->connect == connect) in soc_dapm_connect_path()
2271 path->connect = connect; in soc_dapm_connect_path()
2272 dapm_mark_dirty(path->source, reason); in soc_dapm_connect_path()
2273 dapm_mark_dirty(path->sink, reason); in soc_dapm_connect_path()
2285 lockdep_assert_held(&card->dapm_mutex); in soc_dapm_mux_update_power()
2291 if (e && !(strcmp(path->name, e->texts[mux]))) in soc_dapm_mux_update_power()
2309 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_mux_update_power()
2312 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_mux_update_power()
2313 card->update = update; in snd_soc_dapm_mux_update_power()
2315 card->update = NULL; in snd_soc_dapm_mux_update_power()
2316 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_mux_update_power()
2331 lockdep_assert_held(&card->dapm_mutex); in soc_dapm_mixer_update_power()
2374 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_mixer_update_power()
2377 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_mixer_update_power()
2378 card->update = update; in snd_soc_dapm_mixer_update_power()
2379 ret = soc_dapm_mixer_update_power(card, kcontrol, connect, -1); in snd_soc_dapm_mixer_update_power()
2380 card->update = NULL; in snd_soc_dapm_mixer_update_power()
2381 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_mixer_update_power()
2399 if (!cmpnt->card) in dapm_widget_show_component()
2402 for_each_card_widgets(cmpnt->card, w) { in dapm_widget_show_component()
2403 if (w->dapm != dapm) in dapm_widget_show_component()
2407 switch (w->id) { in dapm_widget_show_component()
2424 if (w->name) in dapm_widget_show_component()
2426 w->name, w->power ? "On":"Off"); in dapm_widget_show_component()
2460 mutex_lock(&rtd->card->dapm_mutex); in dapm_widget_show()
2463 struct snd_soc_component *cmpnt = codec_dai->component; in dapm_widget_show()
2468 mutex_unlock(&rtd->card->dapm_mutex); in dapm_widget_show()
2482 list_del(&path->list_node[SND_SOC_DAPM_DIR_IN]); in dapm_free_path()
2483 list_del(&path->list_node[SND_SOC_DAPM_DIR_OUT]); in dapm_free_path()
2484 list_del(&path->list_kcontrol); in dapm_free_path()
2485 list_del(&path->list); in dapm_free_path()
2490 * snd_soc_dapm_free_widget - Free specified widget
2500 list_del(&w->list); in snd_soc_dapm_free_widget()
2501 list_del(&w->dirty); in snd_soc_dapm_free_widget()
2512 kfree(w->kcontrols); in snd_soc_dapm_free_widget()
2513 kfree_const(w->name); in snd_soc_dapm_free_widget()
2514 kfree_const(w->sname); in snd_soc_dapm_free_widget()
2521 dapm->path_sink_cache.widget = NULL; in snd_soc_dapm_reset_cache()
2522 dapm->path_source_cache.widget = NULL; in snd_soc_dapm_reset_cache()
2530 for_each_card_widgets_safe(dapm->card, w, next_w) { in dapm_free_widgets()
2531 if (w->dapm != dapm) in dapm_free_widgets()
2556 for_each_card_widgets(dapm->card, w) { in dapm_find_widget()
2557 if (!strcmp(w->name, pin_name)) { in dapm_find_widget()
2558 if (w->dapm == dapm) in dapm_find_widget()
2585 dev_err(dapm->dev, "ASoC: DAPM unknown pin %s\n", pin); in __snd_soc_dapm_set_pin()
2586 return -EINVAL; in __snd_soc_dapm_set_pin()
2589 if (w->connected != status) { in __snd_soc_dapm_set_pin()
2596 w->connected = status; in __snd_soc_dapm_set_pin()
2598 w->force = 0; in __snd_soc_dapm_set_pin()
2616 * snd_soc_dapm_sync_unlocked - scan and power dapm paths
2632 if (!dapm->card || !dapm->card->instantiated) in snd_soc_dapm_sync_unlocked()
2635 return dapm_power_widgets(dapm->card, SND_SOC_DAPM_STREAM_NOP); in snd_soc_dapm_sync_unlocked()
2640 * snd_soc_dapm_sync - scan and power dapm paths
2652 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_sync()
2654 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_sync()
2663 switch (w->id) { in dapm_update_dai_chan()
2671 dev_dbg(w->dapm->dev, "%s DAI route %s -> %s\n", in dapm_update_dai_chan()
2672 w->channel < channels ? "Connecting" : "Disconnecting", in dapm_update_dai_chan()
2673 p->source->name, p->sink->name); in dapm_update_dai_chan()
2675 if (w->channel < channels) in dapm_update_dai_chan()
2687 int dir = substream->stream; in dapm_update_dai_unlocked()
2698 dev_dbg(dai->dev, "Update DAI routes for %s %s\n", dai->name, in dapm_update_dai_unlocked()
2702 ret = dapm_update_dai_chan(p, p->sink, channels); in dapm_update_dai_unlocked()
2708 ret = dapm_update_dai_chan(p, p->source, channels); in dapm_update_dai_unlocked()
2723 mutex_lock_nested(&rtd->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_update_dai()
2725 mutex_unlock(&rtd->card->dapm_mutex); in snd_soc_dapm_update_dai()
2732 * dapm_update_widget_flags() - Re-compute widget sink and source flags
2746 switch (w->id) { in dapm_update_widget_flags()
2749 if (w->dapm->card->fully_routed) in dapm_update_widget_flags()
2753 if (p->source->id == snd_soc_dapm_micbias || in dapm_update_widget_flags()
2754 p->source->id == snd_soc_dapm_mic || in dapm_update_widget_flags()
2755 p->source->id == snd_soc_dapm_line || in dapm_update_widget_flags()
2756 p->source->id == snd_soc_dapm_output) { in dapm_update_widget_flags()
2764 if (w->dapm->card->fully_routed) in dapm_update_widget_flags()
2768 if (p->sink->id == snd_soc_dapm_spk || in dapm_update_widget_flags()
2769 p->sink->id == snd_soc_dapm_hp || in dapm_update_widget_flags()
2770 p->sink->id == snd_soc_dapm_line || in dapm_update_widget_flags()
2771 p->sink->id == snd_soc_dapm_input) { in dapm_update_widget_flags()
2780 if (!list_empty(&w->edges[dir])) in dapm_update_widget_flags()
2788 w->is_ep = ep; in dapm_update_widget_flags()
2801 switch (source->id) { in snd_soc_dapm_check_dynamic_path()
2809 switch (sink->id) { in snd_soc_dapm_check_dynamic_path()
2821 dev_err(dapm->dev, in snd_soc_dapm_check_dynamic_path()
2822 "Direct connection between demux and mixer/mux not supported for path %s -> [%s] -> %s\n", in snd_soc_dapm_check_dynamic_path()
2823 source->name, control, sink->name); in snd_soc_dapm_check_dynamic_path()
2824 return -EINVAL; in snd_soc_dapm_check_dynamic_path()
2826 dev_err(dapm->dev, in snd_soc_dapm_check_dynamic_path()
2827 "Control not supported for path %s -> [%s] -> %s\n", in snd_soc_dapm_check_dynamic_path()
2828 source->name, control, sink->name); in snd_soc_dapm_check_dynamic_path()
2829 return -EINVAL; in snd_soc_dapm_check_dynamic_path()
2846 if (wsink->is_supply && !wsource->is_supply) { in snd_soc_dapm_add_path()
2847 dev_err(dapm->dev, in snd_soc_dapm_add_path()
2848 "Connecting non-supply widget to supply widget is not supported (%s -> %s)\n", in snd_soc_dapm_add_path()
2849 wsource->name, wsink->name); in snd_soc_dapm_add_path()
2850 return -EINVAL; in snd_soc_dapm_add_path()
2853 if (connected && !wsource->is_supply) { in snd_soc_dapm_add_path()
2854 dev_err(dapm->dev, in snd_soc_dapm_add_path()
2855 "connected() callback only supported for supply widgets (%s -> %s)\n", in snd_soc_dapm_add_path()
2856 wsource->name, wsink->name); in snd_soc_dapm_add_path()
2857 return -EINVAL; in snd_soc_dapm_add_path()
2860 if (wsource->is_supply && control) { in snd_soc_dapm_add_path()
2861 dev_err(dapm->dev, in snd_soc_dapm_add_path()
2862 "Conditional paths are not supported for supply widgets (%s -> [%s] -> %s)\n", in snd_soc_dapm_add_path()
2863 wsource->name, control, wsink->name); in snd_soc_dapm_add_path()
2864 return -EINVAL; in snd_soc_dapm_add_path()
2873 return -ENOMEM; in snd_soc_dapm_add_path()
2875 path->node[SND_SOC_DAPM_DIR_IN] = wsource; in snd_soc_dapm_add_path()
2876 path->node[SND_SOC_DAPM_DIR_OUT] = wsink; in snd_soc_dapm_add_path()
2880 path->connected = connected; in snd_soc_dapm_add_path()
2881 INIT_LIST_HEAD(&path->list); in snd_soc_dapm_add_path()
2882 INIT_LIST_HEAD(&path->list_kcontrol); in snd_soc_dapm_add_path()
2884 if (wsource->is_supply || wsink->is_supply) in snd_soc_dapm_add_path()
2885 path->is_supply = 1; in snd_soc_dapm_add_path()
2889 path->connect = 1; in snd_soc_dapm_add_path()
2891 switch (wsource->id) { in snd_soc_dapm_add_path()
2901 switch (wsink->id) { in snd_soc_dapm_add_path()
2919 list_add(&path->list, &dapm->card->paths); in snd_soc_dapm_add_path()
2921 list_add(&path->list_node[dir], &widgets[dir]->edges[dir]); in snd_soc_dapm_add_path()
2928 if (dapm->card->instantiated && path->connect) in snd_soc_dapm_add_path()
2954 prefix, route->sink); in snd_soc_dapm_add_route()
2957 prefix, route->source); in snd_soc_dapm_add_route()
2960 sink = route->sink; in snd_soc_dapm_add_route()
2961 source = route->source; in snd_soc_dapm_add_route()
2964 wsource = dapm_wcache_lookup(&dapm->path_source_cache, source); in snd_soc_dapm_add_route()
2965 wsink = dapm_wcache_lookup(&dapm->path_sink_cache, sink); in snd_soc_dapm_add_route()
2974 for_each_card_widgets(dapm->card, w) { in snd_soc_dapm_add_route()
2975 if (!wsink && !(strcmp(w->name, sink))) { in snd_soc_dapm_add_route()
2977 if (w->dapm == dapm) { in snd_soc_dapm_add_route()
2984 dev_warn(dapm->dev, in snd_soc_dapm_add_route()
2986 w->name); in snd_soc_dapm_add_route()
2989 if (!wsource && !(strcmp(w->name, source))) { in snd_soc_dapm_add_route()
2991 if (w->dapm == dapm) { in snd_soc_dapm_add_route()
2998 dev_warn(dapm->dev, in snd_soc_dapm_add_route()
3000 w->name); in snd_soc_dapm_add_route()
3010 dev_err(dapm->dev, "ASoC: no source widget found for %s\n", in snd_soc_dapm_add_route()
3011 route->source); in snd_soc_dapm_add_route()
3012 return -ENODEV; in snd_soc_dapm_add_route()
3015 dev_err(dapm->dev, "ASoC: no sink widget found for %s\n", in snd_soc_dapm_add_route()
3016 route->sink); in snd_soc_dapm_add_route()
3017 return -ENODEV; in snd_soc_dapm_add_route()
3021 dapm_wcache_update(&dapm->path_sink_cache, wsink); in snd_soc_dapm_add_route()
3022 dapm_wcache_update(&dapm->path_source_cache, wsource); in snd_soc_dapm_add_route()
3024 ret = snd_soc_dapm_add_path(dapm, wsource, wsink, route->control, in snd_soc_dapm_add_route()
3025 route->connected); in snd_soc_dapm_add_route()
3031 dev_warn(dapm->dev, "ASoC: no dapm match for %s --> %s --> %s\n", in snd_soc_dapm_add_route()
3032 source, route->control, sink); in snd_soc_dapm_add_route()
3046 if (route->control) { in snd_soc_dapm_del_route()
3047 dev_err(dapm->dev, in snd_soc_dapm_del_route()
3049 return -EINVAL; in snd_soc_dapm_del_route()
3055 prefix, route->sink); in snd_soc_dapm_del_route()
3058 prefix, route->source); in snd_soc_dapm_del_route()
3061 sink = route->sink; in snd_soc_dapm_del_route()
3062 source = route->source; in snd_soc_dapm_del_route()
3066 list_for_each_entry(p, &dapm->card->paths, list) { in snd_soc_dapm_del_route()
3067 if (strcmp(p->source->name, source) != 0) in snd_soc_dapm_del_route()
3069 if (strcmp(p->sink->name, sink) != 0) in snd_soc_dapm_del_route()
3076 struct snd_soc_dapm_widget *wsource = path->source; in snd_soc_dapm_del_route()
3077 struct snd_soc_dapm_widget *wsink = path->sink; in snd_soc_dapm_del_route()
3081 if (path->connect) in snd_soc_dapm_del_route()
3090 dev_warn(dapm->dev, "ASoC: Route %s->%s does not exist\n", in snd_soc_dapm_del_route()
3098 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
3115 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_add_routes()
3119 dev_err(dapm->dev, "ASoC: Failed to add route %s -> %s -> %s\n", in snd_soc_dapm_add_routes()
3120 route->source, in snd_soc_dapm_add_routes()
3121 route->control ? route->control : "direct", in snd_soc_dapm_add_routes()
3122 route->sink); in snd_soc_dapm_add_routes()
3127 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_add_routes()
3134 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
3146 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_del_routes()
3151 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_del_routes()
3161 route->source, in snd_soc_dapm_weak_route()
3164 route->sink, in snd_soc_dapm_weak_route()
3170 dev_err(dapm->dev, "ASoC: Unable to find source %s for weak route\n", in snd_soc_dapm_weak_route()
3171 route->source); in snd_soc_dapm_weak_route()
3172 return -ENODEV; in snd_soc_dapm_weak_route()
3176 dev_err(dapm->dev, "ASoC: Unable to find sink %s for weak route\n", in snd_soc_dapm_weak_route()
3177 route->sink); in snd_soc_dapm_weak_route()
3178 return -ENODEV; in snd_soc_dapm_weak_route()
3181 if (route->control || route->connected) in snd_soc_dapm_weak_route()
3182 dev_warn(dapm->dev, "ASoC: Ignoring control for weak route %s->%s\n", in snd_soc_dapm_weak_route()
3183 route->source, route->sink); in snd_soc_dapm_weak_route()
3186 if (path->sink == sink) { in snd_soc_dapm_weak_route()
3187 path->weak = 1; in snd_soc_dapm_weak_route()
3193 dev_err(dapm->dev, "ASoC: No path found for weak route %s->%s\n", in snd_soc_dapm_weak_route()
3194 route->source, route->sink); in snd_soc_dapm_weak_route()
3196 dev_warn(dapm->dev, "ASoC: %d paths found for weak route %s->%s\n", in snd_soc_dapm_weak_route()
3197 count, route->source, route->sink); in snd_soc_dapm_weak_route()
3203 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
3213 * level but which aren't intended to be "used".
3224 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); in snd_soc_dapm_weak_routes()
3231 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_weak_routes()
3238 * snd_soc_dapm_new_widgets - add new dapm widgets
3250 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); in snd_soc_dapm_new_widgets()
3254 if (w->new) in snd_soc_dapm_new_widgets()
3257 if (w->num_kcontrols) { in snd_soc_dapm_new_widgets()
3258 w->kcontrols = kcalloc(w->num_kcontrols, in snd_soc_dapm_new_widgets()
3261 if (!w->kcontrols) { in snd_soc_dapm_new_widgets()
3262 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_new_widgets()
3263 return -ENOMEM; in snd_soc_dapm_new_widgets()
3267 switch(w->id) { in snd_soc_dapm_new_widgets()
3290 if (w->reg >= 0) { in snd_soc_dapm_new_widgets()
3291 val = soc_dapm_read(w->dapm, w->reg); in snd_soc_dapm_new_widgets()
3292 val = val >> w->shift; in snd_soc_dapm_new_widgets()
3293 val &= w->mask; in snd_soc_dapm_new_widgets()
3294 if (val == w->on_val) in snd_soc_dapm_new_widgets()
3295 w->power = 1; in snd_soc_dapm_new_widgets()
3298 w->new = 1; in snd_soc_dapm_new_widgets()
3305 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_new_widgets()
3311 * snd_soc_dapm_get_volsw - dapm mixer get callback
3323 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_get_volsw()
3325 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_dapm_get_volsw()
3326 int reg = mc->reg; in snd_soc_dapm_get_volsw()
3327 unsigned int shift = mc->shift; in snd_soc_dapm_get_volsw()
3328 int max = mc->max; in snd_soc_dapm_get_volsw()
3330 unsigned int mask = (1 << fls(max)) - 1; in snd_soc_dapm_get_volsw()
3331 unsigned int invert = mc->invert; in snd_soc_dapm_get_volsw()
3334 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_get_volsw()
3339 if (reg != mc->rreg) in snd_soc_dapm_get_volsw()
3340 reg_val = soc_dapm_read(dapm, mc->rreg); in snd_soc_dapm_get_volsw()
3343 rval = (reg_val >> mc->rshift) & mask; in snd_soc_dapm_get_volsw()
3351 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_get_volsw()
3354 ucontrol->value.integer.value[0] = max - val; in snd_soc_dapm_get_volsw()
3356 ucontrol->value.integer.value[0] = val; in snd_soc_dapm_get_volsw()
3360 ucontrol->value.integer.value[1] = max - rval; in snd_soc_dapm_get_volsw()
3362 ucontrol->value.integer.value[1] = rval; in snd_soc_dapm_get_volsw()
3370 * snd_soc_dapm_put_volsw - dapm mixer set callback
3382 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_put_volsw()
3384 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_dapm_put_volsw()
3385 int reg = mc->reg; in snd_soc_dapm_put_volsw()
3386 unsigned int shift = mc->shift; in snd_soc_dapm_put_volsw()
3387 int max = mc->max; in snd_soc_dapm_put_volsw()
3389 unsigned int mask = (1 << width) - 1; in snd_soc_dapm_put_volsw()
3390 unsigned int invert = mc->invert; in snd_soc_dapm_put_volsw()
3392 int connect, rconnect = -1, change, reg_change = 0; in snd_soc_dapm_put_volsw()
3396 val = (ucontrol->value.integer.value[0] & mask); in snd_soc_dapm_put_volsw()
3400 val = max - val; in snd_soc_dapm_put_volsw()
3403 rval = (ucontrol->value.integer.value[1] & mask); in snd_soc_dapm_put_volsw()
3406 rval = max - rval; in snd_soc_dapm_put_volsw()
3409 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_put_volsw()
3413 dev_warn(dapm->dev, in snd_soc_dapm_put_volsw()
3415 kcontrol->id.name); in snd_soc_dapm_put_volsw()
3420 rval = rval << mc->rshift; in snd_soc_dapm_put_volsw()
3425 reg_change |= soc_dapm_test_bits(dapm, mc->rreg, in snd_soc_dapm_put_volsw()
3426 mask << mc->rshift, in snd_soc_dapm_put_volsw()
3434 update.reg2 = mc->rreg; in snd_soc_dapm_put_volsw()
3435 update.mask2 = mask << mc->rshift; in snd_soc_dapm_put_volsw()
3442 card->update = &update; in snd_soc_dapm_put_volsw()
3448 card->update = NULL; in snd_soc_dapm_put_volsw()
3451 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_put_volsw()
3461 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
3473 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_get_enum_double()
3474 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in snd_soc_dapm_get_enum_double()
3477 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_get_enum_double()
3478 if (e->reg != SND_SOC_NOPM && dapm_kcontrol_is_powered(kcontrol)) { in snd_soc_dapm_get_enum_double()
3479 reg_val = soc_dapm_read(dapm, e->reg); in snd_soc_dapm_get_enum_double()
3483 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_get_enum_double()
3485 val = (reg_val >> e->shift_l) & e->mask; in snd_soc_dapm_get_enum_double()
3486 ucontrol->value.enumerated.item[0] = snd_soc_enum_val_to_item(e, val); in snd_soc_dapm_get_enum_double()
3487 if (e->shift_l != e->shift_r) { in snd_soc_dapm_get_enum_double()
3488 val = (reg_val >> e->shift_r) & e->mask; in snd_soc_dapm_get_enum_double()
3490 ucontrol->value.enumerated.item[1] = val; in snd_soc_dapm_get_enum_double()
3498 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
3510 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_put_enum_double()
3511 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in snd_soc_dapm_put_enum_double()
3512 unsigned int *item = ucontrol->value.enumerated.item; in snd_soc_dapm_put_enum_double()
3518 if (item[0] >= e->items) in snd_soc_dapm_put_enum_double()
3519 return -EINVAL; in snd_soc_dapm_put_enum_double()
3521 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l; in snd_soc_dapm_put_enum_double()
3522 mask = e->mask << e->shift_l; in snd_soc_dapm_put_enum_double()
3523 if (e->shift_l != e->shift_r) { in snd_soc_dapm_put_enum_double()
3524 if (item[1] > e->items) in snd_soc_dapm_put_enum_double()
3525 return -EINVAL; in snd_soc_dapm_put_enum_double()
3526 val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_r; in snd_soc_dapm_put_enum_double()
3527 mask |= e->mask << e->shift_r; in snd_soc_dapm_put_enum_double()
3530 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_put_enum_double()
3534 if (e->reg != SND_SOC_NOPM) in snd_soc_dapm_put_enum_double()
3535 reg_change = soc_dapm_test_bits(dapm, e->reg, mask, val); in snd_soc_dapm_put_enum_double()
3540 update.reg = e->reg; in snd_soc_dapm_put_enum_double()
3543 card->update = &update; in snd_soc_dapm_put_enum_double()
3548 card->update = NULL; in snd_soc_dapm_put_enum_double()
3551 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_put_enum_double()
3561 * snd_soc_dapm_info_pin_switch - Info for a pin switch
3571 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; in snd_soc_dapm_info_pin_switch()
3572 uinfo->count = 1; in snd_soc_dapm_info_pin_switch()
3573 uinfo->value.integer.min = 0; in snd_soc_dapm_info_pin_switch()
3574 uinfo->value.integer.max = 1; in snd_soc_dapm_info_pin_switch()
3581 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
3590 const char *pin = (const char *)kcontrol->private_value; in snd_soc_dapm_get_pin_switch()
3592 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_get_pin_switch()
3594 ucontrol->value.integer.value[0] = in snd_soc_dapm_get_pin_switch()
3595 snd_soc_dapm_get_pin_status(&card->dapm, pin); in snd_soc_dapm_get_pin_switch()
3597 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_get_pin_switch()
3604 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
3613 const char *pin = (const char *)kcontrol->private_value; in snd_soc_dapm_put_pin_switch()
3616 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_put_pin_switch()
3617 ret = __snd_soc_dapm_set_pin(&card->dapm, pin, in snd_soc_dapm_put_pin_switch()
3618 !!ucontrol->value.integer.value[0]); in snd_soc_dapm_put_pin_switch()
3619 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_put_pin_switch()
3621 snd_soc_dapm_sync(&card->dapm); in snd_soc_dapm_put_pin_switch()
3633 int ret = -ENOMEM; in snd_soc_dapm_new_control_unlocked()
3640 w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, widget->name); in snd_soc_dapm_new_control_unlocked()
3642 w->name = kstrdup_const(widget->name, GFP_KERNEL); in snd_soc_dapm_new_control_unlocked()
3643 if (!w->name) in snd_soc_dapm_new_control_unlocked()
3646 switch (w->id) { in snd_soc_dapm_new_control_unlocked()
3648 w->regulator = devm_regulator_get(dapm->dev, widget->name); in snd_soc_dapm_new_control_unlocked()
3649 if (IS_ERR(w->regulator)) { in snd_soc_dapm_new_control_unlocked()
3650 ret = PTR_ERR(w->regulator); in snd_soc_dapm_new_control_unlocked()
3654 if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) { in snd_soc_dapm_new_control_unlocked()
3655 ret = regulator_allow_bypass(w->regulator, true); in snd_soc_dapm_new_control_unlocked()
3657 dev_warn(dapm->dev, in snd_soc_dapm_new_control_unlocked()
3659 w->name, ret); in snd_soc_dapm_new_control_unlocked()
3663 w->pinctrl = devm_pinctrl_get(dapm->dev); in snd_soc_dapm_new_control_unlocked()
3664 if (IS_ERR(w->pinctrl)) { in snd_soc_dapm_new_control_unlocked()
3665 ret = PTR_ERR(w->pinctrl); in snd_soc_dapm_new_control_unlocked()
3673 w->clk = devm_clk_get(dapm->dev, w->name); in snd_soc_dapm_new_control_unlocked()
3674 if (IS_ERR(w->clk)) { in snd_soc_dapm_new_control_unlocked()
3675 ret = PTR_ERR(w->clk); in snd_soc_dapm_new_control_unlocked()
3683 switch (w->id) { in snd_soc_dapm_new_control_unlocked()
3685 w->is_ep = SND_SOC_DAPM_EP_SOURCE; in snd_soc_dapm_new_control_unlocked()
3686 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3689 if (!dapm->card->fully_routed) in snd_soc_dapm_new_control_unlocked()
3690 w->is_ep = SND_SOC_DAPM_EP_SOURCE; in snd_soc_dapm_new_control_unlocked()
3691 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3695 w->is_ep = SND_SOC_DAPM_EP_SINK; in snd_soc_dapm_new_control_unlocked()
3696 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3699 if (!dapm->card->fully_routed) in snd_soc_dapm_new_control_unlocked()
3700 w->is_ep = SND_SOC_DAPM_EP_SINK; in snd_soc_dapm_new_control_unlocked()
3701 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3705 w->is_ep = SND_SOC_DAPM_EP_SOURCE; in snd_soc_dapm_new_control_unlocked()
3706 w->power_check = dapm_always_on_check_power; in snd_soc_dapm_new_control_unlocked()
3709 w->is_ep = SND_SOC_DAPM_EP_SINK; in snd_soc_dapm_new_control_unlocked()
3710 w->power_check = dapm_always_on_check_power; in snd_soc_dapm_new_control_unlocked()
3736 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3743 w->is_supply = 1; in snd_soc_dapm_new_control_unlocked()
3744 w->power_check = dapm_supply_check_power; in snd_soc_dapm_new_control_unlocked()
3747 w->power_check = dapm_always_on_check_power; in snd_soc_dapm_new_control_unlocked()
3751 w->dapm = dapm; in snd_soc_dapm_new_control_unlocked()
3752 INIT_LIST_HEAD(&w->list); in snd_soc_dapm_new_control_unlocked()
3753 INIT_LIST_HEAD(&w->dirty); in snd_soc_dapm_new_control_unlocked()
3755 list_add_tail(&w->list, &dapm->card->widgets); in snd_soc_dapm_new_control_unlocked()
3758 INIT_LIST_HEAD(&w->edges[dir]); in snd_soc_dapm_new_control_unlocked()
3759 w->endpoints[dir] = -1; in snd_soc_dapm_new_control_unlocked()
3763 w->connected = 1; in snd_soc_dapm_new_control_unlocked()
3767 dev_err_probe(dapm->dev, ret, "ASoC: Failed to request %s\n", in snd_soc_dapm_new_control_unlocked()
3768 w->name); in snd_soc_dapm_new_control_unlocked()
3769 kfree_const(w->name); in snd_soc_dapm_new_control_unlocked()
3771 kfree_const(w->sname); in snd_soc_dapm_new_control_unlocked()
3778 * snd_soc_dapm_new_control - create new dapm control
3792 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_new_control()
3794 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_new_control()
3801 * snd_soc_dapm_new_controls - create new dapm controls
3817 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); in snd_soc_dapm_new_controls()
3826 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_new_controls()
3855 return -ENOMEM; in snd_soc_dai_link_event_pre_pmu()
3859 ret = -ENOMEM; in snd_soc_dai_link_event_pre_pmu()
3863 substream->runtime = runtime; in snd_soc_dai_link_event_pre_pmu()
3865 substream->stream = SNDRV_PCM_STREAM_CAPTURE; in snd_soc_dai_link_event_pre_pmu()
3867 source = path->source->priv; in snd_soc_dai_link_event_pre_pmu()
3873 snd_soc_dai_activate(source, substream->stream); in snd_soc_dai_link_event_pre_pmu()
3876 substream->stream = SNDRV_PCM_STREAM_PLAYBACK; in snd_soc_dai_link_event_pre_pmu()
3878 sink = path->sink->priv; in snd_soc_dai_link_event_pre_pmu()
3884 snd_soc_dai_activate(sink, substream->stream); in snd_soc_dai_link_event_pre_pmu()
3887 substream->hw_opened = 1; in snd_soc_dai_link_event_pre_pmu()
3894 config = rtd->dai_link->params + rtd->params_select; in snd_soc_dai_link_event_pre_pmu()
3896 dev_err(w->dapm->dev, "ASoC: link config missing\n"); in snd_soc_dai_link_event_pre_pmu()
3897 ret = -EINVAL; in snd_soc_dai_link_event_pre_pmu()
3902 if (!config->formats) { in snd_soc_dai_link_event_pre_pmu()
3903 dev_warn(w->dapm->dev, "ASoC: Invalid format was specified\n"); in snd_soc_dai_link_event_pre_pmu()
3905 ret = -EINVAL; in snd_soc_dai_link_event_pre_pmu()
3909 fmt = ffs(config->formats) - 1; in snd_soc_dai_link_event_pre_pmu()
3912 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min = in snd_soc_dai_link_event_pre_pmu()
3913 config->rate_min; in snd_soc_dai_link_event_pre_pmu()
3914 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max = in snd_soc_dai_link_event_pre_pmu()
3915 config->rate_max; in snd_soc_dai_link_event_pre_pmu()
3916 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min in snd_soc_dai_link_event_pre_pmu()
3917 = config->channels_min; in snd_soc_dai_link_event_pre_pmu()
3918 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->max in snd_soc_dai_link_event_pre_pmu()
3919 = config->channels_max; in snd_soc_dai_link_event_pre_pmu()
3921 substream->stream = SNDRV_PCM_STREAM_CAPTURE; in snd_soc_dai_link_event_pre_pmu()
3923 source = path->source->priv; in snd_soc_dai_link_event_pre_pmu()
3932 substream->stream = SNDRV_PCM_STREAM_PLAYBACK; in snd_soc_dai_link_event_pre_pmu()
3934 sink = path->sink->priv; in snd_soc_dai_link_event_pre_pmu()
3943 runtime->format = params_format(params); in snd_soc_dai_link_event_pre_pmu()
3944 runtime->subformat = params_subformat(params); in snd_soc_dai_link_event_pre_pmu()
3945 runtime->channels = params_channels(params); in snd_soc_dai_link_event_pre_pmu()
3946 runtime->rate = params_rate(params); in snd_soc_dai_link_event_pre_pmu()
3960 struct snd_pcm_substream *substream = w->priv; in snd_soc_dai_link_event()
3961 int ret = 0, saved_stream = substream->stream; in snd_soc_dai_link_event()
3963 if (WARN_ON(list_empty(&w->edges[SND_SOC_DAPM_DIR_OUT]) || in snd_soc_dai_link_event()
3964 list_empty(&w->edges[SND_SOC_DAPM_DIR_IN]))) in snd_soc_dai_link_event()
3965 return -EINVAL; in snd_soc_dai_link_event()
3977 sink = path->sink->priv; in snd_soc_dai_link_event()
3986 sink = path->sink->priv; in snd_soc_dai_link_event()
3992 substream->stream = SNDRV_PCM_STREAM_CAPTURE; in snd_soc_dai_link_event()
3994 source = path->source->priv; in snd_soc_dai_link_event()
3998 substream->stream = SNDRV_PCM_STREAM_PLAYBACK; in snd_soc_dai_link_event()
4000 sink = path->sink->priv; in snd_soc_dai_link_event()
4004 substream->stream = SNDRV_PCM_STREAM_CAPTURE; in snd_soc_dai_link_event()
4006 source = path->source->priv; in snd_soc_dai_link_event()
4007 snd_soc_dai_deactivate(source, substream->stream); in snd_soc_dai_link_event()
4011 substream->stream = SNDRV_PCM_STREAM_PLAYBACK; in snd_soc_dai_link_event()
4013 sink = path->sink->priv; in snd_soc_dai_link_event()
4014 snd_soc_dai_deactivate(sink, substream->stream); in snd_soc_dai_link_event()
4020 kfree(substream->runtime); in snd_soc_dai_link_event()
4024 WARN(1, "Unknown event %d\n", event); in snd_soc_dai_link_event()
4025 ret = -EINVAL; in snd_soc_dai_link_event()
4030 substream->stream = saved_stream; in snd_soc_dai_link_event()
4038 struct snd_soc_pcm_runtime *rtd = w->priv; in snd_soc_dapm_dai_link_get()
4040 ucontrol->value.enumerated.item[0] = rtd->params_select; in snd_soc_dapm_dai_link_get()
4049 struct snd_soc_pcm_runtime *rtd = w->priv; in snd_soc_dapm_dai_link_put()
4052 if (w->power) in snd_soc_dapm_dai_link_put()
4053 return -EBUSY; in snd_soc_dapm_dai_link_put()
4055 if (ucontrol->value.enumerated.item[0] == rtd->params_select) in snd_soc_dapm_dai_link_put()
4058 if (ucontrol->value.enumerated.item[0] >= rtd->dai_link->num_params) in snd_soc_dapm_dai_link_put()
4059 return -EINVAL; in snd_soc_dapm_dai_link_put()
4061 rtd->params_select = ucontrol->value.enumerated.item[0]; in snd_soc_dapm_dai_link_put()
4074 devm_kfree(card->dev, (void *)*private_value); in snd_soc_dapm_free_kcontrol()
4080 devm_kfree(card->dev, (void *)w_param_text[count]); in snd_soc_dapm_free_kcontrol()
4081 devm_kfree(card->dev, w_param_text); in snd_soc_dapm_free_kcontrol()
4104 if (!config->stream_name) { in snd_soc_dapm_alloc_kcontrol()
4105 dev_warn(card->dapm.dev, in snd_soc_dapm_alloc_kcontrol()
4109 devm_kasprintf(card->dev, GFP_KERNEL, in snd_soc_dapm_alloc_kcontrol()
4113 w_param_text[count] = devm_kmemdup(card->dev, in snd_soc_dapm_alloc_kcontrol()
4114 config->stream_name, in snd_soc_dapm_alloc_kcontrol()
4115 strlen(config->stream_name) + 1, in snd_soc_dapm_alloc_kcontrol()
4127 (unsigned long) devm_kmemdup(card->dev, in snd_soc_dapm_alloc_kcontrol()
4131 dev_err(card->dev, "ASoC: Failed to create control for %s widget\n", in snd_soc_dapm_alloc_kcontrol()
4137 kcontrol_news = devm_kmemdup(card->dev, &kcontrol_dai_link[0], in snd_soc_dapm_alloc_kcontrol()
4141 dev_err(card->dev, "ASoC: Failed to create control for %s widget\n", in snd_soc_dapm_alloc_kcontrol()
4165 link_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s-%s", in snd_soc_dapm_new_dai()
4166 rtd->dai_link->name, id); in snd_soc_dapm_new_dai()
4168 return ERR_PTR(-ENOMEM); in snd_soc_dapm_new_dai()
4180 if (rtd->dai_link->num_params > 1) { in snd_soc_dapm_new_dai()
4181 w_param_text = devm_kcalloc(card->dev, in snd_soc_dapm_new_dai()
4182 rtd->dai_link->num_params, in snd_soc_dapm_new_dai()
4185 ret = -ENOMEM; in snd_soc_dapm_new_dai()
4193 rtd->dai_link->params, in snd_soc_dapm_new_dai()
4194 rtd->dai_link->num_params, in snd_soc_dapm_new_dai()
4197 ret = -ENOMEM; in snd_soc_dapm_new_dai()
4203 dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name); in snd_soc_dapm_new_dai()
4205 w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template); in snd_soc_dapm_new_dai()
4208 dev_err(rtd->dev, "ASoC: Failed to create %s widget: %d\n", in snd_soc_dapm_new_dai()
4213 w->priv = substream; in snd_soc_dapm_new_dai()
4218 devm_kfree(card->dev, (void *)template.kcontrol_news); in snd_soc_dapm_new_dai()
4220 rtd->dai_link->num_params, w_param_text); in snd_soc_dapm_new_dai()
4222 devm_kfree(card->dev, link_name); in snd_soc_dapm_new_dai()
4227 * snd_soc_dapm_new_dai_widgets - Create new DAPM widgets
4239 WARN_ON(dapm->dev != dai->dev); in snd_soc_dapm_new_dai_widgets()
4244 if (dai->driver->playback.stream_name) { in snd_soc_dapm_new_dai_widgets()
4246 template.name = dai->driver->playback.stream_name; in snd_soc_dapm_new_dai_widgets()
4247 template.sname = dai->driver->playback.stream_name; in snd_soc_dapm_new_dai_widgets()
4249 dev_dbg(dai->dev, "ASoC: adding %s widget\n", in snd_soc_dapm_new_dai_widgets()
4256 w->priv = dai; in snd_soc_dapm_new_dai_widgets()
4257 dai->playback_widget = w; in snd_soc_dapm_new_dai_widgets()
4260 if (dai->driver->capture.stream_name) { in snd_soc_dapm_new_dai_widgets()
4262 template.name = dai->driver->capture.stream_name; in snd_soc_dapm_new_dai_widgets()
4263 template.sname = dai->driver->capture.stream_name; in snd_soc_dapm_new_dai_widgets()
4265 dev_dbg(dai->dev, "ASoC: adding %s widget\n", in snd_soc_dapm_new_dai_widgets()
4272 w->priv = dai; in snd_soc_dapm_new_dai_widgets()
4273 dai->capture_widget = w; in snd_soc_dapm_new_dai_widgets()
4288 switch (dai_w->id) { in snd_soc_dapm_link_dai_widgets()
4297 if (!dai_w->priv) { in snd_soc_dapm_link_dai_widgets()
4298 dev_dbg(card->dev, "dai widget %s has no DAI\n", in snd_soc_dapm_link_dai_widgets()
4299 dai_w->name); in snd_soc_dapm_link_dai_widgets()
4303 dai = dai_w->priv; in snd_soc_dapm_link_dai_widgets()
4307 if (w->dapm != dai_w->dapm) in snd_soc_dapm_link_dai_widgets()
4310 switch (w->id) { in snd_soc_dapm_link_dai_widgets()
4318 if (!w->sname || !strstr(w->sname, dai_w->sname)) in snd_soc_dapm_link_dai_widgets()
4321 if (dai_w->id == snd_soc_dapm_dai_in) { in snd_soc_dapm_link_dai_widgets()
4328 dev_dbg(dai->dev, "%s -> %s\n", src->name, sink->name); in snd_soc_dapm_link_dai_widgets()
4329 snd_soc_dapm_add_path(w->dapm, src, sink, NULL, NULL); in snd_soc_dapm_link_dai_widgets()
4343 dev_dbg(dapm->dev, "connected DAI link %s:%s -> %s:%s\n", in dapm_connect_dai_routes()
4344 src_dai->component->name, src->name, in dapm_connect_dai_routes()
4345 sink_dai->component->name, sink->name); in dapm_connect_dai_routes()
4360 struct snd_soc_dai_link *dai_link = rtd->dai_link; in dapm_connect_dai_pair()
4363 struct snd_pcm_str *streams = rtd->pcm->streams; in dapm_connect_dai_pair()
4366 if (dai_link->params) { in dapm_connect_dai_pair()
4367 playback_cpu = cpu_dai->capture_widget; in dapm_connect_dai_pair()
4368 capture_cpu = cpu_dai->playback_widget; in dapm_connect_dai_pair()
4370 playback_cpu = cpu_dai->playback_widget; in dapm_connect_dai_pair()
4371 capture_cpu = cpu_dai->capture_widget; in dapm_connect_dai_pair()
4376 codec = codec_dai->playback_widget; in dapm_connect_dai_pair()
4379 if (dai_link->params && !rtd->c2c_widget[stream]) { in dapm_connect_dai_pair()
4384 rtd->c2c_widget[stream] = dai; in dapm_connect_dai_pair()
4387 dapm_connect_dai_routes(&card->dapm, cpu_dai, playback_cpu, in dapm_connect_dai_pair()
4388 rtd->c2c_widget[stream], in dapm_connect_dai_pair()
4395 codec = codec_dai->capture_widget; in dapm_connect_dai_pair()
4398 if (dai_link->params && !rtd->c2c_widget[stream]) { in dapm_connect_dai_pair()
4403 rtd->c2c_widget[stream] = dai; in dapm_connect_dai_pair()
4406 dapm_connect_dai_routes(&card->dapm, codec_dai, codec, in dapm_connect_dai_pair()
4407 rtd->c2c_widget[stream], in dapm_connect_dai_pair()
4424 if (w->id == snd_soc_dapm_dai_in) { in soc_dapm_dai_stream_event()
4434 w->active = 1; in soc_dapm_dai_stream_event()
4435 w->is_ep = ep; in soc_dapm_dai_stream_event()
4438 w->active = 0; in soc_dapm_dai_stream_event()
4439 w->is_ep = 0; in soc_dapm_dai_stream_event()
4460 * CODEC<->CODEC links have no direct connection. in snd_soc_dapm_connect_dai_link_widgets()
4462 if (rtd->dai_link->dynamic) in snd_soc_dapm_connect_dai_link_widgets()
4465 if (rtd->dai_link->num_cpus == 1) { in snd_soc_dapm_connect_dai_link_widgets()
4469 } else if (rtd->dai_link->num_codecs == rtd->dai_link->num_cpus) { in snd_soc_dapm_connect_dai_link_widgets()
4474 dev_err(card->dev, in snd_soc_dapm_connect_dai_link_widgets()
4489 dapm_power_widgets(rtd->card, event); in soc_dapm_stream_event()
4493 * snd_soc_dapm_stream_event - send a stream event to the dapm core
4506 struct snd_soc_card *card = rtd->card; in snd_soc_dapm_stream_event()
4508 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_stream_event()
4510 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_stream_event()
4523 rtd->pop_wait = 1; in snd_soc_dapm_stream_stop()
4525 &rtd->delayed_work, in snd_soc_dapm_stream_stop()
4526 msecs_to_jiffies(rtd->pmdown_time)); in snd_soc_dapm_stream_stop()
4537 * snd_soc_dapm_enable_pin_unlocked - enable pin.
4557 * snd_soc_dapm_enable_pin - enable pin.
4571 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_enable_pin()
4575 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_enable_pin()
4582 * snd_soc_dapm_force_enable_pin_unlocked - force a pin to be enabled
4601 dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin); in snd_soc_dapm_force_enable_pin_unlocked()
4602 return -EINVAL; in snd_soc_dapm_force_enable_pin_unlocked()
4605 dev_dbg(w->dapm->dev, "ASoC: force enable pin %s\n", pin); in snd_soc_dapm_force_enable_pin_unlocked()
4606 if (!w->connected) { in snd_soc_dapm_force_enable_pin_unlocked()
4608 * w->force does not affect the number of input or output paths, in snd_soc_dapm_force_enable_pin_unlocked()
4609 * so we only have to recheck if w->connected is changed in snd_soc_dapm_force_enable_pin_unlocked()
4613 w->connected = 1; in snd_soc_dapm_force_enable_pin_unlocked()
4615 w->force = 1; in snd_soc_dapm_force_enable_pin_unlocked()
4623 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
4639 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_force_enable_pin()
4643 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_force_enable_pin()
4650 * snd_soc_dapm_disable_pin_unlocked - disable pin.
4669 * snd_soc_dapm_disable_pin - disable pin.
4683 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_disable_pin()
4687 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_disable_pin()
4694 * snd_soc_dapm_nc_pin_unlocked - permanently disable pin.
4717 * snd_soc_dapm_nc_pin - permanently disable pin.
4734 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_nc_pin()
4738 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_nc_pin()
4745 * snd_soc_dapm_get_pin_status - get audio pin status
4749 * Get audio pin status - connected or disconnected.
4759 return w->connected; in snd_soc_dapm_get_pin_status()
4766 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
4782 dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin); in snd_soc_dapm_ignore_suspend()
4783 return -EINVAL; in snd_soc_dapm_ignore_suspend()
4786 w->ignore_suspend = 1; in snd_soc_dapm_ignore_suspend()
4793 * snd_soc_dapm_free - free dapm resources
4802 list_del(&dapm->list); in snd_soc_dapm_free()
4810 dapm->card = card; in snd_soc_dapm_init()
4811 dapm->component = component; in snd_soc_dapm_init()
4812 dapm->bias_level = SND_SOC_BIAS_OFF; in snd_soc_dapm_init()
4815 dapm->dev = component->dev; in snd_soc_dapm_init()
4816 dapm->idle_bias_off = !component->driver->idle_bias_on; in snd_soc_dapm_init()
4817 dapm->suspend_bias_off = component->driver->suspend_bias_off; in snd_soc_dapm_init()
4819 dapm->dev = card->dev; in snd_soc_dapm_init()
4822 INIT_LIST_HEAD(&dapm->list); in snd_soc_dapm_init()
4824 list_add(&dapm->list, &card->dapm_list); in snd_soc_dapm_init()
4830 struct snd_soc_card *card = dapm->card; in soc_dapm_shutdown_dapm()
4835 mutex_lock(&card->dapm_mutex); in soc_dapm_shutdown_dapm()
4837 for_each_card_widgets(dapm->card, w) { in soc_dapm_shutdown_dapm()
4838 if (w->dapm != dapm) in soc_dapm_shutdown_dapm()
4840 if (w->power) { in soc_dapm_shutdown_dapm()
4842 w->new_power = 0; in soc_dapm_shutdown_dapm()
4851 if (dapm->bias_level == SND_SOC_BIAS_ON) in soc_dapm_shutdown_dapm()
4855 if (dapm->bias_level == SND_SOC_BIAS_PREPARE) in soc_dapm_shutdown_dapm()
4860 mutex_unlock(&card->dapm_mutex); in soc_dapm_shutdown_dapm()
4864 * snd_soc_dapm_shutdown - callback for system shutdown
4871 if (dapm != &card->dapm) { in snd_soc_dapm_shutdown()
4873 if (dapm->bias_level == SND_SOC_BIAS_STANDBY) in snd_soc_dapm_shutdown()
4879 soc_dapm_shutdown_dapm(&card->dapm); in snd_soc_dapm_shutdown()
4880 if (card->dapm.bias_level == SND_SOC_BIAS_STANDBY) in snd_soc_dapm_shutdown()
4881 snd_soc_dapm_set_bias_level(&card->dapm, in snd_soc_dapm_shutdown()
4887 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");