2 * ALSA SoC SPDIF DIT driver
4 * This driver is used by controllers which can operate in DIT (SPDI/F) where
5 * no codec is needed. This file provides stub codec that can be used
6 * in these configurations. TI DaVinci Audio controller uses this driver.
8 * Author: Steve Chen, <schen@mvista.com>
9 * Copyright: (C) 2009 MontaVista Software, Inc., <source@mvista.com>
10 * Copyright: (C) 2009 Texas Instruments, India
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
17 #include <linux/module.h>
18 #include <linux/moduleparam.h>
19 #include <sound/soc.h>
20 #include <sound/pcm.h>
21 #include <sound/initval.h>
23 #include "spdif_transciever.h"
25 MODULE_LICENSE("GPL");
27 #define STUB_RATES SNDRV_PCM_RATE_8000_96000
28 #define STUB_FORMATS SNDRV_PCM_FMTBIT_S16_LE
30 static struct snd_soc_codec *spdif_dit_codec;
32 static int spdif_dit_codec_probe(struct platform_device *pdev)
34 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
35 struct snd_soc_codec *codec;
38 if (spdif_dit_codec == NULL) {
39 dev_err(&pdev->dev, "Codec device not registered\n");
43 socdev->card->codec = spdif_dit_codec;
44 codec = spdif_dit_codec;
46 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
48 dev_err(codec->dev, "failed to create pcms: %d\n", ret);
58 static int spdif_dit_codec_remove(struct platform_device *pdev)
60 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
62 snd_soc_free_pcms(socdev);
67 struct snd_soc_codec_device soc_codec_dev_spdif_dit = {
68 .probe = spdif_dit_codec_probe,
69 .remove = spdif_dit_codec_remove,
70 }; EXPORT_SYMBOL_GPL(soc_codec_dev_spdif_dit);
72 struct snd_soc_dai dit_stub_dai = {
75 .stream_name = "Playback",
79 .formats = STUB_FORMATS,
82 EXPORT_SYMBOL_GPL(dit_stub_dai);
84 static int spdif_dit_probe(struct platform_device *pdev)
86 struct snd_soc_codec *codec;
89 if (spdif_dit_codec) {
90 dev_err(&pdev->dev, "Another Codec is registered\n");
95 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
99 codec->dev = &pdev->dev;
101 mutex_init(&codec->mutex);
103 INIT_LIST_HEAD(&codec->dapm_widgets);
104 INIT_LIST_HEAD(&codec->dapm_paths);
106 codec->name = "spdif-dit";
107 codec->owner = THIS_MODULE;
108 codec->dai = &dit_stub_dai;
111 spdif_dit_codec = codec;
113 ret = snd_soc_register_codec(codec);
115 dev_err(codec->dev, "Failed to register codec: %d\n", ret);
119 dit_stub_dai.dev = &pdev->dev;
120 ret = snd_soc_register_dai(&dit_stub_dai);
122 dev_err(codec->dev, "Failed to register dai: %d\n", ret);
129 snd_soc_unregister_codec(codec);
131 kfree(spdif_dit_codec);
135 static int spdif_dit_remove(struct platform_device *pdev)
137 snd_soc_unregister_dai(&dit_stub_dai);
138 snd_soc_unregister_codec(spdif_dit_codec);
139 kfree(spdif_dit_codec);
140 spdif_dit_codec = NULL;
144 static struct platform_driver spdif_dit_driver = {
145 .probe = spdif_dit_probe,
146 .remove = spdif_dit_remove,
149 .owner = THIS_MODULE,
153 static int __init dit_modinit(void)
155 return platform_driver_register(&spdif_dit_driver);
158 static void __exit dit_exit(void)
160 platform_driver_unregister(&spdif_dit_driver);
163 module_init(dit_modinit);
164 module_exit(dit_exit);