382
if (machine->ops && machine->ops->startup) {
383
ret = machine->ops->startup(substream);
505
if (rtd->dai_link->ops && rtd->dai_link->ops->startup) {
506
ret = rtd->dai_link->ops->startup(substream);
385
printk(KERN_ERR "asoc: %s startup failed\n", machine->name);
508
printk(KERN_ERR "asoc: %s startup failed\n", rtd->dai_link->name);
386
509
goto machine_err;
390
/* Check that the codec and cpu DAI's are compatible */
513
/* Check that the codec and cpu DAIs are compatible */
391
514
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
392
515
runtime->hw.rate_min =
393
max(codec_dai->playback.rate_min,
394
cpu_dai->playback.rate_min);
516
max(codec_dai_drv->playback.rate_min,
517
cpu_dai_drv->playback.rate_min);
395
518
runtime->hw.rate_max =
396
min(codec_dai->playback.rate_max,
397
cpu_dai->playback.rate_max);
519
min(codec_dai_drv->playback.rate_max,
520
cpu_dai_drv->playback.rate_max);
398
521
runtime->hw.channels_min =
399
max(codec_dai->playback.channels_min,
400
cpu_dai->playback.channels_min);
522
max(codec_dai_drv->playback.channels_min,
523
cpu_dai_drv->playback.channels_min);
401
524
runtime->hw.channels_max =
402
min(codec_dai->playback.channels_max,
403
cpu_dai->playback.channels_max);
525
min(codec_dai_drv->playback.channels_max,
526
cpu_dai_drv->playback.channels_max);
404
527
runtime->hw.formats =
405
codec_dai->playback.formats & cpu_dai->playback.formats;
528
codec_dai_drv->playback.formats & cpu_dai_drv->playback.formats;
406
529
runtime->hw.rates =
407
codec_dai->playback.rates & cpu_dai->playback.rates;
408
if (codec_dai->playback.rates
409
& (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
410
runtime->hw.rates |= cpu_dai->playback.rates;
411
if (cpu_dai->playback.rates
412
& (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
413
runtime->hw.rates |= codec_dai->playback.rates;
530
codec_dai_drv->playback.rates & cpu_dai_drv->playback.rates;
531
if (codec_dai_drv->playback.rates
532
& (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
533
runtime->hw.rates |= cpu_dai_drv->playback.rates;
534
if (cpu_dai_drv->playback.rates
535
& (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
536
runtime->hw.rates |= codec_dai_drv->playback.rates;
415
538
runtime->hw.rate_min =
416
max(codec_dai->capture.rate_min,
417
cpu_dai->capture.rate_min);
539
max(codec_dai_drv->capture.rate_min,
540
cpu_dai_drv->capture.rate_min);
418
541
runtime->hw.rate_max =
419
min(codec_dai->capture.rate_max,
420
cpu_dai->capture.rate_max);
542
min(codec_dai_drv->capture.rate_max,
543
cpu_dai_drv->capture.rate_max);
421
544
runtime->hw.channels_min =
422
max(codec_dai->capture.channels_min,
423
cpu_dai->capture.channels_min);
545
max(codec_dai_drv->capture.channels_min,
546
cpu_dai_drv->capture.channels_min);
424
547
runtime->hw.channels_max =
425
min(codec_dai->capture.channels_max,
426
cpu_dai->capture.channels_max);
548
min(codec_dai_drv->capture.channels_max,
549
cpu_dai_drv->capture.channels_max);
427
550
runtime->hw.formats =
428
codec_dai->capture.formats & cpu_dai->capture.formats;
551
codec_dai_drv->capture.formats & cpu_dai_drv->capture.formats;
429
552
runtime->hw.rates =
430
codec_dai->capture.rates & cpu_dai->capture.rates;
431
if (codec_dai->capture.rates
432
& (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
433
runtime->hw.rates |= cpu_dai->capture.rates;
434
if (cpu_dai->capture.rates
435
& (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
436
runtime->hw.rates |= codec_dai->capture.rates;
553
codec_dai_drv->capture.rates & cpu_dai_drv->capture.rates;
554
if (codec_dai_drv->capture.rates
555
& (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
556
runtime->hw.rates |= cpu_dai_drv->capture.rates;
557
if (cpu_dai_drv->capture.rates
558
& (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
559
runtime->hw.rates |= codec_dai_drv->capture.rates;
439
562
snd_pcm_limit_hw_rates(runtime);
868
970
static int soc_suspend(struct device *dev)
870
972
struct platform_device *pdev = to_platform_device(dev);
871
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
872
struct snd_soc_card *card = socdev->card;
873
struct snd_soc_platform *platform = card->platform;
874
struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
875
struct snd_soc_codec *codec = card->codec;
973
struct snd_soc_card *card = platform_get_drvdata(pdev);
974
struct snd_soc_codec *codec;
878
977
/* If the initialization of this soc device failed, there is no codec
879
978
* associated with it. Just bail out in this case.
980
if (list_empty(&card->codec_dev_list))
884
983
/* Due to the resume being scheduled into a workqueue we could
885
984
* suspend before that's finished - wait for it to complete.
887
snd_power_lock(codec->card);
888
snd_power_wait(codec->card, SNDRV_CTL_POWER_D0);
889
snd_power_unlock(codec->card);
986
snd_power_lock(card->snd_card);
987
snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
988
snd_power_unlock(card->snd_card);
891
990
/* we're going to block userspace touching us until resume completes */
892
snd_power_change_state(codec->card, SNDRV_CTL_POWER_D3hot);
894
/* mute any active DAC's */
895
for (i = 0; i < card->num_links; i++) {
896
struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
897
if (dai->ops->digital_mute && dai->playback.active)
898
dai->ops->digital_mute(dai, 1);
991
snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
993
/* mute any active DACs */
994
for (i = 0; i < card->num_rtd; i++) {
995
struct snd_soc_dai *dai = card->rtd[i].codec_dai;
996
struct snd_soc_dai_driver *drv = dai->driver;
998
if (card->rtd[i].dai_link->ignore_suspend)
1001
if (drv->ops->digital_mute && dai->playback_active)
1002
drv->ops->digital_mute(dai, 1);
901
1005
/* suspend all pcms */
902
for (i = 0; i < card->num_links; i++)
903
snd_pcm_suspend_all(card->dai_link[i].pcm);
1006
for (i = 0; i < card->num_rtd; i++) {
1007
if (card->rtd[i].dai_link->ignore_suspend)
1010
snd_pcm_suspend_all(card->rtd[i].pcm);
905
1013
if (card->suspend_pre)
906
1014
card->suspend_pre(pdev, PMSG_SUSPEND);
908
for (i = 0; i < card->num_links; i++) {
909
struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
910
if (cpu_dai->suspend && !cpu_dai->ac97_control)
911
cpu_dai->suspend(cpu_dai);
912
if (platform->suspend)
913
platform->suspend(&card->dai_link[i]);
1016
for (i = 0; i < card->num_rtd; i++) {
1017
struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
1018
struct snd_soc_platform *platform = card->rtd[i].platform;
1020
if (card->rtd[i].dai_link->ignore_suspend)
1023
if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
1024
cpu_dai->driver->suspend(cpu_dai);
1025
if (platform->driver->suspend && !platform->suspended) {
1026
platform->driver->suspend(cpu_dai);
1027
platform->suspended = 1;
916
1031
/* close any waiting streams and save state */
917
run_delayed_work(&card->delayed_work);
918
codec->suspend_bias_level = codec->bias_level;
920
for (i = 0; i < codec->num_dai; i++) {
921
char *stream = codec->dai[i].playback.stream_name;
923
snd_soc_dapm_stream_event(codec, stream,
924
SND_SOC_DAPM_STREAM_SUSPEND);
925
stream = codec->dai[i].capture.stream_name;
927
snd_soc_dapm_stream_event(codec, stream,
928
SND_SOC_DAPM_STREAM_SUSPEND);
931
if (codec_dev->suspend)
932
codec_dev->suspend(pdev, PMSG_SUSPEND);
934
for (i = 0; i < card->num_links; i++) {
935
struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
936
if (cpu_dai->suspend && cpu_dai->ac97_control)
937
cpu_dai->suspend(cpu_dai);
1032
for (i = 0; i < card->num_rtd; i++) {
1033
flush_delayed_work_sync(&card->rtd[i].delayed_work);
1034
card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
1037
for (i = 0; i < card->num_rtd; i++) {
1038
struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
1040
if (card->rtd[i].dai_link->ignore_suspend)
1043
if (driver->playback.stream_name != NULL)
1044
snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
1045
SND_SOC_DAPM_STREAM_SUSPEND);
1047
if (driver->capture.stream_name != NULL)
1048
snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
1049
SND_SOC_DAPM_STREAM_SUSPEND);
1052
/* suspend all CODECs */
1053
list_for_each_entry(codec, &card->codec_dev_list, card_list) {
1054
/* If there are paths active then the CODEC will be held with
1055
* bias _ON and should not be suspended. */
1056
if (!codec->suspended && codec->driver->suspend) {
1057
switch (codec->dapm.bias_level) {
1058
case SND_SOC_BIAS_STANDBY:
1059
case SND_SOC_BIAS_OFF:
1060
codec->driver->suspend(codec, PMSG_SUSPEND);
1061
codec->suspended = 1;
1064
dev_dbg(codec->dev, "CODEC is on over suspend\n");
1070
for (i = 0; i < card->num_rtd; i++) {
1071
struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
1073
if (card->rtd[i].dai_link->ignore_suspend)
1076
if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
1077
cpu_dai->driver->suspend(cpu_dai);
940
1080
if (card->suspend_post)
949
1089
static void soc_resume_deferred(struct work_struct *work)
951
struct snd_soc_card *card = container_of(work,
953
deferred_resume_work);
954
struct snd_soc_device *socdev = card->socdev;
955
struct snd_soc_platform *platform = card->platform;
956
struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
957
struct snd_soc_codec *codec = card->codec;
958
struct platform_device *pdev = to_platform_device(socdev->dev);
1091
struct snd_soc_card *card =
1092
container_of(work, struct snd_soc_card, deferred_resume_work);
1093
struct platform_device *pdev = to_platform_device(card->dev);
1094
struct snd_soc_codec *codec;
961
1097
/* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
962
1098
* so userspace apps are blocked from touching us
965
dev_dbg(socdev->dev, "starting resume work\n");
1101
dev_dbg(card->dev, "starting resume work\n");
1103
/* Bring us up into D2 so that DAPM starts enabling things */
1104
snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
967
1106
if (card->resume_pre)
968
1107
card->resume_pre(pdev);
970
for (i = 0; i < card->num_links; i++) {
971
struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
972
if (cpu_dai->resume && cpu_dai->ac97_control)
973
cpu_dai->resume(cpu_dai);
976
if (codec_dev->resume)
977
codec_dev->resume(pdev);
979
for (i = 0; i < codec->num_dai; i++) {
980
char *stream = codec->dai[i].playback.stream_name;
982
snd_soc_dapm_stream_event(codec, stream,
1109
/* resume AC97 DAIs */
1110
for (i = 0; i < card->num_rtd; i++) {
1111
struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
1113
if (card->rtd[i].dai_link->ignore_suspend)
1116
if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
1117
cpu_dai->driver->resume(cpu_dai);
1120
list_for_each_entry(codec, &card->codec_dev_list, card_list) {
1121
/* If the CODEC was idle over suspend then it will have been
1122
* left with bias OFF or STANDBY and suspended so we must now
1123
* resume. Otherwise the suspend was suppressed.
1125
if (codec->driver->resume && codec->suspended) {
1126
switch (codec->dapm.bias_level) {
1127
case SND_SOC_BIAS_STANDBY:
1128
case SND_SOC_BIAS_OFF:
1129
codec->driver->resume(codec);
1130
codec->suspended = 0;
1133
dev_dbg(codec->dev, "CODEC was on over suspend\n");
1139
for (i = 0; i < card->num_rtd; i++) {
1140
struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
1142
if (card->rtd[i].dai_link->ignore_suspend)
1145
if (driver->playback.stream_name != NULL)
1146
snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
983
1147
SND_SOC_DAPM_STREAM_RESUME);
984
stream = codec->dai[i].capture.stream_name;
986
snd_soc_dapm_stream_event(codec, stream,
1149
if (driver->capture.stream_name != NULL)
1150
snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
987
1151
SND_SOC_DAPM_STREAM_RESUME);
990
1154
/* unmute any active DACs */
991
for (i = 0; i < card->num_links; i++) {
992
struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
993
if (dai->ops->digital_mute && dai->playback.active)
994
dai->ops->digital_mute(dai, 0);
1155
for (i = 0; i < card->num_rtd; i++) {
1156
struct snd_soc_dai *dai = card->rtd[i].codec_dai;
1157
struct snd_soc_dai_driver *drv = dai->driver;
1159
if (card->rtd[i].dai_link->ignore_suspend)
1162
if (drv->ops->digital_mute && dai->playback_active)
1163
drv->ops->digital_mute(dai, 0);
997
for (i = 0; i < card->num_links; i++) {
998
struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
999
if (cpu_dai->resume && !cpu_dai->ac97_control)
1000
cpu_dai->resume(cpu_dai);
1001
if (platform->resume)
1002
platform->resume(&card->dai_link[i]);
1166
for (i = 0; i < card->num_rtd; i++) {
1167
struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
1168
struct snd_soc_platform *platform = card->rtd[i].platform;
1170
if (card->rtd[i].dai_link->ignore_suspend)
1173
if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
1174
cpu_dai->driver->resume(cpu_dai);
1175
if (platform->driver->resume && platform->suspended) {
1176
platform->driver->resume(cpu_dai);
1177
platform->suspended = 0;
1005
1181
if (card->resume_post)
1006
1182
card->resume_post(pdev);
1008
dev_dbg(socdev->dev, "resume work completed\n");
1184
dev_dbg(card->dev, "resume work completed\n");
1010
1186
/* userspace can access us now we are back as we were before */
1011
snd_power_change_state(codec->card, SNDRV_CTL_POWER_D0);
1187
snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
1014
1190
/* powers up audio subsystem after a suspend */
1015
1191
static int soc_resume(struct device *dev)
1017
1193
struct platform_device *pdev = to_platform_device(dev);
1018
struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1019
struct snd_soc_card *card = socdev->card;
1020
struct snd_soc_dai *cpu_dai = card->dai_link[0].cpu_dai;
1022
/* If the initialization of this soc device failed, there is no codec
1023
* associated with it. Just bail out in this case.
1194
struct snd_soc_card *card = platform_get_drvdata(pdev);
1028
1197
/* AC97 devices might have other drivers hanging off them so
1029
1198
* need to resume immediately. Other drivers don't have that
1030
1199
* problem and may take a substantial amount of time to resume
1031
1200
* due to I/O costs and anti-pop so handle them out of line.
1033
if (cpu_dai->ac97_control) {
1034
dev_dbg(socdev->dev, "Resuming AC97 immediately\n");
1035
soc_resume_deferred(&card->deferred_resume_work);
1037
dev_dbg(socdev->dev, "Scheduling resume work\n");
1038
if (!schedule_work(&card->deferred_resume_work))
1039
dev_err(socdev->dev, "resume work item may be lost\n");
1202
for (i = 0; i < card->num_rtd; i++) {
1203
struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
1204
if (cpu_dai->driver->ac97_control) {
1205
dev_dbg(dev, "Resuming AC97 immediately\n");
1206
soc_resume_deferred(&card->deferred_resume_work);
1208
dev_dbg(dev, "Scheduling resume work\n");
1209
if (!schedule_work(&card->deferred_resume_work))
1210
dev_err(dev, "resume work item may be lost\n");
1049
1221
static struct snd_soc_dai_ops null_dai_ops = {
1224
static int soc_bind_dai_link(struct snd_soc_card *card, int num)
1226
struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1227
struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1228
struct snd_soc_codec *codec;
1229
struct snd_soc_platform *platform;
1230
struct snd_soc_dai *codec_dai, *cpu_dai;
1234
dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num);
1236
/* do we already have the CPU DAI for this link ? */
1240
/* no, then find CPU DAI from registered DAIs*/
1241
list_for_each_entry(cpu_dai, &dai_list, list) {
1242
if (!strcmp(cpu_dai->name, dai_link->cpu_dai_name)) {
1244
if (!try_module_get(cpu_dai->dev->driver->owner))
1247
rtd->cpu_dai = cpu_dai;
1251
dev_dbg(card->dev, "CPU DAI %s not registered\n",
1252
dai_link->cpu_dai_name);
1255
/* do we already have the CODEC for this link ? */
1260
/* no, then find CODEC from registered CODECs*/
1261
list_for_each_entry(codec, &codec_list, list) {
1262
if (!strcmp(codec->name, dai_link->codec_name)) {
1265
/* CODEC found, so find CODEC DAI from registered DAIs from this CODEC*/
1266
list_for_each_entry(codec_dai, &dai_list, list) {
1267
if (codec->dev == codec_dai->dev &&
1268
!strcmp(codec_dai->name, dai_link->codec_dai_name)) {
1269
rtd->codec_dai = codec_dai;
1273
dev_dbg(card->dev, "CODEC DAI %s not registered\n",
1274
dai_link->codec_dai_name);
1279
dev_dbg(card->dev, "CODEC %s not registered\n",
1280
dai_link->codec_name);
1283
/* do we already have the CODEC DAI for this link ? */
1284
if (rtd->platform) {
1287
/* no, then find CPU DAI from registered DAIs*/
1288
list_for_each_entry(platform, &platform_list, list) {
1289
if (!strcmp(platform->name, dai_link->platform_name)) {
1290
rtd->platform = platform;
1295
dev_dbg(card->dev, "platform %s not registered\n",
1296
dai_link->platform_name);
1300
/* mark rtd as complete if we found all 4 of our client devices */
1301
if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) {
1308
static void soc_remove_codec(struct snd_soc_codec *codec)
1312
if (codec->driver->remove) {
1313
err = codec->driver->remove(codec);
1316
"asoc: failed to remove %s: %d\n",
1320
/* Make sure all DAPM widgets are freed */
1321
snd_soc_dapm_free(&codec->dapm);
1323
soc_cleanup_codec_debugfs(codec);
1325
list_del(&codec->card_list);
1326
module_put(codec->dev->driver->owner);
1329
static void soc_remove_dai_link(struct snd_soc_card *card, int num)
1331
struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1332
struct snd_soc_codec *codec = rtd->codec;
1333
struct snd_soc_platform *platform = rtd->platform;
1334
struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
1337
/* unregister the rtd device */
1338
if (rtd->dev_registered) {
1339
device_remove_file(&rtd->dev, &dev_attr_pmdown_time);
1340
device_remove_file(&rtd->dev, &dev_attr_codec_reg);
1341
device_unregister(&rtd->dev);
1342
rtd->dev_registered = 0;
1345
/* remove the CODEC DAI */
1346
if (codec_dai && codec_dai->probed) {
1347
if (codec_dai->driver->remove) {
1348
err = codec_dai->driver->remove(codec_dai);
1350
printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name);
1352
codec_dai->probed = 0;
1353
list_del(&codec_dai->card_list);
1356
/* remove the platform */
1357
if (platform && platform->probed) {
1358
if (platform->driver->remove) {
1359
err = platform->driver->remove(platform);
1361
printk(KERN_ERR "asoc: failed to remove %s\n", platform->name);
1363
platform->probed = 0;
1364
list_del(&platform->card_list);
1365
module_put(platform->dev->driver->owner);
1368
/* remove the CODEC */
1369
if (codec && codec->probed)
1370
soc_remove_codec(codec);
1372
/* remove the cpu_dai */
1373
if (cpu_dai && cpu_dai->probed) {
1374
if (cpu_dai->driver->remove) {
1375
err = cpu_dai->driver->remove(cpu_dai);
1377
printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name);
1379
cpu_dai->probed = 0;
1380
list_del(&cpu_dai->card_list);
1381
module_put(cpu_dai->dev->driver->owner);
1385
static void soc_set_name_prefix(struct snd_soc_card *card,
1386
struct snd_soc_codec *codec)
1390
if (card->codec_conf == NULL)
1393
for (i = 0; i < card->num_configs; i++) {
1394
struct snd_soc_codec_conf *map = &card->codec_conf[i];
1395
if (map->dev_name && !strcmp(codec->name, map->dev_name)) {
1396
codec->name_prefix = map->name_prefix;
1402
static int soc_probe_codec(struct snd_soc_card *card,
1403
struct snd_soc_codec *codec)
1408
codec->dapm.card = card;
1409
soc_set_name_prefix(card, codec);
1411
if (codec->driver->probe) {
1412
ret = codec->driver->probe(codec);
1415
"asoc: failed to probe CODEC %s: %d\n",
1421
soc_init_codec_debugfs(codec);
1423
/* mark codec as probed and add to card codec list */
1424
if (!try_module_get(codec->dev->driver->owner))
1428
list_add(&codec->card_list, &card->codec_dev_list);
1429
list_add(&codec->dapm.list, &card->dapm_list);
1434
static void rtd_release(struct device *dev) {}
1436
static int soc_post_component_init(struct snd_soc_card *card,
1437
struct snd_soc_codec *codec,
1438
int num, int dailess)
1440
struct snd_soc_dai_link *dai_link = NULL;
1441
struct snd_soc_aux_dev *aux_dev = NULL;
1442
struct snd_soc_pcm_runtime *rtd;
1443
const char *temp, *name;
1447
dai_link = &card->dai_link[num];
1448
rtd = &card->rtd[num];
1449
name = dai_link->name;
1451
aux_dev = &card->aux_dev[num];
1452
rtd = &card->rtd_aux[num];
1453
name = aux_dev->name;
1456
/* machine controls, routes and widgets are not prefixed */
1457
temp = codec->name_prefix;
1458
codec->name_prefix = NULL;
1460
/* do machine specific initialization */
1461
if (!dailess && dai_link->init)
1462
ret = dai_link->init(rtd);
1463
else if (dailess && aux_dev->init)
1464
ret = aux_dev->init(&codec->dapm);
1466
dev_err(card->dev, "asoc: failed to init %s: %d\n", name, ret);
1469
codec->name_prefix = temp;
1471
/* Make sure all DAPM widgets are instantiated */
1472
snd_soc_dapm_new_widgets(&codec->dapm);
1474
/* register the rtd device */
1477
rtd->dev.parent = card->dev;
1478
rtd->dev.release = rtd_release;
1479
rtd->dev.init_name = name;
1480
ret = device_register(&rtd->dev);
1483
"asoc: failed to register runtime device: %d\n", ret);
1486
rtd->dev_registered = 1;
1488
/* add DAPM sysfs entries for this codec */
1489
ret = snd_soc_dapm_sys_add(&rtd->dev);
1492
"asoc: failed to add codec dapm sysfs entries: %d\n",
1495
/* add codec sysfs entries */
1496
ret = device_create_file(&rtd->dev, &dev_attr_codec_reg);
1499
"asoc: failed to add codec sysfs files: %d\n", ret);
1504
static int soc_probe_dai_link(struct snd_soc_card *card, int num)
1506
struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1507
struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1508
struct snd_soc_codec *codec = rtd->codec;
1509
struct snd_soc_platform *platform = rtd->platform;
1510
struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
1513
dev_dbg(card->dev, "probe %s dai link %d\n", card->name, num);
1515
/* config components */
1516
codec_dai->codec = codec;
1517
cpu_dai->platform = platform;
1518
codec_dai->card = card;
1519
cpu_dai->card = card;
1521
/* set default power off timeout */
1522
rtd->pmdown_time = pmdown_time;
1524
/* probe the cpu_dai */
1525
if (!cpu_dai->probed) {
1526
if (cpu_dai->driver->probe) {
1527
ret = cpu_dai->driver->probe(cpu_dai);
1529
printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n",
1534
cpu_dai->probed = 1;
1535
/* mark cpu_dai as probed and add to card cpu_dai list */
1536
list_add(&cpu_dai->card_list, &card->dai_dev_list);
1539
/* probe the CODEC */
1540
if (!codec->probed) {
1541
ret = soc_probe_codec(card, codec);
1546
/* probe the platform */
1547
if (!platform->probed) {
1548
if (platform->driver->probe) {
1549
ret = platform->driver->probe(platform);
1551
printk(KERN_ERR "asoc: failed to probe platform %s\n",
1556
/* mark platform as probed and add to card platform list */
1558
if (!try_module_get(platform->dev->driver->owner))
1561
platform->probed = 1;
1562
list_add(&platform->card_list, &card->platform_dev_list);
1565
/* probe the CODEC DAI */
1566
if (!codec_dai->probed) {
1567
if (codec_dai->driver->probe) {
1568
ret = codec_dai->driver->probe(codec_dai);
1570
printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n",
1576
/* mark cpu_dai as probed and add to card cpu_dai list */
1577
codec_dai->probed = 1;
1578
list_add(&codec_dai->card_list, &card->dai_dev_list);
1581
/* DAPM dai link stream work */
1582
INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
1584
ret = soc_post_component_init(card, codec, num, 0);
1588
ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time);
1590
printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1592
/* create the pcm */
1593
ret = soc_new_pcm(rtd, num);
1595
printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name);
1599
/* add platform data for AC97 devices */
1600
if (rtd->codec_dai->driver->ac97_control)
1601
snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
1606
#ifdef CONFIG_SND_SOC_AC97_BUS
1607
static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1611
/* Only instantiate AC97 if not already done by the adaptor
1612
* for the generic AC97 subsystem.
1614
if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
1616
* It is possible that the AC97 device is already registered to
1617
* the device subsystem. This happens when the device is created
1618
* via snd_ac97_mixer(). Currently only SoC codec that does so
1619
* is the generic AC97 glue but others migh emerge.
1621
* In those cases we don't try to register the device again.
1623
if (!rtd->codec->ac97_created)
1626
ret = soc_ac97_dev_register(rtd->codec);
1628
printk(KERN_ERR "asoc: AC97 device register failed\n");
1632
rtd->codec->ac97_registered = 1;
1637
static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1639
if (codec->ac97_registered) {
1640
soc_ac97_dev_unregister(codec);
1641
codec->ac97_registered = 0;
1646
static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
1648
struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
1649
struct snd_soc_codec *codec;
1652
/* find CODEC from registered CODECs*/
1653
list_for_each_entry(codec, &codec_list, list) {
1654
if (!strcmp(codec->name, aux_dev->codec_name)) {
1655
if (codec->probed) {
1657
"asoc: codec already probed");
1664
/* codec not found */
1665
dev_err(card->dev, "asoc: codec %s not found", aux_dev->codec_name);
1669
if (!try_module_get(codec->dev->driver->owner))
1672
ret = soc_probe_codec(card, codec);
1676
ret = soc_post_component_init(card, codec, num, 1);
1682
static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
1684
struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
1685
struct snd_soc_codec *codec = rtd->codec;
1687
/* unregister the rtd device */
1688
if (rtd->dev_registered) {
1689
device_remove_file(&rtd->dev, &dev_attr_codec_reg);
1690
device_unregister(&rtd->dev);
1691
rtd->dev_registered = 0;
1694
if (codec && codec->probed)
1695
soc_remove_codec(codec);
1698
static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
1699
enum snd_soc_compress_type compress_type)
1703
if (codec->cache_init)
1706
/* override the compress_type if necessary */
1707
if (compress_type && codec->compress_type != compress_type)
1708
codec->compress_type = compress_type;
1709
ret = snd_soc_cache_init(codec);
1711
dev_err(codec->dev, "Failed to set cache compression type: %d\n",
1715
codec->cache_init = 1;
1052
1719
static void snd_soc_instantiate_card(struct snd_soc_card *card)
1054
struct platform_device *pdev = container_of(card->dev,
1055
struct platform_device,
1057
struct snd_soc_codec_device *codec_dev = card->socdev->codec_dev;
1721
struct platform_device *pdev = to_platform_device(card->dev);
1058
1722
struct snd_soc_codec *codec;
1059
struct snd_soc_platform *platform;
1060
struct snd_soc_dai *dai;
1061
int i, found, ret, ac97;
1063
if (card->instantiated)
1067
list_for_each_entry(platform, &platform_list, list)
1068
if (card->platform == platform) {
1073
dev_dbg(card->dev, "Platform %s not registered\n",
1074
card->platform->name);
1079
for (i = 0; i < card->num_links; i++) {
1081
list_for_each_entry(dai, &dai_list, list)
1082
if (card->dai_link[i].cpu_dai == dai) {
1087
dev_dbg(card->dev, "DAI %s not registered\n",
1088
card->dai_link[i].cpu_dai->name);
1092
if (card->dai_link[i].cpu_dai->ac97_control)
1096
for (i = 0; i < card->num_links; i++) {
1097
if (!card->dai_link[i].codec_dai->ops)
1098
card->dai_link[i].codec_dai->ops = &null_dai_ops;
1101
/* If we have AC97 in the system then don't wait for the
1102
* codec. This will need revisiting if we have to handle
1103
* systems with mixed AC97 and non-AC97 parts. Only check for
1104
* DAIs currently; we can't do this per link since some AC97
1105
* codecs have non-AC97 DAIs.
1108
for (i = 0; i < card->num_links; i++) {
1110
list_for_each_entry(dai, &dai_list, list)
1111
if (card->dai_link[i].codec_dai == dai) {
1723
struct snd_soc_codec_conf *codec_conf;
1724
enum snd_soc_compress_type compress_type;
1727
mutex_lock(&card->mutex);
1729
if (card->instantiated) {
1730
mutex_unlock(&card->mutex);
1735
for (i = 0; i < card->num_links; i++)
1736
soc_bind_dai_link(card, i);
1738
/* bind completed ? */
1739
if (card->num_rtd != card->num_links) {
1740
mutex_unlock(&card->mutex);
1744
/* initialize the register cache for each available codec */
1745
list_for_each_entry(codec, &codec_list, list) {
1746
if (codec->cache_init)
1748
/* by default we don't override the compress_type */
1750
/* check to see if we need to override the compress_type */
1751
for (i = 0; i < card->num_configs; ++i) {
1752
codec_conf = &card->codec_conf[i];
1753
if (!strcmp(codec->name, codec_conf->dev_name)) {
1754
compress_type = codec_conf->compress_type;
1755
if (compress_type && compress_type
1756
!= codec->compress_type)
1116
dev_dbg(card->dev, "DAI %s not registered\n",
1117
card->dai_link[i].codec_dai->name);
1122
/* Note that we do not current check for codec components */
1124
dev_dbg(card->dev, "All components present, instantiating\n");
1126
/* Found everything, bring it up */
1127
card->pmdown_time = pmdown_time;
1760
ret = snd_soc_init_codec_cache(codec, compress_type);
1762
mutex_unlock(&card->mutex);
1767
/* card bind complete so register a sound card */
1768
ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1769
card->owner, 0, &card->snd_card);
1771
printk(KERN_ERR "asoc: can't create sound card for card %s\n",
1773
mutex_unlock(&card->mutex);
1776
card->snd_card->dev = card->dev;
1779
/* deferred resume work */
1780
INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1783
/* initialise the sound card only once */
1129
1784
if (card->probe) {
1130
1785
ret = card->probe(pdev);
1135
for (i = 0; i < card->num_links; i++) {
1136
struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
1137
if (cpu_dai->probe) {
1138
ret = cpu_dai->probe(pdev, cpu_dai);
1144
if (codec_dev->probe) {
1145
ret = codec_dev->probe(pdev);
1149
codec = card->codec;
1151
if (platform->probe) {
1152
ret = platform->probe(pdev);
1157
/* DAPM stream work */
1158
INIT_DELAYED_WORK(&card->delayed_work, close_delayed_work);
1160
/* deferred resume work */
1161
INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1164
for (i = 0; i < card->num_links; i++) {
1165
if (card->dai_link[i].init) {
1166
ret = card->dai_link[i].init(codec);
1168
printk(KERN_ERR "asoc: failed to init %s\n",
1169
card->dai_link[i].stream_name);
1173
if (card->dai_link[i].codec_dai->ac97_control)
1177
snprintf(codec->card->shortname, sizeof(codec->card->shortname),
1787
goto card_probe_error;
1790
for (i = 0; i < card->num_links; i++) {
1791
ret = soc_probe_dai_link(card, i);
1793
pr_err("asoc: failed to instantiate card %s: %d\n",
1799
for (i = 0; i < card->num_aux_devs; i++) {
1800
ret = soc_probe_aux_dev(card, i);
1802
pr_err("asoc: failed to add auxiliary devices %s: %d\n",
1804
goto probe_aux_dev_err;
1808
snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
1178
1809
"%s", card->name);
1179
snprintf(codec->card->longname, sizeof(codec->card->longname),
1180
"%s (%s)", card->name, codec->name);
1182
/* Make sure all DAPM widgets are instantiated */
1183
snd_soc_dapm_new_widgets(codec);
1185
ret = snd_card_register(codec->card);
1810
snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1813
ret = snd_card_register(card->snd_card);
1187
printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
1815
printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
1816
goto probe_aux_dev_err;
1192
mutex_lock(&codec->mutex);
1193
1819
#ifdef CONFIG_SND_SOC_AC97_BUS
1194
/* Only instantiate AC97 if not already done by the adaptor
1195
* for the generic AC97 subsystem.
1197
if (ac97 && strcmp(codec->name, "AC97") != 0) {
1198
ret = soc_ac97_dev_register(codec);
1820
/* register any AC97 codecs */
1821
for (i = 0; i < card->num_rtd; i++) {
1822
ret = soc_register_ac97_dai_link(&card->rtd[i]);
1200
printk(KERN_ERR "asoc: AC97 device register failed\n");
1201
snd_card_free(codec->card);
1202
mutex_unlock(&codec->mutex);
1824
printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name);
1826
soc_unregister_ac97_dai_link(card->rtd[i].codec);
1827
goto probe_aux_dev_err;
1208
ret = snd_soc_dapm_sys_add(card->socdev->dev);
1210
printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n");
1212
ret = device_create_file(card->socdev->dev, &dev_attr_pmdown_time);
1214
printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1216
ret = device_create_file(card->socdev->dev, &dev_attr_codec_reg);
1218
printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
1220
soc_init_codec_debugfs(codec);
1221
mutex_unlock(&codec->mutex);
1223
1832
card->instantiated = 1;
1833
mutex_unlock(&card->mutex);
1228
if (platform->remove)
1229
platform->remove(pdev);
1232
if (codec_dev->remove)
1233
codec_dev->remove(pdev);
1236
for (i--; i >= 0; i--) {
1237
struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
1238
if (cpu_dai->remove)
1239
cpu_dai->remove(pdev, cpu_dai);
1837
for (i = 0; i < card->num_aux_devs; i++)
1838
soc_remove_aux_dev(card, i);
1841
for (i = 0; i < card->num_links; i++)
1842
soc_remove_dai_link(card, i);
1242
1845
if (card->remove)
1243
1846
card->remove(pdev);
1848
snd_card_free(card->snd_card);
1850
mutex_unlock(&card->mutex);
1247
* Attempt to initialise any uninitalised cards. Must be called with
1854
* Attempt to initialise any uninitialised cards. Must be called with
1248
1855
* client_mutex.
1250
1857
static void snd_soc_instantiate_cards(void)