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