blob: 35a6292889a59b7777c8844311d1cbe41bde06e7 [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>
Hebbar, Gururaja10884342012-08-08 20:40:32 +053024#include <linux/pm_runtime.h>
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +053025#include <linux/of.h>
26#include <linux/of_platform.h>
27#include <linux/of_device.h>
Chaithrika U Sb67f4482009-06-05 06:28:40 -040028
29#include <sound/core.h>
30#include <sound/pcm.h>
31#include <sound/pcm_params.h>
32#include <sound/initval.h>
33#include <sound/soc.h>
34
35#include "davinci-pcm.h"
36#include "davinci-mcasp.h"
37
Peter Ujfalusi70091a32013-11-14 11:35:29 +020038struct davinci_mcasp {
Peter Ujfalusi21400a72013-11-14 11:35:26 +020039 struct davinci_pcm_dma_params dma_params[2];
40 void __iomem *base;
Peter Ujfalusi487dce82013-11-14 11:35:31 +020041 u32 fifo_base;
Peter Ujfalusi21400a72013-11-14 11:35:26 +020042 struct device *dev;
43
44 /* McASP specific data */
45 int tdm_slots;
46 u8 op_mode;
47 u8 num_serializer;
48 u8 *serial_dir;
49 u8 version;
50 u16 bclk_lrclk_ratio;
51
52 /* McASP FIFO related */
53 u8 txnumevt;
54 u8 rxnumevt;
55
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +020056 bool dat_port;
57
Peter Ujfalusi21400a72013-11-14 11:35:26 +020058#ifdef CONFIG_PM_SLEEP
59 struct {
60 u32 txfmtctl;
61 u32 rxfmtctl;
62 u32 txfmt;
63 u32 rxfmt;
64 u32 aclkxctl;
65 u32 aclkrctl;
66 u32 pdir;
67 } context;
68#endif
69};
70
Chaithrika U Sb67f4482009-06-05 06:28:40 -040071static inline void mcasp_set_bits(void __iomem *reg, u32 val)
72{
73 __raw_writel(__raw_readl(reg) | val, reg);
74}
75
76static inline void mcasp_clr_bits(void __iomem *reg, u32 val)
77{
78 __raw_writel((__raw_readl(reg) & ~(val)), reg);
79}
80
81static inline void mcasp_mod_bits(void __iomem *reg, u32 val, u32 mask)
82{
83 __raw_writel((__raw_readl(reg) & ~mask) | val, reg);
84}
85
86static inline void mcasp_set_reg(void __iomem *reg, u32 val)
87{
88 __raw_writel(val, reg);
89}
90
91static inline u32 mcasp_get_reg(void __iomem *reg)
92{
93 return (unsigned int)__raw_readl(reg);
94}
95
Peter Ujfalusieba0ecf2013-11-14 11:35:28 +020096static void mcasp_set_ctl_reg(void __iomem *regs, u32 val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -040097{
98 int i = 0;
99
100 mcasp_set_bits(regs, val);
101
102 /* programming GBLCTL needs to read back from GBLCTL and verfiy */
103 /* loop count is to avoid the lock-up */
104 for (i = 0; i < 1000; i++) {
105 if ((mcasp_get_reg(regs) & val) == val)
106 break;
107 }
108
109 if (i == 1000 && ((mcasp_get_reg(regs) & val) != val))
110 printk(KERN_ERR "GBLCTL write error\n");
111}
112
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200113static void mcasp_start_rx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400114{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200115 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, RXHCLKRST);
116 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, RXCLKRST);
117 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, RXSERCLR);
118 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_RXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400119
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200120 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, RXSMRST);
121 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, RXFSRST);
122 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_RXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400123
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200124 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, RXSMRST);
125 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, RXFSRST);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400126}
127
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200128static void mcasp_start_tx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400129{
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400130 u8 offset = 0, i;
131 u32 cnt;
132
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200133 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST);
134 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
135 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLX_REG, TXSERCLR);
136 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400137
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200138 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLX_REG, TXSMRST);
139 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLX_REG, TXFSRST);
140 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXBUF_REG, 0);
141 for (i = 0; i < mcasp->num_serializer; i++) {
142 if (mcasp->serial_dir[i] == TX_MODE) {
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400143 offset = i;
144 break;
145 }
146 }
147
148 /* wait for TX ready */
149 cnt = 0;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200150 while (!(mcasp_get_reg(mcasp->base + DAVINCI_MCASP_XRSRCTL_REG(offset)) &
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400151 TXSTATE) && (cnt < 100000))
152 cnt++;
153
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200154 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400155}
156
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200157static void davinci_mcasp_start(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400158{
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200159 u32 reg;
160
Chaithrika U S539d3d82009-09-23 10:12:08 -0400161 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200162 if (mcasp->txnumevt) { /* enable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200163 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
164 mcasp_clr_bits(mcasp->base + reg, FIFO_ENABLE);
165 mcasp_set_bits(mcasp->base + reg, FIFO_ENABLE);
Vaibhav Bedia0d624272012-08-08 20:40:31 +0530166 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200167 mcasp_start_tx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400168 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200169 if (mcasp->rxnumevt) { /* enable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200170 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
171 mcasp_clr_bits(mcasp->base + reg, FIFO_ENABLE);
172 mcasp_set_bits(mcasp->base + reg, FIFO_ENABLE);
Vaibhav Bedia0d624272012-08-08 20:40:31 +0530173 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200174 mcasp_start_rx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400175 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400176}
177
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200178static void mcasp_stop_rx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400179{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200180 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, 0);
181 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400182}
183
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200184static void mcasp_stop_tx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400185{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200186 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_GBLCTLX_REG, 0);
187 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400188}
189
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200190static void davinci_mcasp_stop(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400191{
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200192 u32 reg;
193
Chaithrika U S539d3d82009-09-23 10:12:08 -0400194 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200195 if (mcasp->txnumevt) { /* disable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200196 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
197 mcasp_clr_bits(mcasp->base + reg, FIFO_ENABLE);
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530198 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200199 mcasp_stop_tx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400200 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200201 if (mcasp->rxnumevt) { /* disable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200202 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
203 mcasp_clr_bits(mcasp->base + reg, FIFO_ENABLE);
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530204 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200205 mcasp_stop_rx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400206 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400207}
208
209static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
210 unsigned int fmt)
211{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200212 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
213 void __iomem *base = mcasp->base;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400214
Daniel Mack5296cf22012-10-04 15:08:42 +0200215 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
216 case SND_SOC_DAIFMT_DSP_B:
217 case SND_SOC_DAIFMT_AC97:
Peter Ujfalusi8f113b72013-11-14 11:35:30 +0200218 mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
219 mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
Daniel Mack5296cf22012-10-04 15:08:42 +0200220 break;
221 default:
222 /* configure a full-word SYNC pulse (LRCLK) */
Peter Ujfalusi8f113b72013-11-14 11:35:30 +0200223 mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
224 mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
Daniel Mack5296cf22012-10-04 15:08:42 +0200225
226 /* make 1st data bit occur one ACLK cycle after the frame sync */
Peter Ujfalusi8f113b72013-11-14 11:35:30 +0200227 mcasp_set_bits(base + DAVINCI_MCASP_TXFMT_REG, FSXDLY(1));
228 mcasp_set_bits(base + DAVINCI_MCASP_RXFMT_REG, FSRDLY(1));
Daniel Mack5296cf22012-10-04 15:08:42 +0200229 break;
230 }
231
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400232 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
233 case SND_SOC_DAIFMT_CBS_CFS:
234 /* codec is clock and frame slave */
235 mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
236 mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
237
238 mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
239 mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
240
Marek Belisko81ee6832013-04-26 14:38:11 +0200241 mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG,
242 ACLKX | ACLKR);
243 mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG,
244 AFSX | AFSR);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400245 break;
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400246 case SND_SOC_DAIFMT_CBM_CFS:
247 /* codec is clock master and frame slave */
Ben Gardinera90f5492011-04-21 14:19:03 -0400248 mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400249 mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
250
Ben Gardinera90f5492011-04-21 14:19:03 -0400251 mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400252 mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
253
Ben Gardinerdb92f432011-04-21 14:19:04 -0400254 mcasp_clr_bits(base + DAVINCI_MCASP_PDIR_REG,
255 ACLKX | ACLKR);
Ben Gardiner9595c8f2011-04-21 14:19:02 -0400256 mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG,
Ben Gardinerdb92f432011-04-21 14:19:04 -0400257 AFSX | AFSR);
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400258 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400259 case SND_SOC_DAIFMT_CBM_CFM:
260 /* codec is clock and frame master */
261 mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
262 mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
263
264 mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
265 mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
266
Ben Gardiner9595c8f2011-04-21 14:19:02 -0400267 mcasp_clr_bits(base + DAVINCI_MCASP_PDIR_REG,
268 ACLKX | AHCLKX | AFSX | ACLKR | AHCLKR | AFSR);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400269 break;
270
271 default:
272 return -EINVAL;
273 }
274
275 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
276 case SND_SOC_DAIFMT_IB_NF:
277 mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
278 mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL);
279
280 mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
281 mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL);
282 break;
283
284 case SND_SOC_DAIFMT_NB_IF:
285 mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
286 mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL);
287
288 mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
289 mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL);
290 break;
291
292 case SND_SOC_DAIFMT_IB_IF:
293 mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
294 mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL);
295
296 mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
297 mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL);
298 break;
299
300 case SND_SOC_DAIFMT_NB_NF:
301 mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
302 mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL);
303
Marek Beliskodf4a4ee2013-05-03 07:37:36 +0200304 mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400305 mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL);
306 break;
307
308 default:
309 return -EINVAL;
310 }
311
312 return 0;
313}
314
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200315static int davinci_mcasp_set_clkdiv(struct snd_soc_dai *dai, int div_id, int div)
316{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200317 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200318
319 switch (div_id) {
320 case 0: /* MCLK divider */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200321 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_AHCLKXCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200322 AHCLKXDIV(div - 1), AHCLKXDIV_MASK);
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200323 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_AHCLKRCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200324 AHCLKRDIV(div - 1), AHCLKRDIV_MASK);
325 break;
326
327 case 1: /* BCLK divider */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200328 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_ACLKXCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200329 ACLKXDIV(div - 1), ACLKXDIV_MASK);
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200330 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_ACLKRCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200331 ACLKRDIV(div - 1), ACLKRDIV_MASK);
332 break;
333
Daniel Mack1b3bc062012-12-05 18:20:38 +0100334 case 2: /* BCLK/LRCLK ratio */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200335 mcasp->bclk_lrclk_ratio = div;
Daniel Mack1b3bc062012-12-05 18:20:38 +0100336 break;
337
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200338 default:
339 return -EINVAL;
340 }
341
342 return 0;
343}
344
Daniel Mack5b66aa22012-10-04 15:08:41 +0200345static int davinci_mcasp_set_sysclk(struct snd_soc_dai *dai, int clk_id,
346 unsigned int freq, int dir)
347{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200348 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200349
350 if (dir == SND_SOC_CLOCK_OUT) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200351 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE);
352 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE);
353 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_PDIR_REG, AHCLKX);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200354 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200355 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE);
356 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE);
357 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_PDIR_REG, AHCLKX);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200358 }
359
360 return 0;
361}
362
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200363static int davinci_config_channel_size(struct davinci_mcasp *mcasp,
Daniel Mackba764b32012-12-05 18:20:37 +0100364 int word_length)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400365{
Daniel Mackba764b32012-12-05 18:20:37 +0100366 u32 fmt;
Daniel Mack79671892013-05-16 15:25:01 +0200367 u32 tx_rotate = (word_length / 4) & 0x7;
368 u32 rx_rotate = (32 - word_length) / 4;
Daniel Mackba764b32012-12-05 18:20:37 +0100369 u32 mask = (1ULL << word_length) - 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400370
Daniel Mack1b3bc062012-12-05 18:20:38 +0100371 /*
372 * if s BCLK-to-LRCLK ratio has been configured via the set_clkdiv()
373 * callback, take it into account here. That allows us to for example
374 * send 32 bits per channel to the codec, while only 16 of them carry
375 * audio payload.
Michal Bachratyd486fea2013-04-19 15:28:44 +0200376 * The clock ratio is given for a full period of data (for I2S format
377 * both left and right channels), so it has to be divided by number of
378 * tdm-slots (for I2S - divided by 2).
Daniel Mack1b3bc062012-12-05 18:20:38 +0100379 */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200380 if (mcasp->bclk_lrclk_ratio)
381 word_length = mcasp->bclk_lrclk_ratio / mcasp->tdm_slots;
Daniel Mack1b3bc062012-12-05 18:20:38 +0100382
Daniel Mackba764b32012-12-05 18:20:37 +0100383 /* mapping of the XSSZ bit-field as described in the datasheet */
384 fmt = (word_length >> 1) - 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400385
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200386 if (mcasp->op_mode != DAVINCI_MCASP_DIT_MODE) {
387 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_RXFMT_REG,
Yegor Yefremovf5023af2013-04-04 16:13:20 +0200388 RXSSZ(fmt), RXSSZ(0x0F));
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200389 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_TXFMT_REG,
Yegor Yefremovf5023af2013-04-04 16:13:20 +0200390 TXSSZ(fmt), TXSSZ(0x0F));
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200391 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_TXFMT_REG,
Daniel Mack79671892013-05-16 15:25:01 +0200392 TXROT(tx_rotate), TXROT(7));
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200393 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_RXFMT_REG,
Daniel Mack79671892013-05-16 15:25:01 +0200394 RXROT(rx_rotate), RXROT(7));
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200395 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_RXMASK_REG,
Yegor Yefremovf5023af2013-04-04 16:13:20 +0200396 mask);
397 }
398
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200399 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXMASK_REG, mask);
Chaithrika U S0c31cf32009-09-15 18:13:29 -0400400
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400401 return 0;
402}
403
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200404static int davinci_hw_common_param(struct davinci_mcasp *mcasp, int stream,
Michal Bachraty2952b272013-02-28 16:07:08 +0100405 int channels)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400406{
407 int i;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400408 u8 tx_ser = 0;
409 u8 rx_ser = 0;
Michal Bachraty2952b272013-02-28 16:07:08 +0100410 u8 ser;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200411 u8 slots = mcasp->tdm_slots;
Michal Bachraty2952b272013-02-28 16:07:08 +0100412 u8 max_active_serializers = (channels + slots - 1) / slots;
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200413 u32 reg;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400414 /* Default configuration */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200415 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_PWREMUMGT_REG, MCASP_SOFT);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400416
417 /* All PINS as McASP */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200418 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_PFUNC_REG, 0x00000000);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400419
420 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200421 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF);
422 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_XEVTCTL_REG,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400423 TXDATADMADIS);
424 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200425 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
426 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_REVTCTL_REG,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400427 RXDATADMADIS);
428 }
429
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200430 for (i = 0; i < mcasp->num_serializer; i++) {
431 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_XRSRCTL_REG(i),
432 mcasp->serial_dir[i]);
433 if (mcasp->serial_dir[i] == TX_MODE &&
Michal Bachraty2952b272013-02-28 16:07:08 +0100434 tx_ser < max_active_serializers) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200435 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_PDIR_REG,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400436 AXR(i));
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400437 tx_ser++;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200438 } else if (mcasp->serial_dir[i] == RX_MODE &&
Michal Bachraty2952b272013-02-28 16:07:08 +0100439 rx_ser < max_active_serializers) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200440 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_PDIR_REG,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400441 AXR(i));
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400442 rx_ser++;
Michal Bachraty2952b272013-02-28 16:07:08 +0100443 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200444 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_XRSRCTL_REG(i),
Michal Bachraty2952b272013-02-28 16:07:08 +0100445 SRMOD_INACTIVE, SRMOD_MASK);
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400446 }
447 }
448
Daniel Mackecf327c2013-03-08 14:19:38 +0100449 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
450 ser = tx_ser;
451 else
452 ser = rx_ser;
453
454 if (ser < max_active_serializers) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200455 dev_warn(mcasp->dev, "stream has more channels (%d) than are "
Daniel Mackecf327c2013-03-08 14:19:38 +0100456 "enabled in mcasp (%d)\n", channels, ser * slots);
457 return -EINVAL;
458 }
459
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200460 if (mcasp->txnumevt && stream == SNDRV_PCM_STREAM_PLAYBACK) {
461 if (mcasp->txnumevt * tx_ser > 64)
462 mcasp->txnumevt = 1;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400463
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200464 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
465 mcasp_mod_bits(mcasp->base + reg, tx_ser, NUMDMA_MASK);
466 mcasp_mod_bits(mcasp->base + reg,
467 ((mcasp->txnumevt * tx_ser) << 8), NUMEVT_MASK);
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400468 }
469
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200470 if (mcasp->rxnumevt && stream == SNDRV_PCM_STREAM_CAPTURE) {
471 if (mcasp->rxnumevt * rx_ser > 64)
472 mcasp->rxnumevt = 1;
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200473
474 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
475 mcasp_mod_bits(mcasp->base + reg, rx_ser, NUMDMA_MASK);
476 mcasp_mod_bits(mcasp->base + reg,
477 ((mcasp->rxnumevt * rx_ser) << 8), NUMEVT_MASK);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400478 }
Michal Bachraty2952b272013-02-28 16:07:08 +0100479
480 return 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400481}
482
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200483static void davinci_hw_param(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400484{
485 int i, active_slots;
486 u32 mask = 0;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200487 u32 busel = 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400488
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200489 active_slots = (mcasp->tdm_slots > 31) ? 32 : mcasp->tdm_slots;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400490 for (i = 0; i < active_slots; i++)
491 mask |= (1 << i);
492
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200493 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC);
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400494
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200495 if (!mcasp->dat_port)
496 busel = TXSEL;
497
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400498 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
499 /* bit stream is MSB first with no delay */
500 /* DSP_B mode */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200501 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXTDM_REG, mask);
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200502 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_TXFMT_REG,
503 busel | TXORD);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400504
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200505 if ((mcasp->tdm_slots >= 2) && (mcasp->tdm_slots <= 32))
506 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_TXFMCTL_REG,
507 FSXMOD(mcasp->tdm_slots), FSXMOD(0x1FF));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400508 else
509 printk(KERN_ERR "playback tdm slot %d not supported\n",
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200510 mcasp->tdm_slots);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400511 } else {
512 /* bit stream is MSB first with no delay */
513 /* DSP_B mode */
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200514 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_RXFMT_REG,
515 busel | RXORD);
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200516 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_RXTDM_REG, mask);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400517
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200518 if ((mcasp->tdm_slots >= 2) && (mcasp->tdm_slots <= 32))
519 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_RXFMCTL_REG,
520 FSRMOD(mcasp->tdm_slots), FSRMOD(0x1FF));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400521 else
522 printk(KERN_ERR "capture tdm slot %d not supported\n",
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200523 mcasp->tdm_slots);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400524 }
525}
526
527/* S/PDIF */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200528static void davinci_hw_dit_param(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400529{
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400530 /* Set the TX format : 24 bit right rotation, 32 bit slot, Pad 0
531 and LSB first */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200532 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_TXFMT_REG,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400533 TXROT(6) | TXSSZ(15));
534
535 /* Set TX frame synch : DIT Mode, 1 bit width, internal, rising edge */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200536 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXFMCTL_REG,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400537 AFSXE | FSXMOD(0x180));
538
539 /* Set the TX tdm : for all the slots */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200540 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXTDM_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400541
542 /* Set the TX clock controls : div = 1 and internal */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200543 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_ACLKXCTL_REG,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400544 ACLKXE | TX_ASYNC);
545
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200546 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400547
548 /* Only 44100 and 48000 are valid, both have the same setting */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200549 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXDIV(3));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400550
551 /* Enable the DIT */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200552 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_TXDITCTL_REG, DITEN);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400553}
554
555static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
556 struct snd_pcm_hw_params *params,
557 struct snd_soc_dai *cpu_dai)
558{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200559 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400560 struct davinci_pcm_dma_params *dma_params =
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200561 &mcasp->dma_params[substream->stream];
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400562 int word_length;
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400563 u8 fifo_level;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200564 u8 slots = mcasp->tdm_slots;
Michal Bachraty7c21a782013-04-19 15:28:03 +0200565 u8 active_serializers;
Michal Bachraty2952b272013-02-28 16:07:08 +0100566 int channels;
567 struct snd_interval *pcm_channels = hw_param_interval(params,
568 SNDRV_PCM_HW_PARAM_CHANNELS);
569 channels = pcm_channels->min;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400570
Michal Bachraty7c21a782013-04-19 15:28:03 +0200571 active_serializers = (channels + slots - 1) / slots;
572
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200573 if (davinci_hw_common_param(mcasp, substream->stream, channels) == -EINVAL)
Michal Bachraty2952b272013-02-28 16:07:08 +0100574 return -EINVAL;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400575 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200576 fifo_level = mcasp->txnumevt * active_serializers;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400577 else
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200578 fifo_level = mcasp->rxnumevt * active_serializers;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400579
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200580 if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE)
581 davinci_hw_dit_param(mcasp);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400582 else
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200583 davinci_hw_param(mcasp, substream->stream);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400584
585 switch (params_format(params)) {
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400586 case SNDRV_PCM_FORMAT_U8:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400587 case SNDRV_PCM_FORMAT_S8:
588 dma_params->data_type = 1;
Daniel Mackba764b32012-12-05 18:20:37 +0100589 word_length = 8;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400590 break;
591
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400592 case SNDRV_PCM_FORMAT_U16_LE:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400593 case SNDRV_PCM_FORMAT_S16_LE:
594 dma_params->data_type = 2;
Daniel Mackba764b32012-12-05 18:20:37 +0100595 word_length = 16;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400596 break;
597
Daniel Mack21eb24d2012-10-09 09:35:16 +0200598 case SNDRV_PCM_FORMAT_U24_3LE:
599 case SNDRV_PCM_FORMAT_S24_3LE:
Daniel Mack21eb24d2012-10-09 09:35:16 +0200600 dma_params->data_type = 3;
Daniel Mackba764b32012-12-05 18:20:37 +0100601 word_length = 24;
Daniel Mack21eb24d2012-10-09 09:35:16 +0200602 break;
603
Daniel Mack6b7fa012012-10-09 11:56:40 +0200604 case SNDRV_PCM_FORMAT_U24_LE:
605 case SNDRV_PCM_FORMAT_S24_LE:
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400606 case SNDRV_PCM_FORMAT_U32_LE:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400607 case SNDRV_PCM_FORMAT_S32_LE:
608 dma_params->data_type = 4;
Daniel Mackba764b32012-12-05 18:20:37 +0100609 word_length = 32;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400610 break;
611
612 default:
613 printk(KERN_WARNING "davinci-mcasp: unsupported PCM format");
614 return -EINVAL;
615 }
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400616
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200617 if (mcasp->version == MCASP_VERSION_2 && !fifo_level)
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400618 dma_params->acnt = 4;
619 else
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400620 dma_params->acnt = dma_params->data_type;
621
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400622 dma_params->fifo_level = fifo_level;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200623 davinci_config_channel_size(mcasp, word_length);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400624
625 return 0;
626}
627
628static int davinci_mcasp_trigger(struct snd_pcm_substream *substream,
629 int cmd, struct snd_soc_dai *cpu_dai)
630{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200631 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400632 int ret = 0;
633
634 switch (cmd) {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400635 case SNDRV_PCM_TRIGGER_RESUME:
Chaithrika U Se473b842010-01-20 17:06:33 +0530636 case SNDRV_PCM_TRIGGER_START:
637 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200638 ret = pm_runtime_get_sync(mcasp->dev);
Hebbar, Gururaja10884342012-08-08 20:40:32 +0530639 if (IS_ERR_VALUE(ret))
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200640 dev_err(mcasp->dev, "pm_runtime_get_sync() failed\n");
641 davinci_mcasp_start(mcasp, substream->stream);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400642 break;
643
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400644 case SNDRV_PCM_TRIGGER_SUSPEND:
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200645 davinci_mcasp_stop(mcasp, substream->stream);
646 ret = pm_runtime_put_sync(mcasp->dev);
Hebbar, Gururaja10884342012-08-08 20:40:32 +0530647 if (IS_ERR_VALUE(ret))
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200648 dev_err(mcasp->dev, "pm_runtime_put_sync() failed\n");
Chaithrika U Sa47979b2009-12-03 18:56:56 +0530649 break;
650
651 case SNDRV_PCM_TRIGGER_STOP:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400652 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200653 davinci_mcasp_stop(mcasp, substream->stream);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400654 break;
655
656 default:
657 ret = -EINVAL;
658 }
659
660 return ret;
661}
662
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000663static int davinci_mcasp_startup(struct snd_pcm_substream *substream,
664 struct snd_soc_dai *dai)
665{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200666 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000667
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200668 snd_soc_dai_set_dma_data(dai, substream, mcasp->dma_params);
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000669 return 0;
670}
671
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100672static const struct snd_soc_dai_ops davinci_mcasp_dai_ops = {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000673 .startup = davinci_mcasp_startup,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400674 .trigger = davinci_mcasp_trigger,
675 .hw_params = davinci_mcasp_hw_params,
676 .set_fmt = davinci_mcasp_set_dai_fmt,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200677 .set_clkdiv = davinci_mcasp_set_clkdiv,
Daniel Mack5b66aa22012-10-04 15:08:41 +0200678 .set_sysclk = davinci_mcasp_set_sysclk,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400679};
680
Peter Ujfalusied29cd52013-11-14 11:35:22 +0200681#define DAVINCI_MCASP_RATES SNDRV_PCM_RATE_8000_192000
682
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400683#define DAVINCI_MCASP_PCM_FMTS (SNDRV_PCM_FMTBIT_S8 | \
684 SNDRV_PCM_FMTBIT_U8 | \
685 SNDRV_PCM_FMTBIT_S16_LE | \
686 SNDRV_PCM_FMTBIT_U16_LE | \
Daniel Mack21eb24d2012-10-09 09:35:16 +0200687 SNDRV_PCM_FMTBIT_S24_LE | \
688 SNDRV_PCM_FMTBIT_U24_LE | \
689 SNDRV_PCM_FMTBIT_S24_3LE | \
690 SNDRV_PCM_FMTBIT_U24_3LE | \
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400691 SNDRV_PCM_FMTBIT_S32_LE | \
692 SNDRV_PCM_FMTBIT_U32_LE)
693
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000694static struct snd_soc_dai_driver davinci_mcasp_dai[] = {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400695 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000696 .name = "davinci-mcasp.0",
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400697 .playback = {
698 .channels_min = 2,
Michal Bachraty2952b272013-02-28 16:07:08 +0100699 .channels_max = 32 * 16,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400700 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400701 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400702 },
703 .capture = {
704 .channels_min = 2,
Michal Bachraty2952b272013-02-28 16:07:08 +0100705 .channels_max = 32 * 16,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400706 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400707 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400708 },
709 .ops = &davinci_mcasp_dai_ops,
710
711 },
712 {
Peter Ujfalusi58e48d92013-11-14 11:35:24 +0200713 .name = "davinci-mcasp.1",
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400714 .playback = {
715 .channels_min = 1,
716 .channels_max = 384,
717 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400718 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400719 },
720 .ops = &davinci_mcasp_dai_ops,
721 },
722
723};
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400724
Kuninori Morimotoeeef0ed2013-03-21 03:31:19 -0700725static const struct snd_soc_component_driver davinci_mcasp_component = {
726 .name = "davinci-mcasp",
727};
728
Jyri Sarha256ba182013-10-18 18:37:42 +0300729/* Some HW specific values and defaults. The rest is filled in from DT. */
730static struct snd_platform_data dm646x_mcasp_pdata = {
731 .tx_dma_offset = 0x400,
732 .rx_dma_offset = 0x400,
733 .asp_chan_q = EVENTQ_0,
734 .version = MCASP_VERSION_1,
735};
736
737static struct snd_platform_data da830_mcasp_pdata = {
738 .tx_dma_offset = 0x2000,
739 .rx_dma_offset = 0x2000,
740 .asp_chan_q = EVENTQ_0,
741 .version = MCASP_VERSION_2,
742};
743
744static struct snd_platform_data omap2_mcasp_pdata = {
745 .tx_dma_offset = 0,
746 .rx_dma_offset = 0,
747 .asp_chan_q = EVENTQ_0,
748 .version = MCASP_VERSION_3,
749};
750
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530751static const struct of_device_id mcasp_dt_ids[] = {
752 {
753 .compatible = "ti,dm646x-mcasp-audio",
Jyri Sarha256ba182013-10-18 18:37:42 +0300754 .data = &dm646x_mcasp_pdata,
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530755 },
756 {
757 .compatible = "ti,da830-mcasp-audio",
Jyri Sarha256ba182013-10-18 18:37:42 +0300758 .data = &da830_mcasp_pdata,
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530759 },
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530760 {
Jyri Sarha3af9e032013-10-18 18:37:44 +0300761 .compatible = "ti,am33xx-mcasp-audio",
Jyri Sarha256ba182013-10-18 18:37:42 +0300762 .data = &omap2_mcasp_pdata,
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530763 },
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530764 { /* sentinel */ }
765};
766MODULE_DEVICE_TABLE(of, mcasp_dt_ids);
767
768static struct snd_platform_data *davinci_mcasp_set_pdata_from_of(
769 struct platform_device *pdev)
770{
771 struct device_node *np = pdev->dev.of_node;
772 struct snd_platform_data *pdata = NULL;
773 const struct of_device_id *match =
Sachin Kamatea421eb2013-05-22 16:53:37 +0530774 of_match_device(mcasp_dt_ids, &pdev->dev);
Jyri Sarha4023fe62013-10-18 18:37:43 +0300775 struct of_phandle_args dma_spec;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530776
777 const u32 *of_serial_dir32;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530778 u32 val;
779 int i, ret = 0;
780
781 if (pdev->dev.platform_data) {
782 pdata = pdev->dev.platform_data;
783 return pdata;
784 } else if (match) {
Jyri Sarha256ba182013-10-18 18:37:42 +0300785 pdata = (struct snd_platform_data *) match->data;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530786 } else {
787 /* control shouldn't reach here. something is wrong */
788 ret = -EINVAL;
789 goto nodata;
790 }
791
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530792 ret = of_property_read_u32(np, "op-mode", &val);
793 if (ret >= 0)
794 pdata->op_mode = val;
795
796 ret = of_property_read_u32(np, "tdm-slots", &val);
Michal Bachraty2952b272013-02-28 16:07:08 +0100797 if (ret >= 0) {
798 if (val < 2 || val > 32) {
799 dev_err(&pdev->dev,
800 "tdm-slots must be in rage [2-32]\n");
801 ret = -EINVAL;
802 goto nodata;
803 }
804
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530805 pdata->tdm_slots = val;
Michal Bachraty2952b272013-02-28 16:07:08 +0100806 }
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530807
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530808 of_serial_dir32 = of_get_property(np, "serial-dir", &val);
809 val /= sizeof(u32);
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530810 if (of_serial_dir32) {
Peter Ujfalusi1427e662013-10-18 18:37:46 +0300811 u8 *of_serial_dir = devm_kzalloc(&pdev->dev,
812 (sizeof(*of_serial_dir) * val),
813 GFP_KERNEL);
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530814 if (!of_serial_dir) {
815 ret = -ENOMEM;
816 goto nodata;
817 }
818
Peter Ujfalusi1427e662013-10-18 18:37:46 +0300819 for (i = 0; i < val; i++)
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530820 of_serial_dir[i] = be32_to_cpup(&of_serial_dir32[i]);
821
Peter Ujfalusi1427e662013-10-18 18:37:46 +0300822 pdata->num_serializer = val;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530823 pdata->serial_dir = of_serial_dir;
824 }
825
Jyri Sarha4023fe62013-10-18 18:37:43 +0300826 ret = of_property_match_string(np, "dma-names", "tx");
827 if (ret < 0)
828 goto nodata;
829
830 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
831 &dma_spec);
832 if (ret < 0)
833 goto nodata;
834
835 pdata->tx_dma_channel = dma_spec.args[0];
836
837 ret = of_property_match_string(np, "dma-names", "rx");
838 if (ret < 0)
839 goto nodata;
840
841 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
842 &dma_spec);
843 if (ret < 0)
844 goto nodata;
845
846 pdata->rx_dma_channel = dma_spec.args[0];
847
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530848 ret = of_property_read_u32(np, "tx-num-evt", &val);
849 if (ret >= 0)
850 pdata->txnumevt = val;
851
852 ret = of_property_read_u32(np, "rx-num-evt", &val);
853 if (ret >= 0)
854 pdata->rxnumevt = val;
855
856 ret = of_property_read_u32(np, "sram-size-playback", &val);
857 if (ret >= 0)
858 pdata->sram_size_playback = val;
859
860 ret = of_property_read_u32(np, "sram-size-capture", &val);
861 if (ret >= 0)
862 pdata->sram_size_capture = val;
863
864 return pdata;
865
866nodata:
867 if (ret < 0) {
868 dev_err(&pdev->dev, "Error populating platform data, err %d\n",
869 ret);
870 pdata = NULL;
871 }
872 return pdata;
873}
874
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400875static int davinci_mcasp_probe(struct platform_device *pdev)
876{
877 struct davinci_pcm_dma_params *dma_data;
Jyri Sarha256ba182013-10-18 18:37:42 +0300878 struct resource *mem, *ioarea, *res, *dat;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400879 struct snd_platform_data *pdata;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200880 struct davinci_mcasp *mcasp;
Julia Lawall96d31e22011-12-29 17:51:21 +0100881 int ret;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400882
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530883 if (!pdev->dev.platform_data && !pdev->dev.of_node) {
884 dev_err(&pdev->dev, "No platform data supplied\n");
885 return -EINVAL;
886 }
887
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200888 mcasp = devm_kzalloc(&pdev->dev, sizeof(struct davinci_mcasp),
Julia Lawall96d31e22011-12-29 17:51:21 +0100889 GFP_KERNEL);
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200890 if (!mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400891 return -ENOMEM;
892
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530893 pdata = davinci_mcasp_set_pdata_from_of(pdev);
894 if (!pdata) {
895 dev_err(&pdev->dev, "no platform data\n");
896 return -EINVAL;
897 }
898
Jyri Sarha256ba182013-10-18 18:37:42 +0300899 mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400900 if (!mem) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200901 dev_warn(mcasp->dev,
Jyri Sarha256ba182013-10-18 18:37:42 +0300902 "\"mpu\" mem resource not found, using index 0\n");
903 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
904 if (!mem) {
905 dev_err(&pdev->dev, "no mem resource?\n");
906 return -ENODEV;
907 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400908 }
909
Julia Lawall96d31e22011-12-29 17:51:21 +0100910 ioarea = devm_request_mem_region(&pdev->dev, mem->start,
Vaibhav Bediad852f4462011-02-09 18:39:52 +0530911 resource_size(mem), pdev->name);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400912 if (!ioarea) {
913 dev_err(&pdev->dev, "Audio region already claimed\n");
Julia Lawall96d31e22011-12-29 17:51:21 +0100914 return -EBUSY;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400915 }
916
Hebbar, Gururaja10884342012-08-08 20:40:32 +0530917 pm_runtime_enable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400918
Hebbar, Gururaja10884342012-08-08 20:40:32 +0530919 ret = pm_runtime_get_sync(&pdev->dev);
920 if (IS_ERR_VALUE(ret)) {
921 dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
922 return ret;
923 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400924
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200925 mcasp->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
926 if (!mcasp->base) {
Vaibhav Bedia4f82f022011-02-09 18:39:54 +0530927 dev_err(&pdev->dev, "ioremap failed\n");
928 ret = -ENOMEM;
929 goto err_release_clk;
930 }
931
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200932 mcasp->op_mode = pdata->op_mode;
933 mcasp->tdm_slots = pdata->tdm_slots;
934 mcasp->num_serializer = pdata->num_serializer;
935 mcasp->serial_dir = pdata->serial_dir;
936 mcasp->version = pdata->version;
937 mcasp->txnumevt = pdata->txnumevt;
938 mcasp->rxnumevt = pdata->rxnumevt;
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200939
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200940 mcasp->dev = &pdev->dev;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400941
Jyri Sarha256ba182013-10-18 18:37:42 +0300942 dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200943 if (dat)
944 mcasp->dat_port = true;
Jyri Sarha256ba182013-10-18 18:37:42 +0300945
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200946 dma_data = &mcasp->dma_params[SNDRV_PCM_STREAM_PLAYBACK];
Sekhar Nori48519f02010-07-19 12:31:16 +0530947 dma_data->asp_chan_q = pdata->asp_chan_q;
948 dma_data->ram_chan_q = pdata->ram_chan_q;
Matt Porterb8ec56d2012-10-17 16:08:03 +0200949 dma_data->sram_pool = pdata->sram_pool;
Ben Gardinera0c83262011-05-18 09:27:45 -0400950 dma_data->sram_size = pdata->sram_size_playback;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200951 if (dat)
952 dma_data->dma_addr = dat->start;
953 else
954 dma_data->dma_addr = mem->start + pdata->tx_dma_offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400955
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400956 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
Jyri Sarha4023fe62013-10-18 18:37:43 +0300957 if (res)
958 dma_data->channel = res->start;
959 else
960 dma_data->channel = pdata->tx_dma_channel;
Troy Kisky92e2a6f2009-09-11 14:29:03 -0700961
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200962 dma_data = &mcasp->dma_params[SNDRV_PCM_STREAM_CAPTURE];
Sekhar Nori48519f02010-07-19 12:31:16 +0530963 dma_data->asp_chan_q = pdata->asp_chan_q;
964 dma_data->ram_chan_q = pdata->ram_chan_q;
Matt Porterb8ec56d2012-10-17 16:08:03 +0200965 dma_data->sram_pool = pdata->sram_pool;
Ben Gardinera0c83262011-05-18 09:27:45 -0400966 dma_data->sram_size = pdata->sram_size_capture;
Peter Ujfalusicbc7956c2013-11-14 11:35:32 +0200967 if (dat)
968 dma_data->dma_addr = dat->start;
969 else
970 dma_data->dma_addr = mem->start + pdata->rx_dma_offset;
971
972 if (mcasp->version < MCASP_VERSION_3) {
973 mcasp->fifo_base = DAVINCI_MCASP_V2_AFIFO_BASE;
974 /* dma_data->dma_addr is pointing to the data port address */
975 mcasp->dat_port = true;
976 } else {
977 mcasp->fifo_base = DAVINCI_MCASP_V3_AFIFO_BASE;
978 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400979
980 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
Jyri Sarha4023fe62013-10-18 18:37:43 +0300981 if (res)
982 dma_data->channel = res->start;
983 else
984 dma_data->channel = pdata->rx_dma_channel;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400985
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200986 dev_set_drvdata(&pdev->dev, mcasp);
Kuninori Morimotoeeef0ed2013-03-21 03:31:19 -0700987 ret = snd_soc_register_component(&pdev->dev, &davinci_mcasp_component,
988 &davinci_mcasp_dai[pdata->op_mode], 1);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400989
990 if (ret != 0)
Julia Lawall96d31e22011-12-29 17:51:21 +0100991 goto err_release_clk;
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530992
993 ret = davinci_soc_platform_register(&pdev->dev);
994 if (ret) {
995 dev_err(&pdev->dev, "register PCM failed: %d\n", ret);
Kuninori Morimotoeeef0ed2013-03-21 03:31:19 -0700996 goto err_unregister_component;
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530997 }
998
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400999 return 0;
1000
Kuninori Morimotoeeef0ed2013-03-21 03:31:19 -07001001err_unregister_component:
1002 snd_soc_unregister_component(&pdev->dev);
Vaibhav Bediaeef6d7b2011-02-09 18:39:53 +05301003err_release_clk:
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301004 pm_runtime_put_sync(&pdev->dev);
1005 pm_runtime_disable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001006 return ret;
1007}
1008
1009static int davinci_mcasp_remove(struct platform_device *pdev)
1010{
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001011
Kuninori Morimotoeeef0ed2013-03-21 03:31:19 -07001012 snd_soc_unregister_component(&pdev->dev);
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +05301013 davinci_soc_platform_unregister(&pdev->dev);
Hebbar, Gururaja10884342012-08-08 20:40:32 +05301014
1015 pm_runtime_put_sync(&pdev->dev);
1016 pm_runtime_disable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001017
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001018 return 0;
1019}
1020
Daniel Macka85e4192013-10-01 14:50:02 +02001021#ifdef CONFIG_PM_SLEEP
1022static int davinci_mcasp_suspend(struct device *dev)
1023{
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001024 struct davinci_mcasp *mcasp = dev_get_drvdata(dev);
1025 void __iomem *base = mcasp->base;
Daniel Macka85e4192013-10-01 14:50:02 +02001026
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001027 mcasp->context.txfmtctl = mcasp_get_reg(base + DAVINCI_MCASP_TXFMCTL_REG);
1028 mcasp->context.rxfmtctl = mcasp_get_reg(base + DAVINCI_MCASP_RXFMCTL_REG);
1029 mcasp->context.txfmt = mcasp_get_reg(base + DAVINCI_MCASP_TXFMT_REG);
1030 mcasp->context.rxfmt = mcasp_get_reg(base + DAVINCI_MCASP_RXFMT_REG);
1031 mcasp->context.aclkxctl = mcasp_get_reg(base + DAVINCI_MCASP_ACLKXCTL_REG);
1032 mcasp->context.aclkrctl = mcasp_get_reg(base + DAVINCI_MCASP_ACLKRCTL_REG);
1033 mcasp->context.pdir = mcasp_get_reg(base + DAVINCI_MCASP_PDIR_REG);
Daniel Macka85e4192013-10-01 14:50:02 +02001034
1035 return 0;
1036}
1037
1038static int davinci_mcasp_resume(struct device *dev)
1039{
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001040 struct davinci_mcasp *mcasp = dev_get_drvdata(dev);
1041 void __iomem *base = mcasp->base;
Daniel Macka85e4192013-10-01 14:50:02 +02001042
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001043 mcasp_set_reg(base + DAVINCI_MCASP_TXFMCTL_REG, mcasp->context.txfmtctl);
1044 mcasp_set_reg(base + DAVINCI_MCASP_RXFMCTL_REG, mcasp->context.rxfmtctl);
1045 mcasp_set_reg(base + DAVINCI_MCASP_TXFMT_REG, mcasp->context.txfmt);
1046 mcasp_set_reg(base + DAVINCI_MCASP_RXFMT_REG, mcasp->context.rxfmt);
1047 mcasp_set_reg(base + DAVINCI_MCASP_ACLKXCTL_REG, mcasp->context.aclkxctl);
1048 mcasp_set_reg(base + DAVINCI_MCASP_ACLKRCTL_REG, mcasp->context.aclkrctl);
1049 mcasp_set_reg(base + DAVINCI_MCASP_PDIR_REG, mcasp->context.pdir);
Daniel Macka85e4192013-10-01 14:50:02 +02001050
1051 return 0;
1052}
1053#endif
1054
1055SIMPLE_DEV_PM_OPS(davinci_mcasp_pm_ops,
1056 davinci_mcasp_suspend,
1057 davinci_mcasp_resume);
1058
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001059static struct platform_driver davinci_mcasp_driver = {
1060 .probe = davinci_mcasp_probe,
1061 .remove = davinci_mcasp_remove,
1062 .driver = {
1063 .name = "davinci-mcasp",
1064 .owner = THIS_MODULE,
Daniel Macka85e4192013-10-01 14:50:02 +02001065 .pm = &davinci_mcasp_pm_ops,
Sachin Kamatea421eb2013-05-22 16:53:37 +05301066 .of_match_table = mcasp_dt_ids,
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001067 },
1068};
1069
Axel Linf9b8a512011-11-25 10:09:27 +08001070module_platform_driver(davinci_mcasp_driver);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001071
1072MODULE_AUTHOR("Steve Chen");
1073MODULE_DESCRIPTION("TI DAVINCI McASP SoC Interface");
1074MODULE_LICENSE("GPL");