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