blob: 6a6b2ff7d7d73daf4b6742242af4247e5585ebcc [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 Ujfalusi21400a722013-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 Ujfalusi21400a722013-11-14 11:35:26 +020058 void __iomem *base;
Peter Ujfalusi487dce82013-11-14 11:35:31 +020059 u32 fifo_base;
Peter Ujfalusi21400a722013-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;
Daniel Mack82675252014-07-16 14:04:41 +020068 u8 bclk_div;
Peter Ujfalusi21400a722013-11-14 11:35:26 +020069 u16 bclk_lrclk_ratio;
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +020070 int streams;
Peter Ujfalusi21400a722013-11-14 11:35:26 +020071
Jyri Sarhaab8b14b2014-01-27 17:37:52 +020072 int sysclk_freq;
73 bool bclk_master;
74
Peter Ujfalusi21400a722013-11-14 11:35:26 +020075 /* McASP FIFO related */
76 u8 txnumevt;
77 u8 rxnumevt;
78
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +020079 bool dat_port;
80
Peter Ujfalusi21400a722013-11-14 11:35:26 +020081#ifdef CONFIG_PM_SLEEP
Peter Ujfalusi790bb942014-02-03 14:51:52 +020082 struct davinci_mcasp_context context;
Peter Ujfalusi21400a722013-11-14 11:35:26 +020083#endif
84};
85
Peter Ujfalusif68205a2013-11-14 11:35:36 +020086static inline void mcasp_set_bits(struct davinci_mcasp *mcasp, u32 offset,
87 u32 val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -040088{
Peter Ujfalusif68205a2013-11-14 11:35:36 +020089 void __iomem *reg = mcasp->base + offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -040090 __raw_writel(__raw_readl(reg) | val, reg);
91}
92
Peter Ujfalusif68205a2013-11-14 11:35:36 +020093static inline void mcasp_clr_bits(struct davinci_mcasp *mcasp, u32 offset,
94 u32 val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -040095{
Peter Ujfalusif68205a2013-11-14 11:35:36 +020096 void __iomem *reg = mcasp->base + offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -040097 __raw_writel((__raw_readl(reg) & ~(val)), reg);
98}
99
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200100static inline void mcasp_mod_bits(struct davinci_mcasp *mcasp, u32 offset,
101 u32 val, u32 mask)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400102{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200103 void __iomem *reg = mcasp->base + offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400104 __raw_writel((__raw_readl(reg) & ~mask) | val, reg);
105}
106
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200107static inline void mcasp_set_reg(struct davinci_mcasp *mcasp, u32 offset,
108 u32 val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400109{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200110 __raw_writel(val, mcasp->base + offset);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400111}
112
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200113static inline u32 mcasp_get_reg(struct davinci_mcasp *mcasp, u32 offset)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400114{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200115 return (u32)__raw_readl(mcasp->base + offset);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400116}
117
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200118static void mcasp_set_ctl_reg(struct davinci_mcasp *mcasp, u32 ctl_reg, u32 val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400119{
120 int i = 0;
121
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200122 mcasp_set_bits(mcasp, ctl_reg, val);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400123
124 /* programming GBLCTL needs to read back from GBLCTL and verfiy */
125 /* loop count is to avoid the lock-up */
126 for (i = 0; i < 1000; i++) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200127 if ((mcasp_get_reg(mcasp, ctl_reg) & val) == val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400128 break;
129 }
130
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200131 if (i == 1000 && ((mcasp_get_reg(mcasp, ctl_reg) & val) != val))
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400132 printk(KERN_ERR "GBLCTL write error\n");
133}
134
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200135static bool mcasp_is_synchronous(struct davinci_mcasp *mcasp)
136{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200137 u32 rxfmctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG);
138 u32 aclkxctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200139
140 return !(aclkxctl & TX_ASYNC) && rxfmctl & AFSRE;
141}
142
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200143static void mcasp_start_rx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400144{
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200145 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXHCLKRST);
146 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXCLKRST);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200147
148 /*
149 * When ASYNC == 0 the transmit and receive sections operate
150 * synchronously from the transmit clock and frame sync. We need to make
151 * sure that the TX signlas are enabled when starting reception.
152 */
153 if (mcasp_is_synchronous(mcasp)) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200154 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST);
155 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200156 }
157
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200158 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSERCLR);
159 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400160
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200161 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXSMRST);
162 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, RXFSRST);
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);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200167
168 if (mcasp_is_synchronous(mcasp))
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200169 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXFSRST);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400170}
171
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200172static void mcasp_start_tx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400173{
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400174 u8 offset = 0, i;
175 u32 cnt;
176
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200177 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST);
178 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
179 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXSERCLR);
180 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400181
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200182 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXSMRST);
183 mcasp_set_ctl_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, TXFSRST);
184 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXBUF_REG, 0);
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200185 for (i = 0; i < mcasp->num_serializer; i++) {
186 if (mcasp->serial_dir[i] == TX_MODE) {
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400187 offset = i;
188 break;
189 }
190 }
191
192 /* wait for TX ready */
193 cnt = 0;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200194 while (!(mcasp_get_reg(mcasp, DAVINCI_MCASP_XRSRCTL_REG(offset)) &
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400195 TXSTATE) && (cnt < 100000))
196 cnt++;
197
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200198 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400199}
200
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200201static void davinci_mcasp_start(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400202{
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200203 u32 reg;
204
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200205 mcasp->streams++;
206
Chaithrika U S539d3d82009-09-23 10:12:08 -0400207 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200208 if (mcasp->txnumevt) { /* enable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200209 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200210 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
211 mcasp_set_bits(mcasp, reg, FIFO_ENABLE);
Vaibhav Bedia0d624272012-08-08 20:40:31 +0530212 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200213 mcasp_start_tx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400214 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200215 if (mcasp->rxnumevt) { /* enable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200216 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200217 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
218 mcasp_set_bits(mcasp, reg, FIFO_ENABLE);
Vaibhav Bedia0d624272012-08-08 20:40:31 +0530219 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200220 mcasp_start_rx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400221 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400222}
223
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200224static void mcasp_stop_rx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400225{
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200226 /*
227 * In synchronous mode stop the TX clocks if no other stream is
228 * running
229 */
230 if (mcasp_is_synchronous(mcasp) && !mcasp->streams)
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200231 mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, 0);
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200232
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200233 mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLR_REG, 0);
234 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400235}
236
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200237static void mcasp_stop_tx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400238{
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200239 u32 val = 0;
240
241 /*
242 * In synchronous mode keep TX clocks running if the capture stream is
243 * still running.
244 */
245 if (mcasp_is_synchronous(mcasp) && mcasp->streams)
246 val = TXHCLKRST | TXCLKRST | TXFSRST;
247
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200248 mcasp_set_reg(mcasp, DAVINCI_MCASP_GBLCTLX_REG, val);
249 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400250}
251
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200252static void davinci_mcasp_stop(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400253{
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200254 u32 reg;
255
Peter Ujfalusi4dcb5a02013-11-14 11:35:33 +0200256 mcasp->streams--;
257
Chaithrika U S539d3d82009-09-23 10:12:08 -0400258 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200259 if (mcasp->txnumevt) { /* disable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200260 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200261 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530262 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200263 mcasp_stop_tx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400264 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200265 if (mcasp->rxnumevt) { /* disable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200266 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200267 mcasp_clr_bits(mcasp, reg, FIFO_ENABLE);
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530268 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200269 mcasp_stop_rx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400270 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400271}
272
273static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
274 unsigned int fmt)
275{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200276 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200277 int ret = 0;
Peter Ujfalusi6dfa9a42014-04-04 14:31:42 +0300278 u32 data_delay;
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300279 bool fs_pol_rising;
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300280 bool inv_fs = false;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400281
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200282 pm_runtime_get_sync(mcasp->dev);
Daniel Mack5296cf22012-10-04 15:08:42 +0200283 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
Peter Ujfalusi188edc52014-04-04 14:31:43 +0300284 case SND_SOC_DAIFMT_DSP_A:
285 mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
286 mcasp_clr_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
Peter Ujfalusi188edc52014-04-04 14:31:43 +0300287 /* 1st data bit occur one ACLK cycle after the frame sync */
288 data_delay = 1;
289 break;
Daniel Mack5296cf22012-10-04 15:08:42 +0200290 case SND_SOC_DAIFMT_DSP_B:
291 case SND_SOC_DAIFMT_AC97:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200292 mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
293 mcasp_clr_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
Peter Ujfalusi6dfa9a42014-04-04 14:31:42 +0300294 /* No delay after FS */
295 data_delay = 0;
Daniel Mack5296cf22012-10-04 15:08:42 +0200296 break;
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300297 case SND_SOC_DAIFMT_I2S:
Daniel Mack5296cf22012-10-04 15:08:42 +0200298 /* configure a full-word SYNC pulse (LRCLK) */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200299 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
300 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
Peter Ujfalusi6dfa9a42014-04-04 14:31:42 +0300301 /* 1st data bit occur one ACLK cycle after the frame sync */
302 data_delay = 1;
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300303 /* FS need to be inverted */
304 inv_fs = true;
Daniel Mack5296cf22012-10-04 15:08:42 +0200305 break;
Peter Ujfalusi423761e2014-04-04 14:31:46 +0300306 case SND_SOC_DAIFMT_LEFT_J:
307 /* configure a full-word SYNC pulse (LRCLK) */
308 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
309 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
310 /* No delay after FS */
311 data_delay = 0;
312 break;
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300313 default:
314 ret = -EINVAL;
315 goto out;
Daniel Mack5296cf22012-10-04 15:08:42 +0200316 }
317
Peter Ujfalusi6dfa9a42014-04-04 14:31:42 +0300318 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, FSXDLY(data_delay),
319 FSXDLY(3));
320 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, FSRDLY(data_delay),
321 FSRDLY(3));
322
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400323 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
324 case SND_SOC_DAIFMT_CBS_CFS:
325 /* codec is clock and frame slave */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200326 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
327 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400328
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200329 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
330 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400331
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200332 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, ACLKX | ACLKR);
333 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200334 mcasp->bclk_master = 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400335 break;
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400336 case SND_SOC_DAIFMT_CBM_CFS:
337 /* codec is clock master and frame slave */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200338 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
339 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400340
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200341 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
342 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400343
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200344 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, ACLKX | ACLKR);
345 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AFSX | AFSR);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200346 mcasp->bclk_master = 0;
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400347 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400348 case SND_SOC_DAIFMT_CBM_CFM:
349 /* codec is clock and frame master */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200350 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
351 mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400352
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200353 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
354 mcasp_clr_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400355
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200356 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG,
357 ACLKX | AHCLKX | AFSX | ACLKR | AHCLKR | AFSR);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200358 mcasp->bclk_master = 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400359 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400360 default:
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200361 ret = -EINVAL;
362 goto out;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400363 }
364
365 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
366 case SND_SOC_DAIFMT_IB_NF:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200367 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
Peter Ujfalusi74ddd8c2014-04-04 14:31:41 +0300368 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300369 fs_pol_rising = true;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400370 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400371 case SND_SOC_DAIFMT_NB_IF:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200372 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
Peter Ujfalusi74ddd8c2014-04-04 14:31:41 +0300373 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300374 fs_pol_rising = false;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400375 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400376 case SND_SOC_DAIFMT_IB_IF:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200377 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
Peter Ujfalusi74ddd8c2014-04-04 14:31:41 +0300378 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300379 fs_pol_rising = false;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400380 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400381 case SND_SOC_DAIFMT_NB_NF:
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200382 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200383 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300384 fs_pol_rising = true;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400385 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400386 default:
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200387 ret = -EINVAL;
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300388 goto out;
389 }
390
Peter Ujfalusiffd950f2014-04-04 14:31:45 +0300391 if (inv_fs)
392 fs_pol_rising = !fs_pol_rising;
393
Peter Ujfalusi83f12502014-04-04 14:31:44 +0300394 if (fs_pol_rising) {
395 mcasp_clr_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXPOL);
396 mcasp_clr_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRPOL);
397 } else {
398 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG, FSXPOL);
399 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG, FSRPOL);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400400 }
Peter Ujfalusi1d17a042014-01-30 15:21:30 +0200401out:
402 pm_runtime_put_sync(mcasp->dev);
403 return ret;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400404}
405
Jyri Sarha88135432014-08-06 16:47:16 +0300406static int __davinci_mcasp_set_clkdiv(struct snd_soc_dai *dai, int div_id,
407 int div, bool explicit)
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200408{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200409 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200410
411 switch (div_id) {
412 case 0: /* MCLK divider */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200413 mcasp_mod_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200414 AHCLKXDIV(div - 1), AHCLKXDIV_MASK);
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200415 mcasp_mod_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200416 AHCLKRDIV(div - 1), AHCLKRDIV_MASK);
417 break;
418
419 case 1: /* BCLK divider */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200420 mcasp_mod_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200421 ACLKXDIV(div - 1), ACLKXDIV_MASK);
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200422 mcasp_mod_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200423 ACLKRDIV(div - 1), ACLKRDIV_MASK);
Jyri Sarha88135432014-08-06 16:47:16 +0300424 if (explicit)
425 mcasp->bclk_div = div;
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200426 break;
427
Daniel Mack1b3bc062012-12-05 18:20:38 +0100428 case 2: /* BCLK/LRCLK ratio */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200429 mcasp->bclk_lrclk_ratio = div;
Daniel Mack1b3bc062012-12-05 18:20:38 +0100430 break;
431
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200432 default:
433 return -EINVAL;
434 }
435
436 return 0;
437}
438
Jyri Sarha88135432014-08-06 16:47:16 +0300439static int davinci_mcasp_set_clkdiv(struct snd_soc_dai *dai, int div_id,
440 int div)
441{
442 return __davinci_mcasp_set_clkdiv(dai, div_id, div, 1);
443}
444
Daniel Mack5b66aa22012-10-04 15:08:41 +0200445static int davinci_mcasp_set_sysclk(struct snd_soc_dai *dai, int clk_id,
446 unsigned int freq, int dir)
447{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200448 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200449
450 if (dir == SND_SOC_CLOCK_OUT) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200451 mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE);
452 mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE);
453 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AHCLKX);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200454 } else {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200455 mcasp_clr_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE);
456 mcasp_clr_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE);
457 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AHCLKX);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200458 }
459
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200460 mcasp->sysclk_freq = freq;
461
Daniel Mack5b66aa22012-10-04 15:08:41 +0200462 return 0;
463}
464
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200465static int davinci_config_channel_size(struct davinci_mcasp *mcasp,
Daniel Mackba764b32012-12-05 18:20:37 +0100466 int word_length)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400467{
Daniel Mackba764b32012-12-05 18:20:37 +0100468 u32 fmt;
Daniel Mack79671892013-05-16 15:25:01 +0200469 u32 tx_rotate = (word_length / 4) & 0x7;
470 u32 rx_rotate = (32 - word_length) / 4;
Daniel Mackba764b32012-12-05 18:20:37 +0100471 u32 mask = (1ULL << word_length) - 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400472
Daniel Mack1b3bc062012-12-05 18:20:38 +0100473 /*
474 * if s BCLK-to-LRCLK ratio has been configured via the set_clkdiv()
475 * callback, take it into account here. That allows us to for example
476 * send 32 bits per channel to the codec, while only 16 of them carry
477 * audio payload.
Michal Bachratyd486fea2013-04-19 15:28:44 +0200478 * The clock ratio is given for a full period of data (for I2S format
479 * both left and right channels), so it has to be divided by number of
480 * tdm-slots (for I2S - divided by 2).
Daniel Mack1b3bc062012-12-05 18:20:38 +0100481 */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200482 if (mcasp->bclk_lrclk_ratio)
483 word_length = mcasp->bclk_lrclk_ratio / mcasp->tdm_slots;
Daniel Mack1b3bc062012-12-05 18:20:38 +0100484
Daniel Mackba764b32012-12-05 18:20:37 +0100485 /* mapping of the XSSZ bit-field as described in the datasheet */
486 fmt = (word_length >> 1) - 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400487
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200488 if (mcasp->op_mode != DAVINCI_MCASP_DIT_MODE) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200489 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, RXSSZ(fmt),
490 RXSSZ(0x0F));
491 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXSSZ(fmt),
492 TXSSZ(0x0F));
493 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXROT(tx_rotate),
494 TXROT(7));
495 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, RXROT(rx_rotate),
496 RXROT(7));
497 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXMASK_REG, mask);
Yegor Yefremovf5023af2013-04-04 16:13:20 +0200498 }
499
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200500 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXMASK_REG, mask);
Chaithrika U S0c31cf32009-09-15 18:13:29 -0400501
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400502 return 0;
503}
504
Peter Ujfalusi662ffae2014-01-30 15:15:22 +0200505static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream,
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300506 int period_words, int channels)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400507{
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300508 struct davinci_pcm_dma_params *dma_params = &mcasp->dma_params[stream];
509 struct snd_dmaengine_dai_dma_data *dma_data = &mcasp->dma_data[stream];
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400510 int i;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400511 u8 tx_ser = 0;
512 u8 rx_ser = 0;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200513 u8 slots = mcasp->tdm_slots;
Michal Bachraty2952b272013-02-28 16:07:08 +0100514 u8 max_active_serializers = (channels + slots - 1) / slots;
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300515 int active_serializers, numevt, n;
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200516 u32 reg;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400517 /* Default configuration */
Peter Ujfalusi40448e52014-04-04 15:56:30 +0300518 if (mcasp->version < MCASP_VERSION_3)
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200519 mcasp_set_bits(mcasp, DAVINCI_MCASP_PWREMUMGT_REG, MCASP_SOFT);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400520
521 /* All PINS as McASP */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200522 mcasp_set_reg(mcasp, DAVINCI_MCASP_PFUNC_REG, 0x00000000);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400523
524 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200525 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF);
526 mcasp_clr_bits(mcasp, DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400527 } else {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200528 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
529 mcasp_clr_bits(mcasp, DAVINCI_MCASP_REVTCTL_REG, RXDATADMADIS);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400530 }
531
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200532 for (i = 0; i < mcasp->num_serializer; i++) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200533 mcasp_set_bits(mcasp, DAVINCI_MCASP_XRSRCTL_REG(i),
534 mcasp->serial_dir[i]);
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200535 if (mcasp->serial_dir[i] == TX_MODE &&
Michal Bachraty2952b272013-02-28 16:07:08 +0100536 tx_ser < max_active_serializers) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200537 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AXR(i));
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400538 tx_ser++;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200539 } else if (mcasp->serial_dir[i] == RX_MODE &&
Michal Bachraty2952b272013-02-28 16:07:08 +0100540 rx_ser < max_active_serializers) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200541 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AXR(i));
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400542 rx_ser++;
Michal Bachraty2952b272013-02-28 16:07:08 +0100543 } else {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200544 mcasp_mod_bits(mcasp, DAVINCI_MCASP_XRSRCTL_REG(i),
545 SRMOD_INACTIVE, SRMOD_MASK);
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400546 }
547 }
548
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300549 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
550 active_serializers = tx_ser;
551 numevt = mcasp->txnumevt;
552 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
553 } else {
554 active_serializers = rx_ser;
555 numevt = mcasp->rxnumevt;
556 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
557 }
Daniel Mackecf327c2013-03-08 14:19:38 +0100558
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300559 if (active_serializers < max_active_serializers) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200560 dev_warn(mcasp->dev, "stream has more channels (%d) than are "
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300561 "enabled in mcasp (%d)\n", channels,
562 active_serializers * slots);
Daniel Mackecf327c2013-03-08 14:19:38 +0100563 return -EINVAL;
564 }
565
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300566 /* AFIFO is not in use */
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300567 if (!numevt) {
568 /* Configure the burst size for platform drivers */
Peter Ujfalusi33445642014-04-01 15:55:12 +0300569 if (active_serializers > 1) {
570 /*
571 * If more than one serializers are in use we have one
572 * DMA request to provide data for all serializers.
573 * For example if three serializers are enabled the DMA
574 * need to transfer three words per DMA request.
575 */
576 dma_params->fifo_level = active_serializers;
577 dma_data->maxburst = active_serializers;
578 } else {
579 dma_params->fifo_level = 0;
580 dma_data->maxburst = 0;
581 }
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300582 return 0;
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300583 }
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400584
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300585 if (period_words % active_serializers) {
586 dev_err(mcasp->dev, "Invalid combination of period words and "
587 "active serializers: %d, %d\n", period_words,
588 active_serializers);
589 return -EINVAL;
590 }
591
592 /*
593 * Calculate the optimal AFIFO depth for platform side:
594 * The number of words for numevt need to be in steps of active
595 * serializers.
596 */
597 n = numevt % active_serializers;
598 if (n)
599 numevt += (active_serializers - n);
600 while (period_words % numevt && numevt > 0)
601 numevt -= active_serializers;
602 if (numevt <= 0)
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300603 numevt = active_serializers;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400604
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300605 mcasp_mod_bits(mcasp, reg, active_serializers, NUMDMA_MASK);
606 mcasp_mod_bits(mcasp, reg, NUMEVT(numevt), NUMEVT_MASK);
Michal Bachraty2952b272013-02-28 16:07:08 +0100607
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300608 /* Configure the burst size for platform drivers */
Peter Ujfalusi33445642014-04-01 15:55:12 +0300609 if (numevt == 1)
610 numevt = 0;
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300611 dma_params->fifo_level = numevt;
612 dma_data->maxburst = numevt;
613
Michal Bachraty2952b272013-02-28 16:07:08 +0100614 return 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400615}
616
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200617static int mcasp_i2s_hw_param(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400618{
619 int i, active_slots;
620 u32 mask = 0;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200621 u32 busel = 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400622
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200623 if ((mcasp->tdm_slots < 2) || (mcasp->tdm_slots > 32)) {
624 dev_err(mcasp->dev, "tdm slot %d not supported\n",
625 mcasp->tdm_slots);
626 return -EINVAL;
627 }
628
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200629 active_slots = (mcasp->tdm_slots > 31) ? 32 : mcasp->tdm_slots;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400630 for (i = 0; i < active_slots; i++)
631 mask |= (1 << i);
632
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200633 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC);
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400634
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200635 if (!mcasp->dat_port)
636 busel = TXSEL;
637
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200638 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, mask);
639 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, busel | TXORD);
640 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG,
641 FSXMOD(mcasp->tdm_slots), FSXMOD(0x1FF));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400642
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200643 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXTDM_REG, mask);
644 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, busel | RXORD);
645 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG,
646 FSRMOD(mcasp->tdm_slots), FSRMOD(0x1FF));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400647
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200648 return 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400649}
650
651/* S/PDIF */
Daniel Mack64792852014-03-27 11:27:40 +0100652static int mcasp_dit_hw_param(struct davinci_mcasp *mcasp,
653 unsigned int rate)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400654{
Daniel Mack64792852014-03-27 11:27:40 +0100655 u32 cs_value = 0;
656 u8 *cs_bytes = (u8*) &cs_value;
657
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400658 /* Set the TX format : 24 bit right rotation, 32 bit slot, Pad 0
659 and LSB first */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200660 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXROT(6) | TXSSZ(15));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400661
662 /* Set TX frame synch : DIT Mode, 1 bit width, internal, rising edge */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200663 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE | FSXMOD(0x180));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400664
665 /* Set the TX tdm : for all the slots */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200666 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400667
668 /* Set the TX clock controls : div = 1 and internal */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200669 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE | TX_ASYNC);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400670
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200671 mcasp_clr_bits(mcasp, DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400672
673 /* Only 44100 and 48000 are valid, both have the same setting */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200674 mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXDIV(3));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400675
676 /* Enable the DIT */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200677 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXDITCTL_REG, DITEN);
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200678
Daniel Mack64792852014-03-27 11:27:40 +0100679 /* Set S/PDIF channel status bits */
680 cs_bytes[0] = IEC958_AES0_CON_NOT_COPYRIGHT;
681 cs_bytes[1] = IEC958_AES1_CON_PCM_CODER;
682
683 switch (rate) {
684 case 22050:
685 cs_bytes[3] |= IEC958_AES3_CON_FS_22050;
686 break;
687 case 24000:
688 cs_bytes[3] |= IEC958_AES3_CON_FS_24000;
689 break;
690 case 32000:
691 cs_bytes[3] |= IEC958_AES3_CON_FS_32000;
692 break;
693 case 44100:
694 cs_bytes[3] |= IEC958_AES3_CON_FS_44100;
695 break;
696 case 48000:
697 cs_bytes[3] |= IEC958_AES3_CON_FS_48000;
698 break;
699 case 88200:
700 cs_bytes[3] |= IEC958_AES3_CON_FS_88200;
701 break;
702 case 96000:
703 cs_bytes[3] |= IEC958_AES3_CON_FS_96000;
704 break;
705 case 176400:
706 cs_bytes[3] |= IEC958_AES3_CON_FS_176400;
707 break;
708 case 192000:
709 cs_bytes[3] |= IEC958_AES3_CON_FS_192000;
710 break;
711 default:
712 printk(KERN_WARNING "unsupported sampling rate: %d\n", rate);
713 return -EINVAL;
714 }
715
716 mcasp_set_reg(mcasp, DAVINCI_MCASP_DITCSRA_REG, cs_value);
717 mcasp_set_reg(mcasp, DAVINCI_MCASP_DITCSRB_REG, cs_value);
718
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200719 return 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400720}
721
722static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
723 struct snd_pcm_hw_params *params,
724 struct snd_soc_dai *cpu_dai)
725{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200726 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400727 struct davinci_pcm_dma_params *dma_params =
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200728 &mcasp->dma_params[substream->stream];
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400729 int word_length;
Peter Ujfalusia7e46bd2014-02-03 14:51:50 +0200730 int channels = params_channels(params);
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300731 int period_size = params_period_size(params);
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200732 int ret;
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200733
Daniel Mack82675252014-07-16 14:04:41 +0200734 /*
735 * If mcasp is BCLK master, and a BCLK divider was not provided by
736 * the machine driver, we need to calculate the ratio.
737 */
738 if (mcasp->bclk_master && mcasp->bclk_div == 0 && mcasp->sysclk_freq) {
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200739 unsigned int bclk_freq = snd_soc_params_to_bclk(params);
Jyri Sarha09298782014-06-13 12:50:00 +0300740 unsigned int div = mcasp->sysclk_freq / bclk_freq;
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200741 if (mcasp->sysclk_freq % bclk_freq != 0) {
Jyri Sarha09298782014-06-13 12:50:00 +0300742 if (((mcasp->sysclk_freq / div) - bclk_freq) >
743 (bclk_freq - (mcasp->sysclk_freq / (div+1))))
744 div++;
745 dev_warn(mcasp->dev,
746 "Inaccurate BCLK: %u Hz / %u != %u Hz\n",
747 mcasp->sysclk_freq, div, bclk_freq);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200748 }
Jyri Sarha88135432014-08-06 16:47:16 +0300749 __davinci_mcasp_set_clkdiv(cpu_dai, 1, div, 0);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200750 }
751
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300752 ret = mcasp_common_hw_param(mcasp, substream->stream,
753 period_size * channels, channels);
Peter Ujfalusi0f7d9a62014-01-30 15:15:24 +0200754 if (ret)
755 return ret;
756
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200757 if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE)
Daniel Mack64792852014-03-27 11:27:40 +0100758 ret = mcasp_dit_hw_param(mcasp, params_rate(params));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400759 else
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200760 ret = mcasp_i2s_hw_param(mcasp, substream->stream);
761
762 if (ret)
763 return ret;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400764
765 switch (params_format(params)) {
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400766 case SNDRV_PCM_FORMAT_U8:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400767 case SNDRV_PCM_FORMAT_S8:
768 dma_params->data_type = 1;
Daniel Mackba764b32012-12-05 18:20:37 +0100769 word_length = 8;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400770 break;
771
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400772 case SNDRV_PCM_FORMAT_U16_LE:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400773 case SNDRV_PCM_FORMAT_S16_LE:
774 dma_params->data_type = 2;
Daniel Mackba764b32012-12-05 18:20:37 +0100775 word_length = 16;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400776 break;
777
Daniel Mack21eb24d2012-10-09 09:35:16 +0200778 case SNDRV_PCM_FORMAT_U24_3LE:
779 case SNDRV_PCM_FORMAT_S24_3LE:
Daniel Mack21eb24d2012-10-09 09:35:16 +0200780 dma_params->data_type = 3;
Daniel Mackba764b32012-12-05 18:20:37 +0100781 word_length = 24;
Daniel Mack21eb24d2012-10-09 09:35:16 +0200782 break;
783
Daniel Mack6b7fa012012-10-09 11:56:40 +0200784 case SNDRV_PCM_FORMAT_U24_LE:
785 case SNDRV_PCM_FORMAT_S24_LE:
Peter Ujfalusi182bef82014-06-26 08:09:24 +0300786 dma_params->data_type = 4;
787 word_length = 24;
788 break;
789
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400790 case SNDRV_PCM_FORMAT_U32_LE:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400791 case SNDRV_PCM_FORMAT_S32_LE:
792 dma_params->data_type = 4;
Daniel Mackba764b32012-12-05 18:20:37 +0100793 word_length = 32;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400794 break;
795
796 default:
797 printk(KERN_WARNING "davinci-mcasp: unsupported PCM format");
798 return -EINVAL;
799 }
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400800
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300801 if (mcasp->version == MCASP_VERSION_2 && !dma_params->fifo_level)
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400802 dma_params->acnt = 4;
803 else
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400804 dma_params->acnt = dma_params->data_type;
805
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200806 davinci_config_channel_size(mcasp, word_length);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400807
808 return 0;
809}
810
811static int davinci_mcasp_trigger(struct snd_pcm_substream *substream,
812 int cmd, struct snd_soc_dai *cpu_dai)
813{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200814 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400815 int ret = 0;
816
817 switch (cmd) {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400818 case SNDRV_PCM_TRIGGER_RESUME:
Chaithrika U Se473b842010-01-20 17:06:33 +0530819 case SNDRV_PCM_TRIGGER_START:
820 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200821 davinci_mcasp_start(mcasp, substream->stream);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400822 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400823 case SNDRV_PCM_TRIGGER_SUSPEND:
Chaithrika U Sa47979b2009-12-03 18:56:56 +0530824 case SNDRV_PCM_TRIGGER_STOP:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400825 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200826 davinci_mcasp_stop(mcasp, substream->stream);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400827 break;
828
829 default:
830 ret = -EINVAL;
831 }
832
833 return ret;
834}
835
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100836static const struct snd_soc_dai_ops davinci_mcasp_dai_ops = {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400837 .trigger = davinci_mcasp_trigger,
838 .hw_params = davinci_mcasp_hw_params,
839 .set_fmt = davinci_mcasp_set_dai_fmt,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200840 .set_clkdiv = davinci_mcasp_set_clkdiv,
Daniel Mack5b66aa22012-10-04 15:08:41 +0200841 .set_sysclk = davinci_mcasp_set_sysclk,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400842};
843
Peter Ujfalusid5902f692014-04-01 15:55:07 +0300844static int davinci_mcasp_dai_probe(struct snd_soc_dai *dai)
845{
846 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
847
Peter Ujfalusif3f9cfa2014-07-16 15:12:04 +0300848 if (mcasp->version >= MCASP_VERSION_3) {
Peter Ujfalusid5902f692014-04-01 15:55:07 +0300849 /* Using dmaengine PCM */
850 dai->playback_dma_data =
851 &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
852 dai->capture_dma_data =
853 &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE];
854 } else {
855 /* Using davinci-pcm */
856 dai->playback_dma_data = mcasp->dma_params;
857 dai->capture_dma_data = mcasp->dma_params;
858 }
859
860 return 0;
861}
862
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200863#ifdef CONFIG_PM_SLEEP
864static int davinci_mcasp_suspend(struct snd_soc_dai *dai)
865{
866 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Peter Ujfalusi790bb942014-02-03 14:51:52 +0200867 struct davinci_mcasp_context *context = &mcasp->context;
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200868
Peter Ujfalusi790bb942014-02-03 14:51:52 +0200869 context->txfmtctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG);
870 context->rxfmtctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG);
871 context->txfmt = mcasp_get_reg(mcasp, DAVINCI_MCASP_TXFMT_REG);
872 context->rxfmt = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMT_REG);
873 context->aclkxctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG);
874 context->aclkrctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKRCTL_REG);
875 context->pdir = mcasp_get_reg(mcasp, DAVINCI_MCASP_PDIR_REG);
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200876
877 return 0;
878}
879
880static int davinci_mcasp_resume(struct snd_soc_dai *dai)
881{
882 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Peter Ujfalusi790bb942014-02-03 14:51:52 +0200883 struct davinci_mcasp_context *context = &mcasp->context;
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200884
Peter Ujfalusi790bb942014-02-03 14:51:52 +0200885 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG, context->txfmtctl);
886 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG, context->rxfmtctl);
887 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMT_REG, context->txfmt);
888 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXFMT_REG, context->rxfmt);
889 mcasp_set_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, context->aclkxctl);
890 mcasp_set_reg(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, context->aclkrctl);
891 mcasp_set_reg(mcasp, DAVINCI_MCASP_PDIR_REG, context->pdir);
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200892
893 return 0;
894}
895#else
896#define davinci_mcasp_suspend NULL
897#define davinci_mcasp_resume NULL
898#endif
899
Peter Ujfalusied29cd52013-11-14 11:35:22 +0200900#define DAVINCI_MCASP_RATES SNDRV_PCM_RATE_8000_192000
901
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400902#define DAVINCI_MCASP_PCM_FMTS (SNDRV_PCM_FMTBIT_S8 | \
903 SNDRV_PCM_FMTBIT_U8 | \
904 SNDRV_PCM_FMTBIT_S16_LE | \
905 SNDRV_PCM_FMTBIT_U16_LE | \
Daniel Mack21eb24d2012-10-09 09:35:16 +0200906 SNDRV_PCM_FMTBIT_S24_LE | \
907 SNDRV_PCM_FMTBIT_U24_LE | \
908 SNDRV_PCM_FMTBIT_S24_3LE | \
909 SNDRV_PCM_FMTBIT_U24_3LE | \
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400910 SNDRV_PCM_FMTBIT_S32_LE | \
911 SNDRV_PCM_FMTBIT_U32_LE)
912
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000913static struct snd_soc_dai_driver davinci_mcasp_dai[] = {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400914 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000915 .name = "davinci-mcasp.0",
Peter Ujfalusid5902f692014-04-01 15:55:07 +0300916 .probe = davinci_mcasp_dai_probe,
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200917 .suspend = davinci_mcasp_suspend,
918 .resume = davinci_mcasp_resume,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400919 .playback = {
920 .channels_min = 2,
Michal Bachraty2952b272013-02-28 16:07:08 +0100921 .channels_max = 32 * 16,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400922 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400923 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400924 },
925 .capture = {
926 .channels_min = 2,
Michal Bachraty2952b272013-02-28 16:07:08 +0100927 .channels_max = 32 * 16,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400928 .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 {
Peter Ujfalusi58e48d92013-11-14 11:35:24 +0200935 .name = "davinci-mcasp.1",
Peter Ujfalusid5902f692014-04-01 15:55:07 +0300936 .probe = davinci_mcasp_dai_probe,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400937 .playback = {
938 .channels_min = 1,
939 .channels_max = 384,
940 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400941 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400942 },
943 .ops = &davinci_mcasp_dai_ops,
944 },
945
946};
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400947
Kuninori Morimotoeeef0ed2013-03-21 03:31:19 -0700948static const struct snd_soc_component_driver davinci_mcasp_component = {
949 .name = "davinci-mcasp",
950};
951
Jyri Sarha256ba182013-10-18 18:37:42 +0300952/* Some HW specific values and defaults. The rest is filled in from DT. */
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200953static struct davinci_mcasp_pdata dm646x_mcasp_pdata = {
Jyri Sarha256ba182013-10-18 18:37:42 +0300954 .tx_dma_offset = 0x400,
955 .rx_dma_offset = 0x400,
956 .asp_chan_q = EVENTQ_0,
957 .version = MCASP_VERSION_1,
958};
959
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200960static struct davinci_mcasp_pdata da830_mcasp_pdata = {
Jyri Sarha256ba182013-10-18 18:37:42 +0300961 .tx_dma_offset = 0x2000,
962 .rx_dma_offset = 0x2000,
963 .asp_chan_q = EVENTQ_0,
964 .version = MCASP_VERSION_2,
965};
966
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200967static struct davinci_mcasp_pdata am33xx_mcasp_pdata = {
Jyri Sarha256ba182013-10-18 18:37:42 +0300968 .tx_dma_offset = 0,
969 .rx_dma_offset = 0,
970 .asp_chan_q = EVENTQ_0,
971 .version = MCASP_VERSION_3,
972};
973
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200974static struct davinci_mcasp_pdata dra7_mcasp_pdata = {
Peter Ujfalusi453c4992013-11-14 11:35:34 +0200975 .tx_dma_offset = 0x200,
976 .rx_dma_offset = 0x284,
977 .asp_chan_q = EVENTQ_0,
978 .version = MCASP_VERSION_4,
979};
980
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530981static const struct of_device_id mcasp_dt_ids[] = {
982 {
983 .compatible = "ti,dm646x-mcasp-audio",
Jyri Sarha256ba182013-10-18 18:37:42 +0300984 .data = &dm646x_mcasp_pdata,
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530985 },
986 {
987 .compatible = "ti,da830-mcasp-audio",
Jyri Sarha256ba182013-10-18 18:37:42 +0300988 .data = &da830_mcasp_pdata,
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530989 },
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530990 {
Jyri Sarha3af9e032013-10-18 18:37:44 +0300991 .compatible = "ti,am33xx-mcasp-audio",
Peter Ujfalusib14899d2013-11-14 11:35:37 +0200992 .data = &am33xx_mcasp_pdata,
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530993 },
Peter Ujfalusi453c4992013-11-14 11:35:34 +0200994 {
995 .compatible = "ti,dra7-mcasp-audio",
996 .data = &dra7_mcasp_pdata,
997 },
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530998 { /* sentinel */ }
999};
1000MODULE_DEVICE_TABLE(of, mcasp_dt_ids);
1001
Peter Ujfalusiae726e92013-11-14 11:35:35 +02001002static int mcasp_reparent_fck(struct platform_device *pdev)
1003{
1004 struct device_node *node = pdev->dev.of_node;
1005 struct clk *gfclk, *parent_clk;
1006 const char *parent_name;
1007 int ret;
1008
1009 if (!node)
1010 return 0;
1011
1012 parent_name = of_get_property(node, "fck_parent", NULL);
1013 if (!parent_name)
1014 return 0;
1015
1016 gfclk = clk_get(&pdev->dev, "fck");
1017 if (IS_ERR(gfclk)) {
1018 dev_err(&pdev->dev, "failed to get fck\n");
1019 return PTR_ERR(gfclk);
1020 }
1021
1022 parent_clk = clk_get(NULL, parent_name);
1023 if (IS_ERR(parent_clk)) {
1024 dev_err(&pdev->dev, "failed to get parent clock\n");
1025 ret = PTR_ERR(parent_clk);
1026 goto err1;
1027 }
1028
1029 ret = clk_set_parent(gfclk, parent_clk);
1030 if (ret) {
1031 dev_err(&pdev->dev, "failed to reparent fck\n");
1032 goto err2;
1033 }
1034
1035err2:
1036 clk_put(parent_clk);
1037err1:
1038 clk_put(gfclk);
1039 return ret;
1040}
1041
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001042static struct davinci_mcasp_pdata *davinci_mcasp_set_pdata_from_of(
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301043 struct platform_device *pdev)
1044{
1045 struct device_node *np = pdev->dev.of_node;
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001046 struct davinci_mcasp_pdata *pdata = NULL;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301047 const struct of_device_id *match =
Sachin Kamatea421eb2013-05-22 16:53:37 +05301048 of_match_device(mcasp_dt_ids, &pdev->dev);
Jyri Sarha4023fe62013-10-18 18:37:43 +03001049 struct of_phandle_args dma_spec;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301050
1051 const u32 *of_serial_dir32;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301052 u32 val;
1053 int i, ret = 0;
1054
1055 if (pdev->dev.platform_data) {
1056 pdata = pdev->dev.platform_data;
1057 return pdata;
1058 } else if (match) {
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001059 pdata = (struct davinci_mcasp_pdata*) match->data;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301060 } else {
1061 /* control shouldn't reach here. something is wrong */
1062 ret = -EINVAL;
1063 goto nodata;
1064 }
1065
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301066 ret = of_property_read_u32(np, "op-mode", &val);
1067 if (ret >= 0)
1068 pdata->op_mode = val;
1069
1070 ret = of_property_read_u32(np, "tdm-slots", &val);
Michal Bachraty2952b272013-02-28 16:07:08 +01001071 if (ret >= 0) {
1072 if (val < 2 || val > 32) {
1073 dev_err(&pdev->dev,
1074 "tdm-slots must be in rage [2-32]\n");
1075 ret = -EINVAL;
1076 goto nodata;
1077 }
1078
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301079 pdata->tdm_slots = val;
Michal Bachraty2952b272013-02-28 16:07:08 +01001080 }
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301081
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301082 of_serial_dir32 = of_get_property(np, "serial-dir", &val);
1083 val /= sizeof(u32);
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301084 if (of_serial_dir32) {
Peter Ujfalusi1427e662013-10-18 18:37:46 +03001085 u8 *of_serial_dir = devm_kzalloc(&pdev->dev,
1086 (sizeof(*of_serial_dir) * val),
1087 GFP_KERNEL);
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301088 if (!of_serial_dir) {
1089 ret = -ENOMEM;
1090 goto nodata;
1091 }
1092
Peter Ujfalusi1427e662013-10-18 18:37:46 +03001093 for (i = 0; i < val; i++)
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301094 of_serial_dir[i] = be32_to_cpup(&of_serial_dir32[i]);
1095
Peter Ujfalusi1427e662013-10-18 18:37:46 +03001096 pdata->num_serializer = val;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301097 pdata->serial_dir = of_serial_dir;
1098 }
1099
Jyri Sarha4023fe62013-10-18 18:37:43 +03001100 ret = of_property_match_string(np, "dma-names", "tx");
1101 if (ret < 0)
1102 goto nodata;
1103
1104 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
1105 &dma_spec);
1106 if (ret < 0)
1107 goto nodata;
1108
1109 pdata->tx_dma_channel = dma_spec.args[0];
1110
1111 ret = of_property_match_string(np, "dma-names", "rx");
1112 if (ret < 0)
1113 goto nodata;
1114
1115 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
1116 &dma_spec);
1117 if (ret < 0)
1118 goto nodata;
1119
1120 pdata->rx_dma_channel = dma_spec.args[0];
1121
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301122 ret = of_property_read_u32(np, "tx-num-evt", &val);
1123 if (ret >= 0)
1124 pdata->txnumevt = val;
1125
1126 ret = of_property_read_u32(np, "rx-num-evt", &val);
1127 if (ret >= 0)
1128 pdata->rxnumevt = val;
1129
1130 ret = of_property_read_u32(np, "sram-size-playback", &val);
1131 if (ret >= 0)
1132 pdata->sram_size_playback = val;
1133
1134 ret = of_property_read_u32(np, "sram-size-capture", &val);
1135 if (ret >= 0)
1136 pdata->sram_size_capture = val;
1137
1138 return pdata;
1139
1140nodata:
1141 if (ret < 0) {
1142 dev_err(&pdev->dev, "Error populating platform data, err %d\n",
1143 ret);
1144 pdata = NULL;
1145 }
1146 return pdata;
1147}
1148
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001149static int davinci_mcasp_probe(struct platform_device *pdev)
1150{
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001151 struct davinci_pcm_dma_params *dma_params;
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001152 struct snd_dmaengine_dai_dma_data *dma_data;
Jyri Sarha256ba182013-10-18 18:37:42 +03001153 struct resource *mem, *ioarea, *res, *dat;
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001154 struct davinci_mcasp_pdata *pdata;
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001155 struct davinci_mcasp *mcasp;
Julia Lawall96d31e22011-12-29 17:51:21 +01001156 int ret;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001157
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301158 if (!pdev->dev.platform_data && !pdev->dev.of_node) {
1159 dev_err(&pdev->dev, "No platform data supplied\n");
1160 return -EINVAL;
1161 }
1162
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001163 mcasp = devm_kzalloc(&pdev->dev, sizeof(struct davinci_mcasp),
Julia Lawall96d31e22011-12-29 17:51:21 +01001164 GFP_KERNEL);
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001165 if (!mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001166 return -ENOMEM;
1167
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301168 pdata = davinci_mcasp_set_pdata_from_of(pdev);
1169 if (!pdata) {
1170 dev_err(&pdev->dev, "no platform data\n");
1171 return -EINVAL;
1172 }
1173
Jyri Sarha256ba182013-10-18 18:37:42 +03001174 mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001175 if (!mem) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001176 dev_warn(mcasp->dev,
Jyri Sarha256ba182013-10-18 18:37:42 +03001177 "\"mpu\" mem resource not found, using index 0\n");
1178 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1179 if (!mem) {
1180 dev_err(&pdev->dev, "no mem resource?\n");
1181 return -ENODEV;
1182 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001183 }
1184
Julia Lawall96d31e22011-12-29 17:51:21 +01001185 ioarea = devm_request_mem_region(&pdev->dev, mem->start,
Vaibhav Bediad852f4462011-02-09 18:39:52 +05301186 resource_size(mem), pdev->name);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001187 if (!ioarea) {
1188 dev_err(&pdev->dev, "Audio region already claimed\n");
Julia Lawall96d31e22011-12-29 17:51:21 +01001189 return -EBUSY;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001190 }
1191
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301192 pm_runtime_enable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001193
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301194 ret = pm_runtime_get_sync(&pdev->dev);
1195 if (IS_ERR_VALUE(ret)) {
1196 dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
1197 return ret;
1198 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001199
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001200 mcasp->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
1201 if (!mcasp->base) {
Vaibhav Bedia4f82f022011-02-09 18:39:54 +05301202 dev_err(&pdev->dev, "ioremap failed\n");
1203 ret = -ENOMEM;
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001204 goto err;
Vaibhav Bedia4f82f022011-02-09 18:39:54 +05301205 }
1206
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001207 mcasp->op_mode = pdata->op_mode;
1208 mcasp->tdm_slots = pdata->tdm_slots;
1209 mcasp->num_serializer = pdata->num_serializer;
1210 mcasp->serial_dir = pdata->serial_dir;
1211 mcasp->version = pdata->version;
1212 mcasp->txnumevt = pdata->txnumevt;
1213 mcasp->rxnumevt = pdata->rxnumevt;
Peter Ujfalusi487dce82013-11-14 11:35:31 +02001214
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001215 mcasp->dev = &pdev->dev;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001216
Jyri Sarha256ba182013-10-18 18:37:42 +03001217 dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001218 if (dat)
1219 mcasp->dat_port = true;
Jyri Sarha256ba182013-10-18 18:37:42 +03001220
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001221 dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_PLAYBACK];
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001222 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001223 dma_params->asp_chan_q = pdata->asp_chan_q;
1224 dma_params->ram_chan_q = pdata->ram_chan_q;
1225 dma_params->sram_pool = pdata->sram_pool;
1226 dma_params->sram_size = pdata->sram_size_playback;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001227 if (dat)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001228 dma_params->dma_addr = dat->start;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001229 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001230 dma_params->dma_addr = mem->start + pdata->tx_dma_offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001231
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001232 /* Unconditional dmaengine stuff */
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001233 dma_data->addr = dma_params->dma_addr;
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001234
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001235 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
Jyri Sarha4023fe62013-10-18 18:37:43 +03001236 if (res)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001237 dma_params->channel = res->start;
Jyri Sarha4023fe62013-10-18 18:37:43 +03001238 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001239 dma_params->channel = pdata->tx_dma_channel;
Troy Kisky92e2a6f2009-09-11 14:29:03 -07001240
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001241 /* dmaengine filter data for DT and non-DT boot */
1242 if (pdev->dev.of_node)
1243 dma_data->filter_data = "tx";
1244 else
1245 dma_data->filter_data = &dma_params->channel;
1246
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001247 dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_CAPTURE];
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001248 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE];
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001249 dma_params->asp_chan_q = pdata->asp_chan_q;
1250 dma_params->ram_chan_q = pdata->ram_chan_q;
1251 dma_params->sram_pool = pdata->sram_pool;
1252 dma_params->sram_size = pdata->sram_size_capture;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001253 if (dat)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001254 dma_params->dma_addr = dat->start;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001255 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001256 dma_params->dma_addr = mem->start + pdata->rx_dma_offset;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001257
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001258 /* Unconditional dmaengine stuff */
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001259 dma_data->addr = dma_params->dma_addr;
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001260
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001261 if (mcasp->version < MCASP_VERSION_3) {
1262 mcasp->fifo_base = DAVINCI_MCASP_V2_AFIFO_BASE;
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001263 /* dma_params->dma_addr is pointing to the data port address */
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001264 mcasp->dat_port = true;
1265 } else {
1266 mcasp->fifo_base = DAVINCI_MCASP_V3_AFIFO_BASE;
1267 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001268
1269 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
Jyri Sarha4023fe62013-10-18 18:37:43 +03001270 if (res)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001271 dma_params->channel = res->start;
Jyri Sarha4023fe62013-10-18 18:37:43 +03001272 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001273 dma_params->channel = pdata->rx_dma_channel;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001274
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001275 /* dmaengine filter data for DT and non-DT boot */
1276 if (pdev->dev.of_node)
1277 dma_data->filter_data = "rx";
1278 else
1279 dma_data->filter_data = &dma_params->channel;
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001280
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001281 dev_set_drvdata(&pdev->dev, mcasp);
Peter Ujfalusiae726e92013-11-14 11:35:35 +02001282
1283 mcasp_reparent_fck(pdev);
1284
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001285 ret = devm_snd_soc_register_component(&pdev->dev,
1286 &davinci_mcasp_component,
1287 &davinci_mcasp_dai[pdata->op_mode], 1);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001288
1289 if (ret != 0)
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001290 goto err;
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +05301291
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001292 switch (mcasp->version) {
Jyri Sarha7f28f352014-06-13 12:49:59 +03001293#if IS_BUILTIN(CONFIG_SND_DAVINCI_SOC) || \
1294 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \
1295 IS_MODULE(CONFIG_SND_DAVINCI_SOC))
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001296 case MCASP_VERSION_1:
1297 case MCASP_VERSION_2:
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001298 ret = davinci_soc_platform_register(&pdev->dev);
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001299 break;
Jyri Sarha7f28f352014-06-13 12:49:59 +03001300#endif
Peter Ujfalusif3f9cfa2014-07-16 15:12:04 +03001301#if IS_BUILTIN(CONFIG_SND_EDMA_SOC) || \
1302 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \
1303 IS_MODULE(CONFIG_SND_EDMA_SOC))
1304 case MCASP_VERSION_3:
1305 ret = edma_pcm_platform_register(&pdev->dev);
1306 break;
1307#endif
Jyri Sarha7f28f352014-06-13 12:49:59 +03001308#if IS_BUILTIN(CONFIG_SND_OMAP_SOC) || \
1309 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \
1310 IS_MODULE(CONFIG_SND_OMAP_SOC))
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001311 case MCASP_VERSION_4:
1312 ret = omap_pcm_platform_register(&pdev->dev);
1313 break;
Jyri Sarha7f28f352014-06-13 12:49:59 +03001314#endif
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001315 default:
1316 dev_err(&pdev->dev, "Invalid McASP version: %d\n",
1317 mcasp->version);
1318 ret = -EINVAL;
1319 break;
1320 }
1321
1322 if (ret) {
1323 dev_err(&pdev->dev, "register PCM failed: %d\n", ret);
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001324 goto err;
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +05301325 }
1326
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001327 return 0;
1328
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001329err:
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301330 pm_runtime_put_sync(&pdev->dev);
1331 pm_runtime_disable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001332 return ret;
1333}
1334
1335static int davinci_mcasp_remove(struct platform_device *pdev)
1336{
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301337 pm_runtime_put_sync(&pdev->dev);
1338 pm_runtime_disable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001339
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001340 return 0;
1341}
1342
1343static struct platform_driver davinci_mcasp_driver = {
1344 .probe = davinci_mcasp_probe,
1345 .remove = davinci_mcasp_remove,
1346 .driver = {
1347 .name = "davinci-mcasp",
1348 .owner = THIS_MODULE,
Sachin Kamatea421eb2013-05-22 16:53:37 +05301349 .of_match_table = mcasp_dt_ids,
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001350 },
1351};
1352
Axel Linf9b8a512011-11-25 10:09:27 +08001353module_platform_driver(davinci_mcasp_driver);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001354
1355MODULE_AUTHOR("Steve Chen");
1356MODULE_DESCRIPTION("TI DAVINCI McASP SoC Interface");
1357MODULE_LICENSE("GPL");