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 | 815ecf8d | 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 | 815ecf8d | 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) { |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 921 | pop_dbg(dapm->dev, card->pop_time, |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 922 | "pop test : Applying 0x%x/0x%x to %x in %dms\n", |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 923 | value, mask, reg, card->pop_time); |
| 924 | pop_wait(card->pop_time); |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame^] | 925 | soc_widget_update_bits(w, reg, mask, value); |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | list_for_each_entry(w, pending, power_list) { |
Mark Brown | 68f89ad | 2010-11-03 23:51:49 -0400 | [diff] [blame] | 929 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU); |
| 930 | dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD); |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 931 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 932 | } |
| 933 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 934 | /* Apply a DAPM power sequence. |
| 935 | * |
| 936 | * We walk over a pre-sorted list of widgets to apply power to. In |
| 937 | * order to minimise the number of writes to the device required |
| 938 | * multiple widgets will be updated in a single write where possible. |
| 939 | * Currently anything that requires more than a single write is not |
| 940 | * handled. |
| 941 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 942 | static void dapm_seq_run(struct snd_soc_dapm_context *dapm, |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 943 | struct list_head *list, int event, bool power_up) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 944 | { |
| 945 | struct snd_soc_dapm_widget *w, *n; |
| 946 | LIST_HEAD(pending); |
| 947 | int cur_sort = -1; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 948 | int cur_subseq = -1; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 949 | int cur_reg = SND_SOC_NOPM; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 950 | struct snd_soc_dapm_context *cur_dapm = NULL; |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 951 | int ret, i; |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 952 | int *sort; |
| 953 | |
| 954 | if (power_up) |
| 955 | sort = dapm_up_seq; |
| 956 | else |
| 957 | sort = dapm_down_seq; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 958 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 959 | list_for_each_entry_safe(w, n, list, power_list) { |
| 960 | ret = 0; |
| 961 | |
| 962 | /* Do we need to apply any queued changes? */ |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 963 | if (sort[w->id] != cur_sort || w->reg != cur_reg || |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 964 | w->dapm != cur_dapm || w->subseq != cur_subseq) { |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 965 | if (!list_empty(&pending)) |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 966 | dapm_seq_run_coalesced(cur_dapm, &pending); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 967 | |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 968 | if (cur_dapm && cur_dapm->seq_notifier) { |
| 969 | for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) |
| 970 | if (sort[i] == cur_sort) |
| 971 | cur_dapm->seq_notifier(cur_dapm, |
Mark Brown | f85a9e0 | 2011-01-26 21:41:28 +0000 | [diff] [blame] | 972 | i, |
| 973 | cur_subseq); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 974 | } |
| 975 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 976 | INIT_LIST_HEAD(&pending); |
| 977 | cur_sort = -1; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 978 | cur_subseq = -1; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 979 | cur_reg = SND_SOC_NOPM; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 980 | cur_dapm = NULL; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 981 | } |
| 982 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 983 | switch (w->id) { |
| 984 | case snd_soc_dapm_pre: |
| 985 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 986 | list_for_each_entry_safe_continue(w, n, list, |
| 987 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 988 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 989 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 990 | ret = w->event(w, |
| 991 | NULL, SND_SOC_DAPM_PRE_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 992 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 993 | ret = w->event(w, |
| 994 | NULL, SND_SOC_DAPM_PRE_PMD); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 995 | break; |
| 996 | |
| 997 | case snd_soc_dapm_post: |
| 998 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 999 | list_for_each_entry_safe_continue(w, n, list, |
| 1000 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1001 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1002 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1003 | ret = w->event(w, |
| 1004 | NULL, SND_SOC_DAPM_POST_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1005 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1006 | ret = w->event(w, |
| 1007 | NULL, SND_SOC_DAPM_POST_PMD); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1008 | break; |
| 1009 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1010 | default: |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1011 | /* Queue it up for application */ |
| 1012 | cur_sort = sort[w->id]; |
Mark Brown | 20e4859 | 2011-01-15 13:40:50 +0000 | [diff] [blame] | 1013 | cur_subseq = w->subseq; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1014 | cur_reg = w->reg; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1015 | cur_dapm = w->dapm; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 1016 | list_move(&w->power_list, &pending); |
| 1017 | break; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1018 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1019 | |
| 1020 | if (ret < 0) |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 1021 | dev_err(w->dapm->dev, |
| 1022 | "Failed to apply widget power: %d\n", ret); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1023 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 1024 | |
| 1025 | if (!list_empty(&pending)) |
Mark Brown | 28e8680 | 2011-03-08 19:29:53 +0000 | [diff] [blame] | 1026 | dapm_seq_run_coalesced(cur_dapm, &pending); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1027 | |
| 1028 | if (cur_dapm && cur_dapm->seq_notifier) { |
| 1029 | for (i = 0; i < ARRAY_SIZE(dapm_up_seq); i++) |
| 1030 | if (sort[i] == cur_sort) |
| 1031 | cur_dapm->seq_notifier(cur_dapm, |
Mark Brown | f85a9e0 | 2011-01-26 21:41:28 +0000 | [diff] [blame] | 1032 | i, cur_subseq); |
Mark Brown | 474b62d | 2011-01-18 16:14:44 +0000 | [diff] [blame] | 1033 | } |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 1034 | } |
| 1035 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1036 | static void dapm_widget_update(struct snd_soc_dapm_context *dapm) |
| 1037 | { |
| 1038 | struct snd_soc_dapm_update *update = dapm->update; |
| 1039 | struct snd_soc_dapm_widget *w; |
| 1040 | int ret; |
| 1041 | |
| 1042 | if (!update) |
| 1043 | return; |
| 1044 | |
| 1045 | w = update->widget; |
| 1046 | |
| 1047 | if (w->event && |
| 1048 | (w->event_flags & SND_SOC_DAPM_PRE_REG)) { |
| 1049 | ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG); |
| 1050 | if (ret != 0) |
| 1051 | pr_err("%s DAPM pre-event failed: %d\n", |
| 1052 | w->name, ret); |
| 1053 | } |
| 1054 | |
| 1055 | ret = snd_soc_update_bits(w->codec, update->reg, update->mask, |
| 1056 | update->val); |
| 1057 | if (ret < 0) |
| 1058 | pr_err("%s DAPM update failed: %d\n", w->name, ret); |
| 1059 | |
| 1060 | if (w->event && |
| 1061 | (w->event_flags & SND_SOC_DAPM_POST_REG)) { |
| 1062 | ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG); |
| 1063 | if (ret != 0) |
| 1064 | pr_err("%s DAPM post-event failed: %d\n", |
| 1065 | w->name, ret); |
| 1066 | } |
| 1067 | } |
| 1068 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1069 | /* Async callback run prior to DAPM sequences - brings to _PREPARE if |
| 1070 | * they're changing state. |
| 1071 | */ |
| 1072 | static void dapm_pre_sequence_async(void *data, async_cookie_t cookie) |
| 1073 | { |
| 1074 | struct snd_soc_dapm_context *d = data; |
| 1075 | int ret; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1076 | |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1077 | /* If we're off and we're not supposed to be go into STANDBY */ |
| 1078 | if (d->bias_level == SND_SOC_BIAS_OFF && |
| 1079 | d->target_bias_level != SND_SOC_BIAS_OFF) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1080 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY); |
| 1081 | if (ret != 0) |
| 1082 | dev_err(d->dev, |
| 1083 | "Failed to turn on bias: %d\n", ret); |
| 1084 | } |
| 1085 | |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1086 | /* Prepare for a STADDBY->ON or ON->STANDBY transition */ |
| 1087 | if (d->bias_level != d->target_bias_level) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1088 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_PREPARE); |
| 1089 | if (ret != 0) |
| 1090 | dev_err(d->dev, |
| 1091 | "Failed to prepare bias: %d\n", ret); |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | /* Async callback run prior to DAPM sequences - brings to their final |
| 1096 | * state. |
| 1097 | */ |
| 1098 | static void dapm_post_sequence_async(void *data, async_cookie_t cookie) |
| 1099 | { |
| 1100 | struct snd_soc_dapm_context *d = data; |
| 1101 | int ret; |
| 1102 | |
| 1103 | /* If we just powered the last thing off drop to standby bias */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1104 | if (d->bias_level == SND_SOC_BIAS_PREPARE && |
| 1105 | (d->target_bias_level == SND_SOC_BIAS_STANDBY || |
| 1106 | d->target_bias_level == SND_SOC_BIAS_OFF)) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1107 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY); |
| 1108 | if (ret != 0) |
| 1109 | dev_err(d->dev, "Failed to apply standby bias: %d\n", |
| 1110 | ret); |
| 1111 | } |
| 1112 | |
| 1113 | /* 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] | 1114 | if (d->bias_level == SND_SOC_BIAS_STANDBY && |
| 1115 | d->target_bias_level == SND_SOC_BIAS_OFF) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1116 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_OFF); |
| 1117 | if (ret != 0) |
| 1118 | dev_err(d->dev, "Failed to turn off bias: %d\n", ret); |
| 1119 | } |
| 1120 | |
| 1121 | /* If we just powered up then move to active bias */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1122 | if (d->bias_level == SND_SOC_BIAS_PREPARE && |
| 1123 | d->target_bias_level == SND_SOC_BIAS_ON) { |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1124 | ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_ON); |
| 1125 | if (ret != 0) |
| 1126 | dev_err(d->dev, "Failed to apply active bias: %d\n", |
| 1127 | ret); |
| 1128 | } |
| 1129 | } |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1130 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1131 | /* |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1132 | * Scan each dapm widget for complete audio path. |
| 1133 | * A complete path is a route that has valid endpoints i.e.:- |
| 1134 | * |
| 1135 | * o DAC to output pin. |
| 1136 | * o Input Pin to ADC. |
| 1137 | * o Input pin to Output pin (bypass, sidetone) |
| 1138 | * o DAC to ADC (loopback). |
| 1139 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1140 | 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] | 1141 | { |
Mark Brown | 12ea2c7 | 2011-03-02 18:17:32 +0000 | [diff] [blame] | 1142 | struct snd_soc_card *card = dapm->card; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1143 | struct snd_soc_dapm_widget *w; |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1144 | struct snd_soc_dapm_context *d; |
Mark Brown | 291f3bb | 2009-06-07 13:57:17 +0100 | [diff] [blame] | 1145 | LIST_HEAD(up_list); |
| 1146 | LIST_HEAD(down_list); |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1147 | LIST_HEAD(async_domain); |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1148 | enum snd_soc_bias_level bias; |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 1149 | int power; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1150 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1151 | trace_snd_soc_dapm_start(card); |
| 1152 | |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1153 | list_for_each_entry(d, &card->dapm_list, list) { |
| 1154 | if (d->n_widgets || d->codec == NULL) { |
| 1155 | if (d->idle_bias_off) |
| 1156 | d->target_bias_level = SND_SOC_BIAS_OFF; |
| 1157 | else |
| 1158 | d->target_bias_level = SND_SOC_BIAS_STANDBY; |
| 1159 | } |
| 1160 | } |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 1161 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1162 | /* Check which widgets we need to power and store them in |
| 1163 | * lists indicating if they should be powered up or down. |
| 1164 | */ |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1165 | list_for_each_entry(w, &card->widgets, list) { |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1166 | switch (w->id) { |
| 1167 | case snd_soc_dapm_pre: |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1168 | dapm_seq_insert(w, &down_list, false); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1169 | break; |
| 1170 | case snd_soc_dapm_post: |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1171 | dapm_seq_insert(w, &up_list, true); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1172 | break; |
| 1173 | |
| 1174 | default: |
| 1175 | if (!w->power_check) |
| 1176 | continue; |
| 1177 | |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 1178 | if (!w->force) |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1179 | power = w->power_check(w); |
Mark Brown | 9949788 | 2010-05-07 20:24:05 +0100 | [diff] [blame] | 1180 | else |
| 1181 | power = 1; |
Mark Brown | dfcc904 | 2011-06-04 11:34:43 +0100 | [diff] [blame] | 1182 | |
| 1183 | if (power) { |
| 1184 | d = w->dapm; |
| 1185 | |
| 1186 | /* Supplies and micbiases only bring |
| 1187 | * the context up to STANDBY as unless |
| 1188 | * something else is active and |
| 1189 | * passing audio they generally don't |
| 1190 | * require full power. |
| 1191 | */ |
| 1192 | switch (w->id) { |
| 1193 | case snd_soc_dapm_supply: |
| 1194 | case snd_soc_dapm_micbias: |
| 1195 | if (d->target_bias_level < SND_SOC_BIAS_STANDBY) |
| 1196 | d->target_bias_level = SND_SOC_BIAS_STANDBY; |
| 1197 | break; |
| 1198 | default: |
| 1199 | d->target_bias_level = SND_SOC_BIAS_ON; |
| 1200 | break; |
| 1201 | } |
| 1202 | } |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1203 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1204 | if (w->power == power) |
| 1205 | continue; |
| 1206 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1207 | trace_snd_soc_dapm_widget_power(w, power); |
| 1208 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1209 | if (power) |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1210 | dapm_seq_insert(w, &up_list, true); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1211 | else |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1212 | dapm_seq_insert(w, &down_list, false); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1213 | |
| 1214 | w->power = power; |
| 1215 | break; |
| 1216 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1217 | } |
| 1218 | |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1219 | /* If there are no DAPM widgets then try to figure out power from the |
| 1220 | * event type. |
| 1221 | */ |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1222 | if (!dapm->n_widgets) { |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1223 | switch (event) { |
| 1224 | case SND_SOC_DAPM_STREAM_START: |
| 1225 | case SND_SOC_DAPM_STREAM_RESUME: |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1226 | dapm->target_bias_level = SND_SOC_BIAS_ON; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1227 | break; |
Jarkko Nikula | 862af8a | 2010-12-10 20:53:55 +0200 | [diff] [blame] | 1228 | case SND_SOC_DAPM_STREAM_STOP: |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1229 | if (dapm->codec->active) |
| 1230 | dapm->target_bias_level = SND_SOC_BIAS_ON; |
| 1231 | else |
| 1232 | dapm->target_bias_level = SND_SOC_BIAS_STANDBY; |
Jarkko Nikula | 862af8a | 2010-12-10 20:53:55 +0200 | [diff] [blame] | 1233 | break; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1234 | case SND_SOC_DAPM_STREAM_SUSPEND: |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1235 | dapm->target_bias_level = SND_SOC_BIAS_STANDBY; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1236 | break; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1237 | case SND_SOC_DAPM_STREAM_NOP: |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1238 | dapm->target_bias_level = dapm->bias_level; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 1239 | break; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 1240 | default: |
| 1241 | break; |
| 1242 | } |
| 1243 | } |
| 1244 | |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1245 | /* Force all contexts in the card to the same bias state */ |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1246 | bias = SND_SOC_BIAS_OFF; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1247 | list_for_each_entry(d, &card->dapm_list, list) |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1248 | if (d->target_bias_level > bias) |
| 1249 | bias = d->target_bias_level; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1250 | list_for_each_entry(d, &card->dapm_list, list) |
Mark Brown | 56fba41 | 2011-06-04 11:25:10 +0100 | [diff] [blame] | 1251 | d->target_bias_level = bias; |
Mark Brown | 52ba67b | 2011-04-04 21:05:11 +0900 | [diff] [blame] | 1252 | |
| 1253 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1254 | /* Run all the bias changes in parallel */ |
| 1255 | list_for_each_entry(d, &dapm->card->dapm_list, list) |
| 1256 | async_schedule_domain(dapm_pre_sequence_async, d, |
| 1257 | &async_domain); |
| 1258 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1259 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1260 | /* Power down widgets first; try to avoid amplifying pops. */ |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1261 | dapm_seq_run(dapm, &down_list, event, false); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1262 | |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 1263 | dapm_widget_update(dapm); |
| 1264 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 1265 | /* Now power up. */ |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 1266 | dapm_seq_run(dapm, &up_list, event, true); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1267 | |
Mark Brown | 9d0624a | 2011-02-18 11:49:43 -0800 | [diff] [blame] | 1268 | /* Run all the bias changes in parallel */ |
| 1269 | list_for_each_entry(d, &dapm->card->dapm_list, list) |
| 1270 | async_schedule_domain(dapm_post_sequence_async, d, |
| 1271 | &async_domain); |
| 1272 | async_synchronize_full_domain(&async_domain); |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 1273 | |
Jarkko Nikula | fd8d3bc | 2010-11-09 14:40:28 +0200 | [diff] [blame] | 1274 | pop_dbg(dapm->dev, card->pop_time, |
| 1275 | "DAPM sequencing finished, waiting %dms\n", card->pop_time); |
Jarkko Nikula | 3a45b86 | 2010-11-05 20:35:21 +0200 | [diff] [blame] | 1276 | pop_wait(card->pop_time); |
Mark Brown | cb507e7 | 2009-07-08 18:54:57 +0100 | [diff] [blame] | 1277 | |
Mark Brown | 84e9093 | 2010-11-04 00:07:02 -0400 | [diff] [blame] | 1278 | trace_snd_soc_dapm_done(card); |
| 1279 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1280 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1281 | } |
| 1282 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1283 | #ifdef CONFIG_DEBUG_FS |
| 1284 | static int dapm_widget_power_open_file(struct inode *inode, struct file *file) |
| 1285 | { |
| 1286 | file->private_data = inode->i_private; |
| 1287 | return 0; |
| 1288 | } |
| 1289 | |
| 1290 | static ssize_t dapm_widget_power_read_file(struct file *file, |
| 1291 | char __user *user_buf, |
| 1292 | size_t count, loff_t *ppos) |
| 1293 | { |
| 1294 | struct snd_soc_dapm_widget *w = file->private_data; |
| 1295 | char *buf; |
| 1296 | int in, out; |
| 1297 | ssize_t ret; |
| 1298 | struct snd_soc_dapm_path *p = NULL; |
| 1299 | |
| 1300 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 1301 | if (!buf) |
| 1302 | return -ENOMEM; |
| 1303 | |
| 1304 | in = is_connected_input_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1305 | dapm_clear_walk(w->dapm); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1306 | out = is_connected_output_ep(w); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1307 | dapm_clear_walk(w->dapm); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1308 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1309 | ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1310 | w->name, w->power ? "On" : "Off", in, out); |
| 1311 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1312 | if (w->reg >= 0) |
| 1313 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
| 1314 | " - R%d(0x%x) bit %d", |
| 1315 | w->reg, w->reg, w->shift); |
| 1316 | |
| 1317 | ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n"); |
| 1318 | |
Mark Brown | 3eef08b | 2009-09-14 16:49:00 +0100 | [diff] [blame] | 1319 | if (w->sname) |
| 1320 | ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n", |
| 1321 | w->sname, |
| 1322 | w->active ? "active" : "inactive"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1323 | |
| 1324 | list_for_each_entry(p, &w->sources, list_sink) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1325 | if (p->connected && !p->connected(w, p->sink)) |
| 1326 | continue; |
| 1327 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1328 | if (p->connect) |
| 1329 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Dimitris Papastamos | 67f5ed6 | 2011-02-24 17:09:32 +0000 | [diff] [blame] | 1330 | " in \"%s\" \"%s\"\n", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1331 | p->name ? p->name : "static", |
| 1332 | p->source->name); |
| 1333 | } |
| 1334 | list_for_each_entry(p, &w->sinks, list_source) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1335 | if (p->connected && !p->connected(w, p->sink)) |
| 1336 | continue; |
| 1337 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1338 | if (p->connect) |
| 1339 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
Dimitris Papastamos | 67f5ed6 | 2011-02-24 17:09:32 +0000 | [diff] [blame] | 1340 | " out \"%s\" \"%s\"\n", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1341 | p->name ? p->name : "static", |
| 1342 | p->sink->name); |
| 1343 | } |
| 1344 | |
| 1345 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 1346 | |
| 1347 | kfree(buf); |
| 1348 | return ret; |
| 1349 | } |
| 1350 | |
| 1351 | static const struct file_operations dapm_widget_power_fops = { |
| 1352 | .open = dapm_widget_power_open_file, |
| 1353 | .read = dapm_widget_power_read_file, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 1354 | .llseek = default_llseek, |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1355 | }; |
| 1356 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1357 | static int dapm_bias_open_file(struct inode *inode, struct file *file) |
| 1358 | { |
| 1359 | file->private_data = inode->i_private; |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
| 1363 | static ssize_t dapm_bias_read_file(struct file *file, char __user *user_buf, |
| 1364 | size_t count, loff_t *ppos) |
| 1365 | { |
| 1366 | struct snd_soc_dapm_context *dapm = file->private_data; |
| 1367 | char *level; |
| 1368 | |
| 1369 | switch (dapm->bias_level) { |
| 1370 | case SND_SOC_BIAS_ON: |
| 1371 | level = "On\n"; |
| 1372 | break; |
| 1373 | case SND_SOC_BIAS_PREPARE: |
| 1374 | level = "Prepare\n"; |
| 1375 | break; |
| 1376 | case SND_SOC_BIAS_STANDBY: |
| 1377 | level = "Standby\n"; |
| 1378 | break; |
| 1379 | case SND_SOC_BIAS_OFF: |
| 1380 | level = "Off\n"; |
| 1381 | break; |
| 1382 | default: |
| 1383 | BUG(); |
| 1384 | level = "Unknown\n"; |
| 1385 | break; |
| 1386 | } |
| 1387 | |
| 1388 | return simple_read_from_buffer(user_buf, count, ppos, level, |
| 1389 | strlen(level)); |
| 1390 | } |
| 1391 | |
| 1392 | static const struct file_operations dapm_bias_fops = { |
| 1393 | .open = dapm_bias_open_file, |
| 1394 | .read = dapm_bias_read_file, |
| 1395 | .llseek = default_llseek, |
| 1396 | }; |
| 1397 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1398 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 1399 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1400 | { |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1401 | struct dentry *d; |
| 1402 | |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1403 | dapm->debugfs_dapm = debugfs_create_dir("dapm", parent); |
| 1404 | |
| 1405 | if (!dapm->debugfs_dapm) { |
| 1406 | printk(KERN_WARNING |
| 1407 | "Failed to create DAPM debugfs directory\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1408 | return; |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1409 | } |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1410 | |
Mark Brown | ef49e4f | 2011-04-04 20:48:13 +0900 | [diff] [blame] | 1411 | d = debugfs_create_file("bias_level", 0444, |
| 1412 | dapm->debugfs_dapm, dapm, |
| 1413 | &dapm_bias_fops); |
| 1414 | if (!d) |
| 1415 | dev_warn(dapm->dev, |
| 1416 | "ASoC: Failed to create bias level debugfs file\n"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1417 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1418 | |
| 1419 | static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 1420 | { |
| 1421 | struct snd_soc_dapm_context *dapm = w->dapm; |
| 1422 | struct dentry *d; |
| 1423 | |
| 1424 | if (!dapm->debugfs_dapm || !w->name) |
| 1425 | return; |
| 1426 | |
| 1427 | d = debugfs_create_file(w->name, 0444, |
| 1428 | dapm->debugfs_dapm, w, |
| 1429 | &dapm_widget_power_fops); |
| 1430 | if (!d) |
| 1431 | dev_warn(w->dapm->dev, |
| 1432 | "ASoC: Failed to create %s debugfs file\n", |
| 1433 | w->name); |
| 1434 | } |
| 1435 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 1436 | static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 1437 | { |
| 1438 | debugfs_remove_recursive(dapm->debugfs_dapm); |
| 1439 | } |
| 1440 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1441 | #else |
Lars-Peter Clausen | 8eecaf6 | 2011-04-30 19:45:48 +0200 | [diff] [blame] | 1442 | void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm, |
| 1443 | struct dentry *parent) |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1444 | { |
| 1445 | } |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 1446 | |
| 1447 | static inline void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w) |
| 1448 | { |
| 1449 | } |
| 1450 | |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 1451 | static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm) |
| 1452 | { |
| 1453 | } |
| 1454 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1455 | #endif |
| 1456 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1457 | /* test and update the power status of a mux widget */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 1458 | static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget, |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1459 | struct snd_kcontrol *kcontrol, int change, |
| 1460 | int mux, struct soc_enum *e) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1461 | { |
| 1462 | struct snd_soc_dapm_path *path; |
| 1463 | int found = 0; |
| 1464 | |
Peter Ujfalusi | eff317d | 2009-01-15 14:40:47 +0200 | [diff] [blame] | 1465 | if (widget->id != snd_soc_dapm_mux && |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 1466 | widget->id != snd_soc_dapm_virt_mux && |
Peter Ujfalusi | eff317d | 2009-01-15 14:40:47 +0200 | [diff] [blame] | 1467 | widget->id != snd_soc_dapm_value_mux) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1468 | return -ENODEV; |
| 1469 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1470 | if (!change) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1471 | return 0; |
| 1472 | |
| 1473 | /* find dapm widget path assoc with kcontrol */ |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1474 | list_for_each_entry(path, &widget->dapm->card->paths, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1475 | if (path->kcontrol != kcontrol) |
| 1476 | continue; |
| 1477 | |
Richard Zhao | cb01e2b | 2008-10-07 08:05:20 +0800 | [diff] [blame] | 1478 | if (!path->name || !e->texts[mux]) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1479 | continue; |
| 1480 | |
| 1481 | found = 1; |
| 1482 | /* 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] | 1483 | if (!(strcmp(path->name, e->texts[mux]))) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1484 | path->connect = 1; /* new connection */ |
| 1485 | else |
| 1486 | path->connect = 0; /* old connection must be powered down */ |
| 1487 | } |
| 1488 | |
Mark Brown | b91b8fa | 2010-01-20 18:18:35 +0000 | [diff] [blame] | 1489 | if (found) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1490 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1491 | |
| 1492 | return 0; |
| 1493 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1494 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1495 | /* test and update the power status of a mixer or switch widget */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 1496 | static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1497 | struct snd_kcontrol *kcontrol, int connect) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1498 | { |
| 1499 | struct snd_soc_dapm_path *path; |
| 1500 | int found = 0; |
| 1501 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1502 | if (widget->id != snd_soc_dapm_mixer && |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1503 | widget->id != snd_soc_dapm_mixer_named_ctl && |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1504 | widget->id != snd_soc_dapm_switch) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1505 | return -ENODEV; |
| 1506 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1507 | /* find dapm widget path assoc with kcontrol */ |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1508 | list_for_each_entry(path, &widget->dapm->card->paths, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1509 | if (path->kcontrol != kcontrol) |
| 1510 | continue; |
| 1511 | |
| 1512 | /* found, now check type */ |
| 1513 | found = 1; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1514 | path->connect = connect; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1515 | break; |
| 1516 | } |
| 1517 | |
Mark Brown | b91b8fa | 2010-01-20 18:18:35 +0000 | [diff] [blame] | 1518 | if (found) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1519 | dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1520 | |
| 1521 | return 0; |
| 1522 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1523 | |
| 1524 | /* show dapm widget status in sys fs */ |
| 1525 | static ssize_t dapm_widget_show(struct device *dev, |
| 1526 | struct device_attribute *attr, char *buf) |
| 1527 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1528 | struct snd_soc_pcm_runtime *rtd = |
| 1529 | container_of(dev, struct snd_soc_pcm_runtime, dev); |
| 1530 | struct snd_soc_codec *codec =rtd->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1531 | struct snd_soc_dapm_widget *w; |
| 1532 | int count = 0; |
| 1533 | char *state = "not set"; |
| 1534 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1535 | list_for_each_entry(w, &codec->card->widgets, list) { |
| 1536 | if (w->dapm != &codec->dapm) |
| 1537 | continue; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1538 | |
| 1539 | /* only display widgets that burnm power */ |
| 1540 | switch (w->id) { |
| 1541 | case snd_soc_dapm_hp: |
| 1542 | case snd_soc_dapm_mic: |
| 1543 | case snd_soc_dapm_spk: |
| 1544 | case snd_soc_dapm_line: |
| 1545 | case snd_soc_dapm_micbias: |
| 1546 | case snd_soc_dapm_dac: |
| 1547 | case snd_soc_dapm_adc: |
| 1548 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 1549 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1550 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1551 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1552 | case snd_soc_dapm_supply: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1553 | if (w->name) |
| 1554 | count += sprintf(buf + count, "%s: %s\n", |
| 1555 | w->name, w->power ? "On":"Off"); |
| 1556 | break; |
| 1557 | default: |
| 1558 | break; |
| 1559 | } |
| 1560 | } |
| 1561 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1562 | switch (codec->dapm.bias_level) { |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1563 | case SND_SOC_BIAS_ON: |
| 1564 | state = "On"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1565 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1566 | case SND_SOC_BIAS_PREPARE: |
| 1567 | state = "Prepare"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1568 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1569 | case SND_SOC_BIAS_STANDBY: |
| 1570 | state = "Standby"; |
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_OFF: |
| 1573 | state = "Off"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1574 | break; |
| 1575 | } |
| 1576 | count += sprintf(buf + count, "PM State: %s\n", state); |
| 1577 | |
| 1578 | return count; |
| 1579 | } |
| 1580 | |
| 1581 | static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL); |
| 1582 | |
| 1583 | int snd_soc_dapm_sys_add(struct device *dev) |
| 1584 | { |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1585 | return device_create_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | static void snd_soc_dapm_sys_remove(struct device *dev) |
| 1589 | { |
Mark Brown | aef9084 | 2009-05-16 17:53:16 +0100 | [diff] [blame] | 1590 | device_remove_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | /* free all dapm widgets and resources */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1594 | static void dapm_free_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1595 | { |
| 1596 | struct snd_soc_dapm_widget *w, *next_w; |
| 1597 | struct snd_soc_dapm_path *p, *next_p; |
| 1598 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1599 | list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) { |
| 1600 | if (w->dapm != dapm) |
| 1601 | continue; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1602 | list_del(&w->list); |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1603 | /* |
| 1604 | * remove source and sink paths associated to this widget. |
| 1605 | * While removing the path, remove reference to it from both |
| 1606 | * source and sink widgets so that path is removed only once. |
| 1607 | */ |
| 1608 | list_for_each_entry_safe(p, next_p, &w->sources, list_sink) { |
| 1609 | list_del(&p->list_sink); |
| 1610 | list_del(&p->list_source); |
| 1611 | list_del(&p->list); |
| 1612 | kfree(p->long_name); |
| 1613 | kfree(p); |
| 1614 | } |
| 1615 | list_for_each_entry_safe(p, next_p, &w->sinks, list_source) { |
| 1616 | list_del(&p->list_sink); |
| 1617 | list_del(&p->list_source); |
| 1618 | list_del(&p->list); |
| 1619 | kfree(p->long_name); |
| 1620 | kfree(p); |
| 1621 | } |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 1622 | kfree(w->kcontrols); |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1623 | kfree(w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1624 | kfree(w); |
| 1625 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1626 | } |
| 1627 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1628 | static struct snd_soc_dapm_widget *dapm_find_widget( |
| 1629 | struct snd_soc_dapm_context *dapm, const char *pin, |
| 1630 | bool search_other_contexts) |
| 1631 | { |
| 1632 | struct snd_soc_dapm_widget *w; |
| 1633 | struct snd_soc_dapm_widget *fallback = NULL; |
| 1634 | |
| 1635 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 1636 | if (!strcmp(w->name, pin)) { |
| 1637 | if (w->dapm == dapm) |
| 1638 | return w; |
| 1639 | else |
| 1640 | fallback = w; |
| 1641 | } |
| 1642 | } |
| 1643 | |
| 1644 | if (search_other_contexts) |
| 1645 | return fallback; |
| 1646 | |
| 1647 | return NULL; |
| 1648 | } |
| 1649 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1650 | 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] | 1651 | const char *pin, int status) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1652 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1653 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1654 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1655 | if (!w) { |
| 1656 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 1657 | return -EINVAL; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1658 | } |
| 1659 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1660 | w->connected = status; |
| 1661 | if (status == 0) |
| 1662 | w->force = 0; |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 1663 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 1664 | return 0; |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1665 | } |
| 1666 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1667 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1668 | * snd_soc_dapm_sync - scan and power dapm paths |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1669 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1670 | * |
| 1671 | * Walks all dapm audio paths and powers widgets according to their |
| 1672 | * stream or path usage. |
| 1673 | * |
| 1674 | * Returns 0 for success. |
| 1675 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1676 | int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1677 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1678 | return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1679 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1680 | EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1681 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1682 | 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] | 1683 | const struct snd_soc_dapm_route *route) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1684 | { |
| 1685 | struct snd_soc_dapm_path *path; |
| 1686 | struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w; |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1687 | struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1688 | const char *sink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1689 | const char *control = route->control; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1690 | const char *source; |
| 1691 | char prefixed_sink[80]; |
| 1692 | char prefixed_source[80]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1693 | int ret = 0; |
| 1694 | |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 1695 | if (dapm->codec && dapm->codec->name_prefix) { |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 1696 | snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s", |
| 1697 | dapm->codec->name_prefix, route->sink); |
| 1698 | sink = prefixed_sink; |
| 1699 | snprintf(prefixed_source, sizeof(prefixed_source), "%s %s", |
| 1700 | dapm->codec->name_prefix, route->source); |
| 1701 | source = prefixed_source; |
| 1702 | } else { |
| 1703 | sink = route->sink; |
| 1704 | source = route->source; |
| 1705 | } |
| 1706 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1707 | /* |
| 1708 | * find src and dest widgets over all widgets but favor a widget from |
| 1709 | * current DAPM context |
| 1710 | */ |
| 1711 | list_for_each_entry(w, &dapm->card->widgets, list) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1712 | if (!wsink && !(strcmp(w->name, sink))) { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1713 | wtsink = w; |
| 1714 | if (w->dapm == dapm) |
| 1715 | wsink = w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1716 | continue; |
| 1717 | } |
| 1718 | if (!wsource && !(strcmp(w->name, source))) { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1719 | wtsource = w; |
| 1720 | if (w->dapm == dapm) |
| 1721 | wsource = w; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1722 | } |
| 1723 | } |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1724 | /* use widget from another DAPM context if not found from this */ |
| 1725 | if (!wsink) |
| 1726 | wsink = wtsink; |
| 1727 | if (!wsource) |
| 1728 | wsource = wtsource; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1729 | |
| 1730 | if (wsource == NULL || wsink == NULL) |
| 1731 | return -ENODEV; |
| 1732 | |
| 1733 | path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL); |
| 1734 | if (!path) |
| 1735 | return -ENOMEM; |
| 1736 | |
| 1737 | path->source = wsource; |
| 1738 | path->sink = wsink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1739 | path->connected = route->connected; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1740 | INIT_LIST_HEAD(&path->list); |
| 1741 | INIT_LIST_HEAD(&path->list_source); |
| 1742 | INIT_LIST_HEAD(&path->list_sink); |
| 1743 | |
| 1744 | /* check for external widgets */ |
| 1745 | if (wsink->id == snd_soc_dapm_input) { |
| 1746 | if (wsource->id == snd_soc_dapm_micbias || |
| 1747 | wsource->id == snd_soc_dapm_mic || |
Rongrong Cao | 087d53a | 2009-07-10 20:13:30 +0100 | [diff] [blame] | 1748 | wsource->id == snd_soc_dapm_line || |
| 1749 | wsource->id == snd_soc_dapm_output) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1750 | wsink->ext = 1; |
| 1751 | } |
| 1752 | if (wsource->id == snd_soc_dapm_output) { |
| 1753 | if (wsink->id == snd_soc_dapm_spk || |
| 1754 | wsink->id == snd_soc_dapm_hp || |
Seth Forshee | 1e39221 | 2007-04-16 15:36:42 +0200 | [diff] [blame] | 1755 | wsink->id == snd_soc_dapm_line || |
| 1756 | wsink->id == snd_soc_dapm_input) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1757 | wsource->ext = 1; |
| 1758 | } |
| 1759 | |
| 1760 | /* connect static paths */ |
| 1761 | if (control == NULL) { |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1762 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1763 | list_add(&path->list_sink, &wsink->sources); |
| 1764 | list_add(&path->list_source, &wsource->sinks); |
| 1765 | path->connect = 1; |
| 1766 | return 0; |
| 1767 | } |
| 1768 | |
| 1769 | /* connect dynamic paths */ |
Lu Guanqun | dc2bea6 | 2011-04-20 16:00:36 +0800 | [diff] [blame] | 1770 | switch (wsink->id) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1771 | case snd_soc_dapm_adc: |
| 1772 | case snd_soc_dapm_dac: |
| 1773 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 1774 | case snd_soc_dapm_out_drv: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1775 | case snd_soc_dapm_input: |
| 1776 | case snd_soc_dapm_output: |
| 1777 | case snd_soc_dapm_micbias: |
| 1778 | case snd_soc_dapm_vmid: |
| 1779 | case snd_soc_dapm_pre: |
| 1780 | case snd_soc_dapm_post: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1781 | case snd_soc_dapm_supply: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 1782 | case snd_soc_dapm_aif_in: |
| 1783 | case snd_soc_dapm_aif_out: |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1784 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1785 | list_add(&path->list_sink, &wsink->sources); |
| 1786 | list_add(&path->list_source, &wsource->sinks); |
| 1787 | path->connect = 1; |
| 1788 | return 0; |
| 1789 | case snd_soc_dapm_mux: |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 1790 | case snd_soc_dapm_virt_mux: |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 1791 | case snd_soc_dapm_value_mux: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1792 | ret = dapm_connect_mux(dapm, wsource, wsink, path, control, |
Stephen Warren | 82cfecd | 2011-04-28 17:37:58 -0600 | [diff] [blame] | 1793 | &wsink->kcontrol_news[0]); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1794 | if (ret != 0) |
| 1795 | goto err; |
| 1796 | break; |
| 1797 | case snd_soc_dapm_switch: |
| 1798 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1799 | case snd_soc_dapm_mixer_named_ctl: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1800 | ret = dapm_connect_mixer(dapm, wsource, wsink, path, control); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1801 | if (ret != 0) |
| 1802 | goto err; |
| 1803 | break; |
| 1804 | case snd_soc_dapm_hp: |
| 1805 | case snd_soc_dapm_mic: |
| 1806 | case snd_soc_dapm_line: |
| 1807 | case snd_soc_dapm_spk: |
Jarkko Nikula | 8ddab3f | 2010-12-14 12:18:30 +0200 | [diff] [blame] | 1808 | list_add(&path->list, &dapm->card->paths); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1809 | list_add(&path->list_sink, &wsink->sources); |
| 1810 | list_add(&path->list_source, &wsource->sinks); |
| 1811 | path->connect = 0; |
| 1812 | return 0; |
| 1813 | } |
| 1814 | return 0; |
| 1815 | |
| 1816 | err: |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 1817 | dev_warn(dapm->dev, "asoc: no dapm match for %s --> %s --> %s\n", |
| 1818 | source, control, sink); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1819 | kfree(path); |
| 1820 | return ret; |
| 1821 | } |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1822 | |
| 1823 | /** |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1824 | * snd_soc_dapm_add_routes - Add routes between DAPM widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1825 | * @dapm: DAPM context |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1826 | * @route: audio routes |
| 1827 | * @num: number of routes |
| 1828 | * |
| 1829 | * Connects 2 dapm widgets together via a named audio path. The sink is |
| 1830 | * the widget receiving the audio signal, whilst the source is the sender |
| 1831 | * of the audio signal. |
| 1832 | * |
| 1833 | * Returns 0 for success else error. On error all resources can be freed |
| 1834 | * with a call to snd_soc_card_free(). |
| 1835 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1836 | int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm, |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1837 | const struct snd_soc_dapm_route *route, int num) |
| 1838 | { |
| 1839 | int i, ret; |
| 1840 | |
| 1841 | for (i = 0; i < num; i++) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1842 | ret = snd_soc_dapm_add_route(dapm, route); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1843 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 1844 | dev_err(dapm->dev, "Failed to add route %s->%s\n", |
| 1845 | route->source, route->sink); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1846 | return ret; |
| 1847 | } |
| 1848 | route++; |
| 1849 | } |
| 1850 | |
| 1851 | return 0; |
| 1852 | } |
| 1853 | EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes); |
| 1854 | |
Mark Brown | bf3a9e1 | 2011-06-13 16:42:29 +0100 | [diff] [blame] | 1855 | static int snd_soc_dapm_weak_route(struct snd_soc_dapm_context *dapm, |
| 1856 | const struct snd_soc_dapm_route *route) |
| 1857 | { |
| 1858 | struct snd_soc_dapm_widget *source = dapm_find_widget(dapm, |
| 1859 | route->source, |
| 1860 | true); |
| 1861 | struct snd_soc_dapm_widget *sink = dapm_find_widget(dapm, |
| 1862 | route->sink, |
| 1863 | true); |
| 1864 | struct snd_soc_dapm_path *path; |
| 1865 | int count = 0; |
| 1866 | |
| 1867 | if (!source) { |
| 1868 | dev_err(dapm->dev, "Unable to find source %s for weak route\n", |
| 1869 | route->source); |
| 1870 | return -ENODEV; |
| 1871 | } |
| 1872 | |
| 1873 | if (!sink) { |
| 1874 | dev_err(dapm->dev, "Unable to find sink %s for weak route\n", |
| 1875 | route->sink); |
| 1876 | return -ENODEV; |
| 1877 | } |
| 1878 | |
| 1879 | if (route->control || route->connected) |
| 1880 | dev_warn(dapm->dev, "Ignoring control for weak route %s->%s\n", |
| 1881 | route->source, route->sink); |
| 1882 | |
| 1883 | list_for_each_entry(path, &source->sinks, list_source) { |
| 1884 | if (path->sink == sink) { |
| 1885 | path->weak = 1; |
| 1886 | count++; |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | if (count == 0) |
| 1891 | dev_err(dapm->dev, "No path found for weak route %s->%s\n", |
| 1892 | route->source, route->sink); |
| 1893 | if (count > 1) |
| 1894 | dev_warn(dapm->dev, "%d paths found for weak route %s->%s\n", |
| 1895 | count, route->source, route->sink); |
| 1896 | |
| 1897 | return 0; |
| 1898 | } |
| 1899 | |
| 1900 | /** |
| 1901 | * snd_soc_dapm_weak_routes - Mark routes between DAPM widgets as weak |
| 1902 | * @dapm: DAPM context |
| 1903 | * @route: audio routes |
| 1904 | * @num: number of routes |
| 1905 | * |
| 1906 | * Mark existing routes matching those specified in the passed array |
| 1907 | * as being weak, meaning that they are ignored for the purpose of |
| 1908 | * power decisions. The main intended use case is for sidetone paths |
| 1909 | * which couple audio between other independent paths if they are both |
| 1910 | * active in order to make the combination work better at the user |
| 1911 | * level but which aren't intended to be "used". |
| 1912 | * |
| 1913 | * Note that CODEC drivers should not use this as sidetone type paths |
| 1914 | * can frequently also be used as bypass paths. |
| 1915 | */ |
| 1916 | int snd_soc_dapm_weak_routes(struct snd_soc_dapm_context *dapm, |
| 1917 | const struct snd_soc_dapm_route *route, int num) |
| 1918 | { |
| 1919 | int i, err; |
| 1920 | int ret = 0; |
| 1921 | |
| 1922 | for (i = 0; i < num; i++) { |
| 1923 | err = snd_soc_dapm_weak_route(dapm, route); |
| 1924 | if (err) |
| 1925 | ret = err; |
| 1926 | route++; |
| 1927 | } |
| 1928 | |
| 1929 | return ret; |
| 1930 | } |
| 1931 | EXPORT_SYMBOL_GPL(snd_soc_dapm_weak_routes); |
| 1932 | |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1933 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1934 | * snd_soc_dapm_new_widgets - add new dapm widgets |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1935 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1936 | * |
| 1937 | * Checks the codec for any new dapm widgets and creates them if found. |
| 1938 | * |
| 1939 | * Returns 0 for success. |
| 1940 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1941 | int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1942 | { |
| 1943 | struct snd_soc_dapm_widget *w; |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 1944 | unsigned int val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1945 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 1946 | list_for_each_entry(w, &dapm->card->widgets, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1947 | { |
| 1948 | if (w->new) |
| 1949 | continue; |
| 1950 | |
Stephen Warren | fad5988 | 2011-04-28 17:37:59 -0600 | [diff] [blame] | 1951 | if (w->num_kcontrols) { |
| 1952 | w->kcontrols = kzalloc(w->num_kcontrols * |
| 1953 | sizeof(struct snd_kcontrol *), |
| 1954 | GFP_KERNEL); |
| 1955 | if (!w->kcontrols) |
| 1956 | return -ENOMEM; |
| 1957 | } |
| 1958 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1959 | switch(w->id) { |
| 1960 | case snd_soc_dapm_switch: |
| 1961 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1962 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1963 | w->power_check = dapm_generic_check_power; |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 1964 | dapm_new_mixer(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1965 | break; |
| 1966 | case snd_soc_dapm_mux: |
Dimitris Papastamos | 24ff33a | 2010-12-16 15:53:39 +0000 | [diff] [blame] | 1967 | case snd_soc_dapm_virt_mux: |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1968 | case snd_soc_dapm_value_mux: |
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_mux(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1971 | break; |
| 1972 | case snd_soc_dapm_adc: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 1973 | case snd_soc_dapm_aif_out: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1974 | w->power_check = dapm_adc_check_power; |
| 1975 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1976 | case snd_soc_dapm_dac: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 1977 | case snd_soc_dapm_aif_in: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1978 | w->power_check = dapm_dac_check_power; |
| 1979 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1980 | case snd_soc_dapm_pga: |
Olaya, Margarita | d88429a | 2010-12-10 21:11:44 -0600 | [diff] [blame] | 1981 | case snd_soc_dapm_out_drv: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1982 | w->power_check = dapm_generic_check_power; |
Lars-Peter Clausen | 4b80b8c | 2011-06-09 13:22:36 +0200 | [diff] [blame] | 1983 | dapm_new_pga(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1984 | break; |
| 1985 | case snd_soc_dapm_input: |
| 1986 | case snd_soc_dapm_output: |
| 1987 | case snd_soc_dapm_micbias: |
| 1988 | case snd_soc_dapm_spk: |
| 1989 | case snd_soc_dapm_hp: |
| 1990 | case snd_soc_dapm_mic: |
| 1991 | case snd_soc_dapm_line: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1992 | w->power_check = dapm_generic_check_power; |
| 1993 | break; |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1994 | case snd_soc_dapm_supply: |
| 1995 | w->power_check = dapm_supply_check_power; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1996 | case snd_soc_dapm_vmid: |
| 1997 | case snd_soc_dapm_pre: |
| 1998 | case snd_soc_dapm_post: |
| 1999 | break; |
| 2000 | } |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2001 | |
| 2002 | /* Read the initial power state from the device */ |
| 2003 | if (w->reg >= 0) { |
Liam Girdwood | 0445bdf | 2011-06-13 19:37:36 +0100 | [diff] [blame^] | 2004 | val = soc_widget_read(w, w->reg); |
Mark Brown | b66a70d | 2011-02-09 18:04:11 +0000 | [diff] [blame] | 2005 | val &= 1 << w->shift; |
| 2006 | if (w->invert) |
| 2007 | val = !val; |
| 2008 | |
| 2009 | if (val) |
| 2010 | w->power = 1; |
| 2011 | } |
| 2012 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2013 | w->new = 1; |
Lars-Peter Clausen | d5d1e0b | 2011-04-30 19:45:49 +0200 | [diff] [blame] | 2014 | |
| 2015 | dapm_debugfs_add_widget(w); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2016 | } |
| 2017 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2018 | dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2019 | return 0; |
| 2020 | } |
| 2021 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); |
| 2022 | |
| 2023 | /** |
| 2024 | * snd_soc_dapm_get_volsw - dapm mixer get callback |
| 2025 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2026 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2027 | * |
| 2028 | * Callback to get the value of a dapm mixer control. |
| 2029 | * |
| 2030 | * Returns 0 for success. |
| 2031 | */ |
| 2032 | int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, |
| 2033 | struct snd_ctl_elem_value *ucontrol) |
| 2034 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2035 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2036 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2037 | struct soc_mixer_control *mc = |
| 2038 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2039 | unsigned int reg = mc->reg; |
| 2040 | unsigned int shift = mc->shift; |
| 2041 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2042 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2043 | unsigned int invert = mc->invert; |
| 2044 | unsigned int mask = (1 << fls(max)) - 1; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2045 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2046 | ucontrol->value.integer.value[0] = |
| 2047 | (snd_soc_read(widget->codec, reg) >> shift) & mask; |
| 2048 | if (shift != rshift) |
| 2049 | ucontrol->value.integer.value[1] = |
| 2050 | (snd_soc_read(widget->codec, reg) >> rshift) & mask; |
| 2051 | if (invert) { |
| 2052 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2053 | max - ucontrol->value.integer.value[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2054 | if (shift != rshift) |
| 2055 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2056 | max - ucontrol->value.integer.value[1]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | return 0; |
| 2060 | } |
| 2061 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw); |
| 2062 | |
| 2063 | /** |
| 2064 | * snd_soc_dapm_put_volsw - dapm mixer set callback |
| 2065 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2066 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2067 | * |
| 2068 | * Callback to set the value of a dapm mixer control. |
| 2069 | * |
| 2070 | * Returns 0 for success. |
| 2071 | */ |
| 2072 | int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, |
| 2073 | struct snd_ctl_elem_value *ucontrol) |
| 2074 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2075 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2076 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2077 | struct snd_soc_codec *codec = widget->codec; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2078 | struct soc_mixer_control *mc = |
| 2079 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2080 | unsigned int reg = mc->reg; |
| 2081 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 2082 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 2083 | unsigned int mask = (1 << fls(max)) - 1; |
| 2084 | unsigned int invert = mc->invert; |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2085 | unsigned int val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2086 | int connect, change; |
| 2087 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2088 | int wi; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2089 | |
| 2090 | val = (ucontrol->value.integer.value[0] & mask); |
| 2091 | |
| 2092 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 2093 | val = max - val; |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2094 | mask = mask << shift; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2095 | val = val << shift; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2096 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2097 | if (val) |
| 2098 | /* new connection */ |
| 2099 | connect = invert ? 0 : 1; |
| 2100 | else |
| 2101 | /* old connection must be powered down */ |
| 2102 | connect = invert ? 1 : 0; |
| 2103 | |
| 2104 | mutex_lock(&codec->mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2105 | |
Stephen Warren | e9cf704 | 2011-01-27 14:54:05 -0700 | [diff] [blame] | 2106 | change = snd_soc_test_bits(widget->codec, reg, mask, val); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2107 | if (change) { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2108 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2109 | widget = wlist->widgets[wi]; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 2110 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2111 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2112 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2113 | update.kcontrol = kcontrol; |
| 2114 | update.widget = widget; |
| 2115 | update.reg = reg; |
| 2116 | update.mask = mask; |
| 2117 | update.val = val; |
| 2118 | widget->dapm->update = &update; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2119 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2120 | dapm_mixer_update_power(widget, kcontrol, connect); |
| 2121 | |
| 2122 | widget->dapm->update = NULL; |
| 2123 | } |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 2124 | } |
| 2125 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2126 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2127 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2128 | } |
| 2129 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); |
| 2130 | |
| 2131 | /** |
| 2132 | * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback |
| 2133 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2134 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2135 | * |
| 2136 | * Callback to get the value of a dapm enumerated double mixer control. |
| 2137 | * |
| 2138 | * Returns 0 for success. |
| 2139 | */ |
| 2140 | int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, |
| 2141 | struct snd_ctl_elem_value *ucontrol) |
| 2142 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2143 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2144 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2145 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2146 | unsigned int val, bitmask; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2147 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2148 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2149 | ; |
| 2150 | val = snd_soc_read(widget->codec, e->reg); |
| 2151 | ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1); |
| 2152 | if (e->shift_l != e->shift_r) |
| 2153 | ucontrol->value.enumerated.item[1] = |
| 2154 | (val >> e->shift_r) & (bitmask - 1); |
| 2155 | |
| 2156 | return 0; |
| 2157 | } |
| 2158 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double); |
| 2159 | |
| 2160 | /** |
| 2161 | * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback |
| 2162 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2163 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2164 | * |
| 2165 | * Callback to set the value of a dapm enumerated double mixer control. |
| 2166 | * |
| 2167 | * Returns 0 for success. |
| 2168 | */ |
| 2169 | int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, |
| 2170 | struct snd_ctl_elem_value *ucontrol) |
| 2171 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2172 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2173 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2174 | struct snd_soc_codec *codec = widget->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2175 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2176 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2177 | unsigned int mask, bitmask; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2178 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2179 | int wi; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2180 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2181 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2182 | ; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2183 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2184 | return -EINVAL; |
| 2185 | mux = ucontrol->value.enumerated.item[0]; |
| 2186 | val = mux << e->shift_l; |
| 2187 | mask = (bitmask - 1) << e->shift_l; |
| 2188 | if (e->shift_l != e->shift_r) { |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 2189 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2190 | return -EINVAL; |
| 2191 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; |
| 2192 | mask |= (bitmask - 1) << e->shift_r; |
| 2193 | } |
| 2194 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2195 | mutex_lock(&codec->mutex); |
| 2196 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2197 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2198 | if (change) { |
| 2199 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2200 | widget = wlist->widgets[wi]; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2201 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2202 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2203 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2204 | update.kcontrol = kcontrol; |
| 2205 | update.widget = widget; |
| 2206 | update.reg = e->reg; |
| 2207 | update.mask = mask; |
| 2208 | update.val = val; |
| 2209 | widget->dapm->update = &update; |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2210 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2211 | dapm_mux_update_power(widget, kcontrol, change, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2212 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2213 | widget->dapm->update = NULL; |
| 2214 | } |
| 2215 | } |
| 2216 | |
| 2217 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2218 | return change; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2219 | } |
| 2220 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); |
| 2221 | |
| 2222 | /** |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2223 | * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux |
| 2224 | * @kcontrol: mixer control |
| 2225 | * @ucontrol: control element information |
| 2226 | * |
| 2227 | * Returns 0 for success. |
| 2228 | */ |
| 2229 | int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol, |
| 2230 | struct snd_ctl_elem_value *ucontrol) |
| 2231 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2232 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2233 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2234 | |
| 2235 | ucontrol->value.enumerated.item[0] = widget->value; |
| 2236 | |
| 2237 | return 0; |
| 2238 | } |
| 2239 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt); |
| 2240 | |
| 2241 | /** |
| 2242 | * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux |
| 2243 | * @kcontrol: mixer control |
| 2244 | * @ucontrol: control element information |
| 2245 | * |
| 2246 | * Returns 0 for success. |
| 2247 | */ |
| 2248 | int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol, |
| 2249 | struct snd_ctl_elem_value *ucontrol) |
| 2250 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2251 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2252 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2253 | struct snd_soc_codec *codec = widget->codec; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2254 | struct soc_enum *e = |
| 2255 | (struct soc_enum *)kcontrol->private_value; |
| 2256 | int change; |
| 2257 | int ret = 0; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2258 | int wi; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2259 | |
| 2260 | if (ucontrol->value.enumerated.item[0] >= e->max) |
| 2261 | return -EINVAL; |
| 2262 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2263 | mutex_lock(&codec->mutex); |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2264 | |
| 2265 | change = widget->value != ucontrol->value.enumerated.item[0]; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2266 | if (change) { |
| 2267 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2268 | widget = wlist->widgets[wi]; |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2269 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2270 | widget->value = ucontrol->value.enumerated.item[0]; |
| 2271 | |
| 2272 | dapm_mux_update_power(widget, kcontrol, change, |
| 2273 | widget->value, e); |
| 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | mutex_unlock(&codec->mutex); |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 2278 | return ret; |
| 2279 | } |
| 2280 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt); |
| 2281 | |
| 2282 | /** |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2283 | * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get |
| 2284 | * callback |
| 2285 | * @kcontrol: mixer control |
| 2286 | * @ucontrol: control element information |
| 2287 | * |
| 2288 | * Callback to get the value of a dapm semi enumerated double mixer control. |
| 2289 | * |
| 2290 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2291 | * used for handling bitfield coded enumeration for example. |
| 2292 | * |
| 2293 | * Returns 0 for success. |
| 2294 | */ |
| 2295 | int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2296 | struct snd_ctl_elem_value *ucontrol) |
| 2297 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2298 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2299 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2300 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2301 | unsigned int reg_val, val, mux; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2302 | |
| 2303 | reg_val = snd_soc_read(widget->codec, e->reg); |
| 2304 | val = (reg_val >> e->shift_l) & e->mask; |
| 2305 | for (mux = 0; mux < e->max; mux++) { |
| 2306 | if (val == e->values[mux]) |
| 2307 | break; |
| 2308 | } |
| 2309 | ucontrol->value.enumerated.item[0] = mux; |
| 2310 | if (e->shift_l != e->shift_r) { |
| 2311 | val = (reg_val >> e->shift_r) & e->mask; |
| 2312 | for (mux = 0; mux < e->max; mux++) { |
| 2313 | if (val == e->values[mux]) |
| 2314 | break; |
| 2315 | } |
| 2316 | ucontrol->value.enumerated.item[1] = mux; |
| 2317 | } |
| 2318 | |
| 2319 | return 0; |
| 2320 | } |
| 2321 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double); |
| 2322 | |
| 2323 | /** |
| 2324 | * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set |
| 2325 | * callback |
| 2326 | * @kcontrol: mixer control |
| 2327 | * @ucontrol: control element information |
| 2328 | * |
| 2329 | * Callback to set the value of a dapm semi enumerated double mixer control. |
| 2330 | * |
| 2331 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 2332 | * used for handling bitfield coded enumeration for example. |
| 2333 | * |
| 2334 | * Returns 0 for success. |
| 2335 | */ |
| 2336 | int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, |
| 2337 | struct snd_ctl_elem_value *ucontrol) |
| 2338 | { |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2339 | struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol); |
| 2340 | struct snd_soc_dapm_widget *widget = wlist->widgets[0]; |
| 2341 | struct snd_soc_codec *codec = widget->codec; |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 2342 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2343 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 2344 | unsigned int mask; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2345 | struct snd_soc_dapm_update update; |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2346 | int wi; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2347 | |
| 2348 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 2349 | return -EINVAL; |
| 2350 | mux = ucontrol->value.enumerated.item[0]; |
| 2351 | val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; |
| 2352 | mask = e->mask << e->shift_l; |
| 2353 | if (e->shift_l != e->shift_r) { |
| 2354 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
| 2355 | return -EINVAL; |
| 2356 | val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; |
| 2357 | mask |= e->mask << e->shift_r; |
| 2358 | } |
| 2359 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2360 | mutex_lock(&codec->mutex); |
| 2361 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 2362 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2363 | if (change) { |
| 2364 | for (wi = 0; wi < wlist->num_widgets; wi++) { |
| 2365 | widget = wlist->widgets[wi]; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2366 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2367 | widget->value = val; |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2368 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2369 | update.kcontrol = kcontrol; |
| 2370 | update.widget = widget; |
| 2371 | update.reg = e->reg; |
| 2372 | update.mask = mask; |
| 2373 | update.val = val; |
| 2374 | widget->dapm->update = &update; |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2375 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2376 | dapm_mux_update_power(widget, kcontrol, change, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 2377 | |
Stephen Warren | fafd217 | 2011-04-28 17:38:00 -0600 | [diff] [blame] | 2378 | widget->dapm->update = NULL; |
| 2379 | } |
| 2380 | } |
| 2381 | |
| 2382 | mutex_unlock(&codec->mutex); |
Mark Brown | 97404f2 | 2010-12-14 16:13:57 +0000 | [diff] [blame] | 2383 | return change; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 2384 | } |
| 2385 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); |
| 2386 | |
| 2387 | /** |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2388 | * snd_soc_dapm_info_pin_switch - Info for a pin switch |
| 2389 | * |
| 2390 | * @kcontrol: mixer control |
| 2391 | * @uinfo: control element information |
| 2392 | * |
| 2393 | * Callback to provide information about a pin switch control. |
| 2394 | */ |
| 2395 | int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol, |
| 2396 | struct snd_ctl_elem_info *uinfo) |
| 2397 | { |
| 2398 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 2399 | uinfo->count = 1; |
| 2400 | uinfo->value.integer.min = 0; |
| 2401 | uinfo->value.integer.max = 1; |
| 2402 | |
| 2403 | return 0; |
| 2404 | } |
| 2405 | EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch); |
| 2406 | |
| 2407 | /** |
| 2408 | * snd_soc_dapm_get_pin_switch - Get information for a pin switch |
| 2409 | * |
| 2410 | * @kcontrol: mixer control |
| 2411 | * @ucontrol: Value |
| 2412 | */ |
| 2413 | int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol, |
| 2414 | struct snd_ctl_elem_value *ucontrol) |
| 2415 | { |
| 2416 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2417 | const char *pin = (const char *)kcontrol->private_value; |
| 2418 | |
| 2419 | mutex_lock(&codec->mutex); |
| 2420 | |
| 2421 | ucontrol->value.integer.value[0] = |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2422 | snd_soc_dapm_get_pin_status(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2423 | |
| 2424 | mutex_unlock(&codec->mutex); |
| 2425 | |
| 2426 | return 0; |
| 2427 | } |
| 2428 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch); |
| 2429 | |
| 2430 | /** |
| 2431 | * snd_soc_dapm_put_pin_switch - Set information for a pin switch |
| 2432 | * |
| 2433 | * @kcontrol: mixer control |
| 2434 | * @ucontrol: Value |
| 2435 | */ |
| 2436 | int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol, |
| 2437 | struct snd_ctl_elem_value *ucontrol) |
| 2438 | { |
| 2439 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 2440 | const char *pin = (const char *)kcontrol->private_value; |
| 2441 | |
| 2442 | mutex_lock(&codec->mutex); |
| 2443 | |
| 2444 | if (ucontrol->value.integer.value[0]) |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2445 | snd_soc_dapm_enable_pin(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2446 | else |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2447 | snd_soc_dapm_disable_pin(&codec->dapm, pin); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2448 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2449 | snd_soc_dapm_sync(&codec->dapm); |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 2450 | |
| 2451 | mutex_unlock(&codec->mutex); |
| 2452 | |
| 2453 | return 0; |
| 2454 | } |
| 2455 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch); |
| 2456 | |
| 2457 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2458 | * snd_soc_dapm_new_control - create new dapm control |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2459 | * @dapm: DAPM context |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2460 | * @widget: widget template |
| 2461 | * |
| 2462 | * Creates a new dapm control based upon the template. |
| 2463 | * |
| 2464 | * Returns 0 for success else error. |
| 2465 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2466 | int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2467 | const struct snd_soc_dapm_widget *widget) |
| 2468 | { |
| 2469 | struct snd_soc_dapm_widget *w; |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2470 | size_t name_len; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2471 | |
| 2472 | if ((w = dapm_cnew_widget(widget)) == NULL) |
| 2473 | return -ENOMEM; |
| 2474 | |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2475 | name_len = strlen(widget->name) + 1; |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 2476 | if (dapm->codec && dapm->codec->name_prefix) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2477 | name_len += 1 + strlen(dapm->codec->name_prefix); |
| 2478 | w->name = kmalloc(name_len, GFP_KERNEL); |
| 2479 | if (w->name == NULL) { |
| 2480 | kfree(w); |
| 2481 | return -ENOMEM; |
| 2482 | } |
Mark Brown | 88e8b9a | 2011-03-02 18:18:24 +0000 | [diff] [blame] | 2483 | if (dapm->codec && dapm->codec->name_prefix) |
Jarkko Nikula | ead9b91 | 2010-11-13 20:40:44 +0200 | [diff] [blame] | 2484 | snprintf(w->name, name_len, "%s %s", |
| 2485 | dapm->codec->name_prefix, widget->name); |
| 2486 | else |
| 2487 | snprintf(w->name, name_len, "%s", widget->name); |
| 2488 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2489 | dapm->n_widgets++; |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2490 | w->dapm = dapm; |
| 2491 | w->codec = dapm->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2492 | INIT_LIST_HEAD(&w->sources); |
| 2493 | INIT_LIST_HEAD(&w->sinks); |
| 2494 | INIT_LIST_HEAD(&w->list); |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2495 | list_add(&w->list, &dapm->card->widgets); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2496 | |
| 2497 | /* machine layer set ups unconnected pins and insertions */ |
| 2498 | w->connected = 1; |
| 2499 | return 0; |
| 2500 | } |
| 2501 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control); |
| 2502 | |
| 2503 | /** |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2504 | * snd_soc_dapm_new_controls - create new dapm controls |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2505 | * @dapm: DAPM context |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2506 | * @widget: widget array |
| 2507 | * @num: number of widgets |
| 2508 | * |
| 2509 | * Creates new DAPM controls based upon the templates. |
| 2510 | * |
| 2511 | * Returns 0 for success else error. |
| 2512 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2513 | int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm, |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2514 | const struct snd_soc_dapm_widget *widget, |
| 2515 | int num) |
| 2516 | { |
| 2517 | int i, ret; |
| 2518 | |
| 2519 | for (i = 0; i < num; i++) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2520 | ret = snd_soc_dapm_new_control(dapm, widget); |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 2521 | if (ret < 0) { |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2522 | dev_err(dapm->dev, |
| 2523 | "ASoC: Failed to create DAPM control %s: %d\n", |
| 2524 | widget->name, ret); |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2525 | return ret; |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 2526 | } |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 2527 | widget++; |
| 2528 | } |
| 2529 | return 0; |
| 2530 | } |
| 2531 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); |
| 2532 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2533 | static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2534 | const char *stream, int event) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2535 | { |
| 2536 | struct snd_soc_dapm_widget *w; |
| 2537 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2538 | list_for_each_entry(w, &dapm->card->widgets, list) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2539 | { |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2540 | if (!w->sname || w->dapm != dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2541 | continue; |
Jarkko Nikula | f7d41ae | 2010-11-09 14:40:27 +0200 | [diff] [blame] | 2542 | dev_dbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n", |
| 2543 | w->name, w->sname, stream, event); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2544 | if (strstr(w->sname, stream)) { |
| 2545 | switch(event) { |
| 2546 | case SND_SOC_DAPM_STREAM_START: |
| 2547 | w->active = 1; |
| 2548 | break; |
| 2549 | case SND_SOC_DAPM_STREAM_STOP: |
| 2550 | w->active = 0; |
| 2551 | break; |
| 2552 | case SND_SOC_DAPM_STREAM_SUSPEND: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2553 | case SND_SOC_DAPM_STREAM_RESUME: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2554 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2555 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: |
| 2556 | break; |
| 2557 | } |
| 2558 | } |
| 2559 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2560 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2561 | dapm_power_widgets(dapm, event); |
| 2562 | } |
| 2563 | |
| 2564 | /** |
| 2565 | * snd_soc_dapm_stream_event - send a stream event to the dapm core |
| 2566 | * @rtd: PCM runtime data |
| 2567 | * @stream: stream name |
| 2568 | * @event: stream event |
| 2569 | * |
| 2570 | * Sends a stream event to the dapm core. The core then makes any |
| 2571 | * necessary widget power changes. |
| 2572 | * |
| 2573 | * Returns 0 for success else error. |
| 2574 | */ |
| 2575 | int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, |
| 2576 | const char *stream, int event) |
| 2577 | { |
| 2578 | struct snd_soc_codec *codec = rtd->codec; |
| 2579 | |
| 2580 | if (stream == NULL) |
| 2581 | return 0; |
| 2582 | |
| 2583 | mutex_lock(&codec->mutex); |
| 2584 | soc_dapm_stream_event(&codec->dapm, stream, event); |
Eero Nurkkala | 8e8b2d6 | 2009-10-12 08:41:59 +0300 | [diff] [blame] | 2585 | mutex_unlock(&codec->mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2586 | return 0; |
| 2587 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2588 | |
| 2589 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2590 | * snd_soc_dapm_enable_pin - enable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2591 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2592 | * @pin: pin name |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2593 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 2594 | * 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] | 2595 | * a valid audio route and active audio stream. |
| 2596 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2597 | * do any widget power switching. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2598 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2599 | 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] | 2600 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2601 | return snd_soc_dapm_set_pin(dapm, pin, 1); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2602 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2603 | EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2604 | |
| 2605 | /** |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2606 | * snd_soc_dapm_force_enable_pin - force a pin to be enabled |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2607 | * @dapm: DAPM context |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2608 | * @pin: pin name |
| 2609 | * |
| 2610 | * Enables input/output pin regardless of any other state. This is |
| 2611 | * intended for use with microphone bias supplies used in microphone |
| 2612 | * jack detection. |
| 2613 | * |
| 2614 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2615 | * do any widget power switching. |
| 2616 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2617 | int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm, |
| 2618 | const char *pin) |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2619 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2620 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2621 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2622 | if (!w) { |
| 2623 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 2624 | return -EINVAL; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2627 | dev_dbg(w->dapm->dev, "dapm: force enable pin %s\n", pin); |
| 2628 | w->connected = 1; |
| 2629 | w->force = 1; |
Mark Brown | 0d86733 | 2011-04-06 11:38:14 +0900 | [diff] [blame] | 2630 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2631 | return 0; |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2632 | } |
| 2633 | EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin); |
| 2634 | |
| 2635 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2636 | * snd_soc_dapm_disable_pin - disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2637 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2638 | * @pin: pin name |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2639 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 2640 | * Disables input/output pin and its parents or children widgets. |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2641 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2642 | * do any widget power switching. |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2643 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2644 | int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm, |
| 2645 | const char *pin) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2646 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2647 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2648 | } |
| 2649 | EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin); |
| 2650 | |
| 2651 | /** |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2652 | * snd_soc_dapm_nc_pin - permanently disable pin. |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2653 | * @dapm: DAPM context |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2654 | * @pin: pin name |
| 2655 | * |
| 2656 | * Marks the specified pin as being not connected, disabling it along |
| 2657 | * any parent or child widgets. At present this is identical to |
| 2658 | * snd_soc_dapm_disable_pin() but in future it will be extended to do |
| 2659 | * additional things such as disabling controls which only affect |
| 2660 | * paths through the pin. |
| 2661 | * |
| 2662 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2663 | * do any widget power switching. |
| 2664 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2665 | 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] | 2666 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2667 | return snd_soc_dapm_set_pin(dapm, pin, 0); |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2668 | } |
| 2669 | EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin); |
| 2670 | |
| 2671 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2672 | * snd_soc_dapm_get_pin_status - get audio pin status |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2673 | * @dapm: DAPM context |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2674 | * @pin: audio signal pin endpoint (or start point) |
| 2675 | * |
| 2676 | * Get audio pin status - connected or disconnected. |
| 2677 | * |
| 2678 | * Returns 1 for connected otherwise 0. |
| 2679 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2680 | int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm, |
| 2681 | const char *pin) |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2682 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2683 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, true); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2684 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2685 | if (w) |
| 2686 | return w->connected; |
Stephen Warren | a68b38a | 2011-04-19 15:25:11 -0600 | [diff] [blame] | 2687 | |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2688 | return 0; |
| 2689 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2690 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2691 | |
| 2692 | /** |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2693 | * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2694 | * @dapm: DAPM context |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2695 | * @pin: audio signal pin endpoint (or start point) |
| 2696 | * |
| 2697 | * Mark the given endpoint or pin as ignoring suspend. When the |
| 2698 | * system is disabled a path between two endpoints flagged as ignoring |
| 2699 | * suspend will not be disabled. The path must already be enabled via |
| 2700 | * normal means at suspend time, it will not be turned on if it was not |
| 2701 | * already enabled. |
| 2702 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2703 | int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm, |
| 2704 | const char *pin) |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2705 | { |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2706 | struct snd_soc_dapm_widget *w = dapm_find_widget(dapm, pin, false); |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2707 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2708 | if (!w) { |
| 2709 | dev_err(dapm->dev, "dapm: unknown pin %s\n", pin); |
| 2710 | return -EINVAL; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2711 | } |
| 2712 | |
Lars-Peter Clausen | 91a5fca | 2011-04-27 18:34:31 +0200 | [diff] [blame] | 2713 | w->ignore_suspend = 1; |
| 2714 | |
| 2715 | return 0; |
Mark Brown | 1547aba | 2010-05-07 21:11:40 +0100 | [diff] [blame] | 2716 | } |
| 2717 | EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend); |
| 2718 | |
| 2719 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2720 | * snd_soc_dapm_free - free dapm resources |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2721 | * @card: SoC device |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2722 | * |
| 2723 | * Free all dapm widgets and resources. |
| 2724 | */ |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2725 | void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2726 | { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2727 | snd_soc_dapm_sys_remove(dapm->dev); |
Lars-Peter Clausen | 6c45e12 | 2011-04-30 19:45:50 +0200 | [diff] [blame] | 2728 | dapm_debugfs_cleanup(dapm); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2729 | dapm_free_widgets(dapm); |
Jarkko Nikula | 7be31be8 | 2010-12-14 12:18:32 +0200 | [diff] [blame] | 2730 | list_del(&dapm->list); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2731 | } |
| 2732 | EXPORT_SYMBOL_GPL(snd_soc_dapm_free); |
| 2733 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2734 | static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm) |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2735 | { |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2736 | struct snd_soc_dapm_widget *w; |
| 2737 | LIST_HEAD(down_list); |
| 2738 | int powerdown = 0; |
| 2739 | |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 2740 | list_for_each_entry(w, &dapm->card->widgets, list) { |
| 2741 | if (w->dapm != dapm) |
| 2742 | continue; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2743 | if (w->power) { |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 2744 | dapm_seq_insert(w, &down_list, false); |
Mark Brown | c2caa4d | 2009-06-26 15:36:56 +0100 | [diff] [blame] | 2745 | w->power = 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2746 | powerdown = 1; |
| 2747 | } |
| 2748 | } |
| 2749 | |
| 2750 | /* If there were no widgets to power down we're already in |
| 2751 | * standby. |
| 2752 | */ |
| 2753 | if (powerdown) { |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 2754 | snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_PREPARE); |
Mark Brown | 828a842 | 2011-01-15 13:14:30 +0000 | [diff] [blame] | 2755 | dapm_seq_run(dapm, &down_list, 0, false); |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 2756 | snd_soc_dapm_set_bias_level(dapm, SND_SOC_BIAS_STANDBY); |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2757 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2758 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2759 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 2760 | /* |
| 2761 | * snd_soc_dapm_shutdown - callback for system shutdown |
| 2762 | */ |
| 2763 | void snd_soc_dapm_shutdown(struct snd_soc_card *card) |
| 2764 | { |
| 2765 | struct snd_soc_codec *codec; |
| 2766 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2767 | list_for_each_entry(codec, &card->codec_dev_list, list) { |
| 2768 | soc_dapm_shutdown_codec(&codec->dapm); |
Mark Brown | ed5a4c4 | 2011-02-18 11:12:42 -0800 | [diff] [blame] | 2769 | snd_soc_dapm_set_bias_level(&codec->dapm, SND_SOC_BIAS_OFF); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 2770 | } |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2771 | } |
| 2772 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2773 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 2774 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2775 | MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC"); |
| 2776 | MODULE_LICENSE("GPL"); |