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