All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yao Zi <me@ziyao.cc>
To: Kuan-Wei Chiu <visitorckw@gmail.com>,
	alison.wang@nxp.com, angelo@kernel-space.org
Cc: trini@konsulko.com, daniel@0x0f.com, jserv@ccns.ncku.edu.tw,
	eleanor15x@gmail.com, u-boot@lists.denx.de
Subject: Re: [PATCH v2 1/4] serial: Add Goldfish TTY driver
Date: Sat, 27 Dec 2025 02:07:47 +0000	[thread overview]
Message-ID: <aU8_VIK_oTHY2RTF@pie> (raw)
In-Reply-To: <20251226175400.1154417-2-visitorckw@gmail.com>

On Fri, Dec 26, 2025 at 05:53:57PM +0000, Kuan-Wei Chiu 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>
> ---
> Changes in v2:
> - Update SPDX license identifier to GPL-2.0-or-later.
> - Sort header inclusions alphabetically.
> - Move RX buffer into goldfish_tty_priv instead of using a static buffer.
> - Make sure getc only read a single byte at a time.
> 
>  MAINTAINERS                      |   6 ++
>  drivers/serial/Kconfig           |   8 +++
>  drivers/serial/Makefile          |   1 +
>  drivers/serial/serial_goldfish.c | 104 +++++++++++++++++++++++++++++++
>  include/goldfish_tty.h           |  18 ++++++
>  5 files changed, 137 insertions(+)
>  create mode 100644 drivers/serial/serial_goldfish.c
>  create mode 100644 include/goldfish_tty.h

...

> diff --git a/drivers/serial/serial_goldfish.c b/drivers/serial/serial_goldfish.c
> new file mode 100644
> index 00000000000..ce5bff6bf4c
> --- /dev/null
> +++ b/drivers/serial/serial_goldfish.c
> @@ -0,0 +1,104 @@
> +// 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 <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 base = (unsigned long)priv->base;
> +	unsigned long paddr;
> +	u32 count;
> +
> +	count = __raw_readl((void *)(base + GOLDFISH_TTY_BYTES_READY));

I think it's okay to do pointer arithmetic directly against priv->base
in GNU C, right? In which case void * is treated like char *.

If I'm correct, variable base could be dropped, and we could avoid some
casts here and below.

> +	if (count == 0)
> +		return -EAGAIN;
> +
> +	paddr = virt_to_phys((void *)&priv->rx_buf);
> +
> +	__raw_writel(0, (void *)(base + GOLDFISH_TTY_DATA_PTR_HIGH));
> +	__raw_writel(paddr, (void *)(base + GOLDFISH_TTY_DATA_PTR));
> +	__raw_writel(1, (void *)(base + GOLDFISH_TTY_DATA_LEN));
> +
> +	__raw_writel(CMD_READ_BUFFER, (void *)(base + GOLDFISH_TTY_CMD));
> +
> +	return priv->rx_buf;
> +}

Regards,
Yao Zi

  reply	other threads:[~2025-12-27  2:08 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-26 17:53 [PATCH v2 0/4] m68k: Add support for QEMU virt machine Kuan-Wei Chiu
2025-12-26 17:53 ` [PATCH v2 1/4] serial: Add Goldfish TTY driver Kuan-Wei Chiu
2025-12-27  2:07   ` Yao Zi [this message]
2025-12-27 14:06     ` Kuan-Wei Chiu
2025-12-26 17:53 ` [PATCH v2 2/4] m68k: Add support for M68040 CPU Kuan-Wei Chiu
2025-12-28  1:28   ` Daniel Palmer
2025-12-28 19:29     ` Kuan-Wei Chiu
2025-12-29  1:54       ` Daniel Palmer
2025-12-29 13:27         ` Kuan-Wei Chiu
2025-12-26 17:53 ` [PATCH v2 3/4] board: Add QEMU m68k virt board support Kuan-Wei Chiu
2025-12-28  1:16   ` Daniel Palmer
2025-12-28 19:13     ` Kuan-Wei Chiu
2025-12-29  1:42       ` Daniel Palmer
2025-12-29 13:44         ` Kuan-Wei Chiu
2025-12-31  3:20           ` Daniel Palmer
2025-12-26 17:54 ` [PATCH v2 4/4] CI: Add test jobs for QEMU m68k virt machine Kuan-Wei Chiu
2025-12-26 18:09   ` Tom Rini
2025-12-26 18:57     ` Kuan-Wei Chiu
2025-12-26 18:59       ` Tom Rini

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=aU8_VIK_oTHY2RTF@pie \
    --to=me@ziyao.cc \
    --cc=alison.wang@nxp.com \
    --cc=angelo@kernel-space.org \
    --cc=daniel@0x0f.com \
    --cc=eleanor15x@gmail.com \
    --cc=jserv@ccns.ncku.edu.tw \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=visitorckw@gmail.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 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.