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