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