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