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