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