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