public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
* Fwd: [PULL REQUEST] Tweak to support 1Mbaud and similar baudrates that require Mode16 instead of Mode13
       [not found] <CAOmKuSpRJhBibSDxTFCH157-XokhaFhvQ-gYxKZe+PfzokaBoA@mail.gmail.com>
@ 2012-11-27 21:35 ` Alexey Pelykh
  2012-11-27 21:46   ` Alan Cox
  2012-11-27 21:56   ` Fwd: " Alexey Pelykh
  0 siblings, 2 replies; 8+ messages in thread
From: Alexey Pelykh @ 2012-11-27 21:35 UTC (permalink / raw)
  To: Alan Cox; +Cc: linux-serial

Hello everyone,

Original table in OMAP TRM named "UART Mode Baud Rates, Divisor
Values, and Error Rates" determines modes not for all common baud
rates. E.g. for 1000000 baud rate mode should be 16x, but according to
that table it's determined as 13x. According to current implementation
of mode
divisor selection, after requesting 1000000 baudrate from driver,
later one will configure chip to use MODE13 divisor. Assuming 48Mhz as
common UART clock speed, MODE13 divisor will effectively give 1230769
baudrate, what is quite far from desired 1000000 baudrate. While with
MODE16 divisor, chip will produce exact 1000000 baudrate.

In old driver that served UART devices (8250.c and serial_core.c) this
divisor could have been configured by user-space program, but in
omap_serial.c driver implementation this ability was not implemented
(afaik, by design) thus disallowing proper usage of MODE16-compatible
baudrates.

Best regards,
Alexey Pelykh

The following changes since commit 77b67063bb6bce6d475e910d3b886a606d0d91f7:

  Linux 3.7-rc5 (2012-11-11 13:44:33 +0100)

are available in the git repository at:

  git://github.com/alexey-pelykh/linux.git omap_serial_mode_fix

for you to fetch changes up to cf827bb4057fdcdaeac20b95b01c29c068109185:

  Tweak to support 1Mbaud and similar baudrates that require Mode16
instead of Mode13 (2012-11-12 19:29:27 +0200)

----------------------------------------------------------------
Alexey Pelykh (1):
      Tweak to support 1Mbaud and similar baudrates that require
Mode16 instead of Mode13

 drivers/tty/serial/omap-serial.c |   38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PULL REQUEST] Tweak to support 1Mbaud and similar baudrates that require Mode16 instead of Mode13
  2012-11-27 21:35 ` Fwd: [PULL REQUEST] Tweak to support 1Mbaud and similar baudrates that require Mode16 instead of Mode13 Alexey Pelykh
@ 2012-11-27 21:46   ` Alan Cox
  2012-11-27 21:56   ` Fwd: " Alexey Pelykh
  1 sibling, 0 replies; 8+ messages in thread
From: Alan Cox @ 2012-11-27 21:46 UTC (permalink / raw)
  To: Alexey Pelykh; +Cc: linux-serial

I am not going to go rummaging around in git repositories for patches.
Please post it to the list.

Alan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Fwd: [PULL REQUEST] Tweak to support 1Mbaud and similar baudrates that require Mode16 instead of Mode13
  2012-11-27 21:35 ` Fwd: [PULL REQUEST] Tweak to support 1Mbaud and similar baudrates that require Mode16 instead of Mode13 Alexey Pelykh
  2012-11-27 21:46   ` Alan Cox
