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