All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support
@ 2022-03-29 15:24 Miquel Raynal
  2022-03-29 15:24 ` [PATCH v3 01/10] serial: 8250: dw: Move the per-device structure Miquel Raynal
                   ` (10 more replies)
  0 siblings, 11 replies; 20+ messages in thread
From: Miquel Raynal @ 2022-03-29 15:24 UTC (permalink / raw)
  To: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby
  Cc: Miquel Raynal, Andy Shevchenko, linux-renesas-soc, linux-serial,
	Milan Stevanovic, Jimmy Lalande, Pascal Eberhard,
	Thomas Petazzoni, Herve Codina, Clement Leger

Hello,

Support for the RZN1 DMA engine allows us adapt a little bit the 8250 DW
UART driver with to bring DMA support for this SoC.

This short series applies on top of the series bringing RZN1 DMA
support, currently on its v5, see [1]. Technically speaking, only the DT
patch needs to be applied after [1]. The other patches can come in at
any moment, because if no "dmas" property is provided in the DT, DMA
support will simply be ignored.

[1] https://lore.kernel.org/dmaengine/20220315191255.221473-1-miquel.raynal@bootlin.com/T/#m0ef3323abce3eec961e142bf2fb35e95b9045fc5

Thanks,
Miquèl

Changes in v3:
* Added Geert's Reviewed-by's.
* Used forward declaration in dwlib.h when relevant.
* Reordered the headers when necessary.
* Added a patch changing the quirks type from unsigned long to unsigned
  int as advised by Andy.
* s/up->port.dev/p->dev/ when relevant.
* Added a debug message in dwlib when no CPR is available.
* Dropped the CPR_DMA_EXTRA bit addition: we assume DMA is there.
* Changed the prefix of certain definitions.

Changes in v2:
* Rebased on top of Emil's patches. Added platform data structures
  instead of raw quirk integers in order to provide a CPR value.
* Added includes in dwlib.h even though it's not particularly useful, it
  may help preventing a build error later on if we ever decide to include
  this file from another location.
* Dropped the call to ->tx_dma and instead implemented a callback that
  can be called from serial8250_tx/rx_dma.
* Used the device API instead of the of API.
* Changed the logic about DMA capabilities to avoid breaking existing
  designs.
* Introduced a new quirk related to the flow-control feature of the
  RZ/N1 version of the UART controller when used with DMA.
* Re-arranged the entire series as advised by Andy and Geert.
* Added several preparation patches to ease the review of various
  functional changes.

Miquel Raynal (7):
  serial: 8250: dw: Use the device API
  serial: 8250: dw: Change the quirks type to unsigned int
  serial: 8250: dw: Create a more generic platform data structure
  serial: 8250: dw: Allow to use a fallback CPR value if not synthesized
  serial: 8250: dma: Allow driver operations before starting DMA
    transfers
  serial: 8250: dw: Introduce an rx_timeout variable in the IRQ path
  ARM: dts: r9a06g032: Fill the UART DMA properties

Phil Edworthy (3):
  serial: 8250: dw: Move the per-device structure
  serial: 8250: dw: Add support for DMA flow controlling devices
  serial: 8250: dw: Improve RZN1 support

 arch/arm/boot/dts/r9a06g032.dtsi     |  15 ++++
 drivers/tty/serial/8250/8250.h       |  18 +++++
 drivers/tty/serial/8250/8250_dma.c   |   4 +
 drivers/tty/serial/8250/8250_dw.c    | 114 +++++++++++++++++++++------
 drivers/tty/serial/8250/8250_dwlib.c |   9 +++
 drivers/tty/serial/8250/8250_dwlib.h |  26 ++++++
 6 files changed, 163 insertions(+), 23 deletions(-)

-- 
2.27.0


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

