Kuninori Morimoto | c01f3af | 2018-07-02 06:24:31 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // soc-dapm.c -- ALSA SoC Dynamic Audio Power Management |
| 4 | // |
| 5 | // Copyright 2005 Wolfson Microelectronics PLC. |
| 6 | // Author: Liam Girdwood <lrg@slimlogic.co.uk> |
| 7 | // |
| 8 | // Features: |
| 9 | // o Changes power status of internal codec blocks depending on the |
| 10 | // dynamic configuration of codec internal audio paths and active |
| 11 | // DACs/ADCs. |
| 12 | // o Platform power domain - can support external components i.e. amps and |
| 13 | // mic/headphone insertion events. |
| 14 | // o Automatic Mic Bias support |
| 15 | // o Jack insertion power event initiation - e.g. hp insertion will enable |
| 16 | // sinks, dacs, etc |
| 17 | // o Delayed power down of audio subsystem to reduce pops between a quick |
| 18 | // device reopen. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 19 | |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/moduleparam.h> |
| 22 | #include <linux/init.h> |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 23 | #include <linux/async.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 24 | #include <linux/delay.h> |
| 25 | #include <linux/pm.h> |
| 26 | #include <linux/bitops.h> |
| 27 | #include <linux/platform_device.h> |
| 28 | #include <linux/jiffies.h> |
Takashi Iwai | 20496ff | 2009-08-24 09:40:34 +0200 | [diff] [blame] | 29 | #include <linux/debugfs.h> |
Mark Brown | f1aac48 | 2011-12-05 15:17:06 +0000 | [diff] [blame] | 30 | #include <linux/pm_runtime.h> |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 31 | #include <linux/regulator/consumer.h> |
Srinivas Kandagatla | 5b2d15b | 2018-03-10 02:37:27 +0000 | [diff] [blame] | 32 | #include <linux/pinctrl/consumer.h> |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 33 | #include <linux/clk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 35 | #include <sound/core.h> |
| 36 | #include <sound/pcm.h> |
| 37 | #include <sound/pcm_params.h> |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 38 | #include <sound/soc.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 39 | #include <sound/initval.h> |
| 40 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 41 | #include <trace/events/asoc.h> |
| 42 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 43 | #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++; |
| 44 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 45 | #define SND_SOC_DAPM_DIR_REVERSE(x) ((x == SND_SOC_DAPM_DIR_IN) ? \ |
| 46 | SND_SOC_DAPM_DIR_OUT : SND_SOC_DAPM_DIR_IN) |
| 47 | |
| 48 | #define snd_soc_dapm_for_each_direction(dir) \ |
| 49 | for ((dir) = SND_SOC_DAPM_DIR_IN; (dir) <= SND_SOC_DAPM_DIR_OUT; \ |
| 50 | (dir)++) |
| 51 | |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 52 | static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm, |
| 53 | struct snd_soc_dapm_widget *wsource, struct snd_soc_dapm_widget *wsink, |
| 54 | const char *control, |
| 55 | int (*connected)(struct snd_soc_dapm_widget *source, |
| 56 | struct snd_soc_dapm_widget *sink)); |
Vladimir Zapolskiy | 5353f65 | 2015-06-02 00:57:53 +0300 | [diff] [blame] | 57 | |
Liam Girdwood | cc76e7d | 2015-06-04 15:13:09 +0100 | [diff] [blame] | 58 | struct snd_soc_dapm_widget * |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 59 | snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, |
| 60 | const struct snd_soc_dapm_widget *widget); |
| 61 | |
Liam Girdwood | 02aa78a | 2015-05-25 18:21:17 +0100 | [diff] [blame] | 62 | struct snd_soc_dapm_widget * |
| 63 | snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 64 | const struct snd_soc_dapm_widget *widget); |
| 65 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 66 | /* dapm power sequences - make this per codec in the future */ |
| 67 | static int dapm_up_seq[] = { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 68 | [snd_soc_dapm_pre] = 0, |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 69 | [snd_soc_dapm_regulator_supply] = 1, |
Srinivas Kandagatla | 5b2d15b | 2018-03-10 02:37:27 +0000 | [diff] [blame] | 70 | [snd_soc_dapm_pinctrl] = 1, |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 71 | [snd_soc_dapm_clock_supply] = 1, |
Mark Brown | 1dd275b | 2013-10-09 13:56:37 +0100 | [diff] [blame] | 72 | [snd_soc_dapm_supply] = 2, |
| 73 | [snd_soc_dapm_micbias] = 3, |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 74 | [snd_soc_dapm_dai_link] = 2, |
Mark Brown | 1dd275b | 2013-10-09 13:56:37 +0100 | [diff] [blame] | 75 | [snd_soc_dapm_dai_in] = 4, |
| 76 | [snd_soc_dapm_dai_out] = 4, |
| 77 | [snd_soc_dapm_aif_in] = 4, |
| 78 | [snd_soc_dapm_aif_out] = 4, |
| 79 | [snd_soc_dapm_mic] = 5, |
| 80 | [snd_soc_dapm_mux] = 6, |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 81 | [snd_soc_dapm_demux] = 6, |
Mark Brown | 1dd275b | 2013-10-09 13:56:37 +0100 | [diff] [blame] | 82 | [snd_soc_dapm_dac] = 7, |
| 83 | [snd_soc_dapm_switch] = 8, |
| 84 | [snd_soc_dapm_mixer] = 8, |
| 85 | [snd_soc_dapm_mixer_named_ctl] = 8, |
| 86 | [snd_soc_dapm_pga] = 9, |
| 87 | [snd_soc_dapm_adc] = 10, |
| 88 | [snd_soc_dapm_out_drv] = 11, |
| 89 | [snd_soc_dapm_hp] = 11, |
| 90 | [snd_soc_dapm_spk] = 11, |
| 91 | [snd_soc_dapm_line] = 11, |
| 92 | [snd_soc_dapm_kcontrol] = 12, |
| 93 | [snd_soc_dapm_post] = 13, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 94 | }; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 95 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 96 | static int dapm_down_seq[] = { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 97 | [snd_soc_dapm_pre] = 0, |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 98 | [snd_soc_dapm_kcontrol] = 1, |
| 99 | [snd_soc_dapm_adc] = 2, |
| 100 | [snd_soc_dapm_hp] = 3, |
| 101 | [snd_soc_dapm_spk] = 3, |
| 102 | [snd_soc_dapm_line] = 3, |
| 103 | [snd_soc_dapm_out_drv] = 3, |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 104 | [snd_soc_dapm_pga] = 4, |
Lars-Peter Clausen | efc77e3 | 2013-06-14 13:16:50 +0200 | [diff] [blame] | 105 | [snd_soc_dapm_switch] = 5, |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 106 | [snd_soc_dapm_mixer_named_ctl] = 5, |
Mark Brown | e3d4dab | 2009-06-07 13:08:45 +0100 | [diff] [blame] | 107 | [snd_soc_dapm_mixer] = 5, |
| 108 | [snd_soc_dapm_dac] = 6, |
| 109 | [snd_soc_dapm_mic] = 7, |
| 110 | [snd_soc_dapm_micbias] = 8, |
| 111 | [snd_soc_dapm_mux] = 9, |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 112 | [snd_soc_dapm_demux] = 9, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 113 | [snd_soc_dapm_aif_in] = 10, |
| 114 | [snd_soc_dapm_aif_out] = 10, |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 115 | [snd_soc_dapm_dai_in] = 10, |
| 116 | [snd_soc_dapm_dai_out] = 10, |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 117 | [snd_soc_dapm_dai_link] = 11, |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 118 | [snd_soc_dapm_supply] = 12, |
Mark Brown | 1dd275b | 2013-10-09 13:56:37 +0100 | [diff] [blame] | 119 | [snd_soc_dapm_clock_supply] = 13, |
Srinivas Kandagatla | 5b2d15b | 2018-03-10 02:37:27 +0000 | [diff] [blame] | 120 | [snd_soc_dapm_pinctrl] = 13, |
Mark Brown | 1dd275b | 2013-10-09 13:56:37 +0100 | [diff] [blame] | 121 | [snd_soc_dapm_regulator_supply] = 13, |
| 122 | [snd_soc_dapm_post] = 14, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 123 | }; |
| 124 | |
Mark Brown | f9fa2b1 | 2014-03-06 16:49:11 +0800 | [diff] [blame] | 125 | static void dapm_assert_locked(struct snd_soc_dapm_context *dapm) |
| 126 | { |
| 127 | if (dapm->card && dapm->card->instantiated) |
| 128 | lockdep_assert_held(&dapm->card->dapm_mutex); |
| 129 | } |
| 130 | |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 131 | static void pop_wait(u32 pop_time) |
Mark Brown | 15e4c72f | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 132 | { |
| 133 | if (pop_time) |
| 134 | schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time)); |
| 135 | } |
| 136 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 137 | static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...) |
Mark Brown | 15e4c72f | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 138 | { |
| 139 | va_list args; |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 140 | char *buf; |
| 141 | |
| 142 | if (!pop_time) |
| 143 | return; |
| 144 | |
| 145 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 146 | if (buf == NULL) |
| 147 | return; |
Mark Brown | 15e4c72f | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 148 | |
| 149 | va_start(args, fmt); |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 150 | vsnprintf(buf, PAGE_SIZE, fmt, args); |
Takashi Iwai | 9d01df0 | 2010-12-22 14:08:40 +0100 | [diff] [blame] | 151 | dev_info(dev, "%s", buf); |
Mark Brown | 15e4c72f | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 152 | va_end(args); |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 153 | |
| 154 | kfree(buf); |
Mark Brown | 15e4c72f | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 155 | } |
| 156 | |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 157 | static bool dapm_dirty_widget(struct snd_soc_dapm_widget *w) |
| 158 | { |
| 159 | return !list_empty(&w->dirty); |
| 160 | } |
| 161 | |
Mark Brown | 492c0a1 | 2014-03-06 16:15:48 +0800 | [diff] [blame] | 162 | static void dapm_mark_dirty(struct snd_soc_dapm_widget *w, const char *reason) |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 163 | { |
Mark Brown | f9fa2b1 | 2014-03-06 16:49:11 +0800 | [diff] [blame] | 164 | dapm_assert_locked(w->dapm); |
| 165 | |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 166 | if (!dapm_dirty_widget(w)) { |
| 167 | dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n", |
| 168 | w->name, reason); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 169 | list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty); |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 170 | } |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 171 | } |
| 172 | |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 173 | /* |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 174 | * Common implementation for dapm_widget_invalidate_input_paths() and |
| 175 | * dapm_widget_invalidate_output_paths(). The function is inlined since the |
| 176 | * combined size of the two specialized functions is only marginally larger then |
| 177 | * the size of the generic function and at the same time the fast path of the |
| 178 | * specialized functions is significantly smaller than the generic function. |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 179 | */ |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 180 | static __always_inline void dapm_widget_invalidate_paths( |
| 181 | struct snd_soc_dapm_widget *w, enum snd_soc_dapm_direction dir) |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 182 | { |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 183 | enum snd_soc_dapm_direction rdir = SND_SOC_DAPM_DIR_REVERSE(dir); |
| 184 | struct snd_soc_dapm_widget *node; |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 185 | struct snd_soc_dapm_path *p; |
| 186 | LIST_HEAD(list); |
| 187 | |
| 188 | dapm_assert_locked(w->dapm); |
| 189 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 190 | if (w->endpoints[dir] == -1) |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 191 | return; |
| 192 | |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 193 | list_add_tail(&w->work_list, &list); |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 194 | w->endpoints[dir] = -1; |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 195 | |
| 196 | list_for_each_entry(w, &list, work_list) { |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 197 | snd_soc_dapm_widget_for_each_path(w, dir, p) { |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 198 | if (p->is_supply || p->weak || !p->connect) |
| 199 | continue; |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 200 | node = p->node[rdir]; |
| 201 | if (node->endpoints[dir] != -1) { |
| 202 | node->endpoints[dir] = -1; |
| 203 | list_add_tail(&node->work_list, &list); |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | /* |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 210 | * dapm_widget_invalidate_input_paths() - Invalidate the cached number of |
| 211 | * input paths |
| 212 | * @w: The widget for which to invalidate the cached number of input paths |
| 213 | * |
| 214 | * Resets the cached number of inputs for the specified widget and all widgets |
| 215 | * that can be reached via outcoming paths from the widget. |
| 216 | * |
| 217 | * This function must be called if the number of output paths for a widget might |
| 218 | * have changed. E.g. if the source state of a widget changes or a path is added |
| 219 | * or activated with the widget as the sink. |
| 220 | */ |
| 221 | static void dapm_widget_invalidate_input_paths(struct snd_soc_dapm_widget *w) |
| 222 | { |
| 223 | dapm_widget_invalidate_paths(w, SND_SOC_DAPM_DIR_IN); |
| 224 | } |
| 225 | |
| 226 | /* |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 227 | * dapm_widget_invalidate_output_paths() - Invalidate the cached number of |
| 228 | * output paths |
| 229 | * @w: The widget for which to invalidate the cached number of output paths |
| 230 | * |
| 231 | * Resets the cached number of outputs for the specified widget and all widgets |
| 232 | * that can be reached via incoming paths from the widget. |
| 233 | * |
| 234 | * This function must be called if the number of output paths for a widget might |
| 235 | * have changed. E.g. if the sink state of a widget changes or a path is added |
| 236 | * or activated with the widget as the source. |
| 237 | */ |
| 238 | static void dapm_widget_invalidate_output_paths(struct snd_soc_dapm_widget *w) |
| 239 | { |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 240 | dapm_widget_invalidate_paths(w, SND_SOC_DAPM_DIR_OUT); |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | /* |
| 244 | * dapm_path_invalidate() - Invalidates the cached number of inputs and outputs |
| 245 | * for the widgets connected to a path |
| 246 | * @p: The path to invalidate |
| 247 | * |
| 248 | * Resets the cached number of inputs for the sink of the path and the cached |
| 249 | * number of outputs for the source of the path. |
| 250 | * |
| 251 | * This function must be called when a path is added, removed or the connected |
| 252 | * state changes. |
| 253 | */ |
| 254 | static void dapm_path_invalidate(struct snd_soc_dapm_path *p) |
| 255 | { |
| 256 | /* |
| 257 | * Weak paths or supply paths do not influence the number of input or |
| 258 | * output paths of their neighbors. |
| 259 | */ |
| 260 | if (p->weak || p->is_supply) |
| 261 | return; |
| 262 | |
| 263 | /* |
| 264 | * The number of connected endpoints is the sum of the number of |
| 265 | * connected endpoints of all neighbors. If a node with 0 connected |
| 266 | * endpoints is either connected or disconnected that sum won't change, |
| 267 | * so there is no need to re-check the path. |
| 268 | */ |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 269 | if (p->source->endpoints[SND_SOC_DAPM_DIR_IN] != 0) |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 270 | dapm_widget_invalidate_input_paths(p->sink); |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 271 | if (p->sink->endpoints[SND_SOC_DAPM_DIR_OUT] != 0) |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 272 | dapm_widget_invalidate_output_paths(p->source); |
| 273 | } |
| 274 | |
Lars-Peter Clausen | 8be4da2 | 2014-10-25 17:42:01 +0200 | [diff] [blame] | 275 | void dapm_mark_endpoints_dirty(struct snd_soc_card *card) |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 276 | { |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 277 | struct snd_soc_dapm_widget *w; |
| 278 | |
| 279 | mutex_lock(&card->dapm_mutex); |
| 280 | |
| 281 | list_for_each_entry(w, &card->widgets, list) { |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 282 | if (w->is_ep) { |
Lars-Peter Clausen | 8be4da2 | 2014-10-25 17:42:01 +0200 | [diff] [blame] | 283 | dapm_mark_dirty(w, "Rechecking endpoints"); |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 284 | if (w->is_ep & SND_SOC_DAPM_EP_SINK) |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 285 | dapm_widget_invalidate_output_paths(w); |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 286 | if (w->is_ep & SND_SOC_DAPM_EP_SOURCE) |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 287 | dapm_widget_invalidate_input_paths(w); |
| 288 | } |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | mutex_unlock(&card->dapm_mutex); |
| 292 | } |
Lars-Peter Clausen | 8be4da2 | 2014-10-25 17:42:01 +0200 | [diff] [blame] | 293 | EXPORT_SYMBOL_GPL(dapm_mark_endpoints_dirty); |
Mark Brown | e2d32ff | 2012-08-31 17:38:32 -0700 | [diff] [blame] | 294 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 295 | /* create a new dapm widget */ |
Takashi Iwai | 88cb429 | 2007-02-05 14:56:20 +0100 | [diff] [blame] | 296 | static inline struct snd_soc_dapm_widget *dapm_cnew_widget( |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 297 | const struct snd_soc_dapm_widget *_widget) |
| 298 | { |
Takashi Iwai | 88cb429 | 2007-02-05 14:56:20 +0100 | [diff] [blame] | 299 | return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 300 | } |
| 301 | |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 302 | struct dapm_kcontrol_data { |
Lars-Peter Clausen | cf7c1de | 2013-07-29 17:13:59 +0200 | [diff] [blame] | 303 | unsigned int value; |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 304 | struct snd_soc_dapm_widget *widget; |
Lars-Peter Clausen | 5106b92 | 2013-07-29 17:14:00 +0200 | [diff] [blame] | 305 | struct list_head paths; |
Lars-Peter Clausen | 2c75bdf | 2013-08-01 14:08:07 +0200 | [diff] [blame] | 306 | struct snd_soc_dapm_widget_list *wlist; |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 307 | }; |
| 308 | |
| 309 | static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget, |
Lars-Peter Clausen | 41d8002 | 2016-02-03 21:59:50 +0100 | [diff] [blame] | 310 | struct snd_kcontrol *kcontrol, const char *ctrl_name) |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 311 | { |
| 312 | struct dapm_kcontrol_data *data; |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 313 | struct soc_mixer_control *mc; |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 314 | struct soc_enum *e; |
Charles Keepax | 773da9b | 2015-05-01 12:37:25 +0100 | [diff] [blame] | 315 | const char *name; |
| 316 | int ret; |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 317 | |
Lars-Peter Clausen | 2c75bdf | 2013-08-01 14:08:07 +0200 | [diff] [blame] | 318 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
Charles Keepax | 40b7bea | 2015-05-01 12:37:24 +0100 | [diff] [blame] | 319 | if (!data) |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 320 | return -ENOMEM; |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 321 | |
Lars-Peter Clausen | 5106b92 | 2013-07-29 17:14:00 +0200 | [diff] [blame] | 322 | INIT_LIST_HEAD(&data->paths); |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 323 | |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 324 | switch (widget->id) { |
| 325 | case snd_soc_dapm_switch: |
| 326 | case snd_soc_dapm_mixer: |
| 327 | case snd_soc_dapm_mixer_named_ctl: |
| 328 | mc = (struct soc_mixer_control *)kcontrol->private_value; |
| 329 | |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 330 | if (mc->autodisable && snd_soc_volsw_is_stereo(mc)) |
| 331 | dev_warn(widget->dapm->dev, |
| 332 | "ASoC: Unsupported stereo autodisable control '%s'\n", |
| 333 | ctrl_name); |
| 334 | |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 335 | if (mc->autodisable) { |
| 336 | struct snd_soc_dapm_widget template; |
| 337 | |
Lars-Peter Clausen | 41d8002 | 2016-02-03 21:59:50 +0100 | [diff] [blame] | 338 | name = kasprintf(GFP_KERNEL, "%s %s", ctrl_name, |
Charles Keepax | 773da9b | 2015-05-01 12:37:25 +0100 | [diff] [blame] | 339 | "Autodisable"); |
| 340 | if (!name) { |
| 341 | ret = -ENOMEM; |
| 342 | goto err_data; |
| 343 | } |
| 344 | |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 345 | memset(&template, 0, sizeof(template)); |
| 346 | template.reg = mc->reg; |
| 347 | template.mask = (1 << fls(mc->max)) - 1; |
| 348 | template.shift = mc->shift; |
| 349 | if (mc->invert) |
| 350 | template.off_val = mc->max; |
| 351 | else |
| 352 | template.off_val = 0; |
| 353 | template.on_val = template.off_val; |
| 354 | template.id = snd_soc_dapm_kcontrol; |
Charles Keepax | 773da9b | 2015-05-01 12:37:25 +0100 | [diff] [blame] | 355 | template.name = name; |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 356 | |
Lars-Peter Clausen | 2daabd7 | 2013-08-30 17:39:33 +0200 | [diff] [blame] | 357 | data->value = template.on_val; |
| 358 | |
Liam Girdwood | 02aa78a | 2015-05-25 18:21:17 +0100 | [diff] [blame] | 359 | data->widget = |
| 360 | snd_soc_dapm_new_control_unlocked(widget->dapm, |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 361 | &template); |
Lars-Peter Clausen | e18077b | 2015-07-08 21:59:59 +0200 | [diff] [blame] | 362 | kfree(name); |
Linus Walleij | 37e1df8 | 2017-01-13 10:23:52 +0100 | [diff] [blame] | 363 | if (IS_ERR(data->widget)) { |
| 364 | ret = PTR_ERR(data->widget); |
| 365 | goto err_data; |
| 366 | } |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 367 | } |
| 368 | break; |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 369 | case snd_soc_dapm_demux: |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 370 | case snd_soc_dapm_mux: |
| 371 | e = (struct soc_enum *)kcontrol->private_value; |
| 372 | |
| 373 | if (e->autodisable) { |
| 374 | struct snd_soc_dapm_widget template; |
| 375 | |
Lars-Peter Clausen | 41d8002 | 2016-02-03 21:59:50 +0100 | [diff] [blame] | 376 | name = kasprintf(GFP_KERNEL, "%s %s", ctrl_name, |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 377 | "Autodisable"); |
| 378 | if (!name) { |
| 379 | ret = -ENOMEM; |
| 380 | goto err_data; |
| 381 | } |
| 382 | |
| 383 | memset(&template, 0, sizeof(template)); |
| 384 | template.reg = e->reg; |
| 385 | template.mask = e->mask << e->shift_l; |
| 386 | template.shift = e->shift_l; |
| 387 | template.off_val = snd_soc_enum_item_to_val(e, 0); |
| 388 | template.on_val = template.off_val; |
| 389 | template.id = snd_soc_dapm_kcontrol; |
| 390 | template.name = name; |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 391 | |
| 392 | data->value = template.on_val; |
| 393 | |
Charles Keepax | ffacb48 | 2015-06-26 10:39:43 +0100 | [diff] [blame] | 394 | data->widget = snd_soc_dapm_new_control_unlocked( |
| 395 | widget->dapm, &template); |
Lars-Peter Clausen | e18077b | 2015-07-08 21:59:59 +0200 | [diff] [blame] | 396 | kfree(name); |
Linus Walleij | 37e1df8 | 2017-01-13 10:23:52 +0100 | [diff] [blame] | 397 | if (IS_ERR(data->widget)) { |
| 398 | ret = PTR_ERR(data->widget); |
| 399 | goto err_data; |
| 400 | } |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 401 | |
| 402 | snd_soc_dapm_add_path(widget->dapm, data->widget, |
| 403 | widget, NULL, NULL); |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 404 | } |
| 405 | break; |
| 406 | default: |
| 407 | break; |
| 408 | } |
| 409 | |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 410 | kcontrol->private_data = data; |
| 411 | |
| 412 | return 0; |
Charles Keepax | 773da9b | 2015-05-01 12:37:25 +0100 | [diff] [blame] | 413 | |
Charles Keepax | 773da9b | 2015-05-01 12:37:25 +0100 | [diff] [blame] | 414 | err_data: |
| 415 | kfree(data); |
| 416 | return ret; |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static void dapm_kcontrol_free(struct snd_kcontrol *kctl) |
| 420 | { |
| 421 | struct dapm_kcontrol_data *data = snd_kcontrol_chip(kctl); |
Srinivas Kandagatla | ff2faf1 | 2018-06-04 12:13:26 +0100 | [diff] [blame] | 422 | |
| 423 | list_del(&data->paths); |
Lars-Peter Clausen | 2c75bdf | 2013-08-01 14:08:07 +0200 | [diff] [blame] | 424 | kfree(data->wlist); |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 425 | kfree(data); |
| 426 | } |
| 427 | |
| 428 | static struct snd_soc_dapm_widget_list *dapm_kcontrol_get_wlist( |
| 429 | const struct snd_kcontrol *kcontrol) |
| 430 | { |
| 431 | struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol); |
| 432 | |
Lars-Peter Clausen | 2c75bdf | 2013-08-01 14:08:07 +0200 | [diff] [blame] | 433 | return data->wlist; |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | static int dapm_kcontrol_add_widget(struct snd_kcontrol *kcontrol, |
| 437 | struct snd_soc_dapm_widget *widget) |
| 438 | { |
| 439 | struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol); |
Lars-Peter Clausen | 2c75bdf | 2013-08-01 14:08:07 +0200 | [diff] [blame] | 440 | struct snd_soc_dapm_widget_list *new_wlist; |
| 441 | unsigned int n; |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 442 | |
Lars-Peter Clausen | 2c75bdf | 2013-08-01 14:08:07 +0200 | [diff] [blame] | 443 | if (data->wlist) |
| 444 | n = data->wlist->num_widgets + 1; |
| 445 | else |
| 446 | n = 1; |
| 447 | |
| 448 | new_wlist = krealloc(data->wlist, |
| 449 | sizeof(*new_wlist) + sizeof(widget) * n, GFP_KERNEL); |
| 450 | if (!new_wlist) |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 451 | return -ENOMEM; |
| 452 | |
Lars-Peter Clausen | 2c75bdf | 2013-08-01 14:08:07 +0200 | [diff] [blame] | 453 | new_wlist->widgets[n - 1] = widget; |
| 454 | new_wlist->num_widgets = n; |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 455 | |
Lars-Peter Clausen | 2c75bdf | 2013-08-01 14:08:07 +0200 | [diff] [blame] | 456 | data->wlist = new_wlist; |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
Lars-Peter Clausen | 5106b92 | 2013-07-29 17:14:00 +0200 | [diff] [blame] | 461 | static void dapm_kcontrol_add_path(const struct snd_kcontrol *kcontrol, |
| 462 | struct snd_soc_dapm_path *path) |
| 463 | { |
| 464 | struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol); |
| 465 | |
| 466 | list_add_tail(&path->list_kcontrol, &data->paths); |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | static bool dapm_kcontrol_is_powered(const struct snd_kcontrol *kcontrol) |
| 470 | { |
| 471 | struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol); |
| 472 | |
| 473 | if (!data->widget) |
| 474 | return true; |
| 475 | |
| 476 | return data->widget->power; |
Lars-Peter Clausen | 5106b92 | 2013-07-29 17:14:00 +0200 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | static struct list_head *dapm_kcontrol_get_path_list( |
| 480 | const struct snd_kcontrol *kcontrol) |
| 481 | { |
| 482 | struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol); |
| 483 | |
| 484 | return &data->paths; |
| 485 | } |
| 486 | |
| 487 | #define dapm_kcontrol_for_each_path(path, kcontrol) \ |
| 488 | list_for_each_entry(path, dapm_kcontrol_get_path_list(kcontrol), \ |
| 489 | list_kcontrol) |
| 490 | |
Subhransu S. Prusty | 5dc0158a | 2014-09-19 16:46:05 +0530 | [diff] [blame] | 491 | unsigned int dapm_kcontrol_get_value(const struct snd_kcontrol *kcontrol) |
Lars-Peter Clausen | cf7c1de | 2013-07-29 17:13:59 +0200 | [diff] [blame] | 492 | { |
| 493 | struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol); |
| 494 | |
| 495 | return data->value; |
| 496 | } |
Subhransu S. Prusty | 5dc0158a | 2014-09-19 16:46:05 +0530 | [diff] [blame] | 497 | EXPORT_SYMBOL_GPL(dapm_kcontrol_get_value); |
Lars-Peter Clausen | cf7c1de | 2013-07-29 17:13:59 +0200 | [diff] [blame] | 498 | |
| 499 | static bool dapm_kcontrol_set_value(const struct snd_kcontrol *kcontrol, |
| 500 | unsigned int value) |
| 501 | { |
| 502 | struct dapm_kcontrol_data *data = snd_kcontrol_chip(kcontrol); |
| 503 | |
| 504 | if (data->value == value) |
| 505 | return false; |
| 506 | |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 507 | if (data->widget) |
| 508 | data->widget->on_val = value; |
| 509 | |
Lars-Peter Clausen | cf7c1de | 2013-07-29 17:13:59 +0200 | [diff] [blame] | 510 | data->value = value; |
| 511 | |
| 512 | return true; |
| 513 | } |
| 514 | |
Lars-Peter Clausen | eee5d7f | 2013-07-29 17:13:57 +0200 | [diff] [blame] | 515 | /** |
Mythri P K | 93e39a1 | 2015-10-20 22:30:08 +0530 | [diff] [blame] | 516 | * snd_soc_dapm_kcontrol_widget() - Returns the widget associated to a |
| 517 | * kcontrol |
| 518 | * @kcontrol: The kcontrol |
| 519 | */ |
| 520 | struct snd_soc_dapm_widget *snd_soc_dapm_kcontrol_widget( |
| 521 | struct snd_kcontrol *kcontrol) |
| 522 | { |
| 523 | return dapm_kcontrol_get_wlist(kcontrol)->widgets[0]; |
| 524 | } |
| 525 | EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_widget); |
| 526 | |
| 527 | /** |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 528 | * snd_soc_dapm_kcontrol_dapm() - Returns the dapm context associated to a |
| 529 | * kcontrol |
| 530 | * @kcontrol: The kcontrol |
| 531 | * |
| 532 | * Note: This function must only be used on kcontrols that are known to have |
| 533 | * been registered for a CODEC. Otherwise the behaviour is undefined. |
| 534 | */ |
| 535 | struct snd_soc_dapm_context *snd_soc_dapm_kcontrol_dapm( |
| 536 | struct snd_kcontrol *kcontrol) |
| 537 | { |
| 538 | return dapm_kcontrol_get_wlist(kcontrol)->widgets[0]->dapm; |
| 539 | } |
| 540 | EXPORT_SYMBOL_GPL(snd_soc_dapm_kcontrol_dapm); |
| 541 | |
Liam Girdwood | 6c120e1 | 2012-02-15 15:15:34 +0000 | [diff] [blame] | 542 | static void dapm_reset(struct snd_soc_card *card) |
| 543 | { |
| 544 | struct snd_soc_dapm_widget *w; |
| 545 | |
Mark Brown | f9fa2b1 | 2014-03-06 16:49:11 +0800 | [diff] [blame] | 546 | lockdep_assert_held(&card->dapm_mutex); |
| 547 | |
Liam Girdwood | 6c120e1 | 2012-02-15 15:15:34 +0000 | [diff] [blame] | 548 | memset(&card->dapm_stats, 0, sizeof(card->dapm_stats)); |
| 549 | |
| 550 | list_for_each_entry(w, &card->widgets, list) { |
Lars-Peter Clausen | 39eb5fd | 2013-07-29 17:14:03 +0200 | [diff] [blame] | 551 | w->new_power = w->power; |
Liam Girdwood | 6c120e1 | 2012-02-15 15:15:34 +0000 | [diff] [blame] | 552 | w->power_checked = false; |
Liam Girdwood | 6c120e1 | 2012-02-15 15:15:34 +0000 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 556 | static const char *soc_dapm_prefix(struct snd_soc_dapm_context *dapm) |
| 557 | { |
| 558 | if (!dapm->component) |
| 559 | return NULL; |
| 560 | return dapm->component->name_prefix; |
| 561 | } |
| 562 | |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 563 | static int soc_dapm_read(struct snd_soc_dapm_context *dapm, int reg, |
Arun Shamanna Lakshmi | f7d3c17 | 2014-01-14 15:31:54 -0800 | [diff] [blame] | 564 | unsigned int *value) |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 565 | { |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 566 | if (!dapm->component) |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 567 | return -EIO; |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 568 | return snd_soc_component_read(dapm->component, reg, value); |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 569 | } |
| 570 | |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 571 | static int soc_dapm_update_bits(struct snd_soc_dapm_context *dapm, |
Bard Liao | 3477501 | 2014-04-17 20:12:56 +0800 | [diff] [blame] | 572 | int reg, unsigned int mask, unsigned int value) |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 573 | { |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 574 | if (!dapm->component) |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 575 | return -EIO; |
Mark Brown | fcf6c5e | 2014-12-15 13:08:48 +0000 | [diff] [blame] | 576 | return snd_soc_component_update_bits(dapm->component, reg, |
| 577 | mask, value); |
Liam Girdwood | 49575fb5 | 2012-03-06 18:16:19 +0000 | [diff] [blame] | 578 | } |
| 579 | |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 580 | static int soc_dapm_test_bits(struct snd_soc_dapm_context *dapm, |
| 581 | int reg, unsigned int mask, unsigned int value) |
| 582 | { |
| 583 | if (!dapm->component) |
| 584 | return -EIO; |
| 585 | return snd_soc_component_test_bits(dapm->component, reg, mask, value); |
| 586 | } |
| 587 | |
Mark Brown | eb270e9 | 2013-10-09 13:52:52 +0100 | [diff] [blame] | 588 | static void soc_dapm_async_complete(struct snd_soc_dapm_context *dapm) |
| 589 | { |
Lars-Peter Clausen | e2c330b | 2014-04-22 13:23:13 +0200 | [diff] [blame] | 590 | if (dapm->component) |
| 591 | snd_soc_component_async_complete(dapm->component); |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 592 | } |
| 593 | |
Charles Keepax | 45a110a | 2015-05-11 13:50:30 +0100 | [diff] [blame] | 594 | static struct snd_soc_dapm_widget * |
| 595 | dapm_wcache_lookup(struct snd_soc_dapm_wcache *wcache, const char *name) |
| 596 | { |
| 597 | struct snd_soc_dapm_widget *w = wcache->widget; |
| 598 | struct list_head *wlist; |
| 599 | const int depth = 2; |
| 600 | int i = 0; |
| 601 | |
| 602 | if (w) { |
| 603 | wlist = &w->dapm->card->widgets; |
| 604 | |
| 605 | list_for_each_entry_from(w, wlist, list) { |
| 606 | if (!strcmp(name, w->name)) |
| 607 | return w; |
| 608 | |
| 609 | if (++i == depth) |
| 610 | break; |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | return NULL; |
| 615 | } |
| 616 | |
| 617 | static inline void dapm_wcache_update(struct snd_soc_dapm_wcache *wcache, |
| 618 | struct snd_soc_dapm_widget *w) |
| 619 | { |
| 620 | wcache->widget = w; |
| 621 | } |
| 622 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 623 | /** |
Lars-Peter Clausen | fa88077 | 2015-04-27 22:13:23 +0200 | [diff] [blame] | 624 | * snd_soc_dapm_force_bias_level() - Sets the DAPM bias level |
| 625 | * @dapm: The DAPM context for which to set the level |
| 626 | * @level: The level to set |
| 627 | * |
| 628 | * Forces the DAPM bias level to a specific state. It will call the bias level |
| 629 | * callback of DAPM context with the specified level. This will even happen if |
| 630 | * the context is already at the same level. Furthermore it will not go through |
| 631 | * the normal bias level sequencing, meaning any intermediate states between the |
| 632 | * current and the target state will not be entered. |
| 633 | * |
| 634 | * Note that the change in bias level is only temporary and the next time |
| 635 | * snd_soc_dapm_sync() is called the state will be set to the level as |
| 636 | * determined by the DAPM core. The function is mainly intended to be used to |
| 637 | * used during probe or resume from suspend to power up the device so |
| 638 | * initialization can be done, before the DAPM core takes over. |
| 639 | */ |
| 640 | int snd_soc_dapm_force_bias_level(struct snd_soc_dapm_context *dapm, |
| 641 | enum snd_soc_bias_level level) |
| 642 | { |
| 643 | int ret = 0; |
| 644 | |
| 645 | if (dapm->set_bias_level) |
| 646 | ret = dapm->set_bias_level(dapm, level); |
| 647 | |
Lars-Peter Clausen | f4bf8d7 | 2015-04-27 22:13:25 +0200 | [diff] [blame] | 648 | if (ret == 0) |
| 649 | dapm->bias_level = level; |
| 650 | |
Lars-Peter Clausen | fa88077 | 2015-04-27 22:13:23 +0200 | [diff] [blame] | 651 | return ret; |
| 652 | } |
| 653 | EXPORT_SYMBOL_GPL(snd_soc_dapm_force_bias_level); |
| 654 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 655 | /** |
| 656 | * snd_soc_dapm_set_bias_level - set the bias level for the system |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 657 | * @dapm: DAPM context |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 658 | * @level: level to configure |
| 659 | * |
| 660 | * Configure the bias (power) levels for the SoC audio device. |
| 661 | * |
| 662 | * Returns 0 for success else error. |
| 663 | */ |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 664 | static int snd_soc_dapm_set_bias_level(struct snd_soc_dapm_context *dapm, |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 665 | enum snd_soc_bias_level level) |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 666 | { |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 667 | struct snd_soc_card *card = dapm->card; |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 668 | int ret = 0; |
| 669 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 670 | trace_snd_soc_bias_level_start(card, level); |
| 671 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 672 | if (card && card->set_bias_level) |
Mark Brown | d4c6005 | 2011-06-06 19:13:23 +0100 | [diff] [blame] | 673 | ret = card->set_bias_level(card, dapm, level); |
Mark Brown | 171ec6b | 2011-06-06 18:15:19 +0100 | [diff] [blame] | 674 | if (ret != 0) |
| 675 | goto out; |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 676 | |
Lars-Peter Clausen | fa88077 | 2015-04-27 22:13:23 +0200 | [diff] [blame] | 677 | if (!card || dapm != &card->dapm) |
| 678 | ret = snd_soc_dapm_force_bias_level(dapm, level); |
Liam Girdwood | 4123128 | 2012-07-06 16:56:16 +0100 | [diff] [blame] | 679 | |
Mark Brown | 171ec6b | 2011-06-06 18:15:19 +0100 | [diff] [blame] | 680 | if (ret != 0) |
| 681 | goto out; |
| 682 | |
| 683 | if (card && card->set_bias_level_post) |
Mark Brown | d4c6005 | 2011-06-06 19:13:23 +0100 | [diff] [blame] | 684 | ret = card->set_bias_level_post(card, dapm, level); |
Mark Brown | 171ec6b | 2011-06-06 18:15:19 +0100 | [diff] [blame] | 685 | out: |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 686 | trace_snd_soc_bias_level_done(card, level); |
| 687 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 688 | return ret; |
| 689 | } |
| 690 | |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 691 | /* connect mux widget to its interconnecting audio paths */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 692 | static int dapm_connect_mux(struct snd_soc_dapm_context *dapm, |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 693 | struct snd_soc_dapm_path *path, const char *control_name, |
| 694 | struct snd_soc_dapm_widget *w) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 695 | { |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 696 | const struct snd_kcontrol_new *kcontrol = &w->kcontrol_news[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 697 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Lars-Peter Clausen | 234c0b8 | 2014-02-28 08:31:12 +0100 | [diff] [blame] | 698 | unsigned int val, item; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 699 | int i; |
| 700 | |
Lars-Peter Clausen | 234c0b8 | 2014-02-28 08:31:12 +0100 | [diff] [blame] | 701 | if (e->reg != SND_SOC_NOPM) { |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 702 | soc_dapm_read(dapm, e->reg, &val); |
Lars-Peter Clausen | 234c0b8 | 2014-02-28 08:31:12 +0100 | [diff] [blame] | 703 | val = (val >> e->shift_l) & e->mask; |
| 704 | item = snd_soc_enum_val_to_item(e, val); |
| 705 | } else { |
| 706 | /* since a virtual mux has no backing registers to |
| 707 | * decide which path to connect, it will try to match |
| 708 | * with the first enumeration. This is to ensure |
| 709 | * that the default mux choice (the first) will be |
| 710 | * correctly powered up during initialization. |
| 711 | */ |
| 712 | item = 0; |
| 713 | } |
| 714 | |
Xie Yisheng | f9e0b4a | 2018-05-31 19:11:23 +0800 | [diff] [blame] | 715 | i = match_string(e->texts, e->items, control_name); |
| 716 | if (i < 0) |
| 717 | return -ENODEV; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 718 | |
Xie Yisheng | f9e0b4a | 2018-05-31 19:11:23 +0800 | [diff] [blame] | 719 | path->name = e->texts[i]; |
| 720 | path->connect = (i == item); |
| 721 | return 0; |
| 722 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 723 | } |
| 724 | |
Lars-Peter Clausen | 234c0b8 | 2014-02-28 08:31:12 +0100 | [diff] [blame] | 725 | /* set up initial codec paths */ |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 726 | static void dapm_set_mixer_path_status(struct snd_soc_dapm_path *p, int i, |
| 727 | int nth_path) |
Lars-Peter Clausen | 234c0b8 | 2014-02-28 08:31:12 +0100 | [diff] [blame] | 728 | { |
| 729 | struct soc_mixer_control *mc = (struct soc_mixer_control *) |
Lars-Peter Clausen | 5fe5b76 | 2014-10-25 17:41:58 +0200 | [diff] [blame] | 730 | p->sink->kcontrol_news[i].private_value; |
Lars-Peter Clausen | 234c0b8 | 2014-02-28 08:31:12 +0100 | [diff] [blame] | 731 | unsigned int reg = mc->reg; |
| 732 | unsigned int shift = mc->shift; |
| 733 | unsigned int max = mc->max; |
| 734 | unsigned int mask = (1 << fls(max)) - 1; |
| 735 | unsigned int invert = mc->invert; |
| 736 | unsigned int val; |
| 737 | |
| 738 | if (reg != SND_SOC_NOPM) { |
Lars-Peter Clausen | 5fe5b76 | 2014-10-25 17:41:58 +0200 | [diff] [blame] | 739 | soc_dapm_read(p->sink->dapm, reg, &val); |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 740 | /* |
| 741 | * The nth_path argument allows this function to know |
| 742 | * which path of a kcontrol it is setting the initial |
| 743 | * status for. Ideally this would support any number |
| 744 | * of paths and channels. But since kcontrols only come |
| 745 | * in mono and stereo variants, we are limited to 2 |
| 746 | * channels. |
| 747 | * |
| 748 | * The following code assumes for stereo controls the |
| 749 | * first path is the left channel, and all remaining |
| 750 | * paths are the right channel. |
| 751 | */ |
| 752 | if (snd_soc_volsw_is_stereo(mc) && nth_path > 0) { |
| 753 | if (reg != mc->rreg) |
| 754 | soc_dapm_read(p->sink->dapm, mc->rreg, &val); |
| 755 | val = (val >> mc->rshift) & mask; |
| 756 | } else { |
| 757 | val = (val >> shift) & mask; |
| 758 | } |
Lars-Peter Clausen | 234c0b8 | 2014-02-28 08:31:12 +0100 | [diff] [blame] | 759 | if (invert) |
| 760 | val = max - val; |
| 761 | p->connect = !!val; |
| 762 | } else { |
| 763 | p->connect = 0; |
| 764 | } |
| 765 | } |
| 766 | |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 767 | /* connect mixer widget to its interconnecting audio paths */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 768 | static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 769 | struct snd_soc_dapm_path *path, const char *control_name) |
| 770 | { |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 771 | int i, nth_path = 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 772 | |
| 773 | /* search for mixer kcontrol */ |
Lars-Peter Clausen | 5fe5b76 | 2014-10-25 17:41:58 +0200 | [diff] [blame] | 774 | for (i = 0; i < path->sink->num_kcontrols; i++) { |
| 775 | if (!strcmp(control_name, path->sink->kcontrol_news[i].name)) { |
| 776 | path->name = path->sink->kcontrol_news[i].name; |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 777 | dapm_set_mixer_path_status(path, i, nth_path++); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 778 | return 0; |
| 779 | } |
| 780 | } |
| 781 | return -ENODEV; |
| 782 | } |
| 783 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 784 | static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm, |
Stephen Warren | 1007da0 | 2011-05-26 09:57:33 -0600 | [diff] [blame] | 785 | struct snd_soc_dapm_widget *kcontrolw, |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 786 | const struct snd_kcontrol_new *kcontrol_new, |
| 787 | struct snd_kcontrol **kcontrol) |
| 788 | { |
| 789 | struct snd_soc_dapm_widget *w; |
| 790 | int i; |
| 791 | |
| 792 | *kcontrol = NULL; |
| 793 | |
| 794 | list_for_each_entry(w, &dapm->card->widgets, list) { |
Stephen Warren | 1007da0 | 2011-05-26 09:57:33 -0600 | [diff] [blame] | 795 | if (w == kcontrolw || w->dapm != kcontrolw->dapm) |
| 796 | continue; |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 797 | for (i = 0; i < w->num_kcontrols; i++) { |
| 798 | if (&w->kcontrol_news[i] == kcontrol_new) { |
| 799 | if (w->kcontrols) |
| 800 | *kcontrol = w->kcontrols[i]; |
| 801 | return 1; |
| 802 | } |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 809 | /* |
| 810 | * Determine if a kcontrol is shared. If it is, look it up. If it isn't, |
| 811 | * create it. Either way, add the widget into the control's widget list |
| 812 | */ |
Jeeja KP | 19a2557b | 2015-10-20 22:30:06 +0530 | [diff] [blame] | 813 | static int dapm_create_or_share_kcontrol(struct snd_soc_dapm_widget *w, |
Mark Brown | 946d92a | 2013-08-12 23:28:42 +0100 | [diff] [blame] | 814 | int kci) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 815 | { |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 816 | struct snd_soc_dapm_context *dapm = w->dapm; |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 817 | struct snd_card *card = dapm->card->snd_card; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 818 | const char *prefix; |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 819 | size_t prefix_len; |
| 820 | int shared; |
| 821 | struct snd_kcontrol *kcontrol; |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 822 | bool wname_in_long_name, kcname_in_long_name; |
Daniel Mack | e5092c9 | 2014-10-07 13:41:24 +0200 | [diff] [blame] | 823 | char *long_name = NULL; |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 824 | const char *name; |
Daniel Mack | e5092c9 | 2014-10-07 13:41:24 +0200 | [diff] [blame] | 825 | int ret = 0; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 826 | |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 827 | prefix = soc_dapm_prefix(dapm); |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 828 | if (prefix) |
| 829 | prefix_len = strlen(prefix) + 1; |
| 830 | else |
| 831 | prefix_len = 0; |
| 832 | |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 833 | shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[kci], |
| 834 | &kcontrol); |
| 835 | |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 836 | if (!kcontrol) { |
| 837 | if (shared) { |
| 838 | wname_in_long_name = false; |
| 839 | kcname_in_long_name = true; |
| 840 | } else { |
| 841 | switch (w->id) { |
| 842 | case snd_soc_dapm_switch: |
| 843 | case snd_soc_dapm_mixer: |
Jeeja KP | 19a2557b | 2015-10-20 22:30:06 +0530 | [diff] [blame] | 844 | case snd_soc_dapm_pga: |
Chen-Yu Tsai | a3930ed | 2016-08-27 19:28:00 +0800 | [diff] [blame] | 845 | case snd_soc_dapm_out_drv: |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 846 | wname_in_long_name = true; |
| 847 | kcname_in_long_name = true; |
| 848 | break; |
| 849 | case snd_soc_dapm_mixer_named_ctl: |
| 850 | wname_in_long_name = false; |
| 851 | kcname_in_long_name = true; |
| 852 | break; |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 853 | case snd_soc_dapm_demux: |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 854 | case snd_soc_dapm_mux: |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 855 | wname_in_long_name = true; |
| 856 | kcname_in_long_name = false; |
| 857 | break; |
| 858 | default: |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 859 | return -EINVAL; |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | if (wname_in_long_name && kcname_in_long_name) { |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 864 | /* |
| 865 | * The control will get a prefix from the control |
| 866 | * creation process but we're also using the same |
| 867 | * prefix for widgets so cut the prefix off the |
| 868 | * front of the widget name. |
| 869 | */ |
Lars-Peter Clausen | 2b58107 | 2013-05-14 11:05:32 +0200 | [diff] [blame] | 870 | long_name = kasprintf(GFP_KERNEL, "%s %s", |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 871 | w->name + prefix_len, |
| 872 | w->kcontrol_news[kci].name); |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 873 | if (long_name == NULL) |
Lars-Peter Clausen | 2b58107 | 2013-05-14 11:05:32 +0200 | [diff] [blame] | 874 | return -ENOMEM; |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 875 | |
| 876 | name = long_name; |
| 877 | } else if (wname_in_long_name) { |
| 878 | long_name = NULL; |
| 879 | name = w->name + prefix_len; |
| 880 | } else { |
| 881 | long_name = NULL; |
| 882 | name = w->kcontrol_news[kci].name; |
| 883 | } |
| 884 | |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 885 | kcontrol = snd_soc_cnew(&w->kcontrol_news[kci], NULL, name, |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 886 | prefix); |
Daniel Mack | e5092c9 | 2014-10-07 13:41:24 +0200 | [diff] [blame] | 887 | if (!kcontrol) { |
| 888 | ret = -ENOMEM; |
| 889 | goto exit_free; |
| 890 | } |
| 891 | |
Lars-Peter Clausen | 9356e9d | 2013-08-01 14:08:06 +0200 | [diff] [blame] | 892 | kcontrol->private_free = dapm_kcontrol_free; |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 893 | |
Lars-Peter Clausen | 41d8002 | 2016-02-03 21:59:50 +0100 | [diff] [blame] | 894 | ret = dapm_kcontrol_data_alloc(w, kcontrol, name); |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 895 | if (ret) { |
| 896 | snd_ctl_free_one(kcontrol); |
Daniel Mack | e5092c9 | 2014-10-07 13:41:24 +0200 | [diff] [blame] | 897 | goto exit_free; |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 898 | } |
| 899 | |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 900 | ret = snd_ctl_add(card, kcontrol); |
| 901 | if (ret < 0) { |
| 902 | dev_err(dapm->dev, |
| 903 | "ASoC: failed to add widget %s dapm kcontrol %s: %d\n", |
| 904 | w->name, name, ret); |
Daniel Mack | e5092c9 | 2014-10-07 13:41:24 +0200 | [diff] [blame] | 905 | goto exit_free; |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 906 | } |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 907 | } |
| 908 | |
Lars-Peter Clausen | 2c75bdf | 2013-08-01 14:08:07 +0200 | [diff] [blame] | 909 | ret = dapm_kcontrol_add_widget(kcontrol, w); |
Daniel Mack | e5092c9 | 2014-10-07 13:41:24 +0200 | [diff] [blame] | 910 | if (ret == 0) |
| 911 | w->kcontrols[kci] = kcontrol; |
Lars-Peter Clausen | 2c75bdf | 2013-08-01 14:08:07 +0200 | [diff] [blame] | 912 | |
Daniel Mack | e5092c9 | 2014-10-07 13:41:24 +0200 | [diff] [blame] | 913 | exit_free: |
| 914 | kfree(long_name); |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 915 | |
Daniel Mack | e5092c9 | 2014-10-07 13:41:24 +0200 | [diff] [blame] | 916 | return ret; |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | /* create new dapm mixer control */ |
| 920 | static int dapm_new_mixer(struct snd_soc_dapm_widget *w) |
| 921 | { |
| 922 | int i, ret; |
| 923 | struct snd_soc_dapm_path *path; |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 924 | struct dapm_kcontrol_data *data; |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 925 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 926 | /* add kcontrol */ |
| 927 | for (i = 0; i < w->num_kcontrols; i++) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 928 | /* match name */ |
Lars-Peter Clausen | e63bfd4 | 2015-07-26 19:05:00 +0200 | [diff] [blame] | 929 | snd_soc_dapm_widget_for_each_source_path(w, path) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 930 | /* mixer/mux paths name must match control name */ |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 931 | if (path->name != (char *)w->kcontrol_news[i].name) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 932 | continue; |
| 933 | |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 934 | if (!w->kcontrols[i]) { |
Jeeja KP | 19a2557b | 2015-10-20 22:30:06 +0530 | [diff] [blame] | 935 | ret = dapm_create_or_share_kcontrol(w, i); |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 936 | if (ret < 0) |
| 937 | return ret; |
Lars-Peter Clausen | 82cd876 | 2011-08-15 20:15:21 +0200 | [diff] [blame] | 938 | } |
| 939 | |
Mark Brown | 946d92a | 2013-08-12 23:28:42 +0100 | [diff] [blame] | 940 | dapm_kcontrol_add_path(w->kcontrols[i], path); |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 941 | |
| 942 | data = snd_kcontrol_chip(w->kcontrols[i]); |
| 943 | if (data->widget) |
| 944 | snd_soc_dapm_add_path(data->widget->dapm, |
| 945 | data->widget, |
| 946 | path->source, |
| 947 | NULL, NULL); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 948 | } |
| 949 | } |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 950 | |
| 951 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | /* create new dapm mux control */ |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 955 | static int dapm_new_mux(struct snd_soc_dapm_widget *w) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 956 | { |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 957 | struct snd_soc_dapm_context *dapm = w->dapm; |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 958 | enum snd_soc_dapm_direction dir; |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 959 | struct snd_soc_dapm_path *path; |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 960 | const char *type; |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 961 | int ret; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 962 | |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 963 | switch (w->id) { |
| 964 | case snd_soc_dapm_mux: |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 965 | dir = SND_SOC_DAPM_DIR_OUT; |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 966 | type = "mux"; |
| 967 | break; |
| 968 | case snd_soc_dapm_demux: |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 969 | dir = SND_SOC_DAPM_DIR_IN; |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 970 | type = "demux"; |
| 971 | break; |
| 972 | default: |
| 973 | return -EINVAL; |
| 974 | } |
| 975 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 976 | if (w->num_kcontrols != 1) { |
| 977 | dev_err(dapm->dev, |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 978 | "ASoC: %s %s has incorrect number of controls\n", type, |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 979 | w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 980 | return -EINVAL; |
| 981 | } |
| 982 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 983 | if (list_empty(&w->edges[dir])) { |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 984 | dev_err(dapm->dev, "ASoC: %s %s has no paths\n", type, w->name); |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 985 | return -EINVAL; |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 986 | } |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 987 | |
Jeeja KP | 19a2557b | 2015-10-20 22:30:06 +0530 | [diff] [blame] | 988 | ret = dapm_create_or_share_kcontrol(w, 0); |
Stephen Warren | 85762e7 | 2013-03-29 15:40:10 -0600 | [diff] [blame] | 989 | if (ret < 0) |
| 990 | return ret; |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 991 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 992 | snd_soc_dapm_widget_for_each_path(w, dir, path) { |
| 993 | if (path->name) |
| 994 | dapm_kcontrol_add_path(w->kcontrols[0], path); |
Lars-Peter Clausen | 98407ef | 2014-10-25 17:41:57 +0200 | [diff] [blame] | 995 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 996 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 997 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | /* create new dapm volume control */ |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 1001 | static int dapm_new_pga(struct snd_soc_dapm_widget *w) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1002 | { |
Jeeja KP | 19a2557b | 2015-10-20 22:30:06 +0530 | [diff] [blame] | 1003 | int i, ret; |
| 1004 | |
| 1005 | for (i = 0; i < w->num_kcontrols; i++) { |
| 1006 | ret = dapm_create_or_share_kcontrol(w, i); |
| 1007 | if (ret < 0) |
| 1008 | return ret; |
| 1009 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1010 | |
Mark Brown | a6c6573 | 2010-03-03 17:45:21 +0000 | [diff] [blame] | 1011 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1012 | } |
| 1013 | |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 1014 | /* create new dapm dai link control */ |
| 1015 | static int dapm_new_dai_link(struct snd_soc_dapm_widget *w) |
| 1016 | { |
| 1017 | int i, ret; |
| 1018 | struct snd_kcontrol *kcontrol; |
| 1019 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 1020 | struct snd_card *card = dapm->card->snd_card; |
Charles Keepax | 243bcfa | 2018-09-05 15:21:02 +0100 | [diff] [blame] | 1021 | struct snd_soc_pcm_runtime *rtd = w->priv; |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 1022 | |
| 1023 | /* create control for links with > 1 config */ |
Charles Keepax | 243bcfa | 2018-09-05 15:21:02 +0100 | [diff] [blame] | 1024 | if (rtd->dai_link->num_params <= 1) |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 1025 | return 0; |
| 1026 | |
| 1027 | /* add kcontrol */ |
| 1028 | for (i = 0; i < w->num_kcontrols; i++) { |
| 1029 | kcontrol = snd_soc_cnew(&w->kcontrol_news[i], w, |
| 1030 | w->name, NULL); |
| 1031 | ret = snd_ctl_add(card, kcontrol); |
| 1032 | if (ret < 0) { |
| 1033 | dev_err(dapm->dev, |
| 1034 | "ASoC: failed to add widget %s dapm kcontrol %s: %d\n", |
| 1035 | w->name, w->kcontrol_news[i].name, ret); |
| 1036 | return ret; |
| 1037 | } |
| 1038 | kcontrol->private_data = w; |
| 1039 | w->kcontrols[i] = kcontrol; |
| 1040 | } |
| 1041 | |
| 1042 | return 0; |
| 1043 | } |
| 1044 | |
Mark Brown | 9949788b | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 1045 | /* We implement power down on suspend by checking the power state of |
| 1046 | * the ALSA card - when we are suspending the ALSA state for the card |
| 1047 | * is set to D3. |
| 1048 | */ |
| 1049 | static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget) |
| 1050 | { |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 1051 | int level = snd_power_get_state(widget->dapm->card->snd_card); |
Mark Brown | 9949788b | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 1052 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1053 | switch (level) { |
Mark Brown | 9949788b | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 1054 | case SNDRV_CTL_POWER_D3hot: |
| 1055 | case SNDRV_CTL_POWER_D3cold: |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 1056 | if (widget->ignore_suspend) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1057 | dev_dbg(widget->dapm->dev, "ASoC: %s ignoring suspend\n", |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 1058 | widget->name); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 1059 | return widget->ignore_suspend; |
Mark Brown | 9949788b | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 1060 | default: |
| 1061 | return 1; |
| 1062 | } |
| 1063 | } |
| 1064 | |
Lars-Peter Clausen | 1ce43ac | 2015-07-26 19:04:59 +0200 | [diff] [blame] | 1065 | static int dapm_widget_list_create(struct snd_soc_dapm_widget_list **list, |
| 1066 | struct list_head *widgets) |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1067 | { |
Lars-Peter Clausen | 1ce43ac | 2015-07-26 19:04:59 +0200 | [diff] [blame] | 1068 | struct snd_soc_dapm_widget *w; |
| 1069 | struct list_head *it; |
| 1070 | unsigned int size = 0; |
| 1071 | unsigned int i = 0; |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1072 | |
Lars-Peter Clausen | 1ce43ac | 2015-07-26 19:04:59 +0200 | [diff] [blame] | 1073 | list_for_each(it, widgets) |
| 1074 | size++; |
| 1075 | |
Kees Cook | acafe7e | 2018-05-08 13:45:50 -0700 | [diff] [blame] | 1076 | *list = kzalloc(struct_size(*list, widgets, size), GFP_KERNEL); |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1077 | if (*list == NULL) |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1078 | return -ENOMEM; |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1079 | |
Lars-Peter Clausen | 1ce43ac | 2015-07-26 19:04:59 +0200 | [diff] [blame] | 1080 | list_for_each_entry(w, widgets, work_list) |
| 1081 | (*list)->widgets[i++] = w; |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1082 | |
Lars-Peter Clausen | 1ce43ac | 2015-07-26 19:04:59 +0200 | [diff] [blame] | 1083 | (*list)->num_widgets = i; |
| 1084 | |
| 1085 | return 0; |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1086 | } |
| 1087 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 1088 | /* |
| 1089 | * Common implementation for is_connected_output_ep() and |
| 1090 | * is_connected_input_ep(). The function is inlined since the combined size of |
| 1091 | * the two specialized functions is only marginally larger then the size of the |
| 1092 | * generic function and at the same time the fast path of the specialized |
| 1093 | * functions is significantly smaller than the generic function. |
| 1094 | */ |
| 1095 | static __always_inline int is_connected_ep(struct snd_soc_dapm_widget *widget, |
| 1096 | struct list_head *list, enum snd_soc_dapm_direction dir, |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1097 | int (*fn)(struct snd_soc_dapm_widget *, struct list_head *, |
| 1098 | bool (*custom_stop_condition)(struct snd_soc_dapm_widget *, |
| 1099 | enum snd_soc_dapm_direction)), |
| 1100 | bool (*custom_stop_condition)(struct snd_soc_dapm_widget *, |
| 1101 | enum snd_soc_dapm_direction)) |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 1102 | { |
| 1103 | enum snd_soc_dapm_direction rdir = SND_SOC_DAPM_DIR_REVERSE(dir); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1104 | struct snd_soc_dapm_path *path; |
| 1105 | int con = 0; |
| 1106 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 1107 | if (widget->endpoints[dir] >= 0) |
| 1108 | return widget->endpoints[dir]; |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 1109 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 1110 | DAPM_UPDATE_STAT(widget, path_checks); |
| 1111 | |
Lars-Peter Clausen | 1ce43ac | 2015-07-26 19:04:59 +0200 | [diff] [blame] | 1112 | /* do we need to add this widget to the list ? */ |
| 1113 | if (list) |
| 1114 | list_add_tail(&widget->work_list, list); |
| 1115 | |
Jeeja KP | 0946497 | 2016-06-15 11:16:55 +0530 | [diff] [blame] | 1116 | if (custom_stop_condition && custom_stop_condition(widget, dir)) { |
| 1117 | widget->endpoints[dir] = 1; |
| 1118 | return widget->endpoints[dir]; |
| 1119 | } |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1120 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 1121 | if ((widget->is_ep & SND_SOC_DAPM_DIR_TO_EP(dir)) && widget->connected) { |
| 1122 | widget->endpoints[dir] = snd_soc_dapm_suspend_check(widget); |
| 1123 | return widget->endpoints[dir]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1124 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1125 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 1126 | snd_soc_dapm_widget_for_each_path(widget, rdir, path) { |
Mark Brown | e56235e0 | 2011-09-21 18:19:14 +0100 | [diff] [blame] | 1127 | DAPM_UPDATE_STAT(widget, neighbour_checks); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1128 | |
Lars-Peter Clausen | c1862c8 | 2014-10-25 17:42:00 +0200 | [diff] [blame] | 1129 | if (path->weak || path->is_supply) |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 1130 | continue; |
| 1131 | |
Mark Brown | 8af294b | 2013-02-22 17:48:15 +0000 | [diff] [blame] | 1132 | if (path->walking) |
| 1133 | return 1; |
| 1134 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 1135 | trace_snd_soc_dapm_path(widget, dir, path); |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1136 | |
Lars-Peter Clausen | 7ddd4cd | 2014-10-20 19:36:34 +0200 | [diff] [blame] | 1137 | if (path->connect) { |
Mark Brown | 8af294b | 2013-02-22 17:48:15 +0000 | [diff] [blame] | 1138 | path->walking = 1; |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1139 | con += fn(path->node[dir], list, custom_stop_condition); |
Mark Brown | 8af294b | 2013-02-22 17:48:15 +0000 | [diff] [blame] | 1140 | path->walking = 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1141 | } |
| 1142 | } |
| 1143 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 1144 | widget->endpoints[dir] = con; |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 1145 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1146 | return con; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | /* |
| 1150 | * Recursively check for a completed path to an active or physically connected |
| 1151 | * output widget. Returns number of complete paths. |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1152 | * |
| 1153 | * Optionally, can be supplied with a function acting as a stopping condition. |
| 1154 | * This function takes the dapm widget currently being examined and the walk |
| 1155 | * direction as an arguments, it should return true if the walk should be |
| 1156 | * stopped and false otherwise. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1157 | */ |
| 1158 | static int is_connected_output_ep(struct snd_soc_dapm_widget *widget, |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1159 | struct list_head *list, |
| 1160 | bool (*custom_stop_condition)(struct snd_soc_dapm_widget *i, |
| 1161 | enum snd_soc_dapm_direction)) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1162 | { |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 1163 | return is_connected_ep(widget, list, SND_SOC_DAPM_DIR_OUT, |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1164 | is_connected_output_ep, custom_stop_condition); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | /* |
| 1168 | * Recursively check for a completed path to an active or physically connected |
| 1169 | * input widget. Returns number of complete paths. |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1170 | * |
| 1171 | * Optionally, can be supplied with a function acting as a stopping condition. |
| 1172 | * This function takes the dapm widget currently being examined and the walk |
| 1173 | * direction as an arguments, it should return true if the walk should be |
| 1174 | * stopped and false otherwise. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1175 | */ |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1176 | static int is_connected_input_ep(struct snd_soc_dapm_widget *widget, |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1177 | struct list_head *list, |
| 1178 | bool (*custom_stop_condition)(struct snd_soc_dapm_widget *i, |
| 1179 | enum snd_soc_dapm_direction)) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1180 | { |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 1181 | return is_connected_ep(widget, list, SND_SOC_DAPM_DIR_IN, |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1182 | is_connected_input_ep, custom_stop_condition); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1183 | } |
| 1184 | |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1185 | /** |
| 1186 | * snd_soc_dapm_get_connected_widgets - query audio path and it's widgets. |
| 1187 | * @dai: the soc DAI. |
| 1188 | * @stream: stream direction. |
| 1189 | * @list: list of active widgets for this stream. |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1190 | * @custom_stop_condition: (optional) a function meant to stop the widget graph |
| 1191 | * walk based on custom logic. |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1192 | * |
Peter Meerwald-Stadler | c804600 | 2016-08-16 16:56:17 +0200 | [diff] [blame] | 1193 | * Queries DAPM graph as to whether a valid audio stream path exists for |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1194 | * the initial stream specified by name. This takes into account |
| 1195 | * current mixer and mux kcontrol settings. Creates list of valid widgets. |
| 1196 | * |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1197 | * Optionally, can be supplied with a function acting as a stopping condition. |
| 1198 | * This function takes the dapm widget currently being examined and the walk |
| 1199 | * direction as an arguments, it should return true if the walk should be |
| 1200 | * stopped and false otherwise. |
| 1201 | * |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1202 | * Returns the number of valid paths or negative error. |
| 1203 | */ |
| 1204 | int snd_soc_dapm_dai_get_connected_widgets(struct snd_soc_dai *dai, int stream, |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1205 | struct snd_soc_dapm_widget_list **list, |
| 1206 | bool (*custom_stop_condition)(struct snd_soc_dapm_widget *, |
| 1207 | enum snd_soc_dapm_direction)) |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1208 | { |
Lars-Peter Clausen | 313665b | 2014-11-04 11:30:58 +0100 | [diff] [blame] | 1209 | struct snd_soc_card *card = dai->component->card; |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 1210 | struct snd_soc_dapm_widget *w; |
Lars-Peter Clausen | 1ce43ac | 2015-07-26 19:04:59 +0200 | [diff] [blame] | 1211 | LIST_HEAD(widgets); |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1212 | int paths; |
Lars-Peter Clausen | 1ce43ac | 2015-07-26 19:04:59 +0200 | [diff] [blame] | 1213 | int ret; |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1214 | |
| 1215 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 1216 | |
| 1217 | /* |
| 1218 | * For is_connected_{output,input}_ep fully discover the graph we need |
| 1219 | * to reset the cached number of inputs and outputs. |
| 1220 | */ |
| 1221 | list_for_each_entry(w, &card->widgets, list) { |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 1222 | w->endpoints[SND_SOC_DAPM_DIR_IN] = -1; |
| 1223 | w->endpoints[SND_SOC_DAPM_DIR_OUT] = -1; |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 1224 | } |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1225 | |
Lars-Peter Clausen | 130897a | 2014-10-20 19:36:39 +0200 | [diff] [blame] | 1226 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1227 | paths = is_connected_output_ep(dai->playback_widget, &widgets, |
| 1228 | custom_stop_condition); |
Lars-Peter Clausen | 130897a | 2014-10-20 19:36:39 +0200 | [diff] [blame] | 1229 | else |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1230 | paths = is_connected_input_ep(dai->capture_widget, &widgets, |
| 1231 | custom_stop_condition); |
Lars-Peter Clausen | 1ce43ac | 2015-07-26 19:04:59 +0200 | [diff] [blame] | 1232 | |
| 1233 | /* Drop starting point */ |
| 1234 | list_del(widgets.next); |
| 1235 | |
| 1236 | ret = dapm_widget_list_create(list, &widgets); |
| 1237 | if (ret) |
Lars-Peter Clausen | 30abbe7 | 2015-08-11 21:37:59 +0200 | [diff] [blame] | 1238 | paths = ret; |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1239 | |
| 1240 | trace_snd_soc_dapm_connected(paths, stream); |
Liam Girdwood | ec2e303 | 2012-04-18 11:41:11 +0100 | [diff] [blame] | 1241 | mutex_unlock(&card->dapm_mutex); |
| 1242 | |
| 1243 | return paths; |
| 1244 | } |
| 1245 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1246 | /* |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 1247 | * Handler for regulator supply widget. |
| 1248 | */ |
| 1249 | int dapm_regulator_event(struct snd_soc_dapm_widget *w, |
| 1250 | struct snd_kcontrol *kcontrol, int event) |
| 1251 | { |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1252 | int ret; |
| 1253 | |
Mark Brown | eb270e9 | 2013-10-09 13:52:52 +0100 | [diff] [blame] | 1254 | soc_dapm_async_complete(w->dapm); |
| 1255 | |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1256 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
Lars-Peter Clausen | de9ba98 | 2013-07-29 17:14:01 +0200 | [diff] [blame] | 1257 | if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) { |
Mark Brown | 8784c77 | 2013-01-10 19:33:47 +0000 | [diff] [blame] | 1258 | ret = regulator_allow_bypass(w->regulator, false); |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1259 | if (ret != 0) |
| 1260 | dev_warn(w->dapm->dev, |
Charles Keepax | 30686c3 | 2014-02-18 16:05:27 +0000 | [diff] [blame] | 1261 | "ASoC: Failed to unbypass %s: %d\n", |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1262 | w->name, ret); |
| 1263 | } |
| 1264 | |
Liam Girdwood | a3cc056 | 2012-03-09 17:20:16 +0000 | [diff] [blame] | 1265 | return regulator_enable(w->regulator); |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1266 | } else { |
Lars-Peter Clausen | de9ba98 | 2013-07-29 17:14:01 +0200 | [diff] [blame] | 1267 | if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) { |
Mark Brown | 8784c77 | 2013-01-10 19:33:47 +0000 | [diff] [blame] | 1268 | ret = regulator_allow_bypass(w->regulator, true); |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1269 | if (ret != 0) |
| 1270 | dev_warn(w->dapm->dev, |
Charles Keepax | 30686c3 | 2014-02-18 16:05:27 +0000 | [diff] [blame] | 1271 | "ASoC: Failed to bypass %s: %d\n", |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1272 | w->name, ret); |
| 1273 | } |
| 1274 | |
Liam Girdwood | a3cc056 | 2012-03-09 17:20:16 +0000 | [diff] [blame] | 1275 | return regulator_disable_deferred(w->regulator, w->shift); |
Mark Brown | c05b84d | 2012-09-07 12:57:11 +0800 | [diff] [blame] | 1276 | } |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 1277 | } |
| 1278 | EXPORT_SYMBOL_GPL(dapm_regulator_event); |
| 1279 | |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 1280 | /* |
Srinivas Kandagatla | 5b2d15b | 2018-03-10 02:37:27 +0000 | [diff] [blame] | 1281 | * Handler for pinctrl widget. |
| 1282 | */ |
| 1283 | int dapm_pinctrl_event(struct snd_soc_dapm_widget *w, |
| 1284 | struct snd_kcontrol *kcontrol, int event) |
| 1285 | { |
| 1286 | struct snd_soc_dapm_pinctrl_priv *priv = w->priv; |
| 1287 | struct pinctrl *p = w->pinctrl; |
| 1288 | struct pinctrl_state *s; |
| 1289 | |
| 1290 | if (!p || !priv) |
| 1291 | return -EIO; |
| 1292 | |
| 1293 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 1294 | s = pinctrl_lookup_state(p, priv->active_state); |
| 1295 | else |
| 1296 | s = pinctrl_lookup_state(p, priv->sleep_state); |
| 1297 | |
| 1298 | if (IS_ERR(s)) |
| 1299 | return PTR_ERR(s); |
| 1300 | |
| 1301 | return pinctrl_select_state(p, s); |
| 1302 | } |
| 1303 | EXPORT_SYMBOL_GPL(dapm_pinctrl_event); |
| 1304 | |
| 1305 | /* |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 1306 | * Handler for clock supply widget. |
| 1307 | */ |
| 1308 | int dapm_clock_event(struct snd_soc_dapm_widget *w, |
| 1309 | struct snd_kcontrol *kcontrol, int event) |
| 1310 | { |
| 1311 | if (!w->clk) |
| 1312 | return -EIO; |
| 1313 | |
Mark Brown | eb270e9 | 2013-10-09 13:52:52 +0100 | [diff] [blame] | 1314 | soc_dapm_async_complete(w->dapm); |
| 1315 | |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 1316 | if (SND_SOC_DAPM_EVENT_ON(event)) { |
Fabio Baltieri | 37c1b92 | 2013-04-30 16:09:52 +0200 | [diff] [blame] | 1317 | return clk_prepare_enable(w->clk); |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 1318 | } else { |
Fabio Baltieri | 37c1b92 | 2013-04-30 16:09:52 +0200 | [diff] [blame] | 1319 | clk_disable_unprepare(w->clk); |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 1320 | return 0; |
| 1321 | } |
Charles Keepax | d78b1e43 | 2018-08-28 14:35:02 +0100 | [diff] [blame] | 1322 | |
Marek Belisko | 98b3cf1 | 2012-07-12 23:00:16 +0200 | [diff] [blame] | 1323 | return 0; |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 1324 | } |
| 1325 | EXPORT_SYMBOL_GPL(dapm_clock_event); |
| 1326 | |
Mark Brown | d805002b | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 1327 | static int dapm_widget_power_check(struct snd_soc_dapm_widget *w) |
| 1328 | { |
Mark Brown | 9b8a83b | 2011-10-04 22:15:59 +0100 | [diff] [blame] | 1329 | if (w->power_checked) |
| 1330 | return w->new_power; |
| 1331 | |
Mark Brown | d805002b | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 1332 | if (w->force) |
Mark Brown | 9b8a83b | 2011-10-04 22:15:59 +0100 | [diff] [blame] | 1333 | w->new_power = 1; |
Mark Brown | d805002b | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 1334 | else |
Mark Brown | 9b8a83b | 2011-10-04 22:15:59 +0100 | [diff] [blame] | 1335 | w->new_power = w->power_check(w); |
| 1336 | |
| 1337 | w->power_checked = true; |
| 1338 | |
| 1339 | return w->new_power; |
Mark Brown | d805002b | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 1340 | } |
| 1341 | |
Peter Meerwald-Stadler | c804600 | 2016-08-16 16:56:17 +0200 | [diff] [blame] | 1342 | /* Generic check to see if a widget should be powered. */ |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 1343 | static int dapm_generic_check_power(struct snd_soc_dapm_widget *w) |
| 1344 | { |
| 1345 | int in, out; |
| 1346 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 1347 | DAPM_UPDATE_STAT(w, power_checks); |
| 1348 | |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 1349 | in = is_connected_input_ep(w, NULL, NULL); |
| 1350 | out = is_connected_output_ep(w, NULL, NULL); |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 1351 | return out != 0 && in != 0; |
| 1352 | } |
| 1353 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1354 | /* Check to see if a power supply is needed */ |
| 1355 | static int dapm_supply_check_power(struct snd_soc_dapm_widget *w) |
| 1356 | { |
| 1357 | struct snd_soc_dapm_path *path; |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1358 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 1359 | DAPM_UPDATE_STAT(w, power_checks); |
| 1360 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1361 | /* Check if one of our outputs is connected */ |
Lars-Peter Clausen | e63bfd4 | 2015-07-26 19:05:00 +0200 | [diff] [blame] | 1362 | snd_soc_dapm_widget_for_each_sink_path(w, path) { |
Mark Brown | a8fdac8 | 2011-09-28 18:20:26 +0100 | [diff] [blame] | 1363 | DAPM_UPDATE_STAT(w, neighbour_checks); |
| 1364 | |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 1365 | if (path->weak) |
| 1366 | continue; |
| 1367 | |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1368 | if (path->connected && |
| 1369 | !path->connected(path->source, path->sink)) |
| 1370 | continue; |
| 1371 | |
Mark Brown | f68d7e1 | 2011-10-04 22:57:50 +0100 | [diff] [blame] | 1372 | if (dapm_widget_power_check(path->sink)) |
| 1373 | return 1; |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1374 | } |
| 1375 | |
Mark Brown | f68d7e1 | 2011-10-04 22:57:50 +0100 | [diff] [blame] | 1376 | return 0; |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1377 | } |
| 1378 | |
Mark Brown | 35c64bc | 2011-09-28 18:23:53 +0100 | [diff] [blame] | 1379 | static int dapm_always_on_check_power(struct snd_soc_dapm_widget *w) |
| 1380 | { |
Charles Keepax | 20bb018 | 2015-12-02 10:22:16 +0000 | [diff] [blame] | 1381 | return w->connected; |
Mark Brown | 35c64bc | 2011-09-28 18:23:53 +0100 | [diff] [blame] | 1382 | } |
| 1383 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1384 | static int dapm_seq_compare(struct snd_soc_dapm_widget *a, |
| 1385 | struct snd_soc_dapm_widget *b, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1386 | bool power_up) |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1387 | { |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1388 | int *sort; |
| 1389 | |
| 1390 | if (power_up) |
| 1391 | sort = dapm_up_seq; |
| 1392 | else |
| 1393 | sort = dapm_down_seq; |
| 1394 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1395 | if (sort[a->id] != sort[b->id]) |
| 1396 | return sort[a->id] - sort[b->id]; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1397 | if (a->subseq != b->subseq) { |
| 1398 | if (power_up) |
| 1399 | return a->subseq - b->subseq; |
| 1400 | else |
| 1401 | return b->subseq - a->subseq; |
| 1402 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1403 | if (a->reg != b->reg) |
| 1404 | return a->reg - b->reg; |
Mark Brown | 84dab56 | 2010-11-12 15:28:42 +0000 | [diff] [blame] | 1405 | if (a->dapm != b->dapm) |
| 1406 | return (unsigned long)a->dapm - (unsigned long)b->dapm; |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1407 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1408 | return 0; |
| 1409 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1410 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1411 | /* Insert a widget in order into a DAPM power sequence. */ |
| 1412 | static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget, |
| 1413 | struct list_head *list, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1414 | bool power_up) |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1415 | { |
| 1416 | struct snd_soc_dapm_widget *w; |
| 1417 | |
| 1418 | list_for_each_entry(w, list, power_list) |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1419 | if (dapm_seq_compare(new_widget, w, power_up) < 0) { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1420 | list_add_tail(&new_widget->power_list, &w->power_list); |
| 1421 | return; |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1422 | } |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 1423 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1424 | list_add_tail(&new_widget->power_list, list); |
| 1425 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1426 | |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1427 | static void dapm_seq_check_event(struct snd_soc_card *card, |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1428 | struct snd_soc_dapm_widget *w, int event) |
| 1429 | { |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1430 | const char *ev_name; |
| 1431 | int power, ret; |
| 1432 | |
| 1433 | switch (event) { |
| 1434 | case SND_SOC_DAPM_PRE_PMU: |
| 1435 | ev_name = "PRE_PMU"; |
| 1436 | power = 1; |
| 1437 | break; |
| 1438 | case SND_SOC_DAPM_POST_PMU: |
| 1439 | ev_name = "POST_PMU"; |
| 1440 | power = 1; |
| 1441 | break; |
| 1442 | case SND_SOC_DAPM_PRE_PMD: |
| 1443 | ev_name = "PRE_PMD"; |
| 1444 | power = 0; |
| 1445 | break; |
| 1446 | case SND_SOC_DAPM_POST_PMD: |
| 1447 | ev_name = "POST_PMD"; |
| 1448 | power = 0; |
| 1449 | break; |
Mark Brown | 8011412 | 2013-02-25 15:14:19 +0000 | [diff] [blame] | 1450 | case SND_SOC_DAPM_WILL_PMU: |
| 1451 | ev_name = "WILL_PMU"; |
| 1452 | power = 1; |
| 1453 | break; |
| 1454 | case SND_SOC_DAPM_WILL_PMD: |
| 1455 | ev_name = "WILL_PMD"; |
| 1456 | power = 0; |
| 1457 | break; |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1458 | default: |
Takashi Iwai | a6ed060 | 2013-11-06 11:07:19 +0100 | [diff] [blame] | 1459 | WARN(1, "Unknown event %d\n", event); |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1460 | return; |
| 1461 | } |
| 1462 | |
Lars-Peter Clausen | 39eb5fd | 2013-07-29 17:14:03 +0200 | [diff] [blame] | 1463 | if (w->new_power != power) |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1464 | return; |
| 1465 | |
| 1466 | if (w->event && (w->event_flags & event)) { |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1467 | pop_dbg(w->dapm->dev, card->pop_time, "pop test : %s %s\n", |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1468 | w->name, ev_name); |
Mark Brown | eb270e9 | 2013-10-09 13:52:52 +0100 | [diff] [blame] | 1469 | soc_dapm_async_complete(w->dapm); |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1470 | trace_snd_soc_dapm_widget_event_start(w, event); |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1471 | ret = w->event(w, NULL, event); |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1472 | trace_snd_soc_dapm_widget_event_done(w, event); |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1473 | if (ret < 0) |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1474 | dev_err(w->dapm->dev, "ASoC: %s: %s event failed: %d\n", |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1475 | ev_name, w->name, ret); |
| 1476 | } |
| 1477 | } |
| 1478 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1479 | /* Apply the coalesced changes from a DAPM sequence */ |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1480 | static void dapm_seq_run_coalesced(struct snd_soc_card *card, |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1481 | struct list_head *pending) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1482 | { |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 1483 | struct snd_soc_dapm_context *dapm; |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1484 | struct snd_soc_dapm_widget *w; |
Lars-Peter Clausen | de9ba98 | 2013-07-29 17:14:01 +0200 | [diff] [blame] | 1485 | int reg; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1486 | unsigned int value = 0; |
| 1487 | unsigned int mask = 0; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1488 | |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 1489 | w = list_first_entry(pending, struct snd_soc_dapm_widget, power_list); |
| 1490 | reg = w->reg; |
| 1491 | dapm = w->dapm; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1492 | |
| 1493 | list_for_each_entry(w, pending, power_list) { |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 1494 | WARN_ON(reg != w->reg || dapm != w->dapm); |
Lars-Peter Clausen | 39eb5fd | 2013-07-29 17:14:03 +0200 | [diff] [blame] | 1495 | w->power = w->new_power; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1496 | |
Lars-Peter Clausen | de9ba98 | 2013-07-29 17:14:01 +0200 | [diff] [blame] | 1497 | mask |= w->mask << w->shift; |
| 1498 | if (w->power) |
| 1499 | value |= w->on_val << w->shift; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1500 | else |
Lars-Peter Clausen | de9ba98 | 2013-07-29 17:14:01 +0200 | [diff] [blame] | 1501 | value |= w->off_val << w->shift; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1502 | |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 1503 | pop_dbg(dapm->dev, card->pop_time, |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1504 | "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n", |
| 1505 | w->name, reg, value, mask); |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1506 | |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1507 | /* Check for events */ |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1508 | dapm_seq_check_event(card, w, SND_SOC_DAPM_PRE_PMU); |
| 1509 | dapm_seq_check_event(card, w, SND_SOC_DAPM_PRE_PMD); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1510 | } |
| 1511 | |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1512 | if (reg >= 0) { |
Mark Brown | 29376bc | 2011-06-19 13:49:28 +0100 | [diff] [blame] | 1513 | /* Any widget will do, they should all be updating the |
| 1514 | * same register. |
| 1515 | */ |
Mark Brown | 29376bc | 2011-06-19 13:49:28 +0100 | [diff] [blame] | 1516 | |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 1517 | pop_dbg(dapm->dev, card->pop_time, |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1518 | "pop test : Applying 0x%x/0x%x to %x in %dms\n", |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1519 | value, mask, reg, card->pop_time); |
| 1520 | pop_wait(card->pop_time); |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 1521 | soc_dapm_update_bits(dapm, reg, mask, value); |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | list_for_each_entry(w, pending, power_list) { |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1525 | dapm_seq_check_event(card, w, SND_SOC_DAPM_POST_PMU); |
| 1526 | dapm_seq_check_event(card, w, SND_SOC_DAPM_POST_PMD); |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1527 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1530 | /* Apply a DAPM power sequence. |
| 1531 | * |
| 1532 | * We walk over a pre-sorted list of widgets to apply power to. In |
| 1533 | * order to minimise the number of writes to the device required |
| 1534 | * multiple widgets will be updated in a single write where possible. |
| 1535 | * Currently anything that requires more than a single write is not |
| 1536 | * handled. |
| 1537 | */ |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1538 | static void dapm_seq_run(struct snd_soc_card *card, |
| 1539 | struct list_head *list, int event, bool power_up) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1540 | { |
| 1541 | struct snd_soc_dapm_widget *w, *n; |
Mark Brown | eb270e9 | 2013-10-09 13:52:52 +0100 | [diff] [blame] | 1542 | struct snd_soc_dapm_context *d; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1543 | LIST_HEAD(pending); |
| 1544 | int cur_sort = -1; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1545 | int cur_subseq = -1; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1546 | int cur_reg = SND_SOC_NOPM; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1547 | struct snd_soc_dapm_context *cur_dapm = NULL; |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1548 | int ret, i; |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1549 | int *sort; |
| 1550 | |
| 1551 | if (power_up) |
| 1552 | sort = dapm_up_seq; |
| 1553 | else |
| 1554 | sort = dapm_down_seq; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1555 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1556 | list_for_each_entry_safe(w, n, list, power_list) { |
| 1557 | ret = 0; |
| 1558 | |
| 1559 | /* Do we need to apply any queued changes? */ |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1560 | if (sort[w->id] != cur_sort || w->reg != cur_reg || |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1561 | w->dapm != cur_dapm || w->subseq != cur_subseq) { |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1562 | if (!list_empty(&pending)) |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1563 | dapm_seq_run_coalesced(card, &pending); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1564 | |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1565 | if (cur_dapm && cur_dapm->seq_notifier) { |
| 1566 | for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) |
| 1567 | if (sort[i] == cur_sort) |
| 1568 | cur_dapm->seq_notifier(cur_dapm, |
Mark Brown | f85a9e0 | 2011-01-26 21:41:28 +0000 | [diff] [blame] | 1569 | i, |
| 1570 | cur_subseq); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
Mark Brown | eb270e9 | 2013-10-09 13:52:52 +0100 | [diff] [blame] | 1573 | if (cur_dapm && w->dapm != cur_dapm) |
| 1574 | soc_dapm_async_complete(cur_dapm); |
| 1575 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1576 | INIT_LIST_HEAD(&pending); |
| 1577 | cur_sort = -1; |
Mark Brown | b0b3e6f | 2011-07-16 10:55:08 +0900 | [diff] [blame] | 1578 | cur_subseq = INT_MIN; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1579 | cur_reg = SND_SOC_NOPM; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1580 | cur_dapm = NULL; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1581 | } |
| 1582 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1583 | switch (w->id) { |
| 1584 | case snd_soc_dapm_pre: |
| 1585 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1586 | list_for_each_entry_safe_continue(w, n, list, |
| 1587 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1588 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1589 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1590 | ret = w->event(w, |
| 1591 | NULL, SND_SOC_DAPM_PRE_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1592 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1593 | ret = w->event(w, |
| 1594 | NULL, SND_SOC_DAPM_PRE_PMD); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1595 | break; |
| 1596 | |
| 1597 | case snd_soc_dapm_post: |
| 1598 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1599 | list_for_each_entry_safe_continue(w, n, list, |
| 1600 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1601 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1602 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1603 | ret = w->event(w, |
| 1604 | NULL, SND_SOC_DAPM_POST_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1605 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1606 | ret = w->event(w, |
| 1607 | NULL, SND_SOC_DAPM_POST_PMD); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1608 | break; |
| 1609 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1610 | default: |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1611 | /* Queue it up for application */ |
| 1612 | cur_sort = sort[w->id]; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1613 | cur_subseq = w->subseq; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1614 | cur_reg = w->reg; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1615 | cur_dapm = w->dapm; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1616 | list_move(&w->power_list, &pending); |
| 1617 | break; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1618 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1619 | |
| 1620 | if (ret < 0) |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 1621 | dev_err(w->dapm->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1622 | "ASoC: Failed to apply widget power: %d\n", ret); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1623 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1624 | |
| 1625 | if (!list_empty(&pending)) |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1626 | dapm_seq_run_coalesced(card, &pending); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1627 | |
| 1628 | if (cur_dapm && cur_dapm->seq_notifier) { |
| 1629 | for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) |
| 1630 | if (sort[i] == cur_sort) |
| 1631 | cur_dapm->seq_notifier(cur_dapm, |
Mark Brown | f85a9e0 | 2011-01-26 21:41:28 +0000 | [diff] [blame] | 1632 | i, cur_subseq); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1633 | } |
Mark Brown | eb270e9 | 2013-10-09 13:52:52 +0100 | [diff] [blame] | 1634 | |
| 1635 | list_for_each_entry(d, &card->dapm_list, list) { |
| 1636 | soc_dapm_async_complete(d); |
| 1637 | } |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1638 | } |
| 1639 | |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1640 | static void dapm_widget_update(struct snd_soc_card *card) |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1641 | { |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1642 | struct snd_soc_dapm_update *update = card->update; |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame] | 1643 | struct snd_soc_dapm_widget_list *wlist; |
| 1644 | struct snd_soc_dapm_widget *w = NULL; |
| 1645 | unsigned int wi; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1646 | int ret; |
| 1647 | |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 1648 | if (!update || !dapm_kcontrol_is_powered(update->kcontrol)) |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1649 | return; |
| 1650 | |
Lars-Peter Clausen | e84357f | 2013-07-29 17:13:58 +0200 | [diff] [blame] | 1651 | wlist = dapm_kcontrol_get_wlist(update->kcontrol); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1652 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame] | 1653 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 1654 | w = wlist->widgets[wi]; |
| 1655 | |
| 1656 | if (w->event && (w->event_flags & SND_SOC_DAPM_PRE_REG)) { |
| 1657 | ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG); |
| 1658 | if (ret != 0) |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1659 | dev_err(w->dapm->dev, "ASoC: %s DAPM pre-event failed: %d\n", |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame] | 1660 | w->name, ret); |
| 1661 | } |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame] | 1664 | if (!w) |
| 1665 | return; |
| 1666 | |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 1667 | ret = soc_dapm_update_bits(w->dapm, update->reg, update->mask, |
| 1668 | update->val); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1669 | if (ret < 0) |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1670 | dev_err(w->dapm->dev, "ASoC: %s DAPM update failed: %d\n", |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1671 | w->name, ret); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1672 | |
Chen-Yu Tsai | e411b0b | 2016-11-02 15:35:58 +0800 | [diff] [blame] | 1673 | if (update->has_second_set) { |
| 1674 | ret = soc_dapm_update_bits(w->dapm, update->reg2, |
| 1675 | update->mask2, update->val2); |
| 1676 | if (ret < 0) |
| 1677 | dev_err(w->dapm->dev, |
| 1678 | "ASoC: %s DAPM update failed: %d\n", |
| 1679 | w->name, ret); |
| 1680 | } |
| 1681 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame] | 1682 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 1683 | w = wlist->widgets[wi]; |
| 1684 | |
| 1685 | if (w->event && (w->event_flags & SND_SOC_DAPM_POST_REG)) { |
| 1686 | ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG); |
| 1687 | if (ret != 0) |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1688 | dev_err(w->dapm->dev, "ASoC: %s DAPM post-event failed: %d\n", |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame] | 1689 | w->name, ret); |
| 1690 | } |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1691 | } |
| 1692 | } |
| 1693 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1694 | /* Async callback run prior to DAPM sequences - brings to _PREPARE if |
| 1695 | * they're changing state. |
| 1696 | */ |
| 1697 | static void dapm_pre_sequence_async(void *data, async_cookie_t cookie) |
| 1698 | { |
| 1699 | struct snd_soc_dapm_context *d = data; |
| 1700 | int ret; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1701 | |
Peter Meerwald-Stadler | c804600 | 2016-08-16 16:56:17 +0200 | [diff] [blame] | 1702 | /* If we're off and we're not supposed to go into STANDBY */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1703 | if (d->bias_level == SND_SOC_BIAS_OFF && |
| 1704 | d->target_bias_level != SND_SOC_BIAS_OFF) { |
Mark Brown | f1aac48 | 2011-12-05 15:17:06 +0000 | [diff] [blame] | 1705 | if (d->dev) |
| 1706 | pm_runtime_get_sync(d->dev); |
| 1707 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1708 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY); |
| 1709 | if (ret != 0) |
| 1710 | dev_err(d->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1711 | "ASoC: Failed to turn on bias: %d\n", ret); |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1712 | } |
| 1713 | |
Lars-Peter Clausen | ce85a4d | 2014-05-06 10:32:15 +0200 | [diff] [blame] | 1714 | /* Prepare for a transition to ON or away from ON */ |
| 1715 | if ((d->target_bias_level == SND_SOC_BIAS_ON && |
| 1716 | d->bias_level != SND_SOC_BIAS_ON) || |
| 1717 | (d->target_bias_level != SND_SOC_BIAS_ON && |
| 1718 | d->bias_level == SND_SOC_BIAS_ON)) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1719 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE); |
| 1720 | if (ret != 0) |
| 1721 | dev_err(d->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1722 | "ASoC: Failed to prepare bias: %d\n", ret); |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | /* Async callback run prior to DAPM sequences - brings to their final |
| 1727 | * state. |
| 1728 | */ |
| 1729 | static void dapm_post_sequence_async(void *data, async_cookie_t cookie) |
| 1730 | { |
| 1731 | struct snd_soc_dapm_context *d = data; |
| 1732 | int ret; |
| 1733 | |
| 1734 | /* If we just powered the last thing off drop to standby bias */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1735 | if (d->bias_level == SND_SOC_BIAS_PREPARE && |
| 1736 | (d->target_bias_level == SND_SOC_BIAS_STANDBY || |
| 1737 | d->target_bias_level == SND_SOC_BIAS_OFF)) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1738 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY); |
| 1739 | if (ret != 0) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1740 | dev_err(d->dev, "ASoC: Failed to apply standby bias: %d\n", |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1741 | ret); |
| 1742 | } |
| 1743 | |
| 1744 | /* If we're in standby and can support bias off then do that */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1745 | if (d->bias_level == SND_SOC_BIAS_STANDBY && |
| 1746 | d->target_bias_level == SND_SOC_BIAS_OFF) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1747 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF); |
| 1748 | if (ret != 0) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1749 | dev_err(d->dev, "ASoC: Failed to turn off bias: %d\n", |
| 1750 | ret); |
Mark Brown | f1aac48 | 2011-12-05 15:17:06 +0000 | [diff] [blame] | 1751 | |
| 1752 | if (d->dev) |
Mark Brown | fb644e9 | 2012-01-25 19:53:58 +0000 | [diff] [blame] | 1753 | pm_runtime_put(d->dev); |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | /* If we just powered up then move to active bias */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1757 | if (d->bias_level == SND_SOC_BIAS_PREPARE && |
| 1758 | d->target_bias_level == SND_SOC_BIAS_ON) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1759 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON); |
| 1760 | if (ret != 0) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 1761 | dev_err(d->dev, "ASoC: Failed to apply active bias: %d\n", |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1762 | ret); |
| 1763 | } |
| 1764 | } |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1765 | |
Mark Brown | fe4fda5 | 2011-10-03 22:36:57 +0100 | [diff] [blame] | 1766 | static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget *peer, |
| 1767 | bool power, bool connect) |
| 1768 | { |
| 1769 | /* If a connection is being made or broken then that update |
| 1770 | * will have marked the peer dirty, otherwise the widgets are |
| 1771 | * not connected and this update has no impact. */ |
| 1772 | if (!connect) |
| 1773 | return; |
| 1774 | |
| 1775 | /* If the peer is already in the state we're moving to then we |
| 1776 | * won't have an impact on it. */ |
| 1777 | if (power != peer->power) |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1778 | dapm_mark_dirty(peer, "peer state change"); |
Mark Brown | fe4fda5 | 2011-10-03 22:36:57 +0100 | [diff] [blame] | 1779 | } |
| 1780 | |
Mark Brown | 05623c4 | 2011-09-28 17:02:31 +0100 | [diff] [blame] | 1781 | static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power, |
| 1782 | struct list_head *up_list, |
| 1783 | struct list_head *down_list) |
| 1784 | { |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1785 | struct snd_soc_dapm_path *path; |
| 1786 | |
Mark Brown | 05623c4 | 2011-09-28 17:02:31 +0100 | [diff] [blame] | 1787 | if (w->power == power) |
| 1788 | return; |
| 1789 | |
| 1790 | trace_snd_soc_dapm_widget_power(w, power); |
| 1791 | |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1792 | /* If we changed our power state perhaps our neigbours changed |
Mark Brown | fe4fda5 | 2011-10-03 22:36:57 +0100 | [diff] [blame] | 1793 | * also. |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1794 | */ |
Lars-Peter Clausen | e63bfd4 | 2015-07-26 19:05:00 +0200 | [diff] [blame] | 1795 | snd_soc_dapm_widget_for_each_source_path(w, path) |
Lars-Peter Clausen | 7ddd4cd | 2014-10-20 19:36:34 +0200 | [diff] [blame] | 1796 | dapm_widget_set_peer_power(path->source, power, path->connect); |
| 1797 | |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 1798 | /* Supplies can't affect their outputs, only their inputs */ |
| 1799 | if (!w->is_supply) { |
Lars-Peter Clausen | e63bfd4 | 2015-07-26 19:05:00 +0200 | [diff] [blame] | 1800 | snd_soc_dapm_widget_for_each_sink_path(w, path) |
Lars-Peter Clausen | 7ddd4cd | 2014-10-20 19:36:34 +0200 | [diff] [blame] | 1801 | dapm_widget_set_peer_power(path->sink, power, |
| 1802 | path->connect); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1803 | } |
| 1804 | |
Mark Brown | 05623c4 | 2011-09-28 17:02:31 +0100 | [diff] [blame] | 1805 | if (power) |
| 1806 | dapm_seq_insert(w, up_list, true); |
| 1807 | else |
| 1808 | dapm_seq_insert(w, down_list, false); |
Mark Brown | 05623c4 | 2011-09-28 17:02:31 +0100 | [diff] [blame] | 1809 | } |
| 1810 | |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1811 | static void dapm_power_one_widget(struct snd_soc_dapm_widget *w, |
| 1812 | struct list_head *up_list, |
| 1813 | struct list_head *down_list) |
| 1814 | { |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1815 | int power; |
| 1816 | |
| 1817 | switch (w->id) { |
| 1818 | case snd_soc_dapm_pre: |
| 1819 | dapm_seq_insert(w, down_list, false); |
| 1820 | break; |
| 1821 | case snd_soc_dapm_post: |
| 1822 | dapm_seq_insert(w, up_list, true); |
| 1823 | break; |
| 1824 | |
| 1825 | default: |
Mark Brown | d805002b | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 1826 | power = dapm_widget_power_check(w); |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1827 | |
Mark Brown | 05623c4 | 2011-09-28 17:02:31 +0100 | [diff] [blame] | 1828 | dapm_widget_set_power(w, power, up_list, down_list); |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1829 | break; |
| 1830 | } |
| 1831 | } |
| 1832 | |
Lars-Peter Clausen | 86dbf2a | 2014-09-04 19:44:06 +0200 | [diff] [blame] | 1833 | static bool dapm_idle_bias_off(struct snd_soc_dapm_context *dapm) |
| 1834 | { |
| 1835 | if (dapm->idle_bias_off) |
| 1836 | return true; |
| 1837 | |
| 1838 | switch (snd_power_get_state(dapm->card->snd_card)) { |
| 1839 | case SNDRV_CTL_POWER_D3hot: |
| 1840 | case SNDRV_CTL_POWER_D3cold: |
| 1841 | return dapm->suspend_bias_off; |
| 1842 | default: |
| 1843 | break; |
| 1844 | } |
| 1845 | |
| 1846 | return false; |
| 1847 | } |
| 1848 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1849 | /* |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1850 | * Scan each dapm widget for complete audio path. |
| 1851 | * A complete path is a route that has valid endpoints i.e.:- |
| 1852 | * |
| 1853 | * o DAC to output pin. |
Peter Meerwald-Stadler | c804600 | 2016-08-16 16:56:17 +0200 | [diff] [blame] | 1854 | * o Input pin to ADC. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1855 | * o Input pin to Output pin (bypass, sidetone) |
| 1856 | * o DAC to ADC (loopback). |
| 1857 | */ |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1858 | static int dapm_power_widgets(struct snd_soc_card *card, int event) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1859 | { |
| 1860 | struct snd_soc_dapm_widget *w; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1861 | struct snd_soc_dapm_context *d; |
Mark Brown | 291f3bb | 2009-06-07 13:57:17 +0100 | [diff] [blame] | 1862 | LIST_HEAD(up_list); |
| 1863 | LIST_HEAD(down_list); |
Dan Williams | 2955b47 | 2012-07-09 19:33:25 -0700 | [diff] [blame] | 1864 | ASYNC_DOMAIN_EXCLUSIVE(async_domain); |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1865 | enum snd_soc_bias_level bias; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1866 | |
Mark Brown | f9fa2b1 | 2014-03-06 16:49:11 +0800 | [diff] [blame] | 1867 | lockdep_assert_held(&card->dapm_mutex); |
| 1868 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1869 | trace_snd_soc_dapm_start(card); |
| 1870 | |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1871 | list_for_each_entry(d, &card->dapm_list, list) { |
Lars-Peter Clausen | 86dbf2a | 2014-09-04 19:44:06 +0200 | [diff] [blame] | 1872 | if (dapm_idle_bias_off(d)) |
Mark Brown | 497098be | 2012-03-08 15:06:09 +0000 | [diff] [blame] | 1873 | d->target_bias_level = SND_SOC_BIAS_OFF; |
| 1874 | else |
| 1875 | d->target_bias_level = SND_SOC_BIAS_STANDBY; |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1876 | } |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1877 | |
Liam Girdwood | 6c120e1 | 2012-02-15 15:15:34 +0000 | [diff] [blame] | 1878 | dapm_reset(card); |
Mark Brown | 9b8a83b | 2011-10-04 22:15:59 +0100 | [diff] [blame] | 1879 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1880 | /* Check which widgets we need to power and store them in |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1881 | * lists indicating if they should be powered up or down. We |
| 1882 | * only check widgets that have been flagged as dirty but note |
| 1883 | * that new widgets may be added to the dirty list while we |
| 1884 | * iterate. |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1885 | */ |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1886 | list_for_each_entry(w, &card->dapm_dirty, dirty) { |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1887 | dapm_power_one_widget(w, &up_list, &down_list); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1888 | } |
| 1889 | |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1890 | list_for_each_entry(w, &card->widgets, list) { |
Mark Brown | 0ff97eb | 2012-07-20 17:29:34 +0100 | [diff] [blame] | 1891 | switch (w->id) { |
| 1892 | case snd_soc_dapm_pre: |
| 1893 | case snd_soc_dapm_post: |
| 1894 | /* These widgets always need to be powered */ |
| 1895 | break; |
| 1896 | default: |
| 1897 | list_del_init(&w->dirty); |
| 1898 | break; |
| 1899 | } |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1900 | |
Lars-Peter Clausen | 39eb5fd | 2013-07-29 17:14:03 +0200 | [diff] [blame] | 1901 | if (w->new_power) { |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1902 | d = w->dapm; |
| 1903 | |
| 1904 | /* Supplies and micbiases only bring the |
| 1905 | * context up to STANDBY as unless something |
| 1906 | * else is active and passing audio they |
Mark Brown | afe6236 | 2012-01-25 19:55:22 +0000 | [diff] [blame] | 1907 | * generally don't require full power. Signal |
| 1908 | * generators are virtual pins and have no |
| 1909 | * power impact themselves. |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1910 | */ |
| 1911 | switch (w->id) { |
Mark Brown | afe6236 | 2012-01-25 19:55:22 +0000 | [diff] [blame] | 1912 | case snd_soc_dapm_siggen: |
Lars-Peter Clausen | da83fea | 2013-10-05 19:26:17 +0200 | [diff] [blame] | 1913 | case snd_soc_dapm_vmid: |
Mark Brown | afe6236 | 2012-01-25 19:55:22 +0000 | [diff] [blame] | 1914 | break; |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1915 | case snd_soc_dapm_supply: |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 1916 | case snd_soc_dapm_regulator_supply: |
Srinivas Kandagatla | 5b2d15b | 2018-03-10 02:37:27 +0000 | [diff] [blame] | 1917 | case snd_soc_dapm_pinctrl: |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 1918 | case snd_soc_dapm_clock_supply: |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1919 | case snd_soc_dapm_micbias: |
| 1920 | if (d->target_bias_level < SND_SOC_BIAS_STANDBY) |
| 1921 | d->target_bias_level = SND_SOC_BIAS_STANDBY; |
| 1922 | break; |
| 1923 | default: |
| 1924 | d->target_bias_level = SND_SOC_BIAS_ON; |
| 1925 | break; |
| 1926 | } |
| 1927 | } |
| 1928 | |
| 1929 | } |
| 1930 | |
Mark Brown | 85a843c | 2011-09-21 21:29:47 +0100 | [diff] [blame] | 1931 | /* Force all contexts in the card to the same bias state if |
| 1932 | * they're not ground referenced. |
| 1933 | */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1934 | bias = SND_SOC_BIAS_OFF; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1935 | list_for_each_entry(d, &card->dapm_list, list) |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1936 | if (d->target_bias_level > bias) |
| 1937 | bias = d->target_bias_level; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1938 | list_for_each_entry(d, &card->dapm_list, list) |
Lars-Peter Clausen | 86dbf2a | 2014-09-04 19:44:06 +0200 | [diff] [blame] | 1939 | if (!dapm_idle_bias_off(d)) |
Mark Brown | 85a843c | 2011-09-21 21:29:47 +0100 | [diff] [blame] | 1940 | d->target_bias_level = bias; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1941 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 1942 | trace_snd_soc_dapm_walk_done(card); |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1943 | |
Xiang Xiao | 17282ba | 2014-03-02 00:04:03 +0800 | [diff] [blame] | 1944 | /* Run card bias changes at first */ |
| 1945 | dapm_pre_sequence_async(&card->dapm, 0); |
| 1946 | /* Run other bias changes in parallel */ |
| 1947 | list_for_each_entry(d, &card->dapm_list, list) { |
Jon Hunter | e03546d | 2018-08-17 16:35:43 +0100 | [diff] [blame] | 1948 | if (d != &card->dapm && d->bias_level != d->target_bias_level) |
Xiang Xiao | 17282ba | 2014-03-02 00:04:03 +0800 | [diff] [blame] | 1949 | async_schedule_domain(dapm_pre_sequence_async, d, |
| 1950 | &async_domain); |
| 1951 | } |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1952 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1953 | |
Lars-Peter Clausen | cf1f7c6 | 2013-05-23 00:12:53 +0200 | [diff] [blame] | 1954 | list_for_each_entry(w, &down_list, power_list) { |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1955 | dapm_seq_check_event(card, w, SND_SOC_DAPM_WILL_PMD); |
Mark Brown | 8011412 | 2013-02-25 15:14:19 +0000 | [diff] [blame] | 1956 | } |
| 1957 | |
Lars-Peter Clausen | cf1f7c6 | 2013-05-23 00:12:53 +0200 | [diff] [blame] | 1958 | list_for_each_entry(w, &up_list, power_list) { |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1959 | dapm_seq_check_event(card, w, SND_SOC_DAPM_WILL_PMU); |
Mark Brown | 8011412 | 2013-02-25 15:14:19 +0000 | [diff] [blame] | 1960 | } |
| 1961 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1962 | /* Power down widgets first; try to avoid amplifying pops. */ |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1963 | dapm_seq_run(card, &down_list, event, false); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1964 | |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1965 | dapm_widget_update(card); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1966 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1967 | /* Now power up. */ |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1968 | dapm_seq_run(card, &up_list, event, true); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1969 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1970 | /* Run all the bias changes in parallel */ |
Xiang Xiao | 17282ba | 2014-03-02 00:04:03 +0800 | [diff] [blame] | 1971 | list_for_each_entry(d, &card->dapm_list, list) { |
Jon Hunter | e03546d | 2018-08-17 16:35:43 +0100 | [diff] [blame] | 1972 | if (d != &card->dapm && d->bias_level != d->target_bias_level) |
Xiang Xiao | 17282ba | 2014-03-02 00:04:03 +0800 | [diff] [blame] | 1973 | async_schedule_domain(dapm_post_sequence_async, d, |
| 1974 | &async_domain); |
| 1975 | } |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1976 | async_synchronize_full_domain(&async_domain); |
Xiang Xiao | 17282ba | 2014-03-02 00:04:03 +0800 | [diff] [blame] | 1977 | /* Run card bias changes at last */ |
| 1978 | dapm_post_sequence_async(&card->dapm, 0); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1979 | |
Liam Girdwood | 8078d87 | 2012-02-15 15:15:35 +0000 | [diff] [blame] | 1980 | /* do we need to notify any clients that DAPM event is complete */ |
| 1981 | list_for_each_entry(d, &card->dapm_list, list) { |
| 1982 | if (d->stream_event) |
| 1983 | d->stream_event(d, event); |
| 1984 | } |
| 1985 | |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 1986 | pop_dbg(card->dev, card->pop_time, |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 1987 | "DAPM sequencing finished, waiting %dms\n", card->pop_time); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1988 | pop_wait(card->pop_time); |
Mark Brown | cb507e7 | 2009-07-08 18:54:57 +0100 | [diff] [blame] | 1989 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1990 | trace_snd_soc_dapm_done(card); |
| 1991 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1992 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1993 | } |
| 1994 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1995 | #ifdef CONFIG_DEBUG_FS |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1996 | static ssize_t dapm_widget_power_read_file(struct file *file, |
| 1997 | char __user *user_buf, |
| 1998 | size_t count, loff_t *ppos) |
| 1999 | { |
| 2000 | struct snd_soc_dapm_widget *w = file->private_data; |
Lars-Peter Clausen | e50b1e0 | 2015-07-06 17:01:24 +0200 | [diff] [blame] | 2001 | struct snd_soc_card *card = w->dapm->card; |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2002 | enum snd_soc_dapm_direction dir, rdir; |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2003 | char *buf; |
| 2004 | int in, out; |
| 2005 | ssize_t ret; |
| 2006 | struct snd_soc_dapm_path *p = NULL; |
| 2007 | |
| 2008 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 2009 | if (!buf) |
| 2010 | return -ENOMEM; |
| 2011 | |
Lars-Peter Clausen | e50b1e0 | 2015-07-06 17:01:24 +0200 | [diff] [blame] | 2012 | mutex_lock(&card->dapm_mutex); |
| 2013 | |
Lars-Peter Clausen | c1862c8 | 2014-10-25 17:42:00 +0200 | [diff] [blame] | 2014 | /* Supply widgets are not handled by is_connected_{input,output}_ep() */ |
| 2015 | if (w->is_supply) { |
| 2016 | in = 0; |
| 2017 | out = 0; |
| 2018 | } else { |
Piotr Stankiewicz | 6742064 | 2016-05-13 17:03:55 +0100 | [diff] [blame] | 2019 | in = is_connected_input_ep(w, NULL, NULL); |
| 2020 | out = is_connected_output_ep(w, NULL, NULL); |
Lars-Peter Clausen | c1862c8 | 2014-10-25 17:42:00 +0200 | [diff] [blame] | 2021 | } |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2022 | |
Mark Brown | f13ebad | 2012-03-03 18:01:01 +0000 | [diff] [blame] | 2023 | ret = snprintf(buf, PAGE_SIZE, "%s: %s%s in %d out %d", |
| 2024 | w->name, w->power ? "On" : "Off", |
| 2025 | w->force ? " (forced)" : "", in, out); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2026 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 2027 | if (w->reg >= 0) |
| 2028 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Lars-Peter Clausen | de9ba98 | 2013-07-29 17:14:01 +0200 | [diff] [blame] | 2029 | " - R%d(0x%x) mask 0x%x", |
| 2030 | w->reg, w->reg, w->mask << w->shift); |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 2031 | |
| 2032 | ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n"); |
| 2033 | |
Mark Brown | 3eef08b | 2009-09-14 16:49:00 +0100 | [diff] [blame] | 2034 | if (w->sname) |
| 2035 | ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n", |
| 2036 | w->sname, |
| 2037 | w->active ? "active" : "inactive"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2038 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2039 | snd_soc_dapm_for_each_direction(dir) { |
| 2040 | rdir = SND_SOC_DAPM_DIR_REVERSE(dir); |
| 2041 | snd_soc_dapm_widget_for_each_path(w, dir, p) { |
KaiChieh Chuang | 28735af | 2018-02-05 13:00:00 +0800 | [diff] [blame] | 2042 | if (p->connected && !p->connected(p->source, p->sink)) |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2043 | continue; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 2044 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2045 | if (!p->connect) |
| 2046 | continue; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 2047 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2048 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2049 | " %s \"%s\" \"%s\"\n", |
| 2050 | (rdir == SND_SOC_DAPM_DIR_IN) ? "in" : "out", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2051 | p->name ? p->name : "static", |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2052 | p->node[rdir]->name); |
| 2053 | } |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2054 | } |
| 2055 | |
Lars-Peter Clausen | e50b1e0 | 2015-07-06 17:01:24 +0200 | [diff] [blame] | 2056 | mutex_unlock(&card->dapm_mutex); |
| 2057 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2058 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 2059 | |
| 2060 | kfree(buf); |
| 2061 | return ret; |
| 2062 | } |
| 2063 | |
| 2064 | static const struct file_operations dapm_widget_power_fops = { |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 2065 | .open = simple_open, |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2066 | .read = dapm_widget_power_read_file, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 2067 | .llseek = default_llseek, |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2068 | }; |
| 2069 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 2070 | static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf, |
| 2071 | size_t count, loff_t *ppos) |
| 2072 | { |
| 2073 | struct snd_soc_dapm_context *dapm = file->private_data; |
| 2074 | char *level; |
| 2075 | |
| 2076 | switch (dapm->bias_level) { |
| 2077 | case SND_SOC_BIAS_ON: |
| 2078 | level = "On\n"; |
| 2079 | break; |
| 2080 | case SND_SOC_BIAS_PREPARE: |
| 2081 | level = "Prepare\n"; |
| 2082 | break; |
| 2083 | case SND_SOC_BIAS_STANDBY: |
| 2084 | level = "Standby\n"; |
| 2085 | break; |
| 2086 | case SND_SOC_BIAS_OFF: |
| 2087 | level = "Off\n"; |
| 2088 | break; |
| 2089 | default: |
Takashi Iwai | a6ed060 | 2013-11-06 11:07:19 +0100 | [diff] [blame] | 2090 | WARN(1, "Unknown bias_level %d\n", dapm->bias_level); |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 2091 | level = "Unknown\n"; |
| 2092 | break; |
| 2093 | } |
| 2094 | |
| 2095 | return simple_read_from_buffer(user_buf, count, ppos, level, |
| 2096 | strlen(level)); |
| 2097 | } |
| 2098 | |
| 2099 | static const struct file_operations dapm_bias_fops = { |
Stephen Boyd | 234e340 | 2012-04-05 14:25:11 -0700 | [diff] [blame] | 2100 | .open = simple_open, |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 2101 | .read = dapm_bias_read_file, |
| 2102 | .llseek = default_llseek, |
| 2103 | }; |
| 2104 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 2105 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 2106 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2107 | { |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2108 | struct dentry *d; |
| 2109 | |
Lars-Peter Clausen | 6553bf06 | 2015-04-09 10:52:38 +0200 | [diff] [blame] | 2110 | if (!parent) |
| 2111 | return; |
| 2112 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 2113 | dapm->debugfs_dapm = debugfs_create_dir("dapm", parent); |
| 2114 | |
| 2115 | if (!dapm->debugfs_dapm) { |
Liam Girdwood | f1e90af | 2012-03-06 18:13:25 +0000 | [diff] [blame] | 2116 | dev_warn(dapm->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2117 | "ASoC: Failed to create DAPM debugfs directory\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2118 | return; |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 2119 | } |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2120 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 2121 | d = debugfs_create_file("bias_level", 0444, |
| 2122 | dapm->debugfs_dapm, dapm, |
| 2123 | &dapm_bias_fops); |
| 2124 | if (!d) |
| 2125 | dev_warn(dapm->dev, |
| 2126 | "ASoC: Failed to create bias level debugfs file\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2127 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 2128 | |
| 2129 | static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 2130 | { |
| 2131 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 2132 | struct dentry *d; |
| 2133 | |
| 2134 | if (!dapm->debugfs_dapm || !w->name) |
| 2135 | return; |
| 2136 | |
| 2137 | d = debugfs_create_file(w->name, 0444, |
| 2138 | dapm->debugfs_dapm, w, |
| 2139 | &dapm_widget_power_fops); |
| 2140 | if (!d) |
| 2141 | dev_warn(w->dapm->dev, |
| 2142 | "ASoC: Failed to create %s debugfs file\n", |
| 2143 | w->name); |
| 2144 | } |
| 2145 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 2146 | static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 2147 | { |
| 2148 | debugfs_remove_recursive(dapm->debugfs_dapm); |
| 2149 | } |
| 2150 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2151 | #else |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 2152 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 2153 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2154 | { |
| 2155 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 2156 | |
| 2157 | static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 2158 | { |
| 2159 | } |
| 2160 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 2161 | static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 2162 | { |
| 2163 | } |
| 2164 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 2165 | #endif |
| 2166 | |
Lars-Peter Clausen | 4a20194 | 2014-10-25 17:41:56 +0200 | [diff] [blame] | 2167 | /* |
| 2168 | * soc_dapm_connect_path() - Connects or disconnects a path |
| 2169 | * @path: The path to update |
| 2170 | * @connect: The new connect state of the path. True if the path is connected, |
Peter Meerwald-Stadler | c804600 | 2016-08-16 16:56:17 +0200 | [diff] [blame] | 2171 | * false if it is disconnected. |
Lars-Peter Clausen | 4a20194 | 2014-10-25 17:41:56 +0200 | [diff] [blame] | 2172 | * @reason: The reason why the path changed (for debugging only) |
| 2173 | */ |
| 2174 | static void soc_dapm_connect_path(struct snd_soc_dapm_path *path, |
| 2175 | bool connect, const char *reason) |
| 2176 | { |
| 2177 | if (path->connect == connect) |
| 2178 | return; |
| 2179 | |
| 2180 | path->connect = connect; |
| 2181 | dapm_mark_dirty(path->source, reason); |
| 2182 | dapm_mark_dirty(path->sink, reason); |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 2183 | dapm_path_invalidate(path); |
Lars-Peter Clausen | 4a20194 | 2014-10-25 17:41:56 +0200 | [diff] [blame] | 2184 | } |
| 2185 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2186 | /* test and update the power status of a mux widget */ |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 2187 | static int soc_dapm_mux_update_power(struct snd_soc_card *card, |
Liam Girdwood | 40f02cd | 2012-02-06 16:05:14 +0000 | [diff] [blame] | 2188 | struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2189 | { |
| 2190 | struct snd_soc_dapm_path *path; |
| 2191 | int found = 0; |
Lars-Peter Clausen | 4a20194 | 2014-10-25 17:41:56 +0200 | [diff] [blame] | 2192 | bool connect; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2193 | |
Mark Brown | f9fa2b1 | 2014-03-06 16:49:11 +0800 | [diff] [blame] | 2194 | lockdep_assert_held(&card->dapm_mutex); |
| 2195 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2196 | /* find dapm widget path assoc with kcontrol */ |
Lars-Peter Clausen | 5106b92 | 2013-07-29 17:14:00 +0200 | [diff] [blame] | 2197 | dapm_kcontrol_for_each_path(path, kcontrol) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2198 | found = 1; |
| 2199 | /* we now need to match the string in the enum to the path */ |
Lars-Peter Clausen | 4a20194 | 2014-10-25 17:41:56 +0200 | [diff] [blame] | 2200 | if (!(strcmp(path->name, e->texts[mux]))) |
| 2201 | connect = true; |
| 2202 | else |
| 2203 | connect = false; |
| 2204 | |
| 2205 | soc_dapm_connect_path(path, connect, "mux update"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2206 | } |
| 2207 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame] | 2208 | if (found) |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 2209 | dapm_power_widgets(card, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2210 | |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2211 | return found; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2212 | } |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2213 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame] | 2214 | int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_context *dapm, |
Lars-Peter Clausen | 6b3fc03 | 2013-07-24 15:27:38 +0200 | [diff] [blame] | 2215 | struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e, |
| 2216 | struct snd_soc_dapm_update *update) |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2217 | { |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame] | 2218 | struct snd_soc_card *card = dapm->card; |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2219 | int ret; |
| 2220 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 2221 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Lars-Peter Clausen | 564c6504 | 2013-07-29 17:13:55 +0200 | [diff] [blame] | 2222 | card->update = update; |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 2223 | ret = soc_dapm_mux_update_power(card, kcontrol, mux, e); |
Lars-Peter Clausen | 564c6504 | 2013-07-29 17:13:55 +0200 | [diff] [blame] | 2224 | card->update = NULL; |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2225 | mutex_unlock(&card->dapm_mutex); |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2226 | if (ret > 0) |
Lars-Peter Clausen | c3f48ae | 2013-07-24 15:27:36 +0200 | [diff] [blame] | 2227 | soc_dpcm_runtime_update(card); |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2228 | return ret; |
| 2229 | } |
Liam Girdwood | 40f02cd | 2012-02-06 16:05:14 +0000 | [diff] [blame] | 2230 | EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2231 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 2232 | /* test and update the power status of a mixer or switch widget */ |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 2233 | static int soc_dapm_mixer_update_power(struct snd_soc_card *card, |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 2234 | struct snd_kcontrol *kcontrol, |
| 2235 | int connect, int rconnect) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2236 | { |
| 2237 | struct snd_soc_dapm_path *path; |
| 2238 | int found = 0; |
| 2239 | |
Mark Brown | f9fa2b1 | 2014-03-06 16:49:11 +0800 | [diff] [blame] | 2240 | lockdep_assert_held(&card->dapm_mutex); |
| 2241 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2242 | /* find dapm widget path assoc with kcontrol */ |
Lars-Peter Clausen | 5106b92 | 2013-07-29 17:14:00 +0200 | [diff] [blame] | 2243 | dapm_kcontrol_for_each_path(path, kcontrol) { |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 2244 | /* |
| 2245 | * Ideally this function should support any number of |
| 2246 | * paths and channels. But since kcontrols only come |
| 2247 | * in mono and stereo variants, we are limited to 2 |
| 2248 | * channels. |
| 2249 | * |
| 2250 | * The following code assumes for stereo controls the |
| 2251 | * first path (when 'found == 0') is the left channel, |
| 2252 | * and all remaining paths (when 'found == 1') are the |
| 2253 | * right channel. |
| 2254 | * |
| 2255 | * A stereo control is signified by a valid 'rconnect' |
| 2256 | * value, either 0 for unconnected, or >= 0 for connected. |
| 2257 | * This is chosen instead of using snd_soc_volsw_is_stereo, |
| 2258 | * so that the behavior of snd_soc_dapm_mixer_update_power |
| 2259 | * doesn't change even when the kcontrol passed in is |
| 2260 | * stereo. |
| 2261 | * |
| 2262 | * It passes 'connect' as the path connect status for |
| 2263 | * the left channel, and 'rconnect' for the right |
| 2264 | * channel. |
| 2265 | */ |
| 2266 | if (found && rconnect >= 0) |
| 2267 | soc_dapm_connect_path(path, rconnect, "mixer update"); |
| 2268 | else |
| 2269 | soc_dapm_connect_path(path, connect, "mixer update"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2270 | found = 1; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2271 | } |
| 2272 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame] | 2273 | if (found) |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 2274 | dapm_power_widgets(card, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2275 | |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2276 | return found; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2277 | } |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2278 | |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame] | 2279 | int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_context *dapm, |
Lars-Peter Clausen | 6b3fc03 | 2013-07-24 15:27:38 +0200 | [diff] [blame] | 2280 | struct snd_kcontrol *kcontrol, int connect, |
| 2281 | struct snd_soc_dapm_update *update) |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2282 | { |
Lars-Peter Clausen | ce6cfaf | 2013-07-24 15:27:37 +0200 | [diff] [blame] | 2283 | struct snd_soc_card *card = dapm->card; |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2284 | int ret; |
| 2285 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 2286 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Lars-Peter Clausen | 564c6504 | 2013-07-29 17:13:55 +0200 | [diff] [blame] | 2287 | card->update = update; |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 2288 | ret = soc_dapm_mixer_update_power(card, kcontrol, connect, -1); |
Lars-Peter Clausen | 564c6504 | 2013-07-29 17:13:55 +0200 | [diff] [blame] | 2289 | card->update = NULL; |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2290 | mutex_unlock(&card->dapm_mutex); |
Liam Girdwood | 618dae1 | 2012-04-25 12:12:51 +0100 | [diff] [blame] | 2291 | if (ret > 0) |
Lars-Peter Clausen | c3f48ae | 2013-07-24 15:27:36 +0200 | [diff] [blame] | 2292 | soc_dpcm_runtime_update(card); |
Liam Girdwood | 4edbb345 | 2012-03-07 10:38:27 +0000 | [diff] [blame] | 2293 | return ret; |
| 2294 | } |
Liam Girdwood | 40f02cd | 2012-02-06 16:05:14 +0000 | [diff] [blame] | 2295 | EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2296 | |
Lars-Peter Clausen | b3c25fb | 2015-07-06 15:38:10 +0200 | [diff] [blame] | 2297 | static ssize_t dapm_widget_show_component(struct snd_soc_component *cmpnt, |
| 2298 | char *buf) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2299 | { |
Lars-Peter Clausen | b3c25fb | 2015-07-06 15:38:10 +0200 | [diff] [blame] | 2300 | struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(cmpnt); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2301 | struct snd_soc_dapm_widget *w; |
| 2302 | int count = 0; |
| 2303 | char *state = "not set"; |
| 2304 | |
Mark Brown | 4732507 | 2016-03-18 12:04:23 +0000 | [diff] [blame] | 2305 | /* card won't be set for the dummy component, as a spot fix |
| 2306 | * we're checking for that case specifically here but in future |
| 2307 | * we will ensure that the dummy component looks like others. |
| 2308 | */ |
| 2309 | if (!cmpnt->card) |
| 2310 | return 0; |
| 2311 | |
Lars-Peter Clausen | b3c25fb | 2015-07-06 15:38:10 +0200 | [diff] [blame] | 2312 | list_for_each_entry(w, &cmpnt->card->widgets, list) { |
| 2313 | if (w->dapm != dapm) |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2314 | continue; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2315 | |
Peter Meerwald-Stadler | c804600 | 2016-08-16 16:56:17 +0200 | [diff] [blame] | 2316 | /* only display widgets that burn power */ |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2317 | switch (w->id) { |
| 2318 | case snd_soc_dapm_hp: |
| 2319 | case snd_soc_dapm_mic: |
| 2320 | case snd_soc_dapm_spk: |
| 2321 | case snd_soc_dapm_line: |
| 2322 | case snd_soc_dapm_micbias: |
| 2323 | case snd_soc_dapm_dac: |
| 2324 | case snd_soc_dapm_adc: |
| 2325 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 2326 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2327 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 2328 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 2329 | case snd_soc_dapm_supply: |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 2330 | case snd_soc_dapm_regulator_supply: |
Srinivas Kandagatla | 5b2d15b | 2018-03-10 02:37:27 +0000 | [diff] [blame] | 2331 | case snd_soc_dapm_pinctrl: |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 2332 | case snd_soc_dapm_clock_supply: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2333 | if (w->name) |
| 2334 | count += sprintf(buf + count, "%s: %s\n", |
| 2335 | w->name, w->power ? "On":"Off"); |
| 2336 | break; |
| 2337 | default: |
| 2338 | break; |
| 2339 | } |
| 2340 | } |
| 2341 | |
Lars-Peter Clausen | b3c25fb | 2015-07-06 15:38:10 +0200 | [diff] [blame] | 2342 | switch (snd_soc_dapm_get_bias_level(dapm)) { |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 2343 | case SND_SOC_BIAS_ON: |
| 2344 | state = "On"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2345 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 2346 | case SND_SOC_BIAS_PREPARE: |
| 2347 | state = "Prepare"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2348 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 2349 | case SND_SOC_BIAS_STANDBY: |
| 2350 | state = "Standby"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2351 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 2352 | case SND_SOC_BIAS_OFF: |
| 2353 | state = "Off"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2354 | break; |
| 2355 | } |
| 2356 | count += sprintf(buf + count, "PM State: %s\n", state); |
| 2357 | |
| 2358 | return count; |
| 2359 | } |
| 2360 | |
Benoit Cousson | 44ba264 | 2014-07-08 23:19:36 +0200 | [diff] [blame] | 2361 | /* show dapm widget status in sys fs */ |
| 2362 | static ssize_t dapm_widget_show(struct device *dev, |
| 2363 | struct device_attribute *attr, char *buf) |
| 2364 | { |
| 2365 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 2366 | struct snd_soc_dai *codec_dai; |
Benoit Cousson | 44ba264 | 2014-07-08 23:19:36 +0200 | [diff] [blame] | 2367 | int i, count = 0; |
| 2368 | |
Lars-Peter Clausen | e50b1e0 | 2015-07-06 17:01:24 +0200 | [diff] [blame] | 2369 | mutex_lock(&rtd->card->dapm_mutex); |
| 2370 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 2371 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
| 2372 | struct snd_soc_component *cmpnt = codec_dai->component; |
Lars-Peter Clausen | b3c25fb | 2015-07-06 15:38:10 +0200 | [diff] [blame] | 2373 | |
| 2374 | count += dapm_widget_show_component(cmpnt, buf + count); |
Benoit Cousson | 44ba264 | 2014-07-08 23:19:36 +0200 | [diff] [blame] | 2375 | } |
| 2376 | |
Lars-Peter Clausen | e50b1e0 | 2015-07-06 17:01:24 +0200 | [diff] [blame] | 2377 | mutex_unlock(&rtd->card->dapm_mutex); |
| 2378 | |
Benoit Cousson | 44ba264 | 2014-07-08 23:19:36 +0200 | [diff] [blame] | 2379 | return count; |
| 2380 | } |
| 2381 | |
Joe Perches | c828a89 | 2017-12-19 10:15:08 -0800 | [diff] [blame] | 2382 | static DEVICE_ATTR_RO(dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2383 | |
Takashi Iwai | d29697d | 2015-01-30 20:16:37 +0100 | [diff] [blame] | 2384 | struct attribute *soc_dapm_dev_attrs[] = { |
| 2385 | &dev_attr_dapm_widget.attr, |
| 2386 | NULL |
| 2387 | }; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2388 | |
Lars-Peter Clausen | 8872293 | 2013-06-14 13:16:53 +0200 | [diff] [blame] | 2389 | static void dapm_free_path(struct snd_soc_dapm_path *path) |
| 2390 | { |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2391 | list_del(&path->list_node[SND_SOC_DAPM_DIR_IN]); |
| 2392 | list_del(&path->list_node[SND_SOC_DAPM_DIR_OUT]); |
Lars-Peter Clausen | 5106b92 | 2013-07-29 17:14:00 +0200 | [diff] [blame] | 2393 | list_del(&path->list_kcontrol); |
Lars-Peter Clausen | 8872293 | 2013-06-14 13:16:53 +0200 | [diff] [blame] | 2394 | list_del(&path->list); |
Lars-Peter Clausen | 8872293 | 2013-06-14 13:16:53 +0200 | [diff] [blame] | 2395 | kfree(path); |
| 2396 | } |
| 2397 | |
Lars-Peter Clausen | b97e269 | 2015-07-21 18:11:07 +0200 | [diff] [blame] | 2398 | void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w) |
| 2399 | { |
| 2400 | struct snd_soc_dapm_path *p, *next_p; |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2401 | enum snd_soc_dapm_direction dir; |
Lars-Peter Clausen | b97e269 | 2015-07-21 18:11:07 +0200 | [diff] [blame] | 2402 | |
| 2403 | list_del(&w->list); |
| 2404 | /* |
| 2405 | * remove source and sink paths associated to this widget. |
| 2406 | * While removing the path, remove reference to it from both |
| 2407 | * source and sink widgets so that path is removed only once. |
| 2408 | */ |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2409 | snd_soc_dapm_for_each_direction(dir) { |
| 2410 | snd_soc_dapm_widget_for_each_path_safe(w, dir, p, next_p) |
| 2411 | dapm_free_path(p); |
| 2412 | } |
Lars-Peter Clausen | b97e269 | 2015-07-21 18:11:07 +0200 | [diff] [blame] | 2413 | |
| 2414 | kfree(w->kcontrols); |
Lars-Peter Clausen | 4806896 | 2015-07-21 18:11:08 +0200 | [diff] [blame] | 2415 | kfree_const(w->name); |
Lars-Peter Clausen | b97e269 | 2015-07-21 18:11:07 +0200 | [diff] [blame] | 2416 | kfree(w); |
| 2417 | } |
| 2418 | |
Jyri Sarha | fd589a1 | 2015-11-10 18:12:42 +0200 | [diff] [blame] | 2419 | void snd_soc_dapm_reset_cache(struct snd_soc_dapm_context *dapm) |
| 2420 | { |
| 2421 | dapm->path_sink_cache.widget = NULL; |
| 2422 | dapm->path_source_cache.widget = NULL; |
| 2423 | } |
| 2424 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2425 | /* free all dapm widgets and resources */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2426 | static void dapm_free_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2427 | { |
| 2428 | struct snd_soc_dapm_widget *w, *next_w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2429 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2430 | list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) { |
| 2431 | if (w->dapm != dapm) |
| 2432 | continue; |
Lars-Peter Clausen | b97e269 | 2015-07-21 18:11:07 +0200 | [diff] [blame] | 2433 | snd_soc_dapm_free_widget(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2434 | } |
Jyri Sarha | fd589a1 | 2015-11-10 18:12:42 +0200 | [diff] [blame] | 2435 | snd_soc_dapm_reset_cache(dapm); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2436 | } |
| 2437 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2438 | static struct snd_soc_dapm_widget *dapm_find_widget( |
| 2439 | struct snd_soc_dapm_context *dapm, const char *pin, |
| 2440 | bool search_other_contexts) |
| 2441 | { |
| 2442 | struct snd_soc_dapm_widget *w; |
| 2443 | struct snd_soc_dapm_widget *fallback = NULL; |
| 2444 | |
| 2445 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 2446 | if (!strcmp(w->name, pin)) { |
| 2447 | if (w->dapm == dapm) |
| 2448 | return w; |
| 2449 | else |
| 2450 | fallback = w; |
| 2451 | } |
| 2452 | } |
| 2453 | |
| 2454 | if (search_other_contexts) |
| 2455 | return fallback; |
| 2456 | |
| 2457 | return NULL; |
| 2458 | } |
| 2459 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2460 | static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm, |
Mark Brown | 1649923 | 2009-01-07 18:25:13 +0000 | [diff] [blame] | 2461 | const char *pin, int status) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2462 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2463 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2464 | |
Mark Brown | f9fa2b1 | 2014-03-06 16:49:11 +0800 | [diff] [blame] | 2465 | dapm_assert_locked(dapm); |
| 2466 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2467 | if (!w) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2468 | dev_err(dapm->dev, "ASoC: DAPM unknown pin %s\n", pin); |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2469 | return -EINVAL; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2470 | } |
| 2471 | |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 2472 | if (w->connected != status) { |
Mark Brown | 1a8b2d9 | 2012-02-16 11:50:07 -0800 | [diff] [blame] | 2473 | dapm_mark_dirty(w, "pin configuration"); |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 2474 | dapm_widget_invalidate_input_paths(w); |
| 2475 | dapm_widget_invalidate_output_paths(w); |
| 2476 | } |
Mark Brown | 1a8b2d9 | 2012-02-16 11:50:07 -0800 | [diff] [blame] | 2477 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2478 | w->connected = status; |
| 2479 | if (status == 0) |
| 2480 | w->force = 0; |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 2481 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2482 | return 0; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2483 | } |
| 2484 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2485 | /** |
Charles Keepax | 3eb29df | 2014-02-18 15:22:15 +0000 | [diff] [blame] | 2486 | * snd_soc_dapm_sync_unlocked - scan and power dapm paths |
| 2487 | * @dapm: DAPM context |
| 2488 | * |
| 2489 | * Walks all dapm audio paths and powers widgets according to their |
| 2490 | * stream or path usage. |
| 2491 | * |
| 2492 | * Requires external locking. |
| 2493 | * |
| 2494 | * Returns 0 for success. |
| 2495 | */ |
| 2496 | int snd_soc_dapm_sync_unlocked(struct snd_soc_dapm_context *dapm) |
| 2497 | { |
| 2498 | /* |
| 2499 | * Suppress early reports (eg, jacks syncing their state) to avoid |
| 2500 | * silly DAPM runs during card startup. |
| 2501 | */ |
| 2502 | if (!dapm->card || !dapm->card->instantiated) |
| 2503 | return 0; |
| 2504 | |
| 2505 | return dapm_power_widgets(dapm->card, SND_SOC_DAPM_STREAM_NOP); |
| 2506 | } |
| 2507 | EXPORT_SYMBOL_GPL(snd_soc_dapm_sync_unlocked); |
| 2508 | |
| 2509 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2510 | * snd_soc_dapm_sync - scan and power dapm paths |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2511 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2512 | * |
| 2513 | * Walks all dapm audio paths and powers widgets according to their |
| 2514 | * stream or path usage. |
| 2515 | * |
| 2516 | * Returns 0 for success. |
| 2517 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2518 | int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2519 | { |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2520 | int ret; |
| 2521 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 2522 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Charles Keepax | 3eb29df | 2014-02-18 15:22:15 +0000 | [diff] [blame] | 2523 | ret = snd_soc_dapm_sync_unlocked(dapm); |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2524 | mutex_unlock(&dapm->card->dapm_mutex); |
| 2525 | return ret; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2526 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2527 | EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2528 | |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 2529 | /* |
| 2530 | * dapm_update_widget_flags() - Re-compute widget sink and source flags |
| 2531 | * @w: The widget for which to update the flags |
| 2532 | * |
| 2533 | * Some widgets have a dynamic category which depends on which neighbors they |
| 2534 | * are connected to. This function update the category for these widgets. |
| 2535 | * |
| 2536 | * This function must be called whenever a path is added or removed to a widget. |
| 2537 | */ |
| 2538 | static void dapm_update_widget_flags(struct snd_soc_dapm_widget *w) |
| 2539 | { |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2540 | enum snd_soc_dapm_direction dir; |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 2541 | struct snd_soc_dapm_path *p; |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2542 | unsigned int ep; |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 2543 | |
| 2544 | switch (w->id) { |
| 2545 | case snd_soc_dapm_input: |
Peter Meerwald-Stadler | c804600 | 2016-08-16 16:56:17 +0200 | [diff] [blame] | 2546 | /* On a fully routed card an input is never a source */ |
Lars-Peter Clausen | 86d7500 | 2014-12-21 11:05:44 +0100 | [diff] [blame] | 2547 | if (w->dapm->card->fully_routed) |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2548 | return; |
| 2549 | ep = SND_SOC_DAPM_EP_SOURCE; |
Lars-Peter Clausen | e63bfd4 | 2015-07-26 19:05:00 +0200 | [diff] [blame] | 2550 | snd_soc_dapm_widget_for_each_source_path(w, p) { |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 2551 | if (p->source->id == snd_soc_dapm_micbias || |
| 2552 | p->source->id == snd_soc_dapm_mic || |
| 2553 | p->source->id == snd_soc_dapm_line || |
| 2554 | p->source->id == snd_soc_dapm_output) { |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2555 | ep = 0; |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 2556 | break; |
| 2557 | } |
| 2558 | } |
| 2559 | break; |
| 2560 | case snd_soc_dapm_output: |
Lars-Peter Clausen | 86d7500 | 2014-12-21 11:05:44 +0100 | [diff] [blame] | 2561 | /* On a fully routed card a output is never a sink */ |
| 2562 | if (w->dapm->card->fully_routed) |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2563 | return; |
| 2564 | ep = SND_SOC_DAPM_EP_SINK; |
Lars-Peter Clausen | e63bfd4 | 2015-07-26 19:05:00 +0200 | [diff] [blame] | 2565 | snd_soc_dapm_widget_for_each_sink_path(w, p) { |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 2566 | if (p->sink->id == snd_soc_dapm_spk || |
| 2567 | p->sink->id == snd_soc_dapm_hp || |
| 2568 | p->sink->id == snd_soc_dapm_line || |
| 2569 | p->sink->id == snd_soc_dapm_input) { |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2570 | ep = 0; |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 2571 | break; |
| 2572 | } |
| 2573 | } |
| 2574 | break; |
| 2575 | case snd_soc_dapm_line: |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2576 | ep = 0; |
| 2577 | snd_soc_dapm_for_each_direction(dir) { |
| 2578 | if (!list_empty(&w->edges[dir])) |
| 2579 | ep |= SND_SOC_DAPM_DIR_TO_EP(dir); |
| 2580 | } |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 2581 | break; |
| 2582 | default: |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2583 | return; |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 2584 | } |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2585 | |
| 2586 | w->is_ep = ep; |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 2587 | } |
| 2588 | |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 2589 | static int snd_soc_dapm_check_dynamic_path(struct snd_soc_dapm_context *dapm, |
| 2590 | struct snd_soc_dapm_widget *source, struct snd_soc_dapm_widget *sink, |
| 2591 | const char *control) |
| 2592 | { |
| 2593 | bool dynamic_source = false; |
| 2594 | bool dynamic_sink = false; |
| 2595 | |
| 2596 | if (!control) |
| 2597 | return 0; |
| 2598 | |
| 2599 | switch (source->id) { |
| 2600 | case snd_soc_dapm_demux: |
| 2601 | dynamic_source = true; |
| 2602 | break; |
| 2603 | default: |
| 2604 | break; |
| 2605 | } |
| 2606 | |
| 2607 | switch (sink->id) { |
| 2608 | case snd_soc_dapm_mux: |
| 2609 | case snd_soc_dapm_switch: |
| 2610 | case snd_soc_dapm_mixer: |
| 2611 | case snd_soc_dapm_mixer_named_ctl: |
| 2612 | dynamic_sink = true; |
| 2613 | break; |
| 2614 | default: |
| 2615 | break; |
| 2616 | } |
| 2617 | |
| 2618 | if (dynamic_source && dynamic_sink) { |
| 2619 | dev_err(dapm->dev, |
| 2620 | "Direct connection between demux and mixer/mux not supported for path %s -> [%s] -> %s\n", |
| 2621 | source->name, control, sink->name); |
| 2622 | return -EINVAL; |
| 2623 | } else if (!dynamic_source && !dynamic_sink) { |
| 2624 | dev_err(dapm->dev, |
| 2625 | "Control not supported for path %s -> [%s] -> %s\n", |
| 2626 | source->name, control, sink->name); |
| 2627 | return -EINVAL; |
| 2628 | } |
| 2629 | |
| 2630 | return 0; |
| 2631 | } |
| 2632 | |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2633 | static int snd_soc_dapm_add_path(struct snd_soc_dapm_context *dapm, |
| 2634 | struct snd_soc_dapm_widget *wsource, struct snd_soc_dapm_widget *wsink, |
| 2635 | const char *control, |
| 2636 | int (*connected)(struct snd_soc_dapm_widget *source, |
| 2637 | struct snd_soc_dapm_widget *sink)) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2638 | { |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2639 | struct snd_soc_dapm_widget *widgets[2]; |
| 2640 | enum snd_soc_dapm_direction dir; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2641 | struct snd_soc_dapm_path *path; |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2642 | int ret; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2643 | |
Lars-Peter Clausen | e409dfb | 2014-10-25 17:42:02 +0200 | [diff] [blame] | 2644 | if (wsink->is_supply && !wsource->is_supply) { |
| 2645 | dev_err(dapm->dev, |
| 2646 | "Connecting non-supply widget to supply widget is not supported (%s -> %s)\n", |
| 2647 | wsource->name, wsink->name); |
| 2648 | return -EINVAL; |
| 2649 | } |
| 2650 | |
| 2651 | if (connected && !wsource->is_supply) { |
| 2652 | dev_err(dapm->dev, |
| 2653 | "connected() callback only supported for supply widgets (%s -> %s)\n", |
| 2654 | wsource->name, wsink->name); |
| 2655 | return -EINVAL; |
| 2656 | } |
| 2657 | |
| 2658 | if (wsource->is_supply && control) { |
| 2659 | dev_err(dapm->dev, |
| 2660 | "Conditional paths are not supported for supply widgets (%s -> [%s] -> %s)\n", |
| 2661 | wsource->name, control, wsink->name); |
| 2662 | return -EINVAL; |
| 2663 | } |
| 2664 | |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 2665 | ret = snd_soc_dapm_check_dynamic_path(dapm, wsource, wsink, control); |
| 2666 | if (ret) |
| 2667 | return ret; |
| 2668 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2669 | path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL); |
| 2670 | if (!path) |
| 2671 | return -ENOMEM; |
| 2672 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2673 | path->node[SND_SOC_DAPM_DIR_IN] = wsource; |
| 2674 | path->node[SND_SOC_DAPM_DIR_OUT] = wsink; |
| 2675 | widgets[SND_SOC_DAPM_DIR_IN] = wsource; |
| 2676 | widgets[SND_SOC_DAPM_DIR_OUT] = wsink; |
| 2677 | |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2678 | path->connected = connected; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2679 | INIT_LIST_HEAD(&path->list); |
Mark Brown | 69c2d34 | 2013-08-13 00:20:36 +0100 | [diff] [blame] | 2680 | INIT_LIST_HEAD(&path->list_kcontrol); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2681 | |
Lars-Peter Clausen | c1862c8 | 2014-10-25 17:42:00 +0200 | [diff] [blame] | 2682 | if (wsource->is_supply || wsink->is_supply) |
| 2683 | path->is_supply = 1; |
| 2684 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2685 | /* connect static paths */ |
| 2686 | if (control == NULL) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2687 | path->connect = 1; |
Lars-Peter Clausen | 5fe5b76 | 2014-10-25 17:41:58 +0200 | [diff] [blame] | 2688 | } else { |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 2689 | switch (wsource->id) { |
| 2690 | case snd_soc_dapm_demux: |
| 2691 | ret = dapm_connect_mux(dapm, path, control, wsource); |
| 2692 | if (ret) |
| 2693 | goto err; |
| 2694 | break; |
| 2695 | default: |
| 2696 | break; |
| 2697 | } |
| 2698 | |
Lars-Peter Clausen | 5fe5b76 | 2014-10-25 17:41:58 +0200 | [diff] [blame] | 2699 | switch (wsink->id) { |
| 2700 | case snd_soc_dapm_mux: |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 2701 | ret = dapm_connect_mux(dapm, path, control, wsink); |
Lars-Peter Clausen | 5fe5b76 | 2014-10-25 17:41:58 +0200 | [diff] [blame] | 2702 | if (ret != 0) |
| 2703 | goto err; |
| 2704 | break; |
| 2705 | case snd_soc_dapm_switch: |
| 2706 | case snd_soc_dapm_mixer: |
| 2707 | case snd_soc_dapm_mixer_named_ctl: |
| 2708 | ret = dapm_connect_mixer(dapm, path, control); |
| 2709 | if (ret != 0) |
| 2710 | goto err; |
| 2711 | break; |
| 2712 | default: |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 2713 | break; |
Lars-Peter Clausen | 5fe5b76 | 2014-10-25 17:41:58 +0200 | [diff] [blame] | 2714 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2715 | } |
| 2716 | |
Lars-Peter Clausen | 5fe5b76 | 2014-10-25 17:41:58 +0200 | [diff] [blame] | 2717 | list_add(&path->list, &dapm->card->paths); |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2718 | snd_soc_dapm_for_each_direction(dir) |
| 2719 | list_add(&path->list_node[dir], &widgets[dir]->edges[dir]); |
Lars-Peter Clausen | 5fe5b76 | 2014-10-25 17:41:58 +0200 | [diff] [blame] | 2720 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 2721 | snd_soc_dapm_for_each_direction(dir) { |
| 2722 | dapm_update_widget_flags(widgets[dir]); |
| 2723 | dapm_mark_dirty(widgets[dir], "Route added"); |
| 2724 | } |
Mark Brown | fabd038 | 2012-07-05 17:20:06 +0100 | [diff] [blame] | 2725 | |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 2726 | if (dapm->card->instantiated && path->connect) |
| 2727 | dapm_path_invalidate(path); |
| 2728 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2729 | return 0; |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2730 | err: |
| 2731 | kfree(path); |
| 2732 | return ret; |
| 2733 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2734 | |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2735 | static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm, |
Lars-Peter Clausen | a4e9154 | 2014-05-07 16:20:25 +0200 | [diff] [blame] | 2736 | const struct snd_soc_dapm_route *route) |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2737 | { |
| 2738 | struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w; |
| 2739 | struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL; |
| 2740 | const char *sink; |
| 2741 | const char *source; |
| 2742 | char prefixed_sink[80]; |
| 2743 | char prefixed_source[80]; |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 2744 | const char *prefix; |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2745 | int ret; |
| 2746 | |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 2747 | prefix = soc_dapm_prefix(dapm); |
| 2748 | if (prefix) { |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2749 | snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s", |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 2750 | prefix, route->sink); |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2751 | sink = prefixed_sink; |
| 2752 | snprintf(prefixed_source, sizeof(prefixed_source), "%s %s", |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 2753 | prefix, route->source); |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2754 | source = prefixed_source; |
| 2755 | } else { |
| 2756 | sink = route->sink; |
| 2757 | source = route->source; |
| 2758 | } |
| 2759 | |
Charles Keepax | 45a110a | 2015-05-11 13:50:30 +0100 | [diff] [blame] | 2760 | wsource = dapm_wcache_lookup(&dapm->path_source_cache, source); |
| 2761 | wsink = dapm_wcache_lookup(&dapm->path_sink_cache, sink); |
| 2762 | |
| 2763 | if (wsink && wsource) |
| 2764 | goto skip_search; |
| 2765 | |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2766 | /* |
| 2767 | * find src and dest widgets over all widgets but favor a widget from |
| 2768 | * current DAPM context |
| 2769 | */ |
| 2770 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 2771 | if (!wsink && !(strcmp(w->name, sink))) { |
| 2772 | wtsink = w; |
Charles Keepax | 70c7510 | 2015-05-07 11:33:58 +0100 | [diff] [blame] | 2773 | if (w->dapm == dapm) { |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2774 | wsink = w; |
Charles Keepax | 70c7510 | 2015-05-07 11:33:58 +0100 | [diff] [blame] | 2775 | if (wsource) |
| 2776 | break; |
| 2777 | } |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2778 | continue; |
| 2779 | } |
| 2780 | if (!wsource && !(strcmp(w->name, source))) { |
| 2781 | wtsource = w; |
Charles Keepax | 70c7510 | 2015-05-07 11:33:58 +0100 | [diff] [blame] | 2782 | if (w->dapm == dapm) { |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2783 | wsource = w; |
Charles Keepax | 70c7510 | 2015-05-07 11:33:58 +0100 | [diff] [blame] | 2784 | if (wsink) |
| 2785 | break; |
| 2786 | } |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2787 | } |
| 2788 | } |
| 2789 | /* use widget from another DAPM context if not found from this */ |
| 2790 | if (!wsink) |
| 2791 | wsink = wtsink; |
| 2792 | if (!wsource) |
| 2793 | wsource = wtsource; |
| 2794 | |
| 2795 | if (wsource == NULL) { |
| 2796 | dev_err(dapm->dev, "ASoC: no source widget found for %s\n", |
| 2797 | route->source); |
| 2798 | return -ENODEV; |
| 2799 | } |
| 2800 | if (wsink == NULL) { |
| 2801 | dev_err(dapm->dev, "ASoC: no sink widget found for %s\n", |
| 2802 | route->sink); |
| 2803 | return -ENODEV; |
| 2804 | } |
| 2805 | |
Charles Keepax | 45a110a | 2015-05-11 13:50:30 +0100 | [diff] [blame] | 2806 | skip_search: |
| 2807 | dapm_wcache_update(&dapm->path_sink_cache, wsink); |
| 2808 | dapm_wcache_update(&dapm->path_source_cache, wsource); |
| 2809 | |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2810 | ret = snd_soc_dapm_add_path(dapm, wsource, wsink, route->control, |
| 2811 | route->connected); |
| 2812 | if (ret) |
| 2813 | goto err; |
| 2814 | |
| 2815 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2816 | err: |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2817 | dev_warn(dapm->dev, "ASoC: no dapm match for %s --> %s --> %s\n", |
Lars-Peter Clausen | 2553628 | 2013-07-29 17:14:02 +0200 | [diff] [blame] | 2818 | source, route->control, sink); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2819 | return ret; |
| 2820 | } |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2821 | |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2822 | static int snd_soc_dapm_del_route(struct snd_soc_dapm_context *dapm, |
| 2823 | const struct snd_soc_dapm_route *route) |
| 2824 | { |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 2825 | struct snd_soc_dapm_widget *wsource, *wsink; |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2826 | struct snd_soc_dapm_path *path, *p; |
| 2827 | const char *sink; |
| 2828 | const char *source; |
| 2829 | char prefixed_sink[80]; |
| 2830 | char prefixed_source[80]; |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 2831 | const char *prefix; |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2832 | |
| 2833 | if (route->control) { |
| 2834 | dev_err(dapm->dev, |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2835 | "ASoC: Removal of routes with controls not supported\n"); |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2836 | return -EINVAL; |
| 2837 | } |
| 2838 | |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 2839 | prefix = soc_dapm_prefix(dapm); |
| 2840 | if (prefix) { |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2841 | snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s", |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 2842 | prefix, route->sink); |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2843 | sink = prefixed_sink; |
| 2844 | snprintf(prefixed_source, sizeof(prefixed_source), "%s %s", |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 2845 | prefix, route->source); |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2846 | source = prefixed_source; |
| 2847 | } else { |
| 2848 | sink = route->sink; |
| 2849 | source = route->source; |
| 2850 | } |
| 2851 | |
| 2852 | path = NULL; |
| 2853 | list_for_each_entry(p, &dapm->card->paths, list) { |
| 2854 | if (strcmp(p->source->name, source) != 0) |
| 2855 | continue; |
| 2856 | if (strcmp(p->sink->name, sink) != 0) |
| 2857 | continue; |
| 2858 | path = p; |
| 2859 | break; |
| 2860 | } |
| 2861 | |
| 2862 | if (path) { |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 2863 | wsource = path->source; |
| 2864 | wsink = path->sink; |
| 2865 | |
| 2866 | dapm_mark_dirty(wsource, "Route removed"); |
| 2867 | dapm_mark_dirty(wsink, "Route removed"); |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 2868 | if (path->connect) |
| 2869 | dapm_path_invalidate(path); |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2870 | |
Lars-Peter Clausen | 8872293 | 2013-06-14 13:16:53 +0200 | [diff] [blame] | 2871 | dapm_free_path(path); |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 2872 | |
| 2873 | /* Update any path related flags */ |
| 2874 | dapm_update_widget_flags(wsource); |
| 2875 | dapm_update_widget_flags(wsink); |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2876 | } else { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2877 | dev_warn(dapm->dev, "ASoC: Route %s->%s does not exist\n", |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2878 | source, sink); |
| 2879 | } |
| 2880 | |
| 2881 | return 0; |
| 2882 | } |
| 2883 | |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2884 | /** |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2885 | * snd_soc_dapm_add_routes - Add routes between DAPM widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2886 | * @dapm: DAPM context |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2887 | * @route: audio routes |
| 2888 | * @num: number of routes |
| 2889 | * |
| 2890 | * Connects 2 dapm widgets together via a named audio path. The sink is |
| 2891 | * the widget receiving the audio signal, whilst the source is the sender |
| 2892 | * of the audio signal. |
| 2893 | * |
| 2894 | * Returns 0 for success else error. On error all resources can be freed |
| 2895 | * with a call to snd_soc_card_free(). |
| 2896 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2897 | int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm, |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2898 | const struct snd_soc_dapm_route *route, int num) |
| 2899 | { |
Mark Brown | 62d4a4b | 2012-06-22 12:21:49 +0100 | [diff] [blame] | 2900 | int i, r, ret = 0; |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2901 | |
Stuart Henderson | f19c181 | 2017-09-21 11:02:12 +0100 | [diff] [blame] | 2902 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2903 | for (i = 0; i < num; i++) { |
Lars-Peter Clausen | a4e9154 | 2014-05-07 16:20:25 +0200 | [diff] [blame] | 2904 | r = snd_soc_dapm_add_route(dapm, route); |
Mark Brown | 62d4a4b | 2012-06-22 12:21:49 +0100 | [diff] [blame] | 2905 | if (r < 0) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2906 | dev_err(dapm->dev, "ASoC: Failed to add route %s -> %s -> %s\n", |
| 2907 | route->source, |
| 2908 | route->control ? route->control : "direct", |
| 2909 | route->sink); |
Mark Brown | 62d4a4b | 2012-06-22 12:21:49 +0100 | [diff] [blame] | 2910 | ret = r; |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2911 | } |
| 2912 | route++; |
| 2913 | } |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 2914 | mutex_unlock(&dapm->card->dapm_mutex); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2915 | |
Dan Carpenter | 60884c2 | 2012-04-13 22:25:43 +0300 | [diff] [blame] | 2916 | return ret; |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2917 | } |
| 2918 | EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes); |
| 2919 | |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2920 | /** |
| 2921 | * snd_soc_dapm_del_routes - Remove routes between DAPM widgets |
| 2922 | * @dapm: DAPM context |
| 2923 | * @route: audio routes |
| 2924 | * @num: number of routes |
| 2925 | * |
| 2926 | * Removes routes from the DAPM context. |
| 2927 | */ |
| 2928 | int snd_soc_dapm_del_routes(struct snd_soc_dapm_context *dapm, |
| 2929 | const struct snd_soc_dapm_route *route, int num) |
| 2930 | { |
Rajan Vaja | e066ea2 | 2016-02-11 11:23:35 +0530 | [diff] [blame] | 2931 | int i; |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2932 | |
Stuart Henderson | f19c181 | 2017-09-21 11:02:12 +0100 | [diff] [blame] | 2933 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2934 | for (i = 0; i < num; i++) { |
| 2935 | snd_soc_dapm_del_route(dapm, route); |
| 2936 | route++; |
| 2937 | } |
| 2938 | mutex_unlock(&dapm->card->dapm_mutex); |
| 2939 | |
Rajan Vaja | e066ea2 | 2016-02-11 11:23:35 +0530 | [diff] [blame] | 2940 | return 0; |
Mark Brown | efcc3c6 | 2012-07-05 17:24:19 +0100 | [diff] [blame] | 2941 | } |
| 2942 | EXPORT_SYMBOL_GPL(snd_soc_dapm_del_routes); |
| 2943 | |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2944 | static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm, |
| 2945 | const struct snd_soc_dapm_route *route) |
| 2946 | { |
| 2947 | struct snd_soc_dapm_widget *source = dapm_find_widget(dapm, |
| 2948 | route->source, |
| 2949 | true); |
| 2950 | struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm, |
| 2951 | route->sink, |
| 2952 | true); |
| 2953 | struct snd_soc_dapm_path *path; |
| 2954 | int count = 0; |
| 2955 | |
| 2956 | if (!source) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2957 | dev_err(dapm->dev, "ASoC: Unable to find source %s for weak route\n", |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2958 | route->source); |
| 2959 | return -ENODEV; |
| 2960 | } |
| 2961 | |
| 2962 | if (!sink) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2963 | dev_err(dapm->dev, "ASoC: Unable to find sink %s for weak route\n", |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2964 | route->sink); |
| 2965 | return -ENODEV; |
| 2966 | } |
| 2967 | |
| 2968 | if (route->control || route->connected) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2969 | dev_warn(dapm->dev, "ASoC: Ignoring control for weak route %s->%s\n", |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2970 | route->source, route->sink); |
| 2971 | |
Lars-Peter Clausen | e63bfd4 | 2015-07-26 19:05:00 +0200 | [diff] [blame] | 2972 | snd_soc_dapm_widget_for_each_sink_path(source, path) { |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2973 | if (path->sink == sink) { |
| 2974 | path->weak = 1; |
| 2975 | count++; |
| 2976 | } |
| 2977 | } |
| 2978 | |
| 2979 | if (count == 0) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2980 | dev_err(dapm->dev, "ASoC: No path found for weak route %s->%s\n", |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2981 | route->source, route->sink); |
| 2982 | if (count > 1) |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 2983 | dev_warn(dapm->dev, "ASoC: %d paths found for weak route %s->%s\n", |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2984 | count, route->source, route->sink); |
| 2985 | |
| 2986 | return 0; |
| 2987 | } |
| 2988 | |
| 2989 | /** |
| 2990 | * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak |
| 2991 | * @dapm: DAPM context |
| 2992 | * @route: audio routes |
| 2993 | * @num: number of routes |
| 2994 | * |
| 2995 | * Mark existing routes matching those specified in the passed array |
| 2996 | * as being weak, meaning that they are ignored for the purpose of |
| 2997 | * power decisions. The main intended use case is for sidetone paths |
| 2998 | * which couple audio between other independent paths if they are both |
| 2999 | * active in order to make the combination work better at the user |
| 3000 | * level but which aren't intended to be "used". |
| 3001 | * |
| 3002 | * Note that CODEC drivers should not use this as sidetone type paths |
| 3003 | * can frequently also be used as bypass paths. |
| 3004 | */ |
| 3005 | int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm, |
| 3006 | const struct snd_soc_dapm_route *route, int num) |
| 3007 | { |
| 3008 | int i, err; |
| 3009 | int ret = 0; |
| 3010 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3011 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 3012 | for (i = 0; i < num; i++) { |
| 3013 | err = snd_soc_dapm_weak_route(dapm, route); |
| 3014 | if (err) |
| 3015 | ret = err; |
| 3016 | route++; |
| 3017 | } |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3018 | mutex_unlock(&dapm->card->dapm_mutex); |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 3019 | |
| 3020 | return ret; |
| 3021 | } |
| 3022 | EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes); |
| 3023 | |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 3024 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3025 | * snd_soc_dapm_new_widgets - add new dapm widgets |
Jonathan Corbet | 628536e | 2015-08-25 01:14:48 -0600 | [diff] [blame] | 3026 | * @card: card to be checked for new dapm widgets |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3027 | * |
| 3028 | * Checks the codec for any new dapm widgets and creates them if found. |
| 3029 | * |
| 3030 | * Returns 0 for success. |
| 3031 | */ |
Lars-Peter Clausen | 824ef82 | 2013-08-27 15:51:01 +0200 | [diff] [blame] | 3032 | int snd_soc_dapm_new_widgets(struct snd_soc_card *card) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3033 | { |
| 3034 | struct snd_soc_dapm_widget *w; |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 3035 | unsigned int val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3036 | |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 3037 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3038 | |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 3039 | list_for_each_entry(w, &card->widgets, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3040 | { |
| 3041 | if (w->new) |
| 3042 | continue; |
| 3043 | |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 3044 | if (w->num_kcontrols) { |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 3045 | w->kcontrols = kcalloc(w->num_kcontrols, |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 3046 | sizeof(struct snd_kcontrol *), |
| 3047 | GFP_KERNEL); |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3048 | if (!w->kcontrols) { |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 3049 | mutex_unlock(&card->dapm_mutex); |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 3050 | return -ENOMEM; |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3051 | } |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 3052 | } |
| 3053 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3054 | switch(w->id) { |
| 3055 | case snd_soc_dapm_switch: |
| 3056 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 3057 | case snd_soc_dapm_mixer_named_ctl: |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 3058 | dapm_new_mixer(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3059 | break; |
| 3060 | case snd_soc_dapm_mux: |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 3061 | case snd_soc_dapm_demux: |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 3062 | dapm_new_mux(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3063 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3064 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 3065 | case snd_soc_dapm_out_drv: |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 3066 | dapm_new_pga(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3067 | break; |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3068 | case snd_soc_dapm_dai_link: |
| 3069 | dapm_new_dai_link(w); |
| 3070 | break; |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 3071 | default: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3072 | break; |
| 3073 | } |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 3074 | |
| 3075 | /* Read the initial power state from the device */ |
| 3076 | if (w->reg >= 0) { |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 3077 | soc_dapm_read(w->dapm, w->reg, &val); |
Arun Shamanna Lakshmi | f7d3c17 | 2014-01-14 15:31:54 -0800 | [diff] [blame] | 3078 | val = val >> w->shift; |
Lars-Peter Clausen | de9ba98 | 2013-07-29 17:14:01 +0200 | [diff] [blame] | 3079 | val &= w->mask; |
| 3080 | if (val == w->on_val) |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 3081 | w->power = 1; |
| 3082 | } |
| 3083 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3084 | w->new = 1; |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 3085 | |
Mark Brown | 7508b12 | 2011-10-05 12:09:12 +0100 | [diff] [blame] | 3086 | dapm_mark_dirty(w, "new widget"); |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 3087 | dapm_debugfs_add_widget(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3088 | } |
| 3089 | |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 3090 | dapm_power_widgets(card, SND_SOC_DAPM_STREAM_NOP); |
| 3091 | mutex_unlock(&card->dapm_mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3092 | return 0; |
| 3093 | } |
| 3094 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); |
| 3095 | |
| 3096 | /** |
| 3097 | * snd_soc_dapm_get_volsw - dapm mixer get callback |
| 3098 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3099 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3100 | * |
| 3101 | * Callback to get the value of a dapm mixer control. |
| 3102 | * |
| 3103 | * Returns 0 for success. |
| 3104 | */ |
| 3105 | int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, |
| 3106 | struct snd_ctl_elem_value *ucontrol) |
| 3107 | { |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 3108 | struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); |
| 3109 | struct snd_soc_card *card = dapm->card; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3110 | struct soc_mixer_control *mc = |
| 3111 | (struct soc_mixer_control *)kcontrol->private_value; |
Lars-Peter Clausen | 249ce13 | 2013-10-06 13:43:49 +0200 | [diff] [blame] | 3112 | int reg = mc->reg; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3113 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3114 | int max = mc->max; |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 3115 | unsigned int width = fls(max); |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3116 | unsigned int mask = (1 << fls(max)) - 1; |
Benoît Thébaudeau | da602ab | 2012-07-03 20:18:17 +0200 | [diff] [blame] | 3117 | unsigned int invert = mc->invert; |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 3118 | unsigned int reg_val, val, rval = 0; |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 3119 | int ret = 0; |
Benoît Thébaudeau | da602ab | 2012-07-03 20:18:17 +0200 | [diff] [blame] | 3120 | |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 3121 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 3122 | if (dapm_kcontrol_is_powered(kcontrol) && reg != SND_SOC_NOPM) { |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 3123 | ret = soc_dapm_read(dapm, reg, ®_val); |
| 3124 | val = (reg_val >> shift) & mask; |
| 3125 | |
| 3126 | if (ret == 0 && reg != mc->rreg) |
| 3127 | ret = soc_dapm_read(dapm, mc->rreg, ®_val); |
| 3128 | |
| 3129 | if (snd_soc_volsw_is_stereo(mc)) |
| 3130 | rval = (reg_val >> mc->rshift) & mask; |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 3131 | } else { |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 3132 | reg_val = dapm_kcontrol_get_value(kcontrol); |
| 3133 | val = reg_val & mask; |
| 3134 | |
| 3135 | if (snd_soc_volsw_is_stereo(mc)) |
| 3136 | rval = (reg_val >> width) & mask; |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 3137 | } |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 3138 | mutex_unlock(&card->dapm_mutex); |
| 3139 | |
Chen-Yu Tsai | 01ad5e7 | 2016-08-27 19:27:58 +0800 | [diff] [blame] | 3140 | if (ret) |
| 3141 | return ret; |
| 3142 | |
Benoît Thébaudeau | da602ab | 2012-07-03 20:18:17 +0200 | [diff] [blame] | 3143 | if (invert) |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 3144 | ucontrol->value.integer.value[0] = max - val; |
| 3145 | else |
| 3146 | ucontrol->value.integer.value[0] = val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3147 | |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 3148 | if (snd_soc_volsw_is_stereo(mc)) { |
| 3149 | if (invert) |
| 3150 | ucontrol->value.integer.value[1] = max - rval; |
| 3151 | else |
| 3152 | ucontrol->value.integer.value[1] = rval; |
| 3153 | } |
| 3154 | |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 3155 | return ret; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3156 | } |
| 3157 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw); |
| 3158 | |
| 3159 | /** |
| 3160 | * snd_soc_dapm_put_volsw - dapm mixer set callback |
| 3161 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3162 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3163 | * |
| 3164 | * Callback to set the value of a dapm mixer control. |
| 3165 | * |
| 3166 | * Returns 0 for success. |
| 3167 | */ |
| 3168 | int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, |
| 3169 | struct snd_ctl_elem_value *ucontrol) |
| 3170 | { |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 3171 | struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); |
| 3172 | struct snd_soc_card *card = dapm->card; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3173 | struct soc_mixer_control *mc = |
| 3174 | (struct soc_mixer_control *)kcontrol->private_value; |
Lars-Peter Clausen | 249ce13 | 2013-10-06 13:43:49 +0200 | [diff] [blame] | 3175 | int reg = mc->reg; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3176 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 3177 | int max = mc->max; |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 3178 | unsigned int width = fls(max); |
| 3179 | unsigned int mask = (1 << width) - 1; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 3180 | unsigned int invert = mc->invert; |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 3181 | unsigned int val, rval = 0; |
| 3182 | int connect, rconnect = -1, change, reg_change = 0; |
Fabio Estevam | 33d9245 | 2018-02-14 13:39:05 -0200 | [diff] [blame] | 3183 | struct snd_soc_dapm_update update = {}; |
Nenghua Cao | 5276597 | 2013-12-13 20:13:49 +0800 | [diff] [blame] | 3184 | int ret = 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3185 | |
| 3186 | val = (ucontrol->value.integer.value[0] & mask); |
Benoît Thébaudeau | 8a72071 | 2012-06-18 22:41:28 +0200 | [diff] [blame] | 3187 | connect = !!val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3188 | |
| 3189 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 3190 | val = max - val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3191 | |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 3192 | if (snd_soc_volsw_is_stereo(mc)) { |
| 3193 | rval = (ucontrol->value.integer.value[1] & mask); |
| 3194 | rconnect = !!rval; |
| 3195 | if (invert) |
| 3196 | rval = max - rval; |
| 3197 | } |
| 3198 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 3199 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3200 | |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 3201 | /* This assumes field width < (bits in unsigned int / 2) */ |
| 3202 | if (width > sizeof(unsigned int) * 8 / 2) |
| 3203 | dev_warn(dapm->dev, |
| 3204 | "ASoC: control %s field width limit exceeded\n", |
| 3205 | kcontrol->id.name); |
| 3206 | change = dapm_kcontrol_set_value(kcontrol, val | (rval << width)); |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 3207 | |
Jarkko Nikula | 18626c7 | 2014-06-09 14:20:29 +0300 | [diff] [blame] | 3208 | if (reg != SND_SOC_NOPM) { |
Jarkko Nikula | 18626c7 | 2014-06-09 14:20:29 +0300 | [diff] [blame] | 3209 | val = val << shift; |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 3210 | rval = rval << mc->rshift; |
Lars-Peter Clausen | c9e065c | 2014-05-04 19:17:05 +0200 | [diff] [blame] | 3211 | |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 3212 | reg_change = soc_dapm_test_bits(dapm, reg, mask << shift, val); |
| 3213 | |
| 3214 | if (snd_soc_volsw_is_stereo(mc)) |
| 3215 | reg_change |= soc_dapm_test_bits(dapm, mc->rreg, |
| 3216 | mask << mc->rshift, |
| 3217 | rval); |
Jarkko Nikula | 18626c7 | 2014-06-09 14:20:29 +0300 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | if (change || reg_change) { |
| 3221 | if (reg_change) { |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 3222 | if (snd_soc_volsw_is_stereo(mc)) { |
| 3223 | update.has_second_set = true; |
| 3224 | update.reg2 = mc->rreg; |
| 3225 | update.mask2 = mask << mc->rshift; |
| 3226 | update.val2 = rval; |
| 3227 | } |
Jarkko Nikula | 18626c7 | 2014-06-09 14:20:29 +0300 | [diff] [blame] | 3228 | update.kcontrol = kcontrol; |
| 3229 | update.reg = reg; |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 3230 | update.mask = mask << shift; |
Jarkko Nikula | 18626c7 | 2014-06-09 14:20:29 +0300 | [diff] [blame] | 3231 | update.val = val; |
| 3232 | card->update = &update; |
Lars-Peter Clausen | 249ce13 | 2013-10-06 13:43:49 +0200 | [diff] [blame] | 3233 | } |
Jarkko Nikula | 18626c7 | 2014-06-09 14:20:29 +0300 | [diff] [blame] | 3234 | change |= reg_change; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 3235 | |
Chen-Yu Tsai | e7aa450 | 2016-11-02 15:35:59 +0800 | [diff] [blame] | 3236 | ret = soc_dapm_mixer_update_power(card, kcontrol, connect, |
| 3237 | rconnect); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 3238 | |
Lars-Peter Clausen | 564c6504 | 2013-07-29 17:13:55 +0200 | [diff] [blame] | 3239 | card->update = NULL; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 3240 | } |
| 3241 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3242 | mutex_unlock(&card->dapm_mutex); |
Nenghua Cao | 5276597 | 2013-12-13 20:13:49 +0800 | [diff] [blame] | 3243 | |
| 3244 | if (ret > 0) |
| 3245 | soc_dpcm_runtime_update(card); |
| 3246 | |
Lars-Peter Clausen | 56a6783 | 2013-07-24 15:27:35 +0200 | [diff] [blame] | 3247 | return change; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3248 | } |
| 3249 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); |
| 3250 | |
| 3251 | /** |
| 3252 | * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback |
| 3253 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3254 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3255 | * |
| 3256 | * Callback to get the value of a dapm enumerated double mixer control. |
| 3257 | * |
| 3258 | * Returns 0 for success. |
| 3259 | */ |
| 3260 | int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, |
| 3261 | struct snd_ctl_elem_value *ucontrol) |
| 3262 | { |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 3263 | struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 3264 | struct snd_soc_card *card = dapm->card; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3265 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Lars-Peter Clausen | 3727b49 | 2014-02-28 08:31:04 +0100 | [diff] [blame] | 3266 | unsigned int reg_val, val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3267 | |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 3268 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
| 3269 | if (e->reg != SND_SOC_NOPM && dapm_kcontrol_is_powered(kcontrol)) { |
Geert Uytterhoeven | 6912831 | 2014-08-08 17:29:35 +0200 | [diff] [blame] | 3270 | int ret = soc_dapm_read(dapm, e->reg, ®_val); |
Charles Keepax | 964a0b8 | 2015-05-08 10:50:10 +0100 | [diff] [blame] | 3271 | if (ret) { |
| 3272 | mutex_unlock(&card->dapm_mutex); |
Geert Uytterhoeven | 6912831 | 2014-08-08 17:29:35 +0200 | [diff] [blame] | 3273 | return ret; |
Charles Keepax | 964a0b8 | 2015-05-08 10:50:10 +0100 | [diff] [blame] | 3274 | } |
Geert Uytterhoeven | 6912831 | 2014-08-08 17:29:35 +0200 | [diff] [blame] | 3275 | } else { |
Lars-Peter Clausen | 236aaa6 | 2014-02-28 08:31:11 +0100 | [diff] [blame] | 3276 | reg_val = dapm_kcontrol_get_value(kcontrol); |
Geert Uytterhoeven | 6912831 | 2014-08-08 17:29:35 +0200 | [diff] [blame] | 3277 | } |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 3278 | mutex_unlock(&card->dapm_mutex); |
Lars-Peter Clausen | 236aaa6 | 2014-02-28 08:31:11 +0100 | [diff] [blame] | 3279 | |
Lars-Peter Clausen | 3727b49 | 2014-02-28 08:31:04 +0100 | [diff] [blame] | 3280 | val = (reg_val >> e->shift_l) & e->mask; |
| 3281 | ucontrol->value.enumerated.item[0] = snd_soc_enum_val_to_item(e, val); |
| 3282 | if (e->shift_l != e->shift_r) { |
| 3283 | val = (reg_val >> e->shift_r) & e->mask; |
| 3284 | val = snd_soc_enum_val_to_item(e, val); |
| 3285 | ucontrol->value.enumerated.item[1] = val; |
| 3286 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3287 | |
Geert Uytterhoeven | 6912831 | 2014-08-08 17:29:35 +0200 | [diff] [blame] | 3288 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3289 | } |
| 3290 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double); |
| 3291 | |
| 3292 | /** |
| 3293 | * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback |
| 3294 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 3295 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3296 | * |
| 3297 | * Callback to set the value of a dapm enumerated double mixer control. |
| 3298 | * |
| 3299 | * Returns 0 for success. |
| 3300 | */ |
| 3301 | int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, |
| 3302 | struct snd_ctl_elem_value *ucontrol) |
| 3303 | { |
Lars-Peter Clausen | ce0fc93 | 2014-06-16 18:13:06 +0200 | [diff] [blame] | 3304 | struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); |
| 3305 | struct snd_soc_card *card = dapm->card; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3306 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Lars-Peter Clausen | 3727b49 | 2014-02-28 08:31:04 +0100 | [diff] [blame] | 3307 | unsigned int *item = ucontrol->value.enumerated.item; |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 3308 | unsigned int val, change, reg_change = 0; |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 3309 | unsigned int mask; |
Fabio Estevam | 33d9245 | 2018-02-14 13:39:05 -0200 | [diff] [blame] | 3310 | struct snd_soc_dapm_update update = {}; |
Nenghua Cao | 5276597 | 2013-12-13 20:13:49 +0800 | [diff] [blame] | 3311 | int ret = 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3312 | |
Lars-Peter Clausen | 3727b49 | 2014-02-28 08:31:04 +0100 | [diff] [blame] | 3313 | if (item[0] >= e->items) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3314 | return -EINVAL; |
Lars-Peter Clausen | 3727b49 | 2014-02-28 08:31:04 +0100 | [diff] [blame] | 3315 | |
| 3316 | val = snd_soc_enum_item_to_val(e, item[0]) << e->shift_l; |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 3317 | mask = e->mask << e->shift_l; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3318 | if (e->shift_l != e->shift_r) { |
Lars-Peter Clausen | 3727b49 | 2014-02-28 08:31:04 +0100 | [diff] [blame] | 3319 | if (item[1] > e->items) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3320 | return -EINVAL; |
Chen-Yu Tsai | 071133a | 2016-08-27 19:27:59 +0800 | [diff] [blame] | 3321 | val |= snd_soc_enum_item_to_val(e, item[1]) << e->shift_r; |
Lars-Peter Clausen | 86767b7 | 2012-09-14 13:57:27 +0200 | [diff] [blame] | 3322 | mask |= e->mask << e->shift_r; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3323 | } |
| 3324 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 3325 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 3326 | |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 3327 | change = dapm_kcontrol_set_value(kcontrol, val); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 3328 | |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 3329 | if (e->reg != SND_SOC_NOPM) |
| 3330 | reg_change = soc_dapm_test_bits(dapm, e->reg, mask, val); |
| 3331 | |
| 3332 | if (change || reg_change) { |
| 3333 | if (reg_change) { |
Lars-Peter Clausen | 236aaa6 | 2014-02-28 08:31:11 +0100 | [diff] [blame] | 3334 | update.kcontrol = kcontrol; |
| 3335 | update.reg = e->reg; |
| 3336 | update.mask = mask; |
| 3337 | update.val = val; |
| 3338 | card->update = &update; |
| 3339 | } |
Charles Keepax | 561ed68 | 2015-05-01 12:37:26 +0100 | [diff] [blame] | 3340 | change |= reg_change; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 3341 | |
Lars-Peter Clausen | 3727b49 | 2014-02-28 08:31:04 +0100 | [diff] [blame] | 3342 | ret = soc_dapm_mux_update_power(card, kcontrol, item[0], e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 3343 | |
Lars-Peter Clausen | 564c6504 | 2013-07-29 17:13:55 +0200 | [diff] [blame] | 3344 | card->update = NULL; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 3345 | } |
| 3346 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3347 | mutex_unlock(&card->dapm_mutex); |
Nenghua Cao | 5276597 | 2013-12-13 20:13:49 +0800 | [diff] [blame] | 3348 | |
| 3349 | if (ret > 0) |
| 3350 | soc_dpcm_runtime_update(card); |
| 3351 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 3352 | return change; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3353 | } |
| 3354 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); |
| 3355 | |
| 3356 | /** |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3357 | * snd_soc_dapm_info_pin_switch - Info for a pin switch |
| 3358 | * |
| 3359 | * @kcontrol: mixer control |
| 3360 | * @uinfo: control element information |
| 3361 | * |
| 3362 | * Callback to provide information about a pin switch control. |
| 3363 | */ |
| 3364 | int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol, |
| 3365 | struct snd_ctl_elem_info *uinfo) |
| 3366 | { |
| 3367 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 3368 | uinfo->count = 1; |
| 3369 | uinfo->value.integer.min = 0; |
| 3370 | uinfo->value.integer.max = 1; |
| 3371 | |
| 3372 | return 0; |
| 3373 | } |
| 3374 | EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch); |
| 3375 | |
| 3376 | /** |
| 3377 | * snd_soc_dapm_get_pin_switch - Get information for a pin switch |
| 3378 | * |
| 3379 | * @kcontrol: mixer control |
| 3380 | * @ucontrol: Value |
| 3381 | */ |
| 3382 | int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol, |
| 3383 | struct snd_ctl_elem_value *ucontrol) |
| 3384 | { |
Mark Brown | 48a8c39 | 2012-02-14 17:11:15 -0800 | [diff] [blame] | 3385 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3386 | const char *pin = (const char *)kcontrol->private_value; |
| 3387 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 3388 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3389 | |
| 3390 | ucontrol->value.integer.value[0] = |
Mark Brown | 48a8c39 | 2012-02-14 17:11:15 -0800 | [diff] [blame] | 3391 | snd_soc_dapm_get_pin_status(&card->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3392 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3393 | mutex_unlock(&card->dapm_mutex); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3394 | |
| 3395 | return 0; |
| 3396 | } |
| 3397 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch); |
| 3398 | |
| 3399 | /** |
| 3400 | * snd_soc_dapm_put_pin_switch - Set information for a pin switch |
| 3401 | * |
| 3402 | * @kcontrol: mixer control |
| 3403 | * @ucontrol: Value |
| 3404 | */ |
| 3405 | int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol, |
| 3406 | struct snd_ctl_elem_value *ucontrol) |
| 3407 | { |
Mark Brown | 48a8c39 | 2012-02-14 17:11:15 -0800 | [diff] [blame] | 3408 | struct snd_soc_card *card = snd_kcontrol_chip(kcontrol); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3409 | const char *pin = (const char *)kcontrol->private_value; |
| 3410 | |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3411 | if (ucontrol->value.integer.value[0]) |
Mark Brown | 48a8c39 | 2012-02-14 17:11:15 -0800 | [diff] [blame] | 3412 | snd_soc_dapm_enable_pin(&card->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3413 | else |
Mark Brown | 48a8c39 | 2012-02-14 17:11:15 -0800 | [diff] [blame] | 3414 | snd_soc_dapm_disable_pin(&card->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3415 | |
Mark Brown | 48a8c39 | 2012-02-14 17:11:15 -0800 | [diff] [blame] | 3416 | snd_soc_dapm_sync(&card->dapm); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 3417 | return 0; |
| 3418 | } |
| 3419 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch); |
| 3420 | |
Liam Girdwood | cc76e7d | 2015-06-04 15:13:09 +0100 | [diff] [blame] | 3421 | struct snd_soc_dapm_widget * |
Liam Girdwood | 02aa78a | 2015-05-25 18:21:17 +0100 | [diff] [blame] | 3422 | snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm, |
Mark Brown | 5ba06fc | 2012-02-16 11:07:13 -0800 | [diff] [blame] | 3423 | const struct snd_soc_dapm_widget *widget) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3424 | { |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 3425 | enum snd_soc_dapm_direction dir; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3426 | struct snd_soc_dapm_widget *w; |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 3427 | const char *prefix; |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 3428 | int ret; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3429 | |
| 3430 | if ((w = dapm_cnew_widget(widget)) == NULL) |
Charles Keepax | 3bbf5d3 | 2018-09-05 15:20:58 +0100 | [diff] [blame] | 3431 | return ERR_PTR(-ENOMEM); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3432 | |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 3433 | switch (w->id) { |
| 3434 | case snd_soc_dapm_regulator_supply: |
Liam Girdwood | a3cc056 | 2012-03-09 17:20:16 +0000 | [diff] [blame] | 3435 | w->regulator = devm_regulator_get(dapm->dev, w->name); |
| 3436 | if (IS_ERR(w->regulator)) { |
| 3437 | ret = PTR_ERR(w->regulator); |
Charles Keepax | 3bbf5d3 | 2018-09-05 15:20:58 +0100 | [diff] [blame] | 3438 | goto request_failed; |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 3439 | } |
Mark Brown | 8784c77 | 2013-01-10 19:33:47 +0000 | [diff] [blame] | 3440 | |
Lars-Peter Clausen | de9ba98 | 2013-07-29 17:14:01 +0200 | [diff] [blame] | 3441 | if (w->on_val & SND_SOC_DAPM_REGULATOR_BYPASS) { |
Mark Brown | 8784c77 | 2013-01-10 19:33:47 +0000 | [diff] [blame] | 3442 | ret = regulator_allow_bypass(w->regulator, true); |
| 3443 | if (ret != 0) |
Charles Keepax | 3bbf5d3 | 2018-09-05 15:20:58 +0100 | [diff] [blame] | 3444 | dev_warn(dapm->dev, |
Charles Keepax | 30686c3 | 2014-02-18 16:05:27 +0000 | [diff] [blame] | 3445 | "ASoC: Failed to bypass %s: %d\n", |
Mark Brown | 8784c77 | 2013-01-10 19:33:47 +0000 | [diff] [blame] | 3446 | w->name, ret); |
| 3447 | } |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 3448 | break; |
Srinivas Kandagatla | 5b2d15b | 2018-03-10 02:37:27 +0000 | [diff] [blame] | 3449 | case snd_soc_dapm_pinctrl: |
| 3450 | w->pinctrl = devm_pinctrl_get(dapm->dev); |
Charles Keepax | a5cd7e9 | 2018-08-28 14:35:03 +0100 | [diff] [blame] | 3451 | if (IS_ERR(w->pinctrl)) { |
Srinivas Kandagatla | 5b2d15b | 2018-03-10 02:37:27 +0000 | [diff] [blame] | 3452 | ret = PTR_ERR(w->pinctrl); |
Charles Keepax | 3bbf5d3 | 2018-09-05 15:20:58 +0100 | [diff] [blame] | 3453 | goto request_failed; |
Srinivas Kandagatla | 5b2d15b | 2018-03-10 02:37:27 +0000 | [diff] [blame] | 3454 | } |
| 3455 | break; |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 3456 | case snd_soc_dapm_clock_supply: |
Mark Brown | 695594f1 | 2012-06-04 08:14:13 +0100 | [diff] [blame] | 3457 | w->clk = devm_clk_get(dapm->dev, w->name); |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 3458 | if (IS_ERR(w->clk)) { |
| 3459 | ret = PTR_ERR(w->clk); |
Charles Keepax | 3bbf5d3 | 2018-09-05 15:20:58 +0100 | [diff] [blame] | 3460 | goto request_failed; |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 3461 | } |
| 3462 | break; |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 3463 | default: |
| 3464 | break; |
| 3465 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3466 | |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 3467 | prefix = soc_dapm_prefix(dapm); |
Lars-Peter Clausen | a798c24 | 2015-07-21 11:51:35 +0200 | [diff] [blame] | 3468 | if (prefix) |
Lars-Peter Clausen | 94f99c8 | 2014-06-16 18:13:01 +0200 | [diff] [blame] | 3469 | w->name = kasprintf(GFP_KERNEL, "%s %s", prefix, widget->name); |
Lars-Peter Clausen | a798c24 | 2015-07-21 11:51:35 +0200 | [diff] [blame] | 3470 | else |
Lars-Peter Clausen | 4806896 | 2015-07-21 18:11:08 +0200 | [diff] [blame] | 3471 | w->name = kstrdup_const(widget->name, GFP_KERNEL); |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 3472 | if (w->name == NULL) { |
| 3473 | kfree(w); |
Charles Keepax | 3bbf5d3 | 2018-09-05 15:20:58 +0100 | [diff] [blame] | 3474 | return ERR_PTR(-ENOMEM); |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 3475 | } |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 3476 | |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 3477 | switch (w->id) { |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 3478 | case snd_soc_dapm_mic: |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 3479 | w->is_ep = SND_SOC_DAPM_EP_SOURCE; |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 3480 | w->power_check = dapm_generic_check_power; |
| 3481 | break; |
Lars-Peter Clausen | 86d7500 | 2014-12-21 11:05:44 +0100 | [diff] [blame] | 3482 | case snd_soc_dapm_input: |
| 3483 | if (!dapm->card->fully_routed) |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 3484 | w->is_ep = SND_SOC_DAPM_EP_SOURCE; |
Lars-Peter Clausen | 86d7500 | 2014-12-21 11:05:44 +0100 | [diff] [blame] | 3485 | w->power_check = dapm_generic_check_power; |
| 3486 | break; |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 3487 | case snd_soc_dapm_spk: |
| 3488 | case snd_soc_dapm_hp: |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 3489 | w->is_ep = SND_SOC_DAPM_EP_SINK; |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 3490 | w->power_check = dapm_generic_check_power; |
| 3491 | break; |
Lars-Peter Clausen | 86d7500 | 2014-12-21 11:05:44 +0100 | [diff] [blame] | 3492 | case snd_soc_dapm_output: |
| 3493 | if (!dapm->card->fully_routed) |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 3494 | w->is_ep = SND_SOC_DAPM_EP_SINK; |
Lars-Peter Clausen | 86d7500 | 2014-12-21 11:05:44 +0100 | [diff] [blame] | 3495 | w->power_check = dapm_generic_check_power; |
| 3496 | break; |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 3497 | case snd_soc_dapm_vmid: |
| 3498 | case snd_soc_dapm_siggen: |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 3499 | w->is_ep = SND_SOC_DAPM_EP_SOURCE; |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 3500 | w->power_check = dapm_always_on_check_power; |
| 3501 | break; |
Vinod Koul | 56b4437 | 2015-11-23 21:22:30 +0530 | [diff] [blame] | 3502 | case snd_soc_dapm_sink: |
| 3503 | w->is_ep = SND_SOC_DAPM_EP_SINK; |
| 3504 | w->power_check = dapm_always_on_check_power; |
| 3505 | break; |
| 3506 | |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 3507 | case snd_soc_dapm_mux: |
Lars-Peter Clausen | d714f97 | 2015-05-01 18:02:43 +0200 | [diff] [blame] | 3508 | case snd_soc_dapm_demux: |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 3509 | case snd_soc_dapm_switch: |
| 3510 | case snd_soc_dapm_mixer: |
| 3511 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | 63c69a6 | 2013-07-18 22:03:01 +0100 | [diff] [blame] | 3512 | case snd_soc_dapm_adc: |
| 3513 | case snd_soc_dapm_aif_out: |
| 3514 | case snd_soc_dapm_dac: |
| 3515 | case snd_soc_dapm_aif_in: |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 3516 | case snd_soc_dapm_pga: |
| 3517 | case snd_soc_dapm_out_drv: |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 3518 | case snd_soc_dapm_micbias: |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 3519 | case snd_soc_dapm_line: |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3520 | case snd_soc_dapm_dai_link: |
Lars-Peter Clausen | cdef2ad | 2014-10-20 19:36:38 +0200 | [diff] [blame] | 3521 | case snd_soc_dapm_dai_out: |
| 3522 | case snd_soc_dapm_dai_in: |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 3523 | w->power_check = dapm_generic_check_power; |
| 3524 | break; |
| 3525 | case snd_soc_dapm_supply: |
Mark Brown | 62ea874 | 2012-01-21 21:14:48 +0000 | [diff] [blame] | 3526 | case snd_soc_dapm_regulator_supply: |
Srinivas Kandagatla | 5b2d15b | 2018-03-10 02:37:27 +0000 | [diff] [blame] | 3527 | case snd_soc_dapm_pinctrl: |
Ola Lilja | d7e7eb9 | 2012-05-24 15:26:25 +0200 | [diff] [blame] | 3528 | case snd_soc_dapm_clock_supply: |
Lars-Peter Clausen | 5729507 | 2013-08-05 11:27:31 +0200 | [diff] [blame] | 3529 | case snd_soc_dapm_kcontrol: |
Lars-Peter Clausen | 6dd98b0 | 2014-10-25 17:41:59 +0200 | [diff] [blame] | 3530 | w->is_supply = 1; |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 3531 | w->power_check = dapm_supply_check_power; |
| 3532 | break; |
| 3533 | default: |
| 3534 | w->power_check = dapm_always_on_check_power; |
| 3535 | break; |
| 3536 | } |
| 3537 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3538 | w->dapm = dapm; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3539 | INIT_LIST_HEAD(&w->list); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 3540 | INIT_LIST_HEAD(&w->dirty); |
Lars-Peter Clausen | 92fa124 | 2015-05-01 18:02:42 +0200 | [diff] [blame] | 3541 | list_add_tail(&w->list, &dapm->card->widgets); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3542 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 3543 | snd_soc_dapm_for_each_direction(dir) { |
| 3544 | INIT_LIST_HEAD(&w->edges[dir]); |
| 3545 | w->endpoints[dir] = -1; |
| 3546 | } |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 3547 | |
Peter Meerwald-Stadler | c804600 | 2016-08-16 16:56:17 +0200 | [diff] [blame] | 3548 | /* machine layer sets up unconnected pins and insertions */ |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3549 | w->connected = 1; |
Mark Brown | 5ba06fc | 2012-02-16 11:07:13 -0800 | [diff] [blame] | 3550 | return w; |
Charles Keepax | 3bbf5d3 | 2018-09-05 15:20:58 +0100 | [diff] [blame] | 3551 | |
| 3552 | request_failed: |
| 3553 | if (ret != -EPROBE_DEFER) |
| 3554 | dev_err(dapm->dev, "ASoC: Failed to request %s: %d\n", |
| 3555 | w->name, ret); |
| 3556 | |
| 3557 | return ERR_PTR(ret); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3558 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3559 | |
| 3560 | /** |
Charles Keepax | 94e630a | 2018-09-05 15:20:59 +0100 | [diff] [blame] | 3561 | * snd_soc_dapm_new_control - create new dapm control |
| 3562 | * @dapm: DAPM context |
| 3563 | * @widget: widget template |
| 3564 | * |
| 3565 | * Creates new DAPM control based upon a template. |
| 3566 | * |
| 3567 | * Returns a widget pointer on success or an error pointer on failure |
| 3568 | */ |
| 3569 | struct snd_soc_dapm_widget * |
| 3570 | snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, |
| 3571 | const struct snd_soc_dapm_widget *widget) |
| 3572 | { |
| 3573 | struct snd_soc_dapm_widget *w; |
| 3574 | |
| 3575 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
| 3576 | w = snd_soc_dapm_new_control_unlocked(dapm, widget); |
| 3577 | mutex_unlock(&dapm->card->dapm_mutex); |
| 3578 | |
| 3579 | return w; |
| 3580 | } |
| 3581 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control); |
| 3582 | |
| 3583 | /** |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 3584 | * snd_soc_dapm_new_controls - create new dapm controls |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3585 | * @dapm: DAPM context |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 3586 | * @widget: widget array |
| 3587 | * @num: number of widgets |
| 3588 | * |
| 3589 | * Creates new DAPM controls based upon the templates. |
| 3590 | * |
| 3591 | * Returns 0 for success else error. |
| 3592 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3593 | int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm, |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 3594 | const struct snd_soc_dapm_widget *widget, |
| 3595 | int num) |
| 3596 | { |
Mark Brown | 5ba06fc | 2012-02-16 11:07:13 -0800 | [diff] [blame] | 3597 | struct snd_soc_dapm_widget *w; |
| 3598 | int i; |
Dan Carpenter | 60884c2 | 2012-04-13 22:25:43 +0300 | [diff] [blame] | 3599 | int ret = 0; |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 3600 | |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3601 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 3602 | for (i = 0; i < num; i++) { |
Liam Girdwood | 02aa78a | 2015-05-25 18:21:17 +0100 | [diff] [blame] | 3603 | w = snd_soc_dapm_new_control_unlocked(dapm, widget); |
Linus Walleij | 37e1df8 | 2017-01-13 10:23:52 +0100 | [diff] [blame] | 3604 | if (IS_ERR(w)) { |
| 3605 | ret = PTR_ERR(w); |
Dan Carpenter | 60884c2 | 2012-04-13 22:25:43 +0300 | [diff] [blame] | 3606 | break; |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 3607 | } |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 3608 | widget++; |
| 3609 | } |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 3610 | mutex_unlock(&dapm->card->dapm_mutex); |
Dan Carpenter | 60884c2 | 2012-04-13 22:25:43 +0300 | [diff] [blame] | 3611 | return ret; |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 3612 | } |
| 3613 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); |
| 3614 | |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3615 | static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, |
| 3616 | struct snd_kcontrol *kcontrol, int event) |
| 3617 | { |
Charles Keepax | 4a75aae | 2018-09-05 15:21:01 +0100 | [diff] [blame] | 3618 | struct snd_soc_dapm_path *path; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3619 | struct snd_soc_dai *source, *sink; |
Charles Keepax | 249dc49 | 2018-08-15 13:11:35 +0100 | [diff] [blame] | 3620 | struct snd_soc_pcm_runtime *rtd = w->priv; |
Charles Keepax | 243bcfa | 2018-09-05 15:21:02 +0100 | [diff] [blame] | 3621 | const struct snd_soc_pcm_stream *config; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3622 | struct snd_pcm_substream substream; |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3623 | struct snd_pcm_hw_params *params = NULL; |
Nicolin Chen | 8053f21 | 2016-07-26 14:55:51 -0700 | [diff] [blame] | 3624 | struct snd_pcm_runtime *runtime = NULL; |
Takashi Iwai | 3ba66fe | 2018-07-25 22:43:26 +0200 | [diff] [blame] | 3625 | unsigned int fmt; |
Charles Keepax | fc269c0 | 2018-09-06 17:41:55 +0100 | [diff] [blame^] | 3626 | int ret = 0; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3627 | |
Charles Keepax | 243bcfa | 2018-09-05 15:21:02 +0100 | [diff] [blame] | 3628 | config = rtd->dai_link->params + rtd->params_select; |
| 3629 | |
Takashi Iwai | bf4edea | 2013-11-07 18:38:47 +0100 | [diff] [blame] | 3630 | if (WARN_ON(!config) || |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 3631 | WARN_ON(list_empty(&w->edges[SND_SOC_DAPM_DIR_OUT]) || |
| 3632 | list_empty(&w->edges[SND_SOC_DAPM_DIR_IN]))) |
Takashi Iwai | bf4edea | 2013-11-07 18:38:47 +0100 | [diff] [blame] | 3633 | return -EINVAL; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3634 | |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3635 | /* Be a little careful as we don't want to overflow the mask array */ |
| 3636 | if (config->formats) { |
| 3637 | fmt = ffs(config->formats) - 1; |
| 3638 | } else { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3639 | dev_warn(w->dapm->dev, "ASoC: Invalid format %llx specified\n", |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3640 | config->formats); |
| 3641 | fmt = 0; |
| 3642 | } |
| 3643 | |
| 3644 | /* Currently very limited parameter selection */ |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3645 | params = kzalloc(sizeof(*params), GFP_KERNEL); |
| 3646 | if (!params) { |
| 3647 | ret = -ENOMEM; |
| 3648 | goto out; |
| 3649 | } |
| 3650 | snd_mask_set(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), fmt); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3651 | |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3652 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->min = |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3653 | config->rate_min; |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3654 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE)->max = |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3655 | config->rate_max; |
| 3656 | |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3657 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->min |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3658 | = config->channels_min; |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3659 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS)->max |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3660 | = config->channels_max; |
| 3661 | |
| 3662 | memset(&substream, 0, sizeof(substream)); |
| 3663 | |
Nicolin Chen | 8053f21 | 2016-07-26 14:55:51 -0700 | [diff] [blame] | 3664 | /* Allocate a dummy snd_pcm_runtime for startup() and other ops() */ |
| 3665 | runtime = kzalloc(sizeof(*runtime), GFP_KERNEL); |
| 3666 | if (!runtime) { |
| 3667 | ret = -ENOMEM; |
| 3668 | goto out; |
| 3669 | } |
| 3670 | substream.runtime = runtime; |
Charles Keepax | 249dc49 | 2018-08-15 13:11:35 +0100 | [diff] [blame] | 3671 | substream.private_data = rtd; |
Nicolin Chen | 8053f21 | 2016-07-26 14:55:51 -0700 | [diff] [blame] | 3672 | |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3673 | switch (event) { |
| 3674 | case SND_SOC_DAPM_PRE_PMU: |
Benoit Cousson | 93e6958 | 2014-07-08 23:19:38 +0200 | [diff] [blame] | 3675 | substream.stream = SNDRV_PCM_STREAM_CAPTURE; |
Charles Keepax | 4a75aae | 2018-09-05 15:21:01 +0100 | [diff] [blame] | 3676 | snd_soc_dapm_widget_for_each_source_path(w, path) { |
| 3677 | source = path->source->priv; |
| 3678 | |
| 3679 | if (source->driver->ops->startup) { |
| 3680 | ret = source->driver->ops->startup(&substream, |
| 3681 | source); |
| 3682 | if (ret < 0) { |
| 3683 | dev_err(source->dev, |
| 3684 | "ASoC: startup() failed: %d\n", |
| 3685 | ret); |
| 3686 | goto out; |
| 3687 | } |
| 3688 | source->active++; |
Jeeja KP | 9b8ef9f | 2015-10-20 22:30:07 +0530 | [diff] [blame] | 3689 | } |
Charles Keepax | 4a75aae | 2018-09-05 15:21:01 +0100 | [diff] [blame] | 3690 | ret = soc_dai_hw_params(&substream, params, source); |
| 3691 | if (ret < 0) |
| 3692 | goto out; |
Jeeja KP | 9b8ef9f | 2015-10-20 22:30:07 +0530 | [diff] [blame] | 3693 | } |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3694 | |
Benoit Cousson | 93e6958 | 2014-07-08 23:19:38 +0200 | [diff] [blame] | 3695 | substream.stream = SNDRV_PCM_STREAM_PLAYBACK; |
Charles Keepax | 4a75aae | 2018-09-05 15:21:01 +0100 | [diff] [blame] | 3696 | snd_soc_dapm_widget_for_each_sink_path(w, path) { |
| 3697 | sink = path->sink->priv; |
| 3698 | |
| 3699 | if (sink->driver->ops->startup) { |
| 3700 | ret = sink->driver->ops->startup(&substream, |
| 3701 | sink); |
| 3702 | if (ret < 0) { |
| 3703 | dev_err(sink->dev, |
| 3704 | "ASoC: startup() failed: %d\n", |
| 3705 | ret); |
| 3706 | goto out; |
| 3707 | } |
| 3708 | sink->active++; |
Jeeja KP | 9b8ef9f | 2015-10-20 22:30:07 +0530 | [diff] [blame] | 3709 | } |
Charles Keepax | 4a75aae | 2018-09-05 15:21:01 +0100 | [diff] [blame] | 3710 | ret = soc_dai_hw_params(&substream, params, sink); |
| 3711 | if (ret < 0) |
| 3712 | goto out; |
Jeeja KP | 9b8ef9f | 2015-10-20 22:30:07 +0530 | [diff] [blame] | 3713 | } |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3714 | break; |
| 3715 | |
| 3716 | case SND_SOC_DAPM_POST_PMU: |
Charles Keepax | 4a75aae | 2018-09-05 15:21:01 +0100 | [diff] [blame] | 3717 | snd_soc_dapm_widget_for_each_sink_path(w, path) { |
| 3718 | sink = path->sink->priv; |
| 3719 | |
| 3720 | ret = snd_soc_dai_digital_mute(sink, 0, |
| 3721 | SNDRV_PCM_STREAM_PLAYBACK); |
| 3722 | if (ret != 0 && ret != -ENOTSUPP) |
| 3723 | dev_warn(sink->dev, |
| 3724 | "ASoC: Failed to unmute: %d\n", ret); |
| 3725 | ret = 0; |
| 3726 | } |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3727 | break; |
| 3728 | |
| 3729 | case SND_SOC_DAPM_PRE_PMD: |
Charles Keepax | 4a75aae | 2018-09-05 15:21:01 +0100 | [diff] [blame] | 3730 | snd_soc_dapm_widget_for_each_sink_path(w, path) { |
| 3731 | sink = path->sink->priv; |
Jeeja KP | 9b8ef9f | 2015-10-20 22:30:07 +0530 | [diff] [blame] | 3732 | |
Charles Keepax | 4a75aae | 2018-09-05 15:21:01 +0100 | [diff] [blame] | 3733 | ret = snd_soc_dai_digital_mute(sink, 1, |
| 3734 | SNDRV_PCM_STREAM_PLAYBACK); |
| 3735 | if (ret != 0 && ret != -ENOTSUPP) |
| 3736 | dev_warn(sink->dev, |
| 3737 | "ASoC: Failed to mute: %d\n", ret); |
| 3738 | ret = 0; |
Jeeja KP | 9b8ef9f | 2015-10-20 22:30:07 +0530 | [diff] [blame] | 3739 | } |
| 3740 | |
Charles Keepax | 4a75aae | 2018-09-05 15:21:01 +0100 | [diff] [blame] | 3741 | snd_soc_dapm_widget_for_each_source_path(w, path) { |
| 3742 | source = path->source->priv; |
| 3743 | |
| 3744 | source->active--; |
| 3745 | if (source->driver->ops->shutdown) { |
| 3746 | substream.stream = SNDRV_PCM_STREAM_CAPTURE; |
| 3747 | source->driver->ops->shutdown(&substream, |
| 3748 | source); |
| 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | snd_soc_dapm_widget_for_each_sink_path(w, path) { |
| 3753 | sink = path->sink->priv; |
| 3754 | |
| 3755 | sink->active--; |
| 3756 | if (sink->driver->ops->shutdown) { |
| 3757 | substream.stream = SNDRV_PCM_STREAM_PLAYBACK; |
| 3758 | sink->driver->ops->shutdown(&substream, sink); |
| 3759 | } |
Jeeja KP | 9b8ef9f | 2015-10-20 22:30:07 +0530 | [diff] [blame] | 3760 | } |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3761 | break; |
| 3762 | |
| 3763 | default: |
Takashi Iwai | a6ed060 | 2013-11-06 11:07:19 +0100 | [diff] [blame] | 3764 | WARN(1, "Unknown event %d\n", event); |
Sudip Mukherjee | 75881df | 2015-09-10 18:01:44 +0530 | [diff] [blame] | 3765 | ret = -EINVAL; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3766 | } |
| 3767 | |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3768 | out: |
Nicolin Chen | 8053f21 | 2016-07-26 14:55:51 -0700 | [diff] [blame] | 3769 | kfree(runtime); |
Mark Brown | 9747cec | 2012-04-26 19:12:21 +0100 | [diff] [blame] | 3770 | kfree(params); |
| 3771 | return ret; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3772 | } |
| 3773 | |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3774 | static int snd_soc_dapm_dai_link_get(struct snd_kcontrol *kcontrol, |
| 3775 | struct snd_ctl_elem_value *ucontrol) |
| 3776 | { |
| 3777 | struct snd_soc_dapm_widget *w = snd_kcontrol_chip(kcontrol); |
Charles Keepax | 243bcfa | 2018-09-05 15:21:02 +0100 | [diff] [blame] | 3778 | struct snd_soc_pcm_runtime *rtd = w->priv; |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3779 | |
Charles Keepax | 243bcfa | 2018-09-05 15:21:02 +0100 | [diff] [blame] | 3780 | ucontrol->value.enumerated.item[0] = rtd->params_select; |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3781 | |
| 3782 | return 0; |
| 3783 | } |
| 3784 | |
| 3785 | static int snd_soc_dapm_dai_link_put(struct snd_kcontrol *kcontrol, |
| 3786 | struct snd_ctl_elem_value *ucontrol) |
| 3787 | { |
| 3788 | struct snd_soc_dapm_widget *w = snd_kcontrol_chip(kcontrol); |
Charles Keepax | 243bcfa | 2018-09-05 15:21:02 +0100 | [diff] [blame] | 3789 | struct snd_soc_pcm_runtime *rtd = w->priv; |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3790 | |
| 3791 | /* Can't change the config when widget is already powered */ |
| 3792 | if (w->power) |
| 3793 | return -EBUSY; |
| 3794 | |
Charles Keepax | 243bcfa | 2018-09-05 15:21:02 +0100 | [diff] [blame] | 3795 | if (ucontrol->value.enumerated.item[0] == rtd->params_select) |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3796 | return 0; |
| 3797 | |
Charles Keepax | 243bcfa | 2018-09-05 15:21:02 +0100 | [diff] [blame] | 3798 | if (ucontrol->value.enumerated.item[0] >= rtd->dai_link->num_params) |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3799 | return -EINVAL; |
| 3800 | |
Charles Keepax | 243bcfa | 2018-09-05 15:21:02 +0100 | [diff] [blame] | 3801 | rtd->params_select = ucontrol->value.enumerated.item[0]; |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3802 | |
| 3803 | return 0; |
| 3804 | } |
| 3805 | |
Arnd Bergmann | c42c5ac | 2017-10-10 11:20:11 +0200 | [diff] [blame] | 3806 | static void |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3807 | snd_soc_dapm_free_kcontrol(struct snd_soc_card *card, |
| 3808 | unsigned long *private_value, |
| 3809 | int num_params, |
| 3810 | const char **w_param_text) |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3811 | { |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3812 | int count; |
| 3813 | |
| 3814 | devm_kfree(card->dev, (void *)*private_value); |
| 3815 | for (count = 0 ; count < num_params; count++) |
| 3816 | devm_kfree(card->dev, (void *)w_param_text[count]); |
| 3817 | devm_kfree(card->dev, w_param_text); |
| 3818 | } |
| 3819 | |
| 3820 | static struct snd_kcontrol_new * |
| 3821 | snd_soc_dapm_alloc_kcontrol(struct snd_soc_card *card, |
| 3822 | char *link_name, |
| 3823 | const struct snd_soc_pcm_stream *params, |
| 3824 | int num_params, const char **w_param_text, |
| 3825 | unsigned long *private_value) |
| 3826 | { |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3827 | struct soc_enum w_param_enum[] = { |
| 3828 | SOC_ENUM_SINGLE(0, 0, 0, NULL), |
| 3829 | }; |
| 3830 | struct snd_kcontrol_new kcontrol_dai_link[] = { |
| 3831 | SOC_ENUM_EXT(NULL, w_param_enum[0], |
| 3832 | snd_soc_dapm_dai_link_get, |
| 3833 | snd_soc_dapm_dai_link_put), |
| 3834 | }; |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3835 | struct snd_kcontrol_new *kcontrol_news; |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3836 | const struct snd_soc_pcm_stream *config = params; |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3837 | int count; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3838 | |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3839 | for (count = 0 ; count < num_params; count++) { |
| 3840 | if (!config->stream_name) { |
| 3841 | dev_warn(card->dapm.dev, |
| 3842 | "ASoC: anonymous config %d for dai link %s\n", |
| 3843 | count, link_name); |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3844 | w_param_text[count] = |
Charles Keepax | 46172b6 | 2015-03-25 11:22:35 +0000 | [diff] [blame] | 3845 | devm_kasprintf(card->dev, GFP_KERNEL, |
| 3846 | "Anonymous Configuration %d", |
| 3847 | count); |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3848 | } else { |
| 3849 | w_param_text[count] = devm_kmemdup(card->dev, |
| 3850 | config->stream_name, |
| 3851 | strlen(config->stream_name) + 1, |
| 3852 | GFP_KERNEL); |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3853 | } |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3854 | if (!w_param_text[count]) |
| 3855 | goto outfree_w_param; |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3856 | config++; |
| 3857 | } |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3858 | |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3859 | w_param_enum[0].items = num_params; |
| 3860 | w_param_enum[0].texts = w_param_text; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3861 | |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3862 | *private_value = |
| 3863 | (unsigned long) devm_kmemdup(card->dev, |
| 3864 | (void *)(kcontrol_dai_link[0].private_value), |
| 3865 | sizeof(struct soc_enum), GFP_KERNEL); |
| 3866 | if (!*private_value) { |
| 3867 | dev_err(card->dev, "ASoC: Failed to create control for %s widget\n", |
| 3868 | link_name); |
| 3869 | goto outfree_w_param; |
| 3870 | } |
| 3871 | kcontrol_dai_link[0].private_value = *private_value; |
| 3872 | /* duplicate kcontrol_dai_link on heap so that memory persists */ |
| 3873 | kcontrol_news = devm_kmemdup(card->dev, &kcontrol_dai_link[0], |
| 3874 | sizeof(struct snd_kcontrol_new), |
| 3875 | GFP_KERNEL); |
| 3876 | if (!kcontrol_news) { |
| 3877 | dev_err(card->dev, "ASoC: Failed to create control for %s widget\n", |
| 3878 | link_name); |
| 3879 | goto outfree_w_param; |
| 3880 | } |
| 3881 | return kcontrol_news; |
| 3882 | |
| 3883 | outfree_w_param: |
| 3884 | snd_soc_dapm_free_kcontrol(card, private_value, num_params, w_param_text); |
| 3885 | return NULL; |
| 3886 | } |
| 3887 | |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 3888 | static struct snd_soc_dapm_widget * |
| 3889 | snd_soc_dapm_new_dai(struct snd_soc_card *card, struct snd_soc_pcm_runtime *rtd, |
| 3890 | struct snd_soc_dapm_widget *source, |
| 3891 | struct snd_soc_dapm_widget *sink) |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3892 | { |
| 3893 | struct snd_soc_dapm_widget template; |
| 3894 | struct snd_soc_dapm_widget *w; |
| 3895 | const char **w_param_text; |
| 3896 | unsigned long private_value; |
| 3897 | char *link_name; |
| 3898 | int ret; |
| 3899 | |
| 3900 | link_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s-%s", |
| 3901 | source->name, sink->name); |
| 3902 | if (!link_name) |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 3903 | return ERR_PTR(-ENOMEM); |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3904 | |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3905 | memset(&template, 0, sizeof(template)); |
| 3906 | template.reg = SND_SOC_NOPM; |
| 3907 | template.id = snd_soc_dapm_dai_link; |
| 3908 | template.name = link_name; |
| 3909 | template.event = snd_soc_dai_link_event; |
| 3910 | template.event_flags = SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | |
| 3911 | SND_SOC_DAPM_PRE_PMD; |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3912 | template.kcontrol_news = NULL; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3913 | |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3914 | /* allocate memory for control, only in case of multiple configs */ |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 3915 | if (rtd->dai_link->num_params > 1) { |
| 3916 | w_param_text = devm_kcalloc(card->dev, |
| 3917 | rtd->dai_link->num_params, |
| 3918 | sizeof(char *), GFP_KERNEL); |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3919 | if (!w_param_text) { |
| 3920 | ret = -ENOMEM; |
| 3921 | goto param_fail; |
| 3922 | } |
| 3923 | |
| 3924 | template.num_kcontrols = 1; |
| 3925 | template.kcontrol_news = |
| 3926 | snd_soc_dapm_alloc_kcontrol(card, |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 3927 | link_name, |
| 3928 | rtd->dai_link->params, |
| 3929 | rtd->dai_link->num_params, |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3930 | w_param_text, &private_value); |
| 3931 | if (!template.kcontrol_news) { |
| 3932 | ret = -ENOMEM; |
| 3933 | goto param_fail; |
| 3934 | } |
Arnd Bergmann | 667ebc9 | 2017-10-10 11:20:10 +0200 | [diff] [blame] | 3935 | } else { |
| 3936 | w_param_text = NULL; |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3937 | } |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3938 | dev_dbg(card->dev, "ASoC: adding %s widget\n", link_name); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3939 | |
Liam Girdwood | 02aa78a | 2015-05-25 18:21:17 +0100 | [diff] [blame] | 3940 | w = snd_soc_dapm_new_control_unlocked(&card->dapm, &template); |
Charles Keepax | 3bbf5d3 | 2018-09-05 15:20:58 +0100 | [diff] [blame] | 3941 | if (IS_ERR(w)) |
Linus Walleij | 37e1df8 | 2017-01-13 10:23:52 +0100 | [diff] [blame] | 3942 | goto outfree_kcontrol_news; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3943 | |
Charles Keepax | 249dc49 | 2018-08-15 13:11:35 +0100 | [diff] [blame] | 3944 | w->priv = rtd; |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3945 | |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 3946 | return w; |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3947 | |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3948 | outfree_kcontrol_news: |
| 3949 | devm_kfree(card->dev, (void *)template.kcontrol_news); |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 3950 | snd_soc_dapm_free_kcontrol(card, &private_value, |
| 3951 | rtd->dai_link->num_params, w_param_text); |
anish kumar | 19ad683 | 2017-09-28 21:52:39 -0700 | [diff] [blame] | 3952 | param_fail: |
Nikesh Oswal | c661508 | 2015-02-02 17:06:44 +0000 | [diff] [blame] | 3953 | devm_kfree(card->dev, link_name); |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 3954 | return ERR_PTR(ret); |
Mark Brown | c74184e | 2012-04-04 22:12:09 +0100 | [diff] [blame] | 3955 | } |
| 3956 | |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3957 | int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm, |
| 3958 | struct snd_soc_dai *dai) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3959 | { |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3960 | struct snd_soc_dapm_widget template; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3961 | struct snd_soc_dapm_widget *w; |
| 3962 | |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3963 | WARN_ON(dapm->dev != dai->dev); |
| 3964 | |
| 3965 | memset(&template, 0, sizeof(template)); |
| 3966 | template.reg = SND_SOC_NOPM; |
| 3967 | |
| 3968 | if (dai->driver->playback.stream_name) { |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 3969 | template.id = snd_soc_dapm_dai_in; |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3970 | template.name = dai->driver->playback.stream_name; |
| 3971 | template.sname = dai->driver->playback.stream_name; |
| 3972 | |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3973 | dev_dbg(dai->dev, "ASoC: adding %s widget\n", |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3974 | template.name); |
| 3975 | |
Liam Girdwood | 02aa78a | 2015-05-25 18:21:17 +0100 | [diff] [blame] | 3976 | w = snd_soc_dapm_new_control_unlocked(dapm, &template); |
Charles Keepax | 3bbf5d3 | 2018-09-05 15:20:58 +0100 | [diff] [blame] | 3977 | if (IS_ERR(w)) |
| 3978 | return PTR_ERR(w); |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3979 | |
| 3980 | w->priv = dai; |
| 3981 | dai->playback_widget = w; |
| 3982 | } |
| 3983 | |
| 3984 | if (dai->driver->capture.stream_name) { |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 3985 | template.id = snd_soc_dapm_dai_out; |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3986 | template.name = dai->driver->capture.stream_name; |
| 3987 | template.sname = dai->driver->capture.stream_name; |
| 3988 | |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 3989 | dev_dbg(dai->dev, "ASoC: adding %s widget\n", |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3990 | template.name); |
| 3991 | |
Liam Girdwood | 02aa78a | 2015-05-25 18:21:17 +0100 | [diff] [blame] | 3992 | w = snd_soc_dapm_new_control_unlocked(dapm, &template); |
Charles Keepax | 3bbf5d3 | 2018-09-05 15:20:58 +0100 | [diff] [blame] | 3993 | if (IS_ERR(w)) |
| 3994 | return PTR_ERR(w); |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 3995 | |
| 3996 | w->priv = dai; |
| 3997 | dai->capture_widget = w; |
| 3998 | } |
| 3999 | |
| 4000 | return 0; |
| 4001 | } |
| 4002 | |
| 4003 | int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card) |
| 4004 | { |
| 4005 | struct snd_soc_dapm_widget *dai_w, *w; |
Lars-Peter Clausen | 0f9bd7b | 2014-05-07 16:20:28 +0200 | [diff] [blame] | 4006 | struct snd_soc_dapm_widget *src, *sink; |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 4007 | struct snd_soc_dai *dai; |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 4008 | |
| 4009 | /* For each DAI widget... */ |
| 4010 | list_for_each_entry(dai_w, &card->widgets, list) { |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 4011 | switch (dai_w->id) { |
| 4012 | case snd_soc_dapm_dai_in: |
| 4013 | case snd_soc_dapm_dai_out: |
| 4014 | break; |
| 4015 | default: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4016 | continue; |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 4017 | } |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 4018 | |
Liam Girdwood | e01b4f6 | 2018-06-14 20:26:42 +0100 | [diff] [blame] | 4019 | /* let users know there is no DAI to link */ |
| 4020 | if (!dai_w->priv) { |
| 4021 | dev_dbg(card->dev, "dai widget %s has no DAI\n", |
| 4022 | dai_w->name); |
| 4023 | continue; |
| 4024 | } |
| 4025 | |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 4026 | dai = dai_w->priv; |
| 4027 | |
| 4028 | /* ...find all widgets with the same stream and link them */ |
| 4029 | list_for_each_entry(w, &card->widgets, list) { |
| 4030 | if (w->dapm != dai_w->dapm) |
| 4031 | continue; |
| 4032 | |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 4033 | switch (w->id) { |
| 4034 | case snd_soc_dapm_dai_in: |
| 4035 | case snd_soc_dapm_dai_out: |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 4036 | continue; |
Mark Brown | 4616274 | 2013-06-05 19:36:11 +0100 | [diff] [blame] | 4037 | default: |
| 4038 | break; |
| 4039 | } |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 4040 | |
Lars-Peter Clausen | a798c24 | 2015-07-21 11:51:35 +0200 | [diff] [blame] | 4041 | if (!w->sname || !strstr(w->sname, dai_w->sname)) |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 4042 | continue; |
| 4043 | |
Lars-Peter Clausen | 0f9bd7b | 2014-05-07 16:20:28 +0200 | [diff] [blame] | 4044 | if (dai_w->id == snd_soc_dapm_dai_in) { |
| 4045 | src = dai_w; |
| 4046 | sink = w; |
| 4047 | } else { |
| 4048 | src = w; |
| 4049 | sink = dai_w; |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 4050 | } |
Lars-Peter Clausen | 0f9bd7b | 2014-05-07 16:20:28 +0200 | [diff] [blame] | 4051 | dev_dbg(dai->dev, "%s -> %s\n", src->name, sink->name); |
| 4052 | snd_soc_dapm_add_path(w->dapm, src, sink, NULL, NULL); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4053 | } |
| 4054 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4055 | |
Mark Brown | 888df39 | 2012-02-16 19:37:51 -0800 | [diff] [blame] | 4056 | return 0; |
| 4057 | } |
Liam Girdwood | 64a648c | 2011-07-25 11:15:15 +0100 | [diff] [blame] | 4058 | |
Benoit Cousson | 44ba264 | 2014-07-08 23:19:36 +0200 | [diff] [blame] | 4059 | static void dapm_connect_dai_link_widgets(struct snd_soc_card *card, |
| 4060 | struct snd_soc_pcm_runtime *rtd) |
Liam Girdwood | b893ea5 | 2014-01-08 10:40:19 +0000 | [diff] [blame] | 4061 | { |
Benoit Cousson | 44ba264 | 2014-07-08 23:19:36 +0200 | [diff] [blame] | 4062 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 4063 | struct snd_soc_dai *codec_dai; |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 4064 | struct snd_soc_dapm_widget *playback = NULL, *capture = NULL; |
| 4065 | struct snd_soc_dapm_widget *codec, *playback_cpu, *capture_cpu; |
Liam Girdwood | b893ea5 | 2014-01-08 10:40:19 +0000 | [diff] [blame] | 4066 | int i; |
| 4067 | |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 4068 | if (rtd->dai_link->params) { |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 4069 | playback_cpu = cpu_dai->capture_widget; |
| 4070 | capture_cpu = cpu_dai->playback_widget; |
| 4071 | } else { |
| 4072 | playback = cpu_dai->playback_widget; |
| 4073 | capture = cpu_dai->capture_widget; |
| 4074 | playback_cpu = playback; |
| 4075 | capture_cpu = capture; |
| 4076 | } |
| 4077 | |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 4078 | for_each_rtd_codec_dai(rtd, i, codec_dai) { |
Liam Girdwood | b893ea5 | 2014-01-08 10:40:19 +0000 | [diff] [blame] | 4079 | |
Liam Girdwood | b893ea5 | 2014-01-08 10:40:19 +0000 | [diff] [blame] | 4080 | /* connect BE DAI playback if widgets are valid */ |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 4081 | codec = codec_dai->playback_widget; |
Liam Girdwood | b893ea5 | 2014-01-08 10:40:19 +0000 | [diff] [blame] | 4082 | |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 4083 | if (playback_cpu && codec) { |
| 4084 | if (!playback) { |
| 4085 | playback = snd_soc_dapm_new_dai(card, rtd, |
| 4086 | playback_cpu, |
| 4087 | codec); |
| 4088 | |
| 4089 | snd_soc_dapm_add_path(&card->dapm, playback_cpu, |
| 4090 | playback, NULL, NULL); |
| 4091 | } |
| 4092 | |
| 4093 | dev_dbg(rtd->dev, "connected DAI link %s:%s -> %s:%s\n", |
| 4094 | cpu_dai->component->name, playback_cpu->name, |
| 4095 | codec_dai->component->name, codec->name); |
| 4096 | |
| 4097 | snd_soc_dapm_add_path(&card->dapm, playback, codec, |
| 4098 | NULL, NULL); |
Liam Girdwood | b893ea5 | 2014-01-08 10:40:19 +0000 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | /* connect BE DAI capture if widgets are valid */ |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 4102 | codec = codec_dai->capture_widget; |
Liam Girdwood | b893ea5 | 2014-01-08 10:40:19 +0000 | [diff] [blame] | 4103 | |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 4104 | if (codec && capture_cpu) { |
| 4105 | if (!capture) { |
| 4106 | capture = snd_soc_dapm_new_dai(card, rtd, |
| 4107 | codec, |
| 4108 | capture_cpu); |
| 4109 | |
| 4110 | snd_soc_dapm_add_path(&card->dapm, capture, |
| 4111 | capture_cpu, NULL, NULL); |
| 4112 | } |
| 4113 | |
| 4114 | dev_dbg(rtd->dev, "connected DAI link %s:%s -> %s:%s\n", |
| 4115 | codec_dai->component->name, codec->name, |
| 4116 | cpu_dai->component->name, capture_cpu->name); |
| 4117 | |
| 4118 | snd_soc_dapm_add_path(&card->dapm, codec, capture, |
| 4119 | NULL, NULL); |
Liam Girdwood | b893ea5 | 2014-01-08 10:40:19 +0000 | [diff] [blame] | 4120 | } |
Liam Girdwood | b893ea5 | 2014-01-08 10:40:19 +0000 | [diff] [blame] | 4121 | } |
| 4122 | } |
Liam Girdwood | b893ea5 | 2014-01-08 10:40:19 +0000 | [diff] [blame] | 4123 | |
Lars-Peter Clausen | c471fdd | 2014-04-29 14:51:22 +0200 | [diff] [blame] | 4124 | static void soc_dapm_dai_stream_event(struct snd_soc_dai *dai, int stream, |
| 4125 | int event) |
| 4126 | { |
| 4127 | struct snd_soc_dapm_widget *w; |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 4128 | unsigned int ep; |
Lars-Peter Clausen | c471fdd | 2014-04-29 14:51:22 +0200 | [diff] [blame] | 4129 | |
| 4130 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 4131 | w = dai->playback_widget; |
| 4132 | else |
| 4133 | w = dai->capture_widget; |
| 4134 | |
| 4135 | if (w) { |
| 4136 | dapm_mark_dirty(w, "stream event"); |
| 4137 | |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 4138 | if (w->id == snd_soc_dapm_dai_in) { |
| 4139 | ep = SND_SOC_DAPM_EP_SOURCE; |
| 4140 | dapm_widget_invalidate_input_paths(w); |
| 4141 | } else { |
| 4142 | ep = SND_SOC_DAPM_EP_SINK; |
| 4143 | dapm_widget_invalidate_output_paths(w); |
| 4144 | } |
| 4145 | |
Lars-Peter Clausen | c471fdd | 2014-04-29 14:51:22 +0200 | [diff] [blame] | 4146 | switch (event) { |
| 4147 | case SND_SOC_DAPM_STREAM_START: |
| 4148 | w->active = 1; |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 4149 | w->is_ep = ep; |
Lars-Peter Clausen | c471fdd | 2014-04-29 14:51:22 +0200 | [diff] [blame] | 4150 | break; |
| 4151 | case SND_SOC_DAPM_STREAM_STOP: |
| 4152 | w->active = 0; |
Lars-Peter Clausen | a3423b0 | 2015-08-11 21:38:00 +0200 | [diff] [blame] | 4153 | w->is_ep = 0; |
Lars-Peter Clausen | c471fdd | 2014-04-29 14:51:22 +0200 | [diff] [blame] | 4154 | break; |
| 4155 | case SND_SOC_DAPM_STREAM_SUSPEND: |
| 4156 | case SND_SOC_DAPM_STREAM_RESUME: |
| 4157 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: |
| 4158 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: |
| 4159 | break; |
| 4160 | } |
Liam Girdwood | b893ea5 | 2014-01-08 10:40:19 +0000 | [diff] [blame] | 4161 | } |
| 4162 | } |
| 4163 | |
Benoit Cousson | 44ba264 | 2014-07-08 23:19:36 +0200 | [diff] [blame] | 4164 | void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card) |
| 4165 | { |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 4166 | struct snd_soc_pcm_runtime *rtd; |
Benoit Cousson | 44ba264 | 2014-07-08 23:19:36 +0200 | [diff] [blame] | 4167 | |
| 4168 | /* for each BE DAI link... */ |
Mengdong Lin | 1a49798 | 2015-11-18 02:34:11 -0500 | [diff] [blame] | 4169 | list_for_each_entry(rtd, &card->rtd_list, list) { |
Benoit Cousson | 44ba264 | 2014-07-08 23:19:36 +0200 | [diff] [blame] | 4170 | /* |
| 4171 | * dynamic FE links have no fixed DAI mapping. |
| 4172 | * CODEC<->CODEC links have no direct connection. |
| 4173 | */ |
Charles Keepax | 778ff5b | 2018-09-05 15:21:00 +0100 | [diff] [blame] | 4174 | if (rtd->dai_link->dynamic) |
Benoit Cousson | 44ba264 | 2014-07-08 23:19:36 +0200 | [diff] [blame] | 4175 | continue; |
| 4176 | |
| 4177 | dapm_connect_dai_link_widgets(card, rtd); |
| 4178 | } |
| 4179 | } |
| 4180 | |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 4181 | static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, |
| 4182 | int event) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4183 | { |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 4184 | struct snd_soc_dai *codec_dai; |
Benoit Cousson | 44ba264 | 2014-07-08 23:19:36 +0200 | [diff] [blame] | 4185 | int i; |
| 4186 | |
Lars-Peter Clausen | c471fdd | 2014-04-29 14:51:22 +0200 | [diff] [blame] | 4187 | soc_dapm_dai_stream_event(rtd->cpu_dai, stream, event); |
Kuninori Morimoto | 0b7990e | 2018-09-03 02:12:56 +0000 | [diff] [blame] | 4188 | for_each_rtd_codec_dai(rtd, i, codec_dai) |
| 4189 | soc_dapm_dai_stream_event(codec_dai, stream, event); |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 4190 | |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 4191 | dapm_power_widgets(rtd->card, event); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4192 | } |
| 4193 | |
| 4194 | /** |
| 4195 | * snd_soc_dapm_stream_event - send a stream event to the dapm core |
| 4196 | * @rtd: PCM runtime data |
| 4197 | * @stream: stream name |
| 4198 | * @event: stream event |
| 4199 | * |
| 4200 | * Sends a stream event to the dapm core. The core then makes any |
| 4201 | * necessary widget power changes. |
| 4202 | * |
| 4203 | * Returns 0 for success else error. |
| 4204 | */ |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 4205 | void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, |
| 4206 | int event) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4207 | { |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 4208 | struct snd_soc_card *card = rtd->card; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4209 | |
Liam Girdwood | 3cd0434 | 2012-03-09 12:02:08 +0000 | [diff] [blame] | 4210 | mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Liam Girdwood | d9b0951 | 2012-03-07 16:32:59 +0000 | [diff] [blame] | 4211 | soc_dapm_stream_event(rtd, stream, event); |
Liam Girdwood | a73fb2d | 2012-03-07 10:38:26 +0000 | [diff] [blame] | 4212 | mutex_unlock(&card->dapm_mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4213 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4214 | |
| 4215 | /** |
Charles Keepax | 1139110 | 2014-02-18 15:22:14 +0000 | [diff] [blame] | 4216 | * snd_soc_dapm_enable_pin_unlocked - enable pin. |
| 4217 | * @dapm: DAPM context |
| 4218 | * @pin: pin name |
| 4219 | * |
| 4220 | * Enables input/output pin and its parents or children widgets iff there is |
| 4221 | * a valid audio route and active audio stream. |
| 4222 | * |
| 4223 | * Requires external locking. |
| 4224 | * |
| 4225 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 4226 | * do any widget power switching. |
| 4227 | */ |
| 4228 | int snd_soc_dapm_enable_pin_unlocked(struct snd_soc_dapm_context *dapm, |
| 4229 | const char *pin) |
| 4230 | { |
| 4231 | return snd_soc_dapm_set_pin(dapm, pin, 1); |
| 4232 | } |
| 4233 | EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin_unlocked); |
| 4234 | |
| 4235 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 4236 | * snd_soc_dapm_enable_pin - enable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4237 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 4238 | * @pin: pin name |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4239 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 4240 | * Enables input/output pin and its parents or children widgets iff there is |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 4241 | * a valid audio route and active audio stream. |
Charles Keepax | 1139110 | 2014-02-18 15:22:14 +0000 | [diff] [blame] | 4242 | * |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 4243 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 4244 | * do any widget power switching. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4245 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4246 | int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4247 | { |
Charles Keepax | 1139110 | 2014-02-18 15:22:14 +0000 | [diff] [blame] | 4248 | int ret; |
| 4249 | |
| 4250 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
| 4251 | |
| 4252 | ret = snd_soc_dapm_set_pin(dapm, pin, 1); |
| 4253 | |
| 4254 | mutex_unlock(&dapm->card->dapm_mutex); |
| 4255 | |
| 4256 | return ret; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4257 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 4258 | EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4259 | |
| 4260 | /** |
Charles Keepax | 1139110 | 2014-02-18 15:22:14 +0000 | [diff] [blame] | 4261 | * snd_soc_dapm_force_enable_pin_unlocked - force a pin to be enabled |
| 4262 | * @dapm: DAPM context |
| 4263 | * @pin: pin name |
| 4264 | * |
| 4265 | * Enables input/output pin regardless of any other state. This is |
| 4266 | * intended for use with microphone bias supplies used in microphone |
| 4267 | * jack detection. |
| 4268 | * |
| 4269 | * Requires external locking. |
| 4270 | * |
| 4271 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 4272 | * do any widget power switching. |
| 4273 | */ |
| 4274 | int snd_soc_dapm_force_enable_pin_unlocked(struct snd_soc_dapm_context *dapm, |
| 4275 | const char *pin) |
| 4276 | { |
| 4277 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
| 4278 | |
| 4279 | if (!w) { |
| 4280 | dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin); |
| 4281 | return -EINVAL; |
| 4282 | } |
| 4283 | |
| 4284 | dev_dbg(w->dapm->dev, "ASoC: force enable pin %s\n", pin); |
Lars-Peter Clausen | 92a99ea | 2014-10-25 17:42:03 +0200 | [diff] [blame] | 4285 | if (!w->connected) { |
| 4286 | /* |
| 4287 | * w->force does not affect the number of input or output paths, |
| 4288 | * so we only have to recheck if w->connected is changed |
| 4289 | */ |
| 4290 | dapm_widget_invalidate_input_paths(w); |
| 4291 | dapm_widget_invalidate_output_paths(w); |
| 4292 | w->connected = 1; |
| 4293 | } |
Charles Keepax | 1139110 | 2014-02-18 15:22:14 +0000 | [diff] [blame] | 4294 | w->force = 1; |
| 4295 | dapm_mark_dirty(w, "force enable"); |
| 4296 | |
| 4297 | return 0; |
| 4298 | } |
| 4299 | EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin_unlocked); |
| 4300 | |
| 4301 | /** |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 4302 | * snd_soc_dapm_force_enable_pin - force a pin to be enabled |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4303 | * @dapm: DAPM context |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 4304 | * @pin: pin name |
| 4305 | * |
| 4306 | * Enables input/output pin regardless of any other state. This is |
| 4307 | * intended for use with microphone bias supplies used in microphone |
| 4308 | * jack detection. |
| 4309 | * |
| 4310 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 4311 | * do any widget power switching. |
| 4312 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4313 | int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm, |
| 4314 | const char *pin) |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 4315 | { |
Charles Keepax | 1139110 | 2014-02-18 15:22:14 +0000 | [diff] [blame] | 4316 | int ret; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 4317 | |
Charles Keepax | 1139110 | 2014-02-18 15:22:14 +0000 | [diff] [blame] | 4318 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 4319 | |
Charles Keepax | 1139110 | 2014-02-18 15:22:14 +0000 | [diff] [blame] | 4320 | ret = snd_soc_dapm_force_enable_pin_unlocked(dapm, pin); |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 4321 | |
Charles Keepax | 1139110 | 2014-02-18 15:22:14 +0000 | [diff] [blame] | 4322 | mutex_unlock(&dapm->card->dapm_mutex); |
| 4323 | |
| 4324 | return ret; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 4325 | } |
| 4326 | EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin); |
| 4327 | |
| 4328 | /** |
Charles Keepax | 1139110 | 2014-02-18 15:22:14 +0000 | [diff] [blame] | 4329 | * snd_soc_dapm_disable_pin_unlocked - disable pin. |
| 4330 | * @dapm: DAPM context |
| 4331 | * @pin: pin name |
| 4332 | * |
| 4333 | * Disables input/output pin and its parents or children widgets. |
| 4334 | * |
| 4335 | * Requires external locking. |
| 4336 | * |
| 4337 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 4338 | * do any widget power switching. |
| 4339 | */ |
| 4340 | int snd_soc_dapm_disable_pin_unlocked(struct snd_soc_dapm_context *dapm, |
| 4341 | const char *pin) |
| 4342 | { |
| 4343 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
| 4344 | } |
| 4345 | EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin_unlocked); |
| 4346 | |
| 4347 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 4348 | * snd_soc_dapm_disable_pin - disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4349 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 4350 | * @pin: pin name |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 4351 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 4352 | * Disables input/output pin and its parents or children widgets. |
Charles Keepax | 1139110 | 2014-02-18 15:22:14 +0000 | [diff] [blame] | 4353 | * |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 4354 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 4355 | * do any widget power switching. |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 4356 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4357 | int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm, |
| 4358 | const char *pin) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 4359 | { |
Charles Keepax | 1139110 | 2014-02-18 15:22:14 +0000 | [diff] [blame] | 4360 | int ret; |
| 4361 | |
| 4362 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
| 4363 | |
| 4364 | ret = snd_soc_dapm_set_pin(dapm, pin, 0); |
| 4365 | |
| 4366 | mutex_unlock(&dapm->card->dapm_mutex); |
| 4367 | |
| 4368 | return ret; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 4369 | } |
| 4370 | EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin); |
| 4371 | |
| 4372 | /** |
Charles Keepax | 1139110 | 2014-02-18 15:22:14 +0000 | [diff] [blame] | 4373 | * snd_soc_dapm_nc_pin_unlocked - permanently disable pin. |
| 4374 | * @dapm: DAPM context |
| 4375 | * @pin: pin name |
| 4376 | * |
| 4377 | * Marks the specified pin as being not connected, disabling it along |
| 4378 | * any parent or child widgets. At present this is identical to |
| 4379 | * snd_soc_dapm_disable_pin() but in future it will be extended to do |
| 4380 | * additional things such as disabling controls which only affect |
| 4381 | * paths through the pin. |
| 4382 | * |
| 4383 | * Requires external locking. |
| 4384 | * |
| 4385 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 4386 | * do any widget power switching. |
| 4387 | */ |
| 4388 | int snd_soc_dapm_nc_pin_unlocked(struct snd_soc_dapm_context *dapm, |
| 4389 | const char *pin) |
| 4390 | { |
| 4391 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
| 4392 | } |
| 4393 | EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin_unlocked); |
| 4394 | |
| 4395 | /** |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 4396 | * snd_soc_dapm_nc_pin - permanently disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4397 | * @dapm: DAPM context |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 4398 | * @pin: pin name |
| 4399 | * |
| 4400 | * Marks the specified pin as being not connected, disabling it along |
| 4401 | * any parent or child widgets. At present this is identical to |
| 4402 | * snd_soc_dapm_disable_pin() but in future it will be extended to do |
| 4403 | * additional things such as disabling controls which only affect |
| 4404 | * paths through the pin. |
| 4405 | * |
| 4406 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 4407 | * do any widget power switching. |
| 4408 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4409 | int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin) |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 4410 | { |
Charles Keepax | 1139110 | 2014-02-18 15:22:14 +0000 | [diff] [blame] | 4411 | int ret; |
| 4412 | |
| 4413 | mutex_lock_nested(&dapm->card->dapm_mutex, SND_SOC_DAPM_CLASS_RUNTIME); |
| 4414 | |
| 4415 | ret = snd_soc_dapm_set_pin(dapm, pin, 0); |
| 4416 | |
| 4417 | mutex_unlock(&dapm->card->dapm_mutex); |
| 4418 | |
| 4419 | return ret; |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 4420 | } |
| 4421 | EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin); |
| 4422 | |
| 4423 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 4424 | * snd_soc_dapm_get_pin_status - get audio pin status |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4425 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 4426 | * @pin: audio signal pin endpoint (or start point) |
| 4427 | * |
| 4428 | * Get audio pin status - connected or disconnected. |
| 4429 | * |
| 4430 | * Returns 1 for connected otherwise 0. |
| 4431 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4432 | int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm, |
| 4433 | const char *pin) |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 4434 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 4435 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 4436 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 4437 | if (w) |
| 4438 | return w->connected; |
Stephen Warren | a68b38a | 2011-04-19 15:25:11 -0600 | [diff] [blame] | 4439 | |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 4440 | return 0; |
| 4441 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 4442 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 4443 | |
| 4444 | /** |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 4445 | * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4446 | * @dapm: DAPM context |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 4447 | * @pin: audio signal pin endpoint (or start point) |
| 4448 | * |
| 4449 | * Mark the given endpoint or pin as ignoring suspend. When the |
| 4450 | * system is disabled a path between two endpoints flagged as ignoring |
| 4451 | * suspend will not be disabled. The path must already be enabled via |
| 4452 | * normal means at suspend time, it will not be turned on if it was not |
| 4453 | * already enabled. |
| 4454 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4455 | int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm, |
| 4456 | const char *pin) |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 4457 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 4458 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 4459 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 4460 | if (!w) { |
Liam Girdwood | 30a6a1a | 2012-11-19 14:39:12 +0000 | [diff] [blame] | 4461 | dev_err(dapm->dev, "ASoC: unknown pin %s\n", pin); |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 4462 | return -EINVAL; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 4463 | } |
| 4464 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 4465 | w->ignore_suspend = 1; |
| 4466 | |
| 4467 | return 0; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 4468 | } |
| 4469 | EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend); |
| 4470 | |
Lars-Peter Clausen | cdc4508 | 2014-10-20 19:36:33 +0200 | [diff] [blame] | 4471 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4472 | * snd_soc_dapm_free - free dapm resources |
Peter Ujfalusi | 728a522 | 2011-08-26 16:33:52 +0300 | [diff] [blame] | 4473 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4474 | * |
| 4475 | * Free all dapm widgets and resources. |
| 4476 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4477 | void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4478 | { |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 4479 | dapm_debugfs_cleanup(dapm); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4480 | dapm_free_widgets(dapm); |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 4481 | list_del(&dapm->list); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4482 | } |
| 4483 | EXPORT_SYMBOL_GPL(snd_soc_dapm_free); |
| 4484 | |
Xiang Xiao | 5799635 | 2014-03-02 00:04:02 +0800 | [diff] [blame] | 4485 | static void soc_dapm_shutdown_dapm(struct snd_soc_dapm_context *dapm) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 4486 | { |
Liam Girdwood | 01005a7 | 2012-07-06 16:57:05 +0100 | [diff] [blame] | 4487 | struct snd_soc_card *card = dapm->card; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 4488 | struct snd_soc_dapm_widget *w; |
| 4489 | LIST_HEAD(down_list); |
| 4490 | int powerdown = 0; |
| 4491 | |
Liam Girdwood | 01005a7 | 2012-07-06 16:57:05 +0100 | [diff] [blame] | 4492 | mutex_lock(&card->dapm_mutex); |
| 4493 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 4494 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 4495 | if (w->dapm != dapm) |
| 4496 | continue; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 4497 | if (w->power) { |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 4498 | dapm_seq_insert(w, &down_list, false); |
Mark Brown | c2caa4d | 2009-06-26 15:36:56 +0100 | [diff] [blame] | 4499 | w->power = 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 4500 | powerdown = 1; |
| 4501 | } |
| 4502 | } |
| 4503 | |
| 4504 | /* If there were no widgets to power down we're already in |
| 4505 | * standby. |
| 4506 | */ |
| 4507 | if (powerdown) { |
Mark Brown | 7679e42 | 2012-02-22 15:52:56 +0000 | [diff] [blame] | 4508 | if (dapm->bias_level == SND_SOC_BIAS_ON) |
| 4509 | snd_soc_dapm_set_bias_level(dapm, |
| 4510 | SND_SOC_BIAS_PREPARE); |
Lars-Peter Clausen | 95dd5cd | 2013-07-29 17:13:56 +0200 | [diff] [blame] | 4511 | dapm_seq_run(card, &down_list, 0, false); |
Mark Brown | 7679e42 | 2012-02-22 15:52:56 +0000 | [diff] [blame] | 4512 | if (dapm->bias_level == SND_SOC_BIAS_PREPARE) |
| 4513 | snd_soc_dapm_set_bias_level(dapm, |
| 4514 | SND_SOC_BIAS_STANDBY); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 4515 | } |
Liam Girdwood | 01005a7 | 2012-07-06 16:57:05 +0100 | [diff] [blame] | 4516 | |
| 4517 | mutex_unlock(&card->dapm_mutex); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4518 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 4519 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4520 | /* |
| 4521 | * snd_soc_dapm_shutdown - callback for system shutdown |
| 4522 | */ |
| 4523 | void snd_soc_dapm_shutdown(struct snd_soc_card *card) |
| 4524 | { |
Xiang Xiao | 5799635 | 2014-03-02 00:04:02 +0800 | [diff] [blame] | 4525 | struct snd_soc_dapm_context *dapm; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 4526 | |
Xiang Xiao | 5799635 | 2014-03-02 00:04:02 +0800 | [diff] [blame] | 4527 | list_for_each_entry(dapm, &card->dapm_list, list) { |
Xiang Xiao | 17282ba | 2014-03-02 00:04:03 +0800 | [diff] [blame] | 4528 | if (dapm != &card->dapm) { |
| 4529 | soc_dapm_shutdown_dapm(dapm); |
| 4530 | if (dapm->bias_level == SND_SOC_BIAS_STANDBY) |
| 4531 | snd_soc_dapm_set_bias_level(dapm, |
| 4532 | SND_SOC_BIAS_OFF); |
| 4533 | } |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 4534 | } |
Xiang Xiao | 17282ba | 2014-03-02 00:04:03 +0800 | [diff] [blame] | 4535 | |
| 4536 | soc_dapm_shutdown_dapm(&card->dapm); |
| 4537 | if (card->dapm.bias_level == SND_SOC_BIAS_STANDBY) |
| 4538 | snd_soc_dapm_set_bias_level(&card->dapm, |
| 4539 | SND_SOC_BIAS_OFF); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 4540 | } |
| 4541 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4542 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 4543 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 4544 | MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC"); |
| 4545 | MODULE_LICENSE("GPL"); |