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