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