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