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