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