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