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