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