aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r--sound/soc/soc-core.c1665
1 files changed, 994 insertions, 671 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 5299932db0b..a004876a39a 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -3,6 +3,8 @@
3 * 3 *
4 * Copyright 2005 Wolfson Microelectronics PLC. 4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Copyright 2005 Openedhand Ltd. 5 * Copyright 2005 Openedhand Ltd.
6 * Copyright (C) 2010 Slimlogic Ltd.
7 * Copyright (C) 2010 Texas Instruments Inc.
6 * 8 *
7 * Author: Liam Girdwood <lrg@slimlogic.co.uk> 9 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
8 * with code, comments and ideas from :- 10 * with code, comments and ideas from :-
@@ -37,6 +39,8 @@
37#include <sound/soc-dapm.h> 39#include <sound/soc-dapm.h>
38#include <sound/initval.h> 40#include <sound/initval.h>
39 41
42#define NAME_SIZE 32
43
40static DEFINE_MUTEX(pcm_mutex); 44static DEFINE_MUTEX(pcm_mutex);
41static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq); 45static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
42 46
@@ -52,6 +56,7 @@ static LIST_HEAD(codec_list);
52 56
53static int snd_soc_register_card(struct snd_soc_card *card); 57static int snd_soc_register_card(struct snd_soc_card *card);
54static int snd_soc_unregister_card(struct snd_soc_card *card); 58static int snd_soc_unregister_card(struct snd_soc_card *card);
59static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
55 60
56/* 61/*
57 * This is a timeout to do a DAPM powerdown after a stream is closed(). 62 * This is a timeout to do a DAPM powerdown after a stream is closed().
@@ -86,30 +91,30 @@ static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
86{ 91{
87 int ret, i, step = 1, count = 0; 92 int ret, i, step = 1, count = 0;
88 93
89 if (!codec->reg_cache_size) 94 if (!codec->driver->reg_cache_size)
90 return 0; 95 return 0;
91 96
92 if (codec->reg_cache_step) 97 if (codec->driver->reg_cache_step)
93 step = codec->reg_cache_step; 98 step = codec->driver->reg_cache_step;
94 99
95 count += sprintf(buf, "%s registers\n", codec->name); 100 count += sprintf(buf, "%s registers\n", codec->name);
96 for (i = 0; i < codec->reg_cache_size; i += step) { 101 for (i = 0; i < codec->driver->reg_cache_size; i += step) {
97 if (codec->readable_register && !codec->readable_register(i)) 102 if (codec->driver->readable_register && !codec->driver->readable_register(i))
98 continue; 103 continue;
99 104
100 count += sprintf(buf + count, "%2x: ", i); 105 count += sprintf(buf + count, "%2x: ", i);
101 if (count >= PAGE_SIZE - 1) 106 if (count >= PAGE_SIZE - 1)
102 break; 107 break;
103 108
104 if (codec->display_register) { 109 if (codec->driver->display_register) {
105 count += codec->display_register(codec, buf + count, 110 count += codec->driver->display_register(codec, buf + count,
106 PAGE_SIZE - count, i); 111 PAGE_SIZE - count, i);
107 } else { 112 } else {
108 /* If the read fails it's almost certainly due to 113 /* If the read fails it's almost certainly due to
109 * the register being volatile and the device being 114 * the register being volatile and the device being
110 * powered off. 115 * powered off.
111 */ 116 */
112 ret = codec->read(codec, i); 117 ret = codec->driver->read(codec, i);
113 if (ret >= 0) 118 if (ret >= 0)
114 count += snprintf(buf + count, 119 count += snprintf(buf + count,
115 PAGE_SIZE - count, 120 PAGE_SIZE - count,
@@ -137,8 +142,10 @@ static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
137static ssize_t codec_reg_show(struct device *dev, 142static ssize_t codec_reg_show(struct device *dev,
138 struct device_attribute *attr, char *buf) 143 struct device_attribute *attr, char *buf)
139{ 144{
140 struct snd_soc_device *devdata = dev_get_drvdata(dev); 145 struct snd_soc_pcm_runtime *rtd =
141 return soc_codec_reg_show(devdata->card->codec, buf); 146 container_of(dev, struct snd_soc_pcm_runtime, dev);
147
148 return soc_codec_reg_show(rtd->codec, buf);
142} 149}
143 150
144static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); 151static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
@@ -146,20 +153,20 @@ static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
146static ssize_t pmdown_time_show(struct device *dev, 153static ssize_t pmdown_time_show(struct device *dev,
147 struct device_attribute *attr, char *buf) 154 struct device_attribute *attr, char *buf)
148{ 155{
149 struct snd_soc_device *socdev = dev_get_drvdata(dev); 156 struct snd_soc_pcm_runtime *rtd =
150 struct snd_soc_card *card = socdev->card; 157 container_of(dev, struct snd_soc_pcm_runtime, dev);
151 158
152 return sprintf(buf, "%ld\n", card->pmdown_time); 159 return sprintf(buf, "%ld\n", rtd->pmdown_time);
153} 160}
154 161
155static ssize_t pmdown_time_set(struct device *dev, 162static ssize_t pmdown_time_set(struct device *dev,
156 struct device_attribute *attr, 163 struct device_attribute *attr,
157 const char *buf, size_t count) 164 const char *buf, size_t count)
158{ 165{
159 struct snd_soc_device *socdev = dev_get_drvdata(dev); 166 struct snd_soc_pcm_runtime *rtd =
160 struct snd_soc_card *card = socdev->card; 167 container_of(dev, struct snd_soc_pcm_runtime, dev);
161 168
162 strict_strtol(buf, 10, &card->pmdown_time); 169 strict_strtol(buf, 10, &rtd->pmdown_time);
163 170
164 return count; 171 return count;
165} 172}
@@ -203,19 +210,19 @@ static ssize_t codec_reg_write_file(struct file *file,
203 return -EFAULT; 210 return -EFAULT;
204 buf[buf_size] = 0; 211 buf[buf_size] = 0;
205 212
206 if (codec->reg_cache_step) 213 if (codec->driver->reg_cache_step)
207 step = codec->reg_cache_step; 214 step = codec->driver->reg_cache_step;
208 215
209 while (*start == ' ') 216 while (*start == ' ')
210 start++; 217 start++;
211 reg = simple_strtoul(start, &start, 16); 218 reg = simple_strtoul(start, &start, 16);
212 if ((reg >= codec->reg_cache_size) || (reg % step)) 219 if ((reg >= codec->driver->reg_cache_size) || (reg % step))
213 return -EINVAL; 220 return -EINVAL;
214 while (*start == ' ') 221 while (*start == ' ')
215 start++; 222 start++;
216 if (strict_strtoul(start, 16, &value)) 223 if (strict_strtoul(start, 16, &value))
217 return -EINVAL; 224 return -EINVAL;
218 codec->write(codec, reg, value); 225 codec->driver->write(codec, reg, value);
219 return buf_size; 226 return buf_size;
220} 227}
221 228
@@ -305,7 +312,7 @@ static int soc_ac97_dev_register(struct snd_soc_codec *codec)
305 codec->ac97->dev.release = soc_ac97_device_release; 312 codec->ac97->dev.release = soc_ac97_device_release;
306 313
307 dev_set_name(&codec->ac97->dev, "%d-%d:%s", 314 dev_set_name(&codec->ac97->dev, "%d-%d:%s",
308 codec->card->number, 0, codec->name); 315 codec->card->snd_card->number, 0, codec->name);
309 err = device_register(&codec->ac97->dev); 316 err = device_register(&codec->ac97->dev);
310 if (err < 0) { 317 if (err < 0) {
311 snd_printk(KERN_ERR "Can't register ac97 bus\n"); 318 snd_printk(KERN_ERR "Can't register ac97 bus\n");
@@ -319,24 +326,21 @@ static int soc_ac97_dev_register(struct snd_soc_codec *codec)
319static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream) 326static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream)
320{ 327{
321 struct snd_soc_pcm_runtime *rtd = substream->private_data; 328 struct snd_soc_pcm_runtime *rtd = substream->private_data;
322 struct snd_soc_device *socdev = rtd->socdev; 329 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
323 struct snd_soc_card *card = socdev->card; 330 struct snd_soc_dai *codec_dai = rtd->codec_dai;
324 struct snd_soc_dai_link *machine = rtd->dai;
325 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
326 struct snd_soc_dai *codec_dai = machine->codec_dai;
327 int ret; 331 int ret;
328 332
329 if (codec_dai->symmetric_rates || cpu_dai->symmetric_rates || 333 if (codec_dai->driver->symmetric_rates || cpu_dai->driver->symmetric_rates ||
330 machine->symmetric_rates) { 334 rtd->dai_link->symmetric_rates) {
331 dev_dbg(card->dev, "Symmetry forces %dHz rate\n", 335 dev_dbg(&rtd->dev, "Symmetry forces %dHz rate\n",
332 machine->rate); 336 rtd->rate);
333 337
334 ret = snd_pcm_hw_constraint_minmax(substream->runtime, 338 ret = snd_pcm_hw_constraint_minmax(substream->runtime,
335 SNDRV_PCM_HW_PARAM_RATE, 339 SNDRV_PCM_HW_PARAM_RATE,
336 machine->rate, 340 rtd->rate,
337 machine->rate); 341 rtd->rate);
338 if (ret < 0) { 342 if (ret < 0) {
339 dev_err(card->dev, 343 dev_err(&rtd->dev,
340 "Unable to apply rate symmetry constraint: %d\n", ret); 344 "Unable to apply rate symmetry constraint: %d\n", ret);
341 return ret; 345 return ret;
342 } 346 }
@@ -353,20 +357,19 @@ static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream)
353static int soc_pcm_open(struct snd_pcm_substream *substream) 357static int soc_pcm_open(struct snd_pcm_substream *substream)
354{ 358{
355 struct snd_soc_pcm_runtime *rtd = substream->private_data; 359 struct snd_soc_pcm_runtime *rtd = substream->private_data;
356 struct snd_soc_device *socdev = rtd->socdev;
357 struct snd_soc_card *card = socdev->card;
358 struct snd_pcm_runtime *runtime = substream->runtime; 360 struct snd_pcm_runtime *runtime = substream->runtime;
359 struct snd_soc_dai_link *machine = rtd->dai; 361 struct snd_soc_platform *platform = rtd->platform;
360 struct snd_soc_platform *platform = card->platform; 362 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
361 struct snd_soc_dai *cpu_dai = machine->cpu_dai; 363 struct snd_soc_dai *codec_dai = rtd->codec_dai;
362 struct snd_soc_dai *codec_dai = machine->codec_dai; 364 struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver;
365 struct snd_soc_dai_driver *codec_dai_drv = codec_dai->driver;
363 int ret = 0; 366 int ret = 0;
364 367
365 mutex_lock(&pcm_mutex); 368 mutex_lock(&pcm_mutex);
366 369
367 /* startup the audio subsystem */ 370 /* startup the audio subsystem */
368 if (cpu_dai->ops->startup) { 371 if (cpu_dai->driver->ops->startup) {
369 ret = cpu_dai->ops->startup(substream, cpu_dai); 372 ret = cpu_dai->driver->ops->startup(substream, cpu_dai);
370 if (ret < 0) { 373 if (ret < 0) {
371 printk(KERN_ERR "asoc: can't open interface %s\n", 374 printk(KERN_ERR "asoc: can't open interface %s\n",
372 cpu_dai->name); 375 cpu_dai->name);
@@ -374,16 +377,16 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
374 } 377 }
375 } 378 }
376 379
377 if (platform->pcm_ops->open) { 380 if (platform->driver->ops->open) {
378 ret = platform->pcm_ops->open(substream); 381 ret = platform->driver->ops->open(substream);
379 if (ret < 0) { 382 if (ret < 0) {
380 printk(KERN_ERR "asoc: can't open platform %s\n", platform->name); 383 printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
381 goto platform_err; 384 goto platform_err;
382 } 385 }
383 } 386 }
384 387
385 if (codec_dai->ops->startup) { 388 if (codec_dai->driver->ops->startup) {
386 ret = codec_dai->ops->startup(substream, codec_dai); 389 ret = codec_dai->driver->ops->startup(substream, codec_dai);
387 if (ret < 0) { 390 if (ret < 0) {
388 printk(KERN_ERR "asoc: can't open codec %s\n", 391 printk(KERN_ERR "asoc: can't open codec %s\n",
389 codec_dai->name); 392 codec_dai->name);
@@ -391,10 +394,10 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
391 } 394 }
392 } 395 }
393 396
394 if (machine->ops && machine->ops->startup) { 397 if (rtd->dai_link->ops && rtd->dai_link->ops->startup) {
395 ret = machine->ops->startup(substream); 398 ret = rtd->dai_link->ops->startup(substream);
396 if (ret < 0) { 399 if (ret < 0) {
397 printk(KERN_ERR "asoc: %s startup failed\n", machine->name); 400 printk(KERN_ERR "asoc: %s startup failed\n", rtd->dai_link->name);
398 goto machine_err; 401 goto machine_err;
399 } 402 }
400 } 403 }
@@ -402,50 +405,50 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
402 /* Check that the codec and cpu DAI's are compatible */ 405 /* Check that the codec and cpu DAI's are compatible */
403 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 406 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
404 runtime->hw.rate_min = 407 runtime->hw.rate_min =
405 max(codec_dai->playback.rate_min, 408 max(codec_dai_drv->playback.rate_min,
406 cpu_dai->playback.rate_min); 409 cpu_dai_drv->playback.rate_min);
407 runtime->hw.rate_max = 410 runtime->hw.rate_max =
408 min(codec_dai->playback.rate_max, 411 min(codec_dai_drv->playback.rate_max,
409 cpu_dai->playback.rate_max); 412 cpu_dai_drv->playback.rate_max);
410 runtime->hw.channels_min = 413 runtime->hw.channels_min =
411 max(codec_dai->playback.channels_min, 414 max(codec_dai_drv->playback.channels_min,
412 cpu_dai->playback.channels_min); 415 cpu_dai_drv->playback.channels_min);
413 runtime->hw.channels_max = 416 runtime->hw.channels_max =
414 min(codec_dai->playback.channels_max, 417 min(codec_dai_drv->playback.channels_max,
415 cpu_dai->playback.channels_max); 418 cpu_dai_drv->playback.channels_max);
416 runtime->hw.formats = 419 runtime->hw.formats =
417 codec_dai->playback.formats & cpu_dai->playback.formats; 420 codec_dai_drv->playback.formats & cpu_dai_drv->playback.formats;
418 runtime->hw.rates = 421 runtime->hw.rates =
419 codec_dai->playback.rates & cpu_dai->playback.rates; 422 codec_dai_drv->playback.rates & cpu_dai_drv->playback.rates;
420 if (codec_dai->playback.rates 423 if (codec_dai_drv->playback.rates
421 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS)) 424 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
422 runtime->hw.rates |= cpu_dai->playback.rates; 425 runtime->hw.rates |= cpu_dai_drv->playback.rates;
423 if (cpu_dai->playback.rates 426 if (cpu_dai_drv->playback.rates
424 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS)) 427 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
425 runtime->hw.rates |= codec_dai->playback.rates; 428 runtime->hw.rates |= codec_dai_drv->playback.rates;
426 } else { 429 } else {
427 runtime->hw.rate_min = 430 runtime->hw.rate_min =
428 max(codec_dai->capture.rate_min, 431 max(codec_dai_drv->capture.rate_min,
429 cpu_dai->capture.rate_min); 432 cpu_dai_drv->capture.rate_min);
430 runtime->hw.rate_max = 433 runtime->hw.rate_max =
431 min(codec_dai->capture.rate_max, 434 min(codec_dai_drv->capture.rate_max,
432 cpu_dai->capture.rate_max); 435 cpu_dai_drv->capture.rate_max);
433 runtime->hw.channels_min = 436 runtime->hw.channels_min =
434 max(codec_dai->capture.channels_min, 437 max(codec_dai_drv->capture.channels_min,
435 cpu_dai->capture.channels_min); 438 cpu_dai_drv->capture.channels_min);
436 runtime->hw.channels_max = 439 runtime->hw.channels_max =
437 min(codec_dai->capture.channels_max, 440 min(codec_dai_drv->capture.channels_max,
438 cpu_dai->capture.channels_max); 441 cpu_dai_drv->capture.channels_max);
439 runtime->hw.formats = 442 runtime->hw.formats =
440 codec_dai->capture.formats & cpu_dai->capture.formats; 443 codec_dai_drv->capture.formats & cpu_dai_drv->capture.formats;
441 runtime->hw.rates = 444 runtime->hw.rates =
442 codec_dai->capture.rates & cpu_dai->capture.rates; 445 codec_dai_drv->capture.rates & cpu_dai_drv->capture.rates;
443 if (codec_dai->capture.rates 446 if (codec_dai_drv->capture.rates
444 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS)) 447 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
445 runtime->hw.rates |= cpu_dai->capture.rates; 448 runtime->hw.rates |= cpu_dai_drv->capture.rates;
446 if (cpu_dai->capture.rates 449 if (cpu_dai_drv->capture.rates
447 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS)) 450 & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
448 runtime->hw.rates |= codec_dai->capture.rates; 451 runtime->hw.rates |= codec_dai_drv->capture.rates;
449 } 452 }
450 453
451 snd_pcm_limit_hw_rates(runtime); 454 snd_pcm_limit_hw_rates(runtime);
@@ -461,7 +464,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
461 } 464 }
462 if (!runtime->hw.channels_min || !runtime->hw.channels_max) { 465 if (!runtime->hw.channels_min || !runtime->hw.channels_max) {
463 printk(KERN_ERR "asoc: %s <-> %s No matching channels\n", 466 printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
464 codec_dai->name, cpu_dai->name); 467 codec_dai->name, cpu_dai->name);
465 goto config_err; 468 goto config_err;
466 } 469 }
467 470
@@ -472,7 +475,8 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
472 goto config_err; 475 goto config_err;
473 } 476 }
474 477
475 pr_debug("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name); 478 pr_debug("asoc: %s <-> %s info:\n",
479 codec_dai->name, cpu_dai->name);
476 pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates); 480 pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates);
477 pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min, 481 pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
478 runtime->hw.channels_max); 482 runtime->hw.channels_max);
@@ -480,33 +484,33 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
480 runtime->hw.rate_max); 484 runtime->hw.rate_max);
481 485
482 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 486 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
483 cpu_dai->playback.active++; 487 cpu_dai->playback_active++;
484 codec_dai->playback.active++; 488 codec_dai->playback_active++;
485 } else { 489 } else {
486 cpu_dai->capture.active++; 490 cpu_dai->capture_active++;
487 codec_dai->capture.active++; 491 codec_dai->capture_active++;
488 } 492 }
489 cpu_dai->active++; 493 cpu_dai->active++;
490 codec_dai->active++; 494 codec_dai->active++;
491 card->codec->active++; 495 rtd->codec->active++;
492 mutex_unlock(&pcm_mutex); 496 mutex_unlock(&pcm_mutex);
493 return 0; 497 return 0;
494 498
495config_err: 499config_err:
496 if (machine->ops && machine->ops->shutdown) 500 if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
497 machine->ops->shutdown(substream); 501 rtd->dai_link->ops->shutdown(substream);
498 502
499machine_err: 503machine_err:
500 if (codec_dai->ops->shutdown) 504 if (codec_dai->driver->ops->shutdown)
501 codec_dai->ops->shutdown(substream, codec_dai); 505 codec_dai->driver->ops->shutdown(substream, codec_dai);
502 506
503codec_dai_err: 507codec_dai_err:
504 if (platform->pcm_ops->close) 508 if (platform->driver->ops->close)
505 platform->pcm_ops->close(substream); 509 platform->driver->ops->close(substream);
506 510
507platform_err: 511platform_err:
508 if (cpu_dai->ops->shutdown) 512 if (cpu_dai->driver->ops->shutdown)
509 cpu_dai->ops->shutdown(substream, cpu_dai); 513 cpu_dai->driver->ops->shutdown(substream, cpu_dai);
510out: 514out:
511 mutex_unlock(&pcm_mutex); 515 mutex_unlock(&pcm_mutex);
512 return ret; 516 return ret;
@@ -519,29 +523,25 @@ out:
519 */ 523 */
520static void close_delayed_work(struct work_struct *work) 524static void close_delayed_work(struct work_struct *work)
521{ 525{
522 struct snd_soc_card *card = container_of(work, struct snd_soc_card, 526 struct snd_soc_pcm_runtime *rtd =
523 delayed_work.work); 527 container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
524 struct snd_soc_codec *codec = card->codec; 528 struct snd_soc_dai *codec_dai = rtd->codec_dai;
525 struct snd_soc_dai *codec_dai;
526 int i;
527 529
528 mutex_lock(&pcm_mutex); 530 mutex_lock(&pcm_mutex);
529 for (i = 0; i < codec->num_dai; i++) { 531
530 codec_dai = &codec->dai[i]; 532 pr_debug("pop wq checking: %s status: %s waiting: %s\n",
531 533 codec_dai->driver->playback.stream_name,
532 pr_debug("pop wq checking: %s status: %s waiting: %s\n", 534 codec_dai->playback_active ? "active" : "inactive",
533 codec_dai->playback.stream_name, 535 codec_dai->pop_wait ? "yes" : "no");
534 codec_dai->playback.active ? "active" : "inactive", 536
535 codec_dai->pop_wait ? "yes" : "no"); 537 /* are we waiting on this codec DAI stream */
536 538 if (codec_dai->pop_wait == 1) {
537 /* are we waiting on this codec DAI stream */ 539 codec_dai->pop_wait = 0;
538 if (codec_dai->pop_wait == 1) { 540 snd_soc_dapm_stream_event(rtd,
539 codec_dai->pop_wait = 0; 541 codec_dai->driver->playback.stream_name,
540 snd_soc_dapm_stream_event(codec, 542 SND_SOC_DAPM_STREAM_STOP);
541 codec_dai->playback.stream_name,
542 SND_SOC_DAPM_STREAM_STOP);
543 }
544 } 543 }
544
545 mutex_unlock(&pcm_mutex); 545 mutex_unlock(&pcm_mutex);
546} 546}
547 547
@@ -553,22 +553,19 @@ static void close_delayed_work(struct work_struct *work)
553static int soc_codec_close(struct snd_pcm_substream *substream) 553static int soc_codec_close(struct snd_pcm_substream *substream)
554{ 554{
555 struct snd_soc_pcm_runtime *rtd = substream->private_data; 555 struct snd_soc_pcm_runtime *rtd = substream->private_data;
556 struct snd_soc_device *socdev = rtd->socdev; 556 struct snd_soc_platform *platform = rtd->platform;
557 struct snd_soc_card *card = socdev->card; 557 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
558 struct snd_soc_dai_link *machine = rtd->dai; 558 struct snd_soc_dai *codec_dai = rtd->codec_dai;
559 struct snd_soc_platform *platform = card->platform; 559 struct snd_soc_codec *codec = rtd->codec;
560 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
561 struct snd_soc_dai *codec_dai = machine->codec_dai;
562 struct snd_soc_codec *codec = card->codec;
563 560
564 mutex_lock(&pcm_mutex); 561 mutex_lock(&pcm_mutex);
565 562
566 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 563 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
567 cpu_dai->playback.active--; 564 cpu_dai->playback_active--;
568 codec_dai->playback.active--; 565 codec_dai->playback_active--;
569 } else { 566 } else {
570 cpu_dai->capture.active--; 567 cpu_dai->capture_active--;
571 codec_dai->capture.active--; 568 codec_dai->capture_active--;
572 } 569 }
573 570
574 cpu_dai->active--; 571 cpu_dai->active--;
@@ -581,27 +578,28 @@ static int soc_codec_close(struct snd_pcm_substream *substream)
581 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 578 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
582 snd_soc_dai_digital_mute(codec_dai, 1); 579 snd_soc_dai_digital_mute(codec_dai, 1);
583 580
584 if (cpu_dai->ops->shutdown) 581 if (cpu_dai->driver->ops->shutdown)
585 cpu_dai->ops->shutdown(substream, cpu_dai); 582 cpu_dai->driver->ops->shutdown(substream, cpu_dai);
586 583
587 if (codec_dai->ops->shutdown) 584 if (codec_dai->driver->ops->shutdown)
588 codec_dai->ops->shutdown(substream, codec_dai); 585 codec_dai->driver->ops->shutdown(substream, codec_dai);
589 586
590 if (machine->ops && machine->ops->shutdown) 587 if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
591 machine->ops->shutdown(substream); 588 rtd->dai_link->ops->shutdown(substream);
592 589
593 if (platform->pcm_ops->close) 590 if (platform->driver->ops->close)
594 platform->pcm_ops->close(substream); 591 platform->driver->ops->close(substream);
592 cpu_dai->runtime = NULL;
595 593
596 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 594 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
597 /* start delayed pop wq here for playback streams */ 595 /* start delayed pop wq here for playback streams */
598 codec_dai->pop_wait = 1; 596 codec_dai->pop_wait = 1;
599 schedule_delayed_work(&card->delayed_work, 597 schedule_delayed_work(&rtd->delayed_work,
600 msecs_to_jiffies(card->pmdown_time)); 598 msecs_to_jiffies(rtd->pmdown_time));
601 } else { 599 } else {
602 /* capture streams can be powered down now */ 600 /* capture streams can be powered down now */
603 snd_soc_dapm_stream_event(codec, 601 snd_soc_dapm_stream_event(rtd,
604 codec_dai->capture.stream_name, 602 codec_dai->driver->capture.stream_name,
605 SND_SOC_DAPM_STREAM_STOP); 603 SND_SOC_DAPM_STREAM_STOP);
606 } 604 }
607 605
@@ -617,43 +615,39 @@ static int soc_codec_close(struct snd_pcm_substream *substream)
617static int soc_pcm_prepare(struct snd_pcm_substream *substream) 615static int soc_pcm_prepare(struct snd_pcm_substream *substream)
618{ 616{
619 struct snd_soc_pcm_runtime *rtd = substream->private_data; 617 struct snd_soc_pcm_runtime *rtd = substream->private_data;
620 struct snd_soc_device *socdev = rtd->socdev; 618 struct snd_soc_platform *platform = rtd->platform;
621 struct snd_soc_card *card = socdev->card; 619 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
622 struct snd_soc_dai_link *machine = rtd->dai; 620 struct snd_soc_dai *codec_dai = rtd->codec_dai;
623 struct snd_soc_platform *platform = card->platform;
624 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
625 struct snd_soc_dai *codec_dai = machine->codec_dai;
626 struct snd_soc_codec *codec = card->codec;
627 int ret = 0; 621 int ret = 0;
628 622
629 mutex_lock(&pcm_mutex); 623 mutex_lock(&pcm_mutex);
630 624
631 if (machine->ops && machine->ops->prepare) { 625 if (rtd->dai_link->ops && rtd->dai_link->ops->prepare) {
632 ret = machine->ops->prepare(substream); 626 ret = rtd->dai_link->ops->prepare(substream);
633 if (ret < 0) { 627 if (ret < 0) {
634 printk(KERN_ERR "asoc: machine prepare error\n"); 628 printk(KERN_ERR "asoc: machine prepare error\n");
635 goto out; 629 goto out;
636 } 630 }
637 } 631 }
638 632
639 if (platform->pcm_ops->prepare) { 633 if (platform->driver->ops->prepare) {
640 ret = platform->pcm_ops->prepare(substream); 634 ret = platform->driver->ops->prepare(substream);
641 if (ret < 0) { 635 if (ret < 0) {
642 printk(KERN_ERR "asoc: platform prepare error\n"); 636 printk(KERN_ERR "asoc: platform prepare error\n");
643 goto out; 637 goto out;
644 } 638 }
645 } 639 }
646 640
647 if (codec_dai->ops->prepare) { 641 if (codec_dai->driver->ops->prepare) {
648 ret = codec_dai->ops->prepare(substream, codec_dai); 642 ret = codec_dai->driver->ops->prepare(substream, codec_dai);
649 if (ret < 0) { 643 if (ret < 0) {
650 printk(KERN_ERR "asoc: codec DAI prepare error\n"); 644 printk(KERN_ERR "asoc: codec DAI prepare error\n");
651 goto out; 645 goto out;
652 } 646 }
653 } 647 }
654 648
655 if (cpu_dai->ops->prepare) { 649 if (cpu_dai->driver->ops->prepare) {
656 ret = cpu_dai->ops->prepare(substream, cpu_dai); 650 ret = cpu_dai->driver->ops->prepare(substream, cpu_dai);
657 if (ret < 0) { 651 if (ret < 0) {
658 printk(KERN_ERR "asoc: cpu DAI prepare error\n"); 652 printk(KERN_ERR "asoc: cpu DAI prepare error\n");
659 goto out; 653 goto out;
@@ -664,16 +658,16 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
664 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && 658 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
665 codec_dai->pop_wait) { 659 codec_dai->pop_wait) {
666 codec_dai->pop_wait = 0; 660 codec_dai->pop_wait = 0;
667 cancel_delayed_work(&card->delayed_work); 661 cancel_delayed_work(&rtd->delayed_work);
668 } 662 }
669 663
670 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 664 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
671 snd_soc_dapm_stream_event(codec, 665 snd_soc_dapm_stream_event(rtd,
672 codec_dai->playback.stream_name, 666 codec_dai->driver->playback.stream_name,
673 SND_SOC_DAPM_STREAM_START); 667 SND_SOC_DAPM_STREAM_START);
674 else 668 else
675 snd_soc_dapm_stream_event(codec, 669 snd_soc_dapm_stream_event(rtd,
676 codec_dai->capture.stream_name, 670 codec_dai->driver->capture.stream_name,
677 SND_SOC_DAPM_STREAM_START); 671 SND_SOC_DAPM_STREAM_START);
678 672
679 snd_soc_dai_digital_mute(codec_dai, 0); 673 snd_soc_dai_digital_mute(codec_dai, 0);
@@ -692,26 +686,23 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
692 struct snd_pcm_hw_params *params) 686 struct snd_pcm_hw_params *params)
693{ 687{
694 struct snd_soc_pcm_runtime *rtd = substream->private_data; 688 struct snd_soc_pcm_runtime *rtd = substream->private_data;
695 struct snd_soc_device *socdev = rtd->socdev; 689 struct snd_soc_platform *platform = rtd->platform;
696 struct snd_soc_dai_link *machine = rtd->dai; 690 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
697 struct snd_soc_card *card = socdev->card; 691 struct snd_soc_dai *codec_dai = rtd->codec_dai;
698 struct snd_soc_platform *platform = card->platform;
699 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
700 struct snd_soc_dai *codec_dai = machine->codec_dai;
701 int ret = 0; 692 int ret = 0;
702 693
703 mutex_lock(&pcm_mutex); 694 mutex_lock(&pcm_mutex);
704 695
705 if (machine->ops && machine->ops->hw_params) { 696 if (rtd->dai_link->ops && rtd->dai_link->ops->hw_params) {
706 ret = machine->ops->hw_params(substream, params); 697 ret = rtd->dai_link->ops->hw_params(substream, params);
707 if (ret < 0) { 698 if (ret < 0) {
708 printk(KERN_ERR "asoc: machine hw_params failed\n"); 699 printk(KERN_ERR "asoc: machine hw_params failed\n");
709 goto out; 700 goto out;
710 } 701 }
711 } 702 }
712 703
713 if (codec_dai->ops->hw_params) { 704 if (codec_dai->driver->ops->hw_params) {
714 ret = codec_dai->ops->hw_params(substream, params, codec_dai); 705 ret = codec_dai->driver->ops->hw_params(substream, params, codec_dai);
715 if (ret < 0) { 706 if (ret < 0) {
716 printk(KERN_ERR "asoc: can't set codec %s hw params\n", 707 printk(KERN_ERR "asoc: can't set codec %s hw params\n",
717 codec_dai->name); 708 codec_dai->name);
@@ -719,8 +710,8 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
719 } 710 }
720 } 711 }
721 712
722 if (cpu_dai->ops->hw_params) { 713 if (cpu_dai->driver->ops->hw_params) {
723 ret = cpu_dai->ops->hw_params(substream, params, cpu_dai); 714 ret = cpu_dai->driver->ops->hw_params(substream, params, cpu_dai);
724 if (ret < 0) { 715 if (ret < 0) {
725 printk(KERN_ERR "asoc: interface %s hw params failed\n", 716 printk(KERN_ERR "asoc: interface %s hw params failed\n",
726 cpu_dai->name); 717 cpu_dai->name);
@@ -728,8 +719,8 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
728 } 719 }
729 } 720 }
730 721
731 if (platform->pcm_ops->hw_params) { 722 if (platform->driver->ops->hw_params) {
732 ret = platform->pcm_ops->hw_params(substream, params); 723 ret = platform->driver->ops->hw_params(substream, params);
733 if (ret < 0) { 724 if (ret < 0) {
734 printk(KERN_ERR "asoc: platform %s hw params failed\n", 725 printk(KERN_ERR "asoc: platform %s hw params failed\n",
735 platform->name); 726 platform->name);
@@ -737,23 +728,23 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
737 } 728 }
738 } 729 }
739 730
740 machine->rate = params_rate(params); 731 rtd->rate = params_rate(params);
741 732
742out: 733out:
743 mutex_unlock(&pcm_mutex); 734 mutex_unlock(&pcm_mutex);
744 return ret; 735 return ret;
745 736
746platform_err: 737platform_err:
747 if (cpu_dai->ops->hw_free) 738 if (cpu_dai->driver->ops->hw_free)
748 cpu_dai->ops->hw_free(substream, cpu_dai); 739 cpu_dai->driver->ops->hw_free(substream, cpu_dai);
749 740
750interface_err: 741interface_err:
751 if (codec_dai->ops->hw_free) 742 if (codec_dai->driver->ops->hw_free)
752 codec_dai->ops->hw_free(substream, codec_dai); 743 codec_dai->driver->ops->hw_free(substream, codec_dai);
753 744
754codec_err: 745codec_err:
755 if (machine->ops && machine->ops->hw_free) 746 if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
756 machine->ops->hw_free(substream); 747 rtd->dai_link->ops->hw_free(substream);
757 748
758 mutex_unlock(&pcm_mutex); 749 mutex_unlock(&pcm_mutex);
759 return ret; 750 return ret;
@@ -765,13 +756,10 @@ codec_err:
765static int soc_pcm_hw_free(struct snd_pcm_substream *substream) 756static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
766{ 757{
767 struct snd_soc_pcm_runtime *rtd = substream->private_data; 758 struct snd_soc_pcm_runtime *rtd = substream->private_data;
768 struct snd_soc_device *socdev = rtd->socdev; 759 struct snd_soc_platform *platform = rtd->platform;
769 struct snd_soc_dai_link *machine = rtd->dai; 760 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
770 struct snd_soc_card *card = socdev->card; 761 struct snd_soc_dai *codec_dai = rtd->codec_dai;
771 struct snd_soc_platform *platform = card->platform; 762 struct snd_soc_codec *codec = rtd->codec;
772 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
773 struct snd_soc_dai *codec_dai = machine->codec_dai;
774 struct snd_soc_codec *codec = card->codec;
775 763
776 mutex_lock(&pcm_mutex); 764 mutex_lock(&pcm_mutex);
777 765
@@ -780,19 +768,19 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
780 snd_soc_dai_digital_mute(codec_dai, 1); 768 snd_soc_dai_digital_mute(codec_dai, 1);
781 769
782 /* free any machine hw params */ 770 /* free any machine hw params */
783 if (machine->ops && machine->ops->hw_free) 771 if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
784 machine->ops->hw_free(substream); 772 rtd->dai_link->ops->hw_free(substream);
785 773
786 /* free any DMA resources */ 774 /* free any DMA resources */
787 if (platform->pcm_ops->hw_free) 775 if (platform->driver->ops->hw_free)
788 platform->pcm_ops->hw_free(substream); 776 platform->driver->ops->hw_free(substream);
789 777
790 /* now free hw params for the DAI's */ 778 /* now free hw params for the DAI's */
791 if (codec_dai->ops->hw_free) 779 if (codec_dai->driver->ops->hw_free)
792 codec_dai->ops->hw_free(substream, codec_dai); 780 codec_dai->driver->ops->hw_free(substream, codec_dai);
793 781
794 if (cpu_dai->ops->hw_free) 782 if (cpu_dai->driver->ops->hw_free)
795 cpu_dai->ops->hw_free(substream, cpu_dai); 783 cpu_dai->driver->ops->hw_free(substream, cpu_dai);
796 784
797 mutex_unlock(&pcm_mutex); 785 mutex_unlock(&pcm_mutex);
798 return 0; 786 return 0;
@@ -801,28 +789,25 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
801static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 789static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
802{ 790{
803 struct snd_soc_pcm_runtime *rtd = substream->private_data; 791 struct snd_soc_pcm_runtime *rtd = substream->private_data;
804 struct snd_soc_device *socdev = rtd->socdev; 792 struct snd_soc_platform *platform = rtd->platform;
805 struct snd_soc_card *card= socdev->card; 793 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
806 struct snd_soc_dai_link *machine = rtd->dai; 794 struct snd_soc_dai *codec_dai = rtd->codec_dai;
807 struct snd_soc_platform *platform = card->platform;
808 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
809 struct snd_soc_dai *codec_dai = machine->codec_dai;
810 int ret; 795 int ret;
811 796
812 if (codec_dai->ops->trigger) { 797 if (codec_dai->driver->ops->trigger) {
813 ret = codec_dai->ops->trigger(substream, cmd, codec_dai); 798 ret = codec_dai->driver->ops->trigger(substream, cmd, codec_dai);
814 if (ret < 0) 799 if (ret < 0)
815 return ret; 800 return ret;
816 } 801 }
817 802
818 if (platform->pcm_ops->trigger) { 803 if (platform->driver->ops->trigger) {
819 ret = platform->pcm_ops->trigger(substream, cmd); 804 ret = platform->driver->ops->trigger(substream, cmd);
820 if (ret < 0) 805 if (ret < 0)
821 return ret; 806 return ret;
822 } 807 }
823 808
824 if (cpu_dai->ops->trigger) { 809 if (cpu_dai->driver->ops->trigger) {
825 ret = cpu_dai->ops->trigger(substream, cmd, cpu_dai); 810 ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai);
826 if (ret < 0) 811 if (ret < 0)
827 return ret; 812 return ret;
828 } 813 }
@@ -837,27 +822,24 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
837static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream) 822static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
838{ 823{
839 struct snd_soc_pcm_runtime *rtd = substream->private_data; 824 struct snd_soc_pcm_runtime *rtd = substream->private_data;
840 struct snd_soc_device *socdev = rtd->socdev; 825 struct snd_soc_platform *platform = rtd->platform;
841 struct snd_soc_card *card = socdev->card; 826 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
842 struct snd_soc_platform *platform = card->platform; 827 struct snd_soc_dai *codec_dai = rtd->codec_dai;
843 struct snd_soc_dai_link *machine = rtd->dai;
844 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
845 struct snd_soc_dai *codec_dai = machine->codec_dai;
846 struct snd_pcm_runtime *runtime = substream->runtime; 828 struct snd_pcm_runtime *runtime = substream->runtime;
847 snd_pcm_uframes_t offset = 0; 829 snd_pcm_uframes_t offset = 0;
848 snd_pcm_sframes_t delay = 0; 830 snd_pcm_sframes_t delay = 0;
849 831
850 if (platform->pcm_ops->pointer) 832 if (platform->driver->ops->pointer)
851 offset = platform->pcm_ops->pointer(substream); 833 offset = platform->driver->ops->pointer(substream);
852 834
853 if (cpu_dai->ops->delay) 835 if (cpu_dai->driver->ops->delay)
854 delay += cpu_dai->ops->delay(substream, cpu_dai); 836 delay += cpu_dai->driver->ops->delay(substream, cpu_dai);
855 837
856 if (codec_dai->ops->delay) 838 if (codec_dai->driver->ops->delay)
857 delay += codec_dai->ops->delay(substream, codec_dai); 839 delay += codec_dai->driver->ops->delay(substream, codec_dai);
858 840
859 if (platform->delay) 841 if (platform->driver->delay)
860 delay += platform->delay(substream, codec_dai); 842 delay += platform->driver->delay(substream, codec_dai);
861 843
862 runtime->delay = delay; 844 runtime->delay = delay;
863 845
@@ -880,104 +862,111 @@ static struct snd_pcm_ops soc_pcm_ops = {
880static int soc_suspend(struct device *dev) 862static int soc_suspend(struct device *dev)
881{ 863{
882 struct platform_device *pdev = to_platform_device(dev); 864 struct platform_device *pdev = to_platform_device(dev);
883 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 865 struct snd_soc_card *card = platform_get_drvdata(pdev);
884 struct snd_soc_card *card = socdev->card;
885 struct snd_soc_platform *platform = card->platform;
886 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
887 struct snd_soc_codec *codec = card->codec;
888 int i; 866 int i;
889 867
890 /* If the initialization of this soc device failed, there is no codec 868 /* If the initialization of this soc device failed, there is no codec
891 * associated with it. Just bail out in this case. 869 * associated with it. Just bail out in this case.
892 */ 870 */
893 if (!codec) 871 if (list_empty(&card->codec_dev_list))
894 return 0; 872 return 0;
895 873
896 /* Due to the resume being scheduled into a workqueue we could 874 /* Due to the resume being scheduled into a workqueue we could
897 * suspend before that's finished - wait for it to complete. 875 * suspend before that's finished - wait for it to complete.
898 */ 876 */
899 snd_power_lock(codec->card); 877 snd_power_lock(card->snd_card);
900 snd_power_wait(codec->card, SNDRV_CTL_POWER_D0); 878 snd_power_wait(card->snd_card, SNDRV_CTL_POWER_D0);
901 snd_power_unlock(codec->card); 879 snd_power_unlock(card->snd_card);
902 880
903 /* we're going to block userspace touching us until resume completes */ 881 /* we're going to block userspace touching us until resume completes */
904 snd_power_change_state(codec->card, SNDRV_CTL_POWER_D3hot); 882 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D3hot);
905 883
906 /* mute any active DAC's */ 884 /* mute any active DAC's */
907 for (i = 0; i < card->num_links; i++) { 885 for (i = 0; i < card->num_rtd; i++) {
908 struct snd_soc_dai *dai = card->dai_link[i].codec_dai; 886 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
887 struct snd_soc_dai_driver *drv = dai->driver;
909 888
910 if (card->dai_link[i].ignore_suspend) 889 if (card->rtd[i].dai_link->ignore_suspend)
911 continue; 890 continue;
912 891
913 if (dai->ops->digital_mute && dai->playback.active) 892 if (drv->ops->digital_mute && dai->playback_active)
914 dai->ops->digital_mute(dai, 1); 893 drv->ops->digital_mute(dai, 1);
915 } 894 }
916 895
917 /* suspend all pcms */ 896 /* suspend all pcms */
918 for (i = 0; i < card->num_links; i++) { 897 for (i = 0; i < card->num_rtd; i++) {
919 if (card->dai_link[i].ignore_suspend) 898 if (card->rtd[i].dai_link->ignore_suspend)
920 continue; 899 continue;
921 900
922 snd_pcm_suspend_all(card->dai_link[i].pcm); 901 snd_pcm_suspend_all(card->rtd[i].pcm);
923 } 902 }
924 903
925 if (card->suspend_pre) 904 if (card->suspend_pre)
926 card->suspend_pre(pdev, PMSG_SUSPEND); 905 card->suspend_pre(pdev, PMSG_SUSPEND);
927 906
928 for (i = 0; i < card->num_links; i++) { 907 for (i = 0; i < card->num_rtd; i++) {
929 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; 908 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
909 struct snd_soc_platform *platform = card->rtd[i].platform;
930 910
931 if (card->dai_link[i].ignore_suspend) 911 if (card->rtd[i].dai_link->ignore_suspend)
932 continue; 912 continue;
933 913
934 if (cpu_dai->suspend && !cpu_dai->ac97_control) 914 if (cpu_dai->driver->suspend && !cpu_dai->driver->ac97_control)
935 cpu_dai->suspend(cpu_dai); 915 cpu_dai->driver->suspend(cpu_dai);
936 if (platform->suspend) 916 if (platform->driver->suspend && !platform->suspended) {
937 platform->suspend(&card->dai_link[i]); 917 platform->driver->suspend(cpu_dai);
918 platform->suspended = 1;
919 }
938 } 920 }
939 921
940 /* close any waiting streams and save state */ 922 /* close any waiting streams and save state */
941 run_delayed_work(&card->delayed_work); 923 for (i = 0; i < card->num_rtd; i++) {
942 codec->suspend_bias_level = codec->bias_level; 924 run_delayed_work(&card->rtd[i].delayed_work);
925 card->rtd[i].codec->suspend_bias_level = card->rtd[i].codec->bias_level;
926 }
943 927
944 for (i = 0; i < codec->num_dai; i++) { 928 for (i = 0; i < card->num_rtd; i++) {
945 char *stream = codec->dai[i].playback.stream_name; 929 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
946 930
947 if (card->dai_link[i].ignore_suspend) 931 if (card->rtd[i].dai_link->ignore_suspend)
948 continue; 932 continue;
949 933
950 if (stream != NULL) 934 if (driver->playback.stream_name != NULL)
951 snd_soc_dapm_stream_event(codec, stream, 935 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
952 SND_SOC_DAPM_STREAM_SUSPEND); 936 SND_SOC_DAPM_STREAM_SUSPEND);
953 stream = codec->dai[i].capture.stream_name; 937
954 if (stream != NULL) 938 if (driver->capture.stream_name != NULL)
955 snd_soc_dapm_stream_event(codec, stream, 939 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
956 SND_SOC_DAPM_STREAM_SUSPEND); 940 SND_SOC_DAPM_STREAM_SUSPEND);
957 } 941 }
958 942
959 /* If there are paths active then the CODEC will be held with 943 /* suspend all CODECs */
960 * bias _ON and should not be suspended. */ 944 for (i = 0; i < card->num_rtd; i++) {
961 if (codec_dev->suspend) { 945 struct snd_soc_codec *codec = card->rtd[i].codec;
962 switch (codec->bias_level) { 946 /* If there are paths active then the CODEC will be held with
963 case SND_SOC_BIAS_STANDBY: 947 * bias _ON and should not be suspended. */
964 case SND_SOC_BIAS_OFF: 948 if (!codec->suspended && codec->driver->suspend) {
965 codec_dev->suspend(pdev, PMSG_SUSPEND); 949 switch (codec->bias_level) {
966 break; 950 case SND_SOC_BIAS_STANDBY:
967 default: 951 case SND_SOC_BIAS_OFF:
968 dev_dbg(socdev->dev, "CODEC is on over suspend\n"); 952 codec->driver->suspend(codec, PMSG_SUSPEND);
969 break; 953 codec->suspended = 1;
954 break;
955 default:
956 dev_dbg(codec->dev, "CODEC is on over suspend\n");
957 break;
958 }
970 } 959 }
971 } 960 }
972 961
973 for (i = 0; i < card->num_links; i++) { 962 for (i = 0; i < card->num_rtd; i++) {
974 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; 963 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
975 964
976 if (card->dai_link[i].ignore_suspend) 965 if (card->rtd[i].dai_link->ignore_suspend)
977 continue; 966 continue;
978 967
979 if (cpu_dai->suspend && cpu_dai->ac97_control) 968 if (cpu_dai->driver->suspend && cpu_dai->driver->ac97_control)
980 cpu_dai->suspend(cpu_dai); 969 cpu_dai->driver->suspend(cpu_dai);
981 } 970 }
982 971
983 if (card->suspend_post) 972 if (card->suspend_post)
@@ -991,127 +980,127 @@ static int soc_suspend(struct device *dev)
991 */ 980 */
992static void soc_resume_deferred(struct work_struct *work) 981static void soc_resume_deferred(struct work_struct *work)
993{ 982{
994 struct snd_soc_card *card = container_of(work, 983 struct snd_soc_card *card =
995 struct snd_soc_card, 984 container_of(work, struct snd_soc_card, deferred_resume_work);
996 deferred_resume_work); 985 struct platform_device *pdev = to_platform_device(card->dev);
997 struct snd_soc_device *socdev = card->socdev;
998 struct snd_soc_platform *platform = card->platform;
999 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
1000 struct snd_soc_codec *codec = card->codec;
1001 struct platform_device *pdev = to_platform_device(socdev->dev);
1002 int i; 986 int i;
1003 987
1004 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time, 988 /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
1005 * so userspace apps are blocked from touching us 989 * so userspace apps are blocked from touching us
1006 */ 990 */
1007 991
1008 dev_dbg(socdev->dev, "starting resume work\n"); 992 dev_dbg(card->dev, "starting resume work\n");
1009 993
1010 /* Bring us up into D2 so that DAPM starts enabling things */ 994 /* Bring us up into D2 so that DAPM starts enabling things */
1011 snd_power_change_state(codec->card, SNDRV_CTL_POWER_D2); 995 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
1012 996
1013 if (card->resume_pre) 997 if (card->resume_pre)
1014 card->resume_pre(pdev); 998 card->resume_pre(pdev);
1015 999
1016 for (i = 0; i < card->num_links; i++) { 1000 /* resume AC97 DAIs */
1017 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; 1001 for (i = 0; i < card->num_rtd; i++) {
1002 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
1018 1003
1019 if (card->dai_link[i].ignore_suspend) 1004 if (card->rtd[i].dai_link->ignore_suspend)
1020 continue; 1005 continue;
1021 1006
1022 if (cpu_dai->resume && cpu_dai->ac97_control) 1007 if (cpu_dai->driver->resume && cpu_dai->driver->ac97_control)
1023 cpu_dai->resume(cpu_dai); 1008 cpu_dai->driver->resume(cpu_dai);
1024 } 1009 }
1025 1010
1026 /* If the CODEC was idle over suspend then it will have been 1011 for (i = 0; i < card->num_rtd; i++) {
1027 * left with bias OFF or STANDBY and suspended so we must now 1012 struct snd_soc_codec *codec = card->rtd[i].codec;
1028 * resume. Otherwise the suspend was suppressed. 1013 /* If the CODEC was idle over suspend then it will have been
1029 */ 1014 * left with bias OFF or STANDBY and suspended so we must now
1030 if (codec_dev->resume) { 1015 * resume. Otherwise the suspend was suppressed.
1031 switch (codec->bias_level) { 1016 */
1032 case SND_SOC_BIAS_STANDBY: 1017 if (codec->driver->resume && codec->suspended) {
1033 case SND_SOC_BIAS_OFF: 1018 switch (codec->bias_level) {
1034 codec_dev->resume(pdev); 1019 case SND_SOC_BIAS_STANDBY:
1035 break; 1020 case SND_SOC_BIAS_OFF:
1036 default: 1021 codec->driver->resume(codec);
1037 dev_dbg(socdev->dev, "CODEC was on over suspend\n"); 1022 codec->suspended = 0;
1038 break; 1023 break;
1024 default:
1025 dev_dbg(codec->dev, "CODEC was on over suspend\n");
1026 break;
1027 }
1039 } 1028 }
1040 } 1029 }
1041 1030
1042 for (i = 0; i < codec->num_dai; i++) { 1031 for (i = 0; i < card->num_rtd; i++) {
1043 char *stream = codec->dai[i].playback.stream_name; 1032 struct snd_soc_dai_driver *driver = card->rtd[i].codec_dai->driver;
1044 1033
1045 if (card->dai_link[i].ignore_suspend) 1034 if (card->rtd[i].dai_link->ignore_suspend)
1046 continue; 1035 continue;
1047 1036
1048 if (stream != NULL) 1037 if (driver->playback.stream_name != NULL)
1049 snd_soc_dapm_stream_event(codec, stream, 1038 snd_soc_dapm_stream_event(&card->rtd[i], driver->playback.stream_name,
1050 SND_SOC_DAPM_STREAM_RESUME); 1039 SND_SOC_DAPM_STREAM_RESUME);
1051 stream = codec->dai[i].capture.stream_name; 1040
1052 if (stream != NULL) 1041 if (driver->capture.stream_name != NULL)
1053 snd_soc_dapm_stream_event(codec, stream, 1042 snd_soc_dapm_stream_event(&card->rtd[i], driver->capture.stream_name,
1054 SND_SOC_DAPM_STREAM_RESUME); 1043 SND_SOC_DAPM_STREAM_RESUME);
1055 } 1044 }
1056 1045
1057 /* unmute any active DACs */ 1046 /* unmute any active DACs */
1058 for (i = 0; i < card->num_links; i++) { 1047 for (i = 0; i < card->num_rtd; i++) {
1059 struct snd_soc_dai *dai = card->dai_link[i].codec_dai; 1048 struct snd_soc_dai *dai = card->rtd[i].codec_dai;
1049 struct snd_soc_dai_driver *drv = dai->driver;
1060 1050
1061 if (card->dai_link[i].ignore_suspend) 1051 if (card->rtd[i].dai_link->ignore_suspend)
1062 continue; 1052 continue;
1063 1053
1064 if (dai->ops->digital_mute && dai->playback.active) 1054 if (drv->ops->digital_mute && dai->playback_active)
1065 dai->ops->digital_mute(dai, 0); 1055 drv->ops->digital_mute(dai, 0);
1066 } 1056 }
1067 1057
1068 for (i = 0; i < card->num_links; i++) { 1058 for (i = 0; i < card->num_rtd; i++) {
1069 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; 1059 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
1060 struct snd_soc_platform *platform = card->rtd[i].platform;
1070 1061
1071 if (card->dai_link[i].ignore_suspend) 1062 if (card->rtd[i].dai_link->ignore_suspend)
1072 continue; 1063 continue;
1073 1064
1074 if (cpu_dai->resume && !cpu_dai->ac97_control) 1065 if (cpu_dai->driver->resume && !cpu_dai->driver->ac97_control)
1075 cpu_dai->resume(cpu_dai); 1066 cpu_dai->driver->resume(cpu_dai);
1076 if (platform->resume) 1067 if (platform->driver->resume && platform->suspended) {
1077 platform->resume(&card->dai_link[i]); 1068 platform->driver->resume(cpu_dai);
1069 platform->suspended = 0;
1070 }
1078 } 1071 }
1079 1072
1080 if (card->resume_post) 1073 if (card->resume_post)
1081 card->resume_post(pdev); 1074 card->resume_post(pdev);
1082 1075
1083 dev_dbg(socdev->dev, "resume work completed\n"); 1076 dev_dbg(card->dev, "resume work completed\n");
1084 1077
1085 /* userspace can access us now we are back as we were before */ 1078 /* userspace can access us now we are back as we were before */
1086 snd_power_change_state(codec->card, SNDRV_CTL_POWER_D0); 1079 snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D0);
1087} 1080}
1088 1081
1089/* powers up audio subsystem after a suspend */ 1082/* powers up audio subsystem after a suspend */
1090static int soc_resume(struct device *dev) 1083static int soc_resume(struct device *dev)
1091{ 1084{
1092 struct platform_device *pdev = to_platform_device(dev); 1085 struct platform_device *pdev = to_platform_device(dev);
1093 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1086 struct snd_soc_card *card = platform_get_drvdata(pdev);
1094 struct snd_soc_card *card = socdev->card; 1087 int i;
1095 struct snd_soc_dai *cpu_dai = card->dai_link[0].cpu_dai;
1096
1097 /* If the initialization of this soc device failed, there is no codec
1098 * associated with it. Just bail out in this case.
1099 */
1100 if (!card->codec)
1101 return 0;
1102 1088
1103 /* AC97 devices might have other drivers hanging off them so 1089 /* AC97 devices might have other drivers hanging off them so
1104 * need to resume immediately. Other drivers don't have that 1090 * need to resume immediately. Other drivers don't have that
1105 * problem and may take a substantial amount of time to resume 1091 * problem and may take a substantial amount of time to resume
1106 * due to I/O costs and anti-pop so handle them out of line. 1092 * due to I/O costs and anti-pop so handle them out of line.
1107 */ 1093 */
1108 if (cpu_dai->ac97_control) { 1094 for (i = 0; i < card->num_rtd; i++) {
1109 dev_dbg(socdev->dev, "Resuming AC97 immediately\n"); 1095 struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
1110 soc_resume_deferred(&card->deferred_resume_work); 1096 if (cpu_dai->driver->ac97_control) {
1111 } else { 1097 dev_dbg(dev, "Resuming AC97 immediately\n");
1112 dev_dbg(socdev->dev, "Scheduling resume work\n"); 1098 soc_resume_deferred(&card->deferred_resume_work);
1113 if (!schedule_work(&card->deferred_resume_work)) 1099 } else {
1114 dev_err(socdev->dev, "resume work item may be lost\n"); 1100 dev_dbg(dev, "Scheduling resume work\n");
1101 if (!schedule_work(&card->deferred_resume_work))
1102 dev_err(dev, "resume work item may be lost\n");
1103 }
1115 } 1104 }
1116 1105
1117 return 0; 1106 return 0;
@@ -1124,198 +1113,429 @@ static int soc_resume(struct device *dev)
1124static struct snd_soc_dai_ops null_dai_ops = { 1113static struct snd_soc_dai_ops null_dai_ops = {
1125}; 1114};
1126 1115
1127static void snd_soc_instantiate_card(struct snd_soc_card *card) 1116static int soc_bind_dai_link(struct snd_soc_card *card, int num)
1128{ 1117{
1129 struct platform_device *pdev = container_of(card->dev, 1118 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1130 struct platform_device, 1119 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1131 dev);
1132 struct snd_soc_codec_device *codec_dev = card->socdev->codec_dev;
1133 struct snd_soc_codec *codec; 1120 struct snd_soc_codec *codec;
1134 struct snd_soc_platform *platform; 1121 struct snd_soc_platform *platform;
1135 struct snd_soc_dai *dai; 1122 struct snd_soc_dai *codec_dai, *cpu_dai;
1136 int i, found, ret, ac97;
1137 1123
1138 if (card->instantiated) 1124 if (rtd->complete)
1139 return; 1125 return 1;
1126 dev_dbg(card->dev, "binding %s at idx %d\n", dai_link->name, num);
1140 1127
1141 found = 0; 1128 /* do we already have the CPU DAI for this link ? */
1142 list_for_each_entry(platform, &platform_list, list) 1129 if (rtd->cpu_dai) {
1143 if (card->platform == platform) { 1130 goto find_codec;
1144 found = 1; 1131 }
1145 break; 1132 /* no, then find CPU DAI from registered DAIs*/
1133 list_for_each_entry(cpu_dai, &dai_list, list) {
1134 if (!strcmp(cpu_dai->name, dai_link->cpu_dai_name)) {
1135
1136 if (!try_module_get(cpu_dai->dev->driver->owner))
1137 return -ENODEV;
1138
1139 rtd->cpu_dai = cpu_dai;
1140 goto find_codec;
1146 } 1141 }
1147 if (!found) {
1148 dev_dbg(card->dev, "Platform %s not registered\n",
1149 card->platform->name);
1150 return;
1151 } 1142 }
1143 dev_dbg(card->dev, "CPU DAI %s not registered\n",
1144 dai_link->cpu_dai_name);
1152 1145
1153 ac97 = 0; 1146find_codec:
1154 for (i = 0; i < card->num_links; i++) { 1147 /* do we already have the CODEC for this link ? */
1155 found = 0; 1148 if (rtd->codec) {
1156 list_for_each_entry(dai, &dai_list, list) 1149 goto find_platform;
1157 if (card->dai_link[i].cpu_dai == dai) { 1150 }
1158 found = 1; 1151
1159 break; 1152 /* no, then find CODEC from registered CODECs*/
1153 list_for_each_entry(codec, &codec_list, list) {
1154 if (!strcmp(codec->name, dai_link->codec_name)) {
1155 rtd->codec = codec;
1156
1157 if (!try_module_get(codec->dev->driver->owner))
1158 return -ENODEV;
1159
1160 /* CODEC found, so find CODEC DAI from registered DAIs from this CODEC*/
1161 list_for_each_entry(codec_dai, &dai_list, list) {
1162 if (codec->dev == codec_dai->dev &&
1163 !strcmp(codec_dai->name, dai_link->codec_dai_name)) {
1164 rtd->codec_dai = codec_dai;
1165 goto find_platform;
1166 }
1160 } 1167 }
1161 if (!found) { 1168 dev_dbg(card->dev, "CODEC DAI %s not registered\n",
1162 dev_dbg(card->dev, "DAI %s not registered\n", 1169 dai_link->codec_dai_name);
1163 card->dai_link[i].cpu_dai->name); 1170
1164 return; 1171 goto find_platform;
1165 } 1172 }
1173 }
1174 dev_dbg(card->dev, "CODEC %s not registered\n",
1175 dai_link->codec_name);
1166 1176
1167 if (card->dai_link[i].cpu_dai->ac97_control) 1177find_platform:
1168 ac97 = 1; 1178 /* do we already have the CODEC DAI for this link ? */
1179 if (rtd->platform) {
1180 goto out;
1169 } 1181 }
1182 /* no, then find CPU DAI from registered DAIs*/
1183 list_for_each_entry(platform, &platform_list, list) {
1184 if (!strcmp(platform->name, dai_link->platform_name)) {
1170 1185
1171 for (i = 0; i < card->num_links; i++) { 1186 if (!try_module_get(platform->dev->driver->owner))
1172 if (!card->dai_link[i].codec_dai->ops) 1187 return -ENODEV;
1173 card->dai_link[i].codec_dai->ops = &null_dai_ops; 1188
1189 rtd->platform = platform;
1190 goto out;
1191 }
1174 } 1192 }
1175 1193
1176 /* If we have AC97 in the system then don't wait for the 1194 dev_dbg(card->dev, "platform %s not registered\n",
1177 * codec. This will need revisiting if we have to handle 1195 dai_link->platform_name);
1178 * systems with mixed AC97 and non-AC97 parts. Only check for 1196 return 0;
1179 * DAIs currently; we can't do this per link since some AC97 1197
1180 * codecs have non-AC97 DAIs. 1198out:
1181 */ 1199 /* mark rtd as complete if we found all 4 of our client devices */
1182 if (!ac97) 1200 if (rtd->codec && rtd->codec_dai && rtd->platform && rtd->cpu_dai) {
1183 for (i = 0; i < card->num_links; i++) { 1201 rtd->complete = 1;
1184 found = 0; 1202 card->num_rtd++;
1185 list_for_each_entry(dai, &dai_list, list) 1203 }
1186 if (card->dai_link[i].codec_dai == dai) { 1204 return 1;
1187 found = 1; 1205}
1188 break; 1206
1189 } 1207static void soc_remove_dai_link(struct snd_soc_card *card, int num)
1190 if (!found) { 1208{
1191 dev_dbg(card->dev, "DAI %s not registered\n", 1209 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1192 card->dai_link[i].codec_dai->name); 1210 struct snd_soc_codec *codec = rtd->codec;
1193 return; 1211 struct snd_soc_platform *platform = rtd->platform;
1194 } 1212 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
1213 int err;
1214
1215 /* unregister the rtd device */
1216 if (rtd->dev_registered) {
1217 device_remove_file(&rtd->dev, &dev_attr_pmdown_time);
1218 device_unregister(&rtd->dev);
1219 rtd->dev_registered = 0;
1220 }
1221
1222 /* remove the CODEC DAI */
1223 if (codec_dai && codec_dai->probed) {
1224 if (codec_dai->driver->remove) {
1225 err = codec_dai->driver->remove(codec_dai);
1226 if (err < 0)
1227 printk(KERN_ERR "asoc: failed to remove %s\n", codec_dai->name);
1195 } 1228 }
1229 codec_dai->probed = 0;
1230 list_del(&codec_dai->card_list);
1231 }
1196 1232
1197 /* Note that we do not current check for codec components */ 1233 /* remove the platform */
1234 if (platform && platform->probed) {
1235 if (platform->driver->remove) {
1236 err = platform->driver->remove(platform);
1237 if (err < 0)
1238 printk(KERN_ERR "asoc: failed to remove %s\n", platform->name);
1239 }
1240 platform->probed = 0;
1241 list_del(&platform->card_list);
1242 module_put(platform->dev->driver->owner);
1243 }
1198 1244
1199 dev_dbg(card->dev, "All components present, instantiating\n"); 1245 /* remove the CODEC */
1246 if (codec && codec->probed) {
1247 if (codec->driver->remove) {
1248 err = codec->driver->remove(codec);
1249 if (err < 0)
1250 printk(KERN_ERR "asoc: failed to remove %s\n", codec->name);
1251 }
1200 1252
1201 /* Found everything, bring it up */ 1253 /* Make sure all DAPM widgets are freed */
1202 card->pmdown_time = pmdown_time; 1254 snd_soc_dapm_free(codec);
1203 1255
1204 if (card->probe) { 1256 soc_cleanup_codec_debugfs(codec);
1205 ret = card->probe(pdev); 1257 device_remove_file(&rtd->dev, &dev_attr_codec_reg);
1206 if (ret < 0) 1258 codec->probed = 0;
1207 return; 1259 list_del(&codec->card_list);
1260 module_put(codec->dev->driver->owner);
1208 } 1261 }
1209 1262
1210 for (i = 0; i < card->num_links; i++) { 1263 /* remove the cpu_dai */
1211 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; 1264 if (cpu_dai && cpu_dai->probed) {
1212 if (cpu_dai->probe) { 1265 if (cpu_dai->driver->remove) {
1213 ret = cpu_dai->probe(pdev, cpu_dai); 1266 err = cpu_dai->driver->remove(cpu_dai);
1214 if (ret < 0) 1267 if (err < 0)
1215 goto cpu_dai_err; 1268 printk(KERN_ERR "asoc: failed to remove %s\n", cpu_dai->name);
1216 } 1269 }
1270 cpu_dai->probed = 0;
1271 list_del(&cpu_dai->card_list);
1272 module_put(cpu_dai->dev->driver->owner);
1217 } 1273 }
1274}
1218 1275
1219 if (codec_dev->probe) { 1276static void rtd_release(struct device *dev) {}
1220 ret = codec_dev->probe(pdev); 1277
1221 if (ret < 0) 1278static int soc_probe_dai_link(struct snd_soc_card *card, int num)
1222 goto cpu_dai_err; 1279{
1280 struct snd_soc_dai_link *dai_link = &card->dai_link[num];
1281 struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
1282 struct snd_soc_codec *codec = rtd->codec;
1283 struct snd_soc_platform *platform = rtd->platform;
1284 struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
1285 int ret;
1286
1287 dev_dbg(card->dev, "probe %s dai link %d\n", card->name, num);
1288
1289 /* config components */
1290 codec_dai->codec = codec;
1291 codec->card = card;
1292 cpu_dai->platform = platform;
1293 rtd->card = card;
1294 rtd->dev.parent = card->dev;
1295 codec_dai->card = card;
1296 cpu_dai->card = card;
1297
1298 /* set default power off timeout */
1299 rtd->pmdown_time = pmdown_time;
1300
1301 /* probe the cpu_dai */
1302 if (!cpu_dai->probed) {
1303 if (cpu_dai->driver->probe) {
1304 ret = cpu_dai->driver->probe(cpu_dai);
1305 if (ret < 0) {
1306 printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n",
1307 cpu_dai->name);
1308 return ret;
1309 }
1310 }
1311 cpu_dai->probed = 1;
1312 /* mark cpu_dai as probed and add to card cpu_dai list */
1313 list_add(&cpu_dai->card_list, &card->dai_dev_list);
1223 } 1314 }
1224 codec = card->codec;
1225 1315
1226 if (platform->probe) { 1316 /* probe the CODEC */
1227 ret = platform->probe(pdev); 1317 if (!codec->probed) {
1228 if (ret < 0) 1318 if (codec->driver->probe) {
1229 goto platform_err; 1319 ret = codec->driver->probe(codec);
1320 if (ret < 0) {
1321 printk(KERN_ERR "asoc: failed to probe CODEC %s\n",
1322 codec->name);
1323 return ret;
1324 }
1325 }
1326 /* mark codec as probed and add to card codec list */
1327 codec->probed = 1;
1328 list_add(&codec->card_list, &card->codec_dev_list);
1230 } 1329 }
1231 1330
1232 /* DAPM stream work */ 1331 /* probe the platform */
1233 INIT_DELAYED_WORK(&card->delayed_work, close_delayed_work); 1332 if (!platform->probed) {
1234#ifdef CONFIG_PM 1333 if (platform->driver->probe) {
1235 /* deferred resume work */ 1334 ret = platform->driver->probe(platform);
1236 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred); 1335 if (ret < 0) {
1237#endif 1336 printk(KERN_ERR "asoc: failed to probe platform %s\n",
1337 platform->name);
1338 return ret;
1339 }
1340 }
1341 /* mark platform as probed and add to card platform list */
1342 platform->probed = 1;
1343 list_add(&platform->card_list, &card->platform_dev_list);
1344 }
1238 1345
1239 for (i = 0; i < card->num_links; i++) { 1346 /* probe the CODEC DAI */
1240 if (card->dai_link[i].init) { 1347 if (!codec_dai->probed) {
1241 ret = card->dai_link[i].init(codec); 1348 if (codec_dai->driver->probe) {
1349 ret = codec_dai->driver->probe(codec_dai);
1242 if (ret < 0) { 1350 if (ret < 0) {
1243 printk(KERN_ERR "asoc: failed to init %s\n", 1351 printk(KERN_ERR "asoc: failed to probe CODEC DAI %s\n",
1244 card->dai_link[i].stream_name); 1352 codec_dai->name);
1245 continue; 1353 return ret;
1246 } 1354 }
1247 } 1355 }
1248 if (card->dai_link[i].codec_dai->ac97_control) 1356
1249 ac97 = 1; 1357 /* mark cpu_dai as probed and add to card cpu_dai list */
1358 codec_dai->probed = 1;
1359 list_add(&codec_dai->card_list, &card->dai_dev_list);
1250 } 1360 }
1251 1361
1252 snprintf(codec->card->shortname, sizeof(codec->card->shortname), 1362 /* DAPM dai link stream work */
1253 "%s", card->name); 1363 INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
1254 snprintf(codec->card->longname, sizeof(codec->card->longname), 1364
1255 "%s (%s)", card->name, codec->name); 1365 /* now that all clients have probed, initialise the DAI link */
1366 if (dai_link->init) {
1367 ret = dai_link->init(rtd);
1368 if (ret < 0) {
1369 printk(KERN_ERR "asoc: failed to init %s\n", dai_link->stream_name);
1370 return ret;
1371 }
1372 }
1256 1373
1257 /* Make sure all DAPM widgets are instantiated */ 1374 /* Make sure all DAPM widgets are instantiated */
1258 snd_soc_dapm_new_widgets(codec); 1375 snd_soc_dapm_new_widgets(codec);
1376 snd_soc_dapm_sync(codec);
1259 1377
1260 ret = snd_card_register(codec->card); 1378 /* register the rtd device */
1379 rtd->dev.init_name = rtd->dai_link->stream_name;
1380 rtd->dev.release = rtd_release;
1381 rtd->dev.init_name = dai_link->name;
1382 ret = device_register(&rtd->dev);
1261 if (ret < 0) { 1383 if (ret < 0) {
1262 printk(KERN_ERR "asoc: failed to register soundcard for %s\n", 1384 printk(KERN_ERR "asoc: failed to register DAI runtime device %d\n", ret);
1263 codec->name); 1385 return ret;
1264 goto card_err;
1265 } 1386 }
1266 1387
1267 mutex_lock(&codec->mutex); 1388 rtd->dev_registered = 1;
1389 ret = device_create_file(&rtd->dev, &dev_attr_pmdown_time);
1390 if (ret < 0)
1391 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1392
1393 /* add DAPM sysfs entries for this codec */
1394 ret = snd_soc_dapm_sys_add(&rtd->dev);
1395 if (ret < 0)
1396 printk(KERN_WARNING "asoc: failed to add codec dapm sysfs entries\n");
1397
1398 /* add codec sysfs entries */
1399 ret = device_create_file(&rtd->dev, &dev_attr_codec_reg);
1400 if (ret < 0)
1401 printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
1402
1403 soc_init_codec_debugfs(codec);
1404
1405 /* create the pcm */
1406 ret = soc_new_pcm(rtd, num);
1407 if (ret < 0) {
1408 printk(KERN_ERR "asoc: can't create pcm %s\n", dai_link->stream_name);
1409 return ret;
1410 }
1411
1412 /* add platform data for AC97 devices */
1413 if (rtd->codec_dai->driver->ac97_control)
1414 snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
1415
1416 return 0;
1417}
1418
1268#ifdef CONFIG_SND_SOC_AC97_BUS 1419#ifdef CONFIG_SND_SOC_AC97_BUS
1420static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
1421{
1422 int ret;
1423
1269 /* Only instantiate AC97 if not already done by the adaptor 1424 /* Only instantiate AC97 if not already done by the adaptor
1270 * for the generic AC97 subsystem. 1425 * for the generic AC97 subsystem.
1271 */ 1426 */
1272 if (ac97 && strcmp(codec->name, "AC97") != 0) { 1427 if (rtd->codec_dai->driver->ac97_control && !rtd->codec->ac97_registered) {
1273 ret = soc_ac97_dev_register(codec); 1428
1429 ret = soc_ac97_dev_register(rtd->codec);
1274 if (ret < 0) { 1430 if (ret < 0) {
1275 printk(KERN_ERR "asoc: AC97 device register failed\n"); 1431 printk(KERN_ERR "asoc: AC97 device register failed\n");
1276 snd_card_free(codec->card); 1432 return ret;
1277 mutex_unlock(&codec->mutex);
1278 goto card_err;
1279 } 1433 }
1434
1435 rtd->codec->ac97_registered = 1;
1280 } 1436 }
1437 return 0;
1438}
1439
1440static void soc_unregister_ac97_dai_link(struct snd_soc_codec *codec)
1441{
1442 if (codec->ac97_registered) {
1443 soc_ac97_dev_unregister(codec);
1444 codec->ac97_registered = 0;
1445 }
1446}
1281#endif 1447#endif
1282 1448
1283 ret = snd_soc_dapm_sys_add(card->socdev->dev); 1449static void snd_soc_instantiate_card(struct snd_soc_card *card)
1284 if (ret < 0) 1450{
1285 printk(KERN_WARNING "asoc: failed to add dapm sysfs entries\n"); 1451 struct platform_device *pdev = to_platform_device(card->dev);
1452 int ret, i;
1286 1453
1287 ret = device_create_file(card->socdev->dev, &dev_attr_pmdown_time); 1454 mutex_lock(&card->mutex);
1288 if (ret < 0)
1289 printk(KERN_WARNING "asoc: failed to add pmdown_time sysfs\n");
1290 1455
1291 ret = device_create_file(card->socdev->dev, &dev_attr_codec_reg); 1456 if (card->instantiated) {
1292 if (ret < 0) 1457 mutex_unlock(&card->mutex);
1293 printk(KERN_WARNING "asoc: failed to add codec sysfs files\n"); 1458 return;
1459 }
1294 1460
1295 soc_init_codec_debugfs(codec); 1461 /* bind DAIs */
1296 mutex_unlock(&codec->mutex); 1462 for (i = 0; i < card->num_links; i++)
1463 soc_bind_dai_link(card, i);
1297 1464
1298 card->instantiated = 1; 1465 /* bind completed ? */
1466 if (card->num_rtd != card->num_links) {
1467 mutex_unlock(&card->mutex);
1468 return;
1469 }
1299 1470
1300 return; 1471 /* card bind complete so register a sound card */
1472 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1473 card->owner, 0, &card->snd_card);
1474 if (ret < 0) {
1475 printk(KERN_ERR "asoc: can't create sound card for card %s\n",
1476 card->name);
1477 mutex_unlock(&card->mutex);
1478 return;
1479 }
1480 card->snd_card->dev = card->dev;
1481
1482#ifdef CONFIG_PM
1483 /* deferred resume work */
1484 INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
1485#endif
1301 1486
1302card_err: 1487 /* initialise the sound card only once */
1303 if (platform->remove) 1488 if (card->probe) {
1304 platform->remove(pdev); 1489 ret = card->probe(pdev);
1490 if (ret < 0)
1491 goto card_probe_error;
1492 }
1305 1493
1306platform_err: 1494 for (i = 0; i < card->num_links; i++) {
1307 if (codec_dev->remove) 1495 ret = soc_probe_dai_link(card, i);
1308 codec_dev->remove(pdev); 1496 if (ret < 0) {
1497 printk(KERN_ERR "asoc: failed to instanciate card %s\n", card->name);
1498 goto probe_dai_err;
1499 }
1500 }
1309 1501
1310cpu_dai_err: 1502 snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
1311 for (i--; i >= 0; i--) { 1503 "%s", card->name);
1312 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai; 1504 snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
1313 if (cpu_dai->remove) 1505 "%s", card->name);
1314 cpu_dai->remove(pdev, cpu_dai); 1506
1507 ret = snd_card_register(card->snd_card);
1508 if (ret < 0) {
1509 printk(KERN_ERR "asoc: failed to register soundcard for %s\n", card->name);
1510 goto probe_dai_err;
1315 } 1511 }
1316 1512
1513#ifdef CONFIG_SND_SOC_AC97_BUS
1514 /* register any AC97 codecs */
1515 for (i = 0; i < card->num_rtd; i++) {
1516 ret = soc_register_ac97_dai_link(&card->rtd[i]);
1517 if (ret < 0) {
1518 printk(KERN_ERR "asoc: failed to register AC97 %s\n", card->name);
1519 goto probe_dai_err;
1520 }
1521 }
1522#endif
1523
1524 card->instantiated = 1;
1525 mutex_unlock(&card->mutex);
1526 return;
1527
1528probe_dai_err:
1529 for (i = 0; i < card->num_links; i++)
1530 soc_remove_dai_link(card, i);
1531
1532card_probe_error:
1317 if (card->remove) 1533 if (card->remove)
1318 card->remove(pdev); 1534 card->remove(pdev);
1535
1536 snd_card_free(card->snd_card);
1537
1538 mutex_unlock(&card->mutex);
1319} 1539}
1320 1540
1321/* 1541/*
@@ -1332,15 +1552,15 @@ static void snd_soc_instantiate_cards(void)
1332/* probes a new socdev */ 1552/* probes a new socdev */
1333static int soc_probe(struct platform_device *pdev) 1553static int soc_probe(struct platform_device *pdev)
1334{ 1554{
1555 struct snd_soc_card *card = platform_get_drvdata(pdev);
1335 int ret = 0; 1556 int ret = 0;
1336 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1337 struct snd_soc_card *card = socdev->card;
1338
1339 /* Bodge while we push things out of socdev */
1340 card->socdev = socdev;
1341 1557
1342 /* Bodge while we unpick instantiation */ 1558 /* Bodge while we unpick instantiation */
1343 card->dev = &pdev->dev; 1559 card->dev = &pdev->dev;
1560 INIT_LIST_HEAD(&card->dai_dev_list);
1561 INIT_LIST_HEAD(&card->codec_dev_list);
1562 INIT_LIST_HEAD(&card->platform_dev_list);
1563
1344 ret = snd_soc_register_card(card); 1564 ret = snd_soc_register_card(card);
1345 if (ret != 0) { 1565 if (ret != 0) {
1346 dev_err(&pdev->dev, "Failed to register card\n"); 1566 dev_err(&pdev->dev, "Failed to register card\n");
@@ -1353,50 +1573,49 @@ static int soc_probe(struct platform_device *pdev)
1353/* removes a socdev */ 1573/* removes a socdev */
1354static int soc_remove(struct platform_device *pdev) 1574static int soc_remove(struct platform_device *pdev)
1355{ 1575{
1576 struct snd_soc_card *card = platform_get_drvdata(pdev);
1356 int i; 1577 int i;
1357 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1358 struct snd_soc_card *card = socdev->card;
1359 struct snd_soc_platform *platform = card->platform;
1360 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
1361 1578
1362 if (card->instantiated) { 1579 if (card->instantiated) {
1363 run_delayed_work(&card->delayed_work);
1364 1580
1365 if (platform->remove) 1581 /* make sure any delayed work runs */
1366 platform->remove(pdev); 1582 for (i = 0; i < card->num_rtd; i++) {
1367 1583 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1368 if (codec_dev->remove) 1584 run_delayed_work(&rtd->delayed_work);
1369 codec_dev->remove(pdev);
1370
1371 for (i = 0; i < card->num_links; i++) {
1372 struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
1373 if (cpu_dai->remove)
1374 cpu_dai->remove(pdev, cpu_dai);
1375 } 1585 }
1376 1586
1587 /* remove and free each DAI */
1588 for (i = 0; i < card->num_rtd; i++)
1589 soc_remove_dai_link(card, i);
1590
1591 /* remove the card */
1377 if (card->remove) 1592 if (card->remove)
1378 card->remove(pdev); 1593 card->remove(pdev);
1379 }
1380 1594
1595 kfree(card->rtd);
1596 snd_card_free(card->snd_card);
1597 }
1381 snd_soc_unregister_card(card); 1598 snd_soc_unregister_card(card);
1382
1383 return 0; 1599 return 0;
1384} 1600}
1385 1601
1386static int soc_poweroff(struct device *dev) 1602static int soc_poweroff(struct device *dev)
1387{ 1603{
1388 struct platform_device *pdev = to_platform_device(dev); 1604 struct platform_device *pdev = to_platform_device(dev);
1389 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1605 struct snd_soc_card *card = platform_get_drvdata(pdev);
1390 struct snd_soc_card *card = socdev->card; 1606 int i;
1391 1607
1392 if (!card->instantiated) 1608 if (!card->instantiated)
1393 return 0; 1609 return 0;
1394 1610
1395 /* Flush out pmdown_time work - we actually do want to run it 1611 /* Flush out pmdown_time work - we actually do want to run it
1396 * now, we're shutting down so no imminent restart. */ 1612 * now, we're shutting down so no imminent restart. */
1397 run_delayed_work(&card->delayed_work); 1613 for (i = 0; i < card->num_rtd; i++) {
1614 struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
1615 run_delayed_work(&rtd->delayed_work);
1616 }
1398 1617
1399 snd_soc_dapm_shutdown(socdev); 1618 snd_soc_dapm_shutdown(card);
1400 1619
1401 return 0; 1620 return 0;
1402} 1621}
@@ -1419,53 +1638,42 @@ static struct platform_driver soc_driver = {
1419}; 1638};
1420 1639
1421/* create a new pcm */ 1640/* create a new pcm */
1422static int soc_new_pcm(struct snd_soc_device *socdev, 1641static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
1423 struct snd_soc_dai_link *dai_link, int num) 1642{
1424{ 1643 struct snd_soc_codec *codec = rtd->codec;
1425 struct snd_soc_card *card = socdev->card; 1644 struct snd_soc_platform *platform = rtd->platform;
1426 struct snd_soc_codec *codec = card->codec; 1645 struct snd_soc_dai *codec_dai = rtd->codec_dai;
1427 struct snd_soc_platform *platform = card->platform; 1646 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
1428 struct snd_soc_dai *codec_dai = dai_link->codec_dai;
1429 struct snd_soc_dai *cpu_dai = dai_link->cpu_dai;
1430 struct snd_soc_pcm_runtime *rtd;
1431 struct snd_pcm *pcm; 1647 struct snd_pcm *pcm;
1432 char new_name[64]; 1648 char new_name[64];
1433 int ret = 0, playback = 0, capture = 0; 1649 int ret = 0, playback = 0, capture = 0;
1434 1650
1435 rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
1436 if (rtd == NULL)
1437 return -ENOMEM;
1438
1439 rtd->dai = dai_link;
1440 rtd->socdev = socdev;
1441 codec_dai->codec = card->codec;
1442
1443 /* check client and interface hw capabilities */ 1651 /* check client and interface hw capabilities */
1444 snprintf(new_name, sizeof(new_name), "%s %s-%d", 1652 snprintf(new_name, sizeof(new_name), "%s %s-%d",
1445 dai_link->stream_name, codec_dai->name, num); 1653 rtd->dai_link->stream_name, codec_dai->name, num);
1446 1654
1447 if (codec_dai->playback.channels_min) 1655 if (codec_dai->driver->playback.channels_min)
1448 playback = 1; 1656 playback = 1;
1449 if (codec_dai->capture.channels_min) 1657 if (codec_dai->driver->capture.channels_min)
1450 capture = 1; 1658 capture = 1;
1451 1659
1452 ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback, 1660 dev_dbg(rtd->card->dev, "registered pcm #%d %s\n",num,new_name);
1453 capture, &pcm); 1661 ret = snd_pcm_new(rtd->card->snd_card, new_name,
1662 num, playback, capture, &pcm);
1454 if (ret < 0) { 1663 if (ret < 0) {
1455 printk(KERN_ERR "asoc: can't create pcm for codec %s\n", 1664 printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name);
1456 codec->name);
1457 kfree(rtd);
1458 return ret; 1665 return ret;
1459 } 1666 }
1460 1667
1461 dai_link->pcm = pcm; 1668 rtd->pcm = pcm;
1462 pcm->private_data = rtd; 1669 pcm->private_data = rtd;
1463 soc_pcm_ops.mmap = platform->pcm_ops->mmap; 1670 soc_pcm_ops.mmap = platform->driver->ops->mmap;
1464 soc_pcm_ops.ioctl = platform->pcm_ops->ioctl; 1671 soc_pcm_ops.pointer = platform->driver->ops->pointer;
1465 soc_pcm_ops.copy = platform->pcm_ops->copy; 1672 soc_pcm_ops.ioctl = platform->driver->ops->ioctl;
1466 soc_pcm_ops.silence = platform->pcm_ops->silence; 1673 soc_pcm_ops.copy = platform->driver->ops->copy;
1467 soc_pcm_ops.ack = platform->pcm_ops->ack; 1674 soc_pcm_ops.silence = platform->driver->ops->silence;
1468 soc_pcm_ops.page = platform->pcm_ops->page; 1675 soc_pcm_ops.ack = platform->driver->ops->ack;
1676 soc_pcm_ops.page = platform->driver->ops->page;
1469 1677
1470 if (playback) 1678 if (playback)
1471 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops); 1679 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
@@ -1473,14 +1681,13 @@ static int soc_new_pcm(struct snd_soc_device *socdev,
1473 if (capture) 1681 if (capture)
1474 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops); 1682 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
1475 1683
1476 ret = platform->pcm_new(codec->card, codec_dai, pcm); 1684 ret = platform->driver->pcm_new(rtd->card->snd_card, codec_dai, pcm);
1477 if (ret < 0) { 1685 if (ret < 0) {
1478 printk(KERN_ERR "asoc: platform pcm constructor failed\n"); 1686 printk(KERN_ERR "asoc: platform pcm constructor failed\n");
1479 kfree(rtd);
1480 return ret; 1687 return ret;
1481 } 1688 }
1482 1689
1483 pcm->private_free = platform->pcm_free; 1690 pcm->private_free = platform->driver->pcm_free;
1484 printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name, 1691 printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
1485 cpu_dai->name); 1692 cpu_dai->name);
1486 return ret; 1693 return ret;
@@ -1496,8 +1703,8 @@ static int soc_new_pcm(struct snd_soc_device *socdev,
1496 */ 1703 */
1497int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, int reg) 1704int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, int reg)
1498{ 1705{
1499 if (codec->volatile_register) 1706 if (codec->driver->volatile_register)
1500 return codec->volatile_register(reg); 1707 return codec->driver->volatile_register(reg);
1501 else 1708 else
1502 return 0; 1709 return 0;
1503} 1710}
@@ -1532,7 +1739,6 @@ int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
1532 1739
1533 codec->ac97->bus->ops = ops; 1740 codec->ac97->bus->ops = ops;
1534 codec->ac97->num = num; 1741 codec->ac97->num = num;
1535 codec->dev = &codec->ac97->dev;
1536 mutex_unlock(&codec->mutex); 1742 mutex_unlock(&codec->mutex);
1537 return 0; 1743 return 0;
1538} 1744}
@@ -1547,6 +1753,9 @@ EXPORT_SYMBOL_GPL(snd_soc_new_ac97_codec);
1547void snd_soc_free_ac97_codec(struct snd_soc_codec *codec) 1753void snd_soc_free_ac97_codec(struct snd_soc_codec *codec)
1548{ 1754{
1549 mutex_lock(&codec->mutex); 1755 mutex_lock(&codec->mutex);
1756#ifdef CONFIG_SND_SOC_AC97_BUS
1757 soc_unregister_ac97_dai_link(codec);
1758#endif
1550 kfree(codec->ac97->bus); 1759 kfree(codec->ac97->bus);
1551 kfree(codec->ac97); 1760 kfree(codec->ac97);
1552 codec->ac97 = NULL; 1761 codec->ac97 = NULL;
@@ -1633,95 +1842,6 @@ int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
1633EXPORT_SYMBOL_GPL(snd_soc_test_bits); 1842EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1634 1843
1635/** 1844/**
1636 * snd_soc_new_pcms - create new sound card and pcms
1637 * @socdev: the SoC audio device
1638 * @idx: ALSA card index
1639 * @xid: card identification
1640 *
1641 * Create a new sound card based upon the codec and interface pcms.
1642 *
1643 * Returns 0 for success, else error.
1644 */
1645int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
1646{
1647 struct snd_soc_card *card = socdev->card;
1648 struct snd_soc_codec *codec = card->codec;
1649 int ret, i;
1650
1651 mutex_lock(&codec->mutex);
1652
1653 /* register a sound card */
1654 ret = snd_card_create(idx, xid, codec->owner, 0, &codec->card);
1655 if (ret < 0) {
1656 printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
1657 codec->name);
1658 mutex_unlock(&codec->mutex);
1659 return ret;
1660 }
1661
1662 codec->socdev = socdev;
1663 codec->card->dev = socdev->dev;
1664 codec->card->private_data = codec;
1665 strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
1666
1667 /* create the pcms */
1668 for (i = 0; i < card->num_links; i++) {
1669 ret = soc_new_pcm(socdev, &card->dai_link[i], i);
1670 if (ret < 0) {
1671 printk(KERN_ERR "asoc: can't create pcm %s\n",
1672 card->dai_link[i].stream_name);
1673 mutex_unlock(&codec->mutex);
1674 return ret;
1675 }
1676 /* Check for codec->ac97 to handle the ac97.c fun */
1677 if (card->dai_link[i].codec_dai->ac97_control && codec->ac97) {
1678 snd_ac97_dev_add_pdata(codec->ac97,
1679 card->dai_link[i].cpu_dai->ac97_pdata);
1680 }
1681 }
1682
1683 mutex_unlock(&codec->mutex);
1684 return ret;
1685}
1686EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1687
1688/**
1689 * snd_soc_free_pcms - free sound card and pcms
1690 * @socdev: the SoC audio device
1691 *
1692 * Frees sound card and pcms associated with the socdev.
1693 * Also unregister the codec if it is an AC97 device.
1694 */
1695void snd_soc_free_pcms(struct snd_soc_device *socdev)
1696{
1697 struct snd_soc_codec *codec = socdev->card->codec;
1698#ifdef CONFIG_SND_SOC_AC97_BUS
1699 struct snd_soc_dai *codec_dai;
1700 int i;
1701#endif
1702
1703 mutex_lock(&codec->mutex);
1704 soc_cleanup_codec_debugfs(codec);
1705#ifdef CONFIG_SND_SOC_AC97_BUS
1706 for (i = 0; i < codec->num_dai; i++) {
1707 codec_dai = &codec->dai[i];
1708 if (codec_dai->ac97_control && codec->ac97 &&
1709 strcmp(codec->name, "AC97") != 0) {
1710 soc_ac97_dev_unregister(codec);
1711 goto free_card;
1712 }
1713 }
1714free_card:
1715#endif
1716
1717 if (codec->card)
1718 snd_card_free(codec->card);
1719 device_remove_file(socdev->dev, &dev_attr_codec_reg);
1720 mutex_unlock(&codec->mutex);
1721}
1722EXPORT_SYMBOL_GPL(snd_soc_free_pcms);
1723
1724/**
1725 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters 1845 * snd_soc_set_runtime_hwparams - set the runtime hardware parameters
1726 * @substream: the pcm substream 1846 * @substream: the pcm substream
1727 * @hw: the hardware parameters 1847 * @hw: the hardware parameters
@@ -1782,7 +1902,7 @@ EXPORT_SYMBOL_GPL(snd_soc_cnew);
1782int snd_soc_add_controls(struct snd_soc_codec *codec, 1902int snd_soc_add_controls(struct snd_soc_codec *codec,
1783 const struct snd_kcontrol_new *controls, int num_controls) 1903 const struct snd_kcontrol_new *controls, int num_controls)
1784{ 1904{
1785 struct snd_card *card = codec->card; 1905 struct snd_card *card = codec->card->snd_card;
1786 int err, i; 1906 int err, i;
1787 1907
1788 for (i = 0; i < num_controls; i++) { 1908 for (i = 0; i < num_controls; i++) {
@@ -2337,7 +2457,7 @@ EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2337int snd_soc_limit_volume(struct snd_soc_codec *codec, 2457int snd_soc_limit_volume(struct snd_soc_codec *codec,
2338 const char *name, int max) 2458 const char *name, int max)
2339{ 2459{
2340 struct snd_card *card = codec->card; 2460 struct snd_card *card = codec->card->snd_card;
2341 struct snd_kcontrol *kctl; 2461 struct snd_kcontrol *kctl;
2342 struct soc_mixer_control *mc; 2462 struct soc_mixer_control *mc;
2343 int found = 0; 2463 int found = 0;
@@ -2469,8 +2589,8 @@ EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r_sx);
2469int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, 2589int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2470 unsigned int freq, int dir) 2590 unsigned int freq, int dir)
2471{ 2591{
2472 if (dai->ops && dai->ops->set_sysclk) 2592 if (dai->driver && dai->driver->ops->set_sysclk)
2473 return dai->ops->set_sysclk(dai, clk_id, freq, dir); 2593 return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
2474 else 2594 else
2475 return -EINVAL; 2595 return -EINVAL;
2476} 2596}
@@ -2489,8 +2609,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2489int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, 2609int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2490 int div_id, int div) 2610 int div_id, int div)
2491{ 2611{
2492 if (dai->ops && dai->ops->set_clkdiv) 2612 if (dai->driver && dai->driver->ops->set_clkdiv)
2493 return dai->ops->set_clkdiv(dai, div_id, div); 2613 return dai->driver->ops->set_clkdiv(dai, div_id, div);
2494 else 2614 else
2495 return -EINVAL; 2615 return -EINVAL;
2496} 2616}
@@ -2509,8 +2629,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2509int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source, 2629int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
2510 unsigned int freq_in, unsigned int freq_out) 2630 unsigned int freq_in, unsigned int freq_out)
2511{ 2631{
2512 if (dai->ops && dai->ops->set_pll) 2632 if (dai->driver && dai->driver->ops->set_pll)
2513 return dai->ops->set_pll(dai, pll_id, source, 2633 return dai->driver->ops->set_pll(dai, pll_id, source,
2514 freq_in, freq_out); 2634 freq_in, freq_out);
2515 else 2635 else
2516 return -EINVAL; 2636 return -EINVAL;
@@ -2526,8 +2646,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2526 */ 2646 */
2527int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 2647int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2528{ 2648{
2529 if (dai->ops && dai->ops->set_fmt) 2649 if (dai->driver && dai->driver->ops->set_fmt)
2530 return dai->ops->set_fmt(dai, fmt); 2650 return dai->driver->ops->set_fmt(dai, fmt);
2531 else 2651 else
2532 return -EINVAL; 2652 return -EINVAL;
2533} 2653}
@@ -2547,8 +2667,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2547int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, 2667int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2548 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) 2668 unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
2549{ 2669{
2550 if (dai->ops && dai->ops->set_tdm_slot) 2670 if (dai->driver && dai->driver->ops->set_tdm_slot)
2551 return dai->ops->set_tdm_slot(dai, tx_mask, rx_mask, 2671 return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
2552 slots, slot_width); 2672 slots, slot_width);
2553 else 2673 else
2554 return -EINVAL; 2674 return -EINVAL;
@@ -2571,8 +2691,8 @@ int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
2571 unsigned int tx_num, unsigned int *tx_slot, 2691 unsigned int tx_num, unsigned int *tx_slot,
2572 unsigned int rx_num, unsigned int *rx_slot) 2692 unsigned int rx_num, unsigned int *rx_slot)
2573{ 2693{
2574 if (dai->ops && dai->ops->set_channel_map) 2694 if (dai->driver && dai->driver->ops->set_channel_map)
2575 return dai->ops->set_channel_map(dai, tx_num, tx_slot, 2695 return dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
2576 rx_num, rx_slot); 2696 rx_num, rx_slot);
2577 else 2697 else
2578 return -EINVAL; 2698 return -EINVAL;
@@ -2588,8 +2708,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
2588 */ 2708 */
2589int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) 2709int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2590{ 2710{
2591 if (dai->ops && dai->ops->set_tristate) 2711 if (dai->driver && dai->driver->ops->set_tristate)
2592 return dai->ops->set_tristate(dai, tristate); 2712 return dai->driver->ops->set_tristate(dai, tristate);
2593 else 2713 else
2594 return -EINVAL; 2714 return -EINVAL;
2595} 2715}
@@ -2604,8 +2724,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2604 */ 2724 */
2605int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) 2725int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
2606{ 2726{
2607 if (dai->ops && dai->ops->digital_mute) 2727 if (dai->driver && dai->driver->ops->digital_mute)
2608 return dai->ops->digital_mute(dai, mute); 2728 return dai->driver->ops->digital_mute(dai, mute);
2609 else 2729 else
2610 return -EINVAL; 2730 return -EINVAL;
2611} 2731}
@@ -2622,11 +2742,22 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
2622 */ 2742 */
2623static int snd_soc_register_card(struct snd_soc_card *card) 2743static int snd_soc_register_card(struct snd_soc_card *card)
2624{ 2744{
2745 int i;
2746
2625 if (!card->name || !card->dev) 2747 if (!card->name || !card->dev)
2626 return -EINVAL; 2748 return -EINVAL;
2627 2749
2750 card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) * card->num_links,
2751 GFP_KERNEL);
2752 if (card->rtd == NULL)
2753 return -ENOMEM;
2754
2755 for (i = 0; i < card->num_links; i++)
2756 card->rtd[i].dai_link = &card->dai_link[i];
2757
2628 INIT_LIST_HEAD(&card->list); 2758 INIT_LIST_HEAD(&card->list);
2629 card->instantiated = 0; 2759 card->instantiated = 0;
2760 mutex_init(&card->mutex);
2630 2761
2631 mutex_lock(&client_mutex); 2762 mutex_lock(&client_mutex);
2632 list_add(&card->list, &card_list); 2763 list_add(&card->list, &card_list);
@@ -2652,30 +2783,97 @@ static int snd_soc_unregister_card(struct snd_soc_card *card)
2652 mutex_lock(&client_mutex); 2783 mutex_lock(&client_mutex);
2653 list_del(&card->list); 2784 list_del(&card->list);
2654 mutex_unlock(&client_mutex); 2785 mutex_unlock(&client_mutex);
2655
2656 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name); 2786 dev_dbg(card->dev, "Unregistered card '%s'\n", card->name);
2657 2787
2658 return 0; 2788 return 0;
2659} 2789}
2660 2790
2791/*
2792 * Simplify DAI link configuration by removing ".-1" from device names
2793 * and sanitizing names.
2794 */
2795static inline char *fmt_single_name(struct device *dev, int *id)
2796{
2797 char *found, name[NAME_SIZE];
2798 int id1, id2;
2799
2800 if (dev_name(dev) == NULL)
2801 return NULL;
2802
2803 strncpy(name, dev_name(dev), NAME_SIZE);
2804
2805 /* are we a "%s.%d" name (platform and SPI components) */
2806 found = strstr(name, dev->driver->name);
2807 if (found) {
2808 /* get ID */
2809 if (sscanf(&found[strlen(dev->driver->name)], ".%d", id) == 1) {
2810
2811 /* discard ID from name if ID == -1 */
2812 if (*id == -1)
2813 found[strlen(dev->driver->name)] = '\0';
2814 }
2815
2816 } else {
2817 /* I2C component devices are named "bus-addr" */
2818 if (sscanf(name, "%x-%x", &id1, &id2) == 2) {
2819 char tmp[NAME_SIZE];
2820
2821 /* create unique ID number from I2C addr and bus */
2822 *id = ((id1 && 0xffff) << 16) + id2;
2823
2824 /* sanitize component name for DAI link creation */
2825 snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
2826 strncpy(name, tmp, NAME_SIZE);
2827 } else
2828 *id = 0;
2829 }
2830
2831 return kstrdup(name, GFP_KERNEL);
2832}
2833
2834/*
2835 * Simplify DAI link naming for single devices with multiple DAIs by removing
2836 * any ".-1" and using the DAI name (instead of device name).
2837 */
2838static inline char *fmt_multiple_name(struct device *dev,
2839 struct snd_soc_dai_driver *dai_drv)
2840{
2841 if (dai_drv->name == NULL) {
2842 printk(KERN_ERR "asoc: error - multiple DAI %s registered with no name\n",
2843 dev_name(dev));
2844 return NULL;
2845 }
2846
2847 return kstrdup(dai_drv->name, GFP_KERNEL);
2848}
2849
2661/** 2850/**
2662 * snd_soc_register_dai - Register a DAI with the ASoC core 2851 * snd_soc_register_dai - Register a DAI with the ASoC core
2663 * 2852 *
2664 * @dai: DAI to register 2853 * @dai: DAI to register
2665 */ 2854 */
2666int snd_soc_register_dai(struct snd_soc_dai *dai) 2855int snd_soc_register_dai(struct device *dev,
2856 struct snd_soc_dai_driver *dai_drv)
2667{ 2857{
2668 if (!dai->name) 2858 struct snd_soc_dai *dai;
2669 return -EINVAL; 2859
2860 dev_dbg(dev, "dai register %s\n", dev_name(dev));
2670 2861
2671 /* The device should become mandatory over time */ 2862 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
2672 if (!dai->dev) 2863 if (dai == NULL)
2673 printk(KERN_WARNING "No device for DAI %s\n", dai->name); 2864 return -ENOMEM;
2674 2865
2675 if (!dai->ops) 2866 /* create DAI component name */
2676 dai->ops = &null_dai_ops; 2867 dai->name = fmt_single_name(dev, &dai->id);
2868 if (dai->name == NULL) {
2869 kfree(dai);
2870 return -ENOMEM;
2871 }
2677 2872
2678 INIT_LIST_HEAD(&dai->list); 2873 dai->dev = dev;
2874 dai->driver = dai_drv;
2875 if (!dai->driver->ops)
2876 dai->driver->ops = &null_dai_ops;
2679 2877
2680 mutex_lock(&client_mutex); 2878 mutex_lock(&client_mutex);
2681 list_add(&dai->list, &dai_list); 2879 list_add(&dai->list, &dai_list);
@@ -2693,13 +2891,24 @@ EXPORT_SYMBOL_GPL(snd_soc_register_dai);
2693 * 2891 *
2694 * @dai: DAI to unregister 2892 * @dai: DAI to unregister
2695 */ 2893 */
2696void snd_soc_unregister_dai(struct snd_soc_dai *dai) 2894void snd_soc_unregister_dai(struct device *dev)
2697{ 2895{
2896 struct snd_soc_dai *dai;
2897
2898 list_for_each_entry(dai, &dai_list, list) {
2899 if (dev == dai->dev)
2900 goto found;
2901 }
2902 return;
2903
2904found:
2698 mutex_lock(&client_mutex); 2905 mutex_lock(&client_mutex);
2699 list_del(&dai->list); 2906 list_del(&dai->list);
2700 mutex_unlock(&client_mutex); 2907 mutex_unlock(&client_mutex);
2701 2908
2702 pr_debug("Unregistered DAI '%s'\n", dai->name); 2909 pr_debug("Unregistered DAI '%s'\n", dai->name);
2910 kfree(dai->name);
2911 kfree(dai);
2703} 2912}
2704EXPORT_SYMBOL_GPL(snd_soc_unregister_dai); 2913EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
2705 2914
@@ -2709,21 +2918,47 @@ EXPORT_SYMBOL_GPL(snd_soc_unregister_dai);
2709 * @dai: Array of DAIs to register 2918 * @dai: Array of DAIs to register
2710 * @count: Number of DAIs 2919 * @count: Number of DAIs
2711 */ 2920 */
2712int snd_soc_register_dais(struct snd_soc_dai *dai, size_t count) 2921int snd_soc_register_dais(struct device *dev,
2922 struct snd_soc_dai_driver *dai_drv, size_t count)
2713{ 2923{
2714 int i, ret; 2924 struct snd_soc_dai *dai;
2925 int i, ret = 0;
2926
2927 dev_dbg(dev, "dai register %s #%d\n", dev_name(dev), count);
2715 2928
2716 for (i = 0; i < count; i++) { 2929 for (i = 0; i < count; i++) {
2717 ret = snd_soc_register_dai(&dai[i]); 2930
2718 if (ret != 0) 2931 dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
2932 if (dai == NULL)
2933 return -ENOMEM;
2934
2935 /* create DAI component name */
2936 dai->name = fmt_multiple_name(dev, &dai_drv[i]);
2937 if (dai->name == NULL) {
2938 kfree(dai);
2939 ret = -EINVAL;
2719 goto err; 2940 goto err;
2941 }
2942
2943 dai->dev = dev;
2944 dai->id = i;
2945 dai->driver = &dai_drv[i];
2946 if (!dai->driver->ops)
2947 dai->driver->ops = &null_dai_ops;
2948
2949 mutex_lock(&client_mutex);
2950 list_add(&dai->list, &dai_list);
2951 mutex_unlock(&client_mutex);
2952
2953 pr_debug("Registered DAI '%s'\n", dai->name);
2720 } 2954 }
2721 2955
2956 snd_soc_instantiate_cards();
2722 return 0; 2957 return 0;
2723 2958
2724err: 2959err:
2725 for (i--; i >= 0; i--) 2960 for (i--; i >= 0; i--)
2726 snd_soc_unregister_dai(&dai[i]); 2961 snd_soc_unregister_dai(dev);
2727 2962
2728 return ret; 2963 return ret;
2729} 2964}
@@ -2735,12 +2970,12 @@ EXPORT_SYMBOL_GPL(snd_soc_register_dais);
2735 * @dai: Array of DAIs to unregister 2970 * @dai: Array of DAIs to unregister
2736 * @count: Number of DAIs 2971 * @count: Number of DAIs
2737 */ 2972 */
2738void snd_soc_unregister_dais(struct snd_soc_dai *dai, size_t count) 2973void snd_soc_unregister_dais(struct device *dev, size_t count)
2739{ 2974{
2740 int i; 2975 int i;
2741 2976
2742 for (i = 0; i < count; i++) 2977 for (i = 0; i < count; i++)
2743 snd_soc_unregister_dai(&dai[i]); 2978 snd_soc_unregister_dai(dev);
2744} 2979}
2745EXPORT_SYMBOL_GPL(snd_soc_unregister_dais); 2980EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
2746 2981
@@ -2749,12 +2984,26 @@ EXPORT_SYMBOL_GPL(snd_soc_unregister_dais);
2749 * 2984 *
2750 * @platform: platform to register 2985 * @platform: platform to register
2751 */ 2986 */
2752int snd_soc_register_platform(struct snd_soc_platform *platform) 2987int snd_soc_register_platform(struct device *dev,
2988 struct snd_soc_platform_driver *platform_drv)
2753{ 2989{
2754 if (!platform->name) 2990 struct snd_soc_platform *platform;
2755 return -EINVAL; 2991
2992 dev_dbg(dev, "platform register %s\n", dev_name(dev));
2993
2994 platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
2995 if (platform == NULL)
2996 return -ENOMEM;
2997
2998 /* create platform component name */
2999 platform->name = fmt_single_name(dev, &platform->id);
3000 if (platform->name == NULL) {
3001 kfree(platform);
3002 return -ENOMEM;
3003 }
2756 3004
2757 INIT_LIST_HEAD(&platform->list); 3005 platform->dev = dev;
3006 platform->driver = platform_drv;
2758 3007
2759 mutex_lock(&client_mutex); 3008 mutex_lock(&client_mutex);
2760 list_add(&platform->list, &platform_list); 3009 list_add(&platform->list, &platform_list);
@@ -2772,13 +3021,24 @@ EXPORT_SYMBOL_GPL(snd_soc_register_platform);
2772 * 3021 *
2773 * @platform: platform to unregister 3022 * @platform: platform to unregister
2774 */ 3023 */
2775void snd_soc_unregister_platform(struct snd_soc_platform *platform) 3024void snd_soc_unregister_platform(struct device *dev)
2776{ 3025{
3026 struct snd_soc_platform *platform;
3027
3028 list_for_each_entry(platform, &platform_list, list) {
3029 if (dev == platform->dev)
3030 goto found;
3031 }
3032 return;
3033
3034found:
2777 mutex_lock(&client_mutex); 3035 mutex_lock(&client_mutex);
2778 list_del(&platform->list); 3036 list_del(&platform->list);
2779 mutex_unlock(&client_mutex); 3037 mutex_unlock(&client_mutex);
2780 3038
2781 pr_debug("Unregistered platform '%s'\n", platform->name); 3039 pr_debug("Unregistered platform '%s'\n", platform->name);
3040 kfree(platform->name);
3041 kfree(platform);
2782} 3042}
2783EXPORT_SYMBOL_GPL(snd_soc_unregister_platform); 3043EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
2784 3044
@@ -2820,32 +3080,78 @@ static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
2820 * 3080 *
2821 * @codec: codec to register 3081 * @codec: codec to register
2822 */ 3082 */
2823int snd_soc_register_codec(struct snd_soc_codec *codec) 3083int snd_soc_register_codec(struct device *dev,
3084 struct snd_soc_codec_driver *codec_drv,
3085 struct snd_soc_dai_driver *dai_drv, int num_dai)
2824{ 3086{
2825 int i; 3087 struct snd_soc_codec *codec;
3088 int ret, i;
2826 3089
2827 if (!codec->name) 3090 dev_dbg(dev, "codec register %s\n", dev_name(dev));
2828 return -EINVAL; 3091
3092 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
3093 if (codec == NULL)
3094 return -ENOMEM;
2829 3095
2830 /* The device should become mandatory over time */ 3096 /* create CODEC component name */
2831 if (!codec->dev) 3097 codec->name = fmt_single_name(dev, &codec->id);
2832 printk(KERN_WARNING "No device for codec %s\n", codec->name); 3098 if (codec->name == NULL) {
3099 kfree(codec);
3100 return -ENOMEM;
3101 }
3102
3103 /* allocate CODEC register cache */
3104 if (codec_drv->reg_cache_size && codec_drv->reg_word_size) {
2833 3105
2834 INIT_LIST_HEAD(&codec->list); 3106 if (codec_drv->reg_cache_default)
3107 codec->reg_cache = kmemdup(codec_drv->reg_cache_default,
3108 codec_drv->reg_cache_size * codec_drv->reg_word_size, GFP_KERNEL);
3109 else
3110 codec->reg_cache = kzalloc(codec_drv->reg_cache_size *
3111 codec_drv->reg_word_size, GFP_KERNEL);
2835 3112
2836 for (i = 0; i < codec->num_dai; i++) { 3113 if (codec->reg_cache == NULL) {
2837 fixup_codec_formats(&codec->dai[i].playback); 3114 kfree(codec->name);
2838 fixup_codec_formats(&codec->dai[i].capture); 3115 kfree(codec);
3116 return -ENOMEM;
3117 }
2839 } 3118 }
2840 3119
3120 codec->dev = dev;
3121 codec->driver = codec_drv;
3122 codec->bias_level = SND_SOC_BIAS_OFF;
3123 codec->num_dai = num_dai;
3124 mutex_init(&codec->mutex);
3125 INIT_LIST_HEAD(&codec->dapm_widgets);
3126 INIT_LIST_HEAD(&codec->dapm_paths);
3127
3128 for (i = 0; i < num_dai; i++) {
3129 fixup_codec_formats(&dai_drv[i].playback);
3130 fixup_codec_formats(&dai_drv[i].capture);
3131 }
3132
3133 /* register DAIs */
3134 ret = snd_soc_register_dais(dev, dai_drv, num_dai);
3135 if (ret < 0)
3136 goto error;
3137
2841 mutex_lock(&client_mutex); 3138 mutex_lock(&client_mutex);
2842 list_add(&codec->list, &codec_list); 3139 list_add(&codec->list, &codec_list);
2843 snd_soc_instantiate_cards(); 3140 snd_soc_instantiate_cards();
2844 mutex_unlock(&client_mutex); 3141 mutex_unlock(&client_mutex);
2845 3142
2846 pr_debug("Registered codec '%s'\n", codec->name); 3143 pr_debug("Registered codec '%s'\n", codec->name);
2847
2848 return 0; 3144 return 0;
3145
3146error:
3147 for (i--; i >= 0; i--)
3148 snd_soc_unregister_dai(dev);
3149
3150 if (codec->reg_cache)
3151 kfree(codec->reg_cache);
3152 kfree(codec->name);
3153 kfree(codec);
3154 return ret;
2849} 3155}
2850EXPORT_SYMBOL_GPL(snd_soc_register_codec); 3156EXPORT_SYMBOL_GPL(snd_soc_register_codec);
2851 3157
@@ -2854,13 +3160,30 @@ EXPORT_SYMBOL_GPL(snd_soc_register_codec);
2854 * 3160 *
2855 * @codec: codec to unregister 3161 * @codec: codec to unregister
2856 */ 3162 */
2857void snd_soc_unregister_codec(struct snd_soc_codec *codec) 3163void snd_soc_unregister_codec(struct device *dev)
2858{ 3164{
3165 struct snd_soc_codec *codec;
3166 int i;
3167
3168 list_for_each_entry(codec, &codec_list, list) {
3169 if (dev == codec->dev)
3170 goto found;
3171 }
3172 return;
3173
3174found:
3175 for (i = 0; i < codec->num_dai; i++)
3176 snd_soc_unregister_dai(dev);
3177
2859 mutex_lock(&client_mutex); 3178 mutex_lock(&client_mutex);
2860 list_del(&codec->list); 3179 list_del(&codec->list);
2861 mutex_unlock(&client_mutex); 3180 mutex_unlock(&client_mutex);
2862 3181
2863 pr_debug("Unregistered codec '%s'\n", codec->name); 3182 pr_debug("Unregistered codec '%s'\n", codec->name);
3183
3184 if (codec->reg_cache)
3185 kfree(codec->reg_cache);
3186 kfree(codec);
2864} 3187}
2865EXPORT_SYMBOL_GPL(snd_soc_unregister_codec); 3188EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
2866 3189