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