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