dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3][V2] include: fpga: adi-axi-common.h: add common regs & defs header
@ 2019-05-21 14:14 Alexandru Ardelean
  2019-05-21 14:14 ` [PATCH 2/3][V2] dmaengine: axi-dmac: Discover length alignment requirement Alexandru Ardelean
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Alexandru Ardelean @ 2019-05-21 14:14 UTC (permalink / raw)
  To: dmaengine; +Cc: Alexandru Ardelean

The AXI HDL cores provided for Analog Devices reference designs all share
some common base registers (e.g. version register at address 0x00).

To reduce duplication for this, a common header is added to define these
registers as well as bitfields & macros to work with these registers.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 include/linux/fpga/adi-axi-common.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 include/linux/fpga/adi-axi-common.h

diff --git a/include/linux/fpga/adi-axi-common.h b/include/linux/fpga/adi-axi-common.h
new file mode 100644
index 000000000000..7966c89561b1
--- /dev/null
+++ b/include/linux/fpga/adi-axi-common.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Analog Devices AXI common registers & definitions
+ *
+ * Copyright 2019 Analog Devices Inc.
+ *
+ * https://wiki.analog.com/resources/fpga/docs/axi_ip
+ * https://wiki.analog.com/resources/fpga/docs/hdl/regmap
+ */
+
+#ifndef ADI_AXI_COMMON_H_
+#define ADI_AXI_COMMON_H_
+
+#define	ADI_AXI_REG_VERSION			0x0000
+
+#define ADI_AXI_PCORE_VER(major, minor, patch)	\
+	(((major) << 16) | ((minor) << 8) | (patch))
+
+#endif /* ADI_AXI_COMMON_H_ */
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3][V2] dmaengine: axi-dmac: Discover length alignment requirement
  2019-05-21 14:14 [PATCH 1/3][V2] include: fpga: adi-axi-common.h: add common regs & defs header Alexandru Ardelean
@ 2019-05-21 14:14 ` Alexandru Ardelean
  2019-05-21 14:14 ` [PATCH 3/3][V2] dmaengine: axi-dmac: assign `copy_align` property Alexandru Ardelean
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Alexandru Ardelean @ 2019-05-21 14:14 UTC (permalink / raw)
  To: dmaengine; +Cc: Lars-Peter Clausen, Alexandru Ardelean

From: Lars-Peter Clausen <lars@metafoo.de>

Starting with version 4.1.a the AXI-DMAC is capable of reporting the
required length alignment.

The LSBs that are required to be set for alignment will always read back as
set from the transfer length register. It is not possible to clear them by
writing a 0. This means the driver can discover the length alignment
requirement by writing 0 to that register and reading back the value.

Since the DMA will support length alignment requirements that are different
from the address alignment requirement track both of them independently.

For older versions of the peripheral assume that the length alignment
requirement is equal to the address alignment requirement.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/dma/dma-axi-dmac.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c
index 0984ae6eb155..196e6c429182 100644
--- a/drivers/dma/dma-axi-dmac.c
+++ b/drivers/dma/dma-axi-dmac.c
@@ -20,6 +20,7 @@
 #include <linux/of_dma.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
+#include <linux/fpga/adi-axi-common.h>
 
 #include <dt-bindings/dma/axi-dmac.h>
 
@@ -110,7 +111,8 @@ struct axi_dmac_chan {
 	unsigned int dest_type;
 
 	unsigned int max_length;
-	unsigned int align_mask;
+	unsigned int address_align_mask;
+	unsigned int length_align_mask;
 
 	bool hw_cyclic;
 	bool hw_2d;
@@ -169,14 +171,14 @@ static bool axi_dmac_check_len(struct axi_dmac_chan *chan, unsigned int len)
 {
 	if (len == 0)
 		return false;
-	if ((len & chan->align_mask) != 0) /* Not aligned */
+	if ((len & chan->length_align_mask) != 0) /* Not aligned */
 		return false;
 	return true;
 }
 
 static bool axi_dmac_check_addr(struct axi_dmac_chan *chan, dma_addr_t addr)
 {
-	if ((addr & chan->align_mask) != 0) /* Not aligned */
+	if ((addr & chan->address_align_mask) != 0) /* Not aligned */
 		return false;
 	return true;
 }
@@ -394,7 +396,7 @@ static struct axi_dmac_sg *axi_dmac_fill_linear_sg(struct axi_dmac_chan *chan,
 	num_segments = DIV_ROUND_UP(period_len, chan->max_length);
 	segment_size = DIV_ROUND_UP(period_len, num_segments);
 	/* Take care of alignment */
-	segment_size = ((segment_size - 1) | chan->align_mask) + 1;
+	segment_size = ((segment_size - 1) | chan->length_align_mask) + 1;
 
 	for (i = 0; i < num_periods; i++) {
 		len = period_len;
@@ -623,7 +625,7 @@ static int axi_dmac_parse_chan_dt(struct device_node *of_chan,
 		return ret;
 	chan->dest_width = val / 8;
 
-	chan->align_mask = max(chan->dest_width, chan->src_width) - 1;
+	chan->address_align_mask = max(chan->dest_width, chan->src_width) - 1;
 
 	if (axi_dmac_dest_is_mem(chan) && axi_dmac_src_is_mem(chan))
 		chan->direction = DMA_MEM_TO_MEM;
@@ -640,6 +642,9 @@ static int axi_dmac_parse_chan_dt(struct device_node *of_chan,
 static int axi_dmac_detect_caps(struct axi_dmac *dmac)
 {
 	struct axi_dmac_chan *chan = &dmac->chan;
+	unsigned int version;
+
+	version = axi_dmac_read(dmac, ADI_AXI_REG_VERSION);
 
 	axi_dmac_write(dmac, AXI_DMAC_REG_FLAGS, AXI_DMAC_FLAG_CYCLIC);
 	if (axi_dmac_read(dmac, AXI_DMAC_REG_FLAGS) == AXI_DMAC_FLAG_CYCLIC)
@@ -670,6 +675,13 @@ static int axi_dmac_detect_caps(struct axi_dmac *dmac)
 		return -ENODEV;
 	}
 
+	if (version >= ADI_AXI_PCORE_VER(4, 1, 'a')) {
+		axi_dmac_write(dmac, AXI_DMAC_REG_X_LENGTH, 0x00);
+		chan->length_align_mask = axi_dmac_read(dmac, AXI_DMAC_REG_X_LENGTH);
+	} else {
+		chan->length_align_mask = chan->address_align_mask;
+	}
+
 	return 0;
 }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3][V2] dmaengine: axi-dmac: assign `copy_align` property
  2019-05-21 14:14 [PATCH 1/3][V2] include: fpga: adi-axi-common.h: add common regs & defs header Alexandru Ardelean
  2019-05-21 14:14 ` [PATCH 2/3][V2] dmaengine: axi-dmac: Discover length alignment requirement Alexandru Ardelean
