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