Re: sh-sci driver doesn't report actual baud rate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Violeta,

On 04/04/2015 09:54 AM, Violeta Menendez Gonzalez wrote:
> Hello everyone,
> 
> I'm testing UART with different custom baud rates on a renesas lager board that uses the sh-sci driver.
> 
> After discovering that TIOCSSERIAL is deprecated

ioctl(TIOCSSERIAL) is not deprecated but not every driver supports its
(full) functionality. Feel free to add that (missing) functionality to the
sh-sci driver.

> I found the way of doing it with TCSETS2, which seems to work. My problem comes when trying to confirm the speed that I've tried to set, it seems to set any speed I request, when it's obvious that some of those speeds are not even valid. The issue seems to be with set_termios(), the serial driver API does not allow the serial driver to return an error, it must make a best effort. But then when I ask back for the speed again it returns the speed I had requested, instead of the actual one.

Well, there are two issues here:
1) You need to set BOTHER in termios2.c_cflag like this:
	termios2.c_cflag &= CBAUD;
	termios2.c_cflag |= BOTHER;
   That disables nearest baud fitting in the serial core.

2) There's a limit to the baud resolution you can achieve
   Using the original 16550 as an example, which has a 1.843Mhz clock,
   the following baud rates are achievable:

divisor    baud rate
  11         10472
  12          9599
  13          8860

Faster uart clocks achieve smaller intervals but nowhere near +/-13 baud.

You could use the ->base_baud field obtained with ioctl(TIOCGSERIAL) to
determine the actual baud:

    div = round_nearest(base_baud / baud);
    actual = round_nearest(base_baud / div);

There's some complications with the sh-sci driver because it may be using
oversampling other than 16 (based on port type, which is also in TIOCGSERIAL),
but hopefully you get the general idea.

> So for example, when I run my code trying to set up a speed of 9587bps, I would expect it to actually set 9600, but when I ask for the speed back I still get 9587.
>
> Is this the normal/expected behaviour?

Serial drivers are notoriously bad at updating the termios with what is
actually set, and now the problem has become that userspace now relies
on serial drivers _not_ updating the termios.

For example, no driver I know of masks off CRTSCTS if not available.

Regards,
Peter Hurley
--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux