aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r--sound/soc/codecs/Kconfig4
-rw-r--r--sound/soc/codecs/Makefile2
-rw-r--r--sound/soc/codecs/cq93vc.c298
-rw-r--r--sound/soc/codecs/cq93vc.h29
4 files changed, 333 insertions, 0 deletions
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 1743d565e996..16c47edb8266 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -21,6 +21,7 @@ config SND_SOC_ALL_CODECS
21 select SND_SOC_AK4535 if I2C 21 select SND_SOC_AK4535 if I2C
22 select SND_SOC_AK4642 if I2C 22 select SND_SOC_AK4642 if I2C
23 select SND_SOC_AK4671 if I2C 23 select SND_SOC_AK4671 if I2C
24 select SND_SOC_CQ0093VC if MFD_DAVINCI_VOICECODEC
24 select SND_SOC_CS4270 if I2C 25 select SND_SOC_CS4270 if I2C
25 select SND_SOC_MAX9877 if I2C 26 select SND_SOC_MAX9877 if I2C
26 select SND_SOC_DA7210 if I2C 27 select SND_SOC_DA7210 if I2C
@@ -114,6 +115,9 @@ config SND_SOC_AK4642
114config SND_SOC_AK4671 115config SND_SOC_AK4671
115 tristate 116 tristate
116 117
118config SND_SOC_CQ0093VC
119 tristate
120
117# Cirrus Logic CS4270 Codec 121# Cirrus Logic CS4270 Codec
118config SND_SOC_CS4270 122config SND_SOC_CS4270
119 tristate 123 tristate
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index dd5ce6df6292..69817778b2bd 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -8,6 +8,7 @@ snd-soc-ak4104-objs := ak4104.o
8snd-soc-ak4535-objs := ak4535.o 8snd-soc-ak4535-objs := ak4535.o
9snd-soc-ak4642-objs := ak4642.o 9snd-soc-ak4642-objs := ak4642.o
10snd-soc-ak4671-objs := ak4671.o 10snd-soc-ak4671-objs := ak4671.o
11snd-soc-cq93vc-objs := cq93vc.o
11snd-soc-cs4270-objs := cs4270.o 12snd-soc-cs4270-objs := cs4270.o
12snd-soc-cx20442-objs := cx20442.o 13snd-soc-cx20442-objs := cx20442.o
13snd-soc-da7210-objs := da7210.o 14snd-soc-da7210-objs := da7210.o
@@ -70,6 +71,7 @@ obj-$(CONFIG_SND_SOC_AK4104) += snd-soc-ak4104.o
70obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o 71obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o
71obj-$(CONFIG_SND_SOC_AK4642) += snd-soc-ak4642.o 72obj-$(CONFIG_SND_SOC_AK4642) += snd-soc-ak4642.o
72obj-$(CONFIG_SND_SOC_AK4671) += snd-soc-ak4671.o 73obj-$(CONFIG_SND_SOC_AK4671) += snd-soc-ak4671.o
74obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o
73obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o 75obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
74obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o 76obj-$(CONFIG_SND_SOC_CX20442) += snd-soc-cx20442.o
75obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o 77obj-$(CONFIG_SND_SOC_DA7210) += snd-soc-da7210.o
diff --git a/sound/soc/codecs/cq93vc.c b/sound/soc/codecs/cq93vc.c
new file mode 100644
index 000000000000..513297441369
--- /dev/null
+++ b/sound/soc/codecs/cq93vc.c
@@ -0,0 +1,298 @@
1/*
2 * ALSA SoC CQ0093 Voice Codec Driver for DaVinci platforms
3 *
4 * Copyright (C) 2010 Texas Instruments, Inc
5 *
6 * Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22#include <linux/module.h>
23#include <linux/moduleparam.h>
24#include <linux/init.h>
25#include <linux/io.h>
26#include <linux/delay.h>
27#include <linux/pm.h>
28#include <linux/platform_device.h>
29#include <linux/device.h>
30#include <linux/clk.h>
31#include <linux/mfd/davinci_voicecodec.h>
32
33#include <sound/core.h>
34#include <sound/pcm.h>
35#include <sound/pcm_params.h>
36#include <sound/soc.h>
37#include <sound/soc-dai.h>
38#include <sound/soc-dapm.h>
39#include <sound/initval.h>
40
41#include <mach/dm365.h>
42
43#include "cq93vc.h"
44
45static inline unsigned int cq93vc_read(struct snd_soc_codec *codec,
46 unsigned int reg)
47{
48 struct davinci_vc *davinci_vc = codec->control_data;
49
50 return readl(davinci_vc->base + reg);
51}
52
53static inline int cq93vc_write(struct snd_soc_codec *codec, unsigned int reg,
54 unsigned int value)
55{
56 struct davinci_vc *davinci_vc = codec->control_data;
57
58 writel(value, davinci_vc->base + reg);
59
60 return 0;
61}
62
63static const struct snd_kcontrol_new cq93vc_snd_controls[] = {
64 SOC_SINGLE("PGA Capture Volume", DAVINCI_VC_REG05, 0, 0x03, 0),
65 SOC_SINGLE("Mono DAC Playback Volume", DAVINCI_VC_REG09, 0, 0x3f, 0),
66};
67
68static int cq93vc_mute(struct snd_soc_dai *dai, int mute)
69{
70 struct snd_soc_codec *codec = dai->codec;
71 u8 reg = cq93vc_read(codec, DAVINCI_VC_REG09) & ~DAVINCI_VC_REG09_MUTE;
72
73 if (mute)
74 cq93vc_write(codec, DAVINCI_VC_REG09,
75 reg | DAVINCI_VC_REG09_MUTE);
76 else
77 cq93vc_write(codec, DAVINCI_VC_REG09, reg);
78
79 return 0;
80}
81
82static int cq93vc_set_dai_sysclk(struct snd_soc_dai *codec_dai,
83 int clk_id, unsigned int freq, int dir)
84{
85 struct snd_soc_codec *codec = codec_dai->codec;
86 struct davinci_vc *davinci_vc = codec->control_data;
87
88 switch (freq) {
89 case 22579200:
90 case 27000000:
91 case 33868800:
92 davinci_vc->cq93vc.sysclk = freq;
93 return 0;
94 }
95
96 return -EINVAL;
97}
98
99static int cq93vc_set_bias_level(struct snd_soc_codec *codec,
100 enum snd_soc_bias_level level)
101{
102 switch (level) {
103 case SND_SOC_BIAS_ON:
104 cq93vc_write(codec, DAVINCI_VC_REG12,
105 DAVINCI_VC_REG12_POWER_ALL_ON);
106 break;
107 case SND_SOC_BIAS_PREPARE:
108 break;
109 case SND_SOC_BIAS_STANDBY:
110 cq93vc_write(codec, DAVINCI_VC_REG12,
111 DAVINCI_VC_REG12_POWER_ALL_OFF);
112 break;
113 case SND_SOC_BIAS_OFF:
114 /* force all power off */
115 cq93vc_write(codec, DAVINCI_VC_REG12,
116 DAVINCI_VC_REG12_POWER_ALL_OFF);
117 break;
118 }
119 codec->bias_level = level;
120
121 return 0;
122}
123
124#define CQ93VC_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000)
125#define CQ93VC_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
126
127static struct snd_soc_dai_ops cq93vc_dai_ops = {
128 .digital_mute = cq93vc_mute,
129 .set_sysclk = cq93vc_set_dai_sysclk,
130};
131
132struct snd_soc_dai cq93vc_dai = {
133 .name = "CQ93VC",
134 .playback = {
135 .stream_name = "Playback",
136 .channels_min = 1,
137 .channels_max = 2,
138 .rates = CQ93VC_RATES,
139 .formats = CQ93VC_FORMATS,},
140 .capture = {
141 .stream_name = "Capture",
142 .channels_min = 1,
143 .channels_max = 2,
144 .rates = CQ93VC_RATES,
145 .formats = CQ93VC_FORMATS,},
146 .ops = &cq93vc_dai_ops,
147};
148EXPORT_SYMBOL_GPL(cq93vc_dai);
149
150static int cq93vc_resume(struct platform_device *pdev)
151{
152 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
153 struct snd_soc_codec *codec = socdev->card->codec;
154
155 cq93vc_set_bias_level(codec, codec->suspend_bias_level);
156
157 return 0;
158}
159
160static struct snd_soc_codec *cq93vc_codec;
161
162static int cq93vc_probe(struct platform_device *pdev)
163{
164 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
165 struct device *dev = &pdev->dev;
166 struct snd_soc_codec *codec;
167 int ret;
168
169 socdev->card->codec = cq93vc_codec;
170 codec = socdev->card->codec;
171
172 /* Register pcms */
173 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
174 if (ret < 0) {
175 dev_err(dev, "%s: failed to create pcms\n", pdev->name);
176 return ret;
177 }
178
179 /* Set controls */
180 snd_soc_add_controls(codec, cq93vc_snd_controls,
181 ARRAY_SIZE(cq93vc_snd_controls));
182
183 /* Off, with power on */
184 cq93vc_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
185
186 return 0;
187}
188
189static int cq93vc_remove(struct platform_device *pdev)
190{
191 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
192
193 snd_soc_free_pcms(socdev);
194 snd_soc_dapm_free(socdev);
195
196 return 0;
197}
198
199struct snd_soc_codec_device soc_codec_dev_cq93vc = {
200 .probe = cq93vc_probe,
201 .remove = cq93vc_remove,
202 .resume = cq93vc_resume,
203};
204EXPORT_SYMBOL_GPL(soc_codec_dev_cq93vc);
205
206static __init int cq93vc_codec_probe(struct platform_device *pdev)
207{
208 struct davinci_vc *davinci_vc = platform_get_drvdata(pdev);
209 struct snd_soc_codec *codec;
210 int ret;
211
212 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
213 if (codec == NULL) {
214 dev_dbg(davinci_vc->dev,
215 "could not allocate memory for codec data\n");
216 return -ENOMEM;
217 }
218
219 davinci_vc->cq93vc.codec = codec;
220
221 cq93vc_dai.dev = &pdev->dev;
222
223 mutex_init(&codec->mutex);
224 INIT_LIST_HEAD(&codec->dapm_widgets);
225 INIT_LIST_HEAD(&codec->dapm_paths);
226 codec->dev = &pdev->dev;
227 codec->name = "CQ93VC";
228 codec->owner = THIS_MODULE;
229 codec->read = cq93vc_read;
230 codec->write = cq93vc_write;
231 codec->set_bias_level = cq93vc_set_bias_level;
232 codec->dai = &cq93vc_dai;
233 codec->num_dai = 1;
234 codec->control_data = davinci_vc;
235
236 cq93vc_codec = codec;
237
238 ret = snd_soc_register_codec(codec);
239 if (ret) {
240 dev_err(davinci_vc->dev, "failed to register codec\n");
241 goto fail1;
242 }
243
244 ret = snd_soc_register_dai(&cq93vc_dai);
245 if (ret) {
246 dev_err(davinci_vc->dev, "could register dai\n");
247 goto fail2;
248 }
249 return 0;
250
251fail2:
252 snd_soc_unregister_codec(codec);
253
254fail1:
255 kfree(codec);
256 cq93vc_codec = NULL;
257
258 return ret;
259}
260
261static int __devexit cq93vc_codec_remove(struct platform_device *pdev)
262{
263 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
264 struct snd_soc_codec *codec = socdev->card->codec;
265
266 snd_soc_unregister_dai(&cq93vc_dai);
267 snd_soc_unregister_codec(&codec);
268
269 kfree(codec);
270 cq93vc_codec = NULL;
271
272 return 0;
273}
274
275static struct platform_driver cq93vc_codec_driver = {
276 .driver = {
277 .name = "cq93vc",
278 .owner = THIS_MODULE,
279 },
280 .probe = cq93vc_codec_probe,
281 .remove = __devexit_p(cq93vc_codec_remove),
282};
283
284static __init int cq93vc_init(void)
285{
286 return platform_driver_probe(&cq93vc_codec_driver, cq93vc_codec_probe);
287}
288module_init(cq93vc_init);
289
290static __exit void cq93vc_exit(void)
291{
292 platform_driver_unregister(&cq93vc_codec_driver);
293}
294module_exit(cq93vc_exit);
295
296MODULE_DESCRIPTION("Texas Instruments DaVinci ASoC CQ0093 Voice Codec Driver");
297MODULE_AUTHOR("Miguel Aguilar");
298MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cq93vc.h b/sound/soc/codecs/cq93vc.h
new file mode 100644
index 000000000000..845b1968ef9c
--- /dev/null
+++ b/sound/soc/codecs/cq93vc.h
@@ -0,0 +1,29 @@
1/*
2 * ALSA SoC CQ0093 Voice Codec Driver for DaVinci platforms
3 *
4 * Copyright (C) 2010 Texas Instruments, Inc
5 *
6 * Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#ifndef _CQ93VC_H
24#define _CQ93VC_H
25
26extern struct snd_soc_dai cq93vc_dai;
27extern struct snd_soc_codec_device soc_codec_dev_cq93vc;
28
29#endif