Skip to content

Commit 7de8732

Browse files
Fabrizio Castrovinodkoul
authored andcommitted
dmaengine: sh: rz-dmac: Add RZ/V2H(P) support
The DMAC IP found on the Renesas RZ/V2H(P) family of SoCs is similar to the version found on the Renesas RZ/G2L family of SoCs, but there are some differences: * It only uses one register area * It only uses one clock * It only uses one reset * Instead of using MID/IRD it uses REQ No * It is connected to the Interrupt Control Unit (ICU) * On the RZ/G2L there is only 1 DMAC, on the RZ/V2H(P) there are 5 Add specific support for the Renesas RZ/V2H(P) family of SoC by tackling the aforementioned differences. Signed-off-by: Fabrizio Castro <[email protected]> Reviewed-by: Lad Prabhakar <[email protected]> Reviewed-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 056a8aa commit 7de8732

File tree

1 file changed

+74
-7
lines changed

1 file changed

+74
-7
lines changed

drivers/dma/sh/rz-dmac.c

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/dmaengine.h>
1515
#include <linux/interrupt.h>
1616
#include <linux/iopoll.h>
17+
#include <linux/irqchip/irq-renesas-rzv2h.h>
1718
#include <linux/list.h>
1819
#include <linux/module.h>
1920
#include <linux/of.h>
@@ -89,8 +90,14 @@ struct rz_dmac_chan {
8990

9091
#define to_rz_dmac_chan(c) container_of(c, struct rz_dmac_chan, vc.chan)
9192

93+
struct rz_dmac_icu {
94+
struct platform_device *pdev;
95+
u8 dmac_index;
96+
};
97+
9298
struct rz_dmac {
9399
struct dma_device engine;
100+
struct rz_dmac_icu icu;
94101
struct device *dev;
95102
struct reset_control *rstc;
96103
void __iomem *base;
@@ -99,6 +106,8 @@ struct rz_dmac {
99106
unsigned int n_channels;
100107
struct rz_dmac_chan *channels;
101108

109+
bool has_icu;
110+
102111
DECLARE_BITMAP(modules, 1024);
103112
};
104113

@@ -167,6 +176,9 @@ struct rz_dmac {
167176
#define RZ_DMAC_MAX_CHANNELS 16
168177
#define DMAC_NR_LMDESC 64
169178

179+
/* RZ/V2H ICU related */
180+
#define RZV2H_MAX_DMAC_INDEX 4
181+
170182
/*
171183
* -----------------------------------------------------------------------------
172184
* Device access
@@ -324,7 +336,13 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_dmac_chan *channel)
324336
lmdesc->chext = 0;
325337
lmdesc->header = HEADER_LV;
326338

327-
rz_dmac_set_dmars_register(dmac, channel->index, 0);
339+
if (dmac->has_icu) {
340+
rzv2h_icu_register_dma_req(dmac->icu.pdev, dmac->icu.dmac_index,
341+
channel->index,
342+
RZV2H_ICU_DMAC_REQ_NO_DEFAULT);
343+
} else {
344+
rz_dmac_set_dmars_register(dmac, channel->index, 0);
345+
}
328346

329347
channel->chcfg = chcfg;
330348
channel->chctrl = CHCTRL_STG | CHCTRL_SETEN;
@@ -375,7 +393,13 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel)
375393

376394
channel->lmdesc.tail = lmdesc;
377395

378-
rz_dmac_set_dmars_register(dmac, channel->index, channel->mid_rid);
396+
if (dmac->has_icu) {
397+
rzv2h_icu_register_dma_req(dmac->icu.pdev, dmac->icu.dmac_index,
398+
channel->index, channel->mid_rid);
399+
} else {
400+
rz_dmac_set_dmars_register(dmac, channel->index, channel->mid_rid);
401+
}
402+
379403
channel->chctrl = CHCTRL_SETEN;
380404
}
381405

@@ -647,7 +671,13 @@ static void rz_dmac_device_synchronize(struct dma_chan *chan)
647671
if (ret < 0)
648672
dev_warn(dmac->dev, "DMA Timeout");
649673

650-
rz_dmac_set_dmars_register(dmac, channel->index, 0);
674+
if (dmac->has_icu) {
675+
rzv2h_icu_register_dma_req(dmac->icu.pdev, dmac->icu.dmac_index,
676+
channel->index,
677+
RZV2H_ICU_DMAC_REQ_NO_DEFAULT);
678+
} else {
679+
rz_dmac_set_dmars_register(dmac, channel->index, 0);
680+
}
651681
}
652682

653683
/*
@@ -824,6 +854,38 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac,
824854
return 0;
825855
}
826856

857+
static int rz_dmac_parse_of_icu(struct device *dev, struct rz_dmac *dmac)
858+
{
859+
struct device_node *np = dev->of_node;
860+
struct of_phandle_args args;
861+
uint32_t dmac_index;
862+
int ret;
863+
864+
ret = of_parse_phandle_with_fixed_args(np, "renesas,icu", 1, 0, &args);
865+
if (ret == -ENOENT)
866+
return 0;
867+
if (ret)
868+
return ret;
869+
870+
dmac->has_icu = true;
871+
872+
dmac->icu.pdev = of_find_device_by_node(args.np);
873+
of_node_put(args.np);
874+
if (!dmac->icu.pdev) {
875+
dev_err(dev, "ICU device not found.\n");
876+
return -ENODEV;
877+
}
878+
879+
dmac_index = args.args[0];
880+
if (dmac_index > RZV2H_MAX_DMAC_INDEX) {
881+
dev_err(dev, "DMAC index %u invalid.\n", dmac_index);
882+
return -EINVAL;
883+
}
884+
dmac->icu.dmac_index = dmac_index;
885+
886+
return 0;
887+
}
888+
827889
static int rz_dmac_parse_of(struct device *dev, struct rz_dmac *dmac)
828890
{
829891
struct device_node *np = dev->of_node;
@@ -840,7 +902,7 @@ static int rz_dmac_parse_of(struct device *dev, struct rz_dmac *dmac)
840902
return -EINVAL;
841903
}
842904

843-
return 0;
905+
return rz_dmac_parse_of_icu(dev, dmac);
844906
}
845907

846908
static int rz_dmac_probe(struct platform_device *pdev)
@@ -874,9 +936,11 @@ static int rz_dmac_probe(struct platform_device *pdev)
874936
if (IS_ERR(dmac->base))
875937
return PTR_ERR(dmac->base);
876938

877-
dmac->ext_base = devm_platform_ioremap_resource(pdev, 1);
878-
if (IS_ERR(dmac->ext_base))
879-
return PTR_ERR(dmac->ext_base);
939+
if (!dmac->has_icu) {
940+
dmac->ext_base = devm_platform_ioremap_resource(pdev, 1);
941+
if (IS_ERR(dmac->ext_base))
942+
return PTR_ERR(dmac->ext_base);
943+
}
880944

881945
/* Register interrupt handler for error */
882946
irq = platform_get_irq_byname(pdev, irqname);
@@ -991,9 +1055,12 @@ static void rz_dmac_remove(struct platform_device *pdev)
9911055
reset_control_assert(dmac->rstc);
9921056
pm_runtime_put(&pdev->dev);
9931057
pm_runtime_disable(&pdev->dev);
1058+
1059+
platform_device_put(dmac->icu.pdev);
9941060
}
9951061

9961062
static const struct of_device_id of_rz_dmac_match[] = {
1063+
{ .compatible = "renesas,r9a09g057-dmac", },
9971064
{ .compatible = "renesas,rz-dmac", },
9981065
{ /* Sentinel */ }
9991066
};

0 commit comments

Comments
 (0)