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