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