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