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