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