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