@ 2012-11-27 21:56   ` Alexey Pelykh
  2012-11-27 23:00     ` Alan Cox
  2012-11-28  0:42     ` Fwd: " Greg KH
  1 sibling, 2 replies; 8+ messages in thread
From: Alexey Pelykh @ 2012-11-27 21:56 UTC (permalink / raw)
  To: linux-serial

Hello everyone,

Original table in OMAP TRM named "UART Mode Baud Rates, Divisor
Values, and Error Rates" determines modes not for all common baud
rates. E.g. for 1000000 baud rate mode should be 16x, but according to
that table it's determined as 13x. According to current implementation
of mode
divisor selection, after requesting 1000000 baudrate from driver,
later one will configure chip to use MODE13 divisor. Assuming 48Mhz as
common UART clock speed, MODE13 divisor will effectively give 1230769
baudrate, what is quite far from desired 1000000 baudrate. While with
MODE16 divisor, chip will produce exact 1000000 baudrate.

In old driver that served UART devices (8250.c and serial_core.c) this
divisor could have been configured by user-space program, but in
omap_serial.c driver implementation this ability was not implemented
(afaik, by design) thus disallowing proper usage of MODE16-compatible
baudrates.

Best regards,
Alexey Pelykh

The following changes since commit 77b67063bb6bce6d475e910d3b886a606d0d91f7:

  Linux 3.7-rc5 (2012-11-11 13:44:33 +0100)

are available in the git repository at:

  git://github.com/alexey-pelykh/linux.git omap_serial_mode_fix

for you to fetch changes up to cf827bb4057fdcdaeac20b95b01c29c068109185:

  Tweak to support 1Mbaud and similar baudrates that require Mode16
instead of Mode13 (2012-11-12 19:29:27 +0200)

----------------------------------------------------------------
Alexey Pelykh (1):
      Tweak to support 1Mbaud and similar baudrates that require
Mode16 instead of Mode13

 drivers/tty/serial/omap-serial.c |   38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)


diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 6d3d26a..6d567dd 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -182,24 +182,42 @@ static void serial_omap_enable_wakeup(struct
uart_omap_port *up, bool enable)
 }

 /*
+ * serial_omap_baud_is_mode16 - check if baud rate is MODE16X
+ * @port: uart port info
+ * @baud: baudrate for which mode needs to be determined
+ *
+ * Returns true if baud rate is MODE16X and false if MODE13X
+ * Original table in OMAP TRM named "UART Mode Baud Rates, Divisor Values,
+ * and Error Rates" determines modes not for all common baud rates.
+ * E.g. for 1000000 baud rate mode must be 16x, but according to that
+ * table it's determined as 13x.
+ */
+static bool
+serial_omap_baud_is_mode16(struct uart_port *port, unsigned int baud)
+{
+       unsigned int n13 = port->uartclk / (13 * baud);
+       unsigned int n16 = port->uartclk / (16 * baud);
+       int baudAbsDiff13 = baud - (port->uartclk / (13 * n13));
+       int baudAbsDiff16 = baud - (port->uartclk / (16 * n16));
+       if(baudAbsDiff13 < 0)
+               baudAbsDiff13 = -baudAbsDiff13;
+       if(baudAbsDiff16 < 0)
+               baudAbsDiff16 = -baudAbsDiff16;
+
+       return (baudAbsDiff13 > baudAbsDiff16);
+}
+
+/*
  * serial_omap_get_divisor - calculate divisor value
  * @port: uart port info
  * @baud: baudrate for which divisor needs to be calculated.
- *
- * We have written our own function to get the divisor so as to support
- * 13x mode. 3Mbps Baudrate as an different divisor.
- * Reference OMAP TRM Chapter 17:
- * Table 17-1. UART Mode Baud Rates, Divisor Values, and Error Rates
- * referring to oversampling - divisor value
- * baudrate 460,800 to 3,686,400 all have divisor 13
- * except 3,000,000 which has divisor value 16
  */
 static unsigned int
 serial_omap_get_divisor(struct uart_port *port, unsigned int baud)
 {
        unsigned int divisor;

-       if (baud > OMAP_MODE13X_SPEED && baud != 3000000)
+       if (!serial_omap_baud_is_mode16(port, baud))
                divisor = 13;
        else
                divisor = 16;
@@ -893,7 +911,7 @@ serial_omap_set_termios(struct uart_port *port,
struct ktermios *termios,
        serial_out(up, UART_EFR, up->efr);
        serial_out(up, UART_LCR, cval);

-       if (baud > 230400 && baud != 3000000)
+       if (!serial_omap_baud_is_mode16(port, baud))
                up->mdr1 = UART_OMAP_MDR1_13X_MODE;
        else
                up->mdr1 = UART_OMAP_MDR1_16X_MODE;

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PULL REQUEST] Tweak to support 1Mbaud and similar baudrates that require Mode16 instead of Mode13
  2012-11-27 21:56   ` Fwd: " Alexey Pelykh
