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