summaryrefslogtreecommitdiff
path: root/cpu/mcf52x2/serial.c
diff options
context:
space:
mode:
authorJon Loeliger <jdl@freescale.com>2006-08-09 13:36:54 -0500
committerJon Loeliger <jdl@freescale.com>2006-08-09 13:36:54 -0500
commit281f69ede28cd3d8be5d62a96b5a0b73e6065858 (patch)
tree8f1a0f42ce7d9c66d0ff2ecf93c9b069cbc68cc0 /cpu/mcf52x2/serial.c
parent870cbeaa45ccdbd6566882741da9f82433bd4a86 (diff)
parent6587f7e1e98bfcb7910a47bae2eb51e9a5fbd4da (diff)
downloadu-boot-imx-281f69ede28cd3d8be5d62a96b5a0b73e6065858.zip
u-boot-imx-281f69ede28cd3d8be5d62a96b5a0b73e6065858.tar.gz
u-boot-imx-281f69ede28cd3d8be5d62a96b5a0b73e6065858.tar.bz2
Merge branch 'wd'
Diffstat (limited to 'cpu/mcf52x2/serial.c')
-rw-r--r--cpu/mcf52x2/serial.c73
1 files changed, 51 insertions, 22 deletions
diff --git a/cpu/mcf52x2/serial.c b/cpu/mcf52x2/serial.c
index 1011788..8be09e3 100644
--- a/cpu/mcf52x2/serial.c
+++ b/cpu/mcf52x2/serial.c
@@ -55,45 +55,75 @@ void rs_serial_setbaudrate(int port,int baudrate)
{
#if defined(CONFIG_M5272) || defined(CONFIG_M5249) || defined(CONFIG_M5271)
volatile unsigned char *uartp;
-#ifndef CONFIG_M5271
+# ifndef CONFIG_M5271
double fraction;
-#endif
+# endif
double clock;
if (port == 0)
- uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE1);
+ uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE1);
else
- uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE2);
+ uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE2);
- clock = DoubleClock(baudrate); /* Set baud above */
+ clock = DoubleClock(baudrate); /* Set baud above */
- uartp[MCFUART_UBG1] = (((int)clock >> 8) & 0xff); /* set msb baud */
- uartp[MCFUART_UBG2] = ((int)clock & 0xff); /* set lsb baud */
+ uartp[MCFUART_UBG1] = (((int)clock >> 8) & 0xff); /* set msb baud */
+ uartp[MCFUART_UBG2] = ((int)clock & 0xff); /* set lsb baud */
-#ifndef CONFIG_M5271
+# ifndef CONFIG_M5271
fraction = ((clock - (int)clock) * 16.0) + 0.5;
- uartp[MCFUART_UFPD] = ((int)fraction & 0xf); /* set baud fraction adjust */
+ uartp[MCFUART_UFPD] = ((int)fraction & 0xf); /* set baud fraction adjust */
+# endif
#endif
+
+#if defined(CONFIG_M5282)
+ volatile unsigned char *uartp;
+ long clock;
+
+ switch (port) {
+ case 1:
+ uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE2);
+ break;
+ case 2:
+ uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE3);
+ break;
+ default:
+ uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE1);
+ }
+
+ clock = (long) CFG_CLK / ((long) 32 * baudrate); /* Set baud above */
+
+ uartp[MCFUART_UBG1] = (((int)clock >> 8) & 0xff); /* set msb baud */
+ uartp[MCFUART_UBG2] = ((int) clock & 0xff); /* set lsb baud */
+
#endif
};
-void rs_serial_init(int port,int baudrate)
+void rs_serial_init (int port, int baudrate)
{
- volatile unsigned char *uartp;
+ volatile unsigned char *uartp;
/*
- * Reset UART, get it into known state...
+ * Reset UART, get it into known state...
*/
- if (port == 0)
- uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE1);
- else
+ switch (port) {
+ case 1:
uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE2);
+ break;
+#if defined(CONFIG_M5282)
+ case 2:
+ uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE3);
+ break;
+#endif
+ default:
+ uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE1);
+ }
- uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
- uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
- uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
- uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETERR; /* reset Error pointer */
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
+ uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETERR; /* reset Error pointer */
/*
* Set port for CONSOLE_BAUD_RATE, 8 data bits, 1 stop bit, no parity.
@@ -107,7 +137,7 @@ void rs_serial_init(int port,int baudrate)
/* Set clock Select Register: Tx/Rx clock is timer */
uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
- rs_serial_setbaudrate(port,baudrate);
+ rs_serial_setbaudrate (port, baudrate);
/* Enable Tx/Rx */
uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
@@ -169,9 +199,8 @@ void serial_putc(const char c) {
}
void serial_puts (const char *s) {
- while (*s) {
+ while (*s)
serial_putc(*s++);
- }
}
int serial_getc(void) {