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