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