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