blob: 72ea45893abf37a0f55e675d2bb97457b21763c9 [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
56#ifdef CONFIG_PM_SLEEP
57 struct {
58 u32 txfmtctl;
59 u32 rxfmtctl;
60 u32 txfmt;
61 u32 rxfmt;
62 u32 aclkxctl;
63 u32 aclkrctl;
64 u32 pdir;
65 } context;
66#endif
67};
68
Chaithrika U Sb67f4482009-06-05 06:28:40 -040069static inline void mcasp_set_bits(void __iomem *reg, u32 val)
70{
71 __raw_writel(__raw_readl(reg) | val, reg);
72}
73
74static inline void mcasp_clr_bits(void __iomem *reg, u32 val)
75{
76 __raw_writel((__raw_readl(reg) & ~(val)), reg);
77}
78
79static inline void mcasp_mod_bits(void __iomem *reg, u32 val, u32 mask)
80{
81 __raw_writel((__raw_readl(reg) & ~mask) | val, reg);
82}
83
84static inline void mcasp_set_reg(void __iomem *reg, u32 val)
85{
86 __raw_writel(val, reg);
87}
88
89static inline u32 mcasp_get_reg(void __iomem *reg)
90{
91 return (unsigned int)__raw_readl(reg);
92}
93
Peter Ujfalusieba0ecf2013-11-14 11:35:28 +020094static void mcasp_set_ctl_reg(void __iomem *regs, u32 val)
Chaithrika U Sb67f4482009-06-05 06:28:40 -040095{
96 int i = 0;
97
98 mcasp_set_bits(regs, val);
99
100 /* programming GBLCTL needs to read back from GBLCTL and verfiy */
101 /* loop count is to avoid the lock-up */
102 for (i = 0; i < 1000; i++) {
103 if ((mcasp_get_reg(regs) & val) == val)
104 break;
105 }
106
107 if (i == 1000 && ((mcasp_get_reg(regs) & val) != val))
108 printk(KERN_ERR "GBLCTL write error\n");
109}
110
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200111static void mcasp_start_rx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400112{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200113 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, RXHCLKRST);
114 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, RXCLKRST);
115 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, RXSERCLR);
116 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_RXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400117
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200118 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, RXSMRST);
119 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, RXFSRST);
120 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_RXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400121
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200122 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, RXSMRST);
123 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, RXFSRST);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400124}
125
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200126static void mcasp_start_tx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400127{
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400128 u8 offset = 0, i;
129 u32 cnt;
130
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200131 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST);
132 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST);
133 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLX_REG, TXSERCLR);
134 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400135
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200136 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLX_REG, TXSMRST);
137 mcasp_set_ctl_reg(mcasp->base + DAVINCI_MCASP_GBLCTLX_REG, TXFSRST);
138 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXBUF_REG, 0);
139 for (i = 0; i < mcasp->num_serializer; i++) {
140 if (mcasp->serial_dir[i] == TX_MODE) {
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400141 offset = i;
142 break;
143 }
144 }
145
146 /* wait for TX ready */
147 cnt = 0;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200148 while (!(mcasp_get_reg(mcasp->base + DAVINCI_MCASP_XRSRCTL_REG(offset)) &
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400149 TXSTATE) && (cnt < 100000))
150 cnt++;
151
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200152 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXBUF_REG, 0);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400153}
154
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200155static void davinci_mcasp_start(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400156{
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200157 u32 reg;
158
Chaithrika U S539d3d82009-09-23 10:12:08 -0400159 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200160 if (mcasp->txnumevt) { /* enable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200161 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
162 mcasp_clr_bits(mcasp->base + reg, FIFO_ENABLE);
163 mcasp_set_bits(mcasp->base + reg, FIFO_ENABLE);
Vaibhav Bedia0d624272012-08-08 20:40:31 +0530164 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200165 mcasp_start_tx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400166 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200167 if (mcasp->rxnumevt) { /* enable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200168 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
169 mcasp_clr_bits(mcasp->base + reg, FIFO_ENABLE);
170 mcasp_set_bits(mcasp->base + reg, FIFO_ENABLE);
Vaibhav Bedia0d624272012-08-08 20:40:31 +0530171 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200172 mcasp_start_rx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400173 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400174}
175
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200176static void mcasp_stop_rx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400177{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200178 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_GBLCTLR_REG, 0);
179 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400180}
181
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200182static void mcasp_stop_tx(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400183{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200184 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_GBLCTLX_REG, 0);
185 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400186}
187
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200188static void davinci_mcasp_stop(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400189{
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200190 u32 reg;
191
Chaithrika U S539d3d82009-09-23 10:12:08 -0400192 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200193 if (mcasp->txnumevt) { /* disable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200194 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
195 mcasp_clr_bits(mcasp->base + reg, FIFO_ENABLE);
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530196 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200197 mcasp_stop_tx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400198 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200199 if (mcasp->rxnumevt) { /* disable FIFO */
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200200 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
201 mcasp_clr_bits(mcasp->base + reg, FIFO_ENABLE);
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530202 }
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200203 mcasp_stop_rx(mcasp);
Chaithrika U S539d3d82009-09-23 10:12:08 -0400204 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400205}
206
207static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
208 unsigned int fmt)
209{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200210 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
211 void __iomem *base = mcasp->base;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400212
Daniel Mack5296cf22012-10-04 15:08:42 +0200213 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
214 case SND_SOC_DAIFMT_DSP_B:
215 case SND_SOC_DAIFMT_AC97:
Peter Ujfalusi8f113b72013-11-14 11:35:30 +0200216 mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
217 mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
Daniel Mack5296cf22012-10-04 15:08:42 +0200218 break;
219 default:
220 /* configure a full-word SYNC pulse (LRCLK) */
Peter Ujfalusi8f113b72013-11-14 11:35:30 +0200221 mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXDUR);
222 mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRDUR);
Daniel Mack5296cf22012-10-04 15:08:42 +0200223
224 /* make 1st data bit occur one ACLK cycle after the frame sync */
Peter Ujfalusi8f113b72013-11-14 11:35:30 +0200225 mcasp_set_bits(base + DAVINCI_MCASP_TXFMT_REG, FSXDLY(1));
226 mcasp_set_bits(base + DAVINCI_MCASP_RXFMT_REG, FSRDLY(1));
Daniel Mack5296cf22012-10-04 15:08:42 +0200227 break;
228 }
229
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400230 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
231 case SND_SOC_DAIFMT_CBS_CFS:
232 /* codec is clock and frame slave */
233 mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
234 mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
235
236 mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
237 mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
238
Marek Belisko81ee6832013-04-26 14:38:11 +0200239 mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG,
240 ACLKX | ACLKR);
241 mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG,
242 AFSX | AFSR);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400243 break;
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400244 case SND_SOC_DAIFMT_CBM_CFS:
245 /* codec is clock master and frame slave */
Ben Gardinera90f5492011-04-21 14:19:03 -0400246 mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400247 mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
248
Ben Gardinera90f5492011-04-21 14:19:03 -0400249 mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400250 mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
251
Ben Gardinerdb92f432011-04-21 14:19:04 -0400252 mcasp_clr_bits(base + DAVINCI_MCASP_PDIR_REG,
253 ACLKX | ACLKR);
Ben Gardiner9595c8f2011-04-21 14:19:02 -0400254 mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG,
Ben Gardinerdb92f432011-04-21 14:19:04 -0400255 AFSX | AFSR);
Chaithrika U S517ee6c2009-08-11 16:59:12 -0400256 break;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400257 case SND_SOC_DAIFMT_CBM_CFM:
258 /* codec is clock and frame master */
259 mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE);
260 mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE);
261
262 mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE);
263 mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE);
264
Ben Gardiner9595c8f2011-04-21 14:19:02 -0400265 mcasp_clr_bits(base + DAVINCI_MCASP_PDIR_REG,
266 ACLKX | AHCLKX | AFSX | ACLKR | AHCLKR | AFSR);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400267 break;
268
269 default:
270 return -EINVAL;
271 }
272
273 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
274 case SND_SOC_DAIFMT_IB_NF:
275 mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
276 mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL);
277
278 mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
279 mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL);
280 break;
281
282 case SND_SOC_DAIFMT_NB_IF:
283 mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
284 mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL);
285
286 mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
287 mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL);
288 break;
289
290 case SND_SOC_DAIFMT_IB_IF:
291 mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
292 mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL);
293
294 mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
295 mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL);
296 break;
297
298 case SND_SOC_DAIFMT_NB_NF:
299 mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL);
300 mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL);
301
Marek Beliskodf4a4ee2013-05-03 07:37:36 +0200302 mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400303 mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL);
304 break;
305
306 default:
307 return -EINVAL;
308 }
309
310 return 0;
311}
312
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200313static int davinci_mcasp_set_clkdiv(struct snd_soc_dai *dai, int div_id, int div)
314{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200315 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200316
317 switch (div_id) {
318 case 0: /* MCLK divider */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200319 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_AHCLKXCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200320 AHCLKXDIV(div - 1), AHCLKXDIV_MASK);
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200321 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_AHCLKRCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200322 AHCLKRDIV(div - 1), AHCLKRDIV_MASK);
323 break;
324
325 case 1: /* BCLK divider */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200326 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_ACLKXCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200327 ACLKXDIV(div - 1), ACLKXDIV_MASK);
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200328 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_ACLKRCTL_REG,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200329 ACLKRDIV(div - 1), ACLKRDIV_MASK);
330 break;
331
Daniel Mack1b3bc062012-12-05 18:20:38 +0100332 case 2: /* BCLK/LRCLK ratio */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200333 mcasp->bclk_lrclk_ratio = div;
Daniel Mack1b3bc062012-12-05 18:20:38 +0100334 break;
335
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200336 default:
337 return -EINVAL;
338 }
339
340 return 0;
341}
342
Daniel Mack5b66aa22012-10-04 15:08:41 +0200343static int davinci_mcasp_set_sysclk(struct snd_soc_dai *dai, int clk_id,
344 unsigned int freq, int dir)
345{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200346 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200347
348 if (dir == SND_SOC_CLOCK_OUT) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200349 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE);
350 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE);
351 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_PDIR_REG, AHCLKX);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200352 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200353 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE);
354 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE);
355 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_PDIR_REG, AHCLKX);
Daniel Mack5b66aa22012-10-04 15:08:41 +0200356 }
357
358 return 0;
359}
360
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200361static int davinci_config_channel_size(struct davinci_mcasp *mcasp,
Daniel Mackba764b32012-12-05 18:20:37 +0100362 int word_length)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400363{
Daniel Mackba764b32012-12-05 18:20:37 +0100364 u32 fmt;
Daniel Mack79671892013-05-16 15:25:01 +0200365 u32 tx_rotate = (word_length / 4) & 0x7;
366 u32 rx_rotate = (32 - word_length) / 4;
Daniel Mackba764b32012-12-05 18:20:37 +0100367 u32 mask = (1ULL << word_length) - 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400368
Daniel Mack1b3bc062012-12-05 18:20:38 +0100369 /*
370 * if s BCLK-to-LRCLK ratio has been configured via the set_clkdiv()
371 * callback, take it into account here. That allows us to for example
372 * send 32 bits per channel to the codec, while only 16 of them carry
373 * audio payload.
Michal Bachratyd486fea2013-04-19 15:28:44 +0200374 * The clock ratio is given for a full period of data (for I2S format
375 * both left and right channels), so it has to be divided by number of
376 * tdm-slots (for I2S - divided by 2).
Daniel Mack1b3bc062012-12-05 18:20:38 +0100377 */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200378 if (mcasp->bclk_lrclk_ratio)
379 word_length = mcasp->bclk_lrclk_ratio / mcasp->tdm_slots;
Daniel Mack1b3bc062012-12-05 18:20:38 +0100380
Daniel Mackba764b32012-12-05 18:20:37 +0100381 /* mapping of the XSSZ bit-field as described in the datasheet */
382 fmt = (word_length >> 1) - 1;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400383
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200384 if (mcasp->op_mode != DAVINCI_MCASP_DIT_MODE) {
385 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_RXFMT_REG,
Yegor Yefremovf5023af2013-04-04 16:13:20 +0200386 RXSSZ(fmt), RXSSZ(0x0F));
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200387 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_TXFMT_REG,
Yegor Yefremovf5023af2013-04-04 16:13:20 +0200388 TXSSZ(fmt), TXSSZ(0x0F));
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200389 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_TXFMT_REG,
Daniel Mack79671892013-05-16 15:25:01 +0200390 TXROT(tx_rotate), TXROT(7));
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200391 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_RXFMT_REG,
Daniel Mack79671892013-05-16 15:25:01 +0200392 RXROT(rx_rotate), RXROT(7));
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200393 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_RXMASK_REG,
Yegor Yefremovf5023af2013-04-04 16:13:20 +0200394 mask);
395 }
396
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200397 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXMASK_REG, mask);
Chaithrika U S0c31cf32009-09-15 18:13:29 -0400398
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400399 return 0;
400}
401
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200402static int davinci_hw_common_param(struct davinci_mcasp *mcasp, int stream,
Michal Bachraty2952b272013-02-28 16:07:08 +0100403 int channels)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400404{
405 int i;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400406 u8 tx_ser = 0;
407 u8 rx_ser = 0;
Michal Bachraty2952b272013-02-28 16:07:08 +0100408 u8 ser;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200409 u8 slots = mcasp->tdm_slots;
Michal Bachraty2952b272013-02-28 16:07:08 +0100410 u8 max_active_serializers = (channels + slots - 1) / slots;
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200411 u32 reg;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400412 /* Default configuration */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200413 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_PWREMUMGT_REG, MCASP_SOFT);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400414
415 /* All PINS as McASP */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200416 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_PFUNC_REG, 0x00000000);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400417
418 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200419 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF);
420 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_XEVTCTL_REG,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400421 TXDATADMADIS);
422 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200423 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF);
424 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_REVTCTL_REG,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400425 RXDATADMADIS);
426 }
427
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200428 for (i = 0; i < mcasp->num_serializer; i++) {
429 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_XRSRCTL_REG(i),
430 mcasp->serial_dir[i]);
431 if (mcasp->serial_dir[i] == TX_MODE &&
Michal Bachraty2952b272013-02-28 16:07:08 +0100432 tx_ser < max_active_serializers) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200433 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_PDIR_REG,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400434 AXR(i));
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400435 tx_ser++;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200436 } else if (mcasp->serial_dir[i] == RX_MODE &&
Michal Bachraty2952b272013-02-28 16:07:08 +0100437 rx_ser < max_active_serializers) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200438 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_PDIR_REG,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400439 AXR(i));
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400440 rx_ser++;
Michal Bachraty2952b272013-02-28 16:07:08 +0100441 } else {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200442 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_XRSRCTL_REG(i),
Michal Bachraty2952b272013-02-28 16:07:08 +0100443 SRMOD_INACTIVE, SRMOD_MASK);
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400444 }
445 }
446
Daniel Mackecf327c2013-03-08 14:19:38 +0100447 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
448 ser = tx_ser;
449 else
450 ser = rx_ser;
451
452 if (ser < max_active_serializers) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200453 dev_warn(mcasp->dev, "stream has more channels (%d) than are "
Daniel Mackecf327c2013-03-08 14:19:38 +0100454 "enabled in mcasp (%d)\n", channels, ser * slots);
455 return -EINVAL;
456 }
457
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200458 if (mcasp->txnumevt && stream == SNDRV_PCM_STREAM_PLAYBACK) {
459 if (mcasp->txnumevt * tx_ser > 64)
460 mcasp->txnumevt = 1;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400461
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200462 reg = mcasp->fifo_base + MCASP_WFIFOCTL_OFFSET;
463 mcasp_mod_bits(mcasp->base + reg, tx_ser, NUMDMA_MASK);
464 mcasp_mod_bits(mcasp->base + reg,
465 ((mcasp->txnumevt * tx_ser) << 8), NUMEVT_MASK);
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400466 }
467
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200468 if (mcasp->rxnumevt && stream == SNDRV_PCM_STREAM_CAPTURE) {
469 if (mcasp->rxnumevt * rx_ser > 64)
470 mcasp->rxnumevt = 1;
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200471
472 reg = mcasp->fifo_base + MCASP_RFIFOCTL_OFFSET;
473 mcasp_mod_bits(mcasp->base + reg, rx_ser, NUMDMA_MASK);
474 mcasp_mod_bits(mcasp->base + reg,
475 ((mcasp->rxnumevt * rx_ser) << 8), NUMEVT_MASK);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400476 }
Michal Bachraty2952b272013-02-28 16:07:08 +0100477
478 return 0;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400479}
480
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200481static void davinci_hw_param(struct davinci_mcasp *mcasp, int stream)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400482{
483 int i, active_slots;
484 u32 mask = 0;
485
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200486 active_slots = (mcasp->tdm_slots > 31) ? 32 : mcasp->tdm_slots;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400487 for (i = 0; i < active_slots; i++)
488 mask |= (1 << i);
489
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200490 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC);
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400491
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400492 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
493 /* bit stream is MSB first with no delay */
494 /* DSP_B mode */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200495 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXTDM_REG, mask);
496 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_TXFMT_REG, TXORD);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400497
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200498 if ((mcasp->tdm_slots >= 2) && (mcasp->tdm_slots <= 32))
499 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_TXFMCTL_REG,
500 FSXMOD(mcasp->tdm_slots), FSXMOD(0x1FF));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400501 else
502 printk(KERN_ERR "playback tdm slot %d not supported\n",
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200503 mcasp->tdm_slots);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400504 } else {
505 /* bit stream is MSB first with no delay */
506 /* DSP_B mode */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200507 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_RXFMT_REG, RXORD);
508 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_RXTDM_REG, mask);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400509
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200510 if ((mcasp->tdm_slots >= 2) && (mcasp->tdm_slots <= 32))
511 mcasp_mod_bits(mcasp->base + DAVINCI_MCASP_RXFMCTL_REG,
512 FSRMOD(mcasp->tdm_slots), FSRMOD(0x1FF));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400513 else
514 printk(KERN_ERR "capture tdm slot %d not supported\n",
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200515 mcasp->tdm_slots);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400516 }
517}
518
519/* S/PDIF */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200520static void davinci_hw_dit_param(struct davinci_mcasp *mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400521{
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400522 /* Set the TX format : 24 bit right rotation, 32 bit slot, Pad 0
523 and LSB first */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200524 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_TXFMT_REG,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400525 TXROT(6) | TXSSZ(15));
526
527 /* Set TX frame synch : DIT Mode, 1 bit width, internal, rising edge */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200528 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXFMCTL_REG,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400529 AFSXE | FSXMOD(0x180));
530
531 /* Set the TX tdm : for all the slots */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200532 mcasp_set_reg(mcasp->base + DAVINCI_MCASP_TXTDM_REG, 0xFFFFFFFF);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400533
534 /* Set the TX clock controls : div = 1 and internal */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200535 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_ACLKXCTL_REG,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400536 ACLKXE | TX_ASYNC);
537
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200538 mcasp_clr_bits(mcasp->base + DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400539
540 /* Only 44100 and 48000 are valid, both have the same setting */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200541 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXDIV(3));
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400542
543 /* Enable the DIT */
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200544 mcasp_set_bits(mcasp->base + DAVINCI_MCASP_TXDITCTL_REG, DITEN);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400545}
546
547static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
548 struct snd_pcm_hw_params *params,
549 struct snd_soc_dai *cpu_dai)
550{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200551 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400552 struct davinci_pcm_dma_params *dma_params =
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200553 &mcasp->dma_params[substream->stream];
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400554 int word_length;
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400555 u8 fifo_level;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200556 u8 slots = mcasp->tdm_slots;
Michal Bachraty7c21a782013-04-19 15:28:03 +0200557 u8 active_serializers;
Michal Bachraty2952b272013-02-28 16:07:08 +0100558 int channels;
559 struct snd_interval *pcm_channels = hw_param_interval(params,
560 SNDRV_PCM_HW_PARAM_CHANNELS);
561 channels = pcm_channels->min;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400562
Michal Bachraty7c21a782013-04-19 15:28:03 +0200563 active_serializers = (channels + slots - 1) / slots;
564
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200565 if (davinci_hw_common_param(mcasp, substream->stream, channels) == -EINVAL)
Michal Bachraty2952b272013-02-28 16:07:08 +0100566 return -EINVAL;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400567 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200568 fifo_level = mcasp->txnumevt * active_serializers;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400569 else
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200570 fifo_level = mcasp->rxnumevt * active_serializers;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400571
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200572 if (mcasp->op_mode == DAVINCI_MCASP_DIT_MODE)
573 davinci_hw_dit_param(mcasp);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400574 else
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200575 davinci_hw_param(mcasp, substream->stream);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400576
577 switch (params_format(params)) {
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400578 case SNDRV_PCM_FORMAT_U8:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400579 case SNDRV_PCM_FORMAT_S8:
580 dma_params->data_type = 1;
Daniel Mackba764b32012-12-05 18:20:37 +0100581 word_length = 8;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400582 break;
583
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400584 case SNDRV_PCM_FORMAT_U16_LE:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400585 case SNDRV_PCM_FORMAT_S16_LE:
586 dma_params->data_type = 2;
Daniel Mackba764b32012-12-05 18:20:37 +0100587 word_length = 16;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400588 break;
589
Daniel Mack21eb24d2012-10-09 09:35:16 +0200590 case SNDRV_PCM_FORMAT_U24_3LE:
591 case SNDRV_PCM_FORMAT_S24_3LE:
Daniel Mack21eb24d2012-10-09 09:35:16 +0200592 dma_params->data_type = 3;
Daniel Mackba764b32012-12-05 18:20:37 +0100593 word_length = 24;
Daniel Mack21eb24d2012-10-09 09:35:16 +0200594 break;
595
Daniel Mack6b7fa012012-10-09 11:56:40 +0200596 case SNDRV_PCM_FORMAT_U24_LE:
597 case SNDRV_PCM_FORMAT_S24_LE:
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400598 case SNDRV_PCM_FORMAT_U32_LE:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400599 case SNDRV_PCM_FORMAT_S32_LE:
600 dma_params->data_type = 4;
Daniel Mackba764b32012-12-05 18:20:37 +0100601 word_length = 32;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400602 break;
603
604 default:
605 printk(KERN_WARNING "davinci-mcasp: unsupported PCM format");
606 return -EINVAL;
607 }
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400608
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200609 if (mcasp->version == MCASP_VERSION_2 && !fifo_level)
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400610 dma_params->acnt = 4;
611 else
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400612 dma_params->acnt = dma_params->data_type;
613
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400614 dma_params->fifo_level = fifo_level;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200615 davinci_config_channel_size(mcasp, word_length);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400616
617 return 0;
618}
619
620static int davinci_mcasp_trigger(struct snd_pcm_substream *substream,
621 int cmd, struct snd_soc_dai *cpu_dai)
622{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200623 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(cpu_dai);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400624 int ret = 0;
625
626 switch (cmd) {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400627 case SNDRV_PCM_TRIGGER_RESUME:
Chaithrika U Se473b842010-01-20 17:06:33 +0530628 case SNDRV_PCM_TRIGGER_START:
629 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200630 ret = pm_runtime_get_sync(mcasp->dev);
Hebbar, Gururaja10884342012-08-08 20:40:32 +0530631 if (IS_ERR_VALUE(ret))
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200632 dev_err(mcasp->dev, "pm_runtime_get_sync() failed\n");
633 davinci_mcasp_start(mcasp, substream->stream);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400634 break;
635
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400636 case SNDRV_PCM_TRIGGER_SUSPEND:
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200637 davinci_mcasp_stop(mcasp, substream->stream);
638 ret = pm_runtime_put_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_put_sync() failed\n");
Chaithrika U Sa47979b2009-12-03 18:56:56 +0530641 break;
642
643 case SNDRV_PCM_TRIGGER_STOP:
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400644 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200645 davinci_mcasp_stop(mcasp, substream->stream);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400646 break;
647
648 default:
649 ret = -EINVAL;
650 }
651
652 return ret;
653}
654
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000655static int davinci_mcasp_startup(struct snd_pcm_substream *substream,
656 struct snd_soc_dai *dai)
657{
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200658 struct davinci_mcasp *mcasp = snd_soc_dai_get_drvdata(dai);
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000659
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200660 snd_soc_dai_set_dma_data(dai, substream, mcasp->dma_params);
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000661 return 0;
662}
663
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100664static const struct snd_soc_dai_ops davinci_mcasp_dai_ops = {
Chris Paulson-Ellisbedad0c2010-11-16 12:27:09 +0000665 .startup = davinci_mcasp_startup,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400666 .trigger = davinci_mcasp_trigger,
667 .hw_params = davinci_mcasp_hw_params,
668 .set_fmt = davinci_mcasp_set_dai_fmt,
Daniel Mack4ed8c9b2012-10-04 15:08:39 +0200669 .set_clkdiv = davinci_mcasp_set_clkdiv,
Daniel Mack5b66aa22012-10-04 15:08:41 +0200670 .set_sysclk = davinci_mcasp_set_sysclk,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400671};
672
Peter Ujfalusied29cd52013-11-14 11:35:22 +0200673#define DAVINCI_MCASP_RATES SNDRV_PCM_RATE_8000_192000
674
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400675#define DAVINCI_MCASP_PCM_FMTS (SNDRV_PCM_FMTBIT_S8 | \
676 SNDRV_PCM_FMTBIT_U8 | \
677 SNDRV_PCM_FMTBIT_S16_LE | \
678 SNDRV_PCM_FMTBIT_U16_LE | \
Daniel Mack21eb24d2012-10-09 09:35:16 +0200679 SNDRV_PCM_FMTBIT_S24_LE | \
680 SNDRV_PCM_FMTBIT_U24_LE | \
681 SNDRV_PCM_FMTBIT_S24_3LE | \
682 SNDRV_PCM_FMTBIT_U24_3LE | \
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400683 SNDRV_PCM_FMTBIT_S32_LE | \
684 SNDRV_PCM_FMTBIT_U32_LE)
685
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000686static struct snd_soc_dai_driver davinci_mcasp_dai[] = {
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400687 {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000688 .name = "davinci-mcasp.0",
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400689 .playback = {
690 .channels_min = 2,
Michal Bachraty2952b272013-02-28 16:07:08 +0100691 .channels_max = 32 * 16,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400692 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400693 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400694 },
695 .capture = {
696 .channels_min = 2,
Michal Bachraty2952b272013-02-28 16:07:08 +0100697 .channels_max = 32 * 16,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400698 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400699 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400700 },
701 .ops = &davinci_mcasp_dai_ops,
702
703 },
704 {
Peter Ujfalusi58e48d92013-11-14 11:35:24 +0200705 .name = "davinci-mcasp.1",
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400706 .playback = {
707 .channels_min = 1,
708 .channels_max = 384,
709 .rates = DAVINCI_MCASP_RATES,
Ben Gardiner0a9d1382011-08-26 12:02:44 -0400710 .formats = DAVINCI_MCASP_PCM_FMTS,
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400711 },
712 .ops = &davinci_mcasp_dai_ops,
713 },
714
715};
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400716
Kuninori Morimotoeeef0ed2013-03-21 03:31:19 -0700717static const struct snd_soc_component_driver davinci_mcasp_component = {
718 .name = "davinci-mcasp",
719};
720
Jyri Sarha256ba182013-10-18 18:37:42 +0300721/* Some HW specific values and defaults. The rest is filled in from DT. */
722static struct snd_platform_data dm646x_mcasp_pdata = {
723 .tx_dma_offset = 0x400,
724 .rx_dma_offset = 0x400,
725 .asp_chan_q = EVENTQ_0,
726 .version = MCASP_VERSION_1,
727};
728
729static struct snd_platform_data da830_mcasp_pdata = {
730 .tx_dma_offset = 0x2000,
731 .rx_dma_offset = 0x2000,
732 .asp_chan_q = EVENTQ_0,
733 .version = MCASP_VERSION_2,
734};
735
736static struct snd_platform_data omap2_mcasp_pdata = {
737 .tx_dma_offset = 0,
738 .rx_dma_offset = 0,
739 .asp_chan_q = EVENTQ_0,
740 .version = MCASP_VERSION_3,
741};
742
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530743static const struct of_device_id mcasp_dt_ids[] = {
744 {
745 .compatible = "ti,dm646x-mcasp-audio",
Jyri Sarha256ba182013-10-18 18:37:42 +0300746 .data = &dm646x_mcasp_pdata,
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530747 },
748 {
749 .compatible = "ti,da830-mcasp-audio",
Jyri Sarha256ba182013-10-18 18:37:42 +0300750 .data = &da830_mcasp_pdata,
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530751 },
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530752 {
Jyri Sarha3af9e032013-10-18 18:37:44 +0300753 .compatible = "ti,am33xx-mcasp-audio",
Jyri Sarha256ba182013-10-18 18:37:42 +0300754 .data = &omap2_mcasp_pdata,
Hebbar, Gururajae5ec69d2012-09-03 13:40:40 +0530755 },
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530756 { /* sentinel */ }
757};
758MODULE_DEVICE_TABLE(of, mcasp_dt_ids);
759
760static struct snd_platform_data *davinci_mcasp_set_pdata_from_of(
761 struct platform_device *pdev)
762{
763 struct device_node *np = pdev->dev.of_node;
764 struct snd_platform_data *pdata = NULL;
765 const struct of_device_id *match =
Sachin Kamatea421eb2013-05-22 16:53:37 +0530766 of_match_device(mcasp_dt_ids, &pdev->dev);
Jyri Sarha4023fe62013-10-18 18:37:43 +0300767 struct of_phandle_args dma_spec;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530768
769 const u32 *of_serial_dir32;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530770 u32 val;
771 int i, ret = 0;
772
773 if (pdev->dev.platform_data) {
774 pdata = pdev->dev.platform_data;
775 return pdata;
776 } else if (match) {
Jyri Sarha256ba182013-10-18 18:37:42 +0300777 pdata = (struct snd_platform_data *) match->data;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530778 } else {
779 /* control shouldn't reach here. something is wrong */
780 ret = -EINVAL;
781 goto nodata;
782 }
783
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530784 ret = of_property_read_u32(np, "op-mode", &val);
785 if (ret >= 0)
786 pdata->op_mode = val;
787
788 ret = of_property_read_u32(np, "tdm-slots", &val);
Michal Bachraty2952b272013-02-28 16:07:08 +0100789 if (ret >= 0) {
790 if (val < 2 || val > 32) {
791 dev_err(&pdev->dev,
792 "tdm-slots must be in rage [2-32]\n");
793 ret = -EINVAL;
794 goto nodata;
795 }
796
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530797 pdata->tdm_slots = val;
Michal Bachraty2952b272013-02-28 16:07:08 +0100798 }
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530799
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530800 of_serial_dir32 = of_get_property(np, "serial-dir", &val);
801 val /= sizeof(u32);
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530802 if (of_serial_dir32) {
Peter Ujfalusi1427e662013-10-18 18:37:46 +0300803 u8 *of_serial_dir = devm_kzalloc(&pdev->dev,
804 (sizeof(*of_serial_dir) * val),
805 GFP_KERNEL);
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530806 if (!of_serial_dir) {
807 ret = -ENOMEM;
808 goto nodata;
809 }
810
Peter Ujfalusi1427e662013-10-18 18:37:46 +0300811 for (i = 0; i < val; i++)
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530812 of_serial_dir[i] = be32_to_cpup(&of_serial_dir32[i]);
813
Peter Ujfalusi1427e662013-10-18 18:37:46 +0300814 pdata->num_serializer = val;
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530815 pdata->serial_dir = of_serial_dir;
816 }
817
Jyri Sarha4023fe62013-10-18 18:37:43 +0300818 ret = of_property_match_string(np, "dma-names", "tx");
819 if (ret < 0)
820 goto nodata;
821
822 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
823 &dma_spec);
824 if (ret < 0)
825 goto nodata;
826
827 pdata->tx_dma_channel = dma_spec.args[0];
828
829 ret = of_property_match_string(np, "dma-names", "rx");
830 if (ret < 0)
831 goto nodata;
832
833 ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret,
834 &dma_spec);
835 if (ret < 0)
836 goto nodata;
837
838 pdata->rx_dma_channel = dma_spec.args[0];
839
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530840 ret = of_property_read_u32(np, "tx-num-evt", &val);
841 if (ret >= 0)
842 pdata->txnumevt = val;
843
844 ret = of_property_read_u32(np, "rx-num-evt", &val);
845 if (ret >= 0)
846 pdata->rxnumevt = val;
847
848 ret = of_property_read_u32(np, "sram-size-playback", &val);
849 if (ret >= 0)
850 pdata->sram_size_playback = val;
851
852 ret = of_property_read_u32(np, "sram-size-capture", &val);
853 if (ret >= 0)
854 pdata->sram_size_capture = val;
855
856 return pdata;
857
858nodata:
859 if (ret < 0) {
860 dev_err(&pdev->dev, "Error populating platform data, err %d\n",
861 ret);
862 pdata = NULL;
863 }
864 return pdata;
865}
866
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400867static int davinci_mcasp_probe(struct platform_device *pdev)
868{
869 struct davinci_pcm_dma_params *dma_data;
Jyri Sarha256ba182013-10-18 18:37:42 +0300870 struct resource *mem, *ioarea, *res, *dat;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400871 struct snd_platform_data *pdata;
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200872 struct davinci_mcasp *mcasp;
Julia Lawall96d31e22011-12-29 17:51:21 +0100873 int ret;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400874
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530875 if (!pdev->dev.platform_data && !pdev->dev.of_node) {
876 dev_err(&pdev->dev, "No platform data supplied\n");
877 return -EINVAL;
878 }
879
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200880 mcasp = devm_kzalloc(&pdev->dev, sizeof(struct davinci_mcasp),
Julia Lawall96d31e22011-12-29 17:51:21 +0100881 GFP_KERNEL);
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200882 if (!mcasp)
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400883 return -ENOMEM;
884
Hebbar, Gururaja3e3b8c32012-08-27 18:56:42 +0530885 pdata = davinci_mcasp_set_pdata_from_of(pdev);
886 if (!pdata) {
887 dev_err(&pdev->dev, "no platform data\n");
888 return -EINVAL;
889 }
890
Jyri Sarha256ba182013-10-18 18:37:42 +0300891 mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400892 if (!mem) {
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200893 dev_warn(mcasp->dev,
Jyri Sarha256ba182013-10-18 18:37:42 +0300894 "\"mpu\" mem resource not found, using index 0\n");
895 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
896 if (!mem) {
897 dev_err(&pdev->dev, "no mem resource?\n");
898 return -ENODEV;
899 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400900 }
901
Julia Lawall96d31e22011-12-29 17:51:21 +0100902 ioarea = devm_request_mem_region(&pdev->dev, mem->start,
Vaibhav Bediad852f4462011-02-09 18:39:52 +0530903 resource_size(mem), pdev->name);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400904 if (!ioarea) {
905 dev_err(&pdev->dev, "Audio region already claimed\n");
Julia Lawall96d31e22011-12-29 17:51:21 +0100906 return -EBUSY;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400907 }
908
Hebbar, Gururaja10884342012-08-08 20:40:32 +0530909 pm_runtime_enable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400910
Hebbar, Gururaja10884342012-08-08 20:40:32 +0530911 ret = pm_runtime_get_sync(&pdev->dev);
912 if (IS_ERR_VALUE(ret)) {
913 dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n");
914 return ret;
915 }
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400916
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200917 mcasp->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
918 if (!mcasp->base) {
Vaibhav Bedia4f82f022011-02-09 18:39:54 +0530919 dev_err(&pdev->dev, "ioremap failed\n");
920 ret = -ENOMEM;
921 goto err_release_clk;
922 }
923
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200924 mcasp->op_mode = pdata->op_mode;
925 mcasp->tdm_slots = pdata->tdm_slots;
926 mcasp->num_serializer = pdata->num_serializer;
927 mcasp->serial_dir = pdata->serial_dir;
928 mcasp->version = pdata->version;
929 mcasp->txnumevt = pdata->txnumevt;
930 mcasp->rxnumevt = pdata->rxnumevt;
Peter Ujfalusi487dce82013-11-14 11:35:31 +0200931 if (mcasp->version < MCASP_VERSION_3)
932 mcasp->fifo_base = DAVINCI_MCASP_V2_AFIFO_BASE;
933 else
934 mcasp->fifo_base = DAVINCI_MCASP_V3_AFIFO_BASE;
935
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200936 mcasp->dev = &pdev->dev;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400937
Jyri Sarha256ba182013-10-18 18:37:42 +0300938 dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat");
939 if (!dat)
940 dat = mem;
941
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200942 dma_data = &mcasp->dma_params[SNDRV_PCM_STREAM_PLAYBACK];
Sekhar Nori48519f02010-07-19 12:31:16 +0530943 dma_data->asp_chan_q = pdata->asp_chan_q;
944 dma_data->ram_chan_q = pdata->ram_chan_q;
Matt Porterb8ec56d2012-10-17 16:08:03 +0200945 dma_data->sram_pool = pdata->sram_pool;
Ben Gardinera0c83262011-05-18 09:27:45 -0400946 dma_data->sram_size = pdata->sram_size_playback;
Jyri Sarha256ba182013-10-18 18:37:42 +0300947 dma_data->dma_addr = dat->start + pdata->tx_dma_offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400948
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400949 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
Jyri Sarha4023fe62013-10-18 18:37:43 +0300950 if (res)
951 dma_data->channel = res->start;
952 else
953 dma_data->channel = pdata->tx_dma_channel;
Troy Kisky92e2a6f2009-09-11 14:29:03 -0700954
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200955 dma_data = &mcasp->dma_params[SNDRV_PCM_STREAM_CAPTURE];
Sekhar Nori48519f02010-07-19 12:31:16 +0530956 dma_data->asp_chan_q = pdata->asp_chan_q;
957 dma_data->ram_chan_q = pdata->ram_chan_q;
Matt Porterb8ec56d2012-10-17 16:08:03 +0200958 dma_data->sram_pool = pdata->sram_pool;
Ben Gardinera0c83262011-05-18 09:27:45 -0400959 dma_data->sram_size = pdata->sram_size_capture;
Jyri Sarha256ba182013-10-18 18:37:42 +0300960 dma_data->dma_addr = dat->start + pdata->rx_dma_offset;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400961
962 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
Jyri Sarha4023fe62013-10-18 18:37:43 +0300963 if (res)
964 dma_data->channel = res->start;
965 else
966 dma_data->channel = pdata->rx_dma_channel;
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400967
Peter Ujfalusi70091a32013-11-14 11:35:29 +0200968 dev_set_drvdata(&pdev->dev, mcasp);
Kuninori Morimotoeeef0ed2013-03-21 03:31:19 -0700969 ret = snd_soc_register_component(&pdev->dev, &davinci_mcasp_component,
970 &davinci_mcasp_dai[pdata->op_mode], 1);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400971
972 if (ret != 0)
Julia Lawall96d31e22011-12-29 17:51:21 +0100973 goto err_release_clk;
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530974
975 ret = davinci_soc_platform_register(&pdev->dev);
976 if (ret) {
977 dev_err(&pdev->dev, "register PCM failed: %d\n", ret);
Kuninori Morimotoeeef0ed2013-03-21 03:31:19 -0700978 goto err_unregister_component;
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530979 }
980
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400981 return 0;
982
Kuninori Morimotoeeef0ed2013-03-21 03:31:19 -0700983err_unregister_component:
984 snd_soc_unregister_component(&pdev->dev);
Vaibhav Bediaeef6d7b2011-02-09 18:39:53 +0530985err_release_clk:
Hebbar, Gururaja10884342012-08-08 20:40:32 +0530986 pm_runtime_put_sync(&pdev->dev);
987 pm_runtime_disable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400988 return ret;
989}
990
991static int davinci_mcasp_remove(struct platform_device *pdev)
992{
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400993
Kuninori Morimotoeeef0ed2013-03-21 03:31:19 -0700994 snd_soc_unregister_component(&pdev->dev);
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530995 davinci_soc_platform_unregister(&pdev->dev);
Hebbar, Gururaja10884342012-08-08 20:40:32 +0530996
997 pm_runtime_put_sync(&pdev->dev);
998 pm_runtime_disable(&pdev->dev);
Chaithrika U Sb67f4482009-06-05 06:28:40 -0400999
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001000 return 0;
1001}
1002
Daniel Macka85e4192013-10-01 14:50:02 +02001003#ifdef CONFIG_PM_SLEEP
1004static int davinci_mcasp_suspend(struct device *dev)
1005{
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001006 struct davinci_mcasp *mcasp = dev_get_drvdata(dev);
1007 void __iomem *base = mcasp->base;
Daniel Macka85e4192013-10-01 14:50:02 +02001008
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001009 mcasp->context.txfmtctl = mcasp_get_reg(base + DAVINCI_MCASP_TXFMCTL_REG);
1010 mcasp->context.rxfmtctl = mcasp_get_reg(base + DAVINCI_MCASP_RXFMCTL_REG);
1011 mcasp->context.txfmt = mcasp_get_reg(base + DAVINCI_MCASP_TXFMT_REG);
1012 mcasp->context.rxfmt = mcasp_get_reg(base + DAVINCI_MCASP_RXFMT_REG);
1013 mcasp->context.aclkxctl = mcasp_get_reg(base + DAVINCI_MCASP_ACLKXCTL_REG);
1014 mcasp->context.aclkrctl = mcasp_get_reg(base + DAVINCI_MCASP_ACLKRCTL_REG);
1015 mcasp->context.pdir = mcasp_get_reg(base + DAVINCI_MCASP_PDIR_REG);
Daniel Macka85e4192013-10-01 14:50:02 +02001016
1017 return 0;
1018}
1019
1020static int davinci_mcasp_resume(struct device *dev)
1021{
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001022 struct davinci_mcasp *mcasp = dev_get_drvdata(dev);
1023 void __iomem *base = mcasp->base;
Daniel Macka85e4192013-10-01 14:50:02 +02001024
Peter Ujfalusi70091a32013-11-14 11:35:29 +02001025 mcasp_set_reg(base + DAVINCI_MCASP_TXFMCTL_REG, mcasp->context.txfmtctl);
1026 mcasp_set_reg(base + DAVINCI_MCASP_RXFMCTL_REG, mcasp->context.rxfmtctl);
1027 mcasp_set_reg(base + DAVINCI_MCASP_TXFMT_REG, mcasp->context.txfmt);
1028 mcasp_set_reg(base + DAVINCI_MCASP_RXFMT_REG, mcasp->context.rxfmt);
1029 mcasp_set_reg(base + DAVINCI_MCASP_ACLKXCTL_REG, mcasp->context.aclkxctl);
1030 mcasp_set_reg(base + DAVINCI_MCASP_ACLKRCTL_REG, mcasp->context.aclkrctl);
1031 mcasp_set_reg(base + DAVINCI_MCASP_PDIR_REG, mcasp->context.pdir);
Daniel Macka85e4192013-10-01 14:50:02 +02001032
1033 return 0;
1034}
1035#endif
1036
1037SIMPLE_DEV_PM_OPS(davinci_mcasp_pm_ops,
1038 davinci_mcasp_suspend,
1039 davinci_mcasp_resume);
1040
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001041static struct platform_driver davinci_mcasp_driver = {
1042 .probe = davinci_mcasp_probe,
1043 .remove = davinci_mcasp_remove,
1044 .driver = {
1045 .name = "davinci-mcasp",
1046 .owner = THIS_MODULE,
Daniel Macka85e4192013-10-01 14:50:02 +02001047 .pm = &davinci_mcasp_pm_ops,
Sachin Kamatea421eb2013-05-22 16:53:37 +05301048 .of_match_table = mcasp_dt_ids,
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001049 },
1050};
1051
Axel Linf9b8a512011-11-25 10:09:27 +08001052module_platform_driver(davinci_mcasp_driver);
Chaithrika U Sb67f4482009-06-05 06:28:40 -04001053
1054MODULE_AUTHOR("Steve Chen");
1055MODULE_DESCRIPTION("TI DAVINCI McASP SoC Interface");
1056MODULE_LICENSE("GPL");