blob: 960790cc6fbc67a40d99f7ae811d38b50911f1d7 [file] [log] [blame]
Richard Purdie2b97eab2006-10-06 18:32:18 +02001/*
2 * soc-dapm.c -- ALSA SoC Dynamic Audio Power Management
3 *
4 * Copyright 2005 Wolfson Microelectronics PLC.
Liam Girdwoodd3311242008-10-12 13:17:36 +01005 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
Richard Purdie2b97eab2006-10-06 18:32:18 +02006 *
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 Purdie2b97eab2006-10-06 18:32:18 +020012 * Features:
13 * o Changes power status of internal codec blocks depending on the
14 * dynamic configuration of codec internal audio paths and active
Mark Brown74b8f952009-06-06 11:26:15 +010015 * DACs/ADCs.
Richard Purdie2b97eab2006-10-06 18:32:18 +020016 * 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. Day3a4fa0a2007-10-19 23:10:43 +020021 * o Delayed powerdown of audio susbsystem to reduce pops between a quick
Richard Purdie2b97eab2006-10-06 18:32:18 +020022 * 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 Iwai20496ff2009-08-24 09:40:34 +020040#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Richard Purdie2b97eab2006-10-06 18:32:18 +020042#include <sound/core.h>
43#include <sound/pcm.h>
44#include <sound/pcm_params.h>
Liam Girdwoodce6120c2010-11-05 15:53:46 +020045#include <sound/soc.h>
Richard Purdie2b97eab2006-10-06 18:32:18 +020046#include <sound/soc-dapm.h>
47#include <sound/initval.h>
48
Richard Purdie2b97eab2006-10-06 18:32:18 +020049/* dapm power sequences - make this per codec in the future */
50static int dapm_up_seq[] = {
Mark Brown38357ab2009-06-06 19:03:23 +010051 [snd_soc_dapm_pre] = 0,
52 [snd_soc_dapm_supply] = 1,
53 [snd_soc_dapm_micbias] = 2,
Mark Brown010ff262009-08-17 17:39:22 +010054 [snd_soc_dapm_aif_in] = 3,
55 [snd_soc_dapm_aif_out] = 3,
56 [snd_soc_dapm_mic] = 4,
57 [snd_soc_dapm_mux] = 5,
58 [snd_soc_dapm_value_mux] = 5,
59 [snd_soc_dapm_dac] = 6,
60 [snd_soc_dapm_mixer] = 7,
61 [snd_soc_dapm_mixer_named_ctl] = 7,
62 [snd_soc_dapm_pga] = 8,
63 [snd_soc_dapm_adc] = 9,
64 [snd_soc_dapm_hp] = 10,
65 [snd_soc_dapm_spk] = 10,
66 [snd_soc_dapm_post] = 11,
Richard Purdie2b97eab2006-10-06 18:32:18 +020067};
Ian Moltonca9c1aa2009-01-06 20:11:51 +000068
Richard Purdie2b97eab2006-10-06 18:32:18 +020069static int dapm_down_seq[] = {
Mark Brown38357ab2009-06-06 19:03:23 +010070 [snd_soc_dapm_pre] = 0,
71 [snd_soc_dapm_adc] = 1,
72 [snd_soc_dapm_hp] = 2,
Mark Brown1ca04062009-08-17 16:26:59 +010073 [snd_soc_dapm_spk] = 2,
Mark Brown38357ab2009-06-06 19:03:23 +010074 [snd_soc_dapm_pga] = 4,
75 [snd_soc_dapm_mixer_named_ctl] = 5,
Mark Browne3d4dab2009-06-07 13:08:45 +010076 [snd_soc_dapm_mixer] = 5,
77 [snd_soc_dapm_dac] = 6,
78 [snd_soc_dapm_mic] = 7,
79 [snd_soc_dapm_micbias] = 8,
80 [snd_soc_dapm_mux] = 9,
81 [snd_soc_dapm_value_mux] = 9,
Mark Brown010ff262009-08-17 17:39:22 +010082 [snd_soc_dapm_aif_in] = 10,
83 [snd_soc_dapm_aif_out] = 10,
84 [snd_soc_dapm_supply] = 11,
85 [snd_soc_dapm_post] = 12,
Richard Purdie2b97eab2006-10-06 18:32:18 +020086};
87
Troy Kisky12ef1932008-10-13 17:42:14 -070088static void pop_wait(u32 pop_time)
Mark Brown15e4c72f2008-07-02 11:51:20 +010089{
90 if (pop_time)
91 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
92}
93
Troy Kisky12ef1932008-10-13 17:42:14 -070094static void pop_dbg(u32 pop_time, const char *fmt, ...)
Mark Brown15e4c72f2008-07-02 11:51:20 +010095{
96 va_list args;
97
98 va_start(args, fmt);
99
100 if (pop_time) {
101 vprintk(fmt, args);
Mark Brown15e4c72f2008-07-02 11:51:20 +0100102 }
103
104 va_end(args);
105}
106
Richard Purdie2b97eab2006-10-06 18:32:18 +0200107/* create a new dapm widget */
Takashi Iwai88cb4292007-02-05 14:56:20 +0100108static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
Richard Purdie2b97eab2006-10-06 18:32:18 +0200109 const struct snd_soc_dapm_widget *_widget)
110{
Takashi Iwai88cb4292007-02-05 14:56:20 +0100111 return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200112}
113
Mark Brown452c5ea2009-05-17 21:41:23 +0100114/**
115 * snd_soc_dapm_set_bias_level - set the bias level for the system
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000116 * @card: audio device
Mark Brown452c5ea2009-05-17 21:41:23 +0100117 * @level: level to configure
118 *
119 * Configure the bias (power) levels for the SoC audio device.
120 *
121 * Returns 0 for success else error.
122 */
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000123static int snd_soc_dapm_set_bias_level(struct snd_soc_card *card,
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200124 struct snd_soc_dapm_context *dapm,
125 enum snd_soc_bias_level level)
Mark Brown452c5ea2009-05-17 21:41:23 +0100126{
Mark Brown452c5ea2009-05-17 21:41:23 +0100127 int ret = 0;
128
Mark Brownf83fba82009-05-18 15:44:43 +0100129 switch (level) {
130 case SND_SOC_BIAS_ON:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200131 dev_dbg(dapm->dev, "Setting full bias\n");
Mark Brownf83fba82009-05-18 15:44:43 +0100132 break;
133 case SND_SOC_BIAS_PREPARE:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200134 dev_dbg(dapm->dev, "Setting bias prepare\n");
Mark Brownf83fba82009-05-18 15:44:43 +0100135 break;
136 case SND_SOC_BIAS_STANDBY:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200137 dev_dbg(dapm->dev, "Setting standby bias\n");
Mark Brownf83fba82009-05-18 15:44:43 +0100138 break;
139 case SND_SOC_BIAS_OFF:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200140 dev_dbg(dapm->dev, "Setting bias off\n");
Mark Brownf83fba82009-05-18 15:44:43 +0100141 break;
142 default:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200143 dev_err(dapm->dev, "Setting invalid bias %d\n", level);
Mark Brownf83fba82009-05-18 15:44:43 +0100144 return -EINVAL;
145 }
146
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000147 if (card && card->set_bias_level)
Mark Brown452c5ea2009-05-17 21:41:23 +0100148 ret = card->set_bias_level(card, level);
Mark Brown474e09c2009-08-19 14:18:53 +0100149 if (ret == 0) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200150 if (dapm->codec && dapm->codec->driver->set_bias_level)
151 ret = dapm->codec->driver->set_bias_level(dapm->codec, level);
Mark Brown474e09c2009-08-19 14:18:53 +0100152 else
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200153 dapm->bias_level = level;
Mark Brown474e09c2009-08-19 14:18:53 +0100154 }
Mark Brown452c5ea2009-05-17 21:41:23 +0100155
156 return ret;
157}
158
Richard Purdie2b97eab2006-10-06 18:32:18 +0200159/* set up initial codec paths */
160static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
161 struct snd_soc_dapm_path *p, int i)
162{
163 switch (w->id) {
164 case snd_soc_dapm_switch:
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000165 case snd_soc_dapm_mixer:
166 case snd_soc_dapm_mixer_named_ctl: {
Richard Purdie2b97eab2006-10-06 18:32:18 +0200167 int val;
Jon Smirl4eaa9812008-07-29 11:42:26 +0100168 struct soc_mixer_control *mc = (struct soc_mixer_control *)
169 w->kcontrols[i].private_value;
Jon Smirl815ecf8d2008-07-29 10:22:24 -0400170 unsigned int reg = mc->reg;
171 unsigned int shift = mc->shift;
Jon Smirl4eaa9812008-07-29 11:42:26 +0100172 int max = mc->max;
Jon Smirl815ecf8d2008-07-29 10:22:24 -0400173 unsigned int mask = (1 << fls(max)) - 1;
174 unsigned int invert = mc->invert;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200175
176 val = snd_soc_read(w->codec, reg);
177 val = (val >> shift) & mask;
178
179 if ((invert && !val) || (!invert && val))
180 p->connect = 1;
181 else
182 p->connect = 0;
183 }
184 break;
185 case snd_soc_dapm_mux: {
186 struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value;
187 int val, item, bitmask;
188
Jon Smirlf8ba0b72008-07-29 11:42:27 +0100189 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200190 ;
191 val = snd_soc_read(w->codec, e->reg);
192 item = (val >> e->shift_l) & (bitmask - 1);
193
194 p->connect = 0;
Jon Smirlf8ba0b72008-07-29 11:42:27 +0100195 for (i = 0; i < e->max; i++) {
Richard Purdie2b97eab2006-10-06 18:32:18 +0200196 if (!(strcmp(p->name, e->texts[i])) && item == i)
197 p->connect = 1;
198 }
199 }
200 break;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +0200201 case snd_soc_dapm_value_mux: {
Peter Ujfalusi74155552009-01-08 13:34:29 +0200202 struct soc_enum *e = (struct soc_enum *)
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +0200203 w->kcontrols[i].private_value;
204 int val, item;
205
206 val = snd_soc_read(w->codec, e->reg);
207 val = (val >> e->shift_l) & e->mask;
208 for (item = 0; item < e->max; item++) {
209 if (val == e->values[item])
210 break;
211 }
212
213 p->connect = 0;
214 for (i = 0; i < e->max; i++) {
215 if (!(strcmp(p->name, e->texts[i])) && item == i)
216 p->connect = 1;
217 }
218 }
219 break;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200220 /* does not effect routing - always connected */
221 case snd_soc_dapm_pga:
222 case snd_soc_dapm_output:
223 case snd_soc_dapm_adc:
224 case snd_soc_dapm_input:
225 case snd_soc_dapm_dac:
226 case snd_soc_dapm_micbias:
227 case snd_soc_dapm_vmid:
Mark Brown246d0a12009-04-22 18:24:55 +0100228 case snd_soc_dapm_supply:
Mark Brown010ff262009-08-17 17:39:22 +0100229 case snd_soc_dapm_aif_in:
230 case snd_soc_dapm_aif_out:
Richard Purdie2b97eab2006-10-06 18:32:18 +0200231 p->connect = 1;
232 break;
233 /* does effect routing - dynamically connected */
234 case snd_soc_dapm_hp:
235 case snd_soc_dapm_mic:
236 case snd_soc_dapm_spk:
237 case snd_soc_dapm_line:
238 case snd_soc_dapm_pre:
239 case snd_soc_dapm_post:
240 p->connect = 0;
241 break;
242 }
243}
244
Mark Brown74b8f952009-06-06 11:26:15 +0100245/* connect mux widget to its interconnecting audio paths */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200246static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
Richard Purdie2b97eab2006-10-06 18:32:18 +0200247 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
248 struct snd_soc_dapm_path *path, const char *control_name,
249 const struct snd_kcontrol_new *kcontrol)
250{
251 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
252 int i;
253
Jon Smirlf8ba0b72008-07-29 11:42:27 +0100254 for (i = 0; i < e->max; i++) {
Richard Purdie2b97eab2006-10-06 18:32:18 +0200255 if (!(strcmp(control_name, e->texts[i]))) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200256 list_add(&path->list, &dapm->paths);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200257 list_add(&path->list_sink, &dest->sources);
258 list_add(&path->list_source, &src->sinks);
259 path->name = (char*)e->texts[i];
260 dapm_set_path_status(dest, path, 0);
261 return 0;
262 }
263 }
264
265 return -ENODEV;
266}
267
Mark Brown74b8f952009-06-06 11:26:15 +0100268/* connect mixer widget to its interconnecting audio paths */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200269static int dapm_connect_mixer(struct snd_soc_dapm_context *dapm,
Richard Purdie2b97eab2006-10-06 18:32:18 +0200270 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
271 struct snd_soc_dapm_path *path, const char *control_name)
272{
273 int i;
274
275 /* search for mixer kcontrol */
276 for (i = 0; i < dest->num_kcontrols; i++) {
277 if (!strcmp(control_name, dest->kcontrols[i].name)) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200278 list_add(&path->list, &dapm->paths);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200279 list_add(&path->list_sink, &dest->sources);
280 list_add(&path->list_source, &src->sinks);
281 path->name = dest->kcontrols[i].name;
282 dapm_set_path_status(dest, path, i);
283 return 0;
284 }
285 }
286 return -ENODEV;
287}
288
289/* update dapm codec register bits */
290static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
291{
292 int change, power;
Daniel Ribeiro46f58222009-06-07 02:49:11 -0300293 unsigned int old, new;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200294 struct snd_soc_codec *codec = widget->codec;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200295 struct snd_soc_dapm_context *dapm = widget->dapm;
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200296 struct snd_soc_card *card = dapm->card;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200297
298 /* check for valid widgets */
299 if (widget->reg < 0 || widget->id == snd_soc_dapm_input ||
300 widget->id == snd_soc_dapm_output ||
301 widget->id == snd_soc_dapm_hp ||
302 widget->id == snd_soc_dapm_mic ||
303 widget->id == snd_soc_dapm_line ||
304 widget->id == snd_soc_dapm_spk)
305 return 0;
306
307 power = widget->power;
308 if (widget->invert)
309 power = (power ? 0:1);
310
311 old = snd_soc_read(codec, widget->reg);
312 new = (old & ~(0x1 << widget->shift)) | (power << widget->shift);
313
314 change = old != new;
315 if (change) {
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200316 pop_dbg(card->pop_time, "pop test %s : %s in %d ms\n",
Troy Kisky12ef1932008-10-13 17:42:14 -0700317 widget->name, widget->power ? "on" : "off",
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200318 card->pop_time);
319 pop_wait(card->pop_time);
Mark Brown69224712010-03-03 14:57:09 +0000320 snd_soc_write(codec, widget->reg, new);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200321 }
Mark Brownc1286b82008-07-07 19:26:03 +0100322 pr_debug("reg %x old %x new %x change %d\n", widget->reg,
323 old, new, change);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200324 return change;
325}
326
Richard Purdie2b97eab2006-10-06 18:32:18 +0200327/* create new dapm mixer control */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200328static int dapm_new_mixer(struct snd_soc_dapm_context *dapm,
Richard Purdie2b97eab2006-10-06 18:32:18 +0200329 struct snd_soc_dapm_widget *w)
330{
331 int i, ret = 0;
Mark Brown219b93f2008-10-28 13:02:31 +0000332 size_t name_len;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200333 struct snd_soc_dapm_path *path;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200334 struct snd_card *card = dapm->codec->card->snd_card;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200335
336 /* add kcontrol */
337 for (i = 0; i < w->num_kcontrols; i++) {
338
339 /* match name */
340 list_for_each_entry(path, &w->sources, list_sink) {
341
342 /* mixer/mux paths name must match control name */
343 if (path->name != (char*)w->kcontrols[i].name)
344 continue;
345
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000346 /* add dapm control with long name.
347 * for dapm_mixer this is the concatenation of the
348 * mixer and kcontrol name.
349 * for dapm_mixer_named_ctl this is simply the
350 * kcontrol name.
351 */
352 name_len = strlen(w->kcontrols[i].name) + 1;
Mark Brown07495f32009-03-05 17:06:23 +0000353 if (w->id != snd_soc_dapm_mixer_named_ctl)
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000354 name_len += 1 + strlen(w->name);
355
Mark Brown219b93f2008-10-28 13:02:31 +0000356 path->long_name = kmalloc(name_len, GFP_KERNEL);
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000357
Richard Purdie2b97eab2006-10-06 18:32:18 +0200358 if (path->long_name == NULL)
359 return -ENOMEM;
360
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000361 switch (w->id) {
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000362 default:
363 snprintf(path->long_name, name_len, "%s %s",
364 w->name, w->kcontrols[i].name);
Mark Brown07495f32009-03-05 17:06:23 +0000365 break;
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000366 case snd_soc_dapm_mixer_named_ctl:
367 snprintf(path->long_name, name_len, "%s",
368 w->kcontrols[i].name);
Mark Brown07495f32009-03-05 17:06:23 +0000369 break;
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000370 }
371
Mark Brown219b93f2008-10-28 13:02:31 +0000372 path->long_name[name_len - 1] = '\0';
373
Richard Purdie2b97eab2006-10-06 18:32:18 +0200374 path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
375 path->long_name);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200376 ret = snd_ctl_add(card, path->kcontrol);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200377 if (ret < 0) {
Mark Brown6553e192009-04-06 16:59:32 +0100378 printk(KERN_ERR "asoc: failed to add dapm kcontrol %s: %d\n",
379 path->long_name,
380 ret);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200381 kfree(path->long_name);
382 path->long_name = NULL;
383 return ret;
384 }
385 }
386 }
387 return ret;
388}
389
390/* create new dapm mux control */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200391static int dapm_new_mux(struct snd_soc_dapm_context *dapm,
Richard Purdie2b97eab2006-10-06 18:32:18 +0200392 struct snd_soc_dapm_widget *w)
393{
394 struct snd_soc_dapm_path *path = NULL;
395 struct snd_kcontrol *kcontrol;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200396 struct snd_card *card = dapm->codec->card->snd_card;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200397 int ret = 0;
398
399 if (!w->num_kcontrols) {
400 printk(KERN_ERR "asoc: mux %s has no controls\n", w->name);
401 return -EINVAL;
402 }
403
404 kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200405 ret = snd_ctl_add(card, kcontrol);
406
Richard Purdie2b97eab2006-10-06 18:32:18 +0200407 if (ret < 0)
408 goto err;
409
410 list_for_each_entry(path, &w->sources, list_sink)
411 path->kcontrol = kcontrol;
412
413 return ret;
414
415err:
416 printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name);
417 return ret;
418}
419
420/* create new dapm volume control */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200421static int dapm_new_pga(struct snd_soc_dapm_context *dapm,
Richard Purdie2b97eab2006-10-06 18:32:18 +0200422 struct snd_soc_dapm_widget *w)
423{
Mark Browna6c65732010-03-03 17:45:21 +0000424 if (w->num_kcontrols)
425 pr_err("asoc: PGA controls not supported: '%s'\n", w->name);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200426
Mark Browna6c65732010-03-03 17:45:21 +0000427 return 0;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200428}
429
430/* reset 'walked' bit for each dapm path */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200431static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200432{
433 struct snd_soc_dapm_path *p;
434
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200435 list_for_each_entry(p, &dapm->paths, list)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200436 p->walked = 0;
437}
438
Mark Brown9949788b2010-05-07 20:24:05 +0100439/* We implement power down on suspend by checking the power state of
440 * the ALSA card - when we are suspending the ALSA state for the card
441 * is set to D3.
442 */
443static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
444{
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200445 int level = snd_power_get_state(widget->dapm->codec->card->snd_card);
Mark Brown9949788b2010-05-07 20:24:05 +0100446
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000447 switch (level) {
Mark Brown9949788b2010-05-07 20:24:05 +0100448 case SNDRV_CTL_POWER_D3hot:
449 case SNDRV_CTL_POWER_D3cold:
Mark Brown1547aba2010-05-07 21:11:40 +0100450 if (widget->ignore_suspend)
451 pr_debug("%s ignoring suspend\n", widget->name);
452 return widget->ignore_suspend;
Mark Brown9949788b2010-05-07 20:24:05 +0100453 default:
454 return 1;
455 }
456}
457
Richard Purdie2b97eab2006-10-06 18:32:18 +0200458/*
459 * Recursively check for a completed path to an active or physically connected
460 * output widget. Returns number of complete paths.
461 */
462static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
463{
464 struct snd_soc_dapm_path *path;
465 int con = 0;
466
Mark Brown246d0a12009-04-22 18:24:55 +0100467 if (widget->id == snd_soc_dapm_supply)
468 return 0;
469
Mark Brown010ff262009-08-17 17:39:22 +0100470 switch (widget->id) {
471 case snd_soc_dapm_adc:
472 case snd_soc_dapm_aif_out:
473 if (widget->active)
Mark Brown9949788b2010-05-07 20:24:05 +0100474 return snd_soc_dapm_suspend_check(widget);
Mark Brown010ff262009-08-17 17:39:22 +0100475 default:
476 break;
477 }
Richard Purdie2b97eab2006-10-06 18:32:18 +0200478
479 if (widget->connected) {
480 /* connected pin ? */
481 if (widget->id == snd_soc_dapm_output && !widget->ext)
Mark Brown9949788b2010-05-07 20:24:05 +0100482 return snd_soc_dapm_suspend_check(widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200483
484 /* connected jack or spk ? */
485 if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
Peter Ujfalusieaeae5d2009-09-30 09:27:24 +0300486 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources)))
Mark Brown9949788b2010-05-07 20:24:05 +0100487 return snd_soc_dapm_suspend_check(widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200488 }
489
490 list_for_each_entry(path, &widget->sinks, list_source) {
491 if (path->walked)
492 continue;
493
494 if (path->sink && path->connect) {
495 path->walked = 1;
496 con += is_connected_output_ep(path->sink);
497 }
498 }
499
500 return con;
501}
502
503/*
504 * Recursively check for a completed path to an active or physically connected
505 * input widget. Returns number of complete paths.
506 */
507static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
508{
509 struct snd_soc_dapm_path *path;
510 int con = 0;
511
Mark Brown246d0a12009-04-22 18:24:55 +0100512 if (widget->id == snd_soc_dapm_supply)
513 return 0;
514
Richard Purdie2b97eab2006-10-06 18:32:18 +0200515 /* active stream ? */
Mark Brown010ff262009-08-17 17:39:22 +0100516 switch (widget->id) {
517 case snd_soc_dapm_dac:
518 case snd_soc_dapm_aif_in:
519 if (widget->active)
Mark Brown9949788b2010-05-07 20:24:05 +0100520 return snd_soc_dapm_suspend_check(widget);
Mark Brown010ff262009-08-17 17:39:22 +0100521 default:
522 break;
523 }
Richard Purdie2b97eab2006-10-06 18:32:18 +0200524
525 if (widget->connected) {
526 /* connected pin ? */
527 if (widget->id == snd_soc_dapm_input && !widget->ext)
Mark Brown9949788b2010-05-07 20:24:05 +0100528 return snd_soc_dapm_suspend_check(widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200529
530 /* connected VMID/Bias for lower pops */
531 if (widget->id == snd_soc_dapm_vmid)
Mark Brown9949788b2010-05-07 20:24:05 +0100532 return snd_soc_dapm_suspend_check(widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200533
534 /* connected jack ? */
Peter Ujfalusieaeae5d2009-09-30 09:27:24 +0300535 if (widget->id == snd_soc_dapm_mic ||
536 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks)))
Mark Brown9949788b2010-05-07 20:24:05 +0100537 return snd_soc_dapm_suspend_check(widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200538 }
539
540 list_for_each_entry(path, &widget->sources, list_sink) {
541 if (path->walked)
542 continue;
543
544 if (path->source && path->connect) {
545 path->walked = 1;
546 con += is_connected_input_ep(path->source);
547 }
548 }
549
550 return con;
551}
552
553/*
Jarkko Nikulae2be2cc2008-06-25 14:42:07 +0300554 * Handler for generic register modifier widget.
555 */
556int dapm_reg_event(struct snd_soc_dapm_widget *w,
557 struct snd_kcontrol *kcontrol, int event)
558{
559 unsigned int val;
560
561 if (SND_SOC_DAPM_EVENT_ON(event))
562 val = w->on_val;
563 else
564 val = w->off_val;
565
566 snd_soc_update_bits(w->codec, -(w->reg + 1),
567 w->mask << w->shift, val << w->shift);
568
569 return 0;
570}
Mark Brown11589412008-07-29 11:42:23 +0100571EXPORT_SYMBOL_GPL(dapm_reg_event);
Jarkko Nikulae2be2cc2008-06-25 14:42:07 +0300572
Mark Brown025756ec2009-04-13 11:09:18 +0100573/* Standard power change method, used to apply power changes to most
574 * widgets.
575 */
576static int dapm_generic_apply_power(struct snd_soc_dapm_widget *w)
577{
578 int ret;
579
580 /* call any power change event handlers */
581 if (w->event)
582 pr_debug("power %s event for %s flags %x\n",
583 w->power ? "on" : "off",
584 w->name, w->event_flags);
585
586 /* power up pre event */
587 if (w->power && w->event &&
588 (w->event_flags & SND_SOC_DAPM_PRE_PMU)) {
589 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
590 if (ret < 0)
591 return ret;
592 }
593
594 /* power down pre event */
595 if (!w->power && w->event &&
596 (w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
597 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
598 if (ret < 0)
599 return ret;
600 }
601
Mark Brown025756ec2009-04-13 11:09:18 +0100602 dapm_update_bits(w);
603
Mark Brown025756ec2009-04-13 11:09:18 +0100604 /* power up post event */
605 if (w->power && w->event &&
606 (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
607 ret = w->event(w,
608 NULL, SND_SOC_DAPM_POST_PMU);
609 if (ret < 0)
610 return ret;
611 }
612
613 /* power down post event */
614 if (!w->power && w->event &&
615 (w->event_flags & SND_SOC_DAPM_POST_PMD)) {
616 ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
617 if (ret < 0)
618 return ret;
619 }
620
621 return 0;
622}
623
Mark Browncd0f2d42009-04-20 16:56:59 +0100624/* Generic check to see if a widget should be powered.
625 */
626static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
627{
628 int in, out;
629
630 in = is_connected_input_ep(w);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200631 dapm_clear_walk(w->dapm);
Mark Browncd0f2d42009-04-20 16:56:59 +0100632 out = is_connected_output_ep(w);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200633 dapm_clear_walk(w->dapm);
Mark Browncd0f2d42009-04-20 16:56:59 +0100634 return out != 0 && in != 0;
635}
636
Mark Brown6ea31b92009-04-20 17:15:41 +0100637/* Check to see if an ADC has power */
638static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
639{
640 int in;
641
642 if (w->active) {
643 in = is_connected_input_ep(w);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200644 dapm_clear_walk(w->dapm);
Mark Brown6ea31b92009-04-20 17:15:41 +0100645 return in != 0;
646 } else {
647 return dapm_generic_check_power(w);
648 }
649}
650
651/* Check to see if a DAC has power */
652static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
653{
654 int out;
655
656 if (w->active) {
657 out = is_connected_output_ep(w);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200658 dapm_clear_walk(w->dapm);
Mark Brown6ea31b92009-04-20 17:15:41 +0100659 return out != 0;
660 } else {
661 return dapm_generic_check_power(w);
662 }
663}
664
Mark Brown246d0a12009-04-22 18:24:55 +0100665/* Check to see if a power supply is needed */
666static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
667{
668 struct snd_soc_dapm_path *path;
669 int power = 0;
670
671 /* Check if one of our outputs is connected */
672 list_for_each_entry(path, &w->sinks, list_source) {
Mark Brown215edda2009-09-08 18:59:05 +0100673 if (path->connected &&
674 !path->connected(path->source, path->sink))
675 continue;
676
Mark Brown246d0a12009-04-22 18:24:55 +0100677 if (path->sink && path->sink->power_check &&
678 path->sink->power_check(path->sink)) {
679 power = 1;
680 break;
681 }
682 }
683
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200684 dapm_clear_walk(w->dapm);
Mark Brown246d0a12009-04-22 18:24:55 +0100685
686 return power;
687}
688
Mark Brown38357ab2009-06-06 19:03:23 +0100689static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
690 struct snd_soc_dapm_widget *b,
691 int sort[])
Mark Brown42aa3412009-03-01 19:21:10 +0000692{
Mark Brownd207c682009-12-07 17:13:55 +0000693 if (a->codec != b->codec)
694 return (unsigned long)a - (unsigned long)b;
Mark Brown38357ab2009-06-06 19:03:23 +0100695 if (sort[a->id] != sort[b->id])
696 return sort[a->id] - sort[b->id];
Mark Brownb22ead22009-06-07 12:51:26 +0100697 if (a->reg != b->reg)
698 return a->reg - b->reg;
Mark Brown42aa3412009-03-01 19:21:10 +0000699
Mark Brown38357ab2009-06-06 19:03:23 +0100700 return 0;
701}
Mark Brown42aa3412009-03-01 19:21:10 +0000702
Mark Brown38357ab2009-06-06 19:03:23 +0100703/* Insert a widget in order into a DAPM power sequence. */
704static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
705 struct list_head *list,
706 int sort[])
707{
708 struct snd_soc_dapm_widget *w;
709
710 list_for_each_entry(w, list, power_list)
711 if (dapm_seq_compare(new_widget, w, sort) < 0) {
712 list_add_tail(&new_widget->power_list, &w->power_list);
713 return;
Mark Brown42aa3412009-03-01 19:21:10 +0000714 }
Mark Brown6ea31b92009-04-20 17:15:41 +0100715
Mark Brown38357ab2009-06-06 19:03:23 +0100716 list_add_tail(&new_widget->power_list, list);
717}
Mark Brown42aa3412009-03-01 19:21:10 +0000718
Mark Brownb22ead22009-06-07 12:51:26 +0100719/* Apply the coalesced changes from a DAPM sequence */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200720static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
Mark Brownb22ead22009-06-07 12:51:26 +0100721 struct list_head *pending)
Mark Brown163cac02009-06-07 10:12:52 +0100722{
723 struct snd_soc_dapm_widget *w;
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200724 struct snd_soc_card *card = dapm->card;
Mark Brown81628102009-06-07 13:21:24 +0100725 int reg, power, ret;
Mark Brownb22ead22009-06-07 12:51:26 +0100726 unsigned int value = 0;
727 unsigned int mask = 0;
728 unsigned int cur_mask;
729
730 reg = list_first_entry(pending, struct snd_soc_dapm_widget,
731 power_list)->reg;
732
733 list_for_each_entry(w, pending, power_list) {
734 cur_mask = 1 << w->shift;
735 BUG_ON(reg != w->reg);
736
737 if (w->invert)
738 power = !w->power;
739 else
740 power = w->power;
741
742 mask |= cur_mask;
743 if (power)
744 value |= cur_mask;
745
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200746 pop_dbg(card->pop_time,
Mark Brownb22ead22009-06-07 12:51:26 +0100747 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
748 w->name, reg, value, mask);
Mark Brown81628102009-06-07 13:21:24 +0100749
750 /* power up pre event */
751 if (w->power && w->event &&
752 (w->event_flags & SND_SOC_DAPM_PRE_PMU)) {
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200753 pop_dbg(card->pop_time, "pop test : %s PRE_PMU\n",
Mark Brown81628102009-06-07 13:21:24 +0100754 w->name);
755 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
756 if (ret < 0)
757 pr_err("%s: pre event failed: %d\n",
758 w->name, ret);
759 }
760
761 /* power down pre event */
762 if (!w->power && w->event &&
763 (w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200764 pop_dbg(card->pop_time, "pop test : %s PRE_PMD\n",
Mark Brown81628102009-06-07 13:21:24 +0100765 w->name);
766 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
767 if (ret < 0)
768 pr_err("%s: pre event failed: %d\n",
769 w->name, ret);
770 }
Mark Brownb22ead22009-06-07 12:51:26 +0100771 }
772
Mark Brown81628102009-06-07 13:21:24 +0100773 if (reg >= 0) {
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200774 pop_dbg(card->pop_time,
Mark Brown81628102009-06-07 13:21:24 +0100775 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200776 value, mask, reg, card->pop_time);
777 pop_wait(card->pop_time);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200778 snd_soc_update_bits(dapm->codec, reg, mask, value);
Mark Brown81628102009-06-07 13:21:24 +0100779 }
780
781 list_for_each_entry(w, pending, power_list) {
782 /* power up post event */
783 if (w->power && w->event &&
784 (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200785 pop_dbg(card->pop_time, "pop test : %s POST_PMU\n",
Mark Brown81628102009-06-07 13:21:24 +0100786 w->name);
Mark Brown42aa3412009-03-01 19:21:10 +0000787 ret = w->event(w,
788 NULL, SND_SOC_DAPM_POST_PMU);
789 if (ret < 0)
Mark Brown81628102009-06-07 13:21:24 +0100790 pr_err("%s: post event failed: %d\n",
791 w->name, ret);
Mark Brown42aa3412009-03-01 19:21:10 +0000792 }
Mark Brown6ea31b92009-04-20 17:15:41 +0100793
Mark Brown81628102009-06-07 13:21:24 +0100794 /* power down post event */
795 if (!w->power && w->event &&
796 (w->event_flags & SND_SOC_DAPM_POST_PMD)) {
Jarkko Nikula3a45b862010-11-05 20:35:21 +0200797 pop_dbg(card->pop_time, "pop test : %s POST_PMD\n",
Mark Brown81628102009-06-07 13:21:24 +0100798 w->name);
799 ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
800 if (ret < 0)
801 pr_err("%s: post event failed: %d\n",
802 w->name, ret);
803 }
Mark Brown42aa3412009-03-01 19:21:10 +0000804 }
Mark Brown42aa3412009-03-01 19:21:10 +0000805}
806
Mark Brownb22ead22009-06-07 12:51:26 +0100807/* Apply a DAPM power sequence.
808 *
809 * We walk over a pre-sorted list of widgets to apply power to. In
810 * order to minimise the number of writes to the device required
811 * multiple widgets will be updated in a single write where possible.
812 * Currently anything that requires more than a single write is not
813 * handled.
814 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200815static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
816 struct list_head *list, int event, int sort[])
Mark Brownb22ead22009-06-07 12:51:26 +0100817{
818 struct snd_soc_dapm_widget *w, *n;
819 LIST_HEAD(pending);
820 int cur_sort = -1;
821 int cur_reg = SND_SOC_NOPM;
Mark Brown163cac02009-06-07 10:12:52 +0100822 int ret;
823
Mark Brownb22ead22009-06-07 12:51:26 +0100824 list_for_each_entry_safe(w, n, list, power_list) {
825 ret = 0;
826
827 /* Do we need to apply any queued changes? */
828 if (sort[w->id] != cur_sort || w->reg != cur_reg) {
829 if (!list_empty(&pending))
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200830 dapm_seq_run_coalesced(dapm, &pending);
Mark Brownb22ead22009-06-07 12:51:26 +0100831
832 INIT_LIST_HEAD(&pending);
833 cur_sort = -1;
834 cur_reg = SND_SOC_NOPM;
835 }
836
Mark Brown163cac02009-06-07 10:12:52 +0100837 switch (w->id) {
838 case snd_soc_dapm_pre:
839 if (!w->event)
Mark Brownb22ead22009-06-07 12:51:26 +0100840 list_for_each_entry_safe_continue(w, n, list,
841 power_list);
Mark Brown163cac02009-06-07 10:12:52 +0100842
Mark Brownb22ead22009-06-07 12:51:26 +0100843 if (event == SND_SOC_DAPM_STREAM_START)
Mark Brown163cac02009-06-07 10:12:52 +0100844 ret = w->event(w,
845 NULL, SND_SOC_DAPM_PRE_PMU);
Mark Brownb22ead22009-06-07 12:51:26 +0100846 else if (event == SND_SOC_DAPM_STREAM_STOP)
Mark Brown163cac02009-06-07 10:12:52 +0100847 ret = w->event(w,
848 NULL, SND_SOC_DAPM_PRE_PMD);
Mark Brown163cac02009-06-07 10:12:52 +0100849 break;
850
851 case snd_soc_dapm_post:
852 if (!w->event)
Mark Brownb22ead22009-06-07 12:51:26 +0100853 list_for_each_entry_safe_continue(w, n, list,
854 power_list);
Mark Brown163cac02009-06-07 10:12:52 +0100855
Mark Brownb22ead22009-06-07 12:51:26 +0100856 if (event == SND_SOC_DAPM_STREAM_START)
Mark Brown163cac02009-06-07 10:12:52 +0100857 ret = w->event(w,
858 NULL, SND_SOC_DAPM_POST_PMU);
Mark Brownb22ead22009-06-07 12:51:26 +0100859 else if (event == SND_SOC_DAPM_STREAM_STOP)
Mark Brown163cac02009-06-07 10:12:52 +0100860 ret = w->event(w,
861 NULL, SND_SOC_DAPM_POST_PMD);
Mark Brownb22ead22009-06-07 12:51:26 +0100862 break;
863
864 case snd_soc_dapm_input:
865 case snd_soc_dapm_output:
866 case snd_soc_dapm_hp:
867 case snd_soc_dapm_mic:
868 case snd_soc_dapm_line:
869 case snd_soc_dapm_spk:
870 /* No register support currently */
Mark Brownb22ead22009-06-07 12:51:26 +0100871 ret = dapm_generic_apply_power(w);
Mark Brown163cac02009-06-07 10:12:52 +0100872 break;
873
874 default:
Mark Brown81628102009-06-07 13:21:24 +0100875 /* Queue it up for application */
876 cur_sort = sort[w->id];
877 cur_reg = w->reg;
878 list_move(&w->power_list, &pending);
879 break;
Mark Brown163cac02009-06-07 10:12:52 +0100880 }
Mark Brownb22ead22009-06-07 12:51:26 +0100881
882 if (ret < 0)
883 pr_err("Failed to apply widget power: %d\n",
884 ret);
Mark Brown163cac02009-06-07 10:12:52 +0100885 }
Mark Brownb22ead22009-06-07 12:51:26 +0100886
887 if (!list_empty(&pending))
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200888 dapm_seq_run_coalesced(dapm, &pending);
Mark Brown163cac02009-06-07 10:12:52 +0100889}
890
Mark Brown42aa3412009-03-01 19:21:10 +0000891/*
Richard Purdie2b97eab2006-10-06 18:32:18 +0200892 * Scan each dapm widget for complete audio path.
893 * A complete path is a route that has valid endpoints i.e.:-
894 *
895 * o DAC to output pin.
896 * o Input Pin to ADC.
897 * o Input pin to Output pin (bypass, sidetone)
898 * o DAC to ADC (loopback).
899 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200900static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200901{
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200902 struct snd_soc_card *card = dapm->codec->card;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200903 struct snd_soc_dapm_widget *w;
Mark Brown291f3bb2009-06-07 13:57:17 +0100904 LIST_HEAD(up_list);
905 LIST_HEAD(down_list);
Mark Brown6d3ddc82009-05-16 17:47:29 +0100906 int ret = 0;
Mark Brown38357ab2009-06-06 19:03:23 +0100907 int power;
Mark Brown452c5ea2009-05-17 21:41:23 +0100908 int sys_power = 0;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200909
Mark Brown6d3ddc82009-05-16 17:47:29 +0100910 /* Check which widgets we need to power and store them in
911 * lists indicating if they should be powered up or down.
912 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200913 list_for_each_entry(w, &dapm->widgets, list) {
Mark Brown6d3ddc82009-05-16 17:47:29 +0100914 switch (w->id) {
915 case snd_soc_dapm_pre:
Mark Brown291f3bb2009-06-07 13:57:17 +0100916 dapm_seq_insert(w, &down_list, dapm_down_seq);
Mark Brown6d3ddc82009-05-16 17:47:29 +0100917 break;
918 case snd_soc_dapm_post:
Mark Brown291f3bb2009-06-07 13:57:17 +0100919 dapm_seq_insert(w, &up_list, dapm_up_seq);
Mark Brown6d3ddc82009-05-16 17:47:29 +0100920 break;
921
922 default:
923 if (!w->power_check)
924 continue;
925
Mark Brown9949788b2010-05-07 20:24:05 +0100926 if (!w->force)
Mark Brown50b6bce2009-11-23 13:11:53 +0000927 power = w->power_check(w);
Mark Brown9949788b2010-05-07 20:24:05 +0100928 else
929 power = 1;
930 if (power)
931 sys_power = 1;
Mark Brown452c5ea2009-05-17 21:41:23 +0100932
Mark Brown6d3ddc82009-05-16 17:47:29 +0100933 if (w->power == power)
934 continue;
935
936 if (power)
Mark Brown291f3bb2009-06-07 13:57:17 +0100937 dapm_seq_insert(w, &up_list, dapm_up_seq);
Mark Brown6d3ddc82009-05-16 17:47:29 +0100938 else
Mark Brown291f3bb2009-06-07 13:57:17 +0100939 dapm_seq_insert(w, &down_list, dapm_down_seq);
Mark Brown6d3ddc82009-05-16 17:47:29 +0100940
941 w->power = power;
942 break;
943 }
Richard Purdie2b97eab2006-10-06 18:32:18 +0200944 }
945
Mark Brownb14b76a52009-08-17 11:55:38 +0100946 /* If there are no DAPM widgets then try to figure out power from the
947 * event type.
948 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200949 if (list_empty(&dapm->widgets)) {
Mark Brownb14b76a52009-08-17 11:55:38 +0100950 switch (event) {
951 case SND_SOC_DAPM_STREAM_START:
952 case SND_SOC_DAPM_STREAM_RESUME:
953 sys_power = 1;
954 break;
Mark Brown50b6bce2009-11-23 13:11:53 +0000955 case SND_SOC_DAPM_STREAM_SUSPEND:
956 sys_power = 0;
957 break;
Mark Brownb14b76a52009-08-17 11:55:38 +0100958 case SND_SOC_DAPM_STREAM_NOP:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200959 switch (dapm->bias_level) {
Mark Browna96ca332010-01-19 22:49:43 +0000960 case SND_SOC_BIAS_STANDBY:
961 case SND_SOC_BIAS_OFF:
962 sys_power = 0;
963 break;
964 default:
965 sys_power = 1;
966 break;
967 }
Mark Brown50b6bce2009-11-23 13:11:53 +0000968 break;
Mark Brownb14b76a52009-08-17 11:55:38 +0100969 default:
970 break;
971 }
972 }
973
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200974 if (sys_power && dapm->bias_level == SND_SOC_BIAS_OFF) {
975 ret = snd_soc_dapm_set_bias_level(card, dapm,
Mark Browna96ca332010-01-19 22:49:43 +0000976 SND_SOC_BIAS_STANDBY);
977 if (ret != 0)
978 pr_err("Failed to turn on bias: %d\n", ret);
979 }
980
Mark Brown452c5ea2009-05-17 21:41:23 +0100981 /* If we're changing to all on or all off then prepare */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200982 if ((sys_power && dapm->bias_level == SND_SOC_BIAS_STANDBY) ||
983 (!sys_power && dapm->bias_level == SND_SOC_BIAS_ON)) {
984 ret = snd_soc_dapm_set_bias_level(card, dapm, SND_SOC_BIAS_PREPARE);
Mark Brown452c5ea2009-05-17 21:41:23 +0100985 if (ret != 0)
986 pr_err("Failed to prepare bias: %d\n", ret);
987 }
988
Mark Brown6d3ddc82009-05-16 17:47:29 +0100989 /* Power down widgets first; try to avoid amplifying pops. */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200990 dapm_seq_run(dapm, &down_list, event, dapm_down_seq);
Mark Brown6d3ddc82009-05-16 17:47:29 +0100991
992 /* Now power up. */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200993 dapm_seq_run(dapm, &up_list, event, dapm_up_seq);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200994
Mark Brown452c5ea2009-05-17 21:41:23 +0100995 /* If we just powered the last thing off drop to standby bias */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200996 if (dapm->bias_level == SND_SOC_BIAS_PREPARE && !sys_power) {
997 ret = snd_soc_dapm_set_bias_level(card, dapm, SND_SOC_BIAS_STANDBY);
Mark Brown452c5ea2009-05-17 21:41:23 +0100998 if (ret != 0)
999 pr_err("Failed to apply standby bias: %d\n", ret);
1000 }
1001
Mark Browna96ca332010-01-19 22:49:43 +00001002 /* If we're in standby and can support bias off then do that */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001003 if (dapm->bias_level == SND_SOC_BIAS_STANDBY &&
1004 dapm->idle_bias_off) {
1005 ret = snd_soc_dapm_set_bias_level(card, dapm, SND_SOC_BIAS_OFF);
Mark Browna96ca332010-01-19 22:49:43 +00001006 if (ret != 0)
1007 pr_err("Failed to turn off bias: %d\n", ret);
1008 }
1009
Mark Brown452c5ea2009-05-17 21:41:23 +01001010 /* If we just powered up then move to active bias */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001011 if (dapm->bias_level == SND_SOC_BIAS_PREPARE && sys_power) {
1012 ret = snd_soc_dapm_set_bias_level(card, dapm, SND_SOC_BIAS_ON);
Mark Brown452c5ea2009-05-17 21:41:23 +01001013 if (ret != 0)
1014 pr_err("Failed to apply active bias: %d\n", ret);
1015 }
1016
Jarkko Nikula3a45b862010-11-05 20:35:21 +02001017 pop_dbg(card->pop_time, "DAPM sequencing finished, waiting %dms\n",
1018 card->pop_time);
1019 pop_wait(card->pop_time);
Mark Browncb507e72009-07-08 18:54:57 +01001020
Mark Brown42aa3412009-03-01 19:21:10 +00001021 return 0;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001022}
1023
Mark Brown79fb9382009-08-21 16:38:13 +01001024#ifdef CONFIG_DEBUG_FS
1025static int dapm_widget_power_open_file(struct inode *inode, struct file *file)
1026{
1027 file->private_data = inode->i_private;
1028 return 0;
1029}
1030
1031static ssize_t dapm_widget_power_read_file(struct file *file,
1032 char __user *user_buf,
1033 size_t count, loff_t *ppos)
1034{
1035 struct snd_soc_dapm_widget *w = file->private_data;
1036 char *buf;
1037 int in, out;
1038 ssize_t ret;
1039 struct snd_soc_dapm_path *p = NULL;
1040
1041 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1042 if (!buf)
1043 return -ENOMEM;
1044
1045 in = is_connected_input_ep(w);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001046 dapm_clear_walk(w->dapm);
Mark Brown79fb9382009-08-21 16:38:13 +01001047 out = is_connected_output_ep(w);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001048 dapm_clear_walk(w->dapm);
Mark Brown79fb9382009-08-21 16:38:13 +01001049
Mark Brownd033c362009-12-04 15:25:56 +00001050 ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d",
Mark Brown79fb9382009-08-21 16:38:13 +01001051 w->name, w->power ? "On" : "Off", in, out);
1052
Mark Brownd033c362009-12-04 15:25:56 +00001053 if (w->reg >= 0)
1054 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1055 " - R%d(0x%x) bit %d",
1056 w->reg, w->reg, w->shift);
1057
1058 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
1059
Mark Brown3eef08b2009-09-14 16:49:00 +01001060 if (w->sname)
1061 ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
1062 w->sname,
1063 w->active ? "active" : "inactive");
Mark Brown79fb9382009-08-21 16:38:13 +01001064
1065 list_for_each_entry(p, &w->sources, list_sink) {
Mark Brown215edda2009-09-08 18:59:05 +01001066 if (p->connected && !p->connected(w, p->sink))
1067 continue;
1068
Mark Brown79fb9382009-08-21 16:38:13 +01001069 if (p->connect)
1070 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1071 " in %s %s\n",
1072 p->name ? p->name : "static",
1073 p->source->name);
1074 }
1075 list_for_each_entry(p, &w->sinks, list_source) {
Mark Brown215edda2009-09-08 18:59:05 +01001076 if (p->connected && !p->connected(w, p->sink))
1077 continue;
1078
Mark Brown79fb9382009-08-21 16:38:13 +01001079 if (p->connect)
1080 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1081 " out %s %s\n",
1082 p->name ? p->name : "static",
1083 p->sink->name);
1084 }
1085
1086 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1087
1088 kfree(buf);
1089 return ret;
1090}
1091
1092static const struct file_operations dapm_widget_power_fops = {
1093 .open = dapm_widget_power_open_file,
1094 .read = dapm_widget_power_read_file,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001095 .llseek = default_llseek,
Mark Brown79fb9382009-08-21 16:38:13 +01001096};
1097
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001098void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm)
Mark Brown79fb9382009-08-21 16:38:13 +01001099{
1100 struct snd_soc_dapm_widget *w;
1101 struct dentry *d;
1102
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001103 if (!dapm->debugfs_dapm)
Mark Brown79fb9382009-08-21 16:38:13 +01001104 return;
1105
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001106 list_for_each_entry(w, &dapm->widgets, list) {
Mark Brown79fb9382009-08-21 16:38:13 +01001107 if (!w->name)
1108 continue;
1109
1110 d = debugfs_create_file(w->name, 0444,
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001111 dapm->debugfs_dapm, w,
Mark Brown79fb9382009-08-21 16:38:13 +01001112 &dapm_widget_power_fops);
1113 if (!d)
1114 printk(KERN_WARNING
1115 "ASoC: Failed to create %s debugfs file\n",
1116 w->name);
1117 }
1118}
1119#else
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001120void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm)
Mark Brown79fb9382009-08-21 16:38:13 +01001121{
1122}
1123#endif
1124
Richard Purdie2b97eab2006-10-06 18:32:18 +02001125/* test and update the power status of a mux widget */
Adrian Bunkd9c96cf2006-11-28 12:10:09 +01001126static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
Mark Brown3a655772009-10-05 17:23:30 +01001127 struct snd_kcontrol *kcontrol, int change,
1128 int mux, struct soc_enum *e)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001129{
1130 struct snd_soc_dapm_path *path;
1131 int found = 0;
1132
Peter Ujfalusieff317d2009-01-15 14:40:47 +02001133 if (widget->id != snd_soc_dapm_mux &&
1134 widget->id != snd_soc_dapm_value_mux)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001135 return -ENODEV;
1136
Mark Brown3a655772009-10-05 17:23:30 +01001137 if (!change)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001138 return 0;
1139
1140 /* find dapm widget path assoc with kcontrol */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001141 list_for_each_entry(path, &widget->dapm->paths, list) {
Richard Purdie2b97eab2006-10-06 18:32:18 +02001142 if (path->kcontrol != kcontrol)
1143 continue;
1144
Richard Zhaocb01e2b2008-10-07 08:05:20 +08001145 if (!path->name || !e->texts[mux])
Richard Purdie2b97eab2006-10-06 18:32:18 +02001146 continue;
1147
1148 found = 1;
1149 /* we now need to match the string in the enum to the path */
Richard Zhaocb01e2b2008-10-07 08:05:20 +08001150 if (!(strcmp(path->name, e->texts[mux])))
Richard Purdie2b97eab2006-10-06 18:32:18 +02001151 path->connect = 1; /* new connection */
1152 else
1153 path->connect = 0; /* old connection must be powered down */
1154 }
1155
Mark Brownb91b8fa2010-01-20 18:18:35 +00001156 if (found)
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001157 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001158
1159 return 0;
1160}
Richard Purdie2b97eab2006-10-06 18:32:18 +02001161
Milan plzik1b075e32008-01-10 14:39:46 +01001162/* test and update the power status of a mixer or switch widget */
Adrian Bunkd9c96cf2006-11-28 12:10:09 +01001163static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
Mark Brown283375c2009-12-07 18:09:03 +00001164 struct snd_kcontrol *kcontrol, int connect)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001165{
1166 struct snd_soc_dapm_path *path;
1167 int found = 0;
1168
Milan plzik1b075e32008-01-10 14:39:46 +01001169 if (widget->id != snd_soc_dapm_mixer &&
Ian Moltonca9c1aa2009-01-06 20:11:51 +00001170 widget->id != snd_soc_dapm_mixer_named_ctl &&
Milan plzik1b075e32008-01-10 14:39:46 +01001171 widget->id != snd_soc_dapm_switch)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001172 return -ENODEV;
1173
Richard Purdie2b97eab2006-10-06 18:32:18 +02001174 /* find dapm widget path assoc with kcontrol */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001175 list_for_each_entry(path, &widget->dapm->paths, list) {
Richard Purdie2b97eab2006-10-06 18:32:18 +02001176 if (path->kcontrol != kcontrol)
1177 continue;
1178
1179 /* found, now check type */
1180 found = 1;
Mark Brown283375c2009-12-07 18:09:03 +00001181 path->connect = connect;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001182 break;
1183 }
1184
Mark Brownb91b8fa2010-01-20 18:18:35 +00001185 if (found)
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001186 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001187
1188 return 0;
1189}
Richard Purdie2b97eab2006-10-06 18:32:18 +02001190
1191/* show dapm widget status in sys fs */
1192static ssize_t dapm_widget_show(struct device *dev,
1193 struct device_attribute *attr, char *buf)
1194{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001195 struct snd_soc_pcm_runtime *rtd =
1196 container_of(dev, struct snd_soc_pcm_runtime, dev);
1197 struct snd_soc_codec *codec =rtd->codec;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001198 struct snd_soc_dapm_widget *w;
1199 int count = 0;
1200 char *state = "not set";
1201
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001202 list_for_each_entry(w, &codec->dapm.widgets, list) {
Richard Purdie2b97eab2006-10-06 18:32:18 +02001203
1204 /* only display widgets that burnm power */
1205 switch (w->id) {
1206 case snd_soc_dapm_hp:
1207 case snd_soc_dapm_mic:
1208 case snd_soc_dapm_spk:
1209 case snd_soc_dapm_line:
1210 case snd_soc_dapm_micbias:
1211 case snd_soc_dapm_dac:
1212 case snd_soc_dapm_adc:
1213 case snd_soc_dapm_pga:
1214 case snd_soc_dapm_mixer:
Ian Moltonca9c1aa2009-01-06 20:11:51 +00001215 case snd_soc_dapm_mixer_named_ctl:
Mark Brown246d0a12009-04-22 18:24:55 +01001216 case snd_soc_dapm_supply:
Richard Purdie2b97eab2006-10-06 18:32:18 +02001217 if (w->name)
1218 count += sprintf(buf + count, "%s: %s\n",
1219 w->name, w->power ? "On":"Off");
1220 break;
1221 default:
1222 break;
1223 }
1224 }
1225
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001226 switch (codec->dapm.bias_level) {
Mark Brown0be98982008-05-19 12:31:28 +02001227 case SND_SOC_BIAS_ON:
1228 state = "On";
Richard Purdie2b97eab2006-10-06 18:32:18 +02001229 break;
Mark Brown0be98982008-05-19 12:31:28 +02001230 case SND_SOC_BIAS_PREPARE:
1231 state = "Prepare";
Richard Purdie2b97eab2006-10-06 18:32:18 +02001232 break;
Mark Brown0be98982008-05-19 12:31:28 +02001233 case SND_SOC_BIAS_STANDBY:
1234 state = "Standby";
Richard Purdie2b97eab2006-10-06 18:32:18 +02001235 break;
Mark Brown0be98982008-05-19 12:31:28 +02001236 case SND_SOC_BIAS_OFF:
1237 state = "Off";
Richard Purdie2b97eab2006-10-06 18:32:18 +02001238 break;
1239 }
1240 count += sprintf(buf + count, "PM State: %s\n", state);
1241
1242 return count;
1243}
1244
1245static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
1246
1247int snd_soc_dapm_sys_add(struct device *dev)
1248{
Troy Kisky12ef1932008-10-13 17:42:14 -07001249 return device_create_file(dev, &dev_attr_dapm_widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001250}
1251
1252static void snd_soc_dapm_sys_remove(struct device *dev)
1253{
Mark Brownaef90842009-05-16 17:53:16 +01001254 device_remove_file(dev, &dev_attr_dapm_widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001255}
1256
1257/* free all dapm widgets and resources */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001258static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001259{
1260 struct snd_soc_dapm_widget *w, *next_w;
1261 struct snd_soc_dapm_path *p, *next_p;
1262
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001263 list_for_each_entry_safe(w, next_w, &dapm->widgets, list) {
Richard Purdie2b97eab2006-10-06 18:32:18 +02001264 list_del(&w->list);
1265 kfree(w);
1266 }
1267
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001268 list_for_each_entry_safe(p, next_p, &dapm->paths, list) {
Richard Purdie2b97eab2006-10-06 18:32:18 +02001269 list_del(&p->list);
1270 kfree(p->long_name);
1271 kfree(p);
1272 }
1273}
1274
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001275static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
Mark Brown16499232009-01-07 18:25:13 +00001276 const char *pin, int status)
Liam Girdwooda5302182008-07-07 13:35:17 +01001277{
1278 struct snd_soc_dapm_widget *w;
1279
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001280 list_for_each_entry(w, &dapm->widgets, list) {
Liam Girdwooda5302182008-07-07 13:35:17 +01001281 if (!strcmp(w->name, pin)) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001282 pr_debug("dapm: %s: pin %s\n", dapm->codec->name, pin);
Liam Girdwooda5302182008-07-07 13:35:17 +01001283 w->connected = status;
Mark Brown5b9e87c2010-03-22 13:36:13 +00001284 /* Allow disabling of forced pins */
1285 if (status == 0)
1286 w->force = 0;
Liam Girdwooda5302182008-07-07 13:35:17 +01001287 return 0;
1288 }
1289 }
1290
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001291 pr_err("dapm: %s: configuring unknown pin %s\n",
1292 dapm->codec->name, pin);
Liam Girdwooda5302182008-07-07 13:35:17 +01001293 return -EINVAL;
1294}
1295
Richard Purdie2b97eab2006-10-06 18:32:18 +02001296/**
Liam Girdwooda5302182008-07-07 13:35:17 +01001297 * snd_soc_dapm_sync - scan and power dapm paths
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001298 * @dapm: DAPM context
Richard Purdie2b97eab2006-10-06 18:32:18 +02001299 *
1300 * Walks all dapm audio paths and powers widgets according to their
1301 * stream or path usage.
1302 *
1303 * Returns 0 for success.
1304 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001305int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001306{
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001307 return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001308}
Liam Girdwooda5302182008-07-07 13:35:17 +01001309EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001310
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001311static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
Mark Brown215edda2009-09-08 18:59:05 +01001312 const struct snd_soc_dapm_route *route)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001313{
1314 struct snd_soc_dapm_path *path;
1315 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
Mark Brown215edda2009-09-08 18:59:05 +01001316 const char *sink = route->sink;
1317 const char *control = route->control;
1318 const char *source = route->source;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001319 int ret = 0;
1320
1321 /* find src and dest widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001322 list_for_each_entry(w, &dapm->widgets, list) {
Richard Purdie2b97eab2006-10-06 18:32:18 +02001323
1324 if (!wsink && !(strcmp(w->name, sink))) {
1325 wsink = w;
1326 continue;
1327 }
1328 if (!wsource && !(strcmp(w->name, source))) {
1329 wsource = w;
1330 }
1331 }
1332
1333 if (wsource == NULL || wsink == NULL)
1334 return -ENODEV;
1335
1336 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
1337 if (!path)
1338 return -ENOMEM;
1339
1340 path->source = wsource;
1341 path->sink = wsink;
Mark Brown215edda2009-09-08 18:59:05 +01001342 path->connected = route->connected;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001343 INIT_LIST_HEAD(&path->list);
1344 INIT_LIST_HEAD(&path->list_source);
1345 INIT_LIST_HEAD(&path->list_sink);
1346
1347 /* check for external widgets */
1348 if (wsink->id == snd_soc_dapm_input) {
1349 if (wsource->id == snd_soc_dapm_micbias ||
1350 wsource->id == snd_soc_dapm_mic ||
Rongrong Cao087d53a2009-07-10 20:13:30 +01001351 wsource->id == snd_soc_dapm_line ||
1352 wsource->id == snd_soc_dapm_output)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001353 wsink->ext = 1;
1354 }
1355 if (wsource->id == snd_soc_dapm_output) {
1356 if (wsink->id == snd_soc_dapm_spk ||
1357 wsink->id == snd_soc_dapm_hp ||
Seth Forshee1e392212007-04-16 15:36:42 +02001358 wsink->id == snd_soc_dapm_line ||
1359 wsink->id == snd_soc_dapm_input)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001360 wsource->ext = 1;
1361 }
1362
1363 /* connect static paths */
1364 if (control == NULL) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001365 list_add(&path->list, &dapm->paths);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001366 list_add(&path->list_sink, &wsink->sources);
1367 list_add(&path->list_source, &wsource->sinks);
1368 path->connect = 1;
1369 return 0;
1370 }
1371
1372 /* connect dynamic paths */
1373 switch(wsink->id) {
1374 case snd_soc_dapm_adc:
1375 case snd_soc_dapm_dac:
1376 case snd_soc_dapm_pga:
1377 case snd_soc_dapm_input:
1378 case snd_soc_dapm_output:
1379 case snd_soc_dapm_micbias:
1380 case snd_soc_dapm_vmid:
1381 case snd_soc_dapm_pre:
1382 case snd_soc_dapm_post:
Mark Brown246d0a12009-04-22 18:24:55 +01001383 case snd_soc_dapm_supply:
Mark Brown010ff262009-08-17 17:39:22 +01001384 case snd_soc_dapm_aif_in:
1385 case snd_soc_dapm_aif_out:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001386 list_add(&path->list, &dapm->paths);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001387 list_add(&path->list_sink, &wsink->sources);
1388 list_add(&path->list_source, &wsource->sinks);
1389 path->connect = 1;
1390 return 0;
1391 case snd_soc_dapm_mux:
Peter Ujfalusi74155552009-01-08 13:34:29 +02001392 case snd_soc_dapm_value_mux:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001393 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
Richard Purdie2b97eab2006-10-06 18:32:18 +02001394 &wsink->kcontrols[0]);
1395 if (ret != 0)
1396 goto err;
1397 break;
1398 case snd_soc_dapm_switch:
1399 case snd_soc_dapm_mixer:
Ian Moltonca9c1aa2009-01-06 20:11:51 +00001400 case snd_soc_dapm_mixer_named_ctl:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001401 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001402 if (ret != 0)
1403 goto err;
1404 break;
1405 case snd_soc_dapm_hp:
1406 case snd_soc_dapm_mic:
1407 case snd_soc_dapm_line:
1408 case snd_soc_dapm_spk:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001409 list_add(&path->list, &dapm->paths);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001410 list_add(&path->list_sink, &wsink->sources);
1411 list_add(&path->list_source, &wsource->sinks);
1412 path->connect = 0;
1413 return 0;
1414 }
1415 return 0;
1416
1417err:
1418 printk(KERN_WARNING "asoc: no dapm match for %s --> %s --> %s\n", source,
1419 control, sink);
1420 kfree(path);
1421 return ret;
1422}
Mark Brown105f1c22008-05-13 14:52:19 +02001423
1424/**
Mark Brown105f1c22008-05-13 14:52:19 +02001425 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001426 * @dapm: DAPM context
Mark Brown105f1c22008-05-13 14:52:19 +02001427 * @route: audio routes
1428 * @num: number of routes
1429 *
1430 * Connects 2 dapm widgets together via a named audio path. The sink is
1431 * the widget receiving the audio signal, whilst the source is the sender
1432 * of the audio signal.
1433 *
1434 * Returns 0 for success else error. On error all resources can be freed
1435 * with a call to snd_soc_card_free().
1436 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001437int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
Mark Brown105f1c22008-05-13 14:52:19 +02001438 const struct snd_soc_dapm_route *route, int num)
1439{
1440 int i, ret;
1441
1442 for (i = 0; i < num; i++) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001443 ret = snd_soc_dapm_add_route(dapm, route);
Mark Brown105f1c22008-05-13 14:52:19 +02001444 if (ret < 0) {
1445 printk(KERN_ERR "Failed to add route %s->%s\n",
1446 route->source,
1447 route->sink);
1448 return ret;
1449 }
1450 route++;
1451 }
1452
1453 return 0;
1454}
1455EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
1456
1457/**
Richard Purdie2b97eab2006-10-06 18:32:18 +02001458 * snd_soc_dapm_new_widgets - add new dapm widgets
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001459 * @dapm: DAPM context
Richard Purdie2b97eab2006-10-06 18:32:18 +02001460 *
1461 * Checks the codec for any new dapm widgets and creates them if found.
1462 *
1463 * Returns 0 for success.
1464 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001465int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001466{
1467 struct snd_soc_dapm_widget *w;
1468
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001469 list_for_each_entry(w, &dapm->widgets, list)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001470 {
1471 if (w->new)
1472 continue;
1473
1474 switch(w->id) {
1475 case snd_soc_dapm_switch:
1476 case snd_soc_dapm_mixer:
Ian Moltonca9c1aa2009-01-06 20:11:51 +00001477 case snd_soc_dapm_mixer_named_ctl:
Mark Brownb75576d2009-04-20 17:56:13 +01001478 w->power_check = dapm_generic_check_power;
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001479 dapm_new_mixer(dapm, w);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001480 break;
1481 case snd_soc_dapm_mux:
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001482 case snd_soc_dapm_value_mux:
Mark Brownb75576d2009-04-20 17:56:13 +01001483 w->power_check = dapm_generic_check_power;
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001484 dapm_new_mux(dapm, w);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001485 break;
1486 case snd_soc_dapm_adc:
Mark Brown010ff262009-08-17 17:39:22 +01001487 case snd_soc_dapm_aif_out:
Mark Brownb75576d2009-04-20 17:56:13 +01001488 w->power_check = dapm_adc_check_power;
1489 break;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001490 case snd_soc_dapm_dac:
Mark Brown010ff262009-08-17 17:39:22 +01001491 case snd_soc_dapm_aif_in:
Mark Brownb75576d2009-04-20 17:56:13 +01001492 w->power_check = dapm_dac_check_power;
1493 break;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001494 case snd_soc_dapm_pga:
Mark Brownb75576d2009-04-20 17:56:13 +01001495 w->power_check = dapm_generic_check_power;
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001496 dapm_new_pga(dapm, w);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001497 break;
1498 case snd_soc_dapm_input:
1499 case snd_soc_dapm_output:
1500 case snd_soc_dapm_micbias:
1501 case snd_soc_dapm_spk:
1502 case snd_soc_dapm_hp:
1503 case snd_soc_dapm_mic:
1504 case snd_soc_dapm_line:
Mark Brownb75576d2009-04-20 17:56:13 +01001505 w->power_check = dapm_generic_check_power;
1506 break;
Mark Brown246d0a12009-04-22 18:24:55 +01001507 case snd_soc_dapm_supply:
1508 w->power_check = dapm_supply_check_power;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001509 case snd_soc_dapm_vmid:
1510 case snd_soc_dapm_pre:
1511 case snd_soc_dapm_post:
1512 break;
1513 }
1514 w->new = 1;
1515 }
1516
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001517 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001518 return 0;
1519}
1520EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
1521
1522/**
1523 * snd_soc_dapm_get_volsw - dapm mixer get callback
1524 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00001525 * @ucontrol: control element information
Richard Purdie2b97eab2006-10-06 18:32:18 +02001526 *
1527 * Callback to get the value of a dapm mixer control.
1528 *
1529 * Returns 0 for success.
1530 */
1531int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
1532 struct snd_ctl_elem_value *ucontrol)
1533{
1534 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
Jon Smirl4eaa9812008-07-29 11:42:26 +01001535 struct soc_mixer_control *mc =
1536 (struct soc_mixer_control *)kcontrol->private_value;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04001537 unsigned int reg = mc->reg;
1538 unsigned int shift = mc->shift;
1539 unsigned int rshift = mc->rshift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01001540 int max = mc->max;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04001541 unsigned int invert = mc->invert;
1542 unsigned int mask = (1 << fls(max)) - 1;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001543
Richard Purdie2b97eab2006-10-06 18:32:18 +02001544 ucontrol->value.integer.value[0] =
1545 (snd_soc_read(widget->codec, reg) >> shift) & mask;
1546 if (shift != rshift)
1547 ucontrol->value.integer.value[1] =
1548 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
1549 if (invert) {
1550 ucontrol->value.integer.value[0] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001551 max - ucontrol->value.integer.value[0];
Richard Purdie2b97eab2006-10-06 18:32:18 +02001552 if (shift != rshift)
1553 ucontrol->value.integer.value[1] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001554 max - ucontrol->value.integer.value[1];
Richard Purdie2b97eab2006-10-06 18:32:18 +02001555 }
1556
1557 return 0;
1558}
1559EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
1560
1561/**
1562 * snd_soc_dapm_put_volsw - dapm mixer set callback
1563 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00001564 * @ucontrol: control element information
Richard Purdie2b97eab2006-10-06 18:32:18 +02001565 *
1566 * Callback to set the value of a dapm mixer control.
1567 *
1568 * Returns 0 for success.
1569 */
1570int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
1571 struct snd_ctl_elem_value *ucontrol)
1572{
1573 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
Jon Smirl4eaa9812008-07-29 11:42:26 +01001574 struct soc_mixer_control *mc =
1575 (struct soc_mixer_control *)kcontrol->private_value;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04001576 unsigned int reg = mc->reg;
1577 unsigned int shift = mc->shift;
1578 unsigned int rshift = mc->rshift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01001579 int max = mc->max;
Jon Smirl815ecf8d2008-07-29 10:22:24 -04001580 unsigned int mask = (1 << fls(max)) - 1;
1581 unsigned int invert = mc->invert;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001582 unsigned int val, val2, val_mask;
Mark Brown283375c2009-12-07 18:09:03 +00001583 int connect;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001584 int ret;
1585
1586 val = (ucontrol->value.integer.value[0] & mask);
1587
1588 if (invert)
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001589 val = max - val;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001590 val_mask = mask << shift;
1591 val = val << shift;
1592 if (shift != rshift) {
1593 val2 = (ucontrol->value.integer.value[1] & mask);
1594 if (invert)
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001595 val2 = max - val2;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001596 val_mask |= mask << rshift;
1597 val |= val2 << rshift;
1598 }
1599
1600 mutex_lock(&widget->codec->mutex);
1601 widget->value = val;
1602
Mark Brown283375c2009-12-07 18:09:03 +00001603 if (snd_soc_test_bits(widget->codec, reg, val_mask, val)) {
1604 if (val)
1605 /* new connection */
1606 connect = invert ? 0:1;
1607 else
1608 /* old connection must be powered down */
1609 connect = invert ? 1:0;
1610
1611 dapm_mixer_update_power(widget, kcontrol, connect);
1612 }
1613
Richard Purdie2b97eab2006-10-06 18:32:18 +02001614 if (widget->event) {
1615 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
Laim Girdwood9af6d952008-01-10 14:41:02 +01001616 ret = widget->event(widget, kcontrol,
1617 SND_SOC_DAPM_PRE_REG);
1618 if (ret < 0) {
1619 ret = 1;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001620 goto out;
Laim Girdwood9af6d952008-01-10 14:41:02 +01001621 }
Richard Purdie2b97eab2006-10-06 18:32:18 +02001622 }
1623 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1624 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
Laim Girdwood9af6d952008-01-10 14:41:02 +01001625 ret = widget->event(widget, kcontrol,
1626 SND_SOC_DAPM_POST_REG);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001627 } else
1628 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1629
1630out:
1631 mutex_unlock(&widget->codec->mutex);
1632 return ret;
1633}
1634EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
1635
1636/**
1637 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
1638 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00001639 * @ucontrol: control element information
Richard Purdie2b97eab2006-10-06 18:32:18 +02001640 *
1641 * Callback to get the value of a dapm enumerated double mixer control.
1642 *
1643 * Returns 0 for success.
1644 */
1645int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
1646 struct snd_ctl_elem_value *ucontrol)
1647{
1648 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1649 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001650 unsigned int val, bitmask;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001651
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001652 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001653 ;
1654 val = snd_soc_read(widget->codec, e->reg);
1655 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
1656 if (e->shift_l != e->shift_r)
1657 ucontrol->value.enumerated.item[1] =
1658 (val >> e->shift_r) & (bitmask - 1);
1659
1660 return 0;
1661}
1662EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
1663
1664/**
1665 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
1666 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00001667 * @ucontrol: control element information
Richard Purdie2b97eab2006-10-06 18:32:18 +02001668 *
1669 * Callback to set the value of a dapm enumerated double mixer control.
1670 *
1671 * Returns 0 for success.
1672 */
1673int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
1674 struct snd_ctl_elem_value *ucontrol)
1675{
1676 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1677 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Mark Brown3a655772009-10-05 17:23:30 +01001678 unsigned int val, mux, change;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001679 unsigned int mask, bitmask;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001680 int ret = 0;
1681
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001682 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001683 ;
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001684 if (ucontrol->value.enumerated.item[0] > e->max - 1)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001685 return -EINVAL;
1686 mux = ucontrol->value.enumerated.item[0];
1687 val = mux << e->shift_l;
1688 mask = (bitmask - 1) << e->shift_l;
1689 if (e->shift_l != e->shift_r) {
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001690 if (ucontrol->value.enumerated.item[1] > e->max - 1)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001691 return -EINVAL;
1692 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1693 mask |= (bitmask - 1) << e->shift_r;
1694 }
1695
1696 mutex_lock(&widget->codec->mutex);
1697 widget->value = val;
Mark Brown3a655772009-10-05 17:23:30 +01001698 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
1699 dapm_mux_update_power(widget, kcontrol, change, mux, e);
Mark Brown1642e3d2009-10-05 16:24:26 +01001700
1701 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1702 ret = widget->event(widget,
1703 kcontrol, SND_SOC_DAPM_PRE_REG);
1704 if (ret < 0)
1705 goto out;
1706 }
1707
1708 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1709
1710 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1711 ret = widget->event(widget,
1712 kcontrol, SND_SOC_DAPM_POST_REG);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001713
1714out:
1715 mutex_unlock(&widget->codec->mutex);
1716 return ret;
1717}
1718EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
1719
1720/**
Mark Brownd2b247a2009-10-06 15:21:04 +01001721 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
1722 * @kcontrol: mixer control
1723 * @ucontrol: control element information
1724 *
1725 * Returns 0 for success.
1726 */
1727int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
1728 struct snd_ctl_elem_value *ucontrol)
1729{
1730 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1731
1732 ucontrol->value.enumerated.item[0] = widget->value;
1733
1734 return 0;
1735}
1736EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
1737
1738/**
1739 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
1740 * @kcontrol: mixer control
1741 * @ucontrol: control element information
1742 *
1743 * Returns 0 for success.
1744 */
1745int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
1746 struct snd_ctl_elem_value *ucontrol)
1747{
1748 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1749 struct soc_enum *e =
1750 (struct soc_enum *)kcontrol->private_value;
1751 int change;
1752 int ret = 0;
1753
1754 if (ucontrol->value.enumerated.item[0] >= e->max)
1755 return -EINVAL;
1756
1757 mutex_lock(&widget->codec->mutex);
1758
1759 change = widget->value != ucontrol->value.enumerated.item[0];
1760 widget->value = ucontrol->value.enumerated.item[0];
1761 dapm_mux_update_power(widget, kcontrol, change, widget->value, e);
1762
1763 mutex_unlock(&widget->codec->mutex);
1764 return ret;
1765}
1766EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
1767
1768/**
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001769 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
1770 * callback
1771 * @kcontrol: mixer control
1772 * @ucontrol: control element information
1773 *
1774 * Callback to get the value of a dapm semi enumerated double mixer control.
1775 *
1776 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1777 * used for handling bitfield coded enumeration for example.
1778 *
1779 * Returns 0 for success.
1780 */
1781int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
1782 struct snd_ctl_elem_value *ucontrol)
1783{
1784 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
Peter Ujfalusi74155552009-01-08 13:34:29 +02001785 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001786 unsigned int reg_val, val, mux;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001787
1788 reg_val = snd_soc_read(widget->codec, e->reg);
1789 val = (reg_val >> e->shift_l) & e->mask;
1790 for (mux = 0; mux < e->max; mux++) {
1791 if (val == e->values[mux])
1792 break;
1793 }
1794 ucontrol->value.enumerated.item[0] = mux;
1795 if (e->shift_l != e->shift_r) {
1796 val = (reg_val >> e->shift_r) & e->mask;
1797 for (mux = 0; mux < e->max; mux++) {
1798 if (val == e->values[mux])
1799 break;
1800 }
1801 ucontrol->value.enumerated.item[1] = mux;
1802 }
1803
1804 return 0;
1805}
1806EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
1807
1808/**
1809 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
1810 * callback
1811 * @kcontrol: mixer control
1812 * @ucontrol: control element information
1813 *
1814 * Callback to set the value of a dapm semi enumerated double mixer control.
1815 *
1816 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1817 * used for handling bitfield coded enumeration for example.
1818 *
1819 * Returns 0 for success.
1820 */
1821int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
1822 struct snd_ctl_elem_value *ucontrol)
1823{
1824 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
Peter Ujfalusi74155552009-01-08 13:34:29 +02001825 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Mark Brown3a655772009-10-05 17:23:30 +01001826 unsigned int val, mux, change;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001827 unsigned int mask;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001828 int ret = 0;
1829
1830 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1831 return -EINVAL;
1832 mux = ucontrol->value.enumerated.item[0];
1833 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
1834 mask = e->mask << e->shift_l;
1835 if (e->shift_l != e->shift_r) {
1836 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1837 return -EINVAL;
1838 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
1839 mask |= e->mask << e->shift_r;
1840 }
1841
1842 mutex_lock(&widget->codec->mutex);
1843 widget->value = val;
Mark Brown3a655772009-10-05 17:23:30 +01001844 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
1845 dapm_mux_update_power(widget, kcontrol, change, mux, e);
Mark Brown1642e3d2009-10-05 16:24:26 +01001846
1847 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1848 ret = widget->event(widget,
1849 kcontrol, SND_SOC_DAPM_PRE_REG);
1850 if (ret < 0)
1851 goto out;
1852 }
1853
1854 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1855
1856 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1857 ret = widget->event(widget,
1858 kcontrol, SND_SOC_DAPM_POST_REG);
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001859
1860out:
1861 mutex_unlock(&widget->codec->mutex);
1862 return ret;
1863}
1864EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
1865
1866/**
Mark Brown8b37dbd2009-02-28 21:14:20 +00001867 * snd_soc_dapm_info_pin_switch - Info for a pin switch
1868 *
1869 * @kcontrol: mixer control
1870 * @uinfo: control element information
1871 *
1872 * Callback to provide information about a pin switch control.
1873 */
1874int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
1875 struct snd_ctl_elem_info *uinfo)
1876{
1877 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1878 uinfo->count = 1;
1879 uinfo->value.integer.min = 0;
1880 uinfo->value.integer.max = 1;
1881
1882 return 0;
1883}
1884EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
1885
1886/**
1887 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
1888 *
1889 * @kcontrol: mixer control
1890 * @ucontrol: Value
1891 */
1892int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
1893 struct snd_ctl_elem_value *ucontrol)
1894{
1895 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1896 const char *pin = (const char *)kcontrol->private_value;
1897
1898 mutex_lock(&codec->mutex);
1899
1900 ucontrol->value.integer.value[0] =
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001901 snd_soc_dapm_get_pin_status(&codec->dapm, pin);
Mark Brown8b37dbd2009-02-28 21:14:20 +00001902
1903 mutex_unlock(&codec->mutex);
1904
1905 return 0;
1906}
1907EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
1908
1909/**
1910 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
1911 *
1912 * @kcontrol: mixer control
1913 * @ucontrol: Value
1914 */
1915int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
1916 struct snd_ctl_elem_value *ucontrol)
1917{
1918 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1919 const char *pin = (const char *)kcontrol->private_value;
1920
1921 mutex_lock(&codec->mutex);
1922
1923 if (ucontrol->value.integer.value[0])
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001924 snd_soc_dapm_enable_pin(&codec->dapm, pin);
Mark Brown8b37dbd2009-02-28 21:14:20 +00001925 else
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001926 snd_soc_dapm_disable_pin(&codec->dapm, pin);
Mark Brown8b37dbd2009-02-28 21:14:20 +00001927
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001928 snd_soc_dapm_sync(&codec->dapm);
Mark Brown8b37dbd2009-02-28 21:14:20 +00001929
1930 mutex_unlock(&codec->mutex);
1931
1932 return 0;
1933}
1934EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
1935
1936/**
Richard Purdie2b97eab2006-10-06 18:32:18 +02001937 * snd_soc_dapm_new_control - create new dapm control
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001938 * @dapm: DAPM context
Richard Purdie2b97eab2006-10-06 18:32:18 +02001939 * @widget: widget template
1940 *
1941 * Creates a new dapm control based upon the template.
1942 *
1943 * Returns 0 for success else error.
1944 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001945int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
Richard Purdie2b97eab2006-10-06 18:32:18 +02001946 const struct snd_soc_dapm_widget *widget)
1947{
1948 struct snd_soc_dapm_widget *w;
1949
1950 if ((w = dapm_cnew_widget(widget)) == NULL)
1951 return -ENOMEM;
1952
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001953 w->dapm = dapm;
1954 w->codec = dapm->codec;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001955 INIT_LIST_HEAD(&w->sources);
1956 INIT_LIST_HEAD(&w->sinks);
1957 INIT_LIST_HEAD(&w->list);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001958 list_add(&w->list, &dapm->widgets);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001959
1960 /* machine layer set ups unconnected pins and insertions */
1961 w->connected = 1;
1962 return 0;
1963}
1964EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
1965
1966/**
Mark Brown4ba13272008-05-13 14:51:19 +02001967 * snd_soc_dapm_new_controls - create new dapm controls
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001968 * @dapm: DAPM context
Mark Brown4ba13272008-05-13 14:51:19 +02001969 * @widget: widget array
1970 * @num: number of widgets
1971 *
1972 * Creates new DAPM controls based upon the templates.
1973 *
1974 * Returns 0 for success else error.
1975 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001976int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
Mark Brown4ba13272008-05-13 14:51:19 +02001977 const struct snd_soc_dapm_widget *widget,
1978 int num)
1979{
1980 int i, ret;
1981
1982 for (i = 0; i < num; i++) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001983 ret = snd_soc_dapm_new_control(dapm, widget);
Mark Brownb8b33cb2008-12-18 11:19:30 +00001984 if (ret < 0) {
1985 printk(KERN_ERR
1986 "ASoC: Failed to create DAPM control %s: %d\n",
1987 widget->name, ret);
Mark Brown4ba13272008-05-13 14:51:19 +02001988 return ret;
Mark Brownb8b33cb2008-12-18 11:19:30 +00001989 }
Mark Brown4ba13272008-05-13 14:51:19 +02001990 widget++;
1991 }
1992 return 0;
1993}
1994EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
1995
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001996static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001997 const char *stream, int event)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001998{
1999 struct snd_soc_dapm_widget *w;
2000
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002001 list_for_each_entry(w, &dapm->widgets, list)
Richard Purdie2b97eab2006-10-06 18:32:18 +02002002 {
2003 if (!w->sname)
2004 continue;
Mark Brownc1286b82008-07-07 19:26:03 +01002005 pr_debug("widget %s\n %s stream %s event %d\n",
2006 w->name, w->sname, stream, event);
Richard Purdie2b97eab2006-10-06 18:32:18 +02002007 if (strstr(w->sname, stream)) {
2008 switch(event) {
2009 case SND_SOC_DAPM_STREAM_START:
2010 w->active = 1;
2011 break;
2012 case SND_SOC_DAPM_STREAM_STOP:
2013 w->active = 0;
2014 break;
2015 case SND_SOC_DAPM_STREAM_SUSPEND:
Richard Purdie2b97eab2006-10-06 18:32:18 +02002016 case SND_SOC_DAPM_STREAM_RESUME:
Richard Purdie2b97eab2006-10-06 18:32:18 +02002017 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
Richard Purdie2b97eab2006-10-06 18:32:18 +02002018 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
2019 break;
2020 }
2021 }
2022 }
Richard Purdie2b97eab2006-10-06 18:32:18 +02002023
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002024 dapm_power_widgets(dapm, event);
2025}
2026
2027/**
2028 * snd_soc_dapm_stream_event - send a stream event to the dapm core
2029 * @rtd: PCM runtime data
2030 * @stream: stream name
2031 * @event: stream event
2032 *
2033 * Sends a stream event to the dapm core. The core then makes any
2034 * necessary widget power changes.
2035 *
2036 * Returns 0 for success else error.
2037 */
2038int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
2039 const char *stream, int event)
2040{
2041 struct snd_soc_codec *codec = rtd->codec;
2042
2043 if (stream == NULL)
2044 return 0;
2045
2046 mutex_lock(&codec->mutex);
2047 soc_dapm_stream_event(&codec->dapm, stream, event);
Eero Nurkkala8e8b2d62009-10-12 08:41:59 +03002048 mutex_unlock(&codec->mutex);
Richard Purdie2b97eab2006-10-06 18:32:18 +02002049 return 0;
2050}
2051EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
2052
2053/**
Liam Girdwooda5302182008-07-07 13:35:17 +01002054 * snd_soc_dapm_enable_pin - enable pin.
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002055 * @dapm: DAPM context
Liam Girdwooda5302182008-07-07 13:35:17 +01002056 * @pin: pin name
Richard Purdie2b97eab2006-10-06 18:32:18 +02002057 *
Mark Brown74b8f952009-06-06 11:26:15 +01002058 * Enables input/output pin and its parents or children widgets iff there is
Liam Girdwooda5302182008-07-07 13:35:17 +01002059 * a valid audio route and active audio stream.
2060 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2061 * do any widget power switching.
Richard Purdie2b97eab2006-10-06 18:32:18 +02002062 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002063int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
Richard Purdie2b97eab2006-10-06 18:32:18 +02002064{
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002065 return snd_soc_dapm_set_pin(dapm, pin, 1);
Richard Purdie2b97eab2006-10-06 18:32:18 +02002066}
Liam Girdwooda5302182008-07-07 13:35:17 +01002067EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
Richard Purdie2b97eab2006-10-06 18:32:18 +02002068
2069/**
Mark Brownda341832010-03-15 19:23:37 +00002070 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002071 * @dapm: DAPM context
Mark Brownda341832010-03-15 19:23:37 +00002072 * @pin: pin name
2073 *
2074 * Enables input/output pin regardless of any other state. This is
2075 * intended for use with microphone bias supplies used in microphone
2076 * jack detection.
2077 *
2078 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2079 * do any widget power switching.
2080 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002081int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
2082 const char *pin)
Mark Brownda341832010-03-15 19:23:37 +00002083{
2084 struct snd_soc_dapm_widget *w;
2085
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002086 list_for_each_entry(w, &dapm->widgets, list) {
Mark Brownda341832010-03-15 19:23:37 +00002087 if (!strcmp(w->name, pin)) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002088 pr_debug("dapm: %s: pin %s\n", dapm->codec->name, pin);
Mark Brownda341832010-03-15 19:23:37 +00002089 w->connected = 1;
2090 w->force = 1;
2091 return 0;
2092 }
2093 }
2094
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002095 pr_err("dapm: %s: configuring unknown pin %s\n",
2096 dapm->codec->name, pin);
Mark Brownda341832010-03-15 19:23:37 +00002097 return -EINVAL;
2098}
2099EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
2100
2101/**
Liam Girdwooda5302182008-07-07 13:35:17 +01002102 * snd_soc_dapm_disable_pin - disable pin.
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002103 * @dapm: DAPM context
Liam Girdwooda5302182008-07-07 13:35:17 +01002104 * @pin: pin name
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02002105 *
Mark Brown74b8f952009-06-06 11:26:15 +01002106 * Disables input/output pin and its parents or children widgets.
Liam Girdwooda5302182008-07-07 13:35:17 +01002107 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2108 * do any widget power switching.
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02002109 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002110int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
2111 const char *pin)
Liam Girdwooda5302182008-07-07 13:35:17 +01002112{
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002113 return snd_soc_dapm_set_pin(dapm, pin, 0);
Liam Girdwooda5302182008-07-07 13:35:17 +01002114}
2115EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
2116
2117/**
Mark Brown5817b522008-09-24 11:23:11 +01002118 * snd_soc_dapm_nc_pin - permanently disable pin.
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002119 * @dapm: DAPM context
Mark Brown5817b522008-09-24 11:23:11 +01002120 * @pin: pin name
2121 *
2122 * Marks the specified pin as being not connected, disabling it along
2123 * any parent or child widgets. At present this is identical to
2124 * snd_soc_dapm_disable_pin() but in future it will be extended to do
2125 * additional things such as disabling controls which only affect
2126 * paths through the pin.
2127 *
2128 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2129 * do any widget power switching.
2130 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002131int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
Mark Brown5817b522008-09-24 11:23:11 +01002132{
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002133 return snd_soc_dapm_set_pin(dapm, pin, 0);
Mark Brown5817b522008-09-24 11:23:11 +01002134}
2135EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
2136
2137/**
Liam Girdwooda5302182008-07-07 13:35:17 +01002138 * snd_soc_dapm_get_pin_status - get audio pin status
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002139 * @dapm: DAPM context
Liam Girdwooda5302182008-07-07 13:35:17 +01002140 * @pin: audio signal pin endpoint (or start point)
2141 *
2142 * Get audio pin status - connected or disconnected.
2143 *
2144 * Returns 1 for connected otherwise 0.
2145 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002146int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
2147 const char *pin)
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02002148{
2149 struct snd_soc_dapm_widget *w;
2150
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002151 list_for_each_entry(w, &dapm->widgets, list) {
Liam Girdwooda5302182008-07-07 13:35:17 +01002152 if (!strcmp(w->name, pin))
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02002153 return w->connected;
2154 }
2155
2156 return 0;
2157}
Liam Girdwooda5302182008-07-07 13:35:17 +01002158EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02002159
2160/**
Mark Brown1547aba2010-05-07 21:11:40 +01002161 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002162 * @dapm: DAPM context
Mark Brown1547aba2010-05-07 21:11:40 +01002163 * @pin: audio signal pin endpoint (or start point)
2164 *
2165 * Mark the given endpoint or pin as ignoring suspend. When the
2166 * system is disabled a path between two endpoints flagged as ignoring
2167 * suspend will not be disabled. The path must already be enabled via
2168 * normal means at suspend time, it will not be turned on if it was not
2169 * already enabled.
2170 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002171int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
2172 const char *pin)
Mark Brown1547aba2010-05-07 21:11:40 +01002173{
2174 struct snd_soc_dapm_widget *w;
2175
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002176 list_for_each_entry(w, &dapm->widgets, list) {
Mark Brown1547aba2010-05-07 21:11:40 +01002177 if (!strcmp(w->name, pin)) {
2178 w->ignore_suspend = 1;
2179 return 0;
2180 }
2181 }
2182
2183 pr_err("Unknown DAPM pin: %s\n", pin);
2184 return -EINVAL;
2185}
2186EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
2187
2188/**
Richard Purdie2b97eab2006-10-06 18:32:18 +02002189 * snd_soc_dapm_free - free dapm resources
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002190 * @card: SoC device
Richard Purdie2b97eab2006-10-06 18:32:18 +02002191 *
2192 * Free all dapm widgets and resources.
2193 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002194void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
Richard Purdie2b97eab2006-10-06 18:32:18 +02002195{
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002196 snd_soc_dapm_sys_remove(dapm->dev);
2197 dapm_free_widgets(dapm);
Richard Purdie2b97eab2006-10-06 18:32:18 +02002198}
2199EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
2200
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002201static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
Mark Brown51737472009-06-22 13:16:51 +01002202{
Mark Brown51737472009-06-22 13:16:51 +01002203 struct snd_soc_dapm_widget *w;
2204 LIST_HEAD(down_list);
2205 int powerdown = 0;
2206
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002207 list_for_each_entry(w, &dapm->widgets, list) {
Mark Brown51737472009-06-22 13:16:51 +01002208 if (w->power) {
2209 dapm_seq_insert(w, &down_list, dapm_down_seq);
Mark Brownc2caa4d2009-06-26 15:36:56 +01002210 w->power = 0;
Mark Brown51737472009-06-22 13:16:51 +01002211 powerdown = 1;
2212 }
2213 }
2214
2215 /* If there were no widgets to power down we're already in
2216 * standby.
2217 */
2218 if (powerdown) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002219 snd_soc_dapm_set_bias_level(NULL, dapm, SND_SOC_BIAS_PREPARE);
2220 dapm_seq_run(dapm, &down_list, 0, dapm_down_seq);
2221 snd_soc_dapm_set_bias_level(NULL, dapm, SND_SOC_BIAS_STANDBY);
Mark Brown51737472009-06-22 13:16:51 +01002222 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002223}
Mark Brown51737472009-06-22 13:16:51 +01002224
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002225/*
2226 * snd_soc_dapm_shutdown - callback for system shutdown
2227 */
2228void snd_soc_dapm_shutdown(struct snd_soc_card *card)
2229{
2230 struct snd_soc_codec *codec;
2231
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002232 list_for_each_entry(codec, &card->codec_dev_list, list) {
2233 soc_dapm_shutdown_codec(&codec->dapm);
2234 snd_soc_dapm_set_bias_level(card, &codec->dapm, SND_SOC_BIAS_OFF);
2235 }
Mark Brown51737472009-06-22 13:16:51 +01002236}
2237
Richard Purdie2b97eab2006-10-06 18:32:18 +02002238/* Module information */
Liam Girdwoodd3311242008-10-12 13:17:36 +01002239MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
Richard Purdie2b97eab2006-10-06 18:32:18 +02002240MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
2241MODULE_LICENSE("GPL");