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) { |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1293 | if (!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 | |
| 1353 | if (!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 | |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1570 | list_for_each_entry(d, &card->dapm_list, list) { |
| 1571 | if (d->n_widgets || d->codec == NULL) { |
| 1572 | if (d->idle_bias_off) |
| 1573 | d->target_bias_level = SND_SOC_BIAS_OFF; |
| 1574 | else |
| 1575 | d->target_bias_level = SND_SOC_BIAS_STANDBY; |
| 1576 | } |
| 1577 | } |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1578 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1579 | memset(&card->dapm_stats, 0, sizeof(card->dapm_stats)); |
| 1580 | |
| 1581 | list_for_each_entry(w, &card->widgets, list) { |
| 1582 | w->power_checked = false; |
| 1583 | w->inputs = -1; |
| 1584 | w->outputs = -1; |
| 1585 | } |
Mark Brown | 9b8a83b | 2011-10-04 22:15:59 +0100 | [diff] [blame] | 1586 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1587 | /* Check which widgets we need to power and store them in |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1588 | * lists indicating if they should be powered up or down. We |
| 1589 | * only check widgets that have been flagged as dirty but note |
| 1590 | * that new widgets may be added to the dirty list while we |
| 1591 | * iterate. |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1592 | */ |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1593 | list_for_each_entry(w, &card->dapm_dirty, dirty) { |
Mark Brown | 7c81beb | 2011-09-20 22:22:32 +0100 | [diff] [blame] | 1594 | dapm_power_one_widget(w, &up_list, &down_list); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1595 | } |
| 1596 | |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1597 | list_for_each_entry(w, &card->widgets, list) { |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1598 | list_del_init(&w->dirty); |
| 1599 | |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1600 | if (w->power) { |
| 1601 | d = w->dapm; |
| 1602 | |
| 1603 | /* Supplies and micbiases only bring the |
| 1604 | * context up to STANDBY as unless something |
| 1605 | * else is active and passing audio they |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1606 | * generally don't require full power. |
Mark Brown | f9de6d7 | 2011-09-28 17:19:47 +0100 | [diff] [blame] | 1607 | */ |
| 1608 | switch (w->id) { |
| 1609 | case snd_soc_dapm_supply: |
| 1610 | case snd_soc_dapm_micbias: |
| 1611 | if (d->target_bias_level < SND_SOC_BIAS_STANDBY) |
| 1612 | d->target_bias_level = SND_SOC_BIAS_STANDBY; |
| 1613 | break; |
| 1614 | default: |
| 1615 | d->target_bias_level = SND_SOC_BIAS_ON; |
| 1616 | break; |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | } |
| 1621 | |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1622 | /* If there are no DAPM widgets then try to figure out power from the |
| 1623 | * event type. |
| 1624 | */ |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1625 | if (!dapm->n_widgets) { |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1626 | switch (event) { |
| 1627 | case SND_SOC_DAPM_STREAM_START: |
| 1628 | case SND_SOC_DAPM_STREAM_RESUME: |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1629 | dapm->target_bias_level = SND_SOC_BIAS_ON; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1630 | break; |
Jarkko Nikula | 862af8a | 2010-12-10 20:53:55 +0200 | [diff] [blame] | 1631 | case SND_SOC_DAPM_STREAM_STOP: |
Liam Girdwood | e7c80e2 | 2012-01-16 15:23:31 +0000 | [diff] [blame] | 1632 | if (dapm->codec && dapm->codec->active) |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1633 | dapm->target_bias_level = SND_SOC_BIAS_ON; |
| 1634 | else |
| 1635 | dapm->target_bias_level = SND_SOC_BIAS_STANDBY; |
Jarkko Nikula | 862af8a | 2010-12-10 20:53:55 +0200 | [diff] [blame] | 1636 | break; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1637 | case SND_SOC_DAPM_STREAM_SUSPEND: |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1638 | dapm->target_bias_level = SND_SOC_BIAS_STANDBY; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1639 | break; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1640 | case SND_SOC_DAPM_STREAM_NOP: |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1641 | dapm->target_bias_level = dapm->bias_level; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1642 | break; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1643 | default: |
| 1644 | break; |
| 1645 | } |
| 1646 | } |
| 1647 | |
Mark Brown | 85a843c | 2011-09-21 21:29:47 +0100 | [diff] [blame] | 1648 | /* Force all contexts in the card to the same bias state if |
| 1649 | * they're not ground referenced. |
| 1650 | */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1651 | bias = SND_SOC_BIAS_OFF; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1652 | list_for_each_entry(d, &card->dapm_list, list) |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1653 | if (d->target_bias_level > bias) |
| 1654 | bias = d->target_bias_level; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1655 | list_for_each_entry(d, &card->dapm_list, list) |
Mark Brown | 85a843c | 2011-09-21 21:29:47 +0100 | [diff] [blame] | 1656 | if (!d->idle_bias_off) |
| 1657 | d->target_bias_level = bias; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1658 | |
Mark Brown | de02d07 | 2011-09-20 21:43:24 +0100 | [diff] [blame] | 1659 | trace_snd_soc_dapm_walk_done(card); |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1660 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1661 | /* Run all the bias changes in parallel */ |
| 1662 | list_for_each_entry(d, &dapm->card->dapm_list, list) |
| 1663 | async_schedule_domain(dapm_pre_sequence_async, d, |
| 1664 | &async_domain); |
| 1665 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1666 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1667 | /* Power down widgets first; try to avoid amplifying pops. */ |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1668 | dapm_seq_run(dapm, &down_list, event, false); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1669 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1670 | dapm_widget_update(dapm); |
| 1671 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1672 | /* Now power up. */ |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1673 | dapm_seq_run(dapm, &up_list, event, true); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1674 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1675 | /* Run all the bias changes in parallel */ |
| 1676 | list_for_each_entry(d, &dapm->card->dapm_list, list) |
| 1677 | async_schedule_domain(dapm_post_sequence_async, d, |
| 1678 | &async_domain); |
| 1679 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1680 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 1681 | pop_dbg(dapm->dev, card->pop_time, |
| 1682 | "DAPM sequencing finished, waiting %dms\n", card->pop_time); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1683 | pop_wait(card->pop_time); |
Mark Brown | cb507e7 | 2009-07-08 18:54:57 +0100 | [diff] [blame] | 1684 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1685 | trace_snd_soc_dapm_done(card); |
| 1686 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1687 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1688 | } |
| 1689 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1690 | #ifdef CONFIG_DEBUG_FS |
| 1691 | static int dapm_widget_power_open_file(struct inode *inode, struct file *file) |
| 1692 | { |
| 1693 | file->private_data = inode->i_private; |
| 1694 | return 0; |
| 1695 | } |
| 1696 | |
| 1697 | static ssize_t dapm_widget_power_read_file(struct file *file, |
| 1698 | char __user *user_buf, |
| 1699 | size_t count, loff_t *ppos) |
| 1700 | { |
| 1701 | struct snd_soc_dapm_widget *w = file->private_data; |
| 1702 | char *buf; |
| 1703 | int in, out; |
| 1704 | ssize_t ret; |
| 1705 | struct snd_soc_dapm_path *p = NULL; |
| 1706 | |
| 1707 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 1708 | if (!buf) |
| 1709 | return -ENOMEM; |
| 1710 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1711 | in = is_connected_input_ep(w, NULL); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1712 | dapm_clear_walk(w->dapm); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1713 | out = is_connected_output_ep(w, NULL); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1714 | dapm_clear_walk(w->dapm); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1715 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1716 | ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1717 | w->name, w->power ? "On" : "Off", in, out); |
| 1718 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1719 | if (w->reg >= 0) |
| 1720 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
| 1721 | " - R%d(0x%x) bit %d", |
| 1722 | w->reg, w->reg, w->shift); |
| 1723 | |
| 1724 | ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n"); |
| 1725 | |
Mark Brown | 3eef08b | 2009-09-14 16:49:00 +0100 | [diff] [blame] | 1726 | if (w->sname) |
| 1727 | ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n", |
| 1728 | w->sname, |
| 1729 | w->active ? "active" : "inactive"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1730 | |
| 1731 | list_for_each_entry(p, &w->sources, list_sink) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1732 | if (p->connected && !p->connected(w, p->sink)) |
| 1733 | continue; |
| 1734 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1735 | if (p->connect) |
| 1736 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Dimitris Papastamos | 67f5ed6 | 2011-02-24 17:09:32 +0000 | [diff] [blame] | 1737 | " in \"%s\" \"%s\"\n", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1738 | p->name ? p->name : "static", |
| 1739 | p->source->name); |
| 1740 | } |
| 1741 | list_for_each_entry(p, &w->sinks, list_source) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1742 | if (p->connected && !p->connected(w, p->sink)) |
| 1743 | continue; |
| 1744 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1745 | if (p->connect) |
| 1746 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Dimitris Papastamos | 67f5ed6 | 2011-02-24 17:09:32 +0000 | [diff] [blame] | 1747 | " out \"%s\" \"%s\"\n", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1748 | p->name ? p->name : "static", |
| 1749 | p->sink->name); |
| 1750 | } |
| 1751 | |
| 1752 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 1753 | |
| 1754 | kfree(buf); |
| 1755 | return ret; |
| 1756 | } |
| 1757 | |
| 1758 | static const struct file_operations dapm_widget_power_fops = { |
| 1759 | .open = dapm_widget_power_open_file, |
| 1760 | .read = dapm_widget_power_read_file, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1761 | .llseek = default_llseek, |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1762 | }; |
| 1763 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1764 | static int dapm_bias_open_file(struct inode *inode, struct file *file) |
| 1765 | { |
| 1766 | file->private_data = inode->i_private; |
| 1767 | return 0; |
| 1768 | } |
| 1769 | |
| 1770 | static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf, |
| 1771 | size_t count, loff_t *ppos) |
| 1772 | { |
| 1773 | struct snd_soc_dapm_context *dapm = file->private_data; |
| 1774 | char *level; |
| 1775 | |
| 1776 | switch (dapm->bias_level) { |
| 1777 | case SND_SOC_BIAS_ON: |
| 1778 | level = "On\n"; |
| 1779 | break; |
| 1780 | case SND_SOC_BIAS_PREPARE: |
| 1781 | level = "Prepare\n"; |
| 1782 | break; |
| 1783 | case SND_SOC_BIAS_STANDBY: |
| 1784 | level = "Standby\n"; |
| 1785 | break; |
| 1786 | case SND_SOC_BIAS_OFF: |
| 1787 | level = "Off\n"; |
| 1788 | break; |
| 1789 | default: |
| 1790 | BUG(); |
| 1791 | level = "Unknown\n"; |
| 1792 | break; |
| 1793 | } |
| 1794 | |
| 1795 | return simple_read_from_buffer(user_buf, count, ppos, level, |
| 1796 | strlen(level)); |
| 1797 | } |
| 1798 | |
| 1799 | static const struct file_operations dapm_bias_fops = { |
| 1800 | .open = dapm_bias_open_file, |
| 1801 | .read = dapm_bias_read_file, |
| 1802 | .llseek = default_llseek, |
| 1803 | }; |
| 1804 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1805 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 1806 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1807 | { |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1808 | struct dentry *d; |
| 1809 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1810 | dapm->debugfs_dapm = debugfs_create_dir("dapm", parent); |
| 1811 | |
| 1812 | if (!dapm->debugfs_dapm) { |
| 1813 | printk(KERN_WARNING |
| 1814 | "Failed to create DAPM debugfs directory\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1815 | return; |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1816 | } |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1817 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1818 | d = debugfs_create_file("bias_level", 0444, |
| 1819 | dapm->debugfs_dapm, dapm, |
| 1820 | &dapm_bias_fops); |
| 1821 | if (!d) |
| 1822 | dev_warn(dapm->dev, |
| 1823 | "ASoC: Failed to create bias level debugfs file\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1824 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1825 | |
| 1826 | static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 1827 | { |
| 1828 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 1829 | struct dentry *d; |
| 1830 | |
| 1831 | if (!dapm->debugfs_dapm || !w->name) |
| 1832 | return; |
| 1833 | |
| 1834 | d = debugfs_create_file(w->name, 0444, |
| 1835 | dapm->debugfs_dapm, w, |
| 1836 | &dapm_widget_power_fops); |
| 1837 | if (!d) |
| 1838 | dev_warn(w->dapm->dev, |
| 1839 | "ASoC: Failed to create %s debugfs file\n", |
| 1840 | w->name); |
| 1841 | } |
| 1842 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 1843 | static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 1844 | { |
| 1845 | debugfs_remove_recursive(dapm->debugfs_dapm); |
| 1846 | } |
| 1847 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1848 | #else |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1849 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 1850 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1851 | { |
| 1852 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1853 | |
| 1854 | static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 1855 | { |
| 1856 | } |
| 1857 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 1858 | static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 1859 | { |
| 1860 | } |
| 1861 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1862 | #endif |
| 1863 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1864 | /* test and update the power status of a mux widget */ |
Liam Girdwood | 40f02cd | 2012-02-06 16:05:14 +0000 | [diff] [blame] | 1865 | 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] | 1866 | struct snd_kcontrol *kcontrol, int change, |
| 1867 | int mux, struct soc_enum *e) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1868 | { |
| 1869 | struct snd_soc_dapm_path *path; |
| 1870 | int found = 0; |
| 1871 | |
Peter Ujfalusi | eff317d | 2009-01-15 14:40:47 +0200 | [diff] [blame] | 1872 | if (widget->id != snd_soc_dapm_mux && |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 1873 | widget->id != snd_soc_dapm_virt_mux && |
Peter Ujfalusi | eff317d | 2009-01-15 14:40:47 +0200 | [diff] [blame] | 1874 | widget->id != snd_soc_dapm_value_mux) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1875 | return -ENODEV; |
| 1876 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1877 | if (!change) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1878 | return 0; |
| 1879 | |
| 1880 | /* find dapm widget path assoc with kcontrol */ |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1881 | list_for_each_entry(path, &widget->dapm->card->paths, list) { |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 1882 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1883 | if (path->kcontrol != kcontrol) |
| 1884 | continue; |
| 1885 | |
Liam Girdwood | a8f13d8 | 2011-05-18 18:39:21 +0100 | [diff] [blame] | 1886 | if (!path->name || !snd_soc_get_enum_text(e, mux)) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1887 | continue; |
| 1888 | |
| 1889 | found = 1; |
| 1890 | /* 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] | 1891 | if (!(strcmp(path->name, snd_soc_get_enum_text(e, mux)))) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1892 | path->connect = 1; /* new connection */ |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1893 | dapm_mark_dirty(path->source, "mux connection"); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1894 | } else { |
| 1895 | if (path->connect) |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1896 | dapm_mark_dirty(path->source, |
| 1897 | "mux disconnection"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1898 | path->connect = 0; /* old connection must be powered down */ |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1899 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1900 | } |
| 1901 | |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1902 | if (found) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1903 | if (widget->platform) { |
| 1904 | soc_dpcm_runtime_update(widget); |
| 1905 | } else { |
| 1906 | dapm_mark_dirty(widget, "mux change"); |
Patrick Lai | a8d41ee | 2011-09-12 12:42:04 -0700 | [diff] [blame] | 1907 | dapm_power_widgets(widget->dapm, |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1908 | SND_SOC_DAPM_STREAM_NOP); |
| 1909 | } |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1910 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1911 | |
| 1912 | return 0; |
| 1913 | } |
Liam Girdwood | 40f02cd | 2012-02-06 16:05:14 +0000 | [diff] [blame] | 1914 | EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1915 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1916 | /* test and update the power status of a mixer or switch widget */ |
Liam Girdwood | 40f02cd | 2012-02-06 16:05:14 +0000 | [diff] [blame] | 1917 | 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] | 1918 | struct snd_kcontrol *kcontrol, int connect) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1919 | { |
| 1920 | struct snd_soc_dapm_path *path; |
| 1921 | int found = 0; |
| 1922 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1923 | if (widget->id != snd_soc_dapm_mixer && |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1924 | widget->id != snd_soc_dapm_mixer_named_ctl && |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1925 | widget->id != snd_soc_dapm_switch) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1926 | return -ENODEV; |
| 1927 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1928 | /* find dapm widget path assoc with kcontrol */ |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1929 | list_for_each_entry(path, &widget->dapm->card->paths, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1930 | if (path->kcontrol != kcontrol) |
| 1931 | continue; |
| 1932 | |
| 1933 | /* found, now check type */ |
| 1934 | found = 1; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1935 | path->connect = connect; |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1936 | dapm_mark_dirty(path->source, "mixer connection"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1937 | } |
| 1938 | |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1939 | if (found) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1940 | if (widget->platform) { |
| 1941 | soc_dpcm_runtime_update(widget); |
| 1942 | } else { |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 1943 | dapm_mark_dirty(widget, "mixer update"); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1944 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 1947 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1948 | |
| 1949 | return 0; |
| 1950 | } |
Liam Girdwood | 40f02cd | 2012-02-06 16:05:14 +0000 | [diff] [blame] | 1951 | EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1952 | |
| 1953 | /* show dapm widget status in sys fs */ |
| 1954 | static ssize_t dapm_widget_show(struct device *dev, |
| 1955 | struct device_attribute *attr, char *buf) |
| 1956 | { |
Mark Brown | 36ae1a9 | 2012-01-06 17:12:45 -0800 | [diff] [blame] | 1957 | struct snd_soc_pcm_runtime *rtd = dev_get_drvdata(dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1958 | struct snd_soc_codec *codec =rtd->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1959 | struct snd_soc_dapm_widget *w; |
| 1960 | int count = 0; |
| 1961 | char *state = "not set"; |
| 1962 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1963 | list_for_each_entry(w, &codec->card->widgets, list) { |
| 1964 | if (w->dapm != &codec->dapm) |
| 1965 | continue; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1966 | |
| 1967 | /* only display widgets that burnm power */ |
| 1968 | switch (w->id) { |
| 1969 | case snd_soc_dapm_hp: |
| 1970 | case snd_soc_dapm_mic: |
| 1971 | case snd_soc_dapm_spk: |
| 1972 | case snd_soc_dapm_line: |
| 1973 | case snd_soc_dapm_micbias: |
| 1974 | case snd_soc_dapm_dac: |
| 1975 | case snd_soc_dapm_adc: |
| 1976 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 1977 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1978 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1979 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1980 | case snd_soc_dapm_supply: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1981 | if (w->name) |
| 1982 | count += sprintf(buf + count, "%s: %s\n", |
| 1983 | w->name, w->power ? "On":"Off"); |
| 1984 | break; |
| 1985 | default: |
| 1986 | break; |
| 1987 | } |
| 1988 | } |
| 1989 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1990 | switch (codec->dapm.bias_level) { |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1991 | case SND_SOC_BIAS_ON: |
| 1992 | state = "On"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1993 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1994 | case SND_SOC_BIAS_PREPARE: |
| 1995 | state = "Prepare"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1996 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1997 | case SND_SOC_BIAS_STANDBY: |
| 1998 | state = "Standby"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1999 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 2000 | case SND_SOC_BIAS_OFF: |
| 2001 | state = "Off"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2002 | break; |
| 2003 | } |
| 2004 | count += sprintf(buf + count, "PM State: %s\n", state); |
| 2005 | |
| 2006 | return count; |
| 2007 | } |
| 2008 | |
| 2009 | static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL); |
| 2010 | |
| 2011 | int snd_soc_dapm_sys_add(struct device *dev) |
| 2012 | { |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 2013 | return device_create_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | static void snd_soc_dapm_sys_remove(struct device *dev) |
| 2017 | { |
Mark Brown | aef9084 | 2009-05-16 17:53:16 +0100 | [diff] [blame] | 2018 | device_remove_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | /* free all dapm widgets and resources */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2022 | static void dapm_free_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2023 | { |
| 2024 | struct snd_soc_dapm_widget *w, *next_w; |
| 2025 | struct snd_soc_dapm_path *p, *next_p; |
| 2026 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2027 | list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) { |
| 2028 | if (w->dapm != dapm) |
| 2029 | continue; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2030 | list_del(&w->list); |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 2031 | /* |
| 2032 | * remove source and sink paths associated to this widget. |
| 2033 | * While removing the path, remove reference to it from both |
| 2034 | * source and sink widgets so that path is removed only once. |
| 2035 | */ |
| 2036 | list_for_each_entry_safe(p, next_p, &w->sources, list_sink) { |
| 2037 | list_del(&p->list_sink); |
| 2038 | list_del(&p->list_source); |
| 2039 | list_del(&p->list); |
| 2040 | kfree(p->long_name); |
| 2041 | kfree(p); |
| 2042 | } |
| 2043 | list_for_each_entry_safe(p, next_p, &w->sinks, list_source) { |
| 2044 | list_del(&p->list_sink); |
| 2045 | list_del(&p->list_source); |
| 2046 | list_del(&p->list); |
| 2047 | kfree(p->long_name); |
| 2048 | kfree(p); |
| 2049 | } |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 2050 | kfree(w->kcontrols); |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2051 | kfree(w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2052 | kfree(w); |
| 2053 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2054 | } |
| 2055 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2056 | static struct snd_soc_dapm_widget *dapm_find_widget( |
| 2057 | struct snd_soc_dapm_context *dapm, const char *pin, |
| 2058 | bool search_other_contexts) |
| 2059 | { |
| 2060 | struct snd_soc_dapm_widget *w; |
| 2061 | struct snd_soc_dapm_widget *fallback = NULL; |
| 2062 | |
| 2063 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 2064 | if (!strcmp(w->name, pin)) { |
| 2065 | if (w->dapm == dapm) |
| 2066 | return w; |
| 2067 | else |
| 2068 | fallback = w; |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | if (search_other_contexts) |
| 2073 | return fallback; |
| 2074 | |
| 2075 | return NULL; |
| 2076 | } |
| 2077 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2078 | 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] | 2079 | const char *pin, int status) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2080 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2081 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2082 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2083 | if (!w) { |
| 2084 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 2085 | return -EINVAL; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2086 | } |
| 2087 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2088 | w->connected = status; |
| 2089 | if (status == 0) |
| 2090 | w->force = 0; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2091 | dapm_mark_dirty(w, "pin configuration"); |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 2092 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2093 | return 0; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2094 | } |
| 2095 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2096 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2097 | * snd_soc_dapm_sync - scan and power dapm paths |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2098 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2099 | * |
| 2100 | * Walks all dapm audio paths and powers widgets according to their |
| 2101 | * stream or path usage. |
| 2102 | * |
| 2103 | * Returns 0 for success. |
| 2104 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2105 | int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2106 | { |
Mark Brown | 4f4c007 | 2011-10-07 14:29:19 +0100 | [diff] [blame] | 2107 | /* |
| 2108 | * Suppress early reports (eg, jacks syncing their state) to avoid |
| 2109 | * silly DAPM runs during card startup. |
| 2110 | */ |
| 2111 | if (!dapm->card || !dapm->card->instantiated) |
| 2112 | return 0; |
| 2113 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2114 | return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2115 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2116 | EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2117 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2118 | 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] | 2119 | const struct snd_soc_dapm_route *route) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2120 | { |
| 2121 | struct snd_soc_dapm_path *path; |
| 2122 | struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w; |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2123 | struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2124 | const char *sink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 2125 | const char *control = route->control; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2126 | const char *source; |
| 2127 | char prefixed_sink[80]; |
| 2128 | char prefixed_source[80]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2129 | int ret = 0; |
| 2130 | |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 2131 | if (dapm->codec && dapm->codec->name_prefix) { |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2132 | snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s", |
| 2133 | dapm->codec->name_prefix, route->sink); |
| 2134 | sink = prefixed_sink; |
| 2135 | snprintf(prefixed_source, sizeof(prefixed_source), "%s %s", |
| 2136 | dapm->codec->name_prefix, route->source); |
| 2137 | source = prefixed_source; |
| 2138 | } else { |
| 2139 | sink = route->sink; |
| 2140 | source = route->source; |
| 2141 | } |
| 2142 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2143 | /* |
| 2144 | * find src and dest widgets over all widgets but favor a widget from |
| 2145 | * current DAPM context |
| 2146 | */ |
| 2147 | list_for_each_entry(w, &dapm->card->widgets, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2148 | if (!wsink && !(strcmp(w->name, sink))) { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2149 | wtsink = w; |
| 2150 | if (w->dapm == dapm) |
| 2151 | wsink = w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2152 | continue; |
| 2153 | } |
| 2154 | if (!wsource && !(strcmp(w->name, source))) { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2155 | wtsource = w; |
| 2156 | if (w->dapm == dapm) |
| 2157 | wsource = w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2158 | } |
| 2159 | } |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2160 | /* use widget from another DAPM context if not found from this */ |
| 2161 | if (!wsink) |
| 2162 | wsink = wtsink; |
| 2163 | if (!wsource) |
| 2164 | wsource = wtsource; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2165 | |
| 2166 | if (wsource == NULL || wsink == NULL) |
| 2167 | return -ENODEV; |
| 2168 | |
| 2169 | path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL); |
| 2170 | if (!path) |
| 2171 | return -ENOMEM; |
| 2172 | |
| 2173 | path->source = wsource; |
| 2174 | path->sink = wsink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 2175 | path->connected = route->connected; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2176 | INIT_LIST_HEAD(&path->list); |
| 2177 | INIT_LIST_HEAD(&path->list_source); |
| 2178 | INIT_LIST_HEAD(&path->list_sink); |
| 2179 | |
| 2180 | /* check for external widgets */ |
| 2181 | if (wsink->id == snd_soc_dapm_input) { |
| 2182 | if (wsource->id == snd_soc_dapm_micbias || |
| 2183 | wsource->id == snd_soc_dapm_mic || |
Rongrong Cao | 087d53a | 2009-07-10 20:13:30 +0100 | [diff] [blame] | 2184 | wsource->id == snd_soc_dapm_line || |
| 2185 | wsource->id == snd_soc_dapm_output) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2186 | wsink->ext = 1; |
| 2187 | } |
| 2188 | if (wsource->id == snd_soc_dapm_output) { |
| 2189 | if (wsink->id == snd_soc_dapm_spk || |
| 2190 | wsink->id == snd_soc_dapm_hp || |
Seth Forshee | 1e39221 | 2007-04-16 15:36:42 +0200 | [diff] [blame] | 2191 | wsink->id == snd_soc_dapm_line || |
| 2192 | wsink->id == snd_soc_dapm_input) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2193 | wsource->ext = 1; |
| 2194 | } |
| 2195 | |
| 2196 | /* connect static paths */ |
| 2197 | if (control == NULL) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 2198 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2199 | list_add(&path->list_sink, &wsink->sources); |
| 2200 | list_add(&path->list_source, &wsource->sinks); |
| 2201 | path->connect = 1; |
| 2202 | return 0; |
| 2203 | } |
| 2204 | |
| 2205 | /* connect dynamic paths */ |
Lu Guanqun | dc2bea6 | 2011-04-20 16:00:36 +0800 | [diff] [blame] | 2206 | switch (wsink->id) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2207 | case snd_soc_dapm_adc: |
| 2208 | case snd_soc_dapm_dac: |
| 2209 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 2210 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2211 | case snd_soc_dapm_input: |
| 2212 | case snd_soc_dapm_output: |
Mark Brown | 1ab97c8 | 2011-11-27 16:21:51 +0000 | [diff] [blame] | 2213 | case snd_soc_dapm_siggen: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2214 | case snd_soc_dapm_micbias: |
| 2215 | case snd_soc_dapm_vmid: |
| 2216 | case snd_soc_dapm_pre: |
| 2217 | case snd_soc_dapm_post: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 2218 | case snd_soc_dapm_supply: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 2219 | case snd_soc_dapm_aif_in: |
| 2220 | case snd_soc_dapm_aif_out: |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 2221 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2222 | list_add(&path->list_sink, &wsink->sources); |
| 2223 | list_add(&path->list_source, &wsource->sinks); |
| 2224 | path->connect = 1; |
| 2225 | return 0; |
| 2226 | case snd_soc_dapm_mux: |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 2227 | case snd_soc_dapm_virt_mux: |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2228 | case snd_soc_dapm_value_mux: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2229 | ret = dapm_connect_mux(dapm, wsource, wsink, path, control, |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 2230 | &wsink->kcontrol_news[0]); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2231 | if (ret != 0) |
| 2232 | goto err; |
| 2233 | break; |
| 2234 | case snd_soc_dapm_switch: |
| 2235 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 2236 | case snd_soc_dapm_mixer_named_ctl: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2237 | ret = dapm_connect_mixer(dapm, wsource, wsink, path, control); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2238 | if (ret != 0) |
| 2239 | goto err; |
| 2240 | break; |
| 2241 | case snd_soc_dapm_hp: |
| 2242 | case snd_soc_dapm_mic: |
| 2243 | case snd_soc_dapm_line: |
| 2244 | case snd_soc_dapm_spk: |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 2245 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2246 | list_add(&path->list_sink, &wsink->sources); |
| 2247 | list_add(&path->list_source, &wsource->sinks); |
| 2248 | path->connect = 0; |
| 2249 | return 0; |
| 2250 | } |
| 2251 | return 0; |
| 2252 | |
| 2253 | err: |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2254 | dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n", |
| 2255 | source, control, sink); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2256 | kfree(path); |
| 2257 | return ret; |
| 2258 | } |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2259 | |
| 2260 | /** |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2261 | * snd_soc_dapm_add_routes - Add routes between DAPM widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2262 | * @dapm: DAPM context |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2263 | * @route: audio routes |
| 2264 | * @num: number of routes |
| 2265 | * |
| 2266 | * Connects 2 dapm widgets together via a named audio path. The sink is |
| 2267 | * the widget receiving the audio signal, whilst the source is the sender |
| 2268 | * of the audio signal. |
| 2269 | * |
| 2270 | * Returns 0 for success else error. On error all resources can be freed |
| 2271 | * with a call to snd_soc_card_free(). |
| 2272 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2273 | int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm, |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2274 | const struct snd_soc_dapm_route *route, int num) |
| 2275 | { |
| 2276 | int i, ret; |
| 2277 | |
| 2278 | for (i = 0; i < num; i++) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2279 | ret = snd_soc_dapm_add_route(dapm, route); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2280 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2281 | dev_err(dapm->dev, "Failed to add route %s->%s\n", |
| 2282 | route->source, route->sink); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2283 | return ret; |
| 2284 | } |
| 2285 | route++; |
| 2286 | } |
| 2287 | |
| 2288 | return 0; |
| 2289 | } |
| 2290 | EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes); |
| 2291 | |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 2292 | static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm, |
| 2293 | const struct snd_soc_dapm_route *route) |
| 2294 | { |
| 2295 | struct snd_soc_dapm_widget *source = dapm_find_widget(dapm, |
| 2296 | route->source, |
| 2297 | true); |
| 2298 | struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm, |
| 2299 | route->sink, |
| 2300 | true); |
| 2301 | struct snd_soc_dapm_path *path; |
| 2302 | int count = 0; |
| 2303 | |
| 2304 | if (!source) { |
| 2305 | dev_err(dapm->dev, "Unable to find source %s for weak route\n", |
| 2306 | route->source); |
| 2307 | return -ENODEV; |
| 2308 | } |
| 2309 | |
| 2310 | if (!sink) { |
| 2311 | dev_err(dapm->dev, "Unable to find sink %s for weak route\n", |
| 2312 | route->sink); |
| 2313 | return -ENODEV; |
| 2314 | } |
| 2315 | |
| 2316 | if (route->control || route->connected) |
| 2317 | dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n", |
| 2318 | route->source, route->sink); |
| 2319 | |
| 2320 | list_for_each_entry(path, &source->sinks, list_source) { |
| 2321 | if (path->sink == sink) { |
| 2322 | path->weak = 1; |
| 2323 | count++; |
| 2324 | } |
| 2325 | } |
| 2326 | |
| 2327 | if (count == 0) |
| 2328 | dev_err(dapm->dev, "No path found for weak route %s->%s\n", |
| 2329 | route->source, route->sink); |
| 2330 | if (count > 1) |
| 2331 | dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n", |
| 2332 | count, route->source, route->sink); |
| 2333 | |
| 2334 | return 0; |
| 2335 | } |
| 2336 | |
| 2337 | /** |
| 2338 | * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak |
| 2339 | * @dapm: DAPM context |
| 2340 | * @route: audio routes |
| 2341 | * @num: number of routes |
| 2342 | * |
| 2343 | * Mark existing routes matching those specified in the passed array |
| 2344 | * as being weak, meaning that they are ignored for the purpose of |
| 2345 | * power decisions. The main intended use case is for sidetone paths |
| 2346 | * which couple audio between other independent paths if they are both |
| 2347 | * active in order to make the combination work better at the user |
| 2348 | * level but which aren't intended to be "used". |
| 2349 | * |
| 2350 | * Note that CODEC drivers should not use this as sidetone type paths |
| 2351 | * can frequently also be used as bypass paths. |
| 2352 | */ |
| 2353 | int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm, |
| 2354 | const struct snd_soc_dapm_route *route, int num) |
| 2355 | { |
| 2356 | int i, err; |
| 2357 | int ret = 0; |
| 2358 | |
| 2359 | for (i = 0; i < num; i++) { |
| 2360 | err = snd_soc_dapm_weak_route(dapm, route); |
| 2361 | if (err) |
| 2362 | ret = err; |
| 2363 | route++; |
| 2364 | } |
| 2365 | |
| 2366 | return ret; |
| 2367 | } |
| 2368 | EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes); |
| 2369 | |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 2370 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2371 | * snd_soc_dapm_new_widgets - add new dapm widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2372 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2373 | * |
| 2374 | * Checks the codec for any new dapm widgets and creates them if found. |
| 2375 | * |
| 2376 | * Returns 0 for success. |
| 2377 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2378 | int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2379 | { |
| 2380 | struct snd_soc_dapm_widget *w; |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2381 | unsigned int val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2382 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2383 | list_for_each_entry(w, &dapm->card->widgets, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2384 | { |
| 2385 | if (w->new) |
| 2386 | continue; |
| 2387 | |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 2388 | if (w->num_kcontrols) { |
| 2389 | w->kcontrols = kzalloc(w->num_kcontrols * |
| 2390 | sizeof(struct snd_kcontrol *), |
| 2391 | GFP_KERNEL); |
| 2392 | if (!w->kcontrols) |
| 2393 | return -ENOMEM; |
| 2394 | } |
| 2395 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2396 | switch(w->id) { |
| 2397 | case snd_soc_dapm_switch: |
| 2398 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 2399 | case snd_soc_dapm_mixer_named_ctl: |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2400 | dapm_new_mixer(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2401 | break; |
| 2402 | case snd_soc_dapm_mux: |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 2403 | case snd_soc_dapm_virt_mux: |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2404 | case snd_soc_dapm_value_mux: |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2405 | dapm_new_mux(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2406 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2407 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 2408 | case snd_soc_dapm_out_drv: |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 2409 | dapm_new_pga(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2410 | break; |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 2411 | default: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2412 | break; |
| 2413 | } |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2414 | |
| 2415 | /* Read the initial power state from the device */ |
| 2416 | if (w->reg >= 0) { |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame] | 2417 | val = soc_widget_read(w, w->reg); |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2418 | val &= 1 << w->shift; |
| 2419 | if (w->invert) |
| 2420 | val = !val; |
| 2421 | |
| 2422 | if (val) |
| 2423 | w->power = 1; |
| 2424 | } |
| 2425 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2426 | w->new = 1; |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 2427 | |
Mark Brown | 7508b12 | 2011-10-05 12:09:12 +0100 | [diff] [blame] | 2428 | dapm_mark_dirty(w, "new widget"); |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 2429 | dapm_debugfs_add_widget(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2430 | } |
| 2431 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2432 | dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2433 | return 0; |
| 2434 | } |
| 2435 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); |
| 2436 | |
| 2437 | /** |
| 2438 | * snd_soc_dapm_get_volsw - dapm mixer get callback |
| 2439 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2440 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2441 | * |
| 2442 | * Callback to get the value of a dapm mixer control. |
| 2443 | * |
| 2444 | * Returns 0 for success. |
| 2445 | */ |
| 2446 | int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, |
| 2447 | struct snd_ctl_elem_value *ucontrol) |
| 2448 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2449 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2450 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2451 | struct soc_mixer_control *mc = |
| 2452 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2453 | unsigned int reg = mc->reg; |
| 2454 | unsigned int shift = mc->shift; |
| 2455 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2456 | int max = mc->max; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2457 | unsigned int invert = mc->invert; |
| 2458 | unsigned int mask = (1 << fls(max)) - 1; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2459 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2460 | ucontrol->value.integer.value[0] = |
| 2461 | (snd_soc_read(widget->codec, reg) >> shift) & mask; |
| 2462 | if (shift != rshift) |
| 2463 | ucontrol->value.integer.value[1] = |
| 2464 | (snd_soc_read(widget->codec, reg) >> rshift) & mask; |
| 2465 | if (invert) { |
| 2466 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2467 | max - ucontrol->value.integer.value[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2468 | if (shift != rshift) |
| 2469 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2470 | max - ucontrol->value.integer.value[1]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | return 0; |
| 2474 | } |
| 2475 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw); |
| 2476 | |
| 2477 | /** |
| 2478 | * snd_soc_dapm_put_volsw - dapm mixer set callback |
| 2479 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2480 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2481 | * |
| 2482 | * Callback to set the value of a dapm mixer control. |
| 2483 | * |
| 2484 | * Returns 0 for success. |
| 2485 | */ |
| 2486 | int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, |
| 2487 | struct snd_ctl_elem_value *ucontrol) |
| 2488 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2489 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2490 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2491 | struct snd_soc_codec *codec = widget->codec; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2492 | struct soc_mixer_control *mc = |
| 2493 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2494 | unsigned int reg = mc->reg; |
| 2495 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2496 | int max = mc->max; |
Jon Smirl | 815ecf8 | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2497 | unsigned int mask = (1 << fls(max)) - 1; |
| 2498 | unsigned int invert = mc->invert; |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2499 | unsigned int val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2500 | int connect, change; |
| 2501 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2502 | int wi; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2503 | |
| 2504 | val = (ucontrol->value.integer.value[0] & mask); |
| 2505 | |
| 2506 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2507 | val = max - val; |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2508 | mask = mask << shift; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2509 | val = val << shift; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2510 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2511 | if (val) |
| 2512 | /* new connection */ |
| 2513 | connect = invert ? 0 : 1; |
| 2514 | else |
| 2515 | /* old connection must be powered down */ |
| 2516 | connect = invert ? 1 : 0; |
| 2517 | |
| 2518 | mutex_lock(&codec->mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2519 | |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2520 | change = snd_soc_test_bits(widget->codec, reg, mask, val); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2521 | if (change) { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2522 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2523 | widget = wlist->widgets[wi]; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 2524 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2525 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2526 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2527 | update.kcontrol = kcontrol; |
| 2528 | update.widget = widget; |
| 2529 | update.reg = reg; |
| 2530 | update.mask = mask; |
| 2531 | update.val = val; |
| 2532 | widget->dapm->update = &update; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2533 | |
Liam Girdwood | 40f02cd | 2012-02-06 16:05:14 +0000 | [diff] [blame] | 2534 | snd_soc_dapm_mixer_update_power(widget, kcontrol, connect); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2535 | |
| 2536 | widget->dapm->update = NULL; |
| 2537 | } |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2540 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2541 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2542 | } |
| 2543 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); |
| 2544 | |
| 2545 | /** |
| 2546 | * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback |
| 2547 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2548 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2549 | * |
| 2550 | * Callback to get the value of a dapm enumerated double mixer control. |
| 2551 | * |
| 2552 | * Returns 0 for success. |
| 2553 | */ |
| 2554 | int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, |
| 2555 | struct snd_ctl_elem_value *ucontrol) |
| 2556 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2557 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2558 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2559 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2560 | unsigned int val, bitmask; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2561 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2562 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2563 | ; |
| 2564 | val = snd_soc_read(widget->codec, e->reg); |
| 2565 | ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1); |
| 2566 | if (e->shift_l != e->shift_r) |
| 2567 | ucontrol->value.enumerated.item[1] = |
| 2568 | (val >> e->shift_r) & (bitmask - 1); |
| 2569 | |
| 2570 | return 0; |
| 2571 | } |
| 2572 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double); |
| 2573 | |
| 2574 | /** |
| 2575 | * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback |
| 2576 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2577 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2578 | * |
| 2579 | * Callback to set the value of a dapm enumerated double mixer control. |
| 2580 | * |
| 2581 | * Returns 0 for success. |
| 2582 | */ |
| 2583 | int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, |
| 2584 | struct snd_ctl_elem_value *ucontrol) |
| 2585 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2586 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2587 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2588 | struct snd_soc_codec *codec = widget->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2589 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2590 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2591 | unsigned int mask, bitmask; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2592 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2593 | int wi; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2594 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2595 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2596 | ; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2597 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2598 | return -EINVAL; |
| 2599 | mux = ucontrol->value.enumerated.item[0]; |
| 2600 | val = mux << e->shift_l; |
| 2601 | mask = (bitmask - 1) << e->shift_l; |
| 2602 | if (e->shift_l != e->shift_r) { |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2603 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2604 | return -EINVAL; |
| 2605 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; |
| 2606 | mask |= (bitmask - 1) << e->shift_r; |
| 2607 | } |
| 2608 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2609 | mutex_lock(&codec->mutex); |
| 2610 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2611 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2612 | if (change) { |
| 2613 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2614 | widget = wlist->widgets[wi]; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2615 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2616 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2617 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2618 | update.kcontrol = kcontrol; |
| 2619 | update.widget = widget; |
| 2620 | update.reg = e->reg; |
| 2621 | update.mask = mask; |
| 2622 | update.val = val; |
| 2623 | widget->dapm->update = &update; |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2624 | |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 2625 | snd_soc_dapm_mux_update_power(widget, kcontrol, change, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2626 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2627 | widget->dapm->update = NULL; |
| 2628 | } |
| 2629 | } |
| 2630 | |
| 2631 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2632 | return change; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2633 | } |
| 2634 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); |
| 2635 | |
| 2636 | /** |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2637 | * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux |
| 2638 | * @kcontrol: mixer control |
| 2639 | * @ucontrol: control element information |
| 2640 | * |
| 2641 | * Returns 0 for success. |
| 2642 | */ |
| 2643 | int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol, |
| 2644 | struct snd_ctl_elem_value *ucontrol) |
| 2645 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2646 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2647 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2648 | |
| 2649 | ucontrol->value.enumerated.item[0] = widget->value; |
| 2650 | |
| 2651 | return 0; |
| 2652 | } |
| 2653 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt); |
| 2654 | |
| 2655 | /** |
| 2656 | * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux |
| 2657 | * @kcontrol: mixer control |
| 2658 | * @ucontrol: control element information |
| 2659 | * |
| 2660 | * Returns 0 for success. |
| 2661 | */ |
| 2662 | int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol, |
| 2663 | struct snd_ctl_elem_value *ucontrol) |
| 2664 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2665 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2666 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2667 | struct snd_soc_codec *codec = widget->codec; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2668 | struct soc_enum *e = |
| 2669 | (struct soc_enum *)kcontrol->private_value; |
| 2670 | int change; |
| 2671 | int ret = 0; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2672 | int wi; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2673 | |
| 2674 | if (ucontrol->value.enumerated.item[0] >= e->max) |
| 2675 | return -EINVAL; |
| 2676 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2677 | mutex_lock(&codec->mutex); |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2678 | |
| 2679 | change = widget->value != ucontrol->value.enumerated.item[0]; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2680 | if (change) { |
| 2681 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2682 | widget = wlist->widgets[wi]; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2683 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2684 | widget->value = ucontrol->value.enumerated.item[0]; |
| 2685 | |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 2686 | snd_soc_dapm_mux_update_power(widget, kcontrol, change, |
| 2687 | widget->value, e); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2688 | } |
| 2689 | } |
| 2690 | |
| 2691 | mutex_unlock(&codec->mutex); |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2692 | return ret; |
| 2693 | } |
| 2694 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt); |
| 2695 | |
| 2696 | /** |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2697 | * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get |
| 2698 | * callback |
| 2699 | * @kcontrol: mixer control |
| 2700 | * @ucontrol: control element information |
| 2701 | * |
| 2702 | * Callback to get the value of a dapm semi enumerated double mixer control. |
| 2703 | * |
| 2704 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2705 | * used for handling bitfield coded enumeration for example. |
| 2706 | * |
| 2707 | * Returns 0 for success. |
| 2708 | */ |
| 2709 | int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2710 | struct snd_ctl_elem_value *ucontrol) |
| 2711 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2712 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2713 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2714 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2715 | unsigned int reg_val, val, mux; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2716 | |
| 2717 | reg_val = snd_soc_read(widget->codec, e->reg); |
| 2718 | val = (reg_val >> e->shift_l) & e->mask; |
| 2719 | for (mux = 0; mux < e->max; mux++) { |
| 2720 | if (val == e->values[mux]) |
| 2721 | break; |
| 2722 | } |
| 2723 | ucontrol->value.enumerated.item[0] = mux; |
| 2724 | if (e->shift_l != e->shift_r) { |
| 2725 | val = (reg_val >> e->shift_r) & e->mask; |
| 2726 | for (mux = 0; mux < e->max; mux++) { |
| 2727 | if (val == e->values[mux]) |
| 2728 | break; |
| 2729 | } |
| 2730 | ucontrol->value.enumerated.item[1] = mux; |
| 2731 | } |
| 2732 | |
| 2733 | return 0; |
| 2734 | } |
| 2735 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double); |
| 2736 | |
| 2737 | /** |
| 2738 | * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set |
| 2739 | * callback |
| 2740 | * @kcontrol: mixer control |
| 2741 | * @ucontrol: control element information |
| 2742 | * |
| 2743 | * Callback to set the value of a dapm semi enumerated double mixer control. |
| 2744 | * |
| 2745 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2746 | * used for handling bitfield coded enumeration for example. |
| 2747 | * |
| 2748 | * Returns 0 for success. |
| 2749 | */ |
| 2750 | int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2751 | struct snd_ctl_elem_value *ucontrol) |
| 2752 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2753 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2754 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2755 | struct snd_soc_codec *codec = widget->codec; |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2756 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2757 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2758 | unsigned int mask; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2759 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2760 | int wi; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2761 | |
| 2762 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 2763 | return -EINVAL; |
| 2764 | mux = ucontrol->value.enumerated.item[0]; |
| 2765 | val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; |
| 2766 | mask = e->mask << e->shift_l; |
| 2767 | if (e->shift_l != e->shift_r) { |
| 2768 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
| 2769 | return -EINVAL; |
| 2770 | val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; |
| 2771 | mask |= e->mask << e->shift_r; |
| 2772 | } |
| 2773 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2774 | mutex_lock(&codec->mutex); |
| 2775 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2776 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2777 | if (change) { |
| 2778 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2779 | widget = wlist->widgets[wi]; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2780 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2781 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2782 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2783 | update.kcontrol = kcontrol; |
| 2784 | update.widget = widget; |
| 2785 | update.reg = e->reg; |
| 2786 | update.mask = mask; |
| 2787 | update.val = val; |
| 2788 | widget->dapm->update = &update; |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2789 | |
Liam Girdwood | e002c98 | 2011-02-08 11:45:20 +0000 | [diff] [blame] | 2790 | snd_soc_dapm_mux_update_power(widget, kcontrol, change, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2791 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2792 | widget->dapm->update = NULL; |
| 2793 | } |
| 2794 | } |
| 2795 | |
| 2796 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2797 | return change; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2798 | } |
| 2799 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); |
| 2800 | |
| 2801 | /** |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2802 | * snd_soc_dapm_info_pin_switch - Info for a pin switch |
| 2803 | * |
| 2804 | * @kcontrol: mixer control |
| 2805 | * @uinfo: control element information |
| 2806 | * |
| 2807 | * Callback to provide information about a pin switch control. |
| 2808 | */ |
| 2809 | int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol, |
| 2810 | struct snd_ctl_elem_info *uinfo) |
| 2811 | { |
| 2812 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2813 | uinfo->count = 1; |
| 2814 | uinfo->value.integer.min = 0; |
| 2815 | uinfo->value.integer.max = 1; |
| 2816 | |
| 2817 | return 0; |
| 2818 | } |
| 2819 | EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch); |
| 2820 | |
| 2821 | /** |
| 2822 | * snd_soc_dapm_get_pin_switch - Get information for a pin switch |
| 2823 | * |
| 2824 | * @kcontrol: mixer control |
| 2825 | * @ucontrol: Value |
| 2826 | */ |
| 2827 | int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol, |
| 2828 | struct snd_ctl_elem_value *ucontrol) |
| 2829 | { |
| 2830 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2831 | const char *pin = (const char *)kcontrol->private_value; |
| 2832 | |
| 2833 | mutex_lock(&codec->mutex); |
| 2834 | |
| 2835 | ucontrol->value.integer.value[0] = |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2836 | snd_soc_dapm_get_pin_status(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2837 | |
| 2838 | mutex_unlock(&codec->mutex); |
| 2839 | |
| 2840 | return 0; |
| 2841 | } |
| 2842 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch); |
| 2843 | |
| 2844 | /** |
| 2845 | * snd_soc_dapm_put_pin_switch - Set information for a pin switch |
| 2846 | * |
| 2847 | * @kcontrol: mixer control |
| 2848 | * @ucontrol: Value |
| 2849 | */ |
| 2850 | int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol, |
| 2851 | struct snd_ctl_elem_value *ucontrol) |
| 2852 | { |
| 2853 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2854 | const char *pin = (const char *)kcontrol->private_value; |
| 2855 | |
| 2856 | mutex_lock(&codec->mutex); |
| 2857 | |
| 2858 | if (ucontrol->value.integer.value[0]) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2859 | snd_soc_dapm_enable_pin(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2860 | else |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2861 | snd_soc_dapm_disable_pin(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2862 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2863 | snd_soc_dapm_sync(&codec->dapm); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2864 | |
| 2865 | mutex_unlock(&codec->mutex); |
| 2866 | |
| 2867 | return 0; |
| 2868 | } |
| 2869 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch); |
| 2870 | |
| 2871 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2872 | * snd_soc_dapm_new_control - create new dapm control |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2873 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2874 | * @widget: widget template |
| 2875 | * |
| 2876 | * Creates a new dapm control based upon the template. |
| 2877 | * |
| 2878 | * Returns 0 for success else error. |
| 2879 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2880 | int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2881 | const struct snd_soc_dapm_widget *widget) |
| 2882 | { |
| 2883 | struct snd_soc_dapm_widget *w; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2884 | size_t name_len; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2885 | |
| 2886 | if ((w = dapm_cnew_widget(widget)) == NULL) |
| 2887 | return -ENOMEM; |
| 2888 | |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2889 | name_len = strlen(widget->name) + 1; |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 2890 | if (dapm->codec && dapm->codec->name_prefix) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2891 | name_len += 1 + strlen(dapm->codec->name_prefix); |
| 2892 | w->name = kmalloc(name_len, GFP_KERNEL); |
| 2893 | if (w->name == NULL) { |
| 2894 | kfree(w); |
| 2895 | return -ENOMEM; |
| 2896 | } |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 2897 | if (dapm->codec && dapm->codec->name_prefix) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2898 | snprintf(w->name, name_len, "%s %s", |
| 2899 | dapm->codec->name_prefix, widget->name); |
| 2900 | else |
| 2901 | snprintf(w->name, name_len, "%s", widget->name); |
| 2902 | |
Mark Brown | 7ca3a18 | 2011-10-08 14:04:50 +0100 | [diff] [blame] | 2903 | switch (w->id) { |
| 2904 | case snd_soc_dapm_switch: |
| 2905 | case snd_soc_dapm_mixer: |
| 2906 | case snd_soc_dapm_mixer_named_ctl: |
| 2907 | w->power_check = dapm_generic_check_power; |
| 2908 | break; |
| 2909 | case snd_soc_dapm_mux: |
| 2910 | case snd_soc_dapm_virt_mux: |
| 2911 | case snd_soc_dapm_value_mux: |
| 2912 | w->power_check = dapm_generic_check_power; |
| 2913 | break; |
| 2914 | case snd_soc_dapm_adc: |
| 2915 | case snd_soc_dapm_aif_out: |
| 2916 | w->power_check = dapm_adc_check_power; |
| 2917 | break; |
| 2918 | case snd_soc_dapm_dac: |
| 2919 | case snd_soc_dapm_aif_in: |
| 2920 | w->power_check = dapm_dac_check_power; |
| 2921 | break; |
| 2922 | case snd_soc_dapm_pga: |
| 2923 | case snd_soc_dapm_out_drv: |
| 2924 | case snd_soc_dapm_input: |
| 2925 | case snd_soc_dapm_output: |
| 2926 | case snd_soc_dapm_micbias: |
| 2927 | case snd_soc_dapm_spk: |
| 2928 | case snd_soc_dapm_hp: |
| 2929 | case snd_soc_dapm_mic: |
| 2930 | case snd_soc_dapm_line: |
| 2931 | w->power_check = dapm_generic_check_power; |
| 2932 | break; |
| 2933 | case snd_soc_dapm_supply: |
| 2934 | w->power_check = dapm_supply_check_power; |
| 2935 | break; |
| 2936 | default: |
| 2937 | w->power_check = dapm_always_on_check_power; |
| 2938 | break; |
| 2939 | } |
| 2940 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2941 | dapm->n_widgets++; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2942 | w->dapm = dapm; |
| 2943 | w->codec = dapm->codec; |
Liam Girdwood | b795064 | 2011-07-04 22:10:52 +0100 | [diff] [blame] | 2944 | w->platform = dapm->platform; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2945 | w->dai = dapm->dai; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2946 | INIT_LIST_HEAD(&w->sources); |
| 2947 | INIT_LIST_HEAD(&w->sinks); |
| 2948 | INIT_LIST_HEAD(&w->list); |
Mark Brown | db432b4 | 2011-10-03 21:06:40 +0100 | [diff] [blame] | 2949 | INIT_LIST_HEAD(&w->dirty); |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2950 | list_add(&w->list, &dapm->card->widgets); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2951 | |
| 2952 | /* machine layer set ups unconnected pins and insertions */ |
| 2953 | w->connected = 1; |
| 2954 | return 0; |
| 2955 | } |
| 2956 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control); |
| 2957 | |
| 2958 | /** |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2959 | * snd_soc_dapm_new_controls - create new dapm controls |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2960 | * @dapm: DAPM context |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2961 | * @widget: widget array |
| 2962 | * @num: number of widgets |
| 2963 | * |
| 2964 | * Creates new DAPM controls based upon the templates. |
| 2965 | * |
| 2966 | * Returns 0 for success else error. |
| 2967 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2968 | int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm, |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2969 | const struct snd_soc_dapm_widget *widget, |
| 2970 | int num) |
| 2971 | { |
| 2972 | int i, ret; |
| 2973 | |
| 2974 | for (i = 0; i < num; i++) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2975 | ret = snd_soc_dapm_new_control(dapm, widget); |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 2976 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2977 | dev_err(dapm->dev, |
| 2978 | "ASoC: Failed to create DAPM control %s: %d\n", |
| 2979 | widget->name, ret); |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2980 | return ret; |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 2981 | } |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2982 | widget++; |
| 2983 | } |
| 2984 | return 0; |
| 2985 | } |
| 2986 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); |
| 2987 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2988 | static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2989 | const char *stream, int event) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2990 | { |
| 2991 | struct snd_soc_dapm_widget *w; |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 2992 | |
Liam Girdwood | 13e13a3 | 2011-01-31 21:30:52 +0000 | [diff] [blame] | 2993 | if (!dapm) |
| 2994 | return; |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 2995 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2996 | list_for_each_entry(w, &dapm->card->widgets, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2997 | { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2998 | if (!w->sname || w->dapm != dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2999 | continue; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3000 | 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] | 3001 | w->name, w->sname, stream, event); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3002 | if (strstr(w->sname, stream)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3003 | dapm_mark_dirty(w, "stream event"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3004 | switch(event) { |
| 3005 | case SND_SOC_DAPM_STREAM_START: |
| 3006 | w->active = 1; |
| 3007 | break; |
| 3008 | case SND_SOC_DAPM_STREAM_STOP: |
| 3009 | w->active = 0; |
| 3010 | break; |
| 3011 | case SND_SOC_DAPM_STREAM_SUSPEND: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3012 | case SND_SOC_DAPM_STREAM_RESUME: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3013 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3014 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: |
| 3015 | break; |
| 3016 | } |
| 3017 | } |
| 3018 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3019 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3020 | dapm_power_widgets(dapm, event); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3021 | |
Liam Girdwood | 670ff44 | 2011-03-30 23:27:27 +0100 | [diff] [blame] | 3022 | /* do we need to notify any clients that DAPM stream is complete */ |
| 3023 | if (dapm->stream_event) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3024 | dapm->stream_event(dapm, event); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3025 | } |
| 3026 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3027 | static void widget_stream_event(struct snd_soc_dapm_context *dapm, |
| 3028 | struct snd_soc_dapm_widget *w, int event) |
| 3029 | { |
Mark Brown | fe36068 | 2012-02-16 19:43:20 -0800 | [diff] [blame] | 3030 | if (!w) |
Mark Brown | 7bd3a6f | 2012-02-16 15:03:27 -0800 | [diff] [blame] | 3031 | return; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3032 | |
Mark Brown | fe36068 | 2012-02-16 19:43:20 -0800 | [diff] [blame] | 3033 | dapm_mark_dirty(w, "stream event"); |
| 3034 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3035 | switch(event) { |
Mark Brown | fe36068 | 2012-02-16 19:43:20 -0800 | [diff] [blame] | 3036 | case SND_SOC_DAPM_STREAM_START: |
| 3037 | w->active = 1; |
| 3038 | break; |
| 3039 | case SND_SOC_DAPM_STREAM_STOP: |
| 3040 | w->active = 0; |
| 3041 | break; |
| 3042 | case SND_SOC_DAPM_STREAM_SUSPEND: |
| 3043 | case SND_SOC_DAPM_STREAM_RESUME: |
| 3044 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: |
| 3045 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: |
| 3046 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3047 | } |
| 3048 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3049 | dapm_power_widgets(dapm, event); |
| 3050 | } |
| 3051 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3052 | void snd_soc_dapm_rtd_stream_event(struct snd_soc_pcm_runtime *rtd, |
| 3053 | int stream, int event) |
| 3054 | { |
| 3055 | struct snd_soc_dapm_context *pdapm = &rtd->platform->dapm; |
| 3056 | struct snd_soc_dapm_context *cdapm = &rtd->codec->dapm; |
| 3057 | |
| 3058 | dev_dbg(rtd->dev, "rtd stream %d event %d\n", stream, event); |
| 3059 | |
| 3060 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 3061 | widget_stream_event(pdapm, rtd->cpu_dai->playback_aif, event); |
| 3062 | widget_stream_event(cdapm, rtd->codec_dai->playback_aif, event); |
| 3063 | } else { |
| 3064 | widget_stream_event(pdapm, rtd->cpu_dai->capture_aif, event); |
| 3065 | widget_stream_event(cdapm, rtd->codec_dai->capture_aif, event); |
| 3066 | } |
| 3067 | |
| 3068 | /* do we need to notify any clients that DAPM stream is complete */ |
| 3069 | if (pdapm->stream_event) |
| 3070 | pdapm->stream_event(pdapm, event); |
| 3071 | if (cdapm->stream_event) |
| 3072 | cdapm->stream_event(cdapm, event); |
| 3073 | } |
| 3074 | EXPORT_SYMBOL_GPL(snd_soc_dapm_rtd_stream_event); |
| 3075 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3076 | /** |
| 3077 | * snd_soc_dapm_stream_event - send a stream event to the dapm core |
| 3078 | * @rtd: PCM runtime data |
| 3079 | * @stream: stream name |
| 3080 | * @event: stream event |
| 3081 | * |
| 3082 | * Sends a stream event to the dapm core. The core then makes any |
| 3083 | * necessary widget power changes. |
| 3084 | * |
| 3085 | * Returns 0 for success else error. |
| 3086 | */ |
| 3087 | int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, |
| 3088 | const char *stream, int event) |
| 3089 | { |
| 3090 | struct snd_soc_codec *codec = rtd->codec; |
| 3091 | |
| 3092 | if (stream == NULL) |
| 3093 | return 0; |
Liam Girdwood | ecc1a0d | 2011-02-16 16:24:17 +0000 | [diff] [blame] | 3094 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3095 | //mutex_lock(&codec->mutex); |
| 3096 | soc_dapm_stream_event(&codec->dapm, stream, event); |
| 3097 | //mutex_unlock(&codec->mutex); |
| 3098 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3099 | return 0; |
| 3100 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3101 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3102 | void snd_soc_dapm_codec_stream_event(struct snd_soc_codec *codec, |
| 3103 | const char *stream, int event) |
| 3104 | { |
| 3105 | // mutex_lock(&codec->card->dapm_mutex); |
| 3106 | soc_dapm_stream_event(&codec->dapm, stream, event); |
| 3107 | // mutex_unlock(&codec->card->dapm_mutex); |
| 3108 | } |
| 3109 | EXPORT_SYMBOL(snd_soc_dapm_codec_stream_event); |
| 3110 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3111 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3112 | * snd_soc_dapm_enable_pin - enable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3113 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3114 | * @pin: pin name |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3115 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 3116 | * 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] | 3117 | * a valid audio route and active audio stream. |
| 3118 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 3119 | * do any widget power switching. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3120 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3121 | 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] | 3122 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3123 | return snd_soc_dapm_set_pin(dapm, pin, 1); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3124 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3125 | EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3126 | |
| 3127 | /** |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 3128 | * snd_soc_dapm_force_enable_pin - force a pin to be enabled |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3129 | * @dapm: DAPM context |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 3130 | * @pin: pin name |
| 3131 | * |
| 3132 | * Enables input/output pin regardless of any other state. This is |
| 3133 | * intended for use with microphone bias supplies used in microphone |
| 3134 | * jack detection. |
| 3135 | * |
| 3136 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 3137 | * do any widget power switching. |
| 3138 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3139 | int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm, |
| 3140 | const char *pin) |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 3141 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3142 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 3143 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3144 | if (!w) { |
| 3145 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 3146 | return -EINVAL; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 3147 | } |
| 3148 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3149 | dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin); |
| 3150 | w->connected = 1; |
| 3151 | w->force = 1; |
Mark Brown | 75c1f89 | 2011-10-04 22:28:08 +0100 | [diff] [blame] | 3152 | dapm_mark_dirty(w, "force enable"); |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 3153 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3154 | return 0; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 3155 | } |
| 3156 | EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin); |
| 3157 | |
| 3158 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3159 | * snd_soc_dapm_disable_pin - disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3160 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3161 | * @pin: pin name |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 3162 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 3163 | * Disables input/output pin and its parents or children widgets. |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3164 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 3165 | * do any widget power switching. |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 3166 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3167 | int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm, |
| 3168 | const char *pin) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3169 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3170 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3171 | } |
| 3172 | EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin); |
| 3173 | |
| 3174 | /** |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 3175 | * snd_soc_dapm_nc_pin - permanently disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3176 | * @dapm: DAPM context |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 3177 | * @pin: pin name |
| 3178 | * |
| 3179 | * Marks the specified pin as being not connected, disabling it along |
| 3180 | * any parent or child widgets. At present this is identical to |
| 3181 | * snd_soc_dapm_disable_pin() but in future it will be extended to do |
| 3182 | * additional things such as disabling controls which only affect |
| 3183 | * paths through the pin. |
| 3184 | * |
| 3185 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 3186 | * do any widget power switching. |
| 3187 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3188 | 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] | 3189 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3190 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 3191 | } |
| 3192 | EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin); |
| 3193 | |
| 3194 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3195 | * snd_soc_dapm_get_pin_status - get audio pin status |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3196 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3197 | * @pin: audio signal pin endpoint (or start point) |
| 3198 | * |
| 3199 | * Get audio pin status - connected or disconnected. |
| 3200 | * |
| 3201 | * Returns 1 for connected otherwise 0. |
| 3202 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3203 | int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm, |
| 3204 | const char *pin) |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 3205 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3206 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 3207 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3208 | if (w) |
| 3209 | return w->connected; |
Stephen Warren | a68b38a | 2011-04-19 15:25:11 -0600 | [diff] [blame] | 3210 | |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 3211 | return 0; |
| 3212 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 3213 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 3214 | |
| 3215 | /** |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3216 | * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3217 | * @dapm: DAPM context |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3218 | * @pin: audio signal pin endpoint (or start point) |
| 3219 | * |
| 3220 | * Mark the given endpoint or pin as ignoring suspend. When the |
| 3221 | * system is disabled a path between two endpoints flagged as ignoring |
| 3222 | * suspend will not be disabled. The path must already be enabled via |
| 3223 | * normal means at suspend time, it will not be turned on if it was not |
| 3224 | * already enabled. |
| 3225 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3226 | int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm, |
| 3227 | const char *pin) |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3228 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3229 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3230 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3231 | if (!w) { |
| 3232 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 3233 | return -EINVAL; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3234 | } |
| 3235 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 3236 | w->ignore_suspend = 1; |
| 3237 | |
| 3238 | return 0; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3239 | } |
| 3240 | EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend); |
| 3241 | |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 3242 | static bool snd_soc_dapm_widget_in_card_paths(struct snd_soc_card *card, |
| 3243 | struct snd_soc_dapm_widget *w) |
| 3244 | { |
| 3245 | struct snd_soc_dapm_path *p; |
| 3246 | |
| 3247 | list_for_each_entry(p, &card->paths, list) { |
| 3248 | if ((p->source == w) || (p->sink == w)) { |
| 3249 | dev_dbg(card->dev, |
| 3250 | "... Path %s(id:%d dapm:%p) - %s(id:%d dapm:%p)\n", |
| 3251 | p->source->name, p->source->id, p->source->dapm, |
| 3252 | p->sink->name, p->sink->id, p->sink->dapm); |
| 3253 | |
| 3254 | /* Connected to something other than the codec */ |
| 3255 | if (p->source->dapm != p->sink->dapm) |
| 3256 | return true; |
| 3257 | /* |
| 3258 | * Loopback connection from codec external pin to |
| 3259 | * codec external pin |
| 3260 | */ |
| 3261 | if (p->sink->id == snd_soc_dapm_input) { |
| 3262 | switch (p->source->id) { |
| 3263 | case snd_soc_dapm_output: |
| 3264 | case snd_soc_dapm_micbias: |
| 3265 | return true; |
| 3266 | default: |
| 3267 | break; |
| 3268 | } |
| 3269 | } |
| 3270 | } |
| 3271 | } |
| 3272 | |
| 3273 | return false; |
| 3274 | } |
| 3275 | |
| 3276 | /** |
| 3277 | * snd_soc_dapm_auto_nc_codec_pins - call snd_soc_dapm_nc_pin for unused pins |
| 3278 | * @codec: The codec whose pins should be processed |
| 3279 | * |
| 3280 | * Automatically call snd_soc_dapm_nc_pin() for any external pins in the codec |
| 3281 | * which are unused. Pins are used if they are connected externally to the |
| 3282 | * codec, whether that be to some other device, or a loop-back connection to |
| 3283 | * the codec itself. |
| 3284 | */ |
| 3285 | void snd_soc_dapm_auto_nc_codec_pins(struct snd_soc_codec *codec) |
| 3286 | { |
| 3287 | struct snd_soc_card *card = codec->card; |
| 3288 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
| 3289 | struct snd_soc_dapm_widget *w; |
| 3290 | |
Mark Brown | a094b80 | 2011-11-27 19:42:20 +0000 | [diff] [blame] | 3291 | dev_dbg(codec->dev, "Auto NC: DAPMs: card:%p codec:%p\n", |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 3292 | &card->dapm, &codec->dapm); |
| 3293 | |
| 3294 | list_for_each_entry(w, &card->widgets, list) { |
| 3295 | if (w->dapm != dapm) |
| 3296 | continue; |
| 3297 | switch (w->id) { |
| 3298 | case snd_soc_dapm_input: |
| 3299 | case snd_soc_dapm_output: |
| 3300 | case snd_soc_dapm_micbias: |
Mark Brown | a094b80 | 2011-11-27 19:42:20 +0000 | [diff] [blame] | 3301 | dev_dbg(codec->dev, "Auto NC: Checking widget %s\n", |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 3302 | w->name); |
| 3303 | if (!snd_soc_dapm_widget_in_card_paths(card, w)) { |
Mark Brown | a094b80 | 2011-11-27 19:42:20 +0000 | [diff] [blame] | 3304 | dev_dbg(codec->dev, |
Stephen Warren | 1633281 | 2011-11-23 12:42:04 -0700 | [diff] [blame] | 3305 | "... Not in map; disabling\n"); |
| 3306 | snd_soc_dapm_nc_pin(dapm, w->name); |
| 3307 | } |
| 3308 | break; |
| 3309 | default: |
| 3310 | break; |
| 3311 | } |
| 3312 | } |
| 3313 | } |
| 3314 | |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 3315 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3316 | * snd_soc_dapm_free - free dapm resources |
Peter Ujfalusi | 728a522 | 2011-08-26 16:33:52 +0300 | [diff] [blame] | 3317 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3318 | * |
| 3319 | * Free all dapm widgets and resources. |
| 3320 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3321 | void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3322 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3323 | snd_soc_dapm_sys_remove(dapm->dev); |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 3324 | dapm_debugfs_cleanup(dapm); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3325 | dapm_free_widgets(dapm); |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 3326 | list_del(&dapm->list); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3327 | } |
| 3328 | EXPORT_SYMBOL_GPL(snd_soc_dapm_free); |
| 3329 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3330 | static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3331 | { |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3332 | struct snd_soc_dapm_widget *w; |
| 3333 | LIST_HEAD(down_list); |
| 3334 | int powerdown = 0; |
| 3335 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 3336 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 3337 | if (w->dapm != dapm) |
| 3338 | continue; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3339 | if (w->power) { |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 3340 | dapm_seq_insert(w, &down_list, false); |
Mark Brown | c2caa4d | 2009-06-26 15:36:56 +0100 | [diff] [blame] | 3341 | w->power = 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3342 | powerdown = 1; |
| 3343 | } |
| 3344 | } |
| 3345 | |
| 3346 | /* If there were no widgets to power down we're already in |
| 3347 | * standby. |
| 3348 | */ |
| 3349 | if (powerdown) { |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 3350 | snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE); |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 3351 | dapm_seq_run(dapm, &down_list, 0, false); |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 3352 | snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3353 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3354 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3355 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 3356 | /* |
| 3357 | * snd_soc_dapm_shutdown - callback for system shutdown |
| 3358 | */ |
| 3359 | void snd_soc_dapm_shutdown(struct snd_soc_card *card) |
| 3360 | { |
| 3361 | struct snd_soc_codec *codec; |
| 3362 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3363 | list_for_each_entry(codec, &card->codec_dev_list, list) { |
| 3364 | soc_dapm_shutdown_codec(&codec->dapm); |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 3365 | snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 3366 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 3367 | } |
| 3368 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3369 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 3370 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 3371 | MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC"); |
| 3372 | MODULE_LICENSE("GPL"); |