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