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