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