* arch/ppc/8xx_io/commproc.c brg calculation patch
@ 2003-03-07 7:26 Paul Ruhland
0 siblings, 0 replies; only message in thread
From: Paul Ruhland @ 2003-03-07 7:26 UTC (permalink / raw)
To: linuxppc-embedded
[-- 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;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-03-07 7:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-07 7:26 arch/ppc/8xx_io/commproc.c brg calculation patch Paul Ruhland
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).