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