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