blob: ad0d801677c13ccd64eaa7942f1c120ecb07b144 [file] [log] [blame]
Richard Purdie2b97eab2006-10-06 18:32:18 +02001/*
2 * soc-dapm.c -- ALSA SoC Dynamic Audio Power Management
3 *
4 * Copyright 2005 Wolfson Microelectronics PLC.
Liam Girdwoodd3311242008-10-12 13:17:36 +01005 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
Richard Purdie2b97eab2006-10-06 18:32:18 +02006 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
Richard Purdie2b97eab2006-10-06 18:32:18 +020012 * Features:
13 * o Changes power status of internal codec blocks depending on the
14 * dynamic configuration of codec internal audio paths and active
15 * DAC's/ADC's.
16 * o Platform power domain - can support external components i.e. amps and
17 * mic/meadphone insertion events.
18 * o Automatic Mic Bias support
19 * o Jack insertion power event initiation - e.g. hp insertion will enable
20 * sinks, dacs, etc
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +020021 * o Delayed powerdown of audio susbsystem to reduce pops between a quick
Richard Purdie2b97eab2006-10-06 18:32:18 +020022 * device reopen.
23 *
24 * Todo:
25 * o DAPM power change sequencing - allow for configurable per
26 * codec sequences.
27 * o Support for analogue bias optimisation.
28 * o Support for reduced codec oversampling rates.
29 * o Support for reduced codec bias currents.
30 */
31
32#include <linux/module.h>
33#include <linux/moduleparam.h>
34#include <linux/init.h>
35#include <linux/delay.h>
36#include <linux/pm.h>
37#include <linux/bitops.h>
38#include <linux/platform_device.h>
39#include <linux/jiffies.h>
Richard Purdie2b97eab2006-10-06 18:32:18 +020040#include <sound/core.h>
41#include <sound/pcm.h>
42#include <sound/pcm_params.h>
43#include <sound/soc-dapm.h>
44#include <sound/initval.h>
45
46/* debug */
Mark Brownc1286b82008-07-07 19:26:03 +010047#ifdef DEBUG
Richard Purdie2b97eab2006-10-06 18:32:18 +020048#define dump_dapm(codec, action) dbg_dump_dapm(codec, action)
Richard Purdie2b97eab2006-10-06 18:32:18 +020049#else
50#define dump_dapm(codec, action)
Richard Purdie2b97eab2006-10-06 18:32:18 +020051#endif
52
Richard Purdie2b97eab2006-10-06 18:32:18 +020053/* dapm power sequences - make this per codec in the future */
54static int dapm_up_seq[] = {
55 snd_soc_dapm_pre, snd_soc_dapm_micbias, snd_soc_dapm_mic,
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +020056 snd_soc_dapm_mux, snd_soc_dapm_value_mux, snd_soc_dapm_dac,
57 snd_soc_dapm_mixer, snd_soc_dapm_pga, snd_soc_dapm_adc, snd_soc_dapm_hp,
58 snd_soc_dapm_spk, snd_soc_dapm_post
Richard Purdie2b97eab2006-10-06 18:32:18 +020059};
60static int dapm_down_seq[] = {
61 snd_soc_dapm_pre, snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk,
62 snd_soc_dapm_pga, snd_soc_dapm_mixer, snd_soc_dapm_dac, snd_soc_dapm_mic,
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +020063 snd_soc_dapm_micbias, snd_soc_dapm_mux, snd_soc_dapm_value_mux,
64 snd_soc_dapm_post
Richard Purdie2b97eab2006-10-06 18:32:18 +020065};
66
67static int dapm_status = 1;
68module_param(dapm_status, int, 0);
69MODULE_PARM_DESC(dapm_status, "enable DPM sysfs entries");
70
Troy Kisky12ef1932008-10-13 17:42:14 -070071static void pop_wait(u32 pop_time)
Mark Brown15e4c722008-07-02 11:51:20 +010072{
73 if (pop_time)
74 schedule_timeout_uninterruptible(msecs_to_jiffies(pop_time));
75}
76
Troy Kisky12ef1932008-10-13 17:42:14 -070077static void pop_dbg(u32 pop_time, const char *fmt, ...)
Mark Brown15e4c722008-07-02 11:51:20 +010078{
79 va_list args;
80
81 va_start(args, fmt);
82
83 if (pop_time) {
84 vprintk(fmt, args);
Troy Kisky12ef1932008-10-13 17:42:14 -070085 pop_wait(pop_time);
Mark Brown15e4c722008-07-02 11:51:20 +010086 }
87
88 va_end(args);
89}
90
Richard Purdie2b97eab2006-10-06 18:32:18 +020091/* create a new dapm widget */
Takashi Iwai88cb4292007-02-05 14:56:20 +010092static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
Richard Purdie2b97eab2006-10-06 18:32:18 +020093 const struct snd_soc_dapm_widget *_widget)
94{
Takashi Iwai88cb4292007-02-05 14:56:20 +010095 return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
Richard Purdie2b97eab2006-10-06 18:32:18 +020096}
97
98/* set up initial codec paths */
99static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
100 struct snd_soc_dapm_path *p, int i)
101{
102 switch (w->id) {
103 case snd_soc_dapm_switch:
104 case snd_soc_dapm_mixer: {
105 int val;
Jon Smirl4eaa9812008-07-29 11:42:26 +0100106 struct soc_mixer_control *mc = (struct soc_mixer_control *)
107 w->kcontrols[i].private_value;
Jon Smirl815ecf82008-07-29 10:22:24 -0400108 unsigned int reg = mc->reg;
109 unsigned int shift = mc->shift;
Jon Smirl4eaa9812008-07-29 11:42:26 +0100110 int max = mc->max;
Jon Smirl815ecf82008-07-29 10:22:24 -0400111 unsigned int mask = (1 << fls(max)) - 1;
112 unsigned int invert = mc->invert;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200113
114 val = snd_soc_read(w->codec, reg);
115 val = (val >> shift) & mask;
116
117 if ((invert && !val) || (!invert && val))
118 p->connect = 1;
119 else
120 p->connect = 0;
121 }
122 break;
123 case snd_soc_dapm_mux: {
124 struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value;
125 int val, item, bitmask;
126
Jon Smirlf8ba0b72008-07-29 11:42:27 +0100127 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200128 ;
129 val = snd_soc_read(w->codec, e->reg);
130 item = (val >> e->shift_l) & (bitmask - 1);
131
132 p->connect = 0;
Jon Smirlf8ba0b72008-07-29 11:42:27 +0100133 for (i = 0; i < e->max; i++) {
Richard Purdie2b97eab2006-10-06 18:32:18 +0200134 if (!(strcmp(p->name, e->texts[i])) && item == i)
135 p->connect = 1;
136 }
137 }
138 break;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +0200139 case snd_soc_dapm_value_mux: {
140 struct soc_value_enum *e = (struct soc_value_enum *)
141 w->kcontrols[i].private_value;
142 int val, item;
143
144 val = snd_soc_read(w->codec, e->reg);
145 val = (val >> e->shift_l) & e->mask;
146 for (item = 0; item < e->max; item++) {
147 if (val == e->values[item])
148 break;
149 }
150
151 p->connect = 0;
152 for (i = 0; i < e->max; i++) {
153 if (!(strcmp(p->name, e->texts[i])) && item == i)
154 p->connect = 1;
155 }
156 }
157 break;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200158 /* does not effect routing - always connected */
159 case snd_soc_dapm_pga:
160 case snd_soc_dapm_output:
161 case snd_soc_dapm_adc:
162 case snd_soc_dapm_input:
163 case snd_soc_dapm_dac:
164 case snd_soc_dapm_micbias:
165 case snd_soc_dapm_vmid:
166 p->connect = 1;
167 break;
168 /* does effect routing - dynamically connected */
169 case snd_soc_dapm_hp:
170 case snd_soc_dapm_mic:
171 case snd_soc_dapm_spk:
172 case snd_soc_dapm_line:
173 case snd_soc_dapm_pre:
174 case snd_soc_dapm_post:
175 p->connect = 0;
176 break;
177 }
178}
179
180/* connect mux widget to it's interconnecting audio paths */
181static int dapm_connect_mux(struct snd_soc_codec *codec,
182 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
183 struct snd_soc_dapm_path *path, const char *control_name,
184 const struct snd_kcontrol_new *kcontrol)
185{
186 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
187 int i;
188
Jon Smirlf8ba0b72008-07-29 11:42:27 +0100189 for (i = 0; i < e->max; i++) {
Richard Purdie2b97eab2006-10-06 18:32:18 +0200190 if (!(strcmp(control_name, e->texts[i]))) {
191 list_add(&path->list, &codec->dapm_paths);
192 list_add(&path->list_sink, &dest->sources);
193 list_add(&path->list_source, &src->sinks);
194 path->name = (char*)e->texts[i];
195 dapm_set_path_status(dest, path, 0);
196 return 0;
197 }
198 }
199
200 return -ENODEV;
201}
202
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +0200203/* connect value_mux widget to it's interconnecting audio paths */
204static int dapm_connect_value_mux(struct snd_soc_codec *codec,
205 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
206 struct snd_soc_dapm_path *path, const char *control_name,
207 const struct snd_kcontrol_new *kcontrol)
208{
209 struct soc_value_enum *e = (struct soc_value_enum *)
210 kcontrol->private_value;
211 int i;
212
213 for (i = 0; i < e->max; i++) {
214 if (!(strcmp(control_name, e->texts[i]))) {
215 list_add(&path->list, &codec->dapm_paths);
216 list_add(&path->list_sink, &dest->sources);
217 list_add(&path->list_source, &src->sinks);
218 path->name = (char *)e->texts[i];
219 dapm_set_path_status(dest, path, 0);
220 return 0;
221 }
222 }
223
224 return -ENODEV;
225}
226
Richard Purdie2b97eab2006-10-06 18:32:18 +0200227/* connect mixer widget to it's interconnecting audio paths */
228static int dapm_connect_mixer(struct snd_soc_codec *codec,
229 struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
230 struct snd_soc_dapm_path *path, const char *control_name)
231{
232 int i;
233
234 /* search for mixer kcontrol */
235 for (i = 0; i < dest->num_kcontrols; i++) {
236 if (!strcmp(control_name, dest->kcontrols[i].name)) {
237 list_add(&path->list, &codec->dapm_paths);
238 list_add(&path->list_sink, &dest->sources);
239 list_add(&path->list_source, &src->sinks);
240 path->name = dest->kcontrols[i].name;
241 dapm_set_path_status(dest, path, i);
242 return 0;
243 }
244 }
245 return -ENODEV;
246}
247
248/* update dapm codec register bits */
249static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
250{
251 int change, power;
252 unsigned short old, new;
253 struct snd_soc_codec *codec = widget->codec;
254
255 /* check for valid widgets */
256 if (widget->reg < 0 || widget->id == snd_soc_dapm_input ||
257 widget->id == snd_soc_dapm_output ||
258 widget->id == snd_soc_dapm_hp ||
259 widget->id == snd_soc_dapm_mic ||
260 widget->id == snd_soc_dapm_line ||
261 widget->id == snd_soc_dapm_spk)
262 return 0;
263
264 power = widget->power;
265 if (widget->invert)
266 power = (power ? 0:1);
267
268 old = snd_soc_read(codec, widget->reg);
269 new = (old & ~(0x1 << widget->shift)) | (power << widget->shift);
270
271 change = old != new;
272 if (change) {
Troy Kisky12ef1932008-10-13 17:42:14 -0700273 pop_dbg(codec->pop_time, "pop test %s : %s in %d ms\n",
274 widget->name, widget->power ? "on" : "off",
275 codec->pop_time);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200276 snd_soc_write(codec, widget->reg, new);
Troy Kisky12ef1932008-10-13 17:42:14 -0700277 pop_wait(codec->pop_time);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200278 }
Mark Brownc1286b82008-07-07 19:26:03 +0100279 pr_debug("reg %x old %x new %x change %d\n", widget->reg,
280 old, new, change);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200281 return change;
282}
283
284/* ramps the volume up or down to minimise pops before or after a
285 * DAPM power event */
286static int dapm_set_pga(struct snd_soc_dapm_widget *widget, int power)
287{
288 const struct snd_kcontrol_new *k = widget->kcontrols;
289
290 if (widget->muted && !power)
291 return 0;
292 if (!widget->muted && power)
293 return 0;
294
295 if (widget->num_kcontrols && k) {
Jon Smirl4eaa9812008-07-29 11:42:26 +0100296 struct soc_mixer_control *mc =
297 (struct soc_mixer_control *)k->private_value;
Jon Smirl815ecf82008-07-29 10:22:24 -0400298 unsigned int reg = mc->reg;
299 unsigned int shift = mc->shift;
Jon Smirl4eaa9812008-07-29 11:42:26 +0100300 int max = mc->max;
Jon Smirl815ecf82008-07-29 10:22:24 -0400301 unsigned int mask = (1 << fls(max)) - 1;
302 unsigned int invert = mc->invert;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200303
304 if (power) {
305 int i;
306 /* power up has happended, increase volume to last level */
307 if (invert) {
Jon Smirl4eaa9812008-07-29 11:42:26 +0100308 for (i = max; i > widget->saved_value; i--)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200309 snd_soc_update_bits(widget->codec, reg, mask, i);
310 } else {
311 for (i = 0; i < widget->saved_value; i++)
312 snd_soc_update_bits(widget->codec, reg, mask, i);
313 }
314 widget->muted = 0;
315 } else {
316 /* power down is about to occur, decrease volume to mute */
317 int val = snd_soc_read(widget->codec, reg);
318 int i = widget->saved_value = (val >> shift) & mask;
319 if (invert) {
320 for (; i < mask; i++)
321 snd_soc_update_bits(widget->codec, reg, mask, i);
322 } else {
323 for (; i > 0; i--)
324 snd_soc_update_bits(widget->codec, reg, mask, i);
325 }
326 widget->muted = 1;
327 }
328 }
329 return 0;
330}
331
332/* create new dapm mixer control */
333static int dapm_new_mixer(struct snd_soc_codec *codec,
334 struct snd_soc_dapm_widget *w)
335{
336 int i, ret = 0;
Mark Brown219b93f2008-10-28 13:02:31 +0000337 size_t name_len;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200338 struct snd_soc_dapm_path *path;
339
340 /* add kcontrol */
341 for (i = 0; i < w->num_kcontrols; i++) {
342
343 /* match name */
344 list_for_each_entry(path, &w->sources, list_sink) {
345
346 /* mixer/mux paths name must match control name */
347 if (path->name != (char*)w->kcontrols[i].name)
348 continue;
349
350 /* add dapm control with long name */
Mark Brown219b93f2008-10-28 13:02:31 +0000351 name_len = 2 + strlen(w->name)
352 + strlen(w->kcontrols[i].name);
353 path->long_name = kmalloc(name_len, GFP_KERNEL);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200354 if (path->long_name == NULL)
355 return -ENOMEM;
356
Mark Brown219b93f2008-10-28 13:02:31 +0000357 snprintf(path->long_name, name_len, "%s %s",
358 w->name, w->kcontrols[i].name);
359 path->long_name[name_len - 1] = '\0';
360
Richard Purdie2b97eab2006-10-06 18:32:18 +0200361 path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
362 path->long_name);
363 ret = snd_ctl_add(codec->card, path->kcontrol);
364 if (ret < 0) {
365 printk(KERN_ERR "asoc: failed to add dapm kcontrol %s\n",
366 path->long_name);
367 kfree(path->long_name);
368 path->long_name = NULL;
369 return ret;
370 }
371 }
372 }
373 return ret;
374}
375
376/* create new dapm mux control */
377static int dapm_new_mux(struct snd_soc_codec *codec,
378 struct snd_soc_dapm_widget *w)
379{
380 struct snd_soc_dapm_path *path = NULL;
381 struct snd_kcontrol *kcontrol;
382 int ret = 0;
383
384 if (!w->num_kcontrols) {
385 printk(KERN_ERR "asoc: mux %s has no controls\n", w->name);
386 return -EINVAL;
387 }
388
389 kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
390 ret = snd_ctl_add(codec->card, kcontrol);
391 if (ret < 0)
392 goto err;
393
394 list_for_each_entry(path, &w->sources, list_sink)
395 path->kcontrol = kcontrol;
396
397 return ret;
398
399err:
400 printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name);
401 return ret;
402}
403
404/* create new dapm volume control */
405static int dapm_new_pga(struct snd_soc_codec *codec,
406 struct snd_soc_dapm_widget *w)
407{
408 struct snd_kcontrol *kcontrol;
409 int ret = 0;
410
411 if (!w->num_kcontrols)
412 return -EINVAL;
413
414 kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
415 ret = snd_ctl_add(codec->card, kcontrol);
416 if (ret < 0) {
417 printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name);
418 return ret;
419 }
420
421 return ret;
422}
423
424/* reset 'walked' bit for each dapm path */
425static 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 */
437static 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_adc && widget->active)
443 return 1;
444
445 if (widget->connected) {
446 /* connected pin ? */
447 if (widget->id == snd_soc_dapm_output && !widget->ext)
448 return 1;
449
450 /* connected jack or spk ? */
451 if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
452 widget->id == snd_soc_dapm_line)
453 return 1;
454 }
455
456 list_for_each_entry(path, &widget->sinks, list_source) {
457 if (path->walked)
458 continue;
459
460 if (path->sink && path->connect) {
461 path->walked = 1;
462 con += is_connected_output_ep(path->sink);
463 }
464 }
465
466 return con;
467}
468
469/*
470 * Recursively check for a completed path to an active or physically connected
471 * input widget. Returns number of complete paths.
472 */
473static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
474{
475 struct snd_soc_dapm_path *path;
476 int con = 0;
477
478 /* active stream ? */
479 if (widget->id == snd_soc_dapm_dac && widget->active)
480 return 1;
481
482 if (widget->connected) {
483 /* connected pin ? */
484 if (widget->id == snd_soc_dapm_input && !widget->ext)
485 return 1;
486
487 /* connected VMID/Bias for lower pops */
488 if (widget->id == snd_soc_dapm_vmid)
489 return 1;
490
491 /* connected jack ? */
492 if (widget->id == snd_soc_dapm_mic || widget->id == snd_soc_dapm_line)
493 return 1;
494 }
495
496 list_for_each_entry(path, &widget->sources, list_sink) {
497 if (path->walked)
498 continue;
499
500 if (path->source && path->connect) {
501 path->walked = 1;
502 con += is_connected_input_ep(path->source);
503 }
504 }
505
506 return con;
507}
508
509/*
Jarkko Nikulae2be2cc2008-06-25 14:42:07 +0300510 * Handler for generic register modifier widget.
511 */
512int dapm_reg_event(struct snd_soc_dapm_widget *w,
513 struct snd_kcontrol *kcontrol, int event)
514{
515 unsigned int val;
516
517 if (SND_SOC_DAPM_EVENT_ON(event))
518 val = w->on_val;
519 else
520 val = w->off_val;
521
522 snd_soc_update_bits(w->codec, -(w->reg + 1),
523 w->mask << w->shift, val << w->shift);
524
525 return 0;
526}
Mark Brown11589412008-07-29 11:42:23 +0100527EXPORT_SYMBOL_GPL(dapm_reg_event);
Jarkko Nikulae2be2cc2008-06-25 14:42:07 +0300528
529/*
Richard Purdie2b97eab2006-10-06 18:32:18 +0200530 * Scan each dapm widget for complete audio path.
531 * A complete path is a route that has valid endpoints i.e.:-
532 *
533 * o DAC to output pin.
534 * o Input Pin to ADC.
535 * o Input pin to Output pin (bypass, sidetone)
536 * o DAC to ADC (loopback).
537 */
Adrian Bunkd9c96cf2006-11-28 12:10:09 +0100538static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200539{
540 struct snd_soc_dapm_widget *w;
541 int in, out, i, c = 1, *seq = NULL, ret = 0, power_change, power;
542
543 /* do we have a sequenced stream event */
544 if (event == SND_SOC_DAPM_STREAM_START) {
545 c = ARRAY_SIZE(dapm_up_seq);
546 seq = dapm_up_seq;
547 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
548 c = ARRAY_SIZE(dapm_down_seq);
549 seq = dapm_down_seq;
550 }
551
552 for(i = 0; i < c; i++) {
553 list_for_each_entry(w, &codec->dapm_widgets, list) {
554
555 /* is widget in stream order */
556 if (seq && seq[i] && w->id != seq[i])
557 continue;
558
559 /* vmid - no action */
560 if (w->id == snd_soc_dapm_vmid)
561 continue;
562
563 /* active ADC */
564 if (w->id == snd_soc_dapm_adc && w->active) {
565 in = is_connected_input_ep(w);
566 dapm_clear_walk(w->codec);
567 w->power = (in != 0) ? 1 : 0;
568 dapm_update_bits(w);
569 continue;
570 }
571
572 /* active DAC */
573 if (w->id == snd_soc_dapm_dac && w->active) {
574 out = is_connected_output_ep(w);
575 dapm_clear_walk(w->codec);
576 w->power = (out != 0) ? 1 : 0;
577 dapm_update_bits(w);
578 continue;
579 }
580
Richard Purdie2b97eab2006-10-06 18:32:18 +0200581 /* pre and post event widgets */
582 if (w->id == snd_soc_dapm_pre) {
583 if (!w->event)
584 continue;
585
586 if (event == SND_SOC_DAPM_STREAM_START) {
Laim Girdwood9af6d952008-01-10 14:41:02 +0100587 ret = w->event(w,
588 NULL, SND_SOC_DAPM_PRE_PMU);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200589 if (ret < 0)
590 return ret;
591 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
Laim Girdwood9af6d952008-01-10 14:41:02 +0100592 ret = w->event(w,
593 NULL, SND_SOC_DAPM_PRE_PMD);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200594 if (ret < 0)
595 return ret;
596 }
597 continue;
598 }
599 if (w->id == snd_soc_dapm_post) {
600 if (!w->event)
601 continue;
602
603 if (event == SND_SOC_DAPM_STREAM_START) {
Laim Girdwood9af6d952008-01-10 14:41:02 +0100604 ret = w->event(w,
605 NULL, SND_SOC_DAPM_POST_PMU);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200606 if (ret < 0)
607 return ret;
608 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
Laim Girdwood9af6d952008-01-10 14:41:02 +0100609 ret = w->event(w,
610 NULL, SND_SOC_DAPM_POST_PMD);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200611 if (ret < 0)
612 return ret;
613 }
614 continue;
615 }
616
617 /* all other widgets */
618 in = is_connected_input_ep(w);
619 dapm_clear_walk(w->codec);
620 out = is_connected_output_ep(w);
621 dapm_clear_walk(w->codec);
622 power = (out != 0 && in != 0) ? 1 : 0;
623 power_change = (w->power == power) ? 0: 1;
624 w->power = power;
625
Mark Brown2927d6e2008-07-17 15:06:50 +0100626 if (!power_change)
627 continue;
628
Richard Purdie2b97eab2006-10-06 18:32:18 +0200629 /* call any power change event handlers */
Mark Brown2927d6e2008-07-17 15:06:50 +0100630 if (w->event)
631 pr_debug("power %s event for %s flags %x\n",
632 w->power ? "on" : "off",
633 w->name, w->event_flags);
634
635 /* power up pre event */
636 if (power && w->event &&
637 (w->event_flags & SND_SOC_DAPM_PRE_PMU)) {
638 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
639 if (ret < 0)
640 return ret;
641 }
642
643 /* power down pre event */
644 if (!power && w->event &&
645 (w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
646 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
647 if (ret < 0)
648 return ret;
649 }
650
Mark Brown9dd8d812008-07-17 15:06:51 +0100651 /* Lower PGA volume to reduce pops */
652 if (w->id == snd_soc_dapm_pga && !power)
653 dapm_set_pga(w, power);
654
Mark Brown2927d6e2008-07-17 15:06:50 +0100655 dapm_update_bits(w);
656
Mark Brown9dd8d812008-07-17 15:06:51 +0100657 /* Raise PGA volume to reduce pops */
658 if (w->id == snd_soc_dapm_pga && power)
659 dapm_set_pga(w, power);
660
Mark Brown2927d6e2008-07-17 15:06:50 +0100661 /* power up post event */
662 if (power && w->event &&
663 (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
664 ret = w->event(w,
665 NULL, SND_SOC_DAPM_POST_PMU);
666 if (ret < 0)
667 return ret;
668 }
669
670 /* power down post event */
671 if (!power && w->event &&
672 (w->event_flags & SND_SOC_DAPM_POST_PMD)) {
673 ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
674 if (ret < 0)
675 return ret;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200676 }
677 }
678 }
679
680 return ret;
681}
682
Mark Brownc1286b82008-07-07 19:26:03 +0100683#ifdef DEBUG
Richard Purdie2b97eab2006-10-06 18:32:18 +0200684static void dbg_dump_dapm(struct snd_soc_codec* codec, const char *action)
685{
686 struct snd_soc_dapm_widget *w;
687 struct snd_soc_dapm_path *p = NULL;
688 int in, out;
689
690 printk("DAPM %s %s\n", codec->name, action);
691
692 list_for_each_entry(w, &codec->dapm_widgets, list) {
693
694 /* only display widgets that effect routing */
695 switch (w->id) {
696 case snd_soc_dapm_pre:
697 case snd_soc_dapm_post:
698 case snd_soc_dapm_vmid:
699 continue;
700 case snd_soc_dapm_mux:
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +0200701 case snd_soc_dapm_value_mux:
Richard Purdie2b97eab2006-10-06 18:32:18 +0200702 case snd_soc_dapm_output:
703 case snd_soc_dapm_input:
704 case snd_soc_dapm_switch:
705 case snd_soc_dapm_hp:
706 case snd_soc_dapm_mic:
707 case snd_soc_dapm_spk:
708 case snd_soc_dapm_line:
709 case snd_soc_dapm_micbias:
710 case snd_soc_dapm_dac:
711 case snd_soc_dapm_adc:
712 case snd_soc_dapm_pga:
713 case snd_soc_dapm_mixer:
714 if (w->name) {
715 in = is_connected_input_ep(w);
716 dapm_clear_walk(w->codec);
717 out = is_connected_output_ep(w);
718 dapm_clear_walk(w->codec);
719 printk("%s: %s in %d out %d\n", w->name,
720 w->power ? "On":"Off",in, out);
721
722 list_for_each_entry(p, &w->sources, list_sink) {
723 if (p->connect)
724 printk(" in %s %s\n", p->name ? p->name : "static",
725 p->source->name);
726 }
727 list_for_each_entry(p, &w->sinks, list_source) {
Richard Purdie2b97eab2006-10-06 18:32:18 +0200728 if (p->connect)
729 printk(" out %s %s\n", p->name ? p->name : "static",
730 p->sink->name);
731 }
732 }
733 break;
734 }
735 }
736}
737#endif
738
739/* test and update the power status of a mux widget */
Adrian Bunkd9c96cf2006-11-28 12:10:09 +0100740static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
741 struct snd_kcontrol *kcontrol, int mask,
Richard Zhaocb01e2b2008-10-07 08:05:20 +0800742 int mux, int val, struct soc_enum *e)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200743{
744 struct snd_soc_dapm_path *path;
745 int found = 0;
746
747 if (widget->id != snd_soc_dapm_mux)
748 return -ENODEV;
749
750 if (!snd_soc_test_bits(widget->codec, e->reg, mask, val))
751 return 0;
752
753 /* find dapm widget path assoc with kcontrol */
754 list_for_each_entry(path, &widget->codec->dapm_paths, list) {
755 if (path->kcontrol != kcontrol)
756 continue;
757
Richard Zhaocb01e2b2008-10-07 08:05:20 +0800758 if (!path->name || !e->texts[mux])
Richard Purdie2b97eab2006-10-06 18:32:18 +0200759 continue;
760
761 found = 1;
762 /* we now need to match the string in the enum to the path */
Richard Zhaocb01e2b2008-10-07 08:05:20 +0800763 if (!(strcmp(path->name, e->texts[mux])))
Richard Purdie2b97eab2006-10-06 18:32:18 +0200764 path->connect = 1; /* new connection */
765 else
766 path->connect = 0; /* old connection must be powered down */
767 }
768
Mark Brown3fccd8b2008-07-07 19:26:04 +0100769 if (found) {
Richard Purdie2b97eab2006-10-06 18:32:18 +0200770 dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
Mark Brown3fccd8b2008-07-07 19:26:04 +0100771 dump_dapm(widget->codec, "mux power update");
772 }
Richard Purdie2b97eab2006-10-06 18:32:18 +0200773
774 return 0;
775}
Richard Purdie2b97eab2006-10-06 18:32:18 +0200776
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +0200777/* test and update the power status of a value_mux widget */
778static int dapm_value_mux_update_power(struct snd_soc_dapm_widget *widget,
779 struct snd_kcontrol *kcontrol, int mask,
780 int mux, int val, struct soc_value_enum *e)
781{
782 struct snd_soc_dapm_path *path;
783 int found = 0;
784
785 if (widget->id != snd_soc_dapm_value_mux)
786 return -ENODEV;
787
788 if (!snd_soc_test_bits(widget->codec, e->reg, mask, val))
789 return 0;
790
791 /* find dapm widget path assoc with kcontrol */
792 list_for_each_entry(path, &widget->codec->dapm_paths, list) {
793 if (path->kcontrol != kcontrol)
794 continue;
795
796 if (!path->name || !e->texts[mux])
797 continue;
798
799 found = 1;
800 /* we now need to match the string in the enum to the path */
801 if (!(strcmp(path->name, e->texts[mux])))
802 path->connect = 1; /* new connection */
803 else
804 path->connect = 0; /* old connection must be
805 powered down */
806 }
807
808 if (found) {
809 dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
810 dump_dapm(widget->codec, "mux power update");
811 }
812
813 return 0;
814}
815
Milan plzik1b075e32008-01-10 14:39:46 +0100816/* test and update the power status of a mixer or switch widget */
Adrian Bunkd9c96cf2006-11-28 12:10:09 +0100817static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
818 struct snd_kcontrol *kcontrol, int reg,
819 int val_mask, int val, int invert)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200820{
821 struct snd_soc_dapm_path *path;
822 int found = 0;
823
Milan plzik1b075e32008-01-10 14:39:46 +0100824 if (widget->id != snd_soc_dapm_mixer &&
825 widget->id != snd_soc_dapm_switch)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200826 return -ENODEV;
827
828 if (!snd_soc_test_bits(widget->codec, reg, val_mask, val))
829 return 0;
830
831 /* find dapm widget path assoc with kcontrol */
832 list_for_each_entry(path, &widget->codec->dapm_paths, list) {
833 if (path->kcontrol != kcontrol)
834 continue;
835
836 /* found, now check type */
837 found = 1;
838 if (val)
839 /* new connection */
840 path->connect = invert ? 0:1;
841 else
842 /* old connection must be powered down */
843 path->connect = invert ? 1:0;
844 break;
845 }
846
Mark Brown3fccd8b2008-07-07 19:26:04 +0100847 if (found) {
Richard Purdie2b97eab2006-10-06 18:32:18 +0200848 dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
Mark Brown3fccd8b2008-07-07 19:26:04 +0100849 dump_dapm(widget->codec, "mixer power update");
850 }
Richard Purdie2b97eab2006-10-06 18:32:18 +0200851
852 return 0;
853}
Richard Purdie2b97eab2006-10-06 18:32:18 +0200854
855/* show dapm widget status in sys fs */
856static ssize_t dapm_widget_show(struct device *dev,
857 struct device_attribute *attr, char *buf)
858{
859 struct snd_soc_device *devdata = dev_get_drvdata(dev);
860 struct snd_soc_codec *codec = devdata->codec;
861 struct snd_soc_dapm_widget *w;
862 int count = 0;
863 char *state = "not set";
864
865 list_for_each_entry(w, &codec->dapm_widgets, list) {
866
867 /* only display widgets that burnm power */
868 switch (w->id) {
869 case snd_soc_dapm_hp:
870 case snd_soc_dapm_mic:
871 case snd_soc_dapm_spk:
872 case snd_soc_dapm_line:
873 case snd_soc_dapm_micbias:
874 case snd_soc_dapm_dac:
875 case snd_soc_dapm_adc:
876 case snd_soc_dapm_pga:
877 case snd_soc_dapm_mixer:
878 if (w->name)
879 count += sprintf(buf + count, "%s: %s\n",
880 w->name, w->power ? "On":"Off");
881 break;
882 default:
883 break;
884 }
885 }
886
Mark Brown0be98982008-05-19 12:31:28 +0200887 switch (codec->bias_level) {
888 case SND_SOC_BIAS_ON:
889 state = "On";
Richard Purdie2b97eab2006-10-06 18:32:18 +0200890 break;
Mark Brown0be98982008-05-19 12:31:28 +0200891 case SND_SOC_BIAS_PREPARE:
892 state = "Prepare";
Richard Purdie2b97eab2006-10-06 18:32:18 +0200893 break;
Mark Brown0be98982008-05-19 12:31:28 +0200894 case SND_SOC_BIAS_STANDBY:
895 state = "Standby";
Richard Purdie2b97eab2006-10-06 18:32:18 +0200896 break;
Mark Brown0be98982008-05-19 12:31:28 +0200897 case SND_SOC_BIAS_OFF:
898 state = "Off";
Richard Purdie2b97eab2006-10-06 18:32:18 +0200899 break;
900 }
901 count += sprintf(buf + count, "PM State: %s\n", state);
902
903 return count;
904}
905
906static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
907
908int snd_soc_dapm_sys_add(struct device *dev)
909{
Mark Brownf0062a92008-08-28 12:46:24 +0100910 if (!dapm_status)
911 return 0;
Troy Kisky12ef1932008-10-13 17:42:14 -0700912 return device_create_file(dev, &dev_attr_dapm_widget);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200913}
914
915static void snd_soc_dapm_sys_remove(struct device *dev)
916{
Mark Brown15e4c722008-07-02 11:51:20 +0100917 if (dapm_status) {
Richard Purdie2b97eab2006-10-06 18:32:18 +0200918 device_remove_file(dev, &dev_attr_dapm_widget);
Mark Brown15e4c722008-07-02 11:51:20 +0100919 }
Richard Purdie2b97eab2006-10-06 18:32:18 +0200920}
921
922/* free all dapm widgets and resources */
Adrian Bunkd9c96cf2006-11-28 12:10:09 +0100923static void dapm_free_widgets(struct snd_soc_codec *codec)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200924{
925 struct snd_soc_dapm_widget *w, *next_w;
926 struct snd_soc_dapm_path *p, *next_p;
927
928 list_for_each_entry_safe(w, next_w, &codec->dapm_widgets, list) {
929 list_del(&w->list);
930 kfree(w);
931 }
932
933 list_for_each_entry_safe(p, next_p, &codec->dapm_paths, list) {
934 list_del(&p->list);
935 kfree(p->long_name);
936 kfree(p);
937 }
938}
939
Liam Girdwooda5302182008-07-07 13:35:17 +0100940static int snd_soc_dapm_set_pin(struct snd_soc_codec *codec,
941 char *pin, int status)
942{
943 struct snd_soc_dapm_widget *w;
944
945 list_for_each_entry(w, &codec->dapm_widgets, list) {
946 if (!strcmp(w->name, pin)) {
Mark Brownc1286b82008-07-07 19:26:03 +0100947 pr_debug("dapm: %s: pin %s\n", codec->name, pin);
Liam Girdwooda5302182008-07-07 13:35:17 +0100948 w->connected = status;
949 return 0;
950 }
951 }
952
Mark Brownc1286b82008-07-07 19:26:03 +0100953 pr_err("dapm: %s: configuring unknown pin %s\n", codec->name, pin);
Liam Girdwooda5302182008-07-07 13:35:17 +0100954 return -EINVAL;
955}
956
Richard Purdie2b97eab2006-10-06 18:32:18 +0200957/**
Liam Girdwooda5302182008-07-07 13:35:17 +0100958 * snd_soc_dapm_sync - scan and power dapm paths
Richard Purdie2b97eab2006-10-06 18:32:18 +0200959 * @codec: audio codec
960 *
961 * Walks all dapm audio paths and powers widgets according to their
962 * stream or path usage.
963 *
964 * Returns 0 for success.
965 */
Liam Girdwooda5302182008-07-07 13:35:17 +0100966int snd_soc_dapm_sync(struct snd_soc_codec *codec)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200967{
Mark Brown3fccd8b2008-07-07 19:26:04 +0100968 int ret = dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
969 dump_dapm(codec, "sync");
970 return ret;
Richard Purdie2b97eab2006-10-06 18:32:18 +0200971}
Liam Girdwooda5302182008-07-07 13:35:17 +0100972EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
Richard Purdie2b97eab2006-10-06 18:32:18 +0200973
Mark Brown105f1c22008-05-13 14:52:19 +0200974static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
975 const char *sink, const char *control, const char *source)
Richard Purdie2b97eab2006-10-06 18:32:18 +0200976{
977 struct snd_soc_dapm_path *path;
978 struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
979 int ret = 0;
980
981 /* find src and dest widgets */
982 list_for_each_entry(w, &codec->dapm_widgets, list) {
983
984 if (!wsink && !(strcmp(w->name, sink))) {
985 wsink = w;
986 continue;
987 }
988 if (!wsource && !(strcmp(w->name, source))) {
989 wsource = w;
990 }
991 }
992
993 if (wsource == NULL || wsink == NULL)
994 return -ENODEV;
995
996 path = kzalloc(sizeof(struct snd_soc_dapm_path), GFP_KERNEL);
997 if (!path)
998 return -ENOMEM;
999
1000 path->source = wsource;
1001 path->sink = wsink;
1002 INIT_LIST_HEAD(&path->list);
1003 INIT_LIST_HEAD(&path->list_source);
1004 INIT_LIST_HEAD(&path->list_sink);
1005
1006 /* check for external widgets */
1007 if (wsink->id == snd_soc_dapm_input) {
1008 if (wsource->id == snd_soc_dapm_micbias ||
1009 wsource->id == snd_soc_dapm_mic ||
Seth Forshee1e392212007-04-16 15:36:42 +02001010 wsink->id == snd_soc_dapm_line ||
1011 wsink->id == snd_soc_dapm_output)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001012 wsink->ext = 1;
1013 }
1014 if (wsource->id == snd_soc_dapm_output) {
1015 if (wsink->id == snd_soc_dapm_spk ||
1016 wsink->id == snd_soc_dapm_hp ||
Seth Forshee1e392212007-04-16 15:36:42 +02001017 wsink->id == snd_soc_dapm_line ||
1018 wsink->id == snd_soc_dapm_input)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001019 wsource->ext = 1;
1020 }
1021
1022 /* connect static paths */
1023 if (control == NULL) {
1024 list_add(&path->list, &codec->dapm_paths);
1025 list_add(&path->list_sink, &wsink->sources);
1026 list_add(&path->list_source, &wsource->sinks);
1027 path->connect = 1;
1028 return 0;
1029 }
1030
1031 /* connect dynamic paths */
1032 switch(wsink->id) {
1033 case snd_soc_dapm_adc:
1034 case snd_soc_dapm_dac:
1035 case snd_soc_dapm_pga:
1036 case snd_soc_dapm_input:
1037 case snd_soc_dapm_output:
1038 case snd_soc_dapm_micbias:
1039 case snd_soc_dapm_vmid:
1040 case snd_soc_dapm_pre:
1041 case snd_soc_dapm_post:
1042 list_add(&path->list, &codec->dapm_paths);
1043 list_add(&path->list_sink, &wsink->sources);
1044 list_add(&path->list_source, &wsource->sinks);
1045 path->connect = 1;
1046 return 0;
1047 case snd_soc_dapm_mux:
1048 ret = dapm_connect_mux(codec, wsource, wsink, path, control,
1049 &wsink->kcontrols[0]);
1050 if (ret != 0)
1051 goto err;
1052 break;
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001053 case snd_soc_dapm_value_mux:
1054 ret = dapm_connect_value_mux(codec, wsource, wsink, path,
1055 control, &wsink->kcontrols[0]);
1056 if (ret != 0)
1057 goto err;
1058 break;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001059 case snd_soc_dapm_switch:
1060 case snd_soc_dapm_mixer:
1061 ret = dapm_connect_mixer(codec, wsource, wsink, path, control);
1062 if (ret != 0)
1063 goto err;
1064 break;
1065 case snd_soc_dapm_hp:
1066 case snd_soc_dapm_mic:
1067 case snd_soc_dapm_line:
1068 case snd_soc_dapm_spk:
1069 list_add(&path->list, &codec->dapm_paths);
1070 list_add(&path->list_sink, &wsink->sources);
1071 list_add(&path->list_source, &wsource->sinks);
1072 path->connect = 0;
1073 return 0;
1074 }
1075 return 0;
1076
1077err:
1078 printk(KERN_WARNING "asoc: no dapm match for %s --> %s --> %s\n", source,
1079 control, sink);
1080 kfree(path);
1081 return ret;
1082}
Mark Brown105f1c22008-05-13 14:52:19 +02001083
1084/**
Mark Brown105f1c22008-05-13 14:52:19 +02001085 * snd_soc_dapm_add_routes - Add routes between DAPM widgets
1086 * @codec: codec
1087 * @route: audio routes
1088 * @num: number of routes
1089 *
1090 * Connects 2 dapm widgets together via a named audio path. The sink is
1091 * the widget receiving the audio signal, whilst the source is the sender
1092 * of the audio signal.
1093 *
1094 * Returns 0 for success else error. On error all resources can be freed
1095 * with a call to snd_soc_card_free().
1096 */
1097int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
1098 const struct snd_soc_dapm_route *route, int num)
1099{
1100 int i, ret;
1101
1102 for (i = 0; i < num; i++) {
1103 ret = snd_soc_dapm_add_route(codec, route->sink,
1104 route->control, route->source);
1105 if (ret < 0) {
1106 printk(KERN_ERR "Failed to add route %s->%s\n",
1107 route->source,
1108 route->sink);
1109 return ret;
1110 }
1111 route++;
1112 }
1113
1114 return 0;
1115}
1116EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
1117
1118/**
Richard Purdie2b97eab2006-10-06 18:32:18 +02001119 * snd_soc_dapm_new_widgets - add new dapm widgets
1120 * @codec: audio codec
1121 *
1122 * Checks the codec for any new dapm widgets and creates them if found.
1123 *
1124 * Returns 0 for success.
1125 */
1126int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
1127{
1128 struct snd_soc_dapm_widget *w;
1129
Richard Purdie2b97eab2006-10-06 18:32:18 +02001130 list_for_each_entry(w, &codec->dapm_widgets, list)
1131 {
1132 if (w->new)
1133 continue;
1134
1135 switch(w->id) {
1136 case snd_soc_dapm_switch:
1137 case snd_soc_dapm_mixer:
1138 dapm_new_mixer(codec, w);
1139 break;
1140 case snd_soc_dapm_mux:
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001141 case snd_soc_dapm_value_mux:
Richard Purdie2b97eab2006-10-06 18:32:18 +02001142 dapm_new_mux(codec, w);
1143 break;
1144 case snd_soc_dapm_adc:
1145 case snd_soc_dapm_dac:
1146 case snd_soc_dapm_pga:
1147 dapm_new_pga(codec, w);
1148 break;
1149 case snd_soc_dapm_input:
1150 case snd_soc_dapm_output:
1151 case snd_soc_dapm_micbias:
1152 case snd_soc_dapm_spk:
1153 case snd_soc_dapm_hp:
1154 case snd_soc_dapm_mic:
1155 case snd_soc_dapm_line:
1156 case snd_soc_dapm_vmid:
1157 case snd_soc_dapm_pre:
1158 case snd_soc_dapm_post:
1159 break;
1160 }
1161 w->new = 1;
1162 }
1163
1164 dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001165 return 0;
1166}
1167EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
1168
1169/**
1170 * snd_soc_dapm_get_volsw - dapm mixer get callback
1171 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00001172 * @ucontrol: control element information
Richard Purdie2b97eab2006-10-06 18:32:18 +02001173 *
1174 * Callback to get the value of a dapm mixer control.
1175 *
1176 * Returns 0 for success.
1177 */
1178int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
1179 struct snd_ctl_elem_value *ucontrol)
1180{
1181 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
Jon Smirl4eaa9812008-07-29 11:42:26 +01001182 struct soc_mixer_control *mc =
1183 (struct soc_mixer_control *)kcontrol->private_value;
Jon Smirl815ecf82008-07-29 10:22:24 -04001184 unsigned int reg = mc->reg;
1185 unsigned int shift = mc->shift;
1186 unsigned int rshift = mc->rshift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01001187 int max = mc->max;
Jon Smirl815ecf82008-07-29 10:22:24 -04001188 unsigned int invert = mc->invert;
1189 unsigned int mask = (1 << fls(max)) - 1;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001190
1191 /* return the saved value if we are powered down */
1192 if (widget->id == snd_soc_dapm_pga && !widget->power) {
1193 ucontrol->value.integer.value[0] = widget->saved_value;
1194 return 0;
1195 }
1196
1197 ucontrol->value.integer.value[0] =
1198 (snd_soc_read(widget->codec, reg) >> shift) & mask;
1199 if (shift != rshift)
1200 ucontrol->value.integer.value[1] =
1201 (snd_soc_read(widget->codec, reg) >> rshift) & mask;
1202 if (invert) {
1203 ucontrol->value.integer.value[0] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001204 max - ucontrol->value.integer.value[0];
Richard Purdie2b97eab2006-10-06 18:32:18 +02001205 if (shift != rshift)
1206 ucontrol->value.integer.value[1] =
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001207 max - ucontrol->value.integer.value[1];
Richard Purdie2b97eab2006-10-06 18:32:18 +02001208 }
1209
1210 return 0;
1211}
1212EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
1213
1214/**
1215 * snd_soc_dapm_put_volsw - dapm mixer set callback
1216 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00001217 * @ucontrol: control element information
Richard Purdie2b97eab2006-10-06 18:32:18 +02001218 *
1219 * Callback to set the value of a dapm mixer control.
1220 *
1221 * Returns 0 for success.
1222 */
1223int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
1224 struct snd_ctl_elem_value *ucontrol)
1225{
1226 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
Jon Smirl4eaa9812008-07-29 11:42:26 +01001227 struct soc_mixer_control *mc =
1228 (struct soc_mixer_control *)kcontrol->private_value;
Jon Smirl815ecf82008-07-29 10:22:24 -04001229 unsigned int reg = mc->reg;
1230 unsigned int shift = mc->shift;
1231 unsigned int rshift = mc->rshift;
Jon Smirl4eaa9812008-07-29 11:42:26 +01001232 int max = mc->max;
Jon Smirl815ecf82008-07-29 10:22:24 -04001233 unsigned int mask = (1 << fls(max)) - 1;
1234 unsigned int invert = mc->invert;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001235 unsigned short val, val2, val_mask;
1236 int ret;
1237
1238 val = (ucontrol->value.integer.value[0] & mask);
1239
1240 if (invert)
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001241 val = max - val;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001242 val_mask = mask << shift;
1243 val = val << shift;
1244 if (shift != rshift) {
1245 val2 = (ucontrol->value.integer.value[1] & mask);
1246 if (invert)
Philipp Zabela7a4ac82008-01-10 14:37:42 +01001247 val2 = max - val2;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001248 val_mask |= mask << rshift;
1249 val |= val2 << rshift;
1250 }
1251
1252 mutex_lock(&widget->codec->mutex);
1253 widget->value = val;
1254
1255 /* save volume value if the widget is powered down */
1256 if (widget->id == snd_soc_dapm_pga && !widget->power) {
1257 widget->saved_value = val;
1258 mutex_unlock(&widget->codec->mutex);
1259 return 1;
1260 }
1261
1262 dapm_mixer_update_power(widget, kcontrol, reg, val_mask, val, invert);
1263 if (widget->event) {
1264 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
Laim Girdwood9af6d952008-01-10 14:41:02 +01001265 ret = widget->event(widget, kcontrol,
1266 SND_SOC_DAPM_PRE_REG);
1267 if (ret < 0) {
1268 ret = 1;
Richard Purdie2b97eab2006-10-06 18:32:18 +02001269 goto out;
Laim Girdwood9af6d952008-01-10 14:41:02 +01001270 }
Richard Purdie2b97eab2006-10-06 18:32:18 +02001271 }
1272 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1273 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
Laim Girdwood9af6d952008-01-10 14:41:02 +01001274 ret = widget->event(widget, kcontrol,
1275 SND_SOC_DAPM_POST_REG);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001276 } else
1277 ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1278
1279out:
1280 mutex_unlock(&widget->codec->mutex);
1281 return ret;
1282}
1283EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
1284
1285/**
1286 * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
1287 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00001288 * @ucontrol: control element information
Richard Purdie2b97eab2006-10-06 18:32:18 +02001289 *
1290 * Callback to get the value of a dapm enumerated double mixer control.
1291 *
1292 * Returns 0 for success.
1293 */
1294int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
1295 struct snd_ctl_elem_value *ucontrol)
1296{
1297 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1298 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1299 unsigned short val, bitmask;
1300
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001301 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001302 ;
1303 val = snd_soc_read(widget->codec, e->reg);
1304 ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
1305 if (e->shift_l != e->shift_r)
1306 ucontrol->value.enumerated.item[1] =
1307 (val >> e->shift_r) & (bitmask - 1);
1308
1309 return 0;
1310}
1311EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
1312
1313/**
1314 * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
1315 * @kcontrol: mixer control
Mark Brownac11a2b2009-01-01 12:18:17 +00001316 * @ucontrol: control element information
Richard Purdie2b97eab2006-10-06 18:32:18 +02001317 *
1318 * Callback to set the value of a dapm enumerated double mixer control.
1319 *
1320 * Returns 0 for success.
1321 */
1322int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
1323 struct snd_ctl_elem_value *ucontrol)
1324{
1325 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1326 struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
1327 unsigned short val, mux;
1328 unsigned short mask, bitmask;
1329 int ret = 0;
1330
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001331 for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001332 ;
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001333 if (ucontrol->value.enumerated.item[0] > e->max - 1)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001334 return -EINVAL;
1335 mux = ucontrol->value.enumerated.item[0];
1336 val = mux << e->shift_l;
1337 mask = (bitmask - 1) << e->shift_l;
1338 if (e->shift_l != e->shift_r) {
Jon Smirlf8ba0b72008-07-29 11:42:27 +01001339 if (ucontrol->value.enumerated.item[1] > e->max - 1)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001340 return -EINVAL;
1341 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
1342 mask |= (bitmask - 1) << e->shift_r;
1343 }
1344
1345 mutex_lock(&widget->codec->mutex);
1346 widget->value = val;
Richard Zhaocb01e2b2008-10-07 08:05:20 +08001347 dapm_mux_update_power(widget, kcontrol, mask, mux, val, e);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001348 if (widget->event) {
1349 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
Laim Girdwood9af6d952008-01-10 14:41:02 +01001350 ret = widget->event(widget,
1351 kcontrol, SND_SOC_DAPM_PRE_REG);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001352 if (ret < 0)
1353 goto out;
1354 }
1355 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1356 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
Laim Girdwood9af6d952008-01-10 14:41:02 +01001357 ret = widget->event(widget,
1358 kcontrol, SND_SOC_DAPM_POST_REG);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001359 } else
1360 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1361
1362out:
1363 mutex_unlock(&widget->codec->mutex);
1364 return ret;
1365}
1366EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
1367
1368/**
Peter Ujfalusi2e72f8e2009-01-05 09:54:57 +02001369 * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
1370 * callback
1371 * @kcontrol: mixer control
1372 * @ucontrol: control element information
1373 *
1374 * Callback to get the value of a dapm semi enumerated double mixer control.
1375 *
1376 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1377 * used for handling bitfield coded enumeration for example.
1378 *
1379 * Returns 0 for success.
1380 */
1381int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
1382 struct snd_ctl_elem_value *ucontrol)
1383{
1384 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1385 struct soc_value_enum *e = (struct soc_value_enum *)
1386 kcontrol->private_value;
1387 unsigned short reg_val, val, mux;
1388
1389 reg_val = snd_soc_read(widget->codec, e->reg);
1390 val = (reg_val >> e->shift_l) & e->mask;
1391 for (mux = 0; mux < e->max; mux++) {
1392 if (val == e->values[mux])
1393 break;
1394 }
1395 ucontrol->value.enumerated.item[0] = mux;
1396 if (e->shift_l != e->shift_r) {
1397 val = (reg_val >> e->shift_r) & e->mask;
1398 for (mux = 0; mux < e->max; mux++) {
1399 if (val == e->values[mux])
1400 break;
1401 }
1402 ucontrol->value.enumerated.item[1] = mux;
1403 }
1404
1405 return 0;
1406}
1407EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
1408
1409/**
1410 * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
1411 * callback
1412 * @kcontrol: mixer control
1413 * @ucontrol: control element information
1414 *
1415 * Callback to set the value of a dapm semi enumerated double mixer control.
1416 *
1417 * Semi enumerated mixer: the enumerated items are referred as values. Can be
1418 * used for handling bitfield coded enumeration for example.
1419 *
1420 * Returns 0 for success.
1421 */
1422int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
1423 struct snd_ctl_elem_value *ucontrol)
1424{
1425 struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
1426 struct soc_value_enum *e = (struct soc_value_enum *)
1427 kcontrol->private_value;
1428 unsigned short val, mux;
1429 unsigned short mask;
1430 int ret = 0;
1431
1432 if (ucontrol->value.enumerated.item[0] > e->max - 1)
1433 return -EINVAL;
1434 mux = ucontrol->value.enumerated.item[0];
1435 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
1436 mask = e->mask << e->shift_l;
1437 if (e->shift_l != e->shift_r) {
1438 if (ucontrol->value.enumerated.item[1] > e->max - 1)
1439 return -EINVAL;
1440 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
1441 mask |= e->mask << e->shift_r;
1442 }
1443
1444 mutex_lock(&widget->codec->mutex);
1445 widget->value = val;
1446 dapm_value_mux_update_power(widget, kcontrol, mask, mux, val, e);
1447 if (widget->event) {
1448 if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1449 ret = widget->event(widget,
1450 kcontrol, SND_SOC_DAPM_PRE_REG);
1451 if (ret < 0)
1452 goto out;
1453 }
1454 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1455 if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1456 ret = widget->event(widget,
1457 kcontrol, SND_SOC_DAPM_POST_REG);
1458 } else
1459 ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1460
1461out:
1462 mutex_unlock(&widget->codec->mutex);
1463 return ret;
1464}
1465EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
1466
1467/**
Richard Purdie2b97eab2006-10-06 18:32:18 +02001468 * snd_soc_dapm_new_control - create new dapm control
1469 * @codec: audio codec
1470 * @widget: widget template
1471 *
1472 * Creates a new dapm control based upon the template.
1473 *
1474 * Returns 0 for success else error.
1475 */
1476int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
1477 const struct snd_soc_dapm_widget *widget)
1478{
1479 struct snd_soc_dapm_widget *w;
1480
1481 if ((w = dapm_cnew_widget(widget)) == NULL)
1482 return -ENOMEM;
1483
1484 w->codec = codec;
1485 INIT_LIST_HEAD(&w->sources);
1486 INIT_LIST_HEAD(&w->sinks);
1487 INIT_LIST_HEAD(&w->list);
1488 list_add(&w->list, &codec->dapm_widgets);
1489
1490 /* machine layer set ups unconnected pins and insertions */
1491 w->connected = 1;
1492 return 0;
1493}
1494EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
1495
1496/**
Mark Brown4ba13272008-05-13 14:51:19 +02001497 * snd_soc_dapm_new_controls - create new dapm controls
1498 * @codec: audio codec
1499 * @widget: widget array
1500 * @num: number of widgets
1501 *
1502 * Creates new DAPM controls based upon the templates.
1503 *
1504 * Returns 0 for success else error.
1505 */
1506int snd_soc_dapm_new_controls(struct snd_soc_codec *codec,
1507 const struct snd_soc_dapm_widget *widget,
1508 int num)
1509{
1510 int i, ret;
1511
1512 for (i = 0; i < num; i++) {
1513 ret = snd_soc_dapm_new_control(codec, widget);
Mark Brownb8b33cb2008-12-18 11:19:30 +00001514 if (ret < 0) {
1515 printk(KERN_ERR
1516 "ASoC: Failed to create DAPM control %s: %d\n",
1517 widget->name, ret);
Mark Brown4ba13272008-05-13 14:51:19 +02001518 return ret;
Mark Brownb8b33cb2008-12-18 11:19:30 +00001519 }
Mark Brown4ba13272008-05-13 14:51:19 +02001520 widget++;
1521 }
1522 return 0;
1523}
1524EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
1525
1526
1527/**
Richard Purdie2b97eab2006-10-06 18:32:18 +02001528 * snd_soc_dapm_stream_event - send a stream event to the dapm core
1529 * @codec: audio codec
1530 * @stream: stream name
1531 * @event: stream event
1532 *
1533 * Sends a stream event to the dapm core. The core then makes any
1534 * necessary widget power changes.
1535 *
1536 * Returns 0 for success else error.
1537 */
1538int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
1539 char *stream, int event)
1540{
1541 struct snd_soc_dapm_widget *w;
1542
Seth Forshee11da21a2007-02-02 17:14:19 +01001543 if (stream == NULL)
1544 return 0;
1545
Richard Purdie2b97eab2006-10-06 18:32:18 +02001546 mutex_lock(&codec->mutex);
1547 list_for_each_entry(w, &codec->dapm_widgets, list)
1548 {
1549 if (!w->sname)
1550 continue;
Mark Brownc1286b82008-07-07 19:26:03 +01001551 pr_debug("widget %s\n %s stream %s event %d\n",
1552 w->name, w->sname, stream, event);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001553 if (strstr(w->sname, stream)) {
1554 switch(event) {
1555 case SND_SOC_DAPM_STREAM_START:
1556 w->active = 1;
1557 break;
1558 case SND_SOC_DAPM_STREAM_STOP:
1559 w->active = 0;
1560 break;
1561 case SND_SOC_DAPM_STREAM_SUSPEND:
1562 if (w->active)
1563 w->suspend = 1;
1564 w->active = 0;
1565 break;
1566 case SND_SOC_DAPM_STREAM_RESUME:
1567 if (w->suspend) {
1568 w->active = 1;
1569 w->suspend = 0;
1570 }
1571 break;
1572 case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
1573 break;
1574 case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
1575 break;
1576 }
1577 }
1578 }
1579 mutex_unlock(&codec->mutex);
1580
1581 dapm_power_widgets(codec, event);
Harvey Harrison9bf8e7d2008-03-03 15:32:18 -08001582 dump_dapm(codec, __func__);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001583 return 0;
1584}
1585EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
1586
1587/**
Mark Brown0be98982008-05-19 12:31:28 +02001588 * snd_soc_dapm_set_bias_level - set the bias level for the system
Liam Girdwood0b4d2212008-01-10 14:36:20 +01001589 * @socdev: audio device
Mark Brown0be98982008-05-19 12:31:28 +02001590 * @level: level to configure
Liam Girdwood0b4d2212008-01-10 14:36:20 +01001591 *
Mark Brown0be98982008-05-19 12:31:28 +02001592 * Configure the bias (power) levels for the SoC audio device.
Liam Girdwood0b4d2212008-01-10 14:36:20 +01001593 *
1594 * Returns 0 for success else error.
1595 */
Mark Brown0be98982008-05-19 12:31:28 +02001596int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
1597 enum snd_soc_bias_level level)
Liam Girdwood0b4d2212008-01-10 14:36:20 +01001598{
1599 struct snd_soc_codec *codec = socdev->codec;
Mark Brown87506542008-11-18 20:50:34 +00001600 struct snd_soc_card *card = socdev->card;
Mark Brown0be98982008-05-19 12:31:28 +02001601 int ret = 0;
Liam Girdwood0b4d2212008-01-10 14:36:20 +01001602
Mark Brown87506542008-11-18 20:50:34 +00001603 if (card->set_bias_level)
1604 ret = card->set_bias_level(card, level);
Mark Brown0be98982008-05-19 12:31:28 +02001605 if (ret == 0 && codec->set_bias_level)
1606 ret = codec->set_bias_level(codec, level);
1607
1608 return ret;
Liam Girdwood0b4d2212008-01-10 14:36:20 +01001609}
Liam Girdwood0b4d2212008-01-10 14:36:20 +01001610
1611/**
Liam Girdwooda5302182008-07-07 13:35:17 +01001612 * snd_soc_dapm_enable_pin - enable pin.
Mark Brownac11a2b2009-01-01 12:18:17 +00001613 * @codec: SoC codec
Liam Girdwooda5302182008-07-07 13:35:17 +01001614 * @pin: pin name
Richard Purdie2b97eab2006-10-06 18:32:18 +02001615 *
Liam Girdwooda5302182008-07-07 13:35:17 +01001616 * Enables input/output pin and it's parents or children widgets iff there is
1617 * a valid audio route and active audio stream.
1618 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1619 * do any widget power switching.
Richard Purdie2b97eab2006-10-06 18:32:18 +02001620 */
Liam Girdwooda5302182008-07-07 13:35:17 +01001621int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, char *pin)
Richard Purdie2b97eab2006-10-06 18:32:18 +02001622{
Liam Girdwooda5302182008-07-07 13:35:17 +01001623 return snd_soc_dapm_set_pin(codec, pin, 1);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001624}
Liam Girdwooda5302182008-07-07 13:35:17 +01001625EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
Richard Purdie2b97eab2006-10-06 18:32:18 +02001626
1627/**
Liam Girdwooda5302182008-07-07 13:35:17 +01001628 * snd_soc_dapm_disable_pin - disable pin.
1629 * @codec: SoC codec
1630 * @pin: pin name
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02001631 *
Liam Girdwooda5302182008-07-07 13:35:17 +01001632 * Disables input/output pin and it's parents or children widgets.
1633 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1634 * do any widget power switching.
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02001635 */
Liam Girdwooda5302182008-07-07 13:35:17 +01001636int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, char *pin)
1637{
1638 return snd_soc_dapm_set_pin(codec, pin, 0);
1639}
1640EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
1641
1642/**
Mark Brown5817b522008-09-24 11:23:11 +01001643 * snd_soc_dapm_nc_pin - permanently disable pin.
1644 * @codec: SoC codec
1645 * @pin: pin name
1646 *
1647 * Marks the specified pin as being not connected, disabling it along
1648 * any parent or child widgets. At present this is identical to
1649 * snd_soc_dapm_disable_pin() but in future it will be extended to do
1650 * additional things such as disabling controls which only affect
1651 * paths through the pin.
1652 *
1653 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1654 * do any widget power switching.
1655 */
1656int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, char *pin)
1657{
1658 return snd_soc_dapm_set_pin(codec, pin, 0);
1659}
1660EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
1661
1662/**
Liam Girdwooda5302182008-07-07 13:35:17 +01001663 * snd_soc_dapm_get_pin_status - get audio pin status
1664 * @codec: audio codec
1665 * @pin: audio signal pin endpoint (or start point)
1666 *
1667 * Get audio pin status - connected or disconnected.
1668 *
1669 * Returns 1 for connected otherwise 0.
1670 */
1671int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, char *pin)
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02001672{
1673 struct snd_soc_dapm_widget *w;
1674
1675 list_for_each_entry(w, &codec->dapm_widgets, list) {
Liam Girdwooda5302182008-07-07 13:35:17 +01001676 if (!strcmp(w->name, pin))
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02001677 return w->connected;
1678 }
1679
1680 return 0;
1681}
Liam Girdwooda5302182008-07-07 13:35:17 +01001682EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
Graeme Gregoryeeec12b2008-04-30 19:27:40 +02001683
1684/**
Richard Purdie2b97eab2006-10-06 18:32:18 +02001685 * snd_soc_dapm_free - free dapm resources
1686 * @socdev: SoC device
1687 *
1688 * Free all dapm widgets and resources.
1689 */
1690void snd_soc_dapm_free(struct snd_soc_device *socdev)
1691{
1692 struct snd_soc_codec *codec = socdev->codec;
1693
1694 snd_soc_dapm_sys_remove(socdev->dev);
1695 dapm_free_widgets(codec);
1696}
1697EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
1698
1699/* Module information */
Liam Girdwoodd3311242008-10-12 13:17:36 +01001700MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
Richard Purdie2b97eab2006-10-06 18:32:18 +02001701MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
1702MODULE_LICENSE("GPL");