blob: b8f653eaffaa059833bdfc7f572bd4566b41efac [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 Brown15e4c722008-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 Brown15e4c722008-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 Brown15e4c722008-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 Smirl815ecf82008-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 Smirl815ecf82008-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 Smirlf8ba0b7b2008-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 Smirlf8ba0b7b2008-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 Smirlf8ba0b7b2008-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;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200296
297 /* check for valid widgets */
298 if (widget->reg < 0 || widget->id == snd_soc_dapm_input ||
299 widget->id == snd_soc_dapm_output ||
300 widget->id == snd_soc_dapm_hp ||
301 widget->id == snd_soc_dapm_mic ||
302 widget->id == snd_soc_dapm_line ||
303 widget->id == snd_soc_dapm_spk)
304 return 0;
305
306 power = widget->power;
307 if (widget->invert)
308 power = (power ? 0:1);
309
310 old = snd_soc_read(codec, widget->reg);
311 new = (old & ~(0x1 << widget->shift)) | (power << widget->shift);
312
313 change = old != new;
314 if (change) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200315 pop_dbg(dapm->pop_time, "pop test %s : %s in %d ms\n",
Troy Kisky12ef1932008-10-13 17:42:14 -0700316 widget->name, widget->power ? "on" : "off",
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200317 dapm->pop_time);
318 pop_wait(dapm->pop_time);
Mark Brown69224712010-03-03 14:57:09 +0000319 snd_soc_write(codec, widget->reg, new);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200320 }
Mark Brownc1286b82008-07-07 19:26:03 +0100321 pr_debug("reg %x old %x new %x change %d\n", widget->reg,
322 old, new, change);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200323 return change;
324}
325
Richard Purdie2b97eab2006-10-06 18:32:18 +0200326/* create new dapm mixer control */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200327static int dapm_new_mixer(struct snd_soc_dapm_context *dapm,
Richard Purdie2b97eab2006-10-06 18:32:18 +0200328 struct snd_soc_dapm_widget *w)
329{
330 int i, ret = 0;
Mark Brown219b93f2008-10-28 13:02:31 +0000331 size_t name_len;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200332 struct snd_soc_dapm_path *path;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200333 struct snd_card *card = dapm->codec->card->snd_card;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200334
335 /* add kcontrol */
336 for (i = 0; i < w->num_kcontrols; i++) {
337
338 /* match name */
339 list_for_each_entry(path, &w->sources, list_sink) {
340
341 /* mixer/mux paths name must match control name */
342 if (path->name != (char*)w->kcontrols[i].name)
343 continue;
344
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000345 /* add dapm control with long name.
346 * for dapm_mixer this is the concatenation of the
347 * mixer and kcontrol name.
348 * for dapm_mixer_named_ctl this is simply the
349 * kcontrol name.
350 */
351 name_len = strlen(w->kcontrols[i].name) + 1;
Mark Brown07495f32009-03-05 17:06:23 +0000352 if (w->id != snd_soc_dapm_mixer_named_ctl)
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000353 name_len += 1 + strlen(w->name);
354
Mark Brown219b93f2008-10-28 13:02:31 +0000355 path->long_name = kmalloc(name_len, GFP_KERNEL);
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000356
Richard Purdie2b97eab2006-10-06 18:32:18 +0200357 if (path->long_name == NULL)
358 return -ENOMEM;
359
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000360 switch (w->id) {
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000361 default:
362 snprintf(path->long_name, name_len, "%s %s",
363 w->name, w->kcontrols[i].name);
Mark Brown07495f32009-03-05 17:06:23 +0000364 break;
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000365 case snd_soc_dapm_mixer_named_ctl:
366 snprintf(path->long_name, name_len, "%s",
367 w->kcontrols[i].name);
Mark Brown07495f32009-03-05 17:06:23 +0000368 break;
Ian Moltonca9c1aa2009-01-06 20:11:51 +0000369 }
370
Mark Brown219b93f2008-10-28 13:02:31 +0000371 path->long_name[name_len - 1] = '\0';
372
Richard Purdie2b97eab2006-10-06 18:32:18 +0200373 path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
374 path->long_name);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200375 ret = snd_ctl_add(card, path->kcontrol);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200376 if (ret < 0) {
Mark Brown6553e192009-04-06 16:59:32 +0100377 printk(KERN_ERR "asoc: failed to add dapm kcontrol %s: %d\n",
378 path->long_name,
379 ret);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200380 kfree(path->long_name);
381 path->long_name = NULL;
382 return ret;
383 }
384 }
385 }
386 return ret;
387}
388
389/* create new dapm mux control */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200390static int dapm_new_mux(struct snd_soc_dapm_context *dapm,
Richard Purdie2b97eab2006-10-06 18:32:18 +0200391 struct snd_soc_dapm_widget *w)
392{
393 struct snd_soc_dapm_path *path = NULL;
394 struct snd_kcontrol *kcontrol;
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200395 struct snd_card *card = dapm->codec->card->snd_card;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200396 int ret = 0;
397
398 if (!w->num_kcontrols) {
399 printk(KERN_ERR "asoc: mux %s has no controls\n", w->name);
400 return -EINVAL;
401 }
402
403 kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200404 ret = snd_ctl_add(card, kcontrol);
405
Richard Purdie2b97eab2006-10-06 18:32:18 +0200406 if (ret < 0)
407 goto err;
408
409 list_for_each_entry(path, &w->sources, list_sink)
410 path->kcontrol = kcontrol;
411
412 return ret;
413
414err:
415 printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name);
416 return ret;
417}
418
419/* create new dapm volume control */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200420static int dapm_new_pga(struct snd_soc_dapm_context *dapm,
Richard Purdie2b97eab2006-10-06 18:32:18 +0200421 struct snd_soc_dapm_widget *w)
422{
Mark Browna6c65732010-03-03 17:45:21 +0000423 if (w->num_kcontrols)
424 pr_err("asoc: PGA controls not supported: '%s'\n", w->name);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200425
Mark Browna6c65732010-03-03 17:45:21 +0000426 return 0;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200427}
428
429/* reset 'walked' bit for each dapm path */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200430static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200431{
432 struct snd_soc_dapm_path *p;
433
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200434 list_for_each_entry(p, &dapm->paths, list)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200435 p->walked = 0;
436}
437
Mark Brown99497882010-05-07 20:24:05 +0100438/* We implement power down on suspend by checking the power state of
439 * the ALSA card - when we are suspending the ALSA state for the card
440 * is set to D3.
441 */
442static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
443{
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200444 int level = snd_power_get_state(widget->dapm->codec->card->snd_card);
Mark Brown99497882010-05-07 20:24:05 +0100445
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000446 switch (level) {
Mark Brown99497882010-05-07 20:24:05 +0100447 case SNDRV_CTL_POWER_D3hot:
448 case SNDRV_CTL_POWER_D3cold:
Mark Brown1547aba2010-05-07 21:11:40 +0100449 if (widget->ignore_suspend)
450 pr_debug("%s ignoring suspend\n", widget->name);
451 return widget->ignore_suspend;
Mark Brown99497882010-05-07 20:24:05 +0100452 default:
453 return 1;
454 }
455}
456
Richard Purdie2b97eab2006-10-06 18:32:18 +0200457/*
458 * Recursively check for a completed path to an active or physically connected
459 * output widget. Returns number of complete paths.
460 */
461static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
462{
463 struct snd_soc_dapm_path *path;
464 int con = 0;
465
Mark Brown246d0a12009-04-22 18:24:55 +0100466 if (widget->id == snd_soc_dapm_supply)
467 return 0;
468
Mark Brown010ff262009-08-17 17:39:22 +0100469 switch (widget->id) {
470 case snd_soc_dapm_adc:
471 case snd_soc_dapm_aif_out:
472 if (widget->active)
Mark Brown99497882010-05-07 20:24:05 +0100473 return snd_soc_dapm_suspend_check(widget);
Mark Brown010ff262009-08-17 17:39:22 +0100474 default:
475 break;
476 }
Richard Purdie2b97eab2006-10-06 18:32:18 +0200477
478 if (widget->connected) {
479 /* connected pin ? */
480 if (widget->id == snd_soc_dapm_output && !widget->ext)
Mark Brown99497882010-05-07 20:24:05 +0100481 return snd_soc_dapm_suspend_check(widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200482
483 /* connected jack or spk ? */
484 if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
Peter Ujfalusieaeae5d2009-09-30 09:27:24 +0300485 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources)))
Mark Brown99497882010-05-07 20:24:05 +0100486 return snd_soc_dapm_suspend_check(widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200487 }
488
489 list_for_each_entry(path, &widget->sinks, list_source) {
490 if (path->walked)
491 continue;
492
493 if (path->sink && path->connect) {
494 path->walked = 1;
495 con += is_connected_output_ep(path->sink);
496 }
497 }
498
499 return con;
500}
501
502/*
503 * Recursively check for a completed path to an active or physically connected
504 * input widget. Returns number of complete paths.
505 */
506static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
507{
508 struct snd_soc_dapm_path *path;
509 int con = 0;
510
Mark Brown246d0a12009-04-22 18:24:55 +0100511 if (widget->id == snd_soc_dapm_supply)
512 return 0;
513
Richard Purdie2b97eab2006-10-06 18:32:18 +0200514 /* active stream ? */
Mark Brown010ff262009-08-17 17:39:22 +0100515 switch (widget->id) {
516 case snd_soc_dapm_dac:
517 case snd_soc_dapm_aif_in:
518 if (widget->active)
Mark Brown99497882010-05-07 20:24:05 +0100519 return snd_soc_dapm_suspend_check(widget);
Mark Brown010ff262009-08-17 17:39:22 +0100520 default:
521 break;
522 }
Richard Purdie2b97eab2006-10-06 18:32:18 +0200523
524 if (widget->connected) {
525 /* connected pin ? */
526 if (widget->id == snd_soc_dapm_input && !widget->ext)
Mark Brown99497882010-05-07 20:24:05 +0100527 return snd_soc_dapm_suspend_check(widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200528
529 /* connected VMID/Bias for lower pops */
530 if (widget->id == snd_soc_dapm_vmid)
Mark Brown99497882010-05-07 20:24:05 +0100531 return snd_soc_dapm_suspend_check(widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200532
533 /* connected jack ? */
Peter Ujfalusieaeae5d2009-09-30 09:27:24 +0300534 if (widget->id == snd_soc_dapm_mic ||
535 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks)))
Mark Brown99497882010-05-07 20:24:05 +0100536 return snd_soc_dapm_suspend_check(widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200537 }
538
539 list_for_each_entry(path, &widget->sources, list_sink) {
540 if (path->walked)
541 continue;
542
543 if (path->source && path->connect) {
544 path->walked = 1;
545 con += is_connected_input_ep(path->source);
546 }
547 }
548
549 return con;
550}
551
552/*
Jarkko Nikulae2be2cc2008-06-25 14:42:07 +0300553 * Handler for generic register modifier widget.
554 */
555int dapm_reg_event(struct snd_soc_dapm_widget *w,
556 struct snd_kcontrol *kcontrol, int event)
557{
558 unsigned int val;
559
560 if (SND_SOC_DAPM_EVENT_ON(event))
561 val = w->on_val;
562 else
563 val = w->off_val;
564
565 snd_soc_update_bits(w->codec, -(w->reg + 1),
566 w->mask << w->shift, val << w->shift);
567
568 return 0;
569}
Mark Brown11589412008-07-29 11:42:23 +0100570EXPORT_SYMBOL_GPL(dapm_reg_event);
Jarkko Nikulae2be2cc2008-06-25 14:42:07 +0300571
Mark Brown025756e2009-04-13 11:09:18 +0100572/* Standard power change method, used to apply power changes to most
573 * widgets.
574 */
575static int dapm_generic_apply_power(struct snd_soc_dapm_widget *w)
576{
577 int ret;
578
579 /* call any power change event handlers */
580 if (w->event)
581 pr_debug("power %s event for %s flags %x\n",
582 w->power ? "on" : "off",
583 w->name, w->event_flags);
584
585 /* power up pre event */
586 if (w->power && w->event &&
587 (w->event_flags & SND_SOC_DAPM_PRE_PMU)) {
588 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
589 if (ret < 0)
590 return ret;
591 }
592
593 /* power down pre event */
594 if (!w->power && w->event &&
595 (w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
596 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
597 if (ret < 0)
598 return ret;
599 }
600
Mark Brown025756e2009-04-13 11:09:18 +0100601 dapm_update_bits(w);
602
Mark Brown025756e2009-04-13 11:09:18 +0100603 /* power up post event */
604 if (w->power && w->event &&
605 (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
606 ret = w->event(w,
607 NULL, SND_SOC_DAPM_POST_PMU);
608 if (ret < 0)
609 return ret;
610 }
611
612 /* power down post event */
613 if (!w->power && w->event &&
614 (w->event_flags & SND_SOC_DAPM_POST_PMD)) {
615 ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
616 if (ret < 0)
617 return ret;
618 }
619
620 return 0;
621}
622
Mark Browncd0f2d42009-04-20 16:56:59 +0100623/* Generic check to see if a widget should be powered.
624 */
625static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
626{
627 int in, out;
628
629 in = is_connected_input_ep(w);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200630 dapm_clear_walk(w->dapm);
Mark Browncd0f2d42009-04-20 16:56:59 +0100631 out = is_connected_output_ep(w);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200632 dapm_clear_walk(w->dapm);
Mark Browncd0f2d42009-04-20 16:56:59 +0100633 return out != 0 && in != 0;
634}
635
Mark Brown6ea31b92009-04-20 17:15:41 +0100636/* Check to see if an ADC has power */
637static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
638{
639 int in;
640
641 if (w->active) {
642 in = is_connected_input_ep(w);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200643 dapm_clear_walk(w->dapm);
Mark Brown6ea31b92009-04-20 17:15:41 +0100644 return in != 0;
645 } else {
646 return dapm_generic_check_power(w);
647 }
648}
649
650/* Check to see if a DAC has power */
651static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
652{
653 int out;
654
655 if (w->active) {
656 out = is_connected_output_ep(w);
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200657 dapm_clear_walk(w->dapm);
Mark Brown6ea31b92009-04-20 17:15:41 +0100658 return out != 0;
659 } else {
660 return dapm_generic_check_power(w);
661 }
662}
663
Mark Brown246d0a12009-04-22 18:24:55 +0100664/* Check to see if a power supply is needed */
665static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
666{
667 struct snd_soc_dapm_path *path;
668 int power = 0;
669
670 /* Check if one of our outputs is connected */
671 list_for_each_entry(path, &w->sinks, list_source) {
Mark Brown215edda2009-09-08 18:59:05 +0100672 if (path->connected &&
673 !path->connected(path->source, path->sink))
674 continue;
675
Mark Brown246d0a12009-04-22 18:24:55 +0100676 if (path->sink && path->sink->power_check &&
677 path->sink->power_check(path->sink)) {
678 power = 1;
679 break;
680 }
681 }
682
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200683 dapm_clear_walk(w->dapm);
Mark Brown246d0a12009-04-22 18:24:55 +0100684
685 return power;
686}
687
Mark Brown38357ab2009-06-06 19:03:23 +0100688static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
689 struct snd_soc_dapm_widget *b,
690 int sort[])
Mark Brown42aa3412009-03-01 19:21:10 +0000691{
Mark Brownd207c682009-12-07 17:13:55 +0000692 if (a->codec != b->codec)
693 return (unsigned long)a - (unsigned long)b;
Mark Brown38357ab2009-06-06 19:03:23 +0100694 if (sort[a->id] != sort[b->id])
695 return sort[a->id] - sort[b->id];
Mark Brownb22ead22009-06-07 12:51:26 +0100696 if (a->reg != b->reg)
697 return a->reg - b->reg;
Mark Brown42aa3412009-03-01 19:21:10 +0000698
Mark Brown38357ab2009-06-06 19:03:23 +0100699 return 0;
700}
Mark Brown42aa3412009-03-01 19:21:10 +0000701
Mark Brown38357ab2009-06-06 19:03:23 +0100702/* Insert a widget in order into a DAPM power sequence. */
703static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
704 struct list_head *list,
705 int sort[])
706{
707 struct snd_soc_dapm_widget *w;
708
709 list_for_each_entry(w, list, power_list)
710 if (dapm_seq_compare(new_widget, w, sort) < 0) {
711 list_add_tail(&new_widget->power_list, &w->power_list);
712 return;
Mark Brown42aa3412009-03-01 19:21:10 +0000713 }
Mark Brown6ea31b92009-04-20 17:15:41 +0100714
Mark Brown38357ab2009-06-06 19:03:23 +0100715 list_add_tail(&new_widget->power_list, list);
716}
Mark Brown42aa3412009-03-01 19:21:10 +0000717
Mark Brownb22ead22009-06-07 12:51:26 +0100718/* Apply the coalesced changes from a DAPM sequence */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200719static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
Mark Brownb22ead22009-06-07 12:51:26 +0100720 struct list_head *pending)
Mark Brown163cac02009-06-07 10:12:52 +0100721{
722 struct snd_soc_dapm_widget *w;
Mark Brown81628102009-06-07 13:21:24 +0100723 int reg, power, ret;
Mark Brownb22ead22009-06-07 12:51:26 +0100724 unsigned int value = 0;
725 unsigned int mask = 0;
726 unsigned int cur_mask;
727
728 reg = list_first_entry(pending, struct snd_soc_dapm_widget,
729 power_list)->reg;
730
731 list_for_each_entry(w, pending, power_list) {
732 cur_mask = 1 << w->shift;
733 BUG_ON(reg != w->reg);
734
735 if (w->invert)
736 power = !w->power;
737 else
738 power = w->power;
739
740 mask |= cur_mask;
741 if (power)
742 value |= cur_mask;
743
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200744 pop_dbg(dapm->pop_time,
Mark Brownb22ead22009-06-07 12:51:26 +0100745 "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
746 w->name, reg, value, mask);
Mark Brown81628102009-06-07 13:21:24 +0100747
748 /* power up pre event */
749 if (w->power && w->event &&
750 (w->event_flags & SND_SOC_DAPM_PRE_PMU)) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200751 pop_dbg(dapm->pop_time, "pop test : %s PRE_PMU\n",
Mark Brown81628102009-06-07 13:21:24 +0100752 w->name);
753 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
754 if (ret < 0)
755 pr_err("%s: pre event failed: %d\n",
756 w->name, ret);
757 }
758
759 /* power down pre event */
760 if (!w->power && w->event &&
761 (w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200762 pop_dbg(dapm->pop_time, "pop test : %s PRE_PMD\n",
Mark Brown81628102009-06-07 13:21:24 +0100763 w->name);
764 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
765 if (ret < 0)
766 pr_err("%s: pre event failed: %d\n",
767 w->name, ret);
768 }
Mark Brownb22ead22009-06-07 12:51:26 +0100769 }
770
Mark Brown81628102009-06-07 13:21:24 +0100771 if (reg >= 0) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200772 pop_dbg(dapm->pop_time,
Mark Brown81628102009-06-07 13:21:24 +0100773 "pop test : Applying 0x%x/0x%x to %x in %dms\n",
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200774 value, mask, reg, dapm->pop_time);
775 pop_wait(dapm->pop_time);
776 snd_soc_update_bits(dapm->codec, reg, mask, value);
Mark Brown81628102009-06-07 13:21:24 +0100777 }
778
779 list_for_each_entry(w, pending, power_list) {
780 /* power up post event */
781 if (w->power && w->event &&
782 (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200783 pop_dbg(dapm->pop_time, "pop test : %s POST_PMU\n",
Mark Brown81628102009-06-07 13:21:24 +0100784 w->name);
Mark Brown42aa3412009-03-01 19:21:10 +0000785 ret = w->event(w,
786 NULL, SND_SOC_DAPM_POST_PMU);
787 if (ret < 0)
Mark Brown81628102009-06-07 13:21:24 +0100788 pr_err("%s: post event failed: %d\n",
789 w->name, ret);
Mark Brown42aa3412009-03-01 19:21:10 +0000790 }
Mark Brown6ea31b92009-04-20 17:15:41 +0100791
Mark Brown81628102009-06-07 13:21:24 +0100792 /* power down post event */
793 if (!w->power && w->event &&
794 (w->event_flags & SND_SOC_DAPM_POST_PMD)) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200795 pop_dbg(dapm->pop_time, "pop test : %s POST_PMD\n",
Mark Brown81628102009-06-07 13:21:24 +0100796 w->name);
797 ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
798 if (ret < 0)
799 pr_err("%s: post event failed: %d\n",
800 w->name, ret);
801 }
Mark Brown42aa3412009-03-01 19:21:10 +0000802 }
Mark Brown42aa3412009-03-01 19:21:10 +0000803}
804
Mark Brownb22ead22009-06-07 12:51:26 +0100805/* Apply a DAPM power sequence.
806 *
807 * We walk over a pre-sorted list of widgets to apply power to. In
808 * order to minimise the number of writes to the device required
809 * multiple widgets will be updated in a single write where possible.
810 * Currently anything that requires more than a single write is not
811 * handled.
812 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200813static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
814 struct list_head *list, int event, int sort[])
Mark Brownb22ead22009-06-07 12:51:26 +0100815{
816 struct snd_soc_dapm_widget *w, *n;
817 LIST_HEAD(pending);
818 int cur_sort = -1;
819 int cur_reg = SND_SOC_NOPM;
Mark Brown163cac02009-06-07 10:12:52 +0100820 int ret;
821
Mark Brownb22ead22009-06-07 12:51:26 +0100822 list_for_each_entry_safe(w, n, list, power_list) {
823 ret = 0;
824
825 /* Do we need to apply any queued changes? */
826 if (sort[w->id] != cur_sort || w->reg != cur_reg) {
827 if (!list_empty(&pending))
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200828 dapm_seq_run_coalesced(dapm, &pending);
Mark Brownb22ead22009-06-07 12:51:26 +0100829
830 INIT_LIST_HEAD(&pending);
831 cur_sort = -1;
832 cur_reg = SND_SOC_NOPM;
833 }
834
Mark Brown163cac02009-06-07 10:12:52 +0100835 switch (w->id) {
836 case snd_soc_dapm_pre:
837 if (!w->event)
Mark Brownb22ead22009-06-07 12:51:26 +0100838 list_for_each_entry_safe_continue(w, n, list,
839 power_list);
Mark Brown163cac02009-06-07 10:12:52 +0100840
Mark Brownb22ead22009-06-07 12:51:26 +0100841 if (event == SND_SOC_DAPM_STREAM_START)
Mark Brown163cac02009-06-07 10:12:52 +0100842 ret = w->event(w,
843 NULL, SND_SOC_DAPM_PRE_PMU);
Mark Brownb22ead22009-06-07 12:51:26 +0100844 else if (event == SND_SOC_DAPM_STREAM_STOP)
Mark Brown163cac02009-06-07 10:12:52 +0100845 ret = w->event(w,
846 NULL, SND_SOC_DAPM_PRE_PMD);
Mark Brown163cac02009-06-07 10:12:52 +0100847 break;
848
849 case snd_soc_dapm_post:
850 if (!w->event)
Mark Brownb22ead22009-06-07 12:51:26 +0100851 list_for_each_entry_safe_continue(w, n, list,
852 power_list);
Mark Brown163cac02009-06-07 10:12:52 +0100853
Mark Brownb22ead22009-06-07 12:51:26 +0100854 if (event == SND_SOC_DAPM_STREAM_START)
Mark Brown163cac02009-06-07 10:12:52 +0100855 ret = w->event(w,
856 NULL, SND_SOC_DAPM_POST_PMU);
Mark Brownb22ead22009-06-07 12:51:26 +0100857 else if (event == SND_SOC_DAPM_STREAM_STOP)
Mark Brown163cac02009-06-07 10:12:52 +0100858 ret = w->event(w,
859 NULL, SND_SOC_DAPM_POST_PMD);
Mark Brownb22ead22009-06-07 12:51:26 +0100860 break;
861
862 case snd_soc_dapm_input:
863 case snd_soc_dapm_output:
864 case snd_soc_dapm_hp:
865 case snd_soc_dapm_mic:
866 case snd_soc_dapm_line:
867 case snd_soc_dapm_spk:
868 /* No register support currently */
Mark Brownb22ead22009-06-07 12:51:26 +0100869 ret = dapm_generic_apply_power(w);
Mark Brown163cac02009-06-07 10:12:52 +0100870 break;
871
872 default:
Mark Brown81628102009-06-07 13:21:24 +0100873 /* Queue it up for application */
874 cur_sort = sort[w->id];
875 cur_reg = w->reg;
876 list_move(&w->power_list, &pending);
877 break;
Mark Brown163cac02009-06-07 10:12:52 +0100878 }
Mark Brownb22ead22009-06-07 12:51:26 +0100879
880 if (ret < 0)
881 pr_err("Failed to apply widget power: %d\n",
882 ret);
Mark Brown163cac02009-06-07 10:12:52 +0100883 }
Mark Brownb22ead22009-06-07 12:51:26 +0100884
885 if (!list_empty(&pending))
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200886 dapm_seq_run_coalesced(dapm, &pending);
Mark Brown163cac02009-06-07 10:12:52 +0100887}
888
Mark Brown42aa3412009-03-01 19:21:10 +0000889/*
Richard Purdie2b97eab2006-10-06 18:32:18 +0200890 * Scan each dapm widget for complete audio path.
891 * A complete path is a route that has valid endpoints i.e.:-
892 *
893 * o DAC to output pin.
894 * o Input Pin to ADC.
895 * o Input pin to Output pin (bypass, sidetone)
896 * o DAC to ADC (loopback).
897 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200898static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200899{
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200900 struct snd_soc_card *card = dapm->codec->card;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200901 struct snd_soc_dapm_widget *w;
Mark Brown291f3bb2009-06-07 13:57:17 +0100902 LIST_HEAD(up_list);
903 LIST_HEAD(down_list);
Mark Brown6d3ddc82009-05-16 17:47:29 +0100904 int ret = 0;
Mark Brown38357ab2009-06-06 19:03:23 +0100905 int power;
Mark Brown452c5ea2009-05-17 21:41:23 +0100906 int sys_power = 0;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200907
Mark Brown6d3ddc82009-05-16 17:47:29 +0100908 /* Check which widgets we need to power and store them in
909 * lists indicating if they should be powered up or down.
910 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200911 list_for_each_entry(w, &dapm->widgets, list) {
Mark Brown6d3ddc82009-05-16 17:47:29 +0100912 switch (w->id) {
913 case snd_soc_dapm_pre:
Mark Brown291f3bb2009-06-07 13:57:17 +0100914 dapm_seq_insert(w, &down_list, dapm_down_seq);
Mark Brown6d3ddc82009-05-16 17:47:29 +0100915 break;
916 case snd_soc_dapm_post:
Mark Brown291f3bb2009-06-07 13:57:17 +0100917 dapm_seq_insert(w, &up_list, dapm_up_seq);
Mark Brown6d3ddc82009-05-16 17:47:29 +0100918 break;
919
920 default:
921 if (!w->power_check)
922 continue;
923
Mark Brown99497882010-05-07 20:24:05 +0100924 if (!w->force)
Mark Brown50b6bce2009-11-23 13:11:53 +0000925 power = w->power_check(w);
Mark Brown99497882010-05-07 20:24:05 +0100926 else
927 power = 1;
928 if (power)
929 sys_power = 1;
Mark Brown452c5ea2009-05-17 21:41:23 +0100930
Mark Brown6d3ddc82009-05-16 17:47:29 +0100931 if (w->power == power)
932 continue;
933
934 if (power)
Mark Brown291f3bb2009-06-07 13:57:17 +0100935 dapm_seq_insert(w, &up_list, dapm_up_seq);
Mark Brown6d3ddc82009-05-16 17:47:29 +0100936 else
Mark Brown291f3bb2009-06-07 13:57:17 +0100937 dapm_seq_insert(w, &down_list, dapm_down_seq);
Mark Brown6d3ddc82009-05-16 17:47:29 +0100938
939 w->power = power;
940 break;
941 }
Richard Purdie2b97eab2006-10-06 18:32:18 +0200942 }
943
Mark Brownb14b76a2009-08-17 11:55:38 +0100944 /* If there are no DAPM widgets then try to figure out power from the
945 * event type.
946 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200947 if (list_empty(&dapm->widgets)) {
Mark Brownb14b76a2009-08-17 11:55:38 +0100948 switch (event) {
949 case SND_SOC_DAPM_STREAM_START:
950 case SND_SOC_DAPM_STREAM_RESUME:
951 sys_power = 1;
952 break;
Mark Brown50b6bce2009-11-23 13:11:53 +0000953 case SND_SOC_DAPM_STREAM_SUSPEND:
954 sys_power = 0;
955 break;
Mark Brownb14b76a2009-08-17 11:55:38 +0100956 case SND_SOC_DAPM_STREAM_NOP:
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200957 switch (dapm->bias_level) {
Mark Browna96ca332010-01-19 22:49:43 +0000958 case SND_SOC_BIAS_STANDBY:
959 case SND_SOC_BIAS_OFF:
960 sys_power = 0;
961 break;
962 default:
963 sys_power = 1;
964 break;
965 }
Mark Brown50b6bce2009-11-23 13:11:53 +0000966 break;
Mark Brownb14b76a2009-08-17 11:55:38 +0100967 default:
968 break;
969 }
970 }
971
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200972 if (sys_power && dapm->bias_level == SND_SOC_BIAS_OFF) {
973 ret = snd_soc_dapm_set_bias_level(card, dapm,
Mark Browna96ca332010-01-19 22:49:43 +0000974 SND_SOC_BIAS_STANDBY);
975 if (ret != 0)
976 pr_err("Failed to turn on bias: %d\n", ret);
977 }
978
Mark Brown452c5ea2009-05-17 21:41:23 +0100979 /* If we're changing to all on or all off then prepare */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200980 if ((sys_power && dapm->bias_level == SND_SOC_BIAS_STANDBY) ||
981 (!sys_power && dapm->bias_level == SND_SOC_BIAS_ON)) {
982 ret = snd_soc_dapm_set_bias_level(card, dapm, SND_SOC_BIAS_PREPARE);
Mark Brown452c5ea2009-05-17 21:41:23 +0100983 if (ret != 0)
984 pr_err("Failed to prepare bias: %d\n", ret);
985 }
986
Mark Brown6d3ddc82009-05-16 17:47:29 +0100987 /* Power down widgets first; try to avoid amplifying pops. */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200988 dapm_seq_run(dapm, &down_list, event, dapm_down_seq);
Mark Brown6d3ddc82009-05-16 17:47:29 +0100989
990 /* Now power up. */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200991 dapm_seq_run(dapm, &up_list, event, dapm_up_seq);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200992
Mark Brown452c5ea2009-05-17 21:41:23 +0100993 /* If we just powered the last thing off drop to standby bias */
Liam Girdwoodce6120c2010-11-05 15:53:46 +0200994 if (dapm->bias_level == SND_SOC_BIAS_PREPARE && !sys_power) {
995 ret = snd_soc_dapm_set_bias_level(card, dapm, SND_SOC_BIAS_STANDBY);
Mark Brown452c5ea2009-05-17 21:41:23 +0100996 if (ret != 0)
997 pr_err("Failed to apply standby bias: %d\n", ret);
998 }
999
Mark Browna96ca332010-01-19 22:49:43 +00001000 /* If we're in standby and can support bias off then do that */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001001 if (dapm->bias_level == SND_SOC_BIAS_STANDBY &&
1002 dapm->idle_bias_off) {
1003 ret = snd_soc_dapm_set_bias_level(card, dapm, SND_SOC_BIAS_OFF);
Mark Browna96ca332010-01-19 22:49:43 +00001004 if (ret != 0)
1005 pr_err("Failed to turn off bias: %d\n", ret);
1006 }
1007
Mark Brown452c5ea2009-05-17 21:41:23 +01001008 /* If we just powered up then move to active bias */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001009 if (dapm->bias_level == SND_SOC_BIAS_PREPARE && sys_power) {
1010 ret = snd_soc_dapm_set_bias_level(card, dapm, SND_SOC_BIAS_ON);
Mark Brown452c5ea2009-05-17 21:41:23 +01001011 if (ret != 0)
1012 pr_err("Failed to apply active bias: %d\n", ret);
1013 }
1014
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001015 pop_dbg(dapm->pop_time, "DAPM sequencing finished, waiting %dms\n",
1016 dapm->pop_time);
1017 pop_wait(dapm->pop_time);
Mark Browncb507e72009-07-08 18:54:57 +01001018
Mark Brown42aa3412009-03-01 19:21:10 +00001019 return 0;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001020}
1021
Mark Brown79fb9382009-08-21 16:38:13 +01001022#ifdef CONFIG_DEBUG_FS
1023static int dapm_widget_power_open_file(struct inode *inode, struct file *file)
1024{
1025 file->private_data = inode->i_private;
1026 return 0;
1027}
1028
1029static ssize_t dapm_widget_power_read_file(struct file *file,
1030 char __user *user_buf,
1031 size_t count, loff_t *ppos)
1032{
1033 struct snd_soc_dapm_widget *w = file->private_data;
1034 char *buf;
1035 int in, out;
1036 ssize_t ret;
1037 struct snd_soc_dapm_path *p = NULL;
1038
1039 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1040 if (!buf)
1041 return -ENOMEM;
1042
1043 in = is_connected_input_ep(w);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001044 dapm_clear_walk(w->dapm);
Mark Brown79fb9382009-08-21 16:38:13 +01001045 out = is_connected_output_ep(w);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001046 dapm_clear_walk(w->dapm);
Mark Brown79fb9382009-08-21 16:38:13 +01001047
Mark Brownd033c362009-12-04 15:25:56 +00001048 ret = snprintf(buf, PAGE_SIZE, "%s: %s in %d out %d",
Mark Brown79fb9382009-08-21 16:38:13 +01001049 w->name, w->power ? "On" : "Off", in, out);
1050
Mark Brownd033c362009-12-04 15:25:56 +00001051 if (w->reg >= 0)
1052 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1053 " - R%d(0x%x) bit %d",
1054 w->reg, w->reg, w->shift);
1055
1056 ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
1057
Mark Brown3eef08b2009-09-14 16:49:00 +01001058 if (w->sname)
1059 ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
1060 w->sname,
1061 w->active ? "active" : "inactive");
Mark Brown79fb9382009-08-21 16:38:13 +01001062
1063 list_for_each_entry(p, &w->sources, list_sink) {
Mark Brown215edda2009-09-08 18:59:05 +01001064 if (p->connected && !p->connected(w, p->sink))
1065 continue;
1066
Mark Brown79fb9382009-08-21 16:38:13 +01001067 if (p->connect)
1068 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1069 " in %s %s\n",
1070 p->name ? p->name : "static",
1071 p->source->name);
1072 }
1073 list_for_each_entry(p, &w->sinks, list_source) {
Mark Brown215edda2009-09-08 18:59:05 +01001074 if (p->connected && !p->connected(w, p->sink))
1075 continue;
1076
Mark Brown79fb9382009-08-21 16:38:13 +01001077 if (p->connect)
1078 ret += snprintf(buf + ret, PAGE_SIZE - ret,
1079 " out %s %s\n",
1080 p->name ? p->name : "static",
1081 p->sink->name);
1082 }
1083
1084 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1085
1086 kfree(buf);
1087 return ret;
1088}
1089
1090static const struct file_operations dapm_widget_power_fops = {
1091 .open = dapm_widget_power_open_file,
1092 .read = dapm_widget_power_read_file,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001093 .llseek = default_llseek,
Mark Brown79fb9382009-08-21 16:38:13 +01001094};
1095
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001096void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm)
Mark Brown79fb9382009-08-21 16:38:13 +01001097{
1098 struct snd_soc_dapm_widget *w;
1099 struct dentry *d;
1100
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001101 if (!dapm->debugfs_dapm)
Mark Brown79fb9382009-08-21 16:38:13 +01001102 return;
1103
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001104 list_for_each_entry(w, &dapm->widgets, list) {
Mark Brown79fb9382009-08-21 16:38:13 +01001105 if (!w->name)
1106 continue;
1107
1108 d = debugfs_create_file(w->name, 0444,
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001109 dapm->debugfs_dapm, w,
Mark Brown79fb9382009-08-21 16:38:13 +01001110 &dapm_widget_power_fops);
1111 if (!d)
1112 printk(KERN_WARNING
1113 "ASoC: Failed to create %s debugfs file\n",
1114 w->name);
1115 }
1116}
1117#else
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001118void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm)
Mark Brown79fb9382009-08-21 16:38:13 +01001119{
1120}
1121#endif
1122
Richard Purdie2b97eab2006-10-06 18:32:18 +02001123/* test and update the power status of a mux widget */
Adrian Bunkd9c96cf2006-11-28 12:10:09 +01001124static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
Mark Brown3a655772009-10-05 17:23:30 +01001125 struct snd_kcontrol *kcontrol, int change,
1126 int mux, struct soc_enum *e)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001127{
1128 struct snd_soc_dapm_path *path;
1129 int found = 0;
1130
Peter Ujfalusieff317d2009-01-15 14:40:47 +02001131 if (widget->id != snd_soc_dapm_mux &&
1132 widget->id != snd_soc_dapm_value_mux)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001133 return -ENODEV;
1134
Mark Brown3a655772009-10-05 17:23:30 +01001135 if (!change)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001136 return 0;
1137
1138 /* find dapm widget path assoc with kcontrol */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001139 list_for_each_entry(path, &widget->dapm->paths, list) {
Richard Purdie2b97eab2006-10-06 18:32:18 +02001140 if (path->kcontrol != kcontrol)
1141 continue;
1142
Richard Zhaocb01e2b2008-10-07 08:05:20 +08001143 if (!path->name || !e->texts[mux])
Richard Purdie2b97eab2006-10-06 18:32:18 +02001144 continue;
1145
1146 found = 1;
1147 /* we now need to match the string in the enum to the path */
Richard Zhaocb01e2b2008-10-07 08:05:20 +08001148 if (!(strcmp(path->name, e->texts[mux])))
Richard Purdie2b97eab2006-10-06 18:32:18 +02001149 path->connect = 1; /* new connection */
1150 else
1151 path->connect = 0; /* old connection must be powered down */
1152 }
1153
Mark Brownb91b8fa2010-01-20 18:18:35 +00001154 if (found)
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001155 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001156
1157 return 0;
1158}
Richard Purdie2b97eab2006-10-06 18:32:18 +02001159
Milan plzik1b075e32008-01-10 14:39:46 +01001160/* test and update the power status of a mixer or switch widget */
Adrian Bunkd9c96cf2006-11-28 12:10:09 +01001161static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
Mark Brown283375c2009-12-07 18:09:03 +00001162 struct snd_kcontrol *kcontrol, int connect)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001163{
1164 struct snd_soc_dapm_path *path;
1165 int found = 0;
1166
Milan plzik1b075e32008-01-10 14:39:46 +01001167 if (widget->id != snd_soc_dapm_mixer &&
Ian Moltonca9c1aa2009-01-06 20:11:51 +00001168 widget->id != snd_soc_dapm_mixer_named_ctl &&
Milan plzik1b075e32008-01-10 14:39:46 +01001169 widget->id != snd_soc_dapm_switch)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001170 return -ENODEV;
1171
Richard Purdie2b97eab2006-10-06 18:32:18 +02001172 /* find dapm widget path assoc with kcontrol */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001173 list_for_each_entry(path, &widget->dapm->paths, list) {
Richard Purdie2b97eab2006-10-06 18:32:18 +02001174 if (path->kcontrol != kcontrol)
1175 continue;
1176
1177 /* found, now check type */
1178 found = 1;
Mark Brown283375c2009-12-07 18:09:03 +00001179 path->connect = connect;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001180 break;
1181 }
1182
Mark Brownb91b8fa2010-01-20 18:18:35 +00001183 if (found)
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001184 dapm_power_widgets(widget->dapm, SND_SOC_DAPM_STREAM_NOP);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001185
1186 return 0;
1187}
Richard Purdie2b97eab2006-10-06 18:32:18 +02001188
1189/* show dapm widget status in sys fs */
1190static ssize_t dapm_widget_show(struct device *dev,
1191 struct device_attribute *attr, char *buf)
1192{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001193 struct snd_soc_pcm_runtime *rtd =
1194 container_of(dev, struct snd_soc_pcm_runtime, dev);
1195 struct snd_soc_codec *codec =rtd->codec;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001196 struct snd_soc_dapm_widget *w;
1197 int count = 0;
1198 char *state = "not set";
1199
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001200 list_for_each_entry(w, &codec->dapm.widgets, list) {
Richard Purdie2b97eab2006-10-06 18:32:18 +02001201
1202 /* only display widgets that burnm power */
1203 switch (w->id) {
1204 case snd_soc_dapm_hp:
1205 case snd_soc_dapm_mic:
1206 case snd_soc_dapm_spk:
1207 case snd_soc_dapm_line:
1208 case snd_soc_dapm_micbias:
1209 case snd_soc_dapm_dac:
1210 case snd_soc_dapm_adc:
1211 case snd_soc_dapm_pga:
1212 case snd_soc_dapm_mixer:
Ian Moltonca9c1aa2009-01-06 20:11:51 +00001213 case snd_soc_dapm_mixer_named_ctl:
Mark Brown246d0a12009-04-22 18:24:55 +01001214 case snd_soc_dapm_supply:
Richard Purdie2b97eab2006-10-06 18:32:18 +02001215 if (w->name)
1216 count += sprintf(buf + count, "%s: %s\n",
1217 w->name, w->power ? "On":"Off");
1218 break;
1219 default:
1220 break;
1221 }
1222 }
1223
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001224 switch (codec->dapm.bias_level) {
Mark Brown0be98982008-05-19 12:31:28 +02001225 case SND_SOC_BIAS_ON:
1226 state = "On";
Richard Purdie2b97eab2006-10-06 18:32:18 +02001227 break;
Mark Brown0be98982008-05-19 12:31:28 +02001228 case SND_SOC_BIAS_PREPARE:
1229 state = "Prepare";
Richard Purdie2b97eab2006-10-06 18:32:18 +02001230 break;
Mark Brown0be98982008-05-19 12:31:28 +02001231 case SND_SOC_BIAS_STANDBY:
1232 state = "Standby";
Richard Purdie2b97eab2006-10-06 18:32:18 +02001233 break;
Mark Brown0be98982008-05-19 12:31:28 +02001234 case SND_SOC_BIAS_OFF:
1235 state = "Off";
Richard Purdie2b97eab2006-10-06 18:32:18 +02001236 break;
1237 }
1238 count += sprintf(buf + count, "PM State: %s\n", state);
1239
1240 return count;
1241}
1242
1243static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
1244
1245int snd_soc_dapm_sys_add(struct device *dev)
1246{
Troy Kisky12ef1932008-10-13 17:42:14 -07001247 return device_create_file(dev, &dev_attr_dapm_widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001248}
1249
1250static void snd_soc_dapm_sys_remove(struct device *dev)
1251{
Mark Brownaef90842009-05-16 17:53:16 +01001252 device_remove_file(dev, &dev_attr_dapm_widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001253}
1254
1255/* free all dapm widgets and resources */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001256static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001257{
1258 struct snd_soc_dapm_widget *w, *next_w;
1259 struct snd_soc_dapm_path *p, *next_p;
1260
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001261 list_for_each_entry_safe(w, next_w, &dapm->widgets, list) {
Richard Purdie2b97eab2006-10-06 18:32:18 +02001262 list_del(&w->list);
1263 kfree(w);
1264 }
1265
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001266 list_for_each_entry_safe(p, next_p, &dapm->paths, list) {
Richard Purdie2b97eab2006-10-06 18:32:18 +02001267 list_del(&p->list);
1268 kfree(p->long_name);
1269 kfree(p);
1270 }
1271}
1272
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001273static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
Mark Brown16499232009-01-07 18:25:13 +00001274 const char *pin, int status)
Liam Girdwooda5302182008-07-07 13:35:17 +01001275{
1276 struct snd_soc_dapm_widget *w;
1277
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001278 list_for_each_entry(w, &dapm->widgets, list) {
Liam Girdwooda5302182008-07-07 13:35:17 +01001279 if (!strcmp(w->name, pin)) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001280 pr_debug("dapm: %s: pin %s\n", dapm->codec->name, pin);
Liam Girdwooda5302182008-07-07 13:35:17 +01001281 w->connected = status;
Mark Brown5b9e87c2010-03-22 13:36:13 +00001282 /* Allow disabling of forced pins */
1283 if (status == 0)
1284 w->force = 0;
Liam Girdwooda5302182008-07-07 13:35:17 +01001285 return 0;
1286 }
1287 }
1288
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001289 pr_err("dapm: %s: configuring unknown pin %s\n",
1290 dapm->codec->name, pin);
Liam Girdwooda5302182008-07-07 13:35:17 +01001291 return -EINVAL;
1292}
1293
Richard Purdie2b97eab2006-10-06 18:32:18 +02001294/**
Liam Girdwooda5302182008-07-07 13:35:17 +01001295 * snd_soc_dapm_sync - scan and power dapm paths
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001296 * @dapm: DAPM context
Richard Purdie2b97eab2006-10-06 18:32:18 +02001297 *
1298 * Walks all dapm audio paths and powers widgets according to their
1299 * stream or path usage.
1300 *
1301 * Returns 0 for success.
1302 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001303int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001304{
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001305 return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001306}
Liam Girdwooda5302182008-07-07 13:35:17 +01001307EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001308
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001309static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
Mark Brown215edda2009-09-08 18:59:05 +01001310 const struct snd_soc_dapm_route *route)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001311{
1312 struct snd_soc_dapm_path *path;
1313 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
Mark Brown215edda2009-09-08 18:59:05 +01001314 const char *sink = route->sink;
1315 const char *control = route->control;
1316 const char *source = route->source;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001317 int ret = 0;
1318
1319 /* find src and dest widgets */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001320 list_for_each_entry(w, &dapm->widgets, list) {
Richard Purdie2b97eab2006-10-06 18:32:18 +02001321
1322 if (!wsink && !(strcmp(w->name, sink))) {
1323 wsink = w;
1324 continue;
1325 }
1326 if (!wsource && !(strcmp(w->name, source))) {
1327 wsource = w;
1328 }
1329 }
1330
1331 if (wsource == NULL || wsink == NULL)
1332 return -ENODEV;
1333
1334 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
1335 if (!path)
1336 return -ENOMEM;
1337
1338 path->source = wsource;
1339 path->sink = wsink;
Mark Brown215edda2009-09-08 18:59:05 +01001340 path->connected = route->connected;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001341 INIT_LIST_HEAD(&path->list);
1342 INIT_LIST_HEAD(&path->list_source);
1343 INIT_LIST_HEAD(&path->list_sink);
1344
1345 /* check for external widgets */
1346 if (wsink->id == snd_soc_dapm_input) {
1347 if (wsource->id == snd_soc_dapm_micbias ||
1348 wsource->id == snd_soc_dapm_mic ||
Rongrong Cao087d53a2009-07-10 20:13:30 +01001349 wsource->id == snd_soc_dapm_line ||
1350 wsource->id == snd_soc_dapm_output)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001351 wsink->ext = 1;
1352 }
1353 if (wsource->id == snd_soc_dapm_output) {
1354 if (wsink->id == snd_soc_dapm_spk ||
1355 wsink->id == snd_soc_dapm_hp ||
Seth Forshee1e392212007-04-16 15:36:42 +02001356 wsink->id == snd_soc_dapm_line ||
1357 wsink->id == snd_soc_dapm_input)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001358 wsource->ext = 1;
1359 }
1360
1361 /* connect static paths */
1362 if (control == NULL) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001363 list_add(&path->list, &dapm->paths);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001364 list_add(&path->list_sink, &wsink->sources);
1365 list_add(&path->list_source, &wsource->sinks);
1366 path->connect = 1;
1367 return 0;
1368 }
1369
1370 /* connect dynamic paths */
1371 switch(wsink->id) {
1372 case snd_soc_dapm_adc:
1373 case snd_soc_dapm_dac:
1374 case snd_soc_dapm_pga:
1375 case snd_soc_dapm_input:
1376 case snd_soc_dapm_output:
1377 case snd_soc_dapm_micbias:
1378 case snd_soc_dapm_vmid:
1379 case snd_soc_dapm_pre:
1380 case snd_soc_dapm_post:
Mark Brown246d0a12009-04-22 18:24:55 +01001381 case snd_soc_dapm_supply:
Mark Brown010ff262009-08-17 17:39:22 +01001382 case snd_soc_dapm_aif_in:
1383 case snd_soc_dapm_aif_out:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001384 list_add(&path->list, &dapm->paths);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001385 list_add(&path->list_sink, &wsink->sources);
1386 list_add(&path->list_source, &wsource->sinks);
1387 path->connect = 1;
1388 return 0;
1389 case snd_soc_dapm_mux:
Peter Ujfalusi74155552009-01-08 13:34:29 +02001390 case snd_soc_dapm_value_mux:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001391 ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
Richard Purdie2b97eab2006-10-06 18:32:18 +02001392 &wsink->kcontrols[0]);
1393 if (ret != 0)
1394 goto err;
1395 break;
1396 case snd_soc_dapm_switch:
1397 case snd_soc_dapm_mixer:
Ian Moltonca9c1aa2009-01-06 20:11:51 +00001398 case snd_soc_dapm_mixer_named_ctl:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001399 ret = dapm_connect_mixer(dapm, wsource, wsink, path, control);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001400 if (ret != 0)
1401 goto err;
1402 break;
1403 case snd_soc_dapm_hp:
1404 case snd_soc_dapm_mic:
1405 case snd_soc_dapm_line:
1406 case snd_soc_dapm_spk:
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001407 list_add(&path->list, &dapm->paths);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001408 list_add(&path->list_sink, &wsink->sources);
1409 list_add(&path->list_source, &wsource->sinks);
1410 path->connect = 0;
1411 return 0;
1412 }
1413 return 0;
1414
1415err:
1416 printk(KERN_WARNING "asoc: no dapm match for %s --> %s --> %s\n", source,
1417 control, sink);
1418 kfree(path);
1419 return ret;
1420}
Mark Brown105f1c22008-05-13 14:52:19 +02001421
1422/**
Mark Brown105f1c22008-05-13 14:52:19 +02001423 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001424 * @dapm: DAPM context
Mark Brown105f1c22008-05-13 14:52:19 +02001425 * @route: audio routes
1426 * @num: number of routes
1427 *
1428 * Connects 2 dapm widgets together via a named audio path. The sink is
1429 * the widget receiving the audio signal, whilst the source is the sender
1430 * of the audio signal.
1431 *
1432 * Returns 0 for success else error. On error all resources can be freed
1433 * with a call to snd_soc_card_free().
1434 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001435int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
Mark Brown105f1c22008-05-13 14:52:19 +02001436 const struct snd_soc_dapm_route *route, int num)
1437{
1438 int i, ret;
1439
1440 for (i = 0; i < num; i++) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001441 ret = snd_soc_dapm_add_route(dapm, route);
Mark Brown105f1c22008-05-13 14:52:19 +02001442 if (ret < 0) {
1443 printk(KERN_ERR "Failed to add route %s->%s\n",
1444 route->source,
1445 route->sink);
1446 return ret;
1447 }
1448 route++;
1449 }
1450
1451 return 0;
1452}
1453EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
1454
1455/**
Richard Purdie2b97eab2006-10-06 18:32:18 +02001456 * snd_soc_dapm_new_widgets - add new dapm widgets
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001457 * @dapm: DAPM context
Richard Purdie2b97eab2006-10-06 18:32:18 +02001458 *
1459 * Checks the codec for any new dapm widgets and creates them if found.
1460 *
1461 * Returns 0 for success.
1462 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001463int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001464{
1465 struct snd_soc_dapm_widget *w;
1466
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001467 list_for_each_entry(w, &dapm->widgets, list)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001468 {
1469 if (w->new)
1470 continue;
1471
1472 switch(w->id) {
1473 case snd_soc_dapm_switch:
1474 case snd_soc_dapm_mixer:
Ian Moltonca9c1aa2009-01-06 20:11:51 +00001475 case snd_soc_dapm_mixer_named_ctl:
Mark Brownb75576d2009-04-20 17:56:13 +01001476 w->power_check = dapm_generic_check_power;
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001477 dapm_new_mixer(dapm, w);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001478 break;
1479 case snd_soc_dapm_mux:
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001480 case snd_soc_dapm_value_mux:
Mark Brownb75576d2009-04-20 17:56:13 +01001481 w->power_check = dapm_generic_check_power;
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001482 dapm_new_mux(dapm, w);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001483 break;
1484 case snd_soc_dapm_adc:
Mark Brown010ff262009-08-17 17:39:22 +01001485 case snd_soc_dapm_aif_out:
Mark Brownb75576d2009-04-20 17:56:13 +01001486 w->power_check = dapm_adc_check_power;
1487 break;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001488 case snd_soc_dapm_dac:
Mark Brown010ff262009-08-17 17:39:22 +01001489 case snd_soc_dapm_aif_in:
Mark Brownb75576d2009-04-20 17:56:13 +01001490 w->power_check = dapm_dac_check_power;
1491 break;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001492 case snd_soc_dapm_pga:
Mark Brownb75576d2009-04-20 17:56:13 +01001493 w->power_check = dapm_generic_check_power;
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001494 dapm_new_pga(dapm, w);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001495 break;
1496 case snd_soc_dapm_input:
1497 case snd_soc_dapm_output:
1498 case snd_soc_dapm_micbias:
1499 case snd_soc_dapm_spk:
1500 case snd_soc_dapm_hp:
1501 case snd_soc_dapm_mic:
1502 case snd_soc_dapm_line:
Mark Brownb75576d2009-04-20 17:56:13 +01001503 w->power_check = dapm_generic_check_power;
1504 break;
Mark Brown246d0a12009-04-22 18:24:55 +01001505 case snd_soc_dapm_supply:
1506 w->power_check = dapm_supply_check_power;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001507 case snd_soc_dapm_vmid:
1508 case snd_soc_dapm_pre:
1509 case snd_soc_dapm_post:
1510 break;
1511 }
1512 w->new = 1;
1513 }
1514
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001515 dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001516 return 0;
1517}
1518EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
1519
1520/**
1521 * snd_soc_dapm_get_volsw - dapm mixer get callback
1522 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00001523 * @ucontrol: control element information
Richard Purdie2b97eab2006-10-06 18:32:18 +02001524 *
1525 * Callback to get the value of a dapm mixer control.
1526 *
1527 * Returns 0 for success.
1528 */
1529int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
1530 struct snd_ctl_elem_value *ucontrol)
1531{
1532 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
Jon Smirl4eaa9812008-07-29 11:42:26 +01001533 struct soc_mixer_control *mc =
1534 (struct soc_mixer_control *)kcontrol->private_value;
Jon Smirl815ecf82008-07-29 10:22:24 -04001535 unsigned int reg = mc->reg;
1536 unsigned int shift = mc->shift;
1537 unsigned int rshift = mc->rshift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01001538 int max = mc->max;
Jon Smirl815ecf82008-07-29 10:22:24 -04001539 unsigned int invert = mc->invert;
1540 unsigned int mask = (1 << fls(max)) - 1;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001541
Richard Purdie2b97eab2006-10-06 18:32:18 +02001542 ucontrol->value.integer.value[0] =
1543 (snd_soc_read(widget->codec, reg) >> shift) & mask;
1544 if (shift != rshift)
1545 ucontrol->value.integer.value[1] =
1546 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
1547 if (invert) {
1548 ucontrol->value.integer.value[0] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001549 max - ucontrol->value.integer.value[0];
Richard Purdie2b97eab2006-10-06 18:32:18 +02001550 if (shift != rshift)
1551 ucontrol->value.integer.value[1] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001552 max - ucontrol->value.integer.value[1];
Richard Purdie2b97eab2006-10-06 18:32:18 +02001553 }
1554
1555 return 0;
1556}
1557EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
1558
1559/**
1560 * snd_soc_dapm_put_volsw - dapm mixer set callback
1561 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00001562 * @ucontrol: control element information
Richard Purdie2b97eab2006-10-06 18:32:18 +02001563 *
1564 * Callback to set the value of a dapm mixer control.
1565 *
1566 * Returns 0 for success.
1567 */
1568int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
1569 struct snd_ctl_elem_value *ucontrol)
1570{
1571 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
Jon Smirl4eaa9812008-07-29 11:42:26 +01001572 struct soc_mixer_control *mc =
1573 (struct soc_mixer_control *)kcontrol->private_value;
Jon Smirl815ecf82008-07-29 10:22:24 -04001574 unsigned int reg = mc->reg;
1575 unsigned int shift = mc->shift;
1576 unsigned int rshift = mc->rshift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01001577 int max = mc->max;
Jon Smirl815ecf82008-07-29 10:22:24 -04001578 unsigned int mask = (1 << fls(max)) - 1;
1579 unsigned int invert = mc->invert;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001580 unsigned int val, val2, val_mask;
Mark Brown283375c2009-12-07 18:09:03 +00001581 int connect;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001582 int ret;
1583
1584 val = (ucontrol->value.integer.value[0] & mask);
1585
1586 if (invert)
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001587 val = max - val;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001588 val_mask = mask << shift;
1589 val = val << shift;
1590 if (shift != rshift) {
1591 val2 = (ucontrol->value.integer.value[1] & mask);
1592 if (invert)
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001593 val2 = max - val2;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001594 val_mask |= mask << rshift;
1595 val |= val2 << rshift;
1596 }
1597
1598 mutex_lock(&widget->codec->mutex);
1599 widget->value = val;
1600
Mark Brown283375c2009-12-07 18:09:03 +00001601 if (snd_soc_test_bits(widget->codec, reg, val_mask, val)) {
1602 if (val)
1603 /* new connection */
1604 connect = invert ? 0:1;
1605 else
1606 /* old connection must be powered down */
1607 connect = invert ? 1:0;
1608
1609 dapm_mixer_update_power(widget, kcontrol, connect);
1610 }
1611
Richard Purdie2b97eab2006-10-06 18:32:18 +02001612 if (widget->event) {
1613 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
Laim Girdwood9af6d952008-01-10 14:41:02 +01001614 ret = widget->event(widget, kcontrol,
1615 SND_SOC_DAPM_PRE_REG);
1616 if (ret < 0) {
1617 ret = 1;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001618 goto out;
Laim Girdwood9af6d952008-01-10 14:41:02 +01001619 }
Richard Purdie2b97eab2006-10-06 18:32:18 +02001620 }
1621 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1622 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
Laim Girdwood9af6d952008-01-10 14:41:02 +01001623 ret = widget->event(widget, kcontrol,
1624 SND_SOC_DAPM_POST_REG);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001625 } else
1626 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1627
1628out:
1629 mutex_unlock(&widget->codec->mutex);
1630 return ret;
1631}
1632EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
1633
1634/**
1635 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
1636 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00001637 * @ucontrol: control element information
Richard Purdie2b97eab2006-10-06 18:32:18 +02001638 *
1639 * Callback to get the value of a dapm enumerated double mixer control.
1640 *
1641 * Returns 0 for success.
1642 */
1643int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
1644 struct snd_ctl_elem_value *ucontrol)
1645{
1646 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1647 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001648 unsigned int val, bitmask;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001649
Jon Smirlf8ba0b7b2008-07-29 11:42:27 +01001650 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001651 ;
1652 val = snd_soc_read(widget->codec, e->reg);
1653 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
1654 if (e->shift_l != e->shift_r)
1655 ucontrol->value.enumerated.item[1] =
1656 (val >> e->shift_r) & (bitmask - 1);
1657
1658 return 0;
1659}
1660EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
1661
1662/**
1663 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
1664 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00001665 * @ucontrol: control element information
Richard Purdie2b97eab2006-10-06 18:32:18 +02001666 *
1667 * Callback to set the value of a dapm enumerated double mixer control.
1668 *
1669 * Returns 0 for success.
1670 */
1671int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
1672 struct snd_ctl_elem_value *ucontrol)
1673{
1674 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1675 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Mark Brown3a655772009-10-05 17:23:30 +01001676 unsigned int val, mux, change;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001677 unsigned int mask, bitmask;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001678 int ret = 0;
1679
Jon Smirlf8ba0b7b2008-07-29 11:42:27 +01001680 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001681 ;
Jon Smirlf8ba0b7b2008-07-29 11:42:27 +01001682 if (ucontrol->value.enumerated.item[0] > e->max - 1)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001683 return -EINVAL;
1684 mux = ucontrol->value.enumerated.item[0];
1685 val = mux << e->shift_l;
1686 mask = (bitmask - 1) << e->shift_l;
1687 if (e->shift_l != e->shift_r) {
Jon Smirlf8ba0b7b2008-07-29 11:42:27 +01001688 if (ucontrol->value.enumerated.item[1] > e->max - 1)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001689 return -EINVAL;
1690 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1691 mask |= (bitmask - 1) << e->shift_r;
1692 }
1693
1694 mutex_lock(&widget->codec->mutex);
1695 widget->value = val;
Mark Brown3a655772009-10-05 17:23:30 +01001696 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
1697 dapm_mux_update_power(widget, kcontrol, change, mux, e);
Mark Brown1642e3d2009-10-05 16:24:26 +01001698
1699 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1700 ret = widget->event(widget,
1701 kcontrol, SND_SOC_DAPM_PRE_REG);
1702 if (ret < 0)
1703 goto out;
1704 }
1705
1706 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1707
1708 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1709 ret = widget->event(widget,
1710 kcontrol, SND_SOC_DAPM_POST_REG);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001711
1712out:
1713 mutex_unlock(&widget->codec->mutex);
1714 return ret;
1715}
1716EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
1717
1718/**
Mark Brownd2b247a2009-10-06 15:21:04 +01001719 * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
1720 * @kcontrol: mixer control
1721 * @ucontrol: control element information
1722 *
1723 * Returns 0 for success.
1724 */
1725int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
1726 struct snd_ctl_elem_value *ucontrol)
1727{
1728 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1729
1730 ucontrol->value.enumerated.item[0] = widget->value;
1731
1732 return 0;
1733}
1734EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
1735
1736/**
1737 * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
1738 * @kcontrol: mixer control
1739 * @ucontrol: control element information
1740 *
1741 * Returns 0 for success.
1742 */
1743int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
1744 struct snd_ctl_elem_value *ucontrol)
1745{
1746 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1747 struct soc_enum *e =
1748 (struct soc_enum *)kcontrol->private_value;
1749 int change;
1750 int ret = 0;
1751
1752 if (ucontrol->value.enumerated.item[0] >= e->max)
1753 return -EINVAL;
1754
1755 mutex_lock(&widget->codec->mutex);
1756
1757 change = widget->value != ucontrol->value.enumerated.item[0];
1758 widget->value = ucontrol->value.enumerated.item[0];
1759 dapm_mux_update_power(widget, kcontrol, change, widget->value, e);
1760
1761 mutex_unlock(&widget->codec->mutex);
1762 return ret;
1763}
1764EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
1765
1766/**
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001767 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
1768 * callback
1769 * @kcontrol: mixer control
1770 * @ucontrol: control element information
1771 *
1772 * Callback to get the value of a dapm semi enumerated double mixer control.
1773 *
1774 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1775 * used for handling bitfield coded enumeration for example.
1776 *
1777 * Returns 0 for success.
1778 */
1779int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
1780 struct snd_ctl_elem_value *ucontrol)
1781{
1782 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
Peter Ujfalusi74155552009-01-08 13:34:29 +02001783 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001784 unsigned int reg_val, val, mux;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001785
1786 reg_val = snd_soc_read(widget->codec, e->reg);
1787 val = (reg_val >> e->shift_l) & e->mask;
1788 for (mux = 0; mux < e->max; mux++) {
1789 if (val == e->values[mux])
1790 break;
1791 }
1792 ucontrol->value.enumerated.item[0] = mux;
1793 if (e->shift_l != e->shift_r) {
1794 val = (reg_val >> e->shift_r) & e->mask;
1795 for (mux = 0; mux < e->max; mux++) {
1796 if (val == e->values[mux])
1797 break;
1798 }
1799 ucontrol->value.enumerated.item[1] = mux;
1800 }
1801
1802 return 0;
1803}
1804EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
1805
1806/**
1807 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
1808 * callback
1809 * @kcontrol: mixer control
1810 * @ucontrol: control element information
1811 *
1812 * Callback to set the value of a dapm semi enumerated double mixer control.
1813 *
1814 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1815 * used for handling bitfield coded enumeration for example.
1816 *
1817 * Returns 0 for success.
1818 */
1819int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
1820 struct snd_ctl_elem_value *ucontrol)
1821{
1822 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
Peter Ujfalusi74155552009-01-08 13:34:29 +02001823 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
Mark Brown3a655772009-10-05 17:23:30 +01001824 unsigned int val, mux, change;
Daniel Ribeiro46f58222009-06-07 02:49:11 -03001825 unsigned int mask;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001826 int ret = 0;
1827
1828 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1829 return -EINVAL;
1830 mux = ucontrol->value.enumerated.item[0];
1831 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
1832 mask = e->mask << e->shift_l;
1833 if (e->shift_l != e->shift_r) {
1834 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1835 return -EINVAL;
1836 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
1837 mask |= e->mask << e->shift_r;
1838 }
1839
1840 mutex_lock(&widget->codec->mutex);
1841 widget->value = val;
Mark Brown3a655772009-10-05 17:23:30 +01001842 change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
1843 dapm_mux_update_power(widget, kcontrol, change, mux, e);
Mark Brown1642e3d2009-10-05 16:24:26 +01001844
1845 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1846 ret = widget->event(widget,
1847 kcontrol, SND_SOC_DAPM_PRE_REG);
1848 if (ret < 0)
1849 goto out;
1850 }
1851
1852 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1853
1854 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1855 ret = widget->event(widget,
1856 kcontrol, SND_SOC_DAPM_POST_REG);
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001857
1858out:
1859 mutex_unlock(&widget->codec->mutex);
1860 return ret;
1861}
1862EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
1863
1864/**
Mark Brown8b37dbd2009-02-28 21:14:20 +00001865 * snd_soc_dapm_info_pin_switch - Info for a pin switch
1866 *
1867 * @kcontrol: mixer control
1868 * @uinfo: control element information
1869 *
1870 * Callback to provide information about a pin switch control.
1871 */
1872int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
1873 struct snd_ctl_elem_info *uinfo)
1874{
1875 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1876 uinfo->count = 1;
1877 uinfo->value.integer.min = 0;
1878 uinfo->value.integer.max = 1;
1879
1880 return 0;
1881}
1882EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
1883
1884/**
1885 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
1886 *
1887 * @kcontrol: mixer control
1888 * @ucontrol: Value
1889 */
1890int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
1891 struct snd_ctl_elem_value *ucontrol)
1892{
1893 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1894 const char *pin = (const char *)kcontrol->private_value;
1895
1896 mutex_lock(&codec->mutex);
1897
1898 ucontrol->value.integer.value[0] =
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001899 snd_soc_dapm_get_pin_status(&codec->dapm, pin);
Mark Brown8b37dbd2009-02-28 21:14:20 +00001900
1901 mutex_unlock(&codec->mutex);
1902
1903 return 0;
1904}
1905EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
1906
1907/**
1908 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
1909 *
1910 * @kcontrol: mixer control
1911 * @ucontrol: Value
1912 */
1913int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
1914 struct snd_ctl_elem_value *ucontrol)
1915{
1916 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1917 const char *pin = (const char *)kcontrol->private_value;
1918
1919 mutex_lock(&codec->mutex);
1920
1921 if (ucontrol->value.integer.value[0])
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001922 snd_soc_dapm_enable_pin(&codec->dapm, pin);
Mark Brown8b37dbd2009-02-28 21:14:20 +00001923 else
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001924 snd_soc_dapm_disable_pin(&codec->dapm, pin);
Mark Brown8b37dbd2009-02-28 21:14:20 +00001925
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001926 snd_soc_dapm_sync(&codec->dapm);
Mark Brown8b37dbd2009-02-28 21:14:20 +00001927
1928 mutex_unlock(&codec->mutex);
1929
1930 return 0;
1931}
1932EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
1933
1934/**
Richard Purdie2b97eab2006-10-06 18:32:18 +02001935 * snd_soc_dapm_new_control - create new dapm control
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001936 * @dapm: DAPM context
Richard Purdie2b97eab2006-10-06 18:32:18 +02001937 * @widget: widget template
1938 *
1939 * Creates a new dapm control based upon the template.
1940 *
1941 * Returns 0 for success else error.
1942 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001943int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
Richard Purdie2b97eab2006-10-06 18:32:18 +02001944 const struct snd_soc_dapm_widget *widget)
1945{
1946 struct snd_soc_dapm_widget *w;
1947
1948 if ((w = dapm_cnew_widget(widget)) == NULL)
1949 return -ENOMEM;
1950
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001951 w->dapm = dapm;
1952 w->codec = dapm->codec;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001953 INIT_LIST_HEAD(&w->sources);
1954 INIT_LIST_HEAD(&w->sinks);
1955 INIT_LIST_HEAD(&w->list);
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001956 list_add(&w->list, &dapm->widgets);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001957
1958 /* machine layer set ups unconnected pins and insertions */
1959 w->connected = 1;
1960 return 0;
1961}
1962EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
1963
1964/**
Mark Brown4ba13272008-05-13 14:51:19 +02001965 * snd_soc_dapm_new_controls - create new dapm controls
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001966 * @dapm: DAPM context
Mark Brown4ba13272008-05-13 14:51:19 +02001967 * @widget: widget array
1968 * @num: number of widgets
1969 *
1970 * Creates new DAPM controls based upon the templates.
1971 *
1972 * Returns 0 for success else error.
1973 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001974int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
Mark Brown4ba13272008-05-13 14:51:19 +02001975 const struct snd_soc_dapm_widget *widget,
1976 int num)
1977{
1978 int i, ret;
1979
1980 for (i = 0; i < num; i++) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001981 ret = snd_soc_dapm_new_control(dapm, widget);
Mark Brownb8b33cb2008-12-18 11:19:30 +00001982 if (ret < 0) {
1983 printk(KERN_ERR
1984 "ASoC: Failed to create DAPM control %s: %d\n",
1985 widget->name, ret);
Mark Brown4ba13272008-05-13 14:51:19 +02001986 return ret;
Mark Brownb8b33cb2008-12-18 11:19:30 +00001987 }
Mark Brown4ba13272008-05-13 14:51:19 +02001988 widget++;
1989 }
1990 return 0;
1991}
1992EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
1993
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001994static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00001995 const char *stream, int event)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001996{
1997 struct snd_soc_dapm_widget *w;
1998
Liam Girdwoodce6120c2010-11-05 15:53:46 +02001999 list_for_each_entry(w, &dapm->widgets, list)
Richard Purdie2b97eab2006-10-06 18:32:18 +02002000 {
2001 if (!w->sname)
2002 continue;
Mark Brownc1286b82008-07-07 19:26:03 +01002003 pr_debug("widget %s\n %s stream %s event %d\n",
2004 w->name, w->sname, stream, event);
Richard Purdie2b97eab2006-10-06 18:32:18 +02002005 if (strstr(w->sname, stream)) {
2006 switch(event) {
2007 case SND_SOC_DAPM_STREAM_START:
2008 w->active = 1;
2009 break;
2010 case SND_SOC_DAPM_STREAM_STOP:
2011 w->active = 0;
2012 break;
2013 case SND_SOC_DAPM_STREAM_SUSPEND:
Richard Purdie2b97eab2006-10-06 18:32:18 +02002014 case SND_SOC_DAPM_STREAM_RESUME:
Richard Purdie2b97eab2006-10-06 18:32:18 +02002015 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
Richard Purdie2b97eab2006-10-06 18:32:18 +02002016 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
2017 break;
2018 }
2019 }
2020 }
Richard Purdie2b97eab2006-10-06 18:32:18 +02002021
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002022 dapm_power_widgets(dapm, event);
2023}
2024
2025/**
2026 * snd_soc_dapm_stream_event - send a stream event to the dapm core
2027 * @rtd: PCM runtime data
2028 * @stream: stream name
2029 * @event: stream event
2030 *
2031 * Sends a stream event to the dapm core. The core then makes any
2032 * necessary widget power changes.
2033 *
2034 * Returns 0 for success else error.
2035 */
2036int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
2037 const char *stream, int event)
2038{
2039 struct snd_soc_codec *codec = rtd->codec;
2040
2041 if (stream == NULL)
2042 return 0;
2043
2044 mutex_lock(&codec->mutex);
2045 soc_dapm_stream_event(&codec->dapm, stream, event);
Eero Nurkkala8e8b2d62009-10-12 08:41:59 +03002046 mutex_unlock(&codec->mutex);
Richard Purdie2b97eab2006-10-06 18:32:18 +02002047 return 0;
2048}
2049EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
2050
2051/**
Liam Girdwooda5302182008-07-07 13:35:17 +01002052 * snd_soc_dapm_enable_pin - enable pin.
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002053 * @dapm: DAPM context
Liam Girdwooda5302182008-07-07 13:35:17 +01002054 * @pin: pin name
Richard Purdie2b97eab2006-10-06 18:32:18 +02002055 *
Mark Brown74b8f952009-06-06 11:26:15 +01002056 * Enables input/output pin and its parents or children widgets iff there is
Liam Girdwooda5302182008-07-07 13:35:17 +01002057 * a valid audio route and active audio stream.
2058 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2059 * do any widget power switching.
Richard Purdie2b97eab2006-10-06 18:32:18 +02002060 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002061int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
Richard Purdie2b97eab2006-10-06 18:32:18 +02002062{
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002063 return snd_soc_dapm_set_pin(dapm, pin, 1);
Richard Purdie2b97eab2006-10-06 18:32:18 +02002064}
Liam Girdwooda5302182008-07-07 13:35:17 +01002065EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
Richard Purdie2b97eab2006-10-06 18:32:18 +02002066
2067/**
Mark Brownda341832010-03-15 19:23:37 +00002068 * snd_soc_dapm_force_enable_pin - force a pin to be enabled
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002069 * @dapm: DAPM context
Mark Brownda341832010-03-15 19:23:37 +00002070 * @pin: pin name
2071 *
2072 * Enables input/output pin regardless of any other state. This is
2073 * intended for use with microphone bias supplies used in microphone
2074 * jack detection.
2075 *
2076 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2077 * do any widget power switching.
2078 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002079int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
2080 const char *pin)
Mark Brownda341832010-03-15 19:23:37 +00002081{
2082 struct snd_soc_dapm_widget *w;
2083
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002084 list_for_each_entry(w, &dapm->widgets, list) {
Mark Brownda341832010-03-15 19:23:37 +00002085 if (!strcmp(w->name, pin)) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002086 pr_debug("dapm: %s: pin %s\n", dapm->codec->name, pin);
Mark Brownda341832010-03-15 19:23:37 +00002087 w->connected = 1;
2088 w->force = 1;
2089 return 0;
2090 }
2091 }
2092
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002093 pr_err("dapm: %s: configuring unknown pin %s\n",
2094 dapm->codec->name, pin);
Mark Brownda341832010-03-15 19:23:37 +00002095 return -EINVAL;
2096}
2097EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
2098
2099/**
Liam Girdwooda5302182008-07-07 13:35:17 +01002100 * snd_soc_dapm_disable_pin - disable pin.
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002101 * @dapm: DAPM context
Liam Girdwooda5302182008-07-07 13:35:17 +01002102 * @pin: pin name
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02002103 *
Mark Brown74b8f952009-06-06 11:26:15 +01002104 * Disables input/output pin and its parents or children widgets.
Liam Girdwooda5302182008-07-07 13:35:17 +01002105 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2106 * do any widget power switching.
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02002107 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002108int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
2109 const char *pin)
Liam Girdwooda5302182008-07-07 13:35:17 +01002110{
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002111 return snd_soc_dapm_set_pin(dapm, pin, 0);
Liam Girdwooda5302182008-07-07 13:35:17 +01002112}
2113EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
2114
2115/**
Mark Brown5817b522008-09-24 11:23:11 +01002116 * snd_soc_dapm_nc_pin - permanently disable pin.
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002117 * @dapm: DAPM context
Mark Brown5817b522008-09-24 11:23:11 +01002118 * @pin: pin name
2119 *
2120 * Marks the specified pin as being not connected, disabling it along
2121 * any parent or child widgets. At present this is identical to
2122 * snd_soc_dapm_disable_pin() but in future it will be extended to do
2123 * additional things such as disabling controls which only affect
2124 * paths through the pin.
2125 *
2126 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2127 * do any widget power switching.
2128 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002129int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
Mark Brown5817b522008-09-24 11:23:11 +01002130{
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002131 return snd_soc_dapm_set_pin(dapm, pin, 0);
Mark Brown5817b522008-09-24 11:23:11 +01002132}
2133EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
2134
2135/**
Liam Girdwooda5302182008-07-07 13:35:17 +01002136 * snd_soc_dapm_get_pin_status - get audio pin status
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002137 * @dapm: DAPM context
Liam Girdwooda5302182008-07-07 13:35:17 +01002138 * @pin: audio signal pin endpoint (or start point)
2139 *
2140 * Get audio pin status - connected or disconnected.
2141 *
2142 * Returns 1 for connected otherwise 0.
2143 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002144int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
2145 const char *pin)
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02002146{
2147 struct snd_soc_dapm_widget *w;
2148
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002149 list_for_each_entry(w, &dapm->widgets, list) {
Liam Girdwooda5302182008-07-07 13:35:17 +01002150 if (!strcmp(w->name, pin))
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02002151 return w->connected;
2152 }
2153
2154 return 0;
2155}
Liam Girdwooda5302182008-07-07 13:35:17 +01002156EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02002157
2158/**
Mark Brown1547aba2010-05-07 21:11:40 +01002159 * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002160 * @dapm: DAPM context
Mark Brown1547aba2010-05-07 21:11:40 +01002161 * @pin: audio signal pin endpoint (or start point)
2162 *
2163 * Mark the given endpoint or pin as ignoring suspend. When the
2164 * system is disabled a path between two endpoints flagged as ignoring
2165 * suspend will not be disabled. The path must already be enabled via
2166 * normal means at suspend time, it will not be turned on if it was not
2167 * already enabled.
2168 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002169int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
2170 const char *pin)
Mark Brown1547aba2010-05-07 21:11:40 +01002171{
2172 struct snd_soc_dapm_widget *w;
2173
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002174 list_for_each_entry(w, &dapm->widgets, list) {
Mark Brown1547aba2010-05-07 21:11:40 +01002175 if (!strcmp(w->name, pin)) {
2176 w->ignore_suspend = 1;
2177 return 0;
2178 }
2179 }
2180
2181 pr_err("Unknown DAPM pin: %s\n", pin);
2182 return -EINVAL;
2183}
2184EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
2185
2186/**
Richard Purdie2b97eab2006-10-06 18:32:18 +02002187 * snd_soc_dapm_free - free dapm resources
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002188 * @card: SoC device
Richard Purdie2b97eab2006-10-06 18:32:18 +02002189 *
2190 * Free all dapm widgets and resources.
2191 */
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002192void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
Richard Purdie2b97eab2006-10-06 18:32:18 +02002193{
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002194 snd_soc_dapm_sys_remove(dapm->dev);
2195 dapm_free_widgets(dapm);
Richard Purdie2b97eab2006-10-06 18:32:18 +02002196}
2197EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
2198
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002199static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
Mark Brown51737472009-06-22 13:16:51 +01002200{
Mark Brown51737472009-06-22 13:16:51 +01002201 struct snd_soc_dapm_widget *w;
2202 LIST_HEAD(down_list);
2203 int powerdown = 0;
2204
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002205 list_for_each_entry(w, &dapm->widgets, list) {
Mark Brown51737472009-06-22 13:16:51 +01002206 if (w->power) {
2207 dapm_seq_insert(w, &down_list, dapm_down_seq);
Mark Brownc2caa4d2009-06-26 15:36:56 +01002208 w->power = 0;
Mark Brown51737472009-06-22 13:16:51 +01002209 powerdown = 1;
2210 }
2211 }
2212
2213 /* If there were no widgets to power down we're already in
2214 * standby.
2215 */
2216 if (powerdown) {
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002217 snd_soc_dapm_set_bias_level(NULL, dapm, SND_SOC_BIAS_PREPARE);
2218 dapm_seq_run(dapm, &down_list, 0, dapm_down_seq);
2219 snd_soc_dapm_set_bias_level(NULL, dapm, SND_SOC_BIAS_STANDBY);
Mark Brown51737472009-06-22 13:16:51 +01002220 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002221}
Mark Brown51737472009-06-22 13:16:51 +01002222
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +00002223/*
2224 * snd_soc_dapm_shutdown - callback for system shutdown
2225 */
2226void snd_soc_dapm_shutdown(struct snd_soc_card *card)
2227{
2228 struct snd_soc_codec *codec;
2229
Liam Girdwoodce6120c2010-11-05 15:53:46 +02002230 list_for_each_entry(codec, &card->codec_dev_list, list) {
2231 soc_dapm_shutdown_codec(&codec->dapm);
2232 snd_soc_dapm_set_bias_level(card, &codec->dapm, SND_SOC_BIAS_OFF);
2233 }
Mark Brown51737472009-06-22 13:16:51 +01002234}
2235
Richard Purdie2b97eab2006-10-06 18:32:18 +02002236/* Module information */
Liam Girdwoodd3311242008-10-12 13:17:36 +01002237MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
Richard Purdie2b97eab2006-10-06 18:32:18 +02002238MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
2239MODULE_LICENSE("GPL");