114
127
* snd_soc_dapm_set_bias_level - set the bias level for the system
115
* @socdev: audio device
128
* @card: audio device
116
129
* @level: level to configure
118
131
* Configure the bias (power) levels for the SoC audio device.
120
133
* Returns 0 for success else error.
122
static int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
135
static int snd_soc_dapm_set_bias_level(struct snd_soc_card *card,
136
struct snd_soc_dapm_context *dapm,
123
137
enum snd_soc_bias_level level)
125
struct snd_soc_card *card = socdev->card;
126
struct snd_soc_codec *codec = socdev->card->codec;
130
142
case SND_SOC_BIAS_ON:
131
dev_dbg(socdev->dev, "Setting full bias\n");
143
dev_dbg(dapm->dev, "Setting full bias\n");
133
145
case SND_SOC_BIAS_PREPARE:
134
dev_dbg(socdev->dev, "Setting bias prepare\n");
146
dev_dbg(dapm->dev, "Setting bias prepare\n");
136
148
case SND_SOC_BIAS_STANDBY:
137
dev_dbg(socdev->dev, "Setting standby bias\n");
149
dev_dbg(dapm->dev, "Setting standby bias\n");
139
151
case SND_SOC_BIAS_OFF:
140
dev_dbg(socdev->dev, "Setting bias off\n");
152
dev_dbg(dapm->dev, "Setting bias off\n");
143
dev_err(socdev->dev, "Setting invalid bias %d\n", level);
155
dev_err(dapm->dev, "Setting invalid bias %d\n", level);
147
if (card->set_bias_level)
159
trace_snd_soc_bias_level_start(card, level);
161
if (card && card->set_bias_level)
148
162
ret = card->set_bias_level(card, level);
150
if (codec->set_bias_level)
151
ret = codec->set_bias_level(codec, level);
164
if (dapm->codec && dapm->codec->driver->set_bias_level)
165
ret = dapm->codec->driver->set_bias_level(dapm->codec, level);
153
codec->bias_level = level;
167
dapm->bias_level = level;
170
if (card && card->set_bias_level_post)
171
ret = card->set_bias_level_post(card, level);
174
trace_snd_soc_bias_level_done(card, level);
221
case snd_soc_dapm_virt_mux: {
222
struct soc_enum *e = (struct soc_enum *)w->kcontrols[i].private_value;
225
/* since a virtual mux has no backing registers to
226
* decide which path to connect, it will try to match
227
* with the first enumeration. This is to ensure
228
* that the default mux choice (the first) will be
229
* correctly powered up during initialization.
231
if (!strcmp(p->name, e->texts[0]))
201
235
case snd_soc_dapm_value_mux: {
202
236
struct soc_enum *e = (struct soc_enum *)
203
237
w->kcontrols[i].private_value;
312
349
change = old != new;
314
pop_dbg(codec->pop_time, "pop test %s : %s in %d ms\n",
351
pop_dbg(dapm->dev, card->pop_time,
352
"pop test %s : %s in %d ms\n",
315
353
widget->name, widget->power ? "on" : "off",
317
pop_wait(codec->pop_time);
355
pop_wait(card->pop_time);
318
356
snd_soc_write(codec, widget->reg, new);
320
pr_debug("reg %x old %x new %x change %d\n", widget->reg,
358
dev_dbg(dapm->dev, "reg %x old %x new %x change %d\n", widget->reg,
325
363
/* create new dapm mixer control */
326
static int dapm_new_mixer(struct snd_soc_codec *codec,
364
static int dapm_new_mixer(struct snd_soc_dapm_context *dapm,
327
365
struct snd_soc_dapm_widget *w)
331
369
struct snd_soc_dapm_path *path;
370
struct snd_card *card = dapm->codec->card->snd_card;
333
372
/* add kcontrol */
334
373
for (i = 0; i < w->num_kcontrols; i++) {
387
426
/* create new dapm mux control */
388
static int dapm_new_mux(struct snd_soc_codec *codec,
427
static int dapm_new_mux(struct snd_soc_dapm_context *dapm,
389
428
struct snd_soc_dapm_widget *w)
391
430
struct snd_soc_dapm_path *path = NULL;
392
431
struct snd_kcontrol *kcontrol;
432
struct snd_card *card = dapm->codec->card->snd_card;
395
435
if (!w->num_kcontrols) {
396
printk(KERN_ERR "asoc: mux %s has no controls\n", w->name);
436
dev_err(dapm->dev, "asoc: mux %s has no controls\n", w->name);
400
440
kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
401
ret = snd_ctl_add(codec->card, kcontrol);
441
ret = snd_ctl_add(card, kcontrol);
411
printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name);
452
dev_err(dapm->dev, "asoc: failed to add kcontrol %s\n", w->name);
415
456
/* create new dapm volume control */
416
static int dapm_new_pga(struct snd_soc_codec *codec,
457
static int dapm_new_pga(struct snd_soc_dapm_context *dapm,
417
458
struct snd_soc_dapm_widget *w)
419
460
if (w->num_kcontrols)
420
pr_err("asoc: PGA controls not supported: '%s'\n", w->name);
461
dev_err(w->dapm->dev,
462
"asoc: PGA controls not supported: '%s'\n", w->name);
425
467
/* reset 'walked' bit for each dapm path */
426
static inline void dapm_clear_walk(struct snd_soc_codec *codec)
468
static inline void dapm_clear_walk(struct snd_soc_dapm_context *dapm)
428
470
struct snd_soc_dapm_path *p;
430
list_for_each_entry(p, &codec->dapm_paths, list)
472
list_for_each_entry(p, &dapm->card->paths, list)
476
/* We implement power down on suspend by checking the power state of
477
* the ALSA card - when we are suspending the ALSA state for the card
480
static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
482
int level = snd_power_get_state(widget->dapm->codec->card->snd_card);
485
case SNDRV_CTL_POWER_D3hot:
486
case SNDRV_CTL_POWER_D3cold:
487
if (widget->ignore_suspend)
488
dev_dbg(widget->dapm->dev, "%s ignoring suspend\n",
490
return widget->ignore_suspend;
435
497
* Recursively check for a completed path to an active or physically connected
436
498
* output widget. Returns number of complete paths.
692
754
list_add_tail(&new_widget->power_list, list);
757
static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
758
struct snd_soc_dapm_widget *w, int event)
760
struct snd_soc_card *card = dapm->card;
765
case SND_SOC_DAPM_PRE_PMU:
769
case SND_SOC_DAPM_POST_PMU:
770
ev_name = "POST_PMU";
773
case SND_SOC_DAPM_PRE_PMD:
777
case SND_SOC_DAPM_POST_PMD:
778
ev_name = "POST_PMD";
786
if (w->power != power)
789
if (w->event && (w->event_flags & event)) {
790
pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
792
trace_snd_soc_dapm_widget_event_start(w, event);
793
ret = w->event(w, NULL, event);
794
trace_snd_soc_dapm_widget_event_done(w, event);
796
pr_err("%s: %s event failed: %d\n",
797
ev_name, w->name, ret);
695
801
/* Apply the coalesced changes from a DAPM sequence */
696
static void dapm_seq_run_coalesced(struct snd_soc_codec *codec,
802
static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
697
803
struct list_head *pending)
805
struct snd_soc_card *card = dapm->card;
699
806
struct snd_soc_dapm_widget *w;
701
808
unsigned int value = 0;
702
809
unsigned int mask = 0;
703
810
unsigned int cur_mask;
719
826
value |= cur_mask;
721
pop_dbg(codec->pop_time,
828
pop_dbg(dapm->dev, card->pop_time,
722
829
"pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
723
830
w->name, reg, value, mask);
725
/* power up pre event */
726
if (w->power && w->event &&
727
(w->event_flags & SND_SOC_DAPM_PRE_PMU)) {
728
pop_dbg(codec->pop_time, "pop test : %s PRE_PMU\n",
730
ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
732
pr_err("%s: pre event failed: %d\n",
736
/* power down pre event */
737
if (!w->power && w->event &&
738
(w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
739
pop_dbg(codec->pop_time, "pop test : %s PRE_PMD\n",
741
ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
743
pr_err("%s: pre event failed: %d\n",
832
/* Check for events */
833
dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
834
dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
749
pop_dbg(codec->pop_time,
838
pop_dbg(dapm->dev, card->pop_time,
750
839
"pop test : Applying 0x%x/0x%x to %x in %dms\n",
751
value, mask, reg, codec->pop_time);
752
pop_wait(codec->pop_time);
753
snd_soc_update_bits(codec, reg, mask, value);
840
value, mask, reg, card->pop_time);
841
pop_wait(card->pop_time);
842
snd_soc_update_bits(dapm->codec, reg, mask, value);
756
845
list_for_each_entry(w, pending, power_list) {
757
/* power up post event */
758
if (w->power && w->event &&
759
(w->event_flags & SND_SOC_DAPM_POST_PMU)) {
760
pop_dbg(codec->pop_time, "pop test : %s POST_PMU\n",
763
NULL, SND_SOC_DAPM_POST_PMU);
765
pr_err("%s: post event failed: %d\n",
769
/* power down post event */
770
if (!w->power && w->event &&
771
(w->event_flags & SND_SOC_DAPM_POST_PMD)) {
772
pop_dbg(codec->pop_time, "pop test : %s POST_PMD\n",
774
ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
776
pr_err("%s: post event failed: %d\n",
846
dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
847
dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
787
856
* Currently anything that requires more than a single write is not
790
static void dapm_seq_run(struct snd_soc_codec *codec, struct list_head *list,
791
int event, int sort[])
859
static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
860
struct list_head *list, int event, int sort[])
793
862
struct snd_soc_dapm_widget *w, *n;
794
863
LIST_HEAD(pending);
795
864
int cur_sort = -1;
796
865
int cur_reg = SND_SOC_NOPM;
866
struct snd_soc_dapm_context *cur_dapm = NULL;
799
869
list_for_each_entry_safe(w, n, list, power_list) {
802
872
/* Do we need to apply any queued changes? */
803
if (sort[w->id] != cur_sort || w->reg != cur_reg) {
873
if (sort[w->id] != cur_sort || w->reg != cur_reg ||
874
w->dapm != cur_dapm) {
804
875
if (!list_empty(&pending))
805
dapm_seq_run_coalesced(codec, &pending);
876
dapm_seq_run_coalesced(cur_dapm, &pending);
807
878
INIT_LIST_HEAD(&pending);
809
880
cur_reg = SND_SOC_NOPM;
850
922
/* Queue it up for application */
851
923
cur_sort = sort[w->id];
852
924
cur_reg = w->reg;
853
926
list_move(&w->power_list, &pending);
858
pr_err("Failed to apply widget power: %d\n",
931
dev_err(w->dapm->dev,
932
"Failed to apply widget power: %d\n", ret);
862
935
if (!list_empty(&pending))
863
dapm_seq_run_coalesced(codec, &pending);
936
dapm_seq_run_coalesced(dapm, &pending);
939
static void dapm_widget_update(struct snd_soc_dapm_context *dapm)
941
struct snd_soc_dapm_update *update = dapm->update;
942
struct snd_soc_dapm_widget *w;
951
(w->event_flags & SND_SOC_DAPM_PRE_REG)) {
952
ret = w->event(w, update->kcontrol, SND_SOC_DAPM_PRE_REG);
954
pr_err("%s DAPM pre-event failed: %d\n",
958
ret = snd_soc_update_bits(w->codec, update->reg, update->mask,
961
pr_err("%s DAPM update failed: %d\n", w->name, ret);
964
(w->event_flags & SND_SOC_DAPM_POST_REG)) {
965
ret = w->event(w, update->kcontrol, SND_SOC_DAPM_POST_REG);
967
pr_err("%s DAPM post-event failed: %d\n",
867
975
* Scan each dapm widget for complete audio path.
872
980
* o Input pin to Output pin (bypass, sidetone)
873
981
* o DAC to ADC (loopback).
875
static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
983
static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
877
struct snd_soc_device *socdev = codec->socdev;
985
struct snd_soc_card *card = dapm->codec->card;
878
986
struct snd_soc_dapm_widget *w;
987
struct snd_soc_dapm_context *d;
879
988
LIST_HEAD(up_list);
880
989
LIST_HEAD(down_list);
993
trace_snd_soc_dapm_start(card);
995
list_for_each_entry(d, &card->dapm_list, list)
885
999
/* Check which widgets we need to power and store them in
886
1000
* lists indicating if they should be powered up or down.
888
list_for_each_entry(w, &codec->dapm_widgets, list) {
1002
list_for_each_entry(w, &card->widgets, list) {
889
1003
switch (w->id) {
890
1004
case snd_soc_dapm_pre:
891
1005
dapm_seq_insert(w, &down_list, dapm_down_seq);
959
if (sys_power && codec->bias_level == SND_SOC_BIAS_OFF) {
960
ret = snd_soc_dapm_set_bias_level(socdev,
961
SND_SOC_BIAS_STANDBY);
963
pr_err("Failed to turn on bias: %d\n", ret);
1068
list_for_each_entry(d, &dapm->card->dapm_list, list) {
1069
if (d->dev_power && d->bias_level == SND_SOC_BIAS_OFF) {
1070
ret = snd_soc_dapm_set_bias_level(card, d,
1071
SND_SOC_BIAS_STANDBY);
1074
"Failed to turn on bias: %d\n", ret);
966
/* If we're changing to all on or all off then prepare */
967
if ((sys_power && codec->bias_level == SND_SOC_BIAS_STANDBY) ||
968
(!sys_power && codec->bias_level == SND_SOC_BIAS_ON)) {
969
ret = snd_soc_dapm_set_bias_level(socdev,
970
SND_SOC_BIAS_PREPARE);
972
pr_err("Failed to prepare bias: %d\n", ret);
1077
/* If we're changing to all on or all off then prepare */
1078
if ((d->dev_power && d->bias_level == SND_SOC_BIAS_STANDBY) ||
1079
(!d->dev_power && d->bias_level == SND_SOC_BIAS_ON)) {
1080
ret = snd_soc_dapm_set_bias_level(card, d,
1081
SND_SOC_BIAS_PREPARE);
1084
"Failed to prepare bias: %d\n", ret);
975
1088
/* Power down widgets first; try to avoid amplifying pops. */
976
dapm_seq_run(codec, &down_list, event, dapm_down_seq);
1089
dapm_seq_run(dapm, &down_list, event, dapm_down_seq);
1091
dapm_widget_update(dapm);
978
1093
/* Now power up. */
979
dapm_seq_run(codec, &up_list, event, dapm_up_seq);
981
/* If we just powered the last thing off drop to standby bias */
982
if (codec->bias_level == SND_SOC_BIAS_PREPARE && !sys_power) {
983
ret = snd_soc_dapm_set_bias_level(socdev,
984
SND_SOC_BIAS_STANDBY);
986
pr_err("Failed to apply standby bias: %d\n", ret);
989
/* If we're in standby and can support bias off then do that */
990
if (codec->bias_level == SND_SOC_BIAS_STANDBY &&
991
codec->idle_bias_off) {
992
ret = snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_OFF);
994
pr_err("Failed to turn off bias: %d\n", ret);
997
/* If we just powered up then move to active bias */
998
if (codec->bias_level == SND_SOC_BIAS_PREPARE && sys_power) {
999
ret = snd_soc_dapm_set_bias_level(socdev,
1002
pr_err("Failed to apply active bias: %d\n", ret);
1005
pop_dbg(codec->pop_time, "DAPM sequencing finished, waiting %dms\n",
1007
pop_wait(codec->pop_time);
1094
dapm_seq_run(dapm, &up_list, event, dapm_up_seq);
1096
list_for_each_entry(d, &dapm->card->dapm_list, list) {
1097
/* If we just powered the last thing off drop to standby bias */
1098
if (d->bias_level == SND_SOC_BIAS_PREPARE && !d->dev_power) {
1099
ret = snd_soc_dapm_set_bias_level(card, d,
1100
SND_SOC_BIAS_STANDBY);
1103
"Failed to apply standby bias: %d\n",
1107
/* If we're in standby and can support bias off then do that */
1108
if (d->bias_level == SND_SOC_BIAS_STANDBY &&
1110
ret = snd_soc_dapm_set_bias_level(card, d,
1114
"Failed to turn off bias: %d\n", ret);
1117
/* If we just powered up then move to active bias */
1118
if (d->bias_level == SND_SOC_BIAS_PREPARE && d->dev_power) {
1119
ret = snd_soc_dapm_set_bias_level(card, d,
1123
"Failed to apply active bias: %d\n",
1128
pop_dbg(dapm->dev, card->pop_time,
1129
"DAPM sequencing finished, waiting %dms\n", card->pop_time);
1130
pop_wait(card->pop_time);
1132
trace_snd_soc_dapm_done(card);
1080
1205
static const struct file_operations dapm_widget_power_fops = {
1081
1206
.open = dapm_widget_power_open_file,
1082
1207
.read = dapm_widget_power_read_file,
1208
.llseek = default_llseek,
1085
void snd_soc_dapm_debugfs_init(struct snd_soc_codec *codec)
1211
void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm)
1087
1213
struct snd_soc_dapm_widget *w;
1088
1214
struct dentry *d;
1090
if (!codec->debugfs_dapm)
1216
if (!dapm->debugfs_dapm)
1093
list_for_each_entry(w, &codec->dapm_widgets, list) {
1219
list_for_each_entry(w, &dapm->card->widgets, list) {
1220
if (!w->name || w->dapm != dapm)
1097
1223
d = debugfs_create_file(w->name, 0444,
1098
codec->debugfs_dapm, w,
1224
dapm->debugfs_dapm, w,
1099
1225
&dapm_widget_power_fops);
1102
"ASoC: Failed to create %s debugfs file\n",
1227
dev_warn(w->dapm->dev,
1228
"ASoC: Failed to create %s debugfs file\n",
1107
void snd_soc_dapm_debugfs_init(struct snd_soc_codec *codec)
1233
void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm)
1179
1306
static ssize_t dapm_widget_show(struct device *dev,
1180
1307
struct device_attribute *attr, char *buf)
1182
struct snd_soc_device *devdata = dev_get_drvdata(dev);
1183
struct snd_soc_codec *codec = devdata->card->codec;
1309
struct snd_soc_pcm_runtime *rtd =
1310
container_of(dev, struct snd_soc_pcm_runtime, dev);
1311
struct snd_soc_codec *codec =rtd->codec;
1184
1312
struct snd_soc_dapm_widget *w;
1186
1314
char *state = "not set";
1188
list_for_each_entry(w, &codec->dapm_widgets, list) {
1316
list_for_each_entry(w, &codec->card->widgets, list) {
1317
if (w->dapm != &codec->dapm)
1190
1320
/* only display widgets that burnm power */
1191
1321
switch (w->id) {
1243
1374
/* free all dapm widgets and resources */
1244
static void dapm_free_widgets(struct snd_soc_codec *codec)
1375
static void dapm_free_widgets(struct snd_soc_dapm_context *dapm)
1246
1377
struct snd_soc_dapm_widget *w, *next_w;
1247
1378
struct snd_soc_dapm_path *p, *next_p;
1249
list_for_each_entry_safe(w, next_w, &codec->dapm_widgets, list) {
1380
list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) {
1381
if (w->dapm != dapm)
1250
1383
list_del(&w->list);
1385
* remove source and sink paths associated to this widget.
1386
* While removing the path, remove reference to it from both
1387
* source and sink widgets so that path is removed only once.
1389
list_for_each_entry_safe(p, next_p, &w->sources, list_sink) {
1390
list_del(&p->list_sink);
1391
list_del(&p->list_source);
1393
kfree(p->long_name);
1396
list_for_each_entry_safe(p, next_p, &w->sinks, list_source) {
1397
list_del(&p->list_sink);
1398
list_del(&p->list_source);
1400
kfree(p->long_name);
1254
list_for_each_entry_safe(p, next_p, &codec->dapm_paths, list) {
1256
kfree(p->long_name);
1261
static int snd_soc_dapm_set_pin(struct snd_soc_codec *codec,
1408
static int snd_soc_dapm_set_pin(struct snd_soc_dapm_context *dapm,
1262
1409
const char *pin, int status)
1264
1411
struct snd_soc_dapm_widget *w;
1266
list_for_each_entry(w, &codec->dapm_widgets, list) {
1413
list_for_each_entry(w, &dapm->card->widgets, list) {
1414
if (w->dapm != dapm)
1267
1416
if (!strcmp(w->name, pin)) {
1268
pr_debug("dapm: %s: pin %s\n", codec->name, pin);
1417
dev_dbg(w->dapm->dev, "dapm: pin %s = %d\n",
1269
1419
w->connected = status;
1270
1420
/* Allow disabling of forced pins */
1271
1421
if (status == 0)
1277
pr_err("dapm: %s: configuring unknown pin %s\n", codec->name, pin);
1427
dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
1278
1428
return -EINVAL;
1282
1432
* snd_soc_dapm_sync - scan and power dapm paths
1283
* @codec: audio codec
1433
* @dapm: DAPM context
1285
1435
* Walks all dapm audio paths and powers widgets according to their
1286
1436
* stream or path usage.
1288
1438
* Returns 0 for success.
1290
int snd_soc_dapm_sync(struct snd_soc_codec *codec)
1440
int snd_soc_dapm_sync(struct snd_soc_dapm_context *dapm)
1292
return dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
1442
return dapm_power_widgets(dapm, SND_SOC_DAPM_STREAM_NOP);
1294
1444
EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
1296
static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
1446
static int snd_soc_dapm_add_route(struct snd_soc_dapm_context *dapm,
1297
1447
const struct snd_soc_dapm_route *route)
1299
1449
struct snd_soc_dapm_path *path;
1300
1450
struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
1301
const char *sink = route->sink;
1451
struct snd_soc_dapm_widget *wtsource = NULL, *wtsink = NULL;
1302
1453
const char *control = route->control;
1303
const char *source = route->source;
1455
char prefixed_sink[80];
1456
char prefixed_source[80];
1306
/* find src and dest widgets */
1307
list_for_each_entry(w, &codec->dapm_widgets, list) {
1459
if (dapm->codec->name_prefix) {
1460
snprintf(prefixed_sink, sizeof(prefixed_sink), "%s %s",
1461
dapm->codec->name_prefix, route->sink);
1462
sink = prefixed_sink;
1463
snprintf(prefixed_source, sizeof(prefixed_source), "%s %s",
1464
dapm->codec->name_prefix, route->source);
1465
source = prefixed_source;
1468
source = route->source;
1472
* find src and dest widgets over all widgets but favor a widget from
1473
* current DAPM context
1475
list_for_each_entry(w, &dapm->card->widgets, list) {
1309
1476
if (!wsink && !(strcmp(w->name, sink))) {
1478
if (w->dapm == dapm)
1313
1482
if (!wsource && !(strcmp(w->name, source))) {
1484
if (w->dapm == dapm)
1488
/* use widget from another DAPM context if not found from this */
1318
1494
if (wsource == NULL || wsink == NULL)
1319
1495
return -ENODEV;
1368
1545
case snd_soc_dapm_supply:
1369
1546
case snd_soc_dapm_aif_in:
1370
1547
case snd_soc_dapm_aif_out:
1371
list_add(&path->list, &codec->dapm_paths);
1548
list_add(&path->list, &dapm->card->paths);
1372
1549
list_add(&path->list_sink, &wsink->sources);
1373
1550
list_add(&path->list_source, &wsource->sinks);
1374
1551
path->connect = 1;
1376
1553
case snd_soc_dapm_mux:
1554
case snd_soc_dapm_virt_mux:
1377
1555
case snd_soc_dapm_value_mux:
1378
ret = dapm_connect_mux(codec, wsource, wsink, path, control,
1556
ret = dapm_connect_mux(dapm, wsource, wsink, path, control,
1379
1557
&wsink->kcontrols[0]);
1419
1597
* Returns 0 for success else error. On error all resources can be freed
1420
1598
* with a call to snd_soc_card_free().
1422
int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
1600
int snd_soc_dapm_add_routes(struct snd_soc_dapm_context *dapm,
1423
1601
const struct snd_soc_dapm_route *route, int num)
1427
1605
for (i = 0; i < num; i++) {
1428
ret = snd_soc_dapm_add_route(codec, route);
1606
ret = snd_soc_dapm_add_route(dapm, route);
1430
printk(KERN_ERR "Failed to add route %s->%s\n",
1608
dev_err(dapm->dev, "Failed to add route %s->%s\n",
1609
route->source, route->sink);
1593
1765
/* old connection must be powered down */
1594
1766
connect = invert ? 1:0;
1768
update.kcontrol = kcontrol;
1769
update.widget = widget;
1773
widget->dapm->update = &update;
1596
1775
dapm_mixer_update_power(widget, kcontrol, connect);
1777
widget->dapm->update = NULL;
1599
if (widget->event) {
1600
if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1601
ret = widget->event(widget, kcontrol,
1602
SND_SOC_DAPM_PRE_REG);
1608
ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1609
if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1610
ret = widget->event(widget, kcontrol,
1611
SND_SOC_DAPM_POST_REG);
1613
ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
1616
1780
mutex_unlock(&widget->codec->mutex);
1619
1783
EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
1681
1845
mutex_lock(&widget->codec->mutex);
1682
1846
widget->value = val;
1683
1847
change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
1849
update.kcontrol = kcontrol;
1850
update.widget = widget;
1851
update.reg = e->reg;
1854
widget->dapm->update = &update;
1684
1856
dapm_mux_update_power(widget, kcontrol, change, mux, e);
1686
if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1687
ret = widget->event(widget,
1688
kcontrol, SND_SOC_DAPM_PRE_REG);
1693
ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1695
if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1696
ret = widget->event(widget,
1697
kcontrol, SND_SOC_DAPM_POST_REG);
1858
widget->dapm->update = NULL;
1700
1860
mutex_unlock(&widget->codec->mutex);
1703
1863
EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
1827
1987
mutex_lock(&widget->codec->mutex);
1828
1988
widget->value = val;
1829
1989
change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
1991
update.kcontrol = kcontrol;
1992
update.widget = widget;
1993
update.reg = e->reg;
1996
widget->dapm->update = &update;
1830
1998
dapm_mux_update_power(widget, kcontrol, change, mux, e);
1832
if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
1833
ret = widget->event(widget,
1834
kcontrol, SND_SOC_DAPM_PRE_REG);
1839
ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
1841
if (widget->event_flags & SND_SOC_DAPM_POST_REG)
1842
ret = widget->event(widget,
1843
kcontrol, SND_SOC_DAPM_POST_REG);
2000
widget->dapm->update = NULL;
1846
2002
mutex_unlock(&widget->codec->mutex);
1849
2005
EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
1922
2078
* snd_soc_dapm_new_control - create new dapm control
1923
* @codec: audio codec
2079
* @dapm: DAPM context
1924
2080
* @widget: widget template
1926
2082
* Creates a new dapm control based upon the template.
1928
2084
* Returns 0 for success else error.
1930
int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
2086
int snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm,
1931
2087
const struct snd_soc_dapm_widget *widget)
1933
2089
struct snd_soc_dapm_widget *w;
1935
2092
if ((w = dapm_cnew_widget(widget)) == NULL)
1936
2093
return -ENOMEM;
2095
name_len = strlen(widget->name) + 1;
2096
if (dapm->codec->name_prefix)
2097
name_len += 1 + strlen(dapm->codec->name_prefix);
2098
w->name = kmalloc(name_len, GFP_KERNEL);
2099
if (w->name == NULL) {
2103
if (dapm->codec->name_prefix)
2104
snprintf(w->name, name_len, "%s %s",
2105
dapm->codec->name_prefix, widget->name);
2107
snprintf(w->name, name_len, "%s", widget->name);
2111
w->codec = dapm->codec;
1939
2112
INIT_LIST_HEAD(&w->sources);
1940
2113
INIT_LIST_HEAD(&w->sinks);
1941
2114
INIT_LIST_HEAD(&w->list);
1942
list_add(&w->list, &codec->dapm_widgets);
2115
list_add(&w->list, &dapm->card->widgets);
1944
2117
/* machine layer set ups unconnected pins and insertions */
1945
2118
w->connected = 1;
1958
2131
* Returns 0 for success else error.
1960
int snd_soc_dapm_new_controls(struct snd_soc_codec *codec,
2133
int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
1961
2134
const struct snd_soc_dapm_widget *widget,
1966
2139
for (i = 0; i < num; i++) {
1967
ret = snd_soc_dapm_new_control(codec, widget);
2140
ret = snd_soc_dapm_new_control(dapm, widget);
1970
"ASoC: Failed to create DAPM control %s: %d\n",
2143
"ASoC: Failed to create DAPM control %s: %d\n",
1978
2151
EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
1982
* snd_soc_dapm_stream_event - send a stream event to the dapm core
1983
* @codec: audio codec
1984
* @stream: stream name
1985
* @event: stream event
1987
* Sends a stream event to the dapm core. The core then makes any
1988
* necessary widget power changes.
1990
* Returns 0 for success else error.
1992
int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
1993
char *stream, int event)
2153
static void soc_dapm_stream_event(struct snd_soc_dapm_context *dapm,
2154
const char *stream, int event)
1995
2156
struct snd_soc_dapm_widget *w;
2000
mutex_lock(&codec->mutex);
2001
list_for_each_entry(w, &codec->dapm_widgets, list)
2158
list_for_each_entry(w, &dapm->card->widgets, list)
2160
if (!w->sname || w->dapm != dapm)
2005
pr_debug("widget %s\n %s stream %s event %d\n",
2006
w->name, w->sname, stream, event);
2162
dev_dbg(w->dapm->dev, "widget %s\n %s stream %s event %d\n",
2163
w->name, w->sname, stream, event);
2007
2164
if (strstr(w->sname, stream)) {
2008
2165
switch(event) {
2009
2166
case SND_SOC_DAPM_STREAM_START:
2015
2172
case SND_SOC_DAPM_STREAM_SUSPEND:
2020
2173
case SND_SOC_DAPM_STREAM_RESUME:
2026
2174
case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
2028
2175
case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
2034
dapm_power_widgets(codec, event);
2181
dapm_power_widgets(dapm, event);
2185
* snd_soc_dapm_stream_event - send a stream event to the dapm core
2186
* @rtd: PCM runtime data
2187
* @stream: stream name
2188
* @event: stream event
2190
* Sends a stream event to the dapm core. The core then makes any
2191
* necessary widget power changes.
2193
* Returns 0 for success else error.
2195
int snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd,
2196
const char *stream, int event)
2198
struct snd_soc_codec *codec = rtd->codec;
2203
mutex_lock(&codec->mutex);
2204
soc_dapm_stream_event(&codec->dapm, stream, event);
2035
2205
mutex_unlock(&codec->mutex);
2047
2217
* NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2048
2218
* do any widget power switching.
2050
int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, const char *pin)
2220
int snd_soc_dapm_enable_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2052
return snd_soc_dapm_set_pin(codec, pin, 1);
2222
return snd_soc_dapm_set_pin(dapm, pin, 1);
2054
2224
EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
2057
2227
* snd_soc_dapm_force_enable_pin - force a pin to be enabled
2228
* @dapm: DAPM context
2059
2229
* @pin: pin name
2061
2231
* Enables input/output pin regardless of any other state. This is
2065
2235
* NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2066
2236
* do any widget power switching.
2068
int snd_soc_dapm_force_enable_pin(struct snd_soc_codec *codec, const char *pin)
2238
int snd_soc_dapm_force_enable_pin(struct snd_soc_dapm_context *dapm,
2070
2241
struct snd_soc_dapm_widget *w;
2072
list_for_each_entry(w, &codec->dapm_widgets, list) {
2243
list_for_each_entry(w, &dapm->card->widgets, list) {
2244
if (w->dapm != dapm)
2073
2246
if (!strcmp(w->name, pin)) {
2074
pr_debug("dapm: %s: pin %s\n", codec->name, pin);
2247
dev_dbg(w->dapm->dev,
2248
"dapm: force enable pin %s\n", pin);
2075
2249
w->connected = 1;
2081
pr_err("dapm: %s: configuring unknown pin %s\n", codec->name, pin);
2255
dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2082
2256
return -EINVAL;
2084
2258
EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
2087
2261
* snd_soc_dapm_disable_pin - disable pin.
2262
* @dapm: DAPM context
2089
2263
* @pin: pin name
2091
2265
* Disables input/output pin and its parents or children widgets.
2092
2266
* NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2093
2267
* do any widget power switching.
2095
int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, const char *pin)
2269
int snd_soc_dapm_disable_pin(struct snd_soc_dapm_context *dapm,
2097
return snd_soc_dapm_set_pin(codec, pin, 0);
2272
return snd_soc_dapm_set_pin(dapm, pin, 0);
2099
2274
EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
2102
2277
* snd_soc_dapm_nc_pin - permanently disable pin.
2278
* @dapm: DAPM context
2104
2279
* @pin: pin name
2106
2281
* Marks the specified pin as being not connected, disabling it along
2112
2287
* NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
2113
2288
* do any widget power switching.
2115
int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, const char *pin)
2290
int snd_soc_dapm_nc_pin(struct snd_soc_dapm_context *dapm, const char *pin)
2117
return snd_soc_dapm_set_pin(codec, pin, 0);
2292
return snd_soc_dapm_set_pin(dapm, pin, 0);
2119
2294
EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
2122
2297
* snd_soc_dapm_get_pin_status - get audio pin status
2123
* @codec: audio codec
2298
* @dapm: DAPM context
2124
2299
* @pin: audio signal pin endpoint (or start point)
2126
2301
* Get audio pin status - connected or disconnected.
2128
2303
* Returns 1 for connected otherwise 0.
2130
int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin)
2305
int snd_soc_dapm_get_pin_status(struct snd_soc_dapm_context *dapm,
2132
2308
struct snd_soc_dapm_widget *w;
2134
list_for_each_entry(w, &codec->dapm_widgets, list) {
2310
list_for_each_entry(w, &dapm->card->widgets, list) {
2311
if (w->dapm != dapm)
2135
2313
if (!strcmp(w->name, pin))
2136
2314
return w->connected;
2141
2319
EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
2322
* snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
2323
* @dapm: DAPM context
2324
* @pin: audio signal pin endpoint (or start point)
2326
* Mark the given endpoint or pin as ignoring suspend. When the
2327
* system is disabled a path between two endpoints flagged as ignoring
2328
* suspend will not be disabled. The path must already be enabled via
2329
* normal means at suspend time, it will not be turned on if it was not
2332
int snd_soc_dapm_ignore_suspend(struct snd_soc_dapm_context *dapm,
2335
struct snd_soc_dapm_widget *w;
2337
list_for_each_entry(w, &dapm->card->widgets, list) {
2338
if (w->dapm != dapm)
2340
if (!strcmp(w->name, pin)) {
2341
w->ignore_suspend = 1;
2346
dev_err(dapm->dev, "dapm: unknown pin %s\n", pin);
2349
EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
2144
2352
* snd_soc_dapm_free - free dapm resources
2145
* @socdev: SoC device
2147
2355
* Free all dapm widgets and resources.
2149
void snd_soc_dapm_free(struct snd_soc_device *socdev)
2357
void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
2151
struct snd_soc_codec *codec = socdev->card->codec;
2153
snd_soc_dapm_sys_remove(socdev->dev);
2154
dapm_free_widgets(codec);
2359
snd_soc_dapm_sys_remove(dapm->dev);
2360
dapm_free_widgets(dapm);
2361
list_del(&dapm->list);
2156
2363
EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
2159
* snd_soc_dapm_shutdown - callback for system shutdown
2161
void snd_soc_dapm_shutdown(struct snd_soc_device *socdev)
2365
static void soc_dapm_shutdown_codec(struct snd_soc_dapm_context *dapm)
2163
struct snd_soc_codec *codec = socdev->card->codec;
2164
2367
struct snd_soc_dapm_widget *w;
2165
2368
LIST_HEAD(down_list);
2166
2369
int powerdown = 0;
2168
list_for_each_entry(w, &codec->dapm_widgets, list) {
2371
list_for_each_entry(w, &dapm->card->widgets, list) {
2372
if (w->dapm != dapm)
2169
2374
if (w->power) {
2170
2375
dapm_seq_insert(w, &down_list, dapm_down_seq);
2179
2384
if (powerdown) {
2180
snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_PREPARE);
2181
dapm_seq_run(codec, &down_list, 0, dapm_down_seq);
2182
snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_STANDBY);
2185
snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_OFF);
2385
snd_soc_dapm_set_bias_level(NULL, dapm, SND_SOC_BIAS_PREPARE);
2386
dapm_seq_run(dapm, &down_list, 0, dapm_down_seq);
2387
snd_soc_dapm_set_bias_level(NULL, dapm, SND_SOC_BIAS_STANDBY);
2392
* snd_soc_dapm_shutdown - callback for system shutdown
2394
void snd_soc_dapm_shutdown(struct snd_soc_card *card)
2396
struct snd_soc_codec *codec;
2398
list_for_each_entry(codec, &card->codec_dev_list, list) {
2399
soc_dapm_shutdown_codec(&codec->dapm);
2400
snd_soc_dapm_set_bias_level(card, &codec->dapm, SND_SOC_BIAS_OFF);
2188
2404
/* Module information */