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