All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Sean Anderson <sean.anderson@seco.com>
Cc: Peter Korsgaard <peter.korsgaard@barco.com>,
	Peter Korsgaard <peter@korsgaard.com>,
	linux-serial@vger.kernel.org,
	Alexander Sverdlin <alexander.sverdlin@nokia.com>,
	Michal Simek <michal.simek@xilinx.com>
Subject: Re: [PATCH 4/5] tty: serial: uartlite: Initialize termios with fixed synthesis parameters
Date: Thu, 29 Jul 2021 17:02:50 +0200	[thread overview]
Message-ID: <YQLDGujm26qrtIsM@kroah.com> (raw)
In-Reply-To: <302ea0f9-6e61-ee8d-eb40-63f3bb81a278@seco.com>

On Mon, Jul 26, 2021 at 04:53:39PM -0400, Sean Anderson wrote:
> 
> 
> On 7/23/21 6:31 PM, Sean Anderson wrote:
> > This reads the various new devicetree parameters to discover how the
> > uart was configured when it was synthesized. Note that these properties
> > are fixed and undiscoverable. Once we have determined how the uart is
> > configured, we set the termios to let users know, and to initialize the
> > timeout to the correct value.
> > 
> > The defaults match ulite_console_setup. xlnx,use-parity,
> > xlnx,odd-parity, and xlnx,data-bits are optional since there were
> > in-tree users (and presumably out-of-tree users) who did not set them.
> > 
> > Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> > ---
> > 
> >   drivers/tty/serial/uartlite.c | 66 +++++++++++++++++++++++++++++++----
> >   1 file changed, 60 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
> > index f42ccc40ffa6..39c17ab206ca 100644
> > --- a/drivers/tty/serial/uartlite.c
> > +++ b/drivers/tty/serial/uartlite.c
> > @@ -60,9 +60,20 @@
> >   static struct uart_port *console_port;
> >   #endif
> > 
> > +/**
> > + * struct uartlite_data: Driver private data
> > + * reg_ops: Functions to read/write registers
> > + * clk: Our parent clock, if present
> > + * baud: The baud rate configured when this device was synthesized
> > + * parity: The parity settings, like for uart_set_options()
> > + * bits: The number of data bits
> > + */
> >   struct uartlite_data {
> >   	const struct uartlite_reg_ops *reg_ops;
> >   	struct clk *clk;
> > +	int baud;
> > +	int parity;
> > +	int bits;
> >   };
> > 
> >   struct uartlite_reg_ops {
> > @@ -652,6 +663,9 @@ static int ulite_assign(struct device *dev, int id, u32 base, int irq,
> >   	port->type = PORT_UNKNOWN;
> >   	port->line = id;
> >   	port->private_data = pdata;
> > +	/* Initialize the termios to what was configured at synthesis-time */
> > +	uart_set_options(port, NULL, pdata->baud, pdata->parity, pdata->bits,
> > +			 'n');
> 
> I did some testing today, and discovered that the termios are not set
> properly. I think I missed this the first time around because on
> Microblaze QEMU this UART is the console, and the baud etc. gets set
> properly because of stdout-path (or bootargs). However, uart_set_options
> doesn't actually do anything with the termios when co is NULL.
> 
> The initial termios are set up by tty_init_termios (called from
> tty_init_dev). They come from either tty->driver->init_termios, or from
> tty->driver->termios[idx]. There is only one init_termios per-driver,
> so we would need to have multiple drivers if we wanted to have multiple
> UARTs with different (e.g.) bauds.
> 
> The indexed termios are designed to keep the settings from the previous
> time the tty was opened. So I think (ab)using them is not too terrible,
> especially since we will only set them once. Unfortunately, we cannot
> use tty_save_termios to initialize the indexed termio, since the tty is
> not set until tty_port_open, which is called after tty_init_dev.
> 
> Based on this, I think the neatest cut would be something like
> 
> /* perhaps just do this in ulite_assign? */
> ulite_request_port () {
> 	/* ... */
> 	termios = &ulite_uart_driver.tty_driver->termios[port->line];
> 	termios = kzalloc(sizeof(*termios));
> 	if (!termios)
> 		/* ... */
> 	termios.c_cflags = /* ... */
> 	/* etc */
> }
> 
> Unfortunately, according to include/linux/serial_core.h, tty_driver is
> not supposed to be touched by the low-level driver. But I think we have
> a bit of an unusual case here with a device that can't change baud. If
> anyone has other suggestions, I'm all for them.

If a driver can not support changes in baud rates, then just ignore all
changes to baud rates as there will not be an issue for anyone :)

thanks,

greg k-h

  reply	other threads:[~2021-07-29 15:02 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-23 22:31 [PATCH 0/5] tty: serial: uartlite: Disable changing fixed parameters Sean Anderson
2021-07-23 22:31 ` [PATCH 1/5] dt-bindings: serial: uartlite: Convert to json-schema Sean Anderson
2021-07-23 22:31 ` [PATCH 2/5] dt-bindings: serial: uartlite: Add properties for synthesis-time parameters Sean Anderson
2021-07-26 12:30   ` Michal Simek
2021-07-26 15:16     ` Sean Anderson
2021-07-23 22:31 ` [PATCH 3/5] sh: j2: Update uartlite binding with data and parity properties Sean Anderson
2021-07-23 22:31 ` [PATCH 4/5] tty: serial: uartlite: Initialize termios with fixed synthesis parameters Sean Anderson
2021-07-26 20:53   ` Sean Anderson
2021-07-29 15:02     ` Greg Kroah-Hartman [this message]
2021-07-23 22:31 ` [PATCH 5/5] tty: serial: uartlite: Prevent changing fixed parameters Sean Anderson
2021-07-29 15:01   ` Greg Kroah-Hartman
2021-07-29 15:26     ` Sean Anderson
2021-07-29 15:32       ` Greg Kroah-Hartman
2021-07-29 15:43         ` Sean Anderson
2021-07-30  5:25           ` Greg Kroah-Hartman
2021-07-30 15:33             ` Sean Anderson
2021-08-09  8:58             ` Maarten Brock
2021-07-26 14:19 ` [PATCH 0/5] tty: serial: uartlite: Disable " Michal Simek

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=YQLDGujm26qrtIsM@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=alexander.sverdlin@nokia.com \
    --cc=linux-serial@vger.kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=peter.korsgaard@barco.com \
    --cc=peter@korsgaard.com \
    --cc=sean.anderson@seco.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.