From 81cc32322acb1b3225ee45606ced48e2a14824dc Mon Sep 17 00:00:00 2001 From: TsiChung Liew Date: Thu, 29 May 2008 12:21:54 -0500 Subject: ColdFire: Fix UART baudrate formula The formula "counter = (u32) (gd->bus_clk / gd->baudrate) / 32" can generate the wrong divisor due to integer division truncation. Round the calculated divisor value by adding 1/2 the baudrate before dividing by the baudrate. Signed-off-by: TsiChung Liew Acked-by: Gerald Van Baren --- drivers/serial/mcfuart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/serial') diff --git a/drivers/serial/mcfuart.c b/drivers/serial/mcfuart.c index 88f3eb10ab..5eb4f458f8 100644 --- a/drivers/serial/mcfuart.c +++ b/drivers/serial/mcfuart.c @@ -63,8 +63,8 @@ int serial_init(void) uart->umr = UART_UMR_SB_STOP_BITS_1; /* Setting up BaudRate */ - counter = (u32) (gd->bus_clk / (gd->baudrate)); - counter >>= 5; + counter = (u32) ((gd->bus_clk / 32) + (gd->baudrate / 2)); + counter = counter / gd->baudrate; /* write to CTUR: divide counter upper byte */ uart->ubg1 = (u8) ((counter & 0xff00) >> 8); -- cgit From ef130d3093bdf88f01cf3e000fe5df249ebf2b1a Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Fri, 11 Jul 2008 10:24:15 -0400 Subject: Fix integer overflow warning in calc_divisor() which happened when rounding the serial port clock divisor Signed-off-by: Hugo Villeneuve --- drivers/serial/serial.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'drivers/serial') diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index 182ca2d149..4ccaee28b0 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -124,6 +124,8 @@ static NS16550_t serial_ports[4] = { static int calc_divisor (NS16550_t port) { + uint32_t clk_divisor; + #ifdef CONFIG_OMAP1510 /* If can't cleanly clock 115200 set div to 1 */ if ((CFG_NS16550_CLK == 12000000) && (gd->baudrate == 115200)) { @@ -147,10 +149,15 @@ static int calc_divisor (NS16550_t port) /* Compute divisor value. Normally, we should simply return: * CFG_NS16550_CLK) / MODE_X_DIV / gd->baudrate - * but we need to round that value by adding 0.5 or 8/16. + * but we need to round that value by adding 0.5 (2/4). * Rounding is especially important at high baud rates. */ - return (((16 * CFG_NS16550_CLK) / MODE_X_DIV / gd->baudrate) + 8) / 16; + clk_divisor = (((4 * CFG_NS16550_CLK) / + (MODE_X_DIV * gd->baudrate)) + 2) / 4; + + debug("NS16550 clock divisor = %d\n", clk_divisor); + + return clk_divisor; } #if !defined(CONFIG_SERIAL_MULTI) -- cgit From 53ea981c3124b13c137c2d10e975b7c6672266e0 Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Fri, 11 Jul 2008 10:10:31 +0200 Subject: microblaze: Clean uartlite driver Redesign uartlite driver to in_be32 and out_be32 macros Fix missing header in io.h Signed-off-by: Michal Simek Acked-by: Grant Likely --- drivers/serial/serial_xuartlite.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'drivers/serial') diff --git a/drivers/serial/serial_xuartlite.c b/drivers/serial/serial_xuartlite.c index d678ab6b76..5c41a1c40a 100644 --- a/drivers/serial/serial_xuartlite.c +++ b/drivers/serial/serial_xuartlite.c @@ -1,6 +1,8 @@ /* - * (C) Copyright 2004 Atmark Techno, Inc. + * (C) Copyright 2008 Michal Simek + * Clean driver and add xilinx constant from header file * + * (C) Copyright 2004 Atmark Techno, Inc. * Yasushi SHOJI * * See file CREDITS for list of people who contributed to this @@ -13,7 +15,7 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License @@ -23,19 +25,21 @@ */ #include +#include #ifdef CONFIG_XILINX_UARTLITE -#include +#define RX_FIFO_OFFSET 0 /* receive FIFO, read only */ +#define TX_FIFO_OFFSET 4 /* transmit FIFO, write only */ +#define STATUS_REG_OFFSET 8 /* status register, read only */ -/* FIXME: we should convert these to in32 and out32 */ -#define IO_WORD(offset) (*(volatile unsigned long *)(offset)) -#define IO_SERIAL(offset) IO_WORD(CONFIG_SERIAL_BASE + (offset)) +#define SR_TX_FIFO_FULL 0x08 /* transmit FIFO full */ +#define SR_RX_FIFO_VALID_DATA 0x01 /* data in receive FIFO */ +#define SR_RX_FIFO_FULL 0x02 /* receive FIFO full */ -#define IO_SERIAL_RX_FIFO IO_SERIAL(XUL_RX_FIFO_OFFSET) -#define IO_SERIAL_TX_FIFO IO_SERIAL(XUL_TX_FIFO_OFFSET) -#define IO_SERIAL_STATUS IO_SERIAL(XUL_STATUS_REG_OFFSET) -#define IO_SERIAL_CONTROL IO_SERIAL(XUL_CONTROL_REG_OFFSET) +#define UARTLITE_STATUS (CONFIG_SERIAL_BASE + STATUS_REG_OFFSET) +#define UARTLITE_TX_FIFO (CONFIG_SERIAL_BASE + TX_FIFO_OFFSET) +#define UARTLITE_RX_FIFO (CONFIG_SERIAL_BASE + RX_FIFO_OFFSET) int serial_init(void) { @@ -50,9 +54,10 @@ void serial_setbrg(void) void serial_putc(const char c) { - if (c == '\n') serial_putc('\r'); - while (IO_SERIAL_STATUS & XUL_SR_TX_FIFO_FULL); - IO_SERIAL_TX_FIFO = (unsigned char) (c & 0xff); + if (c == '\n') + serial_putc('\r'); + while (in_be32(UARTLITE_STATUS) & SR_TX_FIFO_FULL); + out_be32(UARTLITE_TX_FIFO, (unsigned char) (c & 0xff)); } void serial_puts(const char * s) @@ -64,13 +69,13 @@ void serial_puts(const char * s) int serial_getc(void) { - while (!(IO_SERIAL_STATUS & XUL_SR_RX_FIFO_VALID_DATA)); - return IO_SERIAL_RX_FIFO & 0xff; + while (!(in_be32(UARTLITE_STATUS) & SR_RX_FIFO_VALID_DATA)); + return in_be32(UARTLITE_RX_FIFO) & 0xff; } int serial_tstc(void) { - return (IO_SERIAL_STATUS & XUL_SR_RX_FIFO_VALID_DATA); + return (in_be32(UARTLITE_STATUS) & SR_RX_FIFO_VALID_DATA); } #endif /* CONFIG_MICROBLZE */ -- cgit From b64f190b7a34224df09b559ca111eb1b733f00ad Mon Sep 17 00:00:00 2001 From: Wolfgang Denk Date: Mon, 14 Jul 2008 15:06:35 +0200 Subject: Fix printf() format issues with sizeof_t types by using %zu Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Wolfgang Denk --- drivers/serial/usbtty.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/serial') diff --git a/drivers/serial/usbtty.c b/drivers/serial/usbtty.c index cc2bdac479..2bc5c3c838 100644 --- a/drivers/serial/usbtty.c +++ b/drivers/serial/usbtty.c @@ -529,8 +529,8 @@ int drv_usbtty_init (void) } snlen = strlen(sn); if (snlen > sizeof(serial_number) - 1) { - printf ("Warning: serial number %s is too long (%d > %d)\n", - sn, snlen, sizeof(serial_number) - 1); + printf ("Warning: serial number %s is too long (%d > %lu)\n", + sn, snlen, (ulong)(sizeof(serial_number) - 1)); snlen = sizeof(serial_number) - 1; } memcpy (serial_number, sn, snlen); -- cgit From bcab74baa6b1b1c969038ab6f64a186239180405 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Tue, 15 Jul 2008 11:23:02 -0400 Subject: Round the serial port clock divisor value returned by calc_divisor() Round the serial port clock divisor value returned by calc_divisor() Signed-off-by: Hugo Villeneuve Acked-by: Gerald Van Baren --- drivers/serial/serial.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'drivers/serial') diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index 4ccaee28b0..8bbfcf9c0c 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -124,8 +124,6 @@ static NS16550_t serial_ports[4] = { static int calc_divisor (NS16550_t port) { - uint32_t clk_divisor; - #ifdef CONFIG_OMAP1510 /* If can't cleanly clock 115200 set div to 1 */ if ((CFG_NS16550_CLK == 12000000) && (gd->baudrate == 115200)) { @@ -149,15 +147,11 @@ static int calc_divisor (NS16550_t port) /* Compute divisor value. Normally, we should simply return: * CFG_NS16550_CLK) / MODE_X_DIV / gd->baudrate - * but we need to round that value by adding 0.5 (2/4). + * but we need to round that value by adding 0.5. * Rounding is especially important at high baud rates. */ - clk_divisor = (((4 * CFG_NS16550_CLK) / - (MODE_X_DIV * gd->baudrate)) + 2) / 4; - - debug("NS16550 clock divisor = %d\n", clk_divisor); - - return clk_divisor; + return (CFG_NS16550_CLK + (gd->baudrate * (MODE_X_DIV / 2))) / + (MODE_X_DIV * gd->baudrate); } #if !defined(CONFIG_SERIAL_MULTI) -- cgit From f13f64cf42d5abec3e0f920233f6a7a61e7ae494 Mon Sep 17 00:00:00 2001 From: Ricardo Ribalda Delgado Date: Wed, 16 Jul 2008 16:22:32 +0200 Subject: serial_xuartlite.c: fix compiler warnings Signed-off-by: Ricardo Ribalda Delgado Acked-by: Grant Likely --- drivers/serial/serial_xuartlite.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/serial') diff --git a/drivers/serial/serial_xuartlite.c b/drivers/serial/serial_xuartlite.c index 5c41a1c40a..74546ce846 100644 --- a/drivers/serial/serial_xuartlite.c +++ b/drivers/serial/serial_xuartlite.c @@ -56,8 +56,8 @@ void serial_putc(const char c) { if (c == '\n') serial_putc('\r'); - while (in_be32(UARTLITE_STATUS) & SR_TX_FIFO_FULL); - out_be32(UARTLITE_TX_FIFO, (unsigned char) (c & 0xff)); + while (in_be32((u32 *) UARTLITE_STATUS) & SR_TX_FIFO_FULL); + out_be32((u32 *) UARTLITE_TX_FIFO, (unsigned char) (c & 0xff)); } void serial_puts(const char * s) @@ -69,13 +69,13 @@ void serial_puts(const char * s) int serial_getc(void) { - while (!(in_be32(UARTLITE_STATUS) & SR_RX_FIFO_VALID_DATA)); - return in_be32(UARTLITE_RX_FIFO) & 0xff; + while (!(in_be32((u32 *) UARTLITE_STATUS) & SR_RX_FIFO_VALID_DATA)); + return in_be32((u32 *) UARTLITE_RX_FIFO) & 0xff; } int serial_tstc(void) { - return (in_be32(UARTLITE_STATUS) & SR_RX_FIFO_VALID_DATA); + return (in_be32((u32 *) UARTLITE_STATUS) & SR_RX_FIFO_VALID_DATA); } #endif /* CONFIG_MICROBLZE */ -- cgit