2 * ALSA SoC CQ0093 Voice Codec Driver for DaVinci platforms
4 * Copyright (C) 2010 Texas Instruments, Inc
6 * Author: Miguel Aguilar <miguel.aguilar@ridgerun.com>
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.
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.
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
22 #include <linux/module.h>
23 #include <linux/moduleparam.h>
24 #include <linux/init.h>
26 #include <linux/delay.h>
28 #include <linux/platform_device.h>
29 #include <linux/device.h>
30 #include <linux/clk.h>
31 #include <linux/mfd/davinci_voicecodec.h>
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>
41 #include <mach/dm365.h>
45 static inline unsigned int cq93vc_read(struct snd_soc_codec
*codec
,
48 struct davinci_vc
*davinci_vc
= codec
->control_data
;
50 return readl(davinci_vc
->base
+ reg
);
53 static inline int cq93vc_write(struct snd_soc_codec
*codec
, unsigned int reg
,
56 struct davinci_vc
*davinci_vc
= codec
->control_data
;
58 writel(value
, davinci_vc
->base
+ reg
);
63 static 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),
68 static int cq93vc_mute(struct snd_soc_dai
*dai
, int mute
)
70 struct snd_soc_codec
*codec
= dai
->codec
;
71 u8 reg
= cq93vc_read(codec
, DAVINCI_VC_REG09
) & ~DAVINCI_VC_REG09_MUTE
;
74 cq93vc_write(codec
, DAVINCI_VC_REG09
,
75 reg
| DAVINCI_VC_REG09_MUTE
);
77 cq93vc_write(codec
, DAVINCI_VC_REG09
, reg
);
82 static int cq93vc_set_dai_sysclk(struct snd_soc_dai
*codec_dai
,
83 int clk_id
, unsigned int freq
, int dir
)
85 struct snd_soc_codec
*codec
= codec_dai
->codec
;
86 struct davinci_vc
*davinci_vc
= codec
->control_data
;
92 davinci_vc
->cq93vc
.sysclk
= freq
;
99 static int cq93vc_set_bias_level(struct snd_soc_codec
*codec
,
100 enum snd_soc_bias_level level
)
103 case SND_SOC_BIAS_ON
:
104 cq93vc_write(codec
, DAVINCI_VC_REG12
,
105 DAVINCI_VC_REG12_POWER_ALL_ON
);
107 case SND_SOC_BIAS_PREPARE
:
109 case SND_SOC_BIAS_STANDBY
:
110 cq93vc_write(codec
, DAVINCI_VC_REG12
,
111 DAVINCI_VC_REG12_POWER_ALL_OFF
);
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
);
119 codec
->bias_level
= level
;
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)
127 static struct snd_soc_dai_ops cq93vc_dai_ops
= {
128 .digital_mute
= cq93vc_mute
,
129 .set_sysclk
= cq93vc_set_dai_sysclk
,
132 struct snd_soc_dai cq93vc_dai
= {
135 .stream_name
= "Playback",
138 .rates
= CQ93VC_RATES
,
139 .formats
= CQ93VC_FORMATS
,},
141 .stream_name
= "Capture",
144 .rates
= CQ93VC_RATES
,
145 .formats
= CQ93VC_FORMATS
,},
146 .ops
= &cq93vc_dai_ops
,
148 EXPORT_SYMBOL_GPL(cq93vc_dai
);
150 static int cq93vc_resume(struct platform_device
*pdev
)
152 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
153 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
155 cq93vc_set_bias_level(codec
, codec
->suspend_bias_level
);
160 static struct snd_soc_codec
*cq93vc_codec
;
162 static int cq93vc_probe(struct platform_device
*pdev
)
164 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
165 struct device
*dev
= &pdev
->dev
;
166 struct snd_soc_codec
*codec
;
169 socdev
->card
->codec
= cq93vc_codec
;
170 codec
= socdev
->card
->codec
;
173 ret
= snd_soc_new_pcms(socdev
, SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
);
175 dev_err(dev
, "%s: failed to create pcms\n", pdev
->name
);
180 snd_soc_add_controls(codec
, cq93vc_snd_controls
,
181 ARRAY_SIZE(cq93vc_snd_controls
));
183 /* Off, with power on */
184 cq93vc_set_bias_level(codec
, SND_SOC_BIAS_STANDBY
);
189 static int cq93vc_remove(struct platform_device
*pdev
)
191 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
193 snd_soc_free_pcms(socdev
);
194 snd_soc_dapm_free(socdev
);
199 struct snd_soc_codec_device soc_codec_dev_cq93vc
= {
200 .probe
= cq93vc_probe
,
201 .remove
= cq93vc_remove
,
202 .resume
= cq93vc_resume
,
204 EXPORT_SYMBOL_GPL(soc_codec_dev_cq93vc
);
206 static __init
int cq93vc_codec_probe(struct platform_device
*pdev
)
208 struct davinci_vc
*davinci_vc
= platform_get_drvdata(pdev
);
209 struct snd_soc_codec
*codec
;
212 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
214 dev_dbg(davinci_vc
->dev
,
215 "could not allocate memory for codec data\n");
219 davinci_vc
->cq93vc
.codec
= codec
;
221 cq93vc_dai
.dev
= &pdev
->dev
;
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
;
234 codec
->control_data
= davinci_vc
;
236 cq93vc_codec
= codec
;
238 ret
= snd_soc_register_codec(codec
);
240 dev_err(davinci_vc
->dev
, "failed to register codec\n");
244 ret
= snd_soc_register_dai(&cq93vc_dai
);
246 dev_err(davinci_vc
->dev
, "could register dai\n");
252 snd_soc_unregister_codec(codec
);
261 static int __devexit
cq93vc_codec_remove(struct platform_device
*pdev
)
263 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
264 struct snd_soc_codec
*codec
= socdev
->card
->codec
;
266 snd_soc_unregister_dai(&cq93vc_dai
);
267 snd_soc_unregister_codec(&codec
);
275 static struct platform_driver cq93vc_codec_driver
= {
278 .owner
= THIS_MODULE
,
280 .probe
= cq93vc_codec_probe
,
281 .remove
= __devexit_p(cq93vc_codec_remove
),
284 static __init
int cq93vc_init(void)
286 return platform_driver_probe(&cq93vc_codec_driver
, cq93vc_codec_probe
);
288 module_init(cq93vc_init
);
290 static __exit
void cq93vc_exit(void)
292 platform_driver_unregister(&cq93vc_codec_driver
);
294 module_exit(cq93vc_exit
);
296 MODULE_DESCRIPTION("Texas Instruments DaVinci ASoC CQ0093 Voice Codec Driver");
297 MODULE_AUTHOR("Miguel Aguilar");
298 MODULE_LICENSE("GPL");