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 |
| 17 | * mic/meadphone insertion events. |
| 18 | * o Automatic Mic Bias support |
| 19 | * o Jack insertion power event initiation - e.g. hp insertion will enable |
| 20 | * sinks, dacs, etc |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 21 | * o Delayed powerdown of audio susbsystem to reduce pops between a quick |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 22 | * device reopen. |
| 23 | * |
| 24 | * Todo: |
| 25 | * o DAPM power change sequencing - allow for configurable per |
| 26 | * codec sequences. |
| 27 | * o Support for analogue bias optimisation. |
| 28 | * o Support for reduced codec oversampling rates. |
| 29 | * o Support for reduced codec bias currents. |
| 30 | */ |
| 31 | |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/moduleparam.h> |
| 34 | #include <linux/init.h> |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 35 | #include <linux/async.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 36 | #include <linux/delay.h> |
| 37 | #include <linux/pm.h> |
| 38 | #include <linux/bitops.h> |
| 39 | #include <linux/platform_device.h> |
| 40 | #include <linux/jiffies.h> |
Takashi Iwai | 20496ff | 2009-08-24 09:40:34 +0200 | [diff] [blame] | 41 | #include <linux/debugfs.h> |
Mark Brown | f1aac48 | 2011-12-05 15:17:06 +0000 | [diff] [blame] | 42 | #include <linux/pm_runtime.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 43 | #include <linux/slab.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 44 | #include <sound/core.h> |
| 45 | #include <sound/pcm.h> |
| 46 | #include <sound/pcm_params.h> |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 47 | #include <sound/soc.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 48 | #include <sound/initval.h> |
| 49 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 50 | #include <trace/events/asoc.h> |
| 51 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 52 | #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++; |
| 53 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 54 | /* dapm power sequences - make this per codec in the future */ |
| 55 | static int dapm_up_seq[] = { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 56 | [snd_soc_dapm_pre] = 0, |
| 57 | [snd_soc_dapm_supply] = 1, |
| 58 | [snd_soc_dapm_micbias] = 2, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 59 | [snd_soc_dapm_aif_in] = 3, |
| 60 | [snd_soc_dapm_aif_out] = 3, |
| 61 | [snd_soc_dapm_mic] = 4, |
| 62 | [snd_soc_dapm_mux] = 5, |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 63 | [snd_soc_dapm_virt_mux] = 5, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 64 | [snd_soc_dapm_value_mux] = 5, |
| 65 | [snd_soc_dapm_dac] = 6, |
| 66 | [snd_soc_dapm_mixer] = 7, |
| 67 | [snd_soc_dapm_mixer_named_ctl] = 7, |
| 68 | [snd_soc_dapm_pga] = 8, |
| 69 | [snd_soc_dapm_adc] = 9, |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 70 | [snd_soc_dapm_out_drv] = 10, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 71 | [snd_soc_dapm_hp] = 10, |
| 72 | [snd_soc_dapm_spk] = 10, |
| 73 | [snd_soc_dapm_post] = 11, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 74 | }; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 75 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 76 | static int dapm_down_seq[] = { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 77 | [snd_soc_dapm_pre] = 0, |
| 78 | [snd_soc_dapm_adc] = 1, |
| 79 | [snd_soc_dapm_hp] = 2, |
Mark Brown | 1ca0406 | 2009-08-17 16:26:59 +0100 | [diff] [blame] | 80 | [snd_soc_dapm_spk] = 2, |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 81 | [snd_soc_dapm_out_drv] = 2, |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 82 | [snd_soc_dapm_pga] = 4, |
| 83 | [snd_soc_dapm_mixer_named_ctl] = 5, |
Mark Brown | e3d4dab | 2009-06-07 13:08:45 +0100 | [diff] [blame] | 84 | [snd_soc_dapm_mixer] = 5, |
| 85 | [snd_soc_dapm_dac] = 6, |
| 86 | [snd_soc_dapm_mic] = 7, |
| 87 | [snd_soc_dapm_micbias] = 8, |
| 88 | [snd_soc_dapm_mux] = 9, |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 89 | [snd_soc_dapm_virt_mux] = 9, |
Mark Brown | e3d4dab | 2009-06-07 13:08:45 +0100 | [diff] [blame] | 90 | [snd_soc_dapm_value_mux] = 9, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 91 | [snd_soc_dapm_aif_in] = 10, |
| 92 | [snd_soc_dapm_aif_out] = 10, |
| 93 | [snd_soc_dapm_supply] = 11, |
| 94 | [snd_soc_dapm_post] = 12, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 95 | }; |
| 96 | |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 97 | static void pop_wait(u32 pop_time) |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 98 | { |
| 99 | if (pop_time) |
| 100 | schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time)); |
| 101 | } |
| 102 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 103 | static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...) |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 104 | { |
| 105 | va_list args; |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 106 | char *buf; |
| 107 | |
| 108 | if (!pop_time) |
| 109 | return; |
| 110 | |
| 111 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 112 | if (buf == NULL) |
| 113 | return; |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 114 | |
| 115 | va_start(args, fmt); |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 116 | vsnprintf(buf, PAGE_SIZE, fmt, args); |
Takashi Iwai | 9d01df0 | 2010-12-22 14:08:40 +0100 | [diff] [blame] | 117 | dev_info(dev, "%s", buf); |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 118 | va_end(args); |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 119 | |
| 120 | kfree(buf); |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 121 | } |
| 122 | |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 123 | static bool dapm_dirty_widget(struct snd_soc_dapm_widget *w) |
| 124 | { |
| 125 | return !list_empty(&w->dirty); |
| 126 | } |
| 127 | |
Mark Brown | 25c77c5 | 2011-10-08 13:36:03 +0100 | [diff] [blame] | 128 | 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] | 129 | { |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 130 | if (!dapm_dirty_widget(w)) { |
| 131 | dev_vdbg(w->dapm->dev, "Marking %s dirty due to %s\n", |
| 132 | w->name, reason); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 133 | list_add_tail(&w->dirty, &w->dapm->card->dapm_dirty); |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 134 | } |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 135 | } |
Mark Brown | 25c77c5 | 2011-10-08 13:36:03 +0100 | [diff] [blame] | 136 | EXPORT_SYMBOL_GPL(dapm_mark_dirty); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 137 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 138 | /* create a new dapm widget */ |
Takashi Iwai | 88cb429 | 2007-02-05 14:56:20 +0100 | [diff] [blame] | 139 | static inline struct snd_soc_dapm_widget *dapm_cnew_widget( |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 140 | const struct snd_soc_dapm_widget *_widget) |
| 141 | { |
Takashi Iwai | 88cb429 | 2007-02-05 14:56:20 +0100 | [diff] [blame] | 142 | return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 143 | } |
| 144 | |
Liam Girdwood | 4805608 | 2011-07-20 12:23:33 +0100 | [diff] [blame] | 145 | /* get snd_card from DAPM context */ |
| 146 | static inline struct snd_card *dapm_get_snd_card( |
| 147 | struct snd_soc_dapm_context *dapm) |
| 148 | { |
| 149 | if (dapm->codec) |
| 150 | return dapm->codec->card->snd_card; |
| 151 | else if (dapm->platform) |
| 152 | return dapm->platform->card->snd_card; |
| 153 | else |
| 154 | BUG(); |
| 155 | |
| 156 | /* unreachable */ |
| 157 | return NULL; |
| 158 | } |
| 159 | |
| 160 | /* get soc_card from DAPM context */ |
| 161 | static inline struct snd_soc_card *dapm_get_soc_card( |
| 162 | struct snd_soc_dapm_context *dapm) |
| 163 | { |
| 164 | if (dapm->codec) |
| 165 | return dapm->codec->card; |
| 166 | else if (dapm->platform) |
| 167 | return dapm->platform->card; |
| 168 | else |
| 169 | BUG(); |
| 170 | |
| 171 | /* unreachable */ |
| 172 | return NULL; |
| 173 | } |
| 174 | |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 175 | static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg) |
| 176 | { |
| 177 | if (w->codec) |
| 178 | return snd_soc_read(w->codec, reg); |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 179 | else if (w->platform) |
| 180 | return snd_soc_platform_read(w->platform, reg); |
| 181 | |
| 182 | dev_err(w->dapm->dev, "no valid widget read method\n"); |
| 183 | return -1; |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val) |
| 187 | { |
| 188 | if (w->codec) |
| 189 | return snd_soc_write(w->codec, reg, val); |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 190 | else if (w->platform) |
| 191 | return snd_soc_platform_write(w->platform, reg, val); |
| 192 | |
| 193 | dev_err(w->dapm->dev, "no valid widget write method\n"); |
| 194 | return -1; |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static int soc_widget_update_bits(struct snd_soc_dapm_widget *w, |
| 198 | unsigned short reg, unsigned int mask, unsigned int value) |
| 199 | { |
| 200 | int change; |
| 201 | unsigned int old, new; |
| 202 | int ret; |
| 203 | |
| 204 | ret = soc_widget_read(w, reg); |
| 205 | if (ret < 0) |
| 206 | return ret; |
| 207 | |
| 208 | old = ret; |
| 209 | new = (old & ~mask) | (value & mask); |
| 210 | change = old != new; |
| 211 | if (change) { |
| 212 | ret = soc_widget_write(w, reg, new); |
| 213 | if (ret < 0) |
| 214 | return ret; |
| 215 | } |
| 216 | |
| 217 | return change; |
| 218 | } |
| 219 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 220 | /** |
| 221 | * 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] | 222 | * @dapm: DAPM context |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 223 | * @level: level to configure |
| 224 | * |
| 225 | * Configure the bias (power) levels for the SoC audio device. |
| 226 | * |
| 227 | * Returns 0 for success else error. |
| 228 | */ |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 229 | 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] | 230 | enum snd_soc_bias_level level) |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 231 | { |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 232 | struct snd_soc_card *card = dapm->card; |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 233 | int ret = 0; |
| 234 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 235 | trace_snd_soc_bias_level_start(card, level); |
| 236 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 237 | if (card && card->set_bias_level) |
Mark Brown | d4c6005 | 2011-06-06 19:13:23 +0100 | [diff] [blame] | 238 | ret = card->set_bias_level(card, dapm, level); |
Mark Brown | 171ec6b | 2011-06-06 18:15:19 +0100 | [diff] [blame] | 239 | if (ret != 0) |
| 240 | goto out; |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 241 | |
Mark Brown | cc4c670 | 2011-06-06 19:03:34 +0100 | [diff] [blame] | 242 | if (dapm->codec) { |
| 243 | if (dapm->codec->driver->set_bias_level) |
| 244 | ret = dapm->codec->driver->set_bias_level(dapm->codec, |
| 245 | level); |
| 246 | else |
| 247 | dapm->bias_level = level; |
| 248 | } |
Mark Brown | 171ec6b | 2011-06-06 18:15:19 +0100 | [diff] [blame] | 249 | if (ret != 0) |
| 250 | goto out; |
| 251 | |
| 252 | if (card && card->set_bias_level_post) |
Mark Brown | d4c6005 | 2011-06-06 19:13:23 +0100 | [diff] [blame] | 253 | ret = card->set_bias_level_post(card, dapm, level); |
Mark Brown | 171ec6b | 2011-06-06 18:15:19 +0100 | [diff] [blame] | 254 | out: |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 255 | trace_snd_soc_bias_level_done(card, level); |
| 256 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 257 | return ret; |
| 258 | } |
| 259 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 260 | /* set up initial codec paths */ |
| 261 | static void dapm_set_path_status(struct snd_soc_dapm_widget *w, |
| 262 | struct snd_soc_dapm_path *p, int i) |
| 263 | { |
| 264 | switch (w->id) { |
| 265 | case snd_soc_dapm_switch: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 266 | case snd_soc_dapm_mixer: |
| 267 | case snd_soc_dapm_mixer_named_ctl: { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 268 | int val; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 269 | struct soc_mixer_control *mc = (struct soc_mixer_control *) |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 270 | w->kcontrol_news[i].private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 271 | unsigned int reg = mc->reg; |
| 272 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 273 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 274 | unsigned int mask = (1 << fls(max)) - 1; |
| 275 | unsigned int invert = mc->invert; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 276 | |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 277 | val = soc_widget_read(w, reg); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 278 | val = (val >> shift) & mask; |
| 279 | |
| 280 | if ((invert && !val) || (!invert && val)) |
| 281 | p->connect = 1; |
| 282 | else |
| 283 | p->connect = 0; |
| 284 | } |
| 285 | break; |
| 286 | case snd_soc_dapm_mux: { |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 287 | struct soc_enum *e = (struct soc_enum *) |
| 288 | w->kcontrol_news[i].private_value; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 289 | int val, item, bitmask; |
| 290 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 291 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Mark Brown | 88d9608 | 2011-06-06 16:16:34 +0100 | [diff] [blame] | 292 | ; |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 293 | val = soc_widget_read(w, e->reg); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 294 | item = (val >> e->shift_l) & (bitmask - 1); |
| 295 | |
| 296 | p->connect = 0; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 297 | for (i = 0; i < e->max; i++) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 298 | if (!(strcmp(p->name, e->texts[i])) && item == i) |
| 299 | p->connect = 1; |
| 300 | } |
| 301 | } |
| 302 | break; |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 303 | case snd_soc_dapm_virt_mux: { |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 304 | struct soc_enum *e = (struct soc_enum *) |
| 305 | w->kcontrol_news[i].private_value; |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 306 | |
| 307 | p->connect = 0; |
| 308 | /* since a virtual mux has no backing registers to |
| 309 | * decide which path to connect, it will try to match |
| 310 | * with the first enumeration. This is to ensure |
| 311 | * that the default mux choice (the first) will be |
| 312 | * correctly powered up during initialization. |
| 313 | */ |
| 314 | if (!strcmp(p->name, e->texts[0])) |
| 315 | p->connect = 1; |
| 316 | } |
| 317 | break; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 318 | case snd_soc_dapm_value_mux: { |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 319 | struct soc_enum *e = (struct soc_enum *) |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 320 | w->kcontrol_news[i].private_value; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 321 | int val, item; |
| 322 | |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 323 | val = soc_widget_read(w, e->reg); |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 324 | val = (val >> e->shift_l) & e->mask; |
| 325 | for (item = 0; item < e->max; item++) { |
| 326 | if (val == e->values[item]) |
| 327 | break; |
| 328 | } |
| 329 | |
| 330 | p->connect = 0; |
| 331 | for (i = 0; i < e->max; i++) { |
| 332 | if (!(strcmp(p->name, e->texts[i])) && item == i) |
| 333 | p->connect = 1; |
| 334 | } |
| 335 | } |
| 336 | break; |
Mark Brown | 5656310 | 2011-10-03 22:41:09 +0100 | [diff] [blame] | 337 | /* does not affect routing - always connected */ |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 338 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 339 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 340 | case snd_soc_dapm_output: |
| 341 | case snd_soc_dapm_adc: |
| 342 | case snd_soc_dapm_input: |
Mark Brown | 1ab97c8 | 2011-11-27 16:21:51 +0000 | [diff] [blame] | 343 | case snd_soc_dapm_siggen: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 344 | case snd_soc_dapm_dac: |
| 345 | case snd_soc_dapm_micbias: |
| 346 | case snd_soc_dapm_vmid: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 347 | case snd_soc_dapm_supply: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 348 | case snd_soc_dapm_aif_in: |
| 349 | case snd_soc_dapm_aif_out: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 350 | case snd_soc_dapm_hp: |
| 351 | case snd_soc_dapm_mic: |
| 352 | case snd_soc_dapm_spk: |
| 353 | case snd_soc_dapm_line: |
Mark Brown | 5656310 | 2011-10-03 22:41:09 +0100 | [diff] [blame] | 354 | p->connect = 1; |
| 355 | break; |
| 356 | /* does affect routing - dynamically connected */ |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 357 | case snd_soc_dapm_pre: |
| 358 | case snd_soc_dapm_post: |
| 359 | p->connect = 0; |
| 360 | break; |
| 361 | } |
| 362 | } |
| 363 | |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 364 | /* connect mux widget to its interconnecting audio paths */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 365 | static int dapm_connect_mux(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 366 | struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, |
| 367 | struct snd_soc_dapm_path *path, const char *control_name, |
| 368 | const struct snd_kcontrol_new *kcontrol) |
| 369 | { |
| 370 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 371 | int i; |
| 372 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 373 | for (i = 0; i < e->max; i++) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 374 | if (!(strcmp(control_name, e->texts[i]))) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 375 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 376 | list_add(&path->list_sink, &dest->sources); |
| 377 | list_add(&path->list_source, &src->sinks); |
| 378 | path->name = (char*)e->texts[i]; |
| 379 | dapm_set_path_status(dest, path, 0); |
| 380 | return 0; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | return -ENODEV; |
| 385 | } |
| 386 | |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 387 | /* connect mixer widget to its interconnecting audio paths */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 388 | static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 389 | struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, |
| 390 | struct snd_soc_dapm_path *path, const char *control_name) |
| 391 | { |
| 392 | int i; |
| 393 | |
| 394 | /* search for mixer kcontrol */ |
| 395 | for (i = 0; i < dest->num_kcontrols; i++) { |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 396 | if (!strcmp(control_name, dest->kcontrol_news[i].name)) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 397 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 398 | list_add(&path->list_sink, &dest->sources); |
| 399 | list_add(&path->list_source, &src->sinks); |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 400 | path->name = dest->kcontrol_news[i].name; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 401 | dapm_set_path_status(dest, path, i); |
| 402 | return 0; |
| 403 | } |
| 404 | } |
| 405 | return -ENODEV; |
| 406 | } |
| 407 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 408 | static int dapm_is_shared_kcontrol(struct snd_soc_dapm_context *dapm, |
Stephen Warren | 1007da0 | 2011-05-26 09:57:33 -0600 | [diff] [blame] | 409 | struct snd_soc_dapm_widget *kcontrolw, |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 410 | const struct snd_kcontrol_new *kcontrol_new, |
| 411 | struct snd_kcontrol **kcontrol) |
| 412 | { |
| 413 | struct snd_soc_dapm_widget *w; |
| 414 | int i; |
| 415 | |
| 416 | *kcontrol = NULL; |
| 417 | |
| 418 | list_for_each_entry(w, &dapm->card->widgets, list) { |
Stephen Warren | 1007da0 | 2011-05-26 09:57:33 -0600 | [diff] [blame] | 419 | if (w == kcontrolw || w->dapm != kcontrolw->dapm) |
| 420 | continue; |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 421 | for (i = 0; i < w->num_kcontrols; i++) { |
| 422 | if (&w->kcontrol_news[i] == kcontrol_new) { |
| 423 | if (w->kcontrols) |
| 424 | *kcontrol = w->kcontrols[i]; |
| 425 | return 1; |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | return 0; |
| 431 | } |
| 432 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 433 | /* create new dapm mixer control */ |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 434 | static int dapm_new_mixer(struct snd_soc_dapm_widget *w) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 435 | { |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 436 | struct snd_soc_dapm_context *dapm = w->dapm; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 437 | int i, ret = 0; |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 438 | size_t name_len, prefix_len; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 439 | struct snd_soc_dapm_path *path; |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 440 | struct snd_card *card = dapm->card->snd_card; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 441 | const char *prefix; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 442 | struct snd_soc_dapm_widget_list *wlist; |
| 443 | size_t wlistsize; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 444 | |
| 445 | if (dapm->codec) |
| 446 | prefix = dapm->codec->name_prefix; |
| 447 | else |
| 448 | prefix = NULL; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 449 | |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 450 | if (prefix) |
| 451 | prefix_len = strlen(prefix) + 1; |
| 452 | else |
| 453 | prefix_len = 0; |
| 454 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 455 | /* add kcontrol */ |
| 456 | for (i = 0; i < w->num_kcontrols; i++) { |
| 457 | |
| 458 | /* match name */ |
| 459 | list_for_each_entry(path, &w->sources, list_sink) { |
| 460 | |
| 461 | /* mixer/mux paths name must match control name */ |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 462 | if (path->name != (char *)w->kcontrol_news[i].name) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 463 | continue; |
| 464 | |
Lars-Peter Clausen | 82cd876 | 2011-08-15 20:15:21 +0200 | [diff] [blame] | 465 | if (w->kcontrols[i]) { |
| 466 | path->kcontrol = w->kcontrols[i]; |
| 467 | continue; |
| 468 | } |
| 469 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 470 | wlistsize = sizeof(struct snd_soc_dapm_widget_list) + |
| 471 | sizeof(struct snd_soc_dapm_widget *), |
| 472 | wlist = kzalloc(wlistsize, GFP_KERNEL); |
| 473 | if (wlist == NULL) { |
| 474 | dev_err(dapm->dev, |
| 475 | "asoc: can't allocate widget list for %s\n", |
| 476 | w->name); |
| 477 | return -ENOMEM; |
| 478 | } |
| 479 | wlist->num_widgets = 1; |
| 480 | wlist->widgets[0] = w; |
| 481 | |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 482 | /* add dapm control with long name. |
| 483 | * for dapm_mixer this is the concatenation of the |
| 484 | * mixer and kcontrol name. |
| 485 | * for dapm_mixer_named_ctl this is simply the |
| 486 | * kcontrol name. |
| 487 | */ |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 488 | name_len = strlen(w->kcontrol_news[i].name) + 1; |
Mark Brown | 07495f3 | 2009-03-05 17:06:23 +0000 | [diff] [blame] | 489 | if (w->id != snd_soc_dapm_mixer_named_ctl) |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 490 | name_len += 1 + strlen(w->name); |
| 491 | |
Mark Brown | 219b93f | 2008-10-28 13:02:31 +0000 | [diff] [blame] | 492 | path->long_name = kmalloc(name_len, GFP_KERNEL); |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 493 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 494 | if (path->long_name == NULL) { |
| 495 | kfree(wlist); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 496 | return -ENOMEM; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 497 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 498 | |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 499 | switch (w->id) { |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 500 | default: |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 501 | /* The control will get a prefix from |
| 502 | * the control creation process but |
| 503 | * we're also using the same prefix |
| 504 | * for widgets so cut the prefix off |
| 505 | * the front of the widget name. |
| 506 | */ |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 507 | snprintf(path->long_name, name_len, "%s %s", |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 508 | w->name + prefix_len, |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 509 | w->kcontrol_news[i].name); |
Mark Brown | 07495f3 | 2009-03-05 17:06:23 +0000 | [diff] [blame] | 510 | break; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 511 | case snd_soc_dapm_mixer_named_ctl: |
| 512 | snprintf(path->long_name, name_len, "%s", |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 513 | w->kcontrol_news[i].name); |
Mark Brown | 07495f3 | 2009-03-05 17:06:23 +0000 | [diff] [blame] | 514 | break; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Mark Brown | 219b93f | 2008-10-28 13:02:31 +0000 | [diff] [blame] | 517 | path->long_name[name_len - 1] = '\0'; |
| 518 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 519 | path->kcontrol = snd_soc_cnew(&w->kcontrol_news[i], |
| 520 | wlist, path->long_name, |
| 521 | prefix); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 522 | ret = snd_ctl_add(card, path->kcontrol); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 523 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 524 | dev_err(dapm->dev, |
| 525 | "asoc: failed to add dapm kcontrol %s: %d\n", |
| 526 | path->long_name, ret); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 527 | kfree(wlist); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 528 | kfree(path->long_name); |
| 529 | path->long_name = NULL; |
| 530 | return ret; |
| 531 | } |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 532 | w->kcontrols[i] = path->kcontrol; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | return ret; |
| 536 | } |
| 537 | |
| 538 | /* create new dapm mux control */ |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 539 | static int dapm_new_mux(struct snd_soc_dapm_widget *w) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 540 | { |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 541 | struct snd_soc_dapm_context *dapm = w->dapm; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 542 | struct snd_soc_dapm_path *path = NULL; |
| 543 | struct snd_kcontrol *kcontrol; |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 544 | struct snd_card *card = dapm->card->snd_card; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 545 | const char *prefix; |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 546 | size_t prefix_len; |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 547 | int ret; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 548 | struct snd_soc_dapm_widget_list *wlist; |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 549 | int shared, wlistentries; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 550 | size_t wlistsize; |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 551 | char *name; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 552 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 553 | if (w->num_kcontrols != 1) { |
| 554 | dev_err(dapm->dev, |
| 555 | "asoc: mux %s has incorrect number of controls\n", |
| 556 | w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 557 | return -EINVAL; |
| 558 | } |
| 559 | |
Stephen Warren | 1007da0 | 2011-05-26 09:57:33 -0600 | [diff] [blame] | 560 | shared = dapm_is_shared_kcontrol(dapm, w, &w->kcontrol_news[0], |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 561 | &kcontrol); |
| 562 | if (kcontrol) { |
| 563 | wlist = kcontrol->private_data; |
| 564 | wlistentries = wlist->num_widgets + 1; |
| 565 | } else { |
| 566 | wlist = NULL; |
| 567 | wlistentries = 1; |
| 568 | } |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 569 | wlistsize = sizeof(struct snd_soc_dapm_widget_list) + |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 570 | wlistentries * sizeof(struct snd_soc_dapm_widget *), |
| 571 | wlist = krealloc(wlist, wlistsize, GFP_KERNEL); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 572 | if (wlist == NULL) { |
| 573 | dev_err(dapm->dev, |
| 574 | "asoc: can't allocate widget list for %s\n", w->name); |
| 575 | return -ENOMEM; |
| 576 | } |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 577 | wlist->num_widgets = wlistentries; |
| 578 | wlist->widgets[wlistentries - 1] = w; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 579 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 580 | if (!kcontrol) { |
| 581 | if (dapm->codec) |
| 582 | prefix = dapm->codec->name_prefix; |
| 583 | else |
| 584 | prefix = NULL; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 585 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 586 | if (shared) { |
| 587 | name = w->kcontrol_news[0].name; |
| 588 | prefix_len = 0; |
| 589 | } else { |
| 590 | name = w->name; |
| 591 | if (prefix) |
| 592 | prefix_len = strlen(prefix) + 1; |
| 593 | else |
| 594 | prefix_len = 0; |
| 595 | } |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 596 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 597 | /* |
| 598 | * The control will get a prefix from the control creation |
| 599 | * process but we're also using the same prefix for widgets so |
| 600 | * cut the prefix off the front of the widget name. |
| 601 | */ |
| 602 | kcontrol = snd_soc_cnew(&w->kcontrol_news[0], wlist, |
| 603 | name + prefix_len, prefix); |
| 604 | ret = snd_ctl_add(card, kcontrol); |
| 605 | if (ret < 0) { |
Mark Brown | 53daf20 | 2011-09-05 10:51:05 -0700 | [diff] [blame] | 606 | dev_err(dapm->dev, "failed to add kcontrol %s: %d\n", |
| 607 | w->name, ret); |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 608 | kfree(wlist); |
| 609 | return ret; |
| 610 | } |
| 611 | } |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 612 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 613 | kcontrol->private_data = wlist; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 614 | |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 615 | w->kcontrols[0] = kcontrol; |
| 616 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 617 | list_for_each_entry(path, &w->sources, list_sink) |
| 618 | path->kcontrol = kcontrol; |
| 619 | |
Stephen Warren | af46800 | 2011-04-28 17:38:01 -0600 | [diff] [blame] | 620 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | /* create new dapm volume control */ |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 624 | static int dapm_new_pga(struct snd_soc_dapm_widget *w) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 625 | { |
Mark Brown | a6c6573 | 2010-03-03 17:45:21 +0000 | [diff] [blame] | 626 | if (w->num_kcontrols) |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 627 | dev_err(w->dapm->dev, |
| 628 | "asoc: PGA controls not supported: '%s'\n", w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 629 | |
Mark Brown | a6c6573 | 2010-03-03 17:45:21 +0000 | [diff] [blame] | 630 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | /* reset 'walked' bit for each dapm path */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 634 | static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 635 | { |
| 636 | struct snd_soc_dapm_path *p; |
| 637 | |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 638 | list_for_each_entry(p, &dapm->card->paths, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 639 | p->walked = 0; |
| 640 | } |
| 641 | |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 642 | /* We implement power down on suspend by checking the power state of |
| 643 | * the ALSA card - when we are suspending the ALSA state for the card |
| 644 | * is set to D3. |
| 645 | */ |
| 646 | static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget) |
| 647 | { |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 648 | int level = snd_power_get_state(widget->dapm->card->snd_card); |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 649 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 650 | switch (level) { |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 651 | case SNDRV_CTL_POWER_D3hot: |
| 652 | case SNDRV_CTL_POWER_D3cold: |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 653 | if (widget->ignore_suspend) |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 654 | dev_dbg(widget->dapm->dev, "%s ignoring suspend\n", |
| 655 | widget->name); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 656 | return widget->ignore_suspend; |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 657 | default: |
| 658 | return 1; |
| 659 | } |
| 660 | } |
| 661 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 662 | /* |
| 663 | * Recursively check for a completed path to an active or physically connected |
| 664 | * output widget. Returns number of complete paths. |
| 665 | */ |
| 666 | static int is_connected_output_ep(struct snd_soc_dapm_widget *widget) |
| 667 | { |
| 668 | struct snd_soc_dapm_path *path; |
| 669 | int con = 0; |
| 670 | |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 671 | if (widget->outputs >= 0) |
| 672 | return widget->outputs; |
| 673 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 674 | DAPM_UPDATE_STAT(widget, path_checks); |
| 675 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 676 | if (widget->id == snd_soc_dapm_supply) |
| 677 | return 0; |
| 678 | |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 679 | switch (widget->id) { |
| 680 | case snd_soc_dapm_adc: |
| 681 | case snd_soc_dapm_aif_out: |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 682 | if (widget->active) { |
| 683 | widget->outputs = snd_soc_dapm_suspend_check(widget); |
| 684 | return widget->outputs; |
| 685 | } |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 686 | default: |
| 687 | break; |
| 688 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 689 | |
| 690 | if (widget->connected) { |
| 691 | /* connected pin ? */ |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 692 | if (widget->id == snd_soc_dapm_output && !widget->ext) { |
| 693 | widget->outputs = snd_soc_dapm_suspend_check(widget); |
| 694 | return widget->outputs; |
| 695 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 696 | |
| 697 | /* connected jack or spk ? */ |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 698 | if (widget->id == snd_soc_dapm_hp || |
| 699 | widget->id == snd_soc_dapm_spk || |
| 700 | (widget->id == snd_soc_dapm_line && |
| 701 | !list_empty(&widget->sources))) { |
| 702 | widget->outputs = snd_soc_dapm_suspend_check(widget); |
| 703 | return widget->outputs; |
| 704 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | list_for_each_entry(path, &widget->sinks, list_source) { |
Mark Brown | e56235e | 2011-09-21 18:19:14 +0100 | [diff] [blame] | 708 | DAPM_UPDATE_STAT(widget, neighbour_checks); |
| 709 | |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 710 | if (path->weak) |
| 711 | continue; |
| 712 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 713 | if (path->walked) |
| 714 | continue; |
| 715 | |
| 716 | if (path->sink && path->connect) { |
| 717 | path->walked = 1; |
| 718 | con += is_connected_output_ep(path->sink); |
| 719 | } |
| 720 | } |
| 721 | |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 722 | widget->outputs = con; |
| 723 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 724 | return con; |
| 725 | } |
| 726 | |
| 727 | /* |
| 728 | * Recursively check for a completed path to an active or physically connected |
| 729 | * input widget. Returns number of complete paths. |
| 730 | */ |
| 731 | static int is_connected_input_ep(struct snd_soc_dapm_widget *widget) |
| 732 | { |
| 733 | struct snd_soc_dapm_path *path; |
| 734 | int con = 0; |
| 735 | |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 736 | if (widget->inputs >= 0) |
| 737 | return widget->inputs; |
| 738 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 739 | DAPM_UPDATE_STAT(widget, path_checks); |
| 740 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 741 | if (widget->id == snd_soc_dapm_supply) |
| 742 | return 0; |
| 743 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 744 | /* active stream ? */ |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 745 | switch (widget->id) { |
| 746 | case snd_soc_dapm_dac: |
| 747 | case snd_soc_dapm_aif_in: |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 748 | if (widget->active) { |
| 749 | widget->inputs = snd_soc_dapm_suspend_check(widget); |
| 750 | return widget->inputs; |
| 751 | } |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 752 | default: |
| 753 | break; |
| 754 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 755 | |
| 756 | if (widget->connected) { |
| 757 | /* connected pin ? */ |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 758 | if (widget->id == snd_soc_dapm_input && !widget->ext) { |
| 759 | widget->inputs = snd_soc_dapm_suspend_check(widget); |
| 760 | return widget->inputs; |
| 761 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 762 | |
| 763 | /* connected VMID/Bias for lower pops */ |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 764 | if (widget->id == snd_soc_dapm_vmid) { |
| 765 | widget->inputs = snd_soc_dapm_suspend_check(widget); |
| 766 | return widget->inputs; |
| 767 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 768 | |
| 769 | /* connected jack ? */ |
Peter Ujfalusi | eaeae5d | 2009-09-30 09:27:24 +0300 | [diff] [blame] | 770 | if (widget->id == snd_soc_dapm_mic || |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 771 | (widget->id == snd_soc_dapm_line && |
| 772 | !list_empty(&widget->sinks))) { |
| 773 | widget->inputs = snd_soc_dapm_suspend_check(widget); |
| 774 | return widget->inputs; |
| 775 | } |
| 776 | |
Mark Brown | 1ab97c8 | 2011-11-27 16:21:51 +0000 | [diff] [blame] | 777 | /* signal generator */ |
| 778 | if (widget->id == snd_soc_dapm_siggen) { |
| 779 | widget->inputs = snd_soc_dapm_suspend_check(widget); |
| 780 | return widget->inputs; |
| 781 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | list_for_each_entry(path, &widget->sources, list_sink) { |
Mark Brown | e56235e | 2011-09-21 18:19:14 +0100 | [diff] [blame] | 785 | DAPM_UPDATE_STAT(widget, neighbour_checks); |
| 786 | |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 787 | if (path->weak) |
| 788 | continue; |
| 789 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 790 | if (path->walked) |
| 791 | continue; |
| 792 | |
| 793 | if (path->source && path->connect) { |
| 794 | path->walked = 1; |
| 795 | con += is_connected_input_ep(path->source); |
| 796 | } |
| 797 | } |
| 798 | |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 799 | widget->inputs = con; |
| 800 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 801 | return con; |
| 802 | } |
| 803 | |
| 804 | /* |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 805 | * Handler for generic register modifier widget. |
| 806 | */ |
| 807 | int dapm_reg_event(struct snd_soc_dapm_widget *w, |
| 808 | struct snd_kcontrol *kcontrol, int event) |
| 809 | { |
| 810 | unsigned int val; |
| 811 | |
| 812 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 813 | val = w->on_val; |
| 814 | else |
| 815 | val = w->off_val; |
| 816 | |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 817 | soc_widget_update_bits(w, -(w->reg + 1), |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 818 | w->mask << w->shift, val << w->shift); |
| 819 | |
| 820 | return 0; |
| 821 | } |
Mark Brown | 1158941 | 2008-07-29 11:42:23 +0100 | [diff] [blame] | 822 | EXPORT_SYMBOL_GPL(dapm_reg_event); |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 823 | |
Mark Brown | d805002 | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 824 | static int dapm_widget_power_check(struct snd_soc_dapm_widget *w) |
| 825 | { |
Mark Brown | 9b8a83b | 2011-10-04 22:15:59 +0100 | [diff] [blame] | 826 | if (w->power_checked) |
| 827 | return w->new_power; |
| 828 | |
Mark Brown | d805002 | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 829 | if (w->force) |
Mark Brown | 9b8a83b | 2011-10-04 22:15:59 +0100 | [diff] [blame] | 830 | w->new_power = 1; |
Mark Brown | d805002 | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 831 | else |
Mark Brown | 9b8a83b | 2011-10-04 22:15:59 +0100 | [diff] [blame] | 832 | w->new_power = w->power_check(w); |
| 833 | |
| 834 | w->power_checked = true; |
| 835 | |
| 836 | return w->new_power; |
Mark Brown | d805002 | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 837 | } |
| 838 | |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 839 | /* Generic check to see if a widget should be powered. |
| 840 | */ |
| 841 | static int dapm_generic_check_power(struct snd_soc_dapm_widget *w) |
| 842 | { |
| 843 | int in, out; |
| 844 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 845 | DAPM_UPDATE_STAT(w, power_checks); |
| 846 | |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 847 | in = is_connected_input_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 848 | dapm_clear_walk(w->dapm); |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 849 | out = is_connected_output_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 850 | dapm_clear_walk(w->dapm); |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 851 | return out != 0 && in != 0; |
| 852 | } |
| 853 | |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 854 | /* Check to see if an ADC has power */ |
| 855 | static int dapm_adc_check_power(struct snd_soc_dapm_widget *w) |
| 856 | { |
| 857 | int in; |
| 858 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 859 | DAPM_UPDATE_STAT(w, power_checks); |
| 860 | |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 861 | if (w->active) { |
| 862 | in = is_connected_input_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 863 | dapm_clear_walk(w->dapm); |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 864 | return in != 0; |
| 865 | } else { |
| 866 | return dapm_generic_check_power(w); |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | /* Check to see if a DAC has power */ |
| 871 | static int dapm_dac_check_power(struct snd_soc_dapm_widget *w) |
| 872 | { |
| 873 | int out; |
| 874 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 875 | DAPM_UPDATE_STAT(w, power_checks); |
| 876 | |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 877 | if (w->active) { |
| 878 | out = is_connected_output_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 879 | dapm_clear_walk(w->dapm); |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 880 | return out != 0; |
| 881 | } else { |
| 882 | return dapm_generic_check_power(w); |
| 883 | } |
| 884 | } |
| 885 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 886 | /* Check to see if a power supply is needed */ |
| 887 | static int dapm_supply_check_power(struct snd_soc_dapm_widget *w) |
| 888 | { |
| 889 | struct snd_soc_dapm_path *path; |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 890 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 891 | DAPM_UPDATE_STAT(w, power_checks); |
| 892 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 893 | /* Check if one of our outputs is connected */ |
| 894 | list_for_each_entry(path, &w->sinks, list_source) { |
Mark Brown | a8fdac8 | 2011-09-28 18:20:26 +0100 | [diff] [blame] | 895 | DAPM_UPDATE_STAT(w, neighbour_checks); |
| 896 | |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 897 | if (path->weak) |
| 898 | continue; |
| 899 | |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 900 | if (path->connected && |
| 901 | !path->connected(path->source, path->sink)) |
| 902 | continue; |
| 903 | |
Mark Brown | 3017358 | 2011-02-11 11:42:19 +0000 | [diff] [blame] | 904 | if (!path->sink) |
| 905 | continue; |
| 906 | |
Mark Brown | f68d7e1 | 2011-10-04 22:57:50 +0100 | [diff] [blame] | 907 | if (dapm_widget_power_check(path->sink)) |
| 908 | return 1; |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 909 | } |
| 910 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 911 | dapm_clear_walk(w->dapm); |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 912 | |
Mark Brown | f68d7e1 | 2011-10-04 22:57:50 +0100 | [diff] [blame] | 913 | return 0; |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 914 | } |
| 915 | |
Mark Brown | 35c64bc | 2011-09-28 18:23:53 +0100 | [diff] [blame] | 916 | static int dapm_always_on_check_power(struct snd_soc_dapm_widget *w) |
| 917 | { |
| 918 | return 1; |
| 919 | } |
| 920 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 921 | static int dapm_seq_compare(struct snd_soc_dapm_widget *a, |
| 922 | struct snd_soc_dapm_widget *b, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 923 | bool power_up) |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 924 | { |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 925 | int *sort; |
| 926 | |
| 927 | if (power_up) |
| 928 | sort = dapm_up_seq; |
| 929 | else |
| 930 | sort = dapm_down_seq; |
| 931 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 932 | if (sort[a->id] != sort[b->id]) |
| 933 | return sort[a->id] - sort[b->id]; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 934 | if (a->subseq != b->subseq) { |
| 935 | if (power_up) |
| 936 | return a->subseq - b->subseq; |
| 937 | else |
| 938 | return b->subseq - a->subseq; |
| 939 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 940 | if (a->reg != b->reg) |
| 941 | return a->reg - b->reg; |
Mark Brown | 84dab56 | 2010-11-12 15:28:42 +0000 | [diff] [blame] | 942 | if (a->dapm != b->dapm) |
| 943 | return (unsigned long)a->dapm - (unsigned long)b->dapm; |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 944 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 945 | return 0; |
| 946 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 947 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 948 | /* Insert a widget in order into a DAPM power sequence. */ |
| 949 | static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget, |
| 950 | struct list_head *list, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 951 | bool power_up) |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 952 | { |
| 953 | struct snd_soc_dapm_widget *w; |
| 954 | |
| 955 | list_for_each_entry(w, list, power_list) |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 956 | if (dapm_seq_compare(new_widget, w, power_up) < 0) { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 957 | list_add_tail(&new_widget->power_list, &w->power_list); |
| 958 | return; |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 959 | } |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 960 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 961 | list_add_tail(&new_widget->power_list, list); |
| 962 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 963 | |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 964 | static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm, |
| 965 | struct snd_soc_dapm_widget *w, int event) |
| 966 | { |
| 967 | struct snd_soc_card *card = dapm->card; |
| 968 | const char *ev_name; |
| 969 | int power, ret; |
| 970 | |
| 971 | switch (event) { |
| 972 | case SND_SOC_DAPM_PRE_PMU: |
| 973 | ev_name = "PRE_PMU"; |
| 974 | power = 1; |
| 975 | break; |
| 976 | case SND_SOC_DAPM_POST_PMU: |
| 977 | ev_name = "POST_PMU"; |
| 978 | power = 1; |
| 979 | break; |
| 980 | case SND_SOC_DAPM_PRE_PMD: |
| 981 | ev_name = "PRE_PMD"; |
| 982 | power = 0; |
| 983 | break; |
| 984 | case SND_SOC_DAPM_POST_PMD: |
| 985 | ev_name = "POST_PMD"; |
| 986 | power = 0; |
| 987 | break; |
| 988 | default: |
| 989 | BUG(); |
| 990 | return; |
| 991 | } |
| 992 | |
| 993 | if (w->power != power) |
| 994 | return; |
| 995 | |
| 996 | if (w->event && (w->event_flags & event)) { |
| 997 | pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n", |
| 998 | w->name, ev_name); |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 999 | trace_snd_soc_dapm_widget_event_start(w, event); |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1000 | ret = w->event(w, NULL, event); |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1001 | trace_snd_soc_dapm_widget_event_done(w, event); |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1002 | if (ret < 0) |
| 1003 | pr_err("%s: %s event failed: %d\n", |
| 1004 | ev_name, w->name, ret); |
| 1005 | } |
| 1006 | } |
| 1007 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1008 | /* Apply the coalesced changes from a DAPM sequence */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1009 | static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm, |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1010 | struct list_head *pending) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1011 | { |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1012 | struct snd_soc_card *card = dapm->card; |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1013 | struct snd_soc_dapm_widget *w; |
| 1014 | int reg, power; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1015 | unsigned int value = 0; |
| 1016 | unsigned int mask = 0; |
| 1017 | unsigned int cur_mask; |
| 1018 | |
| 1019 | reg = list_first_entry(pending, struct snd_soc_dapm_widget, |
| 1020 | power_list)->reg; |
| 1021 | |
| 1022 | list_for_each_entry(w, pending, power_list) { |
| 1023 | cur_mask = 1 << w->shift; |
| 1024 | BUG_ON(reg != w->reg); |
| 1025 | |
| 1026 | if (w->invert) |
| 1027 | power = !w->power; |
| 1028 | else |
| 1029 | power = w->power; |
| 1030 | |
| 1031 | mask |= cur_mask; |
| 1032 | if (power) |
| 1033 | value |= cur_mask; |
| 1034 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 1035 | pop_dbg(dapm->dev, card->pop_time, |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1036 | "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n", |
| 1037 | w->name, reg, value, mask); |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1038 | |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1039 | /* Check for events */ |
| 1040 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU); |
| 1041 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1042 | } |
| 1043 | |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1044 | if (reg >= 0) { |
Mark Brown | 29376bc | 2011-06-19 13:49:28 +0100 | [diff] [blame] | 1045 | /* Any widget will do, they should all be updating the |
| 1046 | * same register. |
| 1047 | */ |
| 1048 | w = list_first_entry(pending, struct snd_soc_dapm_widget, |
| 1049 | power_list); |
| 1050 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 1051 | pop_dbg(dapm->dev, card->pop_time, |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1052 | "pop test : Applying 0x%x/0x%x to %x in %dms\n", |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1053 | value, mask, reg, card->pop_time); |
| 1054 | pop_wait(card->pop_time); |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 1055 | soc_widget_update_bits(w, reg, mask, value); |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | list_for_each_entry(w, pending, power_list) { |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 1059 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU); |
| 1060 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD); |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1061 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1064 | /* Apply a DAPM power sequence. |
| 1065 | * |
| 1066 | * We walk over a pre-sorted list of widgets to apply power to. In |
| 1067 | * order to minimise the number of writes to the device required |
| 1068 | * multiple widgets will be updated in a single write where possible. |
| 1069 | * Currently anything that requires more than a single write is not |
| 1070 | * handled. |
| 1071 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1072 | static void dapm_seq_run(struct snd_soc_dapm_context *dapm, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1073 | struct list_head *list, int event, bool power_up) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1074 | { |
| 1075 | struct snd_soc_dapm_widget *w, *n; |
| 1076 | LIST_HEAD(pending); |
| 1077 | int cur_sort = -1; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1078 | int cur_subseq = -1; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1079 | int cur_reg = SND_SOC_NOPM; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1080 | struct snd_soc_dapm_context *cur_dapm = NULL; |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1081 | int ret, i; |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1082 | int *sort; |
| 1083 | |
| 1084 | if (power_up) |
| 1085 | sort = dapm_up_seq; |
| 1086 | else |
| 1087 | sort = dapm_down_seq; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1088 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1089 | list_for_each_entry_safe(w, n, list, power_list) { |
| 1090 | ret = 0; |
| 1091 | |
| 1092 | /* Do we need to apply any queued changes? */ |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1093 | if (sort[w->id] != cur_sort || w->reg != cur_reg || |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1094 | w->dapm != cur_dapm || w->subseq != cur_subseq) { |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1095 | if (!list_empty(&pending)) |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1096 | dapm_seq_run_coalesced(cur_dapm, &pending); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1097 | |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1098 | if (cur_dapm && cur_dapm->seq_notifier) { |
| 1099 | for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) |
| 1100 | if (sort[i] == cur_sort) |
| 1101 | cur_dapm->seq_notifier(cur_dapm, |
Mark Brown | f85a9e0 | 2011-01-26 21:41:28 +0000 | [diff] [blame] | 1102 | i, |
| 1103 | cur_subseq); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1106 | INIT_LIST_HEAD(&pending); |
| 1107 | cur_sort = -1; |
Mark Brown | b0b3e6f | 2011-07-16 10:55:08 +0900 | [diff] [blame] | 1108 | cur_subseq = INT_MIN; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1109 | cur_reg = SND_SOC_NOPM; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1110 | cur_dapm = NULL; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1111 | } |
| 1112 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1113 | switch (w->id) { |
| 1114 | case snd_soc_dapm_pre: |
| 1115 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1116 | list_for_each_entry_safe_continue(w, n, list, |
| 1117 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1118 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1119 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1120 | ret = w->event(w, |
| 1121 | NULL, SND_SOC_DAPM_PRE_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1122 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1123 | ret = w->event(w, |
| 1124 | NULL, SND_SOC_DAPM_PRE_PMD); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1125 | break; |
| 1126 | |
| 1127 | case snd_soc_dapm_post: |
| 1128 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1129 | list_for_each_entry_safe_continue(w, n, list, |
| 1130 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1131 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1132 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1133 | ret = w->event(w, |
| 1134 | NULL, SND_SOC_DAPM_POST_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1135 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1136 | ret = w->event(w, |
| 1137 | NULL, SND_SOC_DAPM_POST_PMD); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1138 | break; |
| 1139 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1140 | default: |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1141 | /* Queue it up for application */ |
| 1142 | cur_sort = sort[w->id]; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1143 | cur_subseq = w->subseq; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1144 | cur_reg = w->reg; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1145 | cur_dapm = w->dapm; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1146 | list_move(&w->power_list, &pending); |
| 1147 | break; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1148 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1149 | |
| 1150 | if (ret < 0) |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 1151 | dev_err(w->dapm->dev, |
| 1152 | "Failed to apply widget power: %d\n", ret); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1153 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1154 | |
| 1155 | if (!list_empty(&pending)) |
Mark Brown | 28e8680 | 2011-03-08 19:29:53 +0000 | [diff] [blame] | 1156 | dapm_seq_run_coalesced(cur_dapm, &pending); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1157 | |
| 1158 | if (cur_dapm && cur_dapm->seq_notifier) { |
| 1159 | for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) |
| 1160 | if (sort[i] == cur_sort) |
| 1161 | cur_dapm->seq_notifier(cur_dapm, |
Mark Brown | f85a9e0 | 2011-01-26 21:41:28 +0000 | [diff] [blame] | 1162 | i, cur_subseq); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1163 | } |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1164 | } |
| 1165 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1166 | static void dapm_widget_update(struct snd_soc_dapm_context *dapm) |
| 1167 | { |
| 1168 | struct snd_soc_dapm_update *update = dapm->update; |
| 1169 | struct snd_soc_dapm_widget *w; |
| 1170 | int ret; |
| 1171 | |
| 1172 | if (!update) |
| 1173 | return; |
| 1174 | |
| 1175 | w = update->widget; |
| 1176 | |
| 1177 | if (w->event && |
| 1178 | (w->event_flags & SND_SOC_DAPM_PRE_REG)) { |
| 1179 | ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG); |
| 1180 | if (ret != 0) |
| 1181 | pr_err("%s DAPM pre-event failed: %d\n", |
| 1182 | w->name, ret); |
| 1183 | } |
| 1184 | |
| 1185 | ret = snd_soc_update_bits(w->codec, update->reg, update->mask, |
| 1186 | update->val); |
| 1187 | if (ret < 0) |
| 1188 | pr_err("%s DAPM update failed: %d\n", w->name, ret); |
| 1189 | |
| 1190 | if (w->event && |
| 1191 | (w->event_flags & SND_SOC_DAPM_POST_REG)) { |
| 1192 | ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG); |
| 1193 | if (ret != 0) |
| 1194 | pr_err("%s DAPM post-event failed: %d\n", |
| 1195 | w->name, ret); |
| 1196 | } |
| 1197 | } |
| 1198 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1199 | /* Async callback run prior to DAPM sequences - brings to _PREPARE if |
| 1200 | * they're changing state. |
| 1201 | */ |
| 1202 | static void dapm_pre_sequence_async(void *data, async_cookie_t cookie) |
| 1203 | { |
| 1204 | struct snd_soc_dapm_context *d = data; |
| 1205 | int ret; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1206 | |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1207 | /* If we're off and we're not supposed to be go into STANDBY */ |
| 1208 | if (d->bias_level == SND_SOC_BIAS_OFF && |
| 1209 | d->target_bias_level != SND_SOC_BIAS_OFF) { |
Mark Brown | f1aac48 | 2011-12-05 15:17:06 +0000 | [diff] [blame] | 1210 | if (d->dev) |
| 1211 | pm_runtime_get_sync(d->dev); |
| 1212 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1213 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY); |
| 1214 | if (ret != 0) |
| 1215 | dev_err(d->dev, |
| 1216 | "Failed to turn on bias: %d\n", ret); |
| 1217 | } |
| 1218 | |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1219 | /* Prepare for a STADDBY->ON or ON->STANDBY transition */ |
| 1220 | if (d->bias_level != d->target_bias_level) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1221 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE); |
| 1222 | if (ret != 0) |
| 1223 | dev_err(d->dev, |
| 1224 | "Failed to prepare bias: %d\n", ret); |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | /* Async callback run prior to DAPM sequences - brings to their final |
| 1229 | * state. |
| 1230 | */ |
| 1231 | static void dapm_post_sequence_async(void *data, async_cookie_t cookie) |
| 1232 | { |
| 1233 | struct snd_soc_dapm_context *d = data; |
| 1234 | int ret; |
| 1235 | |
| 1236 | /* If we just powered the last thing off drop to standby bias */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1237 | if (d->bias_level == SND_SOC_BIAS_PREPARE && |
| 1238 | (d->target_bias_level == SND_SOC_BIAS_STANDBY || |
| 1239 | d->target_bias_level == SND_SOC_BIAS_OFF)) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1240 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY); |
| 1241 | if (ret != 0) |
| 1242 | dev_err(d->dev, "Failed to apply standby bias: %d\n", |
| 1243 | ret); |
| 1244 | } |
| 1245 | |
| 1246 | /* 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] | 1247 | if (d->bias_level == SND_SOC_BIAS_STANDBY && |
| 1248 | d->target_bias_level == SND_SOC_BIAS_OFF) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1249 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF); |
| 1250 | if (ret != 0) |
| 1251 | dev_err(d->dev, "Failed to turn off bias: %d\n", ret); |
Mark Brown | f1aac48 | 2011-12-05 15:17:06 +0000 | [diff] [blame] | 1252 | |
| 1253 | if (d->dev) |
| 1254 | pm_runtime_put_sync(d->dev); |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | /* If we just powered up then move to active bias */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1258 | if (d->bias_level == SND_SOC_BIAS_PREPARE && |
| 1259 | d->target_bias_level == SND_SOC_BIAS_ON) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1260 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON); |
| 1261 | if (ret != 0) |
| 1262 | dev_err(d->dev, "Failed to apply active bias: %d\n", |
| 1263 | ret); |
| 1264 | } |
| 1265 | } |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1266 | |
Mark Brown | fe4fda5 | 2011-10-03 22:36:57 +0100 | [diff] [blame] | 1267 | static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget *peer, |
| 1268 | bool power, bool connect) |
| 1269 | { |
| 1270 | /* If a connection is being made or broken then that update |
| 1271 | * will have marked the peer dirty, otherwise the widgets are |
| 1272 | * not connected and this update has no impact. */ |
| 1273 | if (!connect) |
| 1274 | return; |
| 1275 | |
| 1276 | /* If the peer is already in the state we're moving to then we |
| 1277 | * won't have an impact on it. */ |
| 1278 | if (power != peer->power) |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1279 | dapm_mark_dirty(peer, "peer state change"); |
Mark Brown | fe4fda5 | 2011-10-03 22:36:57 +0100 | [diff] [blame] | 1280 | } |
| 1281 | |
Mark Brown | 05623c4 | 2011-09-28 17:02:31 +0100 | [diff] [blame] | 1282 | static void dapm_widget_set_power(struct snd_soc_dapm_widget *w, bool power, |
| 1283 | struct list_head *up_list, |
| 1284 | struct list_head *down_list) |
| 1285 | { |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1286 | struct snd_soc_dapm_path *path; |
| 1287 | |
Mark Brown | 05623c4 | 2011-09-28 17:02:31 +0100 | [diff] [blame] | 1288 | if (w->power == power) |
| 1289 | return; |
| 1290 | |
| 1291 | trace_snd_soc_dapm_widget_power(w, power); |
| 1292 | |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1293 | /* If we changed our power state perhaps our neigbours changed |
Mark Brown | fe4fda5 | 2011-10-03 22:36:57 +0100 | [diff] [blame] | 1294 | * also. |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1295 | */ |
| 1296 | list_for_each_entry(path, &w->sources, list_sink) { |
| 1297 | if (path->source) { |
Mark Brown | fe4fda5 | 2011-10-03 22:36:57 +0100 | [diff] [blame] | 1298 | dapm_widget_set_peer_power(path->source, power, |
| 1299 | path->connect); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1300 | } |
| 1301 | } |
Mark Brown | f3bf3e4 | 2011-10-04 22:43:31 +0100 | [diff] [blame] | 1302 | switch (w->id) { |
| 1303 | case snd_soc_dapm_supply: |
| 1304 | /* Supplies can't affect their outputs, only their inputs */ |
| 1305 | break; |
| 1306 | default: |
| 1307 | list_for_each_entry(path, &w->sinks, list_source) { |
| 1308 | if (path->sink) { |
| 1309 | dapm_widget_set_peer_power(path->sink, power, |
| 1310 | path->connect); |
| 1311 | } |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1312 | } |
Mark Brown | f3bf3e4 | 2011-10-04 22:43:31 +0100 | [diff] [blame] | 1313 | break; |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1314 | } |
| 1315 | |
Mark Brown | 05623c4 | 2011-09-28 17:02:31 +0100 | [diff] [blame] | 1316 | if (power) |
| 1317 | dapm_seq_insert(w, up_list, true); |
| 1318 | else |
| 1319 | dapm_seq_insert(w, down_list, false); |
| 1320 | |
| 1321 | w->power = power; |
| 1322 | } |
| 1323 | |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1324 | static void dapm_power_one_widget(struct snd_soc_dapm_widget *w, |
| 1325 | struct list_head *up_list, |
| 1326 | struct list_head *down_list) |
| 1327 | { |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1328 | int power; |
| 1329 | |
| 1330 | switch (w->id) { |
| 1331 | case snd_soc_dapm_pre: |
| 1332 | dapm_seq_insert(w, down_list, false); |
| 1333 | break; |
| 1334 | case snd_soc_dapm_post: |
| 1335 | dapm_seq_insert(w, up_list, true); |
| 1336 | break; |
| 1337 | |
| 1338 | default: |
Mark Brown | d805002 | 2011-09-28 18:28:23 +0100 | [diff] [blame] | 1339 | power = dapm_widget_power_check(w); |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1340 | |
Mark Brown | 05623c4 | 2011-09-28 17:02:31 +0100 | [diff] [blame] | 1341 | dapm_widget_set_power(w, power, up_list, down_list); |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1342 | break; |
| 1343 | } |
| 1344 | } |
| 1345 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1346 | /* |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1347 | * Scan each dapm widget for complete audio path. |
| 1348 | * A complete path is a route that has valid endpoints i.e.:- |
| 1349 | * |
| 1350 | * o DAC to output pin. |
| 1351 | * o Input Pin to ADC. |
| 1352 | * o Input pin to Output pin (bypass, sidetone) |
| 1353 | * o DAC to ADC (loopback). |
| 1354 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1355 | static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1356 | { |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 1357 | struct snd_soc_card *card = dapm->card; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1358 | struct snd_soc_dapm_widget *w; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1359 | struct snd_soc_dapm_context *d; |
Mark Brown | 291f3bb | 2009-06-07 13:57:17 +0100 | [diff] [blame] | 1360 | LIST_HEAD(up_list); |
| 1361 | LIST_HEAD(down_list); |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1362 | LIST_HEAD(async_domain); |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1363 | enum snd_soc_bias_level bias; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1364 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1365 | trace_snd_soc_dapm_start(card); |
| 1366 | |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1367 | list_for_each_entry(d, &card->dapm_list, list) { |
| 1368 | if (d->n_widgets || d->codec == NULL) { |
| 1369 | if (d->idle_bias_off) |
| 1370 | d->target_bias_level = SND_SOC_BIAS_OFF; |
| 1371 | else |
| 1372 | d->target_bias_level = SND_SOC_BIAS_STANDBY; |
| 1373 | } |
| 1374 | } |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1375 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 1376 | memset(&card->dapm_stats, 0, sizeof(card->dapm_stats)); |
| 1377 | |
Mark Brown | 9b8a83b | 2011-10-04 22:15:59 +0100 | [diff] [blame] | 1378 | list_for_each_entry(w, &card->widgets, list) { |
| 1379 | w->power_checked = false; |
Mark Brown | 024dc07 | 2011-10-09 11:52:05 +0100 | [diff] [blame] | 1380 | w->inputs = -1; |
| 1381 | w->outputs = -1; |
Mark Brown | 9b8a83b | 2011-10-04 22:15:59 +0100 | [diff] [blame] | 1382 | } |
| 1383 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1384 | /* Check which widgets we need to power and store them in |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1385 | * lists indicating if they should be powered up or down. We |
| 1386 | * only check widgets that have been flagged as dirty but note |
| 1387 | * that new widgets may be added to the dirty list while we |
| 1388 | * iterate. |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1389 | */ |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1390 | list_for_each_entry(w, &card->dapm_dirty, dirty) { |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1391 | dapm_power_one_widget(w, &up_list, &down_list); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1392 | } |
| 1393 | |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1394 | list_for_each_entry(w, &card->widgets, list) { |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1395 | list_del_init(&w->dirty); |
| 1396 | |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1397 | if (w->power) { |
| 1398 | d = w->dapm; |
| 1399 | |
| 1400 | /* Supplies and micbiases only bring the |
| 1401 | * context up to STANDBY as unless something |
| 1402 | * else is active and passing audio they |
| 1403 | * generally don't require full power. |
| 1404 | */ |
| 1405 | switch (w->id) { |
| 1406 | case snd_soc_dapm_supply: |
| 1407 | case snd_soc_dapm_micbias: |
| 1408 | if (d->target_bias_level < SND_SOC_BIAS_STANDBY) |
| 1409 | d->target_bias_level = SND_SOC_BIAS_STANDBY; |
| 1410 | break; |
| 1411 | default: |
| 1412 | d->target_bias_level = SND_SOC_BIAS_ON; |
| 1413 | break; |
| 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | } |
| 1418 | |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1419 | /* If there are no DAPM widgets then try to figure out power from the |
| 1420 | * event type. |
| 1421 | */ |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1422 | if (!dapm->n_widgets) { |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1423 | switch (event) { |
| 1424 | case SND_SOC_DAPM_STREAM_START: |
| 1425 | case SND_SOC_DAPM_STREAM_RESUME: |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1426 | dapm->target_bias_level = SND_SOC_BIAS_ON; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1427 | break; |
Jarkko Nikula | 862af8a | 2010-12-10 20:53:55 +0200 | [diff] [blame] | 1428 | case SND_SOC_DAPM_STREAM_STOP: |
Liam Girdwood | e7c80e2 | 2012-01-16 15:23:31 +0000 | [diff] [blame] | 1429 | if (dapm->codec && dapm->codec->active) |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1430 | dapm->target_bias_level = SND_SOC_BIAS_ON; |
| 1431 | else |
| 1432 | dapm->target_bias_level = SND_SOC_BIAS_STANDBY; |
Jarkko Nikula | 862af8a | 2010-12-10 20:53:55 +0200 | [diff] [blame] | 1433 | break; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1434 | case SND_SOC_DAPM_STREAM_SUSPEND: |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1435 | dapm->target_bias_level = SND_SOC_BIAS_STANDBY; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1436 | break; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1437 | case SND_SOC_DAPM_STREAM_NOP: |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1438 | dapm->target_bias_level = dapm->bias_level; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1439 | break; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1440 | default: |
| 1441 | break; |
| 1442 | } |
| 1443 | } |
| 1444 | |
Mark Brown | 85a843c | 2011-09-21 21:29:47 +0100 | [diff] [blame] | 1445 | /* Force all contexts in the card to the same bias state if |
| 1446 | * they're not ground referenced. |
| 1447 | */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1448 | bias = SND_SOC_BIAS_OFF; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1449 | list_for_each_entry(d, &card->dapm_list, list) |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1450 | if (d->target_bias_level > bias) |
| 1451 | bias = d->target_bias_level; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1452 | list_for_each_entry(d, &card->dapm_list, list) |
Mark Brown | 85a843c | 2011-09-21 21:29:47 +0100 | [diff] [blame] | 1453 | if (!d->idle_bias_off) |
| 1454 | d->target_bias_level = bias; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1455 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 1456 | trace_snd_soc_dapm_walk_done(card); |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1457 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1458 | /* Run all the bias changes in parallel */ |
| 1459 | list_for_each_entry(d, &dapm->card->dapm_list, list) |
| 1460 | async_schedule_domain(dapm_pre_sequence_async, d, |
| 1461 | &async_domain); |
| 1462 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1463 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1464 | /* Power down widgets first; try to avoid amplifying pops. */ |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1465 | dapm_seq_run(dapm, &down_list, event, false); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1466 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1467 | dapm_widget_update(dapm); |
| 1468 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1469 | /* Now power up. */ |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1470 | dapm_seq_run(dapm, &up_list, event, true); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1471 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1472 | /* Run all the bias changes in parallel */ |
| 1473 | list_for_each_entry(d, &dapm->card->dapm_list, list) |
| 1474 | async_schedule_domain(dapm_post_sequence_async, d, |
| 1475 | &async_domain); |
| 1476 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1477 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 1478 | pop_dbg(dapm->dev, card->pop_time, |
| 1479 | "DAPM sequencing finished, waiting %dms\n", card->pop_time); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1480 | pop_wait(card->pop_time); |
Mark Brown | cb507e7 | 2009-07-08 18:54:57 +0100 | [diff] [blame] | 1481 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1482 | trace_snd_soc_dapm_done(card); |
| 1483 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1484 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1485 | } |
| 1486 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1487 | #ifdef CONFIG_DEBUG_FS |
| 1488 | static int dapm_widget_power_open_file(struct inode *inode, struct file *file) |
| 1489 | { |
| 1490 | file->private_data = inode->i_private; |
| 1491 | return 0; |
| 1492 | } |
| 1493 | |
| 1494 | static ssize_t dapm_widget_power_read_file(struct file *file, |
| 1495 | char __user *user_buf, |
| 1496 | size_t count, loff_t *ppos) |
| 1497 | { |
| 1498 | struct snd_soc_dapm_widget *w = file->private_data; |
| 1499 | char *buf; |
| 1500 | int in, out; |
| 1501 | ssize_t ret; |
| 1502 | struct snd_soc_dapm_path *p = NULL; |
| 1503 | |
| 1504 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 1505 | if (!buf) |
| 1506 | return -ENOMEM; |
| 1507 | |
| 1508 | in = is_connected_input_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1509 | dapm_clear_walk(w->dapm); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1510 | out = is_connected_output_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1511 | dapm_clear_walk(w->dapm); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1512 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1513 | ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1514 | w->name, w->power ? "On" : "Off", in, out); |
| 1515 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1516 | if (w->reg >= 0) |
| 1517 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
| 1518 | " - R%d(0x%x) bit %d", |
| 1519 | w->reg, w->reg, w->shift); |
| 1520 | |
| 1521 | ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n"); |
| 1522 | |
Mark Brown | 3eef08b | 2009-09-14 16:49:00 +0100 | [diff] [blame] | 1523 | if (w->sname) |
| 1524 | ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n", |
| 1525 | w->sname, |
| 1526 | w->active ? "active" : "inactive"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1527 | |
| 1528 | list_for_each_entry(p, &w->sources, list_sink) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1529 | if (p->connected && !p->connected(w, p->sink)) |
| 1530 | continue; |
| 1531 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1532 | if (p->connect) |
| 1533 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Dimitris Papastamos | 67f5ed6 | 2011-02-24 17:09:32 +0000 | [diff] [blame] | 1534 | " in \"%s\" \"%s\"\n", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1535 | p->name ? p->name : "static", |
| 1536 | p->source->name); |
| 1537 | } |
| 1538 | list_for_each_entry(p, &w->sinks, list_source) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1539 | if (p->connected && !p->connected(w, p->sink)) |
| 1540 | continue; |
| 1541 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1542 | if (p->connect) |
| 1543 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Dimitris Papastamos | 67f5ed6 | 2011-02-24 17:09:32 +0000 | [diff] [blame] | 1544 | " out \"%s\" \"%s\"\n", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1545 | p->name ? p->name : "static", |
| 1546 | p->sink->name); |
| 1547 | } |
| 1548 | |
| 1549 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 1550 | |
| 1551 | kfree(buf); |
| 1552 | return ret; |
| 1553 | } |
| 1554 | |
| 1555 | static const struct file_operations dapm_widget_power_fops = { |
| 1556 | .open = dapm_widget_power_open_file, |
| 1557 | .read = dapm_widget_power_read_file, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1558 | .llseek = default_llseek, |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1559 | }; |
| 1560 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1561 | static int dapm_bias_open_file(struct inode *inode, struct file *file) |
| 1562 | { |
| 1563 | file->private_data = inode->i_private; |
| 1564 | return 0; |
| 1565 | } |
| 1566 | |
| 1567 | static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf, |
| 1568 | size_t count, loff_t *ppos) |
| 1569 | { |
| 1570 | struct snd_soc_dapm_context *dapm = file->private_data; |
| 1571 | char *level; |
| 1572 | |
| 1573 | switch (dapm->bias_level) { |
| 1574 | case SND_SOC_BIAS_ON: |
| 1575 | level = "On\n"; |
| 1576 | break; |
| 1577 | case SND_SOC_BIAS_PREPARE: |
| 1578 | level = "Prepare\n"; |
| 1579 | break; |
| 1580 | case SND_SOC_BIAS_STANDBY: |
| 1581 | level = "Standby\n"; |
| 1582 | break; |
| 1583 | case SND_SOC_BIAS_OFF: |
| 1584 | level = "Off\n"; |
| 1585 | break; |
| 1586 | default: |
| 1587 | BUG(); |
| 1588 | level = "Unknown\n"; |
| 1589 | break; |
| 1590 | } |
| 1591 | |
| 1592 | return simple_read_from_buffer(user_buf, count, ppos, level, |
| 1593 | strlen(level)); |
| 1594 | } |
| 1595 | |
| 1596 | static const struct file_operations dapm_bias_fops = { |
| 1597 | .open = dapm_bias_open_file, |
| 1598 | .read = dapm_bias_read_file, |
| 1599 | .llseek = default_llseek, |
| 1600 | }; |
| 1601 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1602 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 1603 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1604 | { |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1605 | struct dentry *d; |
| 1606 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1607 | dapm->debugfs_dapm = debugfs_create_dir("dapm", parent); |
| 1608 | |
| 1609 | if (!dapm->debugfs_dapm) { |
| 1610 | printk(KERN_WARNING |
| 1611 | "Failed to create DAPM debugfs directory\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1612 | return; |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1613 | } |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1614 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1615 | d = debugfs_create_file("bias_level", 0444, |
| 1616 | dapm->debugfs_dapm, dapm, |
| 1617 | &dapm_bias_fops); |
| 1618 | if (!d) |
| 1619 | dev_warn(dapm->dev, |
| 1620 | "ASoC: Failed to create bias level debugfs file\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1621 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1622 | |
| 1623 | static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 1624 | { |
| 1625 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 1626 | struct dentry *d; |
| 1627 | |
| 1628 | if (!dapm->debugfs_dapm || !w->name) |
| 1629 | return; |
| 1630 | |
| 1631 | d = debugfs_create_file(w->name, 0444, |
| 1632 | dapm->debugfs_dapm, w, |
| 1633 | &dapm_widget_power_fops); |
| 1634 | if (!d) |
| 1635 | dev_warn(w->dapm->dev, |
| 1636 | "ASoC: Failed to create %s debugfs file\n", |
| 1637 | w->name); |
| 1638 | } |
| 1639 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 1640 | static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 1641 | { |
| 1642 | debugfs_remove_recursive(dapm->debugfs_dapm); |
| 1643 | } |
| 1644 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1645 | #else |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1646 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 1647 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1648 | { |
| 1649 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1650 | |
| 1651 | static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 1652 | { |
| 1653 | } |
| 1654 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 1655 | static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 1656 | { |
| 1657 | } |
| 1658 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1659 | #endif |
| 1660 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1661 | /* test and update the power status of a mux widget */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 1662 | static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget, |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1663 | struct snd_kcontrol *kcontrol, int change, |
| 1664 | int mux, struct soc_enum *e) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1665 | { |
| 1666 | struct snd_soc_dapm_path *path; |
| 1667 | int found = 0; |
| 1668 | |
Peter Ujfalusi | eff317d | 2009-01-15 14:40:47 +0200 | [diff] [blame] | 1669 | if (widget->id != snd_soc_dapm_mux && |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 1670 | widget->id != snd_soc_dapm_virt_mux && |
Peter Ujfalusi | eff317d | 2009-01-15 14:40:47 +0200 | [diff] [blame] | 1671 | widget->id != snd_soc_dapm_value_mux) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1672 | return -ENODEV; |
| 1673 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1674 | if (!change) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1675 | return 0; |
| 1676 | |
| 1677 | /* find dapm widget path assoc with kcontrol */ |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1678 | list_for_each_entry(path, &widget->dapm->card->paths, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1679 | if (path->kcontrol != kcontrol) |
| 1680 | continue; |
| 1681 | |
Richard Zhao | cb01e2b | 2008-10-07 08:05:20 +0800 | [diff] [blame] | 1682 | if (!path->name || !e->texts[mux]) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1683 | continue; |
| 1684 | |
| 1685 | found = 1; |
| 1686 | /* 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] | 1687 | if (!(strcmp(path->name, e->texts[mux]))) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1688 | path->connect = 1; /* new connection */ |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1689 | dapm_mark_dirty(path->source, "mux connection"); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1690 | } else { |
| 1691 | if (path->connect) |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1692 | dapm_mark_dirty(path->source, |
| 1693 | "mux disconnection"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1694 | path->connect = 0; /* old connection must be powered down */ |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1695 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1696 | } |
| 1697 | |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1698 | if (found) { |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1699 | dapm_mark_dirty(widget, "mux change"); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1700 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1701 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1702 | |
| 1703 | return 0; |
| 1704 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1705 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1706 | /* test and update the power status of a mixer or switch widget */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 1707 | static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1708 | struct snd_kcontrol *kcontrol, int connect) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1709 | { |
| 1710 | struct snd_soc_dapm_path *path; |
| 1711 | int found = 0; |
| 1712 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1713 | if (widget->id != snd_soc_dapm_mixer && |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1714 | widget->id != snd_soc_dapm_mixer_named_ctl && |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1715 | widget->id != snd_soc_dapm_switch) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1716 | return -ENODEV; |
| 1717 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1718 | /* find dapm widget path assoc with kcontrol */ |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1719 | list_for_each_entry(path, &widget->dapm->card->paths, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1720 | if (path->kcontrol != kcontrol) |
| 1721 | continue; |
| 1722 | |
| 1723 | /* found, now check type */ |
| 1724 | found = 1; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1725 | path->connect = connect; |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1726 | dapm_mark_dirty(path->source, "mixer connection"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1727 | } |
| 1728 | |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1729 | if (found) { |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1730 | dapm_mark_dirty(widget, "mixer update"); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1731 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1732 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1733 | |
| 1734 | return 0; |
| 1735 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1736 | |
| 1737 | /* show dapm widget status in sys fs */ |
| 1738 | static ssize_t dapm_widget_show(struct device *dev, |
| 1739 | struct device_attribute *attr, char *buf) |
| 1740 | { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1741 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1742 | struct snd_soc_codec *codec =rtd->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1743 | struct snd_soc_dapm_widget *w; |
| 1744 | int count = 0; |
| 1745 | char *state = "not set"; |
| 1746 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1747 | list_for_each_entry(w, &codec->card->widgets, list) { |
| 1748 | if (w->dapm != &codec->dapm) |
| 1749 | continue; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1750 | |
| 1751 | /* only display widgets that burnm power */ |
| 1752 | switch (w->id) { |
| 1753 | case snd_soc_dapm_hp: |
| 1754 | case snd_soc_dapm_mic: |
| 1755 | case snd_soc_dapm_spk: |
| 1756 | case snd_soc_dapm_line: |
| 1757 | case snd_soc_dapm_micbias: |
| 1758 | case snd_soc_dapm_dac: |
| 1759 | case snd_soc_dapm_adc: |
| 1760 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 1761 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1762 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1763 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1764 | case snd_soc_dapm_supply: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1765 | if (w->name) |
| 1766 | count += sprintf(buf + count, "%s: %s\n", |
| 1767 | w->name, w->power ? "On":"Off"); |
| 1768 | break; |
| 1769 | default: |
| 1770 | break; |
| 1771 | } |
| 1772 | } |
| 1773 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1774 | switch (codec->dapm.bias_level) { |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1775 | case SND_SOC_BIAS_ON: |
| 1776 | state = "On"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1777 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1778 | case SND_SOC_BIAS_PREPARE: |
| 1779 | state = "Prepare"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1780 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1781 | case SND_SOC_BIAS_STANDBY: |
| 1782 | state = "Standby"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1783 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1784 | case SND_SOC_BIAS_OFF: |
| 1785 | state = "Off"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1786 | break; |
| 1787 | } |
| 1788 | count += sprintf(buf + count, "PM State: %s\n", state); |
| 1789 | |
| 1790 | return count; |
| 1791 | } |
| 1792 | |
| 1793 | static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL); |
| 1794 | |
| 1795 | int snd_soc_dapm_sys_add(struct device *dev) |
| 1796 | { |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1797 | return device_create_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | static void snd_soc_dapm_sys_remove(struct device *dev) |
| 1801 | { |
Mark Brown | aef9084 | 2009-05-16 17:53:16 +0100 | [diff] [blame] | 1802 | device_remove_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | /* free all dapm widgets and resources */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1806 | static void dapm_free_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1807 | { |
| 1808 | struct snd_soc_dapm_widget *w, *next_w; |
| 1809 | struct snd_soc_dapm_path *p, *next_p; |
| 1810 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1811 | list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) { |
| 1812 | if (w->dapm != dapm) |
| 1813 | continue; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1814 | list_del(&w->list); |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1815 | /* |
| 1816 | * remove source and sink paths associated to this widget. |
| 1817 | * While removing the path, remove reference to it from both |
| 1818 | * source and sink widgets so that path is removed only once. |
| 1819 | */ |
| 1820 | list_for_each_entry_safe(p, next_p, &w->sources, list_sink) { |
| 1821 | list_del(&p->list_sink); |
| 1822 | list_del(&p->list_source); |
| 1823 | list_del(&p->list); |
| 1824 | kfree(p->long_name); |
| 1825 | kfree(p); |
| 1826 | } |
| 1827 | list_for_each_entry_safe(p, next_p, &w->sinks, list_source) { |
| 1828 | list_del(&p->list_sink); |
| 1829 | list_del(&p->list_source); |
| 1830 | list_del(&p->list); |
| 1831 | kfree(p->long_name); |
| 1832 | kfree(p); |
| 1833 | } |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 1834 | kfree(w->kcontrols); |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1835 | kfree(w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1836 | kfree(w); |
| 1837 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1838 | } |
| 1839 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1840 | static struct snd_soc_dapm_widget *dapm_find_widget( |
| 1841 | struct snd_soc_dapm_context *dapm, const char *pin, |
| 1842 | bool search_other_contexts) |
| 1843 | { |
| 1844 | struct snd_soc_dapm_widget *w; |
| 1845 | struct snd_soc_dapm_widget *fallback = NULL; |
| 1846 | |
| 1847 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 1848 | if (!strcmp(w->name, pin)) { |
| 1849 | if (w->dapm == dapm) |
| 1850 | return w; |
| 1851 | else |
| 1852 | fallback = w; |
| 1853 | } |
| 1854 | } |
| 1855 | |
| 1856 | if (search_other_contexts) |
| 1857 | return fallback; |
| 1858 | |
| 1859 | return NULL; |
| 1860 | } |
| 1861 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1862 | 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] | 1863 | const char *pin, int status) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1864 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1865 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1866 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1867 | if (!w) { |
| 1868 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 1869 | return -EINVAL; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1870 | } |
| 1871 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1872 | w->connected = status; |
| 1873 | if (status == 0) |
| 1874 | w->force = 0; |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1875 | dapm_mark_dirty(w, "pin configuration"); |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 1876 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1877 | return 0; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1878 | } |
| 1879 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1880 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1881 | * snd_soc_dapm_sync - scan and power dapm paths |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1882 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1883 | * |
| 1884 | * Walks all dapm audio paths and powers widgets according to their |
| 1885 | * stream or path usage. |
| 1886 | * |
| 1887 | * Returns 0 for success. |
| 1888 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1889 | int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1890 | { |
Mark Brown | 4f4c007 | 2011-10-07 14:29:19 +0100 | [diff] [blame] | 1891 | /* |
| 1892 | * Suppress early reports (eg, jacks syncing their state) to avoid |
| 1893 | * silly DAPM runs during card startup. |
| 1894 | */ |
| 1895 | if (!dapm->card || !dapm->card->instantiated) |
| 1896 | return 0; |
| 1897 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1898 | return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1899 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1900 | EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1901 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1902 | 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] | 1903 | const struct snd_soc_dapm_route *route) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1904 | { |
| 1905 | struct snd_soc_dapm_path *path; |
| 1906 | struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w; |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1907 | struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1908 | const char *sink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1909 | const char *control = route->control; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1910 | const char *source; |
| 1911 | char prefixed_sink[80]; |
| 1912 | char prefixed_source[80]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1913 | int ret = 0; |
| 1914 | |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 1915 | if (dapm->codec && dapm->codec->name_prefix) { |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1916 | snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s", |
| 1917 | dapm->codec->name_prefix, route->sink); |
| 1918 | sink = prefixed_sink; |
| 1919 | snprintf(prefixed_source, sizeof(prefixed_source), "%s %s", |
| 1920 | dapm->codec->name_prefix, route->source); |
| 1921 | source = prefixed_source; |
| 1922 | } else { |
| 1923 | sink = route->sink; |
| 1924 | source = route->source; |
| 1925 | } |
| 1926 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1927 | /* |
| 1928 | * find src and dest widgets over all widgets but favor a widget from |
| 1929 | * current DAPM context |
| 1930 | */ |
| 1931 | list_for_each_entry(w, &dapm->card->widgets, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1932 | if (!wsink && !(strcmp(w->name, sink))) { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1933 | wtsink = w; |
| 1934 | if (w->dapm == dapm) |
| 1935 | wsink = w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1936 | continue; |
| 1937 | } |
| 1938 | if (!wsource && !(strcmp(w->name, source))) { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1939 | wtsource = w; |
| 1940 | if (w->dapm == dapm) |
| 1941 | wsource = w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1942 | } |
| 1943 | } |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1944 | /* use widget from another DAPM context if not found from this */ |
| 1945 | if (!wsink) |
| 1946 | wsink = wtsink; |
| 1947 | if (!wsource) |
| 1948 | wsource = wtsource; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1949 | |
| 1950 | if (wsource == NULL || wsink == NULL) |
| 1951 | return -ENODEV; |
| 1952 | |
| 1953 | path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL); |
| 1954 | if (!path) |
| 1955 | return -ENOMEM; |
| 1956 | |
| 1957 | path->source = wsource; |
| 1958 | path->sink = wsink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1959 | path->connected = route->connected; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1960 | INIT_LIST_HEAD(&path->list); |
| 1961 | INIT_LIST_HEAD(&path->list_source); |
| 1962 | INIT_LIST_HEAD(&path->list_sink); |
| 1963 | |
| 1964 | /* check for external widgets */ |
| 1965 | if (wsink->id == snd_soc_dapm_input) { |
| 1966 | if (wsource->id == snd_soc_dapm_micbias || |
| 1967 | wsource->id == snd_soc_dapm_mic || |
Rongrong Cao | 087d53a | 2009-07-10 20:13:30 +0100 | [diff] [blame] | 1968 | wsource->id == snd_soc_dapm_line || |
| 1969 | wsource->id == snd_soc_dapm_output) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1970 | wsink->ext = 1; |
| 1971 | } |
| 1972 | if (wsource->id == snd_soc_dapm_output) { |
| 1973 | if (wsink->id == snd_soc_dapm_spk || |
| 1974 | wsink->id == snd_soc_dapm_hp || |
Seth Forshee | 1e39221 | 2007-04-16 15:36:42 +0200 | [diff] [blame] | 1975 | wsink->id == snd_soc_dapm_line || |
| 1976 | wsink->id == snd_soc_dapm_input) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1977 | wsource->ext = 1; |
| 1978 | } |
| 1979 | |
| 1980 | /* connect static paths */ |
| 1981 | if (control == NULL) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1982 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1983 | list_add(&path->list_sink, &wsink->sources); |
| 1984 | list_add(&path->list_source, &wsource->sinks); |
| 1985 | path->connect = 1; |
| 1986 | return 0; |
| 1987 | } |
| 1988 | |
| 1989 | /* connect dynamic paths */ |
Lu Guanqun | dc2bea6 | 2011-04-20 16:00:36 +0800 | [diff] [blame] | 1990 | switch (wsink->id) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1991 | case snd_soc_dapm_adc: |
| 1992 | case snd_soc_dapm_dac: |
| 1993 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 1994 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1995 | case snd_soc_dapm_input: |
| 1996 | case snd_soc_dapm_output: |
Mark Brown | 1ab97c8 | 2011-11-27 16:21:51 +0000 | [diff] [blame] | 1997 | case snd_soc_dapm_siggen: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1998 | case snd_soc_dapm_micbias: |
| 1999 | case snd_soc_dapm_vmid: |
| 2000 | case snd_soc_dapm_pre: |
| 2001 | case snd_soc_dapm_post: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 2002 | case snd_soc_dapm_supply: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 2003 | case snd_soc_dapm_aif_in: |
| 2004 | case snd_soc_dapm_aif_out: |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 2005 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2006 | list_add(&path->list_sink, &wsink->sources); |
| 2007 | list_add(&path->list_source, &wsource->sinks); |
| 2008 | path->connect = 1; |
| 2009 | return 0; |
| 2010 | case snd_soc_dapm_mux: |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 2011 | case snd_soc_dapm_virt_mux: |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2012 | case snd_soc_dapm_value_mux: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2013 | ret = dapm_connect_mux(dapm, wsource, wsink, path, control, |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 2014 | &wsink->kcontrol_news[0]); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2015 | if (ret != 0) |
| 2016 | goto err; |
| 2017 | break; |
| 2018 | case snd_soc_dapm_switch: |
| 2019 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 2020 | case snd_soc_dapm_mixer_named_ctl: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2021 | ret = dapm_connect_mixer(dapm, wsource, wsink, path, control); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2022 | if (ret != 0) |
| 2023 | goto err; |
| 2024 | break; |
| 2025 | case snd_soc_dapm_hp: |
| 2026 | case snd_soc_dapm_mic: |
| 2027 | case snd_soc_dapm_line: |
| 2028 | case snd_soc_dapm_spk: |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 2029 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2030 | list_add(&path->list_sink, &wsink->sources); |
| 2031 | list_add(&path->list_source, &wsource->sinks); |
| 2032 | path->connect = 0; |
| 2033 | return 0; |
| 2034 | } |
| 2035 | return 0; |
| 2036 | |
| 2037 | err: |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2038 | dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n", |
| 2039 | source, control, sink); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2040 | kfree(path); |
| 2041 | return ret; |
| 2042 | } |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2043 | |
| 2044 | /** |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2045 | * snd_soc_dapm_add_routes - Add routes between DAPM widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2046 | * @dapm: DAPM context |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2047 | * @route: audio routes |
| 2048 | * @num: number of routes |
| 2049 | * |
| 2050 | * Connects 2 dapm widgets together via a named audio path. The sink is |
| 2051 | * the widget receiving the audio signal, whilst the source is the sender |
| 2052 | * of the audio signal. |
| 2053 | * |
| 2054 | * Returns 0 for success else error. On error all resources can be freed |
| 2055 | * with a call to snd_soc_card_free(). |
| 2056 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2057 | int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm, |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2058 | const struct snd_soc_dapm_route *route, int num) |
| 2059 | { |
| 2060 | int i, ret; |
| 2061 | |
| 2062 | for (i = 0; i < num; i++) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2063 | ret = snd_soc_dapm_add_route(dapm, route); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2064 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2065 | dev_err(dapm->dev, "Failed to add route %s->%s\n", |
| 2066 | route->source, route->sink); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2067 | return ret; |
| 2068 | } |
| 2069 | route++; |
| 2070 | } |
| 2071 | |
| 2072 | return 0; |
| 2073 | } |
| 2074 | EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes); |
| 2075 | |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2076 | static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm, |
| 2077 | const struct snd_soc_dapm_route *route) |
| 2078 | { |
| 2079 | struct snd_soc_dapm_widget *source = dapm_find_widget(dapm, |
| 2080 | route->source, |
| 2081 | true); |
| 2082 | struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm, |
| 2083 | route->sink, |
| 2084 | true); |
| 2085 | struct snd_soc_dapm_path *path; |
| 2086 | int count = 0; |
| 2087 | |
| 2088 | if (!source) { |
| 2089 | dev_err(dapm->dev, "Unable to find source %s for weak route\n", |
| 2090 | route->source); |
| 2091 | return -ENODEV; |
| 2092 | } |
| 2093 | |
| 2094 | if (!sink) { |
| 2095 | dev_err(dapm->dev, "Unable to find sink %s for weak route\n", |
| 2096 | route->sink); |
| 2097 | return -ENODEV; |
| 2098 | } |
| 2099 | |
| 2100 | if (route->control || route->connected) |
| 2101 | dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n", |
| 2102 | route->source, route->sink); |
| 2103 | |
| 2104 | list_for_each_entry(path, &source->sinks, list_source) { |
| 2105 | if (path->sink == sink) { |
| 2106 | path->weak = 1; |
| 2107 | count++; |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | if (count == 0) |
| 2112 | dev_err(dapm->dev, "No path found for weak route %s->%s\n", |
| 2113 | route->source, route->sink); |
| 2114 | if (count > 1) |
| 2115 | dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n", |
| 2116 | count, route->source, route->sink); |
| 2117 | |
| 2118 | return 0; |
| 2119 | } |
| 2120 | |
| 2121 | /** |
| 2122 | * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak |
| 2123 | * @dapm: DAPM context |
| 2124 | * @route: audio routes |
| 2125 | * @num: number of routes |
| 2126 | * |
| 2127 | * Mark existing routes matching those specified in the passed array |
| 2128 | * as being weak, meaning that they are ignored for the purpose of |
| 2129 | * power decisions. The main intended use case is for sidetone paths |
| 2130 | * which couple audio between other independent paths if they are both |
| 2131 | * active in order to make the combination work better at the user |
| 2132 | * level but which aren't intended to be "used". |
| 2133 | * |
| 2134 | * Note that CODEC drivers should not use this as sidetone type paths |
| 2135 | * can frequently also be used as bypass paths. |
| 2136 | */ |
| 2137 | int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm, |
| 2138 | const struct snd_soc_dapm_route *route, int num) |
| 2139 | { |
| 2140 | int i, err; |
| 2141 | int ret = 0; |
| 2142 | |
| 2143 | for (i = 0; i < num; i++) { |
| 2144 | err = snd_soc_dapm_weak_route(dapm, route); |
| 2145 | if (err) |
| 2146 | ret = err; |
| 2147 | route++; |
| 2148 | } |
| 2149 | |
| 2150 | return ret; |
| 2151 | } |
| 2152 | EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes); |
| 2153 | |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2154 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2155 | * snd_soc_dapm_new_widgets - add new dapm widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2156 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2157 | * |
| 2158 | * Checks the codec for any new dapm widgets and creates them if found. |
| 2159 | * |
| 2160 | * Returns 0 for success. |
| 2161 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2162 | int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2163 | { |
| 2164 | struct snd_soc_dapm_widget *w; |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2165 | unsigned int val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2166 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2167 | list_for_each_entry(w, &dapm->card->widgets, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2168 | { |
| 2169 | if (w->new) |
| 2170 | continue; |
| 2171 | |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 2172 | if (w->num_kcontrols) { |
| 2173 | w->kcontrols = kzalloc(w->num_kcontrols * |
| 2174 | sizeof(struct snd_kcontrol *), |
| 2175 | GFP_KERNEL); |
| 2176 | if (!w->kcontrols) |
| 2177 | return -ENOMEM; |
| 2178 | } |
| 2179 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2180 | switch(w->id) { |
| 2181 | case snd_soc_dapm_switch: |
| 2182 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 2183 | case snd_soc_dapm_mixer_named_ctl: |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2184 | dapm_new_mixer(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2185 | break; |
| 2186 | case snd_soc_dapm_mux: |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 2187 | case snd_soc_dapm_virt_mux: |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2188 | case snd_soc_dapm_value_mux: |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2189 | dapm_new_mux(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2190 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2191 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 2192 | case snd_soc_dapm_out_drv: |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2193 | dapm_new_pga(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2194 | break; |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 2195 | default: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2196 | break; |
| 2197 | } |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2198 | |
| 2199 | /* Read the initial power state from the device */ |
| 2200 | if (w->reg >= 0) { |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 2201 | val = soc_widget_read(w, w->reg); |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2202 | val &= 1 << w->shift; |
| 2203 | if (w->invert) |
| 2204 | val = !val; |
| 2205 | |
| 2206 | if (val) |
| 2207 | w->power = 1; |
| 2208 | } |
| 2209 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2210 | w->new = 1; |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 2211 | |
Mark Brown | 7508b12 | 2011-10-05 12:09:12 +0100 | [diff] [blame] | 2212 | dapm_mark_dirty(w, "new widget"); |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 2213 | dapm_debugfs_add_widget(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2214 | } |
| 2215 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2216 | dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2217 | return 0; |
| 2218 | } |
| 2219 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); |
| 2220 | |
| 2221 | /** |
| 2222 | * snd_soc_dapm_get_volsw - dapm mixer get callback |
| 2223 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2224 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2225 | * |
| 2226 | * Callback to get the value of a dapm mixer control. |
| 2227 | * |
| 2228 | * Returns 0 for success. |
| 2229 | */ |
| 2230 | int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, |
| 2231 | struct snd_ctl_elem_value *ucontrol) |
| 2232 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2233 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2234 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2235 | struct soc_mixer_control *mc = |
| 2236 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2237 | unsigned int reg = mc->reg; |
| 2238 | unsigned int shift = mc->shift; |
| 2239 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2240 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2241 | unsigned int invert = mc->invert; |
| 2242 | unsigned int mask = (1 << fls(max)) - 1; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2243 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2244 | ucontrol->value.integer.value[0] = |
| 2245 | (snd_soc_read(widget->codec, reg) >> shift) & mask; |
| 2246 | if (shift != rshift) |
| 2247 | ucontrol->value.integer.value[1] = |
| 2248 | (snd_soc_read(widget->codec, reg) >> rshift) & mask; |
| 2249 | if (invert) { |
| 2250 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2251 | max - ucontrol->value.integer.value[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2252 | if (shift != rshift) |
| 2253 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2254 | max - ucontrol->value.integer.value[1]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | return 0; |
| 2258 | } |
| 2259 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw); |
| 2260 | |
| 2261 | /** |
| 2262 | * snd_soc_dapm_put_volsw - dapm mixer set callback |
| 2263 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2264 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2265 | * |
| 2266 | * Callback to set the value of a dapm mixer control. |
| 2267 | * |
| 2268 | * Returns 0 for success. |
| 2269 | */ |
| 2270 | int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, |
| 2271 | struct snd_ctl_elem_value *ucontrol) |
| 2272 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2273 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2274 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2275 | struct snd_soc_codec *codec = widget->codec; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2276 | struct soc_mixer_control *mc = |
| 2277 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2278 | unsigned int reg = mc->reg; |
| 2279 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2280 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2281 | unsigned int mask = (1 << fls(max)) - 1; |
| 2282 | unsigned int invert = mc->invert; |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2283 | unsigned int val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2284 | int connect, change; |
| 2285 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2286 | int wi; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2287 | |
| 2288 | val = (ucontrol->value.integer.value[0] & mask); |
| 2289 | |
| 2290 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2291 | val = max - val; |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2292 | mask = mask << shift; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2293 | val = val << shift; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2294 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2295 | if (val) |
| 2296 | /* new connection */ |
| 2297 | connect = invert ? 0 : 1; |
| 2298 | else |
| 2299 | /* old connection must be powered down */ |
| 2300 | connect = invert ? 1 : 0; |
| 2301 | |
| 2302 | mutex_lock(&codec->mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2303 | |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2304 | change = snd_soc_test_bits(widget->codec, reg, mask, val); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2305 | if (change) { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2306 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2307 | widget = wlist->widgets[wi]; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 2308 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2309 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2310 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2311 | update.kcontrol = kcontrol; |
| 2312 | update.widget = widget; |
| 2313 | update.reg = reg; |
| 2314 | update.mask = mask; |
| 2315 | update.val = val; |
| 2316 | widget->dapm->update = &update; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2317 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2318 | dapm_mixer_update_power(widget, kcontrol, connect); |
| 2319 | |
| 2320 | widget->dapm->update = NULL; |
| 2321 | } |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 2322 | } |
| 2323 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2324 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2325 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2326 | } |
| 2327 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); |
| 2328 | |
| 2329 | /** |
| 2330 | * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback |
| 2331 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2332 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2333 | * |
| 2334 | * Callback to get the value of a dapm enumerated double mixer control. |
| 2335 | * |
| 2336 | * Returns 0 for success. |
| 2337 | */ |
| 2338 | int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, |
| 2339 | struct snd_ctl_elem_value *ucontrol) |
| 2340 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2341 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2342 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2343 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2344 | unsigned int val, bitmask; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2345 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2346 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2347 | ; |
| 2348 | val = snd_soc_read(widget->codec, e->reg); |
| 2349 | ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1); |
| 2350 | if (e->shift_l != e->shift_r) |
| 2351 | ucontrol->value.enumerated.item[1] = |
| 2352 | (val >> e->shift_r) & (bitmask - 1); |
| 2353 | |
| 2354 | return 0; |
| 2355 | } |
| 2356 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double); |
| 2357 | |
| 2358 | /** |
| 2359 | * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback |
| 2360 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2361 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2362 | * |
| 2363 | * Callback to set the value of a dapm enumerated double mixer control. |
| 2364 | * |
| 2365 | * Returns 0 for success. |
| 2366 | */ |
| 2367 | int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, |
| 2368 | struct snd_ctl_elem_value *ucontrol) |
| 2369 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2370 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2371 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2372 | struct snd_soc_codec *codec = widget->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2373 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2374 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2375 | unsigned int mask, bitmask; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2376 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2377 | int wi; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2378 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2379 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2380 | ; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2381 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2382 | return -EINVAL; |
| 2383 | mux = ucontrol->value.enumerated.item[0]; |
| 2384 | val = mux << e->shift_l; |
| 2385 | mask = (bitmask - 1) << e->shift_l; |
| 2386 | if (e->shift_l != e->shift_r) { |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2387 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2388 | return -EINVAL; |
| 2389 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; |
| 2390 | mask |= (bitmask - 1) << e->shift_r; |
| 2391 | } |
| 2392 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2393 | mutex_lock(&codec->mutex); |
| 2394 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2395 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2396 | if (change) { |
| 2397 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2398 | widget = wlist->widgets[wi]; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2399 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2400 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2401 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2402 | update.kcontrol = kcontrol; |
| 2403 | update.widget = widget; |
| 2404 | update.reg = e->reg; |
| 2405 | update.mask = mask; |
| 2406 | update.val = val; |
| 2407 | widget->dapm->update = &update; |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2408 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2409 | dapm_mux_update_power(widget, kcontrol, change, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2410 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2411 | widget->dapm->update = NULL; |
| 2412 | } |
| 2413 | } |
| 2414 | |
| 2415 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2416 | return change; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2417 | } |
| 2418 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); |
| 2419 | |
| 2420 | /** |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2421 | * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux |
| 2422 | * @kcontrol: mixer control |
| 2423 | * @ucontrol: control element information |
| 2424 | * |
| 2425 | * Returns 0 for success. |
| 2426 | */ |
| 2427 | int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol, |
| 2428 | struct snd_ctl_elem_value *ucontrol) |
| 2429 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2430 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2431 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2432 | |
| 2433 | ucontrol->value.enumerated.item[0] = widget->value; |
| 2434 | |
| 2435 | return 0; |
| 2436 | } |
| 2437 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt); |
| 2438 | |
| 2439 | /** |
| 2440 | * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux |
| 2441 | * @kcontrol: mixer control |
| 2442 | * @ucontrol: control element information |
| 2443 | * |
| 2444 | * Returns 0 for success. |
| 2445 | */ |
| 2446 | int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol, |
| 2447 | struct snd_ctl_elem_value *ucontrol) |
| 2448 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2449 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2450 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2451 | struct snd_soc_codec *codec = widget->codec; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2452 | struct soc_enum *e = |
| 2453 | (struct soc_enum *)kcontrol->private_value; |
| 2454 | int change; |
| 2455 | int ret = 0; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2456 | int wi; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2457 | |
| 2458 | if (ucontrol->value.enumerated.item[0] >= e->max) |
| 2459 | return -EINVAL; |
| 2460 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2461 | mutex_lock(&codec->mutex); |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2462 | |
| 2463 | change = widget->value != ucontrol->value.enumerated.item[0]; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2464 | if (change) { |
| 2465 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2466 | widget = wlist->widgets[wi]; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2467 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2468 | widget->value = ucontrol->value.enumerated.item[0]; |
| 2469 | |
| 2470 | dapm_mux_update_power(widget, kcontrol, change, |
| 2471 | widget->value, e); |
| 2472 | } |
| 2473 | } |
| 2474 | |
| 2475 | mutex_unlock(&codec->mutex); |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2476 | return ret; |
| 2477 | } |
| 2478 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt); |
| 2479 | |
| 2480 | /** |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2481 | * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get |
| 2482 | * callback |
| 2483 | * @kcontrol: mixer control |
| 2484 | * @ucontrol: control element information |
| 2485 | * |
| 2486 | * Callback to get the value of a dapm semi enumerated double mixer control. |
| 2487 | * |
| 2488 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2489 | * used for handling bitfield coded enumeration for example. |
| 2490 | * |
| 2491 | * Returns 0 for success. |
| 2492 | */ |
| 2493 | int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2494 | struct snd_ctl_elem_value *ucontrol) |
| 2495 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2496 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2497 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2498 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2499 | unsigned int reg_val, val, mux; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2500 | |
| 2501 | reg_val = snd_soc_read(widget->codec, e->reg); |
| 2502 | val = (reg_val >> e->shift_l) & e->mask; |
| 2503 | for (mux = 0; mux < e->max; mux++) { |
| 2504 | if (val == e->values[mux]) |
| 2505 | break; |
| 2506 | } |
| 2507 | ucontrol->value.enumerated.item[0] = mux; |
| 2508 | if (e->shift_l != e->shift_r) { |
| 2509 | val = (reg_val >> e->shift_r) & e->mask; |
| 2510 | for (mux = 0; mux < e->max; mux++) { |
| 2511 | if (val == e->values[mux]) |
| 2512 | break; |
| 2513 | } |
| 2514 | ucontrol->value.enumerated.item[1] = mux; |
| 2515 | } |
| 2516 | |
| 2517 | return 0; |
| 2518 | } |
| 2519 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double); |
| 2520 | |
| 2521 | /** |
| 2522 | * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set |
| 2523 | * callback |
| 2524 | * @kcontrol: mixer control |
| 2525 | * @ucontrol: control element information |
| 2526 | * |
| 2527 | * Callback to set the value of a dapm semi enumerated double mixer control. |
| 2528 | * |
| 2529 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2530 | * used for handling bitfield coded enumeration for example. |
| 2531 | * |
| 2532 | * Returns 0 for success. |
| 2533 | */ |
| 2534 | int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2535 | struct snd_ctl_elem_value *ucontrol) |
| 2536 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2537 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2538 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2539 | struct snd_soc_codec *codec = widget->codec; |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2540 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2541 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2542 | unsigned int mask; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2543 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2544 | int wi; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2545 | |
| 2546 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 2547 | return -EINVAL; |
| 2548 | mux = ucontrol->value.enumerated.item[0]; |
| 2549 | val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; |
| 2550 | mask = e->mask << e->shift_l; |
| 2551 | if (e->shift_l != e->shift_r) { |
| 2552 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
| 2553 | return -EINVAL; |
| 2554 | val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; |
| 2555 | mask |= e->mask << e->shift_r; |
| 2556 | } |
| 2557 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2558 | mutex_lock(&codec->mutex); |
| 2559 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2560 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2561 | if (change) { |
| 2562 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2563 | widget = wlist->widgets[wi]; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2564 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2565 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2566 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2567 | update.kcontrol = kcontrol; |
| 2568 | update.widget = widget; |
| 2569 | update.reg = e->reg; |
| 2570 | update.mask = mask; |
| 2571 | update.val = val; |
| 2572 | widget->dapm->update = &update; |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2573 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2574 | dapm_mux_update_power(widget, kcontrol, change, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2575 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2576 | widget->dapm->update = NULL; |
| 2577 | } |
| 2578 | } |
| 2579 | |
| 2580 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2581 | return change; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2582 | } |
| 2583 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); |
| 2584 | |
| 2585 | /** |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2586 | * snd_soc_dapm_info_pin_switch - Info for a pin switch |
| 2587 | * |
| 2588 | * @kcontrol: mixer control |
| 2589 | * @uinfo: control element information |
| 2590 | * |
| 2591 | * Callback to provide information about a pin switch control. |
| 2592 | */ |
| 2593 | int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol, |
| 2594 | struct snd_ctl_elem_info *uinfo) |
| 2595 | { |
| 2596 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2597 | uinfo->count = 1; |
| 2598 | uinfo->value.integer.min = 0; |
| 2599 | uinfo->value.integer.max = 1; |
| 2600 | |
| 2601 | return 0; |
| 2602 | } |
| 2603 | EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch); |
| 2604 | |
| 2605 | /** |
| 2606 | * snd_soc_dapm_get_pin_switch - Get information for a pin switch |
| 2607 | * |
| 2608 | * @kcontrol: mixer control |
| 2609 | * @ucontrol: Value |
| 2610 | */ |
| 2611 | int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol, |
| 2612 | struct snd_ctl_elem_value *ucontrol) |
| 2613 | { |
| 2614 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2615 | const char *pin = (const char *)kcontrol->private_value; |
| 2616 | |
| 2617 | mutex_lock(&codec->mutex); |
| 2618 | |
| 2619 | ucontrol->value.integer.value[0] = |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2620 | snd_soc_dapm_get_pin_status(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2621 | |
| 2622 | mutex_unlock(&codec->mutex); |
| 2623 | |
| 2624 | return 0; |
| 2625 | } |
| 2626 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch); |
| 2627 | |
| 2628 | /** |
| 2629 | * snd_soc_dapm_put_pin_switch - Set information for a pin switch |
| 2630 | * |
| 2631 | * @kcontrol: mixer control |
| 2632 | * @ucontrol: Value |
| 2633 | */ |
| 2634 | int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol, |
| 2635 | struct snd_ctl_elem_value *ucontrol) |
| 2636 | { |
| 2637 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2638 | const char *pin = (const char *)kcontrol->private_value; |
| 2639 | |
| 2640 | mutex_lock(&codec->mutex); |
| 2641 | |
| 2642 | if (ucontrol->value.integer.value[0]) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2643 | snd_soc_dapm_enable_pin(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2644 | else |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2645 | snd_soc_dapm_disable_pin(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2646 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2647 | snd_soc_dapm_sync(&codec->dapm); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2648 | |
| 2649 | mutex_unlock(&codec->mutex); |
| 2650 | |
| 2651 | return 0; |
| 2652 | } |
| 2653 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch); |
| 2654 | |
| 2655 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2656 | * snd_soc_dapm_new_control - create new dapm control |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2657 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2658 | * @widget: widget template |
| 2659 | * |
| 2660 | * Creates a new dapm control based upon the template. |
| 2661 | * |
| 2662 | * Returns 0 for success else error. |
| 2663 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2664 | int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2665 | const struct snd_soc_dapm_widget *widget) |
| 2666 | { |
| 2667 | struct snd_soc_dapm_widget *w; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2668 | size_t name_len; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2669 | |
| 2670 | if ((w = dapm_cnew_widget(widget)) == NULL) |
| 2671 | return -ENOMEM; |
| 2672 | |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2673 | name_len = strlen(widget->name) + 1; |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 2674 | if (dapm->codec && dapm->codec->name_prefix) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2675 | name_len += 1 + strlen(dapm->codec->name_prefix); |
| 2676 | w->name = kmalloc(name_len, GFP_KERNEL); |
| 2677 | if (w->name == NULL) { |
| 2678 | kfree(w); |
| 2679 | return -ENOMEM; |
| 2680 | } |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 2681 | if (dapm->codec && dapm->codec->name_prefix) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2682 | snprintf(w->name, name_len, "%s %s", |
| 2683 | dapm->codec->name_prefix, widget->name); |
| 2684 | else |
| 2685 | snprintf(w->name, name_len, "%s", widget->name); |
| 2686 | |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 2687 | switch (w->id) { |
| 2688 | case snd_soc_dapm_switch: |
| 2689 | case snd_soc_dapm_mixer: |
| 2690 | case snd_soc_dapm_mixer_named_ctl: |
| 2691 | w->power_check = dapm_generic_check_power; |
| 2692 | break; |
| 2693 | case snd_soc_dapm_mux: |
| 2694 | case snd_soc_dapm_virt_mux: |
| 2695 | case snd_soc_dapm_value_mux: |
| 2696 | w->power_check = dapm_generic_check_power; |
| 2697 | break; |
| 2698 | case snd_soc_dapm_adc: |
| 2699 | case snd_soc_dapm_aif_out: |
| 2700 | w->power_check = dapm_adc_check_power; |
| 2701 | break; |
| 2702 | case snd_soc_dapm_dac: |
| 2703 | case snd_soc_dapm_aif_in: |
| 2704 | w->power_check = dapm_dac_check_power; |
| 2705 | break; |
| 2706 | case snd_soc_dapm_pga: |
| 2707 | case snd_soc_dapm_out_drv: |
| 2708 | case snd_soc_dapm_input: |
| 2709 | case snd_soc_dapm_output: |
| 2710 | case snd_soc_dapm_micbias: |
| 2711 | case snd_soc_dapm_spk: |
| 2712 | case snd_soc_dapm_hp: |
| 2713 | case snd_soc_dapm_mic: |
| 2714 | case snd_soc_dapm_line: |
| 2715 | w->power_check = dapm_generic_check_power; |
| 2716 | break; |
| 2717 | case snd_soc_dapm_supply: |
| 2718 | w->power_check = dapm_supply_check_power; |
| 2719 | break; |
| 2720 | default: |
| 2721 | w->power_check = dapm_always_on_check_power; |
| 2722 | break; |
| 2723 | } |
| 2724 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2725 | dapm->n_widgets++; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2726 | w->dapm = dapm; |
| 2727 | w->codec = dapm->codec; |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 2728 | w->platform = dapm->platform; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2729 | INIT_LIST_HEAD(&w->sources); |
| 2730 | INIT_LIST_HEAD(&w->sinks); |
| 2731 | INIT_LIST_HEAD(&w->list); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 2732 | INIT_LIST_HEAD(&w->dirty); |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2733 | list_add(&w->list, &dapm->card->widgets); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2734 | |
| 2735 | /* machine layer set ups unconnected pins and insertions */ |
| 2736 | w->connected = 1; |
| 2737 | return 0; |
| 2738 | } |
| 2739 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control); |
| 2740 | |
| 2741 | /** |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2742 | * snd_soc_dapm_new_controls - create new dapm controls |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2743 | * @dapm: DAPM context |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2744 | * @widget: widget array |
| 2745 | * @num: number of widgets |
| 2746 | * |
| 2747 | * Creates new DAPM controls based upon the templates. |
| 2748 | * |
| 2749 | * Returns 0 for success else error. |
| 2750 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2751 | int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm, |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2752 | const struct snd_soc_dapm_widget *widget, |
| 2753 | int num) |
| 2754 | { |
| 2755 | int i, ret; |
| 2756 | |
| 2757 | for (i = 0; i < num; i++) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2758 | ret = snd_soc_dapm_new_control(dapm, widget); |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 2759 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2760 | dev_err(dapm->dev, |
| 2761 | "ASoC: Failed to create DAPM control %s: %d\n", |
| 2762 | widget->name, ret); |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2763 | return ret; |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 2764 | } |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2765 | widget++; |
| 2766 | } |
| 2767 | return 0; |
| 2768 | } |
| 2769 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); |
| 2770 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2771 | static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2772 | const char *stream, int event) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2773 | { |
| 2774 | struct snd_soc_dapm_widget *w; |
| 2775 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2776 | list_for_each_entry(w, &dapm->card->widgets, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2777 | { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2778 | if (!w->sname || w->dapm != dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2779 | continue; |
Liam Girdwood | ee47b36 | 2011-07-25 11:15:50 +0100 | [diff] [blame] | 2780 | dev_vdbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n", |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2781 | w->name, w->sname, stream, event); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2782 | if (strstr(w->sname, stream)) { |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 2783 | dapm_mark_dirty(w, "stream event"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2784 | switch(event) { |
| 2785 | case SND_SOC_DAPM_STREAM_START: |
| 2786 | w->active = 1; |
| 2787 | break; |
| 2788 | case SND_SOC_DAPM_STREAM_STOP: |
| 2789 | w->active = 0; |
| 2790 | break; |
| 2791 | case SND_SOC_DAPM_STREAM_SUSPEND: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2792 | case SND_SOC_DAPM_STREAM_RESUME: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2793 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2794 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: |
| 2795 | break; |
| 2796 | } |
| 2797 | } |
| 2798 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2799 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2800 | dapm_power_widgets(dapm, event); |
Liam Girdwood | 64a648c | 2011-07-25 11:15:15 +0100 | [diff] [blame] | 2801 | |
| 2802 | /* do we need to notify any clients that DAPM stream is complete */ |
| 2803 | if (dapm->stream_event) |
| 2804 | dapm->stream_event(dapm, event); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2805 | } |
| 2806 | |
| 2807 | /** |
| 2808 | * snd_soc_dapm_stream_event - send a stream event to the dapm core |
| 2809 | * @rtd: PCM runtime data |
| 2810 | * @stream: stream name |
| 2811 | * @event: stream event |
| 2812 | * |
| 2813 | * Sends a stream event to the dapm core. The core then makes any |
| 2814 | * necessary widget power changes. |
| 2815 | * |
| 2816 | * Returns 0 for success else error. |
| 2817 | */ |
| 2818 | int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, |
| 2819 | const char *stream, int event) |
| 2820 | { |
| 2821 | struct snd_soc_codec *codec = rtd->codec; |
| 2822 | |
| 2823 | if (stream == NULL) |
| 2824 | return 0; |
| 2825 | |
| 2826 | mutex_lock(&codec->mutex); |
| 2827 | soc_dapm_stream_event(&codec->dapm, stream, event); |
Eero Nurkkala | 8e8b2d6 | 2009-10-12 08:41:59 +0300 | [diff] [blame] | 2828 | mutex_unlock(&codec->mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2829 | return 0; |
| 2830 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2831 | |
| 2832 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2833 | * snd_soc_dapm_enable_pin - enable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2834 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2835 | * @pin: pin name |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2836 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 2837 | * 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] | 2838 | * a valid audio route and active audio stream. |
| 2839 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2840 | * do any widget power switching. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2841 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2842 | 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] | 2843 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2844 | return snd_soc_dapm_set_pin(dapm, pin, 1); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2845 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2846 | EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2847 | |
| 2848 | /** |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2849 | * snd_soc_dapm_force_enable_pin - force a pin to be enabled |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2850 | * @dapm: DAPM context |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2851 | * @pin: pin name |
| 2852 | * |
| 2853 | * Enables input/output pin regardless of any other state. This is |
| 2854 | * intended for use with microphone bias supplies used in microphone |
| 2855 | * jack detection. |
| 2856 | * |
| 2857 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2858 | * do any widget power switching. |
| 2859 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2860 | int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm, |
| 2861 | const char *pin) |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2862 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2863 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2864 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2865 | if (!w) { |
| 2866 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 2867 | return -EINVAL; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2868 | } |
| 2869 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2870 | dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin); |
| 2871 | w->connected = 1; |
| 2872 | w->force = 1; |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 2873 | dapm_mark_dirty(w, "force enable"); |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 2874 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2875 | return 0; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2876 | } |
| 2877 | EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin); |
| 2878 | |
| 2879 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2880 | * snd_soc_dapm_disable_pin - disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2881 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2882 | * @pin: pin name |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2883 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 2884 | * Disables input/output pin and its parents or children widgets. |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2885 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2886 | * do any widget power switching. |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2887 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2888 | int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm, |
| 2889 | const char *pin) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2890 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2891 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2892 | } |
| 2893 | EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin); |
| 2894 | |
| 2895 | /** |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2896 | * snd_soc_dapm_nc_pin - permanently disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2897 | * @dapm: DAPM context |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2898 | * @pin: pin name |
| 2899 | * |
| 2900 | * Marks the specified pin as being not connected, disabling it along |
| 2901 | * any parent or child widgets. At present this is identical to |
| 2902 | * snd_soc_dapm_disable_pin() but in future it will be extended to do |
| 2903 | * additional things such as disabling controls which only affect |
| 2904 | * paths through the pin. |
| 2905 | * |
| 2906 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2907 | * do any widget power switching. |
| 2908 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2909 | 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] | 2910 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2911 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2912 | } |
| 2913 | EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin); |
| 2914 | |
| 2915 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2916 | * snd_soc_dapm_get_pin_status - get audio pin status |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2917 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2918 | * @pin: audio signal pin endpoint (or start point) |
| 2919 | * |
| 2920 | * Get audio pin status - connected or disconnected. |
| 2921 | * |
| 2922 | * Returns 1 for connected otherwise 0. |
| 2923 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2924 | int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm, |
| 2925 | const char *pin) |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2926 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2927 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2928 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2929 | if (w) |
| 2930 | return w->connected; |
Stephen Warren | a68b38a | 2011-04-19 15:25:11 -0600 | [diff] [blame] | 2931 | |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2932 | return 0; |
| 2933 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2934 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2935 | |
| 2936 | /** |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2937 | * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2938 | * @dapm: DAPM context |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2939 | * @pin: audio signal pin endpoint (or start point) |
| 2940 | * |
| 2941 | * Mark the given endpoint or pin as ignoring suspend. When the |
| 2942 | * system is disabled a path between two endpoints flagged as ignoring |
| 2943 | * suspend will not be disabled. The path must already be enabled via |
| 2944 | * normal means at suspend time, it will not be turned on if it was not |
| 2945 | * already enabled. |
| 2946 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2947 | int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm, |
| 2948 | const char *pin) |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2949 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2950 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2951 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2952 | if (!w) { |
| 2953 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 2954 | return -EINVAL; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2955 | } |
| 2956 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2957 | w->ignore_suspend = 1; |
| 2958 | |
| 2959 | return 0; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2960 | } |
| 2961 | EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend); |
| 2962 | |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 2963 | static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card, |
| 2964 | struct snd_soc_dapm_widget *w) |
| 2965 | { |
| 2966 | struct snd_soc_dapm_path *p; |
| 2967 | |
| 2968 | list_for_each_entry(p, &card->paths, list) { |
| 2969 | if ((p->source == w) || (p->sink == w)) { |
| 2970 | dev_dbg(card->dev, |
| 2971 | "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n", |
| 2972 | p->source->name, p->source->id, p->source->dapm, |
| 2973 | p->sink->name, p->sink->id, p->sink->dapm); |
| 2974 | |
| 2975 | /* Connected to something other than the codec */ |
| 2976 | if (p->source->dapm != p->sink->dapm) |
| 2977 | return true; |
| 2978 | /* |
| 2979 | * Loopback connection from codec external pin to |
| 2980 | * codec external pin |
| 2981 | */ |
| 2982 | if (p->sink->id == snd_soc_dapm_input) { |
| 2983 | switch (p->source->id) { |
| 2984 | case snd_soc_dapm_output: |
| 2985 | case snd_soc_dapm_micbias: |
| 2986 | return true; |
| 2987 | default: |
| 2988 | break; |
| 2989 | } |
| 2990 | } |
| 2991 | } |
| 2992 | } |
| 2993 | |
| 2994 | return false; |
| 2995 | } |
| 2996 | |
| 2997 | /** |
| 2998 | * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins |
| 2999 | * @codec: The codec whose pins should be processed |
| 3000 | * |
| 3001 | * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec |
| 3002 | * which are unused. Pins are used if they are connected externally to the |
| 3003 | * codec, whether that be to some other device, or a loop-back connection to |
| 3004 | * the codec itself. |
| 3005 | */ |
| 3006 | void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec) |
| 3007 | { |
| 3008 | struct snd_soc_card *card = codec->card; |
| 3009 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 3010 | struct snd_soc_dapm_widget *w; |
| 3011 | |
Mark Brown | a094b80 | 2011-11-27 19:42:20 +0000 | [diff] [blame] | 3012 | dev_dbg(codec->dev, "Auto NC: DAPMs: card:%p codec:%p\n", |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 3013 | &card->dapm, &codec->dapm); |
| 3014 | |
| 3015 | list_for_each_entry(w, &card->widgets, list) { |
| 3016 | if (w->dapm != dapm) |
| 3017 | continue; |
| 3018 | switch (w->id) { |
| 3019 | case snd_soc_dapm_input: |
| 3020 | case snd_soc_dapm_output: |
| 3021 | case snd_soc_dapm_micbias: |
Mark Brown | a094b80 | 2011-11-27 19:42:20 +0000 | [diff] [blame] | 3022 | dev_dbg(codec->dev, "Auto NC: Checking widget %s\n", |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 3023 | w->name); |
| 3024 | if (!snd_soc_dapm_widget_in_card_paths(card, w)) { |
Mark Brown | a094b80 | 2011-11-27 19:42:20 +0000 | [diff] [blame] | 3025 | dev_dbg(codec->dev, |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 3026 | "... Not in map; disabling\n"); |
| 3027 | snd_soc_dapm_nc_pin(dapm, w->name); |
| 3028 | } |
| 3029 | break; |
| 3030 | default: |
| 3031 | break; |
| 3032 | } |
| 3033 | } |
| 3034 | } |
| 3035 | |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3036 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3037 | * snd_soc_dapm_free - free dapm resources |
Peter Ujfalusi | 728a522 | 2011-08-26 16:33:52 +0300 | [diff] [blame] | 3038 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3039 | * |
| 3040 | * Free all dapm widgets and resources. |
| 3041 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3042 | void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3043 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3044 | snd_soc_dapm_sys_remove(dapm->dev); |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 3045 | dapm_debugfs_cleanup(dapm); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3046 | dapm_free_widgets(dapm); |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 3047 | list_del(&dapm->list); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3048 | } |
| 3049 | EXPORT_SYMBOL_GPL(snd_soc_dapm_free); |
| 3050 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3051 | static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3052 | { |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3053 | struct snd_soc_dapm_widget *w; |
| 3054 | LIST_HEAD(down_list); |
| 3055 | int powerdown = 0; |
| 3056 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 3057 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 3058 | if (w->dapm != dapm) |
| 3059 | continue; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3060 | if (w->power) { |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 3061 | dapm_seq_insert(w, &down_list, false); |
Mark Brown | c2caa4d | 2009-06-26 15:36:56 +0100 | [diff] [blame] | 3062 | w->power = 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3063 | powerdown = 1; |
| 3064 | } |
| 3065 | } |
| 3066 | |
| 3067 | /* If there were no widgets to power down we're already in |
| 3068 | * standby. |
| 3069 | */ |
| 3070 | if (powerdown) { |
Mark Brown | 7679e42 | 2012-02-22 15:52:56 +0000 | [diff] [blame^] | 3071 | if (dapm->bias_level == SND_SOC_BIAS_ON) |
| 3072 | snd_soc_dapm_set_bias_level(dapm, |
| 3073 | SND_SOC_BIAS_PREPARE); |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 3074 | dapm_seq_run(dapm, &down_list, 0, false); |
Mark Brown | 7679e42 | 2012-02-22 15:52:56 +0000 | [diff] [blame^] | 3075 | if (dapm->bias_level == SND_SOC_BIAS_PREPARE) |
| 3076 | snd_soc_dapm_set_bias_level(dapm, |
| 3077 | SND_SOC_BIAS_STANDBY); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3078 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3079 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3080 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3081 | /* |
| 3082 | * snd_soc_dapm_shutdown - callback for system shutdown |
| 3083 | */ |
| 3084 | void snd_soc_dapm_shutdown(struct snd_soc_card *card) |
| 3085 | { |
| 3086 | struct snd_soc_codec *codec; |
| 3087 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3088 | list_for_each_entry(codec, &card->codec_dev_list, list) { |
| 3089 | soc_dapm_shutdown_codec(&codec->dapm); |
Mark Brown | 7679e42 | 2012-02-22 15:52:56 +0000 | [diff] [blame^] | 3090 | if (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY) |
| 3091 | snd_soc_dapm_set_bias_level(&codec->dapm, |
| 3092 | SND_SOC_BIAS_OFF); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3093 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3094 | } |
| 3095 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3096 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 3097 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3098 | MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC"); |
| 3099 | MODULE_LICENSE("GPL"); |