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