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 void rsnd_dmapp_bset(struct rsnd_dma
*dma
, u32 data
, u32 mask
, u32 reg
)
459 struct rsnd_mod
*mod
= rsnd_mod_get(dma
);
460 struct rsnd_priv
*priv
= rsnd_mod_to_priv(mod
);
461 struct rsnd_dma_ctrl
*dmac
= rsnd_priv_to_dmac(priv
);
462 void __iomem
*addr
= rsnd_dmapp_addr(dmac
, dma
, reg
);
463 u32 val
= ioread32(addr
);
466 val
|= (data
& mask
);
468 iowrite32(val
, addr
);
471 static int rsnd_dmapp_stop(struct rsnd_mod
*mod
,
472 struct rsnd_dai_stream
*io
,
473 struct rsnd_priv
*priv
)
475 struct rsnd_dma
*dma
= rsnd_mod_to_dma(mod
);
478 rsnd_dmapp_bset(dma
, 0, PDMACHCR_DE
, PDMACHCR
);
480 for (i
= 0; i
< 1024; i
++) {
481 if (0 == (rsnd_dmapp_read(dma
, PDMACHCR
) & PDMACHCR_DE
))
489 static int rsnd_dmapp_start(struct rsnd_mod
*mod
,
490 struct rsnd_dai_stream
*io
,
491 struct rsnd_priv
*priv
)
493 struct rsnd_dma
*dma
= rsnd_mod_to_dma(mod
);
494 struct rsnd_dmapp
*dmapp
= rsnd_dma_to_dmapp(dma
);
496 rsnd_dmapp_write(dma
, dma
->src_addr
, PDMASAR
);
497 rsnd_dmapp_write(dma
, dma
->dst_addr
, PDMADAR
);
498 rsnd_dmapp_write(dma
, dmapp
->chcr
, PDMACHCR
);
503 static int rsnd_dmapp_attach(struct rsnd_dai_stream
*io
,
504 struct rsnd_dma
*dma
,
505 struct rsnd_mod
*mod_from
, struct rsnd_mod
*mod_to
)
507 struct rsnd_dmapp
*dmapp
= rsnd_dma_to_dmapp(dma
);
508 struct rsnd_priv
*priv
= rsnd_io_to_priv(io
);
509 struct rsnd_dma_ctrl
*dmac
= rsnd_priv_to_dmac(priv
);
510 struct device
*dev
= rsnd_priv_to_dev(priv
);
512 dmapp
->dmapp_id
= dmac
->dmapp_num
;
513 dmapp
->chcr
= rsnd_dmapp_get_chcr(io
, mod_from
, mod_to
) | PDMACHCR_DE
;
517 dev_dbg(dev
, "id/src/dst/chcr = %d/%pad/%pad/%08x\n",
518 dmapp
->dmapp_id
, &dma
->src_addr
, &dma
->dst_addr
, dmapp
->chcr
);
523 static struct rsnd_mod_ops rsnd_dmapp_ops
= {
525 .start
= rsnd_dmapp_start
,
526 .stop
= rsnd_dmapp_stop
,
527 .quit
= rsnd_dmapp_stop
,
531 * Common DMAC Interface
535 * DMA read/write register offset
537 * RSND_xxx_I_N for Audio DMAC input
538 * RSND_xxx_O_N for Audio DMAC output
539 * RSND_xxx_I_P for Audio DMAC peri peri input
540 * RSND_xxx_O_P for Audio DMAC peri peri output
543 * mod / DMAC in / DMAC out / DMAC PP in / DMAC pp out
544 * SSI : 0xec541000 / 0xec241008 / 0xec24100c
545 * SSIU: 0xec541000 / 0xec100000 / 0xec100000 / 0xec400000 / 0xec400000
546 * SCU : 0xec500000 / 0xec000000 / 0xec004000 / 0xec300000 / 0xec304000
547 * CMD : 0xec500000 / / 0xec008000 0xec308000
549 #define RDMA_SSI_I_N(addr, i) (addr ##_reg - 0x00300000 + (0x40 * i) + 0x8)
550 #define RDMA_SSI_O_N(addr, i) (addr ##_reg - 0x00300000 + (0x40 * i) + 0xc)
552 #define RDMA_SSIU_I_N(addr, i) (addr ##_reg - 0x00441000 + (0x1000 * i))
553 #define RDMA_SSIU_O_N(addr, i) (addr ##_reg - 0x00441000 + (0x1000 * i))
555 #define RDMA_SSIU_I_P(addr, i) (addr ##_reg - 0x00141000 + (0x1000 * i))
556 #define RDMA_SSIU_O_P(addr, i) (addr ##_reg - 0x00141000 + (0x1000 * i))
558 #define RDMA_SRC_I_N(addr, i) (addr ##_reg - 0x00500000 + (0x400 * i))
559 #define RDMA_SRC_O_N(addr, i) (addr ##_reg - 0x004fc000 + (0x400 * i))
561 #define RDMA_SRC_I_P(addr, i) (addr ##_reg - 0x00200000 + (0x400 * i))
562 #define RDMA_SRC_O_P(addr, i) (addr ##_reg - 0x001fc000 + (0x400 * i))
564 #define RDMA_CMD_O_N(addr, i) (addr ##_reg - 0x004f8000 + (0x400 * i))
565 #define RDMA_CMD_O_P(addr, i) (addr ##_reg - 0x001f8000 + (0x400 * i))
568 rsnd_gen2_dma_addr(struct rsnd_dai_stream
*io
,
569 struct rsnd_mod
*mod
,
570 int is_play
, int is_from
)
572 struct rsnd_priv
*priv
= rsnd_io_to_priv(io
);
573 struct device
*dev
= rsnd_priv_to_dev(priv
);
574 phys_addr_t ssi_reg
= rsnd_gen_get_phy_addr(priv
, RSND_GEN2_SSI
);
575 phys_addr_t src_reg
= rsnd_gen_get_phy_addr(priv
, RSND_GEN2_SCU
);
576 int is_ssi
= !!(rsnd_io_to_mod_ssi(io
) == mod
);
577 int use_src
= !!rsnd_io_to_mod_src(io
);
578 int use_cmd
= !!rsnd_io_to_mod_dvc(io
) ||
579 !!rsnd_io_to_mod_mix(io
) ||
580 !!rsnd_io_to_mod_ctu(io
);
581 int id
= rsnd_mod_id(mod
);
585 } dma_addrs
[3][2][3] = {
589 { RDMA_SRC_O_N(src
, id
), RDMA_SRC_I_P(src
, id
) },
590 { RDMA_CMD_O_N(src
, id
), RDMA_SRC_I_P(src
, id
) } },
593 { RDMA_SRC_O_P(src
, id
), RDMA_SRC_I_N(src
, id
) },
594 { RDMA_CMD_O_P(src
, id
), RDMA_SRC_I_N(src
, id
) } }
598 {{{ RDMA_SSI_O_N(ssi
, id
), 0 },
599 { RDMA_SSIU_O_P(ssi
, id
), 0 },
600 { RDMA_SSIU_O_P(ssi
, id
), 0 } },
602 {{ 0, RDMA_SSI_I_N(ssi
, id
) },
603 { 0, RDMA_SSIU_I_P(ssi
, id
) },
604 { 0, RDMA_SSIU_I_P(ssi
, id
) } }
608 {{{ RDMA_SSIU_O_N(ssi
, id
), 0 },
609 { RDMA_SSIU_O_P(ssi
, id
), 0 },
610 { RDMA_SSIU_O_P(ssi
, id
), 0 } },
612 {{ 0, RDMA_SSIU_I_N(ssi
, id
) },
613 { 0, RDMA_SSIU_I_P(ssi
, id
) },
614 { 0, RDMA_SSIU_I_P(ssi
, id
) } } },
617 /* it shouldn't happen */
618 if (use_cmd
&& !use_src
)
619 dev_err(dev
, "DVC is selected without SRC\n");
621 /* use SSIU or SSI ? */
622 if (is_ssi
&& rsnd_ssi_use_busif(io
))
626 dma_addrs
[is_ssi
][is_play
][use_src
+ use_cmd
].out_addr
:
627 dma_addrs
[is_ssi
][is_play
][use_src
+ use_cmd
].in_addr
;
630 static dma_addr_t
rsnd_dma_addr(struct rsnd_dai_stream
*io
,
631 struct rsnd_mod
*mod
,
632 int is_play
, int is_from
)
634 struct rsnd_priv
*priv
= rsnd_io_to_priv(io
);
637 * gen1 uses default DMA addr
639 if (rsnd_is_gen1(priv
))
645 return rsnd_gen2_dma_addr(io
, mod
, is_play
, is_from
);
648 #define MOD_MAX (RSND_MOD_MAX + 1) /* +Memory */
649 static void rsnd_dma_of_path(struct rsnd_mod
*this,
650 struct rsnd_dai_stream
*io
,
652 struct rsnd_mod
**mod_from
,
653 struct rsnd_mod
**mod_to
)
655 struct rsnd_mod
*ssi
= rsnd_io_to_mod_ssi(io
);
656 struct rsnd_mod
*src
= rsnd_io_to_mod_src(io
);
657 struct rsnd_mod
*ctu
= rsnd_io_to_mod_ctu(io
);
658 struct rsnd_mod
*mix
= rsnd_io_to_mod_mix(io
);
659 struct rsnd_mod
*dvc
= rsnd_io_to_mod_dvc(io
);
660 struct rsnd_mod
*mod
[MOD_MAX
];
661 struct rsnd_mod
*mod_start
, *mod_end
;
662 struct rsnd_priv
*priv
= rsnd_mod_to_priv(this);
663 struct device
*dev
= rsnd_priv_to_dev(priv
);
670 for (i
= 0; i
< MOD_MAX
; i
++) {
672 nr
+= !!rsnd_io_to_mod(io
, i
);
677 * [S] -*-> SRC -o-> [E]
678 * [S] -*-> SRC -> DVC -o-> [E]
679 * [S] -*-> SRC -> CTU -> MIX -> DVC -o-> [E]
688 * -o-> Audio DMAC peri peri
690 mod_start
= (is_play
) ? NULL
: ssi
;
691 mod_end
= (is_play
) ? ssi
: NULL
;
694 mod
[idx
++] = mod_start
;
695 for (i
= 1; i
< nr
; i
++) {
714 * -------------+-----+-----+
718 if ((this == ssi
) == (is_play
)) {
719 *mod_from
= mod
[idx
- 1];
726 dev_dbg(dev
, "module connection (this is %s[%d])\n",
727 rsnd_mod_name(this), rsnd_mod_id(this));
728 for (i
= 0; i
<= idx
; i
++) {
729 dev_dbg(dev
, " %s[%d]%s\n",
730 rsnd_mod_name(mod
[i
]), rsnd_mod_id(mod
[i
]),
731 (mod
[i
] == *mod_from
) ? " from" :
732 (mod
[i
] == *mod_to
) ? " to" : "");
736 int rsnd_dma_attach(struct rsnd_dai_stream
*io
, struct rsnd_mod
*mod
,
737 struct rsnd_mod
**dma_mod
)
739 struct rsnd_mod
*mod_from
= NULL
;
740 struct rsnd_mod
*mod_to
= NULL
;
741 struct rsnd_priv
*priv
= rsnd_io_to_priv(io
);
742 struct rsnd_dma_ctrl
*dmac
= rsnd_priv_to_dmac(priv
);
743 struct device
*dev
= rsnd_priv_to_dev(priv
);
744 struct rsnd_mod_ops
*ops
;
745 enum rsnd_mod_type type
;
746 int (*attach
)(struct rsnd_dai_stream
*io
, struct rsnd_dma
*dma
,
747 struct rsnd_mod
*mod_from
, struct rsnd_mod
*mod_to
);
748 int is_play
= rsnd_io_is_play(io
);
752 * DMA failed. try to PIO mode
754 * rsnd_ssi_fallback()
755 * rsnd_rdai_continuance_probe()
760 rsnd_dma_of_path(mod
, io
, is_play
, &mod_from
, &mod_to
);
763 if (mod_from
&& mod_to
) {
764 ops
= &rsnd_dmapp_ops
;
765 attach
= rsnd_dmapp_attach
;
766 dma_id
= dmac
->dmapp_num
;
767 type
= RSND_MOD_AUDMAPP
;
769 ops
= &rsnd_dmaen_ops
;
770 attach
= rsnd_dmaen_attach
;
771 dma_id
= dmac
->dmaen_num
;
772 type
= RSND_MOD_AUDMA
;
775 /* for Gen1, overwrite */
776 if (rsnd_is_gen1(priv
)) {
777 ops
= &rsnd_dmaen_ops
;
778 attach
= rsnd_dmaen_attach
;
779 dma_id
= dmac
->dmaen_num
;
780 type
= RSND_MOD_AUDMA
;
784 struct rsnd_dma
*dma
;
786 dma
= devm_kzalloc(dev
, sizeof(*dma
), GFP_KERNEL
);
790 *dma_mod
= rsnd_mod_get(dma
);
792 ret
= rsnd_mod_init(priv
, *dma_mod
, ops
, NULL
,
793 rsnd_mod_get_status
, type
, dma_id
);
797 dev_dbg(dev
, "%s[%d] %s[%d] -> %s[%d]\n",
798 rsnd_mod_name(*dma_mod
), rsnd_mod_id(*dma_mod
),
799 rsnd_mod_name(mod_from
), rsnd_mod_id(mod_from
),
800 rsnd_mod_name(mod_to
), rsnd_mod_id(mod_to
));
802 ret
= attach(io
, dma
, mod_from
, mod_to
);
806 dma
->src_addr
= rsnd_dma_addr(io
, mod_from
, is_play
, 1);
807 dma
->dst_addr
= rsnd_dma_addr(io
, mod_to
, is_play
, 0);
808 dma
->mod_from
= mod_from
;
809 dma
->mod_to
= mod_to
;
812 ret
= rsnd_dai_connect(*dma_mod
, io
, type
);
819 int rsnd_dma_probe(struct rsnd_priv
*priv
)
821 struct platform_device
*pdev
= rsnd_priv_to_pdev(priv
);
822 struct device
*dev
= rsnd_priv_to_dev(priv
);
823 struct rsnd_dma_ctrl
*dmac
;
824 struct resource
*res
;
829 if (rsnd_is_gen1(priv
))
835 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "audmapp");
836 dmac
= devm_kzalloc(dev
, sizeof(*dmac
), GFP_KERNEL
);
838 dev_err(dev
, "dma allocate failed\n");
839 return 0; /* it will be PIO mode */
843 dmac
->base
= devm_ioremap_resource(dev
, res
);
844 if (IS_ERR(dmac
->base
))
845 return PTR_ERR(dmac
->base
);