Lines Matching +full:dynamic +full:- +full:power +full:- +full:switching

1 // SPDX-License-Identifier: GPL-2.0+
3 // soc-dapm.c -- ALSA SoC Dynamic Audio Power Management
9 // o Changes power status of internal codec blocks depending on the
10 // dynamic configuration of codec internal audio paths and active
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
17 // o Delayed power down of audio subsystem to reduce pops between a quick
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 (snd_soc_card_is_instantiated(dapm->card)) 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()
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()
333 w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, _widget->name); in dapm_cnew_widget()
335 w->name = kstrdup_const(_widget->name, GFP_KERNEL); in dapm_cnew_widget()
336 if (!w->name) { in dapm_cnew_widget()
341 if (_widget->sname) { in dapm_cnew_widget()
342 w->sname = kstrdup_const(_widget->sname, GFP_KERNEL); in dapm_cnew_widget()
343 if (!w->sname) { in dapm_cnew_widget()
344 kfree_const(w->name); in dapm_cnew_widget()
370 return -ENOMEM; in dapm_kcontrol_data_alloc()
372 INIT_LIST_HEAD(&data->paths); in dapm_kcontrol_data_alloc()
374 switch (widget->id) { in dapm_kcontrol_data_alloc()
378 mc = (struct soc_mixer_control *)kcontrol->private_value; in dapm_kcontrol_data_alloc()
380 if (mc->autodisable) { in dapm_kcontrol_data_alloc()
384 dev_warn(widget->dapm->dev, in dapm_kcontrol_data_alloc()
391 ret = -ENOMEM; in dapm_kcontrol_data_alloc()
396 template.reg = mc->reg; in dapm_kcontrol_data_alloc()
397 template.mask = (1 << fls(mc->max)) - 1; in dapm_kcontrol_data_alloc()
398 template.shift = mc->shift; in dapm_kcontrol_data_alloc()
399 if (mc->invert) in dapm_kcontrol_data_alloc()
400 template.off_val = mc->max; in dapm_kcontrol_data_alloc()
407 data->value = template.on_val; in dapm_kcontrol_data_alloc()
409 data->widget = in dapm_kcontrol_data_alloc()
410 snd_soc_dapm_new_control_unlocked(widget->dapm, in dapm_kcontrol_data_alloc()
413 if (IS_ERR(data->widget)) { in dapm_kcontrol_data_alloc()
414 ret = PTR_ERR(data->widget); in dapm_kcontrol_data_alloc()
421 e = (struct soc_enum *)kcontrol->private_value; in dapm_kcontrol_data_alloc()
423 if (e->autodisable) { in dapm_kcontrol_data_alloc()
429 ret = -ENOMEM; in dapm_kcontrol_data_alloc()
434 template.reg = e->reg; in dapm_kcontrol_data_alloc()
435 template.mask = e->mask; in dapm_kcontrol_data_alloc()
436 template.shift = e->shift_l; in dapm_kcontrol_data_alloc()
442 data->value = template.on_val; in dapm_kcontrol_data_alloc()
444 data->widget = snd_soc_dapm_new_control_unlocked( in dapm_kcontrol_data_alloc()
445 widget->dapm, &template); in dapm_kcontrol_data_alloc()
447 if (IS_ERR(data->widget)) { in dapm_kcontrol_data_alloc()
448 ret = PTR_ERR(data->widget); in dapm_kcontrol_data_alloc()
452 snd_soc_dapm_add_path(widget->dapm, data->widget, in dapm_kcontrol_data_alloc()
454 } else if (e->reg != SND_SOC_NOPM) { in dapm_kcontrol_data_alloc()
455 data->value = soc_dapm_read(widget->dapm, e->reg) & in dapm_kcontrol_data_alloc()
456 (e->mask << e->shift_l); in dapm_kcontrol_data_alloc()
463 kcontrol->private_data = data; in dapm_kcontrol_data_alloc()
476 list_del(&data->paths); in dapm_kcontrol_free()
477 kfree(data->wlist); in dapm_kcontrol_free()
486 return data->wlist; in dapm_kcontrol_get_wlist()
496 if (data->wlist) in dapm_kcontrol_add_widget()
497 n = data->wlist->num_widgets + 1; in dapm_kcontrol_add_widget()
501 new_wlist = krealloc(data->wlist, in dapm_kcontrol_add_widget()
505 return -ENOMEM; in dapm_kcontrol_add_widget()
507 new_wlist->num_widgets = n; in dapm_kcontrol_add_widget()
508 new_wlist->widgets[n - 1] = widget; in dapm_kcontrol_add_widget()
510 data->wlist = new_wlist; in dapm_kcontrol_add_widget()
520 list_add_tail(&path->list_kcontrol, &data->paths); in dapm_kcontrol_add_path()
527 if (!data->widget) in dapm_kcontrol_is_powered()
530 return data->widget->power; in dapm_kcontrol_is_powered()
538 return &data->paths; in dapm_kcontrol_get_path_list()
549 return data->value; in dapm_kcontrol_get_value()
558 if (data->value == value) in dapm_kcontrol_set_value()
561 if (data->widget) { in dapm_kcontrol_set_value()
562 switch (dapm_kcontrol_get_wlist(kcontrol)->widgets[0]->id) { in dapm_kcontrol_set_value()
566 data->widget->on_val = value & data->widget->mask; in dapm_kcontrol_set_value()
570 data->widget->on_val = value >> data->widget->shift; in dapm_kcontrol_set_value()
573 data->widget->on_val = value; in dapm_kcontrol_set_value()
578 data->value = value; in dapm_kcontrol_set_value()
584 * snd_soc_dapm_kcontrol_widget() - Returns the widget associated to a
591 return dapm_kcontrol_get_wlist(kcontrol)->widgets[0]; in snd_soc_dapm_kcontrol_widget()
596 * snd_soc_dapm_kcontrol_dapm() - Returns the dapm context associated to a
606 return dapm_kcontrol_get_wlist(kcontrol)->widgets[0]->dapm; in snd_soc_dapm_kcontrol_dapm()
616 memset(&card->dapm_stats, 0, sizeof(card->dapm_stats)); in dapm_reset()
619 w->new_power = w->power; in dapm_reset()
620 w->power_checked = false; in dapm_reset()
626 if (!dapm->component) in soc_dapm_prefix()
628 return dapm->component->name_prefix; in soc_dapm_prefix()
633 if (!dapm->component) in soc_dapm_read()
634 return -EIO; in soc_dapm_read()
635 return snd_soc_component_read(dapm->component, reg); in soc_dapm_read()
641 if (!dapm->component) in soc_dapm_update_bits()
642 return -EIO; in soc_dapm_update_bits()
643 return snd_soc_component_update_bits(dapm->component, reg, in soc_dapm_update_bits()
650 if (!dapm->component) in soc_dapm_test_bits()
651 return -EIO; in soc_dapm_test_bits()
652 return snd_soc_component_test_bits(dapm->component, reg, mask, value); in soc_dapm_test_bits()
657 if (dapm->component) in soc_dapm_async_complete()
658 snd_soc_component_async_complete(dapm->component); in soc_dapm_async_complete()
665 struct list_head *wlist = &w->dapm->card->widgets; in dapm_wcache_lookup()
670 if (!strcmp(name, w->name)) in dapm_wcache_lookup()
682 * snd_soc_dapm_force_bias_level() - Sets the DAPM bias level
695 * used during probe or resume from suspend to power up the device so
703 if (dapm->component) in snd_soc_dapm_force_bias_level()
704 ret = snd_soc_component_set_bias_level(dapm->component, level); in snd_soc_dapm_force_bias_level()
707 dapm->bias_level = level; in snd_soc_dapm_force_bias_level()
714 * snd_soc_dapm_set_bias_level - set the bias level for the system
718 * Configure the bias (power) levels for the SoC audio device.
725 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_set_bias_level()
734 if (!card || dapm != &card->dapm) in snd_soc_dapm_set_bias_level()
752 const struct snd_kcontrol_new *kcontrol = &w->kcontrol_news[0]; in dapm_connect_mux()
753 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in dapm_connect_mux()
757 if (e->reg != SND_SOC_NOPM) { in dapm_connect_mux()
759 val = soc_dapm_read(dapm, e->reg); in dapm_connect_mux()
760 val = (val >> e->shift_l) & e->mask; in dapm_connect_mux()
772 i = match_string(e->texts, e->items, control_name); in dapm_connect_mux()
774 return -ENODEV; in dapm_connect_mux()
776 path->name = e->texts[i]; in dapm_connect_mux()
777 path->connect = (i == item); in dapm_connect_mux()
787 p->sink->kcontrol_news[i].private_value; in dapm_set_mixer_path_status()
788 unsigned int reg = mc->reg; in dapm_set_mixer_path_status()
789 unsigned int invert = mc->invert; in dapm_set_mixer_path_status()
792 unsigned int shift = mc->shift; in dapm_set_mixer_path_status()
793 unsigned int max = mc->max; in dapm_set_mixer_path_status()
794 unsigned int mask = (1 << fls(max)) - 1; in dapm_set_mixer_path_status()
795 unsigned int val = soc_dapm_read(p->sink->dapm, reg); in dapm_set_mixer_path_status()
810 if (reg != mc->rreg) in dapm_set_mixer_path_status()
811 val = soc_dapm_read(p->sink->dapm, mc->rreg); in dapm_set_mixer_path_status()
812 val = (val >> mc->rshift) & mask; in dapm_set_mixer_path_status()
817 val = max - val; in dapm_set_mixer_path_status()
818 p->connect = !!val; in dapm_set_mixer_path_status()
826 p->connect = invert; in dapm_set_mixer_path_status()
837 for (i = 0; i < path->sink->num_kcontrols; i++) { in dapm_connect_mixer()
838 if (!strcmp(control_name, path->sink->kcontrol_news[i].name)) { in dapm_connect_mixer()
839 path->name = path->sink->kcontrol_news[i].name; in dapm_connect_mixer()
844 return -ENODEV; in dapm_connect_mixer()
857 for_each_card_widgets(dapm->card, w) { in dapm_is_shared_kcontrol()
858 if (w == kcontrolw || w->dapm != kcontrolw->dapm) in dapm_is_shared_kcontrol()
860 for (i = 0; i < w->num_kcontrols; i++) { in dapm_is_shared_kcontrol()
861 if (&w->kcontrol_news[i] == kcontrol_new) { in dapm_is_shared_kcontrol()
862 if (w->kcontrols) in dapm_is_shared_kcontrol()
863 *kcontrol = w->kcontrols[i]; in dapm_is_shared_kcontrol()
879 struct snd_soc_dapm_context *dapm = w->dapm; in dapm_create_or_share_kcontrol()
880 struct snd_card *card = dapm->card->snd_card; in dapm_create_or_share_kcontrol()
896 shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[kci], in dapm_create_or_share_kcontrol()
904 switch (w->id) { in dapm_create_or_share_kcontrol()
923 return -EINVAL; in dapm_create_or_share_kcontrol()
926 if (w->no_wname_in_kcontrol_name) in dapm_create_or_share_kcontrol()
937 w->name + prefix_len, in dapm_create_or_share_kcontrol()
938 w->kcontrol_news[kci].name); in dapm_create_or_share_kcontrol()
940 return -ENOMEM; in dapm_create_or_share_kcontrol()
945 name = w->name + prefix_len; in dapm_create_or_share_kcontrol()
948 name = w->kcontrol_news[kci].name; in dapm_create_or_share_kcontrol()
951 kcontrol = snd_soc_cnew(&w->kcontrol_news[kci], NULL, name, in dapm_create_or_share_kcontrol()
954 ret = -ENOMEM; in dapm_create_or_share_kcontrol()
958 kcontrol->private_free = dapm_kcontrol_free; in dapm_create_or_share_kcontrol()
968 dev_err(dapm->dev, in dapm_create_or_share_kcontrol()
970 w->name, name, ret); in dapm_create_or_share_kcontrol()
977 w->kcontrols[kci] = kcontrol; in dapm_create_or_share_kcontrol()
993 for (i = 0; i < w->num_kcontrols; i++) { in dapm_new_mixer()
997 if (path->name != (char *)w->kcontrol_news[i].name) in dapm_new_mixer()
1000 if (!w->kcontrols[i]) { in dapm_new_mixer()
1006 dapm_kcontrol_add_path(w->kcontrols[i], path); in dapm_new_mixer()
1008 data = snd_kcontrol_chip(w->kcontrols[i]); in dapm_new_mixer()
1009 if (data->widget) in dapm_new_mixer()
1010 snd_soc_dapm_add_path(data->widget->dapm, in dapm_new_mixer()
1011 data->widget, in dapm_new_mixer()
1012 path->source, in dapm_new_mixer()
1023 struct snd_soc_dapm_context *dapm = w->dapm; in dapm_new_mux()
1029 switch (w->id) { in dapm_new_mux()
1039 return -EINVAL; in dapm_new_mux()
1042 if (w->num_kcontrols != 1) { in dapm_new_mux()
1043 dev_err(dapm->dev, in dapm_new_mux()
1045 w->name); in dapm_new_mux()
1046 return -EINVAL; in dapm_new_mux()
1049 if (list_empty(&w->edges[dir])) { in dapm_new_mux()
1050 dev_err(dapm->dev, "ASoC: %s %s has no paths\n", type, w->name); in dapm_new_mux()
1051 return -EINVAL; in dapm_new_mux()
1059 if (path->name) in dapm_new_mux()
1060 dapm_kcontrol_add_path(w->kcontrols[0], path); in dapm_new_mux()
1071 for (i = 0; i < w->num_kcontrols; i++) { in dapm_new_pga()
1084 struct snd_soc_pcm_runtime *rtd = w->priv; in dapm_new_dai_link()
1087 if (rtd->dai_link->num_c2c_params <= 1) in dapm_new_dai_link()
1091 for (i = 0; i < w->num_kcontrols; i++) { in dapm_new_dai_link()
1092 struct snd_soc_dapm_context *dapm = w->dapm; in dapm_new_dai_link()
1093 struct snd_card *card = dapm->card->snd_card; in dapm_new_dai_link()
1094 struct snd_kcontrol *kcontrol = snd_soc_cnew(&w->kcontrol_news[i], in dapm_new_dai_link()
1095 w, w->name, NULL); in dapm_new_dai_link()
1099 dev_err(dapm->dev, in dapm_new_dai_link()
1101 w->name, w->kcontrol_news[i].name, ret); in dapm_new_dai_link()
1104 kcontrol->private_data = w; in dapm_new_dai_link()
1105 w->kcontrols[i] = kcontrol; in dapm_new_dai_link()
1111 /* We implement power down on suspend by checking the power state of
1112 * the ALSA card - when we are suspending the ALSA state for the card
1117 int level = snd_power_get_state(widget->dapm->card->snd_card); in snd_soc_dapm_suspend_check()
1122 if (widget->ignore_suspend) in snd_soc_dapm_suspend_check()
1123 dev_dbg(widget->dapm->dev, "ASoC: %s ignoring suspend\n", in snd_soc_dapm_suspend_check()
1124 widget->name); in snd_soc_dapm_suspend_check()
1125 return widget->ignore_suspend; in snd_soc_dapm_suspend_check()
1149 return -ENOMEM; in dapm_widget_list_create()
1152 (*list)->widgets[i++] = w; in dapm_widget_list_create()
1154 (*list)->num_widgets = i; in dapm_widget_list_create()
1170 widget->endpoints[dir] = -1; in invalidate_paths_ep()
1173 if (path->weak || path->is_supply) in invalidate_paths_ep()
1176 if (path->walking) in invalidate_paths_ep()
1179 if (path->connect) { in invalidate_paths_ep()
1180 path->walking = 1; in invalidate_paths_ep()
1181 invalidate_paths_ep(path->node[dir], dir); in invalidate_paths_ep()
1182 path->walking = 0; in invalidate_paths_ep()
1206 if (widget->endpoints[dir] >= 0) in is_connected_ep()
1207 return widget->endpoints[dir]; in is_connected_ep()
1213 list_add_tail(&widget->work_list, list); in is_connected_ep()
1220 if ((widget->is_ep & SND_SOC_DAPM_DIR_TO_EP(dir)) && widget->connected) { in is_connected_ep()
1221 widget->endpoints[dir] = snd_soc_dapm_suspend_check(widget); in is_connected_ep()
1222 return widget->endpoints[dir]; in is_connected_ep()
1228 if (path->weak || path->is_supply) in is_connected_ep()
1231 if (path->walking) in is_connected_ep()
1236 if (path->connect) { in is_connected_ep()
1237 path->walking = 1; in is_connected_ep()
1238 con += fn(path->node[dir], list, custom_stop_condition); in is_connected_ep()
1239 path->walking = 0; in is_connected_ep()
1243 widget->endpoints[dir] = con; in is_connected_ep()
1285 * snd_soc_dapm_dai_get_connected_widgets - query audio path and it's widgets.
1308 struct snd_soc_card *card = dai->component->card; in snd_soc_dapm_dai_get_connected_widgets()
1354 soc_dapm_async_complete(w->dapm); in dapm_regulator_event()
1357 if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) { in dapm_regulator_event()
1358 ret = regulator_allow_bypass(w->regulator, false); in dapm_regulator_event()
1360 dev_warn(w->dapm->dev, in dapm_regulator_event()
1362 w->name, ret); in dapm_regulator_event()
1365 return regulator_enable(w->regulator); in dapm_regulator_event()
1367 if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) { in dapm_regulator_event()
1368 ret = regulator_allow_bypass(w->regulator, true); in dapm_regulator_event()
1370 dev_warn(w->dapm->dev, in dapm_regulator_event()
1372 w->name, ret); in dapm_regulator_event()
1375 return regulator_disable_deferred(w->regulator, w->shift); in dapm_regulator_event()
1386 struct snd_soc_dapm_pinctrl_priv *priv = w->priv; in dapm_pinctrl_event()
1387 struct pinctrl *p = w->pinctrl; in dapm_pinctrl_event()
1391 return -EIO; in dapm_pinctrl_event()
1394 s = pinctrl_lookup_state(p, priv->active_state); in dapm_pinctrl_event()
1396 s = pinctrl_lookup_state(p, priv->sleep_state); in dapm_pinctrl_event()
1411 if (!w->clk) in dapm_clock_event()
1412 return -EIO; in dapm_clock_event()
1414 soc_dapm_async_complete(w->dapm); in dapm_clock_event()
1417 return clk_prepare_enable(w->clk); in dapm_clock_event()
1419 clk_disable_unprepare(w->clk); in dapm_clock_event()
1429 if (w->power_checked) in dapm_widget_power_check()
1430 return w->new_power; in dapm_widget_power_check()
1432 if (w->force) in dapm_widget_power_check()
1433 w->new_power = 1; in dapm_widget_power_check()
1435 w->new_power = w->power_check(w); in dapm_widget_power_check()
1437 w->power_checked = true; in dapm_widget_power_check()
1439 return w->new_power; in dapm_widget_power_check()
1454 /* Check to see if a power supply is needed */
1465 if (path->weak) in dapm_supply_check_power()
1468 if (path->connected && in dapm_supply_check_power()
1469 !path->connected(path->source, path->sink)) in dapm_supply_check_power()
1472 if (dapm_widget_power_check(path->sink)) in dapm_supply_check_power()
1481 return w->connected; in dapm_always_on_check_power()
1498 WARN_ONCE(sort[a->id] == 0, "offset a->id %d not initialized\n", a->id); in dapm_seq_compare()
1499 WARN_ONCE(sort[b->id] == 0, "offset b->id %d not initialized\n", b->id); in dapm_seq_compare()
1501 if (sort[a->id] != sort[b->id]) in dapm_seq_compare()
1502 return sort[a->id] - sort[b->id]; in dapm_seq_compare()
1503 if (a->subseq != b->subseq) { in dapm_seq_compare()
1505 return a->subseq - b->subseq; in dapm_seq_compare()
1507 return b->subseq - a->subseq; in dapm_seq_compare()
1509 if (a->reg != b->reg) in dapm_seq_compare()
1510 return a->reg - b->reg; in dapm_seq_compare()
1511 if (a->dapm != b->dapm) in dapm_seq_compare()
1512 return (unsigned long)a->dapm - (unsigned long)b->dapm; in dapm_seq_compare()
1517 /* Insert a widget in order into a DAPM power sequence. */
1526 list_add_tail(&new_widget->power_list, &w->power_list); in dapm_seq_insert()
1530 list_add_tail(&new_widget->power_list, list); in dapm_seq_insert()
1537 int power; in dapm_seq_check_event() local
1542 power = 1; in dapm_seq_check_event()
1546 power = 1; in dapm_seq_check_event()
1550 power = 0; in dapm_seq_check_event()
1554 power = 0; in dapm_seq_check_event()
1558 power = 1; in dapm_seq_check_event()
1562 power = 0; in dapm_seq_check_event()
1569 if (w->new_power != power) in dapm_seq_check_event()
1572 if (w->event && (w->event_flags & event)) { in dapm_seq_check_event()
1575 pop_dbg(w->dapm->dev, card->pop_time, "pop test : %s %s\n", in dapm_seq_check_event()
1576 w->name, ev_name); in dapm_seq_check_event()
1577 soc_dapm_async_complete(w->dapm); in dapm_seq_check_event()
1579 ret = w->event(w, NULL, event); in dapm_seq_check_event()
1582 dev_err(w->dapm->dev, "ASoC: %s: %s event failed: %d\n", in dapm_seq_check_event()
1583 ev_name, w->name, ret); in dapm_seq_check_event()
1598 reg = w->reg; in dapm_seq_run_coalesced()
1599 dapm = w->dapm; in dapm_seq_run_coalesced()
1602 WARN_ON(reg != w->reg || dapm != w->dapm); in dapm_seq_run_coalesced()
1603 w->power = w->new_power; in dapm_seq_run_coalesced()
1605 mask |= w->mask << w->shift; in dapm_seq_run_coalesced()
1606 if (w->power) in dapm_seq_run_coalesced()
1607 value |= w->on_val << w->shift; in dapm_seq_run_coalesced()
1609 value |= w->off_val << w->shift; in dapm_seq_run_coalesced()
1611 pop_dbg(dapm->dev, card->pop_time, in dapm_seq_run_coalesced()
1613 w->name, reg, value, mask); in dapm_seq_run_coalesced()
1625 pop_dbg(dapm->dev, card->pop_time, in dapm_seq_run_coalesced()
1627 value, mask, reg, card->pop_time); in dapm_seq_run_coalesced()
1628 pop_wait(card->pop_time); in dapm_seq_run_coalesced()
1638 /* Apply a DAPM power sequence.
1640 * We walk over a pre-sorted list of widgets to apply power to. In
1652 int cur_sort = -1; in dapm_seq_run()
1653 int cur_subseq = -1; in dapm_seq_run()
1668 if (sort[w->id] != cur_sort || w->reg != cur_reg || in dapm_seq_run()
1669 w->dapm != cur_dapm || w->subseq != cur_subseq) { in dapm_seq_run()
1673 if (cur_dapm && cur_dapm->component) { in dapm_seq_run()
1677 cur_dapm->component, in dapm_seq_run()
1681 if (cur_dapm && w->dapm != cur_dapm) in dapm_seq_run()
1685 cur_sort = -1; in dapm_seq_run()
1691 switch (w->id) { in dapm_seq_run()
1693 if (!w->event) in dapm_seq_run()
1697 ret = w->event(w, in dapm_seq_run()
1700 ret = w->event(w, in dapm_seq_run()
1705 if (!w->event) in dapm_seq_run()
1709 ret = w->event(w, in dapm_seq_run()
1712 ret = w->event(w, in dapm_seq_run()
1718 cur_sort = sort[w->id]; in dapm_seq_run()
1719 cur_subseq = w->subseq; in dapm_seq_run()
1720 cur_reg = w->reg; in dapm_seq_run()
1721 cur_dapm = w->dapm; in dapm_seq_run()
1722 list_move(&w->power_list, &pending); in dapm_seq_run()
1727 dev_err(w->dapm->dev, in dapm_seq_run()
1728 "ASoC: Failed to apply widget power: %d\n", ret); in dapm_seq_run()
1734 if (cur_dapm && cur_dapm->component) { in dapm_seq_run()
1738 cur_dapm->component, in dapm_seq_run()
1748 struct snd_soc_dapm_update *update = card->update; in dapm_widget_update()
1754 if (!update || !dapm_kcontrol_is_powered(update->kcontrol)) in dapm_widget_update()
1757 wlist = dapm_kcontrol_get_wlist(update->kcontrol); in dapm_widget_update()
1760 if (w->event && (w->event_flags & SND_SOC_DAPM_PRE_REG)) { in dapm_widget_update()
1761 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG); in dapm_widget_update()
1763 dev_err(w->dapm->dev, "ASoC: %s DAPM pre-event failed: %d\n", in dapm_widget_update()
1764 w->name, ret); in dapm_widget_update()
1771 ret = soc_dapm_update_bits(w->dapm, update->reg, update->mask, in dapm_widget_update()
1772 update->val); in dapm_widget_update()
1774 dev_err(w->dapm->dev, "ASoC: %s DAPM update failed: %d\n", in dapm_widget_update()
1775 w->name, ret); in dapm_widget_update()
1777 if (update->has_second_set) { in dapm_widget_update()
1778 ret = soc_dapm_update_bits(w->dapm, update->reg2, in dapm_widget_update()
1779 update->mask2, update->val2); in dapm_widget_update()
1781 dev_err(w->dapm->dev, in dapm_widget_update()
1783 w->name, ret); in dapm_widget_update()
1787 if (w->event && (w->event_flags & SND_SOC_DAPM_POST_REG)) { in dapm_widget_update()
1788 ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG); in dapm_widget_update()
1790 dev_err(w->dapm->dev, "ASoC: %s DAPM post-event failed: %d\n", in dapm_widget_update()
1791 w->name, ret); in dapm_widget_update()
1796 /* Async callback run prior to DAPM sequences - brings to _PREPARE if
1805 if (d->bias_level == SND_SOC_BIAS_OFF && in dapm_pre_sequence_async()
1806 d->target_bias_level != SND_SOC_BIAS_OFF) { in dapm_pre_sequence_async()
1807 if (d->dev && cookie) in dapm_pre_sequence_async()
1808 pm_runtime_get_sync(d->dev); in dapm_pre_sequence_async()
1812 dev_err(d->dev, in dapm_pre_sequence_async()
1817 if ((d->target_bias_level == SND_SOC_BIAS_ON && in dapm_pre_sequence_async()
1818 d->bias_level != SND_SOC_BIAS_ON) || in dapm_pre_sequence_async()
1819 (d->target_bias_level != SND_SOC_BIAS_ON && in dapm_pre_sequence_async()
1820 d->bias_level == SND_SOC_BIAS_ON)) { in dapm_pre_sequence_async()
1823 dev_err(d->dev, in dapm_pre_sequence_async()
1828 /* Async callback run prior to DAPM sequences - brings to their final
1837 if (d->bias_level == SND_SOC_BIAS_PREPARE && in dapm_post_sequence_async()
1838 (d->target_bias_level == SND_SOC_BIAS_STANDBY || in dapm_post_sequence_async()
1839 d->target_bias_level == SND_SOC_BIAS_OFF)) { in dapm_post_sequence_async()
1842 dev_err(d->dev, "ASoC: Failed to apply standby bias: %d\n", in dapm_post_sequence_async()
1847 if (d->bias_level == SND_SOC_BIAS_STANDBY && in dapm_post_sequence_async()
1848 d->target_bias_level == SND_SOC_BIAS_OFF) { in dapm_post_sequence_async()
1851 dev_err(d->dev, "ASoC: Failed to turn off bias: %d\n", in dapm_post_sequence_async()
1854 if (d->dev && cookie) in dapm_post_sequence_async()
1855 pm_runtime_put(d->dev); in dapm_post_sequence_async()
1859 if (d->bias_level == SND_SOC_BIAS_PREPARE && in dapm_post_sequence_async()
1860 d->target_bias_level == SND_SOC_BIAS_ON) { in dapm_post_sequence_async()
1863 dev_err(d->dev, "ASoC: Failed to apply active bias: %d\n", in dapm_post_sequence_async()
1869 bool power, bool connect) in dapm_widget_set_peer_power() argument
1879 if (power != peer->power) in dapm_widget_set_peer_power()
1888 int power; in dapm_power_one_widget() local
1890 switch (w->id) { in dapm_power_one_widget()
1892 power = 0; in dapm_power_one_widget()
1895 power = 1; in dapm_power_one_widget()
1901 power = dapm_widget_power_check(w); in dapm_power_one_widget()
1903 if (w->power == power) in dapm_power_one_widget()
1906 trace_snd_soc_dapm_widget_power(w, power); in dapm_power_one_widget()
1909 * If we changed our power state perhaps our neigbours in dapm_power_one_widget()
1913 dapm_widget_set_peer_power(path->source, power, path->connect); in dapm_power_one_widget()
1918 if (!w->is_supply) in dapm_power_one_widget()
1920 dapm_widget_set_peer_power(path->sink, power, path->connect); in dapm_power_one_widget()
1923 if (power) in dapm_power_one_widget()
1931 if (dapm->idle_bias_off) in dapm_idle_bias_off()
1934 switch (snd_power_get_state(dapm->card->snd_card)) { in dapm_idle_bias_off()
1937 return dapm->suspend_bias_off; in dapm_idle_bias_off()
1947 * A complete path is a route that has valid endpoints i.e.:-
1970 d->target_bias_level = SND_SOC_BIAS_OFF; in dapm_power_widgets()
1972 d->target_bias_level = SND_SOC_BIAS_STANDBY; in dapm_power_widgets()
1977 /* Check which widgets we need to power and store them in in dapm_power_widgets()
1983 list_for_each_entry(w, &card->dapm_dirty, dirty) { in dapm_power_widgets()
1988 switch (w->id) { in dapm_power_widgets()
1994 list_del_init(&w->dirty); in dapm_power_widgets()
1998 if (w->new_power) { in dapm_power_widgets()
1999 d = w->dapm; in dapm_power_widgets()
2004 * generally don't require full power. Signal in dapm_power_widgets()
2006 * power impact themselves. in dapm_power_widgets()
2008 switch (w->id) { in dapm_power_widgets()
2017 if (d->target_bias_level < SND_SOC_BIAS_STANDBY) in dapm_power_widgets()
2018 d->target_bias_level = SND_SOC_BIAS_STANDBY; in dapm_power_widgets()
2021 d->target_bias_level = SND_SOC_BIAS_ON; in dapm_power_widgets()
2033 if (d->target_bias_level > bias) in dapm_power_widgets()
2034 bias = d->target_bias_level; in dapm_power_widgets()
2037 d->target_bias_level = bias; in dapm_power_widgets()
2042 dapm_pre_sequence_async(&card->dapm, 0); in dapm_power_widgets()
2045 if (d != &card->dapm && d->bias_level != d->target_bias_level) in dapm_power_widgets()
2059 /* Power down widgets first; try to avoid amplifying pops. */ in dapm_power_widgets()
2064 /* Now power up. */ in dapm_power_widgets()
2069 if (d != &card->dapm && d->bias_level != d->target_bias_level) in dapm_power_widgets()
2075 dapm_post_sequence_async(&card->dapm, 0); in dapm_power_widgets()
2079 if (!d->component) in dapm_power_widgets()
2082 ret = snd_soc_component_stream_event(d->component, event); in dapm_power_widgets()
2087 pop_dbg(card->dev, card->pop_time, in dapm_power_widgets()
2088 "DAPM sequencing finished, waiting %dms\n", card->pop_time); in dapm_power_widgets()
2089 pop_wait(card->pop_time); in dapm_power_widgets()
2101 struct snd_soc_dapm_widget *w = file->private_data; in dapm_widget_power_read_file()
2110 return -ENOMEM; in dapm_widget_power_read_file()
2112 snd_soc_dapm_mutex_lock_root(w->dapm); in dapm_widget_power_read_file()
2115 if (w->is_supply) { in dapm_widget_power_read_file()
2124 w->name, w->power ? "On" : "Off", in dapm_widget_power_read_file()
2125 w->force ? " (forced)" : "", in, out); in dapm_widget_power_read_file()
2127 if (w->reg >= 0) in dapm_widget_power_read_file()
2128 ret += scnprintf(buf + ret, PAGE_SIZE - ret, in dapm_widget_power_read_file()
2129 " - R%d(0x%x) mask 0x%x", in dapm_widget_power_read_file()
2130 w->reg, w->reg, w->mask << w->shift); in dapm_widget_power_read_file()
2132 ret += scnprintf(buf + ret, PAGE_SIZE - ret, "\n"); in dapm_widget_power_read_file()
2134 if (w->sname) in dapm_widget_power_read_file()
2135 ret += scnprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n", in dapm_widget_power_read_file()
2136 w->sname, in dapm_widget_power_read_file()
2137 w->active ? "active" : "inactive"); in dapm_widget_power_read_file()
2142 if (p->connected && !p->connected(p->source, p->sink)) in dapm_widget_power_read_file()
2145 if (!p->connect) in dapm_widget_power_read_file()
2148 ret += scnprintf(buf + ret, PAGE_SIZE - ret, in dapm_widget_power_read_file()
2151 p->name ? p->name : "static", in dapm_widget_power_read_file()
2152 p->node[rdir]->name); in dapm_widget_power_read_file()
2156 snd_soc_dapm_mutex_unlock(w->dapm); in dapm_widget_power_read_file()
2173 struct snd_soc_dapm_context *dapm = file->private_data; in dapm_bias_read_file()
2176 switch (dapm->bias_level) { in dapm_bias_read_file()
2190 WARN(1, "Unknown bias_level %d\n", dapm->bias_level); in dapm_bias_read_file()
2211 dapm->debugfs_dapm = debugfs_create_dir("dapm", parent); in snd_soc_dapm_debugfs_init()
2213 debugfs_create_file("bias_level", 0444, dapm->debugfs_dapm, dapm, in snd_soc_dapm_debugfs_init()
2219 struct snd_soc_dapm_context *dapm = w->dapm; in dapm_debugfs_add_widget()
2221 if (!dapm->debugfs_dapm || !w->name) in dapm_debugfs_add_widget()
2224 debugfs_create_file(w->name, 0444, dapm->debugfs_dapm, w, in dapm_debugfs_add_widget()
2230 struct snd_soc_dapm_context *dapm = w->dapm; in dapm_debugfs_free_widget()
2232 if (!dapm->debugfs_dapm || !w->name) in dapm_debugfs_free_widget()
2235 debugfs_lookup_and_remove(w->name, dapm->debugfs_dapm); in dapm_debugfs_free_widget()
2240 debugfs_remove_recursive(dapm->debugfs_dapm); in dapm_debugfs_cleanup()
2241 dapm->debugfs_dapm = NULL; in dapm_debugfs_cleanup()
2265 * soc_dapm_connect_path() - Connects or disconnects a path
2274 if (path->connect == connect) in soc_dapm_connect_path()
2277 path->connect = connect; in soc_dapm_connect_path()
2278 dapm_mark_dirty(path->source, reason); in soc_dapm_connect_path()
2279 dapm_mark_dirty(path->sink, reason); in soc_dapm_connect_path()
2283 /* test and update the power status of a mux widget */
2297 if (e && !(strcmp(path->name, e->texts[mux]))) in soc_dapm_mux_update_power()
2315 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_mux_update_power()
2319 card->update = update; in snd_soc_dapm_mux_update_power()
2321 card->update = NULL; in snd_soc_dapm_mux_update_power()
2329 /* test and update the power status of a mixer or switch widget */
2380 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_mixer_update_power()
2384 card->update = update; in snd_soc_dapm_mixer_update_power()
2385 ret = soc_dapm_mixer_update_power(card, kcontrol, connect, -1); in snd_soc_dapm_mixer_update_power()
2386 card->update = NULL; in snd_soc_dapm_mixer_update_power()
2405 if (!cmpnt->card) in dapm_widget_show_component()
2408 for_each_card_widgets(cmpnt->card, w) { in dapm_widget_show_component()
2409 if (w->dapm != dapm) in dapm_widget_show_component()
2412 /* only display widgets that burn power */ in dapm_widget_show_component()
2413 switch (w->id) { in dapm_widget_show_component()
2430 if (w->name) in dapm_widget_show_component()
2432 w->name, w->power ? "On":"Off"); in dapm_widget_show_component()
2466 snd_soc_dapm_mutex_lock_root(rtd->card); in dapm_widget_show()
2469 struct snd_soc_component *cmpnt = codec_dai->component; in dapm_widget_show()
2474 snd_soc_dapm_mutex_unlock(rtd->card); in dapm_widget_show()
2488 list_del(&path->list_node[SND_SOC_DAPM_DIR_IN]); in dapm_free_path()
2489 list_del(&path->list_node[SND_SOC_DAPM_DIR_OUT]); in dapm_free_path()
2490 list_del(&path->list_kcontrol); in dapm_free_path()
2491 list_del(&path->list); in dapm_free_path()
2496 * snd_soc_dapm_free_widget - Free specified widget
2509 list_del(&w->list); in snd_soc_dapm_free_widget()
2510 list_del(&w->dirty); in snd_soc_dapm_free_widget()
2523 kfree(w->kcontrols); in snd_soc_dapm_free_widget()
2524 kfree_const(w->name); in snd_soc_dapm_free_widget()
2525 kfree_const(w->sname); in snd_soc_dapm_free_widget()
2535 for_each_card_widgets_safe(dapm->card, w, next_w) { in dapm_free_widgets()
2536 if (w->dapm != dapm) in dapm_free_widgets()
2541 dapm->wcache_sink = NULL; in dapm_free_widgets()
2542 dapm->wcache_source = NULL; in dapm_free_widgets()
2563 for_each_card_widgets(dapm->card, w) { in dapm_find_widget()
2564 if (!strcmp(w->name, pin_name)) { in dapm_find_widget()
2565 if (w->dapm == dapm) in dapm_find_widget()
2592 dev_err(dapm->dev, "ASoC: DAPM unknown pin %s\n", pin); in __snd_soc_dapm_set_pin()
2593 return -EINVAL; in __snd_soc_dapm_set_pin()
2596 if (w->connected != status) { in __snd_soc_dapm_set_pin()
2603 w->connected = status; in __snd_soc_dapm_set_pin()
2605 w->force = 0; in __snd_soc_dapm_set_pin()
2623 * snd_soc_dapm_sync_unlocked - scan and power dapm paths
2639 if (!snd_soc_card_is_instantiated(dapm->card)) in snd_soc_dapm_sync_unlocked()
2642 return dapm_power_widgets(dapm->card, SND_SOC_DAPM_STREAM_NOP); in snd_soc_dapm_sync_unlocked()
2647 * snd_soc_dapm_sync - scan and power dapm paths
2670 switch (w->id) { in dapm_update_dai_chan()
2678 dev_dbg(w->dapm->dev, "%s DAI route %s -> %s\n", in dapm_update_dai_chan()
2679 w->channel < channels ? "Connecting" : "Disconnecting", in dapm_update_dai_chan()
2680 p->source->name, p->sink->name); in dapm_update_dai_chan()
2682 if (w->channel < channels) in dapm_update_dai_chan()
2694 int dir = substream->stream; in dapm_update_dai_unlocked()
2705 dev_dbg(dai->dev, "Update DAI routes for %s %s\n", dai->name, in dapm_update_dai_unlocked()
2709 ret = dapm_update_dai_chan(p, p->sink, channels); in dapm_update_dai_unlocked()
2715 ret = dapm_update_dai_chan(p, p->source, channels); in dapm_update_dai_unlocked()
2730 snd_soc_dapm_mutex_lock(rtd->card); in snd_soc_dapm_update_dai()
2732 snd_soc_dapm_mutex_unlock(rtd->card); in snd_soc_dapm_update_dai()
2740 struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm); in snd_soc_dapm_widget_name_cmp()
2741 const char *wname = widget->name; in snd_soc_dapm_widget_name_cmp()
2743 if (component->name_prefix) in snd_soc_dapm_widget_name_cmp()
2744 wname += strlen(component->name_prefix) + 1; /* plus space */ in snd_soc_dapm_widget_name_cmp()
2751 * dapm_update_widget_flags() - Re-compute widget sink and source flags
2754 * Some widgets have a dynamic category which depends on which neighbors they
2765 switch (w->id) { in dapm_update_widget_flags()
2768 if (w->dapm->card->fully_routed) in dapm_update_widget_flags()
2772 if (p->source->id == snd_soc_dapm_micbias || in dapm_update_widget_flags()
2773 p->source->id == snd_soc_dapm_mic || in dapm_update_widget_flags()
2774 p->source->id == snd_soc_dapm_line || in dapm_update_widget_flags()
2775 p->source->id == snd_soc_dapm_output) { in dapm_update_widget_flags()
2783 if (w->dapm->card->fully_routed) in dapm_update_widget_flags()
2787 if (p->sink->id == snd_soc_dapm_spk || in dapm_update_widget_flags()
2788 p->sink->id == snd_soc_dapm_hp || in dapm_update_widget_flags()
2789 p->sink->id == snd_soc_dapm_line || in dapm_update_widget_flags()
2790 p->sink->id == snd_soc_dapm_input) { in dapm_update_widget_flags()
2799 if (!list_empty(&w->edges[dir])) in dapm_update_widget_flags()
2807 w->is_ep = ep; in dapm_update_widget_flags()
2820 switch (source->id) { in snd_soc_dapm_check_dynamic_path()
2828 switch (sink->id) { in snd_soc_dapm_check_dynamic_path()
2840 dev_err(dapm->dev, in snd_soc_dapm_check_dynamic_path()
2841 "Direct connection between demux and mixer/mux not supported for path %s -> [%s] -> %s\n", in snd_soc_dapm_check_dynamic_path()
2842 source->name, control, sink->name); in snd_soc_dapm_check_dynamic_path()
2843 return -EINVAL; in snd_soc_dapm_check_dynamic_path()
2845 dev_err(dapm->dev, in snd_soc_dapm_check_dynamic_path()
2846 "Control not supported for path %s -> [%s] -> %s\n", in snd_soc_dapm_check_dynamic_path()
2847 source->name, control, sink->name); in snd_soc_dapm_check_dynamic_path()
2848 return -EINVAL; in snd_soc_dapm_check_dynamic_path()
2864 if (wsink->is_supply && !wsource->is_supply) { in snd_soc_dapm_add_path()
2865 dev_err(dapm->dev, in snd_soc_dapm_add_path()
2866 "Connecting non-supply widget to supply widget is not supported (%s -> %s)\n", in snd_soc_dapm_add_path()
2867 wsource->name, wsink->name); in snd_soc_dapm_add_path()
2868 return -EINVAL; in snd_soc_dapm_add_path()
2871 if (connected && !wsource->is_supply) { in snd_soc_dapm_add_path()
2872 dev_err(dapm->dev, in snd_soc_dapm_add_path()
2873 "connected() callback only supported for supply widgets (%s -> %s)\n", in snd_soc_dapm_add_path()
2874 wsource->name, wsink->name); in snd_soc_dapm_add_path()
2875 return -EINVAL; in snd_soc_dapm_add_path()
2878 if (wsource->is_supply && control) { in snd_soc_dapm_add_path()
2879 dev_err(dapm->dev, in snd_soc_dapm_add_path()
2880 "Conditional paths are not supported for supply widgets (%s -> [%s] -> %s)\n", in snd_soc_dapm_add_path()
2881 wsource->name, control, wsink->name); in snd_soc_dapm_add_path()
2882 return -EINVAL; in snd_soc_dapm_add_path()
2891 return -ENOMEM; in snd_soc_dapm_add_path()
2893 path->node[SND_SOC_DAPM_DIR_IN] = wsource; in snd_soc_dapm_add_path()
2894 path->node[SND_SOC_DAPM_DIR_OUT] = wsink; in snd_soc_dapm_add_path()
2896 path->connected = connected; in snd_soc_dapm_add_path()
2897 INIT_LIST_HEAD(&path->list); in snd_soc_dapm_add_path()
2898 INIT_LIST_HEAD(&path->list_kcontrol); in snd_soc_dapm_add_path()
2900 if (wsource->is_supply || wsink->is_supply) in snd_soc_dapm_add_path()
2901 path->is_supply = 1; in snd_soc_dapm_add_path()
2905 path->connect = 1; in snd_soc_dapm_add_path()
2907 switch (wsource->id) { in snd_soc_dapm_add_path()
2917 switch (wsink->id) { in snd_soc_dapm_add_path()
2935 list_add(&path->list, &dapm->card->paths); in snd_soc_dapm_add_path()
2938 list_add(&path->list_node[dir], &path->node[dir]->edges[dir]); in snd_soc_dapm_add_path()
2941 dapm_update_widget_flags(path->node[dir]); in snd_soc_dapm_add_path()
2942 dapm_mark_dirty(path->node[dir], "Route added"); in snd_soc_dapm_add_path()
2945 if (snd_soc_card_is_instantiated(dapm->card) && path->connect) in snd_soc_dapm_add_path()
2971 prefix, route->sink); in snd_soc_dapm_add_route()
2974 prefix, route->source); in snd_soc_dapm_add_route()
2977 sink = route->sink; in snd_soc_dapm_add_route()
2978 source = route->source; in snd_soc_dapm_add_route()
2981 wsource = dapm_wcache_lookup(dapm->wcache_source, source); in snd_soc_dapm_add_route()
2982 wsink = dapm_wcache_lookup(dapm->wcache_sink, sink); in snd_soc_dapm_add_route()
2991 for_each_card_widgets(dapm->card, w) { in snd_soc_dapm_add_route()
2992 if (!wsink && !(strcmp(w->name, sink))) { in snd_soc_dapm_add_route()
2994 if (w->dapm == dapm) { in snd_soc_dapm_add_route()
3001 dev_warn(dapm->dev, in snd_soc_dapm_add_route()
3003 w->name); in snd_soc_dapm_add_route()
3006 if (!wsource && !(strcmp(w->name, source))) { in snd_soc_dapm_add_route()
3008 if (w->dapm == dapm) { in snd_soc_dapm_add_route()
3015 dev_warn(dapm->dev, in snd_soc_dapm_add_route()
3017 w->name); in snd_soc_dapm_add_route()
3026 ret = -ENODEV; in snd_soc_dapm_add_route()
3034 dapm->wcache_sink = wsink; in snd_soc_dapm_add_route()
3035 dapm->wcache_source = wsource; in snd_soc_dapm_add_route()
3037 ret = snd_soc_dapm_add_path(dapm, wsource, wsink, route->control, in snd_soc_dapm_add_route()
3038 route->connected); in snd_soc_dapm_add_route()
3041 dev_err(dapm->dev, "ASoC: Failed to add route %s%s -%s%s%s> %s%s\n", in snd_soc_dapm_add_route()
3043 !route->control ? "" : "> [", in snd_soc_dapm_add_route()
3044 !route->control ? "" : route->control, in snd_soc_dapm_add_route()
3045 !route->control ? "" : "] -", in snd_soc_dapm_add_route()
3060 if (route->control) { in snd_soc_dapm_del_route()
3061 dev_err(dapm->dev, in snd_soc_dapm_del_route()
3063 return -EINVAL; in snd_soc_dapm_del_route()
3069 prefix, route->sink); in snd_soc_dapm_del_route()
3072 prefix, route->source); in snd_soc_dapm_del_route()
3075 sink = route->sink; in snd_soc_dapm_del_route()
3076 source = route->source; in snd_soc_dapm_del_route()
3080 list_for_each_entry(p, &dapm->card->paths, list) { in snd_soc_dapm_del_route()
3081 if (strcmp(p->source->name, source) != 0) in snd_soc_dapm_del_route()
3083 if (strcmp(p->sink->name, sink) != 0) in snd_soc_dapm_del_route()
3090 struct snd_soc_dapm_widget *wsource = path->source; in snd_soc_dapm_del_route()
3091 struct snd_soc_dapm_widget *wsink = path->sink; in snd_soc_dapm_del_route()
3095 if (path->connect) in snd_soc_dapm_del_route()
3104 dev_warn(dapm->dev, "ASoC: Route %s->%s does not exist\n", in snd_soc_dapm_del_route()
3112 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
3143 * snd_soc_dapm_del_routes - Remove routes between DAPM widgets
3170 route->source, in snd_soc_dapm_weak_route()
3173 route->sink, in snd_soc_dapm_weak_route()
3179 dev_err(dapm->dev, "ASoC: Unable to find source %s for weak route\n", in snd_soc_dapm_weak_route()
3180 route->source); in snd_soc_dapm_weak_route()
3181 return -ENODEV; in snd_soc_dapm_weak_route()
3185 dev_err(dapm->dev, "ASoC: Unable to find sink %s for weak route\n", in snd_soc_dapm_weak_route()
3186 route->sink); in snd_soc_dapm_weak_route()
3187 return -ENODEV; in snd_soc_dapm_weak_route()
3190 if (route->control || route->connected) in snd_soc_dapm_weak_route()
3191 dev_warn(dapm->dev, "ASoC: Ignoring control for weak route %s->%s\n", in snd_soc_dapm_weak_route()
3192 route->source, route->sink); in snd_soc_dapm_weak_route()
3195 if (path->sink == sink) { in snd_soc_dapm_weak_route()
3196 path->weak = 1; in snd_soc_dapm_weak_route()
3202 dev_err(dapm->dev, "ASoC: No path found for weak route %s->%s\n", in snd_soc_dapm_weak_route()
3203 route->source, route->sink); in snd_soc_dapm_weak_route()
3205 dev_warn(dapm->dev, "ASoC: %d paths found for weak route %s->%s\n", in snd_soc_dapm_weak_route()
3206 count, route->source, route->sink); in snd_soc_dapm_weak_route()
3212 * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak
3219 * power decisions. The main intended use case is for sidetone paths
3247 * snd_soc_dapm_new_widgets - add new dapm widgets
3263 if (w->new) in snd_soc_dapm_new_widgets()
3266 if (w->num_kcontrols) { in snd_soc_dapm_new_widgets()
3267 w->kcontrols = kcalloc(w->num_kcontrols, in snd_soc_dapm_new_widgets()
3270 if (!w->kcontrols) { in snd_soc_dapm_new_widgets()
3272 return -ENOMEM; in snd_soc_dapm_new_widgets()
3276 switch(w->id) { in snd_soc_dapm_new_widgets()
3298 /* Read the initial power state from the device */ in snd_soc_dapm_new_widgets()
3299 if (w->reg >= 0) { in snd_soc_dapm_new_widgets()
3300 val = soc_dapm_read(w->dapm, w->reg); in snd_soc_dapm_new_widgets()
3301 val = val >> w->shift; in snd_soc_dapm_new_widgets()
3302 val &= w->mask; in snd_soc_dapm_new_widgets()
3303 if (val == w->on_val) in snd_soc_dapm_new_widgets()
3304 w->power = 1; in snd_soc_dapm_new_widgets()
3307 w->new = 1; in snd_soc_dapm_new_widgets()
3320 * snd_soc_dapm_get_volsw - dapm mixer get callback
3333 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_dapm_get_volsw()
3334 int reg = mc->reg; in snd_soc_dapm_get_volsw()
3335 unsigned int shift = mc->shift; in snd_soc_dapm_get_volsw()
3336 int max = mc->max; in snd_soc_dapm_get_volsw()
3338 unsigned int mask = (1 << fls(max)) - 1; in snd_soc_dapm_get_volsw()
3339 unsigned int invert = mc->invert; in snd_soc_dapm_get_volsw()
3347 if (reg != mc->rreg) in snd_soc_dapm_get_volsw()
3348 reg_val = soc_dapm_read(dapm, mc->rreg); in snd_soc_dapm_get_volsw()
3351 rval = (reg_val >> mc->rshift) & mask; in snd_soc_dapm_get_volsw()
3362 ucontrol->value.integer.value[0] = max - val; in snd_soc_dapm_get_volsw()
3364 ucontrol->value.integer.value[0] = val; in snd_soc_dapm_get_volsw()
3368 ucontrol->value.integer.value[1] = max - rval; in snd_soc_dapm_get_volsw()
3370 ucontrol->value.integer.value[1] = rval; in snd_soc_dapm_get_volsw()
3378 * snd_soc_dapm_put_volsw - dapm mixer set callback
3390 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_put_volsw()
3392 (struct soc_mixer_control *)kcontrol->private_value; in snd_soc_dapm_put_volsw()
3393 int reg = mc->reg; in snd_soc_dapm_put_volsw()
3394 unsigned int shift = mc->shift; in snd_soc_dapm_put_volsw()
3395 int max = mc->max; in snd_soc_dapm_put_volsw()
3397 unsigned int mask = (1 << width) - 1; in snd_soc_dapm_put_volsw()
3398 unsigned int invert = mc->invert; in snd_soc_dapm_put_volsw()
3400 int connect, rconnect = -1, change, reg_change = 0; in snd_soc_dapm_put_volsw()
3404 val = (ucontrol->value.integer.value[0] & mask); in snd_soc_dapm_put_volsw()
3408 val = max - val; in snd_soc_dapm_put_volsw()
3411 rval = (ucontrol->value.integer.value[1] & mask); in snd_soc_dapm_put_volsw()
3414 rval = max - rval; in snd_soc_dapm_put_volsw()
3421 dev_warn(dapm->dev, in snd_soc_dapm_put_volsw()
3423 kcontrol->id.name); in snd_soc_dapm_put_volsw()
3428 rval = rval << mc->rshift; in snd_soc_dapm_put_volsw()
3433 reg_change |= soc_dapm_test_bits(dapm, mc->rreg, in snd_soc_dapm_put_volsw()
3434 mask << mc->rshift, in snd_soc_dapm_put_volsw()
3442 update.reg2 = mc->rreg; in snd_soc_dapm_put_volsw()
3443 update.mask2 = mask << mc->rshift; in snd_soc_dapm_put_volsw()
3450 card->update = &update; in snd_soc_dapm_put_volsw()
3456 card->update = NULL; in snd_soc_dapm_put_volsw()
3469 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
3481 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in snd_soc_dapm_get_enum_double()
3485 if (e->reg != SND_SOC_NOPM && dapm_kcontrol_is_powered(kcontrol)) { in snd_soc_dapm_get_enum_double()
3486 reg_val = soc_dapm_read(dapm, e->reg); in snd_soc_dapm_get_enum_double()
3492 val = (reg_val >> e->shift_l) & e->mask; in snd_soc_dapm_get_enum_double()
3493 ucontrol->value.enumerated.item[0] = snd_soc_enum_val_to_item(e, val); in snd_soc_dapm_get_enum_double()
3494 if (e->shift_l != e->shift_r) { in snd_soc_dapm_get_enum_double()
3495 val = (reg_val >> e->shift_r) & e->mask; in snd_soc_dapm_get_enum_double()
3497 ucontrol->value.enumerated.item[1] = val; in snd_soc_dapm_get_enum_double()
3505 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
3517 struct snd_soc_card *card = dapm->card; in snd_soc_dapm_put_enum_double()
3518 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; in snd_soc_dapm_put_enum_double()
3519 unsigned int *item = ucontrol->value.enumerated.item; in snd_soc_dapm_put_enum_double()
3525 if (item[0] >= e->items) in snd_soc_dapm_put_enum_double()
3526 return -EINVAL; in snd_soc_dapm_put_enum_double()
3528 val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l; in snd_soc_dapm_put_enum_double()
3529 mask = e->mask << e->shift_l; in snd_soc_dapm_put_enum_double()
3530 if (e->shift_l != e->shift_r) { in snd_soc_dapm_put_enum_double()
3531 if (item[1] > e->items) in snd_soc_dapm_put_enum_double()
3532 return -EINVAL; in snd_soc_dapm_put_enum_double()
3533 val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_r; in snd_soc_dapm_put_enum_double()
3534 mask |= e->mask << e->shift_r; in snd_soc_dapm_put_enum_double()
3541 if (e->reg != SND_SOC_NOPM) in snd_soc_dapm_put_enum_double()
3542 reg_change = soc_dapm_test_bits(dapm, e->reg, mask, val); in snd_soc_dapm_put_enum_double()
3547 update.reg = e->reg; in snd_soc_dapm_put_enum_double()
3550 card->update = &update; in snd_soc_dapm_put_enum_double()
3555 card->update = NULL; in snd_soc_dapm_put_enum_double()
3568 * snd_soc_dapm_info_pin_switch - Info for a pin switch
3578 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; in snd_soc_dapm_info_pin_switch()
3579 uinfo->count = 1; in snd_soc_dapm_info_pin_switch()
3580 uinfo->value.integer.min = 0; in snd_soc_dapm_info_pin_switch()
3581 uinfo->value.integer.max = 1; in snd_soc_dapm_info_pin_switch()
3588 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
3597 const char *pin = (const char *)kcontrol->private_value; in snd_soc_dapm_get_pin_switch()
3601 ucontrol->value.integer.value[0] = in snd_soc_dapm_get_pin_switch()
3602 snd_soc_dapm_get_pin_status(&card->dapm, pin); in snd_soc_dapm_get_pin_switch()
3611 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
3620 const char *pin = (const char *)kcontrol->private_value; in snd_soc_dapm_put_pin_switch()
3624 ret = __snd_soc_dapm_set_pin(&card->dapm, pin, in snd_soc_dapm_put_pin_switch()
3625 !!ucontrol->value.integer.value[0]); in snd_soc_dapm_put_pin_switch()
3628 snd_soc_dapm_sync(&card->dapm); in snd_soc_dapm_put_pin_switch()
3639 int ret = -ENOMEM; in snd_soc_dapm_new_control_unlocked()
3645 switch (w->id) { in snd_soc_dapm_new_control_unlocked()
3647 w->regulator = devm_regulator_get(dapm->dev, widget->name); in snd_soc_dapm_new_control_unlocked()
3648 if (IS_ERR(w->regulator)) { in snd_soc_dapm_new_control_unlocked()
3649 ret = PTR_ERR(w->regulator); in snd_soc_dapm_new_control_unlocked()
3653 if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) { in snd_soc_dapm_new_control_unlocked()
3654 ret = regulator_allow_bypass(w->regulator, true); in snd_soc_dapm_new_control_unlocked()
3656 dev_warn(dapm->dev, in snd_soc_dapm_new_control_unlocked()
3658 w->name, ret); in snd_soc_dapm_new_control_unlocked()
3662 w->pinctrl = devm_pinctrl_get(dapm->dev); in snd_soc_dapm_new_control_unlocked()
3663 if (IS_ERR(w->pinctrl)) { in snd_soc_dapm_new_control_unlocked()
3664 ret = PTR_ERR(w->pinctrl); in snd_soc_dapm_new_control_unlocked()
3672 w->clk = devm_clk_get(dapm->dev, widget->name); in snd_soc_dapm_new_control_unlocked()
3673 if (IS_ERR(w->clk)) { in snd_soc_dapm_new_control_unlocked()
3674 ret = PTR_ERR(w->clk); in snd_soc_dapm_new_control_unlocked()
3682 switch (w->id) { in snd_soc_dapm_new_control_unlocked()
3684 w->is_ep = SND_SOC_DAPM_EP_SOURCE; in snd_soc_dapm_new_control_unlocked()
3685 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3688 if (!dapm->card->fully_routed) in snd_soc_dapm_new_control_unlocked()
3689 w->is_ep = SND_SOC_DAPM_EP_SOURCE; in snd_soc_dapm_new_control_unlocked()
3690 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3694 w->is_ep = SND_SOC_DAPM_EP_SINK; in snd_soc_dapm_new_control_unlocked()
3695 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3698 if (!dapm->card->fully_routed) in snd_soc_dapm_new_control_unlocked()
3699 w->is_ep = SND_SOC_DAPM_EP_SINK; in snd_soc_dapm_new_control_unlocked()
3700 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3704 w->is_ep = SND_SOC_DAPM_EP_SOURCE; in snd_soc_dapm_new_control_unlocked()
3705 w->power_check = dapm_always_on_check_power; in snd_soc_dapm_new_control_unlocked()
3708 w->is_ep = SND_SOC_DAPM_EP_SINK; in snd_soc_dapm_new_control_unlocked()
3709 w->power_check = dapm_always_on_check_power; in snd_soc_dapm_new_control_unlocked()
3735 w->power_check = dapm_generic_check_power; in snd_soc_dapm_new_control_unlocked()
3742 w->is_supply = 1; in snd_soc_dapm_new_control_unlocked()
3743 w->power_check = dapm_supply_check_power; in snd_soc_dapm_new_control_unlocked()
3746 w->power_check = dapm_always_on_check_power; in snd_soc_dapm_new_control_unlocked()
3750 w->dapm = dapm; in snd_soc_dapm_new_control_unlocked()
3751 INIT_LIST_HEAD(&w->list); in snd_soc_dapm_new_control_unlocked()
3752 INIT_LIST_HEAD(&w->dirty); in snd_soc_dapm_new_control_unlocked()
3754 list_add_tail(&w->list, &dapm->card->widgets); in snd_soc_dapm_new_control_unlocked()
3757 INIT_LIST_HEAD(&w->edges[dir]); in snd_soc_dapm_new_control_unlocked()
3758 w->endpoints[dir] = -1; in snd_soc_dapm_new_control_unlocked()
3762 w->connected = 1; in snd_soc_dapm_new_control_unlocked()
3766 dev_err_probe(dapm->dev, ret, "ASoC: Failed to request %s\n", in snd_soc_dapm_new_control_unlocked()
3767 w->name); in snd_soc_dapm_new_control_unlocked()
3768 kfree_const(w->name); in snd_soc_dapm_new_control_unlocked()
3769 kfree_const(w->sname); in snd_soc_dapm_new_control_unlocked()
3776 * snd_soc_dapm_new_control - create new dapm control
3799 * snd_soc_dapm_new_controls - create new dapm controls
3853 return -ENOMEM; in snd_soc_dai_link_event_pre_pmu()
3857 ret = -ENOMEM; in snd_soc_dai_link_event_pre_pmu()
3861 substream->runtime = runtime; in snd_soc_dai_link_event_pre_pmu()
3863 substream->stream = SNDRV_PCM_STREAM_CAPTURE; in snd_soc_dai_link_event_pre_pmu()
3865 source = path->source->priv; in snd_soc_dai_link_event_pre_pmu()
3871 snd_soc_dai_activate(source, substream->stream); in snd_soc_dai_link_event_pre_pmu()
3874 substream->stream = SNDRV_PCM_STREAM_PLAYBACK; in snd_soc_dai_link_event_pre_pmu()
3876 sink = path->sink->priv; in snd_soc_dai_link_event_pre_pmu()
3882 snd_soc_dai_activate(sink, substream->stream); in snd_soc_dai_link_event_pre_pmu()
3885 substream->hw_opened = 1; in snd_soc_dai_link_event_pre_pmu()
3892 config = rtd->dai_link->c2c_params + rtd->c2c_params_select; in snd_soc_dai_link_event_pre_pmu()
3894 dev_err(w->dapm->dev, "ASoC: link config missing\n"); in snd_soc_dai_link_event_pre_pmu()
3895 ret = -EINVAL; in snd_soc_dai_link_event_pre_pmu()
3900 if (!config->formats) { in snd_soc_dai_link_event_pre_pmu()
3901 dev_warn(w->dapm->dev, "ASoC: Invalid format was specified\n"); in snd_soc_dai_link_event_pre_pmu()
3903 ret = -EINVAL; in snd_soc_dai_link_event_pre_pmu()
3907 fmt = ffs(config->formats) - 1; in snd_soc_dai_link_event_pre_pmu()
3910 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min = in snd_soc_dai_link_event_pre_pmu()
3911 config->rate_min; in snd_soc_dai_link_event_pre_pmu()
3912 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max = in snd_soc_dai_link_event_pre_pmu()
3913 config->rate_max; in snd_soc_dai_link_event_pre_pmu()
3914 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min in snd_soc_dai_link_event_pre_pmu()
3915 = config->channels_min; in snd_soc_dai_link_event_pre_pmu()
3916 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->max in snd_soc_dai_link_event_pre_pmu()
3917 = config->channels_max; in snd_soc_dai_link_event_pre_pmu()
3919 substream->stream = SNDRV_PCM_STREAM_CAPTURE; in snd_soc_dai_link_event_pre_pmu()
3921 source = path->source->priv; in snd_soc_dai_link_event_pre_pmu()
3930 substream->stream = SNDRV_PCM_STREAM_PLAYBACK; in snd_soc_dai_link_event_pre_pmu()
3932 sink = path->sink->priv; in snd_soc_dai_link_event_pre_pmu()
3941 runtime->format = params_format(params); in snd_soc_dai_link_event_pre_pmu()
3942 runtime->subformat = params_subformat(params); in snd_soc_dai_link_event_pre_pmu()
3943 runtime->channels = params_channels(params); in snd_soc_dai_link_event_pre_pmu()
3944 runtime->rate = params_rate(params); in snd_soc_dai_link_event_pre_pmu()
3958 struct snd_pcm_substream *substream = w->priv; in snd_soc_dai_link_event()
3959 int ret = 0, saved_stream = substream->stream; in snd_soc_dai_link_event()
3961 if (WARN_ON(list_empty(&w->edges[SND_SOC_DAPM_DIR_OUT]) || in snd_soc_dai_link_event()
3962 list_empty(&w->edges[SND_SOC_DAPM_DIR_IN]))) in snd_soc_dai_link_event()
3963 return -EINVAL; in snd_soc_dai_link_event()
3975 sink = path->sink->priv; in snd_soc_dai_link_event()
3984 sink = path->sink->priv; in snd_soc_dai_link_event()
3990 substream->stream = SNDRV_PCM_STREAM_CAPTURE; in snd_soc_dai_link_event()
3992 source = path->source->priv; in snd_soc_dai_link_event()
3996 substream->stream = SNDRV_PCM_STREAM_PLAYBACK; in snd_soc_dai_link_event()
3998 sink = path->sink->priv; in snd_soc_dai_link_event()
4002 substream->stream = SNDRV_PCM_STREAM_CAPTURE; in snd_soc_dai_link_event()
4004 source = path->source->priv; in snd_soc_dai_link_event()
4005 snd_soc_dai_deactivate(source, substream->stream); in snd_soc_dai_link_event()
4009 substream->stream = SNDRV_PCM_STREAM_PLAYBACK; in snd_soc_dai_link_event()
4011 sink = path->sink->priv; in snd_soc_dai_link_event()
4012 snd_soc_dai_deactivate(sink, substream->stream); in snd_soc_dai_link_event()
4018 kfree(substream->runtime); in snd_soc_dai_link_event()
4023 ret = -EINVAL; in snd_soc_dai_link_event()
4028 substream->stream = saved_stream; in snd_soc_dai_link_event()
4036 struct snd_soc_pcm_runtime *rtd = w->priv; in snd_soc_dapm_dai_link_get()
4038 ucontrol->value.enumerated.item[0] = rtd->c2c_params_select; in snd_soc_dapm_dai_link_get()
4047 struct snd_soc_pcm_runtime *rtd = w->priv; in snd_soc_dapm_dai_link_put()
4050 if (w->power) in snd_soc_dapm_dai_link_put()
4051 return -EBUSY; in snd_soc_dapm_dai_link_put()
4053 if (ucontrol->value.enumerated.item[0] == rtd->c2c_params_select) in snd_soc_dapm_dai_link_put()
4056 if (ucontrol->value.enumerated.item[0] >= rtd->dai_link->num_c2c_params) in snd_soc_dapm_dai_link_put()
4057 return -EINVAL; in snd_soc_dapm_dai_link_put()
4059 rtd->c2c_params_select = ucontrol->value.enumerated.item[0]; in snd_soc_dapm_dai_link_put()
4072 devm_kfree(card->dev, (void *)*private_value); in snd_soc_dapm_free_kcontrol()
4078 devm_kfree(card->dev, (void *)w_param_text[count]); in snd_soc_dapm_free_kcontrol()
4079 devm_kfree(card->dev, w_param_text); in snd_soc_dapm_free_kcontrol()
4102 if (!config->stream_name) { in snd_soc_dapm_alloc_kcontrol()
4103 dev_warn(card->dapm.dev, in snd_soc_dapm_alloc_kcontrol()
4107 devm_kasprintf(card->dev, GFP_KERNEL, in snd_soc_dapm_alloc_kcontrol()
4111 w_param_text[count] = devm_kmemdup(card->dev, in snd_soc_dapm_alloc_kcontrol()
4112 config->stream_name, in snd_soc_dapm_alloc_kcontrol()
4113 strlen(config->stream_name) + 1, in snd_soc_dapm_alloc_kcontrol()
4125 (unsigned long) devm_kmemdup(card->dev, in snd_soc_dapm_alloc_kcontrol()
4129 dev_err(card->dev, "ASoC: Failed to create control for %s widget\n", in snd_soc_dapm_alloc_kcontrol()
4135 kcontrol_news = devm_kmemdup(card->dev, &kcontrol_dai_link[0], in snd_soc_dapm_alloc_kcontrol()
4139 dev_err(card->dev, "ASoC: Failed to create control for %s widget\n", in snd_soc_dapm_alloc_kcontrol()
4163 int ret = -ENOMEM; in snd_soc_dapm_new_dai()
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()
4174 if (rtd->dai_link->num_c2c_params > 1) { in snd_soc_dapm_new_dai()
4175 w_param_text = devm_kcalloc(card->dev, in snd_soc_dapm_new_dai()
4176 rtd->dai_link->num_c2c_params, in snd_soc_dapm_new_dai()
4183 rtd->dai_link->c2c_params, in snd_soc_dapm_new_dai()
4184 rtd->dai_link->num_c2c_params, in snd_soc_dapm_new_dai()
4200 dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name); in snd_soc_dapm_new_dai()
4202 w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template); in snd_soc_dapm_new_dai()
4208 w->priv = substream; in snd_soc_dapm_new_dai()
4213 devm_kfree(card->dev, (void *)template.kcontrol_news); in snd_soc_dapm_new_dai()
4215 rtd->dai_link->num_c2c_params, w_param_text); in snd_soc_dapm_new_dai()
4217 devm_kfree(card->dev, link_name); in snd_soc_dapm_new_dai()
4219 dev_err(rtd->dev, "ASoC: Failed to create %s-%s widget: %d\n", in snd_soc_dapm_new_dai()
4220 rtd->dai_link->name, id, ret); in snd_soc_dapm_new_dai()
4225 * snd_soc_dapm_new_dai_widgets - Create new DAPM widgets
4237 WARN_ON(dapm->dev != dai->dev); in snd_soc_dapm_new_dai_widgets()
4242 if (dai->driver->playback.stream_name) { in snd_soc_dapm_new_dai_widgets()
4244 template.name = dai->driver->playback.stream_name; in snd_soc_dapm_new_dai_widgets()
4245 template.sname = dai->driver->playback.stream_name; in snd_soc_dapm_new_dai_widgets()
4247 dev_dbg(dai->dev, "ASoC: adding %s widget\n", in snd_soc_dapm_new_dai_widgets()
4254 w->priv = dai; in snd_soc_dapm_new_dai_widgets()
4258 if (dai->driver->capture.stream_name) { in snd_soc_dapm_new_dai_widgets()
4260 template.name = dai->driver->capture.stream_name; in snd_soc_dapm_new_dai_widgets()
4261 template.sname = dai->driver->capture.stream_name; in snd_soc_dapm_new_dai_widgets()
4263 dev_dbg(dai->dev, "ASoC: adding %s widget\n", in snd_soc_dapm_new_dai_widgets()
4270 w->priv = dai; in snd_soc_dapm_new_dai_widgets()
4286 switch (dai_w->id) { in snd_soc_dapm_link_dai_widgets()
4295 if (!dai_w->priv) { in snd_soc_dapm_link_dai_widgets()
4296 dev_dbg(card->dev, "dai widget %s has no DAI\n", in snd_soc_dapm_link_dai_widgets()
4297 dai_w->name); in snd_soc_dapm_link_dai_widgets()
4301 dai = dai_w->priv; in snd_soc_dapm_link_dai_widgets()
4305 if (w->dapm != dai_w->dapm) in snd_soc_dapm_link_dai_widgets()
4308 switch (w->id) { in snd_soc_dapm_link_dai_widgets()
4316 if (!w->sname || !strstr(w->sname, dai_w->sname)) in snd_soc_dapm_link_dai_widgets()
4319 if (dai_w->id == snd_soc_dapm_dai_in) { in snd_soc_dapm_link_dai_widgets()
4326 dev_dbg(dai->dev, "%s -> %s\n", src->name, sink->name); in snd_soc_dapm_link_dai_widgets()
4327 snd_soc_dapm_add_path(w->dapm, src, sink, NULL, NULL); in snd_soc_dapm_link_dai_widgets()
4341 dev_dbg(dapm->dev, "connected DAI link %s:%s -> %s:%s\n", in dapm_connect_dai_routes()
4342 src_dai->component->name, src->name, in dapm_connect_dai_routes()
4343 sink_dai->component->name, sink->name); in dapm_connect_dai_routes()
4358 struct snd_soc_dai_link *dai_link = rtd->dai_link; in dapm_connect_dai_pair()
4381 if (dai_link->c2c_params && !rtd->c2c_widget[stream]) { in dapm_connect_dai_pair()
4382 struct snd_pcm_substream *substream = rtd->pcm->streams[stream].substream; in dapm_connect_dai_pair()
4389 rtd->c2c_widget[stream] = dai; in dapm_connect_dai_pair()
4392 dapm_connect_dai_routes(&card->dapm, src_dai[stream], *src[stream], in dapm_connect_dai_pair()
4393 rtd->c2c_widget[stream], in dapm_connect_dai_pair()
4410 if (w->id == snd_soc_dapm_dai_in) { in soc_dapm_dai_stream_event()
4420 w->active = 1; in soc_dapm_dai_stream_event()
4421 w->is_ep = ep; in soc_dapm_dai_stream_event()
4424 w->active = 0; in soc_dapm_dai_stream_event()
4425 w->is_ep = 0; in soc_dapm_dai_stream_event()
4448 * dynamic FE links have no fixed DAI mapping. in snd_soc_dapm_connect_dai_link_widgets()
4449 * CODEC<->CODEC links have no direct connection. in snd_soc_dapm_connect_dai_link_widgets()
4451 if (rtd->dai_link->dynamic) in snd_soc_dapm_connect_dai_link_widgets()
4456 * soc.h :: [dai_link->ch_maps Image sample] in snd_soc_dapm_connect_dai_link_widgets()
4459 cpu_dai = snd_soc_rtd_to_cpu(rtd, ch_maps->cpu); in snd_soc_dapm_connect_dai_link_widgets()
4460 codec_dai = snd_soc_rtd_to_codec(rtd, ch_maps->codec); in snd_soc_dapm_connect_dai_link_widgets()
4476 dapm_power_widgets(rtd->card, event); in soc_dapm_stream_event()
4480 * snd_soc_dapm_stream_event - send a stream event to the dapm core
4486 * necessary widget power changes.
4493 struct snd_soc_card *card = rtd->card; in snd_soc_dapm_stream_event()
4510 rtd->pop_wait = 1; in snd_soc_dapm_stream_stop()
4512 &rtd->delayed_work, in snd_soc_dapm_stream_stop()
4513 msecs_to_jiffies(rtd->pmdown_time)); in snd_soc_dapm_stream_stop()
4524 * snd_soc_dapm_enable_pin_unlocked - enable pin.
4534 * do any widget power switching.
4544 * snd_soc_dapm_enable_pin - enable pin.
4552 * do any widget power switching.
4569 * snd_soc_dapm_force_enable_pin_unlocked - force a pin to be enabled
4580 * do any widget power switching.
4588 dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin); in snd_soc_dapm_force_enable_pin_unlocked()
4589 return -EINVAL; in snd_soc_dapm_force_enable_pin_unlocked()
4592 dev_dbg(w->dapm->dev, "ASoC: force enable pin %s\n", pin); in snd_soc_dapm_force_enable_pin_unlocked()
4593 if (!w->connected) { in snd_soc_dapm_force_enable_pin_unlocked()
4595 * w->force does not affect the number of input or output paths, in snd_soc_dapm_force_enable_pin_unlocked()
4596 * so we only have to recheck if w->connected is changed in snd_soc_dapm_force_enable_pin_unlocked()
4600 w->connected = 1; in snd_soc_dapm_force_enable_pin_unlocked()
4602 w->force = 1; in snd_soc_dapm_force_enable_pin_unlocked()
4610 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
4619 * do any widget power switching.
4637 * snd_soc_dapm_disable_pin_unlocked - disable pin.
4646 * do any widget power switching.
4656 * snd_soc_dapm_disable_pin - disable pin.
4663 * do any widget power switching.
4681 * snd_soc_dapm_nc_pin_unlocked - permanently disable pin.
4694 * do any widget power switching.
4704 * snd_soc_dapm_nc_pin - permanently disable pin.
4715 * do any widget power switching.
4732 * snd_soc_dapm_get_pin_status - get audio pin status
4736 * Get audio pin status - connected or disconnected.
4746 return w->connected; in snd_soc_dapm_get_pin_status()
4753 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
4769 dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin); in snd_soc_dapm_ignore_suspend()
4770 return -EINVAL; in snd_soc_dapm_ignore_suspend()
4773 w->ignore_suspend = 1; in snd_soc_dapm_ignore_suspend()
4780 * snd_soc_dapm_free - free dapm resources
4789 list_del(&dapm->list); in snd_soc_dapm_free()
4797 dapm->card = card; in snd_soc_dapm_init()
4798 dapm->component = component; in snd_soc_dapm_init()
4799 dapm->bias_level = SND_SOC_BIAS_OFF; in snd_soc_dapm_init()
4802 dapm->dev = component->dev; in snd_soc_dapm_init()
4803 dapm->idle_bias_off = !component->driver->idle_bias_on; in snd_soc_dapm_init()
4804 dapm->suspend_bias_off = component->driver->suspend_bias_off; in snd_soc_dapm_init()
4806 dapm->dev = card->dev; in snd_soc_dapm_init()
4809 INIT_LIST_HEAD(&dapm->list); in snd_soc_dapm_init()
4811 list_add(&dapm->list, &card->dapm_list); in snd_soc_dapm_init()
4817 struct snd_soc_card *card = dapm->card; in soc_dapm_shutdown_dapm()
4824 for_each_card_widgets(dapm->card, w) { in soc_dapm_shutdown_dapm()
4825 if (w->dapm != dapm) in soc_dapm_shutdown_dapm()
4827 if (w->power) { in soc_dapm_shutdown_dapm()
4829 w->new_power = 0; in soc_dapm_shutdown_dapm()
4834 /* If there were no widgets to power down we're already in in soc_dapm_shutdown_dapm()
4838 if (dapm->bias_level == SND_SOC_BIAS_ON) in soc_dapm_shutdown_dapm()
4842 if (dapm->bias_level == SND_SOC_BIAS_PREPARE) in soc_dapm_shutdown_dapm()
4851 * snd_soc_dapm_shutdown - callback for system shutdown
4858 if (dapm != &card->dapm) { in snd_soc_dapm_shutdown()
4860 if (dapm->bias_level == SND_SOC_BIAS_STANDBY) in snd_soc_dapm_shutdown()
4866 soc_dapm_shutdown_dapm(&card->dapm); in snd_soc_dapm_shutdown()
4867 if (card->dapm.bias_level == SND_SOC_BIAS_STANDBY) in snd_soc_dapm_shutdown()
4868 snd_soc_dapm_set_bias_level(&card->dapm, in snd_soc_dapm_shutdown()
4874 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");