at91: add kernel support for sama7g5 soc
[openwrt/staging/dedeckeh.git] / target / linux / at91 / patches-5.10 / 134-dmaengine-at_xdmac-add-AXI-priority-support-and-reco.patch
1 From 4833d6ea13a6d2c44a91247991a82c3eb6c1613e Mon Sep 17 00:00:00 2001
2 From: Eugen Hristev <eugen.hristev@microchip.com>
3 Date: Fri, 16 Oct 2020 12:39:18 +0300
4 Subject: [PATCH 134/247] dmaengine: at_xdmac: add AXI priority support and
5 recommended settings
6
7 The sama7g5 version of the XDMAC supports priority configuration and
8 outstanding capabilities.
9 Add defines for the specific registers for this configuration, together
10 with recommended settings.
11 However the settings are very different if the XDMAC is a mem2mem or a
12 per2mem controller.
13 Thus, we need to differentiate according to device tree property.
14
15 Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
16 Link: https://lore.kernel.org/r/20201016093918.290137-1-eugen.hristev@microchip.com
17 Signed-off-by: Vinod Koul <vkoul@kernel.org>
18 ---
19 drivers/dma/at_xdmac.c | 47 ++++++++++++++++++++++++++++++++++++++++++
20 1 file changed, 47 insertions(+)
21
22 diff --git a/drivers/dma/at_xdmac.c b/drivers/dma/at_xdmac.c
23 index 2b096ea04018..8ca86d09b255 100644
24 --- a/drivers/dma/at_xdmac.c
25 +++ b/drivers/dma/at_xdmac.c
26 @@ -30,7 +30,24 @@
27 #define AT_XDMAC_FIFO_SZ(i) (((i) >> 5) & 0x7FF) /* Number of Bytes */
28 #define AT_XDMAC_NB_REQ(i) ((((i) >> 16) & 0x3F) + 1) /* Number of Peripheral Requests Minus One */
29 #define AT_XDMAC_GCFG 0x04 /* Global Configuration Register */
30 +#define AT_XDMAC_WRHP(i) (((i) & 0xF) << 4)
31 +#define AT_XDMAC_WRMP(i) (((i) & 0xF) << 8)
32 +#define AT_XDMAC_WRLP(i) (((i) & 0xF) << 12)
33 +#define AT_XDMAC_RDHP(i) (((i) & 0xF) << 16)
34 +#define AT_XDMAC_RDMP(i) (((i) & 0xF) << 20)
35 +#define AT_XDMAC_RDLP(i) (((i) & 0xF) << 24)
36 +#define AT_XDMAC_RDSG(i) (((i) & 0xF) << 28)
37 +#define AT_XDMAC_GCFG_M2M (AT_XDMAC_RDLP(0xF) | AT_XDMAC_WRLP(0xF))
38 +#define AT_XDMAC_GCFG_P2M (AT_XDMAC_RDSG(0x1) | AT_XDMAC_RDHP(0x3) | \
39 + AT_XDMAC_WRHP(0x5))
40 #define AT_XDMAC_GWAC 0x08 /* Global Weighted Arbiter Configuration Register */
41 +#define AT_XDMAC_PW0(i) (((i) & 0xF) << 0)
42 +#define AT_XDMAC_PW1(i) (((i) & 0xF) << 4)
43 +#define AT_XDMAC_PW2(i) (((i) & 0xF) << 8)
44 +#define AT_XDMAC_PW3(i) (((i) & 0xF) << 12)
45 +#define AT_XDMAC_GWAC_M2M 0
46 +#define AT_XDMAC_GWAC_P2M (AT_XDMAC_PW0(0xF) | AT_XDMAC_PW2(0xF))
47 +
48 #define AT_XDMAC_GIE 0x0C /* Global Interrupt Enable Register */
49 #define AT_XDMAC_GID 0x10 /* Global Interrupt Disable Register */
50 #define AT_XDMAC_GIM 0x14 /* Global Interrupt Mask Register */
51 @@ -190,6 +207,8 @@ struct at_xdmac_layout {
52 u8 chan_cc_reg_base;
53 /* Source/Destination Interface must be specified or not */
54 bool sdif;
55 + /* AXI queue priority configuration supported */
56 + bool axi_config;
57 };
58
59 /* ----- Channels ----- */
60 @@ -268,6 +287,7 @@ static const struct at_xdmac_layout at_xdmac_sama5d4_layout = {
61 .gswf = 0x40,
62 .chan_cc_reg_base = 0x50,
63 .sdif = true,
64 + .axi_config = false,
65 };
66
67 static const struct at_xdmac_layout at_xdmac_sama7g5_layout = {
68 @@ -280,6 +300,7 @@ static const struct at_xdmac_layout at_xdmac_sama7g5_layout = {
69 .gswf = 0x50,
70 .chan_cc_reg_base = 0x60,
71 .sdif = false,
72 + .axi_config = true,
73 };
74
75 static inline void __iomem *at_xdmac_chan_reg_base(struct at_xdmac *atxdmac, unsigned int chan_nb)
76 @@ -1996,6 +2017,30 @@ static int atmel_xdmac_resume(struct device *dev)
77 }
78 #endif /* CONFIG_PM_SLEEP */
79
80 +static void at_xdmac_axi_config(struct platform_device *pdev)
81 +{
82 + struct at_xdmac *atxdmac = (struct at_xdmac *)platform_get_drvdata(pdev);
83 + bool dev_m2m = false;
84 + u32 dma_requests;
85 +
86 + if (!atxdmac->layout->axi_config)
87 + return; /* Not supported */
88 +
89 + if (!of_property_read_u32(pdev->dev.of_node, "dma-requests",
90 + &dma_requests)) {
91 + dev_info(&pdev->dev, "controller in mem2mem mode.\n");
92 + dev_m2m = true;
93 + }
94 +
95 + if (dev_m2m) {
96 + at_xdmac_write(atxdmac, AT_XDMAC_GCFG, AT_XDMAC_GCFG_M2M);
97 + at_xdmac_write(atxdmac, AT_XDMAC_GWAC, AT_XDMAC_GWAC_M2M);
98 + } else {
99 + at_xdmac_write(atxdmac, AT_XDMAC_GCFG, AT_XDMAC_GCFG_P2M);
100 + at_xdmac_write(atxdmac, AT_XDMAC_GWAC, AT_XDMAC_GWAC_P2M);
101 + }
102 +}
103 +
104 static int at_xdmac_probe(struct platform_device *pdev)
105 {
106 struct at_xdmac *atxdmac;
107 @@ -2140,6 +2185,8 @@ static int at_xdmac_probe(struct platform_device *pdev)
108 dev_info(&pdev->dev, "%d channels, mapped at 0x%p\n",
109 nr_channels, atxdmac->regs);
110
111 + at_xdmac_axi_config(pdev);
112 +
113 return 0;
114
115 err_dma_unregister:
116 --
117 2.32.0
118