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