blob: 02421d4275f51a484d23f77016bc0c146b831abe [file] [log] [blame]
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001/*
2 * ALSA SoC McASP Audio Layer for TI DAVINCI processor
3 *
4 * Multi-channel Audio Serial Port Driver
5 *
6 * Author: Nirmal Pandey <n-pandey@ti.com>,
7 * Suresh Rajashekara <suresh.r@ti.com>
8 * Steve Chen <schen@.mvista.com>
9 *
10 * Copyright: (C) 2009 MontaVista Software, Inc., <source@mvista.com>
11 * Copyright: (C) 2009 Texas Instruments, India
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
16 */
17
18#include <linux/init.h>
19#include <linux/module.h>
20#include <linux/device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Chaithrika U Sb67f4482009-06-05 06:28:40 -040022#include <linux/delay.h>
23#include <linux/io.h>
Peter Ujfalusiae726e92013-11-14 11:35:35 +020024#include <linux/clk.h>
Hebbar, Gururaja10884342012-08-08 20:40:32 +053025#include <linux/pm_runtime.h>
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +053026#include <linux/of.h>
27#include <linux/of_platform.h>
28#include <linux/of_device.h>
Chaithrika U Sb67f4482009-06-05 06:28:40 -040029
Daniel Mack64792852014-03-27 11:27:40 +010030#include <sound/asoundef.h>
Chaithrika U Sb67f4482009-06-05 06:28:40 -040031#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>
Peter Ujfalusi453c4992013-11-14 11:35:34 +020036#include <sound/dmaengine_pcm.h>
Jyri Sarha87c19362014-05-26 11:51:14 +030037#include <sound/omap-pcm.h>
Chaithrika U Sb67f4482009-06-05 06:28:40 -040038
39#include "davinci-pcm.h"
Peter Ujfalusif3f9cfa2014-07-16 15:12:04 +030040#include "edma-pcm.h"
Chaithrika U Sb67f4482009-06-05 06:28:40 -040041#include "davinci-mcasp.h"
42
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +030043#define MCASP_MAX_AFIFO_DEPTH 64
44
Peter Ujfalusi790bb942014-02-03 14:51:52 +020045struct davinci_mcasp_context {
46 u32 txfmtctl;
47 u32 rxfmtctl;
48 u32 txfmt;
49 u32 rxfmt;
50 u32 aclkxctl;
51 u32 aclkrctl;
52 u32 pdir;
53};
54
Peter Ujfalusi70091a32013-11-14 11:35:29 +020055struct davinci_mcasp {
Peter Ujfalusi21400a72013-11-14 11:35:26 +020056 struct davinci_pcm_dma_params dma_params[2];
Peter Ujfalusi453c4992013-11-14 11:35:34 +020057 struct snd_dmaengine_dai_dma_data dma_data[2];
Peter Ujfalusi21400a72013-11-14 11:35:26 +020058 void __iomem *base;
Peter Ujfalusi487dce82013-11-14 11:35:31 +020059 u32 fifo_base;
Peter Ujfalusi21400a72013-11-14 11:35:26 +020060 struct device *dev;
61
62 /* McASP specific data */
63 int tdm_slots;
64 u8 op_mode;
65 u8 num_serializer;
66 u8 *serial_dir;
67 u8 version;
68 u16 bclk_lrclk_ratio;
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +020069 int streams;
Peter Ujfalusi21400a72013-11-14 11:35:26 +020070
Jyri Sarhaab8b14b2014-01-27 17:37:52 +020071 int sysclk_freq;
72 bool bclk_master;
73
Peter Ujfalusi21400a72013-11-14 11:35:26 +020074 /* McASP FIFO related */
75 u8 txnumevt;
76 u8 rxnumevt;
77
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +020078 bool dat_port;
79
Peter Ujfalusi21400a72013-11-14 11:35:26 +020080#ifdef CONFIG_PM_SLEEP
Peter Ujfalusi790bb942014-02-03 14:51:52 +020081 struct davinci_mcasp_context context;
Peter Ujfalusi21400a72013-11-14 11:35:26 +020082#endif
83};
84
Peter Ujfalusif68205a2013-11-14 11:35:36 +020085static inline void mcasp_set_bits(struct davinci_mcasp *mcasp, u32 offset,
86 u32 val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -040087{
Peter Ujfalusif68205a2013-11-14 11:35:36 +020088 void __iomem *reg = mcasp->base + offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -040089 __raw_writel(__raw_readl(reg) | val, reg);
90}
91
Peter Ujfalusif68205a2013-11-14 11:35:36 +020092static inline void mcasp_clr_bits(struct davinci_mcasp *mcasp, u32 offset,
93 u32 val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -040094{
Peter Ujfalusif68205a2013-11-14 11:35:36 +020095 void __iomem *reg = mcasp->base + offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -040096 __raw_writel((__raw_readl(reg) & ~(val)), reg);
97}
98
Peter Ujfalusif68205a2013-11-14 11:35:36 +020099static inline void mcasp_mod_bits(struct davinci_mcasp *mcasp, u32 offset,
100 u32 val, u32 mask)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400101{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200102 void __iomem *reg = mcasp->base + offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400103 __raw_writel((__raw_readl(reg) & ~mask) | val, reg);
104}
105
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200106static inline void mcasp_set_reg(struct davinci_mcasp *mcasp, u32 offset,
107 u32 val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400108{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200109 __raw_writel(val, mcasp->base + offset);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400110}
111
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200112static inline u32 mcasp_get_reg(struct davinci_mcasp *mcasp, u32 offset)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400113{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200114 return (u32)__raw_readl(mcasp->base + offset);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400115}
116
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200117static void mcasp_set_ctl_reg(struct davinci_mcasp *mcasp, u32 ctl_reg, u32 val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400118{
119 int i = 0;
120
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200121 mcasp_set_bits(mcasp, ctl_reg, val);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400122
123 /* programming GBLCTL needs to read back from GBLCTL and verfiy */
124 /* loop count is to avoid the lock-up */
125 for (i = 0; i < 1000; i++) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200126 if ((mcasp_get_reg(mcasp, ctl_reg) & val) == val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400127 break;
128 }
129
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200130 if (i == 1000 && ((mcasp_get_reg(mcasp, ctl_reg) & val) != val))
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400131 printk(KERN_ERR "GBLCTL write error\n");
132}
133
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200134static bool mcasp_is_synchronous(struct davinci_mcasp *mcasp)
135{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200136 u32 rxfmctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG);
137 u32 aclkxctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200138
139 return !(aclkxctl & TX_ASYNC) && rxfmctl & AFSRE;
140}
141
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200142static void mcasp_start_rx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400143{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200144 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXHCLKRST);
145 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXCLKRST);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200146
147 /*
148 * When ASYNC == 0 the transmit and receive sections operate
149 * synchronously from the transmit clock and frame sync. We need to make
150 * sure that the TX signlas are enabled when starting reception.
151 */
152 if (mcasp_is_synchronous(mcasp)) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200153 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST);
154 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200155 }
156
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200157 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSERCLR);
158 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400159
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200160 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSMRST);
161 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXFSRST);
162 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400163
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200164 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSMRST);
165 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXFSRST);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200166
167 if (mcasp_is_synchronous(mcasp))
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200168 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXFSRST);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400169}
170
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200171static void mcasp_start_tx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400172{
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400173 u8 offset = 0, i;
174 u32 cnt;
175
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200176 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST);
177 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
178 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXSERCLR);
179 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400180
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200181 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXSMRST);
182 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXFSRST);
183 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXBUF_REG, 0);
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200184 for (i = 0; i < mcasp->num_serializer; i++) {
185 if (mcasp->serial_dir[i] == TX_MODE) {
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400186 offset = i;
187 break;
188 }
189 }
190
191 /* wait for TX ready */
192 cnt = 0;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200193 while (!(mcasp_get_reg(mcasp, DAVINCI_MCASP_XRSRCTL_REG(offset)) &
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400194 TXSTATE) && (cnt < 100000))
195 cnt++;
196
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200197 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400198}
199
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200200static void davinci_mcasp_start(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400201{
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200202 u32 reg;
203
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200204 mcasp->streams++;
205
Chaithrika U S539d3d82009-09-23 10:12:08 -0400206 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200207 if (mcasp->txnumevt) { /* enable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200208 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200209 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
210 mcasp_set_bits(mcasp, reg, FIFO_ENABLE);
Vaibhav Bedia0d624272012-08-08 20:40:31 +0530211 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200212 mcasp_start_tx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400213 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200214 if (mcasp->rxnumevt) { /* enable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200215 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200216 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
217 mcasp_set_bits(mcasp, reg, FIFO_ENABLE);
Vaibhav Bedia0d624272012-08-08 20:40:31 +0530218 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200219 mcasp_start_rx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400220 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400221}
222
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200223static void mcasp_stop_rx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400224{
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200225 /*
226 * In synchronous mode stop the TX clocks if no other stream is
227 * running
228 */
229 if (mcasp_is_synchronous(mcasp) && !mcasp->streams)
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200230 mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, 0);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200231
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200232 mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, 0);
233 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400234}
235
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200236static void mcasp_stop_tx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400237{
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200238 u32 val = 0;
239
240 /*
241 * In synchronous mode keep TX clocks running if the capture stream is
242 * still running.
243 */
244 if (mcasp_is_synchronous(mcasp) && mcasp->streams)
245 val = TXHCLKRST | TXCLKRST | TXFSRST;
246
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200247 mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, val);
248 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400249}
250
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200251static void davinci_mcasp_stop(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400252{
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200253 u32 reg;
254
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200255 mcasp->streams--;
256
Chaithrika U S539d3d82009-09-23 10:12:08 -0400257 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200258 if (mcasp->txnumevt) { /* disable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200259 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200260 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530261 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200262 mcasp_stop_tx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400263 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200264 if (mcasp->rxnumevt) { /* disable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200265 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200266 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530267 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200268 mcasp_stop_rx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400269 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400270}
271
272static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
273 unsigned int fmt)
274{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200275 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200276 int ret = 0;
Peter Ujfalusi6dfa9a42014-04-04 14:31:42 +0300277 u32 data_delay;
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300278 bool fs_pol_rising;
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300279 bool inv_fs = false;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400280
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200281 pm_runtime_get_sync(mcasp->dev);
Daniel Mack5296cf22012-10-04 15:08:42 +0200282 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
Peter Ujfalusi188edc52014-04-04 14:31:43 +0300283 case SND_SOC_DAIFMT_DSP_A:
284 mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
285 mcasp_clr_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
Peter Ujfalusi188edc52014-04-04 14:31:43 +0300286 /* 1st data bit occur one ACLK cycle after the frame sync */
287 data_delay = 1;
288 break;
Daniel Mack5296cf22012-10-04 15:08:42 +0200289 case SND_SOC_DAIFMT_DSP_B:
290 case SND_SOC_DAIFMT_AC97:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200291 mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
292 mcasp_clr_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
Peter Ujfalusi6dfa9a42014-04-04 14:31:42 +0300293 /* No delay after FS */
294 data_delay = 0;
Daniel Mack5296cf22012-10-04 15:08:42 +0200295 break;
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300296 case SND_SOC_DAIFMT_I2S:
Daniel Mack5296cf22012-10-04 15:08:42 +0200297 /* configure a full-word SYNC pulse (LRCLK) */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200298 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
299 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
Peter Ujfalusi6dfa9a42014-04-04 14:31:42 +0300300 /* 1st data bit occur one ACLK cycle after the frame sync */
301 data_delay = 1;
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300302 /* FS need to be inverted */
303 inv_fs = true;
Daniel Mack5296cf22012-10-04 15:08:42 +0200304 break;
Peter Ujfalusi423761e2014-04-04 14:31:46 +0300305 case SND_SOC_DAIFMT_LEFT_J:
306 /* configure a full-word SYNC pulse (LRCLK) */
307 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
308 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
309 /* No delay after FS */
310 data_delay = 0;
311 break;
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300312 default:
313 ret = -EINVAL;
314 goto out;
Daniel Mack5296cf22012-10-04 15:08:42 +0200315 }
316
Peter Ujfalusi6dfa9a42014-04-04 14:31:42 +0300317 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, FSXDLY(data_delay),
318 FSXDLY(3));
319 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, FSRDLY(data_delay),
320 FSRDLY(3));
321
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400322 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
323 case SND_SOC_DAIFMT_CBS_CFS:
324 /* codec is clock and frame slave */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200325 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
326 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400327
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200328 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
329 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400330
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200331 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, ACLKX | ACLKR);
332 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200333 mcasp->bclk_master = 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400334 break;
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400335 case SND_SOC_DAIFMT_CBM_CFS:
336 /* codec is clock master and frame slave */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200337 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
338 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400339
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200340 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
341 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400342
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200343 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, ACLKX | ACLKR);
344 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200345 mcasp->bclk_master = 0;
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400346 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400347 case SND_SOC_DAIFMT_CBM_CFM:
348 /* codec is clock and frame master */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200349 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
350 mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400351
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200352 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
353 mcasp_clr_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400354
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200355 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG,
356 ACLKX | AHCLKX | AFSX | ACLKR | AHCLKR | AFSR);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200357 mcasp->bclk_master = 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400358 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400359 default:
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200360 ret = -EINVAL;
361 goto out;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400362 }
363
364 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
365 case SND_SOC_DAIFMT_IB_NF:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200366 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
Peter Ujfalusi74ddd8c2014-04-04 14:31:41 +0300367 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300368 fs_pol_rising = true;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400369 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400370 case SND_SOC_DAIFMT_NB_IF:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200371 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
Peter Ujfalusi74ddd8c2014-04-04 14:31:41 +0300372 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300373 fs_pol_rising = false;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400374 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400375 case SND_SOC_DAIFMT_IB_IF:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200376 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
Peter Ujfalusi74ddd8c2014-04-04 14:31:41 +0300377 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300378 fs_pol_rising = false;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400379 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400380 case SND_SOC_DAIFMT_NB_NF:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200381 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200382 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300383 fs_pol_rising = true;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400384 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400385 default:
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200386 ret = -EINVAL;
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300387 goto out;
388 }
389
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300390 if (inv_fs)
391 fs_pol_rising = !fs_pol_rising;
392
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300393 if (fs_pol_rising) {
394 mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXPOL);
395 mcasp_clr_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRPOL);
396 } else {
397 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXPOL);
398 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRPOL);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400399 }
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200400out:
401 pm_runtime_put_sync(mcasp->dev);
402 return ret;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400403}
404
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200405static int davinci_mcasp_set_clkdiv(struct snd_soc_dai *dai, int div_id, int div)
406{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200407 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200408
409 switch (div_id) {
410 case 0: /* MCLK divider */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200411 mcasp_mod_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200412 AHCLKXDIV(div - 1), AHCLKXDIV_MASK);
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200413 mcasp_mod_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200414 AHCLKRDIV(div - 1), AHCLKRDIV_MASK);
415 break;
416
417 case 1: /* BCLK divider */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200418 mcasp_mod_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200419 ACLKXDIV(div - 1), ACLKXDIV_MASK);
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200420 mcasp_mod_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200421 ACLKRDIV(div - 1), ACLKRDIV_MASK);
422 break;
423
Daniel Mack1b3bc062012-12-05 18:20:38 +0100424 case 2: /* BCLK/LRCLK ratio */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200425 mcasp->bclk_lrclk_ratio = div;
Daniel Mack1b3bc062012-12-05 18:20:38 +0100426 break;
427
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200428 default:
429 return -EINVAL;
430 }
431
432 return 0;
433}
434
Daniel Mack5b66aa22012-10-04 15:08:41 +0200435static int davinci_mcasp_set_sysclk(struct snd_soc_dai *dai, int clk_id,
436 unsigned int freq, int dir)
437{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200438 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200439
440 if (dir == SND_SOC_CLOCK_OUT) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200441 mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE);
442 mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE);
443 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AHCLKX);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200444 } else {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200445 mcasp_clr_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE);
446 mcasp_clr_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE);
447 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AHCLKX);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200448 }
449
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200450 mcasp->sysclk_freq = freq;
451
Daniel Mack5b66aa22012-10-04 15:08:41 +0200452 return 0;
453}
454
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200455static int davinci_config_channel_size(struct davinci_mcasp *mcasp,
Daniel Mackba764b32012-12-05 18:20:37 +0100456 int word_length)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400457{
Daniel Mackba764b32012-12-05 18:20:37 +0100458 u32 fmt;
Daniel Mack79671892013-05-16 15:25:01 +0200459 u32 tx_rotate = (word_length / 4) & 0x7;
460 u32 rx_rotate = (32 - word_length) / 4;
Daniel Mackba764b32012-12-05 18:20:37 +0100461 u32 mask = (1ULL << word_length) - 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400462
Daniel Mack1b3bc062012-12-05 18:20:38 +0100463 /*
464 * if s BCLK-to-LRCLK ratio has been configured via the set_clkdiv()
465 * callback, take it into account here. That allows us to for example
466 * send 32 bits per channel to the codec, while only 16 of them carry
467 * audio payload.
Michal Bachratyd486fea2013-04-19 15:28:44 +0200468 * The clock ratio is given for a full period of data (for I2S format
469 * both left and right channels), so it has to be divided by number of
470 * tdm-slots (for I2S - divided by 2).
Daniel Mack1b3bc062012-12-05 18:20:38 +0100471 */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200472 if (mcasp->bclk_lrclk_ratio)
473 word_length = mcasp->bclk_lrclk_ratio / mcasp->tdm_slots;
Daniel Mack1b3bc062012-12-05 18:20:38 +0100474
Daniel Mackba764b32012-12-05 18:20:37 +0100475 /* mapping of the XSSZ bit-field as described in the datasheet */
476 fmt = (word_length >> 1) - 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400477
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200478 if (mcasp->op_mode != DAVINCI_MCASP_DIT_MODE) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200479 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, RXSSZ(fmt),
480 RXSSZ(0x0F));
481 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXSSZ(fmt),
482 TXSSZ(0x0F));
483 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXROT(tx_rotate),
484 TXROT(7));
485 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, RXROT(rx_rotate),
486 RXROT(7));
487 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXMASK_REG, mask);
Yegor Yefremovf5023af2013-04-04 16:13:20 +0200488 }
489
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200490 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXMASK_REG, mask);
Chaithrika U S0c31cf32009-09-15 18:13:29 -0400491
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400492 return 0;
493}
494
Peter Ujfalusi662ffae2014-01-30 15:15:22 +0200495static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream,
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300496 int period_words, int channels)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400497{
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300498 struct davinci_pcm_dma_params *dma_params = &mcasp->dma_params[stream];
499 struct snd_dmaengine_dai_dma_data *dma_data = &mcasp->dma_data[stream];
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400500 int i;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400501 u8 tx_ser = 0;
502 u8 rx_ser = 0;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200503 u8 slots = mcasp->tdm_slots;
Michal Bachraty2952b272013-02-28 16:07:08 +0100504 u8 max_active_serializers = (channels + slots - 1) / slots;
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300505 int active_serializers, numevt, n;
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200506 u32 reg;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400507 /* Default configuration */
Peter Ujfalusi40448e52014-04-04 15:56:30 +0300508 if (mcasp->version < MCASP_VERSION_3)
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200509 mcasp_set_bits(mcasp, DAVINCI_MCASP_PWREMUMGT_REG, MCASP_SOFT);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400510
511 /* All PINS as McASP */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200512 mcasp_set_reg(mcasp, DAVINCI_MCASP_PFUNC_REG, 0x00000000);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400513
514 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200515 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF);
516 mcasp_clr_bits(mcasp, DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400517 } else {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200518 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
519 mcasp_clr_bits(mcasp, DAVINCI_MCASP_REVTCTL_REG, RXDATADMADIS);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400520 }
521
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200522 for (i = 0; i < mcasp->num_serializer; i++) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200523 mcasp_set_bits(mcasp, DAVINCI_MCASP_XRSRCTL_REG(i),
524 mcasp->serial_dir[i]);
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200525 if (mcasp->serial_dir[i] == TX_MODE &&
Michal Bachraty2952b272013-02-28 16:07:08 +0100526 tx_ser < max_active_serializers) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200527 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AXR(i));
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400528 tx_ser++;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200529 } else if (mcasp->serial_dir[i] == RX_MODE &&
Michal Bachraty2952b272013-02-28 16:07:08 +0100530 rx_ser < max_active_serializers) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200531 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AXR(i));
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400532 rx_ser++;
Michal Bachraty2952b272013-02-28 16:07:08 +0100533 } else {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200534 mcasp_mod_bits(mcasp, DAVINCI_MCASP_XRSRCTL_REG(i),
535 SRMOD_INACTIVE, SRMOD_MASK);
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400536 }
537 }
538
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300539 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
540 active_serializers = tx_ser;
541 numevt = mcasp->txnumevt;
542 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
543 } else {
544 active_serializers = rx_ser;
545 numevt = mcasp->rxnumevt;
546 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
547 }
Daniel Mackecf327c2013-03-08 14:19:38 +0100548
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300549 if (active_serializers < max_active_serializers) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200550 dev_warn(mcasp->dev, "stream has more channels (%d) than are "
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300551 "enabled in mcasp (%d)\n", channels,
552 active_serializers * slots);
Daniel Mackecf327c2013-03-08 14:19:38 +0100553 return -EINVAL;
554 }
555
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300556 /* AFIFO is not in use */
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300557 if (!numevt) {
558 /* Configure the burst size for platform drivers */
Peter Ujfalusi33445642014-04-01 15:55:12 +0300559 if (active_serializers > 1) {
560 /*
561 * If more than one serializers are in use we have one
562 * DMA request to provide data for all serializers.
563 * For example if three serializers are enabled the DMA
564 * need to transfer three words per DMA request.
565 */
566 dma_params->fifo_level = active_serializers;
567 dma_data->maxburst = active_serializers;
568 } else {
569 dma_params->fifo_level = 0;
570 dma_data->maxburst = 0;
571 }
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300572 return 0;
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300573 }
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400574
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300575 if (period_words % active_serializers) {
576 dev_err(mcasp->dev, "Invalid combination of period words and "
577 "active serializers: %d, %d\n", period_words,
578 active_serializers);
579 return -EINVAL;
580 }
581
582 /*
583 * Calculate the optimal AFIFO depth for platform side:
584 * The number of words for numevt need to be in steps of active
585 * serializers.
586 */
587 n = numevt % active_serializers;
588 if (n)
589 numevt += (active_serializers - n);
590 while (period_words % numevt && numevt > 0)
591 numevt -= active_serializers;
592 if (numevt <= 0)
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300593 numevt = active_serializers;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400594
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300595 mcasp_mod_bits(mcasp, reg, active_serializers, NUMDMA_MASK);
596 mcasp_mod_bits(mcasp, reg, NUMEVT(numevt), NUMEVT_MASK);
Michal Bachraty2952b272013-02-28 16:07:08 +0100597
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300598 /* Configure the burst size for platform drivers */
Peter Ujfalusi33445642014-04-01 15:55:12 +0300599 if (numevt == 1)
600 numevt = 0;
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300601 dma_params->fifo_level = numevt;
602 dma_data->maxburst = numevt;
603
Michal Bachraty2952b272013-02-28 16:07:08 +0100604 return 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400605}
606
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200607static int mcasp_i2s_hw_param(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400608{
609 int i, active_slots;
610 u32 mask = 0;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200611 u32 busel = 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400612
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200613 if ((mcasp->tdm_slots < 2) || (mcasp->tdm_slots > 32)) {
614 dev_err(mcasp->dev, "tdm slot %d not supported\n",
615 mcasp->tdm_slots);
616 return -EINVAL;
617 }
618
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200619 active_slots = (mcasp->tdm_slots > 31) ? 32 : mcasp->tdm_slots;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400620 for (i = 0; i < active_slots; i++)
621 mask |= (1 << i);
622
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200623 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC);
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400624
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200625 if (!mcasp->dat_port)
626 busel = TXSEL;
627
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200628 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, mask);
629 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, busel | TXORD);
630 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG,
631 FSXMOD(mcasp->tdm_slots), FSXMOD(0x1FF));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400632
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200633 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXTDM_REG, mask);
634 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, busel | RXORD);
635 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG,
636 FSRMOD(mcasp->tdm_slots), FSRMOD(0x1FF));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400637
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200638 return 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400639}
640
641/* S/PDIF */
Daniel Mack64792852014-03-27 11:27:40 +0100642static int mcasp_dit_hw_param(struct davinci_mcasp *mcasp,
643 unsigned int rate)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400644{
Daniel Mack64792852014-03-27 11:27:40 +0100645 u32 cs_value = 0;
646 u8 *cs_bytes = (u8*) &cs_value;
647
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400648 /* Set the TX format : 24 bit right rotation, 32 bit slot, Pad 0
649 and LSB first */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200650 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXROT(6) | TXSSZ(15));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400651
652 /* Set TX frame synch : DIT Mode, 1 bit width, internal, rising edge */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200653 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE | FSXMOD(0x180));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400654
655 /* Set the TX tdm : for all the slots */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200656 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400657
658 /* Set the TX clock controls : div = 1 and internal */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200659 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE | TX_ASYNC);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400660
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200661 mcasp_clr_bits(mcasp, DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400662
663 /* Only 44100 and 48000 are valid, both have the same setting */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200664 mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXDIV(3));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400665
666 /* Enable the DIT */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200667 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXDITCTL_REG, DITEN);
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200668
Daniel Mack64792852014-03-27 11:27:40 +0100669 /* Set S/PDIF channel status bits */
670 cs_bytes[0] = IEC958_AES0_CON_NOT_COPYRIGHT;
671 cs_bytes[1] = IEC958_AES1_CON_PCM_CODER;
672
673 switch (rate) {
674 case 22050:
675 cs_bytes[3] |= IEC958_AES3_CON_FS_22050;
676 break;
677 case 24000:
678 cs_bytes[3] |= IEC958_AES3_CON_FS_24000;
679 break;
680 case 32000:
681 cs_bytes[3] |= IEC958_AES3_CON_FS_32000;
682 break;
683 case 44100:
684 cs_bytes[3] |= IEC958_AES3_CON_FS_44100;
685 break;
686 case 48000:
687 cs_bytes[3] |= IEC958_AES3_CON_FS_48000;
688 break;
689 case 88200:
690 cs_bytes[3] |= IEC958_AES3_CON_FS_88200;
691 break;
692 case 96000:
693 cs_bytes[3] |= IEC958_AES3_CON_FS_96000;
694 break;
695 case 176400:
696 cs_bytes[3] |= IEC958_AES3_CON_FS_176400;
697 break;
698 case 192000:
699 cs_bytes[3] |= IEC958_AES3_CON_FS_192000;
700 break;
701 default:
702 printk(KERN_WARNING "unsupported sampling rate: %d\n", rate);
703 return -EINVAL;
704 }
705
706 mcasp_set_reg(mcasp, DAVINCI_MCASP_DITCSRA_REG, cs_value);
707 mcasp_set_reg(mcasp, DAVINCI_MCASP_DITCSRB_REG, cs_value);
708
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200709 return 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400710}
711
712static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
713 struct snd_pcm_hw_params *params,
714 struct snd_soc_dai *cpu_dai)
715{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200716 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400717 struct davinci_pcm_dma_params *dma_params =
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200718 &mcasp->dma_params[substream->stream];
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400719 int word_length;
Peter Ujfalusia7e46bd2014-02-03 14:51:50 +0200720 int channels = params_channels(params);
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300721 int period_size = params_period_size(params);
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200722 int ret;
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200723
724 /* If mcasp is BCLK master we need to set BCLK divider */
Jyri Sarha09298782014-06-13 12:50:00 +0300725 if (mcasp->bclk_master && mcasp->sysclk_freq) {
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200726 unsigned int bclk_freq = snd_soc_params_to_bclk(params);
Jyri Sarha09298782014-06-13 12:50:00 +0300727 unsigned int div = mcasp->sysclk_freq / bclk_freq;
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200728 if (mcasp->sysclk_freq % bclk_freq != 0) {
Jyri Sarha09298782014-06-13 12:50:00 +0300729 if (((mcasp->sysclk_freq / div) - bclk_freq) >
730 (bclk_freq - (mcasp->sysclk_freq / (div+1))))
731 div++;
732 dev_warn(mcasp->dev,
733 "Inaccurate BCLK: %u Hz / %u != %u Hz\n",
734 mcasp->sysclk_freq, div, bclk_freq);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200735 }
Jyri Sarha09298782014-06-13 12:50:00 +0300736 davinci_mcasp_set_clkdiv(cpu_dai, 1, div);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200737 }
738
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300739 ret = mcasp_common_hw_param(mcasp, substream->stream,
740 period_size * channels, channels);
Peter Ujfalusi0f7d9a62014-01-30 15:15:24 +0200741 if (ret)
742 return ret;
743
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200744 if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE)
Daniel Mack64792852014-03-27 11:27:40 +0100745 ret = mcasp_dit_hw_param(mcasp, params_rate(params));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400746 else
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200747 ret = mcasp_i2s_hw_param(mcasp, substream->stream);
748
749 if (ret)
750 return ret;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400751
752 switch (params_format(params)) {
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400753 case SNDRV_PCM_FORMAT_U8:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400754 case SNDRV_PCM_FORMAT_S8:
755 dma_params->data_type = 1;
Daniel Mackba764b32012-12-05 18:20:37 +0100756 word_length = 8;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400757 break;
758
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400759 case SNDRV_PCM_FORMAT_U16_LE:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400760 case SNDRV_PCM_FORMAT_S16_LE:
761 dma_params->data_type = 2;
Daniel Mackba764b32012-12-05 18:20:37 +0100762 word_length = 16;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400763 break;
764
Daniel Mack21eb24d2012-10-09 09:35:16 +0200765 case SNDRV_PCM_FORMAT_U24_3LE:
766 case SNDRV_PCM_FORMAT_S24_3LE:
Daniel Mack21eb24d2012-10-09 09:35:16 +0200767 dma_params->data_type = 3;
Daniel Mackba764b32012-12-05 18:20:37 +0100768 word_length = 24;
Daniel Mack21eb24d2012-10-09 09:35:16 +0200769 break;
770
Daniel Mack6b7fa012012-10-09 11:56:40 +0200771 case SNDRV_PCM_FORMAT_U24_LE:
772 case SNDRV_PCM_FORMAT_S24_LE:
Peter Ujfalusi182bef82014-06-26 08:09:24 +0300773 dma_params->data_type = 4;
774 word_length = 24;
775 break;
776
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400777 case SNDRV_PCM_FORMAT_U32_LE:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400778 case SNDRV_PCM_FORMAT_S32_LE:
779 dma_params->data_type = 4;
Daniel Mackba764b32012-12-05 18:20:37 +0100780 word_length = 32;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400781 break;
782
783 default:
784 printk(KERN_WARNING "davinci-mcasp: unsupported PCM format");
785 return -EINVAL;
786 }
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400787
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300788 if (mcasp->version == MCASP_VERSION_2 && !dma_params->fifo_level)
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400789 dma_params->acnt = 4;
790 else
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400791 dma_params->acnt = dma_params->data_type;
792
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200793 davinci_config_channel_size(mcasp, word_length);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400794
795 return 0;
796}
797
798static int davinci_mcasp_trigger(struct snd_pcm_substream *substream,
799 int cmd, struct snd_soc_dai *cpu_dai)
800{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200801 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400802 int ret = 0;
803
804 switch (cmd) {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400805 case SNDRV_PCM_TRIGGER_RESUME:
Chaithrika U Se473b842010-01-20 17:06:33 +0530806 case SNDRV_PCM_TRIGGER_START:
807 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200808 davinci_mcasp_start(mcasp, substream->stream);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400809 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400810 case SNDRV_PCM_TRIGGER_SUSPEND:
Chaithrika U Sa47979b2009-12-03 18:56:56 +0530811 case SNDRV_PCM_TRIGGER_STOP:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400812 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200813 davinci_mcasp_stop(mcasp, substream->stream);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400814 break;
815
816 default:
817 ret = -EINVAL;
818 }
819
820 return ret;
821}
822
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100823static const struct snd_soc_dai_ops davinci_mcasp_dai_ops = {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400824 .trigger = davinci_mcasp_trigger,
825 .hw_params = davinci_mcasp_hw_params,
826 .set_fmt = davinci_mcasp_set_dai_fmt,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200827 .set_clkdiv = davinci_mcasp_set_clkdiv,
Daniel Mack5b66aa22012-10-04 15:08:41 +0200828 .set_sysclk = davinci_mcasp_set_sysclk,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400829};
830
Peter Ujfalusid5902f62014-04-01 15:55:07 +0300831static int davinci_mcasp_dai_probe(struct snd_soc_dai *dai)
832{
833 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
834
Peter Ujfalusif3f9cfa2014-07-16 15:12:04 +0300835 if (mcasp->version >= MCASP_VERSION_3) {
Peter Ujfalusid5902f62014-04-01 15:55:07 +0300836 /* Using dmaengine PCM */
837 dai->playback_dma_data =
838 &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
839 dai->capture_dma_data =
840 &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE];
841 } else {
842 /* Using davinci-pcm */
843 dai->playback_dma_data = mcasp->dma_params;
844 dai->capture_dma_data = mcasp->dma_params;
845 }
846
847 return 0;
848}
849
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200850#ifdef CONFIG_PM_SLEEP
851static int davinci_mcasp_suspend(struct snd_soc_dai *dai)
852{
853 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Peter Ujfalusi790bb942014-02-03 14:51:52 +0200854 struct davinci_mcasp_context *context = &mcasp->context;
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200855
Peter Ujfalusi790bb942014-02-03 14:51:52 +0200856 context->txfmtctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG);
857 context->rxfmtctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG);
858 context->txfmt = mcasp_get_reg(mcasp, DAVINCI_MCASP_TXFMT_REG);
859 context->rxfmt = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMT_REG);
860 context->aclkxctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG);
861 context->aclkrctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKRCTL_REG);
862 context->pdir = mcasp_get_reg(mcasp, DAVINCI_MCASP_PDIR_REG);
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200863
864 return 0;
865}
866
867static int davinci_mcasp_resume(struct snd_soc_dai *dai)
868{
869 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Peter Ujfalusi790bb942014-02-03 14:51:52 +0200870 struct davinci_mcasp_context *context = &mcasp->context;
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200871
Peter Ujfalusi790bb942014-02-03 14:51:52 +0200872 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG, context->txfmtctl);
873 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG, context->rxfmtctl);
874 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMT_REG, context->txfmt);
875 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXFMT_REG, context->rxfmt);
876 mcasp_set_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, context->aclkxctl);
877 mcasp_set_reg(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, context->aclkrctl);
878 mcasp_set_reg(mcasp, DAVINCI_MCASP_PDIR_REG, context->pdir);
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200879
880 return 0;
881}
882#else
883#define davinci_mcasp_suspend NULL
884#define davinci_mcasp_resume NULL
885#endif
886
Peter Ujfalusied29cd52013-11-14 11:35:22 +0200887#define DAVINCI_MCASP_RATES SNDRV_PCM_RATE_8000_192000
888
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400889#define DAVINCI_MCASP_PCM_FMTS (SNDRV_PCM_FMTBIT_S8 | \
890 SNDRV_PCM_FMTBIT_U8 | \
891 SNDRV_PCM_FMTBIT_S16_LE | \
892 SNDRV_PCM_FMTBIT_U16_LE | \
Daniel Mack21eb24d2012-10-09 09:35:16 +0200893 SNDRV_PCM_FMTBIT_S24_LE | \
894 SNDRV_PCM_FMTBIT_U24_LE | \
895 SNDRV_PCM_FMTBIT_S24_3LE | \
896 SNDRV_PCM_FMTBIT_U24_3LE | \
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400897 SNDRV_PCM_FMTBIT_S32_LE | \
898 SNDRV_PCM_FMTBIT_U32_LE)
899
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000900static struct snd_soc_dai_driver davinci_mcasp_dai[] = {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400901 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000902 .name = "davinci-mcasp.0",
Peter Ujfalusid5902f62014-04-01 15:55:07 +0300903 .probe = davinci_mcasp_dai_probe,
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200904 .suspend = davinci_mcasp_suspend,
905 .resume = davinci_mcasp_resume,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400906 .playback = {
907 .channels_min = 2,
Michal Bachraty2952b272013-02-28 16:07:08 +0100908 .channels_max = 32 * 16,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400909 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400910 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400911 },
912 .capture = {
913 .channels_min = 2,
Michal Bachraty2952b272013-02-28 16:07:08 +0100914 .channels_max = 32 * 16,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400915 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400916 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400917 },
918 .ops = &davinci_mcasp_dai_ops,
919
920 },
921 {
Peter Ujfalusi58e48d92013-11-14 11:35:24 +0200922 .name = "davinci-mcasp.1",
Peter Ujfalusid5902f62014-04-01 15:55:07 +0300923 .probe = davinci_mcasp_dai_probe,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400924 .playback = {
925 .channels_min = 1,
926 .channels_max = 384,
927 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400928 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400929 },
930 .ops = &davinci_mcasp_dai_ops,
931 },
932
933};
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400934
Kuninori Morimotoeeef0ed2013-03-21 03:31:19 -0700935static const struct snd_soc_component_driver davinci_mcasp_component = {
936 .name = "davinci-mcasp",
937};
938
Jyri Sarha256ba182013-10-18 18:37:42 +0300939/* Some HW specific values and defaults. The rest is filled in from DT. */
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200940static struct davinci_mcasp_pdata dm646x_mcasp_pdata = {
Jyri Sarha256ba182013-10-18 18:37:42 +0300941 .tx_dma_offset = 0x400,
942 .rx_dma_offset = 0x400,
943 .asp_chan_q = EVENTQ_0,
944 .version = MCASP_VERSION_1,
945};
946
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200947static struct davinci_mcasp_pdata da830_mcasp_pdata = {
Jyri Sarha256ba182013-10-18 18:37:42 +0300948 .tx_dma_offset = 0x2000,
949 .rx_dma_offset = 0x2000,
950 .asp_chan_q = EVENTQ_0,
951 .version = MCASP_VERSION_2,
952};
953
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200954static struct davinci_mcasp_pdata am33xx_mcasp_pdata = {
Jyri Sarha256ba182013-10-18 18:37:42 +0300955 .tx_dma_offset = 0,
956 .rx_dma_offset = 0,
957 .asp_chan_q = EVENTQ_0,
958 .version = MCASP_VERSION_3,
959};
960
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200961static struct davinci_mcasp_pdata dra7_mcasp_pdata = {
Peter Ujfalusi453c4992013-11-14 11:35:34 +0200962 .tx_dma_offset = 0x200,
963 .rx_dma_offset = 0x284,
964 .asp_chan_q = EVENTQ_0,
965 .version = MCASP_VERSION_4,
966};
967
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530968static const struct of_device_id mcasp_dt_ids[] = {
969 {
970 .compatible = "ti,dm646x-mcasp-audio",
Jyri Sarha256ba182013-10-18 18:37:42 +0300971 .data = &dm646x_mcasp_pdata,
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530972 },
973 {
974 .compatible = "ti,da830-mcasp-audio",
Jyri Sarha256ba182013-10-18 18:37:42 +0300975 .data = &da830_mcasp_pdata,
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530976 },
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530977 {
Jyri Sarha3af9e032013-10-18 18:37:44 +0300978 .compatible = "ti,am33xx-mcasp-audio",
Peter Ujfalusib14899d2013-11-14 11:35:37 +0200979 .data = &am33xx_mcasp_pdata,
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530980 },
Peter Ujfalusi453c4992013-11-14 11:35:34 +0200981 {
982 .compatible = "ti,dra7-mcasp-audio",
983 .data = &dra7_mcasp_pdata,
984 },
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530985 { /* sentinel */ }
986};
987MODULE_DEVICE_TABLE(of, mcasp_dt_ids);
988
Peter Ujfalusiae726e92013-11-14 11:35:35 +0200989static int mcasp_reparent_fck(struct platform_device *pdev)
990{
991 struct device_node *node = pdev->dev.of_node;
992 struct clk *gfclk, *parent_clk;
993 const char *parent_name;
994 int ret;
995
996 if (!node)
997 return 0;
998
999 parent_name = of_get_property(node, "fck_parent", NULL);
1000 if (!parent_name)
1001 return 0;
1002
1003 gfclk = clk_get(&pdev->dev, "fck");
1004 if (IS_ERR(gfclk)) {
1005 dev_err(&pdev->dev, "failed to get fck\n");
1006 return PTR_ERR(gfclk);
1007 }
1008
1009 parent_clk = clk_get(NULL, parent_name);
1010 if (IS_ERR(parent_clk)) {
1011 dev_err(&pdev->dev, "failed to get parent clock\n");
1012 ret = PTR_ERR(parent_clk);
1013 goto err1;
1014 }
1015
1016 ret = clk_set_parent(gfclk, parent_clk);
1017 if (ret) {
1018 dev_err(&pdev->dev, "failed to reparent fck\n");
1019 goto err2;
1020 }
1021
1022err2:
1023 clk_put(parent_clk);
1024err1:
1025 clk_put(gfclk);
1026 return ret;
1027}
1028
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001029static struct davinci_mcasp_pdata *davinci_mcasp_set_pdata_from_of(
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301030 struct platform_device *pdev)
1031{
1032 struct device_node *np = pdev->dev.of_node;
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001033 struct davinci_mcasp_pdata *pdata = NULL;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301034 const struct of_device_id *match =
Sachin Kamatea421eb2013-05-22 16:53:37 +05301035 of_match_device(mcasp_dt_ids, &pdev->dev);
Jyri Sarha4023fe62013-10-18 18:37:43 +03001036 struct of_phandle_args dma_spec;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301037
1038 const u32 *of_serial_dir32;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301039 u32 val;
1040 int i, ret = 0;
1041
1042 if (pdev->dev.platform_data) {
1043 pdata = pdev->dev.platform_data;
1044 return pdata;
1045 } else if (match) {
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001046 pdata = (struct davinci_mcasp_pdata*) match->data;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301047 } else {
1048 /* control shouldn't reach here. something is wrong */
1049 ret = -EINVAL;
1050 goto nodata;
1051 }
1052
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301053 ret = of_property_read_u32(np, "op-mode", &val);
1054 if (ret >= 0)
1055 pdata->op_mode = val;
1056
1057 ret = of_property_read_u32(np, "tdm-slots", &val);
Michal Bachraty2952b272013-02-28 16:07:08 +01001058 if (ret >= 0) {
1059 if (val < 2 || val > 32) {
1060 dev_err(&pdev->dev,
1061 "tdm-slots must be in rage [2-32]\n");
1062 ret = -EINVAL;
1063 goto nodata;
1064 }
1065
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301066 pdata->tdm_slots = val;
Michal Bachraty2952b272013-02-28 16:07:08 +01001067 }
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301068
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301069 of_serial_dir32 = of_get_property(np, "serial-dir", &val);
1070 val /= sizeof(u32);
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301071 if (of_serial_dir32) {
Peter Ujfalusi1427e662013-10-18 18:37:46 +03001072 u8 *of_serial_dir = devm_kzalloc(&pdev->dev,
1073 (sizeof(*of_serial_dir) * val),
1074 GFP_KERNEL);
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301075 if (!of_serial_dir) {
1076 ret = -ENOMEM;
1077 goto nodata;
1078 }
1079
Peter Ujfalusi1427e662013-10-18 18:37:46 +03001080 for (i = 0; i < val; i++)
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301081 of_serial_dir[i] = be32_to_cpup(&of_serial_dir32[i]);
1082
Peter Ujfalusi1427e662013-10-18 18:37:46 +03001083 pdata->num_serializer = val;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301084 pdata->serial_dir = of_serial_dir;
1085 }
1086
Jyri Sarha4023fe62013-10-18 18:37:43 +03001087 ret = of_property_match_string(np, "dma-names", "tx");
1088 if (ret < 0)
1089 goto nodata;
1090
1091 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
1092 &dma_spec);
1093 if (ret < 0)
1094 goto nodata;
1095
1096 pdata->tx_dma_channel = dma_spec.args[0];
1097
1098 ret = of_property_match_string(np, "dma-names", "rx");
1099 if (ret < 0)
1100 goto nodata;
1101
1102 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
1103 &dma_spec);
1104 if (ret < 0)
1105 goto nodata;
1106
1107 pdata->rx_dma_channel = dma_spec.args[0];
1108
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301109 ret = of_property_read_u32(np, "tx-num-evt", &val);
1110 if (ret >= 0)
1111 pdata->txnumevt = val;
1112
1113 ret = of_property_read_u32(np, "rx-num-evt", &val);
1114 if (ret >= 0)
1115 pdata->rxnumevt = val;
1116
1117 ret = of_property_read_u32(np, "sram-size-playback", &val);
1118 if (ret >= 0)
1119 pdata->sram_size_playback = val;
1120
1121 ret = of_property_read_u32(np, "sram-size-capture", &val);
1122 if (ret >= 0)
1123 pdata->sram_size_capture = val;
1124
1125 return pdata;
1126
1127nodata:
1128 if (ret < 0) {
1129 dev_err(&pdev->dev, "Error populating platform data, err %d\n",
1130 ret);
1131 pdata = NULL;
1132 }
1133 return pdata;
1134}
1135
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001136static int davinci_mcasp_probe(struct platform_device *pdev)
1137{
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001138 struct davinci_pcm_dma_params *dma_params;
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001139 struct snd_dmaengine_dai_dma_data *dma_data;
Jyri Sarha256ba182013-10-18 18:37:42 +03001140 struct resource *mem, *ioarea, *res, *dat;
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001141 struct davinci_mcasp_pdata *pdata;
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001142 struct davinci_mcasp *mcasp;
Julia Lawall96d31e22011-12-29 17:51:21 +01001143 int ret;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001144
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301145 if (!pdev->dev.platform_data && !pdev->dev.of_node) {
1146 dev_err(&pdev->dev, "No platform data supplied\n");
1147 return -EINVAL;
1148 }
1149
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001150 mcasp = devm_kzalloc(&pdev->dev, sizeof(struct davinci_mcasp),
Julia Lawall96d31e22011-12-29 17:51:21 +01001151 GFP_KERNEL);
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001152 if (!mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001153 return -ENOMEM;
1154
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301155 pdata = davinci_mcasp_set_pdata_from_of(pdev);
1156 if (!pdata) {
1157 dev_err(&pdev->dev, "no platform data\n");
1158 return -EINVAL;
1159 }
1160
Jyri Sarha256ba182013-10-18 18:37:42 +03001161 mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001162 if (!mem) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001163 dev_warn(mcasp->dev,
Jyri Sarha256ba182013-10-18 18:37:42 +03001164 "\"mpu\" mem resource not found, using index 0\n");
1165 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1166 if (!mem) {
1167 dev_err(&pdev->dev, "no mem resource?\n");
1168 return -ENODEV;
1169 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001170 }
1171
Julia Lawall96d31e22011-12-29 17:51:21 +01001172 ioarea = devm_request_mem_region(&pdev->dev, mem->start,
Vaibhav Bediad852f4462011-02-09 18:39:52 +05301173 resource_size(mem), pdev->name);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001174 if (!ioarea) {
1175 dev_err(&pdev->dev, "Audio region already claimed\n");
Julia Lawall96d31e22011-12-29 17:51:21 +01001176 return -EBUSY;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001177 }
1178
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301179 pm_runtime_enable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001180
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301181 ret = pm_runtime_get_sync(&pdev->dev);
1182 if (IS_ERR_VALUE(ret)) {
1183 dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
1184 return ret;
1185 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001186
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001187 mcasp->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
1188 if (!mcasp->base) {
Vaibhav Bedia4f82f022011-02-09 18:39:54 +05301189 dev_err(&pdev->dev, "ioremap failed\n");
1190 ret = -ENOMEM;
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001191 goto err;
Vaibhav Bedia4f82f022011-02-09 18:39:54 +05301192 }
1193
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001194 mcasp->op_mode = pdata->op_mode;
1195 mcasp->tdm_slots = pdata->tdm_slots;
1196 mcasp->num_serializer = pdata->num_serializer;
1197 mcasp->serial_dir = pdata->serial_dir;
1198 mcasp->version = pdata->version;
1199 mcasp->txnumevt = pdata->txnumevt;
1200 mcasp->rxnumevt = pdata->rxnumevt;
Peter Ujfalusi487dce82013-11-14 11:35:31 +02001201
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001202 mcasp->dev = &pdev->dev;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001203
Jyri Sarha256ba182013-10-18 18:37:42 +03001204 dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001205 if (dat)
1206 mcasp->dat_port = true;
Jyri Sarha256ba182013-10-18 18:37:42 +03001207
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001208 dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_PLAYBACK];
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001209 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001210 dma_params->asp_chan_q = pdata->asp_chan_q;
1211 dma_params->ram_chan_q = pdata->ram_chan_q;
1212 dma_params->sram_pool = pdata->sram_pool;
1213 dma_params->sram_size = pdata->sram_size_playback;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001214 if (dat)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001215 dma_params->dma_addr = dat->start;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001216 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001217 dma_params->dma_addr = mem->start + pdata->tx_dma_offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001218
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001219 /* Unconditional dmaengine stuff */
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001220 dma_data->addr = dma_params->dma_addr;
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001221
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001222 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
Jyri Sarha4023fe62013-10-18 18:37:43 +03001223 if (res)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001224 dma_params->channel = res->start;
Jyri Sarha4023fe62013-10-18 18:37:43 +03001225 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001226 dma_params->channel = pdata->tx_dma_channel;
Troy Kisky92e2a6f2009-09-11 14:29:03 -07001227
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001228 /* dmaengine filter data for DT and non-DT boot */
1229 if (pdev->dev.of_node)
1230 dma_data->filter_data = "tx";
1231 else
1232 dma_data->filter_data = &dma_params->channel;
1233
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001234 dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_CAPTURE];
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001235 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE];
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001236 dma_params->asp_chan_q = pdata->asp_chan_q;
1237 dma_params->ram_chan_q = pdata->ram_chan_q;
1238 dma_params->sram_pool = pdata->sram_pool;
1239 dma_params->sram_size = pdata->sram_size_capture;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001240 if (dat)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001241 dma_params->dma_addr = dat->start;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001242 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001243 dma_params->dma_addr = mem->start + pdata->rx_dma_offset;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001244
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001245 /* Unconditional dmaengine stuff */
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001246 dma_data->addr = dma_params->dma_addr;
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001247
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001248 if (mcasp->version < MCASP_VERSION_3) {
1249 mcasp->fifo_base = DAVINCI_MCASP_V2_AFIFO_BASE;
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001250 /* dma_params->dma_addr is pointing to the data port address */
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001251 mcasp->dat_port = true;
1252 } else {
1253 mcasp->fifo_base = DAVINCI_MCASP_V3_AFIFO_BASE;
1254 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001255
1256 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
Jyri Sarha4023fe62013-10-18 18:37:43 +03001257 if (res)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001258 dma_params->channel = res->start;
Jyri Sarha4023fe62013-10-18 18:37:43 +03001259 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001260 dma_params->channel = pdata->rx_dma_channel;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001261
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001262 /* dmaengine filter data for DT and non-DT boot */
1263 if (pdev->dev.of_node)
1264 dma_data->filter_data = "rx";
1265 else
1266 dma_data->filter_data = &dma_params->channel;
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001267
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001268 dev_set_drvdata(&pdev->dev, mcasp);
Peter Ujfalusiae726e92013-11-14 11:35:35 +02001269
1270 mcasp_reparent_fck(pdev);
1271
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001272 ret = devm_snd_soc_register_component(&pdev->dev,
1273 &davinci_mcasp_component,
1274 &davinci_mcasp_dai[pdata->op_mode], 1);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001275
1276 if (ret != 0)
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001277 goto err;
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +05301278
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001279 switch (mcasp->version) {
Jyri Sarha7f28f352014-06-13 12:49:59 +03001280#if IS_BUILTIN(CONFIG_SND_DAVINCI_SOC) || \
1281 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \
1282 IS_MODULE(CONFIG_SND_DAVINCI_SOC))
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001283 case MCASP_VERSION_1:
1284 case MCASP_VERSION_2:
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001285 ret = davinci_soc_platform_register(&pdev->dev);
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001286 break;
Jyri Sarha7f28f352014-06-13 12:49:59 +03001287#endif
Peter Ujfalusif3f9cfa2014-07-16 15:12:04 +03001288#if IS_BUILTIN(CONFIG_SND_EDMA_SOC) || \
1289 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \
1290 IS_MODULE(CONFIG_SND_EDMA_SOC))
1291 case MCASP_VERSION_3:
1292 ret = edma_pcm_platform_register(&pdev->dev);
1293 break;
1294#endif
Jyri Sarha7f28f352014-06-13 12:49:59 +03001295#if IS_BUILTIN(CONFIG_SND_OMAP_SOC) || \
1296 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \
1297 IS_MODULE(CONFIG_SND_OMAP_SOC))
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001298 case MCASP_VERSION_4:
1299 ret = omap_pcm_platform_register(&pdev->dev);
1300 break;
Jyri Sarha7f28f352014-06-13 12:49:59 +03001301#endif
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001302 default:
1303 dev_err(&pdev->dev, "Invalid McASP version: %d\n",
1304 mcasp->version);
1305 ret = -EINVAL;
1306 break;
1307 }
1308
1309 if (ret) {
1310 dev_err(&pdev->dev, "register PCM failed: %d\n", ret);
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001311 goto err;
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +05301312 }
1313
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001314 return 0;
1315
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001316err:
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301317 pm_runtime_put_sync(&pdev->dev);
1318 pm_runtime_disable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001319 return ret;
1320}
1321
1322static int davinci_mcasp_remove(struct platform_device *pdev)
1323{
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301324 pm_runtime_put_sync(&pdev->dev);
1325 pm_runtime_disable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001326
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001327 return 0;
1328}
1329
1330static struct platform_driver davinci_mcasp_driver = {
1331 .probe = davinci_mcasp_probe,
1332 .remove = davinci_mcasp_remove,
1333 .driver = {
1334 .name = "davinci-mcasp",
1335 .owner = THIS_MODULE,
Sachin Kamatea421eb2013-05-22 16:53:37 +05301336 .of_match_table = mcasp_dt_ids,
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001337 },
1338};
1339
Axel Linf9b8a512011-11-25 10:09:27 +08001340module_platform_driver(davinci_mcasp_driver);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001341
1342MODULE_AUTHOR("Steve Chen");
1343MODULE_DESCRIPTION("TI DAVINCI McASP SoC Interface");
1344MODULE_LICENSE("GPL");