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