mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Antony Pavlov <antonynpavlov@gmail.com>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2 05/11] serial: add litex UART driver
Date: Fri, 7 May 2021 15:02:26 +0300	[thread overview]
Message-ID: <20210507150226.83b72d0056e42883842ca398@gmail.com> (raw)
In-Reply-To: <c2ca4628-d34f-f9b6-4f9b-5348c57526a6@pengutronix.de>

On Fri, 7 May 2021 13:45:57 +0200
Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:

> Hi,
> 
> On 07.05.21 00:08, Antony Pavlov wrote:
> > Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> > ---
> >  drivers/serial/Makefile       |  1 +
> >  drivers/serial/serial_litex.c | 96 +++++++++++++++++++++++++++++++++++
> >  2 files changed, 97 insertions(+)
> > 
> > diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
> > index 5120b17376..45055371ea 100644
> > --- a/drivers/serial/Makefile
> > +++ b/drivers/serial/Makefile
> > @@ -24,3 +24,4 @@ obj-$(CONFIG_DRIVER_SERIAL_DIGIC)		+= serial_digic.o
> >  obj-$(CONFIG_DRIVER_SERIAL_LPUART)		+= serial_lpuart.o
> >  obj-$(CONFIG_VIRTIO_CONSOLE)			+= virtio_console.o
> >  obj-$(CONFIG_SERIAL_SIFIVE)			+= serial_sifive.o
> > +obj-$(CONFIG_SOC_LITEX)				+= serial_litex.o
> > diff --git a/drivers/serial/serial_litex.c b/drivers/serial/serial_litex.c
> > new file mode 100644
> > index 0000000000..8562a45ecc
> > --- /dev/null
> > +++ b/drivers/serial/serial_litex.c
> > @@ -0,0 +1,96 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright (C) 2019 Antony Pavlov <antonynpavlov@gmail.com>
> > + *
> > + */
> > +
> > +#include <common.h>
> > +#include <init.h>
> > +#include <io.h>
> > +
> > +#define UART_RXTX	0x00
> > +#define UART_TXFULL	0x04
> > +#define UART_RXEMPTY	0x08
> > +#define UART_EV_PENDING	0x10
> > +#define  UART_EV_RX	(1 << 1)
> > +
> > +static inline uint32_t litex_serial_readb(struct console_device *cdev,
> > +						uint32_t offset)
> > +{
> > +	void __iomem *base = cdev->dev->priv;
> > +
> > +	return readb(base + offset);
> > +}
> > +
> > +static inline void litex_serial_writeb(struct console_device *cdev,
> > +					uint32_t value, uint32_t offset)
> > +{
> > +	void __iomem *base = cdev->dev->priv;
> > +
> > +	writeb(value, base + offset);
> > +}
> > +
> > +static void litex_serial_putc(struct console_device *cdev, char c)
> > +{
> > +	while (litex_serial_readb(cdev, UART_TXFULL))
> > +		;
> > +
> > +	litex_serial_writeb(cdev, c, UART_RXTX);
> > +}
> > +
> > +static int litex_serial_getc(struct console_device *cdev)
> > +{
> > +	int c;
> > +
> > +	while (litex_serial_readb(cdev, UART_RXEMPTY))
> > +		;
> > +
> > +	c = litex_serial_readb(cdev, UART_RXTX);
> > +
> > +	/* refresh UART_RXEMPTY by writing UART_EV_RX to UART_EV_PENDING */
> > +	litex_serial_writeb(cdev, UART_EV_RX, UART_EV_PENDING);
> > +
> > +	return c;
> > +}
> > +
> > +static int litex_serial_tstc(struct console_device *cdev)
> > +{
> > +	return !litex_serial_readb(cdev, UART_RXEMPTY);
> > +}
> > +
> > +static int litex_serial_probe(struct device_d *dev)
> > +{
> > +	struct resource *iores;
> > +	struct console_device *cdev;
> > +
> > +	cdev = xzalloc(sizeof(struct console_device));
> > +	iores = dev_request_mem_resource(dev, 0);
> > +	if (IS_ERR(iores))
> > +		return PTR_ERR(iores);
> > +
> > +	dev->priv = IOMEM(iores->start);
> > +	cdev->dev = dev;
> > +	cdev->tstc = &litex_serial_tstc;
> > +	cdev->putc = &litex_serial_putc;
> > +	cdev->getc = &litex_serial_getc;
> > +	cdev->setbrg = NULL;
> 
> Does the IP only output a fixed baudrate/configuration?

Yes, this IP works at fixed baudrate.

Baudrate is selected during FPGA bitstream compilation,
e.g. see https://github.com/litex-hub/linux-on-litex-vexriscv/commit/0b133cc3

At the moment there is a problem with this fixed speed port: loady command does not work.

> > +
> > +	console_register(cdev);
> > +
> > +	return 0;
> > +}
> > +
> > +static __maybe_unused struct of_device_id litex_serial_dt_ids[] = {
> > +	{
> > +		.compatible = "litex,uart",
> > +	}, {
> > +		/* sentinel */
> > +	}
> > +};
> > +
> > +static struct driver_d litex_serial_driver = {
> > +	.name  = "litex-uart",
> > +	.probe = litex_serial_probe,
> > +	.of_compatible = DRV_OF_COMPAT(litex_serial_dt_ids),
> > +};
> > +console_platform_driver(litex_serial_driver);
> > 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
> 31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |


