xref: /linux/sound/soc/codecs/spdif_receiver.c (revision 2f6e3ba0e0645011cbbd0289e9082d8007141498)
1cdf60525SVipin Kumar /*
2cdf60525SVipin Kumar  * ALSA SoC SPDIF DIR (Digital Interface Reciever) driver
3cdf60525SVipin Kumar  *
4cdf60525SVipin Kumar  * Based on ALSA SoC SPDIF DIT driver
5cdf60525SVipin Kumar  *
6cdf60525SVipin Kumar  *  This driver is used by controllers which can operate in DIR (SPDI/F) where
7cdf60525SVipin Kumar  *  no codec is needed.  This file provides stub codec that can be used
8cdf60525SVipin Kumar  *  in these configurations. SPEAr SPDIF IN Audio controller uses this driver.
9cdf60525SVipin Kumar  *
10cdf60525SVipin Kumar  * Author:      Vipin Kumar,  <vipin.kumar@st.com>
11cdf60525SVipin Kumar  * Copyright:   (C) 2012  ST Microelectronics
12cdf60525SVipin Kumar  *
13cdf60525SVipin Kumar  * This program is free software; you can redistribute it and/or modify
14cdf60525SVipin Kumar  * it under the terms of the GNU General Public License version 2 as
15cdf60525SVipin Kumar  * published by the Free Software Foundation.
16cdf60525SVipin Kumar  */
17cdf60525SVipin Kumar 
18cdf60525SVipin Kumar #include <linux/module.h>
19cdf60525SVipin Kumar #include <linux/moduleparam.h>
20cdf60525SVipin Kumar #include <linux/slab.h>
21cdf60525SVipin Kumar #include <sound/soc.h>
22cdf60525SVipin Kumar #include <sound/pcm.h>
23cdf60525SVipin Kumar #include <sound/initval.h>
24f9c8ba89SMarek Belisko #include <linux/of.h>
25cdf60525SVipin Kumar 
26*2f6e3ba0SMark Brown static const struct snd_soc_dapm_widget dir_widgets[] = {
27*2f6e3ba0SMark Brown 	SND_SOC_DAPM_INPUT("spdif-in"),
28*2f6e3ba0SMark Brown };
29*2f6e3ba0SMark Brown 
30*2f6e3ba0SMark Brown static const struct snd_soc_dapm_route dir_routes[] = {
31*2f6e3ba0SMark Brown 	{ "Capture", NULL, "spdif-in" },
32*2f6e3ba0SMark Brown };
33*2f6e3ba0SMark Brown 
34cdf60525SVipin Kumar #define STUB_RATES	SNDRV_PCM_RATE_8000_192000
35cdf60525SVipin Kumar #define STUB_FORMATS	(SNDRV_PCM_FMTBIT_S16_LE | \
36db5ff954SNicolin Chen 			SNDRV_PCM_FMTBIT_S20_3LE | \
37db5ff954SNicolin Chen 			SNDRV_PCM_FMTBIT_S24_LE | \
38cdf60525SVipin Kumar 			SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE)
39cdf60525SVipin Kumar 
40*2f6e3ba0SMark Brown static struct snd_soc_codec_driver soc_codec_spdif_dir = {
41*2f6e3ba0SMark Brown 	.dapm_widgets = dir_widgets,
42*2f6e3ba0SMark Brown 	.num_dapm_widgets = ARRAY_SIZE(dir_widgets),
43*2f6e3ba0SMark Brown 	.dapm_routes = dir_routes,
44*2f6e3ba0SMark Brown 	.num_dapm_routes = ARRAY_SIZE(dir_routes),
45*2f6e3ba0SMark Brown };
46cdf60525SVipin Kumar 
47cdf60525SVipin Kumar static struct snd_soc_dai_driver dir_stub_dai = {
48cdf60525SVipin Kumar 	.name		= "dir-hifi",
49cdf60525SVipin Kumar 	.capture	= {
50cdf60525SVipin Kumar 		.stream_name	= "Capture",
51cdf60525SVipin Kumar 		.channels_min	= 1,
52cdf60525SVipin Kumar 		.channels_max	= 384,
53cdf60525SVipin Kumar 		.rates		= STUB_RATES,
54cdf60525SVipin Kumar 		.formats	= STUB_FORMATS,
55cdf60525SVipin Kumar 	},
56cdf60525SVipin Kumar };
57cdf60525SVipin Kumar 
58cdf60525SVipin Kumar static int spdif_dir_probe(struct platform_device *pdev)
59cdf60525SVipin Kumar {
60cdf60525SVipin Kumar 	return snd_soc_register_codec(&pdev->dev, &soc_codec_spdif_dir,
61cdf60525SVipin Kumar 			&dir_stub_dai, 1);
62cdf60525SVipin Kumar }
63cdf60525SVipin Kumar 
64cdf60525SVipin Kumar static int spdif_dir_remove(struct platform_device *pdev)
65cdf60525SVipin Kumar {
66cdf60525SVipin Kumar 	snd_soc_unregister_codec(&pdev->dev);
67cdf60525SVipin Kumar 	return 0;
68cdf60525SVipin Kumar }
69cdf60525SVipin Kumar 
70f9c8ba89SMarek Belisko #ifdef CONFIG_OF
71f9c8ba89SMarek Belisko static const struct of_device_id spdif_dir_dt_ids[] = {
72f9c8ba89SMarek Belisko 	{ .compatible = "linux,spdif-dir", },
73f9c8ba89SMarek Belisko 	{ }
74f9c8ba89SMarek Belisko };
75f9c8ba89SMarek Belisko MODULE_DEVICE_TABLE(of, spdif_dir_dt_ids);
76f9c8ba89SMarek Belisko #endif
77f9c8ba89SMarek Belisko 
78cdf60525SVipin Kumar static struct platform_driver spdif_dir_driver = {
79cdf60525SVipin Kumar 	.probe		= spdif_dir_probe,
80cdf60525SVipin Kumar 	.remove		= spdif_dir_remove,
81cdf60525SVipin Kumar 	.driver		= {
82cdf60525SVipin Kumar 		.name	= "spdif-dir",
83cdf60525SVipin Kumar 		.owner	= THIS_MODULE,
84f9c8ba89SMarek Belisko 		.of_match_table = of_match_ptr(spdif_dir_dt_ids),
85cdf60525SVipin Kumar 	},
86cdf60525SVipin Kumar };
87cdf60525SVipin Kumar 
88cdf60525SVipin Kumar module_platform_driver(spdif_dir_driver);
89cdf60525SVipin Kumar 
90cdf60525SVipin Kumar MODULE_DESCRIPTION("ASoC SPDIF DIR driver");
91cdf60525SVipin Kumar MODULE_AUTHOR("Vipin Kumar <vipin.kumar@st.com>");
92cdf60525SVipin Kumar MODULE_LICENSE("GPL");
93