linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Emil Renner Berthing <kernel@esmil.dk>
To: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Emil Renner Berthing <kernel@esmil.dk>,
	Linux-Renesas <linux-renesas-soc@vger.kernel.org>,
	Magnus Damm <magnus.damm@gmail.com>,
	Gareth Williams <gareth.williams.jx@renesas.com>,
	Phil Edworthy <phil.edworthy@renesas.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	"open list:SERIAL DRIVERS" <linux-serial@vger.kernel.org>,
	Milan Stevanovic <milan.stevanovic@se.com>,
	Jimmy Lalande <jimmy.lalande@se.com>,
	Pascal Eberhard <pascal.eberhard@se.com>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Herve Codina <herve.codina@bootlin.com>,
	Clement Leger <clement.leger@bootlin.com>,
	Geert Uytterhoeven <geert@linux-m68k.org>
Subject: [PATCH] serial: 8250_dw: Use device tree match data
Date: Fri, 11 Mar 2022 15:48:14 +0100	[thread overview]
Message-ID: <20220311144814.21944-1-kernel@esmil.dk> (raw)
In-Reply-To: <20220311105934.5827d0d6@xps13>

..rather than multiple calls to of_device_is_compatible().

Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
---

Hi Miquel,

> > > > --- a/drivers/tty/serial/8250/8250_dma.c
> > > > +++ b/drivers/tty/serial/8250/8250_dma.c =20
> > > =20
> > > > @@ -501,6 +589,8 @@ static int dw8250_probe(struct platform_device *p=
> dev)
> > > >                 data->msr_mask_off |=3D UART_MSR_TERI;
> > > >         }
> > > >
> > > > +       data->is_rzn1 =3D of_device_is_compatible(dev->of_node, "rene=
> sas,rzn1-uart"); =20
> > >
> > > Explicit checks for compatible values are frowned upon if you have
> > > a match table.
> > > Please handle this through of_device.data, cfr. the various quirks. =20
> >=20
> > Oops, these are not yet upstream, but present in my tree due to including
> > support for StarLight, cfr.
> > https://github.com/esmil/linux/commits/visionfive/drivers/tty/serial/8250=
> /8250_dw.c
> 
> Oh thanks for pointing it! Too bad that these quirks were not
> introduced inside a wider structure, I think it's always a must even if
> there is only one parameter there. Anyway, I'll introduce a wider
> specific structure and use it.

For reference this is the patch I wrote for the StarFive JH7100 tree.
Feel free to use it or do something better as you see fit.

/Emil

 drivers/tty/serial/8250/8250_dw.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index 1769808031c5..f564a019a7be 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -37,6 +37,11 @@
 /* DesignWare specific register fields */
 #define DW_UART_MCR_SIRE		BIT(6)
 
+/* 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)
+
 struct dw8250_data {
 	struct dw8250_port_data	data;
 
@@ -389,6 +394,7 @@ static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
 	struct device_node *np = p->dev->of_node;
 
 	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 */
@@ -396,7 +402,7 @@ static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
 		if (id >= 0)
 			p->line = id;
 #ifdef CONFIG_64BIT
-		if (of_device_is_compatible(np, "cavium,octeon-3860-uart")) {
+		if (quirks & DW_UART_QUIRK_OCTEON) {
 			p->serial_in = dw8250_serial_inq;
 			p->serial_out = dw8250_serial_outq;
 			p->flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_FIXED_TYPE;
@@ -412,9 +418,9 @@ static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
 			p->serial_out = dw8250_serial_out32be;
 		}
 
-		if (of_device_is_compatible(np, "marvell,armada-38x-uart"))
+		if (quirks & DW_UART_QUIRK_ARMADA_38X)
 			p->serial_out = dw8250_serial_out38x;
-		if (of_device_is_compatible(np, "starfive,jh7100-uart"))
+		if (quirks & DW_UART_QUIRK_SKIP_SET_RATE)
 			p->set_termios = dw8250_do_set_termios;
 
 	} else if (acpi_dev_present("APMC0D08", NULL, -1)) {
@@ -695,10 +701,10 @@ static const struct dev_pm_ops dw8250_pm_ops = {
 
 static const struct of_device_id dw8250_of_match[] = {
 	{ .compatible = "snps,dw-apb-uart" },
-	{ .compatible = "cavium,octeon-3860-uart" },
-	{ .compatible = "marvell,armada-38x-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 = "renesas,rzn1-uart" },
-	{ .compatible = "starfive,jh7100-uart" },
+	{ .compatible = "starfive,jh7100-uart",    .data = (void *)DW_UART_QUIRK_SKIP_SET_RATE },
 	{ /* Sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, dw8250_of_match);
-- 
2.35.1


  reply	other threads:[~2022-03-11 14:49 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-10 16:16 [PATCH 0/7] RZN1 UART DMA support Miquel Raynal
2022-03-10 16:16 ` [PATCH 1/7] serial: 8250_dma: Use ->tx_dma function pointer to start next DMA Miquel Raynal
2022-03-10 17:59   ` Andy Shevchenko
2022-03-10 16:16 ` [PATCH 2/7] serial: 8250_dw: Move the per-device structure Miquel Raynal
2022-03-10 18:01   ` Andy Shevchenko
2022-03-10 16:16 ` [PATCH 3/7] serial: 8250_dw: Use a fallback CPR value if not synthesized Miquel Raynal
2022-03-10 18:02   ` Andy Shevchenko
2022-03-10 19:01     ` Miquel Raynal
2022-03-11 17:05       ` Andy Shevchenko
2022-03-10 16:16 ` [PATCH 4/7] serial: 8250_dw: Provide the RZN1 CPR register value Miquel Raynal
2022-03-10 16:16 ` [PATCH 5/7] serial: 8250_dw: Add a dma_capable bit to the platform data Miquel Raynal
2022-03-10 18:06   ` Andy Shevchenko
2022-03-10 19:13     ` Miquel Raynal
2022-03-11 17:09       ` Andy Shevchenko
2022-03-10 16:16 ` [PATCH 6/7] serial: 8250_dw: Add support for RZ/N1 DMA Miquel Raynal
2022-03-10 18:25   ` Andy Shevchenko
2022-03-10 19:27     ` Miquel Raynal
2022-03-11 17:14       ` Andy Shevchenko
2022-03-11  9:39   ` Geert Uytterhoeven
2022-03-11  9:51     ` Geert Uytterhoeven
2022-03-11  9:59       ` Miquel Raynal
2022-03-11 14:48         ` Emil Renner Berthing [this message]
2022-03-11 17:27           ` [PATCH] serial: 8250_dw: Use device tree match data Andy Shevchenko
2022-03-16 14:40           ` Miquel Raynal
2022-03-10 16:16 ` [PATCH 7/7] ARM: dts: r9a06g032: Fill the UART DMA properties Miquel Raynal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220311144814.21944-1-kernel@esmil.dk \
    --to=kernel@esmil.dk \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=clement.leger@bootlin.com \
    --cc=gareth.williams.jx@renesas.com \
    --cc=geert@linux-m68k.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=herve.codina@bootlin.com \
    --cc=jimmy.lalande@se.com \
    --cc=jirislaby@kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=milan.stevanovic@se.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=pascal.eberhard@se.com \
    --cc=phil.edworthy@renesas.com \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).