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 |
| 17 | * mic/meadphone insertion events. |
| 18 | * o Automatic Mic Bias support |
| 19 | * o Jack insertion power event initiation - e.g. hp insertion will enable |
| 20 | * sinks, dacs, etc |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 21 | * o Delayed powerdown of audio susbsystem to reduce pops between a quick |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 22 | * device reopen. |
| 23 | * |
| 24 | * Todo: |
| 25 | * o DAPM power change sequencing - allow for configurable per |
| 26 | * codec sequences. |
| 27 | * o Support for analogue bias optimisation. |
| 28 | * o Support for reduced codec oversampling rates. |
| 29 | * o Support for reduced codec bias currents. |
| 30 | */ |
| 31 | |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/moduleparam.h> |
| 34 | #include <linux/init.h> |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 35 | #include <linux/async.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 36 | #include <linux/delay.h> |
| 37 | #include <linux/pm.h> |
| 38 | #include <linux/bitops.h> |
| 39 | #include <linux/platform_device.h> |
| 40 | #include <linux/jiffies.h> |
Takashi Iwai | 20496ff | 2009-08-24 09:40:34 +0200 | [diff] [blame] | 41 | #include <linux/debugfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 42 | #include <linux/slab.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 43 | #include <sound/core.h> |
| 44 | #include <sound/pcm.h> |
| 45 | #include <sound/pcm_params.h> |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 46 | #include <sound/soc.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 47 | #include <sound/initval.h> |
| 48 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 49 | #include <trace/events/asoc.h> |
| 50 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 51 | /* dapm power sequences - make this per codec in the future */ |
| 52 | static int dapm_up_seq[] = { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 53 | [snd_soc_dapm_pre] = 0, |
| 54 | [snd_soc_dapm_supply] = 1, |
| 55 | [snd_soc_dapm_micbias] = 2, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 56 | [snd_soc_dapm_aif_in] = 3, |
| 57 | [snd_soc_dapm_aif_out] = 3, |
| 58 | [snd_soc_dapm_mic] = 4, |
| 59 | [snd_soc_dapm_mux] = 5, |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 60 | [snd_soc_dapm_virt_mux] = 5, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 61 | [snd_soc_dapm_value_mux] = 5, |
| 62 | [snd_soc_dapm_dac] = 6, |
| 63 | [snd_soc_dapm_mixer] = 7, |
| 64 | [snd_soc_dapm_mixer_named_ctl] = 7, |
| 65 | [snd_soc_dapm_pga] = 8, |
| 66 | [snd_soc_dapm_adc] = 9, |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 67 | [snd_soc_dapm_out_drv] = 10, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 68 | [snd_soc_dapm_hp] = 10, |
| 69 | [snd_soc_dapm_spk] = 10, |
| 70 | [snd_soc_dapm_post] = 11, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 71 | }; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 72 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 73 | static int dapm_down_seq[] = { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 74 | [snd_soc_dapm_pre] = 0, |
| 75 | [snd_soc_dapm_adc] = 1, |
| 76 | [snd_soc_dapm_hp] = 2, |
Mark Brown | 1ca0406 | 2009-08-17 16:26:59 +0100 | [diff] [blame] | 77 | [snd_soc_dapm_spk] = 2, |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 78 | [snd_soc_dapm_out_drv] = 2, |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 79 | [snd_soc_dapm_pga] = 4, |
| 80 | [snd_soc_dapm_mixer_named_ctl] = 5, |
Mark Brown | e3d4dab | 2009-06-07 13:08:45 +0100 | [diff] [blame] | 81 | [snd_soc_dapm_mixer] = 5, |
| 82 | [snd_soc_dapm_dac] = 6, |
| 83 | [snd_soc_dapm_mic] = 7, |
| 84 | [snd_soc_dapm_micbias] = 8, |
| 85 | [snd_soc_dapm_mux] = 9, |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 86 | [snd_soc_dapm_virt_mux] = 9, |
Mark Brown | e3d4dab | 2009-06-07 13:08:45 +0100 | [diff] [blame] | 87 | [snd_soc_dapm_value_mux] = 9, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 88 | [snd_soc_dapm_aif_in] = 10, |
| 89 | [snd_soc_dapm_aif_out] = 10, |
| 90 | [snd_soc_dapm_supply] = 11, |
| 91 | [snd_soc_dapm_post] = 12, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 92 | }; |
| 93 | |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 94 | static void pop_wait(u32 pop_time) |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 95 | { |
| 96 | if (pop_time) |
| 97 | schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time)); |
| 98 | } |
| 99 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 100 | 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] | 101 | { |
| 102 | va_list args; |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 103 | char *buf; |
| 104 | |
| 105 | if (!pop_time) |
| 106 | return; |
| 107 | |
| 108 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 109 | if (buf == NULL) |
| 110 | return; |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 111 | |
| 112 | va_start(args, fmt); |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 113 | vsnprintf(buf, PAGE_SIZE, fmt, args); |
Takashi Iwai | 9d01df0 | 2010-12-22 14:08:40 +0100 | [diff] [blame] | 114 | dev_info(dev, "%s", buf); |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 115 | va_end(args); |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 116 | |
| 117 | kfree(buf); |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 120 | /* create a new dapm widget */ |
Takashi Iwai | 88cb429 | 2007-02-05 14:56:20 +0100 | [diff] [blame] | 121 | static inline struct snd_soc_dapm_widget *dapm_cnew_widget( |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 122 | const struct snd_soc_dapm_widget *_widget) |
| 123 | { |
Takashi Iwai | 88cb429 | 2007-02-05 14:56:20 +0100 | [diff] [blame] | 124 | return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 125 | } |
| 126 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 127 | /** |
| 128 | * 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] | 129 | * @dapm: DAPM context |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 130 | * @level: level to configure |
| 131 | * |
| 132 | * Configure the bias (power) levels for the SoC audio device. |
| 133 | * |
| 134 | * Returns 0 for success else error. |
| 135 | */ |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 136 | 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] | 137 | enum snd_soc_bias_level level) |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 138 | { |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 139 | struct snd_soc_card *card = dapm->card; |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 140 | int ret = 0; |
| 141 | |
Mark Brown | f83fba8 | 2009-05-18 15:44:43 +0100 | [diff] [blame] | 142 | switch (level) { |
| 143 | case SND_SOC_BIAS_ON: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 144 | dev_dbg(dapm->dev, "Setting full bias\n"); |
Mark Brown | f83fba8 | 2009-05-18 15:44:43 +0100 | [diff] [blame] | 145 | break; |
| 146 | case SND_SOC_BIAS_PREPARE: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 147 | dev_dbg(dapm->dev, "Setting bias prepare\n"); |
Mark Brown | f83fba8 | 2009-05-18 15:44:43 +0100 | [diff] [blame] | 148 | break; |
| 149 | case SND_SOC_BIAS_STANDBY: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 150 | dev_dbg(dapm->dev, "Setting standby bias\n"); |
Mark Brown | f83fba8 | 2009-05-18 15:44:43 +0100 | [diff] [blame] | 151 | break; |
| 152 | case SND_SOC_BIAS_OFF: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 153 | dev_dbg(dapm->dev, "Setting bias off\n"); |
Mark Brown | f83fba8 | 2009-05-18 15:44:43 +0100 | [diff] [blame] | 154 | break; |
| 155 | default: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 156 | dev_err(dapm->dev, "Setting invalid bias %d\n", level); |
Mark Brown | f83fba8 | 2009-05-18 15:44:43 +0100 | [diff] [blame] | 157 | return -EINVAL; |
| 158 | } |
| 159 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 160 | trace_snd_soc_bias_level_start(card, level); |
| 161 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 162 | if (card && card->set_bias_level) |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 163 | ret = card->set_bias_level(card, level); |
Mark Brown | 474e09c | 2009-08-19 14:18:53 +0100 | [diff] [blame] | 164 | if (ret == 0) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 165 | if (dapm->codec && dapm->codec->driver->set_bias_level) |
| 166 | ret = dapm->codec->driver->set_bias_level(dapm->codec, level); |
Mark Brown | 474e09c | 2009-08-19 14:18:53 +0100 | [diff] [blame] | 167 | else |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 168 | dapm->bias_level = level; |
Mark Brown | 474e09c | 2009-08-19 14:18:53 +0100 | [diff] [blame] | 169 | } |
Mark Brown | 1badabd | 2010-12-04 12:41:04 +0000 | [diff] [blame] | 170 | if (ret == 0) { |
| 171 | if (card && card->set_bias_level_post) |
| 172 | ret = card->set_bias_level_post(card, level); |
| 173 | } |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 174 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 175 | trace_snd_soc_bias_level_done(card, level); |
| 176 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 177 | return ret; |
| 178 | } |
| 179 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 180 | /* set up initial codec paths */ |
| 181 | static void dapm_set_path_status(struct snd_soc_dapm_widget *w, |
| 182 | struct snd_soc_dapm_path *p, int i) |
| 183 | { |
| 184 | switch (w->id) { |
| 185 | case snd_soc_dapm_switch: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 186 | case snd_soc_dapm_mixer: |
| 187 | case snd_soc_dapm_mixer_named_ctl: { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 188 | int val; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 189 | struct soc_mixer_control *mc = (struct soc_mixer_control *) |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 190 | w->kcontrol_news[i].private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 191 | unsigned int reg = mc->reg; |
| 192 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 193 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 194 | unsigned int mask = (1 << fls(max)) - 1; |
| 195 | unsigned int invert = mc->invert; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 196 | |
| 197 | val = snd_soc_read(w->codec, reg); |
| 198 | val = (val >> shift) & mask; |
| 199 | |
| 200 | if ((invert && !val) || (!invert && val)) |
| 201 | p->connect = 1; |
| 202 | else |
| 203 | p->connect = 0; |
| 204 | } |
| 205 | break; |
| 206 | case snd_soc_dapm_mux: { |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 207 | struct soc_enum *e = (struct soc_enum *) |
| 208 | w->kcontrol_news[i].private_value; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 209 | int val, item, bitmask; |
| 210 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 211 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 212 | ; |
| 213 | val = snd_soc_read(w->codec, e->reg); |
| 214 | item = (val >> e->shift_l) & (bitmask - 1); |
| 215 | |
| 216 | p->connect = 0; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 217 | for (i = 0; i < e->max; i++) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 218 | if (!(strcmp(p->name, e->texts[i])) && item == i) |
| 219 | p->connect = 1; |
| 220 | } |
| 221 | } |
| 222 | break; |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 223 | case snd_soc_dapm_virt_mux: { |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 224 | struct soc_enum *e = (struct soc_enum *) |
| 225 | w->kcontrol_news[i].private_value; |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 226 | |
| 227 | p->connect = 0; |
| 228 | /* since a virtual mux has no backing registers to |
| 229 | * decide which path to connect, it will try to match |
| 230 | * with the first enumeration. This is to ensure |
| 231 | * that the default mux choice (the first) will be |
| 232 | * correctly powered up during initialization. |
| 233 | */ |
| 234 | if (!strcmp(p->name, e->texts[0])) |
| 235 | p->connect = 1; |
| 236 | } |
| 237 | break; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 238 | case snd_soc_dapm_value_mux: { |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 239 | struct soc_enum *e = (struct soc_enum *) |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 240 | w->kcontrol_news[i].private_value; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 241 | int val, item; |
| 242 | |
| 243 | val = snd_soc_read(w->codec, e->reg); |
| 244 | val = (val >> e->shift_l) & e->mask; |
| 245 | for (item = 0; item < e->max; item++) { |
| 246 | if (val == e->values[item]) |
| 247 | break; |
| 248 | } |
| 249 | |
| 250 | p->connect = 0; |
| 251 | for (i = 0; i < e->max; i++) { |
| 252 | if (!(strcmp(p->name, e->texts[i])) && item == i) |
| 253 | p->connect = 1; |
| 254 | } |
| 255 | } |
| 256 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 257 | /* does not effect routing - always connected */ |
| 258 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 259 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 260 | case snd_soc_dapm_output: |
| 261 | case snd_soc_dapm_adc: |
| 262 | case snd_soc_dapm_input: |
| 263 | case snd_soc_dapm_dac: |
| 264 | case snd_soc_dapm_micbias: |
| 265 | case snd_soc_dapm_vmid: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 266 | case snd_soc_dapm_supply: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 267 | case snd_soc_dapm_aif_in: |
| 268 | case snd_soc_dapm_aif_out: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 269 | p->connect = 1; |
| 270 | break; |
| 271 | /* does effect routing - dynamically connected */ |
| 272 | case snd_soc_dapm_hp: |
| 273 | case snd_soc_dapm_mic: |
| 274 | case snd_soc_dapm_spk: |
| 275 | case snd_soc_dapm_line: |
| 276 | case snd_soc_dapm_pre: |
| 277 | case snd_soc_dapm_post: |
| 278 | p->connect = 0; |
| 279 | break; |
| 280 | } |
| 281 | } |
| 282 | |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 283 | /* connect mux widget to its interconnecting audio paths */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 284 | static int dapm_connect_mux(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 285 | struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, |
| 286 | struct snd_soc_dapm_path *path, const char *control_name, |
| 287 | const struct snd_kcontrol_new *kcontrol) |
| 288 | { |
| 289 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 290 | int i; |
| 291 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 292 | for (i = 0; i < e->max; i++) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 293 | if (!(strcmp(control_name, e->texts[i]))) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 294 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 295 | list_add(&path->list_sink, &dest->sources); |
| 296 | list_add(&path->list_source, &src->sinks); |
| 297 | path->name = (char*)e->texts[i]; |
| 298 | dapm_set_path_status(dest, path, 0); |
| 299 | return 0; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | return -ENODEV; |
| 304 | } |
| 305 | |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 306 | /* connect mixer widget to its interconnecting audio paths */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 307 | static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 308 | struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, |
| 309 | struct snd_soc_dapm_path *path, const char *control_name) |
| 310 | { |
| 311 | int i; |
| 312 | |
| 313 | /* search for mixer kcontrol */ |
| 314 | for (i = 0; i < dest->num_kcontrols; i++) { |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 315 | if (!strcmp(control_name, dest->kcontrol_news[i].name)) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 316 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 317 | list_add(&path->list_sink, &dest->sources); |
| 318 | list_add(&path->list_source, &src->sinks); |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 319 | path->name = dest->kcontrol_news[i].name; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 320 | dapm_set_path_status(dest, path, i); |
| 321 | return 0; |
| 322 | } |
| 323 | } |
| 324 | return -ENODEV; |
| 325 | } |
| 326 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 327 | /* create new dapm mixer control */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 328 | static int dapm_new_mixer(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 329 | struct snd_soc_dapm_widget *w) |
| 330 | { |
| 331 | int i, ret = 0; |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 332 | size_t name_len, prefix_len; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 333 | struct snd_soc_dapm_path *path; |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 334 | struct snd_card *card = dapm->card->snd_card; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 335 | const char *prefix; |
| 336 | |
| 337 | if (dapm->codec) |
| 338 | prefix = dapm->codec->name_prefix; |
| 339 | else |
| 340 | prefix = NULL; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 341 | |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 342 | if (prefix) |
| 343 | prefix_len = strlen(prefix) + 1; |
| 344 | else |
| 345 | prefix_len = 0; |
| 346 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 347 | /* add kcontrol */ |
| 348 | for (i = 0; i < w->num_kcontrols; i++) { |
| 349 | |
| 350 | /* match name */ |
| 351 | list_for_each_entry(path, &w->sources, list_sink) { |
| 352 | |
| 353 | /* mixer/mux paths name must match control name */ |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 354 | if (path->name != (char *)w->kcontrol_news[i].name) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 355 | continue; |
| 356 | |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 357 | /* add dapm control with long name. |
| 358 | * for dapm_mixer this is the concatenation of the |
| 359 | * mixer and kcontrol name. |
| 360 | * for dapm_mixer_named_ctl this is simply the |
| 361 | * kcontrol name. |
| 362 | */ |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 363 | name_len = strlen(w->kcontrol_news[i].name) + 1; |
Mark Brown | 07495f3 | 2009-03-05 17:06:23 +0000 | [diff] [blame] | 364 | if (w->id != snd_soc_dapm_mixer_named_ctl) |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 365 | name_len += 1 + strlen(w->name); |
| 366 | |
Mark Brown | 219b93f | 2008-10-28 13:02:31 +0000 | [diff] [blame] | 367 | path->long_name = kmalloc(name_len, GFP_KERNEL); |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 368 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 369 | if (path->long_name == NULL) |
| 370 | return -ENOMEM; |
| 371 | |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 372 | switch (w->id) { |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 373 | default: |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 374 | /* The control will get a prefix from |
| 375 | * the control creation process but |
| 376 | * we're also using the same prefix |
| 377 | * for widgets so cut the prefix off |
| 378 | * the front of the widget name. |
| 379 | */ |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 380 | snprintf(path->long_name, name_len, "%s %s", |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 381 | w->name + prefix_len, |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 382 | w->kcontrol_news[i].name); |
Mark Brown | 07495f3 | 2009-03-05 17:06:23 +0000 | [diff] [blame] | 383 | break; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 384 | case snd_soc_dapm_mixer_named_ctl: |
| 385 | snprintf(path->long_name, name_len, "%s", |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 386 | w->kcontrol_news[i].name); |
Mark Brown | 07495f3 | 2009-03-05 17:06:23 +0000 | [diff] [blame] | 387 | break; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Mark Brown | 219b93f | 2008-10-28 13:02:31 +0000 | [diff] [blame] | 390 | path->long_name[name_len - 1] = '\0'; |
| 391 | |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 392 | path->kcontrol = snd_soc_cnew(&w->kcontrol_news[i], w, |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 393 | path->long_name, prefix); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 394 | ret = snd_ctl_add(card, path->kcontrol); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 395 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 396 | dev_err(dapm->dev, |
| 397 | "asoc: failed to add dapm kcontrol %s: %d\n", |
| 398 | path->long_name, ret); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 399 | kfree(path->long_name); |
| 400 | path->long_name = NULL; |
| 401 | return ret; |
| 402 | } |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame^] | 403 | w->kcontrols[i] = path->kcontrol; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | return ret; |
| 407 | } |
| 408 | |
| 409 | /* create new dapm mux control */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 410 | static int dapm_new_mux(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 411 | struct snd_soc_dapm_widget *w) |
| 412 | { |
| 413 | struct snd_soc_dapm_path *path = NULL; |
| 414 | struct snd_kcontrol *kcontrol; |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 415 | struct snd_card *card = dapm->card->snd_card; |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 416 | const char *prefix; |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 417 | size_t prefix_len; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 418 | int ret = 0; |
| 419 | |
| 420 | if (!w->num_kcontrols) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 421 | dev_err(dapm->dev, "asoc: mux %s has no controls\n", w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 422 | return -EINVAL; |
| 423 | } |
| 424 | |
Mark Brown | efb7ac3 | 2011-03-08 17:23:24 +0000 | [diff] [blame] | 425 | if (dapm->codec) |
| 426 | prefix = dapm->codec->name_prefix; |
| 427 | else |
| 428 | prefix = NULL; |
| 429 | |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 430 | if (prefix) |
| 431 | prefix_len = strlen(prefix) + 1; |
| 432 | else |
| 433 | prefix_len = 0; |
| 434 | |
| 435 | /* The control will get a prefix from the control creation |
| 436 | * process but we're also using the same prefix for widgets so |
| 437 | * cut the prefix off the front of the widget name. |
| 438 | */ |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 439 | kcontrol = snd_soc_cnew(&w->kcontrol_news[0], w, w->name + prefix_len, |
Mark Brown | 3e5ff4d | 2011-03-09 11:33:09 +0000 | [diff] [blame] | 440 | prefix); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 441 | ret = snd_ctl_add(card, kcontrol); |
| 442 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 443 | if (ret < 0) |
| 444 | goto err; |
| 445 | |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame^] | 446 | w->kcontrols[0] = kcontrol; |
| 447 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 448 | list_for_each_entry(path, &w->sources, list_sink) |
| 449 | path->kcontrol = kcontrol; |
| 450 | |
| 451 | return ret; |
| 452 | |
| 453 | err: |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 454 | dev_err(dapm->dev, "asoc: failed to add kcontrol %s\n", w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 455 | return ret; |
| 456 | } |
| 457 | |
| 458 | /* create new dapm volume control */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 459 | static int dapm_new_pga(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 460 | struct snd_soc_dapm_widget *w) |
| 461 | { |
Mark Brown | a6c6573 | 2010-03-03 17:45:21 +0000 | [diff] [blame] | 462 | if (w->num_kcontrols) |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 463 | dev_err(w->dapm->dev, |
| 464 | "asoc: PGA controls not supported: '%s'\n", w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 465 | |
Mark Brown | a6c6573 | 2010-03-03 17:45:21 +0000 | [diff] [blame] | 466 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | /* reset 'walked' bit for each dapm path */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 470 | static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 471 | { |
| 472 | struct snd_soc_dapm_path *p; |
| 473 | |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 474 | list_for_each_entry(p, &dapm->card->paths, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 475 | p->walked = 0; |
| 476 | } |
| 477 | |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 478 | /* We implement power down on suspend by checking the power state of |
| 479 | * the ALSA card - when we are suspending the ALSA state for the card |
| 480 | * is set to D3. |
| 481 | */ |
| 482 | static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget) |
| 483 | { |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 484 | int level = snd_power_get_state(widget->dapm->card->snd_card); |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 485 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 486 | switch (level) { |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 487 | case SNDRV_CTL_POWER_D3hot: |
| 488 | case SNDRV_CTL_POWER_D3cold: |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 489 | if (widget->ignore_suspend) |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 490 | dev_dbg(widget->dapm->dev, "%s ignoring suspend\n", |
| 491 | widget->name); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 492 | return widget->ignore_suspend; |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 493 | default: |
| 494 | return 1; |
| 495 | } |
| 496 | } |
| 497 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 498 | /* |
| 499 | * Recursively check for a completed path to an active or physically connected |
| 500 | * output widget. Returns number of complete paths. |
| 501 | */ |
| 502 | static int is_connected_output_ep(struct snd_soc_dapm_widget *widget) |
| 503 | { |
| 504 | struct snd_soc_dapm_path *path; |
| 505 | int con = 0; |
| 506 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 507 | if (widget->id == snd_soc_dapm_supply) |
| 508 | return 0; |
| 509 | |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 510 | switch (widget->id) { |
| 511 | case snd_soc_dapm_adc: |
| 512 | case snd_soc_dapm_aif_out: |
| 513 | if (widget->active) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 514 | return snd_soc_dapm_suspend_check(widget); |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 515 | default: |
| 516 | break; |
| 517 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 518 | |
| 519 | if (widget->connected) { |
| 520 | /* connected pin ? */ |
| 521 | if (widget->id == snd_soc_dapm_output && !widget->ext) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 522 | return snd_soc_dapm_suspend_check(widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 523 | |
| 524 | /* connected jack or spk ? */ |
| 525 | if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk || |
Peter Ujfalusi | eaeae5d | 2009-09-30 09:27:24 +0300 | [diff] [blame] | 526 | (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources))) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 527 | return snd_soc_dapm_suspend_check(widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | list_for_each_entry(path, &widget->sinks, list_source) { |
| 531 | if (path->walked) |
| 532 | continue; |
| 533 | |
| 534 | if (path->sink && path->connect) { |
| 535 | path->walked = 1; |
| 536 | con += is_connected_output_ep(path->sink); |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | return con; |
| 541 | } |
| 542 | |
| 543 | /* |
| 544 | * Recursively check for a completed path to an active or physically connected |
| 545 | * input widget. Returns number of complete paths. |
| 546 | */ |
| 547 | static int is_connected_input_ep(struct snd_soc_dapm_widget *widget) |
| 548 | { |
| 549 | struct snd_soc_dapm_path *path; |
| 550 | int con = 0; |
| 551 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 552 | if (widget->id == snd_soc_dapm_supply) |
| 553 | return 0; |
| 554 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 555 | /* active stream ? */ |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 556 | switch (widget->id) { |
| 557 | case snd_soc_dapm_dac: |
| 558 | case snd_soc_dapm_aif_in: |
| 559 | if (widget->active) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 560 | return snd_soc_dapm_suspend_check(widget); |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 561 | default: |
| 562 | break; |
| 563 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 564 | |
| 565 | if (widget->connected) { |
| 566 | /* connected pin ? */ |
| 567 | if (widget->id == snd_soc_dapm_input && !widget->ext) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 568 | return snd_soc_dapm_suspend_check(widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 569 | |
| 570 | /* connected VMID/Bias for lower pops */ |
| 571 | if (widget->id == snd_soc_dapm_vmid) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 572 | return snd_soc_dapm_suspend_check(widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 573 | |
| 574 | /* connected jack ? */ |
Peter Ujfalusi | eaeae5d | 2009-09-30 09:27:24 +0300 | [diff] [blame] | 575 | if (widget->id == snd_soc_dapm_mic || |
| 576 | (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks))) |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 577 | return snd_soc_dapm_suspend_check(widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | list_for_each_entry(path, &widget->sources, list_sink) { |
| 581 | if (path->walked) |
| 582 | continue; |
| 583 | |
| 584 | if (path->source && path->connect) { |
| 585 | path->walked = 1; |
| 586 | con += is_connected_input_ep(path->source); |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | return con; |
| 591 | } |
| 592 | |
| 593 | /* |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 594 | * Handler for generic register modifier widget. |
| 595 | */ |
| 596 | int dapm_reg_event(struct snd_soc_dapm_widget *w, |
| 597 | struct snd_kcontrol *kcontrol, int event) |
| 598 | { |
| 599 | unsigned int val; |
| 600 | |
| 601 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 602 | val = w->on_val; |
| 603 | else |
| 604 | val = w->off_val; |
| 605 | |
| 606 | snd_soc_update_bits(w->codec, -(w->reg + 1), |
| 607 | w->mask << w->shift, val << w->shift); |
| 608 | |
| 609 | return 0; |
| 610 | } |
Mark Brown | 1158941 | 2008-07-29 11:42:23 +0100 | [diff] [blame] | 611 | EXPORT_SYMBOL_GPL(dapm_reg_event); |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 612 | |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 613 | /* Generic check to see if a widget should be powered. |
| 614 | */ |
| 615 | static int dapm_generic_check_power(struct snd_soc_dapm_widget *w) |
| 616 | { |
| 617 | int in, out; |
| 618 | |
| 619 | in = is_connected_input_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 620 | dapm_clear_walk(w->dapm); |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 621 | out = is_connected_output_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 622 | dapm_clear_walk(w->dapm); |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 623 | return out != 0 && in != 0; |
| 624 | } |
| 625 | |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 626 | /* Check to see if an ADC has power */ |
| 627 | static int dapm_adc_check_power(struct snd_soc_dapm_widget *w) |
| 628 | { |
| 629 | int in; |
| 630 | |
| 631 | if (w->active) { |
| 632 | in = is_connected_input_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 633 | dapm_clear_walk(w->dapm); |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 634 | return in != 0; |
| 635 | } else { |
| 636 | return dapm_generic_check_power(w); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | /* Check to see if a DAC has power */ |
| 641 | static int dapm_dac_check_power(struct snd_soc_dapm_widget *w) |
| 642 | { |
| 643 | int out; |
| 644 | |
| 645 | if (w->active) { |
| 646 | out = is_connected_output_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 647 | dapm_clear_walk(w->dapm); |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 648 | return out != 0; |
| 649 | } else { |
| 650 | return dapm_generic_check_power(w); |
| 651 | } |
| 652 | } |
| 653 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 654 | /* Check to see if a power supply is needed */ |
| 655 | static int dapm_supply_check_power(struct snd_soc_dapm_widget *w) |
| 656 | { |
| 657 | struct snd_soc_dapm_path *path; |
| 658 | int power = 0; |
| 659 | |
| 660 | /* Check if one of our outputs is connected */ |
| 661 | list_for_each_entry(path, &w->sinks, list_source) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 662 | if (path->connected && |
| 663 | !path->connected(path->source, path->sink)) |
| 664 | continue; |
| 665 | |
Mark Brown | 3017358 | 2011-02-11 11:42:19 +0000 | [diff] [blame] | 666 | if (!path->sink) |
| 667 | continue; |
| 668 | |
| 669 | if (path->sink->force) { |
| 670 | power = 1; |
| 671 | break; |
| 672 | } |
| 673 | |
| 674 | if (path->sink->power_check && |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 675 | path->sink->power_check(path->sink)) { |
| 676 | power = 1; |
| 677 | break; |
| 678 | } |
| 679 | } |
| 680 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 681 | dapm_clear_walk(w->dapm); |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 682 | |
| 683 | return power; |
| 684 | } |
| 685 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 686 | static int dapm_seq_compare(struct snd_soc_dapm_widget *a, |
| 687 | struct snd_soc_dapm_widget *b, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 688 | bool power_up) |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 689 | { |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 690 | int *sort; |
| 691 | |
| 692 | if (power_up) |
| 693 | sort = dapm_up_seq; |
| 694 | else |
| 695 | sort = dapm_down_seq; |
| 696 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 697 | if (sort[a->id] != sort[b->id]) |
| 698 | return sort[a->id] - sort[b->id]; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 699 | if (a->subseq != b->subseq) { |
| 700 | if (power_up) |
| 701 | return a->subseq - b->subseq; |
| 702 | else |
| 703 | return b->subseq - a->subseq; |
| 704 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 705 | if (a->reg != b->reg) |
| 706 | return a->reg - b->reg; |
Mark Brown | 84dab56 | 2010-11-12 15:28:42 +0000 | [diff] [blame] | 707 | if (a->dapm != b->dapm) |
| 708 | return (unsigned long)a->dapm - (unsigned long)b->dapm; |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 709 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 710 | return 0; |
| 711 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 712 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 713 | /* Insert a widget in order into a DAPM power sequence. */ |
| 714 | static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget, |
| 715 | struct list_head *list, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 716 | bool power_up) |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 717 | { |
| 718 | struct snd_soc_dapm_widget *w; |
| 719 | |
| 720 | list_for_each_entry(w, list, power_list) |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 721 | if (dapm_seq_compare(new_widget, w, power_up) < 0) { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 722 | list_add_tail(&new_widget->power_list, &w->power_list); |
| 723 | return; |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 724 | } |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 725 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 726 | list_add_tail(&new_widget->power_list, list); |
| 727 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 728 | |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 729 | static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm, |
| 730 | struct snd_soc_dapm_widget *w, int event) |
| 731 | { |
| 732 | struct snd_soc_card *card = dapm->card; |
| 733 | const char *ev_name; |
| 734 | int power, ret; |
| 735 | |
| 736 | switch (event) { |
| 737 | case SND_SOC_DAPM_PRE_PMU: |
| 738 | ev_name = "PRE_PMU"; |
| 739 | power = 1; |
| 740 | break; |
| 741 | case SND_SOC_DAPM_POST_PMU: |
| 742 | ev_name = "POST_PMU"; |
| 743 | power = 1; |
| 744 | break; |
| 745 | case SND_SOC_DAPM_PRE_PMD: |
| 746 | ev_name = "PRE_PMD"; |
| 747 | power = 0; |
| 748 | break; |
| 749 | case SND_SOC_DAPM_POST_PMD: |
| 750 | ev_name = "POST_PMD"; |
| 751 | power = 0; |
| 752 | break; |
| 753 | default: |
| 754 | BUG(); |
| 755 | return; |
| 756 | } |
| 757 | |
| 758 | if (w->power != power) |
| 759 | return; |
| 760 | |
| 761 | if (w->event && (w->event_flags & event)) { |
| 762 | pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n", |
| 763 | w->name, ev_name); |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 764 | trace_snd_soc_dapm_widget_event_start(w, event); |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 765 | ret = w->event(w, NULL, event); |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 766 | trace_snd_soc_dapm_widget_event_done(w, event); |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 767 | if (ret < 0) |
| 768 | pr_err("%s: %s event failed: %d\n", |
| 769 | ev_name, w->name, ret); |
| 770 | } |
| 771 | } |
| 772 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 773 | /* Apply the coalesced changes from a DAPM sequence */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 774 | static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm, |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 775 | struct list_head *pending) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 776 | { |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 777 | struct snd_soc_card *card = dapm->card; |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 778 | struct snd_soc_dapm_widget *w; |
| 779 | int reg, power; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 780 | unsigned int value = 0; |
| 781 | unsigned int mask = 0; |
| 782 | unsigned int cur_mask; |
| 783 | |
| 784 | reg = list_first_entry(pending, struct snd_soc_dapm_widget, |
| 785 | power_list)->reg; |
| 786 | |
| 787 | list_for_each_entry(w, pending, power_list) { |
| 788 | cur_mask = 1 << w->shift; |
| 789 | BUG_ON(reg != w->reg); |
| 790 | |
| 791 | if (w->invert) |
| 792 | power = !w->power; |
| 793 | else |
| 794 | power = w->power; |
| 795 | |
| 796 | mask |= cur_mask; |
| 797 | if (power) |
| 798 | value |= cur_mask; |
| 799 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 800 | pop_dbg(dapm->dev, card->pop_time, |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 801 | "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n", |
| 802 | w->name, reg, value, mask); |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 803 | |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 804 | /* Check for events */ |
| 805 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU); |
| 806 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 807 | } |
| 808 | |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 809 | if (reg >= 0) { |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 810 | pop_dbg(dapm->dev, card->pop_time, |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 811 | "pop test : Applying 0x%x/0x%x to %x in %dms\n", |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 812 | value, mask, reg, card->pop_time); |
| 813 | pop_wait(card->pop_time); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 814 | snd_soc_update_bits(dapm->codec, reg, mask, value); |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | list_for_each_entry(w, pending, power_list) { |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 818 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU); |
| 819 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD); |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 820 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 821 | } |
| 822 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 823 | /* Apply a DAPM power sequence. |
| 824 | * |
| 825 | * We walk over a pre-sorted list of widgets to apply power to. In |
| 826 | * order to minimise the number of writes to the device required |
| 827 | * multiple widgets will be updated in a single write where possible. |
| 828 | * Currently anything that requires more than a single write is not |
| 829 | * handled. |
| 830 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 831 | static void dapm_seq_run(struct snd_soc_dapm_context *dapm, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 832 | struct list_head *list, int event, bool power_up) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 833 | { |
| 834 | struct snd_soc_dapm_widget *w, *n; |
| 835 | LIST_HEAD(pending); |
| 836 | int cur_sort = -1; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 837 | int cur_subseq = -1; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 838 | int cur_reg = SND_SOC_NOPM; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 839 | struct snd_soc_dapm_context *cur_dapm = NULL; |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 840 | int ret, i; |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 841 | int *sort; |
| 842 | |
| 843 | if (power_up) |
| 844 | sort = dapm_up_seq; |
| 845 | else |
| 846 | sort = dapm_down_seq; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 847 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 848 | list_for_each_entry_safe(w, n, list, power_list) { |
| 849 | ret = 0; |
| 850 | |
| 851 | /* Do we need to apply any queued changes? */ |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 852 | if (sort[w->id] != cur_sort || w->reg != cur_reg || |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 853 | w->dapm != cur_dapm || w->subseq != cur_subseq) { |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 854 | if (!list_empty(&pending)) |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 855 | dapm_seq_run_coalesced(cur_dapm, &pending); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 856 | |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 857 | if (cur_dapm && cur_dapm->seq_notifier) { |
| 858 | for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) |
| 859 | if (sort[i] == cur_sort) |
| 860 | cur_dapm->seq_notifier(cur_dapm, |
Mark Brown | f85a9e0 | 2011-01-26 21:41:28 +0000 | [diff] [blame] | 861 | i, |
| 862 | cur_subseq); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 865 | INIT_LIST_HEAD(&pending); |
| 866 | cur_sort = -1; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 867 | cur_subseq = -1; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 868 | cur_reg = SND_SOC_NOPM; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 869 | cur_dapm = NULL; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 870 | } |
| 871 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 872 | switch (w->id) { |
| 873 | case snd_soc_dapm_pre: |
| 874 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 875 | list_for_each_entry_safe_continue(w, n, list, |
| 876 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 877 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 878 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 879 | ret = w->event(w, |
| 880 | NULL, SND_SOC_DAPM_PRE_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 881 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 882 | ret = w->event(w, |
| 883 | NULL, SND_SOC_DAPM_PRE_PMD); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 884 | break; |
| 885 | |
| 886 | case snd_soc_dapm_post: |
| 887 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 888 | list_for_each_entry_safe_continue(w, n, list, |
| 889 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 890 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 891 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 892 | ret = w->event(w, |
| 893 | NULL, SND_SOC_DAPM_POST_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 894 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 895 | ret = w->event(w, |
| 896 | NULL, SND_SOC_DAPM_POST_PMD); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 897 | break; |
| 898 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 899 | default: |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 900 | /* Queue it up for application */ |
| 901 | cur_sort = sort[w->id]; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 902 | cur_subseq = w->subseq; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 903 | cur_reg = w->reg; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 904 | cur_dapm = w->dapm; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 905 | list_move(&w->power_list, &pending); |
| 906 | break; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 907 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 908 | |
| 909 | if (ret < 0) |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 910 | dev_err(w->dapm->dev, |
| 911 | "Failed to apply widget power: %d\n", ret); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 912 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 913 | |
| 914 | if (!list_empty(&pending)) |
Mark Brown | 28e8680 | 2011-03-08 19:29:53 +0000 | [diff] [blame] | 915 | dapm_seq_run_coalesced(cur_dapm, &pending); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 916 | |
| 917 | if (cur_dapm && cur_dapm->seq_notifier) { |
| 918 | for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) |
| 919 | if (sort[i] == cur_sort) |
| 920 | cur_dapm->seq_notifier(cur_dapm, |
Mark Brown | f85a9e0 | 2011-01-26 21:41:28 +0000 | [diff] [blame] | 921 | i, cur_subseq); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 922 | } |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 923 | } |
| 924 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 925 | static void dapm_widget_update(struct snd_soc_dapm_context *dapm) |
| 926 | { |
| 927 | struct snd_soc_dapm_update *update = dapm->update; |
| 928 | struct snd_soc_dapm_widget *w; |
| 929 | int ret; |
| 930 | |
| 931 | if (!update) |
| 932 | return; |
| 933 | |
| 934 | w = update->widget; |
| 935 | |
| 936 | if (w->event && |
| 937 | (w->event_flags & SND_SOC_DAPM_PRE_REG)) { |
| 938 | ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG); |
| 939 | if (ret != 0) |
| 940 | pr_err("%s DAPM pre-event failed: %d\n", |
| 941 | w->name, ret); |
| 942 | } |
| 943 | |
| 944 | ret = snd_soc_update_bits(w->codec, update->reg, update->mask, |
| 945 | update->val); |
| 946 | if (ret < 0) |
| 947 | pr_err("%s DAPM update failed: %d\n", w->name, ret); |
| 948 | |
| 949 | if (w->event && |
| 950 | (w->event_flags & SND_SOC_DAPM_POST_REG)) { |
| 951 | ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG); |
| 952 | if (ret != 0) |
| 953 | pr_err("%s DAPM post-event failed: %d\n", |
| 954 | w->name, ret); |
| 955 | } |
| 956 | } |
| 957 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 958 | /* Async callback run prior to DAPM sequences - brings to _PREPARE if |
| 959 | * they're changing state. |
| 960 | */ |
| 961 | static void dapm_pre_sequence_async(void *data, async_cookie_t cookie) |
| 962 | { |
| 963 | struct snd_soc_dapm_context *d = data; |
| 964 | int ret; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 965 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 966 | if (d->dev_power && d->bias_level == SND_SOC_BIAS_OFF) { |
| 967 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY); |
| 968 | if (ret != 0) |
| 969 | dev_err(d->dev, |
| 970 | "Failed to turn on bias: %d\n", ret); |
| 971 | } |
| 972 | |
| 973 | /* If we're changing to all on or all off then prepare */ |
| 974 | if ((d->dev_power && d->bias_level == SND_SOC_BIAS_STANDBY) || |
| 975 | (!d->dev_power && d->bias_level == SND_SOC_BIAS_ON)) { |
| 976 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE); |
| 977 | if (ret != 0) |
| 978 | dev_err(d->dev, |
| 979 | "Failed to prepare bias: %d\n", ret); |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | /* Async callback run prior to DAPM sequences - brings to their final |
| 984 | * state. |
| 985 | */ |
| 986 | static void dapm_post_sequence_async(void *data, async_cookie_t cookie) |
| 987 | { |
| 988 | struct snd_soc_dapm_context *d = data; |
| 989 | int ret; |
| 990 | |
| 991 | /* If we just powered the last thing off drop to standby bias */ |
| 992 | if (d->bias_level == SND_SOC_BIAS_PREPARE && !d->dev_power) { |
| 993 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY); |
| 994 | if (ret != 0) |
| 995 | dev_err(d->dev, "Failed to apply standby bias: %d\n", |
| 996 | ret); |
| 997 | } |
| 998 | |
| 999 | /* If we're in standby and can support bias off then do that */ |
| 1000 | if (d->bias_level == SND_SOC_BIAS_STANDBY && d->idle_bias_off) { |
| 1001 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF); |
| 1002 | if (ret != 0) |
| 1003 | dev_err(d->dev, "Failed to turn off bias: %d\n", ret); |
| 1004 | } |
| 1005 | |
| 1006 | /* If we just powered up then move to active bias */ |
| 1007 | if (d->bias_level == SND_SOC_BIAS_PREPARE && d->dev_power) { |
| 1008 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON); |
| 1009 | if (ret != 0) |
| 1010 | dev_err(d->dev, "Failed to apply active bias: %d\n", |
| 1011 | ret); |
| 1012 | } |
| 1013 | } |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1014 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1015 | /* |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1016 | * Scan each dapm widget for complete audio path. |
| 1017 | * A complete path is a route that has valid endpoints i.e.:- |
| 1018 | * |
| 1019 | * o DAC to output pin. |
| 1020 | * o Input Pin to ADC. |
| 1021 | * o Input pin to Output pin (bypass, sidetone) |
| 1022 | * o DAC to ADC (loopback). |
| 1023 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1024 | 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] | 1025 | { |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 1026 | struct snd_soc_card *card = dapm->card; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1027 | struct snd_soc_dapm_widget *w; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1028 | struct snd_soc_dapm_context *d; |
Mark Brown | 291f3bb | 2009-06-07 13:57:17 +0100 | [diff] [blame] | 1029 | LIST_HEAD(up_list); |
| 1030 | LIST_HEAD(down_list); |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1031 | LIST_HEAD(async_domain); |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1032 | int power; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1033 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1034 | trace_snd_soc_dapm_start(card); |
| 1035 | |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1036 | list_for_each_entry(d, &card->dapm_list, list) |
| 1037 | if (d->n_widgets) |
| 1038 | d->dev_power = 0; |
| 1039 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1040 | /* Check which widgets we need to power and store them in |
| 1041 | * lists indicating if they should be powered up or down. |
| 1042 | */ |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1043 | list_for_each_entry(w, &card->widgets, list) { |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1044 | switch (w->id) { |
| 1045 | case snd_soc_dapm_pre: |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1046 | dapm_seq_insert(w, &down_list, false); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1047 | break; |
| 1048 | case snd_soc_dapm_post: |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1049 | dapm_seq_insert(w, &up_list, true); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1050 | break; |
| 1051 | |
| 1052 | default: |
| 1053 | if (!w->power_check) |
| 1054 | continue; |
| 1055 | |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 1056 | if (!w->force) |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1057 | power = w->power_check(w); |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 1058 | else |
| 1059 | power = 1; |
| 1060 | if (power) |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1061 | w->dapm->dev_power = 1; |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1062 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1063 | if (w->power == power) |
| 1064 | continue; |
| 1065 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1066 | trace_snd_soc_dapm_widget_power(w, power); |
| 1067 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1068 | if (power) |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1069 | dapm_seq_insert(w, &up_list, true); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1070 | else |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1071 | dapm_seq_insert(w, &down_list, false); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1072 | |
| 1073 | w->power = power; |
| 1074 | break; |
| 1075 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1076 | } |
| 1077 | |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1078 | /* If there are no DAPM widgets then try to figure out power from the |
| 1079 | * event type. |
| 1080 | */ |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1081 | if (!dapm->n_widgets) { |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1082 | switch (event) { |
| 1083 | case SND_SOC_DAPM_STREAM_START: |
| 1084 | case SND_SOC_DAPM_STREAM_RESUME: |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1085 | dapm->dev_power = 1; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1086 | break; |
Jarkko Nikula | 862af8a | 2010-12-10 20:53:55 +0200 | [diff] [blame] | 1087 | case SND_SOC_DAPM_STREAM_STOP: |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1088 | dapm->dev_power = !!dapm->codec->active; |
Jarkko Nikula | 862af8a | 2010-12-10 20:53:55 +0200 | [diff] [blame] | 1089 | break; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1090 | case SND_SOC_DAPM_STREAM_SUSPEND: |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1091 | dapm->dev_power = 0; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1092 | break; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1093 | case SND_SOC_DAPM_STREAM_NOP: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1094 | switch (dapm->bias_level) { |
Mark Brown | a96ca33 | 2010-01-19 22:49:43 +0000 | [diff] [blame] | 1095 | case SND_SOC_BIAS_STANDBY: |
| 1096 | case SND_SOC_BIAS_OFF: |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1097 | dapm->dev_power = 0; |
Mark Brown | a96ca33 | 2010-01-19 22:49:43 +0000 | [diff] [blame] | 1098 | break; |
| 1099 | default: |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1100 | dapm->dev_power = 1; |
Mark Brown | a96ca33 | 2010-01-19 22:49:43 +0000 | [diff] [blame] | 1101 | break; |
| 1102 | } |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1103 | break; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1104 | default: |
| 1105 | break; |
| 1106 | } |
| 1107 | } |
| 1108 | |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1109 | /* Force all contexts in the card to the same bias state */ |
| 1110 | power = 0; |
| 1111 | list_for_each_entry(d, &card->dapm_list, list) |
| 1112 | if (d->dev_power) |
| 1113 | power = 1; |
| 1114 | list_for_each_entry(d, &card->dapm_list, list) |
| 1115 | d->dev_power = power; |
| 1116 | |
| 1117 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1118 | /* Run all the bias changes in parallel */ |
| 1119 | list_for_each_entry(d, &dapm->card->dapm_list, list) |
| 1120 | async_schedule_domain(dapm_pre_sequence_async, d, |
| 1121 | &async_domain); |
| 1122 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1123 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1124 | /* Power down widgets first; try to avoid amplifying pops. */ |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1125 | dapm_seq_run(dapm, &down_list, event, false); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1126 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1127 | dapm_widget_update(dapm); |
| 1128 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1129 | /* Now power up. */ |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1130 | dapm_seq_run(dapm, &up_list, event, true); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1131 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1132 | /* Run all the bias changes in parallel */ |
| 1133 | list_for_each_entry(d, &dapm->card->dapm_list, list) |
| 1134 | async_schedule_domain(dapm_post_sequence_async, d, |
| 1135 | &async_domain); |
| 1136 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1137 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 1138 | pop_dbg(dapm->dev, card->pop_time, |
| 1139 | "DAPM sequencing finished, waiting %dms\n", card->pop_time); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1140 | pop_wait(card->pop_time); |
Mark Brown | cb507e7 | 2009-07-08 18:54:57 +0100 | [diff] [blame] | 1141 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1142 | trace_snd_soc_dapm_done(card); |
| 1143 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1144 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1145 | } |
| 1146 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1147 | #ifdef CONFIG_DEBUG_FS |
| 1148 | static int dapm_widget_power_open_file(struct inode *inode, struct file *file) |
| 1149 | { |
| 1150 | file->private_data = inode->i_private; |
| 1151 | return 0; |
| 1152 | } |
| 1153 | |
| 1154 | static ssize_t dapm_widget_power_read_file(struct file *file, |
| 1155 | char __user *user_buf, |
| 1156 | size_t count, loff_t *ppos) |
| 1157 | { |
| 1158 | struct snd_soc_dapm_widget *w = file->private_data; |
| 1159 | char *buf; |
| 1160 | int in, out; |
| 1161 | ssize_t ret; |
| 1162 | struct snd_soc_dapm_path *p = NULL; |
| 1163 | |
| 1164 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 1165 | if (!buf) |
| 1166 | return -ENOMEM; |
| 1167 | |
| 1168 | in = is_connected_input_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1169 | dapm_clear_walk(w->dapm); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1170 | out = is_connected_output_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1171 | dapm_clear_walk(w->dapm); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1172 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1173 | ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1174 | w->name, w->power ? "On" : "Off", in, out); |
| 1175 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1176 | if (w->reg >= 0) |
| 1177 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
| 1178 | " - R%d(0x%x) bit %d", |
| 1179 | w->reg, w->reg, w->shift); |
| 1180 | |
| 1181 | ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n"); |
| 1182 | |
Mark Brown | 3eef08b | 2009-09-14 16:49:00 +0100 | [diff] [blame] | 1183 | if (w->sname) |
| 1184 | ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n", |
| 1185 | w->sname, |
| 1186 | w->active ? "active" : "inactive"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1187 | |
| 1188 | list_for_each_entry(p, &w->sources, list_sink) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1189 | if (p->connected && !p->connected(w, p->sink)) |
| 1190 | continue; |
| 1191 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1192 | if (p->connect) |
| 1193 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Dimitris Papastamos | 67f5ed6 | 2011-02-24 17:09:32 +0000 | [diff] [blame] | 1194 | " in \"%s\" \"%s\"\n", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1195 | p->name ? p->name : "static", |
| 1196 | p->source->name); |
| 1197 | } |
| 1198 | list_for_each_entry(p, &w->sinks, list_source) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1199 | if (p->connected && !p->connected(w, p->sink)) |
| 1200 | continue; |
| 1201 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1202 | if (p->connect) |
| 1203 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Dimitris Papastamos | 67f5ed6 | 2011-02-24 17:09:32 +0000 | [diff] [blame] | 1204 | " out \"%s\" \"%s\"\n", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1205 | p->name ? p->name : "static", |
| 1206 | p->sink->name); |
| 1207 | } |
| 1208 | |
| 1209 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 1210 | |
| 1211 | kfree(buf); |
| 1212 | return ret; |
| 1213 | } |
| 1214 | |
| 1215 | static const struct file_operations dapm_widget_power_fops = { |
| 1216 | .open = dapm_widget_power_open_file, |
| 1217 | .read = dapm_widget_power_read_file, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1218 | .llseek = default_llseek, |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1219 | }; |
| 1220 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1221 | static int dapm_bias_open_file(struct inode *inode, struct file *file) |
| 1222 | { |
| 1223 | file->private_data = inode->i_private; |
| 1224 | return 0; |
| 1225 | } |
| 1226 | |
| 1227 | static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf, |
| 1228 | size_t count, loff_t *ppos) |
| 1229 | { |
| 1230 | struct snd_soc_dapm_context *dapm = file->private_data; |
| 1231 | char *level; |
| 1232 | |
| 1233 | switch (dapm->bias_level) { |
| 1234 | case SND_SOC_BIAS_ON: |
| 1235 | level = "On\n"; |
| 1236 | break; |
| 1237 | case SND_SOC_BIAS_PREPARE: |
| 1238 | level = "Prepare\n"; |
| 1239 | break; |
| 1240 | case SND_SOC_BIAS_STANDBY: |
| 1241 | level = "Standby\n"; |
| 1242 | break; |
| 1243 | case SND_SOC_BIAS_OFF: |
| 1244 | level = "Off\n"; |
| 1245 | break; |
| 1246 | default: |
| 1247 | BUG(); |
| 1248 | level = "Unknown\n"; |
| 1249 | break; |
| 1250 | } |
| 1251 | |
| 1252 | return simple_read_from_buffer(user_buf, count, ppos, level, |
| 1253 | strlen(level)); |
| 1254 | } |
| 1255 | |
| 1256 | static const struct file_operations dapm_bias_fops = { |
| 1257 | .open = dapm_bias_open_file, |
| 1258 | .read = dapm_bias_read_file, |
| 1259 | .llseek = default_llseek, |
| 1260 | }; |
| 1261 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1262 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 1263 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1264 | { |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1265 | struct dentry *d; |
| 1266 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1267 | dapm->debugfs_dapm = debugfs_create_dir("dapm", parent); |
| 1268 | |
| 1269 | if (!dapm->debugfs_dapm) { |
| 1270 | printk(KERN_WARNING |
| 1271 | "Failed to create DAPM debugfs directory\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1272 | return; |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1273 | } |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1274 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1275 | d = debugfs_create_file("bias_level", 0444, |
| 1276 | dapm->debugfs_dapm, dapm, |
| 1277 | &dapm_bias_fops); |
| 1278 | if (!d) |
| 1279 | dev_warn(dapm->dev, |
| 1280 | "ASoC: Failed to create bias level debugfs file\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1281 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1282 | |
| 1283 | static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 1284 | { |
| 1285 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 1286 | struct dentry *d; |
| 1287 | |
| 1288 | if (!dapm->debugfs_dapm || !w->name) |
| 1289 | return; |
| 1290 | |
| 1291 | d = debugfs_create_file(w->name, 0444, |
| 1292 | dapm->debugfs_dapm, w, |
| 1293 | &dapm_widget_power_fops); |
| 1294 | if (!d) |
| 1295 | dev_warn(w->dapm->dev, |
| 1296 | "ASoC: Failed to create %s debugfs file\n", |
| 1297 | w->name); |
| 1298 | } |
| 1299 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 1300 | static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 1301 | { |
| 1302 | debugfs_remove_recursive(dapm->debugfs_dapm); |
| 1303 | } |
| 1304 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1305 | #else |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1306 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 1307 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1308 | { |
| 1309 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1310 | |
| 1311 | static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 1312 | { |
| 1313 | } |
| 1314 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 1315 | static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 1316 | { |
| 1317 | } |
| 1318 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1319 | #endif |
| 1320 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1321 | /* test and update the power status of a mux widget */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 1322 | static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget, |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1323 | struct snd_kcontrol *kcontrol, int change, |
| 1324 | int mux, struct soc_enum *e) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1325 | { |
| 1326 | struct snd_soc_dapm_path *path; |
| 1327 | int found = 0; |
| 1328 | |
Peter Ujfalusi | eff317d | 2009-01-15 14:40:47 +0200 | [diff] [blame] | 1329 | if (widget->id != snd_soc_dapm_mux && |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 1330 | widget->id != snd_soc_dapm_virt_mux && |
Peter Ujfalusi | eff317d | 2009-01-15 14:40:47 +0200 | [diff] [blame] | 1331 | widget->id != snd_soc_dapm_value_mux) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1332 | return -ENODEV; |
| 1333 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1334 | if (!change) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1335 | return 0; |
| 1336 | |
| 1337 | /* find dapm widget path assoc with kcontrol */ |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1338 | list_for_each_entry(path, &widget->dapm->card->paths, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1339 | if (path->kcontrol != kcontrol) |
| 1340 | continue; |
| 1341 | |
Richard Zhao | cb01e2b | 2008-10-07 08:05:20 +0800 | [diff] [blame] | 1342 | if (!path->name || !e->texts[mux]) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1343 | continue; |
| 1344 | |
| 1345 | found = 1; |
| 1346 | /* we now need to match the string in the enum to the path */ |
Richard Zhao | cb01e2b | 2008-10-07 08:05:20 +0800 | [diff] [blame] | 1347 | if (!(strcmp(path->name, e->texts[mux]))) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1348 | path->connect = 1; /* new connection */ |
| 1349 | else |
| 1350 | path->connect = 0; /* old connection must be powered down */ |
| 1351 | } |
| 1352 | |
Mark Brown | b91b8fa | 2010-01-20 18:18:35 +0000 | [diff] [blame] | 1353 | if (found) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1354 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1355 | |
| 1356 | return 0; |
| 1357 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1358 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1359 | /* test and update the power status of a mixer or switch widget */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 1360 | static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1361 | struct snd_kcontrol *kcontrol, int connect) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1362 | { |
| 1363 | struct snd_soc_dapm_path *path; |
| 1364 | int found = 0; |
| 1365 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1366 | if (widget->id != snd_soc_dapm_mixer && |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1367 | widget->id != snd_soc_dapm_mixer_named_ctl && |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1368 | widget->id != snd_soc_dapm_switch) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1369 | return -ENODEV; |
| 1370 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1371 | /* find dapm widget path assoc with kcontrol */ |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1372 | list_for_each_entry(path, &widget->dapm->card->paths, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1373 | if (path->kcontrol != kcontrol) |
| 1374 | continue; |
| 1375 | |
| 1376 | /* found, now check type */ |
| 1377 | found = 1; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1378 | path->connect = connect; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1379 | break; |
| 1380 | } |
| 1381 | |
Mark Brown | b91b8fa | 2010-01-20 18:18:35 +0000 | [diff] [blame] | 1382 | if (found) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1383 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1384 | |
| 1385 | return 0; |
| 1386 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1387 | |
| 1388 | /* show dapm widget status in sys fs */ |
| 1389 | static ssize_t dapm_widget_show(struct device *dev, |
| 1390 | struct device_attribute *attr, char *buf) |
| 1391 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1392 | struct snd_soc_pcm_runtime *rtd = |
| 1393 | container_of(dev, struct snd_soc_pcm_runtime, dev); |
| 1394 | struct snd_soc_codec *codec =rtd->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1395 | struct snd_soc_dapm_widget *w; |
| 1396 | int count = 0; |
| 1397 | char *state = "not set"; |
| 1398 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1399 | list_for_each_entry(w, &codec->card->widgets, list) { |
| 1400 | if (w->dapm != &codec->dapm) |
| 1401 | continue; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1402 | |
| 1403 | /* only display widgets that burnm power */ |
| 1404 | switch (w->id) { |
| 1405 | case snd_soc_dapm_hp: |
| 1406 | case snd_soc_dapm_mic: |
| 1407 | case snd_soc_dapm_spk: |
| 1408 | case snd_soc_dapm_line: |
| 1409 | case snd_soc_dapm_micbias: |
| 1410 | case snd_soc_dapm_dac: |
| 1411 | case snd_soc_dapm_adc: |
| 1412 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 1413 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1414 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1415 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1416 | case snd_soc_dapm_supply: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1417 | if (w->name) |
| 1418 | count += sprintf(buf + count, "%s: %s\n", |
| 1419 | w->name, w->power ? "On":"Off"); |
| 1420 | break; |
| 1421 | default: |
| 1422 | break; |
| 1423 | } |
| 1424 | } |
| 1425 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1426 | switch (codec->dapm.bias_level) { |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1427 | case SND_SOC_BIAS_ON: |
| 1428 | state = "On"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1429 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1430 | case SND_SOC_BIAS_PREPARE: |
| 1431 | state = "Prepare"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1432 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1433 | case SND_SOC_BIAS_STANDBY: |
| 1434 | state = "Standby"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1435 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1436 | case SND_SOC_BIAS_OFF: |
| 1437 | state = "Off"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1438 | break; |
| 1439 | } |
| 1440 | count += sprintf(buf + count, "PM State: %s\n", state); |
| 1441 | |
| 1442 | return count; |
| 1443 | } |
| 1444 | |
| 1445 | static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL); |
| 1446 | |
| 1447 | int snd_soc_dapm_sys_add(struct device *dev) |
| 1448 | { |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1449 | return device_create_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | static void snd_soc_dapm_sys_remove(struct device *dev) |
| 1453 | { |
Mark Brown | aef9084 | 2009-05-16 17:53:16 +0100 | [diff] [blame] | 1454 | device_remove_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | /* free all dapm widgets and resources */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1458 | static void dapm_free_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1459 | { |
| 1460 | struct snd_soc_dapm_widget *w, *next_w; |
| 1461 | struct snd_soc_dapm_path *p, *next_p; |
| 1462 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1463 | list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) { |
| 1464 | if (w->dapm != dapm) |
| 1465 | continue; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1466 | list_del(&w->list); |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1467 | /* |
| 1468 | * remove source and sink paths associated to this widget. |
| 1469 | * While removing the path, remove reference to it from both |
| 1470 | * source and sink widgets so that path is removed only once. |
| 1471 | */ |
| 1472 | list_for_each_entry_safe(p, next_p, &w->sources, list_sink) { |
| 1473 | list_del(&p->list_sink); |
| 1474 | list_del(&p->list_source); |
| 1475 | list_del(&p->list); |
| 1476 | kfree(p->long_name); |
| 1477 | kfree(p); |
| 1478 | } |
| 1479 | list_for_each_entry_safe(p, next_p, &w->sinks, list_source) { |
| 1480 | list_del(&p->list_sink); |
| 1481 | list_del(&p->list_source); |
| 1482 | list_del(&p->list); |
| 1483 | kfree(p->long_name); |
| 1484 | kfree(p); |
| 1485 | } |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame^] | 1486 | kfree(w->kcontrols); |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1487 | kfree(w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1488 | kfree(w); |
| 1489 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1490 | } |
| 1491 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1492 | static struct snd_soc_dapm_widget *dapm_find_widget( |
| 1493 | struct snd_soc_dapm_context *dapm, const char *pin, |
| 1494 | bool search_other_contexts) |
| 1495 | { |
| 1496 | struct snd_soc_dapm_widget *w; |
| 1497 | struct snd_soc_dapm_widget *fallback = NULL; |
| 1498 | |
| 1499 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 1500 | if (!strcmp(w->name, pin)) { |
| 1501 | if (w->dapm == dapm) |
| 1502 | return w; |
| 1503 | else |
| 1504 | fallback = w; |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | if (search_other_contexts) |
| 1509 | return fallback; |
| 1510 | |
| 1511 | return NULL; |
| 1512 | } |
| 1513 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1514 | 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] | 1515 | const char *pin, int status) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1516 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1517 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1518 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1519 | if (!w) { |
| 1520 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 1521 | return -EINVAL; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1522 | } |
| 1523 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1524 | w->connected = status; |
| 1525 | if (status == 0) |
| 1526 | w->force = 0; |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 1527 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1528 | return 0; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1529 | } |
| 1530 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1531 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1532 | * snd_soc_dapm_sync - scan and power dapm paths |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1533 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1534 | * |
| 1535 | * Walks all dapm audio paths and powers widgets according to their |
| 1536 | * stream or path usage. |
| 1537 | * |
| 1538 | * Returns 0 for success. |
| 1539 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1540 | int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1541 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1542 | return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1543 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1544 | EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1545 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1546 | 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] | 1547 | const struct snd_soc_dapm_route *route) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1548 | { |
| 1549 | struct snd_soc_dapm_path *path; |
| 1550 | struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w; |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1551 | struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1552 | const char *sink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1553 | const char *control = route->control; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1554 | const char *source; |
| 1555 | char prefixed_sink[80]; |
| 1556 | char prefixed_source[80]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1557 | int ret = 0; |
| 1558 | |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 1559 | if (dapm->codec && dapm->codec->name_prefix) { |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1560 | snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s", |
| 1561 | dapm->codec->name_prefix, route->sink); |
| 1562 | sink = prefixed_sink; |
| 1563 | snprintf(prefixed_source, sizeof(prefixed_source), "%s %s", |
| 1564 | dapm->codec->name_prefix, route->source); |
| 1565 | source = prefixed_source; |
| 1566 | } else { |
| 1567 | sink = route->sink; |
| 1568 | source = route->source; |
| 1569 | } |
| 1570 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1571 | /* |
| 1572 | * find src and dest widgets over all widgets but favor a widget from |
| 1573 | * current DAPM context |
| 1574 | */ |
| 1575 | list_for_each_entry(w, &dapm->card->widgets, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1576 | if (!wsink && !(strcmp(w->name, sink))) { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1577 | wtsink = w; |
| 1578 | if (w->dapm == dapm) |
| 1579 | wsink = w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1580 | continue; |
| 1581 | } |
| 1582 | if (!wsource && !(strcmp(w->name, source))) { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1583 | wtsource = w; |
| 1584 | if (w->dapm == dapm) |
| 1585 | wsource = w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1586 | } |
| 1587 | } |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1588 | /* use widget from another DAPM context if not found from this */ |
| 1589 | if (!wsink) |
| 1590 | wsink = wtsink; |
| 1591 | if (!wsource) |
| 1592 | wsource = wtsource; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1593 | |
| 1594 | if (wsource == NULL || wsink == NULL) |
| 1595 | return -ENODEV; |
| 1596 | |
| 1597 | path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL); |
| 1598 | if (!path) |
| 1599 | return -ENOMEM; |
| 1600 | |
| 1601 | path->source = wsource; |
| 1602 | path->sink = wsink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1603 | path->connected = route->connected; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1604 | INIT_LIST_HEAD(&path->list); |
| 1605 | INIT_LIST_HEAD(&path->list_source); |
| 1606 | INIT_LIST_HEAD(&path->list_sink); |
| 1607 | |
| 1608 | /* check for external widgets */ |
| 1609 | if (wsink->id == snd_soc_dapm_input) { |
| 1610 | if (wsource->id == snd_soc_dapm_micbias || |
| 1611 | wsource->id == snd_soc_dapm_mic || |
Rongrong Cao | 087d53a | 2009-07-10 20:13:30 +0100 | [diff] [blame] | 1612 | wsource->id == snd_soc_dapm_line || |
| 1613 | wsource->id == snd_soc_dapm_output) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1614 | wsink->ext = 1; |
| 1615 | } |
| 1616 | if (wsource->id == snd_soc_dapm_output) { |
| 1617 | if (wsink->id == snd_soc_dapm_spk || |
| 1618 | wsink->id == snd_soc_dapm_hp || |
Seth Forshee | 1e39221 | 2007-04-16 15:36:42 +0200 | [diff] [blame] | 1619 | wsink->id == snd_soc_dapm_line || |
| 1620 | wsink->id == snd_soc_dapm_input) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1621 | wsource->ext = 1; |
| 1622 | } |
| 1623 | |
| 1624 | /* connect static paths */ |
| 1625 | if (control == NULL) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1626 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1627 | list_add(&path->list_sink, &wsink->sources); |
| 1628 | list_add(&path->list_source, &wsource->sinks); |
| 1629 | path->connect = 1; |
| 1630 | return 0; |
| 1631 | } |
| 1632 | |
| 1633 | /* connect dynamic paths */ |
Lu Guanqun | dc2bea6 | 2011-04-20 16:00:36 +0800 | [diff] [blame] | 1634 | switch (wsink->id) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1635 | case snd_soc_dapm_adc: |
| 1636 | case snd_soc_dapm_dac: |
| 1637 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 1638 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1639 | case snd_soc_dapm_input: |
| 1640 | case snd_soc_dapm_output: |
| 1641 | case snd_soc_dapm_micbias: |
| 1642 | case snd_soc_dapm_vmid: |
| 1643 | case snd_soc_dapm_pre: |
| 1644 | case snd_soc_dapm_post: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1645 | case snd_soc_dapm_supply: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 1646 | case snd_soc_dapm_aif_in: |
| 1647 | case snd_soc_dapm_aif_out: |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1648 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1649 | list_add(&path->list_sink, &wsink->sources); |
| 1650 | list_add(&path->list_source, &wsource->sinks); |
| 1651 | path->connect = 1; |
| 1652 | return 0; |
| 1653 | case snd_soc_dapm_mux: |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 1654 | case snd_soc_dapm_virt_mux: |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 1655 | case snd_soc_dapm_value_mux: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1656 | ret = dapm_connect_mux(dapm, wsource, wsink, path, control, |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 1657 | &wsink->kcontrol_news[0]); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1658 | if (ret != 0) |
| 1659 | goto err; |
| 1660 | break; |
| 1661 | case snd_soc_dapm_switch: |
| 1662 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1663 | case snd_soc_dapm_mixer_named_ctl: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1664 | ret = dapm_connect_mixer(dapm, wsource, wsink, path, control); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1665 | if (ret != 0) |
| 1666 | goto err; |
| 1667 | break; |
| 1668 | case snd_soc_dapm_hp: |
| 1669 | case snd_soc_dapm_mic: |
| 1670 | case snd_soc_dapm_line: |
| 1671 | case snd_soc_dapm_spk: |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1672 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1673 | list_add(&path->list_sink, &wsink->sources); |
| 1674 | list_add(&path->list_source, &wsource->sinks); |
| 1675 | path->connect = 0; |
| 1676 | return 0; |
| 1677 | } |
| 1678 | return 0; |
| 1679 | |
| 1680 | err: |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 1681 | dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n", |
| 1682 | source, control, sink); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1683 | kfree(path); |
| 1684 | return ret; |
| 1685 | } |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1686 | |
| 1687 | /** |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1688 | * snd_soc_dapm_add_routes - Add routes between DAPM widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1689 | * @dapm: DAPM context |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1690 | * @route: audio routes |
| 1691 | * @num: number of routes |
| 1692 | * |
| 1693 | * Connects 2 dapm widgets together via a named audio path. The sink is |
| 1694 | * the widget receiving the audio signal, whilst the source is the sender |
| 1695 | * of the audio signal. |
| 1696 | * |
| 1697 | * Returns 0 for success else error. On error all resources can be freed |
| 1698 | * with a call to snd_soc_card_free(). |
| 1699 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1700 | int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm, |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1701 | const struct snd_soc_dapm_route *route, int num) |
| 1702 | { |
| 1703 | int i, ret; |
| 1704 | |
| 1705 | for (i = 0; i < num; i++) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1706 | ret = snd_soc_dapm_add_route(dapm, route); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1707 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 1708 | dev_err(dapm->dev, "Failed to add route %s->%s\n", |
| 1709 | route->source, route->sink); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1710 | return ret; |
| 1711 | } |
| 1712 | route++; |
| 1713 | } |
| 1714 | |
| 1715 | return 0; |
| 1716 | } |
| 1717 | EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes); |
| 1718 | |
| 1719 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1720 | * snd_soc_dapm_new_widgets - add new dapm widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1721 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1722 | * |
| 1723 | * Checks the codec for any new dapm widgets and creates them if found. |
| 1724 | * |
| 1725 | * Returns 0 for success. |
| 1726 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1727 | int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1728 | { |
| 1729 | struct snd_soc_dapm_widget *w; |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 1730 | unsigned int val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1731 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1732 | list_for_each_entry(w, &dapm->card->widgets, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1733 | { |
| 1734 | if (w->new) |
| 1735 | continue; |
| 1736 | |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame^] | 1737 | if (w->num_kcontrols) { |
| 1738 | w->kcontrols = kzalloc(w->num_kcontrols * |
| 1739 | sizeof(struct snd_kcontrol *), |
| 1740 | GFP_KERNEL); |
| 1741 | if (!w->kcontrols) |
| 1742 | return -ENOMEM; |
| 1743 | } |
| 1744 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1745 | switch(w->id) { |
| 1746 | case snd_soc_dapm_switch: |
| 1747 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1748 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1749 | w->power_check = dapm_generic_check_power; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1750 | dapm_new_mixer(dapm, w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1751 | break; |
| 1752 | case snd_soc_dapm_mux: |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 1753 | case snd_soc_dapm_virt_mux: |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1754 | case snd_soc_dapm_value_mux: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1755 | w->power_check = dapm_generic_check_power; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1756 | dapm_new_mux(dapm, w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1757 | break; |
| 1758 | case snd_soc_dapm_adc: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 1759 | case snd_soc_dapm_aif_out: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1760 | w->power_check = dapm_adc_check_power; |
| 1761 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1762 | case snd_soc_dapm_dac: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 1763 | case snd_soc_dapm_aif_in: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1764 | w->power_check = dapm_dac_check_power; |
| 1765 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1766 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 1767 | case snd_soc_dapm_out_drv: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1768 | w->power_check = dapm_generic_check_power; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1769 | dapm_new_pga(dapm, w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1770 | break; |
| 1771 | case snd_soc_dapm_input: |
| 1772 | case snd_soc_dapm_output: |
| 1773 | case snd_soc_dapm_micbias: |
| 1774 | case snd_soc_dapm_spk: |
| 1775 | case snd_soc_dapm_hp: |
| 1776 | case snd_soc_dapm_mic: |
| 1777 | case snd_soc_dapm_line: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1778 | w->power_check = dapm_generic_check_power; |
| 1779 | break; |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1780 | case snd_soc_dapm_supply: |
| 1781 | w->power_check = dapm_supply_check_power; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1782 | case snd_soc_dapm_vmid: |
| 1783 | case snd_soc_dapm_pre: |
| 1784 | case snd_soc_dapm_post: |
| 1785 | break; |
| 1786 | } |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 1787 | |
| 1788 | /* Read the initial power state from the device */ |
| 1789 | if (w->reg >= 0) { |
| 1790 | val = snd_soc_read(w->codec, w->reg); |
| 1791 | val &= 1 << w->shift; |
| 1792 | if (w->invert) |
| 1793 | val = !val; |
| 1794 | |
| 1795 | if (val) |
| 1796 | w->power = 1; |
| 1797 | } |
| 1798 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1799 | w->new = 1; |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1800 | |
| 1801 | dapm_debugfs_add_widget(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1802 | } |
| 1803 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1804 | dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1805 | return 0; |
| 1806 | } |
| 1807 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); |
| 1808 | |
| 1809 | /** |
| 1810 | * snd_soc_dapm_get_volsw - dapm mixer get callback |
| 1811 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1812 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1813 | * |
| 1814 | * Callback to get the value of a dapm mixer control. |
| 1815 | * |
| 1816 | * Returns 0 for success. |
| 1817 | */ |
| 1818 | int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, |
| 1819 | struct snd_ctl_elem_value *ucontrol) |
| 1820 | { |
| 1821 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1822 | struct soc_mixer_control *mc = |
| 1823 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1824 | unsigned int reg = mc->reg; |
| 1825 | unsigned int shift = mc->shift; |
| 1826 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1827 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1828 | unsigned int invert = mc->invert; |
| 1829 | unsigned int mask = (1 << fls(max)) - 1; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1830 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1831 | ucontrol->value.integer.value[0] = |
| 1832 | (snd_soc_read(widget->codec, reg) >> shift) & mask; |
| 1833 | if (shift != rshift) |
| 1834 | ucontrol->value.integer.value[1] = |
| 1835 | (snd_soc_read(widget->codec, reg) >> rshift) & mask; |
| 1836 | if (invert) { |
| 1837 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1838 | max - ucontrol->value.integer.value[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1839 | if (shift != rshift) |
| 1840 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1841 | max - ucontrol->value.integer.value[1]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | return 0; |
| 1845 | } |
| 1846 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw); |
| 1847 | |
| 1848 | /** |
| 1849 | * snd_soc_dapm_put_volsw - dapm mixer set callback |
| 1850 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1851 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1852 | * |
| 1853 | * Callback to set the value of a dapm mixer control. |
| 1854 | * |
| 1855 | * Returns 0 for success. |
| 1856 | */ |
| 1857 | int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, |
| 1858 | struct snd_ctl_elem_value *ucontrol) |
| 1859 | { |
| 1860 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1861 | struct soc_mixer_control *mc = |
| 1862 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1863 | unsigned int reg = mc->reg; |
| 1864 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1865 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1866 | unsigned int mask = (1 << fls(max)) - 1; |
| 1867 | unsigned int invert = mc->invert; |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 1868 | unsigned int val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1869 | int connect, change; |
| 1870 | struct snd_soc_dapm_update update; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1871 | |
| 1872 | val = (ucontrol->value.integer.value[0] & mask); |
| 1873 | |
| 1874 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1875 | val = max - val; |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 1876 | mask = mask << shift; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1877 | val = val << shift; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1878 | |
| 1879 | mutex_lock(&widget->codec->mutex); |
| 1880 | widget->value = val; |
| 1881 | |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 1882 | change = snd_soc_test_bits(widget->codec, reg, mask, val); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1883 | if (change) { |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1884 | if (val) |
| 1885 | /* new connection */ |
| 1886 | connect = invert ? 0:1; |
| 1887 | else |
| 1888 | /* old connection must be powered down */ |
| 1889 | connect = invert ? 1:0; |
| 1890 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1891 | update.kcontrol = kcontrol; |
| 1892 | update.widget = widget; |
| 1893 | update.reg = reg; |
| 1894 | update.mask = mask; |
| 1895 | update.val = val; |
| 1896 | widget->dapm->update = &update; |
| 1897 | |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1898 | dapm_mixer_update_power(widget, kcontrol, connect); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1899 | |
| 1900 | widget->dapm->update = NULL; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1901 | } |
| 1902 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1903 | mutex_unlock(&widget->codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1904 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1905 | } |
| 1906 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); |
| 1907 | |
| 1908 | /** |
| 1909 | * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback |
| 1910 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1911 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1912 | * |
| 1913 | * Callback to get the value of a dapm enumerated double mixer control. |
| 1914 | * |
| 1915 | * Returns 0 for success. |
| 1916 | */ |
| 1917 | int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, |
| 1918 | struct snd_ctl_elem_value *ucontrol) |
| 1919 | { |
| 1920 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
| 1921 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 1922 | unsigned int val, bitmask; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1923 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1924 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1925 | ; |
| 1926 | val = snd_soc_read(widget->codec, e->reg); |
| 1927 | ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1); |
| 1928 | if (e->shift_l != e->shift_r) |
| 1929 | ucontrol->value.enumerated.item[1] = |
| 1930 | (val >> e->shift_r) & (bitmask - 1); |
| 1931 | |
| 1932 | return 0; |
| 1933 | } |
| 1934 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double); |
| 1935 | |
| 1936 | /** |
| 1937 | * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback |
| 1938 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1939 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1940 | * |
| 1941 | * Callback to set the value of a dapm enumerated double mixer control. |
| 1942 | * |
| 1943 | * Returns 0 for success. |
| 1944 | */ |
| 1945 | int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, |
| 1946 | struct snd_ctl_elem_value *ucontrol) |
| 1947 | { |
| 1948 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
| 1949 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1950 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 1951 | unsigned int mask, bitmask; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1952 | struct snd_soc_dapm_update update; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1953 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1954 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1955 | ; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1956 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1957 | return -EINVAL; |
| 1958 | mux = ucontrol->value.enumerated.item[0]; |
| 1959 | val = mux << e->shift_l; |
| 1960 | mask = (bitmask - 1) << e->shift_l; |
| 1961 | if (e->shift_l != e->shift_r) { |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1962 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1963 | return -EINVAL; |
| 1964 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; |
| 1965 | mask |= (bitmask - 1) << e->shift_r; |
| 1966 | } |
| 1967 | |
| 1968 | mutex_lock(&widget->codec->mutex); |
| 1969 | widget->value = val; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1970 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1971 | |
| 1972 | update.kcontrol = kcontrol; |
| 1973 | update.widget = widget; |
| 1974 | update.reg = e->reg; |
| 1975 | update.mask = mask; |
| 1976 | update.val = val; |
| 1977 | widget->dapm->update = &update; |
| 1978 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1979 | dapm_mux_update_power(widget, kcontrol, change, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 1980 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1981 | widget->dapm->update = NULL; |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 1982 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1983 | mutex_unlock(&widget->codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1984 | return change; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1985 | } |
| 1986 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); |
| 1987 | |
| 1988 | /** |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 1989 | * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux |
| 1990 | * @kcontrol: mixer control |
| 1991 | * @ucontrol: control element information |
| 1992 | * |
| 1993 | * Returns 0 for success. |
| 1994 | */ |
| 1995 | int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol, |
| 1996 | struct snd_ctl_elem_value *ucontrol) |
| 1997 | { |
| 1998 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
| 1999 | |
| 2000 | ucontrol->value.enumerated.item[0] = widget->value; |
| 2001 | |
| 2002 | return 0; |
| 2003 | } |
| 2004 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt); |
| 2005 | |
| 2006 | /** |
| 2007 | * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux |
| 2008 | * @kcontrol: mixer control |
| 2009 | * @ucontrol: control element information |
| 2010 | * |
| 2011 | * Returns 0 for success. |
| 2012 | */ |
| 2013 | int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol, |
| 2014 | struct snd_ctl_elem_value *ucontrol) |
| 2015 | { |
| 2016 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
| 2017 | struct soc_enum *e = |
| 2018 | (struct soc_enum *)kcontrol->private_value; |
| 2019 | int change; |
| 2020 | int ret = 0; |
| 2021 | |
| 2022 | if (ucontrol->value.enumerated.item[0] >= e->max) |
| 2023 | return -EINVAL; |
| 2024 | |
| 2025 | mutex_lock(&widget->codec->mutex); |
| 2026 | |
| 2027 | change = widget->value != ucontrol->value.enumerated.item[0]; |
| 2028 | widget->value = ucontrol->value.enumerated.item[0]; |
| 2029 | dapm_mux_update_power(widget, kcontrol, change, widget->value, e); |
| 2030 | |
| 2031 | mutex_unlock(&widget->codec->mutex); |
| 2032 | return ret; |
| 2033 | } |
| 2034 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt); |
| 2035 | |
| 2036 | /** |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2037 | * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get |
| 2038 | * callback |
| 2039 | * @kcontrol: mixer control |
| 2040 | * @ucontrol: control element information |
| 2041 | * |
| 2042 | * Callback to get the value of a dapm semi enumerated double mixer control. |
| 2043 | * |
| 2044 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2045 | * used for handling bitfield coded enumeration for example. |
| 2046 | * |
| 2047 | * Returns 0 for success. |
| 2048 | */ |
| 2049 | int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2050 | struct snd_ctl_elem_value *ucontrol) |
| 2051 | { |
| 2052 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2053 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2054 | unsigned int reg_val, val, mux; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2055 | |
| 2056 | reg_val = snd_soc_read(widget->codec, e->reg); |
| 2057 | val = (reg_val >> e->shift_l) & e->mask; |
| 2058 | for (mux = 0; mux < e->max; mux++) { |
| 2059 | if (val == e->values[mux]) |
| 2060 | break; |
| 2061 | } |
| 2062 | ucontrol->value.enumerated.item[0] = mux; |
| 2063 | if (e->shift_l != e->shift_r) { |
| 2064 | val = (reg_val >> e->shift_r) & e->mask; |
| 2065 | for (mux = 0; mux < e->max; mux++) { |
| 2066 | if (val == e->values[mux]) |
| 2067 | break; |
| 2068 | } |
| 2069 | ucontrol->value.enumerated.item[1] = mux; |
| 2070 | } |
| 2071 | |
| 2072 | return 0; |
| 2073 | } |
| 2074 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double); |
| 2075 | |
| 2076 | /** |
| 2077 | * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set |
| 2078 | * callback |
| 2079 | * @kcontrol: mixer control |
| 2080 | * @ucontrol: control element information |
| 2081 | * |
| 2082 | * Callback to set the value of a dapm semi enumerated double mixer control. |
| 2083 | * |
| 2084 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2085 | * used for handling bitfield coded enumeration for example. |
| 2086 | * |
| 2087 | * Returns 0 for success. |
| 2088 | */ |
| 2089 | int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2090 | struct snd_ctl_elem_value *ucontrol) |
| 2091 | { |
| 2092 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2093 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2094 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2095 | unsigned int mask; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2096 | struct snd_soc_dapm_update update; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2097 | |
| 2098 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 2099 | return -EINVAL; |
| 2100 | mux = ucontrol->value.enumerated.item[0]; |
| 2101 | val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; |
| 2102 | mask = e->mask << e->shift_l; |
| 2103 | if (e->shift_l != e->shift_r) { |
| 2104 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
| 2105 | return -EINVAL; |
| 2106 | val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; |
| 2107 | mask |= e->mask << e->shift_r; |
| 2108 | } |
| 2109 | |
| 2110 | mutex_lock(&widget->codec->mutex); |
| 2111 | widget->value = val; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2112 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2113 | |
| 2114 | update.kcontrol = kcontrol; |
| 2115 | update.widget = widget; |
| 2116 | update.reg = e->reg; |
| 2117 | update.mask = mask; |
| 2118 | update.val = val; |
| 2119 | widget->dapm->update = &update; |
| 2120 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2121 | dapm_mux_update_power(widget, kcontrol, change, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2122 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2123 | widget->dapm->update = NULL; |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2124 | |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2125 | mutex_unlock(&widget->codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2126 | return change; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2127 | } |
| 2128 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); |
| 2129 | |
| 2130 | /** |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2131 | * snd_soc_dapm_info_pin_switch - Info for a pin switch |
| 2132 | * |
| 2133 | * @kcontrol: mixer control |
| 2134 | * @uinfo: control element information |
| 2135 | * |
| 2136 | * Callback to provide information about a pin switch control. |
| 2137 | */ |
| 2138 | int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol, |
| 2139 | struct snd_ctl_elem_info *uinfo) |
| 2140 | { |
| 2141 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2142 | uinfo->count = 1; |
| 2143 | uinfo->value.integer.min = 0; |
| 2144 | uinfo->value.integer.max = 1; |
| 2145 | |
| 2146 | return 0; |
| 2147 | } |
| 2148 | EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch); |
| 2149 | |
| 2150 | /** |
| 2151 | * snd_soc_dapm_get_pin_switch - Get information for a pin switch |
| 2152 | * |
| 2153 | * @kcontrol: mixer control |
| 2154 | * @ucontrol: Value |
| 2155 | */ |
| 2156 | int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol, |
| 2157 | struct snd_ctl_elem_value *ucontrol) |
| 2158 | { |
| 2159 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2160 | const char *pin = (const char *)kcontrol->private_value; |
| 2161 | |
| 2162 | mutex_lock(&codec->mutex); |
| 2163 | |
| 2164 | ucontrol->value.integer.value[0] = |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2165 | snd_soc_dapm_get_pin_status(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2166 | |
| 2167 | mutex_unlock(&codec->mutex); |
| 2168 | |
| 2169 | return 0; |
| 2170 | } |
| 2171 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch); |
| 2172 | |
| 2173 | /** |
| 2174 | * snd_soc_dapm_put_pin_switch - Set information for a pin switch |
| 2175 | * |
| 2176 | * @kcontrol: mixer control |
| 2177 | * @ucontrol: Value |
| 2178 | */ |
| 2179 | int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol, |
| 2180 | struct snd_ctl_elem_value *ucontrol) |
| 2181 | { |
| 2182 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2183 | const char *pin = (const char *)kcontrol->private_value; |
| 2184 | |
| 2185 | mutex_lock(&codec->mutex); |
| 2186 | |
| 2187 | if (ucontrol->value.integer.value[0]) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2188 | snd_soc_dapm_enable_pin(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2189 | else |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2190 | snd_soc_dapm_disable_pin(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2191 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2192 | snd_soc_dapm_sync(&codec->dapm); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2193 | |
| 2194 | mutex_unlock(&codec->mutex); |
| 2195 | |
| 2196 | return 0; |
| 2197 | } |
| 2198 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch); |
| 2199 | |
| 2200 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2201 | * snd_soc_dapm_new_control - create new dapm control |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2202 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2203 | * @widget: widget template |
| 2204 | * |
| 2205 | * Creates a new dapm control based upon the template. |
| 2206 | * |
| 2207 | * Returns 0 for success else error. |
| 2208 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2209 | int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2210 | const struct snd_soc_dapm_widget *widget) |
| 2211 | { |
| 2212 | struct snd_soc_dapm_widget *w; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2213 | size_t name_len; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2214 | |
| 2215 | if ((w = dapm_cnew_widget(widget)) == NULL) |
| 2216 | return -ENOMEM; |
| 2217 | |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2218 | name_len = strlen(widget->name) + 1; |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 2219 | if (dapm->codec && dapm->codec->name_prefix) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2220 | name_len += 1 + strlen(dapm->codec->name_prefix); |
| 2221 | w->name = kmalloc(name_len, GFP_KERNEL); |
| 2222 | if (w->name == NULL) { |
| 2223 | kfree(w); |
| 2224 | return -ENOMEM; |
| 2225 | } |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 2226 | if (dapm->codec && dapm->codec->name_prefix) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2227 | snprintf(w->name, name_len, "%s %s", |
| 2228 | dapm->codec->name_prefix, widget->name); |
| 2229 | else |
| 2230 | snprintf(w->name, name_len, "%s", widget->name); |
| 2231 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2232 | dapm->n_widgets++; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2233 | w->dapm = dapm; |
| 2234 | w->codec = dapm->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2235 | INIT_LIST_HEAD(&w->sources); |
| 2236 | INIT_LIST_HEAD(&w->sinks); |
| 2237 | INIT_LIST_HEAD(&w->list); |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2238 | list_add(&w->list, &dapm->card->widgets); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2239 | |
| 2240 | /* machine layer set ups unconnected pins and insertions */ |
| 2241 | w->connected = 1; |
| 2242 | return 0; |
| 2243 | } |
| 2244 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control); |
| 2245 | |
| 2246 | /** |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2247 | * snd_soc_dapm_new_controls - create new dapm controls |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2248 | * @dapm: DAPM context |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2249 | * @widget: widget array |
| 2250 | * @num: number of widgets |
| 2251 | * |
| 2252 | * Creates new DAPM controls based upon the templates. |
| 2253 | * |
| 2254 | * Returns 0 for success else error. |
| 2255 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2256 | int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm, |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2257 | const struct snd_soc_dapm_widget *widget, |
| 2258 | int num) |
| 2259 | { |
| 2260 | int i, ret; |
| 2261 | |
| 2262 | for (i = 0; i < num; i++) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2263 | ret = snd_soc_dapm_new_control(dapm, widget); |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 2264 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2265 | dev_err(dapm->dev, |
| 2266 | "ASoC: Failed to create DAPM control %s: %d\n", |
| 2267 | widget->name, ret); |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2268 | return ret; |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 2269 | } |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2270 | widget++; |
| 2271 | } |
| 2272 | return 0; |
| 2273 | } |
| 2274 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); |
| 2275 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2276 | static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2277 | const char *stream, int event) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2278 | { |
| 2279 | struct snd_soc_dapm_widget *w; |
| 2280 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2281 | list_for_each_entry(w, &dapm->card->widgets, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2282 | { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2283 | if (!w->sname || w->dapm != dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2284 | continue; |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2285 | dev_dbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n", |
| 2286 | w->name, w->sname, stream, event); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2287 | if (strstr(w->sname, stream)) { |
| 2288 | switch(event) { |
| 2289 | case SND_SOC_DAPM_STREAM_START: |
| 2290 | w->active = 1; |
| 2291 | break; |
| 2292 | case SND_SOC_DAPM_STREAM_STOP: |
| 2293 | w->active = 0; |
| 2294 | break; |
| 2295 | case SND_SOC_DAPM_STREAM_SUSPEND: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2296 | case SND_SOC_DAPM_STREAM_RESUME: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2297 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2298 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: |
| 2299 | break; |
| 2300 | } |
| 2301 | } |
| 2302 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2303 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2304 | dapm_power_widgets(dapm, event); |
| 2305 | } |
| 2306 | |
| 2307 | /** |
| 2308 | * snd_soc_dapm_stream_event - send a stream event to the dapm core |
| 2309 | * @rtd: PCM runtime data |
| 2310 | * @stream: stream name |
| 2311 | * @event: stream event |
| 2312 | * |
| 2313 | * Sends a stream event to the dapm core. The core then makes any |
| 2314 | * necessary widget power changes. |
| 2315 | * |
| 2316 | * Returns 0 for success else error. |
| 2317 | */ |
| 2318 | int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, |
| 2319 | const char *stream, int event) |
| 2320 | { |
| 2321 | struct snd_soc_codec *codec = rtd->codec; |
| 2322 | |
| 2323 | if (stream == NULL) |
| 2324 | return 0; |
| 2325 | |
| 2326 | mutex_lock(&codec->mutex); |
| 2327 | soc_dapm_stream_event(&codec->dapm, stream, event); |
Eero Nurkkala | 8e8b2d6 | 2009-10-12 08:41:59 +0300 | [diff] [blame] | 2328 | mutex_unlock(&codec->mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2329 | return 0; |
| 2330 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2331 | |
| 2332 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2333 | * snd_soc_dapm_enable_pin - enable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2334 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2335 | * @pin: pin name |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2336 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 2337 | * 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] | 2338 | * a valid audio route and active audio stream. |
| 2339 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2340 | * do any widget power switching. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2341 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2342 | 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] | 2343 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2344 | return snd_soc_dapm_set_pin(dapm, pin, 1); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2345 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2346 | EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2347 | |
| 2348 | /** |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2349 | * snd_soc_dapm_force_enable_pin - force a pin to be enabled |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2350 | * @dapm: DAPM context |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2351 | * @pin: pin name |
| 2352 | * |
| 2353 | * Enables input/output pin regardless of any other state. This is |
| 2354 | * intended for use with microphone bias supplies used in microphone |
| 2355 | * jack detection. |
| 2356 | * |
| 2357 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2358 | * do any widget power switching. |
| 2359 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2360 | int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm, |
| 2361 | const char *pin) |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2362 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2363 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2364 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2365 | if (!w) { |
| 2366 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 2367 | return -EINVAL; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2368 | } |
| 2369 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2370 | dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin); |
| 2371 | w->connected = 1; |
| 2372 | w->force = 1; |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 2373 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2374 | return 0; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2375 | } |
| 2376 | EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin); |
| 2377 | |
| 2378 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2379 | * snd_soc_dapm_disable_pin - disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2380 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2381 | * @pin: pin name |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2382 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 2383 | * Disables input/output pin and its parents or children widgets. |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2384 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2385 | * do any widget power switching. |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2386 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2387 | int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm, |
| 2388 | const char *pin) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2389 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2390 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2391 | } |
| 2392 | EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin); |
| 2393 | |
| 2394 | /** |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2395 | * snd_soc_dapm_nc_pin - permanently disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2396 | * @dapm: DAPM context |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2397 | * @pin: pin name |
| 2398 | * |
| 2399 | * Marks the specified pin as being not connected, disabling it along |
| 2400 | * any parent or child widgets. At present this is identical to |
| 2401 | * snd_soc_dapm_disable_pin() but in future it will be extended to do |
| 2402 | * additional things such as disabling controls which only affect |
| 2403 | * paths through the pin. |
| 2404 | * |
| 2405 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2406 | * do any widget power switching. |
| 2407 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2408 | 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] | 2409 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2410 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2411 | } |
| 2412 | EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin); |
| 2413 | |
| 2414 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2415 | * snd_soc_dapm_get_pin_status - get audio pin status |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2416 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2417 | * @pin: audio signal pin endpoint (or start point) |
| 2418 | * |
| 2419 | * Get audio pin status - connected or disconnected. |
| 2420 | * |
| 2421 | * Returns 1 for connected otherwise 0. |
| 2422 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2423 | int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm, |
| 2424 | const char *pin) |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2425 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2426 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2427 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2428 | if (w) |
| 2429 | return w->connected; |
Stephen Warren | a68b38a | 2011-04-19 15:25:11 -0600 | [diff] [blame] | 2430 | |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2431 | return 0; |
| 2432 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2433 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2434 | |
| 2435 | /** |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2436 | * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2437 | * @dapm: DAPM context |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2438 | * @pin: audio signal pin endpoint (or start point) |
| 2439 | * |
| 2440 | * Mark the given endpoint or pin as ignoring suspend. When the |
| 2441 | * system is disabled a path between two endpoints flagged as ignoring |
| 2442 | * suspend will not be disabled. The path must already be enabled via |
| 2443 | * normal means at suspend time, it will not be turned on if it was not |
| 2444 | * already enabled. |
| 2445 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2446 | int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm, |
| 2447 | const char *pin) |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2448 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2449 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2450 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2451 | if (!w) { |
| 2452 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 2453 | return -EINVAL; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2454 | } |
| 2455 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2456 | w->ignore_suspend = 1; |
| 2457 | |
| 2458 | return 0; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2459 | } |
| 2460 | EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend); |
| 2461 | |
| 2462 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2463 | * snd_soc_dapm_free - free dapm resources |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2464 | * @card: SoC device |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2465 | * |
| 2466 | * Free all dapm widgets and resources. |
| 2467 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2468 | void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2469 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2470 | snd_soc_dapm_sys_remove(dapm->dev); |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 2471 | dapm_debugfs_cleanup(dapm); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2472 | dapm_free_widgets(dapm); |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 2473 | list_del(&dapm->list); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2474 | } |
| 2475 | EXPORT_SYMBOL_GPL(snd_soc_dapm_free); |
| 2476 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2477 | static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2478 | { |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2479 | struct snd_soc_dapm_widget *w; |
| 2480 | LIST_HEAD(down_list); |
| 2481 | int powerdown = 0; |
| 2482 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2483 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 2484 | if (w->dapm != dapm) |
| 2485 | continue; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2486 | if (w->power) { |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 2487 | dapm_seq_insert(w, &down_list, false); |
Mark Brown | c2caa4d | 2009-06-26 15:36:56 +0100 | [diff] [blame] | 2488 | w->power = 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2489 | powerdown = 1; |
| 2490 | } |
| 2491 | } |
| 2492 | |
| 2493 | /* If there were no widgets to power down we're already in |
| 2494 | * standby. |
| 2495 | */ |
| 2496 | if (powerdown) { |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 2497 | snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE); |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 2498 | dapm_seq_run(dapm, &down_list, 0, false); |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 2499 | snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2500 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2501 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2502 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2503 | /* |
| 2504 | * snd_soc_dapm_shutdown - callback for system shutdown |
| 2505 | */ |
| 2506 | void snd_soc_dapm_shutdown(struct snd_soc_card *card) |
| 2507 | { |
| 2508 | struct snd_soc_codec *codec; |
| 2509 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2510 | list_for_each_entry(codec, &card->codec_dev_list, list) { |
| 2511 | soc_dapm_shutdown_codec(&codec->dapm); |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 2512 | snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2513 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2514 | } |
| 2515 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2516 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 2517 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2518 | MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC"); |
| 2519 | MODULE_LICENSE("GPL"); |