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