Lines Matching +full:adc +full:- +full:channel +full:- +full:clk +full:- +full:src

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
32 #include <linux/clk.h>
42 #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++;
65 /* dapm power sequences - make this per codec in the future */
150 if (dapm->card && dapm->card->instantiated) in dapm_assert_locked()
151 lockdep_assert_held(&dapm->card->dapm_mutex); in dapm_assert_locked()
183 return !list_empty(&w->dirty); in dapm_dirty_widget()
188 dapm_assert_locked(w->dapm); in dapm_mark_dirty()
191 dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n", in dapm_mark_dirty()
192 w->name, reason); in dapm_mark_dirty()
193 list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty); in dapm_mark_dirty()
212 dapm_assert_locked(w->dapm); in dapm_widget_invalidate_paths()
214 if (w->endpoints[dir] == -1) in dapm_widget_invalidate_paths()
217 list_add_tail(&w->work_list, &list); in dapm_widget_invalidate_paths()
218 w->endpoints[dir] = -1; in dapm_widget_invalidate_paths()
222 if (p->is_supply || p->weak || !p->connect) in dapm_widget_invalidate_paths()
224 node = p->node[rdir]; in dapm_widget_invalidate_paths()
225 if (node->endpoints[dir] != -1) { in dapm_widget_invalidate_paths()
226 node->endpoints[dir] = -1; in dapm_widget_invalidate_paths()
227 list_add_tail(&node->work_list, &list); in dapm_widget_invalidate_paths()
234 * dapm_widget_invalidate_input_paths() - Invalidate the cached number of
251 * dapm_widget_invalidate_output_paths() - Invalidate the cached number of
268 * dapm_path_invalidate() - Invalidates the cached number of inputs and outputs
284 if (p->weak || p->is_supply) in dapm_path_invalidate()
291 * so there is no need to re-check the path. in dapm_path_invalidate()
293 if (p->source->endpoints[SND_SOC_DAPM_DIR_IN] != 0) in dapm_path_invalidate()
294 dapm_widget_invalidate_input_paths(p->sink); in dapm_path_invalidate()
295 if (p->sink->endpoints[SND_SOC_DAPM_DIR_OUT] != 0) in dapm_path_invalidate()
296 dapm_widget_invalidate_output_paths(p->source); in dapm_path_invalidate()
303 mutex_lock(&card->dapm_mutex); in dapm_mark_endpoints_dirty()
306 if (w->is_ep) { in dapm_mark_endpoints_dirty()
308 if (w->is_ep & SND_SOC_DAPM_EP_SINK) in dapm_mark_endpoints_dirty()
310 if (w->is_ep & SND_SOC_DAPM_EP_SOURCE) in dapm_mark_endpoints_dirty()
315 mutex_unlock(&card->dapm_mutex); in dapm_mark_endpoints_dirty()
330 * w->name is duplicated in caller, but w->sname isn't. in dapm_cnew_widget()
333 if (_widget->sname) { in dapm_cnew_widget()
334 w->sname = kstrdup_const(_widget->sname, GFP_KERNEL); in dapm_cnew_widget()
335 if (!w->sname) { in dapm_cnew_widget()
361 return -ENOMEM; in dapm_kcontrol_data_alloc()
363 INIT_LIST_HEAD(&data->paths); in dapm_kcontrol_data_alloc()
365 switch (widget->id) { in dapm_kcontrol_data_alloc()
369 mc = (struct soc_mixer_control *)kcontrol->private_value; in dapm_kcontrol_data_alloc()
371 if (mc->autodisable && snd_soc_volsw_is_stereo(mc)) in dapm_kcontrol_data_alloc()
372 dev_warn(widget->dapm->dev, in dapm_kcontrol_data_alloc()
376 if (mc->autodisable) { in dapm_kcontrol_data_alloc()
382 ret = -ENOMEM; in dapm_kcontrol_data_alloc()
387 template.reg = mc->reg; in dapm_kcontrol_data_alloc()
388 template.mask = (1 << fls(mc->max)) - 1; in dapm_kcontrol_data_alloc()
389 template.shift = mc->shift; in dapm_kcontrol_data_alloc()
390 if (mc->invert) in dapm_kcontrol_data_alloc()
391 template.off_val = mc->max; in dapm_kcontrol_data_alloc()
398 data->value = template.on_val; in dapm_kcontrol_data_alloc()
400 data->widget = in dapm_kcontrol_data_alloc()
401 snd_soc_dapm_new_control_unlocked(widget->dapm, in dapm_kcontrol_data_alloc()
404 if (IS_ERR(data->widget)) { in dapm_kcontrol_data_alloc()
405 ret = PTR_ERR(data->widget); in dapm_kcontrol_data_alloc()
412 e = (struct soc_enum *)kcontrol->private_value; in dapm_kcontrol_data_alloc()
414 if (e->autodisable) { in dapm_kcontrol_data_alloc()
420 ret = -ENOMEM; in dapm_kcontrol_data_alloc()
425 template.reg = e->reg; in dapm_kcontrol_data_alloc()
426 template.mask = e->mask; in dapm_kcontrol_data_alloc()
427 template.shift = e->shift_l; in dapm_kcontrol_data_alloc()
433 data->value = template.on_val; in dapm_kcontrol_data_alloc()
435 data->widget = snd_soc_dapm_new_control_unlocked( in dapm_kcontrol_data_alloc()
436 widget->dapm, &template); in dapm_kcontrol_data_alloc()
438 if (IS_ERR(data->widget)) { in dapm_kcontrol_data_alloc()
439 ret = PTR_ERR(data->widget); in dapm_kcontrol_data_alloc()
443 snd_soc_dapm_add_path(widget->dapm, data->widget, in dapm_kcontrol_data_alloc()
451 kcontrol->private_data = data; in dapm_kcontrol_data_alloc()
464 list_del(&data->paths); in dapm_kcontrol_free()
465 kfree(data->wlist); in dapm_kcontrol_free()
474 return data->wlist; in dapm_kcontrol_get_wlist()
484 if (data->wlist) in dapm_kcontrol_add_widget()
485 n = data->wlist->num_widgets + 1; in dapm_kcontrol_add_widget()
489 new_wlist = krealloc(data->wlist, in dapm_kcontrol_add_widget()
493 return -ENOMEM; in dapm_kcontrol_add_widget()
495 new_wlist->widgets[n - 1] = widget; in dapm_kcontrol_add_widget()
496 new_wlist->num_widgets = n; in dapm_kcontrol_add_widget()
498 data->wlist = new_wlist; in dapm_kcontrol_add_widget()
508 list_add_tail(&path->list_kcontrol, &data->paths); in dapm_kcontrol_add_path()
515 if (!data->widget) in dapm_kcontrol_is_powered()
518 return data->widget->power; in dapm_kcontrol_is_powered()
526 return &data->paths; in dapm_kcontrol_get_path_list()
537 return data->value; in dapm_kcontrol_get_value()
546 if (data->value == value) in dapm_kcontrol_set_value()
549 if (data->widget) { in dapm_kcontrol_set_value()
550 switch (dapm_kcontrol_get_wlist(kcontrol)->widgets[0]->id) { in dapm_kcontrol_set_value()
554 data->widget->on_val = value & data->widget->mask; in dapm_kcontrol_set_value()
558 data->widget->on_val = value >> data->widget->shift; in dapm_kcontrol_set_value()
561 data->widget->on_val = value; in dapm_kcontrol_set_value()
566 data->value = value; in dapm_kcontrol_set_value()
572 * snd_soc_dapm_kcontrol_widget() - Returns the widget associated to a
579 return dapm_kcontrol_get_wlist(kcontrol)->widgets[0]; in snd_soc_dapm_kcontrol_widget()
584 * snd_soc_dapm_kcontrol_dapm() - Returns the dapm context associated to a
594 return dapm_kcontrol_get_wlist(kcontrol)->widgets[0]->dapm; in snd_soc_dapm_kcontrol_dapm()
602 lockdep_assert_held(&card->dapm_mutex); in dapm_reset()
604 memset(&card->dapm_stats, 0, sizeof(card->dapm_stats)); in dapm_reset()
607 w->new_power = w->power; in dapm_reset()
608 w->power_checked = false; in dapm_reset()
614 if (!dapm->component) in soc_dapm_prefix()
616 return dapm->component->name_prefix; in soc_dapm_prefix()
621 if (!dapm->component) in soc_dapm_read()
622 return -EIO; in soc_dapm_read()
623 return snd_soc_component_read(dapm->component, reg); in soc_dapm_read()
629 if (!dapm->component) in soc_dapm_update_bits()
630 return -EIO; in soc_dapm_update_bits()
631 return snd_soc_component_update_bits(dapm->component, reg, in soc_dapm_update_bits()
638 if (!dapm->component) in soc_dapm_test_bits()
639 return -EIO; in soc_dapm_test_bits()
640 return snd_soc_component_test_bits(dapm->component, reg, mask, value); in soc_dapm_test_bits()
645 if (dapm->component) in soc_dapm_async_complete()
646 snd_soc_component_async_complete(dapm->component); in soc_dapm_async_complete()
652 struct snd_soc_dapm_widget *w = wcache->widget; in dapm_wcache_lookup()
655 struct list_head *wlist = &w->dapm->card->widgets; in dapm_wcache_lookup()
660 if (!strcmp(name, w->name)) in dapm_wcache_lookup()
674 wcache->widget = w; in dapm_wcache_update()
678 * snd_soc_dapm_force_bias_level() - Sets the DAPM bias level
699 if (dapm->component) in snd_soc_dapm_force_bias_level()
700 ret = snd_soc_component_set_bias_level(dapm->component, level); in snd_soc_dapm_force_bias_level()
703 dapm->bias_level = level; in snd_soc_dapm_force_bias_level()
710 * snd_soc_dapm_set_bias_level - set the bias level for the system
721 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_set_bias_level()
730 if (!card || dapm != &card->dapm) in snd_soc_dapm_set_bias_level()
748 const struct snd_kcontrol_new *kcontrol = &w->kcontrol_news[0]; in dapm_connect_mux()
749 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in dapm_connect_mux()
753 if (e->reg != SND_SOC_NOPM) { in dapm_connect_mux()
755 val = soc_dapm_read(dapm, e->reg); in dapm_connect_mux()
756 val = (val >> e->shift_l) & e->mask; in dapm_connect_mux()
768 i = match_string(e->texts, e->items, control_name); in dapm_connect_mux()
770 return -ENODEV; in dapm_connect_mux()
772 path->name = e->texts[i]; in dapm_connect_mux()
773 path->connect = (i == item); in dapm_connect_mux()
783 p->sink->kcontrol_news[i].private_value; in dapm_set_mixer_path_status()
784 unsigned int reg = mc->reg; in dapm_set_mixer_path_status()
785 unsigned int invert = mc->invert; in dapm_set_mixer_path_status()
788 unsigned int shift = mc->shift; in dapm_set_mixer_path_status()
789 unsigned int max = mc->max; in dapm_set_mixer_path_status()
790 unsigned int mask = (1 << fls(max)) - 1; in dapm_set_mixer_path_status()
791 unsigned int val = soc_dapm_read(p->sink->dapm, reg); in dapm_set_mixer_path_status()
802 * first path is the left channel, and all remaining in dapm_set_mixer_path_status()
803 * paths are the right channel. in dapm_set_mixer_path_status()
806 if (reg != mc->rreg) in dapm_set_mixer_path_status()
807 val = soc_dapm_read(p->sink->dapm, mc->rreg); in dapm_set_mixer_path_status()
808 val = (val >> mc->rshift) & mask; in dapm_set_mixer_path_status()
813 val = max - val; in dapm_set_mixer_path_status()
814 p->connect = !!val; in dapm_set_mixer_path_status()
822 p->connect = invert; in dapm_set_mixer_path_status()
833 for (i = 0; i < path->sink->num_kcontrols; i++) { in dapm_connect_mixer()
834 if (!strcmp(control_name, path->sink->kcontrol_news[i].name)) { in dapm_connect_mixer()
835 path->name = path->sink->kcontrol_news[i].name; in dapm_connect_mixer()
840 return -ENODEV; in dapm_connect_mixer()
853 for_each_card_widgets(dapm->card, w) { in dapm_is_shared_kcontrol()
854 if (w == kcontrolw || w->dapm != kcontrolw->dapm) in dapm_is_shared_kcontrol()
856 for (i = 0; i < w->num_kcontrols; i++) { in dapm_is_shared_kcontrol()
857 if (&w->kcontrol_news[i] == kcontrol_new) { in dapm_is_shared_kcontrol()
858 if (w->kcontrols) in dapm_is_shared_kcontrol()
859 *kcontrol = w->kcontrols[i]; in dapm_is_shared_kcontrol()
875 struct snd_soc_dapm_context *dapm = w->dapm; in dapm_create_or_share_kcontrol()
876 struct snd_card *card = dapm->card->snd_card; in dapm_create_or_share_kcontrol()
892 shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[kci], in dapm_create_or_share_kcontrol()
900 switch (w->id) { in dapm_create_or_share_kcontrol()
919 return -EINVAL; in dapm_create_or_share_kcontrol()
931 w->name + prefix_len, in dapm_create_or_share_kcontrol()
932 w->kcontrol_news[kci].name); in dapm_create_or_share_kcontrol()
934 return -ENOMEM; in dapm_create_or_share_kcontrol()
939 name = w->name + prefix_len; in dapm_create_or_share_kcontrol()
942 name = w->kcontrol_news[kci].name; in dapm_create_or_share_kcontrol()
945 kcontrol = snd_soc_cnew(&w->kcontrol_news[kci], NULL, name, in dapm_create_or_share_kcontrol()
948 ret = -ENOMEM; in dapm_create_or_share_kcontrol()
952 kcontrol->private_free = dapm_kcontrol_free; in dapm_create_or_share_kcontrol()
962 dev_err(dapm->dev, in dapm_create_or_share_kcontrol()
964 w->name, name, ret); in dapm_create_or_share_kcontrol()
971 w->kcontrols[kci] = kcontrol; in dapm_create_or_share_kcontrol()
987 for (i = 0; i < w->num_kcontrols; i++) { in dapm_new_mixer()
991 if (path->name != (char *)w->kcontrol_news[i].name) in dapm_new_mixer()
994 if (!w->kcontrols[i]) { in dapm_new_mixer()
1000 dapm_kcontrol_add_path(w->kcontrols[i], path); in dapm_new_mixer()
1002 data = snd_kcontrol_chip(w->kcontrols[i]); in dapm_new_mixer()
1003 if (data->widget) in dapm_new_mixer()
1004 snd_soc_dapm_add_path(data->widget->dapm, in dapm_new_mixer()
1005 data->widget, in dapm_new_mixer()
1006 path->source, in dapm_new_mixer()
1017 struct snd_soc_dapm_context *dapm = w->dapm; in dapm_new_mux()
1023 switch (w->id) { in dapm_new_mux()
1033 return -EINVAL; in dapm_new_mux()
1036 if (w->num_kcontrols != 1) { in dapm_new_mux()
1037 dev_err(dapm->dev, in dapm_new_mux()
1039 w->name); in dapm_new_mux()
1040 return -EINVAL; in dapm_new_mux()
1043 if (list_empty(&w->edges[dir])) { in dapm_new_mux()
1044 dev_err(dapm->dev, "ASoC: %s %s has no paths\n", type, w->name); in dapm_new_mux()
1045 return -EINVAL; in dapm_new_mux()
1053 if (path->name) in dapm_new_mux()
1054 dapm_kcontrol_add_path(w->kcontrols[0], path); in dapm_new_mux()
1065 for (i = 0; i < w->num_kcontrols; i++) { in dapm_new_pga()
1078 struct snd_soc_pcm_runtime *rtd = w->priv; in dapm_new_dai_link()
1081 if (rtd->dai_link->num_params <= 1) in dapm_new_dai_link()
1085 for (i = 0; i < w->num_kcontrols; i++) { in dapm_new_dai_link()
1086 struct snd_soc_dapm_context *dapm = w->dapm; in dapm_new_dai_link()
1087 struct snd_card *card = dapm->card->snd_card; in dapm_new_dai_link()
1088 struct snd_kcontrol *kcontrol = snd_soc_cnew(&w->kcontrol_news[i], in dapm_new_dai_link()
1089 w, w->name, NULL); in dapm_new_dai_link()
1093 dev_err(dapm->dev, in dapm_new_dai_link()
1095 w->name, w->kcontrol_news[i].name, ret); in dapm_new_dai_link()
1098 kcontrol->private_data = w; in dapm_new_dai_link()
1099 w->kcontrols[i] = kcontrol; in dapm_new_dai_link()
1106 * the ALSA card - when we are suspending the ALSA state for the card
1111 int level = snd_power_get_state(widget->dapm->card->snd_card); in snd_soc_dapm_suspend_check()
1116 if (widget->ignore_suspend) in snd_soc_dapm_suspend_check()
1117 dev_dbg(widget->dapm->dev, "ASoC: %s ignoring suspend\n", in snd_soc_dapm_suspend_check()
1118 widget->name); in snd_soc_dapm_suspend_check()
1119 return widget->ignore_suspend; in snd_soc_dapm_suspend_check()
1143 return -ENOMEM; in dapm_widget_list_create()
1146 (*list)->widgets[i++] = w; in dapm_widget_list_create()
1148 (*list)->num_widgets = i; in dapm_widget_list_create()
1164 widget->endpoints[dir] = -1; in invalidate_paths_ep()
1167 if (path->weak || path->is_supply) in invalidate_paths_ep()
1170 if (path->walking) in invalidate_paths_ep()
1173 if (path->connect) { in invalidate_paths_ep()
1174 path->walking = 1; in invalidate_paths_ep()
1175 invalidate_paths_ep(path->node[dir], dir); in invalidate_paths_ep()
1176 path->walking = 0; in invalidate_paths_ep()
1200 if (widget->endpoints[dir] >= 0) in is_connected_ep()
1201 return widget->endpoints[dir]; in is_connected_ep()
1207 list_add_tail(&widget->work_list, list); in is_connected_ep()
1214 if ((widget->is_ep & SND_SOC_DAPM_DIR_TO_EP(dir)) && widget->connected) { in is_connected_ep()
1215 widget->endpoints[dir] = snd_soc_dapm_suspend_check(widget); in is_connected_ep()
1216 return widget->endpoints[dir]; in is_connected_ep()
1222 if (path->weak || path->is_supply) in is_connected_ep()
1225 if (path->walking) in is_connected_ep()
1230 if (path->connect) { in is_connected_ep()
1231 path->walking = 1; in is_connected_ep()
1232 con += fn(path->node[dir], list, custom_stop_condition); in is_connected_ep()
1233 path->walking = 0; in is_connected_ep()
1237 widget->endpoints[dir] = con; in is_connected_ep()
1279 * snd_soc_dapm_dai_get_connected_widgets - query audio path and it's widgets.
1302 struct snd_soc_card *card = dai->component->card; in snd_soc_dapm_dai_get_connected_widgets()
1308 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_dai_get_connected_widgets()
1311 w = dai->playback_widget; in snd_soc_dapm_dai_get_connected_widgets()
1316 w = dai->capture_widget; in snd_soc_dapm_dai_get_connected_widgets()
1330 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_dai_get_connected_widgets()
1348 soc_dapm_async_complete(w->dapm); in dapm_regulator_event()
1351 if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) { in dapm_regulator_event()
1352 ret = regulator_allow_bypass(w->regulator, false); in dapm_regulator_event()
1354 dev_warn(w->dapm->dev, in dapm_regulator_event()
1356 w->name, ret); in dapm_regulator_event()
1359 return regulator_enable(w->regulator); in dapm_regulator_event()
1361 if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) { in dapm_regulator_event()
1362 ret = regulator_allow_bypass(w->regulator, true); in dapm_regulator_event()
1364 dev_warn(w->dapm->dev, in dapm_regulator_event()
1366 w->name, ret); in dapm_regulator_event()
1369 return regulator_disable_deferred(w->regulator, w->shift); in dapm_regulator_event()
1380 struct snd_soc_dapm_pinctrl_priv *priv = w->priv; in dapm_pinctrl_event()
1381 struct pinctrl *p = w->pinctrl; in dapm_pinctrl_event()
1385 return -EIO; in dapm_pinctrl_event()
1388 s = pinctrl_lookup_state(p, priv->active_state); in dapm_pinctrl_event()
1390 s = pinctrl_lookup_state(p, priv->sleep_state); in dapm_pinctrl_event()
1405 if (!w->clk) in dapm_clock_event()
1406 return -EIO; in dapm_clock_event()
1408 soc_dapm_async_complete(w->dapm); in dapm_clock_event()
1411 return clk_prepare_enable(w->clk); in dapm_clock_event()
1413 clk_disable_unprepare(w->clk); in dapm_clock_event()
1423 if (w->power_checked) in dapm_widget_power_check()
1424 return w->new_power; in dapm_widget_power_check()
1426 if (w->force) in dapm_widget_power_check()
1427 w->new_power = 1; in dapm_widget_power_check()
1429 w->new_power = w->power_check(w); in dapm_widget_power_check()
1431 w->power_checked = true; in dapm_widget_power_check()
1433 return w->new_power; in dapm_widget_power_check()
1459 if (path->weak) in dapm_supply_check_power()
1462 if (path->connected && in dapm_supply_check_power()
1463 !path->connected(path->source, path->sink)) in dapm_supply_check_power()
1466 if (dapm_widget_power_check(path->sink)) in dapm_supply_check_power()
1475 return w->connected; in dapm_always_on_check_power()
1492 WARN_ONCE(sort[a->id] == 0, "offset a->id %d not initialized\n", a->id); in dapm_seq_compare()
1493 WARN_ONCE(sort[b->id] == 0, "offset b->id %d not initialized\n", b->id); in dapm_seq_compare()
1495 if (sort[a->id] != sort[b->id]) in dapm_seq_compare()
1496 return sort[a->id] - sort[b->id]; in dapm_seq_compare()
1497 if (a->subseq != b->subseq) { in dapm_seq_compare()
1499 return a->subseq - b->subseq; in dapm_seq_compare()
1501 return b->subseq - a->subseq; in dapm_seq_compare()
1503 if (a->reg != b->reg) in dapm_seq_compare()
1504 return a->reg - b->reg; in dapm_seq_compare()
1505 if (a->dapm != b->dapm) in dapm_seq_compare()
1506 return (unsigned long)a->dapm - (unsigned long)b->dapm; in dapm_seq_compare()
1520 list_add_tail(&new_widget->power_list, &w->power_list); in dapm_seq_insert()
1524 list_add_tail(&new_widget->power_list, list); in dapm_seq_insert()
1563 if (w->new_power != power) in dapm_seq_check_event()
1566 if (w->event && (w->event_flags & event)) { in dapm_seq_check_event()
1569 pop_dbg(w->dapm->dev, card->pop_time, "pop test : %s %s\n", in dapm_seq_check_event()
1570 w->name, ev_name); in dapm_seq_check_event()
1571 soc_dapm_async_complete(w->dapm); in dapm_seq_check_event()
1573 ret = w->event(w, NULL, event); in dapm_seq_check_event()
1576 dev_err(w->dapm->dev, "ASoC: %s: %s event failed: %d\n", in dapm_seq_check_event()
1577 ev_name, w->name, ret); in dapm_seq_check_event()
1592 reg = w->reg; in dapm_seq_run_coalesced()
1593 dapm = w->dapm; in dapm_seq_run_coalesced()
1596 WARN_ON(reg != w->reg || dapm != w->dapm); in dapm_seq_run_coalesced()
1597 w->power = w->new_power; in dapm_seq_run_coalesced()
1599 mask |= w->mask << w->shift; in dapm_seq_run_coalesced()
1600 if (w->power) in dapm_seq_run_coalesced()
1601 value |= w->on_val << w->shift; in dapm_seq_run_coalesced()
1603 value |= w->off_val << w->shift; in dapm_seq_run_coalesced()
1605 pop_dbg(dapm->dev, card->pop_time, in dapm_seq_run_coalesced()
1607 w->name, reg, value, mask); in dapm_seq_run_coalesced()
1619 pop_dbg(dapm->dev, card->pop_time, in dapm_seq_run_coalesced()
1621 value, mask, reg, card->pop_time); in dapm_seq_run_coalesced()
1622 pop_wait(card->pop_time); in dapm_seq_run_coalesced()
1634 * We walk over a pre-sorted list of widgets to apply power to. In
1646 int cur_sort = -1; in dapm_seq_run()
1647 int cur_subseq = -1; in dapm_seq_run()
1662 if (sort[w->id] != cur_sort || w->reg != cur_reg || in dapm_seq_run()
1663 w->dapm != cur_dapm || w->subseq != cur_subseq) { in dapm_seq_run()
1667 if (cur_dapm && cur_dapm->component) { in dapm_seq_run()
1671 cur_dapm->component, in dapm_seq_run()
1675 if (cur_dapm && w->dapm != cur_dapm) in dapm_seq_run()
1679 cur_sort = -1; in dapm_seq_run()
1685 switch (w->id) { in dapm_seq_run()
1687 if (!w->event) in dapm_seq_run()
1692 ret = w->event(w, in dapm_seq_run()
1695 ret = w->event(w, in dapm_seq_run()
1700 if (!w->event) in dapm_seq_run()
1705 ret = w->event(w, in dapm_seq_run()
1708 ret = w->event(w, in dapm_seq_run()
1714 cur_sort = sort[w->id]; in dapm_seq_run()
1715 cur_subseq = w->subseq; in dapm_seq_run()
1716 cur_reg = w->reg; in dapm_seq_run()
1717 cur_dapm = w->dapm; in dapm_seq_run()
1718 list_move(&w->power_list, &pending); in dapm_seq_run()
1723 dev_err(w->dapm->dev, in dapm_seq_run()
1730 if (cur_dapm && cur_dapm->component) { in dapm_seq_run()
1734 cur_dapm->component, in dapm_seq_run()
1744 struct snd_soc_dapm_update *update = card->update; in dapm_widget_update()
1750 if (!update || !dapm_kcontrol_is_powered(update->kcontrol)) in dapm_widget_update()
1753 wlist = dapm_kcontrol_get_wlist(update->kcontrol); in dapm_widget_update()
1756 if (w->event && (w->event_flags & SND_SOC_DAPM_PRE_REG)) { in dapm_widget_update()
1757 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG); in dapm_widget_update()
1759 dev_err(w->dapm->dev, "ASoC: %s DAPM pre-event failed: %d\n", in dapm_widget_update()
1760 w->name, ret); in dapm_widget_update()
1767 ret = soc_dapm_update_bits(w->dapm, update->reg, update->mask, in dapm_widget_update()
1768 update->val); in dapm_widget_update()
1770 dev_err(w->dapm->dev, "ASoC: %s DAPM update failed: %d\n", in dapm_widget_update()
1771 w->name, ret); in dapm_widget_update()
1773 if (update->has_second_set) { in dapm_widget_update()
1774 ret = soc_dapm_update_bits(w->dapm, update->reg2, in dapm_widget_update()
1775 update->mask2, update->val2); in dapm_widget_update()
1777 dev_err(w->dapm->dev, in dapm_widget_update()
1779 w->name, ret); in dapm_widget_update()
1783 if (w->event && (w->event_flags & SND_SOC_DAPM_POST_REG)) { in dapm_widget_update()
1784 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG); in dapm_widget_update()
1786 dev_err(w->dapm->dev, "ASoC: %s DAPM post-event failed: %d\n", in dapm_widget_update()
1787 w->name, ret); in dapm_widget_update()
1792 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1801 if (d->bias_level == SND_SOC_BIAS_OFF && in dapm_pre_sequence_async()
1802 d->target_bias_level != SND_SOC_BIAS_OFF) { in dapm_pre_sequence_async()
1803 if (d->dev && cookie) in dapm_pre_sequence_async()
1804 pm_runtime_get_sync(d->dev); in dapm_pre_sequence_async()
1808 dev_err(d->dev, in dapm_pre_sequence_async()
1813 if ((d->target_bias_level == SND_SOC_BIAS_ON && in dapm_pre_sequence_async()
1814 d->bias_level != SND_SOC_BIAS_ON) || in dapm_pre_sequence_async()
1815 (d->target_bias_level != SND_SOC_BIAS_ON && in dapm_pre_sequence_async()
1816 d->bias_level == SND_SOC_BIAS_ON)) { in dapm_pre_sequence_async()
1819 dev_err(d->dev, in dapm_pre_sequence_async()
1824 /* Async callback run prior to DAPM sequences - brings to their final
1833 if (d->bias_level == SND_SOC_BIAS_PREPARE && in dapm_post_sequence_async()
1834 (d->target_bias_level == SND_SOC_BIAS_STANDBY || in dapm_post_sequence_async()
1835 d->target_bias_level == SND_SOC_BIAS_OFF)) { in dapm_post_sequence_async()
1838 dev_err(d->dev, "ASoC: Failed to apply standby bias: %d\n", in dapm_post_sequence_async()
1843 if (d->bias_level == SND_SOC_BIAS_STANDBY && in dapm_post_sequence_async()
1844 d->target_bias_level == SND_SOC_BIAS_OFF) { in dapm_post_sequence_async()
1847 dev_err(d->dev, "ASoC: Failed to turn off bias: %d\n", in dapm_post_sequence_async()
1850 if (d->dev && cookie) in dapm_post_sequence_async()
1851 pm_runtime_put(d->dev); in dapm_post_sequence_async()
1855 if (d->bias_level == SND_SOC_BIAS_PREPARE && in dapm_post_sequence_async()
1856 d->target_bias_level == SND_SOC_BIAS_ON) { in dapm_post_sequence_async()
1859 dev_err(d->dev, "ASoC: Failed to apply active bias: %d\n", in dapm_post_sequence_async()
1875 if (power != peer->power) in dapm_widget_set_peer_power()
1885 if (w->power == power) in dapm_widget_set_power()
1894 dapm_widget_set_peer_power(path->source, power, path->connect); in dapm_widget_set_power()
1897 if (!w->is_supply) { in dapm_widget_set_power()
1899 dapm_widget_set_peer_power(path->sink, power, in dapm_widget_set_power()
1900 path->connect); in dapm_widget_set_power()
1915 switch (w->id) { in dapm_power_one_widget()
1933 if (dapm->idle_bias_off) in dapm_idle_bias_off()
1936 switch (snd_power_get_state(dapm->card->snd_card)) { in dapm_idle_bias_off()
1939 return dapm->suspend_bias_off; in dapm_idle_bias_off()
1949 * A complete path is a route that has valid endpoints i.e.:-
1952 * o Input pin to ADC.
1954 * o DAC to ADC (loopback).
1966 lockdep_assert_held(&card->dapm_mutex); in dapm_power_widgets()
1972 d->target_bias_level = SND_SOC_BIAS_OFF; in dapm_power_widgets()
1974 d->target_bias_level = SND_SOC_BIAS_STANDBY; in dapm_power_widgets()
1985 list_for_each_entry(w, &card->dapm_dirty, dirty) { in dapm_power_widgets()
1990 switch (w->id) { in dapm_power_widgets()
1996 list_del_init(&w->dirty); in dapm_power_widgets()
2000 if (w->new_power) { in dapm_power_widgets()
2001 d = w->dapm; in dapm_power_widgets()
2010 switch (w->id) { in dapm_power_widgets()
2019 if (d->target_bias_level < SND_SOC_BIAS_STANDBY) in dapm_power_widgets()
2020 d->target_bias_level = SND_SOC_BIAS_STANDBY; in dapm_power_widgets()
2023 d->target_bias_level = SND_SOC_BIAS_ON; in dapm_power_widgets()
2035 if (d->target_bias_level > bias) in dapm_power_widgets()
2036 bias = d->target_bias_level; in dapm_power_widgets()
2039 d->target_bias_level = bias; in dapm_power_widgets()
2044 dapm_pre_sequence_async(&card->dapm, 0); in dapm_power_widgets()
2047 if (d != &card->dapm && d->bias_level != d->target_bias_level) in dapm_power_widgets()
2071 if (d != &card->dapm && d->bias_level != d->target_bias_level) in dapm_power_widgets()
2077 dapm_post_sequence_async(&card->dapm, 0); in dapm_power_widgets()
2081 if (!d->component) in dapm_power_widgets()
2084 ret = snd_soc_component_stream_event(d->component, event); in dapm_power_widgets()
2089 pop_dbg(card->dev, card->pop_time, in dapm_power_widgets()
2090 "DAPM sequencing finished, waiting %dms\n", card->pop_time); in dapm_power_widgets()
2091 pop_wait(card->pop_time); in dapm_power_widgets()
2103 struct snd_soc_dapm_widget *w = file->private_data; in dapm_widget_power_read_file()
2104 struct snd_soc_card *card = w->dapm->card; in dapm_widget_power_read_file()
2113 return -ENOMEM; in dapm_widget_power_read_file()
2115 mutex_lock(&card->dapm_mutex); in dapm_widget_power_read_file()
2118 if (w->is_supply) { in dapm_widget_power_read_file()
2127 w->name, w->power ? "On" : "Off", in dapm_widget_power_read_file()
2128 w->force ? " (forced)" : "", in, out); in dapm_widget_power_read_file()
2130 if (w->reg >= 0) in dapm_widget_power_read_file()
2131 ret += scnprintf(buf + ret, PAGE_SIZE - ret, in dapm_widget_power_read_file()
2132 " - R%d(0x%x) mask 0x%x", in dapm_widget_power_read_file()
2133 w->reg, w->reg, w->mask << w->shift); in dapm_widget_power_read_file()
2135 ret += scnprintf(buf + ret, PAGE_SIZE - ret, "\n"); in dapm_widget_power_read_file()
2137 if (w->sname) in dapm_widget_power_read_file()
2138 ret += scnprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n", in dapm_widget_power_read_file()
2139 w->sname, in dapm_widget_power_read_file()
2140 w->active ? "active" : "inactive"); in dapm_widget_power_read_file()
2145 if (p->connected && !p->connected(p->source, p->sink)) in dapm_widget_power_read_file()
2148 if (!p->connect) in dapm_widget_power_read_file()
2151 ret += scnprintf(buf + ret, PAGE_SIZE - ret, in dapm_widget_power_read_file()
2154 p->name ? p->name : "static", in dapm_widget_power_read_file()
2155 p->node[rdir]->name); in dapm_widget_power_read_file()
2159 mutex_unlock(&card->dapm_mutex); in dapm_widget_power_read_file()
2176 struct snd_soc_dapm_context *dapm = file->private_data; in dapm_bias_read_file()
2179 switch (dapm->bias_level) { in dapm_bias_read_file()
2193 WARN(1, "Unknown bias_level %d\n", dapm->bias_level); in dapm_bias_read_file()
2214 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent); in snd_soc_dapm_debugfs_init()
2216 debugfs_create_file("bias_level", 0444, dapm->debugfs_dapm, dapm, in snd_soc_dapm_debugfs_init()
2222 struct snd_soc_dapm_context *dapm = w->dapm; in dapm_debugfs_add_widget()
2224 if (!dapm->debugfs_dapm || !w->name) in dapm_debugfs_add_widget()
2227 debugfs_create_file(w->name, 0444, dapm->debugfs_dapm, w, in dapm_debugfs_add_widget()
2233 debugfs_remove_recursive(dapm->debugfs_dapm); in dapm_debugfs_cleanup()
2234 dapm->debugfs_dapm = NULL; in dapm_debugfs_cleanup()
2254 * soc_dapm_connect_path() - Connects or disconnects a path
2263 if (path->connect == connect) in soc_dapm_connect_path()
2266 path->connect = connect; in soc_dapm_connect_path()
2267 dapm_mark_dirty(path->source, reason); in soc_dapm_connect_path()
2268 dapm_mark_dirty(path->sink, reason); in soc_dapm_connect_path()
2280 lockdep_assert_held(&card->dapm_mutex); in soc_dapm_mux_update_power()
2286 if (e && !(strcmp(path->name, e->texts[mux]))) in soc_dapm_mux_update_power()
2304 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_mux_update_power()
2307 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_mux_update_power()
2308 card->update = update; in snd_soc_dapm_mux_update_power()
2310 card->update = NULL; in snd_soc_dapm_mux_update_power()
2311 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_mux_update_power()
2326 lockdep_assert_held(&card->dapm_mutex); in soc_dapm_mixer_update_power()
2337 * first path (when 'found == 0') is the left channel, in soc_dapm_mixer_update_power()
2339 * right channel. in soc_dapm_mixer_update_power()
2349 * the left channel, and 'rconnect' for the right in soc_dapm_mixer_update_power()
2350 * channel. in soc_dapm_mixer_update_power()
2369 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_mixer_update_power()
2372 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_mixer_update_power()
2373 card->update = update; in snd_soc_dapm_mixer_update_power()
2374 ret = soc_dapm_mixer_update_power(card, kcontrol, connect, -1); in snd_soc_dapm_mixer_update_power()
2375 card->update = NULL; in snd_soc_dapm_mixer_update_power()
2376 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_mixer_update_power()
2395 if (!cmpnt->card) in dapm_widget_show_component()
2398 for_each_card_widgets(cmpnt->card, w) { in dapm_widget_show_component()
2399 if (w->dapm != dapm) in dapm_widget_show_component()
2403 switch (w->id) { in dapm_widget_show_component()
2420 if (w->name) in dapm_widget_show_component()
2422 w->name, w->power ? "On":"Off"); in dapm_widget_show_component()
2456 mutex_lock(&rtd->card->dapm_mutex); in dapm_widget_show()
2459 struct snd_soc_component *cmpnt = codec_dai->component; in dapm_widget_show()
2464 mutex_unlock(&rtd->card->dapm_mutex); in dapm_widget_show()
2478 list_del(&path->list_node[SND_SOC_DAPM_DIR_IN]); in dapm_free_path()
2479 list_del(&path->list_node[SND_SOC_DAPM_DIR_OUT]); in dapm_free_path()
2480 list_del(&path->list_kcontrol); in dapm_free_path()
2481 list_del(&path->list); in dapm_free_path()
2490 list_del(&w->list); in snd_soc_dapm_free_widget()
2491 list_del(&w->dirty); in snd_soc_dapm_free_widget()
2502 kfree(w->kcontrols); in snd_soc_dapm_free_widget()
2503 kfree_const(w->name); in snd_soc_dapm_free_widget()
2504 kfree_const(w->sname); in snd_soc_dapm_free_widget()
2510 dapm->path_sink_cache.widget = NULL; in snd_soc_dapm_reset_cache()
2511 dapm->path_source_cache.widget = NULL; in snd_soc_dapm_reset_cache()
2519 for_each_card_widgets_safe(dapm->card, w, next_w) { in dapm_free_widgets()
2520 if (w->dapm != dapm) in dapm_free_widgets()
2545 for_each_card_widgets(dapm->card, w) { in dapm_find_widget()
2546 if (!strcmp(w->name, pin_name)) { in dapm_find_widget()
2547 if (w->dapm == dapm) in dapm_find_widget()
2569 dev_err(dapm->dev, "ASoC: DAPM unknown pin %s\n", pin); in snd_soc_dapm_set_pin()
2570 return -EINVAL; in snd_soc_dapm_set_pin()
2573 if (w->connected != status) { in snd_soc_dapm_set_pin()
2580 w->connected = status; in snd_soc_dapm_set_pin()
2582 w->force = 0; in snd_soc_dapm_set_pin()
2588 * snd_soc_dapm_sync_unlocked - scan and power dapm paths
2604 if (!dapm->card || !dapm->card->instantiated) in snd_soc_dapm_sync_unlocked()
2607 return dapm_power_widgets(dapm->card, SND_SOC_DAPM_STREAM_NOP); in snd_soc_dapm_sync_unlocked()
2612 * snd_soc_dapm_sync - scan and power dapm paths
2624 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_sync()
2626 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_sync()
2635 switch (w->id) { in dapm_update_dai_chan()
2643 dev_dbg(w->dapm->dev, "%s DAI route %s -> %s\n", in dapm_update_dai_chan()
2644 w->channel < channels ? "Connecting" : "Disconnecting", in dapm_update_dai_chan()
2645 p->source->name, p->sink->name); in dapm_update_dai_chan()
2647 if (w->channel < channels) in dapm_update_dai_chan()
2659 int dir = substream->stream; in dapm_update_dai_unlocked()
2670 dev_dbg(dai->dev, "Update DAI routes for %s %s\n", dai->name, in dapm_update_dai_unlocked()
2674 ret = dapm_update_dai_chan(p, p->sink, channels); in dapm_update_dai_unlocked()
2680 ret = dapm_update_dai_chan(p, p->source, channels); in dapm_update_dai_unlocked()
2695 mutex_lock_nested(&rtd->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_update_dai()
2697 mutex_unlock(&rtd->card->dapm_mutex); in snd_soc_dapm_update_dai()
2704 * dapm_update_widget_flags() - Re-compute widget sink and source flags
2718 switch (w->id) { in dapm_update_widget_flags()
2721 if (w->dapm->card->fully_routed) in dapm_update_widget_flags()
2725 if (p->source->id == snd_soc_dapm_micbias || in dapm_update_widget_flags()
2726 p->source->id == snd_soc_dapm_mic || in dapm_update_widget_flags()
2727 p->source->id == snd_soc_dapm_line || in dapm_update_widget_flags()
2728 p->source->id == snd_soc_dapm_output) { in dapm_update_widget_flags()
2736 if (w->dapm->card->fully_routed) in dapm_update_widget_flags()
2740 if (p->sink->id == snd_soc_dapm_spk || in dapm_update_widget_flags()
2741 p->sink->id == snd_soc_dapm_hp || in dapm_update_widget_flags()
2742 p->sink->id == snd_soc_dapm_line || in dapm_update_widget_flags()
2743 p->sink->id == snd_soc_dapm_input) { in dapm_update_widget_flags()
2752 if (!list_empty(&w->edges[dir])) in dapm_update_widget_flags()
2760 w->is_ep = ep; in dapm_update_widget_flags()
2773 switch (source->id) { in snd_soc_dapm_check_dynamic_path()
2781 switch (sink->id) { in snd_soc_dapm_check_dynamic_path()
2793 dev_err(dapm->dev, in snd_soc_dapm_check_dynamic_path()
2794 "Direct connection between demux and mixer/mux not supported for path %s -> [%s] -> %s\n", in snd_soc_dapm_check_dynamic_path()
2795 source->name, control, sink->name); in snd_soc_dapm_check_dynamic_path()
2796 return -EINVAL; in snd_soc_dapm_check_dynamic_path()
2798 dev_err(dapm->dev, in snd_soc_dapm_check_dynamic_path()
2799 "Control not supported for path %s -> [%s] -> %s\n", in snd_soc_dapm_check_dynamic_path()
2800 source->name, control, sink->name); in snd_soc_dapm_check_dynamic_path()
2801 return -EINVAL; in snd_soc_dapm_check_dynamic_path()
2818 if (wsink->is_supply && !wsource->is_supply) { in snd_soc_dapm_add_path()
2819 dev_err(dapm->dev, in snd_soc_dapm_add_path()
2820 "Connecting non-supply widget to supply widget is not supported (%s -> %s)\n", in snd_soc_dapm_add_path()
2821 wsource->name, wsink->name); in snd_soc_dapm_add_path()
2822 return -EINVAL; in snd_soc_dapm_add_path()
2825 if (connected && !wsource->is_supply) { in snd_soc_dapm_add_path()
2826 dev_err(dapm->dev, in snd_soc_dapm_add_path()
2827 "connected() callback only supported for supply widgets (%s -> %s)\n", in snd_soc_dapm_add_path()
2828 wsource->name, wsink->name); in snd_soc_dapm_add_path()
2829 return -EINVAL; in snd_soc_dapm_add_path()
2832 if (wsource->is_supply && control) { in snd_soc_dapm_add_path()
2833 dev_err(dapm->dev, in snd_soc_dapm_add_path()
2834 "Conditional paths are not supported for supply widgets (%s -> [%s] -> %s)\n", in snd_soc_dapm_add_path()
2835 wsource->name, control, wsink->name); in snd_soc_dapm_add_path()
2836 return -EINVAL; in snd_soc_dapm_add_path()
2845 return -ENOMEM; in snd_soc_dapm_add_path()
2847 path->node[SND_SOC_DAPM_DIR_IN] = wsource; in snd_soc_dapm_add_path()
2848 path->node[SND_SOC_DAPM_DIR_OUT] = wsink; in snd_soc_dapm_add_path()
2852 path->connected = connected; in snd_soc_dapm_add_path()
2853 INIT_LIST_HEAD(&path->list); in snd_soc_dapm_add_path()
2854 INIT_LIST_HEAD(&path->list_kcontrol); in snd_soc_dapm_add_path()
2856 if (wsource->is_supply || wsink->is_supply) in snd_soc_dapm_add_path()
2857 path->is_supply = 1; in snd_soc_dapm_add_path()
2861 path->connect = 1; in snd_soc_dapm_add_path()
2863 switch (wsource->id) { in snd_soc_dapm_add_path()
2873 switch (wsink->id) { in snd_soc_dapm_add_path()
2891 list_add(&path->list, &dapm->card->paths); in snd_soc_dapm_add_path()
2893 list_add(&path->list_node[dir], &widgets[dir]->edges[dir]); in snd_soc_dapm_add_path()
2900 if (dapm->card->instantiated && path->connect) in snd_soc_dapm_add_path()
2926 prefix, route->sink); in snd_soc_dapm_add_route()
2929 prefix, route->source); in snd_soc_dapm_add_route()
2932 sink = route->sink; in snd_soc_dapm_add_route()
2933 source = route->source; in snd_soc_dapm_add_route()
2936 wsource = dapm_wcache_lookup(&dapm->path_source_cache, source); in snd_soc_dapm_add_route()
2937 wsink = dapm_wcache_lookup(&dapm->path_sink_cache, sink); in snd_soc_dapm_add_route()
2943 * find src and dest widgets over all widgets but favor a widget from in snd_soc_dapm_add_route()
2946 for_each_card_widgets(dapm->card, w) { in snd_soc_dapm_add_route()
2947 if (!wsink && !(strcmp(w->name, sink))) { in snd_soc_dapm_add_route()
2949 if (w->dapm == dapm) { in snd_soc_dapm_add_route()
2956 dev_warn(dapm->dev, in snd_soc_dapm_add_route()
2958 w->name); in snd_soc_dapm_add_route()
2961 if (!wsource && !(strcmp(w->name, source))) { in snd_soc_dapm_add_route()
2963 if (w->dapm == dapm) { in snd_soc_dapm_add_route()
2970 dev_warn(dapm->dev, in snd_soc_dapm_add_route()
2972 w->name); in snd_soc_dapm_add_route()
2982 dev_err(dapm->dev, "ASoC: no source widget found for %s\n", in snd_soc_dapm_add_route()
2983 route->source); in snd_soc_dapm_add_route()
2984 return -ENODEV; in snd_soc_dapm_add_route()
2987 dev_err(dapm->dev, "ASoC: no sink widget found for %s\n", in snd_soc_dapm_add_route()
2988 route->sink); in snd_soc_dapm_add_route()
2989 return -ENODEV; in snd_soc_dapm_add_route()
2993 dapm_wcache_update(&dapm->path_sink_cache, wsink); in snd_soc_dapm_add_route()
2994 dapm_wcache_update(&dapm->path_source_cache, wsource); in snd_soc_dapm_add_route()
2996 ret = snd_soc_dapm_add_path(dapm, wsource, wsink, route->control, in snd_soc_dapm_add_route()
2997 route->connected); in snd_soc_dapm_add_route()
3003 dev_warn(dapm->dev, "ASoC: no dapm match for %s --> %s --> %s\n", in snd_soc_dapm_add_route()
3004 source, route->control, sink); in snd_soc_dapm_add_route()
3018 if (route->control) { in snd_soc_dapm_del_route()
3019 dev_err(dapm->dev, in snd_soc_dapm_del_route()
3021 return -EINVAL; in snd_soc_dapm_del_route()
3027 prefix, route->sink); in snd_soc_dapm_del_route()
3030 prefix, route->source); in snd_soc_dapm_del_route()
3033 sink = route->sink; in snd_soc_dapm_del_route()
3034 source = route->source; in snd_soc_dapm_del_route()
3038 list_for_each_entry(p, &dapm->card->paths, list) { in snd_soc_dapm_del_route()
3039 if (strcmp(p->source->name, source) != 0) in snd_soc_dapm_del_route()
3041 if (strcmp(p->sink->name, sink) != 0) in snd_soc_dapm_del_route()
3048 struct snd_soc_dapm_widget *wsource = path->source; in snd_soc_dapm_del_route()
3049 struct snd_soc_dapm_widget *wsink = path->sink; in snd_soc_dapm_del_route()
3053 if (path->connect) in snd_soc_dapm_del_route()
3062 dev_warn(dapm->dev, "ASoC: Route %s->%s does not exist\n", in snd_soc_dapm_del_route()
3070 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
3087 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_add_routes()
3091 dev_err(dapm->dev, "ASoC: Failed to add route %s -> %s -> %s\n", in snd_soc_dapm_add_routes()
3092 route->source, in snd_soc_dapm_add_routes()
3093 route->control ? route->control : "direct", in snd_soc_dapm_add_routes()
3094 route->sink); in snd_soc_dapm_add_routes()
3099 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_add_routes()
3106 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
3118 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_del_routes()
3123 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_del_routes()
3133 route->source, in snd_soc_dapm_weak_route()
3136 route->sink, in snd_soc_dapm_weak_route()
3142 dev_err(dapm->dev, "ASoC: Unable to find source %s for weak route\n", in snd_soc_dapm_weak_route()
3143 route->source); in snd_soc_dapm_weak_route()
3144 return -ENODEV; in snd_soc_dapm_weak_route()
3148 dev_err(dapm->dev, "ASoC: Unable to find sink %s for weak route\n", in snd_soc_dapm_weak_route()
3149 route->sink); in snd_soc_dapm_weak_route()
3150 return -ENODEV; in snd_soc_dapm_weak_route()
3153 if (route->control || route->connected) in snd_soc_dapm_weak_route()
3154 dev_warn(dapm->dev, "ASoC: Ignoring control for weak route %s->%s\n", in snd_soc_dapm_weak_route()
3155 route->source, route->sink); in snd_soc_dapm_weak_route()
3158 if (path->sink == sink) { in snd_soc_dapm_weak_route()
3159 path->weak = 1; in snd_soc_dapm_weak_route()
3165 dev_err(dapm->dev, "ASoC: No path found for weak route %s->%s\n", in snd_soc_dapm_weak_route()
3166 route->source, route->sink); in snd_soc_dapm_weak_route()
3168 dev_warn(dapm->dev, "ASoC: %d paths found for weak route %s->%s\n", in snd_soc_dapm_weak_route()
3169 count, route->source, route->sink); in snd_soc_dapm_weak_route()
3175 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
3196 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); in snd_soc_dapm_weak_routes()
3203 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_weak_routes()
3210 * snd_soc_dapm_new_widgets - add new dapm widgets
3222 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); in snd_soc_dapm_new_widgets()
3226 if (w->new) in snd_soc_dapm_new_widgets()
3229 if (w->num_kcontrols) { in snd_soc_dapm_new_widgets()
3230 w->kcontrols = kcalloc(w->num_kcontrols, in snd_soc_dapm_new_widgets()
3233 if (!w->kcontrols) { in snd_soc_dapm_new_widgets()
3234 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_new_widgets()
3235 return -ENOMEM; in snd_soc_dapm_new_widgets()
3239 switch(w->id) { in snd_soc_dapm_new_widgets()
3262 if (w->reg >= 0) { in snd_soc_dapm_new_widgets()
3263 val = soc_dapm_read(w->dapm, w->reg); in snd_soc_dapm_new_widgets()
3264 val = val >> w->shift; in snd_soc_dapm_new_widgets()
3265 val &= w->mask; in snd_soc_dapm_new_widgets()
3266 if (val == w->on_val) in snd_soc_dapm_new_widgets()
3267 w->power = 1; in snd_soc_dapm_new_widgets()
3270 w->new = 1; in snd_soc_dapm_new_widgets()
3277 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_new_widgets()
3283 * snd_soc_dapm_get_volsw - dapm mixer get callback
3295 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_get_volsw()
3297 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_dapm_get_volsw()
3298 int reg = mc->reg; in snd_soc_dapm_get_volsw()
3299 unsigned int shift = mc->shift; in snd_soc_dapm_get_volsw()
3300 int max = mc->max; in snd_soc_dapm_get_volsw()
3302 unsigned int mask = (1 << fls(max)) - 1; in snd_soc_dapm_get_volsw()
3303 unsigned int invert = mc->invert; in snd_soc_dapm_get_volsw()
3306 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_get_volsw()
3311 if (reg != mc->rreg) in snd_soc_dapm_get_volsw()
3312 reg_val = soc_dapm_read(dapm, mc->rreg); in snd_soc_dapm_get_volsw()
3315 rval = (reg_val >> mc->rshift) & mask; in snd_soc_dapm_get_volsw()
3323 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_get_volsw()
3326 ucontrol->value.integer.value[0] = max - val; in snd_soc_dapm_get_volsw()
3328 ucontrol->value.integer.value[0] = val; in snd_soc_dapm_get_volsw()
3332 ucontrol->value.integer.value[1] = max - rval; in snd_soc_dapm_get_volsw()
3334 ucontrol->value.integer.value[1] = rval; in snd_soc_dapm_get_volsw()
3342 * snd_soc_dapm_put_volsw - dapm mixer set callback
3354 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_put_volsw()
3356 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_dapm_put_volsw()
3357 int reg = mc->reg; in snd_soc_dapm_put_volsw()
3358 unsigned int shift = mc->shift; in snd_soc_dapm_put_volsw()
3359 int max = mc->max; in snd_soc_dapm_put_volsw()
3361 unsigned int mask = (1 << width) - 1; in snd_soc_dapm_put_volsw()
3362 unsigned int invert = mc->invert; in snd_soc_dapm_put_volsw()
3364 int connect, rconnect = -1, change, reg_change = 0; in snd_soc_dapm_put_volsw()
3368 val = (ucontrol->value.integer.value[0] & mask); in snd_soc_dapm_put_volsw()
3372 val = max - val; in snd_soc_dapm_put_volsw()
3375 rval = (ucontrol->value.integer.value[1] & mask); in snd_soc_dapm_put_volsw()
3378 rval = max - rval; in snd_soc_dapm_put_volsw()
3381 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_put_volsw()
3385 dev_warn(dapm->dev, in snd_soc_dapm_put_volsw()
3387 kcontrol->id.name); in snd_soc_dapm_put_volsw()
3392 rval = rval << mc->rshift; in snd_soc_dapm_put_volsw()
3397 reg_change |= soc_dapm_test_bits(dapm, mc->rreg, in snd_soc_dapm_put_volsw()
3398 mask << mc->rshift, in snd_soc_dapm_put_volsw()
3406 update.reg2 = mc->rreg; in snd_soc_dapm_put_volsw()
3407 update.mask2 = mask << mc->rshift; in snd_soc_dapm_put_volsw()
3414 card->update = &update; in snd_soc_dapm_put_volsw()
3421 card->update = NULL; in snd_soc_dapm_put_volsw()
3424 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_put_volsw()
3434 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
3446 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_get_enum_double()
3447 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in snd_soc_dapm_get_enum_double()
3450 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_get_enum_double()
3451 if (e->reg != SND_SOC_NOPM && dapm_kcontrol_is_powered(kcontrol)) { in snd_soc_dapm_get_enum_double()
3452 reg_val = soc_dapm_read(dapm, e->reg); in snd_soc_dapm_get_enum_double()
3456 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_get_enum_double()
3458 val = (reg_val >> e->shift_l) & e->mask; in snd_soc_dapm_get_enum_double()
3459 ucontrol->value.enumerated.item[0] = snd_soc_enum_val_to_item(e, val); in snd_soc_dapm_get_enum_double()
3460 if (e->shift_l != e->shift_r) { in snd_soc_dapm_get_enum_double()
3461 val = (reg_val >> e->shift_r) & e->mask; in snd_soc_dapm_get_enum_double()
3463 ucontrol->value.enumerated.item[1] = val; in snd_soc_dapm_get_enum_double()
3471 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
3483 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_put_enum_double()
3484 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in snd_soc_dapm_put_enum_double()
3485 unsigned int *item = ucontrol->value.enumerated.item; in snd_soc_dapm_put_enum_double()
3491 if (item[0] >= e->items) in snd_soc_dapm_put_enum_double()
3492 return -EINVAL; in snd_soc_dapm_put_enum_double()
3494 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l; in snd_soc_dapm_put_enum_double()
3495 mask = e->mask << e->shift_l; in snd_soc_dapm_put_enum_double()
3496 if (e->shift_l != e->shift_r) { in snd_soc_dapm_put_enum_double()
3497 if (item[1] > e->items) in snd_soc_dapm_put_enum_double()
3498 return -EINVAL; in snd_soc_dapm_put_enum_double()
3499 val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_r; in snd_soc_dapm_put_enum_double()
3500 mask |= e->mask << e->shift_r; in snd_soc_dapm_put_enum_double()
3503 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_put_enum_double()
3507 if (e->reg != SND_SOC_NOPM) in snd_soc_dapm_put_enum_double()
3508 reg_change = soc_dapm_test_bits(dapm, e->reg, mask, val); in snd_soc_dapm_put_enum_double()
3513 update.reg = e->reg; in snd_soc_dapm_put_enum_double()
3516 card->update = &update; in snd_soc_dapm_put_enum_double()
3522 card->update = NULL; in snd_soc_dapm_put_enum_double()
3525 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_put_enum_double()
3535 * snd_soc_dapm_info_pin_switch - Info for a pin switch
3545 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; in snd_soc_dapm_info_pin_switch()
3546 uinfo->count = 1; in snd_soc_dapm_info_pin_switch()
3547 uinfo->value.integer.min = 0; in snd_soc_dapm_info_pin_switch()
3548 uinfo->value.integer.max = 1; in snd_soc_dapm_info_pin_switch()
3555 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
3564 const char *pin = (const char *)kcontrol->private_value; in snd_soc_dapm_get_pin_switch()
3566 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_get_pin_switch()
3568 ucontrol->value.integer.value[0] = in snd_soc_dapm_get_pin_switch()
3569 snd_soc_dapm_get_pin_status(&card->dapm, pin); in snd_soc_dapm_get_pin_switch()
3571 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_get_pin_switch()
3578 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
3587 const char *pin = (const char *)kcontrol->private_value; in snd_soc_dapm_put_pin_switch()
3590 if (ucontrol->value.integer.value[0]) in snd_soc_dapm_put_pin_switch()
3591 ret = snd_soc_dapm_enable_pin(&card->dapm, pin); in snd_soc_dapm_put_pin_switch()
3593 ret = snd_soc_dapm_disable_pin(&card->dapm, pin); in snd_soc_dapm_put_pin_switch()
3595 snd_soc_dapm_sync(&card->dapm); in snd_soc_dapm_put_pin_switch()
3610 return ERR_PTR(-ENOMEM); in snd_soc_dapm_new_control_unlocked()
3612 switch (w->id) { in snd_soc_dapm_new_control_unlocked()
3614 w->regulator = devm_regulator_get(dapm->dev, w->name); in snd_soc_dapm_new_control_unlocked()
3615 if (IS_ERR(w->regulator)) { in snd_soc_dapm_new_control_unlocked()
3616 ret = PTR_ERR(w->regulator); in snd_soc_dapm_new_control_unlocked()
3620 if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) { in snd_soc_dapm_new_control_unlocked()
3621 ret = regulator_allow_bypass(w->regulator, true); in snd_soc_dapm_new_control_unlocked()
3623 dev_warn(dapm->dev, in snd_soc_dapm_new_control_unlocked()
3625 w->name, ret); in snd_soc_dapm_new_control_unlocked()
3629 w->pinctrl = devm_pinctrl_get(dapm->dev); in snd_soc_dapm_new_control_unlocked()
3630 if (IS_ERR(w->pinctrl)) { in snd_soc_dapm_new_control_unlocked()
3631 ret = PTR_ERR(w->pinctrl); in snd_soc_dapm_new_control_unlocked()
3639 w->clk = devm_clk_get(dapm->dev, w->name); in snd_soc_dapm_new_control_unlocked()
3640 if (IS_ERR(w->clk)) { in snd_soc_dapm_new_control_unlocked()
3641 ret = PTR_ERR(w->clk); in snd_soc_dapm_new_control_unlocked()
3651 w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, widget->name); in snd_soc_dapm_new_control_unlocked()
3653 w->name = kstrdup_const(widget->name, GFP_KERNEL); in snd_soc_dapm_new_control_unlocked()
3654 if (w->name == NULL) { in snd_soc_dapm_new_control_unlocked()
3655 kfree_const(w->sname); in snd_soc_dapm_new_control_unlocked()
3657 return ERR_PTR(-ENOMEM); in snd_soc_dapm_new_control_unlocked()
3660 switch (w->id) { in snd_soc_dapm_new_control_unlocked()
3662 w->is_ep = SND_SOC_DAPM_EP_SOURCE; in snd_soc_dapm_new_control_unlocked()
3663 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3666 if (!dapm->card->fully_routed) in snd_soc_dapm_new_control_unlocked()
3667 w->is_ep = SND_SOC_DAPM_EP_SOURCE; in snd_soc_dapm_new_control_unlocked()
3668 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3672 w->is_ep = SND_SOC_DAPM_EP_SINK; in snd_soc_dapm_new_control_unlocked()
3673 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3676 if (!dapm->card->fully_routed) in snd_soc_dapm_new_control_unlocked()
3677 w->is_ep = SND_SOC_DAPM_EP_SINK; in snd_soc_dapm_new_control_unlocked()
3678 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3682 w->is_ep = SND_SOC_DAPM_EP_SOURCE; in snd_soc_dapm_new_control_unlocked()
3683 w->power_check = dapm_always_on_check_power; in snd_soc_dapm_new_control_unlocked()
3686 w->is_ep = SND_SOC_DAPM_EP_SINK; in snd_soc_dapm_new_control_unlocked()
3687 w->power_check = dapm_always_on_check_power; in snd_soc_dapm_new_control_unlocked()
3713 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3720 w->is_supply = 1; in snd_soc_dapm_new_control_unlocked()
3721 w->power_check = dapm_supply_check_power; in snd_soc_dapm_new_control_unlocked()
3724 w->power_check = dapm_always_on_check_power; in snd_soc_dapm_new_control_unlocked()
3728 w->dapm = dapm; in snd_soc_dapm_new_control_unlocked()
3729 INIT_LIST_HEAD(&w->list); in snd_soc_dapm_new_control_unlocked()
3730 INIT_LIST_HEAD(&w->dirty); in snd_soc_dapm_new_control_unlocked()
3732 list_add_tail(&w->list, &dapm->card->widgets); in snd_soc_dapm_new_control_unlocked()
3735 INIT_LIST_HEAD(&w->edges[dir]); in snd_soc_dapm_new_control_unlocked()
3736 w->endpoints[dir] = -1; in snd_soc_dapm_new_control_unlocked()
3740 w->connected = 1; in snd_soc_dapm_new_control_unlocked()
3744 if (ret != -EPROBE_DEFER) in snd_soc_dapm_new_control_unlocked()
3745 dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n", in snd_soc_dapm_new_control_unlocked()
3746 w->name, ret); in snd_soc_dapm_new_control_unlocked()
3748 kfree_const(w->sname); in snd_soc_dapm_new_control_unlocked()
3754 * snd_soc_dapm_new_control - create new dapm control
3768 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_new_control()
3770 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_new_control()
3777 * snd_soc_dapm_new_controls - create new dapm controls
3793 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); in snd_soc_dapm_new_controls()
3802 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_new_controls()
3822 return -ENOMEM; in snd_soc_dai_link_event_pre_pmu()
3826 ret = -ENOMEM; in snd_soc_dai_link_event_pre_pmu()
3830 substream->runtime = runtime; in snd_soc_dai_link_event_pre_pmu()
3832 substream->stream = SNDRV_PCM_STREAM_CAPTURE; in snd_soc_dai_link_event_pre_pmu()
3834 source = path->source->priv; in snd_soc_dai_link_event_pre_pmu()
3840 snd_soc_dai_activate(source, substream->stream); in snd_soc_dai_link_event_pre_pmu()
3843 substream->stream = SNDRV_PCM_STREAM_PLAYBACK; in snd_soc_dai_link_event_pre_pmu()
3845 sink = path->sink->priv; in snd_soc_dai_link_event_pre_pmu()
3851 snd_soc_dai_activate(sink, substream->stream); in snd_soc_dai_link_event_pre_pmu()
3854 substream->hw_opened = 1; in snd_soc_dai_link_event_pre_pmu()
3861 config = rtd->dai_link->params + rtd->params_select; in snd_soc_dai_link_event_pre_pmu()
3863 dev_err(w->dapm->dev, "ASoC: link config missing\n"); in snd_soc_dai_link_event_pre_pmu()
3864 ret = -EINVAL; in snd_soc_dai_link_event_pre_pmu()
3869 if (config->formats) { in snd_soc_dai_link_event_pre_pmu()
3870 fmt = ffs(config->formats) - 1; in snd_soc_dai_link_event_pre_pmu()
3872 dev_warn(w->dapm->dev, "ASoC: Invalid format %llx specified\n", in snd_soc_dai_link_event_pre_pmu()
3873 config->formats); in snd_soc_dai_link_event_pre_pmu()
3875 ret = -EINVAL; in snd_soc_dai_link_event_pre_pmu()
3880 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min = in snd_soc_dai_link_event_pre_pmu()
3881 config->rate_min; in snd_soc_dai_link_event_pre_pmu()
3882 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max = in snd_soc_dai_link_event_pre_pmu()
3883 config->rate_max; in snd_soc_dai_link_event_pre_pmu()
3884 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min in snd_soc_dai_link_event_pre_pmu()
3885 = config->channels_min; in snd_soc_dai_link_event_pre_pmu()
3886 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->max in snd_soc_dai_link_event_pre_pmu()
3887 = config->channels_max; in snd_soc_dai_link_event_pre_pmu()
3889 substream->stream = SNDRV_PCM_STREAM_CAPTURE; in snd_soc_dai_link_event_pre_pmu()
3891 source = path->source->priv; in snd_soc_dai_link_event_pre_pmu()
3900 substream->stream = SNDRV_PCM_STREAM_PLAYBACK; in snd_soc_dai_link_event_pre_pmu()
3902 sink = path->sink->priv; in snd_soc_dai_link_event_pre_pmu()
3911 runtime->format = params_format(params); in snd_soc_dai_link_event_pre_pmu()
3912 runtime->subformat = params_subformat(params); in snd_soc_dai_link_event_pre_pmu()
3913 runtime->channels = params_channels(params); in snd_soc_dai_link_event_pre_pmu()
3914 runtime->rate = params_rate(params); in snd_soc_dai_link_event_pre_pmu()
3926 struct snd_pcm_substream *substream = w->priv; in snd_soc_dai_link_event()
3927 int ret = 0, saved_stream = substream->stream; in snd_soc_dai_link_event()
3929 if (WARN_ON(list_empty(&w->edges[SND_SOC_DAPM_DIR_OUT]) || in snd_soc_dai_link_event()
3930 list_empty(&w->edges[SND_SOC_DAPM_DIR_IN]))) in snd_soc_dai_link_event()
3931 return -EINVAL; in snd_soc_dai_link_event()
3943 sink = path->sink->priv; in snd_soc_dai_link_event()
3952 sink = path->sink->priv; in snd_soc_dai_link_event()
3958 substream->stream = SNDRV_PCM_STREAM_CAPTURE; in snd_soc_dai_link_event()
3960 source = path->source->priv; in snd_soc_dai_link_event()
3964 substream->stream = SNDRV_PCM_STREAM_PLAYBACK; in snd_soc_dai_link_event()
3966 sink = path->sink->priv; in snd_soc_dai_link_event()
3970 substream->stream = SNDRV_PCM_STREAM_CAPTURE; in snd_soc_dai_link_event()
3972 source = path->source->priv; in snd_soc_dai_link_event()
3973 snd_soc_dai_deactivate(source, substream->stream); in snd_soc_dai_link_event()
3977 substream->stream = SNDRV_PCM_STREAM_PLAYBACK; in snd_soc_dai_link_event()
3979 sink = path->sink->priv; in snd_soc_dai_link_event()
3980 snd_soc_dai_deactivate(sink, substream->stream); in snd_soc_dai_link_event()
3986 kfree(substream->runtime); in snd_soc_dai_link_event()
3991 ret = -EINVAL; in snd_soc_dai_link_event()
3996 substream->stream = saved_stream; in snd_soc_dai_link_event()
4004 struct snd_soc_pcm_runtime *rtd = w->priv; in snd_soc_dapm_dai_link_get()
4006 ucontrol->value.enumerated.item[0] = rtd->params_select; in snd_soc_dapm_dai_link_get()
4015 struct snd_soc_pcm_runtime *rtd = w->priv; in snd_soc_dapm_dai_link_put()
4018 if (w->power) in snd_soc_dapm_dai_link_put()
4019 return -EBUSY; in snd_soc_dapm_dai_link_put()
4021 if (ucontrol->value.enumerated.item[0] == rtd->params_select) in snd_soc_dapm_dai_link_put()
4024 if (ucontrol->value.enumerated.item[0] >= rtd->dai_link->num_params) in snd_soc_dapm_dai_link_put()
4025 return -EINVAL; in snd_soc_dapm_dai_link_put()
4027 rtd->params_select = ucontrol->value.enumerated.item[0]; in snd_soc_dapm_dai_link_put()
4040 devm_kfree(card->dev, (void *)*private_value); in snd_soc_dapm_free_kcontrol()
4046 devm_kfree(card->dev, (void *)w_param_text[count]); in snd_soc_dapm_free_kcontrol()
4047 devm_kfree(card->dev, w_param_text); in snd_soc_dapm_free_kcontrol()
4070 if (!config->stream_name) { in snd_soc_dapm_alloc_kcontrol()
4071 dev_warn(card->dapm.dev, in snd_soc_dapm_alloc_kcontrol()
4075 devm_kasprintf(card->dev, GFP_KERNEL, in snd_soc_dapm_alloc_kcontrol()
4079 w_param_text[count] = devm_kmemdup(card->dev, in snd_soc_dapm_alloc_kcontrol()
4080 config->stream_name, in snd_soc_dapm_alloc_kcontrol()
4081 strlen(config->stream_name) + 1, in snd_soc_dapm_alloc_kcontrol()
4093 (unsigned long) devm_kmemdup(card->dev, in snd_soc_dapm_alloc_kcontrol()
4097 dev_err(card->dev, "ASoC: Failed to create control for %s widget\n", in snd_soc_dapm_alloc_kcontrol()
4103 kcontrol_news = devm_kmemdup(card->dev, &kcontrol_dai_link[0], in snd_soc_dapm_alloc_kcontrol()
4107 dev_err(card->dev, "ASoC: Failed to create control for %s widget\n", in snd_soc_dapm_alloc_kcontrol()
4131 link_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s-%s", in snd_soc_dapm_new_dai()
4132 rtd->dai_link->name, id); in snd_soc_dapm_new_dai()
4134 return ERR_PTR(-ENOMEM); in snd_soc_dapm_new_dai()
4146 if (rtd->dai_link->num_params > 1) { in snd_soc_dapm_new_dai()
4147 w_param_text = devm_kcalloc(card->dev, in snd_soc_dapm_new_dai()
4148 rtd->dai_link->num_params, in snd_soc_dapm_new_dai()
4151 ret = -ENOMEM; in snd_soc_dapm_new_dai()
4159 rtd->dai_link->params, in snd_soc_dapm_new_dai()
4160 rtd->dai_link->num_params, in snd_soc_dapm_new_dai()
4163 ret = -ENOMEM; in snd_soc_dapm_new_dai()
4169 dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name); in snd_soc_dapm_new_dai()
4171 w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template); in snd_soc_dapm_new_dai()
4174 dev_err(rtd->dev, "ASoC: Failed to create %s widget: %d\n", in snd_soc_dapm_new_dai()
4179 w->priv = substream; in snd_soc_dapm_new_dai()
4184 devm_kfree(card->dev, (void *)template.kcontrol_news); in snd_soc_dapm_new_dai()
4186 rtd->dai_link->num_params, w_param_text); in snd_soc_dapm_new_dai()
4188 devm_kfree(card->dev, link_name); in snd_soc_dapm_new_dai()
4198 WARN_ON(dapm->dev != dai->dev); in snd_soc_dapm_new_dai_widgets()
4203 if (dai->driver->playback.stream_name) { in snd_soc_dapm_new_dai_widgets()
4205 template.name = dai->driver->playback.stream_name; in snd_soc_dapm_new_dai_widgets()
4206 template.sname = dai->driver->playback.stream_name; in snd_soc_dapm_new_dai_widgets()
4208 dev_dbg(dai->dev, "ASoC: adding %s widget\n", in snd_soc_dapm_new_dai_widgets()
4215 w->priv = dai; in snd_soc_dapm_new_dai_widgets()
4216 dai->playback_widget = w; in snd_soc_dapm_new_dai_widgets()
4219 if (dai->driver->capture.stream_name) { in snd_soc_dapm_new_dai_widgets()
4221 template.name = dai->driver->capture.stream_name; in snd_soc_dapm_new_dai_widgets()
4222 template.sname = dai->driver->capture.stream_name; in snd_soc_dapm_new_dai_widgets()
4224 dev_dbg(dai->dev, "ASoC: adding %s widget\n", in snd_soc_dapm_new_dai_widgets()
4231 w->priv = dai; in snd_soc_dapm_new_dai_widgets()
4232 dai->capture_widget = w; in snd_soc_dapm_new_dai_widgets()
4241 struct snd_soc_dapm_widget *src, *sink; in snd_soc_dapm_link_dai_widgets() local
4246 switch (dai_w->id) { in snd_soc_dapm_link_dai_widgets()
4255 if (!dai_w->priv) { in snd_soc_dapm_link_dai_widgets()
4256 dev_dbg(card->dev, "dai widget %s has no DAI\n", in snd_soc_dapm_link_dai_widgets()
4257 dai_w->name); in snd_soc_dapm_link_dai_widgets()
4261 dai = dai_w->priv; in snd_soc_dapm_link_dai_widgets()
4265 if (w->dapm != dai_w->dapm) in snd_soc_dapm_link_dai_widgets()
4268 switch (w->id) { in snd_soc_dapm_link_dai_widgets()
4276 if (!w->sname || !strstr(w->sname, dai_w->sname)) in snd_soc_dapm_link_dai_widgets()
4279 if (dai_w->id == snd_soc_dapm_dai_in) { in snd_soc_dapm_link_dai_widgets()
4280 src = dai_w; in snd_soc_dapm_link_dai_widgets()
4283 src = w; in snd_soc_dapm_link_dai_widgets()
4286 dev_dbg(dai->dev, "%s -> %s\n", src->name, sink->name); in snd_soc_dapm_link_dai_widgets()
4287 snd_soc_dapm_add_path(w->dapm, src, sink, NULL, NULL); in snd_soc_dapm_link_dai_widgets()
4296 struct snd_soc_dapm_widget *src, in dapm_connect_dai_routes() argument
4301 dev_dbg(dapm->dev, "connected DAI link %s:%s -> %s:%s\n", in dapm_connect_dai_routes()
4302 src_dai->component->name, src->name, in dapm_connect_dai_routes()
4303 sink_dai->component->name, sink->name); in dapm_connect_dai_routes()
4306 snd_soc_dapm_add_path(dapm, src, dai, NULL, NULL); in dapm_connect_dai_routes()
4307 src = dai; in dapm_connect_dai_routes()
4310 snd_soc_dapm_add_path(dapm, src, sink, NULL, NULL); in dapm_connect_dai_routes()
4318 struct snd_soc_dai_link *dai_link = rtd->dai_link; in dapm_connect_dai_pair()
4321 struct snd_pcm_str *streams = rtd->pcm->streams; in dapm_connect_dai_pair()
4323 if (dai_link->params) { in dapm_connect_dai_pair()
4324 playback_cpu = cpu_dai->capture_widget; in dapm_connect_dai_pair()
4325 capture_cpu = cpu_dai->playback_widget; in dapm_connect_dai_pair()
4327 playback_cpu = cpu_dai->playback_widget; in dapm_connect_dai_pair()
4328 capture_cpu = cpu_dai->capture_widget; in dapm_connect_dai_pair()
4332 codec = codec_dai->playback_widget; in dapm_connect_dai_pair()
4335 if (dai_link->params && !rtd->playback_widget) { in dapm_connect_dai_pair()
4340 rtd->playback_widget = dai; in dapm_connect_dai_pair()
4343 dapm_connect_dai_routes(&card->dapm, cpu_dai, playback_cpu, in dapm_connect_dai_pair()
4344 rtd->playback_widget, in dapm_connect_dai_pair()
4350 codec = codec_dai->capture_widget; in dapm_connect_dai_pair()
4353 if (dai_link->params && !rtd->capture_widget) { in dapm_connect_dai_pair()
4358 rtd->capture_widget = dai; in dapm_connect_dai_pair()
4361 dapm_connect_dai_routes(&card->dapm, codec_dai, codec, in dapm_connect_dai_pair()
4362 rtd->capture_widget, in dapm_connect_dai_pair()
4379 if (w->id == snd_soc_dapm_dai_in) { in soc_dapm_dai_stream_event()
4389 w->active = 1; in soc_dapm_dai_stream_event()
4390 w->is_ep = ep; in soc_dapm_dai_stream_event()
4393 w->active = 0; in soc_dapm_dai_stream_event()
4394 w->is_ep = 0; in soc_dapm_dai_stream_event()
4415 * CODEC<->CODEC links have no direct connection. in snd_soc_dapm_connect_dai_link_widgets()
4417 if (rtd->dai_link->dynamic) in snd_soc_dapm_connect_dai_link_widgets()
4420 if (rtd->num_cpus == 1) { in snd_soc_dapm_connect_dai_link_widgets()
4424 } else if (rtd->num_codecs == rtd->num_cpus) { in snd_soc_dapm_connect_dai_link_widgets()
4429 dev_err(card->dev, in snd_soc_dapm_connect_dai_link_widgets()
4444 dapm_power_widgets(rtd->card, event); in soc_dapm_stream_event()
4448 * snd_soc_dapm_stream_event - send a stream event to the dapm core
4461 struct snd_soc_card *card = rtd->card; in snd_soc_dapm_stream_event()
4463 mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_stream_event()
4465 mutex_unlock(&card->dapm_mutex); in snd_soc_dapm_stream_event()
4478 rtd->pop_wait = 1; in snd_soc_dapm_stream_stop()
4480 &rtd->delayed_work, in snd_soc_dapm_stream_stop()
4481 msecs_to_jiffies(rtd->pmdown_time)); in snd_soc_dapm_stream_stop()
4492 * snd_soc_dapm_enable_pin_unlocked - enable pin.
4512 * snd_soc_dapm_enable_pin - enable pin.
4526 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_enable_pin()
4530 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_enable_pin()
4537 * snd_soc_dapm_force_enable_pin_unlocked - force a pin to be enabled
4556 dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin); in snd_soc_dapm_force_enable_pin_unlocked()
4557 return -EINVAL; in snd_soc_dapm_force_enable_pin_unlocked()
4560 dev_dbg(w->dapm->dev, "ASoC: force enable pin %s\n", pin); in snd_soc_dapm_force_enable_pin_unlocked()
4561 if (!w->connected) { in snd_soc_dapm_force_enable_pin_unlocked()
4563 * w->force does not affect the number of input or output paths, in snd_soc_dapm_force_enable_pin_unlocked()
4564 * so we only have to recheck if w->connected is changed in snd_soc_dapm_force_enable_pin_unlocked()
4568 w->connected = 1; in snd_soc_dapm_force_enable_pin_unlocked()
4570 w->force = 1; in snd_soc_dapm_force_enable_pin_unlocked()
4578 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
4594 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_force_enable_pin()
4598 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_force_enable_pin()
4605 * snd_soc_dapm_disable_pin_unlocked - disable pin.
4624 * snd_soc_dapm_disable_pin - disable pin.
4638 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_disable_pin()
4642 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_disable_pin()
4649 * snd_soc_dapm_nc_pin_unlocked - permanently disable pin.
4672 * snd_soc_dapm_nc_pin - permanently disable pin.
4689 mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); in snd_soc_dapm_nc_pin()
4693 mutex_unlock(&dapm->card->dapm_mutex); in snd_soc_dapm_nc_pin()
4700 * snd_soc_dapm_get_pin_status - get audio pin status
4704 * Get audio pin status - connected or disconnected.
4714 return w->connected; in snd_soc_dapm_get_pin_status()
4721 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
4737 dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin); in snd_soc_dapm_ignore_suspend()
4738 return -EINVAL; in snd_soc_dapm_ignore_suspend()
4741 w->ignore_suspend = 1; in snd_soc_dapm_ignore_suspend()
4748 * snd_soc_dapm_free - free dapm resources
4757 list_del(&dapm->list); in snd_soc_dapm_free()
4765 dapm->card = card; in snd_soc_dapm_init()
4766 dapm->component = component; in snd_soc_dapm_init()
4767 dapm->bias_level = SND_SOC_BIAS_OFF; in snd_soc_dapm_init()
4770 dapm->dev = component->dev; in snd_soc_dapm_init()
4771 dapm->idle_bias_off = !component->driver->idle_bias_on; in snd_soc_dapm_init()
4772 dapm->suspend_bias_off = component->driver->suspend_bias_off; in snd_soc_dapm_init()
4774 dapm->dev = card->dev; in snd_soc_dapm_init()
4777 INIT_LIST_HEAD(&dapm->list); in snd_soc_dapm_init()
4779 list_add(&dapm->list, &card->dapm_list); in snd_soc_dapm_init()
4785 struct snd_soc_card *card = dapm->card; in soc_dapm_shutdown_dapm()
4790 mutex_lock(&card->dapm_mutex); in soc_dapm_shutdown_dapm()
4792 for_each_card_widgets(dapm->card, w) { in soc_dapm_shutdown_dapm()
4793 if (w->dapm != dapm) in soc_dapm_shutdown_dapm()
4795 if (w->power) { in soc_dapm_shutdown_dapm()
4797 w->new_power = 0; in soc_dapm_shutdown_dapm()
4806 if (dapm->bias_level == SND_SOC_BIAS_ON) in soc_dapm_shutdown_dapm()
4810 if (dapm->bias_level == SND_SOC_BIAS_PREPARE) in soc_dapm_shutdown_dapm()
4815 mutex_unlock(&card->dapm_mutex); in soc_dapm_shutdown_dapm()
4819 * snd_soc_dapm_shutdown - callback for system shutdown
4826 if (dapm != &card->dapm) { in snd_soc_dapm_shutdown()
4828 if (dapm->bias_level == SND_SOC_BIAS_STANDBY) in snd_soc_dapm_shutdown()
4834 soc_dapm_shutdown_dapm(&card->dapm); in snd_soc_dapm_shutdown()
4835 if (card->dapm.bias_level == SND_SOC_BIAS_STANDBY) in snd_soc_dapm_shutdown()
4836 snd_soc_dapm_set_bias_level(&card->dapm, in snd_soc_dapm_shutdown()