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