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