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