2009-09-30 16:19:42

by Breno Leitao

[permalink] [raw]
Subject: [PATCH] jsm: fixing termios structure to be compatible with stty application

Currently stty returns "unable to perform all requested operations",
when it changes the speed of a jsm device.
It was happening because c_ispeed and c_ospeed were not set properly.
This patch just set them, so that when stty compare the requested
and the new mode(struct termios), they are the same.

Signed-off-by: Breno Leitão <[email protected]>
---
drivers/serial/jsm/jsm_tty.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/serial/jsm/jsm_tty.c b/drivers/serial/jsm/jsm_tty.c
index 00f4577..dd1ed76 100644
--- a/drivers/serial/jsm/jsm_tty.c
+++ b/drivers/serial/jsm/jsm_tty.c
@@ -321,6 +321,10 @@ static void jsm_tty_set_termios(struct uart_port *port,

channel->ch_bd->bd_ops->param(channel);
jsm_carrier(channel);
+
+ termios->c_ispeed = termios->c_cflag & CBAUD;
+ termios->c_ospeed = termios->c_cflag & CBAUD;
+
spin_unlock_irqrestore(&port->lock, lock_flags);
}

--
1.6.0.2


2009-09-30 20:30:26

by Alan

[permalink] [raw]
Subject: Re: [PATCH] jsm: fixing termios structure to be compatible with stty application

> +
> + termios->c_ispeed = termios->c_cflag & CBAUD;
> + termios->c_ospeed = termios->c_cflag & CBAUD;
> +

NAK

termios->c_ispeed/ospeed are the actual baud rates not bit encodings, and
are used for devices that support arbitary speeds

Use

tty_termios_encode_baudrate(termios, ispeed, ospeed);

where ispeed/ospeed are actual input and output baud.

It does all the hard work and knows about

- keeping requests for traditional style B38400 type requests in their
native form (so a request for 38400 that comes out at 38100 will still
get encoded as B38400)
- Encoding arbitary rates using BOTHER
- Handling platforms that haven't been updated properly.


The patch you posted is a nonsense patch so if it helps it might be worth
looking harder as to why..

Alan

2009-10-01 20:34:16

by Breno Leitao

[permalink] [raw]
Subject: Re: [PATCH] jsm: fixing termios structure to be compatible with stty application

Alan Cox wrote:
> NAK
>
> termios->c_ispeed/ospeed are the actual baud rates not bit encodings
Well, c_flag & CBAUD is the baud rate encoded in the Bfoo format.

> Use
>
> tty_termios_encode_baudrate(termios, ispeed, ospeed);

Well, let me explain you what I want to do.
Actually stty.c source code do:

tcsetattr (STDIN_FILENO, TCSADRAIN, &mode)
tcgetattr (STDIN_FILENO, &new_mode)
...
if (memcmp (&mode, &new_mode, sizeof (mode)) != 0)
error (EXIT_FAILURE, 0,....)

When I run stty -F /dev/ttyn0 speed 9600, the mode structure is different
from new_mode, causing that error.
Debugging those structure, I found that ispeed and ospeed were not set in the
Bfoo format, as expected, since mode->[o|i]speed are set in Bfoo format.

Hence, I just assigned ospeed and ispeed with the requested speed in Bfoo
format (c_flag & CBAUD).

I also tested the tty_termios_encode_baud_rate(), and it will basically do what
I did:

termios->c_ispeed = ibaud;
termios->c_ospeed = obaud;

Thanks for the review, and sorry if I missed the point completely.
Breno

2009-10-01 21:09:25

by Alan

[permalink] [raw]
Subject: Re: [PATCH] jsm: fixing termios structure to be compatible with stty application

> Hence, I just assigned ospeed and ispeed with the requested speed in Bfoo
> format (c_flag & CBAUD).

The kernel ospeed and ispeed are not in Bfoo format, they are actual bit
rates. (I've no idea what glibc does, last time I checked it didn't even
support 2007 era Linux speed setting properly so apps still have to use
ioctls directly for them)

>
> I also tested the tty_termios_encode_baud_rate(), and it will basically do what
> I did:
>
> termios->c_ispeed = ibaud;
> termios->c_ospeed = obaud;
>
> Thanks for the review, and sorry if I missed the point completely.

ibaud != Bfoo