* [PATCH v3 01/10] serial: 8250: dw: Move the per-device structure
  2022-03-29 15:24 [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Miquel Raynal
@ 2022-03-29 15:24 ` Miquel Raynal
  2022-03-29 15:24 ` [PATCH v3 02/10] serial: 8250: dw: Use the device API Miquel Raynal
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2022-03-29 15:24 UTC (permalink / raw)
  To: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby
  Cc: Miquel Raynal, Andy Shevchenko, linux-renesas-soc, linux-serial,
	Milan Stevanovic, Jimmy Lalande, Pascal Eberhard,
	Thomas Petazzoni, Herve Codina, Clement Leger, Phil Edworthy

From: Phil Edworthy <phil.edworthy@renesas.com>

This structure needs to be reused from dwlib, so let's move it into a
shared header. There is no functional change.

Signed-off-by: Phil Edworthy <phil.edworthy@renesas.com>
[miquel.raynal@bootlin.com: Extracted from a bigger change]
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/tty/serial/8250/8250_dw.c    | 16 ----------------
 drivers/tty/serial/8250/8250_dwlib.h | 21 +++++++++++++++++++++
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index 96a62e95726b..d89731d6c94c 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -42,22 +42,6 @@
 #define DW_UART_QUIRK_ARMADA_38X	BIT(1)
 #define DW_UART_QUIRK_SKIP_SET_RATE	BIT(2)
 
-struct dw8250_data {
-	struct dw8250_port_data	data;
-
-	u8			usr_reg;
-	int			msr_mask_on;
-	int			msr_mask_off;
-	struct clk		*clk;
-	struct clk		*pclk;
-	struct notifier_block	clk_notifier;
-	struct work_struct	clk_work;
-	struct reset_control	*rst;
-
-	unsigned int		skip_autocfg:1;
-	unsigned int		uart_16550_compatible:1;
-};
-
 static inline struct dw8250_data *to_dw8250_data(struct dw8250_port_data *data)
 {
 	return container_of(data, struct dw8250_data, data);
diff --git a/drivers/tty/serial/8250/8250_dwlib.h b/drivers/tty/serial/8250/8250_dwlib.h
index 83d528e5cc21..e973f804c2f4 100644
--- a/drivers/tty/serial/8250/8250_dwlib.h
+++ b/drivers/tty/serial/8250/8250_dwlib.h
@@ -1,10 +1,15 @@
 /* SPDX-License-Identifier: GPL-2.0+ */
 /* Synopsys DesignWare 8250 library header file. */
 
+#include <linux/notifier.h>
 #include <linux/types.h>
+#include <linux/workqueue.h>
 
 #include "8250.h"
 
+struct clk;
+struct reset_control;
+
 struct dw8250_port_data {
 	/* Port properties */
 	int			line;
@@ -16,5 +21,21 @@ struct dw8250_port_data {
 	u8			dlf_size;
 };
 
+struct dw8250_data {
+	struct dw8250_port_data	data;
+
+	u8			usr_reg;
+	int			msr_mask_on;
+	int			msr_mask_off;
+	struct clk		*clk;
+	struct clk		*pclk;
+	struct notifier_block	clk_notifier;
+	struct work_struct	clk_work;
+	struct reset_control	*rst;
+
+	unsigned int		skip_autocfg:1;
+	unsigned int		uart_16550_compatible:1;
+};
+
 void dw8250_do_set_termios(struct uart_port *p, struct ktermios *termios, struct ktermios *old);
 void dw8250_setup_port(struct uart_port *p);
-- 
2.27.0


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

* [PATCH v3 02/10] serial: 8250: dw: Use the device API
  2022-03-29 15:24 [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Miquel Raynal
  2022-03-29 15:24 ` [PATCH v3 01/10] serial: 8250: dw: Move the per-device structure Miquel Raynal
@ 2022-03-29 15:24 ` Miquel Raynal
  2022-03-29 15:24 ` [PATCH v3 03/10] serial: 8250: dw: Change the quirks type to unsigned int Miquel Raynal
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2022-03-29 15:24 UTC (permalink / raw)
  To: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby
  Cc: Miquel Raynal, Andy Shevchenko, linux-renesas-soc, linux-serial,
	Milan Stevanovic, Jimmy Lalande, Pascal Eberhard,
	Thomas Petazzoni, Herve Codina, Clement Leger,
	Emil Renner Berthing

Use the device API instead of the of_* API.
While at it move this operation outside of the if block to reduce the
indentation level.

Cc: Emil Renner Berthing <kernel@esmil.dk>
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/tty/serial/8250/8250_dw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index d89731d6c94c..28f0dea2ed88 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -376,9 +376,9 @@ static bool dw8250_idma_filter(struct dma_chan *chan, void *param)
 static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
 {
 	struct device_node *np = p->dev->of_node;
+	unsigned long quirks = (unsigned long)device_get_match_data(p->dev);
 
 	if (np) {
-		unsigned long quirks = (unsigned long)of_device_get_match_data(p->dev);
 		int id;
 
 		/* get index of serial line, if found in DT aliases */
-- 
2.27.0


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

* [PATCH v3 03/10] serial: 8250: dw: Change the quirks type to unsigned int
  2022-03-29 15:24 [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Miquel Raynal
  2022-03-29 15:24 ` [PATCH v3 01/10] serial: 8250: dw: Move the per-device structure Miquel Raynal
  2022-03-29 15:24 ` [PATCH v3 02/10] serial: 8250: dw: Use the device API Miquel Raynal
@ 2022-03-29 15:24 ` Miquel Raynal
  2022-03-29 15:43   ` Andy Shevchenko
  2022-03-29 15:58   ` Geert Uytterhoeven
  2022-03-29 15:24 ` [PATCH v3 04/10] serial: 8250: dw: Create a more generic platform data structure Miquel Raynal
                   ` (7 subsequent siblings)
  10 siblings, 2 replies; 20+ messages in thread
From: Miquel Raynal @ 2022-03-29 15:24 UTC (permalink / raw)
  To: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby
  Cc: Miquel Raynal, Andy Shevchenko, linux-renesas-soc, linux-serial,
	Milan Stevanovic, Jimmy Lalande, Pascal Eberhard,
	Thomas Petazzoni, Herve Codina, Clement Leger

Unsigned int is better than unsigned long as its size does not change
between setups and we don't really need this variable to be more than a
few bits wide for now.

Suggested-by: Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/tty/serial/8250/8250_dw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index 28f0dea2ed88..20c9ca03225b 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -376,7 +376,7 @@ static bool dw8250_idma_filter(struct dma_chan *chan, void *param)
 static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
 {
 	struct device_node *np = p->dev->of_node;
-	unsigned long quirks = (unsigned long)device_get_match_data(p->dev);
+	unsigned int quirks = (unsigned int)device_get_match_data(p->dev);
 
 	if (np) {
 		int id;
-- 
2.27.0


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

* [PATCH v3 04/10] serial: 8250: dw: Create a more generic platform data structure
  2022-03-29 15:24 [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Miquel Raynal
                   ` (2 preceding siblings ...)
  2022-03-29 15:24 ` [PATCH v3 03/10] serial: 8250: dw: Change the quirks type to unsigned int Miquel Raynal
@ 2022-03-29 15:24 ` Miquel Raynal
  2022-03-29 15:51   ` Andy Shevchenko
  2022-03-29 15:24 ` [PATCH v3 05/10] serial: 8250: dw: Allow to use a fallback CPR value if not synthesized Miquel Raynal
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Miquel Raynal @ 2022-03-29 15:24 UTC (permalink / raw)
  To: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby
  Cc: Miquel Raynal, Andy Shevchenko, linux-renesas-soc, linux-serial,
	Milan Stevanovic, Jimmy Lalande, Pascal Eberhard,
	Thomas Petazzoni, Herve Codina, Clement Leger,
	Emil Renner Berthing

Before adding more platform data information, let's turn the quirks
information as being a member of a wider structure. More fields will be
added later.

Cc: Emil Renner Berthing <kernel@esmil.dk>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/tty/serial/8250/8250_dw.c    | 24 +++++++++++++++++++-----
 drivers/tty/serial/8250/8250_dwlib.h |  4 ++++
 2 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index 20c9ca03225b..95c4321022d5 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -19,6 +19,7 @@
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/workqueue.h>
 #include <linux/notifier.h>
 #include <linux/slab.h>
@@ -376,7 +377,8 @@ static bool dw8250_idma_filter(struct dma_chan *chan, void *param)
 static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
 {
 	struct device_node *np = p->dev->of_node;
-	unsigned int quirks = (unsigned int)device_get_match_data(p->dev);
+	const struct dw8250_platform_data *pdata = device_get_match_data(p->dev);
+	unsigned int quirks = pdata ? pdata->quirks : 0;
 
 	if (np) {
 		int id;
@@ -683,13 +685,25 @@ static const struct dev_pm_ops dw8250_pm_ops = {
 	SET_RUNTIME_PM_OPS(dw8250_runtime_suspend, dw8250_runtime_resume, NULL)
 };
 
+static const struct dw8250_platform_data dw8250_octeon_3860_data = {
+	.quirks = DW_UART_QUIRK_OCTEON,
+};
+
+static const struct dw8250_platform_data dw8250_armada_38x_data = {
+	.quirks = DW_UART_QUIRK_ARMADA_38X,
+};
+
+static const struct dw8250_platform_data dw8250_starfive_jh7100_data = {
+	.quirks = DW_UART_QUIRK_SKIP_SET_RATE,
+};
+
 static const struct of_device_id dw8250_of_match[] = {
 	{ .compatible = "snps,dw-apb-uart" },
-	{ .compatible = "cavium,octeon-3860-uart", .data = (void *)DW_UART_QUIRK_OCTEON },
-	{ .compatible = "marvell,armada-38x-uart", .data = (void *)DW_UART_QUIRK_ARMADA_38X },
+	{ .compatible = "cavium,octeon-3860-uart", .data = &dw8250_octeon_3860_data },
+	{ .compatible = "marvell,armada-38x-uart", .data = &dw8250_armada_38x_data },
 	{ .compatible = "renesas,rzn1-uart" },
-	{ .compatible = "starfive,jh7100-hsuart",  .data = (void *)DW_UART_QUIRK_SKIP_SET_RATE },
-	{ .compatible = "starfive,jh7100-uart",    .data = (void *)DW_UART_QUIRK_SKIP_SET_RATE },
+	{ .compatible = "starfive,jh7100-hsuart", .data = &dw8250_starfive_jh7100_data },
+	{ .compatible = "starfive,jh7100-uart", .data = &dw8250_starfive_jh7100_data },
 	{ /* Sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, dw8250_of_match);
diff --git a/drivers/tty/serial/8250/8250_dwlib.h b/drivers/tty/serial/8250/8250_dwlib.h
index e973f804c2f4..7dfc2d6361e5 100644
--- a/drivers/tty/serial/8250/8250_dwlib.h
+++ b/drivers/tty/serial/8250/8250_dwlib.h
@@ -21,6 +21,10 @@ struct dw8250_port_data {
 	u8			dlf_size;
 };
 
+struct dw8250_platform_data {
+	unsigned int quirks;
+};
+
 struct dw8250_data {
 	struct dw8250_port_data	data;
 
-- 
2.27.0


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

* [PATCH v3 05/10] serial: 8250: dw: Allow to use a fallback CPR value if not synthesized
  2022-03-29 15:24 [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Miquel Raynal
                   ` (3 preceding siblings ...)
  2022-03-29 15:24 ` [PATCH v3 04/10] serial: 8250: dw: Create a more generic platform data structure Miquel Raynal
@ 2022-03-29 15:24 ` Miquel Raynal
  2022-03-29 15:49   ` Andy Shevchenko
  2022-03-29 15:24 ` [PATCH v3 06/10] serial: 8250: dma: Allow driver operations before starting DMA transfers Miquel Raynal
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Miquel Raynal @ 2022-03-29 15:24 UTC (permalink / raw)
  To: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby
  Cc: Miquel Raynal, Andy Shevchenko, linux-renesas-soc, linux-serial,
	Milan Stevanovic, Jimmy Lalande, Pascal Eberhard,
	Thomas Petazzoni, Herve Codina, Clement Leger, Phil Edworthy

DW UART controllers can be synthesized without the CPR register.
In this case, allow to the platform information to provide a CPR value.

Signed-off-by: Phil Edworthy <phil.edworthy@renesas.com>
Co-developed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/tty/serial/8250/8250_dwlib.c | 9 +++++++++
 drivers/tty/serial/8250/8250_dwlib.h | 1 +
 2 files changed, 10 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_dwlib.c b/drivers/tty/serial/8250/8250_dwlib.c
index 622d3b0d89e7..6c4fe1792eb5 100644
--- a/drivers/tty/serial/8250/8250_dwlib.c
+++ b/drivers/tty/serial/8250/8250_dwlib.c
@@ -5,6 +5,7 @@
 #include <linux/device.h>
 #include <linux/io.h>
 #include <linux/kernel.h>
+#include <linux/property.h>
 #include <linux/serial_8250.h>
 #include <linux/serial_core.h>
 
@@ -90,6 +91,7 @@ EXPORT_SYMBOL_GPL(dw8250_do_set_termios);
 void dw8250_setup_port(struct uart_port *p)
 {
 	struct uart_8250_port *up = up_to_u8250p(p);
+	const struct dw8250_platform_data *pdata = device_get_match_data(p->dev);
 	u32 reg;
 
 	/*
@@ -116,6 +118,13 @@ void dw8250_setup_port(struct uart_port *p)
 	}
 
 	reg = dw8250_readl_ext(p, DW_UART_CPR);
+	if (!reg) {
+		if (pdata)
+			reg = pdata->cpr;
+
+		dev_dbg(p->dev, "CPR is not available, using %x instead\n", reg);
+	}
+
 	if (!reg)
 		return;
 
diff --git a/drivers/tty/serial/8250/8250_dwlib.h b/drivers/tty/serial/8250/8250_dwlib.h
index 7dfc2d6361e5..19c530b7fd1d 100644
--- a/drivers/tty/serial/8250/8250_dwlib.h
+++ b/drivers/tty/serial/8250/8250_dwlib.h
@@ -23,6 +23,7 @@ struct dw8250_port_data {
 
 struct dw8250_platform_data {
 	unsigned int quirks;
+	u32 cpr;
 };
 
 struct dw8250_data {
-- 
2.27.0


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

* [PATCH v3 06/10] serial: 8250: dma: Allow driver operations before starting DMA transfers
  2022-03-29 15:24 [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Miquel Raynal
                   ` (4 preceding siblings ...)
  2022-03-29 15:24 ` [PATCH v3 05/10] serial: 8250: dw: Allow to use a fallback CPR value if not synthesized Miquel Raynal
@ 2022-03-29 15:24 ` Miquel Raynal
  2022-03-29 15:24 ` [PATCH v3 07/10] serial: 8250: dw: Introduce an rx_timeout variable in the IRQ path Miquel Raynal
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2022-03-29 15:24 UTC (permalink / raw)
  To: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby
  Cc: Miquel Raynal, Andy Shevchenko, linux-renesas-soc, linux-serial,
	Milan Stevanovic, Jimmy Lalande, Pascal Eberhard,
	Thomas Petazzoni, Herve Codina, Clement Leger

One situation where this could be used is when configuring the UART
controller to be the DMA flow controller. This is a typical case where
the driver might need to program a few more registers before starting a
DMA transfer. Provide the necessary infrastructure to support this
case.

Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/tty/serial/8250/8250.h     | 18 ++++++++++++++++++
 drivers/tty/serial/8250/8250_dma.c |  4 ++++
 2 files changed, 22 insertions(+)

diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h
index db784ace25d8..d19f24e4d13e 100644
--- a/drivers/tty/serial/8250/8250.h
+++ b/drivers/tty/serial/8250/8250.h
@@ -17,6 +17,8 @@
 struct uart_8250_dma {
 	int (*tx_dma)(struct uart_8250_port *p);
 	int (*rx_dma)(struct uart_8250_port *p);
+	void (*prepare_tx_dma)(struct uart_8250_port *p);
+	void (*prepare_rx_dma)(struct uart_8250_port *p);
 
 	/* Filter function */
 	dma_filter_fn		fn;
@@ -301,6 +303,22 @@ extern int serial8250_rx_dma(struct uart_8250_port *);
 extern void serial8250_rx_dma_flush(struct uart_8250_port *);
 extern int serial8250_request_dma(struct uart_8250_port *);
 extern void serial8250_release_dma(struct uart_8250_port *);
+
+static inline void serial8250_do_prepare_tx_dma(struct uart_8250_port *p)
+{
+	struct uart_8250_dma *dma = p->dma;
+
+	if (dma->prepare_tx_dma)
+		dma->prepare_tx_dma(p);
+}
+
+static inline void serial8250_do_prepare_rx_dma(struct uart_8250_port *p)
+{
+	struct uart_8250_dma *dma = p->dma;
+
+	if (dma->prepare_rx_dma)
+		dma->prepare_rx_dma(p);
+}
 #else
 static inline int serial8250_tx_dma(struct uart_8250_port *p)
 {
diff --git a/drivers/tty/serial/8250/8250_dma.c b/drivers/tty/serial/8250/8250_dma.c
index 890fa7ddaa7f..558d3a2ac65b 100644
--- a/drivers/tty/serial/8250/8250_dma.c
+++ b/drivers/tty/serial/8250/8250_dma.c
@@ -77,6 +77,8 @@ int serial8250_tx_dma(struct uart_8250_port *p)
 
 	dma->tx_size = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
 
+	serial8250_do_prepare_tx_dma(p);
+
 	desc = dmaengine_prep_slave_single(dma->txchan,
 					   dma->tx_addr + xmit->tail,
 					   dma->tx_size, DMA_MEM_TO_DEV,
@@ -114,6 +116,8 @@ int serial8250_rx_dma(struct uart_8250_port *p)
 	if (dma->rx_running)
 		return 0;
 
+	serial8250_do_prepare_rx_dma(p);
+
 	desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr,
 					   dma->rx_size, DMA_DEV_TO_MEM,
 					   DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
-- 
2.27.0


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

* [PATCH v3 07/10] serial: 8250: dw: Introduce an rx_timeout variable in the IRQ path
  2022-03-29 15:24 [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Miquel Raynal
                   ` (5 preceding siblings ...)
  2022-03-29 15:24 ` [PATCH v3 06/10] serial: 8250: dma: Allow driver operations before starting DMA transfers Miquel Raynal
@ 2022-03-29 15:24 ` Miquel Raynal
  2022-03-29 15:24 ` [PATCH v3 08/10] serial: 8250: dw: Add support for DMA flow controlling devices Miquel Raynal
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2022-03-29 15:24 UTC (permalink / raw)
  To: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby
  Cc: Miquel Raynal, Andy Shevchenko, linux-renesas-soc, linux-serial,
	Milan Stevanovic, Jimmy Lalande, Pascal Eberhard,
	Thomas Petazzoni, Herve Codina, Clement Leger

In a next change we are going to need the same Rx timeout condition as
we already have in the IRQ handling code. Let's just create a boolean to
clarify what this operation does before reusing it.

There is no functional change.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/tty/serial/8250/8250_dw.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index 95c4321022d5..1a6932d69332 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -228,6 +228,7 @@ static int dw8250_handle_irq(struct uart_port *p)
 	struct uart_8250_port *up = up_to_u8250p(p);
 	struct dw8250_data *d = to_dw8250_data(p->private_data);
 	unsigned int iir = p->serial_in(p, UART_IIR);
+	bool rx_timeout = (iir & 0x3f) == UART_IIR_RX_TIMEOUT;
 	unsigned int status;
 	unsigned long flags;
 
@@ -241,7 +242,7 @@ static int dw8250_handle_irq(struct uart_port *p)
 	 * This problem has only been observed so far when not in DMA mode
 	 * so we limit the workaround only to non-DMA mode.
 	 */
-	if (!up->dma && ((iir & 0x3f) == UART_IIR_RX_TIMEOUT)) {
+	if (!up->dma && rx_timeout) {
 		spin_lock_irqsave(&p->lock, flags);
 		status = p->serial_in(p, UART_LSR);
 
-- 
2.27.0


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

* [PATCH v3 08/10] serial: 8250: dw: Add support for DMA flow controlling devices
  2022-03-29 15:24 [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Miquel Raynal
                   ` (6 preceding siblings ...)
  2022-03-29 15:24 ` [PATCH v3 07/10] serial: 8250: dw: Introduce an rx_timeout variable in the IRQ path Miquel Raynal
@ 2022-03-29 15:24 ` Miquel Raynal
  2022-03-29 15:58   ` Andy Shevchenko
  2022-03-29 15:24 ` [PATCH v3 09/10] serial: 8250: dw: Improve RZN1 support Miquel Raynal
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 20+ messages in thread
From: Miquel Raynal @ 2022-03-29 15:24 UTC (permalink / raw)
  To: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby
  Cc: Miquel Raynal, Andy Shevchenko, linux-renesas-soc, linux-serial,
	Milan Stevanovic, Jimmy Lalande, Pascal Eberhard,
	Thomas Petazzoni, Herve Codina, Clement Leger, Phil Edworthy

From: Phil Edworthy <phil.edworthy@renesas.com>

DW based controllers like the one on Renesas RZ/N1 must be programmed as
flow controllers when using DMA.

* Table 11.45 of the system manual, "Flow Control Combinations", states
  that using UART with DMA requires setting the DMA in the peripheral
  flow controller mode regardless of the direction.

* Chapter 11.6.1.3 of the system manual, "Basic Interface Definitions",
  explains that the burst size in the above case must be configured in
  the peripheral's register DEST/SRC_BURST_SIZE.

Experiments shown that upon Rx timeout, the DMA transaction needed to be
manually cleared as well.

Signed-off-by: Phil Edworthy <phil.edworthy@renesas.com>
Co-developed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/tty/serial/8250/8250_dw.c | 64 +++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index 1a6932d69332..af9fcc77ee76 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -34,14 +34,25 @@
 
 /* Offsets for the DesignWare specific registers */
 #define DW_UART_USR	0x1f /* UART Status Register */
+#define DW_UART_DMASA	0xa8 /* DMA Software Ack */
+#define RZN1_UART_TDMACR 0x10c /* DMA Control Register Transmit Mode */
+#define RZN1_UART_RDMACR 0x110 /* DMA Control Register Receive Mode */
 
 /* DesignWare specific register fields */
 #define DW_UART_MCR_SIRE		BIT(6)
 
+/* Renesas specific register fields */
+#define RZN1_UART_xDMACR_DMA_EN		BIT(0)
+#define RZN1_UART_xDMACR_1_WORD_BURST	(0 << 1)
+#define RZN1_UART_xDMACR_4_WORD_BURST	(1 << 1)
+#define RZN1_UART_xDMACR_8_WORD_BURST	(3 << 1)
+#define RZN1_UART_xDMACR_BLK_SZ(x)	((x) << 3)
+
 /* Quirks */
 #define DW_UART_QUIRK_OCTEON		BIT(0)
 #define DW_UART_QUIRK_ARMADA_38X	BIT(1)
 #define DW_UART_QUIRK_SKIP_SET_RATE	BIT(2)
+#define DW_UART_QUIRK_IS_DMA_FLOW_CONTROLLER BIT(3)
 
 static inline struct dw8250_data *to_dw8250_data(struct dw8250_port_data *data)
 {
@@ -225,6 +236,7 @@ static unsigned int dw8250_serial_in32be(struct uart_port *p, int offset)
 
 static int dw8250_handle_irq(struct uart_port *p)
 {
+	const struct dw8250_platform_data *pdata = device_get_match_data(p->dev);
 	struct uart_8250_port *up = up_to_u8250p(p);
 	struct dw8250_data *d = to_dw8250_data(p->private_data);
 	unsigned int iir = p->serial_in(p, UART_IIR);
@@ -252,6 +264,16 @@ static int dw8250_handle_irq(struct uart_port *p)
 		spin_unlock_irqrestore(&p->lock, flags);
 	}
 
+	/* Manually stop the Rx DMA transfer when acting as flow controller */
+	if (up->dma && up->dma->rx_running && rx_timeout && pdata &&
+	    pdata->quirks & DW_UART_QUIRK_IS_DMA_FLOW_CONTROLLER) {
+		status = p->serial_in(p, UART_LSR);
+		if (status & (UART_LSR_DR | UART_LSR_BI)) {
+			writel(0, p->membase + RZN1_UART_RDMACR);
+			writel(1, p->membase + DW_UART_DMASA);
+		}
+	}
+
 	if (serial8250_handle_irq(p, iir))
 		return 1;
 
@@ -375,6 +397,42 @@ static bool dw8250_idma_filter(struct dma_chan *chan, void *param)
 	return param == chan->device->dev;
 }
 
+static u32 dw8250_rzn1_get_dmacr_burst(int max_burst)
+{
+	if (max_burst >= 8)
+		return RZN1_UART_xDMACR_8_WORD_BURST;
+	else if (max_burst >= 4)
+		return RZN1_UART_xDMACR_4_WORD_BURST;
+	else
+		return RZN1_UART_xDMACR_1_WORD_BURST;
+}
+
+static void dw8250_prepare_tx_dma(struct uart_8250_port *p)
+{
+	struct uart_port *up = &p->port;
+	struct uart_8250_dma *dma = p->dma;
+	u32 val;
+
+	writel(0, up->membase + RZN1_UART_TDMACR);
+	val = dw8250_rzn1_get_dmacr_burst(dma->txconf.dst_maxburst) |
+	      RZN1_UART_xDMACR_BLK_SZ(dma->tx_size) |
+	      RZN1_UART_xDMACR_DMA_EN;
+	writel(val, up->membase + RZN1_UART_TDMACR);
+}
+
+static void dw8250_prepare_rx_dma(struct uart_8250_port *p)
+{
+	struct uart_port *up = &p->port;
+	struct uart_8250_dma *dma = p->dma;
+	u32 val;
+
+	writel(0, up->membase + RZN1_UART_RDMACR);
+	val = dw8250_rzn1_get_dmacr_burst(dma->rxconf.src_maxburst) |
+	      RZN1_UART_xDMACR_BLK_SZ(dma->rx_size) |
+	      RZN1_UART_xDMACR_DMA_EN;
+	writel(val, up->membase + RZN1_UART_RDMACR);
+}
+
 static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
 {
 	struct device_node *np = p->dev->of_node;
@@ -409,6 +467,12 @@ static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
 			p->serial_out = dw8250_serial_out38x;
 		if (quirks & DW_UART_QUIRK_SKIP_SET_RATE)
 			p->set_termios = dw8250_do_set_termios;
+		if (quirks & DW_UART_QUIRK_IS_DMA_FLOW_CONTROLLER) {
+			data->data.dma.txconf.device_fc = 1;
+			data->data.dma.rxconf.device_fc = 1;
+			data->data.dma.prepare_tx_dma = dw8250_prepare_tx_dma;
+			data->data.dma.prepare_rx_dma = dw8250_prepare_rx_dma;
+		}
 
 	} else if (acpi_dev_present("APMC0D08", NULL, -1)) {
 		p->iotype = UPIO_MEM32;
-- 
2.27.0


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

* [PATCH v3 09/10] serial: 8250: dw: Improve RZN1 support
  2022-03-29 15:24 [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Miquel Raynal
                   ` (7 preceding siblings ...)
  2022-03-29 15:24 ` [PATCH v3 08/10] serial: 8250: dw: Add support for DMA flow controlling devices Miquel Raynal
@ 2022-03-29 15:24 ` Miquel Raynal
  2022-03-29 16:00   ` Andy Shevchenko
  2022-03-29 15:24 ` [PATCH v3 10/10] ARM: dts: r9a06g032: Fill the UART DMA properties Miquel Raynal
  2022-03-29 16:01 ` [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Andy Shevchenko
  10 siblings, 1 reply; 20+ messages in thread
From: Miquel Raynal @ 2022-03-29 15:24 UTC (permalink / raw)
  To: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby
  Cc: Miquel Raynal, Andy Shevchenko, linux-renesas-soc, linux-serial,
	Milan Stevanovic, Jimmy Lalande, Pascal Eberhard,
	Thomas Petazzoni, Herve Codina, Clement Leger, Phil Edworthy

From: Phil Edworthy <phil.edworthy@renesas.com>

Renesas RZ/N1 SoC features a slightly modified DW UART.

On this SoC, the CPR register value is known but not synthetized in
hardware. We hence need to provide a CPR value in the platform
data. This version of the controller also relies on acting as flow
controller when using DMA, so we need to provide the
'IS_DMA_FLOW_CONTROLLER' quirk.

Signed-off-by: Phil Edworthy <phil.edworthy@renesas.com>
Co-developed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/tty/serial/8250/8250_dw.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index af9fcc77ee76..efc5c686dbfa 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -758,6 +758,11 @@ static const struct dw8250_platform_data dw8250_armada_38x_data = {
 	.quirks = DW_UART_QUIRK_ARMADA_38X,
 };
 
+static const struct dw8250_platform_data dw8250_renesas_rzn1_data = {
+	.quirks = DW_UART_QUIRK_IS_DMA_FLOW_CONTROLLER,
+	.cpr = 0x00012f32,
+};
+
 static const struct dw8250_platform_data dw8250_starfive_jh7100_data = {
 	.quirks = DW_UART_QUIRK_SKIP_SET_RATE,
 };
@@ -766,7 +771,7 @@ static const struct of_device_id dw8250_of_match[] = {
 	{ .compatible = "snps,dw-apb-uart" },
 	{ .compatible = "cavium,octeon-3860-uart", .data = &dw8250_octeon_3860_data },
 	{ .compatible = "marvell,armada-38x-uart", .data = &dw8250_armada_38x_data },
-	{ .compatible = "renesas,rzn1-uart" },
+	{ .compatible = "renesas,rzn1-uart", .data = &dw8250_renesas_rzn1_data },
 	{ .compatible = "starfive,jh7100-hsuart", .data = &dw8250_starfive_jh7100_data },
 	{ .compatible = "starfive,jh7100-uart", .data = &dw8250_starfive_jh7100_data },
 	{ /* Sentinel */ }
-- 
2.27.0


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

* [PATCH v3 10/10] ARM: dts: r9a06g032: Fill the UART DMA properties
  2022-03-29 15:24 [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Miquel Raynal
                   ` (8 preceding siblings ...)
  2022-03-29 15:24 ` [PATCH v3 09/10] serial: 8250: dw: Improve RZN1 support Miquel Raynal
@ 2022-03-29 15:24 ` Miquel Raynal
  2022-03-29 16:01 ` [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Andy Shevchenko
  10 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2022-03-29 15:24 UTC (permalink / raw)
  To: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby
  Cc: Miquel Raynal, Andy Shevchenko, linux-renesas-soc, linux-serial,
	Milan Stevanovic, Jimmy Lalande, Pascal Eberhard,
	Thomas Petazzoni, Herve Codina, Clement Leger

UART 0 to 2 do not have DMA support, while UART 3 to 7 do.

Fill the "dmas" and "dma-names" properties for each of these nodes.

Please mind that these nodes go through the dmamux node which will
redirect the requests to the right DMA controller. The first 4 cells of
the "dmas" properties will be transferred as-is to the DMA
controllers. The last 2 cells are consumed by the dmamux. Which means
cell 0 and 4 are almost redundant, one giving the controller request ID
and the other the dmamux channel which is a 1:1 translation of the
request IDs, shifted by 16 when pointing to the second DMA controller.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 arch/arm/boot/dts/r9a06g032.dtsi | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm/boot/dts/r9a06g032.dtsi b/arch/arm/boot/dts/r9a06g032.dtsi
index 804f2d6f416f..aa447e2622e0 100644
--- a/arch/arm/boot/dts/r9a06g032.dtsi
+++ b/arch/arm/boot/dts/r9a06g032.dtsi
@@ -128,6 +128,9 @@ uart3: serial@50000000 {
 			reg-io-width = <4>;
 			clocks = <&sysctrl R9A06G032_CLK_UART3>, <&sysctrl R9A06G032_HCLK_UART3>;
 			clock-names = "baudclk", "apb_pclk";
+			dmas =  <&dmamux 0 0 0 0 0 1>,
+				<&dmamux 1 0 0 0 1 1>;
+			dma-names = "rx", "tx";
 			status = "disabled";
 		};
 
@@ -139,6 +142,9 @@ uart4: serial@50001000 {
 			reg-io-width = <4>;
 			clocks = <&sysctrl R9A06G032_CLK_UART4>, <&sysctrl R9A06G032_HCLK_UART4>;
 			clock-names = "baudclk", "apb_pclk";
+			dmas =  <&dmamux 2 0 0 0 2 1>,
+				<&dmamux 3 0 0 0 3 1>;
+			dma-names = "rx", "tx";
 			status = "disabled";
 		};
 
@@ -150,6 +156,9 @@ uart5: serial@50002000 {
 			reg-io-width = <4>;
 			clocks = <&sysctrl R9A06G032_CLK_UART5>, <&sysctrl R9A06G032_HCLK_UART5>;
 			clock-names = "baudclk", "apb_pclk";
+			dmas =  <&dmamux 4 0 0 0 4 1>,
+				<&dmamux 5 0 0 0 5 1>;
+			dma-names = "rx", "tx";
 			status = "disabled";
 		};
 
@@ -161,6 +170,9 @@ uart6: serial@50003000 {
 			reg-io-width = <4>;
 			clocks = <&sysctrl R9A06G032_CLK_UART6>, <&sysctrl R9A06G032_HCLK_UART6>;
 			clock-names = "baudclk", "apb_pclk";
+			dmas =  <&dmamux 6 0 0 0 6 1>,
+				<&dmamux 7 0 0 0 7 1>;
+			dma-names = "rx", "tx";
 			status = "disabled";
 		};
 
@@ -172,6 +184,9 @@ uart7: serial@50004000 {
 			reg-io-width = <4>;
 			clocks = <&sysctrl R9A06G032_CLK_UART7>, <&sysctrl R9A06G032_HCLK_UART7>;
 			clock-names = "baudclk", "apb_pclk";
+			dmas =  <&dmamux 4 0 0 0 20 1>,
+				<&dmamux 5 0 0 0 21 1>;
+			dma-names = "rx", "tx";
 			status = "disabled";
 		};
 
-- 
2.27.0


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

* Re: [PATCH v3 03/10] serial: 8250: dw: Change the quirks type to unsigned int
  2022-03-29 15:24 ` [PATCH v3 03/10] serial: 8250: dw: Change the quirks type to unsigned int Miquel Raynal
@ 2022-03-29 15:43   ` Andy Shevchenko
  2022-03-29 15:58   ` Geert Uytterhoeven
  1 sibling, 0 replies; 20+ messages in thread
From: Andy Shevchenko @ 2022-03-29 15:43 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby,
	linux-renesas-soc, linux-serial, Milan Stevanovic, Jimmy Lalande,
	Pascal Eberhard, Thomas Petazzoni, Herve Codina, Clement Leger

On Tue, Mar 29, 2022 at 05:24:23PM +0200, Miquel Raynal wrote:
> Unsigned int is better than unsigned long as its size does not change
> between setups and we don't really need this variable to be more than a
> few bits wide for now.
> 
> Suggested-by: Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

One tag is enough :-)

Looking into the following patch, I think you may squash this one into it,
just add an explanation in the commit message that you reduced variable for
quirks.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v3 05/10] serial: 8250: dw: Allow to use a fallback CPR value if not synthesized
  2022-03-29 15:24 ` [PATCH v3 05/10] serial: 8250: dw: Allow to use a fallback CPR value if not synthesized Miquel Raynal
@ 2022-03-29 15:49   ` Andy Shevchenko
  0 siblings, 0 replies; 20+ messages in thread
From: Andy Shevchenko @ 2022-03-29 15:49 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby,
	linux-renesas-soc, linux-serial, Milan Stevanovic, Jimmy Lalande,
	Pascal Eberhard, Thomas Petazzoni, Herve Codina, Clement Leger,
	Phil Edworthy

On Tue, Mar 29, 2022 at 05:24:25PM +0200, Miquel Raynal wrote:
> DW UART controllers can be synthesized without the CPR register.
> In this case, allow to the platform information to provide a CPR value.

> +	const struct dw8250_platform_data *pdata = device_get_match_data(p->dev);

Hmm... So, we will have two functions that do the same.
Perhaps you may store somewhere the pdata pointer (or contents) once
and call these functions at the time that the pdata is known to be set.
That's how usual pattern looks like. Calling device_get_match_data()
several times is unusual and potentially might be error prone.

...

>  	reg = dw8250_readl_ext(p, DW_UART_CPR);
> +	if (!reg) {

> +		if (pdata)
> +			reg = pdata->cpr;

If you store the content this becomes something like:

		reg = data->pdata.cpr;

But, please experiment a bit with it and choose the best option.

> +		dev_dbg(p->dev, "CPR is not available, using %x instead\n", reg);
> +	}

> +

No need of this blank line.

>  	if (!reg)
>  		return;

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v3 04/10] serial: 8250: dw: Create a more generic platform data structure
  2022-03-29 15:24 ` [PATCH v3 04/10] serial: 8250: dw: Create a more generic platform data structure Miquel Raynal
@ 2022-03-29 15:51   ` Andy Shevchenko
  0 siblings, 0 replies; 20+ messages in thread
From: Andy Shevchenko @ 2022-03-29 15:51 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby,
	linux-renesas-soc, linux-serial, Milan Stevanovic, Jimmy Lalande,
	Pascal Eberhard, Thomas Petazzoni, Herve Codina, Clement Leger,
	Emil Renner Berthing

On Tue, Mar 29, 2022 at 05:24:24PM +0200, Miquel Raynal wrote:
> Before adding more platform data information, let's turn the quirks
> information as being a member of a wider structure. More fields will be
> added later.

>  	struct device_node *np = p->dev->of_node;
> -	unsigned int quirks = (unsigned int)device_get_match_data(p->dev);
> +	const struct dw8250_platform_data *pdata = device_get_match_data(p->dev);
> +	unsigned int quirks = pdata ? pdata->quirks : 0;

I remember Greg is not fan of ternary operators. Taking into account my
suggestion in the next patch, I think this can simply become

	unsigned int quirks = data->pdata.quirks;

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v3 03/10] serial: 8250: dw: Change the quirks type to unsigned int
  2022-03-29 15:24 ` [PATCH v3 03/10] serial: 8250: dw: Change the quirks type to unsigned int Miquel Raynal
  2022-03-29 15:43   ` Andy Shevchenko
@ 2022-03-29 15:58   ` Geert Uytterhoeven
  2022-03-29 16:06     ` Miquel Raynal
  1 sibling, 1 reply; 20+ messages in thread
From: Geert Uytterhoeven @ 2022-03-29 15:58 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Magnus Damm, Greg Kroah-Hartman, Jiri Slaby, Andy Shevchenko,
	Linux-Renesas, open list:SERIAL DRIVERS, Milan Stevanovic,
	Jimmy Lalande, Pascal Eberhard, Thomas Petazzoni, Herve Codina,
	Clement Leger

Hi Miquel,

On Tue, Mar 29, 2022 at 5:24 PM Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> Unsigned int is better than unsigned long as its size does not change
> between setups and we don't really need this variable to be more than a
> few bits wide for now.
>
> Suggested-by: Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>

Thanks for your patch!

> --- a/drivers/tty/serial/8250/8250_dw.c
> +++ b/drivers/tty/serial/8250/8250_dw.c
> @@ -376,7 +376,7 @@ static bool dw8250_idma_filter(struct dma_chan *chan, void *param)
>  static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
>  {
>         struct device_node *np = p->dev->of_node;
> -       unsigned long quirks = (unsigned long)device_get_match_data(p->dev);
> +       unsigned int quirks = (unsigned int)device_get_match_data(p->dev);

"(uintptr_t)" (or "(unsigned long)" ;-), else you'll get a "cast from
pointer to integer of different size" warning on 64-bit builds.

>
>         if (np) {
>                 int id;

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

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

* Re: [PATCH v3 08/10] serial: 8250: dw: Add support for DMA flow controlling devices
  2022-03-29 15:24 ` [PATCH v3 08/10] serial: 8250: dw: Add support for DMA flow controlling devices Miquel Raynal
@ 2022-03-29 15:58   ` Andy Shevchenko
  0 siblings, 0 replies; 20+ messages in thread
From: Andy Shevchenko @ 2022-03-29 15:58 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby,
	linux-renesas-soc, linux-serial, Milan Stevanovic, Jimmy Lalande,
	Pascal Eberhard, Thomas Petazzoni, Herve Codina, Clement Leger,
	Phil Edworthy

On Tue, Mar 29, 2022 at 05:24:28PM +0200, Miquel Raynal wrote:
> From: Phil Edworthy <phil.edworthy@renesas.com>
> 
> DW based controllers like the one on Renesas RZ/N1 must be programmed as
> flow controllers when using DMA.
> 
> * Table 11.45 of the system manual, "Flow Control Combinations", states
>   that using UART with DMA requires setting the DMA in the peripheral
>   flow controller mode regardless of the direction.
> 
> * Chapter 11.6.1.3 of the system manual, "Basic Interface Definitions",
>   explains that the burst size in the above case must be configured in
>   the peripheral's register DEST/SRC_BURST_SIZE.
> 
> Experiments shown that upon Rx timeout, the DMA transaction needed to be
> manually cleared as well.

...

>  #define DW_UART_USR	0x1f /* UART Status Register */
> +#define DW_UART_DMASA	0xa8 /* DMA Software Ack */
> +#define RZN1_UART_TDMACR 0x10c /* DMA Control Register Transmit Mode */
> +#define RZN1_UART_RDMACR 0x110 /* DMA Control Register Receive Mode */

Yep!

Since it seems we may have a v4, I would add a blank line between Synopsys
and custom register groups.

...

>  #define DW_UART_QUIRK_OCTEON		BIT(0)
>  #define DW_UART_QUIRK_ARMADA_38X	BIT(1)
>  #define DW_UART_QUIRK_SKIP_SET_RATE	BIT(2)
> +#define DW_UART_QUIRK_IS_DMA_FLOW_CONTROLLER BIT(3)

Seems the last has no TAB in it. It may require to indent the above as well.
Alternatively you may rename FLOW_CONTROLLER --> FC and add a comment on top
to explain this.

...

> +	const struct dw8250_platform_data *pdata = device_get_match_data(p->dev);

Third one!

> +	/* Manually stop the Rx DMA transfer when acting as flow controller */
> +	if (up->dma && up->dma->rx_running && rx_timeout && pdata &&
> +	    pdata->quirks & DW_UART_QUIRK_IS_DMA_FLOW_CONTROLLER) {

For example,

	unsigned int quirks = data->pdata.quirks;

	if (up->dma && up->dma->rx_running && rx_timeout && quirks & DW_UART_QUIRK_IS_DMA_FC) {

(It's also fine to have that on one line)

> +		status = p->serial_in(p, UART_LSR);
> +		if (status & (UART_LSR_DR | UART_LSR_BI)) {
> +			writel(0, p->membase + RZN1_UART_RDMACR);
> +			writel(1, p->membase + DW_UART_DMASA);
> +		}
> +	}

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v3 09/10] serial: 8250: dw: Improve RZN1 support
  2022-03-29 15:24 ` [PATCH v3 09/10] serial: 8250: dw: Improve RZN1 support Miquel Raynal
@ 2022-03-29 16:00   ` Andy Shevchenko
  0 siblings, 0 replies; 20+ messages in thread
From: Andy Shevchenko @ 2022-03-29 16:00 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby,
	linux-renesas-soc, linux-serial, Milan Stevanovic, Jimmy Lalande,
	Pascal Eberhard, Thomas Petazzoni, Herve Codina, Clement Leger,
	Phil Edworthy

On Tue, Mar 29, 2022 at 05:24:29PM +0200, Miquel Raynal wrote:
> From: Phil Edworthy <phil.edworthy@renesas.com>
> 
> Renesas RZ/N1 SoC features a slightly modified DW UART.
> 
> On this SoC, the CPR register value is known but not synthetized in
> hardware. We hence need to provide a CPR value in the platform
> data. This version of the controller also relies on acting as flow
> controller when using DMA, so we need to provide the
> 'IS_DMA_FLOW_CONTROLLER' quirk.

...

> -	{ .compatible = "renesas,rzn1-uart" },
> +	{ .compatible = "renesas,rzn1-uart", .data = &dw8250_renesas_rzn1_data },

Btw, you may avoid if (pdata) checks if you add a stub in the first place here.
It will also make this patch shorter.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support
  2022-03-29 15:24 [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Miquel Raynal
                   ` (9 preceding siblings ...)
  2022-03-29 15:24 ` [PATCH v3 10/10] ARM: dts: r9a06g032: Fill the UART DMA properties Miquel Raynal
@ 2022-03-29 16:01 ` Andy Shevchenko
  2022-03-29 16:10   ` Miquel Raynal
  10 siblings, 1 reply; 20+ messages in thread
From: Andy Shevchenko @ 2022-03-29 16:01 UTC (permalink / raw)
  To: Miquel Raynal
  Cc: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby,
	linux-renesas-soc, linux-serial, Milan Stevanovic, Jimmy Lalande,
	Pascal Eberhard, Thomas Petazzoni, Herve Codina, Clement Leger

On Tue, Mar 29, 2022 at 05:24:20PM +0200, Miquel Raynal wrote:
> Hello,
> 
> Support for the RZN1 DMA engine allows us adapt a little bit the 8250 DW
> UART driver with to bring DMA support for this SoC.
> 
> This short series applies on top of the series bringing RZN1 DMA
> support, currently on its v5, see [1]. Technically speaking, only the DT
> patch needs to be applied after [1]. The other patches can come in at
> any moment, because if no "dmas" property is provided in the DT, DMA
> support will simply be ignored.
> 
> [1] https://lore.kernel.org/dmaengine/20220315191255.221473-1-miquel.raynal@bootlin.com/T/#m0ef3323abce3eec961e142bf2fb35e95b9045fc5

Thanks for a new version!

It becomes definitely closer to the good enough state.
Since I have comments and we still in the middle of the merge window
we have time to address them.

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v3 03/10] serial: 8250: dw: Change the quirks type to unsigned int
  2022-03-29 15:58   ` Geert Uytterhoeven
@ 2022-03-29 16:06     ` Miquel Raynal
  0 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2022-03-29 16:06 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Magnus Damm, Greg Kroah-Hartman, Jiri Slaby, Andy Shevchenko,
	Linux-Renesas, open list:SERIAL DRIVERS, Milan Stevanovic,
	Jimmy Lalande, Pascal Eberhard, Thomas Petazzoni, Herve Codina,
	Clement Leger

Hi Geert,

geert@linux-m68k.org wrote on Tue, 29 Mar 2022 17:58:40 +0200:

> Hi Miquel,
> 
> On Tue, Mar 29, 2022 at 5:24 PM Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> > Unsigned int is better than unsigned long as its size does not change
> > between setups and we don't really need this variable to be more than a
> > few bits wide for now.
> >
> > Suggested-by: Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>  
> 
> Thanks for your patch!
> 
> > --- a/drivers/tty/serial/8250/8250_dw.c
> > +++ b/drivers/tty/serial/8250/8250_dw.c
> > @@ -376,7 +376,7 @@ static bool dw8250_idma_filter(struct dma_chan *chan, void *param)
> >  static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
> >  {
> >         struct device_node *np = p->dev->of_node;
> > -       unsigned long quirks = (unsigned long)device_get_match_data(p->dev);
> > +       unsigned int quirks = (unsigned int)device_get_match_data(p->dev);  
> 
> "(uintptr_t)" (or "(unsigned long)" ;-), else you'll get a "cast from
> pointer to integer of different size" warning on 64-bit builds.

Actually as I'm changing that quirks entry from being the entire device
data to be a member of a wider structure, I'll change its type when
doing the switch to avoid such a warning.

Thanks,
Miquèl

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

* Re: [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support
  2022-03-29 16:01 ` [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Andy Shevchenko
@ 2022-03-29 16:10   ` Miquel Raynal
  0 siblings, 0 replies; 20+ messages in thread
From: Miquel Raynal @ 2022-03-29 16:10 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Geert Uytterhoeven, Magnus Damm, Greg Kroah-Hartman, Jiri Slaby,
	linux-renesas-soc, linux-serial, Milan Stevanovic, Jimmy Lalande,
	Pascal Eberhard, Thomas Petazzoni, Herve Codina, Clement Leger

Hi Andy,

andriy.shevchenko@linux.intel.com wrote on Tue, 29 Mar 2022 19:01:14
+0300:

> On Tue, Mar 29, 2022 at 05:24:20PM +0200, Miquel Raynal wrote:
> > Hello,
> > 
> > Support for the RZN1 DMA engine allows us adapt a little bit the 8250 DW
> > UART driver with to bring DMA support for this SoC.
> > 
> > This short series applies on top of the series bringing RZN1 DMA
> > support, currently on its v5, see [1]. Technically speaking, only the DT
> > patch needs to be applied after [1]. The other patches can come in at
> > any moment, because if no "dmas" property is provided in the DT, DMA
> > support will simply be ignored.
> > 
> > [1] https://lore.kernel.org/dmaengine/20220315191255.221473-1-miquel.raynal@bootlin.com/T/#m0ef3323abce3eec961e142bf2fb35e95b9045fc5  
> 
> Thanks for a new version!
> 
> It becomes definitely closer to the good enough state.
> Since I have comments and we still in the middle of the merge window
> we have time to address them.

Yes sure, thanks for your quick feedback. I'll propose an updated
version with:
- Empty pdata structures for all the compatibles (only one will remain
  at the end) in order to avoid the "if (pdata)" checks.
- Save the pdata pointer once for all and use derive it directly
  everywhere else.

BTW, you may probably send your Reviewed-by to the DMA series which was
sent a couple of weeks back if you don't have more comments on it?

Thanks,
Miquèl

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

end of thread, other threads:[~2022-03-29 16:10 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-29 15:24 [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Miquel Raynal
2022-03-29 15:24 ` [PATCH v3 01/10] serial: 8250: dw: Move the per-device structure Miquel Raynal
2022-03-29 15:24 ` [PATCH v3 02/10] serial: 8250: dw: Use the device API Miquel Raynal
2022-03-29 15:24 ` [PATCH v3 03/10] serial: 8250: dw: Change the quirks type to unsigned int Miquel Raynal
2022-03-29 15:43   ` Andy Shevchenko
2022-03-29 15:58   ` Geert Uytterhoeven
2022-03-29 16:06     ` Miquel Raynal
2022-03-29 15:24 ` [PATCH v3 04/10] serial: 8250: dw: Create a more generic platform data structure Miquel Raynal
2022-03-29 15:51   ` Andy Shevchenko
2022-03-29 15:24 ` [PATCH v3 05/10] serial: 8250: dw: Allow to use a fallback CPR value if not synthesized Miquel Raynal
2022-03-29 15:49   ` Andy Shevchenko
2022-03-29 15:24 ` [PATCH v3 06/10] serial: 8250: dma: Allow driver operations before starting DMA transfers Miquel Raynal
2022-03-29 15:24 ` [PATCH v3 07/10] serial: 8250: dw: Introduce an rx_timeout variable in the IRQ path Miquel Raynal
2022-03-29 15:24 ` [PATCH v3 08/10] serial: 8250: dw: Add support for DMA flow controlling devices Miquel Raynal
2022-03-29 15:58   ` Andy Shevchenko
2022-03-29 15:24 ` [PATCH v3 09/10] serial: 8250: dw: Improve RZN1 support Miquel Raynal
2022-03-29 16:00   ` Andy Shevchenko
2022-03-29 15:24 ` [PATCH v3 10/10] ARM: dts: r9a06g032: Fill the UART DMA properties Miquel Raynal
2022-03-29 16:01 ` [PATCH v3 00/10] serial: 8250: dw: RZN1 DMA support Andy Shevchenko
2022-03-29 16:10   ` Miquel Raynal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.