blob: 63e24449eb8959f606222a207b7e5e9bf848664a [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 Ujfalusi1cc0c052014-10-01 16:02:11 +030045static u32 context_regs[] = {
46 DAVINCI_MCASP_TXFMCTL_REG,
47 DAVINCI_MCASP_RXFMCTL_REG,
48 DAVINCI_MCASP_TXFMT_REG,
49 DAVINCI_MCASP_RXFMT_REG,
50 DAVINCI_MCASP_ACLKXCTL_REG,
51 DAVINCI_MCASP_ACLKRCTL_REG,
52 DAVINCI_MCASP_PDIR_REG,
53};
54
Peter Ujfalusi790bb942014-02-03 14:51:52 +020055struct davinci_mcasp_context {
Peter Ujfalusi1cc0c052014-10-01 16:02:11 +030056 u32 config_regs[ARRAY_SIZE(context_regs)];
Peter Ujfalusi790bb942014-02-03 14:51:52 +020057};
58
Peter Ujfalusi70091a32013-11-14 11:35:29 +020059struct davinci_mcasp {
Peter Ujfalusi21400a72013-11-14 11:35:26 +020060 struct davinci_pcm_dma_params dma_params[2];
Peter Ujfalusi453c4992013-11-14 11:35:34 +020061 struct snd_dmaengine_dai_dma_data dma_data[2];
Peter Ujfalusi21400a72013-11-14 11:35:26 +020062 void __iomem *base;
Peter Ujfalusi487dce82013-11-14 11:35:31 +020063 u32 fifo_base;
Peter Ujfalusi21400a72013-11-14 11:35:26 +020064 struct device *dev;
65
66 /* McASP specific data */
67 int tdm_slots;
68 u8 op_mode;
69 u8 num_serializer;
70 u8 *serial_dir;
71 u8 version;
Daniel Mack82675252014-07-16 14:04:41 +020072 u8 bclk_div;
Peter Ujfalusi21400a72013-11-14 11:35:26 +020073 u16 bclk_lrclk_ratio;
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +020074 int streams;
Peter Ujfalusi21400a72013-11-14 11:35:26 +020075
Jyri Sarhaab8b14b2014-01-27 17:37:52 +020076 int sysclk_freq;
77 bool bclk_master;
78
Peter Ujfalusi21400a72013-11-14 11:35:26 +020079 /* McASP FIFO related */
80 u8 txnumevt;
81 u8 rxnumevt;
82
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +020083 bool dat_port;
84
Peter Ujfalusi21400a72013-11-14 11:35:26 +020085#ifdef CONFIG_PM_SLEEP
Peter Ujfalusi790bb942014-02-03 14:51:52 +020086 struct davinci_mcasp_context context;
Peter Ujfalusi21400a72013-11-14 11:35:26 +020087#endif
88};
89
Peter Ujfalusif68205a2013-11-14 11:35:36 +020090static inline void mcasp_set_bits(struct davinci_mcasp *mcasp, u32 offset,
91 u32 val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -040092{
Peter Ujfalusif68205a2013-11-14 11:35:36 +020093 void __iomem *reg = mcasp->base + offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -040094 __raw_writel(__raw_readl(reg) | val, reg);
95}
96
Peter Ujfalusif68205a2013-11-14 11:35:36 +020097static inline void mcasp_clr_bits(struct davinci_mcasp *mcasp, u32 offset,
98 u32 val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -040099{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200100 void __iomem *reg = mcasp->base + offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400101 __raw_writel((__raw_readl(reg) & ~(val)), reg);
102}
103
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200104static inline void mcasp_mod_bits(struct davinci_mcasp *mcasp, u32 offset,
105 u32 val, u32 mask)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400106{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200107 void __iomem *reg = mcasp->base + offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400108 __raw_writel((__raw_readl(reg) & ~mask) | val, reg);
109}
110
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200111static inline void mcasp_set_reg(struct davinci_mcasp *mcasp, u32 offset,
112 u32 val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400113{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200114 __raw_writel(val, mcasp->base + offset);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400115}
116
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200117static inline u32 mcasp_get_reg(struct davinci_mcasp *mcasp, u32 offset)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400118{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200119 return (u32)__raw_readl(mcasp->base + offset);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400120}
121
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200122static void mcasp_set_ctl_reg(struct davinci_mcasp *mcasp, u32 ctl_reg, u32 val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400123{
124 int i = 0;
125
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200126 mcasp_set_bits(mcasp, ctl_reg, val);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400127
128 /* programming GBLCTL needs to read back from GBLCTL and verfiy */
129 /* loop count is to avoid the lock-up */
130 for (i = 0; i < 1000; i++) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200131 if ((mcasp_get_reg(mcasp, ctl_reg) & val) == val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400132 break;
133 }
134
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200135 if (i == 1000 && ((mcasp_get_reg(mcasp, ctl_reg) & val) != val))
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400136 printk(KERN_ERR "GBLCTL write error\n");
137}
138
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200139static bool mcasp_is_synchronous(struct davinci_mcasp *mcasp)
140{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200141 u32 rxfmctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG);
142 u32 aclkxctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200143
144 return !(aclkxctl & TX_ASYNC) && rxfmctl & AFSRE;
145}
146
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200147static void mcasp_start_rx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400148{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200149 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXHCLKRST);
150 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXCLKRST);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200151
152 /*
153 * When ASYNC == 0 the transmit and receive sections operate
154 * synchronously from the transmit clock and frame sync. We need to make
155 * sure that the TX signlas are enabled when starting reception.
156 */
157 if (mcasp_is_synchronous(mcasp)) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200158 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST);
159 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200160 }
161
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200162 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSERCLR);
163 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400164
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200165 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSMRST);
166 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXFSRST);
167 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400168
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200169 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSMRST);
170 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXFSRST);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200171
172 if (mcasp_is_synchronous(mcasp))
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200173 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXFSRST);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400174}
175
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200176static void mcasp_start_tx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400177{
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400178 u8 offset = 0, i;
179 u32 cnt;
180
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200181 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST);
182 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
183 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXSERCLR);
184 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400185
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200186 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXSMRST);
187 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXFSRST);
188 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXBUF_REG, 0);
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200189 for (i = 0; i < mcasp->num_serializer; i++) {
190 if (mcasp->serial_dir[i] == TX_MODE) {
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400191 offset = i;
192 break;
193 }
194 }
195
196 /* wait for TX ready */
197 cnt = 0;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200198 while (!(mcasp_get_reg(mcasp, DAVINCI_MCASP_XRSRCTL_REG(offset)) &
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400199 TXSTATE) && (cnt < 100000))
200 cnt++;
201
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200202 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400203}
204
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200205static void davinci_mcasp_start(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400206{
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200207 u32 reg;
208
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200209 mcasp->streams++;
210
Chaithrika U S539d3d82009-09-23 10:12:08 -0400211 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200212 if (mcasp->txnumevt) { /* enable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200213 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200214 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
215 mcasp_set_bits(mcasp, reg, FIFO_ENABLE);
Vaibhav Bedia0d624272012-08-08 20:40:31 +0530216 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200217 mcasp_start_tx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400218 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200219 if (mcasp->rxnumevt) { /* enable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200220 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200221 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
222 mcasp_set_bits(mcasp, reg, FIFO_ENABLE);
Vaibhav Bedia0d624272012-08-08 20:40:31 +0530223 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200224 mcasp_start_rx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400225 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400226}
227
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200228static void mcasp_stop_rx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400229{
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200230 /*
231 * In synchronous mode stop the TX clocks if no other stream is
232 * running
233 */
234 if (mcasp_is_synchronous(mcasp) && !mcasp->streams)
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200235 mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, 0);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200236
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200237 mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, 0);
238 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400239}
240
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200241static void mcasp_stop_tx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400242{
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200243 u32 val = 0;
244
245 /*
246 * In synchronous mode keep TX clocks running if the capture stream is
247 * still running.
248 */
249 if (mcasp_is_synchronous(mcasp) && mcasp->streams)
250 val = TXHCLKRST | TXCLKRST | TXFSRST;
251
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200252 mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, val);
253 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400254}
255
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200256static void davinci_mcasp_stop(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400257{
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200258 u32 reg;
259
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200260 mcasp->streams--;
261
Chaithrika U S539d3d82009-09-23 10:12:08 -0400262 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200263 if (mcasp->txnumevt) { /* disable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200264 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200265 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530266 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200267 mcasp_stop_tx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400268 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200269 if (mcasp->rxnumevt) { /* disable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200270 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200271 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530272 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200273 mcasp_stop_rx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400274 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400275}
276
277static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
278 unsigned int fmt)
279{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200280 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200281 int ret = 0;
Peter Ujfalusi6dfa9a42014-04-04 14:31:42 +0300282 u32 data_delay;
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300283 bool fs_pol_rising;
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300284 bool inv_fs = false;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400285
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200286 pm_runtime_get_sync(mcasp->dev);
Daniel Mack5296cf22012-10-04 15:08:42 +0200287 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
Peter Ujfalusi188edc52014-04-04 14:31:43 +0300288 case SND_SOC_DAIFMT_DSP_A:
289 mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
290 mcasp_clr_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
Peter Ujfalusi188edc52014-04-04 14:31:43 +0300291 /* 1st data bit occur one ACLK cycle after the frame sync */
292 data_delay = 1;
293 break;
Daniel Mack5296cf22012-10-04 15:08:42 +0200294 case SND_SOC_DAIFMT_DSP_B:
295 case SND_SOC_DAIFMT_AC97:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200296 mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
297 mcasp_clr_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
Peter Ujfalusi6dfa9a42014-04-04 14:31:42 +0300298 /* No delay after FS */
299 data_delay = 0;
Daniel Mack5296cf22012-10-04 15:08:42 +0200300 break;
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300301 case SND_SOC_DAIFMT_I2S:
Daniel Mack5296cf22012-10-04 15:08:42 +0200302 /* configure a full-word SYNC pulse (LRCLK) */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200303 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
304 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
Peter Ujfalusi6dfa9a42014-04-04 14:31:42 +0300305 /* 1st data bit occur one ACLK cycle after the frame sync */
306 data_delay = 1;
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300307 /* FS need to be inverted */
308 inv_fs = true;
Daniel Mack5296cf22012-10-04 15:08:42 +0200309 break;
Peter Ujfalusi423761e2014-04-04 14:31:46 +0300310 case SND_SOC_DAIFMT_LEFT_J:
311 /* configure a full-word SYNC pulse (LRCLK) */
312 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
313 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
314 /* No delay after FS */
315 data_delay = 0;
316 break;
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300317 default:
318 ret = -EINVAL;
319 goto out;
Daniel Mack5296cf22012-10-04 15:08:42 +0200320 }
321
Peter Ujfalusi6dfa9a42014-04-04 14:31:42 +0300322 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, FSXDLY(data_delay),
323 FSXDLY(3));
324 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, FSRDLY(data_delay),
325 FSRDLY(3));
326
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400327 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
328 case SND_SOC_DAIFMT_CBS_CFS:
329 /* codec is clock and frame slave */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200330 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
331 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400332
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200333 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
334 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400335
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200336 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, ACLKX | ACLKR);
337 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200338 mcasp->bclk_master = 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400339 break;
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400340 case SND_SOC_DAIFMT_CBM_CFS:
341 /* codec is clock master and frame slave */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200342 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
343 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400344
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200345 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
346 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400347
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200348 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, ACLKX | ACLKR);
349 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200350 mcasp->bclk_master = 0;
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400351 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400352 case SND_SOC_DAIFMT_CBM_CFM:
353 /* codec is clock and frame master */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200354 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
355 mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400356
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200357 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
358 mcasp_clr_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400359
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200360 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG,
361 ACLKX | AHCLKX | AFSX | ACLKR | AHCLKR | AFSR);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200362 mcasp->bclk_master = 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400363 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400364 default:
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200365 ret = -EINVAL;
366 goto out;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400367 }
368
369 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
370 case SND_SOC_DAIFMT_IB_NF:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200371 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
Peter Ujfalusi74ddd8c2014-04-04 14:31:41 +0300372 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300373 fs_pol_rising = true;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400374 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400375 case SND_SOC_DAIFMT_NB_IF:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200376 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
Peter Ujfalusi74ddd8c2014-04-04 14:31:41 +0300377 mcasp_set_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_IB_IF:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200381 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
Peter Ujfalusi74ddd8c2014-04-04 14:31:41 +0300382 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300383 fs_pol_rising = false;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400384 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400385 case SND_SOC_DAIFMT_NB_NF:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200386 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200387 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300388 fs_pol_rising = true;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400389 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400390 default:
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200391 ret = -EINVAL;
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300392 goto out;
393 }
394
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300395 if (inv_fs)
396 fs_pol_rising = !fs_pol_rising;
397
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300398 if (fs_pol_rising) {
399 mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXPOL);
400 mcasp_clr_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRPOL);
401 } else {
402 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXPOL);
403 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRPOL);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400404 }
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200405out:
406 pm_runtime_put_sync(mcasp->dev);
407 return ret;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400408}
409
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200410static int davinci_mcasp_set_clkdiv(struct snd_soc_dai *dai, int div_id, int div)
411{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200412 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200413
414 switch (div_id) {
415 case 0: /* MCLK divider */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200416 mcasp_mod_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200417 AHCLKXDIV(div - 1), AHCLKXDIV_MASK);
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200418 mcasp_mod_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200419 AHCLKRDIV(div - 1), AHCLKRDIV_MASK);
420 break;
421
422 case 1: /* BCLK divider */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200423 mcasp_mod_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200424 ACLKXDIV(div - 1), ACLKXDIV_MASK);
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200425 mcasp_mod_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200426 ACLKRDIV(div - 1), ACLKRDIV_MASK);
Daniel Mack82675252014-07-16 14:04:41 +0200427 mcasp->bclk_div = div;
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200428 break;
429
Daniel Mack1b3bc062012-12-05 18:20:38 +0100430 case 2: /* BCLK/LRCLK ratio */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200431 mcasp->bclk_lrclk_ratio = div;
Daniel Mack1b3bc062012-12-05 18:20:38 +0100432 break;
433
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200434 default:
435 return -EINVAL;
436 }
437
438 return 0;
439}
440
Daniel Mack5b66aa22012-10-04 15:08:41 +0200441static int davinci_mcasp_set_sysclk(struct snd_soc_dai *dai, int clk_id,
442 unsigned int freq, int dir)
443{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200444 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200445
446 if (dir == SND_SOC_CLOCK_OUT) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200447 mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE);
448 mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE);
449 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AHCLKX);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200450 } else {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200451 mcasp_clr_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE);
452 mcasp_clr_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE);
453 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AHCLKX);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200454 }
455
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200456 mcasp->sysclk_freq = freq;
457
Daniel Mack5b66aa22012-10-04 15:08:41 +0200458 return 0;
459}
460
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200461static int davinci_config_channel_size(struct davinci_mcasp *mcasp,
Daniel Mackba764b32012-12-05 18:20:37 +0100462 int word_length)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400463{
Daniel Mackba764b32012-12-05 18:20:37 +0100464 u32 fmt;
Daniel Mack79671892013-05-16 15:25:01 +0200465 u32 tx_rotate = (word_length / 4) & 0x7;
466 u32 rx_rotate = (32 - word_length) / 4;
Daniel Mackba764b32012-12-05 18:20:37 +0100467 u32 mask = (1ULL << word_length) - 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400468
Daniel Mack1b3bc062012-12-05 18:20:38 +0100469 /*
470 * if s BCLK-to-LRCLK ratio has been configured via the set_clkdiv()
471 * callback, take it into account here. That allows us to for example
472 * send 32 bits per channel to the codec, while only 16 of them carry
473 * audio payload.
Michal Bachratyd486fea2013-04-19 15:28:44 +0200474 * The clock ratio is given for a full period of data (for I2S format
475 * both left and right channels), so it has to be divided by number of
476 * tdm-slots (for I2S - divided by 2).
Daniel Mack1b3bc062012-12-05 18:20:38 +0100477 */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200478 if (mcasp->bclk_lrclk_ratio)
479 word_length = mcasp->bclk_lrclk_ratio / mcasp->tdm_slots;
Daniel Mack1b3bc062012-12-05 18:20:38 +0100480
Daniel Mackba764b32012-12-05 18:20:37 +0100481 /* mapping of the XSSZ bit-field as described in the datasheet */
482 fmt = (word_length >> 1) - 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400483
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200484 if (mcasp->op_mode != DAVINCI_MCASP_DIT_MODE) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200485 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, RXSSZ(fmt),
486 RXSSZ(0x0F));
487 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXSSZ(fmt),
488 TXSSZ(0x0F));
489 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXROT(tx_rotate),
490 TXROT(7));
491 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, RXROT(rx_rotate),
492 RXROT(7));
493 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXMASK_REG, mask);
Yegor Yefremovf5023af2013-04-04 16:13:20 +0200494 }
495
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200496 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXMASK_REG, mask);
Chaithrika U S0c31cf32009-09-15 18:13:29 -0400497
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400498 return 0;
499}
500
Peter Ujfalusi662ffae2014-01-30 15:15:22 +0200501static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream,
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300502 int period_words, int channels)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400503{
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300504 struct davinci_pcm_dma_params *dma_params = &mcasp->dma_params[stream];
505 struct snd_dmaengine_dai_dma_data *dma_data = &mcasp->dma_data[stream];
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400506 int i;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400507 u8 tx_ser = 0;
508 u8 rx_ser = 0;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200509 u8 slots = mcasp->tdm_slots;
Michal Bachraty2952b272013-02-28 16:07:08 +0100510 u8 max_active_serializers = (channels + slots - 1) / slots;
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300511 int active_serializers, numevt, n;
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200512 u32 reg;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400513 /* Default configuration */
Peter Ujfalusi40448e52014-04-04 15:56:30 +0300514 if (mcasp->version < MCASP_VERSION_3)
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200515 mcasp_set_bits(mcasp, DAVINCI_MCASP_PWREMUMGT_REG, MCASP_SOFT);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400516
517 /* All PINS as McASP */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200518 mcasp_set_reg(mcasp, DAVINCI_MCASP_PFUNC_REG, 0x00000000);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400519
520 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200521 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF);
522 mcasp_clr_bits(mcasp, DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400523 } else {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200524 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
525 mcasp_clr_bits(mcasp, DAVINCI_MCASP_REVTCTL_REG, RXDATADMADIS);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400526 }
527
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200528 for (i = 0; i < mcasp->num_serializer; i++) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200529 mcasp_set_bits(mcasp, DAVINCI_MCASP_XRSRCTL_REG(i),
530 mcasp->serial_dir[i]);
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200531 if (mcasp->serial_dir[i] == TX_MODE &&
Michal Bachraty2952b272013-02-28 16:07:08 +0100532 tx_ser < max_active_serializers) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200533 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AXR(i));
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400534 tx_ser++;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200535 } else if (mcasp->serial_dir[i] == RX_MODE &&
Michal Bachraty2952b272013-02-28 16:07:08 +0100536 rx_ser < max_active_serializers) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200537 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AXR(i));
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400538 rx_ser++;
Michal Bachraty2952b272013-02-28 16:07:08 +0100539 } else {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200540 mcasp_mod_bits(mcasp, DAVINCI_MCASP_XRSRCTL_REG(i),
541 SRMOD_INACTIVE, SRMOD_MASK);
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400542 }
543 }
544
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300545 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
546 active_serializers = tx_ser;
547 numevt = mcasp->txnumevt;
548 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
549 } else {
550 active_serializers = rx_ser;
551 numevt = mcasp->rxnumevt;
552 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
553 }
Daniel Mackecf327c2013-03-08 14:19:38 +0100554
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300555 if (active_serializers < max_active_serializers) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200556 dev_warn(mcasp->dev, "stream has more channels (%d) than are "
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300557 "enabled in mcasp (%d)\n", channels,
558 active_serializers * slots);
Daniel Mackecf327c2013-03-08 14:19:38 +0100559 return -EINVAL;
560 }
561
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300562 /* AFIFO is not in use */
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300563 if (!numevt) {
564 /* Configure the burst size for platform drivers */
Peter Ujfalusi33445642014-04-01 15:55:12 +0300565 if (active_serializers > 1) {
566 /*
567 * If more than one serializers are in use we have one
568 * DMA request to provide data for all serializers.
569 * For example if three serializers are enabled the DMA
570 * need to transfer three words per DMA request.
571 */
572 dma_params->fifo_level = active_serializers;
573 dma_data->maxburst = active_serializers;
574 } else {
575 dma_params->fifo_level = 0;
576 dma_data->maxburst = 0;
577 }
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300578 return 0;
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300579 }
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400580
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300581 if (period_words % active_serializers) {
582 dev_err(mcasp->dev, "Invalid combination of period words and "
583 "active serializers: %d, %d\n", period_words,
584 active_serializers);
585 return -EINVAL;
586 }
587
588 /*
589 * Calculate the optimal AFIFO depth for platform side:
590 * The number of words for numevt need to be in steps of active
591 * serializers.
592 */
593 n = numevt % active_serializers;
594 if (n)
595 numevt += (active_serializers - n);
596 while (period_words % numevt && numevt > 0)
597 numevt -= active_serializers;
598 if (numevt <= 0)
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300599 numevt = active_serializers;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400600
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300601 mcasp_mod_bits(mcasp, reg, active_serializers, NUMDMA_MASK);
602 mcasp_mod_bits(mcasp, reg, NUMEVT(numevt), NUMEVT_MASK);
Michal Bachraty2952b272013-02-28 16:07:08 +0100603
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300604 /* Configure the burst size for platform drivers */
Peter Ujfalusi33445642014-04-01 15:55:12 +0300605 if (numevt == 1)
606 numevt = 0;
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300607 dma_params->fifo_level = numevt;
608 dma_data->maxburst = numevt;
609
Michal Bachraty2952b272013-02-28 16:07:08 +0100610 return 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400611}
612
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200613static int mcasp_i2s_hw_param(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400614{
615 int i, active_slots;
616 u32 mask = 0;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200617 u32 busel = 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400618
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200619 if ((mcasp->tdm_slots < 2) || (mcasp->tdm_slots > 32)) {
620 dev_err(mcasp->dev, "tdm slot %d not supported\n",
621 mcasp->tdm_slots);
622 return -EINVAL;
623 }
624
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200625 active_slots = (mcasp->tdm_slots > 31) ? 32 : mcasp->tdm_slots;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400626 for (i = 0; i < active_slots; i++)
627 mask |= (1 << i);
628
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200629 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC);
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400630
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200631 if (!mcasp->dat_port)
632 busel = TXSEL;
633
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200634 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, mask);
635 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, busel | TXORD);
636 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG,
637 FSXMOD(mcasp->tdm_slots), FSXMOD(0x1FF));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400638
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200639 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXTDM_REG, mask);
640 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, busel | RXORD);
641 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG,
642 FSRMOD(mcasp->tdm_slots), FSRMOD(0x1FF));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400643
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200644 return 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400645}
646
647/* S/PDIF */
Daniel Mack64792852014-03-27 11:27:40 +0100648static int mcasp_dit_hw_param(struct davinci_mcasp *mcasp,
649 unsigned int rate)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400650{
Daniel Mack64792852014-03-27 11:27:40 +0100651 u32 cs_value = 0;
652 u8 *cs_bytes = (u8*) &cs_value;
653
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400654 /* Set the TX format : 24 bit right rotation, 32 bit slot, Pad 0
655 and LSB first */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200656 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXROT(6) | TXSSZ(15));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400657
658 /* Set TX frame synch : DIT Mode, 1 bit width, internal, rising edge */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200659 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE | FSXMOD(0x180));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400660
661 /* Set the TX tdm : for all the slots */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200662 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400663
664 /* Set the TX clock controls : div = 1 and internal */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200665 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE | TX_ASYNC);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400666
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200667 mcasp_clr_bits(mcasp, DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400668
669 /* Only 44100 and 48000 are valid, both have the same setting */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200670 mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXDIV(3));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400671
672 /* Enable the DIT */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200673 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXDITCTL_REG, DITEN);
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200674
Daniel Mack64792852014-03-27 11:27:40 +0100675 /* Set S/PDIF channel status bits */
676 cs_bytes[0] = IEC958_AES0_CON_NOT_COPYRIGHT;
677 cs_bytes[1] = IEC958_AES1_CON_PCM_CODER;
678
679 switch (rate) {
680 case 22050:
681 cs_bytes[3] |= IEC958_AES3_CON_FS_22050;
682 break;
683 case 24000:
684 cs_bytes[3] |= IEC958_AES3_CON_FS_24000;
685 break;
686 case 32000:
687 cs_bytes[3] |= IEC958_AES3_CON_FS_32000;
688 break;
689 case 44100:
690 cs_bytes[3] |= IEC958_AES3_CON_FS_44100;
691 break;
692 case 48000:
693 cs_bytes[3] |= IEC958_AES3_CON_FS_48000;
694 break;
695 case 88200:
696 cs_bytes[3] |= IEC958_AES3_CON_FS_88200;
697 break;
698 case 96000:
699 cs_bytes[3] |= IEC958_AES3_CON_FS_96000;
700 break;
701 case 176400:
702 cs_bytes[3] |= IEC958_AES3_CON_FS_176400;
703 break;
704 case 192000:
705 cs_bytes[3] |= IEC958_AES3_CON_FS_192000;
706 break;
707 default:
708 printk(KERN_WARNING "unsupported sampling rate: %d\n", rate);
709 return -EINVAL;
710 }
711
712 mcasp_set_reg(mcasp, DAVINCI_MCASP_DITCSRA_REG, cs_value);
713 mcasp_set_reg(mcasp, DAVINCI_MCASP_DITCSRB_REG, cs_value);
714
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200715 return 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400716}
717
718static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
719 struct snd_pcm_hw_params *params,
720 struct snd_soc_dai *cpu_dai)
721{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200722 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400723 struct davinci_pcm_dma_params *dma_params =
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200724 &mcasp->dma_params[substream->stream];
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400725 int word_length;
Peter Ujfalusia7e46bd2014-02-03 14:51:50 +0200726 int channels = params_channels(params);
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300727 int period_size = params_period_size(params);
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200728 int ret;
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200729
Daniel Mack82675252014-07-16 14:04:41 +0200730 /*
731 * If mcasp is BCLK master, and a BCLK divider was not provided by
732 * the machine driver, we need to calculate the ratio.
733 */
734 if (mcasp->bclk_master && mcasp->bclk_div == 0 && mcasp->sysclk_freq) {
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200735 unsigned int bclk_freq = snd_soc_params_to_bclk(params);
Jyri Sarha09298782014-06-13 12:50:00 +0300736 unsigned int div = mcasp->sysclk_freq / bclk_freq;
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200737 if (mcasp->sysclk_freq % bclk_freq != 0) {
Jyri Sarha09298782014-06-13 12:50:00 +0300738 if (((mcasp->sysclk_freq / div) - bclk_freq) >
739 (bclk_freq - (mcasp->sysclk_freq / (div+1))))
740 div++;
741 dev_warn(mcasp->dev,
742 "Inaccurate BCLK: %u Hz / %u != %u Hz\n",
743 mcasp->sysclk_freq, div, bclk_freq);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200744 }
Jyri Sarha09298782014-06-13 12:50:00 +0300745 davinci_mcasp_set_clkdiv(cpu_dai, 1, div);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200746 }
747
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300748 ret = mcasp_common_hw_param(mcasp, substream->stream,
749 period_size * channels, channels);
Peter Ujfalusi0f7d9a62014-01-30 15:15:24 +0200750 if (ret)
751 return ret;
752
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200753 if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE)
Daniel Mack64792852014-03-27 11:27:40 +0100754 ret = mcasp_dit_hw_param(mcasp, params_rate(params));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400755 else
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200756 ret = mcasp_i2s_hw_param(mcasp, substream->stream);
757
758 if (ret)
759 return ret;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400760
761 switch (params_format(params)) {
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400762 case SNDRV_PCM_FORMAT_U8:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400763 case SNDRV_PCM_FORMAT_S8:
764 dma_params->data_type = 1;
Daniel Mackba764b32012-12-05 18:20:37 +0100765 word_length = 8;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400766 break;
767
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400768 case SNDRV_PCM_FORMAT_U16_LE:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400769 case SNDRV_PCM_FORMAT_S16_LE:
770 dma_params->data_type = 2;
Daniel Mackba764b32012-12-05 18:20:37 +0100771 word_length = 16;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400772 break;
773
Daniel Mack21eb24d2012-10-09 09:35:16 +0200774 case SNDRV_PCM_FORMAT_U24_3LE:
775 case SNDRV_PCM_FORMAT_S24_3LE:
Daniel Mack21eb24d2012-10-09 09:35:16 +0200776 dma_params->data_type = 3;
Daniel Mackba764b32012-12-05 18:20:37 +0100777 word_length = 24;
Daniel Mack21eb24d2012-10-09 09:35:16 +0200778 break;
779
Daniel Mack6b7fa012012-10-09 11:56:40 +0200780 case SNDRV_PCM_FORMAT_U24_LE:
781 case SNDRV_PCM_FORMAT_S24_LE:
Peter Ujfalusi182bef82014-06-26 08:09:24 +0300782 dma_params->data_type = 4;
783 word_length = 24;
784 break;
785
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400786 case SNDRV_PCM_FORMAT_U32_LE:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400787 case SNDRV_PCM_FORMAT_S32_LE:
788 dma_params->data_type = 4;
Daniel Mackba764b32012-12-05 18:20:37 +0100789 word_length = 32;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400790 break;
791
792 default:
793 printk(KERN_WARNING "davinci-mcasp: unsupported PCM format");
794 return -EINVAL;
795 }
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400796
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300797 if (mcasp->version == MCASP_VERSION_2 && !dma_params->fifo_level)
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400798 dma_params->acnt = 4;
799 else
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400800 dma_params->acnt = dma_params->data_type;
801
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200802 davinci_config_channel_size(mcasp, word_length);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400803
804 return 0;
805}
806
807static int davinci_mcasp_trigger(struct snd_pcm_substream *substream,
808 int cmd, struct snd_soc_dai *cpu_dai)
809{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200810 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400811 int ret = 0;
812
813 switch (cmd) {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400814 case SNDRV_PCM_TRIGGER_RESUME:
Chaithrika U Se473b842010-01-20 17:06:33 +0530815 case SNDRV_PCM_TRIGGER_START:
816 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200817 davinci_mcasp_start(mcasp, substream->stream);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400818 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400819 case SNDRV_PCM_TRIGGER_SUSPEND:
Chaithrika U Sa47979b2009-12-03 18:56:56 +0530820 case SNDRV_PCM_TRIGGER_STOP:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400821 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200822 davinci_mcasp_stop(mcasp, substream->stream);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400823 break;
824
825 default:
826 ret = -EINVAL;
827 }
828
829 return ret;
830}
831
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100832static const struct snd_soc_dai_ops davinci_mcasp_dai_ops = {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400833 .trigger = davinci_mcasp_trigger,
834 .hw_params = davinci_mcasp_hw_params,
835 .set_fmt = davinci_mcasp_set_dai_fmt,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200836 .set_clkdiv = davinci_mcasp_set_clkdiv,
Daniel Mack5b66aa22012-10-04 15:08:41 +0200837 .set_sysclk = davinci_mcasp_set_sysclk,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400838};
839
Peter Ujfalusid5902f62014-04-01 15:55:07 +0300840static int davinci_mcasp_dai_probe(struct snd_soc_dai *dai)
841{
842 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
843
Peter Ujfalusif3f9cfa2014-07-16 15:12:04 +0300844 if (mcasp->version >= MCASP_VERSION_3) {
Peter Ujfalusid5902f62014-04-01 15:55:07 +0300845 /* Using dmaengine PCM */
846 dai->playback_dma_data =
847 &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
848 dai->capture_dma_data =
849 &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE];
850 } else {
851 /* Using davinci-pcm */
852 dai->playback_dma_data = mcasp->dma_params;
853 dai->capture_dma_data = mcasp->dma_params;
854 }
855
856 return 0;
857}
858
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200859#ifdef CONFIG_PM_SLEEP
860static int davinci_mcasp_suspend(struct snd_soc_dai *dai)
861{
862 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Peter Ujfalusi790bb942014-02-03 14:51:52 +0200863 struct davinci_mcasp_context *context = &mcasp->context;
Peter Ujfalusi1cc0c052014-10-01 16:02:11 +0300864 int i;
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200865
Peter Ujfalusi1cc0c052014-10-01 16:02:11 +0300866 for (i = 0; i < ARRAY_SIZE(context_regs); i++)
867 context->config_regs[i] = mcasp_get_reg(mcasp, context_regs[i]);
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200868
869 return 0;
870}
871
872static int davinci_mcasp_resume(struct snd_soc_dai *dai)
873{
874 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Peter Ujfalusi790bb942014-02-03 14:51:52 +0200875 struct davinci_mcasp_context *context = &mcasp->context;
Peter Ujfalusi1cc0c052014-10-01 16:02:11 +0300876 int i;
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200877
Peter Ujfalusi1cc0c052014-10-01 16:02:11 +0300878 for (i = 0; i < ARRAY_SIZE(context_regs); i++)
879 mcasp_set_reg(mcasp, context_regs[i], context->config_regs[i]);
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200880
881 return 0;
882}
883#else
884#define davinci_mcasp_suspend NULL
885#define davinci_mcasp_resume NULL
886#endif
887
Peter Ujfalusied29cd52013-11-14 11:35:22 +0200888#define DAVINCI_MCASP_RATES SNDRV_PCM_RATE_8000_192000
889
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400890#define DAVINCI_MCASP_PCM_FMTS (SNDRV_PCM_FMTBIT_S8 | \
891 SNDRV_PCM_FMTBIT_U8 | \
892 SNDRV_PCM_FMTBIT_S16_LE | \
893 SNDRV_PCM_FMTBIT_U16_LE | \
Daniel Mack21eb24d2012-10-09 09:35:16 +0200894 SNDRV_PCM_FMTBIT_S24_LE | \
895 SNDRV_PCM_FMTBIT_U24_LE | \
896 SNDRV_PCM_FMTBIT_S24_3LE | \
897 SNDRV_PCM_FMTBIT_U24_3LE | \
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400898 SNDRV_PCM_FMTBIT_S32_LE | \
899 SNDRV_PCM_FMTBIT_U32_LE)
900
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000901static struct snd_soc_dai_driver davinci_mcasp_dai[] = {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400902 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000903 .name = "davinci-mcasp.0",
Peter Ujfalusid5902f62014-04-01 15:55:07 +0300904 .probe = davinci_mcasp_dai_probe,
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200905 .suspend = davinci_mcasp_suspend,
906 .resume = davinci_mcasp_resume,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400907 .playback = {
908 .channels_min = 2,
Michal Bachraty2952b272013-02-28 16:07:08 +0100909 .channels_max = 32 * 16,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400910 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400911 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400912 },
913 .capture = {
914 .channels_min = 2,
Michal Bachraty2952b272013-02-28 16:07:08 +0100915 .channels_max = 32 * 16,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400916 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400917 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400918 },
919 .ops = &davinci_mcasp_dai_ops,
920
921 },
922 {
Peter Ujfalusi58e48d92013-11-14 11:35:24 +0200923 .name = "davinci-mcasp.1",
Peter Ujfalusid5902f62014-04-01 15:55:07 +0300924 .probe = davinci_mcasp_dai_probe,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400925 .playback = {
926 .channels_min = 1,
927 .channels_max = 384,
928 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400929 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400930 },
931 .ops = &davinci_mcasp_dai_ops,
932 },
933
934};
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400935
Kuninori Morimotoeeef0ed2013-03-21 03:31:19 -0700936static const struct snd_soc_component_driver davinci_mcasp_component = {
937 .name = "davinci-mcasp",
938};
939
Jyri Sarha256ba182013-10-18 18:37:42 +0300940/* Some HW specific values and defaults. The rest is filled in from DT. */
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200941static struct davinci_mcasp_pdata dm646x_mcasp_pdata = {
Jyri Sarha256ba182013-10-18 18:37:42 +0300942 .tx_dma_offset = 0x400,
943 .rx_dma_offset = 0x400,
944 .asp_chan_q = EVENTQ_0,
945 .version = MCASP_VERSION_1,
946};
947
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200948static struct davinci_mcasp_pdata da830_mcasp_pdata = {
Jyri Sarha256ba182013-10-18 18:37:42 +0300949 .tx_dma_offset = 0x2000,
950 .rx_dma_offset = 0x2000,
951 .asp_chan_q = EVENTQ_0,
952 .version = MCASP_VERSION_2,
953};
954
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200955static struct davinci_mcasp_pdata am33xx_mcasp_pdata = {
Jyri Sarha256ba182013-10-18 18:37:42 +0300956 .tx_dma_offset = 0,
957 .rx_dma_offset = 0,
958 .asp_chan_q = EVENTQ_0,
959 .version = MCASP_VERSION_3,
960};
961
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200962static struct davinci_mcasp_pdata dra7_mcasp_pdata = {
Peter Ujfalusi453c4992013-11-14 11:35:34 +0200963 .tx_dma_offset = 0x200,
964 .rx_dma_offset = 0x284,
965 .asp_chan_q = EVENTQ_0,
966 .version = MCASP_VERSION_4,
967};
968
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530969static const struct of_device_id mcasp_dt_ids[] = {
970 {
971 .compatible = "ti,dm646x-mcasp-audio",
Jyri Sarha256ba182013-10-18 18:37:42 +0300972 .data = &dm646x_mcasp_pdata,
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530973 },
974 {
975 .compatible = "ti,da830-mcasp-audio",
Jyri Sarha256ba182013-10-18 18:37:42 +0300976 .data = &da830_mcasp_pdata,
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530977 },
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530978 {
Jyri Sarha3af9e032013-10-18 18:37:44 +0300979 .compatible = "ti,am33xx-mcasp-audio",
Peter Ujfalusib14899d2013-11-14 11:35:37 +0200980 .data = &am33xx_mcasp_pdata,
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530981 },
Peter Ujfalusi453c4992013-11-14 11:35:34 +0200982 {
983 .compatible = "ti,dra7-mcasp-audio",
984 .data = &dra7_mcasp_pdata,
985 },
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530986 { /* sentinel */ }
987};
988MODULE_DEVICE_TABLE(of, mcasp_dt_ids);
989
Peter Ujfalusiae726e92013-11-14 11:35:35 +0200990static int mcasp_reparent_fck(struct platform_device *pdev)
991{
992 struct device_node *node = pdev->dev.of_node;
993 struct clk *gfclk, *parent_clk;
994 const char *parent_name;
995 int ret;
996
997 if (!node)
998 return 0;
999
1000 parent_name = of_get_property(node, "fck_parent", NULL);
1001 if (!parent_name)
1002 return 0;
1003
1004 gfclk = clk_get(&pdev->dev, "fck");
1005 if (IS_ERR(gfclk)) {
1006 dev_err(&pdev->dev, "failed to get fck\n");
1007 return PTR_ERR(gfclk);
1008 }
1009
1010 parent_clk = clk_get(NULL, parent_name);
1011 if (IS_ERR(parent_clk)) {
1012 dev_err(&pdev->dev, "failed to get parent clock\n");
1013 ret = PTR_ERR(parent_clk);
1014 goto err1;
1015 }
1016
1017 ret = clk_set_parent(gfclk, parent_clk);
1018 if (ret) {
1019 dev_err(&pdev->dev, "failed to reparent fck\n");
1020 goto err2;
1021 }
1022
1023err2:
1024 clk_put(parent_clk);
1025err1:
1026 clk_put(gfclk);
1027 return ret;
1028}
1029
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001030static struct davinci_mcasp_pdata *davinci_mcasp_set_pdata_from_of(
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301031 struct platform_device *pdev)
1032{
1033 struct device_node *np = pdev->dev.of_node;
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001034 struct davinci_mcasp_pdata *pdata = NULL;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301035 const struct of_device_id *match =
Sachin Kamatea421eb2013-05-22 16:53:37 +05301036 of_match_device(mcasp_dt_ids, &pdev->dev);
Jyri Sarha4023fe62013-10-18 18:37:43 +03001037 struct of_phandle_args dma_spec;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301038
1039 const u32 *of_serial_dir32;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301040 u32 val;
1041 int i, ret = 0;
1042
1043 if (pdev->dev.platform_data) {
1044 pdata = pdev->dev.platform_data;
1045 return pdata;
1046 } else if (match) {
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001047 pdata = (struct davinci_mcasp_pdata*) match->data;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301048 } else {
1049 /* control shouldn't reach here. something is wrong */
1050 ret = -EINVAL;
1051 goto nodata;
1052 }
1053
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301054 ret = of_property_read_u32(np, "op-mode", &val);
1055 if (ret >= 0)
1056 pdata->op_mode = val;
1057
1058 ret = of_property_read_u32(np, "tdm-slots", &val);
Michal Bachraty2952b272013-02-28 16:07:08 +01001059 if (ret >= 0) {
1060 if (val < 2 || val > 32) {
1061 dev_err(&pdev->dev,
1062 "tdm-slots must be in rage [2-32]\n");
1063 ret = -EINVAL;
1064 goto nodata;
1065 }
1066
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301067 pdata->tdm_slots = val;
Michal Bachraty2952b272013-02-28 16:07:08 +01001068 }
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301069
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301070 of_serial_dir32 = of_get_property(np, "serial-dir", &val);
1071 val /= sizeof(u32);
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301072 if (of_serial_dir32) {
Peter Ujfalusi1427e662013-10-18 18:37:46 +03001073 u8 *of_serial_dir = devm_kzalloc(&pdev->dev,
1074 (sizeof(*of_serial_dir) * val),
1075 GFP_KERNEL);
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301076 if (!of_serial_dir) {
1077 ret = -ENOMEM;
1078 goto nodata;
1079 }
1080
Peter Ujfalusi1427e662013-10-18 18:37:46 +03001081 for (i = 0; i < val; i++)
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301082 of_serial_dir[i] = be32_to_cpup(&of_serial_dir32[i]);
1083
Peter Ujfalusi1427e662013-10-18 18:37:46 +03001084 pdata->num_serializer = val;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301085 pdata->serial_dir = of_serial_dir;
1086 }
1087
Jyri Sarha4023fe62013-10-18 18:37:43 +03001088 ret = of_property_match_string(np, "dma-names", "tx");
1089 if (ret < 0)
1090 goto nodata;
1091
1092 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
1093 &dma_spec);
1094 if (ret < 0)
1095 goto nodata;
1096
1097 pdata->tx_dma_channel = dma_spec.args[0];
1098
1099 ret = of_property_match_string(np, "dma-names", "rx");
1100 if (ret < 0)
1101 goto nodata;
1102
1103 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
1104 &dma_spec);
1105 if (ret < 0)
1106 goto nodata;
1107
1108 pdata->rx_dma_channel = dma_spec.args[0];
1109
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301110 ret = of_property_read_u32(np, "tx-num-evt", &val);
1111 if (ret >= 0)
1112 pdata->txnumevt = val;
1113
1114 ret = of_property_read_u32(np, "rx-num-evt", &val);
1115 if (ret >= 0)
1116 pdata->rxnumevt = val;
1117
1118 ret = of_property_read_u32(np, "sram-size-playback", &val);
1119 if (ret >= 0)
1120 pdata->sram_size_playback = val;
1121
1122 ret = of_property_read_u32(np, "sram-size-capture", &val);
1123 if (ret >= 0)
1124 pdata->sram_size_capture = val;
1125
1126 return pdata;
1127
1128nodata:
1129 if (ret < 0) {
1130 dev_err(&pdev->dev, "Error populating platform data, err %d\n",
1131 ret);
1132 pdata = NULL;
1133 }
1134 return pdata;
1135}
1136
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001137static int davinci_mcasp_probe(struct platform_device *pdev)
1138{
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001139 struct davinci_pcm_dma_params *dma_params;
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001140 struct snd_dmaengine_dai_dma_data *dma_data;
Jyri Sarha256ba182013-10-18 18:37:42 +03001141 struct resource *mem, *ioarea, *res, *dat;
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001142 struct davinci_mcasp_pdata *pdata;
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001143 struct davinci_mcasp *mcasp;
Julia Lawall96d31e22011-12-29 17:51:21 +01001144 int ret;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001145
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301146 if (!pdev->dev.platform_data && !pdev->dev.of_node) {
1147 dev_err(&pdev->dev, "No platform data supplied\n");
1148 return -EINVAL;
1149 }
1150
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001151 mcasp = devm_kzalloc(&pdev->dev, sizeof(struct davinci_mcasp),
Julia Lawall96d31e22011-12-29 17:51:21 +01001152 GFP_KERNEL);
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001153 if (!mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001154 return -ENOMEM;
1155
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301156 pdata = davinci_mcasp_set_pdata_from_of(pdev);
1157 if (!pdata) {
1158 dev_err(&pdev->dev, "no platform data\n");
1159 return -EINVAL;
1160 }
1161
Jyri Sarha256ba182013-10-18 18:37:42 +03001162 mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001163 if (!mem) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001164 dev_warn(mcasp->dev,
Jyri Sarha256ba182013-10-18 18:37:42 +03001165 "\"mpu\" mem resource not found, using index 0\n");
1166 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1167 if (!mem) {
1168 dev_err(&pdev->dev, "no mem resource?\n");
1169 return -ENODEV;
1170 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001171 }
1172
Julia Lawall96d31e22011-12-29 17:51:21 +01001173 ioarea = devm_request_mem_region(&pdev->dev, mem->start,
Vaibhav Bediad852f4462011-02-09 18:39:52 +05301174 resource_size(mem), pdev->name);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001175 if (!ioarea) {
1176 dev_err(&pdev->dev, "Audio region already claimed\n");
Julia Lawall96d31e22011-12-29 17:51:21 +01001177 return -EBUSY;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001178 }
1179
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301180 pm_runtime_enable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001181
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301182 ret = pm_runtime_get_sync(&pdev->dev);
1183 if (IS_ERR_VALUE(ret)) {
1184 dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
1185 return ret;
1186 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001187
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001188 mcasp->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
1189 if (!mcasp->base) {
Vaibhav Bedia4f82f022011-02-09 18:39:54 +05301190 dev_err(&pdev->dev, "ioremap failed\n");
1191 ret = -ENOMEM;
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001192 goto err;
Vaibhav Bedia4f82f022011-02-09 18:39:54 +05301193 }
1194
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001195 mcasp->op_mode = pdata->op_mode;
1196 mcasp->tdm_slots = pdata->tdm_slots;
1197 mcasp->num_serializer = pdata->num_serializer;
1198 mcasp->serial_dir = pdata->serial_dir;
1199 mcasp->version = pdata->version;
1200 mcasp->txnumevt = pdata->txnumevt;
1201 mcasp->rxnumevt = pdata->rxnumevt;
Peter Ujfalusi487dce82013-11-14 11:35:31 +02001202
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001203 mcasp->dev = &pdev->dev;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001204
Jyri Sarha256ba182013-10-18 18:37:42 +03001205 dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001206 if (dat)
1207 mcasp->dat_port = true;
Jyri Sarha256ba182013-10-18 18:37:42 +03001208
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001209 dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_PLAYBACK];
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001210 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001211 dma_params->asp_chan_q = pdata->asp_chan_q;
1212 dma_params->ram_chan_q = pdata->ram_chan_q;
1213 dma_params->sram_pool = pdata->sram_pool;
1214 dma_params->sram_size = pdata->sram_size_playback;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001215 if (dat)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001216 dma_params->dma_addr = dat->start;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001217 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001218 dma_params->dma_addr = mem->start + pdata->tx_dma_offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001219
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001220 /* Unconditional dmaengine stuff */
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001221 dma_data->addr = dma_params->dma_addr;
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001222
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001223 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
Jyri Sarha4023fe62013-10-18 18:37:43 +03001224 if (res)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001225 dma_params->channel = res->start;
Jyri Sarha4023fe62013-10-18 18:37:43 +03001226 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001227 dma_params->channel = pdata->tx_dma_channel;
Troy Kisky92e2a6f2009-09-11 14:29:03 -07001228
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001229 /* dmaengine filter data for DT and non-DT boot */
1230 if (pdev->dev.of_node)
1231 dma_data->filter_data = "tx";
1232 else
1233 dma_data->filter_data = &dma_params->channel;
1234
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001235 dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_CAPTURE];
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001236 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE];
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001237 dma_params->asp_chan_q = pdata->asp_chan_q;
1238 dma_params->ram_chan_q = pdata->ram_chan_q;
1239 dma_params->sram_pool = pdata->sram_pool;
1240 dma_params->sram_size = pdata->sram_size_capture;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001241 if (dat)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001242 dma_params->dma_addr = dat->start;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001243 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001244 dma_params->dma_addr = mem->start + pdata->rx_dma_offset;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001245
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001246 /* Unconditional dmaengine stuff */
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001247 dma_data->addr = dma_params->dma_addr;
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001248
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001249 if (mcasp->version < MCASP_VERSION_3) {
1250 mcasp->fifo_base = DAVINCI_MCASP_V2_AFIFO_BASE;
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001251 /* dma_params->dma_addr is pointing to the data port address */
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001252 mcasp->dat_port = true;
1253 } else {
1254 mcasp->fifo_base = DAVINCI_MCASP_V3_AFIFO_BASE;
1255 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001256
1257 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
Jyri Sarha4023fe62013-10-18 18:37:43 +03001258 if (res)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001259 dma_params->channel = res->start;
Jyri Sarha4023fe62013-10-18 18:37:43 +03001260 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001261 dma_params->channel = pdata->rx_dma_channel;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001262
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001263 /* dmaengine filter data for DT and non-DT boot */
1264 if (pdev->dev.of_node)
1265 dma_data->filter_data = "rx";
1266 else
1267 dma_data->filter_data = &dma_params->channel;
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001268
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001269 dev_set_drvdata(&pdev->dev, mcasp);
Peter Ujfalusiae726e92013-11-14 11:35:35 +02001270
1271 mcasp_reparent_fck(pdev);
1272
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001273 ret = devm_snd_soc_register_component(&pdev->dev,
1274 &davinci_mcasp_component,
1275 &davinci_mcasp_dai[pdata->op_mode], 1);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001276
1277 if (ret != 0)
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001278 goto err;
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +05301279
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001280 switch (mcasp->version) {
Jyri Sarha7f28f352014-06-13 12:49:59 +03001281#if IS_BUILTIN(CONFIG_SND_DAVINCI_SOC) || \
1282 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \
1283 IS_MODULE(CONFIG_SND_DAVINCI_SOC))
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001284 case MCASP_VERSION_1:
1285 case MCASP_VERSION_2:
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001286 ret = davinci_soc_platform_register(&pdev->dev);
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001287 break;
Jyri Sarha7f28f352014-06-13 12:49:59 +03001288#endif
Peter Ujfalusif3f9cfa2014-07-16 15:12:04 +03001289#if IS_BUILTIN(CONFIG_SND_EDMA_SOC) || \
1290 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \
1291 IS_MODULE(CONFIG_SND_EDMA_SOC))
1292 case MCASP_VERSION_3:
1293 ret = edma_pcm_platform_register(&pdev->dev);
1294 break;
1295#endif
Jyri Sarha7f28f352014-06-13 12:49:59 +03001296#if IS_BUILTIN(CONFIG_SND_OMAP_SOC) || \
1297 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \
1298 IS_MODULE(CONFIG_SND_OMAP_SOC))
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001299 case MCASP_VERSION_4:
1300 ret = omap_pcm_platform_register(&pdev->dev);
1301 break;
Jyri Sarha7f28f352014-06-13 12:49:59 +03001302#endif
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001303 default:
1304 dev_err(&pdev->dev, "Invalid McASP version: %d\n",
1305 mcasp->version);
1306 ret = -EINVAL;
1307 break;
1308 }
1309
1310 if (ret) {
1311 dev_err(&pdev->dev, "register PCM failed: %d\n", ret);
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001312 goto err;
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +05301313 }
1314
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001315 return 0;
1316
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001317err:
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301318 pm_runtime_put_sync(&pdev->dev);
1319 pm_runtime_disable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001320 return ret;
1321}
1322
1323static int davinci_mcasp_remove(struct platform_device *pdev)
1324{
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301325 pm_runtime_put_sync(&pdev->dev);
1326 pm_runtime_disable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001327
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001328 return 0;
1329}
1330
1331static struct platform_driver davinci_mcasp_driver = {
1332 .probe = davinci_mcasp_probe,
1333 .remove = davinci_mcasp_remove,
1334 .driver = {
1335 .name = "davinci-mcasp",
1336 .owner = THIS_MODULE,
Sachin Kamatea421eb2013-05-22 16:53:37 +05301337 .of_match_table = mcasp_dt_ids,
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001338 },
1339};
1340
Axel Linf9b8a512011-11-25 10:09:27 +08001341module_platform_driver(davinci_mcasp_driver);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001342
1343MODULE_AUTHOR("Steve Chen");
1344MODULE_DESCRIPTION("TI DAVINCI McASP SoC Interface");
1345MODULE_LICENSE("GPL");