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> |
| 35 | #include <linux/delay.h> |
| 36 | #include <linux/pm.h> |
| 37 | #include <linux/bitops.h> |
| 38 | #include <linux/platform_device.h> |
| 39 | #include <linux/jiffies.h> |
Takashi Iwai | 20496ff | 2009-08-24 09:40:34 +0200 | [diff] [blame] | 40 | #include <linux/debugfs.h> |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 41 | #include <sound/core.h> |
| 42 | #include <sound/pcm.h> |
| 43 | #include <sound/pcm_params.h> |
| 44 | #include <sound/soc-dapm.h> |
| 45 | #include <sound/initval.h> |
| 46 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 47 | /* dapm power sequences - make this per codec in the future */ |
| 48 | static int dapm_up_seq[] = { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 49 | [snd_soc_dapm_pre] = 0, |
| 50 | [snd_soc_dapm_supply] = 1, |
| 51 | [snd_soc_dapm_micbias] = 2, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 52 | [snd_soc_dapm_aif_in] = 3, |
| 53 | [snd_soc_dapm_aif_out] = 3, |
| 54 | [snd_soc_dapm_mic] = 4, |
| 55 | [snd_soc_dapm_mux] = 5, |
| 56 | [snd_soc_dapm_value_mux] = 5, |
| 57 | [snd_soc_dapm_dac] = 6, |
| 58 | [snd_soc_dapm_mixer] = 7, |
| 59 | [snd_soc_dapm_mixer_named_ctl] = 7, |
| 60 | [snd_soc_dapm_pga] = 8, |
| 61 | [snd_soc_dapm_adc] = 9, |
| 62 | [snd_soc_dapm_hp] = 10, |
| 63 | [snd_soc_dapm_spk] = 10, |
| 64 | [snd_soc_dapm_post] = 11, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 65 | }; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 66 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 67 | static int dapm_down_seq[] = { |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 68 | [snd_soc_dapm_pre] = 0, |
| 69 | [snd_soc_dapm_adc] = 1, |
| 70 | [snd_soc_dapm_hp] = 2, |
Mark Brown | 1ca0406 | 2009-08-17 16:26:59 +0100 | [diff] [blame] | 71 | [snd_soc_dapm_spk] = 2, |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 72 | [snd_soc_dapm_pga] = 4, |
| 73 | [snd_soc_dapm_mixer_named_ctl] = 5, |
Mark Brown | e3d4dab | 2009-06-07 13:08:45 +0100 | [diff] [blame] | 74 | [snd_soc_dapm_mixer] = 5, |
| 75 | [snd_soc_dapm_dac] = 6, |
| 76 | [snd_soc_dapm_mic] = 7, |
| 77 | [snd_soc_dapm_micbias] = 8, |
| 78 | [snd_soc_dapm_mux] = 9, |
| 79 | [snd_soc_dapm_value_mux] = 9, |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 80 | [snd_soc_dapm_aif_in] = 10, |
| 81 | [snd_soc_dapm_aif_out] = 10, |
| 82 | [snd_soc_dapm_supply] = 11, |
| 83 | [snd_soc_dapm_post] = 12, |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 84 | }; |
| 85 | |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 86 | static void pop_wait(u32 pop_time) |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 87 | { |
| 88 | if (pop_time) |
| 89 | schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time)); |
| 90 | } |
| 91 | |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 92 | static void pop_dbg(u32 pop_time, const char *fmt, ...) |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 93 | { |
| 94 | va_list args; |
| 95 | |
| 96 | va_start(args, fmt); |
| 97 | |
| 98 | if (pop_time) { |
| 99 | vprintk(fmt, args); |
Mark Brown | 15e4c72 | 2008-07-02 11:51:20 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | va_end(args); |
| 103 | } |
| 104 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 105 | /* create a new dapm widget */ |
Takashi Iwai | 88cb429 | 2007-02-05 14:56:20 +0100 | [diff] [blame] | 106 | static inline struct snd_soc_dapm_widget *dapm_cnew_widget( |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 107 | const struct snd_soc_dapm_widget *_widget) |
| 108 | { |
Takashi Iwai | 88cb429 | 2007-02-05 14:56:20 +0100 | [diff] [blame] | 109 | return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 112 | /** |
| 113 | * snd_soc_dapm_set_bias_level - set the bias level for the system |
| 114 | * @socdev: audio device |
| 115 | * @level: level to configure |
| 116 | * |
| 117 | * Configure the bias (power) levels for the SoC audio device. |
| 118 | * |
| 119 | * Returns 0 for success else error. |
| 120 | */ |
| 121 | static int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev, |
| 122 | enum snd_soc_bias_level level) |
| 123 | { |
| 124 | struct snd_soc_card *card = socdev->card; |
| 125 | struct snd_soc_codec *codec = socdev->card->codec; |
| 126 | int ret = 0; |
| 127 | |
Mark Brown | f83fba8 | 2009-05-18 15:44:43 +0100 | [diff] [blame] | 128 | switch (level) { |
| 129 | case SND_SOC_BIAS_ON: |
| 130 | dev_dbg(socdev->dev, "Setting full bias\n"); |
| 131 | break; |
| 132 | case SND_SOC_BIAS_PREPARE: |
| 133 | dev_dbg(socdev->dev, "Setting bias prepare\n"); |
| 134 | break; |
| 135 | case SND_SOC_BIAS_STANDBY: |
| 136 | dev_dbg(socdev->dev, "Setting standby bias\n"); |
| 137 | break; |
| 138 | case SND_SOC_BIAS_OFF: |
| 139 | dev_dbg(socdev->dev, "Setting bias off\n"); |
| 140 | break; |
| 141 | default: |
| 142 | dev_err(socdev->dev, "Setting invalid bias %d\n", level); |
| 143 | return -EINVAL; |
| 144 | } |
| 145 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 146 | if (card->set_bias_level) |
| 147 | ret = card->set_bias_level(card, level); |
Mark Brown | 474e09c | 2009-08-19 14:18:53 +0100 | [diff] [blame] | 148 | if (ret == 0) { |
| 149 | if (codec->set_bias_level) |
| 150 | ret = codec->set_bias_level(codec, level); |
| 151 | else |
| 152 | codec->bias_level = level; |
| 153 | } |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 154 | |
| 155 | return ret; |
| 156 | } |
| 157 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 158 | /* set up initial codec paths */ |
| 159 | static void dapm_set_path_status(struct snd_soc_dapm_widget *w, |
| 160 | struct snd_soc_dapm_path *p, int i) |
| 161 | { |
| 162 | switch (w->id) { |
| 163 | case snd_soc_dapm_switch: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 164 | case snd_soc_dapm_mixer: |
| 165 | case snd_soc_dapm_mixer_named_ctl: { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 166 | int val; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 167 | struct soc_mixer_control *mc = (struct soc_mixer_control *) |
| 168 | w->kcontrols[i].private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 169 | unsigned int reg = mc->reg; |
| 170 | unsigned int shift = mc->shift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 171 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 172 | unsigned int mask = (1 << fls(max)) - 1; |
| 173 | unsigned int invert = mc->invert; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 174 | |
| 175 | val = snd_soc_read(w->codec, reg); |
| 176 | val = (val >> shift) & mask; |
| 177 | |
| 178 | if ((invert && !val) || (!invert && val)) |
| 179 | p->connect = 1; |
| 180 | else |
| 181 | p->connect = 0; |
| 182 | } |
| 183 | break; |
| 184 | case snd_soc_dapm_mux: { |
| 185 | struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value; |
| 186 | int val, item, bitmask; |
| 187 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 188 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 189 | ; |
| 190 | val = snd_soc_read(w->codec, e->reg); |
| 191 | item = (val >> e->shift_l) & (bitmask - 1); |
| 192 | |
| 193 | p->connect = 0; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 194 | for (i = 0; i < e->max; i++) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 195 | if (!(strcmp(p->name, e->texts[i])) && item == i) |
| 196 | p->connect = 1; |
| 197 | } |
| 198 | } |
| 199 | break; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 200 | case snd_soc_dapm_value_mux: { |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 201 | struct soc_enum *e = (struct soc_enum *) |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 202 | w->kcontrols[i].private_value; |
| 203 | int val, item; |
| 204 | |
| 205 | val = snd_soc_read(w->codec, e->reg); |
| 206 | val = (val >> e->shift_l) & e->mask; |
| 207 | for (item = 0; item < e->max; item++) { |
| 208 | if (val == e->values[item]) |
| 209 | break; |
| 210 | } |
| 211 | |
| 212 | p->connect = 0; |
| 213 | for (i = 0; i < e->max; i++) { |
| 214 | if (!(strcmp(p->name, e->texts[i])) && item == i) |
| 215 | p->connect = 1; |
| 216 | } |
| 217 | } |
| 218 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 219 | /* does not effect routing - always connected */ |
| 220 | case snd_soc_dapm_pga: |
| 221 | case snd_soc_dapm_output: |
| 222 | case snd_soc_dapm_adc: |
| 223 | case snd_soc_dapm_input: |
| 224 | case snd_soc_dapm_dac: |
| 225 | case snd_soc_dapm_micbias: |
| 226 | case snd_soc_dapm_vmid: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 227 | case snd_soc_dapm_supply: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 228 | case snd_soc_dapm_aif_in: |
| 229 | case snd_soc_dapm_aif_out: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 230 | p->connect = 1; |
| 231 | break; |
| 232 | /* does effect routing - dynamically connected */ |
| 233 | case snd_soc_dapm_hp: |
| 234 | case snd_soc_dapm_mic: |
| 235 | case snd_soc_dapm_spk: |
| 236 | case snd_soc_dapm_line: |
| 237 | case snd_soc_dapm_pre: |
| 238 | case snd_soc_dapm_post: |
| 239 | p->connect = 0; |
| 240 | break; |
| 241 | } |
| 242 | } |
| 243 | |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 244 | /* connect mux widget to its interconnecting audio paths */ |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 245 | static int dapm_connect_mux(struct snd_soc_codec *codec, |
| 246 | struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, |
| 247 | struct snd_soc_dapm_path *path, const char *control_name, |
| 248 | const struct snd_kcontrol_new *kcontrol) |
| 249 | { |
| 250 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
| 251 | int i; |
| 252 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 253 | for (i = 0; i < e->max; i++) { |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 254 | if (!(strcmp(control_name, e->texts[i]))) { |
| 255 | list_add(&path->list, &codec->dapm_paths); |
| 256 | list_add(&path->list_sink, &dest->sources); |
| 257 | list_add(&path->list_source, &src->sinks); |
| 258 | path->name = (char*)e->texts[i]; |
| 259 | dapm_set_path_status(dest, path, 0); |
| 260 | return 0; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | return -ENODEV; |
| 265 | } |
| 266 | |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 267 | /* connect mixer widget to its interconnecting audio paths */ |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 268 | static int dapm_connect_mixer(struct snd_soc_codec *codec, |
| 269 | struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest, |
| 270 | struct snd_soc_dapm_path *path, const char *control_name) |
| 271 | { |
| 272 | int i; |
| 273 | |
| 274 | /* search for mixer kcontrol */ |
| 275 | for (i = 0; i < dest->num_kcontrols; i++) { |
| 276 | if (!strcmp(control_name, dest->kcontrols[i].name)) { |
| 277 | list_add(&path->list, &codec->dapm_paths); |
| 278 | list_add(&path->list_sink, &dest->sources); |
| 279 | list_add(&path->list_source, &src->sinks); |
| 280 | path->name = dest->kcontrols[i].name; |
| 281 | dapm_set_path_status(dest, path, i); |
| 282 | return 0; |
| 283 | } |
| 284 | } |
| 285 | return -ENODEV; |
| 286 | } |
| 287 | |
| 288 | /* update dapm codec register bits */ |
| 289 | static int dapm_update_bits(struct snd_soc_dapm_widget *widget) |
| 290 | { |
| 291 | int change, power; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 292 | unsigned int old, new; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 293 | struct snd_soc_codec *codec = widget->codec; |
| 294 | |
| 295 | /* check for valid widgets */ |
| 296 | if (widget->reg < 0 || widget->id == snd_soc_dapm_input || |
| 297 | widget->id == snd_soc_dapm_output || |
| 298 | widget->id == snd_soc_dapm_hp || |
| 299 | widget->id == snd_soc_dapm_mic || |
| 300 | widget->id == snd_soc_dapm_line || |
| 301 | widget->id == snd_soc_dapm_spk) |
| 302 | return 0; |
| 303 | |
| 304 | power = widget->power; |
| 305 | if (widget->invert) |
| 306 | power = (power ? 0:1); |
| 307 | |
| 308 | old = snd_soc_read(codec, widget->reg); |
| 309 | new = (old & ~(0x1 << widget->shift)) | (power << widget->shift); |
| 310 | |
| 311 | change = old != new; |
| 312 | if (change) { |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 313 | pop_dbg(codec->pop_time, "pop test %s : %s in %d ms\n", |
| 314 | widget->name, widget->power ? "on" : "off", |
| 315 | codec->pop_time); |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 316 | pop_wait(codec->pop_time); |
Mark Brown | 6922471 | 2010-03-03 14:57:09 +0000 | [diff] [blame] | 317 | snd_soc_write(codec, widget->reg, new); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 318 | } |
Mark Brown | c1286b8 | 2008-07-07 19:26:03 +0100 | [diff] [blame] | 319 | pr_debug("reg %x old %x new %x change %d\n", widget->reg, |
| 320 | old, new, change); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 321 | return change; |
| 322 | } |
| 323 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 324 | /* create new dapm mixer control */ |
| 325 | static int dapm_new_mixer(struct snd_soc_codec *codec, |
| 326 | struct snd_soc_dapm_widget *w) |
| 327 | { |
| 328 | int i, ret = 0; |
Mark Brown | 219b93f | 2008-10-28 13:02:31 +0000 | [diff] [blame] | 329 | size_t name_len; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 330 | struct snd_soc_dapm_path *path; |
| 331 | |
| 332 | /* add kcontrol */ |
| 333 | for (i = 0; i < w->num_kcontrols; i++) { |
| 334 | |
| 335 | /* match name */ |
| 336 | list_for_each_entry(path, &w->sources, list_sink) { |
| 337 | |
| 338 | /* mixer/mux paths name must match control name */ |
| 339 | if (path->name != (char*)w->kcontrols[i].name) |
| 340 | continue; |
| 341 | |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 342 | /* add dapm control with long name. |
| 343 | * for dapm_mixer this is the concatenation of the |
| 344 | * mixer and kcontrol name. |
| 345 | * for dapm_mixer_named_ctl this is simply the |
| 346 | * kcontrol name. |
| 347 | */ |
| 348 | name_len = strlen(w->kcontrols[i].name) + 1; |
Mark Brown | 07495f3 | 2009-03-05 17:06:23 +0000 | [diff] [blame] | 349 | if (w->id != snd_soc_dapm_mixer_named_ctl) |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 350 | name_len += 1 + strlen(w->name); |
| 351 | |
Mark Brown | 219b93f | 2008-10-28 13:02:31 +0000 | [diff] [blame] | 352 | path->long_name = kmalloc(name_len, GFP_KERNEL); |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 353 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 354 | if (path->long_name == NULL) |
| 355 | return -ENOMEM; |
| 356 | |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 357 | switch (w->id) { |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 358 | default: |
| 359 | snprintf(path->long_name, name_len, "%s %s", |
| 360 | w->name, w->kcontrols[i].name); |
Mark Brown | 07495f3 | 2009-03-05 17:06:23 +0000 | [diff] [blame] | 361 | break; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 362 | case snd_soc_dapm_mixer_named_ctl: |
| 363 | snprintf(path->long_name, name_len, "%s", |
| 364 | w->kcontrols[i].name); |
Mark Brown | 07495f3 | 2009-03-05 17:06:23 +0000 | [diff] [blame] | 365 | break; |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Mark Brown | 219b93f | 2008-10-28 13:02:31 +0000 | [diff] [blame] | 368 | path->long_name[name_len - 1] = '\0'; |
| 369 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 370 | path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w, |
| 371 | path->long_name); |
| 372 | ret = snd_ctl_add(codec->card, path->kcontrol); |
| 373 | if (ret < 0) { |
Mark Brown | 6553e19 | 2009-04-06 16:59:32 +0100 | [diff] [blame] | 374 | printk(KERN_ERR "asoc: failed to add dapm kcontrol %s: %d\n", |
| 375 | path->long_name, |
| 376 | ret); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 377 | kfree(path->long_name); |
| 378 | path->long_name = NULL; |
| 379 | return ret; |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | return ret; |
| 384 | } |
| 385 | |
| 386 | /* create new dapm mux control */ |
| 387 | static int dapm_new_mux(struct snd_soc_codec *codec, |
| 388 | struct snd_soc_dapm_widget *w) |
| 389 | { |
| 390 | struct snd_soc_dapm_path *path = NULL; |
| 391 | struct snd_kcontrol *kcontrol; |
| 392 | int ret = 0; |
| 393 | |
| 394 | if (!w->num_kcontrols) { |
| 395 | printk(KERN_ERR "asoc: mux %s has no controls\n", w->name); |
| 396 | return -EINVAL; |
| 397 | } |
| 398 | |
| 399 | kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name); |
| 400 | ret = snd_ctl_add(codec->card, kcontrol); |
| 401 | if (ret < 0) |
| 402 | goto err; |
| 403 | |
| 404 | list_for_each_entry(path, &w->sources, list_sink) |
| 405 | path->kcontrol = kcontrol; |
| 406 | |
| 407 | return ret; |
| 408 | |
| 409 | err: |
| 410 | printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name); |
| 411 | return ret; |
| 412 | } |
| 413 | |
| 414 | /* create new dapm volume control */ |
| 415 | static int dapm_new_pga(struct snd_soc_codec *codec, |
| 416 | struct snd_soc_dapm_widget *w) |
| 417 | { |
Mark Brown | a6c6573 | 2010-03-03 17:45:21 +0000 | [diff] [blame^] | 418 | if (w->num_kcontrols) |
| 419 | pr_err("asoc: PGA controls not supported: '%s'\n", w->name); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 420 | |
Mark Brown | a6c6573 | 2010-03-03 17:45:21 +0000 | [diff] [blame^] | 421 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | /* reset 'walked' bit for each dapm path */ |
| 425 | static inline void dapm_clear_walk(struct snd_soc_codec *codec) |
| 426 | { |
| 427 | struct snd_soc_dapm_path *p; |
| 428 | |
| 429 | list_for_each_entry(p, &codec->dapm_paths, list) |
| 430 | p->walked = 0; |
| 431 | } |
| 432 | |
| 433 | /* |
| 434 | * Recursively check for a completed path to an active or physically connected |
| 435 | * output widget. Returns number of complete paths. |
| 436 | */ |
| 437 | static int is_connected_output_ep(struct snd_soc_dapm_widget *widget) |
| 438 | { |
| 439 | struct snd_soc_dapm_path *path; |
| 440 | int con = 0; |
| 441 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 442 | if (widget->id == snd_soc_dapm_supply) |
| 443 | return 0; |
| 444 | |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 445 | switch (widget->id) { |
| 446 | case snd_soc_dapm_adc: |
| 447 | case snd_soc_dapm_aif_out: |
| 448 | if (widget->active) |
| 449 | return 1; |
| 450 | default: |
| 451 | break; |
| 452 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 453 | |
| 454 | if (widget->connected) { |
| 455 | /* connected pin ? */ |
| 456 | if (widget->id == snd_soc_dapm_output && !widget->ext) |
| 457 | return 1; |
| 458 | |
| 459 | /* connected jack or spk ? */ |
| 460 | 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] | 461 | (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources))) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 462 | return 1; |
| 463 | } |
| 464 | |
| 465 | list_for_each_entry(path, &widget->sinks, list_source) { |
| 466 | if (path->walked) |
| 467 | continue; |
| 468 | |
| 469 | if (path->sink && path->connect) { |
| 470 | path->walked = 1; |
| 471 | con += is_connected_output_ep(path->sink); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | return con; |
| 476 | } |
| 477 | |
| 478 | /* |
| 479 | * Recursively check for a completed path to an active or physically connected |
| 480 | * input widget. Returns number of complete paths. |
| 481 | */ |
| 482 | static int is_connected_input_ep(struct snd_soc_dapm_widget *widget) |
| 483 | { |
| 484 | struct snd_soc_dapm_path *path; |
| 485 | int con = 0; |
| 486 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 487 | if (widget->id == snd_soc_dapm_supply) |
| 488 | return 0; |
| 489 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 490 | /* active stream ? */ |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 491 | switch (widget->id) { |
| 492 | case snd_soc_dapm_dac: |
| 493 | case snd_soc_dapm_aif_in: |
| 494 | if (widget->active) |
| 495 | return 1; |
| 496 | default: |
| 497 | break; |
| 498 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 499 | |
| 500 | if (widget->connected) { |
| 501 | /* connected pin ? */ |
| 502 | if (widget->id == snd_soc_dapm_input && !widget->ext) |
| 503 | return 1; |
| 504 | |
| 505 | /* connected VMID/Bias for lower pops */ |
| 506 | if (widget->id == snd_soc_dapm_vmid) |
| 507 | return 1; |
| 508 | |
| 509 | /* connected jack ? */ |
Peter Ujfalusi | eaeae5d | 2009-09-30 09:27:24 +0300 | [diff] [blame] | 510 | if (widget->id == snd_soc_dapm_mic || |
| 511 | (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks))) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 512 | return 1; |
| 513 | } |
| 514 | |
| 515 | list_for_each_entry(path, &widget->sources, list_sink) { |
| 516 | if (path->walked) |
| 517 | continue; |
| 518 | |
| 519 | if (path->source && path->connect) { |
| 520 | path->walked = 1; |
| 521 | con += is_connected_input_ep(path->source); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | return con; |
| 526 | } |
| 527 | |
| 528 | /* |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 529 | * Handler for generic register modifier widget. |
| 530 | */ |
| 531 | int dapm_reg_event(struct snd_soc_dapm_widget *w, |
| 532 | struct snd_kcontrol *kcontrol, int event) |
| 533 | { |
| 534 | unsigned int val; |
| 535 | |
| 536 | if (SND_SOC_DAPM_EVENT_ON(event)) |
| 537 | val = w->on_val; |
| 538 | else |
| 539 | val = w->off_val; |
| 540 | |
| 541 | snd_soc_update_bits(w->codec, -(w->reg + 1), |
| 542 | w->mask << w->shift, val << w->shift); |
| 543 | |
| 544 | return 0; |
| 545 | } |
Mark Brown | 1158941 | 2008-07-29 11:42:23 +0100 | [diff] [blame] | 546 | EXPORT_SYMBOL_GPL(dapm_reg_event); |
Jarkko Nikula | e2be2cc | 2008-06-25 14:42:07 +0300 | [diff] [blame] | 547 | |
Mark Brown | 025756e | 2009-04-13 11:09:18 +0100 | [diff] [blame] | 548 | /* Standard power change method, used to apply power changes to most |
| 549 | * widgets. |
| 550 | */ |
| 551 | static int dapm_generic_apply_power(struct snd_soc_dapm_widget *w) |
| 552 | { |
| 553 | int ret; |
| 554 | |
| 555 | /* call any power change event handlers */ |
| 556 | if (w->event) |
| 557 | pr_debug("power %s event for %s flags %x\n", |
| 558 | w->power ? "on" : "off", |
| 559 | w->name, w->event_flags); |
| 560 | |
| 561 | /* power up pre event */ |
| 562 | if (w->power && w->event && |
| 563 | (w->event_flags & SND_SOC_DAPM_PRE_PMU)) { |
| 564 | ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU); |
| 565 | if (ret < 0) |
| 566 | return ret; |
| 567 | } |
| 568 | |
| 569 | /* power down pre event */ |
| 570 | if (!w->power && w->event && |
| 571 | (w->event_flags & SND_SOC_DAPM_PRE_PMD)) { |
| 572 | ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD); |
| 573 | if (ret < 0) |
| 574 | return ret; |
| 575 | } |
| 576 | |
Mark Brown | 025756e | 2009-04-13 11:09:18 +0100 | [diff] [blame] | 577 | dapm_update_bits(w); |
| 578 | |
Mark Brown | 025756e | 2009-04-13 11:09:18 +0100 | [diff] [blame] | 579 | /* power up post event */ |
| 580 | if (w->power && w->event && |
| 581 | (w->event_flags & SND_SOC_DAPM_POST_PMU)) { |
| 582 | ret = w->event(w, |
| 583 | NULL, SND_SOC_DAPM_POST_PMU); |
| 584 | if (ret < 0) |
| 585 | return ret; |
| 586 | } |
| 587 | |
| 588 | /* power down post event */ |
| 589 | if (!w->power && w->event && |
| 590 | (w->event_flags & SND_SOC_DAPM_POST_PMD)) { |
| 591 | ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD); |
| 592 | if (ret < 0) |
| 593 | return ret; |
| 594 | } |
| 595 | |
| 596 | return 0; |
| 597 | } |
| 598 | |
Mark Brown | cd0f2d4 | 2009-04-20 16:56:59 +0100 | [diff] [blame] | 599 | /* Generic check to see if a widget should be powered. |
| 600 | */ |
| 601 | static int dapm_generic_check_power(struct snd_soc_dapm_widget *w) |
| 602 | { |
| 603 | int in, out; |
| 604 | |
| 605 | in = is_connected_input_ep(w); |
| 606 | dapm_clear_walk(w->codec); |
| 607 | out = is_connected_output_ep(w); |
| 608 | dapm_clear_walk(w->codec); |
| 609 | return out != 0 && in != 0; |
| 610 | } |
| 611 | |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 612 | /* Check to see if an ADC has power */ |
| 613 | static int dapm_adc_check_power(struct snd_soc_dapm_widget *w) |
| 614 | { |
| 615 | int in; |
| 616 | |
| 617 | if (w->active) { |
| 618 | in = is_connected_input_ep(w); |
| 619 | dapm_clear_walk(w->codec); |
| 620 | return in != 0; |
| 621 | } else { |
| 622 | return dapm_generic_check_power(w); |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | /* Check to see if a DAC has power */ |
| 627 | static int dapm_dac_check_power(struct snd_soc_dapm_widget *w) |
| 628 | { |
| 629 | int out; |
| 630 | |
| 631 | if (w->active) { |
| 632 | out = is_connected_output_ep(w); |
| 633 | dapm_clear_walk(w->codec); |
| 634 | return out != 0; |
| 635 | } else { |
| 636 | return dapm_generic_check_power(w); |
| 637 | } |
| 638 | } |
| 639 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 640 | /* Check to see if a power supply is needed */ |
| 641 | static int dapm_supply_check_power(struct snd_soc_dapm_widget *w) |
| 642 | { |
| 643 | struct snd_soc_dapm_path *path; |
| 644 | int power = 0; |
| 645 | |
| 646 | /* Check if one of our outputs is connected */ |
| 647 | list_for_each_entry(path, &w->sinks, list_source) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 648 | if (path->connected && |
| 649 | !path->connected(path->source, path->sink)) |
| 650 | continue; |
| 651 | |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 652 | if (path->sink && path->sink->power_check && |
| 653 | path->sink->power_check(path->sink)) { |
| 654 | power = 1; |
| 655 | break; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | dapm_clear_walk(w->codec); |
| 660 | |
| 661 | return power; |
| 662 | } |
| 663 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 664 | static int dapm_seq_compare(struct snd_soc_dapm_widget *a, |
| 665 | struct snd_soc_dapm_widget *b, |
| 666 | int sort[]) |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 667 | { |
Mark Brown | d207c68 | 2009-12-07 17:13:55 +0000 | [diff] [blame] | 668 | if (a->codec != b->codec) |
| 669 | return (unsigned long)a - (unsigned long)b; |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 670 | if (sort[a->id] != sort[b->id]) |
| 671 | return sort[a->id] - sort[b->id]; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 672 | if (a->reg != b->reg) |
| 673 | return a->reg - b->reg; |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 674 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 675 | return 0; |
| 676 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 677 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 678 | /* Insert a widget in order into a DAPM power sequence. */ |
| 679 | static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget, |
| 680 | struct list_head *list, |
| 681 | int sort[]) |
| 682 | { |
| 683 | struct snd_soc_dapm_widget *w; |
| 684 | |
| 685 | list_for_each_entry(w, list, power_list) |
| 686 | if (dapm_seq_compare(new_widget, w, sort) < 0) { |
| 687 | list_add_tail(&new_widget->power_list, &w->power_list); |
| 688 | return; |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 689 | } |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 690 | |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 691 | list_add_tail(&new_widget->power_list, list); |
| 692 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 693 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 694 | /* Apply the coalesced changes from a DAPM sequence */ |
| 695 | static void dapm_seq_run_coalesced(struct snd_soc_codec *codec, |
| 696 | struct list_head *pending) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 697 | { |
| 698 | struct snd_soc_dapm_widget *w; |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 699 | int reg, power, ret; |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 700 | unsigned int value = 0; |
| 701 | unsigned int mask = 0; |
| 702 | unsigned int cur_mask; |
| 703 | |
| 704 | reg = list_first_entry(pending, struct snd_soc_dapm_widget, |
| 705 | power_list)->reg; |
| 706 | |
| 707 | list_for_each_entry(w, pending, power_list) { |
| 708 | cur_mask = 1 << w->shift; |
| 709 | BUG_ON(reg != w->reg); |
| 710 | |
| 711 | if (w->invert) |
| 712 | power = !w->power; |
| 713 | else |
| 714 | power = w->power; |
| 715 | |
| 716 | mask |= cur_mask; |
| 717 | if (power) |
| 718 | value |= cur_mask; |
| 719 | |
| 720 | pop_dbg(codec->pop_time, |
| 721 | "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n", |
| 722 | w->name, reg, value, mask); |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 723 | |
| 724 | /* power up pre event */ |
| 725 | if (w->power && w->event && |
| 726 | (w->event_flags & SND_SOC_DAPM_PRE_PMU)) { |
| 727 | pop_dbg(codec->pop_time, "pop test : %s PRE_PMU\n", |
| 728 | w->name); |
| 729 | ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU); |
| 730 | if (ret < 0) |
| 731 | pr_err("%s: pre event failed: %d\n", |
| 732 | w->name, ret); |
| 733 | } |
| 734 | |
| 735 | /* power down pre event */ |
| 736 | if (!w->power && w->event && |
| 737 | (w->event_flags & SND_SOC_DAPM_PRE_PMD)) { |
| 738 | pop_dbg(codec->pop_time, "pop test : %s PRE_PMD\n", |
| 739 | w->name); |
| 740 | ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD); |
| 741 | if (ret < 0) |
| 742 | pr_err("%s: pre event failed: %d\n", |
| 743 | w->name, ret); |
| 744 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 745 | } |
| 746 | |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 747 | if (reg >= 0) { |
| 748 | pop_dbg(codec->pop_time, |
| 749 | "pop test : Applying 0x%x/0x%x to %x in %dms\n", |
| 750 | value, mask, reg, codec->pop_time); |
| 751 | pop_wait(codec->pop_time); |
| 752 | snd_soc_update_bits(codec, reg, mask, value); |
| 753 | } |
| 754 | |
| 755 | list_for_each_entry(w, pending, power_list) { |
| 756 | /* power up post event */ |
| 757 | if (w->power && w->event && |
| 758 | (w->event_flags & SND_SOC_DAPM_POST_PMU)) { |
| 759 | pop_dbg(codec->pop_time, "pop test : %s POST_PMU\n", |
| 760 | w->name); |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 761 | ret = w->event(w, |
| 762 | NULL, SND_SOC_DAPM_POST_PMU); |
| 763 | if (ret < 0) |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 764 | pr_err("%s: post event failed: %d\n", |
| 765 | w->name, ret); |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 766 | } |
Mark Brown | 6ea31b9 | 2009-04-20 17:15:41 +0100 | [diff] [blame] | 767 | |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 768 | /* power down post event */ |
| 769 | if (!w->power && w->event && |
| 770 | (w->event_flags & SND_SOC_DAPM_POST_PMD)) { |
| 771 | pop_dbg(codec->pop_time, "pop test : %s POST_PMD\n", |
| 772 | w->name); |
| 773 | ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD); |
| 774 | if (ret < 0) |
| 775 | pr_err("%s: post event failed: %d\n", |
| 776 | w->name, ret); |
| 777 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 778 | } |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 779 | } |
| 780 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 781 | /* Apply a DAPM power sequence. |
| 782 | * |
| 783 | * We walk over a pre-sorted list of widgets to apply power to. In |
| 784 | * order to minimise the number of writes to the device required |
| 785 | * multiple widgets will be updated in a single write where possible. |
| 786 | * Currently anything that requires more than a single write is not |
| 787 | * handled. |
| 788 | */ |
| 789 | static void dapm_seq_run(struct snd_soc_codec *codec, struct list_head *list, |
| 790 | int event, int sort[]) |
| 791 | { |
| 792 | struct snd_soc_dapm_widget *w, *n; |
| 793 | LIST_HEAD(pending); |
| 794 | int cur_sort = -1; |
| 795 | int cur_reg = SND_SOC_NOPM; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 796 | int ret; |
| 797 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 798 | list_for_each_entry_safe(w, n, list, power_list) { |
| 799 | ret = 0; |
| 800 | |
| 801 | /* Do we need to apply any queued changes? */ |
| 802 | if (sort[w->id] != cur_sort || w->reg != cur_reg) { |
| 803 | if (!list_empty(&pending)) |
| 804 | dapm_seq_run_coalesced(codec, &pending); |
| 805 | |
| 806 | INIT_LIST_HEAD(&pending); |
| 807 | cur_sort = -1; |
| 808 | cur_reg = SND_SOC_NOPM; |
| 809 | } |
| 810 | |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 811 | switch (w->id) { |
| 812 | case snd_soc_dapm_pre: |
| 813 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 814 | list_for_each_entry_safe_continue(w, n, list, |
| 815 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 816 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 817 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 818 | ret = w->event(w, |
| 819 | NULL, SND_SOC_DAPM_PRE_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 820 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 821 | ret = w->event(w, |
| 822 | NULL, SND_SOC_DAPM_PRE_PMD); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 823 | break; |
| 824 | |
| 825 | case snd_soc_dapm_post: |
| 826 | if (!w->event) |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 827 | list_for_each_entry_safe_continue(w, n, list, |
| 828 | power_list); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 829 | |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 830 | if (event == SND_SOC_DAPM_STREAM_START) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 831 | ret = w->event(w, |
| 832 | NULL, SND_SOC_DAPM_POST_PMU); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 833 | else if (event == SND_SOC_DAPM_STREAM_STOP) |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 834 | ret = w->event(w, |
| 835 | NULL, SND_SOC_DAPM_POST_PMD); |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 836 | break; |
| 837 | |
| 838 | case snd_soc_dapm_input: |
| 839 | case snd_soc_dapm_output: |
| 840 | case snd_soc_dapm_hp: |
| 841 | case snd_soc_dapm_mic: |
| 842 | case snd_soc_dapm_line: |
| 843 | case snd_soc_dapm_spk: |
| 844 | /* No register support currently */ |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 845 | ret = dapm_generic_apply_power(w); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 846 | break; |
| 847 | |
| 848 | default: |
Mark Brown | 8162810 | 2009-06-07 13:21:24 +0100 | [diff] [blame] | 849 | /* Queue it up for application */ |
| 850 | cur_sort = sort[w->id]; |
| 851 | cur_reg = w->reg; |
| 852 | list_move(&w->power_list, &pending); |
| 853 | break; |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 854 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 855 | |
| 856 | if (ret < 0) |
| 857 | pr_err("Failed to apply widget power: %d\n", |
| 858 | ret); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 859 | } |
Mark Brown | b22ead2 | 2009-06-07 12:51:26 +0100 | [diff] [blame] | 860 | |
| 861 | if (!list_empty(&pending)) |
| 862 | dapm_seq_run_coalesced(codec, &pending); |
Mark Brown | 163cac0 | 2009-06-07 10:12:52 +0100 | [diff] [blame] | 863 | } |
| 864 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 865 | /* |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 866 | * Scan each dapm widget for complete audio path. |
| 867 | * A complete path is a route that has valid endpoints i.e.:- |
| 868 | * |
| 869 | * o DAC to output pin. |
| 870 | * o Input Pin to ADC. |
| 871 | * o Input pin to Output pin (bypass, sidetone) |
| 872 | * o DAC to ADC (loopback). |
| 873 | */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 874 | static int dapm_power_widgets(struct snd_soc_codec *codec, int event) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 875 | { |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 876 | struct snd_soc_device *socdev = codec->socdev; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 877 | struct snd_soc_dapm_widget *w; |
Mark Brown | 291f3bb | 2009-06-07 13:57:17 +0100 | [diff] [blame] | 878 | LIST_HEAD(up_list); |
| 879 | LIST_HEAD(down_list); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 880 | int ret = 0; |
Mark Brown | 38357ab | 2009-06-06 19:03:23 +0100 | [diff] [blame] | 881 | int power; |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 882 | int sys_power = 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 883 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 884 | /* Check which widgets we need to power and store them in |
| 885 | * lists indicating if they should be powered up or down. |
| 886 | */ |
| 887 | list_for_each_entry(w, &codec->dapm_widgets, list) { |
| 888 | switch (w->id) { |
| 889 | case snd_soc_dapm_pre: |
Mark Brown | 291f3bb | 2009-06-07 13:57:17 +0100 | [diff] [blame] | 890 | dapm_seq_insert(w, &down_list, dapm_down_seq); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 891 | break; |
| 892 | case snd_soc_dapm_post: |
Mark Brown | 291f3bb | 2009-06-07 13:57:17 +0100 | [diff] [blame] | 893 | dapm_seq_insert(w, &up_list, dapm_up_seq); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 894 | break; |
| 895 | |
| 896 | default: |
| 897 | if (!w->power_check) |
| 898 | continue; |
| 899 | |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 900 | /* If we're suspending then pull down all the |
| 901 | * power. */ |
| 902 | switch (event) { |
| 903 | case SND_SOC_DAPM_STREAM_SUSPEND: |
| 904 | power = 0; |
| 905 | break; |
| 906 | |
| 907 | default: |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 908 | if (!w->force) |
| 909 | power = w->power_check(w); |
| 910 | else |
| 911 | power = 1; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 912 | if (power) |
| 913 | sys_power = 1; |
| 914 | break; |
| 915 | } |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 916 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 917 | if (w->power == power) |
| 918 | continue; |
| 919 | |
| 920 | if (power) |
Mark Brown | 291f3bb | 2009-06-07 13:57:17 +0100 | [diff] [blame] | 921 | dapm_seq_insert(w, &up_list, dapm_up_seq); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 922 | else |
Mark Brown | 291f3bb | 2009-06-07 13:57:17 +0100 | [diff] [blame] | 923 | dapm_seq_insert(w, &down_list, dapm_down_seq); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 924 | |
| 925 | w->power = power; |
| 926 | break; |
| 927 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 928 | } |
| 929 | |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 930 | /* If there are no DAPM widgets then try to figure out power from the |
| 931 | * event type. |
| 932 | */ |
| 933 | if (list_empty(&codec->dapm_widgets)) { |
| 934 | switch (event) { |
| 935 | case SND_SOC_DAPM_STREAM_START: |
| 936 | case SND_SOC_DAPM_STREAM_RESUME: |
| 937 | sys_power = 1; |
| 938 | break; |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 939 | case SND_SOC_DAPM_STREAM_SUSPEND: |
| 940 | sys_power = 0; |
| 941 | break; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 942 | case SND_SOC_DAPM_STREAM_NOP: |
Mark Brown | a96ca33 | 2010-01-19 22:49:43 +0000 | [diff] [blame] | 943 | switch (codec->bias_level) { |
| 944 | case SND_SOC_BIAS_STANDBY: |
| 945 | case SND_SOC_BIAS_OFF: |
| 946 | sys_power = 0; |
| 947 | break; |
| 948 | default: |
| 949 | sys_power = 1; |
| 950 | break; |
| 951 | } |
Mark Brown | 50b6bce | 2009-11-23 13:11:53 +0000 | [diff] [blame] | 952 | break; |
Mark Brown | b14b76a | 2009-08-17 11:55:38 +0100 | [diff] [blame] | 953 | default: |
| 954 | break; |
| 955 | } |
| 956 | } |
| 957 | |
Mark Brown | a96ca33 | 2010-01-19 22:49:43 +0000 | [diff] [blame] | 958 | if (sys_power && codec->bias_level == SND_SOC_BIAS_OFF) { |
| 959 | ret = snd_soc_dapm_set_bias_level(socdev, |
| 960 | SND_SOC_BIAS_STANDBY); |
| 961 | if (ret != 0) |
| 962 | pr_err("Failed to turn on bias: %d\n", ret); |
| 963 | } |
| 964 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 965 | /* If we're changing to all on or all off then prepare */ |
| 966 | if ((sys_power && codec->bias_level == SND_SOC_BIAS_STANDBY) || |
| 967 | (!sys_power && codec->bias_level == SND_SOC_BIAS_ON)) { |
| 968 | ret = snd_soc_dapm_set_bias_level(socdev, |
| 969 | SND_SOC_BIAS_PREPARE); |
| 970 | if (ret != 0) |
| 971 | pr_err("Failed to prepare bias: %d\n", ret); |
| 972 | } |
| 973 | |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 974 | /* Power down widgets first; try to avoid amplifying pops. */ |
Mark Brown | 291f3bb | 2009-06-07 13:57:17 +0100 | [diff] [blame] | 975 | dapm_seq_run(codec, &down_list, event, dapm_down_seq); |
Mark Brown | 6d3ddc8 | 2009-05-16 17:47:29 +0100 | [diff] [blame] | 976 | |
| 977 | /* Now power up. */ |
Mark Brown | 291f3bb | 2009-06-07 13:57:17 +0100 | [diff] [blame] | 978 | dapm_seq_run(codec, &up_list, event, dapm_up_seq); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 979 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 980 | /* If we just powered the last thing off drop to standby bias */ |
| 981 | if (codec->bias_level == SND_SOC_BIAS_PREPARE && !sys_power) { |
| 982 | ret = snd_soc_dapm_set_bias_level(socdev, |
| 983 | SND_SOC_BIAS_STANDBY); |
| 984 | if (ret != 0) |
| 985 | pr_err("Failed to apply standby bias: %d\n", ret); |
| 986 | } |
| 987 | |
Mark Brown | a96ca33 | 2010-01-19 22:49:43 +0000 | [diff] [blame] | 988 | /* If we're in standby and can support bias off then do that */ |
| 989 | if (codec->bias_level == SND_SOC_BIAS_STANDBY && |
| 990 | codec->idle_bias_off) { |
| 991 | ret = snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_OFF); |
| 992 | if (ret != 0) |
| 993 | pr_err("Failed to turn off bias: %d\n", ret); |
| 994 | } |
| 995 | |
Mark Brown | 452c5ea | 2009-05-17 21:41:23 +0100 | [diff] [blame] | 996 | /* If we just powered up then move to active bias */ |
| 997 | if (codec->bias_level == SND_SOC_BIAS_PREPARE && sys_power) { |
| 998 | ret = snd_soc_dapm_set_bias_level(socdev, |
| 999 | SND_SOC_BIAS_ON); |
| 1000 | if (ret != 0) |
| 1001 | pr_err("Failed to apply active bias: %d\n", ret); |
| 1002 | } |
| 1003 | |
Mark Brown | cb507e7 | 2009-07-08 18:54:57 +0100 | [diff] [blame] | 1004 | pop_dbg(codec->pop_time, "DAPM sequencing finished, waiting %dms\n", |
| 1005 | codec->pop_time); |
Mark Brown | 6922471 | 2010-03-03 14:57:09 +0000 | [diff] [blame] | 1006 | pop_wait(codec->pop_time); |
Mark Brown | cb507e7 | 2009-07-08 18:54:57 +0100 | [diff] [blame] | 1007 | |
Mark Brown | 42aa341 | 2009-03-01 19:21:10 +0000 | [diff] [blame] | 1008 | return 0; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1009 | } |
| 1010 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1011 | #ifdef CONFIG_DEBUG_FS |
| 1012 | static int dapm_widget_power_open_file(struct inode *inode, struct file *file) |
| 1013 | { |
| 1014 | file->private_data = inode->i_private; |
| 1015 | return 0; |
| 1016 | } |
| 1017 | |
| 1018 | static ssize_t dapm_widget_power_read_file(struct file *file, |
| 1019 | char __user *user_buf, |
| 1020 | size_t count, loff_t *ppos) |
| 1021 | { |
| 1022 | struct snd_soc_dapm_widget *w = file->private_data; |
| 1023 | char *buf; |
| 1024 | int in, out; |
| 1025 | ssize_t ret; |
| 1026 | struct snd_soc_dapm_path *p = NULL; |
| 1027 | |
| 1028 | buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 1029 | if (!buf) |
| 1030 | return -ENOMEM; |
| 1031 | |
| 1032 | in = is_connected_input_ep(w); |
| 1033 | dapm_clear_walk(w->codec); |
| 1034 | out = is_connected_output_ep(w); |
| 1035 | dapm_clear_walk(w->codec); |
| 1036 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1037 | ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d", |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1038 | w->name, w->power ? "On" : "Off", in, out); |
| 1039 | |
Mark Brown | d033c36 | 2009-12-04 15:25:56 +0000 | [diff] [blame] | 1040 | if (w->reg >= 0) |
| 1041 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
| 1042 | " - R%d(0x%x) bit %d", |
| 1043 | w->reg, w->reg, w->shift); |
| 1044 | |
| 1045 | ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n"); |
| 1046 | |
Mark Brown | 3eef08b | 2009-09-14 16:49:00 +0100 | [diff] [blame] | 1047 | if (w->sname) |
| 1048 | ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n", |
| 1049 | w->sname, |
| 1050 | w->active ? "active" : "inactive"); |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1051 | |
| 1052 | list_for_each_entry(p, &w->sources, list_sink) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1053 | if (p->connected && !p->connected(w, p->sink)) |
| 1054 | continue; |
| 1055 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1056 | if (p->connect) |
| 1057 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
| 1058 | " in %s %s\n", |
| 1059 | p->name ? p->name : "static", |
| 1060 | p->source->name); |
| 1061 | } |
| 1062 | list_for_each_entry(p, &w->sinks, list_source) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1063 | if (p->connected && !p->connected(w, p->sink)) |
| 1064 | continue; |
| 1065 | |
Mark Brown | 79fb938 | 2009-08-21 16:38:13 +0100 | [diff] [blame] | 1066 | if (p->connect) |
| 1067 | ret += snprintf(buf + ret, PAGE_SIZE - ret, |
| 1068 | " out %s %s\n", |
| 1069 | p->name ? p->name : "static", |
| 1070 | p->sink->name); |
| 1071 | } |
| 1072 | |
| 1073 | ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); |
| 1074 | |
| 1075 | kfree(buf); |
| 1076 | return ret; |
| 1077 | } |
| 1078 | |
| 1079 | static const struct file_operations dapm_widget_power_fops = { |
| 1080 | .open = dapm_widget_power_open_file, |
| 1081 | .read = dapm_widget_power_read_file, |
| 1082 | }; |
| 1083 | |
| 1084 | void snd_soc_dapm_debugfs_init(struct snd_soc_codec *codec) |
| 1085 | { |
| 1086 | struct snd_soc_dapm_widget *w; |
| 1087 | struct dentry *d; |
| 1088 | |
| 1089 | if (!codec->debugfs_dapm) |
| 1090 | return; |
| 1091 | |
| 1092 | list_for_each_entry(w, &codec->dapm_widgets, list) { |
| 1093 | if (!w->name) |
| 1094 | continue; |
| 1095 | |
| 1096 | d = debugfs_create_file(w->name, 0444, |
| 1097 | codec->debugfs_dapm, w, |
| 1098 | &dapm_widget_power_fops); |
| 1099 | if (!d) |
| 1100 | printk(KERN_WARNING |
| 1101 | "ASoC: Failed to create %s debugfs file\n", |
| 1102 | w->name); |
| 1103 | } |
| 1104 | } |
| 1105 | #else |
| 1106 | void snd_soc_dapm_debugfs_init(struct snd_soc_codec *codec) |
| 1107 | { |
| 1108 | } |
| 1109 | #endif |
| 1110 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1111 | /* test and update the power status of a mux widget */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 1112 | static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget, |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1113 | struct snd_kcontrol *kcontrol, int change, |
| 1114 | int mux, struct soc_enum *e) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1115 | { |
| 1116 | struct snd_soc_dapm_path *path; |
| 1117 | int found = 0; |
| 1118 | |
Peter Ujfalusi | eff317d | 2009-01-15 14:40:47 +0200 | [diff] [blame] | 1119 | if (widget->id != snd_soc_dapm_mux && |
| 1120 | widget->id != snd_soc_dapm_value_mux) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1121 | return -ENODEV; |
| 1122 | |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1123 | if (!change) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1124 | return 0; |
| 1125 | |
| 1126 | /* find dapm widget path assoc with kcontrol */ |
| 1127 | list_for_each_entry(path, &widget->codec->dapm_paths, list) { |
| 1128 | if (path->kcontrol != kcontrol) |
| 1129 | continue; |
| 1130 | |
Richard Zhao | cb01e2b | 2008-10-07 08:05:20 +0800 | [diff] [blame] | 1131 | if (!path->name || !e->texts[mux]) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1132 | continue; |
| 1133 | |
| 1134 | found = 1; |
| 1135 | /* we now need to match the string in the enum to the path */ |
Richard Zhao | cb01e2b | 2008-10-07 08:05:20 +0800 | [diff] [blame] | 1136 | if (!(strcmp(path->name, e->texts[mux]))) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1137 | path->connect = 1; /* new connection */ |
| 1138 | else |
| 1139 | path->connect = 0; /* old connection must be powered down */ |
| 1140 | } |
| 1141 | |
Mark Brown | b91b8fa | 2010-01-20 18:18:35 +0000 | [diff] [blame] | 1142 | if (found) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1143 | dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP); |
| 1144 | |
| 1145 | return 0; |
| 1146 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1147 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1148 | /* test and update the power status of a mixer or switch widget */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 1149 | static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1150 | struct snd_kcontrol *kcontrol, int connect) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1151 | { |
| 1152 | struct snd_soc_dapm_path *path; |
| 1153 | int found = 0; |
| 1154 | |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1155 | if (widget->id != snd_soc_dapm_mixer && |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1156 | widget->id != snd_soc_dapm_mixer_named_ctl && |
Milan plzik | 1b075e3 | 2008-01-10 14:39:46 +0100 | [diff] [blame] | 1157 | widget->id != snd_soc_dapm_switch) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1158 | return -ENODEV; |
| 1159 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1160 | /* find dapm widget path assoc with kcontrol */ |
| 1161 | list_for_each_entry(path, &widget->codec->dapm_paths, list) { |
| 1162 | if (path->kcontrol != kcontrol) |
| 1163 | continue; |
| 1164 | |
| 1165 | /* found, now check type */ |
| 1166 | found = 1; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1167 | path->connect = connect; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1168 | break; |
| 1169 | } |
| 1170 | |
Mark Brown | b91b8fa | 2010-01-20 18:18:35 +0000 | [diff] [blame] | 1171 | if (found) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1172 | dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP); |
| 1173 | |
| 1174 | return 0; |
| 1175 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1176 | |
| 1177 | /* show dapm widget status in sys fs */ |
| 1178 | static ssize_t dapm_widget_show(struct device *dev, |
| 1179 | struct device_attribute *attr, char *buf) |
| 1180 | { |
| 1181 | struct snd_soc_device *devdata = dev_get_drvdata(dev); |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 1182 | struct snd_soc_codec *codec = devdata->card->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1183 | struct snd_soc_dapm_widget *w; |
| 1184 | int count = 0; |
| 1185 | char *state = "not set"; |
| 1186 | |
| 1187 | list_for_each_entry(w, &codec->dapm_widgets, list) { |
| 1188 | |
| 1189 | /* only display widgets that burnm power */ |
| 1190 | switch (w->id) { |
| 1191 | case snd_soc_dapm_hp: |
| 1192 | case snd_soc_dapm_mic: |
| 1193 | case snd_soc_dapm_spk: |
| 1194 | case snd_soc_dapm_line: |
| 1195 | case snd_soc_dapm_micbias: |
| 1196 | case snd_soc_dapm_dac: |
| 1197 | case snd_soc_dapm_adc: |
| 1198 | case snd_soc_dapm_pga: |
| 1199 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1200 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1201 | case snd_soc_dapm_supply: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1202 | if (w->name) |
| 1203 | count += sprintf(buf + count, "%s: %s\n", |
| 1204 | w->name, w->power ? "On":"Off"); |
| 1205 | break; |
| 1206 | default: |
| 1207 | break; |
| 1208 | } |
| 1209 | } |
| 1210 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1211 | switch (codec->bias_level) { |
| 1212 | case SND_SOC_BIAS_ON: |
| 1213 | state = "On"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1214 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1215 | case SND_SOC_BIAS_PREPARE: |
| 1216 | state = "Prepare"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1217 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1218 | case SND_SOC_BIAS_STANDBY: |
| 1219 | state = "Standby"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1220 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1221 | case SND_SOC_BIAS_OFF: |
| 1222 | state = "Off"; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1223 | break; |
| 1224 | } |
| 1225 | count += sprintf(buf + count, "PM State: %s\n", state); |
| 1226 | |
| 1227 | return count; |
| 1228 | } |
| 1229 | |
| 1230 | static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL); |
| 1231 | |
| 1232 | int snd_soc_dapm_sys_add(struct device *dev) |
| 1233 | { |
Troy Kisky | 12ef193 | 2008-10-13 17:42:14 -0700 | [diff] [blame] | 1234 | return device_create_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | static void snd_soc_dapm_sys_remove(struct device *dev) |
| 1238 | { |
Mark Brown | aef9084 | 2009-05-16 17:53:16 +0100 | [diff] [blame] | 1239 | device_remove_file(dev, &dev_attr_dapm_widget); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | /* free all dapm widgets and resources */ |
Adrian Bunk | d9c96cf | 2006-11-28 12:10:09 +0100 | [diff] [blame] | 1243 | static void dapm_free_widgets(struct snd_soc_codec *codec) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1244 | { |
| 1245 | struct snd_soc_dapm_widget *w, *next_w; |
| 1246 | struct snd_soc_dapm_path *p, *next_p; |
| 1247 | |
| 1248 | list_for_each_entry_safe(w, next_w, &codec->dapm_widgets, list) { |
| 1249 | list_del(&w->list); |
| 1250 | kfree(w); |
| 1251 | } |
| 1252 | |
| 1253 | list_for_each_entry_safe(p, next_p, &codec->dapm_paths, list) { |
| 1254 | list_del(&p->list); |
| 1255 | kfree(p->long_name); |
| 1256 | kfree(p); |
| 1257 | } |
| 1258 | } |
| 1259 | |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1260 | static int snd_soc_dapm_set_pin(struct snd_soc_codec *codec, |
Mark Brown | 1649923 | 2009-01-07 18:25:13 +0000 | [diff] [blame] | 1261 | const char *pin, int status) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1262 | { |
| 1263 | struct snd_soc_dapm_widget *w; |
| 1264 | |
| 1265 | list_for_each_entry(w, &codec->dapm_widgets, list) { |
| 1266 | if (!strcmp(w->name, pin)) { |
Mark Brown | c1286b8 | 2008-07-07 19:26:03 +0100 | [diff] [blame] | 1267 | pr_debug("dapm: %s: pin %s\n", codec->name, pin); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1268 | w->connected = status; |
| 1269 | return 0; |
| 1270 | } |
| 1271 | } |
| 1272 | |
Mark Brown | c1286b8 | 2008-07-07 19:26:03 +0100 | [diff] [blame] | 1273 | pr_err("dapm: %s: configuring unknown pin %s\n", codec->name, pin); |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1274 | return -EINVAL; |
| 1275 | } |
| 1276 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1277 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1278 | * snd_soc_dapm_sync - scan and power dapm paths |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1279 | * @codec: audio codec |
| 1280 | * |
| 1281 | * Walks all dapm audio paths and powers widgets according to their |
| 1282 | * stream or path usage. |
| 1283 | * |
| 1284 | * Returns 0 for success. |
| 1285 | */ |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1286 | int snd_soc_dapm_sync(struct snd_soc_codec *codec) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1287 | { |
Mark Brown | b91b8fa | 2010-01-20 18:18:35 +0000 | [diff] [blame] | 1288 | return dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1289 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 1290 | EXPORT_SYMBOL_GPL(snd_soc_dapm_sync); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1291 | |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1292 | static int snd_soc_dapm_add_route(struct snd_soc_codec *codec, |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1293 | const struct snd_soc_dapm_route *route) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1294 | { |
| 1295 | struct snd_soc_dapm_path *path; |
| 1296 | struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1297 | const char *sink = route->sink; |
| 1298 | const char *control = route->control; |
| 1299 | const char *source = route->source; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1300 | int ret = 0; |
| 1301 | |
| 1302 | /* find src and dest widgets */ |
| 1303 | list_for_each_entry(w, &codec->dapm_widgets, list) { |
| 1304 | |
| 1305 | if (!wsink && !(strcmp(w->name, sink))) { |
| 1306 | wsink = w; |
| 1307 | continue; |
| 1308 | } |
| 1309 | if (!wsource && !(strcmp(w->name, source))) { |
| 1310 | wsource = w; |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | if (wsource == NULL || wsink == NULL) |
| 1315 | return -ENODEV; |
| 1316 | |
| 1317 | path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL); |
| 1318 | if (!path) |
| 1319 | return -ENOMEM; |
| 1320 | |
| 1321 | path->source = wsource; |
| 1322 | path->sink = wsink; |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1323 | path->connected = route->connected; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1324 | INIT_LIST_HEAD(&path->list); |
| 1325 | INIT_LIST_HEAD(&path->list_source); |
| 1326 | INIT_LIST_HEAD(&path->list_sink); |
| 1327 | |
| 1328 | /* check for external widgets */ |
| 1329 | if (wsink->id == snd_soc_dapm_input) { |
| 1330 | if (wsource->id == snd_soc_dapm_micbias || |
| 1331 | wsource->id == snd_soc_dapm_mic || |
Rongrong Cao | 087d53a | 2009-07-10 20:13:30 +0100 | [diff] [blame] | 1332 | wsource->id == snd_soc_dapm_line || |
| 1333 | wsource->id == snd_soc_dapm_output) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1334 | wsink->ext = 1; |
| 1335 | } |
| 1336 | if (wsource->id == snd_soc_dapm_output) { |
| 1337 | if (wsink->id == snd_soc_dapm_spk || |
| 1338 | wsink->id == snd_soc_dapm_hp || |
Seth Forshee | 1e39221 | 2007-04-16 15:36:42 +0200 | [diff] [blame] | 1339 | wsink->id == snd_soc_dapm_line || |
| 1340 | wsink->id == snd_soc_dapm_input) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1341 | wsource->ext = 1; |
| 1342 | } |
| 1343 | |
| 1344 | /* connect static paths */ |
| 1345 | if (control == NULL) { |
| 1346 | list_add(&path->list, &codec->dapm_paths); |
| 1347 | list_add(&path->list_sink, &wsink->sources); |
| 1348 | list_add(&path->list_source, &wsource->sinks); |
| 1349 | path->connect = 1; |
| 1350 | return 0; |
| 1351 | } |
| 1352 | |
| 1353 | /* connect dynamic paths */ |
| 1354 | switch(wsink->id) { |
| 1355 | case snd_soc_dapm_adc: |
| 1356 | case snd_soc_dapm_dac: |
| 1357 | case snd_soc_dapm_pga: |
| 1358 | case snd_soc_dapm_input: |
| 1359 | case snd_soc_dapm_output: |
| 1360 | case snd_soc_dapm_micbias: |
| 1361 | case snd_soc_dapm_vmid: |
| 1362 | case snd_soc_dapm_pre: |
| 1363 | case snd_soc_dapm_post: |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1364 | case snd_soc_dapm_supply: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 1365 | case snd_soc_dapm_aif_in: |
| 1366 | case snd_soc_dapm_aif_out: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1367 | list_add(&path->list, &codec->dapm_paths); |
| 1368 | list_add(&path->list_sink, &wsink->sources); |
| 1369 | list_add(&path->list_source, &wsource->sinks); |
| 1370 | path->connect = 1; |
| 1371 | return 0; |
| 1372 | case snd_soc_dapm_mux: |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 1373 | case snd_soc_dapm_value_mux: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1374 | ret = dapm_connect_mux(codec, wsource, wsink, path, control, |
| 1375 | &wsink->kcontrols[0]); |
| 1376 | if (ret != 0) |
| 1377 | goto err; |
| 1378 | break; |
| 1379 | case snd_soc_dapm_switch: |
| 1380 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1381 | case snd_soc_dapm_mixer_named_ctl: |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1382 | ret = dapm_connect_mixer(codec, wsource, wsink, path, control); |
| 1383 | if (ret != 0) |
| 1384 | goto err; |
| 1385 | break; |
| 1386 | case snd_soc_dapm_hp: |
| 1387 | case snd_soc_dapm_mic: |
| 1388 | case snd_soc_dapm_line: |
| 1389 | case snd_soc_dapm_spk: |
| 1390 | list_add(&path->list, &codec->dapm_paths); |
| 1391 | list_add(&path->list_sink, &wsink->sources); |
| 1392 | list_add(&path->list_source, &wsource->sinks); |
| 1393 | path->connect = 0; |
| 1394 | return 0; |
| 1395 | } |
| 1396 | return 0; |
| 1397 | |
| 1398 | err: |
| 1399 | printk(KERN_WARNING "asoc: no dapm match for %s --> %s --> %s\n", source, |
| 1400 | control, sink); |
| 1401 | kfree(path); |
| 1402 | return ret; |
| 1403 | } |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1404 | |
| 1405 | /** |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1406 | * snd_soc_dapm_add_routes - Add routes between DAPM widgets |
| 1407 | * @codec: codec |
| 1408 | * @route: audio routes |
| 1409 | * @num: number of routes |
| 1410 | * |
| 1411 | * Connects 2 dapm widgets together via a named audio path. The sink is |
| 1412 | * the widget receiving the audio signal, whilst the source is the sender |
| 1413 | * of the audio signal. |
| 1414 | * |
| 1415 | * Returns 0 for success else error. On error all resources can be freed |
| 1416 | * with a call to snd_soc_card_free(). |
| 1417 | */ |
| 1418 | int snd_soc_dapm_add_routes(struct snd_soc_codec *codec, |
| 1419 | const struct snd_soc_dapm_route *route, int num) |
| 1420 | { |
| 1421 | int i, ret; |
| 1422 | |
| 1423 | for (i = 0; i < num; i++) { |
Mark Brown | 215edda | 2009-09-08 18:59:05 +0100 | [diff] [blame] | 1424 | ret = snd_soc_dapm_add_route(codec, route); |
Mark Brown | 105f1c2 | 2008-05-13 14:52:19 +0200 | [diff] [blame] | 1425 | if (ret < 0) { |
| 1426 | printk(KERN_ERR "Failed to add route %s->%s\n", |
| 1427 | route->source, |
| 1428 | route->sink); |
| 1429 | return ret; |
| 1430 | } |
| 1431 | route++; |
| 1432 | } |
| 1433 | |
| 1434 | return 0; |
| 1435 | } |
| 1436 | EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes); |
| 1437 | |
| 1438 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1439 | * snd_soc_dapm_new_widgets - add new dapm widgets |
| 1440 | * @codec: audio codec |
| 1441 | * |
| 1442 | * Checks the codec for any new dapm widgets and creates them if found. |
| 1443 | * |
| 1444 | * Returns 0 for success. |
| 1445 | */ |
| 1446 | int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec) |
| 1447 | { |
| 1448 | struct snd_soc_dapm_widget *w; |
| 1449 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1450 | list_for_each_entry(w, &codec->dapm_widgets, list) |
| 1451 | { |
| 1452 | if (w->new) |
| 1453 | continue; |
| 1454 | |
| 1455 | switch(w->id) { |
| 1456 | case snd_soc_dapm_switch: |
| 1457 | case snd_soc_dapm_mixer: |
Ian Molton | ca9c1aa | 2009-01-06 20:11:51 +0000 | [diff] [blame] | 1458 | case snd_soc_dapm_mixer_named_ctl: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1459 | w->power_check = dapm_generic_check_power; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1460 | dapm_new_mixer(codec, w); |
| 1461 | break; |
| 1462 | case snd_soc_dapm_mux: |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1463 | case snd_soc_dapm_value_mux: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1464 | w->power_check = dapm_generic_check_power; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1465 | dapm_new_mux(codec, w); |
| 1466 | break; |
| 1467 | case snd_soc_dapm_adc: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 1468 | case snd_soc_dapm_aif_out: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1469 | w->power_check = dapm_adc_check_power; |
| 1470 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1471 | case snd_soc_dapm_dac: |
Mark Brown | 010ff26 | 2009-08-17 17:39:22 +0100 | [diff] [blame] | 1472 | case snd_soc_dapm_aif_in: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1473 | w->power_check = dapm_dac_check_power; |
| 1474 | break; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1475 | case snd_soc_dapm_pga: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1476 | w->power_check = dapm_generic_check_power; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1477 | dapm_new_pga(codec, w); |
| 1478 | break; |
| 1479 | case snd_soc_dapm_input: |
| 1480 | case snd_soc_dapm_output: |
| 1481 | case snd_soc_dapm_micbias: |
| 1482 | case snd_soc_dapm_spk: |
| 1483 | case snd_soc_dapm_hp: |
| 1484 | case snd_soc_dapm_mic: |
| 1485 | case snd_soc_dapm_line: |
Mark Brown | b75576d | 2009-04-20 17:56:13 +0100 | [diff] [blame] | 1486 | w->power_check = dapm_generic_check_power; |
| 1487 | break; |
Mark Brown | 246d0a1 | 2009-04-22 18:24:55 +0100 | [diff] [blame] | 1488 | case snd_soc_dapm_supply: |
| 1489 | w->power_check = dapm_supply_check_power; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1490 | case snd_soc_dapm_vmid: |
| 1491 | case snd_soc_dapm_pre: |
| 1492 | case snd_soc_dapm_post: |
| 1493 | break; |
| 1494 | } |
| 1495 | w->new = 1; |
| 1496 | } |
| 1497 | |
| 1498 | dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1499 | return 0; |
| 1500 | } |
| 1501 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets); |
| 1502 | |
| 1503 | /** |
| 1504 | * snd_soc_dapm_get_volsw - dapm mixer get callback |
| 1505 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1506 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1507 | * |
| 1508 | * Callback to get the value of a dapm mixer control. |
| 1509 | * |
| 1510 | * Returns 0 for success. |
| 1511 | */ |
| 1512 | int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol, |
| 1513 | struct snd_ctl_elem_value *ucontrol) |
| 1514 | { |
| 1515 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1516 | struct soc_mixer_control *mc = |
| 1517 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1518 | unsigned int reg = mc->reg; |
| 1519 | unsigned int shift = mc->shift; |
| 1520 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1521 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1522 | unsigned int invert = mc->invert; |
| 1523 | unsigned int mask = (1 << fls(max)) - 1; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1524 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1525 | ucontrol->value.integer.value[0] = |
| 1526 | (snd_soc_read(widget->codec, reg) >> shift) & mask; |
| 1527 | if (shift != rshift) |
| 1528 | ucontrol->value.integer.value[1] = |
| 1529 | (snd_soc_read(widget->codec, reg) >> rshift) & mask; |
| 1530 | if (invert) { |
| 1531 | ucontrol->value.integer.value[0] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1532 | max - ucontrol->value.integer.value[0]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1533 | if (shift != rshift) |
| 1534 | ucontrol->value.integer.value[1] = |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1535 | max - ucontrol->value.integer.value[1]; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | return 0; |
| 1539 | } |
| 1540 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw); |
| 1541 | |
| 1542 | /** |
| 1543 | * snd_soc_dapm_put_volsw - dapm mixer set callback |
| 1544 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1545 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1546 | * |
| 1547 | * Callback to set the value of a dapm mixer control. |
| 1548 | * |
| 1549 | * Returns 0 for success. |
| 1550 | */ |
| 1551 | int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, |
| 1552 | struct snd_ctl_elem_value *ucontrol) |
| 1553 | { |
| 1554 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1555 | struct soc_mixer_control *mc = |
| 1556 | (struct soc_mixer_control *)kcontrol->private_value; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1557 | unsigned int reg = mc->reg; |
| 1558 | unsigned int shift = mc->shift; |
| 1559 | unsigned int rshift = mc->rshift; |
Jon Smirl | 4eaa981 | 2008-07-29 11:42:26 +0100 | [diff] [blame] | 1560 | int max = mc->max; |
Jon Smirl | 815ecf8d | 2008-07-29 10:22:24 -0400 | [diff] [blame] | 1561 | unsigned int mask = (1 << fls(max)) - 1; |
| 1562 | unsigned int invert = mc->invert; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 1563 | unsigned int val, val2, val_mask; |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1564 | int connect; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1565 | int ret; |
| 1566 | |
| 1567 | val = (ucontrol->value.integer.value[0] & mask); |
| 1568 | |
| 1569 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1570 | val = max - val; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1571 | val_mask = mask << shift; |
| 1572 | val = val << shift; |
| 1573 | if (shift != rshift) { |
| 1574 | val2 = (ucontrol->value.integer.value[1] & mask); |
| 1575 | if (invert) |
Philipp Zabel | a7a4ac8 | 2008-01-10 14:37:42 +0100 | [diff] [blame] | 1576 | val2 = max - val2; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1577 | val_mask |= mask << rshift; |
| 1578 | val |= val2 << rshift; |
| 1579 | } |
| 1580 | |
| 1581 | mutex_lock(&widget->codec->mutex); |
| 1582 | widget->value = val; |
| 1583 | |
Mark Brown | 283375c | 2009-12-07 18:09:03 +0000 | [diff] [blame] | 1584 | if (snd_soc_test_bits(widget->codec, reg, val_mask, val)) { |
| 1585 | if (val) |
| 1586 | /* new connection */ |
| 1587 | connect = invert ? 0:1; |
| 1588 | else |
| 1589 | /* old connection must be powered down */ |
| 1590 | connect = invert ? 1:0; |
| 1591 | |
| 1592 | dapm_mixer_update_power(widget, kcontrol, connect); |
| 1593 | } |
| 1594 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1595 | if (widget->event) { |
| 1596 | if (widget->event_flags & SND_SOC_DAPM_PRE_REG) { |
Laim Girdwood | 9af6d95 | 2008-01-10 14:41:02 +0100 | [diff] [blame] | 1597 | ret = widget->event(widget, kcontrol, |
| 1598 | SND_SOC_DAPM_PRE_REG); |
| 1599 | if (ret < 0) { |
| 1600 | ret = 1; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1601 | goto out; |
Laim Girdwood | 9af6d95 | 2008-01-10 14:41:02 +0100 | [diff] [blame] | 1602 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1603 | } |
| 1604 | ret = snd_soc_update_bits(widget->codec, reg, val_mask, val); |
| 1605 | if (widget->event_flags & SND_SOC_DAPM_POST_REG) |
Laim Girdwood | 9af6d95 | 2008-01-10 14:41:02 +0100 | [diff] [blame] | 1606 | ret = widget->event(widget, kcontrol, |
| 1607 | SND_SOC_DAPM_POST_REG); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1608 | } else |
| 1609 | ret = snd_soc_update_bits(widget->codec, reg, val_mask, val); |
| 1610 | |
| 1611 | out: |
| 1612 | mutex_unlock(&widget->codec->mutex); |
| 1613 | return ret; |
| 1614 | } |
| 1615 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw); |
| 1616 | |
| 1617 | /** |
| 1618 | * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback |
| 1619 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1620 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1621 | * |
| 1622 | * Callback to get the value of a dapm enumerated double mixer control. |
| 1623 | * |
| 1624 | * Returns 0 for success. |
| 1625 | */ |
| 1626 | int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol, |
| 1627 | struct snd_ctl_elem_value *ucontrol) |
| 1628 | { |
| 1629 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
| 1630 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 1631 | unsigned int val, bitmask; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1632 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1633 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1634 | ; |
| 1635 | val = snd_soc_read(widget->codec, e->reg); |
| 1636 | ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1); |
| 1637 | if (e->shift_l != e->shift_r) |
| 1638 | ucontrol->value.enumerated.item[1] = |
| 1639 | (val >> e->shift_r) & (bitmask - 1); |
| 1640 | |
| 1641 | return 0; |
| 1642 | } |
| 1643 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double); |
| 1644 | |
| 1645 | /** |
| 1646 | * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback |
| 1647 | * @kcontrol: mixer control |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 1648 | * @ucontrol: control element information |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1649 | * |
| 1650 | * Callback to set the value of a dapm enumerated double mixer control. |
| 1651 | * |
| 1652 | * Returns 0 for success. |
| 1653 | */ |
| 1654 | int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol, |
| 1655 | struct snd_ctl_elem_value *ucontrol) |
| 1656 | { |
| 1657 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
| 1658 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1659 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 1660 | unsigned int mask, bitmask; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1661 | int ret = 0; |
| 1662 | |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1663 | for (bitmask = 1; bitmask < e->max; bitmask <<= 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1664 | ; |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1665 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1666 | return -EINVAL; |
| 1667 | mux = ucontrol->value.enumerated.item[0]; |
| 1668 | val = mux << e->shift_l; |
| 1669 | mask = (bitmask - 1) << e->shift_l; |
| 1670 | if (e->shift_l != e->shift_r) { |
Jon Smirl | f8ba0b7 | 2008-07-29 11:42:27 +0100 | [diff] [blame] | 1671 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1672 | return -EINVAL; |
| 1673 | val |= ucontrol->value.enumerated.item[1] << e->shift_r; |
| 1674 | mask |= (bitmask - 1) << e->shift_r; |
| 1675 | } |
| 1676 | |
| 1677 | mutex_lock(&widget->codec->mutex); |
| 1678 | widget->value = val; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1679 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
| 1680 | dapm_mux_update_power(widget, kcontrol, change, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 1681 | |
| 1682 | if (widget->event_flags & SND_SOC_DAPM_PRE_REG) { |
| 1683 | ret = widget->event(widget, |
| 1684 | kcontrol, SND_SOC_DAPM_PRE_REG); |
| 1685 | if (ret < 0) |
| 1686 | goto out; |
| 1687 | } |
| 1688 | |
| 1689 | ret = snd_soc_update_bits(widget->codec, e->reg, mask, val); |
| 1690 | |
| 1691 | if (widget->event_flags & SND_SOC_DAPM_POST_REG) |
| 1692 | ret = widget->event(widget, |
| 1693 | kcontrol, SND_SOC_DAPM_POST_REG); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1694 | |
| 1695 | out: |
| 1696 | mutex_unlock(&widget->codec->mutex); |
| 1697 | return ret; |
| 1698 | } |
| 1699 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double); |
| 1700 | |
| 1701 | /** |
Mark Brown | d2b247a | 2009-10-06 15:21:04 +0100 | [diff] [blame] | 1702 | * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux |
| 1703 | * @kcontrol: mixer control |
| 1704 | * @ucontrol: control element information |
| 1705 | * |
| 1706 | * Returns 0 for success. |
| 1707 | */ |
| 1708 | int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol, |
| 1709 | struct snd_ctl_elem_value *ucontrol) |
| 1710 | { |
| 1711 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
| 1712 | |
| 1713 | ucontrol->value.enumerated.item[0] = widget->value; |
| 1714 | |
| 1715 | return 0; |
| 1716 | } |
| 1717 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt); |
| 1718 | |
| 1719 | /** |
| 1720 | * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux |
| 1721 | * @kcontrol: mixer control |
| 1722 | * @ucontrol: control element information |
| 1723 | * |
| 1724 | * Returns 0 for success. |
| 1725 | */ |
| 1726 | int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol, |
| 1727 | struct snd_ctl_elem_value *ucontrol) |
| 1728 | { |
| 1729 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
| 1730 | struct soc_enum *e = |
| 1731 | (struct soc_enum *)kcontrol->private_value; |
| 1732 | int change; |
| 1733 | int ret = 0; |
| 1734 | |
| 1735 | if (ucontrol->value.enumerated.item[0] >= e->max) |
| 1736 | return -EINVAL; |
| 1737 | |
| 1738 | mutex_lock(&widget->codec->mutex); |
| 1739 | |
| 1740 | change = widget->value != ucontrol->value.enumerated.item[0]; |
| 1741 | widget->value = ucontrol->value.enumerated.item[0]; |
| 1742 | dapm_mux_update_power(widget, kcontrol, change, widget->value, e); |
| 1743 | |
| 1744 | mutex_unlock(&widget->codec->mutex); |
| 1745 | return ret; |
| 1746 | } |
| 1747 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt); |
| 1748 | |
| 1749 | /** |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1750 | * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get |
| 1751 | * callback |
| 1752 | * @kcontrol: mixer control |
| 1753 | * @ucontrol: control element information |
| 1754 | * |
| 1755 | * Callback to get the value of a dapm semi enumerated double mixer control. |
| 1756 | * |
| 1757 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 1758 | * used for handling bitfield coded enumeration for example. |
| 1759 | * |
| 1760 | * Returns 0 for success. |
| 1761 | */ |
| 1762 | int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol, |
| 1763 | struct snd_ctl_elem_value *ucontrol) |
| 1764 | { |
| 1765 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 1766 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 1767 | unsigned int reg_val, val, mux; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1768 | |
| 1769 | reg_val = snd_soc_read(widget->codec, e->reg); |
| 1770 | val = (reg_val >> e->shift_l) & e->mask; |
| 1771 | for (mux = 0; mux < e->max; mux++) { |
| 1772 | if (val == e->values[mux]) |
| 1773 | break; |
| 1774 | } |
| 1775 | ucontrol->value.enumerated.item[0] = mux; |
| 1776 | if (e->shift_l != e->shift_r) { |
| 1777 | val = (reg_val >> e->shift_r) & e->mask; |
| 1778 | for (mux = 0; mux < e->max; mux++) { |
| 1779 | if (val == e->values[mux]) |
| 1780 | break; |
| 1781 | } |
| 1782 | ucontrol->value.enumerated.item[1] = mux; |
| 1783 | } |
| 1784 | |
| 1785 | return 0; |
| 1786 | } |
| 1787 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double); |
| 1788 | |
| 1789 | /** |
| 1790 | * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set |
| 1791 | * callback |
| 1792 | * @kcontrol: mixer control |
| 1793 | * @ucontrol: control element information |
| 1794 | * |
| 1795 | * Callback to set the value of a dapm semi enumerated double mixer control. |
| 1796 | * |
| 1797 | * Semi enumerated mixer: the enumerated items are referred as values. Can be |
| 1798 | * used for handling bitfield coded enumeration for example. |
| 1799 | * |
| 1800 | * Returns 0 for success. |
| 1801 | */ |
| 1802 | int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, |
| 1803 | struct snd_ctl_elem_value *ucontrol) |
| 1804 | { |
| 1805 | struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol); |
Peter Ujfalusi | 7415555 | 2009-01-08 13:34:29 +0200 | [diff] [blame] | 1806 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1807 | unsigned int val, mux, change; |
Daniel Ribeiro | 46f5822 | 2009-06-07 02:49:11 -0300 | [diff] [blame] | 1808 | unsigned int mask; |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1809 | int ret = 0; |
| 1810 | |
| 1811 | if (ucontrol->value.enumerated.item[0] > e->max - 1) |
| 1812 | return -EINVAL; |
| 1813 | mux = ucontrol->value.enumerated.item[0]; |
| 1814 | val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; |
| 1815 | mask = e->mask << e->shift_l; |
| 1816 | if (e->shift_l != e->shift_r) { |
| 1817 | if (ucontrol->value.enumerated.item[1] > e->max - 1) |
| 1818 | return -EINVAL; |
| 1819 | val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; |
| 1820 | mask |= e->mask << e->shift_r; |
| 1821 | } |
| 1822 | |
| 1823 | mutex_lock(&widget->codec->mutex); |
| 1824 | widget->value = val; |
Mark Brown | 3a65577 | 2009-10-05 17:23:30 +0100 | [diff] [blame] | 1825 | change = snd_soc_test_bits(widget->codec, e->reg, mask, val); |
| 1826 | dapm_mux_update_power(widget, kcontrol, change, mux, e); |
Mark Brown | 1642e3d | 2009-10-05 16:24:26 +0100 | [diff] [blame] | 1827 | |
| 1828 | if (widget->event_flags & SND_SOC_DAPM_PRE_REG) { |
| 1829 | ret = widget->event(widget, |
| 1830 | kcontrol, SND_SOC_DAPM_PRE_REG); |
| 1831 | if (ret < 0) |
| 1832 | goto out; |
| 1833 | } |
| 1834 | |
| 1835 | ret = snd_soc_update_bits(widget->codec, e->reg, mask, val); |
| 1836 | |
| 1837 | if (widget->event_flags & SND_SOC_DAPM_POST_REG) |
| 1838 | ret = widget->event(widget, |
| 1839 | kcontrol, SND_SOC_DAPM_POST_REG); |
Peter Ujfalusi | 2e72f8e | 2009-01-05 09:54:57 +0200 | [diff] [blame] | 1840 | |
| 1841 | out: |
| 1842 | mutex_unlock(&widget->codec->mutex); |
| 1843 | return ret; |
| 1844 | } |
| 1845 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); |
| 1846 | |
| 1847 | /** |
Mark Brown | 8b37dbd | 2009-02-28 21:14:20 +0000 | [diff] [blame] | 1848 | * snd_soc_dapm_info_pin_switch - Info for a pin switch |
| 1849 | * |
| 1850 | * @kcontrol: mixer control |
| 1851 | * @uinfo: control element information |
| 1852 | * |
| 1853 | * Callback to provide information about a pin switch control. |
| 1854 | */ |
| 1855 | int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol, |
| 1856 | struct snd_ctl_elem_info *uinfo) |
| 1857 | { |
| 1858 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 1859 | uinfo->count = 1; |
| 1860 | uinfo->value.integer.min = 0; |
| 1861 | uinfo->value.integer.max = 1; |
| 1862 | |
| 1863 | return 0; |
| 1864 | } |
| 1865 | EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch); |
| 1866 | |
| 1867 | /** |
| 1868 | * snd_soc_dapm_get_pin_switch - Get information for a pin switch |
| 1869 | * |
| 1870 | * @kcontrol: mixer control |
| 1871 | * @ucontrol: Value |
| 1872 | */ |
| 1873 | int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol, |
| 1874 | struct snd_ctl_elem_value *ucontrol) |
| 1875 | { |
| 1876 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1877 | const char *pin = (const char *)kcontrol->private_value; |
| 1878 | |
| 1879 | mutex_lock(&codec->mutex); |
| 1880 | |
| 1881 | ucontrol->value.integer.value[0] = |
| 1882 | snd_soc_dapm_get_pin_status(codec, pin); |
| 1883 | |
| 1884 | mutex_unlock(&codec->mutex); |
| 1885 | |
| 1886 | return 0; |
| 1887 | } |
| 1888 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch); |
| 1889 | |
| 1890 | /** |
| 1891 | * snd_soc_dapm_put_pin_switch - Set information for a pin switch |
| 1892 | * |
| 1893 | * @kcontrol: mixer control |
| 1894 | * @ucontrol: Value |
| 1895 | */ |
| 1896 | int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol, |
| 1897 | struct snd_ctl_elem_value *ucontrol) |
| 1898 | { |
| 1899 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 1900 | const char *pin = (const char *)kcontrol->private_value; |
| 1901 | |
| 1902 | mutex_lock(&codec->mutex); |
| 1903 | |
| 1904 | if (ucontrol->value.integer.value[0]) |
| 1905 | snd_soc_dapm_enable_pin(codec, pin); |
| 1906 | else |
| 1907 | snd_soc_dapm_disable_pin(codec, pin); |
| 1908 | |
| 1909 | snd_soc_dapm_sync(codec); |
| 1910 | |
| 1911 | mutex_unlock(&codec->mutex); |
| 1912 | |
| 1913 | return 0; |
| 1914 | } |
| 1915 | EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch); |
| 1916 | |
| 1917 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1918 | * snd_soc_dapm_new_control - create new dapm control |
| 1919 | * @codec: audio codec |
| 1920 | * @widget: widget template |
| 1921 | * |
| 1922 | * Creates a new dapm control based upon the template. |
| 1923 | * |
| 1924 | * Returns 0 for success else error. |
| 1925 | */ |
| 1926 | int snd_soc_dapm_new_control(struct snd_soc_codec *codec, |
| 1927 | const struct snd_soc_dapm_widget *widget) |
| 1928 | { |
| 1929 | struct snd_soc_dapm_widget *w; |
| 1930 | |
| 1931 | if ((w = dapm_cnew_widget(widget)) == NULL) |
| 1932 | return -ENOMEM; |
| 1933 | |
| 1934 | w->codec = codec; |
| 1935 | INIT_LIST_HEAD(&w->sources); |
| 1936 | INIT_LIST_HEAD(&w->sinks); |
| 1937 | INIT_LIST_HEAD(&w->list); |
| 1938 | list_add(&w->list, &codec->dapm_widgets); |
| 1939 | |
| 1940 | /* machine layer set ups unconnected pins and insertions */ |
| 1941 | w->connected = 1; |
| 1942 | return 0; |
| 1943 | } |
| 1944 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control); |
| 1945 | |
| 1946 | /** |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 1947 | * snd_soc_dapm_new_controls - create new dapm controls |
| 1948 | * @codec: audio codec |
| 1949 | * @widget: widget array |
| 1950 | * @num: number of widgets |
| 1951 | * |
| 1952 | * Creates new DAPM controls based upon the templates. |
| 1953 | * |
| 1954 | * Returns 0 for success else error. |
| 1955 | */ |
| 1956 | int snd_soc_dapm_new_controls(struct snd_soc_codec *codec, |
| 1957 | const struct snd_soc_dapm_widget *widget, |
| 1958 | int num) |
| 1959 | { |
| 1960 | int i, ret; |
| 1961 | |
| 1962 | for (i = 0; i < num; i++) { |
| 1963 | ret = snd_soc_dapm_new_control(codec, widget); |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 1964 | if (ret < 0) { |
| 1965 | printk(KERN_ERR |
| 1966 | "ASoC: Failed to create DAPM control %s: %d\n", |
| 1967 | widget->name, ret); |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 1968 | return ret; |
Mark Brown | b8b33cb | 2008-12-18 11:19:30 +0000 | [diff] [blame] | 1969 | } |
Mark Brown | 4ba1327 | 2008-05-13 14:51:19 +0200 | [diff] [blame] | 1970 | widget++; |
| 1971 | } |
| 1972 | return 0; |
| 1973 | } |
| 1974 | EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls); |
| 1975 | |
| 1976 | |
| 1977 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1978 | * snd_soc_dapm_stream_event - send a stream event to the dapm core |
| 1979 | * @codec: audio codec |
| 1980 | * @stream: stream name |
| 1981 | * @event: stream event |
| 1982 | * |
| 1983 | * Sends a stream event to the dapm core. The core then makes any |
| 1984 | * necessary widget power changes. |
| 1985 | * |
| 1986 | * Returns 0 for success else error. |
| 1987 | */ |
| 1988 | int snd_soc_dapm_stream_event(struct snd_soc_codec *codec, |
| 1989 | char *stream, int event) |
| 1990 | { |
| 1991 | struct snd_soc_dapm_widget *w; |
| 1992 | |
Seth Forshee | 11da21a | 2007-02-02 17:14:19 +0100 | [diff] [blame] | 1993 | if (stream == NULL) |
| 1994 | return 0; |
| 1995 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 1996 | mutex_lock(&codec->mutex); |
| 1997 | list_for_each_entry(w, &codec->dapm_widgets, list) |
| 1998 | { |
| 1999 | if (!w->sname) |
| 2000 | continue; |
Mark Brown | c1286b8 | 2008-07-07 19:26:03 +0100 | [diff] [blame] | 2001 | pr_debug("widget %s\n %s stream %s event %d\n", |
| 2002 | w->name, w->sname, stream, event); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2003 | if (strstr(w->sname, stream)) { |
| 2004 | switch(event) { |
| 2005 | case SND_SOC_DAPM_STREAM_START: |
| 2006 | w->active = 1; |
| 2007 | break; |
| 2008 | case SND_SOC_DAPM_STREAM_STOP: |
| 2009 | w->active = 0; |
| 2010 | break; |
| 2011 | case SND_SOC_DAPM_STREAM_SUSPEND: |
| 2012 | if (w->active) |
| 2013 | w->suspend = 1; |
| 2014 | w->active = 0; |
| 2015 | break; |
| 2016 | case SND_SOC_DAPM_STREAM_RESUME: |
| 2017 | if (w->suspend) { |
| 2018 | w->active = 1; |
| 2019 | w->suspend = 0; |
| 2020 | } |
| 2021 | break; |
| 2022 | case SND_SOC_DAPM_STREAM_PAUSE_PUSH: |
| 2023 | break; |
| 2024 | case SND_SOC_DAPM_STREAM_PAUSE_RELEASE: |
| 2025 | break; |
| 2026 | } |
| 2027 | } |
| 2028 | } |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2029 | |
| 2030 | dapm_power_widgets(codec, event); |
Eero Nurkkala | 8e8b2d6 | 2009-10-12 08:41:59 +0300 | [diff] [blame] | 2031 | mutex_unlock(&codec->mutex); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2032 | return 0; |
| 2033 | } |
| 2034 | EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event); |
| 2035 | |
| 2036 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2037 | * snd_soc_dapm_enable_pin - enable pin. |
Mark Brown | ac11a2b | 2009-01-01 12:18:17 +0000 | [diff] [blame] | 2038 | * @codec: SoC codec |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2039 | * @pin: pin name |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2040 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 2041 | * 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] | 2042 | * a valid audio route and active audio stream. |
| 2043 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2044 | * do any widget power switching. |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2045 | */ |
Mark Brown | 1649923 | 2009-01-07 18:25:13 +0000 | [diff] [blame] | 2046 | int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, const char *pin) |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2047 | { |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2048 | return snd_soc_dapm_set_pin(codec, pin, 1); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2049 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2050 | EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2051 | |
| 2052 | /** |
Mark Brown | da34183 | 2010-03-15 19:23:37 +0000 | [diff] [blame] | 2053 | * snd_soc_dapm_force_enable_pin - force a pin to be enabled |
| 2054 | * @codec: SoC codec |
| 2055 | * @pin: pin name |
| 2056 | * |
| 2057 | * Enables input/output pin regardless of any other state. This is |
| 2058 | * intended for use with microphone bias supplies used in microphone |
| 2059 | * jack detection. |
| 2060 | * |
| 2061 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2062 | * do any widget power switching. |
| 2063 | */ |
| 2064 | int snd_soc_dapm_force_enable_pin(struct snd_soc_codec *codec, const char *pin) |
| 2065 | { |
| 2066 | struct snd_soc_dapm_widget *w; |
| 2067 | |
| 2068 | list_for_each_entry(w, &codec->dapm_widgets, list) { |
| 2069 | if (!strcmp(w->name, pin)) { |
| 2070 | pr_debug("dapm: %s: pin %s\n", codec->name, pin); |
| 2071 | w->connected = 1; |
| 2072 | w->force = 1; |
| 2073 | return 0; |
| 2074 | } |
| 2075 | } |
| 2076 | |
| 2077 | pr_err("dapm: %s: configuring unknown pin %s\n", codec->name, pin); |
| 2078 | return -EINVAL; |
| 2079 | } |
| 2080 | EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin); |
| 2081 | |
| 2082 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2083 | * snd_soc_dapm_disable_pin - disable pin. |
| 2084 | * @codec: SoC codec |
| 2085 | * @pin: pin name |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2086 | * |
Mark Brown | 74b8f95 | 2009-06-06 11:26:15 +0100 | [diff] [blame] | 2087 | * Disables input/output pin and its parents or children widgets. |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2088 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2089 | * do any widget power switching. |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2090 | */ |
Mark Brown | 1649923 | 2009-01-07 18:25:13 +0000 | [diff] [blame] | 2091 | int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, const char *pin) |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2092 | { |
| 2093 | return snd_soc_dapm_set_pin(codec, pin, 0); |
| 2094 | } |
| 2095 | EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin); |
| 2096 | |
| 2097 | /** |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2098 | * snd_soc_dapm_nc_pin - permanently disable pin. |
| 2099 | * @codec: SoC codec |
| 2100 | * @pin: pin name |
| 2101 | * |
| 2102 | * Marks the specified pin as being not connected, disabling it along |
| 2103 | * any parent or child widgets. At present this is identical to |
| 2104 | * snd_soc_dapm_disable_pin() but in future it will be extended to do |
| 2105 | * additional things such as disabling controls which only affect |
| 2106 | * paths through the pin. |
| 2107 | * |
| 2108 | * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to |
| 2109 | * do any widget power switching. |
| 2110 | */ |
Mark Brown | 1649923 | 2009-01-07 18:25:13 +0000 | [diff] [blame] | 2111 | int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, const char *pin) |
Mark Brown | 5817b52 | 2008-09-24 11:23:11 +0100 | [diff] [blame] | 2112 | { |
| 2113 | return snd_soc_dapm_set_pin(codec, pin, 0); |
| 2114 | } |
| 2115 | EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin); |
| 2116 | |
| 2117 | /** |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2118 | * snd_soc_dapm_get_pin_status - get audio pin status |
| 2119 | * @codec: audio codec |
| 2120 | * @pin: audio signal pin endpoint (or start point) |
| 2121 | * |
| 2122 | * Get audio pin status - connected or disconnected. |
| 2123 | * |
| 2124 | * Returns 1 for connected otherwise 0. |
| 2125 | */ |
Mark Brown | 1649923 | 2009-01-07 18:25:13 +0000 | [diff] [blame] | 2126 | int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin) |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2127 | { |
| 2128 | struct snd_soc_dapm_widget *w; |
| 2129 | |
| 2130 | list_for_each_entry(w, &codec->dapm_widgets, list) { |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2131 | if (!strcmp(w->name, pin)) |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2132 | return w->connected; |
| 2133 | } |
| 2134 | |
| 2135 | return 0; |
| 2136 | } |
Liam Girdwood | a530218 | 2008-07-07 13:35:17 +0100 | [diff] [blame] | 2137 | EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status); |
Graeme Gregory | eeec12b | 2008-04-30 19:27:40 +0200 | [diff] [blame] | 2138 | |
| 2139 | /** |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2140 | * snd_soc_dapm_free - free dapm resources |
| 2141 | * @socdev: SoC device |
| 2142 | * |
| 2143 | * Free all dapm widgets and resources. |
| 2144 | */ |
| 2145 | void snd_soc_dapm_free(struct snd_soc_device *socdev) |
| 2146 | { |
Mark Brown | 6627a65 | 2009-01-23 22:55:23 +0000 | [diff] [blame] | 2147 | struct snd_soc_codec *codec = socdev->card->codec; |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2148 | |
| 2149 | snd_soc_dapm_sys_remove(socdev->dev); |
| 2150 | dapm_free_widgets(codec); |
| 2151 | } |
| 2152 | EXPORT_SYMBOL_GPL(snd_soc_dapm_free); |
| 2153 | |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2154 | /* |
| 2155 | * snd_soc_dapm_shutdown - callback for system shutdown |
| 2156 | */ |
| 2157 | void snd_soc_dapm_shutdown(struct snd_soc_device *socdev) |
| 2158 | { |
| 2159 | struct snd_soc_codec *codec = socdev->card->codec; |
| 2160 | struct snd_soc_dapm_widget *w; |
| 2161 | LIST_HEAD(down_list); |
| 2162 | int powerdown = 0; |
| 2163 | |
| 2164 | list_for_each_entry(w, &codec->dapm_widgets, list) { |
| 2165 | if (w->power) { |
| 2166 | dapm_seq_insert(w, &down_list, dapm_down_seq); |
Mark Brown | c2caa4d | 2009-06-26 15:36:56 +0100 | [diff] [blame] | 2167 | w->power = 0; |
Mark Brown | 5173747 | 2009-06-22 13:16:51 +0100 | [diff] [blame] | 2168 | powerdown = 1; |
| 2169 | } |
| 2170 | } |
| 2171 | |
| 2172 | /* If there were no widgets to power down we're already in |
| 2173 | * standby. |
| 2174 | */ |
| 2175 | if (powerdown) { |
| 2176 | snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_PREPARE); |
| 2177 | dapm_seq_run(codec, &down_list, 0, dapm_down_seq); |
| 2178 | snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_STANDBY); |
| 2179 | } |
| 2180 | |
| 2181 | snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_OFF); |
| 2182 | } |
| 2183 | |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2184 | /* Module information */ |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 2185 | MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk"); |
Richard Purdie | 2b97eab | 2006-10-06 18:32:18 +0200 | [diff] [blame] | 2186 | MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC"); |
| 2187 | MODULE_LICENSE("GPL"); |