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