Skip to content

Commit e870c10

Browse files
John Madieubroonie
authored andcommitted
ASoC: rsnd: Refactor DMA address tables with named structs
Replace the raw multi-dimensional array used for DMA address lookup in rsnd_gen2_dma_addr() with properly named structs: rsnd_dma_addr (in/out pair), rsnd_dma_addr_dir (capture/playback arrays), and rsnd_dma_addr_map (src/ssi/ssiu module sets). While at it, extract the common lookup logic (is_ssi / use_src / use_cmd evaluation and table indexing) into a shared rsnd_dma_addr_lookup() function. No functional change. This is a preparatory refactor for upcoming RZ/G3E support which will add its own DMA address map using the same struct and lookup function. Signed-off-by: John Madieu <john.madieu.xa@bp.renesas.com> Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Link: https://patch.msgid.link/20260525110230.4014435-8-john.madieu.xa@bp.renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent fb859f6 commit e870c10

1 file changed

Lines changed: 99 additions & 48 deletions

File tree

  • sound/soc/renesas/rcar

sound/soc/renesas/rcar/dma.c

Lines changed: 99 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,69 @@ static struct rsnd_mod_ops rsnd_dmapp_ops = {
481481
DEBUG_INFO
482482
};
483483

484+
struct rsnd_dma_addr {
485+
dma_addr_t out_addr;
486+
dma_addr_t in_addr;
487+
};
488+
489+
struct rsnd_dma_addr_dir {
490+
struct rsnd_dma_addr capture[3];
491+
struct rsnd_dma_addr playback[3];
492+
};
493+
494+
struct rsnd_dma_addr_map {
495+
struct rsnd_dma_addr_dir src;
496+
struct rsnd_dma_addr_dir ssi;
497+
struct rsnd_dma_addr_dir ssiu;
498+
};
499+
500+
static dma_addr_t
501+
rsnd_dma_addr_lookup(struct rsnd_dai_stream *io,
502+
struct rsnd_mod *mod,
503+
struct rsnd_priv *priv,
504+
const struct rsnd_dma_addr_map *map,
505+
int is_play, int is_from)
506+
{
507+
struct device *dev = rsnd_priv_to_dev(priv);
508+
int is_ssi = !!(rsnd_io_to_mod_ssi(io) == mod) ||
509+
!!(rsnd_io_to_mod_ssiu(io) == mod);
510+
int use_src = !!rsnd_io_to_mod_src(io);
511+
int use_cmd = !!rsnd_io_to_mod_dvc(io) ||
512+
!!rsnd_io_to_mod_mix(io) ||
513+
!!rsnd_io_to_mod_ctu(io);
514+
int id = rsnd_mod_id(mod);
515+
const struct rsnd_dma_addr_dir *dir;
516+
const struct rsnd_dma_addr *addr;
517+
518+
/* it shouldn't happen */
519+
if (use_cmd && !use_src)
520+
dev_err(dev, "DVC is selected without SRC\n");
521+
522+
/* use SSIU or SSI? */
523+
if (is_ssi && rsnd_ssi_use_busif(io))
524+
is_ssi++;
525+
526+
dev_dbg(dev, "dma%d addr : is_ssi=%d use_src=%d use_cmd=%d\n",
527+
id, is_ssi, use_src, use_cmd);
528+
529+
switch (is_ssi) {
530+
case 2:
531+
dir = &map->ssiu;
532+
break;
533+
case 1:
534+
dir = &map->ssi;
535+
break;
536+
default:
537+
dir = &map->src;
538+
break;
539+
}
540+
541+
addr = is_play ? &dir->playback[use_src + use_cmd]
542+
: &dir->capture[use_src + use_cmd];
543+
544+
return is_from ? addr->out_addr : addr->in_addr;
545+
}
546+
484547
/*
485548
* Common DMAC Interface
486549
*/
@@ -527,47 +590,45 @@ rsnd_gen2_dma_addr(struct rsnd_dai_stream *io,
527590
struct device *dev = rsnd_priv_to_dev(priv);
528591
phys_addr_t ssi_reg = rsnd_gen_get_phy_addr(priv, RSND_BASE_SSI);
529592
phys_addr_t src_reg = rsnd_gen_get_phy_addr(priv, RSND_BASE_SCU);
530-
int is_ssi = !!(rsnd_io_to_mod_ssi(io) == mod) ||
531-
!!(rsnd_io_to_mod_ssiu(io) == mod);
532-
int use_src = !!rsnd_io_to_mod_src(io);
533-
int use_cmd = !!rsnd_io_to_mod_dvc(io) ||
534-
!!rsnd_io_to_mod_mix(io) ||
535-
!!rsnd_io_to_mod_ctu(io);
536593
int id = rsnd_mod_id(mod);
537594
int busif = rsnd_mod_id_sub(rsnd_io_to_mod_ssiu(io));
538-
struct dma_addr {
539-
dma_addr_t out_addr;
540-
dma_addr_t in_addr;
541-
} dma_addrs[3][2][3] = {
542-
/* SRC */
543-
/* Capture */
544-
{{{ 0, 0 },
545-
{ RDMA_SRC_O_N(src, id), RDMA_SRC_I_P(src, id) },
546-
{ RDMA_CMD_O_N(src, id), RDMA_SRC_I_P(src, id) } },
547-
/* Playback */
548-
{{ 0, 0, },
549-
{ RDMA_SRC_O_P(src, id), RDMA_SRC_I_N(src, id) },
550-
{ RDMA_CMD_O_P(src, id), RDMA_SRC_I_N(src, id) } }
595+
const struct rsnd_dma_addr_map map = {
596+
.src = {
597+
.capture = {
598+
{ 0, 0 },
599+
{ RDMA_SRC_O_N(src, id), RDMA_SRC_I_P(src, id) },
600+
{ RDMA_CMD_O_N(src, id), RDMA_SRC_I_P(src, id) },
601+
},
602+
.playback = {
603+
{ 0, 0 },
604+
{ RDMA_SRC_O_P(src, id), RDMA_SRC_I_N(src, id) },
605+
{ RDMA_CMD_O_P(src, id), RDMA_SRC_I_N(src, id) },
606+
},
607+
},
608+
.ssi = {
609+
.capture = {
610+
{ RDMA_SSI_O_N(ssi, id), 0 },
611+
{ RDMA_SSIU_O_P(ssi, id, busif), 0 },
612+
{ RDMA_SSIU_O_P(ssi, id, busif), 0 },
613+
},
614+
.playback = {
615+
{ 0, RDMA_SSI_I_N(ssi, id) },
616+
{ 0, RDMA_SSIU_I_P(ssi, id, busif) },
617+
{ 0, RDMA_SSIU_I_P(ssi, id, busif) },
618+
},
551619
},
552-
/* SSI */
553-
/* Capture */
554-
{{{ RDMA_SSI_O_N(ssi, id), 0 },
555-
{ RDMA_SSIU_O_P(ssi, id, busif), 0 },
556-
{ RDMA_SSIU_O_P(ssi, id, busif), 0 } },
557-
/* Playback */
558-
{{ 0, RDMA_SSI_I_N(ssi, id) },
559-
{ 0, RDMA_SSIU_I_P(ssi, id, busif) },
560-
{ 0, RDMA_SSIU_I_P(ssi, id, busif) } }
620+
.ssiu = {
621+
.capture = {
622+
{ RDMA_SSIU_O_N(ssi, id, busif), 0 },
623+
{ RDMA_SSIU_O_P(ssi, id, busif), 0 },
624+
{ RDMA_SSIU_O_P(ssi, id, busif), 0 },
625+
},
626+
.playback = {
627+
{ 0, RDMA_SSIU_I_N(ssi, id, busif) },
628+
{ 0, RDMA_SSIU_I_P(ssi, id, busif) },
629+
{ 0, RDMA_SSIU_I_P(ssi, id, busif) },
630+
},
561631
},
562-
/* SSIU */
563-
/* Capture */
564-
{{{ RDMA_SSIU_O_N(ssi, id, busif), 0 },
565-
{ RDMA_SSIU_O_P(ssi, id, busif), 0 },
566-
{ RDMA_SSIU_O_P(ssi, id, busif), 0 } },
567-
/* Playback */
568-
{{ 0, RDMA_SSIU_I_N(ssi, id, busif) },
569-
{ 0, RDMA_SSIU_I_P(ssi, id, busif) },
570-
{ 0, RDMA_SSIU_I_P(ssi, id, busif) } } },
571632
};
572633

573634
/*
@@ -580,17 +641,7 @@ rsnd_gen2_dma_addr(struct rsnd_dai_stream *io,
580641
dev_err(dev, "This driver doesn't support SSI%d-%d, so far",
581642
id, busif);
582643

583-
/* it shouldn't happen */
584-
if (use_cmd && !use_src)
585-
dev_err(dev, "DVC is selected without SRC\n");
586-
587-
/* use SSIU or SSI ? */
588-
if (is_ssi && rsnd_ssi_use_busif(io))
589-
is_ssi++;
590-
591-
return (is_from) ?
592-
dma_addrs[is_ssi][is_play][use_src + use_cmd].out_addr :
593-
dma_addrs[is_ssi][is_play][use_src + use_cmd].in_addr;
644+
return rsnd_dma_addr_lookup(io, mod, priv, &map, is_play, is_from);
594645
}
595646

596647
/*

0 commit comments

Comments
 (0)