2 * Renesas R-Car Audio DMAC support
4 * Copyright (C) 2015 Renesas Electronics Corp.
5 * Copyright (c) 2015 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
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.
11 #include <linux/delay.h>
12 #include <linux/of_dma.h>
16 * Audio DMAC peri peri register
23 #define PDMACHCR_DE (1 << 0)
27 struct dma_chan
*chan
;
30 unsigned int dma_period
;
41 struct rsnd_mod
*mod_from
;
42 struct rsnd_mod
*mod_to
;
51 struct rsnd_dma_ctrl
{
57 #define rsnd_priv_to_dmac(p) ((struct rsnd_dma_ctrl *)(p)->dma)
58 #define rsnd_mod_to_dma(_mod) container_of((_mod), struct rsnd_dma, mod)
59 #define rsnd_dma_to_dmaen(dma) (&(dma)->dma.en)
60 #define rsnd_dma_to_dmapp(dma) (&(dma)->dma.pp)
65 #define rsnd_dmaen_sync(dmaen, io, i) __rsnd_dmaen_sync(dmaen, io, i, 1)
66 #define rsnd_dmaen_unsync(dmaen, io, i) __rsnd_dmaen_sync(dmaen, io, i, 0)
67 static void __rsnd_dmaen_sync(struct rsnd_dmaen
*dmaen
, struct rsnd_dai_stream
*io
,
70 struct device
*dev
= dmaen
->chan
->device
->dev
;
71 enum dma_data_direction dir
;
72 int is_play
= rsnd_io_is_play(io
);
78 period
= dmaen
->dma_period
;
81 buf
= dmaen
->dma_buf
+ (period
* i
);
83 dir
= is_play
? DMA_TO_DEVICE
: DMA_FROM_DEVICE
;
86 dma_sync_single_for_device(dev
, buf
, period
, dir
);
88 dma_sync_single_for_cpu(dev
, buf
, period
, dir
);
91 static void __rsnd_dmaen_complete(struct rsnd_mod
*mod
,
92 struct rsnd_dai_stream
*io
)
94 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
95 struct rsnd_dma
*dma
= rsnd_mod_to_dma(mod
);
96 struct rsnd_dmaen
*dmaen
= rsnd_dma_to_dmaen(dma
);
101 * Renesas sound Gen1 needs 1 DMAC,
103 * In Gen2 case, it are Audio-DMAC, and Audio-DMAC-peri-peri.
104 * But, Audio-DMAC-peri-peri doesn't have interrupt,
105 * and this driver is assuming that here.
107 * If Audio-DMAC-peri-peri has interrpt,
108 * rsnd_dai_pointer_update() will be called twice,
109 * ant it will breaks io->byte_pos
111 spin_lock_irqsave(&priv
->lock
, flags
);
113 if (rsnd_io_is_working(io
)) {
114 rsnd_dmaen_unsync(dmaen
, io
, dmaen
->dma_cnt
);
117 * Next period is already started.
118 * Let's sync Next Next period
122 rsnd_dmaen_sync(dmaen
, io
, dmaen
->dma_cnt
+ 2);
124 elapsed
= rsnd_dai_pointer_update(io
, io
->byte_per_period
);
129 spin_unlock_irqrestore(&priv
->lock
, flags
);
132 rsnd_dai_period_elapsed(io
);
135 static void rsnd_dmaen_complete(void *data
)
137 struct rsnd_mod
*mod
= data
;
139 rsnd_mod_interrupt(mod
, __rsnd_dmaen_complete
);
142 static struct dma_chan
*rsnd_dmaen_request_channel(struct rsnd_dai_stream
*io
,
143 struct rsnd_mod
*mod_from
,
144 struct rsnd_mod
*mod_to
)
146 if ((!mod_from
&& !mod_to
) ||
147 (mod_from
&& mod_to
))
151 return rsnd_mod_dma_req(io
, mod_from
);
153 return rsnd_mod_dma_req(io
, mod_to
);
156 static int rsnd_dmaen_stop(struct rsnd_mod
*mod
,
157 struct rsnd_dai_stream
*io
,
158 struct rsnd_priv
*priv
)
160 struct rsnd_dma
*dma
= rsnd_mod_to_dma(mod
);
161 struct rsnd_dmaen
*dmaen
= rsnd_dma_to_dmaen(dma
);
164 int is_play
= rsnd_io_is_play(io
);
166 dmaengine_terminate_all(dmaen
->chan
);
167 dma_unmap_single(dmaen
->chan
->device
->dev
,
168 dmaen
->dma_buf
, dmaen
->dma_len
,
169 is_play
? DMA_TO_DEVICE
: DMA_FROM_DEVICE
);
175 static int rsnd_dmaen_nolock_stop(struct rsnd_mod
*mod
,
176 struct rsnd_dai_stream
*io
,
177 struct rsnd_priv
*priv
)
179 struct rsnd_dma
*dma
= rsnd_mod_to_dma(mod
);
180 struct rsnd_dmaen
*dmaen
= rsnd_dma_to_dmaen(dma
);
183 * DMAEngine release uses mutex lock.
184 * Thus, it shouldn't be called under spinlock.
185 * Let's call it under nolock_start
188 dma_release_channel(dmaen
->chan
);
195 static int rsnd_dmaen_nolock_start(struct rsnd_mod
*mod
,
196 struct rsnd_dai_stream
*io
,
197 struct rsnd_priv
*priv
)
199 struct rsnd_dma
*dma
= rsnd_mod_to_dma(mod
);
200 struct rsnd_dmaen
*dmaen
= rsnd_dma_to_dmaen(dma
);
201 struct device
*dev
= rsnd_priv_to_dev(priv
);
204 dev_err(dev
, "it already has dma channel\n");
209 * DMAEngine request uses mutex lock.
210 * Thus, it shouldn't be called under spinlock.
211 * Let's call it under nolock_start
213 dmaen
->chan
= rsnd_dmaen_request_channel(io
,
216 if (IS_ERR_OR_NULL(dmaen
->chan
)) {
217 int ret
= PTR_ERR(dmaen
->chan
);
220 dev_err(dev
, "can't get dma channel\n");
227 static int rsnd_dmaen_start(struct rsnd_mod
*mod
,
228 struct rsnd_dai_stream
*io
,
229 struct rsnd_priv
*priv
)
231 struct rsnd_dma
*dma
= rsnd_mod_to_dma(mod
);
232 struct rsnd_dmaen
*dmaen
= rsnd_dma_to_dmaen(dma
);
233 struct snd_pcm_substream
*substream
= io
->substream
;
234 struct device
*dev
= rsnd_priv_to_dev(priv
);
235 struct dma_async_tx_descriptor
*desc
;
236 struct dma_slave_config cfg
= {};
240 int is_play
= rsnd_io_is_play(io
);
244 cfg
.direction
= is_play
? DMA_MEM_TO_DEV
: DMA_DEV_TO_MEM
;
245 cfg
.src_addr
= dma
->src_addr
;
246 cfg
.dst_addr
= dma
->dst_addr
;
247 cfg
.src_addr_width
= DMA_SLAVE_BUSWIDTH_4_BYTES
;
248 cfg
.dst_addr_width
= DMA_SLAVE_BUSWIDTH_4_BYTES
;
250 dev_dbg(dev
, "%s[%d] %pad -> %pad\n",
251 rsnd_mod_name(mod
), rsnd_mod_id(mod
),
252 &cfg
.src_addr
, &cfg
.dst_addr
);
254 ret
= dmaengine_slave_config(dmaen
->chan
, &cfg
);
258 len
= snd_pcm_lib_buffer_bytes(substream
);
259 period
= snd_pcm_lib_period_bytes(substream
);
260 buf
= dma_map_single(dmaen
->chan
->device
->dev
,
261 substream
->runtime
->dma_area
,
263 is_play
? DMA_TO_DEVICE
: DMA_FROM_DEVICE
);
264 if (dma_mapping_error(dmaen
->chan
->device
->dev
, buf
)) {
265 dev_err(dev
, "dma map failed\n");
269 desc
= dmaengine_prep_dma_cyclic(dmaen
->chan
,
271 is_play
? DMA_MEM_TO_DEV
: DMA_DEV_TO_MEM
,
272 DMA_PREP_INTERRUPT
| DMA_CTRL_ACK
);
275 dev_err(dev
, "dmaengine_prep_slave_sg() fail\n");
279 desc
->callback
= rsnd_dmaen_complete
;
280 desc
->callback_param
= rsnd_mod_get(dma
);
282 dmaen
->dma_buf
= buf
;
283 dmaen
->dma_len
= len
;
284 dmaen
->dma_period
= period
;
288 * synchronize this and next period
290 * __rsnd_dmaen_complete()
292 for (i
= 0; i
< 2; i
++)
293 rsnd_dmaen_sync(dmaen
, io
, i
);
295 if (dmaengine_submit(desc
) < 0) {
296 dev_err(dev
, "dmaengine_submit() fail\n");
300 dma_async_issue_pending(dmaen
->chan
);
305 struct dma_chan
*rsnd_dma_request_channel(struct device_node
*of_node
,
306 struct rsnd_mod
*mod
, char *name
)
308 struct dma_chan
*chan
= NULL
;
309 struct device_node
*np
;
312 for_each_child_of_node(of_node
, np
) {
313 if (i
== rsnd_mod_id(mod
) && (!chan
))
314 chan
= of_dma_request_slave_channel(np
, name
);
318 /* It should call of_node_put(), since, it is rsnd_xxx_of_node() */
319 of_node_put(of_node
);
324 static int rsnd_dmaen_attach(struct rsnd_dai_stream
*io
,
325 struct rsnd_dma
*dma
,
326 struct rsnd_mod
*mod_from
, struct rsnd_mod
*mod_to
)
328 struct rsnd_priv
*priv
= rsnd_io_to_priv(io
);
329 struct rsnd_dma_ctrl
*dmac
= rsnd_priv_to_dmac(priv
);
330 struct dma_chan
*chan
;
332 /* try to get DMAEngine channel */
333 chan
= rsnd_dmaen_request_channel(io
, mod_from
, mod_to
);
334 if (IS_ERR_OR_NULL(chan
)) {
336 * DMA failed. try to PIO mode
338 * rsnd_ssi_fallback()
339 * rsnd_rdai_continuance_probe()
344 dma_release_channel(chan
);
351 static struct rsnd_mod_ops rsnd_dmaen_ops
= {
353 .nolock_start
= rsnd_dmaen_nolock_start
,
354 .nolock_stop
= rsnd_dmaen_nolock_stop
,
355 .start
= rsnd_dmaen_start
,
356 .stop
= rsnd_dmaen_stop
,
360 * Audio DMAC peri peri
362 static const u8 gen2_id_table_ssiu
[] = {
374 static const u8 gen2_id_table_scu
[] = {
375 0x2d, /* SCU_SRCI0 */
376 0x2e, /* SCU_SRCI1 */
377 0x2f, /* SCU_SRCI2 */
378 0x30, /* SCU_SRCI3 */
379 0x31, /* SCU_SRCI4 */
380 0x32, /* SCU_SRCI5 */
381 0x33, /* SCU_SRCI6 */
382 0x34, /* SCU_SRCI7 */
383 0x35, /* SCU_SRCI8 */
384 0x36, /* SCU_SRCI9 */
386 static const u8 gen2_id_table_cmd
[] = {
391 static u32
rsnd_dmapp_get_id(struct rsnd_dai_stream
*io
,
392 struct rsnd_mod
*mod
)
394 struct rsnd_mod
*ssi
= rsnd_io_to_mod_ssi(io
);
395 struct rsnd_mod
*src
= rsnd_io_to_mod_src(io
);
396 struct rsnd_mod
*dvc
= rsnd_io_to_mod_dvc(io
);
397 const u8
*entry
= NULL
;
398 int id
= rsnd_mod_id(mod
);
402 entry
= gen2_id_table_ssiu
;
403 size
= ARRAY_SIZE(gen2_id_table_ssiu
);
404 } else if (mod
== src
) {
405 entry
= gen2_id_table_scu
;
406 size
= ARRAY_SIZE(gen2_id_table_scu
);
407 } else if (mod
== dvc
) {
408 entry
= gen2_id_table_cmd
;
409 size
= ARRAY_SIZE(gen2_id_table_cmd
);
412 if ((!entry
) || (size
<= id
)) {
413 struct device
*dev
= rsnd_priv_to_dev(rsnd_io_to_priv(io
));
415 dev_err(dev
, "unknown connection (%s[%d])\n",
416 rsnd_mod_name(mod
), rsnd_mod_id(mod
));
418 /* use non-prohibited SRS number as error */
419 return 0x00; /* SSI00 */
425 static u32
rsnd_dmapp_get_chcr(struct rsnd_dai_stream
*io
,
426 struct rsnd_mod
*mod_from
,
427 struct rsnd_mod
*mod_to
)
429 return (rsnd_dmapp_get_id(io
, mod_from
) << 24) +
430 (rsnd_dmapp_get_id(io
, mod_to
) << 16);
433 #define rsnd_dmapp_addr(dmac, dma, reg) \
434 (dmac->base + 0x20 + reg + \
435 (0x10 * rsnd_dma_to_dmapp(dma)->dmapp_id))
436 static void rsnd_dmapp_write(struct rsnd_dma
*dma
, u32 data
, u32 reg
)
438 struct rsnd_mod
*mod
= rsnd_mod_get(dma
);
439 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
440 struct rsnd_dma_ctrl
*dmac
= rsnd_priv_to_dmac(priv
);
441 struct device
*dev
= rsnd_priv_to_dev(priv
);
443 dev_dbg(dev
, "w %p : %08x\n", rsnd_dmapp_addr(dmac
, dma
, reg
), data
);
445 iowrite32(data
, rsnd_dmapp_addr(dmac
, dma
, reg
));
448 static u32
rsnd_dmapp_read(struct rsnd_dma
*dma
, u32 reg
)
450 struct rsnd_mod
*mod
= rsnd_mod_get(dma
);
451 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
452 struct rsnd_dma_ctrl
*dmac
= rsnd_priv_to_dmac(priv
);
454 return ioread32(rsnd_dmapp_addr(dmac
, dma
, reg
));
457 static int rsnd_dmapp_stop(struct rsnd_mod
*mod
,
458 struct rsnd_dai_stream
*io
,
459 struct rsnd_priv
*priv
)
461 struct rsnd_dma
*dma
= rsnd_mod_to_dma(mod
);
464 rsnd_dmapp_write(dma
, 0, PDMACHCR
);
466 for (i
= 0; i
< 1024; i
++) {
467 if (0 == rsnd_dmapp_read(dma
, PDMACHCR
))
475 static int rsnd_dmapp_start(struct rsnd_mod
*mod
,
476 struct rsnd_dai_stream
*io
,
477 struct rsnd_priv
*priv
)
479 struct rsnd_dma
*dma
= rsnd_mod_to_dma(mod
);
480 struct rsnd_dmapp
*dmapp
= rsnd_dma_to_dmapp(dma
);
482 rsnd_dmapp_write(dma
, dma
->src_addr
, PDMASAR
);
483 rsnd_dmapp_write(dma
, dma
->dst_addr
, PDMADAR
);
484 rsnd_dmapp_write(dma
, dmapp
->chcr
, PDMACHCR
);
489 static int rsnd_dmapp_attach(struct rsnd_dai_stream
*io
,
490 struct rsnd_dma
*dma
,
491 struct rsnd_mod
*mod_from
, struct rsnd_mod
*mod_to
)
493 struct rsnd_dmapp
*dmapp
= rsnd_dma_to_dmapp(dma
);
494 struct rsnd_priv
*priv
= rsnd_io_to_priv(io
);
495 struct rsnd_dma_ctrl
*dmac
= rsnd_priv_to_dmac(priv
);
496 struct device
*dev
= rsnd_priv_to_dev(priv
);
498 dmapp
->dmapp_id
= dmac
->dmapp_num
;
499 dmapp
->chcr
= rsnd_dmapp_get_chcr(io
, mod_from
, mod_to
) | PDMACHCR_DE
;
503 dev_dbg(dev
, "id/src/dst/chcr = %d/%pad/%pad/%08x\n",
504 dmapp
->dmapp_id
, &dma
->src_addr
, &dma
->dst_addr
, dmapp
->chcr
);
509 static struct rsnd_mod_ops rsnd_dmapp_ops
= {
511 .start
= rsnd_dmapp_start
,
512 .stop
= rsnd_dmapp_stop
,
513 .quit
= rsnd_dmapp_stop
,
517 * Common DMAC Interface
521 * DMA read/write register offset
523 * RSND_xxx_I_N for Audio DMAC input
524 * RSND_xxx_O_N for Audio DMAC output
525 * RSND_xxx_I_P for Audio DMAC peri peri input
526 * RSND_xxx_O_P for Audio DMAC peri peri output
529 * mod / DMAC in / DMAC out / DMAC PP in / DMAC pp out
530 * SSI : 0xec541000 / 0xec241008 / 0xec24100c
531 * SSIU: 0xec541000 / 0xec100000 / 0xec100000 / 0xec400000 / 0xec400000
532 * SCU : 0xec500000 / 0xec000000 / 0xec004000 / 0xec300000 / 0xec304000
533 * CMD : 0xec500000 / / 0xec008000 0xec308000
535 #define RDMA_SSI_I_N(addr, i) (addr ##_reg - 0x00300000 + (0x40 * i) + 0x8)
536 #define RDMA_SSI_O_N(addr, i) (addr ##_reg - 0x00300000 + (0x40 * i) + 0xc)
538 #define RDMA_SSIU_I_N(addr, i) (addr ##_reg - 0x00441000 + (0x1000 * i))
539 #define RDMA_SSIU_O_N(addr, i) (addr ##_reg - 0x00441000 + (0x1000 * i))
541 #define RDMA_SSIU_I_P(addr, i) (addr ##_reg - 0x00141000 + (0x1000 * i))
542 #define RDMA_SSIU_O_P(addr, i) (addr ##_reg - 0x00141000 + (0x1000 * i))
544 #define RDMA_SRC_I_N(addr, i) (addr ##_reg - 0x00500000 + (0x400 * i))
545 #define RDMA_SRC_O_N(addr, i) (addr ##_reg - 0x004fc000 + (0x400 * i))
547 #define RDMA_SRC_I_P(addr, i) (addr ##_reg - 0x00200000 + (0x400 * i))
548 #define RDMA_SRC_O_P(addr, i) (addr ##_reg - 0x001fc000 + (0x400 * i))
550 #define RDMA_CMD_O_N(addr, i) (addr ##_reg - 0x004f8000 + (0x400 * i))
551 #define RDMA_CMD_O_P(addr, i) (addr ##_reg - 0x001f8000 + (0x400 * i))
554 rsnd_gen2_dma_addr(struct rsnd_dai_stream
*io
,
555 struct rsnd_mod
*mod
,
556 int is_play
, int is_from
)
558 struct rsnd_priv
*priv
= rsnd_io_to_priv(io
);
559 struct device
*dev
= rsnd_priv_to_dev(priv
);
560 phys_addr_t ssi_reg
= rsnd_gen_get_phy_addr(priv
, RSND_GEN2_SSI
);
561 phys_addr_t src_reg
= rsnd_gen_get_phy_addr(priv
, RSND_GEN2_SCU
);
562 int is_ssi
= !!(rsnd_io_to_mod_ssi(io
) == mod
);
563 int use_src
= !!rsnd_io_to_mod_src(io
);
564 int use_cmd
= !!rsnd_io_to_mod_dvc(io
) ||
565 !!rsnd_io_to_mod_mix(io
) ||
566 !!rsnd_io_to_mod_ctu(io
);
567 int id
= rsnd_mod_id(mod
);
571 } dma_addrs
[3][2][3] = {
575 { RDMA_SRC_O_N(src
, id
), RDMA_SRC_I_P(src
, id
) },
576 { RDMA_CMD_O_N(src
, id
), RDMA_SRC_I_P(src
, id
) } },
579 { RDMA_SRC_O_P(src
, id
), RDMA_SRC_I_N(src
, id
) },
580 { RDMA_CMD_O_P(src
, id
), RDMA_SRC_I_N(src
, id
) } }
584 {{{ RDMA_SSI_O_N(ssi
, id
), 0 },
585 { RDMA_SSIU_O_P(ssi
, id
), 0 },
586 { RDMA_SSIU_O_P(ssi
, id
), 0 } },
588 {{ 0, RDMA_SSI_I_N(ssi
, id
) },
589 { 0, RDMA_SSIU_I_P(ssi
, id
) },
590 { 0, RDMA_SSIU_I_P(ssi
, id
) } }
594 {{{ RDMA_SSIU_O_N(ssi
, id
), 0 },
595 { RDMA_SSIU_O_P(ssi
, id
), 0 },
596 { RDMA_SSIU_O_P(ssi
, id
), 0 } },
598 {{ 0, RDMA_SSIU_I_N(ssi
, id
) },
599 { 0, RDMA_SSIU_I_P(ssi
, id
) },
600 { 0, RDMA_SSIU_I_P(ssi
, id
) } } },
603 /* it shouldn't happen */
604 if (use_cmd
&& !use_src
)
605 dev_err(dev
, "DVC is selected without SRC\n");
607 /* use SSIU or SSI ? */
608 if (is_ssi
&& rsnd_ssi_use_busif(io
))
612 dma_addrs
[is_ssi
][is_play
][use_src
+ use_cmd
].out_addr
:
613 dma_addrs
[is_ssi
][is_play
][use_src
+ use_cmd
].in_addr
;
616 static dma_addr_t
rsnd_dma_addr(struct rsnd_dai_stream
*io
,
617 struct rsnd_mod
*mod
,
618 int is_play
, int is_from
)
620 struct rsnd_priv
*priv
= rsnd_io_to_priv(io
);
623 * gen1 uses default DMA addr
625 if (rsnd_is_gen1(priv
))
631 return rsnd_gen2_dma_addr(io
, mod
, is_play
, is_from
);
634 #define MOD_MAX (RSND_MOD_MAX + 1) /* +Memory */
635 static void rsnd_dma_of_path(struct rsnd_mod
*this,
636 struct rsnd_dai_stream
*io
,
638 struct rsnd_mod
**mod_from
,
639 struct rsnd_mod
**mod_to
)
641 struct rsnd_mod
*ssi
= rsnd_io_to_mod_ssi(io
);
642 struct rsnd_mod
*src
= rsnd_io_to_mod_src(io
);
643 struct rsnd_mod
*ctu
= rsnd_io_to_mod_ctu(io
);
644 struct rsnd_mod
*mix
= rsnd_io_to_mod_mix(io
);
645 struct rsnd_mod
*dvc
= rsnd_io_to_mod_dvc(io
);
646 struct rsnd_mod
*mod
[MOD_MAX
];
647 struct rsnd_mod
*mod_start
, *mod_end
;
648 struct rsnd_priv
*priv
= rsnd_mod_to_priv(this);
649 struct device
*dev
= rsnd_priv_to_dev(priv
);
656 for (i
= 0; i
< MOD_MAX
; i
++) {
658 nr
+= !!rsnd_io_to_mod(io
, i
);
663 * [S] -*-> SRC -o-> [E]
664 * [S] -*-> SRC -> DVC -o-> [E]
665 * [S] -*-> SRC -> CTU -> MIX -> DVC -o-> [E]
674 * -o-> Audio DMAC peri peri
676 mod_start
= (is_play
) ? NULL
: ssi
;
677 mod_end
= (is_play
) ? ssi
: NULL
;
680 mod
[idx
++] = mod_start
;
681 for (i
= 1; i
< nr
; i
++) {
700 * -------------+-----+-----+
704 if ((this == ssi
) == (is_play
)) {
705 *mod_from
= mod
[idx
- 1];
712 dev_dbg(dev
, "module connection (this is %s[%d])\n",
713 rsnd_mod_name(this), rsnd_mod_id(this));
714 for (i
= 0; i
<= idx
; i
++) {
715 dev_dbg(dev
, " %s[%d]%s\n",
716 rsnd_mod_name(mod
[i
]), rsnd_mod_id(mod
[i
]),
717 (mod
[i
] == *mod_from
) ? " from" :
718 (mod
[i
] == *mod_to
) ? " to" : "");
722 int rsnd_dma_attach(struct rsnd_dai_stream
*io
, struct rsnd_mod
*mod
,
723 struct rsnd_mod
**dma_mod
)
725 struct rsnd_mod
*mod_from
= NULL
;
726 struct rsnd_mod
*mod_to
= NULL
;
727 struct rsnd_priv
*priv
= rsnd_io_to_priv(io
);
728 struct rsnd_dma_ctrl
*dmac
= rsnd_priv_to_dmac(priv
);
729 struct device
*dev
= rsnd_priv_to_dev(priv
);
730 struct rsnd_mod_ops
*ops
;
731 enum rsnd_mod_type type
;
732 int (*attach
)(struct rsnd_dai_stream
*io
, struct rsnd_dma
*dma
,
733 struct rsnd_mod
*mod_from
, struct rsnd_mod
*mod_to
);
734 int is_play
= rsnd_io_is_play(io
);
738 * DMA failed. try to PIO mode
740 * rsnd_ssi_fallback()
741 * rsnd_rdai_continuance_probe()
746 rsnd_dma_of_path(mod
, io
, is_play
, &mod_from
, &mod_to
);
749 if (mod_from
&& mod_to
) {
750 ops
= &rsnd_dmapp_ops
;
751 attach
= rsnd_dmapp_attach
;
752 dma_id
= dmac
->dmapp_num
;
753 type
= RSND_MOD_AUDMAPP
;
755 ops
= &rsnd_dmaen_ops
;
756 attach
= rsnd_dmaen_attach
;
757 dma_id
= dmac
->dmaen_num
;
758 type
= RSND_MOD_AUDMA
;
761 /* for Gen1, overwrite */
762 if (rsnd_is_gen1(priv
)) {
763 ops
= &rsnd_dmaen_ops
;
764 attach
= rsnd_dmaen_attach
;
765 dma_id
= dmac
->dmaen_num
;
766 type
= RSND_MOD_AUDMA
;
770 struct rsnd_dma
*dma
;
772 dma
= devm_kzalloc(dev
, sizeof(*dma
), GFP_KERNEL
);
776 *dma_mod
= rsnd_mod_get(dma
);
778 ret
= rsnd_mod_init(priv
, *dma_mod
, ops
, NULL
,
779 rsnd_mod_get_status
, type
, dma_id
);
783 dev_dbg(dev
, "%s[%d] %s[%d] -> %s[%d]\n",
784 rsnd_mod_name(*dma_mod
), rsnd_mod_id(*dma_mod
),
785 rsnd_mod_name(mod_from
), rsnd_mod_id(mod_from
),
786 rsnd_mod_name(mod_to
), rsnd_mod_id(mod_to
));
788 ret
= attach(io
, dma
, mod_from
, mod_to
);
792 dma
->src_addr
= rsnd_dma_addr(io
, mod_from
, is_play
, 1);
793 dma
->dst_addr
= rsnd_dma_addr(io
, mod_to
, is_play
, 0);
794 dma
->mod_from
= mod_from
;
795 dma
->mod_to
= mod_to
;
798 ret
= rsnd_dai_connect(*dma_mod
, io
, type
);
805 int rsnd_dma_probe(struct rsnd_priv
*priv
)
807 struct platform_device
*pdev
= rsnd_priv_to_pdev(priv
);
808 struct device
*dev
= rsnd_priv_to_dev(priv
);
809 struct rsnd_dma_ctrl
*dmac
;
810 struct resource
*res
;
815 if (rsnd_is_gen1(priv
))
821 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "audmapp");
822 dmac
= devm_kzalloc(dev
, sizeof(*dmac
), GFP_KERNEL
);
824 dev_err(dev
, "dma allocate failed\n");
825 return 0; /* it will be PIO mode */
829 dmac
->base
= devm_ioremap_resource(dev
, res
);
830 if (IS_ERR(dmac
->base
))
831 return PTR_ERR(dmac
->base
);