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