@ 2012-11-27 23:00     ` Alan Cox
  2012-11-28  0:42     ` Fwd: " Greg KH
  1 sibling, 0 replies; 8+ messages in thread
From: Alan Cox @ 2012-11-27 23:00 UTC (permalink / raw)
  To: Alexey Pelykh; +Cc: linux-serial

> In old driver that served UART devices (8250.c and serial_core.c) this
> divisor could have been configured by user-space program, but in
> omap_serial.c driver implementation this ability was not implemented
> (afaik, by design) thus disallowing proper usage of MODE16-compatible
> baudrates.

Yes in the ideal case the kernel should manage should things.

Looks fine to me from a tty perspective (style wise one might quibble
about baudAbsDiff but I really don;t care 8))

Acked-by: Alan Cox <alan@linux.intel.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fwd: [PULL REQUEST] Tweak to support 1Mbaud and similar baudrates that require Mode16 instead of Mode13
  2012-11-27 21:56   ` Fwd: " Alexey Pelykh
  2012-11-27 23:00     ` Alan Cox
@ 2012-11-28  0:42     ` Greg KH
  2012-11-28  9:05       ` Alexey Pelykh
  1 sibling, 1 reply; 8+ messages in thread
From: Greg KH @ 2012-11-28  0:42 UTC (permalink / raw)
  To: Alexey Pelykh; +Cc: linux-serial

On Tue, Nov 27, 2012 at 11:56:06PM +0200, Alexey Pelykh wrote:
> Hello everyone,
> 
> Original table in OMAP TRM named "UART Mode Baud Rates, Divisor
> Values, and Error Rates" determines modes not for all common baud
> rates. E.g. for 1000000 baud rate mode should be 16x, but according to
> that table it's determined as 13x. According to current implementation
> of mode
> divisor selection, after requesting 1000000 baudrate from driver,
> later one will configure chip to use MODE13 divisor. Assuming 48Mhz as
> common UART clock speed, MODE13 divisor will effectively give 1230769
> baudrate, what is quite far from desired 1000000 baudrate. While with
> MODE16 divisor, chip will produce exact 1000000 baudrate.
> 
> In old driver that served UART devices (8250.c and serial_core.c) this
> divisor could have been configured by user-space program, but in
> omap_serial.c driver implementation this ability was not implemented
> (afaik, by design) thus disallowing proper usage of MODE16-compatible
> baudrates.
> 
> Best regards,
> Alexey Pelykh
> 
> The following changes since commit 77b67063bb6bce6d475e910d3b886a606d0d91f7:
> 
>   Linux 3.7-rc5 (2012-11-11 13:44:33 +0100)
> 
> are available in the git repository at:
> 
>   git://github.com/alexey-pelykh/linux.git omap_serial_mode_fix
> 
> for you to fetch changes up to cf827bb4057fdcdaeac20b95b01c29c068109185:
> 
>   Tweak to support 1Mbaud and similar baudrates that require Mode16
> instead of Mode13 (2012-11-12 19:29:27 +0200)