-- 
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2021-05-07 12:04 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-06 22:08 [PATCH v2 00/11] RISC-V: add LiteX SoC support; resurrect nmon Antony Pavlov
2021-05-06 22:08 ` [PATCH v2 01/11] clocksource: timer-riscv: select CSR from device tree Antony Pavlov
2021-05-07 11:34   ` Ahmad Fatoum
2021-05-07 17:41     ` Antony Pavlov
2021-05-07 18:05       ` Ahmad Fatoum
2021-05-06 22:08 ` [PATCH v2 02/11] RISC-V: make RISCV_SBI and RISCV_M_MODE explicitly mutually exclusive Antony Pavlov
2021-05-07 11:42   ` Ahmad Fatoum
2021-05-07 14:25     ` Antony Pavlov
2021-05-07 14:44       ` Ahmad Fatoum
2021-05-07 17:52         ` Antony Pavlov
2021-05-07 18:08           ` Ahmad Fatoum
2021-05-07 18:36             ` Antony Pavlov
2021-05-06 22:08 ` [PATCH v2 03/11] RISC-V: make it possible to run nmon from PBL C code Antony Pavlov
2021-05-06 22:08 ` [PATCH v2 04/11] RISC-V: boards: erizo: make it possible to use nmon Antony Pavlov
2021-05-06 22:08 ` [PATCH v2 05/11] serial: add litex UART driver Antony Pavlov
2021-05-07 11:45   ` Ahmad Fatoum
2021-05-07 12:02     ` Antony Pavlov [this message]
2021-05-06 22:08 ` [PATCH v2 06/11] gpio: add driver for 74xx-ICs with MMIO access Antony Pavlov
2021-05-06 22:08 ` [PATCH v2 07/11] spi: add litex spiflash driver Antony Pavlov
2021-05-06 22:08 ` [PATCH v2 08/11] net: add LiteEth driver Antony Pavlov
2021-05-06 22:08 ` [PATCH v2 09/11] RISC-V: add LiteX SoC and linux-on-litex-vexriscv support Antony Pavlov
2021-05-06 22:08 ` [PATCH v2 10/11] RISC-V: add litex_linux_defconfig Antony Pavlov
2021-05-06 22:08 ` [PATCH v2 11/11] RISC-V: make it possible to build RV32I multi-image with DEBUG_LL=n Antony Pavlov
2021-05-07 10:27   ` Ahmad Fatoum
2021-05-07 10:23 ` [PATCH v2 00/11] RISC-V: add LiteX SoC support; resurrect nmon Ahmad Fatoum
2021-05-07 11:12   ` Antony Pavlov

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=20210507150226.83b72d0056e42883842ca398@gmail.com \
    --to=antonynpavlov@gmail.com \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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