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