Sorry, I can't take a git pull request for a single patch, please just
send it in an email (the patch that is), with the correct signed-off-by:
information, as described in Documentation/SubmittingPatches, and I will
be glad to queue it up.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fwd: [PULL REQUEST] Tweak to support 1Mbaud and similar baudrates that require Mode16 instead of Mode13
  2012-11-28  0:42     ` Fwd: " Greg KH
@ 2012-11-28  9:05       ` Alexey Pelykh
  2012-11-28 17:25         ` Greg KH
  0 siblings, 1 reply; 8+ messages in thread
From: Alexey Pelykh @ 2012-11-28  9:05 UTC (permalink / raw)
  To: Greg KH, Alan Cox; +Cc: linux-serial

Original table in OMAP TRM named "UART Mode Baud Rates, Divisor
Values, and Error Rates" determines modes not for all common baud
rates. E.g. for 1000000 baud rate mode should be 16x, but according to
that table it's determined as 13x. According to current implementation
of mode
divisor selection, after requesting 1000000 baudrate from driver,
later one will configure chip to use MODE13 divisor. Assuming 48Mhz as
common UART clock speed, MODE13 divisor will effectively give 1230769
baudrate, what is quite far from desired 1000000 baudrate. While with
MODE16 divisor, chip will produce exact 1000000 baudrate.

In old driver that served UART devices (8250.c and serial_core.c) this
divisor could have been configured by user-space program, but in
omap_serial.c driver implementation this ability was not implemented
(afaik, by design) thus disallowing proper usage of MODE16-compatible
baudrates.

Changes: I've fixed styling errors using ./scripts/checkpatch.pl

Signed-off-by: Alexey Pelykh <alexey.pelykh@gmail.com>

The following changes since commit 77b67063bb6bce6d475e910d3b886a606d0d91f7:

  Linux 3.7-rc5 (2012-11-11 13:44:33 +0100)

are available in the git repository at:

  git://github.com/alexey-pelykh/linux.git omap_serial_mode_fix

for you to fetch changes up to cf827bb4057fdcdaeac20b95b01c29c068109185:

  Tweak to support 1Mbaud and similar baudrates that require Mode16
instead of Mode13 (2012-11-12 19:29:27 +0200)

----------------------------------------------------------------
Alexey Pelykh (1):
      Tweak to support 1Mbaud and similar baudrates that require
Mode16 instead of Mode13

 drivers/tty/serial/omap-serial.c |   38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 6d3d26a..6d567dd 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -182,24 +182,42 @@ static void serial_omap_enable_wakeup(struct
uart_omap_port *up, bool enable)
 }

 /*
+ * serial_omap_baud_is_mode16 - check if baud rate is MODE16X
+ * @port: uart port info
+ * @baud: baudrate for which mode needs to be determined
+ *
+ * Returns true if baud rate is MODE16X and false if MODE13X
+ * Original table in OMAP TRM named "UART Mode Baud Rates, Divisor Values,
+ * and Error Rates" determines modes not for all common baud rates.
+ * E.g. for 1000000 baud rate mode must be 16x, but according to that
+ * table it's determined as 13x.
+ */
+static bool
+serial_omap_baud_is_mode16(struct uart_port *port, unsigned int baud)
+{
+       unsigned int n13 = port->uartclk / (13 * baud);
+       unsigned int n16 = port->uartclk / (16 * baud);
+       int baudAbsDiff13 = baud - (port->uartclk / (13 * n13));
+       int baudAbsDiff16 = baud - (port->uartclk / (16 * n16));
+       if (baudAbsDiff13 < 0)
+               baudAbsDiff13 = -baudAbsDiff13;
+       if (baudAbsDiff16 < 0)
+               baudAbsDiff16 = -baudAbsDiff16;
+
+       return (baudAbsDiff13 > baudAbsDiff16);
+}
+
+/*
  * serial_omap_get_divisor - calculate divisor value
  * @port: uart port info
  * @baud: baudrate for which divisor needs to be calculated.
- *
- * We have written our own function to get the divisor so as to support
- * 13x mode. 3Mbps Baudrate as an different divisor.
- * Reference OMAP TRM Chapter 17:
- * Table 17-1. UART Mode Baud Rates, Divisor Values, and Error Rates
- * referring to oversampling - divisor value
- * baudrate 460,800 to 3,686,400 all have divisor 13
- * except 3,000,000 which has divisor value 16
  */
 static unsigned int
 serial_omap_get_divisor(struct uart_port *port, unsigned int baud)
 {
        unsigned int divisor;

-       if (baud > OMAP_MODE13X_SPEED && baud != 3000000)
+       if (!serial_omap_baud_is_mode16(port, baud))
                divisor = 13;
        else
                divisor = 16;
@@ -893,7 +911,7 @@ serial_omap_set_termios(struct uart_port *port,
struct ktermios *termios,
        serial_out(up, UART_EFR, up->efr);
        serial_out(up, UART_LCR, cval);

-       if (baud > 230400 && baud != 3000000)
+       if (!serial_omap_baud_is_mode16(port, baud))
                up->mdr1 = UART_OMAP_MDR1_13X_MODE;
        else
                up->mdr1 = UART_OMAP_MDR1_16X_MODE;

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: Fwd: [PULL REQUEST] Tweak to support 1Mbaud and similar baudrates that require Mode16 instead of Mode13
  2012-11-28  9:05       ` Alexey Pelykh
