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