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