* [PATCH RFC] serial: mxs-auart: fix baud rate range
@ 2015-08-10 12:12 ` Stefan Wahren
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Wahren @ 2015-08-10 12:12 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Jiri Slaby, Janusz Uzycki, Fabio Estevam, jbe, linux-serial,
linux-kernel, Stefan Wahren
Currently mxs-auart doesn't care correctly about the baud rate divisor.
According to reference manual the baud rate divisor must be between
0x000000EC and 0x003FFFC0. So calculate the possible baud rate range
and use it for uart_get_baud_rate().
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
drivers/tty/serial/mxs-auart.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
Here is a userspace application to test the new baud rate range:
https://gist.github.com/lategoodbye/f2d76134aa6c404cd92c
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index 13cf773..afe617c 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -659,7 +659,7 @@ static void mxs_auart_settermios(struct uart_port *u,
{
struct mxs_auart_port *s = to_auart_port(u);
u32 bm, ctrl, ctrl2, div;
- unsigned int cflag, baud;
+ unsigned int cflag, baud, baud_min, baud_max;
cflag = termios->c_cflag;
@@ -752,7 +752,9 @@ static void mxs_auart_settermios(struct uart_port *u,
}
/* set baud rate */
- baud = uart_get_baud_rate(u, termios, old, 0, u->uartclk);
+ baud_min = u->uartclk * 32 / 0x3fffc0;
+ baud_max = u->uartclk * 32 / 0xec;
+ baud = uart_get_baud_rate(u, termios, old, baud_min, baud_max);
div = u->uartclk * 32 / baud;
ctrl |= AUART_LINECTRL_BAUD_DIVFRAC(div & 0x3F);
ctrl |= AUART_LINECTRL_BAUD_DIVINT(div >> 6);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH RFC] serial: mxs-auart: fix baud rate range
@ 2015-08-10 12:12 ` Stefan Wahren
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Wahren @ 2015-08-10 12:12 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Jiri Slaby, Janusz Uzycki, Fabio Estevam, jbe, linux-serial,
linux-kernel, Stefan Wahren
Currently mxs-auart doesn't care correctly about the baud rate divisor.
According to reference manual the baud rate divisor must be between
0x000000EC and 0x003FFFC0. So calculate the possible baud rate range
and use it for uart_get_baud_rate().
Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
drivers/tty/serial/mxs-auart.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
Here is a userspace application to test the new baud rate range:
https://gist.github.com/lategoodbye/f2d76134aa6c404cd92c
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index 13cf773..afe617c 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -659,7 +659,7 @@ static void mxs_auart_settermios(struct uart_port *u,
{
struct mxs_auart_port *s = to_auart_port(u);
u32 bm, ctrl, ctrl2, div;
- unsigned int cflag, baud;
+ unsigned int cflag, baud, baud_min, baud_max;
cflag = termios->c_cflag;
@@ -752,7 +752,9 @@ static void mxs_auart_settermios(struct uart_port *u,
}
/* set baud rate */
- baud = uart_get_baud_rate(u, termios, old, 0, u->uartclk);
+ baud_min = u->uartclk * 32 / 0x3fffc0;
+ baud_max = u->uartclk * 32 / 0xec;
+ baud = uart_get_baud_rate(u, termios, old, baud_min, baud_max);
div = u->uartclk * 32 / baud;
ctrl |= AUART_LINECTRL_BAUD_DIVFRAC(div & 0x3F);
ctrl |= AUART_LINECTRL_BAUD_DIVINT(div >> 6);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH RFC] serial: mxs-auart: fix baud rate range
2015-08-10 12:12 ` Stefan Wahren
(?)
@ 2015-08-10 12:22 ` Fabio Estevam
2015-08-10 17:01 ` Janusz Użycki
-1 siblings, 1 reply; 5+ messages in thread
From: Fabio Estevam @ 2015-08-10 12:22 UTC (permalink / raw)
To: Stefan Wahren
Cc: Greg Kroah-Hartman, Jiri Slaby, Janusz Uzycki, Fabio Estevam,
Juergen Beisert, linux-serial@vger.kernel.org, linux-kernel
On Mon, Aug 10, 2015 at 9:12 AM, Stefan Wahren <stefan.wahren@i2se.com> wrote:
> /* set baud rate */
> - baud = uart_get_baud_rate(u, termios, old, 0, u->uartclk);
> + baud_min = u->uartclk * 32 / 0x3fffc0;
> + baud_max = u->uartclk * 32 / 0xec;
> + baud = uart_get_baud_rate(u, termios, old, baud_min, baud_max);
Looks good. It would be nice to replace 0x3fffc0 and 0xec with defines though.
Regards,
Fabio Estevam
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RFC] serial: mxs-auart: fix baud rate range
2015-08-10 12:22 ` Fabio Estevam
@ 2015-08-10 17:01 ` Janusz Użycki
2015-08-11 7:14 ` Stefan Wahren
0 siblings, 1 reply; 5+ messages in thread
From: Janusz Użycki @ 2015-08-10 17:01 UTC (permalink / raw)
To: Fabio Estevam, Stefan Wahren
Cc: Greg Kroah-Hartman, Jiri Slaby, Janusz Uzycki, Fabio Estevam,
Juergen Beisert, linux-serial@vger.kernel.org, linux-kernel
W dniu 2015-08-10 o 14:22, Fabio Estevam pisze:
> On Mon, Aug 10, 2015 at 9:12 AM, Stefan Wahren <stefan.wahren@i2se.com> wrote:
>
>> /* set baud rate */
>> - baud = uart_get_baud_rate(u, termios, old, 0, u->uartclk);
>> + baud_min = u->uartclk * 32 / 0x3fffc0;
>> + baud_max = u->uartclk * 32 / 0xec;
>> + baud = uart_get_baud_rate(u, termios, old, baud_min, baud_max);
> Looks good. It would be nice to replace 0x3fffc0 and 0xec with defines though.
I agree with Fabio.
In addition let's look at the example for uartclk = 24MHz:
baud_max = 3,254,237.29 => will be rounded down to 3,254,237bauds and it
is OK
baud_min = 183.1 => will be rounded to 183 bauds. To avoid div=0x400971
it should be 184
so DIV_ROUND_UP() macro could be used.
best regards
Janusz
>
> Regards,
>
> Fabio Estevam
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RFC] serial: mxs-auart: fix baud rate range
2015-08-10 17:01 ` Janusz Użycki
@ 2015-08-11 7:14 ` Stefan Wahren
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Wahren @ 2015-08-11 7:14 UTC (permalink / raw)
To: Fabio Estevam, Janusz Użycki
Cc: linux-serial@vger.kernel.org, Jiri Slaby, Greg Kroah-Hartman,
linux-kernel, Fabio Estevam, Juergen Beisert
Hi Janusz,
> Janusz Użycki <j.uzycki@elpromaelectronics.com> hat am 10. August 2015 um
> 19:01 geschrieben:
>
>
>
>
> W dniu 2015-08-10 o 14:22, Fabio Estevam pisze:
> > On Mon, Aug 10, 2015 at 9:12 AM, Stefan Wahren <stefan.wahren@i2se.com>
> > wrote:
> >
> >> /* set baud rate */
> >> - baud = uart_get_baud_rate(u, termios, old, 0, u->uartclk);
> >> + baud_min = u->uartclk * 32 / 0x3fffc0;
> >> + baud_max = u->uartclk * 32 / 0xec;
> >> + baud = uart_get_baud_rate(u, termios, old, baud_min, baud_max);
> > Looks good. It would be nice to replace 0x3fffc0 and 0xec with defines
> > though.
>
> I agree with Fabio.
i will name them AUART_LINECTRL_BAUD_DIV_MIN and AUART_LINECTRL_BAUD_DIV_MAX.
>
> In addition let's look at the example for uartclk = 24MHz:
> baud_max = 3,254,237.29 => will be rounded down to 3,254,237bauds and it
> is OK
> baud_min = 183.1 => will be rounded to 183 bauds. To avoid div=0x400971
> it should be 184
> so DIV_ROUND_UP() macro could be used.
Thanks for pointing out. I will fix that.
Best regards
Stefan
>
> best regards
> Janusz
>
> >
> > Regards,
> >
> > Fabio Estevam
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-08-11 7:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-10 12:12 [PATCH RFC] serial: mxs-auart: fix baud rate range Stefan Wahren
2015-08-10 12:12 ` Stefan Wahren
2015-08-10 12:22 ` Fabio Estevam
2015-08-10 17:01 ` Janusz Użycki
2015-08-11 7:14 ` Stefan Wahren
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.