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