Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1 | /* |
| 2 | * soc-dapm.c -- ALSA SoC Dynamic Audio Power Management |
| 3 | * |
| 4 | * Copyright 2005 Wolfson Microelectronics PLC. |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 5 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | * |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 12 | * Features: |
| 13 | * o Changes power status of internal codec blocks depending on the |
| 14 | * dynamic configuration of codec internal audio paths and active |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 15 | * DACs/ADCs. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 16 | * o Platform power domain - can support external components i.e. amps and |
| 17 | * mic/meadphone insertion events. |
| 18 | * o Automatic Mic Bias support |
| 19 | * o Jack insertion power event initiation - e.g. hp insertion will enable |
| 20 | * sinks, dacs, etc |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 21 | * o Delayed powerdown of audio susbsystem to reduce pops between a quick |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 22 | * device reopen. |
| 23 | * |
| 24 | * Todo: |
| 25 | * o DAPM power change sequencing - allow for configurable per |
| 26 | * codec sequences. |
| 27 | * o Support for analogue bias optimisation. |
| 28 | * o Support for reduced codec oversampling rates. |
| 29 | * o Support for reduced codec bias currents. |
| 30 | */ |
| 31 | |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/moduleparam.h> |
| 34 | #include <linux/init.h> |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 35 | #include <linux/async.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 36 | #include <linux/delay.h> |
| 37 | #include <linux/pm.h> |
| 38 | #include <linux/bitops.h> |
| 39 | #include <linux/platform_device.h> |
| 40 | #include <linux/jiffies.h> |
Takashi Iwai | 20496ff | 2009-08-24 09:40:34 +0200 | [diff] [blame] | 41 | #include <linux/debugfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 43 | #include <sound/core.h> |
| 44 | #include <sound/pcm.h> |
| 45 | #include <sound/pcm_params.h> |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 46 | #include <sound/soc.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 47 | #include <sound/initval.h> |
| 48 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 49 | #include <trace/events/asoc.h> |
| 50 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 51 | #define DAPM_UPDATE_STAT(widget, val) widget->dapm->card->dapm_stats.val++; |
| 52 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 53 | /* dapm power sequences - make this per codec in the future */ |
| 54 | static int dapm_up_seq[] = { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 55 | [snd_soc_dapm_pre] = 0, |
| 56 | [snd_soc_dapm_supply] = 1, |
| 57 | [snd_soc_dapm_micbias] = 2, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 58 | [snd_soc_dapm_aif_in] = 3, |
| 59 | [snd_soc_dapm_aif_out] = 3, |
| 60 | [snd_soc_dapm_mic] = 4, |
| 61 | [snd_soc_dapm_mux] = 5, |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 62 | [snd_soc_dapm_virt_mux] = 5, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 63 | [snd_soc_dapm_value_mux] = 5, |
| 64 | [snd_soc_dapm_dac] = 6, |
| 65 | [snd_soc_dapm_mixer] = 7, |
| 66 | [snd_soc_dapm_mixer_named_ctl] = 7, |
| 67 | [snd_soc_dapm_pga] = 8, |
| 68 | [snd_soc_dapm_adc] = 9, |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 69 | [snd_soc_dapm_out_drv] = 10, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 70 | [snd_soc_dapm_hp] = 10, |
| 71 | [snd_soc_dapm_spk] = 10, |
| 72 | [snd_soc_dapm_post] = 11, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 73 | }; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 74 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 75 | static int dapm_down_seq[] = { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 76 | [snd_soc_dapm_pre] = 0, |
| 77 | [snd_soc_dapm_adc] = 1, |
| 78 | [snd_soc_dapm_hp] = 2, |
Mark Brown | 1ca0406 | 2009-08-17 16:26:59 +0100 | [diff] [blame] | 79 | [snd_soc_dapm_spk] = 2, |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 80 | [snd_soc_dapm_out_drv] = 2, |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 81 | [snd_soc_dapm_pga] = 4, |
| 82 | [snd_soc_dapm_mixer_named_ctl] = 5, |
Mark Brown | e3d4dab | 2009-06-07 13:08:45 +0100 | [diff] [blame] | 83 | [snd_soc_dapm_mixer] = 5, |
| 84 | [snd_soc_dapm_dac] = 6, |
| 85 | [snd_soc_dapm_mic] = 7, |
| 86 | [snd_soc_dapm_micbias] = 8, |
| 87 | [snd_soc_dapm_mux] = 9, |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 88 | [snd_soc_dapm_virt_mux] = 9, |
Mark Brown | e3d4dab | 2009-06-07 13:08:45 +0100 | [diff] [blame] | 89 | [snd_soc_dapm_value_mux] = 9, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 90 | [snd_soc_dapm_aif_in] = 10, |
| 91 | [snd_soc_dapm_aif_out] = 10, |
| 92 | [snd_soc_dapm_supply] = 11, |
| 93 | [snd_soc_dapm_post] = 12, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 94 | }; |
| 95 | |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 96 | static void pop_wait(u32 pop_time) |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 97 | { |
| 98 | if (pop_time) |
| 99 | schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time)); |
| 100 | } |
| 101 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 102 | static void pop_dbg(struct device *dev, u32 pop_time, const char *fmt, ...) |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 103 | { |
| 104 | va_list args; |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 105 | char *buf; |
| 106 | |
| 107 | if (!pop_time) |
| 108 | return; |
| 109 | |
| 110 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 111 | if (buf == NULL) |
| 112 | return; |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 113 | |
| 114 | va_start(args, fmt); |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 115 | vsnprintf(buf, PAGE_SIZE, fmt, args); |
Takashi Iwai | 9d01df0 | 2010-12-22 14:08:40 +0100 | [diff] [blame] | 116 | dev_info(dev, "%s", buf); |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 117 | va_end(args); |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 118 | |
| 119 | kfree(buf); |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 120 | } |
| 121 | |
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 | 9949788 | 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 | 9949788 | 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 | 9949788 | 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 | 9949788 | 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 | 9949788 | 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 | 9949788 | 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 | 9949788 | 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 | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 680 | if (path->weak) |
| 681 | continue; |
| 682 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 683 | if (path->walked) |
| 684 | continue; |
| 685 | |
| 686 | if (path->sink && path->connect) { |
| 687 | path->walked = 1; |
| 688 | con += is_connected_output_ep(path->sink); |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | return con; |
| 693 | } |
| 694 | |
| 695 | /* |
| 696 | * Recursively check for a completed path to an active or physically connected |
| 697 | * input widget. Returns number of complete paths. |
| 698 | */ |
| 699 | static int is_connected_input_ep(struct snd_soc_dapm_widget *widget) |
| 700 | { |
| 701 | struct snd_soc_dapm_path *path; |
| 702 | int con = 0; |
| 703 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 704 | DAPM_UPDATE_STAT(widget, path_checks); |
| 705 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 706 | if (widget->id == snd_soc_dapm_supply) |
| 707 | return 0; |
| 708 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 709 | /* active stream ? */ |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 710 | switch (widget->id) { |
| 711 | case snd_soc_dapm_dac: |
| 712 | case snd_soc_dapm_aif_in: |
| 713 | if (widget->active) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 714 | return snd_soc_dapm_suspend_check(widget); |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 715 | default: |
| 716 | break; |
| 717 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 718 | |
| 719 | if (widget->connected) { |
| 720 | /* connected pin ? */ |
| 721 | if (widget->id == snd_soc_dapm_input && !widget->ext) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 722 | return snd_soc_dapm_suspend_check(widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 723 | |
| 724 | /* connected VMID/Bias for lower pops */ |
| 725 | if (widget->id == snd_soc_dapm_vmid) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 726 | return snd_soc_dapm_suspend_check(widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 727 | |
| 728 | /* connected jack ? */ |
Peter Ujfalusi | eaeae5d | 2009-09-30 09:27:24 +0300 | [diff] [blame] | 729 | if (widget->id == snd_soc_dapm_mic || |
| 730 | (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks))) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 731 | return snd_soc_dapm_suspend_check(widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | list_for_each_entry(path, &widget->sources, list_sink) { |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 735 | if (path->weak) |
| 736 | continue; |
| 737 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 738 | if (path->walked) |
| 739 | continue; |
| 740 | |
| 741 | if (path->source && path->connect) { |
| 742 | path->walked = 1; |
| 743 | con += is_connected_input_ep(path->source); |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | return con; |
| 748 | } |
| 749 | |
| 750 | /* |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 751 | * Handler for generic register modifier widget. |
| 752 | */ |
| 753 | int dapm_reg_event(struct snd_soc_dapm_widget *w, |
| 754 | struct snd_kcontrol *kcontrol, int event) |
| 755 | { |
| 756 | unsigned int val; |
| 757 | |
| 758 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 759 | val = w->on_val; |
| 760 | else |
| 761 | val = w->off_val; |
| 762 | |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 763 | soc_widget_update_bits(w, -(w->reg + 1), |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 764 | w->mask << w->shift, val << w->shift); |
| 765 | |
| 766 | return 0; |
| 767 | } |
Mark Brown | 1158941 | 2008-07-29 11:42:23 +0100 | [diff] [blame] | 768 | EXPORT_SYMBOL_GPL(dapm_reg_event); |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 769 | |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 770 | /* Generic check to see if a widget should be powered. |
| 771 | */ |
| 772 | static int dapm_generic_check_power(struct snd_soc_dapm_widget *w) |
| 773 | { |
| 774 | int in, out; |
| 775 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 776 | DAPM_UPDATE_STAT(w, power_checks); |
| 777 | |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 778 | in = is_connected_input_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 779 | dapm_clear_walk(w->dapm); |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 780 | out = is_connected_output_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 781 | dapm_clear_walk(w->dapm); |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 782 | return out != 0 && in != 0; |
| 783 | } |
| 784 | |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 785 | /* Check to see if an ADC has power */ |
| 786 | static int dapm_adc_check_power(struct snd_soc_dapm_widget *w) |
| 787 | { |
| 788 | int in; |
| 789 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 790 | DAPM_UPDATE_STAT(w, power_checks); |
| 791 | |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 792 | if (w->active) { |
| 793 | in = is_connected_input_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 794 | dapm_clear_walk(w->dapm); |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 795 | return in != 0; |
| 796 | } else { |
| 797 | return dapm_generic_check_power(w); |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | /* Check to see if a DAC has power */ |
| 802 | static int dapm_dac_check_power(struct snd_soc_dapm_widget *w) |
| 803 | { |
| 804 | int out; |
| 805 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 806 | DAPM_UPDATE_STAT(w, power_checks); |
| 807 | |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 808 | if (w->active) { |
| 809 | out = is_connected_output_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 810 | dapm_clear_walk(w->dapm); |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 811 | return out != 0; |
| 812 | } else { |
| 813 | return dapm_generic_check_power(w); |
| 814 | } |
| 815 | } |
| 816 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 817 | /* Check to see if a power supply is needed */ |
| 818 | static int dapm_supply_check_power(struct snd_soc_dapm_widget *w) |
| 819 | { |
| 820 | struct snd_soc_dapm_path *path; |
| 821 | int power = 0; |
| 822 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 823 | DAPM_UPDATE_STAT(w, power_checks); |
| 824 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 825 | /* Check if one of our outputs is connected */ |
| 826 | list_for_each_entry(path, &w->sinks, list_source) { |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 827 | if (path->weak) |
| 828 | continue; |
| 829 | |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 830 | if (path->connected && |
| 831 | !path->connected(path->source, path->sink)) |
| 832 | continue; |
| 833 | |
Mark Brown | 3017358 | 2011-02-11 11:42:19 +0000 | [diff] [blame] | 834 | if (!path->sink) |
| 835 | continue; |
| 836 | |
| 837 | if (path->sink->force) { |
| 838 | power = 1; |
| 839 | break; |
| 840 | } |
| 841 | |
| 842 | if (path->sink->power_check && |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 843 | path->sink->power_check(path->sink)) { |
| 844 | power = 1; |
| 845 | break; |
| 846 | } |
| 847 | } |
| 848 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 849 | dapm_clear_walk(w->dapm); |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 850 | |
| 851 | return power; |
| 852 | } |
| 853 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 854 | static int dapm_seq_compare(struct snd_soc_dapm_widget *a, |
| 855 | struct snd_soc_dapm_widget *b, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 856 | bool power_up) |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 857 | { |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 858 | int *sort; |
| 859 | |
| 860 | if (power_up) |
| 861 | sort = dapm_up_seq; |
| 862 | else |
| 863 | sort = dapm_down_seq; |
| 864 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 865 | if (sort[a->id] != sort[b->id]) |
| 866 | return sort[a->id] - sort[b->id]; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 867 | if (a->subseq != b->subseq) { |
| 868 | if (power_up) |
| 869 | return a->subseq - b->subseq; |
| 870 | else |
| 871 | return b->subseq - a->subseq; |
| 872 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 873 | if (a->reg != b->reg) |
| 874 | return a->reg - b->reg; |
Mark Brown | 84dab56 | 2010-11-12 15:28:42 +0000 | [diff] [blame] | 875 | if (a->dapm != b->dapm) |
| 876 | return (unsigned long)a->dapm - (unsigned long)b->dapm; |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 877 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 878 | return 0; |
| 879 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 880 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 881 | /* Insert a widget in order into a DAPM power sequence. */ |
| 882 | static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget, |
| 883 | struct list_head *list, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 884 | bool power_up) |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 885 | { |
| 886 | struct snd_soc_dapm_widget *w; |
| 887 | |
| 888 | list_for_each_entry(w, list, power_list) |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 889 | if (dapm_seq_compare(new_widget, w, power_up) < 0) { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 890 | list_add_tail(&new_widget->power_list, &w->power_list); |
| 891 | return; |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 892 | } |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 893 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 894 | list_add_tail(&new_widget->power_list, list); |
| 895 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 896 | |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 897 | static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm, |
| 898 | struct snd_soc_dapm_widget *w, int event) |
| 899 | { |
| 900 | struct snd_soc_card *card = dapm->card; |
| 901 | const char *ev_name; |
| 902 | int power, ret; |
| 903 | |
| 904 | switch (event) { |
| 905 | case SND_SOC_DAPM_PRE_PMU: |
| 906 | ev_name = "PRE_PMU"; |
| 907 | power = 1; |
| 908 | break; |
| 909 | case SND_SOC_DAPM_POST_PMU: |
| 910 | ev_name = "POST_PMU"; |
| 911 | power = 1; |
| 912 | break; |
| 913 | case SND_SOC_DAPM_PRE_PMD: |
| 914 | ev_name = "PRE_PMD"; |
| 915 | power = 0; |
| 916 | break; |
| 917 | case SND_SOC_DAPM_POST_PMD: |
| 918 | ev_name = "POST_PMD"; |
| 919 | power = 0; |
| 920 | break; |
| 921 | default: |
| 922 | BUG(); |
| 923 | return; |
| 924 | } |
| 925 | |
| 926 | if (w->power != power) |
| 927 | return; |
| 928 | |
| 929 | if (w->event && (w->event_flags & event)) { |
| 930 | pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n", |
| 931 | w->name, ev_name); |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 932 | trace_snd_soc_dapm_widget_event_start(w, event); |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 933 | ret = w->event(w, NULL, event); |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 934 | trace_snd_soc_dapm_widget_event_done(w, event); |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 935 | if (ret < 0) |
| 936 | pr_err("%s: %s event failed: %d\n", |
| 937 | ev_name, w->name, ret); |
| 938 | } |
| 939 | } |
| 940 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 941 | /* Apply the coalesced changes from a DAPM sequence */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 942 | static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm, |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 943 | struct list_head *pending) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 944 | { |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 945 | struct snd_soc_card *card = dapm->card; |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 946 | struct snd_soc_dapm_widget *w; |
| 947 | int reg, power; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 948 | unsigned int value = 0; |
| 949 | unsigned int mask = 0; |
| 950 | unsigned int cur_mask; |
| 951 | |
| 952 | reg = list_first_entry(pending, struct snd_soc_dapm_widget, |
| 953 | power_list)->reg; |
| 954 | |
| 955 | list_for_each_entry(w, pending, power_list) { |
| 956 | cur_mask = 1 << w->shift; |
| 957 | BUG_ON(reg != w->reg); |
| 958 | |
| 959 | if (w->invert) |
| 960 | power = !w->power; |
| 961 | else |
| 962 | power = w->power; |
| 963 | |
| 964 | mask |= cur_mask; |
| 965 | if (power) |
| 966 | value |= cur_mask; |
| 967 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 968 | pop_dbg(dapm->dev, card->pop_time, |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 969 | "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n", |
| 970 | w->name, reg, value, mask); |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 971 | |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 972 | /* Check for events */ |
| 973 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU); |
| 974 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 975 | } |
| 976 | |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 977 | if (reg >= 0) { |
Mark Brown | 29376bc | 2011-06-19 13:49:28 +0100 | [diff] [blame] | 978 | /* Any widget will do, they should all be updating the |
| 979 | * same register. |
| 980 | */ |
| 981 | w = list_first_entry(pending, struct snd_soc_dapm_widget, |
| 982 | power_list); |
| 983 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 984 | pop_dbg(dapm->dev, card->pop_time, |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 985 | "pop test : Applying 0x%x/0x%x to %x in %dms\n", |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 986 | value, mask, reg, card->pop_time); |
| 987 | pop_wait(card->pop_time); |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 988 | soc_widget_update_bits(w, reg, mask, value); |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | list_for_each_entry(w, pending, power_list) { |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 992 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU); |
| 993 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD); |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 994 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 995 | } |
| 996 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 997 | /* Apply a DAPM power sequence. |
| 998 | * |
| 999 | * We walk over a pre-sorted list of widgets to apply power to. In |
| 1000 | * order to minimise the number of writes to the device required |
| 1001 | * multiple widgets will be updated in a single write where possible. |
| 1002 | * Currently anything that requires more than a single write is not |
| 1003 | * handled. |
| 1004 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1005 | static void dapm_seq_run(struct snd_soc_dapm_context *dapm, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1006 | struct list_head *list, int event, bool power_up) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1007 | { |
| 1008 | struct snd_soc_dapm_widget *w, *n; |
| 1009 | LIST_HEAD(pending); |
| 1010 | int cur_sort = -1; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1011 | int cur_subseq = -1; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1012 | int cur_reg = SND_SOC_NOPM; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1013 | struct snd_soc_dapm_context *cur_dapm = NULL; |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1014 | int ret, i; |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1015 | int *sort; |
| 1016 | |
| 1017 | if (power_up) |
| 1018 | sort = dapm_up_seq; |
| 1019 | else |
| 1020 | sort = dapm_down_seq; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1021 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1022 | list_for_each_entry_safe(w, n, list, power_list) { |
| 1023 | ret = 0; |
| 1024 | |
| 1025 | /* Do we need to apply any queued changes? */ |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1026 | if (sort[w->id] != cur_sort || w->reg != cur_reg || |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1027 | w->dapm != cur_dapm || w->subseq != cur_subseq) { |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1028 | if (!list_empty(&pending)) |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1029 | dapm_seq_run_coalesced(cur_dapm, &pending); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1030 | |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1031 | if (cur_dapm && cur_dapm->seq_notifier) { |
| 1032 | for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) |
| 1033 | if (sort[i] == cur_sort) |
| 1034 | cur_dapm->seq_notifier(cur_dapm, |
Mark Brown | f85a9e0 | 2011-01-26 21:41:28 +0000 | [diff] [blame] | 1035 | i, |
| 1036 | cur_subseq); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1039 | INIT_LIST_HEAD(&pending); |
| 1040 | cur_sort = -1; |
Mark Brown | b0b3e6f | 2011-07-16 10:55:08 +0900 | [diff] [blame] | 1041 | cur_subseq = INT_MIN; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1042 | cur_reg = SND_SOC_NOPM; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1043 | cur_dapm = NULL; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1044 | } |
| 1045 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1046 | switch (w->id) { |
| 1047 | case snd_soc_dapm_pre: |
| 1048 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1049 | list_for_each_entry_safe_continue(w, n, list, |
| 1050 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1051 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1052 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1053 | ret = w->event(w, |
| 1054 | NULL, SND_SOC_DAPM_PRE_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1055 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1056 | ret = w->event(w, |
| 1057 | NULL, SND_SOC_DAPM_PRE_PMD); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1058 | break; |
| 1059 | |
| 1060 | case snd_soc_dapm_post: |
| 1061 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1062 | list_for_each_entry_safe_continue(w, n, list, |
| 1063 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1064 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1065 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1066 | ret = w->event(w, |
| 1067 | NULL, SND_SOC_DAPM_POST_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1068 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1069 | ret = w->event(w, |
| 1070 | NULL, SND_SOC_DAPM_POST_PMD); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1071 | break; |
| 1072 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1073 | default: |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1074 | /* Queue it up for application */ |
| 1075 | cur_sort = sort[w->id]; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1076 | cur_subseq = w->subseq; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1077 | cur_reg = w->reg; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1078 | cur_dapm = w->dapm; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1079 | list_move(&w->power_list, &pending); |
| 1080 | break; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1081 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1082 | |
| 1083 | if (ret < 0) |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 1084 | dev_err(w->dapm->dev, |
| 1085 | "Failed to apply widget power: %d\n", ret); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1086 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1087 | |
| 1088 | if (!list_empty(&pending)) |
Mark Brown | 28e8680 | 2011-03-08 19:29:53 +0000 | [diff] [blame] | 1089 | dapm_seq_run_coalesced(cur_dapm, &pending); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1090 | |
| 1091 | if (cur_dapm && cur_dapm->seq_notifier) { |
| 1092 | for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) |
| 1093 | if (sort[i] == cur_sort) |
| 1094 | cur_dapm->seq_notifier(cur_dapm, |
Mark Brown | f85a9e0 | 2011-01-26 21:41:28 +0000 | [diff] [blame] | 1095 | i, cur_subseq); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1096 | } |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1097 | } |
| 1098 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1099 | static void dapm_widget_update(struct snd_soc_dapm_context *dapm) |
| 1100 | { |
| 1101 | struct snd_soc_dapm_update *update = dapm->update; |
| 1102 | struct snd_soc_dapm_widget *w; |
| 1103 | int ret; |
| 1104 | |
| 1105 | if (!update) |
| 1106 | return; |
| 1107 | |
| 1108 | w = update->widget; |
| 1109 | |
| 1110 | if (w->event && |
| 1111 | (w->event_flags & SND_SOC_DAPM_PRE_REG)) { |
| 1112 | ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG); |
| 1113 | if (ret != 0) |
| 1114 | pr_err("%s DAPM pre-event failed: %d\n", |
| 1115 | w->name, ret); |
| 1116 | } |
| 1117 | |
| 1118 | ret = snd_soc_update_bits(w->codec, update->reg, update->mask, |
| 1119 | update->val); |
| 1120 | if (ret < 0) |
| 1121 | pr_err("%s DAPM update failed: %d\n", w->name, ret); |
| 1122 | |
| 1123 | if (w->event && |
| 1124 | (w->event_flags & SND_SOC_DAPM_POST_REG)) { |
| 1125 | ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG); |
| 1126 | if (ret != 0) |
| 1127 | pr_err("%s DAPM post-event failed: %d\n", |
| 1128 | w->name, ret); |
| 1129 | } |
| 1130 | } |
| 1131 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1132 | /* Async callback run prior to DAPM sequences - brings to _PREPARE if |
| 1133 | * they're changing state. |
| 1134 | */ |
| 1135 | static void dapm_pre_sequence_async(void *data, async_cookie_t cookie) |
| 1136 | { |
| 1137 | struct snd_soc_dapm_context *d = data; |
| 1138 | int ret; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1139 | |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1140 | /* If we're off and we're not supposed to be go into STANDBY */ |
| 1141 | if (d->bias_level == SND_SOC_BIAS_OFF && |
| 1142 | d->target_bias_level != SND_SOC_BIAS_OFF) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1143 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY); |
| 1144 | if (ret != 0) |
| 1145 | dev_err(d->dev, |
| 1146 | "Failed to turn on bias: %d\n", ret); |
| 1147 | } |
| 1148 | |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1149 | /* Prepare for a STADDBY->ON or ON->STANDBY transition */ |
| 1150 | if (d->bias_level != d->target_bias_level) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1151 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE); |
| 1152 | if (ret != 0) |
| 1153 | dev_err(d->dev, |
| 1154 | "Failed to prepare bias: %d\n", ret); |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | /* Async callback run prior to DAPM sequences - brings to their final |
| 1159 | * state. |
| 1160 | */ |
| 1161 | static void dapm_post_sequence_async(void *data, async_cookie_t cookie) |
| 1162 | { |
| 1163 | struct snd_soc_dapm_context *d = data; |
| 1164 | int ret; |
| 1165 | |
| 1166 | /* If we just powered the last thing off drop to standby bias */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1167 | if (d->bias_level == SND_SOC_BIAS_PREPARE && |
| 1168 | (d->target_bias_level == SND_SOC_BIAS_STANDBY || |
| 1169 | d->target_bias_level == SND_SOC_BIAS_OFF)) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1170 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY); |
| 1171 | if (ret != 0) |
| 1172 | dev_err(d->dev, "Failed to apply standby bias: %d\n", |
| 1173 | ret); |
| 1174 | } |
| 1175 | |
| 1176 | /* 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] | 1177 | if (d->bias_level == SND_SOC_BIAS_STANDBY && |
| 1178 | d->target_bias_level == SND_SOC_BIAS_OFF) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1179 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF); |
| 1180 | if (ret != 0) |
| 1181 | dev_err(d->dev, "Failed to turn off bias: %d\n", ret); |
| 1182 | } |
| 1183 | |
| 1184 | /* If we just powered up then move to active bias */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1185 | if (d->bias_level == SND_SOC_BIAS_PREPARE && |
| 1186 | d->target_bias_level == SND_SOC_BIAS_ON) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1187 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON); |
| 1188 | if (ret != 0) |
| 1189 | dev_err(d->dev, "Failed to apply active bias: %d\n", |
| 1190 | ret); |
| 1191 | } |
| 1192 | } |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1193 | |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1194 | static void dapm_power_one_widget(struct snd_soc_dapm_widget *w, |
| 1195 | struct list_head *up_list, |
| 1196 | struct list_head *down_list) |
| 1197 | { |
| 1198 | struct snd_soc_dapm_context *d; |
| 1199 | int power; |
| 1200 | |
| 1201 | switch (w->id) { |
| 1202 | case snd_soc_dapm_pre: |
| 1203 | dapm_seq_insert(w, down_list, false); |
| 1204 | break; |
| 1205 | case snd_soc_dapm_post: |
| 1206 | dapm_seq_insert(w, up_list, true); |
| 1207 | break; |
| 1208 | |
| 1209 | default: |
| 1210 | if (!w->power_check) |
| 1211 | break; |
| 1212 | |
| 1213 | if (!w->force) |
| 1214 | power = w->power_check(w); |
| 1215 | else |
| 1216 | power = 1; |
| 1217 | |
| 1218 | if (power) { |
| 1219 | d = w->dapm; |
| 1220 | |
| 1221 | /* Supplies and micbiases only bring the |
| 1222 | * context up to STANDBY as unless something |
| 1223 | * else is active and passing audio they |
| 1224 | * generally don't require full power. |
| 1225 | */ |
| 1226 | switch (w->id) { |
| 1227 | case snd_soc_dapm_supply: |
| 1228 | case snd_soc_dapm_micbias: |
| 1229 | if (d->target_bias_level < SND_SOC_BIAS_STANDBY) |
| 1230 | d->target_bias_level = SND_SOC_BIAS_STANDBY; |
| 1231 | break; |
| 1232 | default: |
| 1233 | d->target_bias_level = SND_SOC_BIAS_ON; |
| 1234 | break; |
| 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | if (w->power == power) |
| 1239 | break; |
| 1240 | |
| 1241 | trace_snd_soc_dapm_widget_power(w, power); |
| 1242 | |
| 1243 | if (power) |
| 1244 | dapm_seq_insert(w, up_list, true); |
| 1245 | else |
| 1246 | dapm_seq_insert(w, down_list, false); |
| 1247 | |
| 1248 | w->power = power; |
| 1249 | break; |
| 1250 | } |
| 1251 | } |
| 1252 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1253 | /* |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1254 | * Scan each dapm widget for complete audio path. |
| 1255 | * A complete path is a route that has valid endpoints i.e.:- |
| 1256 | * |
| 1257 | * o DAC to output pin. |
| 1258 | * o Input Pin to ADC. |
| 1259 | * o Input pin to Output pin (bypass, sidetone) |
| 1260 | * o DAC to ADC (loopback). |
| 1261 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1262 | 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] | 1263 | { |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 1264 | struct snd_soc_card *card = dapm->card; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1265 | struct snd_soc_dapm_widget *w; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1266 | struct snd_soc_dapm_context *d; |
Mark Brown | 291f3bb | 2009-06-07 13:57:17 +0100 | [diff] [blame] | 1267 | LIST_HEAD(up_list); |
| 1268 | LIST_HEAD(down_list); |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1269 | LIST_HEAD(async_domain); |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1270 | enum snd_soc_bias_level bias; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1271 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1272 | trace_snd_soc_dapm_start(card); |
| 1273 | |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1274 | list_for_each_entry(d, &card->dapm_list, list) { |
| 1275 | if (d->n_widgets || d->codec == NULL) { |
| 1276 | if (d->idle_bias_off) |
| 1277 | d->target_bias_level = SND_SOC_BIAS_OFF; |
| 1278 | else |
| 1279 | d->target_bias_level = SND_SOC_BIAS_STANDBY; |
| 1280 | } |
| 1281 | } |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1282 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 1283 | memset(&card->dapm_stats, 0, sizeof(card->dapm_stats)); |
| 1284 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1285 | /* Check which widgets we need to power and store them in |
| 1286 | * lists indicating if they should be powered up or down. |
| 1287 | */ |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1288 | list_for_each_entry(w, &card->widgets, list) { |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1289 | dapm_power_one_widget(w, &up_list, &down_list); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1290 | } |
| 1291 | |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1292 | /* If there are no DAPM widgets then try to figure out power from the |
| 1293 | * event type. |
| 1294 | */ |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1295 | if (!dapm->n_widgets) { |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1296 | switch (event) { |
| 1297 | case SND_SOC_DAPM_STREAM_START: |
| 1298 | case SND_SOC_DAPM_STREAM_RESUME: |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1299 | dapm->target_bias_level = SND_SOC_BIAS_ON; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1300 | break; |
Jarkko Nikula | 862af8a | 2010-12-10 20:53:55 +0200 | [diff] [blame] | 1301 | case SND_SOC_DAPM_STREAM_STOP: |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1302 | if (dapm->codec->active) |
| 1303 | dapm->target_bias_level = SND_SOC_BIAS_ON; |
| 1304 | else |
| 1305 | dapm->target_bias_level = SND_SOC_BIAS_STANDBY; |
Jarkko Nikula | 862af8a | 2010-12-10 20:53:55 +0200 | [diff] [blame] | 1306 | break; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1307 | case SND_SOC_DAPM_STREAM_SUSPEND: |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1308 | dapm->target_bias_level = SND_SOC_BIAS_STANDBY; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1309 | break; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1310 | case SND_SOC_DAPM_STREAM_NOP: |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1311 | dapm->target_bias_level = dapm->bias_level; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1312 | break; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1313 | default: |
| 1314 | break; |
| 1315 | } |
| 1316 | } |
| 1317 | |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1318 | /* Force all contexts in the card to the same bias state */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1319 | bias = SND_SOC_BIAS_OFF; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1320 | list_for_each_entry(d, &card->dapm_list, list) |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1321 | if (d->target_bias_level > bias) |
| 1322 | bias = d->target_bias_level; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1323 | list_for_each_entry(d, &card->dapm_list, list) |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1324 | d->target_bias_level = bias; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1325 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 1326 | trace_snd_soc_dapm_walk_done(card); |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1327 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1328 | /* Run all the bias changes in parallel */ |
| 1329 | list_for_each_entry(d, &dapm->card->dapm_list, list) |
| 1330 | async_schedule_domain(dapm_pre_sequence_async, d, |
| 1331 | &async_domain); |
| 1332 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1333 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1334 | /* Power down widgets first; try to avoid amplifying pops. */ |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1335 | dapm_seq_run(dapm, &down_list, event, false); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1336 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1337 | dapm_widget_update(dapm); |
| 1338 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1339 | /* Now power up. */ |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1340 | dapm_seq_run(dapm, &up_list, event, true); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1341 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1342 | /* Run all the bias changes in parallel */ |
| 1343 | list_for_each_entry(d, &dapm->card->dapm_list, list) |
| 1344 | async_schedule_domain(dapm_post_sequence_async, d, |
| 1345 | &async_domain); |
| 1346 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1347 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 1348 | pop_dbg(dapm->dev, card->pop_time, |
| 1349 | "DAPM sequencing finished, waiting %dms\n", card->pop_time); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1350 | pop_wait(card->pop_time); |
Mark Brown | cb507e7 | 2009-07-08 18:54:57 +0100 | [diff] [blame] | 1351 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1352 | trace_snd_soc_dapm_done(card); |
| 1353 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1354 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1355 | } |
| 1356 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1357 | #ifdef CONFIG_DEBUG_FS |
| 1358 | static int dapm_widget_power_open_file(struct inode *inode, struct file *file) |
| 1359 | { |
| 1360 | file->private_data = inode->i_private; |
| 1361 | return 0; |
| 1362 | } |
| 1363 | |
| 1364 | static ssize_t dapm_widget_power_read_file(struct file *file, |
| 1365 | char __user *user_buf, |
| 1366 | size_t count, loff_t *ppos) |
| 1367 | { |
| 1368 | struct snd_soc_dapm_widget *w = file->private_data; |
| 1369 | char *buf; |
| 1370 | int in, out; |
| 1371 | ssize_t ret; |
| 1372 | struct snd_soc_dapm_path *p = NULL; |
| 1373 | |
| 1374 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 1375 | if (!buf) |
| 1376 | return -ENOMEM; |
| 1377 | |
| 1378 | in = is_connected_input_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1379 | dapm_clear_walk(w->dapm); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1380 | out = is_connected_output_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1381 | dapm_clear_walk(w->dapm); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1382 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1383 | ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1384 | w->name, w->power ? "On" : "Off", in, out); |
| 1385 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1386 | if (w->reg >= 0) |
| 1387 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
| 1388 | " - R%d(0x%x) bit %d", |
| 1389 | w->reg, w->reg, w->shift); |
| 1390 | |
| 1391 | ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n"); |
| 1392 | |
Mark Brown | 3eef08b | 2009-09-14 16:49:00 +0100 | [diff] [blame] | 1393 | if (w->sname) |
| 1394 | ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n", |
| 1395 | w->sname, |
| 1396 | w->active ? "active" : "inactive"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1397 | |
| 1398 | list_for_each_entry(p, &w->sources, list_sink) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1399 | if (p->connected && !p->connected(w, p->sink)) |
| 1400 | continue; |
| 1401 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1402 | if (p->connect) |
| 1403 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Dimitris Papastamos | 67f5ed6 | 2011-02-24 17:09:32 +0000 | [diff] [blame] | 1404 | " in \"%s\" \"%s\"\n", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1405 | p->name ? p->name : "static", |
| 1406 | p->source->name); |
| 1407 | } |
| 1408 | list_for_each_entry(p, &w->sinks, list_source) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1409 | if (p->connected && !p->connected(w, p->sink)) |
| 1410 | continue; |
| 1411 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1412 | if (p->connect) |
| 1413 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Dimitris Papastamos | 67f5ed6 | 2011-02-24 17:09:32 +0000 | [diff] [blame] | 1414 | " out \"%s\" \"%s\"\n", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1415 | p->name ? p->name : "static", |
| 1416 | p->sink->name); |
| 1417 | } |
| 1418 | |
| 1419 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 1420 | |
| 1421 | kfree(buf); |
| 1422 | return ret; |
| 1423 | } |
| 1424 | |
| 1425 | static const struct file_operations dapm_widget_power_fops = { |
| 1426 | .open = dapm_widget_power_open_file, |
| 1427 | .read = dapm_widget_power_read_file, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1428 | .llseek = default_llseek, |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1429 | }; |
| 1430 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1431 | static int dapm_bias_open_file(struct inode *inode, struct file *file) |
| 1432 | { |
| 1433 | file->private_data = inode->i_private; |
| 1434 | return 0; |
| 1435 | } |
| 1436 | |
| 1437 | static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf, |
| 1438 | size_t count, loff_t *ppos) |
| 1439 | { |
| 1440 | struct snd_soc_dapm_context *dapm = file->private_data; |
| 1441 | char *level; |
| 1442 | |
| 1443 | switch (dapm->bias_level) { |
| 1444 | case SND_SOC_BIAS_ON: |
| 1445 | level = "On\n"; |
| 1446 | break; |
| 1447 | case SND_SOC_BIAS_PREPARE: |
| 1448 | level = "Prepare\n"; |
| 1449 | break; |
| 1450 | case SND_SOC_BIAS_STANDBY: |
| 1451 | level = "Standby\n"; |
| 1452 | break; |
| 1453 | case SND_SOC_BIAS_OFF: |
| 1454 | level = "Off\n"; |
| 1455 | break; |
| 1456 | default: |
| 1457 | BUG(); |
| 1458 | level = "Unknown\n"; |
| 1459 | break; |
| 1460 | } |
| 1461 | |
| 1462 | return simple_read_from_buffer(user_buf, count, ppos, level, |
| 1463 | strlen(level)); |
| 1464 | } |
| 1465 | |
| 1466 | static const struct file_operations dapm_bias_fops = { |
| 1467 | .open = dapm_bias_open_file, |
| 1468 | .read = dapm_bias_read_file, |
| 1469 | .llseek = default_llseek, |
| 1470 | }; |
| 1471 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1472 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 1473 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1474 | { |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1475 | struct dentry *d; |
| 1476 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1477 | dapm->debugfs_dapm = debugfs_create_dir("dapm", parent); |
| 1478 | |
| 1479 | if (!dapm->debugfs_dapm) { |
| 1480 | printk(KERN_WARNING |
| 1481 | "Failed to create DAPM debugfs directory\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1482 | return; |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1483 | } |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1484 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1485 | d = debugfs_create_file("bias_level", 0444, |
| 1486 | dapm->debugfs_dapm, dapm, |
| 1487 | &dapm_bias_fops); |
| 1488 | if (!d) |
| 1489 | dev_warn(dapm->dev, |
| 1490 | "ASoC: Failed to create bias level debugfs file\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1491 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1492 | |
| 1493 | static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 1494 | { |
| 1495 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 1496 | struct dentry *d; |
| 1497 | |
| 1498 | if (!dapm->debugfs_dapm || !w->name) |
| 1499 | return; |
| 1500 | |
| 1501 | d = debugfs_create_file(w->name, 0444, |
| 1502 | dapm->debugfs_dapm, w, |
| 1503 | &dapm_widget_power_fops); |
| 1504 | if (!d) |
| 1505 | dev_warn(w->dapm->dev, |
| 1506 | "ASoC: Failed to create %s debugfs file\n", |
| 1507 | w->name); |
| 1508 | } |
| 1509 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 1510 | static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 1511 | { |
| 1512 | debugfs_remove_recursive(dapm->debugfs_dapm); |
| 1513 | } |
| 1514 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1515 | #else |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1516 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 1517 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1518 | { |
| 1519 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1520 | |
| 1521 | static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 1522 | { |
| 1523 | } |
| 1524 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 1525 | static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 1526 | { |
| 1527 | } |
| 1528 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1529 | #endif |
| 1530 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1531 | /* test and update the power status of a mux widget */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 1532 | static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget, |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1533 | struct snd_kcontrol *kcontrol, int change, |
| 1534 | int mux, struct soc_enum *e) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1535 | { |
| 1536 | struct snd_soc_dapm_path *path; |
| 1537 | int found = 0; |
| 1538 | |
Peter Ujfalusi | eff317d | 2009-01-15 14:40:47 +0200 | [diff] [blame] | 1539 | if (widget->id != snd_soc_dapm_mux && |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 1540 | widget->id != snd_soc_dapm_virt_mux && |
Peter Ujfalusi | eff317d | 2009-01-15 14:40:47 +0200 | [diff] [blame] | 1541 | widget->id != snd_soc_dapm_value_mux) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1542 | return -ENODEV; |
| 1543 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1544 | if (!change) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1545 | return 0; |
| 1546 | |
| 1547 | /* find dapm widget path assoc with kcontrol */ |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1548 | list_for_each_entry(path, &widget->dapm->card->paths, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1549 | if (path->kcontrol != kcontrol) |
| 1550 | continue; |
| 1551 | |
Richard Zhao | cb01e2b | 2008-10-07 08:05:20 +0800 | [diff] [blame] | 1552 | if (!path->name || !e->texts[mux]) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1553 | continue; |
| 1554 | |
| 1555 | found = 1; |
| 1556 | /* 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] | 1557 | if (!(strcmp(path->name, e->texts[mux]))) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1558 | path->connect = 1; /* new connection */ |
| 1559 | else |
| 1560 | path->connect = 0; /* old connection must be powered down */ |
| 1561 | } |
| 1562 | |
Mark Brown | b91b8fa | 2010-01-20 18:18:35 +0000 | [diff] [blame] | 1563 | if (found) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1564 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1565 | |
| 1566 | return 0; |
| 1567 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1568 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1569 | /* test and update the power status of a mixer or switch widget */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 1570 | static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1571 | struct snd_kcontrol *kcontrol, int connect) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1572 | { |
| 1573 | struct snd_soc_dapm_path *path; |
| 1574 | int found = 0; |
| 1575 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1576 | if (widget->id != snd_soc_dapm_mixer && |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1577 | widget->id != snd_soc_dapm_mixer_named_ctl && |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1578 | widget->id != snd_soc_dapm_switch) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1579 | return -ENODEV; |
| 1580 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1581 | /* find dapm widget path assoc with kcontrol */ |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1582 | list_for_each_entry(path, &widget->dapm->card->paths, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1583 | if (path->kcontrol != kcontrol) |
| 1584 | continue; |
| 1585 | |
| 1586 | /* found, now check type */ |
| 1587 | found = 1; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1588 | path->connect = connect; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1589 | } |
| 1590 | |
Mark Brown | b91b8fa | 2010-01-20 18:18:35 +0000 | [diff] [blame] | 1591 | if (found) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1592 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1593 | |
| 1594 | return 0; |
| 1595 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1596 | |
| 1597 | /* show dapm widget status in sys fs */ |
| 1598 | static ssize_t dapm_widget_show(struct device *dev, |
| 1599 | struct device_attribute *attr, char *buf) |
| 1600 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1601 | struct snd_soc_pcm_runtime *rtd = |
| 1602 | container_of(dev, struct snd_soc_pcm_runtime, dev); |
| 1603 | struct snd_soc_codec *codec =rtd->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1604 | struct snd_soc_dapm_widget *w; |
| 1605 | int count = 0; |
| 1606 | char *state = "not set"; |
| 1607 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1608 | list_for_each_entry(w, &codec->card->widgets, list) { |
| 1609 | if (w->dapm != &codec->dapm) |
| 1610 | continue; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1611 | |
| 1612 | /* only display widgets that burnm power */ |
| 1613 | switch (w->id) { |
| 1614 | case snd_soc_dapm_hp: |
| 1615 | case snd_soc_dapm_mic: |
| 1616 | case snd_soc_dapm_spk: |
| 1617 | case snd_soc_dapm_line: |
| 1618 | case snd_soc_dapm_micbias: |
| 1619 | case snd_soc_dapm_dac: |
| 1620 | case snd_soc_dapm_adc: |
| 1621 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 1622 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1623 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1624 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1625 | case snd_soc_dapm_supply: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1626 | if (w->name) |
| 1627 | count += sprintf(buf + count, "%s: %s\n", |
| 1628 | w->name, w->power ? "On":"Off"); |
| 1629 | break; |
| 1630 | default: |
| 1631 | break; |
| 1632 | } |
| 1633 | } |
| 1634 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1635 | switch (codec->dapm.bias_level) { |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1636 | case SND_SOC_BIAS_ON: |
| 1637 | state = "On"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1638 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1639 | case SND_SOC_BIAS_PREPARE: |
| 1640 | state = "Prepare"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1641 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1642 | case SND_SOC_BIAS_STANDBY: |
| 1643 | state = "Standby"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1644 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1645 | case SND_SOC_BIAS_OFF: |
| 1646 | state = "Off"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1647 | break; |
| 1648 | } |
| 1649 | count += sprintf(buf + count, "PM State: %s\n", state); |
| 1650 | |
| 1651 | return count; |
| 1652 | } |
| 1653 | |
| 1654 | static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL); |
| 1655 | |
| 1656 | int snd_soc_dapm_sys_add(struct device *dev) |
| 1657 | { |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1658 | return device_create_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | static void snd_soc_dapm_sys_remove(struct device *dev) |
| 1662 | { |
Mark Brown | aef9084 | 2009-05-16 17:53:16 +0100 | [diff] [blame] | 1663 | device_remove_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | /* free all dapm widgets and resources */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1667 | static void dapm_free_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1668 | { |
| 1669 | struct snd_soc_dapm_widget *w, *next_w; |
| 1670 | struct snd_soc_dapm_path *p, *next_p; |
| 1671 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1672 | list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) { |
| 1673 | if (w->dapm != dapm) |
| 1674 | continue; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1675 | list_del(&w->list); |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1676 | /* |
| 1677 | * remove source and sink paths associated to this widget. |
| 1678 | * While removing the path, remove reference to it from both |
| 1679 | * source and sink widgets so that path is removed only once. |
| 1680 | */ |
| 1681 | list_for_each_entry_safe(p, next_p, &w->sources, list_sink) { |
| 1682 | list_del(&p->list_sink); |
| 1683 | list_del(&p->list_source); |
| 1684 | list_del(&p->list); |
| 1685 | kfree(p->long_name); |
| 1686 | kfree(p); |
| 1687 | } |
| 1688 | list_for_each_entry_safe(p, next_p, &w->sinks, list_source) { |
| 1689 | list_del(&p->list_sink); |
| 1690 | list_del(&p->list_source); |
| 1691 | list_del(&p->list); |
| 1692 | kfree(p->long_name); |
| 1693 | kfree(p); |
| 1694 | } |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 1695 | kfree(w->kcontrols); |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1696 | kfree(w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1697 | kfree(w); |
| 1698 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1699 | } |
| 1700 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1701 | static struct snd_soc_dapm_widget *dapm_find_widget( |
| 1702 | struct snd_soc_dapm_context *dapm, const char *pin, |
| 1703 | bool search_other_contexts) |
| 1704 | { |
| 1705 | struct snd_soc_dapm_widget *w; |
| 1706 | struct snd_soc_dapm_widget *fallback = NULL; |
| 1707 | |
| 1708 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 1709 | if (!strcmp(w->name, pin)) { |
| 1710 | if (w->dapm == dapm) |
| 1711 | return w; |
| 1712 | else |
| 1713 | fallback = w; |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | if (search_other_contexts) |
| 1718 | return fallback; |
| 1719 | |
| 1720 | return NULL; |
| 1721 | } |
| 1722 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1723 | 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] | 1724 | const char *pin, int status) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1725 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1726 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1727 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1728 | if (!w) { |
| 1729 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 1730 | return -EINVAL; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1731 | } |
| 1732 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1733 | w->connected = status; |
| 1734 | if (status == 0) |
| 1735 | w->force = 0; |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 1736 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1737 | return 0; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1738 | } |
| 1739 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1740 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1741 | * snd_soc_dapm_sync - scan and power dapm paths |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1742 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1743 | * |
| 1744 | * Walks all dapm audio paths and powers widgets according to their |
| 1745 | * stream or path usage. |
| 1746 | * |
| 1747 | * Returns 0 for success. |
| 1748 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1749 | int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1750 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1751 | return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1752 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1753 | EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1754 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1755 | 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] | 1756 | const struct snd_soc_dapm_route *route) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1757 | { |
| 1758 | struct snd_soc_dapm_path *path; |
| 1759 | struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w; |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1760 | struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1761 | const char *sink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1762 | const char *control = route->control; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1763 | const char *source; |
| 1764 | char prefixed_sink[80]; |
| 1765 | char prefixed_source[80]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1766 | int ret = 0; |
| 1767 | |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 1768 | if (dapm->codec && dapm->codec->name_prefix) { |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1769 | snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s", |
| 1770 | dapm->codec->name_prefix, route->sink); |
| 1771 | sink = prefixed_sink; |
| 1772 | snprintf(prefixed_source, sizeof(prefixed_source), "%s %s", |
| 1773 | dapm->codec->name_prefix, route->source); |
| 1774 | source = prefixed_source; |
| 1775 | } else { |
| 1776 | sink = route->sink; |
| 1777 | source = route->source; |
| 1778 | } |
| 1779 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1780 | /* |
| 1781 | * find src and dest widgets over all widgets but favor a widget from |
| 1782 | * current DAPM context |
| 1783 | */ |
| 1784 | list_for_each_entry(w, &dapm->card->widgets, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1785 | if (!wsink && !(strcmp(w->name, sink))) { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1786 | wtsink = w; |
| 1787 | if (w->dapm == dapm) |
| 1788 | wsink = w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1789 | continue; |
| 1790 | } |
| 1791 | if (!wsource && !(strcmp(w->name, source))) { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1792 | wtsource = w; |
| 1793 | if (w->dapm == dapm) |
| 1794 | wsource = w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1795 | } |
| 1796 | } |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1797 | /* use widget from another DAPM context if not found from this */ |
| 1798 | if (!wsink) |
| 1799 | wsink = wtsink; |
| 1800 | if (!wsource) |
| 1801 | wsource = wtsource; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1802 | |
| 1803 | if (wsource == NULL || wsink == NULL) |
| 1804 | return -ENODEV; |
| 1805 | |
| 1806 | path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL); |
| 1807 | if (!path) |
| 1808 | return -ENOMEM; |
| 1809 | |
| 1810 | path->source = wsource; |
| 1811 | path->sink = wsink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1812 | path->connected = route->connected; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1813 | INIT_LIST_HEAD(&path->list); |
| 1814 | INIT_LIST_HEAD(&path->list_source); |
| 1815 | INIT_LIST_HEAD(&path->list_sink); |
| 1816 | |
| 1817 | /* check for external widgets */ |
| 1818 | if (wsink->id == snd_soc_dapm_input) { |
| 1819 | if (wsource->id == snd_soc_dapm_micbias || |
| 1820 | wsource->id == snd_soc_dapm_mic || |
Rongrong Cao | 087d53a | 2009-07-10 20:13:30 +0100 | [diff] [blame] | 1821 | wsource->id == snd_soc_dapm_line || |
| 1822 | wsource->id == snd_soc_dapm_output) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1823 | wsink->ext = 1; |
| 1824 | } |
| 1825 | if (wsource->id == snd_soc_dapm_output) { |
| 1826 | if (wsink->id == snd_soc_dapm_spk || |
| 1827 | wsink->id == snd_soc_dapm_hp || |
Seth Forshee | 1e39221 | 2007-04-16 15:36:42 +0200 | [diff] [blame] | 1828 | wsink->id == snd_soc_dapm_line || |
| 1829 | wsink->id == snd_soc_dapm_input) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1830 | wsource->ext = 1; |
| 1831 | } |
| 1832 | |
| 1833 | /* connect static paths */ |
| 1834 | if (control == NULL) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1835 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1836 | list_add(&path->list_sink, &wsink->sources); |
| 1837 | list_add(&path->list_source, &wsource->sinks); |
| 1838 | path->connect = 1; |
| 1839 | return 0; |
| 1840 | } |
| 1841 | |
| 1842 | /* connect dynamic paths */ |
Lu Guanqun | dc2bea6 | 2011-04-20 16:00:36 +0800 | [diff] [blame] | 1843 | switch (wsink->id) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1844 | case snd_soc_dapm_adc: |
| 1845 | case snd_soc_dapm_dac: |
| 1846 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 1847 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1848 | case snd_soc_dapm_input: |
| 1849 | case snd_soc_dapm_output: |
| 1850 | case snd_soc_dapm_micbias: |
| 1851 | case snd_soc_dapm_vmid: |
| 1852 | case snd_soc_dapm_pre: |
| 1853 | case snd_soc_dapm_post: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1854 | case snd_soc_dapm_supply: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 1855 | case snd_soc_dapm_aif_in: |
| 1856 | case snd_soc_dapm_aif_out: |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1857 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1858 | list_add(&path->list_sink, &wsink->sources); |
| 1859 | list_add(&path->list_source, &wsource->sinks); |
| 1860 | path->connect = 1; |
| 1861 | return 0; |
| 1862 | case snd_soc_dapm_mux: |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 1863 | case snd_soc_dapm_virt_mux: |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 1864 | case snd_soc_dapm_value_mux: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1865 | ret = dapm_connect_mux(dapm, wsource, wsink, path, control, |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 1866 | &wsink->kcontrol_news[0]); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1867 | if (ret != 0) |
| 1868 | goto err; |
| 1869 | break; |
| 1870 | case snd_soc_dapm_switch: |
| 1871 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1872 | case snd_soc_dapm_mixer_named_ctl: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1873 | ret = dapm_connect_mixer(dapm, wsource, wsink, path, control); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1874 | if (ret != 0) |
| 1875 | goto err; |
| 1876 | break; |
| 1877 | case snd_soc_dapm_hp: |
| 1878 | case snd_soc_dapm_mic: |
| 1879 | case snd_soc_dapm_line: |
| 1880 | case snd_soc_dapm_spk: |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1881 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1882 | list_add(&path->list_sink, &wsink->sources); |
| 1883 | list_add(&path->list_source, &wsource->sinks); |
| 1884 | path->connect = 0; |
| 1885 | return 0; |
| 1886 | } |
| 1887 | return 0; |
| 1888 | |
| 1889 | err: |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 1890 | dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n", |
| 1891 | source, control, sink); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1892 | kfree(path); |
| 1893 | return ret; |
| 1894 | } |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1895 | |
| 1896 | /** |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1897 | * snd_soc_dapm_add_routes - Add routes between DAPM widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1898 | * @dapm: DAPM context |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1899 | * @route: audio routes |
| 1900 | * @num: number of routes |
| 1901 | * |
| 1902 | * Connects 2 dapm widgets together via a named audio path. The sink is |
| 1903 | * the widget receiving the audio signal, whilst the source is the sender |
| 1904 | * of the audio signal. |
| 1905 | * |
| 1906 | * Returns 0 for success else error. On error all resources can be freed |
| 1907 | * with a call to snd_soc_card_free(). |
| 1908 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1909 | int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm, |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1910 | const struct snd_soc_dapm_route *route, int num) |
| 1911 | { |
| 1912 | int i, ret; |
| 1913 | |
| 1914 | for (i = 0; i < num; i++) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1915 | ret = snd_soc_dapm_add_route(dapm, route); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1916 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 1917 | dev_err(dapm->dev, "Failed to add route %s->%s\n", |
| 1918 | route->source, route->sink); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1919 | return ret; |
| 1920 | } |
| 1921 | route++; |
| 1922 | } |
| 1923 | |
| 1924 | return 0; |
| 1925 | } |
| 1926 | EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes); |
| 1927 | |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 1928 | static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm, |
| 1929 | const struct snd_soc_dapm_route *route) |
| 1930 | { |
| 1931 | struct snd_soc_dapm_widget *source = dapm_find_widget(dapm, |
| 1932 | route->source, |
| 1933 | true); |
| 1934 | struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm, |
| 1935 | route->sink, |
| 1936 | true); |
| 1937 | struct snd_soc_dapm_path *path; |
| 1938 | int count = 0; |
| 1939 | |
| 1940 | if (!source) { |
| 1941 | dev_err(dapm->dev, "Unable to find source %s for weak route\n", |
| 1942 | route->source); |
| 1943 | return -ENODEV; |
| 1944 | } |
| 1945 | |
| 1946 | if (!sink) { |
| 1947 | dev_err(dapm->dev, "Unable to find sink %s for weak route\n", |
| 1948 | route->sink); |
| 1949 | return -ENODEV; |
| 1950 | } |
| 1951 | |
| 1952 | if (route->control || route->connected) |
| 1953 | dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n", |
| 1954 | route->source, route->sink); |
| 1955 | |
| 1956 | list_for_each_entry(path, &source->sinks, list_source) { |
| 1957 | if (path->sink == sink) { |
| 1958 | path->weak = 1; |
| 1959 | count++; |
| 1960 | } |
| 1961 | } |
| 1962 | |
| 1963 | if (count == 0) |
| 1964 | dev_err(dapm->dev, "No path found for weak route %s->%s\n", |
| 1965 | route->source, route->sink); |
| 1966 | if (count > 1) |
| 1967 | dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n", |
| 1968 | count, route->source, route->sink); |
| 1969 | |
| 1970 | return 0; |
| 1971 | } |
| 1972 | |
| 1973 | /** |
| 1974 | * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak |
| 1975 | * @dapm: DAPM context |
| 1976 | * @route: audio routes |
| 1977 | * @num: number of routes |
| 1978 | * |
| 1979 | * Mark existing routes matching those specified in the passed array |
| 1980 | * as being weak, meaning that they are ignored for the purpose of |
| 1981 | * power decisions. The main intended use case is for sidetone paths |
| 1982 | * which couple audio between other independent paths if they are both |
| 1983 | * active in order to make the combination work better at the user |
| 1984 | * level but which aren't intended to be "used". |
| 1985 | * |
| 1986 | * Note that CODEC drivers should not use this as sidetone type paths |
| 1987 | * can frequently also be used as bypass paths. |
| 1988 | */ |
| 1989 | int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm, |
| 1990 | const struct snd_soc_dapm_route *route, int num) |
| 1991 | { |
| 1992 | int i, err; |
| 1993 | int ret = 0; |
| 1994 | |
| 1995 | for (i = 0; i < num; i++) { |
| 1996 | err = snd_soc_dapm_weak_route(dapm, route); |
| 1997 | if (err) |
| 1998 | ret = err; |
| 1999 | route++; |
| 2000 | } |
| 2001 | |
| 2002 | return ret; |
| 2003 | } |
| 2004 | EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes); |
| 2005 | |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2006 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2007 | * snd_soc_dapm_new_widgets - add new dapm widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2008 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2009 | * |
| 2010 | * Checks the codec for any new dapm widgets and creates them if found. |
| 2011 | * |
| 2012 | * Returns 0 for success. |
| 2013 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2014 | int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2015 | { |
| 2016 | struct snd_soc_dapm_widget *w; |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2017 | unsigned int val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2018 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2019 | list_for_each_entry(w, &dapm->card->widgets, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2020 | { |
| 2021 | if (w->new) |
| 2022 | continue; |
| 2023 | |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 2024 | if (w->num_kcontrols) { |
| 2025 | w->kcontrols = kzalloc(w->num_kcontrols * |
| 2026 | sizeof(struct snd_kcontrol *), |
| 2027 | GFP_KERNEL); |
| 2028 | if (!w->kcontrols) |
| 2029 | return -ENOMEM; |
| 2030 | } |
| 2031 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2032 | switch(w->id) { |
| 2033 | case snd_soc_dapm_switch: |
| 2034 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 2035 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 2036 | w->power_check = dapm_generic_check_power; |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2037 | dapm_new_mixer(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2038 | break; |
| 2039 | case snd_soc_dapm_mux: |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 2040 | case snd_soc_dapm_virt_mux: |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2041 | case snd_soc_dapm_value_mux: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 2042 | w->power_check = dapm_generic_check_power; |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2043 | dapm_new_mux(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2044 | break; |
| 2045 | case snd_soc_dapm_adc: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 2046 | case snd_soc_dapm_aif_out: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 2047 | w->power_check = dapm_adc_check_power; |
| 2048 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2049 | case snd_soc_dapm_dac: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 2050 | case snd_soc_dapm_aif_in: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 2051 | w->power_check = dapm_dac_check_power; |
| 2052 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2053 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 2054 | case snd_soc_dapm_out_drv: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 2055 | w->power_check = dapm_generic_check_power; |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2056 | dapm_new_pga(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2057 | break; |
| 2058 | case snd_soc_dapm_input: |
| 2059 | case snd_soc_dapm_output: |
| 2060 | case snd_soc_dapm_micbias: |
| 2061 | case snd_soc_dapm_spk: |
| 2062 | case snd_soc_dapm_hp: |
| 2063 | case snd_soc_dapm_mic: |
| 2064 | case snd_soc_dapm_line: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 2065 | w->power_check = dapm_generic_check_power; |
| 2066 | break; |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 2067 | case snd_soc_dapm_supply: |
| 2068 | w->power_check = dapm_supply_check_power; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2069 | case snd_soc_dapm_vmid: |
| 2070 | case snd_soc_dapm_pre: |
| 2071 | case snd_soc_dapm_post: |
| 2072 | break; |
| 2073 | } |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2074 | |
| 2075 | /* Read the initial power state from the device */ |
| 2076 | if (w->reg >= 0) { |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 2077 | val = soc_widget_read(w, w->reg); |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2078 | val &= 1 << w->shift; |
| 2079 | if (w->invert) |
| 2080 | val = !val; |
| 2081 | |
| 2082 | if (val) |
| 2083 | w->power = 1; |
| 2084 | } |
| 2085 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2086 | w->new = 1; |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 2087 | |
| 2088 | dapm_debugfs_add_widget(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2089 | } |
| 2090 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2091 | dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2092 | return 0; |
| 2093 | } |
| 2094 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); |
| 2095 | |
| 2096 | /** |
| 2097 | * snd_soc_dapm_get_volsw - dapm mixer get callback |
| 2098 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2099 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2100 | * |
| 2101 | * Callback to get the value of a dapm mixer control. |
| 2102 | * |
| 2103 | * Returns 0 for success. |
| 2104 | */ |
| 2105 | int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, |
| 2106 | struct snd_ctl_elem_value *ucontrol) |
| 2107 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2108 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2109 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2110 | struct soc_mixer_control *mc = |
| 2111 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2112 | unsigned int reg = mc->reg; |
| 2113 | unsigned int shift = mc->shift; |
| 2114 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2115 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2116 | unsigned int invert = mc->invert; |
| 2117 | unsigned int mask = (1 << fls(max)) - 1; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2118 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2119 | ucontrol->value.integer.value[0] = |
| 2120 | (snd_soc_read(widget->codec, reg) >> shift) & mask; |
| 2121 | if (shift != rshift) |
| 2122 | ucontrol->value.integer.value[1] = |
| 2123 | (snd_soc_read(widget->codec, reg) >> rshift) & mask; |
| 2124 | if (invert) { |
| 2125 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2126 | max - ucontrol->value.integer.value[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2127 | if (shift != rshift) |
| 2128 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2129 | max - ucontrol->value.integer.value[1]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | return 0; |
| 2133 | } |
| 2134 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw); |
| 2135 | |
| 2136 | /** |
| 2137 | * snd_soc_dapm_put_volsw - dapm mixer set callback |
| 2138 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2139 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2140 | * |
| 2141 | * Callback to set the value of a dapm mixer control. |
| 2142 | * |
| 2143 | * Returns 0 for success. |
| 2144 | */ |
| 2145 | int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, |
| 2146 | struct snd_ctl_elem_value *ucontrol) |
| 2147 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2148 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2149 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2150 | struct snd_soc_codec *codec = widget->codec; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2151 | struct soc_mixer_control *mc = |
| 2152 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2153 | unsigned int reg = mc->reg; |
| 2154 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2155 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2156 | unsigned int mask = (1 << fls(max)) - 1; |
| 2157 | unsigned int invert = mc->invert; |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2158 | unsigned int val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2159 | int connect, change; |
| 2160 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2161 | int wi; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2162 | |
| 2163 | val = (ucontrol->value.integer.value[0] & mask); |
| 2164 | |
| 2165 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2166 | val = max - val; |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2167 | mask = mask << shift; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2168 | val = val << shift; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2169 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2170 | if (val) |
| 2171 | /* new connection */ |
| 2172 | connect = invert ? 0 : 1; |
| 2173 | else |
| 2174 | /* old connection must be powered down */ |
| 2175 | connect = invert ? 1 : 0; |
| 2176 | |
| 2177 | mutex_lock(&codec->mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2178 | |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2179 | change = snd_soc_test_bits(widget->codec, reg, mask, val); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2180 | if (change) { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2181 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2182 | widget = wlist->widgets[wi]; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 2183 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2184 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2185 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2186 | update.kcontrol = kcontrol; |
| 2187 | update.widget = widget; |
| 2188 | update.reg = reg; |
| 2189 | update.mask = mask; |
| 2190 | update.val = val; |
| 2191 | widget->dapm->update = &update; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2192 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2193 | dapm_mixer_update_power(widget, kcontrol, connect); |
| 2194 | |
| 2195 | widget->dapm->update = NULL; |
| 2196 | } |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2199 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2200 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2201 | } |
| 2202 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); |
| 2203 | |
| 2204 | /** |
| 2205 | * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback |
| 2206 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2207 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2208 | * |
| 2209 | * Callback to get the value of a dapm enumerated double mixer control. |
| 2210 | * |
| 2211 | * Returns 0 for success. |
| 2212 | */ |
| 2213 | int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, |
| 2214 | struct snd_ctl_elem_value *ucontrol) |
| 2215 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2216 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2217 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2218 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2219 | unsigned int val, bitmask; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2220 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2221 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2222 | ; |
| 2223 | val = snd_soc_read(widget->codec, e->reg); |
| 2224 | ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1); |
| 2225 | if (e->shift_l != e->shift_r) |
| 2226 | ucontrol->value.enumerated.item[1] = |
| 2227 | (val >> e->shift_r) & (bitmask - 1); |
| 2228 | |
| 2229 | return 0; |
| 2230 | } |
| 2231 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double); |
| 2232 | |
| 2233 | /** |
| 2234 | * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback |
| 2235 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2236 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2237 | * |
| 2238 | * Callback to set the value of a dapm enumerated double mixer control. |
| 2239 | * |
| 2240 | * Returns 0 for success. |
| 2241 | */ |
| 2242 | int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, |
| 2243 | struct snd_ctl_elem_value *ucontrol) |
| 2244 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2245 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2246 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2247 | struct snd_soc_codec *codec = widget->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2248 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2249 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2250 | unsigned int mask, bitmask; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2251 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2252 | int wi; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2253 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2254 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2255 | ; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2256 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2257 | return -EINVAL; |
| 2258 | mux = ucontrol->value.enumerated.item[0]; |
| 2259 | val = mux << e->shift_l; |
| 2260 | mask = (bitmask - 1) << e->shift_l; |
| 2261 | if (e->shift_l != e->shift_r) { |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2262 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2263 | return -EINVAL; |
| 2264 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; |
| 2265 | mask |= (bitmask - 1) << e->shift_r; |
| 2266 | } |
| 2267 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2268 | mutex_lock(&codec->mutex); |
| 2269 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2270 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2271 | if (change) { |
| 2272 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2273 | widget = wlist->widgets[wi]; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2274 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2275 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2276 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2277 | update.kcontrol = kcontrol; |
| 2278 | update.widget = widget; |
| 2279 | update.reg = e->reg; |
| 2280 | update.mask = mask; |
| 2281 | update.val = val; |
| 2282 | widget->dapm->update = &update; |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2283 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2284 | dapm_mux_update_power(widget, kcontrol, change, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2285 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2286 | widget->dapm->update = NULL; |
| 2287 | } |
| 2288 | } |
| 2289 | |
| 2290 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2291 | return change; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2292 | } |
| 2293 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); |
| 2294 | |
| 2295 | /** |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2296 | * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux |
| 2297 | * @kcontrol: mixer control |
| 2298 | * @ucontrol: control element information |
| 2299 | * |
| 2300 | * Returns 0 for success. |
| 2301 | */ |
| 2302 | int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol, |
| 2303 | struct snd_ctl_elem_value *ucontrol) |
| 2304 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2305 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2306 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2307 | |
| 2308 | ucontrol->value.enumerated.item[0] = widget->value; |
| 2309 | |
| 2310 | return 0; |
| 2311 | } |
| 2312 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt); |
| 2313 | |
| 2314 | /** |
| 2315 | * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux |
| 2316 | * @kcontrol: mixer control |
| 2317 | * @ucontrol: control element information |
| 2318 | * |
| 2319 | * Returns 0 for success. |
| 2320 | */ |
| 2321 | int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol, |
| 2322 | struct snd_ctl_elem_value *ucontrol) |
| 2323 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2324 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2325 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2326 | struct snd_soc_codec *codec = widget->codec; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2327 | struct soc_enum *e = |
| 2328 | (struct soc_enum *)kcontrol->private_value; |
| 2329 | int change; |
| 2330 | int ret = 0; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2331 | int wi; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2332 | |
| 2333 | if (ucontrol->value.enumerated.item[0] >= e->max) |
| 2334 | return -EINVAL; |
| 2335 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2336 | mutex_lock(&codec->mutex); |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2337 | |
| 2338 | change = widget->value != ucontrol->value.enumerated.item[0]; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2339 | if (change) { |
| 2340 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2341 | widget = wlist->widgets[wi]; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2342 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2343 | widget->value = ucontrol->value.enumerated.item[0]; |
| 2344 | |
| 2345 | dapm_mux_update_power(widget, kcontrol, change, |
| 2346 | widget->value, e); |
| 2347 | } |
| 2348 | } |
| 2349 | |
| 2350 | mutex_unlock(&codec->mutex); |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2351 | return ret; |
| 2352 | } |
| 2353 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt); |
| 2354 | |
| 2355 | /** |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2356 | * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get |
| 2357 | * callback |
| 2358 | * @kcontrol: mixer control |
| 2359 | * @ucontrol: control element information |
| 2360 | * |
| 2361 | * Callback to get the value of a dapm semi enumerated double mixer control. |
| 2362 | * |
| 2363 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2364 | * used for handling bitfield coded enumeration for example. |
| 2365 | * |
| 2366 | * Returns 0 for success. |
| 2367 | */ |
| 2368 | int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2369 | struct snd_ctl_elem_value *ucontrol) |
| 2370 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2371 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2372 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2373 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2374 | unsigned int reg_val, val, mux; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2375 | |
| 2376 | reg_val = snd_soc_read(widget->codec, e->reg); |
| 2377 | val = (reg_val >> e->shift_l) & e->mask; |
| 2378 | for (mux = 0; mux < e->max; mux++) { |
| 2379 | if (val == e->values[mux]) |
| 2380 | break; |
| 2381 | } |
| 2382 | ucontrol->value.enumerated.item[0] = mux; |
| 2383 | if (e->shift_l != e->shift_r) { |
| 2384 | val = (reg_val >> e->shift_r) & e->mask; |
| 2385 | for (mux = 0; mux < e->max; mux++) { |
| 2386 | if (val == e->values[mux]) |
| 2387 | break; |
| 2388 | } |
| 2389 | ucontrol->value.enumerated.item[1] = mux; |
| 2390 | } |
| 2391 | |
| 2392 | return 0; |
| 2393 | } |
| 2394 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double); |
| 2395 | |
| 2396 | /** |
| 2397 | * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set |
| 2398 | * callback |
| 2399 | * @kcontrol: mixer control |
| 2400 | * @ucontrol: control element information |
| 2401 | * |
| 2402 | * Callback to set the value of a dapm semi enumerated double mixer control. |
| 2403 | * |
| 2404 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2405 | * used for handling bitfield coded enumeration for example. |
| 2406 | * |
| 2407 | * Returns 0 for success. |
| 2408 | */ |
| 2409 | int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2410 | struct snd_ctl_elem_value *ucontrol) |
| 2411 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2412 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2413 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2414 | struct snd_soc_codec *codec = widget->codec; |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2415 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2416 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2417 | unsigned int mask; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2418 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2419 | int wi; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2420 | |
| 2421 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 2422 | return -EINVAL; |
| 2423 | mux = ucontrol->value.enumerated.item[0]; |
| 2424 | val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; |
| 2425 | mask = e->mask << e->shift_l; |
| 2426 | if (e->shift_l != e->shift_r) { |
| 2427 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
| 2428 | return -EINVAL; |
| 2429 | val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; |
| 2430 | mask |= e->mask << e->shift_r; |
| 2431 | } |
| 2432 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2433 | mutex_lock(&codec->mutex); |
| 2434 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2435 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2436 | if (change) { |
| 2437 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2438 | widget = wlist->widgets[wi]; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2439 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2440 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2441 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2442 | update.kcontrol = kcontrol; |
| 2443 | update.widget = widget; |
| 2444 | update.reg = e->reg; |
| 2445 | update.mask = mask; |
| 2446 | update.val = val; |
| 2447 | widget->dapm->update = &update; |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2448 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2449 | dapm_mux_update_power(widget, kcontrol, change, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2450 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2451 | widget->dapm->update = NULL; |
| 2452 | } |
| 2453 | } |
| 2454 | |
| 2455 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2456 | return change; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2457 | } |
| 2458 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); |
| 2459 | |
| 2460 | /** |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2461 | * snd_soc_dapm_info_pin_switch - Info for a pin switch |
| 2462 | * |
| 2463 | * @kcontrol: mixer control |
| 2464 | * @uinfo: control element information |
| 2465 | * |
| 2466 | * Callback to provide information about a pin switch control. |
| 2467 | */ |
| 2468 | int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol, |
| 2469 | struct snd_ctl_elem_info *uinfo) |
| 2470 | { |
| 2471 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2472 | uinfo->count = 1; |
| 2473 | uinfo->value.integer.min = 0; |
| 2474 | uinfo->value.integer.max = 1; |
| 2475 | |
| 2476 | return 0; |
| 2477 | } |
| 2478 | EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch); |
| 2479 | |
| 2480 | /** |
| 2481 | * snd_soc_dapm_get_pin_switch - Get information for a pin switch |
| 2482 | * |
| 2483 | * @kcontrol: mixer control |
| 2484 | * @ucontrol: Value |
| 2485 | */ |
| 2486 | int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol, |
| 2487 | struct snd_ctl_elem_value *ucontrol) |
| 2488 | { |
| 2489 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2490 | const char *pin = (const char *)kcontrol->private_value; |
| 2491 | |
| 2492 | mutex_lock(&codec->mutex); |
| 2493 | |
| 2494 | ucontrol->value.integer.value[0] = |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2495 | snd_soc_dapm_get_pin_status(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2496 | |
| 2497 | mutex_unlock(&codec->mutex); |
| 2498 | |
| 2499 | return 0; |
| 2500 | } |
| 2501 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch); |
| 2502 | |
| 2503 | /** |
| 2504 | * snd_soc_dapm_put_pin_switch - Set information for a pin switch |
| 2505 | * |
| 2506 | * @kcontrol: mixer control |
| 2507 | * @ucontrol: Value |
| 2508 | */ |
| 2509 | int snd_soc_dapm_put_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 | if (ucontrol->value.integer.value[0]) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2518 | snd_soc_dapm_enable_pin(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2519 | else |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2520 | snd_soc_dapm_disable_pin(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2521 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2522 | snd_soc_dapm_sync(&codec->dapm); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2523 | |
| 2524 | mutex_unlock(&codec->mutex); |
| 2525 | |
| 2526 | return 0; |
| 2527 | } |
| 2528 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch); |
| 2529 | |
| 2530 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2531 | * snd_soc_dapm_new_control - create new dapm control |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2532 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2533 | * @widget: widget template |
| 2534 | * |
| 2535 | * Creates a new dapm control based upon the template. |
| 2536 | * |
| 2537 | * Returns 0 for success else error. |
| 2538 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2539 | int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2540 | const struct snd_soc_dapm_widget *widget) |
| 2541 | { |
| 2542 | struct snd_soc_dapm_widget *w; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2543 | size_t name_len; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2544 | |
| 2545 | if ((w = dapm_cnew_widget(widget)) == NULL) |
| 2546 | return -ENOMEM; |
| 2547 | |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2548 | name_len = strlen(widget->name) + 1; |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 2549 | if (dapm->codec && dapm->codec->name_prefix) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2550 | name_len += 1 + strlen(dapm->codec->name_prefix); |
| 2551 | w->name = kmalloc(name_len, GFP_KERNEL); |
| 2552 | if (w->name == NULL) { |
| 2553 | kfree(w); |
| 2554 | return -ENOMEM; |
| 2555 | } |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 2556 | if (dapm->codec && dapm->codec->name_prefix) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2557 | snprintf(w->name, name_len, "%s %s", |
| 2558 | dapm->codec->name_prefix, widget->name); |
| 2559 | else |
| 2560 | snprintf(w->name, name_len, "%s", widget->name); |
| 2561 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2562 | dapm->n_widgets++; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2563 | w->dapm = dapm; |
| 2564 | w->codec = dapm->codec; |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 2565 | w->platform = dapm->platform; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2566 | INIT_LIST_HEAD(&w->sources); |
| 2567 | INIT_LIST_HEAD(&w->sinks); |
| 2568 | INIT_LIST_HEAD(&w->list); |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2569 | list_add(&w->list, &dapm->card->widgets); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2570 | |
| 2571 | /* machine layer set ups unconnected pins and insertions */ |
| 2572 | w->connected = 1; |
| 2573 | return 0; |
| 2574 | } |
| 2575 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control); |
| 2576 | |
| 2577 | /** |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2578 | * snd_soc_dapm_new_controls - create new dapm controls |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2579 | * @dapm: DAPM context |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2580 | * @widget: widget array |
| 2581 | * @num: number of widgets |
| 2582 | * |
| 2583 | * Creates new DAPM controls based upon the templates. |
| 2584 | * |
| 2585 | * Returns 0 for success else error. |
| 2586 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2587 | int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm, |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2588 | const struct snd_soc_dapm_widget *widget, |
| 2589 | int num) |
| 2590 | { |
| 2591 | int i, ret; |
| 2592 | |
| 2593 | for (i = 0; i < num; i++) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2594 | ret = snd_soc_dapm_new_control(dapm, widget); |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 2595 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2596 | dev_err(dapm->dev, |
| 2597 | "ASoC: Failed to create DAPM control %s: %d\n", |
| 2598 | widget->name, ret); |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2599 | return ret; |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 2600 | } |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2601 | widget++; |
| 2602 | } |
| 2603 | return 0; |
| 2604 | } |
| 2605 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); |
| 2606 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2607 | static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2608 | const char *stream, int event) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2609 | { |
| 2610 | struct snd_soc_dapm_widget *w; |
| 2611 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2612 | list_for_each_entry(w, &dapm->card->widgets, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2613 | { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2614 | if (!w->sname || w->dapm != dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2615 | continue; |
Liam Girdwood | ee47b36 | 2011-07-25 11:15:50 +0100 | [diff] [blame] | 2616 | 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] | 2617 | w->name, w->sname, stream, event); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2618 | if (strstr(w->sname, stream)) { |
| 2619 | switch(event) { |
| 2620 | case SND_SOC_DAPM_STREAM_START: |
| 2621 | w->active = 1; |
| 2622 | break; |
| 2623 | case SND_SOC_DAPM_STREAM_STOP: |
| 2624 | w->active = 0; |
| 2625 | break; |
| 2626 | case SND_SOC_DAPM_STREAM_SUSPEND: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2627 | case SND_SOC_DAPM_STREAM_RESUME: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2628 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2629 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: |
| 2630 | break; |
| 2631 | } |
| 2632 | } |
| 2633 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2634 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2635 | dapm_power_widgets(dapm, event); |
Liam Girdwood | 64a648c | 2011-07-25 11:15:15 +0100 | [diff] [blame] | 2636 | |
| 2637 | /* do we need to notify any clients that DAPM stream is complete */ |
| 2638 | if (dapm->stream_event) |
| 2639 | dapm->stream_event(dapm, event); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2640 | } |
| 2641 | |
| 2642 | /** |
| 2643 | * snd_soc_dapm_stream_event - send a stream event to the dapm core |
| 2644 | * @rtd: PCM runtime data |
| 2645 | * @stream: stream name |
| 2646 | * @event: stream event |
| 2647 | * |
| 2648 | * Sends a stream event to the dapm core. The core then makes any |
| 2649 | * necessary widget power changes. |
| 2650 | * |
| 2651 | * Returns 0 for success else error. |
| 2652 | */ |
| 2653 | int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, |
| 2654 | const char *stream, int event) |
| 2655 | { |
| 2656 | struct snd_soc_codec *codec = rtd->codec; |
| 2657 | |
| 2658 | if (stream == NULL) |
| 2659 | return 0; |
| 2660 | |
| 2661 | mutex_lock(&codec->mutex); |
| 2662 | soc_dapm_stream_event(&codec->dapm, stream, event); |
Eero Nurkkala | 8e8b2d6 | 2009-10-12 08:41:59 +0300 | [diff] [blame] | 2663 | mutex_unlock(&codec->mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2664 | return 0; |
| 2665 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2666 | |
| 2667 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2668 | * snd_soc_dapm_enable_pin - enable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2669 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2670 | * @pin: pin name |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2671 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 2672 | * 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] | 2673 | * a valid audio route and active audio stream. |
| 2674 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2675 | * do any widget power switching. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2676 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2677 | 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] | 2678 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2679 | return snd_soc_dapm_set_pin(dapm, pin, 1); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2680 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2681 | EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2682 | |
| 2683 | /** |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2684 | * snd_soc_dapm_force_enable_pin - force a pin to be enabled |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2685 | * @dapm: DAPM context |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2686 | * @pin: pin name |
| 2687 | * |
| 2688 | * Enables input/output pin regardless of any other state. This is |
| 2689 | * intended for use with microphone bias supplies used in microphone |
| 2690 | * jack detection. |
| 2691 | * |
| 2692 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2693 | * do any widget power switching. |
| 2694 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2695 | int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm, |
| 2696 | const char *pin) |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2697 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2698 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2699 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2700 | if (!w) { |
| 2701 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 2702 | return -EINVAL; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2703 | } |
| 2704 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2705 | dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin); |
| 2706 | w->connected = 1; |
| 2707 | w->force = 1; |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 2708 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2709 | return 0; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2710 | } |
| 2711 | EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin); |
| 2712 | |
| 2713 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2714 | * snd_soc_dapm_disable_pin - disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2715 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2716 | * @pin: pin name |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2717 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 2718 | * Disables input/output pin and its parents or children widgets. |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2719 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2720 | * do any widget power switching. |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2721 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2722 | int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm, |
| 2723 | const char *pin) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2724 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2725 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2726 | } |
| 2727 | EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin); |
| 2728 | |
| 2729 | /** |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2730 | * snd_soc_dapm_nc_pin - permanently disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2731 | * @dapm: DAPM context |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2732 | * @pin: pin name |
| 2733 | * |
| 2734 | * Marks the specified pin as being not connected, disabling it along |
| 2735 | * any parent or child widgets. At present this is identical to |
| 2736 | * snd_soc_dapm_disable_pin() but in future it will be extended to do |
| 2737 | * additional things such as disabling controls which only affect |
| 2738 | * paths through the pin. |
| 2739 | * |
| 2740 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2741 | * do any widget power switching. |
| 2742 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2743 | 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] | 2744 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2745 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2746 | } |
| 2747 | EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin); |
| 2748 | |
| 2749 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2750 | * snd_soc_dapm_get_pin_status - get audio pin status |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2751 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2752 | * @pin: audio signal pin endpoint (or start point) |
| 2753 | * |
| 2754 | * Get audio pin status - connected or disconnected. |
| 2755 | * |
| 2756 | * Returns 1 for connected otherwise 0. |
| 2757 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2758 | int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm, |
| 2759 | const char *pin) |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2760 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2761 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2762 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2763 | if (w) |
| 2764 | return w->connected; |
Stephen Warren | a68b38a | 2011-04-19 15:25:11 -0600 | [diff] [blame] | 2765 | |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2766 | return 0; |
| 2767 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2768 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2769 | |
| 2770 | /** |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2771 | * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2772 | * @dapm: DAPM context |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2773 | * @pin: audio signal pin endpoint (or start point) |
| 2774 | * |
| 2775 | * Mark the given endpoint or pin as ignoring suspend. When the |
| 2776 | * system is disabled a path between two endpoints flagged as ignoring |
| 2777 | * suspend will not be disabled. The path must already be enabled via |
| 2778 | * normal means at suspend time, it will not be turned on if it was not |
| 2779 | * already enabled. |
| 2780 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2781 | int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm, |
| 2782 | const char *pin) |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [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, false); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2785 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2786 | if (!w) { |
| 2787 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 2788 | return -EINVAL; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2789 | } |
| 2790 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2791 | w->ignore_suspend = 1; |
| 2792 | |
| 2793 | return 0; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2794 | } |
| 2795 | EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend); |
| 2796 | |
| 2797 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2798 | * snd_soc_dapm_free - free dapm resources |
Peter Ujfalusi | 728a522 | 2011-08-26 16:33:52 +0300 | [diff] [blame] | 2799 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2800 | * |
| 2801 | * Free all dapm widgets and resources. |
| 2802 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2803 | void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2804 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2805 | snd_soc_dapm_sys_remove(dapm->dev); |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 2806 | dapm_debugfs_cleanup(dapm); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2807 | dapm_free_widgets(dapm); |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 2808 | list_del(&dapm->list); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2809 | } |
| 2810 | EXPORT_SYMBOL_GPL(snd_soc_dapm_free); |
| 2811 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2812 | static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2813 | { |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2814 | struct snd_soc_dapm_widget *w; |
| 2815 | LIST_HEAD(down_list); |
| 2816 | int powerdown = 0; |
| 2817 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2818 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 2819 | if (w->dapm != dapm) |
| 2820 | continue; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2821 | if (w->power) { |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 2822 | dapm_seq_insert(w, &down_list, false); |
Mark Brown | c2caa4d | 2009-06-26 15:36:56 +0100 | [diff] [blame] | 2823 | w->power = 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2824 | powerdown = 1; |
| 2825 | } |
| 2826 | } |
| 2827 | |
| 2828 | /* If there were no widgets to power down we're already in |
| 2829 | * standby. |
| 2830 | */ |
| 2831 | if (powerdown) { |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 2832 | snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE); |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 2833 | dapm_seq_run(dapm, &down_list, 0, false); |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 2834 | snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2835 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2836 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2837 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2838 | /* |
| 2839 | * snd_soc_dapm_shutdown - callback for system shutdown |
| 2840 | */ |
| 2841 | void snd_soc_dapm_shutdown(struct snd_soc_card *card) |
| 2842 | { |
| 2843 | struct snd_soc_codec *codec; |
| 2844 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2845 | list_for_each_entry(codec, &card->codec_dev_list, list) { |
| 2846 | soc_dapm_shutdown_codec(&codec->dapm); |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 2847 | snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2848 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2849 | } |
| 2850 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2851 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 2852 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2853 | MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC"); |
| 2854 | MODULE_LICENSE("GPL"); |