2 * ALSA SoC Voice Codec Interface for TI DAVINCI processor
4 * Copyright (C) 2010 Texas Instruments.
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
23 #include <linux/init.h>
24 #include <linux/module.h>
25 #include <linux/device.h>
26 #include <linux/delay.h>
27 #include <linux/slab.h>
29 #include <linux/mfd/davinci_voicecodec.h>
31 #include <sound/core.h>
32 #include <sound/pcm.h>
33 #include <sound/pcm_params.h>
34 #include <sound/initval.h>
35 #include <sound/soc.h>
37 #include "davinci-pcm.h"
38 #include "davinci-i2s.h"
40 #define MOD_REG_BIT(val, mask, set) do { \
48 struct davinci_vcif_dev
{
49 struct davinci_vc
*davinci_vc
;
50 struct davinci_pcm_dma_params dma_params
[2];
53 static void davinci_vcif_start(struct snd_pcm_substream
*substream
)
55 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
56 struct davinci_vcif_dev
*davinci_vcif_dev
=
57 snd_soc_dai_get_drvdata(rtd
->cpu_dai
);
58 struct davinci_vc
*davinci_vc
= davinci_vcif_dev
->davinci_vc
;
61 /* Start the sample generator and enable transmitter/receiver */
62 w
= readl(davinci_vc
->base
+ DAVINCI_VC_CTRL
);
64 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
65 MOD_REG_BIT(w
, DAVINCI_VC_CTRL_RSTDAC
, 1);
67 MOD_REG_BIT(w
, DAVINCI_VC_CTRL_RSTADC
, 1);
69 writel(w
, davinci_vc
->base
+ DAVINCI_VC_CTRL
);
72 static void davinci_vcif_stop(struct snd_pcm_substream
*substream
)
74 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
75 struct davinci_vcif_dev
*davinci_vcif_dev
=
76 snd_soc_dai_get_drvdata(rtd
->cpu_dai
);
77 struct davinci_vc
*davinci_vc
= davinci_vcif_dev
->davinci_vc
;
80 /* Reset transmitter/receiver and sample rate/frame sync generators */
81 w
= readl(davinci_vc
->base
+ DAVINCI_VC_CTRL
);
82 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
83 MOD_REG_BIT(w
, DAVINCI_VC_CTRL_RSTDAC
, 0);
85 MOD_REG_BIT(w
, DAVINCI_VC_CTRL_RSTADC
, 0);
87 writel(w
, davinci_vc
->base
+ DAVINCI_VC_CTRL
);
90 static int davinci_vcif_hw_params(struct snd_pcm_substream
*substream
,
91 struct snd_pcm_hw_params
*params
,
92 struct snd_soc_dai
*dai
)
94 struct davinci_vcif_dev
*davinci_vcif_dev
= snd_soc_dai_get_drvdata(dai
);
95 struct davinci_vc
*davinci_vc
= davinci_vcif_dev
->davinci_vc
;
96 struct davinci_pcm_dma_params
*dma_params
=
97 &davinci_vcif_dev
->dma_params
[substream
->stream
];
100 dai
->capture_dma_data
= davinci_vcif_dev
->dma_params
;
101 dai
->playback_dma_data
= davinci_vcif_dev
->dma_params
;
103 /* Restart the codec before setup */
104 davinci_vcif_stop(substream
);
105 davinci_vcif_start(substream
);
107 /* General line settings */
108 writel(DAVINCI_VC_CTRL_MASK
, davinci_vc
->base
+ DAVINCI_VC_CTRL
);
110 writel(DAVINCI_VC_INT_MASK
, davinci_vc
->base
+ DAVINCI_VC_INTCLR
);
112 writel(DAVINCI_VC_INT_MASK
, davinci_vc
->base
+ DAVINCI_VC_INTEN
);
114 w
= readl(davinci_vc
->base
+ DAVINCI_VC_CTRL
);
116 /* Determine xfer data type */
117 switch (params_format(params
)) {
118 case SNDRV_PCM_FORMAT_U8
:
119 dma_params
->data_type
= 0;
121 MOD_REG_BIT(w
, DAVINCI_VC_CTRL_RD_BITS_8
|
122 DAVINCI_VC_CTRL_RD_UNSIGNED
|
123 DAVINCI_VC_CTRL_WD_BITS_8
|
124 DAVINCI_VC_CTRL_WD_UNSIGNED
, 1);
126 case SNDRV_PCM_FORMAT_S8
:
127 dma_params
->data_type
= 1;
129 MOD_REG_BIT(w
, DAVINCI_VC_CTRL_RD_BITS_8
|
130 DAVINCI_VC_CTRL_WD_BITS_8
, 1);
132 MOD_REG_BIT(w
, DAVINCI_VC_CTRL_RD_UNSIGNED
|
133 DAVINCI_VC_CTRL_WD_UNSIGNED
, 0);
135 case SNDRV_PCM_FORMAT_S16_LE
:
136 dma_params
->data_type
= 2;
138 MOD_REG_BIT(w
, DAVINCI_VC_CTRL_RD_BITS_8
|
139 DAVINCI_VC_CTRL_RD_UNSIGNED
|
140 DAVINCI_VC_CTRL_WD_BITS_8
|
141 DAVINCI_VC_CTRL_WD_UNSIGNED
, 0);
144 printk(KERN_WARNING
"davinci-vcif: unsupported PCM format");
148 dma_params
->acnt
= dma_params
->data_type
;
150 writel(w
, davinci_vc
->base
+ DAVINCI_VC_CTRL
);
155 static int davinci_vcif_trigger(struct snd_pcm_substream
*substream
, int cmd
,
156 struct snd_soc_dai
*dai
)
161 case SNDRV_PCM_TRIGGER_START
:
162 case SNDRV_PCM_TRIGGER_RESUME
:
163 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
164 davinci_vcif_start(substream
);
165 case SNDRV_PCM_TRIGGER_STOP
:
166 case SNDRV_PCM_TRIGGER_SUSPEND
:
167 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
168 davinci_vcif_stop(substream
);
177 #define DAVINCI_VCIF_RATES SNDRV_PCM_RATE_8000_48000
179 static struct snd_soc_dai_ops davinci_vcif_dai_ops
= {
180 .trigger
= davinci_vcif_trigger
,
181 .hw_params
= davinci_vcif_hw_params
,
184 static struct snd_soc_dai_driver davinci_vcif_dai
= {
188 .rates
= DAVINCI_VCIF_RATES
,
189 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
193 .rates
= DAVINCI_VCIF_RATES
,
194 .formats
= SNDRV_PCM_FMTBIT_S16_LE
,},
195 .ops
= &davinci_vcif_dai_ops
,
199 static int davinci_vcif_probe(struct platform_device
*pdev
)
201 struct davinci_vc
*davinci_vc
= platform_get_drvdata(pdev
);
202 struct davinci_vcif_dev
*davinci_vcif_dev
;
205 davinci_vcif_dev
= kzalloc(sizeof(struct davinci_vcif_dev
), GFP_KERNEL
);
206 if (!davinci_vcif_dev
) {
208 "could not allocate memory for private data\n");
213 davinci_vcif_dev
->davinci_vc
= davinci_vc
;
214 davinci_vcif_dev
->dma_params
[SNDRV_PCM_STREAM_PLAYBACK
].channel
=
215 davinci_vc
->davinci_vcif
.dma_tx_channel
;
216 davinci_vcif_dev
->dma_params
[SNDRV_PCM_STREAM_PLAYBACK
].dma_addr
=
217 davinci_vc
->davinci_vcif
.dma_tx_addr
;
220 davinci_vcif_dev
->dma_params
[SNDRV_PCM_STREAM_CAPTURE
].channel
=
221 davinci_vc
->davinci_vcif
.dma_rx_channel
;
222 davinci_vcif_dev
->dma_params
[SNDRV_PCM_STREAM_CAPTURE
].dma_addr
=
223 davinci_vc
->davinci_vcif
.dma_rx_addr
;
225 dev_set_drvdata(&pdev
->dev
, davinci_vcif_dev
);
227 ret
= snd_soc_register_dai(&pdev
->dev
, &davinci_vcif_dai
);
229 dev_err(&pdev
->dev
, "could not register dai\n");
236 kfree(davinci_vcif_dev
);
241 static int davinci_vcif_remove(struct platform_device
*pdev
)
243 snd_soc_unregister_dai(&pdev
->dev
);
248 static struct platform_driver davinci_vcif_driver
= {
249 .probe
= davinci_vcif_probe
,
250 .remove
= davinci_vcif_remove
,
252 .name
= "davinci-vcif",
253 .owner
= THIS_MODULE
,
257 static int __init
davinci_vcif_init(void)
259 return platform_driver_probe(&davinci_vcif_driver
, davinci_vcif_probe
);
261 module_init(davinci_vcif_init
);
263 static void __exit
davinci_vcif_exit(void)
265 platform_driver_unregister(&davinci_vcif_driver
);
267 module_exit(davinci_vcif_exit
);
269 MODULE_AUTHOR("Miguel Aguilar");
270 MODULE_DESCRIPTION("Texas Instruments DaVinci ASoC Voice Codec Interface");
271 MODULE_LICENSE("GPL");