public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Kuan-Wei Chiu <visitorckw@gmail.com>
To: Simon Glass <sjg@chromium.org>
Cc: alison.wang@nxp.com, angelo@kernel-space.org, trini@konsulko.com,
	me@ziyao.cc, daniel@0x0f.com, heinrich.schuchardt@canonical.com,
	jserv@ccns.ncku.edu.tw, eleanor15x@gmail.com,
	u-boot@lists.denx.de
Subject: Re: [PATCH v5 1/7] serial: Add Goldfish TTY driver
Date: Wed, 7 Jan 2026 03:25:50 +0800	[thread overview]
Message-ID: <aV1hvqrtZ-lPlrNj@google.com> (raw)
In-Reply-To: <CAFLszTg-nxHarYP8xGmGNxRwZTuRo7Pb7f1SHPn1C85p-Cbpxg@mail.gmail.com>

Hi Simon,

On Mon, Jan 05, 2026 at 04:30:28PM -0700, Simon Glass wrote:
> Hi Kuan-Wei,
> 
> On Mon, 5 Jan 2026 at 11:21, Kuan-Wei Chiu <visitorckw@gmail.com> wrote:
> >
> > Add support for the Google Goldfish TTY serial device. This virtual
> > device is commonly used in QEMU virtual machines (such as the m68k
> > virt machine) and Android emulators.
> >
> > The driver implements basic console output and input polling using the
> > Goldfish MMIO interface.
> >
> > Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
> > Reviewed-by: Yao Zi <me@ziyao.cc>
> > Tested-by: Daniel Palmer <daniel@0x0f.com>
> > Acked-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> > ---
> > Changes in v5:
> > - Rebase on u-boot/next branch.
> >
> >  MAINTAINERS                      |   6 ++
> >  drivers/serial/Kconfig           |   8 +++
> >  drivers/serial/Makefile          |   1 +
> >  drivers/serial/serial_goldfish.c | 109 +++++++++++++++++++++++++++++++
> >  include/goldfish_tty.h           |  18 +++++
> >  5 files changed, 142 insertions(+)
> >  create mode 100644 drivers/serial/serial_goldfish.c
> >  create mode 100644 include/goldfish_tty.h
> >
> 
> Reviewed-by: Simon Glass <simon.glass@canonical.com>

Thanks for your review!

