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