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