[PATCH 9_9] Use "void *" not "unsigned long *" for block dev read_write buffer pointers
[oweals/u-boot.git] / cpu / pxa / serial.c
index c9d5f70bc473097671f3f429c824a89ae76657ba..cb3a4789901a47baaaa57ed54e88f9dfac3e61e5 100644 (file)
  */
 
 #include <common.h>
+#include <watchdog.h>
 #include <asm/arch/pxa-regs.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 void serial_setbrg (void)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
        unsigned int quot = 0;
 
        if (gd->baudrate == 1200)
-               quot = 192;
+               quot = 768;
        else if (gd->baudrate == 9600)
                quot = 96;
        else if (gd->baudrate == 19200)
@@ -53,8 +54,11 @@ void serial_setbrg (void)
                hang ();
 
 #ifdef CONFIG_FFUART
-
+#ifdef CONFIG_CPU_MONAHANS
+       CKENA |= CKENA_22_FFUART;
+#else
        CKEN |= CKEN6_FFUART;
+#endif /* CONFIG_CPU_MONAHANS */
 
        FFIER = 0;                                      /* Disable for now */
        FFFCR = 0;                                      /* No fifos enabled */
@@ -68,7 +72,11 @@ void serial_setbrg (void)
        FFIER = IER_UUE;                        /* Enable FFUART */
 
 #elif defined(CONFIG_BTUART)
+#ifdef CONFIG_CPU_MONAHANS
+       CKENA |= CKENA_21_BTUART;
+#else
        CKEN |= CKEN7_BTUART;
+#endif /*  CONFIG_CPU_MONAHANS */
 
        BTIER = 0;
        BTFCR = 0;
@@ -82,9 +90,25 @@ void serial_setbrg (void)
        BTIER = IER_UUE;                        /* Enable BFUART */
 
 #elif defined(CONFIG_STUART)
-#error "Bad: not implemented yet!"
+#ifdef CONFIG_CPU_MONAHANS
+       CKENA |= CKENA_23_STUART;
+#else
+       CKEN |= CKEN5_STUART;
+#endif /* CONFIG_CPU_MONAHANS */
+
+       STIER = 0;
+       STFCR = 0;
+
+       /* set baud rate */
+       STLCR = LCR_DLAB;
+       STDLL = quot & 0xff;
+       STDLH = quot >> 8;
+       STLCR = LCR_WLS0 | LCR_WLS1;
+
+       STIER = IER_UUE;                        /* Enable STUART */
+
 #else
-#error "Bad: you didn't configured serial ..."
+#error "Bad: you didn't configure serial ..."
 #endif
 }
 
@@ -109,13 +133,17 @@ void serial_putc (const char c)
 {
 #ifdef CONFIG_FFUART
        /* wait for room in the tx FIFO on FFUART */
-       while ((FFLSR & LSR_TEMT) == 0);
-
+       while ((FFLSR & LSR_TEMT) == 0)
+               WATCHDOG_RESET ();      /* Reset HW Watchdog, if needed */
        FFTHR = c;
 #elif defined(CONFIG_BTUART)
-       while ((BTLSR & LSR_TEMT ) == 0 );
+       while ((BTLSR & LSR_TEMT ) == 0 )
+               WATCHDOG_RESET ();      /* Reset HW Watchdog, if needed */
        BTTHR = c;
 #elif defined(CONFIG_STUART)
+       while ((STLSR & LSR_TEMT ) == 0 )
+               WATCHDOG_RESET ();      /* Reset HW Watchdog, if needed */
+       STTHR = c;
 #endif
 
        /* If \n, also do \r */
@@ -135,6 +163,7 @@ int serial_tstc (void)
 #elif defined(CONFIG_BTUART)
        return BTLSR & LSR_DR;
 #elif defined(CONFIG_STUART)
+       return STLSR & LSR_DR;
 #endif
 }
 
@@ -146,14 +175,17 @@ int serial_tstc (void)
 int serial_getc (void)
 {
 #ifdef CONFIG_FFUART
-       while (!(FFLSR & LSR_DR));
-
+       while (!(FFLSR & LSR_DR))
+               WATCHDOG_RESET ();      /* Reset HW Watchdog, if needed */
        return (char) FFRBR & 0xff;
 #elif defined(CONFIG_BTUART)
-       while (!(BTLSR & LSR_DR));
-
+       while (!(BTLSR & LSR_DR))
+               WATCHDOG_RESET ();      /* Reset HW Watchdog, if needed */
        return (char) BTRBR & 0xff;
 #elif defined(CONFIG_STUART)
+       while (!(STLSR & LSR_DR))
+               WATCHDOG_RESET ();      /* Reset HW Watchdog, if needed */
+       return (char) STRBR & 0xff;
 #endif
 }