blob: c28508da34cf3ba4354ba6d54de685a03d112ca4 [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
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200406static int davinci_mcasp_set_clkdiv(struct snd_soc_dai *dai, int div_id, int div)
407{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200408 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200409
410 switch (div_id) {
411 case 0: /* MCLK divider */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200412 mcasp_mod_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200413 AHCLKXDIV(div - 1), AHCLKXDIV_MASK);
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200414 mcasp_mod_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200415 AHCLKRDIV(div - 1), AHCLKRDIV_MASK);
416 break;
417
418 case 1: /* BCLK divider */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200419 mcasp_mod_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200420 ACLKXDIV(div - 1), ACLKXDIV_MASK);
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200421 mcasp_mod_bits(mcasp, DAVINCI_MCASP_ACLKRCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200422 ACLKRDIV(div - 1), ACLKRDIV_MASK);
Daniel Mack82675252014-07-16 14:04:41 +0200423 mcasp->bclk_div = div;
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200424 break;
425
Daniel Mack1b3bc062012-12-05 18:20:38 +0100426 case 2: /* BCLK/LRCLK ratio */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200427 mcasp->bclk_lrclk_ratio = div;
Daniel Mack1b3bc062012-12-05 18:20:38 +0100428 break;
429
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200430 default:
431 return -EINVAL;
432 }
433
434 return 0;
435}
436
Daniel Mack5b66aa22012-10-04 15:08:41 +0200437static int davinci_mcasp_set_sysclk(struct snd_soc_dai *dai, int clk_id,
438 unsigned int freq, int dir)
439{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200440 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200441
442 if (dir == SND_SOC_CLOCK_OUT) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200443 mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE);
444 mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE);
445 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AHCLKX);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200446 } else {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200447 mcasp_clr_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE);
448 mcasp_clr_bits(mcasp, DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE);
449 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AHCLKX);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200450 }
451
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200452 mcasp->sysclk_freq = freq;
453
Daniel Mack5b66aa22012-10-04 15:08:41 +0200454 return 0;
455}
456
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200457static int davinci_config_channel_size(struct davinci_mcasp *mcasp,
Daniel Mackba764b32012-12-05 18:20:37 +0100458 int word_length)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400459{
Daniel Mackba764b32012-12-05 18:20:37 +0100460 u32 fmt;
Daniel Mack79671892013-05-16 15:25:01 +0200461 u32 tx_rotate = (word_length / 4) & 0x7;
462 u32 rx_rotate = (32 - word_length) / 4;
Daniel Mackba764b32012-12-05 18:20:37 +0100463 u32 mask = (1ULL << word_length) - 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400464
Daniel Mack1b3bc062012-12-05 18:20:38 +0100465 /*
466 * if s BCLK-to-LRCLK ratio has been configured via the set_clkdiv()
467 * callback, take it into account here. That allows us to for example
468 * send 32 bits per channel to the codec, while only 16 of them carry
469 * audio payload.
Michal Bachratyd486fea2013-04-19 15:28:44 +0200470 * The clock ratio is given for a full period of data (for I2S format
471 * both left and right channels), so it has to be divided by number of
472 * tdm-slots (for I2S - divided by 2).
Daniel Mack1b3bc062012-12-05 18:20:38 +0100473 */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200474 if (mcasp->bclk_lrclk_ratio)
475 word_length = mcasp->bclk_lrclk_ratio / mcasp->tdm_slots;
Daniel Mack1b3bc062012-12-05 18:20:38 +0100476
Daniel Mackba764b32012-12-05 18:20:37 +0100477 /* mapping of the XSSZ bit-field as described in the datasheet */
478 fmt = (word_length >> 1) - 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400479
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200480 if (mcasp->op_mode != DAVINCI_MCASP_DIT_MODE) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200481 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, RXSSZ(fmt),
482 RXSSZ(0x0F));
483 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXSSZ(fmt),
484 TXSSZ(0x0F));
485 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXROT(tx_rotate),
486 TXROT(7));
487 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, RXROT(rx_rotate),
488 RXROT(7));
489 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXMASK_REG, mask);
Yegor Yefremovf5023af2013-04-04 16:13:20 +0200490 }
491
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200492 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXMASK_REG, mask);
Chaithrika U S0c31cf32009-09-15 18:13:29 -0400493
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400494 return 0;
495}
496
Peter Ujfalusi662ffae2014-01-30 15:15:22 +0200497static int mcasp_common_hw_param(struct davinci_mcasp *mcasp, int stream,
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300498 int period_words, int channels)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400499{
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300500 struct davinci_pcm_dma_params *dma_params = &mcasp->dma_params[stream];
501 struct snd_dmaengine_dai_dma_data *dma_data = &mcasp->dma_data[stream];
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400502 int i;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400503 u8 tx_ser = 0;
504 u8 rx_ser = 0;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200505 u8 slots = mcasp->tdm_slots;
Michal Bachraty2952b272013-02-28 16:07:08 +0100506 u8 max_active_serializers = (channels + slots - 1) / slots;
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300507 int active_serializers, numevt, n;
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200508 u32 reg;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400509 /* Default configuration */
Peter Ujfalusi40448e52014-04-04 15:56:30 +0300510 if (mcasp->version < MCASP_VERSION_3)
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200511 mcasp_set_bits(mcasp, DAVINCI_MCASP_PWREMUMGT_REG, MCASP_SOFT);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400512
513 /* All PINS as McASP */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200514 mcasp_set_reg(mcasp, DAVINCI_MCASP_PFUNC_REG, 0x00000000);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400515
516 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200517 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF);
518 mcasp_clr_bits(mcasp, DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400519 } else {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200520 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
521 mcasp_clr_bits(mcasp, DAVINCI_MCASP_REVTCTL_REG, RXDATADMADIS);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400522 }
523
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200524 for (i = 0; i < mcasp->num_serializer; i++) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200525 mcasp_set_bits(mcasp, DAVINCI_MCASP_XRSRCTL_REG(i),
526 mcasp->serial_dir[i]);
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200527 if (mcasp->serial_dir[i] == TX_MODE &&
Michal Bachraty2952b272013-02-28 16:07:08 +0100528 tx_ser < max_active_serializers) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200529 mcasp_set_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AXR(i));
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400530 tx_ser++;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200531 } else if (mcasp->serial_dir[i] == RX_MODE &&
Michal Bachraty2952b272013-02-28 16:07:08 +0100532 rx_ser < max_active_serializers) {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200533 mcasp_clr_bits(mcasp, DAVINCI_MCASP_PDIR_REG, AXR(i));
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400534 rx_ser++;
Michal Bachraty2952b272013-02-28 16:07:08 +0100535 } else {
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200536 mcasp_mod_bits(mcasp, DAVINCI_MCASP_XRSRCTL_REG(i),
537 SRMOD_INACTIVE, SRMOD_MASK);
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400538 }
539 }
540
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300541 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
542 active_serializers = tx_ser;
543 numevt = mcasp->txnumevt;
544 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
545 } else {
546 active_serializers = rx_ser;
547 numevt = mcasp->rxnumevt;
548 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
549 }
Daniel Mackecf327c2013-03-08 14:19:38 +0100550
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300551 if (active_serializers < max_active_serializers) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200552 dev_warn(mcasp->dev, "stream has more channels (%d) than are "
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300553 "enabled in mcasp (%d)\n", channels,
554 active_serializers * slots);
Daniel Mackecf327c2013-03-08 14:19:38 +0100555 return -EINVAL;
556 }
557
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300558 /* AFIFO is not in use */
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300559 if (!numevt) {
560 /* Configure the burst size for platform drivers */
Peter Ujfalusi33445642014-04-01 15:55:12 +0300561 if (active_serializers > 1) {
562 /*
563 * If more than one serializers are in use we have one
564 * DMA request to provide data for all serializers.
565 * For example if three serializers are enabled the DMA
566 * need to transfer three words per DMA request.
567 */
568 dma_params->fifo_level = active_serializers;
569 dma_data->maxburst = active_serializers;
570 } else {
571 dma_params->fifo_level = 0;
572 dma_data->maxburst = 0;
573 }
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300574 return 0;
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300575 }
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400576
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300577 if (period_words % active_serializers) {
578 dev_err(mcasp->dev, "Invalid combination of period words and "
579 "active serializers: %d, %d\n", period_words,
580 active_serializers);
581 return -EINVAL;
582 }
583
584 /*
585 * Calculate the optimal AFIFO depth for platform side:
586 * The number of words for numevt need to be in steps of active
587 * serializers.
588 */
589 n = numevt % active_serializers;
590 if (n)
591 numevt += (active_serializers - n);
592 while (period_words % numevt && numevt > 0)
593 numevt -= active_serializers;
594 if (numevt <= 0)
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300595 numevt = active_serializers;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400596
Peter Ujfalusi0bf0e8a2014-04-01 15:55:09 +0300597 mcasp_mod_bits(mcasp, reg, active_serializers, NUMDMA_MASK);
598 mcasp_mod_bits(mcasp, reg, NUMEVT(numevt), NUMEVT_MASK);
Michal Bachraty2952b272013-02-28 16:07:08 +0100599
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300600 /* Configure the burst size for platform drivers */
Peter Ujfalusi33445642014-04-01 15:55:12 +0300601 if (numevt == 1)
602 numevt = 0;
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300603 dma_params->fifo_level = numevt;
604 dma_data->maxburst = numevt;
605
Michal Bachraty2952b272013-02-28 16:07:08 +0100606 return 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400607}
608
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200609static int mcasp_i2s_hw_param(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400610{
611 int i, active_slots;
612 u32 mask = 0;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200613 u32 busel = 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400614
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200615 if ((mcasp->tdm_slots < 2) || (mcasp->tdm_slots > 32)) {
616 dev_err(mcasp->dev, "tdm slot %d not supported\n",
617 mcasp->tdm_slots);
618 return -EINVAL;
619 }
620
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200621 active_slots = (mcasp->tdm_slots > 31) ? 32 : mcasp->tdm_slots;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400622 for (i = 0; i < active_slots; i++)
623 mask |= (1 << i);
624
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200625 mcasp_clr_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC);
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400626
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200627 if (!mcasp->dat_port)
628 busel = TXSEL;
629
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200630 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, mask);
631 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, busel | TXORD);
632 mcasp_mod_bits(mcasp, DAVINCI_MCASP_TXFMCTL_REG,
633 FSXMOD(mcasp->tdm_slots), FSXMOD(0x1FF));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400634
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200635 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXTDM_REG, mask);
636 mcasp_set_bits(mcasp, DAVINCI_MCASP_RXFMT_REG, busel | RXORD);
637 mcasp_mod_bits(mcasp, DAVINCI_MCASP_RXFMCTL_REG,
638 FSRMOD(mcasp->tdm_slots), FSRMOD(0x1FF));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400639
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200640 return 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400641}
642
643/* S/PDIF */
Daniel Mack64792852014-03-27 11:27:40 +0100644static int mcasp_dit_hw_param(struct davinci_mcasp *mcasp,
645 unsigned int rate)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400646{
Daniel Mack64792852014-03-27 11:27:40 +0100647 u32 cs_value = 0;
648 u8 *cs_bytes = (u8*) &cs_value;
649
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400650 /* Set the TX format : 24 bit right rotation, 32 bit slot, Pad 0
651 and LSB first */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200652 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXFMT_REG, TXROT(6) | TXSSZ(15));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400653
654 /* Set TX frame synch : DIT Mode, 1 bit width, internal, rising edge */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200655 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG, AFSXE | FSXMOD(0x180));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400656
657 /* Set the TX tdm : for all the slots */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200658 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXTDM_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400659
660 /* Set the TX clock controls : div = 1 and internal */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200661 mcasp_set_bits(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE | TX_ASYNC);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400662
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200663 mcasp_clr_bits(mcasp, DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400664
665 /* Only 44100 and 48000 are valid, both have the same setting */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200666 mcasp_set_bits(mcasp, DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXDIV(3));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400667
668 /* Enable the DIT */
Peter Ujfalusif68205a2013-11-14 11:35:36 +0200669 mcasp_set_bits(mcasp, DAVINCI_MCASP_TXDITCTL_REG, DITEN);
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200670
Daniel Mack64792852014-03-27 11:27:40 +0100671 /* Set S/PDIF channel status bits */
672 cs_bytes[0] = IEC958_AES0_CON_NOT_COPYRIGHT;
673 cs_bytes[1] = IEC958_AES1_CON_PCM_CODER;
674
675 switch (rate) {
676 case 22050:
677 cs_bytes[3] |= IEC958_AES3_CON_FS_22050;
678 break;
679 case 24000:
680 cs_bytes[3] |= IEC958_AES3_CON_FS_24000;
681 break;
682 case 32000:
683 cs_bytes[3] |= IEC958_AES3_CON_FS_32000;
684 break;
685 case 44100:
686 cs_bytes[3] |= IEC958_AES3_CON_FS_44100;
687 break;
688 case 48000:
689 cs_bytes[3] |= IEC958_AES3_CON_FS_48000;
690 break;
691 case 88200:
692 cs_bytes[3] |= IEC958_AES3_CON_FS_88200;
693 break;
694 case 96000:
695 cs_bytes[3] |= IEC958_AES3_CON_FS_96000;
696 break;
697 case 176400:
698 cs_bytes[3] |= IEC958_AES3_CON_FS_176400;
699 break;
700 case 192000:
701 cs_bytes[3] |= IEC958_AES3_CON_FS_192000;
702 break;
703 default:
704 printk(KERN_WARNING "unsupported sampling rate: %d\n", rate);
705 return -EINVAL;
706 }
707
708 mcasp_set_reg(mcasp, DAVINCI_MCASP_DITCSRA_REG, cs_value);
709 mcasp_set_reg(mcasp, DAVINCI_MCASP_DITCSRB_REG, cs_value);
710
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200711 return 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400712}
713
714static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
715 struct snd_pcm_hw_params *params,
716 struct snd_soc_dai *cpu_dai)
717{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200718 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400719 struct davinci_pcm_dma_params *dma_params =
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200720 &mcasp->dma_params[substream->stream];
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400721 int word_length;
Peter Ujfalusia7e46bd2014-02-03 14:51:50 +0200722 int channels = params_channels(params);
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300723 int period_size = params_period_size(params);
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200724 int ret;
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200725
Daniel Mack82675252014-07-16 14:04:41 +0200726 /*
727 * If mcasp is BCLK master, and a BCLK divider was not provided by
728 * the machine driver, we need to calculate the ratio.
729 */
730 if (mcasp->bclk_master && mcasp->bclk_div == 0 && mcasp->sysclk_freq) {
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200731 unsigned int bclk_freq = snd_soc_params_to_bclk(params);
Jyri Sarha09298782014-06-13 12:50:00 +0300732 unsigned int div = mcasp->sysclk_freq / bclk_freq;
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200733 if (mcasp->sysclk_freq % bclk_freq != 0) {
Jyri Sarha09298782014-06-13 12:50:00 +0300734 if (((mcasp->sysclk_freq / div) - bclk_freq) >
735 (bclk_freq - (mcasp->sysclk_freq / (div+1))))
736 div++;
737 dev_warn(mcasp->dev,
738 "Inaccurate BCLK: %u Hz / %u != %u Hz\n",
739 mcasp->sysclk_freq, div, bclk_freq);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200740 }
Jyri Sarha09298782014-06-13 12:50:00 +0300741 davinci_mcasp_set_clkdiv(cpu_dai, 1, div);
Jyri Sarhaab8b14b2014-01-27 17:37:52 +0200742 }
743
Peter Ujfalusidd093a02014-04-01 15:55:11 +0300744 ret = mcasp_common_hw_param(mcasp, substream->stream,
745 period_size * channels, channels);
Peter Ujfalusi0f7d9a62014-01-30 15:15:24 +0200746 if (ret)
747 return ret;
748
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200749 if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE)
Daniel Mack64792852014-03-27 11:27:40 +0100750 ret = mcasp_dit_hw_param(mcasp, params_rate(params));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400751 else
Peter Ujfalusi2c56c4c2014-01-30 15:15:23 +0200752 ret = mcasp_i2s_hw_param(mcasp, substream->stream);
753
754 if (ret)
755 return ret;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400756
757 switch (params_format(params)) {
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400758 case SNDRV_PCM_FORMAT_U8:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400759 case SNDRV_PCM_FORMAT_S8:
760 dma_params->data_type = 1;
Daniel Mackba764b32012-12-05 18:20:37 +0100761 word_length = 8;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400762 break;
763
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400764 case SNDRV_PCM_FORMAT_U16_LE:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400765 case SNDRV_PCM_FORMAT_S16_LE:
766 dma_params->data_type = 2;
Daniel Mackba764b32012-12-05 18:20:37 +0100767 word_length = 16;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400768 break;
769
Daniel Mack21eb24d2012-10-09 09:35:16 +0200770 case SNDRV_PCM_FORMAT_U24_3LE:
771 case SNDRV_PCM_FORMAT_S24_3LE:
Daniel Mack21eb24d2012-10-09 09:35:16 +0200772 dma_params->data_type = 3;
Daniel Mackba764b32012-12-05 18:20:37 +0100773 word_length = 24;
Daniel Mack21eb24d2012-10-09 09:35:16 +0200774 break;
775
Daniel Mack6b7fa012012-10-09 11:56:40 +0200776 case SNDRV_PCM_FORMAT_U24_LE:
777 case SNDRV_PCM_FORMAT_S24_LE:
Peter Ujfalusi182bef82014-06-26 08:09:24 +0300778 dma_params->data_type = 4;
779 word_length = 24;
780 break;
781
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400782 case SNDRV_PCM_FORMAT_U32_LE:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400783 case SNDRV_PCM_FORMAT_S32_LE:
784 dma_params->data_type = 4;
Daniel Mackba764b32012-12-05 18:20:37 +0100785 word_length = 32;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400786 break;
787
788 default:
789 printk(KERN_WARNING "davinci-mcasp: unsupported PCM format");
790 return -EINVAL;
791 }
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400792
Peter Ujfalusi5f04c602014-04-01 15:55:10 +0300793 if (mcasp->version == MCASP_VERSION_2 && !dma_params->fifo_level)
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400794 dma_params->acnt = 4;
795 else
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400796 dma_params->acnt = dma_params->data_type;
797
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200798 davinci_config_channel_size(mcasp, word_length);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400799
800 return 0;
801}
802
803static int davinci_mcasp_trigger(struct snd_pcm_substream *substream,
804 int cmd, struct snd_soc_dai *cpu_dai)
805{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200806 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400807 int ret = 0;
808
809 switch (cmd) {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400810 case SNDRV_PCM_TRIGGER_RESUME:
Chaithrika U Se473b842010-01-20 17:06:33 +0530811 case SNDRV_PCM_TRIGGER_START:
812 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200813 davinci_mcasp_start(mcasp, substream->stream);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400814 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400815 case SNDRV_PCM_TRIGGER_SUSPEND:
Chaithrika U Sa47979b2009-12-03 18:56:56 +0530816 case SNDRV_PCM_TRIGGER_STOP:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400817 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200818 davinci_mcasp_stop(mcasp, substream->stream);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400819 break;
820
821 default:
822 ret = -EINVAL;
823 }
824
825 return ret;
826}
827
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100828static const struct snd_soc_dai_ops davinci_mcasp_dai_ops = {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400829 .trigger = davinci_mcasp_trigger,
830 .hw_params = davinci_mcasp_hw_params,
831 .set_fmt = davinci_mcasp_set_dai_fmt,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200832 .set_clkdiv = davinci_mcasp_set_clkdiv,
Daniel Mack5b66aa22012-10-04 15:08:41 +0200833 .set_sysclk = davinci_mcasp_set_sysclk,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400834};
835
Peter Ujfalusid5902f692014-04-01 15:55:07 +0300836static int davinci_mcasp_dai_probe(struct snd_soc_dai *dai)
837{
838 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
839
Peter Ujfalusif3f9cfa2014-07-16 15:12:04 +0300840 if (mcasp->version >= MCASP_VERSION_3) {
Peter Ujfalusid5902f692014-04-01 15:55:07 +0300841 /* Using dmaengine PCM */
842 dai->playback_dma_data =
843 &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
844 dai->capture_dma_data =
845 &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE];
846 } else {
847 /* Using davinci-pcm */
848 dai->playback_dma_data = mcasp->dma_params;
849 dai->capture_dma_data = mcasp->dma_params;
850 }
851
852 return 0;
853}
854
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200855#ifdef CONFIG_PM_SLEEP
856static int davinci_mcasp_suspend(struct snd_soc_dai *dai)
857{
858 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Peter Ujfalusi790bb942014-02-03 14:51:52 +0200859 struct davinci_mcasp_context *context = &mcasp->context;
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200860
Peter Ujfalusi790bb942014-02-03 14:51:52 +0200861 context->txfmtctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG);
862 context->rxfmtctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG);
863 context->txfmt = mcasp_get_reg(mcasp, DAVINCI_MCASP_TXFMT_REG);
864 context->rxfmt = mcasp_get_reg(mcasp, DAVINCI_MCASP_RXFMT_REG);
865 context->aclkxctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG);
866 context->aclkrctl = mcasp_get_reg(mcasp, DAVINCI_MCASP_ACLKRCTL_REG);
867 context->pdir = mcasp_get_reg(mcasp, DAVINCI_MCASP_PDIR_REG);
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 Ujfalusi135014a2014-01-30 15:21:32 +0200876
Peter Ujfalusi790bb942014-02-03 14:51:52 +0200877 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMCTL_REG, context->txfmtctl);
878 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXFMCTL_REG, context->rxfmtctl);
879 mcasp_set_reg(mcasp, DAVINCI_MCASP_TXFMT_REG, context->txfmt);
880 mcasp_set_reg(mcasp, DAVINCI_MCASP_RXFMT_REG, context->rxfmt);
881 mcasp_set_reg(mcasp, DAVINCI_MCASP_ACLKXCTL_REG, context->aclkxctl);
882 mcasp_set_reg(mcasp, DAVINCI_MCASP_ACLKRCTL_REG, context->aclkrctl);
883 mcasp_set_reg(mcasp, DAVINCI_MCASP_PDIR_REG, context->pdir);
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200884
885 return 0;
886}
887#else
888#define davinci_mcasp_suspend NULL
889#define davinci_mcasp_resume NULL
890#endif
891
Peter Ujfalusied29cd52013-11-14 11:35:22 +0200892#define DAVINCI_MCASP_RATES SNDRV_PCM_RATE_8000_192000
893
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400894#define DAVINCI_MCASP_PCM_FMTS (SNDRV_PCM_FMTBIT_S8 | \
895 SNDRV_PCM_FMTBIT_U8 | \
896 SNDRV_PCM_FMTBIT_S16_LE | \
897 SNDRV_PCM_FMTBIT_U16_LE | \
Daniel Mack21eb24d2012-10-09 09:35:16 +0200898 SNDRV_PCM_FMTBIT_S24_LE | \
899 SNDRV_PCM_FMTBIT_U24_LE | \
900 SNDRV_PCM_FMTBIT_S24_3LE | \
901 SNDRV_PCM_FMTBIT_U24_3LE | \
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400902 SNDRV_PCM_FMTBIT_S32_LE | \
903 SNDRV_PCM_FMTBIT_U32_LE)
904
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000905static struct snd_soc_dai_driver davinci_mcasp_dai[] = {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400906 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000907 .name = "davinci-mcasp.0",
Peter Ujfalusid5902f692014-04-01 15:55:07 +0300908 .probe = davinci_mcasp_dai_probe,
Peter Ujfalusi135014a2014-01-30 15:21:32 +0200909 .suspend = davinci_mcasp_suspend,
910 .resume = davinci_mcasp_resume,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400911 .playback = {
912 .channels_min = 2,
Michal Bachraty2952b272013-02-28 16:07:08 +0100913 .channels_max = 32 * 16,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400914 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400915 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400916 },
917 .capture = {
918 .channels_min = 2,
Michal Bachraty2952b272013-02-28 16:07:08 +0100919 .channels_max = 32 * 16,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400920 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400921 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400922 },
923 .ops = &davinci_mcasp_dai_ops,
924
925 },
926 {
Peter Ujfalusi58e48d92013-11-14 11:35:24 +0200927 .name = "davinci-mcasp.1",
Peter Ujfalusid5902f692014-04-01 15:55:07 +0300928 .probe = davinci_mcasp_dai_probe,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400929 .playback = {
930 .channels_min = 1,
931 .channels_max = 384,
932 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400933 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400934 },
935 .ops = &davinci_mcasp_dai_ops,
936 },
937
938};
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400939
Kuninori Morimotoeeef0ed2013-03-21 03:31:19 -0700940static const struct snd_soc_component_driver davinci_mcasp_component = {
941 .name = "davinci-mcasp",
942};
943
Jyri Sarha256ba182013-10-18 18:37:42 +0300944/* Some HW specific values and defaults. The rest is filled in from DT. */
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200945static struct davinci_mcasp_pdata dm646x_mcasp_pdata = {
Jyri Sarha256ba182013-10-18 18:37:42 +0300946 .tx_dma_offset = 0x400,
947 .rx_dma_offset = 0x400,
948 .asp_chan_q = EVENTQ_0,
949 .version = MCASP_VERSION_1,
950};
951
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200952static struct davinci_mcasp_pdata da830_mcasp_pdata = {
Jyri Sarha256ba182013-10-18 18:37:42 +0300953 .tx_dma_offset = 0x2000,
954 .rx_dma_offset = 0x2000,
955 .asp_chan_q = EVENTQ_0,
956 .version = MCASP_VERSION_2,
957};
958
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200959static struct davinci_mcasp_pdata am33xx_mcasp_pdata = {
Jyri Sarha256ba182013-10-18 18:37:42 +0300960 .tx_dma_offset = 0,
961 .rx_dma_offset = 0,
962 .asp_chan_q = EVENTQ_0,
963 .version = MCASP_VERSION_3,
964};
965
Peter Ujfalusid1debaf2014-02-03 14:51:51 +0200966static struct davinci_mcasp_pdata dra7_mcasp_pdata = {
Peter Ujfalusi453c4992013-11-14 11:35:34 +0200967 .tx_dma_offset = 0x200,
968 .rx_dma_offset = 0x284,
969 .asp_chan_q = EVENTQ_0,
970 .version = MCASP_VERSION_4,
971};
972
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530973static const struct of_device_id mcasp_dt_ids[] = {
974 {
975 .compatible = "ti,dm646x-mcasp-audio",
Jyri Sarha256ba182013-10-18 18:37:42 +0300976 .data = &dm646x_mcasp_pdata,
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530977 },
978 {
979 .compatible = "ti,da830-mcasp-audio",
Jyri Sarha256ba182013-10-18 18:37:42 +0300980 .data = &da830_mcasp_pdata,
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530981 },
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530982 {
Jyri Sarha3af9e032013-10-18 18:37:44 +0300983 .compatible = "ti,am33xx-mcasp-audio",
Peter Ujfalusib14899d2013-11-14 11:35:37 +0200984 .data = &am33xx_mcasp_pdata,
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530985 },
Peter Ujfalusi453c4992013-11-14 11:35:34 +0200986 {
987 .compatible = "ti,dra7-mcasp-audio",
988 .data = &dra7_mcasp_pdata,
989 },
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530990 { /* sentinel */ }
991};
992MODULE_DEVICE_TABLE(of, mcasp_dt_ids);
993
Peter Ujfalusiae726e92013-11-14 11:35:35 +0200994static int mcasp_reparent_fck(struct platform_device *pdev)
995{
996 struct device_node *node = pdev->dev.of_node;
997 struct clk *gfclk, *parent_clk;
998 const char *parent_name;
999 int ret;
1000
1001 if (!node)
1002 return 0;
1003
1004 parent_name = of_get_property(node, "fck_parent", NULL);
1005 if (!parent_name)
1006 return 0;
1007
1008 gfclk = clk_get(&pdev->dev, "fck");
1009 if (IS_ERR(gfclk)) {
1010 dev_err(&pdev->dev, "failed to get fck\n");
1011 return PTR_ERR(gfclk);
1012 }
1013
1014 parent_clk = clk_get(NULL, parent_name);
1015 if (IS_ERR(parent_clk)) {
1016 dev_err(&pdev->dev, "failed to get parent clock\n");
1017 ret = PTR_ERR(parent_clk);
1018 goto err1;
1019 }
1020
1021 ret = clk_set_parent(gfclk, parent_clk);
1022 if (ret) {
1023 dev_err(&pdev->dev, "failed to reparent fck\n");
1024 goto err2;
1025 }
1026
1027err2:
1028 clk_put(parent_clk);
1029err1:
1030 clk_put(gfclk);
1031 return ret;
1032}
1033
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001034static struct davinci_mcasp_pdata *davinci_mcasp_set_pdata_from_of(
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301035 struct platform_device *pdev)
1036{
1037 struct device_node *np = pdev->dev.of_node;
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001038 struct davinci_mcasp_pdata *pdata = NULL;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301039 const struct of_device_id *match =
Sachin Kamatea421eb2013-05-22 16:53:37 +05301040 of_match_device(mcasp_dt_ids, &pdev->dev);
Jyri Sarha4023fe62013-10-18 18:37:43 +03001041 struct of_phandle_args dma_spec;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301042
1043 const u32 *of_serial_dir32;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301044 u32 val;
1045 int i, ret = 0;
1046
1047 if (pdev->dev.platform_data) {
1048 pdata = pdev->dev.platform_data;
1049 return pdata;
1050 } else if (match) {
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001051 pdata = (struct davinci_mcasp_pdata*) match->data;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301052 } else {
1053 /* control shouldn't reach here. something is wrong */
1054 ret = -EINVAL;
1055 goto nodata;
1056 }
1057
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301058 ret = of_property_read_u32(np, "op-mode", &val);
1059 if (ret >= 0)
1060 pdata->op_mode = val;
1061
1062 ret = of_property_read_u32(np, "tdm-slots", &val);
Michal Bachraty2952b272013-02-28 16:07:08 +01001063 if (ret >= 0) {
1064 if (val < 2 || val > 32) {
1065 dev_err(&pdev->dev,
1066 "tdm-slots must be in rage [2-32]\n");
1067 ret = -EINVAL;
1068 goto nodata;
1069 }
1070
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301071 pdata->tdm_slots = val;
Michal Bachraty2952b272013-02-28 16:07:08 +01001072 }
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301073
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301074 of_serial_dir32 = of_get_property(np, "serial-dir", &val);
1075 val /= sizeof(u32);
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301076 if (of_serial_dir32) {
Peter Ujfalusi1427e662013-10-18 18:37:46 +03001077 u8 *of_serial_dir = devm_kzalloc(&pdev->dev,
1078 (sizeof(*of_serial_dir) * val),
1079 GFP_KERNEL);
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301080 if (!of_serial_dir) {
1081 ret = -ENOMEM;
1082 goto nodata;
1083 }
1084
Peter Ujfalusi1427e662013-10-18 18:37:46 +03001085 for (i = 0; i < val; i++)
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301086 of_serial_dir[i] = be32_to_cpup(&of_serial_dir32[i]);
1087
Peter Ujfalusi1427e662013-10-18 18:37:46 +03001088 pdata->num_serializer = val;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301089 pdata->serial_dir = of_serial_dir;
1090 }
1091
Jyri Sarha4023fe62013-10-18 18:37:43 +03001092 ret = of_property_match_string(np, "dma-names", "tx");
1093 if (ret < 0)
1094 goto nodata;
1095
1096 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
1097 &dma_spec);
1098 if (ret < 0)
1099 goto nodata;
1100
1101 pdata->tx_dma_channel = dma_spec.args[0];
1102
1103 ret = of_property_match_string(np, "dma-names", "rx");
1104 if (ret < 0)
1105 goto nodata;
1106
1107 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
1108 &dma_spec);
1109 if (ret < 0)
1110 goto nodata;
1111
1112 pdata->rx_dma_channel = dma_spec.args[0];
1113
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301114 ret = of_property_read_u32(np, "tx-num-evt", &val);
1115 if (ret >= 0)
1116 pdata->txnumevt = val;
1117
1118 ret = of_property_read_u32(np, "rx-num-evt", &val);
1119 if (ret >= 0)
1120 pdata->rxnumevt = val;
1121
1122 ret = of_property_read_u32(np, "sram-size-playback", &val);
1123 if (ret >= 0)
1124 pdata->sram_size_playback = val;
1125
1126 ret = of_property_read_u32(np, "sram-size-capture", &val);
1127 if (ret >= 0)
1128 pdata->sram_size_capture = val;
1129
1130 return pdata;
1131
1132nodata:
1133 if (ret < 0) {
1134 dev_err(&pdev->dev, "Error populating platform data, err %d\n",
1135 ret);
1136 pdata = NULL;
1137 }
1138 return pdata;
1139}
1140
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001141static int davinci_mcasp_probe(struct platform_device *pdev)
1142{
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001143 struct davinci_pcm_dma_params *dma_params;
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001144 struct snd_dmaengine_dai_dma_data *dma_data;
Jyri Sarha256ba182013-10-18 18:37:42 +03001145 struct resource *mem, *ioarea, *res, *dat;
Peter Ujfalusid1debaf2014-02-03 14:51:51 +02001146 struct davinci_mcasp_pdata *pdata;
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001147 struct davinci_mcasp *mcasp;
Julia Lawall96d31e22011-12-29 17:51:21 +01001148 int ret;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001149
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301150 if (!pdev->dev.platform_data && !pdev->dev.of_node) {
1151 dev_err(&pdev->dev, "No platform data supplied\n");
1152 return -EINVAL;
1153 }
1154
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001155 mcasp = devm_kzalloc(&pdev->dev, sizeof(struct davinci_mcasp),
Julia Lawall96d31e22011-12-29 17:51:21 +01001156 GFP_KERNEL);
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001157 if (!mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001158 return -ENOMEM;
1159
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +05301160 pdata = davinci_mcasp_set_pdata_from_of(pdev);
1161 if (!pdata) {
1162 dev_err(&pdev->dev, "no platform data\n");
1163 return -EINVAL;
1164 }
1165
Jyri Sarha256ba182013-10-18 18:37:42 +03001166 mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001167 if (!mem) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001168 dev_warn(mcasp->dev,
Jyri Sarha256ba182013-10-18 18:37:42 +03001169 "\"mpu\" mem resource not found, using index 0\n");
1170 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1171 if (!mem) {
1172 dev_err(&pdev->dev, "no mem resource?\n");
1173 return -ENODEV;
1174 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001175 }
1176
Julia Lawall96d31e22011-12-29 17:51:21 +01001177 ioarea = devm_request_mem_region(&pdev->dev, mem->start,
Vaibhav Bediad852f4462011-02-09 18:39:52 +05301178 resource_size(mem), pdev->name);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001179 if (!ioarea) {
1180 dev_err(&pdev->dev, "Audio region already claimed\n");
Julia Lawall96d31e22011-12-29 17:51:21 +01001181 return -EBUSY;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001182 }
1183
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301184 pm_runtime_enable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001185
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301186 ret = pm_runtime_get_sync(&pdev->dev);
1187 if (IS_ERR_VALUE(ret)) {
1188 dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
1189 return ret;
1190 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001191
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001192 mcasp->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
1193 if (!mcasp->base) {
Vaibhav Bedia4f82f022011-02-09 18:39:54 +05301194 dev_err(&pdev->dev, "ioremap failed\n");
1195 ret = -ENOMEM;
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001196 goto err;
Vaibhav Bedia4f82f022011-02-09 18:39:54 +05301197 }
1198
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001199 mcasp->op_mode = pdata->op_mode;
1200 mcasp->tdm_slots = pdata->tdm_slots;
1201 mcasp->num_serializer = pdata->num_serializer;
1202 mcasp->serial_dir = pdata->serial_dir;
1203 mcasp->version = pdata->version;
1204 mcasp->txnumevt = pdata->txnumevt;
1205 mcasp->rxnumevt = pdata->rxnumevt;
Peter Ujfalusi487dce82013-11-14 11:35:31 +02001206
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001207 mcasp->dev = &pdev->dev;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001208
Jyri Sarha256ba182013-10-18 18:37:42 +03001209 dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001210 if (dat)
1211 mcasp->dat_port = true;
Jyri Sarha256ba182013-10-18 18:37:42 +03001212
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001213 dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_PLAYBACK];
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001214 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001215 dma_params->asp_chan_q = pdata->asp_chan_q;
1216 dma_params->ram_chan_q = pdata->ram_chan_q;
1217 dma_params->sram_pool = pdata->sram_pool;
1218 dma_params->sram_size = pdata->sram_size_playback;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001219 if (dat)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001220 dma_params->dma_addr = dat->start;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001221 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001222 dma_params->dma_addr = mem->start + pdata->tx_dma_offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001223
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001224 /* Unconditional dmaengine stuff */
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001225 dma_data->addr = dma_params->dma_addr;
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001226
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001227 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
Jyri Sarha4023fe62013-10-18 18:37:43 +03001228 if (res)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001229 dma_params->channel = res->start;
Jyri Sarha4023fe62013-10-18 18:37:43 +03001230 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001231 dma_params->channel = pdata->tx_dma_channel;
Troy Kisky92e2a6f2009-09-11 14:29:03 -07001232
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001233 /* dmaengine filter data for DT and non-DT boot */
1234 if (pdev->dev.of_node)
1235 dma_data->filter_data = "tx";
1236 else
1237 dma_data->filter_data = &dma_params->channel;
1238
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001239 dma_params = &mcasp->dma_params[SNDRV_PCM_STREAM_CAPTURE];
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001240 dma_data = &mcasp->dma_data[SNDRV_PCM_STREAM_CAPTURE];
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001241 dma_params->asp_chan_q = pdata->asp_chan_q;
1242 dma_params->ram_chan_q = pdata->ram_chan_q;
1243 dma_params->sram_pool = pdata->sram_pool;
1244 dma_params->sram_size = pdata->sram_size_capture;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001245 if (dat)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001246 dma_params->dma_addr = dat->start;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001247 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001248 dma_params->dma_addr = mem->start + pdata->rx_dma_offset;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001249
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001250 /* Unconditional dmaengine stuff */
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001251 dma_data->addr = dma_params->dma_addr;
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001252
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001253 if (mcasp->version < MCASP_VERSION_3) {
1254 mcasp->fifo_base = DAVINCI_MCASP_V2_AFIFO_BASE;
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001255 /* dma_params->dma_addr is pointing to the data port address */
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +02001256 mcasp->dat_port = true;
1257 } else {
1258 mcasp->fifo_base = DAVINCI_MCASP_V3_AFIFO_BASE;
1259 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001260
1261 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
Jyri Sarha4023fe62013-10-18 18:37:43 +03001262 if (res)
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001263 dma_params->channel = res->start;
Jyri Sarha4023fe62013-10-18 18:37:43 +03001264 else
Peter Ujfalusi64ebdec2014-03-07 15:03:55 +02001265 dma_params->channel = pdata->rx_dma_channel;
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001266
Peter Ujfalusi8de131f2014-03-14 16:42:46 +02001267 /* dmaengine filter data for DT and non-DT boot */
1268 if (pdev->dev.of_node)
1269 dma_data->filter_data = "rx";
1270 else
1271 dma_data->filter_data = &dma_params->channel;
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001272
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001273 dev_set_drvdata(&pdev->dev, mcasp);
Peter Ujfalusiae726e92013-11-14 11:35:35 +02001274
1275 mcasp_reparent_fck(pdev);
1276
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001277 ret = devm_snd_soc_register_component(&pdev->dev,
1278 &davinci_mcasp_component,
1279 &davinci_mcasp_dai[pdata->op_mode], 1);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001280
1281 if (ret != 0)
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001282 goto err;
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +05301283
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001284 switch (mcasp->version) {
Jyri Sarha7f28f352014-06-13 12:49:59 +03001285#if IS_BUILTIN(CONFIG_SND_DAVINCI_SOC) || \
1286 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \
1287 IS_MODULE(CONFIG_SND_DAVINCI_SOC))
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001288 case MCASP_VERSION_1:
1289 case MCASP_VERSION_2:
Peter Ujfalusi453c4992013-11-14 11:35:34 +02001290 ret = davinci_soc_platform_register(&pdev->dev);
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001291 break;
Jyri Sarha7f28f352014-06-13 12:49:59 +03001292#endif
Peter Ujfalusif3f9cfa2014-07-16 15:12:04 +03001293#if IS_BUILTIN(CONFIG_SND_EDMA_SOC) || \
1294 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \
1295 IS_MODULE(CONFIG_SND_EDMA_SOC))
1296 case MCASP_VERSION_3:
1297 ret = edma_pcm_platform_register(&pdev->dev);
1298 break;
1299#endif
Jyri Sarha7f28f352014-06-13 12:49:59 +03001300#if IS_BUILTIN(CONFIG_SND_OMAP_SOC) || \
1301 (IS_MODULE(CONFIG_SND_DAVINCI_SOC_MCASP) && \
1302 IS_MODULE(CONFIG_SND_OMAP_SOC))
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001303 case MCASP_VERSION_4:
1304 ret = omap_pcm_platform_register(&pdev->dev);
1305 break;
Jyri Sarha7f28f352014-06-13 12:49:59 +03001306#endif
Peter Ujfalusid5c6c592014-04-16 15:46:20 +03001307 default:
1308 dev_err(&pdev->dev, "Invalid McASP version: %d\n",
1309 mcasp->version);
1310 ret = -EINVAL;
1311 break;
1312 }
1313
1314 if (ret) {
1315 dev_err(&pdev->dev, "register PCM failed: %d\n", ret);
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001316 goto err;
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +05301317 }
1318
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001319 return 0;
1320
Peter Ujfalusib6bb3702014-04-22 14:03:13 +03001321err:
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301322 pm_runtime_put_sync(&pdev->dev);
1323 pm_runtime_disable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001324 return ret;
1325}
1326
1327static int davinci_mcasp_remove(struct platform_device *pdev)
1328{
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301329 pm_runtime_put_sync(&pdev->dev);
1330 pm_runtime_disable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001331
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001332 return 0;
1333}
1334
1335static struct platform_driver davinci_mcasp_driver = {
1336 .probe = davinci_mcasp_probe,
1337 .remove = davinci_mcasp_remove,
1338 .driver = {
1339 .name = "davinci-mcasp",
1340 .owner = THIS_MODULE,
Sachin Kamatea421eb2013-05-22 16:53:37 +05301341 .of_match_table = mcasp_dt_ids,
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001342 },
1343};
1344
Axel Linf9b8a512011-11-25 10:09:27 +08001345module_platform_driver(davinci_mcasp_driver);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001346
1347MODULE_AUTHOR("Steve Chen");
1348MODULE_DESCRIPTION("TI DAVINCI McASP SoC Interface");
1349MODULE_LICENSE("GPL");