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