bdd99f582bb1f87e9718850088b87d3bc4b11eda
[linux-drm-fsl-dcu.git] / sound / soc / sh / rcar / dma.c
1 /*
2  * Renesas R-Car Audio DMAC support
3  *
4  * Copyright (C) 2015 Renesas Electronics Corp.
5  * Copyright (c) 2015 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11 #include <linux/delay.h>
12 #include <linux/of_dma.h>
13 #include "rsnd.h"
14
15 /*
16  * Audio DMAC peri peri register
17  */
18 #define PDMASAR         0x00
19 #define PDMADAR         0x04
20 #define PDMACHCR        0x0c
21
22 /* PDMACHCR */
23 #define PDMACHCR_DE             (1 << 0)
24
25 struct rsnd_dma_ctrl {
26         void __iomem *base;
27         int dmapp_num;
28 };
29
30 #define rsnd_priv_to_dmac(p)    ((struct rsnd_dma_ctrl *)(p)->dma)
31
32 /*
33  *              Audio DMAC
34  */
35 static void __rsnd_dmaen_complete(struct rsnd_mod *mod,
36                                   struct rsnd_dai_stream *io)
37 {
38         struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
39         bool elapsed = false;
40         unsigned long flags;
41
42         /*
43          * Renesas sound Gen1 needs 1 DMAC,
44          * Gen2 needs 2 DMAC.
45          * In Gen2 case, it are Audio-DMAC, and Audio-DMAC-peri-peri.
46          * But, Audio-DMAC-peri-peri doesn't have interrupt,
47          * and this driver is assuming that here.
48          *
49          * If Audio-DMAC-peri-peri has interrpt,
50          * rsnd_dai_pointer_update() will be called twice,
51          * ant it will breaks io->byte_pos
52          */
53         spin_lock_irqsave(&priv->lock, flags);
54
55         if (rsnd_mod_is_working(mod))
56                 elapsed = rsnd_dai_pointer_update(io, io->byte_per_period);
57
58         spin_unlock_irqrestore(&priv->lock, flags);
59
60         if (elapsed)
61                 rsnd_dai_period_elapsed(io);
62 }
63
64 static void rsnd_dmaen_complete(void *data)
65 {
66         struct rsnd_mod *mod = data;
67
68         rsnd_mod_interrupt(mod, __rsnd_dmaen_complete);
69 }
70
71 static void rsnd_dmaen_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
72 {
73         struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
74
75         dmaengine_terminate_all(dmaen->chan);
76 }
77
78 static void rsnd_dmaen_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
79 {
80         struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
81         struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
82         struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
83         struct snd_pcm_substream *substream = io->substream;
84         struct device *dev = rsnd_priv_to_dev(priv);
85         struct dma_async_tx_descriptor *desc;
86         int is_play = rsnd_io_is_play(io);
87
88         desc = dmaengine_prep_dma_cyclic(dmaen->chan,
89                                          substream->runtime->dma_addr,
90                                          snd_pcm_lib_buffer_bytes(substream),
91                                          snd_pcm_lib_period_bytes(substream),
92                                          is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM,
93                                          DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
94
95         if (!desc) {
96                 dev_err(dev, "dmaengine_prep_slave_sg() fail\n");
97                 return;
98         }
99
100         desc->callback          = rsnd_dmaen_complete;
101         desc->callback_param    = mod;
102
103         if (dmaengine_submit(desc) < 0) {
104                 dev_err(dev, "dmaengine_submit() fail\n");
105                 return;
106         }
107
108         dma_async_issue_pending(dmaen->chan);
109 }
110
111 struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node,
112                                           struct rsnd_mod *mod, char *name)
113 {
114         struct dma_chan *chan;
115         struct device_node *np;
116         int i = 0;
117
118         for_each_child_of_node(of_node, np) {
119                 if (i == rsnd_mod_id(mod))
120                         break;
121                 i++;
122         }
123
124         chan = of_dma_request_slave_channel(np, name);
125
126         of_node_put(np);
127         of_node_put(of_node);
128
129         return chan;
130 }
131
132 static struct dma_chan *rsnd_dmaen_request_channel(struct rsnd_dai_stream *io,
133                                                    struct rsnd_mod *mod_from,
134                                                    struct rsnd_mod *mod_to)
135 {
136         if ((!mod_from && !mod_to) ||
137             (mod_from && mod_to))
138                 return NULL;
139
140         if (mod_from)
141                 return rsnd_mod_dma_req(io, mod_from);
142         else
143                 return rsnd_mod_dma_req(io, mod_to);
144 }
145
146 static int rsnd_dmaen_init(struct rsnd_dai_stream *io,
147                            struct rsnd_dma *dma, int id,
148                            struct rsnd_mod *mod_from, struct rsnd_mod *mod_to)
149 {
150         struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
151         struct rsnd_priv *priv = rsnd_io_to_priv(io);
152         struct device *dev = rsnd_priv_to_dev(priv);
153         struct dma_slave_config cfg = {};
154         int is_play = rsnd_io_is_play(io);
155         int ret;
156
157         if (dmaen->chan) {
158                 dev_err(dev, "it already has dma channel\n");
159                 return -EIO;
160         }
161
162         if (dev->of_node) {
163                 dmaen->chan = rsnd_dmaen_request_channel(io, mod_from, mod_to);
164         } else {
165                 dma_cap_mask_t mask;
166
167                 dma_cap_zero(mask);
168                 dma_cap_set(DMA_SLAVE, mask);
169
170                 dmaen->chan = dma_request_channel(mask, shdma_chan_filter,
171                                                   (void *)id);
172         }
173         if (IS_ERR_OR_NULL(dmaen->chan)) {
174                 dev_err(dev, "can't get dma channel\n");
175                 goto rsnd_dma_channel_err;
176         }
177
178         cfg.direction   = is_play ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM;
179         cfg.src_addr    = dma->src_addr;
180         cfg.dst_addr    = dma->dst_addr;
181         cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
182         cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
183
184         dev_dbg(dev, "dma : %pad -> %pad\n",
185                 &cfg.src_addr, &cfg.dst_addr);
186
187         ret = dmaengine_slave_config(dmaen->chan, &cfg);
188         if (ret < 0)
189                 goto rsnd_dma_init_err;
190
191         return 0;
192
193 rsnd_dma_init_err:
194         rsnd_dma_quit(io, dma);
195 rsnd_dma_channel_err:
196
197         /*
198          * DMA failed. try to PIO mode
199          * see
200          *      rsnd_ssi_fallback()
201          *      rsnd_rdai_continuance_probe()
202          */
203         return -EAGAIN;
204 }
205
206 static void rsnd_dmaen_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
207 {
208         struct rsnd_dmaen *dmaen = rsnd_dma_to_dmaen(dma);
209
210         if (dmaen->chan)
211                 dma_release_channel(dmaen->chan);
212
213         dmaen->chan = NULL;
214 }
215
216 static struct rsnd_dma_ops rsnd_dmaen_ops = {
217         .start  = rsnd_dmaen_start,
218         .stop   = rsnd_dmaen_stop,
219         .init   = rsnd_dmaen_init,
220         .quit   = rsnd_dmaen_quit,
221 };
222
223 /*
224  *              Audio DMAC peri peri
225  */
226 static const u8 gen2_id_table_ssiu[] = {
227         0x00, /* SSI00 */
228         0x04, /* SSI10 */
229         0x08, /* SSI20 */
230         0x0c, /* SSI3  */
231         0x0d, /* SSI4  */
232         0x0e, /* SSI5  */
233         0x0f, /* SSI6  */
234         0x10, /* SSI7  */
235         0x11, /* SSI8  */
236         0x12, /* SSI90 */
237 };
238 static const u8 gen2_id_table_scu[] = {
239         0x2d, /* SCU_SRCI0 */
240         0x2e, /* SCU_SRCI1 */
241         0x2f, /* SCU_SRCI2 */
242         0x30, /* SCU_SRCI3 */
243         0x31, /* SCU_SRCI4 */
244         0x32, /* SCU_SRCI5 */
245         0x33, /* SCU_SRCI6 */
246         0x34, /* SCU_SRCI7 */
247         0x35, /* SCU_SRCI8 */
248         0x36, /* SCU_SRCI9 */
249 };
250 static const u8 gen2_id_table_cmd[] = {
251         0x37, /* SCU_CMD0 */
252         0x38, /* SCU_CMD1 */
253 };
254
255 static u32 rsnd_dmapp_get_id(struct rsnd_dai_stream *io,
256                              struct rsnd_mod *mod)
257 {
258         struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io);
259         struct rsnd_mod *src = rsnd_io_to_mod_src(io);
260         struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
261         const u8 *entry = NULL;
262         int id = rsnd_mod_id(mod);
263         int size = 0;
264
265         if (mod == ssi) {
266                 entry = gen2_id_table_ssiu;
267                 size = ARRAY_SIZE(gen2_id_table_ssiu);
268         } else if (mod == src) {
269                 entry = gen2_id_table_scu;
270                 size = ARRAY_SIZE(gen2_id_table_scu);
271         } else if (mod == dvc) {
272                 entry = gen2_id_table_cmd;
273                 size = ARRAY_SIZE(gen2_id_table_cmd);
274         }
275
276         if (!entry)
277                 return 0xFF;
278
279         if (size <= id)
280                 return 0xFF;
281
282         return entry[id];
283 }
284
285 static u32 rsnd_dmapp_get_chcr(struct rsnd_dai_stream *io,
286                                struct rsnd_mod *mod_from,
287                                struct rsnd_mod *mod_to)
288 {
289         return  (rsnd_dmapp_get_id(io, mod_from) << 24) +
290                 (rsnd_dmapp_get_id(io, mod_to) << 16);
291 }
292
293 #define rsnd_dmapp_addr(dmac, dma, reg) \
294         (dmac->base + 0x20 + reg + \
295          (0x10 * rsnd_dma_to_dmapp(dma)->dmapp_id))
296 static void rsnd_dmapp_write(struct rsnd_dma *dma, u32 data, u32 reg)
297 {
298         struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
299         struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
300         struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
301         struct device *dev = rsnd_priv_to_dev(priv);
302
303         dev_dbg(dev, "w %p : %08x\n", rsnd_dmapp_addr(dmac, dma, reg), data);
304
305         iowrite32(data, rsnd_dmapp_addr(dmac, dma, reg));
306 }
307
308 static u32 rsnd_dmapp_read(struct rsnd_dma *dma, u32 reg)
309 {
310         struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
311         struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
312         struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
313
314         return ioread32(rsnd_dmapp_addr(dmac, dma, reg));
315 }
316
317 static void rsnd_dmapp_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
318 {
319         int i;
320
321         rsnd_dmapp_write(dma, 0, PDMACHCR);
322
323         for (i = 0; i < 1024; i++) {
324                 if (0 == rsnd_dmapp_read(dma, PDMACHCR))
325                         return;
326                 udelay(1);
327         }
328 }
329
330 static void rsnd_dmapp_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
331 {
332         struct rsnd_dmapp *dmapp = rsnd_dma_to_dmapp(dma);
333
334         rsnd_dmapp_write(dma, dma->src_addr,    PDMASAR);
335         rsnd_dmapp_write(dma, dma->dst_addr,    PDMADAR);
336         rsnd_dmapp_write(dma, dmapp->chcr,      PDMACHCR);
337 }
338
339 static int rsnd_dmapp_init(struct rsnd_dai_stream *io,
340                            struct rsnd_dma *dma, int id,
341                            struct rsnd_mod *mod_from, struct rsnd_mod *mod_to)
342 {
343         struct rsnd_dmapp *dmapp = rsnd_dma_to_dmapp(dma);
344         struct rsnd_priv *priv = rsnd_io_to_priv(io);
345         struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
346         struct device *dev = rsnd_priv_to_dev(priv);
347
348         dmapp->dmapp_id = dmac->dmapp_num;
349         dmapp->chcr = rsnd_dmapp_get_chcr(io, mod_from, mod_to) | PDMACHCR_DE;
350
351         dmac->dmapp_num++;
352
353         rsnd_dmapp_stop(io, dma);
354
355         dev_dbg(dev, "id/src/dst/chcr = %d/%pad/%pad/%08x\n",
356                 dmapp->dmapp_id, &dma->src_addr, &dma->dst_addr, dmapp->chcr);
357
358         return 0;
359 }
360
361 static struct rsnd_dma_ops rsnd_dmapp_ops = {
362         .start  = rsnd_dmapp_start,
363         .stop   = rsnd_dmapp_stop,
364         .init   = rsnd_dmapp_init,
365         .quit   = rsnd_dmapp_stop,
366 };
367
368 /*
369  *              Common DMAC Interface
370  */
371
372 /*
373  *      DMA read/write register offset
374  *
375  *      RSND_xxx_I_N    for Audio DMAC input
376  *      RSND_xxx_O_N    for Audio DMAC output
377  *      RSND_xxx_I_P    for Audio DMAC peri peri input
378  *      RSND_xxx_O_P    for Audio DMAC peri peri output
379  *
380  *      ex) R-Car H2 case
381  *            mod        / DMAC in    / DMAC out   / DMAC PP in / DMAC pp out
382  *      SSI : 0xec541000 / 0xec241008 / 0xec24100c
383  *      SSIU: 0xec541000 / 0xec100000 / 0xec100000 / 0xec400000 / 0xec400000
384  *      SCU : 0xec500000 / 0xec000000 / 0xec004000 / 0xec300000 / 0xec304000
385  *      CMD : 0xec500000 /            / 0xec008000                0xec308000
386  */
387 #define RDMA_SSI_I_N(addr, i)   (addr ##_reg - 0x00300000 + (0x40 * i) + 0x8)
388 #define RDMA_SSI_O_N(addr, i)   (addr ##_reg - 0x00300000 + (0x40 * i) + 0xc)
389
390 #define RDMA_SSIU_I_N(addr, i)  (addr ##_reg - 0x00441000 + (0x1000 * i))
391 #define RDMA_SSIU_O_N(addr, i)  (addr ##_reg - 0x00441000 + (0x1000 * i))
392
393 #define RDMA_SSIU_I_P(addr, i)  (addr ##_reg - 0x00141000 + (0x1000 * i))
394 #define RDMA_SSIU_O_P(addr, i)  (addr ##_reg - 0x00141000 + (0x1000 * i))
395
396 #define RDMA_SRC_I_N(addr, i)   (addr ##_reg - 0x00500000 + (0x400 * i))
397 #define RDMA_SRC_O_N(addr, i)   (addr ##_reg - 0x004fc000 + (0x400 * i))
398
399 #define RDMA_SRC_I_P(addr, i)   (addr ##_reg - 0x00200000 + (0x400 * i))
400 #define RDMA_SRC_O_P(addr, i)   (addr ##_reg - 0x001fc000 + (0x400 * i))
401
402 #define RDMA_CMD_O_N(addr, i)   (addr ##_reg - 0x004f8000 + (0x400 * i))
403 #define RDMA_CMD_O_P(addr, i)   (addr ##_reg - 0x001f8000 + (0x400 * i))
404
405 static dma_addr_t
406 rsnd_gen2_dma_addr(struct rsnd_dai_stream *io,
407                    struct rsnd_mod *mod,
408                    int is_play, int is_from)
409 {
410         struct rsnd_priv *priv = rsnd_io_to_priv(io);
411         struct device *dev = rsnd_priv_to_dev(priv);
412         phys_addr_t ssi_reg = rsnd_gen_get_phy_addr(priv, RSND_GEN2_SSI);
413         phys_addr_t src_reg = rsnd_gen_get_phy_addr(priv, RSND_GEN2_SCU);
414         int is_ssi = !!(rsnd_io_to_mod_ssi(io) == mod);
415         int use_src = !!rsnd_io_to_mod_src(io);
416         int use_dvc = !!rsnd_io_to_mod_dvc(io);
417         int id = rsnd_mod_id(mod);
418         struct dma_addr {
419                 dma_addr_t out_addr;
420                 dma_addr_t in_addr;
421         } dma_addrs[3][2][3] = {
422                 /* SRC */
423                 {{{ 0,                          0 },
424                   /* Capture */
425                   { RDMA_SRC_O_N(src, id),      RDMA_SRC_I_P(src, id) },
426                   { RDMA_CMD_O_N(src, id),      RDMA_SRC_I_P(src, id) } },
427                  /* Playback */
428                  {{ 0,                          0, },
429                   { RDMA_SRC_O_P(src, id),      RDMA_SRC_I_N(src, id) },
430                   { RDMA_CMD_O_P(src, id),      RDMA_SRC_I_N(src, id) } }
431                 },
432                 /* SSI */
433                 /* Capture */
434                 {{{ RDMA_SSI_O_N(ssi, id),      0 },
435                   { RDMA_SSIU_O_P(ssi, id),     0 },
436                   { RDMA_SSIU_O_P(ssi, id),     0 } },
437                  /* Playback */
438                  {{ 0,                          RDMA_SSI_I_N(ssi, id) },
439                   { 0,                          RDMA_SSIU_I_P(ssi, id) },
440                   { 0,                          RDMA_SSIU_I_P(ssi, id) } }
441                 },
442                 /* SSIU */
443                 /* Capture */
444                 {{{ RDMA_SSIU_O_N(ssi, id),     0 },
445                   { RDMA_SSIU_O_P(ssi, id),     0 },
446                   { RDMA_SSIU_O_P(ssi, id),     0 } },
447                  /* Playback */
448                  {{ 0,                          RDMA_SSIU_I_N(ssi, id) },
449                   { 0,                          RDMA_SSIU_I_P(ssi, id) },
450                   { 0,                          RDMA_SSIU_I_P(ssi, id) } } },
451         };
452
453         /* it shouldn't happen */
454         if (use_dvc && !use_src)
455                 dev_err(dev, "DVC is selected without SRC\n");
456
457         /* use SSIU or SSI ? */
458         if (is_ssi && rsnd_ssi_use_busif(mod))
459                 is_ssi++;
460
461         return (is_from) ?
462                 dma_addrs[is_ssi][is_play][use_src + use_dvc].out_addr :
463                 dma_addrs[is_ssi][is_play][use_src + use_dvc].in_addr;
464 }
465
466 static dma_addr_t rsnd_dma_addr(struct rsnd_dai_stream *io,
467                                 struct rsnd_mod *mod,
468                                 int is_play, int is_from)
469 {
470         struct rsnd_priv *priv = rsnd_io_to_priv(io);
471
472         /*
473          * gen1 uses default DMA addr
474          */
475         if (rsnd_is_gen1(priv))
476                 return 0;
477
478         if (!mod)
479                 return 0;
480
481         return rsnd_gen2_dma_addr(io, mod, is_play, is_from);
482 }
483
484 #define MOD_MAX 4 /* MEM/SSI/SRC/DVC */
485 static void rsnd_dma_of_path(struct rsnd_dma *dma,
486                              struct rsnd_dai_stream *io,
487                              int is_play,
488                              struct rsnd_mod **mod_from,
489                              struct rsnd_mod **mod_to)
490 {
491         struct rsnd_mod *this = rsnd_dma_to_mod(dma);
492         struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io);
493         struct rsnd_mod *src = rsnd_io_to_mod_src(io);
494         struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
495         struct rsnd_mod *mod[MOD_MAX];
496         int i, index;
497
498
499         for (i = 0; i < MOD_MAX; i++)
500                 mod[i] = NULL;
501
502         /*
503          * in play case...
504          *
505          * src -> dst
506          *
507          * mem -> SSI
508          * mem -> SRC -> SSI
509          * mem -> SRC -> DVC -> SSI
510          */
511         mod[0] = NULL; /* for "mem" */
512         index = 1;
513         for (i = 1; i < MOD_MAX; i++) {
514                 if (!src) {
515                         mod[i] = ssi;
516                 } else if (!dvc) {
517                         mod[i] = src;
518                         src = NULL;
519                 } else {
520                         if ((!is_play) && (this == src))
521                                 this = dvc;
522
523                         mod[i] = (is_play) ? src : dvc;
524                         i++;
525                         mod[i] = (is_play) ? dvc : src;
526                         src = NULL;
527                         dvc = NULL;
528                 }
529
530                 if (mod[i] == this)
531                         index = i;
532
533                 if (mod[i] == ssi)
534                         break;
535         }
536
537         if (is_play) {
538                 *mod_from = mod[index - 1];
539                 *mod_to   = mod[index];
540         } else {
541                 *mod_from = mod[index];
542                 *mod_to   = mod[index - 1];
543         }
544 }
545
546 void rsnd_dma_stop(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
547 {
548         dma->ops->stop(io, dma);
549 }
550
551 void rsnd_dma_start(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
552 {
553         dma->ops->start(io, dma);
554 }
555
556 void rsnd_dma_quit(struct rsnd_dai_stream *io, struct rsnd_dma *dma)
557 {
558         struct rsnd_mod *mod = rsnd_dma_to_mod(dma);
559         struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
560         struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
561
562         if (!dmac)
563                 return;
564
565         dma->ops->quit(io, dma);
566 }
567
568 int rsnd_dma_init(struct rsnd_dai_stream *io, struct rsnd_dma *dma, int id)
569 {
570         struct rsnd_mod *mod_from;
571         struct rsnd_mod *mod_to;
572         struct rsnd_priv *priv = rsnd_io_to_priv(io);
573         struct rsnd_dma_ctrl *dmac = rsnd_priv_to_dmac(priv);
574         int is_play = rsnd_io_is_play(io);
575
576         /*
577          * DMA failed. try to PIO mode
578          * see
579          *      rsnd_ssi_fallback()
580          *      rsnd_rdai_continuance_probe()
581          */
582         if (!dmac)
583                 return -EAGAIN;
584
585         rsnd_dma_of_path(dma, io, is_play, &mod_from, &mod_to);
586
587         dma->src_addr = rsnd_dma_addr(io, mod_from, is_play, 1);
588         dma->dst_addr = rsnd_dma_addr(io, mod_to,   is_play, 0);
589
590         /* for Gen2 */
591         if (mod_from && mod_to)
592                 dma->ops = &rsnd_dmapp_ops;
593         else
594                 dma->ops = &rsnd_dmaen_ops;
595
596         /* for Gen1, overwrite */
597         if (rsnd_is_gen1(priv))
598                 dma->ops = &rsnd_dmaen_ops;
599
600         return dma->ops->init(io, dma, id, mod_from, mod_to);
601 }
602
603 int rsnd_dma_probe(struct platform_device *pdev,
604                    const struct rsnd_of_data *of_data,
605                    struct rsnd_priv *priv)
606 {
607         struct device *dev = rsnd_priv_to_dev(priv);
608         struct rsnd_dma_ctrl *dmac;
609         struct resource *res;
610
611         /*
612          * for Gen1
613          */
614         if (rsnd_is_gen1(priv))
615                 return 0;
616
617         /*
618          * for Gen2
619          */
620         res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "audmapp");
621         dmac = devm_kzalloc(dev, sizeof(*dmac), GFP_KERNEL);
622         if (!dmac || !res) {
623                 dev_err(dev, "dma allocate failed\n");
624                 return 0; /* it will be PIO mode */
625         }
626
627         dmac->dmapp_num = 0;
628         dmac->base = devm_ioremap_resource(dev, res);
629         if (IS_ERR(dmac->base))
630                 return PTR_ERR(dmac->base);
631
632         priv->dma = dmac;
633
634         return 0;
635 }