@ 2019-05-21 14:14 ` Alexandru Ardelean
  2019-05-21 14:18 ` [PATCH 1/3][V2] include: fpga: adi-axi-common.h: add common regs & defs header Ardelean, Alexandru
  2019-05-27  6:37 ` Vinod Koul
  3 siblings, 0 replies; 6+ messages in thread
From: Alexandru Ardelean @ 2019-05-21 14:14 UTC (permalink / raw)
  To: dmaengine; +Cc: Alexandru Ardelean

The `copy_align` property is a generic property that describes alignment
for DMA memcpy & sg ops.
It serves mostly an informational purpose, and can be used in DMA tests, to
pass the info to know what alignment to expect.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/dma/dma-axi-dmac.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/dma/dma-axi-dmac.c b/drivers/dma/dma-axi-dmac.c
index 196e6c429182..88f9986e0e14 100644
--- a/drivers/dma/dma-axi-dmac.c
+++ b/drivers/dma/dma-axi-dmac.c
@@ -762,6 +762,8 @@ static int axi_dmac_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_clk_disable;
 
+	dma_dev->copy_align = (dmac->chan.address_align_mask + 1);
+
 	axi_dmac_write(dmac, AXI_DMAC_REG_IRQ_MASK, 0x00);
 
 	ret = dma_async_device_register(dma_dev);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3][V2] include: fpga: adi-axi-common.h: add common regs & defs header
  2019-05-21 14:14 [PATCH 1/3][V2] include: fpga: adi-axi-common.h: add common regs & defs header Alexandru Ardelean
  2019-05-21 14:14 ` [PATCH 2/3][V2] dmaengine: axi-dmac: Discover length alignment requirement Alexandru Ardelean
  2019-05-21 14:14 ` [PATCH 3/3][V2] dmaengine: axi-dmac: assign `copy_align` property Alexandru Ardelean
@ 2019-05-21 14:18 ` Ardelean, Alexandru
  2019-05-27  6:37 ` Vinod Koul
  3 siblings, 0 replies; 6+ messages in thread
From: Ardelean, Alexandru @ 2019-05-21 14:18 UTC (permalink / raw)
  To: dmaengine

On Tue, 2019-05-21 at 17:14 +0300, Alexandru Ardelean wrote:
> The AXI HDL cores provided for Analog Devices reference designs all share
> some common base registers (e.g. version register at address 0x00).
> 
> To reduce duplication for this, a common header is added to define these
> registers as well as bitfields & macros to work with these registers.
> 
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> ---

I forgot to add a changelog for this series when writing the patches.

Changelog v1 -> v2:
* add common `include/linux/fpga/adi-axi-common.h` with reg version; more regs will be added
* use macro to check version of HDL core from common header
* add my S-o-B to patch `dmaengine: axi-dmac: Discover length alignment requirement`


>  include/linux/fpga/adi-axi-common.h | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>  create mode 100644 include/linux/fpga/adi-axi-common.h
> 
> diff --git a/include/linux/fpga/adi-axi-common.h b/include/linux/fpga/adi-axi-common.h
> new file mode 100644
> index 000000000000..7966c89561b1
> --- /dev/null
> +++ b/include/linux/fpga/adi-axi-common.h
> @@ -0,0 +1,19 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Analog Devices AXI common registers & definitions
> + *
> + * Copyright 2019 Analog Devices Inc.
> + *
> + * https://wiki.analog.com/resources/fpga/docs/axi_ip
> + * https://wiki.analog.com/resources/fpga/docs/hdl/regmap
> + */
> +
> +#ifndef ADI_AXI_COMMON_H_
> +#define ADI_AXI_COMMON_H_
> +
> +#define	ADI_AXI_REG_VERSION			0x0000
> +
> +#define ADI_AXI_PCORE_VER(major, minor, patch)	\
> +	(((major) << 16) | ((minor) << 8) | (patch))
> +
> +#endif /* ADI_AXI_COMMON_H_ */

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3][V2] include: fpga: adi-axi-common.h: add common regs & defs header
  2019-05-21 14:14 [PATCH 1/3][V2] include: fpga: adi-axi-common.h: add common regs & defs header Alexandru Ardelean
                   ` (2 preceding siblings ...)
  2019-05-21 14:18 ` [PATCH 1/3][V2] include: fpga: adi-axi-common.h: add common regs & defs header Ardelean, Alexandru
@ 2019-05-27  6:37 ` Vinod Koul
  2019-05-27  6:40   ` Ardelean, Alexandru
  3 siblings, 1 reply; 6+ messages in thread
From: Vinod Koul @ 2019-05-27  6:37 UTC (permalink / raw)
  To: Alexandru Ardelean; +Cc: dmaengine

On 21-05-19, 17:14, Alexandru Ardelean wrote:
> The AXI HDL cores provided for Analog Devices reference designs all share
> some common base registers (e.g. version register at address 0x00).
> 
> To reduce duplication for this, a common header is added to define these
> registers as well as bitfields & macros to work with these registers.
> 
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> ---
>  include/linux/fpga/adi-axi-common.h | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>  create mode 100644 include/linux/fpga/adi-axi-common.h
> 
> diff --git a/include/linux/fpga/adi-axi-common.h b/include/linux/fpga/adi-axi-common.h
> new file mode 100644
> index 000000000000..7966c89561b1
> --- /dev/null
> +++ b/include/linux/fpga/adi-axi-common.h
> @@ -0,0 +1,19 @@
> +// SPDX-License-Identifier: GPL-2.0

For headers this is not the style to be used.
See Documentation/process/license-rules.rst

      C source: // SPDX-License-Identifier: <SPDX License Expression>
      C header: /* SPDX-License-Identifier: <SPDX License Expression> */

> +/*
> + * Analog Devices AXI common registers & definitions
> + *
> + * Copyright 2019 Analog Devices Inc.
> + *
> + * https://wiki.analog.com/resources/fpga/docs/axi_ip
> + * https://wiki.analog.com/resources/fpga/docs/hdl/regmap
> + */
> +
> +#ifndef ADI_AXI_COMMON_H_
> +#define ADI_AXI_COMMON_H_
> +
> +#define	ADI_AXI_REG_VERSION			0x0000
> +
> +#define ADI_AXI_PCORE_VER(major, minor, patch)	\
> +	(((major) << 16) | ((minor) << 8) | (patch))
> +
> +#endif /* ADI_AXI_COMMON_H_ */
> -- 
> 2.17.1

-- 
~Vinod

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3][V2] include: fpga: adi-axi-common.h: add common regs & defs header
  2019-05-27  6:37 ` Vinod Koul
