public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Angelo Dureghello <angelo@sysam.it>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 04/11] drivers: serial: mcfuart: add DT support
Date: Tue,  9 Oct 2018 23:43:06 +0200	[thread overview]
Message-ID: <20181009214313.27034-5-angelo@sysam.it> (raw)
In-Reply-To: <20181009214313.27034-1-angelo@sysam.it>

This patch adds devicetree support to the mcfuart.c driver
and removes non DM code.

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
---
Changes for v2:
- remove non DM code
---
 drivers/serial/mcfuart.c | 106 +++++++++++----------------------------
 1 file changed, 28 insertions(+), 78 deletions(-)

diff --git a/drivers/serial/mcfuart.c b/drivers/serial/mcfuart.c
index 1371049de2..066e5a18d8 100644
--- a/drivers/serial/mcfuart.c
+++ b/drivers/serial/mcfuart.c
@@ -5,6 +5,9 @@
  *
  * Modified to add device model (DM) support
  * (C) Copyright 2015  Angelo Dureghello <angelo@sysam.it>
+ *
+ * Modified to add DM and fdt support, removed non DM code
+ * (C) Copyright 2018  Angelo Dureghello <angelo@sysam.it>
  */
 
 /*
@@ -78,83 +81,6 @@ static void mcf_serial_setbrg_common(uart_t *uart, int baudrate)
 	writeb(UART_UCR_RX_ENABLED | UART_UCR_TX_ENABLED, &uart->ucr);
 }
 
-#ifndef CONFIG_DM_SERIAL
-
-static int mcf_serial_init(void)
-{
-	uart_t *uart_base;
-	int port_idx;
-
-	uart_base = (uart_t *)CONFIG_SYS_UART_BASE;
-	port_idx = CONFIG_SYS_UART_PORT;
-
-	return mcf_serial_init_common(uart_base, port_idx, gd->baudrate);
-}
-
-static void mcf_serial_putc(const char c)
-{
-	uart_t *uart = (uart_t *)CONFIG_SYS_UART_BASE;
-
-	if (c == '\n')
-		serial_putc('\r');
-
-	/* Wait for last character to go. */
-	while (!(readb(&uart->usr) & UART_USR_TXRDY))
-		;
-
-	writeb(c, &uart->utb);
-}
-
-static int mcf_serial_getc(void)
-{
-	uart_t *uart = (uart_t *)CONFIG_SYS_UART_BASE;
-
-	/* Wait for a character to arrive. */
-	while (!(readb(&uart->usr) & UART_USR_RXRDY))
-		;
-
-	return readb(&uart->urb);
-}
-
-static void mcf_serial_setbrg(void)
-{
-	uart_t *uart = (uart_t *)CONFIG_SYS_UART_BASE;
-
-	mcf_serial_setbrg_common(uart, gd->baudrate);
-}
-
-static int mcf_serial_tstc(void)
-{
-	uart_t *uart = (uart_t *)CONFIG_SYS_UART_BASE;
-
-	return readb(&uart->usr) & UART_USR_RXRDY;
-}
-
-static struct serial_device mcf_serial_drv = {
-	.name	= "mcf_serial",
-	.start	= mcf_serial_init,
-	.stop	= NULL,
-	.setbrg	= mcf_serial_setbrg,
-	.putc	= mcf_serial_putc,
-	.puts	= default_serial_puts,
-	.getc	= mcf_serial_getc,
-	.tstc	= mcf_serial_tstc,
-};
-
-void mcf_serial_initialize(void)
-{
-	serial_register(&mcf_serial_drv);
-}
-
-__weak struct serial_device *default_serial_console(void)
-{
-	return &mcf_serial_drv;
-}
-
-#endif
-
-#ifdef CONFIG_DM_SERIAL
-
 static int coldfire_serial_probe(struct udevice *dev)
 {
 	struct coldfire_serial_platdata *plat = dev->platdata;
@@ -212,6 +138,23 @@ static int coldfire_serial_pending(struct udevice *dev, bool input)
 	return 0;
 }
 
