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