~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/davinci/davinci-vcif.c

Version: ~ [ linux-5.11 ] ~ [ linux-5.10.17 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.99 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.176 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.221 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.257 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.257 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * ALSA SoC Voice Codec Interface for TI DAVINCI processor
  3  *
  4  * Copyright (C) 2010 Texas Instruments.
  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 #include <linux/init.h>
 24 #include <linux/module.h>
 25 #include <linux/device.h>
 26 #include <linux/delay.h>
 27 #include <linux/slab.h>
 28 #include <linux/io.h>
 29 #include <linux/mfd/davinci_voicecodec.h>
 30 
 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>
 36 #include <sound/dmaengine_pcm.h>
 37 
 38 #include "edma-pcm.h"
 39 #include "davinci-i2s.h"
 40 
 41 #define MOD_REG_BIT(val, mask, set) do { \
 42         if (set) { \
 43                 val |= mask; \
 44         } else { \
 45                 val &= ~mask; \
 46         } \
 47 } while (0)
 48 
 49 struct davinci_vcif_dev {
 50         struct davinci_vc *davinci_vc;
 51         struct snd_dmaengine_dai_dma_data dma_data[2];
 52         int dma_request[2];
 53 };
 54 
 55 static void davinci_vcif_start(struct snd_pcm_substream *substream)
 56 {
 57         struct snd_soc_pcm_runtime *rtd = substream->private_data;
 58         struct davinci_vcif_dev *davinci_vcif_dev =
 59                         snd_soc_dai_get_drvdata(rtd->cpu_dai);
 60         struct davinci_vc *davinci_vc = davinci_vcif_dev->davinci_vc;
 61         u32 w;
 62 
 63         /* Start the sample generator and enable transmitter/receiver */
 64         w = readl(davinci_vc->base + DAVINCI_VC_CTRL);
 65 
 66         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 67                 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RSTDAC, 0);
 68         else
 69                 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RSTADC, 0);
 70 
 71         writel(w, davinci_vc->base + DAVINCI_VC_CTRL);
 72 }
 73 
 74 static void davinci_vcif_stop(struct snd_pcm_substream *substream)
 75 {
 76         struct snd_soc_pcm_runtime *rtd = substream->private_data;
 77         struct davinci_vcif_dev *davinci_vcif_dev =
 78                         snd_soc_dai_get_drvdata(rtd->cpu_dai);
 79         struct davinci_vc *davinci_vc = davinci_vcif_dev->davinci_vc;
 80         u32 w;
 81 
 82         /* Reset transmitter/receiver and sample rate/frame sync generators */
 83         w = readl(davinci_vc->base + DAVINCI_VC_CTRL);
 84         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 85                 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RSTDAC, 1);
 86         else
 87                 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RSTADC, 1);
 88 
 89         writel(w, davinci_vc->base + DAVINCI_VC_CTRL);
 90 }
 91 
 92 static int davinci_vcif_hw_params(struct snd_pcm_substream *substream,
 93                                   struct snd_pcm_hw_params *params,
 94                                   struct snd_soc_dai *dai)
 95 {
 96         struct davinci_vcif_dev *davinci_vcif_dev = snd_soc_dai_get_drvdata(dai);
 97         struct davinci_vc *davinci_vc = davinci_vcif_dev->davinci_vc;
 98         u32 w;
 99 
100         /* Restart the codec before setup */
101         davinci_vcif_stop(substream);
102         davinci_vcif_start(substream);
103 
104         /* General line settings */
105         writel(DAVINCI_VC_CTRL_MASK, davinci_vc->base + DAVINCI_VC_CTRL);
106 
107         writel(DAVINCI_VC_INT_MASK, davinci_vc->base + DAVINCI_VC_INTCLR);
108 
109         writel(DAVINCI_VC_INT_MASK, davinci_vc->base + DAVINCI_VC_INTEN);
110 
111         w = readl(davinci_vc->base + DAVINCI_VC_CTRL);
112 
113         /* Determine xfer data type */
114         switch (params_format(params)) {
115         case SNDRV_PCM_FORMAT_U8:
116                 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 |
117                             DAVINCI_VC_CTRL_RD_UNSIGNED |
118                             DAVINCI_VC_CTRL_WD_BITS_8 |
119                             DAVINCI_VC_CTRL_WD_UNSIGNED, 1);
120                 break;
121         case SNDRV_PCM_FORMAT_S8:
122                 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 |
123                             DAVINCI_VC_CTRL_WD_BITS_8, 1);
124 
125                 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_UNSIGNED |
126                             DAVINCI_VC_CTRL_WD_UNSIGNED, 0);
127                 break;
128         case SNDRV_PCM_FORMAT_S16_LE:
129                 MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 |
130                             DAVINCI_VC_CTRL_RD_UNSIGNED |
131                             DAVINCI_VC_CTRL_WD_BITS_8 |
132                             DAVINCI_VC_CTRL_WD_UNSIGNED, 0);
133                 break;
134         default:
135                 printk(KERN_WARNING "davinci-vcif: unsupported PCM format");
136                 return -EINVAL;
137         }
138 
139         writel(w, davinci_vc->base + DAVINCI_VC_CTRL);
140 
141         return 0;
142 }
143 
144 static int davinci_vcif_trigger(struct snd_pcm_substream *substream, int cmd,
145                                 struct snd_soc_dai *dai)
146 {
147         int ret = 0;
148 
149         switch (cmd) {
150         case SNDRV_PCM_TRIGGER_START:
151         case SNDRV_PCM_TRIGGER_RESUME:
152         case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
153                 davinci_vcif_start(substream);
154                 break;
155         case SNDRV_PCM_TRIGGER_STOP:
156         case SNDRV_PCM_TRIGGER_SUSPEND:
157         case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
158                 davinci_vcif_stop(substream);
159                 break;
160         default:
161                 ret = -EINVAL;
162         }
163 
164         return ret;
165 }
166 
167 #define DAVINCI_VCIF_RATES      SNDRV_PCM_RATE_8000_48000
168 
169 static const struct snd_soc_dai_ops davinci_vcif_dai_ops = {
170         .trigger        = davinci_vcif_trigger,
171         .hw_params      = davinci_vcif_hw_params,
172 };
173 
174 static int davinci_vcif_dai_probe(struct snd_soc_dai *dai)
175 {
176         struct davinci_vcif_dev *dev = snd_soc_dai_get_drvdata(dai);
177 
178         dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
179         dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
180 
181         return 0;
182 }
183 
184 static struct snd_soc_dai_driver davinci_vcif_dai = {
185         .probe = davinci_vcif_dai_probe,
186         .playback = {
187                 .channels_min = 1,
188                 .channels_max = 2,
189                 .rates = DAVINCI_VCIF_RATES,
190                 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
191         .capture = {
192                 .channels_min = 1,
193                 .channels_max = 2,
194                 .rates = DAVINCI_VCIF_RATES,
195                 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
196         .ops = &davinci_vcif_dai_ops,
197 
198 };
199 
200 static const struct snd_soc_component_driver davinci_vcif_component = {
201         .name           = "davinci-vcif",
202 };
203 
204 static int davinci_vcif_probe(struct platform_device *pdev)
205 {
206         struct davinci_vc *davinci_vc = pdev->dev.platform_data;
207         struct davinci_vcif_dev *davinci_vcif_dev;
208         int ret;
209 
210         davinci_vcif_dev = devm_kzalloc(&pdev->dev,
211                                         sizeof(struct davinci_vcif_dev),
212                                         GFP_KERNEL);
213         if (!davinci_vcif_dev)
214                 return -ENOMEM;
215 
216         /* DMA tx params */
217         davinci_vcif_dev->davinci_vc = davinci_vc;
218         davinci_vcif_dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].filter_data =
219                                 &davinci_vc->davinci_vcif.dma_tx_channel;
220         davinci_vcif_dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
221                                 davinci_vc->davinci_vcif.dma_tx_addr;
222 
223         /* DMA rx params */
224         davinci_vcif_dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].filter_data =
225                                 &davinci_vc->davinci_vcif.dma_rx_channel;
226         davinci_vcif_dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
227                                 davinci_vc->davinci_vcif.dma_rx_addr;
228 
229         dev_set_drvdata(&pdev->dev, davinci_vcif_dev);
230 
231         ret = devm_snd_soc_register_component(&pdev->dev,
232                                               &davinci_vcif_component,
233                                               &davinci_vcif_dai, 1);
234         if (ret != 0) {
235                 dev_err(&pdev->dev, "could not register dai\n");
236                 return ret;
237         }
238 
239         ret = edma_pcm_platform_register(&pdev->dev);
240         if (ret) {
241                 dev_err(&pdev->dev, "register PCM failed: %d\n", ret);
242                 return ret;
243         }
244 
245         return 0;
246 }
247 
248 static struct platform_driver davinci_vcif_driver = {
249         .probe          = davinci_vcif_probe,
250         .driver         = {
251                 .name   = "davinci-vcif",
252         },
253 };
254 
255 module_platform_driver(davinci_vcif_driver);
256 
257 MODULE_AUTHOR("Miguel Aguilar");
258 MODULE_DESCRIPTION("Texas Instruments DaVinci ASoC Voice Codec Interface");
259 MODULE_LICENSE("GPL");
260 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp