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