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