tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / sound / soc / sprd / dai / vaudio / vaudio.c
1 /*
2  * sound/soc/sprd/dai/vaudio/vaudio.c
3  *
4  * SpreadTrum Vaudio for the dsp stream.
5  *
6  * Copyright (C) 2012 SpreadTrum Ltd.
7  *
8  * This software is licensed under the terms of the GNU General Public
9  * License version 2, as published by the Free Software Foundation, and
10  * may be copied, distributed, and modified under those terms.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  */
17 #include "sprd-asoc-debug.h"
18 #define pr_fmt(fmt) pr_sprd_fmt(" DSP ") fmt
19
20 #include <linux/module.h>
21 #include <linux/moduleparam.h>
22 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/string.h>
25 #include <linux/sysfs.h>
26 #include <linux/stat.h>
27 #include <linux/device.h>
28 #include <linux/platform_device.h>
29 #include <linux/slab.h>
30 #include <linux/of.h>
31
32 #include <sound/core.h>
33 #include <sound/soc.h>
34 #include <sound/soc-dapm.h>
35 #include <sound/pcm_params.h>
36 #include <sound/tlv.h>
37
38 #include "sprd-asoc-common.h"
39 #include "vaudio.h"
40
41 static int sprd_vaudio_startup(struct snd_pcm_substream *substream,
42                                struct snd_soc_dai *dai)
43 {
44         struct snd_soc_card *card = dai->card;
45         int i;
46
47         sp_asoc_pr_dbg("%s\n", __func__);
48
49         kfree(snd_soc_dai_get_dma_data(dai, substream));
50         snd_soc_dai_set_dma_data(dai, substream, NULL);
51
52         for (i = 0; i < card->num_rtd; i++) {
53                 card->rtd[i].dai_link->ignore_suspend = 1;
54         }
55
56         return 0;
57 }
58
59 static void sprd_vaudio_shutdown(struct snd_pcm_substream *substream,
60                                  struct snd_soc_dai *dai)
61 {
62         struct snd_soc_card *card = dai->card;
63         int i;
64
65         sp_asoc_pr_dbg("%s\n", __func__);
66
67         for (i = 0; i < card->num_rtd; i++) {
68                 card->rtd[i].dai_link->ignore_suspend = 0;
69         }
70 }
71
72 static struct snd_soc_dai_ops sprd_vaudio_dai_ops = {
73         .startup = sprd_vaudio_startup,
74         .shutdown = sprd_vaudio_shutdown,
75 };
76
77 struct snd_soc_dai_driver sprd_vaudio_dai[] = {
78         {
79          .id = VAUDIO_MAGIC_ID,
80          .name = "vaudio",
81          .playback = {
82                       .channels_min = 1,
83                       .channels_max = 2,
84                       .rates = SNDRV_PCM_RATE_CONTINUOUS,
85                       .formats = SNDRV_PCM_FMTBIT_S16_LE,},
86          .capture = {
87                      .channels_min = 1,
88                      .channels_max = 2,
89                      .rates = SNDRV_PCM_RATE_CONTINUOUS,
90                      .formats = SNDRV_PCM_FMTBIT_S16_LE,},
91          .ops = &sprd_vaudio_dai_ops,
92          },
93         {
94          .id = VAUDIO_MAGIC_ID + 1,
95          .name = "vaudio-ad23",
96          .capture = {
97                      .channels_min = 1,
98                      .channels_max = 2, /*ad23 */
99                      .rates = SNDRV_PCM_RATE_CONTINUOUS,
100                      .formats = SNDRV_PCM_FMTBIT_S16_LE,
101                      },
102          .ops = &sprd_vaudio_dai_ops,
103          },
104 };
105
106 static const struct snd_soc_component_driver sprd_vaudio_component = {
107         .name = "vaudio",
108 };
109
110 static int sprd_vaudio_drv_probe(struct platform_device *pdev)
111 {
112         int ret;
113
114         sp_asoc_pr_dbg("%s\n", __func__);
115
116         ret =
117             snd_soc_register_component(&pdev->dev, &sprd_vaudio_component,
118                                        sprd_vaudio_dai,
119                                        ARRAY_SIZE(sprd_vaudio_dai));
120
121         sp_asoc_pr_dbg("return %i\n", ret);
122
123         return ret;
124 }
125
126 static int sprd_vaudio_drv_remove(struct platform_device *pdev)
127 {
128         snd_soc_unregister_component(&pdev->dev);
129         return 0;
130 }
131
132 #ifdef CONFIG_OF
133 static const struct of_device_id vaudio_of_match[] = {
134         {.compatible = "sprd,vaudio",},
135         {},
136 };
137
138 MODULE_DEVICE_TABLE(of, vaudio_of_match);
139 #endif
140
141 static struct platform_driver sprd_vaudio_driver = {
142         .driver = {
143                    .name = "vaudio",
144                    .owner = THIS_MODULE,
145                    .of_match_table = of_match_ptr(vaudio_of_match),
146                    },
147
148         .probe = sprd_vaudio_drv_probe,
149         .remove = sprd_vaudio_drv_remove,
150 };
151
152 module_platform_driver(sprd_vaudio_driver);
153
154 MODULE_DESCRIPTION("SPRD ASoC Vaudio CUP-DAI driver for the DSP");
155 MODULE_AUTHOR("Ken Kuang <ken.kuang@spreadtrum.com>");
156 MODULE_LICENSE("GPL");
157 MODULE_ALIAS("cpu-dai:sprd-vaudio");