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