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