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