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