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