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