+static int coldfire_ofdata_to_platdata(struct udevice *dev)
+{
+	struct coldfire_serial_platdata *plat = dev_get_platdata(dev);
+	fdt_addr_t addr_base;
+
+	addr_base = devfdt_get_addr(dev);
+	if (addr_base == FDT_ADDR_T_NONE)
+		return -ENODEV;
+
+	plat->base = (uint32_t)addr_base;
+
+	plat->port = dev->seq;
+	plat->baudrate = gd->baudrate;
+
+	return 0;
+}
+
 static const struct dm_serial_ops coldfire_serial_ops = {
 	.putc = coldfire_serial_putc,
 	.pending = coldfire_serial_pending,
@@ -219,11 +162,18 @@ static const struct dm_serial_ops coldfire_serial_ops = {
 	.setbrg = coldfire_serial_setbrg,
 };
 
+static const struct udevice_id coldfire_serial_ids[] = {
+	{ .compatible = "fsl,mcf-uart" },
+	{ }
+};
+
 U_BOOT_DRIVER(serial_coldfire) = {
 	.name = "serial_coldfire",
 	.id = UCLASS_SERIAL,
+	.of_match = coldfire_serial_ids,
+	.ofdata_to_platdata = coldfire_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct coldfire_serial_platdata),
 	.probe = coldfire_serial_probe,
 	.ops = &coldfire_serial_ops,
 	.flags = DM_FLAG_PRE_RELOC,
 };
-#endif
-- 
2.19.1

  parent reply	other threads:[~2018-10-09 21:43 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-09 21:43 [U-Boot] [PATCH v2 00/11] m68k: initial devicetree support Angelo Dureghello
2018-10-09 21:43 ` [U-Boot] [PATCH v2 01/11] m68k: add basic set of devicetrees Angelo Dureghello
2018-10-10  5:49   ` Jagan Teki
2018-10-10  9:38     ` Angelo Dureghello
2018-10-09 21:43 ` [U-Boot] [PATCH v2 02/11] drivers: spi: cf_spi: add Kconfig option Angelo Dureghello
2018-10-10  5:51   ` Jagan Teki
2018-10-10  9:40     ` Angelo Dureghello
2018-10-09 21:43 ` [U-Boot] [PATCH v2 03/11] drivers: spi: cf_spi: migrate to DM and DT Angelo Dureghello
2018-10-10  5:58   ` Jagan Teki
2018-10-10  9:57     ` Angelo Dureghello
2018-10-09 21:43 ` Angelo Dureghello [this message]
2018-10-09 21:43 ` [U-Boot] [PATCH v2 05/11] drivers: serial: mcfuart: add Kconfig option Angelo Dureghello
2018-10-09 21:43 ` [U-Boot] [PATCH v2 06/11] m68k: architecture changes to support fdt Angelo Dureghello
2018-10-09 21:43 ` [U-Boot] [PATCH v2 07/11] m68k: add initial dts files for all m68k boards Angelo Dureghello
2018-10-09 21:43 ` [U-Boot] [PATCH v2 08/11] m68k: enabling long jumps on mcf54x5 SoCs Angelo Dureghello
2018-10-09 21:43 ` [U-Boot] [PATCH v2 09/11] configs: enable use of DT for all m68k boards Angelo Dureghello
2018-10-09 21:43 ` [U-Boot] [PATCH v2 10/11] configs: add DM_SPI config option Angelo Dureghello
2018-10-09 21:43 ` [U-Boot] [PATCH v2 11/11] configs: remove CONFIG_SYS_DSPI_XX references Angelo Dureghello

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=20181009214313.27034-5-angelo@sysam.it \
    --to=angelo@sysam.it \
    --cc=u-boot@lists.denx.de \
    /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