public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: John Linn <john.linn@xilinx.com>
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: Re: [PATCH] tty/serial: add support for Xilinx PS UART
Date: Tue, 19 Apr 2011 22:15:30 +0100	[thread overview]
Message-ID: <20110419221530.7370d013@lxorguk.ukuu.org.uk> (raw)
In-Reply-To: <e35578a9-909d-4594-bbe4-41d89b5f9b3e@VA3EHSMHS014.ehs.local>

On Tue, 19 Apr 2011 14:14:52 -0600
John Linn <john.linn@xilinx.com> wrote:

> The Xilinx PS Uart is used on the new ARM based SoC. This
> UART is not compatible with others such that a seperate
> driver is required.

Joyous. I wish people would standardise.

> +		 213 = /dev/ttyPS0		Xilinx PS serial port 0
> +		 214 = /dev/ttyPS1		Xilinx PS serial port 1
> +		 215 = /dev/ttyPS2		Xilinx PS serial port 2
> +		 216 = /dev/ttyPS3		Xilinx PS serial port 3

Is there a specific reason you need fixed minor numbers ? If not please
use a dynamic range and keep Linus happy.

> +/**
> + * xuartps_isr - Interrupt handler
> + * @irq: Irq number
> + * @dev_id: Id of the port
> + *
> + * Returns IRQHANDLED
> + **/
> +static irqreturn_t xuartps_isr(int irq, void *dev_id)
> +{
> +	struct uart_port *port = (struct uart_port *)dev_id;
> +	struct tty_struct *tty = port->state->port.tty;
> +	unsigned long flags;
> +	unsigned int isrstatus, numbytes;
> +	unsigned int data;
> +	char status = TTY_NORMAL;
> +
> +	spin_lock_irqsave(&port->lock, flags);

The ttys are refcounting now and your locking subtly wrong if you want to
avoid it (you lookup port-> stuff before you lock it)

The best way to do this is

	tty = tty_port_tty_get(&port->state->port);

	/* Returns a tty with reference or NULL */

	Do stuff

	tty_kref_put(tty);



> +static void xuartps_set_termios(struct uart_port *port,
> +				struct ktermios *termios, struct ktermios *old)
> +{

> +	/* Min baud rate = 6bps and Max Baud Rate is 10Mbps for 100Mhz clk */
> +	baud = uart_get_baud_rate(port, termios, old, 0, 460800);
> +	xuartps_set_baud_rate(port, baud);

So why pass 460800 ?

> +	if (termios->c_iflag & INPCK)
> +		port->read_status_mask |= XUARTPS_IXR_PARITY |
> +		XUARTPS_IXR_FRAMING;
> +
> +	if (termios->c_iflag & IGNPAR)
> +		port->ignore_status_mask |= XUARTPS_IXR_PARITY |
> +			XUARTPS_IXR_FRAMING | XUARTPS_IXR_OVERRUN;
> +
> +	/* ignore all characters if CREAD is not set */
> +	if ((termios->c_cflag & CREAD) == 0)
> +		port->ignore_status_mask |= XUARTPS_IXR_RXTRIG |
> +			XUARTPS_IXR_TOUT | XUARTPS_IXR_PARITY |
> +			XUARTPS_IXR_FRAMING | XUARTPS_IXR_OVERRUN;
> +
> +	mode_reg = xuartps_readl(XUARTPS_MR_OFFSET);
> +
> +	/* Handling Data Size */
> +	switch (termios->c_cflag & CSIZE) {
> +	case CS6:
> +		cval |= XUARTPS_MR_CHARLEN_6_BIT;
> +		break;
> +	case CS7:
> +		cval |= XUARTPS_MR_CHARLEN_7_BIT;
> +		break;
> +	default:
> +	case CS8:
> +		cval |= XUARTPS_MR_CHARLEN_8_BIT;
> +		break;

You need to clear/set appropriately any flags for hardware requests you
cannot meet. So your default should be

	termios->c_cflag &= ~CSIZE;
	termios->c_cflag |= CS8;

to rewrite CS5

And set the baud rate (see 8250.c for an example). Note that the helper
functions know about mapping slight errors so if you are asked for 9600
and the hardware does 9575 it will report B9600 as you'd expect not do
something crazy.

> +	xuartps_set_baud_rate(port, 9600);

This seems a bit odd in the startup or is there a hardware need to do
this and then fix the rate ? Ditto some of the others


Otherwise looks fine.

Alan

  reply	other threads:[~2011-04-19 21:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-19 20:14 [PATCH] tty/serial: add support for Xilinx PS UART John Linn
2011-04-19 21:15 ` Alan Cox [this message]
2011-04-19 21:51   ` John Linn
2011-04-20  9:25     ` Alan Cox
2011-04-20 13:43       ` John Linn
2011-04-19 22:22   ` John Linn
2011-04-19 23:21     ` Greg KH
2011-04-19 23:39       ` John Linn
2011-04-19 23:42         ` Greg KH
2011-04-19 23:47           ` John Linn
2011-04-20  9:39         ` Alan Cox
2011-04-20 15:19   ` John Linn
2011-04-20 15:35     ` Alan Cox

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=20110419221530.7370d013@lxorguk.ukuu.org.uk \
    --to=alan@lxorguk.ukuu.org.uk \
    --cc=john.linn@xilinx.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.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