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