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