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