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