26 #include <linux/module.h>
32 #include <linux/bitops.h>
39 #include <linux/slab.h>
48 #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++;
51 static int dapm_up_seq[] = {
77 static int dapm_down_seq[] = {
103 static void pop_wait(
u32 pop_time)
109 static void pop_dbg(
struct device *
dev,
u32 pop_time,
const char *
fmt, ...)
131 return !list_empty(&w->
dirty);
136 if (!dapm_dirty_widget(w)) {
174 static inline struct snd_card *dapm_get_snd_card(
178 return dapm->
codec->card->snd_card;
180 return dapm->
platform->card->snd_card;
193 return dapm->
codec->card;
223 dev_err(w->
dapm->dev,
"no valid widget read method\n");
234 dev_err(w->
dapm->dev,
"no valid widget write method\n");
255 unsigned short reg,
unsigned int mask,
unsigned int value)
258 unsigned int old,
new;
263 reg, mask, value, &change);
268 ret = soc_widget_read(w, reg);
270 soc_widget_unlock(w);
275 new = (old & ~mask) | (value & mask);
278 ret = soc_widget_write(w, reg,
new);
280 soc_widget_unlock(w);
284 soc_widget_unlock(w);
305 trace_snd_soc_bias_level_start(card, level);
313 if (dapm->
codec->driver->set_bias_level)
314 ret = dapm->
codec->driver->set_bias_level(dapm->
codec,
318 }
else if (!card || dapm != &card->
dapm) {
328 trace_snd_soc_bias_level_done(card, level);
344 unsigned int reg = mc->
reg;
347 unsigned int mask = (1 << fls(
max)) - 1;
350 val = soc_widget_read(w, reg);
351 val = (val >>
shift) & mask;
363 val = soc_widget_read(w, e->
reg);
367 for (i = 0; i < e->
max; i++) {
393 val = soc_widget_read(w, e->
reg);
401 for (i = 0; i < e->
max; i++) {
447 for (i = 0; i < e->
max; i++) {
449 list_add(&path->
list, &dapm->
card->paths);
453 dapm_set_path_status(dest, path, 0);
471 list_add(&path->
list, &dapm->
card->paths);
475 dapm_set_path_status(dest, path, i);
493 if (w == kcontrolw || w->
dapm != kcontrolw->
dapm)
520 prefix = dapm->
codec->name_prefix;
525 prefix_len =
strlen(prefix) + 1;
549 "asoc: can't allocate widget list for %s\n",
582 "%s %s", w->
name + prefix_len,
591 ((
char *)path->
long_name)[name_len - 1] =
'\0';
599 "asoc: failed to add dapm kcontrol %s: %d\n",
629 "asoc: mux %s has incorrect number of controls\n",
634 shared = dapm_is_shared_kcontrol(dapm, w, &w->
kcontrol_news[0],
648 "asoc: can't allocate widget list for %s\n", w->
name);
652 wlist->
widgets[wlistentries - 1] =
w;
656 prefix = dapm->
codec->name_prefix;
666 prefix_len =
strlen(prefix) + 1;
677 name + prefix_len, prefix);
680 dev_err(dapm->
dev,
"failed to add kcontrol %s: %d\n",
692 path->kcontrol = kcontrol;
700 if (w->num_kcontrols)
702 "asoc: PGA controls not supported: '%s'\n", w->name);
727 if (widget->ignore_suspend)
728 dev_dbg(widget->dapm->dev,
"%s ignoring suspend\n",
730 return widget->ignore_suspend;
741 int wlistsize, wlistentries,
i;
760 dev_err(w->
dapm->dev,
"can't allocate widget list for %s\n",
767 dev_dbg(w->
dapm->dev,
"added %s in widget list pos %d\n",
790 switch (widget->
id) {
799 switch (widget->
id) {
804 widget->
outputs = snd_soc_dapm_suspend_check(widget);
814 widget->
outputs = snd_soc_dapm_suspend_check(widget);
822 !list_empty(&widget->
sources))) {
823 widget->
outputs = snd_soc_dapm_suspend_check(widget);
837 trace_snd_soc_dapm_output_path(widget, path);
845 err = dapm_list_add_widget(list, path->
sink);
847 dev_err(widget->
dapm->dev,
"could not add widget %s\n",
853 con += is_connected_output_ep(path->
sink, list);
877 switch (widget->
id) {
887 switch (widget->
id) {
892 widget->
inputs = snd_soc_dapm_suspend_check(widget);
902 widget->
inputs = snd_soc_dapm_suspend_check(widget);
908 widget->
inputs = snd_soc_dapm_suspend_check(widget);
915 !list_empty(&widget->
sinks))) {
916 widget->
inputs = snd_soc_dapm_suspend_check(widget);
922 widget->
inputs = snd_soc_dapm_suspend_check(widget);
936 trace_snd_soc_dapm_input_path(widget, path);
944 err = dapm_list_add_widget(list, path->
source);
946 dev_err(widget->
dapm->dev,
"could not add widget %s\n",
952 con += is_connected_input_ep(path->
source, list);
987 trace_snd_soc_dapm_connected(paths, stream);
988 dapm_clear_walk(&card->
dapm);
1007 soc_widget_update_bits_locked(w, -(w->
reg + 1),
1027 "Failed to bypass %s: %d\n",
1037 "Failed to unbypass %s: %d\n",
1055 #ifdef CONFIG_HAVE_CLK
1090 in = is_connected_input_ep(w,
NULL);
1091 dapm_clear_walk(w->
dapm);
1092 out = is_connected_output_ep(w,
NULL);
1093 dapm_clear_walk(w->
dapm);
1094 return out != 0 && in != 0;
1104 return dapm_generic_check_power(w);
1115 in = is_connected_input_ep(w,
NULL);
1116 dapm_clear_walk(w->
dapm);
1119 return dapm_generic_check_power(w);
1131 out = is_connected_output_ep(w,
NULL);
1132 dapm_clear_walk(w->
dapm);
1135 return dapm_generic_check_power(w);
1160 if (dapm_widget_power_check(path->
sink))
1164 dapm_clear_walk(w->
dapm);
1183 sort = dapm_down_seq;
1185 if (sort[a->
id] != sort[b->
id])
1186 return sort[a->
id] - sort[b->
id];
1196 return (
unsigned long)a->
dapm - (
unsigned long)b->
dapm;
1209 if (dapm_seq_compare(new_widget, w, power_up) < 0) {
1221 const char *ev_name;
1226 ev_name =
"PRE_PMU";
1230 ev_name =
"POST_PMU";
1234 ev_name =
"PRE_PMD";
1238 ev_name =
"POST_PMD";
1246 if (w->
power != power)
1250 pop_dbg(dapm->
dev, card->
pop_time,
"pop test : %s %s\n",
1252 trace_snd_soc_dapm_widget_event_start(w, event);
1254 trace_snd_soc_dapm_widget_event_done(w, event);
1256 pr_err(
"%s: %s event failed: %d\n",
1257 ev_name, w->
name, ret);
1268 unsigned int value = 0;
1269 unsigned int mask = 0;
1270 unsigned int cur_mask;
1276 cur_mask = 1 << w->
shift;
1289 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
1290 w->
name, reg, value, mask);
1305 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
1308 soc_widget_update_bits_locked(w, reg, mask, value);
1326 struct list_head *list,
int event,
bool power_up)
1331 int cur_subseq = -1;
1340 sort = dapm_down_seq;
1346 if (sort[w->
id] != cur_sort || w->
reg != cur_reg ||
1347 w->
dapm != cur_dapm || w->
subseq != cur_subseq) {
1348 if (!list_empty(&pending))
1349 dapm_seq_run_coalesced(cur_dapm, &pending);
1352 for (i = 0; i <
ARRAY_SIZE(dapm_up_seq); i++)
1353 if (sort[i] == cur_sort)
1359 INIT_LIST_HEAD(&pending);
1395 cur_sort = sort[w->
id];
1405 "Failed to apply widget power: %d\n", ret);
1408 if (!list_empty(&pending))
1409 dapm_seq_run_coalesced(cur_dapm, &pending);
1412 for (i = 0; i <
ARRAY_SIZE(dapm_up_seq); i++)
1413 if (sort[i] == cur_sort)
1434 pr_err(
"%s DAPM pre-event failed: %d\n",
1438 ret = soc_widget_update_bits_locked(w, update->
reg, update->
mask,
1441 pr_err(
"%s DAPM update failed: %d\n", w->
name, ret);
1447 pr_err(
"%s DAPM post-event failed: %d\n",
1464 pm_runtime_get_sync(d->
dev);
1469 "Failed to turn on bias: %d\n", ret);
1477 "Failed to prepare bias: %d\n", ret);
1484 static void dapm_post_sequence_async(
void *data,
async_cookie_t cookie)
1495 dev_err(d->
dev,
"Failed to apply standby bias: %d\n",
1504 dev_err(d->
dev,
"Failed to turn off bias: %d\n", ret);
1507 pm_runtime_put(d->
dev);
1515 dev_err(d->
dev,
"Failed to apply active bias: %d\n",
1521 bool power,
bool connect)
1531 if (power != peer->
power)
1541 if (w->
power == power)
1544 trace_snd_soc_dapm_widget_power(w, power);
1551 dapm_widget_set_peer_power(path->
source, power,
1564 dapm_widget_set_peer_power(path->
sink, power,
1572 dapm_seq_insert(w, up_list,
true);
1574 dapm_seq_insert(w, down_list,
false);
1587 dapm_seq_insert(w, down_list,
false);
1590 dapm_seq_insert(w, up_list,
true);
1594 power = dapm_widget_power_check(w);
1596 dapm_widget_set_power(w, power, up_list, down_list);
1620 trace_snd_soc_dapm_start(card);
1638 dapm_power_one_widget(w, &up_list, &down_list);
1648 list_del_init(&w->
dirty);
1689 d->target_bias_level = bias;
1691 trace_snd_soc_dapm_walk_done(card);
1700 dapm_seq_run(dapm, &down_list, event,
false);
1702 dapm_widget_update(dapm);
1705 dapm_seq_run(dapm, &up_list, event,
true);
1715 if (d->stream_event)
1716 d->stream_event(d, event);
1719 pop_dbg(dapm->dev, card->pop_time,
1720 "DAPM sequencing finished, waiting %dms\n", card->pop_time);
1721 pop_wait(card->pop_time);
1723 trace_snd_soc_dapm_done(card);
1728 #ifdef CONFIG_DEBUG_FS
1730 char __user *user_buf,
1731 size_t count, loff_t *ppos)
1743 in = is_connected_input_ep(w,
NULL);
1744 dapm_clear_walk(w->
dapm);
1745 out = is_connected_output_ep(w,
NULL);
1746 dapm_clear_walk(w->
dapm);
1750 w->
force ?
" (forced)" :
"", in, out);
1754 " - R%d(0x%x) bit %d",
1762 w->
active ?
"active" :
"inactive");
1770 " in \"%s\" \"%s\"\n",
1780 " out \"%s\" \"%s\"\n",
1793 .read = dapm_widget_power_read_file,
1797 static ssize_t dapm_bias_read_file(
struct file *file,
char __user *user_buf,
1798 size_t count, loff_t *ppos)
1808 level =
"Prepare\n";
1811 level =
"Standby\n";
1818 level =
"Unknown\n";
1828 .read = dapm_bias_read_file,
1839 if (!dapm->debugfs_dapm) {
1841 "Failed to create DAPM debugfs directory\n");
1846 dapm->debugfs_dapm, dapm,
1850 "ASoC: Failed to create bias level debugfs file\n");
1858 if (!dapm->debugfs_dapm || !w->
name)
1862 dapm->debugfs_dapm, w,
1863 &dapm_widget_power_fops);
1866 "ASoC: Failed to create %s debugfs file\n",
1919 "mux disconnection");
1939 ret = soc_dapm_mux_update_power(widget, kcontrol, mux, e);
1985 ret = soc_dapm_mixer_update_power(widget, kcontrol, connect);
2001 char *
state =
"not set";
2024 count +=
sprintf(buf + count,
"%s: %s\n",
2032 switch (codec->
dapm.bias_level) {
2046 count +=
sprintf(buf + count,
"PM State: %s\n", state);
2058 static void snd_soc_dapm_sys_remove(
struct device *dev)
2070 if (w->
dapm != dapm)
2100 bool search_other_contexts)
2107 if (w->
dapm == dapm)
2114 if (search_other_contexts)
2121 const char *pin,
int status)
2126 dev_err(dapm->
dev,
"dapm: unknown pin %s\n", pin);
2157 if (!dapm->
card || !dapm->
card->instantiated)
2176 char prefixed_sink[80];
2177 char prefixed_source[80];
2180 if (dapm->
codec && dapm->
codec->name_prefix) {
2181 snprintf(prefixed_sink,
sizeof(prefixed_sink),
"%s %s",
2183 sink = prefixed_sink;
2184 snprintf(prefixed_source,
sizeof(prefixed_source),
"%s %s",
2186 source = prefixed_source;
2197 if (!wsink && !(
strcmp(w->name, sink))) {
2199 if (w->dapm == dapm)
2203 if (!wsource && !(
strcmp(w->name, source))) {
2205 if (w->dapm == dapm)
2215 if (wsource ==
NULL || wsink ==
NULL)
2225 INIT_LIST_HEAD(&path->
list);
2246 if (control ==
NULL) {
2247 list_add(&path->
list, &dapm->
card->paths);
2248 list_add(&path->
list_sink, &wsink->sources);
2255 switch (wsink->id) {
2274 list_add(&path->
list, &dapm->
card->paths);
2275 list_add(&path->
list_sink, &wsink->sources);
2282 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
2283 &wsink->kcontrol_news[0]);
2290 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
2298 list_add(&path->
list, &dapm->
card->paths);
2299 list_add(&path->
list_sink, &wsink->sources);
2311 dev_warn(dapm->
dev,
"asoc: no dapm match for %s --> %s --> %s\n",
2312 source, control, sink);
2323 char prefixed_sink[80];
2324 char prefixed_source[80];
2328 "Removal of routes with controls not supported\n");
2332 if (dapm->
codec && dapm->
codec->name_prefix) {
2333 snprintf(prefixed_sink,
sizeof(prefixed_sink),
"%s %s",
2335 sink = prefixed_sink;
2336 snprintf(prefixed_source,
sizeof(prefixed_source),
"%s %s",
2338 source = prefixed_source;
2363 dev_warn(dapm->
dev,
"Route %s->%s does not exist\n",
2389 for (i = 0; i < num; i++) {
2390 r = snd_soc_dapm_add_route(dapm, route);
2392 dev_err(dapm->
dev,
"Failed to add route %s->%s\n",
2418 for (i = 0; i < num; i++) {
2419 snd_soc_dapm_del_route(dapm, route);
2441 dev_err(dapm->
dev,
"Unable to find source %s for weak route\n",
2447 dev_err(dapm->
dev,
"Unable to find sink %s for weak route\n",
2453 dev_warn(dapm->
dev,
"Ignoring control for weak route %s->%s\n",
2457 if (path->
sink == sink) {
2464 dev_err(dapm->
dev,
"No path found for weak route %s->%s\n",
2467 dev_warn(dapm->
dev,
"%d paths found for weak route %s->%s\n",
2496 for (i = 0; i < num; i++) {
2497 err = snd_soc_dapm_weak_route(dapm, route);
2559 val = soc_widget_read(w, w->
reg);
2560 val &= 1 << w->
shift;
2571 dapm_debugfs_add_widget(w);
2596 unsigned int reg = mc->
reg;
2599 unsigned int mask = (1 << fls(
max)) - 1;
2600 unsigned int invert = mc->
invert;
2602 if (snd_soc_volsw_is_stereo(mc))
2604 "Control '%s' is stereo, which is not supported\n",
2607 ucontrol->
value.integer.value[0] =
2610 ucontrol->
value.integer.value[0] =
2611 max - ucontrol->
value.integer.value[0];
2635 unsigned int reg = mc->
reg;
2638 unsigned int mask = (1 << fls(
max)) - 1;
2639 unsigned int invert = mc->
invert;
2641 int connect, change;
2645 if (snd_soc_volsw_is_stereo(mc))
2647 "Control '%s' is stereo, which is not supported\n",
2650 val = (ucontrol->
value.integer.value[0] &
mask);
2655 mask = mask << shift;
2674 soc_dapm_mixer_update_power(widget, kcontrol, connect);
2705 ucontrol->
value.enumerated.item[1] =
2729 unsigned int val, mux, change;
2734 if (ucontrol->
value.enumerated.item[0] > e->
max - 1)
2736 mux = ucontrol->
value.enumerated.item[0];
2740 if (ucontrol->
value.enumerated.item[1] > e->
max - 1)
2742 val |= ucontrol->
value.enumerated.item[1] << e->
shift_r;
2762 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2786 ucontrol->
value.enumerated.item[0] = widget->
value;
2812 if (ucontrol->
value.enumerated.item[0] >= e->
max)
2817 change = widget->
value != ucontrol->
value.enumerated.item[0];
2822 widget->
value = ucontrol->
value.enumerated.item[0];
2824 soc_dapm_mux_update_power(widget, kcontrol, widget->
value, e);
2852 unsigned int reg_val, val, mux;
2856 for (mux = 0; mux < e->
max; mux++) {
2857 if (val == e->
values[mux])
2860 ucontrol->
value.enumerated.item[0] = mux;
2863 for (mux = 0; mux < e->
max; mux++) {
2864 if (val == e->
values[mux])
2867 ucontrol->
value.enumerated.item[1] = mux;
2895 unsigned int val, mux, change;
2900 if (ucontrol->
value.enumerated.item[0] > e->
max - 1)
2902 mux = ucontrol->
value.enumerated.item[0];
2906 if (ucontrol->
value.enumerated.item[1] > e->
max - 1)
2928 soc_dapm_mux_update_power(widget, kcontrol, mux, e);
2973 ucontrol->
value.integer.value[0] =
2996 if (ucontrol->
value.integer.value[0])
3016 if ((w = dapm_cnew_widget(widget)) ==
NULL)
3024 dev_err(dapm->
dev,
"Failed to request %s: %d\n",
3030 #ifdef CONFIG_CLKDEV_LOOKUP
3032 if (IS_ERR(w->
clk)) {
3033 ret = PTR_ERR(w->
clk);
3034 dev_err(dapm->
dev,
"Failed to request %s: %d\n",
3056 dapm->
codec->name_prefix, widget->
name);
3109 INIT_LIST_HEAD(&w->
sinks);
3110 INIT_LIST_HEAD(&w->
list);
3111 INIT_LIST_HEAD(&w->
dirty);
3112 list_add(&w->
list, &dapm->
card->widgets);
3138 for (i = 0; i < num; i++) {
3139 w = snd_soc_dapm_new_control(dapm, widget);
3142 "ASoC: Failed to create DAPM control %s\n",
3174 BUG_ON(!source_p || !sink_p);
3178 source = source_p->
source->priv;
3179 sink = sink_p->
sink->priv;
3185 dev_warn(w->
dapm->dev,
"Invalid format %llx specified\n",
3191 params = kzalloc(
sizeof(*params),
GFP_KERNEL);
3208 memset(&substream, 0,
sizeof(substream));
3212 if (source->
driver->ops && source->
driver->ops->hw_params) {
3214 ret = source->
driver->ops->hw_params(&substream,
3218 "hw_params() failed: %d\n", ret);
3223 if (sink->
driver->ops && sink->
driver->ops->hw_params) {
3225 ret = sink->
driver->ops->hw_params(&substream, params,
3229 "hw_params() failed: %d\n", ret);
3238 dev_warn(sink->
dev,
"Failed to unmute: %d\n", ret);
3276 memset(&
template, 0,
sizeof(
template));
3279 template.name = link_name;
3280 template.event = snd_soc_dai_link_event;
3284 dev_dbg(card->
dev,
"adding %s widget\n", link_name);
3286 w = snd_soc_dapm_new_control(&card->
dapm, &
template);
3288 dev_err(card->
dev,
"Failed to create %s widget\n",
3295 memset(&routes, 0,
sizeof(routes));
3298 routes[0].
sink = link_name;
3299 routes[1].
source = link_name;
3314 memset(&
template, 0,
sizeof(
template));
3317 if (dai->
driver->playback.stream_name) {
3319 template.name = dai->
driver->playback.stream_name;
3320 template.sname = dai->
driver->playback.stream_name;
3325 w = snd_soc_dapm_new_control(dapm, &
template);
3327 dev_err(dapm->
dev,
"Failed to create %s widget\n",
3328 dai->
driver->playback.stream_name);
3335 if (dai->
driver->capture.stream_name) {
3337 template.name = dai->
driver->capture.stream_name;
3338 template.sname = dai->
driver->capture.stream_name;
3343 w = snd_soc_dapm_new_control(dapm, &
template);
3345 dev_err(dapm->
dev,
"Failed to create %s widget\n",
3346 dai->
driver->capture.stream_name);
3362 memset(&r, 0,
sizeof(r));
3382 if (dai->
driver->playback.stream_name &&
3384 dai->
driver->playback.stream_name)) {
3390 snd_soc_dapm_add_route(w->
dapm, &r);
3393 if (dai->
driver->capture.stream_name &&
3395 dai->
driver->capture.stream_name)) {
3401 snd_soc_dapm_add_route(w->
dapm, &r);
3463 dapm_power_widgets(&rtd->
card->dapm, event);
3483 soc_dapm_stream_event(rtd, stream, event);
3499 return snd_soc_dapm_set_pin(dapm, pin, 1);
3521 dev_err(dapm->
dev,
"dapm: unknown pin %s\n", pin);
3525 dev_dbg(w->
dapm->dev,
"dapm: force enable pin %s\n", pin);
3546 return snd_soc_dapm_set_pin(dapm, pin, 0);
3566 return snd_soc_dapm_set_pin(dapm, pin, 0);
3608 dev_err(dapm->
dev,
"dapm: unknown pin %s\n", pin);
3618 static bool snd_soc_dapm_widget_in_card_paths(
struct snd_soc_card *card,
3626 "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n",
3667 dev_dbg(codec->
dev,
"Auto NC: DAPMs: card:%p codec:%p\n",
3671 if (w->
dapm != dapm)
3677 dev_dbg(codec->
dev,
"Auto NC: Checking widget %s\n",
3679 if (!snd_soc_dapm_widget_in_card_paths(card, w)) {
3681 "... Not in map; disabling\n");
3699 snd_soc_dapm_sys_remove(dapm->
dev);
3700 dapm_debugfs_cleanup(dapm);
3701 dapm_free_widgets(dapm);
3716 if (w->
dapm != dapm)
3719 dapm_seq_insert(w, &down_list,
false);
3730 snd_soc_dapm_set_bias_level(dapm,
3732 dapm_seq_run(dapm, &down_list, 0,
false);
3734 snd_soc_dapm_set_bias_level(dapm,
3749 soc_dapm_shutdown_codec(&codec->
dapm);
3751 snd_soc_dapm_set_bias_level(&codec->
dapm,