> 
> One thought below.
> 
> > diff --git a/MAINTAINERS b/MAINTAINERS
> > index 27ce73d83f4..8f884ff495a 100644
> > --- a/MAINTAINERS
> > +++ b/MAINTAINERS
> > @@ -1260,6 +1260,12 @@ S:       Maintained
> >  F:     drivers/misc/gsc.c
> >  F:     include/gsc.h
> >
> > +GOLDFISH SERIAL DRIVER
> > +M:     Kuan-Wei Chiu <visitorckw@gmail.com>
> > +S:     Maintained
> > +F:     drivers/serial/serial_goldfish.c
> > +F:     include/goldfish_tty.h
> > +
> >  INTERCONNECT:
> >  M:     Neil Armstrong <neil.armstrong@linaro.org>
> >  S:     Maintained
> > diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
> > index 371d7aa5bba..b84cb9ec781 100644
> > --- a/drivers/serial/Kconfig
> > +++ b/drivers/serial/Kconfig
> > @@ -1193,4 +1193,12 @@ config SYS_SDMR
> >         depends on MPC8XX_CONS
> >         default 0x0
> >
> > +config SERIAL_GOLDFISH
> > +       bool "Goldfish TTY support"
> > +       depends on DM_SERIAL
> > +       help
> > +         Select this to enable support for the Goldfish TTY serial port.
> > +         This virtual device is commonly used by QEMU virtual machines
> > +         (e.g. m68k virt) for console output.
> > +
> >  endif
> > diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
> > index 8eaae62b0fc..fe8d23be512 100644
> > --- a/drivers/serial/Makefile
> > +++ b/drivers/serial/Makefile
> > @@ -63,3 +63,4 @@ obj-$(CONFIG_XTENSA_SEMIHOSTING_SERIAL) += serial_xtensa_semihosting.o
> >  obj-$(CONFIG_S5P4418_PL011_SERIAL) += serial_s5p4418_pl011.o
> >
> >  obj-$(CONFIG_UART4_SERIAL) += serial_adi_uart4.o
> > +obj-$(CONFIG_SERIAL_GOLDFISH) += serial_goldfish.o
> > diff --git a/drivers/serial/serial_goldfish.c b/drivers/serial/serial_goldfish.c
> > new file mode 100644
> > index 00000000000..278d0cf3e0d
> > --- /dev/null
> > +++ b/drivers/serial/serial_goldfish.c
> > @@ -0,0 +1,109 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +/*
> > + * Copyright (C) 2025, Kuan-Wei Chiu <visitorckw@gmail.com>
> > + * Goldfish TTY driver for U-Boot
> > + */
> > +
> > +#include <asm/io.h>
> > +#include <dm.h>
> > +#include <goldfish_tty.h>
> > +#include <linux/types.h>
> > +#include <mapmem.h>
> > +#include <serial.h>
> > +
> > +/* Goldfish TTY Register Offsets */
> > +#define GOLDFISH_TTY_PUT_CHAR       0x00
> > +#define GOLDFISH_TTY_BYTES_READY    0x04
> > +#define GOLDFISH_TTY_CMD            0x08
> > +#define GOLDFISH_TTY_DATA_PTR       0x10
> > +#define GOLDFISH_TTY_DATA_LEN       0x14
> > +#define GOLDFISH_TTY_DATA_PTR_HIGH  0x18
> > +#define GOLDFISH_TTY_VERSION        0x20
> > +
> > +/* Commands */
> > +#define CMD_WRITE_BUFFER   2
> > +#define CMD_READ_BUFFER    3
> > +
> > +struct goldfish_tty_priv {
> > +       void __iomem *base;
> > +       u8 rx_buf;
> > +};
> > +
> > +static int goldfish_serial_getc(struct udevice *dev)
> > +{
> > +       struct goldfish_tty_priv *priv = dev_get_priv(dev);
> > +       unsigned long paddr;
> > +       u32 count;
> > +
> > +       count = __raw_readl(priv->base + GOLDFISH_TTY_BYTES_READY);
> > +       if (count == 0)
> > +               return -EAGAIN;
> > +
> > +       paddr = virt_to_phys((void *)&priv->rx_buf);
> > +
> > +       __raw_writel(0, priv->base + GOLDFISH_TTY_DATA_PTR_HIGH);
> > +       __raw_writel(paddr, priv->base + GOLDFISH_TTY_DATA_PTR);
> > +       __raw_writel(1, priv->base + GOLDFISH_TTY_DATA_LEN);
> > +       __raw_writel(CMD_READ_BUFFER, priv->base + GOLDFISH_TTY_CMD);
> > +
> > +       return priv->rx_buf;
> > +}
> > +
> > +static int goldfish_serial_putc(struct udevice *dev, const char ch)
> > +{
> > +       struct goldfish_tty_priv *priv = dev_get_priv(dev);
> > +
> > +       __raw_writel(ch, priv->base + GOLDFISH_TTY_PUT_CHAR);
> > +
> > +       return 0;
> > +}
> > +
> > +static int goldfish_serial_pending(struct udevice *dev, bool input)
> > +{
> > +       struct goldfish_tty_priv *priv = dev_get_priv(dev);
> > +
> > +       if (input)
> > +               return __raw_readl(priv->base + GOLDFISH_TTY_BYTES_READY);
> > +
> > +       return 0;
> > +}
> > +
> > +static int goldfish_serial_probe(struct udevice *dev)
> > +{
> > +       struct goldfish_tty_priv *priv = dev_get_priv(dev);
> > +       struct goldfish_tty_plat *plat = dev_get_plat(dev);
> > +       fdt_addr_t addr;
> > +
> > +       addr = dev_read_addr(dev);
> > +       if (addr != FDT_ADDR_T_NONE) {
> > +               priv->base = map_sysmem(addr, 0x1000);
> > +       } else {
> > +               plat = dev_get_plat(dev);
> > +               if (!plat)
> > +                       return -EINVAL;
> > +               priv->base = plat->base;
> > +       }
> > +
> > +       return 0;
> > +}
> 
> Strictly speaking, reading the devicetree should be done in the
> of_to_plat() method. So you would read the base address there.
> 
> Then probe() would convert that to a pointer (I suggest the same 'reg'
> for registers, but it isn't that important).

I will move the device tree reading to of_to_plat() and rename the
platform data member to reg (using phys_addr_t). The probe() function
will then handle the map_sysmem() conversion. I will also apply this
same pattern to the timer and rtc drivers.

Regards,
Kuan-Wei

> 
> > +
> > +static const struct dm_serial_ops goldfish_serial_ops = {
> > +       .putc = goldfish_serial_putc,
> > +       .pending = goldfish_serial_pending,
> > +       .getc = goldfish_serial_getc,
> > +};
> > +
> > +static const struct udevice_id goldfish_serial_ids[] = {
> > +       { .compatible = "google,goldfish-tty" },
> > +       { }
> > +};
> > +
> > +U_BOOT_DRIVER(serial_goldfish) = {
> > +       .name   = "serial_goldfish",
> > +       .id     = UCLASS_SERIAL,
> > +       .of_match = goldfish_serial_ids,
> > +       .probe  = goldfish_serial_probe,
> > +       .ops    = &goldfish_serial_ops,
> > +       .priv_auto = sizeof(struct goldfish_tty_priv),
> > +       .flags  = DM_FLAG_PRE_RELOC,
> > +};
> > diff --git a/include/goldfish_tty.h b/include/goldfish_tty.h
> > new file mode 100644
> > index 00000000000..8777da4942d
> > --- /dev/null
> > +++ b/include/goldfish_tty.h
> > @@ -0,0 +1,18 @@
> > +/* SPDX-License-Identifier: GPL-2.0-or-later */
> > +/*
> > + * Copyright (C) 2025, Kuan-Wei Chiu <visitorckw@gmail.com>
> > + */
> > +
> > +#ifndef _GOLDFISH_TTY_H_
> > +#define _GOLDFISH_TTY_H_
> > +
> > +#include <linux/types.h>
> > +
> > +/* Platform data for the Goldfish TTY driver
> > + * Used to pass hardware base address from Board to Driver
> > + */
> > +struct goldfish_tty_plat {
> > +       void __iomem *base;
> > +};
> > +
> > +#endif /* _GOLDFISH_TTY_H_ */
> > --
> > 2.52.0.358.g0dd7633a29-goog
> >
> 
> Regards,
> Simon

  reply	other threads:[~2026-01-06 19:28 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05 16:52 [PATCH v5 0/7] m68k: Add support for QEMU virt machine Kuan-Wei Chiu
2026-01-05 16:52 ` [PATCH v5 1/7] serial: Add Goldfish TTY driver Kuan-Wei Chiu
2026-01-05 23:30   ` Simon Glass
2026-01-06 19:25     ` Kuan-Wei Chiu [this message]
2026-01-07 10:59   ` Angelo Dureghello
2026-01-05 16:52 ` [PATCH v5 2/7] timer: Add Goldfish timer driver Kuan-Wei Chiu
2026-01-05 23:30   ` Simon Glass
2026-01-07 11:07   ` Angelo Dureghello
2026-01-05 16:52 ` [PATCH v5 3/7] rtc: goldfish: Support platform data for non-DT probing Kuan-Wei Chiu
2026-01-05 23:30   ` Simon Glass
2026-01-05 23:47     ` Tom Rini
2026-01-06  0:58       ` Daniel Palmer
2026-01-06  1:49         ` Tom Rini
2026-01-06 16:22       ` Simon Glass
2026-01-06 16:58         ` Tom Rini
2026-01-05 16:52 ` [PATCH v5 4/7] m68k: Add support for M68040 CPU Kuan-Wei Chiu
2026-01-05 23:30   ` Simon Glass
2026-01-06 19:38     ` Kuan-Wei Chiu
2026-01-05 16:52 ` [PATCH v5 5/7] board: Add QEMU m68k virt board support Kuan-Wei Chiu
2026-01-05 23:30   ` Simon Glass
2026-01-06 19:22     ` Kuan-Wei Chiu
2026-01-05 16:52 ` [PATCH v5 6/7] CI: Add test jobs for QEMU m68k virt machine Kuan-Wei Chiu
2026-01-05 23:30   ` Simon Glass
2026-01-05 16:52 ` [PATCH v5 7/7] MAINTAINERS: Update m68k entry Kuan-Wei Chiu
2026-01-07 14:37   ` Angelo Dureghello
2026-01-08 18:52   ` Maciej W. Rozycki

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=aV1hvqrtZ-lPlrNj@google.com \
    --to=visitorckw@gmail.com \
    --cc=alison.wang@nxp.com \
    --cc=angelo@kernel-space.org \
    --cc=daniel@0x0f.com \
    --cc=eleanor15x@gmail.com \
    --cc=heinrich.schuchardt@canonical.com \
    --cc=jserv@ccns.ncku.edu.tw \
    --cc=me@ziyao.cc \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --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