linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Paul Ruhland <pruhland@rochester.rr.com>
To: linuxppc-embedded@lists.linuxppc.org
Subject: arch/ppc/8xx_io/commproc.c brg calculation patch
Date: Fri, 7 Mar 2003 02:26:41 -0500	[thread overview]
Message-ID: <200303070226.41690.pruhland@rochester.rr.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 589 bytes --]

This patch is against the linux-2.4 denx cvs. I haven't checked
linxppc-2_4_devel tree but I imagine it is the same.  It adds a bit more
precision to the brg calculation.

Currently, the calculation simply truncates (rounds down) the brg divider
which will make the baud rate on the high side of optimal when a closer value
may exist below optimal rate.  This was causing communication with some
equipment to fail as the higher value was out of tolerance.

This patch will round down (the brg divider) if the fractional part of the
division is < .5 and round up if >= .5.

--
Paul Ruhland

[-- Attachment #2: linux-2.4.brgcalc.patch --]
[-- Type: text/x-diff, Size: 995 bytes --]

diff -ruN linux-2.4.ORIG/arch/ppc/8xx_io/commproc.c linux-2.4/arch/ppc/8xx_io/commproc.c
--- linux-2.4.ORIG/arch/ppc/8xx_io/commproc.c	2002-09-28 05:53:19.000000000 -0400
+++ linux-2.4/arch/ppc/8xx_io/commproc.c	2003-01-18 13:34:23.000000000 -0500
@@ -404,13 +404,18 @@
 	*/
 	bp = (uint *)&cpmp->cp_brgc1;
 	bp += brg;
+
 	/* The BRG has a 12-bit counter.  For really slow baud rates (or
 	 * really fast processors), we may have to further divide by 16.
+	 *
+	 * NOTE: for integer math division, adding (divisor/2) to numerator
+	 * rounds up (if fractional part would be >= .5) for more precision
 	 */
-	if (((BRG_UART_CLK / rate) - 1) < 4096)
-		*bp = (((BRG_UART_CLK / rate) - 1) << 1) | CPM_BRG_EN;
+
+	if ((((BRG_UART_CLK + (rate/2))/ rate) - 1) < 4096)
+		*bp = ((((BRG_UART_CLK +(rate/2)) / rate) - 1) << 1) | CPM_BRG_EN;
 	else
-		*bp = (((BRG_UART_CLK_DIV16 / rate) - 1) << 1) |
+		*bp = ((((BRG_UART_CLK_DIV16 + (rate/2))/ rate) - 1) << 1) |
 						CPM_BRG_EN | CPM_BRG_DIV16;
 }


                 reply	other threads:[~2003-03-07  7:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=200303070226.41690.pruhland@rochester.rr.com \
    --to=pruhland@rochester.rr.com \
    --cc=linuxppc-embedded@lists.linuxppc.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;
as well as URLs for NNTP newsgroup(s).