@ 2019-05-27  6:40   ` Ardelean, Alexandru
  0 siblings, 0 replies; 6+ messages in thread
From: Ardelean, Alexandru @ 2019-05-27  6:40 UTC (permalink / raw)
  To: vkoul; +Cc: dmaengine

On Mon, 2019-05-27 at 12:07 +0530, Vinod Koul wrote:
> [External]
> 
> 
> On 21-05-19, 17:14, Alexandru Ardelean wrote:
> > The AXI HDL cores provided for Analog Devices reference designs all share
> > some common base registers (e.g. version register at address 0x00).
> > 
> > To reduce duplication for this, a common header is added to define these
> > registers as well as bitfields & macros to work with these registers.
> > 
> > Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> > ---
> >  include/linux/fpga/adi-axi-common.h | 19 +++++++++++++++++++
> >  1 file changed, 19 insertions(+)
> >  create mode 100644 include/linux/fpga/adi-axi-common.h
> > 
> > diff --git a/include/linux/fpga/adi-axi-common.h b/include/linux/fpga/adi-axi-common.h
> > new file mode 100644
> > index 000000000000..7966c89561b1
> > --- /dev/null
> > +++ b/include/linux/fpga/adi-axi-common.h
> > @@ -0,0 +1,19 @@
> > +// SPDX-License-Identifier: GPL-2.0
> 
> For headers this is not the style to be used.
> See Documentation/process/license-rules.rst
> 
>       C source: // SPDX-License-Identifier: <SPDX License Expression>
>       C header: /* SPDX-License-Identifier: <SPDX License Expression> */
> 

Ack.
Will re-spin.

> > +/*
> > + * Analog Devices AXI common registers & definitions
> > + *
> > + * Copyright 2019 Analog Devices Inc.
> > + *
> > + * https://wiki.analog.com/resources/fpga/docs/axi_ip
> > + * https://wiki.analog.com/resources/fpga/docs/hdl/regmap
> > + */
> > +
> > +#ifndef ADI_AXI_COMMON_H_
> > +#define ADI_AXI_COMMON_H_
> > +
> > +#define      ADI_AXI_REG_VERSION                     0x0000
> > +
> > +#define ADI_AXI_PCORE_VER(major, minor, patch)       \
> > +     (((major) << 16) | ((minor) << 8) | (patch))
> > +
> > +#endif /* ADI_AXI_COMMON_H_ */
> > --
> > 2.17.1
> 
> --
> ~Vinod

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-05-27  6:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-21 14:14 [PATCH 1/3][V2] include: fpga: adi-axi-common.h: add common regs & defs header Alexandru Ardelean
2019-05-21 14:14 ` [PATCH 2/3][V2] dmaengine: axi-dmac: Discover length alignment requirement Alexandru Ardelean
2019-05-21 14:14 ` [PATCH 3/3][V2] dmaengine: axi-dmac: assign `copy_align` property Alexandru Ardelean
2019-05-21 14:18 ` [PATCH 1/3][V2] include: fpga: adi-axi-common.h: add common regs & defs header Ardelean, Alexandru
2019-05-27  6:37 ` Vinod Koul
2019-05-27  6:40   ` Ardelean, Alexandru

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).