14
14
#include <linux/dmaengine.h>
15
15
#include <linux/interrupt.h>
16
16
#include <linux/iopoll.h>
17
+ #include <linux/irqchip/irq-renesas-rzv2h.h>
17
18
#include <linux/list.h>
18
19
#include <linux/module.h>
19
20
#include <linux/of.h>
@@ -89,8 +90,14 @@ struct rz_dmac_chan {
89
90
90
91
#define to_rz_dmac_chan (c ) container_of(c, struct rz_dmac_chan, vc.chan)
91
92
93
+ struct rz_dmac_icu {
94
+ struct platform_device * pdev ;
95
+ u8 dmac_index ;
96
+ };
97
+
92
98
struct rz_dmac {
93
99
struct dma_device engine ;
100
+ struct rz_dmac_icu icu ;
94
101
struct device * dev ;
95
102
struct reset_control * rstc ;
96
103
void __iomem * base ;
@@ -99,6 +106,8 @@ struct rz_dmac {
99
106
unsigned int n_channels ;
100
107
struct rz_dmac_chan * channels ;
101
108
109
+ bool has_icu ;
110
+
102
111
DECLARE_BITMAP (modules , 1024 );
103
112
};
104
113
@@ -167,6 +176,9 @@ struct rz_dmac {
167
176
#define RZ_DMAC_MAX_CHANNELS 16
168
177
#define DMAC_NR_LMDESC 64
169
178
179
+ /* RZ/V2H ICU related */
180
+ #define RZV2H_MAX_DMAC_INDEX 4
181
+
170
182
/*
171
183
* -----------------------------------------------------------------------------
172
184
* Device access
@@ -324,7 +336,13 @@ static void rz_dmac_prepare_desc_for_memcpy(struct rz_dmac_chan *channel)
324
336
lmdesc -> chext = 0 ;
325
337
lmdesc -> header = HEADER_LV ;
326
338
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
+ }
328
346
329
347
channel -> chcfg = chcfg ;
330
348
channel -> chctrl = CHCTRL_STG | CHCTRL_SETEN ;
@@ -375,7 +393,13 @@ static void rz_dmac_prepare_descs_for_slave_sg(struct rz_dmac_chan *channel)
375
393
376
394
channel -> lmdesc .tail = lmdesc ;
377
395
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
+
379
403
channel -> chctrl = CHCTRL_SETEN ;
380
404
}
381
405
@@ -647,7 +671,13 @@ static void rz_dmac_device_synchronize(struct dma_chan *chan)
647
671
if (ret < 0 )
648
672
dev_warn (dmac -> dev , "DMA Timeout" );
649
673
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
+ }
651
681
}
652
682
653
683
/*
@@ -824,6 +854,38 @@ static int rz_dmac_chan_probe(struct rz_dmac *dmac,
824
854
return 0 ;
825
855
}
826
856
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
+
827
889
static int rz_dmac_parse_of (struct device * dev , struct rz_dmac * dmac )
828
890
{
829
891
struct device_node * np = dev -> of_node ;
@@ -840,7 +902,7 @@ static int rz_dmac_parse_of(struct device *dev, struct rz_dmac *dmac)
840
902
return - EINVAL ;
841
903
}
842
904
843
- return 0 ;
905
+ return rz_dmac_parse_of_icu ( dev , dmac ) ;
844
906
}
845
907
846
908
static int rz_dmac_probe (struct platform_device * pdev )
@@ -874,9 +936,11 @@ static int rz_dmac_probe(struct platform_device *pdev)
874
936
if (IS_ERR (dmac -> base ))
875
937
return PTR_ERR (dmac -> base );
876
938
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
+ }
880
944
881
945
/* Register interrupt handler for error */
882
946
irq = platform_get_irq_byname (pdev , irqname );
@@ -991,9 +1055,12 @@ static void rz_dmac_remove(struct platform_device *pdev)
991
1055
reset_control_assert (dmac -> rstc );
992
1056
pm_runtime_put (& pdev -> dev );
993
1057
pm_runtime_disable (& pdev -> dev );
1058
+
1059
+ platform_device_put (dmac -> icu .pdev );
994
1060
}
995
1061
996
1062
static const struct of_device_id of_rz_dmac_match [] = {
1063
+ { .compatible = "renesas,r9a09g057-dmac" , },
997
1064
{ .compatible = "renesas,rz-dmac" , },
998
1065
{ /* Sentinel */ }
999
1066
};
0 commit comments