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