The Renesas RZ/T2H (R9A09G077) and RZ/N2H (R9A09G087) SoCs use a
completely different ICU unit compared to RZ/V2H, which requires a
separate implementation.
To prepare for adding support for these SoCs, add a chip-specific
structure and put a pointer to the rzv2h_icu_register_dma_req() function
in the .register_dma_req field of the chip-specific structure to allow
for other implementations. Do the same for the default request value,
RZV2H_ICU_DMAC_REQ_NO_DEFAULT.
While at it, factor out the logic that calls .register_dma_req() or
rz_dmac_set_dmars_register() into a separate function to remove some
code duplication. Since the default values are different between the
two, use -1 for designating that the default value should be used.
Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
---
V2:
* remove notes
drivers/dma/sh/rz-dmac.c | 68 +++++++++++++++++++++++-----------------
1 file changed, 39 insertions(+), 29 deletions(-)
diff --git a/drivers/dma/sh/rz-dmac.c b/drivers/dma/sh/rz-dmac.c
index 20a5c1766a58..f94be3f8e232 100644
--- a/drivers/dma/sh/rz-dmac.c
+++ b/drivers/dma/sh/rz-dmac.c
@@ -95,9 +95,16 @@ struct rz_dmac_icu {
u8 dmac_index;
};
+struct rz_dmac_info {
+ void (*register_dma_req)(struct platform_device *icu_dev, u8 dmac_index,
+ u8 dmac_channel, u16 req_no);
+ u16 dma_req_no_default;
+};
+
struct rz_dmac {
struct dma_device engine;
struct rz_dmac_icu icu;
+ const struct rz_dmac_info *info;
struct device *dev;
struct reset_control *rstc;
void __iomem *base;
@@ -106,8 +113,6 @@ struct rz_dmac {
unsigned int n_channels;
struct rz_dmac_chan *channels;
- bool has_icu;
-
DECLARE_BITMAP(modules, 1024);
};
@@ -319,6 +324,19 @@ static void rz_dmac_set_dmars_register(struct rz_dmac *dmac, int nr, u32 dmars)
rz_dmac_ext_writel(dmac, dmars32, dmars_offset);
}
+static void rz_dmac_set_dma_req_no(struct rz_dmac *dmac, unsigned int index,
+ int req_no)
+{
+ if (req_no < 0)
+ req_no = dmac->info->dma_req_no_default;
+
+ if (dmac->info->register_dma_req)
+ dmac->info->register_dma_req(dmac->icu.pdev, dmac->icu.dmac_index,
+ index, req_no);
+ else
+ rz_dmac_set_dmars_register(dmac, index, req_no);
+}
+
static void rz_dmac_prepare_desc_for_memcpy(struct rz_dmac_chan *channel)
{
struct dma_chan *chan = &channel->vc.chan;
@@ -336,13 +354,7 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_dmac_chan *channel)
lmdesc->chext = 0;
lmdesc->header = HEADER_LV;
- if (dmac->has_icu) {
- rzv2h_icu_register_dma_req(dmac->icu.pdev, dmac->icu.dmac_index,
- channel->index,
- RZV2H_ICU_DMAC_REQ_NO_DEFAULT);
- } else {
- rz_dmac_set_dmars_register(dmac, channel->index, 0);
- }
+ rz_dmac_set_dma_req_no(dmac, channel->index, -1);
channel->chcfg = chcfg;
channel->chctrl = CHCTRL_STG | CHCTRL_SETEN;
@@ -393,12 +405,7 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel)
channel->lmdesc.tail = lmdesc;
- if (dmac->has_icu) {
- rzv2h_icu_register_dma_req(dmac->icu.pdev, dmac->icu.dmac_index,
- channel->index, channel->mid_rid);
- } else {
- rz_dmac_set_dmars_register(dmac, channel->index, channel->mid_rid);
- }
+ rz_dmac_set_dma_req_no(dmac, channel->index, channel->mid_rid);
channel->chctrl = CHCTRL_SETEN;
}
@@ -671,13 +678,7 @@ static void rz_dmac_device_synchronize(struct dma_chan *chan)
if (ret < 0)
dev_warn(dmac->dev, "DMA Timeout");
- if (dmac->has_icu) {
- rzv2h_icu_register_dma_req(dmac->icu.pdev, dmac->icu.dmac_index,
- channel->index,
- RZV2H_ICU_DMAC_REQ_NO_DEFAULT);
- } else {
- rz_dmac_set_dmars_register(dmac, channel->index, 0);
- }
+ rz_dmac_set_dma_req_no(dmac, channel->index, -1);
}
/*
@@ -868,14 +869,13 @@ static int rz_dmac_parse_of_icu(struct device *dev, struct rz_dmac *dmac)
uint32_t dmac_index;
int ret;
- ret = of_parse_phandle_with_fixed_args(np, "renesas,icu", 1, 0, &args);
- if (ret == -ENOENT)
+ if (!dmac->info->register_dma_req)
return 0;
+
+ ret = of_parse_phandle_with_fixed_args(np, "renesas,icu", 1, 0, &args);
if (ret)
return ret;
- dmac->has_icu = true;
-
dmac->icu.pdev = of_find_device_by_node(args.np);
of_node_put(args.np);
if (!dmac->icu.pdev) {
@@ -930,6 +930,7 @@ static int rz_dmac_probe(struct platform_device *pdev)
if (!dmac)
return -ENOMEM;
+ dmac->info = device_get_match_data(&pdev->dev);
dmac->dev = &pdev->dev;
platform_set_drvdata(pdev, dmac);
@@ -947,7 +948,7 @@ static int rz_dmac_probe(struct platform_device *pdev)
if (IS_ERR(dmac->base))
return PTR_ERR(dmac->base);
- if (!dmac->has_icu) {
+ if (!dmac->info->register_dma_req) {
dmac->ext_base = devm_platform_ioremap_resource(pdev, 1);
if (IS_ERR(dmac->ext_base))
return PTR_ERR(dmac->ext_base);
@@ -1067,9 +1068,18 @@ static void rz_dmac_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
}
+static const struct rz_dmac_info rz_dmac_v2h_info = {
+ .register_dma_req = rzv2h_icu_register_dma_req,
+ .dma_req_no_default = RZV2H_ICU_DMAC_REQ_NO_DEFAULT,
+};
+
+static const struct rz_dmac_info rz_dmac_common_info = {
+ .dma_req_no_default = 0,
+};
+
static const struct of_device_id of_rz_dmac_match[] = {
- { .compatible = "renesas,r9a09g057-dmac", },
- { .compatible = "renesas,rz-dmac", },
+ { .compatible = "renesas,r9a09g057-dmac", .data = &rz_dmac_v2h_info },
+ { .compatible = "renesas,rz-dmac", .data = &rz_dmac_common_info },
{ /* Sentinel */ }
};
MODULE_DEVICE_TABLE(of, of_rz_dmac_match);
--
2.52.0
Hi Cosmin,
On Mon, 1 Dec 2025 at 13:52, Cosmin Tanislav
<cosmin-gabriel.tanislav.xa@renesas.com> wrote:
> The Renesas RZ/T2H (R9A09G077) and RZ/N2H (R9A09G087) SoCs use a
> completely different ICU unit compared to RZ/V2H, which requires a
> separate implementation.
>
> To prepare for adding support for these SoCs, add a chip-specific
> structure and put a pointer to the rzv2h_icu_register_dma_req() function
> in the .register_dma_req field of the chip-specific structure to allow
> for other implementations. Do the same for the default request value,
> RZV2H_ICU_DMAC_REQ_NO_DEFAULT.
>
> While at it, factor out the logic that calls .register_dma_req() or
> rz_dmac_set_dmars_register() into a separate function to remove some
> code duplication. Since the default values are different between the
> two, use -1 for designating that the default value should be used.
>
> Signed-off-by: Cosmin Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
Thanks for your patch!
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
You can find a few non-functional nits below...
> --- a/drivers/dma/sh/rz-dmac.c
> +++ b/drivers/dma/sh/rz-dmac.c
> @@ -95,9 +95,16 @@ struct rz_dmac_icu {
> u8 dmac_index;
> };
>
> +struct rz_dmac_info {
> + void (*register_dma_req)(struct platform_device *icu_dev, u8 dmac_index,
> + u8 dmac_channel, u16 req_no);
icu_register_dma_req, to make clear this is ICU-specific?
> + u16 dma_req_no_default;
default_dma_req_no, to avoid confusion between literal "no" and an
abbreviation of "number"?
> +};
> +
> @@ -1067,9 +1068,18 @@ static void rz_dmac_remove(struct platform_device *pdev)
> pm_runtime_disable(&pdev->dev);
> }
>
> +static const struct rz_dmac_info rz_dmac_v2h_info = {
> + .register_dma_req = rzv2h_icu_register_dma_req,
> + .dma_req_no_default = RZV2H_ICU_DMAC_REQ_NO_DEFAULT,
Since this is the only remaining user of RZV2H_ICU_DMAC_REQ_NO_DEFAULT,
and this structure does specify hardware, perhaps just hardcode 0x3ff?
> +};
> +
> +static const struct rz_dmac_info rz_dmac_common_info = {
rz_dmac_classic_info, as this is not really common to all variants?
I am open for a different name ;-)
> + .dma_req_no_default = 0,
> +};
> +
> static const struct of_device_id of_rz_dmac_match[] = {
> - { .compatible = "renesas,r9a09g057-dmac", },
> - { .compatible = "renesas,rz-dmac", },
> + { .compatible = "renesas,r9a09g057-dmac", .data = &rz_dmac_v2h_info },
> + { .compatible = "renesas,rz-dmac", .data = &rz_dmac_common_info },
> { /* Sentinel */ }
> };
> MODULE_DEVICE_TABLE(of, of_rz_dmac_match);
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
© 2016 - 2026 Red Hat, Inc.