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