@ 2012-11-28 17:25         ` Greg KH
       [not found]           ` <CAOmKuSq52wWgetb53S1HiMNghT_A3UukPaUO0E9dXtWor+GVvw@mail.gmail.com>
  0 siblings, 1 reply; 8+ messages in thread
From: Greg KH @ 2012-11-28 17:25 UTC (permalink / raw)
  To: Alexey Pelykh; +Cc: Alan Cox, linux-serial

On Wed, Nov 28, 2012 at 11:05:08AM +0200, Alexey Pelykh wrote:
> Original table in OMAP TRM named "UART Mode Baud Rates, Divisor
> Values, and Error Rates" determines modes not for all common baud
> rates. E.g. for 1000000 baud rate mode should be 16x, but according to
> that table it's determined as 13x. According to current implementation
> of mode
> divisor selection, after requesting 1000000 baudrate from driver,
> later one will configure chip to use MODE13 divisor. Assuming 48Mhz as
> common UART clock speed, MODE13 divisor will effectively give 1230769
> baudrate, what is quite far from desired 1000000 baudrate. While with
> MODE16 divisor, chip will produce exact 1000000 baudrate.
> 
> In old driver that served UART devices (8250.c and serial_core.c) this
> divisor could have been configured by user-space program, but in
> omap_serial.c driver implementation this ability was not implemented
> (afaik, by design) thus disallowing proper usage of MODE16-compatible
> baudrates.
> 
> Changes: I've fixed styling errors using ./scripts/checkpatch.pl
> 
> Signed-off-by: Alexey Pelykh <alexey.pelykh@gmail.com>
> 
> The following changes since commit 77b67063bb6bce6d475e910d3b886a606d0d91f7:

Again, I will not take a pull request, why do you keep on sending this?

Please just send your patch through mail, in a format that I can apply
it in (as described in Documentation/SubmittingPatches).

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fwd: [PULL REQUEST] Tweak to support 1Mbaud and similar baudrates that require Mode16 instead of Mode13
       [not found]           ` <CAOmKuSq52wWgetb53S1HiMNghT_A3UukPaUO0E9dXtWor+GVvw@mail.gmail.com>
@ 2012-11-28 17:32             ` Greg KH
  0 siblings, 0 replies; 8+ messages in thread
From: Greg KH @ 2012-11-28 17:32 UTC (permalink / raw)
  To: Alexey Pelykh; +Cc: Alan Cox, linux-serial

On Wed, Nov 28, 2012 at 07:26:32PM +0200, Alexey Pelykh wrote:
> Sorry, probably I've misunderstood you. Should I attach patch as a file to
> email or just embed the patch content (as I did last time) into email body?

As I stated, the file, Documentation/SubmittingPatches decribes all of
this.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-11-28 17:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CAOmKuSpRJhBibSDxTFCH157-XokhaFhvQ-gYxKZe+PfzokaBoA@mail.gmail.com>
2012-11-27 21:35 ` Fwd: [PULL REQUEST] Tweak to support 1Mbaud and similar baudrates that require Mode16 instead of Mode13 Alexey Pelykh
2012-11-27 21:46   ` Alan Cox
2012-11-27 21:56   ` Fwd: " Alexey Pelykh
2012-11-27 23:00     ` Alan Cox
2012-11-28  0:42     ` Fwd: " Greg KH
2012-11-28  9:05       ` Alexey Pelykh
2012-11-28 17:25         ` Greg KH
     [not found]           ` <CAOmKuSq52wWgetb53S1HiMNghT_A3UukPaUO0E9dXtWor+GVvw@mail.gmail.com>
2012-11-28 17:32             ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox