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