aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-core.c
diff options
context:
space:
mode:
authorEric Miao <eric.y.miao@gmail.com>2009-03-02 20:41:00 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2009-03-04 17:29:47 -0500
commit6335d05548eece40092000aa91b64a50310d69d5 (patch)
treeac72c74562f349879a127b4067827476a7875c88 /sound/soc/soc-core.c
parentff09d49ad0176a5f52a398c137a7ff5f669d6be4 (diff)
ASoC: make ops a pointer in 'struct snd_soc_dai'
Considering the fact that most cpu_dai or codec_dai are using a same 'snd_soc_dai_ops' for several similar interfaces, 'ops' would be better made a pointer instead, to make sharing easier and code a bit cleaner. The patch below is rather preliminary since the asoc tree is being actively developed, and this touches almost every piece of code, (and possibly many others in development need to be changed as well). Building of all codecs are OK, yet to every SoC, I didn't test that. Signed-off-by: Eric Miao <eric.miao@marvell.com> Acked-by: Timur Tabi <timur@freescale.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r--sound/soc/soc-core.c102
1 files changed, 54 insertions, 48 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index d4b90d82a098..16518329f6b2 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -133,8 +133,8 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
133 mutex_lock(&pcm_mutex); 133 mutex_lock(&pcm_mutex);
134 134
135 /* startup the audio subsystem */ 135 /* startup the audio subsystem */
136 if (cpu_dai->ops.startup) { 136 if (cpu_dai->ops->startup) {
137 ret = cpu_dai->ops.startup(substream, cpu_dai); 137 ret = cpu_dai->ops->startup(substream, cpu_dai);
138 if (ret < 0) { 138 if (ret < 0) {
139 printk(KERN_ERR "asoc: can't open interface %s\n", 139 printk(KERN_ERR "asoc: can't open interface %s\n",
140 cpu_dai->name); 140 cpu_dai->name);
@@ -150,8 +150,8 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
150 } 150 }
151 } 151 }
152 152
153 if (codec_dai->ops.startup) { 153 if (codec_dai->ops->startup) {
154 ret = codec_dai->ops.startup(substream, codec_dai); 154 ret = codec_dai->ops->startup(substream, codec_dai);
155 if (ret < 0) { 155 if (ret < 0) {
156 printk(KERN_ERR "asoc: can't open codec %s\n", 156 printk(KERN_ERR "asoc: can't open codec %s\n",
157 codec_dai->name); 157 codec_dai->name);
@@ -247,8 +247,8 @@ codec_dai_err:
247 platform->pcm_ops->close(substream); 247 platform->pcm_ops->close(substream);
248 248
249platform_err: 249platform_err:
250 if (cpu_dai->ops.shutdown) 250 if (cpu_dai->ops->shutdown)
251 cpu_dai->ops.shutdown(substream, cpu_dai); 251 cpu_dai->ops->shutdown(substream, cpu_dai);
252out: 252out:
253 mutex_unlock(&pcm_mutex); 253 mutex_unlock(&pcm_mutex);
254 return ret; 254 return ret;
@@ -340,11 +340,11 @@ static int soc_codec_close(struct snd_pcm_substream *substream)
340 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 340 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
341 snd_soc_dai_digital_mute(codec_dai, 1); 341 snd_soc_dai_digital_mute(codec_dai, 1);
342 342
343 if (cpu_dai->ops.shutdown) 343 if (cpu_dai->ops->shutdown)
344 cpu_dai->ops.shutdown(substream, cpu_dai); 344 cpu_dai->ops->shutdown(substream, cpu_dai);
345 345
346 if (codec_dai->ops.shutdown) 346 if (codec_dai->ops->shutdown)
347 codec_dai->ops.shutdown(substream, codec_dai); 347 codec_dai->ops->shutdown(substream, codec_dai);
348 348
349 if (machine->ops && machine->ops->shutdown) 349 if (machine->ops && machine->ops->shutdown)
350 machine->ops->shutdown(substream); 350 machine->ops->shutdown(substream);
@@ -408,16 +408,16 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
408 } 408 }
409 } 409 }
410 410
411 if (codec_dai->ops.prepare) { 411 if (codec_dai->ops->prepare) {
412 ret = codec_dai->ops.prepare(substream, codec_dai); 412 ret = codec_dai->ops->prepare(substream, codec_dai);
413 if (ret < 0) { 413 if (ret < 0) {
414 printk(KERN_ERR "asoc: codec DAI prepare error\n"); 414 printk(KERN_ERR "asoc: codec DAI prepare error\n");
415 goto out; 415 goto out;
416 } 416 }
417 } 417 }
418 418
419 if (cpu_dai->ops.prepare) { 419 if (cpu_dai->ops->prepare) {
420 ret = cpu_dai->ops.prepare(substream, cpu_dai); 420 ret = cpu_dai->ops->prepare(substream, cpu_dai);
421 if (ret < 0) { 421 if (ret < 0) {
422 printk(KERN_ERR "asoc: cpu DAI prepare error\n"); 422 printk(KERN_ERR "asoc: cpu DAI prepare error\n");
423 goto out; 423 goto out;
@@ -494,8 +494,8 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
494 } 494 }
495 } 495 }
496 496
497 if (codec_dai->ops.hw_params) { 497 if (codec_dai->ops->hw_params) {
498 ret = codec_dai->ops.hw_params(substream, params, codec_dai); 498 ret = codec_dai->ops->hw_params(substream, params, codec_dai);
499 if (ret < 0) { 499 if (ret < 0) {
500 printk(KERN_ERR "asoc: can't set codec %s hw params\n", 500 printk(KERN_ERR "asoc: can't set codec %s hw params\n",
501 codec_dai->name); 501 codec_dai->name);
@@ -503,8 +503,8 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
503 } 503 }
504 } 504 }
505 505
506 if (cpu_dai->ops.hw_params) { 506 if (cpu_dai->ops->hw_params) {
507 ret = cpu_dai->ops.hw_params(substream, params, cpu_dai); 507 ret = cpu_dai->ops->hw_params(substream, params, cpu_dai);
508 if (ret < 0) { 508 if (ret < 0) {
509 printk(KERN_ERR "asoc: interface %s hw params failed\n", 509 printk(KERN_ERR "asoc: interface %s hw params failed\n",
510 cpu_dai->name); 510 cpu_dai->name);
@@ -526,12 +526,12 @@ out:
526 return ret; 526 return ret;
527 527
528platform_err: 528platform_err:
529 if (cpu_dai->ops.hw_free) 529 if (cpu_dai->ops->hw_free)
530 cpu_dai->ops.hw_free(substream, cpu_dai); 530 cpu_dai->ops->hw_free(substream, cpu_dai);
531 531
532interface_err: 532interface_err:
533 if (codec_dai->ops.hw_free) 533 if (codec_dai->ops->hw_free)
534 codec_dai->ops.hw_free(substream, codec_dai); 534 codec_dai->ops->hw_free(substream, codec_dai);
535 535
536codec_err: 536codec_err:
537 if (machine->ops && machine->ops->hw_free) 537 if (machine->ops && machine->ops->hw_free)
@@ -570,11 +570,11 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
570 platform->pcm_ops->hw_free(substream); 570 platform->pcm_ops->hw_free(substream);
571 571
572 /* now free hw params for the DAI's */ 572 /* now free hw params for the DAI's */
573 if (codec_dai->ops.hw_free) 573 if (codec_dai->ops->hw_free)
574 codec_dai->ops.hw_free(substream, codec_dai); 574 codec_dai->ops->hw_free(substream, codec_dai);
575 575
576 if (cpu_dai->ops.hw_free) 576 if (cpu_dai->ops->hw_free)
577 cpu_dai->ops.hw_free(substream, cpu_dai); 577 cpu_dai->ops->hw_free(substream, cpu_dai);
578 578
579 mutex_unlock(&pcm_mutex); 579 mutex_unlock(&pcm_mutex);
580 return 0; 580 return 0;
@@ -591,8 +591,8 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
591 struct snd_soc_dai *codec_dai = machine->codec_dai; 591 struct snd_soc_dai *codec_dai = machine->codec_dai;
592 int ret; 592 int ret;
593 593
594 if (codec_dai->ops.trigger) { 594 if (codec_dai->ops->trigger) {
595 ret = codec_dai->ops.trigger(substream, cmd, codec_dai); 595 ret = codec_dai->ops->trigger(substream, cmd, codec_dai);
596 if (ret < 0) 596 if (ret < 0)
597 return ret; 597 return ret;
598 } 598 }
@@ -603,8 +603,8 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
603 return ret; 603 return ret;
604 } 604 }
605 605
606 if (cpu_dai->ops.trigger) { 606 if (cpu_dai->ops->trigger) {
607 ret = cpu_dai->ops.trigger(substream, cmd, cpu_dai); 607 ret = cpu_dai->ops->trigger(substream, cmd, cpu_dai);
608 if (ret < 0) 608 if (ret < 0)
609 return ret; 609 return ret;
610 } 610 }
@@ -645,8 +645,8 @@ static int soc_suspend(struct platform_device *pdev, pm_message_t state)
645 /* mute any active DAC's */ 645 /* mute any active DAC's */
646 for (i = 0; i < card->num_links; i++) { 646 for (i = 0; i < card->num_links; i++) {
647 struct snd_soc_dai *dai = card->dai_link[i].codec_dai; 647 struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
648 if (dai->ops.digital_mute && dai->playback.active) 648 if (dai->ops->digital_mute && dai->playback.active)
649 dai->ops.digital_mute(dai, 1); 649 dai->ops->digital_mute(dai, 1);
650 } 650 }
651 651
652 /* suspend all pcms */ 652 /* suspend all pcms */
@@ -741,8 +741,8 @@ static void soc_resume_deferred(struct work_struct *work)
741 /* unmute any active DACs */ 741 /* unmute any active DACs */
742 for (i = 0; i < card->num_links; i++) { 742 for (i = 0; i < card->num_links; i++) {
743 struct snd_soc_dai *dai = card->dai_link[i].codec_dai; 743 struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
744 if (dai->ops.digital_mute && dai->playback.active) 744 if (dai->ops->digital_mute && dai->playback.active)
745 dai->ops.digital_mute(dai, 0); 745 dai->ops->digital_mute(dai, 0);
746 } 746 }
747 747
748 for (i = 0; i < card->num_links; i++) { 748 for (i = 0; i < card->num_links; i++) {
@@ -2051,8 +2051,8 @@ EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2051int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, 2051int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2052 unsigned int freq, int dir) 2052 unsigned int freq, int dir)
2053{ 2053{
2054 if (dai->ops.set_sysclk) 2054 if (dai->ops->set_sysclk)
2055 return dai->ops.set_sysclk(dai, clk_id, freq, dir); 2055 return dai->ops->set_sysclk(dai, clk_id, freq, dir);
2056 else 2056 else
2057 return -EINVAL; 2057 return -EINVAL;
2058} 2058}
@@ -2071,8 +2071,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2071int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, 2071int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2072 int div_id, int div) 2072 int div_id, int div)
2073{ 2073{
2074 if (dai->ops.set_clkdiv) 2074 if (dai->ops->set_clkdiv)
2075 return dai->ops.set_clkdiv(dai, div_id, div); 2075 return dai->ops->set_clkdiv(dai, div_id, div);
2076 else 2076 else
2077 return -EINVAL; 2077 return -EINVAL;
2078} 2078}
@@ -2090,8 +2090,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2090int snd_soc_dai_set_pll(struct snd_soc_dai *dai, 2090int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
2091 int pll_id, unsigned int freq_in, unsigned int freq_out) 2091 int pll_id, unsigned int freq_in, unsigned int freq_out)
2092{ 2092{
2093 if (dai->ops.set_pll) 2093 if (dai->ops->set_pll)
2094 return dai->ops.set_pll(dai, pll_id, freq_in, freq_out); 2094 return dai->ops->set_pll(dai, pll_id, freq_in, freq_out);
2095 else 2095 else
2096 return -EINVAL; 2096 return -EINVAL;
2097} 2097}
@@ -2106,8 +2106,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2106 */ 2106 */
2107int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 2107int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2108{ 2108{
2109 if (dai->ops.set_fmt) 2109 if (dai->ops->set_fmt)
2110 return dai->ops.set_fmt(dai, fmt); 2110 return dai->ops->set_fmt(dai, fmt);
2111 else 2111 else
2112 return -EINVAL; 2112 return -EINVAL;
2113} 2113}
@@ -2125,8 +2125,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2125int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, 2125int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2126 unsigned int mask, int slots) 2126 unsigned int mask, int slots)
2127{ 2127{
2128 if (dai->ops.set_sysclk) 2128 if (dai->ops->set_sysclk)
2129 return dai->ops.set_tdm_slot(dai, mask, slots); 2129 return dai->ops->set_tdm_slot(dai, mask, slots);
2130 else 2130 else
2131 return -EINVAL; 2131 return -EINVAL;
2132} 2132}
@@ -2141,8 +2141,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2141 */ 2141 */
2142int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) 2142int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2143{ 2143{
2144 if (dai->ops.set_sysclk) 2144 if (dai->ops->set_sysclk)
2145 return dai->ops.set_tristate(dai, tristate); 2145 return dai->ops->set_tristate(dai, tristate);
2146 else 2146 else
2147 return -EINVAL; 2147 return -EINVAL;
2148} 2148}
@@ -2157,8 +2157,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2157 */ 2157 */
2158int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) 2158int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
2159{ 2159{
2160 if (dai->ops.digital_mute) 2160 if (dai->ops->digital_mute)
2161 return dai->ops.digital_mute(dai, mute); 2161 return dai->ops->digital_mute(dai, mute);
2162 else 2162 else
2163 return -EINVAL; 2163 return -EINVAL;
2164} 2164}
@@ -2211,6 +2211,9 @@ static int snd_soc_unregister_card(struct snd_soc_card *card)
2211 return 0; 2211 return 0;
2212} 2212}
2213 2213
2214static struct snd_soc_dai_ops null_dai_ops = {
2215};
2216
2214/** 2217/**
2215 * snd_soc_register_dai - Register a DAI with the ASoC core 2218 * snd_soc_register_dai - Register a DAI with the ASoC core
2216 * 2219 *
@@ -2225,6 +2228,9 @@ int snd_soc_register_dai(struct snd_soc_dai *dai)
2225 if (!dai->dev) 2228 if (!dai->dev)
2226 printk(KERN_WARNING "No device for DAI %s\n", dai->name); 2229 printk(KERN_WARNING "No device for DAI %s\n", dai->name);
2227 2230
2231 if (!dai->ops)
2232 dai->ops = &null_dai_ops;
2233
2228 INIT_LIST_HEAD(&dai->list); 2234 INIT_LIST_HEAD(&dai->list);
2229 2235
2230 mutex_lock(&client_mutex); 2236 mutex_lock(&client_mutex);